Set up NSPRPUB_RELEASE_3_0_LANDING_BRANCH for landing the NSPR20 NSPRPUB_RELEASE_3_0_LANDING_BRANCH
authorwtc%netscape.com
Tue, 22 Sep 1998 22:27:32 +0000
branchNSPRPUB_RELEASE_3_0_LANDING_BRANCH
changeset 252 6849cd06bcb00b84b835466389d75454fe419f25
parent 251 8389b7d24d9fafa96d49587d67cf894cfa47c612
child 253 4a7cc5ada77498e2a095c29933c65fefd88952cc
push idunknown
push userunknown
push dateunknown
Set up NSPRPUB_RELEASE_3_0_LANDING_BRANCH for landing the NSPR20 v3.0 release to mozilla.org.
config/AIX.mk
config/BSD_OS.mk
config/FreeBSD.mk
config/HP-UX.mk
config/IRIX.mk
config/Linux.mk
config/Makefile
config/NCR.mk
config/NEC.mk
config/NEWS-OS.mk
config/NetBSD.mk
config/OSF1.mk
config/OpenBSD.mk
config/Rhapsody.mk
config/SCOOS.mk
config/SINIX.mk
config/SunOS.mk
config/SunOS4.mk
config/SunOS5.mk
config/UNIX.mk
config/UNIXWARE.mk
config/WIN32.mk
config/config.mk
config/now.c
config/nsinstall.c
config/pathsub.c
config/rules.mk
lib/Makefile
lib/ds/Makefile
lib/ds/plevent.c
lib/ds/plhash.c
lib/ds/plhash.h
lib/libc/src/Makefile
lib/libc/src/plerror.c
lib/libc/src/plvrsion.c
lib/msgc/include/gcint.h
lib/msgc/include/prgc.h
lib/msgc/src/Makefile
lib/msgc/src/prmsgc.c
lib/msgc/src/unixgc.c
lib/msgc/tests/Makefile
lib/prstreams/Makefile
pr/include/md/Makefile
pr/include/md/_aix.h
pr/include/md/_bsdi.h
pr/include/md/_darwin.cfg
pr/include/md/_darwin.h
pr/include/md/_dgux.cfg
pr/include/md/_dgux.h
pr/include/md/_freebsd.h
pr/include/md/_hpux.cfg
pr/include/md/_hpux.h
pr/include/md/_hpux32.cfg
pr/include/md/_hpux64.cfg
pr/include/md/_irix.cfg
pr/include/md/_irix.h
pr/include/md/_irix32.cfg
pr/include/md/_irix64.cfg
pr/include/md/_linux.h
pr/include/md/_macos.h
pr/include/md/_ncr.cfg
pr/include/md/_ncr.h
pr/include/md/_nec.h
pr/include/md/_netbsd.h
pr/include/md/_nspr_pthread.h
pr/include/md/_openbsd.cfg
pr/include/md/_openbsd.h
pr/include/md/_os2.h
pr/include/md/_osf1.cfg
pr/include/md/_osf1.h
pr/include/md/_pth.h
pr/include/md/_reliantunix.cfg
pr/include/md/_reliantunix.h
pr/include/md/_rhapsody.cfg
pr/include/md/_rhapsody.h
pr/include/md/_scoos.cfg
pr/include/md/_scoos.h
pr/include/md/_solaris.h
pr/include/md/_sony.h
pr/include/md/_sunos4.h
pr/include/md/_unix_errors.h
pr/include/md/_unixos.h
pr/include/md/_unixware.cfg
pr/include/md/_unixware.h
pr/include/md/_win16.h
pr/include/md/_win95.h
pr/include/md/_winnt.h
pr/include/md/prosdep.h
pr/include/nspr.h
pr/include/obsolete/pralarm.h
pr/include/obsolete/protypes.h
pr/include/pratom.h
pr/include/prbit.h
pr/include/prcountr.h
pr/include/prdtoa.h
pr/include/prerror.h
pr/include/prinit.h
pr/include/prio.h
pr/include/private/Makefile
pr/include/private/pprio.h
pr/include/private/pprmwait.h
pr/include/private/primpl.h
pr/include/prlog.h
pr/include/prmem.h
pr/include/prmwait.h
pr/include/prolock.h
pr/include/prpdce.h
pr/include/prtrace.h
pr/include/prtypes.h
pr/include/prvrsion.h
pr/src/Makefile
pr/src/io/Makefile
pr/src/io/pprmwait.h
pr/src/io/prfdcach.c
pr/src/io/prfile.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/prpolevt.c
pr/src/io/prsocket.c
pr/src/linking/prlink.c
pr/src/malloc/prmalloc.c
pr/src/malloc/prmem.c
pr/src/md/mac/macio.c
pr/src/md/mac/macsockclient.c
pr/src/md/mac/macsockotpt.c
pr/src/md/mac/macthr.c
pr/src/md/os2/os2poll.c
pr/src/md/prosdep.c
pr/src/md/unix/Makefile
pr/src/md/unix/aix.c
pr/src/md/unix/darwin.c
pr/src/md/unix/hpux.c
pr/src/md/unix/irix.c
pr/src/md/unix/ncr.c
pr/src/md/unix/objs.mk
pr/src/md/unix/openbsd.c
pr/src/md/unix/os_Irix.s
pr/src/md/unix/os_SunOS.s
pr/src/md/unix/os_SunOS_ultrasparc.s
pr/src/md/unix/osf1.c
pr/src/md/unix/pthreads_user.c
pr/src/md/unix/rhapsody.c
pr/src/md/unix/scoos.c
pr/src/md/unix/solaris.c
pr/src/md/unix/unix.c
pr/src/md/unix/unix_errors.c
pr/src/md/unix/unixware.c
pr/src/md/unix/uxpoll.c
pr/src/md/unix/uxproces.c
pr/src/md/unix/uxwrap.c
pr/src/md/windows/Makefile
pr/src/md/windows/ntdllmn.c
pr/src/md/windows/ntio.c
pr/src/md/windows/ntmisc.c
pr/src/md/windows/ntthread.c
pr/src/md/windows/w16callb.c
pr/src/md/windows/w16mem.c
pr/src/md/windows/w32poll.c
pr/src/md/windows/w95dllmain.c
pr/src/md/windows/w95sock.c
pr/src/md/windows/w95thred.c
pr/src/md/windows/win32_errors.c
pr/src/memory/prseg.c
pr/src/misc/Makefile
pr/src/misc/pratom.c
pr/src/misc/prcountr.c
pr/src/misc/prdtoa.c
pr/src/misc/prinit.c
pr/src/misc/prolock.c
pr/src/misc/prthinfo.c
pr/src/misc/prtime.c
pr/src/misc/prtrace.c
pr/src/prvrsion.c
pr/src/pthreads/ptio.c
pr/src/pthreads/ptmisc.c
pr/src/pthreads/ptsynch.c
pr/src/pthreads/ptthread.c
pr/src/threads/Makefile
pr/src/threads/combined/prucpu.c
pr/src/threads/combined/prucv.c
pr/src/threads/combined/prustack.c
pr/src/threads/combined/pruthr.c
pr/src/threads/prcthr.c
pr/src/threads/prtpd.c
pr/tests/Makefile
pr/tests/accept.c
pr/tests/atomic.c
pr/tests/attach.c
pr/tests/bigfile.c
pr/tests/cltsrv.c
pr/tests/concur.c
pr/tests/cvar2.c
pr/tests/dceemu.c
pr/tests/dll/Makefile
pr/tests/dlltest.c
pr/tests/foreign.c
pr/tests/forktest.c
pr/tests/initclk.c
pr/tests/inrval.c
pr/tests/instrumt.c
pr/tests/ipv6.c
pr/tests/joinkk.c
pr/tests/layer.c
pr/tests/lock.c
pr/tests/many_cv.c
pr/tests/multiwait.c
pr/tests/nbconn.c
pr/tests/nblayer.c
pr/tests/op_filok.c
pr/tests/op_noacc.c
pr/tests/op_nofil.c
pr/tests/parent.c
pr/tests/perf.c
pr/tests/poll_nm.c
pr/tests/pollable.c
pr/tests/prftest2.c
pr/tests/priotest.c
pr/tests/provider.c
pr/tests/sel_spd.c
pr/tests/socket.c
pr/tests/stack.c
pr/tests/switch.c
pr/tests/testfile.c
pr/tests/tpd.c
pr/tests/udpsrv.c
pr/tests/version.c
--- a/config/AIX.mk
+++ b/config/AIX.mk
@@ -21,77 +21,75 @@
 
 include $(MOD_DEPTH)/config/UNIX.mk
 
 #
 # XXX
 # Temporary define for the Client; to be removed when binary release is used
 #
 ifdef MOZILLA_CLIENT
+ifneq ($(USE_PTHREADS),1)
 CLASSIC_NSPR = 1
 endif
+endif
 
 #
 # There are three implementation strategies available on AIX:
 # pthreads, classic, and pthreads-user.  The default is pthreads.
 # 
 ifeq ($(CLASSIC_NSPR),1)
 	PTHREADS_USER =
 	USE_PTHREADS =
-	IMPL_STRATEGY = _CLASSIC
+	IMPL_STRATEGY = _EMU
 	DEFINES += -D_PR_LOCAL_THREADS_ONLY
 else
 ifeq ($(PTHREADS_USER),1)
 	USE_PTHREADS =
 	IMPL_STRATEGY = _PTH_USER
 else
 	USE_PTHREADS = 1
-endif
+	IMPL_STRATEGY = _PTH
 endif
-
-#
-# XXX
-# Temporary define for the Client; to be removed when binary release is used
-#
-ifdef MOZILLA_CLIENT
-IMPL_STRATEGY =
 endif
 
 ifeq ($(CLASSIC_NSPR),1)
 CC		= xlC
 CCC		= xlC
 else
 CC		= xlC_r
 CCC		= xlC_r
 endif
 
 CPU_ARCH	= rs6000
 
 RANLIB		= ranlib
 
-ifdef USE_AUTOCONF
-OS_CFLAGS	=
-else
-
 OS_CFLAGS 	= -qro -qroconst -DAIX -DSYSV
 ifeq ($(CC),xlC_r)
 OS_CFLAGS 	+= -qarch=com
 endif
 
 ifeq ($(OS_RELEASE),4.1)
-OS_CFLAGS	+= -DAIX4_1
+OS_CFLAGS	+= -DAIX4_1 -D_PR_NO_LARGE_FILES
 else
 DSO_LDOPTS	= -brtl -bM:SRE -bnoentry -bexpall
 MKSHLIB		= $(LD) $(DSO_LDOPTS)
 ifeq ($(OS_RELEASE),4.3)
 OS_CFLAGS	+= -DAIX4_3
 endif
 endif
 
-endif # USE_AUTOCONF
+ifeq (,$(filter-out 4.2 4.3,$(OS_RELEASE)))
+# On these OS revisions, localtime_r() is declared if _THREAD_SAFE
+# is defined.
+ifneq ($(CLASSIC_NSPR),1)
+OS_CFLAGS	+= -DHAVE_POINTER_LOCALTIME_R
+endif
+OS_CFLAGS	+= -D_PR_HAVE_OFF64_T
+endif
 
 #
 # Special link info for constructing AIX programs. On AIX we have to
 # statically link programs that use NSPR into a single .o, rewriting the
 # calls to select to call "aix". Once that is done we then can
 # link that .o with a .o built in nspr which implements the system call.
 #
 ifneq ($(OS_RELEASE),4.1)
--- a/config/BSD_OS.mk
+++ b/config/BSD_OS.mk
@@ -27,21 +27,17 @@ CC		= shlicc2
 CCC		= shlicc2
 RANLIB		= ranlib
 
 DEFINES		+= -D_PR_LOCAL_THREADS_ONLY
 OS_CFLAGS	= -DBSDI -DHAVE_STRERROR -D__386BSD__ -DNEED_BSDREGEX -Di386
 OS_LIBS		= -lcompat -ldl
 
 ifeq ($(OS_RELEASE),2.1)
-OS_CFLAGS	+= -DBSDI_2
-endif
-
-ifdef USE_AUTOCONF
-OS_CFLAGS	=
+OS_CFLAGS	+= -DBSDI_2 -D_PR_TIMESPEC_HAS_TS_SEC
 endif
 
 G++INCLUDES	= -I/usr/include/g++
 
 CPU_ARCH	= x86
 
 NOSUCHFILE	= /no-such-file
 
--- a/config/FreeBSD.mk
+++ b/config/FreeBSD.mk
@@ -23,27 +23,24 @@ include $(MOD_DEPTH)/config/UNIX.mk
 
 CC			= gcc
 CCC			= g++
 RANLIB			= ranlib
 
 OS_REL_CFLAGS		= -mno-486 -Di386
 CPU_ARCH		= x86
 
-ifdef USE_AUTOCONF
-OS_CFLAGS		= $(DSO_CFLAGS)
-else
-OS_CFLAGS		= $(DSO_CFLAGS) $(OS_REL_CFLAGS) -ansi -Wall -pipe -DFREEBSD -DHAVE_STRERROR -DHAVE_BSD_FLOCK -D_PR_NEED_POLL
-endif
+OS_CFLAGS		= $(DSO_CFLAGS) $(OS_REL_CFLAGS) -ansi -Wall -pipe -DFREEBSD -DHAVE_STRERROR -DHAVE_BSD_FLOCK
 
 ifeq ($(USE_PTHREADS),1)
+IMPL_STRATEGY		= _PTH
 OS_LIBS			= -lc_r
-# XXX probably should define _THREAD_SAFE too.
-DEFINES			+= -D_PR_NEED_FAKE_POLL
+DEFINES			+= -D_THREAD_SAFE -D_PR_NEED_FAKE_POLL
 else
+IMPL_STRATEGY		= _EMU
 OS_LIBS			= -lc
 DEFINES			+= -D_PR_LOCAL_THREADS_ONLY
 endif
 
 ARCH			= freebsd
 
 DLL_SUFFIX		= so.1.0
 
--- a/config/HP-UX.mk
+++ b/config/HP-UX.mk
@@ -19,23 +19,24 @@
 # Config stuff for HP-UX
 #
 
 include $(MOD_DEPTH)/config/UNIX.mk
 
 DLL_SUFFIX	= sl
 
 ifdef NS_USE_GCC
-CC			= gcc
-CCC			= g++
-OS_CFLAGS		=
+	CC			        = gcc
+	CCC			        = g++
+	OS_CFLAGS		    =
+	COMPILER_TAG        = _gcc
 else
-CC			= cc -Ae
-CCC			= CC
-OS_CFLAGS		= +ESlit
+	CC			        = cc -Ae
+	CCC			        = CC -ext
+	OS_CFLAGS           = +ESlit
 endif
 
 RANLIB			= echo
 
 CPU_ARCH		= hppa
 
 OS_CFLAGS		+= $(DSO_CFLAGS) -DHPUX -D$(CPU_ARCH) -D_HPUX_SOURCE
 
@@ -47,16 +48,24 @@ OS_CFLAGS		+= $(DSO_CFLAGS) -DHPUX -D$(C
 #
 ifeq ($(basename $(OS_RELEASE)),A.09)
 OS_CFLAGS		+= -D_PR_NEED_H_ERRNO
 endif
 ifeq (,$(filter-out B.10.10 B.10.20,$(OS_RELEASE)))
 OS_CFLAGS		+= -D_PR_NEED_H_ERRNO
 endif
 
+# Do we have localtime_r()?  Does it return 'int' or 'struct tm *'?
+ifeq (,$(filter-out B.10.10 B.10.20,$(OS_RELEASE)))
+OS_CFLAGS		+= -DHAVE_INT_LOCALTIME_R
+endif
+ifeq (,$(filter-out B.10.30 B.11.00,$(OS_RELEASE)))
+OS_CFLAGS		+= -DHAVE_POINTER_LOCALTIME_R
+endif
+
 #
 # XXX
 # Temporary define for the Client; to be removed when binary release is used
 #
 ifdef MOZILLA_CLIENT
 CLASSIC_NSPR = 1
 endif
 
@@ -67,83 +76,89 @@ endif
 # On HP-UX 10.10 and 10.20, the default implementation strategy is
 # pthreads (actually DCE threads).  Classic nspr is also available.
 #
 # On HP-UX 10.30 and 11.00, the default implementation strategy is
 # pthreads.  Classic nspr and pthreads-user are also available.
 #
 ifeq ($(basename $(OS_RELEASE)),A.09)
 OS_CFLAGS		+= -DHPUX9
-DEFAULT_IMPL_STRATEGY = _CLASSIC
+DEFAULT_IMPL_STRATEGY = _EMU
 endif
 
 ifeq ($(OS_RELEASE),B.10.01)
 OS_CFLAGS		+= -DHPUX10
-DEFAULT_IMPL_STRATEGY = _CLASSIC
+DEFAULT_IMPL_STRATEGY = _EMU
 endif
 
 ifeq ($(OS_RELEASE),B.10.10)
 OS_CFLAGS		+= -DHPUX10 -DHPUX10_10
 DEFAULT_IMPL_STRATEGY = _PTH
 endif
 
 ifeq ($(OS_RELEASE),B.10.20)
 OS_CFLAGS		+= -DHPUX10 -DHPUX10_20
+ifndef NS_USE_GCC
+OS_CFLAGS		+= +DAportable +DS1.1
+endif
 DEFAULT_IMPL_STRATEGY = _PTH
 endif
 
 #
 # On 10.30 and 11.00, we use the new ANSI C++ compiler aCC.
 #
 
 ifeq ($(OS_RELEASE),B.10.30)
 ifndef NS_USE_GCC
-CCC			= /opt/aCC/bin/aCC
+CCC			= /opt/aCC/bin/aCC -ext
 OS_CFLAGS		+= +DAportable +DS1.1
 endif
 OS_CFLAGS		+= -DHPUX10 -DHPUX10_30
 DEFAULT_IMPL_STRATEGY = _PTH
 endif
 
 # 11.00 is similar to 10.30.
 ifeq ($(OS_RELEASE),B.11.00)
-ifndef NS_USE_GCC
-CCC			= /opt/aCC/bin/aCC
-OS_CFLAGS		+= +DAportable +DS1.1
-endif
-OS_CFLAGS		+= -DHPUX10 -DHPUX11
+	ifndef NS_USE_GCC
+		CCC			        = /opt/aCC/bin/aCC -ext
+		ifeq ($(USE_64), 1)
+			OS_CFLAGS       += +DA2.0W +DChpux
+			COMPILER_TAG    = _64
+		else
+			OS_CFLAGS       += +DAportable +DS1.1
+			COMPILER_TAG    = _32
+		endif
+	endif
+OS_CFLAGS		+= -DHPUX10 -DHPUX11 -D_LARGEFILE64_SOURCE -D_PR_HAVE_OFF64_T
 DEFAULT_IMPL_STRATEGY = _PTH
 endif
 
-ifeq ($(DEFAULT_IMPL_STRATEGY),_CLASSIC)
+ifeq ($(DEFAULT_IMPL_STRATEGY),_EMU)
 CLASSIC_NSPR = 1
 endif
 
 ifeq ($(DEFAULT_IMPL_STRATEGY),_PTH)
 USE_PTHREADS = 1
+IMPL_STRATEGY = _PTH
 ifeq ($(CLASSIC_NSPR),1)
 USE_PTHREADS =
-IMPL_STRATEGY = _CLASSIC
+IMPL_STRATEGY = _EMU
 endif
 ifeq ($(PTHREADS_USER),1)
 USE_PTHREADS =
 IMPL_STRATEGY = _PTH_USER
 endif
 endif
 
-#
-# XXX
-# Temporary define for the Client; to be removed when binary release is used
-#
-ifdef MOZILLA_CLIENT
-IMPL_STRATEGY =
+ifeq ($(CLASSIC_NSPR),1)
+DEFINES			+= -D_PR_LOCAL_THREADS_ONLY
 endif
 
-ifeq ($(CLASSIC_NSPR),1)
-DEFINES			+= -D_PR_LOCAL_THREADS_ONLY
+ifeq (,$(filter-out A.09 B.10,$(basename $(OS_RELEASE))))
+DEFINES			+= -D_PR_NO_LARGE_FILES
 endif
 
 #
 # To use the true pthread (kernel thread) library on 10.30 and
 # 11.00, we should define _POSIX_C_SOURCE to be 199506L.
 # The _REENTRANT macro is deprecated.
 #
 
@@ -168,12 +183,8 @@ DSO_LDFLAGS		=
 # libraries.
 ifdef NS_USE_GCC
 DSO_CFLAGS		= -fPIC
 else
 DSO_CFLAGS		= +Z
 endif
 
 HAVE_PURIFY		= 1
-
-ifdef USE_AUTOCONF
-OS_CFLAGS		=
-endif
--- a/config/IRIX.mk
+++ b/config/IRIX.mk
@@ -17,101 +17,112 @@
 
 #
 # Config stuff for IRIX
 #
 
 include $(MOD_DEPTH)/config/UNIX.mk
 
 #
-# The default implementation strategy for Irix is classic nspr.
+# XXX
+# Temporary define for the Client; to be removed when binary release is used
+#
+ifdef MOZILLA_CLIENT
+ifneq ($(USE_PTHREADS),1)
+CLASSIC_NSPR = 1
+endif
+endif
+
 #
-ifeq ($(USE_PTHREADS),1)
-IMPL_STRATEGY = _PTH
+# The default implementation strategy for Irix is pthreads.
+# Classic nspr (user-level threads on top of sprocs) is also
+# available.
+#
+ifeq ($(CLASSIC_NSPR),1)
+	IMPL_STRATEGY = _MxN
+else
+	USE_PTHREADS = 1
+	USE_N32 = 1
+	IMPL_STRATEGY = _PTH
 endif
 
 ifdef NS_USE_GCC
-CC			= gcc
-COMPILER_TAG		= _gcc
-AS			= $(CC) -x assembler-with-cpp
-ODD_CFLAGS		= -Wall -Wno-format
-ifdef BUILD_OPT
-OPTIMIZER		= -O6
-endif
-else
-CC			= cc
-CCC         = CC
-ODD_CFLAGS		= -fullwarn -xansi
-ifdef BUILD_OPT
-
-ifeq ($(USE_N32),1)
-OPTIMIZER		= -O -OPT:Olimit=4000
+	CC			= gcc
+	COMPILER_TAG		= _gcc
+	AS			= $(CC) -x assembler-with-cpp -D_ASM -mips2
+	ODD_CFLAGS		= -Wall -Wno-format
+	ifdef BUILD_OPT
+		OPTIMIZER		= -O6
+	endif
 else
-OPTIMIZER		= -O -Olimit 4000
-endif
-
-endif
+	CC			= cc
+	CCC         = CC
+	ODD_CFLAGS		= -fullwarn -xansi
+	ifdef BUILD_OPT
+		ifneq ($(USE_N32),1)
+			OPTIMIZER		= -O -Olimit 4000
+		else
+			OPTIMIZER		= -O -OPT:Olimit=4000
+		endif
+	endif
 
-# For 6.x machines, include this flag
-ifeq ($(basename $(OS_RELEASE)),6)
-ifeq ($(USE_N32),1)
-ODD_CFLAGS		+= -n32 -exceptions -woff 1209,1642,3201
-COMPILER_TAG		= _n32
-else
-ODD_CFLAGS		+=  -32 -multigot
-endif
-else
-ODD_CFLAGS		+= -xgot
-endif
+#
+# The default behavior is still -o32 generation, hence the explicit tests
+# for -n32 and -64 and implicitly assuming -o32. If that changes, ...
+#
+	ifeq ($(basename $(OS_RELEASE)),6)
+		ODD_CFLAGS += -multigot
+		SHLIB_LD_OPTS = -no_unresolved
+		ifeq ($(USE_N32),1)
+			ODD_CFLAGS += -n32 -woff 1209
+			COMPILER_TAG = _n32
+			LDOPTS += -n32
+        	SHLIB_LD_OPTS += -n32
+			ifeq ($(OS_RELEASE), 6_2)
+				LDOPTS += -Wl,-woff,85
+				SHLIB_LD_OPTS += -woff 85
+			endif
+		else
+			ifeq ($(USE_64),1)
+				ODD_CFLAGS +=  -64
+				COMPILER_TAG = _64
+			else
+				ODD_CFLAGS +=  -32
+				COMPILER_TAG = _o32
+			endif
+		endif
+	else
+		ODD_CFLAGS += -xgot
+	endif
 endif
 
 ODD_CFLAGS		+= -DSVR4 -DIRIX
 
-
 CPU_ARCH		= mips
 
 RANLIB			= /bin/true
 
 # For purify
 # XXX: should always define _SGI_MP_SOURCE
 NOMD_OS_CFLAGS		= $(ODD_CFLAGS) -D_SGI_MP_SOURCE
 
 ifeq ($(OS_RELEASE),5.3)
 OS_CFLAGS               += -DIRIX5_3
 endif
 
-ifeq ($(OS_RELEASE),6.2)
-OS_CFLAGS               += -DIRIX6_2
-endif
-
-ifeq ($(OS_RELEASE),6.3)
-OS_CFLAGS               += -DIRIX6_3
-endif
-
 ifndef NO_MDUPDATE
 OS_CFLAGS		+= $(NOMD_OS_CFLAGS) -MDupdate $(DEPENDENCIES)
 else
 OS_CFLAGS		+= $(NOMD_OS_CFLAGS)
 endif
 
-# catch unresolved symbols
-ifeq ($(basename $(OS_RELEASE)),6)
-SHLIB_LD_OPTS = -no_unresolved
-ifeq ($(USE_N32),1)
-SHLIB_LD_OPTS		+= -n32
-else
-SHLIB_LD_OPTS		+= -32
-endif
-endif
-
+# -rdata_shared is an ld option that puts string constants and
+# const data into the text segment, where they will be shared
+# across processes and be read-only.
 MKSHLIB			= $(LD) $(SHLIB_LD_OPTS) -rdata_shared -shared -soname $(@:$(OBJDIR)/%.so=%.so)
 
 HAVE_PURIFY		= 1
 
 DSO_LDOPTS		= -elf -shared -all
 
 ifdef DSO_BACKEND
 DSO_LDOPTS		+= -soname $(DSO_NAME)
 endif
-
-ifdef USE_AUTOCONF
-OS_CFLAGS		=
-endif
--- a/config/Linux.mk
+++ b/config/Linux.mk
@@ -21,51 +21,59 @@
 
 ######################################################################
 # Version-independent
 ######################################################################
 
 include $(MOD_DEPTH)/config/UNIX.mk
 
 #
-# The default implementation strategy for Linux is classic nspr.
+# XXX
+# Temporary define for the Client; to be removed when binary release is used
+#
+ifdef MOZILLA_CLIENT
+ifneq ($(USE_PTHREADS),1)
+CLASSIC_NSPR = 1
+endif
+endif
+
 #
-ifeq ($(USE_PTHREADS),1)
-IMPL_STRATEGY = _PTH
+# The default implementation strategy for Linux is pthreads.
+#
+ifeq ($(CLASSIC_NSPR),1)
+IMPL_STRATEGY		= _EMU
+DEFINES			+= -D_PR_LOCAL_THREADS_ONLY
+else
+USE_PTHREADS		= 1
+IMPL_STRATEGY		= _PTH
 DEFINES			+= -D_REENTRANT
-else
-DEFINES			+= -D_PR_LOCAL_THREADS_ONLY
 endif
 
 ifeq (86,$(findstring 86,$(OS_TEST)))
 CPU_ARCH		:= x86
 else
 ifeq (,$(filter-out sa110,$(OS_TEST)))
 CPU_ARCH		:= arm
 else
 CPU_ARCH		:= $(OS_TEST)
 endif
+endif
 CPU_ARCH_TAG		= _$(CPU_ARCH)
-endif
 
 CC			= gcc
 CCC			= g++
 RANLIB			= ranlib
 
 OS_INCLUDES		=
 G++INCLUDES		= -I/usr/include/g++
 
 PLATFORM_FLAGS		= -ansi -Wall -pipe -DLINUX -Dlinux
 PORT_FLAGS		= -D_POSIX_SOURCE -D_BSD_SOURCE -DHAVE_STRERROR
 
-ifdef USE_AUTOCONF
-OS_CFLAGS		= $(DSO_CFLAGS) #-include $(MOD_DEPTH)/include/config.h
-else
 OS_CFLAGS		= $(DSO_CFLAGS) $(PLATFORM_FLAGS) $(PORT_FLAGS)
-endif
 
 ######################################################################
 # Version-specific stuff
 ######################################################################
 
 ifeq ($(CPU_ARCH),alpha)
 PLATFORM_FLAGS		+= -D_ALPHA_ -D__alpha -mieee
 PORT_FLAGS		+= -D_XOPEN_SOURCE
--- a/config/Makefile
+++ b/config/Makefile
@@ -16,25 +16,63 @@
 # Copyright (C) 1998 Netscape Communications Corporation.  All Rights
 # Reserved.
 #
 
 MOD_DEPTH	= ..
 
 include $(MOD_DEPTH)/config/config.mk
 
-CSRCS	= nsinstall.c pathsub.c
+CSRCS	= nsinstall.c now.c
 
 PLSRCS	= nfspwd.pl
 
-ifneq ($(OS_ARCH),WINNT)
-PROGRAM	= $(OBJDIR)/nsinstall
-TARGETS = $(PROGRAM) $(PLSRCS:.pl=)
+ifeq ($(OS_ARCH), WINNT)
+PROG_SUFFIX = .exe
+else
+PROG_SUFFIX =
+endif
+
+ifeq ($(OS_ARCH), IRIX)
+    ifeq ($(basename $(OS_RELEASE)),6)
+	    ifeq ($(USE_N32),1)
+		    XLDOPTS += -n32 -Wl,-woff,85
+		    ifeq ($(OS_RELEASE), 6_2)
+			    XLDOPTS += -Wl,-woff,85
+		    endif
+	    else
+		    ifeq ($(USE_64),1)
+			    XLDOPTS += -64
+		    else
+			    XLDOPTS += -32
+		    endif
+	    endif
+    endif
+endif
+
+ifeq ($(OS_ARCH), HP-UX)
+    ifeq ($(USE_64),1)
+        XLDOPTS += +DD64
+    endif
 endif
 
 include $(MOD_DEPTH)/config/rules.mk
 
+PROGS	= $(OBJDIR)/now$(PROG_SUFFIX)
+
+ifeq ($(OS_ARCH),WINNT)
+TARGETS = $(PROGS)
+else
+PROGS	+= $(OBJDIR)/nsinstall$(PROG_SUFFIX)
+TARGETS = $(PROGS) $(PLSRCS:.pl=)
+endif
+
 # Redefine MAKE_OBJDIR for just this directory
 define MAKE_OBJDIR
 if test ! -d $(@D); then rm -rf $(@D); mkdir $(@D); fi
 endef
 
 export:: $(TARGETS)
+
+$(OBJDIR)/%$(PROG_SUFFIX): $(OBJDIR)/%.$(OBJ_SUFFIX)
+	@$(MAKE_OBJDIR)
+	$(CC) $(XCFLAGS) $< $(XLDOPTS) -o $@
+
--- a/config/NCR.mk
+++ b/config/NCR.mk
@@ -26,19 +26,17 @@ NS_USE_NATIVE = 1
 # NS_USE_GCC = 1
 
 export PATH:=$(PATH):/opt/ncc/bin
 ###
 
 RANLIB          = true
 GCC_FLAGS_EXTRA = -pipe
 
-ifndef USE_AUTOCONF
 DEFINES		+= -DSVR4 -DSYSV -DHAVE_STRERROR -DNCR -D_PR_LOCAL_THREADS_ONLY
-endif
 
 ifdef NS_USE_NATIVE
 CC              = cc
 CCC             = ncc
 OS_CFLAGS	= -Hnocopyr
 #OS_LIBS         = -L/opt/ncc/lib 
 else
 #OS_LIBS		=
--- a/config/NEC.mk
+++ b/config/NEC.mk
@@ -31,19 +31,15 @@ CC			= $(NSDEPTH)/build/hcc -Xa -KGnum=0
 CCC			= g++
 endif
 
 MKSHLIB			= $(LD) $(DSO_LDOPTS)
 
 RANLIB			= /bin/true
 
 DEFINES			+= -D_PR_LOCAL_THREADS_ONLY
-ifdef USE_AUTOCONF
-OS_CFLAGS		=
-else
 OS_CFLAGS		= $(ODD_CFLAGS) -DSVR4 -D__SVR4 -DNEC -Dnec_ews -DHAVE_STRERROR
-endif
 OS_LIBS			= -lsocket -lnsl -ldl $(LDOPTIONS)
 LDOPTIONS		= -lc -L/usr/ucblib -lucb
 
 NOSUCHFILE		= /no-such-file
 
 DSO_LDOPTS		= -G
--- a/config/NEWS-OS.mk
+++ b/config/NEWS-OS.mk
@@ -34,21 +34,17 @@ RANLIB			= /bin/true
 
 OS_INCLUDES		= -I/usr/include
 G++INCLUDES		=
 #OS_LIBS			= -lsocket -lnsl -lgen -lresolv
 
 PLATFORM_FLAGS		= -Xa -fullwarn -DSONY
 PORT_FLAGS		= -DSYSV -DSVR4 -D__svr4 -D__svr4__ -D_PR_LOCAL_THREADS_ONLY -DHAVE_SVID_GETTOD
 
-ifdef USE_AUTOCONF
-OS_CFLAGS		=
-else
 OS_CFLAGS		= $(PLATFORM_FLAGS) $(PORT_FLAGS)
-endif
 
 ######################################################################
 # Version-specific stuff
 ######################################################################
 
 ######################################################################
 # Overrides for defaults in config.mk (or wherever)
 ######################################################################
--- a/config/NetBSD.mk
+++ b/config/NetBSD.mk
@@ -27,21 +27,17 @@ RANLIB			= ranlib
 
 OS_REL_CFLAGS		=
 ifeq (86,$(findstring 86,$(OS_TEST)))
 CPU_ARCH		= x86
 else
 CPU_ARCH		= $(OS_TEST)
 endif
 
-ifdef USE_AUTOCONF
-OS_CFLAGS		= $(DSO_CFLAGS)
-else
 OS_CFLAGS		= $(DSO_CFLAGS) $(OS_REL_CFLAGS) -ansi -Wall -pipe -DNETBSD -DHAVE_STRERROR -DHAVE_BSD_FLOCK
-endif
 
 ifeq ($(USE_PTHREADS),1)
 OS_LIBS			= -lc_r
 # XXX probably should define _THREAD_SAFE too.
 else
 OS_LIBS			= -lc
 DEFINES			+= -D_PR_LOCAL_THREADS_ONLY
 endif
--- a/config/OSF1.mk
+++ b/config/OSF1.mk
@@ -41,59 +41,48 @@ endif
 #
 # On OSF1 V3.2, classic nspr is the default (and only) implementation
 # strategy.
 #
 # On OSF1 V4.0, pthreads is the default implementation strategy.
 # Classic nspr is also available.
 #
 ifneq ($(OS_RELEASE),V3.2)
-USE_PTHREADS = 1
 ifeq ($(CLASSIC_NSPR), 1)
-	USE_PTHREADS =
-	IMPL_STRATEGY := _CLASSIC
+	IMPL_STRATEGY = _EMU
 	DEFINES += -D_PR_LOCAL_THREADS_ONLY
-endif
+else
+	USE_PTHREADS = 1
+	IMPL_STRATEGY = _PTH
 endif
-
-#
-# XXX
-# Temporary define for the Client; to be removed when binary release is used
-#
-ifdef MOZILLA_CLIENT
-IMPL_STRATEGY =
 endif
 
 CC			= cc $(NON_LD_FLAGS) -std1 -readonly_strings
 # The C++ compiler cxx has -readonly_strings on by default.
 CCC			= cxx
 
 RANLIB			= /bin/true
 
 CPU_ARCH		= alpha
 
 ifdef BUILD_OPT
 OPTIMIZER		+= -Olimit 4000
 endif
 
 NON_LD_FLAGS		= -ieee_with_inexact
 
-ifdef USE_AUTOCONF
-OS_CFLAGS		=
-else
-OS_CFLAGS		= -DOSF1 -D_REENTRANT -taso
+OS_CFLAGS		= -DOSF1 -D_REENTRANT
 
 ifeq ($(OS_RELEASE),V3.2)
-OS_CFLAGS		+= -DOSF1V3
+OS_CFLAGS		+= -DHAVE_INT_LOCALTIME_R
 endif
 
 ifeq (V4,$(findstring V4,$(OS_RELEASE)))
-OS_CFLAGS		+= -DOSF1V4
+OS_CFLAGS		+= -DHAVE_POINTER_LOCALTIME_R
 endif
-endif # USE_AUTOCONF
 
 ifeq ($(USE_PTHREADS),1)
 OS_CFLAGS		+= -pthread
 endif
 
 # The command to build a shared library on OSF1.
 MKSHLIB = ld -shared -all -expect_unresolved "*"
 DSO_LDOPTS		= -shared
new file mode 100644
--- /dev/null
+++ b/config/OpenBSD.mk
@@ -0,0 +1,63 @@
+#
+# The contents of this file are subject to the Netscape Public License
+# Version 1.0 (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.
+#
+
+#
+# Config stuff for OpenBSD
+#
+
+include $(MOD_DEPTH)/config/UNIX.mk
+
+CC                     = gcc
+CCC                    = g++
+RANLIB                 = ranlib
+
+OS_REL_CFLAGS          =
+ifeq (86,$(findstring 86,$(OS_TEST)))
+CPU_ARCH               = x86
+else
+CPU_ARCH               = $(OS_TEST)
+endif
+
+OS_CFLAGS              = $(DSO_CFLAGS) $(OS_REL_CFLAGS) -ansi -Wall -pipe -DOPENBSD
+DHAVE_STRERROR -DHAVE_BSD_FLOCK
+
+ifeq ($(USE_PTHREADS),1)
+OS_LIBS                        = -lc_r
+# XXX probably should define _THREAD_SAFE too.
+else
+OS_LIBS                        = -lc
+DEFINES                        += -D_PR_LOCAL_THREADS_ONLY
+endif
+
+ARCH                   = openbsd
+
+DSO_CFLAGS             = -fPIC
+DSO_LDFLAGS            =
+DSO_LDOPTS             = -Bshareable
+ifeq ($(OS_TEST),alpha)
+DSO_LDOPTS             = -shared
+endif
+ifeq ($(OS_TEST),mips)
+DSO_LDOPTS             = -shared
+endif
+ifeq ($(OS_TEST),pmax)  
+DSO_LDOPTS             = -shared
+endif
+
+MKSHLIB                        = $(LD) $(DSO_LDOPTS)
+
+G++INCLUDES            = -I/usr/include/g++
--- a/config/Rhapsody.mk
+++ b/config/Rhapsody.mk
@@ -16,49 +16,47 @@
 #
 
 #
 # Config stuff for Rhapsody
 #
 
 include $(MOD_DEPTH)/config/UNIX.mk
 
-CC			= cc
+CC              = cc
 ifeq ($(OS_RELEASE),5.0)
-CCC			= cc++
+CCC             = cc++
 else
-CCC			= c++
+CCC             = c++
 endif
 RANLIB			= ranlib
 
-OS_REL_CFLAGS		= -Dppc
+ifeq (86,$(findstring 86,$(OS_TEST)))
+OS_REL_CFLAGS   = -mno-486 -Di386
+CPU_ARCH        = i386
+else
+OS_REL_CFLAGS   = -Dppc
 CPU_ARCH		= ppc
-
-#OS_REL_CFLAGS		= -mno-486 -Di386
-#CPU_ARCH		= x86
+endif
 
 # "Commons" are tentative definitions in a global scope, like this:
 #     int x;
 # The meaning of a common is ambiguous.  It may be a true definition:
 #     int x = 0;
 # or it may be a declaration of a symbol defined in another file:
 #     extern int x;
 # Use the -fno-common option to force all commons to become true
 # definitions so that the linker can catch multiply-defined symbols.
 # Also, common symbols are not allowed with Rhapsody dynamic libraries.
 
-ifdef USE_AUTOCONF
-OS_CFLAGS		= $(DSO_CFLAGS)
-else
 OS_CFLAGS		= $(DSO_CFLAGS) $(OS_REL_CFLAGS) -Wmost -fno-common -pipe -DRHAPSODY -DHAVE_STRERROR -DHAVE_BSD_FLOCK
-endif
 
-DEFINES			+= -D_PR_LOCAL_THREADS_ONLY -D_PR_NEED_FAKE_POLL
+DEFINES			+= -D_PR_LOCAL_THREADS_ONLY
 
 ARCH			= rhapsody
 
 # May override this with -bundle to create a loadable module.
-DSO_LDOPTS		= -dynamiclib
+DSO_LDOPTS		= -dynamiclib -compatibility_version 1 -current_version 1 -all_load
 
 MKSHLIB			= $(CC) -arch $(CPU_ARCH) $(DSO_LDOPTS)
 DLL_SUFFIX		= dylib
 
-#G++INCLUDES		= -I/usr/include/g++
+G++INCLUDES		= -I/usr/include/g++
--- a/config/SCOOS.mk
+++ b/config/SCOOS.mk
@@ -28,22 +28,17 @@ CCC			= g++ -b elf -I/usr/local/lib/g++-
 # CCC			= $(DEPTH)/build/hcpp +.cpp +w
 RANLIB			= /bin/true
 
 DEFINES			+= -D_PR_LOCAL_THREADS_ONLY
 #
 # -DSCO - Changes to Netscape source (consistent with AIX, LINUX, etc..)
 # -Dsco - Needed for /usr/include/X11/*
 #
-ifdef USE_AUTOCONF
-OS_CFLAGS
-else
 OS_CFLAGS		= -DSYSV -D_SVID3 -DHAVE_STRERROR -D_PR_NEED_H_ERRNO -DSCO -Dsco
-endif
-
 #OS_LIBS			= -lpmapi -lsocket -lc
 
 MKSHLIB			= $(LD) $(DSO_LDOPTS)
 
 XINC			= /usr/include/X11
 MOTIFLIB		= -lXm
 INCLUDES		+= -I$(XINC)
 
--- a/config/SINIX.mk
+++ b/config/SINIX.mk
@@ -65,19 +65,15 @@ endif
 CPU_ARCH		= mips
 
 RANLIB			= /bin/true
 
 # For purify
 NOMD_OS_CFLAGS		= $(ODD_CFLAGS)
 
 # we do not have -MDupdate ...
-ifdef USE_AUTOCONF
-OS_CFLAGS		= 
-else
 OS_CFLAGS		= $(NOMD_OS_CFLAGS)
-endif
 OS_LIBS			= -lsocket -lnsl -lresolv -ldl -lc
 NOSUCHFILE		= /no-such-file
 
 HAVE_PURIFY		= 0
 
 DEFINES			+= -D_PR_LOCAL_THREADS_ONLY
--- a/config/SunOS.mk
+++ b/config/SunOS.mk
@@ -15,12 +15,12 @@
 # Reserved.
 #
 
 #
 # Config stuff for SunOS.
 # 4 and 5 are vastly different, so we use 2 different files.
 #
 ifeq ($(basename $(OS_RELEASE)),4.1)
-include $(topsrcdir)/config/SunOS4.mk
+include $(MOD_DEPTH)/config/SunOS4.mk
 else
-include $(topsrcdir)/config/SunOS5.mk
+include $(MOD_DEPTH)/config/SunOS5.mk
 endif
--- a/config/SunOS4.mk
+++ b/config/SunOS4.mk
@@ -21,30 +21,27 @@
 
 include $(MOD_DEPTH)/config/UNIX.mk
 
 # SunOS 4 _requires_ that shared libs have a version number.
 # XXX FIXME: Version number should use NSPR_VERSION_NUMBER?
 DLL_SUFFIX	= so.1.0
 
 CC			= gcc
+CCC			= g++
 COMPILER_TAG		= _gcc
 
 RANLIB			= ranlib
 
 CPU_ARCH		= sparc
 
 DEFINES			+= -D_PR_LOCAL_THREADS_ONLY
 # Purify doesn't like -MDupdate
 NOMD_OS_CFLAGS		= -Wall -Wno-format -DSUNOS4
-ifdef USE_AUTOCONF
-OS_CFLAGS		= $(DSO_CFLAGS)
-else
 OS_CFLAGS		= $(DSO_CFLAGS) $(NOMD_OS_CFLAGS) -MDupdate $(DEPENDENCIES)
-endif
 
 MKSHLIB			= $(LD) $(DSO_LDOPTS)
 
 HAVE_PURIFY		= 1
 
 NOSUCHFILE		= /no-such-file
 
 DSO_LDOPTS		=
--- a/config/SunOS5.mk
+++ b/config/SunOS5.mk
@@ -21,58 +21,46 @@
 
 include $(MOD_DEPTH)/config/UNIX.mk
 
 #
 # XXX
 # Temporary define for the Client; to be removed when binary release is used
 #
 ifdef MOZILLA_CLIENT
+ifneq ($(USE_PTHREADS),1)
 LOCAL_THREADS_ONLY = 1
+endif
 ifndef NS_USE_NATIVE
 NS_USE_GCC = 1
 endif
 endif
 
 #
-# The default implementation strategy on Solaris is global threads only.
-# Local threads only and pthreads are also available.
+# The default implementation strategy on Solaris is pthreads.
+# Global threads only and local threads only are also available.
 #
-ifeq ($(USE_PTHREADS),1)
-  IMPL_STRATEGY = _PTH
+ifeq ($(GLOBAL_THREADS_ONLY),1)
+  IMPL_STRATEGY = _NATIVE
+  DEFINES += -D_PR_GLOBAL_THREADS_ONLY
 else
   ifeq ($(LOCAL_THREADS_ONLY),1)
-    IMPL_STRATEGY = _LOCAL
+    IMPL_STRATEGY = _EMU
     DEFINES += -D_PR_LOCAL_THREADS_ONLY
   else
-    DEFINES += -D_PR_GLOBAL_THREADS_ONLY
+    USE_PTHREADS = 1
+    IMPL_STRATEGY = _PTH
   endif
 endif
 
-#
-# XXX
-# Temporary define for the Client; to be removed when binary release is used
-#
-ifdef MOZILLA_CLIENT
-IMPL_STRATEGY =
-endif
-
 ifdef NS_USE_GCC
 CC			= gcc -Wall
 CCC			= g++ -Wall
-#
-# XXX
-# Temporary define for the Client; to be removed when binary release is used
-#
-ifdef MOZILLA_CLIENT
-#COMPILER_TAG		= _gcc
-else
 COMPILER_TAG		= _gcc
-endif
-#ASFLAGS			+= -x assembler-with-cpp
+ASFLAGS			+= -x assembler-with-cpp
 ifdef NO_MDUPDATE
 OS_CFLAGS		= $(NOMD_OS_CFLAGS)
 else
 OS_CFLAGS		= $(NOMD_OS_CFLAGS) -MDupdate $(DEPENDENCIES)
 endif
 else
 CC			= cc -xstrconst
 CCC			= CC -Qoption cg -xstrconst
@@ -92,45 +80,43 @@ endif
 endif
 
 RANLIB			= echo
 
 OS_DEFINES		= -DSVR4 -DSYSV -D__svr4 -D__svr4__ -DSOLARIS
 
 ifeq ($(OS_TEST),i86pc)
 CPU_ARCH		= x86
-CPU_ARCH_TAG		= _i86pc
 OS_DEFINES		+= -Di386
 # The default debug format, DWARF (-g), is not supported by gcc
 # on i386-ANY-sysv4/solaris, but the stabs format is.  It is
 # assumed that the Solaris assembler /usr/ccs/bin/as is used.
 # If your gcc uses GNU as, you do not need the -Wa,-s option.
 ifndef BUILD_OPT
 ifdef NS_USE_GCC
 OPTIMIZER		= -Wa,-s -gstabs
 endif
 endif
 else
 CPU_ARCH		= sparc
 endif
+CPU_ARCH_TAG		= _$(CPU_ARCH)
 
 ifeq (5.5,$(findstring 5.5,$(OS_RELEASE)))
 OS_DEFINES		+= -DSOLARIS2_5
+else
+OS_DEFINES		+= -D_PR_HAVE_OFF64_T
 endif
 
 ifneq ($(LOCAL_THREADS_ONLY),1)
-OS_DEFINES		+= -D_REENTRANT
+OS_DEFINES		+= -D_REENTRANT -DHAVE_POINTER_LOCALTIME_R
 endif
 
 # Purify doesn't like -MDupdate
-ifdef USE_AUTOCONF
-NOMD_OS_CFLAGS		= $(DSO_CFLAGS) #-DSOLARIS
-else
 NOMD_OS_CFLAGS		= $(DSO_CFLAGS) $(OS_DEFINES) $(SOL_CFLAGS)
-endif
 
 MKSHLIB			= $(LD) $(DSO_LDOPTS)
 
 # ld options:
 # -G: produce a shared object
 # -z defs: no unresolved symbols allowed
 DSO_LDOPTS		= -G
 
--- a/config/UNIX.mk
+++ b/config/UNIX.mk
@@ -10,36 +10,39 @@
 # 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.
 #
 
+PR_UNIXOS	= 1
 XP_DEFINE	= -DXP_UNIX
 OBJ_SUFFIX	= o
 LIB_SUFFIX	= a
 DLL_SUFFIX	= so
 AR		= ar cr $@
 
-ifndef USE_AUTOCONF
 ifdef BUILD_OPT
 OPTIMIZER	= -O
 DEFINES		= -UDEBUG -DNDEBUG
 OBJDIR_TAG	= _OPT
 else
 OPTIMIZER	= -g
 DEFINES		= -DDEBUG -UNDEBUG -DDEBUG_$(shell whoami)
 OBJDIR_TAG	= _DBG
 endif
 
 # Name of the binary code directories
+ifdef MOZILLA_CLIENT
+OBJDIR_NAME	= $(OS_CONFIG)$(CPU_ARCH_TAG)$(OBJDIR_TAG).OBJ
+else
 OBJDIR_NAME	= $(OS_CONFIG)$(CPU_ARCH_TAG)$(COMPILER_TAG)$(IMPL_STRATEGY)$(OBJDIR_TAG).OBJ
-endif # !USE_AUTOCONF
+endif
 
 MKDEPEND_DIR    = $(DEPTH)/config/mkdepend
 MKDEPEND 	= $(MKDEPEND_DIR)/$(OBJDIR_NAME)/mkdepend
 MKDEPENDENCIES  = $(OBJDIR)/depend.mk
 
 ####################################################################
 #
 # One can define the makefile variable NSDISTMODE to control
--- a/config/UNIXWARE.mk
+++ b/config/UNIXWARE.mk
@@ -28,21 +28,17 @@
 include $(MOD_DEPTH)/config/UNIX.mk
 
 CC		= $(NSDEPTH)/build/hcc
 CCC		= $(NSDEPTH)/build/hcpp
 
 RANLIB		= true
 
 DEFINES		+= -D_PR_LOCAL_THREADS_ONLY
-ifdef USE_AUTOCONF
-OS_CFLAGS	=
-else
 OS_CFLAGS	= -DSVR4 -DSYSV -DUNIXWARE
-endif
 
 MKSHLIB		= $(LD) $(DSO_LDOPTS)
 DSO_LDOPTS	= -G
 
 CPU_ARCH	= x86
 ARCH		= sco
 
 NOSUCHFILE	= /no-such-file
--- a/config/WIN32.mk
+++ b/config/WIN32.mk
@@ -24,32 +24,16 @@
 # Client build: make sure we use the shmsdos.exe under $(MOZ_TOOLS).
 # $(MOZ_TOOLS_FLIPPED) is $(MOZ_TOOLS) with all the backslashes
 # flipped, so that gmake won't interpret them as escape characters.
 #
 ifdef PR_CLIENT_BUILD_WINDOWS
 SHELL = $(MOZ_TOOLS_FLIPPED)/bin/shmsdos.exe
 endif
 
-#
-# On NT, we use static thread local storage by default because it
-# gives us better performance.  However, we can't use static TLS
-# on Alpha NT because the Alpha version of MSVC does not seem to
-# support the -GT flag, which is necessary to make static TLS safe
-# for fibers.
-#
-# On Win95, we use the TlsXXX() functions by default because that
-# allows us to load the NSPR DLL at run time using LoadLibrary().
-#
-ifeq ($(OS_TARGET),WINNT)
-ifneq ($(CPU_ARCH),ALPHA)
-USE_STATIC_TLS = 1
-endif
-endif
-
 CC = cl
 CCC = cl
 LINK = link
 AR = lib -NOLOGO -OUT:"$@"
 RANLIB = echo
 BSDECHO = echo
 NSINSTALL = nsinstall
 INSTALL	= $(NSINSTALL)
@@ -62,74 +46,82 @@ GARBAGE = $(OBJDIR)/vc20.pdb $(OBJDIR)/v
 
 XP_DEFINE = -DXP_PC
 OBJ_SUFFIX = obj
 LIB_SUFFIX = lib
 DLL_SUFFIX = dll
 
 OS_CFLAGS = -W3 -nologo -GF -Gy
 
+ifdef MOZ_PROF
+
+#
+# compile with debug symbols, but without DEBUG code and ASSERTs
+#
+ifdef USE_DEBUG_RTL
+OS_CFLAGS += -MDd
+else
+OS_CFLAGS += -MD
+endif
+OPTIMIZER = -Od -Z7
+#OPTIMIZER = -Zi -Fd$(OBJDIR)/ -Od
+DEFINES = -UDEBUG -U_DEBUG -DNDEBUG
+DLLFLAGS = -DEBUG -DEBUGTYPE:CV -OUT:"$@"
+OBJDIR_TAG = _DBG
+LDFLAGS = -DEBUG -DEBUGTYPE:CV
+
+else
+
 ifdef BUILD_OPT
 OS_CFLAGS += -MD
 OPTIMIZER = -O2
 DEFINES = -UDEBUG -U_DEBUG -DNDEBUG
 DLLFLAGS = -OUT:"$@"
 OBJDIR_TAG = _OPT
-
-# Add symbolic information for use by a profiler
-ifdef MOZ_PROF
-OPTIMIZER += -Z7
-DLLFLAGS += -DEBUG -DEBUGTYPE:CV
-LDFLAGS += -DEBUG -DEBUGTYPE:CV
-endif
-
 else
 #
 # Define USE_DEBUG_RTL if you want to use the debug runtime library
 # (RTL) in the debug build
 #
 ifdef USE_DEBUG_RTL
 OS_CFLAGS += -MDd
 else
 OS_CFLAGS += -MD
 endif
 OPTIMIZER = -Od -Z7
 #OPTIMIZER = -Zi -Fd$(OBJDIR)/ -Od
 DEFINES = -DDEBUG -D_DEBUG -UNDEBUG
-
 DLLFLAGS = -DEBUG -DEBUGTYPE:CV -OUT:"$@"
-ifeq ($(MOZ_BITS),32)
-ifdef GLOWCODE
-ifdef MOZ_DEBUG
-DLLFLAGS = -DEBUG -DEBUGTYPE:both -INCLUDE:_GlowCode -OUT:"$@"
-endif
+OBJDIR_TAG = _DBG
+LDFLAGS = -DEBUG -DEBUGTYPE:CV
 endif
 endif
 
-OBJDIR_TAG = _DBG
-LDFLAGS = -DEBUG -DEBUGTYPE:CV
-endif
+DEFINES += -DWIN32
 
-DEFINES += -DWIN32
+#
+# On Win95, we use the TlsXXX() interface by default because that
+# allows us to load the NSPR DLL dynamically at run time.
+# If you want to use static thread-local storage (TLS) for better
+# performance, build the NSPR library with USE_STATIC_TLS=1.
+#
 ifeq ($(USE_STATIC_TLS),1)
 DEFINES += -D_PR_USE_STATIC_TLS
 endif
 
 #
-# NSPR uses fibers on NT.  Therefore, if we use static local
-# storage (i.e., __declspec(thread) variables), we need the -GT
+# NSPR uses both fibers and static thread-local storage
+# (i.e., __declspec(thread) variables) on NT.  We need the -GT
 # flag to turn off certain compiler optimizations so that fibers
 # can use static TLS safely.
 #
 # Also, we optimize for Pentium (-G5) on NT.
 #
 ifeq ($(OS_TARGET),WINNT)
-ifeq ($(USE_STATIC_TLS),1)
 OS_CFLAGS += -GT
-endif
 ifeq ($(CPU_ARCH),x86)
 OS_CFLAGS += -G5
 endif
 DEFINES += -DWINNT
 else
 DEFINES += -DWIN95 -D_PR_GLOBAL_THREADS_ONLY
 endif
 
--- a/config/config.mk
+++ b/config/config.mk
@@ -11,28 +11,24 @@
 # 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.
 #
 
-ifndef topsrcdir
-topsrcdir = $(MOD_DEPTH)
-endif
-
 # Configuration information for building in the NSPR source module
 
 # Define an include-at-most-once-flag
 NSPR_CONFIG_MK	= 1
 
-include $(topsrcdir)/config/module.df
+include $(MOD_DEPTH)/config/module.df
 
-include $(topsrcdir)/config/arch.mk
+include $(MOD_DEPTH)/config/arch.mk
 
 ifndef NSDEPTH
 NSDEPTH = $(MOD_DEPTH)/..
 endif
 
 #
 # Default command macros; can be overridden in <arch>.mk.
 #
@@ -41,61 +37,37 @@ AS		= $(CC)
 ASFLAGS		= $(CFLAGS)
 PURIFY		= purify $(PURIFYOPTIONS)
 LINK_DLL	= $(LINK) $(OS_DLLFLAGS) $(DLLFLAGS)
 NFSPWD		= $(MOD_DEPTH)/config/nfspwd
 
 LIBNSPR		= $(DIST)/lib/libnspr.$(LIB_SUFFIX)
 PURELIBNSPR	= $(DIST)/lib/libpurenspr.$(LIB_SUFFIX)
 
-CFLAGS		= $(OPTIMIZER) $(OS_CFLAGS) $(XP_DEFINE) $(DEFINES) $(INCLUDES) \
-				$(XCFLAGS)
+CFLAGS		= $(CC_ONLY_FLAGS) $(OPTIMIZER) $(OS_CFLAGS)\
+		  $(XP_DEFINE) $(DEFINES) $(INCLUDES) $(XCFLAGS)
+CCCFLAGS	= $(CCC_ONLY_FLAGS) $(OPTIMIZER) $(OS_CFLAGS)\
+		  $(XP_DEFINE) $(DEFINES) $(INCLUDES) $(XCFLAGS)
 # For purify
-NOMD_CFLAGS	= $(OPTIMIZER) $(NOMD_OS_CFLAGS) $(XP_DEFINE) $(DEFINES) $(INCLUDES) \
-				$(XCFLAGS)
-
-ifdef USE_AUTOCONF
-OPTIMIZER	= $(ACCFLAGS)
-DEFINES		+=  -UDEBUG -DNDEBUG -DTRIMMED
-endif
+NOMD_CFLAGS	= $(CC_ONLY_FLAGS) $(OPTIMIZER) $(NOMD_OS_CFLAGS)\
+		  $(XP_DEFINE) $(DEFINES) $(INCLUDES) $(XCFLAGS)
 
-ifdef MOZ_DEBUG
-ifdef USE_AUTOCONF
-OPTIMIZER	= $(ACCFLAGS)
-else
-OPTIMIZER	= -g
-endif
-JAVA_OPTIMIZER	= -g
-DEFINES		= -DDEBUG -UNDEBUG -DDEBUG_$(shell $(WHOAMI)) -DTRACING
-XBCFLAGS	= -FR$*
-endif
-
-include $(topsrcdir)/config/$(OS_TARGET).mk
+include $(MOD_DEPTH)/config/$(OS_TARGET).mk
 
 # Figure out where the binary code lives.
 BUILD		= $(OBJDIR_NAME)
 OBJDIR		= $(OBJDIR_NAME)
 DIST		= $(NSDEPTH)/dist/$(OBJDIR_NAME)
 ifeq ($(MOZ_BITS),16)
 MOZ_INCL	= $(NSDEPTH)/dist/public/win16
 MOZ_DIST	= $(NSDEPTH)/dist/WIN16D_D.OBJ
 endif
 
-ifdef USE_AUTOCONF
-EMACS			= $(ACEMACS)
-PERL			= $(ACPERL)
-RANLIB			= $(ACRANLIB)
-UNZIP_PROG		= $(ACUNZIP)
-WHOAMI			= $(ACWHOAMI)
-ZIP_PROG		= $(ACZIP)
-DEPENDENCIES	= .md
-else
 VPATH		= $(OBJDIR)
 DEPENDENCIES	= $(OBJDIR)/.md
-endif
 
 ifdef BUILD_DEBUG_GC
 DEFINES		+= -DDEBUG_GC
 endif
 
 GARBAGE		+= $(DEPENDENCIES) core $(wildcard core.[0-9]*)
 
 ####################################################################
new file mode 100644
--- /dev/null
+++ b/config/now.c
@@ -0,0 +1,57 @@
+/* -*- 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.0 (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 <stdio.h>
+#include <stdlib.h>
+
+#if defined(XP_UNIX)
+#include <sys/time.h>
+#elif defined(WIN32)
+#include <sys/timeb.h>
+#else
+#error "Architecture not supported"
+#endif
+
+
+int main(int argc, char **argv)
+{
+#if defined(XP_UNIX)
+   long long now;
+   struct timeval tv;
+    gettimeofday(&tv, NULL);
+    now = ((1000000LL) * tv.tv_sec) + (long long)tv.tv_usec;
+#if defined(OSF1)
+    return fprintf(stdout, "%ld", now);
+#else
+    return fprintf(stdout, "%lld", now);
+#endif
+
+#elif defined(WIN32)
+    __int64 now;
+    struct timeb b;
+    ftime(&b);
+    now = b.time;
+    now *= 1000000;
+    now += (1000 * b.millitm);
+    return fprintf(stdout, "%I64d", now);
+#else
+#error "Architecture not supported"
+#endif
+}  /* main */
+
+/* now.c */
--- a/config/nsinstall.c
+++ b/config/nsinstall.c
@@ -19,43 +19,48 @@
 /*
 ** Netscape portable install command.
 **
 ** Brendan Eich, 7/20/95
 */
 #include <stdio.h>  /* OSF/1 requires this before grp.h, so put it first */
 #include <assert.h>
 #include <fcntl.h>
-#include <errno.h>
 #include <grp.h>
 #include <pwd.h>
-#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
 #include <utime.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <dirent.h>
+#include <errno.h>
+#include <stdarg.h>
+#ifdef USE_REENTRANT_LIBC
+#include "libc_r.h"
+#endif /* USE_REENTRANT_LIBC */
+
 #include "pathsub.h"
 
 #define HAVE_LCHOWN
 
-#if defined(AIX) || defined(BSDI) || defined(HPUX) || defined(linux) || defined(SUNOS4) || defined(SCO) || defined(UNIXWARE) || defined(RHAPSODY)
+#if defined(AIX) || defined(BSDI) || defined(HPUX) || defined(LINUX) || defined(SUNOS4) || defined(SCO) || defined(UNIXWARE) || defined(RHAPSODY)
 #undef HAVE_LCHOWN
 #endif
 
 /*
  * Does getcwd() take NULL as the first argument and malloc
  * the result buffer?
  */
 #if !defined(RHAPSODY)
 #define GETCWD_CAN_MALLOC
 #endif
 
-#ifdef linux
+#ifdef LINUX
 #include <getopt.h>
 #endif
 
 #if defined(SCO) || defined(UNIXWARE) || defined(SNI) || defined(NCR) || defined(NEC)
 #if !defined(S_ISLNK) && defined(S_IFLNK)
 #define S_ISLNK(a)	(((a) & S_IFMT) == S_IFLNK)
 #endif
 #endif
@@ -65,44 +70,39 @@ extern int fchmod(int fildes, mode_t mod
 #endif
 
 static void
 usage(void)
 {
     fprintf(stderr,
 	"usage: %s [-C cwd] [-L linkprefix] [-m mode] [-o owner] [-g group]\n"
 	"       %*s [-DdltR] file [file ...] directory\n",
-	program, strlen(program), "");
+	program, (int)strlen(program), "");
     exit(2);
 }
 
 static int
 mkdirs(char *path, mode_t mode)
 {
     char *cp;
     struct stat sb;
-    int res;
-
+    
     while (*path == '/' && path[1] == '/')
 	path++;
     while ((cp = strrchr(path, '/')) && cp[1] == '\0')
 	*cp = '\0';
     if (cp && cp != path) {
 	*cp = '\0';
 	if ((lstat(path, &sb) < 0 || !S_ISDIR(sb.st_mode)) &&
 	    mkdirs(path, mode) < 0) {
 	    return -1;
 	}
 	*cp = '/';
     }
-    res = mkdir(path, mode);
-    if ((res != 0) && (errno == EEXIST))
-      return 0;
-    else
-      return res;
+    return mkdir(path, mode);
 }
 
 static uid_t
 touid(char *owner)
 {
     struct passwd *pw;
     uid_t uid;
     char *cp;
@@ -335,8 +335,196 @@ main(int argc, char **argv)
 
 	free(toname);
     }
 
     free(cwd);
     free(todir);
     return 0;
 }
+
+/*
+** Pathname subroutines.
+**
+** Brendan Eich, 8/29/95
+*/
+
+char *program;
+
+void
+fail(char *format, ...)
+{
+    int error;
+    va_list ap;
+
+#ifdef USE_REENTRANT_LIBC
+    R_STRERROR_INIT_R();
+#endif
+
+    error = errno;
+    fprintf(stderr, "%s: ", program);
+    va_start(ap, format);
+    vfprintf(stderr, format, ap);
+    va_end(ap);
+    if (error)
+
+#ifdef USE_REENTRANT_LIBC
+    R_STRERROR_R(errno);
+	fprintf(stderr, ": %s", r_strerror_r);
+#else
+	fprintf(stderr, ": %s", strerror(errno));
+#endif
+
+    putc('\n', stderr);
+    exit(1);
+}
+
+char *
+getcomponent(char *path, char *name)
+{
+    if (*path == '\0')
+	return 0;
+    if (*path == '/') {
+	*name++ = '/';
+    } else {
+	do {
+	    *name++ = *path++;
+	} while (*path != '/' && *path != '\0');
+    }
+    *name = '\0';
+    while (*path == '/')
+	path++;
+    return path;
+}
+
+#ifdef UNIXWARE
+/* Sigh.  The static buffer in Unixware's readdir is too small. */
+struct dirent * readdir(DIR *d)
+{
+        static struct dirent *buf = NULL;
+#define MAX_PATH_LEN 1024
+
+
+        if(buf == NULL)
+                buf = (struct dirent *) malloc(sizeof(struct dirent) + MAX_PATH_LEN)
+;
+        return(readdir_r(d, buf));
+}
+#endif
+
+char *
+ino2name(ino_t ino, char *dir)
+{
+    DIR *dp;
+    struct dirent *ep;
+    char *name;
+
+    dp = opendir("..");
+    if (!dp)
+	fail("cannot read parent directory");
+    for (;;) {
+	if (!(ep = readdir(dp)))
+	    fail("cannot find current directory");
+	if (ep->d_ino == ino)
+	    break;
+    }
+    name = xstrdup(ep->d_name);
+    closedir(dp);
+    return name;
+}
+
+void *
+xmalloc(size_t size)
+{
+    void *p = malloc(size);
+    if (!p)
+	fail("cannot allocate %u bytes", size);
+    return p;
+}
+
+char *
+xstrdup(char *s)
+{
+    return strcpy((char*)xmalloc(strlen(s) + 1), s);
+}
+
+char *
+xbasename(char *path)
+{
+    char *cp;
+
+    while ((cp = strrchr(path, '/')) && cp[1] == '\0')
+	*cp = '\0';
+    if (!cp) return path;
+    return cp + 1;
+}
+
+void
+xchdir(char *dir)
+{
+    if (chdir(dir) < 0)
+	fail("cannot change directory to %s", dir);
+}
+
+int
+relatepaths(char *from, char *to, char *outpath)
+{
+    char *cp, *cp2;
+    int len;
+    char buf[NAME_MAX];
+
+    assert(*from == '/' && *to == '/');
+    for (cp = to, cp2 = from; *cp == *cp2; cp++, cp2++)
+	if (*cp == '\0')
+	    break;
+    while (cp[-1] != '/')
+	cp--, cp2--;
+    if (cp - 1 == to) {
+	/* closest common ancestor is /, so use full pathname */
+	len = strlen(strcpy(outpath, to));
+	if (outpath[len] != '/') {
+	    outpath[len++] = '/';
+	    outpath[len] = '\0';
+	}
+    } else {
+	len = 0;
+	while ((cp2 = getcomponent(cp2, buf)) != 0) {
+	    strcpy(outpath + len, "../");
+	    len += 3;
+	}
+	while ((cp = getcomponent(cp, buf)) != 0) {
+	    sprintf(outpath + len, "%s/", buf);
+	    len += strlen(outpath + len);
+	}
+    }
+    return len;
+}
+
+void
+reversepath(char *inpath, char *name, int len, char *outpath)
+{
+    char *cp, *cp2;
+    char buf[NAME_MAX];
+    struct stat sb;
+
+    cp = strcpy(outpath + PATH_MAX - (len + 1), name);
+    cp2 = inpath;
+    while ((cp2 = getcomponent(cp2, buf)) != 0) {
+	if (strcmp(buf, ".") == 0)
+	    continue;
+	if (strcmp(buf, "..") == 0) {
+	    if (stat(".", &sb) < 0)
+		fail("cannot stat current directory");
+	    name = ino2name(sb.st_ino, "..");
+	    len = strlen(name);
+	    cp -= len + 1;
+	    strcpy(cp, name);
+	    cp[len] = '/';
+	    free(name);
+	    xchdir("..");
+	} else {
+	    cp -= 3;
+	    strncpy(cp, "../", 3);
+	    xchdir(buf);
+	}
+    }
+    strcpy(outpath, cp);
+}
deleted file mode 100644
--- a/config/pathsub.c
+++ /dev/null
@@ -1,219 +0,0 @@
-/* -*- 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.0 (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.
- */
-
-/*
-** Pathname subroutines.
-**
-** Brendan Eich, 8/29/95
-*/
-#include <assert.h>
-#include <sys/types.h>
-#include <dirent.h>
-#include <errno.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include "pathsub.h"
-#ifdef USE_REENTRANT_LIBC
-#include "libc_r.h"
-#endif /* USE_REENTRANT_LIBC */
-
-char *program;
-
-void
-fail(char *format, ...)
-{
-    int error;
-    va_list ap;
-
-#ifdef USE_REENTRANT_LIBC
-    R_STRERROR_INIT_R();
-#endif
-
-    error = errno;
-    fprintf(stderr, "%s: ", program);
-    va_start(ap, format);
-    vfprintf(stderr, format, ap);
-    va_end(ap);
-    if (error)
-
-#ifdef USE_REENTRANT_LIBC
-    R_STRERROR_R(errno);
-	fprintf(stderr, ": %s", r_strerror_r);
-#else
-	fprintf(stderr, ": %s", strerror(errno));
-#endif
-
-    putc('\n', stderr);
-    exit(1);
-}
-
-char *
-getcomponent(char *path, char *name)
-{
-    if (*path == '\0')
-	return 0;
-    if (*path == '/') {
-	*name++ = '/';
-    } else {
-	do {
-	    *name++ = *path++;
-	} while (*path != '/' && *path != '\0');
-    }
-    *name = '\0';
-    while (*path == '/')
-	path++;
-    return path;
-}
-
-#ifdef UNIXWARE
-/* Sigh.  The static buffer in Unixware's readdir is too small. */
-struct dirent * readdir(DIR *d)
-{
-        static struct dirent *buf = NULL;
-#define MAX_PATH_LEN 1024
-
-
-        if(buf == NULL)
-                buf = (struct dirent *) malloc(sizeof(struct dirent) + MAX_PATH_LEN)
-;
-        return(readdir_r(d, buf));
-}
-#endif
-
-char *
-ino2name(ino_t ino, char *dir)
-{
-    DIR *dp;
-    struct dirent *ep;
-    char *name;
-
-    dp = opendir("..");
-    if (!dp)
-	fail("cannot read parent directory");
-    for (;;) {
-	if (!(ep = readdir(dp)))
-	    fail("cannot find current directory");
-	if (ep->d_ino == ino)
-	    break;
-    }
-    name = xstrdup(ep->d_name);
-    closedir(dp);
-    return name;
-}
-
-void *
-xmalloc(size_t size)
-{
-    void *p = malloc(size);
-    if (!p)
-	fail("cannot allocate %u bytes", size);
-    return p;
-}
-
-char *
-xstrdup(char *s)
-{
-    return strcpy((char*)xmalloc(strlen(s) + 1), s);
-}
-
-char *
-xbasename(char *path)
-{
-    char *cp;
-
-    while ((cp = strrchr(path, '/')) && cp[1] == '\0')
-	*cp = '\0';
-    if (!cp) return path;
-    return cp + 1;
-}
-
-void
-xchdir(char *dir)
-{
-    if (chdir(dir) < 0)
-	fail("cannot change directory to %s", dir);
-}
-
-int
-relatepaths(char *from, char *to, char *outpath)
-{
-    char *cp, *cp2;
-    int len;
-    char buf[NAME_MAX];
-
-    assert(*from == '/' && *to == '/');
-    for (cp = to, cp2 = from; *cp == *cp2; cp++, cp2++)
-	if (*cp == '\0')
-	    break;
-    while (cp[-1] != '/')
-	cp--, cp2--;
-    if (cp - 1 == to) {
-	/* closest common ancestor is /, so use full pathname */
-	len = strlen(strcpy(outpath, to));
-	if (outpath[len] != '/') {
-	    outpath[len++] = '/';
-	    outpath[len] = '\0';
-	}
-    } else {
-	len = 0;
-	while ((cp2 = getcomponent(cp2, buf)) != 0) {
-	    strcpy(outpath + len, "../");
-	    len += 3;
-	}
-	while ((cp = getcomponent(cp, buf)) != 0) {
-	    sprintf(outpath + len, "%s/", buf);
-	    len += strlen(outpath + len);
-	}
-    }
-    return len;
-}
-
-void
-reversepath(char *inpath, char *name, int len, char *outpath)
-{
-    char *cp, *cp2;
-    char buf[NAME_MAX];
-    struct stat sb;
-
-    cp = strcpy(outpath + PATH_MAX - (len + 1), name);
-    cp2 = inpath;
-    while ((cp2 = getcomponent(cp2, buf)) != 0) {
-	if (strcmp(buf, ".") == 0)
-	    continue;
-	if (strcmp(buf, "..") == 0) {
-	    if (stat(".", &sb) < 0)
-		fail("cannot stat current directory");
-	    name = ino2name(sb.st_ino, "..");
-	    len = strlen(name);
-	    cp -= len + 1;
-	    strcpy(cp, name);
-	    cp[len] = '/';
-	    free(name);
-	    xchdir("..");
-	} else {
-	    cp -= 3;
-	    strncpy(cp, "../", 3);
-	    xchdir(buf);
-	}
-    }
-    strcpy(outpath, cp);
-}
--- a/config/rules.mk
+++ b/config/rules.mk
@@ -42,22 +42,19 @@
 # d)
 #	PROGRAM	-- the target program name to create from $OBJS
 #			($OBJDIR automatically prepended to it)
 # e)
 #	LIBRARY	-- the target library name to create from $OBJS
 #			($OBJDIR automatically prepended to it)
 #
 ################################################################################
-ifndef topsrcdir
-topsrcdir = $(MOD_DEPTH)
-endif
 
 ifndef NSPR_CONFIG_MK
-include $(topsrcdir)/config/config.mk
+include $(MOD_DEPTH)/config/config.mk
 endif
 
 #
 # This makefile contains rules for building the following kinds of
 # libraries:
 # - LIBRARY: a static (archival) library
 # - SHARED_LIBRARY: a shared (dynamic link) library
 # - IMPORT_LIBRARY: an import library, used only on Windows and OS/2
@@ -85,18 +82,20 @@ IMPORT_LIBRARY	= $(OBJDIR)/lib$(LIBRARY_
 endif
 
 else
 
 LIBRARY		= $(OBJDIR)/lib$(LIBRARY_NAME)$(LIBRARY_VERSION).$(LIB_SUFFIX)
 ifeq ($(OS_ARCH)$(OS_RELEASE), AIX4.1)
 SHARED_LIBRARY	= $(OBJDIR)/lib$(LIBRARY_NAME)$(LIBRARY_VERSION)_shr.a
 else
+ifdef MKSHLIB
 SHARED_LIBRARY	= $(OBJDIR)/lib$(LIBRARY_NAME)$(LIBRARY_VERSION).$(DLL_SUFFIX)
 endif
+endif
 ifdef HAVE_PURIFY
 ifdef DSO_BACKEND
 PURE_LIBRARY	= $(OBJDIR)/purelib$(LIBRARY_NAME)$(LIBRARY_VERSION).$(DLL_SUFFIX)
 else
 PURE_LIBRARY	= $(OBJDIR)/purelib$(LIBRARY_NAME)$(LIBRARY_VERSION).$(LIB_SUFFIX)
 endif
 endif
 
@@ -146,20 +145,16 @@ OBJS += $(RES)
 endif
 endif
 endif
 
 ALL_TRASH		= $(TARGETS) $(OBJS) $(OBJDIR) LOGS TAGS $(GARBAGE) \
 			  $(NOSUCHFILE) \
 			  so_locations
 
-ifdef USE_AUTOCONF
-ALL_TRASH		:= $(filter-out $(OBJDIR), $(ALL_TRASH))
-endif
-
 ifdef DIRS
 LOOP_OVER_DIRS		=					\
 	@for d in $(DIRS); do					\
 		if test -d $$d; then				\
 			set -e;					\
 			echo "cd $$d; $(MAKE) $@";		\
 			$(MAKE) -C $$d $@;			\
 			set +e;					\
@@ -182,21 +177,17 @@ libs::
 install::
 	+$(LOOP_OVER_DIRS)
 
 clean::
 	rm -rf $(OBJS) so_locations $(NOSUCHFILE)
 	+$(LOOP_OVER_DIRS)
 
 clobber::
-ifdef USE_AUTOCONF
-	rm -rf $(OBJS) $(TARGETS) $(GARBAGE) so_locations $(NOSUCHFILE)
-else
 	rm -rf $(OBJS) $(TARGETS) $(OBJDIR) $(GARBAGE) so_locations $(NOSUCHFILE)
-endif
 	+$(LOOP_OVER_DIRS)
 
 realclean clobber_all::
 	rm -rf $(wildcard *.OBJ *.OBJD) dist $(ALL_TRASH)
 	+$(LOOP_OVER_DIRS)
 
 release:: export
 ifdef RELEASE_LIBS
@@ -321,19 +312,19 @@ else
 	$(RC) -Fo$(RES) $(RESNAME)
 endif
 	@echo $(RES) finished
 endif
 
 $(OBJDIR)/%.$(OBJ_SUFFIX): %.cpp
 	@$(MAKE_OBJDIR)
 ifeq ($(OS_ARCH), WINNT)
-	$(CCC) -Fo$@ -c $(CFLAGS) $<
+	$(CCC) -Fo$@ -c $(CCCFLAGS) $<
 else
-	$(CCC) -o $@ -c $(CFLAGS) $< 
+	$(CCC) -o $@ -c $(CCCFLAGS) $< 
 endif
 
 WCCFLAGS1 = $(subst /,\\,$(CFLAGS))
 WCCFLAGS2 = $(subst -I,-i=,$(WCCFLAGS1))
 WCCFLAGS3 = $(subst -D,-d,$(WCCFLAGS2))
 $(OBJDIR)/%.$(OBJ_SUFFIX): %.c
 	@$(MAKE_OBJDIR)
 ifeq ($(OS_ARCH), WINNT)
@@ -341,28 +332,28 @@ ifeq ($(OS_TARGET), WIN16)
 #	$(MOD_DEPTH)/config/w16opt $(WCCFLAGS3)
 	echo $(WCCFLAGS3) >w16wccf
 	$(CC) -zq -fo$(OBJDIR)\\$*.$(OBJ_SUFFIX)  @w16wccf $*.c
 	rm w16wccf
 else
 	$(CC) -Fo$@ -c $(CFLAGS) $*.c
 endif
 else
-	$(CC) -o $@ -c $(CFLAGS) $<
+	$(CC) -o $@ -c $(CFLAGS) $*.c
 endif
 
 $(OBJDIR)/%.$(OBJ_SUFFIX): %.s
 	@$(MAKE_OBJDIR)
-	$(AS) -o $@ $(ASFLAGS) -c $<
+	$(AS) -o $@ $(ASFLAGS) -c $*.s
 
 %.i: %.c
 	$(CC) -C -E $(CFLAGS) $< > $*.i
 
 %: %.pl
-	rm -f $@; cp $< $@; chmod +x $@
+	rm -f $@; cp $*.pl $@; chmod +x $@
 
 ################################################################################
 # Special gmake rules.
 ################################################################################
 
 #
 # Re-define the list of default suffixes, so gmake won't have to churn through
 # hundreds of built-in suffix rules for stuff we don't need.
@@ -370,8 +361,17 @@ endif
 .SUFFIXES:
 .SUFFIXES: .a .$(OBJ_SUFFIX) .c .cpp .s .h .i .pl
 
 #
 # Fake targets.  Always run these rules, even if a file/directory with that
 # name already exists.
 #
 .PHONY: all alltags clean export install libs realclean release
+
+#
+# List the target pattern of an implicit rule as a dependency of the
+# special target .PRECIOUS to preserve intermediate files made by
+# implicit rules whose target patterns match that file's name.
+# (See GNU Make documentation, Edition 0.51, May 1996, Sec. 10.4,
+# p. 107.)
+#
+.PRECIOUS: $(OBJDIR)/%.$(OBJ_SUFFIX)
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -18,15 +18,15 @@
 #! gmake
 
 MOD_DEPTH = ..
 
 export NSPR20=1
 
 include $(MOD_DEPTH)/config/config.mk
 
-DIRS = ds libc msgc
+DIRS = ds libc
 
 include $(MOD_DEPTH)/config/rules.mk
 
 export:: $(TARGETS)
 
 install:: export
--- a/lib/ds/Makefile
+++ b/lib/ds/Makefile
@@ -29,44 +29,35 @@ endif
 endif
 
 INCLUDES = -I$(DIST)/include/private -I$(DIST)/include
 
 CSRCS = \
 	plarena.c \
 	plevent.c \
 	plhash.c \
-	plvector.c \
 	$(NULL)
 
 HEADERS = \
 	plarenas.h \
 	plarena.h \
 	plevent.h \
 	plhash.h \
-	plvector.h \
 	$(NULL)
 
 ifeq ($(OS_ARCH), WINNT)
 ifeq (,$(filter-out WIN16 OS2,$(OS_TARGET)))
 # OS_CFLAGS = $(OS_EXE_CFLAGS)
 EXTRA_LIBS = $(DIST)/lib/nspr$(MOD_VERSION).lib
 else
 DLLBASE=/BASE:0x30000000
 RES=$(OBJDIR)/ds.res
 RESNAME=$(MOD_DEPTH)/pr/src/nspr.rc
 OS_LIBS = user32.lib
 EXTRA_LIBS = $(DIST)/lib/libnspr$(MOD_VERSION).lib
-
-ifdef MOZ_DEBUG
-ifdef GLOWCODE
-EXTRA_LIBS += $(GLOWDIR)/glowcode.lib
-endif
-endif
-
 endif
 else
 ifeq ($(OS_ARCH), AIX)
 ifeq ($(CLASSIC_NSPR),1)
 OS_LIBS += -lc
 else
 OS_LIBS += -lc_r
 endif
@@ -101,17 +92,19 @@ include $(MOD_DEPTH)/config/rules.mk
 #
 # The Client build wants the shared libraries in $(DIST)/bin,
 # so we also install them there.
 #
 
 export:: $(TARGETS)
 	$(INSTALL) -m 444 $(HEADERS) $(DIST)/include
 	$(INSTALL) -m 444 $(TARGETS) $(DIST)/lib
+ifdef SHARED_LIBRARY
 	$(INSTALL) -m 444 $(SHARED_LIBRARY) $(DIST)/bin
+endif
 ifeq ($(MOZ_BITS),16)
 	$(INSTALL) -m 444 $(HEADERS) $(MOZ_INCL)
 	$(INSTALL) -m 444 $(TARGETS) $(MOZ_DIST)/lib
 	$(INSTALL) -m 444 $(TARGETS) $(MOZ_DIST)/bin
 endif
 
 install:: export
 
--- a/lib/ds/plevent.c
+++ b/lib/ds/plevent.c
@@ -187,17 +187,17 @@ PL_PostSynchronousEvent(PLEventQueue* se
 	   is also the thread that's supposed to do the handling. */
 	result = event->handler(event);
     }
     else {
 	int inEventQueueMon = PR_GetMonitorEntryCount(self->monitor);
 	int i, entryCount = self->monitor->entryCount;
 
 	event->synchronousResult = (void*)PR_TRUE;
-	PR_PostEvent(self, event);
+	PL_PostEvent(self, event);
 	/* We need to temporarily give up our event queue monitor if
 	   we're holding it, otherwise, the thread we're going to wait
 	   for notification from won't be able to enter it to process
 	   the event. */
 	if (inEventQueueMon) {
 	    for (i = 0; i < entryCount; i++)
 		PR_ExitMonitor(self->monitor);
 	}
@@ -325,17 +325,17 @@ PL_RevokeEvents(PLEventQueue* self, void
     ** Discard any pending events for this owner:
     */
     PL_MapEvents(self, _pl_DestroyEventForOwner, owner);
 
 #ifdef DEBUG
     {
 	PRCList* qp = self->queue.next;
 	while (qp != &self->queue) {
-	    PREvent* event = PR_EVENT_PTR(qp);
+	    PLEvent* event = PR_EVENT_PTR(qp);
 	    qp = qp->next;
 	    PR_ASSERT(event->owner != owner);
 	}
     }
 #endif /* DEBUG */
 
     PR_ExitMonitor(self->monitor);
 
--- a/lib/ds/plhash.c
+++ b/lib/ds/plhash.c
@@ -22,16 +22,33 @@
 #include "plhash.h"
 #include "prbit.h"
 #include "prlog.h"
 #include "prmem.h"
 #include "prtypes.h"
 #include <stdlib.h>
 #include <string.h>
 
+struct PLHashTable {
+    PLHashEntry         **buckets;      /* vector of hash buckets */
+    PRUint32              nentries;       /* number of entries in table */
+    PRUint32              shift;          /* multiplicative hash shift */
+    PLHashFunction      keyHash;        /* key hash function */
+    PLHashComparator    keyCompare;     /* key comparison function */
+    PLHashComparator    valueCompare;   /* value comparison function */
+    const PLHashAllocOps *allocOps;     /* allocation operations */
+    void                *allocPriv;     /* allocation private data */
+#ifdef HASHMETER
+    PRUint32              nlookups;       /* total number of lookups */
+    PRUint32              nsteps;         /* number of hash chains traversed */
+    PRUint32              ngrows;         /* number of table expansions */
+    PRUint32              nshrinks;       /* number of table contractions */
+#endif
+};
+
 /* Compute the number of buckets in ht */
 #define NBUCKETS(ht)    (1 << (PL_HASH_BITS - (ht)->shift))
 
 /* The smallest table has 16 buckets */
 #define MINBUCKETSLOG2  4
 #define MINBUCKETS      (1 << MINBUCKETSLOG2)
 
 /* Compute the maximum entries given n buckets that we will tolerate, ~90% */
@@ -55,17 +72,17 @@ DefaultAllocTable(void *pool, PRSize siz
 
 static void PR_CALLBACK
 DefaultFreeTable(void *pool, void *item)
 {
 #if defined(XP_MAC)
 #pragma unused (pool)
 #endif
 
-    PR_DELETE(item);
+    PR_Free(item);
 }
 
 static PLHashEntry * PR_CALLBACK
 DefaultAllocEntry(void *pool, const void *key)
 {
 #if defined(XP_MAC)
 #pragma unused (pool,key)
 #endif
@@ -76,31 +93,31 @@ DefaultAllocEntry(void *pool, const void
 static void PR_CALLBACK
 DefaultFreeEntry(void *pool, PLHashEntry *he, PRUintn flag)
 {
 #if defined(XP_MAC)
 #pragma unused (pool)
 #endif
 
     if (flag == HT_FREE_ENTRY)
-        PR_DELETE(he);
+        PR_Free(he);
 }
 
 static PLHashAllocOps defaultHashAllocOps = {
     DefaultAllocTable, DefaultFreeTable,
     DefaultAllocEntry, DefaultFreeEntry
 };
 
 PR_IMPLEMENT(PLHashTable *)
 PL_NewHashTable(PRUint32 n, PLHashFunction keyHash,
                 PLHashComparator keyCompare, PLHashComparator valueCompare,
-                PLHashAllocOps *allocOps, void *allocPriv)
+                const PLHashAllocOps *allocOps, void *allocPriv)
 {
     PLHashTable *ht;
-    PRUint32 nb;
+    PRSize nb;
 
     if (n <= MINBUCKETS) {
         n = MINBUCKETSLOG2;
     } else {
         n = PR_CeilingLog2(n);
         if ((PRInt32)n < 0)
             return 0;
     }
@@ -108,17 +125,17 @@ PL_NewHashTable(PRUint32 n, PLHashFuncti
     if (!allocOps) allocOps = &defaultHashAllocOps;
 
     ht = (PLHashTable*)((*allocOps->allocTable)(allocPriv, sizeof *ht));
     if (!ht)
 	return 0;
     memset(ht, 0, sizeof *ht);
     ht->shift = PL_HASH_BITS - n;
     n = 1 << n;
-#if defined(XP_PC) && !defined(_WIN32)
+#if defined(WIN16)
     if (n > 16000) {
         (*allocOps->freeTable)(allocPriv, ht);
         return 0;
     }
 #endif  /* WIN16 */
     nb = n * sizeof(PLHashEntry *);
     ht->buckets = (PLHashEntry**)((*allocOps->allocTable)(allocPriv, nb));
     if (!ht->buckets) {
@@ -135,17 +152,17 @@ PL_NewHashTable(PRUint32 n, PLHashFuncti
     return ht;
 }
 
 PR_IMPLEMENT(void)
 PL_HashTableDestroy(PLHashTable *ht)
 {
     PRUint32 i, n;
     PLHashEntry *he, *next;
-    PLHashAllocOps *allocOps = ht->allocOps;
+    const PLHashAllocOps *allocOps = ht->allocOps;
     void *allocPriv = ht->allocPriv;
 
     n = NBUCKETS(ht);
     for (i = 0; i < n; i++) {
         for (he = ht->buckets[i]; he; he = next) {
             next = he->next;
             (*allocOps->freeEntry)(allocPriv, he, HT_FREE_ENTRY);
         }
@@ -196,27 +213,27 @@ PL_HashTableRawLookup(PLHashTable *ht, P
 }
 
 PR_IMPLEMENT(PLHashEntry *)
 PL_HashTableRawAdd(PLHashTable *ht, PLHashEntry **hep,
                    PLHashNumber keyHash, const void *key, void *value)
 {
     PRUint32 i, n;
     PLHashEntry *he, *next, **oldbuckets;
-    PRUint32 nb;
+    PRSize nb;
 
     /* Grow the table if it is overloaded */
     n = NBUCKETS(ht);
     if (ht->nentries >= OVERLOADED(n)) {
 #ifdef HASHMETER
         ht->ngrows++;
 #endif
         ht->shift--;
         oldbuckets = ht->buckets;
-#if defined(XP_PC) && !defined(_WIN32)
+#if defined(WIN16)
         if (2 * n > 16000)
             return 0;
 #endif  /* WIN16 */
         nb = 2 * n * sizeof(PLHashEntry *);
         ht->buckets = (PLHashEntry**)
             ((*ht->allocOps->allocTable)(ht->allocPriv, nb));
         if (!ht->buckets) {
             ht->buckets = oldbuckets;
@@ -275,17 +292,17 @@ PL_HashTableAdd(PLHashTable *ht, const v
     return PL_HashTableRawAdd(ht, hep, keyHash, key, value);
 }
 
 PR_IMPLEMENT(void)
 PL_HashTableRawRemove(PLHashTable *ht, PLHashEntry **hep, PLHashEntry *he)
 {
     PRUint32 i, n;
     PLHashEntry *next, **oldbuckets;
-    PRUint32 nb;
+    PRSize nb;
 
     *hep = he->next;
     (*ht->allocOps->freeEntry)(ht->allocPriv, he, HT_FREE_ENTRY);
 
     /* Shrink table if it's underloaded */
     n = NBUCKETS(ht);
     if (--ht->nentries < UNDERLOADED(n)) {
 #ifdef HASHMETER
--- a/lib/ds/plhash.h
+++ b/lib/ds/plhash.h
@@ -16,29 +16,28 @@
  * Reserved.
  */
 
 #ifndef plhash_h___
 #define plhash_h___
 /*
  * API to portable hash table code.
  */
-#include <stddef.h>
 #include <stdio.h>
 #include "prtypes.h"
 
 PR_BEGIN_EXTERN_C
 
 typedef struct PLHashEntry  PLHashEntry;
 typedef struct PLHashTable  PLHashTable;
 typedef PRUint32 PLHashNumber;
-#define PL_HASH_BITS 32
+#define PL_HASH_BITS 32  /* Number of bits in PLHashNumber */
 typedef PLHashNumber (PR_CALLBACK *PLHashFunction)(const void *key);
 typedef PRIntn (PR_CALLBACK *PLHashComparator)(const void *v1, const void *v2);
-typedef PRIntn (PR_CALLBACK *PLHashEnumerator)(PLHashEntry *he, PRIntn i, void *arg);
+typedef PRIntn (PR_CALLBACK *PLHashEnumerator)(PLHashEntry *he, PRIntn index, void *arg);
 
 /* Flag bits in PLHashEnumerator's return value */
 #define HT_ENUMERATE_NEXT       0       /* continue enumerating entries */
 #define HT_ENUMERATE_STOP       1       /* stop enumerating entries */
 #define HT_ENUMERATE_REMOVE     2       /* remove and free the current entry */
 #define HT_ENUMERATE_UNHASH     4       /* just unhash the current entry */
 
 typedef struct PLHashAllocOps {
@@ -53,79 +52,63 @@ typedef struct PLHashAllocOps {
 
 struct PLHashEntry {
     PLHashEntry         *next;          /* hash chain linkage */
     PLHashNumber        keyHash;        /* key hash function result */
     const void          *key;           /* ptr to opaque key */
     void                *value;         /* ptr to opaque value */
 };
 
-struct PLHashTable {
-    PLHashEntry         **buckets;      /* vector of hash buckets */
-    PRUint32              nentries;       /* number of entries in table */
-    PRUint32              shift;          /* multiplicative hash shift */
-    PLHashFunction      keyHash;        /* key hash function */
-    PLHashComparator    keyCompare;     /* key comparison function */
-    PLHashComparator    valueCompare;   /* value comparison function */
-    PLHashAllocOps      *allocOps;      /* allocation operations */
-    void                *allocPriv;     /* allocation private data */
-#ifdef HASHMETER
-    PRUint32              nlookups;       /* total number of lookups */
-    PRUint32              nsteps;         /* number of hash chains traversed */
-    PRUint32              ngrows;         /* number of table expansions */
-    PRUint32              nshrinks;       /* number of table contractions */
-#endif
-};
-
 /*
  * Create a new hash table.
  * If allocOps is null, use default allocator ops built on top of malloc().
  */
 PR_EXTERN(PLHashTable *)
-PL_NewHashTable(PRUint32 n, PLHashFunction keyHash,
+PL_NewHashTable(PRUint32 numBuckets, PLHashFunction keyHash,
                 PLHashComparator keyCompare, PLHashComparator valueCompare,
-                PLHashAllocOps *allocOps, void *allocPriv);
+                const PLHashAllocOps *allocOps, void *allocPriv);
 
 PR_EXTERN(void)
 PL_HashTableDestroy(PLHashTable *ht);
 
+/* Higher level access methods */
+PR_EXTERN(PLHashEntry *)
+PL_HashTableAdd(PLHashTable *ht, const void *key, void *value);
+
+PR_EXTERN(PRBool)
+PL_HashTableRemove(PLHashTable *ht, const void *key);
+
+PR_EXTERN(void *)
+PL_HashTableLookup(PLHashTable *ht, const void *key);
+
+PR_EXTERN(PRIntn)
+PL_HashTableEnumerateEntries(PLHashTable *ht, PLHashEnumerator f, void *arg);
+
+/* General-purpose C string hash function. */
+PR_EXTERN(PLHashNumber)
+PL_HashString(const void *key);
+
+/* Compare strings using strcmp(), return true if equal. */
+PR_EXTERN(PRIntn)
+PL_CompareStrings(const void *v1, const void *v2);
+
+/* Stub function just returns v1 == v2 */
+PR_EXTERN(PRIntn)
+PL_CompareValues(const void *v1, const void *v2);
+
 /* Low level access methods */
 PR_EXTERN(PLHashEntry **)
 PL_HashTableRawLookup(PLHashTable *ht, PLHashNumber keyHash, const void *key);
 
 PR_EXTERN(PLHashEntry *)
 PL_HashTableRawAdd(PLHashTable *ht, PLHashEntry **hep, PLHashNumber keyHash,
                    const void *key, void *value);
 
 PR_EXTERN(void)
 PL_HashTableRawRemove(PLHashTable *ht, PLHashEntry **hep, PLHashEntry *he);
 
-/* Higher level access methods */
-PR_EXTERN(PLHashEntry *)
-PL_HashTableAdd(PLHashTable *ht, const void *key, void *value);
-
-PR_EXTERN(PRBool)
-PL_HashTableRemove(PLHashTable *ht, const void *key);
-
-PR_EXTERN(PRIntn)
-PL_HashTableEnumerateEntries(PLHashTable *ht, PLHashEnumerator f, void *arg);
-
-PR_EXTERN(void *)
-PL_HashTableLookup(PLHashTable *ht, const void *key);
-
+/* This can be trivially implemented using PL_HashTableEnumerateEntries. */
 PR_EXTERN(PRIntn)
 PL_HashTableDump(PLHashTable *ht, PLHashEnumerator dump, FILE *fp);
 
-/* General-purpose C string hash function. */
-PR_EXTERN(PLHashNumber)
-PL_HashString(const void *key);
-
-/* Compare strings using strcmp(), return true if equal. */
-PR_EXTERN(int)
-PL_CompareStrings(const void *v1, const void *v2);
-
-/* Stub function just returns v1 == v2 */
-PR_EXTERN(PRIntn)
-PL_CompareValues(const void *v1, const void *v2);
-
 PR_END_EXTERN_C
 
 #endif /* plhash_h___ */
--- a/lib/libc/src/Makefile
+++ b/lib/libc/src/Makefile
@@ -26,16 +26,17 @@ ifeq ($(OS_ARCH),SunOS)
 ifeq ($(OS_RELEASE),4.1.3_U1)
 OPTIMIZER =
 endif
 endif
 
 INCLUDES = -I$(DIST)/include
 
 CSRCS =\
+	plvrsion.c  \
 	strlen.c  \
 	strcpy.c  \
 	strdup.c  \
 	strcat.c  \
 	strcmp.c  \
 	strccmp.c \
 	strchr.c  \
 	strpbrk.c \
@@ -54,23 +55,16 @@ RELEASE_LIBS = $(TARGETS)
 ifeq ($(OS_ARCH),WINNT)
 ifeq (,$(filter-out WIN16 OS2,$(OS_TARGET)))
 EXTRA_LIBS = $(DIST)/lib/nspr$(MOD_VERSION).lib
 else
 DLLBASE=/BASE:0x30000000
 RES=$(OBJDIR)/plc.res
 RESNAME=$(MOD_DEPTH)/pr/src/nspr.rc
 EXTRA_LIBS = $(DIST)/lib/libnspr$(MOD_VERSION).lib
-
-ifdef MOZ_DEBUG
-ifdef GLOWCODE
-EXTRA_LIBS += $(GLOWDIR)/glowcode.lib
-endif
-endif
-
 endif
 else
 ifeq ($(OS_ARCH), AIX)
 ifeq ($(CLASSIC_NSPR),1)
 OS_LIBS += -lc
 else
 OS_LIBS += -lc_r
 endif
@@ -91,22 +85,61 @@ EXTRA_LIBS =
 endif
 ifeq ($(OS_ARCH),SCOOS)
 EXTRA_LIBS =
 endif
 
 include $(MOD_DEPTH)/config/rules.mk
 
 #
+# Version information generation (begin)
+#
+RM = rm
+ECHO = echo
+INCLUDES = -I$(DIST)/include
+TINC = $(OBJDIR)/_pl_bld.h
+PROD = libplc$(MOD_VERSION).$(DLL_SUFFIX)
+NOW = $(MOD_DEPTH)/config/$(OBJDIR)/now
+SH_DATE = $(shell date)
+SH_NOW = $(shell $(NOW))
+
+ifeq ($(OS_ARCH), WINNT)
+	SUF = i64
+	SH_QUOTE =
+else
+	SUF = LL
+	SH_QUOTE = "
+endif
+
+$(TINC):
+	@$(MAKE_OBJDIR)
+	@$(ECHO) $(SH_QUOTE)#define _BUILD_STRING \"$(SH_DATE)\"$(SH_QUOTE) > $(TINC)
+	@$(ECHO) $(SH_QUOTE)#define _BUILD_TIME $(SH_NOW)$(SUF)$(SH_QUOTE) >> $(TINC)
+	@$(ECHO) $(SH_QUOTE)#define _PRODUCTION \"$(PROD)\"$(SH_QUOTE) >> $(TINC)
+
+
+$(OBJDIR)/plvrsion.$(OBJ_SUFFIX): $(TINC)
+ifeq ($(OS_ARCH), WINNT)
+	$(CC) -Fo$@ -c $(CFLAGS) -I$(OBJDIR) plvrsion.c
+else
+	$(CC) -o $@ -c $(CFLAGS) -I$(OBJDIR) plvrsion.c
+endif
+#
+# Version information generation (end)
+#
+
+#
 # The Client build wants the shared libraries in $(DIST)/bin,
 # so we also install them there.
 #
 
 export:: $(TARGETS)
 	$(INSTALL) -m 444 $(TARGETS) $(DIST)/lib
+ifdef SHARED_LIBRARY
 	$(INSTALL) -m 444 $(SHARED_LIBRARY) $(DIST)/bin
+endif
 ifeq ($(MOZ_BITS),16)
 	$(INSTALL) -m 444 $(TARGETS) $(MOZ_DIST)/lib
 	$(INSTALL) -m 444 $(TARGETS) $(MOZ_DIST)/bin
 endif
 
 install:: export
 
--- a/lib/libc/src/plerror.c
+++ b/lib/libc/src/plerror.c
@@ -95,16 +95,20 @@ static const char *tags[] =
     "PR_NO_MORE_FILES_ERROR",
     "PR_END_OF_FILE_ERROR",
     "PR_FILE_SEEK_ERROR",
     "PR_FILE_IS_BUSY_ERROR", 
     "PR_IN_PROGRESS_ERROR",
     "PR_ALREADY_INITIATED_ERROR",
     "PR_GROUP_EMPTY_ERROR",
     "PR_INVALID_STATE_ERROR",
+    "PR_NETWORK_DOWN_ERROR",
+    "PR_SOCKET_SHUTDOWN_ERROR",
+    "PR_CONNECT_ABORTED_ERROR",
+    "PR_HOST_UNREACHABLE_ERROR",
     "PR_MAX_ERROR"
 };
 
 PRErrorCode error = PR_GetError();
 PRInt32 oserror = PR_GetOSError();
 PRIntn thoseIKnowAbout = sizeof(tags) / sizeof(char*);
 PRIntn lastError = PR_NSPR_ERROR_BASE + thoseIKnowAbout;
 
new file mode 100644
--- /dev/null
+++ b/lib/libc/src/plvrsion.c
@@ -0,0 +1,65 @@
+/* -*- 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.0 (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 "prinit.h"
+#include "prvrsion.h"
+
+/************************************************************************/
+/**************************IDENTITY AND VERSIONING***********************/
+/************************************************************************/
+#include "_pl_bld.h"
+#if !defined(_BUILD_TIME)
+#define _BUILD_TIME 0
+#endif
+#if !defined(_BUILD_STRING)
+#define _BUILD_STRING ""
+#endif
+#if !defined(_PRODUCTION)
+#define _PRODUCTION ""
+#endif
+
+static PRVersionDescription prVersionDescription_libplc21 =
+{
+    /* version          */  2,                  /* this is the only one supported */
+    /* buildTime        */  _BUILD_TIME,        /* usecs since midnight 1/1/1970 GMT */
+    /* buildTimeString  */  _BUILD_STRING,       /*    ditto, but human readable */
+    /* vMajor           */  PR_VMAJOR,          /* NSPR's version number */
+    /* vMinor           */  PR_VMINOR,          /*  and minor version */
+    /* vPatch           */  PR_VPATCH,          /*  and patch */
+    /* beta             */  PR_BETA,            /* beta build boolean */
+#if defined(DEBUG)
+    /* debug            */  PR_TRUE,            /* a debug build */
+#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/",
+    /* specialString    */ ""
+};
+
+PR_IMPLEMENT(const PRVersionDescription*) libVersionPoint()
+{
+    return &prVersionDescription_libplc21;
+}  /* versionEntryPointType */
+
+/* prvrsion.c */
+
--- a/lib/msgc/include/gcint.h
+++ b/lib/msgc/include/gcint.h
@@ -70,17 +70,17 @@ struct RootFinderStr {
     GCRootFinder *func;
     char *name;
     void *arg;
 };
 extern RootFinder *_pr_rootFinders;
 
 typedef struct CollectorTypeStr {
     GCType gctype;
-    uint32 flags;
+    PRUint32 flags;
 } CollectorType;
 
 #define GC_MAX_TYPES	256
 extern CollectorType *_pr_collectorTypes;
 
 #define _GC_TYPE_BUSY   0x1
 #define _GC_TYPE_FINAL  0x2
 #define _GC_TYPE_WEAK   0x4
--- a/lib/msgc/include/prgc.h
+++ b/lib/msgc/include/prgc.h
@@ -60,18 +60,18 @@ typedef PRInt32 (*PRWalkFun)(void GCPTR*
 
 /*
 ** GC Type record. This defines all of the GC operations used on a
 ** particular object type. These structures are passed to
 ** PR_RegisterType.
 */
 typedef struct GCType {
     /*
-    ** Scan an object that is in the GC heap and call PR_LiveObject on
-    ** all of the pointers in it. If this slot is null then the object
+    ** Scan an object that is in the GC heap and call GCInfo.livePointer
+    ** on all of the pointers in it. If this slot is null then the object
     ** won't be scanned (i.e. it has no embedded pointers).
     */
     void (PR_CALLBACK *scan)(void GCPTR *obj);
 
     /*
     ** Finalize an object that has no references. This is called by the
     ** GC after it has determined where the object debris is but before
     ** it has moved the debris to the logical "free list". The object is
@@ -348,17 +348,17 @@ typedef struct GCInfoStr {
 #endif
 } GCInfo;
 
 PR_EXTERN(GCInfo *) PR_GetGCInfo(void);
 PR_EXTERN(PRBool) PR_GC_In_Heap(void GCPTR *object);
 
 /*
 ** Simple bounds check to see if a pointer is anywhere near the GC heap.
-** Used to avoid calls to PR_ProcessRoot and PR_LiveObject by object
+** Used to avoid calls to PR_ProcessRoot and GCInfo.livePointer by object
 ** scanning code.
 */
 #if !defined(XP_PC) || defined(_WIN32)
 #define GC_IN_HEAP(_info, _p) (((PRWord*)(_p) >= (_info)->lowSeg) && \
                                ((PRWord*)(_p) <  (_info)->highSeg))
 #else
 /*
 ** The simple bounds check, above, doesn't work in Win16, because we don't
--- a/lib/msgc/src/Makefile
+++ b/lib/msgc/src/Makefile
@@ -52,23 +52,16 @@ ifeq ($(OS_ARCH), WINNT)
 ifeq (,$(filter-out WIN16 OS2,$(OS_TARGET)))
 EXTRA_LIBS = $(DIST)/lib/nspr$(NSPR_VERSION).lib
 else
 DLLBASE=/BASE:0x30000000
 #RES=$(OBJDIR)/ds.res
 #RESNAME=$(MOD_DEPTH)/pr/src/nspr.rc
 #OS_LIBS = user32.lib
 EXTRA_LIBS = $(DIST)/lib/libnspr$(NSPR_VERSION).lib
-
-ifdef MOZ_DEBUG
-ifdef GLOWCODE
-EXTRA_LIBS += $(GLOWDIR)/glowcode.lib
-endif
-endif
-
 endif
 else
 ifeq ($(OS_ARCH), AIX)
 ifeq ($(CLASSIC_NSPR),1)
 OS_LIBS += -lc
 else
 OS_LIBS += -lc_r
 endif
@@ -100,15 +93,17 @@ include $(MOD_DEPTH)/config/rules.mk
 
 #
 # The Client build wants the shared libraries in $(DIST)/bin,
 # so we also install them there.
 #
 
 export:: $(TARGETS)
 	$(INSTALL) -m 444 $(TARGETS) $(DIST)/lib
+ifdef SHARED_LIBRARY
 	$(INSTALL) -m 444 $(SHARED_LIBRARY) $(DIST)/bin
+endif
 ifeq ($(MOZ_BITS),16)
 	$(INSTALL) -m 444 $(TARGETS) $(MOZ_DIST)/lib
 	$(INSTALL) -m 444 $(TARGETS) $(MOZ_DIST)/bin
 endif	
 
 install:: export
--- a/lib/msgc/src/prmsgc.c
+++ b/lib/msgc/src/prmsgc.c
@@ -728,17 +728,20 @@ void ScanScanQ(GCScanQ *iscan)
 
     if (!iscan->queued) return;
 
     _GCTRACE(GC_MARK, ("begin scanQ @ 0x%x (%d)", iscan, iscan->queued));
     scan = iscan;
     next = &nextQ;
     while (scan->queued) {
 	_GCTRACE(GC_MARK, ("continue scanQ @ 0x%x (%d)", scan, scan->queued));
-    /* Set pointer to current scanQ so that pr_liveObject can find it */
+    /*
+     * Set pointer to current scanQ so that _pr_gcData.livePointer
+     * can find it.
+     */
     pScanQ = next;
     next->queued = 0;
 
     /* Now scan the scan Q */
     pp = scan->q;
     epp = &scan->q[scan->queued];
     scan->queued = 0;
     while (pp < epp) {
@@ -1885,17 +1888,17 @@ pr_ConservativeWalkPointer(void* ptr, PR
     PR_Abort();
 #endif
     return 0;
 
  winner:
     return walkRootPointer(p, data);
 }
 
-static int32 PR_CALLBACK
+static PRInt32 PR_CALLBACK
 pr_ConservativeWalkBlock(void **base, PRInt32 count,
 			 PRWalkFun walkRootPointer, void* data)
 {
     PRWord *p0;
     while (--count >= 0) {
 	PRInt32 status;
         p0 = (PRWord*) *base++;
 	status = pr_ConservativeWalkPointer(p0, walkRootPointer, data);
@@ -2078,17 +2081,17 @@ PR_DumpGCHeap(FILE *out, PRBool detailed
 PR_IMPLEMENT(void)
 PR_DumpMemory(PRBool detailed)
 {
     PR_DumpToFile("memory.out", "Dumping memory", PR_DumpGCHeap, detailed);
 }
 
 /******************************************************************************/
 
-static int32 PR_CALLBACK
+static PRInt32 PR_CALLBACK
 pr_DumpRootPointer(PRWord* p, void* data)
 {
 #ifdef XP_MAC
 #pragma unused(data)
 #endif
     PRWord h = p[0];
     PRWord tix = GET_TYPEIX(h);
       size_t bytes = OBJ_BYTES(h);
@@ -2242,17 +2245,17 @@ pr_Mark(PRWord* p)
     end->traceGeneration = pr_traceGen;
 }
 
 PRWord* pr_traceObj;	/* set this in the debugger, then execute PR_TraceRoot() */
 
 static PRInt32 PR_CALLBACK
 pr_TraceRootObject(void* obj, void* data);
 
-static int32 PR_CALLBACK
+static PRInt32 PR_CALLBACK
 pr_TraceRootPointer(PRWord *p, void* data)
 {
     PRInt32 printTrace = 0;
     PRWord h = p[0];
     PRWord tix = GET_TYPEIX(h);
     GCType* tp = &_pr_collectorTypes[tix].gctype;
     FILE* out = _pr_gcData.dumpOutput;
 
@@ -3089,16 +3092,22 @@ PR_AllocSimpleMemory(PRWord requestedByt
 #if defined(GC_CHECK) || defined(GC_STATS) || defined(GC_TRACEROOTS)
     bytes += sizeof(GCBlockEnd);
 #endif
 
 #if defined(WIN16)
     PR_ASSERT( bytes < MAX_ALLOC_SIZE );
 #endif
     /* Java can ask for objects bigger than 4M, but it won't get them */
+    /*
+     * This check was added because there is a fundamental limit of
+     * the size field maintained by the gc code.  Going over the 4M
+     * limit caused some bits to roll over into another bit field,
+     * violating the max segment size and causing a bug.
+     */
     if (bytes >= MAX_ALLOC_SIZE) {
         return NULL;
     }
 #ifdef DEBUG
     if (gc_thrash == -1L
 	? (gc_thrash = (long)PR_GetEnv("GC_THRASH"))
 	: gc_thrash) {
 	PR_GC();
@@ -3178,17 +3187,17 @@ PR_AllocSimpleMemory(PRWord requestedByt
 	GCBlockEnd* end = (GCBlockEnd*)((char*)p + OBJ_BYTES(p[0]) - sizeof(GCBlockEnd));
 	end->check = PR_BLOCK_END;
     }
 #endif
 #ifdef GC_STATS
     {
 	PRInt64 now = PR_Now();
 	double delta;
-	int32 bin;
+	PRInt32 bin;
 	GCBlockEnd* end = (GCBlockEnd*)((char*)p + OBJ_BYTES(p[0]) - sizeof(GCBlockEnd));
 
 	end->allocTime = allocTime;
 	LL_SUB(ldelta, now, allocTime);
 	LL_L2D(delta, ldelta);
 	InlineBinNumber(bin, requestedBytes);
 	end->bin = bin;
 	gcstats[bin].nallocs++;
--- a/lib/msgc/src/unixgc.c
+++ b/lib/msgc/src/unixgc.c
@@ -26,17 +26,17 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <sys/mman.h>
 
 #define _PR_GC_VMBASE 0x40000000
 
 #if defined(SOLARIS)
 #define _MD_MMAP_FLAGS MAP_SHARED
-#elif defined(OSF1) || defined(RELIANTUNIX)
+#elif defined(RELIANTUNIX)
 #define _MD_MMAP_FLAGS MAP_PRIVATE|MAP_FIXED
 #else
 #define _MD_MMAP_FLAGS MAP_PRIVATE
 #endif
 
 static PRInt32 zero_fd = -1;
 static PRLock *zero_fd_lock = NULL;
 
--- a/lib/msgc/tests/Makefile
+++ b/lib/msgc/tests/Makefile
@@ -100,17 +100,17 @@ ifeq ($(OS_RELEASE), V3.2)
   LIBGC = $(DIST)/lib/libmsgc$(GC_VERSION).a
   EXTRA_LIBS = -lc_r
 else
   LDOPTS += -rpath $(PWD)/$(DIST)/lib
 endif
 endif
 
 ifeq ($(OS_ARCH), HP-UX)
-LDOPTS += -Wl,+s,+b,$(PWD)/$(DIST)/lib
+LDOPTS += -z -Wl,+s,+b,$(PWD)/$(DIST)/lib
 endif
 
 # AIX
 ifeq ($(OS_ARCH),AIX)
 ifeq ($(CLASSIC_NSPR),1)
 LDOPTS += -blibpath:.:$(PWD)/$(DIST)/lib:/usr/lpp/xlC/lib:/usr/lib:/lib
 else
 LDOPTS += -blibpath:.:$(PWD)/$(DIST)/lib:/usr/lib/threads:/usr/lpp/xlC/lib:/usr/lib:/lib
--- a/lib/prstreams/Makefile
+++ b/lib/prstreams/Makefile
@@ -18,84 +18,91 @@
 #! gmake
 
 MOD_DEPTH = ../..
 
 include $(MOD_DEPTH)/config/config.mk
 
 # Disable optimization of the nspr on SunOS4.1.3
 ifeq ($(OS_ARCH),SunOS)
-ifeq ($(OS_RELEASE),4.1.3_U1)
-OPTIMIZER =
+    ifeq ($(OS_RELEASE),4.1.3_U1)
+        OPTIMIZER =
+    endif
 endif
-endif
+
 ifeq ($(OS_ARCH), IRIX)
-CFLAGS += -KPIC
-ifneq ($(OS_RELEASE),5.3)
-CFLAGS += -exceptions
+    CFLAGS += -KPIC
+    ifneq ($(OS_RELEASE),5.3)
+        CFLAGS += -exceptions
+    endif
 endif
+
+ifeq ($(OS_ARCH),HP-UX)
+    ifeq (($USE_64),1)
+        CCCFLAGS += +DA2.0W
+    endif
 endif
 
 INCLUDES = -I$(DIST)/include -I../../../include
 
 HEADERS = *.h
 
-CXXSRCS =           \
-	prstrms.cpp    \
+CXXSRCS = \
+	prstrms.cpp \
 	$(NULL)
 
 OBJS = $(addprefix $(OBJDIR)/,$(CXXSRCS:.cpp=.$(OBJ_SUFFIX)))
 
 ifeq ($(OS_ARCH), WINNT)
-ifeq (,$(filter-out WIN16 OS2,$(OS_TARGET)))
-EXTRA_LIBS = $(DIST)/lib/nspr$(MOD_VERSION).lib
-else
-DLLBASE=/BASE:0x30000000
-RES=$(OBJDIR)/prstrms.res
-RESNAME=$(MOD_DEPTH)/pr/src/nspr.rc
-OS_LIBS = user32.lib
-EXTRA_LIBS = $(DIST)/lib/libnspr$(MOD_VERSION).lib
-endif
-else
-ifeq ($(OS_ARCH), AIX)
-  ifeq ($(OS_RELEASE), 4.1)
-    ifeq ($(CLASSIC_NSPR),1)
-    OS_LIBS += -lC -lc
+    ifeq (,$(filter-out WIN16 OS2,$(OS_TARGET)))
+        EXTRA_LIBS = $(DIST)/lib/nspr$(MOD_VERSION).lib
     else
-    OS_LIBS += -lC_r -lc_r
-    endif
-  else
-    ifeq ($(CLASSIC_NSPR),1)
-    MKSHLIB = /usr/lpp/xlC/bin/makeC++SharedLib -p 0
-    else
-    MKSHLIB = /usr/lpp/xlC/bin/makeC++SharedLib_r -p 0
+        DLLBASE=/BASE:0x30000000
+        RES=$(OBJDIR)/prstrms.res
+        RESNAME=$(MOD_DEPTH)/pr/src/nspr.rc
+        OS_LIBS = user32.lib
+        EXTRA_LIBS = $(DIST)/lib/libnspr$(MOD_VERSION).lib
     endif
-    OS_LIBS += -ldl
-  endif
-endif
-ifeq ($(OS_ARCH)$(OS_RELEASE), AIX4.1)
-EXTRA_LIBS = -L$(DIST)/lib -lnspr$(MOD_VERSION)_shr
 else
-EXTRA_LIBS = -L$(DIST)/lib -lnspr$(MOD_VERSION)
-endif
+    ifeq ($(OS_ARCH), AIX)
+      ifeq ($(OS_RELEASE), 4.1)
+        ifeq ($(CLASSIC_NSPR),1)
+            OS_LIBS += -lC -lc
+        else
+            OS_LIBS += -lC_r -lc_r
+        endif
+      else
+        ifeq ($(CLASSIC_NSPR),1)
+            MKSHLIB = /usr/lpp/xlC/bin/makeC++SharedLib -p 0
+        else
+            MKSHLIB = /usr/lpp/xlC/bin/makeC++SharedLib_r -p 0
+        endif
+        OS_LIBS += -ldl
+      endif
+    endif
+    ifeq ($(OS_ARCH)$(OS_RELEASE), AIX4.1)
+        EXTRA_LIBS = -L$(DIST)/lib -lnspr$(MOD_VERSION)_shr
+    else
+        EXTRA_LIBS = -L$(DIST)/lib -lnspr$(MOD_VERSION)
+    endif
 endif
 
 # On NCR and SCOOS, we can't link with extra libraries when
 # we build a shared library.  If we do so, the linker doesn't
 # complain, but we would run into weird problems at run-time.
 # Therefore on these platforms, we link just the object files.
 ifeq ($(OS_ARCH),NCR)
-EXTRA_LIBS =
+    EXTRA_LIBS =
 endif
 ifeq ($(OS_ARCH),SCOOS)
-EXTRA_LIBS =
+    EXTRA_LIBS =
 endif
 
 ifeq ($(OS_ARCH), UNIXWARE)
-OS_LIBS += -lC
+    OS_LIBS += -lC
 endif
 
 LIBRARY_NAME    = prstrms
 LIBRARY_VERSION = $(MOD_VERSION)
 
 RELEASE_HEADERS = $(HEADERS)
 RELEASE_HEADERS_DEST = $(RELEASE_INCLUDE_DIR)
 RELEASE_LIBS    = $(TARGETS)
--- a/pr/include/md/Makefile
+++ b/pr/include/md/Makefile
@@ -19,17 +19,21 @@
 
 MOD_DEPTH = ../../..
 
 HEADERS = $(wildcard *.h)
 
 include $(MOD_DEPTH)/config/rules.mk
 
 ifeq ($(OS_ARCH),IRIX)
-MDCPUCFG_H = _irix.cfg
+ifeq ($(USE_64), 1)
+MDCPUCFG_H = _irix64.cfg
+else
+MDCPUCFG_H = _irix32.cfg
+endif
 endif
 
 ifeq ($(OS_ARCH),WINNT)
 ifeq ($(OS_TARGET), WIN95)
 MDCPUCFG_H = _win95.cfg
 else
 ifeq ($(OS_TARGET), WIN16)
 MDCPUCFG_H = _win16.cfg
@@ -50,22 +54,30 @@ endif
 ifeq ($(OS_ARCH),BSD_OS)
 MDCPUCFG_H = _bsdi.cfg
 endif
 
 ifeq ($(OS_ARCH),FreeBSD)
 MDCPUCFG_H = _freebsd.cfg
 endif
 
+ifeq ($(OS_ARCH),OpenBSD)
+MDCPUCFG_H = _openbsd.cfg
+endif
+
 ifeq ($(OS_ARCH),NetBSD)
 MDCPUCFG_H = _netbsd.cfg
 endif
 
 ifeq ($(OS_ARCH),HP-UX)
-MDCPUCFG_H = _hpux.cfg
+ifeq ($(USE_64), 1)
+MDCPUCFG_H = _hpux64.cfg
+else
+MDCPUCFG_H = _hpux32.cfg
+endif
 endif
 
 ifeq ($(OS_ARCH),Linux)
 MDCPUCFG_H = _linux.cfg
 endif
 
 ifeq ($(OS_ARCH),OSF1)
 MDCPUCFG_H = _osf1.cfg
--- a/pr/include/md/_aix.h
+++ b/pr/include/md/_aix.h
@@ -49,25 +49,41 @@
 
 #define NEED_TIME_R
 #undef  HAVE_STACK_GROWING_UP
 #undef	HAVE_WEAK_IO_SYMBOLS
 #undef	HAVE_WEAK_MALLOC_SYMBOLS
 #define	HAVE_DLL
 #define	USE_DLFCN
 #define _PR_HAVE_SOCKADDR_LEN
+#define _PR_POLL_AVAILABLE
+#define _PR_USE_POLL
+#define _PR_STAT_HAS_ONLY_ST_ATIME
 
+/* Timer operations */
+#define AIX_TIMERS
+#if defined(AIX_TIMERS)
+extern PRIntervalTime _MD_AixGetInterval(void);
+#define _MD_GET_INTERVAL _MD_AixGetInterval
+
+extern PRIntervalTime _MD_AixIntervalPerSec(void);
+#define _MD_INTERVAL_PER_SEC _MD_AixIntervalPerSec
+
+#else  /* defined(AIX_TIMERS) */
 #define _MD_GET_INTERVAL        _PR_UNIX_GetInterval
 #define _MD_INTERVAL_PER_SEC    _PR_UNIX_TicksPerSecond
+#endif  /* defined(AIX_TIMERS) */
 
 /* The atomic operations */
 #include <sys/atomic_op.h>
 #define _PR_HAVE_ATOMIC_OPS
+#define _PR_HAVE_ATOMIC_CAS
 #define _MD_INIT_ATOMIC()
 #define _MD_ATOMIC_INCREMENT(val)   ((PRInt32)fetch_and_add((atomic_p)val, 1) + 1)
+#define _MD_ATOMIC_ADD(ptr, val)   ((PRInt32)fetch_and_add((atomic_p)ptr, val) + val)
 #define _MD_ATOMIC_DECREMENT(val)   ((PRInt32)fetch_and_add((atomic_p)val, -1) - 1)
 #define _MD_ATOMIC_SET(val, newval) _AIX_AtomicSet(val, newval)
 
 #define USE_SETJMP
 
 #include <setjmp.h>
 
 #define _MD_GET_SP(_t)				(_t)->md.jb[3]
@@ -133,16 +149,52 @@ struct _MDSemaphore {
 struct _MDCVar {
     PRInt8 notused;
 };
 
 struct _MDSegment {
     PRInt8 notused;
 };
 
+/*
+ * md-specific cpu structure field
+ */
+#define _PR_MD_MAX_OSFD FD_SETSIZE
+
+struct _MDCPU_Unix {
+    PRCList ioQ;
+    PRUint32 ioq_timeout;
+    PRInt32 ioq_max_osfd;
+    PRInt32 ioq_osfd_cnt;
+#ifndef _PR_USE_POLL
+    fd_set fd_read_set, fd_write_set, fd_exception_set;
+    PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
+				fd_exception_cnt[_PR_MD_MAX_OSFD];
+#else
+	struct pollfd *ioq_pollfds;
+	int ioq_pollfds_size;
+#endif	/* _PR_USE_POLL */
+};
+
+#define _PR_IOQ(_cpu)			((_cpu)->md.md_unix.ioQ)
+#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
+#define _PR_FD_READ_SET(_cpu)		((_cpu)->md.md_unix.fd_read_set)
+#define _PR_FD_READ_CNT(_cpu)		((_cpu)->md.md_unix.fd_read_cnt)
+#define _PR_FD_WRITE_SET(_cpu)		((_cpu)->md.md_unix.fd_write_set)
+#define _PR_FD_WRITE_CNT(_cpu)		((_cpu)->md.md_unix.fd_write_cnt)
+#define _PR_FD_EXCEPTION_SET(_cpu)	((_cpu)->md.md_unix.fd_exception_set)
+#define _PR_FD_EXCEPTION_CNT(_cpu)	((_cpu)->md.md_unix.fd_exception_cnt)
+#define _PR_IOQ_TIMEOUT(_cpu)		((_cpu)->md.md_unix.ioq_timeout)
+#define _PR_IOQ_MAX_OSFD(_cpu)		((_cpu)->md.md_unix.ioq_max_osfd)
+#define _PR_IOQ_OSFD_CNT(_cpu)		((_cpu)->md.md_unix.ioq_osfd_cnt)
+#define _PR_IOQ_POLLFDS(_cpu)		((_cpu)->md.md_unix.ioq_pollfds)
+#define _PR_IOQ_POLLFDS_SIZE(_cpu)	((_cpu)->md.md_unix.ioq_pollfds_size)
+
+#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)	32
+
 struct _MDCPU {
     struct _MDCPU_Unix md_unix;
 };
 
 #if !defined(_PR_PTHREADS)
 #define _MD_INIT_LOCKS()
 #endif
 
--- a/pr/include/md/_bsdi.h
+++ b/pr/include/md/_bsdi.h
@@ -32,16 +32,18 @@
 #define _MD_DEFAULT_STACK_SIZE	65536L
 #define _MD_MMAP_FLAGS          MAP_PRIVATE
 
 #define	HAVE_DLL
 #define USE_DLFCN
 #define HAVE_BSD_FLOCK
 #define NEED_TIME_R
 #define _PR_HAVE_SOCKADDR_LEN
+#define _PR_STAT_HAS_ST_ATIMESPEC
+#define _PR_NO_LARGE_FILES
 
 #if defined(BSDI_2)
 #define PROT_NONE 0x0
 #endif
 
 #define USE_SETJMP
 
 #include <setjmp.h>
@@ -105,16 +107,52 @@ struct _MDSemaphore {
 struct _MDCVar {
     PRInt8 notused;
 };
 
 struct _MDSegment {
     PRInt8 notused;
 };
 
+/*
+ * md-specific cpu structure field
+ */
+#define _PR_MD_MAX_OSFD FD_SETSIZE
+
+struct _MDCPU_Unix {
+    PRCList ioQ;
+    PRUint32 ioq_timeout;
+    PRInt32 ioq_max_osfd;
+    PRInt32 ioq_osfd_cnt;
+#ifndef _PR_USE_POLL
+    fd_set fd_read_set, fd_write_set, fd_exception_set;
+    PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
+				fd_exception_cnt[_PR_MD_MAX_OSFD];
+#else
+	struct pollfd *ioq_pollfds;
+	int ioq_pollfds_size;
+#endif	/* _PR_USE_POLL */
+};
+
+#define _PR_IOQ(_cpu)			((_cpu)->md.md_unix.ioQ)
+#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
+#define _PR_FD_READ_SET(_cpu)		((_cpu)->md.md_unix.fd_read_set)
+#define _PR_FD_READ_CNT(_cpu)		((_cpu)->md.md_unix.fd_read_cnt)
+#define _PR_FD_WRITE_SET(_cpu)		((_cpu)->md.md_unix.fd_write_set)
+#define _PR_FD_WRITE_CNT(_cpu)		((_cpu)->md.md_unix.fd_write_cnt)
+#define _PR_FD_EXCEPTION_SET(_cpu)	((_cpu)->md.md_unix.fd_exception_set)
+#define _PR_FD_EXCEPTION_CNT(_cpu)	((_cpu)->md.md_unix.fd_exception_cnt)
+#define _PR_IOQ_TIMEOUT(_cpu)		((_cpu)->md.md_unix.ioq_timeout)
+#define _PR_IOQ_MAX_OSFD(_cpu)		((_cpu)->md.md_unix.ioq_max_osfd)
+#define _PR_IOQ_OSFD_CNT(_cpu)		((_cpu)->md.md_unix.ioq_osfd_cnt)
+#define _PR_IOQ_POLLFDS(_cpu)		((_cpu)->md.md_unix.ioq_pollfds)
+#define _PR_IOQ_POLLFDS_SIZE(_cpu)	((_cpu)->md.md_unix.ioq_pollfds_size)
+
+#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)	32
+
 struct _MDCPU {
 	struct _MDCPU_Unix md_unix;
 };
 
 #define _MD_INIT_LOCKS()
 #define _MD_NEW_LOCK(lock) PR_SUCCESS
 #define _MD_FREE_LOCK(lock)
 #define _MD_LOCK(lock)
--- a/pr/include/md/_darwin.cfg
+++ b/pr/include/md/_darwin.cfg
@@ -22,18 +22,24 @@
 #ifndef XP_UNIX
 #define XP_UNIX
 #endif
 
 #ifndef RHAPOSDY
 #define RHAPOSDY
 #endif
 
+#if defined(i386)
+#undef IS_BIG_ENDIAN
+#define  IS_LITTLE_ENDIAN 1
+#else
 #undef IS_LITTLE_ENDIAN
 #define  IS_BIG_ENDIAN 1
+#endif
+
 #define	HAVE_LONG_LONG
 #undef	HAVE_ALIGNED_DOUBLES
 #define	HAVE_ALIGNED_LONGLONGS 1
 
 #define PR_BYTES_PER_BYTE   1
 #define PR_BYTES_PER_SHORT  2
 #define PR_BYTES_PER_INT    4
 #define PR_BYTES_PER_INT64  8
@@ -48,16 +54,17 @@
 #define PR_BITS_PER_BYTE    8
 #define PR_BITS_PER_SHORT   16
 #define PR_BITS_PER_INT     32
 #define PR_BITS_PER_INT64   64
 #define PR_BITS_PER_LONG    32
 #define PR_BITS_PER_FLOAT   32
 #define PR_BITS_PER_DOUBLE  64
 #define PR_BITS_PER_WORD    32
+#define PR_BITS_PER_DWORD   64
 
 #define PR_BITS_PER_BYTE_LOG2   3
 #define PR_BITS_PER_SHORT_LOG2  4
 #define PR_BITS_PER_INT_LOG2    5
 #define PR_BITS_PER_INT64_LOG2  6
 #define PR_BITS_PER_LONG_LOG2   5
 #define PR_BITS_PER_FLOAT_LOG2  5
 #define PR_BITS_PER_DOUBLE_LOG2 6
@@ -112,8 +119,9 @@
 
 #define BYTES_PER_WORD_LOG2	PR_BYTES_PER_WORD_LOG2
 #define BYTES_PER_DWORD_LOG2	PR_BYTES_PER_DWORD_LOG2
 #define WORDS_PER_DWORD_LOG2	PR_WORDS_PER_DWORD_LOG2
 
 #endif /* NO_NSPR_10_SUPPORT */
 
 #endif /* nspr_cpucfg___ */
+
--- a/pr/include/md/_darwin.h
+++ b/pr/include/md/_darwin.h
@@ -33,45 +33,44 @@
 #define PR_DLL_SUFFIX		".dylib"
 
 #define _PR_VMBASE              0x30000000
 #define _PR_STACK_VMBASE	0x50000000
 #define _MD_DEFAULT_STACK_SIZE	65536L
 #define _MD_MMAP_FLAGS          MAP_PRIVATE
 
 #undef  HAVE_STACK_GROWING_UP
-#define HAVE_WEAK_MALLOC_SYMBOLS
-/* do this until I figure out the rhapsody dll stuff. */
 #define HAVE_DLL
-#define USE_RLD
-#define _PR_HAVE_SOCKADDR_LEN
+#define _PR_HAVE_SOCKADDR_LEN  
+#define _PR_STAT_HAS_ST_ATIMESPEC
+#define _PR_TIMESPEC_HAS_TS_SEC
+#define _PR_NO_LARGE_FILES
 
 #define USE_SETJMP
 
-#ifndef _PR_PTHREADS
+#if !defined(_PR_PTHREADS)
 
 #include <setjmp.h>
 
 #define PR_CONTEXT_TYPE	jmp_buf
 
-#define CONTEXT(_th) ((_th)->md.context)
-
-#define _MD_GET_SP(_th)    (_th)->md.context[0]
-#define PR_NUM_GCREGS	_JBLEN
+#define CONTEXT(_th)       ((_th)->md.context)
+#define _MD_GET_SP(_th)    (((struct sigcontext *) (_th)->md.context)->sc_onstack)
+#define PR_NUM_GCREGS	    _JBLEN
 
 /*
 ** Initialize a thread context to run "_main()" when started
 */
 #define _MD_INIT_CONTEXT(_thread, _sp, _main, status)  \
 {  \
     *status = PR_TRUE;  \
     if (setjmp(CONTEXT(_thread))) {  \
         _main();  \
     }  \
-    _MD_GET_SP(_thread) = (int) ((_sp) - 64); \
+    _MD_GET_SP(_thread) = (unsigned char*) ((_sp) - 64); \
 }
 
 #define _MD_SWITCH_CONTEXT(_thread)  \
     if (!setjmp(CONTEXT(_thread))) {  \
 	(_thread)->md.errcode = errno;  \
 	_PR_Schedule();  \
     }
 
@@ -108,16 +107,52 @@ struct _MDSemaphore {
 struct _MDCVar {
     PRInt8 notused;
 };
 
 struct _MDSegment {
     PRInt8 notused;
 };
 
+/*
+ * md-specific cpu structure field
+ */
+#define _PR_MD_MAX_OSFD FD_SETSIZE
+
+struct _MDCPU_Unix {
+    PRCList ioQ;
+    PRUint32 ioq_timeout;
+    PRInt32 ioq_max_osfd;
+    PRInt32 ioq_osfd_cnt;
+#ifndef _PR_USE_POLL
+    fd_set fd_read_set, fd_write_set, fd_exception_set;
+    PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
+				fd_exception_cnt[_PR_MD_MAX_OSFD];
+#else
+	struct pollfd *ioq_pollfds;
+	int ioq_pollfds_size;
+#endif	/* _PR_USE_POLL */
+};
+
+#define _PR_IOQ(_cpu)			((_cpu)->md.md_unix.ioQ)
+#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
+#define _PR_FD_READ_SET(_cpu)		((_cpu)->md.md_unix.fd_read_set)
+#define _PR_FD_READ_CNT(_cpu)		((_cpu)->md.md_unix.fd_read_cnt)
+#define _PR_FD_WRITE_SET(_cpu)		((_cpu)->md.md_unix.fd_write_set)
+#define _PR_FD_WRITE_CNT(_cpu)		((_cpu)->md.md_unix.fd_write_cnt)
+#define _PR_FD_EXCEPTION_SET(_cpu)	((_cpu)->md.md_unix.fd_exception_set)
+#define _PR_FD_EXCEPTION_CNT(_cpu)	((_cpu)->md.md_unix.fd_exception_cnt)
+#define _PR_IOQ_TIMEOUT(_cpu)		((_cpu)->md.md_unix.ioq_timeout)
+#define _PR_IOQ_MAX_OSFD(_cpu)		((_cpu)->md.md_unix.ioq_max_osfd)
+#define _PR_IOQ_OSFD_CNT(_cpu)		((_cpu)->md.md_unix.ioq_osfd_cnt)
+#define _PR_IOQ_POLLFDS(_cpu)		((_cpu)->md.md_unix.ioq_pollfds)
+#define _PR_IOQ_POLLFDS_SIZE(_cpu)	((_cpu)->md.md_unix.ioq_pollfds_size)
+
+#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)	32
+
 struct _MDCPU {
 	struct _MDCPU_Unix md_unix;
 };
 
 #define _MD_INIT_LOCKS()
 #define _MD_NEW_LOCK(lock) PR_SUCCESS
 #define _MD_FREE_LOCK(lock)
 #define _MD_LOCK(lock)
@@ -144,24 +179,24 @@ extern PRStatus _MD_CREATE_THREAD(
     PRUint32 stackSize);
 extern void _MD_SET_PRIORITY(struct _MDThread *thread, PRUintn newPri);
 extern PRStatus _MD_WAIT(PRThread *, PRIntervalTime timeout);
 extern PRStatus _MD_WAKEUP_WAITER(PRThread *);
 extern void _MD_YIELD(void);
 
 #endif /* ! _PR_PTHREADS */
 
-extern void _MD_EarlyInit(void);
-extern PRIntervalTime _PR_UNIX_GetInterval(void);
-extern PRIntervalTime _PR_UNIX_TicksPerSecond(void);
+#define _MD_EARLY_INIT          _MD_EarlyInit
+#define _MD_FINAL_INIT			_PR_UnixInit
+#define _MD_GET_INTERVAL        _PR_UNIX_GetInterval
+#define _MD_INTERVAL_PER_SEC    _PR_UNIX_TicksPerSecond
 
-#define _MD_EARLY_INIT                  _MD_EarlyInit
-#define _MD_FINAL_INIT			_PR_UnixInit
-#define _MD_GET_INTERVAL                  _PR_UNIX_GetInterval
-#define _MD_INTERVAL_PER_SEC              _PR_UNIX_TicksPerSecond
+extern void             _MD_EarlyInit(void);
+extern PRIntervalTime   _PR_UNIX_GetInterval(void);
+extern PRIntervalTime   _PR_UNIX_TicksPerSecond(void);
 
 /*
  * We wrapped the select() call.  _MD_SELECT refers to the built-in,
  * unwrapped version.
  */
 #define _MD_SELECT(nfds,r,w,e,tv) syscall(SYS_select,nfds,r,w,e,tv)
 
 /* For writev() */
--- a/pr/include/md/_dgux.cfg
+++ b/pr/include/md/_dgux.cfg
@@ -66,19 +66,16 @@
 #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_FLOAT   4
 #define PR_ALIGN_OF_DOUBLE  4
 #define PR_ALIGN_OF_POINTER 4
 
-#define _PR_USE_POLL
-#define _PR_POLL_AVAILABLE
-
 #ifndef NO_NSPR_10_SUPPORT
 
 #define BYTES_PER_BYTE		PR_BYTES_PER_BYTE
 #define BYTES_PER_SHORT 	PR_BYTES_PER_SHORT
 #define BYTES_PER_INT 		PR_BYTES_PER_INT
 #define BYTES_PER_INT64		PR_BYTES_PER_INT64
 #define BYTES_PER_LONG		PR_BYTES_PER_LONG
 #define BYTES_PER_FLOAT		PR_BYTES_PER_FLOAT
--- a/pr/include/md/_dgux.h
+++ b/pr/include/md/_dgux.h
@@ -39,16 +39,18 @@
 
 #undef  HAVE_STACK_GROWING_UP
 #define HAVE_NETCONFIG
 #define	HAVE_DLL
 #define	USE_DLFCN
 #define NEED_STRFTIME_LOCK
 #define NEED_TIME_R
 #define _PR_NEED_STRCASECMP
+#define _PR_POLL_AVAILABLE
+#define _PR_USE_POLL
 
 #define USE_SETJMP
 
 #include <setjmp.h>
 
 #define _SETJMP setjmp
 #define _LONGJMP longjmp
 #define _PR_CONTEXT_TYPE         jmp_buf
--- a/pr/include/md/_freebsd.h
+++ b/pr/include/md/_freebsd.h
@@ -32,16 +32,18 @@
 #define _PR_STACK_VMBASE	0x50000000
 #define _MD_DEFAULT_STACK_SIZE	65536L
 #define _MD_MMAP_FLAGS          MAP_PRIVATE
 
 #undef  HAVE_STACK_GROWING_UP
 #define HAVE_DLL
 #define USE_DLFCN
 #define _PR_HAVE_SOCKADDR_LEN
+#define _PR_STAT_HAS_ST_ATIMESPEC
+#define _PR_NO_LARGE_FILES
 
 #define USE_SETJMP
 
 #ifndef _PR_PTHREADS
 #include <setjmp.h>
 
 #define PR_CONTEXT_TYPE	sigjmp_buf
 
@@ -101,16 +103,52 @@ struct _MDSemaphore {
 struct _MDCVar {
     PRInt8 notused;
 };
 
 struct _MDSegment {
     PRInt8 notused;
 };
 
+/*
+ * md-specific cpu structure field
+ */
+#define _PR_MD_MAX_OSFD FD_SETSIZE
+
+struct _MDCPU_Unix {
+    PRCList ioQ;
+    PRUint32 ioq_timeout;
+    PRInt32 ioq_max_osfd;
+    PRInt32 ioq_osfd_cnt;
+#ifndef _PR_USE_POLL
+    fd_set fd_read_set, fd_write_set, fd_exception_set;
+    PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
+				fd_exception_cnt[_PR_MD_MAX_OSFD];
+#else
+	struct pollfd *ioq_pollfds;
+	int ioq_pollfds_size;
+#endif	/* _PR_USE_POLL */
+};
+
+#define _PR_IOQ(_cpu)			((_cpu)->md.md_unix.ioQ)
+#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
+#define _PR_FD_READ_SET(_cpu)		((_cpu)->md.md_unix.fd_read_set)
+#define _PR_FD_READ_CNT(_cpu)		((_cpu)->md.md_unix.fd_read_cnt)
+#define _PR_FD_WRITE_SET(_cpu)		((_cpu)->md.md_unix.fd_write_set)
+#define _PR_FD_WRITE_CNT(_cpu)		((_cpu)->md.md_unix.fd_write_cnt)
+#define _PR_FD_EXCEPTION_SET(_cpu)	((_cpu)->md.md_unix.fd_exception_set)
+#define _PR_FD_EXCEPTION_CNT(_cpu)	((_cpu)->md.md_unix.fd_exception_cnt)
+#define _PR_IOQ_TIMEOUT(_cpu)		((_cpu)->md.md_unix.ioq_timeout)
+#define _PR_IOQ_MAX_OSFD(_cpu)		((_cpu)->md.md_unix.ioq_max_osfd)
+#define _PR_IOQ_OSFD_CNT(_cpu)		((_cpu)->md.md_unix.ioq_osfd_cnt)
+#define _PR_IOQ_POLLFDS(_cpu)		((_cpu)->md.md_unix.ioq_pollfds)
+#define _PR_IOQ_POLLFDS_SIZE(_cpu)	((_cpu)->md.md_unix.ioq_pollfds_size)
+
+#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)	32
+
 struct _MDCPU {
 	struct _MDCPU_Unix md_unix;
 };
 
 #define _MD_INIT_LOCKS()
 #define _MD_NEW_LOCK(lock) PR_SUCCESS
 #define _MD_FREE_LOCK(lock)
 #define _MD_LOCK(lock)
deleted file mode 100644
--- a/pr/include/md/_hpux.cfg
+++ /dev/null
@@ -1,121 +0,0 @@
-/* -*- 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.0 (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.
- */
-
-#ifndef nspr_cpucfg___
-#define nspr_cpucfg___
-
-#ifndef XP_UNIX
-#define XP_UNIX
-#endif
-
-#ifndef HPUX
-#define HPUX
-#endif
-
-#undef  IS_LITTLE_ENDIAN
-#define IS_BIG_ENDIAN 1
-
-#define PR_BYTES_PER_BYTE   1
-#define PR_BYTES_PER_SHORT  2
-#define PR_BYTES_PER_INT    4
-#define PR_BYTES_PER_INT64  8
-#define PR_BYTES_PER_LONG   4
-#define PR_BYTES_PER_FLOAT  4
-#define PR_BYTES_PER_DOUBLE 8
-#define PR_BYTES_PER_WORD   4
-#define PR_BYTES_PER_DWORD  8
-
-#define PR_BYTES_PER_WORD_LOG2 2
-#define PR_BYTES_PER_DWORD_LOG2 3
-
-#define PR_BITS_PER_BYTE    8
-#define PR_BITS_PER_SHORT   16
-#define PR_BITS_PER_INT     32
-#define PR_BITS_PER_INT64   64
-#define PR_BITS_PER_LONG    32
-#define PR_BITS_PER_FLOAT   32
-#define PR_BITS_PER_DOUBLE  64
-#define PR_BITS_PER_WORD    32
-
-#define PR_BITS_PER_BYTE_LOG2   3
-#define PR_BITS_PER_SHORT_LOG2  4
-#define PR_BITS_PER_INT_LOG2    5
-#define PR_BITS_PER_INT64_LOG2  6
-#define PR_BITS_PER_LONG_LOG2   5
-#define PR_BITS_PER_FLOAT_LOG2  5
-#define PR_BITS_PER_DOUBLE_LOG2 6
-#define PR_BITS_PER_WORD_LOG2   5
-
-#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_FLOAT   4
-#define PR_ALIGN_OF_DOUBLE  8
-#define PR_ALIGN_OF_POINTER 4
-
-#undef 	HAVE_LONG_LONG
-#define	HAVE_ALIGNED_DOUBLES
-#undef 	HAVE_ALIGNED_LONGLONGS
-
-#ifndef NO_NSPR_10_SUPPORT
-
-#define BYTES_PER_BYTE		PR_BYTES_PER_BYTE
-#define BYTES_PER_SHORT 	PR_BYTES_PER_SHORT
-#define BYTES_PER_INT 		PR_BYTES_PER_INT
-#define BYTES_PER_INT64		PR_BYTES_PER_INT64
-#define BYTES_PER_LONG		PR_BYTES_PER_LONG
-#define BYTES_PER_FLOAT		PR_BYTES_PER_FLOAT
-#define BYTES_PER_DOUBLE	PR_BYTES_PER_DOUBLE
-#define BYTES_PER_WORD		PR_BYTES_PER_WORD
-#define BYTES_PER_DWORD		PR_BYTES_PER_DWORD
-
-#define BITS_PER_BYTE		PR_BITS_PER_BYTE
-#define BITS_PER_SHORT		PR_BITS_PER_SHORT
-#define BITS_PER_INT		PR_BITS_PER_INT
-#define BITS_PER_INT64		PR_BITS_PER_INT64
-#define BITS_PER_LONG		PR_BITS_PER_LONG
-#define BITS_PER_FLOAT		PR_BITS_PER_FLOAT
-#define BITS_PER_DOUBLE		PR_BITS_PER_DOUBLE
-#define BITS_PER_WORD		PR_BITS_PER_WORD
-
-#define BITS_PER_BYTE_LOG2	PR_BITS_PER_BYTE_LOG2
-#define BITS_PER_SHORT_LOG2	PR_BITS_PER_SHORT_LOG2
-#define BITS_PER_INT_LOG2	PR_BITS_PER_INT_LOG2
-#define BITS_PER_INT64_LOG2	PR_BITS_PER_INT64_LOG2
-#define BITS_PER_LONG_LOG2	PR_BITS_PER_LONG_LOG2
-#define BITS_PER_FLOAT_LOG2	PR_BITS_PER_FLOAT_LOG2
-#define BITS_PER_DOUBLE_LOG2 	PR_BITS_PER_DOUBLE_LOG2
-#define BITS_PER_WORD_LOG2	PR_BITS_PER_WORD_LOG2
-
-#define ALIGN_OF_SHORT		PR_ALIGN_OF_SHORT
-#define ALIGN_OF_INT		PR_ALIGN_OF_INT
-#define ALIGN_OF_LONG		PR_ALIGN_OF_LONG
-#define ALIGN_OF_INT64		PR_ALIGN_OF_INT64
-#define ALIGN_OF_FLOAT		PR_ALIGN_OF_FLOAT
-#define ALIGN_OF_DOUBLE		PR_ALIGN_OF_DOUBLE
-#define ALIGN_OF_POINTER	PR_ALIGN_OF_POINTER
-#define ALIGN_OF_WORD		PR_ALIGN_OF_WORD
-
-#define BYTES_PER_WORD_LOG2	PR_BYTES_PER_WORD_LOG2
-#define BYTES_PER_DWORD_LOG2	PR_BYTES_PER_DWORD_LOG2
-#define WORDS_PER_DWORD_LOG2	PR_WORDS_PER_DWORD_LOG2
-
-#endif /* NO_NSPR_10_SUPPORT */
-
-#endif /* nspr_cpucfg___ */
--- a/pr/include/md/_hpux.h
+++ b/pr/include/md/_hpux.h
@@ -38,16 +38,19 @@
 #define HAVE_STACK_GROWING_UP
 #undef	HAVE_WEAK_IO_SYMBOLS
 #undef	HAVE_WEAK_MALLOC_SYMBOLS
 #define	HAVE_DLL
 #define USE_HPSHL
 #ifndef HAVE_STRERROR
 #define HAVE_STRERROR
 #endif
+#define _PR_POLL_AVAILABLE
+#define _PR_USE_POLL
+#define _PR_STAT_HAS_ONLY_ST_ATIME
 
 #undef _PR_HAVE_ATOMIC_OPS
 
 #if !defined(_PR_PTHREADS)
 
 #include <syscall.h>
 #include <setjmp.h>
 
@@ -112,16 +115,52 @@ struct _MDSemaphore {
 struct _MDCVar {
     PRInt8 notused;
 };
 
 struct _MDSegment {
     PRInt8 notused;
 };
 
+/*
+ * md-specific cpu structure field
+ */
+#define _PR_MD_MAX_OSFD FD_SETSIZE
+
+struct _MDCPU_Unix {
+    PRCList ioQ;
+    PRUint32 ioq_timeout;
+    PRInt32 ioq_max_osfd;
+    PRInt32 ioq_osfd_cnt;
+#ifndef _PR_USE_POLL
+    fd_set fd_read_set, fd_write_set, fd_exception_set;
+    PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
+				fd_exception_cnt[_PR_MD_MAX_OSFD];
+#else
+	struct pollfd *ioq_pollfds;
+	int ioq_pollfds_size;
+#endif	/* _PR_USE_POLL */
+};
+
+#define _PR_IOQ(_cpu)			((_cpu)->md.md_unix.ioQ)
+#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
+#define _PR_FD_READ_SET(_cpu)		((_cpu)->md.md_unix.fd_read_set)
+#define _PR_FD_READ_CNT(_cpu)		((_cpu)->md.md_unix.fd_read_cnt)
+#define _PR_FD_WRITE_SET(_cpu)		((_cpu)->md.md_unix.fd_write_set)
+#define _PR_FD_WRITE_CNT(_cpu)		((_cpu)->md.md_unix.fd_write_cnt)
+#define _PR_FD_EXCEPTION_SET(_cpu)	((_cpu)->md.md_unix.fd_exception_set)
+#define _PR_FD_EXCEPTION_CNT(_cpu)	((_cpu)->md.md_unix.fd_exception_cnt)
+#define _PR_IOQ_TIMEOUT(_cpu)		((_cpu)->md.md_unix.ioq_timeout)
+#define _PR_IOQ_MAX_OSFD(_cpu)		((_cpu)->md.md_unix.ioq_max_osfd)
+#define _PR_IOQ_OSFD_CNT(_cpu)		((_cpu)->md.md_unix.ioq_osfd_cnt)
+#define _PR_IOQ_POLLFDS(_cpu)		((_cpu)->md.md_unix.ioq_pollfds)
+#define _PR_IOQ_POLLFDS_SIZE(_cpu)	((_cpu)->md.md_unix.ioq_pollfds_size)
+
+#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)	32
+
 struct _MDCPU {
     struct _MDCPU_Unix md_unix;
 };
 
 #define _MD_INIT_LOCKS()
 #define _MD_NEW_LOCK(lock) PR_SUCCESS
 #define _MD_FREE_LOCK(lock)
 #define _MD_LOCK(lock)
@@ -145,28 +184,34 @@ struct _MDCPU {
 
 #endif  /* !defined(_PR_PTHREADS) */
 
 #if !defined(PTHREADS_USER)
 #define _MD_EARLY_INIT                 	_MD_EarlyInit
 #define _MD_FINAL_INIT					_PR_UnixInit
 #endif 
 
+#if defined(HPUX_LW_TIMER)
+extern void _PR_HPUX_LW_IntervalInit(void);
+extern PRIntervalTime _PR_HPUX_LW_GetInterval(void);
+#define _MD_INTERVAL_INIT                 _PR_HPUX_LW_IntervalInit
+#define _MD_GET_INTERVAL                  _PR_HPUX_LW_GetInterval
+#define _MD_INTERVAL_PER_SEC()            1000
+#else
 #define _MD_GET_INTERVAL                  _PR_UNIX_GetInterval
 #define _MD_INTERVAL_PER_SEC              _PR_UNIX_TicksPerSecond
+#endif
 
 /*
  * We wrapped the select() call.  _MD_SELECT refers to the built-in,
  * unwrapped version.
  */
 #define _MD_SELECT(nfds,r,w,e,tv) syscall(SYS_select,nfds,r,w,e,tv)
 #define _MD_POLL(fds,nfds,timeout) syscall(SYS_poll,fds,nfds,timeout)
 
-extern void _MD_hpux_install_sigfpe_handler(void);
-
 #ifdef HPUX11
 extern void _MD_hpux_map_sendfile_error(int err);
 #if !defined(_PR_PTHREADS)
 extern PRInt32 _PR_HPUXTransmitFile(PRFileDesc *sd, PRFileDesc *fd,
         const void *headers, PRInt32 hlen,
         PRTransmitFileFlags flags, PRIntervalTime timeout);
 #endif /* !_PR_PTHREADS */
 #endif /* HPUX11 */
new file mode 100644
--- /dev/null
+++ b/pr/include/md/_hpux32.cfg
@@ -0,0 +1,121 @@
+/* -*- 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.0 (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.
+ */
+
+#ifndef nspr_cpucfg___
+#define nspr_cpucfg___
+
+#ifndef XP_UNIX
+#define XP_UNIX
+#endif
+
+#ifndef HPUX
+#define HPUX
+#endif
+
+#undef  IS_LITTLE_ENDIAN
+#define IS_BIG_ENDIAN 1
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   4
+#define PR_BYTES_PER_DWORD  8
+
+#define PR_BYTES_PER_WORD_LOG2 2
+#define PR_BYTES_PER_DWORD_LOG2 3
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    32
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    32
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   5
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   5
+
+#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_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  8
+#define PR_ALIGN_OF_POINTER 4
+
+#define	HAVE_LONG_LONG
+#define	HAVE_ALIGNED_DOUBLES
+#define	HAVE_ALIGNED_LONGLONGS
+
+#ifndef NO_NSPR_10_SUPPORT
+
+#define BYTES_PER_BYTE		PR_BYTES_PER_BYTE
+#define BYTES_PER_SHORT 	PR_BYTES_PER_SHORT
+#define BYTES_PER_INT 		PR_BYTES_PER_INT
+#define BYTES_PER_INT64		PR_BYTES_PER_INT64
+#define BYTES_PER_LONG		PR_BYTES_PER_LONG
+#define BYTES_PER_FLOAT		PR_BYTES_PER_FLOAT
+#define BYTES_PER_DOUBLE	PR_BYTES_PER_DOUBLE
+#define BYTES_PER_WORD		PR_BYTES_PER_WORD
+#define BYTES_PER_DWORD		PR_BYTES_PER_DWORD
+
+#define BITS_PER_BYTE		PR_BITS_PER_BYTE
+#define BITS_PER_SHORT		PR_BITS_PER_SHORT
+#define BITS_PER_INT		PR_BITS_PER_INT
+#define BITS_PER_INT64		PR_BITS_PER_INT64
+#define BITS_PER_LONG		PR_BITS_PER_LONG
+#define BITS_PER_FLOAT		PR_BITS_PER_FLOAT
+#define BITS_PER_DOUBLE		PR_BITS_PER_DOUBLE
+#define BITS_PER_WORD		PR_BITS_PER_WORD
+
+#define BITS_PER_BYTE_LOG2	PR_BITS_PER_BYTE_LOG2
+#define BITS_PER_SHORT_LOG2	PR_BITS_PER_SHORT_LOG2
+#define BITS_PER_INT_LOG2	PR_BITS_PER_INT_LOG2
+#define BITS_PER_INT64_LOG2	PR_BITS_PER_INT64_LOG2
+#define BITS_PER_LONG_LOG2	PR_BITS_PER_LONG_LOG2
+#define BITS_PER_FLOAT_LOG2	PR_BITS_PER_FLOAT_LOG2
+#define BITS_PER_DOUBLE_LOG2 	PR_BITS_PER_DOUBLE_LOG2
+#define BITS_PER_WORD_LOG2	PR_BITS_PER_WORD_LOG2
+
+#define ALIGN_OF_SHORT		PR_ALIGN_OF_SHORT
+#define ALIGN_OF_INT		PR_ALIGN_OF_INT
+#define ALIGN_OF_LONG		PR_ALIGN_OF_LONG
+#define ALIGN_OF_INT64		PR_ALIGN_OF_INT64
+#define ALIGN_OF_FLOAT		PR_ALIGN_OF_FLOAT
+#define ALIGN_OF_DOUBLE		PR_ALIGN_OF_DOUBLE
+#define ALIGN_OF_POINTER	PR_ALIGN_OF_POINTER
+#define ALIGN_OF_WORD		PR_ALIGN_OF_WORD
+
+#define BYTES_PER_WORD_LOG2	PR_BYTES_PER_WORD_LOG2
+#define BYTES_PER_DWORD_LOG2	PR_BYTES_PER_DWORD_LOG2
+#define WORDS_PER_DWORD_LOG2	PR_WORDS_PER_DWORD_LOG2
+
+#endif /* NO_NSPR_10_SUPPORT */
+
+#endif /* nspr_cpucfg___ */
new file mode 100644
--- /dev/null
+++ b/pr/include/md/_hpux64.cfg
@@ -0,0 +1,122 @@
+/* -*- 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.0 (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.
+ */
+
+#ifndef nspr_cpucfg___
+#define nspr_cpucfg___
+
+#ifndef XP_UNIX
+#define XP_UNIX
+#endif
+
+#ifndef HPUX
+#define HPUX
+#endif
+
+#undef  IS_LITTLE_ENDIAN
+#define IS_BIG_ENDIAN 1
+#define IS_64
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   8
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   8
+#define PR_BYTES_PER_DWORD  8
+
+#define PR_BYTES_PER_WORD_LOG2 3
+#define PR_BYTES_PER_DWORD_LOG2 3
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    64
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    64
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#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_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
+
+#ifndef NO_NSPR_10_SUPPORT
+
+#define BYTES_PER_BYTE		PR_BYTES_PER_BYTE
+#define BYTES_PER_SHORT 	PR_BYTES_PER_SHORT
+#define BYTES_PER_INT 		PR_BYTES_PER_INT
+#define BYTES_PER_INT64		PR_BYTES_PER_INT64
+#define BYTES_PER_LONG		PR_BYTES_PER_LONG
+#define BYTES_PER_FLOAT		PR_BYTES_PER_FLOAT
+#define BYTES_PER_DOUBLE	PR_BYTES_PER_DOUBLE
+#define BYTES_PER_WORD		PR_BYTES_PER_WORD
+#define BYTES_PER_DWORD		PR_BYTES_PER_DWORD
+
+#define BITS_PER_BYTE		PR_BITS_PER_BYTE
+#define BITS_PER_SHORT		PR_BITS_PER_SHORT
+#define BITS_PER_INT		PR_BITS_PER_INT
+#define BITS_PER_INT64		PR_BITS_PER_INT64
+#define BITS_PER_LONG		PR_BITS_PER_LONG
+#define BITS_PER_FLOAT		PR_BITS_PER_FLOAT
+#define BITS_PER_DOUBLE		PR_BITS_PER_DOUBLE
+#define BITS_PER_WORD		PR_BITS_PER_WORD
+
+#define BITS_PER_BYTE_LOG2	PR_BITS_PER_BYTE_LOG2
+#define BITS_PER_SHORT_LOG2	PR_BITS_PER_SHORT_LOG2
+#define BITS_PER_INT_LOG2	PR_BITS_PER_INT_LOG2
+#define BITS_PER_INT64_LOG2	PR_BITS_PER_INT64_LOG2
+#define BITS_PER_LONG_LOG2	PR_BITS_PER_LONG_LOG2
+#define BITS_PER_FLOAT_LOG2	PR_BITS_PER_FLOAT_LOG2
+#define BITS_PER_DOUBLE_LOG2 	PR_BITS_PER_DOUBLE_LOG2
+#define BITS_PER_WORD_LOG2	PR_BITS_PER_WORD_LOG2
+
+#define ALIGN_OF_SHORT		PR_ALIGN_OF_SHORT
+#define ALIGN_OF_INT		PR_ALIGN_OF_INT
+#define ALIGN_OF_LONG		PR_ALIGN_OF_LONG
+#define ALIGN_OF_INT64		PR_ALIGN_OF_INT64
+#define ALIGN_OF_FLOAT		PR_ALIGN_OF_FLOAT
+#define ALIGN_OF_DOUBLE		PR_ALIGN_OF_DOUBLE
+#define ALIGN_OF_POINTER	PR_ALIGN_OF_POINTER
+#define ALIGN_OF_WORD		PR_ALIGN_OF_WORD
+
+#define BYTES_PER_WORD_LOG2	PR_BYTES_PER_WORD_LOG2
+#define BYTES_PER_DWORD_LOG2	PR_BYTES_PER_DWORD_LOG2
+#define WORDS_PER_DWORD_LOG2	PR_WORDS_PER_DWORD_LOG2
+
+#endif /* NO_NSPR_10_SUPPORT */
+
+#endif /* nspr_cpucfg___ */
deleted file mode 100644
--- a/pr/include/md/_irix.cfg
+++ /dev/null
@@ -1,129 +0,0 @@
-/* -*- 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.0 (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.
- */
-
-#ifndef nspr_cpucfg___
-#define nspr_cpucfg___
-
-#ifndef _SGI_MP_SOURCE
-#define _SGI_MP_SOURCE
-#endif
-
-#ifndef XP_UNIX
-#define XP_UNIX
-#endif
-
-#ifndef IRIX
-#define IRIX
-#endif
-
-#undef  IS_LITTLE_ENDIAN
-#define IS_BIG_ENDIAN 1
-
-#define PR_BYTES_PER_BYTE   1
-#define PR_BYTES_PER_SHORT  2
-#define PR_BYTES_PER_INT    4
-#define PR_BYTES_PER_INT64  8
-#define PR_BYTES_PER_LONG   4
-#define PR_BYTES_PER_FLOAT  4
-#define PR_BYTES_PER_DOUBLE 8
-#define PR_BYTES_PER_WORD   4
-#define PR_BYTES_PER_DWORD  8
-
-#define PR_BITS_PER_BYTE    8
-#define PR_BITS_PER_SHORT   16
-#define PR_BITS_PER_INT     32
-#define PR_BITS_PER_INT64   64
-#define PR_BITS_PER_LONG    32
-#define PR_BITS_PER_FLOAT   32
-#define PR_BITS_PER_DOUBLE  64
-#define PR_BITS_PER_WORD    32
-
-#define PR_BITS_PER_BYTE_LOG2   3
-#define PR_BITS_PER_SHORT_LOG2  4
-#define PR_BITS_PER_INT_LOG2    5
-#define PR_BITS_PER_INT64_LOG2  6
-#define PR_BITS_PER_LONG_LOG2   5
-#define PR_BITS_PER_FLOAT_LOG2  5
-#define PR_BITS_PER_DOUBLE_LOG2 6
-#define PR_BITS_PER_WORD_LOG2   5
-
-#define PR_BYTES_PER_WORD_LOG2  2
-#define PR_BYTES_PER_DWORD_LOG2 3
-
-#define PR_ALIGN_OF_SHORT   2
-#define PR_ALIGN_OF_INT     4
-#define PR_ALIGN_OF_LONG    4
-#define PR_ALIGN_OF_INT64   8
-#define PR_ALIGN_OF_FLOAT   4
-#define PR_ALIGN_OF_DOUBLE  8
-#define PR_ALIGN_OF_POINTER 4
-#define PR_ALIGN_OF_WORD    4
-
-#define HAVE_LONG_LONG
-#define HAVE_ALIGNED_DOUBLES
-#define HAVE_ALIGNED_LONGLONGS
-
-#define _PR_POLL_AVAILABLE
-#define _PR_USE_POLL
-
-#ifndef NO_NSPR_10_SUPPORT
-
-#define BYTES_PER_BYTE		PR_BYTES_PER_BYTE
-#define BYTES_PER_SHORT 	PR_BYTES_PER_SHORT
-#define BYTES_PER_INT 		PR_BYTES_PER_INT
-#define BYTES_PER_INT64		PR_BYTES_PER_INT64
-#define BYTES_PER_LONG		PR_BYTES_PER_LONG
-#define BYTES_PER_FLOAT		PR_BYTES_PER_FLOAT
-#define BYTES_PER_DOUBLE	PR_BYTES_PER_DOUBLE
-#define BYTES_PER_WORD		PR_BYTES_PER_WORD
-#define BYTES_PER_DWORD		PR_BYTES_PER_DWORD
-
-#define BITS_PER_BYTE		PR_BITS_PER_BYTE
-#define BITS_PER_SHORT		PR_BITS_PER_SHORT
-#define BITS_PER_INT		PR_BITS_PER_INT
-#define BITS_PER_INT64		PR_BITS_PER_INT64
-#define BITS_PER_LONG		PR_BITS_PER_LONG
-#define BITS_PER_FLOAT		PR_BITS_PER_FLOAT
-#define BITS_PER_DOUBLE		PR_BITS_PER_DOUBLE
-#define BITS_PER_WORD		PR_BITS_PER_WORD
-
-#define BITS_PER_BYTE_LOG2	PR_BITS_PER_BYTE_LOG2
-#define BITS_PER_SHORT_LOG2	PR_BITS_PER_SHORT_LOG2
-#define BITS_PER_INT_LOG2	PR_BITS_PER_INT_LOG2
-#define BITS_PER_INT64_LOG2	PR_BITS_PER_INT64_LOG2
-#define BITS_PER_LONG_LOG2	PR_BITS_PER_LONG_LOG2
-#define BITS_PER_FLOAT_LOG2	PR_BITS_PER_FLOAT_LOG2
-#define BITS_PER_DOUBLE_LOG2 	PR_BITS_PER_DOUBLE_LOG2
-#define BITS_PER_WORD_LOG2	PR_BITS_PER_WORD_LOG2
-
-#define ALIGN_OF_SHORT		PR_ALIGN_OF_SHORT
-#define ALIGN_OF_INT		PR_ALIGN_OF_INT
-#define ALIGN_OF_LONG		PR_ALIGN_OF_LONG
-#define ALIGN_OF_INT64		PR_ALIGN_OF_INT64
-#define ALIGN_OF_FLOAT		PR_ALIGN_OF_FLOAT
-#define ALIGN_OF_DOUBLE		PR_ALIGN_OF_DOUBLE
-#define ALIGN_OF_POINTER	PR_ALIGN_OF_POINTER
-#define ALIGN_OF_WORD		PR_ALIGN_OF_WORD
-
-#define BYTES_PER_WORD_LOG2	PR_BYTES_PER_WORD_LOG2
-#define BYTES_PER_DWORD_LOG2	PR_BYTES_PER_DWORD_LOG2
-#define WORDS_PER_DWORD_LOG2	PR_WORDS_PER_DWORD_LOG2
-
-#endif /* NO_NSPR_10_SUPPORT */
-
-#endif /* nspr_cpucfg___ */
--- a/pr/include/md/_irix.h
+++ b/pr/include/md/_irix.h
@@ -14,16 +14,23 @@
  * Communications Corporation.  Portions created by Netscape are
  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  * Reserved.
  */
 
 #ifndef nspr_irix_defs_h___
 #define nspr_irix_defs_h___
 
+#define _PR_HAVE_ATOMIC_CAS
+
+/*
+ * MipsPro assembler defines _LANGUAGE_ASSEMBLY
+ */
+#ifndef _LANGUAGE_ASSEMBLY
+
 #include "prclist.h"
 #include "prthread.h"
 #include <sys/ucontext.h>
 
 /*
  * Internal configuration macros
  */
 
@@ -41,41 +48,47 @@
 #define _MD_MIN_STACK_SIZE      16384L
 
 #undef  HAVE_STACK_GROWING_UP
 #define HAVE_WEAK_IO_SYMBOLS
 #define HAVE_WEAK_MALLOC_SYMBOLS
 #define HAVE_DLL
 #define USE_DLFCN
 #define _PR_HAVE_ATOMIC_OPS
+#define _PR_POLL_AVAILABLE
+#define _PR_USE_POLL
+#define _PR_STAT_HAS_ST_ATIM
+#define _PR_HAVE_OFF64_T
+#define HAVE_POINTER_LOCALTIME_R
 
 /* Initialization entry points */
 PR_EXTERN(void) _MD_EarlyInit(void);
 #define _MD_EARLY_INIT _MD_EarlyInit
 
 PR_EXTERN(void) _MD_IrixInit(void);
 #define _MD_FINAL_INIT _MD_IrixInit
 
 #define _MD_INIT_IO()
 
 /* Timer operations */
-PR_EXTERN(PRIntervalTime) _MD_GetInterval(void);
-#define _MD_GET_INTERVAL _MD_GetInterval
+PR_EXTERN(PRIntervalTime) _MD_IrixGetInterval(void);
+#define _MD_GET_INTERVAL _MD_IrixGetInterval
 
-PR_EXTERN(PRIntervalTime) _MD_IntervalPerSec(void);
-#define _MD_INTERVAL_PER_SEC _MD_IntervalPerSec
+PR_EXTERN(PRIntervalTime) _MD_IrixIntervalPerSec(void);
+#define _MD_INTERVAL_PER_SEC _MD_IrixIntervalPerSec
 
 /* GC operations */
 PR_EXTERN(void *) _MD_GetSP(PRThread *thread);
 #define    _MD_GET_SP _MD_GetSP
 
 /* The atomic operations */
 #include <mutex.h>
 #define _MD_INIT_ATOMIC()
 #define _MD_ATOMIC_INCREMENT(val) add_then_test((unsigned long*)val, 1)
+#define _MD_ATOMIC_ADD(ptr, val) add_then_test((unsigned long*)ptr, (unsigned long)val)
 #define _MD_ATOMIC_DECREMENT(val) add_then_test((unsigned long*)val, 0xffffffff)
 #define _MD_ATOMIC_SET(val, newval) test_and_set((unsigned long*)val, newval)
 
 #if defined(_PR_PTHREADS)
 #else /* defined(_PR_PTHREADS) */
 
 /************************************************************************/
 
@@ -102,63 +115,69 @@ struct sproc_private_data {
     struct PRThread *last;
     PRUintn intsOff;
 	int		sproc_pid;
 };
 
 extern char *_nspr_sproc_private;
 
 #define _PR_PRDA() ((struct sproc_private_data *) _nspr_sproc_private)
-#define _MD_CURRENT_THREAD() (_PR_PRDA()->me)
 #define _MD_SET_CURRENT_THREAD(_thread) _PR_PRDA()->me = (_thread)
+#define _MD_THIS_THREAD() (_PR_PRDA()->me)
 #define _MD_LAST_THREAD() (_PR_PRDA()->last)
 #define _MD_SET_LAST_THREAD(_thread) _PR_PRDA()->last = (_thread)
 #define _MD_CURRENT_CPU() (_PR_PRDA()->cpu)
 #define _MD_SET_CURRENT_CPU(_cpu) _PR_PRDA()->cpu = (_cpu)
 #define _MD_SET_INTSOFF(_val) (_PR_PRDA()->intsOff = _val)
 #define _MD_GET_INTSOFF() (_PR_PRDA()->intsOff)
 
 #define _MD_SET_SPROC_PID(_val) (_PR_PRDA()->sproc_pid = _val)
 #define _MD_GET_SPROC_PID() (_PR_PRDA()->sproc_pid)
 
 PR_EXTERN(struct PRThread*) _MD_get_attached_thread(void);
+PR_EXTERN(struct PRThread*) _MD_get_current_thread(void);
 #define _MD_GET_ATTACHED_THREAD()	_MD_get_attached_thread()
+#define _MD_CURRENT_THREAD()	_MD_get_current_thread()
 
 #define _MD_CHECK_FOR_EXIT() {					\
-		if (_pr_irix_exit_now) {			\
+		if (_pr_irix_exit_now) {				\
 			_PR_POST_SEM(_pr_irix_exit_sem);	\
-			exit(0);				\
-		}						\
+			_MD_Wakeup_CPUs();					\
+			_exit(0);							\
+		}										\
 	}
 		
 #define _MD_ATTACH_THREAD(threadp)
 
 #define _MD_SAVE_ERRNO(_thread)			(_thread)->md.errcode = errno;
 #define _MD_RESTORE_ERRNO(_thread)		errno = (_thread)->md.errcode;
 
 extern struct _PRCPU  *_pr_primordialCPU;
 extern usema_t *_pr_irix_exit_sem;
 extern PRInt32 _pr_irix_exit_now;
+extern int _pr_irix_primoridal_cpu_fd[];
+extern PRInt32 _pr_irix_process_exit;
+extern PRInt32 _pr_irix_process_exit_code;
 
 /* Thread operations */
 #define _PR_LOCK_HEAP()	{						\
 			PRIntn _is;					\
 				if (_pr_primordialCPU) {		\
-				if (_PR_MD_CURRENT_THREAD() && 		\
+				if (_MD_GET_ATTACHED_THREAD() && 		\
 					!_PR_IS_NATIVE_THREAD( 		\
-					_PR_MD_CURRENT_THREAD()))	\
+					_MD_GET_ATTACHED_THREAD()))	\
 						_PR_INTSOFF(_is); 	\
 					_PR_LOCK(_pr_heapLock);		\
 				}
 
 #define _PR_UNLOCK_HEAP() 	if (_pr_primordialCPU)	{		\
 					_PR_UNLOCK(_pr_heapLock);	\
-				if (_PR_MD_CURRENT_THREAD() && 		\
+				if (_MD_GET_ATTACHED_THREAD() && 		\
 					!_PR_IS_NATIVE_THREAD( 		\
-					_PR_MD_CURRENT_THREAD()))	\
+					_MD_GET_ATTACHED_THREAD()))	\
 						_PR_INTSON(_is);	\
 				}					\
 			  }
 
 #define _PR_OPEN_POLL_SEM(_sem)  usopenpollsema(_sem, 0666)
 #define _PR_WAIT_SEM(_sem) uspsema(_sem)
 #define _PR_POST_SEM(_sem) usvsema(_sem)
 
@@ -174,27 +193,27 @@ struct _MDLock {
 
 /*
  * disable pre-emption for the LOCAL threads when calling the arena lock
  * routines
  */
 
 #define _PR_LOCK(lock) {						\
 		PRIntn _is;						\
-		PRThread *me = _PR_MD_CURRENT_THREAD();			\
+		PRThread *me = _MD_GET_ATTACHED_THREAD();			\
 		if (me && !_PR_IS_NATIVE_THREAD(me))			\
 			_PR_INTSOFF(_is); 				\
 		ussetlock(lock);					\
 		if (me && !_PR_IS_NATIVE_THREAD(me))			\
 			_PR_FAST_INTSON(_is); 				\
 	}
 
 #define _PR_UNLOCK(lock) {						\
 		PRIntn _is;						\
-		PRThread *me = _PR_MD_CURRENT_THREAD();			\
+		PRThread *me = _MD_GET_ATTACHED_THREAD();			\
 		if (me && !_PR_IS_NATIVE_THREAD(me))			\
 			_PR_INTSOFF(_is); 				\
 		usunsetlock(lock);					\
 		if (me && !_PR_IS_NATIVE_THREAD(me))			\
 			_PR_FAST_INTSON(_is); 				\
 	}
 
 PR_EXTERN(PRStatus) _MD_NEW_LOCK(struct _MDLock *md);
@@ -211,19 +230,16 @@ struct _MDThread {
     usptr_t     *pollsem_arena;
     usema_t     *cvar_pollsem;
     PRInt32     cvar_pollsemfd;
     PRInt32     cvar_pollsem_select;    /* acquire sem by calling select */
     PRInt32     cvar_wait;              /* if 1, thread is waiting on cvar Q */
     PRInt32	id;
     PRInt32	suspending_id;
     int errcode;
-    PRStatus	*creation_status;	/* points to the variable in which
-					 * a newly created child thread is
-					 * to store its creation status */
 };
 
 struct _MDThreadStack {
     PRInt8 notused;
 };
 
 struct _MDSemaphore {
     usema_t *sem;
@@ -232,16 +248,53 @@ struct _MDSemaphore {
 struct _MDCVar {
     ulock_t mdcvar_lock;
 };
 
 struct _MDSegment {
     PRInt8 notused;
 };
 
+/*
+ * md-specific cpu structure field
+ */
+#define _PR_MD_MAX_OSFD FD_SETSIZE
+
+struct _MDCPU_Unix {
+    PRCList ioQ;
+    PRUint32 ioq_timeout;
+    PRInt32 ioq_max_osfd;
+    PRInt32 ioq_osfd_cnt;
+#ifndef _PR_USE_POLL
+    fd_set fd_read_set, fd_write_set, fd_exception_set;
+    PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
+				fd_exception_cnt[_PR_MD_MAX_OSFD];
+#else
+	struct pollfd *ioq_pollfds;
+	int ioq_pollfds_size;
+#endif	/* _PR_USE_POLL */
+};
+
+#define _PR_IOQ(_cpu)			((_cpu)->md.md_unix.ioQ)
+#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
+#define _PR_FD_READ_SET(_cpu)		((_cpu)->md.md_unix.fd_read_set)
+#define _PR_FD_READ_CNT(_cpu)		((_cpu)->md.md_unix.fd_read_cnt)
+#define _PR_FD_WRITE_SET(_cpu)		((_cpu)->md.md_unix.fd_write_set)
+#define _PR_FD_WRITE_CNT(_cpu)		((_cpu)->md.md_unix.fd_write_cnt)
+#define _PR_FD_EXCEPTION_SET(_cpu)	((_cpu)->md.md_unix.fd_exception_set)
+#define _PR_FD_EXCEPTION_CNT(_cpu)	((_cpu)->md.md_unix.fd_exception_cnt)
+#define _PR_IOQ_TIMEOUT(_cpu)		((_cpu)->md.md_unix.ioq_timeout)
+#define _PR_IOQ_MAX_OSFD(_cpu)		((_cpu)->md.md_unix.ioq_max_osfd)
+#define _PR_IOQ_OSFD_CNT(_cpu)		((_cpu)->md.md_unix.ioq_osfd_cnt)
+#define _PR_IOQ_POLLFDS(_cpu)		((_cpu)->md.md_unix.ioq_pollfds)
+#define _PR_IOQ_POLLFDS_SIZE(_cpu)	((_cpu)->md.md_unix.ioq_pollfds_size)
+
+#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)	32
+
+
 struct _MDCPU {
     PRInt32 id;
     PRInt32 suspending_id;
     struct _MDCPU_Unix md_unix;
 };
 
 /*
 ** Initialize the thread context preparing it to execute _main.
@@ -285,19 +338,23 @@ struct _MDCPU {
     PR_BEGIN_MACRO \
     int *jb = (_newThread)->md.jb; \
     _MD_RESTORE_ERRNO(_newThread) \
     _MD_SET_CURRENT_THREAD(_newThread); \
     _newThread->no_sched = 1;		\
     longjmp(jb, 1); \
     PR_END_MACRO
 
-PR_EXTERN(PRStatus) _MD_InitThread(struct PRThread *thread, PRBool wakeup_parent);
+PR_EXTERN(PRStatus) _MD_InitThread(struct PRThread *thread,
+								PRBool wakeup_parent);
+PR_EXTERN(PRStatus) _MD_InitAttachedThread(struct PRThread *thread,
+									PRBool wakeup_parent);
 #define _MD_INIT_THREAD(thread) 			_MD_InitThread(thread, PR_TRUE)
-#define _MD_INIT_ATTACHED_THREAD(thread)	_MD_InitThread(thread, PR_FALSE)
+#define _MD_INIT_ATTACHED_THREAD(thread)		\
+						_MD_InitAttachedThread(thread, PR_FALSE)
 
 PR_EXTERN(void) _MD_ExitThread(struct PRThread *thread);
 #define _MD_EXIT_THREAD _MD_ExitThread
 
 PR_EXTERN(void) _MD_SuspendThread(struct PRThread *thread);
 #define _MD_SUSPEND_THREAD _MD_SuspendThread
 
 PR_EXTERN(void) _MD_ResumeThread(struct PRThread *thread);
@@ -324,16 +381,19 @@ PR_EXTERN(void) _MD_CleanThread(struct P
 #define _MD_YIELD()    sginap(0)
 
 /* The _PR_MD_WAIT_LOCK and _PR_MD_WAKEUP_WAITER functions put to sleep and
  * awaken a thread which is waiting on a lock or cvar.
  */
 PR_EXTERN(PRStatus) _MD_wait(struct PRThread *, PRIntervalTime timeout);
 #define _MD_WAIT _MD_wait
 
+PR_EXTERN(void) _PR_MD_primordial_cpu();
+PR_EXTERN(void) _PR_MD_WAKEUP_PRIMORDIAL_CPU();
+
 PR_EXTERN(PRStatus) _MD_WakeupWaiter(struct PRThread *);
 #define _MD_WAKEUP_WAITER _MD_WakeupWaiter
 
 PR_EXTERN(void ) _MD_exit(PRIntn status);
 #define _MD_EXIT	_MD_exit
 
 #include "prthread.h"
 
@@ -348,16 +408,18 @@ PR_EXTERN(PRStatus) _MD_CreateThread(
                         PRThreadScope scope,
                         PRThreadState state,
                         PRUint32 stackSize);
 #define _MD_CREATE_THREAD _MD_CreateThread
 
 extern void _MD_CleanupBeforeExit(void);
 #define _MD_CLEANUP_BEFORE_EXIT _MD_CleanupBeforeExit
 
+PR_EXTERN(void) _PR_MD_PRE_CLEANUP(PRThread *me);
+
 
 /* The following defines the unwrapped versions of select() and poll(). */
 extern int _select(int nfds, fd_set *readfds, fd_set *writefds,
 	fd_set *exceptfds, struct timeval *timeout);
 #define _MD_SELECT	_select
 
 #include <stropts.h>
 #include <poll.h>
@@ -370,9 +432,11 @@ extern int _poll(struct pollfd *fds, uns
 PR_EXTERN(PRInt32) _MD_GetThreadAffinityMask(PRThread *unused, PRUint32 *mask);
 #define _MD_GETTHREADAFFINITYMASK _MD_GetThreadAffinityMask
 
 PR_EXTERN(void) _MD_InitRunningCPU(struct _PRCPU *cpu);
 #define    _MD_INIT_RUNNING_CPU _MD_InitRunningCPU
 
 #endif  /* defined(_PR_PTHREADS) */
 
+#endif /* _LANGUAGE_ASSEMBLY */
+
 #endif /* nspr_irix_defs_h___ */
new file mode 100644
--- /dev/null
+++ b/pr/include/md/_irix32.cfg
@@ -0,0 +1,128 @@
+/* -*- 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.0 (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.
+ */
+
+#ifndef nspr_cpucfg___
+#define nspr_cpucfg___
+
+#ifndef _SGI_MP_SOURCE
+#define _SGI_MP_SOURCE
+#endif
+
+#ifndef XP_UNIX
+#define XP_UNIX
+#endif
+
+#ifndef IRIX
+#define IRIX
+#endif
+
+#undef  IS_LITTLE_ENDIAN
+#define IS_BIG_ENDIAN 1
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   4
+#define PR_BYTES_PER_DWORD  8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    32
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    32
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   5
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   5
+
+#define PR_BYTES_PER_WORD_LOG2  2
+#define PR_BYTES_PER_DWORD_LOG2 3
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    4
+#define PR_ALIGN_OF_INT64   8
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  8
+#define PR_ALIGN_OF_POINTER 4
+#define PR_ALIGN_OF_WORD    4
+
+#define HAVE_LONG_LONG
+#define HAVE_ALIGNED_DOUBLES
+#define HAVE_ALIGNED_LONGLONGS
+
+#define _PR_POLL_BACKCOMPAT
+
+#ifndef NO_NSPR_10_SUPPORT
+
+#define BYTES_PER_BYTE		PR_BYTES_PER_BYTE
+#define BYTES_PER_SHORT 	PR_BYTES_PER_SHORT
+#define BYTES_PER_INT 		PR_BYTES_PER_INT
+#define BYTES_PER_INT64		PR_BYTES_PER_INT64
+#define BYTES_PER_LONG		PR_BYTES_PER_LONG
+#define BYTES_PER_FLOAT		PR_BYTES_PER_FLOAT
+#define BYTES_PER_DOUBLE	PR_BYTES_PER_DOUBLE
+#define BYTES_PER_WORD		PR_BYTES_PER_WORD
+#define BYTES_PER_DWORD		PR_BYTES_PER_DWORD
+
+#define BITS_PER_BYTE		PR_BITS_PER_BYTE
+#define BITS_PER_SHORT		PR_BITS_PER_SHORT
+#define BITS_PER_INT		PR_BITS_PER_INT
+#define BITS_PER_INT64		PR_BITS_PER_INT64
+#define BITS_PER_LONG		PR_BITS_PER_LONG
+#define BITS_PER_FLOAT		PR_BITS_PER_FLOAT
+#define BITS_PER_DOUBLE		PR_BITS_PER_DOUBLE
+#define BITS_PER_WORD		PR_BITS_PER_WORD
+
+#define BITS_PER_BYTE_LOG2	PR_BITS_PER_BYTE_LOG2
+#define BITS_PER_SHORT_LOG2	PR_BITS_PER_SHORT_LOG2
+#define BITS_PER_INT_LOG2	PR_BITS_PER_INT_LOG2
+#define BITS_PER_INT64_LOG2	PR_BITS_PER_INT64_LOG2
+#define BITS_PER_LONG_LOG2	PR_BITS_PER_LONG_LOG2
+#define BITS_PER_FLOAT_LOG2	PR_BITS_PER_FLOAT_LOG2
+#define BITS_PER_DOUBLE_LOG2 	PR_BITS_PER_DOUBLE_LOG2
+#define BITS_PER_WORD_LOG2	PR_BITS_PER_WORD_LOG2
+
+#define ALIGN_OF_SHORT		PR_ALIGN_OF_SHORT
+#define ALIGN_OF_INT		PR_ALIGN_OF_INT
+#define ALIGN_OF_LONG		PR_ALIGN_OF_LONG
+#define ALIGN_OF_INT64		PR_ALIGN_OF_INT64
+#define ALIGN_OF_FLOAT		PR_ALIGN_OF_FLOAT
+#define ALIGN_OF_DOUBLE		PR_ALIGN_OF_DOUBLE
+#define ALIGN_OF_POINTER	PR_ALIGN_OF_POINTER
+#define ALIGN_OF_WORD		PR_ALIGN_OF_WORD
+
+#define BYTES_PER_WORD_LOG2	PR_BYTES_PER_WORD_LOG2
+#define BYTES_PER_DWORD_LOG2	PR_BYTES_PER_DWORD_LOG2
+#define WORDS_PER_DWORD_LOG2	PR_WORDS_PER_DWORD_LOG2
+
+#endif /* NO_NSPR_10_SUPPORT */
+
+#endif /* nspr_cpucfg___ */
new file mode 100644
--- /dev/null
+++ b/pr/include/md/_irix64.cfg
@@ -0,0 +1,127 @@
+/* -*- 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.0 (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.
+ */
+
+#ifndef nspr_cpucfg___
+#define nspr_cpucfg___
+
+#ifndef _SGI_MP_SOURCE
+#define _SGI_MP_SOURCE
+#endif
+
+#ifndef XP_UNIX
+#define XP_UNIX
+#endif
+
+#ifndef IRIX
+#define IRIX
+#endif
+
+#undef  IS_LITTLE_ENDIAN
+#define IS_BIG_ENDIAN 1
+#define IS_64
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   8
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   8
+#define PR_BYTES_PER_DWORD  8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    64
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    64
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#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_BYTES_PER_WORD_LOG2  3
+#define PR_BYTES_PER_DWORD_LOG2 3
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    4
+#define PR_ALIGN_OF_INT64   8
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  8
+#define PR_ALIGN_OF_POINTER 4
+#define PR_ALIGN_OF_WORD    4
+
+#define HAVE_LONG_LONG
+#define HAVE_ALIGNED_DOUBLES
+#define HAVE_ALIGNED_LONGLONGS
+
+#ifndef NO_NSPR_10_SUPPORT
+
+#define BYTES_PER_BYTE		PR_BYTES_PER_BYTE
+#define BYTES_PER_SHORT 	PR_BYTES_PER_SHORT
+#define BYTES_PER_INT 		PR_BYTES_PER_INT
+#define BYTES_PER_INT64		PR_BYTES_PER_INT64
+#define BYTES_PER_LONG		PR_BYTES_PER_LONG
+#define BYTES_PER_FLOAT		PR_BYTES_PER_FLOAT
+#define BYTES_PER_DOUBLE	PR_BYTES_PER_DOUBLE
+#define BYTES_PER_WORD		PR_BYTES_PER_WORD
+#define BYTES_PER_DWORD		PR_BYTES_PER_DWORD
+
+#define BITS_PER_BYTE		PR_BITS_PER_BYTE
+#define BITS_PER_SHORT		PR_BITS_PER_SHORT
+#define BITS_PER_INT		PR_BITS_PER_INT
+#define BITS_PER_INT64		PR_BITS_PER_INT64
+#define BITS_PER_LONG		PR_BITS_PER_LONG
+#define BITS_PER_FLOAT		PR_BITS_PER_FLOAT
+#define BITS_PER_DOUBLE		PR_BITS_PER_DOUBLE
+#define BITS_PER_WORD		PR_BITS_PER_WORD
+
+#define BITS_PER_BYTE_LOG2	PR_BITS_PER_BYTE_LOG2
+#define BITS_PER_SHORT_LOG2	PR_BITS_PER_SHORT_LOG2
+#define BITS_PER_INT_LOG2	PR_BITS_PER_INT_LOG2
+#define BITS_PER_INT64_LOG2	PR_BITS_PER_INT64_LOG2
+#define BITS_PER_LONG_LOG2	PR_BITS_PER_LONG_LOG2
+#define BITS_PER_FLOAT_LOG2	PR_BITS_PER_FLOAT_LOG2
+#define BITS_PER_DOUBLE_LOG2 	PR_BITS_PER_DOUBLE_LOG2
+#define BITS_PER_WORD_LOG2	PR_BITS_PER_WORD_LOG2
+
+#define ALIGN_OF_SHORT		PR_ALIGN_OF_SHORT
+#define ALIGN_OF_INT		PR_ALIGN_OF_INT
+#define ALIGN_OF_LONG		PR_ALIGN_OF_LONG
+#define ALIGN_OF_INT64		PR_ALIGN_OF_INT64
+#define ALIGN_OF_FLOAT		PR_ALIGN_OF_FLOAT
+#define ALIGN_OF_DOUBLE		PR_ALIGN_OF_DOUBLE
+#define ALIGN_OF_POINTER	PR_ALIGN_OF_POINTER
+#define ALIGN_OF_WORD		PR_ALIGN_OF_WORD
+
+#define BYTES_PER_WORD_LOG2	PR_BYTES_PER_WORD_LOG2
+#define BYTES_PER_DWORD_LOG2	PR_BYTES_PER_DWORD_LOG2
+#define WORDS_PER_DWORD_LOG2	PR_WORDS_PER_DWORD_LOG2
+
+#endif /* NO_NSPR_10_SUPPORT */
+
+#endif /* nspr_cpucfg___ */
--- a/pr/include/md/_linux.h
+++ b/pr/include/md/_linux.h
@@ -59,16 +59,24 @@
 #define HAVE_DLL
 #define USE_DLFCN
 
 #if !defined(MKLINUX) && !defined(NEED_TIME_R)
 #define NEED_TIME_R
 #endif
 
 #define USE_SETJMP
+#define _PR_POLL_AVAILABLE
+#define _PR_USE_POLL
+#define _PR_STAT_HAS_ONLY_ST_ATIME
+#if defined(__alpha)
+#define _PR_HAVE_LARGE_OFF_T
+#else
+#define _PR_NO_LARGE_FILES
+#endif
 
 #ifdef _PR_PTHREADS
 
 extern void _MD_CleanupBeforeExit(void);
 #define _MD_CLEANUP_BEFORE_EXIT _MD_CleanupBeforeExit
 
 #else  /* ! _PR_PTHREADS */
 
@@ -277,16 +285,52 @@ struct _MDSemaphore {
 struct _MDCVar {
     PRInt8 notused;
 };
 
 struct _MDSegment {
     PRInt8 notused;
 };
 
+/*
+ * md-specific cpu structure field
+ */
+#define _PR_MD_MAX_OSFD FD_SETSIZE
+
+struct _MDCPU_Unix {
+    PRCList ioQ;
+    PRUint32 ioq_timeout;
+    PRInt32 ioq_max_osfd;
+    PRInt32 ioq_osfd_cnt;
+#ifndef _PR_USE_POLL
+    fd_set fd_read_set, fd_write_set, fd_exception_set;
+    PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
+				fd_exception_cnt[_PR_MD_MAX_OSFD];
+#else
+	struct pollfd *ioq_pollfds;
+	int ioq_pollfds_size;
+#endif	/* _PR_USE_POLL */
+};
+
+#define _PR_IOQ(_cpu)			((_cpu)->md.md_unix.ioQ)
+#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
+#define _PR_FD_READ_SET(_cpu)		((_cpu)->md.md_unix.fd_read_set)
+#define _PR_FD_READ_CNT(_cpu)		((_cpu)->md.md_unix.fd_read_cnt)
+#define _PR_FD_WRITE_SET(_cpu)		((_cpu)->md.md_unix.fd_write_set)
+#define _PR_FD_WRITE_CNT(_cpu)		((_cpu)->md.md_unix.fd_write_cnt)
+#define _PR_FD_EXCEPTION_SET(_cpu)	((_cpu)->md.md_unix.fd_exception_set)
+#define _PR_FD_EXCEPTION_CNT(_cpu)	((_cpu)->md.md_unix.fd_exception_cnt)
+#define _PR_IOQ_TIMEOUT(_cpu)		((_cpu)->md.md_unix.ioq_timeout)
+#define _PR_IOQ_MAX_OSFD(_cpu)		((_cpu)->md.md_unix.ioq_max_osfd)
+#define _PR_IOQ_OSFD_CNT(_cpu)		((_cpu)->md.md_unix.ioq_osfd_cnt)
+#define _PR_IOQ_POLLFDS(_cpu)		((_cpu)->md.md_unix.ioq_pollfds)
+#define _PR_IOQ_POLLFDS_SIZE(_cpu)	((_cpu)->md.md_unix.ioq_pollfds_size)
+
+#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)	32
+
 struct _MDCPU {
 	struct _MDCPU_Unix md_unix;
 };
 
 #define _MD_INIT_LOCKS()
 #define _MD_NEW_LOCK(lock) PR_SUCCESS
 #define _MD_FREE_LOCK(lock)
 #define _MD_LOCK(lock)
@@ -329,17 +373,17 @@ extern PRIntervalTime _PR_UNIX_TicksPerS
 
 /*
  * We wrapped the select() call.  _MD_SELECT refers to the built-in,
  * unwrapped version.
  */
 #define _MD_SELECT __select
 
 #ifdef _PR_POLL_AVAILABLE
-#include <poll.h>
+#include <sys/poll.h>
 extern int __syscall_poll(struct pollfd *ufds, unsigned long int nfds,
 	int timeout);
 #define _MD_POLL __syscall_poll
 #endif
 
 /* For writev() */
 #include <sys/uio.h>
 
--- a/pr/include/md/_macos.h
+++ b/pr/include/md/_macos.h
@@ -98,16 +98,17 @@ struct _MDFileDesc {
 ** Interrupts Related definitions
 */
 
 #define _MD_START_INTERRUPTS			_MD_StartInterrupts
 #define _MD_STOP_INTERRUPTS	    		_MD_StopInterrupts
 #define _MD_BLOCK_CLOCK_INTERRUPTS()
 #define _MD_UNBLOCK_CLOCK_INTERRUPTS()
 #define _MD_DISABLE_CLOCK_INTERRUPTS()
+#define _MD_ENABLE_CLOCK_INTERRUPTS()
 
 /*
 ** CPU Related definitions
 */
 
 #define _MD_PAUSE_CPU		_MD_PauseCPU
 #define _MD_CLEANUP_BEFORE_EXIT()
 #define _MD_EXIT(status)	exit(status)
@@ -457,30 +458,36 @@ typedef int (*FARPROC)();
 extern long gTimeSlicesOnNonPrimaryThread;
 extern struct PRThread *gPrimaryThread;
 
 typedef short PROSFD;
 
 // Errors not found in the Mac StdCLib
 #define EACCES  		13      	// Permission denied
 #define ENOENT			-43			// No such file or directory
+#define	EMFILE			24			// Too many open files
 #define _OS_INVALID_FD_VALUE -1
 
 #define	STDERR_FILENO	2
 
 #if !defined(MAC_NSPR_STANDALONE)
+#define MAC_PATH_SEPARATOR 				':'
 #define PATH_SEPARATOR 					':'
 #define PATH_SEPARATOR_STR		        ":"
 #define DIRECTORY_SEPARATOR				'/'
 #define DIRECTORY_SEPARATOR_STR			"/"
 #endif
 
 #define UNIX_THIS_DIRECTORY_STR			"./"
 #define UNIX_PARENT_DIRECTORY_STR		"../"
 
+#define MAX_PATH 			512
+#define MAX_MAC_FILENAME	31
+#define MAXPATHLEN			MAX_PATH
+
 
 // Alias a few names
 #define getenv	PR_GetEnv
 #define putenv	_MD_PutEnv
 
 #if defined(MAC_NSPR_STANDALONE)
 typedef unsigned char (*MemoryCacheFlusherProc)(size_t size);
 typedef void (*PreAllocationHookProc)(void);
@@ -522,25 +529,29 @@ extern FILE *_OS_FOPEN(const char *filen
 extern void dprintf(const char *format, ...);
 
 
 // Entry into the memory system's cache flushing
 #if defined(MAC_NSPR_STANDALONE)
 extern PRUint8 CallCacheFlushers(size_t blockSize);
 #endif
 
+enum {
+	kPrivateNSPREventType = 13
+};
+
 #if defined(MAC_NSPR_STANDALONE)
 extern void* reallocSmaller(void* block, size_t newSize);
 #endif
 
 
 /*
 ** PR_GetSystemInfo related definitions
 */
-#define _PR_SI_SYSNAME          "Mac OS"
+#define _PR_SI_SYSNAME          "MacOS"
 #define _PR_SI_ARCHITECTURE     "PowerPC"
 
 /*
  * Memory-mapped files
  */
 
 struct _MDFileMap {
     PRInt8 unused;
--- a/pr/include/md/_ncr.cfg
+++ b/pr/include/md/_ncr.cfg
@@ -66,18 +66,17 @@
 #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_FLOAT   4
 #define PR_ALIGN_OF_DOUBLE  4
 #define PR_ALIGN_OF_POINTER 4
 
-#define _PR_POLL_AVAILABLE
-#define _PR_USE_POLL
+#define _PR_POLL_BACKCOMPAT
 
 #ifndef NO_NSPR_10_SUPPORT
 
 #define BYTES_PER_BYTE		PR_BYTES_PER_BYTE
 #define BYTES_PER_SHORT 	PR_BYTES_PER_SHORT
 #define BYTES_PER_INT 		PR_BYTES_PER_INT
 #define BYTES_PER_INT64		PR_BYTES_PER_INT64
 #define BYTES_PER_LONG		PR_BYTES_PER_LONG
--- a/pr/include/md/_ncr.h
+++ b/pr/include/md/_ncr.h
@@ -40,16 +40,19 @@
 #if !defined (HAVE_STRERROR)
 #define HAVE_STRERROR
 #endif
 
 #ifndef	HAVE_WEAK_IO_SYMBOLS
 #define	HAVE_WEAK_IO_SYMBOLS
 #endif
 
+#define _PR_POLL_AVAILABLE
+#define _PR_USE_POLL
+
 #undef  HAVE_STACK_GROWING_UP
 #define HAVE_NETCONFIG
 #define NEED_STRFTIME_LOCK
 #define NEED_TIME_R
 #define NEED_LOCALTIME_R
 #define NEED_GMTIME_R  
 #define NEED_ASCTIME_R
 #define NEED_STRTOK_R
@@ -119,16 +122,52 @@ struct _MDSemaphore {
 struct _MDCVar {
     PRInt8 notused;
 };
 
 struct _MDSegment {
     PRInt8 notused;
 };
 
+/*
+ * md-specific cpu structure field
+ */
+#define _PR_MD_MAX_OSFD FD_SETSIZE
+
+struct _MDCPU_Unix {
+    PRCList ioQ;
+    PRUint32 ioq_timeout;
+    PRInt32 ioq_max_osfd;
+    PRInt32 ioq_osfd_cnt;
+#ifndef _PR_USE_POLL
+    fd_set fd_read_set, fd_write_set, fd_exception_set;
+    PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
+				fd_exception_cnt[_PR_MD_MAX_OSFD];
+#else
+	struct pollfd *ioq_pollfds;
+	int ioq_pollfds_size;
+#endif	/* _PR_USE_POLL */
+};
+
+#define _PR_IOQ(_cpu)			((_cpu)->md.md_unix.ioQ)
+#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
+#define _PR_FD_READ_SET(_cpu)		((_cpu)->md.md_unix.fd_read_set)
+#define _PR_FD_READ_CNT(_cpu)		((_cpu)->md.md_unix.fd_read_cnt)
+#define _PR_FD_WRITE_SET(_cpu)		((_cpu)->md.md_unix.fd_write_set)
+#define _PR_FD_WRITE_CNT(_cpu)		((_cpu)->md.md_unix.fd_write_cnt)
+#define _PR_FD_EXCEPTION_SET(_cpu)	((_cpu)->md.md_unix.fd_exception_set)
+#define _PR_FD_EXCEPTION_CNT(_cpu)	((_cpu)->md.md_unix.fd_exception_cnt)
+#define _PR_IOQ_TIMEOUT(_cpu)		((_cpu)->md.md_unix.ioq_timeout)
+#define _PR_IOQ_MAX_OSFD(_cpu)		((_cpu)->md.md_unix.ioq_max_osfd)
+#define _PR_IOQ_OSFD_CNT(_cpu)		((_cpu)->md.md_unix.ioq_osfd_cnt)
+#define _PR_IOQ_POLLFDS(_cpu)		((_cpu)->md.md_unix.ioq_pollfds)
+#define _PR_IOQ_POLLFDS_SIZE(_cpu)	((_cpu)->md.md_unix.ioq_pollfds_size)
+
+#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)	32
+
 struct _MDCPU {
 	struct _MDCPU_Unix md_unix;
 };
 
 #define _MD_INIT_LOCKS()
 #define _MD_NEW_LOCK(lock) PR_SUCCESS
 #define _MD_FREE_LOCK(lock)
 #define _MD_LOCK(lock)
--- a/pr/include/md/_nec.h
+++ b/pr/include/md/_nec.h
@@ -103,16 +103,52 @@ struct _MDSemaphore {
 struct _MDCVar {
     PRInt8 notused;
 };
 
 struct _MDSegment {
     PRInt8 notused;
 };
 
+/*
+ * md-specific cpu structure field
+ */
+#define _PR_MD_MAX_OSFD FD_SETSIZE
+
+struct _MDCPU_Unix {
+    PRCList ioQ;
+    PRUint32 ioq_timeout;
+    PRInt32 ioq_max_osfd;
+    PRInt32 ioq_osfd_cnt;
+#ifndef _PR_USE_POLL
+    fd_set fd_read_set, fd_write_set, fd_exception_set;
+    PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
+				fd_exception_cnt[_PR_MD_MAX_OSFD];
+#else
+	struct pollfd *ioq_pollfds;
+	int ioq_pollfds_size;
+#endif	/* _PR_USE_POLL */
+};
+
+#define _PR_IOQ(_cpu)			((_cpu)->md.md_unix.ioQ)
+#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
+#define _PR_FD_READ_SET(_cpu)		((_cpu)->md.md_unix.fd_read_set)
+#define _PR_FD_READ_CNT(_cpu)		((_cpu)->md.md_unix.fd_read_cnt)
+#define _PR_FD_WRITE_SET(_cpu)		((_cpu)->md.md_unix.fd_write_set)
+#define _PR_FD_WRITE_CNT(_cpu)		((_cpu)->md.md_unix.fd_write_cnt)
+#define _PR_FD_EXCEPTION_SET(_cpu)	((_cpu)->md.md_unix.fd_exception_set)
+#define _PR_FD_EXCEPTION_CNT(_cpu)	((_cpu)->md.md_unix.fd_exception_cnt)
+#define _PR_IOQ_TIMEOUT(_cpu)		((_cpu)->md.md_unix.ioq_timeout)
+#define _PR_IOQ_MAX_OSFD(_cpu)		((_cpu)->md.md_unix.ioq_max_osfd)
+#define _PR_IOQ_OSFD_CNT(_cpu)		((_cpu)->md.md_unix.ioq_osfd_cnt)
+#define _PR_IOQ_POLLFDS(_cpu)		((_cpu)->md.md_unix.ioq_pollfds)
+#define _PR_IOQ_POLLFDS_SIZE(_cpu)	((_cpu)->md.md_unix.ioq_pollfds_size)
+
+#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)	32
+
 struct _MDCPU {
 	struct _MDCPU_Unix md_unix;
 };
 
 #define _MD_INIT_LOCKS()
 #define _MD_NEW_LOCK(lock) PR_SUCCESS
 #define _MD_FREE_LOCK(lock)
 #define _MD_LOCK(lock)
--- a/pr/include/md/_netbsd.h
+++ b/pr/include/md/_netbsd.h
@@ -122,16 +122,52 @@ struct _MDSemaphore {
 struct _MDCVar {
     PRInt8 notused;
 };
 
 struct _MDSegment {
     PRInt8 notused;
 };
 
+/*
+ * md-specific cpu structure field
+ */
+#define _PR_MD_MAX_OSFD FD_SETSIZE
+
+struct _MDCPU_Unix {
+    PRCList ioQ;
+    PRUint32 ioq_timeout;
+    PRInt32 ioq_max_osfd;
+    PRInt32 ioq_osfd_cnt;
+#ifndef _PR_USE_POLL
+    fd_set fd_read_set, fd_write_set, fd_exception_set;
+    PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
+				fd_exception_cnt[_PR_MD_MAX_OSFD];
+#else
+	struct pollfd *ioq_pollfds;
+	int ioq_pollfds_size;
+#endif	/* _PR_USE_POLL */
+};
+
+#define _PR_IOQ(_cpu)			((_cpu)->md.md_unix.ioQ)
+#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
+#define _PR_FD_READ_SET(_cpu)		((_cpu)->md.md_unix.fd_read_set)
+#define _PR_FD_READ_CNT(_cpu)		((_cpu)->md.md_unix.fd_read_cnt)
+#define _PR_FD_WRITE_SET(_cpu)		((_cpu)->md.md_unix.fd_write_set)
+#define _PR_FD_WRITE_CNT(_cpu)		((_cpu)->md.md_unix.fd_write_cnt)
+#define _PR_FD_EXCEPTION_SET(_cpu)	((_cpu)->md.md_unix.fd_exception_set)
+#define _PR_FD_EXCEPTION_CNT(_cpu)	((_cpu)->md.md_unix.fd_exception_cnt)
+#define _PR_IOQ_TIMEOUT(_cpu)		((_cpu)->md.md_unix.ioq_timeout)
+#define _PR_IOQ_MAX_OSFD(_cpu)		((_cpu)->md.md_unix.ioq_max_osfd)
+#define _PR_IOQ_OSFD_CNT(_cpu)		((_cpu)->md.md_unix.ioq_osfd_cnt)
+#define _PR_IOQ_POLLFDS(_cpu)		((_cpu)->md.md_unix.ioq_pollfds)
+#define _PR_IOQ_POLLFDS_SIZE(_cpu)	((_cpu)->md.md_unix.ioq_pollfds_size)
+
+#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)	32
+
 struct _MDCPU {
     struct _MDCPU_Unix md_unix;
 };
 
 #define _MD_INIT_LOCKS()
 #define _MD_NEW_LOCK(lock) PR_SUCCESS
 #define _MD_FREE_LOCK(lock)
 #define _MD_LOCK(lock)
--- a/pr/include/md/_nspr_pthread.h
+++ b/pr/include/md/_nspr_pthread.h
@@ -114,16 +114,52 @@ struct _MDSemaphore {
 struct _MDCVar {
 	pthread_mutex_t mutex;
 };
 
 struct _MDSegment {
     PRInt8 notused;
 };
 
+/*
+ * md-specific cpu structure field
+ */
+#define _PR_MD_MAX_OSFD FD_SETSIZE
+
+struct _MDCPU_Unix {
+    PRCList ioQ;
+    PRUint32 ioq_timeout;
+    PRInt32 ioq_max_osfd;
+    PRInt32 ioq_osfd_cnt;
+#ifndef _PR_USE_POLL
+    fd_set fd_read_set, fd_write_set, fd_exception_set;
+    PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
+				fd_exception_cnt[_PR_MD_MAX_OSFD];
+#else
+	struct pollfd *ioq_pollfds;
+	int ioq_pollfds_size;
+#endif	/* _PR_USE_POLL */
+};
+
+#define _PR_IOQ(_cpu)			((_cpu)->md.md_unix.ioQ)
+#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
+#define _PR_FD_READ_SET(_cpu)		((_cpu)->md.md_unix.fd_read_set)
+#define _PR_FD_READ_CNT(_cpu)		((_cpu)->md.md_unix.fd_read_cnt)
+#define _PR_FD_WRITE_SET(_cpu)		((_cpu)->md.md_unix.fd_write_set)
+#define _PR_FD_WRITE_CNT(_cpu)		((_cpu)->md.md_unix.fd_write_cnt)
+#define _PR_FD_EXCEPTION_SET(_cpu)	((_cpu)->md.md_unix.fd_exception_set)
+#define _PR_FD_EXCEPTION_CNT(_cpu)	((_cpu)->md.md_unix.fd_exception_cnt)
+#define _PR_IOQ_TIMEOUT(_cpu)		((_cpu)->md.md_unix.ioq_timeout)
+#define _PR_IOQ_MAX_OSFD(_cpu)		((_cpu)->md.md_unix.ioq_max_osfd)
+#define _PR_IOQ_OSFD_CNT(_cpu)		((_cpu)->md.md_unix.ioq_osfd_cnt)
+#define _PR_IOQ_POLLFDS(_cpu)		((_cpu)->md.md_unix.ioq_pollfds)
+#define _PR_IOQ_POLLFDS_SIZE(_cpu)	((_cpu)->md.md_unix.ioq_pollfds_size)
+
+#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)	32
+
 struct _MDCPU {
     jmp_buf 			jb;
 	pthread_t 			pthread;
 	struct _MDCPU_Unix 	md_unix;
 };
 
 /*
 #define _MD_NEW_LOCK(lock) PR_SUCCESS
new file mode 100644
--- /dev/null
+++ b/pr/include/md/_openbsd.cfg
@@ -0,0 +1,262 @@
+/* -*- 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.0 (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.
+ */
+
+#ifndef nspr_cpucfg___
+#define nspr_cpucfg___
+
+#ifndef XP_UNIX
+#define XP_UNIX
+#endif
+
+#ifndef OPENBSD
+#define OPENBSD
+#endif
+
+#if defined(__i386__) || defined(__arm32__)
+
+#define IS_LITTLE_ENDIAN 1
+#undef  IS_BIG_ENDIAN
+#define        HAVE_LONG_LONG
+#undef HAVE_ALIGNED_DOUBLES
+#undef HAVE_ALIGNED_LONGLONGS
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   4
+#define PR_BYTES_PER_DWORD  8
+#define PR_BYTES_PER_WORD_LOG2   2
+#define PR_BYTES_PER_DWORD_LOG2  3
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    32
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    32
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   5
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   5
+
+#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_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  4
+#define PR_ALIGN_OF_POINTER 4
+
+#elif defined(__sparc__)
+
+#undef IS_LITTLE_ENDIAN 1
+#define  IS_BIG_ENDIAN 1
+#define HAVE_LONG_LONG
+#define  HAVE_ALIGNED_DOUBLES
+#define  HAVE_ALIGNED_LONGLONGS
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   4
+#define PR_BYTES_PER_DWORD  8
+#define PR_BYTES_PER_WORD_LOG2   2
+#define PR_BYTES_PER_DWORD_LOG2  3
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    32
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    32
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   5
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   5
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    4
+#define PR_ALIGN_OF_INT64   8
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  8
+#define PR_ALIGN_OF_POINTER 4
+
+#elif defined(__alpha__)
+#define IS_LITTLE_ENDIAN 1
+#undef  IS_BIG_ENDIAN
+#define IS_64
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   8
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   8
+#define PR_BYTES_PER_DWORD  8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    64
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    64
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#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    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 PR_BYTES_PER_WORD_LOG2  3
+#define PR_BYTES_PER_DWORD_LOG2 3
+
+#elif defined(__powerpc__) || defined(__m68k__)
+
+#undef  IS_LITTLE_ENDIAN
+#define IS_BIG_ENDIAN    1
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   4
+#define PR_BYTES_PER_DWORD  8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    32
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    32
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   5
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   5
+
+#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_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  4
+#define PR_ALIGN_OF_POINTER 4
+
+#define PR_BYTES_PER_WORD_LOG2   2
+#define PR_BYTES_PER_DWORD_LOG2  3
+
+#else
+
+#error Must define constants for type sizes here.
+
+#endif
+
+
+#ifndef NO_NSPR_10_SUPPORT
+
+#define BYTES_PER_BYTE         PR_BYTES_PER_BYTE
+#define BYTES_PER_SHORT        PR_BYTES_PER_SHORT
+#define BYTES_PER_INT          PR_BYTES_PER_INT
+#define BYTES_PER_INT64                PR_BYTES_PER_INT64
+#define BYTES_PER_LONG         PR_BYTES_PER_LONG
+#define BYTES_PER_FLOAT                PR_BYTES_PER_FLOAT
+#define BYTES_PER_DOUBLE       PR_BYTES_PER_DOUBLE
+#define BYTES_PER_WORD         PR_BYTES_PER_WORD
+#define BYTES_PER_DWORD                PR_BYTES_PER_DWORD
+
+#define BITS_PER_BYTE          PR_BITS_PER_BYTE
+#define BITS_PER_SHORT         PR_BITS_PER_SHORT
+#define BITS_PER_INT           PR_BITS_PER_INT
+#define BITS_PER_INT64         PR_BITS_PER_INT64
+#define BITS_PER_LONG          PR_BITS_PER_LONG
+#define BITS_PER_FLOAT         PR_BITS_PER_FLOAT
+#define BITS_PER_DOUBLE                PR_BITS_PER_DOUBLE
+#define BITS_PER_WORD          PR_BITS_PER_WORD
+
+#define BITS_PER_BYTE_LOG2     PR_BITS_PER_BYTE_LOG2
+#define BITS_PER_SHORT_LOG2    PR_BITS_PER_SHORT_LOG2
+#define BITS_PER_INT_LOG2      PR_BITS_PER_INT_LOG2
+#define BITS_PER_INT64_LOG2    PR_BITS_PER_INT64_LOG2
+#define BITS_PER_LONG_LOG2     PR_BITS_PER_LONG_LOG2
+#define BITS_PER_FLOAT_LOG2    PR_BITS_PER_FLOAT_LOG2
+#define BITS_PER_DOUBLE_LOG2   PR_BITS_PER_DOUBLE_LOG2
+#define BITS_PER_WORD_LOG2     PR_BITS_PER_WORD_LOG2
+
+#define ALIGN_OF_SHORT         PR_ALIGN_OF_SHORT
+#define ALIGN_OF_INT           PR_ALIGN_OF_INT
+#define ALIGN_OF_LONG          PR_ALIGN_OF_LONG
+#define ALIGN_OF_INT64         PR_ALIGN_OF_INT64
+#define ALIGN_OF_FLOAT         PR_ALIGN_OF_FLOAT
+#define ALIGN_OF_DOUBLE                PR_ALIGN_OF_DOUBLE
+#define ALIGN_OF_POINTER       PR_ALIGN_OF_POINTER
+#define ALIGN_OF_WORD          PR_ALIGN_OF_WORD
+
+#define BYTES_PER_WORD_LOG2    PR_BYTES_PER_WORD_LOG2
+#define BYTES_PER_DWORD_LOG2   PR_BYTES_PER_DWORD_LOG2
+#define WORDS_PER_DWORD_LOG2   PR_WORDS_PER_DWORD_LOG2
+
+#endif /* NO_NSPR_10_SUPPORT */
+
+#endif /* nspr_cpucfg___ */
new file mode 100644
--- /dev/null
+++ b/pr/include/md/_openbsd.h
@@ -0,0 +1,171 @@
+/* -*- 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.0 (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.
+ */
+
+#ifndef nspr_openbsd_defs_h___
+#define nspr_openbsd_defs_h___
+
+#include <sys/syscall.h>
+
+#define PR_LINKER_ARCH "openbsd"
+#define _PR_SI_SYSNAME  "OpenBSD"
+#if defined(__i386__)
+#define _PR_SI_ARCHITECTURE "x86"
+#elif defined(__alpha__)
+#define _PR_SI_ARCHITECTURE "alpha"
+#elif defined(__m68k__)
+#define _PR_SI_ARCHITECTURE "m68k"
+#elif defined(__powerpc__)
+#define _PR_SI_ARCHITECTURE "powerpc"
+#elif defined(__sparc__)
+#define _PR_SI_ARCHITECTURE "sparc"
+#elif defined(__arm32__)
+#define _PR_SI_ARCHITECTURE "arm32"
+#endif
+
+#define PR_DLL_SUFFIX          ".so.1.0"
+
+#define _PR_VMBASE              0x30000000
+#define _PR_STACK_VMBASE       0x50000000
+#define _MD_DEFAULT_STACK_SIZE 65536L
+#define _MD_MMAP_FLAGS          MAP_PRIVATE
+
+#undef  HAVE_STACK_GROWING_UP
+#define HAVE_DLL
+#define USE_DLFCN
+#define _PR_HAVE_SOCKADDR_LEN
+
+#define USE_SETJMP
+
+#ifndef _PR_PTHREADS
+#include <setjmp.h>
+
+#define PR_CONTEXT_TYPE        sigjmp_buf
+
+#define CONTEXT(_th) ((_th)->md.context)
+
+#if defined(__i386__) || defined(__sparc__) || defined(__m68k__) || defined(__powerpc__)
+#define JB_SP_INDEX 2
+#elif defined(__alpha__)
+#define JB_SP_INDEX 34
+#elif defined(__arm32__)
+/*
+ * On the arm32, the jmpbuf regs underwent a namechange after NetBSD 1.3
+ */
+#ifdef JMPBUF_REG_R13
+#define JB_SP_INDEX JMPBUF_REG_R13
+#else
+#define JB_SP_INDEX _JB_REG_R13
+#endif
+#else
+#error "Need to define SP index in jmp_buf here"
+#endif
+#define _MD_GET_SP(_th)    (_th)->md.context[JB_SP_INDEX]
+
+#define PR_NUM_GCREGS  _JBLEN
+
+/*
+** Initialize a thread context to run "_main()" when started
+*/
+#define _MD_INIT_CONTEXT(_thread, _sp, _main, status)  \
+{  \
+    *status = PR_TRUE;  \
+    if (sigsetjmp(CONTEXT(_thread), 1)) {  \
+        _main();  \
+    }  \
+    _MD_GET_SP(_thread) = (unsigned char*) ((_sp) - 64); \
+}
+
+#define _MD_SWITCH_CONTEXT(_thread)  \
+    if (!sigsetjmp(CONTEXT(_thread), 1)) {  \
+        (_thread)->md.errcode = errno;  \
+        _PR_Schedule();  \
+    }
+
+/*
+** Restore a thread context, saved by _MD_SWITCH_CONTEXT
+*/
+#define _MD_RESTORE_CONTEXT(_thread) \
+{   \
+    errno = (_thread)->md.errcode;  \
+    _MD_SET_CURRENT_THREAD(_thread);  \
+    siglongjmp(CONTEXT(_thread), 1);  \
+}
+
+/* Machine-dependent (MD) data structures */
+
+struct _MDThread {
+    PR_CONTEXT_TYPE context;
+    int id;
+    int errcode;
+};
+
+struct _MDThreadStack {
+    PRInt8 notused;
+};
+
+struct _MDLock {
+    PRInt8 notused;
+};
+
+struct _MDSemaphore {
+    PRInt8 notused;
+};
+
+struct _MDCVar {
+    PRInt8 notused;
+};
+
+struct _MDSegment {
+    PRInt8 notused;
+};
+
+struct _MDCPU {
+    struct _MDCPU_Unix md_unix;
+};
+
+#define _MD_INIT_LOCKS()
+#define _MD_NEW_LOCK(lock) PR_SUCCESS
+#define _MD_FREE_LOCK(lock)
+#define _MD_LOCK(lock)
+#define _MD_UNLOCK(lock)
+#define _MD_INIT_IO()
+#define _MD_IOQ_LOCK()
+#define _MD_IOQ_UNLOCK()
+
+#define _MD_INIT_RUNNING_CPU(cpu)       _MD_unix_init_running_cpu(cpu)
+#define _MD_INIT_THREAD                 _MD_InitializeThread
+#define _MD_EXIT_THREAD(thread)
+#define _MD_SUSPEND_THREAD(thread)      _MD_suspend_thread
+#define _MD_RESUME_THREAD(thread)       _MD_resume_thread
+#define _MD_CLEAN_THREAD(_thread)
+
+#endif /* ! _PR_PTHREADS */
+
+#define _MD_EARLY_INIT                  _MD_EarlyInit
+#define _MD_FINAL_INIT                 _PR_UnixInit
+#define _MD_GET_INTERVAL                  _PR_UNIX_GetInterval
+#define _MD_INTERVAL_PER_SEC              _PR_UNIX_TicksPerSecond
+
+/*
+ * We wrapped the select() call.  _MD_SELECT refers to the built-in,
+ * unwrapped version.
+ */
+#define _MD_SELECT(nfds,r,w,e,tv) syscall(SYS_select,nfds,r,w,e,tv)
+#define _MD_POLL(fds,nfds,timeout) syscall(SYS_poll,fds,nfds,timeout)
+
+#endif /* nspr_openbsd_defs_h___ */
--- a/pr/include/md/_os2.h
+++ b/pr/include/md/_os2.h
@@ -240,16 +240,17 @@ extern PRInt32 _MD_CloseSocket(PRInt32 o
 #define _MD_GETPEERNAME               _PR_MD_GETPEERNAME
 #define _MD_GETSOCKOPT                _PR_MD_GETSOCKOPT
 #define _MD_SETSOCKOPT                _PR_MD_SETSOCKOPT
 #define _MD_SELECT                    select
 #define _MD_FSYNC                     _PR_MD_FSYNC
 
 #define _MD_INIT_ATOMIC               _PR_MD_INIT_ATOMIC
 #define _MD_ATOMIC_INCREMENT(x)       _PR_MD_ATOMIC_INCREMENT(x)
+#define _MD_ATOMIC_ADD(x,y)			  _PR_MD_ATOMIC_ADD(x,y)
 #define _MD_ATOMIC_DECREMENT(x)       _PR_MD_ATOMIC_DECREMENT(x)
 #define _MD_ATOMIC_SET(x,y)           _PR_MD_ATOMIC_SET(x, y)
 
 #define _MD_INIT_IO                   _PR_MD_INIT_IO
 #define _MD_TRANSMITFILE              _PR_MD_TRANSMITFILE
 
 
 /* win95 doesn't have async IO */
@@ -335,16 +336,17 @@ extern PRInt32 _MD_Accept(PRFileDesc *fd
 #define _MD_IOQ_LOCK()                
 #define _MD_IOQ_UNLOCK()              
 
 
 /* --- Initialization stuff --- */
 #define _MD_START_INTERRUPTS()
 #define _MD_STOP_INTERRUPTS()
 #define _MD_DISABLE_CLOCK_INTERRUPTS()
+#define _MD_ENABLE_CLOCK_INTERRUPTS()
 #define _MD_BLOCK_CLOCK_INTERRUPTS()
 #define _MD_UNBLOCK_CLOCK_INTERRUPTS()
 #define _MD_EARLY_INIT                _PR_MD_EARLY_INIT
 #define _MD_FINAL_INIT()
 #define _MD_INIT_CPUS()
 #define _MD_INIT_RUNNING_CPU(cpu)
 
 struct PRProcess;
--- a/pr/include/md/_osf1.cfg
+++ b/pr/include/md/_osf1.cfg
@@ -70,18 +70,17 @@
 #define PR_ALIGN_OF_SHORT   2
 #define PR_ALIGN_OF_INT     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 _PR_POLL_AVAILABLE
-#define _PR_USE_POLL
+#define _PR_POLL_BACKCOMPAT
 
 #ifndef NO_NSPR_10_SUPPORT
 
 #define BYTES_PER_BYTE		PR_BYTES_PER_BYTE
 #define BYTES_PER_SHORT 	PR_BYTES_PER_SHORT
 #define BYTES_PER_INT 		PR_BYTES_PER_INT
 #define BYTES_PER_INT64		PR_BYTES_PER_INT64
 #define BYTES_PER_LONG		PR_BYTES_PER_LONG
--- a/pr/include/md/_osf1.h
+++ b/pr/include/md/_osf1.h
@@ -23,35 +23,37 @@
  * Internal configuration macros
  */
 
 #define PR_LINKER_ARCH	"osf"
 #define _PR_SI_SYSNAME	"OSF"
 #define _PR_SI_ARCHITECTURE "alpha"
 #define PR_DLL_SUFFIX		".so"
 
-#define _PR_VMBASE		0x30000000
-#define _PR_STACK_VMBASE	0x50000000
-#define _MD_DEFAULT_STACK_SIZE	131072L
-/*
- * OSF1 needs the MAP_FIXED flag to ensure that mmap returns a pointer
- * with the upper 32 bits zero.  This is because Java sticks a pointer
- * into an int.
- */
-#define _MD_MMAP_FLAGS          MAP_PRIVATE|MAP_FIXED
+#define _PR_VMBASE              0x30000000
+#define _PR_STACK_VMBASE        0x50000000
+#define _MD_DEFAULT_STACK_SIZE  131072L
+#define _MD_MMAP_FLAGS          MAP_PRIVATE
 
 #undef  HAVE_STACK_GROWING_UP
 #undef 	HAVE_WEAK_IO_SYMBOLS
 #undef 	HAVE_WEAK_MALLOC_SYMBOLS
 #define HAVE_DLL
 #define HAVE_BSD_FLOCK
 
 #define NEED_TIME_R
 #define USE_DLFCN
 
+#define _PR_HAVE_ATOMIC_OPS
+#define _PR_HAVE_ATOMIC_CAS
+#define _PR_POLL_AVAILABLE
+#define _PR_USE_POLL
+#define _PR_STAT_HAS_ONLY_ST_ATIME
+#define _PR_HAVE_LARGE_OFF_T
+
 #define USE_SETJMP
 
 #include <setjmp.h>
 
 /*
  * A jmp_buf is actually a struct sigcontext.  The sc_sp field of
  * struct sigcontext is the stack pointer.
  */
@@ -111,16 +113,52 @@ struct _MDSemaphore {
 struct _MDCVar {
     PRInt8 notused;
 };
 
 struct _MDSegment {
     PRInt8 notused;
 };
 
+/*
+ * md-specific cpu structure field
+ */
+#define _PR_MD_MAX_OSFD FD_SETSIZE
+
+struct _MDCPU_Unix {
+    PRCList ioQ;
+    PRUint32 ioq_timeout;
+    PRInt32 ioq_max_osfd;
+    PRInt32 ioq_osfd_cnt;
+#ifndef _PR_USE_POLL
+    fd_set fd_read_set, fd_write_set, fd_exception_set;
+    PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
+				fd_exception_cnt[_PR_MD_MAX_OSFD];
+#else
+	struct pollfd *ioq_pollfds;
+	int ioq_pollfds_size;
+#endif	/* _PR_USE_POLL */
+};
+
+#define _PR_IOQ(_cpu)			((_cpu)->md.md_unix.ioQ)
+#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
+#define _PR_FD_READ_SET(_cpu)		((_cpu)->md.md_unix.fd_read_set)
+#define _PR_FD_READ_CNT(_cpu)		((_cpu)->md.md_unix.fd_read_cnt)
+#define _PR_FD_WRITE_SET(_cpu)		((_cpu)->md.md_unix.fd_write_set)
+#define _PR_FD_WRITE_CNT(_cpu)		((_cpu)->md.md_unix.fd_write_cnt)
+#define _PR_FD_EXCEPTION_SET(_cpu)	((_cpu)->md.md_unix.fd_exception_set)
+#define _PR_FD_EXCEPTION_CNT(_cpu)	((_cpu)->md.md_unix.fd_exception_cnt)
+#define _PR_IOQ_TIMEOUT(_cpu)		((_cpu)->md.md_unix.ioq_timeout)
+#define _PR_IOQ_MAX_OSFD(_cpu)		((_cpu)->md.md_unix.ioq_max_osfd)
+#define _PR_IOQ_OSFD_CNT(_cpu)		((_cpu)->md.md_unix.ioq_osfd_cnt)
+#define _PR_IOQ_POLLFDS(_cpu)		((_cpu)->md.md_unix.ioq_pollfds)
+#define _PR_IOQ_POLLFDS_SIZE(_cpu)	((_cpu)->md.md_unix.ioq_pollfds_size)
+
+#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)	32
+
 struct _MDCPU {
 	struct _MDCPU_Unix md_unix;
 };
 
 #ifndef _PR_PTHREADS
 #define _MD_INIT_LOCKS()
 #endif
 #define _MD_NEW_LOCK(lock) PR_SUCCESS
@@ -154,20 +192,18 @@ extern int __select (int, fd_set *, fd_s
 
 #include <sys/poll.h>
 #define _MD_POLL __poll
 extern int __poll(struct pollfd filedes[], unsigned int nfds, int timeout);
 
 /*
  * Atomic operations
  */
-
-/* builtins.h is not available for OSF1 V3.2. */
-#ifndef OSF1V3
+#ifdef _PR_HAVE_ATOMIC_OPS
 #include <machine/builtins.h>
-#define _PR_HAVE_ATOMIC_OPS
 #define _MD_INIT_ATOMIC()
 #define _MD_ATOMIC_INCREMENT(val) (__ATOMIC_INCREMENT_LONG(val) + 1)
+#define _MD_ATOMIC_ADD(ptr, val)  (__ATOMIC_ADD_LONG(ptr, val) + val)
 #define _MD_ATOMIC_DECREMENT(val) (__ATOMIC_DECREMENT_LONG(val) - 1)
 #define _MD_ATOMIC_SET(val, newval) __ATOMIC_EXCH_LONG(val, newval)
-#endif /* OSF1V3 */
+#endif /* _PR_HAVE_ATOMIC_OPS */
 
 #endif /* nspr_osf1_defs_h___ */
--- a/pr/include/md/_pth.h
+++ b/pr/include/md/_pth.h
@@ -20,16 +20,17 @@
 #define nspr_pth_defs_h_
 
 /*
 ** Appropriate definitions of entry points not used in a pthreads world
 */
 #define _PR_MD_BLOCK_CLOCK_INTERRUPTS()
 #define _PR_MD_UNBLOCK_CLOCK_INTERRUPTS()
 #define _PR_MD_DISABLE_CLOCK_INTERRUPTS()
+#define _PR_MD_ENABLE_CLOCK_INTERRUPTS()
 
 /* In good standards fashion, the DCE threads (based on posix-4) are not
  * quite the same as newer posix implementations.  These are mostly name
  * changes and small differences, so macros usually do the trick
  */
 #ifdef _PR_DCETHREADS
 #define PTHREAD_MUTEXATTR_INIT        pthread_mutexattr_create
 #define PTHREAD_MUTEXATTR_DESTROY     pthread_mutexattr_delete
@@ -65,17 +66,17 @@
  */
 #if defined(_PR_DCETHREADS)
 #define PTHREAD_ZERO_THR_HANDLE(t)        memset(&(t), 0, sizeof(pthread_t))
 #define PTHREAD_THR_HANDLE_IS_ZERO(t) \
 	(!memcmp(&(t), &pt_zero_tid, sizeof(pthread_t)))
 #define PTHREAD_COPY_THR_HANDLE(st, dt)   (dt) = (st)
 #elif defined(IRIX) || defined(OSF1) || defined(AIX) || defined(SOLARIS) \
 	|| defined(HPUX) || defined(LINUX) || defined(FREEBSD) \
-	|| defined(NETBSD)
+	|| defined(NETBSD) || defined(OPENBSD)
 #define PTHREAD_ZERO_THR_HANDLE(t)        (t) = 0
 #define PTHREAD_THR_HANDLE_IS_ZERO(t)     (t) == 0
 #define PTHREAD_COPY_THR_HANDLE(st, dt)   (dt) = (st)
 #else 
 #error "pthreads is not supported for this architecture"
 #endif
 
 #if defined(_PR_DCETHREADS)
@@ -95,31 +96,16 @@
 #define PTHREAD_KEY_CREATE           pthread_key_create
 #define PTHREAD_ATTR_SETSCHEDPOLICY  pthread_attr_setschedpolicy
 #define PTHREAD_ATTR_GETSTACKSIZE(a, s) pthread_attr_getstacksize(a, s)
 #define PTHREAD_GETSPECIFIC(k, r)    (r) = pthread_getspecific(k)
 #else
 #error "Cannot determine pthread strategy"
 #endif
 
-/*
- * See if we have the privilege to set the scheduling policy and
- * priority of threads.  Returns 0 if privilege is available.
- * Returns EPERM otherwise.
- */
-
-#ifdef AIX
-#define PT_PRIVCHECK()    privcheck(SET_PROC_RAC)
-#elif defined(HPUX) && !defined(_PR_DCETHREADS)
-PR_EXTERN(PRIntn) pt_hpux_privcheck(void);
-#define PT_PRIVCHECK()    pt_hpux_privcheck()
-#else
-#define PT_PRIVCHECK()    0
-#endif  /* AIX */
-
 #if defined(_PR_DCETHREADS)
 #define PTHREAD_EXPLICIT_SCHED      PTHREAD_DEFAULT_SCHED
 #endif
 
 /*
  * pthread_mutex_trylock returns different values in DCE threads and
  * pthreads.
  */
@@ -131,25 +117,25 @@ PR_EXTERN(PRIntn) pt_hpux_privcheck(void
 #define PT_TRYLOCK_BUSY    EBUSY
 #endif
 
 /*
  * These platforms don't have pthread_atfork()
  */
 #if defined(_PR_DCETHREADS) || defined(FREEBSD) \
 	|| (defined(LINUX) && defined(__alpha)) \
-	|| defined(NETBSD)
+	|| defined(NETBSD) || defined(OPENBSD)
 #define PT_NO_ATFORK
 #endif
 
 /*
  * These platforms don't have sigtimedwait()
  */
 #if (defined(AIX) && !defined(AIX4_3)) || defined(LINUX) \
-	|| defined(FREEBSD) || defined(NETBSD)
+	|| defined(FREEBSD) || defined(NETBSD) || defined(OPENBSD)
 #define PT_NO_SIGTIMEDWAIT
 #endif
 
 #if defined(OSF1)
 #define PT_PRIO_MIN            PRI_OTHER_MIN
 #define PT_PRIO_MAX            PRI_OTHER_MAX
 #elif defined(IRIX)
 #include <sys/sched.h>
@@ -181,47 +167,50 @@ PR_EXTERN(PRIntn) pt_hpux_privcheck(void
 /*
  * Solaris doesn't seem to have macros for the min/max priorities.
  * The range of 0-127 is mentioned in the pthread_setschedparam(3T)
  * man pages, and pthread_setschedparam indeed allows 0-127.  However,
  * pthread_attr_setschedparam does not allow 0; it allows 1-127.
  */
 #define PT_PRIO_MIN            1
 #define PT_PRIO_MAX            127
-#elif defined(FREEBSD) || defined(NETBSD) /* XXX */
+#elif defined(FREEBSD) || defined(NETBSD) || defined(OPENBSD) /* XXX */
 #define PT_PRIO_MIN            0
 #define PT_PRIO_MAX            126
 #else
 #error "pthreads is not supported for this architecture"
 #endif
 
-/* Needed for garbage collection -- Look at PR_Suspend/PR_Resume implementation */
-#if defined(OSF1)
+/*
+ * The PTHREAD_YIELD function is called from a signal handler.
+ * Needed for garbage collection -- Look at PR_Suspend/PR_Resume
+ * implementation.
+ */
+#if defined(_PR_DCETHREADS)
+#define PTHREAD_YIELD()            	pthread_yield()
+#elif defined(OSF1)
+/*
+ * sched_yield can't be called from a signal handler.  Must use
+ * the _np version.
+ */
 #define PTHREAD_YIELD()            	pthread_yield_np()
-#elif defined(HPUX10_30) || defined(HPUX11)
-#define PTHREAD_YIELD()            	sched_yield()
-#elif defined(HPUX)
-#define PTHREAD_YIELD()            	pthread_yield()
 #elif defined(AIX)
 extern int (*_PT_aix_yield_fcn)();
 #define PTHREAD_YIELD()			(*_PT_aix_yield_fcn)()
 #elif defined(IRIX)
 #include <time.h>
 #define PTHREAD_YIELD() \
     PR_BEGIN_MACRO               				\
 		struct timespec onemillisec = {0};		\
 		onemillisec.tv_nsec = 1000000L;			\
         nanosleep(&onemillisec,NULL);			\
     PR_END_MACRO
-#elif defined(SOLARIS)
-#define PTHREAD_YIELD()             sched_yield()
-#elif defined(LINUX)
+#elif defined(HPUX) || defined(LINUX) || defined(SOLARIS) \
+	|| defined(FREEBSD) || defined(NETBSD) || defined(OPENBSD)
 #define PTHREAD_YIELD()            	sched_yield()
-#elif defined(FREEBSD) || defined(NETBSD)
-#define PTHREAD_YIELD()                 pthread_yield()
 #else
 #error "Need to define PTHREAD_YIELD for this platform"
 #endif
 
 /*
 ** And when you really wanted hardcore locking w/o any fluff ...
 **
 **          ... and why would you want that????
--- a/pr/include/md/_reliantunix.cfg
+++ b/pr/include/md/_reliantunix.cfg
@@ -71,18 +71,17 @@
 #define PR_ALIGN_OF_INT     4
 #define PR_ALIGN_OF_LONG    4
 #define PR_ALIGN_OF_INT64   8
 #define PR_ALIGN_OF_FLOAT   4
 #define PR_ALIGN_OF_WORD    4
 #define PR_ALIGN_OF_DOUBLE  8
 #define PR_ALIGN_OF_POINTER 4
 
-#define _PR_POLL_AVAILABLE
-#define _PR_USE_POLL
+#define _PR_POLL_BACKCOMPAT
 
 #ifndef NO_NSPR_10_SUPPORT
 
 #define BYTES_PER_BYTE		PR_BYTES_PER_BYTE
 #define BYTES_PER_SHORT 	PR_BYTES_PER_SHORT
 #define BYTES_PER_INT 		PR_BYTES_PER_INT
 #define BYTES_PER_INT64		PR_BYTES_PER_INT64
 #define BYTES_PER_LONG		PR_BYTES_PER_LONG
--- a/pr/include/md/_reliantunix.h
+++ b/pr/include/md/_reliantunix.h
@@ -42,16 +42,18 @@
 #define HAVE_DLL
 #define USE_DLFCN
 #define NEED_STRFTIME_LOCK
 #define NEED_TIME_R
 #define HAVE_NETCONFIG
 #define HAVE_WEAK_IO_SYMBOLS
 #define HAVE_WEAK_MALLOC_SYMBOLS
 #define _PR_RECV_BROKEN /* recv doesn't work on Unix Domain Sockets */
+#define _PR_POLL_AVAILABLE
+#define _PR_USE_POLL
 
 /*
  * Mike Patnode indicated that it is possibly safe now to use context-switching
  * calls that do not change the signal mask, like setjmp vs. sigsetjmp.
  * So we'll use our homegrown, getcontext/setcontext-compatible stuff which 
  * will save us the getcontext/setcontext system calls at each context switch.
  * It already works in FastTrack 2.01, so it should do it here :-)
  *  - chrisk 040497
@@ -104,16 +106,52 @@ struct _MDSemaphore {
 struct _MDCVar {
     PRInt8 notused;
 };
 
 struct _MDSegment {
     PRInt8 notused;
 };
 
+/*
+ * md-specific cpu structure field
+ */
+#define _PR_MD_MAX_OSFD FD_SETSIZE
+
+struct _MDCPU_Unix {
+    PRCList ioQ;
+    PRUint32 ioq_timeout;
+    PRInt32 ioq_max_osfd;
+    PRInt32 ioq_osfd_cnt;
+#ifndef _PR_USE_POLL
+    fd_set fd_read_set, fd_write_set, fd_exception_set;
+    PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
+				fd_exception_cnt[_PR_MD_MAX_OSFD];
+#else
+	struct pollfd *ioq_pollfds;
+	int ioq_pollfds_size;
+#endif	/* _PR_USE_POLL */
+};
+
+#define _PR_IOQ(_cpu)			((_cpu)->md.md_unix.ioQ)
+#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
+#define _PR_FD_READ_SET(_cpu)		((_cpu)->md.md_unix.fd_read_set)
+#define _PR_FD_READ_CNT(_cpu)		((_cpu)->md.md_unix.fd_read_cnt)
+#define _PR_FD_WRITE_SET(_cpu)		((_cpu)->md.md_unix.fd_write_set)
+#define _PR_FD_WRITE_CNT(_cpu)		((_cpu)->md.md_unix.fd_write_cnt)
+#define _PR_FD_EXCEPTION_SET(_cpu)	((_cpu)->md.md_unix.fd_exception_set)
+#define _PR_FD_EXCEPTION_CNT(_cpu)	((_cpu)->md.md_unix.fd_exception_cnt)
+#define _PR_IOQ_TIMEOUT(_cpu)		((_cpu)->md.md_unix.ioq_timeout)
+#define _PR_IOQ_MAX_OSFD(_cpu)		((_cpu)->md.md_unix.ioq_max_osfd)
+#define _PR_IOQ_OSFD_CNT(_cpu)		((_cpu)->md.md_unix.ioq_osfd_cnt)
+#define _PR_IOQ_POLLFDS(_cpu)		((_cpu)->md.md_unix.ioq_pollfds)
+#define _PR_IOQ_POLLFDS_SIZE(_cpu)	((_cpu)->md.md_unix.ioq_pollfds_size)
+
+#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)	32
+
 struct _MDCPU {
 	struct _MDCPU_Unix md_unix;
 };
 
 #define _MD_INIT_LOCKS()
 #define _MD_NEW_LOCK(lock) PR_SUCCESS
 #define _MD_FREE_LOCK(lock)
 #define _MD_LOCK(lock)
--- a/pr/include/md/_rhapsody.cfg
+++ b/pr/include/md/_rhapsody.cfg
@@ -22,18 +22,24 @@
 #ifndef XP_UNIX
 #define XP_UNIX
 #endif
 
 #ifndef RHAPOSDY
 #define RHAPOSDY
 #endif
 
+#if defined(i386)
+#undef IS_BIG_ENDIAN
+#define  IS_LITTLE_ENDIAN 1
+#else
 #undef IS_LITTLE_ENDIAN
 #define  IS_BIG_ENDIAN 1
+#endif
+
 #define	HAVE_LONG_LONG
 #undef	HAVE_ALIGNED_DOUBLES
 #define	HAVE_ALIGNED_LONGLONGS 1
 
 #define PR_BYTES_PER_BYTE   1
 #define PR_BYTES_PER_SHORT  2
 #define PR_BYTES_PER_INT    4
 #define PR_BYTES_PER_INT64  8
@@ -48,16 +54,17 @@
 #define PR_BITS_PER_BYTE    8
 #define PR_BITS_PER_SHORT   16
 #define PR_BITS_PER_INT     32
 #define PR_BITS_PER_INT64   64
 #define PR_BITS_PER_LONG    32
 #define PR_BITS_PER_FLOAT   32
 #define PR_BITS_PER_DOUBLE  64
 #define PR_BITS_PER_WORD    32
+#define PR_BITS_PER_DWORD   64
 
 #define PR_BITS_PER_BYTE_LOG2   3
 #define PR_BITS_PER_SHORT_LOG2  4
 #define PR_BITS_PER_INT_LOG2    5
 #define PR_BITS_PER_INT64_LOG2  6
 #define PR_BITS_PER_LONG_LOG2   5
 #define PR_BITS_PER_FLOAT_LOG2  5
 #define PR_BITS_PER_DOUBLE_LOG2 6
@@ -112,8 +119,9 @@
 
 #define BYTES_PER_WORD_LOG2	PR_BYTES_PER_WORD_LOG2
 #define BYTES_PER_DWORD_LOG2	PR_BYTES_PER_DWORD_LOG2
 #define WORDS_PER_DWORD_LOG2	PR_WORDS_PER_DWORD_LOG2
 
 #endif /* NO_NSPR_10_SUPPORT */
 
 #endif /* nspr_cpucfg___ */
+
--- a/pr/include/md/_rhapsody.h
+++ b/pr/include/md/_rhapsody.h
@@ -33,45 +33,44 @@
 #define PR_DLL_SUFFIX		".dylib"
 
 #define _PR_VMBASE              0x30000000
 #define _PR_STACK_VMBASE	0x50000000
 #define _MD_DEFAULT_STACK_SIZE	65536L
 #define _MD_MMAP_FLAGS          MAP_PRIVATE
 
 #undef  HAVE_STACK_GROWING_UP
-#define HAVE_WEAK_MALLOC_SYMBOLS
-/* do this until I figure out the rhapsody dll stuff. */
 #define HAVE_DLL
-#define USE_RLD
-#define _PR_HAVE_SOCKADDR_LEN
+#define _PR_HAVE_SOCKADDR_LEN  
+#define _PR_STAT_HAS_ST_ATIMESPEC
+#define _PR_TIMESPEC_HAS_TS_SEC
+#define _PR_NO_LARGE_FILES
 
 #define USE_SETJMP
 
-#ifndef _PR_PTHREADS
+#if !defined(_PR_PTHREADS)
 
 #include <setjmp.h>
 
 #define PR_CONTEXT_TYPE	jmp_buf
 
-#define CONTEXT(_th) ((_th)->md.context)
-
-#define _MD_GET_SP(_th)    (_th)->md.context[0]
-#define PR_NUM_GCREGS	_JBLEN
+#define CONTEXT(_th)       ((_th)->md.context)
+#define _MD_GET_SP(_th)    (((struct sigcontext *) (_th)->md.context)->sc_onstack)
+#define PR_NUM_GCREGS	    _JBLEN
 
 /*
 ** Initialize a thread context to run "_main()" when started
 */
 #define _MD_INIT_CONTEXT(_thread, _sp, _main, status)  \
 {  \
     *status = PR_TRUE;  \
     if (setjmp(CONTEXT(_thread))) {  \
         _main();  \
     }  \
-    _MD_GET_SP(_thread) = (int) ((_sp) - 64); \
+    _MD_GET_SP(_thread) = (unsigned char*) ((_sp) - 64); \
 }
 
 #define _MD_SWITCH_CONTEXT(_thread)  \
     if (!setjmp(CONTEXT(_thread))) {  \
 	(_thread)->md.errcode = errno;  \
 	_PR_Schedule();  \
     }
 
@@ -108,16 +107,52 @@ struct _MDSemaphore {
 struct _MDCVar {
     PRInt8 notused;
 };
 
 struct _MDSegment {
     PRInt8 notused;
 };
 
+/*
+ * md-specific cpu structure field
+ */
+#define _PR_MD_MAX_OSFD FD_SETSIZE
+
+struct _MDCPU_Unix {
+    PRCList ioQ;
+    PRUint32 ioq_timeout;
+    PRInt32 ioq_max_osfd;
+    PRInt32 ioq_osfd_cnt;
+#ifndef _PR_USE_POLL
+    fd_set fd_read_set, fd_write_set, fd_exception_set;
+    PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
+				fd_exception_cnt[_PR_MD_MAX_OSFD];
+#else
+	struct pollfd *ioq_pollfds;
+	int ioq_pollfds_size;
+#endif	/* _PR_USE_POLL */
+};
+
+#define _PR_IOQ(_cpu)			((_cpu)->md.md_unix.ioQ)
+#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
+#define _PR_FD_READ_SET(_cpu)		((_cpu)->md.md_unix.fd_read_set)
+#define _PR_FD_READ_CNT(_cpu)		((_cpu)->md.md_unix.fd_read_cnt)
+#define _PR_FD_WRITE_SET(_cpu)		((_cpu)->md.md_unix.fd_write_set)
+#define _PR_FD_WRITE_CNT(_cpu)		((_cpu)->md.md_unix.fd_write_cnt)
+#define _PR_FD_EXCEPTION_SET(_cpu)	((_cpu)->md.md_unix.fd_exception_set)
+#define _PR_FD_EXCEPTION_CNT(_cpu)	((_cpu)->md.md_unix.fd_exception_cnt)
+#define _PR_IOQ_TIMEOUT(_cpu)		((_cpu)->md.md_unix.ioq_timeout)
+#define _PR_IOQ_MAX_OSFD(_cpu)		((_cpu)->md.md_unix.ioq_max_osfd)
+#define _PR_IOQ_OSFD_CNT(_cpu)		((_cpu)->md.md_unix.ioq_osfd_cnt)
+#define _PR_IOQ_POLLFDS(_cpu)		((_cpu)->md.md_unix.ioq_pollfds)
+#define _PR_IOQ_POLLFDS_SIZE(_cpu)	((_cpu)->md.md_unix.ioq_pollfds_size)
+
+#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)	32
+
 struct _MDCPU {
 	struct _MDCPU_Unix md_unix;
 };
 
 #define _MD_INIT_LOCKS()
 #define _MD_NEW_LOCK(lock) PR_SUCCESS
 #define _MD_FREE_LOCK(lock)
 #define _MD_LOCK(lock)
@@ -144,24 +179,24 @@ extern PRStatus _MD_CREATE_THREAD(
     PRUint32 stackSize);
 extern void _MD_SET_PRIORITY(struct _MDThread *thread, PRUintn newPri);
 extern PRStatus _MD_WAIT(PRThread *, PRIntervalTime timeout);
 extern PRStatus _MD_WAKEUP_WAITER(PRThread *);
 extern void _MD_YIELD(void);
 
 #endif /* ! _PR_PTHREADS */
 
-extern void _MD_EarlyInit(void);
-extern PRIntervalTime _PR_UNIX_GetInterval(void);
-extern PRIntervalTime _PR_UNIX_TicksPerSecond(void);
+#define _MD_EARLY_INIT          _MD_EarlyInit
+#define _MD_FINAL_INIT			_PR_UnixInit
+#define _MD_GET_INTERVAL        _PR_UNIX_GetInterval
+#define _MD_INTERVAL_PER_SEC    _PR_UNIX_TicksPerSecond
 
-#define _MD_EARLY_INIT                  _MD_EarlyInit
-#define _MD_FINAL_INIT			_PR_UnixInit
-#define _MD_GET_INTERVAL                  _PR_UNIX_GetInterval
-#define _MD_INTERVAL_PER_SEC              _PR_UNIX_TicksPerSecond
+extern void             _MD_EarlyInit(void);
+extern PRIntervalTime   _PR_UNIX_GetInterval(void);
+extern PRIntervalTime   _PR_UNIX_TicksPerSecond(void);
 
 /*
  * We wrapped the select() call.  _MD_SELECT refers to the built-in,
  * unwrapped version.
  */
 #define _MD_SELECT(nfds,r,w,e,tv) syscall(SYS_select,nfds,r,w,e,tv)
 
 /* For writev() */
--- a/pr/include/md/_scoos.cfg
+++ b/pr/include/md/_scoos.cfg
@@ -66,18 +66,17 @@
 #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_FLOAT   4
 #define PR_ALIGN_OF_DOUBLE  4
 #define PR_ALIGN_OF_POINTER 4
 
-#define _PR_POLL_AVAILABLE
-#define _PR_USE_POLL
+#define _PR_POLL_BACKCOMPAT
 
 #ifndef NO_NSPR_10_SUPPORT
 
 #define BYTES_PER_BYTE		PR_BYTES_PER_BYTE
 #define BYTES_PER_SHORT 	PR_BYTES_PER_SHORT
 #define BYTES_PER_INT 		PR_BYTES_PER_INT
 #define BYTES_PER_INT64		PR_BYTES_PER_INT64
 #define BYTES_PER_LONG		PR_BYTES_PER_LONG
--- a/pr/include/md/_scoos.h
+++ b/pr/include/md/_scoos.h
@@ -40,16 +40,19 @@
 #if !defined (HAVE_STRERROR)
 #define HAVE_STRERROR
 #endif
 
 #ifndef	HAVE_WEAK_IO_SYMBOLS
 #define	HAVE_WEAK_IO_SYMBOLS
 #endif
 
+#define _PR_POLL_AVAILABLE
+#define _PR_USE_POLL
+
 #define NEED_STRFTIME_LOCK
 #define NEED_TIME_R
 #define _PR_RECV_BROKEN /* recv doesn't work on Unix Domain Sockets */
 
 #define USE_SETJMP
 
 #ifdef _PR_LOCAL_THREADS_ONLY
 #include <setjmp.h>
@@ -108,16 +111,52 @@ struct _MDSemaphore {
 struct _MDCVar {
     PRInt8 notused;
 };
 
 struct _MDSegment {
     PRInt8 notused;
 };
 
+/*
+ * md-specific cpu structure field
+ */
+#define _PR_MD_MAX_OSFD FD_SETSIZE
+
+struct _MDCPU_Unix {
+    PRCList ioQ;
+    PRUint32 ioq_timeout;
+    PRInt32 ioq_max_osfd;
+    PRInt32 ioq_osfd_cnt;
+#ifndef _PR_USE_POLL
+    fd_set fd_read_set, fd_write_set, fd_exception_set;
+    PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
+				fd_exception_cnt[_PR_MD_MAX_OSFD];
+#else
+	struct pollfd *ioq_pollfds;
+	int ioq_pollfds_size;
+#endif	/* _PR_USE_POLL */
+};
+
+#define _PR_IOQ(_cpu)			((_cpu)->md.md_unix.ioQ)
+#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
+#define _PR_FD_READ_SET(_cpu)		((_cpu)->md.md_unix.fd_read_set)
+#define _PR_FD_READ_CNT(_cpu)		((_cpu)->md.md_unix.fd_read_cnt)
+#define _PR_FD_WRITE_SET(_cpu)		((_cpu)->md.md_unix.fd_write_set)
+#define _PR_FD_WRITE_CNT(_cpu)		((_cpu)->md.md_unix.fd_write_cnt)
+#define _PR_FD_EXCEPTION_SET(_cpu)	((_cpu)->md.md_unix.fd_exception_set)
+#define _PR_FD_EXCEPTION_CNT(_cpu)	((_cpu)->md.md_unix.fd_exception_cnt)
+#define _PR_IOQ_TIMEOUT(_cpu)		((_cpu)->md.md_unix.ioq_timeout)
+#define _PR_IOQ_MAX_OSFD(_cpu)		((_cpu)->md.md_unix.ioq_max_osfd)
+#define _PR_IOQ_OSFD_CNT(_cpu)		((_cpu)->md.md_unix.ioq_osfd_cnt)
+#define _PR_IOQ_POLLFDS(_cpu)		((_cpu)->md.md_unix.ioq_pollfds)
+#define _PR_IOQ_POLLFDS_SIZE(_cpu)	((_cpu)->md.md_unix.ioq_pollfds_size)
+
+#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)	32
+
 struct _MDCPU {
     struct _MDCPU_Unix md_unix;
 };
 
 #define _MD_INIT_LOCKS()
 #define _MD_NEW_LOCK(lock) PR_SUCCESS
 #define _MD_FREE_LOCK(lock)
 #define _MD_LOCK(lock)
--- a/pr/include/md/_solaris.h
+++ b/pr/include/md/_solaris.h
@@ -43,32 +43,41 @@
 #define	HAVE_DLL
 #define	USE_DLFCN
 #define NEED_STRFTIME_LOCK
 
 #ifdef _PR_LOCAL_THREADS_ONLY
 #undef _PR_HAVE_ATOMIC_OPS
 #else
 #define _PR_HAVE_ATOMIC_OPS
+#define _PR_HAVE_ATOMIC_CAS
 #endif
 
+#define _PR_POLL_AVAILABLE
+#define _PR_USE_POLL
+#define _PR_STAT_HAS_ST_ATIM
+
+#include "prinrval.h"
 PR_EXTERN(PRIntervalTime) _MD_Solaris_GetInterval(void);
 #define _MD_GET_INTERVAL                  _MD_Solaris_GetInterval
 PR_EXTERN(PRIntervalTime) _MD_Solaris_TicksPerSecond(void);
 #define _MD_INTERVAL_PER_SEC              _MD_Solaris_TicksPerSecond
 
 #if defined(_PR_HAVE_ATOMIC_OPS)
 /*
 ** Atomic Operations
 */
 #define _MD_INIT_ATOMIC()
 
 PR_EXTERN(PRInt32) _MD_AtomicIncrement(PRInt32 *val);
 #define _MD_ATOMIC_INCREMENT _MD_AtomicIncrement
 
+PR_EXTERN(PRInt32) _MD_AtomicAdd(PRInt32 *ptr, PRInt32 val);
+#define _MD_ATOMIC_ADD _MD_AtomicAdd
+
 PR_EXTERN(PRInt32) _MD_AtomicDecrement(PRInt32 *val);
 #define _MD_ATOMIC_DECREMENT _MD_AtomicDecrement
 
 PR_EXTERN(PRInt32) _MD_AtomicSet(PRInt32 *val, PRInt32 newval);
 #define _MD_ATOMIC_SET _MD_AtomicSet
 #endif /* _PR_HAVE_ATOMIC_OPS */
 
 #if defined(_PR_PTHREADS)
@@ -280,16 +289,53 @@ struct _MDThread {
 struct _MDThreadStack {
     PRInt8 notused;
 };
 
 struct _MDSegment {
     PRInt8 notused;
 };
 
+/*
+ * md-specific cpu structure field, common to all Unix platforms
+ */
+#define _PR_MD_MAX_OSFD FD_SETSIZE
+
+struct _MDCPU_Unix {
+    PRCList ioQ;
+    PRUint32 ioq_timeout;
+    PRInt32 ioq_max_osfd;
+    PRInt32 ioq_osfd_cnt;
+#ifndef _PR_USE_POLL
+    fd_set fd_read_set, fd_write_set, fd_exception_set;
+    PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
+				fd_exception_cnt[_PR_MD_MAX_OSFD];
+#else
+	struct pollfd *ioq_pollfds;
+	int ioq_pollfds_size;
+#endif	/* _PR_USE_POLL */
+};
+
+#define _PR_IOQ(_cpu)			((_cpu)->md.md_unix.ioQ)
+#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
+#define _PR_FD_READ_SET(_cpu)		((_cpu)->md.md_unix.fd_read_set)
+#define _PR_FD_READ_CNT(_cpu)		((_cpu)->md.md_unix.fd_read_cnt)
+#define _PR_FD_WRITE_SET(_cpu)		((_cpu)->md.md_unix.fd_write_set)
+#define _PR_FD_WRITE_CNT(_cpu)		((_cpu)->md.md_unix.fd_write_cnt)
+#define _PR_FD_EXCEPTION_SET(_cpu)	((_cpu)->md.md_unix.fd_exception_set)
+#define _PR_FD_EXCEPTION_CNT(_cpu)	((_cpu)->md.md_unix.fd_exception_cnt)
+#define _PR_IOQ_TIMEOUT(_cpu)		((_cpu)->md.md_unix.ioq_timeout)
+#define _PR_IOQ_MAX_OSFD(_cpu)		((_cpu)->md.md_unix.ioq_max_osfd)
+#define _PR_IOQ_OSFD_CNT(_cpu)		((_cpu)->md.md_unix.ioq_osfd_cnt)
+#define _PR_IOQ_POLLFDS(_cpu)		((_cpu)->md.md_unix.ioq_pollfds)
+#define _PR_IOQ_POLLFDS_SIZE(_cpu)	((_cpu)->md.md_unix.ioq_pollfds_size)
+
+#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)	32
+
+
 struct _MDCPU {
 	struct _MDCPU_Unix md_unix;
 };
 
 /* The following defines the unwrapped versions of select() and poll(). */
 extern int _select(int nfds, fd_set *readfds, fd_set *writefds,
 	fd_set *exceptfds, struct timeval *timeout);
 #define _MD_SELECT	_select
@@ -561,16 +607,52 @@ struct _MDThread {
 struct _MDThreadStack {
     PRInt8 notused;
 };
 
 struct _MDSegment {
     PRInt8 notused;
 };
 
+/*
+ * md-specific cpu structure field
+ */
+#define _PR_MD_MAX_OSFD FD_SETSIZE
+
+struct _MDCPU_Unix {
+    PRCList ioQ;
+    PRUint32 ioq_timeout;
+    PRInt32 ioq_max_osfd;
+    PRInt32 ioq_osfd_cnt;
+#ifndef _PR_USE_POLL
+    fd_set fd_read_set, fd_write_set, fd_exception_set;
+    PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
+				fd_exception_cnt[_PR_MD_MAX_OSFD];
+#else
+	struct pollfd *ioq_pollfds;
+	int ioq_pollfds_size;
+#endif	/* _PR_USE_POLL */
+};
+
+#define _PR_IOQ(_cpu)			((_cpu)->md.md_unix.ioQ)
+#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
+#define _PR_FD_READ_SET(_cpu)		((_cpu)->md.md_unix.fd_read_set)
+#define _PR_FD_READ_CNT(_cpu)		((_cpu)->md.md_unix.fd_read_cnt)
+#define _PR_FD_WRITE_SET(_cpu)		((_cpu)->md.md_unix.fd_write_set)
+#define _PR_FD_WRITE_CNT(_cpu)		((_cpu)->md.md_unix.fd_write_cnt)
+#define _PR_FD_EXCEPTION_SET(_cpu)	((_cpu)->md.md_unix.fd_exception_set)
+#define _PR_FD_EXCEPTION_CNT(_cpu)	((_cpu)->md.md_unix.fd_exception_cnt)
+#define _PR_IOQ_TIMEOUT(_cpu)		((_cpu)->md.md_unix.ioq_timeout)
+#define _PR_IOQ_MAX_OSFD(_cpu)		((_cpu)->md.md_unix.ioq_max_osfd)
+#define _PR_IOQ_OSFD_CNT(_cpu)		((_cpu)->md.md_unix.ioq_osfd_cnt)
+#define _PR_IOQ_POLLFDS(_cpu)		((_cpu)->md.md_unix.ioq_pollfds)
+#define _PR_IOQ_POLLFDS_SIZE(_cpu)	((_cpu)->md.md_unix.ioq_pollfds_size)
+
+#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)	32
+
 struct _MDCPU {
 	struct _MDCPU_Unix md_unix;
 };
 
 #ifndef _PR_PTHREADS
 #define _MD_INIT_LOCKS()
 #endif
 #define _MD_NEW_LOCK(lock)				PR_SUCCESS
--- a/pr/include/md/_sony.h
+++ b/pr/include/md/_sony.h
@@ -98,16 +98,52 @@ struct _MDSemaphore {
 struct _MDCVar {
     PRInt8 notused;
 };
 
 struct _MDSegment {
     PRInt8 notused;
 };
 
+/*
+ * md-specific cpu structure field
+ */
+#define _PR_MD_MAX_OSFD FD_SETSIZE
+
+struct _MDCPU_Unix {
+    PRCList ioQ;
+    PRUint32 ioq_timeout;
+    PRInt32 ioq_max_osfd;
+    PRInt32 ioq_osfd_cnt;
+#ifndef _PR_USE_POLL
+    fd_set fd_read_set, fd_write_set, fd_exception_set;
+    PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
+				fd_exception_cnt[_PR_MD_MAX_OSFD];
+#else
+	struct pollfd *ioq_pollfds;
+	int ioq_pollfds_size;
+#endif	/* _PR_USE_POLL */
+};
+
+#define _PR_IOQ(_cpu)			((_cpu)->md.md_unix.ioQ)
+#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
+#define _PR_FD_READ_SET(_cpu)		((_cpu)->md.md_unix.fd_read_set)
+#define _PR_FD_READ_CNT(_cpu)		((_cpu)->md.md_unix.fd_read_cnt)
+#define _PR_FD_WRITE_SET(_cpu)		((_cpu)->md.md_unix.fd_write_set)
+#define _PR_FD_WRITE_CNT(_cpu)		((_cpu)->md.md_unix.fd_write_cnt)
+#define _PR_FD_EXCEPTION_SET(_cpu)	((_cpu)->md.md_unix.fd_exception_set)
+#define _PR_FD_EXCEPTION_CNT(_cpu)	((_cpu)->md.md_unix.fd_exception_cnt)
+#define _PR_IOQ_TIMEOUT(_cpu)		((_cpu)->md.md_unix.ioq_timeout)
+#define _PR_IOQ_MAX_OSFD(_cpu)		((_cpu)->md.md_unix.ioq_max_osfd)
+#define _PR_IOQ_OSFD_CNT(_cpu)		((_cpu)->md.md_unix.ioq_osfd_cnt)
+#define _PR_IOQ_POLLFDS(_cpu)		((_cpu)->md.md_unix.ioq_pollfds)
+#define _PR_IOQ_POLLFDS_SIZE(_cpu)	((_cpu)->md.md_unix.ioq_pollfds_size)
+
+#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)	32
+
 struct _MDCPU {
     struct _MDCPU_Unix md_unix;
 };
 
 #define _MD_INIT_LOCKS()
 #define _MD_NEW_LOCK(lock) PR_SUCCESS
 #define _MD_FREE_LOCK(lock)
 #define _MD_LOCK(lock)
--- a/pr/include/md/_sunos4.h
+++ b/pr/include/md/_sunos4.h
@@ -47,16 +47,18 @@
 #undef  HAVE_STACK_GROWING_UP
 #undef	HAVE_WEAK_IO_SYMBOLS
 #undef	HAVE_WEAK_MALLOC_SYMBOLS
 #define	HAVE_DLL
 #define	USE_DLFCN
 #define NEED_STRFTIME_LOCK
 #define NEED_TIME_R
 #define HAVE_BSD_FLOCK
+#define _PR_NO_LARGE_FILES
+#define _PR_STAT_HAS_ONLY_ST_ATIME
 
 #define _MD_GET_INTERVAL                  _PR_UNIX_GetInterval
 #define _MD_INTERVAL_PER_SEC              _PR_UNIX_TicksPerSecond
 
 #define USE_SETJMP
 
 #include <setjmp.h>
 
@@ -140,16 +142,52 @@ struct _MDSemaphore {
 struct _MDCVar {
     PRInt8 notused;
 };
 
 struct _MDSegment {
     PRInt8 notused;
 };
 
+/*
+ * md-specific cpu structure field
+ */
+#define _PR_MD_MAX_OSFD FD_SETSIZE
+
+struct _MDCPU_Unix {
+    PRCList ioQ;
+    PRUint32 ioq_timeout;
+    PRInt32 ioq_max_osfd;
+    PRInt32 ioq_osfd_cnt;
+#ifndef _PR_USE_POLL
+    fd_set fd_read_set, fd_write_set, fd_exception_set;
+    PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
+				fd_exception_cnt[_PR_MD_MAX_OSFD];
+#else
+	struct pollfd *ioq_pollfds;
+	int ioq_pollfds_size;
+#endif	/* _PR_USE_POLL */
+};
+
+#define _PR_IOQ(_cpu)			((_cpu)->md.md_unix.ioQ)
+#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
+#define _PR_FD_READ_SET(_cpu)		((_cpu)->md.md_unix.fd_read_set)
+#define _PR_FD_READ_CNT(_cpu)		((_cpu)->md.md_unix.fd_read_cnt)
+#define _PR_FD_WRITE_SET(_cpu)		((_cpu)->md.md_unix.fd_write_set)
+#define _PR_FD_WRITE_CNT(_cpu)		((_cpu)->md.md_unix.fd_write_cnt)
+#define _PR_FD_EXCEPTION_SET(_cpu)	((_cpu)->md.md_unix.fd_exception_set)
+#define _PR_FD_EXCEPTION_CNT(_cpu)	((_cpu)->md.md_unix.fd_exception_cnt)
+#define _PR_IOQ_TIMEOUT(_cpu)		((_cpu)->md.md_unix.ioq_timeout)
+#define _PR_IOQ_MAX_OSFD(_cpu)		((_cpu)->md.md_unix.ioq_max_osfd)
+#define _PR_IOQ_OSFD_CNT(_cpu)		((_cpu)->md.md_unix.ioq_osfd_cnt)
+#define _PR_IOQ_POLLFDS(_cpu)		((_cpu)->md.md_unix.ioq_pollfds)
+#define _PR_IOQ_POLLFDS_SIZE(_cpu)	((_cpu)->md.md_unix.ioq_pollfds_size)
+
+#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)	32
+
 struct _MDCPU {
 	struct _MDCPU_Unix md_unix;
 };
 
 #define _MD_INIT_LOCKS()
 #define _MD_NEW_LOCK(lock) PR_SUCCESS
 #define _MD_FREE_LOCK(lock)
 #define _MD_LOCK(lock)
--- a/pr/include/md/_unix_errors.h
+++ b/pr/include/md/_unix_errors.h
@@ -133,16 +133,19 @@ PR_EXTERN(void) _MD_unix_map_gethostname
 #define	_PR_MD_MAP_GETHOSTNAME_ERROR	_MD_unix_map_gethostname_error
 
 PR_EXTERN(void) _MD_unix_map_select_error(int err);
 #define	_PR_MD_MAP_SELECT_ERROR	_MD_unix_map_select_error
 
 PR_EXTERN(void) _MD_unix_map_poll_error(int err);
 #define _PR_MD_MAP_POLL_ERROR _MD_unix_map_poll_error
 
+PR_EXTERN(void) _MD_unix_map_poll_revents_error(int err);
+#define _PR_MD_MAP_POLL_REVENTS_ERROR _MD_unix_map_poll_revents_error
+
 PR_EXTERN(void) _MD_unix_map_flock_error(int err);
 #define	_PR_MD_MAP_FLOCK_ERROR	_MD_unix_map_flock_error
 
 PR_EXTERN(void) _MD_unix_map_lockf_error(int err);
 #define	_PR_MD_MAP_LOCKF_ERROR	_MD_unix_map_lockf_error
 
 PR_END_EXTERN_C
 
--- a/pr/include/md/_unixos.h
+++ b/pr/include/md/_unixos.h
@@ -32,52 +32,72 @@
 #define FD_SETSIZE  4096
 #endif
 #endif
 
 #include <unistd.h>
 #include <stddef.h>
 #include <sys/stat.h>
 #include <dirent.h>
+#include <errno.h>
 
 #include "prio.h"
 #include "prmem.h"
 #include "prclist.h"
 
-/* To pick up fd_set */
-#if defined(HPUX)
-#include <sys/time.h>
-#elif defined(OSF1) || defined(AIX) || defined(SOLARIS) || defined(IRIX) \
-        || defined(UNIXWARE) || defined(NCR) || defined(SNI) || defined(NEC) \
-        || defined(BSDI) || defined(SONY)
-#include <sys/select.h>
-#elif defined(SUNOS4) || defined(SCO) || defined(FREEBSD) \
-        || defined(NETBSD) || defined(RHAPSODY) || defined(DGUX)
-#include <sys/types.h>
-#elif defined(LINUX)
+/*
+ * For select(), fd_set, and struct timeval.
+ *
+ * In The Single UNIX(R) Specification, Version 2,
+ * the header file for select() is <sys/time.h>.
+ *
+ * fd_set is defined in <sys/types.h>.  Usually
+ * <sys/time.h> includes <sys/types.h>, but on some
+ * older systems <sys/time.h> does not include
+ * <sys/types.h>, so we include it explicitly.
+ */
 #include <sys/time.h>
 #include <sys/types.h>
-#else
-#error Find out what include file defines fd_set on this platform
+#if defined(AIX)  /* Only pre-4.2 AIX needs it, but for simplicity... */
+#include <sys/select.h>
 #endif
 
 #define PR_DIRECTORY_SEPARATOR		'/'
 #define PR_DIRECTORY_SEPARATOR_STR	"/"
 #define PR_PATH_SEPARATOR		':'
 #define PR_PATH_SEPARATOR_STR		":"
 #define GCPTR
-
 typedef int (*FARPROC)();
 
 /*
  * intervals at which GLOBAL threads wakeup to check for pending interrupt
  */
 #define _PR_INTERRUPT_CHECK_INTERVAL_SECS 5
 extern PRIntervalTime intr_timeout_ticks;
 
+/*
+ * The bit flags for the in_flags and out_flags fields
+ * of _PR_UnixPollDesc
+ */
+#ifdef _PR_USE_POLL
+#define _PR_UNIX_POLL_READ    POLLIN
+#define _PR_UNIX_POLL_WRITE   POLLOUT
+#define _PR_UNIX_POLL_EXCEPT  POLLPRI
+#define _PR_UNIX_POLL_ERR     POLLERR
+#define _PR_UNIX_POLL_NVAL    POLLNVAL
+#define _PR_UNIX_POLL_HUP     POLLHUP
+#else /* _PR_USE_POLL */
+#define _PR_UNIX_POLL_READ    0x1
+#define _PR_UNIX_POLL_WRITE   0x2
+#define _PR_UNIX_POLL_EXCEPT  0x4
+#define _PR_UNIX_POLL_ERR     0x8
+#define _PR_UNIX_POLL_NVAL    0x10
+#define _PR_UNIX_POLL_HUP     0x20
+#endif /* _PR_USE_POLL */
+
 typedef struct _PRUnixPollDesc {
 	PRInt32 osfd;
 	PRInt16 in_flags;
 	PRInt16 out_flags;
 } _PRUnixPollDesc;
 
 typedef struct PRPollQueue {
     PRCList links;        /* for linking PRPollQueue's together */
@@ -87,18 +107,20 @@ typedef struct PRPollQueue {
     PRIntervalTime timeout;        /* timeout, in ticks */
     struct PRThread *thr;
 } PRPollQueue;
 
 #define _PR_POLLQUEUE_PTR(_qp) \
     ((PRPollQueue*) ((char*) (_qp) - offsetof(PRPollQueue,links)))
 
 
-extern PRInt32 _PR_WaitForFD(PRInt32 osfd, PRUintn how,
-					PRIntervalTime timeout);
+extern PRInt32 _PR_WaitForMultipleFDs(
+    _PRUnixPollDesc *unixpds,
+    PRInt32 pdcnt,
+    PRIntervalTime timeout);
 extern void _PR_Unblock_IO_Wait(struct PRThread *thr);
 
 #if defined(_PR_LOCAL_THREADS_ONLY) || defined(_PR_GLOBAL_THREADS_ONLY)
 #define _MD_CHECK_FOR_EXIT()
 #endif
 
 extern fd_set _pr_md_read_set, _pr_md_write_set, _pr_md_exception_set;
 extern PRInt16 _pr_md_read_cnt[], _pr_md_write_cnt[], _pr_md_exception_cnt[];
@@ -108,55 +130,19 @@ extern PRUint32 _pr_md_ioq_timeout;
 struct _MDFileDesc {
     int osfd;
 };
 
 struct _MDDir {
 	DIR *d;
 };
 
-/*
- * md-specific cpu structure field, common to all Unix platforms
- */
-#define _PR_MD_MAX_OSFD FD_SETSIZE
-
-struct _MDCPU_Unix {
-    PRCList ioQ;
-    PRUint32 ioq_timeout;
-    PRInt32 ioq_max_osfd;
-    PRInt32 ioq_osfd_cnt;
-#ifndef _PR_USE_POLL
-    fd_set fd_read_set, fd_write_set, fd_exception_set;
-    PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
-				fd_exception_cnt[_PR_MD_MAX_OSFD];
-#else
-	struct pollfd *ioq_pollfds;
-	int ioq_pollfds_size;
-#endif	/* _PR_USE_POLL */
-};
 struct _PRCPU;
 extern void _MD_unix_init_running_cpu(struct _PRCPU *cpu);
 
-#define _PR_IOQ(_cpu)			((_cpu)->md.md_unix.ioQ)
-#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
-#define _PR_FD_READ_SET(_cpu)		((_cpu)->md.md_unix.fd_read_set)
-#define _PR_FD_READ_CNT(_cpu)		((_cpu)->md.md_unix.fd_read_cnt)
-#define _PR_FD_WRITE_SET(_cpu)		((_cpu)->md.md_unix.fd_write_set)
-#define _PR_FD_WRITE_CNT(_cpu)		((_cpu)->md.md_unix.fd_write_cnt)
-#define _PR_FD_EXCEPTION_SET(_cpu)	((_cpu)->md.md_unix.fd_exception_set)
-#define _PR_FD_EXCEPTION_CNT(_cpu)	((_cpu)->md.md_unix.fd_exception_cnt)
-#define _PR_IOQ_TIMEOUT(_cpu)		((_cpu)->md.md_unix.ioq_timeout)
-#define _PR_IOQ_MAX_OSFD(_cpu)		((_cpu)->md.md_unix.ioq_max_osfd)
-#define _PR_IOQ_OSFD_CNT(_cpu)		((_cpu)->md.md_unix.ioq_osfd_cnt)
-#define _PR_IOQ_POLLFDS(_cpu)		((_cpu)->md.md_unix.ioq_pollfds)
-#define _PR_IOQ_POLLFDS_SIZE(_cpu)	((_cpu)->md.md_unix.ioq_pollfds_size)
-
-#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)	32
-
-
 /*
 ** Make a redzone at both ends of the stack segment. Disallow access
 ** to those pages of memory. It's ok if the mprotect call's don't
 ** work - it just means that we don't really have a functional
 ** redzone.
 */
 #if defined(DEBUG) && !defined(RHAPSODY)
 #if !defined(SOLARIS)	
@@ -243,16 +229,17 @@ extern PRStatus _MD_WaitUnixProcess(stru
 #define _MD_KILL_PROCESS _MD_KillUnixProcess
 extern PRStatus _MD_KillUnixProcess(struct PRProcess *process);
 
 /************************************************************************/
 
 #define _MD_START_INTERRUPTS			_MD_StartInterrupts
 #define _MD_STOP_INTERRUPTS				_MD_StopInterrupts
 #define _MD_DISABLE_CLOCK_INTERRUPTS	_MD_DisableClockInterrupts
+#define _MD_ENABLE_CLOCK_INTERRUPTS		_MD_EnableClockInterrupts
 #define _MD_BLOCK_CLOCK_INTERRUPTS		_MD_BlockClockInterrupts
 #define _MD_UNBLOCK_CLOCK_INTERRUPTS	_MD_UnblockClockInterrupts
 
 /************************************************************************/
 
 extern void		_MD_InitCPUS(void);
 #define _MD_INIT_CPUS           _MD_InitCPUS
 
@@ -286,34 +273,31 @@ extern PRStatus	_MD_AllocSegment(PRSegme
 extern void		_MD_FreeSegment(PRSegment *seg);
 
 #define _MD_INIT_SEGS			_MD_InitSegs
 #define _MD_ALLOC_SEGMENT		_MD_AllocSegment
 #define _MD_FREE_SEGMENT		_MD_FreeSegment
 
 /************************************************************************/
 
+#if !defined(HPUX_LW_TIMER)
 #define _MD_INTERVAL_INIT()
+#endif
 #define _MD_INTERVAL_PER_MILLISEC()	(_PR_MD_INTERVAL_PER_SEC() / 1000)
 #define _MD_INTERVAL_PER_MICROSEC()	(_PR_MD_INTERVAL_PER_SEC() / 1000000)
 
 /************************************************************************/
 
 #define _MD_ERRNO()             	(errno)
 #define _MD_GET_SOCKET_ERROR()		(errno)
 
 /************************************************************************/
 
 extern PRInt32 _MD_AvailableSocket(PRInt32 osfd);
 
-#include <errno.h>
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/stat.h>
-
 extern void _MD_InitSegs(void);
 extern void _MD_StartInterrupts(void);
 extern void _MD_StopInterrupts(void);
 extern void _MD_DisableClockInterrupts(void);
 extern void _MD_BlockClockInterrupts(void);
 extern void _MD_UnblockClockInterrupts(void);
 extern void _MD_PauseCPU(PRIntervalTime timeout);
 
@@ -322,17 +306,17 @@ extern PRInt32  _MD_close_dir(struct _MD
 extern char *   _MD_read_dir(struct _MDDir *, PRIntn);
 extern PRInt32  _MD_open(const char *name, PRIntn osflags, PRIntn mode);
 extern PRInt32	_MD_delete(const char *name);
 extern PRInt32	_MD_getfileinfo(const char *fn, PRFileInfo *info);
 extern PRInt32  _MD_getfileinfo64(const char *fn, PRFileInfo64 *info);
 extern PRInt32  _MD_getopenfileinfo(const PRFileDesc *fd, PRFileInfo *info);
 extern PRInt32  _MD_getopenfileinfo64(const PRFileDesc *fd, PRFileInfo64 *info);
 extern PRInt32	_MD_rename(const char *from, const char *to);
-extern PRInt32	_MD_access(const char *name, PRIntn how);
+extern PRInt32	_MD_access(const char *name, PRAccessHow how);
 extern PRInt32	_MD_mkdir(const char *name, PRIntn mode);
 extern PRInt32	_MD_rmdir(const char *name);
 extern PRInt32	_MD_accept_read(PRInt32 sock, PRInt32 *newSock,
 				PRNetAddr **raddr, void *buf, PRInt32 amount);
 extern PRInt32 	_PR_UnixTransmitFile(PRFileDesc *sd, PRFileDesc *fd,
 			const void *headers, PRInt32 hlen,
 			PRTransmitFileFlags flags, PRIntervalTime timeout);
 
@@ -511,9 +495,77 @@ struct pollfd {
 #define	POLLERR		0x0008		/* fd has error condition */
 #define	POLLHUP		0x0010		/* fd has been hung up on */
 #define	POLLNVAL	0x0020		/* invalid pollfd entry */
 
 extern int poll(struct pollfd *, unsigned long, int);
 
 #endif /* _PR_NEED_FAKE_POLL */
 
+/*
+** A vector of the UNIX I/O calls we use. These are here to smooth over
+** the rough edges needed for large files. All of NSPR's implmentaions
+** go through this vector using syntax of the form
+**      result = _md_iovector.xxx64(args);
+*/
+
+#if defined(SOLARIS2_5)
+/*
+** Special case: Solaris 2.5.1
+** Solaris starts to have 64-bit file I/O in 2.6.  We build on Solaris
+** 2.5.1 so that we can use the same binaries on both Solaris 2.5.1 and
+** 2.6.  At run time, we detect whether 64-bit file I/O is available by
+** looking up the 64-bit file function symbols in libc.  At build time,
+** we need to define the 64-bit file I/O datatypes that are compatible
+** with their definitions on Solaris 2.6.
+*/
+typedef PRInt64 off64_t;
+typedef PRUint64 ino64_t;
+typedef PRUint64 blkcnt64_t;
+struct stat64 {
+    dev_t st_dev;
+    long st_pad1[3];
+    ino64_t st_ino;
+    mode_t st_mode;
+    nlink_t st_nlink;
+    uid_t st_uid;
+    gid_t st_gid;
+    dev_t st_rdev;
+    long t_pad2[2];
+    off64_t st_size;
+    timestruc_t st_atim;
+    timestruc_t st_mtim;
+    timestruc_t st_ctim;
+    long st_blksize;
+    blkcnt64_t st_blocks;
+    char st_fstype[_ST_FSTYPSZ];
+    long st_pad4[8];
+};
+typedef struct stat64 _MDStat64;
+
+#elif defined(_PR_HAVE_OFF64_T)
+typedef struct stat64 _MDStat64;
+#elif defined(_PR_HAVE_LARGE_OFF_T) || defined(_PR_NO_LARGE_FILES)
+typedef struct stat _MDStat64;
+#else
+#error "I don't know yet"
+#endif
+
+typedef PRIntn (*_MD_Fstat64)(PRIntn osfd, _MDStat64 *buf);
+typedef PRIntn (*_MD_Open64)(const char *path, int oflag, ...);
+typedef PRIntn (*_MD_Stat64)(const char *path, _MDStat64 *buf);
+typedef PRInt64 (*_MD_Lseek64)(PRIntn osfd, PRInt64, PRIntn whence);
+typedef PRIntn (*_MD_Lockf64)(PRIntn osfd, PRIntn function, PRInt64 size);
+typedef void* (*_MD_Mmap64)(
+    void *addr, PRSize len, PRIntn prot, PRIntn flags,
+    PRIntn fildes, PRInt64 offset);
+struct _MD_IOVector
+{
+    _MD_Open64 _open64;
+    _MD_Mmap64 _mmap64;
+    _MD_Stat64 _stat64;
+    _MD_Fstat64 _fstat64;
+    _MD_Lockf64 _lockf64;
+    _MD_Lseek64 _lseek64;
+};
+extern struct _MD_IOVector _md_iovector;
+
 #endif /* prunixos_h___ */
--- a/pr/include/md/_unixware.cfg
+++ b/pr/include/md/_unixware.cfg
@@ -66,18 +66,17 @@
 #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_FLOAT   4
 #define PR_ALIGN_OF_DOUBLE  4
 #define PR_ALIGN_OF_POINTER 4
 
-#define _PR_USE_POLL
-#define _PR_POLL_AVAILABLE
+#define _PR_POLL_BACKCOMPAT
 
 #ifndef NO_NSPR_10_SUPPORT
 
 #define BYTES_PER_BYTE		PR_BYTES_PER_BYTE
 #define BYTES_PER_SHORT 	PR_BYTES_PER_SHORT
 #define BYTES_PER_INT 		PR_BYTES_PER_INT
 #define BYTES_PER_INT64		PR_BYTES_PER_INT64
 #define BYTES_PER_LONG		PR_BYTES_PER_LONG
--- a/pr/include/md/_unixware.h
+++ b/pr/include/md/_unixware.h
@@ -31,16 +31,18 @@
 #define _PR_VMBASE	 	0x30000000
 #define _PR_STACK_VMBASE	0x50000000
 #define _MD_DEFAULT_STACK_SIZE	65536L
 #define _MD_MMAP_FLAGS          MAP_PRIVATE
 
 #ifndef	HAVE_WEAK_IO_SYMBOLS
 #define	HAVE_WEAK_IO_SYMBOLS
 #endif
+#define _PR_POLL_AVAILABLE
+#define _PR_USE_POLL
 
 #undef  HAVE_STACK_GROWING_UP
 #define HAVE_NETCONFIG
 #define	HAVE_DLL
 #define	USE_DLFCN
 #define HAVE_STRERROR
 #define NEED_STRFTIME_LOCK
 #define NEED_TIME_R
@@ -109,16 +111,52 @@ struct _MDSemaphore {
 struct _MDCVar {
     PRInt8 notused;
 };
 
 struct _MDSegment {
     PRInt8 notused;
 };
 
+/*
+ * md-specific cpu structure field
+ */
+#define _PR_MD_MAX_OSFD FD_SETSIZE
+
+struct _MDCPU_Unix {
+    PRCList ioQ;
+    PRUint32 ioq_timeout;
+    PRInt32 ioq_max_osfd;
+    PRInt32 ioq_osfd_cnt;
+#ifndef _PR_USE_POLL
+    fd_set fd_read_set, fd_write_set, fd_exception_set;
+    PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
+				fd_exception_cnt[_PR_MD_MAX_OSFD];
+#else
+	struct pollfd *ioq_pollfds;
+	int ioq_pollfds_size;
+#endif	/* _PR_USE_POLL */
+};
+
+#define _PR_IOQ(_cpu)			((_cpu)->md.md_unix.ioQ)
+#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
+#define _PR_FD_READ_SET(_cpu)		((_cpu)->md.md_unix.fd_read_set)
+#define _PR_FD_READ_CNT(_cpu)		((_cpu)->md.md_unix.fd_read_cnt)
+#define _PR_FD_WRITE_SET(_cpu)		((_cpu)->md.md_unix.fd_write_set)
+#define _PR_FD_WRITE_CNT(_cpu)		((_cpu)->md.md_unix.fd_write_cnt)
+#define _PR_FD_EXCEPTION_SET(_cpu)	((_cpu)->md.md_unix.fd_exception_set)
+#define _PR_FD_EXCEPTION_CNT(_cpu)	((_cpu)->md.md_unix.fd_exception_cnt)
+#define _PR_IOQ_TIMEOUT(_cpu)		((_cpu)->md.md_unix.ioq_timeout)
+#define _PR_IOQ_MAX_OSFD(_cpu)		((_cpu)->md.md_unix.ioq_max_osfd)
+#define _PR_IOQ_OSFD_CNT(_cpu)		((_cpu)->md.md_unix.ioq_osfd_cnt)
+#define _PR_IOQ_POLLFDS(_cpu)		((_cpu)->md.md_unix.ioq_pollfds)
+#define _PR_IOQ_POLLFDS_SIZE(_cpu)	((_cpu)->md.md_unix.ioq_pollfds_size)
+
+#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)	32
+
 struct _MDCPU {
 	struct _MDCPU_Unix md_unix;
 };
 
 #define _MD_INIT_LOCKS()
 #define _MD_NEW_LOCK(lock) PR_SUCCESS
 #define _MD_FREE_LOCK(lock)
 #define _MD_LOCK(lock)
--- a/pr/include/md/_win16.h
+++ b/pr/include/md/_win16.h
@@ -291,16 +291,17 @@ extern PRStatus _PR_KillWindowsProcess(s
 #define _MD_GETSOCKOPT                _PR_MD_GETSOCKOPT
 #define _MD_SETSOCKOPT                _PR_MD_SETSOCKOPT
 #define _MD_SELECT                    select
 #define _MD_FSYNC                     _PR_MD_FSYNC
 #define _MD_SOCKETAVAILABLE           _PR_MD_SOCKETAVAILABLE
 
 #define _MD_INIT_ATOMIC()
 #define _MD_ATOMIC_INCREMENT(x)       (*x++)
+#define _MD_ATOMIC_ADD(ptr, val)      ((*x) += val)
 #define _MD_ATOMIC_DECREMENT(x)       (*x--)
 #define _MD_ATOMIC_SET(x,y)           (*x, y)
 
 #define _MD_INIT_IO                   _PR_MD_INIT_IO
 #define _MD_TRANSMITFILE              _PR_MD_TRANSMITFILE
 
 /* win95 doesn't have async IO */
 #define _MD_SOCKET                    _PR_MD_SOCKET
@@ -383,16 +384,17 @@ extern PRStatus _PR_KillWindowsProcess(s
 #define _MD_IOQ_UNLOCK()              
 
 
 /* --- Initialization stuff --- */
 PR_EXTERN(void) _MD_INIT_RUNNING_CPU(struct _PRCPU *cpu );
 #define _MD_START_INTERRUPTS()
 #define _MD_STOP_INTERRUPTS()
 #define _MD_DISABLE_CLOCK_INTERRUPTS()
+#define _MD_ENABLE_CLOCK_INTERRUPTS()
 #define _MD_BLOCK_CLOCK_INTERRUPTS()
 #define _MD_UNBLOCK_CLOCK_INTERRUPTS()
 #define _MD_EARLY_INIT                  _PR_MD_EARLY_INIT
 #define _MD_FINAL_INIT                  _PR_MD_FINAL_INIT
 #define _MD_INIT_CPUS()
 
 /* --- User Threading stuff --- */
 #define _MD_EXIT
--- a/pr/include/md/_win95.h
+++ b/pr/include/md/_win95.h
@@ -217,23 +217,27 @@ extern PRInt32 _MD_CloseSocket(PRInt32 o
 #define _MD_RECVFROM                  _PR_MD_RECVFROM
 #define _MD_SOCKETPAIR(s, type, proto, sv) -1
 #define _MD_GETSOCKNAME               _PR_MD_GETSOCKNAME
 #define _MD_GETPEERNAME               _PR_MD_GETPEERNAME
 #define _MD_GETSOCKOPT                _PR_MD_GETSOCKOPT
 #define _MD_SETSOCKOPT                _PR_MD_SETSOCKOPT
 #define _MD_SELECT                    select
 #define _MD_FSYNC                     _PR_MD_FSYNC
+#define READ_FD                       1
+#define WRITE_FD                      2
 
 #define _MD_INIT_ATOMIC()
 #if defined(_M_IX86) || defined(_X86_)
 #define _MD_ATOMIC_INCREMENT          _PR_MD_ATOMIC_INCREMENT
+#define _MD_ATOMIC_ADD          	  _PR_MD_ATOMIC_ADD
 #define _MD_ATOMIC_DECREMENT          _PR_MD_ATOMIC_DECREMENT
 #else /* non-x86 processors */
 #define _MD_ATOMIC_INCREMENT(x)       InterlockedIncrement((PLONG)x)
+#define _MD_ATOMIC_ADD(ptr,val)    (InterlockedExchangeAdd((PLONG)ptr, (LONG)val) + val)
 #define _MD_ATOMIC_DECREMENT(x)       InterlockedDecrement((PLONG)x)
 #endif /* x86 */
 #define _MD_ATOMIC_SET(x,y)           InterlockedExchange((PLONG)x, (LONG)y)
 
 #define _MD_INIT_IO                   _PR_MD_INIT_IO
 #define _MD_TRANSMITFILE              _PR_MD_TRANSMITFILE
 
 
@@ -320,16 +324,17 @@ extern PRInt32 _MD_Accept(PRFileDesc *fd
 #define _MD_IOQ_LOCK()                
 #define _MD_IOQ_UNLOCK()              
 
 
 /* --- Initialization stuff --- */
 #define _MD_START_INTERRUPTS()
 #define _MD_STOP_INTERRUPTS()
 #define _MD_DISABLE_CLOCK_INTERRUPTS()
+#define _MD_ENABLE_CLOCK_INTERRUPTS()
 #define _MD_BLOCK_CLOCK_INTERRUPTS()
 #define _MD_UNBLOCK_CLOCK_INTERRUPTS()
 #define _MD_EARLY_INIT                _PR_MD_EARLY_INIT
 #define _MD_FINAL_INIT()
 #define _MD_INIT_CPUS()
 #define _MD_INIT_RUNNING_CPU(cpu)
 
 struct PRProcess;
@@ -363,31 +368,33 @@ extern PRStatus _PR_KillWindowsProcess(s
 #define _MD_INTERVAL_INIT                 _PR_MD_INTERVAL_INIT
 #define _MD_GET_INTERVAL                  _PR_MD_GET_INTERVAL
 #define _MD_INTERVAL_PER_SEC              _PR_MD_INTERVAL_PER_SEC
 #define _MD_INTERVAL_PER_MILLISEC()       (_PR_MD_INTERVAL_PER_SEC() / 1000)
 #define _MD_INTERVAL_PER_MICROSEC()       (_PR_MD_INTERVAL_PER_SEC() / 1000000)
 
 /* --- Native-Thread Specific Definitions ------------------------------- */
 
+extern struct PRThread * _MD_CURRENT_THREAD(void);
+
 #ifdef _PR_USE_STATIC_TLS
 extern __declspec(thread) struct PRThread *_pr_currentThread;
-#define _MD_CURRENT_THREAD() _pr_currentThread
+#define _MD_GET_ATTACHED_THREAD() _pr_currentThread
 #define _MD_SET_CURRENT_THREAD(_thread) (_pr_currentThread = (_thread))
 
 extern __declspec(thread) struct PRThread *_pr_thread_last_run;
 #define _MD_LAST_THREAD() _pr_thread_last_run
 #define _MD_SET_LAST_THREAD(_thread) (_pr_thread_last_run = 0)
 
 extern __declspec(thread) struct _PRCPU *_pr_currentCPU;
 #define _MD_CURRENT_CPU() _pr_currentCPU
 #define _MD_SET_CURRENT_CPU(_cpu) (_pr_currentCPU = 0)
 #else /* _PR_USE_STATIC_TLS */
 extern DWORD _pr_currentThreadIndex;
-#define _MD_CURRENT_THREAD() ((PRThread *) TlsGetValue(_pr_currentThreadIndex))
+#define _MD_GET_ATTACHED_THREAD() ((PRThread *) TlsGetValue(_pr_currentThreadIndex))
 #define _MD_SET_CURRENT_THREAD(_thread) TlsSetValue(_pr_currentThreadIndex, (_thread))
 
 extern DWORD _pr_lastThreadIndex;
 #define _MD_LAST_THREAD() ((PRThread *) TlsGetValue(_pr_lastThreadIndex))
 #define _MD_SET_LAST_THREAD(_thread) TlsSetValue(_pr_lastThreadIndex, 0)
 
 extern DWORD _pr_currentCPUIndex;
 #define _MD_CURRENT_CPU() ((struct _PRCPU *) TlsGetValue(_pr_currentCPUIndex))
--- a/pr/include/md/_winnt.h
+++ b/pr/include/md/_winnt.h
@@ -29,31 +29,33 @@
     #define _WIN32_WINNT 0x0400
 #endif /* _WIN32_WINNT */
 
 #include <windows.h>
 #include <winsock.h>
 #include <errno.h>
 
 #include "prio.h"
+#include "prclist.h"
 
 /*
  * Internal configuration macros
  */
 
 #define PR_LINKER_ARCH      "win32"
 #define _PR_SI_SYSNAME        "WINNT"
 #define _PR_SI_ARCHITECTURE   "x86"    /* XXXMB hardcode for now */
 
 #define HAVE_DLL
 #define HAVE_CUSTOM_USER_THREADS
 #define HAVE_THREAD_AFFINITY
 #define HAVE_SOCKET_REUSEADDR
 #define HAVE_SOCKET_KEEPALIVE
 #define _PR_HAVE_ATOMIC_OPS
+#define _PR_HAVE_ATOMIC_CAS
 
 /* --- Common User-Thread/Native-Thread Definitions --------------------- */
 
 /* --- Globals --- */
 extern struct PRLock                      *_pr_schedLock;
 
 /* --- Typedefs --- */
 typedef void (*FiberFunc)(void *);
@@ -67,19 +69,49 @@ typedef PRInt32	                PR_CONTE
 #define _MD_MAGIC_THREADSTACK	0x33333333
 #define _MD_MAGIC_SEGMENT	0x44444444
 #define _MD_MAGIC_DIR		0x55555555
 
 struct _MDCPU {
     int              unused;
 };
 
+enum _MDIOModel {
+    _MD_BlockingIO = 0x38,
+    _MD_MultiWaitIO = 0x49
+};
+
+typedef struct _MDOverlapped {
+    OVERLAPPED overlapped;              /* Used for async I/O */
+
+    enum _MDIOModel ioModel;            /* The I/O model to implement
+                                         * using overlapped I/O.
+                                         */
+
+    union {
+        struct _MDThread *mdThread;     /* For blocking I/O, this structure
+                                         * is embedded in the _MDThread
+                                         * structure.
+                                         */
+        struct {
+            PRCList links;              /* for group->io_ready list */
+            struct PRRecvWait *desc;    /* For multiwait I/O, this structure
+                                         * is associated with a PRRecvWait
+                                         * structure.
+                                         */
+            struct PRWaitGroup *group;
+            struct TimerEvent *timer;
+            DWORD error;
+        } mw;
+    } data;
+} _MDOverlapped;
+
 struct _MDThread {
         /* The overlapped structure must be first! */
-    OVERLAPPED       overlapped;        /* Used for async IO for this thread */
+    struct _MDOverlapped overlapped;    /* Used for async IO for this thread */
     void            *acceptex_buf;      /* Used for AcceptEx() */
     TRANSMIT_FILE_BUFFERS *xmit_bufs;   /* Used for TransmitFile() */
     HANDLE           blocked_sema;      /* Threads block on this when waiting
                                          * for IO or CondVar.
                                          */
     PRInt32          blocked_io_status; /* Status of the completed IO */
     PRInt32          blocked_io_bytes;  /* Bytes transferred for completed IO */
     PRInt32          blocked_io_error;  /* Save error if status is FALSE */
@@ -163,16 +195,17 @@ struct _MDProcess {
     DWORD id;
 };
 
 /* --- Misc stuff --- */
 #define _MD_GET_SP(thread)            (thread)->md.gcContext[6]
 
 /* --- IO stuff --- */
 
+extern PRInt32 _md_Associate(HANDLE);
 extern PRInt32 _PR_MD_CLOSE(PRInt32 osfd, PRBool socket);
 
 #define _MD_OPEN                      _PR_MD_OPEN
 #define _MD_READ                      _PR_MD_READ
 #define _MD_WRITE                     _PR_MD_WRITE
 #define _MD_WRITEV                    _PR_MD_WRITEV
 #define _MD_LSEEK                     _PR_MD_LSEEK
 #define _MD_LSEEK64                   _PR_MD_LSEEK64
@@ -208,19 +241,21 @@ extern PRInt32 _PR_MD_CLOSE(PRInt32 osfd
 #define _MD_SETSOCKOPT                _PR_MD_SETSOCKOPT
 #define _MD_SELECT                    select
 #define _MD_FSYNC                     _PR_MD_FSYNC
 #define _MD_SOCKETAVAILABLE           _PR_MD_SOCKETAVAILABLE
 
 #define _MD_INIT_ATOMIC()
 #if defined(_M_IX86) || defined(_X86_)
 #define _MD_ATOMIC_INCREMENT          _PR_MD_ATOMIC_INCREMENT
+#define _MD_ATOMIC_ADD          	  _PR_MD_ATOMIC_ADD
 #define _MD_ATOMIC_DECREMENT          _PR_MD_ATOMIC_DECREMENT
 #else /* non-x86 processors */
 #define _MD_ATOMIC_INCREMENT(x)       InterlockedIncrement((PLONG)x)
+#define _MD_ATOMIC_ADD(ptr,val)    (InterlockedExchangeAdd((PLONG)ptr, (LONG)val) + val)
 #define _MD_ATOMIC_DECREMENT(x)       InterlockedDecrement((PLONG)x)
 #endif /* x86 */
 #define _MD_ATOMIC_SET(x,y)           InterlockedExchange((PLONG)x, (LONG)y)
 
 #define _MD_INIT_IO                   _PR_MD_INIT_IO
 #define _MD_SOCKET                    _PR_MD_SOCKET
 #define _MD_CONNECT                   _PR_MD_CONNECT
 
@@ -316,16 +351,17 @@ extern  struct _MDLock              _pr_
 #define _MD_IOQ_LOCK()                _MD_LOCK(&_pr_ioq_lock)
 #define _MD_IOQ_UNLOCK()              _MD_UNLOCK(&_pr_ioq_lock)
 
 
 /* --- Initialization stuff --- */
 #define _MD_START_INTERRUPTS()
 #define _MD_STOP_INTERRUPTS()
 #define _MD_DISABLE_CLOCK_INTERRUPTS()
+#define _MD_ENABLE_CLOCK_INTERRUPTS()
 #define _MD_BLOCK_CLOCK_INTERRUPTS()
 #define _MD_UNBLOCK_CLOCK_INTERRUPTS()
 #define _MD_EARLY_INIT                _PR_MD_EARLY_INIT
 #define _MD_FINAL_INIT()
 #define _MD_INIT_CPUS()
 #define _MD_INIT_RUNNING_CPU(cpu)
 
 struct PRProcess;
@@ -365,53 +401,83 @@ extern PRStatus _PR_KillWindowsProcess(s
 #define _MD_INTERVAL_INIT                 _PR_MD_INTERVAL_INIT
 #define _MD_GET_INTERVAL                  _PR_MD_GET_INTERVAL
 #define _MD_INTERVAL_PER_SEC              _PR_MD_INTERVAL_PER_SEC
 #define _MD_INTERVAL_PER_MILLISEC()       (_PR_MD_INTERVAL_PER_SEC() / 1000)
 #define _MD_INTERVAL_PER_MICROSEC()       (_PR_MD_INTERVAL_PER_SEC() / 1000000)
 
 /* --- Native-Thread Specific Definitions ------------------------------- */
 
-#ifdef _PR_USE_STATIC_TLS
+extern BOOL _pr_use_static_tls;
 
 extern __declspec(thread) struct PRThread *_pr_current_fiber;
-#define _MD_CURRENT_THREAD() _pr_current_fiber
-#define _MD_SET_CURRENT_THREAD(_thread) (_pr_current_fiber = (_thread))
+extern DWORD _pr_currentFiberIndex;
+
+#define _MD_GET_ATTACHED_THREAD() \
+    (_pr_use_static_tls ? _pr_current_fiber \
+    : (PRThread *) TlsGetValue(_pr_currentFiberIndex))
+
+extern struct PRThread * _MD_CURRENT_THREAD(void);
+
+#define _MD_SET_CURRENT_THREAD(_thread) \
+    PR_BEGIN_MACRO \
+        if (_pr_use_static_tls) { \
+            _pr_current_fiber = (_thread); \
+        } else { \
+            TlsSetValue(_pr_currentFiberIndex, (_thread)); \
+        } \
+    PR_END_MACRO
 
 extern __declspec(thread) struct PRThread *_pr_fiber_last_run;
-#define _MD_LAST_THREAD() _pr_fiber_last_run
-#define _MD_SET_LAST_THREAD(_thread) (_pr_fiber_last_run = (_thread))
+extern DWORD _pr_lastFiberIndex;
+
+#define _MD_LAST_THREAD() \
+    (_pr_use_static_tls ? _pr_fiber_last_run \
+    : (PRThread *) TlsGetValue(_pr_lastFiberIndex))
+
+#define _MD_SET_LAST_THREAD(_thread) \
+    PR_BEGIN_MACRO \
+        if (_pr_use_static_tls) { \
+            _pr_fiber_last_run = (_thread); \
+        } else { \
+            TlsSetValue(_pr_lastFiberIndex, (_thread)); \
+        } \
+    PR_END_MACRO
 
 extern __declspec(thread) struct _PRCPU *_pr_current_cpu;
-#define _MD_CURRENT_CPU() _pr_current_cpu
-#define _MD_SET_CURRENT_CPU(_cpu) (_pr_current_cpu = (_cpu))
+extern DWORD _pr_currentCPUIndex;
+
+#define _MD_CURRENT_CPU() \
+    (_pr_use_static_tls ? _pr_current_cpu \
+    : (struct _PRCPU *) TlsGetValue(_pr_currentCPUIndex))
+
+#define _MD_SET_CURRENT_CPU(_cpu) \
+    PR_BEGIN_MACRO \
+        if (_pr_use_static_tls) { \
+            _pr_current_cpu = (_cpu); \
+        } else { \
+            TlsSetValue(_pr_currentCPUIndex, (_cpu)); \
+        } \
+    PR_END_MACRO
 
 extern __declspec(thread) PRUintn _pr_ints_off;
-#define _MD_SET_INTSOFF(_val) (_pr_ints_off = (_val))
-#define _MD_GET_INTSOFF() _pr_ints_off
+extern DWORD _pr_intsOffIndex;
 
-#else /* _PR_USE_STATIC_TLS */
-
-extern DWORD _pr_currentFiberIndex;
-#define _MD_CURRENT_THREAD() ((PRThread *) TlsGetValue(_pr_currentFiberIndex))
-#define _MD_SET_CURRENT_THREAD(_thread) TlsSetValue(_pr_currentFiberIndex, (_thread))
+#define _MD_GET_INTSOFF() \
+    (_pr_use_static_tls ? _pr_ints_off \
+    : (PRUintn) TlsGetValue(_pr_intsOffIndex))
 
-extern DWORD _pr_lastFiberIndex;
-#define _MD_LAST_THREAD() ((PRThread *) TlsGetValue(_pr_lastFiberIndex))
-#define _MD_SET_LAST_THREAD(_thread) TlsSetValue(_pr_lastFiberIndex, (_thread))
-
-extern DWORD _pr_currentCPUIndex;
-#define _MD_CURRENT_CPU() ((struct _PRCPU *) TlsGetValue(_pr_currentCPUIndex))
-#define _MD_SET_CURRENT_CPU(_cpu) TlsSetValue(_pr_currentCPUIndex, (_cpu))
-
-extern DWORD _pr_intsOffIndex;
-#define _MD_SET_INTSOFF(_val) TlsSetValue(_pr_intsOffIndex, (LPVOID) (_val))
-#define _MD_GET_INTSOFF() ((PRUintn) TlsGetValue(_pr_intsOffIndex))
-
-#endif /* _PR_USE_STATIC_TLS */
+#define _MD_SET_INTSOFF(_val) \
+    PR_BEGIN_MACRO \
+        if (_pr_use_static_tls) { \
+            _pr_ints_off = (_val); \
+        } else { \
+            TlsSetValue(_pr_intsOffIndex, (LPVOID) (_val)); \
+        } \
+    PR_END_MACRO
 
 /* --- Initialization stuff --- */
 #define _MD_INIT_LOCKS()
 
 /* --- Stack stuff --- */
 #define _MD_INIT_STACK(stack, redzone)
 #define _MD_CLEAR_STACK(stack)
 
--- a/pr/include/md/prosdep.h
+++ b/pr/include/md/prosdep.h
@@ -45,28 +45,28 @@ PR_BEGIN_EXTERN_C
 #endif
 
 #elif defined XP_MAC
 
 #include "_macos.h"
 
 #elif defined(XP_UNIX)
 
-#include "md/_unixos.h"
-#include "md/_unix_errors.h"
-
 #if defined(AIX)
 #include "md/_aix.h"
 
 #elif defined(FREEBSD)
 #include "md/_freebsd.h"
 
 #elif defined(NETBSD)
 #include "md/_netbsd.h"
 
+#elif defined(OPENBSD)
+#include "md/_openbsd.h"
+
 #elif defined(BSDI)
 #include "md/_bsdi.h"
 
 #elif defined(HPUX)
 #include "md/_hpux.h"
 
 #elif defined(IRIX)
 #include "md/_irix.h"
@@ -107,16 +107,19 @@ PR_BEGIN_EXTERN_C
 #elif defined(DGUX)
 #include "md/_dgux.h"
 
 #else
 #error unknown Unix flavor
 
 #endif
 
+#include "md/_unixos.h"
+#include "md/_unix_errors.h"
+
 #else
 
 #error "The platform is not Unix, Windows, or Mac"
 
 #endif
 
 #ifdef _PR_PTHREADS
 #include "md/_pth.h"
--- a/pr/include/nspr.h
+++ b/pr/include/nspr.h
@@ -32,16 +32,17 @@
 #include "prinrval.h"
 #include "prio.h"
 #include "prlink.h"
 #include "prlock.h"
 #include "prlog.h"
 #include "prlong.h"
 #include "prmem.h"
 #include "prmon.h"
+#include "prmwait.h"
 #include "prnetdb.h"
 #include "prprf.h"
 #include "prproces.h"
 #include "prsystem.h"
 #include "prthread.h"
 #include "prtime.h"
 #include "prtypes.h"
 
--- a/pr/include/obsolete/pralarm.h
+++ b/pr/include/obsolete/pralarm.h
@@ -41,16 +41,17 @@
 */
 
 #if !defined(pralarm_h)
 #define pralarm_h
 
 #include "prtypes.h"
 #include "prinrval.h"
 
+
 PR_BEGIN_EXTERN_C
 
 /**********************************************************************/
 /************************* TYPES AND CONSTANTS ************************/
 /**********************************************************************/
 
 typedef struct PRAlarm PRAlarm;
 typedef struct PRAlarmID PRAlarmID;
--- a/pr/include/obsolete/protypes.h
+++ b/pr/include/obsolete/protypes.h
@@ -21,16 +21,17 @@
  * These definitions are scheduled to be eliminated at the earliest
  * possible time. The NSPR API is implemented and documented using
  * the new definitions.
  */
 
 #if !defined(PROTYPES_H)
 #define PROTYPES_H
 
+
 /* SVR4 typedef of uint is commonly found on UNIX machines. */
 #ifdef XP_UNIX
 #include <sys/types.h>
 #else
 typedef PRUintn uint;
 #endif
 
 typedef PRUintn uintn;
--- a/pr/include/pratom.h
+++ b/pr/include/pratom.h
@@ -20,48 +20,132 @@
 ** DESCRIPTION:
 **     PR Atomic operations
 */
 
 #ifndef pratom_h___
 #define pratom_h___
 
 #include "prtypes.h"
+#include "prlock.h"
 
 PR_BEGIN_EXTERN_C
 
 /*
 ** FUNCTION: PR_AtomicIncrement
 ** DESCRIPTION:
 **    Atomically increment a 32 bit value.
 ** INPUTS:
 **    val:  a pointer to the value to increment
 ** RETURN:
-**    the returned value has the same sign as the result
+**    the returned value is the result of the increment
 */
 PR_EXTERN(PRInt32)	PR_AtomicIncrement(PRInt32 *val);
 
 /*
 ** FUNCTION: PR_AtomicDecrement
 ** DESCRIPTION:
 **    Atomically decrement a 32 bit value.
 ** INPUTS:
 **    val:  a pointer to the value to decrement
 ** RETURN:
-**    the returned value has the same sign as the result
+**    the returned value is the result of the decrement
 */
 PR_EXTERN(PRInt32)	PR_AtomicDecrement(PRInt32 *val);
 
 /*
 ** FUNCTION: PR_AtomicSet
 ** DESCRIPTION:
 **    Atomically set a 32 bit value.
 ** INPUTS:
-**    val: A pointer to a 32 bit value to bet set
+**    val: A pointer to a 32 bit value to be set
 **    newval: The newvalue to assign to val
 ** RETURN:
 **    Returns the prior value
 */
 PR_EXTERN(PRInt32) PR_AtomicSet(PRInt32 *val, PRInt32 newval);
 
+/*
+** FUNCTION: PR_AtomicAdd
+** DESCRIPTION:
+**    Atomically add a 32 bit value.
+** INPUTS:
+**    ptr:  a pointer to the value to increment
+**	  val:  value to be added
+** RETURN:
+**    the returned value is the result of the addition
+*/
+PR_EXTERN(PRInt32)	PR_AtomicAdd(PRInt32 *ptr, PRInt32 val);
+
+/*
+** LIFO linked-list (stack)
+*/
+typedef struct PRStackElemStr PRStackElem;
+
+struct PRStackElemStr {
+    PRStackElem	*prstk_elem_next;	/* next pointer MUST be at offset 0;
+									  assembly language code relies on this */
+};
+
+typedef struct PRStackStr PRStack;
+
+struct PRStackStr {
+    PRStackElem	prstk_head;			/* head MUST be at offset 0; assembly
+										language code relies on this
+									*/
+    PRLock		*prstk_lock;
+    char		*prstk_name;
+};
+
+
+/*
+** FUNCTION: PR_CreateStack
+** DESCRIPTION:
+**    Create a stack, a LIFO linked list
+** INPUTS:
+**    stack_name:  a pointer to string containing the name of the stack
+** RETURN:
+**    A pointer to the created stack, if successful, else NULL.
+*/
+PR_EXTERN(PRStack *)	PR_CreateStack(const char *stack_name);
+
+/*
+** FUNCTION: PR_StackPush
+** DESCRIPTION:
+**    Push an element on the top of the stack
+** INPUTS:
+**    stack:		pointer to the stack
+**    stack_elem:	pointer to the stack element
+** RETURN:
+**    None
+*/
+PR_EXTERN(void)			PR_StackPush(PRStack *stack, PRStackElem *stack_elem);
+
+/*
+** FUNCTION: PR_StackPop
+** DESCRIPTION:
+**    Remove the element on the top of the stack
+** INPUTS:
+**    stack:		pointer to the stack
+** RETURN:
+**    A pointer to the stack element removed from the top of the stack,
+**	  if non-empty,
+**    else NULL
+*/
+PR_EXTERN(PRStackElem *)	PR_StackPop(PRStack *stack);
+
+/*
+** FUNCTION: PR_DestroyStack
+** DESCRIPTION:
+**    Destroy the stack
+** INPUTS:
+**    stack:		pointer to the stack
+** RETURN:
+**    PR_SUCCESS - if successfully deleted
+**	  PR_FAILURE - if the stack is not empty
+**					PR_GetError will return
+**						PR_INVALID_STATE_ERROR - stack is not empty
+*/
+PR_EXTERN(PRStatus)		PR_DestroyStack(PRStack *stack);
+
 PR_END_EXTERN_C
 
 #endif /* pratom_h___ */
--- a/pr/include/prbit.h
+++ b/pr/include/prbit.h
@@ -15,16 +15,17 @@
  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  * Reserved.
  */
 
 #ifndef prbit_h___
 #define prbit_h___
 
 #include "prtypes.h"
+PR_BEGIN_EXTERN_C
 
 /*
 ** A prbitmap_t is a long integer that can be used for bitmaps
 */
 typedef unsigned long prbitmap_t;
 
 #define PR_TEST_BIT(_map,_bit) \
     ((_map)[(_bit)>>PR_BITS_PER_LONG_LOG2] & (1L << ((_bit) & (PR_BITS_PER_LONG-1))))
@@ -82,9 +83,10 @@ PR_EXTERN(PRIntn) PR_FloorLog2(PRUint32 
     if ((j_) >> 4)                  \
 	(_log2) += 4, (j_) >>= 4;   \
     if ((j_) >> 2)                  \
 	(_log2) += 2, (j_) >>= 2;   \
     if ((j_) >> 1)                  \
 	(_log2) += 1;               \
   PR_END_MACRO
 
+PR_END_EXTERN_C
 #endif /* prbit_h___ */
new file mode 100644
--- /dev/null
+++ b/pr/include/prcountr.h
@@ -0,0 +1,512 @@
+/* -*- 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.0 (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.
+ */
+
+#ifndef prcountr_h___
+#define prcountr_h___
+
+/*----------------------------------------------------------------------------
+** prcountr.h -- NSPR Instrumentation counters
+**
+** The NSPR Counter Feature provides a means to "count
+** something." Counters can be dynamically defined, incremented,
+** decremented, set, and deleted under application program
+** control.
+** 																                   
+** The Counter Feature is intended to be used as instrumentation,                  
+** not as operational data. If you need a counter for operational                  
+** data, use native integral types.                                                
+** 																                   
+** Counters are 32bit unsigned intergers. On overflow, a counter                   
+** will wrap. No exception is recognized or reported.                              
+**                                                                                 
+** A counter can be dynamically created using a two level naming
+** convention. A "handle" is returned when the counter is
+** created. The counter can subsequently be addressed by its
+** handle. An API is provided to get an existing counter's handle
+** given the names with  which it was originally created. 
+** Similarly, a counter's name can be retrieved given its handle.
+** 
+** The counter naming convention is a two-level hierarchy. The
+** QName is the higher level of the hierarchy; RName is the
+** lower level. RNames can be thought of as existing within a
+** QName. The same RName can exist within multiple QNames. QNames
+** are unique. The NSPR Counter is not a near-zero overhead
+** feature. Application designers should be aware of 
+** serialization issues when using the Counter API. Creating a
+** counter locks a large asset, potentially causing a stall. This
+** suggest that applications should create counters at component
+** initialization, for example, and not create and destroy them
+** willy-nilly. ... You have been warned.
+** 
+** Incrementing and Adding to counters uses atomic operations.
+** The performance of these operations will vary from platform
+** to platform. On platforms where atomic operations are not
+** supported the overhead may be substantial.
+** 
+** When traversing the counter database with FindNext functions,
+** the instantaneous values of any given counter is that at the
+** moment of extraction. The state of the entire counter database
+** may not be viewed as atomic.
+** 
+** The counter interface may be disabled (No-Op'd) at compile
+** time. When DEBUG is defined at compile time, the Counter
+** Feature is compiled into NSPR and applications invoking it.
+** When DEBUG is not defined, the counter macros compile to
+** nothing. To force the Counter Feature to be compiled into an
+** optimized build, define FORCE_NSPR_COUNTERS at compile time
+** for both NSPR and the application intending to use it.
+** 
+** Application designers should use the macro form of the Counter
+** Feature methods to minimize performance impact in optimized
+** builds. The macros normally compile to nothing on optimized
+** builds.
+** 
+** Application designers should be aware of the effects of
+** debug and optimized build differences when using result of the
+** Counter Feature macros in expressions.
+** 
+** The Counter Feature is thread-safe and SMP safe.
+** 
+** /lth. 09-Jun-1998.
+*/
+
+#include "prtypes.h"
+
+PR_BEGIN_EXTERN_C
+
+/*
+** Opaque counter handle type.
+** ... don't even think of looking in here.
+**
+*/
+typedef void *  PRCounterHandle;
+
+#define PRCOUNTER_NAME_MAX 31
+#define PRCOUNTER_DESC_MAX 255
+
+
+#if defined(DEBUG) || defined(FORCE_NSPR_COUNTERS)
+
+/* -----------------------------------------------------------------------
+** FUNCTION: PR_DEFINE_COUNTER() -- Define a PRCounterHandle
+** 
+** DESCRIPTION: PR_DEFINE_COUNTER() is used to define a counter
+** handle.
+** 
+*/
+#define PR_DEFINE_COUNTER(name) PRCounterHandle name
+
+/* -----------------------------------------------------------------------
+** FUNCTION: PR_INIT_COUNTER_HANDLE() -- Set the value of a PRCounterHandle
+** 
+** DESCRIPTION: 
+** PR_INIT_COUNTER_HANDLE() sets the value of a PRCounterHandle
+** to value.
+** 
+*/
+#define PR_INIT_COUNTER_HANDLE(handle,value)\
+    (handle) = (PRCounterHandle)(value)
+
+/* -----------------------------------------------------------------------
+** FUNCTION: PR_CreateCounter() -- Create a counter
+** 
+** DESCRIPTION: PR_CreateCounter() creates a counter object and
+** initializes it to zero.
+** 
+** The macro form takes as its first argument the name of the
+** PRCounterHandle to receive the handle returned from
+** PR_CreateCounter().
+** 
+** INPUTS:
+**  qName: The QName for the counter object. The maximum length
+** of qName is defined by PRCOUNTER_NAME_MAX
+** 
+**  rName: The RName for the counter object. The maximum length
+** of qName is defined by PRCOUNTER_NAME_MAX
+** 
+**  descrioption: The description of the counter object. The
+** maximum length of description is defined by
+** PRCOUNTER_DESC_MAX.
+** 
+** OUTPUTS:
+** 
+** RETURNS:
+**  PRCounterHandle.
+** 
+** RESTRICTIONS:
+** 
+*/
+#define PR_CREATE_COUNTER(handle,qName,rName,description)\
+   (handle) = PR_CreateCounter((qName),(rName),(description))
+
+PR_EXTERN(PRCounterHandle) 
+	PR_CreateCounter( 
+		const char *qName, 
+    	const char *rName, 
+        const char *description 
+);
+
+/* -----------------------------------------------------------------------
+** FUNCTION: PR_DestroyCounter() -- Destroy a counter object.
+** 
+** DESCRIPTION: PR_DestroyCounter() removes a counter and
+** unregisters its handle from the counter database.
+** 
+** INPUTS:
+**  handle: the PRCounterHandle of the counter to be destroyed.
+** 
+** OUTPUTS: 
+**  The counter is destroyed.
+** 
+** RETURNS: void
+** 
+** RESTRICTIONS:
+** 
+*/
+#define PR_DESTROY_COUNTER(handle) PR_DestroyCounter((handle))
+
+PR_EXTERN(void) 
+	PR_DestroyCounter( 
+		PRCounterHandle handle 
+);
+
+
+/* -----------------------------------------------------------------------
+** FUNCTION: PR_GetCounterHandleFromName() -- Retreive a
+** counter's handle give its name.
+** 
+** DESCRIPTION: PR_GetCounterHandleFromName() retreives a
+** counter's handle from the counter database, given the name
+** the counter was originally created with.
+** 
+** INPUTS:
+**  qName: Counter's original QName.
+**  rName: Counter's original RName.
+** 
+** OUTPUTS:
+** 
+** RETURNS: 
+**  PRCounterHandle or PRCounterError.
+** 
+** RESTRICTIONS:
+** 
+*/
+#define PR_GET_COUNTER_HANDLE_FROM_NAME(handle,qName,rName)\
+    (handle) = PR_GetCounterHandleFromName((qName),(rName))
+
+PR_EXTERN(PRCounterHandle) 
+	PR_GetCounterHandleFromName( 
+    	const char *qName, 
+    	const char *rName 
+);
+
+/* -----------------------------------------------------------------------
+** FUNCTION: PR_GetCounterNameFromHandle() -- Retreive a
+** counter's name, given its handle.
+** 
+** DESCRIPTION: PR_GetCounterNameFromHandle() retreives a
+** counter's name given its handle.
+** 
+** INPUTS:
+**  qName: Where to store a pointer to qName.
+**  rName: Where to store a pointer to rName.
+**  description: Where to store a pointer to description.
+** 
+** OUTPUTS: Pointers to the Counter Feature's copies of the names
+** used when the counters were created.
+** 
+** RETURNS: void
+** 
+** RESTRICTIONS:
+** 
+*/
+#define PR_GET_COUNTER_NAME_FROM_HANDLE(handle,qName,rName,description)\
+    PR_GetCounterNameFromHandle((handle),(qName),(rName),(description))
+
+PR_EXTERN(void) 
+	PR_GetCounterNameFromHandle( 
+    	PRCounterHandle handle,  
+	    const char **qName, 
+	    const char **rName, 
+		const char **description 
+);
+
+
+/* -----------------------------------------------------------------------
+** FUNCTION: PR_IncrementCounter() -- Add one to the referenced
+** counter.
+** 
+** DESCRIPTION: Add one to the referenced counter.
+** 
+** INPUTS:
+**  handle: The PRCounterHandle of the counter to be incremented
+** 
+** OUTPUTS: The counter is incrementd.
+** 
+** RETURNS: void
+** 
+** RESTRICTIONS:
+** 
+*/
+#define PR_INCREMENT_COUNTER(handle) PR_IncrementCounter(handle)
+
+PR_EXTERN(void) 
+	PR_IncrementCounter( 
+		PRCounterHandle handle
+);
+
+
+/* -----------------------------------------------------------------------
+** FUNCTION: PR_DecrementCounter() -- Subtract one from the
+** referenced counter
+** 
+** DESCRIPTION: Subtract one from the referenced counter.
+** 
+** INPUTS: 
+**  handle: The PRCounterHandle of the coutner to be
+** decremented.
+** 
+** OUTPUTS: the counter is decremented.
+** 
+** RETURNS: void
+** 
+** RESTRICTIONS:
+** 
+*/
+#define PR_DECREMENT_COUNTER(handle) PR_DecrementCounter(handle)
+
+PR_EXTERN(void) 
+	PR_DecrementCounter( 
+		PRCounterHandle handle
+);
+
+/* -----------------------------------------------------------------------
+** FUNCTION: PR_AddToCounter() -- Add a value to a counter.
+** 
+** DESCRIPTION: Add value to the counter referenced by handle.
+** 
+** INPUTS:
+**  handle: the PRCounterHandle of the counter to be added to.
+** 
+**  value: the value to be added to the counter.
+** 
+** OUTPUTS: new value for counter.
+** 
+** RETURNS: void
+** 
+** RESTRICTIONS:
+** 
+*/
+#define PR_ADD_TO_COUNTER(handle,value)\
+    PR_AddToCounter((handle),(value))
+
+PR_EXTERN(void) 
+	PR_AddToCounter( 
+    	PRCounterHandle handle, 
+	    PRUint32 value 
+);
+
+
+/* -----------------------------------------------------------------------
+** FUNCTION: PR_SubtractFromCounter() -- A value is subtracted
+** from a counter.
+** 
+** DESCRIPTION:
+** Subtract a value from a counter.
+** 
+** INPUTS:
+**  handle: the PRCounterHandle of the counter to be subtracted
+** from.
+** 
+**  value: the value to be subtracted from the counter.
+** 
+** OUTPUTS: new value for counter
+** 
+** RETURNS: void
+** 
+** RESTRICTIONS:
+** 
+*/
+#define PR_SUBTRACT_FROM_COUNTER(handle,value)\
+    PR_SubtractFromCounter((handle),(value))
+
+PR_EXTERN(void) 
+	PR_SubtractFromCounter( 
+    	PRCounterHandle handle, 
+	    PRUint32 value 
+);
+
+
+/* -----------------------------------------------------------------------
+** FUNCTION: PR_GetCounter() -- Retreive the value of a counter
+** 
+** DESCRIPTION:
+** Retreive the value of a counter.
+** 
+** INPUTS:
+**  handle: the PR_CounterHandle of the counter to be retreived
+** 
+** OUTPUTS:
+** 
+** RETURNS: The value of the referenced counter
+** 
+** RESTRICTIONS:
+** 
+*/
+#define PR_GET_COUNTER(counter,handle)\
+    (counter) = PR_GetCounter((handle))
+
+PR_EXTERN(PRUint32) 
+	PR_GetCounter( 
+		PRCounterHandle handle 
+);
+
+/* -----------------------------------------------------------------------
+** FUNCTION: PR_SetCounter() -- Replace the content of counter
+** with value.
+** 
+** DESCRIPTION: The contents of the referenced counter are
+** replaced by value.
+** 
+** INPUTS:
+**  handle: the PRCounterHandle of the counter whose contents
+** are to be replaced.
+** 
+**  value: the new value of the counter.
+** 
+** OUTPUTS:
+** 
+** RETURNS: void
+** 
+** RESTRICTIONS:
+** 
+*/
+#define PR_SET_COUNTER(handle,value) PR_SetCounter((handle),(value))
+
+PR_EXTERN(void) 
+	PR_SetCounter( 
+		PRCounterHandle handle, 
+		PRUint32 value 
+);
+
+
+/* -----------------------------------------------------------------------
+** FUNCTION: PR_FindNextCounterQname() -- Retreive the next QName counter
+** handle iterator
+** 
+** DESCRIPTION:
+** PR_FindNextCounterQname() retreives the first or next Qname
+** the counter data base, depending on the value of handle. When
+** handle is NULL, the function attempts to retreive the first
+** QName handle in the database. When handle is a handle previosly
+** retreived QName handle, then the function attempts to retreive
+** the next QName handle.
+** 
+** INPUTS: 
+**  handle: PRCounterHandle or NULL.
+** 
+** OUTPUTS: returned
+** 
+** RETURNS: PRCounterHandle or NULL when no more QName counter
+** handles are present.
+** 
+** RESTRICTIONS:
+**  A concurrent PR_CreateCounter() or PR_DestroyCounter() may
+** cause unpredictable results.
+** 
+** A PRCounterHandle returned from this function may only be used
+** in another PR_FindNextCounterQname() function call; other
+** operations may cause unpredictable results.
+** 
+*/
+#define PR_FIND_NEXT_COUNTER_QNAME(next,handle)\
+    (next) = PR_FindNextCounterQname((handle))
+
+PR_EXTERN(PRCounterHandle) 
+	PR_FindNextCounterQname( 
+        PRCounterHandle handle
+);
+
+/* -----------------------------------------------------------------------
+** FUNCTION: PR_FindNextCounterRname() -- Retreive the next RName counter
+** handle iterator
+** 
+** DESCRIPTION:
+** PR_FindNextCounterRname() retreives the first or next RNname
+** handle from the counter data base, depending on the
+** value of handle. When handle is NULL, the function attempts to
+** retreive the first RName handle in the database. When handle is
+** a handle previosly retreived RName handle, then the function
+** attempts to retreive the next RName handle.
+** 
+** INPUTS:
+**  handle: PRCounterHandle or NULL.
+**  qhandle: PRCounterHandle of a previously aquired via
+** PR_FIND_NEXT_QNAME_HANDLE()
+** 
+** OUTPUTS: returned
+** 
+** RETURNS: PRCounterHandle or NULL when no more RName counter
+** handles are present.
+** 
+** RESTRICTIONS:
+**  A concurrent PR_CreateCounter() or PR_DestroyCounter() may
+** cause unpredictable results.
+** 
+** A PRCounterHandle returned from this function may only be used
+** in another PR_FindNextCounterRname() function call; other
+** operations may cause unpredictable results.
+** 
+*/
+#define PR_FIND_NEXT_COUNTER_RNAME(next,rhandle,qhandle)\
+    (next) = PR_FindNextCounterRname((rhandle),(qhandle))
+
+PR_EXTERN(PRCounterHandle) 
+	PR_FindNextCounterRname( 
+        PRCounterHandle rhandle,
+        PRCounterHandle qhandle
+);
+
+
+#else /* ( !(defined(DEBUG) || defined(FORCE_NSPR_COUNTERS)) */
+/*
+** When counters are not compiled in, provide macros that 
+** evaluate to No-Ops.
+**
+*/
+
+#define PR_DEFINE_COUNTER(name) PRCounterHandle name
+#define PR_INIT_COUNTER_HANDLE(handle,value)
+#define PR_CREATE_COUNTER(handle,qName,rName,description)
+#define PR_DESTROY_COUNTER(handle)
+#define PR_GET_COUNTER_HANDLE_FROM_NAME(handle,qName,rName)
+#define PR_GET_COUNTER_NAME_FROM_HANDLE(handle,qName,rName,description )
+#define PR_INCREMENT_COUNTER(handle)
+#define PR_DECREMENT_COUNTER(handle)
+#define PR_ADD_TO_COUNTER(handle,value)
+#define PR_SUBTRACT_FROM_COUNTER(handle,value)
+#define PR_GET_COUNTER(counter,handle) 0
+#define PR_SET_COUNTER(handle,value)
+#define PR_FIND_NEXT_COUNTER_QNAME(next,handle) NULL
+#define PR_FIND_NEXT_COUNTER_RNAME(next,rhandle,qhandle)
+
+#endif /* ( !(defined(DEBUG) || defined(FORCE_NSPR_COUNTERS)) */
+
+PR_END_EXTERN_C
+
+#endif /* prcountr_h___ */
--- a/pr/include/prdtoa.h
+++ b/pr/include/prdtoa.h
@@ -16,22 +16,16 @@
  * Reserved.
  */
 
 #ifndef prdtoa_h___
 #define prdtoa_h___
 
 #include "prtypes.h"
 
-/*******************************************************************************/
-/*******************************************************************************/
-/****************** THESE FUNCTIONS MAY NOT BE THREAD SAFE *********************/
-/*******************************************************************************/
-/*******************************************************************************/
-
 PR_BEGIN_EXTERN_C
 
 /*
 ** PR_strtod() returns as a double-precision floating-point number
 ** the  value represented by the character string pointed to by
 ** s00. The string is scanned up to the first unrecognized
 ** character.
 **a
--- a/pr/include/prerror.h
+++ b/pr/include/prerror.h
@@ -20,17 +20,17 @@
 #define prerror_h___
 
 #include "prtypes.h"
 
 PR_BEGIN_EXTERN_C
 
 typedef PRInt32 PRErrorCode;
 
-#define PR_NSPR_ERROR_BASE -2600
+#define PR_NSPR_ERROR_BASE -6000
 
 #define PR_OUT_OF_MEMORY_ERROR              PR_NSPR_ERROR_BASE + 0
                                     /* Insufficient memory to perform request   */
 #define PR_BAD_DESCRIPTOR_ERROR             PR_NSPR_ERROR_BASE + 1
                                     /* the file descriptor used as an argument
                                        in the function is invalid; either it has
                                        been deleted or otherwise corrupted.     */
 #define PR_WOULD_BLOCK_ERROR                PR_NSPR_ERROR_BASE + 2
@@ -142,17 +142,21 @@ typedef PRInt32 PRErrorCode;
 #define PR_END_OF_FILE_ERROR                PR_NSPR_ERROR_BASE + 62
 #define PR_FILE_SEEK_ERROR                  PR_NSPR_ERROR_BASE + 63
 #define PR_FILE_IS_BUSY_ERROR               PR_NSPR_ERROR_BASE + 64
 	
 #define PR_IN_PROGRESS_ERROR                PR_NSPR_ERROR_BASE + 66
 #define PR_ALREADY_INITIATED_ERROR          PR_NSPR_ERROR_BASE + 67
 #define PR_GROUP_EMPTY_ERROR                PR_NSPR_ERROR_BASE + 68
 #define PR_INVALID_STATE_ERROR              PR_NSPR_ERROR_BASE + 69
-#define PR_MAX_ERROR                        PR_NSPR_ERROR_BASE + 70
+#define PR_NETWORK_DOWN_ERROR               PR_NSPR_ERROR_BASE + 70
+#define PR_SOCKET_SHUTDOWN_ERROR            PR_NSPR_ERROR_BASE + 71
+#define PR_CONNECT_ABORTED_ERROR            PR_NSPR_ERROR_BASE + 72
+#define PR_HOST_UNREACHABLE_ERROR           PR_NSPR_ERROR_BASE + 73
+#define PR_MAX_ERROR                        PR_NSPR_ERROR_BASE + 74
                                     /* Place holder for the end of the list     */
 
 /*
 ** Set error will preserve an error condition within a thread context.
 ** The values stored are the NSPR (platform independent) translation of
 ** the error. Also, if available, the platform specific oserror is stored.
 ** If there is no appropriate OS error number, a zero my be supplied.
 */
--- a/pr/include/prinit.h
+++ b/pr/include/prinit.h
@@ -39,17 +39,21 @@ PR_BEGIN_EXTERN_C
 /*
 ** NSPR's version is used to determine the likelihood that the version you
 ** used to build your component is anywhere close to being compatible with
 ** what is in the underlying library.
 **
 ** The format of the version string is
 **     "<major version>.<minor version> <build date>"
 */
-#define PR_VERSION  "2.1 yyyymmdd"
+#define PR_VERSION  "3.0 yyyymmdd"
+#define PR_VMAJOR   3
+#define PR_VMINOR   0
+#define PR_VPATCH   0
+#define PR_BETA     PR_TRUE
 
 /*
 ** PRVersionCheck
 **
 ** The basic signature of the function that is called to provide version
 ** checking. The result will be a boolean that indicates the likelihood
 ** that the underling library will perform as the caller expects.
 **
@@ -76,18 +80,17 @@ PR_EXTERN(PRBool) PR_VersionCheck(const 
 
 
 /************************************************************************/
 /*******************************INITIALIZATION***************************/
 /************************************************************************/
 
 /*
 ** Initialize the runtime. Attach a thread object to the currently
-** executing native thread of type "type" (as if PR_AttachThread were
-** called).
+** executing native thread of type "type".
 **
 ** The specificaiton of 'maxPTDs' is ignored.
 */
 PR_EXTERN(void) PR_Init(
     PRThreadType type, PRThreadPriority priority, PRUintn maxPTDs);
 
 /*
 ** And alternate form of initialization, one that may become the default if
@@ -137,16 +140,22 @@ PR_EXTERN(PRStatus) PR_Cleanup(void);
 
 /*
 ** Disable Interrupts
 **		Disables timer signals used for pre-emptive scheduling.
 */
 PR_EXTERN(void) PR_DisableClockInterrupts(void);
 
 /*
+** Enables Interrupts
+**		Enables timer signals used for pre-emptive scheduling.
+*/
+PR_EXTERN(void) PR_EnableClockInterrupts(void);
+
+/*
 ** Block Interrupts
 **		Blocks the timer signal used for pre-emptive scheduling
 */
 PR_EXTERN(void) PR_BlockClockInterrupts(void);
 
 /*
 ** Unblock Interrupts
 **		Unblocks the timer signal used for pre-emptive scheduling
@@ -154,16 +163,23 @@ PR_EXTERN(void) PR_BlockClockInterrupts(
 PR_EXTERN(void) PR_UnblockClockInterrupts(void);
 
 /*
 ** Create extra virtual processor threads. Generally used with MP systems.
 */
 PR_EXTERN(void) PR_SetConcurrency(PRUintn numCPUs);
 
 /*
+** Control the method and size of the file descriptor (PRFileDesc*)
+** cache used by the runtime. Setting 'high' to zero is for performance,
+** any other value probably for debugging (see memo on FD caching).
+*/
+PR_EXTERN(PRStatus) PR_SetFDCacheSize(PRIntn low, PRIntn high);
+
+/*
  * Cause an immediate, nongraceful, forced termination of the process.
  * It takes a PRIntn argument, which is the exit status code of the
  * process.
  */
 PR_EXTERN(void) PR_ProcessExit(PRIntn status);
 
 /*
 ** Abort the process in a non-graceful manner. This will cause a core file,
--- a/pr/include/prio.h
+++ b/pr/include/prio.h
@@ -1403,34 +1403,34 @@ PR_EXTERN(PRInt32) PR_TransmitFile(
 **
 ** INPUTS:
 **    PRFileDesc *listenSock
 **        A socket descriptor that has been called with the PR_Listen() 
 **        function, also known as the rendezvous socket.
 **    void *buf
 **        A pointer to a buffer to receive data sent by the client.  This 
 **        buffer must be large enough to receive <amount> bytes of data
-**        and two PRNetAddr structures (thus allowing the runtime to align
-**        the addresses as needed).
+**        and two PRNetAddr structures, plus an extra 32 bytes.
 **    PRInt32 amount
 **        The number of bytes of client data to receive.  Does not include
 **        the size of the PRNetAddr structures.  If 0, no data will be read
 **        from the client.
 **    PRIntervalTime timeout
 **        The timeout interval only applies to the read portion of the 
 **        operation.  PR_AcceptRead will block indefinitely until the 
 **        connection is accepted; the read will timeout after the timeout 
 **        interval elapses.
 ** OUTPUTS:
 **    PRFileDesc **acceptedSock
 **        The file descriptor for the newly connected socket.  This parameter
 **        will only be valid if the function return does not indicate failure.
 **    PRNetAddr  **peerAddr,
 **        The address of the remote socket.  This parameter will only be
-**        valid if the function return does not indicate failure.
+**        valid if the function return does not indicate failure.  The
+**        returned address is not guaranteed to be properly aligned.
 ** 
 ** RETURNS:
 **     The number of bytes read from the client or -1 on failure.  The reason 
 **     for the failure is obtained by calling PR_GetError().
 **************************************************************************
 **/
 PR_EXTERN(PRInt32) PR_AcceptRead(
     PRFileDesc *listenSock, PRFileDesc **acceptedSock,
@@ -1565,39 +1565,38 @@ struct PRPollDesc {
     PRFileDesc* fd;
     PRInt16 in_flags;
     PRInt16 out_flags;
 };
 
 /*
 ** Bit values for PRPollDesc.in_flags or PRPollDesc.out_flags. Binary-or
 ** these together to produce the desired poll request.
-**
-** On Unix platforms where the poll() system call is available,
-** the various PR_POLL_XXX flags are mapped to the native poll flags.
 */
 
-#if defined(XP_UNIX) && defined(_PR_POLL_AVAILABLE)
+#if defined(_PR_POLL_BACKCOMPAT)
 
 #include <poll.h>
 #define PR_POLL_READ    POLLIN
 #define PR_POLL_WRITE   POLLOUT
 #define PR_POLL_EXCEPT  POLLPRI
 #define PR_POLL_ERR     POLLERR     /* only in out_flags */
 #define PR_POLL_NVAL    POLLNVAL    /* only in out_flags when fd is bad */
+#define PR_POLL_HUP     POLLHUP     /* only in out_flags */
 
-#else  /* XP_UNIX, _PR_POLL_AVAILABLE */
+#else  /* _PR_POLL_BACKCOMPAT */
 
 #define PR_POLL_READ    0x1
 #define PR_POLL_WRITE   0x2
 #define PR_POLL_EXCEPT  0x4
 #define PR_POLL_ERR     0x8         /* only in out_flags */
 #define PR_POLL_NVAL    0x10        /* only in out_flags when fd is bad */
+#define PR_POLL_HUP     0x20        /* only in out_flags */
 
-#endif  /* XP_UNIX, _PR_POLL_AVAILABLE */
+#endif  /* _PR_POLL_BACKCOMPAT */
 
 /*
 *************************************************************************
 ** FUNCTION:    PR_Poll
 ** DESCRIPTION:
 **
 ** The call returns as soon as I/O is ready on one or more of the underlying
 ** file/socket objects. A count of the number of ready descriptors is
@@ -1627,11 +1626,60 @@ struct PRPollDesc {
 **                              The reason for the failure is obtained by calling 
 **                              PR_GetError().
 ** XXX can we implement this on windoze and mac?
 **************************************************************************
 */
 PR_EXTERN(PRInt32) PR_Poll(
     PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout);
 
+/*
+**************************************************************************
+**
+** Pollable events
+**
+** A pollable event is a special kind of file descriptor.
+** The only I/O operation you can perform on a pollable event
+** is to poll it with the PR_POLL_READ flag.  You can't
+** read from or write to a pollable event.
+**
+** The purpose of a pollable event is to combine event waiting
+** with I/O waiting in a single PR_Poll call.  Pollable events
+** are implemented using a pipe or a pair of TCP sockets
+** connected via the loopback address, therefore setting and
+** waiting for pollable events are expensive operating system
+** calls.  Do not use pollable events for general thread
+** synchronization. Use condition variables instead.
+**
+** A pollable event has two states: set and unset.  Events
+** are not queued, so there is no notion of an event count.
+** A pollable event is either set or unset.
+**
+** A new pollable event is created by a PR_NewPollableEvent
+** call and is initially in the unset state.
+**
+** PR_WaitForPollableEvent blocks the calling thread until
+** the pollable event is set, and then it atomically unsets
+** the pollable event before it returns.
+**
+** To set a pollable event, call PR_SetPollableEvent.
+**
+** One can call PR_Poll with the PR_POLL_READ flag on a pollable
+** event.  When the pollable event is set, PR_Poll returns with
+** the PR_POLL_READ flag set in the out_flags.
+**
+** To close a pollable event, call PR_DestroyPollableEvent
+** (not PR_Close).
+**
+**************************************************************************
+*/
+
+PR_EXTERN(PRFileDesc *) PR_NewPollableEvent(void);
+
+PR_EXTERN(PRStatus) PR_DestroyPollableEvent(PRFileDesc *event);
+
+PR_EXTERN(PRStatus) PR_SetPollableEvent(PRFileDesc *event);
+
+PR_EXTERN(PRStatus) PR_WaitForPollableEvent(PRFileDesc *event);
+
 PR_END_EXTERN_C
 
 #endif /* prio_h___ */
--- a/pr/include/private/Makefile
+++ b/pr/include/private/Makefile
@@ -19,17 +19,17 @@
 
 MOD_DEPTH = ../../..
 
 include $(MOD_DEPTH)/config/config.mk
 
 RELEASE_HEADERS = pprio.h pprthred.h prpriv.h
 RELEASE_HEADERS_DEST = $(RELEASE_INCLUDE_DIR)/private
 
-HEADERS = $(RELEASE_HEADERS) primpl.h
+HEADERS = $(RELEASE_HEADERS) pprmwait.h primpl.h
 
 include $(MOD_DEPTH)/config/rules.mk
 
 export:: $(HEADERS)
 	$(INSTALL) -m 444 $(HEADERS) $(DIST)/include/private
 ifeq ($(MOZ_BITS),16)
 	$(INSTALL) -m 444 $(HEADERS) $(MOZ_INCL)/private
 endif
--- a/pr/include/private/pprio.h
+++ b/pr/include/private/pprio.h
@@ -23,18 +23,29 @@
 */
 
 #ifndef pprio_h___
 #define pprio_h___
 
 #include "prtypes.h"
 #include "prio.h"
 
-NSPR_BEGIN_EXTERN_C
+PR_BEGIN_EXTERN_C
 
+/*
+** File descriptors of the NSPR layer can be in one of the
+** following states (stored in the 'state' field of struct
+** PRFilePrivate):
+** - _PR_FILEDESC_OPEN: The OS fd is open.
+** - _PR_FILEDESC_CLOSED: The OS fd is closed.  The PRFileDesc
+**   is still open but is unusable.  The only operation allowed
+**   on the PRFileDesc is PR_Close().
+** - _PR_FILEDESC_FREED: The OS fd is closed and the PRFileDesc
+**   structure is freed.
+*/
 
 #define _PR_FILEDESC_OPEN       0xaaaaaaaa    /* 1010101... */
 #define _PR_FILEDESC_CLOSED     0x55555555    /* 0101010... */
 #define _PR_FILEDESC_FREED      0x11111111
 
 /************************************************************************/
 /************************************************************************/
 
@@ -181,11 +192,11 @@ PR_EXTERN(void) PR_NTFast_UpdateAcceptCo
 **    WARNING: THIS FUNCTION IS A TEMPORARY HACK AND WILL BE REMOVED SHORTLY
 **    (LIKE ALL FUNCTIONS IN THE PRIVATE AREA).  DO NOT USE THIS FUNCTION AT
 **    ALL WITHOUT CONTACTING mbelshe@netscape.com.
 */
 PR_EXTERN(void) PR_NT_UseNonblock();
 
 #endif /* WIN32 */
 
-NSPR_END_EXTERN_C
+PR_END_EXTERN_C
 
 #endif /* pprio_h___ */
new file mode 100644
--- /dev/null
+++ b/pr/include/private/pprmwait.h
@@ -0,0 +1,112 @@
+/* -*- 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.0 (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.
+ */
+
+#if defined(_PPRMWAIT_H)
+#else
+#define _PPRMWAIT_H
+
+#include "prlock.h"
+#include "prcvar.h"
+#include "prclist.h"
+#include "prthread.h"
+
+#define _PR_HASH_OFFSET 75013
+#define MAX_POLLING_INTERVAL 100
+#define _PR_POLL_COUNT_FUDGE 64
+#define MAX_POLLING_INTERVAL 100
+#define _PR_DEFAULT_HASH_LENGTH 59
+
+#define _MW_REHASH(a, i, m) _MW_HASH((PRUptrdiff)(a) + (i) + _PR_HASH_OFFSET, m)
+#define _MW_HASH(a, m) ((((PRUptrdiff)(a) >> 4) ^ ((PRUptrdiff)(a) >> 10)) % (m))
+#define _MW_ABORTED(_rv) \
+    ((PR_FAILURE == (_rv)) && (PR_PENDING_INTERRUPT_ERROR == PR_GetError()))
+
+typedef enum {_prmw_success, _prmw_rehash, _prmw_error} _PR_HashStory;
+
+typedef struct _PRWaiterHash
+{
+    PRUint16 count;             /* current number in hash table */
+    PRUint16 length;            /* current size of the hash table */
+    PRRecvWait *recv_wait;      /* hash table of receive wait objects */
+} _PRWaiterHash;
+
+typedef enum {_prmw_running, _prmw_stopping, _prmw_stopped} PRMWGroupState;
+
+struct PRWaitGroup
+{
+    PRCList group_link;         /* all groups are linked to each other */
+    PRCList io_ready;           /* list of I/O requests that are ready */
+    PRMWGroupState state;       /* state of this group (so we can shut down) */
+
+    PRLock *ml;                 /* lock for synchronizing this wait group */
+    PRCondVar *io_taken;        /* calling threads notify when they take I/O */
+    PRCondVar *io_complete;     /* calling threads wait here for completions */
+    PRCondVar *new_business;    /* polling thread waits here more work */
+    PRCondVar *mw_manage;       /* used to manage group lists */
+    PRThread* poller;           /* thread that's actually doing the poll() */
+    PRUint16 waiting_threads;   /* number of threads waiting for recv */
+    PRUint16 polling_count;     /* number of elements in the polling list */
+    PRUint32 p_timestamp;       /* pseudo-time group had element removed */
+    PRPollDesc *polling_list;   /* list poller builds for polling */
+    PRIntervalTime last_poll;   /* last time we polled */
+    _PRWaiterHash *waiter;      /* pointer to hash table of wait receive objects */
+
+#ifdef WINNT
+    /*
+     * On NT, idle threads are responsible for getting completed i/o.
+     * They need to add completed i/o to the io_ready list.  Since
+     * idle threads cannot use nspr locks, we have to use an md lock
+     * to protect the io_ready list.
+     */
+    _MDLock mdlock;             /* protect io_ready, waiter, and wait_list */
+    PRCList wait_list;          /* used in place of io_complete.  reuse
+                                 * waitQLinks in the PRThread structure. */
+#endif /* WINNT */
+};
+
+/**********************************************************************
+***********************************************************************
+******************** Wait group enumerations **************************
+***********************************************************************
+**********************************************************************/
+typedef struct _PRGlobalState
+{
+    PRCList group_list;         /* master of the group list */
+    PRWaitGroup *group;         /* the default (NULL) group */
+} _PRGlobalState;
+
+#ifdef WINNT
+extern PRStatus NT_HashRemoveInternal(PRWaitGroup *group, PRFileDesc *fd);
+#endif
+
+typedef enum {_PR_ENUM_UNSEALED=0, _PR_ENUM_SEALED=0x0eadface} _PREnumSeal;
+
+struct PRMWaitEnumerator
+{
+    PRWaitGroup *group;       /* group this enumerator is bound to */
+    PRThread *thread;               /* thread in midst of an enumeration */
+    _PREnumSeal seal;               /* trying to detect deleted objects */
+    PRUint32 p_timestamp;           /* when enumeration was (re)started */
+    PRRecvWait **waiter;            /* pointer into hash table */
+    PRUintn index;                  /* position in hash table */
+    void *pad[4];                   /* some room to grow */
+};
+
+#endif /* defined(_PPRMWAIT_H) */
+
+/* pprmwait.h */
--- a/pr/include/private/primpl.h
+++ b/pr/include/private/primpl.h
@@ -41,16 +41,18 @@
     #undef  _WIN32_WINNT
     #define _WIN32_WINNT 0x0400
 #endif /* _WIN32_WINNT */
 #endif /* WINNT */
 
 #include "nspr.h"
 #include "prpriv.h"
 
+typedef struct PRSegment PRSegment;
+
 #ifdef XP_MAC
 #include "prosdep.h"
 #include "probslet.h"
 #else
 #include "md/prosdep.h"
 #include "obsolete/probslet.h"
 #endif  /* XP_MAC */
 
@@ -123,28 +125,16 @@ typedef struct _MDFileMap _MDFileMap;
 #if defined(_PR_PTHREADS)
 
 /*
 ** The following definitions are unique to implementing NSPR using pthreads.
 ** Since pthreads defines most of the thread and thread synchronization
 ** stuff, this is a pretty small set.
 */
 
-struct _PT_Bookeeping
-{
-    PRLock *ml;                 /* a lock to protect ourselves */
-    PRCondVar *cv;              /* used to signal global things */
-    PRUint16 system, user;      /* a count of the two different types */
-    PRUintn this_many;          /* number of threads allowed for exit */
-    pthread_key_t key;          /* private private data key */
-    pthread_key_t highwater;    /* ordinal value of next key to be allocated */
-    PRThread *first, *last;     /* list of threads we know about */
-    PRInt32 minPrio, maxPrio;   /* range of scheduling priorities */
-};
-
 #define PT_CV_NOTIFIED_LENGTH 6
 typedef struct _PT_Notified _PT_Notified;
 struct _PT_Notified
 {
     PRIntn length;              /* # of used entries in this structure */
     struct
     {
         PRCondVar *cv;          /* the condition variable notified */
@@ -157,17 +147,18 @@ struct _PT_Notified
  * bits defined for pthreads 'state' field 
  */
 #define PT_THREAD_DETACHED  0x01    /* thread can't be joined */
 #define PT_THREAD_GLOBAL    0x02    /* a global thread (unlikely) */
 #define PT_THREAD_SYSTEM    0x04    /* system (not user) thread */
 #define PT_THREAD_PRIMORD   0x08    /* this is the primordial thread */
 #define PT_THREAD_ABORTED   0x10    /* thread has been interrupted */
 #define PT_THREAD_GCABLE    0x20    /* thread is garbage collectible */
-#define PT_THREAD_SUSPENDED 0x40        /* thread has been suspended */
+#define PT_THREAD_SUSPENDED 0x40    /* thread has been suspended */
+#define PT_THREAD_FOREIGN   0x80    /* thread is not one of ours */
 
 /* 
 ** Possible values for thread's suspend field
 ** Note that the first two can be the same as they are really mutually exclusive,
 ** i.e. both cannot be happening at the same time. We have two symbolic names
 ** just as a mnemonic.
 **/
 #define PT_THREAD_RESUMED   0x80    /* thread has been resumed */
@@ -184,23 +175,33 @@ typedef struct PTDebug
     PRUintn recyclesNeeded;
     PRUintn quiescentIO;
     PRUintn locks_created, locks_destroyed;
     PRUintn locks_acquired, locks_released;
     PRUintn cvars_created, cvars_destroyed;
     PRUintn cvars_notified, delayed_cv_deletes;
 } PTDebug;
 
-PR_EXTERN(PTDebug) PT_GetStats(void);
+PR_EXTERN(void) PT_GetStats(PTDebug* here);
 PR_EXTERN(void) PT_FPrintStats(PRFileDesc *fd, const char *msg);
 
+#else
+
+typedef PRUintn PTDebug;
+#define PT_GetStats(_p)
+#define PT_FPrintStats(_fd, _msg)
+
 #endif /* defined(DEBUG) */
 
 #else /* defined(_PR_PTHREADS) */
 
+typedef PRUintn PTDebug;
+#define PT_GetStats(_p)
+#define PT_FPrintStats(_fd, _msg)
+
 /*
 ** This section is contains those parts needed to implement NSPR on
 ** platforms in general. One would assume that the pthreads implementation
 ** included lots of the same types, at least conceptually.
 */
 
 /*
  * Local threads only.  No multiple CPU support and hence all the
@@ -268,17 +269,17 @@ typedef struct _PRInterruptTable {
     const char *name;
     PRUintn missed_bit;
     void (*handler)(void);
 } _PRInterruptTable;
 
 #define _PR_CPU_PTR(_qp) \
     ((_PRCPU*) ((char*) (_qp) - offsetof(_PRCPU,links)))
 
-#if !defined(IRIX)
+#if !defined(IRIX) && !defined(WIN32)
 #define _MD_GET_ATTACHED_THREAD()        (_PR_MD_CURRENT_THREAD())
 #endif
 
 #ifdef _PR_LOCAL_THREADS_ONLY 
 
 PR_EXTERN(struct _PRCPU *)              _pr_currentCPU;
 PR_EXTERN(PRThread *)                   _pr_currentThread;
 PR_EXTERN(PRThread *)                   _pr_lastThread;
@@ -300,18 +301,16 @@ PR_EXTERN(PRInt32)                      
 #define _PR_UNLOCK_HEAP() if (_pr_currentCPU) _PR_INTSON(_is); }
 
 #endif /* _PR_LOCAL_THREADS_ONLY */
 
 #if defined(_PR_GLOBAL_THREADS_ONLY)
 
 #define _MD_GET_INTSOFF() 0
 #define _MD_SET_INTSOFF(_val)
-#define _PR_SET_INTSOFF(_is)
-#define _PR_GET_INTSOFF(_is)
 #define _PR_INTSOFF(_is)
 #define _PR_FAST_INTSON(_is)
 #define _PR_INTSON(_is)
 #define _PR_THREAD_LOCK(_thread)
 #define _PR_THREAD_UNLOCK(_thread)
 #define _PR_RUNQ_LOCK(cpu)
 #define _PR_RUNQ_UNLOCK(cpu)
 #define _PR_SLEEPQ_LOCK(thread)
@@ -332,21 +331,16 @@ PR_EXTERN(PRInt32)                      
 
 #define _PR_THREAD_SWITCH_CPU(_thread, _newCPU)
 
 #define _PR_IS_NATIVE_THREAD(thread) 1
 #define _PR_IS_NATIVE_THREAD_SUPPORTED() 1
 
 #else
 
-#define _PR_SET_INTSOFF(_val) \
-    PR_BEGIN_MACRO \
-        _PR_MD_SET_INTSOFF(_val); \
-    PR_END_MACRO
-
 #define _PR_INTSOFF(_is) \
     PR_BEGIN_MACRO \
         (_is) = _PR_MD_GET_INTSOFF(); \
         _PR_MD_SET_INTSOFF(1); \
     PR_END_MACRO
 
 #define _PR_FAST_INTSON(_is) \
     PR_BEGIN_MACRO \
@@ -551,36 +545,28 @@ extern PRUint32 _PR_CondVarToString(PRCo
 
 PR_EXTERN(void) _PR_Notify(PRMonitor *mon, PRBool all, PRBool sticky);
 
 typedef struct _PRPerThreadExit {
     PRThreadExit func;
     void *arg;
 } _PRPerThreadExit;
 
-/*
- * Thread private data destructor array
- * There is a destructor (or NULL) associated with each key and
- *    applied to all threads known to the system.
- *  Storage allocated in prtpd.c.
- */
-extern PRThreadPrivateDTOR *_pr_tpd_destructors;
-
 /* PRThread.flags */
 #define _PR_SYSTEM          0x01
 #define _PR_INTERRUPT       0x02
 #define _PR_ATTACHED        0x04        /* created via PR_AttachThread */
 #define _PR_PRIMORDIAL      0x08        /* the thread that called PR_Init */
 #define _PR_ON_SLEEPQ       0x10        /* thread is on the sleepQ */
 #define _PR_ON_PAUSEQ       0x20        /* thread is on the pauseQ */
 #define _PR_SUSPENDING      0x40        /* thread wants to suspend */
 #define _PR_GLOBAL_SCOPE    0x80        /* thread is global scope */
 #define _PR_IDLE_THREAD     0x200       /* this is an idle thread        */
 #define _PR_GCABLE_THREAD   0x400       /* this is a collectable thread */
-#define _PR_BOUND_THREAD    0x800       /* a bound thread (only on solaris) */
+#define _PR_BOUND_THREAD    0x800       /* a bound thread */
 
 /* PRThread.state */
 #define _PR_UNBORN       0
 #define _PR_RUNNABLE     1
 #define _PR_RUNNING      2
 #define _PR_LOCK_WAIT    3
 #define _PR_COND_WAIT    4
 #define _PR_JOIN_WAIT    5
@@ -662,19 +648,19 @@ extern PRCList _pr_deadUserQ;
 #define _PR_DEC_DEADUSER    (_pr_numUserDead--)
 #define _PR_NUM_DEADUSER    (_pr_numUserDead)
 
 extern PRUint32 _pr_utid;
 
 extern struct _PRCPU  *_pr_primordialCPU;
 
 extern PRLock *_pr_activeLock;          /* lock for userActive and systemActive */
-extern PRUintn _pr_userActive;          /* number of active user threads */
-extern PRUintn _pr_systemActive;        /* number of active system threads */
-extern PRUintn _pr_primordialExitCount; /* number of user threads left
+extern PRInt32 _pr_userActive;          /* number of active user threads */
+extern PRInt32 _pr_systemActive;        /* number of active system threads */
+extern PRInt32 _pr_primordialExitCount; /* number of user threads left
                                          * before the primordial thread
                                          * can exit.  */
 extern PRCondVar *_pr_primordialExitCVar; /* the condition variable for
                                            * notifying the primordial thread
                                            * when all other user threads
                                            * have terminated.  */
 
 extern PRUintn _pr_maxPTDs;
@@ -713,33 +699,39 @@ PR_EXTERN(PRThread*) _PR_CreateThread(PR
                                      PRThreadScope scope,
                                      PRThreadState state,
                                      PRUint32 stackSize,
                      PRUint32 flags);
 
 extern void _PR_NativeDestroyThread(PRThread *thread);
 extern void _PR_UserDestroyThread(PRThread *thread);
 
-PR_EXTERN(PRThread*) _PRI_AttachThread(
+extern PRThread* _PRI_AttachThread(
     PRThreadType type, PRThreadPriority priority,
     PRThreadStack *stack, PRUint32 flags);
 
+extern void _PRI_DetachThread(void);
+
+
 #define _PR_IO_PENDING(_thread) ((_thread)->io_pending)
 
 PR_EXTERN(void) _PR_MD_INIT_CPUS();
 #define    _PR_MD_INIT_CPUS _MD_INIT_CPUS
 
 PR_EXTERN(void) _PR_MD_WAKEUP_CPUS();
 #define    _PR_MD_WAKEUP_CPUS _MD_WAKEUP_CPUS
 
 /* Interrupts related */
 
 PR_EXTERN(void) _PR_MD_STOP_INTERRUPTS(void);
 #define    _PR_MD_STOP_INTERRUPTS _MD_STOP_INTERRUPTS
 
+PR_EXTERN(void) _PR_MD_ENABLE_CLOCK_INTERRUPTS(void);
+#define    _PR_MD_ENABLE_CLOCK_INTERRUPTS _MD_ENABLE_CLOCK_INTERRUPTS
+
 PR_EXTERN(void) _PR_MD_DISABLE_CLOCK_INTERRUPTS(void);
 #define    _PR_MD_DISABLE_CLOCK_INTERRUPTS _MD_DISABLE_CLOCK_INTERRUPTS
 
 PR_EXTERN(void) _PR_MD_BLOCK_CLOCK_INTERRUPTS(void);
 #define    _PR_MD_BLOCK_CLOCK_INTERRUPTS _MD_BLOCK_CLOCK_INTERRUPTS
 
 PR_EXTERN(void) _PR_MD_UNBLOCK_CLOCK_INTERRUPTS(void);
 #define    _PR_MD_UNBLOCK_CLOCK_INTERRUPTS _MD_UNBLOCK_CLOCK_INTERRUPTS
@@ -990,44 +982,26 @@ extern PRInt32 _PR_MD_READ(PRFileDesc *f
 extern PRInt32 _PR_MD_WRITE(PRFileDesc *fd, const void *buf, PRInt32 amount);
 #define    _PR_MD_WRITE _MD_WRITE
 
 extern PRInt32 _PR_MD_WRITEV(
     PRFileDesc *fd, struct PRIOVec *iov,
     PRInt32 iov_size, PRIntervalTime timeout);
 #define    _PR_MD_WRITEV _MD_WRITEV
 
-extern PRInt32 _PR_MD_LSEEK(PRFileDesc *fd, PRInt32 offset, int whence);
-#define    _PR_MD_LSEEK _MD_LSEEK
-
-extern PRInt64 _PR_MD_LSEEK64(PRFileDesc *fd, PRInt64 offset, int whence);
-#define    _PR_MD_LSEEK64 _MD_LSEEK64
-
 extern PRInt32 _PR_MD_FSYNC(PRFileDesc *fd);
 #define    _PR_MD_FSYNC _MD_FSYNC
 
 extern PRInt32 _PR_MD_DELETE(const char *name);
 #define        _PR_MD_DELETE _MD_DELETE
 
-extern PRInt32 _PR_MD_GETFILEINFO(const char *fn, PRFileInfo *info);
-#define _PR_MD_GETFILEINFO _MD_GETFILEINFO
-
-extern PRInt32 _PR_MD_GETFILEINFO64(const char *fn, PRFileInfo64 *info);
-#define _PR_MD_GETFILEINFO64 _MD_GETFILEINFO64
-
-extern PRInt32 _PR_MD_GETOPENFILEINFO(const PRFileDesc *fd, PRFileInfo *info);
-#define _PR_MD_GETOPENFILEINFO _MD_GETOPENFILEINFO
-
-extern PRInt32 _PR_MD_GETOPENFILEINFO64(const PRFileDesc *fd, PRFileInfo64 *info);
-#define _PR_MD_GETOPENFILEINFO64 _MD_GETOPENFILEINFO64
-
 extern PRInt32 _PR_MD_RENAME(const char *from, const char *to);
 #define _PR_MD_RENAME _MD_RENAME
 
-extern PRInt32 _PR_MD_ACCESS(const char *name, PRIntn how);
+extern PRInt32 _PR_MD_ACCESS(const char *name, PRAccessHow how);
 #define _PR_MD_ACCESS _MD_ACCESS
 
 extern PRInt32 _PR_MD_STAT(const char *name, struct stat *buf);
 #define _PR_MD_STAT _MD_STAT
 
 extern PRInt32 _PR_MD_MKDIR(const char *name, PRIntn mode);
 #define _PR_MD_MKDIR _MD_MKDIR
 
@@ -1169,26 +1143,73 @@ PR_EXTERN(void *) _PR_MD_GET_SP(PRThread
 
 /************************************************************************/
 /*************************************************************************
 ** The remainder of the definitions are shared by pthreads and the classic
 ** NSPR code. These too may be conditionalized.
 *************************************************************************/
 /************************************************************************/
 
+extern PRInt32 _PR_MD_LSEEK(PRFileDesc *fd, PRInt32 offset, PRSeekWhence whence);
+#define    _PR_MD_LSEEK _MD_LSEEK
+
+extern PRInt64 _PR_MD_LSEEK64(PRFileDesc *fd, PRInt64 offset, PRSeekWhence whence);
+#define    _PR_MD_LSEEK64 _MD_LSEEK64
+
+extern PRInt32 _PR_MD_GETFILEINFO(const char *fn, PRFileInfo *info);
+#define _PR_MD_GETFILEINFO _MD_GETFILEINFO
+
+extern PRInt32 _PR_MD_GETFILEINFO64(const char *fn, PRFileInfo64 *info);
+#define _PR_MD_GETFILEINFO64 _MD_GETFILEINFO64
+
+extern PRInt32 _PR_MD_GETOPENFILEINFO(const PRFileDesc *fd, PRFileInfo *info);
+#define _PR_MD_GETOPENFILEINFO _MD_GETOPENFILEINFO
+
+extern PRInt32 _PR_MD_GETOPENFILEINFO64(const PRFileDesc *fd, PRFileInfo64 *info);
+#define _PR_MD_GETOPENFILEINFO64 _MD_GETOPENFILEINFO64
+
+
+/*****************************************************************************/
+/************************** File descriptor caching **************************/
+/*****************************************************************************/
+extern void _PR_InitFdCache(void);
+extern void _PR_CleanupFdCache(void);
+extern PRFileDesc *_PR_Getfd(void);
+extern void _PR_Putfd(PRFileDesc *fd);
+
+/*
+ * These flags are used by NSPR temporarily in the poll
+ * descriptor's out_flags field to record the mapping of
+ * NSPR's poll flags to the system poll flags.
+ *
+ * If _PR_POLL_READ_SYS_WRITE bit is set, it means the
+ * PR_POLL_READ flag specified by the topmost layer is
+ * mapped to the WRITE flag at the system layer.  Similarly
+ * for the other three _PR_POLL_XXX_SYS_YYY flags.  It is
+ * assumed that the PR_POLL_EXCEPT flag doesn't get mapped
+ * to other flags.
+ */
+#define _PR_POLL_READ_SYS_READ     0x1
+#define _PR_POLL_READ_SYS_WRITE    0x2
+#define _PR_POLL_WRITE_SYS_READ    0x4
+#define _PR_POLL_WRITE_SYS_WRITE   0x8
+
 /*
 ** These methods are coerced into file descriptor methods table
 ** when the intended service is inappropriate for the particular
 ** type of file descriptor.
 */
 extern PRIntn _PR_InvalidInt(void);
+extern PRInt16 _PR_InvalidInt16(void);
 extern PRInt64 _PR_InvalidInt64(void);
 extern PRStatus _PR_InvalidStatus(void);
 extern PRFileDesc *_PR_InvalidDesc(void);
 
+extern PRIOMethods _pr_faulty_methods;
+
 extern PRStatus _PR_MapOptionName(
     PRSockOption optname, PRInt32 *level, PRInt32 *name);
 extern void _PR_InitThreads(
     PRThreadType type, PRThreadPriority priority, PRUintn maxPTDs);
 
 PR_EXTERN(void) _PR_MD_START_INTERRUPTS(void);
 #define    _PR_MD_START_INTERRUPTS _MD_START_INTERRUPTS
 
@@ -1224,19 +1245,19 @@ struct PRCondVar {
 #endif /* defined(_PR_PTHREADS) */
 };
 
 /************************************************************************/
 
 struct PRMonitor {
     const char* name;           /* monitor name for debugging */
 #if defined(_PR_PTHREADS)
-        PRLock lock;                /* the lock struture structure */
+    PRLock lock;                /* the lock struture structure */
     pthread_t owner;            /* the owner of the lock or zero */
-    PRCondVar cvar;             /* condition variable queue */
+    PRCondVar *cvar;            /* condition variable queue */
 #else  /* defined(_PR_PTHREADS) */
     PRCondVar *cvar;            /* associated lock and condition variable queue */
 #endif /* defined(_PR_PTHREADS) */
     PRUint32 entryCount;        /* # of times re-entered */
 };
 
 /************************************************************************/
 
@@ -1269,83 +1290,104 @@ struct PRThreadStack {
         PRThread* thr;          /* back pointer to thread owning this stack */
 
 #if defined(_PR_PTHREADS)
 #else /* defined(_PR_PTHREADS) */
     _MDThreadStack md;
 #endif /* defined(_PR_PTHREADS) */
 };
 
+/*
+ * Thread private data destructor array
+ * There is a destructor (or NULL) associated with each key and
+ *    applied to all threads known to the system.
+ *  Storage allocated in prtpd.c.
+ */
+extern PRThreadPrivateDTOR *_pr_tpd_destructors;
+extern void _PR_DestroyThreadPrivate(PRThread*);
 
+typedef void (PR_CALLBACK *_PRStartFn)(void *);
 
 struct PRThread {
     PRUint32 state;                 /* thread's creation state */
     PRThreadPriority priority;      /* apparent priority, loosly defined */
-    PRInt32 errorStringSize;        /* byte length of current error string | zero */
-    PRErrorCode errorCode;          /* current NSPR error code | zero */
-    PRInt32 osErrorCode;            /* mapping of errorCode | zero */
-    
-    char *errorString;              /* current error string | NULL */
 
     void *arg;                      /* argument to the client's entry point */
-    void (PR_CALLBACK *startFunc)(void *arg); /* the root of the client's thread */
+    _PRStartFn startFunc;           /* the root of the client's thread */
 
     PRThreadStack *stack;           /* info about thread's stack (for GC) */
     void *environment;              /* pointer to execution environment */
 
     PRThreadDumpProc dump;          /* dump thread info out */
     void *dumpArg;                  /* argument for the dump function */
 
+    /*
+    ** Per thread private data
+    */
+    PRUint32 tpdLength;             /* thread's current vector length */
+    void **privateData;             /* private data vector or NULL */
+    PRInt32 errorStringSize;        /* byte length of current error string | zero */
+    PRErrorCode errorCode;          /* current NSPR error code | zero */
+    PRInt32 osErrorCode;            /* mapping of errorCode | zero */
+    char *errorString;              /* current error string | NULL */
+
 #if defined(_PR_PTHREADS)
     pthread_t id;                   /* pthread identifier for the thread */
     PRBool okToDelete;              /* ok to delete the PRThread struct? */
     PRCondVar *io_cv;               /* a condition used to run i/o */
     PRCondVar *waiting;             /* where the thread is waiting | NULL */
     void *sp;                       /* recorded sp for garbage collection */
     PRThread *next, *prev;          /* simple linked list of all threads */
     PRUint32 suspend;               /* used to store suspend and resume flags */
 #ifdef PT_NO_SIGTIMEDWAIT
     pthread_mutex_t suspendResumeMutex;
     pthread_cond_t suspendResumeCV;
 #endif
 #else /* defined(_PR_PTHREADS) */
     _MDLock threadLock;             /* Lock to protect thread state variables.
-                                    * Protects the following fields:
-                                    *     state
-                                    *     priority
-                                    *     links
-                                    *     wait
-                                    *     cpu
-                                    */
+                                     * Protects the following fields:
+                                     *     state
+                                     *     priority
+                                     *     links
+                                     *     wait
+                                     *     cpu
+                                     */
     PRUint32 queueCount;
     PRUint32 waitCount;
 
     PRCList active;                 /* on list of all active threads        */
     PRCList links;
     PRCList waitQLinks;             /* when thread is PR_Wait'ing */
     PRCList lockList;               /* list of locks currently holding */
     PRIntervalTime sleep;           /* sleep time when thread is sleeping */
     struct _wait {
         struct PRLock *lock;
         struct PRCondVar *cvar;
     } wait;
 
     PRUint32 id;
     PRUint32 flags;
-    PRUint32 no_sched;
+    PRUint32 no_sched;              /* Don't schedule the thread to run.
+                                     * This flag has relevance only when
+                                     * multiple NSPR CPUs are created.
+                                     * When a thread is de-scheduled, there
+                                     * is a narrow window of time in which
+                                     * the thread is put on the run queue
+                                     * but the scheduler is actually using
+                                     * the stack of this thread.  It is safe
+                                     * to run this thread on a different CPU
+                                     * only when its stack is not in use on
+                                     * any other CPU.  The no_sched flag is
+                                     * set during this interval to prevent
+                                     * the thread from being scheduled on a
+                                     * different CPU.
+                                     */
     PRUint32 numExits;
     _PRPerThreadExit *ptes;
 
-
-    /*
-    ** Per thread private data
-    */
-    PRUint32 tpdLength;             /* thread's current vector length */
-    void **privateData;             /* private data vector or NULL */
-
     /* thread termination condition variable for join */
     PRCondVar *term;
 
     _PRCPU *cpu;                    /* cpu to which this thread is bound    */
     PRUint32 threadAllocatedOnStack;/* boolean */
 
     /* When an async IO is in progress and a second async IO cannot be 
      * initiated, the io_pending flag is set to true.  Some platforms will
@@ -1408,43 +1450,69 @@ extern void _PR_InitCMon(void);
 extern void _PR_InitIO(void);
 extern void _PR_InitLog(void);
 extern void _PR_InitNet(void);
 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_NotifyCondVar(PRCondVar *cvar, PRThread *me);
 extern void _PR_CleanupThread(PRThread *thread);
 extern void _PR_CleanupTPD(void);
 extern void _PR_Cleanup(void);
 extern void _PR_LogCleanup(void);
 extern void _PR_InitLayerCache(void);
 
 extern PRBool _pr_initialized;
 extern void _PR_ImplicitInitialization(void);
 extern PRBool _PR_Obsolete(const char *obsolete, const char *preferred);
 
 /************************************************************************/
 
 struct PRSegment {
-    PRSegmentAccess access;
     void *vaddr;
     PRUint32 size;
     PRUintn flags;
 #if defined(_PR_PTHREADS)
 #else  /* defined(_PR_PTHREADS) */
     _MDSegment md;
 #endif /* defined(_PR_PTHREADS) */
 };
 
 /* PRSegment.flags */
 #define _PR_SEG_VM    0x1
 
+/***********************************************************************
+** 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
+**   address.
+** INPUTS:	size:  size of the desired memory segment
+**          vaddr:  address at which the newly aquired segment is to be
+**                  mapped into memory.
+** OUTPUTS:	a memory segment is allocated, a PRSegment is allocated
+** RETURN:	pointer to PRSegment
+***********************************************************************/
+extern PRSegment* _PR_NewSegment(PRUint32 size, void *vaddr);
+
+/***********************************************************************
+** FUNCTION:	_PR_DestroySegment()
+** DESCRIPTION:
+**   The memory segment and the PRSegment are freed
+** INPUTS:	seg:  pointer to PRSegment to be freed
+** OUTPUTS:	the the PRSegment and its associated memory segment are freed
+** RETURN:	void
+***********************************************************************/
+extern void _PR_DestroySegment(PRSegment *seg);
+
 /************************************************************************/
 
 extern PRInt32 _pr_pageSize;
 extern PRInt32 _pr_pageShift;
 
 extern PRLogModuleInfo *_pr_clock_lm;
 extern PRLogModuleInfo *_pr_cmon_lm;
 extern PRLogModuleInfo *_pr_io_lm;
@@ -1460,24 +1528,19 @@ extern PRFileDesc *_pr_stdout;
 extern PRFileDesc *_pr_stderr;
 
 #if defined(_PR_INET6)
 extern PRBool _pr_ipv6_enabled;  /* defined in prnetdb.c */
 #endif
 
 /* Overriding malloc, free, etc. */
 #if !defined(_PR_NO_PREEMPT) && defined(XP_UNIX) \
-        && (!defined(SOLARIS) || !defined(_PR_GLOBAL_THREADS_ONLY)) \
-        && (!defined(AIX) || !defined(_PR_PTHREADS)) \
-        && (!defined(OSF1) || !defined(_PR_PTHREADS)) \
-        && (!defined(HPUX) || !defined(_PR_PTHREADS)) \
-        && (!defined(IRIX) || !defined(_PR_PTHREADS)) \
-        && (!defined(LINUX) || !defined(_PR_PTHREADS)) \
-	&& (!defined(RHAPSODY)) \
+        && !defined(_PR_PTHREADS) && !defined(_PR_GLOBAL_THREADS_ONLY) \
         && !defined(PURIFY) \
+        && !defined(RHAPSODY) \
         && !(defined (UNIXWARE) && defined (USE_SVR4_THREADS))
 #define _PR_OVERRIDE_MALLOC
 #endif
 
 /*************************************************************************
 * External machine-dependent code provided by each OS.                     *                                                                     *
 *************************************************************************/
 
@@ -1526,16 +1589,19 @@ extern PRIntn _PR_MD_PUT_ENV(const char 
 /* Atomic operations */
 
 extern void _PR_MD_INIT_ATOMIC(void);
 #define    _PR_MD_INIT_ATOMIC _MD_INIT_ATOMIC
 
 extern PRInt32 _PR_MD_ATOMIC_INCREMENT(PRInt32 *);
 #define    _PR_