home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / nsprpub / pr / include / md / _linux.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  6.1 KB  |  247 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. /*
  23.  * Internal configuration macros
  24.  */
  25.  
  26. #define PR_LINKER_ARCH    "linux"
  27. #define _PR_SI_SYSNAME  "LINUX"
  28. #ifdef __powerpc__
  29. #define _PR_SI_ARCHITECTURE "ppc"
  30. #elif defined(__alpha)
  31. #define _PR_SI_ARCHITECTURE "alpha"
  32. #else
  33. #define _PR_SI_ARCHITECTURE "x86"
  34. #endif
  35. #define PR_DLL_SUFFIX        ".so"
  36.  
  37. #define _PR_VMBASE              0x30000000
  38. #define _PR_STACK_VMBASE    0x50000000
  39. #define _MD_DEFAULT_STACK_SIZE    65536L
  40. #define _MD_MMAP_FLAGS          MAP_PRIVATE
  41.  
  42. #undef    HAVE_STACK_GROWING_UP
  43.  
  44. /*
  45.  * Elf linux supports dl* functions
  46.  */
  47. #if defined(LINUX1_2) || defined(LINUX2_0)
  48. #define HAVE_DLL
  49. #define USE_DLFCN
  50. #else
  51. #undef    HAVE_DLL
  52. #undef    USE_DLFCN
  53. #endif
  54.  
  55. #if !defined(MACLINUX) && !defined(NEED_TIME_R)
  56. #define NEED_TIME_R
  57. #endif
  58.  
  59. #if defined(_PR_PTHREADS) && !(defined(__GLIBC__) && __GLIBC__ >= 2)
  60. #define _PR_NEED_FAKE_POLL
  61. #endif
  62.  
  63. #define USE_SETJMP
  64.  
  65. #ifdef _PR_PTHREADS
  66.  
  67. extern void _MD_CleanupBeforeExit(void);
  68. #define _MD_CLEANUP_BEFORE_EXIT _MD_CleanupBeforeExit
  69.  
  70. #else  /* ! _PR_PTHREADS */
  71.  
  72. #include <setjmp.h>
  73.  
  74. #define PR_CONTEXT_TYPE    sigjmp_buf
  75.  
  76. #define CONTEXT(_th) ((_th)->md.context)
  77.  
  78. #ifdef __powerpc__
  79. /* PowerPC based MkLinux */
  80. #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__misc[0]
  81. /* aix = 64, macos = 70 */
  82. #define PR_NUM_GCREGS  64
  83.  
  84. #elif defined(__alpha)
  85. /* Alpha based Linux */
  86.  
  87. #if defined(__GLIBC__) && __GLIBC__ >= 2
  88. #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[JB_SP]
  89. #else
  90. #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__sp
  91. #endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */
  92.  
  93. /* XXX not sure if this is correct, or maybe it should be 17? */
  94. #define PR_NUM_GCREGS 9
  95.  
  96. #else
  97. /* Intel based Linux */
  98. #if defined(__GLIBC__) && __GLIBC__ >= 2
  99. #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[JB_SP]
  100. #else
  101. #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__sp
  102. #endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */
  103. #define PR_NUM_GCREGS   6
  104.  
  105. #endif /*__powerpc__*/
  106.  
  107. /*
  108. ** Initialize a thread context to run "_main()" when started
  109. */
  110. #ifdef __powerpc__
  111.  
  112. #define _MD_INIT_CONTEXT(_thread, _sp, _main, status)  \
  113. {  \
  114.     *status = PR_TRUE;  \
  115.     if (sigsetjmp(CONTEXT(_thread), 1)) {  \
  116.         _main();  \
  117.     }  \
  118.     _MD_GET_SP(_thread) = (unsigned char*) ((_sp) - 128); \
  119. }
  120.  
  121. #else
  122.  
  123. #define _MD_INIT_CONTEXT(_thread, _sp, _main, status)  \
  124. {  \
  125.     *status = PR_TRUE;  \
  126.     if (sigsetjmp(CONTEXT(_thread), 1)) {  \
  127.         _main();  \
  128.     }  \
  129.     _MD_GET_SP(_thread) = (unsigned char*) ((_sp) - 64); \
  130. }
  131.  
  132. #endif /*__powerpc__*/
  133.  
  134. #define _MD_SWITCH_CONTEXT(_thread)  \
  135.     if (!sigsetjmp(CONTEXT(_thread), 1)) {  \
  136.     (_thread)->md.errcode = errno;  \
  137.     _PR_Schedule();  \
  138.     }
  139.  
  140. /*
  141. ** Restore a thread context, saved by _MD_SWITCH_CONTEXT
  142. */
  143. #define _MD_RESTORE_CONTEXT(_thread) \
  144. {   \
  145.     errno = (_thread)->md.errcode;  \
  146.     _MD_SET_CURRENT_THREAD(_thread);  \
  147.     siglongjmp(CONTEXT(_thread), 1);  \
  148. }
  149.  
  150. /* Machine-dependent (MD) data structures */
  151.  
  152. struct _MDThread {
  153.     PR_CONTEXT_TYPE context;
  154.     int id;
  155.     int errcode;
  156. };
  157.  
  158. struct _MDThreadStack {
  159.     PRInt8 notused;
  160. };
  161.  
  162. struct _MDLock {
  163.     PRInt8 notused;
  164. };
  165.  
  166. struct _MDSemaphore {
  167.     PRInt8 notused;
  168. };
  169.  
  170. struct _MDCVar {
  171.     PRInt8 notused;
  172. };
  173.  
  174. struct _MDSegment {
  175.     PRInt8 notused;
  176. };
  177.  
  178. struct _MDCPU {
  179.     struct _MDCPU_Unix md_unix;
  180. };
  181.  
  182. #define _MD_INIT_LOCKS()
  183. #define _MD_NEW_LOCK(lock) PR_SUCCESS
  184. #define _MD_FREE_LOCK(lock)
  185. #define _MD_LOCK(lock)
  186. #define _MD_UNLOCK(lock)
  187. #define _MD_INIT_IO()
  188. #define _MD_IOQ_LOCK()
  189. #define _MD_IOQ_UNLOCK()
  190.  
  191. #define _MD_INIT_RUNNING_CPU(cpu)       _MD_unix_init_running_cpu(cpu)
  192. #define _MD_INIT_THREAD                 _MD_InitializeThread
  193. #define _MD_EXIT_THREAD(thread)
  194. #define _MD_SUSPEND_THREAD(thread)      _MD_suspend_thread
  195. #define _MD_RESUME_THREAD(thread)       _MD_resume_thread
  196. #define _MD_CLEAN_THREAD(_thread)
  197.  
  198. #endif /* ! _PR_PTHREADS */
  199.  
  200. #define _MD_EARLY_INIT                  _MD_EarlyInit
  201. #define _MD_FINAL_INIT                    _PR_UnixInit
  202. #define _MD_GET_INTERVAL                _PR_UNIX_GetInterval
  203. #define _MD_INTERVAL_PER_SEC            _PR_UNIX_TicksPerSecond
  204.  
  205. /*
  206.  * We wrapped the select() call.  _MD_SELECT refers to the built-in,
  207.  * unwrapped version.
  208.  */
  209. #define _MD_SELECT __select
  210.  
  211. #if defined(_PR_NEED_FAKE_POLL)
  212.  
  213. /*
  214.  * XXX: Linux doesn't have poll(), but our pthreads code calls poll().
  215.  * As a temporary measure, I implemented a fake poll() using select().
  216.  * Here are the struct and macro definitions copied from sys/poll.h
  217.  * on Solaris 2.5.
  218.  */
  219.  
  220. struct pollfd {
  221.     int fd;
  222.     short events;
  223.     short revents;
  224. };
  225.  
  226. /* poll events */
  227.  
  228. #define    POLLIN        0x0001        /* fd is readable */
  229. #define    POLLPRI        0x0002        /* high priority info at fd */
  230. #define    POLLOUT        0x0004        /* fd is writeable (won't block) */
  231. #define    POLLRDNORM    0x0040        /* normal data is readable */
  232. #define    POLLWRNORM    POLLOUT
  233. #define    POLLRDBAND    0x0080        /* out-of-band data is readable */
  234. #define    POLLWRBAND    0x0100        /* out-of-band data is writeable */
  235.  
  236. #define    POLLNORM    POLLRDNORM
  237.  
  238. #define    POLLERR        0x0008        /* fd has error condition */
  239. #define    POLLHUP        0x0010        /* fd has been hung up on */
  240. #define    POLLNVAL    0x0020        /* invalid pollfd entry */
  241.  
  242. extern int poll(struct pollfd *, unsigned long, int);
  243.  
  244. #endif /* _PR_NEED_FAKE_POLL */
  245.  
  246. #endif /* nspr_linux_defs_h___ */
  247.