Fix for bug 227049. Prevent cache attacks on Windows 64 bits (AMD64). r=nelson,wtc

This commit is contained in:
julien.pierre.boogz%sun.com 2008-01-29 23:07:02 +00:00
Родитель 8bf2b98740
Коммит 2e7ca34bca
1 изменённых файлов: 33 добавлений и 4 удалений

Просмотреть файл

@ -53,16 +53,19 @@
* *
*/ */
#if defined(i386) || defined(__i386) || defined(__X86__) || defined (_M_IX86) || defined(__x86_64__) || defined(__x86_64) #if defined(i386) || defined(__i386) || defined(__X86__) || defined (_M_IX86) || defined(__x86_64__) || defined(__x86_64) || defined(_M_AMD64)
/* X86 processors have special instructions that tell us about the cache */ /* X86 processors have special instructions that tell us about the cache */
#include "string.h" #include "string.h"
#if defined(__x86_64__) || defined(__x86_64) #if defined(__x86_64__) || defined(__x86_64) || defined(_M_AMD64)
#define AMD_64 1 #define AMD_64 1
#endif #endif
/* Generic CPUID function */ /* Generic CPUID function */
#if defined(AMD_64) #if defined(AMD_64)
#if defined(__GNUC__)
static void cpuid(unsigned long op, unsigned long *eax, static void cpuid(unsigned long op, unsigned long *eax,
unsigned long *ebx, unsigned long *ecx, unsigned long *ebx, unsigned long *ecx,
unsigned long *edx) unsigned long *edx)
@ -74,7 +77,31 @@ static void cpuid(unsigned long op, unsigned long *eax,
"=d" (*edx) "=d" (*edx)
: "0" (op)); : "0" (op));
} }
#elif !defined(_MSC_VER)
#elif defined(_MSC_VER)
#include <intrin.h>
static void cpuid(unsigned long op, unsigned long *eax,
unsigned long *ebx, unsigned long *ecx,
unsigned long *edx)
{
int intrinsic_out[4];
__cpuid(intrinsic_out, op);
*eax = intrinsic_out[0];
*ebx = intrinsic_out[1];
*ecx = intrinsic_out[2];
*edx = intrinsic_out[3];
}
#endif
#else /* !defined(AMD_64) */
/* x86 */
#if defined(__GNUC__)
static void cpuid(unsigned long op, unsigned long *eax, static void cpuid(unsigned long op, unsigned long *eax,
unsigned long *ebx, unsigned long *ecx, unsigned long *ebx, unsigned long *ecx,
unsigned long *edx) unsigned long *edx)
@ -115,7 +142,7 @@ static unsigned long changeFlag(unsigned long flag)
return changedFlags ^ originalFlags; return changedFlags ^ originalFlags;
} }
#else #elif defined(_MSC_VER)
/* /*
* windows versions of the above assembler * windows versions of the above assembler
@ -166,6 +193,8 @@ static unsigned long changeFlag(unsigned long flag)
} }
#endif #endif
#endif
#if !defined(AMD_64) #if !defined(AMD_64)
#define AC_FLAG 0x40000 #define AC_FLAG 0x40000
#define ID_FLAG 0x200000 #define ID_FLAG 0x200000