From 1875e6db29fb832d3cac101024ccb1f690b35028 Mon Sep 17 00:00:00 2001 From: Andy Polyakov Date: Tue, 5 Jul 2005 11:44:45 +0000 Subject: [PATCH 1/1] Pull up Win64 support from 0.9.8. --- Configure | 4 +-- INSTALL.W32 | 1 + INSTALL.W64 | 66 +++++++++++++++++++++++++++++++++++++++++++++++ crypto/cryptlib.c | 2 +- crypto/mem_dbg.c | 8 ++++++ e_os.h | 19 ++++++++++++++ ms/do_win64a.bat | 9 +++++++ ms/do_win64i.bat | 9 +++++++ util/mk1mf.pl | 7 +++-- util/pl/VC-32.pl | 28 ++++++++++++++++++-- 10 files changed, 146 insertions(+), 7 deletions(-) create mode 100644 INSTALL.W64 create mode 100755 ms/do_win64a.bat create mode 100755 ms/do_win64i.bat diff --git a/Configure b/Configure index de5366b723..933246a157 100755 --- 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 -"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", diff --git a/INSTALL.W32 b/INSTALL.W32 index 0f6c302f0d..f18f249677 100644 --- a/INSTALL.W32 +++ b/INSTALL.W32 @@ -3,6 +3,7 @@ ---------------------------------- [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 diff --git a/INSTALL.W64 b/INSTALL.W64 new file mode 100644 index 0000000000..9fa7a19205 --- /dev/null +++ b/INSTALL.W64 @@ -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. + diff --git a/crypto/cryptlib.c b/crypto/cryptlib.c index e73d086eed..21332378cf 100644 --- a/crypto/cryptlib.c +++ b/crypto/cryptlib.c @@ -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; } -int OPENSSL_NONPIC_relocated=0; #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 +int OPENSSL_NONPIC_relocated = 0; #if !defined(OPENSSL_CPUID_SETUP) void OPENSSL_cpuid_setup(void) {} #endif diff --git a/crypto/mem_dbg.c b/crypto/mem_dbg.c index 557516bde9..8316485217 100644 --- a/crypto/mem_dbg.c +++ b/crypto/mem_dbg.c @@ -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) { +#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); +#endif } /* static unsigned long mem_hash(MEM *a) */ diff --git a/e_os.h b/e_os.h index 0b2b1cca67..965d1aa8d7 100644 --- a/e_os.h +++ b/e_os.h @@ -266,6 +266,16 @@ extern "C" { # include # include # include +# 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 # endif # include @@ -426,6 +436,15 @@ extern "C" { # elif !defined(__DJGPP__) # include 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); } diff --git a/ms/do_win64a.bat b/ms/do_win64a.bat new file mode 100755 index 0000000000..825c690221 --- /dev/null +++ b/ms/do_win64a.bat @@ -0,0 +1,9 @@ + +perl util\mkfiles.pl >MINFO +perl ms\uplink.pl win64a > ms\uptable.asm +ml64 -c -Foms\uptable.obj ms\uptable.asm +perl util\mk1mf.pl no-asm VC-WIN64A >ms\nt.mak +perl util\mk1mf.pl dll no-asm VC-WIN64A >ms\ntdll.mak + +perl util\mkdef.pl 32 libeay > ms\libeay32.def +perl util\mkdef.pl 32 ssleay > ms\ssleay32.def diff --git a/ms/do_win64i.bat b/ms/do_win64i.bat new file mode 100755 index 0000000000..7bfc2f1818 --- /dev/null +++ b/ms/do_win64i.bat @@ -0,0 +1,9 @@ + +perl util\mkfiles.pl >MINFO +perl ms\uplink.pl win64i > ms\uptable.asm +ias -o ms\uptable.obj ms\uptable.asm +perl util\mk1mf.pl no-asm VC-WIN64I >ms\nt.mak +perl util\mk1mf.pl dll no-asm VC-WIN64I >ms\ntdll.mak + +perl util\mkdef.pl 32 libeay > ms\libeay32.def +perl util\mkdef.pl 32 ssleay > ms\ssleay32.def diff --git a/util/mk1mf.pl b/util/mk1mf.pl index fa0fbe3673..6090a2b5a6 100755 --- a/util/mk1mf.pl +++ b/util/mk1mf.pl @@ -24,6 +24,8 @@ $infile="MINFO"; %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", @@ -120,9 +122,10 @@ $bin_dir=(defined($VARS{'BIN'}))?$VARS{'BIN'}:''; $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") diff --git a/util/pl/VC-32.pl b/util/pl/VC-32.pl index 710c4cd129..d39715cdad 100644 --- a/util/pl/VC-32.pl +++ b/util/pl/VC-32.pl @@ -11,8 +11,27 @@ $rm='del'; # 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"; @@ -38,6 +57,7 @@ $exep='.exe'; 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'; @@ -115,6 +135,9 @@ EXHEADER= $(EXHEADER) $(INCO_D)\applink.c 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'; + $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"; -- 2.34.1