From: Andy Polyakov Date: Mon, 4 Jul 2005 23:24:12 +0000 (+0000) Subject: To secure Win64 API I'm throwing in this minimalistic Win64 support. X-Git-Tag: OpenSSL_0_9_8~7 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=dabaea8048988709af709e7d329dff311635ff84;p=oweals%2Fopenssl.git To secure Win64 API I'm throwing in this minimalistic Win64 support. --- 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/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 74bfc99ffe..f949bf27d6 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";