Merged the changes from NSPRPUB_PRE_4_2_CLIENT_BRANCH onto the trunk. Most
authorwtc%netscape.com
Wed, 14 May 2003 01:24:08 +0000
changeset 2821 d928f74ae1cc495d01b7ac018680665b07056e80
parent 2818 bd53e66c6e978edab498a68e16bf67279edf8ab5
child 2822 e8e3198c7715b23e2f52c8e7c4bdc3cf129fcd5f
push idunknown
push userunknown
push dateunknown
Merged the changes from NSPRPUB_PRE_4_2_CLIENT_BRANCH onto the trunk. Most of these changes are for OS/2. Modified Files: configure.in build/cygwin-wrapper config/rules.mk lib/ds/Makefile.in lib/ds/plds.def lib/libc/src/Makefile.in lib/libc/src/plc.def pr/include/md/_os2.h pr/src/Makefile.in pr/src/nspr.def pr/src/linking/prlink.c pr/src/md/os2/Makefile.in pr/src/md/os2/objs.mk pr/src/md/os2/os2cv.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 pr/tests/Makefile.in pr/tests/attach.c
build/cygwin-wrapper
config/rules.mk
configure.in
lib/ds/Makefile.in
lib/ds/plds.def
lib/libc/src/Makefile.in
lib/libc/src/plc.def
pr/include/md/_os2.h
pr/src/Makefile.in
pr/src/linking/prlink.c
pr/src/md/os2/Makefile.in
pr/src/md/os2/objs.mk
pr/src/md/os2/os2cv.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
pr/src/nspr.def
pr/tests/Makefile.in
pr/tests/attach.c
--- a/build/cygwin-wrapper
+++ b/build/cygwin-wrapper
@@ -2,16 +2,22 @@
 #
 # Stupid wrapper to avoid win32 dospath/cygdrive issues
 #
 prog=$1
 shift
 if test -z "$prog"; then
     exit 0
 fi
+mountpoint=`mount -p | awk '{ if (/^\//) { print $1; exit } }'`
+if test -z "$mountpoint"; then
+   print "Cannot determine cygwin mount points. Exiting"
+   exit 1
+fi
+mountpoint=`echo $mountpoint | sed 's|/$||'`
 if test "$prog" = "-up"; then
    prog=$1
    shift
-   args=`echo $* | sed -e 's|-I\(.\):|-I/cygdrive/\1|g;'`
+   args=`echo $* | sed -e "s|-I\([a-zA-Z]\):/|-I${mountpoint}/\1/|g;"`
 else
-   args=`echo $* | sed -e 's|/cygdrive/\(.\)/|\1:/|g;'`
+   args=`echo $* | sed -e "s|${mountpoint}/\([a-zA-Z]\)/|\1:/|g;"`
 fi
 exec $prog $args
--- a/config/rules.mk
+++ b/config/rules.mk
@@ -306,18 +306,19 @@ endif
 ifeq ($(MOZ_OS2_TOOLS),VACPP)
 	$(AR) $(subst /,\\,$(OBJS)) $(AR_FLAGS)
 else
 	$(AR) $(AR_FLAGS) $(OBJS) $(AR_EXTRA_ARGS)
 endif
 	$(RANLIB) $@
 
 ifeq ($(OS_TARGET), OS2)
-$(IMPORT_LIBRARY): $(SHARED_LIBRARY)
-	$(IMPLIB) $@ $(SHARED_LIBRARY).def
+$(IMPORT_LIBRARY): $(MAPFILE)
+	rm -f $@
+	$(IMPLIB) $@ $(MAPFILE)
 endif
 
 $(SHARED_LIBRARY): $(OBJS) $(MAPFILE)
 	@$(MAKE_OBJDIR)
 	rm -f $@
 ifeq ($(OS_ARCH)$(OS_RELEASE), AIX4.1)
 	echo "#!" > $(OBJDIR)/lib$(LIBRARY_NAME)_syms
 	nm -B -C -g $(OBJS) \
@@ -325,36 +326,29 @@ ifeq ($(OS_ARCH)$(OS_RELEASE), AIX4.1)
 		| sed -e 's/^\.//' \
 		| sort -u >> $(OBJDIR)/lib$(LIBRARY_NAME)_syms
 	$(LD) $(XCFLAGS) -o $@ $(OBJS) -bE:$(OBJDIR)/lib$(LIBRARY_NAME)_syms \
 		-bM:SRE -bnoentry $(OS_LIBS) $(EXTRA_LIBS)
 else	# AIX 4.1
 ifeq ($(NS_USE_GCC)_$(OS_ARCH),_WINNT)
 	$(LINK_DLL) -MAP $(DLLBASE) $(DLL_LIBS) $(EXTRA_LIBS) $(OBJS)
 else
-ifeq ($(OS_ARCH),OS2)
-# append ( >> ) doesn't seem to be working under OS/2 gmake. Run through OS/2 shell instead.	
-	@cmd /C "echo LIBRARY $(notdir $(basename $(SHARED_LIBRARY))) INITINSTANCE TERMINSTANCE >$@.def"
-	@cmd /C "echo PROTMODE >>$@.def"
-	@cmd /C "echo CODE    LOADONCALL MOVEABLE DISCARDABLE >>$@.def"
-	@cmd /C "echo DATA    PRELOAD MOVEABLE MULTIPLE NONSHARED >>$@.def"	
-	@cmd /C "echo EXPORTS >>$@.def"
-	@cmd /C "$(FILTER) $(LIBRARY) | grep -v _DLL_InitTerm >>$@.def"
-	$(LINK_DLL) $(DLLBASE) $(OBJS) $(OS_LIBS) $(EXTRA_LIBS) $@.def
-else	# OS2
+ifeq ($(MOZ_OS2_TOOLS),VACPP)
+	$(LINK_DLL) $(DLLBASE) $(OBJS) $(OS_LIBS) $(EXTRA_LIBS) $(MAPFILE)
+else	# !os2 vacpp
 ifeq ($(OS_TARGET), OpenVMS)
 	@if test ! -f $(VMS_SYMVEC_FILE); then \
 	  if test -f $(VMS_SYMVEC_FILE_MODULE); then \
 	    echo Creating component options file $(VMS_SYMVEC_FILE); \
 	    cp $(VMS_SYMVEC_FILE_MODULE) $(VMS_SYMVEC_FILE); \
 	  fi; \
 	fi
 endif	# OpenVMS
 	$(MKSHLIB) $(OBJS) $(EXTRA_LIBS)
-endif   # OS2
+endif   # OS2 vacpp
 endif	# WINNT
 endif	# AIX 4.1
 ifdef ENABLE_STRIP
 	$(STRIP) $@
 endif
 
 ifeq (,$(filter-out WINNT OS2,$(OS_ARCH)))
 $(RES): $(RESNAME)
@@ -373,16 +367,25 @@ endif
 endif
 
 $(MAPFILE): $(LIBRARY_NAME).def
 	@$(MAKE_OBJDIR)
 ifeq ($(OS_ARCH),SunOS)
 	grep -v ';-' $< | \
 	sed -e 's,;+,,' -e 's; DATA ;;' -e 's,;;,,' -e 's,;.*,;,' > $@
 endif
+ifeq ($(OS_ARCH),OS2)
+	echo LIBRARY $(LIBRARY_NAME)$(LIBRARY_VERSION) INITINSTANCE TERMINSTANCE > $@
+	echo PROTMODE >> $@
+	echo CODE    LOADONCALL MOVEABLE DISCARDABLE >> $@
+	echo DATA    PRELOAD MOVEABLE MULTIPLE NONSHARED >> $@
+	echo EXPORTS >> $@
+	grep -v ';+' $< | grep -v ';-' | \
+	sed -e 's; DATA ;;' -e 's,;;,,' -e 's,;.*,,' >> $@
+endif
 
 #
 # Translate source filenames to absolute paths. This is required for
 # debuggers under Windows and OS/2 to find source files automatically.
 #
 
 ifeq ($(OS_ARCH),OS2)
 NEED_ABSOLUTE_PATH = 1
--- a/configure.in
+++ b/configure.in
@@ -337,17 +337,17 @@ fi
 if test -n "$MOZ_DEBUG"; then
     AC_DEFINE(DEBUG)
     DEFINES="$DEFINES -UNDEBUG"
 
     case "${target_os}" in
     beos*)
         DEFINES="$DEFINES -DDEBUG_${USER}"
         ;;
-    msvc*|mks*|cygwin*|mingw*)
+    msvc*|mks*|cygwin*|mingw*|os2*)
         DEFINES="$DEFINES -DDEBUG_`echo ${USERNAME} | sed -e 's| |_|g'`"
         ;;
     *) 
         DEFINES="$DEFINES -DDEBUG_`$WHOAMI`"
         ;;
     esac
 else
     AC_DEFINE(NDEBUG)
@@ -446,17 +446,17 @@ else
 fi
 
 if test "$GCC" = "yes"; then
     GNU_CC=1
 fi
 if test "$GXX" = "yes"; then
     GNU_CXX=1
 fi
-if test "`echo | $AS -V 2>&1 | grep -c GNU`" != "0"; then
+if test "`echo | $AS -v 2>&1 | grep -c GNU`" != "0"; then
     GNU_AS=1
 fi
 rm -f a.out
 
 if test "$cross_compiling"  = "yes"; then
     CROSS_COMPILE=1
 else
     CROSS_COMPILE=
@@ -1766,75 +1766,76 @@ mips-sony-newsos*)
     CPU_ARCH=x86
     ;;
 
 *-os2*)
     AC_DEFINE(XP_OS2)
     AC_DEFINE(XP_PC)
     AC_DEFINE(BSD_SELECT)
     AC_DEFINE(_PR_GLOBAL_THREADS_ONLY)
-    OBJ_SUFFIX=obj
     LIB_SUFFIX=lib
     DLL_SUFFIX=dll
-    ASM_SUFFIX=asm
     RC=rc.exe
     PR_MD_ARCH_DIR=os2
     PROG_SUFFIX=.exe
     NSINSTALL=nsinstall
     MDCPUCFG_H=_os2.cfg
     RESOLVE_LINK_SYMBOLS=1
 
     # EMX/GCC build
-    if test "$GNU_CC"; then
+    if test -n "$GNU_CC"; then
         AC_DEFINE(XP_OS2_EMX)
         AC_DEFINE(OS2)
         AR=emxomfar
         AR_FLAGS='-p256 r $@'
-        CFLAGS="-Zmtd -Zomf"
-        HOST_CFLAGS="$CFLAGS"
-        CXXFLAGS="-Zmtd -Zomf"
-        OS_LIBS="-lsocket -lemxio"
-        LD='$(CC)'
-        IMPLIB='emximp -o'
-        FILTER='emxexp'
-        OS_DLLFLAGS='$(DSO_LDOPTS) -o $@'
+        CFLAGS="$CFLAGS -Wall -Zmtd -Zomf"
+        CXXFLAGS="$CFLAGS -Wall -Zmtd -Zomf"
+        MKSHLIB='$(CC) $(DSO_LDOPTS) -o $@'
+        DSO_CFLAGS=
+        DSO_LDOPTS='-Zomf -Zdll -Zmtd'
         _OPTIMIZE_FLAGS="-O2 -s"
-        _DEBUG_FLAGS=-g
-        if test -n "$MOZ_DEBUG"; then
-          DLLFLAGS='-g'
-          EXEFLAGS='-g $(OMF_FLAG) -Zmtd -L$(DIST)/lib -o $@'
-          DSO_LDOPTS='-g -Zomf -Zdll -Zmt -Zcrtdll -Zlinker /NOO'
-        else
-          DLLFLAGS=
-          EXEFLAGS='-Zmtd -o $@'
-          DSO_LDOPTS='-Zomf -Zdll -Zmt -Zcrtdll -Zlinker /NOO'
+        _DEBUG_FLAGS="-g -fno-inline"
+        if test -n "$MOZ_OPTIMIZE"; then
+          DSO_LDOPTS="$DSO_LDOPTS -Zlinker /EXEPACK:2 -Zlinker /PACKCODE -Zlinker /PACKDATA"
         fi
-    fi
-    
+        OS_LIBS="-lsocket -lemxio"
+        IMPLIB='emximp -o'
+        FILTER='emxexp -o'
+
+        if test -z "$EMXOMFLD_LINKER"; then
+          # using LINK386.EXE
+          DSO_LDOPTS="$DSO_LDOPTS -Zlinker /NOO"
+        fi
+
+        # GCC for OS/2 currently predefines these, but we don't want them
+        DEFINES="$DEFINES -Uunix -U__unix -U__unix__"
+
     # Visual Age C++ build
-    if test "$VACPP" = "yes"; then
+    elif test "$VACPP" = "yes"; then
         AC_DEFINE(XP_OS2_VACPP)
         AC_DEFINE(OS2,4)
         AC_DEFINE(TCPV40HDRS)
         AC_DEFINE(_X86_)
+        OBJ_SUFFIX=obj
         AS=alp
         ASFLAGS='-Mb'
+        ASM_SUFFIX=asm
         AR=-ilib
         AR_FLAGS='/NOL /NOI /O:$(subst /,\\,$@)'
         CFLAGS='/Q /qlibansi /Gd+ /Gm+ /Su4 /Mp /Tl9'
         HOST_CFLAGS="$CFLAGS"
         OS_CFLAGS='/Q /qlibansi /Gd+ /Gm+ /Su4 /Mp /Tl9'
         OS_EXE_CFLAGS='/Q /qlibansi /Gd+ /Gm+ /Su4 /Mp /Tl9'
         CXXFLAGS='/Q /qlibansi /Gd+ /Gm+ /Su4 /Mp /Tl9'
         OS_LIBS='so32dll.lib tcp32dll.lib'
         LD='-ilink'
         MKSHLIB='$(LD) $(DSO_LDOPTS)'
         IMPLIB='implib -nologo -noignorecase'
         FILTER='cppfilt -q -B -P'
-        _OPTIMIZE_FLAGS='/O+ /Gl+ /Gx+ /qtune=pentium /qarch=pentium'
+        _OPTIMIZE_FLAGS='/O+ /Gl+ /qtune=pentium /qarch=pentium'
         _DEBUG_FLAGS='/Ti+ '
         LDFLAGS='/NOL /M /L'
         DLLFLAGS='/O:$@ /DLL /INC:_dllentry /MAP:$(@:.dll=.map) /L /NOL'
         EXEFLAGS='/OUT:$@ /PMTYPE:VIO /MAP:$(@:.exe=.map) /L /NOL'
         if test -n "$MOZ_DEBUG"; then
           LDFLAGS="$LDFLAGS /DE"
           DLLFLAGS="$DLLFLAGS /DE"
           EXEFLAGS="$EXEFLAGS /DE"
--- a/lib/ds/Makefile.in
+++ b/lib/ds/Makefile.in
@@ -90,16 +90,22 @@ MKSHLIB += -Wl,--version-script,$(MAPFIL
 else
 MKSHLIB += -Wl,-M,$(MAPFILE)
 endif
 else
 MKSHLIB += -M $(MAPFILE)
 endif
 endif
 
+ifeq ($(OS_ARCH),OS2)
+MAPFILE = $(OBJDIR)/$(LIBRARY_NAME)$(LIBRARY_VERSION).def
+GARBAGE += $(MAPFILE)
+MKSHLIB += $(MAPFILE)
+endif
+
 EXTRA_LIBS = $(LIBNSPR)
 
 # On NCR and SCOOS, we can't link with extra libraries when
 # we build a shared library.  If we do so, the linker doesn't
 # complain, but we would run into weird problems at run-time.
 # Therefore on these platforms, we link just the .o files.
 ifeq ($(OS_ARCH),NCR)
 EXTRA_LIBS =
--- a/lib/ds/plds.def
+++ b/lib/ds/plds.def
@@ -1,11 +1,56 @@
-# nm -n -C -p libplds4.so | awk '/[^ ]* T PL_/ {print $3}'
-NSPR_4.0 {
-    global:
+;+#
+;+# The contents of this file are subject to the Mozilla Public
+;+# License Version 1.1 (the "License"); you may not use this file
+;+# except in compliance with the License. You may obtain a copy of
+;+# the License at http://www.mozilla.org/MPL/
+;+#
+;+# Software distributed under the License is distributed on an "AS
+;+# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+;+# implied. See the License for the specific language governing
+;+# rights and limitations under the License.
+;+#
+;+# The Original Code is the Netscape Portable Runtime (NSPR).
+;+#
+;+# The Initial Developer of the Original Code is Netscape
+;+# Communications Corporation.  Portions created by Netscape are
+;+# Copyright (C) 2002-2003 Netscape Communications Corporation.  All
+;+# Rights Reserved.
+;+#
+;+# Contributor(s):
+;+#
+;+# Alternatively, the contents of this file may be used under the
+;+# terms of the GNU General Public License Version 2 or later (the
+;+# "GPL"), in which case the provisions of the GPL are applicable
+;+# instead of those above.  If you wish to allow use of your
+;+# version of this file only under the terms of the GPL and not to
+;+# allow others to use your version of this file under the MPL,
+;+# indicate your decision by deleting the provisions above and
+;+# replace them with the notice and other provisions required by
+;+# the GPL.  If you do not delete the provisions above, a recipient
+;+# may use your version of this file under either the MPL or the
+;+# GPL.
+;+#
+;+# OK, this file is meant to support SUN, LINUX, AIX, OS/2 and WINDOWS
+;+#   1. For all unix platforms, the string ";-"  means "remove this line"
+;+#   2. For all unix platforms, the string " DATA " will be removed from any 
+;+#     line on which it occurs.
+;+#   3. Lines containing ";+" will have ";+" removed on SUN and LINUX.
+;+#      On AIX, lines containing ";+" will be removed.
+;+#   4. For all unix platforms, the string ";;" will thave the ";;" removed.
+;+#   5. For all unix platforms, after the above processing has taken place,
+;+#    all characters after the first ";" on the line will be removed.
+;+#    And for AIX, the first ";" will also be removed.
+;+#  This file is passed directly to windows. Since ';' is a comment, all UNIX
+;+#   directives are hidden behind ";", ";+", and ";-"
+;+NSPR_4.0 {
+;+    global:
+LIBRARY plds4 ;-
+EXPORTS ;-
 PL_ArenaAllocate;
 PL_ArenaFinish;
 PL_ArenaGrow;
 PL_ArenaRelease;
 PL_CompactArenaPool;
 PL_CompareStrings;
 PL_CompareValues;
 PL_FinishArenaPool;
@@ -18,16 +63,16 @@ PL_HashTableEnumerateEntries;
 PL_HashTableLookup;
 PL_HashTableRawAdd;
 PL_HashTableRawLookup;
 PL_HashTableRawRemove;
 PL_HashTableRemove;
 PL_InitArenaPool;
 PL_NewHashTable;
 libVersionPoint;
-    local: *;
-};
-
-NSPR_4.1 {
-    global:
+;+    local: *;
+;+};
+;+
+;+NSPR_4.1 {
+;+    global:
 PL_HashTableLookupConst;
 PL_HashTableRawLookupConst;
-} NSPR_4.0;
+;+} NSPR_4.0;
--- a/lib/libc/src/Makefile.in
+++ b/lib/libc/src/Makefile.in
@@ -100,16 +100,22 @@ MKSHLIB += -Wl,--version-script,$(MAPFIL
 else
 MKSHLIB += -Wl,-M,$(MAPFILE)
 endif
 else
 MKSHLIB += -M $(MAPFILE)
 endif
 endif
 
+ifeq ($(OS_ARCH),OS2)
+MAPFILE = $(OBJDIR)/$(LIBRARY_NAME)$(LIBRARY_VERSION).def
+GARBAGE += $(MAPFILE)
+MKSHLIB += $(MAPFILE)
+endif
+
 EXTRA_LIBS = $(LIBNSPR)
 
 # On NCR and SCOOS, we can't link with extra libraries when
 # we build a shared library.  If we do so, the linker doesn't
 # complain, but we would run into weird problems at run-time.
 # Therefore on these platforms, we link just the .o files.
 ifeq ($(OS_ARCH),NCR)
 EXTRA_LIBS =
--- a/lib/libc/src/plc.def
+++ b/lib/libc/src/plc.def
@@ -1,11 +1,56 @@
-# nm -n -C -p libplc4.so | awk '/[^ ]* T PL_/ {print $3}'
-NSPR_4.0 {
-    global:
+;+#
+;+# The contents of this file are subject to the Mozilla Public
+;+# License Version 1.1 (the "License"); you may not use this file
+;+# except in compliance with the License. You may obtain a copy of
+;+# the License at http://www.mozilla.org/MPL/
+;+#
+;+# Software distributed under the License is distributed on an "AS
+;+# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+;+# implied. See the License for the specific language governing
+;+# rights and limitations under the License.
+;+#
+;+# The Original Code is the Netscape Portable Runtime (NSPR).
+;+#
+;+# The Initial Developer of the Original Code is Netscape
+;+# Communications Corporation.  Portions created by Netscape are
+;+# Copyright (C) 2002-2003 Netscape Communications Corporation.  All
+;+# Rights Reserved.
+;+#
+;+# Contributor(s):
+;+#
+;+# Alternatively, the contents of this file may be used under the
+;+# terms of the GNU General Public License Version 2 or later (the
+;+# "GPL"), in which case the provisions of the GPL are applicable
+;+# instead of those above.  If you wish to allow use of your
+;+# version of this file only under the terms of the GPL and not to
+;+# allow others to use your version of this file under the MPL,
+;+# indicate your decision by deleting the provisions above and
+;+# replace them with the notice and other provisions required by
+;+# the GPL.  If you do not delete the provisions above, a recipient
+;+# may use your version of this file under either the MPL or the
+;+# GPL.
+;+#
+;+# OK, this file is meant to support SUN, LINUX, AIX, OS/2 and WINDOWS
+;+#   1. For all unix platforms, the string ";-"  means "remove this line"
+;+#   2. For all unix platforms, the string " DATA " will be removed from any 
+;+#     line on which it occurs.
+;+#   3. Lines containing ";+" will have ";+" removed on SUN and LINUX.
+;+#      On AIX, lines containing ";+" will be removed.
+;+#   4. For all unix platforms, the string ";;" will thave the ";;" removed.
+;+#   5. For all unix platforms, after the above processing has taken place,
+;+#    all characters after the first ";" on the line will be removed.
+;+#    And for AIX, the first ";" will also be removed.
+;+#  This file is passed directly to windows. Since ';' is a comment, all UNIX
+;+#   directives are hidden behind ";", ";+", and ";-"
+;+NSPR_4.0 {
+;+    global:
+LIBRARY plc4 ;-
+EXPORTS ;-
 PL_Base64Decode;
 PL_Base64Encode;
 PL_CreateOptState;
 PL_DestroyOptState;
 PL_FPrintError;
 PL_GetNextOpt;
 PL_PrintError;
 PL_strcasecmp;
@@ -35,15 +80,15 @@ PL_strnrchr;
 PL_strnrstr;
 PL_strnstr;
 PL_strpbrk;
 PL_strprbrk;
 PL_strrchr;
 PL_strrstr;
 PL_strstr;
 libVersionPoint;
-    local: *;
-};
-
-NSPR_4.2 {
-    global:
+;+    local: *;
+;+};
+;+
+;+NSPR_4.2 {
+;+    global:
 PL_strtok_r;
-} NSPR_4.0;
+;+} NSPR_4.0;
--- a/pr/include/md/_os2.h
+++ b/pr/include/md/_os2.h
@@ -42,17 +42,20 @@
 #define INCL_WPS
 #include <os2.h>
 #include <sys/select.h>
 
 #include "prio.h"
 
 #include <errno.h>
 
+#ifdef XP_OS2_VACPP
+/* TODO RAMSEMs need to be written for GCC/EMX */
 #define USE_RAMSEM
+#endif
 
 #ifdef USE_RAMSEM
 #pragma pack(4)
 
 #pragma pack(2)
 typedef struct _RAMSEM
 {
    ULONG   ulTIDPID;
@@ -70,25 +73,24 @@ typedef struct _CRITICAL_SECTION
 
 APIRET _Optlink SemRequest486(PRAMSEM, ULONG);
 APIRET _Optlink SemReleasex86(PRAMSEM, ULONG);
 #endif
 
 #ifdef XP_OS2_EMX
 /*
  * EMX-specific tweaks:
- *    o Use stricmp instead of strcmpi.
  *    o Use errno rather than sock_errno()
  *    o Use close rather than soclose
  *    o Ignore sock_init calls.
  */
-#define strcmpi stricmp 
 #define sock_errno() errno
 #define soclose close
 #define sock_init()
+#include <string.h>
 #endif
 
 /*
  * Internal configuration macros
  */
 
 #define PR_LINKER_ARCH      "os2"
 #define _PR_SI_SYSNAME        "OS2"
@@ -303,21 +305,23 @@ extern PRInt32 _MD_SELECT(int nfds, fd_s
                                     fd_set *exceptfds, struct timeval *timeout);
 #else
 #define _MD_SELECT                    select
 #endif
 
 #define _MD_FSYNC                     _PR_MD_FSYNC
 #define _MD_SET_FD_INHERITABLE        (_PR_MD_SET_FD_INHERITABLE)
 
+#ifdef _PR_HAVE_ATOMIC_OPS
 #define _MD_INIT_ATOMIC()
 #define _MD_ATOMIC_INCREMENT          _PR_MD_ATOMIC_INCREMENT
 #define _MD_ATOMIC_ADD                _PR_MD_ATOMIC_ADD
 #define _MD_ATOMIC_DECREMENT          _PR_MD_ATOMIC_DECREMENT
 #define _MD_ATOMIC_SET                _PR_MD_ATOMIC_SET
+#endif
 
 #define _MD_INIT_IO                   (_PR_MD_INIT_IO)
 #define _MD_PR_POLL                   (_PR_MD_PR_POLL)
 
 /* win95 doesn't have async IO */
 #define _MD_SOCKET                    (_PR_MD_SOCKET)
 extern PRInt32 _MD_SocketAvailable(PRFileDesc *fd);
 #define _MD_SOCKETAVAILABLE           _MD_SocketAvailable
--- a/pr/src/Makefile.in
+++ b/pr/src/Makefile.in
@@ -136,16 +136,22 @@ ifeq ($(OS_ARCH),AIX)
 ifneq (,$(filter-out 3.2 4.1,$(OS_RELEASE)))
 ifneq ($(USE_PTHREADS),1)
 BUILD_AIX_RTL_LIBC = 1
 AIX_RTL_LIBC	= $(OBJDIR)/libc.a
 endif
 endif
 endif
 
+ifeq ($(OS_ARCH),OS2)
+MAPFILE = $(OBJDIR)/$(LIBRARY_NAME)$(LIBRARY_VERSION).def
+GARBAGE += $(MAPFILE)
+MKSHLIB += $(MAPFILE)
+endif
+
 ifeq ($(OS_ARCH),OSF1)
 ifeq ($(USE_PTHREADS), 1)
 OS_LIBS 	= -lpthread -lrt
 endif
 ifneq ($(OS_RELEASE),V2.0)
 OS_LIBS		+= -lc_r
 endif
 endif
--- a/pr/src/linking/prlink.c
+++ b/pr/src/linking/prlink.c
@@ -575,19 +575,21 @@ static PRLibrary*
 pr_UnlockedFindLibrary(const char *name)
 {
     PRLibrary* lm = pr_loadmap;
     const char* np = strrchr(name, PR_DIRECTORY_SEPARATOR);
     np = np ? np + 1 : name;
     while (lm) {
     const char* cp = strrchr(lm->name, PR_DIRECTORY_SEPARATOR);
     cp = cp ? cp + 1 : lm->name;
-#ifdef XP_PC
+#ifdef WIN32
         /* Windows DLL names are case insensitive... */
     if (strcmpi(np, cp) == 0) 
+#elif defined(XP_OS2)
+    if (stricmp(np, cp) == 0)
 #else
     if (strcmp(np, cp)  == 0) 
 #endif
     {
         /* found */
         lm->refCount++;
         PR_LOG(_pr_linker_lm, PR_LOG_MIN,
            ("%s incr => %d (find lib)",
--- a/pr/src/md/os2/Makefile.in
+++ b/pr/src/md/os2/Makefile.in
@@ -57,16 +57,20 @@ CSRCS = \
     os2rng.c \
     $(NULL)
 endif
 
 ifeq ($(MOZ_OS2_TOOLS),VACPP)
 ASFILES = os2vacpp.asm
 endif
 
+ifeq ($(MOZ_OS2_TOOLS),EMX)
+ASFILES = os2emx.s
+endif
+
 TARGETS	= $(OBJS)
 
 INCLUDES = -I$(dist_includedir) -I$(topsrcdir)/pr/include -I$(topsrcdir)/pr/include/private
 
 DEFINES	+= -D_NSPR_BUILD_
 
 include $(topsrcdir)/config/rules.mk
 
--- a/pr/src/md/os2/objs.mk
+++ b/pr/src/md/os2/objs.mk
@@ -47,11 +47,15 @@ CSRCS = \
 	os2poll.c    \
 	os2rng.c     \
 	$(NULL)
 
 ifeq ($(MOZ_OS2_TOOLS),VACPP)
 ASFILES = os2vacpp.asm
 endif
 
+ifeq ($(MOZ_OS2_TOOLS),EMX)
+ASFILES = os2emx.s
+endif
+
 OBJS += $(addprefix md/os2/$(OBJDIR)/,$(CSRCS:.c=.$(OBJ_SUFFIX)))  \
-	$(addprefix md/os2/$(OBJDIR)/,$(ASFILES:.asm=.$(OBJ_SUFFIX)))
+	$(addprefix md/os2/$(OBJDIR)/,$(ASFILES:.$(ASM_SUFFIX)=.$(OBJ_SUFFIX)))
 
--- a/pr/src/md/os2/os2cv.c
+++ b/pr/src/md/os2/os2cv.c
@@ -46,16 +46,20 @@
  *  have a better chance to reaquire the lock.
  */
  
 #include "primpl.h"
 
 #ifdef USE_RAMSEM
 ULONG _Far16 _Pascal Dos16GetInfoSeg(PSEL pselGlobal, PSEL pselLocal);
 
+#ifdef XP_OS2_EMX
+typedef unsigned short BOOL16;
+#endif
+
 typedef struct _LINFOSEG
 {
     USHORT  pidCurrent;
     USHORT  pidParent;
     USHORT  prtyCurrent;
     USHORT  tidCurrent;
     USHORT  sgCurrent;
     UCHAR   rfProcStatus;
--- a/pr/src/md/os2/os2misc.c
+++ b/pr/src/md/os2/os2misc.c
@@ -513,48 +513,8 @@ unsigned long _System _DLL_InitTerm( uns
       __ctordtorTerm(0);
       _CRT_term();
       rc = 1;
    }
 
    return rc;
 }
 
-#ifndef XP_OS2_VACPP
-
-PRInt32 _PR_MD_ATOMIC_SET(PRInt32 *intp, PRInt32 val)
-{
-  PRInt32 result;
-  asm volatile ("lock ; xchg %0, %1" 
-                : "=r"(result), "=m"(intp)
-                : "0"(val), "m"(intp));
-  return result;
-}
-
-PRInt32 _PR_MD_ATOMIC_ADD(PRInt32 *intp, PRInt32 val)
-{
-  PRInt32 result;
-  asm volatile ("lock ; xadd %0, %1" 
-                : "=r"(result), "=m"(intp)
-                : "0"(val), "m"(intp));
-  return result + val;
-}
-
-PRInt32 _PR_MD_ATOMIC_INCREMENT(PRInt32 *val)
-{    
-  PRInt32 result;
-  asm volatile ("lock ; xadd %0, %1" 
-                : "=r"(result), "=m"(*val)
-                : "0"(1), "m"(*val));
-  return result + 1;
-}
-
-PRInt32 _PR_MD_ATOMIC_DECREMENT(PRInt32 *val)
-{
-  PRInt32 result;
-  asm volatile ("lock ; xadd %0, %1" 
-                : "=r"(result), "=m"(*val)
-                : "0"(1), "m"(*val));
-  return result - 1;
-}
-
-#endif
-
--- a/pr/src/md/os2/os2poll.c
+++ b/pr/src/md/os2/os2poll.c
@@ -260,17 +260,17 @@ retry:
     for( i = rd, j = npds; j < npds+wt; i++,j++ )
         socks[i] = socks[j];
     for( i = rd+wt, j = npds*2; j < npds*2+ex; i++,j++ )
         socks[i] = socks[j];
     
     ready = _MD_SELECT(socks, rd, wt, ex, msecs);
 #endif
 
-    if (ready == -1 && errno == SOCEINTR)
+    if (ready == -1 && errno == EINTR)
     {
         if (timeout == PR_INTERVAL_NO_TIMEOUT)
             goto retry;
         else
         {
             elapsed = (PRIntervalTime) (PR_IntervalNow() - start);
             if (elapsed > timeout)
                 ready = 0;  /* timed out */
@@ -352,18 +352,18 @@ retry:
             {
                 pd->out_flags = 0;
                 if ((NULL != pd->fd) && (0 != pd->in_flags))
                 {
                     bottom = PR_GetIdentitiesLayer(pd->fd, PR_NSPR_IO_LAYER);
                     if (getsockopt(bottom->secret->md.osfd, SOL_SOCKET,
                         SO_TYPE, (char *) &optval, &optlen) == -1)
                     {
-                        PR_ASSERT(sock_errno() == SOCENOTSOCK);
-                        if (sock_errno() == SOCENOTSOCK)
+                        PR_ASSERT(sock_errno() == ENOTSOCK);
+                        if (sock_errno() == ENOTSOCK)
                         {
                             pd->out_flags = PR_POLL_NVAL;
                             ready++;
                         }
                     }
                 }
             }
             PR_ASSERT(ready > 0);
--- a/pr/src/md/os2/os2sock.c
+++ b/pr/src/md/os2/os2sock.c
@@ -146,17 +146,17 @@ socket_io_wait( PRInt32 osfd, PRInt32 fd
             lTimeout = _PR_INTERRUPT_CHECK_INTERVAL_SECS * 1000; 
             do {
                 socks[0] = osfd;
                 if (fd_type == READ_FD)
                     rv = _MD_SELECT(socks, 1, 0, 0, lTimeout);
                 else
                     rv = _MD_SELECT(socks, 0, 1, 0, lTimeout);
 #endif                    
-                if (rv == -1 && (syserror = sock_errno()) != SOCEINTR) {
+                if (rv == -1 && (syserror = sock_errno()) != EINTR) {
                     _PR_MD_MAP_SELECT_ERROR(syserror);
                     break;
                 }
                 if (_PR_PENDING_INTERRUPT(me)) {
                     me->flags &= ~_PR_INTERRUPT;
                     PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
                     rv = -1;
                     break;
@@ -204,31 +204,31 @@ socket_io_wait( PRInt32 osfd, PRInt32 fd
                 if (fd_type == READ_FD)
                     rv = _MD_SELECT(socks, 1, 0, 0, lTimeout);
                 else
                     rv = _MD_SELECT(socks, 0, 1, 0, lTimeout);
 #endif
                 /*
                  * we don't consider EINTR a real error
                  */
-                if (rv == -1 && (syserror = sock_errno()) != SOCEINTR) {
+                if (rv == -1 && (syserror = sock_errno()) != EINTR) {
                     _PR_MD_MAP_SELECT_ERROR(syserror);
                     break;
                 }
                 if (_PR_PENDING_INTERRUPT(me)) {
                     me->flags &= ~_PR_INTERRUPT;
                     PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
                     rv = -1;
                     break;
                 }
                 /*
                  * We loop again if _MD_SELECT timed out or got interrupted
                  * by a signal, and the timeout deadline has not passed yet.
                  */
-                if (rv == 0 || (rv == -1 && syserror == SOCEINTR)) {
+                if (rv == 0 || (rv == -1 && syserror == EINTR)) {
                     /*
                      * If _MD_SELECT timed out, we know how much time
                      * we spent in blocking, so we can avoid a
                      * PR_IntervalNow() call.
                      */
                     if (rv == 0) {
                         if (wait_for_remaining) {
                             now += remaining;
@@ -247,41 +247,41 @@ socket_io_wait( PRInt32 osfd, PRInt32 fd
                     if (elapsed >= timeout) {
                         PR_SetError(PR_IO_TIMEOUT_ERROR, 0);
                         rv = -1;
                         break;
                     } else {
                         remaining = timeout - elapsed;
                     }
                 }
-            } while (rv == 0 || (rv == -1 && syserror == SOCEINTR));
+            } while (rv == 0 || (rv == -1 && syserror == EINTR));
             break;
         }
     return(rv);
 }
 
 PRInt32
 _MD_Accept(PRFileDesc *fd, PRNetAddr *addr,
            PRUint32 *addrlen, PRIntervalTime timeout)
 {
     PRInt32 osfd = fd->secret->md.osfd;
     PRInt32 rv, err;
     PRThread *me = _PR_MD_CURRENT_THREAD();
 
     while ((rv = accept(osfd, (struct sockaddr*) addr, (int*)addrlen)) == -1)
     {
         err = sock_errno();
-        if ((err == SOCEWOULDBLOCK) || (err == SOCECONNABORTED))
+        if ((err == EWOULDBLOCK) || (err == ECONNABORTED))
         {
             if (fd->secret->nonblocking) {
                 break;
             }
                 if ((rv = socket_io_wait(osfd, READ_FD, timeout)) < 0)
                     goto done;
-        } else if ((err == SOCEINTR) && (!_PR_PENDING_INTERRUPT(me))){
+        } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))){
             continue;
         } else {
             break;
         }
     }
     if (rv < 0) {
         _PR_MD_MAP_ACCEPT_ERROR(err);
     }
@@ -309,26 +309,26 @@ PRInt32
       *    or failed.
       */
 
 retry:
     if ((rv = connect(osfd, (struct sockaddr *)addr, addrlen)) == -1)
     {
         err = sock_errno();
 
-        if (err == SOCEINTR) {
+        if (err == EINTR) {
             if (_PR_PENDING_INTERRUPT(me)) {
                 me->flags &= ~_PR_INTERRUPT;
                 PR_SetError( PR_PENDING_INTERRUPT_ERROR, 0);
                 return -1;
             }
             goto retry;
         }
 
-        if (!fd->secret->nonblocking && (err == SOCEINPROGRESS))
+        if (!fd->secret->nonblocking && (err == EINPROGRESS))
         {
             /*
              * socket_io_wait() may return -1 or 1.
              */
 
             rv = socket_io_wait(osfd, WRITE_FD, timeout);
             if (rv == -1) {
                 return -1;
@@ -386,23 +386,23 @@ PRInt32
 {
     PRInt32 osfd = fd->secret->md.osfd;
     PRInt32 rv, err;
     PRThread *me = _PR_MD_CURRENT_THREAD();
 
     while ((rv = recv(osfd,buf,amount,flags)) == -1)
     {
         err = sock_errno();
-        if ((err == SOCEWOULDBLOCK)) {
+        if ((err == EWOULDBLOCK)) {
             if (fd->secret->nonblocking) {
                 break;
             }
             if ((rv = socket_io_wait(osfd, READ_FD, timeout)) < 0)
                 goto done;
-        } else if ((err == SOCEINTR) && (!_PR_PENDING_INTERRUPT(me))){
+        } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))){
             continue;
         } else {
             break;
         }
     }
     if (rv < 0) {
         _PR_MD_MAP_RECV_ERROR(err);
     }
@@ -416,23 +416,23 @@ PRInt32
 {
     PRInt32 osfd = fd->secret->md.osfd;
     PRInt32 rv, err;
     PRThread *me = _PR_MD_CURRENT_THREAD();
 
     while ((rv = send(osfd,buf,amount,flags)) == -1)
     {
         err = sock_errno();
-        if ((err == SOCEWOULDBLOCK)) {
+        if ((err == EWOULDBLOCK)) {
             if (fd->secret->nonblocking) {
                 break;
             }
             if ((rv = socket_io_wait(osfd, WRITE_FD, timeout)) < 0)
                 goto done;
-        } else if ((err == SOCEINTR) && (!_PR_PENDING_INTERRUPT(me))){
+        } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))){
             continue;
         } else {
             break;
         }
     }
 
      /*
       * optimization; if bytes sent is less than "amount" call
@@ -460,17 +460,17 @@ PRInt32
 {
     PRInt32 osfd = fd->secret->md.osfd;
     PRInt32 rv, err;
     PRThread *me = _PR_MD_CURRENT_THREAD();
     while ((rv = sendto(osfd, buf, amount, flags,
            (struct sockaddr *) addr, addrlen)) == -1)
     {
         err = sock_errno();
-        if ((err == SOCEWOULDBLOCK))
+        if ((err == EWOULDBLOCK))
         {
             if (fd->secret->nonblocking) {
                 break;
             }
             if ((rv = socket_io_wait(osfd, WRITE_FD, timeout)) < 0)
                 goto done;
         } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))){
             continue;
@@ -493,23 +493,23 @@ PRInt32
     PRInt32 rv, err;
     PRThread *me = _PR_MD_CURRENT_THREAD();
 
     while( (*addrlen = PR_NETADDR_SIZE(addr)),
            ((rv = recvfrom(osfd, buf, amount, flags,
              (struct sockaddr *) addr, (int *)addrlen)) == -1))
     {
         err = sock_errno();
-        if ((err == SOCEWOULDBLOCK)) {
+        if ((err == EWOULDBLOCK)) {
             if (fd->secret->nonblocking) {
                 break;
             }
             if ((rv = socket_io_wait(osfd, READ_FD, timeout)) < 0)
                 goto done;
-        } else if ((err == SOCEINTR) && (!_PR_PENDING_INTERRUPT(me))){
+        } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))){
             continue;
         } else {
             break;
         }
     }
     if (rv < 0) {
         _PR_MD_MAP_RECVFROM_ERROR(err);
     }
@@ -536,17 +536,17 @@ PRInt32
     if (!fd->secret->nonblocking) {
         for (index=0; index<iov_size; index++) {
             amount += iov[index].iov_len;
         }
     }
 
     while ((rv = writev(osfd, (const struct iovec*)iov, iov_size)) == -1) {
         err = sock_errno();
-        if ((err == SOCEWOULDBLOCK))    {
+        if ((err == EWOULDBLOCK))    {
             if (fd->secret->nonblocking) {
                 break;
             }
             if ((rv = socket_io_wait(osfd, WRITE_FD, timeout))<0)
                 goto done;
         } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))){
             continue;
         } else {
--- a/pr/src/md/os2/os2thred.c
+++ b/pr/src/md/os2/os2thred.c
@@ -88,24 +88,16 @@ static void
    thread->md.handle = ptib->tib_ptib2->tib2_ultid;
 }
 
 
 PRStatus
 _PR_MD_INIT_THREAD(PRThread *thread)
 {
    APIRET rv;
-#ifdef XP_OS2_EMX
-   /* disable SIGPIPE */
-   struct sigaction sa;
-   sa.sa_handler = SIG_IGN;
-   sa.sa_flags = 0;
-   sigemptyset( &sa.sa_mask);
-   sigaction( SIGPIPE, &sa, NULL);
-#endif
 
    if (thread->flags & (_PR_PRIMORDIAL | _PR_ATTACHED)) {
       _pr_SetThreadMDHandle(thread);
    }
 
    /* Create the blocking IO semaphore */
    rv = DosCreateEventSem(NULL, &(thread->md.blocked_sema), 0, 0);
    return (rv == NO_ERROR) ? PR_SUCCESS : PR_FAILURE;
--- a/pr/src/nspr.def
+++ b/pr/src/nspr.def
@@ -1,11 +1,57 @@
-# nm -n -C -p libnspr4.so | awk '/[^ ]* T PR_/ {print $3}'
-NSPR_4.0 {
-	global:
+;+#
+;+# The contents of this file are subject to the Mozilla Public
+;+# License Version 1.1 (the "License"); you may not use this file
+;+# except in compliance with the License. You may obtain a copy of
+;+# the License at http://www.mozilla.org/MPL/
+;+#
+;+# Software distributed under the License is distributed on an "AS
+;+# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+;+# implied. See the License for the specific language governing
+;+# rights and limitations under the License.
+;+#
+;+# The Original Code is the Netscape Portable Runtime (NSPR).
+;+#
+;+# The Initial Developer of the Original Code is Netscape
+;+# Communications Corporation.  Portions created by Netscape are
+;+# Copyright (C) 2002-2003 Netscape Communications Corporation.  All
+;+# Rights Reserved.
+;+#
+;+# Contributor(s):
+;+#
+;+# Alternatively, the contents of this file may be used under the
+;+# terms of the GNU General Public License Version 2 or later (the
+;+# "GPL"), in which case the provisions of the GPL are applicable
+;+# instead of those above.  If you wish to allow use of your
+;+# version of this file only under the terms of the GPL and not to
+;+# allow others to use your version of this file under the MPL,
+;+# indicate your decision by deleting the provisions above and
+;+# replace them with the notice and other provisions required by
+;+# the GPL.  If you do not delete the provisions above, a recipient
+;+# may use your version of this file under either the MPL or the
+;+# GPL.
+;+#
+;+# OK, this file is meant to support SUN, LINUX, AIX, OS/2 and WINDOWS
+;+#   1. For all unix platforms, the string ";-"  means "remove this line"
+;+#   2. For all unix platforms, the string " DATA " will be removed from any 
+;+#     line on which it occurs.
+;+#   3. Lines containing ";+" will have ";+" removed on SUN and LINUX.
+;+#      On AIX, lines containing ";+" will be removed.
+;+#   4. For all unix platforms, the string ";;" will thave the ";;" removed.
+;+#   5. For all unix platforms, after the above processing has taken place,
+;+#    all characters after the first ";" on the line will be removed.
+;+#    And for AIX, the first ";" will also be removed.
+;+#  This file is passed directly to windows. Since ';' is a comment, all UNIX
+;+#   directives are hidden behind ";", ";+", and ";-"
+;+#
+;+NSPR_4.0 {
+;+	global:
+LIBRARY nspr4 ;-
+EXPORTS ;-
 		LL_MaxInt;
 		LL_MinInt;
 		LL_Zero;
 		PR_Abort;
 		PR_AddToCounter;
 		PR_Accept;
 		PR_AcceptRead;
 		PR_Access;
@@ -360,44 +406,44 @@ NSPR_4.0 {
 		PR_vsxprintf;
 		PRP_DestroyNakedCondVar;
 		PRP_NakedBroadcast;
 		PRP_NakedNotify;
 		PRP_NakedWait;
 		PRP_NewNakedCondVar;
 		PRP_TryLock;
 		libVersionPoint;
-	local: *;
-};
-
-NSPRprivate {
-	global:
+;+	local: *;
+;+};
+;+
+;+NSPRprivate {
+;+	global:
 		GetExecutionEnvironment;
 		PT_FPrintStats;
 		SetExecutionEnvironment;
-	local: *;
-};
-
-NSPR_4.1 {
-	global:
+;+	local: *;
+;+};
+;+
+;+NSPR_4.1 {
+;+	global:
 		PR_ConnectContinue;
 		PR_CreateIOLayer;
 		PR_EmulateAcceptRead;
 		PR_EmulateSendFile;
 		PR_FindFunctionSymbol;
 		PR_FindFunctionSymbolAndLibrary;
 		PR_GetMemMapAlignment;
 		PR_GetNumberOfProcessors;
 		PR_ImportPipe;
 		PR_SetEnv;
-} NSPR_4.0;
-
-NSPR_4.3 {
-	global:
+;+} NSPR_4.0;
+;+
+;+NSPR_4.3 {
+;+	global:
 		LL_MaxUint;
 		PR_CallOnceWithArg;
 		PR_GetLibraryFilePathname;
-} NSPR_4.1;
-
-NSPR_4.4 {
-	global:
+;+} NSPR_4.1;
+;+
+;+NSPR_4.4 {
+;+	global:
 		PR_GetPathSeparator;
-} NSPR_4.3;
+;+} NSPR_4.3;
--- a/pr/tests/Makefile.in
+++ b/pr/tests/Makefile.in
@@ -228,19 +228,18 @@ else
   endif # profile
 endif # NS_USE_GCC
 endif
 
 ifeq ($(OS_ARCH),OS2)
 ifeq ($(MOZ_OS2_TOOLS),VACPP)
   LDOPTS = -NOE -DEBUG -nologo -PMTYPE:VIO
 else
-ifeq ($(MOZ_OS2_EMX_OBJECTFORMAT),OMF)
-  LDOPTS = -Zlinker /PM:VIO
-endif
+  EXTRA_LIBS = $(OS_LIBS)
+  LDOPTS = -Zmtd -Zomf -Zlinker /PM:VIO -Zlinker /ST:0x30000
 endif
 endif
 
 ifneq ($(OS_ARCH), WINNT)
 # Use an absolute pathname as the runtime library path (for the -R
 # or -rpath linker option or the LD_RUN_PATH environment variable).
 ifeq (,$(patsubst /%,,$(DIST)))
 # $(DIST) is already an absolute pathname.
@@ -482,17 +481,17 @@ else
 
 # All platforms that are not AIX pre-4.2.
 
 $(OBJDIR)/%$(PROG_SUFFIX): $(OBJDIR)/%.$(OBJ_SUFFIX)
 	@$(MAKE_OBJDIR)
 ifeq ($(NS_USE_GCC)_$(OS_ARCH),_WINNT)
 	link $(LDOPTS) $(EXTRA_LDOPTS) $< $(LIBPLC) $(LIBNSPR) $(EXTRA_LIBS) -out:$@
 else
-ifeq ($(OS_ARCH),OS2)
+ifeq ($(MOZ_OS2_TOOLS),VACPP)
 	$(LD) $(EXEFLAGS) $(LDOPTS) $< $(LIBPLC) $(LIBNSPR) $(OS_LIBS) $(EXTRA_LIBS)
 else
 	$(PURE) $(CC) $(XCFLAGS) $< $(LDOPTS) $(LIBPLC) $(LIBNSPR) $(EXTRA_LIBS) -o $@
 endif # OS/2
 endif # WINNT
 endif # AIX_PRE_4_2
 
 export:: $(TARGETS)
--- a/pr/tests/attach.c
+++ b/pr/tests/attach.c
@@ -324,29 +324,35 @@ int main(int argc, char **argv)
     if (debug_mode) PR_ASSERT(rv != -1);
 	else  if (rv != -1) {
 		failed_already=1;
 		goto exit_now;
 	}
 
 #elif defined(OS2)
 
+# ifdef __EMX__
+    threadID = (TID) _beginthread((void *)threadStartFunc, NULL,
+            32768, NULL); 
+# else
     threadID = (TID) _beginthread((void(* _Optlink)(void*))threadStartFunc, NULL,
             32768, NULL); 
+# endif
     if (threadID == -1) {
         fprintf(stderr, "thread creation failed: error code %d\n", errno);
-		failed_already=1;
-		goto exit_now;
+        failed_already=1;
+        goto exit_now;
     }
     rv = DosWaitThread(&threadID, DCWW_WAIT);
-    if (debug_mode)PR_ASSERT(rv == NO_ERROR);
-	else if (rv == NO_ERROR) {
-		failed_already=1;
-		goto exit_now;
-	}
+    if (debug_mode) {
+        PR_ASSERT(rv == NO_ERROR);
+    } else if (rv != NO_ERROR) {
+        failed_already=1;
+        goto exit_now;
+    }
 
 #elif defined(XP_BEOS)
 	
 	threadID = spawn_thread(threadStartFunc, NULL, B_NORMAL_PRIORITY, NULL);
 	if (threadID <= B_ERROR) {
 		fprintf(stderr, "thread creation failed: error code %08lx\n", threadID);
 		failed_already = 1;
 		goto exit_now;