mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-23 05:42:29 +00:00
Call thread finalizers on exit()
While we don't call POSIX thread key destructors from exit(), we do need to call these, since C++ uses it for TLS object destructors. See #1076
This commit is contained in:
parent
07db3004d6
commit
81ce2e4cbc
5 changed files with 56 additions and 22 deletions
|
@ -17,6 +17,7 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/cxxabi.h"
|
||||
#include "libc/intrin/cxaatexit.internal.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/intrin/weaken.h"
|
||||
#include "libc/runtime/internal.h"
|
||||
|
@ -36,13 +37,24 @@
|
|||
* @noreturn
|
||||
*/
|
||||
wontreturn void exit(int exitcode) {
|
||||
const uintptr_t *p;
|
||||
STRACE("exit(%d)", exitcode);
|
||||
|
||||
// call thread local c++ object destructors
|
||||
if (_weaken(__cxa_thread_finalize)) {
|
||||
_weaken(__cxa_thread_finalize)();
|
||||
}
|
||||
|
||||
// call atexit() and __cxa_atexit() destructors
|
||||
if (_weaken(__cxa_finalize)) {
|
||||
_weaken(__cxa_finalize)(NULL);
|
||||
}
|
||||
|
||||
// call __destructor__ and finiarray destructors
|
||||
const uintptr_t *p;
|
||||
for (p = __fini_array_end; p > __fini_array_start;) {
|
||||
((void (*)(void))(*--p))();
|
||||
}
|
||||
|
||||
// terminate process
|
||||
_Exit(exitcode);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue