home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / nspr30-e.zip / nspr30-e / include / md / _winnt.h < prev    next >
C/C++ Source or Header  |  1998-11-02  |  19KB  |  505 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /*
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  * 
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  * 
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #ifndef nspr_win32_defs_h___
  20. #define nspr_win32_defs_h___
  21.  
  22. /* Need to force service-pack 3 extensions to be defined by
  23. ** setting _WIN32_WINNT to NT 4.0 for winsock.h, winbase.h, winnt.h.
  24. */ 
  25. #ifndef  _WIN32_WINNT
  26.     #define _WIN32_WINNT 0x0400
  27. #elif   (_WIN32_WINNT < 0x0400)
  28.     #undef  _WIN32_WINNT
  29.     #define _WIN32_WINNT 0x0400
  30. #endif /* _WIN32_WINNT */
  31.  
  32. #include <windows.h>
  33. #include <winsock.h>
  34. #include <errno.h>
  35.  
  36. #include "prio.h"
  37. #include "prclist.h"
  38.  
  39. /*
  40.  * Internal configuration macros
  41.  */
  42.  
  43. #define PR_LINKER_ARCH      "win32"
  44. #define _PR_SI_SYSNAME        "WINNT"
  45. #define _PR_SI_ARCHITECTURE   "x86"    /* XXXMB hardcode for now */
  46.  
  47. #define HAVE_DLL
  48. #define HAVE_CUSTOM_USER_THREADS
  49. #define HAVE_THREAD_AFFINITY
  50. #define HAVE_SOCKET_REUSEADDR
  51. #define HAVE_SOCKET_KEEPALIVE
  52. #define _PR_HAVE_ATOMIC_OPS
  53. #define _PR_HAVE_ATOMIC_CAS
  54.  
  55. /* --- Common User-Thread/Native-Thread Definitions --------------------- */
  56.  
  57. /* --- Globals --- */
  58. extern struct PRLock                      *_pr_schedLock;
  59.  
  60. /* --- Typedefs --- */
  61. typedef void (*FiberFunc)(void *);
  62.  
  63. #define PR_NUM_GCREGS           8
  64. typedef PRInt32                    PR_CONTEXT_TYPE[PR_NUM_GCREGS];
  65. #define GC_VMBASE               0x40000000
  66. #define GC_VMLIMIT              0x00FFFFFF
  67.  
  68. #define _MD_MAGIC_THREAD    0x22222222
  69. #define _MD_MAGIC_THREADSTACK    0x33333333
  70. #define _MD_MAGIC_SEGMENT    0x44444444
  71. #define _MD_MAGIC_DIR        0x55555555
  72.  
  73. struct _MDCPU {
  74.     int              unused;
  75. };
  76.  
  77. enum _MDIOModel {
  78.     _MD_BlockingIO = 0x38,
  79.     _MD_MultiWaitIO = 0x49
  80. };
  81.  
  82. typedef struct _MDOverlapped {
  83.     OVERLAPPED overlapped;              /* Used for async I/O */
  84.  
  85.     enum _MDIOModel ioModel;            /* The I/O model to implement
  86.                                          * using overlapped I/O.
  87.                                          */
  88.  
  89.     union {
  90.         struct _MDThread *mdThread;     /* For blocking I/O, this structure
  91.                                          * is embedded in the _MDThread
  92.                                          * structure.
  93.                                          */
  94.         struct {
  95.             PRCList links;              /* for group->io_ready list */
  96.             struct PRRecvWait *desc;    /* For multiwait I/O, this structure
  97.                                          * is associated with a PRRecvWait
  98.                                          * structure.
  99.                                          */
  100.             struct PRWaitGroup *group;
  101.             struct TimerEvent *timer;
  102.             DWORD error;
  103.         } mw;
  104.     } data;
  105. } _MDOverlapped;
  106.  
  107. struct _MDThread {
  108.         /* The overlapped structure must be first! */
  109.     struct _MDOverlapped overlapped;    /* Used for async IO for this thread */
  110.     void            *acceptex_buf;      /* Used for AcceptEx() */
  111.     TRANSMIT_FILE_BUFFERS *xmit_bufs;   /* Used for TransmitFile() */
  112.     HANDLE           blocked_sema;      /* Threads block on this when waiting
  113.                                          * for IO or CondVar.
  114.                                          */
  115.     PRInt32          blocked_io_status; /* Status of the completed IO */
  116.     PRInt32          blocked_io_bytes;  /* Bytes transferred for completed IO */
  117.     PRInt32          blocked_io_error;  /* Save error if status is FALSE */
  118.     HANDLE           handle;
  119.     PRUint32         id;
  120.     void            *sp;                /* only valid when suspended */
  121.     PRUint32         magic;             /* for debugging */
  122.     PR_CONTEXT_TYPE  gcContext;         /* Thread context for GC */
  123.  
  124.     /* The following are used only if this is a fiber */
  125.     void            *fiber_id;          /* flag whether or not this is a fiber*/
  126.     FiberFunc        fiber_fn;          /* main fiber routine */
  127.     void            *fiber_arg;         /* arg to main fiber routine */
  128.     PRUint32         fiber_stacksize;   /* stacksize for fiber */
  129.     PRInt32          fiber_last_error;  /* last error for the fiber */
  130. };
  131.  
  132. struct _MDThreadStack {
  133.     PRUint32           magic;          /* for debugging */
  134. };
  135.  
  136. struct _MDSegment {
  137.     PRUint32           magic;          /* for debugging */
  138. };
  139.  
  140. #undef PROFILE_LOCKS
  141.  
  142. struct _MDLock {
  143.     CRITICAL_SECTION mutex;          /* this is recursive on NT */
  144. #ifdef PROFILE_LOCKS
  145.     PRInt32 hitcount;
  146.     PRInt32 misscount;
  147. #endif
  148. };
  149.  
  150. struct _MDDir {
  151.     HANDLE           d_hdl;
  152.     WIN32_FIND_DATA  d_entry;
  153.     PRBool           firstEntry;     /* Is this the entry returned
  154.                                       * by FindFirstFile()? */
  155.     PRUint32         magic;          /* for debugging */
  156. };
  157.  
  158. struct _MDCVar {
  159.     PRUint32         unused;
  160. };
  161.  
  162. struct _MDSemaphore {
  163.     HANDLE           sem;
  164. };
  165.  
  166. struct _MDFileDesc {
  167.     PRInt32 osfd;    /* The osfd can come from one of three spaces:
  168.                       * - For stdin, stdout, and stderr, we are using
  169.                       *   the libc file handle (0, 1, 2), which is an int.
  170.                       * - For files and pipes, we are using Win32 HANDLE,
  171.                       *   which is a void*.
  172.                       * - For sockets, we are using Winsock SOCKET, which
  173.                       *   is a u_int.
  174.                       */
  175.     PRBool io_model_committed;  /* The io model (blocking or nonblocking)
  176.                                  * for this osfd has been committed and
  177.                                  * cannot be changed.  The osfd has been
  178.                                  * either associated with the io
  179.                                  * completion port or made nonblocking.
  180.                                  * This is only used for sockets, not
  181.                                  * for files. */
  182.     PRBool nonoverlapped;
  183.     PRBool accepted_socket;     /* Is this an accepted socket (on the
  184.                                  * server side)? */
  185.     PRNetAddr peer_addr;        /* If this is an accepted socket, cache
  186.                                  * the peer's address returned by
  187.                                  * AcceptEx().  This is to work around
  188.                                  * the bug that getpeername() on an
  189.                                  * socket accepted by AcceptEx() returns
  190.                                  * an all-zero net address. */
  191. };
  192.  
  193. struct _MDProcess {
  194.     HANDLE handle;
  195.     DWORD id;
  196. };
  197.  
  198. /* --- Misc stuff --- */
  199. #define _MD_GET_SP(thread)            (thread)->md.gcContext[6]
  200.  
  201. /* --- IO stuff --- */
  202.  
  203. extern PRInt32 _md_Associate(HANDLE);
  204. extern PRInt32 _PR_MD_CLOSE(PRInt32 osfd, PRBool socket);
  205.  
  206. #define _MD_OPEN                      _PR_MD_OPEN
  207. #define _MD_READ                      _PR_MD_READ
  208. #define _MD_WRITE                     _PR_MD_WRITE
  209. #define _MD_WRITEV                    _PR_MD_WRITEV
  210. #define _MD_LSEEK                     _PR_MD_LSEEK
  211. #define _MD_LSEEK64                   _PR_MD_LSEEK64
  212. #define _MD_CLOSE_FILE(f)             _PR_MD_CLOSE(f, PR_FALSE)
  213. #define _MD_GETFILEINFO               _PR_MD_GETFILEINFO
  214. #define _MD_GETFILEINFO64             _PR_MD_GETFILEINFO64
  215. #define _MD_GETOPENFILEINFO           _PR_MD_GETOPENFILEINFO
  216. #define _MD_GETOPENFILEINFO64         _PR_MD_GETOPENFILEINFO64
  217. #define _MD_STAT                      _PR_MD_STAT
  218. #define _MD_RENAME                    _PR_MD_RENAME     
  219. #define _MD_ACCESS                    _PR_MD_ACCESS     
  220. #define _MD_DELETE                    _PR_MD_DELETE     
  221. #define _MD_MKDIR                     _PR_MD_MKDIR      
  222. #define _MD_RMDIR                     _PR_MD_RMDIR      
  223. #define _MD_LOCKFILE                  _PR_MD_LOCKFILE
  224. #define _MD_TLOCKFILE                 _PR_MD_TLOCKFILE
  225. #define _MD_UNLOCKFILE                _PR_MD_UNLOCKFILE
  226.  
  227. /* --- Socket IO stuff --- */
  228. #define _MD_GET_SOCKET_ERROR()    WSAGetLastError()
  229. #define _MD_SET_SOCKET_ERROR(_err) WSASetLastError(_err)
  230.  
  231. #define _MD_MAKE_NONBLOCK             _PR_MD_MAKE_NONBLOCK
  232. #define _MD_SHUTDOWN                  _PR_MD_SHUTDOWN
  233. #define _MD_LISTEN                    _PR_MD_LISTEN
  234. #define _MD_CLOSE_SOCKET(s)           _PR_MD_CLOSE(s, PR_TRUE)
  235. #define _MD_SENDTO                    _PR_MD_SENDTO
  236. #define _MD_RECVFROM                  _PR_MD_RECVFROM
  237. #define _MD_SOCKETPAIR(s, type, proto, sv) -1
  238. #define _MD_GETSOCKNAME               _PR_MD_GETSOCKNAME
  239. #define _MD_GETPEERNAME               _PR_MD_GETPEERNAME
  240. #define _MD_GETSOCKOPT                _PR_MD_GETSOCKOPT
  241. #define _MD_SETSOCKOPT                _PR_MD_SETSOCKOPT
  242. #define _MD_SELECT                    select
  243. #define _MD_FSYNC                     _PR_MD_FSYNC
  244. #define _MD_SOCKETAVAILABLE           _PR_MD_SOCKETAVAILABLE
  245.  
  246. #define _MD_INIT_ATOMIC()
  247. #if defined(_M_IX86) || defined(_X86_)
  248. #define _MD_ATOMIC_INCREMENT          _PR_MD_ATOMIC_INCREMENT
  249. #define _MD_ATOMIC_ADD                _PR_MD_ATOMIC_ADD
  250. #define _MD_ATOMIC_DECREMENT          _PR_MD_ATOMIC_DECREMENT
  251. #else /* non-x86 processors */
  252. #define _MD_ATOMIC_INCREMENT(x)       InterlockedIncrement((PLONG)x)
  253. #define _MD_ATOMIC_ADD(ptr,val)    (InterlockedExchangeAdd((PLONG)ptr, (LONG)val) + val)
  254. #define _MD_ATOMIC_DECREMENT(x)       InterlockedDecrement((PLONG)x)
  255. #endif /* x86 */
  256. #define _MD_ATOMIC_SET(x,y)           InterlockedExchange((PLONG)x, (LONG)y)
  257.  
  258. #define _MD_INIT_IO                   _PR_MD_INIT_IO
  259. #define _MD_SOCKET                    _PR_MD_SOCKET
  260. #define _MD_CONNECT                   _PR_MD_CONNECT
  261.  
  262. #define _MD_ACCEPT(s, a, l, to)       \
  263.         _MD_FAST_ACCEPT(s, a, l, to, PR_FALSE, NULL, NULL)
  264. #define _MD_FAST_ACCEPT(s, a, l, to, fast, cb, cba) \
  265.         _PR_MD_FAST_ACCEPT(s, a, l, to, fast, cb, cba)
  266. #define _MD_ACCEPT_READ(s, ns, ra, buf, l, t) \
  267.         _MD_FAST_ACCEPT_READ(s, ns, ra, buf, l, t, PR_FALSE, NULL, NULL)
  268. #define _MD_FAST_ACCEPT_READ(s, ns, ra, buf, l, t, fast, cb, cba) \
  269.         _PR_MD_FAST_ACCEPT_READ(s, ns, ra, buf, l, t, fast, cb, cba)
  270. #define _MD_UPDATE_ACCEPT_CONTEXT     _PR_MD_UPDATE_ACCEPT_CONTEXT
  271.  
  272. #define _MD_BIND                      _PR_MD_BIND
  273. #define _MD_RECV                      _PR_MD_RECV
  274. #define _MD_SEND                      _PR_MD_SEND
  275. #define _MD_TRANSMITFILE              _PR_MD_TRANSMITFILE
  276. #define _MD_PR_POLL                   _PR_MD_PR_POLL
  277.  
  278. /* --- Scheduler stuff --- */
  279. #define _MD_PAUSE_CPU                   _PR_MD_PAUSE_CPU
  280.  
  281. /* --- DIR stuff --- */
  282. #define PR_DIRECTORY_SEPARATOR        '\\'
  283. #define PR_DIRECTORY_SEPARATOR_STR    "\\"
  284. #define PR_PATH_SEPARATOR        ';'
  285. #define PR_PATH_SEPARATOR_STR        ";"
  286. #define _MD_ERRNO()                   GetLastError()
  287. #define _MD_OPEN_DIR                  _PR_MD_OPEN_DIR
  288. #define _MD_CLOSE_DIR                 _PR_MD_CLOSE_DIR
  289. #define _MD_READ_DIR                  _PR_MD_READ_DIR
  290.  
  291. /* --- Segment stuff --- */
  292. #define _MD_INIT_SEGS()
  293. #define _MD_ALLOC_SEGMENT(seg, size, vaddr)   0
  294. #define _MD_FREE_SEGMENT(seg)
  295.  
  296. /* --- Environment Stuff --- */
  297. #define _MD_GET_ENV                 _PR_MD_GET_ENV
  298. #define _MD_PUT_ENV                 _PR_MD_PUT_ENV
  299.  
  300. /* --- Threading Stuff --- */
  301. #define _MD_DEFAULT_STACK_SIZE            0
  302. #define _MD_INIT_THREAD             _PR_MD_INIT_THREAD
  303. #define _MD_INIT_ATTACHED_THREAD    _PR_MD_INIT_THREAD
  304. #define _MD_INIT_PRIMORDIAL_THREAD  _PR_MD_INIT_PRIMORDIAL_THREAD
  305. #define _MD_CREATE_THREAD           _PR_MD_CREATE_THREAD
  306. #define _MD_YIELD                   _PR_MD_YIELD
  307. #define _MD_SET_PRIORITY            _PR_MD_SET_PRIORITY
  308. #define _MD_CLEAN_THREAD            _PR_MD_CLEAN_THREAD
  309. #define _MD_SETTHREADAFFINITYMASK   _PR_MD_SETTHREADAFFINITYMASK
  310. #define _MD_GETTHREADAFFINITYMASK   _PR_MD_GETTHREADAFFINITYMASK
  311. #define _MD_EXIT_THREAD             _PR_MD_EXIT_THREAD
  312. #define _MD_SUSPEND_THREAD          _PR_MD_SUSPEND_THREAD
  313. #define _MD_RESUME_THREAD           _PR_MD_RESUME_THREAD
  314. #define _MD_SUSPEND_CPU             _PR_MD_SUSPEND_CPU
  315. #define _MD_RESUME_CPU              _PR_MD_RESUME_CPU
  316. #define _MD_BEGIN_SUSPEND_ALL()
  317. #define _MD_BEGIN_RESUME_ALL()
  318. #define _MD_END_SUSPEND_ALL()
  319. #define _MD_END_RESUME_ALL()
  320.  
  321. /* --- Lock stuff --- */
  322. #define _MD_NEW_LOCK(lock)            (InitializeCriticalSection(&((lock)->mutex)),PR_SUCCESS)
  323. #define _MD_FREE_LOCK(lock)           DeleteCriticalSection(&((lock)->mutex))
  324. #ifndef PROFILE_LOCKS
  325. #define _MD_LOCK(lock)                EnterCriticalSection(&((lock)->mutex))
  326. #define _MD_TEST_AND_LOCK(lock)       0  /* XXXMB */
  327. #define _MD_UNLOCK(lock)              LeaveCriticalSection(&((lock)->mutex))
  328. #else
  329. #define _MD_LOCK(lock)                 \
  330.     PR_BEGIN_MACRO \
  331.     BOOL rv = TryEnterCriticalSection(&((lock)->mutex)); \
  332.     if (rv == TRUE) { \
  333.         InterlockedIncrement(&((lock)->hitcount)); \
  334.     } else { \
  335.         InterlockedIncrement(&((lock)->misscount)); \
  336.         EnterCriticalSection(&((lock)->mutex)); \
  337.     } \
  338.     PR_END_MACRO
  339. #define _MD_TEST_AND_LOCK(lock)       0  /* XXXMB */
  340. #define _MD_UNLOCK(lock)              LeaveCriticalSection(&((lock)->mutex))
  341. #endif
  342. #define _PR_LOCK                      _MD_LOCK
  343. #define _PR_UNLOCK                      _MD_UNLOCK
  344.  
  345. /* --- lock and cv waiting --- */
  346. #define _MD_WAIT                      _PR_MD_WAIT
  347. #define _MD_WAKEUP_WAITER             _PR_MD_WAKEUP_WAITER
  348.  
  349.    /* XXXMB- the IOQ stuff is certainly not working correctly yet. */
  350. extern  struct _MDLock              _pr_ioq_lock;
  351. #define _MD_IOQ_LOCK()                _MD_LOCK(&_pr_ioq_lock)
  352. #define _MD_IOQ_UNLOCK()              _MD_UNLOCK(&_pr_ioq_lock)
  353.  
  354.  
  355. /* --- Initialization stuff --- */
  356. #define _MD_START_INTERRUPTS()
  357. #define _MD_STOP_INTERRUPTS()
  358. #define _MD_DISABLE_CLOCK_INTERRUPTS()
  359. #define _MD_ENABLE_CLOCK_INTERRUPTS()
  360. #define _MD_BLOCK_CLOCK_INTERRUPTS()
  361. #define _MD_UNBLOCK_CLOCK_INTERRUPTS()
  362. #define _MD_EARLY_INIT                _PR_MD_EARLY_INIT
  363. #define _MD_FINAL_INIT()
  364. #define _MD_INIT_CPUS()
  365. #define _MD_INIT_RUNNING_CPU(cpu)
  366.  
  367. struct PRProcess;
  368. struct PRProcessAttr;
  369.  
  370. /* --- Create a new process --- */
  371. #define _MD_CREATE_PROCESS _PR_CreateWindowsProcess
  372. extern struct PRProcess * _PR_CreateWindowsProcess(
  373.     const char *path,
  374.     char *const *argv,
  375.     char *const *envp,
  376.     const struct PRProcessAttr *attr
  377. );
  378.  
  379. #define _MD_DETACH_PROCESS _PR_DetachWindowsProcess
  380. extern PRStatus _PR_DetachWindowsProcess(struct PRProcess *process);
  381.  
  382. /* --- Wait for a child process to terminate --- */
  383. #define _MD_WAIT_PROCESS _PR_WaitWindowsProcess
  384. extern PRStatus _PR_WaitWindowsProcess(struct PRProcess *process, 
  385.     PRInt32 *exitCode);
  386.  
  387. #define _MD_KILL_PROCESS _PR_KillWindowsProcess
  388. extern PRStatus _PR_KillWindowsProcess(struct PRProcess *process);
  389.  
  390. /* --- User Threading stuff --- */
  391. #define HAVE_FIBERS
  392. #define _MD_CREATE_USER_THREAD            _PR_MD_CREATE_USER_THREAD
  393. #define _MD_CREATE_PRIMORDIAL_USER_THREAD _PR_MD_CREATE_PRIMORDIAL_USER_THREAD
  394. #define _MD_CLEANUP_BEFORE_EXIT           _PR_MD_CLEANUP_BEFORE_EXIT
  395. #define _MD_EXIT                          _PR_MD_EXIT
  396. #define _MD_INIT_CONTEXT                  _PR_MD_INIT_CONTEXT
  397. #define _MD_SWITCH_CONTEXT                _PR_MD_SWITCH_CONTEXT
  398. #define _MD_RESTORE_CONTEXT               _PR_MD_RESTORE_CONTEXT
  399.  
  400. /* --- Intervals --- */
  401. #define _MD_INTERVAL_INIT                 _PR_MD_INTERVAL_INIT
  402. #define _MD_GET_INTERVAL                  _PR_MD_GET_INTERVAL
  403. #define _MD_INTERVAL_PER_SEC              _PR_MD_INTERVAL_PER_SEC
  404. #define _MD_INTERVAL_PER_MILLISEC()       (_PR_MD_INTERVAL_PER_SEC() / 1000)
  405. #define _MD_INTERVAL_PER_MICROSEC()       (_PR_MD_INTERVAL_PER_SEC() / 1000000)
  406.  
  407. /* --- Native-Thread Specific Definitions ------------------------------- */
  408.  
  409. extern BOOL _pr_use_static_tls;
  410.  
  411. extern __declspec(thread) struct PRThread *_pr_current_fiber;
  412. extern DWORD _pr_currentFiberIndex;
  413.  
  414. #define _MD_GET_ATTACHED_THREAD() \
  415.     (_pr_use_static_tls ? _pr_current_fiber \
  416.     : (PRThread *) TlsGetValue(_pr_currentFiberIndex))
  417.  
  418. extern struct PRThread * _MD_CURRENT_THREAD(void);
  419.  
  420. #define _MD_SET_CURRENT_THREAD(_thread) \
  421.     PR_BEGIN_MACRO \
  422.         if (_pr_use_static_tls) { \
  423.             _pr_current_fiber = (_thread); \
  424.         } else { \
  425.             TlsSetValue(_pr_currentFiberIndex, (_thread)); \
  426.         } \
  427.     PR_END_MACRO
  428.  
  429. extern __declspec(thread) struct PRThread *_pr_fiber_last_run;
  430. extern DWORD _pr_lastFiberIndex;
  431.  
  432. #define _MD_LAST_THREAD() \
  433.     (_pr_use_static_tls ? _pr_fiber_last_run \
  434.     : (PRThread *) TlsGetValue(_pr_lastFiberIndex))
  435.  
  436. #define _MD_SET_LAST_THREAD(_thread) \
  437.     PR_BEGIN_MACRO \
  438.         if (_pr_use_static_tls) { \
  439.             _pr_fiber_last_run = (_thread); \
  440.         } else { \
  441.             TlsSetValue(_pr_lastFiberIndex, (_thread)); \
  442.         } \
  443.     PR_END_MACRO
  444.  
  445. extern __declspec(thread) struct _PRCPU *_pr_current_cpu;
  446. extern DWORD _pr_currentCPUIndex;
  447.  
  448. #define _MD_CURRENT_CPU() \
  449.     (_pr_use_static_tls ? _pr_current_cpu \
  450.     : (struct _PRCPU *) TlsGetValue(_pr_currentCPUIndex))
  451.  
  452. #define _MD_SET_CURRENT_CPU(_cpu) \
  453.     PR_BEGIN_MACRO \
  454.         if (_pr_use_static_tls) { \
  455.             _pr_current_cpu = (_cpu); \
  456.         } else { \
  457.             TlsSetValue(_pr_currentCPUIndex, (_cpu)); \
  458.         } \
  459.     PR_END_MACRO
  460.  
  461. extern __declspec(thread) PRUintn _pr_ints_off;
  462. extern DWORD _pr_intsOffIndex;
  463.  
  464. #define _MD_GET_INTSOFF() \
  465.     (_pr_use_static_tls ? _pr_ints_off \
  466.     : (PRUintn) TlsGetValue(_pr_intsOffIndex))
  467.  
  468. #define _MD_SET_INTSOFF(_val) \
  469.     PR_BEGIN_MACRO \
  470.         if (_pr_use_static_tls) { \
  471.             _pr_ints_off = (_val); \
  472.         } else { \
  473.             TlsSetValue(_pr_intsOffIndex, (LPVOID) (_val)); \
  474.         } \
  475.     PR_END_MACRO
  476.  
  477. /* --- Initialization stuff --- */
  478. #define _MD_INIT_LOCKS()
  479.  
  480. /* --- Stack stuff --- */
  481. #define _MD_INIT_STACK(stack, redzone)
  482. #define _MD_CLEAR_STACK(stack)
  483.  
  484. /* --- Memory-mapped files stuff --- */
  485.  
  486. struct _MDFileMap {
  487.     HANDLE hFileMap;
  488.     DWORD dwAccess;
  489. };
  490.  
  491. extern PRStatus _MD_CreateFileMap(struct PRFileMap *fmap, PRInt64 size);
  492. #define _MD_CREATE_FILE_MAP _MD_CreateFileMap
  493.  
  494. extern void * _MD_MemMap(struct PRFileMap *fmap, PRInt64 offset,
  495.         PRUint32 len);
  496. #define _MD_MEM_MAP _MD_MemMap
  497.  
  498. extern PRStatus _MD_MemUnmap(void *addr, PRUint32 size);
  499. #define _MD_MEM_UNMAP _MD_MemUnmap
  500.  
  501. extern PRStatus _MD_CloseFileMap(struct PRFileMap *fmap);
  502. #define _MD_CLOSE_FILE_MAP _MD_CloseFileMap
  503.  
  504. #endif /* nspr_win32_defs_h___ */
  505.