Pull up Win64 support from 0.9.8.
authorAndy Polyakov <appro@openssl.org>
Tue, 5 Jul 2005 11:44:45 +0000 (11:44 +0000)
committerAndy Polyakov <appro@openssl.org>
Tue, 5 Jul 2005 11:44:45 +0000 (11:44 +0000)
Configure
INSTALL.W32
INSTALL.W64 [new file with mode: 0644]
crypto/cryptlib.c
crypto/mem_dbg.c
e_os.h
ms/do_win64a.bat [new file with mode: 0755]
ms/do_win64i.bat [new file with mode: 0755]
util/mk1mf.pl
util/pl/VC-32.pl

index de5366b7238a5fc1a92b766763085f83f20369f9..933246a15709aa96a31e487734842364b3017e0b 100755 (executable)
--- a/Configure
+++ b/Configure
@@ -456,8 +456,8 @@ my %table=(
 "OS390-Unix","c89.sh:-O -DB_ENDIAN -DCHARSET_EBCDIC -DNO_SYS_PARAM_H  -D_ALL_SOURCE::(unknown):::THIRTY_TWO_BIT DES_PTR DES_UNROLL MD2_CHAR RC4_INDEX RC4_CHAR BF_PTR:::",
 
 # Win64 targets, WIN64I denotes IA-64 and WIN64A - AMD64
 "OS390-Unix","c89.sh:-O -DB_ENDIAN -DCHARSET_EBCDIC -DNO_SYS_PARAM_H  -D_ALL_SOURCE::(unknown):::THIRTY_TWO_BIT DES_PTR DES_UNROLL MD2_CHAR RC4_INDEX RC4_CHAR BF_PTR:::",
 
 # Win64 targets, WIN64I denotes IA-64 and WIN64A - AMD64
-"VC-WIN64I","cl::::WIN64I::SIXTY_FOUR_BIT EXPORT_VAR_AS_FN:${no_asm}:win32",
-"VC-WIN64A","cl::::WIN64A::SIXTY_FOUR_BIT EXPORT_VAR_AS_FN:${no_asm}:win32",
+"VC-WIN64I","cl::::WIN64I::SIXTY_FOUR_BIT RC4_CHUNK_LL DES_INT EXPORT_VAR_AS_FN:${no_asm}:win32",
+"VC-WIN64A","cl::::WIN64A::SIXTY_FOUR_BIT RC4_CHUNK_LL DES_INT EXPORT_VAR_AS_FN:${no_asm}:win32",
 
 # Visual C targets
 "VC-NT","cl::::WINNT::BN_LLONG RC4_INDEX EXPORT_VAR_AS_FN ${x86_gcc_opts}:${no_asm}:win32",
 
 # Visual C targets
 "VC-NT","cl::::WINNT::BN_LLONG RC4_INDEX EXPORT_VAR_AS_FN ${x86_gcc_opts}:${no_asm}:win32",
index 0f6c302f0d7fd3566beeba393f824fde3366d87d..f18f2496779cb2ad1bc501b13e6edc4733d75c38 100644 (file)
@@ -3,6 +3,7 @@
  ----------------------------------
 
  [Instructions for building for Windows CE can be found in INSTALL.WCE]
  ----------------------------------
 
  [Instructions for building for Windows CE can be found in INSTALL.WCE]
+ [Instructions for building for Win64 can be found in INSTALL.W64]
 
  Heres a few comments about building OpenSSL in Windows environments.  Most
  of this is tested on Win32 but it may also work in Win 3.1 with some
 
  Heres a few comments about building OpenSSL in Windows environments.  Most
  of this is tested on Win32 but it may also work in Win 3.1 with some
diff --git a/INSTALL.W64 b/INSTALL.W64
new file mode 100644 (file)
index 0000000..9fa7a19
--- /dev/null
@@ -0,0 +1,66 @@
+
+ INSTALLATION ON THE WIN64 PLATFORM
+ ----------------------------------
+
+ Caveat lector
+ -------------
+
+ As of moment of this writing Win64 support is classified "initial"
+ for the following reasons.
+
+ - No assembler modules are engaged upon initial 0.9.8 release.
+ - API might change within 0.9.8 life-span, *but* in a manner which
+   doesn't break backward binary compatibility. Or in other words,
+   application programs compiled with initial 0.9.8 headers will
+   be expected to work with future minor release .DLL without need
+   to re-compile, even if future minor release features modified API.
+ - Above mentioned API modifications have everything to do with
+   elimination of a number of limitations, which are normally
+   considered inherent to 32-bit platforms. Which in turn is why they
+   are treated as limitations on 64-bit platform such as Win64:-)
+   The current list comprises [but not necessarily limited to]:
+
+   - null-terminated strings may not be longer than 2G-1 bytes,
+     longer strings are treated as zero-length;
+   - dynamically and *internally* allocated chunks can't be larger
+     than 2G-1 bytes;
+   - inability to encrypt/decrypt chunks of data larger than 4GB
+     [it's possibly to *hash* chunks of arbitrary size through];
+
+   Neither of these is actually big deal and hardly encountered
+   in real-life applications.
+
+ Compiling procedure
+ -------------------
+
+ You will need Perl. You can run under Cygwin or you can download
+ ActiveState Perl from http://www.activestate.com/ActivePerl.
+
+ You will need Microsoft Platform SDK, available for download at
+ http://www.microsoft.com/msdownload/platformsdk/sdkupdate/. As per
+ April 2005 Platform SDK is equipped with Win64 compilers, as well
+ as assemblers, but it might change in the future.
+
+ To build for Win64/x64:
+
+ > perl Configure VC-WIN64A
+ > ms\do_win64a
+ > nmake -f ms\ntdll.mak
+ > cd out32dll
+ > ..\ms\test
+
+ To build for Win64/IA64:
+
+ > perl Configure VC-WIN64I
+ > ms\do_win64i
+ > nmake -f ms\ntdll.mak
+ > cd out32dll
+ > ..\ms\test
+
+ Naturally test-suite itself has to be executed on the target platform.
+
+ Installation
+ ------------
+
+ TBD, for now see INSTALL.W32.
+
index e73d086eedd099e7be67f3f7b9aea940fe8ec988..21332378cf0bfcdd15d5df12e3dd5933ffd2987c 100644 (file)
@@ -545,7 +545,6 @@ const char *CRYPTO_get_lock_name(int type)
 
 unsigned long  OPENSSL_ia32cap_P=0;
 unsigned long *OPENSSL_ia32cap_loc(void) { return &OPENSSL_ia32cap_P; }
 
 unsigned long  OPENSSL_ia32cap_P=0;
 unsigned long *OPENSSL_ia32cap_loc(void) { return &OPENSSL_ia32cap_P; }
-int OPENSSL_NONPIC_relocated=0;
 
 #if defined(OPENSSL_CPUID_OBJ) && !defined(OPENSSL_NO_ASM) && !defined(I386_ONLY)
 #define OPENSSL_CPUID_SETUP
 
 #if defined(OPENSSL_CPUID_OBJ) && !defined(OPENSSL_NO_ASM) && !defined(I386_ONLY)
 #define OPENSSL_CPUID_SETUP
@@ -572,6 +571,7 @@ void OPENSSL_cpuid_setup(void)
 #else
 unsigned long *OPENSSL_ia32cap_loc(void) { return NULL; }
 #endif
 #else
 unsigned long *OPENSSL_ia32cap_loc(void) { return NULL; }
 #endif
+int OPENSSL_NONPIC_relocated = 0;
 #if !defined(OPENSSL_CPUID_SETUP)
 void OPENSSL_cpuid_setup(void) {}
 #endif
 #if !defined(OPENSSL_CPUID_SETUP)
 void OPENSSL_cpuid_setup(void) {}
 #endif
index 557516bde95fa4ad87e5c91b15ba4b51da644c55..8316485217ac48847f59ce5ce8a51ba86df2ff97 100644 (file)
@@ -252,8 +252,16 @@ long CRYPTO_dbg_get_options(void)
 /* static int mem_cmp(MEM *a, MEM *b) */
 static int mem_cmp(const void *a_void, const void *b_void)
        {
 /* static int mem_cmp(MEM *a, MEM *b) */
 static int mem_cmp(const void *a_void, const void *b_void)
        {
+#ifdef _WIN64
+       const char *a=(const char *)((const MEM *)a_void)->addr,
+                  *b=(const char *)((const MEM *)b_void)->addr;
+       if (a==b)       return 0;
+       else if (a>b)   return 1;
+       else            return -1;
+#else
        return((const char *)((const MEM *)a_void)->addr
                - (const char *)((const MEM *)b_void)->addr);
        return((const char *)((const MEM *)a_void)->addr
                - (const char *)((const MEM *)b_void)->addr);
+#endif
        }
 
 /* static unsigned long mem_hash(MEM *a) */
        }
 
 /* static unsigned long mem_hash(MEM *a) */
diff --git a/e_os.h b/e_os.h
index 0b2b1cca67e5b0aa78c68eb39fbf8a4a4423f8de..965d1aa8d77136529149e147a7930219ee316058 100644 (file)
--- a/e_os.h
+++ b/e_os.h
@@ -266,6 +266,16 @@ extern "C" {
 #    include <stddef.h>
 #    include <errno.h>
 #    include <string.h>
 #    include <stddef.h>
 #    include <errno.h>
 #    include <string.h>
+#    ifdef _WIN64
+#      define strlen(s) _strlen31(s)
+/* cut strings to 2GB */
+static unsigned int _strlen31(const char *str)
+       {
+       unsigned int len=0;
+       while (*str && len<0x80000000U) str++, len++;
+       return len&0x7FFFFFFF;
+       }
+#    endif
 #    include <malloc.h>
 #  endif
 #  include <io.h>
 #    include <malloc.h>
 #  endif
 #  include <io.h>
@@ -426,6 +436,15 @@ extern "C" {
 #    elif !defined(__DJGPP__)
 #      include <winsock.h>
 extern HINSTANCE _hInstance;
 #    elif !defined(__DJGPP__)
 #      include <winsock.h>
 extern HINSTANCE _hInstance;
+#      ifdef _WIN64
+/*
+ * Even though sizeof(SOCKET) is 8, it's safe to cast it to int, because
+ * the value constitutes an index in per-process table of limited size
+ * and not a real pointer.
+ */
+#        define socket(d,t,p)  ((int)socket(d,t,p))
+#        define accept(s,f,l)  ((int)accept(s,f,l))
+#      endif
 #      define SSLeay_Write(a,b,c)      send((a),(b),(c),0)
 #      define SSLeay_Read(a,b,c)       recv((a),(b),(c),0)
 #      define SHUTDOWN(fd)             { shutdown((fd),0); closesocket(fd); }
 #      define SSLeay_Write(a,b,c)      send((a),(b),(c),0)
 #      define SSLeay_Read(a,b,c)       recv((a),(b),(c),0)
 #      define SHUTDOWN(fd)             { shutdown((fd),0); closesocket(fd); }
diff --git a/ms/do_win64a.bat b/ms/do_win64a.bat
new file mode 100755 (executable)
index 0000000..825c690
--- /dev/null
@@ -0,0 +1,9 @@
+\r
+perl util\mkfiles.pl >MINFO\r
+perl ms\uplink.pl win64a > ms\uptable.asm\r
+ml64 -c -Foms\uptable.obj ms\uptable.asm\r
+perl util\mk1mf.pl no-asm VC-WIN64A >ms\nt.mak\r
+perl util\mk1mf.pl dll no-asm VC-WIN64A >ms\ntdll.mak\r
+\r
+perl util\mkdef.pl 32 libeay > ms\libeay32.def\r
+perl util\mkdef.pl 32 ssleay > ms\ssleay32.def\r
diff --git a/ms/do_win64i.bat b/ms/do_win64i.bat
new file mode 100755 (executable)
index 0000000..7bfc2f1
--- /dev/null
@@ -0,0 +1,9 @@
+\r
+perl util\mkfiles.pl >MINFO\r
+perl ms\uplink.pl win64i > ms\uptable.asm\r
+ias -o ms\uptable.obj ms\uptable.asm\r
+perl util\mk1mf.pl no-asm VC-WIN64I >ms\nt.mak\r
+perl util\mk1mf.pl dll no-asm VC-WIN64I >ms\ntdll.mak\r
+\r
+perl util\mkdef.pl 32 libeay > ms\libeay32.def\r
+perl util\mkdef.pl 32 ssleay > ms\ssleay32.def\r
index fa0fbe3673bdc929dc076eff72946b68966fabe6..6090a2b5a61bf0976cefd60ded899332b6c2534e 100755 (executable)
@@ -24,6 +24,8 @@ $infile="MINFO";
 
 %ops=(
        "VC-WIN32",   "Microsoft Visual C++ [4-6] - Windows NT or 9X",
 
 %ops=(
        "VC-WIN32",   "Microsoft Visual C++ [4-6] - Windows NT or 9X",
+       "VC-WIN64I",  "Microsoft C/C++ - Win64/IA-64",
+       "VC-WIN64A",  "Microsoft C/C++ - Win64/x64",
        "VC-CE",   "Microsoft eMbedded Visual C++ 3.0 - Windows CE ONLY",
        "VC-NT",   "Microsoft Visual C++ [4-6] - Windows NT ONLY",
        "Mingw32", "GNU C++ - Windows NT or 9x",
        "VC-CE",   "Microsoft eMbedded Visual C++ 3.0 - Windows CE ONLY",
        "VC-NT",   "Microsoft Visual C++ [4-6] - Windows NT ONLY",
        "Mingw32", "GNU C++ - Windows NT or 9x",
@@ -120,9 +122,10 @@ $bin_dir=(defined($VARS{'BIN'}))?$VARS{'BIN'}:'';
 $NT=0;
 
 push(@INC,"util/pl","pl");
 $NT=0;
 
 push(@INC,"util/pl","pl");
-if (($platform eq "VC-WIN32") || ($platform eq "VC-NT"))
+if (($platform =~ /VC-(.+)/))
        {
        {
-       $NT = 1 if $platform eq "VC-NT";
+       $FLAVOR=$1;
+       $NT = 1 if $1 eq "NT";
        require 'VC-32.pl';
        }
 elsif ($platform eq "VC-CE")
        require 'VC-32.pl';
        }
 elsif ($platform eq "VC-CE")
index 710c4cd129f8f022788506680fe4dc64e30708b6..d39715cdad62db25d27bc0afad681adff0e44d75 100644 (file)
@@ -11,8 +11,27 @@ $rm='del';
 
 # C compiler stuff
 $cc='cl';
 
 # C compiler stuff
 $cc='cl';
-$cflags=' /MD /W3 /WX /G5 /Ox /O2 /Ob2 /Gs0 /GF /Gy /nologo -DOPENSSL_SYSNAME_WIN32 -DWIN32_LEAN_AND_MEAN -DL_ENDIAN -DDSO_WIN32';
-$lflags="/nologo /subsystem:console /machine:I386 /opt:ref";
+if ($FLAVOR =~ /WIN64/)
+    {
+    # Note that we currently don't have /WX on Win64! There is a lot of
+    # warnings, but only of two types:
+    #
+    # C4344: conversion from '__int64' to 'int/long', possible loss of data
+    # C4267: conversion from 'size_t' to 'int/long', possible loss of data
+    #
+    # Amount of latter type is minimized by aliasing strlen to function of
+    # own desing and limiting its return value to 2GB-1 (see e_os.h). As
+    # per 0.9.8 release remaining warnings were explicitly examines and
+    # considered safe to ignore.
+    # 
+    $cflags=' /MD /W3 /Ox /Gs0 /GF /Gy /nologo -DWIN32_LEAN_AND_MEAN -DL_ENDIAN -DDSO_WIN32 -DOPENSSL_SYSNAME_WIN32 -DOPENSSL_SYSNAME_WINNT -DUNICODE -D_UNICODE';
+    $lflags="/nologo /subsystem:console /opt:ref";
+    }
+else
+    {
+    $cflags=' /MD /W3 /WX /G5 /Ox /O2 /Ob2 /Gs0 /GF /Gy /nologo -DOPENSSL_SYSNAME_WIN32 -DWIN32_LEAN_AND_MEAN -DL_ENDIAN -DDSO_WIN32';
+    $lflags="/nologo /subsystem:console /machine:I386 /opt:ref";
+    }
 $mlflags='';
 
 $out_def="out32";
 $mlflags='';
 
 $out_def="out32";
@@ -38,6 +57,7 @@ $exep='.exe';
 if ($no_sock)
        { $ex_libs=""; }
 else   { $ex_libs="wsock32.lib user32.lib gdi32.lib"; }
 if ($no_sock)
        { $ex_libs=""; }
 else   { $ex_libs="wsock32.lib user32.lib gdi32.lib"; }
+$ex_libs="$ex_libs bufferoverflowu.lib" if ($FLAVOR =~ /WIN64/);
 
 # static library stuff
 $mklib='lib';
 
 # static library stuff
 $mklib='lib';
@@ -115,6 +135,9 @@ EXHEADER= $(EXHEADER) $(INCO_D)\applink.c
 
 LIBS_DEP=$(LIBS_DEP) $(OBJ_D)\applink.obj
 CRYPTOOBJ=$(OBJ_D)\uplink.obj $(CRYPTOOBJ)
 
 LIBS_DEP=$(LIBS_DEP) $(OBJ_D)\applink.obj
 CRYPTOOBJ=$(OBJ_D)\uplink.obj $(CRYPTOOBJ)
+___
+       $banner.=<<'___' if ($FLAVOR =~ /WIN64/);
+CRYPTOOBJ=ms\uptable.obj $(CRYPTOOBJ)
 ___
        }
 
 ___
        }
 
@@ -140,6 +163,7 @@ sub do_lib_rule
                {
                local($ex)=($target =~ /O_SSL/)?' $(L_CRYPTO)':'';
                $ex.=' wsock32.lib gdi32.lib advapi32.lib user32.lib';
                {
                local($ex)=($target =~ /O_SSL/)?' $(L_CRYPTO)':'';
                $ex.=' wsock32.lib gdi32.lib advapi32.lib user32.lib';
+               $ex.=' bufferoverflowu.lib' if ($FLAVOR =~ /WIN64/);
                $ret.="\t\$(LINK) \$(MLFLAGS) $efile$target /def:ms/${Name}.def @<<\n  \$(SHLIB_EX_OBJ) $objs $ex\n<<\n";
                }
        $ret.="\n";
                $ret.="\t\$(LINK) \$(MLFLAGS) $efile$target /def:ms/${Name}.def @<<\n  \$(SHLIB_EX_OBJ) $objs $ex\n<<\n";
                }
        $ret.="\n";