1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/nsprpub/pr/include/md/_linux.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,670 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +/* 1.10 + * This file is used by not only Linux but also other glibc systems 1.11 + * such as GNU/Hurd and GNU/k*BSD. 1.12 + */ 1.13 + 1.14 +#ifndef nspr_linux_defs_h___ 1.15 +#define nspr_linux_defs_h___ 1.16 + 1.17 +#include "prthread.h" 1.18 + 1.19 +/* 1.20 + * Internal configuration macros 1.21 + */ 1.22 + 1.23 +#define PR_LINKER_ARCH "linux" 1.24 +#define _PR_SI_SYSNAME "LINUX" 1.25 +#ifdef __powerpc64__ 1.26 +#define _PR_SI_ARCHITECTURE "ppc64" 1.27 +#elif defined(__powerpc__) 1.28 +#define _PR_SI_ARCHITECTURE "ppc" 1.29 +#elif defined(__alpha) 1.30 +#define _PR_SI_ARCHITECTURE "alpha" 1.31 +#elif defined(__ia64__) 1.32 +#define _PR_SI_ARCHITECTURE "ia64" 1.33 +#elif defined(__x86_64__) 1.34 +#define _PR_SI_ARCHITECTURE "x86-64" 1.35 +#elif defined(__mc68000__) 1.36 +#define _PR_SI_ARCHITECTURE "m68k" 1.37 +#elif defined(__sparc__) && defined(__arch64__) 1.38 +#define _PR_SI_ARCHITECTURE "sparc64" 1.39 +#elif defined(__sparc__) 1.40 +#define _PR_SI_ARCHITECTURE "sparc" 1.41 +#elif defined(__i386__) 1.42 +#define _PR_SI_ARCHITECTURE "x86" 1.43 +#elif defined(__mips__) 1.44 +#define _PR_SI_ARCHITECTURE "mips" 1.45 +#elif defined(__arm__) 1.46 +#define _PR_SI_ARCHITECTURE "arm" 1.47 +#elif defined(__aarch64__) 1.48 +#define _PR_SI_ARCHITECTURE "aarch64" 1.49 +#elif defined(__hppa__) 1.50 +#define _PR_SI_ARCHITECTURE "hppa" 1.51 +#elif defined(__s390x__) 1.52 +#define _PR_SI_ARCHITECTURE "s390x" 1.53 +#elif defined(__s390__) 1.54 +#define _PR_SI_ARCHITECTURE "s390" 1.55 +#elif defined(__sh__) 1.56 +#define _PR_SI_ARCHITECTURE "sh" 1.57 +#elif defined(__avr32__) 1.58 +#define _PR_SI_ARCHITECTURE "avr32" 1.59 +#elif defined(__m32r__) 1.60 +#define _PR_SI_ARCHITECTURE "m32r" 1.61 +#else 1.62 +#error "Unknown CPU architecture" 1.63 +#endif 1.64 +#define PR_DLL_SUFFIX ".so" 1.65 + 1.66 +#define _PR_VMBASE 0x30000000 1.67 +#define _PR_STACK_VMBASE 0x50000000 1.68 +#define _MD_DEFAULT_STACK_SIZE 65536L 1.69 +#define _MD_MMAP_FLAGS MAP_PRIVATE 1.70 + 1.71 +#if defined(__aarch64__) 1.72 +#define _MD_MINIMUM_STACK_SIZE 0x20000 1.73 +#endif 1.74 + 1.75 +#undef HAVE_STACK_GROWING_UP 1.76 + 1.77 +/* 1.78 + * Elf linux supports dl* functions 1.79 + */ 1.80 +#define HAVE_DLL 1.81 +#define USE_DLFCN 1.82 +#if defined(ANDROID) 1.83 +#define NO_DLOPEN_NULL 1.84 +#endif 1.85 + 1.86 +#if defined(__FreeBSD_kernel__) || defined(__GNU__) 1.87 +#define _PR_HAVE_SOCKADDR_LEN 1.88 +#endif 1.89 + 1.90 +#if defined(__i386__) 1.91 +#define _PR_HAVE_ATOMIC_OPS 1.92 +#define _MD_INIT_ATOMIC() 1.93 +extern PRInt32 _PR_x86_AtomicIncrement(PRInt32 *val); 1.94 +#define _MD_ATOMIC_INCREMENT _PR_x86_AtomicIncrement 1.95 +extern PRInt32 _PR_x86_AtomicDecrement(PRInt32 *val); 1.96 +#define _MD_ATOMIC_DECREMENT _PR_x86_AtomicDecrement 1.97 +extern PRInt32 _PR_x86_AtomicAdd(PRInt32 *ptr, PRInt32 val); 1.98 +#define _MD_ATOMIC_ADD _PR_x86_AtomicAdd 1.99 +extern PRInt32 _PR_x86_AtomicSet(PRInt32 *val, PRInt32 newval); 1.100 +#define _MD_ATOMIC_SET _PR_x86_AtomicSet 1.101 +#endif 1.102 + 1.103 +#if defined(__ia64__) 1.104 +#define _PR_HAVE_ATOMIC_OPS 1.105 +#define _MD_INIT_ATOMIC() 1.106 +extern PRInt32 _PR_ia64_AtomicIncrement(PRInt32 *val); 1.107 +#define _MD_ATOMIC_INCREMENT _PR_ia64_AtomicIncrement 1.108 +extern PRInt32 _PR_ia64_AtomicDecrement(PRInt32 *val); 1.109 +#define _MD_ATOMIC_DECREMENT _PR_ia64_AtomicDecrement 1.110 +extern PRInt32 _PR_ia64_AtomicAdd(PRInt32 *ptr, PRInt32 val); 1.111 +#define _MD_ATOMIC_ADD _PR_ia64_AtomicAdd 1.112 +extern PRInt32 _PR_ia64_AtomicSet(PRInt32 *val, PRInt32 newval); 1.113 +#define _MD_ATOMIC_SET _PR_ia64_AtomicSet 1.114 +#endif 1.115 + 1.116 +#if defined(__x86_64__) 1.117 +#define _PR_HAVE_ATOMIC_OPS 1.118 +#define _MD_INIT_ATOMIC() 1.119 +extern PRInt32 _PR_x86_64_AtomicIncrement(PRInt32 *val); 1.120 +#define _MD_ATOMIC_INCREMENT _PR_x86_64_AtomicIncrement 1.121 +extern PRInt32 _PR_x86_64_AtomicDecrement(PRInt32 *val); 1.122 +#define _MD_ATOMIC_DECREMENT _PR_x86_64_AtomicDecrement 1.123 +extern PRInt32 _PR_x86_64_AtomicAdd(PRInt32 *ptr, PRInt32 val); 1.124 +#define _MD_ATOMIC_ADD _PR_x86_64_AtomicAdd 1.125 +extern PRInt32 _PR_x86_64_AtomicSet(PRInt32 *val, PRInt32 newval); 1.126 +#define _MD_ATOMIC_SET _PR_x86_64_AtomicSet 1.127 +#endif 1.128 + 1.129 +#if defined(__powerpc__) && !defined(__powerpc64__) 1.130 +#define _PR_HAVE_ATOMIC_OPS 1.131 +#define _MD_INIT_ATOMIC() 1.132 +extern PRInt32 _PR_ppc_AtomicIncrement(PRInt32 *val); 1.133 +#define _MD_ATOMIC_INCREMENT _PR_ppc_AtomicIncrement 1.134 +extern PRInt32 _PR_ppc_AtomicDecrement(PRInt32 *val); 1.135 +#define _MD_ATOMIC_DECREMENT _PR_ppc_AtomicDecrement 1.136 +extern PRInt32 _PR_ppc_AtomicAdd(PRInt32 *ptr, PRInt32 val); 1.137 +#define _MD_ATOMIC_ADD _PR_ppc_AtomicAdd 1.138 +extern PRInt32 _PR_ppc_AtomicSet(PRInt32 *val, PRInt32 newval); 1.139 +#define _MD_ATOMIC_SET _PR_ppc_AtomicSet 1.140 +#endif 1.141 + 1.142 +#if defined(__powerpc64__) 1.143 +#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) 1.144 +/* Use GCC built-in functions */ 1.145 +#define _PR_HAVE_ATOMIC_OPS 1.146 +#define _MD_INIT_ATOMIC() 1.147 +#define _MD_ATOMIC_INCREMENT(ptr) __sync_add_and_fetch(ptr, 1) 1.148 +#define _MD_ATOMIC_DECREMENT(ptr) __sync_sub_and_fetch(ptr, 1) 1.149 +#define _MD_ATOMIC_ADD(ptr, i) __sync_add_and_fetch(ptr, i) 1.150 +#define _MD_ATOMIC_SET(ptr, nv) __sync_lock_test_and_set(ptr, nv) 1.151 +#endif 1.152 +#endif 1.153 + 1.154 +#if defined(__alpha) 1.155 +#define _PR_HAVE_ATOMIC_OPS 1.156 +#define _MD_INIT_ATOMIC() 1.157 +#define _MD_ATOMIC_ADD(ptr, i) ({ \ 1.158 + PRInt32 __atomic_tmp, __atomic_ret; \ 1.159 + __asm__ __volatile__( \ 1.160 + "1: ldl_l %[ret], %[val] \n" \ 1.161 + " addl %[ret], %[inc], %[tmp] \n" \ 1.162 + " addl %[ret], %[inc], %[ret] \n" \ 1.163 + " stl_c %[tmp], %[val] \n" \ 1.164 + " beq %[tmp], 2f \n" \ 1.165 + ".subsection 2 \n" \ 1.166 + "2: br 1b \n" \ 1.167 + ".previous" \ 1.168 + : [ret] "=&r" (__atomic_ret), \ 1.169 + [tmp] "=&r" (__atomic_tmp), \ 1.170 + [val] "=m" (*ptr) \ 1.171 + : [inc] "Ir" (i), "m" (*ptr)); \ 1.172 + __atomic_ret; \ 1.173 +}) 1.174 +#define _MD_ATOMIC_INCREMENT(ptr) _MD_ATOMIC_ADD(ptr, 1) 1.175 +#define _MD_ATOMIC_DECREMENT(ptr) ({ \ 1.176 + PRInt32 __atomic_tmp, __atomic_ret; \ 1.177 + __asm__ __volatile__( \ 1.178 + "1: ldl_l %[ret], %[val] \n" \ 1.179 + " subl %[ret], 1, %[tmp] \n" \ 1.180 + " subl %[ret], 1, %[ret] \n" \ 1.181 + " stl_c %[tmp], %[val] \n" \ 1.182 + " beq %[tmp], 2f \n" \ 1.183 + ".subsection 2 \n" \ 1.184 + "2: br 1b \n" \ 1.185 + ".previous" \ 1.186 + : [ret] "=&r" (__atomic_ret), \ 1.187 + [tmp] "=&r" (__atomic_tmp), \ 1.188 + [val] "=m" (*ptr) \ 1.189 + : "m" (*ptr)); \ 1.190 + __atomic_ret; \ 1.191 +}) 1.192 +#define _MD_ATOMIC_SET(ptr, n) ({ \ 1.193 + PRInt32 __atomic_tmp, __atomic_ret; \ 1.194 + __asm__ __volatile__( \ 1.195 + "1: ldl_l %[ret], %[val] \n" \ 1.196 + " mov %[newval], %[tmp] \n" \ 1.197 + " stl_c %[tmp], %[val] \n" \ 1.198 + " beq %[tmp], 2f \n" \ 1.199 + ".subsection 2 \n" \ 1.200 + "2: br 1b \n" \ 1.201 + ".previous" \ 1.202 + : [ret] "=&r" (__atomic_ret), \ 1.203 + [tmp] "=&r"(__atomic_tmp), \ 1.204 + [val] "=m" (*ptr) \ 1.205 + : [newval] "Ir" (n), "m" (*ptr)); \ 1.206 + __atomic_ret; \ 1.207 +}) 1.208 +#endif 1.209 + 1.210 +#if defined(__arm__) || defined(__aarch64__) 1.211 +#if defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4) 1.212 +/* Use GCC built-in functions */ 1.213 +#define _PR_HAVE_ATOMIC_OPS 1.214 +#define _MD_INIT_ATOMIC() 1.215 + 1.216 +#define _MD_ATOMIC_INCREMENT(ptr) __sync_add_and_fetch(ptr, 1) 1.217 +#define _MD_ATOMIC_DECREMENT(ptr) __sync_sub_and_fetch(ptr, 1) 1.218 +#define _MD_ATOMIC_SET(ptr, nv) __sync_lock_test_and_set(ptr, nv) 1.219 +#define _MD_ATOMIC_ADD(ptr, i) __sync_add_and_fetch(ptr, i) 1.220 + 1.221 +#elif defined(_PR_ARM_KUSER) 1.222 +#define _PR_HAVE_ATOMIC_OPS 1.223 +#define _MD_INIT_ATOMIC() 1.224 + 1.225 +/* 1.226 + * The kernel provides this helper function at a fixed address with a fixed 1.227 + * ABI signature, directly callable from user space. 1.228 + * 1.229 + * Definition: 1.230 + * Atomically store newval in *ptr if *ptr is equal to oldval. 1.231 + * Return zero if *ptr was changed or non-zero if no exchange happened. 1.232 + */ 1.233 +typedef int (__kernel_cmpxchg_t)(int oldval, int newval, volatile int *ptr); 1.234 +#define __kernel_cmpxchg (*(__kernel_cmpxchg_t *)0xffff0fc0) 1.235 + 1.236 +#define _MD_ATOMIC_INCREMENT(ptr) _MD_ATOMIC_ADD(ptr, 1) 1.237 +#define _MD_ATOMIC_DECREMENT(ptr) _MD_ATOMIC_ADD(ptr, -1) 1.238 + 1.239 +static inline PRInt32 _MD_ATOMIC_ADD(PRInt32 *ptr, PRInt32 n) 1.240 +{ 1.241 + PRInt32 ov, nv; 1.242 + volatile PRInt32 *vp = ptr; 1.243 + 1.244 + do { 1.245 + ov = *vp; 1.246 + nv = ov + n; 1.247 + } while (__kernel_cmpxchg(ov, nv, vp)); 1.248 + 1.249 + return nv; 1.250 +} 1.251 + 1.252 +static inline PRInt32 _MD_ATOMIC_SET(PRInt32 *ptr, PRInt32 nv) 1.253 +{ 1.254 + PRInt32 ov; 1.255 + volatile PRInt32 *vp = ptr; 1.256 + 1.257 + do { 1.258 + ov = *vp; 1.259 + } while (__kernel_cmpxchg(ov, nv, vp)); 1.260 + 1.261 + return ov; 1.262 +} 1.263 +#endif 1.264 +#endif /* __arm__ */ 1.265 + 1.266 +#define USE_SETJMP 1.267 +#if (defined(__GLIBC__) && __GLIBC__ >= 2) || defined(ANDROID) 1.268 +#define _PR_POLL_AVAILABLE 1.269 +#endif 1.270 +#undef _PR_USE_POLL 1.271 +#define _PR_STAT_HAS_ONLY_ST_ATIME 1.272 +#if defined(__alpha) || defined(__ia64__) 1.273 +#define _PR_HAVE_LARGE_OFF_T 1.274 +#elif (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1) \ 1.275 + || defined(ANDROID) 1.276 +#define _PR_HAVE_OFF64_T 1.277 +#else 1.278 +#define _PR_NO_LARGE_FILES 1.279 +#endif 1.280 +#if (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1) \ 1.281 + || defined(ANDROID) 1.282 +#define _PR_INET6 1.283 +#define _PR_HAVE_INET_NTOP 1.284 +#define _PR_HAVE_GETHOSTBYNAME2 1.285 +#define _PR_HAVE_GETADDRINFO 1.286 +#define _PR_INET6_PROBE 1.287 +#endif 1.288 +#ifndef ANDROID 1.289 +#define _PR_HAVE_SYSV_SEMAPHORES 1.290 +#define PR_HAVE_SYSV_NAMED_SHARED_MEMORY 1.291 +#endif 1.292 +/* Android has gethostbyname_r but not gethostbyaddr_r or gethostbyname2_r. */ 1.293 +#if (__GLIBC__ >= 2) && defined(_PR_PTHREADS) 1.294 +#define _PR_HAVE_GETHOST_R 1.295 +#define _PR_HAVE_GETHOST_R_INT 1.296 +#endif 1.297 + 1.298 +#ifdef _PR_PTHREADS 1.299 + 1.300 +extern void _MD_CleanupBeforeExit(void); 1.301 +#define _MD_CLEANUP_BEFORE_EXIT _MD_CleanupBeforeExit 1.302 + 1.303 +#else /* ! _PR_PTHREADS */ 1.304 + 1.305 +#include <setjmp.h> 1.306 + 1.307 +#define PR_CONTEXT_TYPE sigjmp_buf 1.308 + 1.309 +#define CONTEXT(_th) ((_th)->md.context) 1.310 + 1.311 +#ifdef __powerpc__ 1.312 +/* 1.313 + * PowerPC based MkLinux 1.314 + * 1.315 + * On the PowerPC, the new style jmp_buf isn't used until glibc 1.316 + * 2.1. 1.317 + */ 1.318 +#if (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1) 1.319 +#define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[JB_GPR1] 1.320 +#else 1.321 +#define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__misc[0] 1.322 +#endif /* glibc 2.1 or later */ 1.323 +#define _MD_SET_FP(_t, val) 1.324 +#define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t)) 1.325 +#define _MD_GET_FP_PTR(_t) ((void *) 0) 1.326 +/* aix = 64, macos = 70 */ 1.327 +#define PR_NUM_GCREGS 64 1.328 + 1.329 +#elif defined(__alpha) 1.330 +/* Alpha based Linux */ 1.331 + 1.332 +#if defined(__GLIBC__) && __GLIBC__ >= 2 1.333 +#define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[JB_SP] 1.334 +#define _MD_SET_FP(_t, val) 1.335 +#define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t)) 1.336 +#define _MD_GET_FP_PTR(_t) ((void *) 0) 1.337 +#define _MD_SP_TYPE long int 1.338 +#else 1.339 +#define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__sp 1.340 +#define _MD_SET_FP(_t, val) 1.341 +#define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t)) 1.342 +#define _MD_GET_FP_PTR(_t) ((void *) 0) 1.343 +#define _MD_SP_TYPE __ptr_t 1.344 +#endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */ 1.345 + 1.346 +/* XXX not sure if this is correct, or maybe it should be 17? */ 1.347 +#define PR_NUM_GCREGS 9 1.348 + 1.349 +#elif defined(__ia64__) 1.350 + 1.351 +#define _MD_GET_SP(_t) ((long *)((_t)->md.context[0].__jmpbuf)[0]) 1.352 +#define _MD_SET_FP(_t, val) 1.353 +#define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t)) 1.354 +#define _MD_GET_FP_PTR(_t) ((void *) 0) 1.355 +#define _MD_SP_TYPE long int 1.356 + 1.357 +#define PR_NUM_GCREGS _JBLEN 1.358 + 1.359 +#elif defined(__mc68000__) 1.360 +/* m68k based Linux */ 1.361 + 1.362 +/* 1.363 + * On the m68k, glibc still uses the old style sigjmp_buf, even 1.364 + * in glibc 2.0.7. 1.365 + */ 1.366 +#if defined(__GLIBC__) && __GLIBC__ >= 2 1.367 +#define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__sp 1.368 +#define _MD_SET_FP(_t, val) 1.369 +#define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t)) 1.370 +#define _MD_GET_FP_PTR(_t) ((void *) 0) 1.371 +#define _MD_SP_TYPE int 1.372 +#else 1.373 +#define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__sp 1.374 +#define _MD_SET_FP(_t, val) 1.375 +#define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t)) 1.376 +#define _MD_GET_FP_PTR(_t) ((void *) 0) 1.377 +#define _MD_SP_TYPE __ptr_t 1.378 +#endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */ 1.379 + 1.380 +/* XXX not sure if this is correct, or maybe it should be 17? */ 1.381 +#define PR_NUM_GCREGS 9 1.382 + 1.383 +#elif defined(__sparc__) 1.384 +/* Sparc */ 1.385 +#if defined(__GLIBC__) && __GLIBC__ >= 2 1.386 +/* 1.387 + * You need glibc2-2.0.7-25 or later. The libraries that came with 1.388 + * Red Hat 5.1 are not new enough, but they are in 5.2. 1.389 + */ 1.390 +#define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[JB_SP] 1.391 +#define _MD_SET_FP(_t, val) ((_t)->md.context[0].__jmpbuf[JB_FP] = val) 1.392 +#define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t)) 1.393 +#define _MD_GET_FP_PTR(_t) (&(_t)->md.context[0].__jmpbuf[JB_FP]) 1.394 +#define _MD_SP_TYPE int 1.395 +#else 1.396 +#define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__fp 1.397 +#define _MD_SET_FP(_t, val) 1.398 +#define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t)) 1.399 +#define _MD_GET_FP_PTR(_t) ((void *) 0) 1.400 +#define _MD_SP_TYPE __ptr_t 1.401 +#endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */ 1.402 + 1.403 +#elif defined(__i386__) 1.404 +/* Intel based Linux */ 1.405 +#if defined(__GLIBC__) && __GLIBC__ >= 2 1.406 +#define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[JB_SP] 1.407 +#define _MD_SET_FP(_t, val) ((_t)->md.context[0].__jmpbuf[JB_BP] = val) 1.408 +#define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t)) 1.409 +#define _MD_GET_FP_PTR(_t) (&(_t)->md.context[0].__jmpbuf[JB_BP]) 1.410 +#define _MD_SP_TYPE int 1.411 +#else 1.412 +#define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__sp 1.413 +#define _MD_SET_FP(_t, val) ((_t)->md.context[0].__jmpbuf[0].__bp = val) 1.414 +#define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t)) 1.415 +#define _MD_GET_FP_PTR(_t) &((_t)->md.context[0].__jmpbuf[0].__bp) 1.416 +#define _MD_SP_TYPE __ptr_t 1.417 +#endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */ 1.418 +#define PR_NUM_GCREGS 6 1.419 + 1.420 +#elif defined(__mips__) 1.421 +/* Linux/MIPS */ 1.422 +#if defined(__GLIBC__) && __GLIBC__ >= 2 1.423 +#define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__sp 1.424 +#define _MD_SET_FP(_t, val) ((_t)->md.context[0].__jmpbuf[0].__fp = (val)) 1.425 +#define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t)) 1.426 +#define _MD_GET_FP_PTR(_t) (&(_t)->md.context[0].__jmpbuf[0].__fp) 1.427 +#define _MD_SP_TYPE __ptr_t 1.428 +#else 1.429 +#error "Linux/MIPS pre-glibc2 not supported yet" 1.430 +#endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */ 1.431 + 1.432 +#elif defined(__arm__) 1.433 +/* ARM/Linux */ 1.434 +#if defined(__GLIBC__) && __GLIBC__ >= 2 1.435 +#ifdef __ARM_EABI__ 1.436 +/* EABI */ 1.437 +#define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[8] 1.438 +#define _MD_SET_FP(_t, val) ((_t)->md.context[0].__jmpbuf[7] = (val)) 1.439 +#define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t)) 1.440 +#define _MD_GET_FP_PTR(_t) (&(_t)->md.context[0].__jmpbuf[7]) 1.441 +#define _MD_SP_TYPE __ptr_t 1.442 +#else /* __ARM_EABI__ */ 1.443 +/* old ABI */ 1.444 +#define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[20] 1.445 +#define _MD_SET_FP(_t, val) ((_t)->md.context[0].__jmpbuf[19] = (val)) 1.446 +#define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t)) 1.447 +#define _MD_GET_FP_PTR(_t) (&(_t)->md.context[0].__jmpbuf[19]) 1.448 +#define _MD_SP_TYPE __ptr_t 1.449 +#endif /* __ARM_EABI__ */ 1.450 +#else 1.451 +#error "ARM/Linux pre-glibc2 not supported yet" 1.452 +#endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */ 1.453 + 1.454 +#elif defined(__sh__) 1.455 +/* SH/Linux */ 1.456 +#if defined(__GLIBC__) && __GLIBC__ >= 2 1.457 +#define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[7] 1.458 +#define _MD_SET_FP(_t, val) ((_t)->md.context[0].__jmpbuf[6] = (val)) 1.459 +#define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t)) 1.460 +#define _MD_GET_FP_PTR(_t) (&(_t)->md.context[0].__jmpbuf[6]) 1.461 +#define _MD_SP_TYPE __ptr_t 1.462 +#else 1.463 +#error "SH/Linux pre-glibc2 not supported yet" 1.464 +#endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */ 1.465 + 1.466 +#elif defined(__m32r__) 1.467 +/* Linux/M32R */ 1.468 +#if defined(__GLIBC__) && __GLIBC__ >= 2 1.469 +#define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__regs[JB_SP] 1.470 +#define _MD_SET_FP(_t, val) ((_t)->md.context[0].__jmpbuf[0].__regs[JB_FP] = (val)) 1.471 +#define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t)) 1.472 +#define _MD_GET_FP_PTR(_t) (&(_t)->md.context[0].__jmpbuf[0].__regs[JB_FP]) 1.473 +#define _MD_SP_TYPE __ptr_t 1.474 +#else 1.475 +#error "Linux/M32R pre-glibc2 not supported yet" 1.476 +#endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */ 1.477 + 1.478 +#else 1.479 + 1.480 +#error "Unknown CPU architecture" 1.481 + 1.482 +#endif /*__powerpc__*/ 1.483 + 1.484 +/* 1.485 +** Initialize a thread context to run "_main()" when started 1.486 +*/ 1.487 +#ifdef __powerpc__ 1.488 + 1.489 +#define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \ 1.490 +{ \ 1.491 + *status = PR_TRUE; \ 1.492 + if (sigsetjmp(CONTEXT(_thread), 1)) { \ 1.493 + _main(); \ 1.494 + } \ 1.495 + _MD_GET_SP(_thread) = (unsigned char*) ((_sp) - 128); \ 1.496 + _thread->md.sp = _MD_GET_SP_PTR(_thread); \ 1.497 + _thread->md.fp = _MD_GET_FP_PTR(_thread); \ 1.498 + _MD_SET_FP(_thread, 0); \ 1.499 +} 1.500 + 1.501 +#elif defined(__mips__) 1.502 + 1.503 +#define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \ 1.504 +{ \ 1.505 + *status = PR_TRUE; \ 1.506 + (void) sigsetjmp(CONTEXT(_thread), 1); \ 1.507 + _thread->md.context[0].__jmpbuf[0].__pc = (__ptr_t) _main; \ 1.508 + _MD_GET_SP(_thread) = (_MD_SP_TYPE) ((_sp) - 64); \ 1.509 + _thread->md.sp = _MD_GET_SP_PTR(_thread); \ 1.510 + _thread->md.fp = _MD_GET_FP_PTR(_thread); \ 1.511 + _MD_SET_FP(_thread, 0); \ 1.512 +} 1.513 + 1.514 +#else 1.515 + 1.516 +#define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \ 1.517 +{ \ 1.518 + *status = PR_TRUE; \ 1.519 + if (sigsetjmp(CONTEXT(_thread), 1)) { \ 1.520 + _main(); \ 1.521 + } \ 1.522 + _MD_GET_SP(_thread) = (_MD_SP_TYPE) ((_sp) - 64); \ 1.523 + _thread->md.sp = _MD_GET_SP_PTR(_thread); \ 1.524 + _thread->md.fp = _MD_GET_FP_PTR(_thread); \ 1.525 + _MD_SET_FP(_thread, 0); \ 1.526 +} 1.527 + 1.528 +#endif /*__powerpc__*/ 1.529 + 1.530 +#define _MD_SWITCH_CONTEXT(_thread) \ 1.531 + if (!sigsetjmp(CONTEXT(_thread), 1)) { \ 1.532 + (_thread)->md.errcode = errno; \ 1.533 + _PR_Schedule(); \ 1.534 + } 1.535 + 1.536 +/* 1.537 +** Restore a thread context, saved by _MD_SWITCH_CONTEXT 1.538 +*/ 1.539 +#define _MD_RESTORE_CONTEXT(_thread) \ 1.540 +{ \ 1.541 + errno = (_thread)->md.errcode; \ 1.542 + _MD_SET_CURRENT_THREAD(_thread); \ 1.543 + siglongjmp(CONTEXT(_thread), 1); \ 1.544 +} 1.545 + 1.546 +/* Machine-dependent (MD) data structures */ 1.547 + 1.548 +struct _MDThread { 1.549 + PR_CONTEXT_TYPE context; 1.550 + void *sp; 1.551 + void *fp; 1.552 + int id; 1.553 + int errcode; 1.554 +}; 1.555 + 1.556 +struct _MDThreadStack { 1.557 + PRInt8 notused; 1.558 +}; 1.559 + 1.560 +struct _MDLock { 1.561 + PRInt8 notused; 1.562 +}; 1.563 + 1.564 +struct _MDSemaphore { 1.565 + PRInt8 notused; 1.566 +}; 1.567 + 1.568 +struct _MDCVar { 1.569 + PRInt8 notused; 1.570 +}; 1.571 + 1.572 +struct _MDSegment { 1.573 + PRInt8 notused; 1.574 +}; 1.575 + 1.576 +/* 1.577 + * md-specific cpu structure field 1.578 + */ 1.579 +#include <sys/time.h> /* for FD_SETSIZE */ 1.580 +#define _PR_MD_MAX_OSFD FD_SETSIZE 1.581 + 1.582 +struct _MDCPU_Unix { 1.583 + PRCList ioQ; 1.584 + PRUint32 ioq_timeout; 1.585 + PRInt32 ioq_max_osfd; 1.586 + PRInt32 ioq_osfd_cnt; 1.587 +#ifndef _PR_USE_POLL 1.588 + fd_set fd_read_set, fd_write_set, fd_exception_set; 1.589 + PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD], 1.590 + fd_exception_cnt[_PR_MD_MAX_OSFD]; 1.591 +#else 1.592 + struct pollfd *ioq_pollfds; 1.593 + int ioq_pollfds_size; 1.594 +#endif /* _PR_USE_POLL */ 1.595 +}; 1.596 + 1.597 +#define _PR_IOQ(_cpu) ((_cpu)->md.md_unix.ioQ) 1.598 +#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu)) 1.599 +#define _PR_FD_READ_SET(_cpu) ((_cpu)->md.md_unix.fd_read_set) 1.600 +#define _PR_FD_READ_CNT(_cpu) ((_cpu)->md.md_unix.fd_read_cnt) 1.601 +#define _PR_FD_WRITE_SET(_cpu) ((_cpu)->md.md_unix.fd_write_set) 1.602 +#define _PR_FD_WRITE_CNT(_cpu) ((_cpu)->md.md_unix.fd_write_cnt) 1.603 +#define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set) 1.604 +#define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt) 1.605 +#define _PR_IOQ_TIMEOUT(_cpu) ((_cpu)->md.md_unix.ioq_timeout) 1.606 +#define _PR_IOQ_MAX_OSFD(_cpu) ((_cpu)->md.md_unix.ioq_max_osfd) 1.607 +#define _PR_IOQ_OSFD_CNT(_cpu) ((_cpu)->md.md_unix.ioq_osfd_cnt) 1.608 +#define _PR_IOQ_POLLFDS(_cpu) ((_cpu)->md.md_unix.ioq_pollfds) 1.609 +#define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size) 1.610 + 1.611 +#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu) 32 1.612 + 1.613 +struct _MDCPU { 1.614 + struct _MDCPU_Unix md_unix; 1.615 +}; 1.616 + 1.617 +#define _MD_INIT_LOCKS() 1.618 +#define _MD_NEW_LOCK(lock) PR_SUCCESS 1.619 +#define _MD_FREE_LOCK(lock) 1.620 +#define _MD_LOCK(lock) 1.621 +#define _MD_UNLOCK(lock) 1.622 +#define _MD_INIT_IO() 1.623 +#define _MD_IOQ_LOCK() 1.624 +#define _MD_IOQ_UNLOCK() 1.625 + 1.626 +extern PRStatus _MD_InitializeThread(PRThread *thread); 1.627 + 1.628 +#define _MD_INIT_RUNNING_CPU(cpu) _MD_unix_init_running_cpu(cpu) 1.629 +#define _MD_INIT_THREAD _MD_InitializeThread 1.630 +#define _MD_EXIT_THREAD(thread) 1.631 +#define _MD_SUSPEND_THREAD(thread) _MD_suspend_thread 1.632 +#define _MD_RESUME_THREAD(thread) _MD_resume_thread 1.633 +#define _MD_CLEAN_THREAD(_thread) 1.634 + 1.635 +extern PRStatus _MD_CREATE_THREAD( 1.636 + PRThread *thread, 1.637 + void (*start) (void *), 1.638 + PRThreadPriority priority, 1.639 + PRThreadScope scope, 1.640 + PRThreadState state, 1.641 + PRUint32 stackSize); 1.642 +extern void _MD_SET_PRIORITY(struct _MDThread *thread, PRUintn newPri); 1.643 +extern PRStatus _MD_WAIT(PRThread *, PRIntervalTime timeout); 1.644 +extern PRStatus _MD_WAKEUP_WAITER(PRThread *); 1.645 +extern void _MD_YIELD(void); 1.646 + 1.647 +#endif /* ! _PR_PTHREADS */ 1.648 + 1.649 +extern void _MD_EarlyInit(void); 1.650 + 1.651 +#define _MD_EARLY_INIT _MD_EarlyInit 1.652 +#define _MD_FINAL_INIT _PR_UnixInit 1.653 +#define HAVE_CLOCK_MONOTONIC 1.654 + 1.655 +/* 1.656 + * We wrapped the select() call. _MD_SELECT refers to the built-in, 1.657 + * unwrapped version. 1.658 + */ 1.659 +#define _MD_SELECT __select 1.660 + 1.661 +#ifdef _PR_POLL_AVAILABLE 1.662 +#include <sys/poll.h> 1.663 +extern int __syscall_poll(struct pollfd *ufds, unsigned long int nfds, 1.664 + int timeout); 1.665 +#define _MD_POLL __syscall_poll 1.666 +#endif 1.667 + 1.668 +/* For writev() */ 1.669 +#include <sys/uio.h> 1.670 + 1.671 +extern void _MD_linux_map_sendfile_error(int err); 1.672 + 1.673 +#endif /* nspr_linux_defs_h___ */