_reliantunix.h 8.9 KB

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