5 /* Ensure that at least 32 atexit handlers can be registered without malloc */
11 void (*f[COUNT])(void *);
17 void __funcs_on_exit()
20 void (*func)(void *), *arg;
22 for (; head; head=head->next) for (i=COUNT-1; i>=0; i--) {
23 if (!head->f[i]) continue;
33 void __cxa_finalize(void *dso)
37 int __cxa_atexit(void (*func)(void *), void *arg, void *dso)
43 /* Defer initialization of head so it can be in BSS */
44 if (!head) head = &builtin;
46 /* If the current function list is full, add a new one */
47 if (head->f[COUNT-1]) {
48 struct fl *new_fl = calloc(sizeof(struct fl), 1);
57 /* Append function to the list. */
58 for (i=0; i<COUNT && head->f[i]; i++);
66 static void call(void *p)
68 ((void (*)(void))(uintptr_t)p)();
71 int atexit(void (*func)(void))
73 return __cxa_atexit(call, (void *)(uintptr_t)func, 0);