]> git.saurik.com Git - apple/libc.git/blob - stdlib/FreeBSD/atexit.c.patch
1aa7e4240f63f48bf4aeefb3fdaeba78005c35f8
[apple/libc.git] / stdlib / FreeBSD / atexit.c.patch
1 --- atexit.c.orig 2006-04-09 01:23:25.000000000 -0700
2 +++ atexit.c 2006-04-09 01:44:07.000000000 -0700
3 @@ -45,6 +45,9 @@
4 #include <stdlib.h>
5 #include <unistd.h>
6 #include <pthread.h>
7 +#if defined(__DYNAMIC__)
8 +#include <mach-o/dyld.h>
9 +#endif /* defined(__DYNAMIC__) */
10 #include "atexit.h"
11 #include "un-namespace.h"
12
13 @@ -74,6 +77,7 @@
14 };
15
16 static struct atexit *__atexit; /* points to head of LIFO stack */
17 +static int new_registration;
18
19 /*
20 * Register the function described by 'fptr' to be called at application
21 @@ -109,6 +113,7 @@
22 __atexit = p;
23 }
24 p->fns[p->ind++] = *fptr;
25 + new_registration = 1;
26 _MUTEX_UNLOCK(&atexit_mutex);
27 return 0;
28 }
29 @@ -125,7 +130,11 @@
30 fn.fn_type = ATEXIT_FN_STD;
31 fn.fn_ptr.std_func = func;;
32 fn.fn_arg = NULL;
33 +#if defined(__DYNAMIC__)
34 + fn.fn_dso = (void *)_dyld_get_image_header_containing_address((unsigned long) func);
35 +#else /* ! defined(__DYNAMIC__) */
36 fn.fn_dso = NULL;
37 +#endif /* defined(__DYNAMIC__) */
38
39 error = atexit_register(&fn);
40 return (error);
41 @@ -156,13 +165,14 @@
42 * handlers are called.
43 */
44 void
45 -__cxa_finalize(void *dso)
46 +__cxa_finalize(const void *dso)
47 {
48 struct atexit *p;
49 struct atexit_fn fn;
50 int n;
51
52 _MUTEX_LOCK(&atexit_mutex);
53 +restart:
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)
57 @@ -175,6 +185,7 @@
58 has already been called.
59 */
60 p->fns[n].fn_type = ATEXIT_FN_EMPTY;
61 + new_registration = 0;
62 _MUTEX_UNLOCK(&atexit_mutex);
63
64 /* Call the function of correct type. */
65 @@ -183,6 +194,8 @@
66 else if (fn.fn_type == ATEXIT_FN_STD)
67 fn.fn_ptr.std_func();
68 _MUTEX_LOCK(&atexit_mutex);
69 + if (new_registration)
70 + goto restart;
71 }
72 }
73 _MUTEX_UNLOCK(&atexit_mutex);