Move NSPR WinCE port closer to the tip. WINCE_20020710_BRANCH
authorblythe%netscape.com
Thu, 11 Jul 2002 23:58:46 +0000
branchWINCE_20020710_BRANCH
changeset 2432 8ca49efa86cc94e31574030f46bcb47e4448341d
parent 2425 f648e291f81a83b50d5e989b8ed055d8ca580aea
child 2433 eb210d3ca374e76cdbc51497eae6ea86b96b5361
push idunknown
push userunknown
push dateunknown
Move NSPR WinCE port closer to the tip. Still has a linkage error....
config/Makefile.in
config/WIN32.mk
config/WINCE.mk
config/arch.mk
config/autoconf.mk.in
config/rules.mk
configure
configure.in
gmakefile.win
pr/include/md/_pcos.h
pr/include/md/_win32_errors.h
pr/include/md/_win32_time.h
pr/include/md/_win32_unicode.h
pr/include/md/_wince.cfg
pr/include/md/_wince.h
pr/include/md/_wince_libc.h
pr/include/md/_wintime.h
pr/include/md/prosdep.h
pr/include/obsolete/probslet.h
pr/include/private/pprthred.h
pr/src/io/prfile.c
pr/src/io/prio.c
pr/src/io/priometh.c
pr/src/io/prlog.c
pr/src/io/prprf.c
pr/src/io/prsocket.c
pr/src/linking/prlink.c
pr/src/md/windows/Makefile.in
pr/src/md/windows/ntgc.c
pr/src/md/windows/ntmisc.c
pr/src/md/windows/ntsec.c
pr/src/md/windows/objs.mk
pr/src/md/windows/w32ipcsem.c
pr/src/md/windows/w32netdb.c
pr/src/md/windows/w32rng.c
pr/src/md/windows/w32shm.c
pr/src/md/windows/w32time.c
pr/src/md/windows/w32unicode.c
pr/src/md/windows/w95io.c
pr/src/md/windows/w95thred.c
pr/src/md/windows/win32_errors.c
pr/src/misc/prerror.c
pr/src/misc/prerrortable.c
pr/src/misc/prnetdb.c
pr/src/misc/prtime.c
pr/src/threads/combined/prucv.c
pr/src/threads/combined/prulock.c
pr/src/threads/combined/pruthr.c
pr/src/threads/prcthr.c
pr/src/threads/prdump.c
pr/src/threads/prtpd.c
--- a/config/Makefile.in
+++ b/config/Makefile.in
@@ -45,26 +45,28 @@ INTERNAL_TOOLS	= 1
 # autoconf.mk must be deleted last (from the top-level directory)
 # because it is included by every makefile.
 DIST_GARBAGE	= nsprincl.mk nsprincl.sh nspr-config
 
 RELEASE_BINS	= nspr-config
 
 include $(topsrcdir)/config/config.mk
 
+ifneq ($(OS_ARCH),WINCE)
 CSRCS	= now.c
+endif
 
 # This version hasn't been ported for us; the one in mozilla/config has
 ifneq ($(OS_ARCH),OS2)
 CSRCS  += nsinstall.c
  
 PLSRCS	= nfspwd.pl
 endif
 
-ifeq (,$(filter-out WINNT OS2,$(OS_ARCH)))
+ifeq (,$(filter-out WINNT WINCE OS2,$(OS_ARCH)))
 PROG_SUFFIX = .exe
 else
 PROG_SUFFIX =
 endif
 
 # Temporary workaround to disable the generation of
 # library build time because now.c uses the 'long long'
 # data type that's not available on some platforms.
@@ -103,27 +105,29 @@ endif
 
 ifeq ($(MOZ_OS2_TOOLS),PGCC)
 XCFLAGS = $(OS_CFLAGS)
 XLDOPTS = -Zlinker /PM:VIO
 endif
 
 include $(topsrcdir)/config/rules.mk
 
+ifneq ($(OS_ARCH),WINCE)
 PROGS	= $(OBJDIR)/now$(PROG_SUFFIX)
+endif
 
-ifeq (,$(filter-out OS2 WINNT,$(OS_ARCH)))
+ifeq (,$(filter-out OS2 WINNT WINCE,$(OS_ARCH)))
 TARGETS = $(PROGS)
 else
 PROGS	+= $(OBJDIR)/nsinstall$(PROG_SUFFIX)
 TARGETS = $(PROGS) $(PLSRCS:.pl=)
 endif
 
 OUTOPTION = -o # end of the line
-ifeq (,$(filter-out WINNT WIN95,$(OS_TARGET)))
+ifeq (,$(filter-out WINNT WIN95 WINCE,$(OS_TARGET)))
 OUTOPTION = /Fe
 endif
 
 # Redefine MAKE_OBJDIR for just this directory
 define MAKE_OBJDIR
 if test ! -d $(@D); then rm -rf $(@D); mkdir $(@D); else true; fi
 endef
 
--- a/config/WIN32.mk
+++ b/config/WIN32.mk
@@ -64,17 +64,21 @@ 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 BUILD_OPT
+ifeq ($(OS_TARGET),WINCE)
+OS_CFLAGS += -Zl
+else
 OS_CFLAGS += -MD
+endif
 OPTIMIZER = -O2
 DEFINES = -UDEBUG -U_DEBUG -DNDEBUG
 DLLFLAGS = -OUT:"$@"
 OBJDIR_TAG = _OPT
 
 # Add symbolic information for use by a profiler
 ifdef MOZ_PROFILE
 OPTIMIZER += -Z7
@@ -82,21 +86,25 @@ 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
 #
+ifeq ($(OS_TARGET),WINCE)
+OS_CFLAGS += -Zl
+else
 ifdef USE_DEBUG_RTL
 OS_CFLAGS += -MDd
 else
 OS_CFLAGS += -MD
 endif
+endif
 OPTIMIZER = -Od -Z7
 #OPTIMIZER = -Zi -Fd$(OBJDIR)/ -Od
 DEFINES = -DDEBUG -D_DEBUG -UNDEBUG
 
 DLLFLAGS = -DEBUG -DEBUGTYPE:CV -OUT:"$@"
 ifdef GLOWCODE
 DLLFLAGS = -DEBUG -DEBUGTYPE:both -INCLUDE:_GlowCode -OUT:"$@"
 endif
@@ -135,32 +143,44 @@ endif
 #
 ifeq ($(OS_TARGET),WINNT)
 OS_CFLAGS += -GT
 ifeq ($(CPU_ARCH),x86)
 OS_CFLAGS += -G5
 endif
 DEFINES += -DWINNT
 else
-DEFINES += -DWIN95 -D_PR_GLOBAL_THREADS_ONLY
+DEFINES += -D_PR_GLOBAL_THREADS_ONLY
+ifeq ($(OS_TARGET),WINCE)
+DEFINES += -DWINCE -D$(CPU_ARCH) -DUNICODE -D_UNICODE -DUNDER_CE=300 -D_WIN32_WCE=300
+ifeq ($(CPU_ARCH),x86)
+DEFINES += -D_WIN32_WCE_CEPC
+endif
+else
+DEFINES += -DWIN95
+endif
 endif
 
 ifeq ($(CPU_ARCH),x86)
 DEFINES += -D_X86_
 else
 ifeq ($(CPU_ARCH),MIPS)
 DEFINES += -D_MIPS_
 else
 ifeq ($(CPU_ARCH),ALPHA)
 DEFINES += -D_ALPHA_=1
 else
+ifeq ($(CPU_ARCH),ARM)
+DEFINES += -D_ARM_=1
+else
 CPU_ARCH = processor_is_undefined
 endif
 endif
 endif
+endif
 
 # Name of the binary code directories
 
 ifeq ($(CPU_ARCH),x86)
 CPU_ARCH_TAG =
 else
 CPU_ARCH_TAG = $(CPU_ARCH)
 endif
@@ -168,9 +188,17 @@ endif
 ifdef USE_DEBUG_RTL
 OBJDIR_SUFFIX = OBJD
 else
 OBJDIR_SUFFIX = OBJ
 endif
 
 OBJDIR_NAME = $(OS_CONFIG)$(CPU_ARCH_TAG)$(OBJDIR_TAG).$(OBJDIR_SUFFIX)
 
+ifeq ($(OS_TARGET),WINCE)
+ifeq ($(TARGETCPU),X86)
+OS_DLLFLAGS = -nologo -DLL -SUBSYSTEM:WINDOWSCE,3.00 -MACHINE:IX86 -ENTRY:_DllMainCRTStartup -STACK:0x10000,0x1000 -NODEFAULTLIB:OLDNAMES.lib
+else
+OS_DLLFLAGS = -nologo -DLL -SUBSYSTEM:WINDOWSCE,3.00 -MACHINE:ARM -ENTRY:_DllMainCRTStartup -STACK:0x10000,0x1000 -NODEFAULTLIB:OLDNAMES.lib
+endif
+else
 OS_DLLFLAGS = -nologo -DLL -SUBSYSTEM:WINDOWS -PDB:NONE
+endif
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/config/WINCE.mk
@@ -0,0 +1,39 @@
+# 
+# The contents of this file are subject to the Mozilla Public
+# License Version 1.1 (the "License"); you may not use this file
+# except in compliance with the License. You may obtain a copy of
+# the License at http://www.mozilla.org/MPL/
+# 
+# Software distributed under the License is distributed on an "AS
+# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+# implied. See the License for the specific language governing
+# rights and limitations under the License.
+# 
+# The Original Code is the Netscape Portable Runtime (NSPR).
+# 
+# The Initial Developer of the Original Code is Netscape
+# Communications Corporation.  Portions created by Netscape are 
+# Copyright (C) 1998-2000 Netscape Communications Corporation.  All
+# Rights Reserved.
+# 
+# Contributor(s):
+#  Garrett Arch Blythe  01/15/2002
+# 
+# Alternatively, the contents of this file may be used under the
+# terms of the GNU General Public License Version 2 or later (the
+# "GPL"), in which case the provisions of the GPL are applicable 
+# instead of those above.  If you wish to allow use of your 
+# version of this file only under the terms of the GPL and not to
+# allow others to use your version of this file under the MPL,
+# indicate your decision by deleting the provisions above and
+# replace them with the notice and other provisions required by
+# the GPL.  If you do not delete the provisions above, a recipient
+# may use your version of this file under either the MPL or the
+# GPL.
+# 
+
+#
+# Config stuff for WINCE
+#
+
+include $(MOD_DEPTH)/config/WIN32.mk
--- a/config/arch.mk
+++ b/config/arch.mk
@@ -195,16 +195,34 @@ ifeq ($(OS_ARCH),CYGWIN_98-4.10)
 	OS_TARGET := WIN95
 endif
 ifeq ($(OS_ARCH),OS2)
 	OS_ARCH   := OS2
 	OS_TARGET := OS2
 endif
 
 #
+# Cross compiling for WinCE needs a special case here.
+# Only WCE300 (WinCE version 3.00) handled thus far.
+#
+# OSVERSION, and TARGETCPU are defined in a WinCE build environment.
+# Jump through hoops to make X86 look like x86 for the build system.
+#
+ifeq ($(OSVERSION),WCE300)
+	OS_ARCH := WINCE
+	OS_TARGET := WINCE
+	OS_RELEASE := 3.00
+	ifeq ($(TARGETCPU),X86)
+		CPU_ARCH := x86
+	else
+		CPU_ARCH := $(TARGETCPU)
+	endif
+else
+
+#
 # On WIN32, we also define the variable CPU_ARCH.
 #
 
 ifeq ($(OS_ARCH), WINNT)
 	ifneq ($(subst /,_,$(shell uname -s)),OS_2)
 		CPU_ARCH := $(shell uname -p)
 	else
 		CPU_ARCH := $(shell uname -m)
@@ -264,16 +282,17 @@ ifeq ($(OS_ARCH), CYGWIN32_NT)
 	#
 	ifneq (,$(findstring 86,$(CPU_ARCH)))
 		CPU_ARCH = x86
 	endif
 endif
 endif
 endif
 endif
+endif
 
 ifndef OS_TARGET
 	OS_TARGET := $(OS_ARCH)
 endif
 
 ifeq ($(OS_TARGET), WIN95)
 	OS_RELEASE := 4.0
 endif
--- a/config/autoconf.mk.in
+++ b/config/autoconf.mk.in
@@ -72,16 +72,17 @@ OS_CPPFLAGS	= @CPPFLAGS@
 OS_CFLAGS	= $(OS_CPPFLAGS) @CFLAGS@ $(DSO_CFLAGS)
 OS_CXXFLAGS	= $(OS_CPPFLAGS) @CXXFLAGS@ $(DSO_CFLAGS)
 OS_LIBS         = @OS_LIBS@
 OS_LDFLAGS	= @LDFLAGS@
 OS_DLLFLAGS	= @OS_DLLFLAGS@
 DLLFLAGS	= @DLLFLAGS@
 EXEFLAGS  = @EXEFLAGS@
 OPTIMIZER	= @OPTIMIZER@
+DLL_LIBS    = @DLL_LIBS@
 
 MKSHLIB		= @MKSHLIB@
 DSO_CFLAGS	= @DSO_CFLAGS@
 DSO_LDOPTS	= @DSO_LDOPTS@
 
 RESOLVE_LINK_SYMBOLS = @RESOLVE_LINK_SYMBOLS@
 
 HOST_CC		= @HOST_CC@
--- a/config/rules.mk
+++ b/config/rules.mk
@@ -94,23 +94,23 @@ endif
 # - SHARED_LIBRARY: a shared (dynamic link) library
 # - IMPORT_LIBRARY: an import library, used only on Windows and OS/2
 #
 # The names of these libraries can be generated by simply specifying
 # LIBRARY_NAME and LIBRARY_VERSION.
 #
 
 ifdef LIBRARY_NAME
-ifeq (,$(filter-out WINNT OS2,$(OS_ARCH)))
+ifeq (,$(filter-out WINCE WINNT OS2,$(OS_ARCH)))
 
 #
 # Win95, Win16, and OS/2 require library names conforming to the 8.3 rule.
 # other platforms do not.
 #
-ifeq (,$(filter-out WIN95 OS2,$(OS_TARGET)))
+ifeq (,$(filter-out WINCE WIN95 OS2,$(OS_TARGET)))
 LIBRARY		= $(OBJDIR)/$(LIBRARY_NAME)$(LIBRARY_VERSION)_s.$(LIB_SUFFIX)
 SHARED_LIBRARY	= $(OBJDIR)/$(LIBRARY_NAME)$(LIBRARY_VERSION).$(DLL_SUFFIX)
 IMPORT_LIBRARY	= $(OBJDIR)/$(LIBRARY_NAME)$(LIBRARY_VERSION).$(LIB_SUFFIX)
 else
 LIBRARY		= $(OBJDIR)/lib$(LIBRARY_NAME)$(LIBRARY_VERSION)_s.$(LIB_SUFFIX)
 SHARED_LIBRARY	= $(OBJDIR)/lib$(LIBRARY_NAME)$(LIBRARY_VERSION).$(DLL_SUFFIX)
 IMPORT_LIBRARY	= $(OBJDIR)/lib$(LIBRARY_NAME)$(LIBRARY_VERSION).$(LIB_SUFFIX)
 endif
@@ -125,17 +125,17 @@ ifdef MKSHLIB
 SHARED_LIBRARY	= $(OBJDIR)/lib$(LIBRARY_NAME)$(LIBRARY_VERSION).$(DLL_SUFFIX)
 endif
 endif
 
 endif
 endif
 
 ifndef TARGETS
-ifeq (,$(filter-out WINNT OS2,$(OS_ARCH)))
+ifeq (,$(filter-out WINCE WINNT OS2,$(OS_ARCH)))
 TARGETS		= $(LIBRARY) $(SHARED_LIBRARY) $(IMPORT_LIBRARY)
 else
 TARGETS		= $(LIBRARY) $(SHARED_LIBRARY)
 endif
 endif
 
 #
 # OBJS is the list of object files.  It can be constructed by
@@ -143,17 +143,17 @@ endif
 # of assembly language source files).
 #
 
 ifndef OBJS
 OBJS		= $(addprefix $(OBJDIR)/,$(CSRCS:.c=.$(OBJ_SUFFIX))) \
 		  $(addprefix $(OBJDIR)/,$(ASFILES:.$(ASM_SUFFIX)=.$(OBJ_SUFFIX)))
 endif
 
-ifeq ($(OS_ARCH), WINNT)
+ifeq (,$(filter-out WINCE WINNT,$(OS_ARCH)))
 OBJS += $(RES)
 endif
 
 ifeq ($(MOZ_OS2_TOOLS),VACPP)
 EXTRA_LIBS := $(patsubst -l%,$(DIST)/lib/%.$(LIB_SUFFIX),$(EXTRA_LIBS))
 endif
 
 ALL_TRASH		= $(TARGETS) $(OBJS) $(filter-out . .., $(OBJDIR)) LOGS TAGS $(GARBAGE) \
@@ -269,17 +269,17 @@ alltags:
 	find . -name dist -prune -o \( -name '*.[hc]' -o -name '*.cp' -o -name '*.cpp' \) -print | xargs etags -a
 	find . -name dist -prune -o \( -name '*.[hc]' -o -name '*.cp' -o -name '*.cpp' \) -print | xargs ctags -a
 
 $(NFSPWD):
 	cd $(@D); $(MAKE) $(@F)
 
 $(PROGRAM): $(OBJS)
 	@$(MAKE_OBJDIR)
-ifeq ($(OS_ARCH),WINNT)
+ifeq (,$(filter-out WINCE WINNT,$(OS_ARCH)))
 	$(CC) $(OBJS) -Fe$@ -link $(LDFLAGS) $(OS_LIBS) $(EXTRA_LIBS)
 else
 ifeq ($(MOZ_OS2_TOOLS),VACPP)
 	$(CC) $(OBJS) -Fe$@ $(LDFLAGS) $(OS_LIBS) $(EXTRA_LIBS)
 else
 	$(CC) -o $@ $(CFLAGS) $(OBJS) $(LDFLAGS)
 endif
 endif
@@ -309,18 +309,18 @@ ifeq ($(OS_ARCH)$(OS_RELEASE), AIX4.1)
 	echo "#!" > $(OBJDIR)/lib$(LIBRARY_NAME)_syms
 	nm -B -C -g $(OBJS) \
 		| awk '/ [T,D] / {print $$3}' \
 		| sed -e 's/^\.//' \
 		| sort -u >> $(OBJDIR)/lib$(LIBRARY_NAME)_syms
 	$(LD) $(XCFLAGS) -o $@ $(OBJS) -bE:$(OBJDIR)/lib$(LIBRARY_NAME)_syms \
 		-bM:SRE -bnoentry $(OS_LIBS) $(EXTRA_LIBS)
 else	# AIX 4.1
-ifeq ($(OS_ARCH), WINNT)
-	$(LINK_DLL) -MAP $(DLLBASE) $(DLL_LIBS) $(EXTRA_LIBS) $(OBJS)
+ifeq (,$(filter-out WINNT WINCE,$(OS_ARCH)))
+	$(LINK_DLL) -MAP $(DLLBASE) $(EXTRA_LIBS) $(OBJS) $(DLL_LIBS)
 else
 ifeq ($(OS_ARCH),OS2)
 # append ( >> ) doesn't seem to be working under OS/2 gmake. Run through OS/2 shell instead.	
 	@cmd /C "echo LIBRARY $(notdir $(basename $(SHARED_LIBRARY))) INITINSTANCE TERMINSTANCE >$@.def"
 	@cmd /C "echo PROTMODE >>$@.def"
 	@cmd /C "echo CODE    LOADONCALL MOVEABLE DISCARDABLE >>$@.def"
 	@cmd /C "echo DATA    PRELOAD MOVEABLE MULTIPLE NONSHARED >>$@.def"	
 	@cmd /C "echo EXPORTS >>$@.def"
@@ -338,46 +338,46 @@ else	# OpenVMS
 endif	# OpenVMS
 endif   # OS2
 endif	# WINNT
 endif	# AIX 4.1
 ifdef ENABLE_STRIP
 	$(STRIP) $@
 endif
 
-ifeq (,$(filter-out WINNT OS2,$(OS_ARCH)))
+ifeq (,$(filter-out WINCE WINNT OS2,$(OS_ARCH)))
 $(RES): $(RESNAME)
 	@$(MAKE_OBJDIR)
 ifeq ($(OS_TARGET),OS2)
 	$(RC) -DOS2 -r $< $@
 else
 # The resource compiler does not understand the -U option.
 	$(RC) $(filter-out -U%,$(DEFINES)) $(INCLUDES) -Fo$@ $<
 endif
 	@echo $(RES) finished
 endif
 
 $(OBJDIR)/%.$(OBJ_SUFFIX): %.cpp
 	@$(MAKE_OBJDIR)
-ifeq ($(OS_ARCH), WINNT)
+ifeq (,$(filter-out WINCE WINNT,$(OS_ARCH)))
 	$(CCC) -Fo$@ -c $(CCCFLAGS) $<
 else
 ifeq ($(MOZ_OS2_TOOLS),VACPP)
 	$(CCC) -Fo$@ -c $(CCCFLAGS) $<
 else
 	$(CCC) -o $@ -c $(CCCFLAGS) $<
 endif
 endif
 
 WCCFLAGS1 = $(subst /,\\,$(CFLAGS))
 WCCFLAGS2 = $(subst -I,-i=,$(WCCFLAGS1))
 WCCFLAGS3 = $(subst -D,-d,$(WCCFLAGS2))
 $(OBJDIR)/%.$(OBJ_SUFFIX): %.c
 	@$(MAKE_OBJDIR)
-ifeq ($(OS_ARCH), WINNT)
+ifeq (,$(filter-out WINCE WINNT,$(OS_ARCH)))
 	$(CC) -Fo$@ -c $(CFLAGS) $<
 else
 ifeq ($(MOZ_OS2_TOOLS),VACPP)
 	$(CC) -Fo$@ -c $(CFLAGS) $<
 else
 	$(CC) -o $@ -c $(CFLAGS) $<
 endif
 endif
@@ -389,17 +389,22 @@ endif
 
 ifeq ($(MOZ_OS2_TOOLS),VACPP)
 $(OBJDIR)/%.$(OBJ_SUFFIX): %.asm
 	@$(MAKE_OBJDIR)
 	$(AS) -Fdo:./$(OBJDIR) $(ASFLAGS) $<
 endif
 
 %.i: %.c
+ifeq (,$(filter-out WIN%,$(OS_TARGET)))
+	$(CC) -C /P $(CFLAGS) $<
+else
 	$(CC) -C -E $(CFLAGS) $< > $*.i
+endif
+
 
 %: %.pl
 	rm -f $@; cp $< $@; chmod +x $@
 
 #
 # HACK ALERT
 #
 # The only purpose of this rule is to pass Mozilla's Tinderbox depend
--- a/configure
+++ b/configure
@@ -2730,16 +2730,34 @@ elif test "$OS_ARCH" = "CYGWIN_98-4.10";
     OS_ARCH='CYGWIN_NT-4.0'
     OS_TARGET=WIN95
 elif test "$OS_ARCH" = "OS_2"; then
     OS_ARCH=OS2
     OS_TARGET=OS2
 fi
 
 #
+# Cross compiling for WinCE needs a special case here.
+# Only WCE300 (WinCE version 3.00) handled thus far.
+#
+# OSVERSION, and TARGETCPU are defined in a WinCE build environment.
+# Jump through hoops to make X86 look like x86 for the build system.
+#
+if test "$OSVERSION" = "WCE300"; then
+    OS_ARCH=WINCE
+    OS_TARGET=WINCE
+    OS_RELEASE=3.00
+    if test "$TARGETCPU" = "X86"; then
+        CPU_ARCH=x86
+    else
+        CPU_ARCH=$TARGETCPU
+    fi
+else
+
+#
 # On WIN32, we also define the variable CPU_ARCH.
 #
 
 if test "$OS_ARCH" = "WINNT"; then
     CPU_ARCH=`uname -p`
     if test "$CPU_ARCH" = "I386"; then
         CPU_ARCH=x86
     fi
@@ -2789,16 +2807,17 @@ elif test "$OS_ARCH" = "CYGWIN32_NT"; th
     CPU_ARCH=`uname -m`
     #
     # GNU-Win32's uname -m returns "i686" on a Pentium Pro machine.
     #
     if echo "$CPU_ARCH" | grep -c 86 >/dev/null; then
         CPU_ARCH=x86
     fi
 fi
+fi
 
 if test -n "$MOZILLA_CLIENT" && test "$OS_ARCH" = "WINNT"; then
     OS_TARGET=WIN95
     if test -n "$MOZ_DEBUG"; then
         USE_DEBUG_RTL=1
     fi
 fi
 if test -z "$OS_TARGET"; then
@@ -2839,27 +2858,27 @@ EOF
 
     cat >> confdefs.h <<\EOF
 #define SYSV 1
 EOF
 
     DSO_LDOPTS='-brtl -bM:SRE -bnoentry -bexpall'
     ac_safe=`echo "sys/atomic_op.h" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for sys/atomic_op.h""... $ac_c" 1>&6
-echo "configure:2848: checking for sys/atomic_op.h" >&5
+echo "configure:2867: checking for sys/atomic_op.h" >&5
 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 2853 "configure"
+#line 2872 "configure"
 #include "confdefs.h"
 #include <sys/atomic_op.h>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:2858: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:2877: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   rm -rf conftest*
   eval "ac_cv_header_$ac_safe=yes"
 else
   echo "$ac_err" >&5
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
@@ -3009,36 +3028,36 @@ EOF
     PR_MD_ARCH_DIR=beos
     RESOLVE_LINK_SYMBOLS=1
     case "${target_cpu}" in
     i?86)
         _OPTIMIZE_FLAGS=-O2
         _DEBUG_FLAGS='-gdwarf-2 -O0'
         MKSHLIB='$(CCC) $(DSO_LDOPTS) -o $@'
         echo $ac_n "checking for gethostbyaddr in -lbind""... $ac_c" 1>&6
-echo "configure:3018: checking for gethostbyaddr in -lbind" >&5
+echo "configure:3037: checking for gethostbyaddr in -lbind" >&5
 ac_lib_var=`echo bind'_'gethostbyaddr | sed 'y%./+-%__p_%'`
 if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   ac_save_LIBS="$LIBS"
 LIBS="-lbind  $LIBS"
 cat > conftest.$ac_ext <<EOF
-#line 3026 "configure"
+#line 3045 "configure"
 #include "confdefs.h"
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
     builtin and then its argument prototype would still apply.  */
 char gethostbyaddr();
 
 int main() {
 gethostbyaddr()
 ; return 0; }
 EOF
-if { (eval echo configure:3037: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:3056: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=yes"
 else
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=no"
 fi
@@ -3724,18 +3743,28 @@ EOF
 
     if test -n "$GNU_CC"; then
         cat >> confdefs.h <<\EOF
 #define NONAMELESSUNION 1
 EOF
 
         MKSHLIB='$(DLLTOOL) --as=$(AS) -k --dllname $*.dll --output-lib $@'
     else
-        CC=cl
-        CXX=cl
+        if test "$OS_TARGET" = "WINCE"; then
+            if test "$TARGETCPU" = "ARM"; then
+                CC=clarm
+                CXX=clarm
+            else
+                CC=cl
+                CXX=cl
+            fi
+        else
+            CC=cl
+            CXX=cl
+        fi
         LD=link
         AR='lib -NOLOGO -OUT:"$@"'
         AR_FLAGS=
         RANLIB='echo not_ranlib'
         STRIP='echo not_strip'
         NSINSTALL=nsinstall
         RC=rc.exe
         GARBAGE='$(OBJDIR)/vc20.pdb $(OBJDIR)/vc40.pdb'
@@ -3749,46 +3778,61 @@ EOF
             cat >> confdefs.h <<\EOF
 #define _DEBUG 1
 EOF
 
         else
             DEFINES="$DEFINES -U_DEBUG"
         fi
 
+        if test "$OS_TARGET" = "WINCE"; then
+            DLL_LIBS="corelibc.lib coredll.lib winsock.lib"
+        fi
+
         if test -n "$MOZ_OPTIMIZE"; then
-            CFLAGS="$CFLAGS -MD"
+            if test "$OS_TARGET" = "WINCE"; then
+                CFLAGS="$CFLAGS -Zl"
+            else
+                CFLAGS="$CFLAGS -MD"
+            fi
             _OPTIMIZE_FLAGS=-O2
             DLLFLAGS='-OUT:"$@"'
 
             if test -n "$MOZ_PROFILE"; then
                 _OPTIMIZE_FLAGS="$_OPTIMIZE_FLAGS -Z7"
                 DLLFLAGS="$DLLFLAGS -DEBUG -DEBUGTYPE:CV"
                 LDFLAGS="$LDFLAGS -DEBUG -DEBUGTYPE:CV"
             fi
         else
-            if test -n "$USE_DEBUG_RTL"; then
-                CFLAGS="$CFLAGS -MDd"
+            if test "$OS_TARGET" = "WINCE"; then
+                CFLAGS="$CFLAGS -Zl"
             else
-                CFLAGS="$CFLAGS -MD"
+                if test -n "$USE_DEBUG_RTL"; then
+                    CFLAGS="$CFLAGS -MDd"
+                else
+                    CFLAGS="$CFLAGS -MD"
+                fi
             fi
             _DEBUG_FLAGS="-Od -Z7"
             DLLFLAGS='-DEBUG -DEBUGTYPE:CV -OUT:"$@"'
             if test -n "$GLOWCODE"; then
                 DLLFLAGS='-DEBUG -DEBUGTYPE:both -INCLUDE:_GlowCode -OUT:"$@"'
                 DLL_LIBS='$(GLOWDIR)/glowcode.lib'
             fi
             LDFLAGS="-DEBUG -DEBUGTYPE:CV"
             if test -n "$PROFILE"; then
                 LDFLAGS="$LDFLAGS -PROFILE -MAP"
                 DLLFLAGS="$DLLFLAGS -PROFILE -MAP"
             fi
         fi
         
-        if test "$OS_TARGET" = "WINNT"; then
+        if test "$OS_TARGET" = "WINCE"; then
+            LIBNSPR='$(dist_libdir)/libnspr$(MOD_MAJOR_VERSION).$(LIB_SUFFIX)'
+            LIBPLC='$(dist_libdir)/libplc$(MOD_MAJOR_VERSION).$(LIB_SUFFIX)'
+        elif test "$OS_TARGET" = "WINNT"; then
             CFLAGS="$CFLAGS -GT"
             if test "$CPU_ARCH" = "x86"; then
                 CFLAGS="$CFLAGS -G5"
             fi
             LIBNSPR='$(dist_libdir)/libnspr$(MOD_MAJOR_VERSION).$(LIB_SUFFIX)'
             LIBPLC='$(dist_libdir)/libplc$(MOD_MAJOR_VERSION).$(LIB_SUFFIX)'
         else
             LIBNSPR='$(dist_libdir)/nspr$(MOD_MAJOR_VERSION).$(LIB_SUFFIX)'
@@ -3803,16 +3847,25 @@ EOF
 
     fi
 
     if test "$OS_TARGET" = "WINNT"; then
         cat >> confdefs.h <<\EOF
 #define WINNT 1
 EOF
 
+    elif test "$OS_TARGET" = "WINCE"; then
+        cat >> confdefs.h <<\EOF
+#define WINCE 1
+EOF
+
+        cat >> confdefs.h <<\EOF
+#define _PR_GLOBAL_THREADS_ONLY 1
+EOF
+
     else
         cat >> confdefs.h <<\EOF
 #define WIN95 1
 EOF
 
         cat >> confdefs.h <<\EOF
 #define _PR_GLOBAL_THREADS_ONLY 1
 EOF
@@ -3824,59 +3877,111 @@ EOF
     else
         CPU_ARCH_TAG=$CPU_ARCH
     fi
 
     if test -n "$USE_DEBUG_RTL"; then
         OBJDIR_SUFFIX=OBJD
     fi
 
-    OS_DLLFLAGS='-nologo -DLL -SUBSYSTEM:WINDOWS -PDB:NONE'
+    if test "$OS_TARGET" = "WINCE"; then
+        if test "$TARGETCPU" = "X86"; then
+            OS_DLLFLAGS='-nologo -DLL -SUBSYSTEM:WINDOWSCE,3.00 -MACHINE:IX86 -ENTRY:_DllMainCRTStartup -STACK:0x10000,0x1000 -NODEFAULTLIB:OLDNAMES.lib'
+        else
+            OS_DLLFLAGS='-nologo -DLL -SUBSYSTEM:WINDOWSCE,3.00 -MACHINE:ARM -ENTRY:_DllMainCRTStartup -STACK:0x10000,0x1000 -NODEFAULTLIB:OLDNAMES.lib'
+        fi
+    else
+        OS_DLLFLAGS='-nologo -DLL -SUBSYSTEM:WINDOWS -PDB:NONE'
+    fi
 
     case "$OS_TARGET" in
     WINNT)
 	    MDCPUCFG_H=_winnt.cfg
 	    ;;
     WIN95)
 	    MDCPUCFG_H=_win95.cfg
 	    ;;
+    WINCE)
+	    MDCPUCFG_H=_wince.cfg
+	    ;;
     WIN16)
 	    MDCPUCFG_H=_win16.cfg
 	    ;;
     *)
 	    { echo "configure: error: Missing OS_TARGET for ${target}.  Use --enable-win32-target to set." 1>&2; exit 1; }
    	;;
     esac
 
-    case "$target_cpu" in
-    i?86)
-	    cat >> confdefs.h <<\EOF
+    if test "$OS_TARGET" = "WINCE"; then
+        case "$TARGETCPU" in
+        X86)
+	        cat >> confdefs.h <<\EOF
 #define _X86_ 1
 EOF
 
-        ;;
-    alpha)
-	    cat >> confdefs.h <<\EOF
+	        cat >> confdefs.h <<\EOF
+#define x86 1
+EOF
+
+            ;;
+        ARM)
+	        cat >> confdefs.h <<\EOF
+#define _ARM_ 1
+EOF
+
+	        cat >> confdefs.h <<\EOF
+#define ARM 1
+EOF
+
+            ;;
+        *)
+	        cat >> confdefs.h <<\EOF
+#define _CPU_ARCH_NOT_DEFINED_ 1
+EOF
+
+	        cat >> confdefs.h <<\EOF
+#define CPU_ARCH_NOT_DEFINED 1
+EOF
+
+            ;;
+        esac
+    else
+        case "$target_cpu" in
+        i?86)
+	        cat >> confdefs.h <<\EOF
+#define _X86_ 1
+EOF
+
+            ;;
+        alpha)
+	        cat >> confdefs.h <<\EOF
 #define _ALPHA_ 1
 EOF
 
-   	    ;;
-    mips)
-	    cat >> confdefs.h <<\EOF
+       	    ;;
+        mips)
+	        cat >> confdefs.h <<\EOF
 #define _MIPS_ 1
 EOF
 
-	    ;;
-    *)
-	    cat >> confdefs.h <<\EOF
+    	    ;;
+        arm)
+	        cat >> confdefs.h <<\EOF
+#define _ARM_ 1
+EOF
+
+    	    ;;
+        *)
+	        cat >> confdefs.h <<\EOF
 #define _CPU_ARCH_NOT_DEFINED 1
 EOF
 
-	    ;;
-    esac
+    	    ;;
+        esac
+    fi
 
     ;;
 
 *-ncr-sysv*)
     cat >> confdefs.h <<\EOF
 #define XP_UNIX 1
 EOF
 
@@ -4154,27 +4259,27 @@ EOF
 EOF
 
     cat >> confdefs.h <<\EOF
 #define _REENTRANT 1
 EOF
 
     ac_safe=`echo "machine/builtins.h" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for machine/builtins.h""... $ac_c" 1>&6
-echo "configure:4163: checking for machine/builtins.h" >&5
+echo "configure:4268: checking for machine/builtins.h" >&5
 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 4168 "configure"
+#line 4273 "configure"
 #include "confdefs.h"
 #include <machine/builtins.h>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:4173: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:4278: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   rm -rf conftest*
   eval "ac_cv_header_$ac_safe=yes"
 else
   echo "$ac_err" >&5
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
@@ -4679,22 +4784,22 @@ EOF
 
     ;;
    
 esac
 
 if test -z "$SKIP_LIBRARY_CHECKS"; then
 
 echo $ac_n "checking for dlopen""... $ac_c" 1>&6
-echo "configure:4688: checking for dlopen" >&5
+echo "configure:4793: checking for dlopen" >&5
 if eval "test \"`echo '$''{'ac_cv_func_dlopen'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 4693 "configure"
+#line 4798 "configure"
 #include "confdefs.h"
 /* System header to define __stub macros and hopefully few prototypes,
     which can conflict with char dlopen(); below.  */
 #include <assert.h>
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
     builtin and then its argument prototype would still apply.  */
 char dlopen();
@@ -4707,17 +4812,17 @@ int main() {
 #if defined (__stub_dlopen) || defined (__stub___dlopen)
 choke me
 #else
 dlopen();
 #endif
 
 ; return 0; }
 EOF
-if { (eval echo configure:4716: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:4821: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_func_dlopen=yes"
 else
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
   rm -rf conftest*
   eval "ac_cv_func_dlopen=no"
 fi
@@ -4726,36 +4831,36 @@ fi
 
 if eval "test \"`echo '$ac_cv_func_'dlopen`\" = yes"; then
   echo "$ac_t""yes" 1>&6
   :
 else
   echo "$ac_t""no" 1>&6
 
     echo $ac_n "checking for dlopen in -ldl""... $ac_c" 1>&6
-echo "configure:4735: checking for dlopen in -ldl" >&5
+echo "configure:4840: checking for dlopen in -ldl" >&5
 ac_lib_var=`echo dl'_'dlopen | sed 'y%./+-%__p_%'`
 if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   ac_save_LIBS="$LIBS"
 LIBS="-ldl  $LIBS"
 cat > conftest.$ac_ext <<EOF
-#line 4743 "configure"
+#line 4848 "configure"
 #include "confdefs.h"
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
     builtin and then its argument prototype would still apply.  */
 char dlopen();
 
 int main() {
 dlopen()
 ; return 0; }
 EOF
-if { (eval echo configure:4754: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:4859: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=yes"
 else
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=no"
 fi
@@ -4773,23 +4878,23 @@ fi
 
 fi
 
 
 
 
 if test $ac_cv_prog_gcc = yes; then
     echo $ac_n "checking whether ${CC-cc} needs -traditional""... $ac_c" 1>&6
-echo "configure:4782: checking whether ${CC-cc} needs -traditional" >&5
+echo "configure:4887: checking whether ${CC-cc} needs -traditional" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_gcc_traditional'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
     ac_pattern="Autoconf.*'x'"
   cat > conftest.$ac_ext <<EOF
-#line 4788 "configure"
+#line 4893 "configure"
 #include "confdefs.h"
 #include <sgtty.h>
 Autoconf TIOCGETP
 EOF
 if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
   egrep "$ac_pattern" >/dev/null 2>&1; then
   rm -rf conftest*
   ac_cv_prog_gcc_traditional=yes
@@ -4797,17 +4902,17 @@ else
   rm -rf conftest*
   ac_cv_prog_gcc_traditional=no
 fi
 rm -f conftest*
 
 
   if test $ac_cv_prog_gcc_traditional = no; then
     cat > conftest.$ac_ext <<EOF
-#line 4806 "configure"
+#line 4911 "configure"
 #include "confdefs.h"
 #include <termio.h>
 Autoconf TCGETA
 EOF
 if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
   egrep "$ac_pattern" >/dev/null 2>&1; then
   rm -rf conftest*
   ac_cv_prog_gcc_traditional=yes
@@ -4821,22 +4926,22 @@ echo "$ac_t""$ac_cv_prog_gcc_traditional
   if test $ac_cv_prog_gcc_traditional = yes; then
     CC="$CC -traditional"
   fi
 fi
 
 for ac_func in lchown strerror
 do
 echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:4830: checking for $ac_func" >&5
+echo "configure:4935: checking for $ac_func" >&5
 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 4835 "configure"
+#line 4940 "configure"
 #include "confdefs.h"
 /* System header to define __stub macros and hopefully few prototypes,
     which can conflict with char $ac_func(); below.  */
 #include <assert.h>
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
     builtin and then its argument prototype would still apply.  */
 char $ac_func();
@@ -4849,17 +4954,17 @@ int main() {
 #if defined (__stub_$ac_func) || defined (__stub___$ac_func)
 choke me
 #else
 $ac_func();
 #endif
 
 ; return 0; }
 EOF
-if { (eval echo configure:4858: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:4963: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_func_$ac_func=yes"
 else
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
   rm -rf conftest*
   eval "ac_cv_func_$ac_func=no"
 fi
@@ -4887,17 +4992,17 @@ if test "${enable_strip+set}" = set; the
    ENABLE_STRIP=1 
 fi
 
 
 
 
 
 echo $ac_n "checking for pthread_create in -lpthreads""... $ac_c" 1>&6
-echo "configure:4896: checking for pthread_create in -lpthreads" >&5
+echo "configure:5001: checking for pthread_create in -lpthreads" >&5
 echo "
     #include <pthread.h> 
     void *foo(void *v) { int a = 1;  } 
     int main() { 
         pthread_t t;
         if (!pthread_create(&t, 0, &foo, 0)) {
             pthread_join(t, 0);
         }
@@ -4909,17 +5014,17 @@ echo "
     rm -f dummy.c dummy${ac_exeext} ;
     if test "$_res" = "0"; then
         echo "$ac_t""yes" 1>&6
         _HAVE_PTHREADS=1 _PTHREAD_LDFLAGS="-lpthreads"
     else
         echo "$ac_t""no" 1>&6
         
 echo $ac_n "checking for pthread_create in -lpthread""... $ac_c" 1>&6
-echo "configure:4918: checking for pthread_create in -lpthread" >&5
+echo "configure:5023: checking for pthread_create in -lpthread" >&5
 echo "
     #include <pthread.h> 
     void *foo(void *v) { int a = 1;  } 
     int main() { 
         pthread_t t;
         if (!pthread_create(&t, 0, &foo, 0)) {
             pthread_join(t, 0);
         }
@@ -4931,17 +5036,17 @@ echo "
     rm -f dummy.c dummy${ac_exeext} ;
     if test "$_res" = "0"; then
         echo "$ac_t""yes" 1>&6
         _HAVE_PTHREADS=1 _PTHREAD_LDFLAGS="-lpthread"
     else
         echo "$ac_t""no" 1>&6
         
 echo $ac_n "checking for pthread_create in -lc_r""... $ac_c" 1>&6
-echo "configure:4940: checking for pthread_create in -lc_r" >&5
+echo "configure:5045: checking for pthread_create in -lc_r" >&5
 echo "
     #include <pthread.h> 
     void *foo(void *v) { int a = 1;  } 
     int main() { 
         pthread_t t;
         if (!pthread_create(&t, 0, &foo, 0)) {
             pthread_join(t, 0);
         }
@@ -4953,17 +5058,17 @@ echo "
     rm -f dummy.c dummy${ac_exeext} ;
     if test "$_res" = "0"; then
         echo "$ac_t""yes" 1>&6
         _HAVE_PTHREADS=1 _PTHREAD_LDFLAGS="-lc_r"
     else
         echo "$ac_t""no" 1>&6
         
 echo $ac_n "checking for pthread_create in -lc""... $ac_c" 1>&6
-echo "configure:4962: checking for pthread_create in -lc" >&5
+echo "configure:5067: checking for pthread_create in -lc" >&5
 echo "
     #include <pthread.h> 
     void *foo(void *v) { int a = 1;  } 
     int main() { 
         pthread_t t;
         if (!pthread_create(&t, 0, &foo, 0)) {
             pthread_join(t, 0);
         }
@@ -5103,17 +5208,17 @@ EOF
     fi
 fi
 
 
 if test -n "$USE_PTHREADS"; then
       rm -f conftest*
    ac_cv_have_dash_pthread=no
    echo $ac_n "checking whether ${CC-cc} accepts -pthread""... $ac_c" 1>&6
-echo "configure:5112: checking whether ${CC-cc} accepts -pthread" >&5
+echo "configure:5217: checking whether ${CC-cc} accepts -pthread" >&5
    echo 'int main() { return 0; }' | cat > conftest.c
    ${CC-cc} -pthread -o conftest conftest.c > conftest.out 2>&1
    if test $? -eq 0; then
 	if test -z "`egrep -i '(unrecognize|unknown)' conftest.out | grep pthread`" && test -z "`egrep -i '(error|incorrect)' conftest.out`" ; then
 	    ac_cv_have_dash_pthread=yes
 		case "$target_os" in
 	    freebsd*)
 # Freebsd doesn't use -pthread for compiles, it uses them for linking
@@ -5126,17 +5231,17 @@ echo "configure:5112: checking whether $
 	fi
     fi
     rm -f conftest*
     echo "$ac_t""$ac_cv_have_dash_pthread" 1>&6
 
 			    ac_cv_have_dash_pthreads=no
     if test "$ac_cv_have_dash_pthread" = "no"; then
 	    echo $ac_n "checking whether ${CC-cc} accepts -pthreads""... $ac_c" 1>&6
-echo "configure:5135: checking whether ${CC-cc} accepts -pthreads" >&5
+echo "configure:5240: checking whether ${CC-cc} accepts -pthreads" >&5
     	echo 'int main() { return 0; }' | cat > conftest.c
 	    ${CC-cc} -pthreads -o conftest conftest.c > conftest.out 2>&1
     	if test $? -eq 0; then
 	    	if test -z "`egrep -i '(unrecognize|unknown)' conftest.out | grep pthreads`" && test -z "`egrep -i '(error|incorrect)' conftest.out`" ; then
 			    ac_cv_have_dash_pthreads=yes
 			    CFLAGS="$CFLAGS -pthreads"
 			    CXXFLAGS="$CXXFLAGS -pthreads"
 		    fi
@@ -5496,16 +5601,17 @@ RELEASE_OBJDIR_NAME="${OS_CONFIG}${CPU_A
 
 
 
 
 
 
 
 
+
 MAKEFILES="
 Makefile 
 config/Makefile
 config/autoconf.mk
 config/nsprincl.mk
 config/nsprincl.sh
 config/nspr-config
 lib/Makefile 
@@ -5777,16 +5883,17 @@ s%@OBJDIR@%$OBJDIR%g
 s%@OBJDIR_NAME@%$OBJDIR_NAME%g
 s%@RELEASE_OBJDIR_NAME@%$RELEASE_OBJDIR_NAME%g
 s%@NSINSTALL@%$NSINSTALL%g
 s%@OPTIMIZER@%$OPTIMIZER%g
 s%@RC@%$RC%g
 s%@DLLFLAGS@%$DLLFLAGS%g
 s%@EXEFLAGS@%$EXEFLAGS%g
 s%@OS_DLLFLAGS@%$OS_DLLFLAGS%g
+s%@DLL_LIBS@%$DLL_LIBS%g
 
 CEOF
 EOF
 
 cat >> $CONFIG_STATUS <<\EOF
 
 # Split the substitutions into bite-sized pieces for seds with
 # small command number limits, like on Digital OSF/1 and HP-UX.
--- a/configure.in
+++ b/configure.in
@@ -568,16 +568,34 @@ elif test "$OS_ARCH" = "CYGWIN_98-4.10";
     OS_ARCH='CYGWIN_NT-4.0'
     OS_TARGET=WIN95
 elif test "$OS_ARCH" = "OS_2"; then
     OS_ARCH=OS2
     OS_TARGET=OS2
 fi
 
 #
+# Cross compiling for WinCE needs a special case here.
+# Only WCE300 (WinCE version 3.00) handled thus far.
+#
+# OSVERSION, and TARGETCPU are defined in a WinCE build environment.
+# Jump through hoops to make X86 look like x86 for the build system.
+#
+if test "$OSVERSION" = "WCE300"; then
+    OS_ARCH=WINCE
+    OS_TARGET=WINCE
+    OS_RELEASE=3.00
+    if test "$TARGETCPU" = "X86"; then
+        CPU_ARCH=x86
+    else
+        CPU_ARCH=$TARGETCPU
+    fi
+else
+
+#
 # On WIN32, we also define the variable CPU_ARCH.
 #
 
 if test "$OS_ARCH" = "WINNT"; then
     CPU_ARCH=`uname -p`
     if test "$CPU_ARCH" = "I386"; then
         CPU_ARCH=x86
     fi
@@ -627,16 +645,17 @@ elif test "$OS_ARCH" = "CYGWIN32_NT"; th
     CPU_ARCH=`uname -m`
     #
     # GNU-Win32's uname -m returns "i686" on a Pentium Pro machine.
     #
     if echo "$CPU_ARCH" | grep -c 86 >/dev/null; then
         CPU_ARCH=x86
     fi
 fi
+fi
 
 if test -n "$MOZILLA_CLIENT" && test "$OS_ARCH" = "WINNT"; then
     OS_TARGET=WIN95
     if test -n "$MOZ_DEBUG"; then
         USE_DEBUG_RTL=1
     fi
 fi
 if test -z "$OS_TARGET"; then
@@ -1178,18 +1197,28 @@ case "$target" in
     AC_DEFINE(WIN32)
     PR_MD_ARCH_DIR=windows
     RESOLVE_LINK_SYMBOLS=1
 
     if test -n "$GNU_CC"; then
         AC_DEFINE(NONAMELESSUNION)
         MKSHLIB='$(DLLTOOL) --as=$(AS) -k --dllname $*.dll --output-lib $@'
     else
-        CC=cl
-        CXX=cl
+        if test "$OS_TARGET" = "WINCE"; then
+            if test "$TARGETCPU" = "ARM"; then
+                CC=clarm
+                CXX=clarm
+            else
+                CC=cl
+                CXX=cl
+            fi
+        else
+            CC=cl
+            CXX=cl
+        fi
         LD=link
         AR='lib -NOLOGO -OUT:"$@"'
         AR_FLAGS=
         RANLIB='echo not_ranlib'
         STRIP='echo not_strip'
         NSINSTALL=nsinstall
         RC=rc.exe
         GARBAGE='$(OBJDIR)/vc20.pdb $(OBJDIR)/vc40.pdb'
@@ -1200,46 +1229,61 @@ case "$target" in
         CFLAGS="$CFLAGS -W3 -nologo -GF -Gy"
 
         if test -n "$MOZ_DEBUG"; then
             AC_DEFINE(_DEBUG)
         else
             DEFINES="$DEFINES -U_DEBUG"
         fi
 
+        if test "$OS_TARGET" = "WINCE"; then
+            DLL_LIBS="corelibc.lib coredll.lib winsock.lib"
+        fi
+
         if test -n "$MOZ_OPTIMIZE"; then
-            CFLAGS="$CFLAGS -MD"
+            if test "$OS_TARGET" = "WINCE"; then
+                CFLAGS="$CFLAGS -Zl"
+            else
+                CFLAGS="$CFLAGS -MD"
+            fi
             _OPTIMIZE_FLAGS=-O2
             DLLFLAGS='-OUT:"$@"'
 
             if test -n "$MOZ_PROFILE"; then
                 _OPTIMIZE_FLAGS="$_OPTIMIZE_FLAGS -Z7"
                 DLLFLAGS="$DLLFLAGS -DEBUG -DEBUGTYPE:CV"
                 LDFLAGS="$LDFLAGS -DEBUG -DEBUGTYPE:CV"
             fi
         else
-            if test -n "$USE_DEBUG_RTL"; then
-                CFLAGS="$CFLAGS -MDd"
+            if test "$OS_TARGET" = "WINCE"; then
+                CFLAGS="$CFLAGS -Zl"
             else
-                CFLAGS="$CFLAGS -MD"
+                if test -n "$USE_DEBUG_RTL"; then
+                    CFLAGS="$CFLAGS -MDd"
+                else
+                    CFLAGS="$CFLAGS -MD"
+                fi
             fi
             _DEBUG_FLAGS="-Od -Z7"
             DLLFLAGS='-DEBUG -DEBUGTYPE:CV -OUT:"$@"'
             if test -n "$GLOWCODE"; then
                 DLLFLAGS='-DEBUG -DEBUGTYPE:both -INCLUDE:_GlowCode -OUT:"$@"'
                 DLL_LIBS='$(GLOWDIR)/glowcode.lib'
             fi
             LDFLAGS="-DEBUG -DEBUGTYPE:CV"
             if test -n "$PROFILE"; then
                 LDFLAGS="$LDFLAGS -PROFILE -MAP"
                 DLLFLAGS="$DLLFLAGS -PROFILE -MAP"
             fi
         fi
         
-        if test "$OS_TARGET" = "WINNT"; then
+        if test "$OS_TARGET" = "WINCE"; then
+            LIBNSPR='$(dist_libdir)/libnspr$(MOD_MAJOR_VERSION).$(LIB_SUFFIX)'
+            LIBPLC='$(dist_libdir)/libplc$(MOD_MAJOR_VERSION).$(LIB_SUFFIX)'
+        elif test "$OS_TARGET" = "WINNT"; then
             CFLAGS="$CFLAGS -GT"
             if test "$CPU_ARCH" = "x86"; then
                 CFLAGS="$CFLAGS -G5"
             fi
             LIBNSPR='$(dist_libdir)/libnspr$(MOD_MAJOR_VERSION).$(LIB_SUFFIX)'
             LIBPLC='$(dist_libdir)/libplc$(MOD_MAJOR_VERSION).$(LIB_SUFFIX)'
         else
             LIBNSPR='$(dist_libdir)/nspr$(MOD_MAJOR_VERSION).$(LIB_SUFFIX)'
@@ -1248,62 +1292,96 @@ case "$target" in
     fi # GNU_CC
 
     if test -n "$USE_STATIC_TLS"; then
         AC_DEFINE(_PR_USE_STATIC_TLS)
     fi
 
     if test "$OS_TARGET" = "WINNT"; then
         AC_DEFINE(WINNT)
+    elif test "$OS_TARGET" = "WINCE"; then
+        AC_DEFINE(WINCE)
+        AC_DEFINE(_PR_GLOBAL_THREADS_ONLY)
     else
         AC_DEFINE(WIN95)
         AC_DEFINE(_PR_GLOBAL_THREADS_ONLY)
     fi
 
     if test "$CPU_ARCH" = "x86"; then
         CPU_ARCH_TAG=
     else
         CPU_ARCH_TAG=$CPU_ARCH
     fi
 
     if test -n "$USE_DEBUG_RTL"; then
         OBJDIR_SUFFIX=OBJD
     fi
 
-    OS_DLLFLAGS='-nologo -DLL -SUBSYSTEM:WINDOWS -PDB:NONE'
+    if test "$OS_TARGET" = "WINCE"; then
+        if test "$TARGETCPU" = "X86"; then
+            OS_DLLFLAGS='-nologo -DLL -SUBSYSTEM:WINDOWSCE,3.00 -MACHINE:IX86 -ENTRY:_DllMainCRTStartup -STACK:0x10000,0x1000 -NODEFAULTLIB:OLDNAMES.lib'
+        else
+            OS_DLLFLAGS='-nologo -DLL -SUBSYSTEM:WINDOWSCE,3.00 -MACHINE:ARM -ENTRY:_DllMainCRTStartup -STACK:0x10000,0x1000 -NODEFAULTLIB:OLDNAMES.lib'
+        fi
+    else
+        OS_DLLFLAGS='-nologo -DLL -SUBSYSTEM:WINDOWS -PDB:NONE'
+    fi
 
     case "$OS_TARGET" in
     WINNT)
 	    MDCPUCFG_H=_winnt.cfg
 	    ;;
     WIN95)
 	    MDCPUCFG_H=_win95.cfg
 	    ;;
+    WINCE)
+	    MDCPUCFG_H=_wince.cfg
+	    ;;
     WIN16)
 	    MDCPUCFG_H=_win16.cfg
 	    ;;
     *)
 	    AC_MSG_ERROR([Missing OS_TARGET for ${target}.  Use --enable-win32-target to set.])
    	;;
     esac
 
-    case "$target_cpu" in
-    i?86)
-	    AC_DEFINE(_X86_)
-        ;;
-    alpha)
-	    AC_DEFINE(_ALPHA_)
-   	    ;;
-    mips)
-	    AC_DEFINE(_MIPS_)
-	    ;;
-    *)
-	    AC_DEFINE(_CPU_ARCH_NOT_DEFINED)
-	    ;;
-    esac
+    if test "$OS_TARGET" = "WINCE"; then
+        case "$TARGETCPU" in
+        X86)
+	        AC_DEFINE(_X86_)
+	        AC_DEFINE(x86)
+            ;;
+        ARM)
+	        AC_DEFINE(_ARM_)
+	        AC_DEFINE(ARM)
+            ;;
+        *)
+	        AC_DEFINE(_CPU_ARCH_NOT_DEFINED_)
+	        AC_DEFINE(CPU_ARCH_NOT_DEFINED)
+            ;;
+        esac
+    else
+        case "$target_cpu" in
+        i?86)
+	        AC_DEFINE(_X86_)
+            ;;
+        alpha)
+	        AC_DEFINE(_ALPHA_)
+       	    ;;
+        mips)
+	        AC_DEFINE(_MIPS_)
+    	    ;;
+        arm)
+	        AC_DEFINE(_ARM_)
+    	    ;;
+        *)
+	        AC_DEFINE(_CPU_ARCH_NOT_DEFINED)
+    	    ;;
+        esac
+    fi
 
     ;;
 
 *-ncr-sysv*)
     AC_DEFINE(XP_UNIX)
     AC_DEFINE(SVR4)
     AC_DEFINE(SYSV)
     AC_DEFINE(NCR)
@@ -2317,16 +2395,17 @@ AC_SUBST(OBJDIR)
 AC_SUBST(OBJDIR_NAME)
 AC_SUBST(RELEASE_OBJDIR_NAME)
 AC_SUBST(NSINSTALL)
 AC_SUBST(OPTIMIZER)
 AC_SUBST(RC)
 AC_SUBST(DLLFLAGS)
 AC_SUBST(EXEFLAGS)
 AC_SUBST(OS_DLLFLAGS)
+AC_SUBST(DLL_LIBS)
 
 dnl ========================================================
 dnl Generate output files.
 dnl ========================================================
 MAKEFILES="
 Makefile 
 config/Makefile
 config/autoconf.mk
--- a/gmakefile.win
+++ b/gmakefile.win
@@ -39,21 +39,29 @@ ifndef MOZ_SRC_FLIPPED
 endif
 
 ifndef MOZ_TOP
 MOZ_TOP=mozilla
 endif
 
 MOZ_DIST_FLIPPED = $(MOZ_SRC_FLIPPED)/mozilla/dist
 
+ifeq ($(OS_TARGET),WINCE)
+ifdef MOZ_DEBUG
+MOZ_OBJDIR = $(OSVERSION)$(TARGETCPU)_D.OBJ
+else
+MOZ_OBJDIR = $(OSVERSION)$(TARGETCPU)_O.OBJ
+endif
+else
 ifdef MOZ_DEBUG
 MOZ_OBJDIR = WIN32_D.OBJ
 else
 MOZ_OBJDIR = WIN32_O.OBJ
 endif
+endif
 
 NSPR_CONFIGURE := ../configure \
 		--with-mozilla \
 		--with-dist-prefix=$(MOZ_DIST_FLIPPED) \
 		--with-dist-bindir=$(MOZ_DIST_FLIPPED)/$(MOZ_OBJDIR)/bin \
 		--with-dist-libdir=$(MOZ_DIST_FLIPPED)/$(MOZ_OBJDIR)/lib
 
 ifeq (,$(MOZ_DEBUG)$(MOZ_TRACE_MALLOC))
@@ -78,15 +86,15 @@ all:: build_all
 
 build_all: $(MOZ_OBJDIR)/config.status check_old
 	gmake -C $(MOZ_OBJDIR)
 
 clobber_all: $(MOZ_OBJDIR)/config.status check_old
 	gmake -C $(MOZ_OBJDIR) clobber_all
 
 distclean: check_old
-	rm -rf WIN32_D.OBJ WIN32_O.OBJ
+	rm -rf WIN32_D.OBJ WIN32_O.OBJ WINCE_D.OBJ WINCE_O.OBJ
 
 check_old:
 	@if test -f Makefile; then gmake distclean; fi
 
 
 
--- a/pr/include/md/_pcos.h
+++ b/pr/include/md/_pcos.h
@@ -64,19 +64,21 @@ PR_END_EXTERN_C
 /*
 ** Definitions of directory structures amd functions
 ** These definitions are from:
 **      <dirent.h>
 */
 #ifdef XP_OS2_EMX
 #include <sys/types.h>
 #endif
+#if !defined(WINCE)
 #include <sys/stat.h>
 #include <io.h>
 #include <fcntl.h>          /* O_BINARY */
+#endif
 
 #ifdef OS2
 extern PRStatus _MD_OS2GetHostName(char *name, PRUint32 namelen);
 #define _MD_GETHOSTNAME _MD_OS2GetHostName
 #else
 extern PRStatus _MD_WindowsGetHostName(char *name, PRUint32 namelen);
 #define _MD_GETHOSTNAME _MD_WindowsGetHostName
 extern PRStatus _MD_WindowsGetSysInfo(PRSysInfo cmd, char *name, PRUint32 namelen);
--- a/pr/include/md/_win32_errors.h
+++ b/pr/include/md/_win32_errors.h
@@ -32,17 +32,19 @@
  * GPL.
  */
 
 #ifndef nspr_win32_errors_h___
 #define nspr_win32_errors_h___
 
 #include <windows.h>
 #include <winsock.h>
+#if !defined(WINCE)
 #include <errno.h>
+#endif
 
 
 extern void _MD_win32_map_default_error(PRInt32 err);
 #define _PR_MD_MAP_DEFAULT_ERROR	_MD_win32_map_default_error
 
 extern void _MD_win32_map_opendir_error(PRInt32 err);
 #define	_PR_MD_MAP_OPENDIR_ERROR	_MD_win32_map_opendir_error
 
new file mode 100644
--- /dev/null
+++ b/pr/include/md/_win32_time.h
@@ -0,0 +1,178 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* 
+ * The contents of this file are subject to the Mozilla Public
+ * License Version 1.1 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
+ * 
+ * Software distributed under the License is distributed on an "AS
+ * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * rights and limitations under the License.
+ * 
+ * The Original Code is the Netscape Portable Runtime (NSPR).
+ * 
+ * The Initial Developer of the Original Code is Netscape
+ * Communications Corporation.  Portions created by Netscape are 
+ * Copyright (C) 1998-2000 Netscape Communications Corporation.  All
+ * Rights Reserved.
+ * 
+ * Contributor(s):
+ *  Garrett Arch Blythe 01/25/2002
+ * 
+ * Alternatively, the contents of this file may be used under the
+ * terms of the GNU General Public License Version 2 or later (the
+ * "GPL"), in which case the provisions of the GPL are applicable 
+ * instead of those above.  If you wish to allow use of your 
+ * version of this file only under the terms of the GPL and not to
+ * allow others to use your version of this file under the MPL,
+ * indicate your decision by deleting the provisions above and
+ * replace them with the notice and other provisions required by
+ * the GPL.  If you do not delete the provisions above, a recipient
+ * may use your version of this file under either the MPL or the
+ * GPL.
+ */
+
+#ifndef nspr_win32_time_h___
+#define nspr_win32_time_h___
+
+#include <windows.h>
+
+/*
+ * _win23_time.h
+ *
+ * This file mainly exists because when porting NSPR to WinCE there was
+ *  a lack of LIBC support.  Conversion between window's FILETIME and
+ *  time_t was going to be a common operation; thus this file.
+ *
+ * I assume compiler support for int64.
+ */
+
+#if !defined(__GNUC__)
+#define _PR_I64_CONST(number) number ## i64
+#else
+#define _PR_I64_COSNT(number) number ## LL
+#endif
+
+/*
+ * FILETIME has an epoch of 1601.
+ * Precomputed the 1970 epoch so we do not have to below.
+ */
+#define _MD_FILETIME_1970 _PR_I64_CONST(116444736000000000)
+
+/*
+ * Marco to support add/sub/mul/div on a FILETIME level.
+ */
+#define _MD_FILETIME_ARITH(outFileTime, inFileTime, inOperation, inValue) \
+    PR_BEGIN_MACRO \
+        ULARGE_INTEGER _buffer1; \
+        \
+        _buffer1.LowPart = inFileTime.dwLowDateTime; \
+        _buffer1.HighPart = inFileTime.dwHighDateTime; \
+        _buffer1.QuadPart = _buffer1.QuadPart inOperation inValue; \
+        outFileTime.dwLowDateTime = _buffer1.LowPart; \
+        outFileTime.dwHighDateTime = _buffer1.HighPart; \
+    PR_END_MACRO
+
+/*
+ * FILETIME is in 100 nanosecond units.
+ * Provide macros for conversion to other second units.
+ */
+#define _MD_FILETIME_2_MICROSECONDS(outTime, inFileTime) \
+    PR_BEGIN_MACRO \
+        ULARGE_INTEGER _buffer2; \
+        \
+        _buffer2.LowPart = inFileTime.dwLowDateTime; \
+        _buffer2.HighPart = inFileTime.dwHighDateTime; \
+        outTime = _buffer2.QuadPart / _PR_I64_CONST(10); \
+    PR_END_MACRO
+#define _MD_FILETIME_2_MILLISECONDS(outTime, inFileTime) \
+    PR_BEGIN_MACRO \
+        ULARGE_INTEGER _buffer3; \
+        \
+        _buffer3.LowPart = inFileTime.dwLowDateTime; \
+        _buffer3.HighPart = inFileTime.dwHighDateTime; \
+        outTime = _buffer3.QuadPart / _PR_I64_CONST(10000); \
+    PR_END_MACRO
+#define _MD_FILETIME_2_SECONDS(outTime, inFileTime) \
+    PR_BEGIN_MACRO \
+        ULARGE_INTEGER _buffer4; \
+        \
+        _buffer4.LowPart = inFileTime.dwLowDateTime; \
+        _buffer4.HighPart = inFileTime.dwHighDateTime; \
+        outTime = _buffer4.QuadPart / _PR_I64_CONST(10000000); \
+    PR_END_MACRO
+#define _MD_SECONDS_2_FILETIME(outFileTime, inTime) \
+    PR_BEGIN_MACRO \
+        ULARGE_INTEGER _buffer5; \
+        \
+        _buffer5.QuadPart = (ULONGLONG)inTime * _PR_I64_CONST(10000000); \
+        outFileTime.dwLowDateTime = _buffer5.LowPart; \
+        outFileTime.dwHighDateTime = _buffer5.HighPart; \
+    PR_END_MACRO
+
+/*
+ * Conversions from FILETIME 1601 epoch time to LIBC/NSPR 1970 time.epoch.
+ */
+#define _MD_FILETIME_2_PRTime(outPRTime, inFileTime) \
+    PR_BEGIN_MACRO \
+        FILETIME _result1; \
+        ULONGLONG _conversion1; \
+        \
+        _MD_FILETIME_ARITH(_result1, inFileTime, -, _MD_FILETIME_1970); \
+        _MD_FILETIME_2_MICROSECONDS(_conversion1, _result1); \
+        outPRTime = (PRTime)_conversion1; \
+    PR_END_MACRO
+#define _MD_FILETIME_2_time_t(outTimeT, inFileTime) \
+    PR_BEGIN_MACRO \
+        FILETIME _result2; \
+        ULONGLONG _conversion2; \
+        \
+        _MD_FILETIME_ARITH(_result2, inFileTime, -, _MD_FILETIME_1970); \
+        _MD_FILETIME_2_SECONDS(_conversion2, _result2); \
+        outTimeT = (time_t)_conversion2; \
+    PR_END_MACRO
+#define _MD_time_t_2_FILETIME(outFileTime, inTimeT) \
+    PR_BEGIN_MACRO \
+        FILETIME _conversion3; \
+        \
+        _MD_SECONDS_2_FILETIME(_conversion3, inTimeT); \
+        _MD_FILETIME_ARITH(outFileTime, _conversion3, +, _MD_FILETIME_1970); \
+    PR_END_MACRO
+
+
+/*
+ * Sometimes SYSTEMTIME needs to be handled as well.
+ */
+#define _MD_SYSTEMTIME_2_PRTime(outPRTime, inSystemTime) \
+    PR_BEGIN_MACRO \
+        FILETIME _result3; \
+        \
+        SystemTimeToFileTime(&inSystemTime, &_result3); \
+        _MD_FILETIME_2_PRTime(outPRTime, _result3); \
+    PR_END_MACRO
+#define _MD_SYSTEMTIME_2_time_t(outTimeT, inSystemTime) \
+    PR_BEGIN_MACRO \
+        FILETIME _result4; \
+        \
+        SystemTimeToFileTime(&inSystemTime, &_result4); \
+        _MD_FILETIME_2_time_t(outTimeT, _result4); \
+    PR_END_MACRO
+#define _MD_time_t_2_SYSTEMTIME(outSystemTime, inTimeT) \
+    PR_BEGIN_MACRO \
+        FILETIME _conversion4; \
+        \
+        _MD_time_t_2_FILETIME(_conversion4, inTimeT); \
+        FileTimeToSystemTime(&_conversion4, &outSystemTime); \
+    PR_END_MACRO
+#define _MD_time_t_2_LOCALSYSTEMTIME(outSystemTime, inTimeT) \
+    PR_BEGIN_MACRO \
+        FILETIME _conversion5; \
+        FILETIME localConversion; \
+        \
+        _MD_time_t_2_FILETIME(_conversion5, inTimeT); \
+        FileTimeToLocalFileTime(&_conversion5, &localConversion); \
+        FileTimeToSystemTime(&localConversion, &outSystemTime); \
+    PR_END_MACRO
+
+#endif /* nspr_win32_time_h___ */
new file mode 100644
--- /dev/null
+++ b/pr/include/md/_win32_unicode.h
@@ -0,0 +1,149 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* 
+ * The contents of this file are subject to the Mozilla Public
+ * License Version 1.1 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
+ * 
+ * Software distributed under the License is distributed on an "AS
+ * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * rights and limitations under the License.
+ * 
+ * The Original Code is the Netscape Portable Runtime (NSPR).
+ * 
+ * The Initial Developer of the Original Code is Netscape
+ * Communications Corporation.  Portions created by Netscape are 
+ * Copyright (C) 1998-2000 Netscape Communications Corporation.  All
+ * Rights Reserved.
+ * 
+ * Contributor(s):
+ *  Garrett Arch Blythe 02/05/2002
+ * 
+ * Alternatively, the contents of this file may be used under the
+ * terms of the GNU General Public License Version 2 or later (the
+ * "GPL"), in which case the provisions of the GPL are applicable 
+ * instead of those above.  If you wish to allow use of your 
+ * version of this file only under the terms of the GPL and not to
+ * allow others to use your version of this file under the MPL,
+ * indicate your decision by deleting the provisions above and
+ * replace them with the notice and other provisions required by
+ * the GPL.  If you do not delete the provisions above, a recipient
+ * may use your version of this file under either the MPL or the
+ * GPL.
+ */
+
+#ifndef nspr_win32_unicode_h___
+#define nspr_win32_unicode_h___
+
+#include <windows.h>
+
+/*
+ * _PR_MD_MALLOC_A2W
+ *
+ * Automatically PR_Malloc a wide char string and return it based on the
+ *  ANSI (multi byte, ansi code page) string passed in.
+ *
+ * Caller must PR_Free the return value if non-NULL.
+ */
+LPWSTR _PR_MD_MALLOC_A2W(LPCSTR inString);
+
+/*
+ * _PR_MD_A2W
+ *
+ * Non-mallocing/faster version to return a wide char string based on the
+ *  ANSI (multi byte, ansi code page) string passed in.
+ *
+ * NOTE:  inWideStringChars is number of wide characters in outWideString,
+ *          NOT the number of bytes....
+ */
+LPWSTR _PR_MD_A2W(LPCSTR inString, LPWSTR outWideString, int inWideStringChars);
+
+/*
+ * _PR_MD_W2A
+ *
+ * Non-mallocing fucntion to return a ANSI (multi byte, ansi code page)
+ *  string based on the wide char string passed in.
+ *
+ * NOTE:  inWideStringChars is number of wide characters in outWideString,
+ *          NOT the number of bytes....
+ */
+LPSTR _PR_MD_W2A(LPCWSTR inWideString, LPSTR outString, int inStringChars);
+
+#if defined(WINCE)
+/*
+ * WinCE Only
+ *
+ * Some of the functions we intend to proxy to get around multi-byte API
+ *  assumptions are imported from DLLs.  I would rather not fake out
+ *  the linkage by prepending _imp_ ## functioname to make things happen.
+ * We need to provide our own linkage symbol for all this to work out.
+ */
+
+HANDLE
+WINAPI
+_MD_CreateFileA(
+    LPCSTR lpFileName,
+    DWORD dwDesiredAccess,
+    DWORD dwShareMode,
+    LPSECURITY_ATTRIBUTES lpSecurityAttributes,
+    DWORD dwCreationDisposition,
+    DWORD dwFlagsAndAttributes,
+    HANDLE hTemplateFile
+    );
+
+BOOL
+WINAPI
+_MD_DeleteFileA(
+    LPCSTR lpFileName
+    );
+
+BOOL
+WINAPI
+_MD_MoveFileA(
+    LPCSTR lpExistingFileName,
+    LPCSTR lpNewFileName
+    );
+
+DWORD
+WINAPI
+_MD_GetFileAttributesA(
+    LPCSTR lpFileName
+    );
+
+BOOL
+WINAPI
+_MD_CreateDirectoryA(
+    LPCSTR lpPathName,
+    LPSECURITY_ATTRIBUTES lpSecurityAttributes
+    );
+
+BOOL
+WINAPI
+_MD_RemoveDirectoryA(
+    LPCSTR lpPathName
+    );
+
+HANDLE
+WINAPI
+_MD_CreateSemaphoreA(
+    IN LPSECURITY_ATTRIBUTES lpSemaphoreAttributes,
+    IN LONG lInitialCount,
+    IN LONG lMaximumCount,
+    IN LPCSTR lpName
+    );
+
+HANDLE
+WINAPI
+_MD_CreateFileMappingA(
+    HANDLE hFile,
+    LPSECURITY_ATTRIBUTES lpFileMappingAttributes,
+    DWORD flProtect,
+    DWORD dwMaximumSizeHigh,
+    DWORD dwMaximumSizeLow,
+    LPCSTR lpName
+    );
+
+#endif /* WINCE */
+
+#endif /* nspr_win32_unicode_h___ */
new file mode 100644
--- /dev/null
+++ b/pr/include/md/_wince.cfg
@@ -0,0 +1,213 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+
+/* 
+ * The contents of this file are subject to the Mozilla Public
+ * License Version 1.1 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
+ * 
+ * Software distributed under the License is distributed on an "AS
+ * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * rights and limitations under the License.
+ * 
+ * The Original Code is the Netscape Portable Runtime (NSPR).
+ * 
+ * The Initial Developer of the Original Code is Netscape
+ * Communications Corporation.  Portions created by Netscape are 
+ * Copyright (C) 1998-2000 Netscape Communications Corporation.  All
+ * Rights Reserved.
+ * 
+ * Contributor(s):
+ *  Garrett Arch Blythe 01/15/2002
+ * 
+ * Alternatively, the contents of this file may be used under the
+ * terms of the GNU General Public License Version 2 or later (the
+ * "GPL"), in which case the provisions of the GPL are applicable 
+ * instead of those above.  If you wish to allow use of your 
+ * version of this file only under the terms of the GPL and not to
+ * allow others to use your version of this file under the MPL,
+ * indicate your decision by deleting the provisions above and
+ * replace them with the notice and other provisions required by
+ * the GPL.  If you do not delete the provisions above, a recipient
+ * may use your version of this file under either the MPL or the
+ * GPL.
+ */
+#ifndef nspr_cpucfg___
+#define nspr_cpucfg___
+
+#ifndef XP_PC
+#define XP_PC
+#endif
+
+#ifndef WIN32
+#define WIN32
+#endif
+
+#ifndef WINCE
+#define WINCE
+#endif
+
+/*
+ * Some needed types herein.
+ */
+#include <windows.h>
+#include <winnt.h>
+#include <stdlib.h>
+
+#include "md/_wince_libc.h"
+
+#define errno (*PR_GetOSErrorAddress())
+
+#define PR_AF_INET6 (-1) /* IPv6 not supported yet. */
+
+#if defined(_M_IX86) || defined(_X86_)
+
+#define IS_LITTLE_ENDIAN 1
+#undef  IS_BIG_ENDIAN
+
+#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_WORD   4
+#define PR_BYTES_PER_DWORD  8
+#define PR_BYTES_PER_DOUBLE 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_WORD    32
+#define PR_BITS_PER_DWORD   64
+#define PR_BITS_PER_DOUBLE  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_WORD_LOG2	5
+#define PR_BITS_PER_DWORD_LOG2	6
+#define PR_BITS_PER_DOUBLE_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   8
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_WORD    4
+#define PR_ALIGN_OF_DWORD   8
+#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 2
+
+#elif defined(_ARM_)
+
+#define IS_LITTLE_ENDIAN 1
+#undef  IS_BIG_ENDIAN
+
+#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_WORD   4
+#define PR_BYTES_PER_DWORD  8
+#define PR_BYTES_PER_DOUBLE 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_WORD    32
+#define PR_BITS_PER_DWORD   64
+#define PR_BITS_PER_DOUBLE  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_WORD_LOG2   5
+#define PR_BITS_PER_DWORD_LOG2  6
+#define PR_BITS_PER_DOUBLE_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   8
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_WORD    4
+#define PR_ALIGN_OF_DWORD   8
+#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 2
+
+#else /* defined(_M_IX86) || defined(_X86_) */
+
+#error unknown processor architecture
+
+#endif /* defined(_M_IX86) || defined(_X86_) */
+
+#define HAVE_LONG_LONG
+
+#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/_wince.h
@@ -0,0 +1,558 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* 
+ * The contents of this file are subject to the Mozilla Public
+ * License Version 1.1 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
+ * 
+ * Software distributed under the License is distributed on an "AS
+ * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * rights and limitations under the License.
+ * 
+ * The Original Code is the Netscape Portable Runtime (NSPR).
+ * 
+ * The Initial Developer of the Original Code is Netscape
+ * Communications Corporation.  Portions created by Netscape are 
+ * Copyright (C) 1998-2000 Netscape Communications Corporation.  All
+ * Rights Reserved.
+ * 
+ * Contributor(s):
+ *  Garrett Arch Blythe 01/15/2002
+ * 
+ * Alternatively, the contents of this file may be used under the
+ * terms of the GNU General Public License Version 2 or later (the
+ * "GPL"), in which case the provisions of the GPL are applicable 
+ * instead of those above.  If you wish to allow use of your 
+ * version of this file only under the terms of the GPL and not to
+ * allow others to use your version of this file under the MPL,
+ * indicate your decision by deleting the provisions above and
+ * replace them with the notice and other provisions required by
+ * the GPL.  If you do not delete the provisions above, a recipient
+ * may use your version of this file under either the MPL or the
+ * GPL.
+ */
+
+#ifndef nspr_wince_defs_h___
+#define nspr_wince_defs_h___
+
+#include <windows.h>
+#include <winsock.h>
+#include <winnt.h>
+#include <stdlib.h>
+#include "_win32_time.h"
+#include "_win32_unicode.h"
+
+#include "prio.h"
+
+/*
+ * Internal configuration macros
+ */
+
+#define PR_LINKER_ARCH      "win32"
+#define _PR_SI_SYSNAME        "WINCE"
+
+/*
+ * Hardcoded for now.
+ */
+#if defined(_X86_)
+#define _PR_SI_ARCHITECTURE   "x86"
+#elif defined(_ARM_)
+#define _PR_SI_ARCHITECTURE   "ARM"
+#else
+#define _PR_SI_ARHITECTURE    "XX"
+#endif
+
+#define HAVE_DLL
+#undef  HAVE_THREAD_AFFINITY
+#define _PR_HAVE_ATOMIC_OPS
+#define PR_HAVE_WIN32_NAMED_SHARED_MEMORY
+
+/* --- Common User-Thread/Native-Thread Definitions --------------------- */
+
+/* --- Globals --- */
+extern struct PRLock                      *_pr_schedLock;
+
+/* --- Typedefs --- */
+typedef void (*FiberFunc)(void *);
+
+#define PR_NUM_GCREGS           8
+typedef PRInt32	                PR_CONTEXT_TYPE[PR_NUM_GCREGS];
+#define GC_VMBASE               0x40000000
+#define GC_VMLIMIT              0x00FFFFFF
+
+#define _MD_MAGIC_THREAD	0x22222222
+#define _MD_MAGIC_THREADSTACK	0x33333333
+#define _MD_MAGIC_SEGMENT	0x44444444
+#define _MD_MAGIC_DIR		0x55555555
+#define _MD_MAGIC_CV        0x66666666
+
+struct _MDCPU {
+    int              unused;
+};
+
+struct _MDThread {
+    HANDLE           blocked_sema;      /* Threads block on this when waiting
+                                         * for IO or CondVar.
+                                         */
+    PRBool           inCVWaitQueue;     /* PR_TRUE if the thread is in the
+                                         * wait queue of some cond var.
+                                         * PR_FALSE otherwise.  */
+    HANDLE           handle;            /* Win32 thread handle */
+    PRBool           noCloseHandle;     /* Whether or not to CloseHandle */
+    PRUint32         id;
+    void            *sp;                /* only valid when suspended */
+    PRUint32         magic;             /* for debugging */
+    PR_CONTEXT_TYPE  gcContext;         /* Thread context for GC */
+    struct PRThread *prev, *next;       /* used by the cvar wait queue to
+                                         * chain the PRThread structures
+                                         * together */
+};
+
+struct _MDThreadStack {
+    PRUint32           magic;          /* for debugging */
+};
+
+struct _MDSegment {
+    PRUint32           magic;          /* for debugging */
+};
+
+#undef PROFILE_LOCKS
+
+struct _MDDir {
+    HANDLE           d_hdl;
+    WIN32_FIND_DATA  d_entry;
+    CHAR             cFileNameA[ MAX_PATH ];
+    PRBool           firstEntry;     /* Is this the entry returned
+                                      * by FindFirstFile()? */
+    PRUint32         magic;          /* for debugging */
+};
+
+struct _MDCVar {
+    PRUint32 magic;
+    struct PRThread *waitHead, *waitTail;  /* the wait queue: a doubly-
+                                            * linked list of threads
+                                            * waiting on this condition
+                                            * variable */
+    PRIntn nwait;                          /* number of threads in the
+                                            * wait queue */
+};
+
+#define _MD_CV_NOTIFIED_LENGTH 6
+typedef struct _MDNotified _MDNotified;
+struct _MDNotified {
+    PRIntn length;                     /* # of used entries in this
+                                        * structure */
+    struct {
+        struct _MDCVar *cv;            /* the condition variable notified */
+        PRIntn times;                  /* and the number of times notified */
+        struct PRThread *notifyHead;   /* list of threads to wake up */
+    } cv[_MD_CV_NOTIFIED_LENGTH];
+    _MDNotified *link;                 /* link to another of these, or NULL */
+};
+
+struct _MDLock {
+    CRITICAL_SECTION mutex;          /* this is recursive on NT */
+
+    /*
+     * When notifying cvars, there is no point in actually
+     * waking up the threads waiting on the cvars until we've
+     * released the lock.  So, we temporarily record the cvars.
+     * When doing an unlock, we'll then wake up the waiting threads.
+     */
+    struct _MDNotified notified;     /* array of conditions notified */
+#ifdef PROFILE_LOCKS
+    PRInt32 hitcount;
+    PRInt32 misscount;
+#endif
+};
+
+struct _MDSemaphore {
+    HANDLE           sem;
+};
+
+struct _MDFileDesc {
+    PRInt32 osfd;    /* The osfd can come from one of three spaces:
+                      * - For stdin, stdout, and stderr, we are using
+                      *   the libc file handle (0, 1, 2), which is an int.
+                      * - For files and pipes, we are using Win32 HANDLE,
+                      *   which is a void*.
+                      * - For sockets, we are using Winsock SOCKET, which
+                      *   is a u_int.
+                      */
+};
+
+struct _MDProcess {
+    HANDLE handle;
+    DWORD id;
+};
+
+/* --- Misc stuff --- */
+#define _MD_GET_SP(thread)            (thread)->md.gcContext[6]
+
+/* --- NT security stuff --- */
+
+extern void _PR_NT_InitSids(void);
+extern void _PR_NT_FreeSids(void);
+extern PRStatus _PR_NT_MakeSecurityDescriptorACL(
+    PRIntn mode,
+    DWORD accessTable[],
+    PSECURITY_DESCRIPTOR *resultSD,
+    PACL *resultACL
+);
+extern void _PR_NT_FreeSecurityDescriptorACL(
+    PSECURITY_DESCRIPTOR pSD, PACL pACL);
+
+/* --- IO stuff --- */
+
+#define _MD_OPEN                      _PR_MD_OPEN
+#define _MD_OPEN_FILE                 _PR_MD_OPEN_FILE
+#define _MD_READ                      _PR_MD_READ
+#define _MD_WRITE                     _PR_MD_WRITE
+#define _MD_WRITEV                    _PR_MD_WRITEV
+#define _MD_LSEEK                     _PR_MD_LSEEK
+#define _MD_LSEEK64                   _PR_MD_LSEEK64
+extern PRInt32 _MD_CloseFile(PRInt32 osfd);
+#define _MD_CLOSE_FILE                _MD_CloseFile
+#define _MD_GETFILEINFO               _PR_MD_GETFILEINFO
+#define _MD_GETFILEINFO64             _PR_MD_GETFILEINFO64
+#define _MD_GETOPENFILEINFO           _PR_MD_GETOPENFILEINFO
+#define _MD_GETOPENFILEINFO64         _PR_MD_GETOPENFILEINFO64
+#define _MD_STAT                      _PR_MD_STAT
+#define _MD_RENAME                    _PR_MD_RENAME     
+#define _MD_ACCESS                    _PR_MD_ACCESS     
+#define _MD_DELETE                    _PR_MD_DELETE     
+#define _MD_MKDIR                     _PR_MD_MKDIR      
+#define _MD_MAKE_DIR                  _PR_MD_MAKE_DIR
+#define _MD_RMDIR                     _PR_MD_RMDIR      
+#define _MD_LOCKFILE                  _PR_MD_LOCKFILE
+#define _MD_TLOCKFILE                 _PR_MD_TLOCKFILE
+#define _MD_UNLOCKFILE                _PR_MD_UNLOCKFILE
+
+/* --- Socket IO stuff --- */
+#define _MD_EACCES                WSAEACCES
+#define _MD_EADDRINUSE            WSAEADDRINUSE
+#define _MD_EADDRNOTAVAIL         WSAEADDRNOTAVAIL
+#define _MD_EAFNOSUPPORT          WSAEAFNOSUPPORT
+#define _MD_EAGAIN                WSAEWOULDBLOCK
+#define _MD_EALREADY              WSAEALREADY
+#define _MD_EBADF                 WSAEBADF
+#define _MD_ECONNREFUSED          WSAECONNREFUSED
+#define _MD_ECONNRESET            WSAECONNRESET
+#define _MD_EFAULT                WSAEFAULT
+#define _MD_EINPROGRESS           WSAEINPROGRESS
+#define _MD_EINTR                 WSAEINTR
+#define _MD_EINVAL                EINVAL
+#define _MD_EISCONN               WSAEISCONN
+#define _MD_ENETUNREACH           WSAENETUNREACH
+#define _MD_ENOENT                ENOENT
+#define _MD_ENOTCONN              WSAENOTCONN
+#define _MD_ENOTSOCK              WSAENOTSOCK
+#define _MD_EOPNOTSUPP            WSAEOPNOTSUPP
+#define _MD_EWOULDBLOCK           WSAEWOULDBLOCK
+#define _MD_GET_SOCKET_ERROR()    WSAGetLastError()
+#define _MD_SET_SOCKET_ERROR(_err) WSASetLastError(_err)
+
+#define _MD_INIT_FILEDESC(fd)
+extern void _MD_MakeNonblock(PRFileDesc *f);
+#define _MD_MAKE_NONBLOCK             _MD_MakeNonblock
+#define _MD_INIT_FD_INHERITABLE       _PR_MD_INIT_FD_INHERITABLE
+#define _MD_QUERY_FD_INHERITABLE      _PR_MD_QUERY_FD_INHERITABLE
+#define _MD_SHUTDOWN                  _PR_MD_SHUTDOWN
+#define _MD_LISTEN                    _PR_MD_LISTEN
+extern PRInt32 _MD_CloseSocket(PRInt32 osfd);
+#define _MD_CLOSE_SOCKET              _MD_CloseSocket
+#define _MD_SENDTO                    _PR_MD_SENDTO
+#define _MD_RECVFROM                  _PR_MD_RECVFROM
+#define _MD_SOCKETPAIR(s, type, proto, sv) -1
+#define _MD_GETSOCKNAME               _PR_MD_GETSOCKNAME
+#define _MD_GETPEERNAME               _PR_MD_GETPEERNAME
+#define _MD_GETSOCKOPT                _PR_MD_GETSOCKOPT
+#define _MD_SETSOCKOPT                _PR_MD_SETSOCKOPT
+#define _MD_SET_FD_INHERITABLE        _PR_MD_SET_FD_INHERITABLE
+#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)
+#if defined(WINCE)
+#define _MD_ATOMIC_ADD(ptr,val)    (InterlockedExchange((PLONG)ptr, (*(PLONG)ptr) + (LONG)val) + val)
+#else
+#define _MD_ATOMIC_ADD(ptr,val)    (InterlockedExchangeAdd((PLONG)ptr, (LONG)val) + val)
+#endif
+#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
+
+
+/* wince doesn't have async IO */
+#define _MD_SOCKET                    _PR_MD_SOCKET
+extern PRInt32 _MD_SocketAvailable(PRFileDesc *fd);
+#define _MD_SOCKETAVAILABLE           _MD_SocketAvailable
+#define _MD_PIPEAVAILABLE             _PR_MD_PIPEAVAILABLE
+#define _MD_CONNECT                   _PR_MD_CONNECT
+extern PRInt32 _MD_Accept(PRFileDesc *fd, PRNetAddr *raddr, PRUint32 *rlen,
+        PRIntervalTime timeout);
+#define _MD_ACCEPT                    _MD_Accept
+#define _MD_BIND                      _PR_MD_BIND
+#define _MD_RECV                      _PR_MD_RECV
+#define _MD_SEND                      _PR_MD_SEND
+#define _MD_PR_POLL                   _PR_MD_PR_POLL
+
+/* --- Scheduler stuff --- */
+// #define _MD_PAUSE_CPU                 _PR_MD_PAUSE_CPU
+#define _MD_PAUSE_CPU
+
+/* --- DIR stuff --- */
+#define PR_DIRECTORY_SEPARATOR        '\\'
+#define PR_DIRECTORY_SEPARATOR_STR    "\\"
+#define PR_PATH_SEPARATOR		';'
+#define PR_PATH_SEPARATOR_STR		";"
+#define _MD_ERRNO()                   GetLastError()
+#define _MD_OPEN_DIR                  _PR_MD_OPEN_DIR
+#define _MD_CLOSE_DIR                 _PR_MD_CLOSE_DIR
+#define _MD_READ_DIR                  _PR_MD_READ_DIR
+
+/* --- Segment stuff --- */
+#define _MD_INIT_SEGS()
+#define _MD_ALLOC_SEGMENT(seg, size, vaddr)   0
+#define _MD_FREE_SEGMENT(seg)
+
+/* --- Environment Stuff --- */
+#define _MD_GET_ENV                 _PR_MD_GET_ENV
+#define _MD_PUT_ENV                 _PR_MD_PUT_ENV
+
+/* --- Threading Stuff --- */
+#define _MD_DEFAULT_STACK_SIZE            0
+#define _MD_INIT_THREAD             _PR_MD_INIT_THREAD
+#define _MD_INIT_ATTACHED_THREAD    _PR_MD_INIT_THREAD
+#define _MD_CREATE_THREAD           _PR_MD_CREATE_THREAD
+#define _MD_YIELD                   _PR_MD_YIELD
+#define _MD_SET_PRIORITY            _PR_MD_SET_PRIORITY
+#define _MD_CLEAN_THREAD            _PR_MD_CLEAN_THREAD
+#define _MD_SETTHREADAFFINITYMASK   _PR_MD_SETTHREADAFFINITYMASK
+#define _MD_GETTHREADAFFINITYMASK   _PR_MD_GETTHREADAFFINITYMASK
+#define _MD_EXIT_THREAD             _PR_MD_EXIT_THREAD
+#define _MD_EXIT                    _PR_MD_EXIT
+#define _MD_SUSPEND_THREAD          _PR_MD_SUSPEND_THREAD
+#define _MD_RESUME_THREAD           _PR_MD_RESUME_THREAD
+#define _MD_SUSPEND_CPU             _PR_MD_SUSPEND_CPU
+#define _MD_RESUME_CPU              _PR_MD_RESUME_CPU
+#define _MD_BEGIN_SUSPEND_ALL()
+#define _MD_BEGIN_RESUME_ALL()
+#define _MD_END_SUSPEND_ALL()
+#define _MD_END_RESUME_ALL()
+
+/* --- Lock stuff --- */
+#define _PR_LOCK                      _MD_LOCK
+#define _PR_UNLOCK					  _MD_UNLOCK
+
+#define _MD_NEW_LOCK(lock)            (InitializeCriticalSection(&((lock)->mutex)),(lock)->notified.length=0,(lock)->notified.link=NULL,PR_SUCCESS)
+#define _MD_FREE_LOCK(lock)           DeleteCriticalSection(&((lock)->mutex))
+#define _MD_LOCK(lock)                EnterCriticalSection(&((lock)->mutex))
+#define _MD_TEST_AND_LOCK(lock)       (EnterCriticalSection(&((lock)->mutex)),0)
+#define _MD_UNLOCK                    _PR_MD_UNLOCK
+
+/* --- lock and cv waiting --- */
+#define _MD_WAIT                      _PR_MD_WAIT
+#define _MD_WAKEUP_WAITER             _PR_MD_WAKEUP_WAITER
+
+/* --- CVar ------------------- */
+#define _MD_WAIT_CV					  _PR_MD_WAIT_CV
+#define _MD_NEW_CV					  _PR_MD_NEW_CV
+#define _MD_FREE_CV					  _PR_MD_FREE_CV
+#define _MD_NOTIFY_CV				  _PR_MD_NOTIFY_CV	
+#define _MD_NOTIFYALL_CV			  _PR_MD_NOTIFYALL_CV
+
+   /* XXXMB- the IOQ stuff is certainly not working correctly yet. */
+// extern  struct _MDLock              _pr_ioq_lock;
+#define _MD_IOQ_LOCK()                
+#define _MD_IOQ_UNLOCK()              
+
+
+/* --- Initialization stuff --- */
+#define _MD_START_INTERRUPTS()
+#define _MD_STOP_INTERRUPTS()
+#define _MD_DISABLE_CLOCK_INTERRUPTS()
+#define _MD_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;
+struct PRProcessAttr;
+
+#define _MD_CREATE_PROCESS _PR_CreateWindowsProcess
+extern struct PRProcess * _PR_CreateWindowsProcess(
+    const char *path,
+    char *const *argv,
+    char *const *envp,
+    const struct PRProcessAttr *attr
+);
+
+#define _MD_DETACH_PROCESS _PR_DetachWindowsProcess
+extern PRStatus _PR_DetachWindowsProcess(struct PRProcess *process);
+
+/* --- Wait for a child process to terminate --- */
+#define _MD_WAIT_PROCESS _PR_WaitWindowsProcess
+extern PRStatus _PR_WaitWindowsProcess(struct PRProcess *process, 
+    PRInt32 *exitCode);
+
+#define _MD_KILL_PROCESS _PR_KillWindowsProcess
+extern PRStatus _PR_KillWindowsProcess(struct PRProcess *process);
+
+#define _MD_CLEANUP_BEFORE_EXIT           _PR_MD_CLEANUP_BEFORE_EXIT
+#define _MD_INIT_CONTEXT
+#define _MD_SWITCH_CONTEXT
+#define _MD_RESTORE_CONTEXT
+
+/* --- Intervals --- */
+#define _MD_INTERVAL_INIT                 _PR_MD_INTERVAL_INIT
+#define _MD_GET_INTERVAL                  _PR_MD_GET_INTERVAL
+#define _MD_INTERVAL_PER_SEC              _PR_MD_INTERVAL_PER_SEC
+#define _MD_INTERVAL_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_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_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))
+#define _MD_SET_CURRENT_CPU(_cpu) TlsSetValue(_pr_currentCPUIndex, 0)
+#endif /* _PR_USE_STATIC_TLS */
+
+/* --- Scheduler stuff --- */
+#define LOCK_SCHEDULER()                 0
+#define UNLOCK_SCHEDULER()               0
+#define _PR_LockSched()                	 0
+#define _PR_UnlockSched()                0
+
+/* --- Initialization stuff --- */
+#define _MD_INIT_LOCKS()
+
+/* --- Stack stuff --- */
+#define _MD_INIT_STACK(stack, redzone)
+#define _MD_CLEAR_STACK(stack)
+
+/* --- Memory-mapped files stuff --- */
+
+struct _MDFileMap {
+    HANDLE hFileMap;
+    DWORD dwAccess;
+};
+
+extern PRStatus _MD_CreateFileMap(struct PRFileMap *fmap, PRInt64 size);
+#define _MD_CREATE_FILE_MAP _MD_CreateFileMap
+
+extern PRInt32 _MD_GetMemMapAlignment(void);
+#define _MD_GET_MEM_MAP_ALIGNMENT _MD_GetMemMapAlignment
+
+extern void * _MD_MemMap(struct PRFileMap *fmap, PRInt64 offset,
+        PRUint32 len);
+#define _MD_MEM_MAP _MD_MemMap
+
+extern PRStatus _MD_MemUnmap(void *addr, PRUint32 size);
+#define _MD_MEM_UNMAP _MD_MemUnmap
+
+extern PRStatus _MD_CloseFileMap(struct PRFileMap *fmap);
+#define _MD_CLOSE_FILE_MAP _MD_CloseFileMap
+
+/* --- Named semaphores stuff --- */
+#define _PR_HAVE_NAMED_SEMAPHORES
+#define _MD_OPEN_SEMAPHORE            _PR_MD_OPEN_SEMAPHORE
+#define _MD_WAIT_SEMAPHORE            _PR_MD_WAIT_SEMAPHORE
+#define _MD_POST_SEMAPHORE            _PR_MD_POST_SEMAPHORE
+#define _MD_CLOSE_SEMAPHORE           _PR_MD_CLOSE_SEMAPHORE
+#define _MD_DELETE_SEMAPHORE(name)    PR_SUCCESS  /* no op */
+
+
+/*
+ * WINCE LIBC support missing some integral parts
+ */
+
+
+/*
+ * Missing types.
+ */
+typedef long _off_t; /* file offset value */
+
+/*
+ * struct stat
+ *
+ * Assumed by NSPR in a place or two.
+ */
+struct stat {
+    unsigned short st_mode;
+    _off_t st_size;
+    time_t st_atime;
+    time_t st_mtime;
+    time_t st_ctime;
+};
+
+/*
+ * Missing function oldnames.
+ */
+#define stricmp             _stricmp
+#define strcmpi             _stricmp
+#define strdup              _strdup
+
+/*
+ * Missing constants.
+ */
+#define HINSTANCE_ERROR 1 /* LoadLibrary, NULL on failure for WinCE */
+#define _S_IFDIR    0040000 /* stat, is a directory */
+#define _S_IFREG    0100000 /* stat, is a normal file */
+#define _S_IREAD    0000400 /* stat, can read */
+#define _S_IWRITE   0000200 /* stat, can write */
+#define ENOMEM 12 /* errno, out of memory */
+
+/*
+ * struct protoent is actually defined, but the functions that use it are not.
+ *
+ * And related windows specific functions to mimic these absent sockets funcs.
+ */
+#if 0
+struct protoent {
+    char* p_name;
+    char** p_aliases;
+    short p_proto;
+};
+#endif
+extern struct protoent* Wingetprotobyname(const char* inName);
+extern struct protoent* Wingetprotobynumber(int inNumber);
+
+#endif /* nspr_wince_defs_h___ */
new file mode 100644
--- /dev/null
+++ b/pr/include/md/_wince_libc.h
@@ -0,0 +1,110 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+
+/* 
+ * The contents of this file are subject to the Mozilla Public
+ * License Version 1.1 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
+ * 
+ * Software distributed under the License is distributed on an "AS
+ * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * rights and limitations under the License.
+ * 
+ * The Original Code is the Netscape Portable Runtime (NSPR).
+ * 
+ * The Initial Developer of the Original Code is Netscape
+ * Communications Corporation.  Portions created by Netscape are 
+ * Copyright (C) 1998-2000 Netscape Communications Corporation.  All
+ * Rights Reserved.
+ * 
+ * Contributor(s):
+ *  Garrett Arch Blythe 01/15/2002
+ * 
+ * Alternatively, the contents of this file may be used under the
+ * terms of the GNU General Public License Version 2 or later (the
+ * "GPL"), in which case the provisions of the GPL are applicable 
+ * instead of those above.  If you wish to allow use of your 
+ * version of this file only under the terms of the GPL and not to
+ * allow others to use your version of this file under the MPL,
+ * indicate your decision by deleting the provisions above and
+ * replace them with the notice and other provisions required by
+ * the GPL.  If you do not delete the provisions above, a recipient
+ * may use your version of this file under either the MPL or the
+ * GPL.
+ */
+
+#ifndef wince_libc___
+#define wince_libc___
+
+/*
+ * This file contains various #defines, typedefs and functions that are
+ * mising from the WinCE libc implementation.
+ *
+ * They are provided here for compatability with other systems.
+ */
+
+#include <stdlib.h>
+
+#ifdef  __cplusplus
+extern "C" {
+#endif
+
+#if defined(_NSPR_BUILD_)
+#define _NSPRIMP __declspec(dllexport)
+#else
+#define _NSPRIMP __declspec(dllimport)
+#endif
+
+/* The following definitions are generally expected in <stddef.h> */
+
+typedef int ptrdiff_t; /* pointer difference */
+
+
+/* The following definitions are generally expected in <errno.h> */
+
+#define ERANGE 34
+
+#define errno (*PR_GetOSErrorAddress())
+
+
+/* The following definitions are generally expected in <time.h> */
+
+#ifndef _TM_DEFINED
+#define _TM_DEFINED
+/*
+ * struct tm
+ *
+ * And related windows specific functions to mimic LIBC's tm funcs.
+ */
+struct tm {
+    int tm_sec;
+    int tm_min;
+    int tm_hour;
+    int tm_mday;
+    int tm_mon;
+    int tm_year;
+    int tm_wday;
+    int tm_yday;
+    int tm_isdst;
+};
+
+/* WinCE defines time_t in <stdlib.h> */
+
+/*
+ * subset of the function prototypes provided by <time.h>
+ */
+
+_NSPRIMP struct tm* gmtime(const time_t* inTimeT);
+_NSPRIMP struct tm* localtime(const time_t* inTimeT);
+_NSPRIMP time_t mktime(struct tm* inTM);
+#endif
+_NSPRIMP size_t strftime(char *strDest, size_t maxsize, const char *format,
+                         const struct tm *timeptr);
+
+
+#ifdef  __cplusplus
+}
+#endif
+
+#endif /* wince_libc___ */
new file mode 100644
--- /dev/null
+++ b/pr/include/md/_wintime.h
@@ -0,0 +1,180 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* 
+ * The contents of this file are subject to the Mozilla Public
+ * License Version 1.1 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
+ * 
+ * Software distributed under the License is distributed on an "AS
+ * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * rights and limitations under the License.
+ * 
+ * The Original Code is the Netscape Portable Runtime (NSPR).
+ * 
+ * The Initial Developer of the Original Code is Netscape
+ * Communications Corporation.  Portions created by Netscape are 
+ * Copyright (C) 1998-2000 Netscape Communications Corporation.  All
+ * Rights Reserved.
+ * 
+ * Contributor(s):
+ *  Garrett Arch Blythe 01/25/2002
+ * 
+ * Alternatively, the contents of this file may be used under the
+ * terms of the GNU General Public License Version 2 or later (the
+ * "GPL"), in which case the provisions of the GPL are applicable 
+ * instead of those above.  If you wish to allow use of your 
+ * version of this file only under the terms of the GPL and not to
+ * allow others to use your version of this file under the MPL,
+ * indicate your decision by deleting the provisions above and
+ * replace them with the notice and other provisions required by
+ * the GPL.  If you do not delete the provisions above, a recipient
+ * may use your version of this file under either the MPL or the
+ * GPL.
+ */
+
+#ifndef nspr_wintime_h___
+#define nspr_wintime_h___
+
+#include <windows.h>
+
+/*
+ * _wintime.h
+ *
+ * This file mainly exists because when porting NSPR to WinCE there was
+ *  a lack of LIBC support.  Conversion between window's FILETIME and
+ *  time_t was going to be a common operation; thus this file.
+ *
+ * I assume compiler support for int64.
+ */
+
+#if !defined(__GNUC__)
+#define _PR_I64_CONST(number) number ## i64
+#else
+#define _PR_I64_COSNT(number) number ## LL
+#endif
+
+/*
+ * FILETIME has an epoch of 1601.
+ * Precomputed the 1970 epoch so we do not have to below.
+ */
+#define _MD_FILETIME_1970 _PR_I64_CONST(116444736000000000)
+
+/*
+ * Marco to support add/sub/mul/div on a FILETIME level.
+ */
+#define _MD_FILETIME_ARITH(outFileTime, inFileTime, inOperation, inValue) \
+    PR_BEGIN_MACRO \
+        ULARGE_INTEGER buffer; \
+        \
+        buffer.LowPart = inFileTime.dwLowDateTime; \
+        buffer.HighPart = inFileTime.dwHighDateTime; \
+        buffer.QuadPart = buffer.QuadPart inOperation inValue; \
+        outFileTime.dwLowDateTime = buffer.LowPart; \
+        outFileTime.dwHighDateTime = buffer.HighPart; \
+    PR_END_MACRO
+
+/*
+ * FILETIME is in 100 nanosecond units.
+ * Provide macros for conversion to other second units.
+ */
+#define _MD_FILETIME_2_MICROSECONDS(outTime, inFileTime) \
+    PR_BEGIN_MACRO \
+        ULARGE_INTEGER buffer; \
+        \
+        buffer.LowPart = inFileTime.dwLowDateTime; \
+        buffer.HighPart = inFileTime.dwHighDateTime; \
+        outTime = buffer.QuadPart / _PR_I64_CONST(10); \
+    PR_END_MACRO
+#define _MD_FILETIME_2_MILLISECONDS(outTime, inFileTime) \
+    PR_BEGIN_MACRO \
+        ULARGE_INTEGER buffer; \
+        \
+        buffer.LowPart = inFileTime.dwLowDateTime; \
+        buffer.HighPart = inFileTime.dwHighDateTime; \
+        outTime = buffer.QuadPart / _PR_I64_CONST(10000); \
+    PR_END_MACRO
+#define _MD_FILETIME_2_SECONDS(outTime, inFileTime) \
+    PR_BEGIN_MACRO \
+        ULARGE_INTEGER buffer; \
+        \
+        buffer.LowPart = inFileTime.dwLowDateTime; \
+        buffer.HighPart = inFileTime.dwHighDateTime; \
+        outTime = buffer.QuadPart / _PR_I64_CONST(10000000); \
+    PR_END_MACRO
+#define _MD_SECONDS_2_FILETIME(outFileTime, inTime) \
+    PR_BEGIN_MACRO \
+        ULARGE_INTEGER buffer; \
+        \
+        buffer.QuadPart = (ULONGLONG)inTime * _PR_I64_CONST(10000000); \
+        outFileTime.dwLowDateTime = buffer.LowPart; \
+        outFileTime.dwHighDateTime = buffer.HighPart; \
+    PR_END_MACRO
+
+/*
+ * Conversions from FILETIME 1601 epoch time to LIBC/NSPR 1970 time.epoch.
+ */
+#define _MD_FILETIME_2_PRTime(outPRTime, inFileTime) \
+    PR_BEGIN_MACRO \
+        FILETIME result; \
+        ULONGLONG conversion; \
+        \
+        _MD_FILETIME_ARITH(result, inFileTime, -, _MD_FILETIME_1970); \
+        _MD_FILETIME_2_MICROSECONDS(conversion, result); \
+        outPRTime = (PRTime)conversion; \
+    PR_END_MACRO
+#define _MD_FILETIME_2_time_t(outTimeT, inFileTime) \
+    PR_BEGIN_MACRO \
+        FILETIME result; \
+        ULONGLONG conversion; \
+        \
+        _MD_FILETIME_ARITH(result, inFileTime, -, _MD_FILETIME_1970); \
+        _MD_FILETIME_2_SECONDS(conversion, result); \
+        outTimeT = (time_t)conversion; \
+    PR_END_MACRO
+#define _MD_time_t_2_FILETIME(outFileTime, inTimeT) \
+    PR_BEGIN_MACRO \
+        FILETIME conversion; \
+        \
+        _MD_SECONDS_2_FILETIME(conversion, inTimeT); \
+        _MD_FILETIME_ARITH(outFileTime, conversion, +, _MD_FILETIME_1970); \
+    PR_END_MACRO
+
+
+/*
+ * Sometimes SYSTEMTIME needs to be handled as well.
+ */
+#define _MD_SYSTEMTIME_2_PRTime(outPRTime, inSystemTime) \
+    PR_BEGIN_MACRO \
+        FILETIME result; \
+        \
+        SystemTimeToFileTime(&inSystemTime, &result); \
+        _MD_FILETIME_2_PRTime(outPRTime, result); \
+    PR_END_MACRO
+#define _MD_time_t_2_LOCALSYSTEMTIME(outSystemTime, inTimeT) \
+    PR_BEGIN_MACRO \
+        FILETIME conversion; \
+        FILETIME localConversion; \
+        \
+        _MD_time_t_2_FILETIME(conversion, inTimeT); \
+        FileTimeToLocalFileTime(&conversion, &localConversion); \
+        FileTimeToSystemTime(&localConversion, &outSystemTime); \
+    PR_END_MACRO
+
+/*
+ * tm is needed.
+ * Used by Winlocaltime.
+ */
+struct tm {
+    int tm_sec;
+    int tm_min;
+    int tm_hour;
+    int tm_mday;
+    int tm_mon;
+    int tm_year;
+    int tm_wday;
+    int tm_yday;
+    int tm_isdst;
+};
+
+#endif /* nspr_wintime_h___ */
--- a/pr/include/md/prosdep.h
+++ b/pr/include/md/prosdep.h
@@ -46,16 +46,19 @@ PR_BEGIN_EXTERN_C
 
 #include "md/_pcos.h"
 #ifdef WINNT
 #include "md/_winnt.h"
 #include "md/_win32_errors.h"
 #elif defined(WIN95)
 #include "md/_win95.h"
 #include "md/_win32_errors.h"
+#elif defined(WINCE)
+#include "md/_wince.h"
+#include "md/_win32_errors.h"
 #elif defined(WIN16)
 #include "md/_win16.h"
 #elif defined(OS2)
 #include "md/_os2.h"
 #include "md/_os2_errors.h"
 #else
 #error unknown Windows platform
 #endif
--- a/pr/include/obsolete/probslet.h
+++ b/pr/include/obsolete/probslet.h
@@ -153,17 +153,17 @@ NSPR_API(void)        PR_FD_CLR(PRFileDe
 NSPR_API(PRInt32)     PR_FD_ISSET(PRFileDesc *fd, PR_fd_set *set);
 NSPR_API(void)        PR_FD_NSET(PRInt32 osfd, PR_fd_set *set);
 NSPR_API(void)        PR_FD_NCLR(PRInt32 osfd, PR_fd_set *set);
 NSPR_API(PRInt32)     PR_FD_NISSET(PRInt32 osfd, PR_fd_set *set);
 
 #ifndef NO_NSPR_10_SUPPORT
 #ifdef XP_MAC
 #include <stat.h>
-#else
+#elif !defined(WINCE)
 #include <sys/stat.h>
 #endif
 
 NSPR_API(PRInt32) PR_Stat(const char *path, struct stat *buf);
 #endif /* NO_NSPR_10_SUPPORT */
 
 PR_END_EXTERN_C
 
--- a/pr/include/private/pprthred.h
+++ b/pr/include/private/pprthred.h
@@ -121,16 +121,22 @@ NSPR_API(PRInt32) PR_SetCPUAffinityMask(
 */
 NSPR_API(void) PR_ShowStatus(void);
 
 /*
 ** Set thread recycle mode to on (1) or off (0)
 */
 NSPR_API(void) PR_SetThreadRecycleMode(PRUint32 flag);
 
+/*
+** Return the address of thread's last os error variable.
+** Used to implement errno on platforms that lack it.
+*/
+NSPR_API(PRInt32 *) PR_GetOSErrorAddress(void);
+
 
 /*---------------------------------------------------------------------------
 ** THREAD PRIVATE FUNCTIONS FOR GARBAGE COLLECTIBLE THREADS           
 ---------------------------------------------------------------------------*/
 
 /* 
 ** Only Garbage collectible threads participate in resume all, suspend all and 
 ** enumeration operations.  They are also different during creation when
--- a/pr/src/io/prfile.c
+++ b/pr/src/io/prfile.c
@@ -30,17 +30,19 @@
  * the GPL.  If you do not delete the provisions above, a recipient
  * may use your version of this file under either the MPL or the
  * GPL.
  */
 
 #include "primpl.h"
 
 #include <string.h>
+#if !defined(WINCE)
 #include <fcntl.h>
+#endif
 
 #ifdef XP_UNIX
 #if defined(AIX) || defined(QNX)
 /* To pick up sysconf */
 #include <unistd.h>
 #else
 /* To pick up getrlimit, setrlimit */
 #include <sys/time.h>
@@ -698,17 +700,17 @@ PR_IMPLEMENT(PRStatus) PR_CreatePipe(
     PRFileDesc **readPipe,
     PRFileDesc **writePipe
 )
 {
 #if defined(XP_MAC)
 #pragma unused (readPipe, writePipe)
 #endif
 
-#ifdef WIN32
+#if defined(WIN32) && !defined(WINCE)
     HANDLE readEnd, writeEnd;
     SECURITY_ATTRIBUTES pipeAttributes;
 
     if (!_pr_initialized) _PR_ImplicitInitialization();
 
     ZeroMemory(&pipeAttributes, sizeof(pipeAttributes));
     pipeAttributes.nLength = sizeof(pipeAttributes);
     pipeAttributes.bInheritHandle = TRUE;
--- a/pr/src/io/prio.c
+++ b/pr/src/io/prio.c
@@ -47,28 +47,40 @@ void _PR_InitIO(void)
     const PRIOMethods *methods = PR_GetFileMethods();
 
     _PR_InitFdCache();
 
     _pr_flock_lock = PR_NewLock();
     _pr_flock_cv = PR_NewCondVar(_pr_flock_lock);
 
 #ifdef WIN32
+#if !defined(WINCE)
     _pr_stdin = PR_AllocFileDesc((PRInt32)GetStdHandle(STD_INPUT_HANDLE),
             methods);
     _pr_stdout = PR_AllocFileDesc((PRInt32)GetStdHandle(STD_OUTPUT_HANDLE),
             methods);
     _pr_stderr = PR_AllocFileDesc((PRInt32)GetStdHandle(STD_ERROR_HANDLE),
             methods);
 #ifdef WINNT
     _pr_stdin->secret->md.sync_file_io = PR_TRUE;
     _pr_stdout->secret->md.sync_file_io = PR_TRUE;
     _pr_stderr->secret->md.sync_file_io = PR_TRUE;
 #endif
 #else
+    /*
+     * WINCE has some oddity of _getstdfilex to determine stdin, et. al.
+     * As unsure what that code actually does, just get fileno here.
+     *
+     * How odd, _fileno returns a void*, so cast it...
+     */
+    _pr_stdin = PR_AllocFileDesc((PRInt32)_fileno(stdin), methods);
+    _pr_stdout = PR_AllocFileDesc((PRInt32)_fileno(stdout), methods);
+    _pr_stderr = PR_AllocFileDesc((PRInt32)_fileno(stderr), methods);
+#endif
+#else
     _pr_stdin = PR_AllocFileDesc(0, methods);
     _pr_stdout = PR_AllocFileDesc(1, methods);
     _pr_stderr = PR_AllocFileDesc(2, methods);
 #endif
     _PR_MD_INIT_FD_INHERITABLE(_pr_stdin, PR_TRUE);
     _PR_MD_INIT_FD_INHERITABLE(_pr_stdout, PR_TRUE);
     _PR_MD_INIT_FD_INHERITABLE(_pr_stderr, PR_TRUE);
 
--- a/pr/src/io/priometh.c
+++ b/pr/src/io/priometh.c
@@ -355,17 +355,17 @@ PR_IMPLEMENT(PRInt32) PR_EmulateSendFile
     PRUint32 addr_offset, mmap_len;
 
     /* Get file size */
     if (PR_SUCCESS != PR_GetOpenFileInfo(sfd->fd, &info)) {
         count = -1;
         goto done;
     }
     if (sfd->file_nbytes &&
-            (info.size < (sfd->file_offset + sfd->file_nbytes))) {
+            ((PRUint32)info.size < (sfd->file_offset + sfd->file_nbytes))) {
         /*
          * there are fewer bytes in file to send than specified
          */
         PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
         count = -1;
         goto done;
     }
     if (sfd->file_nbytes)
--- a/pr/src/io/prlog.c
+++ b/pr/src/io/prlog.c
@@ -237,17 +237,21 @@ void _PR_InitLog(void)
         PR_SetLogBuffering(isSync ? bufSize : 0);
 
         ev = PR_GetEnv("NSPR_LOG_FILE");
         if (ev && ev[0]) {
             if (!PR_SetLogFile(ev)) {
 #ifdef XP_PC
                 char* str = PR_smprintf("Unable to create nspr log file '%s'\n", ev);
                 if (str) {
+#if !defined(WINCE)
                     OutputDebugString(str);
+#else
+                    OutputDebugStringA(str);
+#endif
                     PR_smprintf_free(str);
                 }
 #else
                 fprintf(stderr, "Unable to create nspr log file '%s'\n", ev);
 #endif
             }
         } else {
 #ifdef _PR_USE_STDIO_FOR_LOGGING
@@ -350,18 +354,20 @@ PR_IMPLEMENT(PRBool) PR_SetLogFile(const
     if ( strcmp( file, "WinDebug") == 0)
     {
         logFile = WIN32_DEBUG_FILE;
         return(PR_TRUE);
     }
 #endif
     newLogFile = fopen(file, "w");
     if (newLogFile) {
+#if !defined(WINCE)
         /* We do buffering ourselves. */
         setvbuf(newLogFile, NULL, _IONBF, 0);
+#endif
         if (logFile && logFile != stdout && logFile != stderr) {
             fclose(logFile);
         }
         logFile = newLogFile;
     }
     return (PRBool) (newLogFile != 0);
 #else
     PRFileDesc *newLogFile;
@@ -435,17 +441,21 @@ PR_IMPLEMENT(void) PR_LogPrint(const cha
 #endif
     }
     va_end(ap);
 
     _PR_LOCK_LOG();
     if (logBuf == 0) {
 #ifdef XP_PC
         if ( logFile == WIN32_DEBUG_FILE)
+#if !defined(WINCE)
             OutputDebugString( line );
+#else
+            OutputDebugStringA( line );
+#endif
         else
             _PUT_LOG(logFile, line, nb);
 #else
         _PUT_LOG(logFile, line, nb);
 #endif
     } else {
         if (logp + nb > logEndp) {
             _PUT_LOG(logFile, logBuf, logp - logBuf);
@@ -468,17 +478,22 @@ PR_IMPLEMENT(void) PR_LogFlush(void)
             }
         _PR_UNLOCK_LOG();
     }
 }
 
 PR_IMPLEMENT(void) PR_Abort(void)
 {
     PR_LogPrint("Aborting");
+
+#if !defined(WINCE)
     abort();
+#else
+    TerminateProcess(GetCurrentProcess(), 3 /* exit code, same as abort */);
+#endif
 }
 
 #if defined(XP_OS2)
 /*
  * Added definitions for DebugBreak() for 2 different OS/2 compilers.
  * Doing the int3 on purpose for Visual Age so that a developer can
  * step over the instruction if so desired.  Not always possible if
  * trapping due to exception handling IBM-AKR
@@ -502,17 +517,17 @@ PR_IMPLEMENT(void) PR_Assert(const char 
 #endif
 #ifdef XP_MAC
     dprintf("Assertion failure: %s, at %s:%d\n", s, file, ln);
 #endif
 #if defined(WIN32) || defined(XP_OS2)
     DebugBreak();
 #endif
 #ifndef XP_MAC
-    abort();
+    PR_Abort();
 #endif
 }
 
 #ifdef XP_MAC
 PR_IMPLEMENT(void) PR_Init_Log(void)
 {
 	_PR_InitLog();
 }
--- a/pr/src/io/prprf.c
+++ b/pr/src/io/prprf.c
@@ -409,21 +409,21 @@ static struct NumArgState* BuildArgArray
     const char* p;
     char  c;
     struct NumArgState* nas;
     
 
     /*
     ** set the l10n_debug flag
     ** this routine should be executed only once
-    ** 'cause getenv does take time
+    ** 'cause _PR_MD_GET_ENV does take time
     */
     if( !l10n_debug_init ){
 	l10n_debug_init = PR_TRUE;
-	p = getenv( "NETSCAPE_LOCALIZATION_DEBUG" );
+	p = _PR_MD_GET_ENV( "NETSCAPE_LOCALIZATION_DEBUG" );
 	if( ( p != NULL ) && ( *p == '1' ) ){
 	    l10n_debug = PR_TRUE;
 	}
     }
 
 
     /*
     **	first pass:
--- a/pr/src/io/prsocket.c
+++ b/pr/src/io/prsocket.c
@@ -59,17 +59,17 @@ static PRBool IsValidNetAddrLen(const PR
     /*
      * The definition of the length of a Unix domain socket address
      * is not uniform, so we don't check it.
      */
     if ((addr != NULL)
 #ifdef XP_UNIX
             && (addr->raw.family != AF_UNIX)
 #endif
-            && (PR_NETADDR_SIZE(addr) != addr_len)) {
+            && (PR_NETADDR_SIZE(addr) != (PRUintn)addr_len)) {
 #if defined(LINUX) && __GLIBC__ == 2 && __GLIBC_MINOR__ == 1
         /*
          * In glibc 2.1, struct sockaddr_in6 is 24 bytes.  In glibc 2.2
          * and in the 2.4 kernel, struct sockaddr_in6 has the scope_id
          * field and is 28 bytes.  It is possible for socket functions
          * to return an addr_len greater than sizeof(struct sockaddr_in6).
          * We need to allow that.  (Bugzilla bug #77264)
          */
--- a/pr/src/linking/prlink.c
+++ b/pr/src/linking/prlink.c
@@ -351,17 +351,17 @@ PR_GetLibraryPath(void)
     PR_EnterMonitor(pr_linker_lock);
     if (_pr_currentLibPath != NULL) {
         goto exit;
     }
 
     /* initialize pr_currentLibPath */
 
 #ifdef XP_PC
-    ev = getenv("LD_LIBRARY_PATH");
+    ev = _PR_MD_GET_ENV("LD_LIBRARY_PATH");
     if (!ev) {
     ev = ".;\\lib";
     }
     ev = strdup(ev);
 #endif
 
 #ifdef XP_MAC
     {
@@ -610,32 +610,40 @@ pr_LoadLibraryByPathname(const char *nam
     }
 #endif /* XP_OS2 */
 
 #if defined(WIN32) || defined(WIN16)
     {
     HINSTANCE h;
     NODL_PROC *pfn;
 
+#if !defined(WINCE)
     h = LoadLibrary(name);
+#else
+    h = LoadLibraryA(name);
+#endif
     if (h < (HINSTANCE)HINSTANCE_ERROR) {
         oserr = _MD_ERRNO();
         PR_DELETE(lm);
         goto unlock;
     }
     lm->name = strdup(name);
     lm->dlh = h;
     lm->next = pr_loadmap;
     pr_loadmap = lm;
 
         /*
         ** Try to load a table of "static functions" provided by the DLL
         */
 
+#if !defined(WINCE)
         pfn = (NODL_PROC *)GetProcAddress(h, "NODL_TABLE");
+#else
+        pfn = (NODL_PROC *)GetProcAddress(h, TEXT("NODL_TABLE"));
+#endif
         if (pfn != NULL) {
             lm->staticTable = (*pfn)();
         }
     }
 #endif /* WIN32 || WIN16 */
 
 #if defined(XP_MAC) && TARGET_RT_MAC_CFM
     {
@@ -1216,17 +1224,21 @@ pr_FindSymbolInLib(PRLibrary *lm, const 
 #endif
     }
     
 #ifdef XP_OS2
     DosQueryProcAddr(lm->dlh, 0, (PSZ) name, (PFN *) &f);
 #endif  /* XP_OS2 */
 
 #if defined(WIN32) || defined(WIN16)
+#if !defined(WINCE)
     f = GetProcAddress(lm->dlh, name);
+#else
+    f = GetProcAddressA(lm->dlh, name);
+#endif
 #endif  /* WIN32 || WIN16 */
 
 #ifdef XP_MAC
 #if TARGET_CARBON
     if (lm->bundle)
     {
         CFStringRef nameRef = CFStringCreateWithCString(NULL, name, kCFStringEncodingASCII);
         if (nameRef) {
--- a/pr/src/md/windows/Makefile.in
+++ b/pr/src/md/windows/Makefile.in
@@ -53,16 +53,38 @@ CSRCS = \
     w16io.c  \
     w16gc.c  \
     w16error.c  \
     w16stdio.c  \
     w16callb.c \
     ntinrval.c \
     $(NULL)
 else
+ifeq ($(OS_TARGET), WINCE)
+CSRCS = \
+    ntmisc.c \
+    ntsec.c   \
+    ntsem.c   \
+    ntinrval.c \
+    ntgc.c \
+    w95thred.c \
+    w95io.c \
+    w95cv.c \
+    w32rng.c \
+    w95sock.c \
+    win32_errors.c \
+    w32ipcsem.c \
+    w32poll.c \
+    w32shm.c \
+    w95dllmain.c \
+    w32time.c \
+    w32unicode.c \
+    w32netdb.c \
+    $(NULL)
+else
 ifeq ($(OS_TARGET), WIN95)
 CSRCS =          \
     ntmisc.c \
     ntsec.c   \
     ntsem.c   \
     ntinrval.c \
     ntgc.c \
 	w95thred.c \
@@ -89,16 +111,17 @@ CSRCS =          \
 	win32_errors.c \
     w32ipcsem.c \
     w32poll.c \
     w32rng.c \
     w32shm.c \
     $(NULL)
 endif
 endif
+endif
 
 TARGETS	= $(OBJS)
 
 INCLUDES = -I$(dist_includedir) -I$(topsrcdir)/pr/include -I$(topsrcdir)/pr/include/private
 
 DEFINES += -D_NSPR_BUILD_
 
 include $(topsrcdir)/config/rules.mk
--- a/pr/src/md/windows/ntgc.c
+++ b/pr/src/md/windows/ntgc.c
@@ -64,17 +64,17 @@ PRWord *_MD_HomeGCRegisters(PRThread *t,
         /* WARNING WARNING WARNING WARNING WARNING WARNING WARNING
          *
          * This code is extremely machine dependant and completely 
          * undocumented by MS.  Its only known to work experimentally.  
          * Ready for a walk on the wild * side?
          *
          * WARNING WARNING WARNING WARNING WARNING WARNING WARNING */
 
-#if !defined WIN95 // Win95 does not have fibers
+#if !defined(WIN95) && !defined(WINCE) /* Win95/WinCE does not have fibers */
         int *fiberData = t->md.fiber_id;
 
         /* I found these offsets by disassembling SwitchToFiber().
          * Are your palms sweating yet?
          */
 
         /* 
         ** EAX is on the stack (ESP+0)
@@ -89,16 +89,18 @@ PRWord *_MD_HomeGCRegisters(PRThread *t,
         t->md.gcContext[5] = fiberData[0x2c];  /* context.Edi */
         t->md.gcContext[6] = fiberData[0x36];  /* context.Esp */
         t->md.gcContext[7] = fiberData[0x32];  /* context.Ebp */
         *np = PR_NUM_GCREGS;
 #endif
     }
     return (PRWord *)&t->md.gcContext;
 #elif defined(_ALPHA_)
+#elif defined(_ARM_)
+    return NULL;
 #endif /* defined(_X86_) */
 }
 
 /* This function is not used right now, but is left as a reference.
  * If you ever need to get the fiberID from the currently running fiber, 
  * this is it.
  */
 void *
@@ -114,10 +116,12 @@ GetMyFiberID()
     __asm {
         mov    EDX, FS:[18h]
         mov    EAX, DWORD PTR [EDX+10h]
         mov    [fiberData], EAX
     }
   
     return fiberData;
 #elif defined(_ALPHA_)
+#elif defined(_ARM_)
+    return NULL;
 #endif /* defined(_X86_) */
 }
--- a/pr/src/md/windows/ntmisc.c
+++ b/pr/src/md/windows/ntmisc.c
@@ -36,41 +36,51 @@
  * ntmisc.c
  *
  */
 
 #include "primpl.h"
 
 char *_PR_MD_GET_ENV(const char *name)
 {
+#if !defined(WINCE)
     return getenv(name);
+#else
+    return NULL;
+#endif
 }
 
 /*
 ** _PR_MD_PUT_ENV() -- add or change environment variable
 **
 **
 */
 PRIntn _PR_MD_PUT_ENV(const char *name)
 {
+#if !defined(WINCE)
     return(putenv(name));
+#else
+    return -1;
+#endif
 }
 
 
 /*
  **************************************************************************
  **************************************************************************
  **
  **     Date and time routines
  **
  **************************************************************************
  **************************************************************************
  */
 
+#if !defined(WINCE)
 #include <sys/timeb.h>
+#endif
 
 /*
  *-----------------------------------------------------------------------
  *
  * PR_Now --
  *
  *     Returns the current time in microseconds since the epoch.
  *     The epoch is midnight January 1, 1970 GMT.
@@ -79,28 +89,36 @@ PRIntn _PR_MD_PUT_ENV(const char *name)
  *     Cf. time_t time(time_t *tp)
  *
  *-----------------------------------------------------------------------
  */
 
 PR_IMPLEMENT(PRTime)
 PR_Now(void)
 {
-    PRInt64 s, ms, ms2us, s2us;
+    PRInt64 s;
+#if !defined(WINCE)
+    PRInt64 ms, ms2us, s2us;
     struct timeb b;
 
     ftime(&b);
     LL_I2L(ms2us, PR_USEC_PER_MSEC);
     LL_I2L(s2us, PR_USEC_PER_SEC);
     LL_I2L(s, b.time);
     LL_I2L(ms, b.millitm);
     LL_MUL(ms, ms, ms2us);
     LL_MUL(s, s, s2us);
     LL_ADD(s, s, ms);
-    return s;       
+#else
+    SYSTEMTIME sysTime;
+
+    GetSystemTime(&sysTime);
+    _MD_SYSTEMTIME_2_PRTime(s, sysTime);
+#endif
+    return s;
 }
 
 /*
  * The following code works around a bug in NT (Netscape Bugsplat
  * Defect ID 47942).
  *
  * In Windows NT 3.51 and 4.0, if the local time zone does not practice
  * daylight savings time, e.g., Arizona, Taiwan, and Japan, the global
@@ -111,21 +129,24 @@ PR_Now(void)
  *     _daylight   1
  *     _timezone   28800
  *
  * So at startup time, we need to invoke _PR_Win32InitTimeZone(), which
  * on NT sets these global variables to the correct values (obtained by
  * calling GetTimeZoneInformation().
  */
 
+#if !defined(WINCE)
 #include <time.h>     /* for _tzname, _daylight, _timezone */
+#endif
 
 void
 _PR_Win32InitTimeZone(void)
 {
+#if !defined(WINCE)
     OSVERSIONINFO version;
     TIME_ZONE_INFORMATION tzinfo;
 
     version.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
     if (GetVersionEx(&version) != FALSE) {
         /* Only Windows NT needs this hack */
         if (version.dwPlatformId != VER_PLATFORM_WIN32_NT) {
             return;
@@ -156,16 +177,17 @@ void
     WideCharToMultiByte(CP_ACP, 0, tzinfo.DaylightName, -1, _tzname[1],
             32, NULL, NULL);
 
     /* _timezone is in seconds.  tzinfo.Bias is in minutes. */
 
     _timezone = tzinfo.Bias * 60;
     _daylight = tzinfo.DaylightBias ? 1 : 0;
     return;
+#endif
 }
 
 /*
  ***********************************************************************
  ***********************************************************************
  *
  * Process creation routines
  *
@@ -286,16 +308,17 @@ static int assembleCmdLine(char *const *
  * and adding a null byte at the end.
  *
  * Returns 0 on success.  The resulting environment block is returned
  * in *envBlock.  Note that if envp is NULL, a NULL pointer is returned
  * in *envBlock.  Returns -1 on failure.
  */
 static int assembleEnvBlock(char **envp, char **envBlock)
 {
+#if !defined(WINCE)
     char *p;
     char *q;
     char **env;
     char *curEnv;
     char *cwdStart, *cwdEnd;
     int envBlockSize;
 
     if (envp == NULL) {
@@ -347,16 +370,23 @@ static int assembleEnvBlock(char **envp,
         q = *env;
         while (*q) {
             *p++ = *q++;
         }
         *p++ = '\0';
     }
     *p = '\0';
     return 0;
+#else
+    /*
+     * No env strings on wince.
+     */
+    *envBlock = NULL;
+    return 0;
+#endif
 }
 
 /*
  * For qsort.  We sort (case-insensitive) the environment strings
  * before generating the environment block.
  */
 static int compare(const void *arg1, const void *arg2)
 {
@@ -364,16 +394,17 @@ static int compare(const void *arg1, con
 }
 
 PRProcess * _PR_CreateWindowsProcess(
     const char *path,
     char *const *argv,
     char *const *envp,
     const PRProcessAttr *attr)
 {
+#if !defined(WINCE)
     STARTUPINFO startupInfo;
     PROCESS_INFORMATION procInfo;
     BOOL retVal;
     char *cmdLine = NULL;
     char *envBlock = NULL;
     char **newEnvp = NULL;
     const char *cwd = NULL; /* current working directory */
     PRProcess *proc = NULL;
@@ -504,16 +535,72 @@ errorExit:
     }
     if (envBlock) {
         PR_DELETE(envBlock);
     }
     if (proc) {
         PR_DELETE(proc);
     }
     return NULL;
+#else
+    PROCESS_INFORMATION procInfo;
+    BOOL retVal;
+    char *cmdLine = NULL;
+    PRProcess *proc = NULL;
+
+    proc = PR_NEW(PRProcess);
+    if (!proc) {
+        PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+        goto errorExit;
+    }
+
+    if (assembleCmdLine(argv, &cmdLine) == -1) {
+        PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+        goto errorExit;
+    }
+
+    retVal =
+#if !defined(WINCE)
+             CreateProcess(
+#else
+             CreateProcessA(
+#endif
+                           path,
+                           cmdLine,
+                           NULL,  /* not supported */
+                           NULL,  /* not supported */
+                           FALSE, /* not supported */
+                           0,     /* creation flags */
+                           NULL,  /* not supported */
+                           NULL,  /* not supported */
+                           NULL,  /* not supported */
+                           &procInfo
+                          );
+    if (retVal == FALSE) {
+        /* XXX what error code? */
+        PR_SetError(PR_UNKNOWN_ERROR, GetLastError());
+        goto errorExit;
+    }
+
+    CloseHandle(procInfo.hThread);
+    proc->md.handle = procInfo.hProcess;
+    proc->md.id = procInfo.dwProcessId;
+
+    PR_DELETE(cmdLine);
+    return proc;
+
+errorExit:
+    if (cmdLine) {
+        PR_DELETE(cmdLine);
+    }
+    if (proc) {
+        PR_DELETE(proc);
+    }
+    return NULL;
+#endif
 }  /* _PR_CreateWindowsProcess */
 
 PRStatus _PR_DetachWindowsProcess(PRProcess *process)
 {
     CloseHandle(process->md.handle);
     PR_DELETE(process);
     return PR_SUCCESS;
 }
@@ -663,18 +750,23 @@ PRStatus _MD_CreateFileMap(PRFileMap *fm
     if (fmap->prot == PR_PROT_READONLY) {
         flProtect = PAGE_READONLY;
         fmap->md.dwAccess = FILE_MAP_READ;
     } else if (fmap->prot == PR_PROT_READWRITE) {
         flProtect = PAGE_READWRITE;
         fmap->md.dwAccess = FILE_MAP_WRITE;
     } else {
         PR_ASSERT(fmap->prot == PR_PROT_WRITECOPY);
+#if !defined(WINCE)
         flProtect = PAGE_WRITECOPY;
         fmap->md.dwAccess = FILE_MAP_COPY;
+#else
+        PR_SetError(PR_OPERATION_NOT_SUPPORTED_ERROR, GetLastError());
+        return PR_FAILURE;
+#endif
     }
 
     fmap->md.hFileMap = CreateFileMapping(
         (HANDLE) osfd,
         NULL,
         flProtect,
         dwHi,
         dwLo,
--- a/pr/src/md/windows/ntsec.c
+++ b/pr/src/md/windows/ntsec.c
@@ -61,16 +61,17 @@ static struct {
 /*
  * Initialize the SIDs for owner, primary group, and the Everyone
  * group in the _pr_nt_sids structure.
  *
  * This function needs to be called by NSPR initialization.
  */
 void _PR_NT_InitSids(void)
 {
+#if !defined(WINCE)
     SID_IDENTIFIER_AUTHORITY SIDAuthWorld = SECURITY_WORLD_SID_AUTHORITY;
     HANDLE hToken = NULL; /* initialized to an arbitrary value to
                            * silence a Purify UMR warning */
     UCHAR infoBuffer[1024];
     PTOKEN_OWNER pTokenOwner = (PTOKEN_OWNER) infoBuffer;
     PTOKEN_PRIMARY_GROUP pTokenPrimaryGroup
             = (PTOKEN_PRIMARY_GROUP) infoBuffer;
     DWORD dwLength;
@@ -120,16 +121,17 @@ void _PR_NT_InitSids(void)
     PR_ASSERT(rv != 0);
 
     /* Create a well-known SID for the Everyone group. */
     rv = AllocateAndInitializeSid(&SIDAuthWorld, 1,
             SECURITY_WORLD_RID,
             0, 0, 0, 0, 0, 0, 0,
             &_pr_nt_sids.everyone);
     PR_ASSERT(rv != 0);
+#endif /* !WINCE */
 }
 
 /*
  * Free the SIDs for owner, primary group, and the Everyone group
  * in the _pr_nt_sids structure.
  *
  * This function needs to be called by NSPR cleanup.
  */
@@ -137,19 +139,21 @@ void
 _PR_NT_FreeSids(void)
 {
     if (_pr_nt_sids.owner) {
         PR_Free(_pr_nt_sids.owner);
     }
     if (_pr_nt_sids.group) {
         PR_Free(_pr_nt_sids.group);
     }
+#if !defined(WINCE)
     if (_pr_nt_sids.everyone) {
         FreeSid(_pr_nt_sids.everyone);
     }
+#endif
 }
 
 /*
  * Construct a security descriptor whose discretionary access-control
  * list implements the specified mode bits.  The SIDs for owner, group,
  * and everyone are obtained from the global _pr_nt_sids structure.
  * Both the security descriptor and access-control list are returned
  * and should be freed by a _PR_NT_FreeSecurityDescriptorACL call.
@@ -160,16 +164,17 @@ void
  */
 PRStatus
 _PR_NT_MakeSecurityDescriptorACL(
     PRIntn mode,
     DWORD accessTable[],
     PSECURITY_DESCRIPTOR *resultSD,
     PACL *resultACL)
 {
+#if !defined(WINCE)
     PSECURITY_DESCRIPTOR pSD = NULL;
     PACL pACL = NULL;
     DWORD cbACL;  /* size of ACL */
     DWORD accessMask;
 
     if (_pr_nt_sids.owner == NULL) {
         PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
         return PR_FAILURE;
@@ -253,16 +258,20 @@ PRStatus
 failed:
     if (pSD) {
         PR_Free(pSD);
     }
     if (pACL) {
         PR_Free(pACL);
     }
     return PR_FAILURE;
+#else
+    PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
+    return PR_FAILURE;
+#endif /* !WINCE */
 }
 
 /*
  * Free the specified security descriptor and access-control list
  * previously created by _PR_NT_MakeSecurityDescriptorACL.
  */
 void
 _PR_NT_FreeSecurityDescriptorACL(PSECURITY_DESCRIPTOR pSD, PACL pACL)
--- a/pr/src/md/windows/objs.mk
+++ b/pr/src/md/windows/objs.mk
@@ -42,16 +42,36 @@ CSRCS = ntmisc.c \
 	ntthread.c \
 	ntdllmn.c \
 	win32_errors.c \
 	w32ipcsem.c \
 	w32poll.c \
 	w32rng.c \
 	w32shm.c
 else
+ifeq ($(OS_TARGET),WINCE)
+CSRCS =	ntmisc.c \
+	ntsec.c \
+	ntsem.c \
+	ntinrval.c \
+	ntgc.c \
+	w95thred.c \
+	w95io.c \
+	w95cv.c \
+	w95sock.c \
+	win32_errors.c \
+	w32ipcsem.c \
+	w32poll.c \
+	w32rng.c \
+	w32shm.c \
+	w95dllmain.c \
+	w32time.c \
+	w32unicode.c \
+	w32netdb.c
+else
 ifeq ($(OS_TARGET),WIN95)
 CSRCS =	ntmisc.c \
 	ntsec.c \
 	ntsem.c \
 	ntinrval.c \
 	ntgc.c \
 	w95thred.c \
 	w95io.c \
@@ -74,16 +94,17 @@ CSRCS =	w16null.c \
 	w16io.c \
 	w16gc.c \
 	w16error.c \
 	w16stdio.c \
 	w16callb.c \
 	ntinrval.c
 endif # win16
 endif # win95
+endif # wince
 endif # winnt
 
 CSRCS	+= $(PR_MD_CSRCS)
 ASFILES += $(PR_MD_ASFILES)
 
 OBJS += $(addprefix md/windows/$(OBJDIR)/,$(CSRCS:.c=.$(OBJ_SUFFIX)))  \
 	$(addprefix md/windows/$(OBJDIR)/,$(ASFILES:.s=.$(OBJ_SUFFIX)))
 
--- a/pr/src/md/windows/w32ipcsem.c
+++ b/pr/src/md/windows/w32ipcsem.c
@@ -139,32 +139,37 @@ PRSem *_PR_MD_OPEN_SEMAPHORE(
     if (flags & PR_SEM_CREATE) {
         if (_PR_NT_MakeSecurityDescriptorACL(mode, semAccessTable,
                 &pSD, &pACL) == PR_SUCCESS) {
             sa.nLength = sizeof(sa);
             sa.lpSecurityDescriptor = pSD;
             sa.bInheritHandle = FALSE;
             lpSA = &sa;
         }
+#if !defined(WINCE)
         sem->sem = CreateSemaphore(lpSA, value, 0x7fffffff, osname);
+#else
+        sem->sem = _MD_CreateSemaphoreA(lpSA, value, 0x7fffffff, osname);
+#endif
         if (lpSA != NULL) {
             _PR_NT_FreeSecurityDescriptorACL(pSD, pACL);
         }
         if (sem->sem == NULL) {
             _PR_MD_MAP_DEFAULT_ERROR(GetLastError());
             PR_DELETE(sem);
             return NULL;
         }
         if ((flags & PR_SEM_EXCL) && (GetLastError() == ERROR_ALREADY_EXISTS)) {
             PR_SetError(PR_FILE_EXISTS_ERROR, ERROR_ALREADY_EXISTS);
             CloseHandle(sem->sem);
             PR_DELETE(sem);
             return NULL;
         }
     } else {
+#if !defined(WINCE)
         sem->sem = OpenSemaphore(
                 SEMAPHORE_MODIFY_STATE|SYNCHRONIZE, FALSE, osname);
         if (sem->sem == NULL) {
             DWORD err = GetLastError();
 
             /*
              * If we open a nonexistent named semaphore, NT
              * returns ERROR_FILE_NOT_FOUND, while Win95
@@ -173,16 +178,46 @@ PRSem *_PR_MD_OPEN_SEMAPHORE(
             if (err == ERROR_INVALID_NAME) {
                 PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
             } else {
                 _PR_MD_MAP_DEFAULT_ERROR(GetLastError());
             }
             PR_DELETE(sem);
             return NULL;
         }
+#else
+        /*
+         * WinCE has odd sematics regarding opening a semaphore.
+         * We create the semaphore.  If it existed previouisly, the
+         *  state is signaled by GetLastError....
+         */
+        sem->sem = _MD_CreateSemaphoreA(lpSA, 0, 0x7fffffff, osname);
+        if(NULL != sem->sem)
+        {
+            DWORD lastErr = GetLastError();
+
+            if(ERROR_ALREADY_EXISTS != lastErr)
+            {
+                /*
+                 * We created, not opened.
+                 * Fail....
+                 */
+                CloseHandle(sem->sem);
+                PR_DELETE(sem);
+                PR_SetError(PR_FILE_NOT_FOUND_ERROR, 0);
+                return NULL;
+            }
+        }
+        else
+        {
+            _PR_MD_MAP_DEFAULT_ERROR(GetLastError());
+            PR_DELETE(sem);
+            return NULL;
+        }
+#endif
     }
     return sem;
 }
 
 PRStatus _PR_MD_WAIT_SEMAPHORE(PRSem *sem)
 {
     DWORD rv;
 
new file mode 100644
--- /dev/null
+++ b/pr/src/md/windows/w32netdb.c
@@ -0,0 +1,109 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* 
+ * The contents of this file are subject to the Mozilla Public
+ * License Version 1.1 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
+ * 
+ * Software distributed under the License is distributed on an "AS
+ * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * rights and limitations under the License.
+ * 
+ * The Original Code is the Netscape Portable Runtime (NSPR).
+ * 
+ * The Initial Developer of the Original Code is Netscape
+ * Communications Corporation.  Portions created by Netscape are 
+ * Copyright (C) 1998-2000 Netscape Communications Corporation.  All
+ * Rights Reserved.
+ * 
+ * Contributor(s):
+ *  Garrett Arch Blythe, 02/07/2002
+ * 
+ * Alternatively, the contents of this file may be used under the
+ * terms of the GNU General Public License Version 2 or later (the
+ * "GPL"), in which case the provisions of the GPL are applicable 
+ * instead of those above.  If you wish to allow use of your 
+ * version of this file only under the terms of the GPL and not to
+ * allow others to use your version of this file under the MPL,
+ * indicate your decision by deleting the provisions above and
+ * replace them with the notice and other provisions required by
+ * the GPL.  If you do not delete the provisions above, a recipient
+ * may use your version of this file under either the MPL or the
+ * GPL.
+ */
+
+/*
+ * w32netdb.c
+ *
+ * This file exists mainly to provide an implementation of the socket
+ *  functions that are missing from certain toolsets; namely
+ *  MS eMbedded Visual Tools (Windows CE).
+ */
+
+#include "primpl.h"
+
+/*
+ * Our static protocols entries.
+ */
+static struct protoent sProtos[] = {
+    { "tcp",    NULL,   IPPROTO_TCP },
+    { "udp",    NULL,   IPPROTO_UDP },
+    { "ip",     NULL,   IPPROTO_IP },
+    { "icmp",   NULL,   IPPROTO_ICMP },
+    { "ggp",    NULL,   IPPROTO_GGP },
+    { "pup",    NULL,   IPPROTO_PUP },
+    { "idp",    NULL,   IPPROTO_IDP },
+    { "nd",     NULL,   IPPROTO_ND },
+    { "raw",    NULL,   IPPROTO_RAW }
+};
+
+#define MAX_PROTOS (sizeof(sProtos) / sizeof(struct protoent))
+
+/*
+ * Wingetprotobyname
+ *
+ * As getprotobyname
+ */
+struct protoent* Wingetprotobyname(const char* inName)
+{
+    struct protoent* retval = NULL;
+
+    if(NULL != inName)
+    {
+        unsigned uLoop;
+
+        for(uLoop = 0; uLoop < MAX_PROTOS; uLoop++)
+        {
+            if(0 == stricmp(inName, sProtos[uLoop].p_name))
+            {
+                retval = &sProtos[uLoop];
+                break;
+            }
+        }
+    }
+
+    return retval;
+}
+
+/*
+ * Wingetprotobynumber
+ *
+ * As getprotobynumber
+ */
+struct protoent* Wingetprotobynumber(int inNumber)
+{
+    struct protoent* retval = NULL;
+    unsigned uLoop;
+    
+    for(uLoop = 0; uLoop < MAX_PROTOS; uLoop++)
+    {
+        if(inNumber == sProtos[uLoop].p_proto)
+        {
+            retval = &sProtos[uLoop];
+            break;
+        }
+    }
+
+    return retval;
+}
--- a/pr/src/md/windows/w32rng.c
+++ b/pr/src/md/windows/w32rng.c
@@ -28,20 +28,22 @@
  * indicate your decision by deleting the provisions above and
  * replace them with the notice and other provisions required by
  * the GPL.  If you do not delete the provisions above, a recipient
  * may use your version of this file under either the MPL or the
  * GPL.
  */
 
 #include <windows.h>
+#if !defined(WINCE)
 #include <time.h>
 #include <io.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#endif
 #include <stdio.h>
 #include <primpl.h>
 
 static BOOL
 CurrentClockTickTime(LPDWORD lpdwHigh, LPDWORD lpdwLow)
 {
     LARGE_INTEGER   liCount;
 
@@ -89,16 +91,20 @@ extern PRSize _PR_MD_GetRandomNoise( voi
     memcpy(((char *)buf) + n, &dwVal, nBytes);
     n += nBytes;
     size -= nBytes;
 
     if (size <= 0)
         return n;
 
     // get the time in seconds since midnight Jan 1, 1970
+#if !defined(WINCE)
     time(&sTime);
+#else
+    sTime = (time_t)(PR_Now() / PR_MSEC_PER_SEC);
+#endif
     nBytes = sizeof(sTime) > size ? size : sizeof(sTime);
     memcpy(((char *)buf) + n, &sTime, nBytes);
     n += nBytes;
 
     return n;
 }
 
--- a/pr/src/md/windows/w32shm.c
+++ b/pr/src/md/windows/w32shm.c
@@ -112,17 +112,23 @@ extern PRSharedMemory * _MD_OpenSharedMe
 
         if (_PR_NT_MakeSecurityDescriptorACL(mode, filemapAccessTable,
                 &pSD, &pACL) == PR_SUCCESS) {
             sa.nLength = sizeof(sa);
             sa.lpSecurityDescriptor = pSD;
             sa.bInheritHandle = FALSE;
             lpSA = &sa;
         }
-        shm->handle = CreateFileMapping(
+        shm->handle =
+#if !defined(WINCE)
+            CreateFileMapping
+#else
+            _MD_CreateFileMappingA
+#endif
+            (
             (HANDLE)-1 ,
             lpSA,
             flProtect,
             dwHi,
             dwLo,
             shm->ipcname);
         if (lpSA != NULL) {
             _PR_NT_FreeSecurityDescriptorACL(pSD, pACL);
@@ -149,31 +155,88 @@ extern PRSharedMemory * _MD_OpenSharedMe
             } else {
                 PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, 
                     ( "PR_OpenSharedMemory: CreateFileMapping() success: %s, handle: %d",
                         shm->ipcname, shm->handle ));
                 return(shm);
             }
         }
     } else {
+#if !defined(WINCE)
         shm->handle = OpenFileMapping( FILE_MAP_WRITE, TRUE, shm->ipcname );
         if ( NULL == shm->handle ) {
             _PR_MD_MAP_DEFAULT_ERROR( GetLastError());
             PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, 
                 ( "PR_OpenSharedMemory: OpenFileMapping() failed: %s, error: %d",
                     shm->ipcname, PR_GetOSError())); 
             PR_FREEIF( shm->ipcname );
             PR_DELETE( shm );
             return(NULL);
         } else {
             PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, 
                 ( "PR_OpenSharedMemory: OpenFileMapping() success: %s, handle: %d",
                     shm->ipcname, shm->handle )); 
                 return(shm);
         }
+#else
+        dwHi = 0;
+        dwLo = shm->size;
+
+        /*
+         * WinCE has odd sematics regarding opening of an existing file
+         *   mapping.  We use CreateFileMapping and must use GetLastError
+         *   to determine if the the mapping already existed.
+         */
+        shm->handle = _MD_CreateFileMappingA(
+            (HANDLE)INVALID_HANDLE_VALUE,
+            NULL,
+            flProtect,
+            dwHi,
+            dwLo,
+            shm->ipcname);
+
+        if(NULL == shm->handle)
+        {
+            PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, 
+                ( "PR_OpenSharedMemory: CreateFileMapping() failed: %s",
+                    shm->ipcname ));
+            _PR_MD_MAP_DEFAULT_ERROR(GetLastError());
+            PR_FREEIF(shm->ipcname);
+            PR_DELETE(shm);
+            return NULL;
+        }
+        else
+        {
+            DWORD dwError = GetLastError();
+
+            /*
+             * Must have existed previously.
+             */
+            if(ERROR_ALREADY_EXISTS != dwError)
+            {
+                CloseHandle(shm->handle);
+                shm->handle = NULL;
+
+                PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, 
+                    ( "PR_OpenSharedMemory: CreateFileMapping() failed: %s",
+                        shm->ipcname ));
+                _PR_MD_MAP_DEFAULT_ERROR(dwError);
+                PR_FREEIF(shm->ipcname);
+                PR_DELETE(shm);
+                return NULL;
+            }
+            else
+            {
+                PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, 
+                    ( "PR_OpenSharedMemory: CreateFileMapping() success: %s, handle: %d",
+                        shm->ipcname, shm->handle )); 
+                return shm;
+            }
+        }
+#endif
     }
     /* returns from separate paths */
 }
 
 extern void * _MD_AttachSharedMemory( PRSharedMemory *shm, PRIntn flags )
 {
     PRUint32    access = FILE_MAP_WRITE;
     void        *addr;
@@ -251,16 +314,17 @@ extern PRStatus _MD_DeleteSharedMemory( 
 extern PRLogModuleInfo *_pr_shma_lm;
 
 extern PRFileMap* _md_OpenAnonFileMap( 
     const char *dirName,
     PRSize      size,
     PRFileMapProtect prot
 )
 {
+#if !defined(WINCE)
     PRFileMap   *fm;
     HANDLE      hFileMap;
 
     fm = PR_CreateFileMap( (PRFileDesc*)-1, size, prot );
     if ( NULL == fm )  {
         PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
             ("_md_OpenAnonFileMap(): PR_CreateFileMap(): failed"));
         goto Finished;
@@ -283,16 +347,24 @@ extern PRFileMap* _md_OpenAnonFileMap(
         fm = NULL;
         goto Finished;
     }
     CloseHandle(fm->md.hFileMap);
     fm->md.hFileMap = hFileMap;
 
 Finished:    
     return(fm);
+#else
+    /*
+    ** WinCE does not have inheritable handles.
+    ** Unsure if this should fail, but here it is....
+    */
+    PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
+    return NULL;
+#endif
 } /* end md_OpenAnonFileMap() */
 
 /*
 ** _md_ExportFileMapAsString()
 **
 */
 extern PRStatus _md_ExportFileMapAsString(
     PRFileMap *fm,
new file mode 100644
--- /dev/null
+++ b/pr/src/md/windows/w32time.c
@@ -0,0 +1,779 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* 
+ * The contents of this file are subject to the Mozilla Public
+ * License Version 1.1 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
+ * 
+ * Software distributed under the License is distributed on an "AS
+ * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * rights and limitations under the License.
+ * 
+ * The Original Code is the Netscape Portable Runtime (NSPR).
+ * 
+ * The Initial Developer of the Original Code is Netscape
+ * Communications Corporation.  Portions created by Netscape are 
+ * Copyright (C) 1998-2000 Netscape Communications Corporation.  All
+ * Rights Reserved.
+ * 
+ * Contributor(s):
+ *  Garrett Arch Blythe, 01/28/2002
+ * 
+ * Alternatively, the contents of this file may be used under the
+ * terms of the GNU General Public License Version 2 or later (the
+ * "GPL"), in which case the provisions of the GPL are applicable 
+ * instead of those above.  If you wish to allow use of your 
+ * version of this file only under the terms of the GPL and not to
+ * allow others to use your version of this file under the MPL,
+ * indicate your decision by deleting the provisions above and
+ * replace them with the notice and other provisions required by
+ * the GPL.  If you do not delete the provisions above, a recipient
+ * may use your version of this file under either the MPL or the
+ * GPL.
+ */
+
+/*
+ * w32time.c
+ *
+ * This file exists mainly to provide an implementation of the time
+ *  functions that are missing from LIBC for certain toolsets; namely
+ *  MS eMbedded Visual Tools (Windows CE).
+ */
+
+#include "primpl.h"
+
+/*
+ * Ugh, LIBC docs should have warned you.
+ * A signle static storage for the struct tm's returned by some funcs.
+ */
+static const int sDaysOfYear[12] = {
+    0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334
+};
+static struct tm tmStorage;
+
+/*
+ *  localtime
+ *
+ *  As LIBC localtime
+ */
+struct tm* localtime_r(const time_t* inTimeT,struct tm* outRetval)
+{
+    struct tm* retval = NULL;
+
+    if(NULL != inTimeT && NULL != outRetval)
+    {
+        SYSTEMTIME winLocalTime;
+        
+        _MD_time_t_2_LOCALSYSTEMTIME(winLocalTime, *inTimeT);
+        
+        outRetval->tm_sec = (int)winLocalTime.wSecond;
+        outRetval->tm_min = (int)winLocalTime.wMinute;
+        outRetval->tm_hour = (int)winLocalTime.wHour;
+        outRetval->tm_mday = (int)winLocalTime.wDay;
+        outRetval->tm_mon = (int)(winLocalTime.wMonth - 1);
+        outRetval->tm_year = (int)(winLocalTime.wYear - 1900);
+        outRetval->tm_wday = (int)winLocalTime.wDayOfWeek;
+        outRetval->tm_isdst = -1;
+
+        outRetval->tm_yday = (int)winLocalTime.wDay + sDaysOfYear[outRetval->tm_mon];
+        if(0 == (winLocalTime.wYear & 3))
+        {
+            if(2 < winLocalTime.wMonth)
+            {
+                if(0 == winLocalTime.wYear % 100)
+                {
+                    if(0 == winLocalTime.wYear % 400)
+                    {
+                        outRetval->tm_yday++;
+                    }
+                }
+                else
+                {
+                    outRetval->tm_yday++;
+                }
+            }
+        }
+
+        retval = &tmStorage;
+    }
+
+    return retval;
+}
+
+__declspec(dllexport)
+struct tm* localtime(const time_t* inTimeT)
+{
+    return localtime_r(inTimeT, &tmStorage);
+}
+
+/*
+ *  gmtime
+ *
+ *  As LIBC gmtime
+ */
+struct tm* gmtime_r(const time_t* inTimeT, struct tm* outRetval)
+{
+    struct tm* retval = NULL;
+
+    if(NULL != inTimeT)
+    {
+        SYSTEMTIME winGMTime;
+        
+        _MD_time_t_2_SYSTEMTIME(winGMTime, *inTimeT);
+        
+        outRetval->tm_sec = (int)winGMTime.wSecond;
+        outRetval->tm_min = (int)winGMTime.wMinute;
+        outRetval->tm_hour = (int)winGMTime.wHour;
+        outRetval->tm_mday = (int)winGMTime.wDay;
+        outRetval->tm_mon = (int)(winGMTime.wMonth - 1);
+        outRetval->tm_year = (int)(winGMTime.wYear - 1900);
+        outRetval->tm_wday = (int)winGMTime.wDayOfWeek;
+        outRetval->tm_isdst = -1;
+
+        outRetval->tm_yday = (int)winGMTime.wDay + sDaysOfYear[outRetval->tm_mon];
+        if(0 == (winGMTime.wYear & 3))
+        {
+            if(2 < winGMTime.wMonth)
+            {
+                if(0 == winGMTime.wYear % 100)
+                {
+                    if(0 == winGMTime.wYear % 400)
+                    {
+                        outRetval->tm_yday++;
+                    }
+                }
+                else
+                {
+                    outRetval->tm_yday++;
+                }
+            }
+        }
+
+        retval = &tmStorage;
+    }
+
+    return retval;
+}
+
+__declspec(dllexport)
+struct tm* gmtime(const time_t* inTimeT)
+{
+    return gmtime_r(inTimeT, &tmStorage);
+}
+
+/*
+ *  mktime
+ *
+ *  As LIBCs mktime
+ *  We likely have a deficiency with the handling of tm_isdst...
+ */
+__declspec(dllexport)
+time_t mktime(struct tm* inTM)
+{
+    time_t retval = (time_t)-1;
+
+    if(NULL != inTM)
+    {
+        SYSTEMTIME winTime;
+        struct tm* gmTime = NULL;
+
+        memset(&winTime, 0, sizeof(winTime));
+
+        /*
+         * Ignore tm_wday and tm_yday.
+         */
+        winTime.wSecond = inTM->tm_sec;
+        winTime.wMinute = inTM->tm_min;
+        winTime.wHour = inTM->tm_hour;
+        winTime.wDay = inTM->tm_mday;
+        winTime.wMonth = inTM->tm_mon + 1;
+        winTime.wYear = inTM->tm_year + 1900;
+
+        /*
+         * First get our time_t.
+         */
+        _MD_SYSTEMTIME_2_time_t(retval, winTime);
+
+        /*
+         * Now overwrite the struct passed in with what we believe it should be.
+         */
+        gmTime = gmtime_r(&retval, inTM);
+    }
+
+    return retval;
+}
+
+static void helper_Winstrftime(LPCWSTR inWStr,
+                               char** outAStr,
+                               int* outAStrMax,
+                               PRBool* outHadError,
+                               PRBool* outEnoughSpace,
+                               char inTestEnd)
+{
+    char *w2aRes = NULL;
+
+    w2aRes = _PR_MD_W2A(inWStr, *outAStr, *outAStrMax);
+    if(NULL != w2aRes)
+    {
+        size_t written = strlen(*outAStr);
+
+        (*outAStr) += written;
+        (*outAStrMax) -= written;
+
+        if(0 == (*outAStrMax) && '\0' != inTestEnd)
+        {
+            /* next one will fail actually, not this one */
+            *outEnoughSpace = PR_FALSE;
+        }
+    }
+    else
+    {
+        *outHadError = PR_TRUE;
+    }
+}
+
+/*
+ *  strftime
+ *
+ *  As LIBCs strftime
+ *  Use GetTimeFormat and GetDateFormat to implement.
+ */
+__declspec(dllexport)
+size_t strftime(char *strDest,
+                size_t maxsize,
+                const char *format,
+                const struct tm *timeptr)
+{
+    size_t retval = 0;
+
+    if(NULL != strDest && 0 != maxsize && NULL != format && NULL != timeptr)
+    {
+        const char* traverse = format;
+        char* outDst = strDest;
+        size_t outMax = maxsize - 1;
+        PRBool hadEnoughSpace = PR_TRUE;
+        struct tm convertTM;
+        time_t convertT;
+        SYSTEMTIME sysTime;
+        PRBool errorOut = PR_FALSE;
+
+        /*
+         * Convert the struct tm to SYSTEMTIME.
+         * The SYSTEMTIME will be used in the API calls.
+         */
+        memcpy(&convertTM, timeptr, sizeof(convertTM));
+        convertT = mktime(&convertTM);
+        _MD_time_t_2_SYSTEMTIME(sysTime, convertT);
+
+        /*
+         * Format may be empty string.
+         */
+        *outDst = '\0';
+
+        /*
+         * Loop over the format and do the right thing.
+         */
+        while('\0' != *traverse && PR_TRUE == hadEnoughSpace && PR_FALSE == errorOut)
+        {
+            switch(*traverse)
+            {
+            case '%':
+                {
+                    PRIntn offset = 0;
+                    PRBool poundOutput = PR_FALSE;
+                    WCHAR buf[128];
+
+                    traverse++;
+                    offset++;
+
+                    /*
+                     * Skip the '#' formatting option.
+                     */
+                    if('#' == *traverse)
+                    {
+                        traverse++;
+                        offset++;
+                        poundOutput = PR_TRUE;
+                    }
+
+                    switch(*traverse)
+                    {
+                    case 'a':
+                        {
+                            int getRes = 0;
+
+                            /*
+                             * Abbreviated weekday name.
+                             */
+                            traverse++;
+                            getRes = GetDateFormatW(LOCALE_USER_DEFAULT, 0, &sysTime, _T("ddd"), buf, sizeof(buf) / sizeof(WCHAR));
+                            if(0 != getRes)
+                            {
+                                helper_Winstrftime(buf, &outDst, &outMax, &errorOut, &hadEnoughSpace, *traverse);
+                            }
+                            else
+                            {
+                                errorOut = PR_TRUE;
+                            }
+                        }
+                        break;
+                    case 'A':
+                        {
+                            int getRes = 0;
+
+                            /*
+                             * Full weekday name.
+                             */
+                            traverse++;
+                            getRes = GetDateFormatW(LOCALE_USER_DEFAULT, 0, &sysTime, _T("dddd"), buf, sizeof(buf) / sizeof(WCHAR));
+                            if(0 != getRes)
+                            {
+                                helper_Winstrftime(buf, &outDst, &outMax, &errorOut, &hadEnoughSpace, *traverse);
+                            }
+                            else
+                            {
+                                errorOut = PR_TRUE;
+                            }
+                        }
+                        break;
+                    case 'b':
+                        {
+                            int getRes = 0;
+
+                            /*
+                             * Abbreviated month name.
+                             */
+                            traverse++;
+                            getRes = GetDateFormatW(LOCALE_USER_DEFAULT, 0, &sysTime, _T("MMM"), buf, sizeof(buf) / sizeof(WCHAR));
+                            if(0 != getRes)
+                            {
+                                helper_Winstrftime(buf, &outDst, &outMax, &errorOut, &hadEnoughSpace, *traverse);
+                            }
+                            else
+                            {
+                                errorOut = PR_TRUE;
+                            }
+                        }
+                        break;
+                    case 'B':
+                        {
+                            int getRes = 0;
+
+                            /*
+                             * Full month name.
+                             */
+                            traverse++;
+                            getRes = GetDateFormatW(LOCALE_USER_DEFAULT, 0, &sysTime, _T("MMMM"), buf, sizeof(buf) / sizeof(WCHAR));
+                            if(0 != getRes)
+                            {
+                                helper_Winstrftime(buf, &outDst, &outMax, &errorOut, &hadEnoughSpace, *traverse);
+                            }
+                            else
+                            {
+                                errorOut = PR_TRUE;
+                            }
+                        }
+                        break;
+                    case 'c':
+                        {
+                            int getRes = 0;
+
+                            /*
+                             * Date and time representation for locale.
+                             */
+                            traverse++;
+
+                            /*
+                             * First the date.
+                             */
+                            getRes = GetDateFormatW(LOCALE_USER_DEFAULT, (PR_TRUE == poundOutput) ? DATE_LONGDATE : DATE_SHORTDATE, &sysTime, NULL, buf, sizeof(buf) / sizeof(WCHAR));
+                            if(0 != getRes)
+                            {
+                                helper_Winstrftime(buf, &outDst, &outMax, &errorOut, &hadEnoughSpace, *traverse);
+                            }
+                            else
+                            {
+                                errorOut = PR_TRUE;
+                            }
+
+                            /*
+                             * Uhm, a guess just a space between date and time.
+                             */
+                            helper_Winstrftime(_T(" "), &outDst, &outMax, &errorOut, &hadEnoughSpace, *traverse);
+
+
+                            /*
+                             * Last the time.
+                             */
+                            getRes = GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &sysTime, NULL, buf, sizeof(buf) / sizeof(WCHAR));
+                            if(0 != getRes)
+                            {
+                                helper_Winstrftime(buf, &outDst, &outMax, &errorOut, &hadEnoughSpace, *traverse);
+                            }
+                            else
+                            {
+                                errorOut = PR_TRUE;
+                            }
+                        }
+                        break;
+                    case 'd':
+                        {
+                            int getRes = 0;
+
+                            /*
+                             * Day of month as decimal.
+                             */
+                            traverse++;
+                            getRes = GetDateFormatW(LOCALE_USER_DEFAULT, 0, &sysTime, (PR_TRUE == poundOutput) ? _T("d") : _T("dd"), buf, sizeof(buf) / sizeof(WCHAR));
+                            if(0 != getRes)
+                            {
+                                helper_Winstrftime(buf, &outDst, &outMax, &errorOut, &hadEnoughSpace, *traverse);
+                            }
+                            else
+                            {
+                                errorOut = PR_TRUE;
+                            }
+                        }
+                        break;
+                    case 'H':
+                        {
+                            int getRes = 0;
+
+                            /*
+                             * Hour in 24 hour format.
+                             */
+                            traverse++;
+                            getRes = GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &sysTime, (PR_TRUE == poundOutput) ? _T("H") : _T("HH"), buf, sizeof(buf) / sizeof(WCHAR));
+                            if(0 != getRes)
+                            {
+                                helper_Winstrftime(buf, &outDst, &outMax, &errorOut, &hadEnoughSpace, *traverse);
+                            }
+                            else
+                            {
+                                errorOut = PR_TRUE;
+                            }
+                        }
+                        break;
+                    case 'I':
+                        {
+                            int getRes = 0;
+
+                            /*
+                             * Hour in 12 hour format.
+                             */
+                            traverse++;
+                            getRes = GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &sysTime, (PR_TRUE == poundOutput) ? _T("h") : _T("hh"), buf, sizeof(buf) / sizeof(WCHAR));
+                            if(0 != getRes)
+                            {
+                                helper_Winstrftime(buf, &outDst, &outMax, &errorOut, &hadEnoughSpace, *traverse);
+                            }
+                            else
+                            {
+                                errorOut = PR_TRUE;
+                            }
+                        }
+                        break;
+                    case 'j':
+                        {
+                            /*
+                             * Day of year.
+                             */
+                            traverse++;
+                            wsprintfW(buf, (PR_TRUE == poundOutput) ? _T("d") : _T(".3d"), convertTM.tm_yday);
+                            helper_Winstrftime(buf, &outDst, &outMax, &errorOut, &hadEnoughSpace, *traverse);
+                        }
+                        break;
+                    case 'm':
+                        {
+                            int getRes = 0;
+
+                            /*
+                             * Month in decimal.
+                             */
+                            traverse++;
+                            getRes = GetDateFormatW(LOCALE_USER_DEFAULT, 0, &sysTime, (PR_TRUE == poundOutput) ? _T("M") : _T("MM"), buf, sizeof(buf) / sizeof(WCHAR));
+                            if(0 != getRes)
+                            {
+                                helper_Winstrftime(buf, &outDst, &outMax, &errorOut, &hadEnoughSpace, *traverse);
+                            }
+                            else
+                            {
+                                errorOut = PR_TRUE;
+                            }
+                        }
+                        break;
+                    case 'M':
+                        {
+                            int getRes = 0;
+
+                            /*
+                             * Minute in decimal.
+                             */
+                            traverse++;
+                            getRes = GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &sysTime, (PR_TRUE == poundOutput) ? _T("m") : _T("mm"), buf, sizeof(buf) / sizeof(WCHAR));
+                            if(0 != getRes)
+                            {
+                                helper_Winstrftime(buf, &outDst, &outMax, &errorOut, &hadEnoughSpace, *traverse);
+                            }
+                            else
+                            {
+                                errorOut = PR_TRUE;
+                            }
+                        }
+                        break;
+                    case 'p':
+                        {
+                            int getRes = 0;
+
+                            /*
+                             * 12 hour indicator.
+                             */
+                            traverse++;
+                            getRes = GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &sysTime, _T("tt"), buf, sizeof(buf) / sizeof(WCHAR));
+                            if(0 != getRes)
+                            {
+                                helper_Winstrftime(buf, &outDst, &outMax, &errorOut, &hadEnoughSpace, *traverse);
+                            }
+                            else
+                            {
+                                errorOut = PR_TRUE;
+                            }
+                        }
+                        break;
+                    case 'S':
+                        {
+                            int getRes = 0;
+
+                            /*
+                             * Second in decimal.
+                             */
+                            traverse++;
+                            getRes = GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &sysTime, (PR_TRUE == poundOutput) ? _T("s") : _T("ss"), buf, sizeof(buf) / sizeof(WCHAR));
+                            if(0 != getRes)
+                            {
+                                helper_Winstrftime(buf, &outDst, &outMax, &errorOut, &hadEnoughSpace, *traverse);
+                            }
+                            else
+                            {
+                                errorOut = PR_TRUE;
+                            }
+                        }
+                        break;
+                    case 'U':
+                        {
+                            int weekOfYear = 0;
+                            int dayAdjust = convertTM.tm_yday;
+
+                            /*
+                             * Week of year in decimal.
+                             * Sunday as first day.
+                             */
+                            traverse++;
+                            if(dayAdjust >= convertTM.tm_wday)
+                            {
+                                dayAdjust -= convertTM.tm_wday;
+                            }
+                            else
+                            {
+                                dayAdjust = 0;
+                            }
+
+                            weekOfYear = dayAdjust / 7;
+
+                            wsprintfW(buf, (PR_TRUE == poundOutput) ? _T("d") : _T(".2d"), weekOfYear);
+                            helper_Winstrftime(buf, &outDst, &outMax, &errorOut, &hadEnoughSpace, *traverse);
+                        }
+                        break;
+                    case 'w':
+                        {
+                            /*
+                             * Weekday as decimal.
+                             */
+                            traverse++;
+                            wsprintfW(buf, _T("d"), convertTM.tm_wday);
+                            helper_Winstrftime(buf, &outDst, &outMax, &errorOut, &hadEnoughSpace, *traverse);
+                        }
+                        break;
+                    case 'W':
+                        {
+                            int weekOfYear = 0;
+                            int dayOfWeek = convertTM.tm_wday;
+                            int dayAdjust = convertTM.tm_yday;
+
+                            /*
+                             * Week of year in decimal.
+                             * Monday as first day.
+                             */
+                            traverse++;
+                            if(0 == dayOfWeek)
+                            {
+                                dayOfWeek = 6;
+                            }
+                            else
+                            {
+                                dayOfWeek--;
+                            }
+                            if(dayAdjust >= dayOfWeek)
+                            {
+                                dayAdjust -= dayOfWeek;
+                            }
+                            else
+                            {
+                                dayAdjust = 0;
+                            }
+
+                            weekOfYear = dayAdjust / 7;
+
+                            wsprintfW(buf, (PR_TRUE == poundOutput) ? _T("d") : _T(".2d"), weekOfYear);
+                            helper_Winstrftime(buf, &outDst, &outMax, &errorOut, &hadEnoughSpace, *traverse);
+                        }
+                        break;
+                    case 'x':
+                        {
+                            int getRes = 0;
+
+                            /*
+                             * Date representation for locale.
+                             */
+                            traverse++;
+                            getRes = GetDateFormatW(LOCALE_USER_DEFAULT, (PR_TRUE == poundOutput) ? DATE_LONGDATE : DATE_SHORTDATE, &sysTime, NULL, buf, sizeof(buf) / sizeof(WCHAR));
+                            if(0 != getRes)
+                            {
+                                helper_Winstrftime(buf, &outDst, &outMax, &errorOut, &hadEnoughSpace, *traverse);
+                            }
+                            else
+                            {
+                                errorOut = PR_TRUE;
+                            }
+                        }
+                        break;
+                    case 'X':
+                        {
+                            int getRes = 0;
+
+                            /*
+                             * Time representation for locale.
+                             */
+                            traverse++;
+                            getRes = GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &sysTime, NULL, buf, sizeof(buf) / sizeof(WCHAR));
+                            if(0 != getRes)
+                            {
+                                helper_Winstrftime(buf, &outDst, &outMax, &errorOut, &hadEnoughSpace, *traverse);
+                            }
+                            else
+                            {
+                                errorOut = PR_TRUE;
+                            }
+                        }
+                        break;
+                    case 'y':
+                        {
+                            /*
+                             * Year without century in decimal. (00-99)
+                             */
+                            traverse++;
+                            wsprintfW(buf, (PR_TRUE == poundOutput) ? _T("d") : _T(".2d"), convertTM.tm_year % 100);
+                            helper_Winstrftime(buf, &outDst, &outMax, &errorOut, &hadEnoughSpace, *traverse);
+                        }
+                        break;
+                    case 'Y':
+                        {
+                            int getRes = 0;
+
+                            /*
+                             * Year with century, in decimal.
+                             */
+                            getRes = GetDateFormatW(LOCALE_USER_DEFAULT, 0, &sysTime, _T("YYYY"), buf, sizeof(buf) / sizeof(WCHAR));
+                            if(0 != getRes)
+                            {
+                                helper_Winstrftime(buf, &outDst, &outMax, &errorOut, &hadEnoughSpace, *traverse);
+                            }
+                            else
+                            {
+                                errorOut = PR_TRUE;
+                            }
+                        }
+                        break;
+                    case 'z':
+                    case 'Z':
+                        {
+                            /*
+                             * Time zone name or abbreviation, or nothing if not known.
+                             * We could possibly do something here with GetTimeZoneInformation,
+                             *  but is that relevant to the tm passed in?
+                             */
+                            traverse++;
+                        }
+                        break;
+                    case '%':
+                        {
+                            /*
+                             * A signle percent.
+                             */
+                            traverse++;
+                            helper_Winstrftime(_T("%"), &outDst, &outMax, &errorOut, &hadEnoughSpace, *traverse);
+                        }
+                        break;
+                    default:
+                        {
+                            /*
+                             * Unrecognized formatting option.
+                             * Back up and just output it.
+                             */
+                            traverse -= offset;
+
+                            outDst[0] = *traverse;
+                            outDst[1] = '\0';
+
+                            outMax--;
+                            outDst++;
+                            traverse++;
+
+                            /*
+                             * Check to see if we used it all up.
+                             */
+                            if(0 == outMax && '\0' != *traverse)
+                            {
+                                hadEnoughSpace = PR_FALSE;
+                            }
+                        }
+                        break;
+                    }
+                }
+                break;
+            default:
+                {
+                    /*
+                     * Add custom formatting to output.
+                     */
+                    outDst[0] = *traverse;
+                    outDst[1] = '\0';
+
+                    outMax--;
+                    outDst++;
+                    traverse++;
+
+                    /*
+                     * Check to see if we used it all up.
+                     */
+                    if(0 == outMax && '\0' != *traverse)
+                    {
+                        hadEnoughSpace = PR_FALSE;
+                    }
+                }
+                break;
+            }
+        }
+
+        if(PR_FALSE == errorOut && PR_TRUE == hadEnoughSpace)
+        {
+            /*
+             * Number of chars written is return value.
+             */
+            retval = maxsize - outMax;
+        }
+    }
+
+    return retval;
+}
new file mode 100644
--- /dev/null
+++ b/pr/src/md/windows/w32unicode.c
@@ -0,0 +1,527 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* 
+ * The contents of this file are subject to the Mozilla Public
+ * License Version 1.1 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
+ * 
+ * Software distributed under the License is distributed on an "AS
+ * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * rights and limitations under the License.
+ * 
+ * The Original Code is the Netscape Portable Runtime (NSPR).
+ * 
+ * The Initial Developer of the Original Code is Netscape
+ * Communications Corporation.  Portions created by Netscape are 
+ * Copyright (C) 1998-2000 Netscape Communications Corporation.  All
+ * Rights Reserved.
+ * 
+ * Contributor(s):
+ *  Garrett Arch Blythe, 02/05/2002
+ * 
+ * Alternatively, the contents of this file may be used under the
+ * terms of the GNU General Public License Version 2 or later (the
+ * "GPL"), in which case the provisions of the GPL are applicable 
+ * instead of those above.  If you wish to allow use of your 
+ * version of this file only under the terms of the GPL and not to
+ * allow others to use your version of this file under the MPL,
+ * indicate your decision by deleting the provisions above and
+ * replace them with the notice and other provisions required by
+ * the GPL.  If you do not delete the provisions above, a recipient
+ * may use your version of this file under either the MPL or the
+ * GPL.
+ */
+
+/*
+ * w32unicode.c
+ *
+ * This file exists mainly to provide easy ways to convert internal
+ *  multibyte string representations into their wide character
+ *  counterparts.
+ *
+ * FYI:
+ *
+ * WinCE only has the UNICODE Win32 API (funcW vs. funcA), and so there
+ *  is no choice as to which API to utilize (the main reason this file
+ *  exists).
+ * WinNT functions as a UNICODE Win32 API with automatic conversions
+ *  functioning in the funcA (using funcW would be faster for NT).
+ * Win95 functions as a multibyte Win32 API with automatic conversions
+ *  functioning in the funcW (using funcA would be faster for win9x).
+ */
+
+#include "primpl.h"
+
+/*
+ * _PR_MD_MALLOC_A2W
+ *
+ * Automatically PR_Malloc a wide char string and return it based on the
+ *  ANSI (multi byte, ansi code page) string passed in.
+ *
+ * Caller must PR_Free the return value if non-NULL.
+ */
+LPWSTR _PR_MD_MALLOC_A2W(LPCSTR inString)
+{
+    LPWSTR retval = NULL;
+
+    if(NULL != inString)
+    {
+        int neededWChars = 0;
+
+        neededWChars = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, inString, -1, NULL, 0);
+        if(0 < neededWChars)
+        {
+            LPWSTR wstr = NULL;
+
+            wstr = (LPWSTR)PR_Malloc(sizeof(WCHAR) * neededWChars);
+            if(NULL != wstr)
+            {
+                int convertRes = 0;
+
+                convertRes = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, inString, -1, wstr, neededWChars);
+                if(0 == convertRes)
+                {
+                    PR_Free(wstr);
+                }
+                else
+                {
+                    retval = wstr;
+                }
+            }
+        }
+    }
+
+    return retval;
+}
+
+/*
+ * _PR_MD_A2W
+ *
+ * Non-mallocing version to return a wide char string based on the
+ *  ANSI (multi byte, ansi code page) string passed in.
+ *
+ * NOTE:  inWideStringChars is number of wide characters in outWideString,
+ *          NOT the number of bytes....
+ */
+LPWSTR _PR_MD_A2W(LPCSTR inString, LPWSTR outWideString, int inWideStringChars)
+{
+    LPWSTR retval = outWideString;
+
+    if(NULL != outWideString)
+    {
+        int convertRes = 0;
+
+        convertRes = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, inString, -1, outWideString, inWideStringChars);
+        if(0 == convertRes)
+        {
+            retval = NULL;
+        }
+    }
+
+    return retval;
+}
+
+/*
+ * _PR_MD_W2A
+ *
+ * Non-mallocing fucntion to return a ANSI (multi byte, ansi code page)
+ *  string based on the wide char string passed in.
+ *
+ * NOTE:  inWideStringChars is number of wide characters in outWideString,
+ *          NOT the number of bytes....
+ */
+LPSTR _PR_MD_W2A(LPCWSTR inWideString, LPSTR outString, int inStringChars)
+{
+    LPSTR retval = outString;
+
+    if(NULL != outString)
+    {
+        int convertRes = 0;
+
+        convertRes = WideCharToMultiByte(
+            CP_ACP,
+            WC_COMPOSITECHECK,
+            inWideString,
+            -1,
+            outString,
+            inStringChars,
+            NULL,
+            NULL
+            );
+        if(0 == convertRes)
+        {
+            retval = NULL;
+        }
+    }
+
+    return retval;
+}
+
+#if defined(WINCE)
+
+/*
+** WINCE Only
+**
+** This entire section of code dedicated to doing conversions between
+**  ANSI code page APIs and UNICODE APIs (funcA to funcW).
+** This is similar to what NT does to support the funcAs.
+*/
+
+VOID
+WINAPI
+OutputDebugStringA(
+    LPCSTR lpOutputString
+    )
+{
+    LPWSTR wideStr = NULL;
+
+    wideStr = _PR_MD_MALLOC_A2W(lpOutputString);
+    if(NULL == lpOutputString || NULL != wideStr)
+    {
+        OutputDebugStringW(wideStr);
+
+        if(NULL != wideStr)
+        {
+            PR_Free(wideStr);
+        }
+    }
+    else
+    {
+        PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+    }
+}
+
+HINSTANCE
+WINAPI
+LoadLibraryA(
+    LPCSTR lpLibFileName
+    )
+{
+    HINSTANCE retval = NULL;
+    LPWSTR wideStr = NULL;
+    WCHAR widePath[MAX_PATH + 1];
+
+    wideStr = _PR_MD_A2W(lpLibFileName, widePath, sizeof(widePath) / sizeof(WCHAR));
+    if(NULL != wideStr)
+    {
+        retval = LoadLibraryW(wideStr);
+    }
+    else
+    {
+        PR_SetError(PR_NAME_TOO_LONG_ERROR, 0);
+    }
+
+    return retval;
+}
+
+BOOL
+WINAPI
+CreateProcessA (
+    LPCSTR pszImageName,
+    LPCSTR pszCmdLine,
+    LPSECURITY_ATTRIBUTES psaProcess,
+    LPSECURITY_ATTRIBUTES psaThread,
+    BOOL fInheritHandles,
+    DWORD fdwCreate,
+    LPVOID pvEnvironment,
+    LPSTR pszCurDir,
+    LPSTARTUPINFO psiStartInfo,
+    LPPROCESS_INFORMATION pProcInfo
+    )
+{
+    BOOL retval = FALSE;
+    LPWSTR wideImageName = NULL;
+
+    wideImageName = _PR_MD_MALLOC_A2W(pszImageName);
+    if(NULL == pszImageName || NULL != wideImageName)
+    {
+        LPWSTR wideCmdLine = NULL;
+
+        wideCmdLine = _PR_MD_MALLOC_A2W(pszCmdLine);
+        if(NULL == pszCmdLine || NULL != wideCmdLine)
+        {
+            LPWSTR wideCurDir = NULL;
+            WCHAR widePath[MAX_PATH + 1];
+
+            wideCurDir = _PR_MD_A2W(pszCurDir, widePath, sizeof(widePath) / sizeof(WCHAR));
+            retval = CreateProcessW(
+                wideImageName,
+                wideCmdLine,
+                psaProcess,
+                psaThread,
+                fInheritHandles,
+                fdwCreate,
+                pvEnvironment,
+                wideCurDir,
+                psiStartInfo,
+                pProcInfo);
+
+            if(NULL != wideCmdLine)
+            {
+                PR_Free(wideCmdLine);
+            }
+        }
+        else
+        {
+            PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+        }
+
+        if(NULL != wideImageName)
+        {
+            PR_Free(wideImageName);
+        }
+    }
+    else
+    {
+        PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+    }
+
+    return retval;
+}
+
+HANDLE
+WINAPI
+_MD_CreateFileA(
+    LPCSTR lpFileName,
+    DWORD dwDesiredAccess,
+    DWORD dwShareMode,
+    LPSECURITY_ATTRIBUTES lpSecurityAttributes,
+    DWORD dwCreationDisposition,
+    DWORD dwFlagsAndAttributes,
+    HANDLE hTemplateFile
+    )
+{
+    HANDLE retval = (HANDLE)INVALID_HANDLE_VALUE;
+    LPWSTR wideStr = NULL;
+    WCHAR widePath[MAX_PATH + 1];
+
+    wideStr = _PR_MD_A2W(lpFileName, widePath, sizeof(widePath) / sizeof(WCHAR));
+    if(NULL != wideStr)
+    {
+        retval = CreateFileW(
+            wideStr,
+            dwDesiredAccess,
+            dwShareMode,
+            lpSecurityAttributes,
+            dwCreationDisposition,
+            dwFlagsAndAttributes,
+            hTemplateFile
+            );
+    }
+    else
+    {
+        PR_SetError(PR_NAME_TOO_LONG_ERROR, 0);
+    }
+
+    return retval;
+}
+
+BOOL
+WINAPI
+_MD_DeleteFileA(
+    LPCSTR lpFileName
+    )
+{
+    BOOL retval = FALSE;
+    LPWSTR wideStr = NULL;
+    WCHAR widePath[MAX_PATH + 1];
+
+    wideStr = _PR_MD_A2W(lpFileName, widePath, sizeof(widePath) / sizeof(WCHAR));
+    if(NULL != wideStr)
+    {
+        retval = DeleteFileW(
+            wideStr
+            );
+    }
+    else
+    {
+        PR_SetError(PR_NAME_TOO_LONG_ERROR, 0);
+    }
+
+    return retval;
+}
+
+BOOL
+WINAPI
+_MD_MoveFileA(
+    LPCSTR lpExistingFileName,
+    LPCSTR lpNewFileName
+    )
+{
+    BOOL retval = FALSE;
+    LPWSTR wideStr = NULL;
+    WCHAR widePath[MAX_PATH + 1];
+    LPWSTR wideNewStr = NULL;
+    WCHAR wideNewPath[MAX_PATH + 1];
+
+    wideStr = _PR_MD_A2W(lpExistingFileName, widePath, sizeof(widePath) / sizeof(WCHAR));
+    wideNewStr = _PR_MD_A2W(lpNewFileName, wideNewPath, sizeof(wideNewPath) / sizeof(WCHAR));
+    if(NULL != wideStr && NULL != wideNewStr)
+    {
+        retval = MoveFileW(
+            wideStr,
+            wideNewStr
+            );
+    }
+    else
+    {
+        PR_SetError(PR_NAME_TOO_LONG_ERROR, 0);
+    }
+
+    return retval;
+}
+
+DWORD
+WINAPI
+_MD_GetFileAttributesA(
+    LPCSTR lpFileName
+    )
+{
+    DWORD retval = (DWORD)-1;
+    LPWSTR wideStr = NULL;
+    WCHAR widePath[MAX_PATH + 1];
+
+    wideStr = _PR_MD_A2W(lpFileName, widePath, sizeof(widePath) / sizeof(WCHAR));
+    if(NULL != wideStr)
+    {
+        retval = GetFileAttributesW(
+            wideStr
+            );
+    }
+    else
+    {
+        PR_SetError(PR_NAME_TOO_LONG_ERROR, 0);
+    }
+
+    return retval;
+}
+
+BOOL
+WINAPI
+_MD_CreateDirectoryA(
+    LPCSTR lpPathName,
+    LPSECURITY_ATTRIBUTES lpSecurityAttributes
+    )
+{
+    BOOL retval = FALSE;
+    LPWSTR wideStr = NULL;
+    WCHAR widePath[MAX_PATH + 1];
+
+    wideStr = _PR_MD_A2W(lpPathName, widePath, sizeof(widePath) / sizeof(WCHAR));
+    if(NULL != wideStr)
+    {
+        retval = CreateDirectoryW(
+            wideStr,
+            lpSecurityAttributes
+            );
+    }
+    else
+    {
+        PR_SetError(PR_NAME_TOO_LONG_ERROR, 0);
+    }
+
+    return retval;
+}
+
+BOOL
+WINAPI
+_MD_RemoveDirectoryA(
+    LPCSTR lpPathName
+    )
+{
+    BOOL retval = FALSE;
+    LPWSTR wideStr = NULL;
+    WCHAR widePath[MAX_PATH + 1];
+
+    wideStr = _PR_MD_A2W(lpPathName, widePath, sizeof(widePath) / sizeof(WCHAR));
+    if(NULL != wideStr)
+    {
+        retval = RemoveDirectoryW(
+            wideStr
+            );
+    }
+    else
+    {
+        PR_SetError(PR_NAME_TOO_LONG_ERROR, 0);
+    }
+
+    return retval;
+}
+
+HANDLE
+WINAPI
+_MD_CreateSemaphoreA(
+    IN LPSECURITY_ATTRIBUTES lpSemaphoreAttributes,
+    IN LONG lInitialCount,
+    IN LONG lMaximumCount,
+    IN LPCSTR lpName
+    )
+{
+    HANDLE retval = NULL;
+    LPWSTR wideStr = NULL;
+
+    wideStr = _PR_MD_MALLOC_A2W(lpName);
+    if(NULL == lpName || NULL != wideStr)
+    {
+        retval = CreateSemaphoreW(
+            lpSemaphoreAttributes,
+            lInitialCount,
+            lMaximumCount,
+            wideStr
+            );
+
+        if(NULL != wideStr)
+        {
+            PR_Free(wideStr);
+        }
+    }
+    else
+    {
+        PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+    }
+
+    return retval;
+}
+
+HANDLE
+WINAPI
+_MD_CreateFileMappingA(
+    HANDLE hFile,
+    LPSECURITY_ATTRIBUTES lpFileMappingAttributes,
+    DWORD flProtect,
+    DWORD dwMaximumSizeHigh,
+    DWORD dwMaximumSizeLow,
+    LPCSTR lpName
+    )
+{
+    HANDLE retval = NULL;
+    LPWSTR wideStr = NULL;
+
+    wideStr = _PR_MD_MALLOC_A2W(lpName);
+    if(NULL == lpName || NULL != wideStr)
+    {
+        retval = CreateFileMappingW(
+            hFile,
+            lpFileMappingAttributes,
+            flProtect,
+            dwMaximumSizeHigh,
+            dwMaximumSizeLow,
+            wideStr
+            );
+
+        if(NULL != wideStr)
+        {
+            PR_Free(wideStr);
+        }
+    }
+    else
+    {
+        PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+    }
+
+    return retval;
+}
+
+
+#endif /* WINCE */
\ No newline at end of file
--- a/pr/src/md/windows/w95io.c
+++ b/pr/src/md/windows/w95io.c
@@ -34,18 +34,20 @@
 
 /* Windows 95 IO module
  *
  * Assumes synchronous I/O.
  *
  */
 
 #include "primpl.h"
+#if !defined(WINCE)
 #include <direct.h>
 #include <mbstring.h>
+#endif
 
 
 struct _MDLock               _pr_ioq_lock;
 
 /*
  * NSPR-to-NT access right mapping table for files.
  */
 static DWORD fileAccessTable[] = {
@@ -199,23 +201,30 @@ PRInt32
             flags = OPEN_ALWAYS;
     } else {
         if (osflags & PR_TRUNCATE)
             flags = TRUNCATE_EXISTING;
         else
             flags = OPEN_EXISTING;
     }
 
-    file = CreateFile(name,
-                      access,
-                      FILE_SHARE_READ|FILE_SHARE_WRITE,
-                      NULL,
-                      flags,
-                      flag6,
-                      NULL);
+    file =
+#if !defined(WINCE)
+           CreateFile
+#else
+           _MD_CreateFileA
+#endif
+                      (
+                       name,
+                       access,
+                       FILE_SHARE_READ|FILE_SHARE_WRITE,
+                       NULL,
+                       flags,
+                       flag6,
+                       NULL);
     if (file == INVALID_HANDLE_VALUE) {
 		_PR_MD_MAP_OPEN_ERROR(GetLastError());
         return -1; 
 	}
 
     return (PRInt32)file;
 }
 
@@ -257,23 +266,30 @@ PRInt32
             flags = OPEN_ALWAYS;
     } else {
         if (osflags & PR_TRUNCATE)
             flags = TRUNCATE_EXISTING;
         else
             flags = OPEN_EXISTING;
     }
 
-    file = CreateFile(name,
-                      access,
-                      FILE_SHARE_READ|FILE_SHARE_WRITE,
-                      lpSA,
-                      flags,
-                      flag6,
-                      NULL);
+    file =
+#if !defined(WINCE)
+          CreateFile
+#else
+          _MD_CreateFileA
+#endif
+                      (
+                       name,
+                       access,
+                       FILE_SHARE_READ|FILE_SHARE_WRITE,
+                       lpSA,
+                       flags,
+                       flag6,
+                       NULL);
     if (lpSA != NULL) {
         _PR_NT_FreeSecurityDescriptorACL(pSD, pACL);
     }
     if (file == INVALID_HANDLE_VALUE) {
 		_PR_MD_MAP_OPEN_ERROR(GetLastError());
         return -1; 
 	}
 
@@ -441,26 +457,41 @@ PRInt32
     rv = (CloseHandle((HANDLE)osfd))?0:-1;
 	if (rv == -1)
 		_PR_MD_MAP_CLOSE_ERROR(GetLastError());
     return rv;
 }
 
 
 /* --- DIR IO ------------------------------------------------------------ */
+#if !defined(WINCE)
 #define GetFileFromDIR(d)       (d)->d_entry.cFileName
+#else
+char* GetFileFromDIR(_MDDir* d)
+{
+    char* retval = NULL;
+
+    retval = _PR_MD_W2A(d->d_entry.cFileName, d->cFileNameA, sizeof(d->cFileNameA));
+
+    return retval;
+}
+#endif
 #define FileIsHidden(d)	((d)->d_entry.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
 
 void FlipSlashes(char *cp, int len)
 {
     while (--len >= 0) {
         if (cp[0] == '/') {
             cp[0] = PR_DIRECTORY_SEPARATOR;
         }
+#if !defined(WINCE)
         cp = _mbsinc(cp);
+#else
+        cp++;
+#endif
     }
 } /* end FlipSlashes() */
 
 
 /*
 **
 ** Local implementations of standard Unix RTL functions which are not provided
 ** by the VC RTL.
@@ -503,17 +534,33 @@ PRStatus
      * another backslash.
      */
     if (filename[len - 1] == '/' || filename[len - 1] == '\\') {
         len--;
     }
     strcpy(&filename[len], "\\*.*");
     FlipSlashes( filename, strlen(filename) );
 
+#if !defined(WINCE)
     d->d_hdl = FindFirstFile( filename, &(d->d_entry) );
+#else
+    {
+        WCHAR ceFileName[MAX_PATH];
+        LPWSTR ceResult = _PR_MD_A2W(filename, ceFileName, MAX_PATH);
+
+        if(NULL != ceResult)
+        {
+            d->d_hdl = FindFirstFile( ceFileName, &(d->d_entry) );
+        }
+        else
+        {
+            d->d_hdl = INVALID_HANDLE_VALUE;
+        }
+    }
+#endif
     if ( d->d_hdl == INVALID_HANDLE_VALUE ) {
 		_PR_MD_MAP_OPENDIR_ERROR(GetLastError());
         return PR_FAILURE;
     }
     d->firstEntry = PR_TRUE;
     d->magic = _MD_MAGIC_DIR;
     return PR_SUCCESS;
 }
@@ -526,46 +573,56 @@ char *
     char *fileName;
 
     if ( d ) {
         while (1) {
             if (d->firstEntry) {
                 d->firstEntry = PR_FALSE;
                 rv = 1;
             } else {
+#if !defined(WINCE)
                 rv = FindNextFile(d->d_hdl, &(d->d_entry));
+#else
+                rv = FindNextFile(d->d_hdl, &(d->d_entry));
+#endif
             }
             if (rv == 0) {
                 break;
             }
+            if ( (flags & PR_SKIP_HIDDEN) && FileIsHidden(d))
+                 continue;
             fileName = GetFileFromDIR(d);
             if ( (flags & PR_SKIP_DOT) &&
                  (fileName[0] == '.') && (fileName[1] == '\0'))
                  continue;
             if ( (flags & PR_SKIP_DOT_DOT) &&
                  (fileName[0] == '.') && (fileName[1] == '.') &&
                  (fileName[2] == '\0'))
                  continue;
-            if ( (flags & PR_SKIP_HIDDEN) && FileIsHidden(d))
-                 continue;
             return fileName;
         }
         err = GetLastError();
         PR_ASSERT(NO_ERROR != err);
 			_PR_MD_MAP_READDIR_ERROR(err);
         return NULL;
 		}
     PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
     return NULL;
 }
 
 PRInt32
 _PR_MD_DELETE(const char *name)
 {
-    if (DeleteFile(name)) {
+    if (
+#if !defined(WINCE)
+        DeleteFile(name)
+#else
+        _MD_DeleteFileA(name)
+#endif
+        ) {
         return 0;
     } else {
 		_PR_MD_MAP_DELETE_ERROR(GetLastError());
         return -1;
     }
 }
 
 static void
@@ -619,16 +676,17 @@ static void
 #endif /* DEBUG */
 }
 
 PRInt32
 _PR_MD_STAT(const char *fn, struct stat *info)
 {
     PRInt32 rv;
 
+#if !defined(WINCE)
     rv = _stat(fn, (struct _stat *)info);
     if (-1 == rv) {
         /*
          * Check for MSVC runtime library _stat() bug.
          * (It's really a bug in FindFirstFile().)
          * If a pathname ends in a backslash or slash,
          * e.g., c:\temp\ or c:/temp/, _stat() will fail.
          * Note: a pathname ending in a slash (e.g., c:/temp/)
@@ -647,16 +705,96 @@ PRInt32
             newfn[len - 1] = '\0';
             rv = _stat(newfn, (struct _stat *)info);
         }
     }
 
     if (-1 == rv) {
         _PR_MD_MAP_STAT_ERROR(errno);
     }
+#else
+    HANDLE readHandle = NULL;
+
+    /*
+     * Initialize the out arguments.
+     */
+    memset(info, 0, sizeof(struct stat));
+    rv = 0;
+
+    /*
+     * Attempt to fill in relevant parts of the struct.
+     * In order to do this we'll need read access to the file.
+     * We won't mind sharing the file.
+     */
+    readHandle = 
+#if !defined(WINCE)
+                 CreateFile
+#else
+                 _MD_CreateFileA
+#endif
+                           (
+                            fn,
+                            GENERIC_READ,
+                            FILE_SHARE_READ | FILE_SHARE_WRITE,
+                            NULL,
+                            OPEN_EXISTING,
+                            FILE_ATTRIBUTE_NORMAL,
+                            NULL);
+    if(NULL == readHandle)
+    {
+        rv = -1;
+    }
+    else
+    {
+        BOOL bRes = FALSE;
+        BY_HANDLE_FILE_INFORMATION fileInfo;
+
+        bRes = GetFileInformationByHandle(readHandle, &fileInfo);
+        if(FALSE == bRes)
+        {
+            rv = -1;
+        }
+        else
+        {
+            /*
+             * Access Times
+             */
+            _MD_FILETIME_2_time_t(info->st_ctime, fileInfo.ftCreationTime);
+            _MD_FILETIME_2_time_t(info->st_atime, fileInfo.ftLastAccessTime);
+            _MD_FILETIME_2_time_t(info->st_mtime, fileInfo.ftLastWriteTime);
+
+            /*
+             * Size.
+             * Note, this is not stat64.
+             */
+            info->st_size = (_off_t)fileInfo.nFileSizeLow;
+
+            /*
+             * Mode.
+             */
+            info->st_mode |= _S_IREAD;
+            if(0 == (FILE_ATTRIBUTE_READONLY & fileInfo.dwFileAttributes))
+            {
+                info->st_mode |= _S_IWRITE;
+            }
+            if(FILE_ATTRIBUTE_DIRECTORY & fileInfo.dwFileAttributes)
+            {
+                info->st_mode |= _S_IFDIR;
+            }
+            else
+            {
+                info->st_mode |= _S_IFREG;
+            }
+        }
+
+        CloseHandle(readHandle);
+        readHandle = NULL;
+    }
+#endif
+
     return rv;
 }
 
 #define _PR_IS_SLASH(ch) ((ch) == '/' || (ch) == '\\')
 
 /*
  * IsRootDirectory --
  *
@@ -681,21 +819,23 @@ IsRootDirectory(char *fn, size_t buflen)
     char *p;
     PRBool slashAdded = PR_FALSE;
     PRBool rv = PR_FALSE;
 
     if (_PR_IS_SLASH(fn[0]) && fn[1] == '\0') {
         return PR_TRUE;
     }
 
+#if !defined(WINCE)
     if (isalpha(fn[0]) && fn[1] == ':' && _PR_IS_SLASH(fn[2])
             && fn[3] == '\0') {
         rv = GetDriveType(fn) > 1 ? PR_TRUE : PR_FALSE;
         return rv;
     }
+#endif
 
     /* The UNC root directory */
 
     if (_PR_IS_SLASH(fn[0]) && _PR_IS_SLASH(fn[1])) {
         /* The 'server' part should have at least one character. */
         p = &fn[2];
         if (*p == '\0' || _PR_IS_SLASH(*p)) {
             return PR_FALSE;
@@ -717,16 +857,17 @@ IsRootDirectory(char *fn, size_t buflen)
 
         /* look for the final slash */
         do {
             p++;
         } while (*p != '\0' && !_PR_IS_SLASH(*p));
         if (_PR_IS_SLASH(*p) && p[1] != '\0') {
             return PR_FALSE;
         }
+#if !defined(WINCE)
         if (*p == '\0') {
             /*
              * GetDriveType() doesn't work correctly if the
              * path is of the form \\server\share, so we add
              * a final slash temporarily.
              */
             if ((p + 1) < (fn + buflen)) {
                 *p++ = '\\';
@@ -736,16 +877,22 @@ IsRootDirectory(char *fn, size_t buflen)
                 return PR_FALSE; /* name too long */
             }
         }
         rv = GetDriveType(fn) > 1 ? PR_TRUE : PR_FALSE;
         /* restore the 'fn' buffer */
         if (slashAdded) {
             *--p = '\0';
         }
+#else
+        /*
+         * Assume the path as root.
+         */
+        rv = PR_TRUE;
+#endif
     }
     return rv;
 }
 
 PRInt32
 _PR_MD_GETFILEINFO64(const char *fn, PRFileInfo64 *info)
 {
     HANDLE hFindFile;
@@ -756,44 +903,79 @@ PRInt32
         PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
         return -1;
     }
 
     /*
      * FindFirstFile() expands wildcard characters.  So
      * we make sure the pathname contains no wildcard.
      */
-    if (NULL != _mbspbrk(fn, "?*")) {
+    if (NULL !=
+#if !defined(WINCE)
+        _mbspbrk(fn, "?*")
+#else
+        strpbrk(fn, "?*")
+#endif
+        ) {
         PR_SetError(PR_FILE_NOT_FOUND_ERROR, 0);
         return -1;
     }
 
+#if !defined(WINCE)
     hFindFile = FindFirstFile(fn, &findFileData);
+#else
+    {
+        WCHAR ceFileName[MAX_PATH + 1];
+        LPWSTR ceResult = _PR_MD_A2W(fn, ceFileName, sizeof(ceFileName) / sizeof(WCHAR));
+
+        if(NULL != ceResult)
+        {
+            hFindFile = FindFirstFile(ceFileName, &findFileData);
+        }
+        else
+        {
+            hFindFile = INVALID_HANDLE_VALUE;
+        }
+    }
+#endif
     if (INVALID_HANDLE_VALUE == hFindFile) {
         DWORD len;
+#if !defined(WINCE)
         char *filePart;
+#endif
 
         /*
          * FindFirstFile() does not work correctly on root directories.
          * It also doesn't work correctly on a pathname that ends in a
          * slash.  So we first check to see if the pathname specifies a
          * root directory.  If not, and if the pathname ends in a slash,
          * we remove the final slash and try again.
          */
 
         /*
          * If the pathname does not contain ., \, and /, it cannot be
          * a root directory or a pathname that ends in a slash.
          */
-        if (NULL == _mbspbrk(fn, ".\\/")) {
+        if (NULL ==
+#if !defined(WINCE)
+            _mbspbrk(fn, ".\\/")
+#else
+            strpbrk(fn, ".\\/")
+#endif
+            ) {
             _PR_MD_MAP_OPENDIR_ERROR(GetLastError());
             return -1;
         } 
+#if !defined(WINCE)
         len = GetFullPathName(fn, sizeof(pathbuf), pathbuf,
                 &filePart);
+#else
+        strncpy(pathbuf, fn, sizeof(pathbuf));
+        len = strlen(pathbuf);
+#endif
         if (0 == len) {
             _PR_MD_MAP_OPENDIR_ERROR(GetLastError());
             return -1;
         }
         if (len > sizeof(pathbuf)) {
             PR_SetError(PR_NAME_TOO_LONG_ERROR, 0);
             return -1;
         }
@@ -807,17 +989,33 @@ PRInt32
             info->creationTime = 0;
             return 0;
         }
         if (!_PR_IS_SLASH(pathbuf[len - 1])) {
             _PR_MD_MAP_OPENDIR_ERROR(GetLastError());
             return -1;
         } else {
             pathbuf[len - 1] = '\0';
+#if !defined(WINCE)
             hFindFile = FindFirstFile(pathbuf, &findFileData);
+#else
+            {
+                WCHAR ceFileName[MAX_PATH + 1];
+                LPWSTR ceResult = _PR_MD_A2W(pathbuf, ceFileName, sizeof(ceFileName) / sizeof(WCHAR));
+                
+                if(NULL != ceResult)
+                {
+                    hFindFile = FindFirstFile(ceFileName, &findFileData);
+                }
+                else
+                {
+                    hFindFile = INVALID_HANDLE_VALUE;
+                }
+            }
+#endif
             if (INVALID_HANDLE_VALUE == hFindFile) {
                 _PR_MD_MAP_OPENDIR_ERROR(GetLastError());
                 return -1;
             }
         }
     }
 
     FindClose(hFindFile);
@@ -899,98 +1097,152 @@ PRInt32
         LL_L2I(info->size, info64.size);
     }
     return rv;
 }
 
 PRStatus
 _PR_MD_SET_FD_INHERITABLE(PRFileDesc *fd, PRBool inheritable)
 {
+#if !defined(WINCE)
     BOOL rv;
 
     /*
      * The SetHandleInformation function fails with the
      * ERROR_CALL_NOT_IMPLEMENTED error on Win95.
      */
     rv = SetHandleInformation(
             (HANDLE)fd->secret->md.osfd,
             HANDLE_FLAG_INHERIT,
             inheritable ? HANDLE_FLAG_INHERIT : 0);
     if (0 == rv) {
         _PR_MD_MAP_DEFAULT_ERROR(GetLastError());
         return PR_FAILURE;
     }
     return PR_SUCCESS;
+#else
+    _PR_MD_MAP_DEFAULT_ERROR(ERROR_CALL_NOT_IMPLEMENTED);
+    return PR_FAILURE;
+#endif
 } 
 
 void
 _PR_MD_INIT_FD_INHERITABLE(PRFileDesc *fd, PRBool imported)
 {
     if (imported) {
         fd->secret->inheritable = _PR_TRI_UNKNOWN;
     } else {
         fd->secret->inheritable = _PR_TRI_FALSE;
     }
 }
 
 void
 _PR_MD_QUERY_FD_INHERITABLE(PRFileDesc *fd)
 {
+#if !defined(WINCE)
     DWORD flags;
 
     PR_ASSERT(_PR_TRI_UNKNOWN == fd->secret->inheritable);
     if (GetHandleInformation((HANDLE)fd->secret->md.osfd, &flags)) {
         if (flags & HANDLE_FLAG_INHERIT) {
             fd->secret->inheritable = _PR_TRI_TRUE;
         } else {
             fd->secret->inheritable = _PR_TRI_FALSE;
         }
     }
+#else
+    fd->secret->inheritable = _PR_TRI_FALSE;
+#endif
 }
 
 PRInt32
 _PR_MD_RENAME(const char *from, const char *to)
 {
     /* Does this work with dot-relative pathnames? */
-    if (MoveFile(from, to)) {
+    if (
+#if !defined(WINCE)
+        MoveFile(from, to)
+#else
+        _MD_MoveFileA(from, to)
+#endif
+        ) {
         return 0;
     } else {
 		_PR_MD_MAP_RENAME_ERROR(GetLastError());
         return -1;
     }
 }
 
 PRInt32
 _PR_MD_ACCESS(const char *name, PRAccessHow how)
 {
-PRInt32 rv;
+    PRInt32 rv = -1;
+
+#if !defined(WINCE)
     switch (how) {
       case PR_ACCESS_WRITE_OK:
         rv = _access(name, 02);
 		break;
       case PR_ACCESS_READ_OK:
         rv = _access(name, 04);
 		break;
       case PR_ACCESS_EXISTS:
         return _access(name, 00);
 	  	break;
       default:
 		PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
 		return -1;
     }
 	if (rv < 0)
 		_PR_MD_MAP_ACCESS_ERROR(errno);
+#else
+    DWORD attribs = 0;
+
+#if !defined(WINCE)
+    attribs = GetFileAttributes(name);
+#else
+    attribs = _MD_GetFileAttributesA(name);
+#endif
+    if((DWORD)-1 != attribs)
+    {
+        switch(how)
+        {
+        case PR_ACCESS_WRITE_OK:
+            if(FILE_ATTRIBUTE_READONLY & attribs)
+            {
+                rv = 0;
+            }
+            break;
+        case PR_ACCESS_READ_OK:
+            rv = 0;
+            break;
+        case PR_ACCESS_EXISTS:
+            rv = 0;
+            break;
+        default:
+            PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+            break;
+        }
+    }
+#endif
+
     return rv;
 }
 
 PRInt32
 _PR_MD_MKDIR(const char *name, PRIntn mode)
 {
     /* XXXMB - how to translate the "mode"??? */
-    if (CreateDirectory(name, NULL)) {
+    if (
+#if !defined(WINCE)
+        CreateDirectory(name, NULL)
+#else
+        _MD_CreateDirectoryA(name, NULL)
+#endif
+        ) {
         return 0;
     } else {
 		_PR_MD_MAP_MKDIR_ERROR(GetLastError());
         return -1;
     }
 }
 
 PRInt32
@@ -1004,84 +1256,104 @@ PRInt32
 
     if (_PR_NT_MakeSecurityDescriptorACL(mode, dirAccessTable,
             &pSD, &pACL) == PR_SUCCESS) {
         sa.nLength = sizeof(sa);
         sa.lpSecurityDescriptor = pSD;
         sa.bInheritHandle = FALSE;
         lpSA = &sa;
     }
+#if !defined(WINCE)
     rv = CreateDirectory(name, lpSA);
+#else
+    rv = _MD_CreateDirectoryA(name, lpSA);
+#endif
     if (lpSA != NULL) {
         _PR_NT_FreeSecurityDescriptorACL(pSD, pACL);
     }
     if (rv) {
         return 0;
     } else {
         _PR_MD_MAP_MKDIR_ERROR(GetLastError());
         return -1;
     }
 }
 
 PRInt32
 _PR_MD_RMDIR(const char *name)
 {
-    if (RemoveDirectory(name)) {
+    if (
+#if !defined(WINCE)
+        RemoveDirectory(name)
+#else
+        _MD_RemoveDirectoryA(name)
+#endif
+        ) {
         return 0;
     } else {
 		_PR_MD_MAP_RMDIR_ERROR(GetLastError());
         return -1;
     }
 }
 
 PRStatus
 _PR_MD_LOCKFILE(PRInt32 f)
 {
+#if !defined(WINCE)
     PRStatus  rc = PR_SUCCESS;
 	DWORD     rv;
 
 	rv = LockFile( (HANDLE)f,
 		0l, 0l,
 		0x0l, 0xffffffffl ); 
 	if ( rv == 0 ) {
         DWORD rc = GetLastError();
         PR_LOG( _pr_io_lm, PR_LOG_ERROR,
             ("_PR_MD_LOCKFILE() failed. Error: %d", rc ));
         rc = PR_FAILURE;
     }
 
     return rc;
+#else
+    PR_SetError( PR_NOT_IMPLEMENTED_ERROR, 0 );
+    return PR_FAILURE;
+#endif
 } /* end _PR_MD_LOCKFILE() */
 
 PRStatus
 _PR_MD_TLOCKFILE(PRInt32 f)
 {
     PR_SetError( PR_NOT_IMPLEMENTED_ERROR, 0 );
     return PR_FAILURE;
 } /* end _PR_MD_TLOCKFILE() */
 
 
 PRStatus
 _PR_MD_UNLOCKFILE(PRInt32 f)
 {
+#if !defined(WINCE)
 	PRInt32   rv;
     
     rv = UnlockFile( (HANDLE) f,
     		0l, 0l,
             0x0l, 0xffffffffl ); 
             
     if ( rv )
     {
     	return PR_SUCCESS;
     }
     else
     {
 		_PR_MD_MAP_DEFAULT_ERROR(GetLastError());
 		return PR_FAILURE;
     }
+#else
+    PR_SetError( PR_NOT_IMPLEMENTED_ERROR, 0 );
+    return PR_FAILURE;
+#endif
 } /* end _PR_MD_UNLOCKFILE() */
 
 PRInt32
 _PR_MD_PIPEAVAILABLE(PRFileDesc *fd)
 {
     if (NULL == fd)
 		PR_SetError(PR_BAD_DESCRIPTOR_ERROR, 0);
 	else
--- a/pr/src/md/windows/w95thred.c
+++ b/pr/src/md/windows/w95thred.c
@@ -28,17 +28,19 @@
  * indicate your decision by deleting the provisions above and
  * replace them with the notice and other provisions required by
  * the GPL.  If you do not delete the provisions above, a recipient
  * may use your version of this file under either the MPL or the
  * GPL.
  */
 
 #include "primpl.h"
+#if !defined(WINCE)
 #include <process.h>  /* for _beginthreadex() */
+#endif
 
 extern void _PR_Win32InitTimeZone(void);  /* defined in ntmisc.c */
 
 /* --- globals ------------------------------------------------ */
 #ifdef _PR_USE_STATIC_TLS
 __declspec(thread) struct PRThread  *_pr_thread_last_run;
 __declspec(thread) struct PRThread  *_pr_currentThread;
 __declspec(thread) struct _PRCPU    *_pr_currentCPU;
@@ -83,24 +85,32 @@ PRStatus
         ** Warning:
         ** --------
         ** NSPR requires a real handle to every thread.
         ** GetCurrentThread() returns a pseudo-handle which
         ** is not suitable for some thread operations (e.g.,
         ** suspending).  Therefore, get a real handle from
         ** the pseudo handle via DuplicateHandle(...)
         */
+#if !defined(WINCE)
         DuplicateHandle(
                 GetCurrentProcess(),     /* Process of source handle */
                 GetCurrentThread(),      /* Pseudo Handle to dup */
                 GetCurrentProcess(),     /* Process of handle */
                 &(thread->md.handle),    /* resulting handle */
                 0L,                      /* access flags */
                 FALSE,                   /* Inheritable */
                 DUPLICATE_SAME_ACCESS);  /* Options */
+#else
+        /*
+        ** On WinCE the thread ID is the same as the real thread handle.
+        */
+        thread->md.handle = (HANDLE)GetCurrentThreadId();
+        thread->md.noCloseHandle = PR_TRUE;
+#endif
     }
 
     /* Create the blocking IO semaphore */
     thread->md.blocked_sema = CreateSemaphore(NULL, 0, 1, NULL);
     if (thread->md.blocked_sema == NULL)
         return PR_FAILURE;
 	else
 		return PR_SUCCESS;
@@ -110,27 +120,37 @@ PRStatus
 _PR_MD_CREATE_THREAD(PRThread *thread, 
                   void (*start)(void *), 
                   PRThreadPriority priority, 
                   PRThreadScope scope, 
                   PRThreadState state, 
                   PRUint32 stackSize)
 {
 
+#if !defined(WINCE)
     thread->md.handle = (HANDLE) _beginthreadex(
                     NULL,
                     thread->stack->stackSize,
 #if defined(__MINGW32__)
                     (void *)start,
 #else
                     (unsigned (__stdcall *)(void *))start,
 #endif
                     (void *)thread,
                     CREATE_SUSPENDED,
                     &(thread->id));
+#else
+    thread->md.handle = CreateThread(NULL,
+        (DWORD)thread->stack->stackSize,
+        (LPTHREAD_START_ROUTINE)start,
+        (LPVOID)thread,
+        (DWORD)CREATE_SUSPENDED,
+        (LPDWORD)&(thread->id));
+#endif /* !WINCE */
+
     if(!thread->md.handle) {
         return PR_FAILURE;
     }
 
     thread->md.id = thread->id;
     /*
      * On windows, a thread is created with a thread priority of
      * THREAD_PRIORITY_NORMAL.
@@ -193,52 +213,74 @@ void
 
     if (thread->md.blocked_sema) {
         rv = CloseHandle(thread->md.blocked_sema);
         PR_ASSERT(rv);
         thread->md.blocked_sema = 0;
     }
 
     if (thread->md.handle) {
+#if !defined(WINCE)
         rv = CloseHandle(thread->md.handle);
         PR_ASSERT(rv);
+#else
+        if(PR_FALSE == thread->md.noCloseHandle) {
+            rv = CloseHandle(thread->md.handle);
+            PR_ASSERT(rv);
+        }
+        else {
+            thread->md.noCloseHandle = PR_FALSE; /* reused? insurance.... */
+        }
+#endif
         thread->md.handle = 0;
     }
 }
 
 void
 _PR_MD_EXIT_THREAD(PRThread *thread)
 {
     _PR_MD_CLEAN_THREAD(thread);
     _PR_MD_SET_CURRENT_THREAD(NULL);
 }
 
 
 void
 _PR_MD_EXIT(PRIntn status)
 {
+#if !defined(WINCE)
     _exit(status);
+#else
+    TerminateProcess(GetCurrentProcess(), status);
+#endif
 }
 
 PRInt32 _PR_MD_SETTHREADAFFINITYMASK(PRThread *thread, PRUint32 mask )
 {
+#if !defined(WINCE)
     int rv;
 
     rv = SetThreadAffinityMask(thread->md.handle, mask);
 
     return rv?0:-1;
+#else
+    return -1;
+#endif
 }
 
 PRInt32 _PR_MD_GETTHREADAFFINITYMASK(PRThread *thread, PRUint32 *mask)
 {
+#if !defined(WINCE)
     PRInt32 rv, system_mask;
 
     rv = GetProcessAffinityMask(GetCurrentProcess(), mask, &system_mask);
     
     return rv?0:-1;
+#else
+    return -1;
+#endif
 }
 
 void 
 _PR_MD_SUSPEND_CPU(_PRCPU *cpu) 
 {
     _PR_MD_SUSPEND_THREAD(cpu->thread);
 }
 
--- a/pr/src/md/windows/win32_errors.c
+++ b/pr/src/md/windows/win32_errors.c
@@ -29,17 +29,19 @@
  * replace them with the notice and other provisions required by
  * the GPL.  If you do not delete the provisions above, a recipient
  * may use your version of this file under either the MPL or the
  * GPL.
  */
 
 #include "prerror.h"
 #include "prlog.h"
+#if !defined(WINCE)
 #include <errno.h>
+#endif
 #include <windows.h>
 
 /*
  * On Win32, we map three kinds of error codes:
  * - GetLastError(): for Win32 functions
  * - WSAGetLastError(): for Winsock functions
  * - errno: for standard C library functions
  * 
@@ -57,22 +59,24 @@
  * be detected at the time we create new sockets.
  */
 
 static void _MD_win32_map_default_errno(PRInt32 err)
 {
     PRErrorCode prError;
 
     switch (err) {
+#if !defined(WINCE)
         case EACCES:
             prError = PR_NO_ACCESS_RIGHTS_ERROR;
             break;
         case ENOENT:
             prError = PR_FILE_NOT_FOUND_ERROR;
             break;
+#endif
         default:
             prError = PR_UNKNOWN_ERROR;
             break;
     }
     PR_SetError(prError, err);
 }
 
 void _MD_win32_map_default_error(PRInt32 err)
--- a/pr/src/misc/prerror.c
+++ b/pr/src/misc/prerror.c
@@ -44,16 +44,22 @@ PR_IMPLEMENT(PRErrorCode) PR_GetError(vo
 }
 
 PR_IMPLEMENT(PRInt32) PR_GetOSError(void)
 {
     PRThread *thread = PR_GetCurrentThread();
     return thread->osErrorCode;
 }
 
+PR_IMPLEMENT(PRInt32 *) PR_GetOSErrorAddress(void)
+{
+    PRThread *thread = PR_GetCurrentThread();
+    return &thread->osErrorCode;
+}
+
 PR_IMPLEMENT(void) PR_SetError(PRErrorCode code, PRInt32 osErr)
 {
     PRThread *thread = PR_GetCurrentThread();
     thread->errorCode = code;
     thread->osErrorCode = osErr;
     thread->errorStringLength = 0;
 }
 
--- a/pr/src/misc/prerrortable.c
+++ b/pr/src/misc/prerrortable.c
@@ -52,18 +52,22 @@ the suitability of this software for any
 provided "as is" without express or implied warranty.
 
 */
 
 #include <string.h>
 #ifdef SUNOS4
 #include "md/sunos4.h"  /* for strerror */
 #endif
+#if !defined(WINCE)
 #include <assert.h>
 #include <errno.h>
+#else
+#include "primpl.h"
+#endif
 #include "prmem.h"
 #include "prerror.h"
 
 #define	ERRCODE_RANGE	8	/* # of bits to shift table number */
 #define	BITS_PER_CHAR	6	/* # bits to shift per character in name */
 
 #ifdef NEED_SYS_ERRLIST
 extern char const * const sys_errlist[];
@@ -140,17 +144,21 @@ PR_ErrorToString(PRErrorCode code, PRLan
 		if (msg) return msg;
 	    }
     
 	    return(et->table->msgs[code - et->table->base].en_text);
 	}
     }
 
     if (code >= 0 && code < 256) {
+#if !defined(WINCE)
 	return strerror(code);
+#else
+        return "errno range error";
+#endif
     }
 
     offset = (int) (code & ((1<<ERRCODE_RANGE)-1));
     table_num = code - offset;
     strcpy (buffer, "Unknown code ");
     if (table_num) {
 	strcat(buffer, error_table_name (table_num));
 	strcat(buffer, " ");
@@ -196,17 +204,21 @@ PR_ErrorLanguages(void)
 PR_IMPLEMENT(PRErrorCode)
 PR_ErrorInstallTable(const struct PRErrorTable *table)
 {
     struct PRErrorTableList * new_et;
 
     new_et = (struct PRErrorTableList *)
 					PR_Malloc(sizeof(struct PRErrorTableList));
     if (!new_et)
+#if !defined(WINCE)
 	return errno;	/* oops */
+#else
+        return ENOMEM;
+#endif
     new_et->table = table;
     if (callback_newtable) {
 	new_et->table_private = callback_newtable(table, callback_private);
     } else {
 	new_et->table_private = 0;
     }
     new_et->next = Table_List;
     Table_List = new_et;
@@ -216,18 +228,23 @@ PR_ErrorInstallTable(const struct PRErro
 PR_IMPLEMENT(void)
 PR_ErrorInstallCallback(const char * const * languages,
 		       PRErrorCallbackLookupFn *lookup, 
 		       PRErrorCallbackNewTableFn *newtable,
 		       struct PRErrorCallbackPrivate *cb_private)
 {
     struct PRErrorTableList *et;
 
+#if !defined(WINCE)
     assert(strcmp(languages[0], "i-default") == 0);
     assert(strcmp(languages[1], "en") == 0);
+#else
+    PR_ASSERT(strcmp(languages[0], "i-default") == 0);
+    PR_ASSERT(strcmp(languages[1], "en") == 0);
+#endif
     
     callback_languages = languages;
     callback_lookup = lookup;
     callback_newtable = newtable;
     callback_private = cb_private;
 
     if (callback_newtable) {
 	for (et = Table_List; et; et = et->next) {
--- a/pr/src/misc/prnetdb.c
+++ b/pr/src/misc/prnetdb.c
@@ -837,24 +837,30 @@ PR_IMPLEMENT(PRStatus) PR_GetHostByAddr(
  * we're not using it. For sure these signatures are different than
  * any usable implementation.
  */
 
 static struct protoent *getprotobyname_r(const char* name)
 {
 #ifdef XP_OS2_VACPP
 	return getprotobyname((char *)name);
+#elif defined(WINCE)
+    return Wingetprotobyname(name);
 #else
 	return getprotobyname(name);
 #endif
 } /* getprotobyname_r */
 
 static struct protoent *getprotobynumber_r(PRInt32 number)
 {
+#if !defined(WINCE)
 	return getprotobynumber(number);
+#else
+    return Wingetprotobynumber(number);
+#endif
 } /* getprotobynumber_r */
 
 #endif /* !defined(_PR_HAVE_GETPROTO_R) */
 
 PR_IMPLEMENT(PRStatus) PR_GetProtoByName(
     const char* name, char* buffer, PRInt32 buflen, PRProtoEnt* result)
 {
 	PRStatus rv = PR_SUCCESS;
--- a/pr/src/misc/prtime.c
+++ b/pr/src/misc/prtime.c
@@ -40,26 +40,29 @@
  */
 
 #include "prinit.h"
 #include "prtime.h"
 #include "prlock.h"
 #include "prprf.h"
 #include "prlog.h"
 
+#if defined(WINCE)
+#include "primpl.h"
+#endif
+
 #include <string.h>
 #include <ctype.h>
 
 #ifdef XP_MAC
 #include <time.h>
 #endif
 
 
 
-
 /*
  * Static variables used by functions in this file
  */
 
 /*
  * The following array contains the day of year for the last day of
  * each month, where index 1 is January, and day 0 is January 1.
  */
@@ -533,17 +536,19 @@ PR_NormalizeTime(PRExplodedTime *time, P
  *     The following uses localtime() from the standard C library.
  *     (time.h)  This is our fallback implementation.  Unix and PC
  *     use this version.  Mac has its own machine-dependent
  *     implementation of this function.
  *
  *-------------------------------------------------------------------------
  */
 
+#if !defined(WINCE)
 #include <time.h>
+#endif
 
 #if defined(HAVE_INT_LOCALTIME_R)
 
 /*
  * In this case we could define the macro as
  *     #define MT_safe_localtime(timer, result) \
  *             (localtime_r(timer, result) == 0 ? result : NULL)
  * I chose to compare the return value of localtime_r with -1 so 
@@ -560,16 +565,18 @@ PR_NormalizeTime(PRExplodedTime *time, P
 
 #define MT_safe_localtime localtime_r
 
 #else
 
 #if defined(XP_MAC)
 extern struct tm *Maclocaltime(const time_t * t);
 #endif
+#if defined(WINCE)
+#endif
 
 static PRLock *monitor = NULL;
 
 static struct tm *MT_safe_localtime(const time_t *clock, struct tm *result)
 {
     struct tm *tmPtr;
     int needLock = PR_Initialized();  /* We need to use a lock to protect
                                        * against NSPR threads only when the
--- a/pr/src/threads/combined/prucv.c
+++ b/pr/src/threads/combined/prucv.c
@@ -35,17 +35,17 @@
 
 #include "primpl.h"
 #include "prinrval.h"
 #include "prtypes.h"
 
 #if defined(WIN95)
 /*
 ** Some local variables report warnings on Win95 because the code paths 
-** using them are conditioned on HAVE_CUSTOME_USER_THREADS.
+** using them are conditioned on HAVE_CUSTOM_USER_THREADS.
 ** The pragma suppresses the warning.
 ** 
 */
 #pragma warning(disable : 4101)
 #endif
 
 
 /*
--- a/pr/src/threads/combined/prulock.c
+++ b/pr/src/threads/combined/prulock.c
@@ -32,17 +32,17 @@
  * GPL.
  */
 
 #include "primpl.h"
 
 #if defined(WIN95)
 /*
 ** Some local variables report warnings on Win95 because the code paths 
-** using them are conditioned on HAVE_CUSTOME_USER_THREADS.
+** using them are conditioned on HAVE_CUSTOM_USER_THREADS.
 ** The pragma suppresses the warning.
 ** 
 */
 #pragma warning(disable : 4101)
 #endif
 
 
 void _PR_InitLocks(void)
--- a/pr/src/threads/combined/pruthr.c
+++ b/pr/src/threads/combined/pruthr.c
@@ -28,23 +28,25 @@
  * indicate your decision by deleting the provisions above and
  * replace them with the notice and other provisions required by
  * the GPL.  If you do not delete the provisions above, a recipient
  * may use your version of this file under either the MPL or the
  * GPL.
  */
 
 #include "primpl.h"
+#if !defined(WINCE)
 #include <signal.h>
+#endif
 #include <string.h>
 
 #if defined(WIN95)                                                                         
 /*
 ** Some local variables report warnings on Win95 because the code paths
-** using them are conditioned on HAVE_CUSTOME_USER_THREADS.
+** using them are conditioned on HAVE_CUSTOM_USER_THREADS.
 ** The pragma suppresses the warning.
 **
 */
 #pragma warning(disable : 4101)
 #endif          
 
 #if defined(XP_MAC)
 #include <LowMem.h>
--- a/pr/src/threads/prcthr.c
+++ b/pr/src/threads/prcthr.c
@@ -32,17 +32,17 @@
  * GPL.
  */
 
 #include "primpl.h"
 
 #if defined(WIN95)
 /*
 ** Some local variables report warnings on Win95 because the code paths 
-** using them are conditioned on HAVE_CUSTOME_USER_THREADS.
+** using them are conditioned on HAVE_CUSTOM_USER_THREADS.
 ** The pragma suppresses the warning.
 ** 
 */
 #pragma warning(disable : 4101)
 #endif
 
 
 extern PRLock *_pr_sleeplock;  /* allocated and initialized in prinit */
--- a/pr/src/threads/prdump.c
+++ b/pr/src/threads/prdump.c
@@ -32,17 +32,17 @@
  * GPL.
  */
 
 #include "primpl.h"
 
 #if defined(WIN95)
 /*
 ** Some local variables report warnings on Win95 because the code paths 
-** using them are conditioned on HAVE_CUSTOME_USER_THREADS.
+** using them are conditioned on HAVE_CUSTOM_USER_THREADS.
 ** The pragma suppresses the warning.
 ** 
 */
 #pragma warning(disable : 4101)
 #endif
 
 /* XXX use unbuffered nspr stdio */
 
--- a/pr/src/threads/prtpd.c
+++ b/pr/src/threads/prtpd.c
@@ -65,17 +65,17 @@
 
 #include "primpl.h"
 
 #include <string.h>
 
 #if defined(WIN95)
 /*
 ** Some local variables report warnings on Win95 because the code paths 
-** using them are conditioned on HAVE_CUSTOME_USER_THREADS.
+** using them are conditioned on HAVE_CUSTOM_USER_THREADS.
 ** The pragma suppresses the warning.
 ** 
 */
 #pragma warning(disable : 4101)
 #endif
 
 #define _PR_TPD_LIMIT 128               /* arbitary limit on the TPD slots */
 static PRInt32 _pr_tpd_length = 0;      /* current length of destructor vector */