summaryrefslogtreecommitdiffstats
path: root/crypto/cryptlib.c
diff options
context:
space:
mode:
authorAndy Polyakov <appro@openssl.org>2011-06-28 13:31:58 +0000
committerAndy Polyakov <appro@openssl.org>2011-06-28 13:31:58 +0000
commit0ec55604c0aa0574fbb04bef9e9617d9ea980568 (patch)
tree8c604563c2d8dc89bb2c50a76ed4d222af805179 /crypto/cryptlib.c
parent500007c9ed9bdd12db519476fc5aa072fc2f474c (diff)
Expand OPENSSL_ia32cap_P to 64 bits. It might appear controversial, because
such operation can be considered as breaking binary compatibility. However! OPNESSL_ia32cap_P is accessed by application through pointer returned by OPENSSL_ia32cap_loc() and such change of *internal* OPENSSL_ia32cap_P declaration is possible specifically on little-endian platforms, such as x86[_64] ones in question. In addition, if 32-bit application calls OPENSSL_ia32cap_loc(), it clears upper half of capability vector maintaining the illusion that it's still 32 bits wide.
Diffstat (limited to 'crypto/cryptlib.c')
-rw-r--r--crypto/cryptlib.c31
1 files changed, 26 insertions, 5 deletions
diff --git a/crypto/cryptlib.c b/crypto/cryptlib.c
index 072b341ca2..8384b5d339 100644
--- a/crypto/cryptlib.c
+++ b/crypto/cryptlib.c
@@ -665,28 +665,49 @@ const char *CRYPTO_get_lock_name(int type)
defined(__INTEL__) || \
defined(__x86_64) || defined(__x86_64__) || defined(_M_AMD64) || defined(_M_X64)
-unsigned long OPENSSL_ia32cap_P=0;
-unsigned long *OPENSSL_ia32cap_loc(void) { return &OPENSSL_ia32cap_P; }
+unsigned int OPENSSL_ia32cap_P[2];
+unsigned long *OPENSSL_ia32cap_loc(void)
+{ if (sizeof(long)==4)
+ /*
+ * If 32-bit application pulls address of OPENSSL_ia32cap_P[0]
+ * clear second element to maintain the illusion that vector
+ * is 32-bit.
+ */
+ OPENSSL_ia32cap_P[1]=0;
+ return (unsigned long *)OPENSSL_ia32cap_P;
+}
#if defined(OPENSSL_CPUID_OBJ) && !defined(OPENSSL_NO_ASM) && !defined(I386_ONLY)
#define OPENSSL_CPUID_SETUP
+#if defined(_WIN32)
+typedef unsigned __int64 IA32CAP;
+#else
+typedef unsigned long long IA32CAP;
+#endif
void OPENSSL_cpuid_setup(void)
{ static int trigger=0;
- unsigned long OPENSSL_ia32_cpuid(void);
+ IA32CAP OPENSSL_ia32_cpuid(void);
+ IA32CAP vec;
char *env;
if (trigger) return;
trigger=1;
if ((env=getenv("OPENSSL_ia32cap")))
- OPENSSL_ia32cap_P = strtoul(env,NULL,0)|(1<<10);
+#if defined(_WIN32)
+ { if (!sscanf(env,"%I64i",&vec)) vec = strtoul(env,NULL,0); }
+#else
+ vec = strtoull(env,NULL,0);
+#endif
else
- OPENSSL_ia32cap_P = OPENSSL_ia32_cpuid()|(1<<10);
+ vec = OPENSSL_ia32_cpuid();
/*
* |(1<<10) sets a reserved bit to signal that variable
* was initialized already... This is to avoid interference
* with cpuid snippets in ELF .init segment.
*/
+ OPENSSL_ia32cap_P[0] = (unsigned int)vec|(1<<10);
+ OPENSSL_ia32cap_P[1] = (unsigned int)(vec>>32);
}
#endif