Debian Codegraph @

nsprpub/pr/include/md/_linux.h

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