1 --- atexit.c.orig 2006-04-09 01:23:25.000000000 -0700
2 +++ atexit.c 2006-04-09 01:44:07.000000000 -0700
7 +#if defined(__DYNAMIC__)
8 +#include <mach-o/dyld.h>
9 +#endif /* defined(__DYNAMIC__) */
11 #include "un-namespace.h"
16 static struct atexit *__atexit; /* points to head of LIFO stack */
17 +static int new_registration;
20 * Register the function described by 'fptr' to be called at application
24 p->fns[p->ind++] = *fptr;
25 + new_registration = 1;
26 _MUTEX_UNLOCK(&atexit_mutex);
30 fn.fn_type = ATEXIT_FN_STD;
31 fn.fn_ptr.std_func = func;;
33 +#if defined(__DYNAMIC__)
34 + fn.fn_dso = (void *)_dyld_get_image_header_containing_address((unsigned long) func);
35 +#else /* ! defined(__DYNAMIC__) */
37 +#endif /* defined(__DYNAMIC__) */
39 error = atexit_register(&fn);
42 * handlers are called.
45 -__cxa_finalize(void *dso)
46 +__cxa_finalize(const void *dso)
52 _MUTEX_LOCK(&atexit_mutex);
54 for (p = __atexit; p; p = p->next) {
55 for (n = p->ind; --n >= 0;) {
56 if (p->fns[n].fn_type == ATEXIT_FN_EMPTY)
58 has already been called.
60 p->fns[n].fn_type = ATEXIT_FN_EMPTY;
61 + new_registration = 0;
62 _MUTEX_UNLOCK(&atexit_mutex);
64 /* Call the function of correct type. */
66 else if (fn.fn_type == ATEXIT_FN_STD)
68 _MUTEX_LOCK(&atexit_mutex);
69 + if (new_registration)
73 _MUTEX_UNLOCK(&atexit_mutex);