]> git.saurik.com Git - apple/libpthread.git/blob - private/tsd_private.h
libpthread-416.60.2.tar.gz
[apple/libpthread.git] / private / tsd_private.h
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>
55 #include <Availability.h>
56 #include <os/tsd.h>
57 #include <pthread/spinlock_private.h>
58
59 #ifndef __TSD_MACH_THREAD_SELF
60 #define __TSD_MACH_THREAD_SELF 3
61 #endif
62
63 #ifndef __TSD_THREAD_QOS_CLASS
64 #define __TSD_THREAD_QOS_CLASS 4
65 #endif
66
67 #ifndef __TSD_RETURN_TO_KERNEL
68 #define __TSD_RETURN_TO_KERNEL 5
69 #endif
70
71 #ifndef __TSD_PTR_MUNGE
72 #define __TSD_PTR_MUNGE 7
73 #endif
74
75 #ifndef __TSD_MACH_SPECIAL_REPLY
76 #define __TSD_MACH_SPECIAL_REPLY 8
77 #endif
78
79 /* Constant TSD slots for inline pthread_getspecific() usage. */
80
81 /* Keys 0 - 9 are for Libsyscall/libplatform usage */
82 #define _PTHREAD_TSD_SLOT_PTHREAD_SELF __TSD_THREAD_SELF
83 #define _PTHREAD_TSD_SLOT_ERRNO __TSD_ERRNO
84 #define _PTHREAD_TSD_SLOT_MIG_REPLY __TSD_MIG_REPLY
85 #define _PTHREAD_TSD_SLOT_MACH_THREAD_SELF __TSD_MACH_THREAD_SELF
86 #define _PTHREAD_TSD_SLOT_PTHREAD_QOS_CLASS __TSD_THREAD_QOS_CLASS
87 #define _PTHREAD_TSD_SLOT_RETURN_TO_KERNEL __TSD_RETURN_TO_KERNEL
88 #define _PTHREAD_TSD_SLOT_PTR_MUNGE __TSD_PTR_MUNGE
89 #define _PTHREAD_TSD_SLOT_MACH_SPECIAL_REPLY __TSD_MACH_SPECIAL_REPLY
90 //#define _PTHREAD_TSD_SLOT_SEMAPHORE_CACHE __TSD_SEMAPHORE_CACHE
91
92 /*
93 * Windows 64-bit ABI bakes %gs relative accesses into its code in the same
94 * range as our TSD keys. To allow some limited interoperability for code
95 * targeting that ABI, we leave slots 6 and 11 unused.
96 *
97 * The Go runtime on x86_64 also uses this because their ABI doesn't reserve a
98 * register for the TSD base. They were previously using an arbitrarily chosen
99 * dynamic key and relying on being able to get it at runtime, but switched to
100 * this slot to avoid issues with that approach. It's assumed that Go and
101 * Windows code won't run in the same address space.
102 */
103 //#define _PTHREAD_TSD_SLOT_RESERVED_WIN64 6
104
105 #define _PTHREAD_TSD_RESERVED_SLOT_COUNT _PTHREAD_TSD_RESERVED_SLOT_COUNT
106
107 /* Keys 10 - 29 are for Libc/Libsystem internal usage */
108 /* used as __pthread_tsd_first + Num */
109 #define __PTK_LIBC_LOCALE_KEY 10
110 //#define __PTK_LIBC_RESERVED_WIN64 11
111 #define __PTK_LIBC_LOCALTIME_KEY 12
112 #define __PTK_LIBC_GMTIME_KEY 13
113 #define __PTK_LIBC_GDTOA_BIGINT_KEY 14
114 #define __PTK_LIBC_PARSEFLOAT_KEY 15
115 #define __PTK_LIBC_TTYNAME_KEY 16
116 /* for usage by dyld */
117 #define __PTK_LIBC_DYLD_Unwind_SjLj_Key 18
118
119 /* Keys 20-29 for libdispatch usage */
120 #define __PTK_LIBDISPATCH_KEY0 20
121 #define __PTK_LIBDISPATCH_KEY1 21
122 #define __PTK_LIBDISPATCH_KEY2 22
123 #define __PTK_LIBDISPATCH_KEY3 23
124 #define __PTK_LIBDISPATCH_KEY4 24
125 #define __PTK_LIBDISPATCH_KEY5 25
126 #define __PTK_LIBDISPATCH_KEY6 26
127 #define __PTK_LIBDISPATCH_KEY7 27
128 #define __PTK_LIBDISPATCH_KEY8 28
129 #define __PTK_LIBDISPATCH_KEY9 29
130
131 /* Keys 30-255 for Non Libsystem usage */
132
133 /* Keys 30-39 for Graphic frameworks usage */
134 #define _PTHREAD_TSD_SLOT_OPENGL 30 /* backwards compat sake */
135 #define __PTK_FRAMEWORK_OPENGL_KEY 30
136 #define __PTK_FRAMEWORK_GRAPHICS_KEY1 31
137 #define __PTK_FRAMEWORK_GRAPHICS_KEY2 32
138 #define __PTK_FRAMEWORK_GRAPHICS_KEY3 33
139 #define __PTK_FRAMEWORK_GRAPHICS_KEY4 34
140 #define __PTK_FRAMEWORK_GRAPHICS_KEY5 35
141 #define __PTK_FRAMEWORK_GRAPHICS_KEY6 36
142 #define __PTK_FRAMEWORK_GRAPHICS_KEY7 37
143 #define __PTK_FRAMEWORK_GRAPHICS_KEY8 38
144 #define __PTK_FRAMEWORK_GRAPHICS_KEY9 39
145
146 /* Keys 40-49 for Objective-C runtime usage */
147 #define __PTK_FRAMEWORK_OBJC_KEY0 40
148 #define __PTK_FRAMEWORK_OBJC_KEY1 41
149 #define __PTK_FRAMEWORK_OBJC_KEY2 42
150 #define __PTK_FRAMEWORK_OBJC_KEY3 43
151 #define __PTK_FRAMEWORK_OBJC_KEY4 44
152 #define __PTK_FRAMEWORK_OBJC_KEY5 45
153 #define __PTK_FRAMEWORK_OBJC_KEY6 46
154 #define __PTK_FRAMEWORK_OBJC_KEY7 47
155 #define __PTK_FRAMEWORK_OBJC_KEY8 48
156 #define __PTK_FRAMEWORK_OBJC_KEY9 49
157
158 /* Keys 50-59 for Core Foundation usage */
159 #define __PTK_FRAMEWORK_COREFOUNDATION_KEY0 50
160 #define __PTK_FRAMEWORK_COREFOUNDATION_KEY1 51
161 #define __PTK_FRAMEWORK_COREFOUNDATION_KEY2 52
162 #define __PTK_FRAMEWORK_COREFOUNDATION_KEY3 53
163 #define __PTK_FRAMEWORK_COREFOUNDATION_KEY4 54
164 #define __PTK_FRAMEWORK_COREFOUNDATION_KEY5 55
165 #define __PTK_FRAMEWORK_COREFOUNDATION_KEY6 56
166 #define __PTK_FRAMEWORK_COREFOUNDATION_KEY7 57
167 #define __PTK_FRAMEWORK_COREFOUNDATION_KEY8 58
168 #define __PTK_FRAMEWORK_COREFOUNDATION_KEY9 59
169
170 /* Keys 60-69 for Foundation usage */
171 #define __PTK_FRAMEWORK_FOUNDATION_KEY0 60
172 #define __PTK_FRAMEWORK_FOUNDATION_KEY1 61
173 #define __PTK_FRAMEWORK_FOUNDATION_KEY2 62
174 #define __PTK_FRAMEWORK_FOUNDATION_KEY3 63
175 #define __PTK_FRAMEWORK_FOUNDATION_KEY4 64
176 #define __PTK_FRAMEWORK_FOUNDATION_KEY5 65
177 #define __PTK_FRAMEWORK_FOUNDATION_KEY6 66
178 #define __PTK_FRAMEWORK_FOUNDATION_KEY7 67
179 #define __PTK_FRAMEWORK_FOUNDATION_KEY8 68
180 #define __PTK_FRAMEWORK_FOUNDATION_KEY9 69
181
182 /* Keys 70-79 for Core Animation/QuartzCore usage */
183 #define __PTK_FRAMEWORK_QUARTZCORE_KEY0 70
184 #define __PTK_FRAMEWORK_QUARTZCORE_KEY1 71
185 #define __PTK_FRAMEWORK_QUARTZCORE_KEY2 72
186 #define __PTK_FRAMEWORK_QUARTZCORE_KEY3 73
187 #define __PTK_FRAMEWORK_QUARTZCORE_KEY4 74
188 #define __PTK_FRAMEWORK_QUARTZCORE_KEY5 75
189 #define __PTK_FRAMEWORK_QUARTZCORE_KEY6 76
190 #define __PTK_FRAMEWORK_QUARTZCORE_KEY7 77
191 #define __PTK_FRAMEWORK_QUARTZCORE_KEY8 78
192 #define __PTK_FRAMEWORK_QUARTZCORE_KEY9 79
193
194
195 /* Keys 80-89 for CoreData */
196 #define __PTK_FRAMEWORK_COREDATA_KEY0 80
197 #define __PTK_FRAMEWORK_COREDATA_KEY1 81
198 #define __PTK_FRAMEWORK_COREDATA_KEY2 82
199 #define __PTK_FRAMEWORK_COREDATA_KEY3 83
200 #define __PTK_FRAMEWORK_COREDATA_KEY4 84
201 #define __PTK_FRAMEWORK_COREDATA_KEY5 85
202 #define __PTK_FRAMEWORK_COREDATA_KEY6 86
203 #define __PTK_FRAMEWORK_COREDATA_KEY7 87
204 #define __PTK_FRAMEWORK_COREDATA_KEY8 88
205 #define __PTK_FRAMEWORK_COREDATA_KEY9 89
206
207 /* Keys 90-94 for JavaScriptCore Collection */
208 #define __PTK_FRAMEWORK_JAVASCRIPTCORE_KEY0 90
209 #define __PTK_FRAMEWORK_JAVASCRIPTCORE_KEY1 91
210 #define __PTK_FRAMEWORK_JAVASCRIPTCORE_KEY2 92
211 #define __PTK_FRAMEWORK_JAVASCRIPTCORE_KEY3 93
212 #define __PTK_FRAMEWORK_JAVASCRIPTCORE_KEY4 94
213 /* Keys 95 for CoreText */
214 #define __PTK_FRAMEWORK_CORETEXT_KEY0 95
215
216 /* Keys 100-109 are for the Swift runtime */
217 #define __PTK_FRAMEWORK_SWIFT_KEY0 100
218 #define __PTK_FRAMEWORK_SWIFT_KEY1 101
219 #define __PTK_FRAMEWORK_SWIFT_KEY2 102
220 #define __PTK_FRAMEWORK_SWIFT_KEY3 103
221 #define __PTK_FRAMEWORK_SWIFT_KEY4 104
222 #define __PTK_FRAMEWORK_SWIFT_KEY5 105
223 #define __PTK_FRAMEWORK_SWIFT_KEY6 106
224 #define __PTK_FRAMEWORK_SWIFT_KEY7 107
225 #define __PTK_FRAMEWORK_SWIFT_KEY8 108
226 #define __PTK_FRAMEWORK_SWIFT_KEY9 109
227
228 /* Keys 190 - 194 are for the use of PerfUtils */
229 #define __PTK_PERF_UTILS_KEY0 190
230 #define __PTK_PERF_UTILS_KEY1 191
231 #define __PTK_PERF_UTILS_KEY2 192
232 #define __PTK_PERF_UTILS_KEY3 193
233 #define __PTK_PERF_UTILS_KEY4 194
234
235 /* Keys 210 - 229 are for libSystem usage within the iOS Simulator */
236 /* They are offset from their corresponding libSystem keys by 200 */
237 #define __PTK_LIBC_SIM_LOCALE_KEY 210
238 #define __PTK_LIBC_SIM_TTYNAME_KEY 211
239 #define __PTK_LIBC_SIM_LOCALTIME_KEY 212
240 #define __PTK_LIBC_SIM_GMTIME_KEY 213
241 #define __PTK_LIBC_SIM_GDTOA_BIGINT_KEY 214
242 #define __PTK_LIBC_SIM_PARSEFLOAT_KEY 215
243
244 __BEGIN_DECLS
245
246 extern void *pthread_getspecific(unsigned long);
247 extern int pthread_setspecific(unsigned long, const void *);
248 /* setup destructor function for static key as it is not created with pthread_key_create() */
249 extern int pthread_key_init_np(int, void (*)(void *));
250
251 __API_AVAILABLE(macos(10.12), ios(10.0), tvos(10.0), watchos(3.0))
252 extern int _pthread_setspecific_static(unsigned long, void *);
253
254 #if PTHREAD_LAYOUT_SPI
255
256 /* SPI intended for CoreSymbolication only */
257
258 __API_AVAILABLE(macos(10.10), ios(8.0))
259 extern const struct pthread_layout_offsets_s {
260 // always add new fields at the end
261 const uint16_t plo_version;
262 // either of the next two fields may be 0; use whichever is set
263 // bytes from pthread_t to base of tsd
264 const uint16_t plo_pthread_tsd_base_offset;
265 // bytes from pthread_t to a pointer to base of tsd
266 const uint16_t plo_pthread_tsd_base_address_offset;
267 const uint16_t plo_pthread_tsd_entry_size;
268 } pthread_layout_offsets;
269
270 #endif // PTHREAD_LAYOUT_SPI
271
272 __header_always_inline int
273 _pthread_has_direct_tsd(void)
274 {
275 #if TARGET_IPHONE_SIMULATOR
276 return 0;
277 #else
278 return 1;
279 #endif
280 }
281
282 /* To be used with static constant keys only */
283 __header_always_inline void *
284 _pthread_getspecific_direct(unsigned long slot)
285 {
286 #if TARGET_IPHONE_SIMULATOR
287 return pthread_getspecific(slot);
288 #else
289 return _os_tsd_get_direct(slot);
290 #endif
291 }
292
293 /* To be used with static constant keys only, assumes destructor is
294 * already setup (with pthread_key_init_np) */
295 __header_always_inline int
296 _pthread_setspecific_direct(unsigned long slot, void * val)
297 {
298 #if TARGET_IPHONE_SIMULATOR
299 return _pthread_setspecific_static(slot, val);
300 #else
301 return _os_tsd_set_direct(slot, val);
302 #endif
303 }
304
305 __END_DECLS
306
307 #endif /* ! __ASSEMBLER__ */
308 #endif /* __PTHREAD_TSD_H__ */