1 /* Copyright (C) 1991-2013 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
24 #include "set-hooks.h"
25 DEFINE_HOOK (__libc_atexit
, (void))
28 /* Call all functions registered with `atexit' and `on_exit',
29 in the reverse of the order in which they were registered
30 perform stdio cleanup, and terminate program execution with STATUS. */
33 __run_exit_handlers (int status
, struct exit_function_list
**listp
,
36 /* First, call the TLS destructors. */
39 /* We do it this way to handle recursive calls to exit () made by
40 the functions registered with `atexit' and `on_exit'. We call
41 everyone on the list and use the status value in the last
43 while (*listp
!= NULL
)
45 struct exit_function_list
*cur
= *listp
;
49 const struct exit_function
*const f
=
50 &cur
->fns
[--cur
->idx
];
54 void (*onfct
) (int status
, void *arg
);
55 void (*cxafct
) (void *arg
, int status
);
61 onfct
= f
->func
.on
.fn
;
65 onfct (status
, f
->func
.on
.arg
);
75 cxafct
= f
->func
.cxa
.fn
;
77 PTR_DEMANGLE (cxafct
);
79 cxafct (f
->func
.cxa
.arg
, status
);
86 /* Don't free the last element in the chain, this is the statically
92 RUN_HOOK (__libc_atexit
, ());
101 __run_exit_handlers (status
, &__exit_funcs
, true);
103 libc_hidden_def (exit
)