_linux.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4. *
  5. * The contents of this file are subject to the Mozilla Public License Version
  6. * 1.1 (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. * http://www.mozilla.org/MPL/
  9. *
  10. * Software distributed under the License is distributed on an "AS IS" basis,
  11. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12. * for the specific language governing rights and limitations under the
  13. * License.
  14. *
  15. * The Original Code is the Netscape Portable Runtime (NSPR).
  16. *
  17. * The Initial Developer of the Original Code is
  18. * Netscape Communications Corporation.
  19. * Portions created by the Initial Developer are Copyright (C) 1998-2000
  20. * the Initial Developer. All Rights Reserved.
  21. *
  22. * Contributor(s):
  23. *
  24. * Alternatively, the contents of this file may be used under the terms of
  25. * either the GNU General Public License Version 2 or later (the "GPL"), or
  26. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27. * in which case the provisions of the GPL or the LGPL are applicable instead
  28. * of those above. If you wish to allow use of your version of this file only
  29. * under the terms of either the GPL or the LGPL, and not to allow others to
  30. * use your version of this file under the terms of the MPL, indicate your
  31. * decision by deleting the provisions above and replace them with the notice
  32. * and other provisions required by the GPL or the LGPL. If you do not delete
  33. * the provisions above, a recipient may use your version of this file under
  34. * the terms of any one of the MPL, the GPL or the LGPL.
  35. *
  36. * ***** END LICENSE BLOCK ***** */
  37. #ifndef nspr_linux_defs_h___
  38. #define nspr_linux_defs_h___
  39. #include "prthread.h"
  40. /*
  41. * Internal configuration macros
  42. */
  43. #define PR_LINKER_ARCH "linux"
  44. #define _PR_SI_SYSNAME "LINUX"
  45. #ifdef __powerpc64__
  46. #define _PR_SI_ARCHITECTURE "ppc64"
  47. #elif defined(__powerpc__)
  48. #define _PR_SI_ARCHITECTURE "ppc"
  49. #elif defined(__alpha)
  50. #define _PR_SI_ARCHITECTURE "alpha"
  51. #elif defined(__ia64__)
  52. #define _PR_SI_ARCHITECTURE "ia64"
  53. #elif defined(__x86_64__)
  54. #define _PR_SI_ARCHITECTURE "x86-64"
  55. #elif defined(__mc68000__)
  56. #define _PR_SI_ARCHITECTURE "m68k"
  57. #elif defined(__sparc__)
  58. #define _PR_SI_ARCHITECTURE "sparc"
  59. #elif defined(__i386__)
  60. #define _PR_SI_ARCHITECTURE "x86"
  61. #elif defined(__mips__)
  62. #define _PR_SI_ARCHITECTURE "mips"
  63. #elif defined(__arm__)
  64. #define _PR_SI_ARCHITECTURE "arm"
  65. #elif defined(__hppa__)
  66. #define _PR_SI_ARCHITECTURE "hppa"
  67. #elif defined(__s390x__)
  68. #define _PR_SI_ARCHITECTURE "s390x"
  69. #elif defined(__s390__)
  70. #define _PR_SI_ARCHITECTURE "s390"
  71. #else
  72. #error "Unknown CPU architecture"
  73. #endif
  74. #define PR_DLL_SUFFIX ".so"
  75. #define _PR_VMBASE 0x30000000
  76. #define _PR_STACK_VMBASE 0x50000000
  77. #define _MD_DEFAULT_STACK_SIZE 65536L
  78. #define _MD_MMAP_FLAGS MAP_PRIVATE
  79. #undef HAVE_STACK_GROWING_UP
  80. /*
  81. * Elf linux supports dl* functions
  82. */
  83. #define HAVE_DLL
  84. #define USE_DLFCN
  85. #if defined(__i386__)
  86. #define _PR_HAVE_ATOMIC_OPS
  87. #define _MD_INIT_ATOMIC()
  88. extern PRInt32 _PR_x86_AtomicIncrement(PRInt32 *val);
  89. #define _MD_ATOMIC_INCREMENT _PR_x86_AtomicIncrement
  90. extern PRInt32 _PR_x86_AtomicDecrement(PRInt32 *val);
  91. #define _MD_ATOMIC_DECREMENT _PR_x86_AtomicDecrement
  92. extern PRInt32 _PR_x86_AtomicAdd(PRInt32 *ptr, PRInt32 val);
  93. #define _MD_ATOMIC_ADD _PR_x86_AtomicAdd
  94. extern PRInt32 _PR_x86_AtomicSet(PRInt32 *val, PRInt32 newval);
  95. #define _MD_ATOMIC_SET _PR_x86_AtomicSet
  96. #endif
  97. #if defined(__ia64__)
  98. #define _PR_HAVE_ATOMIC_OPS
  99. #define _MD_INIT_ATOMIC()
  100. extern PRInt32 _PR_ia64_AtomicIncrement(PRInt32 *val);
  101. #define _MD_ATOMIC_INCREMENT _PR_ia64_AtomicIncrement
  102. extern PRInt32 _PR_ia64_AtomicDecrement(PRInt32 *val);
  103. #define _MD_ATOMIC_DECREMENT _PR_ia64_AtomicDecrement
  104. extern PRInt32 _PR_ia64_AtomicAdd(PRInt32 *ptr, PRInt32 val);
  105. #define _MD_ATOMIC_ADD _PR_ia64_AtomicAdd
  106. extern PRInt32 _PR_ia64_AtomicSet(PRInt32 *val, PRInt32 newval);
  107. #define _MD_ATOMIC_SET _PR_ia64_AtomicSet
  108. #endif
  109. #if defined(__x86_64__)
  110. #define _PR_HAVE_ATOMIC_OPS
  111. #define _MD_INIT_ATOMIC()
  112. extern PRInt32 _PR_x86_64_AtomicIncrement(PRInt32 *val);
  113. #define _MD_ATOMIC_INCREMENT _PR_x86_64_AtomicIncrement
  114. extern PRInt32 _PR_x86_64_AtomicDecrement(PRInt32 *val);
  115. #define _MD_ATOMIC_DECREMENT _PR_x86_64_AtomicDecrement
  116. extern PRInt32 _PR_x86_64_AtomicAdd(PRInt32 *ptr, PRInt32 val);
  117. #define _MD_ATOMIC_ADD _PR_x86_64_AtomicAdd
  118. extern PRInt32 _PR_x86_64_AtomicSet(PRInt32 *val, PRInt32 newval);
  119. #define _MD_ATOMIC_SET _PR_x86_64_AtomicSet
  120. #endif
  121. #if defined(__alpha)
  122. #define _PR_HAVE_ATOMIC_OPS
  123. #define _MD_INIT_ATOMIC()
  124. #define _MD_ATOMIC_ADD(ptr, i) ({ \
  125. PRInt32 __atomic_tmp, __atomic_ret; \
  126. __asm__ __volatile__( \
  127. "1: ldl_l %[ret], %[val] \n" \
  128. " addl %[ret], %[inc], %[tmp] \n" \
  129. " addl %[ret], %[inc], %[ret] \n" \
  130. " stl_c %[tmp], %[val] \n" \
  131. " beq %[tmp], 2f \n" \
  132. ".subsection 2 \n" \
  133. "2: br 1b \n" \
  134. ".previous" \
  135. : [ret] "=&r" (__atomic_ret), \
  136. [tmp] "=&r" (__atomic_tmp), \
  137. [val] "=m" (*ptr) \
  138. : [inc] "Ir" (i), "m" (*ptr)); \
  139. __atomic_ret; \
  140. })
  141. #define _MD_ATOMIC_INCREMENT(ptr) _MD_ATOMIC_ADD(ptr, 1)
  142. #define _MD_ATOMIC_DECREMENT(ptr) ({ \
  143. PRInt32 __atomic_tmp, __atomic_ret; \
  144. __asm__ __volatile__( \
  145. "1: ldl_l %[ret], %[val] \n" \
  146. " subl %[ret], 1, %[tmp] \n" \
  147. " subl %[ret], 1, %[ret] \n" \
  148. " stl_c %[tmp], %[val] \n" \
  149. " beq %[tmp], 2f \n" \
  150. ".subsection 2 \n" \
  151. "2: br 1b \n" \
  152. ".previous" \
  153. : [ret] "=&r" (__atomic_ret), \
  154. [tmp] "=&r" (__atomic_tmp), \
  155. [val] "=m" (*ptr) \
  156. : "m" (*ptr)); \
  157. __atomic_ret; \
  158. })
  159. #define _MD_ATOMIC_SET(ptr, n) ({ \
  160. PRInt32 __atomic_tmp, __atomic_ret; \
  161. __asm__ __volatile__( \
  162. "1: ldl_l %[ret], %[val] \n" \
  163. " mov %[newval], %[tmp] \n" \
  164. " stl_c %[tmp], %[val] \n" \
  165. " beq %[tmp], 2f \n" \
  166. ".subsection 2 \n" \
  167. "2: br 1b \n" \
  168. ".previous" \
  169. : [ret] "=&r" (__atomic_ret), \
  170. [tmp] "=&r"(__atomic_tmp), \
  171. [val] "=m" (*ptr) \
  172. : [newval] "Ir" (n), "m" (*ptr)); \
  173. __atomic_ret; \
  174. })
  175. #endif
  176. #define USE_SETJMP
  177. #if defined(__GLIBC__) && __GLIBC__ >= 2
  178. #define _PR_POLL_AVAILABLE
  179. #endif
  180. #undef _PR_USE_POLL
  181. #define _PR_STAT_HAS_ONLY_ST_ATIME
  182. #if defined(__alpha) || defined(__ia64__)
  183. #define _PR_HAVE_LARGE_OFF_T
  184. #elif (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1)
  185. #define _PR_HAVE_OFF64_T
  186. #else
  187. #define _PR_NO_LARGE_FILES
  188. #endif
  189. #if (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1)
  190. #define _PR_INET6
  191. #define _PR_HAVE_INET_NTOP
  192. #define _PR_HAVE_GETHOSTBYNAME2
  193. #define _PR_HAVE_GETADDRINFO
  194. #define _PR_INET6_PROBE
  195. #endif
  196. #define _PR_HAVE_SYSV_SEMAPHORES
  197. #define PR_HAVE_SYSV_NAMED_SHARED_MEMORY
  198. #if (__GLIBC__ >= 2) && defined(_PR_PTHREADS)
  199. #define _PR_HAVE_GETHOST_R
  200. #define _PR_HAVE_GETHOST_R_INT
  201. #endif
  202. #ifdef _PR_PTHREADS
  203. extern void _MD_CleanupBeforeExit(void);
  204. #define _MD_CLEANUP_BEFORE_EXIT _MD_CleanupBeforeExit
  205. #else /* ! _PR_PTHREADS */
  206. #include <setjmp.h>
  207. #define PR_CONTEXT_TYPE sigjmp_buf
  208. #define CONTEXT(_th) ((_th)->md.context)
  209. #ifdef __powerpc__
  210. /*
  211. * PowerPC based MkLinux
  212. *
  213. * On the PowerPC, the new style jmp_buf isn't used until glibc
  214. * 2.1.
  215. */
  216. #if (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1)
  217. #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[JB_GPR1]
  218. #else
  219. #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__misc[0]
  220. #endif /* glibc 2.1 or later */
  221. #define _MD_SET_FP(_t, val)
  222. #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
  223. #define _MD_GET_FP_PTR(_t) ((void *) 0)
  224. /* aix = 64, macos = 70 */
  225. #define PR_NUM_GCREGS 64
  226. #elif defined(__alpha)
  227. /* Alpha based Linux */
  228. #if defined(__GLIBC__) && __GLIBC__ >= 2
  229. #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[JB_SP]
  230. #define _MD_SET_FP(_t, val)
  231. #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
  232. #define _MD_GET_FP_PTR(_t) ((void *) 0)
  233. #define _MD_SP_TYPE long int
  234. #else
  235. #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__sp
  236. #define _MD_SET_FP(_t, val)
  237. #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
  238. #define _MD_GET_FP_PTR(_t) ((void *) 0)
  239. #define _MD_SP_TYPE __ptr_t
  240. #endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */
  241. /* XXX not sure if this is correct, or maybe it should be 17? */
  242. #define PR_NUM_GCREGS 9
  243. #elif defined(__ia64__)
  244. #define _MD_GET_SP(_t) ((long *)((_t)->md.context[0].__jmpbuf)[0])
  245. #define _MD_SET_FP(_t, val)
  246. #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
  247. #define _MD_GET_FP_PTR(_t) ((void *) 0)
  248. #define _MD_SP_TYPE long int
  249. #define PR_NUM_GCREGS _JBLEN
  250. #elif defined(__mc68000__)
  251. /* m68k based Linux */
  252. /*
  253. * On the m68k, glibc still uses the old style sigjmp_buf, even
  254. * in glibc 2.0.7.
  255. */
  256. #if defined(__GLIBC__) && __GLIBC__ >= 2
  257. #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__sp
  258. #define _MD_SET_FP(_t, val)
  259. #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
  260. #define _MD_GET_FP_PTR(_t) ((void *) 0)
  261. #define _MD_SP_TYPE int
  262. #else
  263. #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__sp
  264. #define _MD_SET_FP(_t, val)
  265. #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
  266. #define _MD_GET_FP_PTR(_t) ((void *) 0)
  267. #define _MD_SP_TYPE __ptr_t
  268. #endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */
  269. /* XXX not sure if this is correct, or maybe it should be 17? */
  270. #define PR_NUM_GCREGS 9
  271. #elif defined(__sparc__)
  272. /* Sparc */
  273. #if defined(__GLIBC__) && __GLIBC__ >= 2
  274. /*
  275. * You need glibc2-2.0.7-25 or later. The libraries that came with
  276. * Red Hat 5.1 are not new enough, but they are in 5.2.
  277. */
  278. #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[JB_SP]
  279. #define _MD_SET_FP(_t, val) ((_t)->md.context[0].__jmpbuf[JB_FP] = val)
  280. #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
  281. #define _MD_GET_FP_PTR(_t) (&(_t)->md.context[0].__jmpbuf[JB_FP])
  282. #define _MD_SP_TYPE int
  283. #else
  284. #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__fp
  285. #define _MD_SET_FP(_t, val)
  286. #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
  287. #define _MD_GET_FP_PTR(_t) ((void *) 0)
  288. #define _MD_SP_TYPE __ptr_t
  289. #endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */
  290. #elif defined(__i386__)
  291. /* Intel based Linux */
  292. #if defined(__GLIBC__) && __GLIBC__ >= 2
  293. #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[JB_SP]
  294. #define _MD_SET_FP(_t, val) ((_t)->md.context[0].__jmpbuf[JB_BP] = val)
  295. #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
  296. #define _MD_GET_FP_PTR(_t) (&(_t)->md.context[0].__jmpbuf[JB_BP])
  297. #define _MD_SP_TYPE int
  298. #else
  299. #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__sp
  300. #define _MD_SET_FP(_t, val) ((_t)->md.context[0].__jmpbuf[0].__bp = val)
  301. #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
  302. #define _MD_GET_FP_PTR(_t) &((_t)->md.context[0].__jmpbuf[0].__bp)
  303. #define _MD_SP_TYPE __ptr_t
  304. #endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */
  305. #define PR_NUM_GCREGS 6
  306. #elif defined(__mips__)
  307. /* Linux/MIPS */
  308. #if defined(__GLIBC__) && __GLIBC__ >= 2
  309. #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__sp
  310. #define _MD_SET_FP(_t, val) ((_t)->md.context[0].__jmpbuf[0].__fp = (val))
  311. #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
  312. #define _MD_GET_FP_PTR(_t) (&(_t)->md.context[0].__jmpbuf[0].__fp)
  313. #define _MD_SP_TYPE __ptr_t
  314. #else
  315. #error "Linux/MIPS pre-glibc2 not supported yet"
  316. #endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */
  317. #elif defined(__arm__)
  318. /* ARM/Linux */
  319. #if defined(__GLIBC__) && __GLIBC__ >= 2
  320. #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[20]
  321. #define _MD_SET_FP(_t, val) ((_t)->md.context[0].__jmpbuf[19] = (val))
  322. #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
  323. #define _MD_GET_FP_PTR(_t) (&(_t)->md.context[0].__jmpbuf[19])
  324. #define _MD_SP_TYPE __ptr_t
  325. #else
  326. #error "ARM/Linux pre-glibc2 not supported yet"
  327. #endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */
  328. #else
  329. #error "Unknown CPU architecture"
  330. #endif /*__powerpc__*/
  331. /*
  332. ** Initialize a thread context to run "_main()" when started
  333. */
  334. #ifdef __powerpc__
  335. #define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
  336. { \
  337. *status = PR_TRUE; \
  338. if (sigsetjmp(CONTEXT(_thread), 1)) { \
  339. _main(); \
  340. } \
  341. _MD_GET_SP(_thread) = (unsigned char*) ((_sp) - 128); \
  342. _thread->md.sp = _MD_GET_SP_PTR(_thread); \
  343. _thread->md.fp = _MD_GET_FP_PTR(_thread); \
  344. _MD_SET_FP(_thread, 0); \
  345. }
  346. #elif defined(__mips__)
  347. #define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
  348. { \
  349. *status = PR_TRUE; \
  350. (void) sigsetjmp(CONTEXT(_thread), 1); \
  351. _thread->md.context[0].__jmpbuf[0].__pc = (__ptr_t) _main; \
  352. _MD_GET_SP(_thread) = (_MD_SP_TYPE) ((_sp) - 64); \
  353. _thread->md.sp = _MD_GET_SP_PTR(_thread); \
  354. _thread->md.fp = _MD_GET_FP_PTR(_thread); \
  355. _MD_SET_FP(_thread, 0); \
  356. }
  357. #else
  358. #define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
  359. { \
  360. *status = PR_TRUE; \
  361. if (sigsetjmp(CONTEXT(_thread), 1)) { \
  362. _main(); \
  363. } \
  364. _MD_GET_SP(_thread) = (_MD_SP_TYPE) ((_sp) - 64); \
  365. _thread->md.sp = _MD_GET_SP_PTR(_thread); \
  366. _thread->md.fp = _MD_GET_FP_PTR(_thread); \
  367. _MD_SET_FP(_thread, 0); \
  368. }
  369. #endif /*__powerpc__*/
  370. #define _MD_SWITCH_CONTEXT(_thread) \
  371. if (!sigsetjmp(CONTEXT(_thread), 1)) { \
  372. (_thread)->md.errcode = errno; \
  373. _PR_Schedule(); \
  374. }
  375. /*
  376. ** Restore a thread context, saved by _MD_SWITCH_CONTEXT
  377. */
  378. #define _MD_RESTORE_CONTEXT(_thread) \
  379. { \
  380. errno = (_thread)->md.errcode; \
  381. _MD_SET_CURRENT_THREAD(_thread); \
  382. siglongjmp(CONTEXT(_thread), 1); \
  383. }
  384. /* Machine-dependent (MD) data structures */
  385. struct _MDThread {
  386. PR_CONTEXT_TYPE context;
  387. void *sp;
  388. void *fp;
  389. int id;
  390. int errcode;
  391. };
  392. struct _MDThreadStack {
  393. PRInt8 notused;
  394. };
  395. struct _MDLock {
  396. PRInt8 notused;
  397. };
  398. struct _MDSemaphore {
  399. PRInt8 notused;
  400. };
  401. struct _MDCVar {
  402. PRInt8 notused;
  403. };
  404. struct _MDSegment {
  405. PRInt8 notused;
  406. };
  407. /*
  408. * md-specific cpu structure field
  409. */
  410. #include <sys/time.h> /* for FD_SETSIZE */
  411. #define _PR_MD_MAX_OSFD FD_SETSIZE
  412. struct _MDCPU_Unix {
  413. PRCList ioQ;
  414. PRUint32 ioq_timeout;
  415. PRInt32 ioq_max_osfd;
  416. PRInt32 ioq_osfd_cnt;
  417. #ifndef _PR_USE_POLL
  418. fd_set fd_read_set, fd_write_set, fd_exception_set;
  419. PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
  420. fd_exception_cnt[_PR_MD_MAX_OSFD];
  421. #else
  422. struct pollfd *ioq_pollfds;
  423. int ioq_pollfds_size;
  424. #endif /* _PR_USE_POLL */
  425. };
  426. #define _PR_IOQ(_cpu) ((_cpu)->md.md_unix.ioQ)
  427. #define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
  428. #define _PR_FD_READ_SET(_cpu) ((_cpu)->md.md_unix.fd_read_set)
  429. #define _PR_FD_READ_CNT(_cpu) ((_cpu)->md.md_unix.fd_read_cnt)
  430. #define _PR_FD_WRITE_SET(_cpu) ((_cpu)->md.md_unix.fd_write_set)
  431. #define _PR_FD_WRITE_CNT(_cpu) ((_cpu)->md.md_unix.fd_write_cnt)
  432. #define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set)
  433. #define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt)
  434. #define _PR_IOQ_TIMEOUT(_cpu) ((_cpu)->md.md_unix.ioq_timeout)
  435. #define _PR_IOQ_MAX_OSFD(_cpu) ((_cpu)->md.md_unix.ioq_max_osfd)
  436. #define _PR_IOQ_OSFD_CNT(_cpu) ((_cpu)->md.md_unix.ioq_osfd_cnt)
  437. #define _PR_IOQ_POLLFDS(_cpu) ((_cpu)->md.md_unix.ioq_pollfds)
  438. #define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size)
  439. #define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu) 32
  440. struct _MDCPU {
  441. struct _MDCPU_Unix md_unix;
  442. };
  443. #define _MD_INIT_LOCKS()
  444. #define _MD_NEW_LOCK(lock) PR_SUCCESS
  445. #define _MD_FREE_LOCK(lock)
  446. #define _MD_LOCK(lock)
  447. #define _MD_UNLOCK(lock)
  448. #define _MD_INIT_IO()
  449. #define _MD_IOQ_LOCK()
  450. #define _MD_IOQ_UNLOCK()
  451. extern PRStatus _MD_InitializeThread(PRThread *thread);
  452. #define _MD_INIT_RUNNING_CPU(cpu) _MD_unix_init_running_cpu(cpu)
  453. #define _MD_INIT_THREAD _MD_InitializeThread
  454. #define _MD_EXIT_THREAD(thread)
  455. #define _MD_SUSPEND_THREAD(thread) _MD_suspend_thread
  456. #define _MD_RESUME_THREAD(thread) _MD_resume_thread
  457. #define _MD_CLEAN_THREAD(_thread)
  458. extern PRStatus _MD_CREATE_THREAD(
  459. PRThread *thread,
  460. void (*start) (void *),
  461. PRThreadPriority priority,
  462. PRThreadScope scope,
  463. PRThreadState state,
  464. PRUint32 stackSize);
  465. extern void _MD_SET_PRIORITY(struct _MDThread *thread, PRUintn newPri);
  466. extern PRStatus _MD_WAIT(PRThread *, PRIntervalTime timeout);
  467. extern PRStatus _MD_WAKEUP_WAITER(PRThread *);
  468. extern void _MD_YIELD(void);
  469. #endif /* ! _PR_PTHREADS */
  470. extern void _MD_EarlyInit(void);
  471. extern PRIntervalTime _PR_UNIX_GetInterval(void);
  472. extern PRIntervalTime _PR_UNIX_TicksPerSecond(void);
  473. #define _MD_EARLY_INIT _MD_EarlyInit
  474. #define _MD_FINAL_INIT _PR_UnixInit
  475. #define _MD_GET_INTERVAL _PR_UNIX_GetInterval
  476. #define _MD_INTERVAL_PER_SEC _PR_UNIX_TicksPerSecond
  477. /*
  478. * We wrapped the select() call. _MD_SELECT refers to the built-in,
  479. * unwrapped version.
  480. */
  481. #define _MD_SELECT __select
  482. #ifdef _PR_POLL_AVAILABLE
  483. #include <sys/poll.h>
  484. extern int __syscall_poll(struct pollfd *ufds, unsigned long int nfds,
  485. int timeout);
  486. #define _MD_POLL __syscall_poll
  487. #endif
  488. /* For writev() */
  489. #include <sys/uio.h>
  490. extern void _MD_linux_map_sendfile_error(int err);
  491. #endif /* nspr_linux_defs_h___ */