Bugzilla bug 129902: sync up the NSPR_PRE_4_2_CLIENT_BRANCH with the NSPR NSPRPUB_PRE_4_2_CLIENT_BRANCH
authorwtc%netscape.com
Thu, 14 Mar 2002 23:21:20 +0000
branchNSPRPUB_PRE_4_2_CLIENT_BRANCH
changeset 2295 8f67766d65ffa1694a8fb3cd56a176ca946bac34
parent 2294 83d15040f951b3385f0f5e9d5953f60966bcdac9
child 2296 ee6e55750a575e0d9f5f896be3fbc48d4e03f444
push idunknown
push userunknown
push dateunknown
bugs129902
Bugzilla bug 129902: sync up the NSPR_PRE_4_2_CLIENT_BRANCH with the NSPR tip. a=dbaron on behalf of drivers@mozilla.org.
Makefile.in
config/Linux.mk
config/prmkdir.bat
configure
configure.in
lib/ds/plarena.c
lib/ds/plvrsion.c
lib/libc/src/plvrsion.c
lib/libc/src/strchr.c
lib/libc/src/strcstr.c
lib/libc/src/strlen.c
lib/libc/src/strpbrk.c
lib/libc/src/strstr.c
lib/prstreams/plvrsion.c
pr/include/md/_hpux.h
pr/include/md/_hpux64.cfg
pr/include/md/_macos.h
pr/include/md/_os2.h
pr/include/md/_os2_errors.h
pr/include/md/_win16.h
pr/include/md/_win95.h
pr/include/prinet.h
pr/include/private/primpl.h
pr/src/io/prfdcach.c
pr/src/io/prio.c
pr/src/io/priometh.c
pr/src/io/prlayer.c
pr/src/io/prlog.c
pr/src/io/prmwait.c
pr/src/io/prsocket.c
pr/src/linking/prlink.c
pr/src/malloc/prmem.c
pr/src/md/mac/macio.c
pr/src/md/mac/macsockotpt.c
pr/src/md/os2/objs.mk
pr/src/md/os2/os2sock.c
pr/src/md/unix/darwin.c
pr/src/md/unix/irix.c
pr/src/md/unix/uxproces.c
pr/src/md/unix/uxrng.c
pr/src/md/unix/uxshm.c
pr/src/md/windows/Makefile.in
pr/src/md/windows/ntthread.c
pr/src/md/windows/w95sock.c
pr/src/md/windows/w95thred.c
pr/src/misc/pralarm.c
pr/src/misc/prdtoa.c
pr/src/misc/prenv.c
pr/src/misc/prerr.c
pr/src/misc/prerr.et
pr/src/misc/prerror.c
pr/src/misc/prinit.c
pr/src/misc/prinrval.c
pr/src/misc/prnetdb.c
pr/src/misc/prsystem.c
pr/src/misc/prtime.c
pr/src/misc/prtpool.c
pr/src/prvrsion.c
pr/src/pthreads/ptio.c
pr/src/pthreads/ptsynch.c
pr/src/pthreads/ptthread.c
pr/src/threads/combined/prucpu.c
pr/src/threads/combined/prustack.c
pr/src/threads/combined/pruthr.c
pr/src/threads/prtpd.c
pr/tests/Makefile.in
pr/tests/sigpipe.c
pr/tests/vercheck.c
--- a/Makefile.in
+++ b/Makefile.in
@@ -105,22 +105,22 @@ release::
 	echo "Manifest-Version: 1.0" > MANIFEST.MF; \
 	echo "" >> MANIFEST.MF; \
 	cd ..; rm -f mdheader.jar; zip $(ZIP_ASCII_OPT) -r mdheader.jar *; \
 	rm -rf META-INF
 ifeq ($(OS_ARCH),WINNT)
 	@if test ! -d $(MDIST)/$(MOD_NAME)/$(BUILD_NUMBER); then \
 		rm -rf $(MDIST)/$(MOD_NAME)/$(BUILD_NUMBER); \
 		echo "making directory $(MDIST)/$(MOD_NAME)/$(BUILD_NUMBER)"; \
-		config/prmkdir.bat $(MDIST_DOS)\\$(MOD_NAME)\\$(BUILD_NUMBER); \
+		$(topsrcdir)/config/prmkdir.bat $(MDIST_DOS)\\$(MOD_NAME)\\$(BUILD_NUMBER); \
 	fi
 	@if test ! -d $(MDIST)/$(MOD_NAME)/$(BUILD_NUMBER)/$(RELEASE_OBJDIR_NAME); then \
 		rm -rf $(MDIST)/$(MOD_NAME)/$(BUILD_NUMBER)/$(RELEASE_OBJDIR_NAME); \
 		echo "making directory $(MDIST)/$(MOD_NAME)/$(BUILD_NUMBER)/$(RELEASE_OBJDIR_NAME)"; \
-		config/prmkdir.bat $(MDIST_DOS)\\$(MOD_NAME)\\$(BUILD_NUMBER)\\$(RELEASE_OBJDIR_NAME); \
+		$(topsrcdir)/config/prmkdir.bat $(MDIST_DOS)\\$(MOD_NAME)\\$(BUILD_NUMBER)\\$(RELEASE_OBJDIR_NAME); \
 	fi
 else
 	@if test ! -d $(MDIST)/$(MOD_NAME)/$(BUILD_NUMBER); then \
 		rm -rf $(MDIST)/$(MOD_NAME)/$(BUILD_NUMBER); \
 		echo "making directory $(MDIST)/$(MOD_NAME)/$(BUILD_NUMBER)"; \
 		$(NSINSTALL) -D $(MDIST)/$(MOD_NAME)/$(BUILD_NUMBER); \
 		chmod 775 $(MDIST)/$(MOD_NAME)/$(BUILD_NUMBER); \
 	fi
--- a/config/Linux.mk
+++ b/config/Linux.mk
@@ -76,17 +76,17 @@ CPU_ARCH_TAG		= _$(CPU_ARCH)
 
 CC			= gcc
 CCC			= g++
 RANLIB			= ranlib
 
 OS_INCLUDES		=
 G++INCLUDES		= -I/usr/include/g++
 
-PLATFORM_FLAGS		= -ansi -Wall -pipe -DLINUX -Dlinux
+PLATFORM_FLAGS		= -ansi -Wall -pipe -DLINUX
 PORT_FLAGS		= -D_POSIX_SOURCE -D_BSD_SOURCE -D_SVID_SOURCE -DHAVE_STRERROR -DHAVE_FCNTL_FILE_LOCKING
 
 OS_CFLAGS		= $(DSO_CFLAGS) $(PLATFORM_FLAGS) $(PORT_FLAGS)
 
 ######################################################################
 # Version-specific stuff
 ######################################################################
 
--- a/config/prmkdir.bat
+++ b/config/prmkdir.bat
@@ -1,18 +1,34 @@
-REM
-REM The contents of this file are subject to the Netscape Public License
-REM Version 1.1 (the "NPL"); you may not use this file except in
-REM compliance with the NPL.  You may obtain a copy of the NPL at
-REM http://www.mozilla.org/NPL/
+REM 
+REM The contents of this file are subject to the Mozilla Public
+REM License Version 1.1 (the "License"); you may not use this file
+REM except in compliance with the License. You may obtain a copy of
+REM the License at http://www.mozilla.org/MPL/
+REM 
+REM Software distributed under the License is distributed on an "AS
+REM IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+REM implied. See the License for the specific language governing
+REM rights and limitations under the License.
+REM 
+REM The Original Code is the Netscape Portable Runtime (NSPR).
 REM 
-REM Software distributed under the NPL is distributed on an "AS IS" basis,
-REM WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
-REM for the specific language governing rights and limitations under the
-REM NPL.
+REM The Initial Developer of the Original Code is Netscape
+REM Communications Corporation.  Portions created by Netscape are 
+REM Copyright (C) 1998-2000 Netscape Communications Corporation.  All
+REM Rights Reserved.
+REM 
+REM Contributor(s):
 REM 
-REM The Initial Developer of this code under the NPL is Netscape
-REM Communications Corporation.  Portions created by Netscape are
-REM Copyright (C) 1998 Netscape Communications Corporation.  All Rights
-REM Reserved.
-REM
+REM Alternatively, the contents of this file may be used under the
+REM terms of the GNU General Public License Version 2 or later (the
+REM "GPL"), in which case the provisions of the GPL are applicable 
+REM instead of those above.  If you wish to allow use of your 
+REM version of this file only under the terms of the GPL and not to
+REM allow others to use your version of this file under the MPL,
+REM indicate your decision by deleting the provisions above and
+REM replace them with the notice and other provisions required by
+REM the GPL.  If you do not delete the provisions above, a recipient
+REM may use your version of this file under either the MPL or the
+REM GPL.
+REM 
 
 mkdir %1
--- a/configure
+++ b/configure
@@ -3310,17 +3310,19 @@ EOF
 
     cat >> confdefs.h <<\EOF
 #define hppa 1
 EOF
 
     DLL_SUFFIX=sl
     DSO_LDOPTS='-b +h $(notdir $@)'
     PR_MD_CSRCS=hpux.c
-    PR_MD_ASFILES=os_HPUX.s
+    if test "$OS_TEST" != "ia64"; then
+        PR_MD_ASFILES=os_HPUX.s
+    fi
     if test -n "$USE_64"; then
         MDCPUCFG_H=_hpux64.cfg
     else
         MDCPUCFG_H=_hpux32.cfg
     fi
     if test -z "$GNU_CC"; then
         CC="$CC -Ae"
         CXX="$CXX -ext"
@@ -3364,17 +3366,17 @@ EOF
 
     if echo "$OS_RELEASE" | egrep '^(B.10.10|B.10.20)' >/dev/null; then
         cat >> confdefs.h <<\EOF
 #define HAVE_INT_LOCALTIME_R 1
 EOF
 
     fi
 
-    if echo "$OS_RELEASE" | egrep '^(B.10.30|B.11.00|B.11.11)' >/dev/null; then
+    if echo "$OS_RELEASE" | egrep '^(B.10.30|B.11.00|B.11.11|B.11.20)' >/dev/null; then
         cat >> confdefs.h <<\EOF
 #define HAVE_POINTER_LOCALTIME_R 1
 EOF
 
     fi
 
     if test "$OS_RELEASE" = "B.10.01"; then
         cat >> confdefs.h <<\EOF
@@ -3423,17 +3425,17 @@ EOF
 
         if test -z "$GNU_CC"; then
             CFLAGS="$CFLAGS +DAportable +DS1.1"
             CXXFLAGS="$CXXFLAGS +DAportable +DS1.1"
         fi
         DEFAULT_IMPL_STRATEGY=_PTH
     fi
 
-    if echo "$OS_RELEASE" | egrep '^(B.11.00|B.11.11)' >/dev/null; then
+    if echo "$OS_RELEASE" | egrep '^(B.11.00|B.11.11|B.11.20)' >/dev/null; then
         cat >> confdefs.h <<\EOF
 #define HPUX10 1
 EOF
 
         cat >> confdefs.h <<\EOF
 #define HPUX11 1
 EOF
 
@@ -3446,21 +3448,31 @@ EOF
 EOF
 
         cat >> confdefs.h <<\EOF
 #define HAVE_FCNTL_FILE_LOCKING 1
 EOF
 
         if test -z "$GNU_CC"; then
             if test -z "$USE_64"; then
-                CFLAGS="$CFLAGS +DAportable +DS2.0"
-                CXXFLAGS="$CXXFLAGS +DAportable +DS2.0"
+                if test "$OS_TEST" = "ia64"; then
+                    CFLAGS="$CFLAGS +DD32"
+                    CXXFLAGS="$CXXFLAGS +DD32"
+                else
+                    CFLAGS="$CFLAGS +DAportable +DS2.0"
+                    CXXFLAGS="$CXXFLAGS +DAportable +DS2.0"
+                fi
             else
-                CFLAGS="$CFLAGS +DA2.0W +DS2.0"
-                CXXFLAGS="$CXXFLAGS +DA2.0W +DS2.0"
+                if test "$OS_TEST" = "ia64"; then
+                    CFLAGS="$CFLAGS +DD64"
+                    CXXFLAGS="$CXXFLAGS +DD64"
+                else
+                    CFLAGS="$CFLAGS +DA2.0W +DS2.0"
+                    CXXFLAGS="$CXXFLAGS +DA2.0W +DS2.0"
+                fi
             fi
         fi
         DEFAULT_IMPL_STRATEGY=_PTH
     fi
 
     if test "$DEFAULT_IMPL_STRATEGY" = "_EMU"; then
         USE_NSPR_THREADS=1
         USE_PTHREADS=
@@ -3632,20 +3644,16 @@ EOF
     cat >> confdefs.h <<\EOF
 #define HAVE_FCNTL_FILE_LOCKING 1
 EOF
 
     cat >> confdefs.h <<\EOF
 #define LINUX 1
 EOF
 
-    cat >> confdefs.h <<\EOF
-#define linux 1
-EOF
-
     CFLAGS="$CFLAGS -ansi -Wall"
     CXXFLAGS="$CXXFLAGS -ansi -Wall"
     MDCPUCFG_H=_linux.cfg
     PR_MD_CSRCS=linux.c
     MKSHLIB='$(CC) $(DSO_LDOPTS) -o $@'
     DSO_CFLAGS=-fPIC
     DSO_LDOPTS='-shared -Wl,-soname -Wl,$(notdir $@)'
     OS_LIBS="$OS_LIBS -lc"
@@ -4137,27 +4145,27 @@ EOF
 EOF
 
     cat >> confdefs.h <<\EOF
 #define _REENTRANT 1
 EOF
 
     ac_safe=`echo "machine/builtins.h" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for machine/builtins.h""... $ac_c" 1>&6
-echo "configure:4146: checking for machine/builtins.h" >&5
+echo "configure:4154: checking for machine/builtins.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 4151 "configure"
+#line 4159 "configure"
 #include "confdefs.h"
 #include <machine/builtins.h>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:4156: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:4164: \"$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
@@ -4662,22 +4670,22 @@ EOF
 
     ;;
    
 esac
 
 if test -z "$SKIP_LIBRARY_CHECKS"; then
 
 echo $ac_n "checking for dlopen""... $ac_c" 1>&6
-echo "configure:4671: checking for dlopen" >&5
+echo "configure:4679: checking for dlopen" >&5
 if eval "test \"`echo '$''{'ac_cv_func_dlopen'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 4676 "configure"
+#line 4684 "configure"
 #include "confdefs.h"
 /* System header to define __stub macros and hopefully few prototypes,
     which can conflict with char dlopen(); 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 dlopen();
@@ -4690,17 +4698,17 @@ int main() {
 #if defined (__stub_dlopen) || defined (__stub___dlopen)
 choke me
 #else
 dlopen();
 #endif
 
 ; return 0; }
 EOF
-if { (eval echo configure:4699: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:4707: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_func_dlopen=yes"
 else
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
   rm -rf conftest*
   eval "ac_cv_func_dlopen=no"
 fi
@@ -4709,36 +4717,36 @@ fi
 
 if eval "test \"`echo '$ac_cv_func_'dlopen`\" = yes"; then
   echo "$ac_t""yes" 1>&6
   :
 else
   echo "$ac_t""no" 1>&6
 
     echo $ac_n "checking for dlopen in -ldl""... $ac_c" 1>&6
-echo "configure:4718: checking for dlopen in -ldl" >&5
+echo "configure:4726: 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 4726 "configure"
+#line 4734 "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:4737: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:4745: \"$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
@@ -4756,23 +4764,23 @@ fi
 
 fi
 
 
 
 
 if test $ac_cv_prog_gcc = yes; then
     echo $ac_n "checking whether ${CC-cc} needs -traditional""... $ac_c" 1>&6
-echo "configure:4765: checking whether ${CC-cc} needs -traditional" >&5
+echo "configure:4773: 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 4771 "configure"
+#line 4779 "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
@@ -4780,17 +4788,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 4789 "configure"
+#line 4797 "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
@@ -4804,22 +4812,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:4813: checking for $ac_func" >&5
+echo "configure:4821: 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 4818 "configure"
+#line 4826 "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();
@@ -4832,17 +4840,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:4841: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:4849: \"$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
@@ -4870,17 +4878,17 @@ if test "${enable_strip+set}" = set; the
    ENABLE_STRIP=1 
 fi
 
 
 
 
 
 echo $ac_n "checking for pthread_create in -lpthreads""... $ac_c" 1>&6
-echo "configure:4879: checking for pthread_create in -lpthreads" >&5
+echo "configure:4887: checking for pthread_create in -lpthreads" >&5
 echo "
     #include <pthread.h> 
     void *foo(void *v) { int a = 1;  } 
     int main() { 
         pthread_t t;
         if (!pthread_create(&t, 0, &foo, 0)) {
             pthread_join(t, 0);
         }
@@ -4892,17 +4900,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:4901: checking for pthread_create in -lpthread" >&5
+echo "configure:4909: checking for pthread_create in -lpthread" >&5
 echo "
     #include <pthread.h> 
     void *foo(void *v) { int a = 1;  } 
     int main() { 
         pthread_t t;
         if (!pthread_create(&t, 0, &foo, 0)) {
             pthread_join(t, 0);
         }
@@ -4914,17 +4922,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:4923: checking for pthread_create in -lc_r" >&5
+echo "configure:4931: checking for pthread_create in -lc_r" >&5
 echo "
     #include <pthread.h> 
     void *foo(void *v) { int a = 1;  } 
     int main() { 
         pthread_t t;
         if (!pthread_create(&t, 0, &foo, 0)) {
             pthread_join(t, 0);
         }
@@ -4936,17 +4944,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:4945: checking for pthread_create in -lc" >&5
+echo "configure:4953: checking for pthread_create in -lc" >&5
 echo "
     #include <pthread.h> 
     void *foo(void *v) { int a = 1;  } 
     int main() { 
         pthread_t t;
         if (!pthread_create(&t, 0, &foo, 0)) {
             pthread_join(t, 0);
         }
@@ -5086,17 +5094,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:5095: checking whether ${CC-cc} accepts -pthread" >&5
+echo "configure:5103: 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
@@ -5109,17 +5117,17 @@ echo "configure:5095: 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:5118: checking whether ${CC-cc} accepts -pthreads" >&5
+echo "configure:5126: 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
@@ -886,17 +886,19 @@ case "$target" in
 *-hpux*)
     AC_DEFINE(XP_UNIX)
     AC_DEFINE(HPUX)
     AC_DEFINE(_HPUX_SOURCE)
     AC_DEFINE(hppa)
     DLL_SUFFIX=sl
     DSO_LDOPTS='-b +h $(notdir $@)'
     PR_MD_CSRCS=hpux.c
-    PR_MD_ASFILES=os_HPUX.s
+    if test "$OS_TEST" != "ia64"; then
+        PR_MD_ASFILES=os_HPUX.s
+    fi
     if test -n "$USE_64"; then
         MDCPUCFG_H=_hpux64.cfg
     else
         MDCPUCFG_H=_hpux32.cfg
     fi
     if test -z "$GNU_CC"; then
         CC="$CC -Ae"
         CXX="$CXX -ext"
@@ -925,17 +927,17 @@ case "$target" in
     if echo "$OS_RELEASE" | egrep '^(B.10.10|B.10.20)' >/dev/null; then
         AC_DEFINE(_PR_NEED_H_ERRNO)
     fi
 
     if echo "$OS_RELEASE" | egrep '^(B.10.10|B.10.20)' >/dev/null; then
         AC_DEFINE(HAVE_INT_LOCALTIME_R)
     fi
 
-    if echo "$OS_RELEASE" | egrep '^(B.10.30|B.11.00|B.11.11)' >/dev/null; then
+    if echo "$OS_RELEASE" | egrep '^(B.10.30|B.11.00|B.11.11|B.11.20)' >/dev/null; then
         AC_DEFINE(HAVE_POINTER_LOCALTIME_R)
     fi
 
     if test "$OS_RELEASE" = "B.10.01"; then
         AC_DEFINE(HPUX10)
         DEFAULT_IMPL_STRATEGY=_EMU
     fi
 
@@ -960,29 +962,39 @@ case "$target" in
         AC_DEFINE(HPUX10_30)
         if test -z "$GNU_CC"; then
             CFLAGS="$CFLAGS +DAportable +DS1.1"
             CXXFLAGS="$CXXFLAGS +DAportable +DS1.1"
         fi
         DEFAULT_IMPL_STRATEGY=_PTH
     fi
 
-    if echo "$OS_RELEASE" | egrep '^(B.11.00|B.11.11)' >/dev/null; then
+    if echo "$OS_RELEASE" | egrep '^(B.11.00|B.11.11|B.11.20)' >/dev/null; then
         AC_DEFINE(HPUX10)
         AC_DEFINE(HPUX11)
         AC_DEFINE(_LARGEFILE64_SOURCE)
         AC_DEFINE(_PR_HAVE_OFF64_T)
         AC_DEFINE(HAVE_FCNTL_FILE_LOCKING)
         if test -z "$GNU_CC"; then
             if test -z "$USE_64"; then
-                CFLAGS="$CFLAGS +DAportable +DS2.0"
-                CXXFLAGS="$CXXFLAGS +DAportable +DS2.0"
+                if test "$OS_TEST" = "ia64"; then
+                    CFLAGS="$CFLAGS +DD32"
+                    CXXFLAGS="$CXXFLAGS +DD32"
+                else
+                    CFLAGS="$CFLAGS +DAportable +DS2.0"
+                    CXXFLAGS="$CXXFLAGS +DAportable +DS2.0"
+                fi
             else
-                CFLAGS="$CFLAGS +DA2.0W +DS2.0"
-                CXXFLAGS="$CXXFLAGS +DA2.0W +DS2.0"
+                if test "$OS_TEST" = "ia64"; then
+                    CFLAGS="$CFLAGS +DD64"
+                    CXXFLAGS="$CXXFLAGS +DD64"
+                else
+                    CFLAGS="$CFLAGS +DA2.0W +DS2.0"
+                    CXXFLAGS="$CXXFLAGS +DA2.0W +DS2.0"
+                fi
             fi
         fi
         DEFAULT_IMPL_STRATEGY=_PTH
     fi
 
     if test "$DEFAULT_IMPL_STRATEGY" = "_EMU"; then
         USE_NSPR_THREADS=1
         USE_PTHREADS=
@@ -1104,17 +1116,16 @@ case "$target" in
     fi
     AC_DEFINE(XP_UNIX)
     AC_DEFINE(_POSIX_SOURCE)
     AC_DEFINE(_BSD_SOURCE)
     AC_DEFINE(_SVID_SOURCE)
     AC_DEFINE(_LARGEFILE64_SOURCE)
     AC_DEFINE(HAVE_FCNTL_FILE_LOCKING)
     AC_DEFINE(LINUX)
-    AC_DEFINE(linux)
     CFLAGS="$CFLAGS -ansi -Wall"
     CXXFLAGS="$CXXFLAGS -ansi -Wall"
     MDCPUCFG_H=_linux.cfg
     PR_MD_CSRCS=linux.c
     MKSHLIB='$(CC) $(DSO_LDOPTS) -o $@'
     DSO_CFLAGS=-fPIC
     DSO_LDOPTS='-shared -Wl,-soname -Wl,$(notdir $@)'
     OS_LIBS="$OS_LIBS -lc"
--- a/lib/ds/plarena.c
+++ b/lib/ds/plarena.c
@@ -61,17 +61,17 @@ static PLArenaStats *arena_stats_list;
 static PRLock    *arenaLock;
 static PRCallOnceType once;
 
 /*
 ** InitializeArenas() -- Initialize arena operations.
 **
 ** InitializeArenas() is called exactly once and only once from 
 ** LockArena(). This function creates the arena protection 
-** monitor: arenaLock.
+** lock: arenaLock.
 **
 ** Note: If the arenaLock cannot be created, InitializeArenas()
 ** fails quietly, returning only PR_FAILURE. This percolates up
 ** to the application using the Arena API. He gets no arena
 ** from PL_ArenaAllocate(). It's up to him to fail gracefully
 ** or recover.
 **
 */
@@ -334,27 +334,30 @@ PR_IMPLEMENT(void) PL_CompactArenaPool(P
         reallocSmaller(curr, curr->avail - (uprword_t)curr);
         curr->limit = curr->avail;
         curr = curr->next;
     }
 #endif
 #endif
 }
 
-PR_IMPLEMENT(void) PL_ArenaFinish()
+PR_IMPLEMENT(void) PL_ArenaFinish(void)
 {
     PLArena *a, *next;
 
-    LockArena();
     for (a = arena_freelist; a; a = next) {
         next = a->next;
         PR_DELETE(a);
     }
     arena_freelist = NULL;
-    UnlockArena();
+
+    if (arenaLock) {
+        PR_DestroyLock(arenaLock);
+        arenaLock = NULL;
+    }
 }
 
 #ifdef PL_ARENAMETER
 PR_IMPLEMENT(void) PL_ArenaCountAllocation(PLArenaPool *pool, PRUint32 nb)
 {
     pool->stats.nallocs++;
     pool->stats.nbytes += nb;
     if (nb > pool->stats.maxalloc)
--- a/lib/ds/plvrsion.c
+++ b/lib/ds/plvrsion.c
@@ -79,17 +79,17 @@ PRVersionDescription VERSION_DESC_NAME =
 #else
     /* debug            */  PR_FALSE,           /* an optomized build */
 #endif
     /* special          */  PR_FALSE,           /* they're all special, but ... */
     /* filename         */  _PRODUCTION,        /* the produced library name */
     /* description      */ "Portable runtime",  /* what we are */
     /* security         */ "N/A",               /* not applicable here */
     /* copywrite        */  "Copyright (c) 1998 Netscape Communications Corporation. All Rights Reserved",
-    /* comment          */  "http://www.mozilla.org/NPL/",
+    /* comment          */  "http://www.mozilla.org/MPL/",
     /* specialString    */ ""
 };
 
 #ifdef XP_UNIX
 
 /*
  * Version information for the 'ident' and 'what commands
  *
--- a/lib/libc/src/plvrsion.c
+++ b/lib/libc/src/plvrsion.c
@@ -79,17 +79,17 @@ PRVersionDescription VERSION_DESC_NAME =
 #else
     /* debug            */  PR_FALSE,           /* an optomized build */
 #endif
     /* special          */  PR_FALSE,           /* they're all special, but ... */
     /* filename         */  _PRODUCTION,        /* the produced library name */
     /* description      */ "Portable runtime",  /* what we are */
     /* security         */ "N/A",               /* not applicable here */
     /* copywrite        */  "Copyright (c) 1998 Netscape Communications Corporation. All Rights Reserved",
-    /* comment          */  "http://www.mozilla.org/NPL/",
+    /* comment          */  "http://www.mozilla.org/MPL/",
     /* specialString    */ ""
 };
 
 #ifdef XP_UNIX
 
 /*
  * Version information for the 'ident' and 'what commands
  *
--- a/lib/libc/src/strchr.c
+++ b/lib/libc/src/strchr.c
@@ -65,35 +65,35 @@ PL_strrchr(const char *s, char c)
     return (char *)0;
 }
 
 PR_IMPLEMENT(char *)
 PL_strnchr(const char *s, char c, PRUint32 n)
 {
     if( (const char *)0 == s ) return (char *)0;
 
-    for( ; *s && n; s++, n-- )
+    for( ; n && *s; s++, n-- )
         if( *s == c )
             return (char *)s;
 
-    if( ((char)0 == c) && ((char)0 == *s) && (n > 0)) return (char *)s;
+    if( ((char)0 == c) && (n > 0) && ((char)0 == *s) ) return (char *)s;
 
     return (char *)0;
 }
 
 PR_IMPLEMENT(char *)
 PL_strnrchr(const char *s, char c, PRUint32 n)
 {
     const char *p;
 
     if( (const char *)0 == s ) return (char *)0;
 
-    for( p = s; *p && n; p++, n-- )
+    for( p = s; n && *p; p++, n-- )
         ;
 
-    if( ((char)0 == c) && ((char)0 == *p) && (n > 0) ) return (char *)p;
+    if( ((char)0 == c) && (n > 0) && ((char)0 == *p) ) return (char *)p;
 
     for( p--; p >= s; p-- )
         if( *p == c )
             return (char *)p;
 
     return (char *)0;
 }
--- a/lib/libc/src/strcstr.c
+++ b/lib/libc/src/strcstr.c
@@ -81,17 +81,17 @@ PL_strncasestr(const char *big, const ch
     if( ((const char *)0 == big) || ((const char *)0 == little) ) return (char *)0;
     if( ((char)0 == *big) || ((char)0 == *little) ) return (char *)0;
 
     ll = PL_strlen(little);
     if( ll > max ) return (char *)0;
     max -= ll;
     max++;
 
-    for( ; *big && max; big++, max-- )
+    for( ; max && *big; big++, max-- )
         /* obvious improvement available here */
             if( 0 == PL_strncasecmp(big, little, ll) )
                 return (char *)big;
 
     return (char *)0;
 }
 
 PR_IMPLEMENT(char *)
@@ -100,17 +100,17 @@ PL_strncaserstr(const char *big, const c
     const char *p;
     PRUint32 ll;
 
     if( ((const char *)0 == big) || ((const char *)0 == little) ) return (char *)0;
     if( ((char)0 == *big) || ((char)0 == *little) ) return (char *)0;
 
     ll = PL_strlen(little);
 
-    for( p = big; *p && max; p++, max-- )
+    for( p = big; max && *p; p++, max-- )
         ;
 
     p -= ll;
     if( p < big ) return (char *)0;
 
     for( ; p >= big; p-- )
         /* obvious improvement available here */
             if( 0 == PL_strncasecmp(p, little, ll) )
--- a/lib/libc/src/strlen.c
+++ b/lib/libc/src/strlen.c
@@ -54,13 +54,13 @@ PL_strlen(const char *str)
 }
 
 PR_IMPLEMENT(PRUint32)
 PL_strnlen(const char *str, PRUint32 max)
 {
     register const char *s;
 
     if( (const char *)0 == str ) return 0;
-    for( s = str; *s && max; s++, max-- )
+    for( s = str; max && *s; s++, max-- )
         ;
 
     return (PRUint32)(s - str);
 }
--- a/lib/libc/src/strpbrk.c
+++ b/lib/libc/src/strpbrk.c
@@ -70,33 +70,33 @@ PL_strprbrk(const char *s, const char *l
 
 PR_IMPLEMENT(char *)
 PL_strnpbrk(const char *s, const char *list, PRUint32 max)
 {
     const char *p;
 
     if( ((const char *)0 == s) || ((const char *)0 == list) ) return (char *)0;
 
-    for( ; *s && max; s++, max-- )
+    for( ; max && *s; s++, max-- )
         for( p = list; *p; p++ )
             if( *s == *p )
                 return (char *)s;
 
     return (char *)0;
 }
 
 PR_IMPLEMENT(char *)
 PL_strnprbrk(const char *s, const char *list, PRUint32 max)
 {
     const char *p;
     const char *r;
 
     if( ((const char *)0 == s) || ((const char *)0 == list) ) return (char *)0;
 
-    for( r = s; *r && max; r++, max-- )
+    for( r = s; max && *r; r++, max-- )
         ;
 
     for( r--; r >= s; r-- )
         for( p = list; *p; p++ )
             if( *r == *p )
                 return (char *)r;
 
     return (char *)0;
--- a/lib/libc/src/strstr.c
+++ b/lib/libc/src/strstr.c
@@ -81,17 +81,17 @@ PL_strnstr(const char *big, const char *
     if( ((const char *)0 == big) || ((const char *)0 == little) ) return (char *)0;
     if( ((char)0 == *big) || ((char)0 == *little) ) return (char *)0;
 
     ll = PL_strlen(little);
     if( ll > max ) return (char *)0;
     max -= ll;
     max++;
 
-    for( ; *big && max; big++, max-- )
+    for( ; max && *big; big++, max-- )
         if( *little == *big )
             if( 0 == PL_strncmp(big, little, ll) )
                 return (char *)big;
 
     return (char *)0;
 }
 
 PR_IMPLEMENT(char *)
@@ -100,17 +100,17 @@ PL_strnrstr(const char *big, const char 
     const char *p;
     PRUint32 ll;
 
     if( ((const char *)0 == big) || ((const char *)0 == little) ) return (char *)0;
     if( ((char)0 == *big) || ((char)0 == *little) ) return (char *)0;
 
     ll = PL_strlen(little);
 
-    for( p = big; *p && max; p++, max-- )
+    for( p = big; max && *p; p++, max-- )
         ;
 
     p -= ll;
     if( p < big ) return (char *)0;
 
     for( ; p >= big; p-- )
         if( *little == *p )
             if( 0 == PL_strncmp(p, little, ll) )
--- a/lib/prstreams/plvrsion.c
+++ b/lib/prstreams/plvrsion.c
@@ -79,17 +79,17 @@ PRVersionDescription VERSION_DESC_NAME =
 #else
     /* debug            */  PR_FALSE,           /* an optomized build */
 #endif
     /* special          */  PR_FALSE,           /* they're all special, but ... */
     /* filename         */  _PRODUCTION,        /* the produced library name */
     /* description      */ "Portable runtime",  /* what we are */
     /* security         */ "N/A",               /* not applicable here */
     /* copywrite        */  "Copyright (c) 1998 Netscape Communications Corporation. All Rights Reserved",
-    /* comment          */  "http://www.mozilla.org/NPL/",
+    /* comment          */  "http://www.mozilla.org/MPL/",
     /* specialString    */ ""
 };
 
 #ifdef XP_UNIX
 
 /*
  * Version information for the 'ident' and 'what commands
  *
--- a/pr/include/md/_hpux.h
+++ b/pr/include/md/_hpux.h
@@ -50,17 +50,21 @@
 #define _MD_MMAP_FLAGS          MAP_PRIVATE
 
 #define NEED_TIME_R
 
 #define HAVE_STACK_GROWING_UP
 #undef	HAVE_WEAK_IO_SYMBOLS
 #undef	HAVE_WEAK_MALLOC_SYMBOLS
 #define	HAVE_DLL
+#ifdef IS_64
+#define USE_DLFCN
+#else
 #define USE_HPSHL
+#endif
 #ifndef HAVE_STRERROR
 #define HAVE_STRERROR
 #endif
 #define _PR_POLL_AVAILABLE
 #define _PR_USE_POLL
 /*
  * OSF1 and HPUX report the POLLHUP event for a socket when the
  * shutdown(SHUT_WR) operation is called for the remote end, even though
--- a/pr/include/md/_hpux64.cfg
+++ b/pr/include/md/_hpux64.cfg
@@ -77,18 +77,18 @@
 #define PR_BITS_PER_INT64_LOG2  6
 #define PR_BITS_PER_LONG_LOG2   6
 #define PR_BITS_PER_FLOAT_LOG2  5
 #define PR_BITS_PER_DOUBLE_LOG2 6
 #define PR_BITS_PER_WORD_LOG2   6
 
 #define PR_ALIGN_OF_SHORT   2
 #define PR_ALIGN_OF_INT     4
-#define PR_ALIGN_OF_LONG    4
-#define PR_ALIGN_OF_INT64   4
+#define PR_ALIGN_OF_LONG    8
+#define PR_ALIGN_OF_INT64   8
 #define PR_ALIGN_OF_FLOAT   4
 #define PR_ALIGN_OF_DOUBLE  8
 #define PR_ALIGN_OF_POINTER 8
 
 #define	HAVE_LONG_LONG
 #define	HAVE_ALIGNED_DOUBLES
 #define	HAVE_ALIGNED_LONGLONGS
 
--- a/pr/include/md/_macos.h
+++ b/pr/include/md/_macos.h
@@ -117,17 +117,17 @@ struct _MDFileDesc {
     PRInt32         osfd;
     PRPackedBool    orderlyDisconnect;
     PRPackedBool    readReady;
     PRPackedBool    writeReady;
     PRPackedBool    exceptReady;
     PRLock *        miscLock;
 
     /* Server sockets: listen bit tells the notifier func what to do */
-    PRBool		    doListen;
+    PRBool          doListen;
 
     /* stored error for non-blocking connects, as a Unix-style error code */
     OTReason        disconnectError;
 
     _MDSocketCallerInfo  misc;
     _MDSocketCallerInfo  read;
     _MDSocketCallerInfo  write;
 };
--- a/pr/include/md/_os2.h
+++ b/pr/include/md/_os2.h
@@ -284,17 +284,17 @@ extern PRInt32 _MD_CloseFile(PRInt32 osf
 #endif  
 
 #define _MD_INIT_FILEDESC(fd)
 extern void _MD_MakeNonblock(PRFileDesc *f);
 #define _MD_MAKE_NONBLOCK             _MD_MakeNonblock
 #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(s, backlog)        listen(s->secret->md.osfd,backlog)
+#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_GETSOCKNAME               (_PR_MD_GETSOCKNAME)
 #define _MD_GETPEERNAME               (_PR_MD_GETPEERNAME)
 #define _MD_GETSOCKOPT                (_PR_MD_GETSOCKOPT)
--- a/pr/include/md/_os2_errors.h
+++ b/pr/include/md/_os2_errors.h
@@ -35,16 +35,19 @@
 #ifndef nspr_os2_errors_h___
 #define nspr_os2_errors_h___
 
 #include "md/_os2.h"
 #ifndef assert
   #include <assert.h>
 #endif  
 
+NSPR_API(void) _MD_os2_map_default_error(PRInt32 err);
+#define	_PR_MD_MAP_DEFAULT_ERROR	_MD_os2_map_default_error
+
 NSPR_API(void) _MD_os2_map_opendir_error(PRInt32 err);
 #define	_PR_MD_MAP_OPENDIR_ERROR	_MD_os2_map_opendir_error
 
 NSPR_API(void) _MD_os2_map_closedir_error(PRInt32 err);
 #define	_PR_MD_MAP_CLOSEDIR_ERROR	_MD_os2_map_closedir_error
 
 NSPR_API(void) _MD_os2_readdir_error(PRInt32 err);
 #define	_PR_MD_MAP_READDIR_ERROR	_MD_os2_readdir_error
--- a/pr/include/md/_win16.h
+++ b/pr/include/md/_win16.h
@@ -438,23 +438,16 @@ NSPR_API(void) _MD_INIT_RUNNING_CPU(stru
 ** Watcom needs to see this to make the linker work.
 **
 */
 NSPR_API(void) _PR_NativeDestroyThread(PRThread *thread);
 NSPR_API(void) _PR_UserDestroyThread(PRThread *thread);
 
 
 /*
- * _PR_ShutdownLinker unloads all dlls loaded by the application via
- * calls to PR_LoadLibrary
- */
-void _PR_ShutdownLinker(void);
-
-
-/*
 ** If thread emulation is used, then setjmp/longjmp stores the register
 ** state of each thread.
 **
 ** CatchBuf layout:
 **  context[0] - IP
 **  context[1] - CS
 **  context[2] - SP
 **  context[3] - BP
--- a/pr/include/md/_win95.h
+++ b/pr/include/md/_win95.h
@@ -238,17 +238,17 @@ extern PRInt32 _MD_CloseFile(PRInt32 osf
 #define _MD_SET_SOCKET_ERROR(_err) WSASetLastError(_err)
 
 #define _MD_INIT_FILEDESC(fd)
 extern void _MD_MakeNonblock(PRFileDesc *f);
 #define _MD_MAKE_NONBLOCK             _MD_MakeNonblock
 #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(s, backlog)        listen(s->secret->md.osfd,backlog)
+#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_GETSOCKNAME               _PR_MD_GETSOCKNAME
 #define _MD_GETPEERNAME               _PR_MD_GETPEERNAME
 #define _MD_GETSOCKOPT                _PR_MD_GETSOCKOPT
--- a/pr/include/prinet.h
+++ b/pr/include/prinet.h
@@ -52,17 +52,17 @@
  *     This file is intended to be included by nspr20 public header
  *     files, such as prio.h.  One should not include this file directly.
  */
 
 #ifndef prinet_h__
 #define prinet_h__
 
 #if defined(XP_UNIX) || defined(XP_OS2) || defined(XP_BEOS)
-#ifdef linux
+#ifdef LINUX
 #undef __STRICT_ANSI__
 #define __STRICT_ANSI__
 #endif
 #include <sys/types.h>
 #include <sys/socket.h>		/* AF_INET */
 #include <netinet/in.h>         /* INADDR_ANY, ..., ntohl(), ... */
 #ifdef XP_OS2
 #include <sys/ioctl.h>
--- a/pr/include/private/primpl.h
+++ b/pr/include/private/primpl.h
@@ -735,20 +735,16 @@ extern PRLock *_pr_terminationCVLock;
 * code.                                                                  *
 *************************************************************************/
 
 extern void _PR_ClockInterrupt(void);
 
 extern void _PR_Schedule(void);
 extern void _PR_SetThreadPriority(
     PRThread* thread, PRThreadPriority priority);
-NSPR_API(void) _PR_Unlock(PRLock *lock);
-
-NSPR_API(void) _PR_SuspendThread(PRThread *t);
-NSPR_API(void) _PR_ResumeThread(PRThread *t);
 
 /***********************************************************************
 ** FUNCTION:	_PR_NewSegment()
 ** DESCRIPTION:
 **   Allocate a memory segment. The "size" value is rounded up to the
 **   native system page size and a page aligned portion of memory is
 **   returned.  This memory is not part of the malloc heap. If "vaddr" is
 **   not NULL then PR tries to allocate the segment at the desired virtual
@@ -1740,16 +1736,26 @@ extern void _PR_InitClock(void);
 extern void _PR_InitLinker(void);
 extern void _PR_InitAtomic(void);
 extern void _PR_InitCPUs(void);
 extern void _PR_InitDtoa(void);
 extern void _PR_InitMW(void);
 extern void _PR_InitRWLocks(void);
 extern void _PR_NotifyCondVar(PRCondVar *cvar, PRThread *me);
 extern void _PR_CleanupThread(PRThread *thread);
+extern void _PR_CleanupCallOnce(void);
+extern void _PR_CleanupMW(void);
+extern void _PR_CleanupDtoa(void);
+extern void _PR_ShutdownLinker(void);
+extern void _PR_CleanupEnv(void);
+extern void _PR_CleanupIO(void);
+extern void _PR_CleanupNet(void);
+extern void _PR_CleanupLayerCache(void);
+extern void _PR_CleanupStacks(void);
+extern void _PR_CleanupThreads(void);
 extern void _PR_CleanupTPD(void);
 extern void _PR_Cleanup(void);
 extern void _PR_LogCleanup(void);
 extern void _PR_InitLayerCache(void);
 #ifdef GC_LEAK_DETECTOR
 extern void _PR_InitGarbageCollector(void);
 #endif
 
@@ -1794,17 +1800,17 @@ extern PRFileDesc *_pr_stderr;
 /* Zone allocator */
 /*
 ** The zone allocator code has hardcoded pthread types and
 ** functions, so it can only be used in the pthreads version.
 ** This can be fixed by replacing the hardcoded pthread types
 ** and functions with macros that expand to the native thread
 ** types and functions on each platform.
 */
-#if defined(_PR_PTHREADS)
+#if defined(_PR_PTHREADS) && !defined(_PR_DCETHREADS)
 #define _PR_ZONE_ALLOCATOR
 #endif
 
 #ifdef _PR_ZONE_ALLOCATOR
 extern void _PR_InitZones(void);
 extern void _PR_DestroyZones(void);
 #endif
 
--- a/pr/src/io/prfdcach.c
+++ b/pr/src/io/prfdcach.c
@@ -68,17 +68,17 @@ typedef struct _PR_Fd_Cache
 static _PR_Fd_Cache _pr_fd_cache;
 static PRFileDesc **stack2fd = &(((PRFileDesc*)NULL)->higher);
 
 
 /*
 ** Get a FileDescriptor from the cache if one exists. If not allocate
 ** a new one from the heap.
 */
-PRFileDesc *_PR_Getfd()
+PRFileDesc *_PR_Getfd(void)
 {
     PRFileDesc *fd;
     /*
     ** $$$
     ** This may look a little wasteful. We'll see. Right now I want to
     ** be able to toggle between caching and not at runtime to measure
     ** the differences. If it isn't too annoying, I'll leave it in.
     ** $$$$
@@ -243,17 +243,17 @@ PR_IMPLEMENT(PRStatus) PR_SetFDCacheSize
                 _pr_fd_cache.count += 1;
             }
         }
     }
     PR_Unlock(_pr_fd_cache.ml);
     return PR_SUCCESS;
 }  /* PR_SetFDCacheSize */
 
-void _PR_InitFdCache()
+void _PR_InitFdCache(void)
 {
     /*
     ** The fd caching is enabled by default for DEBUG builds,
     ** disabled by default for OPT builds. That default can
     ** be overridden at runtime using environment variables
     ** or a super-wiz-bang API.
     */
     const char *low = PR_GetEnv("NSPR_FD_CACHE_SIZE_LOW");
--- a/pr/src/io/prio.c
+++ b/pr/src/io/prio.c
@@ -70,16 +70,37 @@ void _PR_InitIO(void)
 #endif
     _PR_MD_INIT_FD_INHERITABLE(_pr_stdin, PR_TRUE);
     _PR_MD_INIT_FD_INHERITABLE(_pr_stdout, PR_TRUE);
     _PR_MD_INIT_FD_INHERITABLE(_pr_stderr, PR_TRUE);
 
     _PR_MD_INIT_IO();
 }
 
+void _PR_CleanupIO(void)
+{
+    PR_FreeFileDesc(_pr_stdin);
+    _pr_stdin = NULL;
+    PR_FreeFileDesc(_pr_stdout);
+    _pr_stdout = NULL;
+    PR_FreeFileDesc(_pr_stderr);
+    _pr_stderr = NULL;
+
+    if (_pr_flock_cv) {
+        PR_DestroyCondVar(_pr_flock_cv);
+        _pr_flock_cv = NULL;
+    }
+    if (_pr_flock_lock) {
+        PR_DestroyLock(_pr_flock_lock);
+        _pr_flock_lock = NULL;
+    }
+
+    _PR_CleanupFdCache();
+}
+
 PR_IMPLEMENT(PRFileDesc*) PR_GetSpecialFD(PRSpecialFD osfd)
 {
     PRFileDesc *result = NULL;
     PR_ASSERT((int) osfd >= PR_StandardInput && osfd <= PR_StandardError);
 
     if (!_pr_initialized) _PR_ImplicitInitialization();
     
     switch (osfd)
--- a/pr/src/io/priometh.c
+++ b/pr/src/io/priometh.c
@@ -71,55 +71,55 @@ PRIOMethods _pr_faulty_methods = {
     (PRSendfileFN)_PR_InvalidInt, 
     (PRConnectcontinueFN)_PR_InvalidStatus,
     (PRReservedFN)_PR_InvalidInt,
     (PRReservedFN)_PR_InvalidInt,
     (PRReservedFN)_PR_InvalidInt,
     (PRReservedFN)_PR_InvalidInt
 };
 
-PRIntn _PR_InvalidInt()
+PRIntn _PR_InvalidInt(void)
 {
     PR_ASSERT(!"I/O method is invalid");
     PR_SetError(PR_INVALID_METHOD_ERROR, 0);
     return -1;
 }  /* _PR_InvalidInt */
 
-PRInt16 _PR_InvalidInt16()
+PRInt16 _PR_InvalidInt16(void)
 {
     PR_ASSERT(!"I/O method is invalid");
     PR_SetError(PR_INVALID_METHOD_ERROR, 0);
     return -1;
 }  /* _PR_InvalidInt */
 
-PRInt64 _PR_InvalidInt64()
+PRInt64 _PR_InvalidInt64(void)
 {
     PRInt64 rv;
     LL_I2L(rv, -1);
     PR_ASSERT(!"I/O method is invalid");
     PR_SetError(PR_INVALID_METHOD_ERROR, 0);
     return rv;
 }  /* _PR_InvalidInt */
 
 /*
  * An invalid method that returns PRStatus
  */
 
-PRStatus _PR_InvalidStatus()
+PRStatus _PR_InvalidStatus(void)
 {
     PR_ASSERT(!"I/O method is invalid");
     PR_SetError(PR_INVALID_METHOD_ERROR, 0);
     return PR_FAILURE;
 }  /* _PR_InvalidDesc */
 
 /*
  * An invalid method that returns a pointer
  */
 
-PRFileDesc *_PR_InvalidDesc()
+PRFileDesc *_PR_InvalidDesc(void)
 {
     PR_ASSERT(!"I/O method is invalid");
     PR_SetError(PR_INVALID_METHOD_ERROR, 0);
     return NULL;
 }  /* _PR_InvalidDesc */
 
 PR_IMPLEMENT(PRDescType) PR_GetDescType(PRFileDesc *file)
 {
--- a/pr/src/io/prlayer.c
+++ b/pr/src/io/prlayer.c
@@ -454,17 +454,17 @@ static PRIOMethods pl_methods = {
     pl_DefSendfile,
     pl_DefConnectcontinue,
     (PRReservedFN)_PR_InvalidInt,
     (PRReservedFN)_PR_InvalidInt,
     (PRReservedFN)_PR_InvalidInt,
     (PRReservedFN)_PR_InvalidInt
 };
 
-PR_IMPLEMENT(const PRIOMethods*) PR_GetDefaultIOMethods()
+PR_IMPLEMENT(const PRIOMethods*) PR_GetDefaultIOMethods(void)
 {
     return &pl_methods;
 }  /* PR_GetDefaultIOMethods */
 
 PR_IMPLEMENT(PRFileDesc*) PR_CreateIOLayerStub(
     PRDescIdentity ident, const PRIOMethods *methods)
 {
     PRFileDesc *fd = NULL;
@@ -731,16 +731,35 @@ PR_IMPLEMENT(PRFileDesc*) PR_GetIdentiti
     }
     for (layer = fd; layer != NULL; layer = layer->higher)
     {
         if (id == layer->identity) return layer;
     }
     return NULL;
 }  /* PR_GetIdentitiesLayer */
 
-void _PR_InitLayerCache()
+void _PR_InitLayerCache(void)
 {
     memset(&identity_cache, 0, sizeof(identity_cache));
     identity_cache.ml = PR_NewLock();
     PR_ASSERT(NULL != identity_cache.ml);
 }  /* _PR_InitLayerCache */
 
+void _PR_CleanupLayerCache(void)
+{
+    if (identity_cache.ml)
+    {
+        PR_DestroyLock(identity_cache.ml);
+        identity_cache.ml = NULL;
+    }
+
+    if (identity_cache.name)
+    {
+        PRDescIdentity ident;
+
+        for (ident = 0; ident <= identity_cache.ident; ident++)
+            PR_DELETE(identity_cache.name[ident]);
+
+        PR_DELETE(identity_cache.name);
+    }
+}  /* _PR_CleanupLayerCache */
+
 /* prlayer.c */
--- a/pr/src/io/prlog.c
+++ b/pr/src/io/prlog.c
@@ -272,21 +272,26 @@ void _PR_LogCleanup(void)
 #else
     if (logFile && logFile != _pr_stdout && logFile != _pr_stderr) {
         PR_Close(logFile);
     }
 #endif
 
     while (lm != NULL) {
         PRLogModuleInfo *next = lm->next;
-        PR_Free((/*const*/ char *)lm->name);
+        free((/*const*/ char *)lm->name);
         PR_Free(lm);
         lm = next;
     }
     logModules = NULL;
+
+    if (_pr_logLock) {
+        PR_DestroyLock(_pr_logLock);
+        _pr_logLock = NULL;
+    }
 }
 
 static void _PR_SetLogModuleLevel( PRLogModuleInfo *lm )
 {
     char *ev;
 
     ev = PR_GetEnv("NSPR_LOG_MODULES");
     if (ev && ev[0]) {
--- a/pr/src/io/prmwait.c
+++ b/pr/src/io/prmwait.c
@@ -53,29 +53,18 @@ typedef struct TimerEvent {
 } TimerEvent;
 
 #define TIMER_EVENT_PTR(_qp) \
     ((TimerEvent *) ((char *) (_qp) - offsetof(TimerEvent, links)))
 
 struct {
     PRLock *ml;
     PRCondVar *new_timer;
-    PRCondVar *cancel_timer;  /* The cancel_timer condition variable is
-                               * used to cancel a timer (i.e., remove a
-                               * timer event from the timer queue). At
-                               * startup I'm borrowing this condition
-                               * variable for a different purpose (to
-                               * tell the primordial thread that the
-                               * timer manager thread has started) so
-                               * that I don't need to create a new
-                               * condition variable just for this one
-                               * time use.
-                               */
+    PRCondVar *cancel_timer;
     PRThread *manager_thread;
-    PRBool manager_started;
     PRCList timer_queue;
 } tm_vars;
 
 static PRStatus TimerInit(void);
 static void TimerManager(void *arg);
 static TimerEvent *CreateTimer(PRIntervalTime timeout,
     void (*func)(void *), void *arg);
 static PRBool CancelTimer(TimerEvent *timer);
@@ -83,21 +72,16 @@ static PRBool CancelTimer(TimerEvent *ti
 static void TimerManager(void *arg)
 {
     PRIntervalTime now;
     PRIntervalTime timeout;
     PRCList *head;
     TimerEvent *timer;
 
     PR_Lock(tm_vars.ml);
-    /* tell the primordial thread that we have started */
-    tm_vars.manager_started = PR_TRUE;
-    if (!_native_threads_only) {
-        PR_NotifyCondVar(tm_vars.cancel_timer);
-    }
     while (1)
     {
         if (PR_CLIST_IS_EMPTY(&tm_vars.timer_queue))
         {
             PR_WaitCondVar(tm_vars.new_timer, PR_INTERVAL_NO_TIMEOUT);
         }
         else
         {
@@ -211,26 +195,16 @@ static PRStatus TimerInit(void)
     PR_INIT_CLIST(&tm_vars.timer_queue);
     tm_vars.manager_thread = PR_CreateThread(
         PR_SYSTEM_THREAD, TimerManager, NULL, PR_PRIORITY_NORMAL,
         PR_LOCAL_THREAD, PR_UNJOINABLE_THREAD, 0);
     if (NULL == tm_vars.manager_thread)
     {
         goto failed;
     }
-    /*
-     * Need to wait until the timer manager thread starts
-     * if the timer manager thread is a local thread.
-     */
-    if (!_native_threads_only) {
-        PR_Lock(tm_vars.ml);
-        while (!tm_vars.manager_started)
-            PR_WaitCondVar(tm_vars.cancel_timer, PR_INTERVAL_NO_TIMEOUT);
-        PR_Unlock(tm_vars.ml);
-    }
     return PR_SUCCESS;
 
 failed:
     if (NULL != tm_vars.cancel_timer)
     {
         PR_DestroyCondVar(tm_vars.cancel_timer);
     }
     if (NULL != tm_vars.new_timer)
@@ -264,16 +238,27 @@ void _PR_InitMW(void)
     mw_lock = PR_NewLock();
     PR_ASSERT(NULL != mw_lock);
     mw_state = PR_NEWZAP(_PRGlobalState);
     PR_ASSERT(NULL != mw_state);
     PR_INIT_CLIST(&mw_state->group_list);
     max_polling_interval = PR_MillisecondsToInterval(MAX_POLLING_INTERVAL);
 }  /* _PR_InitMW */
 
+void _PR_CleanupMW(void)
+{
+    PR_DestroyLock(mw_lock);
+    mw_lock = NULL;
+    if (mw_state->group) {
+        PR_DestroyWaitGroup(mw_state->group);
+        /* mw_state->group is set to NULL as a side effect. */
+    }
+    PR_DELETE(mw_state);
+}  /* _PR_CleanupMW */
+
 static PRWaitGroup *MW_Init2(void)
 {
     PRWaitGroup *group = mw_state->group;  /* it's the null group */
     if (NULL == group)  /* there is this special case */
     {
         group = PR_CreateWaitGroup(_PR_DEFAULT_HASH_LENGTH);
         if (NULL == group) goto failed_alloc;
         PR_Lock(mw_lock);
--- a/pr/src/io/prsocket.c
+++ b/pr/src/io/prsocket.c
@@ -1390,17 +1390,17 @@ PR_IMPLEMENT(PRStatus) PR_NewTCPSocketPa
      * child process.
      *
      * The default implementation below cannot be used for NT
      * because PR_Accept would have associated the I/O completion
      * port with the listening and accepted sockets.
      */
     SOCKET listenSock;
     SOCKET osfd[2];
-    struct sockaddr_in selfAddr;
+    struct sockaddr_in selfAddr, peerAddr;
     int addrLen;
 
     if (!_pr_initialized) _PR_ImplicitInitialization();
 
     osfd[0] = osfd[1] = INVALID_SOCKET;
     listenSock = socket(AF_INET, SOCK_STREAM, 0);
     if (listenSock == INVALID_SOCKET) {
         goto failed;
@@ -1434,20 +1434,34 @@ PR_IMPLEMENT(PRStatus) PR_NewTCPSocketPa
      * This is the behavior of the BSD socket code.  If
      * connect does not return until accept is called, we
      * will need to create another thread to call connect.
      */
     if (connect(osfd[0], (struct sockaddr *) &selfAddr,
             addrLen) == SOCKET_ERROR) {
         goto failed;
     }
-    osfd[1] = accept(listenSock, NULL, NULL);
+    /*
+     * A malicious local process may connect to the listening
+     * socket, so we need to verify that the accepted connection
+     * is made from our own socket osfd[0].
+     */
+    if (getsockname(osfd[0], (struct sockaddr *) &selfAddr,
+            &addrLen) == SOCKET_ERROR) {
+        goto failed;
+    }
+    osfd[1] = accept(listenSock, (struct sockaddr *) &peerAddr, &addrLen);
     if (osfd[1] == INVALID_SOCKET) {
         goto failed;
     }
+    if (peerAddr.sin_port != selfAddr.sin_port) {
+        /* the connection we accepted is not from osfd[0] */
+        PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, 0);
+        goto failed;
+    }
     closesocket(listenSock);
 
     f[0] = PR_AllocFileDesc(osfd[0], PR_GetTCPMethods());
     if (!f[0]) {
         closesocket(osfd[0]);
         closesocket(osfd[1]);
         /* PR_AllocFileDesc() has invoked PR_SetError(). */
         return PR_FAILURE;
@@ -1474,17 +1488,17 @@ failed:
         closesocket(osfd[1]);
     }
     return PR_FAILURE;
 #else /* not Unix or NT */
     /*
      * default implementation
      */
     PRFileDesc *listenSock;
-    PRNetAddr selfAddr;
+    PRNetAddr selfAddr, peerAddr;
     PRUint16 port;
 
     f[0] = f[1] = NULL;
     listenSock = PR_NewTCPSocket();
     if (listenSock == NULL) {
         goto failed;
     }
     PR_InitializeNetAddr(PR_IpAddrLoopback, 0, &selfAddr); /* BugZilla: 35408 */
@@ -1512,30 +1526,46 @@ failed:
      * This is the behavior of the BSD socket code.  If
      * connect does not return until accept is called, we
      * will need to create another thread to call connect.
      */
     if (PR_Connect(f[0], &selfAddr, PR_INTERVAL_NO_TIMEOUT)
             == PR_FAILURE) {
         goto failed;
     }
-    f[1] = PR_Accept(listenSock, NULL, PR_INTERVAL_NO_TIMEOUT);
+    /*
+     * A malicious local process may connect to the listening
+     * socket, so we need to verify that the accepted connection
+     * is made from our own socket f[0].
+     */
+    if (PR_GetSockName(f[0], &selfAddr) == PR_FAILURE) {
+        goto failed;
+    }
+    f[1] = PR_Accept(listenSock, &peerAddr, PR_INTERVAL_NO_TIMEOUT);
     if (f[1] == NULL) {
         goto failed;
     }
+    if (peerAddr.inet.port != selfAddr.inet.port) {
+        /* the connection we accepted is not from f[0] */
+        PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, 0);
+        goto failed;
+    }
     PR_Close(listenSock);
     return PR_SUCCESS;
 
 failed:
     if (listenSock) {
         PR_Close(listenSock);
     }
     if (f[0]) {
         PR_Close(f[0]);
     }
+    if (f[1]) {
+        PR_Close(f[1]);
+    }
     return PR_FAILURE;
 #endif
 }
 
 PR_IMPLEMENT(PRInt32)
 PR_FileDesc2NativeHandle(PRFileDesc *fd)
 {
     if (fd) {
--- a/pr/src/linking/prlink.c
+++ b/pr/src/linking/prlink.c
@@ -257,16 +257,20 @@ void _PR_InitLinker(void)
 #ifndef XP_MAC
     PR_LOG(_pr_linker_lm, PR_LOG_MIN, ("Loaded library %s (init)", lm?lm->name:"NULL"));
 #endif
 
     PR_ExitMonitor(pr_linker_lock);
 }
 
 #if defined(WIN16)
+/*
+ * _PR_ShutdownLinker unloads all dlls loaded by the application via
+ * calls to PR_LoadLibrary
+ */
 void _PR_ShutdownLinker(void)
 {
     PR_EnterMonitor(pr_linker_lock);
 
     while (pr_loadmap) {
     if (pr_loadmap->refCount > 1) {
 #ifdef DEBUG
         fprintf(stderr, "# Forcing library to unload: %s (%d outstanding references)\n",
@@ -277,27 +281,55 @@ void _PR_ShutdownLinker(void)
     PR_UnloadLibrary(pr_loadmap);
     }
     
     PR_ExitMonitor(pr_linker_lock);
 
     PR_DestroyMonitor(pr_linker_lock);
     pr_linker_lock = NULL;
 }
+#else
+/*
+ * _PR_ShutdownLinker was originally only used on WIN16 (see above),
+ * but I think it should also be used on other platforms.  However,
+ * I disagree with the original implementation's unloading the dlls
+ * for the application.  Any dlls that still remain on the pr_loadmap
+ * list when NSPR shuts down are application programming errors.  The
+ * only exception is pr_exe_loadmap, which was added to the list by
+ * NSPR and hence should be cleaned up by NSPR.
+ */
+void _PR_ShutdownLinker(void)
+{
+    /* FIXME: pr_exe_loadmap should be destroyed. */
+    
+    PR_DestroyMonitor(pr_linker_lock);
+    pr_linker_lock = NULL;
+
+    if (_pr_currentLibPath) {
+        free(_pr_currentLibPath);
+        _pr_currentLibPath = NULL;
+    }
+
+#if !defined(USE_DLFCN) && !defined(HAVE_STRERROR)
+    PR_DELETE(errStrBuf);
+#endif
+}
 #endif
 
 /******************************************************************************/
 
 PR_IMPLEMENT(PRStatus) PR_SetLibraryPath(const char *path)
 {
     PRStatus rv = PR_SUCCESS;
 
     if (!_pr_initialized) _PR_ImplicitInitialization();
     PR_EnterMonitor(pr_linker_lock);
-    PR_FREEIF(_pr_currentLibPath);
+    if (_pr_currentLibPath) {
+        free(_pr_currentLibPath);
+    }
     if (path) {
         _pr_currentLibPath = strdup(path);
         if (!_pr_currentLibPath) {
             PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
         rv = PR_FAILURE;
         }
     } else {
         _pr_currentLibPath = 0;
@@ -305,17 +337,17 @@ PR_IMPLEMENT(PRStatus) PR_SetLibraryPath
     PR_ExitMonitor(pr_linker_lock);
     return rv;
 }
 
 /*
 ** Return the library path for finding shared libraries.
 */
 PR_IMPLEMENT(char *) 
-PR_GetLibraryPath()
+PR_GetLibraryPath(void)
 {
     char *ev;
     char *copy = NULL;  /* a copy of _pr_currentLibPath */
 
     if (!_pr_initialized) _PR_ImplicitInitialization();
     PR_EnterMonitor(pr_linker_lock);
     if (_pr_currentLibPath != NULL) {
         goto exit;
@@ -337,17 +369,17 @@ PR_GetLibraryPath()
     int len;
 
     ev = getenv("LD_LIBRARY_PATH");
     
     if (!ev)
         ev = "";
     
     len = strlen(ev) + 1;        /* +1 for the null */
-    p = (char*) PR_MALLOC(len);
+    p = (char*) malloc(len);
     if (p) {
         strcpy(p, ev);
     }
     ev = p;
     }
 #endif
 
 #if defined(XP_UNIX) || defined(XP_BEOS)
@@ -364,17 +396,17 @@ PR_GetLibraryPath()
 #else
     ev = getenv("LD_LIBRARY_PATH");
     if (!ev) {
         ev = "/usr/lib:/lib";
     }
 #endif
     len = strlen(ev) + 1;        /* +1 for the null */
 
-    p = (char*) PR_MALLOC(len);
+    p = (char*) malloc(len);
     if (p) {
         strcpy(p, ev);
     }   /* if (p)  */
     ev = p;
     PR_LOG(_pr_io_lm, PR_LOG_NOTICE, ("linker path '%s'", ev));
 
     }
 #else
@@ -1143,17 +1175,18 @@ PR_UnloadLibrary(PRLibrary *lib)
     }
     /*
      * We free the PRLibrary structure whether dlclose/shl_unload
      * succeeds or not.
      */
 
   freeLib:
     PR_LOG(_pr_linker_lm, PR_LOG_MIN, ("Unloaded library %s", lib->name));
-    PR_DELETE(lib->name);
+    free(lib->name);
+    lib->name = NULL;
     PR_DELETE(lib);
     if (result == -1) {
         PR_SetError(PR_UNLOAD_LIBRARY_ERROR, _MD_ERRNO());
         DLLErrorInternal(_MD_ERRNO());
         status = PR_FAILURE;
     }
 
 done:
--- a/pr/src/malloc/prmem.c
+++ b/pr/src/malloc/prmem.c
@@ -92,30 +92,89 @@ void
     
     for (j = 0; j < THREAD_POOLS; j++) {
         for (i = 0; i < MEM_ZONES; i++) {
             MemoryZone *mz = &zones[i][j];
             pthread_mutex_destroy(&mz->lock);
             while (mz->head) {
                 MemBlockHdr *hdr = mz->head;
                 mz->head = hdr->s.next;  /* unlink it */
-                pr_ZoneFree(hdr);
+                free(hdr);
                 mz->elements--;
             }
         }
     } 
+    use_zone_allocator = PR_FALSE;
 } 
 
+/*
+** pr_FindSymbolInProg
+**
+** Find the specified data symbol in the program and return
+** its address.
+*/
+
+#ifdef USE_DLFCN
+
+#include <dlfcn.h>
+
+static void *
+pr_FindSymbolInProg(const char *name)
+{
+    void *h;
+    void *sym;
+
+    h = dlopen(0, RTLD_LAZY);
+    if (h == NULL)
+        return NULL;
+    sym = dlsym(h, name);
+    (void)dlclose(h);
+    return sym;
+}
+
+#elif defined(USE_HPSHL)
+
+#include <dl.h>
+
+static void *
+pr_FindSymbolInProg(const char *name)
+{
+    shl_t h = NULL;
+    void *sym;
+
+    if (shl_findsym(&h, name, TYPE_DATA, &sym) == -1)
+        return NULL;
+    return sym;
+}
+
+#elif defined(USE_MACH_DYLD)
+
+static void *
+pr_FindSymbolInProg(const char *name)
+{
+    /* FIXME: not implemented */
+    return NULL;
+}
+
+#else
+
+#error "The zone allocator is not supported on this platform"
+
+#endif
+
 void
 _PR_InitZones(void)
 {
     int i, j;
     char *envp;
+    PRBool *sym;
 
-    if (envp = getenv("NSPR_USE_ZONE_ALLOCATOR")) {
+    if ((sym = pr_FindSymbolInProg("nspr_use_zone_allocator")) != NULL) {
+        use_zone_allocator = *sym;
+    } else if ((envp = getenv("NSPR_USE_ZONE_ALLOCATOR")) != NULL) {
         use_zone_allocator = (atoi(envp) == 1);
     }
 
     if (!use_zone_allocator)
         return;
 
     for (j = 0; j < THREAD_POOLS; j++) { 
         for (i = 0; i < MEM_ZONES; i++) {
@@ -270,16 +329,21 @@ pr_ZoneRealloc(void *oldptr, PRUint32 by
     MemBlockHdr   phony;
 
     if (!oldptr)
         return pr_ZoneMalloc(bytes);
     mb = (MemBlockHdr *)((char *)oldptr - (sizeof *mb));
     PR_ASSERT(mb->s.magic == ZONE_MAGIC);
     if (mb->s.magic != ZONE_MAGIC) {
         /* Maybe this just came from ordinary malloc */
+#ifdef DEBUG
+        fprintf(stderr,
+            "Warning: reallocing memory block %p from ordinary malloc\n",
+            oldptr);
+#endif
         /* We don't know how big it is.  But we can fix that. */
         oldptr = realloc(oldptr, bytes);
         if (!oldptr) {
             if (bytes) {
                 PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
                 return oldptr;
             }
         }
@@ -324,30 +388,34 @@ pr_ZoneFree(void *ptr)
 
     if (!ptr)
         return;
 
     mb = (MemBlockHdr *)((char *)ptr - (sizeof *mb));
 
     if (mb->s.magic != ZONE_MAGIC) {
         /* maybe this came from ordinary malloc */
+#ifdef DEBUG
+        fprintf(stderr,
+            "Warning: freeing memory block %p from ordinary malloc\n", ptr);
+#endif
         free(ptr);
         return;
     }
 
     blockSize = mb->s.blockSize;
     mz        = mb->s.zone;
     mt = (MemBlockHdr *)(((char *)(mb + 1)) + blockSize);
     PR_ASSERT(mt->s.magic == ZONE_MAGIC);
     PR_ASSERT(mt->s.zone  == mz);
     PR_ASSERT(mt->s.blockSize == blockSize);
     if (!mz) {
         PR_ASSERT(blockSize > 65536);
         /* This block was not in any zone.  Just free it. */
-        free(ptr);
+        free(mb);
         return;
     }
     PR_ASSERT(mz->blockSize == blockSize);
     wasLocked = mz->locked;
     pthread_mutex_lock(&mz->lock);
     mz->locked = 1;
     if (wasLocked)
         mz->contention++;
--- a/pr/src/md/mac/macio.c
+++ b/pr/src/md/mac/macio.c
@@ -1,8 +1,9 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* 
  * 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
@@ -25,33 +26,16 @@
  * 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.
  */
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/*
- * The contents of this file are subject to the Netscape Public License
- * Version 1.1 (the "NPL"); you may not use this file except in
- * compliance with the NPL.  You may obtain a copy of the NPL at
- * http://www.mozilla.org/NPL/
- * 
- * Software distributed under the NPL is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
- * for the specific language governing rights and limitations under the
- * NPL.
- * 
- * The Initial Developer of this code under the NPL is Netscape
- * Communications Corporation.  Portions created by Netscape are
- * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
- * Reserved.
- */
 
 #include <string.h>
 
 #include <Types.h>
 #include <Files.h>
 #include <Devices.h>
 #include <Folders.h>
 #include <Errors.h>
@@ -92,18 +76,17 @@ static void AsyncIOCompletion (ExtendedP
 {
     _PRCPU *cpu = _PR_MD_CURRENT_CPU();
     PRThread *thread = pbAsyncPtr->thread;    
     PRIntn is;
     
     if (_PR_MD_GET_INTSOFF()) {
         thread->md.missedIONotify = PR_TRUE;
         cpu->u.missed[cpu->where] |= _PR_MISSED_IO;
-    }
-    else {
+    } else {
         _PR_INTSOFF(is);
 
         thread->md.osErrCode = noErr;
         DoneWaitingOnThisThread(thread);
 
         _PR_FAST_INTSON(is);
     }
 
@@ -478,18 +461,16 @@ ErrorExit:
 /* _MD_CLOSE_FILE, _MD_READ, _MD_WRITE, _MD_GET_FILE_ERROR are defined in _macos.h */
 
 PROffset32 _MD_LSeek(PRFileDesc *fd, PROffset32 offset, PRSeekWhence how)
 {
 	PRInt32 refNum = fd->secret->md.osfd;
 	OSErr 	err = noErr;
 	long	curPos, endPos;
 
-	PR_ASSERT(offset >= 0);
-
 	/* compute new mark */
 	switch (how) {
 		case PR_SEEK_SET:
 			endPos = offset;
 			break;
 		
 		case PR_SEEK_CUR:
 			err = GetFPos(refNum, &curPos);
--- a/pr/src/md/mac/macsockotpt.c
+++ b/pr/src/md/mac/macsockotpt.c
@@ -168,34 +168,33 @@ static pascal void  DNSNotifierRoutine(v
 		dnsContext.thread->md.osErrCode = result;
 		dnsContext.cookie = cookie;
 	
 	switch (otEvent) {
 		case T_DNRSTRINGTOADDRCOMPLETE:
 				if (_PR_MD_GET_INTSOFF()) {
 					dnsContext.thread->md.missedIONotify = PR_TRUE;
 					cpu->u.missed[cpu->where] |= _PR_MISSED_IO;
+				} else {
+					DoneWaitingOnThisThread(dnsContext.thread);
 				}
-				else
-					DoneWaitingOnThisThread(dnsContext.thread);
 				break;
 		
         case kOTProviderWillClose:
                 errOT = OTSetSynchronous(dnsContext.serviceRef);
                 // fall through to kOTProviderIsClosed case
 		
         case kOTProviderIsClosed:
                 errOT = OTCloseProvider((ProviderRef)dnsContext.serviceRef);
                 dnsContext.serviceRef = nil;
 
 				if (_PR_MD_GET_INTSOFF()) {
 					dnsContext.thread->md.missedIONotify = PR_TRUE;
 					cpu->u.missed[cpu->where] |= _PR_MISSED_IO;
-				}
-				else {
+				} else {
 					DoneWaitingOnThisThread(dnsContext.thread);
 				}
                 break;
 
         default: // or else we don't handle the event
 	            PR_ASSERT(otEvent==NULL);
 		
 	}
@@ -294,18 +293,17 @@ WakeUpNotifiedThread(PRThread *thread, O
 {
     _PRCPU *      cpu      = _PR_MD_CURRENT_CPU(); 
 
 	if (thread) {
 		thread->md.osErrCode = result;
 		if (_PR_MD_GET_INTSOFF()) {
 			thread->md.missedIONotify = PR_TRUE;
 			cpu->u.missed[cpu->where] |= _PR_MISSED_IO;
-		}
-		else {
+		} else {
 			DoneWaitingOnThisThread(thread);
 		}
 	}
 	
 	SignalIdleSemaphore();
 }
 
 // Notification routine
@@ -1172,18 +1170,17 @@ static pascal void  RawEndpointNotifierR
             return;
     }
 
 	if (thread) {
 		thread->md.osErrCode = result;
 		if (_PR_MD_GET_INTSOFF()) {
 			thread->md.asyncNotifyPending = PR_TRUE;
 			cpu->u.missed[cpu->where] |= _PR_MISSED_IO;
-		}
-		else {
+		} else {
 			DoneWaitingOnThisThread(thread);
 		}
 	}
 
 	SignalIdleSemaphore();
 }
 
 PRInt32 _MD_accept(PRFileDesc *fd, PRNetAddr *addr, PRUint32 *addrlen, PRIntervalTime timeout)
--- a/pr/src/md/os2/objs.mk
+++ b/pr/src/md/os2/objs.mk
@@ -1,24 +1,40 @@
-#
-# The contents of this file are subject to the Netscape Public License
-# Version 1.1 (the "NPL"); you may not use this file except in
-# compliance with the NPL.  You may obtain a copy of the NPL at
-# http://www.mozilla.org/NPL/
+# 
+# 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).
 # 
-# Software distributed under the NPL is distributed on an "AS IS" basis,
-# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
-# for the specific language governing rights and limitations under the
-# NPL.
+# The Initial Developer of the Original Code is Netscape
+# Communications Corporation.  Portions created by Netscape are 
+# Copyright (C) 1998-2000 Netscape Communications Corporation.  All
+# Rights Reserved.
+# 
+# Contributor(s):
 # 
-# The Initial Developer of this code under the NPL is Netscape
-# Communications Corporation.  Portions created by Netscape are
-# Copyright (C) 1998 Netscape Communications Corporation.  All Rights
-# Reserved.
-#
+# 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.
+# 
 
 # This makefile appends to the variable OBJS the platform-dependent
 # object modules that will be part of the nspr20 library.
 
 CSRCS = \
 	os2io.c      \
 	os2sock.c    \
 	os2thred.c   \
--- a/pr/src/md/os2/os2sock.c
+++ b/pr/src/md/os2/os2sock.c
@@ -353,16 +353,29 @@ PRInt32
         err = sock_errno();
         _PR_MD_MAP_BIND_ERROR(err);
     }
     return(rv);
 }
 
 
 PRInt32
+_PR_MD_LISTEN(PRFileDesc *fd, PRIntn backlog)
+{
+    PRInt32 rv, err;
+    rv = listen(fd->secret->md.osfd, backlog);
+    if (rv < 0)  {
+        err = sock_errno();
+        _PR_MD_MAP_DEFAULT_ERROR(err);
+    }
+    return(rv);
+}
+
+
+PRInt32
 _PR_MD_RECV(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags, 
             PRIntervalTime timeout)
 {
     PRInt32 osfd = fd->secret->md.osfd;
     PRInt32 rv, err;
     PRThread *me = _PR_MD_CURRENT_THREAD();
 
     while ((rv = recv(osfd,buf,amount,flags)) == -1)
--- a/pr/src/md/unix/darwin.c
+++ b/pr/src/md/unix/darwin.c
@@ -125,10 +125,10 @@ int sigtimedwait(const sigset_t *set, si
     const struct timespec *timeout)
 {
     errno = ENOSYS;
     return -1;
 }
 
 #endif /* _PR_PTHREADS */
 
-/* rhapsody.c */
+/* darwin.c */
 
--- a/pr/src/md/unix/irix.c
+++ b/pr/src/md/unix/irix.c
@@ -1446,17 +1446,17 @@ void _MD_EarlyInit(void)
     }
 	_MD_SET_SPROC_PID(getpid());	
     close(fd);
 	__ateachexit(irix_detach_sproc);
 #endif
     _MD_IrixIntervalInit();
 }  /* _MD_EarlyInit */
 
-void _MD_IrixInit()
+void _MD_IrixInit(void)
 {
 #if !defined(_PR_PTHREADS)
     struct sigaction sigact;
     PRThread *me = _PR_MD_CURRENT_THREAD();
 	int rv;
 
 #ifdef _PR_HAVE_SGI_PRDA_PROCMASK
 	/*
@@ -1562,17 +1562,17 @@ static PRUint32 pr_clock_shift = 0;
 static PRIntervalTime pr_ticks = 0;
 static PRUint32 pr_clock_granularity = 1;
 static PRUint32 pr_previous = 0, pr_residual = 0;
 static PRUint32 pr_ticks_per_second = 0;
 
 extern PRIntervalTime _PR_UNIX_GetInterval(void);
 extern PRIntervalTime _PR_UNIX_TicksPerSecond(void);
 
-static void _MD_IrixIntervalInit()
+static void _MD_IrixIntervalInit(void)
 {
     /*
      * As much as I would like, the service available through this
      * interface on R3000's (aka, IP12) just isn't going to make it.
      * The register is only 24 bits wide, and rolls over at a verocious
      * rate.
      */
     PRUint32 one_tick = 0;
@@ -1629,22 +1629,22 @@ static void _MD_IrixIntervalInit()
             ((__psunsigned_t)iotimer_addr + (phys_addr & poffmask));
     }
     else
     {
         pr_ticks_per_second = _PR_UNIX_TicksPerSecond();
     }
 }  /* _MD_IrixIntervalInit */
 
-PRIntervalTime _MD_IrixIntervalPerSec()
+PRIntervalTime _MD_IrixIntervalPerSec(void)
 {
     return pr_ticks_per_second;
 }
 
-PRIntervalTime _MD_IrixGetInterval()
+PRIntervalTime _MD_IrixGetInterval(void)
 {
     if (mmem_fd != -1)
     {
         if (64 == clock_width)
         {
             PRUint64 temp = *(PRUint64*)iotimer_addr;
             pr_ticks = (PRIntervalTime)(temp >> pr_clock_shift);
         }
--- a/pr/src/md/unix/uxproces.c
+++ b/pr/src/md/unix/uxproces.c
@@ -797,17 +797,17 @@ static void pr_InstallSigchldHandler()
     /* Make sure we are not overriding someone else's SIGCHLD handler */
 #ifndef _PR_SHARE_CLONES
     PR_ASSERT(oact.sa_handler == SIG_DFL);
 #endif
 }
 
 #endif  /* !defined(_PR_NATIVE_THREADS) */
 
-static PRStatus _MD_InitProcesses()
+static PRStatus _MD_InitProcesses(void)
 {
 #if !defined(_PR_NATIVE_THREADS)
     int rv;
     int flags;
 #endif
 #ifdef SUNOS4
 #define _PR_NBIO_FLAG FNDELAY
 #else
--- a/pr/src/md/unix/uxrng.c
+++ b/pr/src/md/unix/uxrng.c
@@ -59,25 +59,38 @@ GetHighResClock(void *buf, size_t maxbyt
 static size_t
 GetHighResClock(void *buf, size_t maxbytes)
 {
     return 0;
 }
 
 #elif defined(HPUX)
 
+#ifdef __ia64
+#include <ia64/sys/inline.h>
+
+static size_t
+GetHighResClock(void *buf, size_t maxbytes)
+{
+    PRUint64 t;
+
+    t = _Asm_mov_from_ar(_AREG44);
+    return _pr_CopyLowBits(buf, maxbytes, &t, sizeof(t));
+}
+#else
 static size_t
 GetHighResClock(void *buf, size_t maxbytes)
 {
     extern int ret_cr16();
     int cr16val;
 
     cr16val = ret_cr16();
     return(_pr_CopyLowBits(buf, maxbytes, &cr16val, sizeof(cr16val)));
 }
+#endif
 
 #elif defined(OSF1)
 
 #include <c_asm.h>
 
 /*
  * Use the "get the cycle counter" instruction on the alpha.
  * The low 32 bits completely turn over in less than a minute.
@@ -205,17 +218,17 @@ static size_t GetHighResClock(void *buf,
 
 	        raddr = phys_addr & ~pgoffmask;
 	        mfd = open("/dev/mmem", O_RDONLY);
 	        if (mfd < 0) {
     		    return 0;
 	        }
 	        iotimer_addr = (unsigned *)
 		    mmap(0, pgoffmask, PROT_READ, MAP_PRIVATE, mfd, (int)raddr);
-	        if (iotimer_addr == (void*)-1) {
+	        if (iotimer_addr == (unsigned*)-1) {
 	    	    close(mfd);
 		        iotimer_addr = NULL;
 		        return 0;
 	        }
 	        iotimer_addr = (unsigned*)
 		    ((__psint_t)iotimer_addr | (phys_addr & pgoffmask));
 	        /*
 	         * The file 'mfd' is purposefully not closed.
--- a/pr/src/md/unix/uxshm.c
+++ b/pr/src/md/unix/uxshm.c
@@ -306,17 +306,16 @@ struct _MDSharedMemory {
 extern PRSharedMemory * _MD_OpenSharedMemory( 
     const char *name,
     PRSize      size,
     PRIntn      flags,
     PRIntn      mode
 )
 {
     PRStatus    rc = PR_SUCCESS;
-    PRIntn      id;
     PRInt32     end;
     PRSharedMemory *shm;
     char        ipcname[PR_IPC_NAME_SIZE];
 
     rc = _PR_MakeNativeIPCName( name, ipcname, PR_IPC_NAME_SIZE, _PRIPCShm );
     if ( PR_FAILURE == rc )
     {
         PR_SetError( PR_UNKNOWN_ERROR , errno );
--- a/pr/src/md/windows/Makefile.in
+++ b/pr/src/md/windows/Makefile.in
@@ -100,8 +100,16 @@ TARGETS	= $(OBJS)
 INCLUDES = -I$(dist_includedir) -I$(topsrcdir)/pr/include -I$(topsrcdir)/pr/include/private
 
 DEFINES += -D_NSPR_BUILD_
 
 include $(topsrcdir)/config/rules.mk
 
 export:: $(TARGETS)
 
+# Bug 122433 workaround: disable global optimization (-Og-) on ntio.c.
+ifdef BUILD_OPT
+ifeq ($(OS_TARGET), WINNT)
+$(OBJDIR)/ntio.$(OBJ_SUFFIX): ntio.c
+	@$(MAKE_OBJDIR)
+	$(CC) -Fo$@ -c $(CFLAGS) -Og- $<
+endif
+endif
--- a/pr/src/md/windows/ntthread.c
+++ b/pr/src/md/windows/ntthread.c
@@ -233,16 +233,23 @@ PRStatus
             default:
                 prerror = PR_UNKNOWN_ERROR;
         }
         PR_SetError(prerror, errno);
         return PR_FAILURE;
     }
 
     thread->md.id = thread->id;
+    /*
+     * On windows, a thread is created with a thread priority of
+     * THREAD_PRIORITY_NORMAL.
+     */
+    if (priority != PR_PRIORITY_NORMAL) {
+        _PR_MD_SET_PRIORITY(&(thread->md), priority);
+    }
 
     /* Activate the thread */
     if ( ResumeThread( thread->md.handle ) != -1)
         return PR_SUCCESS;
 
     PR_SetError(PR_UNKNOWN_ERROR, GetLastError());
     return PR_FAILURE;
 }
--- a/pr/src/md/windows/w95sock.c
+++ b/pr/src/md/windows/w95sock.c
@@ -163,28 +163,41 @@ 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, (const struct sockaddr *)&(addr->inet), addrlen);
 
     if (rv == SOCKET_ERROR)  {
         _PR_MD_MAP_BIND_ERROR(WSAGetLastError());
         return -1;
     }
 
     return 0;
 }
 
+PRInt32
+_PR_MD_LISTEN(PRFileDesc *fd, PRIntn backlog)
+{
+    PRInt32 rv;
+
+    rv = listen(fd->secret->md.osfd, backlog);
+
+    if (rv == SOCKET_ERROR)  {
+        _PR_MD_MAP_DEFAULT_ERROR(WSAGetLastError());
+        return -1;
+    }
+
+    return 0;
+}
 
 PRInt32
 _PR_MD_RECV(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags, 
             PRIntervalTime timeout)
 {
     PRInt32 osfd = fd->secret->md.osfd;
     PRInt32 rv, err;
     int osflags;
--- a/pr/src/md/windows/w95thred.c
+++ b/pr/src/md/windows/w95thred.c
@@ -126,17 +126,23 @@ PRStatus
                     (void *)thread,
                     CREATE_SUSPENDED,
                     &(thread->id));
     if(!thread->md.handle) {
         return PR_FAILURE;
     }
 
     thread->md.id = thread->id;
-    _PR_MD_SET_PRIORITY(&(thread->md), priority);
+    /*
+     * On windows, a thread is created with a thread priority of
+     * THREAD_PRIORITY_NORMAL.
+     */
+    if (priority != PR_PRIORITY_NORMAL) {
+        _PR_MD_SET_PRIORITY(&(thread->md), priority);
+    }
 
     /* Activate the thread */
     if ( ResumeThread( thread->md.handle ) != -1)
         return PR_SUCCESS;
 
     return PR_FAILURE;
 }
 
--- a/pr/src/misc/pralarm.c
+++ b/pr/src/misc/pralarm.c
@@ -175,17 +175,17 @@ static void PR_CALLBACK pr_alarmNotifier
                 id = NULL;  /* so it doesn't get back into the list */
             }
             why = scan;  /* so we can cycle through the loop again */
         }
     }
 
 }  /* pr_alarm_notifier */
 
-PR_IMPLEMENT(PRAlarm*) PR_CreateAlarm()
+PR_IMPLEMENT(PRAlarm*) PR_CreateAlarm(void)
 {
     PRAlarm *alarm = PR_NEWZAP(PRAlarm);
     if (alarm != NULL)
     {
         if ((alarm->lock = PR_NewLock()) == NULL) goto done;
         if ((alarm->cond = PR_NewCondVar(alarm->lock)) == NULL) goto done;
         alarm->state = alarm_active;
         PR_INIT_CLIST(&alarm->timers);
--- a/pr/src/misc/prdtoa.c
+++ b/pr/src/misc/prdtoa.c
@@ -1175,16 +1175,26 @@ static CONST double tinytens[] = { 1e-16
 #endif
 
 void _PR_InitDtoa(void)
 {
 	freelist_lock = PR_NewLock();
 	p5s_lock = PR_NewLock();
 }
 
+void _PR_CleanupDtoa(void)
+{
+    PR_DestroyLock(freelist_lock);
+    freelist_lock = NULL;
+    PR_DestroyLock(p5s_lock);
+    p5s_lock = NULL;
+
+    /* FIXME: deal with freelist and p5s. */
+}
+
 #if defined(HAVE_WATCOM_BUG_1)
 PRFloat64 __pascal __loadds  __export
 #else
 PR_IMPLEMENT(PRFloat64) 
 #endif
 PR_strtod(CONST char *s00, char **se)
 {
 	PRInt32 bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, dsign,
--- a/pr/src/misc/prenv.c
+++ b/pr/src/misc/prenv.c
@@ -33,38 +33,47 @@
  */
 
 #include <string.h>
 #include "primpl.h"
 
 /* Lock used to lock the environment */
 #if defined(_PR_NO_PREEMPT)
 #define _PR_NEW_LOCK_ENV()
+#define _PR_DELETE_LOCK_ENV()
 #define _PR_LOCK_ENV()
 #define _PR_UNLOCK_ENV()
 #elif defined(_PR_LOCAL_THREADS_ONLY)
 extern _PRCPU * _pr_primordialCPU;
 static PRIntn _is;
 #define _PR_NEW_LOCK_ENV()
+#define _PR_DELETE_LOCK_ENV()
 #define _PR_LOCK_ENV() if (_pr_primordialCPU) _PR_INTSOFF(_is);
 #define _PR_UNLOCK_ENV() if (_pr_primordialCPU) _PR_INTSON(_is);
 #else
 static PRLock *_pr_envLock = NULL;
 #define _PR_NEW_LOCK_ENV() {_pr_envLock = PR_NewLock();}
+#define _PR_DELETE_LOCK_ENV() \
+    { if (_pr_envLock) { PR_DestroyLock(_pr_envLock); _pr_envLock = NULL; } }
 #define _PR_LOCK_ENV() { if (_pr_envLock) PR_Lock(_pr_envLock); }
 #define _PR_UNLOCK_ENV() { if (_pr_envLock) PR_Unlock(_pr_envLock); }
 #endif
 
 /************************************************************************/
 
-void _PR_InitEnv()
+void _PR_InitEnv(void)
 {
 	_PR_NEW_LOCK_ENV();
 }
 
+void _PR_CleanupEnv(void)
+{
+    _PR_DELETE_LOCK_ENV();
+}
+
 PR_IMPLEMENT(char*) PR_GetEnv(const char *var)
 {
     char *ev;
 
     if (!_pr_initialized) _PR_ImplicitInitialization();
 
     _PR_LOCK_ENV();
     ev = _PR_MD_GET_ENV(var);
--- a/pr/src/misc/prerr.c
+++ b/pr/src/misc/prerr.c
@@ -114,11 +114,11 @@ static const struct PRErrorMessage text[
 	{"PR_CONNECT_ABORTED_ERROR",    "Connection aborted"},
 	{"PR_HOST_UNREACHABLE_ERROR",    "Host is unreachable"},
 	{"PR_MAX_ERROR",    "Placeholder for the end of the list"},
 	{0, 0}
 };
 
 static const struct PRErrorTable et = { text, "prerr", -6000L, 75 };
 
-void nspr_InitializePRErrorTable() {
+void nspr_InitializePRErrorTable(void) {
     PR_ErrorInstallTable(&et);
 }
--- a/pr/src/misc/prerr.et
+++ b/pr/src/misc/prerr.et
@@ -1,22 +1,40 @@
-# The contents of this file are subject to the Netscape Public License
-# Version 1.1 (the "NPL"); you may not use this file except in
-# compliance with the NPL.  You may obtain a copy of the NPL at
-# http://www.mozilla.org/NPL/
-#
-# Software distributed under the NPL is distributed on an "AS IS" basis,
-# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
-# for the specific language governing rights and limitations under the
-# NPL.
-#
-# The Initial Developer of this code under the NPL is Netscape
-# Communications Corporation.  Portions created by Netscape are
-# Copyright (C) 1998 Netscape Communications Corporation.  All Rights
-# Reserved.
+# 
+# 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) 1998-2000 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.
+# 
 
 et nspr -6000
 
 ec PR_OUT_OF_MEMORY_ERROR,      "Memory allocation attempt failed"
 ec PR_BAD_DESCRIPTOR_ERROR,     "Invalid file descriptor"
 ec PR_WOULD_BLOCK_ERROR,        "The operation would have blocked"
 ec PR_ACCESS_FAULT_ERROR,       "Invalid memory address argument"
 ec PR_INVALID_METHOD_ERROR,     "Invalid function for file type"
--- a/pr/src/misc/prerror.c
+++ b/pr/src/misc/prerror.c
@@ -32,23 +32,23 @@
  * GPL.
  */
 
 #include "primpl.h"
 
 #include <string.h>
 #include <stdlib.h>
 
-PR_IMPLEMENT(PRErrorCode) PR_GetError()
+PR_IMPLEMENT(PRErrorCode) PR_GetError(void)
 {
     PRThread *thread = PR_GetCurrentThread();
     return thread->errorCode;
 }
 
-PR_IMPLEMENT(PRInt32) PR_GetOSError()
+PR_IMPLEMENT(PRInt32) PR_GetOSError(void)
 {
     PRThread *thread = PR_GetCurrentThread();
     return thread->osErrorCode;
 }
 
 PR_IMPLEMENT(void) PR_SetError(PRErrorCode code, PRInt32 osErr)
 {
     PRThread *thread = PR_GetCurrentThread();
--- a/pr/src/misc/prinit.c
+++ b/pr/src/misc/prinit.c
@@ -156,24 +156,27 @@ static void _pr_SetNativeThreadsOnlyMode
         _native_threads_only = (*globalp != PR_FALSE);
     } else if (envp = getenv("NSPR_NATIVE_THREADS_ONLY")) {
         _native_threads_only = (atoi(envp) == 1);
     }
 }
 #endif
 
 #if !defined(_PR_INET6) || defined(_PR_INET6_PROBE)
-extern PRStatus _pr_init_ipv6();
+extern PRStatus _pr_init_ipv6(void);
 #endif
 
 static void _PR_InitStuff(void)
 {
 
     if (_pr_initialized) return;
     _pr_initialized = PR_TRUE;
+#ifdef _PR_ZONE_ALLOCATOR
+    _PR_InitZones();
+#endif
 #ifdef WINNT
     _pr_SetNativeThreadsOnlyMode();
 #endif
 
 
     (void) PR_GetPageSize();
 
 	_pr_clock_lm = PR_NewLogModule("clock");
@@ -215,20 +218,16 @@ static void _PR_InitStuff(void)
     _pr_top_of_task_stack = (char *) &top;
 	}
 #endif    
 
 #ifndef _PR_GLOBAL_THREADS_ONLY
 	_PR_InitCPUs();
 #endif
 
-#ifdef _PR_ZONE_ALLOCATOR
-    _PR_InitZones();
-#endif
-
 /*
  * XXX: call _PR_InitMem only on those platforms for which nspr implements
  *	malloc, for now.
  */
 #ifdef _PR_OVERRIDE_MALLOC
     _PR_InitMem();
 #endif
 
@@ -246,17 +245,17 @@ static void _PR_InitStuff(void)
 
 #if !defined(_PR_INET6) || defined(_PR_INET6_PROBE)
 	_pr_init_ipv6();
 #endif
 	
     _PR_MD_FINAL_INIT();
 }
 
-void _PR_ImplicitInitialization()
+void _PR_ImplicitInitialization(void)
 {
 	_PR_InitStuff();
 
     /* Enable interrupts */
 #if !defined(_PR_PTHREADS) && !defined(_PR_GLOBAL_THREADS_ONLY)
     _PR_MD_START_INTERRUPTS();
 #endif
 
@@ -412,28 +411,28 @@ PR_IMPLEMENT(PRStatus) PR_Cleanup()
 #ifdef IRIX
 		_PR_MD_PRE_CLEANUP(me);
 		/*
 		 * The primordial thread must now be running on the primordial cpu
 		 */
     	PR_ASSERT((_PR_IS_NATIVE_THREAD(me)) || (me->cpu->id == 0));
 #endif
 
-#if defined(WIN16)
+        _PR_CleanupMW();
+        _PR_CleanupDtoa();
+        _PR_CleanupCallOnce();
 		_PR_ShutdownLinker();
-#endif
         /* Release the primordial thread's private data, etc. */
         _PR_CleanupThread(me);
 
         _PR_MD_STOP_INTERRUPTS();
 
 	    PR_LOG(_pr_thread_lm, PR_LOG_MIN,
 	            ("PR_Cleanup: clean up before destroying thread"));
 	    _PR_LogCleanup();
-        _PR_CleanupFdCache();
 
         /*
          * This part should look like the end of _PR_NativeRunThread
          * and _PR_UserRunThread.
          */
         if (_PR_IS_NATIVE_THREAD(me)) {
             _PR_MD_EXIT_THREAD(me);
             _PR_NativeDestroyThread(me);
@@ -445,16 +444,24 @@ PR_IMPLEMENT(PRStatus) PR_Cleanup()
 
         /*
          * XXX: We are freeing the heap memory here so that Purify won't
          * complain, but we should also free other kinds of resources
          * that are allocated by the _PR_InitXXX() functions.
          * Ideally, for each _PR_InitXXX(), there should be a corresponding
          * _PR_XXXCleanup() that we can call here.
          */
+        _PR_CleanupNet();
+        _PR_CleanupIO();
+        _PR_CleanupThreads();
+        PR_DestroyLock(_pr_sleeplock);
+        _pr_sleeplock = NULL;
+        _PR_CleanupLayerCache();
+        _PR_CleanupEnv();
+        _PR_CleanupStacks();
         _PR_CleanupBeforeExit();
         _pr_initialized = PR_FALSE;
         return PR_SUCCESS;
     }
     return PR_FAILURE;
 }
 #endif /* defined(_PR_PTHREADS) */
 
@@ -765,23 +772,30 @@ PR_IMPLEMENT(PRStatus) PR_KillProcess(PR
  ********************************************************************
  */
 
 static struct {
     PRLock *ml;
     PRCondVar *cv;
 } mod_init;
 
-static void _PR_InitCallOnce() {
+static void _PR_InitCallOnce(void) {
     mod_init.ml = PR_NewLock();
     PR_ASSERT(NULL != mod_init.ml);
     mod_init.cv = PR_NewCondVar(mod_init.ml);
     PR_ASSERT(NULL != mod_init.cv);
 }
 
+void _PR_CleanupCallOnce()
+{
+    PR_DestroyLock(mod_init.ml);
+    mod_init.ml = NULL;
+    PR_DestroyCondVar(mod_init.cv);
+    mod_init.cv = NULL;
+}
 
 PR_IMPLEMENT(PRStatus) PR_CallOnce(
     PRCallOnceType *once,
     PRCallOnceFN    func)
 {
     if (!_pr_initialized) _PR_ImplicitInitialization();
 
     if (!once->initialized) {
--- a/pr/src/misc/prinrval.c
+++ b/pr/src/misc/prinrval.c
@@ -63,23 +63,23 @@ void _PR_InitClock(void)
 
 /*
  * This version of interval times is based on the time of day
  * capability offered by system. This isn't valid for two reasons:
  * 1) The time of day is neither linear nor montonically increasing
  * 2) The units here are milliseconds. That's not appropriate for our use.
  */
 
-PR_IMPLEMENT(PRIntervalTime) PR_IntervalNow()
+PR_IMPLEMENT(PRIntervalTime) PR_IntervalNow(void)
 {
     if (!_pr_initialized) _PR_ImplicitInitialization();
     return _PR_MD_GET_INTERVAL();
 }  /* PR_IntervalNow */
 
-PR_EXTERN(PRUint32) PR_TicksPerSecond()
+PR_EXTERN(PRUint32) PR_TicksPerSecond(void)
 {
     if (!_pr_initialized) _PR_ImplicitInitialization();
     return _PR_MD_INTERVAL_PER_SEC();
 }  /* PR_TicksPerSecond */
 
 PR_IMPLEMENT(PRIntervalTime) PR_SecondsToInterval(PRUint32 seconds)
 {
     return seconds * PR_TicksPerSecond();
--- a/pr/src/misc/prnetdb.c
+++ b/pr/src/misc/prnetdb.c
@@ -177,16 +177,32 @@ void _PR_InitNet(void)
 #if !defined(_PR_NO_DNS_LOCK)
 	_pr_dnsLock = PR_NewLock();
 #endif
 #if !defined(_PR_HAVE_GETPROTO_R)
 	_getproto_lock = PR_NewLock();
 #endif
 }
 
+void _PR_CleanupNet(void)
+{
+#if !defined(_PR_NO_DNS_LOCK)
+    if (_pr_dnsLock) {
+        PR_DestroyLock(_pr_dnsLock);
+        _pr_dnsLock = NULL;
+    }
+#endif
+#if !defined(_PR_HAVE_GETPROTO_R)
+    if (_getproto_lock) {
+        PR_DestroyLock(_getproto_lock);
+        _getproto_lock = NULL;
+    }
+#endif
+}
+
 /*
 ** Allocate space from the buffer, aligning it to "align" before doing
 ** the allocation. "align" must be a power of 2.
 */
 static char *Alloc(PRIntn amount, char **bufp, PRIntn *buflenp, PRIntn align)
 {
 	char *buf = *bufp;
 	PRIntn buflen = *buflenp;
@@ -515,17 +531,16 @@ PR_IMPLEMENT(PRStatus) PR_GetIPNodeByNam
 	int tmp_flags = 0;
 #endif
 #if defined(_PR_HAVE_GETHOSTBYNAME2)
     PRBool did_af_inet = PR_FALSE;
 #endif
 
     if (!_pr_initialized) _PR_ImplicitInitialization();
 
-    PR_ASSERT(af == PR_AF_INET || af == PR_AF_INET6);
     if (af != PR_AF_INET && af != PR_AF_INET6) {
         PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
         return PR_FAILURE;
     }
 
 #if defined(_PR_HAVE_GETIPNODEBYNAME)
 	if (flags & PR_AI_V4MAPPED)
 		tmp_flags |= AI_V4MAPPED;
@@ -862,17 +877,16 @@ PR_IMPLEMENT(PRStatus) PR_GetProtoByName
             aligned += sizeof(struct protoent_data*) - 1;
             aligned &= ~(sizeof(struct protoent_data*) - 1);
             buflen -= (aligned - (PRUptrdiff)buffer);
             buffer = (char*)aligned;
         }
     }
 #endif  /* defined(_PR_HAVE_GETPROTO_R_INT) */
 
-	PR_ASSERT(PR_NETDB_BUF_SIZE <= buflen);
     if (PR_NETDB_BUF_SIZE > buflen)
     {
         PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
         return PR_FAILURE;
     }
 
 #if defined(_PR_HAVE_GETPROTO_R_POINTER)
     if (NULL == getprotobyname_r(name, res, buffer, buflen))
@@ -943,17 +957,16 @@ PR_IMPLEMENT(PRStatus) PR_GetProtoByNumb
             aligned += sizeof(struct protoent_data*) - 1;
             aligned &= ~(sizeof(struct protoent_data*) - 1);
             buflen -= (aligned - (PRUptrdiff)buffer);
             buffer = (char*)aligned;
         }
     }
 #endif /* defined(_PR_HAVE_GETPROTO_R_INT) */
 
-	PR_ASSERT(PR_NETDB_BUF_SIZE <= buflen);
     if (PR_NETDB_BUF_SIZE > buflen)
     {
         PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
         return PR_FAILURE;
     }
 
 #if defined(_PR_HAVE_GETPROTO_R_POINTER)
     if (NULL == getprotobynumber_r(number, res, buffer, buflen))
@@ -1483,18 +1496,16 @@ PR_IMPLEMENT(PRStatus) PR_NetAddrToStrin
         {
             /* the size of the result buffer is inadequate */
             PR_SetError(PR_BUFFER_OVERFLOW_ERROR, 0);
             return PR_FAILURE;
         }
     }
     else
     {
-        PR_ASSERT(AF_INET == addr->raw.family);
-        PR_ASSERT(size >= 16);
         if (size < 16) goto failed;
         if (AF_INET != addr->raw.family) goto failed;
         else
         {
             unsigned char *byte = (unsigned char*)&addr->inet.ip;
             PR_snprintf(string, size, "%u.%u.%u.%u",
                 byte[0], byte[1], byte[2], byte[3]);
         }
--- a/pr/src/misc/prsystem.c
+++ b/pr/src/misc/prsystem.c
@@ -53,33 +53,33 @@
 #if defined(BSDI) || defined(FREEBSD) || defined(NETBSD) \
     || defined(OPENBSD) || defined(DARWIN)
 #define _PR_HAVE_SYSCTL
 #include <sys/param.h>
 #include <sys/sysctl.h>
 #endif
 
 #if defined(HPUX)
-#include <sys/mp.h>
+#include <sys/mpctl.h>
 #endif
 
 #if defined(XP_UNIX)
 #include <unistd.h>
 #include <sys/utsname.h>
 #endif
 
-PR_IMPLEMENT(char) PR_GetDirectorySeparator()
+PR_IMPLEMENT(char) PR_GetDirectorySeparator(void)
 {
     return PR_DIRECTORY_SEPARATOR;
 }  /* PR_GetDirectorySeparator */
 
 /*
 ** OBSOLETE -- the function name is misspelled.
 */
-PR_IMPLEMENT(char) PR_GetDirectorySepartor()
+PR_IMPLEMENT(char) PR_GetDirectorySepartor(void)
 {
 #if defined(DEBUG)
     static PRBool warn = PR_TRUE;
     if (warn) {
         warn = _PR_Obsolete("PR_GetDirectorySepartor()",
                 "PR_GetDirectorySeparator()");
     }
 #endif
@@ -145,17 +145,16 @@ PR_IMPLEMENT(PRStatus) PR_GetSystemInfo(
 
       case PR_SI_ARCHITECTURE:
         /* Return the architecture of the machine (ie. x86, mips, alpha, ...)*/
         (void)PR_snprintf(buf, buflen, _PR_SI_ARCHITECTURE);
         break;
 	  default:
 			PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
 			return PR_FAILURE;
-			break;
     }
     return PR_SUCCESS;
 }
 
 /*
 ** PR_GetNumberOfProcessors()
 ** 
 ** Implementation notes:
--- a/pr/src/misc/prtime.c
+++ b/pr/src/misc/prtime.c
@@ -59,26 +59,26 @@
  * Static variables used by functions in this file
  */
 
 /*
  * The following array contains the day of year for the last day of
  * each month, where index 1 is January, and day 0 is January 1.
  */
 
-static int lastDayOfMonth[2][13] = {
+static const int lastDayOfMonth[2][13] = {
     {-1, 30, 58, 89, 119, 150, 180, 211, 242, 272, 303, 333, 364},
     {-1, 30, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365}
 };
 
 /*
  * The number of days in a month
  */
 
-static PRInt8 nDays[2][12] = {
+static const PRInt8 nDays[2][12] = {
     {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
     {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
 };
 
 /*
  * Declarations for internal functions defined later in this file.
  */
 
--- a/pr/src/misc/prtpool.c
+++ b/pr/src/misc/prtpool.c
@@ -161,17 +161,17 @@ struct PRJob {
 				jobp->cancel_io = PR_FALSE;				\
 				jobp->on_ioq = PR_FALSE;				\
 				PR_REMOVE_AND_INIT_LINK(&jobp->links);	\
 				tp->ioq.cnt--;							\
 				PR_NotifyCondVar(jobp->cancel_cv);		\
 				PR_END_MACRO
 
 static void delete_job(PRJob *jobp);
-static PRThreadPool * alloc_threadpool();
+static PRThreadPool * alloc_threadpool(void);
 static PRJob * alloc_job(PRBool joinable, PRThreadPool *tp);
 static void notify_ioq(PRThreadPool *tp);
 static void notify_timerq(PRThreadPool *tp);
 
 /*
  * locks are acquired in the following order
  *
  *	tp->ioq.lock,tp->timerq.lock
@@ -594,17 +594,17 @@ delete_threadpool(PRThreadPool *tp)
 		if (NULL != tp->ioq.notify_fd)
 			PR_DestroyPollableEvent(tp->ioq.notify_fd);
 		PR_Free(tp);
 	}
 	return;
 }
 
 static PRThreadPool *
-alloc_threadpool()
+alloc_threadpool(void)
 {
 PRThreadPool *tp;
 
 	tp = PR_CALLOC(sizeof(*tp));
 	if (NULL == tp)
 		goto failed;
 	tp->jobq.lock = PR_NewLock();
 	if (NULL == tp->jobq.lock)
--- a/pr/src/prvrsion.c
+++ b/pr/src/prvrsion.c
@@ -81,17 +81,17 @@ PRVersionDescription VERSION_DESC_NAME =
 #else
     /* debug            */  PR_FALSE,           /* an optomized build */
 #endif
     /* special          */  PR_FALSE,           /* they're all special, but ... */
     /* filename         */  _PRODUCTION,        /* the produced library name */
     /* description      */ "Portable runtime",  /* what we are */
     /* security         */ "N/A",               /* not applicable here */
     /* copywrite        */  "Copyright (c) 1998 Netscape Communications Corporation. All Rights Reserved",
-    /* comment          */  "License information: http://www.mozilla.org/NPL/",
+    /* comment          */  "License information: http://www.mozilla.org/MPL/",
     /* specialString    */ ""
 };
 
 #ifdef XP_UNIX
 
 /*
  * Version information for the 'ident' and 'what commands
  *
--- a/pr/src/pthreads/ptio.c
+++ b/pr/src/pthreads/ptio.c
@@ -1054,17 +1054,17 @@ static PRBool pt_solaris_sendfile_cont(p
 
         return PR_FALSE;
     }
 
     return PR_TRUE;
 }
 #endif  /* SOLARIS */
 
-void _PR_InitIO()
+void _PR_InitIO(void)
 {
 #if defined(DEBUG)
     memset(&pt_debug, 0, sizeof(PTDebug));
     pt_debug.timeStarted = PR_Now();
 #endif
 
     _pr_flock_lock = PR_NewLock();
     PR_ASSERT(NULL != _pr_flock_lock);
@@ -1077,16 +1077,44 @@ void _PR_InitIO()
 
     _pr_stdin = pt_SetMethods(0, PR_DESC_FILE, PR_FALSE, PR_TRUE);
     _pr_stdout = pt_SetMethods(1, PR_DESC_FILE, PR_FALSE, PR_TRUE);
     _pr_stderr = pt_SetMethods(2, PR_DESC_FILE, PR_FALSE, PR_TRUE);
     PR_ASSERT(_pr_stdin && _pr_stdout && _pr_stderr);
 
 }  /* _PR_InitIO */
 
+void _PR_CleanupIO(void)
+{
+    _PR_Putfd(_pr_stdin);
+    _pr_stdin = NULL;
+    _PR_Putfd(_pr_stdout);
+    _pr_stdout = NULL;
+    _PR_Putfd(_pr_stderr); 
+    _pr_stderr = NULL;
+
+    _PR_CleanupFdCache();
+    
+    if (_pr_flock_cv)
+    {
+        PR_DestroyCondVar(_pr_flock_cv);
+        _pr_flock_cv = NULL;
+    }
+    if (_pr_flock_lock)
+    {
+        PR_DestroyLock(_pr_flock_lock);
+        _pr_flock_lock = NULL;
+    }
+    if (_pr_rename_lock)
+    {
+        PR_DestroyLock(_pr_rename_lock);
+        _pr_rename_lock = NULL;
+    }
+}  /* _PR_CleanupIO */
+
 PR_IMPLEMENT(PRFileDesc*) PR_GetSpecialFD(PRSpecialFD osfd)
 {
     PRFileDesc *result = NULL;
     PR_ASSERT(osfd >= PR_StandardInput && osfd <= PR_StandardError);
 
     if (!_pr_initialized) _PR_ImplicitInitialization();
     
     switch (osfd)
@@ -3053,37 +3081,37 @@ static PRFileDesc *pt_SetMethods(
                 break;
             default:
                 break;
         }
     }
     return fd;
 }  /* pt_SetMethods */
 
-PR_IMPLEMENT(const PRIOMethods*) PR_GetFileMethods()
+PR_IMPLEMENT(const PRIOMethods*) PR_GetFileMethods(void)
 {
     return &_pr_file_methods;
 }  /* PR_GetFileMethods */
 
-PR_IMPLEMENT(const PRIOMethods*) PR_GetPipeMethods()
+PR_IMPLEMENT(const PRIOMethods*) PR_GetPipeMethods(void)
 {
     return &_pr_pipe_methods;
 }  /* PR_GetPipeMethods */
 
-PR_IMPLEMENT(const PRIOMethods*) PR_GetTCPMethods()
+PR_IMPLEMENT(const PRIOMethods*) PR_GetTCPMethods(void)
 {
     return &_pr_tcp_methods;
 }  /* PR_GetTCPMethods */
 
-PR_IMPLEMENT(const PRIOMethods*) PR_GetUDPMethods()
+PR_IMPLEMENT(const PRIOMethods*) PR_GetUDPMethods(void)
 {
     return &_pr_udp_methods;
 }  /* PR_GetUDPMethods */
 
-static const PRIOMethods* PR_GetSocketPollFdMethods()
+static const PRIOMethods* PR_GetSocketPollFdMethods(void)
 {
     return &_pr_socketpollfd_methods;
 }  /* PR_GetSocketPollFdMethods */
 
 PR_IMPLEMENT(PRFileDesc*) PR_AllocFileDesc(
     PRInt32 osfd, const PRIOMethods *methods)
 {
     PRFileDesc *fd = _PR_Getfd();
@@ -3984,24 +4012,24 @@ PR_IMPLEMENT(PRDirEntry*) PR_ReadDir(PRD
         if ((flags & PR_SKIP_HIDDEN) && ('.' == dp->d_name[0]))
             continue;
         break;
     }
     dir->d.name = dp->d_name;
     return &dir->d;
 }  /* PR_ReadDir */
 
-PR_IMPLEMENT(PRFileDesc*) PR_NewUDPSocket()
+PR_IMPLEMENT(PRFileDesc*) PR_NewUDPSocket(void)
 {
     PRIntn domain = PF_INET;
 
     return PR_Socket(domain, SOCK_DGRAM, 0);
 }  /* PR_NewUDPSocket */
 
-PR_IMPLEMENT(PRFileDesc*) PR_NewTCPSocket()
+PR_IMPLEMENT(PRFileDesc*) PR_NewTCPSocket(void)
 {
     PRIntn domain = PF_INET;
 
     return PR_Socket(domain, SOCK_STREAM, 0);
 }  /* PR_NewTCPSocket */
 
 PR_IMPLEMENT(PRFileDesc*) PR_OpenUDPSocket(PRIntn af)
 {
@@ -4089,17 +4117,17 @@ PR_IMPLEMENT(PRStatus) PR_SetFDInheritab
     }
     if (fd->secret->inheritable != inheritable)
     {
         if (fcntl(fd->secret->md.osfd, F_SETFD,
         inheritable ? 0 : FD_CLOEXEC) == -1)
         {
             return PR_FAILURE;
         }
-        fd->secret->inheritable = inheritable;
+        fd->secret->inheritable = (_PRTriStateBool) inheritable;
     }
     return PR_SUCCESS;
 }
 
 /*****************************************************************************/
 /***************************** I/O friends methods ***************************/
 /*****************************************************************************/
 
--- a/pr/src/pthreads/ptsynch.c
+++ b/pr/src/pthreads/ptsynch.c
@@ -1036,17 +1036,17 @@ PR_IMPLEMENT(PRStatus) PRP_TryLock(PRLoc
         PR_ASSERT(PR_FALSE == lock->locked);
         lock->locked = PR_TRUE;
         lock->owner = pthread_self();
     }
     /* XXX set error code? */
     return (PT_TRYLOCK_SUCCESS == rv) ? PR_SUCCESS : PR_FAILURE;
 }  /* PRP_TryLock */
 
-PR_IMPLEMENT(PRCondVar*) PRP_NewNakedCondVar()
+PR_IMPLEMENT(PRCondVar*) PRP_NewNakedCondVar(void)
 {
     PRCondVar *cv;
 
     if (!_pr_initialized) _PR_ImplicitInitialization();
 
     cv = PR_NEW(PRCondVar);
     if (cv != NULL)
     {
--- a/pr/src/pthreads/ptthread.c
+++ b/pr/src/pthreads/ptthread.c
@@ -602,19 +602,19 @@ PR_IMPLEMENT(PRStatus) PR_JoinThread(PRT
                     break;
             }
             PR_SetError(prerror, rv);
         }
     }
     return (0 == rv) ? PR_SUCCESS : PR_FAILURE;
 }  /* PR_JoinThread */
 
-PR_IMPLEMENT(void) PR_DetachThread() { }  /* PR_DetachThread */
+PR_IMPLEMENT(void) PR_DetachThread(void) { }  /* PR_DetachThread */
 
-PR_IMPLEMENT(PRThread*) PR_GetCurrentThread()
+PR_IMPLEMENT(PRThread*) PR_GetCurrentThread(void)
 {
     void *thred;
 
     if (!_pr_initialized) _PR_ImplicitInitialization();
 
     _PT_PTHREAD_GETSPECIFIC(pt_book.key, thred);
     if (NULL == thred) thred = pt_AttachThread();
     PR_ASSERT(NULL != thred);
@@ -719,35 +719,35 @@ PR_IMPLEMENT(PRStatus) PR_Interrupt(PRTh
         rv = pthread_cond_broadcast(&cv->cv);
         PR_ASSERT(0 == rv);
         if (0 > PR_AtomicDecrement(&cv->notify_pending))
             PR_DestroyCondVar(cv);
     }
     return PR_SUCCESS;
 }  /* PR_Interrupt */
 
-PR_IMPLEMENT(void) PR_ClearInterrupt()
+PR_IMPLEMENT(void) PR_ClearInterrupt(void)
 {
     PRThread *me = PR_CurrentThread();
     me->state &= ~PT_THREAD_ABORTED;
 }  /* PR_ClearInterrupt */
 
-PR_IMPLEMENT(void) PR_BlockInterrupt()
+PR_IMPLEMENT(void) PR_BlockInterrupt(void)
 {
     PRThread *me = PR_CurrentThread();
     _PT_THREAD_BLOCK_INTERRUPT(me);
 }  /* PR_BlockInterrupt */
 
-PR_IMPLEMENT(void) PR_UnblockInterrupt()
+PR_IMPLEMENT(void) PR_UnblockInterrupt(void)
 {
     PRThread *me = PR_CurrentThread();
     _PT_THREAD_UNBLOCK_INTERRUPT(me);
 }  /* PR_UnblockInterrupt */
 
-PR_IMPLEMENT(PRStatus) PR_Yield()
+PR_IMPLEMENT(PRStatus) PR_Yield(void)
 {
     static PRBool warning = PR_TRUE;
     if (warning) warning = _PR_Obsolete(
         "PR_Yield()", "PR_Sleep(PR_INTERVAL_NO_WAIT)");
     return PR_Sleep(PR_INTERVAL_NO_WAIT);
 }
 
 PR_IMPLEMENT(PRStatus) PR_Sleep(PRIntervalTime ticks)
@@ -903,44 +903,53 @@ void _PR_InitThreads(
      */
     rv = _PT_PTHREAD_KEY_CREATE(&pt_book.key, _pt_thread_death);
     PR_ASSERT(0 == rv);
     rv = pthread_setspecific(pt_book.key, thred);
     PR_ASSERT(0 == rv);    
     PR_SetThreadPriority(thred, priority);
 }  /* _PR_InitThreads */
 
-PR_IMPLEMENT(PRStatus) PR_Cleanup()
+PR_IMPLEMENT(PRStatus) PR_Cleanup(void)
 {
     PRThread *me = PR_CurrentThread();
     PR_LOG(_pr_thread_lm, PR_LOG_MIN, ("PR_Cleanup: shutting down NSPR"));
     PR_ASSERT(me->state & PT_THREAD_PRIMORD);
     if (me->state & PT_THREAD_PRIMORD)
     {
         PR_Lock(pt_book.ml);
         while (pt_book.user > pt_book.this_many)
             PR_WaitCondVar(pt_book.cv, PR_INTERVAL_NO_TIMEOUT);
         PR_Unlock(pt_book.ml);
 
+        _PR_CleanupMW();
+        _PR_CleanupDtoa();
+        _PR_CleanupCallOnce();
+        _PR_ShutdownLinker();
         _PR_LogCleanup();
-        /* Close all the fd's before calling _PR_CleanupFdCache */
-        _PR_CleanupFdCache();
+        _PR_CleanupNet();
+        /* Close all the fd's before calling _PR_CleanupIO */
+        _PR_CleanupIO();
 
         /*
          * I am not sure if it's safe to delete the cv and lock here,
          * since there may still be "system" threads around. If this
          * call isn't immediately prior to exiting, then there's a
          * problem.
          */
         if (0 == pt_book.system)
         {
             PR_DestroyCondVar(pt_book.cv); pt_book.cv = NULL;
             PR_DestroyLock(pt_book.ml); pt_book.ml = NULL;
         }
         _pt_thread_death(me);
+        PR_DestroyLock(_pr_sleeplock);
+        _pr_sleeplock = NULL;
+        _PR_CleanupLayerCache();
+        _PR_CleanupEnv();
 #ifdef _PR_ZONE_ALLOCATOR
         _PR_DestroyZones();
 #endif
         _pr_initialized = PR_FALSE;
         return PR_SUCCESS;
     }
     return PR_FAILURE;
 }  /* PR_Cleanup */
@@ -1017,28 +1026,28 @@ static void null_signal_handler(PRIntn s
 
 #endif /* defined(_PR_DCETHREADS) */
 
 /*
  * Linux pthreads use SIGUSR1 and SIGUSR2 internally, which
  * conflict with the use of these two signals in our GC support.
  * So we don't know how to support GC on Linux pthreads.
  */
-static void init_pthread_gc_support()
+static void init_pthread_gc_support(void)
 {
     PRIntn rv;
 
 #if defined(_PR_DCETHREADS)
 	rv = sigemptyset(&javagc_vtalarm_sigmask);
     PR_ASSERT(0 == rv);
 	rv = sigaddset(&javagc_vtalarm_sigmask, SIGVTALRM);
     PR_ASSERT(0 == rv);
 #else  /* defined(_PR_DCETHREADS) */
 	{
-	    struct sigaction sigact_usr2 = {0};
+	    struct sigaction sigact_usr2;
 
 	    sigact_usr2.sa_handler = suspend_signal_handler;
 	    sigact_usr2.sa_flags = SA_RESTART;
 	    sigemptyset (&sigact_usr2.sa_mask);
 
         rv = sigaction (SIGUSR2, &sigact_usr2, NULL);
         PR_ASSERT(0 == rv);
 
@@ -1046,35 +1055,35 @@ static void init_pthread_gc_support()
 #if defined(PT_NO_SIGTIMEDWAIT)
         sigaddset (&sigwait_set, SIGUSR1);
 #else
         sigaddset (&sigwait_set, SIGUSR2);
 #endif  /* defined(PT_NO_SIGTIMEDWAIT) */
 	}
 #if defined(PT_NO_SIGTIMEDWAIT)
 	{
-	    struct sigaction sigact_null = {0};
+	    struct sigaction sigact_null;
 	    sigact_null.sa_handler = null_signal_handler;
 	    sigact_null.sa_flags = SA_RESTART;
 	    sigemptyset (&sigact_null.sa_mask);
         rv = sigaction (SIGUSR1, &sigact_null, NULL);
 	    PR_ASSERT(0 ==rv); 
     }
 #endif  /* defined(PT_NO_SIGTIMEDWAIT) */
 #endif /* defined(_PR_DCETHREADS) */
 }
 
-PR_IMPLEMENT(void) PR_SetThreadGCAble()
+PR_IMPLEMENT(void) PR_SetThreadGCAble(void)
 {
     PR_Lock(pt_book.ml);
 	PR_CurrentThread()->state |= PT_THREAD_GCABLE;
     PR_Unlock(pt_book.ml);
 }
 
-PR_IMPLEMENT(void) PR_ClearThreadGCAble()
+PR_IMPLEMENT(void) PR_ClearThreadGCAble(void)
 {
     PR_Lock(pt_book.ml);
 	PR_CurrentThread()->state &= (~PT_THREAD_GCABLE);
     PR_Unlock(pt_book.ml);
 }
 
 #if defined(DEBUG)
 static PRBool suspendAllOn = PR_FALSE;
@@ -1347,17 +1356,17 @@ PR_IMPLEMENT(void) PR_ResumeTest(PRThrea
     thred->suspend &= ~PT_THREAD_RESUMED;
 
     PR_LOG(_pr_gc_lm, PR_LOG_ALWAYS, (
         "End PR_ResumeTest thred %X tid %X\n", thred, thred->id));
 }  /* PR_ResumeTest */
 
 static pthread_once_t pt_gc_support_control = PTHREAD_ONCE_INIT;
 
-PR_IMPLEMENT(void) PR_SuspendAll()
+PR_IMPLEMENT(void) PR_SuspendAll(void)
 {
 #ifdef DEBUG
     PRIntervalTime stime, etime;
 #endif
     PRThread* thred = pt_book.first;
     PRThread *me = PR_CurrentThread();
     int rv;
 
@@ -1393,17 +1402,17 @@ PR_IMPLEMENT(void) PR_SuspendAll()
 #ifdef DEBUG
     etime = PR_IntervalNow();
     PR_LOG(_pr_gc_lm, PR_LOG_ALWAYS,\
         ("End PR_SuspendAll (time %dms)\n",
         PR_IntervalToMilliseconds(etime - stime)));
 #endif
 }  /* PR_SuspendAll */
 
-PR_IMPLEMENT(void) PR_ResumeAll()
+PR_IMPLEMENT(void) PR_ResumeAll(void)
 {
 #ifdef DEBUG
     PRIntervalTime stime, etime;
 #endif
     PRThread* thred = pt_book.first;
     PRThread *me = PR_CurrentThread();
     PR_LOG(_pr_gc_lm, PR_LOG_ALWAYS, ("Begin PR_ResumeAll\n"));
     /*
--- a/pr/src/threads/combined/prucpu.c
+++ b/pr/src/threads/combined/prucpu.c
@@ -54,63 +54,68 @@ PRInt32 _pr_cpus_exit;
 PRInt32 _pr_cpu_affinity_mask = 0;
 
 #if !defined (_PR_GLOBAL_THREADS_ONLY)
 
 static PRUintn _pr_cpuID;
 
 static void PR_CALLBACK _PR_CPU_Idle(void *);
 
-static _PRCPU *_PR_CreateCPU(PRThread *thread, PRBool needQueue);
+static _PRCPU *_PR_CreateCPU(void);
+static PRStatus _PR_StartCPU(_PRCPU *cpu, PRThread *thread);
 
 #if !defined(_PR_LOCAL_THREADS_ONLY)
 static void _PR_RunCPU(void *arg);
 #endif
 
 void  _PR_InitCPUs()
 {
     PRThread *me = _PR_MD_CURRENT_THREAD();
 
+    if (_native_threads_only)
+        return;
+
     _pr_cpuID = 0;
     _MD_NEW_LOCK( &_pr_cpuLock);
 #if !defined(_PR_LOCAL_THREADS_ONLY) && !defined(_PR_GLOBAL_THREADS_ONLY)
 #ifndef _PR_HAVE_ATOMIC_OPS
     _MD_NEW_LOCK(&_pr_md_idle_cpus_lock);
 #endif
 #endif
 
 #ifdef _PR_LOCAL_THREADS_ONLY
 
 #ifdef HAVE_CUSTOM_USER_THREADS
-	if (!_native_threads_only)
-    	_PR_MD_CREATE_PRIMORDIAL_USER_THREAD(me);
+    _PR_MD_CREATE_PRIMORDIAL_USER_THREAD(me);
 #endif
 
     /* Now start the first CPU. */
-    _pr_primordialCPU = _PR_CreateCPU(me, PR_TRUE);
+    _pr_primordialCPU = _PR_CreateCPU();
     _pr_numCPU = 1;
+    _PR_StartCPU(_pr_primordialCPU, me);
 
     _PR_MD_SET_CURRENT_CPU(_pr_primordialCPU);
 
     /* Initialize cpu for current thread (could be different from me) */
     _PR_MD_CURRENT_THREAD()->cpu = _pr_primordialCPU;
 
     _PR_MD_SET_LAST_THREAD(me);
 
 #else /* Combined MxN model */
 
+    _pr_primordialCPU = _PR_CreateCPU();
+    _pr_numCPU = 1;
     _PR_CreateThread(PR_SYSTEM_THREAD,
                      _PR_RunCPU,
-                     me,
+                     _pr_primordialCPU,
                      PR_PRIORITY_NORMAL,
                      PR_GLOBAL_THREAD,
                      PR_UNJOINABLE_THREAD,
                      0,
                      _PR_IDLE_THREAD);
-    _PR_MD_WAIT(me, PR_INTERVAL_NO_TIMEOUT);
 
 #endif /* _PR_LOCAL_THREADS_ONLY */
 
     _PR_MD_INIT_CPUS();
 }
 
 
 static _PRCPUQueue *_PR_CreateCPUQueue(void)
@@ -132,131 +137,149 @@ static _PRCPUQueue *_PR_CreateCPUQueue(v
 
     cpuQueue->numCPUs = 1;
 
     return cpuQueue;
 }
 
 /*
  * Create a new CPU.
+ *
+ * This function initializes enough of the _PRCPU structure so
+ * that it can be accessed safely by a global thread or another
+ * CPU.  This function does not create the native thread that
+ * will run the CPU nor does it initialize the parts of _PRCPU
+ * that must be initialized by that native thread.
+ *
+ * The reason we cannot simply have the native thread create
+ * and fully initialize a new CPU is that we need to be able to
+ * create a usable _pr_primordialCPU in _PR_InitCPUs without
+ * assuming that the primordial CPU thread we created can run
+ * during NSPR initialization.  For example, on Windows while
+ * new threads can be created by DllMain, they won't be able
+ * to run during DLL initialization.  If NSPR is initialized
+ * by DllMain, the primordial CPU thread won't run until DLL
+ * initialization is finished.
  */
-static _PRCPU *_PR_CreateCPU(PRThread *thread, PRBool needQueue)
+static _PRCPU *_PR_CreateCPU(void)
 {
     _PRCPU *cpu;
 
-    /*
-    ** Create a new cpu. The assumption this code makes is that the
-    ** underlying operating system creates a stack to go with the new
-    ** native thread. That stack will be used by the cpu when pausing.
-    */
     cpu = PR_NEWZAP(_PRCPU);
     if (cpu) {
-        cpu->last_clock = PR_IntervalNow();
-
-        if (needQueue == PR_TRUE)
-            cpu->queue = _PR_CreateCPUQueue();
-        else 
-            cpu->queue = _PR_MD_CURRENT_CPU()->queue;
-   
+        cpu->queue = _PR_CreateCPUQueue();
         if (!cpu->queue) {
             PR_DELETE(cpu);
             return NULL;
         }
-
-        /* Before we create any threads on this CPU we have to
-         * set the current CPU 
-         */
-        _PR_MD_SET_CURRENT_CPU(cpu);
-        _PR_MD_INIT_RUNNING_CPU(cpu);
-        thread->cpu = cpu;
+    }
+    return cpu;
+}
 
-		if (!_native_threads_only) {
-			
-			cpu->idle_thread = _PR_CreateThread(PR_SYSTEM_THREAD,
-											   _PR_CPU_Idle,
-											   (void *)cpu,
-											   PR_PRIORITY_NORMAL,
-											   PR_LOCAL_THREAD,
-											   PR_UNJOINABLE_THREAD,
-											   0,
-											   _PR_IDLE_THREAD);
+/*
+ * Start a new CPU.
+ *
+ * 'cpu' is a _PRCPU structure created by _PR_CreateCPU().
+ * 'thread' is the native thread that will run the CPU.
+ *
+ * If this function fails, 'cpu' is destroyed.
+ */
+static PRStatus _PR_StartCPU(_PRCPU *cpu, PRThread *thread)
+{
+    /*
+    ** Start a new cpu. The assumption this code makes is that the
+    ** underlying operating system creates a stack to go with the new
+    ** native thread. That stack will be used by the cpu when pausing.
+    */
+
+    PR_ASSERT(!_native_threads_only);
+
+    cpu->last_clock = PR_IntervalNow();
+
+    /* Before we create any threads on this CPU we have to
+     * set the current CPU 
+     */
+    _PR_MD_SET_CURRENT_CPU(cpu);
+    _PR_MD_INIT_RUNNING_CPU(cpu);
+    thread->cpu = cpu;
 
-			if (!cpu->idle_thread) {
-				/* didn't clean up CPU queue XXXMB */
-				PR_DELETE(cpu);
-				return NULL;
-			} 
-			cpu->idle_thread->cpu = cpu;
-
-			cpu->idle_thread->no_sched = 0;
-		}
+    cpu->idle_thread = _PR_CreateThread(PR_SYSTEM_THREAD,
+                                        _PR_CPU_Idle,
+                                        (void *)cpu,
+                                        PR_PRIORITY_NORMAL,
+                                        PR_LOCAL_THREAD,
+                                        PR_UNJOINABLE_THREAD,
+                                        0,
+                                        _PR_IDLE_THREAD);
 
-        cpu->thread = thread;
+    if (!cpu->idle_thread) {
+        /* didn't clean up CPU queue XXXMB */
+        PR_DELETE(cpu);
+        return PR_FAILURE;
+    } 
+    PR_ASSERT(cpu->idle_thread->cpu == cpu);
 
-        if (_pr_cpu_affinity_mask)
-            PR_SetThreadAffinityMask(thread, _pr_cpu_affinity_mask);
+    cpu->idle_thread->no_sched = 0;
+
+    cpu->thread = thread;
 
-	    /* Created a new CPU */
-	_PR_CPU_LIST_LOCK();
-        cpu->id = _pr_cpuID++;
-        PR_APPEND_LINK(&cpu->links, &_PR_CPUQ());
-	_PR_CPU_LIST_UNLOCK();
-   }
-    return cpu;
+    if (_pr_cpu_affinity_mask)
+        PR_SetThreadAffinityMask(thread, _pr_cpu_affinity_mask);
+
+    /* Created and started a new CPU */
+    _PR_CPU_LIST_LOCK();
+    cpu->id = _pr_cpuID++;
+    PR_APPEND_LINK(&cpu->links, &_PR_CPUQ());
+    _PR_CPU_LIST_UNLOCK();
+
+    return PR_SUCCESS;
 }
 
 #if !defined(_PR_GLOBAL_THREADS_ONLY) && !defined(_PR_LOCAL_THREADS_ONLY)
 /*
 ** This code is used during a cpu's initial creation.
 */
 static void _PR_RunCPU(void *arg)
 {
-    _PRCPU *cpu;
+    _PRCPU *cpu = (_PRCPU *)arg;
     PRThread *me = _PR_MD_CURRENT_THREAD();
-    PRThread *waiter = (PRThread *) arg;
 
     PR_ASSERT(NULL != me);
 
     /*
-     * _PR_CreateCPU calls _PR_CreateThread to create the
+     * _PR_StartCPU calls _PR_CreateThread to create the
      * idle thread.  Because _PR_CreateThread calls PR_Lock,
      * the current thread has to remain a global thread
-     * during the _PR_CreateCPU call so that it can wait for
+     * during the _PR_StartCPU call so that it can wait for
      * the lock if the lock is held by another thread.  If
      * we clear the _PR_GLOBAL_SCOPE flag in
      * _PR_MD_CREATE_PRIMORDIAL_THREAD, the current thread
      * will be treated as a local thread and have trouble
      * waiting for the lock because the CPU is not fully
      * constructed yet.
      *
-     * After the CPU is created, it is safe to mark the
+     * After the CPU is started, it is safe to mark the
      * current thread as a local thread.
      */
 
 #ifdef HAVE_CUSTOM_USER_THREADS
     _PR_MD_CREATE_PRIMORDIAL_USER_THREAD(me);
 #endif
 
     me->no_sched = 1;
-    cpu = _PR_CreateCPU(me, PR_TRUE);
+    _PR_StartCPU(cpu, me);
 
 #ifdef HAVE_CUSTOM_USER_THREADS
     me->flags &= (~_PR_GLOBAL_SCOPE);
 #endif
 
     _PR_MD_SET_CURRENT_CPU(cpu);
     _PR_MD_SET_CURRENT_THREAD(cpu->thread);
     me->cpu = cpu;
 
-    if (waiter) {
-        _pr_primordialCPU = cpu;
-        _pr_numCPU = 1;
-        _PR_MD_WAKEUP_WAITER(waiter);
-    }
-
     while(1) {
         PRInt32 is;
         if (!_PR_IS_NATIVE_THREAD(me)) _PR_INTSOFF(is);
 	    _PR_MD_START_INTERRUPTS();
         _PR_MD_SWITCH_CONTEXT(me);
     }
 }
 #endif
@@ -339,35 +362,37 @@ PR_IMPLEMENT(void) PR_SetConcurrency(PRU
 #pragma unused(numCPUs) 
 #endif
 
     /* do nothing */
 
 #else /* combined, MxN thread model */
 
     PRUintn newCPU;
-    PRThread *cpu;
+    _PRCPU *cpu;
+    PRThread *thr;
 
 
     if (!_pr_initialized) _PR_ImplicitInitialization();
 
 	if (_native_threads_only)
 		return;
     
     _PR_CPU_LIST_LOCK();
     if (_pr_numCPU < numCPUs) {
         newCPU = numCPUs - _pr_numCPU;
         _pr_numCPU = numCPUs;
     } else newCPU = 0;
     _PR_CPU_LIST_UNLOCK();
 
     for (; newCPU; newCPU--) {
-        cpu = _PR_CreateThread(PR_SYSTEM_THREAD,
+        cpu = _PR_CreateCPU();
+        thr = _PR_CreateThread(PR_SYSTEM_THREAD,
                               _PR_RunCPU,
-                              NULL,
+                              cpu,
                               PR_PRIORITY_NORMAL,
                               PR_GLOBAL_THREAD,
                               PR_UNJOINABLE_THREAD,
                               0,
                               _PR_IDLE_THREAD);
     }
 #endif
 }
--- a/pr/src/threads/combined/prustack.c
+++ b/pr/src/threads/combined/prustack.c
@@ -53,16 +53,24 @@ PRBool _pr_debugStacks = PR_FALSE;
 #define _PR_THREAD_STACK_PTR(_qp) \
     ((PRThreadStack*) ((char*) (_qp) - offsetof(PRThreadStack,links)))
 
 void _PR_InitStacks(void)
 {
     _pr_stackLock = PR_NewLock();
 }
 
+void _PR_CleanupStacks(void)
+{
+    if (_pr_stackLock) {
+        PR_DestroyLock(_pr_stackLock);
+        _pr_stackLock = NULL;
+    }
+}
+
 /*
 ** Allocate a stack for a thread.
 */
 PRThreadStack *_PR_NewStack(PRUint32 stackSize)
 {
     PRCList *qp;
     PRThreadStack *ts;
     PRThread *thr;
--- a/pr/src/threads/combined/pruthr.c
+++ b/pr/src/threads/combined/pruthr.c
@@ -80,17 +80,16 @@ PRUint32 _pr_join_counter;
 PRUint32 _pr_local_threads;
 PRUint32 _pr_global_threads;
 
 PRBool suspendAllOn = PR_FALSE;
 PRThread *suspendAllThread = NULL;
 
 extern PRCList _pr_active_global_threadQ;
 extern PRCList _pr_active_local_threadQ;
-extern _PRCPU  *_pr_primordialCPU;
 
 static void _PR_DecrActiveThreadCount(PRThread *thread);
 static PRThread *_PR_AttachThread(PRThreadType, PRThreadPriority, PRThreadStack *);
 static void _PR_InitializeNativeStack(PRThreadStack *ts);
 static void _PR_InitializeRecycledThread(PRThread *thread);
 static void _PR_UserRunThread(void);
 
 void _PR_InitThreads(PRThreadType type, PRThreadPriority priority,
@@ -174,16 +173,37 @@ void _PR_InitThreads(PRThreadType type, 
     _pr_recycleThreads = 0;
     _pr_deadQLock = PR_NewLock();
     _pr_numNativeDead = 0;
     _pr_numUserDead = 0;
     PR_INIT_CLIST(&_pr_deadNativeQ);
     PR_INIT_CLIST(&_pr_deadUserQ);
 }
 
+void _PR_CleanupThreads(void)
+{
+    if (_pr_terminationCVLock) {
+        PR_DestroyLock(_pr_terminationCVLock);
+        _pr_terminationCVLock = NULL;
+    }
+    if (_pr_activeLock) {
+        PR_DestroyLock(_pr_activeLock);
+        _pr_activeLock = NULL;
+    }
+    if (_pr_primordialExitCVar) {
+        PR_DestroyCondVar(_pr_primordialExitCVar);
+        _pr_primordialExitCVar = NULL;
+    }
+    /* TODO _pr_dead{Native,User}Q need to be deleted */
+    if (_pr_deadQLock) {
+        PR_DestroyLock(_pr_deadQLock);
+        _pr_deadQLock = NULL;
+    }
+}
+
 /*
 ** Initialize a stack for a native thread
 */
 static void _PR_InitializeNativeStack(PRThreadStack *ts)
 {
     if( ts && (ts->stackTop == 0) ) {
         ts->allocSize = ts->stackSize;
 
--- a/pr/src/threads/prtpd.c
+++ b/pr/src/threads/prtpd.c
@@ -83,17 +83,17 @@ static PRInt32 _pr_tpd_highwater = 0;   
 static PRThreadPrivateDTOR *_pr_tpd_destructors = NULL;
                                         /* the destructors are associated with
                                             the keys, therefore asserting that
                                             the TPD key depicts the data's 'type' */
 
 /*
 ** Initialize the thread private data manipulation
 */
-void _PR_InitTPD()
+void _PR_InitTPD(void)
 {
     _pr_tpd_destructors = (PRThreadPrivateDTOR*)
         PR_CALLOC(_PR_TPD_LIMIT * sizeof(PRThreadPrivateDTOR*));
     PR_ASSERT(NULL != _pr_tpd_destructors);
     _pr_tpd_length = _PR_TPD_LIMIT;
 }
 
 /*
--- a/pr/tests/Makefile.in
+++ b/pr/tests/Makefile.in
@@ -291,18 +291,20 @@ ifeq ($(OS_ARCH), OSF1)
     else
         LDOPTS += -rpath $(ABSOLUTE_LIB_DIR)
     endif
 endif
 
 ifeq ($(OS_ARCH), HP-UX)
     LDOPTS += -z -Wl,+s,+b,$(ABSOLUTE_LIB_DIR)
     ifeq ($(USE_64),1)
-        LDOPTS += +DA2.0W
-        EXTRA_LIBS = -lpthread
+        LDOPTS += +DD64
+    endif
+    ifeq ($(USE_PTHREADS),1)
+        EXTRA_LIBS = $(LIBPTHREAD)
     endif
 endif
 
 # AIX
 ifeq ($(OS_ARCH),AIX)
     LDOPTS += -blibpath:$(ABSOLUTE_LIB_DIR):/usr/lib:/lib
     ifneq ($(OS_ARCH)$(OS_RELEASE),AIX4.1)
         LDOPTS += -brtl
--- a/pr/tests/sigpipe.c
+++ b/pr/tests/sigpipe.c
@@ -64,29 +64,26 @@ int main(void)
 #ifdef XP_OS2_VACPP
 #define EPIPE EBADF  /* IBM's write() doesn't return EPIPE */
 #include <io.h>
 #else
 #include <unistd.h>
 #endif
 #include <errno.h>
 
-int main(void)
+static void Test(void *arg)
 {
 #ifdef XP_OS2
     HFILE pipefd[2];
 #else
     int pipefd[2];
 #endif
     int rv;
     char c = '\0';
 
-    /* This initializes NSPR. */
-    PR_SetError(0, 0);
-
 #ifdef XP_OS2
     if (DosCreatePipe(&pipefd[0], &pipefd[1], 4096) != 0) {
 #else
     if (pipe(pipefd) == -1) {
 #endif
         fprintf(stderr, "cannot create pipe: %d\n", errno);
         exit(1);
     }
@@ -98,13 +95,34 @@ int main(void)
         exit(1);
     }
     if (errno != EPIPE) {
         fprintf(stderr, "write to broken pipe failed but with wrong errno: %d\n", errno);
         exit(1);
     }
     close(pipefd[1]);
     printf("write to broken pipe failed with EPIPE, as expected\n");
+}
+
+int main(void)
+{
+    PRThread *thread;
+
+    /* This initializes NSPR. */
+    PR_SetError(0, 0);
+
+    thread = PR_CreateThread(PR_USER_THREAD, Test, NULL, PR_PRIORITY_NORMAL,
+            PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
+    if (thread == NULL) {
+        fprintf(stderr, "PR_CreateThread failed\n");
+        exit(1);
+    }
+    if (PR_JoinThread(thread) == PR_FAILURE) {
+        fprintf(stderr, "PR_JoinThread failed\n");
+        exit(1);
+    }
+    Test(NULL);
+
     printf("PASSED\n");
     return 0;
 }
 
 #endif /* XP_UNIX */
--- a/pr/tests/vercheck.c
+++ b/pr/tests/vercheck.c
@@ -44,38 +44,38 @@
  */
 
 #include "prinit.h"
 
 #include <stdio.h>
 #include <stdlib.h>
 
 /*
- * This release (4.1) is backward compatible with the
- * 4.0.x releases.  It, of course, is compatible with
- * itself.
+ * This release (4.2) is backward compatible with the
+ * 4.0.x and 4.1.x releases.  It, of course, is compatible
+ * with itself.
  */
 static char *compatible_version[] = {
-    "4.0", "4.0.1", "4.0.2", PR_VERSION
+    "4.0", "4.0.1", "4.1", "4.1.1", "4.1.2", "4.1.3", PR_VERSION
 };
 
 /*
  * This release is not backward compatible with the old
  * NSPR 2.1 and 3.x releases.
  *
  * Any release is incompatible with future releases and
  * patches.
  */
 static char *incompatible_version[] = {
     "2.1 19980529",
     "3.0", "3.0.1",
     "3.1", "3.1.1", "3.1.2", "3.1.3",
     "3.5", "3.5.1",
-    "4.1.3",
-    "4.2", "4.2.1",
+    "4.2.3",
+    "4.3", "4.3.1",
     "10.0", "11.1", "12.14.20"
 };
 
 int main()
 {
     int idx;
     int num_compatible = sizeof(compatible_version) / sizeof(char *);
     int num_incompatible = sizeof(incompatible_version) / sizeof(char *);