summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjulien.pierre.boogz%sun.com <devnull@localhost>2008-01-29 23:06:00 +0000
committerjulien.pierre.boogz%sun.com <devnull@localhost>2008-01-29 23:06:00 +0000
commit2765e3640bb2ed6149b33afc99fdf62def9d21d8 (patch)
treeb012cc1ff951ac654af32c569bf4dc41416808a9
parent3e3f6e04835cd00b689cb8df80058b5d0ec7b481 (diff)
parent85fff929c218a94bd32363107878a4bd00944b71 (diff)
downloadnss-hg-2765e3640bb2ed6149b33afc99fdf62def9d21d8.tar.gz
Fix for bug 227049 . Prevent cache attacks on Windows 64 bits (AMD64) . r=nelson,wtc
-rw-r--r--security/nss/lib/freebl/mpi/mpcpucache.c37
1 files changed, 33 insertions, 4 deletions
diff --git a/security/nss/lib/freebl/mpi/mpcpucache.c b/security/nss/lib/freebl/mpi/mpcpucache.c
index 8adbd33c6..03bd96446 100644
--- a/security/nss/lib/freebl/mpi/mpcpucache.c
+++ b/security/nss/lib/freebl/mpi/mpcpucache.c
@@ -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 */
#include "string.h"
-#if defined(__x86_64__) || defined(__x86_64)
+#if defined(__x86_64__) || defined(__x86_64) || defined(_M_AMD64)
#define AMD_64 1
#endif
/* Generic CPUID function */
#if defined(AMD_64)
+
+#if defined(__GNUC__)
+
static void cpuid(unsigned long op, unsigned long *eax,
unsigned long *ebx, unsigned long *ecx,
unsigned long *edx)
@@ -74,7 +77,31 @@ static void cpuid(unsigned long op, unsigned long *eax,
"=d" (*edx)
: "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,
unsigned long *ebx, unsigned long *ecx,
unsigned long *edx)
@@ -115,7 +142,7 @@ static unsigned long changeFlag(unsigned long flag)
return changedFlags ^ originalFlags;
}
-#else
+#elif defined(_MSC_VER)
/*
* windows versions of the above assembler
@@ -166,6 +193,8 @@ static unsigned long changeFlag(unsigned long flag)
}
#endif
+#endif
+
#if !defined(AMD_64)
#define AC_FLAG 0x40000
#define ID_FLAG 0x200000