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_win32_defs_h___
|
---|
39 | #define nspr_win32_defs_h___
|
---|
40 |
|
---|
41 | /* Need to force service-pack 3 extensions to be defined by
|
---|
42 | ** setting _WIN32_WINNT to NT 4.0 for winsock.h, winbase.h, winnt.h.
|
---|
43 | */
|
---|
44 | #ifndef _WIN32_WINNT
|
---|
45 | #define _WIN32_WINNT 0x0400
|
---|
46 | #elif (_WIN32_WINNT < 0x0400)
|
---|
47 | #undef _WIN32_WINNT
|
---|
48 | #define _WIN32_WINNT 0x0400
|
---|
49 | #endif /* _WIN32_WINNT */
|
---|
50 |
|
---|
51 | #include <windows.h>
|
---|
52 | #include <winsock.h>
|
---|
53 | #ifdef __MINGW32__
|
---|
54 | #include <mswsock.h>
|
---|
55 | #endif
|
---|
56 | #include <errno.h>
|
---|
57 |
|
---|
58 | #include "prio.h"
|
---|
59 | #include "prclist.h"
|
---|
60 |
|
---|
61 | /*
|
---|
62 | * Internal configuration macros
|
---|
63 | */
|
---|
64 |
|
---|
65 | #define PR_LINKER_ARCH "win32"
|
---|
66 | #define _PR_SI_SYSNAME "WINNT"
|
---|
67 | #define _PR_SI_ARCHITECTURE "x86" /* XXXMB hardcode for now */
|
---|
68 |
|
---|
69 | #define HAVE_DLL
|
---|
70 | #define HAVE_CUSTOM_USER_THREADS
|
---|
71 | #define HAVE_THREAD_AFFINITY
|
---|
72 | #define _PR_HAVE_GETADDRINFO
|
---|
73 | #define _PR_INET6_PROBE
|
---|
74 | #ifndef _PR_INET6
|
---|
75 | #define AF_INET6 23
|
---|
76 | /* newer ws2tcpip.h provides these */
|
---|
77 | #ifndef AI_CANONNAME
|
---|
78 | #define AI_CANONNAME 0x2
|
---|
79 | struct addrinfo {
|
---|
80 | int ai_flags;
|
---|
81 | int ai_family;
|
---|
82 | int ai_socktype;
|
---|
83 | int ai_protocol;
|
---|
84 | size_t ai_addrlen;
|
---|
85 | char *ai_canonname;
|
---|
86 | struct sockaddr *ai_addr;
|
---|
87 | struct addrinfo *ai_next;
|
---|
88 | };
|
---|
89 | #endif
|
---|
90 | #endif
|
---|
91 | #define _PR_HAVE_THREADSAFE_GETHOST
|
---|
92 | #define _PR_HAVE_ATOMIC_OPS
|
---|
93 | #define _PR_HAVE_ATOMIC_CAS
|
---|
94 | #define PR_HAVE_WIN32_NAMED_SHARED_MEMORY
|
---|
95 | #define _PR_HAVE_PEEK_BUFFER
|
---|
96 | #define _PR_PEEK_BUFFER_MAX (32 * 1024)
|
---|
97 | #define _PR_FD_NEED_EMULATE_MSG_PEEK(fd) \
|
---|
98 | (!(fd)->secret->nonblocking && (fd)->secret->inheritable != _PR_TRI_TRUE)
|
---|
99 |
|
---|
100 | /* --- Common User-Thread/Native-Thread Definitions --------------------- */
|
---|
101 |
|
---|
102 | /* --- Globals --- */
|
---|
103 | extern struct PRLock *_pr_schedLock;
|
---|
104 |
|
---|
105 | /* --- Typedefs --- */
|
---|
106 | typedef void (*FiberFunc)(void *);
|
---|
107 |
|
---|
108 | #define PR_NUM_GCREGS 8
|
---|
109 | typedef PRInt32 PR_CONTEXT_TYPE[PR_NUM_GCREGS];
|
---|
110 | #define GC_VMBASE 0x40000000
|
---|
111 | #define GC_VMLIMIT 0x00FFFFFF
|
---|
112 |
|
---|
113 | #define _MD_MAGIC_THREAD 0x22222222
|
---|
114 | #define _MD_MAGIC_THREADSTACK 0x33333333
|
---|
115 | #define _MD_MAGIC_SEGMENT 0x44444444
|
---|
116 | #define _MD_MAGIC_DIR 0x55555555
|
---|
117 |
|
---|
118 | struct _MDCPU {
|
---|
119 | int unused;
|
---|
120 | };
|
---|
121 |
|
---|
122 | enum _MDIOModel {
|
---|
123 | _MD_BlockingIO = 0x38,
|
---|
124 | _MD_MultiWaitIO = 0x49
|
---|
125 | };
|
---|
126 |
|
---|
127 | typedef struct _MDOverlapped {
|
---|
128 | OVERLAPPED overlapped; /* Used for async I/O */
|
---|
129 |
|
---|
130 | enum _MDIOModel ioModel; /* The I/O model to implement
|
---|
131 | * using overlapped I/O.
|
---|
132 | */
|
---|
133 | union {
|
---|
134 | struct _MDThread *mdThread; /* For blocking I/O, this structure
|
---|
135 | * is embedded in the _MDThread
|
---|
136 | * structure.
|
---|
137 | */
|
---|
138 | struct {
|
---|
139 | PRCList links; /* for group->io_ready list */
|
---|
140 | struct PRRecvWait *desc; /* For multiwait I/O, this structure
|
---|
141 | * is associated with a PRRecvWait
|
---|
142 | * structure.
|
---|
143 | */
|
---|
144 | struct PRWaitGroup *group;
|
---|
145 | struct TimerEvent *timer;
|
---|
146 | DWORD error;
|
---|
147 | } mw;
|
---|
148 | } data;
|
---|
149 | } _MDOverlapped;
|
---|
150 |
|
---|
151 | struct _MDThread {
|
---|
152 | /* The overlapped structure must be first! */
|
---|
153 | struct _MDOverlapped overlapped; /* Used for async IO for this thread */
|
---|
154 | void *acceptex_buf; /* Used for AcceptEx() */
|
---|
155 | TRANSMIT_FILE_BUFFERS *xmit_bufs; /* Used for TransmitFile() */
|
---|
156 | HANDLE blocked_sema; /* Threads block on this when waiting
|
---|
157 | * for IO or CondVar.
|
---|
158 | */
|
---|
159 | PRInt32 blocked_io_status; /* Status of the completed IO */
|
---|
160 | PRInt32 blocked_io_bytes; /* Bytes transferred for completed IO */
|
---|
161 | PRInt32 blocked_io_error; /* Save error if status is FALSE */
|
---|
162 | HANDLE handle;
|
---|
163 | PRUint32 id;
|
---|
164 | void *sp; /* only valid when suspended */
|
---|
165 | PRUint32 magic; /* for debugging */
|
---|
166 | PR_CONTEXT_TYPE gcContext; /* Thread context for GC */
|
---|
167 | struct _PRCPU *thr_bound_cpu; /* thread bound to cpu */
|
---|
168 | PRBool interrupt_disabled;/* thread cannot be interrupted */
|
---|
169 | HANDLE thr_event; /* For native-threads-only support,
|
---|
170 | thread blocks on this event */
|
---|
171 |
|
---|
172 | /* The following are used only if this is a fiber */
|
---|
173 | void *fiber_id; /* flag whether or not this is a fiber*/
|
---|
174 | FiberFunc fiber_fn; /* main fiber routine */
|
---|
175 | void *fiber_arg; /* arg to main fiber routine */
|
---|
176 | PRUint32 fiber_stacksize; /* stacksize for fiber */
|
---|
177 | PRInt32 fiber_last_error; /* last error for the fiber */
|
---|
178 | void (*start)(void *); /* used by _PR_MD_CREATE_THREAD to
|
---|
179 | * pass its 'start' argument to
|
---|
180 | * pr_root. */
|
---|
181 | };
|
---|
182 |
|
---|
183 | struct _MDThreadStack {
|
---|
184 | PRUint32 magic; /* for debugging */
|
---|
185 | };
|
---|
186 |
|
---|
187 | struct _MDSegment {
|
---|
188 | PRUint32 magic; /* for debugging */
|
---|
189 | };
|
---|
190 |
|
---|
191 | #undef PROFILE_LOCKS
|
---|
192 |
|
---|
193 | struct _MDLock {
|
---|
194 | CRITICAL_SECTION mutex; /* this is recursive on NT */
|
---|
195 | #ifdef PROFILE_LOCKS
|
---|
196 | PRInt32 hitcount;
|
---|
197 | PRInt32 misscount;
|
---|
198 | #endif
|
---|
199 | };
|
---|
200 |
|
---|
201 | struct _MDDir {
|
---|
202 | HANDLE d_hdl;
|
---|
203 | WIN32_FIND_DATA d_entry;
|
---|
204 | PRBool firstEntry; /* Is this the entry returned
|
---|
205 | * by FindFirstFile()? */
|
---|
206 | PRUint32 magic; /* for debugging */
|
---|
207 | };
|
---|
208 |
|
---|
209 | struct _MDCVar {
|
---|
210 | PRUint32 unused;
|
---|
211 | };
|
---|
212 |
|
---|
213 | struct _MDSemaphore {
|
---|
214 | HANDLE sem;
|
---|
215 | };
|
---|
216 |
|
---|
217 | struct _MDFileDesc {
|
---|
218 | PRInt32 osfd; /* The osfd can come from one of three spaces:
|
---|
219 | * - For stdin, stdout, and stderr, we are using
|
---|
220 | * the libc file handle (0, 1, 2), which is an int.
|
---|
221 | * - For files and pipes, we are using Win32 HANDLE,
|
---|
222 | * which is a void*.
|
---|
223 | * - For sockets, we are using Winsock SOCKET, which
|
---|
224 | * is a u_int.
|
---|
225 | */
|
---|
226 | PRBool io_model_committed; /* The io model (blocking or nonblocking)
|
---|
227 | * for this osfd has been committed and
|
---|
228 | * cannot be changed. The osfd has been
|
---|
229 | * either associated with the io
|
---|
230 | * completion port or made nonblocking. */
|
---|
231 | PRBool sync_file_io; /* Use synchronous file I/O on the osfd
|
---|
232 | * (a file handle) */
|
---|
233 | PRBool accepted_socket; /* Is this an accepted socket (on the
|
---|
234 | * server side)? */
|
---|
235 | PRNetAddr peer_addr; /* If this is an accepted socket, cache
|
---|
236 | * the peer's address returned by
|
---|
237 | * AcceptEx(). This is to work around
|
---|
238 | * the bug that getpeername() on an
|
---|
239 | * socket accepted by AcceptEx() returns
|
---|
240 | * an all-zero net address. */
|
---|
241 | };
|
---|
242 |
|
---|
243 | struct _MDProcess {
|
---|
244 | HANDLE handle;
|
---|
245 | DWORD id;
|
---|
246 | };
|
---|
247 |
|
---|
248 |
|
---|
249 | /* --- Misc stuff --- */
|
---|
250 | #define _MD_GET_SP(thread) (thread)->md.gcContext[6]
|
---|
251 |
|
---|
252 | /* --- NT security stuff --- */
|
---|
253 |
|
---|
254 | extern void _PR_NT_InitSids(void);
|
---|
255 | extern void _PR_NT_FreeSids(void);
|
---|
256 | extern PRStatus _PR_NT_MakeSecurityDescriptorACL(
|
---|
257 | PRIntn mode,
|
---|
258 | DWORD accessTable[],
|
---|
259 | PSECURITY_DESCRIPTOR *resultSD,
|
---|
260 | PACL *resultACL
|
---|
261 | );
|
---|
262 | extern void _PR_NT_FreeSecurityDescriptorACL(
|
---|
263 | PSECURITY_DESCRIPTOR pSD, PACL pACL);
|
---|
264 |
|
---|
265 | /* --- IO stuff --- */
|
---|
266 |
|
---|
267 | extern PRInt32 _md_Associate(HANDLE);
|
---|
268 | extern PRInt32 _PR_MD_CLOSE(PRInt32 osfd, PRBool socket);
|
---|
269 |
|
---|
270 | #define _MD_OPEN _PR_MD_OPEN
|
---|
271 | #define _MD_OPEN_FILE _PR_MD_OPEN_FILE
|
---|
272 | #define _MD_READ _PR_MD_READ
|
---|
273 | #define _MD_WRITE _PR_MD_WRITE
|
---|
274 | #define _MD_WRITEV _PR_MD_WRITEV
|
---|
275 | #define _MD_LSEEK _PR_MD_LSEEK
|
---|
276 | #define _MD_LSEEK64 _PR_MD_LSEEK64
|
---|
277 | #define _MD_CLOSE_FILE(f) _PR_MD_CLOSE(f, PR_FALSE)
|
---|
278 | #define _MD_GETFILEINFO _PR_MD_GETFILEINFO
|
---|
279 | #define _MD_GETFILEINFO64 _PR_MD_GETFILEINFO64
|
---|
280 | #define _MD_GETOPENFILEINFO _PR_MD_GETOPENFILEINFO
|
---|
281 | #define _MD_GETOPENFILEINFO64 _PR_MD_GETOPENFILEINFO64
|
---|
282 | #define _MD_STAT _PR_MD_STAT
|
---|
283 | #define _MD_RENAME _PR_MD_RENAME
|
---|
284 | #define _MD_ACCESS _PR_MD_ACCESS
|
---|
285 | #define _MD_DELETE _PR_MD_DELETE
|
---|
286 | #define _MD_MKDIR _PR_MD_MKDIR
|
---|
287 | #define _MD_MAKE_DIR _PR_MD_MAKE_DIR
|
---|
288 | #define _MD_RMDIR _PR_MD_RMDIR
|
---|
289 | #define _MD_LOCKFILE _PR_MD_LOCKFILE
|
---|
290 | #define _MD_TLOCKFILE _PR_MD_TLOCKFILE
|
---|
291 | #define _MD_UNLOCKFILE _PR_MD_UNLOCKFILE
|
---|
292 |
|
---|
293 | /* --- Socket IO stuff --- */
|
---|
294 | #define _MD_GET_SOCKET_ERROR() WSAGetLastError()
|
---|
295 | #define _MD_SET_SOCKET_ERROR(_err) WSASetLastError(_err)
|
---|
296 |
|
---|
297 | #define _MD_INIT_FILEDESC(fd)
|
---|
298 | #define _MD_MAKE_NONBLOCK _PR_MD_MAKE_NONBLOCK
|
---|
299 | #define _MD_INIT_FD_INHERITABLE _PR_MD_INIT_FD_INHERITABLE
|
---|
300 | #define _MD_QUERY_FD_INHERITABLE _PR_MD_QUERY_FD_INHERITABLE
|
---|
301 | #define _MD_SHUTDOWN _PR_MD_SHUTDOWN
|
---|
302 | #define _MD_LISTEN _PR_MD_LISTEN
|
---|
303 | #define _MD_CLOSE_SOCKET(s) _PR_MD_CLOSE(s, PR_TRUE)
|
---|
304 | #define _MD_SENDTO _PR_MD_SENDTO
|
---|
305 | #define _MD_RECVFROM _PR_MD_RECVFROM
|
---|
306 | #define _MD_SOCKETPAIR(s, type, proto, sv) -1
|
---|
307 | #define _MD_GETSOCKNAME _PR_MD_GETSOCKNAME
|
---|
308 | #define _MD_GETPEERNAME _PR_MD_GETPEERNAME
|
---|
309 | #define _MD_GETSOCKOPT _PR_MD_GETSOCKOPT
|
---|
310 | #define _MD_SETSOCKOPT _PR_MD_SETSOCKOPT
|
---|
311 | #define _MD_SELECT select
|
---|
312 | extern int _PR_NTFiberSafeSelect(int, fd_set *, fd_set *, fd_set *,
|
---|
313 | const struct timeval *);
|
---|
314 | #define _MD_FSYNC _PR_MD_FSYNC
|
---|
315 | #define _MD_SOCKETAVAILABLE _PR_MD_SOCKETAVAILABLE
|
---|
316 | #define _MD_PIPEAVAILABLE _PR_MD_PIPEAVAILABLE
|
---|
317 | #define _MD_SET_FD_INHERITABLE _PR_MD_SET_FD_INHERITABLE
|
---|
318 |
|
---|
319 | #define _MD_INIT_ATOMIC()
|
---|
320 | #if defined(_M_IX86) || defined(_X86_)
|
---|
321 | #define _MD_ATOMIC_INCREMENT _PR_MD_ATOMIC_INCREMENT
|
---|
322 | #define _MD_ATOMIC_ADD _PR_MD_ATOMIC_ADD
|
---|
323 | #define _MD_ATOMIC_DECREMENT _PR_MD_ATOMIC_DECREMENT
|
---|
324 | #else /* non-x86 processors */
|
---|
325 | #define _MD_ATOMIC_INCREMENT(x) InterlockedIncrement((PLONG)x)
|
---|
326 | #define _MD_ATOMIC_ADD(ptr,val) (InterlockedExchangeAdd((PLONG)ptr, (LONG)val) + val)
|
---|
327 | #define _MD_ATOMIC_DECREMENT(x) InterlockedDecrement((PLONG)x)
|
---|
328 | #endif /* x86 */
|
---|
329 | #define _MD_ATOMIC_SET(x,y) InterlockedExchange((PLONG)x, (LONG)y)
|
---|
330 |
|
---|
331 | #define _MD_INIT_IO _PR_MD_INIT_IO
|
---|
332 | #define _MD_SOCKET _PR_MD_SOCKET
|
---|
333 | #define _MD_CONNECT _PR_MD_CONNECT
|
---|
334 |
|
---|
335 | #define _MD_ACCEPT(s, a, l, to) \
|
---|
336 | _MD_FAST_ACCEPT(s, a, l, to, PR_FALSE, NULL, NULL)
|
---|
337 | #define _MD_FAST_ACCEPT(s, a, l, to, fast, cb, cba) \
|
---|
338 | _PR_MD_FAST_ACCEPT(s, a, l, to, fast, cb, cba)
|
---|
339 | #define _MD_ACCEPT_READ(s, ns, ra, buf, l, t) \
|
---|
340 | _MD_FAST_ACCEPT_READ(s, ns, ra, buf, l, t, PR_FALSE, NULL, NULL)
|
---|
341 | #define _MD_FAST_ACCEPT_READ(s, ns, ra, buf, l, t, fast, cb, cba) \
|
---|
342 | _PR_MD_FAST_ACCEPT_READ(s, ns, ra, buf, l, t, fast, cb, cba)
|
---|
343 | #define _MD_UPDATE_ACCEPT_CONTEXT _PR_MD_UPDATE_ACCEPT_CONTEXT
|
---|
344 |
|
---|
345 | #define _MD_BIND _PR_MD_BIND
|
---|
346 | #define _MD_RECV _PR_MD_RECV
|
---|
347 | #define _MD_SEND _PR_MD_SEND
|
---|
348 | #define _MD_SENDFILE _PR_MD_SENDFILE
|
---|
349 | #define _MD_PR_POLL _PR_MD_PR_POLL
|
---|
350 |
|
---|
351 | /* --- Scheduler stuff --- */
|
---|
352 | #define _MD_PAUSE_CPU _PR_MD_PAUSE_CPU
|
---|
353 |
|
---|
354 | /* --- DIR stuff --- */
|
---|
355 | #define PR_DIRECTORY_SEPARATOR '\\'
|
---|
356 | #define PR_DIRECTORY_SEPARATOR_STR "\\"
|
---|
357 | #define PR_PATH_SEPARATOR ';'
|
---|
358 | #define PR_PATH_SEPARATOR_STR ";"
|
---|
359 | #define _MD_ERRNO() GetLastError()
|
---|
360 | #define _MD_OPEN_DIR _PR_MD_OPEN_DIR
|
---|
361 | #define _MD_CLOSE_DIR _PR_MD_CLOSE_DIR
|
---|
362 | #define _MD_READ_DIR _PR_MD_READ_DIR
|
---|
363 |
|
---|
364 | /* --- Segment stuff --- */
|
---|
365 | #define _MD_INIT_SEGS()
|
---|
366 | #define _MD_ALLOC_SEGMENT(seg, size, vaddr) 0
|
---|
367 | #define _MD_FREE_SEGMENT(seg)
|
---|
368 |
|
---|
369 | /* --- Environment Stuff --- */
|
---|
370 | #define _MD_GET_ENV _PR_MD_GET_ENV
|
---|
371 | #define _MD_PUT_ENV _PR_MD_PUT_ENV
|
---|
372 |
|
---|
373 | /* --- Threading Stuff --- */
|
---|
374 | #define _MD_DEFAULT_STACK_SIZE 0
|
---|
375 | #define _MD_INIT_THREAD _PR_MD_INIT_THREAD
|
---|
376 | #define _MD_INIT_ATTACHED_THREAD _PR_MD_INIT_THREAD
|
---|
377 | #define _MD_CREATE_THREAD _PR_MD_CREATE_THREAD
|
---|
378 | #define _MD_JOIN_THREAD _PR_MD_JOIN_THREAD
|
---|
379 | #define _MD_END_THREAD _PR_MD_END_THREAD
|
---|
380 | #define _MD_YIELD _PR_MD_YIELD
|
---|
381 | #define _MD_SET_PRIORITY _PR_MD_SET_PRIORITY
|
---|
382 | #define _MD_CLEAN_THREAD _PR_MD_CLEAN_THREAD
|
---|
383 | #define _MD_SETTHREADAFFINITYMASK _PR_MD_SETTHREADAFFINITYMASK
|
---|
384 | #define _MD_GETTHREADAFFINITYMASK _PR_MD_GETTHREADAFFINITYMASK
|
---|
385 | #define _MD_EXIT_THREAD _PR_MD_EXIT_THREAD
|
---|
386 | #define _MD_SUSPEND_THREAD _PR_MD_SUSPEND_THREAD
|
---|
387 | #define _MD_RESUME_THREAD _PR_MD_RESUME_THREAD
|
---|
388 | #define _MD_SUSPEND_CPU _PR_MD_SUSPEND_CPU
|
---|
389 | #define _MD_RESUME_CPU _PR_MD_RESUME_CPU
|
---|
390 | #define _MD_BEGIN_SUSPEND_ALL()
|
---|
391 | #define _MD_BEGIN_RESUME_ALL()
|
---|
392 | #define _MD_END_SUSPEND_ALL()
|
---|
393 | #define _MD_END_RESUME_ALL()
|
---|
394 |
|
---|
395 | extern void _PR_Unblock_IO_Wait(PRThread *thr);
|
---|
396 |
|
---|
397 | /* --- Lock stuff --- */
|
---|
398 | #define _MD_NEW_LOCK(lock) (InitializeCriticalSection(&((lock)->mutex)),PR_SUCCESS)
|
---|
399 | #define _MD_FREE_LOCK(lock) DeleteCriticalSection(&((lock)->mutex))
|
---|
400 | #ifndef PROFILE_LOCKS
|
---|
401 | #define _MD_LOCK(lock) EnterCriticalSection(&((lock)->mutex))
|
---|
402 | #define _MD_TEST_AND_LOCK(lock) (TryEnterCriticalSection(&((lock)->mutex))== FALSE)
|
---|
403 | #define _MD_UNLOCK(lock) LeaveCriticalSection(&((lock)->mutex))
|
---|
404 | #else
|
---|
405 | #define _MD_LOCK(lock) \
|
---|
406 | PR_BEGIN_MACRO \
|
---|
407 | BOOL rv = TryEnterCriticalSection(&((lock)->mutex)); \
|
---|
408 | if (rv == TRUE) { \
|
---|
409 | InterlockedIncrement(&((lock)->hitcount)); \
|
---|
410 | } else { \
|
---|
411 | InterlockedIncrement(&((lock)->misscount)); \
|
---|
412 | EnterCriticalSection(&((lock)->mutex)); \
|
---|
413 | } \
|
---|
414 | PR_END_MACRO
|
---|
415 | #define _MD_TEST_AND_LOCK(lock) 0 /* XXXMB */
|
---|
416 | #define _MD_UNLOCK(lock) LeaveCriticalSection(&((lock)->mutex))
|
---|
417 | #endif
|
---|
418 | #define _PR_LOCK _MD_LOCK
|
---|
419 | #define _PR_UNLOCK _MD_UNLOCK
|
---|
420 |
|
---|
421 | /* --- lock and cv waiting --- */
|
---|
422 | #define _MD_WAIT _PR_MD_WAIT
|
---|
423 | #define _MD_WAKEUP_WAITER _PR_MD_WAKEUP_WAITER
|
---|
424 |
|
---|
425 | /* XXXMB- the IOQ stuff is certainly not working correctly yet. */
|
---|
426 | extern struct _MDLock _pr_ioq_lock;
|
---|
427 | #define _MD_IOQ_LOCK() _MD_LOCK(&_pr_ioq_lock)
|
---|
428 | #define _MD_IOQ_UNLOCK() _MD_UNLOCK(&_pr_ioq_lock)
|
---|
429 |
|
---|
430 |
|
---|
431 | /* --- Initialization stuff --- */
|
---|
432 | #define _MD_START_INTERRUPTS()
|
---|
433 | #define _MD_STOP_INTERRUPTS()
|
---|
434 | #define _MD_DISABLE_CLOCK_INTERRUPTS()
|
---|
435 | #define _MD_ENABLE_CLOCK_INTERRUPTS()
|
---|
436 | #define _MD_BLOCK_CLOCK_INTERRUPTS()
|
---|
437 | #define _MD_UNBLOCK_CLOCK_INTERRUPTS()
|
---|
438 | #define _MD_EARLY_INIT _PR_MD_EARLY_INIT
|
---|
439 | #define _MD_FINAL_INIT()
|
---|
440 | #define _MD_INIT_CPUS()
|
---|
441 | #define _MD_INIT_RUNNING_CPU(cpu)
|
---|
442 |
|
---|
443 | struct PRProcess;
|
---|
444 | struct PRProcessAttr;
|
---|
445 |
|
---|
446 | /* --- Create a new process --- */
|
---|
447 | #define _MD_CREATE_PROCESS _PR_CreateWindowsProcess
|
---|
448 | extern struct PRProcess * _PR_CreateWindowsProcess(
|
---|
449 | const char *path,
|
---|
450 | char *const *argv,
|
---|
451 | char *const *envp,
|
---|
452 | const struct PRProcessAttr *attr
|
---|
453 | );
|
---|
454 |
|
---|
455 | #define _MD_DETACH_PROCESS _PR_DetachWindowsProcess
|
---|
456 | extern PRStatus _PR_DetachWindowsProcess(struct PRProcess *process);
|
---|
457 |
|
---|
458 | /* --- Wait for a child process to terminate --- */
|
---|
459 | #define _MD_WAIT_PROCESS _PR_WaitWindowsProcess
|
---|
460 | extern PRStatus _PR_WaitWindowsProcess(struct PRProcess *process,
|
---|
461 | PRInt32 *exitCode);
|
---|
462 |
|
---|
463 | #define _MD_KILL_PROCESS _PR_KillWindowsProcess
|
---|
464 | extern PRStatus _PR_KillWindowsProcess(struct PRProcess *process);
|
---|
465 |
|
---|
466 | /* --- User Threading stuff --- */
|
---|
467 | #define HAVE_FIBERS
|
---|
468 | #define _MD_CREATE_USER_THREAD _PR_MD_CREATE_USER_THREAD
|
---|
469 | #define _MD_CREATE_PRIMORDIAL_USER_THREAD _PR_MD_CREATE_PRIMORDIAL_USER_THREAD
|
---|
470 | #define _MD_CLEANUP_BEFORE_EXIT _PR_MD_CLEANUP_BEFORE_EXIT
|
---|
471 | #define _MD_EXIT _PR_MD_EXIT
|
---|
472 | #define _MD_INIT_CONTEXT _PR_MD_INIT_CONTEXT
|
---|
473 | #define _MD_SWITCH_CONTEXT _PR_MD_SWITCH_CONTEXT
|
---|
474 | #define _MD_RESTORE_CONTEXT _PR_MD_RESTORE_CONTEXT
|
---|
475 |
|
---|
476 | /* --- Intervals --- */
|
---|
477 | #define _MD_INTERVAL_INIT _PR_MD_INTERVAL_INIT
|
---|
478 | #define _MD_GET_INTERVAL _PR_MD_GET_INTERVAL
|
---|
479 | #define _MD_INTERVAL_PER_SEC _PR_MD_INTERVAL_PER_SEC
|
---|
480 | #define _MD_INTERVAL_PER_MILLISEC() (_PR_MD_INTERVAL_PER_SEC() / 1000)
|
---|
481 | #define _MD_INTERVAL_PER_MICROSEC() (_PR_MD_INTERVAL_PER_SEC() / 1000000)
|
---|
482 |
|
---|
483 | /* --- Time --- */
|
---|
484 | extern void _PR_FileTimeToPRTime(const FILETIME *filetime, PRTime *prtm);
|
---|
485 |
|
---|
486 | /* --- Native-Thread Specific Definitions ------------------------------- */
|
---|
487 |
|
---|
488 | extern BOOL _pr_use_static_tls;
|
---|
489 |
|
---|
490 | extern __declspec(thread) struct PRThread *_pr_current_fiber;
|
---|
491 | extern DWORD _pr_currentFiberIndex;
|
---|
492 |
|
---|
493 | #define _MD_GET_ATTACHED_THREAD() \
|
---|
494 | (_pr_use_static_tls ? _pr_current_fiber \
|
---|
495 | : (PRThread *) TlsGetValue(_pr_currentFiberIndex))
|
---|
496 |
|
---|
497 | extern struct PRThread * _MD_CURRENT_THREAD(void);
|
---|
498 |
|
---|
499 | #define _MD_SET_CURRENT_THREAD(_thread) \
|
---|
500 | PR_BEGIN_MACRO \
|
---|
501 | if (_pr_use_static_tls) { \
|
---|
502 | _pr_current_fiber = (_thread); \
|
---|
503 | } else { \
|
---|
504 | TlsSetValue(_pr_currentFiberIndex, (_thread)); \
|
---|
505 | } \
|
---|
506 | PR_END_MACRO
|
---|
507 |
|
---|
508 | extern __declspec(thread) struct PRThread *_pr_fiber_last_run;
|
---|
509 | extern DWORD _pr_lastFiberIndex;
|
---|
510 |
|
---|
511 | #define _MD_LAST_THREAD() \
|
---|
512 | (_pr_use_static_tls ? _pr_fiber_last_run \
|
---|
513 | : (PRThread *) TlsGetValue(_pr_lastFiberIndex))
|
---|
514 |
|
---|
515 | #define _MD_SET_LAST_THREAD(_thread) \
|
---|
516 | PR_BEGIN_MACRO \
|
---|
517 | if (_pr_use_static_tls) { \
|
---|
518 | _pr_fiber_last_run = (_thread); \
|
---|
519 | } else { \
|
---|
520 | TlsSetValue(_pr_lastFiberIndex, (_thread)); \
|
---|
521 | } \
|
---|
522 | PR_END_MACRO
|
---|
523 |
|
---|
524 | extern __declspec(thread) struct _PRCPU *_pr_current_cpu;
|
---|
525 | extern DWORD _pr_currentCPUIndex;
|
---|
526 |
|
---|
527 | #define _MD_CURRENT_CPU() \
|
---|
528 | (_pr_use_static_tls ? _pr_current_cpu \
|
---|
529 | : (struct _PRCPU *) TlsGetValue(_pr_currentCPUIndex))
|
---|
530 |
|
---|
531 | #define _MD_SET_CURRENT_CPU(_cpu) \
|
---|
532 | PR_BEGIN_MACRO \
|
---|
533 | if (_pr_use_static_tls) { \
|
---|
534 | _pr_current_cpu = (_cpu); \
|
---|
535 | } else { \
|
---|
536 | TlsSetValue(_pr_currentCPUIndex, (_cpu)); \
|
---|
537 | } \
|
---|
538 | PR_END_MACRO
|
---|
539 |
|
---|
540 | extern __declspec(thread) PRUintn _pr_ints_off;
|
---|
541 | extern DWORD _pr_intsOffIndex;
|
---|
542 |
|
---|
543 | #define _MD_GET_INTSOFF() \
|
---|
544 | (_pr_use_static_tls ? _pr_ints_off \
|
---|
545 | : (PRUintn) TlsGetValue(_pr_intsOffIndex))
|
---|
546 |
|
---|
547 | #define _MD_SET_INTSOFF(_val) \
|
---|
548 | PR_BEGIN_MACRO \
|
---|
549 | if (_pr_use_static_tls) { \
|
---|
550 | _pr_ints_off = (_val); \
|
---|
551 | } else { \
|
---|
552 | TlsSetValue(_pr_intsOffIndex, (LPVOID) (_val)); \
|
---|
553 | } \
|
---|
554 | PR_END_MACRO
|
---|
555 |
|
---|
556 | /* --- Initialization stuff --- */
|
---|
557 | #define _MD_INIT_LOCKS()
|
---|
558 |
|
---|
559 | /* --- Stack stuff --- */
|
---|
560 | #define _MD_INIT_STACK(stack, redzone)
|
---|
561 | #define _MD_CLEAR_STACK(stack)
|
---|
562 |
|
---|
563 | /* --- Memory-mapped files stuff --- */
|
---|
564 |
|
---|
565 | struct _MDFileMap {
|
---|
566 | HANDLE hFileMap;
|
---|
567 | DWORD dwAccess;
|
---|
568 | };
|
---|
569 |
|
---|
570 | extern PRStatus _MD_CreateFileMap(struct PRFileMap *fmap, PRInt64 size);
|
---|
571 | #define _MD_CREATE_FILE_MAP _MD_CreateFileMap
|
---|
572 |
|
---|
573 | extern PRInt32 _MD_GetMemMapAlignment(void);
|
---|
574 | #define _MD_GET_MEM_MAP_ALIGNMENT _MD_GetMemMapAlignment
|
---|
575 |
|
---|
576 | extern void * _MD_MemMap(struct PRFileMap *fmap, PRInt64 offset,
|
---|
577 | PRUint32 len);
|
---|
578 | #define _MD_MEM_MAP _MD_MemMap
|
---|
579 |
|
---|
580 | extern PRStatus _MD_MemUnmap(void *addr, PRUint32 size);
|
---|
581 | #define _MD_MEM_UNMAP _MD_MemUnmap
|
---|
582 |
|
---|
583 | extern PRStatus _MD_CloseFileMap(struct PRFileMap *fmap);
|
---|
584 | #define _MD_CLOSE_FILE_MAP _MD_CloseFileMap
|
---|
585 |
|
---|
586 | /* --- Named semaphores stuff --- */
|
---|
587 | #define _PR_HAVE_NAMED_SEMAPHORES
|
---|
588 | #define _MD_OPEN_SEMAPHORE _PR_MD_OPEN_SEMAPHORE
|
---|
589 | #define _MD_WAIT_SEMAPHORE _PR_MD_WAIT_SEMAPHORE
|
---|
590 | #define _MD_POST_SEMAPHORE _PR_MD_POST_SEMAPHORE
|
---|
591 | #define _MD_CLOSE_SEMAPHORE _PR_MD_CLOSE_SEMAPHORE
|
---|
592 | #define _MD_DELETE_SEMAPHORE(name) PR_SUCCESS /* no op */
|
---|
593 |
|
---|
594 | #endif /* nspr_win32_defs_h___ */
|
---|