avoid malloc of deps arrays for ldso and vdso
[musl.git] / src / exit / exit.c
bloba6869b37594ea06585bdbffd5bb4e0e52c956234
1 #include <stdlib.h>
2 #include <stdint.h>
3 #include "libc.h"
5 static void dummy()
9 /* atexit.c and __stdio_exit.c override these. the latter is linked
10 * as a consequence of linking either __toread.c or __towrite.c. */
11 weak_alias(dummy, __funcs_on_exit);
12 weak_alias(dummy, __stdio_exit);
13 weak_alias(dummy, _fini);
15 extern weak hidden void (*const __fini_array_start)(void), (*const __fini_array_end)(void);
17 static void libc_exit_fini(void)
19 uintptr_t a = (uintptr_t)&__fini_array_end;
20 for (; a>(uintptr_t)&__fini_array_start; a-=sizeof(void(*)()))
21 (*(void (**)())(a-sizeof(void(*)())))();
22 _fini();
25 weak_alias(libc_exit_fini, __libc_exit_fini);
27 _Noreturn void exit(int code)
29 __funcs_on_exit();
30 __libc_exit_fini();
31 __stdio_exit();
32 _Exit(code);