tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

_winnt.h (21910B)


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