Bugzilla bug 215581: build with GCC 3.2.2 for OS/2. The patch is NSPRPUB_PRE_4_2_CLIENT_BRANCH
authorwtc%netscape.com
Tue, 16 Sep 2003 02:01:24 +0000
branchNSPRPUB_PRE_4_2_CLIENT_BRANCH
changeset 2925 429115131b0e6da203cd3d1932672008a68c5bdd
parent 2924 66e7c14638d5deada2f56a538c7d82abe5f30e9e
child 2926 9df9c01a68f512342d1b288c2f467013e44be619
push idunknown
push userunknown
push dateunknown
bugs215581
Bugzilla bug 215581: build with GCC 3.2.2 for OS/2. The patch is contributed by Javier Pedemonte <pedemont@us.ibm.com>. r=wtc. Tag: NSPRPUB_PRE_4_2_CLIENT_BRANCH
config/rules.mk
configure
configure.in
pr/include/md/_os2.h
pr/include/md/_os2_errors.h
pr/include/prio.h
pr/include/private/primpl.h
pr/src/Makefile.in
pr/src/io/prlog.c
pr/src/io/prsocket.c
pr/src/linking/prlink.c
pr/src/md/os2/Makefile.in
pr/src/md/os2/objs.mk
pr/src/md/os2/os2_errors.c
pr/src/md/os2/os2poll.c
pr/src/md/os2/os2sock.c
pr/src/md/os2/os2thred.c
pr/src/misc/prnetdb.c
pr/tests/Makefile.in
pr/tests/dll/Makefile.in
--- a/config/rules.mk
+++ b/config/rules.mk
@@ -374,17 +374,19 @@ ifeq ($(OS_ARCH),SunOS)
 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,;.*,,' >> $@
+	sed -e 's; DATA ;;' -e 's,;;,,' -e 's,;.*,,' -e 's,\([\t ]*\),\1_,' | \
+	awk 'BEGIN {ord=1;} { print($$0 " @" ord " RESIDENTNAME"); ord++;}'	>> $@
+	$(ADD_TO_DEF_FILE)
 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)
--- a/configure
+++ b/configure
@@ -4646,37 +4646,36 @@ EOF
         cat >> confdefs.h <<\EOF
 #define XP_OS2_EMX 1
 EOF
 
         cat >> confdefs.h <<\EOF
 #define OS2 1
 EOF
 
+        cat >> confdefs.h <<\EOF
+#define TCPV40HDRS 1
+EOF
+
         AR=emxomfar
-        AR_FLAGS='-p256 r $@'
-        CFLAGS="$CFLAGS -Wall -Zmtd -Zomf"
-        CXXFLAGS="$CFLAGS -Wall -Zmtd -Zomf"
+        AR_FLAGS='r $@'
+        CFLAGS="$CFLAGS -Wall -Zomf"
+        CXXFLAGS="$CFLAGS -Wall -Zomf"
         MKSHLIB='$(CC) $(DSO_LDOPTS) -o $@'
         DSO_CFLAGS=
-        DSO_LDOPTS='-Zomf -Zdll -Zmtd'
+        DSO_LDOPTS='-Zomf -Zdll'
         _OPTIMIZE_FLAGS="-O2 -s"
         _DEBUG_FLAGS="-g -fno-inline"
         if test -n "$MOZ_OPTIMIZE"; then
           DSO_LDOPTS="$DSO_LDOPTS -Zlinker /EXEPACK:2 -Zlinker /PACKCODE -Zlinker /PACKDATA"
         fi
-        OS_LIBS="-lsocket -lemxio"
+        OS_LIBS="-lsocket"
         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
     elif test "$VACPP" = "yes"; then
         cat >> confdefs.h <<\EOF
 #define XP_OS2_VACPP 1
 EOF
@@ -4742,63 +4741,63 @@ if test -z "$SKIP_LIBRARY_CHECKS"; then
 
 
 
 case $target in
 *-darwin*)
     ;;
 *)
     echo $ac_n "checking for dlopen in -ldl""... $ac_c" 1>&6
-echo "configure:4751: checking for dlopen in -ldl" >&5
+echo "configure:4750: checking for dlopen in -ldl" >&5
 ac_lib_var=`echo dl'_'dlopen | sed 'y%./+-%__p_%'`
 if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   ac_save_LIBS="$LIBS"
 LIBS="-ldl  $LIBS"
 cat > conftest.$ac_ext <<EOF
-#line 4759 "configure"
+#line 4758 "configure"
 #include "confdefs.h"
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
     builtin and then its argument prototype would still apply.  */
 char dlopen();
 
 int main() {
 dlopen()
 ; return 0; }
 EOF
-if { (eval echo configure:4770: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:4769: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=yes"
 else
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=no"
 fi
 rm -f conftest*
 LIBS="$ac_save_LIBS"
 
 fi
 if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then
   echo "$ac_t""yes" 1>&6
   ac_safe=`echo "dlfcn.h" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for dlfcn.h""... $ac_c" 1>&6
-echo "configure:4787: checking for dlfcn.h" >&5
+echo "configure:4786: checking for dlfcn.h" >&5
 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 4792 "configure"
+#line 4791 "configure"
 #include "confdefs.h"
 #include <dlfcn.h>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:4797: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:4796: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   rm -rf conftest*
   eval "ac_cv_header_$ac_safe=yes"
 else
   echo "$ac_err" >&5
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
@@ -4821,23 +4820,23 @@ fi
     ;;
 esac
 
 
 
 
 if test $ac_cv_prog_gcc = yes; then
     echo $ac_n "checking whether ${CC-cc} needs -traditional""... $ac_c" 1>&6
-echo "configure:4830: checking whether ${CC-cc} needs -traditional" >&5
+echo "configure:4829: checking whether ${CC-cc} needs -traditional" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_gcc_traditional'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
     ac_pattern="Autoconf.*'x'"
   cat > conftest.$ac_ext <<EOF
-#line 4836 "configure"
+#line 4835 "configure"
 #include "confdefs.h"
 #include <sgtty.h>
 Autoconf TIOCGETP
 EOF
 if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
   egrep "$ac_pattern" >/dev/null 2>&1; then
   rm -rf conftest*
   ac_cv_prog_gcc_traditional=yes
@@ -4845,17 +4844,17 @@ else
   rm -rf conftest*
   ac_cv_prog_gcc_traditional=no
 fi
 rm -f conftest*
 
 
   if test $ac_cv_prog_gcc_traditional = no; then
     cat > conftest.$ac_ext <<EOF
-#line 4854 "configure"
+#line 4853 "configure"
 #include "confdefs.h"
 #include <termio.h>
 Autoconf TCGETA
 EOF
 if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
   egrep "$ac_pattern" >/dev/null 2>&1; then
   rm -rf conftest*
   ac_cv_prog_gcc_traditional=yes
@@ -4869,22 +4868,22 @@ echo "$ac_t""$ac_cv_prog_gcc_traditional
   if test $ac_cv_prog_gcc_traditional = yes; then
     CC="$CC -traditional"
   fi
 fi
 
 for ac_func in lchown strerror
 do
 echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:4878: checking for $ac_func" >&5
+echo "configure:4877: checking for $ac_func" >&5
 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 4883 "configure"
+#line 4882 "configure"
 #include "confdefs.h"
 /* System header to define __stub macros and hopefully few prototypes,
     which can conflict with char $ac_func(); below.  */
 #include <assert.h>
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
     builtin and then its argument prototype would still apply.  */
 char $ac_func();
@@ -4897,17 +4896,17 @@ int main() {
 #if defined (__stub_$ac_func) || defined (__stub___$ac_func)
 choke me
 #else
 $ac_func();
 #endif
 
 ; return 0; }
 EOF
-if { (eval echo configure:4906: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:4905: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_func_$ac_func=yes"
 else
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
   rm -rf conftest*
   eval "ac_cv_func_$ac_func=no"
 fi
@@ -4936,17 +4935,17 @@ if test "${enable_strip+set}" = set; the
 fi
 
 
 case "${target_os}" in
 hpux*)
 if test -z "$GNU_CC"; then
 
     echo $ac_n "checking for +Olit support""... $ac_c" 1>&6
-echo "configure:4945: checking for +Olit support" >&5
+echo "configure:4944: checking for +Olit support" >&5
 if eval "test \"`echo '$''{'ac_cv_hpux_usable_olit_option'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
                   ac_cv_hpux_usable_olit_option=no
         rm -f conftest*
         echo 'int main() { return 0; }' | cat > conftest.c
         ${CC-cc} ${CFLAGS} +Olit=all -o conftest conftest.c > conftest.out 2>&1
         if test $? -eq 0; then
@@ -4970,17 +4969,17 @@ echo "$ac_t""$ac_cv_hpux_usable_olit_opt
 fi
 ;;
 esac
 
 
 
 
 echo $ac_n "checking for pthread_create in -lpthreads""... $ac_c" 1>&6
-echo "configure:4979: checking for pthread_create in -lpthreads" >&5
+echo "configure:4978: checking for pthread_create in -lpthreads" >&5
 echo "
     #include <pthread.h> 
     void *foo(void *v) { return v; } 
     int main() { 
         pthread_t t;
         if (!pthread_create(&t, 0, &foo, 0)) {
             pthread_join(t, 0);
         }
@@ -4992,17 +4991,17 @@ echo "
     rm -f dummy.c dummy${ac_exeext} ;
     if test "$_res" = "0"; then
         echo "$ac_t""yes" 1>&6
         _HAVE_PTHREADS=1 _PTHREAD_LDFLAGS="-lpthreads"
     else
         echo "$ac_t""no" 1>&6
         
 echo $ac_n "checking for pthread_create in -lpthread""... $ac_c" 1>&6
-echo "configure:5001: checking for pthread_create in -lpthread" >&5
+echo "configure:5000: checking for pthread_create in -lpthread" >&5
 echo "
     #include <pthread.h> 
     void *foo(void *v) { return v; } 
     int main() { 
         pthread_t t;
         if (!pthread_create(&t, 0, &foo, 0)) {
             pthread_join(t, 0);
         }
@@ -5014,17 +5013,17 @@ echo "
     rm -f dummy.c dummy${ac_exeext} ;
     if test "$_res" = "0"; then
         echo "$ac_t""yes" 1>&6
         _HAVE_PTHREADS=1 _PTHREAD_LDFLAGS="-lpthread"
     else
         echo "$ac_t""no" 1>&6
         
 echo $ac_n "checking for pthread_create in -lc_r""... $ac_c" 1>&6
-echo "configure:5023: checking for pthread_create in -lc_r" >&5
+echo "configure:5022: checking for pthread_create in -lc_r" >&5
 echo "
     #include <pthread.h> 
     void *foo(void *v) { return v; } 
     int main() { 
         pthread_t t;
         if (!pthread_create(&t, 0, &foo, 0)) {
             pthread_join(t, 0);
         }
@@ -5036,17 +5035,17 @@ echo "
     rm -f dummy.c dummy${ac_exeext} ;
     if test "$_res" = "0"; then
         echo "$ac_t""yes" 1>&6
         _HAVE_PTHREADS=1 _PTHREAD_LDFLAGS="-lc_r"
     else
         echo "$ac_t""no" 1>&6
         
 echo $ac_n "checking for pthread_create in -lc""... $ac_c" 1>&6
-echo "configure:5045: checking for pthread_create in -lc" >&5
+echo "configure:5044: checking for pthread_create in -lc" >&5
 echo "
     #include <pthread.h> 
     void *foo(void *v) { return v; } 
     int main() { 
         pthread_t t;
         if (!pthread_create(&t, 0, &foo, 0)) {
             pthread_join(t, 0);
         }
@@ -5188,17 +5187,17 @@ EOF
     fi
 fi
 
 
 if test -n "$USE_PTHREADS"; then
       rm -f conftest*
    ac_cv_have_dash_pthread=no
    echo $ac_n "checking whether ${CC-cc} accepts -pthread""... $ac_c" 1>&6
-echo "configure:5197: checking whether ${CC-cc} accepts -pthread" >&5
+echo "configure:5196: checking whether ${CC-cc} accepts -pthread" >&5
    echo 'int main() { return 0; }' | cat > conftest.c
    ${CC-cc} -pthread -o conftest conftest.c > conftest.out 2>&1
    if test $? -eq 0; then
 	if test -z "`egrep -i '(unrecognize|unknown)' conftest.out | grep pthread`" && test -z "`egrep -i '(error|incorrect)' conftest.out`" ; then
 	    ac_cv_have_dash_pthread=yes
 		case "$target_os" in
 	    freebsd*)
 # Freebsd doesn't use -pthread for compiles, it uses them for linking
@@ -5211,17 +5210,17 @@ echo "configure:5197: checking whether $
 	fi
     fi
     rm -f conftest*
     echo "$ac_t""$ac_cv_have_dash_pthread" 1>&6
 
 			    ac_cv_have_dash_pthreads=no
     if test "$ac_cv_have_dash_pthread" = "no"; then
 	    echo $ac_n "checking whether ${CC-cc} accepts -pthreads""... $ac_c" 1>&6
-echo "configure:5220: checking whether ${CC-cc} accepts -pthreads" >&5
+echo "configure:5219: checking whether ${CC-cc} accepts -pthreads" >&5
     	echo 'int main() { return 0; }' | cat > conftest.c
 	    ${CC-cc} -pthreads -o conftest conftest.c > conftest.out 2>&1
     	if test $? -eq 0; then
 	    	if test -z "`egrep -i '(unrecognize|unknown)' conftest.out | grep pthreads`" && test -z "`egrep -i '(error|incorrect)' conftest.out`" ; then
 			    ac_cv_have_dash_pthreads=yes
 			    CFLAGS="$CFLAGS -pthreads"
 			    CXXFLAGS="$CXXFLAGS -pthreads"
 		    fi
--- a/configure.in
+++ b/configure.in
@@ -1797,37 +1797,33 @@ mips-sony-newsos*)
     NSINSTALL=nsinstall
     MDCPUCFG_H=_os2.cfg
     RESOLVE_LINK_SYMBOLS=1
 
     # EMX/GCC build
     if test -n "$GNU_CC"; then
         AC_DEFINE(XP_OS2_EMX)
         AC_DEFINE(OS2)
+        AC_DEFINE(TCPV40HDRS)
         AR=emxomfar
-        AR_FLAGS='-p256 r $@'
-        CFLAGS="$CFLAGS -Wall -Zmtd -Zomf"
-        CXXFLAGS="$CFLAGS -Wall -Zmtd -Zomf"
+        AR_FLAGS='r $@'
+        CFLAGS="$CFLAGS -Wall -Zomf"
+        CXXFLAGS="$CFLAGS -Wall -Zomf"
         MKSHLIB='$(CC) $(DSO_LDOPTS) -o $@'
         DSO_CFLAGS=
-        DSO_LDOPTS='-Zomf -Zdll -Zmtd'
+        DSO_LDOPTS='-Zomf -Zdll'
         _OPTIMIZE_FLAGS="-O2 -s"
         _DEBUG_FLAGS="-g -fno-inline"
         if test -n "$MOZ_OPTIMIZE"; then
           DSO_LDOPTS="$DSO_LDOPTS -Zlinker /EXEPACK:2 -Zlinker /PACKCODE -Zlinker /PACKDATA"
         fi
-        OS_LIBS="-lsocket -lemxio"
+        OS_LIBS="-lsocket"
         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
     elif test "$VACPP" = "yes"; then
         AC_DEFINE(XP_OS2_VACPP)
         AC_DEFINE(OS2,4)
         AC_DEFINE(TCPV40HDRS)
--- a/pr/include/md/_os2.h
+++ b/pr/include/md/_os2.h
@@ -70,29 +70,16 @@ typedef struct _CRITICAL_SECTION
     ULONG ulReserved[4]; /* Same size as RAMSEM */
 } CRITICAL_SECTION, *PCRITICAL_SECTION, *LPCRITICAL_SECTION;
 #pragma pack(4)
 
 APIRET _Optlink SemRequest486(PRAMSEM, ULONG);
 APIRET _Optlink SemReleasex86(PRAMSEM, ULONG);
 #endif
 
-#ifdef XP_OS2_EMX
-/*
- * EMX-specific tweaks:
- *    o Use errno rather than sock_errno()
- *    o Use close rather than soclose
- *    o Ignore sock_init calls.
- */
-#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"
 #define _PR_SI_ARCHITECTURE   "x86"    /* XXXMB hardcode for now */
 
@@ -289,29 +276,22 @@ extern void _MD_MakeNonblock(PRFileDesc 
 #define _MD_INIT_FD_INHERITABLE       (_PR_MD_INIT_FD_INHERITABLE)
 #define _MD_QUERY_FD_INHERITABLE      (_PR_MD_QUERY_FD_INHERITABLE)
 #define _MD_SHUTDOWN                  (_PR_MD_SHUTDOWN)
 #define _MD_LISTEN                    _PR_MD_LISTEN
 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_SOCKETPAIR(s, type, proto, sv) -1
+#define _MD_SOCKETPAIR                (_PR_MD_SOCKETPAIR)
 #define _MD_GETSOCKNAME               (_PR_MD_GETSOCKNAME)
 #define _MD_GETPEERNAME               (_PR_MD_GETPEERNAME)
 #define _MD_GETSOCKOPT                (_PR_MD_GETSOCKOPT)
 #define _MD_SETSOCKOPT                (_PR_MD_SETSOCKOPT)
 
-#ifdef XP_OS2_EMX
-extern PRInt32 _MD_SELECT(int nfds, fd_set *readfds, fd_set *writefds,
-                                    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
--- a/pr/include/md/_os2_errors.h
+++ b/pr/include/md/_os2_errors.h
@@ -122,16 +122,19 @@ NSPR_API(void) _MD_os2_map_bind_error(PR
 #define	_PR_MD_MAP_BIND_ERROR	_MD_os2_map_bind_error
 
 NSPR_API(void) _MD_os2_map_listen_error(PRInt32 err);
 #define	_PR_MD_MAP_LISTEN_ERROR	_MD_os2_map_listen_error
 
 NSPR_API(void) _MD_os2_map_shutdown_error(PRInt32 err);
 #define	_PR_MD_MAP_SHUTDOWN_ERROR	_MD_os2_map_shutdown_error
 
+NSPR_API(void) _MD_os2_map_socketpair_error(int err);
+#define	_PR_MD_MAP_SOCKETPAIR_ERROR	_MD_os2_map_socketpair_error
+
 NSPR_API(void) _MD_os2_map_getsockname_error(PRInt32 err);
 #define	_PR_MD_MAP_GETSOCKNAME_ERROR	_MD_os2_map_getsockname_error
 
 NSPR_API(void) _MD_os2_map_getpeername_error(PRInt32 err);
 #define	_PR_MD_MAP_GETPEERNAME_ERROR	_MD_os2_map_getpeername_error
 
 NSPR_API(void) _MD_os2_map_getsockopt_error(PRInt32 err);
 #define	_PR_MD_MAP_GETSOCKOPT_ERROR	_MD_os2_map_getsockopt_error
--- a/pr/include/prio.h
+++ b/pr/include/prio.h
@@ -189,17 +189,17 @@ union PRNetAddr {
     } inet;
     struct {
         PRUint16 family;                /* address family (AF_INET6) */
         PRUint16 port;                  /* port number */
         PRUint32 flowinfo;              /* routing information */
         PRIPv6Addr ip;                  /* the actual 128 bits of address */
         PRUint32 scope_id;              /* set of interfaces for a scope */
     } ipv6;
-#if defined(XP_UNIX)
+#if defined(XP_UNIX) || defined(XP_OS2)
     struct {                            /* Unix domain socket address */
         PRUint16 family;                /* address family (AF_UNIX) */
         char path[104];                 /* null-terminated pathname */
     } local;
 #endif
 };
 
 /*
--- a/pr/include/private/primpl.h
+++ b/pr/include/private/primpl.h
@@ -1390,33 +1390,33 @@ extern PRUintn _PR_NetAddrSize(const PRN
 ** EINVAL.
 **
 ** To pass the correct socket address length to socket
 ** functions, define the macro _PR_HAVE_MD_SOCKADDR_IN6 and
 ** define struct _md_sockaddr_in6 to be isomorphic to
 ** struct sockaddr_in6.
 */
 
-#if defined(XP_UNIX)
+#if defined(XP_UNIX) || defined(XP_OS2)
 #define PR_NETADDR_SIZE(_addr) 					\
         ((_addr)->raw.family == PR_AF_INET		\
         ? sizeof((_addr)->inet)					\
         : ((_addr)->raw.family == PR_AF_INET6	\
         ? sizeof(struct _md_sockaddr_in6)		\
         : sizeof((_addr)->local)))
 #else
 #define PR_NETADDR_SIZE(_addr) 					\
         ((_addr)->raw.family == PR_AF_INET		\
         ? sizeof((_addr)->inet)					\
         : sizeof(struct _md_sockaddr_in6)
 #endif /* defined(XP_UNIX) */
 
 #else
 
-#if defined(XP_UNIX)
+#if defined(XP_UNIX) || defined(XP_OS2)
 #define PR_NETADDR_SIZE(_addr) 					\
         ((_addr)->raw.family == PR_AF_INET		\
         ? sizeof((_addr)->inet)					\
         : ((_addr)->raw.family == PR_AF_INET6	\
         ? sizeof((_addr)->ipv6)					\
         : sizeof((_addr)->local)))
 #else
 #define PR_NETADDR_SIZE(_addr) 					\
--- a/pr/src/Makefile.in
+++ b/pr/src/Makefile.in
@@ -138,16 +138,17 @@ 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
+ADD_TO_DEF_FILE = cat $(srcdir)/os2extra.def >> $(MAPFILE)
 GARBAGE += $(MAPFILE)
 MKSHLIB += $(MAPFILE)
 endif
 
 ifeq ($(OS_ARCH),OSF1)
 ifeq ($(USE_PTHREADS), 1)
 OS_LIBS 	= -lpthread -lrt
 endif
--- a/pr/src/io/prlog.c
+++ b/pr/src/io/prlog.c
@@ -488,18 +488,17 @@ PR_IMPLEMENT(void) PR_Abort(void)
  * Doing the int3 on purpose for Visual Age so that a developer can
  * step over the instruction if so desired.  Not always possible if
  * trapping due to exception handling IBM-AKR
  */
 #if defined(XP_OS2_VACPP)
 #include <builtin.h>
 static void DebugBreak(void) { _interrupt(3); }
 #elif defined(XP_OS2_EMX)
-/* Force a trap */
-static void DebugBreak(void) { int *pTrap=NULL; *pTrap = 1; }
+static void DebugBreak(void) { asm("int $3"); }
 #else
 static void DebugBreak(void) { }
 #endif
 #endif /* XP_OS2 */
 
 PR_IMPLEMENT(void) PR_Assert(const char *s, const char *file, PRIntn ln)
 {
     PR_LogPrint("Assertion failure: %s, at %s:%d\n", s, file, ln);
--- a/pr/src/io/prsocket.c
+++ b/pr/src/io/prsocket.c
@@ -39,34 +39,34 @@
 /************************************************************************/
 
 /* These two functions are only used in assertions. */
 #if defined(DEBUG)
 
 PRBool IsValidNetAddr(const PRNetAddr *addr)
 {
     if ((addr != NULL)
-#ifdef XP_UNIX
+#if defined(XP_UNIX) || defined(XP_OS2)
 	    && (addr->raw.family != PR_AF_LOCAL)
 #endif
 	    && (addr->raw.family != PR_AF_INET6)
 	    && (addr->raw.family != PR_AF_INET)) {
         return PR_FALSE;
     }
     return PR_TRUE;
 }
 
 static PRBool IsValidNetAddrLen(const PRNetAddr *addr, PRInt32 addr_len)
 {
     /*
      * The definition of the length of a Unix domain socket address
      * is not uniform, so we don't check it.
      */
     if ((addr != NULL)
-#ifdef XP_UNIX
+#if defined(XP_UNIX) || defined(XP_OS2)
             && (addr->raw.family != AF_UNIX)
 #endif
             && (PR_NETADDR_SIZE(addr) != addr_len)) {
 #if defined(LINUX) && __GLIBC__ == 2 && __GLIBC_MINOR__ == 1
         /*
          * In glibc 2.1, struct sockaddr_in6 is 24 bytes.  In glibc 2.2
          * and in the 2.4 kernel, struct sockaddr_in6 has the scope_id
          * field and is 28 bytes.  It is possible for socket functions
@@ -1268,17 +1268,17 @@ PR_IMPLEMENT(PRFileDesc*) PR_Socket(PRIn
 {
 	PRInt32 osfd;
 	PRFileDesc *fd;
 	PRInt32 tmp_domain = domain;
 
 	if (!_pr_initialized) _PR_ImplicitInitialization();
 	if (PR_AF_INET != domain
 			&& PR_AF_INET6 != domain
-#if defined(XP_UNIX)
+#if defined(XP_UNIX) || defined(XP_OS2)
 			&& PR_AF_LOCAL != domain
 #endif
 			) {
 		PR_SetError(PR_ADDRESS_NOT_SUPPORTED_ERROR, 0);
 		return NULL;
 	}
 
 #if defined(_PR_INET6_PROBE)
--- a/pr/src/linking/prlink.c
+++ b/pr/src/linking/prlink.c
@@ -157,17 +157,17 @@ struct _imcb *IAC$GL_IMAGE_LIST = NULL;
 #define MAX_DEVNAM 64
 #define MAX_FILNAM 255
 #endif  /* VMS */
 
 /*
  * On these platforms, symbols have a leading '_'.
  */
 #if defined(SUNOS4) || defined(DARWIN) || defined(NEXTSTEP) \
-    || defined(WIN16) \
+    || defined(WIN16) || defined(XP_OS2) \
     || ((defined(OPENBSD) || defined(NETBSD)) && !defined(__ELF__))
 #define NEED_LEADING_UNDERSCORE
 #endif
 
 #ifdef XP_PC
 typedef PRStaticLinkTable *NODL_PROC(void);
 #endif
 
@@ -934,18 +934,17 @@ pr_LoadLibraryByPathname(const char *nam
     lm->staticTable = NULL;
 
 #ifdef XP_OS2  /* Why isn't all this stuff in MD code?! */
     {
         HMODULE h;
         UCHAR pszError[_MAX_PATH];
         ULONG ulRc = NO_ERROR;
 
-        retry:
-              ulRc = DosLoadModule(pszError, _MAX_PATH, (PSZ) name, &h);
+          ulRc = DosLoadModule(pszError, _MAX_PATH, (PSZ) name, &h);
           if (ulRc != NO_ERROR) {
               oserr = ulRc;
               PR_DELETE(lm);
               goto unlock;
           }
           lm->name = strdup(name);
           lm->dlh  = h;
           lm->next = pr_loadmap;
@@ -1427,16 +1426,19 @@ done:
     PR_ExitMonitor(pr_linker_lock);
     return status;
 }
 
 static void* 
 pr_FindSymbolInLib(PRLibrary *lm, const char *name)
 {
     void *f = NULL;
+#ifdef XP_OS2
+    int rc;
+#endif
 
     if (lm->staticTable != NULL) {
         const PRStaticLinkTable* tp;
         for (tp = lm->staticTable; tp->name; tp++) {
             if (strcmp(name, tp->name) == 0) {
                 return (void*) tp->fp;
             }
         }
@@ -1446,17 +1448,27 @@ pr_FindSymbolInLib(PRLibrary *lm, const 
         */
 #if !defined(WIN16) && !defined(XP_BEOS)
         PR_SetError(PR_FIND_SYMBOL_ERROR, 0);
         return (void*)NULL;
 #endif
     }
     
 #ifdef XP_OS2
-    DosQueryProcAddr(lm->dlh, 0, (PSZ) name, (PFN *) &f);
+    rc = DosQueryProcAddr(lm->dlh, 0, (PSZ) name, (PFN *) &f);
+#if defined(NEED_LEADING_UNDERSCORE)
+    /*
+     * Older plugins (not built using GCC) will have symbols that are not
+     * underscore prefixed.  We check for that here.
+     */
+    if (rc != NO_ERROR) {
+        name++;
+        DosQueryProcAddr(lm->dlh, 0, (PSZ) name, (PFN *) &f);
+    }
+#endif
 #endif  /* XP_OS2 */
 
 #if defined(WIN32) || defined(WIN16)
     f = GetProcAddress(lm->dlh, name);
 #endif  /* WIN32 || WIN16 */
 
 #if defined(XP_MAC) || defined(XP_MACOSX)
 #if defined(NEED_LEADING_UNDERSCORE)
--- a/pr/src/md/os2/Makefile.in
+++ b/pr/src/md/os2/Makefile.in
@@ -58,17 +58,17 @@ CSRCS = \
     $(NULL)
 endif
 
 ifeq ($(MOZ_OS2_TOOLS),VACPP)
 ASFILES = os2vacpp.asm
 endif
 
 ifeq ($(MOZ_OS2_TOOLS),EMX)
-ASFILES = os2emx.s
+ASFILES = os2emx.s os2vaclegacy.s
 endif
 
 TARGETS	= $(OBJS)
 
 INCLUDES = -I$(dist_includedir) -I$(topsrcdir)/pr/include -I$(topsrcdir)/pr/include/private
 
 DEFINES	+= -D_NSPR_BUILD_
 
--- a/pr/src/md/os2/objs.mk
+++ b/pr/src/md/os2/objs.mk
@@ -48,14 +48,14 @@ CSRCS = \
 	os2rng.c     \
 	$(NULL)
 
 ifeq ($(MOZ_OS2_TOOLS),VACPP)
 ASFILES = os2vacpp.asm
 endif
 
 ifeq ($(MOZ_OS2_TOOLS),EMX)
-ASFILES = os2emx.s
+ASFILES = os2emx.s os2vaclegacy.s
 endif
 
 OBJS += $(addprefix md/os2/$(OBJDIR)/,$(CSRCS:.c=.$(OBJ_SUFFIX)))  \
 	$(addprefix md/os2/$(OBJDIR)/,$(ASFILES:.$(ASM_SUFFIX)=.$(OBJ_SUFFIX)))
 
--- a/pr/src/md/os2/os2_errors.c
+++ b/pr/src/md/os2/os2_errors.c
@@ -870,16 +870,40 @@ void _MD_os2_map_shutdown_error(PRInt32 
 			PR_SetError(PR_NOT_CONNECTED_ERROR, err);
 			break;
 		default:
 			PR_SetError(PR_UNKNOWN_ERROR, err);
 			break;
 	}
 }
 
+void _MD_os2_map_socketpair_error(PRInt32 err)
+{
+  switch (err) {
+    case ENOMEM:
+      PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
+      break;
+    case EAFNOSUPPORT:
+      PR_SetError(PR_ADDRESS_NOT_SUPPORTED_ERROR, err);
+      break;
+    case EPROTONOSUPPORT:
+      PR_SetError(PR_PROTOCOL_NOT_SUPPORTED_ERROR, err);
+      break;
+    case EOPNOTSUPP:
+      PR_SetError(PR_NOT_TCP_SOCKET_ERROR, err);
+      break;
+    case EPROTOTYPE:
+      PR_SetError(PR_ADDRESS_NOT_SUPPORTED_ERROR, err);
+      break;
+    default:
+      _MD_os2_map_default_error(err);
+      return;
+  }
+}
+
 void _MD_os2_map_getsockname_error(PRInt32 err)
 {
 	switch (err) {
 		case EBADF:
 			PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
 			break;
 		case ENOTSOCK:
 			PR_SetError(PR_NOT_SOCKET_ERROR, err);
--- a/pr/src/md/os2/os2poll.c
+++ b/pr/src/md/os2/os2poll.c
@@ -237,17 +237,17 @@ retry:
     {
         PRInt32 ticksPerSecond = PR_TicksPerSecond();
         tv.tv_sec = remaining / ticksPerSecond;
         tv.tv_usec = remaining - (ticksPerSecond * tv.tv_sec);
         tv.tv_usec = (PR_USEC_PER_SEC * tv.tv_usec) / ticksPerSecond;
         tvp = &tv;
     }
 
-    ready = _MD_SELECT(maxfd + 1, &rd, &wt, &ex, tvp);
+    ready = bsdselect(maxfd + 1, &rd, &wt, &ex, tvp);
 #else
     switch (timeout)
     {
         case PR_INTERVAL_NO_WAIT:
             msecs = 0;
             break;
         case PR_INTERVAL_NO_TIMEOUT:
             msecs = -1;
@@ -257,17 +257,17 @@ retry:
     }
 
      /* compact array */
     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);
+    ready = os2_select(socks, rd, wt, ex, msecs);
 #endif
 
     if (ready == -1 && errno == EINTR)
     {
         if (timeout == PR_INTERVAL_NO_TIMEOUT)
             goto retry;
         else
         {
@@ -373,156 +373,8 @@ retry:
     }
 
 #ifndef BSD_SELECT
     free(socks);
 #endif
     return ready;
 }
 
-#ifdef XP_OS2_EMX
-HMTX thread_select_mutex = 0;	/* because EMX's select is not thread safe - duh! */
-
-typedef struct _thread_select_st {
-	int		nfds;
-	int		isrdfds;
-	struct _fd_set *readfds;
-	int		iswrfds;
-	struct _fd_set *writefds;
-	int		isexfds;
-	struct _fd_set *exceptfds;
-	int		istimeout;
-	struct timeval	timeout;
-	volatile HEV	event;
-	int		result;
-	int		select_errno;
-	volatile int	done;
-} *pthread_select_t;
-	
-void _thread_select(void * arg)
-{
-	pthread_select_t	self = arg;
-	int			result, chkstdin;
-	struct _fd_set		readfds;
-	struct _fd_set		writefds;
-	struct _fd_set		exceptfds;
-	HEV			event = self->event;
-
-	chkstdin = (self->isrdfds && FD_ISSET(0,self->readfds))?1:0;
-
-	do {
-		struct timeval	timeout = {0L,0L};
-
-
-		if (self->isrdfds) readfds = *self->readfds;
-		if (self->iswrfds) writefds = *self->writefds;
-		if (self->isexfds) exceptfds = *self->exceptfds;
-		
-		if (chkstdin) FD_CLR(0,&readfds);
-
-		if (!thread_select_mutex) 
-			DosCreateMutexSem(NULL,&thread_select_mutex,0,1);
-		else
-			DosRequestMutexSem(thread_select_mutex,SEM_INDEFINITE_WAIT);
-		result = select(
-			self->nfds, 
-			self->isrdfds?&readfds:NULL,
-			self->iswrfds?&writefds:NULL,
-			self->isexfds?&exceptfds:NULL,
-			&timeout);
-		DosReleaseMutexSem(thread_select_mutex);
-
-		if (chkstdin) {
-			int charcount = 0, res;
-			res = ioctl(0,FIONREAD,&charcount);
-			if (res==0 && charcount>0) FD_SET(0,&readfds);
-		}
-				
-		if (result>0) {
-			self->done++;
-			if (self->isrdfds) *self->readfds = readfds;
-			if (self->iswrfds) *self->writefds = writefds;
-			if (self->isexfds) *self->exceptfds = exceptfds;
-		} else
-		if (result) self->done++;
-		else DosSleep(1);
-
-	} while (self->event!=0 && self->done==0);
-
-	if (self->event) {
-		self->select_errno = (result < 0)?errno:0;
-		self->result = result;
-		self->done = 3;
-		DosPostEventSem(event);
-	} else {
-		self->done = 3;
-		free(self);
-	}
-
-}
-
-PRInt32
-_MD_SELECT(int nfds, fd_set *readfds, fd_set *writefds,
-                  fd_set *exceptfds, struct timeval *timeout)
-{
-	pthread_select_t sel;
-	HEV		ev = 0;
-	HTIMER		timer = 0;
-	int		result = 0;
-	APIRET		rc;
-	unsigned long	msecs = SEM_INDEFINITE_WAIT;
-
-	if (timeout) {
-		if (timeout->tv_sec != 0 || timeout->tv_usec != 0) 
-			msecs = (timeout->tv_sec * 1000L) + (timeout->tv_usec / 1000L);
-		else
-			msecs = SEM_IMMEDIATE_RETURN;
-	};
-
-	if (!(sel = (pthread_select_t) malloc(sizeof(struct _thread_select_st)))) {
-		result = -1;
-		errno = ENOMEM;
-	} else {
-		sel->nfds = nfds;
-		sel->isrdfds = readfds?1:0;
-		if (sel->isrdfds) sel->readfds = readfds;
-		sel->iswrfds = writefds?1:0;
-		if (sel->iswrfds) sel->writefds = writefds;
-		sel->isexfds = exceptfds?1:0;
-		if (sel->isexfds) sel->exceptfds = exceptfds;
-		sel->istimeout = timeout?1:0;
-		if (sel->istimeout) sel->timeout = *timeout;
-	
-		rc = DosCreateEventSem(NULL,&ev,0,FALSE);
-
-		sel->event = ev;
-		if (msecs == SEM_IMMEDIATE_RETURN)
-			sel->done = 1;
-		else
-			sel->done = 0;
-
-		if (_beginthread(_thread_select,NULL,65536,(void *)sel) == -1) {
-			result = -1; sel->event = 0;
-			DosCloseEventSem(ev);
-		} else {
-			rc = DosWaitEventSem(ev,msecs);
-			if ((!sel->done) && (msecs != SEM_IMMEDIATE_RETURN)) {	/* Interrupted by other thread or timeout */
-				sel->event = 0;
-				result = 0;
-				errno = ETIMEDOUT;
-				
-			} else {
-				while (sel->done && sel->done != 3) {
-					DosSleep(1);
-				}
-				sel->event = 0;
-				result = sel->result;
-				if (sel->select_errno) errno = sel->select_errno;
-				free(sel);
-			}
-			rc = DosCloseEventSem(ev);
-		}
-	}
-
-	return (result);
-}
-
-#endif
--- a/pr/src/md/os2/os2sock.c
+++ b/pr/src/md/os2/os2sock.c
@@ -95,17 +95,17 @@ PRInt32
     return rv;
 }
 
 PRInt32
 _MD_SocketAvailable(PRFileDesc *fd)
 {
     PRInt32 result;
 
-    if (ioctl(fd->secret->md.osfd, FIONREAD, (char *) &result, sizeof(result)) < 0) {
+    if (so_ioctl(fd->secret->md.osfd, FIONREAD, (char *) &result, sizeof(result)) < 0) {
         PR_SetError(PR_BAD_DESCRIPTOR_ERROR, sock_errno());
         return -1;
     }
     return result;
 }
 
 static PRInt32
 socket_io_wait( PRInt32 osfd, PRInt32 fd_type, PRIntervalTime timeout )
@@ -134,27 +134,27 @@ socket_io_wait( PRInt32 osfd, PRInt32 fd
              */
 #ifdef BSD_SELECT
             tv.tv_sec = _PR_INTERRUPT_CHECK_INTERVAL_SECS;
             tv.tv_usec = 0;
             FD_ZERO(&rd_wr);
             do {
                 FD_SET(osfd, &rd_wr);
                 if (fd_type == READ_FD)
-                    rv = _MD_SELECT(osfd + 1, &rd_wr, NULL, NULL, &tv);
+                    rv = bsdselect(osfd + 1, &rd_wr, NULL, NULL, &tv);
                 else
-                    rv = _MD_SELECT(osfd + 1, NULL, &rd_wr, NULL, &tv);
+                    rv = bsdselect(osfd + 1, NULL, &rd_wr, NULL, &tv);
 #else
             lTimeout = _PR_INTERRUPT_CHECK_INTERVAL_SECS * 1000; 
             do {
                 socks[0] = osfd;
                 if (fd_type == READ_FD)
-                    rv = _MD_SELECT(socks, 1, 0, 0, lTimeout);
+                    rv = os2_select(socks, 1, 0, 0, lTimeout);
                 else
-                    rv = _MD_SELECT(socks, 0, 1, 0, lTimeout);
+                    rv = os2_select(socks, 0, 1, 0, lTimeout);
 #endif                    
                 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);
@@ -166,17 +166,17 @@ socket_io_wait( PRInt32 osfd, PRInt32 fd
         default:
             now = epoch = PR_IntervalNow();
             remaining = timeout;
 #ifdef BSD_SELECT
             FD_ZERO(&rd_wr);
 #endif
             do {
                 /*
-                 * We block in _MD_SELECT for at most
+                 * We block in select for at most
                  * _PR_INTERRUPT_CHECK_INTERVAL_SECS seconds,
                  * so that there is an upper limit on the delay
                  * before the interrupt bit is checked.
                  */
 #ifdef BSD_SELECT
                 wait_for_remaining = PR_TRUE;
                 tv.tv_sec = PR_IntervalToSeconds(remaining);
                 if (tv.tv_sec > _PR_INTERRUPT_CHECK_INTERVAL_SECS) {
@@ -185,52 +185,52 @@ socket_io_wait( PRInt32 osfd, PRInt32 fd
                     tv.tv_usec = 0;
                 } else {
                     tv.tv_usec = PR_IntervalToMicroseconds(
                         remaining -
                         PR_SecondsToInterval(tv.tv_sec));
                 }
                 FD_SET(osfd, &rd_wr);
                 if (fd_type == READ_FD)
-                    rv = _MD_SELECT(osfd + 1, &rd_wr, NULL, NULL, &tv);
+                    rv = bsdselect(osfd + 1, &rd_wr, NULL, NULL, &tv);
                 else
-                    rv = _MD_SELECT(osfd + 1, NULL, &rd_wr, NULL, &tv);
+                    rv = bsdselect(osfd + 1, NULL, &rd_wr, NULL, &tv);
 #else
                 wait_for_remaining = PR_TRUE;
                 lTimeout = PR_IntervalToMilliseconds(remaining);
                 if (lTimeout > _PR_INTERRUPT_CHECK_INTERVAL_SECS * 1000) {
                     wait_for_remaining = PR_FALSE;
                     lTimeout = _PR_INTERRUPT_CHECK_INTERVAL_SECS * 1000;
                 }
                 socks[0] = osfd;
                 if (fd_type == READ_FD)
-                    rv = _MD_SELECT(socks, 1, 0, 0, lTimeout);
+                    rv = os2_select(socks, 1, 0, 0, lTimeout);
                 else
-                    rv = _MD_SELECT(socks, 0, 1, 0, lTimeout);
+                    rv = os2_select(socks, 0, 1, 0, lTimeout);
 #endif
                 /*
                  * we don't consider EINTR a real error
                  */
                 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
+                 * We loop again if select timed out or got interrupted
                  * by a signal, and the timeout deadline has not passed yet.
                  */
                 if (rv == 0 || (rv == -1 && syserror == EINTR)) {
                     /*
-                     * If _MD_SELECT timed out, we know how much time
+                     * If 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;
                         } else {
 #ifdef BSD_SELECT
@@ -534,17 +534,17 @@ PRInt32
       * 3)
       */
     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) {
+    while ((rv = so_writev(osfd, (const struct iovec*)iov, iov_size)) == -1) {
         err = sock_errno();
         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))){
@@ -579,16 +579,30 @@ PRInt32
     PRInt32 rv;
 
     rv = shutdown(fd->secret->md.osfd, how);
     if (rv < 0)
         _PR_MD_MAP_SHUTDOWN_ERROR(sock_errno());
     return rv;
 }
 
+PRInt32
+_PR_MD_SOCKETPAIR(int af, int type, int flags, PRInt32 *osfd)
+{
+    PRInt32 rv, err;
+
+    rv = socketpair(af, type, flags, osfd);
+    if (rv < 0) {
+        err = _MD_ERRNO();
+        _PR_MD_MAP_SOCKETPAIR_ERROR(err);
+    }
+    return rv;
+}
+
+
 PRStatus
 _PR_MD_GETSOCKNAME(PRFileDesc *fd, PRNetAddr *addr, PRUint32 *addrlen)
 {
     PRInt32 rv, err;
 
     rv = getsockname(fd->secret->md.osfd,
                      (struct sockaddr *) addr, (int *)addrlen);
     if (rv < 0) {
@@ -647,15 +661,15 @@ void
     PRInt32 err;
     PRUint32  one = 1;
     
     if (osfd <= 2) {
         /* Don't mess around with stdin, stdout or stderr */
         return;
     }
 
-    err = ioctl( osfd, FIONBIO, (char *) &one, sizeof(one));
+    err = so_ioctl( osfd, FIONBIO, (char *) &one, sizeof(one));
     if ( err != 0 )
     {
         err = sock_errno();
         _PR_MD_MAP_SOCKET_ERROR(err);
     }
 }
--- a/pr/src/md/os2/os2thred.c
+++ b/pr/src/md/os2/os2thred.c
@@ -106,21 +106,20 @@ PRStatus
 PRStatus
 _PR_MD_CREATE_THREAD(PRThread *thread, 
                   void (*start)(void *), 
                   PRThreadPriority priority, 
                   PRThreadScope scope, 
                   PRThreadState state, 
                   PRUint32 stackSize)
 {
-    thread->md.handle = thread->id = (TID) _beginthread(
-                    (void(* _Optlink)(void*))start,
-                    NULL, 
-                    thread->stack->stackSize,
-                    thread);
+    thread->md.handle = thread->id = (TID) _beginthread(start,
+                                                        NULL, 
+                                                        thread->stack->stackSize,
+                                                        thread);
     if(thread->md.handle == -1) {
         return PR_FAILURE;
     }
 
     /*
      * On OS/2, a thread is created with a thread priority of
      * THREAD_PRIORITY_NORMAL
      */
--- a/pr/src/misc/prnetdb.c
+++ b/pr/src/misc/prnetdb.c
@@ -1368,17 +1368,17 @@ PRUintn _PR_NetAddrSize(const PRNetAddr*
     if (AF_INET == addr->raw.family)
         addrsize = sizeof(addr->inet);
     else if (PR_AF_INET6 == addr->raw.family)
 #if defined(_PR_INET6)
         addrsize = sizeof(struct sockaddr_in6);
 #else
         addrsize = sizeof(addr->ipv6);
 #endif
-#if defined(XP_UNIX)
+#if defined(XP_UNIX) || defined(XP_OS2)
     else if (AF_UNIX == addr->raw.family)
         addrsize = sizeof(addr->local);
 #endif
     else addrsize = 0;
 
     return addrsize;
 }  /* _PR_NetAddrSize */
 
--- a/pr/tests/Makefile.in
+++ b/pr/tests/Makefile.in
@@ -230,17 +230,17 @@ else
 endif # NS_USE_GCC
 endif
 
 ifeq ($(OS_ARCH),OS2)
 ifeq ($(MOZ_OS2_TOOLS),VACPP)
   LDOPTS = -NOE -DEBUG -nologo -PMTYPE:VIO
 else
   EXTRA_LIBS = $(OS_LIBS)
-  LDOPTS = -Zmtd -Zomf -Zlinker /PM:VIO -Zlinker /ST:0x30000
+  LDOPTS = -Zomf -Zlinker /PM:VIO -Zlinker /ST:0x64000
 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.
--- a/pr/tests/dll/Makefile.in
+++ b/pr/tests/dll/Makefile.in
@@ -73,22 +73,21 @@ RES=$(OBJDIR)/my.res
 RESNAME=../../../pr/src/nspr.rc
 endif
 endif
 
 ifeq (,$(filter-out WINNT OS2,$(OS_ARCH)))
 IMPORT_LIBRARY	= $(OBJDIR)/my.$(LIB_SUFFIX)
 SHARED_LIBRARY	= $(OBJDIR)/my.dll
 ifeq ($(OS_ARCH), OS2)
-LIBRARY		= $(OBJDIR)/my_s.lib
-# XXX $(LIBRARY) probably doesn't need to be added to TARGETS.
-TARGETS		= $(LIBRARY) $(SHARED_LIBRARY) $(IMPORT_LIBRARY)
-else
+MAPFILE		= $(OBJDIR)/my.def
+GARBAGE		+= $(MAPFILE)
+MKSHLIB		+= $(MAPFILE)
+endif
 TARGETS		= $(SHARED_LIBRARY) $(IMPORT_LIBRARY)
-endif
 else
 ifdef MKSHLIB
 SHARED_LIBRARY	= $(OBJDIR)/libmy.$(DLL_SUFFIX)
 endif
 TARGETS		= $(SHARED_LIBRARY)
 endif
 
 #