_solaris.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  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_solaris_defs_h___
  6. #define nspr_solaris_defs_h___
  7. /*
  8. * Internal configuration macros
  9. */
  10. #define PR_LINKER_ARCH "solaris"
  11. #define _PR_SI_SYSNAME "SOLARIS"
  12. #ifdef sparc
  13. #define _PR_SI_ARCHITECTURE "sparc"
  14. #elif defined(__x86_64)
  15. #define _PR_SI_ARCHITECTURE "x86-64"
  16. #elif defined(i386)
  17. #define _PR_SI_ARCHITECTURE "x86"
  18. #else
  19. #error unknown processor
  20. #endif
  21. #define PR_DLL_SUFFIX ".so"
  22. #define _PR_VMBASE 0x30000000
  23. #define _PR_STACK_VMBASE 0x50000000
  24. #define _MD_DEFAULT_STACK_SIZE (2*65536L)
  25. #define _MD_MMAP_FLAGS MAP_SHARED
  26. #undef HAVE_STACK_GROWING_UP
  27. #ifndef HAVE_WEAK_IO_SYMBOLS
  28. #define HAVE_WEAK_IO_SYMBOLS
  29. #endif
  30. #undef HAVE_WEAK_MALLOC_SYMBOLS
  31. #define HAVE_DLL
  32. #define USE_DLFCN
  33. #define NEED_STRFTIME_LOCK
  34. /*
  35. * Intel x86 has atomic instructions.
  36. *
  37. * Sparc v8 does not have instructions to efficiently implement
  38. * atomic increment/decrement operations. We use the default
  39. * atomic routine implementation in pratom.c.
  40. *
  41. * 64-bit Solaris requires sparc v9, which has atomic instructions.
  42. */
  43. #if defined(i386) || defined(IS_64)
  44. #define _PR_HAVE_ATOMIC_OPS
  45. #endif
  46. #define _PR_POLL_AVAILABLE
  47. #define _PR_USE_POLL
  48. #define _PR_STAT_HAS_ST_ATIM
  49. #ifdef SOLARIS2_5
  50. #define _PR_HAVE_SYSV_SEMAPHORES
  51. #define PR_HAVE_SYSV_NAMED_SHARED_MEMORY
  52. #else
  53. #define _PR_HAVE_POSIX_SEMAPHORES
  54. #define PR_HAVE_POSIX_NAMED_SHARED_MEMORY
  55. #endif
  56. #define _PR_HAVE_GETIPNODEBYNAME
  57. #define _PR_HAVE_GETIPNODEBYADDR
  58. #define _PR_HAVE_GETADDRINFO
  59. #define _PR_INET6_PROBE
  60. #define _PR_ACCEPT_INHERIT_NONBLOCK
  61. #ifdef _PR_INET6
  62. #define _PR_HAVE_INET_NTOP
  63. #else
  64. #define AF_INET6 26
  65. struct addrinfo {
  66. int ai_flags;
  67. int ai_family;
  68. int ai_socktype;
  69. int ai_protocol;
  70. size_t ai_addrlen;
  71. char *ai_canonname;
  72. struct sockaddr *ai_addr;
  73. struct addrinfo *ai_next;
  74. };
  75. #define AI_CANONNAME 0x0010
  76. #define AI_V4MAPPED 0x0001
  77. #define AI_ALL 0x0002
  78. #define AI_ADDRCONFIG 0x0004
  79. #define _PR_HAVE_MD_SOCKADDR_IN6
  80. /* isomorphic to struct in6_addr on Solaris 8 */
  81. struct _md_in6_addr {
  82. union {
  83. PRUint8 _S6_u8[16];
  84. PRUint32 _S6_u32[4];
  85. PRUint32 __S6_align;
  86. } _S6_un;
  87. };
  88. /* isomorphic to struct sockaddr_in6 on Solaris 8 */
  89. struct _md_sockaddr_in6 {
  90. PRUint16 sin6_family;
  91. PRUint16 sin6_port;
  92. PRUint32 sin6_flowinfo;
  93. struct _md_in6_addr sin6_addr;
  94. PRUint32 sin6_scope_id;
  95. PRUint32 __sin6_src_id;
  96. };
  97. #endif
  98. #if defined(_PR_PTHREADS)
  99. #define _PR_HAVE_GETHOST_R
  100. #define _PR_HAVE_GETHOST_R_POINTER
  101. #endif
  102. #include "prinrval.h"
  103. #define _MD_INTERVAL_INIT()
  104. NSPR_API(PRIntervalTime) _MD_Solaris_GetInterval(void);
  105. #define _MD_GET_INTERVAL _MD_Solaris_GetInterval
  106. NSPR_API(PRIntervalTime) _MD_Solaris_TicksPerSecond(void);
  107. #define _MD_INTERVAL_PER_SEC _MD_Solaris_TicksPerSecond
  108. #if defined(_PR_HAVE_ATOMIC_OPS)
  109. /*
  110. ** Atomic Operations
  111. */
  112. #define _MD_INIT_ATOMIC()
  113. NSPR_API(PRInt32) _MD_AtomicIncrement(PRInt32 *val);
  114. #define _MD_ATOMIC_INCREMENT _MD_AtomicIncrement
  115. NSPR_API(PRInt32) _MD_AtomicAdd(PRInt32 *ptr, PRInt32 val);
  116. #define _MD_ATOMIC_ADD _MD_AtomicAdd
  117. NSPR_API(PRInt32) _MD_AtomicDecrement(PRInt32 *val);
  118. #define _MD_ATOMIC_DECREMENT _MD_AtomicDecrement
  119. NSPR_API(PRInt32) _MD_AtomicSet(PRInt32 *val, PRInt32 newval);
  120. #define _MD_ATOMIC_SET _MD_AtomicSet
  121. #endif /* _PR_HAVE_ATOMIC_OPS */
  122. #if defined(_PR_PTHREADS)
  123. NSPR_API(void) _MD_EarlyInit(void);
  124. #define _MD_EARLY_INIT _MD_EarlyInit
  125. #define _MD_FINAL_INIT _PR_UnixInit
  126. #else /* _PR_PTHREADS */
  127. /*
  128. * _PR_LOCAL_THREADS_ONLY implementation on Solaris
  129. */
  130. #include "prthread.h"
  131. #include <errno.h>
  132. #include <ucontext.h>
  133. #include <sys/stack.h>
  134. #include <synch.h>
  135. /*
  136. ** Initialization Related definitions
  137. */
  138. NSPR_API(void) _MD_EarlyInit(void);
  139. NSPR_API(void) _MD_SolarisInit();
  140. #define _MD_EARLY_INIT _MD_EarlyInit
  141. #define _MD_FINAL_INIT _MD_SolarisInit
  142. #define _MD_INIT_THREAD _MD_InitializeThread
  143. #ifdef USE_SETJMP
  144. #include <setjmp.h>
  145. #define _PR_CONTEXT_TYPE jmp_buf
  146. #ifdef sparc
  147. #define _MD_GET_SP(_t) (_t)->md.context[2]
  148. #else
  149. #define _MD_GET_SP(_t) (_t)->md.context[4]
  150. #endif
  151. #define PR_NUM_GCREGS _JBLEN
  152. #define CONTEXT(_thread) (_thread)->md.context
  153. #else /* ! USE_SETJMP */
  154. #ifdef sparc
  155. #define _PR_CONTEXT_TYPE ucontext_t
  156. #define _MD_GET_SP(_t) (_t)->md.context.uc_mcontext.gregs[REG_SP]
  157. /*
  158. ** Sparc's use register windows. the _MD_GetRegisters for the sparc's
  159. ** doesn't actually store anything into the argument buffer; instead the
  160. ** register windows are homed to the stack. I assume that the stack
  161. ** always has room for the registers to spill to...
  162. */
  163. #define PR_NUM_GCREGS 0
  164. #else
  165. #define _PR_CONTEXT_TYPE unsigned int edi; sigset_t oldMask, blockMask; ucontext_t
  166. #define _MD_GET_SP(_t) (_t)->md.context.uc_mcontext.gregs[USP]
  167. #define PR_NUM_GCREGS _JBLEN
  168. #endif
  169. #define CONTEXT(_thread) (&(_thread)->md.context)
  170. #endif /* ! USE_SETJMP */
  171. #include <time.h>
  172. /*
  173. * Because clock_gettime() on Solaris/x86 always generates a
  174. * segmentation fault, we use an emulated version _pr_solx86_clock_gettime(),
  175. * which is implemented using gettimeofday().
  176. */
  177. #ifdef i386
  178. #define GETTIME(tt) _pr_solx86_clock_gettime(CLOCK_REALTIME, (tt))
  179. #else
  180. #define GETTIME(tt) clock_gettime(CLOCK_REALTIME, (tt))
  181. #endif /* i386 */
  182. #define _MD_SAVE_ERRNO(_thread) (_thread)->md.errcode = errno;
  183. #define _MD_RESTORE_ERRNO(_thread) errno = (_thread)->md.errcode;
  184. #ifdef sparc
  185. #ifdef USE_SETJMP
  186. #define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
  187. PR_BEGIN_MACRO \
  188. int *context = (_thread)->md.context; \
  189. *status = PR_TRUE; \
  190. (void) setjmp(context); \
  191. (_thread)->md.context[1] = (int) ((_sp) - 64); \
  192. (_thread)->md.context[2] = (int) _main; \
  193. (_thread)->md.context[3] = (int) _main + 4; \
  194. _thread->no_sched = 0; \
  195. PR_END_MACRO
  196. #define _MD_SWITCH_CONTEXT(_thread) \
  197. if (!setjmp(CONTEXT(_thread))) { \
  198. _MD_SAVE_ERRNO(_thread) \
  199. _MD_SET_LAST_THREAD(_thread); \
  200. _MD_SET_CURRENT_THREAD(_thread); \
  201. _PR_Schedule(); \
  202. }
  203. #define _MD_RESTORE_CONTEXT(_newThread) \
  204. { \
  205. _MD_RESTORE_ERRNO(_newThread) \
  206. _MD_SET_CURRENT_THREAD(_newThread); \
  207. longjmp(CONTEXT(_newThread), 1); \
  208. }
  209. #else
  210. /*
  211. ** Initialize the thread context preparing it to execute _main.
  212. */
  213. #define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
  214. PR_BEGIN_MACRO \
  215. ucontext_t *uc = CONTEXT(_thread); \
  216. *status = PR_TRUE; \
  217. getcontext(uc); \
  218. uc->uc_stack.ss_sp = (char *) ((unsigned long)(_sp - WINDOWSIZE - SA(MINFRAME)) & 0xfffffff8); \
  219. uc->uc_stack.ss_size = _thread->stack->stackSize; \
  220. uc->uc_stack.ss_flags = 0; /* ? */ \
  221. uc->uc_mcontext.gregs[REG_SP] = (unsigned int) uc->uc_stack.ss_sp; \
  222. uc->uc_mcontext.gregs[REG_PC] = (unsigned int) _main; \
  223. uc->uc_mcontext.gregs[REG_nPC] = (unsigned int) ((char*)_main)+4; \
  224. uc->uc_flags = UC_ALL; \
  225. _thread->no_sched = 0; \
  226. PR_END_MACRO
  227. /*
  228. ** Switch away from the current thread context by saving its state and
  229. ** calling the thread scheduler. Reload cpu when we come back from the
  230. ** context switch because it might have changed.
  231. */
  232. #define _MD_SWITCH_CONTEXT(_thread) \
  233. PR_BEGIN_MACRO \
  234. if (!getcontext(CONTEXT(_thread))) { \
  235. _MD_SAVE_ERRNO(_thread); \
  236. _MD_SET_LAST_THREAD(_thread); \
  237. _PR_Schedule(); \
  238. } \
  239. PR_END_MACRO
  240. /*
  241. ** Restore a thread context that was saved by _MD_SWITCH_CONTEXT or
  242. ** initialized by _MD_INIT_CONTEXT.
  243. */
  244. #define _MD_RESTORE_CONTEXT(_newThread) \
  245. PR_BEGIN_MACRO \
  246. ucontext_t *uc = CONTEXT(_newThread); \
  247. uc->uc_mcontext.gregs[11] = 1; \
  248. _MD_RESTORE_ERRNO(_newThread); \
  249. _MD_SET_CURRENT_THREAD(_newThread); \
  250. setcontext(uc); \
  251. PR_END_MACRO
  252. #endif
  253. #else /* x86 solaris */
  254. #ifdef USE_SETJMP
  255. #define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
  256. PR_BEGIN_MACRO \
  257. *status = PR_TRUE; \
  258. if (setjmp(CONTEXT(_thread))) _main(); \
  259. _MD_GET_SP(_thread) = (int) ((_sp) - 64); \
  260. PR_END_MACRO
  261. #define _MD_SWITCH_CONTEXT(_thread) \
  262. if (!setjmp(CONTEXT(_thread))) { \
  263. _MD_SAVE_ERRNO(_thread) \
  264. _PR_Schedule(); \
  265. }
  266. #define _MD_RESTORE_CONTEXT(_newThread) \
  267. { \
  268. _MD_RESTORE_ERRNO(_newThread) \
  269. _MD_SET_CURRENT_THREAD(_newThread); \
  270. longjmp(CONTEXT(_newThread), 1); \
  271. }
  272. #else /* USE_SETJMP */
  273. #define WINDOWSIZE 0
  274. int getedi(void);
  275. void setedi(int);
  276. #define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
  277. PR_BEGIN_MACRO \
  278. ucontext_t *uc = CONTEXT(_thread); \
  279. *status = PR_TRUE; \
  280. getcontext(uc); \
  281. /* Force sp to be double aligned! */ \
  282. uc->uc_mcontext.gregs[USP] = (int) ((unsigned long)(_sp - WINDOWSIZE - SA(MINFRAME)) & 0xfffffff8); \
  283. uc->uc_mcontext.gregs[PC] = (int) _main; \
  284. (_thread)->no_sched = 0; \
  285. PR_END_MACRO
  286. /* getcontext() may return 1, contrary to what the man page says */
  287. #define _MD_SWITCH_CONTEXT(_thread) \
  288. PR_BEGIN_MACRO \
  289. ucontext_t *uc = CONTEXT(_thread); \
  290. PR_ASSERT(_thread->no_sched); \
  291. sigfillset(&((_thread)->md.blockMask)); \
  292. sigprocmask(SIG_BLOCK, &((_thread)->md.blockMask), \
  293. &((_thread)->md.oldMask)); \
  294. (_thread)->md.edi = getedi(); \
  295. if (! getcontext(uc)) { \
  296. sigprocmask(SIG_SETMASK, &((_thread)->md.oldMask), NULL); \
  297. uc->uc_mcontext.gregs[EDI] = (_thread)->md.edi; \
  298. _MD_SAVE_ERRNO(_thread) \
  299. _MD_SET_LAST_THREAD(_thread); \
  300. _PR_Schedule(); \
  301. } else { \
  302. sigprocmask(SIG_SETMASK, &((_thread)->md.oldMask), NULL); \
  303. setedi((_thread)->md.edi); \
  304. PR_ASSERT(_MD_LAST_THREAD() !=_MD_CURRENT_THREAD()); \
  305. _MD_LAST_THREAD()->no_sched = 0; \
  306. } \
  307. PR_END_MACRO
  308. /*
  309. ** Restore a thread context, saved by _PR_SWITCH_CONTEXT
  310. */
  311. #define _MD_RESTORE_CONTEXT(_newthread) \
  312. PR_BEGIN_MACRO \
  313. ucontext_t *uc = CONTEXT(_newthread); \
  314. uc->uc_mcontext.gregs[EAX] = 1; \
  315. _MD_RESTORE_ERRNO(_newthread) \
  316. _MD_SET_CURRENT_THREAD(_newthread); \
  317. (_newthread)->no_sched = 1; \
  318. setcontext(uc); \
  319. PR_END_MACRO
  320. #endif /* USE_SETJMP */
  321. #endif /* sparc */
  322. struct _MDLock {
  323. PRInt8 notused;
  324. };
  325. struct _MDCVar {
  326. PRInt8 notused;
  327. };
  328. struct _MDSemaphore {
  329. PRInt8 notused;
  330. };
  331. struct _MDThread {
  332. _PR_CONTEXT_TYPE context;
  333. int errcode;
  334. int id;
  335. };
  336. struct _MDThreadStack {
  337. PRInt8 notused;
  338. };
  339. struct _MDSegment {
  340. PRInt8 notused;
  341. };
  342. /*
  343. * md-specific cpu structure field
  344. */
  345. #define _PR_MD_MAX_OSFD FD_SETSIZE
  346. struct _MDCPU_Unix {
  347. PRCList ioQ;
  348. PRUint32 ioq_timeout;
  349. PRInt32 ioq_max_osfd;
  350. PRInt32 ioq_osfd_cnt;
  351. #ifndef _PR_USE_POLL
  352. fd_set fd_read_set, fd_write_set, fd_exception_set;
  353. PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
  354. fd_exception_cnt[_PR_MD_MAX_OSFD];
  355. #else
  356. struct pollfd *ioq_pollfds;
  357. int ioq_pollfds_size;
  358. #endif /* _PR_USE_POLL */
  359. };
  360. #define _PR_IOQ(_cpu) ((_cpu)->md.md_unix.ioQ)
  361. #define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
  362. #define _PR_FD_READ_SET(_cpu) ((_cpu)->md.md_unix.fd_read_set)
  363. #define _PR_FD_READ_CNT(_cpu) ((_cpu)->md.md_unix.fd_read_cnt)
  364. #define _PR_FD_WRITE_SET(_cpu) ((_cpu)->md.md_unix.fd_write_set)
  365. #define _PR_FD_WRITE_CNT(_cpu) ((_cpu)->md.md_unix.fd_write_cnt)
  366. #define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set)
  367. #define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt)
  368. #define _PR_IOQ_TIMEOUT(_cpu) ((_cpu)->md.md_unix.ioq_timeout)
  369. #define _PR_IOQ_MAX_OSFD(_cpu) ((_cpu)->md.md_unix.ioq_max_osfd)
  370. #define _PR_IOQ_OSFD_CNT(_cpu) ((_cpu)->md.md_unix.ioq_osfd_cnt)
  371. #define _PR_IOQ_POLLFDS(_cpu) ((_cpu)->md.md_unix.ioq_pollfds)
  372. #define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size)
  373. #define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu) 32
  374. struct _MDCPU {
  375. struct _MDCPU_Unix md_unix;
  376. };
  377. #define _MD_INIT_LOCKS()
  378. #define _MD_NEW_LOCK(lock) PR_SUCCESS
  379. #define _MD_FREE_LOCK(lock)
  380. #define _MD_LOCK(lock)
  381. #define _MD_UNLOCK(lock)
  382. #define _MD_INIT_IO()
  383. #define _MD_IOQ_LOCK()
  384. #define _MD_IOQ_UNLOCK()
  385. #define _MD_INIT_RUNNING_CPU(cpu) _MD_unix_init_running_cpu(cpu)
  386. #define _MD_INIT_THREAD _MD_InitializeThread
  387. #define _MD_EXIT_THREAD(thread)
  388. #define _MD_SUSPEND_THREAD(thread)
  389. #define _MD_RESUME_THREAD(thread)
  390. #define _MD_CLEAN_THREAD(_thread)
  391. extern PRStatus _MD_WAIT(struct PRThread *, PRIntervalTime timeout);
  392. extern PRStatus _MD_WAKEUP_WAITER(struct PRThread *);
  393. extern void _MD_YIELD(void);
  394. extern PRStatus _MD_InitializeThread(PRThread *thread);
  395. extern void _MD_SET_PRIORITY(struct _MDThread *thread,
  396. PRThreadPriority newPri);
  397. extern PRStatus _MD_CREATE_THREAD(PRThread *thread, void (*start) (void *),
  398. PRThreadPriority priority, PRThreadScope scope, PRThreadState state,
  399. PRUint32 stackSize);
  400. /* The following defines the unwrapped versions of select() and poll(). */
  401. extern int _select(int nfds, fd_set *readfds, fd_set *writefds,
  402. fd_set *exceptfds, struct timeval *timeout);
  403. #define _MD_SELECT _select
  404. #include <stropts.h>
  405. #include <poll.h>
  406. #define _MD_POLL _poll
  407. extern int _poll(struct pollfd *fds, unsigned long nfds, int timeout);
  408. PR_BEGIN_EXTERN_C
  409. /*
  410. ** Missing function prototypes
  411. */
  412. extern int gethostname (char *name, int namelen);
  413. PR_END_EXTERN_C
  414. #endif /* _PR_PTHREADS */
  415. extern void _MD_solaris_map_sendfile_error(int err);
  416. #endif /* nspr_solaris_defs_h___ */