home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / nspr30-e.zip / nspr30-e / include / md / _linux.h < prev    next >
C/C++ Source or Header  |  1998-11-21  |  12KB  |  407 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /*
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  * 
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  * 
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #ifndef nspr_linux_defs_h___
  20. #define nspr_linux_defs_h___
  21.  
  22. #include "prthread.h"
  23.  
  24. /*
  25.  * Internal configuration macros
  26.  */
  27.  
  28. #define PR_LINKER_ARCH    "linux"
  29. #define _PR_SI_SYSNAME  "LINUX"
  30. #ifdef __powerpc__
  31. #define _PR_SI_ARCHITECTURE "ppc"
  32. #elif defined(__alpha)
  33. #define _PR_SI_ARCHITECTURE "alpha"
  34. #elif defined(__mc68000__)
  35. #define _PR_SI_ARCHITECTURE "m68k"
  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. #else
  45. #error "Unknown CPU architecture"
  46. #endif
  47. #define PR_DLL_SUFFIX        ".so"
  48.  
  49. #define _PR_VMBASE              0x30000000
  50. #define _PR_STACK_VMBASE    0x50000000
  51. #define _MD_DEFAULT_STACK_SIZE    65536L
  52. #define _MD_MMAP_FLAGS          MAP_PRIVATE
  53.  
  54. #undef    HAVE_STACK_GROWING_UP
  55.  
  56. /*
  57.  * Elf linux supports dl* functions
  58.  */
  59. #define HAVE_DLL
  60. #define USE_DLFCN
  61.  
  62. #define USE_SETJMP
  63. #if defined(__GLIBC__) && __GLIBC__ >= 2
  64. #define _PR_POLL_AVAILABLE
  65. #endif
  66. #undef _PR_USE_POLL
  67. #define _PR_STAT_HAS_ONLY_ST_ATIME
  68. #if defined(__alpha)
  69. #define _PR_HAVE_LARGE_OFF_T
  70. #else
  71. #define _PR_NO_LARGE_FILES
  72. #endif
  73.  
  74. #ifdef _PR_PTHREADS
  75.  
  76. extern void _MD_CleanupBeforeExit(void);
  77. #define _MD_CLEANUP_BEFORE_EXIT _MD_CleanupBeforeExit
  78.  
  79. #else  /* ! _PR_PTHREADS */
  80.  
  81. #include <setjmp.h>
  82.  
  83. #define PR_CONTEXT_TYPE    sigjmp_buf
  84.  
  85. #define CONTEXT(_th) ((_th)->md.context)
  86.  
  87. #ifdef __powerpc__
  88. /*
  89.  * PowerPC based MkLinux
  90.  *
  91.  * On the PowerPC, the new style jmp_buf isn't used until glibc
  92.  * 2.1.
  93.  */
  94. #if __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 1
  95. #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[JB_GPR1]
  96. #else
  97. #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__misc[0]
  98. #endif /* __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 1 */
  99. #define _MD_SET_FP(_t, val)
  100. #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
  101. #define _MD_GET_FP_PTR(_t) ((void *) 0)
  102. /* aix = 64, macos = 70 */
  103. #define PR_NUM_GCREGS  64
  104.  
  105. #elif defined(__alpha)
  106. /* Alpha based Linux */
  107.  
  108. #if defined(__GLIBC__) && __GLIBC__ >= 2
  109. #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[JB_SP]
  110. #define _MD_SET_FP(_t, val)
  111. #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
  112. #define _MD_GET_FP_PTR(_t) ((void *) 0)
  113. #define _MD_SP_TYPE long int
  114. #else
  115. #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__sp
  116. #define _MD_SET_FP(_t, val)
  117. #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
  118. #define _MD_GET_FP_PTR(_t) ((void *) 0)
  119. #define _MD_SP_TYPE __ptr_t
  120. #endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */
  121.  
  122. /* XXX not sure if this is correct, or maybe it should be 17? */
  123. #define PR_NUM_GCREGS 9
  124.  
  125. #elif defined(__mc68000__)
  126. /* m68k based Linux */
  127.  
  128. /*
  129.  * On the m68k, glibc still uses the old style sigjmp_buf, even
  130.  * in glibc 2.0.7.
  131.  */
  132. #if defined(__GLIBC__) && __GLIBC__ >= 2
  133. #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__sp
  134. #define _MD_SET_FP(_t, val)
  135. #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
  136. #define _MD_GET_FP_PTR(_t) ((void *) 0)
  137. #define _MD_SP_TYPE int
  138. #else
  139. #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__sp
  140. #define _MD_SET_FP(_t, val)
  141. #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
  142. #define _MD_GET_FP_PTR(_t) ((void *) 0)
  143. #define _MD_SP_TYPE __ptr_t
  144. #endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */
  145.  
  146. /* XXX not sure if this is correct, or maybe it should be 17? */
  147. #define PR_NUM_GCREGS 9
  148.  
  149. #elif defined(__sparc__)
  150. /* Sparc */
  151. #if defined(__GLIBC__) && __GLIBC__ >= 2
  152. /*
  153.  * You need glibc2-2.0.7-25 or later. The libraries that came with
  154.  * Red Hat 5.1 are not new enough, but they are in 5.2.
  155.  */
  156. #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[JB_SP]
  157. #define _MD_SET_FP(_t, val) ((_t)->md.context[0].__jmpbuf[JB_FP] = val)
  158. #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
  159. #define _MD_GET_FP_PTR(_t) (&(_t)->md.context[0].__jmpbuf[JB_FP])
  160. #define _MD_SP_TYPE int
  161. #else
  162. #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__fp
  163. #define _MD_SET_FP(_t, val)
  164. #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
  165. #define _MD_GET_FP_PTR(_t) ((void *) 0)
  166. #define _MD_SP_TYPE __ptr_t
  167. #endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */
  168.  
  169. #elif defined(__i386__)
  170. /* Intel based Linux */
  171. #if defined(__GLIBC__) && __GLIBC__ >= 2
  172. #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[JB_SP]
  173. #define _MD_SET_FP(_t, val) ((_t)->md.context[0].__jmpbuf[JB_BP] = val)
  174. #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
  175. #define _MD_GET_FP_PTR(_t) (&(_t)->md.context[0].__jmpbuf[JB_BP])
  176. #define _MD_SP_TYPE int
  177. #else
  178. #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__sp
  179. #define _MD_SET_FP(_t, val) ((_t)->md.context[0].__jmpbuf[0].__bp = val)
  180. #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
  181. #define _MD_GET_FP_PTR(_t) &((_t)->md.context[0].__jmpbuf[0].__bp)
  182. #define _MD_SP_TYPE __ptr_t
  183. #endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */
  184. #define PR_NUM_GCREGS   6
  185.  
  186. #elif defined(__mips__)
  187. /* Linux/MIPS */
  188. #if defined(__GLIBC__) && __GLIBC__ >= 2
  189. #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__sp
  190. #define _MD_SET_FP(_t, val) ((_t)->md.context[0].__jmpbuf[0].__fp = (val))
  191. #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
  192. #define _MD_GET_FP_PTR(_t) (&(_t)->md.context[0].__jmpbuf[0].__fp)
  193. #define _MD_SP_TYPE __ptr_t
  194. #else
  195. #error "Linux/MIPS pre-glibc2 not supported yet"
  196. #endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */
  197.  
  198. #elif defined(__arm__)
  199. /* ARM/Linux */
  200. #if defined(__GLIBC__) && __GLIBC__ >= 2
  201. #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[20]
  202. #define _MD_SET_FP(_t, val) ((_t)->md.context[0].__jmpbuf[19] = (val))
  203. #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
  204. #define _MD_GET_FP_PTR(_t) (&(_t)->md.context[0].__jmpbuf[19])
  205. #define _MD_SP_TYPE __ptr_t
  206. #else
  207. #error "ARM/Linux pre-glibc2 not supported yet"
  208. #endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */
  209.  
  210. #else
  211.  
  212. #error "Unknown CPU architecture"
  213.  
  214. #endif /*__powerpc__*/
  215.  
  216. /*
  217. ** Initialize a thread context to run "_main()" when started
  218. */
  219. #ifdef __powerpc__
  220.  
  221. #define _MD_INIT_CONTEXT(_thread, _sp, _main, status)  \
  222. {  \
  223.     *status = PR_TRUE;  \
  224.     if (sigsetjmp(CONTEXT(_thread), 1)) {  \
  225.         _main();  \
  226.     }  \
  227.     _MD_GET_SP(_thread) = (unsigned char*) ((_sp) - 128); \
  228.     _thread->md.sp = _MD_GET_SP_PTR(_thread); \
  229.     _thread->md.fp = _MD_GET_FP_PTR(_thread); \
  230.     _MD_SET_FP(_thread, 0); \
  231. }
  232.  
  233. #elif defined(__mips__)
  234.  
  235. #define _MD_INIT_CONTEXT(_thread, _sp, _main, status)  \
  236. {  \
  237.     *status = PR_TRUE;  \
  238.     (void) sigsetjmp(CONTEXT(_thread), 1);  \
  239.     _thread->md.context[0].__jmpbuf[0].__pc = (__ptr_t) _main;  \
  240.     _MD_GET_SP(_thread) = (_MD_SP_TYPE) ((_sp) - 64); \
  241.     _thread->md.sp = _MD_GET_SP_PTR(_thread); \
  242.     _thread->md.fp = _MD_GET_FP_PTR(_thread); \
  243.     _MD_SET_FP(_thread, 0); \
  244. }
  245.  
  246. #else
  247.  
  248. #define _MD_INIT_CONTEXT(_thread, _sp, _main, status)  \
  249. {  \
  250.     *status = PR_TRUE;  \
  251.     if (sigsetjmp(CONTEXT(_thread), 1)) {  \
  252.         _main();  \
  253.     }  \
  254.     _MD_GET_SP(_thread) = (_MD_SP_TYPE) ((_sp) - 64); \
  255.     _thread->md.sp = _MD_GET_SP_PTR(_thread); \
  256.     _thread->md.fp = _MD_GET_FP_PTR(_thread); \
  257.     _MD_SET_FP(_thread, 0); \
  258. }
  259.  
  260. #endif /*__powerpc__*/
  261.  
  262. #define _MD_SWITCH_CONTEXT(_thread)  \
  263.     if (!sigsetjmp(CONTEXT(_thread), 1)) {  \
  264.     (_thread)->md.errcode = errno;  \
  265.     _PR_Schedule();  \
  266.     }
  267.  
  268. /*
  269. ** Restore a thread context, saved by _MD_SWITCH_CONTEXT
  270. */
  271. #define _MD_RESTORE_CONTEXT(_thread) \
  272. {   \
  273.     errno = (_thread)->md.errcode;  \
  274.     _MD_SET_CURRENT_THREAD(_thread);  \
  275.     siglongjmp(CONTEXT(_thread), 1);  \
  276. }
  277.  
  278. /* Machine-dependent (MD) data structures */
  279.  
  280. struct _MDThread {
  281.     PR_CONTEXT_TYPE context;
  282.     void *sp;
  283.     void *fp;
  284.     int id;
  285.     int errcode;
  286. };
  287.  
  288. struct _MDThreadStack {
  289.     PRInt8 notused;
  290. };
  291.  
  292. struct _MDLock {
  293.     PRInt8 notused;
  294. };
  295.  
  296. struct _MDSemaphore {
  297.     PRInt8 notused;
  298. };
  299.  
  300. struct _MDCVar {
  301.     PRInt8 notused;
  302. };
  303.  
  304. struct _MDSegment {
  305.     PRInt8 notused;
  306. };
  307.  
  308. /*
  309.  * md-specific cpu structure field
  310.  */
  311. #include <sys/time.h>  /* for FD_SETSIZE */
  312. #define _PR_MD_MAX_OSFD FD_SETSIZE
  313.  
  314. struct _MDCPU_Unix {
  315.     PRCList ioQ;
  316.     PRUint32 ioq_timeout;
  317.     PRInt32 ioq_max_osfd;
  318.     PRInt32 ioq_osfd_cnt;
  319. #ifndef _PR_USE_POLL
  320.     fd_set fd_read_set, fd_write_set, fd_exception_set;
  321.     PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
  322.                 fd_exception_cnt[_PR_MD_MAX_OSFD];
  323. #else
  324.     struct pollfd *ioq_pollfds;
  325.     int ioq_pollfds_size;
  326. #endif    /* _PR_USE_POLL */
  327. };
  328.  
  329. #define _PR_IOQ(_cpu)            ((_cpu)->md.md_unix.ioQ)
  330. #define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
  331. #define _PR_FD_READ_SET(_cpu)        ((_cpu)->md.md_unix.fd_read_set)
  332. #define _PR_FD_READ_CNT(_cpu)        ((_cpu)->md.md_unix.fd_read_cnt)
  333. #define _PR_FD_WRITE_SET(_cpu)        ((_cpu)->md.md_unix.fd_write_set)
  334. #define _PR_FD_WRITE_CNT(_cpu)        ((_cpu)->md.md_unix.fd_write_cnt)
  335. #define _PR_FD_EXCEPTION_SET(_cpu)    ((_cpu)->md.md_unix.fd_exception_set)
  336. #define _PR_FD_EXCEPTION_CNT(_cpu)    ((_cpu)->md.md_unix.fd_exception_cnt)
  337. #define _PR_IOQ_TIMEOUT(_cpu)        ((_cpu)->md.md_unix.ioq_timeout)
  338. #define _PR_IOQ_MAX_OSFD(_cpu)        ((_cpu)->md.md_unix.ioq_max_osfd)
  339. #define _PR_IOQ_OSFD_CNT(_cpu)        ((_cpu)->md.md_unix.ioq_osfd_cnt)
  340. #define _PR_IOQ_POLLFDS(_cpu)        ((_cpu)->md.md_unix.ioq_pollfds)
  341. #define _PR_IOQ_POLLFDS_SIZE(_cpu)    ((_cpu)->md.md_unix.ioq_pollfds_size)
  342.  
  343. #define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)    32
  344.  
  345. struct _MDCPU {
  346.     struct _MDCPU_Unix md_unix;
  347. };
  348.  
  349. #define _MD_INIT_LOCKS()
  350. #define _MD_NEW_LOCK(lock) PR_SUCCESS
  351. #define _MD_FREE_LOCK(lock)
  352. #define _MD_LOCK(lock)
  353. #define _MD_UNLOCK(lock)
  354. #define _MD_INIT_IO()
  355. #define _MD_IOQ_LOCK()
  356. #define _MD_IOQ_UNLOCK()
  357.  
  358. extern PRStatus _MD_InitializeThread(PRThread *thread);
  359.  
  360. #define _MD_INIT_RUNNING_CPU(cpu)       _MD_unix_init_running_cpu(cpu)
  361. #define _MD_INIT_THREAD                 _MD_InitializeThread
  362. #define _MD_EXIT_THREAD(thread)
  363. #define _MD_SUSPEND_THREAD(thread)      _MD_suspend_thread
  364. #define _MD_RESUME_THREAD(thread)       _MD_resume_thread
  365. #define _MD_CLEAN_THREAD(_thread)
  366.  
  367. extern PRStatus _MD_CREATE_THREAD(
  368.     PRThread *thread,
  369.     void (*start) (void *),
  370.     PRThreadPriority priority,
  371.     PRThreadScope scope,
  372.     PRThreadState state,
  373.     PRUint32 stackSize);
  374. extern void _MD_SET_PRIORITY(struct _MDThread *thread, PRUintn newPri);
  375. extern PRStatus _MD_WAIT(PRThread *, PRIntervalTime timeout);
  376. extern PRStatus _MD_WAKEUP_WAITER(PRThread *);
  377. extern void _MD_YIELD(void);
  378.  
  379. #endif /* ! _PR_PTHREADS */
  380.  
  381. extern void _MD_EarlyInit(void);
  382. extern PRIntervalTime _PR_UNIX_GetInterval(void);
  383. extern PRIntervalTime _PR_UNIX_TicksPerSecond(void);
  384.  
  385. #define _MD_EARLY_INIT                  _MD_EarlyInit
  386. #define _MD_FINAL_INIT                    _PR_UnixInit
  387. #define _MD_GET_INTERVAL                _PR_UNIX_GetInterval
  388. #define _MD_INTERVAL_PER_SEC            _PR_UNIX_TicksPerSecond
  389.  
  390. /*
  391.  * We wrapped the select() call.  _MD_SELECT refers to the built-in,
  392.  * unwrapped version.
  393.  */
  394. #define _MD_SELECT __select
  395.  
  396. #ifdef _PR_POLL_AVAILABLE
  397. #include <sys/poll.h>
  398. extern int __syscall_poll(struct pollfd *ufds, unsigned long int nfds,
  399.     int timeout);
  400. #define _MD_POLL __syscall_poll
  401. #endif
  402.  
  403. /* For writev() */
  404. #include <sys/uio.h>
  405.  
  406. #endif /* nspr_linux_defs_h___ */
  407.