Back to index

lightning-sunbird  0.9+nobinonly
_os2.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is the Netscape Portable Runtime (NSPR).
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998-2000
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef nspr_os2_defs_h___
00039 #define nspr_os2_defs_h___
00040 
00041 #ifndef NO_LONG_LONG
00042 #define INCL_LONGLONG
00043 #endif
00044 #define INCL_DOS
00045 #define INCL_DOSPROCESS
00046 #define INCL_DOSERRORS
00047 #define INCL_WIN
00048 #define INCL_WPS
00049 #include <os2.h>
00050 #include <sys/select.h>
00051 
00052 #include "prio.h"
00053 
00054 #include <errno.h>
00055 
00056 #ifdef XP_OS2_VACPP
00057 /* TODO RAMSEMs need to be written for GCC/EMX */
00058 #define USE_RAMSEM
00059 #endif
00060 
00061 #ifdef USE_RAMSEM
00062 #pragma pack(4)
00063 
00064 #pragma pack(2)
00065 typedef struct _RAMSEM
00066 {
00067    ULONG   ulTIDPID;
00068    ULONG   hevSem;
00069    ULONG   cLocks;
00070    USHORT  cWaiting;
00071    USHORT  cPosts;
00072 } RAMSEM, *PRAMSEM;
00073 
00074 typedef struct _CRITICAL_SECTION
00075 {
00076     ULONG ulReserved[4]; /* Same size as RAMSEM */
00077 } CRITICAL_SECTION, *PCRITICAL_SECTION, *LPCRITICAL_SECTION;
00078 #pragma pack(4)
00079 
00080 APIRET _Optlink SemRequest486(PRAMSEM, ULONG);
00081 APIRET _Optlink SemReleasex86(PRAMSEM, ULONG);
00082 #endif
00083 
00084 /*
00085  * Internal configuration macros
00086  */
00087 
00088 #define PR_LINKER_ARCH      "os2"
00089 #define _PR_SI_SYSNAME        "OS2"
00090 #define _PR_SI_ARCHITECTURE   "x86"    /* XXXMB hardcode for now */
00091 
00092 #define HAVE_DLL
00093 #define _PR_GLOBAL_THREADS_ONLY
00094 #undef  HAVE_THREAD_AFFINITY
00095 #define _PR_HAVE_THREADSAFE_GETHOST
00096 #define _PR_HAVE_ATOMIC_OPS
00097 
00098 #define HANDLE unsigned long
00099 #define HINSTANCE HMODULE
00100 
00101 /* --- Common User-Thread/Native-Thread Definitions --------------------- */
00102 
00103 /* --- Globals --- */
00104 extern struct PRLock                      *_pr_schedLock;
00105 
00106 /* --- Typedefs --- */
00107 typedef void (*FiberFunc)(void *);
00108 
00109 #define PR_NUM_GCREGS           8
00110 typedef PRInt32                      PR_CONTEXT_TYPE[PR_NUM_GCREGS];
00111 #define GC_VMBASE               0x40000000
00112 #define GC_VMLIMIT              0x00FFFFFF
00113 typedef int (*FARPROC)();
00114 
00115 #define _MD_MAGIC_THREAD    0x22222222
00116 #define _MD_MAGIC_THREADSTACK      0x33333333
00117 #define _MD_MAGIC_SEGMENT   0x44444444
00118 #define _MD_MAGIC_DIR              0x55555555
00119 #define _MD_MAGIC_CV        0x66666666
00120 
00121 struct _MDSemaphore {
00122    HEV sem;
00123 };
00124 
00125 struct _MDCPU {
00126     int              unused;
00127 }; 
00128 
00129 struct _MDThread {
00130     HEV              blocked_sema;      /* Threads block on this when waiting
00131                                          * for IO or CondVar.
00132                                          */
00133     PRBool           inCVWaitQueue;     /* PR_TRUE if the thread is in the
00134                                          * wait queue of some cond var.
00135                                          * PR_FALSE otherwise.  */
00136     TID              handle;            /* OS/2 thread handle */
00137     void            *sp;                /* only valid when suspended */
00138     PRUint32         magic;             /* for debugging */
00139     PR_CONTEXT_TYPE  gcContext;         /* Thread context for GC */
00140     struct PRThread *prev, *next;       /* used by the cvar wait queue to
00141                                          * chain the PRThread structures
00142                                          * together */
00143 };
00144 
00145 struct _MDThreadStack {
00146     PRUint32           magic;          /* for debugging */
00147 };
00148 
00149 struct _MDSegment {
00150     PRUint32           magic;          /* for debugging */
00151 };
00152 
00153 #undef PROFILE_LOCKS
00154 
00155 struct _MDDir {
00156     HDIR           d_hdl;
00157     union {
00158         FILEFINDBUF3  small;
00159         FILEFINDBUF3L large;
00160     } d_entry;
00161     PRBool           firstEntry;     /* Is this the entry returned
00162                                       * by FindFirstFile()? */
00163     PRUint32         magic;          /* for debugging */
00164 };
00165 
00166 struct _MDCVar {
00167     PRUint32 magic;
00168     struct PRThread *waitHead, *waitTail;  /* the wait queue: a doubly-
00169                                             * linked list of threads
00170                                             * waiting on this condition
00171                                             * variable */
00172     PRIntn nwait;                          /* number of threads in the
00173                                             * wait queue */
00174 };
00175 
00176 #define _MD_CV_NOTIFIED_LENGTH 6
00177 typedef struct _MDNotified _MDNotified;
00178 struct _MDNotified {
00179     PRIntn length;                     /* # of used entries in this
00180                                         * structure */
00181     struct {
00182         struct _MDCVar *cv;            /* the condition variable notified */
00183         PRIntn times;                  /* and the number of times notified */
00184         struct PRThread *notifyHead;   /* list of threads to wake up */
00185     } cv[_MD_CV_NOTIFIED_LENGTH];
00186     _MDNotified *link;                 /* link to another of these, or NULL */
00187 };
00188 
00189 struct _MDLock {
00190 #ifdef USE_RAMSEM
00191     CRITICAL_SECTION mutex;            /* this is recursive on NT */
00192 #else
00193     HMTX mutex;                        /* this is recursive on NT */
00194 #endif
00195 
00196     /*
00197      * When notifying cvars, there is no point in actually
00198      * waking up the threads waiting on the cvars until we've
00199      * released the lock.  So, we temporarily record the cvars.
00200      * When doing an unlock, we'll then wake up the waiting threads.
00201      */
00202     struct _MDNotified notified;     /* array of conditions notified */
00203 #ifdef PROFILE_LOCKS
00204     PRInt32 hitcount;
00205     PRInt32 misscount;
00206 #endif
00207 };
00208 
00209 struct _MDFileDesc {
00210     PRInt32 osfd;    /* The osfd can come from one of three spaces:
00211                       * - For stdin, stdout, and stderr, we are using
00212                       *   the libc file handle (0, 1, 2), which is an int.
00213                       * - For files and pipes, we are using OS/2 handles,
00214                       *   which is a void*.
00215                       * - For sockets, we are using int
00216                       */
00217 };
00218 
00219 struct _MDProcess {
00220    PID pid;
00221 };
00222 
00223 /* --- Misc stuff --- */
00224 #define _MD_GET_SP(thread)            (thread)->md.gcContext[6]
00225 
00226 /* --- IO stuff --- */
00227 
00228 #define _MD_OPEN                      (_PR_MD_OPEN)
00229 #define _MD_OPEN_FILE                 (_PR_MD_OPEN)
00230 #define _MD_READ                      (_PR_MD_READ)
00231 #define _MD_WRITE                     (_PR_MD_WRITE)
00232 #define _MD_WRITEV                    (_PR_MD_WRITEV)
00233 #define _MD_LSEEK                     (_PR_MD_LSEEK)
00234 #define _MD_LSEEK64                   (_PR_MD_LSEEK64)
00235 extern PRInt32 _MD_CloseFile(PRInt32 osfd);
00236 #define _MD_CLOSE_FILE                _MD_CloseFile
00237 #define _MD_GETFILEINFO               (_PR_MD_GETFILEINFO)
00238 #define _MD_GETFILEINFO64             (_PR_MD_GETFILEINFO64)
00239 #define _MD_GETOPENFILEINFO           (_PR_MD_GETOPENFILEINFO)
00240 #define _MD_GETOPENFILEINFO64         (_PR_MD_GETOPENFILEINFO64)
00241 #define _MD_STAT                      (_PR_MD_STAT)
00242 #define _MD_RENAME                    (_PR_MD_RENAME)
00243 #define _MD_ACCESS                    (_PR_MD_ACCESS)
00244 #define _MD_DELETE                    (_PR_MD_DELETE)
00245 #define _MD_MKDIR                     (_PR_MD_MKDIR)
00246 #define _MD_MAKE_DIR                  (_PR_MD_MKDIR)
00247 #define _MD_RMDIR                     (_PR_MD_RMDIR)
00248 #define _MD_LOCKFILE                  (_PR_MD_LOCKFILE)
00249 #define _MD_TLOCKFILE                 (_PR_MD_TLOCKFILE)
00250 #define _MD_UNLOCKFILE                (_PR_MD_UNLOCKFILE)
00251 
00252 /* --- Socket IO stuff --- */
00253 
00254 /* The ones that don't map directly may need to be re-visited... */
00255 #ifdef XP_OS2_VACPP
00256 #define EPIPE                     EBADF
00257 #define EIO                       ECONNREFUSED
00258 #endif
00259 #define _MD_EACCES                EACCES
00260 #define _MD_EADDRINUSE            EADDRINUSE
00261 #define _MD_EADDRNOTAVAIL         EADDRNOTAVAIL
00262 #define _MD_EAFNOSUPPORT          EAFNOSUPPORT
00263 #define _MD_EAGAIN                EWOULDBLOCK
00264 #define _MD_EALREADY              EALREADY
00265 #define _MD_EBADF                 EBADF
00266 #define _MD_ECONNREFUSED          ECONNREFUSED
00267 #define _MD_ECONNRESET            ECONNRESET
00268 #define _MD_EFAULT                SOCEFAULT
00269 #define _MD_EINPROGRESS           EINPROGRESS
00270 #define _MD_EINTR                 EINTR
00271 #define _MD_EINVAL                EINVAL
00272 #define _MD_EISCONN               EISCONN
00273 #define _MD_ENETUNREACH           ENETUNREACH
00274 #define _MD_ENOENT                ENOENT
00275 #define _MD_ENOTCONN              ENOTCONN
00276 #define _MD_ENOTSOCK              ENOTSOCK
00277 #define _MD_EOPNOTSUPP            EOPNOTSUPP
00278 #define _MD_EWOULDBLOCK           EWOULDBLOCK
00279 #define _MD_GET_SOCKET_ERROR()    sock_errno()
00280 #ifndef INADDR_LOOPBACK /* For some reason this is not defined in OS2 tcpip */
00281 /*  #define INADDR_LOOPBACK         INADDR_ANY */
00282 #endif  
00283 
00284 #define _MD_INIT_FILEDESC(fd)
00285 extern void _MD_MakeNonblock(PRFileDesc *f);
00286 #define _MD_MAKE_NONBLOCK             _MD_MakeNonblock
00287 #define _MD_INIT_FD_INHERITABLE       (_PR_MD_INIT_FD_INHERITABLE)
00288 #define _MD_QUERY_FD_INHERITABLE      (_PR_MD_QUERY_FD_INHERITABLE)
00289 #define _MD_SHUTDOWN                  (_PR_MD_SHUTDOWN)
00290 #define _MD_LISTEN                    _PR_MD_LISTEN
00291 extern PRInt32 _MD_CloseSocket(PRInt32 osfd);
00292 #define _MD_CLOSE_SOCKET              _MD_CloseSocket
00293 #define _MD_SENDTO                    (_PR_MD_SENDTO)
00294 #define _MD_RECVFROM                  (_PR_MD_RECVFROM)
00295 #ifdef XP_OS2_VACPP
00296 #define _MD_SOCKETPAIR(s, type, proto, sv) -1
00297 #else
00298 #define _MD_SOCKETPAIR                (_PR_MD_SOCKETPAIR)
00299 #endif
00300 #define _MD_GETSOCKNAME               (_PR_MD_GETSOCKNAME)
00301 #define _MD_GETPEERNAME               (_PR_MD_GETPEERNAME)
00302 #define _MD_GETSOCKOPT                (_PR_MD_GETSOCKOPT)
00303 #define _MD_SETSOCKOPT                (_PR_MD_SETSOCKOPT)
00304 
00305 #define _MD_FSYNC                     _PR_MD_FSYNC
00306 #define _MD_SET_FD_INHERITABLE        (_PR_MD_SET_FD_INHERITABLE)
00307 
00308 #ifdef _PR_HAVE_ATOMIC_OPS
00309 #define _MD_INIT_ATOMIC()
00310 #define _MD_ATOMIC_INCREMENT          _PR_MD_ATOMIC_INCREMENT
00311 #define _MD_ATOMIC_ADD                _PR_MD_ATOMIC_ADD
00312 #define _MD_ATOMIC_DECREMENT          _PR_MD_ATOMIC_DECREMENT
00313 #define _MD_ATOMIC_SET                _PR_MD_ATOMIC_SET
00314 #endif
00315 
00316 #define _MD_INIT_IO                   (_PR_MD_INIT_IO)
00317 #define _MD_PR_POLL                   (_PR_MD_PR_POLL)
00318 
00319 #define _MD_SOCKET                    (_PR_MD_SOCKET)
00320 extern PRInt32 _MD_SocketAvailable(PRFileDesc *fd);
00321 #define _MD_SOCKETAVAILABLE           _MD_SocketAvailable
00322 #define _MD_PIPEAVAILABLE             _MD_SocketAvailable
00323 #define _MD_CONNECT                   (_PR_MD_CONNECT)
00324 extern PRInt32 _MD_Accept(PRFileDesc *fd, PRNetAddr *raddr, PRUint32 *rlen,
00325         PRIntervalTime timeout);
00326 #define _MD_ACCEPT                    _MD_Accept
00327 #define _MD_BIND                      (_PR_MD_BIND)
00328 #define _MD_RECV                      (_PR_MD_RECV)
00329 #define _MD_SEND                      (_PR_MD_SEND)
00330 
00331 /* --- Scheduler stuff --- */
00332 /* #define _MD_PAUSE_CPU                 _PR_MD_PAUSE_CPU */
00333 #define _MD_PAUSE_CPU
00334 
00335 /* --- DIR stuff --- */
00336 #define PR_DIRECTORY_SEPARATOR        '\\'
00337 #define PR_DIRECTORY_SEPARATOR_STR    "\\"
00338 #define PR_PATH_SEPARATOR          ';'
00339 #define PR_PATH_SEPARATOR_STR             ";"
00340 #define _MD_ERRNO()                   errno
00341 #define _MD_OPEN_DIR                  (_PR_MD_OPEN_DIR)
00342 #define _MD_CLOSE_DIR                 (_PR_MD_CLOSE_DIR)
00343 #define _MD_READ_DIR                  (_PR_MD_READ_DIR)
00344 
00345 /* --- Segment stuff --- */
00346 #define _MD_INIT_SEGS()
00347 #define _MD_ALLOC_SEGMENT(seg, size, vaddr)   0
00348 #define _MD_FREE_SEGMENT(seg)
00349 
00350 /* --- Environment Stuff --- */
00351 #define _MD_GET_ENV                 (_PR_MD_GET_ENV)
00352 #define _MD_PUT_ENV                 (_PR_MD_PUT_ENV)
00353 
00354 /* --- Threading Stuff --- */
00355 #define _MD_DEFAULT_STACK_SIZE      65536L
00356 #define _MD_INIT_THREAD             (_PR_MD_INIT_THREAD)
00357 #define _MD_INIT_ATTACHED_THREAD    (_PR_MD_INIT_THREAD)
00358 #define _MD_CREATE_THREAD           (_PR_MD_CREATE_THREAD)
00359 #define _MD_YIELD                   (_PR_MD_YIELD)
00360 #define _MD_SET_PRIORITY            (_PR_MD_SET_PRIORITY)
00361 #define _MD_CLEAN_THREAD            (_PR_MD_CLEAN_THREAD)
00362 #define _MD_SETTHREADAFFINITYMASK   (_PR_MD_SETTHREADAFFINITYMASK)
00363 #define _MD_GETTHREADAFFINITYMASK   (_PR_MD_GETTHREADAFFINITYMASK)
00364 #define _MD_EXIT_THREAD             (_PR_MD_EXIT_THREAD)
00365 #define _MD_SUSPEND_THREAD          (_PR_MD_SUSPEND_THREAD)
00366 #define _MD_RESUME_THREAD           (_PR_MD_RESUME_THREAD)
00367 #define _MD_SUSPEND_CPU             (_PR_MD_SUSPEND_CPU)
00368 #define _MD_RESUME_CPU              (_PR_MD_RESUME_CPU)
00369 #define _MD_WAKEUP_CPUS             (_PR_MD_WAKEUP_CPUS)
00370 #define _MD_BEGIN_SUSPEND_ALL()
00371 #define _MD_BEGIN_RESUME_ALL()
00372 #define _MD_END_SUSPEND_ALL()
00373 #define _MD_END_RESUME_ALL()
00374 
00375 /* --- Lock stuff --- */
00376 #define _PR_LOCK                      _MD_LOCK
00377 #define _PR_UNLOCK                                 _MD_UNLOCK
00378 
00379 #ifdef USE_RAMSEM
00380 #define _MD_NEW_LOCK                  (_PR_MD_NEW_LOCK)
00381 #define _MD_FREE_LOCK(lock)           (DosCloseEventSem(((PRAMSEM)(&((lock)->mutex)))->hevSem))
00382 #define _MD_LOCK(lock)                (SemRequest486(&((lock)->mutex), -1))
00383 #define _MD_TEST_AND_LOCK(lock)       (SemRequest486(&((lock)->mutex), -1),0)
00384 #define _MD_UNLOCK(lock)              \
00385     PR_BEGIN_MACRO \
00386     if (0 != (lock)->notified.length) { \
00387         md_UnlockAndPostNotifies((lock), NULL, NULL); \
00388     } else { \
00389         SemReleasex86( &(lock)->mutex, 0 ); \
00390     } \
00391     PR_END_MACRO
00392 #else
00393 #define _MD_NEW_LOCK                  (_PR_MD_NEW_LOCK)
00394 #define _MD_FREE_LOCK(lock)           (DosCloseMutexSem((lock)->mutex))
00395 #define _MD_LOCK(lock)                (DosRequestMutexSem((lock)->mutex, SEM_INDEFINITE_WAIT))
00396 #define _MD_TEST_AND_LOCK(lock)       (DosRequestMutexSem((lock)->mutex, SEM_INDEFINITE_WAIT),0)
00397 #define _MD_UNLOCK(lock)              \
00398     PR_BEGIN_MACRO \
00399     if (0 != (lock)->notified.length) { \
00400         md_UnlockAndPostNotifies((lock), NULL, NULL); \
00401     } else { \
00402         DosReleaseMutexSem((lock)->mutex); \
00403     } \
00404     PR_END_MACRO
00405 #endif
00406 
00407 /* --- lock and cv waiting --- */
00408 #define _MD_WAIT                      (_PR_MD_WAIT)
00409 #define _MD_WAKEUP_WAITER             (_PR_MD_WAKEUP_WAITER)
00410 
00411 /* --- CVar ------------------- */
00412 #define _MD_WAIT_CV                                (_PR_MD_WAIT_CV)
00413 #define _MD_NEW_CV                                 (_PR_MD_NEW_CV)
00414 #define _MD_FREE_CV                                (_PR_MD_FREE_CV)
00415 #define _MD_NOTIFY_CV                              (_PR_MD_NOTIFY_CV  )
00416 #define _MD_NOTIFYALL_CV                    (_PR_MD_NOTIFYALL_CV)
00417 
00418    /* XXXMB- the IOQ stuff is certainly not working correctly yet. */
00419 /* extern  struct _MDLock              _pr_ioq_lock; */
00420 #define _MD_IOQ_LOCK()                
00421 #define _MD_IOQ_UNLOCK()              
00422 
00423 
00424 /* --- Initialization stuff --- */
00425 #define _MD_START_INTERRUPTS()
00426 #define _MD_STOP_INTERRUPTS()
00427 #define _MD_DISABLE_CLOCK_INTERRUPTS()
00428 #define _MD_ENABLE_CLOCK_INTERRUPTS()
00429 #define _MD_BLOCK_CLOCK_INTERRUPTS()
00430 #define _MD_UNBLOCK_CLOCK_INTERRUPTS()
00431 #define _MD_EARLY_INIT                (_PR_MD_EARLY_INIT)
00432 #define _MD_FINAL_INIT()
00433 #define _MD_INIT_CPUS()
00434 #define _MD_INIT_RUNNING_CPU(cpu)
00435 
00436 struct PRProcess;
00437 struct PRProcessAttr;
00438 
00439 #define _MD_CREATE_PROCESS _PR_CreateOS2Process
00440 extern struct PRProcess * _PR_CreateOS2Process(
00441     const char *path,
00442     char *const *argv,
00443     char *const *envp,
00444     const struct PRProcessAttr *attr
00445 );
00446 
00447 #define _MD_DETACH_PROCESS _PR_DetachOS2Process
00448 extern PRStatus _PR_DetachOS2Process(struct PRProcess *process);
00449 
00450 /* --- Wait for a child process to terminate --- */
00451 #define _MD_WAIT_PROCESS _PR_WaitOS2Process
00452 extern PRStatus _PR_WaitOS2Process(struct PRProcess *process, 
00453     PRInt32 *exitCode);
00454 
00455 #define _MD_KILL_PROCESS _PR_KillOS2Process
00456 extern PRStatus _PR_KillOS2Process(struct PRProcess *process);
00457 
00458 #define _MD_CLEANUP_BEFORE_EXIT()
00459 #define _MD_EXIT                          (_PR_MD_EXIT)
00460 #define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
00461     PR_BEGIN_MACRO \
00462     *status = PR_TRUE; \
00463     PR_END_MACRO
00464 #define _MD_SWITCH_CONTEXT
00465 #define _MD_RESTORE_CONTEXT
00466 
00467 /* --- Intervals --- */
00468 #define _MD_INTERVAL_INIT                 (_PR_MD_INTERVAL_INIT)
00469 #define _MD_GET_INTERVAL                  (_PR_MD_GET_INTERVAL)
00470 #define _MD_INTERVAL_PER_SEC              (_PR_MD_INTERVAL_PER_SEC)
00471 #define _MD_INTERVAL_PER_MILLISEC()       (_PR_MD_INTERVAL_PER_SEC() / 1000)
00472 #define _MD_INTERVAL_PER_MICROSEC()       (_PR_MD_INTERVAL_PER_SEC() / 1000000)
00473 
00474 /* --- Native-Thread Specific Definitions ------------------------------- */
00475 
00476 typedef struct __NSPR_TLS
00477 {
00478     struct PRThread  *_pr_thread_last_run;
00479     struct PRThread  *_pr_currentThread;
00480     struct _PRCPU    *_pr_currentCPU;
00481 } _NSPR_TLS;
00482 
00483 extern _NSPR_TLS*  pThreadLocalStorage;
00484 NSPR_API(void) _PR_MD_ENSURE_TLS(void);
00485 
00486 #define _MD_GET_ATTACHED_THREAD() pThreadLocalStorage->_pr_currentThread
00487 extern struct PRThread * _MD_CURRENT_THREAD(void);
00488 #define _MD_SET_CURRENT_THREAD(_thread) _PR_MD_ENSURE_TLS(); pThreadLocalStorage->_pr_currentThread = (_thread)
00489 
00490 #define _MD_LAST_THREAD() pThreadLocalStorage->_pr_thread_last_run
00491 #define _MD_SET_LAST_THREAD(_thread) _PR_MD_ENSURE_TLS(); pThreadLocalStorage->_pr_thread_last_run = (_thread)
00492 
00493 #define _MD_CURRENT_CPU() pThreadLocalStorage->_pr_currentCPU
00494 #define _MD_SET_CURRENT_CPU(_cpu) _PR_MD_ENSURE_TLS(); pThreadLocalStorage->_pr_currentCPU = (_cpu)
00495 
00496 /* lth. #define _MD_SET_INTSOFF(_val) (_pr_ints_off = (_val)) */
00497 /* lth. #define _MD_GET_INTSOFF() _pr_ints_off */
00498 /* lth. #define _MD_INCREMENT_INTSOFF() (_pr_ints_off++) */
00499 /* lth. #define _MD_DECREMENT_INTSOFF() (_pr_ints_off--) */
00500 
00501 /* --- Scheduler stuff --- */
00502 #define LOCK_SCHEDULER()                 0
00503 #define UNLOCK_SCHEDULER()               0
00504 #define _PR_LockSched()                    0
00505 #define _PR_UnlockSched()                0
00506 
00507 /* --- Initialization stuff --- */
00508 #define _MD_INIT_LOCKS()
00509 
00510 /* --- Stack stuff --- */
00511 #define _MD_INIT_STACK(stack, redzone)
00512 #define _MD_CLEAR_STACK(stack)
00513 
00514 /* --- Memory-mapped files stuff --- not implemented on OS/2 */
00515 
00516 struct _MDFileMap {
00517     PRInt8 unused;
00518 };
00519 
00520 extern PRStatus _MD_CreateFileMap(struct PRFileMap *fmap, PRInt64 size);
00521 #define _MD_CREATE_FILE_MAP _MD_CreateFileMap
00522 
00523 extern PRInt32 _MD_GetMemMapAlignment(void);
00524 #define _MD_GET_MEM_MAP_ALIGNMENT _MD_GetMemMapAlignment
00525 
00526 extern void * _MD_MemMap(struct PRFileMap *fmap, PRInt64 offset,
00527         PRUint32 len);
00528 #define _MD_MEM_MAP _MD_MemMap
00529 
00530 extern PRStatus _MD_MemUnmap(void *addr, PRUint32 size);
00531 #define _MD_MEM_UNMAP _MD_MemUnmap
00532 
00533 extern PRStatus _MD_CloseFileMap(struct PRFileMap *fmap);
00534 #define _MD_CLOSE_FILE_MAP _MD_CloseFileMap
00535 
00536 /* Some stuff for setting up thread contexts */
00537 typedef ULONG DWORD, *PDWORD;
00538 
00539 /* The following definitions and two structures are new in OS/2 Warp 4.0.
00540  */
00541 #ifndef CONTEXT_CONTROL
00542 #define CONTEXT_CONTROL        0x00000001
00543 #define CONTEXT_INTEGER        0x00000002
00544 #define CONTEXT_SEGMENTS       0x00000004
00545 #define CONTEXT_FLOATING_POINT 0x00000008
00546 #define CONTEXT_FULL           0x0000000F
00547 
00548 #pragma pack(2)
00549 typedef struct _FPREG {
00550     ULONG      losig;    /*  Low 32-bits of the significand. */
00551     ULONG      hisig;    /*  High 32-bits of the significand. */
00552     USHORT     signexp;  /*  Sign and exponent. */
00553 } FPREG;
00554 typedef struct _CONTEXTRECORD {
00555     ULONG     ContextFlags;
00556     ULONG     ctx_env[7];
00557     FPREG     ctx_stack[8];
00558     ULONG     ctx_SegGs;     /*  GS register. */
00559     ULONG     ctx_SegFs;     /*  FS register. */
00560     ULONG     ctx_SegEs;     /*  ES register. */
00561     ULONG     ctx_SegDs;     /*  DS register. */
00562     ULONG     ctx_RegEdi;    /*  EDI register. */
00563     ULONG     ctx_RegEsi;    /*  ESI register. */
00564     ULONG     ctx_RegEax;    /*  EAX register. */
00565     ULONG     ctx_RegEbx;    /*  EBX register. */
00566     ULONG     ctx_RegEcx;    /*  ECX register. */
00567     ULONG     ctx_RegEdx;    /*  EDX register. */
00568     ULONG     ctx_RegEbp;    /*  EBP register. */
00569     ULONG     ctx_RegEip;    /*  EIP register. */
00570     ULONG     ctx_SegCs;     /*  CS register. */
00571     ULONG     ctx_EFlags;    /*  EFLAGS register. */
00572     ULONG     ctx_RegEsp;    /*  ESP register. */
00573     ULONG     ctx_SegSs;     /*  SS register. */
00574 } CONTEXTRECORD, *PCONTEXTRECORD;
00575 #pragma pack()
00576 #endif
00577 
00578 extern APIRET (* APIENTRY QueryThreadContext)(TID, ULONG, PCONTEXTRECORD);
00579 
00580 /*
00581 #define _pr_tid            (((PTIB2)_getTIBvalue(offsetof(TIB, tib_ptib2)))->tib2_ultid)
00582 #define _pr_current_Thread (_system_tls[_pr_tid-1].__pr_current_thread)
00583 */
00584 
00585 /* Some simple mappings of Windows API's to OS/2 API's to make our lives a
00586  * little bit easier.  Only add one here if it is a DIRECT mapping.  We are
00587  * not emulating anything.  Just mapping.
00588  */
00589 #define FreeLibrary(x) DosFreeModule((HMODULE)x)
00590 #define OutputDebugString(x)
00591                                
00592 extern int _MD_os2_get_nonblocking_connect_error(int osfd);
00593 
00594 #endif /* nspr_os2_defs_h___ */