X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fexit%2Fexit.c;h=a6869b37594ea06585bdbffd5bb4e0e52c956234;hb=595416b11dfbc82d40a59d0edd7e3b04ba7a2d6d;hp=ae557c090d1793220764dc413267a4e8e29c5e35;hpb=4750cf4202c29a895639b89099a7bdbe9ae422b6;p=musl diff --git a/src/exit/exit.c b/src/exit/exit.c index ae557c09..a6869b37 100644 --- a/src/exit/exit.c +++ b/src/exit/exit.c @@ -1,31 +1,33 @@ #include -#include -#include +#include #include "libc.h" static void dummy() { } -/* __towrite.c and atexit.c override these */ +/* atexit.c and __stdio_exit.c override these. the latter is linked + * as a consequence of linking either __toread.c or __towrite.c. */ weak_alias(dummy, __funcs_on_exit); -weak_alias(dummy, __fflush_on_exit); +weak_alias(dummy, __stdio_exit); +weak_alias(dummy, _fini); -void exit(int code) +extern weak hidden void (*const __fini_array_start)(void), (*const __fini_array_end)(void); + +static void libc_exit_fini(void) { - static int lock[2]; + uintptr_t a = (uintptr_t)&__fini_array_end; + for (; a>(uintptr_t)&__fini_array_start; a-=sizeof(void(*)())) + (*(void (**)())(a-sizeof(void(*)())))(); + _fini(); +} - /* If more than one thread calls exit, hang until _Exit ends it all */ - LOCK(lock); +weak_alias(libc_exit_fini, __libc_exit_fini); - /* Only do atexit & stdio flush if they were actually used */ +_Noreturn void exit(int code) +{ __funcs_on_exit(); - __fflush_on_exit(); - - /* Destructor s**t is kept separate from atexit to avoid bloat */ - if (libc.fini) libc.fini(); - if (libc.ldso_fini) libc.ldso_fini(); - + __libc_exit_fini(); + __stdio_exit(); _Exit(code); - for(;;); }