]>
git.proxmox.com Git - wasi-libc.git/blob - libc-top-half/musl/src/exit/atexit.c
7 #define malloc __libc_malloc
8 #define calloc __libc_calloc
12 /* Ensure that at least 32 atexit handlers can be registered without malloc */
18 void (*f
[COUNT
])(void *);
24 #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
25 static volatile int lock
[1];
26 volatile int *const __atexit_lockptr
= lock
;
29 void __funcs_on_exit()
31 void (*func
)(void *), *arg
;
33 for (; head
; head
=head
->next
, slot
=COUNT
) while(slot
-->0) {
42 void __cxa_finalize(void *dso
)
46 int __cxa_atexit(void (*func
)(void *), void *arg
, void *dso
)
50 /* Defer initialization of head so it can be in BSS */
51 if (!head
) head
= &builtin
;
53 /* If the current function list is full, add a new one */
55 struct fl
*new_fl
= calloc(sizeof(struct fl
), 1);
65 /* Append function to the list. */
74 static void call(void *p
)
76 ((void (*)(void))(uintptr_t)p
)();
79 int atexit(void (*func
)(void))
81 return __cxa_atexit(call
, (void *)(uintptr_t)func
, 0);