Warpzilla patches OS2_BRANCH
authorlaw
Wed, 08 Apr 1998 01:53:17 +0000
branchOS2_BRANCH
changeset 13 d9af9428853b33769372eefe6225dc1cec03a0c3
parent 12 edd5af52a26f7d2c90583bdb53d43b0e74f817d5
child 14 f6f203ac0be2bbae6c372b54b3b7a4ff5178a830
push idunknown
push userunknown
push dateunknown
Warpzilla patches
pr/include/md/_os2.h
pr/include/md/_os2_errors.h
pr/include/md/_pcos.h
pr/src/linking/prlink.c
pr/src/md/os2/Makefile
pr/src/md/os2/os2_errors.c
pr/src/md/os2/os2cv.c
pr/src/md/os2/os2gc.c
pr/src/md/os2/os2inrval.c
pr/src/md/os2/os2io.c
pr/src/md/os2/os2misc.c
pr/src/md/os2/os2poll.c
pr/src/md/os2/os2sock.c
pr/src/md/os2/os2thred.c
--- a/pr/include/md/_os2.h
+++ b/pr/include/md/_os2.h
@@ -25,29 +25,37 @@
 #define INCL_WPS
 #include <os2.h>
 #include <sys/select.h>
 
 #include "prio.h"
 
 #include <errno.h>
 
+#ifdef XP_OS2_EMX
+/*
+ * EMX-specific tweaks:
+ *    o Use stricmp instead of strcmpi.
+ */
+#define strcmpi stricmp 
+#endif
+
 /*
  * Internal configuration macros
  */
 
 #define PR_LINKER_ARCH      "os2"
 #define _PR_SI_SYSNAME        "OS2"
 #define _PR_SI_ARCHITECTURE   "x86"    /* XXXMB hardcode for now */
 
 #define HAVE_DLL
 #undef  HAVE_THREAD_AFFINITY
 #define HAVE_SOCKET_REUSEADDR
 #define HAVE_SOCKET_KEEPALIVE
-#define _PR_HAVE_ATOMIC_OPS
+#undef  _PR_HAVE_ATOMIC_OPS
 
 #define HANDLE unsigned long
 #define HINSTANCE HMODULE
 
 /* --- Common User-Thread/Native-Thread Definitions --------------------- */
 
 /* --- Globals --- */
 extern struct PRLock                      *_pr_schedLock;
@@ -128,17 +136,17 @@ struct _MDNotified {
         struct _MDCVar *cv;            /* the condition variable notified */
         PRIntn times;                  /* and the number of times notified */
         struct PRThread *notifyHead;   /* list of threads to wake up */
     } cv[_MD_CV_NOTIFIED_LENGTH];
     _MDNotified *link;                 /* link to another of these, or NULL */
 };
 
 struct _MDLock {
-    CRITICAL_SECTION mutex;          /* this is recursive on NT */
+    HMTX mutex;          /* this is recursive on NT */
 
     /*
      * When notifying cvars, there is no point in actually
      * waking up the threads waiting on the cvars until we've
      * released the lock.  So, we temporarily record the cvars.
      * When doing an unlock, we'll then wake up the waiting threads.
      */
     struct _MDNotified notified;     /* array of conditions notified */
@@ -162,38 +170,45 @@ struct _MDProcess {
    PID pid;
 };
 
 /* --- Misc stuff --- */
 #define _MD_GET_SP(thread)            (thread)->md.gcContext[6]
 
 /* --- IO stuff --- */
 
-#define _MD_OPEN                      _PR_MD_OPEN
-#define _MD_READ                      _PR_MD_READ
-#define _MD_WRITE                     _PR_MD_WRITE
-#define _MD_WRITEV                    _PR_MD_WRITEV
-#define _MD_LSEEK                     _PR_MD_LSEEK
-#define _MD_LSEEK64                   _PR_MD_LSEEK64
+#define _MD_OPEN                      (_PR_MD_OPEN)
+#define _MD_READ                      (_PR_MD_READ)
+#define _MD_WRITE                     (_PR_MD_WRITE)
+#define _MD_WRITEV                    (_PR_MD_WRITEV)
+#define _MD_LSEEK                     (_PR_MD_LSEEK)
+#define _MD_LSEEK64                   (_PR_MD_LSEEK64)
 extern PRInt32 _MD_CloseFile(PRInt32 osfd);
 #define _MD_CLOSE_FILE                _MD_CloseFile
-#define _MD_GETFILEINFO               _PR_MD_GETFILEINFO
-#define _MD_GETOPENFILEINFO           _PR_MD_GETOPENFILEINFO
-#define _MD_GETOPENFILEINFO64(a, b)   _PR_MD_GETOPENFILEINFO64(a, b)
-#define _MD_STAT                      _PR_MD_STAT
-#define _MD_RENAME                    _PR_MD_RENAME     
-#define _MD_ACCESS                    _PR_MD_ACCESS     
-#define _MD_DELETE                    _PR_MD_DELETE     
-#define _MD_MKDIR                     _PR_MD_MKDIR      
-#define _MD_RMDIR                     _PR_MD_RMDIR      
-#define _MD_LOCKFILE                  _PR_MD_LOCKFILE
-#define _MD_TLOCKFILE                 _PR_MD_TLOCKFILE
-#define _MD_UNLOCKFILE                _PR_MD_UNLOCKFILE
+#define _MD_GETFILEINFO               (_PR_MD_GETFILEINFO)
+#define _MD_GETFILEINFO64             (_PR_MD_GETFILEINFO64)
+#define _MD_GETOPENFILEINFO           (_PR_MD_GETOPENFILEINFO)
+#define _MD_GETOPENFILEINFO64         (_PR_MD_GETOPENFILEINFO64)
+#define _MD_STAT                      (_PR_MD_STAT)
+#define _MD_RENAME                    (_PR_MD_RENAME)
+#define _MD_ACCESS                    (_PR_MD_ACCESS)
+#define _MD_DELETE                    (_PR_MD_DELETE)
+#define _MD_MKDIR                     (_PR_MD_MKDIR)
+#define _MD_RMDIR                     (_PR_MD_RMDIR)
+#define _MD_LOCKFILE                  (_PR_MD_LOCKFILE)
+#define _MD_TLOCKFILE                 (_PR_MD_TLOCKFILE)
+#define _MD_UNLOCKFILE                (_PR_MD_UNLOCKFILE)
 
 /* --- Socket IO stuff --- */
+
+/* The ones that don't map directly may need to be re-visited... */
+#ifdef XP_OS2_VACPP
+#define EPIPE                     EBADF
+#define EIO                       ECONNREFUSED
+#endif
 #define _MD_EACCES                EACCES
 #define _MD_EADDRINUSE            EADDRINUSE
 #define _MD_EADDRNOTAVAIL         EADDRNOTAVAIL
 #define _MD_EAFNOSUPPORT          EAFNOSUPPORT
 #define _MD_EAGAIN                EWOULDBLOCK
 #define _MD_EALREADY              EALREADY
 #define _MD_EBADF                 EBADF
 #define _MD_ECONNREFUSED          ECONNREFUSED
@@ -211,134 +226,130 @@ extern PRInt32 _MD_CloseFile(PRInt32 osf
 #define _MD_EWOULDBLOCK           EWOULDBLOCK
 #define _MD_GET_SOCKET_ERROR()    sock_errno()
 #ifndef INADDR_LOOPBACK /* For some reason this is not defined in OS2 tcpip */
 /*  #define INADDR_LOOPBACK         INADDR_ANY */
 #endif  
 
 extern void _MD_MakeNonblock(PRFileDesc *f);
 #define _MD_MAKE_NONBLOCK             _MD_MakeNonblock
-#define _MD_SHUTDOWN                  _PR_MD_SHUTDOWN
+#define _MD_SHUTDOWN                  (_PR_MD_SHUTDOWN)
 #define _MD_LISTEN(s, backlog)        listen(s->secret->md.osfd,backlog)
 extern PRInt32 _MD_CloseSocket(PRInt32 osfd);
 #define _MD_CLOSE_SOCKET              _MD_CloseSocket
-#define _MD_SENDTO                    _PR_MD_SENDTO
-#define _MD_RECVFROM                  _PR_MD_RECVFROM
+#define _MD_SENDTO                    (_PR_MD_SENDTO)
+#define _MD_RECVFROM                  (_PR_MD_RECVFROM)
 #define _MD_SOCKETPAIR(s, type, proto, sv) -1
-#define _MD_GETSOCKNAME               _PR_MD_GETSOCKNAME
-#define _MD_GETPEERNAME               _PR_MD_GETPEERNAME
-#define _MD_GETSOCKOPT                _PR_MD_GETSOCKOPT
-#define _MD_SETSOCKOPT                _PR_MD_SETSOCKOPT
+#define _MD_GETSOCKNAME               (_PR_MD_GETSOCKNAME)
+#define _MD_GETPEERNAME               (_PR_MD_GETPEERNAME)
+#define _MD_GETSOCKOPT                (_PR_MD_GETSOCKOPT)
+#define _MD_SETSOCKOPT                (_PR_MD_SETSOCKOPT)
 #define _MD_SELECT                    select
-#define _MD_FSYNC                     _PR_MD_FSYNC
+#define _MD_FSYNC                     (_PR_MD_FSYNC)
 
-long _System InterlockedIncrement(PLONG);
-long _System InterlockedDecrement(PLONG);
-long _System InterlockedExchange(PLONG, LONG);
+#define _MD_INIT_ATOMIC               (_MD_INIT_ATOMIC)
+#define _MD_ATOMIC_INCREMENT          (_MD_ATOMIC_INCREMENT)
+#define _MD_ATOMIC_DECREMENT          (_MD_ATOMIC_DECREMENT)
+#define _MD_ATOMIC_SET                (_MD_ATOMIC_SET)
 
-#define _MD_INIT_ATOMIC()
-#define _MD_ATOMIC_INCREMENT(x)       InterlockedIncrement((PLONG)x)
-#define _MD_ATOMIC_DECREMENT(x)       InterlockedDecrement((PLONG)x)
-#define _MD_ATOMIC_SET(x,y)           InterlockedExchange((PLONG)x, (LONG)y)
-
-#define _MD_INIT_IO                   _PR_MD_INIT_IO
-#define _MD_TRANSMITFILE              _PR_MD_TRANSMITFILE
-
+#define _MD_INIT_IO                   (_PR_MD_INIT_IO)
+#define _MD_TRANSMITFILE              (_PR_MD_TRANSMITFILE)
+#define _MD_PR_POLL                   (_PR_MD_PR_POLL)
 
 /* win95 doesn't have async IO */
-#define _MD_SOCKET                    _PR_MD_SOCKET
+#define _MD_SOCKET                    (_PR_MD_SOCKET)
 extern PRInt32 _MD_SocketAvailable(PRFileDesc *fd);
 #define _MD_SOCKETAVAILABLE           _MD_SocketAvailable
-#define _MD_CONNECT                   _PR_MD_CONNECT
+#define _MD_CONNECT                   (_PR_MD_CONNECT)
 extern PRInt32 _MD_Accept(PRFileDesc *fd, PRNetAddr *raddr, PRUint32 *rlen,
         PRIntervalTime timeout);
 #define _MD_ACCEPT                    _MD_Accept
-#define _MD_BIND                      _PR_MD_BIND
-#define _MD_RECV                      _PR_MD_RECV
-#define _MD_SEND                      _PR_MD_SEND
+#define _MD_BIND                      (_PR_MD_BIND)
+#define _MD_RECV                      (_PR_MD_RECV)
+#define _MD_SEND                      (_PR_MD_SEND)
 
 /* --- Scheduler stuff --- */
 /* #define _MD_PAUSE_CPU                 _PR_MD_PAUSE_CPU */
 #define _MD_PAUSE_CPU
 
 /* --- DIR stuff --- */
 #define PR_DIRECTORY_SEPARATOR        '\\'
 #define PR_DIRECTORY_SEPARATOR_STR    "\\"
 #define PR_PATH_SEPARATOR		';'
 #define PR_PATH_SEPARATOR_STR		";"
 #define _MD_ERRNO()                   errno
-#define _MD_OPEN_DIR                  _PR_MD_OPEN_DIR
-#define _MD_CLOSE_DIR                 _PR_MD_CLOSE_DIR
-#define _MD_READ_DIR                  _PR_MD_READ_DIR
+#define _MD_OPEN_DIR                  (_PR_MD_OPEN_DIR)
+#define _MD_CLOSE_DIR                 (_PR_MD_CLOSE_DIR)
+#define _MD_READ_DIR                  (_PR_MD_READ_DIR)
 
 /* --- Segment stuff --- */
 #define _MD_INIT_SEGS()
 #define _MD_ALLOC_SEGMENT(seg, size, vaddr)   0
 #define _MD_FREE_SEGMENT(seg)
 
 /* --- Environment Stuff --- */
-#define _MD_GET_ENV                 _PR_MD_GET_ENV
-#define _MD_PUT_ENV                 _PR_MD_PUT_ENV
+#define _MD_GET_ENV                 (_PR_MD_GET_ENV)
+#define _MD_PUT_ENV                 (_PR_MD_PUT_ENV)
 
 /* --- Threading Stuff --- */
 #define _MD_DEFAULT_STACK_SIZE      32767L
-#define _MD_INIT_THREAD             _PR_MD_INIT_THREAD
-#define _MD_INIT_ATTACHED_THREAD    _PR_MD_INIT_THREAD
-#define _MD_INIT_PRIMORDIAL_THREAD  _PR_MD_INIT_PRIMORDIAL_THREAD
-#define _MD_CREATE_THREAD           _PR_MD_CREATE_THREAD
-#define _MD_YIELD                   _PR_MD_YIELD
-#define _MD_SET_PRIORITY            _PR_MD_SET_PRIORITY
-#define _MD_CLEAN_THREAD            _PR_MD_CLEAN_THREAD
-#define _MD_SETTHREADAFFINITYMASK   _PR_MD_SETTHREADAFFINITYMASK
-#define _MD_GETTHREADAFFINITYMASK   _PR_MD_GETTHREADAFFINITYMASK
-#define _MD_EXIT_THREAD             _PR_MD_EXIT_THREAD
-#define _MD_SUSPEND_THREAD          _PR_MD_SUSPEND_THREAD
-#define _MD_RESUME_THREAD           _PR_MD_RESUME_THREAD
-#define _MD_SUSPEND_CPU             _PR_MD_SUSPEND_CPU
-#define _MD_RESUME_CPU              _PR_MD_RESUME_CPU
-#define _MD_WAKEUP_CPUS             _PR_MD_WAKEUP_CPUS
+#define _MD_INIT_THREAD             (_PR_MD_INIT_THREAD)
+#define _MD_INIT_ATTACHED_THREAD    (_PR_MD_INIT_THREAD)
+#define _MD_INIT_PRIMORDIAL_THREAD  (_PR_MD_INIT_PRIMORDIAL_THREAD)
+#define _MD_CREATE_THREAD           (_PR_MD_CREATE_THREAD)
+#define _MD_YIELD                   (_PR_MD_YIELD)
+#define _MD_SET_PRIORITY            (_PR_MD_SET_PRIORITY)
+#define _MD_CLEAN_THREAD            (_PR_MD_CLEAN_THREAD)
+#define _MD_SETTHREADAFFINITYMASK   (_PR_MD_SETTHREADAFFINITYMASK)
+#define _MD_GETTHREADAFFINITYMASK   (_PR_MD_GETTHREADAFFINITYMASK)
+#define _MD_EXIT_THREAD             (_PR_MD_EXIT_THREAD)
+#define _MD_SUSPEND_THREAD          (_PR_MD_SUSPEND_THREAD)
+#define _MD_RESUME_THREAD           (_PR_MD_RESUME_THREAD)
+#define _MD_SUSPEND_CPU             (_PR_MD_SUSPEND_CPU)
+#define _MD_RESUME_CPU              (_PR_MD_RESUME_CPU)
+#define _MD_WAKEUP_CPUS             (_PR_MD_WAKEUP_CPUS)
 #define _MD_BEGIN_SUSPEND_ALL()
 #define _MD_BEGIN_RESUME_ALL()
 #define _MD_END_SUSPEND_ALL()
 #define _MD_END_RESUME_ALL()
 
 /* --- Lock stuff --- */
 #define _PR_LOCK                      _MD_LOCK
 #define _PR_UNLOCK					  _MD_UNLOCK
 
-#define _MD_NEW_LOCK(lock)            (InitializeCriticalSection(&((lock)->mutex)),(lock)->notified.length=0,(lock)->notified.link=NULL,PR_SUCCESS)
-#define _MD_FREE_LOCK(lock)           DeleteCriticalSection(&((lock)->mutex))
-#define _MD_LOCK(lock)                EnterCriticalSection(&((lock)->mutex))
-#define _MD_TEST_AND_LOCK(lock)       (EnterCriticalSection(&((lock)->mutex)),PR_SUCCESS)
-#define _MD_UNLOCK                    _PR_MD_UNLOCK
+#define _MD_NEW_LOCK(lock)            (DosCreateMutexSem(0, &((lock)->mutex), 0, 0),(lock)->notified.length=0,(lock)->notified.link=NULL,PR_SUCCESS)
+#define _MD_FREE_LOCK(lock)           DosCloseMutexSem(((lock)->mutex))
+#define _MD_LOCK(lock)                DosRequestMutexSem(((lock)->mutex), SEM_INDEFINITE_WAIT)
+#define _MD_TEST_AND_LOCK(lock)       (DosRequestMutexSem(((lock)->mutex), SEM_INDEFINITE_WAIT),PR_SUCCESS)
+#define _MD_UNLOCK                    (_PR_MD_UNLOCK)
 
 /* --- lock and cv waiting --- */
-#define _MD_WAIT                      _PR_MD_WAIT
-#define _MD_WAKEUP_WAITER             _PR_MD_WAKEUP_WAITER
+#define _MD_WAIT                      (_PR_MD_WAIT)
+#define _MD_WAKEUP_WAITER             (_PR_MD_WAKEUP_WAITER)
 
 /* --- CVar ------------------- */
-#define _MD_WAIT_CV					  _PR_MD_WAIT_CV
-#define _MD_NEW_CV					  _PR_MD_NEW_CV
-#define _MD_FREE_CV					  _PR_MD_FREE_CV
-#define _MD_NOTIFY_CV				  _PR_MD_NOTIFY_CV	
-#define _MD_NOTIFYALL_CV			  _PR_MD_NOTIFYALL_CV
+#define _MD_WAIT_CV					  (_PR_MD_WAIT_CV)
+#define _MD_NEW_CV					  (_PR_MD_NEW_CV)
+#define _MD_FREE_CV					  (_PR_MD_FREE_CV)
+#define _MD_NOTIFY_CV				  (_PR_MD_NOTIFY_CV	)
+#define _MD_NOTIFYALL_CV			  (_PR_MD_NOTIFYALL_CV)
 
    /* XXXMB- the IOQ stuff is certainly not working correctly yet. */
 /* extern  struct _MDLock              _pr_ioq_lock; */
 #define _MD_IOQ_LOCK()                
 #define _MD_IOQ_UNLOCK()              
 
 
 /* --- Initialization stuff --- */
 #define _MD_START_INTERRUPTS()
 #define _MD_STOP_INTERRUPTS()
 #define _MD_DISABLE_CLOCK_INTERRUPTS()
 #define _MD_BLOCK_CLOCK_INTERRUPTS()
 #define _MD_UNBLOCK_CLOCK_INTERRUPTS()
-#define _MD_EARLY_INIT                _PR_MD_EARLY_INIT
+#define _MD_EARLY_INIT                (_PR_MD_EARLY_INIT)
 #define _MD_FINAL_INIT()
 #define _MD_INIT_CPUS()
 #define _MD_INIT_RUNNING_CPU(cpu)
 
 struct PRProcess;
 struct PRProcessAttr;
 
 #define _MD_CREATE_PROCESS _PR_CreateOS2Process
@@ -361,33 +372,33 @@ extern PRStatus _PR_WaitOS2Process(struc
 extern PRStatus _PR_KillOS2Process(struct PRProcess *process);
 
 #define _MD_CLEANUP_BEFORE_EXIT()
 #define _MD_INIT_CONTEXT
 #define _MD_SWITCH_CONTEXT
 #define _MD_RESTORE_CONTEXT
 
 /* --- Intervals --- */
-#define _MD_INTERVAL_INIT                 _PR_MD_INTERVAL_INIT
-#define _MD_GET_INTERVAL                  _PR_MD_GET_INTERVAL
-#define _MD_INTERVAL_PER_SEC              _PR_MD_INTERVAL_PER_SEC
+#define _MD_INTERVAL_INIT                 (_PR_MD_INTERVAL_INIT)
+#define _MD_GET_INTERVAL                  (_PR_MD_GET_INTERVAL)
+#define _MD_INTERVAL_PER_SEC              (_PR_MD_INTERVAL_PER_SEC)
 #define _MD_INTERVAL_PER_MILLISEC()       (_PR_MD_INTERVAL_PER_SEC() / 1000)
 #define _MD_INTERVAL_PER_MICROSEC()       (_PR_MD_INTERVAL_PER_SEC() / 1000000)
 
 /* --- Native-Thread Specific Definitions ------------------------------- */
 
 typedef struct __NSPR_TLS
 {
-    PRThread  *_pr_thread_last_run;
-    PRThread  *_pr_currentThread;
+    struct PRThread  *_pr_thread_last_run;
+    struct PRThread  *_pr_currentThread;
     struct _PRCPU    *_pr_currentCPU;
 } _NSPR_TLS;
 
 extern _NSPR_TLS*  pThreadLocalStorage;
-PR_IMPLEMENT(void) _PR_MD_ENSURE_TLS();
+PR_EXTERN(void) _PR_MD_ENSURE_TLS(void);
 
 #define _MD_CURRENT_THREAD() pThreadLocalStorage->_pr_currentThread
 #define _MD_SET_CURRENT_THREAD(_thread) _PR_MD_ENSURE_TLS(); pThreadLocalStorage->_pr_currentThread = (_thread)
 
 #define _MD_LAST_THREAD() pThreadLocalStorage->_pr_thread_last_run
 #define _MD_SET_LAST_THREAD(_thread) _PR_MD_ENSURE_TLS(); pThreadLocalStorage->_pr_thread_last_run = (_thread)
 
 #define _MD_CURRENT_CPU() pThreadLocalStorage->_pr_currentCPU
@@ -479,10 +490,11 @@ extern APIRET (* APIENTRY QueryThreadCon
 #define _pr_current_Thread (_system_tls[_pr_tid-1].__pr_current_thread)
 */
 
 /* Some simple mappings of Windows API's to OS/2 API's to make our lives a
  * little bit easier.  Only add one here if it is a DIRECT mapping.  We are
  * not emulating anything.  Just mapping.
  */
 #define FreeLibrary(x) DosFreeModule(x)
+#define OutputDebugString(x)
                                
 #endif /* nspr_os2_defs_h___ */
--- a/pr/include/md/_os2_errors.h
+++ b/pr/include/md/_os2_errors.h
@@ -16,17 +16,19 @@
  * Reserved.
  */
 
 #ifndef nspr_os2_errors_h___
 #define nspr_os2_errors_h___
 
 #include "md/_os2.h"
 #include <assert.h>
+#ifdef XP_OS2_VACPP
 #include <nerrno.h>
+#endif
 
 PR_EXTERN(void) _MD_os2_map_opendir_error(PRInt32 err);
 #define	_PR_MD_MAP_OPENDIR_ERROR	_MD_os2_map_opendir_error
 
 PR_EXTERN(void) _MD_os2_map_closedir_error(PRInt32 err);
 #define	_PR_MD_MAP_CLOSEDIR_ERROR	_MD_os2_map_closedir_error
 
 PR_EXTERN(void) _MD_unix_readdir_error(PRInt32 err);
--- a/pr/include/md/_pcos.h
+++ b/pr/include/md/_pcos.h
@@ -55,16 +55,19 @@ PR_END_EXTERN_C
 /*
 ** Definitions of directory structures amd functions
 ** These definitions are from:
 **      <dirent.h>
 */
 #ifdef MOZ_BITS
 #include <time.h>
 #endif
+#ifdef XP_OS2_EMX
+#include <sys/types.h>
+#endif
 #include <sys/stat.h>
 #include <io.h>
 #include <fcntl.h>          /* O_BINARY */
 
 typedef int PROSFD;
 
 /*
 ** Undo the macro define in the Microsoft header files...
--- a/pr/src/linking/prlink.c
+++ b/pr/src/linking/prlink.c
@@ -423,24 +423,21 @@ PR_LoadLibrary(const char *name)
     if (result != NULL) goto unlock;
 
     lm = PR_NEWZAP(PRLibrary);
     if (lm == NULL) goto unlock;
     lm->staticTable = NULL;
 
 #ifdef XP_OS2  /* Why isn't all this stuff in MD code?! */
     {
-        NODL_PROC *pfn;
         HMODULE h;
         UCHAR pszError[_MAX_PATH];
         ULONG ulRc = NO_ERROR;
-        int first_try = 1;
 
-        retry:
-              ulRc = DosLoadModule(pszError, _MAX_PATH, (PSZ) name, &h);
+        ulRc = DosLoadModule(pszError, _MAX_PATH, (PSZ) name, &h);
       	if (ulRc != NO_ERROR) {
       	    PR_DELETE(lm);
       	    goto unlock;
       	}
       	lm->name = strdup(name);
       	lm->dlh  = h;
       	lm->next = pr_loadmap;
       	pr_loadmap = lm;
--- a/pr/src/md/os2/Makefile
+++ b/pr/src/md/os2/Makefile
@@ -38,14 +38,13 @@ endif
 
 TARGETS	= $(OBJS)
 
 INCLUDES = -I$(DIST)/include/private -I$(DIST)/include
 
 include $(MOD_DEPTH)/config/rules.mk
 
 export:: $(TARGETS)
-	@cmd /C "copy *.obj $(OBJDIR)\*.o > nul"
 
 install:: export
 
 
 
--- a/pr/src/md/os2/os2_errors.c
+++ b/pr/src/md/os2/os2_errors.c
@@ -357,19 +357,21 @@ void _MD_os2_map_read_error(PRInt32 err)
 			PR_SetError(PR_CONNECT_RESET_ERROR, err);
 			break;
 		case EBADF:
 			PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
 			break; 
 		case ENOTSOCK:
 			PR_SetError(PR_NOT_SOCKET_ERROR, err);
 			break;
+#ifdef SOCEFAULT
 		case SOCEFAULT:
 			PR_SetError(PR_ACCESS_FAULT_ERROR, err);
 			break;
+#endif
 		default:
 			PR_SetError(PR_UNKNOWN_ERROR, err);
 			break;
 	}
 }
 
 void _MD_os2_map_transmitfile_error(PRInt32 err)
 {
@@ -406,19 +408,21 @@ void _MD_os2_map_transmitfile_error(PRIn
 			PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
 			break;
 		case EBADF:
 			PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
 			break;
 		case ENOTSOCK:
 			PR_SetError(PR_NOT_SOCKET_ERROR, err);
 			break;
+#ifdef SOCEFAULT
 		case SOCEFAULT:
 			PR_SetError(PR_ACCESS_FAULT_ERROR, err);
 			break;
+#endif
 		default:
 			PR_SetError(PR_UNKNOWN_ERROR, err);
 			break;
 	}
 }
 
 void _MD_os2_map_write_error(PRInt32 err)
 {
@@ -466,19 +470,21 @@ void _MD_os2_map_write_error(PRInt32 err
 			PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
 			break;
 		case ECONNREFUSED:
 			PR_SetError(PR_CONNECT_REFUSED_ERROR, err);
 			break;
 		case EISCONN:
 			PR_SetError(PR_IS_CONNECTED_ERROR, err);
 			break;
+#ifdef SOCEFAULT
 		case SOCEFAULT:
 			PR_SetError(PR_ACCESS_FAULT_ERROR, err);
 			break;
+#endif
 		default:
 			PR_SetError(PR_UNKNOWN_ERROR, err);
 			break;
 	}
 }
 
 void _MD_os2_map_lseek_error(PRInt32 err)
 {
@@ -563,19 +569,21 @@ void _MD_os2_map_recv_error(PRInt32 err)
 			PR_SetError(PR_WOULD_BLOCK_ERROR, err);
 			break;
 		case EBADF:
 			PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
 			break;
 		case ENOTSOCK:
 			PR_SetError(PR_NOT_SOCKET_ERROR, err);
 			break;
+#ifdef SOCEFAULT
 		case SOCEFAULT:
 			PR_SetError(PR_ACCESS_FAULT_ERROR, err);
 			break;
+#endif
 		case ERROR_NETNAME_DELETED:
 			PR_SetError(PR_CONNECT_RESET_ERROR, err);
 			break;
 		default:
 			PR_SetError(PR_UNKNOWN_ERROR, err);
 			break;
 	}
 }
@@ -587,19 +595,21 @@ void _MD_os2_map_recvfrom_error(PRInt32 
 			PR_SetError(PR_WOULD_BLOCK_ERROR, err);
 			break;
 		case EBADF:
 			PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
 			break;
 		case ENOTSOCK:
 			PR_SetError(PR_NOT_SOCKET_ERROR, err);
 			break;
+#ifdef SOCEFAULT
 		case SOCEFAULT:
 			PR_SetError(PR_ACCESS_FAULT_ERROR, err);
 			break;
+#endif
 		case ERROR_NETNAME_DELETED:
 			PR_SetError(PR_CONNECT_RESET_ERROR, err);
 			break;
 		default:
 			PR_SetError(PR_UNKNOWN_ERROR, err);
 			break;
 	}
 }
@@ -624,19 +634,21 @@ void _MD_os2_map_send_error(PRInt32 err)
 			PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
 			break;
 		case ECONNREFUSED:
 			PR_SetError(PR_CONNECT_REFUSED_ERROR, err);
 			break;
 		case EISCONN:
 			PR_SetError(PR_IS_CONNECTED_ERROR, err);
 			break;
+#ifdef SOCEFAULT
 		case SOCEFAULT:
 			PR_SetError(PR_ACCESS_FAULT_ERROR, err);
 			break;
+#endif
 		case ERROR_NETNAME_DELETED:
 			PR_SetError(PR_CONNECT_RESET_ERROR, err);
 			break;
 		default:
 			PR_SetError(PR_UNKNOWN_ERROR, err);
 			break;
 	}
 }
@@ -661,19 +673,21 @@ void _MD_os2_map_sendto_error(PRInt32 er
 			PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
 			break;
 		case ECONNREFUSED:
 			PR_SetError(PR_CONNECT_REFUSED_ERROR, err);
 			break;
 		case EISCONN:
 			PR_SetError(PR_IS_CONNECTED_ERROR, err);
 			break;
+#ifdef SOCEFAULT
 		case SOCEFAULT:
 			PR_SetError(PR_ACCESS_FAULT_ERROR, err);
 			break;
+#endif
 		case ERROR_NETNAME_DELETED:
 			PR_SetError(PR_CONNECT_RESET_ERROR, err);
 			break;
 		default:
 			PR_SetError(PR_UNKNOWN_ERROR, err);
 			break;
 	}
 }
@@ -688,19 +702,21 @@ void _MD_os2_map_accept_error(PRInt32 er
 			PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
 			break;
 		case ENOTSOCK:
 			PR_SetError(PR_NOT_SOCKET_ERROR, err);
 			break;
 		case EOPNOTSUPP:
 			PR_SetError(PR_NOT_TCP_SOCKET_ERROR, err);
 			break;
+#ifdef SOCEFAULT
 		case SOCEFAULT:
 			PR_SetError(PR_ACCESS_FAULT_ERROR, err);
 			break;
+#endif
 		case EMFILE:
 			PR_SetError(PR_PROC_DESC_TABLE_FULL_ERROR, err);
 			break;
 		case ENOBUFS:
 			PR_SetError(PR_OUT_OF_MEMORY_ERROR, err);
 			break;
 		default:
 			PR_SetError(PR_UNKNOWN_ERROR, err);
@@ -760,37 +776,41 @@ void _MD_os2_map_connect_error(PRInt32 e
 			PR_SetError(PR_NETWORK_UNREACHABLE_ERROR, err);
 			break;
 		case EADDRINUSE:
 			PR_SetError(PR_ADDRESS_IN_USE_ERROR, err);
 			break;
       case EISCONN:
          PR_SetError(PR_IS_CONNECTED_ERROR, err);
          break;
+#ifdef SOCEFAULT
 		case SOCEFAULT:
 			PR_SetError(PR_ACCESS_FAULT_ERROR, err);
 			break;
+#endif
 		default:
 			PR_SetError(PR_UNKNOWN_ERROR, err);
 			break;
 	}
 }
 
 void _MD_os2_map_bind_error(PRInt32 err)
 {
 	switch (err) {
 		case EBADF:
 			PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
 			break;
 		case ENOTSOCK:
 			PR_SetError(PR_NOT_SOCKET_ERROR, err);
 			break;
+#ifdef SOCEFAULT
 		case SOCEFAULT:
 			PR_SetError(PR_ACCESS_FAULT_ERROR, err);
 			break;
+#endif
 		case EADDRNOTAVAIL:
 			PR_SetError(PR_ADDRESS_NOT_AVAILABLE_ERROR, err);
 			break;
 		case EADDRINUSE:
 			PR_SetError(PR_ADDRESS_IN_USE_ERROR, err);
 			break;
 		case EACCES:
 			PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
@@ -844,19 +864,21 @@ void _MD_os2_map_getsockname_error(PRInt
 {
 	switch (err) {
 		case EBADF:
 			PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
 			break;
 		case ENOTSOCK:
 			PR_SetError(PR_NOT_SOCKET_ERROR, err);
 			break;
+#ifdef SOCEFAULT
 		case SOCEFAULT:
 			PR_SetError(PR_ACCESS_FAULT_ERROR, err);
 			break;
+#endif
 		case ENOBUFS:
 			PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
 			break;
 		default:
 			PR_SetError(PR_UNKNOWN_ERROR, err);
 			break;
 	}
 }
@@ -869,19 +891,21 @@ void _MD_os2_map_getpeername_error(PRInt
 			PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
 			break;
 		case ENOTSOCK:
 			PR_SetError(PR_NOT_SOCKET_ERROR, err);
 			break;
 		case ENOTCONN:
 			PR_SetError(PR_NOT_CONNECTED_ERROR, err);
 			break;
+#ifdef SOCEFAULT
 		case SOCEFAULT:
 			PR_SetError(PR_ACCESS_FAULT_ERROR, err);
 			break;
+#endif
 		case ENOBUFS:
 			PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
 			break;
 		default:
 			PR_SetError(PR_UNKNOWN_ERROR, err);
 			break;
 	}
 }
@@ -893,19 +917,21 @@ void _MD_os2_map_getsockopt_error(PRInt3
 			PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
 			break;
 		case ENOTSOCK:
 			PR_SetError(PR_NOT_SOCKET_ERROR, err);
 			break;
 		case ENOPROTOOPT:
 			PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
 			break;
+#ifdef SOCEFAULT
 		case SOCEFAULT:
 			PR_SetError(PR_ACCESS_FAULT_ERROR, err);
 			break;
+#endif
 		case EINVAL:
 			PR_SetError(PR_BUFFER_OVERFLOW_ERROR, err);
 			break;
 		default:
 			PR_SetError(PR_UNKNOWN_ERROR, err);
 			break;
 	}
 }
@@ -917,19 +943,21 @@ void _MD_os2_map_setsockopt_error(PRInt3
 			PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
 			break;
 		case ENOTSOCK:
 			PR_SetError(PR_NOT_SOCKET_ERROR, err);
 			break;
 		case ENOPROTOOPT:
 			PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
 			break;
+#ifdef SOCEFAULT
 		case SOCEFAULT:
 			PR_SetError(PR_ACCESS_FAULT_ERROR, err);
 			break;
+#endif
 		case EINVAL:
 			PR_SetError(PR_BUFFER_OVERFLOW_ERROR, err);
 			break;
 		default:
 			PR_SetError(PR_UNKNOWN_ERROR, err);
 			break;
 	}
 }
@@ -985,19 +1013,21 @@ void _MD_os2_map_open_error(PRInt32 err)
 			PR_SetError(PR_UNKNOWN_ERROR, err);
 			break;
 	}
 }
 
 void _MD_os2_map_gethostname_error(PRInt32 err)
 {
     switch (err) {
+#ifdef SOCEFAULT
 		case SOCEFAULT:
 			PR_SetError(PR_ACCESS_FAULT_ERROR, err);
 			break;
+#endif
 		case ENETDOWN:
 		case EINPROGRESS:
 		default:
 			PR_SetError(PR_UNKNOWN_ERROR, err);
 			break;
     }
 }
 
@@ -1011,19 +1041,21 @@ void _MD_os2_map_select_error(PRInt32 er
          * context, ENOTSOCK is equivalent to EBADF on Unix.
          */
         case ENOTSOCK:
             prerror = PR_BAD_DESCRIPTOR_ERROR;
             break;
         case EINVAL:
             prerror = PR_INVALID_ARGUMENT_ERROR;
             break;
+#ifdef SOCEFAULT
         case SOCEFAULT:
             prerror = PR_ACCESS_FAULT_ERROR;
             break;
+#endif
         default:
             prerror = PR_UNKNOWN_ERROR;
     }
     PR_SetError(prerror, err);
 }
 
 void _MD_os2_map_lockf_error(PRInt32 err)
 {
--- a/pr/src/md/os2/os2cv.c
+++ b/pr/src/md/os2/os2cv.c
@@ -142,17 +142,17 @@ md_UnlockAndPostNotifies(
         notified = notified->link;
     } while (NULL != notified);
 
     if (waitThred) {
         AddThreadToCVWaitQueueInternal(waitThred, waitCV);
     }
 
     /* Release the lock before notifying */
-        LeaveCriticalSection(&lock->mutex);
+    DosReleaseMutexSem(lock->mutex);
 
     notified = &post;  /* this is where we start */
     do {
         for (index = 0; index < notified->length; ++index) {
             PRThread *thred;
             PRThread *next;
 
             thred = notified->cv[index].notifyHead;
@@ -249,24 +249,24 @@ PR_IMPLEMENT(void)
 
     /*
      * If we have pending notifies, post them now.
      */
     if (0 != lock->notified.length) {
         md_UnlockAndPostNotifies(lock, thred, cv);
     } else {
         AddThreadToCVWaitQueueInternal(thred, cv);
-        LeaveCriticalSection(&lock->mutex); 
+        DosReleaseMutexSem(lock->mutex); 
     }
 
     /* Wait for notification or timeout; don't really care which */
     rv = DosWaitEventSem(thred->md.blocked_sema.sem, msecs);
     DosResetEventSem(thred->md.blocked_sema.sem, &count);
 
-    EnterCriticalSection(&(lock->mutex));
+    DosRequestMutexSem(lock->mutex,-1);
 
     PR_ASSERT(rv == NO_ERROR || rv == ERROR_TIMEOUT);
 
     if(rv == ERROR_TIMEOUT)
     {
        if (thred->md.inCVWaitQueue) {
            PR_ASSERT((cv->waitTail != NULL && cv->waitHead != NULL)
                    || (cv->waitTail == NULL && cv->waitHead == NULL));
@@ -321,12 +321,12 @@ PR_IMPLEMENT(void)
 }
 
 PR_IMPLEMENT(void)
 _PR_MD_UNLOCK(_MDLock *lock)
 {
     if (0 != lock->notified.length) {
         md_UnlockAndPostNotifies(lock, NULL, NULL);
     } else {
-        LeaveCriticalSection(&lock->mutex);
+        DosReleaseMutexSem(lock->mutex);
     }
     return;
 }
--- a/pr/src/md/os2/os2gc.c
+++ b/pr/src/md/os2/os2gc.c
@@ -17,18 +17,16 @@
  */
 
 /*
  * GC related routines
  *
  */
 #include "primpl.h"
 
-extern APIRET (* APIENTRY QueryThreadContext)(TID, ULONG, PCONTEXTRECORD);
-
 PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np) 
 {
     CONTEXTRECORD context;
     context.ContextFlags = CONTEXT_INTEGER;
 
     if (_PR_IS_NATIVE_THREAD(t)) {
         context.ContextFlags |= CONTEXT_CONTROL;
         if (QueryThreadContext(t->md.handle, CONTEXT_CONTROL, &context)) {
--- a/pr/src/md/os2/os2inrval.c
+++ b/pr/src/md/os2/os2inrval.c
@@ -27,18 +27,16 @@ ULONG _os2_ticksPerSec = -1;
 PRIntn _os2_bitShift = 0;
 PRInt32 _os2_highMask = 0;
 
 
    
 PR_IMPLEMENT(void)
 _PR_MD_INTERVAL_INIT()
 {
-   ULONG count;
-
    if (DosTmrQueryFreq(&_os2_ticksPerSec) == NO_ERROR)
    {
       while(_os2_ticksPerSec > PR_INTERVAL_MAX) {
           _os2_ticksPerSec >>= 1;
           _os2_bitShift++;
           _os2_highMask = (_os2_highMask << 1)+1;
       }
    }
--- a/pr/src/md/os2/os2io.c
+++ b/pr/src/md/os2/os2io.c
@@ -18,17 +18,21 @@
 
 /* OS2 IO module
  *
  * Assumes synchronous I/O.
  *
  */
 
 #include "primpl.h"
+#ifdef XP_OS2_VACPP
 #include <direct.h>
+#else
+#include <dirent.h>
+#endif
 
 struct _MDLock               _pr_ioq_lock;
 
 PR_IMPLEMENT(PRStatus)
 _PR_MD_WAIT(PRThread *thread, PRIntervalTime ticks)
 {
     PRInt32 rv;
     ULONG count;
--- a/pr/src/md/os2/os2misc.c
+++ b/pr/src/md/os2/os2misc.c
@@ -15,16 +15,17 @@
  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  * Reserved.
  */
 
 /*
  * os2misc.c
  *
  */
+#include <string.h>
 #include "primpl.h"
 
 PR_IMPLEMENT(char *)
 _PR_MD_GET_ENV(const char *name)
 {
     return getenv(name);
 }
 
@@ -330,18 +331,16 @@ PRProcess * _PR_CreateOS2Process(
        qsort((void *) newEnvp, (size_t) numEnv, sizeof(char *), compare);
    }
    if (assembleEnvBlock(newEnvp, &envBlock) == -1) {
        PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
        goto errorExit;
    }
 
    if (attr) {
-       PRBool redirected = PR_FALSE;
-
       /* On OS/2, there is really no way to pass file handles for stdin, stdout, 
        * and stderr to a new process.  Instead, we can make it a child process       
        * and make the given file handles a copy of our stdin, stdout, and stderr.
        * The child process then inherits ours, and we set ours back.  Twisted
        * and gross I know. If you know a better way, please use it.
        */
        if (attr->stdinFd) {
             hStdIn = (HFILE) attr->stdinFd->secret->md.osfd;
@@ -429,17 +428,17 @@ PRStatus _PR_WaitOS2Process(PRProcess *p
     RESULTCODES results;
     PID pidEnded = 0;
 
     ulRetVal = DosWaitChild(DCWA_PROCESS, DCWW_WAIT, 
                             &results,
                             &pidEnded, process->md.pid);
 
     if (ulRetVal != NO_ERROR) {
-       printf("\nDosWaitChild rc = %i\n", ulRetVal);
+       printf("\nDosWaitChild rc = %lu\n", ulRetVal);
         PR_SetError(PR_UNKNOWN_ERROR, ulRetVal);
         return PR_FAILURE;
     }
     PR_DELETE(process);
     return PR_SUCCESS;
 }
 
 PRStatus _PR_KillOS2Process(PRProcess *process)
@@ -450,17 +449,16 @@ PRStatus _PR_KillOS2Process(PRProcess *p
     }
     PR_SetError(PR_UNKNOWN_ERROR, ulRetVal);
     return PR_FAILURE;
 }
 
 PR_IMPLEMENT(PRStatus) _MD_OS2GetHostName(char *name, PRUint32 namelen)
 {
     PRIntn rv;
-    PRInt32 syserror;
 
     rv = gethostname(name, (PRInt32) namelen);
     if (0 == rv) {
         return PR_SUCCESS;
     }
 	_PR_MD_MAP_GETHOSTNAME_ERROR(sock_errno());
     return PR_FAILURE;
 }
--- a/pr/src/md/os2/os2poll.c
+++ b/pr/src/md/os2/os2poll.c
@@ -15,25 +15,28 @@
  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  * Reserved.
  */
 
 /*
  * This file implements _PR_MD_PR_POLL for OS/2.
  */
 
+#ifdef XP_OS2_EMX
+	#include <sys/time.h> /* For timeval. */
+#endif
+
 #include "primpl.h"
 
 PRInt32
 _PR_MD_PR_POLL(PRPollDesc *pds, PRIntn npds,
 						PRIntervalTime timeout)
 {
     PRPollDesc *pd, *epd;
-    PRInt32 n, err, pdcnt;
-    PRThread *me = _PR_MD_CURRENT_THREAD();
+    PRInt32 n, err;
 
   	 fd_set rd, wt, ex;
   	 struct timeval tv, *tvp = NULL;
   	 int maxfd = -1;
 
     /*
   	  * For restarting _MD_SELECT() if it is interrupted by a signal.
   	  * We use these variables to figure out how much time has elapsed
--- a/pr/src/md/os2/os2sock.c
+++ b/pr/src/md/os2/os2sock.c
@@ -23,16 +23,20 @@
 /*Note from DSR111297 - it should be noted that there are two flavors of select() on OS/2    */
 /*There is standard BSD (which is kind of slow) and a new flavor of select() that takes      */
 /*an integer list of sockets, the number of read sockets, write sockets, except sockets, and */
 /*a millisecond count for timeout. In the interest of performance I have choosen the OS/2    */
 /*specific version of select(). See OS/2 TCP/IP Programmer's Toolkit for more info.          */ 
 
 #include "primpl.h"
 
+#ifdef XP_OS2_EMX
+    #include <sys/time.h> /* For timeval. */
+#endif
+
 void
 _PR_MD_INIT_IO()
 {
     sock_init();
 }
 
 /* --- SOCKET IO --------------------------------------------------------- */
 
@@ -202,17 +206,17 @@ PRInt32
 #else
     int socks[1]; 
     long lTimeout = -1;
 #endif
 
     if ((rv = connect(osfd, (struct sockaddr *) addr, addrlen)) == -1) 
     {
         err = sock_errno();
-        if ((!fd->secret->nonblocking) && (err == EINPROGRESS) || (err == EWOULDBLOCK))
+        if ((!fd->secret->nonblocking) && ((err == EINPROGRESS) || (err == EWOULDBLOCK)))
         {
 #ifdef BSD_SELECT
            if (timeout == PR_INTERVAL_NO_TIMEOUT)
                tvp = NULL;
             else 
             {
                 tv.tv_sec = PR_IntervalToSeconds(timeout);
                 tv.tv_usec = PR_IntervalToMicroseconds(
@@ -286,17 +290,16 @@ PRInt32
     return rv;
 }
 
 
 PRInt32
 _PR_MD_BIND(PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen)
 {
     PRInt32 rv;
-    int one = 1;
 
     rv = bind(fd->secret->md.osfd, (struct sockaddr*) &(addr->inet), addrlen);
 
     if (rv == -1)  {
 		_PR_MD_MAP_BIND_ERROR(sock_errno());
         return -1;
 	}
 
--- a/pr/src/md/os2/os2thred.c
+++ b/pr/src/md/os2/os2thred.c
@@ -14,24 +14,26 @@
  * Communications Corporation.  Portions created by Netscape are
  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  * Reserved.
  */
 
 #include "primpl.h"
 #include <process.h>  /* for _beginthread() */
 
-APIRET (* APIENTRY QueryThreadContext)(TID, ULONG, PCONTEXTRECORD);
+/* --- Declare these to avoid "implicit" warnings --- */
+PR_EXTERN(void) _PR_MD_NEW_SEM(_MDSemaphore *md, PRUintn value);
+PR_EXTERN(void) _PR_MD_DESTROY_SEM(_MDSemaphore *md);
 
 /* --- globals ------------------------------------------------ */
 _NSPR_TLS*        pThreadLocalStorage = 0;
 _PRInterruptTable             _pr_interruptTable[] = { { 0 } };
 
 PR_IMPLEMENT(void)
-_PR_MD_ENSURE_TLS()
+_PR_MD_ENSURE_TLS(void)
 {
    if(!pThreadLocalStorage)
    {
       /* Allocate thread local storage (TLS).  Note, that only 32 bytes can
        * be allocated at a time. 
        */
       int rc = DosAllocThreadLocalMemory(sizeof(_NSPR_TLS) / 4, (PULONG*)&pThreadLocalStorage);
       PR_ASSERT(rc == NO_ERROR);
@@ -60,24 +62,22 @@ PR_IMPLEMENT(void)
 
    thread->md.handle = ptib->tib_ptib2->tib2_ultid;
 }
 
 
 PR_IMPLEMENT(PRStatus)
 _PR_MD_INIT_THREAD(PRThread *thread)
 {
-   APIRET rc;
-
    if (thread->flags & _PR_PRIMORDIAL)
       _PR_MD_INIT_PRIMORDIAL_THREAD(thread);
 
    /* Create the blocking IO semaphore */
    _PR_MD_NEW_SEM(&thread->md.blocked_sema, 1);
-   return (thread->md.blocked_sema.sem != NULL) ? PR_SUCCESS : PR_FAILURE;
+   return (thread->md.blocked_sema.sem != 0) ? PR_SUCCESS : PR_FAILURE;
 }
 
 PR_IMPLEMENT(PRStatus) 
 _PR_MD_CREATE_THREAD(PRThread *thread, 
                   void (*start)(void *), 
                   PRThreadPriority priority, 
                   PRThreadScope scope, 
                   PRThreadState state,