_darwin.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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. #ifndef nspr_darwin_defs_h___
  38. #define nspr_darwin_defs_h___
  39. #include "prthread.h"
  40. #include <sys/syscall.h>
  41. #ifdef XP_MACOSX
  42. #include <AvailabilityMacros.h>
  43. #endif
  44. #define PR_LINKER_ARCH "darwin"
  45. #define _PR_SI_SYSNAME "DARWIN"
  46. #ifdef i386
  47. #define _PR_SI_ARCHITECTURE "x86"
  48. #else
  49. #define _PR_SI_ARCHITECTURE "ppc"
  50. #endif
  51. #define PR_DLL_SUFFIX ".dylib"
  52. #define _PR_VMBASE 0x30000000
  53. #define _PR_STACK_VMBASE 0x50000000
  54. #define _MD_DEFAULT_STACK_SIZE 65536L
  55. #define _MD_MMAP_FLAGS MAP_PRIVATE
  56. #undef HAVE_STACK_GROWING_UP
  57. #define HAVE_DLL
  58. #define USE_MACH_DYLD
  59. #define _PR_HAVE_SOCKADDR_LEN
  60. #define _PR_STAT_HAS_ST_ATIMESPEC
  61. #define _PR_NO_LARGE_FILES
  62. #define PR_HAVE_SYSV_NAMED_SHARED_MEMORY
  63. #define _PR_INET6
  64. /*
  65. * I'd prefer to use getipnodebyname and getipnodebyaddr but the
  66. * getipnodebyname(3) man page on Mac OS X 10.2 says they are not
  67. * thread-safe. AI_V4MAPPED|AI_ADDRCONFIG doesn't work either.
  68. */
  69. #define _PR_HAVE_GETHOSTBYNAME2
  70. #define _PR_HAVE_GETADDRINFO
  71. /*
  72. * On Mac OS X 10.2, gethostbyaddr fails with h_errno=NO_RECOVERY
  73. * if you pass an IPv4-mapped IPv6 address to it.
  74. */
  75. #define _PR_GHBA_DISALLOW_V4MAPPED
  76. #ifdef XP_MACOSX
  77. #if !defined(MAC_OS_X_VERSION_10_3) || \
  78. MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_3
  79. /*
  80. * socket(AF_INET6) fails with EPROTONOSUPPORT on Mac OS X 10.1.
  81. * IPv6 under OS X 10.2 and below is not complete (see bug 222031).
  82. */
  83. #define _PR_INET6_PROBE
  84. #endif /* DT < 10.3 */
  85. #if defined(MAC_OS_X_VERSION_10_2) && \
  86. MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_2
  87. /* Mac OS X 10.2 has inet_ntop and inet_pton. */
  88. #define _PR_HAVE_INET_NTOP
  89. #endif /* DT >= 10.2 */
  90. #endif /* XP_MACOSX */
  91. #define _PR_IPV6_V6ONLY_PROBE
  92. /* The IPV6_V6ONLY socket option is not defined on Mac OS X 10.1. */
  93. #ifndef IPV6_V6ONLY
  94. #define IPV6_V6ONLY 27
  95. #endif
  96. #if defined(__ppc__)
  97. #define _PR_HAVE_ATOMIC_OPS
  98. #define _MD_INIT_ATOMIC()
  99. extern PRInt32 _PR_DarwinPPC_AtomicIncrement(PRInt32 *val);
  100. #define _MD_ATOMIC_INCREMENT(val) _PR_DarwinPPC_AtomicIncrement(val)
  101. extern PRInt32 _PR_DarwinPPC_AtomicDecrement(PRInt32 *val);
  102. #define _MD_ATOMIC_DECREMENT(val) _PR_DarwinPPC_AtomicDecrement(val)
  103. extern PRInt32 _PR_DarwinPPC_AtomicSet(PRInt32 *val, PRInt32 newval);
  104. #define _MD_ATOMIC_SET(val, newval) _PR_DarwinPPC_AtomicSet(val, newval)
  105. extern PRInt32 _PR_DarwinPPC_AtomicAdd(PRInt32 *ptr, PRInt32 val);
  106. #define _MD_ATOMIC_ADD(ptr, val) _PR_DarwinPPC_AtomicAdd(ptr, val)
  107. #endif /* __ppc__ */
  108. #define USE_SETJMP
  109. #if !defined(_PR_PTHREADS)
  110. #include <setjmp.h>
  111. #define PR_CONTEXT_TYPE jmp_buf
  112. #define CONTEXT(_th) ((_th)->md.context)
  113. #define _MD_GET_SP(_th) (((struct sigcontext *) (_th)->md.context)->sc_onstack)
  114. #define PR_NUM_GCREGS _JBLEN
  115. /*
  116. ** Initialize a thread context to run "_main()" when started
  117. */
  118. #define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
  119. { \
  120. *status = PR_TRUE; \
  121. if (setjmp(CONTEXT(_thread))) { \
  122. _main(); \
  123. } \
  124. _MD_GET_SP(_thread) = (unsigned char*) ((_sp) - 64); \
  125. }
  126. #define _MD_SWITCH_CONTEXT(_thread) \
  127. if (!setjmp(CONTEXT(_thread))) { \
  128. (_thread)->md.errcode = errno; \
  129. _PR_Schedule(); \
  130. }
  131. /*
  132. ** Restore a thread context, saved by _MD_SWITCH_CONTEXT
  133. */
  134. #define _MD_RESTORE_CONTEXT(_thread) \
  135. { \
  136. errno = (_thread)->md.errcode; \
  137. _MD_SET_CURRENT_THREAD(_thread); \
  138. longjmp(CONTEXT(_thread), 1); \
  139. }
  140. /* Machine-dependent (MD) data structures */
  141. struct _MDThread {
  142. PR_CONTEXT_TYPE context;
  143. int id;
  144. int errcode;
  145. };
  146. struct _MDThreadStack {
  147. PRInt8 notused;
  148. };
  149. struct _MDLock {
  150. PRInt8 notused;
  151. };
  152. struct _MDSemaphore {
  153. PRInt8 notused;
  154. };
  155. struct _MDCVar {
  156. PRInt8 notused;
  157. };
  158. struct _MDSegment {
  159. PRInt8 notused;
  160. };
  161. /*
  162. * md-specific cpu structure field
  163. */
  164. #define _PR_MD_MAX_OSFD FD_SETSIZE
  165. struct _MDCPU_Unix {
  166. PRCList ioQ;
  167. PRUint32 ioq_timeout;
  168. PRInt32 ioq_max_osfd;
  169. PRInt32 ioq_osfd_cnt;
  170. #ifndef _PR_USE_POLL
  171. fd_set fd_read_set, fd_write_set, fd_exception_set;
  172. PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
  173. fd_exception_cnt[_PR_MD_MAX_OSFD];
  174. #else
  175. struct pollfd *ioq_pollfds;
  176. int ioq_pollfds_size;
  177. #endif /* _PR_USE_POLL */
  178. };
  179. #define _PR_IOQ(_cpu) ((_cpu)->md.md_unix.ioQ)
  180. #define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
  181. #define _PR_FD_READ_SET(_cpu) ((_cpu)->md.md_unix.fd_read_set)
  182. #define _PR_FD_READ_CNT(_cpu) ((_cpu)->md.md_unix.fd_read_cnt)
  183. #define _PR_FD_WRITE_SET(_cpu) ((_cpu)->md.md_unix.fd_write_set)
  184. #define _PR_FD_WRITE_CNT(_cpu) ((_cpu)->md.md_unix.fd_write_cnt)
  185. #define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set)
  186. #define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt)
  187. #define _PR_IOQ_TIMEOUT(_cpu) ((_cpu)->md.md_unix.ioq_timeout)
  188. #define _PR_IOQ_MAX_OSFD(_cpu) ((_cpu)->md.md_unix.ioq_max_osfd)
  189. #define _PR_IOQ_OSFD_CNT(_cpu) ((_cpu)->md.md_unix.ioq_osfd_cnt)
  190. #define _PR_IOQ_POLLFDS(_cpu) ((_cpu)->md.md_unix.ioq_pollfds)
  191. #define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size)
  192. #define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu) 32
  193. struct _MDCPU {
  194. struct _MDCPU_Unix md_unix;
  195. };
  196. #define _MD_INIT_LOCKS()
  197. #define _MD_NEW_LOCK(lock) PR_SUCCESS
  198. #define _MD_FREE_LOCK(lock)
  199. #define _MD_LOCK(lock)
  200. #define _MD_UNLOCK(lock)
  201. #define _MD_INIT_IO()
  202. #define _MD_IOQ_LOCK()
  203. #define _MD_IOQ_UNLOCK()
  204. extern PRStatus _MD_InitializeThread(PRThread *thread);
  205. #define _MD_INIT_RUNNING_CPU(cpu) _MD_unix_init_running_cpu(cpu)
  206. #define _MD_INIT_THREAD _MD_InitializeThread
  207. #define _MD_EXIT_THREAD(thread)
  208. #define _MD_SUSPEND_THREAD(thread) _MD_suspend_thread
  209. #define _MD_RESUME_THREAD(thread) _MD_resume_thread
  210. #define _MD_CLEAN_THREAD(_thread)
  211. extern PRStatus _MD_CREATE_THREAD(
  212. PRThread *thread,
  213. void (*start) (void *),
  214. PRThreadPriority priority,
  215. PRThreadScope scope,
  216. PRThreadState state,
  217. PRUint32 stackSize);
  218. extern void _MD_SET_PRIORITY(struct _MDThread *thread, PRUintn newPri);
  219. extern PRStatus _MD_WAIT(PRThread *, PRIntervalTime timeout);
  220. extern PRStatus _MD_WAKEUP_WAITER(PRThread *);
  221. extern void _MD_YIELD(void);
  222. #endif /* ! _PR_PTHREADS */
  223. #define _MD_EARLY_INIT _MD_EarlyInit
  224. #define _MD_FINAL_INIT _PR_UnixInit
  225. #define _MD_GET_INTERVAL _PR_UNIX_GetInterval
  226. #define _MD_INTERVAL_PER_SEC _PR_UNIX_TicksPerSecond
  227. extern void _MD_EarlyInit(void);
  228. extern PRIntervalTime _PR_UNIX_GetInterval(void);
  229. extern PRIntervalTime _PR_UNIX_TicksPerSecond(void);
  230. /*
  231. * We wrapped the select() call. _MD_SELECT refers to the built-in,
  232. * unwrapped version.
  233. */
  234. #define _MD_SELECT(nfds,r,w,e,tv) syscall(SYS_select,nfds,r,w,e,tv)
  235. /* For writev() */
  236. #include <sys/uio.h>
  237. #endif /* nspr_darwin_defs_h___ */