]>
Commit | Line | Data |
---|---|---|
f1a1da6c A |
1 | /* |
2 | * Copyright (c) 2003-2013 Apple Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
6 | * This file contains Original Code and/or Modifications of Original Code | |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. Please obtain a copy of the License at | |
10 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
11 | * file. | |
12 | * | |
13 | * The Original Code and all software distributed under the License are | |
14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
18 | * Please see the License for the specific language governing rights and | |
19 | * limitations under the License. | |
20 | * | |
21 | * @APPLE_LICENSE_HEADER_END@ | |
22 | */ | |
23 | /* | |
24 | * Copyright 1996 1995 by Open Software Foundation, Inc. 1997 1996 1995 1994 1993 1992 1991 | |
25 | * All Rights Reserved | |
26 | * | |
27 | * Permission to use, copy, modify, and distribute this software and | |
28 | * its documentation for any purpose and without fee is hereby granted, | |
29 | * provided that the above copyright notice appears in all copies and | |
30 | * that both the copyright notice and this permission notice appear in | |
31 | * supporting documentation. | |
32 | * | |
33 | * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE | |
34 | * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | |
35 | * FOR A PARTICULAR PURPOSE. | |
36 | * | |
37 | * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR | |
38 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | |
39 | * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, | |
40 | * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION | |
41 | * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
42 | */ | |
43 | /* | |
44 | * MkLinux | |
45 | */ | |
46 | ||
47 | #ifndef __PTHREAD_TSD_H__ | |
48 | #define __PTHREAD_TSD_H__ | |
49 | ||
50 | #ifndef __ASSEMBLER__ | |
51 | ||
52 | #include <System/machine/cpu_capabilities.h> | |
53 | #include <sys/cdefs.h> | |
54 | #include <TargetConditionals.h> | |
2546420a | 55 | #include <Availability.h> |
f1a1da6c A |
56 | #include <os/tsd.h> |
57 | #include <pthread/spinlock_private.h> | |
58 | ||
f1a1da6c A |
59 | /* Constant TSD slots for inline pthread_getspecific() usage. */ |
60 | ||
61 | /* Keys 0 - 9 are for Libsyscall/libplatform usage */ | |
c1f56ec9 A |
62 | #define _PTHREAD_TSD_SLOT_PTHREAD_SELF __TSD_THREAD_SELF |
63 | #define _PTHREAD_TSD_SLOT_ERRNO __TSD_ERRNO | |
64 | #define _PTHREAD_TSD_SLOT_MIG_REPLY __TSD_MIG_REPLY | |
65 | #define _PTHREAD_TSD_SLOT_MACH_THREAD_SELF __TSD_MACH_THREAD_SELF | |
66 | #define _PTHREAD_TSD_SLOT_PTHREAD_QOS_CLASS __TSD_THREAD_QOS_CLASS | |
67 | #define _PTHREAD_TSD_SLOT_RETURN_TO_KERNEL __TSD_RETURN_TO_KERNEL | |
68 | #define _PTHREAD_TSD_SLOT_PTR_MUNGE __TSD_PTR_MUNGE | |
69 | #define _PTHREAD_TSD_SLOT_MACH_SPECIAL_REPLY __TSD_MACH_SPECIAL_REPLY | |
70 | #define _PTHREAD_TSD_SLOT_SEMAPHORE_CACHE __TSD_SEMAPHORE_CACHE | |
71 | ||
72 | #define _PTHREAD_TSD_SLOT_PTHREAD_SELF_TYPE pthread_t | |
73 | #define _PTHREAD_TSD_SLOT_ERRNO_TYPE int * | |
74 | #define _PTHREAD_TSD_SLOT_MIG_REPLY_TYPE mach_port_t | |
75 | #define _PTHREAD_TSD_SLOT_MACH_THREAD_SELF_TYPE mach_port_t | |
76 | #define _PTHREAD_TSD_SLOT_PTHREAD_QOS_CLASS_TYPE pthread_priority_t | |
77 | #define _PTHREAD_TSD_SLOT_RETURN_TO_KERNEL_TYPE uintptr_t | |
78 | #define _PTHREAD_TSD_SLOT_PTR_MUNGE_TYPE uintptr_t | |
79 | #define _PTHREAD_TSD_SLOT_MACH_SPECIAL_REPLY_TYPE mach_port_t | |
80 | #define _PTHREAD_TSD_SLOT_SEMAPHORE_CACHE_TYPE semaphore_t | |
f1a1da6c | 81 | |
2546420a A |
82 | /* |
83 | * Windows 64-bit ABI bakes %gs relative accesses into its code in the same | |
84 | * range as our TSD keys. To allow some limited interoperability for code | |
85 | * targeting that ABI, we leave slots 6 and 11 unused. | |
235d2f0e A |
86 | * |
87 | * The Go runtime on x86_64 also uses this because their ABI doesn't reserve a | |
88 | * register for the TSD base. They were previously using an arbitrarily chosen | |
89 | * dynamic key and relying on being able to get it at runtime, but switched to | |
90 | * this slot to avoid issues with that approach. It's assumed that Go and | |
91 | * Windows code won't run in the same address space. | |
2546420a A |
92 | */ |
93 | //#define _PTHREAD_TSD_SLOT_RESERVED_WIN64 6 | |
94 | ||
f1a1da6c A |
95 | #define _PTHREAD_TSD_RESERVED_SLOT_COUNT _PTHREAD_TSD_RESERVED_SLOT_COUNT |
96 | ||
97 | /* Keys 10 - 29 are for Libc/Libsystem internal usage */ | |
98 | /* used as __pthread_tsd_first + Num */ | |
99 | #define __PTK_LIBC_LOCALE_KEY 10 | |
2546420a | 100 | //#define __PTK_LIBC_RESERVED_WIN64 11 |
f1a1da6c A |
101 | #define __PTK_LIBC_LOCALTIME_KEY 12 |
102 | #define __PTK_LIBC_GMTIME_KEY 13 | |
103 | #define __PTK_LIBC_GDTOA_BIGINT_KEY 14 | |
104 | #define __PTK_LIBC_PARSEFLOAT_KEY 15 | |
2546420a | 105 | #define __PTK_LIBC_TTYNAME_KEY 16 |
f1a1da6c A |
106 | /* for usage by dyld */ |
107 | #define __PTK_LIBC_DYLD_Unwind_SjLj_Key 18 | |
108 | ||
109 | /* Keys 20-29 for libdispatch usage */ | |
110 | #define __PTK_LIBDISPATCH_KEY0 20 | |
111 | #define __PTK_LIBDISPATCH_KEY1 21 | |
112 | #define __PTK_LIBDISPATCH_KEY2 22 | |
113 | #define __PTK_LIBDISPATCH_KEY3 23 | |
114 | #define __PTK_LIBDISPATCH_KEY4 24 | |
115 | #define __PTK_LIBDISPATCH_KEY5 25 | |
116 | #define __PTK_LIBDISPATCH_KEY6 26 | |
117 | #define __PTK_LIBDISPATCH_KEY7 27 | |
118 | #define __PTK_LIBDISPATCH_KEY8 28 | |
119 | #define __PTK_LIBDISPATCH_KEY9 29 | |
120 | ||
121 | /* Keys 30-255 for Non Libsystem usage */ | |
122 | ||
123 | /* Keys 30-39 for Graphic frameworks usage */ | |
124 | #define _PTHREAD_TSD_SLOT_OPENGL 30 /* backwards compat sake */ | |
125 | #define __PTK_FRAMEWORK_OPENGL_KEY 30 | |
126 | #define __PTK_FRAMEWORK_GRAPHICS_KEY1 31 | |
127 | #define __PTK_FRAMEWORK_GRAPHICS_KEY2 32 | |
128 | #define __PTK_FRAMEWORK_GRAPHICS_KEY3 33 | |
129 | #define __PTK_FRAMEWORK_GRAPHICS_KEY4 34 | |
130 | #define __PTK_FRAMEWORK_GRAPHICS_KEY5 35 | |
131 | #define __PTK_FRAMEWORK_GRAPHICS_KEY6 36 | |
132 | #define __PTK_FRAMEWORK_GRAPHICS_KEY7 37 | |
133 | #define __PTK_FRAMEWORK_GRAPHICS_KEY8 38 | |
134 | #define __PTK_FRAMEWORK_GRAPHICS_KEY9 39 | |
135 | ||
136 | /* Keys 40-49 for Objective-C runtime usage */ | |
137 | #define __PTK_FRAMEWORK_OBJC_KEY0 40 | |
138 | #define __PTK_FRAMEWORK_OBJC_KEY1 41 | |
139 | #define __PTK_FRAMEWORK_OBJC_KEY2 42 | |
140 | #define __PTK_FRAMEWORK_OBJC_KEY3 43 | |
141 | #define __PTK_FRAMEWORK_OBJC_KEY4 44 | |
142 | #define __PTK_FRAMEWORK_OBJC_KEY5 45 | |
143 | #define __PTK_FRAMEWORK_OBJC_KEY6 46 | |
144 | #define __PTK_FRAMEWORK_OBJC_KEY7 47 | |
145 | #define __PTK_FRAMEWORK_OBJC_KEY8 48 | |
146 | #define __PTK_FRAMEWORK_OBJC_KEY9 49 | |
147 | ||
148 | /* Keys 50-59 for Core Foundation usage */ | |
149 | #define __PTK_FRAMEWORK_COREFOUNDATION_KEY0 50 | |
150 | #define __PTK_FRAMEWORK_COREFOUNDATION_KEY1 51 | |
151 | #define __PTK_FRAMEWORK_COREFOUNDATION_KEY2 52 | |
152 | #define __PTK_FRAMEWORK_COREFOUNDATION_KEY3 53 | |
153 | #define __PTK_FRAMEWORK_COREFOUNDATION_KEY4 54 | |
154 | #define __PTK_FRAMEWORK_COREFOUNDATION_KEY5 55 | |
155 | #define __PTK_FRAMEWORK_COREFOUNDATION_KEY6 56 | |
156 | #define __PTK_FRAMEWORK_COREFOUNDATION_KEY7 57 | |
157 | #define __PTK_FRAMEWORK_COREFOUNDATION_KEY8 58 | |
158 | #define __PTK_FRAMEWORK_COREFOUNDATION_KEY9 59 | |
159 | ||
160 | /* Keys 60-69 for Foundation usage */ | |
161 | #define __PTK_FRAMEWORK_FOUNDATION_KEY0 60 | |
162 | #define __PTK_FRAMEWORK_FOUNDATION_KEY1 61 | |
163 | #define __PTK_FRAMEWORK_FOUNDATION_KEY2 62 | |
164 | #define __PTK_FRAMEWORK_FOUNDATION_KEY3 63 | |
165 | #define __PTK_FRAMEWORK_FOUNDATION_KEY4 64 | |
166 | #define __PTK_FRAMEWORK_FOUNDATION_KEY5 65 | |
167 | #define __PTK_FRAMEWORK_FOUNDATION_KEY6 66 | |
168 | #define __PTK_FRAMEWORK_FOUNDATION_KEY7 67 | |
169 | #define __PTK_FRAMEWORK_FOUNDATION_KEY8 68 | |
170 | #define __PTK_FRAMEWORK_FOUNDATION_KEY9 69 | |
171 | ||
172 | /* Keys 70-79 for Core Animation/QuartzCore usage */ | |
173 | #define __PTK_FRAMEWORK_QUARTZCORE_KEY0 70 | |
174 | #define __PTK_FRAMEWORK_QUARTZCORE_KEY1 71 | |
175 | #define __PTK_FRAMEWORK_QUARTZCORE_KEY2 72 | |
176 | #define __PTK_FRAMEWORK_QUARTZCORE_KEY3 73 | |
177 | #define __PTK_FRAMEWORK_QUARTZCORE_KEY4 74 | |
178 | #define __PTK_FRAMEWORK_QUARTZCORE_KEY5 75 | |
179 | #define __PTK_FRAMEWORK_QUARTZCORE_KEY6 76 | |
180 | #define __PTK_FRAMEWORK_QUARTZCORE_KEY7 77 | |
181 | #define __PTK_FRAMEWORK_QUARTZCORE_KEY8 78 | |
182 | #define __PTK_FRAMEWORK_QUARTZCORE_KEY9 79 | |
183 | ||
184 | ||
185 | /* Keys 80-89 for CoreData */ | |
186 | #define __PTK_FRAMEWORK_COREDATA_KEY0 80 | |
187 | #define __PTK_FRAMEWORK_COREDATA_KEY1 81 | |
188 | #define __PTK_FRAMEWORK_COREDATA_KEY2 82 | |
189 | #define __PTK_FRAMEWORK_COREDATA_KEY3 83 | |
190 | #define __PTK_FRAMEWORK_COREDATA_KEY4 84 | |
191 | #define __PTK_FRAMEWORK_COREDATA_KEY5 85 | |
192 | #define __PTK_FRAMEWORK_COREDATA_KEY6 86 | |
193 | #define __PTK_FRAMEWORK_COREDATA_KEY7 87 | |
194 | #define __PTK_FRAMEWORK_COREDATA_KEY8 88 | |
195 | #define __PTK_FRAMEWORK_COREDATA_KEY9 89 | |
196 | ||
197 | /* Keys 90-94 for JavaScriptCore Collection */ | |
198 | #define __PTK_FRAMEWORK_JAVASCRIPTCORE_KEY0 90 | |
199 | #define __PTK_FRAMEWORK_JAVASCRIPTCORE_KEY1 91 | |
200 | #define __PTK_FRAMEWORK_JAVASCRIPTCORE_KEY2 92 | |
201 | #define __PTK_FRAMEWORK_JAVASCRIPTCORE_KEY3 93 | |
202 | #define __PTK_FRAMEWORK_JAVASCRIPTCORE_KEY4 94 | |
203 | /* Keys 95 for CoreText */ | |
204 | #define __PTK_FRAMEWORK_CORETEXT_KEY0 95 | |
205 | ||
235d2f0e A |
206 | /* Keys 100-109 are for the Swift runtime */ |
207 | #define __PTK_FRAMEWORK_SWIFT_KEY0 100 | |
208 | #define __PTK_FRAMEWORK_SWIFT_KEY1 101 | |
209 | #define __PTK_FRAMEWORK_SWIFT_KEY2 102 | |
210 | #define __PTK_FRAMEWORK_SWIFT_KEY3 103 | |
211 | #define __PTK_FRAMEWORK_SWIFT_KEY4 104 | |
212 | #define __PTK_FRAMEWORK_SWIFT_KEY5 105 | |
213 | #define __PTK_FRAMEWORK_SWIFT_KEY6 106 | |
214 | #define __PTK_FRAMEWORK_SWIFT_KEY7 107 | |
215 | #define __PTK_FRAMEWORK_SWIFT_KEY8 108 | |
216 | #define __PTK_FRAMEWORK_SWIFT_KEY9 109 | |
217 | ||
c1f56ec9 A |
218 | /* Keys 110-115 for libmalloc */ |
219 | #define __PTK_LIBMALLOC_KEY0 110 | |
220 | #define __PTK_LIBMALLOC_KEY1 111 | |
221 | #define __PTK_LIBMALLOC_KEY2 112 | |
222 | #define __PTK_LIBMALLOC_KEY3 113 | |
223 | #define __PTK_LIBMALLOC_KEY4 114 | |
224 | ||
225 | /* Keys 115-120 for libdispatch workgroups */ | |
226 | #define __PTK_LIBDISPATCH_WORKGROUP_KEY0 115 | |
227 | #define __PTK_LIBDISPATCH_WORKGROUP_KEY1 116 | |
228 | #define __PTK_LIBDISPATCH_WORKGROUP_KEY2 117 | |
229 | #define __PTK_LIBDISPATCH_WORKGROUP_KEY3 118 | |
230 | #define __PTK_LIBDISPATCH_WORKGROUP_KEY4 119 | |
231 | ||
c6e5f90c A |
232 | /* Keys 190 - 194 are for the use of PerfUtils */ |
233 | #define __PTK_PERF_UTILS_KEY0 190 | |
234 | #define __PTK_PERF_UTILS_KEY1 191 | |
235 | #define __PTK_PERF_UTILS_KEY2 192 | |
236 | #define __PTK_PERF_UTILS_KEY3 193 | |
237 | #define __PTK_PERF_UTILS_KEY4 194 | |
238 | ||
f1a1da6c A |
239 | /* Keys 210 - 229 are for libSystem usage within the iOS Simulator */ |
240 | /* They are offset from their corresponding libSystem keys by 200 */ | |
241 | #define __PTK_LIBC_SIM_LOCALE_KEY 210 | |
242 | #define __PTK_LIBC_SIM_TTYNAME_KEY 211 | |
243 | #define __PTK_LIBC_SIM_LOCALTIME_KEY 212 | |
244 | #define __PTK_LIBC_SIM_GMTIME_KEY 213 | |
245 | #define __PTK_LIBC_SIM_GDTOA_BIGINT_KEY 214 | |
246 | #define __PTK_LIBC_SIM_PARSEFLOAT_KEY 215 | |
247 | ||
248 | __BEGIN_DECLS | |
249 | ||
250 | extern void *pthread_getspecific(unsigned long); | |
251 | extern int pthread_setspecific(unsigned long, const void *); | |
252 | /* setup destructor function for static key as it is not created with pthread_key_create() */ | |
253 | extern int pthread_key_init_np(int, void (*)(void *)); | |
254 | ||
a0619f9c | 255 | __API_AVAILABLE(macos(10.12), ios(10.0), tvos(10.0), watchos(3.0)) |
2546420a A |
256 | extern int _pthread_setspecific_static(unsigned long, void *); |
257 | ||
f1a1da6c A |
258 | #if PTHREAD_LAYOUT_SPI |
259 | ||
260 | /* SPI intended for CoreSymbolication only */ | |
261 | ||
a0619f9c | 262 | __API_AVAILABLE(macos(10.10), ios(8.0)) |
f1a1da6c A |
263 | extern const struct pthread_layout_offsets_s { |
264 | // always add new fields at the end | |
265 | const uint16_t plo_version; | |
266 | // either of the next two fields may be 0; use whichever is set | |
267 | // bytes from pthread_t to base of tsd | |
268 | const uint16_t plo_pthread_tsd_base_offset; | |
269 | // bytes from pthread_t to a pointer to base of tsd | |
270 | const uint16_t plo_pthread_tsd_base_address_offset; | |
271 | const uint16_t plo_pthread_tsd_entry_size; | |
272 | } pthread_layout_offsets; | |
273 | ||
274 | #endif // PTHREAD_LAYOUT_SPI | |
f1a1da6c A |
275 | |
276 | __header_always_inline int | |
277 | _pthread_has_direct_tsd(void) | |
278 | { | |
2546420a | 279 | #if TARGET_IPHONE_SIMULATOR |
f1a1da6c | 280 | return 0; |
2546420a | 281 | #else |
f1a1da6c | 282 | return 1; |
2546420a | 283 | #endif |
f1a1da6c A |
284 | } |
285 | ||
286 | /* To be used with static constant keys only */ | |
287 | __header_always_inline void * | |
288 | _pthread_getspecific_direct(unsigned long slot) | |
289 | { | |
2546420a A |
290 | #if TARGET_IPHONE_SIMULATOR |
291 | return pthread_getspecific(slot); | |
292 | #else | |
f1a1da6c | 293 | return _os_tsd_get_direct(slot); |
2546420a | 294 | #endif |
f1a1da6c A |
295 | } |
296 | ||
2546420a A |
297 | /* To be used with static constant keys only, assumes destructor is |
298 | * already setup (with pthread_key_init_np) */ | |
f1a1da6c A |
299 | __header_always_inline int |
300 | _pthread_setspecific_direct(unsigned long slot, void * val) | |
301 | { | |
2546420a A |
302 | #if TARGET_IPHONE_SIMULATOR |
303 | return _pthread_setspecific_static(slot, val); | |
304 | #else | |
f1a1da6c | 305 | return _os_tsd_set_direct(slot, val); |
2546420a | 306 | #endif |
f1a1da6c A |
307 | } |
308 | ||
2546420a | 309 | __END_DECLS |
f1a1da6c A |
310 | |
311 | #endif /* ! __ASSEMBLER__ */ | |
312 | #endif /* __PTHREAD_TSD_H__ */ |