]>
Commit | Line | Data |
---|---|---|
00b708da | 1 | /* Provide the runtime infrastructure for the transactional memory lib. |
8f8ba4fc | 2 | Copyright (C) 2011 Free Software Foundation, Inc. |
3 | Contributed by Iain Sandoe <iains@gcc.gnu.org> | |
4 | ||
5 | This file is part of GCC. | |
6 | ||
00b708da | 7 | GCC is free software; you can redistribute it and/or modify it under |
8 | the terms of the GNU General Public License as published by the Free | |
9 | Software Foundation; either version 3, or (at your option) any later | |
10 | version. | |
8f8ba4fc | 11 | |
00b708da | 12 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY |
13 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 | for more details. | |
8f8ba4fc | 16 | |
00b708da | 17 | Under Section 7 of GPL version 3, you are granted additional |
18 | permissions described in the GCC Runtime Library Exception, version | |
19 | 3.1, as published by the Free Software Foundation. | |
20 | ||
21 | You should have received a copy of the GNU General Public License and | |
22 | a copy of the GCC Runtime Library Exception along with this program; | |
23 | see the files COPYING3 and COPYING.RUNTIME respectively. If not, see | |
8f8ba4fc | 24 | <http://www.gnu.org/licenses/>. */ |
25 | ||
621d0dd2 | 26 | #include "tsystem.h" |
27 | #include <stddef.h> | |
28 | #include <dlfcn.h> | |
8f8ba4fc | 29 | #include <mach-o/dyld.h> |
621d0dd2 | 30 | #include <mach-o/getsect.h> |
31 | ||
32 | #ifdef __LP64__ | |
33 | #define GET_DATA_TMCT(mh,size) \ | |
34 | getsectdatafromheader_64 ((struct mach_header_64*) mh, \ | |
35 | "__DATA", "__tm_clone_table", (uint64_t *)size) | |
36 | #else | |
37 | #define GET_DATA_TMCT(mh,size) \ | |
38 | getsectdatafromheader (mh, "__DATA", "__tm_clone_table", (uint32_t *)size) | |
39 | #endif | |
8f8ba4fc | 40 | |
41 | #define WEAK __attribute__((weak)) | |
b8f45854 | 42 | #define UNUSED __attribute__((unused)) |
8f8ba4fc | 43 | |
8f8ba4fc | 44 | extern void _ITM_registerTMCloneTable (void *, size_t) WEAK; |
45 | extern void _ITM_deregisterTMCloneTable (void *) WEAK; | |
46 | ||
621d0dd2 | 47 | #if defined(START) || defined(END) |
48 | static inline void *getTMCloneTable (const void *f, size_t *tmct_siz) | |
49 | { | |
50 | char *tmct_fixed, *tmct = NULL; | |
51 | unsigned int i, img_count; | |
52 | struct mach_header *mh; | |
53 | Dl_info info; | |
54 | ||
55 | if (! dladdr (f, &info) || info.dli_fbase == NULL) | |
56 | abort (); | |
57 | ||
58 | mh = (struct mach_header *) info.dli_fbase; | |
59 | tmct_fixed = GET_DATA_TMCT (mh, tmct_siz); | |
60 | *tmct_siz /= (sizeof (size_t) * 2); | |
61 | /* No tm_clone_table or no clones. */ | |
62 | if (tmct_fixed == NULL || *tmct_siz == 0) | |
63 | return NULL; | |
64 | ||
65 | img_count = _dyld_image_count(); | |
66 | for (i = 0; i < img_count && tmct == NULL; i++) | |
67 | { | |
68 | if (mh == _dyld_get_image_header(i)) | |
69 | tmct = tmct_fixed + (unsigned long)_dyld_get_image_vmaddr_slide(i); | |
70 | } | |
71 | ||
72 | return tmct; | |
73 | } | |
74 | #endif | |
75 | ||
8f8ba4fc | 76 | #ifdef START |
77 | ||
78 | void __doTMRegistrations (void) __attribute__ ((constructor)); | |
79 | ||
80 | void __doTMRegistrations (void) | |
81 | { | |
621d0dd2 | 82 | size_t tmct_siz; |
83 | void *tmct; | |
84 | ||
85 | tmct = getTMCloneTable ((const void *)&__doTMRegistrations, &tmct_siz); | |
86 | if (_ITM_registerTMCloneTable != NULL && tmct != NULL) | |
87 | _ITM_registerTMCloneTable (tmct, (size_t)tmct_siz); | |
8f8ba4fc | 88 | } |
89 | ||
90 | #endif | |
91 | ||
92 | #ifdef END | |
93 | ||
94 | void __doTMdeRegistrations (void) __attribute__ ((destructor)); | |
95 | ||
96 | void __doTMdeRegistrations (void) | |
97 | { | |
621d0dd2 | 98 | size_t tmct_siz; |
99 | void *tmct; | |
8f8ba4fc | 100 | |
621d0dd2 | 101 | tmct = getTMCloneTable ((const void *)&__doTMdeRegistrations, &tmct_siz); |
102 | if (_ITM_deregisterTMCloneTable != NULL && tmct != NULL) | |
103 | _ITM_deregisterTMCloneTable (tmct); | |
8f8ba4fc | 104 | } |
105 | ||
8f8ba4fc | 106 | #endif |
b8f45854 | 107 | |
108 | /* Provide dummy functions to satisfy linkage for versions of the Darwin | |
109 | tool-chain that that can't handle undefined weak refs at the link stage. | |
110 | ??? Define these dummy functions only when !HAVE_ELF_STYLE_WEAKREF. */ | |
111 | ||
112 | extern void *__cxa_allocate_exception (size_t) WEAK; | |
113 | extern void __cxa_throw (void *, void *, void *) WEAK; | |
114 | extern void *__cxa_begin_catch (void *) WEAK; | |
115 | extern void *__cxa_end_catch (void) WEAK; | |
116 | extern void __cxa_tm_cleanup (void *, void *, unsigned int) WEAK; | |
117 | ||
118 | extern void *_ZnwX (size_t) WEAK; | |
119 | extern void _ZdlPv (void *) WEAK; | |
120 | extern void *_ZnaX (size_t) WEAK; | |
121 | extern void _ZdaPv (void *) WEAK; | |
122 | ||
123 | typedef const struct nothrow_t { } *c_nothrow_p; | |
124 | ||
125 | extern void *_ZnwXRKSt9nothrow_t (size_t, c_nothrow_p) WEAK; | |
126 | extern void _ZdlPvRKSt9nothrow_t (void *, c_nothrow_p) WEAK; | |
127 | extern void *_ZnaXRKSt9nothrow_t (size_t, c_nothrow_p) WEAK; | |
128 | extern void _ZdaPvRKSt9nothrow_t (void *, c_nothrow_p) WEAK; | |
129 | ||
130 | void *__cxa_allocate_exception (size_t s UNUSED) { return NULL; } | |
131 | void __cxa_throw (void * a UNUSED, void * b UNUSED, void * c UNUSED) | |
132 | { return; } | |
133 | void *__cxa_begin_catch (void * a UNUSED) { return NULL; } | |
134 | void *__cxa_end_catch (void) { return NULL; } | |
135 | void __cxa_tm_cleanup (void * a UNUSED, void * b UNUSED, unsigned int c UNUSED) | |
136 | { return; } | |
137 | ||
138 | void *_ZnwX (size_t s UNUSED) { return NULL; } | |
139 | void _ZdlPv (void * a UNUSED) { return; } | |
140 | void *_ZnaX (size_t s UNUSED) { return NULL; } | |
141 | void _ZdaPv (void * a UNUSED) { return; } | |
142 | ||
143 | void *_ZnwXRKSt9nothrow_t (size_t s UNUSED, c_nothrow_p b UNUSED) | |
144 | { return NULL; } | |
145 | void _ZdlPvRKSt9nothrow_t (void * a UNUSED, c_nothrow_p b UNUSED) { return; } | |
146 | void *_ZnaXRKSt9nothrow_t (size_t s UNUSED, c_nothrow_p b UNUSED) | |
147 | { return NULL; } | |
148 | void _ZdaPvRKSt9nothrow_t (void * a UNUSED, c_nothrow_p b UNUSED) { return; } | |
149 |