_openbsd.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef nspr_openbsd_defs_h___
  6. #define nspr_openbsd_defs_h___
  7. #include <sys/syscall.h>
  8. #define PR_LINKER_ARCH "openbsd"
  9. #define _PR_SI_SYSNAME "OPENBSD"
  10. #if defined(__i386__)
  11. #define _PR_SI_ARCHITECTURE "x86"
  12. #elif defined(__alpha__)
  13. #define _PR_SI_ARCHITECTURE "alpha"
  14. #elif defined(__amd64__)
  15. #define _PR_SI_ARCHITECTURE "amd64"
  16. #elif defined(__m68k__)
  17. #define _PR_SI_ARCHITECTURE "m68k"
  18. #elif defined(__powerpc__)
  19. #define _PR_SI_ARCHITECTURE "powerpc"
  20. #elif defined(__sparc__)
  21. #define _PR_SI_ARCHITECTURE "sparc"
  22. #elif defined(__arm__)
  23. #define _PR_SI_ARCHITECTURE "arm"
  24. #endif
  25. #define PR_DLL_SUFFIX ".so"
  26. #define _PR_VMBASE 0x30000000
  27. #define _PR_STACK_VMBASE 0x50000000
  28. #define _MD_DEFAULT_STACK_SIZE 65536L
  29. #define _MD_MMAP_FLAGS MAP_PRIVATE
  30. #undef HAVE_STACK_GROWING_UP
  31. #define HAVE_DLL
  32. #define USE_DLFCN
  33. #define _PR_HAVE_SOCKADDR_LEN
  34. #define _PR_HAVE_LARGE_OFF_T
  35. #define _PR_STAT_HAS_ST_ATIMESPEC
  36. #define _PR_POLL_AVAILABLE
  37. #define _PR_USE_POLL
  38. #define _PR_HAVE_SYSV_SEMAPHORES
  39. #define PR_HAVE_SYSV_NAMED_SHARED_MEMORY
  40. #define _PR_INET6
  41. #define _PR_HAVE_INET_NTOP
  42. #define _PR_HAVE_GETHOSTBYNAME2
  43. #define _PR_HAVE_GETADDRINFO
  44. #define _PR_INET6_PROBE
  45. #define USE_SETJMP
  46. #ifndef _PR_PTHREADS
  47. #include <setjmp.h>
  48. #define PR_CONTEXT_TYPE sigjmp_buf
  49. #define CONTEXT(_th) ((_th)->md.context)
  50. #if defined(__i386__) || defined(__sparc__) || defined(__m68k__)
  51. #define JB_SP_INDEX 2
  52. #elif defined(__powerpc__)
  53. #define JB_SP_INDEX 1
  54. #elif defined(__alpha__)
  55. #define JB_SP_INDEX 34
  56. #elif defined(__amd64__)
  57. #define JB_SP_INDEX 6
  58. #elif defined(__arm__)
  59. #define JB_SP_INDEX 23
  60. #else
  61. #error "Need to define SP index in jmp_buf here"
  62. #endif
  63. #define _MD_GET_SP(_th) (_th)->md.context[JB_SP_INDEX]
  64. #define PR_NUM_GCREGS _JBLEN
  65. /*
  66. ** Initialize a thread context to run "_main()" when started
  67. */
  68. #define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
  69. { \
  70. *status = PR_TRUE; \
  71. if (sigsetjmp(CONTEXT(_thread), 1)) { \
  72. _main(); \
  73. } \
  74. _MD_GET_SP(_thread) = (unsigned char*) ((_sp) - 64); \
  75. }
  76. #define _MD_SWITCH_CONTEXT(_thread) \
  77. if (!sigsetjmp(CONTEXT(_thread), 1)) { \
  78. (_thread)->md.errcode = errno; \
  79. _PR_Schedule(); \
  80. }
  81. /*
  82. ** Restore a thread context, saved by _MD_SWITCH_CONTEXT
  83. */
  84. #define _MD_RESTORE_CONTEXT(_thread) \
  85. { \
  86. errno = (_thread)->md.errcode; \
  87. _MD_SET_CURRENT_THREAD(_thread); \
  88. siglongjmp(CONTEXT(_thread), 1); \
  89. }
  90. /* Machine-dependent (MD) data structures */
  91. struct _MDThread {
  92. PR_CONTEXT_TYPE context;
  93. int id;
  94. int errcode;
  95. };
  96. struct _MDThreadStack {
  97. PRInt8 notused;
  98. };
  99. struct _MDLock {
  100. PRInt8 notused;
  101. };
  102. struct _MDSemaphore {
  103. PRInt8 notused;
  104. };
  105. struct _MDCVar {
  106. PRInt8 notused;
  107. };
  108. struct _MDSegment {
  109. PRInt8 notused;
  110. };
  111. /*
  112. * md-specific cpu structure field
  113. */
  114. #define _PR_MD_MAX_OSFD FD_SETSIZE
  115. struct _MDCPU_Unix {
  116. PRCList ioQ;
  117. PRUint32 ioq_timeout;
  118. PRInt32 ioq_max_osfd;
  119. PRInt32 ioq_osfd_cnt;
  120. #ifndef _PR_USE_POLL
  121. fd_set fd_read_set, fd_write_set, fd_exception_set;
  122. PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
  123. fd_exception_cnt[_PR_MD_MAX_OSFD];
  124. #else
  125. struct pollfd *ioq_pollfds;
  126. int ioq_pollfds_size;
  127. #endif /* _PR_USE_POLL */
  128. };
  129. #define _PR_IOQ(_cpu) ((_cpu)->md.md_unix.ioQ)
  130. #define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
  131. #define _PR_FD_READ_SET(_cpu) ((_cpu)->md.md_unix.fd_read_set)
  132. #define _PR_FD_READ_CNT(_cpu) ((_cpu)->md.md_unix.fd_read_cnt)
  133. #define _PR_FD_WRITE_SET(_cpu) ((_cpu)->md.md_unix.fd_write_set)
  134. #define _PR_FD_WRITE_CNT(_cpu) ((_cpu)->md.md_unix.fd_write_cnt)
  135. #define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set)
  136. #define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt)
  137. #define _PR_IOQ_TIMEOUT(_cpu) ((_cpu)->md.md_unix.ioq_timeout)
  138. #define _PR_IOQ_MAX_OSFD(_cpu) ((_cpu)->md.md_unix.ioq_max_osfd)
  139. #define _PR_IOQ_OSFD_CNT(_cpu) ((_cpu)->md.md_unix.ioq_osfd_cnt)
  140. #define _PR_IOQ_POLLFDS(_cpu) ((_cpu)->md.md_unix.ioq_pollfds)
  141. #define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size)
  142. #define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu) 32
  143. struct _MDCPU {
  144. struct _MDCPU_Unix md_unix;
  145. };
  146. #define _MD_INIT_LOCKS()
  147. #define _MD_NEW_LOCK(lock) PR_SUCCESS
  148. #define _MD_FREE_LOCK(lock)
  149. #define _MD_LOCK(lock)
  150. #define _MD_UNLOCK(lock)
  151. #define _MD_INIT_IO()
  152. #define _MD_IOQ_LOCK()
  153. #define _MD_IOQ_UNLOCK()
  154. #define _MD_INIT_RUNNING_CPU(cpu) _MD_unix_init_running_cpu(cpu)
  155. #define _MD_INIT_THREAD _MD_InitializeThread
  156. #define _MD_EXIT_THREAD(thread)
  157. #define _MD_SUSPEND_THREAD(thread) _MD_suspend_thread
  158. #define _MD_RESUME_THREAD(thread) _MD_resume_thread
  159. #define _MD_CLEAN_THREAD(_thread)
  160. #endif /* ! _PR_PTHREADS */
  161. #define _MD_EARLY_INIT _MD_EarlyInit
  162. #define _MD_FINAL_INIT _PR_UnixInit
  163. #define _PR_HAVE_CLOCK_MONOTONIC
  164. /*
  165. * We wrapped the select() call. _MD_SELECT refers to the built-in,
  166. * unwrapped version.
  167. */
  168. #define _MD_SELECT(nfds,r,w,e,tv) syscall(SYS_select,nfds,r,w,e,tv)
  169. #include <poll.h>
  170. #define _MD_POLL(fds,nfds,timeout) syscall(SYS_poll,fds,nfds,timeout)
  171. #if OpenBSD1_3 == 1L
  172. typedef unsigned int nfds_t;
  173. #endif
  174. #endif /* nspr_openbsd_defs_h___ */