_linux.h 22 KB

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