home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / nspr30-e.zip / nspr30-e / include / md / _reliantunix.h < prev    next >
C/C++ Source or Header  |  1998-11-02  |  8KB  |  250 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. /*
  20.  * reliantunix.h
  21.  * 5/18/96 Taken from nec.h -- chrisk@netscape.com
  22.  * 3/14/97 Modified for nspr20 -- chrisk@netscape.com
  23.  */
  24. #ifndef nspr_reliantunix_defs_h___
  25. #define nspr_reliantunix_defs_h___
  26.  
  27. /*
  28.  * Internal configuration macros
  29.  */
  30.  
  31. #define PR_LINKER_ARCH    "sinix"
  32. #define _PR_SI_SYSNAME    "SINIX"
  33. #define _PR_SI_ARCHITECTURE "mips"
  34. #define PR_DLL_SUFFIX ".so"
  35.  
  36. #define _PR_VMBASE        0x30000000
  37. #define _PR_STACK_VMBASE    0x50000000
  38. #define _MD_DEFAULT_STACK_SIZE    (2*65536L)
  39. #define _MD_MMAP_FLAGS        MAP_PRIVATE|MAP_FIXED
  40.  
  41. #undef  HAVE_STACK_GROWING_UP
  42. #define HAVE_DLL
  43. #define USE_DLFCN
  44. #define NEED_STRFTIME_LOCK
  45. #define NEED_TIME_R
  46. #define HAVE_NETCONFIG
  47. #define HAVE_WEAK_IO_SYMBOLS
  48. #define HAVE_WEAK_MALLOC_SYMBOLS
  49. #define _PR_RECV_BROKEN /* recv doesn't work on Unix Domain Sockets */
  50. #define _PR_POLL_AVAILABLE
  51. #define _PR_USE_POLL
  52.  
  53. /*
  54.  * Mike Patnode indicated that it is possibly safe now to use context-switching
  55.  * calls that do not change the signal mask, like setjmp vs. sigsetjmp.
  56.  * So we'll use our homegrown, getcontext/setcontext-compatible stuff which 
  57.  * will save us the getcontext/setcontext system calls at each context switch.
  58.  * It already works in FastTrack 2.01, so it should do it here :-)
  59.  *  - chrisk 040497
  60.  */
  61. #define USE_SETCXT /* temporarily disabled... */
  62.  
  63. #include <ucontext.h>
  64.  
  65. #ifdef USE_SETCXT
  66. /* use non-syscall machine language replacement */
  67. #define _GETCONTEXT        getcxt
  68. #define _SETCONTEXT        setcxt
  69. /* defined in os_ReliantUNIX.s */
  70. extern int getcxt(ucontext_t *);
  71. extern int setcxt(ucontext_t *);
  72. #else
  73. #define _GETCONTEXT        getcontext
  74. #define _SETCONTEXT        setcontext
  75. #endif
  76.  
  77. #define _MD_GET_SP(_t)        (_t)->md.context.uc_mcontext.gpregs[CXT_SP]
  78. #define _PR_CONTEXT_TYPE    ucontext_t
  79. #define _PR_NUM_GCREGS        NGREG
  80.  
  81. #define CONTEXT(_thread) (&(_thread)->md.context)
  82.  
  83. #define _PR_IS_NATIVE_THREAD_SUPPORTED() 0
  84.  
  85. /*
  86. ** Machine-dependent (MD) data structures.
  87. */
  88. struct _MDThread {
  89.     _PR_CONTEXT_TYPE context;
  90.     int id;
  91.     int errcode;
  92. };
  93.  
  94. struct _MDThreadStack {
  95.     PRInt8 notused;
  96. };
  97.  
  98. struct _MDLock {
  99.     PRInt8 notused;
  100. };
  101.  
  102. struct _MDSemaphore {
  103.     PRInt8 notused;
  104. };
  105.  
  106. struct _MDCVar {
  107.     PRInt8 notused;
  108. };
  109.  
  110. struct _MDSegment {
  111.     PRInt8 notused;
  112. };
  113.  
  114. /*
  115.  * md-specific cpu structure field
  116.  */
  117. #define _PR_MD_MAX_OSFD FD_SETSIZE
  118.  
  119. struct _MDCPU_Unix {
  120.     PRCList ioQ;
  121.     PRUint32 ioq_timeout;
  122.     PRInt32 ioq_max_osfd;
  123.     PRInt32 ioq_osfd_cnt;
  124. #ifndef _PR_USE_POLL
  125.     fd_set fd_read_set, fd_write_set, fd_exception_set;
  126.     PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
  127.                 fd_exception_cnt[_PR_MD_MAX_OSFD];
  128. #else
  129.     struct pollfd *ioq_pollfds;
  130.     int ioq_pollfds_size;
  131. #endif    /* _PR_USE_POLL */
  132. };
  133.  
  134. #define _PR_IOQ(_cpu)            ((_cpu)->md.md_unix.ioQ)
  135. #define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
  136. #define _PR_FD_READ_SET(_cpu)        ((_cpu)->md.md_unix.fd_read_set)
  137. #define _PR_FD_READ_CNT(_cpu)        ((_cpu)->md.md_unix.fd_read_cnt)
  138. #define _PR_FD_WRITE_SET(_cpu)        ((_cpu)->md.md_unix.fd_write_set)
  139. #define _PR_FD_WRITE_CNT(_cpu)        ((_cpu)->md.md_unix.fd_write_cnt)
  140. #define _PR_FD_EXCEPTION_SET(_cpu)    ((_cpu)->md.md_unix.fd_exception_set)
  141. #define _PR_FD_EXCEPTION_CNT(_cpu)    ((_cpu)->md.md_unix.fd_exception_cnt)
  142. #define _PR_IOQ_TIMEOUT(_cpu)        ((_cpu)->md.md_unix.ioq_timeout)
  143. #define _PR_IOQ_MAX_OSFD(_cpu)        ((_cpu)->md.md_unix.ioq_max_osfd)
  144. #define _PR_IOQ_OSFD_CNT(_cpu)        ((_cpu)->md.md_unix.ioq_osfd_cnt)
  145. #define _PR_IOQ_POLLFDS(_cpu)        ((_cpu)->md.md_unix.ioq_pollfds)
  146. #define _PR_IOQ_POLLFDS_SIZE(_cpu)    ((_cpu)->md.md_unix.ioq_pollfds_size)
  147.  
  148. #define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)    32
  149.  
  150. struct _MDCPU {
  151.     struct _MDCPU_Unix md_unix;
  152. };
  153.  
  154. #define _MD_INIT_LOCKS()
  155. #define _MD_NEW_LOCK(lock) PR_SUCCESS
  156. #define _MD_FREE_LOCK(lock)
  157. #define _MD_LOCK(lock)
  158. #define _MD_UNLOCK(lock)
  159. #define _MD_INIT_IO()
  160. #define _MD_IOQ_LOCK()
  161. #define _MD_IOQ_UNLOCK()
  162.  
  163. /*
  164. ** Initialize the thread context preparing it to execute "_main()"
  165. ** - get a nice, fresh context
  166. ** - set its SP to the stack we allcoated for it
  167. ** - set it to start things at "e"
  168. */
  169. #define _MD_INIT_CONTEXT(thread, _sp, _main, status)                \
  170.     PR_BEGIN_MACRO                                                  \
  171.     *status = PR_TRUE;                                              \
  172.     _GETCONTEXT(CONTEXT(thread));                                   \
  173.     /* this is supposed to point to the stack BASE, not to SP */    \
  174.     CONTEXT(thread)->uc_stack.ss_sp = thread->stack->stackBottom;   \
  175.     CONTEXT(thread)->uc_stack.ss_size = thread->stack->stackSize;   \
  176.     CONTEXT(thread)->uc_mcontext.gpregs[CXT_SP] = ((unsigned long)_sp - 128) & 0xfffffff8; \
  177.     CONTEXT(thread)->uc_mcontext.gpregs[CXT_T9] = _main;            \
  178.     CONTEXT(thread)->uc_mcontext.gpregs[CXT_EPC] = _main;           \
  179.     CONTEXT(thread)->uc_mcontext.gpregs[CXT_RA] = 0;                \
  180.     thread->no_sched = 0;                                           \
  181.     PR_END_MACRO
  182.  
  183. /*
  184. ** Save current context as it is scheduled away
  185. */
  186. #define _MD_SWITCH_CONTEXT(_thread)       \
  187.     PR_BEGIN_MACRO                        \
  188.     if (!_GETCONTEXT(CONTEXT(_thread))) { \
  189.     _MD_SAVE_ERRNO(_thread);          \
  190.     _MD_SET_LAST_THREAD(_thread);     \
  191.         _PR_Schedule();                   \
  192.     }                                     \
  193.     PR_END_MACRO
  194.  
  195. /*
  196. ** Restore a thread context, saved by _MD_SWITCH_CONTEXT or set up
  197. **  by _MD_INIT_CONTEXT
  198. **  CXT_V0 is the register that holds the return value.
  199. **   We must set it to 1 so that we can see if the return from
  200. **   getcontext() is the result of calling getcontext() or
  201. **   setcontext()...
  202. **   setting a context got with getcontext() appears to
  203. **   return from getcontext(), too!
  204. **  CXT_A3 is the register that holds status when returning
  205. **   from a syscall. It is set to 0 to indicate success,
  206. **   because we want getcontext() on the other side of the magic
  207. **   door to be ok.
  208. */
  209. #define _MD_RESTORE_CONTEXT(_thread)   \
  210.     PR_BEGIN_MACRO                     \
  211.     ucontext_t *uc = CONTEXT(_thread); \
  212.     uc->uc_mcontext.gpregs[CXT_V0] = 1;\
  213.     uc->uc_mcontext.gpregs[CXT_A3] = 0;\
  214.     _MD_RESTORE_ERRNO(_thread);        \
  215.     _MD_SET_CURRENT_THREAD(_thread);   \
  216.     _SETCONTEXT(uc);                   \
  217.     PR_END_MACRO
  218.  
  219. #define _MD_SAVE_ERRNO(t)     (t)->md.errcode = errno;
  220. #define _MD_RESTORE_ERRNO(t)     errno = (t)->md.errcode;
  221.  
  222. #define _MD_GET_INTERVAL    _PR_UNIX_GetInterval
  223. #define _MD_INTERVAL_PER_SEC    _PR_UNIX_TicksPerSecond
  224.  
  225. #define _MD_EARLY_INIT        _MD_EarlyInit
  226. #define _MD_FINAL_INIT        _PR_UnixInit
  227. #define _MD_INIT_RUNNING_CPU(cpu) _MD_unix_init_running_cpu(cpu)
  228. #define _MD_INIT_THREAD        _MD_InitializeThread
  229. #define _MD_EXIT_THREAD(thread)
  230. #define _MD_SUSPEND_THREAD(thread)
  231. #define _MD_RESUME_THREAD(thread)
  232. #define _MD_CLEAN_THREAD(_thread)
  233.  
  234. #if !defined(S_ISSOCK) && defined(S_IFSOCK)
  235. #define S_ISSOCK(mode)   ((mode&0xF000) == 0xC000)
  236. #endif
  237. #if !defined(S_ISLNK) && defined(S_IFLNK)
  238. #define S_ISLNK(mode)   ((mode&0xA000) == 0xC000)
  239. #endif
  240.  
  241. #include <sys/time.h>
  242. #include <sys/types.h>
  243. #include <sys/select.h>
  244. extern int _select(int nfds, fd_set *readfds, fd_set *writefds,
  245.     fd_set *execptfds, struct timeval *timeout);
  246. #define _MD_SELECT(nfds,r,w,e,tv) _select(nfds,r,w,e,tv)
  247. #define _MD_POLL _poll
  248.  
  249. #endif /* nspr_reliantunix_defs_h___ */
  250.