void __cxa_finalize (void *dso_handle) { struct exit_function *efp; int exit_count_snapshot = __exit_count; /* In reverse order */ while (exit_count_snapshot) { efp = &__exit_function_table[--exit_count_snapshot]; /* * We check dso_handle match before we verify the type of the union entry. * However, the atomic_exchange will validate that we were really "allowed" * to read dso_handle... */ if ((dso_handle == NULL || dso_handle == efp->funcs.cxa_atexit.dso_handle) /* We don't want to run this cleanup more than once. */ && !atomic_compare_and_exchange_bool_acq(&efp->type, ef_free, ef_cxa_atexit) ) { /* glibc passes status (0) too, but that's not in the prototype */ (*efp->funcs.cxa_atexit.func)(efp->funcs.cxa_atexit.arg); } } #if 0 /* haven't looked into this yet... */ /* * Remove the registered fork handlers. We do not have to * unregister anything if the program is going to terminate anyway. */ #ifdef UNREGISTER_ATFORK if (d != NULL) { UNREGISTER_ATFORK (d); } #endif #endif }
/* If D is non-NULL, call all functions registered with `__cxa_atexit' with the same dso handle. Otherwise, if D is NULL, call all of the registered handlers. */ void __cxa_finalize (void *d) { struct exit_function_list *funcs; restart: for (funcs = __exit_funcs; funcs; funcs = funcs->next) { struct exit_function *f; for (f = &funcs->fns[funcs->idx - 1]; f >= &funcs->fns[0]; --f) { void (*cxafn) (void *arg, int status); void *cxaarg; if ((d == NULL || d == f->func.cxa.dso_handle) /* We don't want to run this cleanup more than once. */ && (cxafn = f->func.cxa.fn, cxaarg = f->func.cxa.arg, ! catomic_compare_and_exchange_bool_acq (&f->flavor, ef_free, ef_cxa))) { uint64_t check = __new_exitfn_called; #ifdef PTR_DEMANGLE PTR_DEMANGLE (cxafn); #endif cxafn (cxaarg, 0); /* It is possible that that last exit function registered more exit functions. Start the loop over. */ if (__builtin_expect (check != __new_exitfn_called, 0)) goto restart; } } } /* Also remove the quick_exit handlers, but do not call them. */ for (funcs = __quick_exit_funcs; funcs; funcs = funcs->next) { struct exit_function *f; for (f = &funcs->fns[funcs->idx - 1]; f >= &funcs->fns[0]; --f) if (d == NULL || d == f->func.cxa.dso_handle) f->flavor = ef_free; } /* Remove the registered fork handlers. We do not have to unregister anything if the program is going to terminate anyway. */ #ifdef UNREGISTER_ATFORK if (d != NULL) UNREGISTER_ATFORK (d); #endif }
/* If D is non-NULL, call all functions registered with `__cxa_atexit' with the same dso handle. Otherwise, if D is NULL, do nothing. */ void __cxa_finalize (void *d) { struct exit_function_list *funcs; for (funcs = __exit_funcs; funcs; funcs = funcs->next) { struct exit_function *f; for (f = &funcs->fns[funcs->idx - 1]; f >= &funcs->fns[0]; --f) if ((d == NULL || d == f->func.cxa.dso_handle) /* We don't want to run this cleanup more than once. */ && compare_and_swap (&f->flavor, ef_cxa, ef_free)) (*f->func.cxa.fn) (f->func.cxa.arg, 0); } /* Remove the registered fork handlers. */ #ifdef UNREGISTER_ATFORK UNREGISTER_ATFORK (d); #endif }