nsprpub/pr/include/md/_linux.h

Fri, 16 Jan 2015 04:50:19 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 04:50:19 +0100
branch
TOR_BUG_9701
changeset 13
44a2da4a2ab2
permissions
-rw-r--r--

Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32

     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/. */
     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  */
    11 #ifndef nspr_linux_defs_h___
    12 #define nspr_linux_defs_h___
    14 #include "prthread.h"
    16 /*
    17  * Internal configuration macros
    18  */
    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"
    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
    68 #if defined(__aarch64__)
    69 #define _MD_MINIMUM_STACK_SIZE  0x20000
    70 #endif
    72 #undef	HAVE_STACK_GROWING_UP
    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
    83 #if defined(__FreeBSD_kernel__) || defined(__GNU__)
    84 #define _PR_HAVE_SOCKADDR_LEN
    85 #endif
    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
   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
   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
   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
   139 #if defined(__powerpc64__)
   140 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)
   141 /* Use GCC built-in functions */
   142 #define _PR_HAVE_ATOMIC_OPS
   143 #define _MD_INIT_ATOMIC()
   144 #define _MD_ATOMIC_INCREMENT(ptr) __sync_add_and_fetch(ptr, 1)
   145 #define _MD_ATOMIC_DECREMENT(ptr) __sync_sub_and_fetch(ptr, 1)
   146 #define _MD_ATOMIC_ADD(ptr, i) __sync_add_and_fetch(ptr, i)
   147 #define _MD_ATOMIC_SET(ptr, nv) __sync_lock_test_and_set(ptr, nv)
   148 #endif
   149 #endif
   151 #if defined(__alpha)
   152 #define _PR_HAVE_ATOMIC_OPS
   153 #define _MD_INIT_ATOMIC()
   154 #define _MD_ATOMIC_ADD(ptr, i) ({               \
   155     PRInt32 __atomic_tmp, __atomic_ret;   \
   156     __asm__ __volatile__(                       \
   157     "1: ldl_l   %[ret], %[val]          \n"     \
   158     "   addl    %[ret], %[inc], %[tmp]  \n"     \
   159     "   addl    %[ret], %[inc], %[ret]  \n"     \
   160     "   stl_c   %[tmp], %[val]          \n"     \
   161     "   beq     %[tmp], 2f              \n"     \
   162     ".subsection 2                      \n"     \
   163     "2: br      1b                      \n"     \
   164     ".previous"                                 \
   165     : [ret] "=&r" (__atomic_ret),               \
   166       [tmp] "=&r" (__atomic_tmp),               \
   167       [val] "=m" (*ptr)                         \
   168     : [inc] "Ir" (i), "m" (*ptr));              \
   169     __atomic_ret;                               \
   170 })
   171 #define _MD_ATOMIC_INCREMENT(ptr) _MD_ATOMIC_ADD(ptr, 1)
   172 #define _MD_ATOMIC_DECREMENT(ptr) ({            \
   173     PRInt32 __atomic_tmp, __atomic_ret;   \
   174     __asm__ __volatile__(                       \
   175     "1: ldl_l   %[ret], %[val]          \n"     \
   176     "   subl    %[ret], 1, %[tmp]       \n"     \
   177     "   subl    %[ret], 1, %[ret]       \n"     \
   178     "   stl_c   %[tmp], %[val]          \n"     \
   179     "   beq     %[tmp], 2f              \n"     \
   180     ".subsection 2                      \n"     \
   181     "2: br      1b                      \n"     \
   182     ".previous"                                 \
   183     : [ret] "=&r" (__atomic_ret),               \
   184       [tmp] "=&r" (__atomic_tmp),               \
   185       [val] "=m" (*ptr)                         \
   186     : "m" (*ptr));                              \
   187     __atomic_ret;                               \
   188 })
   189 #define _MD_ATOMIC_SET(ptr, n) ({               \
   190     PRInt32 __atomic_tmp, __atomic_ret;   \
   191     __asm__ __volatile__(                       \
   192     "1: ldl_l   %[ret], %[val]          \n"     \
   193     "   mov     %[newval], %[tmp]       \n"     \
   194     "   stl_c   %[tmp], %[val]          \n"     \
   195     "   beq     %[tmp], 2f              \n"     \
   196     ".subsection 2                      \n"     \
   197     "2: br      1b                      \n"     \
   198     ".previous"                                 \
   199     : [ret] "=&r" (__atomic_ret),               \
   200       [tmp] "=&r"(__atomic_tmp),                \
   201       [val] "=m" (*ptr)                         \
   202     : [newval] "Ir" (n), "m" (*ptr));           \
   203     __atomic_ret;                               \
   204 })
   205 #endif
   207 #if defined(__arm__) || defined(__aarch64__)
   208 #if defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4)
   209 /* Use GCC built-in functions */
   210 #define _PR_HAVE_ATOMIC_OPS
   211 #define _MD_INIT_ATOMIC()
   213 #define _MD_ATOMIC_INCREMENT(ptr) __sync_add_and_fetch(ptr, 1)
   214 #define _MD_ATOMIC_DECREMENT(ptr) __sync_sub_and_fetch(ptr, 1)
   215 #define _MD_ATOMIC_SET(ptr, nv) __sync_lock_test_and_set(ptr, nv)
   216 #define _MD_ATOMIC_ADD(ptr, i) __sync_add_and_fetch(ptr, i)
   218 #elif defined(_PR_ARM_KUSER)
   219 #define _PR_HAVE_ATOMIC_OPS
   220 #define _MD_INIT_ATOMIC()
   222 /*
   223  * The kernel provides this helper function at a fixed address with a fixed
   224  * ABI signature, directly callable from user space.
   225  *
   226  * Definition:
   227  * Atomically store newval in *ptr if *ptr is equal to oldval.
   228  * Return zero if *ptr was changed or non-zero if no exchange happened.
   229  */
   230 typedef int (__kernel_cmpxchg_t)(int oldval, int newval, volatile int *ptr);
   231 #define __kernel_cmpxchg (*(__kernel_cmpxchg_t *)0xffff0fc0)
   233 #define _MD_ATOMIC_INCREMENT(ptr) _MD_ATOMIC_ADD(ptr, 1)
   234 #define _MD_ATOMIC_DECREMENT(ptr) _MD_ATOMIC_ADD(ptr, -1)
   236 static inline PRInt32 _MD_ATOMIC_ADD(PRInt32 *ptr, PRInt32 n)
   237 {
   238     PRInt32 ov, nv;
   239     volatile PRInt32 *vp = ptr;
   241     do {
   242         ov = *vp;
   243         nv = ov + n;
   244     } while (__kernel_cmpxchg(ov, nv, vp));
   246     return nv;
   247 }
   249 static inline PRInt32 _MD_ATOMIC_SET(PRInt32 *ptr, PRInt32 nv)
   250 {
   251     PRInt32 ov;
   252     volatile PRInt32 *vp = ptr;
   254     do {
   255         ov = *vp;
   256     } while (__kernel_cmpxchg(ov, nv, vp));
   258     return ov;
   259 }
   260 #endif
   261 #endif /* __arm__ */
   263 #define USE_SETJMP
   264 #if (defined(__GLIBC__) && __GLIBC__ >= 2) || defined(ANDROID)
   265 #define _PR_POLL_AVAILABLE
   266 #endif
   267 #undef _PR_USE_POLL
   268 #define _PR_STAT_HAS_ONLY_ST_ATIME
   269 #if defined(__alpha) || defined(__ia64__)
   270 #define _PR_HAVE_LARGE_OFF_T
   271 #elif (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1) \
   272     || defined(ANDROID)
   273 #define _PR_HAVE_OFF64_T
   274 #else
   275 #define _PR_NO_LARGE_FILES
   276 #endif
   277 #if (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1) \
   278     || defined(ANDROID)
   279 #define _PR_INET6
   280 #define _PR_HAVE_INET_NTOP
   281 #define _PR_HAVE_GETHOSTBYNAME2
   282 #define _PR_HAVE_GETADDRINFO
   283 #define _PR_INET6_PROBE
   284 #endif
   285 #ifndef ANDROID
   286 #define _PR_HAVE_SYSV_SEMAPHORES
   287 #define PR_HAVE_SYSV_NAMED_SHARED_MEMORY
   288 #endif
   289 /* Android has gethostbyname_r but not gethostbyaddr_r or gethostbyname2_r. */
   290 #if (__GLIBC__ >= 2) && defined(_PR_PTHREADS)
   291 #define _PR_HAVE_GETHOST_R
   292 #define _PR_HAVE_GETHOST_R_INT
   293 #endif
   295 #ifdef _PR_PTHREADS
   297 extern void _MD_CleanupBeforeExit(void);
   298 #define _MD_CLEANUP_BEFORE_EXIT _MD_CleanupBeforeExit
   300 #else  /* ! _PR_PTHREADS */
   302 #include <setjmp.h>
   304 #define PR_CONTEXT_TYPE	sigjmp_buf
   306 #define CONTEXT(_th) ((_th)->md.context)
   308 #ifdef __powerpc__
   309 /*
   310  * PowerPC based MkLinux
   311  *
   312  * On the PowerPC, the new style jmp_buf isn't used until glibc
   313  * 2.1.
   314  */
   315 #if (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1)
   316 #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[JB_GPR1]
   317 #else
   318 #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__misc[0]
   319 #endif /* glibc 2.1 or later */
   320 #define _MD_SET_FP(_t, val)
   321 #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
   322 #define _MD_GET_FP_PTR(_t) ((void *) 0)
   323 /* aix = 64, macos = 70 */
   324 #define PR_NUM_GCREGS  64
   326 #elif defined(__alpha)
   327 /* Alpha based Linux */
   329 #if defined(__GLIBC__) && __GLIBC__ >= 2
   330 #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[JB_SP]
   331 #define _MD_SET_FP(_t, val)
   332 #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
   333 #define _MD_GET_FP_PTR(_t) ((void *) 0)
   334 #define _MD_SP_TYPE long int
   335 #else
   336 #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__sp
   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 __ptr_t
   341 #endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */
   343 /* XXX not sure if this is correct, or maybe it should be 17? */
   344 #define PR_NUM_GCREGS 9
   346 #elif defined(__ia64__)
   348 #define _MD_GET_SP(_t)      ((long *)((_t)->md.context[0].__jmpbuf)[0])
   349 #define _MD_SET_FP(_t, val)
   350 #define _MD_GET_SP_PTR(_t)  &(_MD_GET_SP(_t))
   351 #define _MD_GET_FP_PTR(_t)  ((void *) 0)
   352 #define _MD_SP_TYPE         long int
   354 #define PR_NUM_GCREGS       _JBLEN
   356 #elif defined(__mc68000__)
   357 /* m68k based Linux */
   359 /*
   360  * On the m68k, glibc still uses the old style sigjmp_buf, even
   361  * in glibc 2.0.7.
   362  */
   363 #if defined(__GLIBC__) && __GLIBC__ >= 2
   364 #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__sp
   365 #define _MD_SET_FP(_t, val)
   366 #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
   367 #define _MD_GET_FP_PTR(_t) ((void *) 0)
   368 #define _MD_SP_TYPE int
   369 #else
   370 #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__sp
   371 #define _MD_SET_FP(_t, val)
   372 #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
   373 #define _MD_GET_FP_PTR(_t) ((void *) 0)
   374 #define _MD_SP_TYPE __ptr_t
   375 #endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */
   377 /* XXX not sure if this is correct, or maybe it should be 17? */
   378 #define PR_NUM_GCREGS 9
   380 #elif defined(__sparc__)
   381 /* Sparc */
   382 #if defined(__GLIBC__) && __GLIBC__ >= 2
   383 /*
   384  * You need glibc2-2.0.7-25 or later. The libraries that came with
   385  * Red Hat 5.1 are not new enough, but they are in 5.2.
   386  */
   387 #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[JB_SP]
   388 #define _MD_SET_FP(_t, val) ((_t)->md.context[0].__jmpbuf[JB_FP] = val)
   389 #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
   390 #define _MD_GET_FP_PTR(_t) (&(_t)->md.context[0].__jmpbuf[JB_FP])
   391 #define _MD_SP_TYPE int
   392 #else
   393 #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__fp
   394 #define _MD_SET_FP(_t, val)
   395 #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
   396 #define _MD_GET_FP_PTR(_t) ((void *) 0)
   397 #define _MD_SP_TYPE __ptr_t
   398 #endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */
   400 #elif defined(__i386__)
   401 /* Intel based Linux */
   402 #if defined(__GLIBC__) && __GLIBC__ >= 2
   403 #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[JB_SP]
   404 #define _MD_SET_FP(_t, val) ((_t)->md.context[0].__jmpbuf[JB_BP] = val)
   405 #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
   406 #define _MD_GET_FP_PTR(_t) (&(_t)->md.context[0].__jmpbuf[JB_BP])
   407 #define _MD_SP_TYPE int
   408 #else
   409 #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__sp
   410 #define _MD_SET_FP(_t, val) ((_t)->md.context[0].__jmpbuf[0].__bp = val)
   411 #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
   412 #define _MD_GET_FP_PTR(_t) &((_t)->md.context[0].__jmpbuf[0].__bp)
   413 #define _MD_SP_TYPE __ptr_t
   414 #endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */
   415 #define PR_NUM_GCREGS   6
   417 #elif defined(__mips__)
   418 /* Linux/MIPS */
   419 #if defined(__GLIBC__) && __GLIBC__ >= 2
   420 #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__sp
   421 #define _MD_SET_FP(_t, val) ((_t)->md.context[0].__jmpbuf[0].__fp = (val))
   422 #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
   423 #define _MD_GET_FP_PTR(_t) (&(_t)->md.context[0].__jmpbuf[0].__fp)
   424 #define _MD_SP_TYPE __ptr_t
   425 #else
   426 #error "Linux/MIPS pre-glibc2 not supported yet"
   427 #endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */
   429 #elif defined(__arm__)
   430 /* ARM/Linux */
   431 #if defined(__GLIBC__) && __GLIBC__ >= 2
   432 #ifdef __ARM_EABI__
   433 /* EABI */
   434 #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[8]
   435 #define _MD_SET_FP(_t, val) ((_t)->md.context[0].__jmpbuf[7] = (val))
   436 #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
   437 #define _MD_GET_FP_PTR(_t) (&(_t)->md.context[0].__jmpbuf[7])
   438 #define _MD_SP_TYPE __ptr_t
   439 #else /* __ARM_EABI__ */
   440 /* old ABI */
   441 #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[20]
   442 #define _MD_SET_FP(_t, val) ((_t)->md.context[0].__jmpbuf[19] = (val))
   443 #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
   444 #define _MD_GET_FP_PTR(_t) (&(_t)->md.context[0].__jmpbuf[19])
   445 #define _MD_SP_TYPE __ptr_t
   446 #endif /* __ARM_EABI__ */
   447 #else
   448 #error "ARM/Linux pre-glibc2 not supported yet"
   449 #endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */
   451 #elif defined(__sh__)
   452 /* SH/Linux */
   453 #if defined(__GLIBC__) && __GLIBC__ >= 2
   454 #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[7]
   455 #define _MD_SET_FP(_t, val) ((_t)->md.context[0].__jmpbuf[6] = (val))
   456 #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
   457 #define _MD_GET_FP_PTR(_t) (&(_t)->md.context[0].__jmpbuf[6])
   458 #define _MD_SP_TYPE __ptr_t
   459 #else
   460 #error "SH/Linux pre-glibc2 not supported yet"
   461 #endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */
   463 #elif defined(__m32r__)
   464 /* Linux/M32R */
   465 #if defined(__GLIBC__) && __GLIBC__ >= 2
   466 #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__regs[JB_SP]
   467 #define _MD_SET_FP(_t, val) ((_t)->md.context[0].__jmpbuf[0].__regs[JB_FP] = (val))
   468 #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
   469 #define _MD_GET_FP_PTR(_t) (&(_t)->md.context[0].__jmpbuf[0].__regs[JB_FP])
   470 #define _MD_SP_TYPE __ptr_t
   471 #else
   472 #error "Linux/M32R pre-glibc2 not supported yet"
   473 #endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */
   475 #else
   477 #error "Unknown CPU architecture"
   479 #endif /*__powerpc__*/
   481 /*
   482 ** Initialize a thread context to run "_main()" when started
   483 */
   484 #ifdef __powerpc__
   486 #define _MD_INIT_CONTEXT(_thread, _sp, _main, status)  \
   487 {  \
   488     *status = PR_TRUE;  \
   489     if (sigsetjmp(CONTEXT(_thread), 1)) {  \
   490         _main();  \
   491     }  \
   492     _MD_GET_SP(_thread) = (unsigned char*) ((_sp) - 128); \
   493     _thread->md.sp = _MD_GET_SP_PTR(_thread); \
   494     _thread->md.fp = _MD_GET_FP_PTR(_thread); \
   495     _MD_SET_FP(_thread, 0); \
   496 }
   498 #elif defined(__mips__)
   500 #define _MD_INIT_CONTEXT(_thread, _sp, _main, status)  \
   501 {  \
   502     *status = PR_TRUE;  \
   503     (void) sigsetjmp(CONTEXT(_thread), 1);  \
   504     _thread->md.context[0].__jmpbuf[0].__pc = (__ptr_t) _main;  \
   505     _MD_GET_SP(_thread) = (_MD_SP_TYPE) ((_sp) - 64); \
   506     _thread->md.sp = _MD_GET_SP_PTR(_thread); \
   507     _thread->md.fp = _MD_GET_FP_PTR(_thread); \
   508     _MD_SET_FP(_thread, 0); \
   509 }
   511 #else
   513 #define _MD_INIT_CONTEXT(_thread, _sp, _main, status)  \
   514 {  \
   515     *status = PR_TRUE;  \
   516     if (sigsetjmp(CONTEXT(_thread), 1)) {  \
   517         _main();  \
   518     }  \
   519     _MD_GET_SP(_thread) = (_MD_SP_TYPE) ((_sp) - 64); \
   520     _thread->md.sp = _MD_GET_SP_PTR(_thread); \
   521     _thread->md.fp = _MD_GET_FP_PTR(_thread); \
   522     _MD_SET_FP(_thread, 0); \
   523 }
   525 #endif /*__powerpc__*/
   527 #define _MD_SWITCH_CONTEXT(_thread)  \
   528     if (!sigsetjmp(CONTEXT(_thread), 1)) {  \
   529 	(_thread)->md.errcode = errno;  \
   530 	_PR_Schedule();  \
   531     }
   533 /*
   534 ** Restore a thread context, saved by _MD_SWITCH_CONTEXT
   535 */
   536 #define _MD_RESTORE_CONTEXT(_thread) \
   537 {   \
   538     errno = (_thread)->md.errcode;  \
   539     _MD_SET_CURRENT_THREAD(_thread);  \
   540     siglongjmp(CONTEXT(_thread), 1);  \
   541 }
   543 /* Machine-dependent (MD) data structures */
   545 struct _MDThread {
   546     PR_CONTEXT_TYPE context;
   547     void *sp;
   548     void *fp;
   549     int id;
   550     int errcode;
   551 };
   553 struct _MDThreadStack {
   554     PRInt8 notused;
   555 };
   557 struct _MDLock {
   558     PRInt8 notused;
   559 };
   561 struct _MDSemaphore {
   562     PRInt8 notused;
   563 };
   565 struct _MDCVar {
   566     PRInt8 notused;
   567 };
   569 struct _MDSegment {
   570     PRInt8 notused;
   571 };
   573 /*
   574  * md-specific cpu structure field
   575  */
   576 #include <sys/time.h>  /* for FD_SETSIZE */
   577 #define _PR_MD_MAX_OSFD FD_SETSIZE
   579 struct _MDCPU_Unix {
   580     PRCList ioQ;
   581     PRUint32 ioq_timeout;
   582     PRInt32 ioq_max_osfd;
   583     PRInt32 ioq_osfd_cnt;
   584 #ifndef _PR_USE_POLL
   585     fd_set fd_read_set, fd_write_set, fd_exception_set;
   586     PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
   587             fd_exception_cnt[_PR_MD_MAX_OSFD];
   588 #else
   589     struct pollfd *ioq_pollfds;
   590     int ioq_pollfds_size;
   591 #endif	/* _PR_USE_POLL */
   592 };
   594 #define _PR_IOQ(_cpu)			((_cpu)->md.md_unix.ioQ)
   595 #define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
   596 #define _PR_FD_READ_SET(_cpu)		((_cpu)->md.md_unix.fd_read_set)
   597 #define _PR_FD_READ_CNT(_cpu)		((_cpu)->md.md_unix.fd_read_cnt)
   598 #define _PR_FD_WRITE_SET(_cpu)		((_cpu)->md.md_unix.fd_write_set)
   599 #define _PR_FD_WRITE_CNT(_cpu)		((_cpu)->md.md_unix.fd_write_cnt)
   600 #define _PR_FD_EXCEPTION_SET(_cpu)	((_cpu)->md.md_unix.fd_exception_set)
   601 #define _PR_FD_EXCEPTION_CNT(_cpu)	((_cpu)->md.md_unix.fd_exception_cnt)
   602 #define _PR_IOQ_TIMEOUT(_cpu)		((_cpu)->md.md_unix.ioq_timeout)
   603 #define _PR_IOQ_MAX_OSFD(_cpu)		((_cpu)->md.md_unix.ioq_max_osfd)
   604 #define _PR_IOQ_OSFD_CNT(_cpu)		((_cpu)->md.md_unix.ioq_osfd_cnt)
   605 #define _PR_IOQ_POLLFDS(_cpu)		((_cpu)->md.md_unix.ioq_pollfds)
   606 #define _PR_IOQ_POLLFDS_SIZE(_cpu)	((_cpu)->md.md_unix.ioq_pollfds_size)
   608 #define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)	32
   610 struct _MDCPU {
   611     struct _MDCPU_Unix md_unix;
   612 };
   614 #define _MD_INIT_LOCKS()
   615 #define _MD_NEW_LOCK(lock) PR_SUCCESS
   616 #define _MD_FREE_LOCK(lock)
   617 #define _MD_LOCK(lock)
   618 #define _MD_UNLOCK(lock)
   619 #define _MD_INIT_IO()
   620 #define _MD_IOQ_LOCK()
   621 #define _MD_IOQ_UNLOCK()
   623 extern PRStatus _MD_InitializeThread(PRThread *thread);
   625 #define _MD_INIT_RUNNING_CPU(cpu)       _MD_unix_init_running_cpu(cpu)
   626 #define _MD_INIT_THREAD                 _MD_InitializeThread
   627 #define _MD_EXIT_THREAD(thread)
   628 #define _MD_SUSPEND_THREAD(thread)      _MD_suspend_thread
   629 #define _MD_RESUME_THREAD(thread)       _MD_resume_thread
   630 #define _MD_CLEAN_THREAD(_thread)
   632 extern PRStatus _MD_CREATE_THREAD(
   633     PRThread *thread,
   634     void (*start) (void *),
   635     PRThreadPriority priority,
   636     PRThreadScope scope,
   637     PRThreadState state,
   638     PRUint32 stackSize);
   639 extern void _MD_SET_PRIORITY(struct _MDThread *thread, PRUintn newPri);
   640 extern PRStatus _MD_WAIT(PRThread *, PRIntervalTime timeout);
   641 extern PRStatus _MD_WAKEUP_WAITER(PRThread *);
   642 extern void _MD_YIELD(void);
   644 #endif /* ! _PR_PTHREADS */
   646 extern void _MD_EarlyInit(void);
   648 #define _MD_EARLY_INIT                  _MD_EarlyInit
   649 #define _MD_FINAL_INIT                  _PR_UnixInit
   650 #define HAVE_CLOCK_MONOTONIC
   652 /*
   653  * We wrapped the select() call.  _MD_SELECT refers to the built-in,
   654  * unwrapped version.
   655  */
   656 #define _MD_SELECT __select
   658 #ifdef _PR_POLL_AVAILABLE
   659 #include <sys/poll.h>
   660 extern int __syscall_poll(struct pollfd *ufds, unsigned long int nfds,
   661 	int timeout);
   662 #define _MD_POLL __syscall_poll
   663 #endif
   665 /* For writev() */
   666 #include <sys/uio.h>
   668 extern void _MD_linux_map_sendfile_error(int err);
   670 #endif /* nspr_linux_defs_h___ */

mercurial