tsd_private.h 9.5 KB

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