7 /* Ensure that at least 32 atexit handlers can be registered without malloc */
13 void (*f[COUNT])(void *);
19 void __funcs_on_exit()
22 void (*func)(void *), *arg;
24 for (; head; head=head->next) {
25 for (i=COUNT-1; i>=0 && !head->f[i]; i--);
36 void __cxa_finalize(void *dso)
40 int __cxa_atexit(void (*func)(void *), void *arg, void *dso)
46 /* Defer initialization of head so it can be in BSS */
47 if (!head) head = &builtin;
49 /* If the current function list is full, add a new one */
50 if (head->f[COUNT-1]) {
51 struct fl *new_fl = calloc(sizeof(struct fl), 1);
60 /* Append function to the list. */
61 for (i=0; i<COUNT && head->f[i]; i++);
69 static void call(void *p)
71 ((void (*)(void))(uintptr_t)p)();
74 int atexit(void (*func)(void))
76 return __cxa_atexit(call, (void *)(uintptr_t)func, 0);