Bugzilla Bug 225859: added 64-bit Windows support. Peter Armistead
authorwtchang%redhat.com
Fri, 21 Oct 2005 18:21:43 +0000
changeset 3480 d85ff6768897d89cdb0c59cededaa322737a3cdd
parent 3477 ce40ce0f80cad4d504134f6e1220a31a2ddc1b42
child 3486 f38d4f1e412e730b9116d63e995c4fc6eede1df9
push idunknown
push userunknown
push dateunknown
bugs225859
Bugzilla Bug 225859: added 64-bit Windows support. Peter Armistead contributed the first 64-bit Windows patch (for IA64) in 2001. Portions of this checkin are based on the patch contributed by Makoto Kato <m_kato@ga2.so-net.ne.jp>. r=wtc. Modified Files: configure configure.in prtypes.h _win95.cfg _win95.h _winnt.cfg _winnt.h probslet.h pprio.h primpl.h pr/src/Makefile.in prfile.c prio.c prsocket.c ntgc.c ntio.c ntmisc.c w32rng.c w32shm.c w95io.c w95sock.c w95thred.c prinit.c pr/tests/prpoll.c
configure
configure.in
pr/include/md/_win95.cfg
pr/include/md/_win95.h
pr/include/md/_winnt.cfg
pr/include/md/_winnt.h
pr/include/obsolete/probslet.h
pr/include/private/pprio.h
pr/include/private/primpl.h
pr/include/prtypes.h
pr/src/Makefile.in
pr/src/io/prfile.c
pr/src/io/prio.c
pr/src/io/prsocket.c
pr/src/md/windows/ntgc.c
pr/src/md/windows/ntio.c
pr/src/md/windows/ntmisc.c
pr/src/md/windows/w32rng.c
pr/src/md/windows/w32shm.c
pr/src/md/windows/w95io.c
pr/src/md/windows/w95sock.c
pr/src/md/windows/w95thred.c
pr/src/misc/prinit.c
pr/tests/prpoll.c
--- a/configure
+++ b/configure
@@ -4028,24 +4028,53 @@ EOF
 
    	    ;;
     mips)
 	    cat >> confdefs.h <<\EOF
 #define _MIPS_ 1
 EOF
 
 	    ;;
+    x86_64)
+	    cat >> confdefs.h <<\EOF
+#define _AMD64_ 1
+EOF
+
+	    cat >> confdefs.h <<\EOF
+#define _M_AMD64 1
+EOF
+
+	    USE_64=1
+	    ;;
+    ia64)
+	    cat >> confdefs.h <<\EOF
+#define _IA64_ 1
+EOF
+
+	    cat >> confdefs.h <<\EOF
+#define _M_IA64 1
+EOF
+
+	    USE_64=1
+	    ;;
     *)
 	    cat >> confdefs.h <<\EOF
 #define _CPU_ARCH_NOT_DEFINED 1
 EOF
 
 	    ;;
     esac
 
+    if test "$USE_64"; then
+        cat >> confdefs.h <<\EOF
+#define _WIN64 1
+EOF
+
+    fi
+
     ;;
 
 *-ncr-sysv*)
     cat >> confdefs.h <<\EOF
 #define XP_UNIX 1
 EOF
 
     cat >> confdefs.h <<\EOF
@@ -4331,27 +4360,27 @@ EOF
     if test -z "$GNU_CC"; then
         CC="$CC -std1 -ieee_with_inexact"
         if test "$OS_RELEASE" != "V2.0"; then
             CC="$CC -readonly_strings"
         fi
         _OPTIMIZE_FLAGS="$_OPTIMIZE_FLAGS -Olimit 4000"
         ac_safe=`echo "machine/builtins.h" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for machine/builtins.h""... $ac_c" 1>&6
-echo "configure:4340: checking for machine/builtins.h" >&5
+echo "configure:4369: checking for machine/builtins.h" >&5
 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 4345 "configure"
+#line 4374 "configure"
 #include "confdefs.h"
 #include <machine/builtins.h>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:4350: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:4379: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   rm -rf conftest*
   eval "ac_cv_header_$ac_safe=yes"
 else
   echo "$ac_err" >&5
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
@@ -4903,63 +4932,63 @@ if test -z "$SKIP_LIBRARY_CHECKS"; then
 
 
 
 case $target in
 *-darwin*)
     ;;
 *)
     echo $ac_n "checking for dlopen in -ldl""... $ac_c" 1>&6
-echo "configure:4912: checking for dlopen in -ldl" >&5
+echo "configure:4941: checking for dlopen in -ldl" >&5
 ac_lib_var=`echo dl'_'dlopen | sed 'y%./+-%__p_%'`
 if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   ac_save_LIBS="$LIBS"
 LIBS="-ldl  $LIBS"
 cat > conftest.$ac_ext <<EOF
-#line 4920 "configure"
+#line 4949 "configure"
 #include "confdefs.h"
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
     builtin and then its argument prototype would still apply.  */
 char dlopen();
 
 int main() {
 dlopen()
 ; return 0; }
 EOF
-if { (eval echo configure:4931: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:4960: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=yes"
 else
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=no"
 fi
 rm -f conftest*
 LIBS="$ac_save_LIBS"
 
 fi
 if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then
   echo "$ac_t""yes" 1>&6
   ac_safe=`echo "dlfcn.h" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for dlfcn.h""... $ac_c" 1>&6
-echo "configure:4948: checking for dlfcn.h" >&5
+echo "configure:4977: checking for dlfcn.h" >&5
 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 4953 "configure"
+#line 4982 "configure"
 #include "confdefs.h"
 #include <dlfcn.h>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:4958: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:4987: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   rm -rf conftest*
   eval "ac_cv_header_$ac_safe=yes"
 else
   echo "$ac_err" >&5
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
@@ -4982,23 +5011,23 @@ fi
     ;;
 esac
 
 
 
 
 if test $ac_cv_prog_gcc = yes; then
     echo $ac_n "checking whether ${CC-cc} needs -traditional""... $ac_c" 1>&6
-echo "configure:4991: checking whether ${CC-cc} needs -traditional" >&5
+echo "configure:5020: checking whether ${CC-cc} needs -traditional" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_gcc_traditional'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
     ac_pattern="Autoconf.*'x'"
   cat > conftest.$ac_ext <<EOF
-#line 4997 "configure"
+#line 5026 "configure"
 #include "confdefs.h"
 #include <sgtty.h>
 Autoconf TIOCGETP
 EOF
 if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
   egrep "$ac_pattern" >/dev/null 2>&1; then
   rm -rf conftest*
   ac_cv_prog_gcc_traditional=yes
@@ -5006,17 +5035,17 @@ else
   rm -rf conftest*
   ac_cv_prog_gcc_traditional=no
 fi
 rm -f conftest*
 
 
   if test $ac_cv_prog_gcc_traditional = no; then
     cat > conftest.$ac_ext <<EOF
-#line 5015 "configure"
+#line 5044 "configure"
 #include "confdefs.h"
 #include <termio.h>
 Autoconf TCGETA
 EOF
 if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
   egrep "$ac_pattern" >/dev/null 2>&1; then
   rm -rf conftest*
   ac_cv_prog_gcc_traditional=yes
@@ -5030,22 +5059,22 @@ echo "$ac_t""$ac_cv_prog_gcc_traditional
   if test $ac_cv_prog_gcc_traditional = yes; then
     CC="$CC -traditional"
   fi
 fi
 
 for ac_func in lchown strerror
 do
 echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:5039: checking for $ac_func" >&5
+echo "configure:5068: checking for $ac_func" >&5
 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 5044 "configure"
+#line 5073 "configure"
 #include "confdefs.h"
 /* System header to define __stub macros and hopefully few prototypes,
     which can conflict with char $ac_func(); below.  */
 #include <assert.h>
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
     builtin and then its argument prototype would still apply.  */
 char $ac_func();
@@ -5058,17 +5087,17 @@ int main() {
 #if defined (__stub_$ac_func) || defined (__stub___$ac_func)
 choke me
 #else
 $ac_func();
 #endif
 
 ; return 0; }
 EOF
-if { (eval echo configure:5067: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:5096: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_func_$ac_func=yes"
 else
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
   rm -rf conftest*
   eval "ac_cv_func_$ac_func=no"
 fi
@@ -5099,17 +5128,17 @@ if test "${enable_strip+set}" = set; the
 fi
 
 
 case "${target_os}" in
 hpux*)
 if test -z "$GNU_CC"; then
 
     echo $ac_n "checking for +Olit support""... $ac_c" 1>&6
-echo "configure:5108: checking for +Olit support" >&5
+echo "configure:5137: checking for +Olit support" >&5
 if eval "test \"`echo '$''{'ac_cv_hpux_usable_olit_option'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
                   ac_cv_hpux_usable_olit_option=no
         rm -f conftest*
         echo 'int main() { return 0; }' | cat > conftest.c
         ${CC-cc} ${CFLAGS} +Olit=all -o conftest conftest.c > conftest.out 2>&1
         if test $? -eq 0; then
@@ -5138,17 +5167,17 @@ esac
 
 case "$target_os" in
 darwin*)
     _HAVE_PTHREADS=1
     ;;
 *)
     
 echo $ac_n "checking for pthread_create in -lpthreads""... $ac_c" 1>&6
-echo "configure:5147: checking for pthread_create in -lpthreads" >&5
+echo "configure:5176: checking for pthread_create in -lpthreads" >&5
 echo "
     #include <pthread.h> 
     void *foo(void *v) { return v; } 
     int main() { 
         pthread_t t;
         if (!pthread_create(&t, 0, &foo, 0)) {
             pthread_join(t, 0);
         }
@@ -5160,17 +5189,17 @@ echo "
     rm -f dummy.c dummy${ac_exeext} ;
     if test "$_res" = "0"; then
         echo "$ac_t""yes" 1>&6
         _HAVE_PTHREADS=1 _PTHREAD_LDFLAGS="-lpthreads"
     else
         echo "$ac_t""no" 1>&6
         
 echo $ac_n "checking for pthread_create in -lpthread""... $ac_c" 1>&6
-echo "configure:5169: checking for pthread_create in -lpthread" >&5
+echo "configure:5198: checking for pthread_create in -lpthread" >&5
 echo "
     #include <pthread.h> 
     void *foo(void *v) { return v; } 
     int main() { 
         pthread_t t;
         if (!pthread_create(&t, 0, &foo, 0)) {
             pthread_join(t, 0);
         }
@@ -5182,17 +5211,17 @@ echo "
     rm -f dummy.c dummy${ac_exeext} ;
     if test "$_res" = "0"; then
         echo "$ac_t""yes" 1>&6
         _HAVE_PTHREADS=1 _PTHREAD_LDFLAGS="-lpthread"
     else
         echo "$ac_t""no" 1>&6
         
 echo $ac_n "checking for pthread_create in -lc_r""... $ac_c" 1>&6
-echo "configure:5191: checking for pthread_create in -lc_r" >&5
+echo "configure:5220: checking for pthread_create in -lc_r" >&5
 echo "
     #include <pthread.h> 
     void *foo(void *v) { return v; } 
     int main() { 
         pthread_t t;
         if (!pthread_create(&t, 0, &foo, 0)) {
             pthread_join(t, 0);
         }
@@ -5204,17 +5233,17 @@ echo "
     rm -f dummy.c dummy${ac_exeext} ;
     if test "$_res" = "0"; then
         echo "$ac_t""yes" 1>&6
         _HAVE_PTHREADS=1 _PTHREAD_LDFLAGS="-lc_r"
     else
         echo "$ac_t""no" 1>&6
         
 echo $ac_n "checking for pthread_create in -lc""... $ac_c" 1>&6
-echo "configure:5213: checking for pthread_create in -lc" >&5
+echo "configure:5242: checking for pthread_create in -lc" >&5
 echo "
     #include <pthread.h> 
     void *foo(void *v) { return v; } 
     int main() { 
         pthread_t t;
         if (!pthread_create(&t, 0, &foo, 0)) {
             pthread_join(t, 0);
         }
@@ -5358,17 +5387,17 @@ EOF
     fi
 fi
 
 
 if test -n "$USE_PTHREADS"; then
       rm -f conftest*
    ac_cv_have_dash_pthread=no
    echo $ac_n "checking whether ${CC-cc} accepts -pthread""... $ac_c" 1>&6
-echo "configure:5367: checking whether ${CC-cc} accepts -pthread" >&5
+echo "configure:5396: checking whether ${CC-cc} accepts -pthread" >&5
    echo 'int main() { return 0; }' | cat > conftest.c
    ${CC-cc} -pthread -o conftest conftest.c > conftest.out 2>&1
    if test $? -eq 0; then
 	if test -z "`egrep -i '(unrecognize|unknown)' conftest.out | grep pthread`" && test -z "`egrep -i '(error|incorrect)' conftest.out`" ; then
 	    ac_cv_have_dash_pthread=yes
 		case "$target_os" in
 	    freebsd*)
 # Freebsd doesn't use -pthread for compiles, it uses them for linking
@@ -5381,17 +5410,17 @@ echo "configure:5367: checking whether $
 	fi
     fi
     rm -f conftest*
     echo "$ac_t""$ac_cv_have_dash_pthread" 1>&6
 
 			    ac_cv_have_dash_pthreads=no
     if test "$ac_cv_have_dash_pthread" = "no"; then
 	    echo $ac_n "checking whether ${CC-cc} accepts -pthreads""... $ac_c" 1>&6
-echo "configure:5390: checking whether ${CC-cc} accepts -pthreads" >&5
+echo "configure:5419: checking whether ${CC-cc} accepts -pthreads" >&5
     	echo 'int main() { return 0; }' | cat > conftest.c
 	    ${CC-cc} -pthreads -o conftest conftest.c > conftest.out 2>&1
     	if test $? -eq 0; then
 	    	if test -z "`egrep -i '(unrecognize|unknown)' conftest.out | grep pthreads`" && test -z "`egrep -i '(error|incorrect)' conftest.out`" ; then
 			    ac_cv_have_dash_pthreads=yes
 			    CFLAGS="$CFLAGS -pthreads"
 			    CXXFLAGS="$CXXFLAGS -pthreads"
 		    fi
--- a/configure.in
+++ b/configure.in
@@ -1487,21 +1487,35 @@ case "$target" in
 	    AC_DEFINE(_X86_)
         ;;
     alpha)
 	    AC_DEFINE(_ALPHA_)
    	    ;;
     mips)
 	    AC_DEFINE(_MIPS_)
 	    ;;
+    x86_64)
+	    AC_DEFINE(_AMD64_)
+	    AC_DEFINE(_M_AMD64)
+	    USE_64=1
+	    ;;
+    ia64)
+	    AC_DEFINE(_IA64_)
+	    AC_DEFINE(_M_IA64)
+	    USE_64=1
+	    ;;
     *)
 	    AC_DEFINE(_CPU_ARCH_NOT_DEFINED)
 	    ;;
     esac
 
+    if test "$USE_64"; then
+        AC_DEFINE(_WIN64)
+    fi
+
     ;;
 
 *-ncr-sysv*)
     AC_DEFINE(XP_UNIX)
     AC_DEFINE(SVR4)
     AC_DEFINE(SYSV)
     AC_DEFINE(NCR)
     USE_NSPR_THREADS=1
--- a/pr/include/md/_win95.cfg
+++ b/pr/include/md/_win95.cfg
@@ -139,16 +139,114 @@
 #define PR_ALIGN_OF_SHORT   2
 #define PR_ALIGN_OF_INT     4
 #define PR_ALIGN_OF_LONG    4
 #define PR_ALIGN_OF_INT64   8
 #define PR_ALIGN_OF_FLOAT   4
 #define PR_ALIGN_OF_DOUBLE  8
 #define PR_ALIGN_OF_POINTER 4
 
+#elif defined(_AMD64_)
+
+#define IS_LITTLE_ENDIAN 1
+#undef  IS_BIG_ENDIAN
+#define IS_64
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_WORD	8
+#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	64
+#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	6
+#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	8
+#define PR_ALIGN_OF_DWORD	8
+#define PR_ALIGN_OF_DOUBLE  8
+#define PR_ALIGN_OF_POINTER 8
+
+#define PR_BYTES_PER_WORD_LOG2	3
+#define PR_BYTES_PER_DWORD_LOG2	3
+
+#elif defined(_IA64_)
+
+#define IS_LITTLE_ENDIAN 1
+#undef  IS_BIG_ENDIAN
+#define IS_64
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_WORD	8
+#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	64
+#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	6
+#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	8
+#define PR_ALIGN_OF_DWORD	8
+#define PR_ALIGN_OF_DOUBLE  8
+#define PR_ALIGN_OF_POINTER 8
+
+#define PR_BYTES_PER_WORD_LOG2	3
+#define PR_BYTES_PER_DWORD_LOG2	3
+
 #else /* defined(_M_IX86) || defined(_X86_) */
 
 #error unknown processor architecture
 
 #endif /* defined(_M_IX86) || defined(_X86_) */
 
 #define HAVE_LONG_LONG
 
--- a/pr/include/md/_win95.h
+++ b/pr/include/md/_win95.h
@@ -45,17 +45,25 @@
 #include <errno.h>
 
 /*
  * Internal configuration macros
  */
 
 #define PR_LINKER_ARCH      "win32"
 #define _PR_SI_SYSNAME        "WIN95"
-#define _PR_SI_ARCHITECTURE   "x86"    /* XXXMB hardcode for now */
+#if defined(_M_IX86) || defined(_X86_)
+#define _PR_SI_ARCHITECTURE   "x86"
+#elif defined(_AMD64_)
+#define _PR_SI_ARCHITECTURE   "x86-64"
+#elif defined(_IA64_)
+#define _PR_SI_ARCHITECTURE   "ia64"
+#else
+#error unknown processor architecture
+#endif
 
 #define HAVE_DLL
 #undef  HAVE_THREAD_AFFINITY
 #define _PR_HAVE_GETADDRINFO
 #define _PR_INET6_PROBE
 #ifndef _PR_INET6
 #define AF_INET6 23
 /* newer ws2tcpip.h provides these */
@@ -203,17 +211,17 @@ struct _MDLock {
 #endif
 };
 
 struct _MDSemaphore {
     HANDLE           sem;
 };
 
 struct _MDFileDesc {
-    PRInt32 osfd;    /* The osfd can come from one of three spaces:
+    PROsfd 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.
                       */
 };
@@ -243,17 +251,17 @@ extern void _PR_NT_FreeSecurityDescripto
 
 #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);
+extern PRInt32 _MD_CloseFile(PROsfd 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     
@@ -300,17 +308,17 @@ extern PRInt32 _MD_CloseFile(PRInt32 osf
 
 #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);
+extern PRInt32 _MD_CloseSocket(PROsfd 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
@@ -336,17 +344,17 @@ extern PRInt32 _MD_CloseSocket(PRInt32 o
 
 
 /* win95 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,
+extern PROsfd _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 --- */
--- a/pr/include/md/_winnt.cfg
+++ b/pr/include/md/_winnt.cfg
@@ -139,16 +139,114 @@
 #define PR_ALIGN_OF_SHORT   2
 #define PR_ALIGN_OF_INT     4
 #define PR_ALIGN_OF_LONG    4
 #define PR_ALIGN_OF_INT64   8
 #define PR_ALIGN_OF_FLOAT   4
 #define PR_ALIGN_OF_DOUBLE  8
 #define PR_ALIGN_OF_POINTER 4
 
+#elif defined(_AMD64_)
+
+#define IS_LITTLE_ENDIAN 1
+#undef  IS_BIG_ENDIAN
+#define IS_64
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_WORD   8
+#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    64
+#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	6
+#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    8
+#define PR_ALIGN_OF_DWORD   8
+#define PR_ALIGN_OF_DOUBLE  8
+#define PR_ALIGN_OF_POINTER 8
+
+#define PR_BYTES_PER_WORD_LOG2	3
+#define PR_BYTES_PER_DWORD_LOG2	3
+
+#elif defined(_IA64_)
+
+#define IS_LITTLE_ENDIAN 1
+#undef  IS_BIG_ENDIAN
+#define IS_64
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_WORD   8
+#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    64
+#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	6
+#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    8
+#define PR_ALIGN_OF_DWORD   8
+#define PR_ALIGN_OF_DOUBLE  8
+#define PR_ALIGN_OF_POINTER 8
+
+#define PR_BYTES_PER_WORD_LOG2	3
+#define PR_BYTES_PER_DWORD_LOG2	3
+
 #else /* defined(_M_IX86) || defined(_X86_) */
 
 #error unknown processor architecture
 
 #endif /* defined(_M_IX86) || defined(_X86_) */
 
 #define HAVE_LONG_LONG
 
--- a/pr/include/md/_winnt.h
+++ b/pr/include/md/_winnt.h
@@ -59,17 +59,25 @@
 #include "prclist.h"
 
 /*
  * Internal configuration macros
  */
 
 #define PR_LINKER_ARCH      "win32"
 #define _PR_SI_SYSNAME        "WINNT"
-#define _PR_SI_ARCHITECTURE   "x86"    /* XXXMB hardcode for now */
+#if defined(_M_IX86) || defined(_X86_)
+#define _PR_SI_ARCHITECTURE   "x86"
+#elif defined(_AMD64_)
+#define _PR_SI_ARCHITECTURE   "x86-64"
+#elif defined(_IA64_)
+#define _PR_SI_ARCHITECTURE   "ia64"
+#else
+#error unknown processor architecture
+#endif
 
 #define HAVE_DLL
 #define HAVE_CUSTOM_USER_THREADS
 #define HAVE_THREAD_AFFINITY
 #define _PR_HAVE_GETADDRINFO
 #define _PR_INET6_PROBE
 #ifndef _PR_INET6
 #define AF_INET6 23
@@ -101,17 +109,19 @@ struct _md_sockaddr_in6 {
     PRUint16 sin6_port;
     PRUint32 sin6_flowinfo;
     struct _md_in6_addr sin6_addr;
     PRUint32 sin6_scope_id;
 };
 #endif
 #define _PR_HAVE_THREADSAFE_GETHOST
 #define _PR_HAVE_ATOMIC_OPS
+#if defined(_M_IX86) || defined(_X86_)
 #define _PR_HAVE_ATOMIC_CAS
+#endif
 #define PR_HAVE_WIN32_NAMED_SHARED_MEMORY
 #define _PR_HAVE_PEEK_BUFFER
 #define _PR_PEEK_BUFFER_MAX (32 * 1024)
 #define _PR_FD_NEED_EMULATE_MSG_PEEK(fd) \
     (!(fd)->secret->nonblocking && (fd)->secret->inheritable != _PR_TRI_TRUE)
 
 /* --- Common User-Thread/Native-Thread Definitions --------------------- */
 
@@ -226,17 +236,17 @@ struct _MDCVar {
     PRUint32         unused;
 };
 
 struct _MDSemaphore {
     HANDLE           sem;
 };
 
 struct _MDFileDesc {
-    PRInt32 osfd;    /* The osfd can come from one of three spaces:
+    PROsfd 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.
                       */
     PRBool io_model_committed;  /* The io model (blocking or nonblocking)
@@ -276,17 +286,17 @@ extern PRStatus _PR_NT_MakeSecurityDescr
     PACL *resultACL
 );
 extern void _PR_NT_FreeSecurityDescriptorACL(
     PSECURITY_DESCRIPTOR pSD, PACL pACL);
 
 /* --- IO stuff --- */
 
 extern PRInt32 _md_Associate(HANDLE);
-extern PRInt32 _PR_MD_CLOSE(PRInt32 osfd, PRBool socket);
+extern PRInt32 _PR_MD_CLOSE(PROsfd osfd, PRBool socket);
 
 #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
--- a/pr/include/obsolete/probslet.h
+++ b/pr/include/obsolete/probslet.h
@@ -39,16 +39,17 @@
 ** A collection of things thought to be obsolete
 */
 
 #if defined(PROBSLET_H)
 #else
 #define PROBSLET_H
 
 #include "prio.h"
+#include "private/pprio.h"  /* for PROsfd */
 
 PR_BEGIN_EXTERN_C
 
 /*
 ** Yield the current thread.  The proper function to use in place of
 ** PR_Yield() is PR_Sleep() with an argument of PR_INTERVAL_NO_WAIT.
 */
 NSPR_API(PRStatus) PR_Yield(void);
@@ -65,17 +66,17 @@ NSPR_API(PRStatus) PR_Yield(void);
 */
 #ifndef PR_MAX_SELECT_DESC
 #define PR_MAX_SELECT_DESC 1024
 #endif
 typedef struct PR_fd_set {
     PRUint32      hsize;
     PRFileDesc   *harray[PR_MAX_SELECT_DESC];
     PRUint32      nsize;
-    PRInt32       narray[PR_MAX_SELECT_DESC];
+    PROsfd        narray[PR_MAX_SELECT_DESC];
 } PR_fd_set;
 
 /*
 *************************************************************************
 ** FUNCTION:    PR_Select
 ** DESCRIPTION:
 **
 ** The call returns as soon as I/O is ready on one or more of the underlying
@@ -149,19 +150,19 @@ NSPR_API(PRInt32) PR_Select(
 ** PR_FD_NISSET(osfd, &fdset) is nonzero if native file descriptor osfd is a member of 
 ** fdset, zero otherwise.
 */
 
 NSPR_API(void)        PR_FD_ZERO(PR_fd_set *set);
 NSPR_API(void)        PR_FD_SET(PRFileDesc *fd, PR_fd_set *set);
 NSPR_API(void)        PR_FD_CLR(PRFileDesc *fd, PR_fd_set *set);
 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);
+NSPR_API(void)        PR_FD_NSET(PROsfd osfd, PR_fd_set *set);
+NSPR_API(void)        PR_FD_NCLR(PROsfd osfd, PR_fd_set *set);
+NSPR_API(PRInt32)     PR_FD_NISSET(PROsfd osfd, PR_fd_set *set);
 
 #ifndef NO_NSPR_10_SUPPORT
 #ifdef XP_MAC
 #include <stat.h>
 #else
 #include <sys/stat.h>
 #endif
 
--- a/pr/include/private/pprio.h
+++ b/pr/include/private/pprio.h
@@ -47,38 +47,44 @@
 #include "prtypes.h"
 #include "prio.h"
 
 PR_BEGIN_EXTERN_C
 
 /************************************************************************/
 /************************************************************************/
 
+#ifdef _WIN64
+typedef __int64 PROsfd;
+#else
+typedef PRInt32 PROsfd;
+#endif
+
 /* Return the method tables for files, tcp sockets and udp sockets */
 NSPR_API(const PRIOMethods*)    PR_GetFileMethods(void);
 NSPR_API(const PRIOMethods*)    PR_GetTCPMethods(void);
 NSPR_API(const PRIOMethods*)    PR_GetUDPMethods(void);
 NSPR_API(const PRIOMethods*)    PR_GetPipeMethods(void);
 
 /*
 ** Convert a NSPR Socket Handle to a Native Socket handle.
 ** This function will be obsoleted with the next release; avoid using it.
 */
-NSPR_API(PRInt32)      PR_FileDesc2NativeHandle(PRFileDesc *);
-NSPR_API(void)         PR_ChangeFileDescNativeHandle(PRFileDesc *, PRInt32);
-NSPR_API(PRFileDesc*)  PR_AllocFileDesc(PRInt32 osfd,
+NSPR_API(PROsfd)       PR_FileDesc2NativeHandle(PRFileDesc *);
+NSPR_API(void)         PR_ChangeFileDescNativeHandle(PRFileDesc *, PROsfd);
+NSPR_API(PRFileDesc*)  PR_AllocFileDesc(PROsfd osfd,
                                          const PRIOMethods *methods);
 NSPR_API(void)         PR_FreeFileDesc(PRFileDesc *fd);
 /*
 ** Import an existing OS file to NSPR. 
 */
-NSPR_API(PRFileDesc*)  PR_ImportFile(PRInt32 osfd);
-NSPR_API(PRFileDesc*)  PR_ImportPipe(PRInt32 osfd);
-NSPR_API(PRFileDesc*)  PR_ImportTCPSocket(PRInt32 osfd);
-NSPR_API(PRFileDesc*)  PR_ImportUDPSocket(PRInt32 osfd);
+NSPR_API(PRFileDesc*)  PR_ImportFile(PROsfd osfd);
+NSPR_API(PRFileDesc*)  PR_ImportPipe(PROsfd osfd);
+NSPR_API(PRFileDesc*)  PR_ImportTCPSocket(PROsfd osfd);
+NSPR_API(PRFileDesc*)  PR_ImportUDPSocket(PROsfd osfd);
 
 
 /*
  *************************************************************************
  * FUNCTION: PR_CreateSocketPollFd
  * DESCRIPTION:
  *     Create a PRFileDesc wrapper for a native socket handle, for use with
  *	   PR_Poll only
@@ -89,17 +95,17 @@ NSPR_API(PRFileDesc*)  PR_ImportUDPSocke
  * RETURN: PRFileDesc*
  *     Upon successful completion, PR_CreateSocketPollFd returns a pointer
  *     to the PRFileDesc created for the native socket handle
  *     Returns a NULL pointer if the create of a new PRFileDesc failed
  *
  **************************************************************************
  */
 
-NSPR_API(PRFileDesc*)	PR_CreateSocketPollFd(PRInt32 osfd);
+NSPR_API(PRFileDesc*)	PR_CreateSocketPollFd(PROsfd osfd);
 
 /*
  *************************************************************************
  * FUNCTION: PR_DestroySocketPollFd
  * DESCRIPTION:
  *     Destroy the PRFileDesc wrapper created by PR_CreateSocketPollFd
  * INPUTS:
  *     None
--- a/pr/include/private/primpl.h
+++ b/pr/include/private/primpl.h
@@ -1093,23 +1093,23 @@ extern void _PR_MD_INIT_FILEDESC(PRFileD
 extern void _PR_MD_FREE_FILEDESC(PRFileDesc *fd);
 #define    _PR_MD_FREE_FILEDESC _MD_FREE_FILEDESC
 #endif
 
 extern void _PR_MD_MAKE_NONBLOCK(PRFileDesc *fd);
 #define    _PR_MD_MAKE_NONBLOCK _MD_MAKE_NONBLOCK
 
 /* File I/O related */
-extern PRInt32 _PR_MD_OPEN(const char *name, PRIntn osflags, PRIntn mode);
+extern PROsfd _PR_MD_OPEN(const char *name, PRIntn osflags, PRIntn mode);
 #define    _PR_MD_OPEN _MD_OPEN
 
-extern PRInt32 _PR_MD_OPEN_FILE(const char *name, PRIntn osflags, PRIntn mode);
+extern PROsfd _PR_MD_OPEN_FILE(const char *name, PRIntn osflags, PRIntn mode);
 #define    _PR_MD_OPEN_FILE _MD_OPEN_FILE
 
-extern PRInt32 _PR_MD_CLOSE_FILE(PRInt32 osfd);
+extern PRInt32 _PR_MD_CLOSE_FILE(PROsfd osfd);
 #define    _PR_MD_CLOSE_FILE _MD_CLOSE_FILE
 
 extern PRInt32 _PR_MD_READ(PRFileDesc *fd, void *buf, PRInt32 amount);
 #define    _PR_MD_READ _MD_READ
 
 extern PRInt32 _PR_MD_WRITE(PRFileDesc *fd, const void *buf, PRInt32 amount);
 #define    _PR_MD_WRITE _MD_WRITE
 
@@ -1142,42 +1142,42 @@ extern PRInt32 _PR_MD_MAKE_DIR(const cha
 extern PRInt32 _PR_MD_RMDIR(const char *name);
 #define _PR_MD_RMDIR _MD_RMDIR
 
 #ifdef MOZ_UNICODE
 /* UTF16 File I/O related */
 extern PRStatus _PR_MD_OPEN_DIR_UTF16(_MDDirUTF16 *md, const PRUnichar *name);
 #define    _PR_MD_OPEN_DIR_UTF16 _MD_OPEN_DIR_UTF16
 
-extern PRInt32 _PR_MD_OPEN_FILE_UTF16(const PRUnichar *name, PRIntn osflags, PRIntn mode);
+extern PROsfd _PR_MD_OPEN_FILE_UTF16(const PRUnichar *name, PRIntn osflags, PRIntn mode);
 #define    _PR_MD_OPEN_FILE_UTF16 _MD_OPEN_FILE_UTF16
 
 extern PRUnichar * _PR_MD_READ_DIR_UTF16(_MDDirUTF16 *md, PRIntn flags);
 #define    _PR_MD_READ_DIR_UTF16 _MD_READ_DIR_UTF16
 
 extern PRInt32 _PR_MD_CLOSE_DIR_UTF16(_MDDirUTF16 *md);
 #define    _PR_MD_CLOSE_DIR_UTF16 _MD_CLOSE_DIR_UTF16
 
 extern PRInt32 _PR_MD_GETFILEINFO64_UTF16(const PRUnichar *fn, PRFileInfo64 *info);
 #define _PR_MD_GETFILEINFO64_UTF16 _MD_GETFILEINFO64_UTF16
 #endif /* MOZ_UNICODE */
 
 /* Socket I/O related */
 extern void _PR_MD_INIT_IO(void);
 #define    _PR_MD_INIT_IO _MD_INIT_IO
 
-extern PRInt32 _PR_MD_CLOSE_SOCKET(PRInt32 osfd);
+extern PRInt32 _PR_MD_CLOSE_SOCKET(PROsfd osfd);
 #define    _PR_MD_CLOSE_SOCKET _MD_CLOSE_SOCKET
 
 extern PRInt32 _PR_MD_CONNECT(
     PRFileDesc *fd, const PRNetAddr *addr,
     PRUint32 addrlen, PRIntervalTime timeout);
 #define    _PR_MD_CONNECT _MD_CONNECT
 
-extern PRInt32 _PR_MD_ACCEPT(
+extern PROsfd _PR_MD_ACCEPT(
     PRFileDesc *fd, PRNetAddr *addr,
     PRUint32 *addrlen, PRIntervalTime timeout);
 #define    _PR_MD_ACCEPT _MD_ACCEPT
 
 extern PRInt32 _PR_MD_BIND(PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen);
 #define    _PR_MD_BIND _MD_BIND
 
 extern PRInt32 _PR_MD_LISTEN(PRFileDesc *fd, PRIntn backlog);
@@ -1190,35 +1190,35 @@ extern PRInt32 _PR_MD_RECV(PRFileDesc *f
                                PRIntn flags, PRIntervalTime timeout);
 #define    _PR_MD_RECV _MD_RECV
 
 extern PRInt32 _PR_MD_SEND(
     PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags, 
     PRIntervalTime timeout);
 #define    _PR_MD_SEND _MD_SEND
 
-extern PRInt32 _PR_MD_ACCEPT_READ(PRFileDesc *sd, PRInt32 *newSock, 
+extern PRInt32 _PR_MD_ACCEPT_READ(PRFileDesc *sd, PROsfd *newSock, 
                                 PRNetAddr **raddr, void *buf, PRInt32 amount,
                                 PRIntervalTime timeout);
 #define _PR_MD_ACCEPT_READ _MD_ACCEPT_READ
 
 #ifdef WIN32
-extern PRInt32 _PR_MD_FAST_ACCEPT(PRFileDesc *fd, PRNetAddr *addr, 
+extern PROsfd _PR_MD_FAST_ACCEPT(PRFileDesc *fd, PRNetAddr *addr, 
                                 PRUint32 *addrlen, PRIntervalTime timeout,
                                 PRBool fast,
                                 _PR_AcceptTimeoutCallback callback,
                                 void *callbackArg);
 
-extern PRInt32 _PR_MD_FAST_ACCEPT_READ(PRFileDesc *sd, PRInt32 *newSock, 
+extern PRInt32 _PR_MD_FAST_ACCEPT_READ(PRFileDesc *sd, PROsfd *newSock, 
                                 PRNetAddr **raddr, void *buf, PRInt32 amount,
                                 PRIntervalTime timeout, PRBool fast,
                                 _PR_AcceptTimeoutCallback callback,
                                 void *callbackArg);
 
-extern void _PR_MD_UPDATE_ACCEPT_CONTEXT(PRInt32 s, PRInt32 ls);
+extern void _PR_MD_UPDATE_ACCEPT_CONTEXT(PROsfd s, PROsfd ls);
 #define _PR_MD_UPDATE_ACCEPT_CONTEXT _MD_UPDATE_ACCEPT_CONTEXT
 #endif /* WIN32 */
 
 extern PRInt32 _PR_MD_SENDFILE(
     PRFileDesc *sock, PRSendFileData *sfd, 
 	PRInt32 flags, PRIntervalTime timeout);
 #define _PR_MD_SENDFILE _MD_SENDFILE
 
@@ -1250,20 +1250,20 @@ extern PRInt32 _PR_MD_RECVFROM(
     PRNetAddr *addr, PRUint32 *addrlen, PRIntervalTime timeout);
 #define    _PR_MD_RECVFROM _MD_RECVFROM
 
 extern PRInt32 _PR_MD_SENDTO(
     PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
     const PRNetAddr *addr, PRUint32 addrlen, PRIntervalTime timeout);
 #define    _PR_MD_SENDTO _MD_SENDTO
 
-extern PRInt32 _PR_MD_SOCKETPAIR(int af, int type, int flags, PRInt32 *osfd);
+extern PRInt32 _PR_MD_SOCKETPAIR(int af, int type, int flags, PROsfd *osfd);
 #define    _PR_MD_SOCKETPAIR _MD_SOCKETPAIR
 
-extern PRInt32 _PR_MD_SOCKET(int af, int type, int flags);
+extern PROsfd _PR_MD_SOCKET(int af, int type, int flags);
 #define    _PR_MD_SOCKET _MD_SOCKET
 
 extern PRInt32 _PR_MD_SOCKETAVAILABLE(PRFileDesc *fd);
 #define    _PR_MD_SOCKETAVAILABLE _MD_SOCKETAVAILABLE
 
 extern PRInt32 _PR_MD_PIPEAVAILABLE(PRFileDesc *fd);
 #define    _PR_MD_PIPEAVAILABLE _MD_PIPEAVAILABLE
 
@@ -1749,16 +1749,28 @@ struct PRFilePrivate {
     PRUint16 af;        /* If the platform requires passing the exact
                          * length of the sockaddr structure for the
                          * address family of the socket to socket
                          * functions like accept(), we need to save
                          * the address family of the socket. */
 #endif
 };
 
+#ifdef _WIN64
+#define PR_PRIdOSFD "lld"       /* for printing PROsfd */
+#define PR_PRIxOSFD "llx"
+#define PR_SCNdOSFD "lld"       /* for scanning PROsfd */
+#define PR_SCNxOSFD "llx"
+#else
+#define PR_PRIdOSFD "ld"        /* for printing PROsfd */
+#define PR_PRIxOSFD "lx"
+#define PR_SCNdOSFD "ld"        /* for scanning PROsfd */
+#define PR_SCNxOSFD "lx"
+#endif
+
 struct PRDir {
     PRDirEntry d;
     _MDDir md;
 };
 
 #ifdef MOZ_UNICODE
 struct PRDirUTF16 { 
     PRDirEntry d; 
@@ -1959,23 +1971,23 @@ extern PRIntervalTime _PR_MD_INTERVAL_PE
 extern PRInt32 _PR_MD_SETTHREADAFFINITYMASK(PRThread *thread, PRUint32 mask );
 #define _PR_MD_SETTHREADAFFINITYMASK _MD_SETTHREADAFFINITYMASK
 
 extern PRInt32 _PR_MD_GETTHREADAFFINITYMASK(PRThread *thread, PRUint32 *mask);
 #define _PR_MD_GETTHREADAFFINITYMASK _MD_GETTHREADAFFINITYMASK
 
 /* File locking */
 
-extern PRStatus _PR_MD_LOCKFILE(PRInt32 osfd);
+extern PRStatus _PR_MD_LOCKFILE(PROsfd osfd);
 #define    _PR_MD_LOCKFILE _MD_LOCKFILE
 
-extern PRStatus _PR_MD_TLOCKFILE(PRInt32 osfd);
+extern PRStatus _PR_MD_TLOCKFILE(PROsfd osfd);
 #define    _PR_MD_TLOCKFILE _MD_TLOCKFILE
 
-extern PRStatus _PR_MD_UNLOCKFILE(PRInt32 osfd);
+extern PRStatus _PR_MD_UNLOCKFILE(PROsfd osfd);
 #define    _PR_MD_UNLOCKFILE _MD_UNLOCKFILE
 
 /* Memory-mapped files */
 
 extern PRStatus _PR_MD_CREATE_FILE_MAP(PRFileMap *fmap, PRInt64 size);
 #define _PR_MD_CREATE_FILE_MAP _MD_CREATE_FILE_MAP
 
 extern PRInt32 _PR_MD_GET_MEM_MAP_ALIGNMENT(void);
--- a/pr/include/prtypes.h
+++ b/pr/include/prtypes.h
@@ -437,17 +437,21 @@ typedef PRInt64 PROffset64;
 typedef ptrdiff_t PRPtrdiff;
 
 /************************************************************************
 ** TYPES:       PRUptrdiff
 ** DESCRIPTION:
 **  A type for pointer difference. Variables of this type are suitable
 **      for storing a pointer or pointer sutraction. 
 ************************************************************************/
+#ifdef _WIN64
+typedef unsigned __int64 PRUptrdiff;
+#else
 typedef unsigned long PRUptrdiff;
+#endif
 
 /************************************************************************
 ** TYPES:       PRBool
 ** DESCRIPTION:
 **  Use PRBool for variables and parameter types. Use PR_FALSE and PR_TRUE
 **      for clarity of target type in assignments and actual arguments. Use
 **      'if (bool)', 'while (!bool)', '(bool) ? x : y' etc., to test booleans
 **      just as you would C int-valued conditions. 
@@ -490,18 +494,23 @@ typedef PRUint16 PRUnichar;
 ** use PRWord and PRUword in new code.
 **
 ** A PRWord is an integer that is the same size as a void*.
 ** It implements the notion of a "word" in the Java Virtual
 ** Machine.  (See Sec. 3.4 "Words", The Java Virtual Machine
 ** Specification, Addison-Wesley, September 1996.
 ** http://java.sun.com/docs/books/vmspec/index.html.)
 */
+#ifdef _WIN64
+typedef __int64 PRWord;
+typedef unsigned __int64 PRUword;
+#else
 typedef long PRWord;
 typedef unsigned long PRUword;
+#endif
 
 #if defined(NO_NSPR_10_SUPPORT)
 #else
 /********* ???????????????? FIX ME       ??????????????????????????? *****/
 /********************** Some old definitions until pr=>ds transition is done ***/
 /********************** Also, we are still using NSPR 1.0. GC ******************/
 /*
 ** Fundamental NSPR macros, used nearly everywhere.
--- a/pr/src/Makefile.in
+++ b/pr/src/Makefile.in
@@ -311,21 +311,23 @@ OBJS += \
 	cplus/$(OBJDIR)/rctime.$(OBJ_SUFFIX)
 endif
 
 ifdef GC_LEAK_DETECTOR
 OBJS += memory/$(OBJDIR)/prgcleak.$(OBJ_SUFFIX)
 endif
 
 ifeq ($(OS_ARCH), WINNT)
+ifndef USE_64
 ifdef NS_USE_GCC
 DLLBASE=-Wl,--image-base -Wl,0x30000000
 else
 DLLBASE=-BASE:0x30000000
 endif # GCC
+endif # !USE_64
 RES=$(OBJDIR)/nspr.res
 RESNAME=nspr.rc
 endif # WINNT
 
 include $(srcdir)/md/$(PR_MD_ARCH_DIR)/objs.mk
 ifdef USE_BTHREADS
 include $(srcdir)/bthreads/objs.mk
 endif
--- a/pr/src/io/prfile.c
+++ b/pr/src/io/prfile.c
@@ -354,17 +354,17 @@ static PRIOMethods _pr_pipeMethods = {
 
 PR_IMPLEMENT(const PRIOMethods*) PR_GetPipeMethods(void)
 {
     return &_pr_pipeMethods;
 }
 
 PR_IMPLEMENT(PRFileDesc*) PR_Open(const char *name, PRIntn flags, PRIntn mode)
 {
-    PRInt32 osfd;
+    PROsfd osfd;
     PRFileDesc *fd = 0;
 #if !defined(_PR_HAVE_O_APPEND)
     PRBool  appendMode = ( PR_APPEND & flags )? PR_TRUE : PR_FALSE;
 #endif
 
     if (!_pr_initialized) _PR_ImplicitInitialization();
 
     /* Map pr open flags and mode to os specific flags */
@@ -382,17 +382,17 @@ PR_IMPLEMENT(PRFileDesc*) PR_Open(const 
         }
     }
     return fd;
 }
 
 PR_IMPLEMENT(PRFileDesc*) PR_OpenFile(
     const char *name, PRIntn flags, PRIntn mode)
 {
-    PRInt32 osfd;
+    PROsfd osfd;
     PRFileDesc *fd = 0;
 #if !defined(_PR_HAVE_O_APPEND)
     PRBool  appendMode = ( PR_APPEND & flags )? PR_TRUE : PR_FALSE;
 #endif
 
     if (!_pr_initialized) _PR_ImplicitInitialization();
 
     /* Map pr open flags and mode to os specific flags */
@@ -553,17 +553,17 @@ PRInt32 rv;
 		return PR_FAILURE;
 	} else
 		return PR_SUCCESS;
 }
 
 /*
 ** Import an existing OS file to NSPR 
 */
-PR_IMPLEMENT(PRFileDesc*) PR_ImportFile(PRInt32 osfd)
+PR_IMPLEMENT(PRFileDesc*) PR_ImportFile(PROsfd osfd)
 {
     PRFileDesc *fd = NULL;
 
     if (!_pr_initialized) _PR_ImplicitInitialization();
 
     fd = PR_AllocFileDesc(osfd, &_pr_fileMethods);
     if( !fd ) {
         (void) _PR_MD_CLOSE_FILE(osfd);
@@ -572,17 +572,17 @@ PR_IMPLEMENT(PRFileDesc*) PR_ImportFile(
     }
 
     return fd;
 }
 
 /*
 ** Import an existing OS pipe to NSPR 
 */
-PR_IMPLEMENT(PRFileDesc*) PR_ImportPipe(PRInt32 osfd)
+PR_IMPLEMENT(PRFileDesc*) PR_ImportPipe(PROsfd osfd)
 {
     PRFileDesc *fd = NULL;
 
     if (!_pr_initialized) _PR_ImplicitInitialization();
 
     fd = PR_AllocFileDesc(osfd, &_pr_pipeMethods);
     if( !fd ) {
         (void) _PR_MD_CLOSE_FILE(osfd);
@@ -728,23 +728,23 @@ PR_IMPLEMENT(PRStatus) PR_CreatePipe(
 
     ZeroMemory(&pipeAttributes, sizeof(pipeAttributes));
     pipeAttributes.nLength = sizeof(pipeAttributes);
     pipeAttributes.bInheritHandle = TRUE;
     if (CreatePipe(&readEnd, &writeEnd, &pipeAttributes, 0) == 0) {
         PR_SetError(PR_UNKNOWN_ERROR, GetLastError());
         return PR_FAILURE;
     }
-    *readPipe = PR_AllocFileDesc((PRInt32)readEnd, &_pr_pipeMethods);
+    *readPipe = PR_AllocFileDesc((PROsfd)readEnd, &_pr_pipeMethods);
     if (NULL == *readPipe) {
         CloseHandle(readEnd);
         CloseHandle(writeEnd);
         return PR_FAILURE;
     }
-    *writePipe = PR_AllocFileDesc((PRInt32)writeEnd, &_pr_pipeMethods);
+    *writePipe = PR_AllocFileDesc((PROsfd)writeEnd, &_pr_pipeMethods);
     if (NULL == *writePipe) {
         PR_Close(*readPipe);
         CloseHandle(writeEnd);
         return PR_FAILURE;
     }
 #ifdef WINNT
     (*readPipe)->secret->md.sync_file_io = PR_TRUE;
     (*writePipe)->secret->md.sync_file_io = PR_TRUE;
@@ -797,17 +797,17 @@ PR_IMPLEMENT(PRStatus) PR_CreatePipe(
 #endif
 }
 
 #ifdef MOZ_UNICODE
 /* ================ UTF16 Interfaces ================================ */
 PR_IMPLEMENT(PRFileDesc*) PR_OpenFileUTF16(
     const PRUnichar *name, PRIntn flags, PRIntn mode)
 { 
-    PRInt32 osfd;
+    PROsfd osfd;
     PRFileDesc *fd = 0;
 #if !defined(_PR_HAVE_O_APPEND)
     PRBool  appendMode = ( PR_APPEND & flags )? PR_TRUE : PR_FALSE;
 #endif
    
     if (!_pr_initialized) _PR_ImplicitInitialization();
   
     /* Map pr open flags and mode to os specific flags */
--- a/pr/src/io/prio.c
+++ b/pr/src/io/prio.c
@@ -50,21 +50,21 @@ 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
-    _pr_stdin = PR_AllocFileDesc((PRInt32)GetStdHandle(STD_INPUT_HANDLE),
+    _pr_stdin = PR_AllocFileDesc((PROsfd)GetStdHandle(STD_INPUT_HANDLE),
             methods);
-    _pr_stdout = PR_AllocFileDesc((PRInt32)GetStdHandle(STD_OUTPUT_HANDLE),
+    _pr_stdout = PR_AllocFileDesc((PROsfd)GetStdHandle(STD_OUTPUT_HANDLE),
             methods);
-    _pr_stderr = PR_AllocFileDesc((PRInt32)GetStdHandle(STD_ERROR_HANDLE),
+    _pr_stderr = PR_AllocFileDesc((PROsfd)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
     _pr_stdin = PR_AllocFileDesc(0, methods);
@@ -113,17 +113,17 @@ PR_IMPLEMENT(PRFileDesc*) PR_GetSpecialF
         case PR_StandardError: result = _pr_stderr; break;
         default:
             (void)PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
     }
     return result;
 }
 
 PR_IMPLEMENT(PRFileDesc*) PR_AllocFileDesc(
-    PRInt32 osfd, const PRIOMethods *methods)
+    PROsfd osfd, const PRIOMethods *methods)
 {
     PRFileDesc *fd;
 
 #ifdef XP_UNIX
 	/*
 	 * Assert that the file descriptor is small enough to fit in the
 	 * fd_set passed to select
 	 */
--- a/pr/src/io/prsocket.c
+++ b/pr/src/io/prsocket.c
@@ -185,48 +185,48 @@ PRInt32 iov_size, PRIntervalTime timeout
 
 	if (iov_copy != local_iov)
 		PR_DELETE(iov_copy);
 	return count;
 }
 
 /************************************************************************/
 
-PR_IMPLEMENT(PRFileDesc *) PR_ImportTCPSocket(PRInt32 osfd)
+PR_IMPLEMENT(PRFileDesc *) PR_ImportTCPSocket(PROsfd osfd)
 {
 PRFileDesc *fd;
 
 	if (!_pr_initialized) _PR_ImplicitInitialization();
 	fd = PR_AllocFileDesc(osfd, PR_GetTCPMethods());
 	if (fd != NULL) {
 		_PR_MD_MAKE_NONBLOCK(fd);
 		_PR_MD_INIT_FD_INHERITABLE(fd, PR_TRUE);
 	} else
 		_PR_MD_CLOSE_SOCKET(osfd);
 	return(fd);
 }
 
-PR_IMPLEMENT(PRFileDesc *) PR_ImportUDPSocket(PRInt32 osfd)
+PR_IMPLEMENT(PRFileDesc *) PR_ImportUDPSocket(PROsfd osfd)
 {
 PRFileDesc *fd;
 
 	if (!_pr_initialized) _PR_ImplicitInitialization();
 	fd = PR_AllocFileDesc(osfd, PR_GetUDPMethods());
 	if (fd != NULL) {
 		_PR_MD_MAKE_NONBLOCK(fd);
 		_PR_MD_INIT_FD_INHERITABLE(fd, PR_TRUE);
 	} else
 		_PR_MD_CLOSE_SOCKET(osfd);
 	return(fd);
 }
 
 
 static const PRIOMethods* PR_GetSocketPollFdMethods(void);
 
-PR_IMPLEMENT(PRFileDesc*) PR_CreateSocketPollFd(PRInt32 osfd)
+PR_IMPLEMENT(PRFileDesc*) PR_CreateSocketPollFd(PROsfd osfd)
 {
     PRFileDesc *fd;
 
     if (!_pr_initialized) _PR_ImplicitInitialization();
 
     fd = _PR_Getfd();
 
     if (fd == NULL) PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
@@ -282,17 +282,17 @@ static PRStatus PR_CALLBACK SocketConnec
 		return PR_SUCCESS;
 	else
 		return PR_FAILURE;
 }
 
 static PRStatus PR_CALLBACK SocketConnectContinue(
     PRFileDesc *fd, PRInt16 out_flags)
 {
-    PRInt32 osfd;
+    PROsfd osfd;
     int err;
 
     if (out_flags & PR_POLL_NVAL) {
         PR_SetError(PR_BAD_DESCRIPTOR_ERROR, 0);
         return PR_FAILURE;
     }
     if ((out_flags & (PR_POLL_WRITE | PR_POLL_EXCEPT | PR_POLL_ERR)) == 0) {
         PR_ASSERT(out_flags == 0);
@@ -392,17 +392,17 @@ PR_IMPLEMENT(PRStatus) PR_GetConnectStat
         return PR_FAILURE;
     }
     return SocketConnectContinue(bottom, pd->out_flags);
 }
 
 static PRFileDesc* PR_CALLBACK SocketAccept(PRFileDesc *fd, PRNetAddr *addr,
 PRIntervalTime timeout)
 {
-	PRInt32 osfd;
+	PROsfd osfd;
 	PRFileDesc *fd2;
 	PRUint32 al;
 	PRThread *me = _PR_MD_CURRENT_THREAD();
 #ifdef WINNT
 	PRNetAddr addrCopy;
 #endif
 
 	if (_PR_PENDING_INTERRUPT(me)) {
@@ -471,17 +471,17 @@ PRIntervalTime timeout)
 
 	return fd2;
 }
 
 #ifdef WINNT
 PR_IMPLEMENT(PRFileDesc*) PR_NTFast_Accept(PRFileDesc *fd, PRNetAddr *addr,
 PRIntervalTime timeout)
 {
-	PRInt32 osfd;
+	PROsfd osfd;
 	PRFileDesc *fd2;
 	PRIntn al;
 	PRThread *me = _PR_MD_CURRENT_THREAD();
 	PRNetAddr addrCopy;
 
 	if (_PR_PENDING_INTERRUPT(me)) {
 		me->flags &= ~_PR_INTERRUPT;
 		PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
@@ -591,18 +591,19 @@ PRIntervalTime timeout)
 		PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
 		return -1;
 	}
 	if (_PR_IO_PENDING(me)) {
 		PR_SetError(PR_IO_PENDING_ERROR, 0);
 		return -1;
 	}
 
-	PR_LOG(_pr_io_lm, PR_LOG_MAX, ("recv: fd=%p osfd=%d buf=%p amount=%d flags=%d",
-		    						fd, fd->secret->md.osfd, buf, amount, flags));
+	PR_LOG(_pr_io_lm, PR_LOG_MAX,
+		("recv: fd=%p osfd=%" PR_PRIdOSFD " buf=%p amount=%d flags=%d",
+		fd, fd->secret->md.osfd, buf, amount, flags));
 
 #ifdef _PR_HAVE_PEEK_BUFFER
 	if (fd->secret->peekBytes != 0) {
 		rv = (amount < fd->secret->peekBytes) ?
 			amount : fd->secret->peekBytes;
 		memcpy(buf, fd->secret->peekBuffer, rv);
 		if (flags == 0) {
 			/* consume the bytes in the peek buffer */
@@ -673,17 +674,17 @@ PRIntn flags, PRIntervalTime timeout)
 	if (_PR_IO_PENDING(me)) {
 		PR_SetError(PR_IO_PENDING_ERROR, 0);
 		return -1;
 	}
 
 	count = 0;
 	while (amount > 0) {
 		PR_LOG(_pr_io_lm, PR_LOG_MAX,
-		    ("send: fd=%p osfd=%d buf=%p amount=%d",
+		    ("send: fd=%p osfd=%" PR_PRIdOSFD " buf=%p amount=%d",
 		    fd, fd->secret->md.osfd, buf, amount));
 		temp = _PR_MD_SEND(fd, buf, amount, flags, timeout);
 		if (temp < 0) {
 					count = -1;
 					break;
 				}
 
 		count += temp;
@@ -860,17 +861,17 @@ PRIntervalTime timeout)
 	if (sd->secret->nonblocking) {
 		PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
 		return -1;
 	}
 	*nd = NULL;
 
 #if defined(WINNT)
 	{
-	PRInt32 newSock;
+	PROsfd newSock;
 	PRNetAddr *raddrCopy;
 
 	if (raddr == NULL) {
 		raddr = &raddrCopy;
 	}
 	rv = _PR_MD_ACCEPT_READ(sd, &newSock, raddr, buf, amount, timeout);
 	if (rv < 0) {
 		rv = -1;
@@ -900,17 +901,17 @@ PRIntervalTime timeout)
 }
 
 #ifdef WINNT
 PR_IMPLEMENT(PRInt32) PR_NTFast_AcceptRead(PRFileDesc *sd, PRFileDesc **nd, 
 PRNetAddr **raddr, void *buf, PRInt32 amount,
 PRIntervalTime timeout)
 {
 	PRInt32 rv;
-	PRInt32 newSock;
+	PROsfd newSock;
 	PRThread *me = _PR_MD_CURRENT_THREAD();
 	PRNetAddr *raddrCopy;
 
 	if (_PR_PENDING_INTERRUPT(me)) {
 		me->flags &= ~_PR_INTERRUPT;
 		PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
 		return -1;
 	}
@@ -951,17 +952,17 @@ PRIntervalTime timeout)
 PR_IMPLEMENT(PRInt32) PR_NTFast_AcceptRead_WithTimeoutCallback(
 PRFileDesc *sd, PRFileDesc **nd, 
 PRNetAddr **raddr, void *buf, PRInt32 amount,
 PRIntervalTime timeout,
 _PR_AcceptTimeoutCallback callback,
 void *callbackArg)
 {
 	PRInt32 rv;
-	PRInt32 newSock;
+	PROsfd newSock;
 	PRThread *me = _PR_MD_CURRENT_THREAD();
 	PRNetAddr *raddrCopy;
 
 	if (_PR_PENDING_INTERRUPT(me)) {
 		me->flags &= ~_PR_INTERRUPT;
 		PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
 		return -1;
 	}
@@ -1249,32 +1250,32 @@ static const PRIOMethods* PR_GetSocketPo
 PR_EXTERN(PRStatus) _pr_push_ipv6toipv4_layer(PRFileDesc *fd);
 
 #if defined(_PR_INET6_PROBE)
 
 PR_EXTERN(PRBool) _pr_ipv6_is_present;
 
 PR_IMPLEMENT(PRBool) _pr_test_ipv6_socket()
 {
-PRInt32 osfd;
+	PROsfd osfd;
 
 	osfd = _PR_MD_SOCKET(AF_INET6, SOCK_STREAM, 0);
 	if (osfd != -1) {
 		_PR_MD_CLOSE_SOCKET(osfd);
 		return PR_TRUE;
 	}
 	return PR_FALSE;
 }
 #endif	/* _PR_INET6_PROBE */
 
 #endif
 
 PR_IMPLEMENT(PRFileDesc*) PR_Socket(PRInt32 domain, PRInt32 type, PRInt32 proto)
 {
-	PRInt32 osfd;
+	PROsfd osfd;
 	PRFileDesc *fd;
 	PRInt32 tmp_domain = domain;
 
 	if (!_pr_initialized) _PR_ImplicitInitialization();
 	if (PR_AF_INET != domain
 			&& PR_AF_INET6 != domain
 #if defined(XP_UNIX) || defined(XP_OS2_EMX)
 			&& PR_AF_LOCAL != domain
@@ -1574,31 +1575,31 @@ failed:
     }
     if (f[1]) {
         PR_Close(f[1]);
     }
     return PR_FAILURE;
 #endif
 }
 
-PR_IMPLEMENT(PRInt32)
+PR_IMPLEMENT(PROsfd)
 PR_FileDesc2NativeHandle(PRFileDesc *fd)
 {
     if (fd) {
         fd = PR_GetIdentitiesLayer(fd, PR_NSPR_IO_LAYER);
     }
     if (!fd) {
         PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
         return -1;
     }
     return fd->secret->md.osfd;
 }
 
 PR_IMPLEMENT(void)
-PR_ChangeFileDescNativeHandle(PRFileDesc *fd, PRInt32 handle)
+PR_ChangeFileDescNativeHandle(PRFileDesc *fd, PROsfd handle)
 {
 	if (fd)
 		fd->secret->md.osfd = handle;
 }
 
 /*
 ** Select compatibility
 **
@@ -1635,38 +1636,38 @@ PR_IMPLEMENT(PRInt32) PR_FD_ISSET(PRFile
 	PRUint32 index;
 	for (index = 0; index<set->hsize; index++)
 		if (set->harray[index] == fh) {
 			return 1;
 		}
 	return 0;
 }
 
-PR_IMPLEMENT(void) PR_FD_NSET(PRInt32 fd, PR_fd_set *set)
+PR_IMPLEMENT(void) PR_FD_NSET(PROsfd fd, PR_fd_set *set)
 {
 	PR_ASSERT( set->nsize < PR_MAX_SELECT_DESC );
 
 	set->narray[set->nsize++] = fd;
 }
 
-PR_IMPLEMENT(void) PR_FD_NCLR(PRInt32 fd, PR_fd_set *set)
+PR_IMPLEMENT(void) PR_FD_NCLR(PROsfd fd, PR_fd_set *set)
 {
 	PRUint32 index, index2;
 
 	for (index = 0; index<set->nsize; index++)
 		if (set->narray[index] == fd) {
 			for (index2=index; index2 < (set->nsize-1); index2++) {
 				set->narray[index2] = set->narray[index2+1];
 			}
 			set->nsize--;
 			break;
 		}
 }
 
-PR_IMPLEMENT(PRInt32) PR_FD_NISSET(PRInt32 fd, PR_fd_set *set)
+PR_IMPLEMENT(PRInt32) PR_FD_NISSET(PROsfd fd, PR_fd_set *set)
 {
 	PRUint32 index;
 	for (index = 0; index<set->nsize; index++)
 		if (set->narray[index] == fd) {
 			return 1;
 		}
 	return 0;
 }
--- a/pr/src/md/windows/ntgc.c
+++ b/pr/src/md/windows/ntgc.c
@@ -91,17 +91,19 @@ PRWord *_MD_HomeGCRegisters(PRThread *t,
         t->md.gcContext[4] = fiberData[0x2d];  /* context.Esi */
         t->md.gcContext[5] = fiberData[0x2c];  /* context.Edi */
         t->md.gcContext[6] = fiberData[0x36];  /* context.Esp */
         t->md.gcContext[7] = fiberData[0x32];  /* context.Ebp */
         *np = PR_NUM_GCREGS;
 #endif
     }
     return (PRWord *)&t->md.gcContext;
-#elif defined(_ALPHA_)
+#else
+    PR_NOT_REACHED("not implemented");
+    return NULL;
 #endif /* defined(_X86_) */
 }
 
 /* This function is not used right now, but is left as a reference.
  * If you ever need to get the fiberID from the currently running fiber, 
  * this is it.
  */
 void *
@@ -116,11 +118,13 @@ GetMyFiberID()
      */
     __asm {
         mov    EDX, FS:[18h]
         mov    EAX, DWORD PTR [EDX+10h]
         mov    [fiberData], EAX
     }
   
     return fiberData;
-#elif defined(_ALPHA_)
+#else
+    PR_NOT_REACHED("not implemented");
+    return NULL;
 #endif /* defined(_X86_) */
 }
--- a/pr/src/md/windows/ntio.c
+++ b/pr/src/md/windows/ntio.c
@@ -113,17 +113,17 @@ static const PRTime _pr_filetime_offset 
 #define _PR_LOCAL_FILE 1
 #define _PR_REMOTE_FILE 2
 PRBool IsFileLocalInit();
 PRInt32 IsFileLocal(HANDLE hFile);
 #endif /* _NEED_351_FILE_LOCKING_HACK */
 
 static PRInt32 _md_MakeNonblock(HANDLE);
 
-static PRInt32 _nt_nonblock_accept(PRFileDesc *fd, struct sockaddr *addr, int *addrlen, PRIntervalTime);
+static PROsfd _nt_nonblock_accept(PRFileDesc *fd, struct sockaddr *addr, int *addrlen, PRIntervalTime);
 static PRInt32 _nt_nonblock_connect(PRFileDesc *fd, struct sockaddr *addr, int addrlen, PRIntervalTime);
 static PRInt32 _nt_nonblock_recv(PRFileDesc *fd, char *buf, int len, int flags, PRIntervalTime);
 static PRInt32 _nt_nonblock_send(PRFileDesc *fd, char *buf, int len, PRIntervalTime);
 static PRInt32 _nt_nonblock_writev(PRFileDesc *fd, const PRIOVec *iov, int size, PRIntervalTime);
 static PRInt32 _nt_nonblock_sendto(PRFileDesc *, const char *, int, const struct sockaddr *, int, PRIntervalTime);
 static PRInt32 _nt_nonblock_recvfrom(PRFileDesc *, char *, int, struct sockaddr *, int *, PRIntervalTime);
 
 /*
@@ -1040,17 +1040,17 @@ static PRInt32
     /* XXX should map error codes on failures */
     return (rv == 0);
 }
 
 static int missing_completions = 0;
 static int max_wait_loops = 0;
 
 static PRInt32
-_NT_IO_ABORT(PRInt32 sock)
+_NT_IO_ABORT(PROsfd sock)
 {
     PRThread *me = _PR_MD_CURRENT_THREAD();
     PRBool fWait;
     PRInt32 rv;
     int loop_count;
 
     /* This is a clumsy way to abort the IO, but it is all we can do.
      * It looks a bit racy, but we handle all the cases. 
@@ -1131,34 +1131,34 @@ static PRInt32
     PR_ASSERT(me->io_pending == PR_FALSE);
     me->md.thr_bound_cpu = NULL;
     me->io_suspended = PR_FALSE;
 
     return rv;
 }
 
 
-PRInt32
+PROsfd
 _PR_MD_SOCKET(int af, int type, int flags)
 {
     SOCKET sock;
 
     sock = socket(af, type, flags);
 
     if (sock == INVALID_SOCKET) {
         _PR_MD_MAP_SOCKET_ERROR(WSAGetLastError());
     }
 
-    return (PRInt32)sock;
+    return (PROsfd)sock;
 }
 
 struct connect_data_s {
     PRInt32 status;
     PRInt32 error;
-    PRInt32 osfd;
+    PROsfd  osfd;
     struct sockaddr *addr;
     PRUint32 addrlen;
     PRIntervalTime timeout;
 };
 
 void
 _PR_MD_connect_thread(void *cdata)
 {
@@ -1172,17 +1172,17 @@ void
     return;
 }
 
 
 PRInt32
 _PR_MD_CONNECT(PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen, 
                PRIntervalTime timeout)
 {
-    PRInt32 osfd = fd->secret->md.osfd;
+    PROsfd osfd = fd->secret->md.osfd;
     PRInt32 rv, err;
     u_long nbio;
     PRInt32 rc;
 
     if (fd->secret->nonblocking) {
         if (!fd->secret->md.io_model_committed) {
             rv = _md_MakeNonblock((HANDLE)osfd);
             PR_ASSERT(0 != rv);
@@ -1240,17 +1240,17 @@ PRInt32
                     (const char *)&one,
                     sizeof(one));
     PR_ASSERT(rv == 0);
 #endif
 
     return 0;
 }
 
-void _PR_MD_UPDATE_ACCEPT_CONTEXT(PRInt32 accept_sock, PRInt32 listen_sock)
+void _PR_MD_UPDATE_ACCEPT_CONTEXT(PROsfd accept_sock, PROsfd listen_sock)
 {
     /* Sockets accept()'d with AcceptEx need to call this setsockopt before
      * calling anything other than ReadFile(), WriteFile(), send(), recv(), 
      * Transmitfile(), and closesocket().  In order to call any other 
      * winsock functions, we have to make this setsockopt call.
      *
      * XXXMB - For the server, we *NEVER* need this in
      * the "normal" code path.  But now we have to call it.  This is a waste
@@ -1263,22 +1263,22 @@ void _PR_MD_UPDATE_ACCEPT_CONTEXT(PRInt3
                SOL_SOCKET, 
                SO_UPDATE_ACCEPT_CONTEXT,
                (char *)&listen_sock,
                sizeof(listen_sock));
 
 }
 
 #define INET_ADDR_PADDED (sizeof(PRNetAddr) + 16)
-PRInt32
+PROsfd
 _PR_MD_FAST_ACCEPT(PRFileDesc *fd, PRNetAddr *raddr, PRUint32 *rlen,
               PRIntervalTime timeout, PRBool fast, 
               _PR_AcceptTimeoutCallback callback, void *callbackArg)
 {
-    PRInt32 osfd = fd->secret->md.osfd;
+    PROsfd osfd = fd->secret->md.osfd;
     PRThread *me = _PR_MD_CURRENT_THREAD();
     SOCKET accept_sock;
     int bytes;
     PRNetAddr *Laddr;
     PRNetAddr *Raddr;
     PRUint32 llen, err;
     int rv;
 
@@ -1415,22 +1415,22 @@ PRInt32
         memcpy((char *)raddr, (char *)&Raddr->inet, *rlen);
 
     PR_ASSERT(me->io_pending == PR_FALSE);
 
     return accept_sock;
 }
 
 PRInt32
-_PR_MD_FAST_ACCEPT_READ(PRFileDesc *sd, PRInt32 *newSock, PRNetAddr **raddr, 
+_PR_MD_FAST_ACCEPT_READ(PRFileDesc *sd, PROsfd *newSock, PRNetAddr **raddr, 
                    void *buf, PRInt32 amount, PRIntervalTime timeout, 
                    PRBool fast, _PR_AcceptTimeoutCallback callback, 
                    void *callbackArg)
 {
-    PRInt32 sock = sd->secret->md.osfd;
+    PROsfd sock = sd->secret->md.osfd;
     PRThread *me = _PR_MD_CURRENT_THREAD();
     int bytes;
     PRNetAddr *Laddr;
     PRUint32 llen, rlen, err;
     int rv;
     PRBool isConnected;
     PRBool madeCallback = PR_FALSE;
 
@@ -1702,17 +1702,17 @@ PRInt32
 
     return me->md.blocked_io_bytes;
 }
 
 PRInt32
 _PR_MD_RECV(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags, 
             PRIntervalTime timeout)
 {
-    PRInt32 osfd = fd->secret->md.osfd;
+    PROsfd osfd = fd->secret->md.osfd;
     PRThread *me = _PR_MD_CURRENT_THREAD();
     int bytes;
     int rv, err;
 
     if (_NT_USE_NB_IO(fd)) {
         if (!fd->secret->md.io_model_committed) {
             rv = _md_MakeNonblock((HANDLE)osfd);
             PR_ASSERT(0 != rv);
@@ -1801,17 +1801,17 @@ PRInt32
 
     return me->md.blocked_io_bytes;
 }
 
 PRInt32
 _PR_MD_SEND(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
             PRIntervalTime timeout)
 {
-    PRInt32 osfd = fd->secret->md.osfd;
+    PROsfd osfd = fd->secret->md.osfd;
     PRThread *me = _PR_MD_CURRENT_THREAD();
     int bytes;
     int rv, err;
 
     if (_NT_USE_NB_IO(fd)) {
         if (!fd->secret->md.io_model_committed) {
             rv = _md_MakeNonblock((HANDLE)osfd);
             PR_ASSERT(0 != rv);
@@ -1896,17 +1896,17 @@ PRInt32
 
     return me->md.blocked_io_bytes;
 }
 
 PRInt32
 _PR_MD_SENDTO(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
               const PRNetAddr *addr, PRUint32 addrlen, PRIntervalTime timeout)
 {
-    PRInt32 osfd = fd->secret->md.osfd;
+    PROsfd osfd = fd->secret->md.osfd;
     PRInt32 rv;
 
     if (!fd->secret->md.io_model_committed) {
         rv = _md_MakeNonblock((HANDLE)osfd);
         PR_ASSERT(0 != rv);
         fd->secret->md.io_model_committed = PR_TRUE;
     }
     if (_NT_USE_NB_IO(fd))
@@ -1914,17 +1914,17 @@ PRInt32
     else
         return pt_SendTo(osfd, buf, amount, flags, addr, addrlen, timeout);
 }
 
 PRInt32
 _PR_MD_RECVFROM(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags,
                 PRNetAddr *addr, PRUint32 *addrlen, PRIntervalTime timeout)
 {
-    PRInt32 osfd = fd->secret->md.osfd;
+    PROsfd osfd = fd->secret->md.osfd;
     PRInt32 rv;
 
     if (!fd->secret->md.io_model_committed) {
         rv = _md_MakeNonblock((HANDLE)osfd);
         PR_ASSERT(0 != rv);
         fd->secret->md.io_model_committed = PR_TRUE;
     }
     if (_NT_USE_NB_IO(fd))
@@ -1932,17 +1932,17 @@ PRInt32
     else
         return pt_RecvFrom(osfd, buf, amount, flags, addr, addrlen, timeout);
 }
 
 /* XXXMB - for now this is a sockets call only */
 PRInt32
 _PR_MD_WRITEV(PRFileDesc *fd, const PRIOVec *iov, PRInt32 iov_size, PRIntervalTime timeout)
 {
-    PRInt32 osfd = fd->secret->md.osfd;
+    PROsfd osfd = fd->secret->md.osfd;
     int index;
     int sent = 0;
     int rv;
 
     if (_NT_USE_NB_IO(fd)) {
         if (!fd->secret->md.io_model_committed) {
             rv = _md_MakeNonblock((HANDLE)osfd);
             PR_ASSERT(0 != rv);
@@ -2077,17 +2077,17 @@ PRStatus
 	else {
 		_PR_MD_MAP_SETSOCKOPT_ERROR(WSAGetLastError());
 		return PR_FAILURE;
 	}
 }
 
 /* --- FILE IO ----------------------------------------------------------- */
 
-PRInt32
+PROsfd
 _PR_MD_OPEN(const char *name, PRIntn osflags, PRIntn mode)
 {
     HANDLE file;
     PRInt32 access = 0;
     PRInt32 flags = 0;
     PRInt32 flag6 = 0;
     
     if (osflags & PR_SYNC) flag6 = FILE_FLAG_WRITE_THROUGH;
@@ -2120,20 +2120,20 @@ PRInt32
     if (osflags & PR_APPEND) {
         if ( SetFilePointer(file, 0, 0, FILE_END) == 0xFFFFFFFF ) {
             _PR_MD_MAP_LSEEK_ERROR(GetLastError());
             CloseHandle(file);
             return -1;
         }
     }
 
-    return (PRInt32)file;
+    return (PROsfd)file;
 }
 
-PRInt32
+PROsfd
 _PR_MD_OPEN_FILE(const char *name, PRIntn osflags, PRIntn mode)
 {
     HANDLE file;
     PRInt32 access = 0;
     PRInt32 flags = 0;
     PRInt32 flag6 = 0;
     SECURITY_ATTRIBUTES sa;
     LPSECURITY_ATTRIBUTES lpSA = NULL;
@@ -2182,23 +2182,23 @@ PRInt32
     if (osflags & PR_APPEND) {
         if ( SetFilePointer(file, 0, 0, FILE_END) == 0xFFFFFFFF ) {
             _PR_MD_MAP_LSEEK_ERROR(GetLastError());
             CloseHandle(file);
             return -1;
         }
     }
 
-    return (PRInt32)file;
+    return (PROsfd)file;
 }
 
 PRInt32 
 _PR_MD_READ(PRFileDesc *fd, void *buf, PRInt32 len)
 {
-    PRInt32 f = fd->secret->md.osfd;
+    PROsfd f = fd->secret->md.osfd;
     PRUint32 bytes;
     int rv, err;
     LONG hiOffset = 0;
     LONG loOffset;
 
     if (!fd->secret->md.sync_file_io) {
         PRThread *me = _PR_MD_CURRENT_THREAD();
 
@@ -2339,17 +2339,17 @@ PRInt32
         }
         return bytes;
     }
 }
 
 PRInt32
 _PR_MD_WRITE(PRFileDesc *fd, const void *buf, PRInt32 len)
 {
-    PRInt32 f = fd->secret->md.osfd;
+    PROsfd f = fd->secret->md.osfd;
     PRInt32 bytes;
     int rv, err;
     LONG hiOffset = 0;
     LONG loOffset;
     LARGE_INTEGER offset; /* use for the calculation of the new offset */
 
     if (!fd->secret->md.sync_file_io) {
         PRThread *me = _PR_MD_CURRENT_THREAD();
@@ -2608,17 +2608,17 @@ PRInt32
 			_PR_MD_MAP_FSYNC_ERROR(err);
 	    return -1;
 	}
     }
     return 0;
 }
 
 PRInt32
-_PR_MD_CLOSE(PRInt32 osfd, PRBool socket)
+_PR_MD_CLOSE(PROsfd osfd, PRBool socket)
 {
     PRInt32 rv;
     PRThread *me = _PR_MD_CURRENT_THREAD();
 
     if (socket)  {
         rv = closesocket((SOCKET)osfd);
         if (rv < 0)
             _PR_MD_MAP_CLOSE_ERROR(WSAGetLastError());
@@ -3263,17 +3263,17 @@ PRInt32
         return 0;
     } else {
         _PR_MD_MAP_RMDIR_ERROR(GetLastError());
         return -1;
     }
 }
 
 PRStatus
-_PR_MD_LOCKFILE(PRInt32 f)
+_PR_MD_LOCKFILE(PROsfd f)
 {
     PRInt32 rv, err;
     PRThread *me = _PR_MD_CURRENT_THREAD();
 
     if (me->io_suspended) {
         PR_SetError(PR_INVALID_STATE_ERROR, 0);
         return PR_FAILURE;
     }
@@ -3382,17 +3382,17 @@ PRStatus
 		_PR_MD_MAP_LOCKF_ERROR(me->md.blocked_io_error);
         return PR_FAILURE;
     }
 
     return PR_SUCCESS;
 }
 
 PRStatus
-_PR_MD_TLOCKFILE(PRInt32 f)
+_PR_MD_TLOCKFILE(PROsfd f)
 {
     PRInt32 rv, err;
     PRThread *me = _PR_MD_CURRENT_THREAD();
 
     if (me->io_suspended) {
         PR_SetError(PR_INVALID_STATE_ERROR, 0);
         return PR_FAILURE;
     }
@@ -3495,17 +3495,17 @@ PRStatus
         return PR_FAILURE;
     }
 
     return PR_SUCCESS;
 }
 
 
 PRStatus
-_PR_MD_UNLOCKFILE(PRInt32 f)
+_PR_MD_UNLOCKFILE(PROsfd f)
 {
     PRInt32 rv;
     PRThread *me = _PR_MD_CURRENT_THREAD();
 
     if (me->io_suspended) {
         PR_SetError(PR_INVALID_STATE_ERROR, 0);
         return PR_FAILURE;
     }
@@ -3787,78 +3787,78 @@ PR_IMPLEMENT(PRStatus) PR_NT_CancelIo(PR
 	me->md.thr_bound_cpu = NULL;
     me->io_suspended = PR_FALSE;
     me->io_pending = PR_FALSE;
 	me->state = _PR_RUNNING;
 	_PR_THREAD_UNLOCK(me);
 	return PR_SUCCESS;
 }
 
-static PRInt32 _nt_nonblock_accept(PRFileDesc *fd, struct sockaddr *addr, int *addrlen, PRIntervalTime timeout)
+static PROsfd _nt_nonblock_accept(PRFileDesc *fd, struct sockaddr *addr, int *addrlen, PRIntervalTime timeout)
 {
-    PRInt32 osfd = fd->secret->md.osfd;
+    PROsfd osfd = fd->secret->md.osfd;
+    SOCKET sock;
     PRInt32 rv, err;
     fd_set rd;
     struct timeval tv, *tvp;
 
     FD_ZERO(&rd);
     FD_SET((SOCKET)osfd, &rd);
     if (timeout == PR_INTERVAL_NO_TIMEOUT) {
-        while ((rv = accept(osfd, addr, addrlen)) == -1) {
+        while ((sock = accept(osfd, addr, addrlen)) == -1) {
             if (((err = WSAGetLastError()) == WSAEWOULDBLOCK)
                     && (!fd->secret->nonblocking)) {
-                if ((rv = _PR_NTFiberSafeSelect(osfd + 1, &rd, NULL, NULL,
+                if ((rv = _PR_NTFiberSafeSelect(0, &rd, NULL, NULL,
                         NULL)) == -1) {
                     _PR_MD_MAP_SELECT_ERROR(WSAGetLastError());
                     break;
                 }
             } else {
                 _PR_MD_MAP_ACCEPT_ERROR(err);
                 break;
             }
         }
     } else if (timeout == PR_INTERVAL_NO_WAIT) {
-        if ((rv = accept(osfd, addr, addrlen)) == -1) {
+        if ((sock = accept(osfd, addr, addrlen)) == -1) {
             if (((err = WSAGetLastError()) == WSAEWOULDBLOCK)
                     && (!fd->secret->nonblocking)) {
                 PR_SetError(PR_IO_TIMEOUT_ERROR, 0);
             } else {
                 _PR_MD_MAP_ACCEPT_ERROR(err);
             }
         }
     } else {
 retry:
-        if ((rv = accept(osfd, addr, addrlen)) == -1) {
+        if ((sock = accept(osfd, addr, addrlen)) == -1) {
             if (((err = WSAGetLastError()) == WSAEWOULDBLOCK)
                     && (!fd->secret->nonblocking)) {
                 tv.tv_sec = PR_IntervalToSeconds(timeout);
                 tv.tv_usec = PR_IntervalToMicroseconds(
                     timeout - PR_SecondsToInterval(tv.tv_sec));
                 tvp = &tv;
 
-                rv = _PR_NTFiberSafeSelect(osfd + 1, &rd, NULL, NULL, tvp);
+                rv = _PR_NTFiberSafeSelect(0, &rd, NULL, NULL, tvp);
                 if (rv > 0) {
                     goto retry;
                 } else if (rv == 0) {
                     PR_SetError(PR_IO_TIMEOUT_ERROR, 0);
-                    rv = -1;
                 } else {
                     _PR_MD_MAP_SELECT_ERROR(WSAGetLastError());
                 }
             } else {
                 _PR_MD_MAP_ACCEPT_ERROR(err);
             }
         }
     }
-    return(rv);
+    return (PROsfd)sock;
 }
 
 static PRInt32 _nt_nonblock_connect(PRFileDesc *fd, struct sockaddr *addr, int addrlen, PRIntervalTime timeout)
 {
-    PRInt32 osfd = fd->secret->md.osfd;
+    PROsfd osfd = fd->secret->md.osfd;
     PRInt32 rv;
     int err;
     fd_set wr, ex;
     struct timeval tv, *tvp;
     int len;
 
     if ((rv = connect(osfd, addr, addrlen)) == -1) {
         if ((err = WSAGetLastError()) == WSAEWOULDBLOCK) {
@@ -3869,17 +3869,17 @@ static PRInt32 _nt_nonblock_connect(PRFi
                 tv.tv_usec = PR_IntervalToMicroseconds(
                     timeout - PR_SecondsToInterval(tv.tv_sec));
                 tvp = &tv;
             }
             FD_ZERO(&wr);
             FD_ZERO(&ex);
             FD_SET((SOCKET)osfd, &wr);
             FD_SET((SOCKET)osfd, &ex);
-            if ((rv = _PR_NTFiberSafeSelect(osfd + 1, NULL, &wr, &ex,
+            if ((rv = _PR_NTFiberSafeSelect(0, NULL, &wr, &ex,
                     tvp)) == -1) {
                 _PR_MD_MAP_SELECT_ERROR(WSAGetLastError());
                 return rv;
             }
             if (rv == 0) {
                 PR_SetError(PR_IO_TIMEOUT_ERROR, 0);
                 return -1;
             }
@@ -3901,17 +3901,17 @@ static PRInt32 _nt_nonblock_connect(PRFi
             _PR_MD_MAP_CONNECT_ERROR(err);
         }
     }
     return rv;
 }
 
 static PRInt32 _nt_nonblock_recv(PRFileDesc *fd, char *buf, int len, int flags, PRIntervalTime timeout)
 {
-    PRInt32 osfd = fd->secret->md.osfd;
+    PROsfd osfd = fd->secret->md.osfd;
     PRInt32 rv, err;
     struct timeval tv, *tvp;
     fd_set rd;
     int osflags;
 
     if (0 == flags) {
         osflags = 0;
     } else {
@@ -3926,17 +3926,17 @@ static PRInt32 _nt_nonblock_recv(PRFileD
             if (timeout == PR_INTERVAL_NO_TIMEOUT) {
                 tvp = NULL;
             } else {
                 tv.tv_sec = PR_IntervalToSeconds(timeout);
                 tv.tv_usec = PR_IntervalToMicroseconds(
                 timeout - PR_SecondsToInterval(tv.tv_sec));
                 tvp = &tv;
             }
-            if ((rv = _PR_NTFiberSafeSelect(osfd + 1, &rd, NULL, NULL,
+            if ((rv = _PR_NTFiberSafeSelect(0, &rd, NULL, NULL,
                     tvp)) == -1) {
                 _PR_MD_MAP_SELECT_ERROR(WSAGetLastError());
                 break;
             } else if (rv == 0) {
                 PR_SetError(PR_IO_TIMEOUT_ERROR, 0);
                 rv = -1;
                 break;
             }
@@ -3945,17 +3945,17 @@ static PRInt32 _nt_nonblock_recv(PRFileD
             break;
         }
     }
     return(rv);
 }
 
 static PRInt32 _nt_nonblock_send(PRFileDesc *fd, char *buf, int len, PRIntervalTime timeout)
 {
-    PRInt32 osfd = fd->secret->md.osfd;
+    PROsfd osfd = fd->secret->md.osfd;
     PRInt32 rv, err;
     struct timeval tv, *tvp;
     fd_set wd;
     PRInt32 bytesSent = 0;
 
     while(bytesSent < len) {
         while ((rv = send(osfd,buf,len,0)) == -1) {
             if (((err = WSAGetLastError()) == WSAEWOULDBLOCK)
@@ -3965,17 +3965,17 @@ static PRInt32 _nt_nonblock_send(PRFileD
                 } else {
                     tv.tv_sec = PR_IntervalToSeconds(timeout);
                     tv.tv_usec = PR_IntervalToMicroseconds(
                         timeout - PR_SecondsToInterval(tv.tv_sec));
                     tvp = &tv;
                 }
                 FD_ZERO(&wd);
                 FD_SET((SOCKET)osfd, &wd);
-                if ((rv = _PR_NTFiberSafeSelect(osfd + 1, NULL, &wd, NULL,
+                if ((rv = _PR_NTFiberSafeSelect(0, NULL, &wd, NULL,
                         tvp)) == -1) {
                     _PR_MD_MAP_SELECT_ERROR(WSAGetLastError());
                     return -1;
                 }
                 if (rv == 0) {
                     PR_SetError(PR_IO_TIMEOUT_ERROR, 0);
                     return -1;
                 }
@@ -3994,17 +3994,17 @@ static PRInt32 _nt_nonblock_send(PRFileD
             } else {
                 tv.tv_sec = PR_IntervalToSeconds(timeout);
                 tv.tv_usec = PR_IntervalToMicroseconds(
                     timeout - PR_SecondsToInterval(tv.tv_sec));
                 tvp = &tv;
             }
             FD_ZERO(&wd);
             FD_SET((SOCKET)osfd, &wd);
-            if ((rv = _PR_NTFiberSafeSelect(osfd + 1, NULL, &wd, NULL,
+            if ((rv = _PR_NTFiberSafeSelect(0, NULL, &wd, NULL,
                     tvp)) == -1) {
                 _PR_MD_MAP_SELECT_ERROR(WSAGetLastError());
                 return -1;
             }
             if (rv == 0) {
                 PR_SetError(PR_IO_TIMEOUT_ERROR, 0);
                 return -1;
             }
@@ -4041,17 +4041,17 @@ static PRInt32 _nt_nonblock_writev(PRFil
 
     return sent;
 }
 
 static PRInt32 _nt_nonblock_sendto(
     PRFileDesc *fd, const char *buf, int len,
     const struct sockaddr *addr, int addrlen, PRIntervalTime timeout)
 {
-    PRInt32 osfd = fd->secret->md.osfd;
+    PROsfd osfd = fd->secret->md.osfd;
     PRInt32 rv, err;
     struct timeval tv, *tvp;
     fd_set wd;
     PRInt32 bytesSent = 0;
 
     while(bytesSent < len) {
         while ((rv = sendto(osfd,buf,len,0, addr, addrlen)) == -1) {
             if (((err = WSAGetLastError()) == WSAEWOULDBLOCK)
@@ -4061,17 +4061,17 @@ static PRInt32 _nt_nonblock_sendto(
                 } else {
                     tv.tv_sec = PR_IntervalToSeconds(timeout);
                     tv.tv_usec = PR_IntervalToMicroseconds(
                         timeout - PR_SecondsToInterval(tv.tv_sec));
                     tvp = &tv;
                 }
                 FD_ZERO(&wd);
                 FD_SET((SOCKET)osfd, &wd);
-                if ((rv = _PR_NTFiberSafeSelect(osfd + 1, NULL, &wd, NULL,
+                if ((rv = _PR_NTFiberSafeSelect(0, NULL, &wd, NULL,
                         tvp)) == -1) {
                     _PR_MD_MAP_SELECT_ERROR(WSAGetLastError());
                     return -1;
                 }
                 if (rv == 0) {
                     PR_SetError(PR_IO_TIMEOUT_ERROR, 0);
                     return -1;
                 }
@@ -4090,33 +4090,33 @@ static PRInt32 _nt_nonblock_sendto(
             } else {
                 tv.tv_sec = PR_IntervalToSeconds(timeout);
                 tv.tv_usec = PR_IntervalToMicroseconds(
                     timeout - PR_SecondsToInterval(tv.tv_sec));
                 tvp = &tv;
             }
             FD_ZERO(&wd);
             FD_SET((SOCKET)osfd, &wd);
-            if ((rv = _PR_NTFiberSafeSelect(osfd + 1, NULL, &wd, NULL,
+            if ((rv = _PR_NTFiberSafeSelect(0, NULL, &wd, NULL,
                     tvp)) == -1) {
                 _PR_MD_MAP_SELECT_ERROR(WSAGetLastError());
                 return -1;
             }
             if (rv == 0) {
                 PR_SetError(PR_IO_TIMEOUT_ERROR, 0);
                 return -1;
             }
         }
     }
     return bytesSent;
 }
 
 static PRInt32 _nt_nonblock_recvfrom(PRFileDesc *fd, char *buf, int len, struct sockaddr *addr, int *addrlen, PRIntervalTime timeout)
 {
-    PRInt32 osfd = fd->secret->md.osfd;
+    PROsfd osfd = fd->secret->md.osfd;
     PRInt32 rv, err;
     struct timeval tv, *tvp;
     fd_set rd;
 
     while ((rv = recvfrom(osfd,buf,len,0,addr, addrlen)) == -1) {
         if (((err = WSAGetLastError()) == WSAEWOULDBLOCK)
                 && (!fd->secret->nonblocking)) {
             if (timeout == PR_INTERVAL_NO_TIMEOUT) {
@@ -4124,17 +4124,17 @@ static PRInt32 _nt_nonblock_recvfrom(PRF
             } else {
                 tv.tv_sec = PR_IntervalToSeconds(timeout);
                 tv.tv_usec = PR_IntervalToMicroseconds(
                 timeout - PR_SecondsToInterval(tv.tv_sec));
                 tvp = &tv;
             }
             FD_ZERO(&rd);
             FD_SET((SOCKET)osfd, &rd);
-            if ((rv = _PR_NTFiberSafeSelect(osfd + 1, &rd, NULL, NULL,
+            if ((rv = _PR_NTFiberSafeSelect(0, &rd, NULL, NULL,
                     tvp)) == -1) {
                 _PR_MD_MAP_SELECT_ERROR(WSAGetLastError());
                 break;
             } else if (rv == 0) {
                 PR_SetError(PR_IO_TIMEOUT_ERROR, 0);
                 rv = -1;
                 break;
             }
--- a/pr/src/md/windows/ntmisc.c
+++ b/pr/src/md/windows/ntmisc.c
@@ -107,17 +107,17 @@ PR_Now(void)
  * Assemble the command line by concatenating the argv array.
  * On success, this function returns 0 and the resulting command
  * line is returned in *cmdLine.  On failure, it returns -1.
  */
 static int assembleCmdLine(char *const *argv, char **cmdLine)
 {
     char *const *arg;
     char *p, *q;
-    int cmdLineSize;
+    size_t cmdLineSize;
     int numBackslashes;
     int i;
     int argNeedQuotes;
 
     /*
      * Find out how large the command line buffer should be.
      */
     cmdLineSize = 0;
@@ -128,17 +128,17 @@ static int assembleCmdLine(char *const *
          * may double.  If we quote an argument, that needs two ".
          * Finally, we need a space between arguments, and
          * a null byte at the end of command line.
          */
         cmdLineSize += 2 * strlen(*arg)  /* \ and " need to be escaped */
                 + 2                      /* we quote every argument */
                 + 1;                     /* space in between, or final null */
     }
-    p = *cmdLine = PR_MALLOC(cmdLineSize);
+    p = *cmdLine = PR_MALLOC((PRUint32) cmdLineSize);
     if (p == NULL) {
         return -1;
     }
 
     for (arg = argv; *arg; arg++) {
         /* Add a space to separates the arguments */
         if (arg != argv) {
             *p++ = ' '; 
@@ -221,17 +221,17 @@ static int assembleCmdLine(char *const *
  */
 static int assembleEnvBlock(char **envp, char **envBlock)
 {
     char *p;
     char *q;
     char **env;
     char *curEnv;
     char *cwdStart, *cwdEnd;
-    int envBlockSize;
+    size_t envBlockSize;
 
     if (envp == NULL) {
         *envBlock = NULL;
         return 0;
     }
 
     curEnv = GetEnvironmentStrings();
 
@@ -256,17 +256,17 @@ static int assembleEnvBlock(char **envp,
     }
     envBlockSize = cwdEnd - cwdStart;
 
     for (env = envp; *env; env++) {
         envBlockSize += strlen(*env) + 1;
     }
     envBlockSize++;
 
-    p = *envBlock = PR_MALLOC(envBlockSize);
+    p = *envBlock = PR_MALLOC((PRUint32) envBlockSize);
     if (p == NULL) {
         FreeEnvironmentStrings(curEnv);
         return -1;
     }
 
     q = cwdStart;
     while (q < cwdEnd) {
         *p++ = *q++;
@@ -578,17 +578,17 @@ PRStatus _MD_WindowsGetReleaseName(char 
  *
  **********************************************************************
  */
 
 PRStatus _MD_CreateFileMap(PRFileMap *fmap, PRInt64 size)
 {
     DWORD dwHi, dwLo;
     DWORD flProtect;
-    PRUint32    osfd;
+    PROsfd osfd;
 
     osfd = ( fmap->fd == (PRFileDesc*)-1 )?  -1 : fmap->fd->secret->md.osfd;
 
     dwLo = (DWORD) (size & 0xffffffff);
     dwHi = (DWORD) (((PRUint64) size >> 32) & 0xffffffff);
 
     if (fmap->prot == PR_PROT_READONLY) {
         flProtect = PAGE_READONLY;
--- a/pr/src/md/windows/w32rng.c
+++ b/pr/src/md/windows/w32rng.c
@@ -54,18 +54,18 @@ CurrentClockTickTime(LPDWORD lpdwHigh, L
     *lpdwHigh = liCount.u.HighPart;
     *lpdwLow = liCount.u.LowPart;
     return TRUE;
 }
 
 extern PRSize _PR_MD_GetRandomNoise( void *buf, PRSize size )
 {
     DWORD   dwHigh, dwLow, dwVal;
-    int     n = 0;
-    int     nBytes;
+    size_t  n = 0;
+    size_t  nBytes;
     time_t  sTime;
 
     if (size <= 0)
         return 0;
 
     CurrentClockTickTime(&dwHigh, &dwLow);
 
     // get the maximally changing bits first
--- a/pr/src/md/windows/w32shm.c
+++ b/pr/src/md/windows/w32shm.c
@@ -87,36 +87,35 @@ extern PRSharedMemory * _MD_OpenSharedMe
     shm = PR_NEWZAP( PRSharedMemory );
     if ( NULL == shm ) 
     {
         PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0 );
         PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, ( "PR_OpenSharedMemory: New PRSharedMemory out of memory")); 
         return(NULL);
     }
 
-    shm->ipcname = PR_MALLOC( strlen( ipcname ) + 1 );
+    shm->ipcname = PR_MALLOC( (PRUint32) (strlen( ipcname ) + 1) );
     if ( NULL == shm->ipcname )
     {
         PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0 );
         PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, ( "PR_OpenSharedMemory: New shm->ipcname out of memory")); 
         PR_DELETE(shm);
         return(NULL);
     }
 
     /* copy args to struct */
     strcpy( shm->ipcname, ipcname );
     shm->size = size; 
     shm->mode = mode;
     shm->flags = flags;
     shm->ident = _PR_SHM_IDENT;
 
     if (flags & PR_SHM_CREATE ) {
-        /* XXX: Not 64bit safe. Fix when WinNT goes 64bit. */
-        dwHi = 0;
-        dwLo = shm->size;
+        dwHi = (DWORD) (((PRUint64) shm->size >> 32) & 0xffffffff);
+        dwLo = (DWORD) (shm->size & 0xffffffff);
 
         if (_PR_NT_MakeSecurityDescriptorACL(mode, filemapAccessTable,
                 &pSD, &pACL) == PR_SUCCESS) {
             sa.nLength = sizeof(sa);
             sa.lpSecurityDescriptor = pSD;
             sa.bInheritHandle = FALSE;
             lpSA = &sa;
         }
@@ -300,19 +299,18 @@ Finished:
 extern PRStatus _md_ExportFileMapAsString(
     PRFileMap *fm,
     PRSize    bufSize,
     char      *buf
 )
 {
     PRIntn  written;
 
-    written = PR_snprintf( buf, bufSize, "%d:%ld:%ld",
-        (PRIntn)fm->prot, (PRInt32)fm->md.hFileMap, (PRInt32)fm->md.dwAccess );
-    /* Watch out on the above snprintf(). Windows HANDLE assumes 32bits; windows calls it void* */
+    written = PR_snprintf( buf, (PRUint32) bufSize, "%d:%" PR_PRIdOSFD ":%ld",
+        (PRIntn)fm->prot, (PROsfd)fm->md.hFileMap, (PRInt32)fm->md.dwAccess );
 
     PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
         ("_md_ExportFileMapAsString(): prot: %x, hFileMap: %x, dwAccess: %x",
             fm->prot, fm->md.hFileMap, fm->md.dwAccess ));
         
     return((written == -1)? PR_FAILURE : PR_SUCCESS);
 } /* end _md_ExportFileMapAsString() */
 
@@ -321,31 +319,32 @@ extern PRStatus _md_ExportFileMapAsStrin
 ** _md_ImportFileMapFromString()
 **
 */
 extern PRFileMap * _md_ImportFileMapFromString(
     const char *fmstring
 )
 {
     PRIntn  prot;
-    PRInt32 hFileMap;
+    PROsfd hFileMap;
     PRInt32 dwAccess;
     PRFileMap *fm = NULL;
 
-    PR_sscanf( fmstring, "%d:%ld:%ld", &prot, &hFileMap, &dwAccess  );
+    PR_sscanf( fmstring, "%d:%" PR_SCNdOSFD ":%ld",
+        &prot, &hFileMap, &dwAccess );
 
     fm = PR_NEWZAP(PRFileMap);
     if ( NULL == fm ) {
         PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
             ("_md_ImportFileMapFromString(): PR_NEWZAP(): Failed"));
         return(fm);
     }
 
     fm->prot = (PRFileMapProtect)prot;
-    fm->md.hFileMap = (HANDLE)hFileMap;  /* Assumes HANDLE is 32bit */
+    fm->md.hFileMap = (HANDLE)hFileMap;
     fm->md.dwAccess = (DWORD)dwAccess;
     fm->fd = (PRFileDesc*)-1;
 
     PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
         ("_md_ImportFileMapFromString(): fm: %p, prot: %d, hFileMap: %8.8x, dwAccess: %8.8x, fd: %x",
             fm, prot, fm->md.hFileMap, fm->md.dwAccess, fm->fd));
     return(fm);
 } /* end _md_ImportFileMapFromString() */
--- a/pr/src/md/windows/w95io.c
+++ b/pr/src/md/windows/w95io.c
@@ -184,17 +184,17 @@ PRStatus
  *  returns: a fileHandle
  *
  *  The NSPR open flags (osflags) are translated into flags for Win95
  *
  *  Mode seems to be passed in as a unix style file permissions argument
  *  as in 0666, in the case of opening the logFile. 
  *
  */
-PRInt32
+PROsfd
 _PR_MD_OPEN(const char *name, PRIntn osflags, int mode)
 {
     HANDLE file;
     PRInt32 access = 0;
     PRInt32 flags = 0;
     PRInt32 flag6 = 0;
     
     if (osflags & PR_SYNC) flag6 = FILE_FLAG_WRITE_THROUGH;
@@ -225,20 +225,20 @@ PRInt32
                       flags,
                       flag6,
                       NULL);
     if (file == INVALID_HANDLE_VALUE) {
 		_PR_MD_MAP_OPEN_ERROR(GetLastError());
         return -1; 
 	}
 
-    return (PRInt32)file;
+    return (PROsfd)file;
 }
 
-PRInt32
+PROsfd
 _PR_MD_OPEN_FILE(const char *name, PRIntn osflags, int mode)
 {
     HANDLE file;
     PRInt32 access = 0;
     PRInt32 flags = 0;
     PRInt32 flag6 = 0;
     SECURITY_ATTRIBUTES sa;
     LPSECURITY_ATTRIBUTES lpSA = NULL;
@@ -286,17 +286,17 @@ PRInt32
     if (lpSA != NULL) {
         _PR_NT_FreeSecurityDescriptorACL(pSD, pACL);
     }
     if (file == INVALID_HANDLE_VALUE) {
 		_PR_MD_MAP_OPEN_ERROR(GetLastError());
         return -1; 
 	}
 
-    return (PRInt32)file;
+    return (PROsfd)file;
 }
 
 PRInt32
 _PR_MD_READ(PRFileDesc *fd, void *buf, PRInt32 len)
 {
     PRUint32 bytes;
     int rv, err;
 
@@ -319,17 +319,17 @@ PRInt32
     }
     }
     return bytes;
 }
 
 PRInt32
 _PR_MD_WRITE(PRFileDesc *fd, const void *buf, PRInt32 len)
 {
-    PRInt32 f = fd->secret->md.osfd;
+    PROsfd f = fd->secret->md.osfd;
     PRInt32 bytes;
     int rv;
     PRThread *me = _PR_MD_CURRENT_THREAD();
     
     rv = WriteFile((HANDLE)f,
             buf,
             len,
             &bytes,
@@ -443,34 +443,34 @@ PRInt32
 			_PR_MD_MAP_FSYNC_ERROR(err);
 	    return -1;
 	}
     }
     return 0;
 }
 
 PRInt32
-_MD_CloseFile(PRInt32 osfd)
+_MD_CloseFile(PROsfd osfd)
 {
     PRInt32 rv;
     
     rv = (CloseHandle((HANDLE)osfd))?0:-1;
 	if (rv == -1)
 		_PR_MD_MAP_CLOSE_ERROR(GetLastError());
     return rv;
 }
 
 
 /* --- DIR IO ------------------------------------------------------------ */
 #define GetFileFromDIR(d)       (d)->d_entry.cFileName
 #define FileIsHidden(d)	((d)->d_entry.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
 
-void FlipSlashes(char *cp, int len)
+void FlipSlashes(char *cp, size_t len)
 {
-    while (--len >= 0) {
+    while (len-- > 0) {
         if (cp[0] == '/') {
             cp[0] = PR_DIRECTORY_SEPARATOR;
         }
         cp = _mbsinc(cp);
     }
 } /* end FlipSlashes() */
 
 
@@ -497,17 +497,17 @@ PRStatus
     return PR_FAILURE;
 }
 
 
 PRStatus
 _PR_MD_OPEN_DIR(_MDDir *d, const char *name)
 {
     char filename[ MAX_PATH ];
-    int len;
+    size_t len;
 
     len = strlen(name);
     /* Need 5 bytes for \*.* and the trailing null byte. */
     if (len + 5 > MAX_PATH) {
         PR_SetError(PR_NAME_TOO_LONG_ERROR, 0);
         return PR_FAILURE;
     }
     strcpy(filename, name);
@@ -647,17 +647,17 @@ PRInt32
          * e.g., c:\temp\ or c:/temp/, _stat() will fail.
          * Note: a pathname ending in a slash (e.g., c:/temp/)
          * can be handled by _stat() on NT but not on Win95.
          *
          * We remove the backslash or slash at the end and
          * try again.
          */
 
-        int len = strlen(fn);
+        size_t len = strlen(fn);
         if (len > 0 && len <= _MAX_PATH
                 && (fn[len - 1] == '\\' || fn[len - 1] == '/')) {
             char newfn[_MAX_PATH + 1];
 
             strcpy(newfn, fn);
             newfn[len - 1] = '\0';
             rv = _stat(newfn, (struct _stat *)info);
         }
@@ -1042,17 +1042,17 @@ PRInt32
         return 0;
     } else {
 		_PR_MD_MAP_RMDIR_ERROR(GetLastError());
         return -1;
     }
 }
 
 PRStatus
-_PR_MD_LOCKFILE(PRInt32 f)
+_PR_MD_LOCKFILE(PROsfd f)
 {
     PRStatus  rc = PR_SUCCESS;
 	DWORD     rv;
 
 	rv = LockFile( (HANDLE)f,
 		0l, 0l,
 		0x0l, 0xffffffffl ); 
 	if ( rv == 0 ) {
@@ -1061,25 +1061,25 @@ PRStatus
             ("_PR_MD_LOCKFILE() failed. Error: %d", rc ));
         rc = PR_FAILURE;
     }
 
     return rc;
 } /* end _PR_MD_LOCKFILE() */
 
 PRStatus
-_PR_MD_TLOCKFILE(PRInt32 f)
+_PR_MD_TLOCKFILE(PROsfd f)
 {
     PR_SetError( PR_NOT_IMPLEMENTED_ERROR, 0 );
     return PR_FAILURE;
 } /* end _PR_MD_TLOCKFILE() */
 
 
 PRStatus
-_PR_MD_UNLOCKFILE(PRInt32 f)
+_PR_MD_UNLOCKFILE(PROsfd f)
 {
 	PRInt32   rv;
     
     rv = UnlockFile( (HANDLE) f,
     		0l, 0l,
             0x0l, 0xffffffffl ); 
             
     if ( rv )
@@ -1134,27 +1134,27 @@ static void InitUnicodeSupport(void)
     createFileW = (CreateFileWFn)GetProcAddress(module, "CreateFileW"); 
     findFirstFileW = (FindFirstFileWFn)GetProcAddress(module, "FindFirstFileW"); 
     findNextFileW = (FindNextFileWFn)GetProcAddress(module, "FindNextFileW"); 
     getDriveTypeW = (GetDriveTypeWFn)GetProcAddress(module, "GetDriveTypeW"); 
     getFullPathNameW = (GetFullPathNameWFn)GetProcAddress(module, "GetFullPathNameW"); 
 }
 
 /* ================ UTF16 Interfaces ================================ */
-void FlipSlashesW(PRUnichar *cp, int len)
+void FlipSlashesW(PRUnichar *cp, size_t len)
 {
-    while (--len >= 0) {
+    while (len-- > 0) {
         if (cp[0] == L'/') {
             cp[0] = L'\\';
         }
         cp++;
     }
 } /* end FlipSlashesW() */
 
-PRInt32
+PROsfd
 _PR_MD_OPEN_FILE_UTF16(const PRUnichar *name, PRIntn osflags, int mode)
 {
     HANDLE file;
     PRInt32 access = 0;
     PRInt32 flags = 0;
     PRInt32 flag6 = 0;
     SECURITY_ATTRIBUTES sa;
     LPSECURITY_ATTRIBUTES lpSA = NULL;
@@ -1207,17 +1207,17 @@ PRInt32
     if (lpSA != NULL) {
         _PR_NT_FreeSecurityDescriptorACL(pSD, pACL);
     }
     if (file == INVALID_HANDLE_VALUE) {
         _PR_MD_MAP_OPEN_ERROR(GetLastError());
         return -1;
     }
  
-    return (PRInt32)file;
+    return (PROsfd)file;
 }
  
 PRStatus
 _PR_MD_OPEN_DIR_UTF16(_MDDirUTF16 *d, const PRUnichar *name)
 {
     PRUnichar filename[ MAX_PATH ];
     int len;
 
--- a/pr/src/md/windows/w95sock.c
+++ b/pr/src/md/windows/w95sock.c
@@ -41,57 +41,57 @@
 
 #include "primpl.h"
 
 #define READ_FD     1
 #define WRITE_FD    2
 #define CONNECT_FD  3
 
 static PRInt32 socket_io_wait(
-    PRInt32 osfd, 
+    PROsfd osfd, 
     PRInt32 fd_type,
     PRIntervalTime timeout);
 
 
 /* --- SOCKET IO --------------------------------------------------------- */
 
 
-PRInt32
+PROsfd
 _PR_MD_SOCKET(int af, int type, int flags)
 {
     SOCKET sock;
     u_long one = 1;
 
     sock = socket(af, type, flags);
 
     if (sock == INVALID_SOCKET ) 
     {
         _PR_MD_MAP_SOCKET_ERROR(WSAGetLastError());
-        return (PRInt32)sock;
+        return (PROsfd)sock;
     }
 
     /*
     ** Make the socket Non-Blocking
     */
     if (ioctlsocket( sock, FIONBIO, &one) != 0)
     {
         PR_SetError(PR_UNKNOWN_ERROR, WSAGetLastError());
         closesocket(sock);
         return -1;
     }
 
-    return (PRInt32)sock;
+    return (PROsfd)sock;
 }
 
 /*
 ** _MD_CloseSocket() -- Close a socket
 **
 */
 PRInt32
-_MD_CloseSocket(PRInt32 osfd)
+_MD_CloseSocket(PROsfd osfd)
 {
     PRInt32 rv;
 
     rv = closesocket((SOCKET) osfd );
     if (rv < 0)
         _PR_MD_MAP_CLOSE_ERROR(WSAGetLastError());
 
     return rv;
@@ -104,49 +104,50 @@ PRInt32
 
     if (ioctlsocket(fd->secret->md.osfd, FIONREAD, &result) < 0) {
         PR_SetError(PR_BAD_DESCRIPTOR_ERROR, WSAGetLastError());
         return -1;
     }
     return result;
 }
 
-PRInt32 _MD_Accept(
+PROsfd _MD_Accept(
     PRFileDesc *fd, 
     PRNetAddr *raddr, 
     PRUint32 *rlen,
     PRIntervalTime timeout )
 {
-    PRInt32 osfd = fd->secret->md.osfd;
+    PROsfd osfd = fd->secret->md.osfd;
+    SOCKET sock;
     PRInt32 rv, err;
 
-    while ((rv = accept(osfd, (struct sockaddr *) raddr, rlen)) == -1) 
+    while ((sock = accept(osfd, (struct sockaddr *) raddr, rlen)) == -1) 
     {
         err = WSAGetLastError();
         if ((err == WSAEWOULDBLOCK) && (!fd->secret->nonblocking))
         {
             if ((rv = socket_io_wait(osfd, READ_FD, timeout)) < 0)
             {
-                return(-1);
+                break;
             }
         }
         else
         {
             _PR_MD_MAP_ACCEPT_ERROR(err);
             break;
         }
     }
-    return(rv);
+    return(sock);
 } /* end _MD_accept() */
 
 PRInt32
 _PR_MD_CONNECT(PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen, 
                PRIntervalTime timeout)
 {
-    PRInt32 osfd = fd->secret->md.osfd;
+    PROsfd osfd = fd->secret->md.osfd;
     PRInt32 rv;
     int     err;
 
     if ((rv = connect(osfd, (struct sockaddr *) addr, addrlen)) == -1) 
     {
         err = WSAGetLastError();
         if ((!fd->secret->nonblocking) && (err == WSAEWOULDBLOCK))
         {
@@ -196,17 +197,17 @@ PRInt32
 
     return 0;
 }
 
 PRInt32
 _PR_MD_RECV(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags, 
             PRIntervalTime timeout)
 {
-    PRInt32 osfd = fd->secret->md.osfd;
+    PROsfd osfd = fd->secret->md.osfd;
     PRInt32 rv, err;
     int osflags;
 
     if (0 == flags) {
         osflags = 0;
     } else {
         PR_ASSERT(PR_MSG_PEEK == flags);
         osflags = MSG_PEEK;
@@ -230,17 +231,17 @@ PRInt32
     } /* end while() */
     return(rv);
 }
 
 PRInt32
 _PR_MD_SEND(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
             PRIntervalTime timeout)
 {
-    PRInt32 osfd = fd->secret->md.osfd;
+    PROsfd osfd = fd->secret->md.osfd;
     PRInt32 rv, err;
     PRInt32 bytesSent = 0;
 
     while(bytesSent < amount ) 
     {
         while ((rv = send( osfd, buf, amount, 0 )) == -1) 
         {
             if (((err = WSAGetLastError()) == WSAEWOULDBLOCK) 
@@ -274,17 +275,17 @@ PRInt32
     }
     return bytesSent;
 }
 
 PRInt32
 _PR_MD_SENDTO(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
               const PRNetAddr *addr, PRUint32 addrlen, PRIntervalTime timeout)
 {
-    PRInt32 osfd = fd->secret->md.osfd;
+    PROsfd osfd = fd->secret->md.osfd;
     PRInt32 rv, err;
     PRInt32 bytesSent = 0;
 
     while(bytesSent < amount) 
     {
         while ((rv = sendto( osfd, buf, amount, 0, (struct sockaddr *) addr,
                 addrlen)) == -1) 
         {
@@ -319,17 +320,17 @@ PRInt32
     }
     return bytesSent;
 }
 
 PRInt32
 _PR_MD_RECVFROM(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags,
                 PRNetAddr *addr, PRUint32 *addrlen, PRIntervalTime timeout)
 {
-    PRInt32 osfd = fd->secret->md.osfd;
+    PROsfd osfd = fd->secret->md.osfd;
     PRInt32 rv, err;
 
     while ((rv = recvfrom( osfd, buf, amount, 0, (struct sockaddr *) addr,
             addrlen)) == -1) 
     {
         if (((err = WSAGetLastError()) == WSAEWOULDBLOCK) 
             && (!fd->secret->nonblocking))
         {
@@ -464,17 +465,17 @@ void
  * Wait for socket i/o, periodically checking for interrupt.
  *
  * This function returns 1 on success.  On failure, it returns
  * -1 and sets the error codes.  It never returns 0.
  */
 #define _PR_INTERRUPT_CHECK_INTERVAL_SECS 5
 
 static PRInt32 socket_io_wait(
-    PRInt32 osfd, 
+    PROsfd osfd, 
     PRInt32 fd_type,
     PRIntervalTime timeout)
 {
     PRInt32 rv = -1;
     struct timeval tv;
     PRThread *me = _PR_MD_CURRENT_THREAD();
     PRIntervalTime elapsed, remaining;
     PRBool wait_for_remaining;
@@ -495,23 +496,23 @@ static PRInt32 socket_io_wait(
             FD_ZERO(&rd_wr);
             FD_ZERO(&ex);
             do {
                 FD_SET(osfd, &rd_wr);
                 FD_SET(osfd, &ex);
                 switch( fd_type )
                 {
                     case READ_FD:
-                        rv = _MD_SELECT(osfd + 1, &rd_wr, NULL, NULL, &tv);
+                        rv = _MD_SELECT(0, &rd_wr, NULL, NULL, &tv);
                         break;
                     case WRITE_FD:
-                        rv = _MD_SELECT(osfd + 1, NULL, &rd_wr, NULL, &tv);
+                        rv = _MD_SELECT(0, NULL, &rd_wr, NULL, &tv);
                         break;
                     case CONNECT_FD:
-                        rv = _MD_SELECT(osfd + 1, NULL, &rd_wr, &ex, &tv);
+                        rv = _MD_SELECT(0, NULL, &rd_wr, &ex, &tv);
                         break;
                     default:
                         PR_ASSERT(0);
                         break;
                 } /* end switch() */
                 if (rv == -1 )
                 {
                     _PR_MD_MAP_SELECT_ERROR(WSAGetLastError());
@@ -575,23 +576,23 @@ static PRInt32 socket_io_wait(
                         remaining -
                         PR_SecondsToInterval(tv.tv_sec));
                 }
                 FD_SET(osfd, &rd_wr);
                 FD_SET(osfd, &ex);
                 switch( fd_type )
                 {
                     case READ_FD:
-                        rv = _MD_SELECT(osfd + 1, &rd_wr, NULL, NULL, &tv);
+                        rv = _MD_SELECT(0, &rd_wr, NULL, NULL, &tv);
                         break;
                     case WRITE_FD:
-                        rv = _MD_SELECT(osfd + 1, NULL, &rd_wr, NULL, &tv);
+                        rv = _MD_SELECT(0, NULL, &rd_wr, NULL, &tv);
                         break;
                     case CONNECT_FD:
-                        rv = _MD_SELECT(osfd + 1, NULL, &rd_wr, &ex, &tv);
+                        rv = _MD_SELECT(0, NULL, &rd_wr, &ex, &tv);
                         break;
                     default:
                         PR_ASSERT(0);
                         break;
                 } /* end switch() */
                 if (rv == -1)
                 {
                     _PR_MD_MAP_SELECT_ERROR(WSAGetLastError());
--- a/pr/src/md/windows/w95thred.c
+++ b/pr/src/md/windows/w95thred.c
@@ -33,16 +33,24 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "primpl.h"
 #include <process.h>  /* for _beginthreadex() */
 
+#if _MSC_VER <= 1200
+/*
+ * VC++ 6.0 doesn't have DWORD_PTR.
+ */
+
+typedef DWORD DWORD_PTR;
+#endif /* _MSC_VER <= 1200 */
+
 /* --- 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;
 #else
 DWORD _pr_currentThreadIndex;
 DWORD _pr_lastThreadIndex;
@@ -219,29 +227,34 @@ void
 void
 _PR_MD_EXIT(PRIntn status)
 {
     _exit(status);
 }
 
 PRInt32 _PR_MD_SETTHREADAFFINITYMASK(PRThread *thread, PRUint32 mask )
 {
-    int rv;
+    DWORD_PTR rv;
 
     rv = SetThreadAffinityMask(thread->md.handle, mask);
 
     return rv?0:-1;
 }
 
 PRInt32 _PR_MD_GETTHREADAFFINITYMASK(PRThread *thread, PRUint32 *mask)
 {
-    PRInt32 rv, system_mask;
+    BOOL rv;
+    DWORD_PTR process_mask;
+    DWORD_PTR system_mask;
 
-    rv = GetProcessAffinityMask(GetCurrentProcess(), mask, &system_mask);
-    
+    rv = GetProcessAffinityMask(GetCurrentProcess(),
+            &process_mask, &system_mask);
+    if (rv)
+        *mask = (PRUint32)process_mask;
+
     return rv?0:-1;
 }
 
 void 
 _PR_MD_SUSPEND_CPU(_PRCPU *cpu) 
 {
     _PR_MD_SUSPEND_THREAD(cpu->thread);
 }
--- a/pr/src/misc/prinit.c
+++ b/pr/src/misc/prinit.c
@@ -582,18 +582,22 @@ PR_ProcessAttrSetInheritableFD(
     PRProcessAttr *attr,
     PRFileDesc *fd,
     const char *name)
 {
     /* We malloc the fd inherit buffer in multiples of this number. */
 #define FD_INHERIT_BUFFER_INCR 128
     /* The length of "NSPR_INHERIT_FDS=" */
 #define NSPR_INHERIT_FDS_STRLEN 17
-    /* The length of osfd (PRInt32) printed in hexadecimal with 0x prefix */
+    /* The length of osfd (PROsfd) printed in hexadecimal with 0x prefix */
+#ifdef _WIN64
+#define OSFD_STRLEN 18
+#else
 #define OSFD_STRLEN 10
+#endif
     /* The length of fd type (PRDescType) printed in decimal */
 #define FD_TYPE_STRLEN 1
     PRSize newSize;
     int remainder;
     char *newBuffer;
     int nwritten;
     char *cur;
     int freeSize;
@@ -640,48 +644,48 @@ PR_ProcessAttrSetInheritableFD(
         }
         attr->fdInheritBuffer = newBuffer;
         attr->fdInheritBufferSize = newSize;
     }
     cur = attr->fdInheritBuffer + attr->fdInheritBufferUsed;
     freeSize = attr->fdInheritBufferSize - attr->fdInheritBufferUsed;
     if (0 == attr->fdInheritBufferUsed) {
         nwritten = PR_snprintf(cur, freeSize,
-                "NSPR_INHERIT_FDS=%s:%d:0x%lx",
+                "NSPR_INHERIT_FDS=%s:%d:0x%" PR_PRIxOSFD,
                 name, (PRIntn)fd->methods->file_type, fd->secret->md.osfd);
     } else {
-        nwritten = PR_snprintf(cur, freeSize, ":%s:%d:0x%lx",
+        nwritten = PR_snprintf(cur, freeSize, ":%s:%d:0x%" PR_PRIxOSFD,
                 name, (PRIntn)fd->methods->file_type, fd->secret->md.osfd);
     }
     attr->fdInheritBufferUsed += nwritten; 
     return PR_SUCCESS;
 }
 
 PR_IMPLEMENT(PRFileDesc *) PR_GetInheritedFD(
     const char *name)
 {
     PRFileDesc *fd;
     const char *envVar;
     const char *ptr;
     int len = strlen(name);
-    PRInt32 osfd;
+    PROsfd osfd;
     int nColons;
     PRIntn fileType;
 
     envVar = PR_GetEnv("NSPR_INHERIT_FDS");
     if (NULL == envVar || '\0' == envVar[0]) {
         PR_SetError(PR_UNKNOWN_ERROR, 0);
         return NULL;
     }
 
     ptr = envVar;
     while (1) {
         if ((ptr[len] == ':') && (strncmp(ptr, name, len) == 0)) {
             ptr += len + 1;
-            PR_sscanf(ptr, "%d:0x%lx", &fileType, &osfd);
+            PR_sscanf(ptr, "%d:0x%" PR_SCNxOSFD, &fileType, &osfd);
             switch ((PRDescType)fileType) {
                 case PR_DESC_FILE:
                     fd = PR_ImportFile(osfd);
                     break;
                 case PR_DESC_PIPE:
                     fd = PR_ImportPipe(osfd);
                     break;
                 case PR_DESC_SOCKET_TCP:
--- a/pr/tests/prpoll.c
+++ b/pr/tests/prpoll.c
@@ -95,18 +95,19 @@ int main(int argc, char **argv)
     PRFileDesc *badFD;
     PRUint16 listenPort1, listenPort2;
     PRNetAddr addr;
     char buf[BUF_SIZE];
     PRThread *clientThread;
     PRPollDesc pds0[10], pds1[10], *pds, *other_pds;
     PRIntn npds;
     PRInt32 retVal;
-    PRInt32 sd, rv;
-	struct sockaddr_in saddr;
+    PRInt32 rv;
+    PROsfd sd;
+    struct sockaddr_in saddr;
     PRIntn saddr_len;
     PRUint16 listenPort3;
     PRFileDesc *socket_poll_fd;
     PRIntn i, j;
 
     PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
     PR_STDIO_INIT();
 
@@ -281,17 +282,17 @@ int main(int argc, char **argv)
 			other_pds[j] = pds[j];
 			PR_ASSERT((pds[j].out_flags & PR_POLL_WRITE) == 0
 				&& (pds[j].out_flags & PR_POLL_EXCEPT) == 0);
 			if (pds[j].out_flags & PR_POLL_READ) {
 				PRFileDesc *sock;
 
 				nEvents++;
 				if (j == 2) {
-					int newsd;
+					PROsfd newsd;
 					newsd = accept(PR_FileDesc2NativeHandle(pds[j].fd), NULL, 0);
 					if (newsd == -1) {
 						fprintf(stderr, "accept() failed\n");
 						exit(1);
 					}
 					other_pds[nextIndex].fd  = PR_CreateSocketPollFd(newsd);
 					PR_ASSERT(other_pds[nextIndex].fd);
 					other_pds[nextIndex].in_flags = PR_POLL_READ;