pthread_machdep.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. /*
  2. * Copyright (c) 2003-2004, 2008, 2011 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. /* Machine-dependent definitions for pthread internals. */
  47. #ifndef _POSIX_PTHREAD_MACHDEP_H
  48. #define _POSIX_PTHREAD_MACHDEP_H
  49. #ifndef __ASSEMBLER__
  50. #include <System/machine/cpu_capabilities.h>
  51. #ifdef __arm__
  52. #include <arm/arch.h>
  53. #endif
  54. #include <TargetConditionals.h>
  55. #include <stdint.h>
  56. /*
  57. ** Define macros for inline pthread_getspecific() usage.
  58. ** We reserve a number of slots for Apple internal use.
  59. ** This number can grow dynamically, no need to fix it.
  60. */
  61. /* This header contains pre defined thread specific keys */
  62. /* 0 is used for pthread_self */
  63. #define _PTHREAD_TSD_SLOT_PTHREAD_SELF 0
  64. /* Keys 1- 9 for use by dyld, directly or indirectly */
  65. #define _PTHREAD_TSD_SLOT_DYLD_1 1
  66. #define _PTHREAD_TSD_SLOT_DYLD_2 2
  67. #define _PTHREAD_TSD_SLOT_DYLD_3 3
  68. #define _PTHREAD_TSD_RESERVED_SLOT_COUNT 4
  69. /* To mirror the usage by dyld for Unwind_SjLj */
  70. #define _PTHREAD_TSD_SLOT_DYLD_8 8
  71. /* Keys 10 - 29 are for Libc/Libsystem internal ussage */
  72. /* used as __pthread_tsd_first + Num */
  73. #define __PTK_LIBC_LOCALE_KEY 10
  74. #define __PTK_LIBC_TTYNAME_KEY 11
  75. #define __PTK_LIBC_LOCALTIME_KEY 12
  76. #define __PTK_LIBC_GMTIME_KEY 13
  77. #define __PTK_LIBC_GDTOA_BIGINT_KEY 14
  78. #define __PTK_LIBC_PARSEFLOAT_KEY 15
  79. /* for usage by dyld */
  80. #define __PTK_LIBC_DYLD_Unwind_SjLj_Key 18
  81. /* Keys 20-25 for libdispactch usage */
  82. #define __PTK_LIBDISPATCH_KEY0 20
  83. #define __PTK_LIBDISPATCH_KEY1 21
  84. #define __PTK_LIBDISPATCH_KEY2 22
  85. #define __PTK_LIBDISPATCH_KEY3 23
  86. #define __PTK_LIBDISPATCH_KEY4 24
  87. #define __PTK_LIBDISPATCH_KEY5 25
  88. /* Keys 30-255 for Non Libsystem usage */
  89. /* Keys 30-39 for Graphic frameworks usage */
  90. #define _PTHREAD_TSD_SLOT_OPENGL 30 /* backwards compat sake */
  91. #define __PTK_FRAMEWORK_OPENGL_KEY 30
  92. #define __PTK_FRAMEWORK_GRAPHICS_KEY1 31
  93. #define __PTK_FRAMEWORK_GRAPHICS_KEY2 32
  94. #define __PTK_FRAMEWORK_GRAPHICS_KEY3 33
  95. #define __PTK_FRAMEWORK_GRAPHICS_KEY4 34
  96. #define __PTK_FRAMEWORK_GRAPHICS_KEY5 35
  97. #define __PTK_FRAMEWORK_GRAPHICS_KEY6 36
  98. #define __PTK_FRAMEWORK_GRAPHICS_KEY7 37
  99. #define __PTK_FRAMEWORK_GRAPHICS_KEY8 38
  100. #define __PTK_FRAMEWORK_GRAPHICS_KEY9 39
  101. /* Keys 40-49 for Objective-C runtime usage */
  102. #define __PTK_FRAMEWORK_OBJC_KEY0 40
  103. #define __PTK_FRAMEWORK_OBJC_KEY1 41
  104. #define __PTK_FRAMEWORK_OBJC_KEY2 42
  105. #define __PTK_FRAMEWORK_OBJC_KEY3 43
  106. #define __PTK_FRAMEWORK_OBJC_KEY4 44
  107. #define __PTK_FRAMEWORK_OBJC_KEY5 45
  108. #define __PTK_FRAMEWORK_OBJC_KEY6 46
  109. #define __PTK_FRAMEWORK_OBJC_KEY7 47
  110. #define __PTK_FRAMEWORK_OBJC_KEY8 48
  111. #define __PTK_FRAMEWORK_OBJC_KEY9 49
  112. /* Keys 50-59 for Core Foundation usage */
  113. #define __PTK_FRAMEWORK_COREFOUNDATION_KEY0 50
  114. #define __PTK_FRAMEWORK_COREFOUNDATION_KEY1 51
  115. #define __PTK_FRAMEWORK_COREFOUNDATION_KEY2 52
  116. #define __PTK_FRAMEWORK_COREFOUNDATION_KEY3 53
  117. #define __PTK_FRAMEWORK_COREFOUNDATION_KEY4 54
  118. #define __PTK_FRAMEWORK_COREFOUNDATION_KEY5 55
  119. #define __PTK_FRAMEWORK_COREFOUNDATION_KEY6 56
  120. #define __PTK_FRAMEWORK_COREFOUNDATION_KEY7 57
  121. #define __PTK_FRAMEWORK_COREFOUNDATION_KEY8 58
  122. #define __PTK_FRAMEWORK_COREFOUNDATION_KEY9 59
  123. /* Keys 60-69 for Foundation usage */
  124. #define __PTK_FRAMEWORK_FOUNDATION_KEY0 60
  125. #define __PTK_FRAMEWORK_FOUNDATION_KEY1 61
  126. #define __PTK_FRAMEWORK_FOUNDATION_KEY2 62
  127. #define __PTK_FRAMEWORK_FOUNDATION_KEY3 63
  128. #define __PTK_FRAMEWORK_FOUNDATION_KEY4 64
  129. #define __PTK_FRAMEWORK_FOUNDATION_KEY5 65
  130. #define __PTK_FRAMEWORK_FOUNDATION_KEY6 66
  131. #define __PTK_FRAMEWORK_FOUNDATION_KEY7 67
  132. #define __PTK_FRAMEWORK_FOUNDATION_KEY8 68
  133. #define __PTK_FRAMEWORK_FOUNDATION_KEY9 69
  134. /* Keys 70-79 for Core Animation/QuartzCore usage */
  135. #define __PTK_FRAMEWORK_QUARTZCORE_KEY0 70
  136. #define __PTK_FRAMEWORK_QUARTZCORE_KEY1 71
  137. #define __PTK_FRAMEWORK_QUARTZCORE_KEY2 72
  138. #define __PTK_FRAMEWORK_QUARTZCORE_KEY3 73
  139. #define __PTK_FRAMEWORK_QUARTZCORE_KEY4 74
  140. #define __PTK_FRAMEWORK_QUARTZCORE_KEY5 75
  141. #define __PTK_FRAMEWORK_QUARTZCORE_KEY6 76
  142. #define __PTK_FRAMEWORK_QUARTZCORE_KEY7 77
  143. #define __PTK_FRAMEWORK_QUARTZCORE_KEY8 78
  144. #define __PTK_FRAMEWORK_QUARTZCORE_KEY9 79
  145. /* Keys 80-89 for Garbage Collection */
  146. #define __PTK_FRAMEWORK_OLDGC_KEY0 80
  147. #define __PTK_FRAMEWORK_OLDGC_KEY1 81
  148. #define __PTK_FRAMEWORK_OLDGC_KEY2 82
  149. #define __PTK_FRAMEWORK_OLDGC_KEY3 83
  150. #define __PTK_FRAMEWORK_OLDGC_KEY4 84
  151. #define __PTK_FRAMEWORK_OLDGC_KEY5 85
  152. #define __PTK_FRAMEWORK_OLDGC_KEY6 86
  153. #define __PTK_FRAMEWORK_OLDGC_KEY7 87
  154. #define __PTK_FRAMEWORK_OLDGC_KEY8 88
  155. #define __PTK_FRAMEWORK_OLDGC_KEY9 89
  156. /* Keys 90-94 for JavaScriptCore Collection */
  157. #define __PTK_FRAMEWORK_JAVASCRIPTCORE_KEY0 90
  158. #define __PTK_FRAMEWORK_JAVASCRIPTCORE_KEY1 91
  159. #define __PTK_FRAMEWORK_JAVASCRIPTCORE_KEY2 92
  160. #define __PTK_FRAMEWORK_JAVASCRIPTCORE_KEY3 93
  161. #define __PTK_FRAMEWORK_JAVASCRIPTCORE_KEY4 94
  162. /* Keys 95 for CoreText */
  163. #define __PTK_FRAMEWORK_CORETEXT_KEY0 95
  164. /* Keys 110-119 for Garbage Collection */
  165. #define __PTK_FRAMEWORK_GC_KEY0 110
  166. #define __PTK_FRAMEWORK_GC_KEY1 111
  167. #define __PTK_FRAMEWORK_GC_KEY2 112
  168. #define __PTK_FRAMEWORK_GC_KEY3 113
  169. #define __PTK_FRAMEWORK_GC_KEY4 114
  170. #define __PTK_FRAMEWORK_GC_KEY5 115
  171. #define __PTK_FRAMEWORK_GC_KEY6 116
  172. #define __PTK_FRAMEWORK_GC_KEY7 117
  173. #define __PTK_FRAMEWORK_GC_KEY8 118
  174. #define __PTK_FRAMEWORK_GC_KEY9 119
  175. /*
  176. ** Define macros for inline pthread_getspecific() usage.
  177. ** We reserve a number of slots for Apple internal use.
  178. ** This number can grow dynamically, no need to fix it.
  179. */
  180. #if defined(__cplusplus)
  181. extern "C" {
  182. #endif
  183. extern void *pthread_getspecific(unsigned long);
  184. extern int pthread_setspecific(unsigned long, const void *);
  185. /* setup destructor function for static key as it is not created with pthread_key_create() */
  186. int pthread_key_init_np(int, void (*)(void *));
  187. #if defined(__cplusplus)
  188. }
  189. #endif
  190. //typedef int pthread_lock_t;
  191. //__inline__ static int
  192. //_pthread_has_direct_tsd(void)
  193. //{
  194. //#if TARGET_IPHONE_SIMULATOR
  195. // /* Simulator will use the host implementation, so bypass the macro that is in the target code */
  196. // return 0;
  197. //#elif defined(__ppc__)
  198. // int *caps = (int *)_COMM_PAGE_CPU_CAPABILITIES;
  199. // if (*caps & kFastThreadLocalStorage) {
  200. // return 1;
  201. // } else {
  202. // return 0;
  203. // }
  204. //#else
  205. // return 1;
  206. //#endif
  207. //}
  208. #if TARGET_IPHONE_SIMULATOR || defined(__ppc__) || defined(__ppc64__) || \
  209. (defined(__arm__) && !defined(_ARM_ARCH_7) && defined(_ARM_ARCH_6) && defined(__thumb__))
  210. #define _pthread_getspecific_direct(key) pthread_getspecific((key))
  211. #define _pthread_setspecific_direct(key, val) pthread_setspecific((key), (val))
  212. #else
  213. /* To be used with static constant keys only */
  214. //__inline__ static void *
  215. //_pthread_getspecific_direct(unsigned long slot)
  216. //{
  217. // void *ret;
  218. //#if defined(__i386__) || defined(__x86_64__)
  219. // __asm__("mov %%gs:%1, %0" : "=r" (ret) : "m" (*(void **)(slot * sizeof(void *))));
  220. //#elif (defined(__arm__) && (defined(_ARM_ARCH_6) || defined(_ARM_ARCH_5)))
  221. // void **__pthread_tsd;
  222. //#if defined(__arm__) && defined(_ARM_ARCH_6)
  223. // uintptr_t __pthread_tpid;
  224. // __asm__("mrc p15, 0, %0, c13, c0, 3" : "=r" (__pthread_tpid));
  225. // __pthread_tsd = (void**)(__pthread_tpid & ~0x3ul);
  226. //#elif defined(__arm__) && defined(_ARM_ARCH_5)
  227. // register uintptr_t __pthread_tpid asm ("r9");
  228. // __pthread_tsd = (void**)__pthread_tpid;
  229. //#endif
  230. // ret = __pthread_tsd[slot];
  231. //#else
  232. //#error no _pthread_getspecific_direct implementation for this arch
  233. //#endif
  234. // return ret;
  235. //}
  236. /* To be used with static constant keys only */
  237. //__inline__ static int
  238. //_pthread_setspecific_direct(unsigned long slot, void * val)
  239. //{
  240. //#if defined(__i386__)
  241. //#if defined(__PIC__)
  242. // __asm__("movl %1,%%gs:%0" : "=m" (*(void **)(slot * sizeof(void *))) : "rn" (val));
  243. //#else
  244. // __asm__("movl %1,%%gs:%0" : "=m" (*(void **)(slot * sizeof(void *))) : "ri" (val));
  245. //#endif
  246. //#elif defined(__x86_64__)
  247. // /* PIC is free and cannot be disabled, even with: gcc -mdynamic-no-pic ... */
  248. // __asm__("movq %1,%%gs:%0" : "=m" (*(void **)(slot * sizeof(void *))) : "rn" (val));
  249. //#elif (defined(__arm__) && (defined(_ARM_ARCH_6) || defined(_ARM_ARCH_5)))
  250. // void **__pthread_tsd;
  251. //#if defined(__arm__) && defined(_ARM_ARCH_6)
  252. // uintptr_t __pthread_tpid;
  253. // __asm__("mrc p15, 0, %0, c13, c0, 3" : "=r" (__pthread_tpid));
  254. // __pthread_tsd = (void**)(__pthread_tpid & ~0x3ul);
  255. //#elif defined(__arm__) && defined(_ARM_ARCH_5)
  256. // register uintptr_t __pthread_tpid asm ("r9");
  257. // __pthread_tsd = (void**)__pthread_tpid;
  258. //#endif
  259. // __pthread_tsd[slot] = val;
  260. //#else
  261. //#error no _pthread_setspecific_direct implementation for this arch
  262. //#endif
  263. // return 0;
  264. //}
  265. #endif
  266. #define LOCK_INIT(l) ((l) = 0)
  267. #define LOCK_INITIALIZER 0
  268. #endif /* ! __ASSEMBLER__ */
  269. #endif /* _POSIX_PTHREAD_MACHDEP_H */