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) for (i=COUNT-1; i>=0; i--) {
25 if (!head->f[i]) continue;
35 void __cxa_finalize(void *dso)
39 int __cxa_atexit(void (*func)(void *), void *arg, void *dso)
45 /* Defer initialization of head so it can be in BSS */
46 if (!head) head = &builtin;
48 /* If the current function list is full, add a new one */
49 if (head->f[COUNT-1]) {
50 struct fl *new_fl = calloc(sizeof(struct fl), 1);
59 /* Append function to the list. */
60 for (i=0; i<COUNT && head->f[i]; i++);
68 static void call(void *p)
70 ((void (*)(void))(uintptr_t)p)();
73 int atexit(void (*func)(void))
75 return __cxa_atexit(call, (void *)(uintptr_t)func, 0);