_netbsd.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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_netbsd_defs_h___
  6. #define nspr_netbsd_defs_h___
  7. #include <sys/syscall.h>
  8. #include <sys/param.h> /* for __NetBSD_Version__ */
  9. #define PR_LINKER_ARCH "netbsd"
  10. #define _PR_SI_SYSNAME "NetBSD"
  11. #if defined(__i386__)
  12. #define _PR_SI_ARCHITECTURE "x86"
  13. #elif defined(__alpha__)
  14. #define _PR_SI_ARCHITECTURE "alpha"
  15. #elif defined(__amd64__)
  16. #define _PR_SI_ARCHITECTURE "amd64"
  17. #elif defined(__m68k__)
  18. #define _PR_SI_ARCHITECTURE "m68k"
  19. #elif defined(__powerpc__)
  20. #define _PR_SI_ARCHITECTURE "powerpc"
  21. #elif defined(__sparc_v9__)
  22. #define _PR_SI_ARCHITECTURE "sparc64"
  23. #elif defined(__sparc__)
  24. #define _PR_SI_ARCHITECTURE "sparc"
  25. #elif defined(__mips__)
  26. #define _PR_SI_ARCHITECTURE "mips"
  27. #elif defined(__arm32__) || defined(__arm__) || defined(__armel__) \
  28. || defined(__armeb__)
  29. #define _PR_SI_ARCHITECTURE "arm"
  30. #endif
  31. #if defined(__ELF__)
  32. #define PR_DLL_SUFFIX ".so"
  33. #else
  34. #define PR_DLL_SUFFIX ".so.1.0"
  35. #endif
  36. #define _PR_VMBASE 0x30000000
  37. #define _PR_STACK_VMBASE 0x50000000
  38. #define _MD_DEFAULT_STACK_SIZE 65536L
  39. #define _MD_MMAP_FLAGS MAP_PRIVATE
  40. #undef HAVE_STACK_GROWING_UP
  41. #define HAVE_DLL
  42. #define USE_DLFCN
  43. #define _PR_HAVE_SOCKADDR_LEN
  44. #define _PR_NO_LARGE_FILES
  45. #define _PR_STAT_HAS_ST_ATIMESPEC
  46. #define _PR_POLL_AVAILABLE
  47. #define _PR_USE_POLL
  48. #define _PR_HAVE_SYSV_SEMAPHORES
  49. #define PR_HAVE_SYSV_NAMED_SHARED_MEMORY
  50. #if __NetBSD_Version__ >= 105000000
  51. #define _PR_INET6
  52. #define _PR_HAVE_INET_NTOP
  53. #define _PR_HAVE_GETHOSTBYNAME2
  54. #define _PR_HAVE_GETADDRINFO
  55. #define _PR_INET6_PROBE
  56. #endif
  57. #define USE_SETJMP
  58. #ifndef _PR_PTHREADS
  59. #include <setjmp.h>
  60. #define PR_CONTEXT_TYPE sigjmp_buf
  61. #define CONTEXT(_th) ((_th)->md.context)
  62. #if defined(__i386__) || defined(__sparc__) || defined(__m68k__) || defined(__powerpc__)
  63. #define JB_SP_INDEX 2
  64. #elif defined(__mips__)
  65. #define JB_SP_INDEX 4
  66. #elif defined(__alpha__)
  67. #define JB_SP_INDEX 34
  68. #elif defined(__arm32__)
  69. /*
  70. * On the arm32, the jmpbuf regs underwent a name change after NetBSD 1.3.
  71. */
  72. #ifdef JMPBUF_REG_R13
  73. #define JB_SP_INDEX JMPBUF_REG_R13
  74. #else
  75. #define JB_SP_INDEX _JB_REG_R13
  76. #endif
  77. #else
  78. #error "Need to define SP index in jmp_buf here"
  79. #endif
  80. #define _MD_GET_SP(_th) (_th)->md.context[JB_SP_INDEX]
  81. #define PR_NUM_GCREGS _JBLEN
  82. /*
  83. ** Initialize a thread context to run "_main()" when started
  84. */
  85. #define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
  86. { \
  87. *status = PR_TRUE; \
  88. if (sigsetjmp(CONTEXT(_thread), 1)) { \
  89. _main(); \
  90. } \
  91. _MD_GET_SP(_thread) = (unsigned char*) ((_sp) - 64); \
  92. }
  93. #define _MD_SWITCH_CONTEXT(_thread) \
  94. if (!sigsetjmp(CONTEXT(_thread), 1)) { \
  95. (_thread)->md.errcode = errno; \
  96. _PR_Schedule(); \
  97. }
  98. /*
  99. ** Restore a thread context, saved by _MD_SWITCH_CONTEXT
  100. */
  101. #define _MD_RESTORE_CONTEXT(_thread) \
  102. { \
  103. errno = (_thread)->md.errcode; \
  104. _MD_SET_CURRENT_THREAD(_thread); \
  105. siglongjmp(CONTEXT(_thread), 1); \
  106. }
  107. /* Machine-dependent (MD) data structures */
  108. struct _MDThread {
  109. PR_CONTEXT_TYPE context;
  110. int id;
  111. int errcode;
  112. };
  113. struct _MDThreadStack {
  114. PRInt8 notused;
  115. };
  116. struct _MDLock {
  117. PRInt8 notused;
  118. };
  119. struct _MDSemaphore {
  120. PRInt8 notused;
  121. };
  122. struct _MDCVar {
  123. PRInt8 notused;
  124. };
  125. struct _MDSegment {
  126. PRInt8 notused;
  127. };
  128. /*
  129. * md-specific cpu structure field
  130. */
  131. #define _PR_MD_MAX_OSFD FD_SETSIZE
  132. struct _MDCPU_Unix {
  133. PRCList ioQ;
  134. PRUint32 ioq_timeout;
  135. PRInt32 ioq_max_osfd;
  136. PRInt32 ioq_osfd_cnt;
  137. #ifndef _PR_USE_POLL
  138. fd_set fd_read_set, fd_write_set, fd_exception_set;
  139. PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
  140. fd_exception_cnt[_PR_MD_MAX_OSFD];
  141. #else
  142. struct pollfd *ioq_pollfds;
  143. int ioq_pollfds_size;
  144. #endif /* _PR_USE_POLL */
  145. };
  146. #define _PR_IOQ(_cpu) ((_cpu)->md.md_unix.ioQ)
  147. #define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
  148. #define _PR_FD_READ_SET(_cpu) ((_cpu)->md.md_unix.fd_read_set)
  149. #define _PR_FD_READ_CNT(_cpu) ((_cpu)->md.md_unix.fd_read_cnt)
  150. #define _PR_FD_WRITE_SET(_cpu) ((_cpu)->md.md_unix.fd_write_set)
  151. #define _PR_FD_WRITE_CNT(_cpu) ((_cpu)->md.md_unix.fd_write_cnt)
  152. #define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set)
  153. #define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt)
  154. #define _PR_IOQ_TIMEOUT(_cpu) ((_cpu)->md.md_unix.ioq_timeout)
  155. #define _PR_IOQ_MAX_OSFD(_cpu) ((_cpu)->md.md_unix.ioq_max_osfd)
  156. #define _PR_IOQ_OSFD_CNT(_cpu) ((_cpu)->md.md_unix.ioq_osfd_cnt)
  157. #define _PR_IOQ_POLLFDS(_cpu) ((_cpu)->md.md_unix.ioq_pollfds)
  158. #define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size)
  159. #define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu) 32
  160. struct _MDCPU {
  161. struct _MDCPU_Unix md_unix;
  162. };
  163. #define _MD_INIT_LOCKS()
  164. #define _MD_NEW_LOCK(lock) PR_SUCCESS
  165. #define _MD_FREE_LOCK(lock)
  166. #define _MD_LOCK(lock)
  167. #define _MD_UNLOCK(lock)
  168. #define _MD_INIT_IO()
  169. #define _MD_IOQ_LOCK()
  170. #define _MD_IOQ_UNLOCK()
  171. #define _MD_INIT_RUNNING_CPU(cpu) _MD_unix_init_running_cpu(cpu)
  172. #define _MD_INIT_THREAD _MD_InitializeThread
  173. #define _MD_EXIT_THREAD(thread)
  174. #define _MD_SUSPEND_THREAD(thread) _MD_suspend_thread
  175. #define _MD_RESUME_THREAD(thread) _MD_resume_thread
  176. #define _MD_CLEAN_THREAD(_thread)
  177. #endif /* ! _PR_PTHREADS */
  178. extern void _MD_EarlyInit(void);
  179. #define _MD_EARLY_INIT _MD_EarlyInit
  180. #define _MD_FINAL_INIT _PR_UnixInit
  181. #define _PR_HAVE_CLOCK_MONOTONIC
  182. /*
  183. * We wrapped the select() call. _MD_SELECT refers to the built-in,
  184. * unwrapped version.
  185. */
  186. #define _MD_SELECT(nfds,r,w,e,tv) syscall(SYS_select,nfds,r,w,e,tv)
  187. #if defined(_PR_POLL_AVAILABLE)
  188. #include <poll.h>
  189. #define _MD_POLL(fds,nfds,timeout) syscall(SYS_poll,fds,nfds,timeout)
  190. #endif
  191. #if NetBSD1_3 == 1L
  192. typedef unsigned int nfds_t;
  193. #endif
  194. #endif /* nspr_netbsd_defs_h___ */