_os2.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  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_os2_defs_h___
  38. #define nspr_os2_defs_h___
  39. #ifndef NO_LONG_LONG
  40. #define INCL_LONGLONG
  41. #endif
  42. #define INCL_DOS
  43. #define INCL_DOSPROCESS
  44. #define INCL_DOSERRORS
  45. #define INCL_WIN
  46. #define INCL_WPS
  47. #include <os2.h>
  48. #include <sys/select.h>
  49. #include "prio.h"
  50. #include <errno.h>
  51. #ifdef XP_OS2_VACPP
  52. /* TODO RAMSEMs need to be written for GCC/EMX */
  53. #define USE_RAMSEM
  54. #endif
  55. #ifdef USE_RAMSEM
  56. #pragma pack(4)
  57. #pragma pack(2)
  58. typedef struct _RAMSEM
  59. {
  60. ULONG ulTIDPID;
  61. ULONG hevSem;
  62. ULONG cLocks;
  63. USHORT cWaiting;
  64. USHORT cPosts;
  65. } RAMSEM, *PRAMSEM;
  66. typedef struct _CRITICAL_SECTION
  67. {
  68. ULONG ulReserved[4]; /* Same size as RAMSEM */
  69. } CRITICAL_SECTION, *PCRITICAL_SECTION, *LPCRITICAL_SECTION;
  70. #pragma pack(4)
  71. APIRET _Optlink SemRequest486(PRAMSEM, ULONG);
  72. APIRET _Optlink SemReleasex86(PRAMSEM, ULONG);
  73. #endif
  74. /*
  75. * Internal configuration macros
  76. */
  77. #define PR_LINKER_ARCH "os2"
  78. #define _PR_SI_SYSNAME "OS2"
  79. #define _PR_SI_ARCHITECTURE "x86" /* XXXMB hardcode for now */
  80. #define HAVE_DLL
  81. #define _PR_GLOBAL_THREADS_ONLY
  82. #undef HAVE_THREAD_AFFINITY
  83. #define _PR_HAVE_THREADSAFE_GETHOST
  84. #define _PR_HAVE_ATOMIC_OPS
  85. #define HANDLE unsigned long
  86. #define HINSTANCE HMODULE
  87. /* --- Common User-Thread/Native-Thread Definitions --------------------- */
  88. /* --- Globals --- */
  89. extern struct PRLock *_pr_schedLock;
  90. /* --- Typedefs --- */
  91. typedef void (*FiberFunc)(void *);
  92. #define PR_NUM_GCREGS 8
  93. typedef PRInt32 PR_CONTEXT_TYPE[PR_NUM_GCREGS];
  94. #define GC_VMBASE 0x40000000
  95. #define GC_VMLIMIT 0x00FFFFFF
  96. typedef int (*FARPROC)();
  97. #define _MD_MAGIC_THREAD 0x22222222
  98. #define _MD_MAGIC_THREADSTACK 0x33333333
  99. #define _MD_MAGIC_SEGMENT 0x44444444
  100. #define _MD_MAGIC_DIR 0x55555555
  101. #define _MD_MAGIC_CV 0x66666666
  102. struct _MDSemaphore {
  103. HEV sem;
  104. };
  105. struct _MDCPU {
  106. int unused;
  107. };
  108. struct _MDThread {
  109. HEV blocked_sema; /* Threads block on this when waiting
  110. * for IO or CondVar.
  111. */
  112. PRBool inCVWaitQueue; /* PR_TRUE if the thread is in the
  113. * wait queue of some cond var.
  114. * PR_FALSE otherwise. */
  115. TID handle; /* OS/2 thread handle */
  116. void *sp; /* only valid when suspended */
  117. PRUint32 magic; /* for debugging */
  118. PR_CONTEXT_TYPE gcContext; /* Thread context for GC */
  119. struct PRThread *prev, *next; /* used by the cvar wait queue to
  120. * chain the PRThread structures
  121. * together */
  122. };
  123. struct _MDThreadStack {
  124. PRUint32 magic; /* for debugging */
  125. };
  126. struct _MDSegment {
  127. PRUint32 magic; /* for debugging */
  128. };
  129. #undef PROFILE_LOCKS
  130. struct _MDDir {
  131. HDIR d_hdl;
  132. union {
  133. FILEFINDBUF3 small;
  134. FILEFINDBUF3L large;
  135. } d_entry;
  136. PRBool firstEntry; /* Is this the entry returned
  137. * by FindFirstFile()? */
  138. PRUint32 magic; /* for debugging */
  139. };
  140. struct _MDCVar {
  141. PRUint32 magic;
  142. struct PRThread *waitHead, *waitTail; /* the wait queue: a doubly-
  143. * linked list of threads
  144. * waiting on this condition
  145. * variable */
  146. PRIntn nwait; /* number of threads in the
  147. * wait queue */
  148. };
  149. #define _MD_CV_NOTIFIED_LENGTH 6
  150. typedef struct _MDNotified _MDNotified;
  151. struct _MDNotified {
  152. PRIntn length; /* # of used entries in this
  153. * structure */
  154. struct {
  155. struct _MDCVar *cv; /* the condition variable notified */
  156. PRIntn times; /* and the number of times notified */
  157. struct PRThread *notifyHead; /* list of threads to wake up */
  158. } cv[_MD_CV_NOTIFIED_LENGTH];
  159. _MDNotified *link; /* link to another of these, or NULL */
  160. };
  161. struct _MDLock {
  162. #ifdef USE_RAMSEM
  163. CRITICAL_SECTION mutex; /* this is recursive on NT */
  164. #else
  165. HMTX mutex; /* this is recursive on NT */
  166. #endif
  167. /*
  168. * When notifying cvars, there is no point in actually
  169. * waking up the threads waiting on the cvars until we've
  170. * released the lock. So, we temporarily record the cvars.
  171. * When doing an unlock, we'll then wake up the waiting threads.
  172. */
  173. struct _MDNotified notified; /* array of conditions notified */
  174. #ifdef PROFILE_LOCKS
  175. PRInt32 hitcount;
  176. PRInt32 misscount;
  177. #endif
  178. };
  179. struct _MDFileDesc {
  180. PRInt32 osfd; /* The osfd can come from one of three spaces:
  181. * - For stdin, stdout, and stderr, we are using
  182. * the libc file handle (0, 1, 2), which is an int.
  183. * - For files and pipes, we are using OS/2 handles,
  184. * which is a void*.
  185. * - For sockets, we are using int
  186. */
  187. };
  188. struct _MDProcess {
  189. PID pid;
  190. };
  191. /* --- Misc stuff --- */
  192. #define _MD_GET_SP(thread) (thread)->md.gcContext[6]
  193. /* --- IO stuff --- */
  194. #define _MD_OPEN (_PR_MD_OPEN)
  195. #define _MD_OPEN_FILE (_PR_MD_OPEN)
  196. #define _MD_READ (_PR_MD_READ)
  197. #define _MD_WRITE (_PR_MD_WRITE)
  198. #define _MD_WRITEV (_PR_MD_WRITEV)
  199. #define _MD_LSEEK (_PR_MD_LSEEK)
  200. #define _MD_LSEEK64 (_PR_MD_LSEEK64)
  201. extern PRInt32 _MD_CloseFile(PRInt32 osfd);
  202. #define _MD_CLOSE_FILE _MD_CloseFile
  203. #define _MD_GETFILEINFO (_PR_MD_GETFILEINFO)
  204. #define _MD_GETFILEINFO64 (_PR_MD_GETFILEINFO64)
  205. #define _MD_GETOPENFILEINFO (_PR_MD_GETOPENFILEINFO)
  206. #define _MD_GETOPENFILEINFO64 (_PR_MD_GETOPENFILEINFO64)
  207. #define _MD_STAT (_PR_MD_STAT)
  208. #define _MD_RENAME (_PR_MD_RENAME)
  209. #define _MD_ACCESS (_PR_MD_ACCESS)
  210. #define _MD_DELETE (_PR_MD_DELETE)
  211. #define _MD_MKDIR (_PR_MD_MKDIR)
  212. #define _MD_MAKE_DIR (_PR_MD_MKDIR)
  213. #define _MD_RMDIR (_PR_MD_RMDIR)
  214. #define _MD_LOCKFILE (_PR_MD_LOCKFILE)
  215. #define _MD_TLOCKFILE (_PR_MD_TLOCKFILE)
  216. #define _MD_UNLOCKFILE (_PR_MD_UNLOCKFILE)
  217. /* --- Socket IO stuff --- */
  218. /* The ones that don't map directly may need to be re-visited... */
  219. #ifdef XP_OS2_VACPP
  220. #define EPIPE EBADF
  221. #define EIO ECONNREFUSED
  222. #endif
  223. #define _MD_EACCES EACCES
  224. #define _MD_EADDRINUSE EADDRINUSE
  225. #define _MD_EADDRNOTAVAIL EADDRNOTAVAIL
  226. #define _MD_EAFNOSUPPORT EAFNOSUPPORT
  227. #define _MD_EAGAIN EWOULDBLOCK
  228. #define _MD_EALREADY EALREADY
  229. #define _MD_EBADF EBADF
  230. #define _MD_ECONNREFUSED ECONNREFUSED
  231. #define _MD_ECONNRESET ECONNRESET
  232. #define _MD_EFAULT SOCEFAULT
  233. #define _MD_EINPROGRESS EINPROGRESS
  234. #define _MD_EINTR EINTR
  235. #define _MD_EINVAL EINVAL
  236. #define _MD_EISCONN EISCONN
  237. #define _MD_ENETUNREACH ENETUNREACH
  238. #define _MD_ENOENT ENOENT
  239. #define _MD_ENOTCONN ENOTCONN
  240. #define _MD_ENOTSOCK ENOTSOCK
  241. #define _MD_EOPNOTSUPP EOPNOTSUPP
  242. #define _MD_EWOULDBLOCK EWOULDBLOCK
  243. #define _MD_GET_SOCKET_ERROR() sock_errno()
  244. #ifndef INADDR_LOOPBACK /* For some reason this is not defined in OS2 tcpip */
  245. /* #define INADDR_LOOPBACK INADDR_ANY */
  246. #endif
  247. #define _MD_INIT_FILEDESC(fd)
  248. extern void _MD_MakeNonblock(PRFileDesc *f);
  249. #define _MD_MAKE_NONBLOCK _MD_MakeNonblock
  250. #define _MD_INIT_FD_INHERITABLE (_PR_MD_INIT_FD_INHERITABLE)
  251. #define _MD_QUERY_FD_INHERITABLE (_PR_MD_QUERY_FD_INHERITABLE)
  252. #define _MD_SHUTDOWN (_PR_MD_SHUTDOWN)
  253. #define _MD_LISTEN _PR_MD_LISTEN
  254. extern PRInt32 _MD_CloseSocket(PRInt32 osfd);
  255. #define _MD_CLOSE_SOCKET _MD_CloseSocket
  256. #define _MD_SENDTO (_PR_MD_SENDTO)
  257. #define _MD_RECVFROM (_PR_MD_RECVFROM)
  258. #ifdef XP_OS2_VACPP
  259. #define _MD_SOCKETPAIR(s, type, proto, sv) -1
  260. #else
  261. #define _MD_SOCKETPAIR (_PR_MD_SOCKETPAIR)
  262. #endif
  263. #define _MD_GETSOCKNAME (_PR_MD_GETSOCKNAME)
  264. #define _MD_GETPEERNAME (_PR_MD_GETPEERNAME)
  265. #define _MD_GETSOCKOPT (_PR_MD_GETSOCKOPT)
  266. #define _MD_SETSOCKOPT (_PR_MD_SETSOCKOPT)
  267. #define _MD_FSYNC _PR_MD_FSYNC
  268. #define _MD_SET_FD_INHERITABLE (_PR_MD_SET_FD_INHERITABLE)
  269. #ifdef _PR_HAVE_ATOMIC_OPS
  270. #define _MD_INIT_ATOMIC()
  271. #define _MD_ATOMIC_INCREMENT _PR_MD_ATOMIC_INCREMENT
  272. #define _MD_ATOMIC_ADD _PR_MD_ATOMIC_ADD
  273. #define _MD_ATOMIC_DECREMENT _PR_MD_ATOMIC_DECREMENT
  274. #define _MD_ATOMIC_SET _PR_MD_ATOMIC_SET
  275. #endif
  276. #define _MD_INIT_IO (_PR_MD_INIT_IO)
  277. #define _MD_PR_POLL (_PR_MD_PR_POLL)
  278. #define _MD_SOCKET (_PR_MD_SOCKET)
  279. extern PRInt32 _MD_SocketAvailable(PRFileDesc *fd);
  280. #define _MD_SOCKETAVAILABLE _MD_SocketAvailable
  281. #define _MD_PIPEAVAILABLE _MD_SocketAvailable
  282. #define _MD_CONNECT (_PR_MD_CONNECT)
  283. extern PRInt32 _MD_Accept(PRFileDesc *fd, PRNetAddr *raddr, PRUint32 *rlen,
  284. PRIntervalTime timeout);
  285. #define _MD_ACCEPT _MD_Accept
  286. #define _MD_BIND (_PR_MD_BIND)
  287. #define _MD_RECV (_PR_MD_RECV)
  288. #define _MD_SEND (_PR_MD_SEND)
  289. /* --- Scheduler stuff --- */
  290. /* #define _MD_PAUSE_CPU _PR_MD_PAUSE_CPU */
  291. #define _MD_PAUSE_CPU
  292. /* --- DIR stuff --- */
  293. #define PR_DIRECTORY_SEPARATOR '\\'
  294. #define PR_DIRECTORY_SEPARATOR_STR "\\"
  295. #define PR_PATH_SEPARATOR ';'
  296. #define PR_PATH_SEPARATOR_STR ";"
  297. #define _MD_ERRNO() errno
  298. #define _MD_OPEN_DIR (_PR_MD_OPEN_DIR)
  299. #define _MD_CLOSE_DIR (_PR_MD_CLOSE_DIR)
  300. #define _MD_READ_DIR (_PR_MD_READ_DIR)
  301. /* --- Segment stuff --- */
  302. #define _MD_INIT_SEGS()
  303. #define _MD_ALLOC_SEGMENT(seg, size, vaddr) 0
  304. #define _MD_FREE_SEGMENT(seg)
  305. /* --- Environment Stuff --- */
  306. #define _MD_GET_ENV (_PR_MD_GET_ENV)
  307. #define _MD_PUT_ENV (_PR_MD_PUT_ENV)
  308. /* --- Threading Stuff --- */
  309. #define _MD_DEFAULT_STACK_SIZE 65536L
  310. #define _MD_INIT_THREAD (_PR_MD_INIT_THREAD)
  311. #define _MD_INIT_ATTACHED_THREAD (_PR_MD_INIT_THREAD)
  312. #define _MD_CREATE_THREAD (_PR_MD_CREATE_THREAD)
  313. #define _MD_YIELD (_PR_MD_YIELD)
  314. #define _MD_SET_PRIORITY (_PR_MD_SET_PRIORITY)
  315. #define _MD_CLEAN_THREAD (_PR_MD_CLEAN_THREAD)
  316. #define _MD_SETTHREADAFFINITYMASK (_PR_MD_SETTHREADAFFINITYMASK)
  317. #define _MD_GETTHREADAFFINITYMASK (_PR_MD_GETTHREADAFFINITYMASK)
  318. #define _MD_EXIT_THREAD (_PR_MD_EXIT_THREAD)
  319. #define _MD_SUSPEND_THREAD (_PR_MD_SUSPEND_THREAD)
  320. #define _MD_RESUME_THREAD (_PR_MD_RESUME_THREAD)
  321. #define _MD_SUSPEND_CPU (_PR_MD_SUSPEND_CPU)
  322. #define _MD_RESUME_CPU (_PR_MD_RESUME_CPU)
  323. #define _MD_WAKEUP_CPUS (_PR_MD_WAKEUP_CPUS)
  324. #define _MD_BEGIN_SUSPEND_ALL()
  325. #define _MD_BEGIN_RESUME_ALL()
  326. #define _MD_END_SUSPEND_ALL()
  327. #define _MD_END_RESUME_ALL()
  328. /* --- Lock stuff --- */
  329. #define _PR_LOCK _MD_LOCK
  330. #define _PR_UNLOCK _MD_UNLOCK
  331. #ifdef USE_RAMSEM
  332. #define _MD_NEW_LOCK (_PR_MD_NEW_LOCK)
  333. #define _MD_FREE_LOCK(lock) (DosCloseEventSem(((PRAMSEM)(&((lock)->mutex)))->hevSem))
  334. #define _MD_LOCK(lock) (SemRequest486(&((lock)->mutex), -1))
  335. #define _MD_TEST_AND_LOCK(lock) (SemRequest486(&((lock)->mutex), -1),0)
  336. #define _MD_UNLOCK(lock) \
  337. PR_BEGIN_MACRO \
  338. if (0 != (lock)->notified.length) { \
  339. md_UnlockAndPostNotifies((lock), NULL, NULL); \
  340. } else { \
  341. SemReleasex86( &(lock)->mutex, 0 ); \
  342. } \
  343. PR_END_MACRO
  344. #else
  345. #define _MD_NEW_LOCK (_PR_MD_NEW_LOCK)
  346. #define _MD_FREE_LOCK(lock) (DosCloseMutexSem((lock)->mutex))
  347. #define _MD_LOCK(lock) (DosRequestMutexSem((lock)->mutex, SEM_INDEFINITE_WAIT))
  348. #define _MD_TEST_AND_LOCK(lock) (DosRequestMutexSem((lock)->mutex, SEM_INDEFINITE_WAIT),0)
  349. #define _MD_UNLOCK(lock) \
  350. PR_BEGIN_MACRO \
  351. if (0 != (lock)->notified.length) { \
  352. md_UnlockAndPostNotifies((lock), NULL, NULL); \
  353. } else { \
  354. DosReleaseMutexSem((lock)->mutex); \
  355. } \
  356. PR_END_MACRO
  357. #endif
  358. /* --- lock and cv waiting --- */
  359. #define _MD_WAIT (_PR_MD_WAIT)
  360. #define _MD_WAKEUP_WAITER (_PR_MD_WAKEUP_WAITER)
  361. /* --- CVar ------------------- */
  362. #define _MD_WAIT_CV (_PR_MD_WAIT_CV)
  363. #define _MD_NEW_CV (_PR_MD_NEW_CV)
  364. #define _MD_FREE_CV (_PR_MD_FREE_CV)
  365. #define _MD_NOTIFY_CV (_PR_MD_NOTIFY_CV )
  366. #define _MD_NOTIFYALL_CV (_PR_MD_NOTIFYALL_CV)
  367. /* XXXMB- the IOQ stuff is certainly not working correctly yet. */
  368. /* extern struct _MDLock _pr_ioq_lock; */
  369. #define _MD_IOQ_LOCK()
  370. #define _MD_IOQ_UNLOCK()
  371. /* --- Initialization stuff --- */
  372. #define _MD_START_INTERRUPTS()
  373. #define _MD_STOP_INTERRUPTS()
  374. #define _MD_DISABLE_CLOCK_INTERRUPTS()
  375. #define _MD_ENABLE_CLOCK_INTERRUPTS()
  376. #define _MD_BLOCK_CLOCK_INTERRUPTS()
  377. #define _MD_UNBLOCK_CLOCK_INTERRUPTS()
  378. #define _MD_EARLY_INIT (_PR_MD_EARLY_INIT)
  379. #define _MD_FINAL_INIT()
  380. #define _MD_INIT_CPUS()
  381. #define _MD_INIT_RUNNING_CPU(cpu)
  382. struct PRProcess;
  383. struct PRProcessAttr;
  384. #define _MD_CREATE_PROCESS _PR_CreateOS2Process
  385. extern struct PRProcess * _PR_CreateOS2Process(
  386. const char *path,
  387. char *const *argv,
  388. char *const *envp,
  389. const struct PRProcessAttr *attr
  390. );
  391. #define _MD_DETACH_PROCESS _PR_DetachOS2Process
  392. extern PRStatus _PR_DetachOS2Process(struct PRProcess *process);
  393. /* --- Wait for a child process to terminate --- */
  394. #define _MD_WAIT_PROCESS _PR_WaitOS2Process
  395. extern PRStatus _PR_WaitOS2Process(struct PRProcess *process,
  396. PRInt32 *exitCode);
  397. #define _MD_KILL_PROCESS _PR_KillOS2Process
  398. extern PRStatus _PR_KillOS2Process(struct PRProcess *process);
  399. #define _MD_CLEANUP_BEFORE_EXIT()
  400. #define _MD_EXIT (_PR_MD_EXIT)
  401. #define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
  402. PR_BEGIN_MACRO \
  403. *status = PR_TRUE; \
  404. PR_END_MACRO
  405. #define _MD_SWITCH_CONTEXT
  406. #define _MD_RESTORE_CONTEXT
  407. /* --- Intervals --- */
  408. #define _MD_INTERVAL_INIT (_PR_MD_INTERVAL_INIT)
  409. #define _MD_GET_INTERVAL (_PR_MD_GET_INTERVAL)
  410. #define _MD_INTERVAL_PER_SEC (_PR_MD_INTERVAL_PER_SEC)
  411. #define _MD_INTERVAL_PER_MILLISEC() (_PR_MD_INTERVAL_PER_SEC() / 1000)
  412. #define _MD_INTERVAL_PER_MICROSEC() (_PR_MD_INTERVAL_PER_SEC() / 1000000)
  413. /* --- Native-Thread Specific Definitions ------------------------------- */
  414. typedef struct __NSPR_TLS
  415. {
  416. struct PRThread *_pr_thread_last_run;
  417. struct PRThread *_pr_currentThread;
  418. struct _PRCPU *_pr_currentCPU;
  419. } _NSPR_TLS;
  420. extern _NSPR_TLS* pThreadLocalStorage;
  421. NSPR_API(void) _PR_MD_ENSURE_TLS(void);
  422. #define _MD_GET_ATTACHED_THREAD() pThreadLocalStorage->_pr_currentThread
  423. extern struct PRThread * _MD_CURRENT_THREAD(void);
  424. #define _MD_SET_CURRENT_THREAD(_thread) _PR_MD_ENSURE_TLS(); pThreadLocalStorage->_pr_currentThread = (_thread)
  425. #define _MD_LAST_THREAD() pThreadLocalStorage->_pr_thread_last_run
  426. #define _MD_SET_LAST_THREAD(_thread) _PR_MD_ENSURE_TLS(); pThreadLocalStorage->_pr_thread_last_run = (_thread)
  427. #define _MD_CURRENT_CPU() pThreadLocalStorage->_pr_currentCPU
  428. #define _MD_SET_CURRENT_CPU(_cpu) _PR_MD_ENSURE_TLS(); pThreadLocalStorage->_pr_currentCPU = (_cpu)
  429. /* lth. #define _MD_SET_INTSOFF(_val) (_pr_ints_off = (_val)) */
  430. /* lth. #define _MD_GET_INTSOFF() _pr_ints_off */
  431. /* lth. #define _MD_INCREMENT_INTSOFF() (_pr_ints_off++) */
  432. /* lth. #define _MD_DECREMENT_INTSOFF() (_pr_ints_off--) */
  433. /* --- Scheduler stuff --- */
  434. #define LOCK_SCHEDULER() 0
  435. #define UNLOCK_SCHEDULER() 0
  436. #define _PR_LockSched() 0
  437. #define _PR_UnlockSched() 0
  438. /* --- Initialization stuff --- */
  439. #define _MD_INIT_LOCKS()
  440. /* --- Stack stuff --- */
  441. #define _MD_INIT_STACK(stack, redzone)
  442. #define _MD_CLEAR_STACK(stack)
  443. /* --- Memory-mapped files stuff --- not implemented on OS/2 */
  444. struct _MDFileMap {
  445. PRInt8 unused;
  446. };
  447. extern PRStatus _MD_CreateFileMap(struct PRFileMap *fmap, PRInt64 size);
  448. #define _MD_CREATE_FILE_MAP _MD_CreateFileMap
  449. extern PRInt32 _MD_GetMemMapAlignment(void);
  450. #define _MD_GET_MEM_MAP_ALIGNMENT _MD_GetMemMapAlignment
  451. extern void * _MD_MemMap(struct PRFileMap *fmap, PRInt64 offset,
  452. PRUint32 len);
  453. #define _MD_MEM_MAP _MD_MemMap
  454. extern PRStatus _MD_MemUnmap(void *addr, PRUint32 size);
  455. #define _MD_MEM_UNMAP _MD_MemUnmap
  456. extern PRStatus _MD_CloseFileMap(struct PRFileMap *fmap);
  457. #define _MD_CLOSE_FILE_MAP _MD_CloseFileMap
  458. /* Some stuff for setting up thread contexts */
  459. typedef ULONG DWORD, *PDWORD;
  460. /* The following definitions and two structures are new in OS/2 Warp 4.0.
  461. */
  462. #ifndef CONTEXT_CONTROL
  463. #define CONTEXT_CONTROL 0x00000001
  464. #define CONTEXT_INTEGER 0x00000002
  465. #define CONTEXT_SEGMENTS 0x00000004
  466. #define CONTEXT_FLOATING_POINT 0x00000008
  467. #define CONTEXT_FULL 0x0000000F
  468. #pragma pack(2)
  469. typedef struct _FPREG {
  470. ULONG losig; /* Low 32-bits of the significand. */
  471. ULONG hisig; /* High 32-bits of the significand. */
  472. USHORT signexp; /* Sign and exponent. */
  473. } FPREG;
  474. typedef struct _CONTEXTRECORD {
  475. ULONG ContextFlags;
  476. ULONG ctx_env[7];
  477. FPREG ctx_stack[8];
  478. ULONG ctx_SegGs; /* GS register. */
  479. ULONG ctx_SegFs; /* FS register. */
  480. ULONG ctx_SegEs; /* ES register. */
  481. ULONG ctx_SegDs; /* DS register. */
  482. ULONG ctx_RegEdi; /* EDI register. */
  483. ULONG ctx_RegEsi; /* ESI register. */
  484. ULONG ctx_RegEax; /* EAX register. */
  485. ULONG ctx_RegEbx; /* EBX register. */
  486. ULONG ctx_RegEcx; /* ECX register. */
  487. ULONG ctx_RegEdx; /* EDX register. */
  488. ULONG ctx_RegEbp; /* EBP register. */
  489. ULONG ctx_RegEip; /* EIP register. */
  490. ULONG ctx_SegCs; /* CS register. */
  491. ULONG ctx_EFlags; /* EFLAGS register. */
  492. ULONG ctx_RegEsp; /* ESP register. */
  493. ULONG ctx_SegSs; /* SS register. */
  494. } CONTEXTRECORD, *PCONTEXTRECORD;
  495. #pragma pack()
  496. #endif
  497. extern APIRET (* APIENTRY QueryThreadContext)(TID, ULONG, PCONTEXTRECORD);
  498. /*
  499. #define _pr_tid (((PTIB2)_getTIBvalue(offsetof(TIB, tib_ptib2)))->tib2_ultid)
  500. #define _pr_current_Thread (_system_tls[_pr_tid-1].__pr_current_thread)
  501. */
  502. /* Some simple mappings of Windows API's to OS/2 API's to make our lives a
  503. * little bit easier. Only add one here if it is a DIRECT mapping. We are
  504. * not emulating anything. Just mapping.
  505. */
  506. #define FreeLibrary(x) DosFreeModule((HMODULE)x)
  507. #define OutputDebugString(x)
  508. extern int _MD_os2_get_nonblocking_connect_error(int osfd);
  509. #endif /* nspr_os2_defs_h___ */