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 int __cxa_atexit(void (*func)(void *), void *arg, void *dso)
42 /* Defer initialization of head so it can be in BSS */
43 if (!head) head = &builtin;
45 /* If the current function list is full, add a new one */
46 if (head->f[COUNT-1]) {
47 struct fl *new_fl = calloc(sizeof(struct fl), 1);
56 /* Append function to the list. */
57 for (i=0; i<COUNT && head->f[i]; i++);
65 static void call(void *p)
67 ((void (*)(void))(uintptr_t)p)();
70 int atexit(void (*func)(void))
72 return __cxa_atexit(call, (void *)(uintptr_t)func, 0);