2 * Copyright (c) 2003-2013 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
24 * Copyright 1996 1995 by Open Software Foundation, Inc. 1997 1996 1995 1994 1993 1992 1991
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.
33 * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
34 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
35 * FOR A PARTICULAR PURPOSE.
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.
47 #ifndef __PTHREAD_TSD_H__
48 #define __PTHREAD_TSD_H__
52 #include <System/machine/cpu_capabilities.h>
53 #include <sys/cdefs.h>
54 #include <TargetConditionals.h>
55 #include <Availability.h>
57 #include <pthread/spinlock_private.h>
59 #ifndef __TSD_MACH_THREAD_SELF
60 #define __TSD_MACH_THREAD_SELF 3
63 #ifndef __TSD_THREAD_QOS_CLASS
64 #define __TSD_THREAD_QOS_CLASS 4
67 /* Constant TSD slots for inline pthread_getspecific() usage. */
69 /* Keys 0 - 9 are for Libsyscall/libplatform usage */
70 #define _PTHREAD_TSD_SLOT_PTHREAD_SELF __TSD_THREAD_SELF
71 #define _PTHREAD_TSD_SLOT_ERRNO __TSD_ERRNO
72 #define _PTHREAD_TSD_SLOT_MIG_REPLY __TSD_MIG_REPLY
73 #define _PTHREAD_TSD_SLOT_MACH_THREAD_SELF __TSD_MACH_THREAD_SELF
74 #define _PTHREAD_TSD_SLOT_PTHREAD_QOS_CLASS __TSD_THREAD_QOS_CLASS
75 //#define _PTHREAD_TSD_SLOT_SEMAPHORE_CACHE__TSD_SEMAPHORE_CACHE
78 * Windows 64-bit ABI bakes %gs relative accesses into its code in the same
79 * range as our TSD keys. To allow some limited interoperability for code
80 * targeting that ABI, we leave slots 6 and 11 unused.
82 //#define _PTHREAD_TSD_SLOT_RESERVED_WIN64 6
84 #define _PTHREAD_TSD_RESERVED_SLOT_COUNT _PTHREAD_TSD_RESERVED_SLOT_COUNT
86 /* Keys 10 - 29 are for Libc/Libsystem internal usage */
87 /* used as __pthread_tsd_first + Num */
88 #define __PTK_LIBC_LOCALE_KEY 10
89 //#define __PTK_LIBC_RESERVED_WIN64 11
90 #define __PTK_LIBC_LOCALTIME_KEY 12
91 #define __PTK_LIBC_GMTIME_KEY 13
92 #define __PTK_LIBC_GDTOA_BIGINT_KEY 14
93 #define __PTK_LIBC_PARSEFLOAT_KEY 15
94 #define __PTK_LIBC_TTYNAME_KEY 16
95 /* for usage by dyld */
96 #define __PTK_LIBC_DYLD_Unwind_SjLj_Key 18
98 /* Keys 20-29 for libdispatch usage */
99 #define __PTK_LIBDISPATCH_KEY0 20
100 #define __PTK_LIBDISPATCH_KEY1 21
101 #define __PTK_LIBDISPATCH_KEY2 22
102 #define __PTK_LIBDISPATCH_KEY3 23
103 #define __PTK_LIBDISPATCH_KEY4 24
104 #define __PTK_LIBDISPATCH_KEY5 25
105 #define __PTK_LIBDISPATCH_KEY6 26
106 #define __PTK_LIBDISPATCH_KEY7 27
107 #define __PTK_LIBDISPATCH_KEY8 28
108 #define __PTK_LIBDISPATCH_KEY9 29
110 /* Keys 30-255 for Non Libsystem usage */
112 /* Keys 30-39 for Graphic frameworks usage */
113 #define _PTHREAD_TSD_SLOT_OPENGL 30 /* backwards compat sake */
114 #define __PTK_FRAMEWORK_OPENGL_KEY 30
115 #define __PTK_FRAMEWORK_GRAPHICS_KEY1 31
116 #define __PTK_FRAMEWORK_GRAPHICS_KEY2 32
117 #define __PTK_FRAMEWORK_GRAPHICS_KEY3 33
118 #define __PTK_FRAMEWORK_GRAPHICS_KEY4 34
119 #define __PTK_FRAMEWORK_GRAPHICS_KEY5 35
120 #define __PTK_FRAMEWORK_GRAPHICS_KEY6 36
121 #define __PTK_FRAMEWORK_GRAPHICS_KEY7 37
122 #define __PTK_FRAMEWORK_GRAPHICS_KEY8 38
123 #define __PTK_FRAMEWORK_GRAPHICS_KEY9 39
125 /* Keys 40-49 for Objective-C runtime usage */
126 #define __PTK_FRAMEWORK_OBJC_KEY0 40
127 #define __PTK_FRAMEWORK_OBJC_KEY1 41
128 #define __PTK_FRAMEWORK_OBJC_KEY2 42
129 #define __PTK_FRAMEWORK_OBJC_KEY3 43
130 #define __PTK_FRAMEWORK_OBJC_KEY4 44
131 #define __PTK_FRAMEWORK_OBJC_KEY5 45
132 #define __PTK_FRAMEWORK_OBJC_KEY6 46
133 #define __PTK_FRAMEWORK_OBJC_KEY7 47
134 #define __PTK_FRAMEWORK_OBJC_KEY8 48
135 #define __PTK_FRAMEWORK_OBJC_KEY9 49
137 /* Keys 50-59 for Core Foundation usage */
138 #define __PTK_FRAMEWORK_COREFOUNDATION_KEY0 50
139 #define __PTK_FRAMEWORK_COREFOUNDATION_KEY1 51
140 #define __PTK_FRAMEWORK_COREFOUNDATION_KEY2 52
141 #define __PTK_FRAMEWORK_COREFOUNDATION_KEY3 53
142 #define __PTK_FRAMEWORK_COREFOUNDATION_KEY4 54
143 #define __PTK_FRAMEWORK_COREFOUNDATION_KEY5 55
144 #define __PTK_FRAMEWORK_COREFOUNDATION_KEY6 56
145 #define __PTK_FRAMEWORK_COREFOUNDATION_KEY7 57
146 #define __PTK_FRAMEWORK_COREFOUNDATION_KEY8 58
147 #define __PTK_FRAMEWORK_COREFOUNDATION_KEY9 59
149 /* Keys 60-69 for Foundation usage */
150 #define __PTK_FRAMEWORK_FOUNDATION_KEY0 60
151 #define __PTK_FRAMEWORK_FOUNDATION_KEY1 61
152 #define __PTK_FRAMEWORK_FOUNDATION_KEY2 62
153 #define __PTK_FRAMEWORK_FOUNDATION_KEY3 63
154 #define __PTK_FRAMEWORK_FOUNDATION_KEY4 64
155 #define __PTK_FRAMEWORK_FOUNDATION_KEY5 65
156 #define __PTK_FRAMEWORK_FOUNDATION_KEY6 66
157 #define __PTK_FRAMEWORK_FOUNDATION_KEY7 67
158 #define __PTK_FRAMEWORK_FOUNDATION_KEY8 68
159 #define __PTK_FRAMEWORK_FOUNDATION_KEY9 69
161 /* Keys 70-79 for Core Animation/QuartzCore usage */
162 #define __PTK_FRAMEWORK_QUARTZCORE_KEY0 70
163 #define __PTK_FRAMEWORK_QUARTZCORE_KEY1 71
164 #define __PTK_FRAMEWORK_QUARTZCORE_KEY2 72
165 #define __PTK_FRAMEWORK_QUARTZCORE_KEY3 73
166 #define __PTK_FRAMEWORK_QUARTZCORE_KEY4 74
167 #define __PTK_FRAMEWORK_QUARTZCORE_KEY5 75
168 #define __PTK_FRAMEWORK_QUARTZCORE_KEY6 76
169 #define __PTK_FRAMEWORK_QUARTZCORE_KEY7 77
170 #define __PTK_FRAMEWORK_QUARTZCORE_KEY8 78
171 #define __PTK_FRAMEWORK_QUARTZCORE_KEY9 79
174 /* Keys 80-89 for CoreData */
175 #define __PTK_FRAMEWORK_COREDATA_KEY0 80
176 #define __PTK_FRAMEWORK_COREDATA_KEY1 81
177 #define __PTK_FRAMEWORK_COREDATA_KEY2 82
178 #define __PTK_FRAMEWORK_COREDATA_KEY3 83
179 #define __PTK_FRAMEWORK_COREDATA_KEY4 84
180 #define __PTK_FRAMEWORK_COREDATA_KEY5 85
181 #define __PTK_FRAMEWORK_COREDATA_KEY6 86
182 #define __PTK_FRAMEWORK_COREDATA_KEY7 87
183 #define __PTK_FRAMEWORK_COREDATA_KEY8 88
184 #define __PTK_FRAMEWORK_COREDATA_KEY9 89
186 /* Keys 90-94 for JavaScriptCore Collection */
187 #define __PTK_FRAMEWORK_JAVASCRIPTCORE_KEY0 90
188 #define __PTK_FRAMEWORK_JAVASCRIPTCORE_KEY1 91
189 #define __PTK_FRAMEWORK_JAVASCRIPTCORE_KEY2 92
190 #define __PTK_FRAMEWORK_JAVASCRIPTCORE_KEY3 93
191 #define __PTK_FRAMEWORK_JAVASCRIPTCORE_KEY4 94
192 /* Keys 95 for CoreText */
193 #define __PTK_FRAMEWORK_CORETEXT_KEY0 95
195 /* Keys 210 - 229 are for libSystem usage within the iOS Simulator */
196 /* They are offset from their corresponding libSystem keys by 200 */
197 #define __PTK_LIBC_SIM_LOCALE_KEY 210
198 #define __PTK_LIBC_SIM_TTYNAME_KEY 211
199 #define __PTK_LIBC_SIM_LOCALTIME_KEY 212
200 #define __PTK_LIBC_SIM_GMTIME_KEY 213
201 #define __PTK_LIBC_SIM_GDTOA_BIGINT_KEY 214
202 #define __PTK_LIBC_SIM_PARSEFLOAT_KEY 215
206 extern void *pthread_getspecific(unsigned long);
207 extern int pthread_setspecific(unsigned long, const void *);
208 /* setup destructor function for static key as it is not created with pthread_key_create() */
209 extern int pthread_key_init_np(int, void (*)(void *));
211 __OSX_AVAILABLE(10.12)
212 __IOS_AVAILABLE(10.0)
213 __TVOS_AVAILABLE(10.0)
214 __WATCHOS_AVAILABLE(3.0)
215 extern int _pthread_setspecific_static(unsigned long, void *);
217 #if PTHREAD_LAYOUT_SPI
219 /* SPI intended for CoreSymbolication only */
221 __OSX_AVAILABLE_STARTING(__MAC_10_10
,__IPHONE_8_0
)
222 extern const struct pthread_layout_offsets_s
{
223 // always add new fields at the end
224 const uint16_t plo_version
;
225 // either of the next two fields may be 0; use whichever is set
226 // bytes from pthread_t to base of tsd
227 const uint16_t plo_pthread_tsd_base_offset
;
228 // bytes from pthread_t to a pointer to base of tsd
229 const uint16_t plo_pthread_tsd_base_address_offset
;
230 const uint16_t plo_pthread_tsd_entry_size
;
231 } pthread_layout_offsets
;
233 #endif // PTHREAD_LAYOUT_SPI
235 __header_always_inline
int
236 _pthread_has_direct_tsd(void)
238 #if TARGET_IPHONE_SIMULATOR
245 /* To be used with static constant keys only */
246 __header_always_inline
void *
247 _pthread_getspecific_direct(unsigned long slot
)
249 #if TARGET_IPHONE_SIMULATOR
250 return pthread_getspecific(slot
);
252 return _os_tsd_get_direct(slot
);
256 /* To be used with static constant keys only, assumes destructor is
257 * already setup (with pthread_key_init_np) */
258 __header_always_inline
int
259 _pthread_setspecific_direct(unsigned long slot
, void * val
)
261 #if TARGET_IPHONE_SIMULATOR
262 return _pthread_setspecific_static(slot
, val
);
264 return _os_tsd_set_direct(slot
, val
);
270 #endif /* ! __ASSEMBLER__ */
271 #endif /* __PTHREAD_TSD_H__ */