_freebsd.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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_freebsd_defs_h___
  6. #define nspr_freebsd_defs_h___
  7. #include "prthread.h"
  8. #if __FreeBSD__ >= 2
  9. #include <osreldate.h> /* for __FreeBSD_version */
  10. #endif
  11. #include <sys/syscall.h>
  12. #define PR_LINKER_ARCH "freebsd"
  13. #define _PR_SI_SYSNAME "FREEBSD"
  14. #if defined(__i386__)
  15. #define _PR_SI_ARCHITECTURE "x86"
  16. #elif defined(__alpha__)
  17. #define _PR_SI_ARCHITECTURE "alpha"
  18. #elif defined(__sparc__)
  19. #define _PR_SI_ARCHITECTURE "sparc"
  20. #elif defined(__ia64__)
  21. #define _PR_SI_ARCHITECTURE "ia64"
  22. #elif defined(__amd64__)
  23. #define _PR_SI_ARCHITECTURE "amd64"
  24. #elif defined(__powerpc64__)
  25. #define _PR_SI_ARCHITECTURE "powerpc64"
  26. #elif defined(__powerpc__)
  27. #define _PR_SI_ARCHITECTURE "powerpc"
  28. #elif defined(__aarch64__)
  29. #define _PR_SI_ARCHITECTURE "aarch64"
  30. #elif defined(__arm__)
  31. #define _PR_SI_ARCHITECTURE "arm"
  32. #elif defined(__mips64__)
  33. #define _PR_SI_ARCHITECTURE "mips64"
  34. #elif defined(__mips__)
  35. #define _PR_SI_ARCHITECTURE "mips"
  36. #else
  37. #error "Unknown CPU architecture"
  38. #endif
  39. #if defined(__ELF__)
  40. #define PR_DLL_SUFFIX ".so"
  41. #else
  42. #define PR_DLL_SUFFIX ".so.1.0"
  43. #endif
  44. #define _PR_VMBASE 0x30000000
  45. #define _PR_STACK_VMBASE 0x50000000
  46. #define _MD_DEFAULT_STACK_SIZE 65536L
  47. #define _MD_MMAP_FLAGS MAP_PRIVATE
  48. #undef HAVE_STACK_GROWING_UP
  49. #define HAVE_DLL
  50. #define USE_DLFCN
  51. #define _PR_HAVE_SOCKADDR_LEN
  52. #define _PR_STAT_HAS_ST_ATIMESPEC
  53. #define _PR_HAVE_LARGE_OFF_T
  54. #if defined(_PR_PTHREADS)
  55. #if __FreeBSD_version >= 400008
  56. /*
  57. * libc_r before this version of FreeBSD doesn't have poll().
  58. * Although libc has poll(), it is not thread-safe so we can't
  59. * use it in the pthreads version.
  60. */
  61. #define _PR_POLL_AVAILABLE
  62. #endif
  63. #else
  64. #if __FreeBSD_version >= 300000
  65. #define _PR_POLL_AVAILABLE
  66. #define _PR_USE_POLL
  67. #endif
  68. #endif
  69. #define _PR_HAVE_SYSV_SEMAPHORES
  70. #define PR_HAVE_SYSV_NAMED_SHARED_MEMORY
  71. #if __FreeBSD_version >= 400014
  72. #define _PR_INET6
  73. #define _PR_HAVE_INET_NTOP
  74. #define _PR_HAVE_GETHOSTBYNAME2
  75. #define _PR_HAVE_GETADDRINFO
  76. #define _PR_INET6_PROBE
  77. #define _PR_IPV6_V6ONLY_PROBE
  78. #endif
  79. #define USE_SETJMP
  80. #ifndef _PR_PTHREADS
  81. #include <setjmp.h>
  82. #define PR_CONTEXT_TYPE sigjmp_buf
  83. #define CONTEXT(_th) ((_th)->md.context)
  84. #define _MD_GET_SP(_th) (_th)->md.context[0]._sjb[2]
  85. #define PR_NUM_GCREGS _JBLEN
  86. /*
  87. ** Initialize a thread context to run "_main()" when started
  88. */
  89. #define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
  90. { \
  91. *status = PR_TRUE; \
  92. if (sigsetjmp(CONTEXT(_thread), 1)) { \
  93. _main(); \
  94. } \
  95. _MD_GET_SP(_thread) = (unsigned char*) ((_sp) - 64); \
  96. }
  97. #define _MD_SWITCH_CONTEXT(_thread) \
  98. if (!sigsetjmp(CONTEXT(_thread), 1)) { \
  99. (_thread)->md.errcode = errno; \
  100. _PR_Schedule(); \
  101. }
  102. /*
  103. ** Restore a thread context, saved by _MD_SWITCH_CONTEXT
  104. */
  105. #define _MD_RESTORE_CONTEXT(_thread) \
  106. { \
  107. errno = (_thread)->md.errcode; \
  108. _MD_SET_CURRENT_THREAD(_thread); \
  109. siglongjmp(CONTEXT(_thread), 1); \
  110. }
  111. /* Machine-dependent (MD) data structures */
  112. struct _MDThread {
  113. PR_CONTEXT_TYPE context;
  114. int id;
  115. int errcode;
  116. };
  117. struct _MDThreadStack {
  118. PRInt8 notused;
  119. };
  120. struct _MDLock {
  121. PRInt8 notused;
  122. };
  123. struct _MDSemaphore {
  124. PRInt8 notused;
  125. };
  126. struct _MDCVar {
  127. PRInt8 notused;
  128. };
  129. struct _MDSegment {
  130. PRInt8 notused;
  131. };
  132. /*
  133. * md-specific cpu structure field
  134. */
  135. #define _PR_MD_MAX_OSFD FD_SETSIZE
  136. struct _MDCPU_Unix {
  137. PRCList ioQ;
  138. PRUint32 ioq_timeout;
  139. PRInt32 ioq_max_osfd;
  140. PRInt32 ioq_osfd_cnt;
  141. #ifndef _PR_USE_POLL
  142. fd_set fd_read_set, fd_write_set, fd_exception_set;
  143. PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
  144. fd_exception_cnt[_PR_MD_MAX_OSFD];
  145. #else
  146. struct pollfd *ioq_pollfds;
  147. int ioq_pollfds_size;
  148. #endif /* _PR_USE_POLL */
  149. };
  150. #define _PR_IOQ(_cpu) ((_cpu)->md.md_unix.ioQ)
  151. #define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
  152. #define _PR_FD_READ_SET(_cpu) ((_cpu)->md.md_unix.fd_read_set)
  153. #define _PR_FD_READ_CNT(_cpu) ((_cpu)->md.md_unix.fd_read_cnt)
  154. #define _PR_FD_WRITE_SET(_cpu) ((_cpu)->md.md_unix.fd_write_set)
  155. #define _PR_FD_WRITE_CNT(_cpu) ((_cpu)->md.md_unix.fd_write_cnt)
  156. #define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set)
  157. #define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt)
  158. #define _PR_IOQ_TIMEOUT(_cpu) ((_cpu)->md.md_unix.ioq_timeout)
  159. #define _PR_IOQ_MAX_OSFD(_cpu) ((_cpu)->md.md_unix.ioq_max_osfd)
  160. #define _PR_IOQ_OSFD_CNT(_cpu) ((_cpu)->md.md_unix.ioq_osfd_cnt)
  161. #define _PR_IOQ_POLLFDS(_cpu) ((_cpu)->md.md_unix.ioq_pollfds)
  162. #define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size)
  163. #define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu) 32
  164. struct _MDCPU {
  165. struct _MDCPU_Unix md_unix;
  166. };
  167. #define _MD_INIT_LOCKS()
  168. #define _MD_NEW_LOCK(lock) PR_SUCCESS
  169. #define _MD_FREE_LOCK(lock)
  170. #define _MD_LOCK(lock)
  171. #define _MD_UNLOCK(lock)
  172. #define _MD_INIT_IO()
  173. #define _MD_IOQ_LOCK()
  174. #define _MD_IOQ_UNLOCK()
  175. extern PRStatus _MD_InitializeThread(PRThread *thread);
  176. #define _MD_INIT_RUNNING_CPU(cpu) _MD_unix_init_running_cpu(cpu)
  177. #define _MD_INIT_THREAD _MD_InitializeThread
  178. #define _MD_EXIT_THREAD(thread)
  179. #define _MD_SUSPEND_THREAD(thread) _MD_suspend_thread
  180. #define _MD_RESUME_THREAD(thread) _MD_resume_thread
  181. #define _MD_CLEAN_THREAD(_thread)
  182. extern PRStatus _MD_CREATE_THREAD(
  183. PRThread *thread,
  184. void (*start) (void *),
  185. PRThreadPriority priority,
  186. PRThreadScope scope,
  187. PRThreadState state,
  188. PRUint32 stackSize);
  189. extern void _MD_SET_PRIORITY(struct _MDThread *thread, PRUintn newPri);
  190. extern PRStatus _MD_WAIT(PRThread *, PRIntervalTime timeout);
  191. extern PRStatus _MD_WAKEUP_WAITER(PRThread *);
  192. extern void _MD_YIELD(void);
  193. #endif /* ! _PR_PTHREADS */
  194. extern void _MD_EarlyInit(void);
  195. #define _MD_EARLY_INIT _MD_EarlyInit
  196. #define _MD_FINAL_INIT _PR_UnixInit
  197. #define _PR_HAVE_CLOCK_MONOTONIC
  198. /*
  199. * We wrapped the select() call. _MD_SELECT refers to the built-in,
  200. * unwrapped version.
  201. */
  202. #define _MD_SELECT(nfds,r,w,e,tv) syscall(SYS_select,nfds,r,w,e,tv)
  203. #if defined(_PR_POLL_AVAILABLE)
  204. #include <poll.h>
  205. #define _MD_POLL(fds,nfds,timeout) syscall(SYS_poll,fds,nfds,timeout)
  206. #endif
  207. /* freebsd has INADDR_LOOPBACK defined, but in /usr/include/rpc/types.h, and I didn't
  208. want to be including that.. */
  209. #ifndef INADDR_LOOPBACK
  210. #define INADDR_LOOPBACK (u_long)0x7F000001
  211. #endif
  212. /* For writev() */
  213. #include <sys/uio.h>
  214. #endif /* nspr_freebsd_defs_h___ */