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