work in progress for NSPR WinCE port WINCE_NSPRPUB_RELEASE_4_2_BETA1
authorblythe%netscape.com
Mon, 04 Feb 2002 21:48:10 +0000
branchWINCE_NSPRPUB_RELEASE_4_2_BETA1
changeset 2214 fe4762e225e70ff56814bbf95448bcc340196974
parent 2198 3af4aee6e8fe4eca1f82429fa9c7dd461b772d4c
child 2215 3be04aa844798c0763a0d54612cf09fb5c248785
push idunknown
push userunknown
push dateunknown
work in progress for NSPR WinCE port
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/_wince.cfg
pr/include/md/_wince.h
pr/include/md/_wintime.h
pr/include/md/prosdep.h
pr/include/obsolete/probslet.h
pr/src/io/prfile.c
pr/src/io/prio.c
pr/src/io/prlog.c
pr/src/io/prprf.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/objs.mk
pr/src/md/windows/w32rng.c
pr/src/md/windows/w32time.c
pr/src/md/windows/w95io.c
pr/src/md/windows/w95thred.c
pr/src/md/windows/win32_errors.c
pr/src/misc/prerrortable.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
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
@@ -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"
--- a/configure
+++ b/configure
@@ -2721,16 +2721,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
@@ -2780,16 +2798,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
@@ -3743,31 +3762,43 @@ EOF
             cat >> confdefs.h <<\EOF
 #define _DEBUG 1
 EOF
 
         else
             DEFINES="$DEFINES -U_DEBUG"
         fi
 
+        if test "$OS_TARGET" = "WINCE"; then
+            DLL_LIBS="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"
@@ -3796,17 +3827,52 @@ EOF
 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
+        cat >> confdefs.h <<\EOF
+#define UNICODE 1
+EOF
+        cat >> confdefs.h <<\EOF
+#define _UNICODE 1
+EOF
+        cat >> confdefs.h <<\EOF
+#define _WIN32_WCE 300
+EOF
+        cat >> confdefs.h <<\EOF
+#define UNDER_CE 300
+EOF
+
+        if test "$CPU_ARCH" = "x86"; then
+            cat >> confdefs.h <<\EOF
+#define x86 1
+EOF
+            cat >> confdefs.h <<\EOF
+#define _WIN32_WCE_CEPC 1
+EOF
+        elif test "$CPU_ARCH" = "ARM"; then
+            cat >> confdefs.h <<\EOF
+#define ARM 1
+EOF
+        else
+            cat >> confdefs.h <<\EOF
+#define UNHANDLED_WINCE_TARGETCPU_HERE 1
+EOF
+        fi
     else
         cat >> confdefs.h <<\EOF
 #define WIN95 1
 EOF
 
         cat >> confdefs.h <<\EOF
 #define _PR_GLOBAL_THREADS_ONLY 1
 EOF
@@ -3827,16 +3893,19 @@ EOF
 
     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
 
@@ -5744,16 +5813,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
@@ -559,16 +559,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
@@ -618,16 +636,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
@@ -1191,31 +1210,43 @@ 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="coredll.lib winsock.lib"
+        fi
+
         if test -n "$MOZ_OPTIMIZE"; then
-            CFLAGS="$CFLAGS -MD"
+            if test -n "$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 -n "$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"
@@ -1239,16 +1270,19 @@ 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
@@ -1263,16 +1297,19 @@ case "$target" in
 
     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
 
@@ -2286,16 +2323,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 = WINCE_D.OBJ
+else
+MOZ_OBJDIR = WINCE_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/_wince.cfg
@@ -0,0 +1,211 @@
+/* -*- 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>
+typedef int ptrdiff_t; /* pointer difference */
+
+
+#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,541 @@
+/* -*- 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 "_wintime.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 */
+    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;
+    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)
+#define _MD_ATOMIC_ADD(ptr,val)    (InterlockedExchangeAdd((PLONG)ptr, (LONG)val) + val)
+#define _MD_ATOMIC_DECREMENT(x)       InterlockedDecrement((PLONG)x)
+#endif /* x86 */
+#define _MD_ATOMIC_SET(x,y)           InterlockedExchange((PLONG)x, (LONG)y)
+
+#define _MD_INIT_IO                   _PR_MD_INIT_IO
+
+
+/* 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 */
+
+/*
+ * Missing structs that are assumed by nspr.
+ */
+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 /* errno, out of memory */
+
+/*
+ * Some quick macros.
+ */
+#define _PR_MD_CE_NOT_IMPLEMENTED _PR_MD_MAP_DEFAULT_ERROR(ERROR_CALL_NOT_IMPLEMENTED)
+
+#endif /* nspr_wince_defs_h___ */
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/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>
--- a/pr/src/io/prio.c
+++ b/pr/src/io/prio.c
@@ -47,28 +47,38 @@ 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.
+     */
+    _pr_stdin = PR_AllocFileDesc(_fileno(stdin), methods);
+    _pr_stdout = PR_AllocFileDesc(_fileno(stdout), methods);
+    _pr_stderr = PR_AllocFileDesc(_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/prlog.c
+++ b/pr/src/io/prlog.c
@@ -104,16 +104,40 @@ static PRLock *_pr_logLock;
 /*
 ** Coerce Win32 log output to use OutputDebugString() when
 ** NSPR_LOG_FILE is set to "WinDebug".
 */
 #if defined(XP_PC)
 #define WIN32_DEBUG_FILE (FILE*)-2
 #endif
 
+/*
+** CE needs a different OutputDebugString (UNICODE only).
+*/
+#if defined(WINCE)
+#define CEOutputDebugString(str) \
+    PR_BEGIN_MACRO \
+        int neededWChars = 0; \
+        \
+        neededWChars = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (str), -1, NULL, 0); \
+        if(0 < neededWChars) \
+        { \
+            LPTSTR wstr = NULL; \
+            \
+            wstr = (LPWSTR)PR_Malloc(sizeof(WCHAR) * neededWChars); \
+            if(NULL != wstr) \
+            { \
+                MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (str), -1, wstr, neededWChars); \
+                OutputDebugString(wstr); \
+                PR_Free(wstr); \
+            } \
+        } \
+    PR_END_MACRO
+#endif
+
 /* Macros used to reduce #ifdef pollution */
 
 #if defined(_PR_USE_STDIO_FOR_LOGGING)
 #define _PUT_LOG(fd, buf, nb) {fputs(buf, fd); fflush(fd);}
 #elif defined(_PR_PTHREADS)
 #define _PUT_LOG(fd, buf, nb) PR_Write(fd, buf, nb)
 #elif defined(XP_MAC)
 #define _PUT_LOG(fd, buf, nb) _PR_MD_WRITE_SYNC(fd, buf, nb)
@@ -237,17 +261,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
+                    CEOutputDebugString(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 +378,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 +465,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
+            CEOutputDebugString( 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);
--- 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/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
     {
--- a/pr/src/md/windows/Makefile.in
+++ b/pr/src/md/windows/Makefile.in
@@ -53,16 +53,36 @@ 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 \
+    $(NULL)
+else
 ifeq ($(OS_TARGET), WIN95)
 CSRCS =          \
     ntmisc.c \
     ntsec.c   \
     ntsem.c   \
     ntinrval.c \
     ntgc.c \
 	w95thred.c \
@@ -89,16 +109,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)
--- 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,66 @@ 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 = CreateProcess(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 +744,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/objs.mk
+++ b/pr/src/md/windows/objs.mk
@@ -42,16 +42,34 @@ 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
+else
 ifeq ($(OS_TARGET),WIN95)
 CSRCS =	ntmisc.c \
 	ntsec.c \
 	ntsem.c \
 	ntinrval.c \
 	ntgc.c \
 	w95thred.c \
 	w95io.c \
@@ -74,16 +92,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/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;
 }
 
new file mode 100644
--- /dev/null
+++ b/pr/src/md/windows/w32time.c
@@ -0,0 +1,114 @@
+/* -*- 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"
+
+/*
+ * Winlocaltime
+ *
+ * As LIBC localtime
+ */
+struct tm* Winlocaltime(const time_t* inTimeT)
+{
+    struct tm* retval = NULL;
+
+    if(NULL != inTimeT)
+    {
+        static struct tm tmStorage;
+        static const int daysOfYear[12] =
+        {
+            0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334
+        };
+        SYSTEMTIME winLocalTime;
+        TIME_ZONE_INFORMATION  winTZInfo;
+        DWORD winDST;
+        
+        _MD_time_t_2_LOCALSYSTEMTIME(winLocalTime, *inTimeT);
+        
+        tmStorage.tm_sec = (int)winLocalTime.wSecond;
+        tmStorage.tm_min = (int)winLocalTime.wMinute;
+        tmStorage.tm_hour = (int)winLocalTime.wHour;
+        tmStorage.tm_mday = (int)winLocalTime.wDay;
+        tmStorage.tm_mon = (int)(winLocalTime.wMonth - 1);
+        tmStorage.tm_year = (int)(winLocalTime.wYear - 1900);
+        tmStorage.tm_wday = (int)winLocalTime.wDayOfWeek;
+        
+        tmStorage.tm_yday = (int)winLocalTime.wDay + daysOfYear[tmStorage.tm_mon];
+        if(0 == (winLocalTime.wYear & 3))
+        {
+            if(2 < winLocalTime.wMonth)
+            {
+                if(0 == winLocalTime.wYear % 100)
+                {
+                    if(0 == winLocalTime.wYear % 400)
+                    {
+                        tmStorage.tm_yday++;
+                    }
+                }
+                else
+                {
+                    tmStorage.tm_yday++;
+                }
+            }
+        }
+
+        winDST = GetTimeZoneInformation(&winTZInfo);
+
+        switch(winDST)
+        {
+        case TIME_ZONE_ID_STANDARD:
+            tmStorage.tm_isdst = 0;
+            break;
+        case TIME_ZONE_ID_DAYLIGHT:
+            tmStorage.tm_isdst = 1;
+            break;
+        default:
+            tmStorage.tm_isdst = -1;
+            break;
+        }
+
+        retval = &tmStorage;
+    }
+
+    return retval;
+}
\ 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[] = {
@@ -619,16 +621,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 +650,89 @@ 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 = CreateFile(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 --
  *
@@ -899,56 +975,65 @@ 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_CE_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)) {
         return 0;
@@ -956,33 +1041,62 @@ PRInt32
 		_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;
+
+    attribs = GetFileAttributes(name);
+    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)) {
--- 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;
--- 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/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[];
@@ -195,18 +199,25 @@ 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 !defined(WINCE)
     if (!new_et)
 	return errno;	/* oops */
+#else
+    if(NULL == new_et)
+    {
+        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;
--- 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,19 @@ 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)
+extern struct tm* Winlocaltime(const time_t* inTimeT);
+#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
@@ -595,16 +603,18 @@ static struct tm *MT_safe_localtime(cons
      *
      * With negative values of clock, emx returns the struct tm for
      * clock plus ULONG_MAX. So we also have to check for the invalid
      * structs returned for timezones west of Greenwich when clock == 0.
      */
     
 #if defined(XP_MAC)
     tmPtr = Maclocaltime(clock);
+#elif defined(WINCE)
+    tmPtr = Winlocaltime(clock);
 #else
     tmPtr = localtime(clock);
 #endif
 
 #if defined(WIN16) || defined(XP_OS2_EMX)
     if ( (PRInt32) *clock < 0 ||
          ( (PRInt32) *clock == 0 && tmPtr->tm_year != 70))
         result = NULL;
--- 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 */