]> git.saurik.com Git - cycript.git/blame - include/pthread_machdep.h
Allow APR link flags to be configure overridden.
[cycript.git] / include / pthread_machdep.h
CommitLineData
7c6c5b0a
JF
1/*
2 * Copyright (c) 2003-2004, 2008 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/* Machine-dependent definitions for pthread internals. */
48
49#ifndef _POSIX_PTHREAD_MACHDEP_H
50#define _POSIX_PTHREAD_MACHDEP_H
51
52#ifdef __LP64__
53#define _PTHREAD_TSD_OFFSET 0x60
54#else
55#define _PTHREAD_TSD_OFFSET 0x48
56#endif /* __LP64__ */
57
58#ifndef __ASSEMBLER__
59
60#include <System/machine/cpu_capabilities.h>
61#ifdef __arm__
62#include <arm/arch.h>
63#endif
64
65/*
66** Define macros for inline pthread_getspecific() usage.
67** We reserve a number of slots for Apple internal use.
68** This number can grow dynamically, no need to fix it.
69*/
70
71/* This header contains pre defined thread specific keys */
72/* 0 is used for pthread_self */
73#define _PTHREAD_TSD_SLOT_PTHREAD_SELF 0
74/* Keys 1- 9 for use by dyld, directly or indirectly */
75#define _PTHREAD_TSD_SLOT_DYLD_1 1
76#define _PTHREAD_TSD_SLOT_DYLD_2 2
77#define _PTHREAD_TSD_SLOT_DYLD_3 3
78#define _PTHREAD_TSD_RESERVED_SLOT_COUNT 4
79
80/* Keys 10 - 29 are for Libc/Libsystem internal ussage */
81/* used as __pthread_tsd_first + Num */
82#define __PTK_LIBC_LOCALE_KEY 10
83#define __PTK_LIBC_TTYNAME_KEY 11
84#define __PTK_LIBC_LOCALTIME_KEY 12
85#define __PTK_LIBC_GMTIME_KEY 13
86#define __PTK_LIBC_GDTOA_BIGINT_KEY 14
87#define __PTK_LIBC_PARSEFLOAT_KEY 15
88
89/* Keys 20-25 for libdispactch 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
97/* Keys 30-255 for Non Libsystem usage */
98
99/* Keys 30-39 for Graphic frameworks usage */
100#define _PTHREAD_TSD_SLOT_OPENGL 30 /* backwards compat sake */
101#define __PTK_FRAMEWORK_OPENGL_KEY 30
102#define __PTK_FRAMEWORK_GRAPHICS_KEY1 31
103#define __PTK_FRAMEWORK_GRAPHICS_KEY2 32
104#define __PTK_FRAMEWORK_GRAPHICS_KEY3 33
105#define __PTK_FRAMEWORK_GRAPHICS_KEY4 34
106#define __PTK_FRAMEWORK_GRAPHICS_KEY5 35
107#define __PTK_FRAMEWORK_GRAPHICS_KEY6 36
108#define __PTK_FRAMEWORK_GRAPHICS_KEY7 37
109#define __PTK_FRAMEWORK_GRAPHICS_KEY8 38
110#define __PTK_FRAMEWORK_GRAPHICS_KEY9 39
111
112/* Keys 40-49 for Objective-C runtime usage */
113#define __PTK_FRAMEWORK_OBJC_KEY0 40
114#define __PTK_FRAMEWORK_OBJC_KEY1 41
115#define __PTK_FRAMEWORK_OBJC_KEY2 42
116#define __PTK_FRAMEWORK_OBJC_KEY3 43
117#define __PTK_FRAMEWORK_OBJC_KEY4 44
118#define __PTK_FRAMEWORK_OBJC_KEY5 45
119#define __PTK_FRAMEWORK_OBJC_KEY6 46
120#define __PTK_FRAMEWORK_OBJC_KEY7 47
121#define __PTK_FRAMEWORK_OBJC_KEY8 48
122#define __PTK_FRAMEWORK_OBJC_KEY9 49
123
124/* Keys 50-59 for Core Foundation usage */
125#define __PTK_FRAMEWORK_COREFOUNDATION_KEY0 50
126#define __PTK_FRAMEWORK_COREFOUNDATION_KEY1 51
127#define __PTK_FRAMEWORK_COREFOUNDATION_KEY2 52
128#define __PTK_FRAMEWORK_COREFOUNDATION_KEY3 53
129#define __PTK_FRAMEWORK_COREFOUNDATION_KEY4 54
130#define __PTK_FRAMEWORK_COREFOUNDATION_KEY5 55
131#define __PTK_FRAMEWORK_COREFOUNDATION_KEY6 56
132#define __PTK_FRAMEWORK_COREFOUNDATION_KEY7 57
133#define __PTK_FRAMEWORK_COREFOUNDATION_KEY8 58
134#define __PTK_FRAMEWORK_COREFOUNDATION_KEY9 59
135
136/* Keys 60-69 for Foundation usage */
137#define __PTK_FRAMEWORK_FOUNDATION_KEY0 60
138#define __PTK_FRAMEWORK_FOUNDATION_KEY1 61
139#define __PTK_FRAMEWORK_FOUNDATION_KEY2 62
140#define __PTK_FRAMEWORK_FOUNDATION_KEY3 63
141#define __PTK_FRAMEWORK_FOUNDATION_KEY4 64
142#define __PTK_FRAMEWORK_FOUNDATION_KEY5 65
143#define __PTK_FRAMEWORK_FOUNDATION_KEY6 66
144#define __PTK_FRAMEWORK_FOUNDATION_KEY7 67
145#define __PTK_FRAMEWORK_FOUNDATION_KEY8 68
146#define __PTK_FRAMEWORK_FOUNDATION_KEY9 69
147
148/* Keys 70-79 for Core Animation/QuartzCore usage */
149#define __PTK_FRAMEWORK_QUARTZCORE_KEY0 70
150#define __PTK_FRAMEWORK_QUARTZCORE_KEY1 71
151#define __PTK_FRAMEWORK_QUARTZCORE_KEY2 72
152#define __PTK_FRAMEWORK_QUARTZCORE_KEY3 73
153#define __PTK_FRAMEWORK_QUARTZCORE_KEY4 74
154#define __PTK_FRAMEWORK_QUARTZCORE_KEY5 75
155#define __PTK_FRAMEWORK_QUARTZCORE_KEY6 76
156#define __PTK_FRAMEWORK_QUARTZCORE_KEY7 77
157#define __PTK_FRAMEWORK_QUARTZCORE_KEY8 78
158#define __PTK_FRAMEWORK_QUARTZCORE_KEY9 79
159
160
161/* Keys 80-89 for Garbage Collection */
162#define __PTK_FRAMEWORK_GC_KEY0 80
163#define __PTK_FRAMEWORK_GC_KEY1 81
164#define __PTK_FRAMEWORK_GC_KEY2 82
165#define __PTK_FRAMEWORK_GC_KEY3 83
166#define __PTK_FRAMEWORK_GC_KEY4 84
167#define __PTK_FRAMEWORK_GC_KEY5 85
168#define __PTK_FRAMEWORK_GC_KEY6 86
169#define __PTK_FRAMEWORK_GC_KEY7 87
170#define __PTK_FRAMEWORK_GC_KEY8 88
171#define __PTK_FRAMEWORK_GC_KEY9 89
172
173
174/*
175** Define macros for inline pthread_getspecific() usage.
176** We reserve a number of slots for Apple internal use.
177** This number can grow dynamically, no need to fix it.
178*/
179
180
181#if defined(__cplusplus)
182extern "C" {
183#endif
184
185extern void *pthread_getspecific(unsigned long);
186/* setup destructor function for static key as it is not created with pthread_key_create() */
187int pthread_key_init_np(int, void (*)(void *));
188
189#if defined(__cplusplus)
190}
191#endif
192
193typedef int pthread_lock_t;
194
195inline static int
196_pthread_has_direct_tsd(void)
197{
198#if defined(__ppc__)
199 int *caps = (int *)_COMM_PAGE_CPU_CAPABILITIES;
200 if (*caps & kFastThreadLocalStorage) {
201 return 1;
202 } else {
203 return 0;
204 }
205#elif defined(__arm__) && defined(__thumb__) && defined(_ARM_ARCH_6) && !defined(_ARM_ARCH_7)
206 return 0;
207#else
208 return 1;
209#endif
210}
211
212/* To be used with static constant keys only */
213inline static void *
214_pthread_getspecific_direct(unsigned long slot)
215{
216 void *ret;
217#if defined(__i386__) || defined(__x86_64__)
218#if defined(__OPTIMIZE__)
219 asm volatile("mov %%gs:%P1, %0" : "=r" (ret) : "i" (slot * sizeof(void *) + _PTHREAD_TSD_OFFSET));
220#else
221 asm("mov %%gs:%P2(,%1,%P3), %0" : "=r" (ret) : "r" (slot), "i" (_PTHREAD_TSD_OFFSET), "i" (sizeof (void *)));
222#endif
223#elif defined(__ppc__)
224 void **__pthread_tsd;
225 asm volatile("mfspr %0, 259" : "=r" (__pthread_tsd));
226 ret = __pthread_tsd[slot + (_PTHREAD_TSD_OFFSET / sizeof(void *))];
227#elif defined(__ppc64__)
228 register void **__pthread_tsd asm ("r13");
229 ret = __pthread_tsd[slot + (_PTHREAD_TSD_OFFSET / sizeof(void *))];
230#elif defined(__arm__) && defined(_ARM_ARCH_6)
231 void **__pthread_tsd;
232 __asm__ ("mrc p15, 0, %0, c13, c0, 3" : "=r"(__pthread_tsd));
233 ret = __pthread_tsd[slot + (_PTHREAD_TSD_OFFSET / sizeof(void *))];
234#elif defined(__arm__) && !defined(_ARM_ARCH_6)
235 register void **__pthread_tsd asm ("r9");
236 ret = __pthread_tsd[slot + (_PTHREAD_TSD_OFFSET / sizeof(void *))];
237#else
238#error no pthread_getspecific_direct implementation for this arch
239#endif
240 return ret;
241}
242
243/* To be used with static constant keys only */
244#define _pthread_setspecific_direct(key, val) pthread_setspecific(key, val)
245
246#define LOCK_INIT(l) ((l) = 0)
247#define LOCK_INITIALIZER 0
248
249#endif /* ! __ASSEMBLER__ */
250#endif /* _POSIX_PTHREAD_MACHDEP_H */