1 /* Copyright (C) 1991,95,96,97,99,2001,2002,2005,2009
2 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
25 #include "set-hooks.h"
26 DEFINE_HOOK (__libc_atexit
, (void))
29 /* Call all functions registered with `atexit' and `on_exit',
30 in the reverse of the order in which they were registered
31 perform stdio cleanup, and terminate program execution with STATUS. */
34 __run_exit_handlers (int status
, struct exit_function_list
**listp
,
37 /* We do it this way to handle recursive calls to exit () made by
38 the functions registered with `atexit' and `on_exit'. We call
39 everyone on the list and use the status value in the last
41 while (*listp
!= NULL
)
43 struct exit_function_list
*cur
= *listp
;
47 const struct exit_function
*const f
=
48 &cur
->fns
[--cur
->idx
];
52 void (*onfct
) (int status
, void *arg
);
53 void (*cxafct
) (void *arg
, int status
);
59 onfct
= f
->func
.on
.fn
;
63 onfct (status
, f
->func
.on
.arg
);
73 cxafct
= f
->func
.cxa
.fn
;
75 PTR_DEMANGLE (cxafct
);
77 cxafct (f
->func
.cxa
.arg
, status
);
84 /* Don't free the last element in the chain, this is the statically
90 RUN_HOOK (__libc_atexit
, ());
99 __run_exit_handlers (status
, &__exit_funcs
, true);
101 libc_hidden_def (exit
)