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_win95_defs_h___
7 #define nspr_win95_defs_h___
8 
9 #include "prio.h"
10 
11 #include <windows.h>
12 #include <winsock.h>
13 #include <errno.h>
14 
15 /*
16  * Internal configuration macros
17  */
18 
19 #define PR_LINKER_ARCH      "win32"
20 #define _PR_SI_SYSNAME        "WIN95"
21 #if defined(_M_IX86) || defined(_X86_)
22 #define _PR_SI_ARCHITECTURE   "x86"
23 #elif defined(_M_X64) || defined(_M_AMD64) || defined(_AMD64_)
24 #define _PR_SI_ARCHITECTURE   "x86-64"
25 #elif defined(_M_IA64) || defined(_IA64_)
26 #define _PR_SI_ARCHITECTURE   "ia64"
27 #elif defined(_M_ARM) || defined(_ARM_)
28 #define _PR_SI_ARCHITECTURE   "arm"
29 #elif defined(_M_ARM64)
30 #define _PR_SI_ARCHITECTURE   "aarch64"
31 #else
32 #error unknown processor architecture
33 #endif
34 
35 #define HAVE_DLL
36 #undef  HAVE_THREAD_AFFINITY
37 #define _PR_HAVE_GETADDRINFO
38 #define _PR_INET6_PROBE
39 #ifndef _PR_INET6
40 #define AF_INET6 23
41 /* newer ws2tcpip.h provides these */
42 #ifndef AI_CANONNAME
43 #define AI_CANONNAME 0x2
44 #define AI_NUMERICHOST 0x4
45 #define NI_NUMERICHOST 0x02
46 struct addrinfo {
47     int ai_flags;
48     int ai_family;
49     int ai_socktype;
50     int ai_protocol;
51     size_t ai_addrlen;
52     char *ai_canonname;
53     struct sockaddr *ai_addr;
54     struct addrinfo *ai_next;
55 };
56 #endif
57 #define _PR_HAVE_MD_SOCKADDR_IN6
58 /* isomorphic to struct in6_addr on Windows */
59 struct _md_in6_addr {
60     union {
61         PRUint8  _S6_u8[16];
62         PRUint16 _S6_u16[8];
63     } _S6_un;
64 };
65 /* isomorphic to struct sockaddr_in6 on Windows */
66 struct _md_sockaddr_in6 {
67     PRInt16 sin6_family;
68     PRUint16 sin6_port;
69     PRUint32 sin6_flowinfo;
70     struct _md_in6_addr sin6_addr;
71     PRUint32 sin6_scope_id;
72 };
73 #endif
74 #define _PR_HAVE_THREADSAFE_GETHOST
75 #define _PR_HAVE_ATOMIC_OPS
76 #define PR_HAVE_WIN32_NAMED_SHARED_MEMORY
77 
78 /* --- Common User-Thread/Native-Thread Definitions --------------------- */
79 
80 /* --- Globals --- */
81 extern struct PRLock                      *_pr_schedLock;
82 
83 /* --- Typedefs --- */
84 typedef void (*FiberFunc)(void *);
85 
86 #define PR_NUM_GCREGS           8
87 typedef PRInt32                 PR_CONTEXT_TYPE[PR_NUM_GCREGS];
88 #define GC_VMBASE               0x40000000
89 #define GC_VMLIMIT              0x00FFFFFF
90 
91 #define _MD_MAGIC_THREAD    0x22222222
92 #define _MD_MAGIC_THREADSTACK   0x33333333
93 #define _MD_MAGIC_SEGMENT   0x44444444
94 #define _MD_MAGIC_DIR       0x55555555
95 #define _MD_MAGIC_CV        0x66666666
96 
97 struct _MDCPU {
98     int              unused;
99 };
100 
101 struct _MDThread {
102     HANDLE           blocked_sema;      /* Threads block on this when waiting
103                                          * for IO or CondVar.
104                                          */
105     PRBool           inCVWaitQueue;     /* PR_TRUE if the thread is in the
106                                          * wait queue of some cond var.
107                                          * PR_FALSE otherwise.  */
108     HANDLE           handle;            /* Win32 thread handle */
109     PRUint32         id;
110     void            *sp;                /* only valid when suspended */
111     PRUint32         magic;             /* for debugging */
112     PR_CONTEXT_TYPE  gcContext;         /* Thread context for GC */
113     struct PRThread *prev, *next;       /* used by the cvar wait queue to
114                                          * chain the PRThread structures
115                                          * together */
116     void (*start)(void *);              /* used by _PR_MD_CREATE_THREAD to
117                                          * pass its 'start' argument to
118                                          * pr_root. */
119 };
120 
121 struct _MDThreadStack {
122     PRUint32           magic;          /* for debugging */
123 };
124 
125 struct _MDSegment {
126     PRUint32           magic;          /* for debugging */
127 };
128 
129 #undef PROFILE_LOCKS
130 
131 struct _MDDir {
132     HANDLE           d_hdl;
133     WIN32_FIND_DATAA d_entry;
134     PRBool           firstEntry;     /* Is this the entry returned
135                                       * by FindFirstFile()? */
136     PRUint32         magic;          /* for debugging */
137 };
138 
139 #ifdef MOZ_UNICODE
140 struct _MDDirUTF16 {
141     HANDLE           d_hdl;
142     WIN32_FIND_DATAW d_entry;
143     PRBool           firstEntry;     /* Is this the entry returned
144                                       * by FindFirstFileW()? */
145     PRUint32         magic;          /* for debugging */
146 };
147 #endif /* MOZ_UNICODE */
148 
149 struct _MDCVar {
150     PRUint32 magic;
151     struct PRThread *waitHead, *waitTail;  /* the wait queue: a doubly-
152                                             * linked list of threads
153                                             * waiting on this condition
154                                             * variable */
155     PRIntn nwait;                          /* number of threads in the
156                                             * wait queue */
157 };
158 
159 #define _MD_CV_NOTIFIED_LENGTH 6
160 typedef struct _MDNotified _MDNotified;
161 struct _MDNotified {
162     PRIntn length;                     /* # of used entries in this
163                                         * structure */
164     struct {
165         struct _MDCVar *cv;            /* the condition variable notified */
166         PRIntn times;                  /* and the number of times notified */
167         struct PRThread *notifyHead;   /* list of threads to wake up */
168     } cv[_MD_CV_NOTIFIED_LENGTH];
169     _MDNotified *link;                 /* link to another of these, or NULL */
170 };
171 
172 struct _MDLock {
173     CRITICAL_SECTION mutex;          /* this is recursive on NT */
174 
175     /*
176      * When notifying cvars, there is no point in actually
177      * waking up the threads waiting on the cvars until we've
178      * released the lock.  So, we temporarily record the cvars.
179      * When doing an unlock, we'll then wake up the waiting threads.
180      */
181     struct _MDNotified notified;     /* array of conditions notified */
182 #ifdef PROFILE_LOCKS
183     PRInt32 hitcount;
184     PRInt32 misscount;
185 #endif
186 };
187 
188 struct _MDSemaphore {
189     HANDLE           sem;
190 };
191 
192 struct _MDFileDesc {
193     PROsfd osfd;     /* The osfd can come from one of three spaces:
194                       * - For stdin, stdout, and stderr, we are using
195                       *   the libc file handle (0, 1, 2), which is an int.
196                       * - For files and pipes, we are using Win32 HANDLE,
197                       *   which is a void*.
198                       * - For sockets, we are using Winsock SOCKET, which
199                       *   is a u_int.
200                       */
201 };
202 
203 struct _MDProcess {
204     HANDLE handle;
205     DWORD id;
206 };
207 
208 /* --- Misc stuff --- */
209 #define _MD_GET_SP(thread)            (thread)->md.gcContext[6]
210 
211 /* --- NT security stuff --- */
212 
213 extern void _PR_NT_InitSids(void);
214 extern void _PR_NT_FreeSids(void);
215 extern PRStatus _PR_NT_MakeSecurityDescriptorACL(
216     PRIntn mode,
217     DWORD accessTable[],
218     PSECURITY_DESCRIPTOR *resultSD,
219     PACL *resultACL
220 );
221 extern void _PR_NT_FreeSecurityDescriptorACL(
222     PSECURITY_DESCRIPTOR pSD, PACL pACL);
223 
224 /* --- IO stuff --- */
225 
226 #define _MD_OPEN                      _PR_MD_OPEN
227 #define _MD_OPEN_FILE                 _PR_MD_OPEN_FILE
228 #define _MD_READ                      _PR_MD_READ
229 #define _MD_WRITE                     _PR_MD_WRITE
230 #define _MD_WRITEV                    _PR_MD_WRITEV
231 #define _MD_LSEEK                     _PR_MD_LSEEK
232 #define _MD_LSEEK64                   _PR_MD_LSEEK64
233 extern PRInt32 _MD_CloseFile(PROsfd osfd);
234 #define _MD_CLOSE_FILE                _MD_CloseFile
235 #define _MD_GETFILEINFO               _PR_MD_GETFILEINFO
236 #define _MD_GETFILEINFO64             _PR_MD_GETFILEINFO64
237 #define _MD_GETOPENFILEINFO           _PR_MD_GETOPENFILEINFO
238 #define _MD_GETOPENFILEINFO64         _PR_MD_GETOPENFILEINFO64
239 #define _MD_STAT                      _PR_MD_STAT
240 #define _MD_RENAME                    _PR_MD_RENAME
241 #define _MD_ACCESS                    _PR_MD_ACCESS
242 #define _MD_DELETE                    _PR_MD_DELETE
243 #define _MD_MKDIR                     _PR_MD_MKDIR
244 #define _MD_MAKE_DIR                  _PR_MD_MAKE_DIR
245 #define _MD_RMDIR                     _PR_MD_RMDIR
246 #define _MD_LOCKFILE                  _PR_MD_LOCKFILE
247 #define _MD_TLOCKFILE                 _PR_MD_TLOCKFILE
248 #define _MD_UNLOCKFILE                _PR_MD_UNLOCKFILE
249 
250 /* --- UTF16 IO stuff --- */
251 #ifdef MOZ_UNICODE
252 #define _MD_OPEN_FILE_UTF16           _PR_MD_OPEN_FILE_UTF16
253 #define _MD_OPEN_DIR_UTF16            _PR_MD_OPEN_DIR_UTF16
254 #define _MD_READ_DIR_UTF16            _PR_MD_READ_DIR_UTF16
255 #define _MD_CLOSE_DIR_UTF16           _PR_MD_CLOSE_DIR_UTF16
256 #define _MD_GETFILEINFO64_UTF16       _PR_MD_GETFILEINFO64_UTF16
257 #endif /* MOZ_UNICODE */
258 
259 /* --- Socket IO stuff --- */
260 extern void _PR_MD_InitSockets(void);
261 extern void _PR_MD_CleanupSockets(void);
262 #define _MD_EACCES                WSAEACCES
263 #define _MD_EADDRINUSE            WSAEADDRINUSE
264 #define _MD_EADDRNOTAVAIL         WSAEADDRNOTAVAIL
265 #define _MD_EAFNOSUPPORT          WSAEAFNOSUPPORT
266 #define _MD_EAGAIN                WSAEWOULDBLOCK
267 #define _MD_EALREADY              WSAEALREADY
268 #define _MD_EBADF                 WSAEBADF
269 #define _MD_ECONNREFUSED          WSAECONNREFUSED
270 #define _MD_ECONNRESET            WSAECONNRESET
271 #define _MD_EFAULT                WSAEFAULT
272 #define _MD_EINPROGRESS           WSAEINPROGRESS
273 #define _MD_EINTR                 WSAEINTR
274 #define _MD_EINVAL                EINVAL
275 #define _MD_EISCONN               WSAEISCONN
276 #define _MD_ENETUNREACH           WSAENETUNREACH
277 #define _MD_ENOENT                ENOENT
278 #define _MD_ENOTCONN              WSAENOTCONN
279 #define _MD_ENOTSOCK              WSAENOTSOCK
280 #define _MD_EOPNOTSUPP            WSAEOPNOTSUPP
281 #define _MD_EWOULDBLOCK           WSAEWOULDBLOCK
282 #define _MD_GET_SOCKET_ERROR()    WSAGetLastError()
283 #define _MD_SET_SOCKET_ERROR(_err) WSASetLastError(_err)
284 
285 #define _MD_INIT_FILEDESC(fd)
286 extern void _MD_MakeNonblock(PRFileDesc *f);
287 #define _MD_MAKE_NONBLOCK             _MD_MakeNonblock
288 #define _MD_INIT_FD_INHERITABLE       _PR_MD_INIT_FD_INHERITABLE
289 #define _MD_QUERY_FD_INHERITABLE      _PR_MD_QUERY_FD_INHERITABLE
290 #define _MD_SHUTDOWN                  _PR_MD_SHUTDOWN
291 #define _MD_LISTEN                    _PR_MD_LISTEN
292 extern PRInt32 _MD_CloseSocket(PROsfd osfd);
293 #define _MD_CLOSE_SOCKET              _MD_CloseSocket
294 #define _MD_SENDTO                    _PR_MD_SENDTO
295 #ifdef _WIN64
296 #define _MD_TCPSENDTO                 _PR_MD_TCPSENDTO
297 #endif
298 #define _MD_RECVFROM                  _PR_MD_RECVFROM
299 #define _MD_SOCKETPAIR(s, type, proto, sv) -1
300 #define _MD_GETSOCKNAME               _PR_MD_GETSOCKNAME
301 #define _MD_GETPEERNAME               _PR_MD_GETPEERNAME
302 #define _MD_GETSOCKOPT                _PR_MD_GETSOCKOPT
303 #define _MD_SETSOCKOPT                _PR_MD_SETSOCKOPT
304 #define _MD_SET_FD_INHERITABLE        _PR_MD_SET_FD_INHERITABLE
305 #define _MD_SELECT                    select
306 #define _MD_FSYNC                     _PR_MD_FSYNC
307 #define READ_FD                       1
308 #define WRITE_FD                      2
309 
310 #define _MD_INIT_ATOMIC()
311 #if defined(_M_IX86) || defined(_X86_)
312 #define _MD_ATOMIC_INCREMENT          _PR_MD_ATOMIC_INCREMENT
313 #define _MD_ATOMIC_ADD                _PR_MD_ATOMIC_ADD
314 #define _MD_ATOMIC_DECREMENT          _PR_MD_ATOMIC_DECREMENT
315 #else /* non-x86 processors */
316 #define _MD_ATOMIC_INCREMENT(x)       InterlockedIncrement((PLONG)x)
317 #define _MD_ATOMIC_ADD(ptr,val)    (InterlockedExchangeAdd((PLONG)ptr, (LONG)val) + val)
318 #define _MD_ATOMIC_DECREMENT(x)       InterlockedDecrement((PLONG)x)
319 #endif /* x86 */
320 #define _MD_ATOMIC_SET(x,y)           InterlockedExchange((PLONG)x, (LONG)y)
321 
322 #define _MD_INIT_IO                   _PR_MD_INIT_IO
323 
324 
325 /* win95 doesn't have async IO */
326 #define _MD_SOCKET                    _PR_MD_SOCKET
327 extern PRInt32 _MD_SocketAvailable(PRFileDesc *fd);
328 #define _MD_SOCKETAVAILABLE           _MD_SocketAvailable
329 #define _MD_PIPEAVAILABLE             _PR_MD_PIPEAVAILABLE
330 #define _MD_CONNECT                   _PR_MD_CONNECT
331 extern PROsfd _MD_Accept(PRFileDesc *fd, PRNetAddr *raddr, PRUint32 *rlen,
332                          PRIntervalTime timeout);
333 #define _MD_ACCEPT                    _MD_Accept
334 #define _MD_BIND                      _PR_MD_BIND
335 #define _MD_RECV                      _PR_MD_RECV
336 #define _MD_SEND                      _PR_MD_SEND
337 #define _MD_PR_POLL                   _PR_MD_PR_POLL
338 
339 /* --- Scheduler stuff --- */
340 // #define _MD_PAUSE_CPU                 _PR_MD_PAUSE_CPU
341 #define _MD_PAUSE_CPU
342 
343 /* --- DIR stuff --- */
344 #define PR_DIRECTORY_SEPARATOR        '\\'
345 #define PR_DIRECTORY_SEPARATOR_STR    "\\"
346 #define PR_PATH_SEPARATOR       ';'
347 #define PR_PATH_SEPARATOR_STR       ";"
348 #define _MD_ERRNO()                   GetLastError()
349 #define _MD_OPEN_DIR                  _PR_MD_OPEN_DIR
350 #define _MD_CLOSE_DIR                 _PR_MD_CLOSE_DIR
351 #define _MD_READ_DIR                  _PR_MD_READ_DIR
352 
353 /* --- Segment stuff --- */
354 #define _MD_INIT_SEGS()
355 #define _MD_ALLOC_SEGMENT(seg, size, vaddr)   0
356 #define _MD_FREE_SEGMENT(seg)
357 
358 /* --- Environment Stuff --- */
359 #define _MD_GET_ENV                 _PR_MD_GET_ENV
360 #define _MD_PUT_ENV                 _PR_MD_PUT_ENV
361 
362 /* --- Threading Stuff --- */
363 #define _MD_DEFAULT_STACK_SIZE            0
364 #define _MD_INIT_THREAD             _PR_MD_INIT_THREAD
365 #define _MD_INIT_ATTACHED_THREAD    _PR_MD_INIT_THREAD
366 #define _MD_CREATE_THREAD           _PR_MD_CREATE_THREAD
367 #define _MD_YIELD                   _PR_MD_YIELD
368 #define _MD_SET_PRIORITY            _PR_MD_SET_PRIORITY
369 #define _MD_SET_CURRENT_THREAD_NAME _PR_MD_SET_CURRENT_THREAD_NAME
370 #define _MD_CLEAN_THREAD            _PR_MD_CLEAN_THREAD
371 #define _MD_SETTHREADAFFINITYMASK   _PR_MD_SETTHREADAFFINITYMASK
372 #define _MD_GETTHREADAFFINITYMASK   _PR_MD_GETTHREADAFFINITYMASK
373 #define _MD_EXIT_THREAD             _PR_MD_EXIT_THREAD
374 #define _MD_EXIT                    _PR_MD_EXIT
375 #define _MD_SUSPEND_THREAD          _PR_MD_SUSPEND_THREAD
376 #define _MD_RESUME_THREAD           _PR_MD_RESUME_THREAD
377 #define _MD_SUSPEND_CPU             _PR_MD_SUSPEND_CPU
378 #define _MD_RESUME_CPU              _PR_MD_RESUME_CPU
379 #define _MD_BEGIN_SUSPEND_ALL()
380 #define _MD_BEGIN_RESUME_ALL()
381 #define _MD_END_SUSPEND_ALL()
382 #define _MD_END_RESUME_ALL()
383 
384 /* --- Lock stuff --- */
385 #define _PR_LOCK                      _MD_LOCK
386 #define _PR_UNLOCK                    _MD_UNLOCK
387 
388 #define _MD_NEW_LOCK                  _PR_MD_NEW_LOCK
389 #define _MD_FREE_LOCK(lock)           DeleteCriticalSection(&((lock)->mutex))
390 #define _MD_LOCK(lock)                EnterCriticalSection(&((lock)->mutex))
391 #define _MD_TEST_AND_LOCK(lock)       (EnterCriticalSection(&((lock)->mutex)),0)
392 #define _MD_UNLOCK                    _PR_MD_UNLOCK
393 
394 /* --- lock and cv waiting --- */
395 #define _MD_WAIT                      _PR_MD_WAIT
396 #define _MD_WAKEUP_WAITER             _PR_MD_WAKEUP_WAITER
397 
398 /* --- CVar ------------------- */
399 #define _MD_WAIT_CV                   _PR_MD_WAIT_CV
400 #define _MD_NEW_CV                    _PR_MD_NEW_CV
401 #define _MD_FREE_CV                   _PR_MD_FREE_CV
402 #define _MD_NOTIFY_CV                 _PR_MD_NOTIFY_CV
403 #define _MD_NOTIFYALL_CV              _PR_MD_NOTIFYALL_CV
404 
405 /* XXXMB- the IOQ stuff is certainly not working correctly yet. */
406 // extern  struct _MDLock              _pr_ioq_lock;
407 #define _MD_IOQ_LOCK()
408 #define _MD_IOQ_UNLOCK()
409 
410 
411 /* --- Initialization stuff --- */
412 #define _MD_START_INTERRUPTS()
413 #define _MD_STOP_INTERRUPTS()
414 #define _MD_DISABLE_CLOCK_INTERRUPTS()
415 #define _MD_ENABLE_CLOCK_INTERRUPTS()
416 #define _MD_BLOCK_CLOCK_INTERRUPTS()
417 #define _MD_UNBLOCK_CLOCK_INTERRUPTS()
418 #define _MD_EARLY_INIT                _PR_MD_EARLY_INIT
419 #define _MD_FINAL_INIT()
420 #define _MD_EARLY_CLEANUP()
421 #define _MD_INIT_CPUS()
422 #define _MD_INIT_RUNNING_CPU(cpu)
423 
424 struct PRProcess;
425 struct PRProcessAttr;
426 
427 #define _MD_CREATE_PROCESS _PR_CreateWindowsProcess
428 extern struct PRProcess * _PR_CreateWindowsProcess(
429     const char *path,
430     char *const *argv,
431     char *const *envp,
432     const struct PRProcessAttr *attr
433 );
434 
435 #define _MD_DETACH_PROCESS _PR_DetachWindowsProcess
436 extern PRStatus _PR_DetachWindowsProcess(struct PRProcess *process);
437 
438 /* --- Wait for a child process to terminate --- */
439 #define _MD_WAIT_PROCESS _PR_WaitWindowsProcess
440 extern PRStatus _PR_WaitWindowsProcess(struct PRProcess *process,
441                                        PRInt32 *exitCode);
442 
443 #define _MD_KILL_PROCESS _PR_KillWindowsProcess
444 extern PRStatus _PR_KillWindowsProcess(struct PRProcess *process);
445 
446 #define _MD_CLEANUP_BEFORE_EXIT           _PR_MD_CLEANUP_BEFORE_EXIT
447 #define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
448     PR_BEGIN_MACRO \
449     *status = PR_TRUE; \
450     PR_END_MACRO
451 #define _MD_SWITCH_CONTEXT
452 #define _MD_RESTORE_CONTEXT
453 
454 /* --- Intervals --- */
455 #define _MD_INTERVAL_INIT                 _PR_MD_INTERVAL_INIT
456 #define _MD_GET_INTERVAL                  _PR_MD_GET_INTERVAL
457 #define _MD_INTERVAL_PER_SEC              _PR_MD_INTERVAL_PER_SEC
458 #define _MD_INTERVAL_PER_MILLISEC()       (_PR_MD_INTERVAL_PER_SEC() / 1000)
459 #define _MD_INTERVAL_PER_MICROSEC()       (_PR_MD_INTERVAL_PER_SEC() / 1000000)
460 
461 /* --- Time --- */
462 extern void _PR_FileTimeToPRTime(const FILETIME *filetime, PRTime *prtm);
463 
464 #ifdef WINCE
465 extern void _MD_InitTime(void);
466 extern void _MD_CleanupTime(void);
467 #endif
468 
469 /* --- Native-Thread Specific Definitions ------------------------------- */
470 
471 extern struct PRThread * _MD_CURRENT_THREAD(void);
472 
473 #ifdef _PR_USE_STATIC_TLS
474 extern __declspec(thread) struct PRThread *_pr_currentThread;
475 #define _MD_GET_ATTACHED_THREAD() _pr_currentThread
476 #define _MD_SET_CURRENT_THREAD(_thread) (_pr_currentThread = (_thread))
477 
478 extern __declspec(thread) struct PRThread *_pr_thread_last_run;
479 #define _MD_LAST_THREAD() _pr_thread_last_run
480 #define _MD_SET_LAST_THREAD(_thread) (_pr_thread_last_run = 0)
481 
482 extern __declspec(thread) struct _PRCPU *_pr_currentCPU;
483 #define _MD_CURRENT_CPU() _pr_currentCPU
484 #define _MD_SET_CURRENT_CPU(_cpu) (_pr_currentCPU = 0)
485 #else /* _PR_USE_STATIC_TLS */
486 extern DWORD _pr_currentThreadIndex;
487 #define _MD_GET_ATTACHED_THREAD() ((PRThread *) TlsGetValue(_pr_currentThreadIndex))
488 #define _MD_SET_CURRENT_THREAD(_thread) TlsSetValue(_pr_currentThreadIndex, (_thread))
489 
490 extern DWORD _pr_lastThreadIndex;
491 #define _MD_LAST_THREAD() ((PRThread *) TlsGetValue(_pr_lastThreadIndex))
492 #define _MD_SET_LAST_THREAD(_thread) TlsSetValue(_pr_lastThreadIndex, 0)
493 
494 extern DWORD _pr_currentCPUIndex;
495 #define _MD_CURRENT_CPU() ((struct _PRCPU *) TlsGetValue(_pr_currentCPUIndex))
496 #define _MD_SET_CURRENT_CPU(_cpu) TlsSetValue(_pr_currentCPUIndex, 0)
497 #endif /* _PR_USE_STATIC_TLS */
498 
499 /* --- Scheduler stuff --- */
500 #define LOCK_SCHEDULER()                 0
501 #define UNLOCK_SCHEDULER()               0
502 #define _PR_LockSched()                  0
503 #define _PR_UnlockSched()                0
504 
505 /* --- Initialization stuff --- */
506 #define _MD_INIT_LOCKS                   _PR_MD_INIT_LOCKS
507 
508 /* --- Stack stuff --- */
509 #define _MD_INIT_STACK(stack, redzone)
510 #define _MD_CLEAR_STACK(stack)
511 
512 /* --- Memory-mapped files stuff --- */
513 
514 struct _MDFileMap {
515     HANDLE hFileMap;
516     DWORD dwAccess;
517 };
518 
519 extern PRStatus _MD_CreateFileMap(struct PRFileMap *fmap, PRInt64 size);
520 #define _MD_CREATE_FILE_MAP _MD_CreateFileMap
521 
522 extern PRInt32 _MD_GetMemMapAlignment(void);
523 #define _MD_GET_MEM_MAP_ALIGNMENT _MD_GetMemMapAlignment
524 
525 extern void * _MD_MemMap(struct PRFileMap *fmap, PRInt64 offset,
526                          PRUint32 len);
527 #define _MD_MEM_MAP _MD_MemMap
528 
529 extern PRStatus _MD_MemUnmap(void *addr, PRUint32 size);
530 #define _MD_MEM_UNMAP _MD_MemUnmap
531 
532 extern PRStatus _MD_CloseFileMap(struct PRFileMap *fmap);
533 #define _MD_CLOSE_FILE_MAP _MD_CloseFileMap
534 
535 extern PRStatus _MD_SyncMemMap(
536     PRFileDesc *fd,
537     void *addr,
538     PRUint32 len);
539 #define _MD_SYNC_MEM_MAP _MD_SyncMemMap
540 
541 /* --- Named semaphores stuff --- */
542 #define _PR_HAVE_NAMED_SEMAPHORES
543 #define _MD_OPEN_SEMAPHORE            _PR_MD_OPEN_SEMAPHORE
544 #define _MD_WAIT_SEMAPHORE            _PR_MD_WAIT_SEMAPHORE
545 #define _MD_POST_SEMAPHORE            _PR_MD_POST_SEMAPHORE
546 #define _MD_CLOSE_SEMAPHORE           _PR_MD_CLOSE_SEMAPHORE
547 #define _MD_DELETE_SEMAPHORE(name)    PR_SUCCESS  /* no op */
548 
549 #endif /* nspr_win32_defs_h___ */
550