_win95.h 20 KB

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