summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorblythe%netscape.com <devnull@localhost>2002-02-04 21:48:10 +0000
committerblythe%netscape.com <devnull@localhost>2002-02-04 21:48:10 +0000
commit7e18b17c1a90adea6691f935c2131e710a9fa184 (patch)
tree1867eb1cd152a4a81fb8b69ff7a6205726ebd2fd
parent246f2b737fc0b32e135642b4c86f30df1616c276 (diff)
downloadnspr-hg-7e18b17c1a90adea6691f935c2131e710a9fa184.tar.gz
work in progress for NSPR WinCE port
-rw-r--r--config/Makefile.in10
-rw-r--r--config/WIN32.mk22
-rw-r--r--config/WINCE.mk39
-rw-r--r--config/arch.mk19
-rw-r--r--config/autoconf.mk.in1
-rw-r--r--config/rules.mk4
-rwxr-xr-xconfigure78
-rw-r--r--configure.in46
-rw-r--r--gmakefile.win10
-rw-r--r--pr/include/md/_pcos.h2
-rw-r--r--pr/include/md/_win32_errors.h2
-rw-r--r--pr/include/md/_wince.cfg211
-rw-r--r--pr/include/md/_wince.h541
-rw-r--r--pr/include/md/_wintime.h180
-rw-r--r--pr/include/md/prosdep.h3
-rw-r--r--pr/include/obsolete/probslet.h2
-rw-r--r--pr/src/io/prfile.c2
-rw-r--r--pr/src/io/prio.c10
-rw-r--r--pr/src/io/prlog.c34
-rw-r--r--pr/src/io/prprf.c4
-rw-r--r--pr/src/linking/prlink.c2
-rw-r--r--pr/src/md/windows/Makefile.in21
-rw-r--r--pr/src/md/windows/ntgc.c2
-rw-r--r--pr/src/md/windows/ntmisc.c90
-rw-r--r--pr/src/md/windows/objs.mk19
-rw-r--r--pr/src/md/windows/w32rng.c6
-rw-r--r--pr/src/md/windows/w32time.c114
-rw-r--r--pr/src/md/windows/w95io.c116
-rw-r--r--pr/src/md/windows/w95thred.c2
-rw-r--r--pr/src/md/windows/win32_errors.c4
-rw-r--r--pr/src/misc/prerrortable.c11
-rw-r--r--pr/src/misc/prtime.c12
-rw-r--r--pr/src/threads/combined/prucv.c2
-rw-r--r--pr/src/threads/combined/prulock.c2
-rw-r--r--pr/src/threads/combined/pruthr.c4
-rw-r--r--pr/src/threads/prcthr.c2
-rw-r--r--pr/src/threads/prdump.c2
-rw-r--r--pr/src/threads/prtpd.c2
38 files changed, 1603 insertions, 30 deletions
diff --git a/config/Makefile.in b/config/Makefile.in
index 0360255b..a943b28e 100644
--- a/config/Makefile.in
+++ b/config/Makefile.in
@@ -50,7 +50,9 @@ 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)
@@ -59,7 +61,7 @@ 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 =
@@ -108,9 +110,11 @@ 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)
@@ -118,7 +122,7 @@ 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
diff --git a/config/WIN32.mk b/config/WIN32.mk
index f002c074..4045c0f6 100644
--- a/config/WIN32.mk
+++ b/config/WIN32.mk
@@ -69,7 +69,11 @@ 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:"$@"
@@ -87,11 +91,15 @@ 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
@@ -140,7 +148,15 @@ 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)
@@ -152,10 +168,14 @@ 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
diff --git a/config/WINCE.mk b/config/WINCE.mk
new file mode 100644
index 00000000..322f31d3
--- /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
diff --git a/config/arch.mk b/config/arch.mk
index 7c0c07df..218b84fb 100644
--- a/config/arch.mk
+++ b/config/arch.mk
@@ -200,6 +200,24 @@ ifeq ($(OS_ARCH),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.
#
@@ -269,6 +287,7 @@ endif
endif
endif
endif
+endif
ifndef OS_TARGET
OS_TARGET := $(OS_ARCH)
diff --git a/config/autoconf.mk.in b/config/autoconf.mk.in
index 3a049f60..30ca541b 100644
--- a/config/autoconf.mk.in
+++ b/config/autoconf.mk.in
@@ -77,6 +77,7 @@ OS_DLLFLAGS = @OS_DLLFLAGS@
DLLFLAGS = @DLLFLAGS@
EXEFLAGS = @EXEFLAGS@
OPTIMIZER = @OPTIMIZER@
+DLL_LIBS = @DLL_LIBS@
MKSHLIB = @MKSHLIB@
DSO_CFLAGS = @DSO_CFLAGS@
diff --git a/config/rules.mk b/config/rules.mk
index ffd63dfc..81d2b8e3 100644
--- a/config/rules.mk
+++ b/config/rules.mk
@@ -314,8 +314,8 @@ ifeq ($(OS_ARCH)$(OS_RELEASE), AIX4.1)
$(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.
diff --git a/configure b/configure
index 24732871..58dc020c 100755
--- a/configure
+++ b/configure
@@ -2726,6 +2726,24 @@ elif test "$OS_ARCH" = "OS_2"; then
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.
#
@@ -2785,6 +2803,7 @@ elif test "$OS_ARCH" = "CYGWIN32_NT"; then
CPU_ARCH=x86
fi
fi
+fi
if test -n "$MOZILLA_CLIENT" && test "$OS_ARCH" = "WINNT"; then
OS_TARGET=WIN95
@@ -3748,8 +3767,16 @@ EOF
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:"$@"'
@@ -3759,10 +3786,14 @@ EOF
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:"$@"'
@@ -3801,7 +3832,42 @@ EOF
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
@@ -3832,6 +3898,9 @@ EOF
WIN95)
MDCPUCFG_H=_win95.cfg
;;
+ WINCE)
+ MDCPUCFG_H=_wince.cfg
+ ;;
WIN16)
MDCPUCFG_H=_win16.cfg
;;
@@ -5749,6 +5818,7 @@ 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
diff --git a/configure.in b/configure.in
index f231b279..d956941d 100644
--- a/configure.in
+++ b/configure.in
@@ -564,6 +564,24 @@ elif test "$OS_ARCH" = "OS_2"; then
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.
#
@@ -623,6 +641,7 @@ elif test "$OS_ARCH" = "CYGWIN32_NT"; then
CPU_ARCH=x86
fi
fi
+fi
if test -n "$MOZILLA_CLIENT" && test "$OS_ARCH" = "WINNT"; then
OS_TARGET=WIN95
@@ -1196,8 +1215,16 @@ case "$target" in
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:"$@"'
@@ -1207,10 +1234,14 @@ case "$target" in
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:"$@"'
@@ -1244,6 +1275,9 @@ case "$target" in
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)
@@ -1268,6 +1302,9 @@ case "$target" in
WIN95)
MDCPUCFG_H=_win95.cfg
;;
+ WINCE)
+ MDCPUCFG_H=_wince.cfg
+ ;;
WIN16)
MDCPUCFG_H=_win16.cfg
;;
@@ -2291,6 +2328,7 @@ AC_SUBST(RC)
AC_SUBST(DLLFLAGS)
AC_SUBST(EXEFLAGS)
AC_SUBST(OS_DLLFLAGS)
+AC_SUBST(DLL_LIBS)
dnl ========================================================
dnl Generate output files.
diff --git a/gmakefile.win b/gmakefile.win
index 05f855fa..ecea6c9d 100644
--- a/gmakefile.win
+++ b/gmakefile.win
@@ -44,11 +44,19 @@ 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 \
@@ -83,7 +91,7 @@ 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
diff --git a/pr/include/md/_pcos.h b/pr/include/md/_pcos.h
index 27abf8c5..82174d66 100644
--- a/pr/include/md/_pcos.h
+++ b/pr/include/md/_pcos.h
@@ -69,9 +69,11 @@ PR_END_EXTERN_C
#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);
diff --git a/pr/include/md/_win32_errors.h b/pr/include/md/_win32_errors.h
index a924ec80..7c98c274 100644
--- a/pr/include/md/_win32_errors.h
+++ b/pr/include/md/_win32_errors.h
@@ -37,7 +37,9 @@
#include <windows.h>
#include <winsock.h>
+#if !defined(WINCE)
#include <errno.h>
+#endif
extern void _MD_win32_map_default_error(PRInt32 err);
diff --git a/pr/include/md/_wince.cfg b/pr/include/md/_wince.cfg
new file mode 100644
index 00000000..ca7d0a54
--- /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___ */
diff --git a/pr/include/md/_wince.h b/pr/include/md/_wince.h
new file mode 100644
index 00000000..46a093cd
--- /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___ */
diff --git a/pr/include/md/_wintime.h b/pr/include/md/_wintime.h
new file mode 100644
index 00000000..806400a9
--- /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___ */
diff --git a/pr/include/md/prosdep.h b/pr/include/md/prosdep.h
index 7016cbb7..bf8518c9 100644
--- a/pr/include/md/prosdep.h
+++ b/pr/include/md/prosdep.h
@@ -51,6 +51,9 @@ PR_BEGIN_EXTERN_C
#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)
diff --git a/pr/include/obsolete/probslet.h b/pr/include/obsolete/probslet.h
index aafa0bb7..5a043c2b 100644
--- a/pr/include/obsolete/probslet.h
+++ b/pr/include/obsolete/probslet.h
@@ -158,7 +158,7 @@ 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
diff --git a/pr/src/io/prfile.c b/pr/src/io/prfile.c
index c000aea4..0307b97d 100644
--- a/pr/src/io/prfile.c
+++ b/pr/src/io/prfile.c
@@ -35,7 +35,9 @@
#include "primpl.h"
#include <string.h>
+#if !defined(WINCE)
#include <fcntl.h>
+#endif
#ifdef XP_UNIX
#if defined(AIX) || defined(QNX)
diff --git a/pr/src/io/prio.c b/pr/src/io/prio.c
index 250d9b6f..71a3e652 100644
--- a/pr/src/io/prio.c
+++ b/pr/src/io/prio.c
@@ -52,6 +52,7 @@ void _PR_InitIO(void)
_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),
@@ -64,6 +65,15 @@ void _PR_InitIO(void)
_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);
diff --git a/pr/src/io/prlog.c b/pr/src/io/prlog.c
index 334fddcc..d79952a6 100644
--- a/pr/src/io/prlog.c
+++ b/pr/src/io/prlog.c
@@ -109,6 +109,30 @@ static PRLock *_pr_logLock;
#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)
@@ -242,7 +266,11 @@ void _PR_InitLog(void)
#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
@@ -355,8 +383,10 @@ PR_IMPLEMENT(PRBool) PR_SetLogFile(const char *file)
#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);
}
@@ -440,7 +470,11 @@ PR_IMPLEMENT(void) PR_LogPrint(const char *fmt, ...)
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
diff --git a/pr/src/io/prprf.c b/pr/src/io/prprf.c
index 2d6a78d8..66e52389 100644
--- a/pr/src/io/prprf.c
+++ b/pr/src/io/prprf.c
@@ -414,11 +414,11 @@ static struct NumArgState* BuildArgArray( const char *fmt, va_list ap, int* rv,
/*
** 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;
}
diff --git a/pr/src/linking/prlink.c b/pr/src/linking/prlink.c
index 24a15f8a..050abca7 100644
--- a/pr/src/linking/prlink.c
+++ b/pr/src/linking/prlink.c
@@ -356,7 +356,7 @@ PR_GetLibraryPath(void)
/* initialize pr_currentLibPath */
#ifdef XP_PC
- ev = getenv("LD_LIBRARY_PATH");
+ ev = _PR_MD_GET_ENV("LD_LIBRARY_PATH");
if (!ev) {
ev = ".;\\lib";
}
diff --git a/pr/src/md/windows/Makefile.in b/pr/src/md/windows/Makefile.in
index 283fa4a4..fad5ebb1 100644
--- a/pr/src/md/windows/Makefile.in
+++ b/pr/src/md/windows/Makefile.in
@@ -58,6 +58,26 @@ CSRCS = \
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 \
@@ -94,6 +114,7 @@ CSRCS = \
$(NULL)
endif
endif
+endif
TARGETS = $(OBJS)
diff --git a/pr/src/md/windows/ntgc.c b/pr/src/md/windows/ntgc.c
index 03b77d80..ff6b97b6 100644
--- a/pr/src/md/windows/ntgc.c
+++ b/pr/src/md/windows/ntgc.c
@@ -69,7 +69,7 @@ PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
*
* 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().
diff --git a/pr/src/md/windows/ntmisc.c b/pr/src/md/windows/ntmisc.c
index c4bb8511..5efe3038 100644
--- a/pr/src/md/windows/ntmisc.c
+++ b/pr/src/md/windows/ntmisc.c
@@ -41,7 +41,11 @@
char *_PR_MD_GET_ENV(const char *name)
{
+#if !defined(WINCE)
return getenv(name);
+#else
+ return NULL;
+#endif
}
/*
@@ -51,7 +55,11 @@ char *_PR_MD_GET_ENV(const char *name)
*/
PRIntn _PR_MD_PUT_ENV(const char *name)
{
+#if !defined(WINCE)
return(putenv(name));
+#else
+ return -1;
+#endif
}
@@ -65,7 +73,9 @@ PRIntn _PR_MD_PUT_ENV(const char *name)
**************************************************************************
*/
+#if !defined(WINCE)
#include <sys/timeb.h>
+#endif
/*
*-----------------------------------------------------------------------
@@ -84,7 +94,9 @@ PRIntn _PR_MD_PUT_ENV(const char *name)
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);
@@ -95,7 +107,13 @@ PR_Now(void)
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;
}
/*
@@ -116,11 +134,14 @@ PR_Now(void)
* 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;
@@ -161,6 +182,7 @@ _PR_Win32InitTimeZone(void)
_timezone = tzinfo.Bias * 60;
_daylight = tzinfo.DaylightBias ? 1 : 0;
return;
+#endif
}
/*
@@ -291,6 +313,7 @@ static int assembleCmdLine(char *const *argv, char **cmdLine)
*/
static int assembleEnvBlock(char **envp, char **envBlock)
{
+#if !defined(WINCE)
char *p;
char *q;
char **env;
@@ -352,6 +375,13 @@ static int assembleEnvBlock(char **envp, char **envBlock)
}
*p = '\0';
return 0;
+#else
+ /*
+ * No env strings on wince.
+ */
+ *envBlock = NULL;
+ return 0;
+#endif
}
/*
@@ -369,6 +399,7 @@ PRProcess * _PR_CreateWindowsProcess(
char *const *envp,
const PRProcessAttr *attr)
{
+#if !defined(WINCE)
STARTUPINFO startupInfo;
PROCESS_INFORMATION procInfo;
BOOL retVal;
@@ -509,6 +540,56 @@ errorExit:
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)
@@ -668,8 +749,13 @@ PRStatus _MD_CreateFileMap(PRFileMap *fmap, PRInt64 size)
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(
diff --git a/pr/src/md/windows/objs.mk b/pr/src/md/windows/objs.mk
index 64922c9d..8a89b24f 100644
--- a/pr/src/md/windows/objs.mk
+++ b/pr/src/md/windows/objs.mk
@@ -47,6 +47,24 @@ CSRCS = ntmisc.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 \
@@ -79,6 +97,7 @@ CSRCS = w16null.c \
ntinrval.c
endif # win16
endif # win95
+endif # wince
endif # winnt
CSRCS += $(PR_MD_CSRCS)
diff --git a/pr/src/md/windows/w32rng.c b/pr/src/md/windows/w32rng.c
index cfc57d4b..03332852 100644
--- a/pr/src/md/windows/w32rng.c
+++ b/pr/src/md/windows/w32rng.c
@@ -33,10 +33,12 @@
*/
#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>
@@ -94,7 +96,11 @@ extern PRSize _PR_MD_GetRandomNoise( void *buf, PRSize size )
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;
diff --git a/pr/src/md/windows/w32time.c b/pr/src/md/windows/w32time.c
new file mode 100644
index 00000000..c359b7d8
--- /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
diff --git a/pr/src/md/windows/w95io.c b/pr/src/md/windows/w95io.c
index 89669e6e..b08786a5 100644
--- a/pr/src/md/windows/w95io.c
+++ b/pr/src/md/windows/w95io.c
@@ -39,8 +39,10 @@
*/
#include "primpl.h"
+#if !defined(WINCE)
#include <direct.h>
#include <mbstring.h>
+#endif
struct _MDLock _pr_ioq_lock;
@@ -624,6 +626,7 @@ _PR_MD_STAT(const char *fn, struct stat *info)
{
PRInt32 rv;
+#if !defined(WINCE)
rv = _stat(fn, (struct _stat *)info);
if (-1 == rv) {
/*
@@ -652,6 +655,79 @@ _PR_MD_STAT(const char *fn, 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;
}
@@ -904,6 +980,7 @@ _PR_MD_GETOPENFILEINFO(const PRFileDesc *fd, PRFileInfo *info)
PRStatus
_PR_MD_SET_FD_INHERITABLE(PRFileDesc *fd, PRBool inheritable)
{
+#if !defined(WINCE)
BOOL rv;
/*
@@ -919,6 +996,10 @@ _PR_MD_SET_FD_INHERITABLE(PRFileDesc *fd, PRBool inheritable)
return PR_FAILURE;
}
return PR_SUCCESS;
+#else
+ _PR_MD_CE_NOT_IMPLEMENTED;
+ return PR_FAILURE;
+#endif
}
void
@@ -934,6 +1015,7 @@ _PR_MD_INIT_FD_INHERITABLE(PRFileDesc *fd, PRBool imported)
void
_PR_MD_QUERY_FD_INHERITABLE(PRFileDesc *fd)
{
+#if !defined(WINCE)
DWORD flags;
PR_ASSERT(_PR_TRI_UNKNOWN == fd->secret->inheritable);
@@ -944,6 +1026,9 @@ _PR_MD_QUERY_FD_INHERITABLE(PRFileDesc *fd)
fd->secret->inheritable = _PR_TRI_FALSE;
}
}
+#else
+ fd->secret->inheritable = _PR_TRI_FALSE;
+#endif
}
PRInt32
@@ -961,7 +1046,9 @@ _PR_MD_RENAME(const char *from, const char *to)
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);
@@ -978,6 +1065,33 @@ PRInt32 rv;
}
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;
}
diff --git a/pr/src/md/windows/w95thred.c b/pr/src/md/windows/w95thred.c
index f8a70043..2453e271 100644
--- a/pr/src/md/windows/w95thred.c
+++ b/pr/src/md/windows/w95thred.c
@@ -33,7 +33,9 @@
*/
#include "primpl.h"
+#if !defined(WINCE)
#include <process.h> /* for _beginthreadex() */
+#endif
extern void _PR_Win32InitTimeZone(void); /* defined in ntmisc.c */
diff --git a/pr/src/md/windows/win32_errors.c b/pr/src/md/windows/win32_errors.c
index ee881389..3176c05f 100644
--- a/pr/src/md/windows/win32_errors.c
+++ b/pr/src/md/windows/win32_errors.c
@@ -34,7 +34,9 @@
#include "prerror.h"
#include "prlog.h"
+#if !defined(WINCE)
#include <errno.h>
+#endif
#include <windows.h>
/*
@@ -62,12 +64,14 @@ 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;
diff --git a/pr/src/misc/prerrortable.c b/pr/src/misc/prerrortable.c
index 43644cc7..acdf426d 100644
--- a/pr/src/misc/prerrortable.c
+++ b/pr/src/misc/prerrortable.c
@@ -57,8 +57,12 @@ provided "as is" without express or implied warranty.
#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"
@@ -200,8 +204,15 @@ PR_ErrorInstallTable(const struct PRErrorTable *table)
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);
diff --git a/pr/src/misc/prtime.c b/pr/src/misc/prtime.c
index 0aa6e46c..2cf0611d 100644
--- a/pr/src/misc/prtime.c
+++ b/pr/src/misc/prtime.c
@@ -45,6 +45,10 @@
#include "prprf.h"
#include "prlog.h"
+#if defined(WINCE)
+#include "primpl.h"
+#endif
+
#include <string.h>
#include <ctype.h>
@@ -54,7 +58,6 @@
-
/*
* Static variables used by functions in this file
*/
@@ -538,7 +541,9 @@ PR_NormalizeTime(PRExplodedTime *time, PRTimeParamFn params)
*-------------------------------------------------------------------------
*/
+#if !defined(WINCE)
#include <time.h>
+#endif
#if defined(HAVE_INT_LOCALTIME_R)
@@ -565,6 +570,9 @@ PR_NormalizeTime(PRExplodedTime *time, PRTimeParamFn params)
#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;
@@ -600,6 +608,8 @@ static struct tm *MT_safe_localtime(const time_t *clock, struct tm *result)
#if defined(XP_MAC)
tmPtr = Maclocaltime(clock);
+#elif defined(WINCE)
+ tmPtr = Winlocaltime(clock);
#else
tmPtr = localtime(clock);
#endif
diff --git a/pr/src/threads/combined/prucv.c b/pr/src/threads/combined/prucv.c
index 38e003fc..fb5d3f57 100644
--- a/pr/src/threads/combined/prucv.c
+++ b/pr/src/threads/combined/prucv.c
@@ -40,7 +40,7 @@
#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.
**
*/
diff --git a/pr/src/threads/combined/prulock.c b/pr/src/threads/combined/prulock.c
index 054f8e53..87ba0f6d 100644
--- a/pr/src/threads/combined/prulock.c
+++ b/pr/src/threads/combined/prulock.c
@@ -37,7 +37,7 @@
#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.
**
*/
diff --git a/pr/src/threads/combined/pruthr.c b/pr/src/threads/combined/pruthr.c
index 77236df1..dad8fdc4 100644
--- a/pr/src/threads/combined/pruthr.c
+++ b/pr/src/threads/combined/pruthr.c
@@ -33,13 +33,15 @@
*/
#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.
**
*/
diff --git a/pr/src/threads/prcthr.c b/pr/src/threads/prcthr.c
index 71dafca4..ca785421 100644
--- a/pr/src/threads/prcthr.c
+++ b/pr/src/threads/prcthr.c
@@ -37,7 +37,7 @@
#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.
**
*/
diff --git a/pr/src/threads/prdump.c b/pr/src/threads/prdump.c
index f860eac9..e46ad57b 100644
--- a/pr/src/threads/prdump.c
+++ b/pr/src/threads/prdump.c
@@ -37,7 +37,7 @@
#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.
**
*/
diff --git a/pr/src/threads/prtpd.c b/pr/src/threads/prtpd.c
index 6d8fd416..d5768b87 100644
--- a/pr/src/threads/prtpd.c
+++ b/pr/src/threads/prtpd.c
@@ -70,7 +70,7 @@
#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.
**
*/