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>
56 #include <pthread/spinlock_private.h>
58 #ifndef __TSD_MACH_THREAD_SELF
59 #define __TSD_MACH_THREAD_SELF 3
62 #ifndef __TSD_THREAD_QOS_CLASS
63 #define __TSD_THREAD_QOS_CLASS 4
66 /* Constant TSD slots for inline pthread_getspecific() usage. */
68 /* Keys 0 - 9 are for Libsyscall/libplatform usage */
69 #define _PTHREAD_TSD_SLOT_PTHREAD_SELF __TSD_THREAD_SELF
70 #define _PTHREAD_TSD_SLOT_ERRNO __TSD_ERRNO
71 #define _PTHREAD_TSD_SLOT_MIG_REPLY __TSD_MIG_REPLY
72 #define _PTHREAD_TSD_SLOT_MACH_THREAD_SELF __TSD_MACH_THREAD_SELF
73 #define _PTHREAD_TSD_SLOT_PTHREAD_QOS_CLASS __TSD_THREAD_QOS_CLASS
74 //#define _PTHREAD_TSD_SLOT_SEMAPHORE_CACHE__TSD_SEMAPHORE_CACHE
76 #define _PTHREAD_TSD_RESERVED_SLOT_COUNT _PTHREAD_TSD_RESERVED_SLOT_COUNT
78 /* Keys 10 - 29 are for Libc/Libsystem internal usage */
79 /* used as __pthread_tsd_first + Num */
80 #define __PTK_LIBC_LOCALE_KEY 10
81 #define __PTK_LIBC_TTYNAME_KEY 11
82 #define __PTK_LIBC_LOCALTIME_KEY 12
83 #define __PTK_LIBC_GMTIME_KEY 13
84 #define __PTK_LIBC_GDTOA_BIGINT_KEY 14
85 #define __PTK_LIBC_PARSEFLOAT_KEY 15
86 /* for usage by dyld */
87 #define __PTK_LIBC_DYLD_Unwind_SjLj_Key 18
89 /* Keys 20-29 for libdispatch usage */
90 #define __PTK_LIBDISPATCH_KEY0 20
91 #define __PTK_LIBDISPATCH_KEY1 21
92 #define __PTK_LIBDISPATCH_KEY2 22
93 #define __PTK_LIBDISPATCH_KEY3 23
94 #define __PTK_LIBDISPATCH_KEY4 24
95 #define __PTK_LIBDISPATCH_KEY5 25
96 #define __PTK_LIBDISPATCH_KEY6 26
97 #define __PTK_LIBDISPATCH_KEY7 27
98 #define __PTK_LIBDISPATCH_KEY8 28
99 #define __PTK_LIBDISPATCH_KEY9 29
101 /* Keys 30-255 for Non Libsystem usage */
103 /* Keys 30-39 for Graphic frameworks usage */
104 #define _PTHREAD_TSD_SLOT_OPENGL 30 /* backwards compat sake */
105 #define __PTK_FRAMEWORK_OPENGL_KEY 30
106 #define __PTK_FRAMEWORK_GRAPHICS_KEY1 31
107 #define __PTK_FRAMEWORK_GRAPHICS_KEY2 32
108 #define __PTK_FRAMEWORK_GRAPHICS_KEY3 33
109 #define __PTK_FRAMEWORK_GRAPHICS_KEY4 34
110 #define __PTK_FRAMEWORK_GRAPHICS_KEY5 35
111 #define __PTK_FRAMEWORK_GRAPHICS_KEY6 36
112 #define __PTK_FRAMEWORK_GRAPHICS_KEY7 37
113 #define __PTK_FRAMEWORK_GRAPHICS_KEY8 38
114 #define __PTK_FRAMEWORK_GRAPHICS_KEY9 39
116 /* Keys 40-49 for Objective-C runtime usage */
117 #define __PTK_FRAMEWORK_OBJC_KEY0 40
118 #define __PTK_FRAMEWORK_OBJC_KEY1 41
119 #define __PTK_FRAMEWORK_OBJC_KEY2 42
120 #define __PTK_FRAMEWORK_OBJC_KEY3 43
121 #define __PTK_FRAMEWORK_OBJC_KEY4 44
122 #define __PTK_FRAMEWORK_OBJC_KEY5 45
123 #define __PTK_FRAMEWORK_OBJC_KEY6 46
124 #define __PTK_FRAMEWORK_OBJC_KEY7 47
125 #define __PTK_FRAMEWORK_OBJC_KEY8 48
126 #define __PTK_FRAMEWORK_OBJC_KEY9 49
128 /* Keys 50-59 for Core Foundation usage */
129 #define __PTK_FRAMEWORK_COREFOUNDATION_KEY0 50
130 #define __PTK_FRAMEWORK_COREFOUNDATION_KEY1 51
131 #define __PTK_FRAMEWORK_COREFOUNDATION_KEY2 52
132 #define __PTK_FRAMEWORK_COREFOUNDATION_KEY3 53
133 #define __PTK_FRAMEWORK_COREFOUNDATION_KEY4 54
134 #define __PTK_FRAMEWORK_COREFOUNDATION_KEY5 55
135 #define __PTK_FRAMEWORK_COREFOUNDATION_KEY6 56
136 #define __PTK_FRAMEWORK_COREFOUNDATION_KEY7 57
137 #define __PTK_FRAMEWORK_COREFOUNDATION_KEY8 58
138 #define __PTK_FRAMEWORK_COREFOUNDATION_KEY9 59
140 /* Keys 60-69 for Foundation usage */
141 #define __PTK_FRAMEWORK_FOUNDATION_KEY0 60
142 #define __PTK_FRAMEWORK_FOUNDATION_KEY1 61
143 #define __PTK_FRAMEWORK_FOUNDATION_KEY2 62
144 #define __PTK_FRAMEWORK_FOUNDATION_KEY3 63
145 #define __PTK_FRAMEWORK_FOUNDATION_KEY4 64
146 #define __PTK_FRAMEWORK_FOUNDATION_KEY5 65
147 #define __PTK_FRAMEWORK_FOUNDATION_KEY6 66
148 #define __PTK_FRAMEWORK_FOUNDATION_KEY7 67
149 #define __PTK_FRAMEWORK_FOUNDATION_KEY8 68
150 #define __PTK_FRAMEWORK_FOUNDATION_KEY9 69
152 /* Keys 70-79 for Core Animation/QuartzCore usage */
153 #define __PTK_FRAMEWORK_QUARTZCORE_KEY0 70
154 #define __PTK_FRAMEWORK_QUARTZCORE_KEY1 71
155 #define __PTK_FRAMEWORK_QUARTZCORE_KEY2 72
156 #define __PTK_FRAMEWORK_QUARTZCORE_KEY3 73
157 #define __PTK_FRAMEWORK_QUARTZCORE_KEY4 74
158 #define __PTK_FRAMEWORK_QUARTZCORE_KEY5 75
159 #define __PTK_FRAMEWORK_QUARTZCORE_KEY6 76
160 #define __PTK_FRAMEWORK_QUARTZCORE_KEY7 77
161 #define __PTK_FRAMEWORK_QUARTZCORE_KEY8 78
162 #define __PTK_FRAMEWORK_QUARTZCORE_KEY9 79
165 /* Keys 80-89 for CoreData */
166 #define __PTK_FRAMEWORK_COREDATA_KEY0 80
167 #define __PTK_FRAMEWORK_COREDATA_KEY1 81
168 #define __PTK_FRAMEWORK_COREDATA_KEY2 82
169 #define __PTK_FRAMEWORK_COREDATA_KEY3 83
170 #define __PTK_FRAMEWORK_COREDATA_KEY4 84
171 #define __PTK_FRAMEWORK_COREDATA_KEY5 85
172 #define __PTK_FRAMEWORK_COREDATA_KEY6 86
173 #define __PTK_FRAMEWORK_COREDATA_KEY7 87
174 #define __PTK_FRAMEWORK_COREDATA_KEY8 88
175 #define __PTK_FRAMEWORK_COREDATA_KEY9 89
177 /* Keys 90-94 for JavaScriptCore Collection */
178 #define __PTK_FRAMEWORK_JAVASCRIPTCORE_KEY0 90
179 #define __PTK_FRAMEWORK_JAVASCRIPTCORE_KEY1 91
180 #define __PTK_FRAMEWORK_JAVASCRIPTCORE_KEY2 92
181 #define __PTK_FRAMEWORK_JAVASCRIPTCORE_KEY3 93
182 #define __PTK_FRAMEWORK_JAVASCRIPTCORE_KEY4 94
183 /* Keys 95 for CoreText */
184 #define __PTK_FRAMEWORK_CORETEXT_KEY0 95
186 /* Keys 110-119 for Garbage Collection */
187 #define __PTK_FRAMEWORK_GC_KEY0 110
188 #define __PTK_FRAMEWORK_GC_KEY1 111
189 #define __PTK_FRAMEWORK_GC_KEY2 112
190 #define __PTK_FRAMEWORK_GC_KEY3 113
191 #define __PTK_FRAMEWORK_GC_KEY4 114
192 #define __PTK_FRAMEWORK_GC_KEY5 115
193 #define __PTK_FRAMEWORK_GC_KEY6 116
194 #define __PTK_FRAMEWORK_GC_KEY7 117
195 #define __PTK_FRAMEWORK_GC_KEY8 118
196 #define __PTK_FRAMEWORK_GC_KEY9 119
198 /* Keys 210 - 229 are for libSystem usage within the iOS Simulator */
199 /* They are offset from their corresponding libSystem keys by 200 */
200 #define __PTK_LIBC_SIM_LOCALE_KEY 210
201 #define __PTK_LIBC_SIM_TTYNAME_KEY 211
202 #define __PTK_LIBC_SIM_LOCALTIME_KEY 212
203 #define __PTK_LIBC_SIM_GMTIME_KEY 213
204 #define __PTK_LIBC_SIM_GDTOA_BIGINT_KEY 214
205 #define __PTK_LIBC_SIM_PARSEFLOAT_KEY 215
209 extern void *pthread_getspecific(unsigned long);
210 extern int pthread_setspecific(unsigned long, const void *);
211 /* setup destructor function for static key as it is not created with pthread_key_create() */
212 extern int pthread_key_init_np(int, void (*)(void *));
214 #if PTHREAD_LAYOUT_SPI
216 /* SPI intended for CoreSymbolication only */
218 __OSX_AVAILABLE_STARTING(__MAC_10_10
,__IPHONE_8_0
)
219 extern const struct pthread_layout_offsets_s
{
220 // always add new fields at the end
221 const uint16_t plo_version
;
222 // either of the next two fields may be 0; use whichever is set
223 // bytes from pthread_t to base of tsd
224 const uint16_t plo_pthread_tsd_base_offset
;
225 // bytes from pthread_t to a pointer to base of tsd
226 const uint16_t plo_pthread_tsd_base_address_offset
;
227 const uint16_t plo_pthread_tsd_entry_size
;
228 } pthread_layout_offsets
;
230 #endif // PTHREAD_LAYOUT_SPI
233 #if TARGET_IPHONE_SIMULATOR
235 __header_always_inline
int
236 _pthread_has_direct_tsd(void)
241 #define _pthread_getspecific_direct(key) pthread_getspecific((key))
242 #define _pthread_setspecific_direct(key, val) pthread_setspecific((key), (val))
244 #else /* TARGET_IPHONE_SIMULATOR */
246 __header_always_inline
int
247 _pthread_has_direct_tsd(void)
252 /* To be used with static constant keys only */
253 __header_always_inline
void *
254 _pthread_getspecific_direct(unsigned long slot
)
256 return _os_tsd_get_direct(slot
);
259 /* To be used with static constant keys only */
260 __header_always_inline
int
261 _pthread_setspecific_direct(unsigned long slot
, void * val
)
263 return _os_tsd_set_direct(slot
, val
);
266 #endif /* TARGET_IPHONE_SIMULATOR */
268 #endif /* ! __ASSEMBLER__ */
269 #endif /* __PTHREAD_TSD_H__ */