_winnt.h 21 KB

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