PageRenderTime 74ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/mozilla/mozilla/dist/include/nspr/md/_winnt.h

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