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