| OLD | NEW |
| (Empty) |
| 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 | |
| 6 #ifndef nspr_darwin_defs_h___ | |
| 7 #define nspr_darwin_defs_h___ | |
| 8 | |
| 9 #include "prthread.h" | |
| 10 | |
| 11 #include <libkern/OSAtomic.h> | |
| 12 #include <sys/syscall.h> | |
| 13 | |
| 14 #ifdef __APPLE__ | |
| 15 #include <AvailabilityMacros.h> | |
| 16 #include <TargetConditionals.h> | |
| 17 #endif | |
| 18 | |
| 19 #define PR_LINKER_ARCH "darwin" | |
| 20 #define _PR_SI_SYSNAME "DARWIN" | |
| 21 #ifdef __i386__ | |
| 22 #define _PR_SI_ARCHITECTURE "x86" | |
| 23 #elif defined(__x86_64__) | |
| 24 #define _PR_SI_ARCHITECTURE "x86-64" | |
| 25 #elif defined(__ppc__) | |
| 26 #define _PR_SI_ARCHITECTURE "ppc" | |
| 27 #elif defined(__arm__) | |
| 28 #define _PR_SI_ARCHITECTURE "arm" | |
| 29 #else | |
| 30 #error "Unknown CPU architecture" | |
| 31 #endif | |
| 32 #define PR_DLL_SUFFIX ".dylib" | |
| 33 | |
| 34 #define _PR_VMBASE 0x30000000 | |
| 35 #define _PR_STACK_VMBASE 0x50000000 | |
| 36 #define _MD_DEFAULT_STACK_SIZE 65536L | |
| 37 #define _MD_MMAP_FLAGS MAP_PRIVATE | |
| 38 | |
| 39 #undef HAVE_STACK_GROWING_UP | |
| 40 #define HAVE_DLL | |
| 41 #if defined(__x86_64__) || TARGET_OS_IPHONE | |
| 42 #define USE_DLFCN | |
| 43 #else | |
| 44 #define USE_MACH_DYLD | |
| 45 #endif | |
| 46 #define _PR_HAVE_SOCKADDR_LEN | |
| 47 #define _PR_STAT_HAS_ST_ATIMESPEC | |
| 48 #define _PR_HAVE_LARGE_OFF_T | |
| 49 #define _PR_HAVE_SYSV_SEMAPHORES | |
| 50 #define PR_HAVE_SYSV_NAMED_SHARED_MEMORY | |
| 51 | |
| 52 #define _PR_INET6 | |
| 53 /* | |
| 54 * I'd prefer to use getipnodebyname and getipnodebyaddr but the | |
| 55 * getipnodebyname(3) man page on Mac OS X 10.2 says they are not | |
| 56 * thread-safe. AI_V4MAPPED|AI_ADDRCONFIG doesn't work either. | |
| 57 */ | |
| 58 #define _PR_HAVE_GETHOSTBYNAME2 | |
| 59 #define _PR_HAVE_GETADDRINFO | |
| 60 /* | |
| 61 * On Mac OS X 10.2, gethostbyaddr fails with h_errno=NO_RECOVERY | |
| 62 * if you pass an IPv4-mapped IPv6 address to it. | |
| 63 */ | |
| 64 #define _PR_GHBA_DISALLOW_V4MAPPED | |
| 65 #ifdef __APPLE__ | |
| 66 #if !defined(MAC_OS_X_VERSION_10_3) || \ | |
| 67 MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_3 | |
| 68 /* | |
| 69 * socket(AF_INET6) fails with EPROTONOSUPPORT on Mac OS X 10.1. | |
| 70 * IPv6 under OS X 10.2 and below is not complete (see bug 222031). | |
| 71 */ | |
| 72 #define _PR_INET6_PROBE | |
| 73 #endif /* DT < 10.3 */ | |
| 74 #if defined(MAC_OS_X_VERSION_10_2) && \ | |
| 75 MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_2 | |
| 76 /* Mac OS X 10.2 has inet_ntop and inet_pton. */ | |
| 77 #define _PR_HAVE_INET_NTOP | |
| 78 #endif /* DT >= 10.2 */ | |
| 79 #endif /* __APPLE__ */ | |
| 80 #define _PR_IPV6_V6ONLY_PROBE | |
| 81 /* The IPV6_V6ONLY socket option is not defined on Mac OS X 10.1. */ | |
| 82 #ifndef IPV6_V6ONLY | |
| 83 #define IPV6_V6ONLY 27 | |
| 84 #endif | |
| 85 | |
| 86 #ifdef __ppc__ | |
| 87 #define _PR_HAVE_ATOMIC_OPS | |
| 88 #define _MD_INIT_ATOMIC() | |
| 89 extern PRInt32 _PR_DarwinPPC_AtomicIncrement(PRInt32 *val); | |
| 90 #define _MD_ATOMIC_INCREMENT(val) _PR_DarwinPPC_AtomicIncrement(val) | |
| 91 extern PRInt32 _PR_DarwinPPC_AtomicDecrement(PRInt32 *val); | |
| 92 #define _MD_ATOMIC_DECREMENT(val) _PR_DarwinPPC_AtomicDecrement(val) | |
| 93 extern PRInt32 _PR_DarwinPPC_AtomicSet(PRInt32 *val, PRInt32 newval); | |
| 94 #define _MD_ATOMIC_SET(val, newval) _PR_DarwinPPC_AtomicSet(val, newval) | |
| 95 extern PRInt32 _PR_DarwinPPC_AtomicAdd(PRInt32 *ptr, PRInt32 val); | |
| 96 #define _MD_ATOMIC_ADD(ptr, val) _PR_DarwinPPC_AtomicAdd(ptr, val) | |
| 97 #endif /* __ppc__ */ | |
| 98 | |
| 99 #ifdef __i386__ | |
| 100 #define _PR_HAVE_ATOMIC_OPS | |
| 101 #define _MD_INIT_ATOMIC() | |
| 102 extern PRInt32 _PR_Darwin_x86_AtomicIncrement(PRInt32 *val); | |
| 103 #define _MD_ATOMIC_INCREMENT(val) _PR_Darwin_x86_AtomicIncrement(val) | |
| 104 extern PRInt32 _PR_Darwin_x86_AtomicDecrement(PRInt32 *val); | |
| 105 #define _MD_ATOMIC_DECREMENT(val) _PR_Darwin_x86_AtomicDecrement(val) | |
| 106 extern PRInt32 _PR_Darwin_x86_AtomicSet(PRInt32 *val, PRInt32 newval); | |
| 107 #define _MD_ATOMIC_SET(val, newval) _PR_Darwin_x86_AtomicSet(val, newval) | |
| 108 extern PRInt32 _PR_Darwin_x86_AtomicAdd(PRInt32 *ptr, PRInt32 val); | |
| 109 #define _MD_ATOMIC_ADD(ptr, val) _PR_Darwin_x86_AtomicAdd(ptr, val) | |
| 110 #endif /* __i386__ */ | |
| 111 | |
| 112 #ifdef __x86_64__ | |
| 113 #define _PR_HAVE_ATOMIC_OPS | |
| 114 #define _MD_INIT_ATOMIC() | |
| 115 extern PRInt32 _PR_Darwin_x86_64_AtomicIncrement(PRInt32 *val); | |
| 116 #define _MD_ATOMIC_INCREMENT(val) _PR_Darwin_x86_64_AtomicIncrement(val) | |
| 117 extern PRInt32 _PR_Darwin_x86_64_AtomicDecrement(PRInt32 *val); | |
| 118 #define _MD_ATOMIC_DECREMENT(val) _PR_Darwin_x86_64_AtomicDecrement(val) | |
| 119 extern PRInt32 _PR_Darwin_x86_64_AtomicSet(PRInt32 *val, PRInt32 newval); | |
| 120 #define _MD_ATOMIC_SET(val, newval) _PR_Darwin_x86_64_AtomicSet(val, newval) | |
| 121 extern PRInt32 _PR_Darwin_x86_64_AtomicAdd(PRInt32 *ptr, PRInt32 val); | |
| 122 #define _MD_ATOMIC_ADD(ptr, val) _PR_Darwin_x86_64_AtomicAdd(ptr, val) | |
| 123 #endif /* __x86_64__ */ | |
| 124 | |
| 125 #ifdef __arm__ | |
| 126 #define _PR_HAVE_ATOMIC_OPS | |
| 127 #define _MD_INIT_ATOMIC() | |
| 128 #define _MD_ATOMIC_INCREMENT(val) OSAtomicIncrement32(val) | |
| 129 #define _MD_ATOMIC_DECREMENT(val) OSAtomicDecrement32(val) | |
| 130 static inline PRInt32 _MD_ATOMIC_SET(PRInt32 *val, PRInt32 newval) | |
| 131 { | |
| 132 PRInt32 oldval; | |
| 133 do { | |
| 134 oldval = *val; | |
| 135 } while (!OSAtomicCompareAndSwap32(oldval, newval, val)); | |
| 136 return oldval; | |
| 137 } | |
| 138 #define _MD_ATOMIC_ADD(ptr, val) OSAtomicAdd32(val, ptr) | |
| 139 #endif /* __arm__ */ | |
| 140 | |
| 141 #define USE_SETJMP | |
| 142 | |
| 143 #if !defined(_PR_PTHREADS) | |
| 144 | |
| 145 #include <setjmp.h> | |
| 146 | |
| 147 #define PR_CONTEXT_TYPE jmp_buf | |
| 148 | |
| 149 #define CONTEXT(_th) ((_th)->md.context) | |
| 150 #define _MD_GET_SP(_th) (((struct sigcontext *) (_th)->md.context)->sc_onstac
k) | |
| 151 #define PR_NUM_GCREGS _JBLEN | |
| 152 | |
| 153 /* | |
| 154 ** Initialize a thread context to run "_main()" when started | |
| 155 */ | |
| 156 #define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \ | |
| 157 { \ | |
| 158 *status = PR_TRUE; \ | |
| 159 if (setjmp(CONTEXT(_thread))) { \ | |
| 160 _main(); \ | |
| 161 } \ | |
| 162 _MD_GET_SP(_thread) = (unsigned char*) ((_sp) - 64); \ | |
| 163 } | |
| 164 | |
| 165 #define _MD_SWITCH_CONTEXT(_thread) \ | |
| 166 if (!setjmp(CONTEXT(_thread))) { \ | |
| 167 (_thread)->md.errcode = errno; \ | |
| 168 _PR_Schedule(); \ | |
| 169 } | |
| 170 | |
| 171 /* | |
| 172 ** Restore a thread context, saved by _MD_SWITCH_CONTEXT | |
| 173 */ | |
| 174 #define _MD_RESTORE_CONTEXT(_thread) \ | |
| 175 { \ | |
| 176 errno = (_thread)->md.errcode; \ | |
| 177 _MD_SET_CURRENT_THREAD(_thread); \ | |
| 178 longjmp(CONTEXT(_thread), 1); \ | |
| 179 } | |
| 180 | |
| 181 /* Machine-dependent (MD) data structures */ | |
| 182 | |
| 183 struct _MDThread { | |
| 184 PR_CONTEXT_TYPE context; | |
| 185 int id; | |
| 186 int errcode; | |
| 187 }; | |
| 188 | |
| 189 struct _MDThreadStack { | |
| 190 PRInt8 notused; | |
| 191 }; | |
| 192 | |
| 193 struct _MDLock { | |
| 194 PRInt8 notused; | |
| 195 }; | |
| 196 | |
| 197 struct _MDSemaphore { | |
| 198 PRInt8 notused; | |
| 199 }; | |
| 200 | |
| 201 struct _MDCVar { | |
| 202 PRInt8 notused; | |
| 203 }; | |
| 204 | |
| 205 struct _MDSegment { | |
| 206 PRInt8 notused; | |
| 207 }; | |
| 208 | |
| 209 /* | |
| 210 * md-specific cpu structure field | |
| 211 */ | |
| 212 #define _PR_MD_MAX_OSFD FD_SETSIZE | |
| 213 | |
| 214 struct _MDCPU_Unix { | |
| 215 PRCList ioQ; | |
| 216 PRUint32 ioq_timeout; | |
| 217 PRInt32 ioq_max_osfd; | |
| 218 PRInt32 ioq_osfd_cnt; | |
| 219 #ifndef _PR_USE_POLL | |
| 220 fd_set fd_read_set, fd_write_set, fd_exception_set; | |
| 221 PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD], | |
| 222 fd_exception_cnt[_PR_MD_MAX_OSFD]; | |
| 223 #else | |
| 224 struct pollfd *ioq_pollfds; | |
| 225 int ioq_pollfds_size; | |
| 226 #endif /* _PR_USE_POLL */ | |
| 227 }; | |
| 228 | |
| 229 #define _PR_IOQ(_cpu) ((_cpu)->md.md_unix.ioQ) | |
| 230 #define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu)) | |
| 231 #define _PR_FD_READ_SET(_cpu) ((_cpu)->md.md_unix.fd_read_set) | |
| 232 #define _PR_FD_READ_CNT(_cpu) ((_cpu)->md.md_unix.fd_read_cnt) | |
| 233 #define _PR_FD_WRITE_SET(_cpu) ((_cpu)->md.md_unix.fd_write_set) | |
| 234 #define _PR_FD_WRITE_CNT(_cpu) ((_cpu)->md.md_unix.fd_write_cnt) | |
| 235 #define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set) | |
| 236 #define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt) | |
| 237 #define _PR_IOQ_TIMEOUT(_cpu) ((_cpu)->md.md_unix.ioq_timeout) | |
| 238 #define _PR_IOQ_MAX_OSFD(_cpu) ((_cpu)->md.md_unix.ioq_max_osfd) | |
| 239 #define _PR_IOQ_OSFD_CNT(_cpu) ((_cpu)->md.md_unix.ioq_osfd_cnt) | |
| 240 #define _PR_IOQ_POLLFDS(_cpu) ((_cpu)->md.md_unix.ioq_pollfds) | |
| 241 #define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size) | |
| 242 | |
| 243 #define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu) 32 | |
| 244 | |
| 245 struct _MDCPU { | |
| 246 struct _MDCPU_Unix md_unix; | |
| 247 }; | |
| 248 | |
| 249 #define _MD_INIT_LOCKS() | |
| 250 #define _MD_NEW_LOCK(lock) PR_SUCCESS | |
| 251 #define _MD_FREE_LOCK(lock) | |
| 252 #define _MD_LOCK(lock) | |
| 253 #define _MD_UNLOCK(lock) | |
| 254 #define _MD_INIT_IO() | |
| 255 #define _MD_IOQ_LOCK() | |
| 256 #define _MD_IOQ_UNLOCK() | |
| 257 | |
| 258 extern PRStatus _MD_InitializeThread(PRThread *thread); | |
| 259 | |
| 260 #define _MD_INIT_RUNNING_CPU(cpu) _MD_unix_init_running_cpu(cpu) | |
| 261 #define _MD_INIT_THREAD _MD_InitializeThread | |
| 262 #define _MD_EXIT_THREAD(thread) | |
| 263 #define _MD_SUSPEND_THREAD(thread) _MD_suspend_thread | |
| 264 #define _MD_RESUME_THREAD(thread) _MD_resume_thread | |
| 265 #define _MD_CLEAN_THREAD(_thread) | |
| 266 | |
| 267 extern PRStatus _MD_CREATE_THREAD( | |
| 268 PRThread *thread, | |
| 269 void (*start) (void *), | |
| 270 PRThreadPriority priority, | |
| 271 PRThreadScope scope, | |
| 272 PRThreadState state, | |
| 273 PRUint32 stackSize); | |
| 274 extern void _MD_SET_PRIORITY(struct _MDThread *thread, PRUintn newPri); | |
| 275 extern PRStatus _MD_WAIT(PRThread *, PRIntervalTime timeout); | |
| 276 extern PRStatus _MD_WAKEUP_WAITER(PRThread *); | |
| 277 extern void _MD_YIELD(void); | |
| 278 | |
| 279 #endif /* ! _PR_PTHREADS */ | |
| 280 | |
| 281 #define _MD_EARLY_INIT _MD_EarlyInit | |
| 282 #define _MD_FINAL_INIT _PR_UnixInit | |
| 283 #define _MD_INTERVAL_INIT _PR_Mach_IntervalInit | |
| 284 #define _MD_GET_INTERVAL _PR_Mach_GetInterval | |
| 285 #define _MD_INTERVAL_PER_SEC _PR_Mach_TicksPerSecond | |
| 286 | |
| 287 extern void _MD_EarlyInit(void); | |
| 288 extern void _PR_Mach_IntervalInit(void); | |
| 289 extern PRIntervalTime _PR_Mach_GetInterval(void); | |
| 290 extern PRIntervalTime _PR_Mach_TicksPerSecond(void); | |
| 291 | |
| 292 /* | |
| 293 * We wrapped the select() call. _MD_SELECT refers to the built-in, | |
| 294 * unwrapped version. | |
| 295 */ | |
| 296 #define _MD_SELECT(nfds,r,w,e,tv) syscall(SYS_select,nfds,r,w,e,tv) | |
| 297 | |
| 298 /* For writev() */ | |
| 299 #include <sys/uio.h> | |
| 300 | |
| 301 #endif /* nspr_darwin_defs_h___ */ | |
| OLD | NEW |