Mercurial > trustbridge > nss-cmake-static
comparison nspr/pr/include/md/_linux.h @ 0:1e5118fa0cb1
This is NSS with a Cmake Buildsyste
To compile a static NSS library for Windows we've used the
Chromium-NSS fork and added a Cmake buildsystem to compile
it statically for Windows. See README.chromium for chromium
changes and README.trustbridge for our modifications.
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Mon, 28 Jul 2014 10:47:06 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:1e5118fa0cb1 |
---|---|
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ | |
2 /* This Source Code Form is subject to the terms of the Mozilla Public | |
3 * License, v. 2.0. If a copy of the MPL was not distributed with this | |
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | |
5 | |
6 /* | |
7 * This file is used by not only Linux but also other glibc systems | |
8 * such as GNU/Hurd and GNU/k*BSD. | |
9 */ | |
10 | |
11 #ifndef nspr_linux_defs_h___ | |
12 #define nspr_linux_defs_h___ | |
13 | |
14 #include "prthread.h" | |
15 | |
16 /* | |
17 * Internal configuration macros | |
18 */ | |
19 | |
20 #define PR_LINKER_ARCH "linux" | |
21 #define _PR_SI_SYSNAME "LINUX" | |
22 #ifdef __powerpc64__ | |
23 #define _PR_SI_ARCHITECTURE "ppc64" | |
24 #elif defined(__powerpc__) | |
25 #define _PR_SI_ARCHITECTURE "ppc" | |
26 #elif defined(__alpha) | |
27 #define _PR_SI_ARCHITECTURE "alpha" | |
28 #elif defined(__ia64__) | |
29 #define _PR_SI_ARCHITECTURE "ia64" | |
30 #elif defined(__x86_64__) | |
31 #define _PR_SI_ARCHITECTURE "x86-64" | |
32 #elif defined(__mc68000__) | |
33 #define _PR_SI_ARCHITECTURE "m68k" | |
34 #elif defined(__sparc__) && defined(__arch64__) | |
35 #define _PR_SI_ARCHITECTURE "sparc64" | |
36 #elif defined(__sparc__) | |
37 #define _PR_SI_ARCHITECTURE "sparc" | |
38 #elif defined(__i386__) | |
39 #define _PR_SI_ARCHITECTURE "x86" | |
40 #elif defined(__mips__) | |
41 #define _PR_SI_ARCHITECTURE "mips" | |
42 #elif defined(__arm__) | |
43 #define _PR_SI_ARCHITECTURE "arm" | |
44 #elif defined(__aarch64__) | |
45 #define _PR_SI_ARCHITECTURE "aarch64" | |
46 #elif defined(__hppa__) | |
47 #define _PR_SI_ARCHITECTURE "hppa" | |
48 #elif defined(__s390x__) | |
49 #define _PR_SI_ARCHITECTURE "s390x" | |
50 #elif defined(__s390__) | |
51 #define _PR_SI_ARCHITECTURE "s390" | |
52 #elif defined(__sh__) | |
53 #define _PR_SI_ARCHITECTURE "sh" | |
54 #elif defined(__avr32__) | |
55 #define _PR_SI_ARCHITECTURE "avr32" | |
56 #elif defined(__m32r__) | |
57 #define _PR_SI_ARCHITECTURE "m32r" | |
58 #else | |
59 #error "Unknown CPU architecture" | |
60 #endif | |
61 #define PR_DLL_SUFFIX ".so" | |
62 | |
63 #define _PR_VMBASE 0x30000000 | |
64 #define _PR_STACK_VMBASE 0x50000000 | |
65 #define _MD_DEFAULT_STACK_SIZE 65536L | |
66 #define _MD_MMAP_FLAGS MAP_PRIVATE | |
67 | |
68 #if defined(__aarch64__) | |
69 #define _MD_MINIMUM_STACK_SIZE 0x20000 | |
70 #endif | |
71 | |
72 #undef HAVE_STACK_GROWING_UP | |
73 | |
74 /* | |
75 * Elf linux supports dl* functions | |
76 */ | |
77 #define HAVE_DLL | |
78 #define USE_DLFCN | |
79 #if defined(ANDROID) | |
80 #define NO_DLOPEN_NULL | |
81 #endif | |
82 | |
83 #ifdef __FreeBSD_kernel__ | |
84 #define _PR_HAVE_SOCKADDR_LEN | |
85 #endif | |
86 | |
87 #if defined(__i386__) | |
88 #define _PR_HAVE_ATOMIC_OPS | |
89 #define _MD_INIT_ATOMIC() | |
90 extern PRInt32 _PR_x86_AtomicIncrement(PRInt32 *val); | |
91 #define _MD_ATOMIC_INCREMENT _PR_x86_AtomicIncrement | |
92 extern PRInt32 _PR_x86_AtomicDecrement(PRInt32 *val); | |
93 #define _MD_ATOMIC_DECREMENT _PR_x86_AtomicDecrement | |
94 extern PRInt32 _PR_x86_AtomicAdd(PRInt32 *ptr, PRInt32 val); | |
95 #define _MD_ATOMIC_ADD _PR_x86_AtomicAdd | |
96 extern PRInt32 _PR_x86_AtomicSet(PRInt32 *val, PRInt32 newval); | |
97 #define _MD_ATOMIC_SET _PR_x86_AtomicSet | |
98 #endif | |
99 | |
100 #if defined(__ia64__) | |
101 #define _PR_HAVE_ATOMIC_OPS | |
102 #define _MD_INIT_ATOMIC() | |
103 extern PRInt32 _PR_ia64_AtomicIncrement(PRInt32 *val); | |
104 #define _MD_ATOMIC_INCREMENT _PR_ia64_AtomicIncrement | |
105 extern PRInt32 _PR_ia64_AtomicDecrement(PRInt32 *val); | |
106 #define _MD_ATOMIC_DECREMENT _PR_ia64_AtomicDecrement | |
107 extern PRInt32 _PR_ia64_AtomicAdd(PRInt32 *ptr, PRInt32 val); | |
108 #define _MD_ATOMIC_ADD _PR_ia64_AtomicAdd | |
109 extern PRInt32 _PR_ia64_AtomicSet(PRInt32 *val, PRInt32 newval); | |
110 #define _MD_ATOMIC_SET _PR_ia64_AtomicSet | |
111 #endif | |
112 | |
113 #if defined(__x86_64__) | |
114 #define _PR_HAVE_ATOMIC_OPS | |
115 #define _MD_INIT_ATOMIC() | |
116 extern PRInt32 _PR_x86_64_AtomicIncrement(PRInt32 *val); | |
117 #define _MD_ATOMIC_INCREMENT _PR_x86_64_AtomicIncrement | |
118 extern PRInt32 _PR_x86_64_AtomicDecrement(PRInt32 *val); | |
119 #define _MD_ATOMIC_DECREMENT _PR_x86_64_AtomicDecrement | |
120 extern PRInt32 _PR_x86_64_AtomicAdd(PRInt32 *ptr, PRInt32 val); | |
121 #define _MD_ATOMIC_ADD _PR_x86_64_AtomicAdd | |
122 extern PRInt32 _PR_x86_64_AtomicSet(PRInt32 *val, PRInt32 newval); | |
123 #define _MD_ATOMIC_SET _PR_x86_64_AtomicSet | |
124 #endif | |
125 | |
126 #if defined(__powerpc__) && !defined(__powerpc64__) | |
127 #define _PR_HAVE_ATOMIC_OPS | |
128 #define _MD_INIT_ATOMIC() | |
129 extern PRInt32 _PR_ppc_AtomicIncrement(PRInt32 *val); | |
130 #define _MD_ATOMIC_INCREMENT _PR_ppc_AtomicIncrement | |
131 extern PRInt32 _PR_ppc_AtomicDecrement(PRInt32 *val); | |
132 #define _MD_ATOMIC_DECREMENT _PR_ppc_AtomicDecrement | |
133 extern PRInt32 _PR_ppc_AtomicAdd(PRInt32 *ptr, PRInt32 val); | |
134 #define _MD_ATOMIC_ADD _PR_ppc_AtomicAdd | |
135 extern PRInt32 _PR_ppc_AtomicSet(PRInt32 *val, PRInt32 newval); | |
136 #define _MD_ATOMIC_SET _PR_ppc_AtomicSet | |
137 #endif | |
138 | |
139 #if defined(__alpha) | |
140 #define _PR_HAVE_ATOMIC_OPS | |
141 #define _MD_INIT_ATOMIC() | |
142 #define _MD_ATOMIC_ADD(ptr, i) ({ \ | |
143 PRInt32 __atomic_tmp, __atomic_ret; \ | |
144 __asm__ __volatile__( \ | |
145 "1: ldl_l %[ret], %[val] \n" \ | |
146 " addl %[ret], %[inc], %[tmp] \n" \ | |
147 " addl %[ret], %[inc], %[ret] \n" \ | |
148 " stl_c %[tmp], %[val] \n" \ | |
149 " beq %[tmp], 2f \n" \ | |
150 ".subsection 2 \n" \ | |
151 "2: br 1b \n" \ | |
152 ".previous" \ | |
153 : [ret] "=&r" (__atomic_ret), \ | |
154 [tmp] "=&r" (__atomic_tmp), \ | |
155 [val] "=m" (*ptr) \ | |
156 : [inc] "Ir" (i), "m" (*ptr)); \ | |
157 __atomic_ret; \ | |
158 }) | |
159 #define _MD_ATOMIC_INCREMENT(ptr) _MD_ATOMIC_ADD(ptr, 1) | |
160 #define _MD_ATOMIC_DECREMENT(ptr) ({ \ | |
161 PRInt32 __atomic_tmp, __atomic_ret; \ | |
162 __asm__ __volatile__( \ | |
163 "1: ldl_l %[ret], %[val] \n" \ | |
164 " subl %[ret], 1, %[tmp] \n" \ | |
165 " subl %[ret], 1, %[ret] \n" \ | |
166 " stl_c %[tmp], %[val] \n" \ | |
167 " beq %[tmp], 2f \n" \ | |
168 ".subsection 2 \n" \ | |
169 "2: br 1b \n" \ | |
170 ".previous" \ | |
171 : [ret] "=&r" (__atomic_ret), \ | |
172 [tmp] "=&r" (__atomic_tmp), \ | |
173 [val] "=m" (*ptr) \ | |
174 : "m" (*ptr)); \ | |
175 __atomic_ret; \ | |
176 }) | |
177 #define _MD_ATOMIC_SET(ptr, n) ({ \ | |
178 PRInt32 __atomic_tmp, __atomic_ret; \ | |
179 __asm__ __volatile__( \ | |
180 "1: ldl_l %[ret], %[val] \n" \ | |
181 " mov %[newval], %[tmp] \n" \ | |
182 " stl_c %[tmp], %[val] \n" \ | |
183 " beq %[tmp], 2f \n" \ | |
184 ".subsection 2 \n" \ | |
185 "2: br 1b \n" \ | |
186 ".previous" \ | |
187 : [ret] "=&r" (__atomic_ret), \ | |
188 [tmp] "=&r"(__atomic_tmp), \ | |
189 [val] "=m" (*ptr) \ | |
190 : [newval] "Ir" (n), "m" (*ptr)); \ | |
191 __atomic_ret; \ | |
192 }) | |
193 #endif | |
194 | |
195 #if defined(__arm__) || defined(__aarch64__) | |
196 #if defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4) | |
197 /* Use GCC built-in functions */ | |
198 #define _PR_HAVE_ATOMIC_OPS | |
199 #define _MD_INIT_ATOMIC() | |
200 | |
201 #define _MD_ATOMIC_INCREMENT(ptr) __sync_add_and_fetch(ptr, 1) | |
202 #define _MD_ATOMIC_DECREMENT(ptr) __sync_sub_and_fetch(ptr, 1) | |
203 #define _MD_ATOMIC_SET(ptr, nv) __sync_lock_test_and_set(ptr, nv) | |
204 #define _MD_ATOMIC_ADD(ptr, i) __sync_add_and_fetch(ptr, i) | |
205 | |
206 #elif defined(_PR_ARM_KUSER) | |
207 #define _PR_HAVE_ATOMIC_OPS | |
208 #define _MD_INIT_ATOMIC() | |
209 | |
210 /* | |
211 * The kernel provides this helper function at a fixed address with a fixed | |
212 * ABI signature, directly callable from user space. | |
213 * | |
214 * Definition: | |
215 * Atomically store newval in *ptr if *ptr is equal to oldval. | |
216 * Return zero if *ptr was changed or non-zero if no exchange happened. | |
217 */ | |
218 typedef int (__kernel_cmpxchg_t)(int oldval, int newval, volatile int *ptr); | |
219 #define __kernel_cmpxchg (*(__kernel_cmpxchg_t *)0xffff0fc0) | |
220 | |
221 #define _MD_ATOMIC_INCREMENT(ptr) _MD_ATOMIC_ADD(ptr, 1) | |
222 #define _MD_ATOMIC_DECREMENT(ptr) _MD_ATOMIC_ADD(ptr, -1) | |
223 | |
224 static inline PRInt32 _MD_ATOMIC_ADD(PRInt32 *ptr, PRInt32 n) | |
225 { | |
226 PRInt32 ov, nv; | |
227 volatile PRInt32 *vp = ptr; | |
228 | |
229 do { | |
230 ov = *vp; | |
231 nv = ov + n; | |
232 } while (__kernel_cmpxchg(ov, nv, vp)); | |
233 | |
234 return nv; | |
235 } | |
236 | |
237 static inline PRInt32 _MD_ATOMIC_SET(PRInt32 *ptr, PRInt32 nv) | |
238 { | |
239 PRInt32 ov; | |
240 volatile PRInt32 *vp = ptr; | |
241 | |
242 do { | |
243 ov = *vp; | |
244 } while (__kernel_cmpxchg(ov, nv, vp)); | |
245 | |
246 return ov; | |
247 } | |
248 #endif | |
249 #endif /* __arm__ */ | |
250 | |
251 #define USE_SETJMP | |
252 #if (defined(__GLIBC__) && __GLIBC__ >= 2) || defined(ANDROID) | |
253 #define _PR_POLL_AVAILABLE | |
254 #endif | |
255 #undef _PR_USE_POLL | |
256 #define _PR_STAT_HAS_ONLY_ST_ATIME | |
257 #if defined(__alpha) || defined(__ia64__) | |
258 #define _PR_HAVE_LARGE_OFF_T | |
259 #elif (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1) \ | |
260 || defined(ANDROID) | |
261 #define _PR_HAVE_OFF64_T | |
262 #else | |
263 #define _PR_NO_LARGE_FILES | |
264 #endif | |
265 #if (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1) \ | |
266 || defined(ANDROID) | |
267 #define _PR_INET6 | |
268 #define _PR_HAVE_INET_NTOP | |
269 #define _PR_HAVE_GETHOSTBYNAME2 | |
270 #define _PR_HAVE_GETADDRINFO | |
271 #define _PR_INET6_PROBE | |
272 #endif | |
273 #ifndef ANDROID | |
274 #define _PR_HAVE_SYSV_SEMAPHORES | |
275 #define PR_HAVE_SYSV_NAMED_SHARED_MEMORY | |
276 #endif | |
277 /* Android has gethostbyname_r but not gethostbyaddr_r or gethostbyname2_r. */ | |
278 #if (__GLIBC__ >= 2) && defined(_PR_PTHREADS) | |
279 #define _PR_HAVE_GETHOST_R | |
280 #define _PR_HAVE_GETHOST_R_INT | |
281 #endif | |
282 | |
283 #ifdef _PR_PTHREADS | |
284 | |
285 extern void _MD_CleanupBeforeExit(void); | |
286 #define _MD_CLEANUP_BEFORE_EXIT _MD_CleanupBeforeExit | |
287 | |
288 #else /* ! _PR_PTHREADS */ | |
289 | |
290 #include <setjmp.h> | |
291 | |
292 #define PR_CONTEXT_TYPE sigjmp_buf | |
293 | |
294 #define CONTEXT(_th) ((_th)->md.context) | |
295 | |
296 #ifdef __powerpc__ | |
297 /* | |
298 * PowerPC based MkLinux | |
299 * | |
300 * On the PowerPC, the new style jmp_buf isn't used until glibc | |
301 * 2.1. | |
302 */ | |
303 #if (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1) | |
304 #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[JB_GPR1] | |
305 #else | |
306 #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__misc[0] | |
307 #endif /* glibc 2.1 or later */ | |
308 #define _MD_SET_FP(_t, val) | |
309 #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t)) | |
310 #define _MD_GET_FP_PTR(_t) ((void *) 0) | |
311 /* aix = 64, macos = 70 */ | |
312 #define PR_NUM_GCREGS 64 | |
313 | |
314 #elif defined(__alpha) | |
315 /* Alpha based Linux */ | |
316 | |
317 #if defined(__GLIBC__) && __GLIBC__ >= 2 | |
318 #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[JB_SP] | |
319 #define _MD_SET_FP(_t, val) | |
320 #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t)) | |
321 #define _MD_GET_FP_PTR(_t) ((void *) 0) | |
322 #define _MD_SP_TYPE long int | |
323 #else | |
324 #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__sp | |
325 #define _MD_SET_FP(_t, val) | |
326 #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t)) | |
327 #define _MD_GET_FP_PTR(_t) ((void *) 0) | |
328 #define _MD_SP_TYPE __ptr_t | |
329 #endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */ | |
330 | |
331 /* XXX not sure if this is correct, or maybe it should be 17? */ | |
332 #define PR_NUM_GCREGS 9 | |
333 | |
334 #elif defined(__ia64__) | |
335 | |
336 #define _MD_GET_SP(_t) ((long *)((_t)->md.context[0].__jmpbuf)[0]) | |
337 #define _MD_SET_FP(_t, val) | |
338 #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t)) | |
339 #define _MD_GET_FP_PTR(_t) ((void *) 0) | |
340 #define _MD_SP_TYPE long int | |
341 | |
342 #define PR_NUM_GCREGS _JBLEN | |
343 | |
344 #elif defined(__mc68000__) | |
345 /* m68k based Linux */ | |
346 | |
347 /* | |
348 * On the m68k, glibc still uses the old style sigjmp_buf, even | |
349 * in glibc 2.0.7. | |
350 */ | |
351 #if defined(__GLIBC__) && __GLIBC__ >= 2 | |
352 #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__sp | |
353 #define _MD_SET_FP(_t, val) | |
354 #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t)) | |
355 #define _MD_GET_FP_PTR(_t) ((void *) 0) | |
356 #define _MD_SP_TYPE int | |
357 #else | |
358 #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__sp | |
359 #define _MD_SET_FP(_t, val) | |
360 #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t)) | |
361 #define _MD_GET_FP_PTR(_t) ((void *) 0) | |
362 #define _MD_SP_TYPE __ptr_t | |
363 #endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */ | |
364 | |
365 /* XXX not sure if this is correct, or maybe it should be 17? */ | |
366 #define PR_NUM_GCREGS 9 | |
367 | |
368 #elif defined(__sparc__) | |
369 /* Sparc */ | |
370 #if defined(__GLIBC__) && __GLIBC__ >= 2 | |
371 /* | |
372 * You need glibc2-2.0.7-25 or later. The libraries that came with | |
373 * Red Hat 5.1 are not new enough, but they are in 5.2. | |
374 */ | |
375 #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[JB_SP] | |
376 #define _MD_SET_FP(_t, val) ((_t)->md.context[0].__jmpbuf[JB_FP] = val) | |
377 #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t)) | |
378 #define _MD_GET_FP_PTR(_t) (&(_t)->md.context[0].__jmpbuf[JB_FP]) | |
379 #define _MD_SP_TYPE int | |
380 #else | |
381 #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__fp | |
382 #define _MD_SET_FP(_t, val) | |
383 #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t)) | |
384 #define _MD_GET_FP_PTR(_t) ((void *) 0) | |
385 #define _MD_SP_TYPE __ptr_t | |
386 #endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */ | |
387 | |
388 #elif defined(__i386__) | |
389 /* Intel based Linux */ | |
390 #if defined(__GLIBC__) && __GLIBC__ >= 2 | |
391 #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[JB_SP] | |
392 #define _MD_SET_FP(_t, val) ((_t)->md.context[0].__jmpbuf[JB_BP] = val) | |
393 #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t)) | |
394 #define _MD_GET_FP_PTR(_t) (&(_t)->md.context[0].__jmpbuf[JB_BP]) | |
395 #define _MD_SP_TYPE int | |
396 #else | |
397 #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__sp | |
398 #define _MD_SET_FP(_t, val) ((_t)->md.context[0].__jmpbuf[0].__bp = val) | |
399 #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t)) | |
400 #define _MD_GET_FP_PTR(_t) &((_t)->md.context[0].__jmpbuf[0].__bp) | |
401 #define _MD_SP_TYPE __ptr_t | |
402 #endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */ | |
403 #define PR_NUM_GCREGS 6 | |
404 | |
405 #elif defined(__mips__) | |
406 /* Linux/MIPS */ | |
407 #if defined(__GLIBC__) && __GLIBC__ >= 2 | |
408 #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__sp | |
409 #define _MD_SET_FP(_t, val) ((_t)->md.context[0].__jmpbuf[0].__fp = (val)) | |
410 #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t)) | |
411 #define _MD_GET_FP_PTR(_t) (&(_t)->md.context[0].__jmpbuf[0].__fp) | |
412 #define _MD_SP_TYPE __ptr_t | |
413 #else | |
414 #error "Linux/MIPS pre-glibc2 not supported yet" | |
415 #endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */ | |
416 | |
417 #elif defined(__arm__) | |
418 /* ARM/Linux */ | |
419 #if defined(__GLIBC__) && __GLIBC__ >= 2 | |
420 #ifdef __ARM_EABI__ | |
421 /* EABI */ | |
422 #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[8] | |
423 #define _MD_SET_FP(_t, val) ((_t)->md.context[0].__jmpbuf[7] = (val)) | |
424 #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t)) | |
425 #define _MD_GET_FP_PTR(_t) (&(_t)->md.context[0].__jmpbuf[7]) | |
426 #define _MD_SP_TYPE __ptr_t | |
427 #else /* __ARM_EABI__ */ | |
428 /* old ABI */ | |
429 #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[20] | |
430 #define _MD_SET_FP(_t, val) ((_t)->md.context[0].__jmpbuf[19] = (val)) | |
431 #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t)) | |
432 #define _MD_GET_FP_PTR(_t) (&(_t)->md.context[0].__jmpbuf[19]) | |
433 #define _MD_SP_TYPE __ptr_t | |
434 #endif /* __ARM_EABI__ */ | |
435 #else | |
436 #error "ARM/Linux pre-glibc2 not supported yet" | |
437 #endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */ | |
438 | |
439 #elif defined(__sh__) | |
440 /* SH/Linux */ | |
441 #if defined(__GLIBC__) && __GLIBC__ >= 2 | |
442 #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[7] | |
443 #define _MD_SET_FP(_t, val) ((_t)->md.context[0].__jmpbuf[6] = (val)) | |
444 #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t)) | |
445 #define _MD_GET_FP_PTR(_t) (&(_t)->md.context[0].__jmpbuf[6]) | |
446 #define _MD_SP_TYPE __ptr_t | |
447 #else | |
448 #error "SH/Linux pre-glibc2 not supported yet" | |
449 #endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */ | |
450 | |
451 #elif defined(__m32r__) | |
452 /* Linux/M32R */ | |
453 #if defined(__GLIBC__) && __GLIBC__ >= 2 | |
454 #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__regs[JB_SP] | |
455 #define _MD_SET_FP(_t, val) ((_t)->md.context[0].__jmpbuf[0].__regs[JB_FP] = (val)) | |
456 #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t)) | |
457 #define _MD_GET_FP_PTR(_t) (&(_t)->md.context[0].__jmpbuf[0].__regs[JB_FP]) | |
458 #define _MD_SP_TYPE __ptr_t | |
459 #else | |
460 #error "Linux/M32R pre-glibc2 not supported yet" | |
461 #endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */ | |
462 | |
463 #else | |
464 | |
465 #error "Unknown CPU architecture" | |
466 | |
467 #endif /*__powerpc__*/ | |
468 | |
469 /* | |
470 ** Initialize a thread context to run "_main()" when started | |
471 */ | |
472 #ifdef __powerpc__ | |
473 | |
474 #define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \ | |
475 { \ | |
476 *status = PR_TRUE; \ | |
477 if (sigsetjmp(CONTEXT(_thread), 1)) { \ | |
478 _main(); \ | |
479 } \ | |
480 _MD_GET_SP(_thread) = (unsigned char*) ((_sp) - 128); \ | |
481 _thread->md.sp = _MD_GET_SP_PTR(_thread); \ | |
482 _thread->md.fp = _MD_GET_FP_PTR(_thread); \ | |
483 _MD_SET_FP(_thread, 0); \ | |
484 } | |
485 | |
486 #elif defined(__mips__) | |
487 | |
488 #define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \ | |
489 { \ | |
490 *status = PR_TRUE; \ | |
491 (void) sigsetjmp(CONTEXT(_thread), 1); \ | |
492 _thread->md.context[0].__jmpbuf[0].__pc = (__ptr_t) _main; \ | |
493 _MD_GET_SP(_thread) = (_MD_SP_TYPE) ((_sp) - 64); \ | |
494 _thread->md.sp = _MD_GET_SP_PTR(_thread); \ | |
495 _thread->md.fp = _MD_GET_FP_PTR(_thread); \ | |
496 _MD_SET_FP(_thread, 0); \ | |
497 } | |
498 | |
499 #else | |
500 | |
501 #define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \ | |
502 { \ | |
503 *status = PR_TRUE; \ | |
504 if (sigsetjmp(CONTEXT(_thread), 1)) { \ | |
505 _main(); \ | |
506 } \ | |
507 _MD_GET_SP(_thread) = (_MD_SP_TYPE) ((_sp) - 64); \ | |
508 _thread->md.sp = _MD_GET_SP_PTR(_thread); \ | |
509 _thread->md.fp = _MD_GET_FP_PTR(_thread); \ | |
510 _MD_SET_FP(_thread, 0); \ | |
511 } | |
512 | |
513 #endif /*__powerpc__*/ | |
514 | |
515 #define _MD_SWITCH_CONTEXT(_thread) \ | |
516 if (!sigsetjmp(CONTEXT(_thread), 1)) { \ | |
517 (_thread)->md.errcode = errno; \ | |
518 _PR_Schedule(); \ | |
519 } | |
520 | |
521 /* | |
522 ** Restore a thread context, saved by _MD_SWITCH_CONTEXT | |
523 */ | |
524 #define _MD_RESTORE_CONTEXT(_thread) \ | |
525 { \ | |
526 errno = (_thread)->md.errcode; \ | |
527 _MD_SET_CURRENT_THREAD(_thread); \ | |
528 siglongjmp(CONTEXT(_thread), 1); \ | |
529 } | |
530 | |
531 /* Machine-dependent (MD) data structures */ | |
532 | |
533 struct _MDThread { | |
534 PR_CONTEXT_TYPE context; | |
535 void *sp; | |
536 void *fp; | |
537 int id; | |
538 int errcode; | |
539 }; | |
540 | |
541 struct _MDThreadStack { | |
542 PRInt8 notused; | |
543 }; | |
544 | |
545 struct _MDLock { | |
546 PRInt8 notused; | |
547 }; | |
548 | |
549 struct _MDSemaphore { | |
550 PRInt8 notused; | |
551 }; | |
552 | |
553 struct _MDCVar { | |
554 PRInt8 notused; | |
555 }; | |
556 | |
557 struct _MDSegment { | |
558 PRInt8 notused; | |
559 }; | |
560 | |
561 /* | |
562 * md-specific cpu structure field | |
563 */ | |
564 #include <sys/time.h> /* for FD_SETSIZE */ | |
565 #define _PR_MD_MAX_OSFD FD_SETSIZE | |
566 | |
567 struct _MDCPU_Unix { | |
568 PRCList ioQ; | |
569 PRUint32 ioq_timeout; | |
570 PRInt32 ioq_max_osfd; | |
571 PRInt32 ioq_osfd_cnt; | |
572 #ifndef _PR_USE_POLL | |
573 fd_set fd_read_set, fd_write_set, fd_exception_set; | |
574 PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD], | |
575 fd_exception_cnt[_PR_MD_MAX_OSFD]; | |
576 #else | |
577 struct pollfd *ioq_pollfds; | |
578 int ioq_pollfds_size; | |
579 #endif /* _PR_USE_POLL */ | |
580 }; | |
581 | |
582 #define _PR_IOQ(_cpu) ((_cpu)->md.md_unix.ioQ) | |
583 #define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu)) | |
584 #define _PR_FD_READ_SET(_cpu) ((_cpu)->md.md_unix.fd_read_set) | |
585 #define _PR_FD_READ_CNT(_cpu) ((_cpu)->md.md_unix.fd_read_cnt) | |
586 #define _PR_FD_WRITE_SET(_cpu) ((_cpu)->md.md_unix.fd_write_set) | |
587 #define _PR_FD_WRITE_CNT(_cpu) ((_cpu)->md.md_unix.fd_write_cnt) | |
588 #define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set) | |
589 #define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt) | |
590 #define _PR_IOQ_TIMEOUT(_cpu) ((_cpu)->md.md_unix.ioq_timeout) | |
591 #define _PR_IOQ_MAX_OSFD(_cpu) ((_cpu)->md.md_unix.ioq_max_osfd) | |
592 #define _PR_IOQ_OSFD_CNT(_cpu) ((_cpu)->md.md_unix.ioq_osfd_cnt) | |
593 #define _PR_IOQ_POLLFDS(_cpu) ((_cpu)->md.md_unix.ioq_pollfds) | |
594 #define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size) | |
595 | |
596 #define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu) 32 | |
597 | |
598 struct _MDCPU { | |
599 struct _MDCPU_Unix md_unix; | |
600 }; | |
601 | |
602 #define _MD_INIT_LOCKS() | |
603 #define _MD_NEW_LOCK(lock) PR_SUCCESS | |
604 #define _MD_FREE_LOCK(lock) | |
605 #define _MD_LOCK(lock) | |
606 #define _MD_UNLOCK(lock) | |
607 #define _MD_INIT_IO() | |
608 #define _MD_IOQ_LOCK() | |
609 #define _MD_IOQ_UNLOCK() | |
610 | |
611 extern PRStatus _MD_InitializeThread(PRThread *thread); | |
612 | |
613 #define _MD_INIT_RUNNING_CPU(cpu) _MD_unix_init_running_cpu(cpu) | |
614 #define _MD_INIT_THREAD _MD_InitializeThread | |
615 #define _MD_EXIT_THREAD(thread) | |
616 #define _MD_SUSPEND_THREAD(thread) _MD_suspend_thread | |
617 #define _MD_RESUME_THREAD(thread) _MD_resume_thread | |
618 #define _MD_CLEAN_THREAD(_thread) | |
619 | |
620 extern PRStatus _MD_CREATE_THREAD( | |
621 PRThread *thread, | |
622 void (*start) (void *), | |
623 PRThreadPriority priority, | |
624 PRThreadScope scope, | |
625 PRThreadState state, | |
626 PRUint32 stackSize); | |
627 extern void _MD_SET_PRIORITY(struct _MDThread *thread, PRUintn newPri); | |
628 extern PRStatus _MD_WAIT(PRThread *, PRIntervalTime timeout); | |
629 extern PRStatus _MD_WAKEUP_WAITER(PRThread *); | |
630 extern void _MD_YIELD(void); | |
631 | |
632 #endif /* ! _PR_PTHREADS */ | |
633 | |
634 extern void _MD_EarlyInit(void); | |
635 | |
636 #define _MD_EARLY_INIT _MD_EarlyInit | |
637 #define _MD_FINAL_INIT _PR_UnixInit | |
638 #define HAVE_CLOCK_MONOTONIC | |
639 | |
640 /* | |
641 * We wrapped the select() call. _MD_SELECT refers to the built-in, | |
642 * unwrapped version. | |
643 */ | |
644 #define _MD_SELECT __select | |
645 | |
646 #ifdef _PR_POLL_AVAILABLE | |
647 #include <sys/poll.h> | |
648 extern int __syscall_poll(struct pollfd *ufds, unsigned long int nfds, | |
649 int timeout); | |
650 #define _MD_POLL __syscall_poll | |
651 #endif | |
652 | |
653 /* For writev() */ | |
654 #include <sys/uio.h> | |
655 | |
656 extern void _MD_linux_map_sendfile_error(int err); | |
657 | |
658 #endif /* nspr_linux_defs_h___ */ |