andre@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ andre@0: /* This Source Code Form is subject to the terms of the Mozilla Public andre@0: * License, v. 2.0. If a copy of the MPL was not distributed with this andre@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ andre@0: andre@0: /* andre@0: * This file is used by not only Linux but also other glibc systems andre@0: * such as GNU/Hurd and GNU/k*BSD. andre@0: */ andre@0: andre@0: #ifndef nspr_linux_defs_h___ andre@0: #define nspr_linux_defs_h___ andre@0: andre@0: #include "prthread.h" andre@0: andre@0: /* andre@0: * Internal configuration macros andre@0: */ andre@0: andre@0: #define PR_LINKER_ARCH "linux" andre@0: #define _PR_SI_SYSNAME "LINUX" andre@0: #ifdef __powerpc64__ andre@0: #define _PR_SI_ARCHITECTURE "ppc64" andre@0: #elif defined(__powerpc__) andre@0: #define _PR_SI_ARCHITECTURE "ppc" andre@0: #elif defined(__alpha) andre@0: #define _PR_SI_ARCHITECTURE "alpha" andre@0: #elif defined(__ia64__) andre@0: #define _PR_SI_ARCHITECTURE "ia64" andre@0: #elif defined(__x86_64__) andre@0: #define _PR_SI_ARCHITECTURE "x86-64" andre@0: #elif defined(__mc68000__) andre@0: #define _PR_SI_ARCHITECTURE "m68k" andre@0: #elif defined(__sparc__) && defined(__arch64__) andre@0: #define _PR_SI_ARCHITECTURE "sparc64" andre@0: #elif defined(__sparc__) andre@0: #define _PR_SI_ARCHITECTURE "sparc" andre@0: #elif defined(__i386__) andre@0: #define _PR_SI_ARCHITECTURE "x86" andre@0: #elif defined(__mips__) andre@0: #define _PR_SI_ARCHITECTURE "mips" andre@0: #elif defined(__arm__) andre@0: #define _PR_SI_ARCHITECTURE "arm" andre@0: #elif defined(__aarch64__) andre@0: #define _PR_SI_ARCHITECTURE "aarch64" andre@0: #elif defined(__hppa__) andre@0: #define _PR_SI_ARCHITECTURE "hppa" andre@0: #elif defined(__s390x__) andre@0: #define _PR_SI_ARCHITECTURE "s390x" andre@0: #elif defined(__s390__) andre@0: #define _PR_SI_ARCHITECTURE "s390" andre@0: #elif defined(__sh__) andre@0: #define _PR_SI_ARCHITECTURE "sh" andre@0: #elif defined(__avr32__) andre@0: #define _PR_SI_ARCHITECTURE "avr32" andre@0: #elif defined(__m32r__) andre@0: #define _PR_SI_ARCHITECTURE "m32r" andre@0: #else andre@0: #error "Unknown CPU architecture" andre@0: #endif andre@0: #define PR_DLL_SUFFIX ".so" andre@0: andre@0: #define _PR_VMBASE 0x30000000 andre@0: #define _PR_STACK_VMBASE 0x50000000 andre@0: #define _MD_DEFAULT_STACK_SIZE 65536L andre@0: #define _MD_MMAP_FLAGS MAP_PRIVATE andre@0: andre@0: #if defined(__aarch64__) andre@0: #define _MD_MINIMUM_STACK_SIZE 0x20000 andre@0: #endif andre@0: andre@0: #undef HAVE_STACK_GROWING_UP andre@0: andre@0: /* andre@0: * Elf linux supports dl* functions andre@0: */ andre@0: #define HAVE_DLL andre@0: #define USE_DLFCN andre@0: #if defined(ANDROID) andre@0: #define NO_DLOPEN_NULL andre@0: #endif andre@0: andre@0: #ifdef __FreeBSD_kernel__ andre@0: #define _PR_HAVE_SOCKADDR_LEN andre@0: #endif andre@0: andre@0: #if defined(__i386__) andre@0: #define _PR_HAVE_ATOMIC_OPS andre@0: #define _MD_INIT_ATOMIC() andre@0: extern PRInt32 _PR_x86_AtomicIncrement(PRInt32 *val); andre@0: #define _MD_ATOMIC_INCREMENT _PR_x86_AtomicIncrement andre@0: extern PRInt32 _PR_x86_AtomicDecrement(PRInt32 *val); andre@0: #define _MD_ATOMIC_DECREMENT _PR_x86_AtomicDecrement andre@0: extern PRInt32 _PR_x86_AtomicAdd(PRInt32 *ptr, PRInt32 val); andre@0: #define _MD_ATOMIC_ADD _PR_x86_AtomicAdd andre@0: extern PRInt32 _PR_x86_AtomicSet(PRInt32 *val, PRInt32 newval); andre@0: #define _MD_ATOMIC_SET _PR_x86_AtomicSet andre@0: #endif andre@0: andre@0: #if defined(__ia64__) andre@0: #define _PR_HAVE_ATOMIC_OPS andre@0: #define _MD_INIT_ATOMIC() andre@0: extern PRInt32 _PR_ia64_AtomicIncrement(PRInt32 *val); andre@0: #define _MD_ATOMIC_INCREMENT _PR_ia64_AtomicIncrement andre@0: extern PRInt32 _PR_ia64_AtomicDecrement(PRInt32 *val); andre@0: #define _MD_ATOMIC_DECREMENT _PR_ia64_AtomicDecrement andre@0: extern PRInt32 _PR_ia64_AtomicAdd(PRInt32 *ptr, PRInt32 val); andre@0: #define _MD_ATOMIC_ADD _PR_ia64_AtomicAdd andre@0: extern PRInt32 _PR_ia64_AtomicSet(PRInt32 *val, PRInt32 newval); andre@0: #define _MD_ATOMIC_SET _PR_ia64_AtomicSet andre@0: #endif andre@0: andre@0: #if defined(__x86_64__) andre@0: #define _PR_HAVE_ATOMIC_OPS andre@0: #define _MD_INIT_ATOMIC() andre@0: extern PRInt32 _PR_x86_64_AtomicIncrement(PRInt32 *val); andre@0: #define _MD_ATOMIC_INCREMENT _PR_x86_64_AtomicIncrement andre@0: extern PRInt32 _PR_x86_64_AtomicDecrement(PRInt32 *val); andre@0: #define _MD_ATOMIC_DECREMENT _PR_x86_64_AtomicDecrement andre@0: extern PRInt32 _PR_x86_64_AtomicAdd(PRInt32 *ptr, PRInt32 val); andre@0: #define _MD_ATOMIC_ADD _PR_x86_64_AtomicAdd andre@0: extern PRInt32 _PR_x86_64_AtomicSet(PRInt32 *val, PRInt32 newval); andre@0: #define _MD_ATOMIC_SET _PR_x86_64_AtomicSet andre@0: #endif andre@0: andre@0: #if defined(__powerpc__) && !defined(__powerpc64__) andre@0: #define _PR_HAVE_ATOMIC_OPS andre@0: #define _MD_INIT_ATOMIC() andre@0: extern PRInt32 _PR_ppc_AtomicIncrement(PRInt32 *val); andre@0: #define _MD_ATOMIC_INCREMENT _PR_ppc_AtomicIncrement andre@0: extern PRInt32 _PR_ppc_AtomicDecrement(PRInt32 *val); andre@0: #define _MD_ATOMIC_DECREMENT _PR_ppc_AtomicDecrement andre@0: extern PRInt32 _PR_ppc_AtomicAdd(PRInt32 *ptr, PRInt32 val); andre@0: #define _MD_ATOMIC_ADD _PR_ppc_AtomicAdd andre@0: extern PRInt32 _PR_ppc_AtomicSet(PRInt32 *val, PRInt32 newval); andre@0: #define _MD_ATOMIC_SET _PR_ppc_AtomicSet andre@0: #endif andre@0: andre@0: #if defined(__alpha) andre@0: #define _PR_HAVE_ATOMIC_OPS andre@0: #define _MD_INIT_ATOMIC() andre@0: #define _MD_ATOMIC_ADD(ptr, i) ({ \ andre@0: PRInt32 __atomic_tmp, __atomic_ret; \ andre@0: __asm__ __volatile__( \ andre@0: "1: ldl_l %[ret], %[val] \n" \ andre@0: " addl %[ret], %[inc], %[tmp] \n" \ andre@0: " addl %[ret], %[inc], %[ret] \n" \ andre@0: " stl_c %[tmp], %[val] \n" \ andre@0: " beq %[tmp], 2f \n" \ andre@0: ".subsection 2 \n" \ andre@0: "2: br 1b \n" \ andre@0: ".previous" \ andre@0: : [ret] "=&r" (__atomic_ret), \ andre@0: [tmp] "=&r" (__atomic_tmp), \ andre@0: [val] "=m" (*ptr) \ andre@0: : [inc] "Ir" (i), "m" (*ptr)); \ andre@0: __atomic_ret; \ andre@0: }) andre@0: #define _MD_ATOMIC_INCREMENT(ptr) _MD_ATOMIC_ADD(ptr, 1) andre@0: #define _MD_ATOMIC_DECREMENT(ptr) ({ \ andre@0: PRInt32 __atomic_tmp, __atomic_ret; \ andre@0: __asm__ __volatile__( \ andre@0: "1: ldl_l %[ret], %[val] \n" \ andre@0: " subl %[ret], 1, %[tmp] \n" \ andre@0: " subl %[ret], 1, %[ret] \n" \ andre@0: " stl_c %[tmp], %[val] \n" \ andre@0: " beq %[tmp], 2f \n" \ andre@0: ".subsection 2 \n" \ andre@0: "2: br 1b \n" \ andre@0: ".previous" \ andre@0: : [ret] "=&r" (__atomic_ret), \ andre@0: [tmp] "=&r" (__atomic_tmp), \ andre@0: [val] "=m" (*ptr) \ andre@0: : "m" (*ptr)); \ andre@0: __atomic_ret; \ andre@0: }) andre@0: #define _MD_ATOMIC_SET(ptr, n) ({ \ andre@0: PRInt32 __atomic_tmp, __atomic_ret; \ andre@0: __asm__ __volatile__( \ andre@0: "1: ldl_l %[ret], %[val] \n" \ andre@0: " mov %[newval], %[tmp] \n" \ andre@0: " stl_c %[tmp], %[val] \n" \ andre@0: " beq %[tmp], 2f \n" \ andre@0: ".subsection 2 \n" \ andre@0: "2: br 1b \n" \ andre@0: ".previous" \ andre@0: : [ret] "=&r" (__atomic_ret), \ andre@0: [tmp] "=&r"(__atomic_tmp), \ andre@0: [val] "=m" (*ptr) \ andre@0: : [newval] "Ir" (n), "m" (*ptr)); \ andre@0: __atomic_ret; \ andre@0: }) andre@0: #endif andre@0: andre@0: #if defined(__arm__) || defined(__aarch64__) andre@0: #if defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4) andre@0: /* Use GCC built-in functions */ andre@0: #define _PR_HAVE_ATOMIC_OPS andre@0: #define _MD_INIT_ATOMIC() andre@0: andre@0: #define _MD_ATOMIC_INCREMENT(ptr) __sync_add_and_fetch(ptr, 1) andre@0: #define _MD_ATOMIC_DECREMENT(ptr) __sync_sub_and_fetch(ptr, 1) andre@0: #define _MD_ATOMIC_SET(ptr, nv) __sync_lock_test_and_set(ptr, nv) andre@0: #define _MD_ATOMIC_ADD(ptr, i) __sync_add_and_fetch(ptr, i) andre@0: andre@0: #elif defined(_PR_ARM_KUSER) andre@0: #define _PR_HAVE_ATOMIC_OPS andre@0: #define _MD_INIT_ATOMIC() andre@0: andre@0: /* andre@0: * The kernel provides this helper function at a fixed address with a fixed andre@0: * ABI signature, directly callable from user space. andre@0: * andre@0: * Definition: andre@0: * Atomically store newval in *ptr if *ptr is equal to oldval. andre@0: * Return zero if *ptr was changed or non-zero if no exchange happened. andre@0: */ andre@0: typedef int (__kernel_cmpxchg_t)(int oldval, int newval, volatile int *ptr); andre@0: #define __kernel_cmpxchg (*(__kernel_cmpxchg_t *)0xffff0fc0) andre@0: andre@0: #define _MD_ATOMIC_INCREMENT(ptr) _MD_ATOMIC_ADD(ptr, 1) andre@0: #define _MD_ATOMIC_DECREMENT(ptr) _MD_ATOMIC_ADD(ptr, -1) andre@0: andre@0: static inline PRInt32 _MD_ATOMIC_ADD(PRInt32 *ptr, PRInt32 n) andre@0: { andre@0: PRInt32 ov, nv; andre@0: volatile PRInt32 *vp = ptr; andre@0: andre@0: do { andre@0: ov = *vp; andre@0: nv = ov + n; andre@0: } while (__kernel_cmpxchg(ov, nv, vp)); andre@0: andre@0: return nv; andre@0: } andre@0: andre@0: static inline PRInt32 _MD_ATOMIC_SET(PRInt32 *ptr, PRInt32 nv) andre@0: { andre@0: PRInt32 ov; andre@0: volatile PRInt32 *vp = ptr; andre@0: andre@0: do { andre@0: ov = *vp; andre@0: } while (__kernel_cmpxchg(ov, nv, vp)); andre@0: andre@0: return ov; andre@0: } andre@0: #endif andre@0: #endif /* __arm__ */ andre@0: andre@0: #define USE_SETJMP andre@0: #if (defined(__GLIBC__) && __GLIBC__ >= 2) || defined(ANDROID) andre@0: #define _PR_POLL_AVAILABLE andre@0: #endif andre@0: #undef _PR_USE_POLL andre@0: #define _PR_STAT_HAS_ONLY_ST_ATIME andre@0: #if defined(__alpha) || defined(__ia64__) andre@0: #define _PR_HAVE_LARGE_OFF_T andre@0: #elif (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1) \ andre@0: || defined(ANDROID) andre@0: #define _PR_HAVE_OFF64_T andre@0: #else andre@0: #define _PR_NO_LARGE_FILES andre@0: #endif andre@0: #if (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1) \ andre@0: || defined(ANDROID) andre@0: #define _PR_INET6 andre@0: #define _PR_HAVE_INET_NTOP andre@0: #define _PR_HAVE_GETHOSTBYNAME2 andre@0: #define _PR_HAVE_GETADDRINFO andre@0: #define _PR_INET6_PROBE andre@0: #endif andre@0: #ifndef ANDROID andre@0: #define _PR_HAVE_SYSV_SEMAPHORES andre@0: #define PR_HAVE_SYSV_NAMED_SHARED_MEMORY andre@0: #endif andre@0: /* Android has gethostbyname_r but not gethostbyaddr_r or gethostbyname2_r. */ andre@0: #if (__GLIBC__ >= 2) && defined(_PR_PTHREADS) andre@0: #define _PR_HAVE_GETHOST_R andre@0: #define _PR_HAVE_GETHOST_R_INT andre@0: #endif andre@0: andre@0: #ifdef _PR_PTHREADS andre@0: andre@0: extern void _MD_CleanupBeforeExit(void); andre@0: #define _MD_CLEANUP_BEFORE_EXIT _MD_CleanupBeforeExit andre@0: andre@0: #else /* ! _PR_PTHREADS */ andre@0: andre@0: #include andre@0: andre@0: #define PR_CONTEXT_TYPE sigjmp_buf andre@0: andre@0: #define CONTEXT(_th) ((_th)->md.context) andre@0: andre@0: #ifdef __powerpc__ andre@0: /* andre@0: * PowerPC based MkLinux andre@0: * andre@0: * On the PowerPC, the new style jmp_buf isn't used until glibc andre@0: * 2.1. andre@0: */ andre@0: #if (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1) andre@0: #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[JB_GPR1] andre@0: #else andre@0: #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__misc[0] andre@0: #endif /* glibc 2.1 or later */ andre@0: #define _MD_SET_FP(_t, val) andre@0: #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t)) andre@0: #define _MD_GET_FP_PTR(_t) ((void *) 0) andre@0: /* aix = 64, macos = 70 */ andre@0: #define PR_NUM_GCREGS 64 andre@0: andre@0: #elif defined(__alpha) andre@0: /* Alpha based Linux */ andre@0: andre@0: #if defined(__GLIBC__) && __GLIBC__ >= 2 andre@0: #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[JB_SP] andre@0: #define _MD_SET_FP(_t, val) andre@0: #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t)) andre@0: #define _MD_GET_FP_PTR(_t) ((void *) 0) andre@0: #define _MD_SP_TYPE long int andre@0: #else andre@0: #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__sp andre@0: #define _MD_SET_FP(_t, val) andre@0: #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t)) andre@0: #define _MD_GET_FP_PTR(_t) ((void *) 0) andre@0: #define _MD_SP_TYPE __ptr_t andre@0: #endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */ andre@0: andre@0: /* XXX not sure if this is correct, or maybe it should be 17? */ andre@0: #define PR_NUM_GCREGS 9 andre@0: andre@0: #elif defined(__ia64__) andre@0: andre@0: #define _MD_GET_SP(_t) ((long *)((_t)->md.context[0].__jmpbuf)[0]) andre@0: #define _MD_SET_FP(_t, val) andre@0: #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t)) andre@0: #define _MD_GET_FP_PTR(_t) ((void *) 0) andre@0: #define _MD_SP_TYPE long int andre@0: andre@0: #define PR_NUM_GCREGS _JBLEN andre@0: andre@0: #elif defined(__mc68000__) andre@0: /* m68k based Linux */ andre@0: andre@0: /* andre@0: * On the m68k, glibc still uses the old style sigjmp_buf, even andre@0: * in glibc 2.0.7. andre@0: */ andre@0: #if defined(__GLIBC__) && __GLIBC__ >= 2 andre@0: #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__sp andre@0: #define _MD_SET_FP(_t, val) andre@0: #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t)) andre@0: #define _MD_GET_FP_PTR(_t) ((void *) 0) andre@0: #define _MD_SP_TYPE int andre@0: #else andre@0: #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__sp andre@0: #define _MD_SET_FP(_t, val) andre@0: #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t)) andre@0: #define _MD_GET_FP_PTR(_t) ((void *) 0) andre@0: #define _MD_SP_TYPE __ptr_t andre@0: #endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */ andre@0: andre@0: /* XXX not sure if this is correct, or maybe it should be 17? */ andre@0: #define PR_NUM_GCREGS 9 andre@0: andre@0: #elif defined(__sparc__) andre@0: /* Sparc */ andre@0: #if defined(__GLIBC__) && __GLIBC__ >= 2 andre@0: /* andre@0: * You need glibc2-2.0.7-25 or later. The libraries that came with andre@0: * Red Hat 5.1 are not new enough, but they are in 5.2. andre@0: */ andre@0: #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[JB_SP] andre@0: #define _MD_SET_FP(_t, val) ((_t)->md.context[0].__jmpbuf[JB_FP] = val) andre@0: #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t)) andre@0: #define _MD_GET_FP_PTR(_t) (&(_t)->md.context[0].__jmpbuf[JB_FP]) andre@0: #define _MD_SP_TYPE int andre@0: #else andre@0: #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__fp andre@0: #define _MD_SET_FP(_t, val) andre@0: #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t)) andre@0: #define _MD_GET_FP_PTR(_t) ((void *) 0) andre@0: #define _MD_SP_TYPE __ptr_t andre@0: #endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */ andre@0: andre@0: #elif defined(__i386__) andre@0: /* Intel based Linux */ andre@0: #if defined(__GLIBC__) && __GLIBC__ >= 2 andre@0: #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[JB_SP] andre@0: #define _MD_SET_FP(_t, val) ((_t)->md.context[0].__jmpbuf[JB_BP] = val) andre@0: #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t)) andre@0: #define _MD_GET_FP_PTR(_t) (&(_t)->md.context[0].__jmpbuf[JB_BP]) andre@0: #define _MD_SP_TYPE int andre@0: #else andre@0: #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__sp andre@0: #define _MD_SET_FP(_t, val) ((_t)->md.context[0].__jmpbuf[0].__bp = val) andre@0: #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t)) andre@0: #define _MD_GET_FP_PTR(_t) &((_t)->md.context[0].__jmpbuf[0].__bp) andre@0: #define _MD_SP_TYPE __ptr_t andre@0: #endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */ andre@0: #define PR_NUM_GCREGS 6 andre@0: andre@0: #elif defined(__mips__) andre@0: /* Linux/MIPS */ andre@0: #if defined(__GLIBC__) && __GLIBC__ >= 2 andre@0: #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__sp andre@0: #define _MD_SET_FP(_t, val) ((_t)->md.context[0].__jmpbuf[0].__fp = (val)) andre@0: #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t)) andre@0: #define _MD_GET_FP_PTR(_t) (&(_t)->md.context[0].__jmpbuf[0].__fp) andre@0: #define _MD_SP_TYPE __ptr_t andre@0: #else andre@0: #error "Linux/MIPS pre-glibc2 not supported yet" andre@0: #endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */ andre@0: andre@0: #elif defined(__arm__) andre@0: /* ARM/Linux */ andre@0: #if defined(__GLIBC__) && __GLIBC__ >= 2 andre@0: #ifdef __ARM_EABI__ andre@0: /* EABI */ andre@0: #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[8] andre@0: #define _MD_SET_FP(_t, val) ((_t)->md.context[0].__jmpbuf[7] = (val)) andre@0: #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t)) andre@0: #define _MD_GET_FP_PTR(_t) (&(_t)->md.context[0].__jmpbuf[7]) andre@0: #define _MD_SP_TYPE __ptr_t andre@0: #else /* __ARM_EABI__ */ andre@0: /* old ABI */ andre@0: #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[20] andre@0: #define _MD_SET_FP(_t, val) ((_t)->md.context[0].__jmpbuf[19] = (val)) andre@0: #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t)) andre@0: #define _MD_GET_FP_PTR(_t) (&(_t)->md.context[0].__jmpbuf[19]) andre@0: #define _MD_SP_TYPE __ptr_t andre@0: #endif /* __ARM_EABI__ */ andre@0: #else andre@0: #error "ARM/Linux pre-glibc2 not supported yet" andre@0: #endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */ andre@0: andre@0: #elif defined(__sh__) andre@0: /* SH/Linux */ andre@0: #if defined(__GLIBC__) && __GLIBC__ >= 2 andre@0: #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[7] andre@0: #define _MD_SET_FP(_t, val) ((_t)->md.context[0].__jmpbuf[6] = (val)) andre@0: #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t)) andre@0: #define _MD_GET_FP_PTR(_t) (&(_t)->md.context[0].__jmpbuf[6]) andre@0: #define _MD_SP_TYPE __ptr_t andre@0: #else andre@0: #error "SH/Linux pre-glibc2 not supported yet" andre@0: #endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */ andre@0: andre@0: #elif defined(__m32r__) andre@0: /* Linux/M32R */ andre@0: #if defined(__GLIBC__) && __GLIBC__ >= 2 andre@0: #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__regs[JB_SP] andre@0: #define _MD_SET_FP(_t, val) ((_t)->md.context[0].__jmpbuf[0].__regs[JB_FP] = (val)) andre@0: #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t)) andre@0: #define _MD_GET_FP_PTR(_t) (&(_t)->md.context[0].__jmpbuf[0].__regs[JB_FP]) andre@0: #define _MD_SP_TYPE __ptr_t andre@0: #else andre@0: #error "Linux/M32R pre-glibc2 not supported yet" andre@0: #endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */ andre@0: andre@0: #else andre@0: andre@0: #error "Unknown CPU architecture" andre@0: andre@0: #endif /*__powerpc__*/ andre@0: andre@0: /* andre@0: ** Initialize a thread context to run "_main()" when started andre@0: */ andre@0: #ifdef __powerpc__ andre@0: andre@0: #define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \ andre@0: { \ andre@0: *status = PR_TRUE; \ andre@0: if (sigsetjmp(CONTEXT(_thread), 1)) { \ andre@0: _main(); \ andre@0: } \ andre@0: _MD_GET_SP(_thread) = (unsigned char*) ((_sp) - 128); \ andre@0: _thread->md.sp = _MD_GET_SP_PTR(_thread); \ andre@0: _thread->md.fp = _MD_GET_FP_PTR(_thread); \ andre@0: _MD_SET_FP(_thread, 0); \ andre@0: } andre@0: andre@0: #elif defined(__mips__) andre@0: andre@0: #define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \ andre@0: { \ andre@0: *status = PR_TRUE; \ andre@0: (void) sigsetjmp(CONTEXT(_thread), 1); \ andre@0: _thread->md.context[0].__jmpbuf[0].__pc = (__ptr_t) _main; \ andre@0: _MD_GET_SP(_thread) = (_MD_SP_TYPE) ((_sp) - 64); \ andre@0: _thread->md.sp = _MD_GET_SP_PTR(_thread); \ andre@0: _thread->md.fp = _MD_GET_FP_PTR(_thread); \ andre@0: _MD_SET_FP(_thread, 0); \ andre@0: } andre@0: andre@0: #else andre@0: andre@0: #define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \ andre@0: { \ andre@0: *status = PR_TRUE; \ andre@0: if (sigsetjmp(CONTEXT(_thread), 1)) { \ andre@0: _main(); \ andre@0: } \ andre@0: _MD_GET_SP(_thread) = (_MD_SP_TYPE) ((_sp) - 64); \ andre@0: _thread->md.sp = _MD_GET_SP_PTR(_thread); \ andre@0: _thread->md.fp = _MD_GET_FP_PTR(_thread); \ andre@0: _MD_SET_FP(_thread, 0); \ andre@0: } andre@0: andre@0: #endif /*__powerpc__*/ andre@0: andre@0: #define _MD_SWITCH_CONTEXT(_thread) \ andre@0: if (!sigsetjmp(CONTEXT(_thread), 1)) { \ andre@0: (_thread)->md.errcode = errno; \ andre@0: _PR_Schedule(); \ andre@0: } andre@0: andre@0: /* andre@0: ** Restore a thread context, saved by _MD_SWITCH_CONTEXT andre@0: */ andre@0: #define _MD_RESTORE_CONTEXT(_thread) \ andre@0: { \ andre@0: errno = (_thread)->md.errcode; \ andre@0: _MD_SET_CURRENT_THREAD(_thread); \ andre@0: siglongjmp(CONTEXT(_thread), 1); \ andre@0: } andre@0: andre@0: /* Machine-dependent (MD) data structures */ andre@0: andre@0: struct _MDThread { andre@0: PR_CONTEXT_TYPE context; andre@0: void *sp; andre@0: void *fp; andre@0: int id; andre@0: int errcode; andre@0: }; andre@0: andre@0: struct _MDThreadStack { andre@0: PRInt8 notused; andre@0: }; andre@0: andre@0: struct _MDLock { andre@0: PRInt8 notused; andre@0: }; andre@0: andre@0: struct _MDSemaphore { andre@0: PRInt8 notused; andre@0: }; andre@0: andre@0: struct _MDCVar { andre@0: PRInt8 notused; andre@0: }; andre@0: andre@0: struct _MDSegment { andre@0: PRInt8 notused; andre@0: }; andre@0: andre@0: /* andre@0: * md-specific cpu structure field andre@0: */ andre@0: #include /* for FD_SETSIZE */ andre@0: #define _PR_MD_MAX_OSFD FD_SETSIZE andre@0: andre@0: struct _MDCPU_Unix { andre@0: PRCList ioQ; andre@0: PRUint32 ioq_timeout; andre@0: PRInt32 ioq_max_osfd; andre@0: PRInt32 ioq_osfd_cnt; andre@0: #ifndef _PR_USE_POLL andre@0: fd_set fd_read_set, fd_write_set, fd_exception_set; andre@0: PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD], andre@0: fd_exception_cnt[_PR_MD_MAX_OSFD]; andre@0: #else andre@0: struct pollfd *ioq_pollfds; andre@0: int ioq_pollfds_size; andre@0: #endif /* _PR_USE_POLL */ andre@0: }; andre@0: andre@0: #define _PR_IOQ(_cpu) ((_cpu)->md.md_unix.ioQ) andre@0: #define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu)) andre@0: #define _PR_FD_READ_SET(_cpu) ((_cpu)->md.md_unix.fd_read_set) andre@0: #define _PR_FD_READ_CNT(_cpu) ((_cpu)->md.md_unix.fd_read_cnt) andre@0: #define _PR_FD_WRITE_SET(_cpu) ((_cpu)->md.md_unix.fd_write_set) andre@0: #define _PR_FD_WRITE_CNT(_cpu) ((_cpu)->md.md_unix.fd_write_cnt) andre@0: #define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set) andre@0: #define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt) andre@0: #define _PR_IOQ_TIMEOUT(_cpu) ((_cpu)->md.md_unix.ioq_timeout) andre@0: #define _PR_IOQ_MAX_OSFD(_cpu) ((_cpu)->md.md_unix.ioq_max_osfd) andre@0: #define _PR_IOQ_OSFD_CNT(_cpu) ((_cpu)->md.md_unix.ioq_osfd_cnt) andre@0: #define _PR_IOQ_POLLFDS(_cpu) ((_cpu)->md.md_unix.ioq_pollfds) andre@0: #define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size) andre@0: andre@0: #define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu) 32 andre@0: andre@0: struct _MDCPU { andre@0: struct _MDCPU_Unix md_unix; andre@0: }; andre@0: andre@0: #define _MD_INIT_LOCKS() andre@0: #define _MD_NEW_LOCK(lock) PR_SUCCESS andre@0: #define _MD_FREE_LOCK(lock) andre@0: #define _MD_LOCK(lock) andre@0: #define _MD_UNLOCK(lock) andre@0: #define _MD_INIT_IO() andre@0: #define _MD_IOQ_LOCK() andre@0: #define _MD_IOQ_UNLOCK() andre@0: andre@0: extern PRStatus _MD_InitializeThread(PRThread *thread); andre@0: andre@0: #define _MD_INIT_RUNNING_CPU(cpu) _MD_unix_init_running_cpu(cpu) andre@0: #define _MD_INIT_THREAD _MD_InitializeThread andre@0: #define _MD_EXIT_THREAD(thread) andre@0: #define _MD_SUSPEND_THREAD(thread) _MD_suspend_thread andre@0: #define _MD_RESUME_THREAD(thread) _MD_resume_thread andre@0: #define _MD_CLEAN_THREAD(_thread) andre@0: andre@0: extern PRStatus _MD_CREATE_THREAD( andre@0: PRThread *thread, andre@0: void (*start) (void *), andre@0: PRThreadPriority priority, andre@0: PRThreadScope scope, andre@0: PRThreadState state, andre@0: PRUint32 stackSize); andre@0: extern void _MD_SET_PRIORITY(struct _MDThread *thread, PRUintn newPri); andre@0: extern PRStatus _MD_WAIT(PRThread *, PRIntervalTime timeout); andre@0: extern PRStatus _MD_WAKEUP_WAITER(PRThread *); andre@0: extern void _MD_YIELD(void); andre@0: andre@0: #endif /* ! _PR_PTHREADS */ andre@0: andre@0: extern void _MD_EarlyInit(void); andre@0: andre@0: #define _MD_EARLY_INIT _MD_EarlyInit andre@0: #define _MD_FINAL_INIT _PR_UnixInit andre@0: #define HAVE_CLOCK_MONOTONIC andre@0: andre@0: /* andre@0: * We wrapped the select() call. _MD_SELECT refers to the built-in, andre@0: * unwrapped version. andre@0: */ andre@0: #define _MD_SELECT __select andre@0: andre@0: #ifdef _PR_POLL_AVAILABLE andre@0: #include andre@0: extern int __syscall_poll(struct pollfd *ufds, unsigned long int nfds, andre@0: int timeout); andre@0: #define _MD_POLL __syscall_poll andre@0: #endif andre@0: andre@0: /* For writev() */ andre@0: #include andre@0: andre@0: extern void _MD_linux_map_sendfile_error(int err); andre@0: andre@0: #endif /* nspr_linux_defs_h___ */