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