From ae696ed5d75c1347c463e190629669d4fd673002 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Tue, 8 Apr 2014 17:49:16 +0000 Subject: [PATCH] intrin.h: Fix up bugs in the cr3 and msr intrinsics Don't include input and output regs in clobbers. Prefix some identifiers with __. Add a memory constraint to __readcr3 to prevent reordering. This constraint is heavy handed, but conservatively correct. Thanks to PaX Team for the suggestions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@205778 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Headers/Intrin.h | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/lib/Headers/Intrin.h b/lib/Headers/Intrin.h index e18b1a6588..6a63b71605 100644 --- a/lib/Headers/Intrin.h +++ b/lib/Headers/Intrin.h @@ -997,23 +997,20 @@ __readmsr(unsigned long __register) { // undefined. unsigned long __edx; unsigned long __eax; - __asm__ ("rdmsr" - : "=d"(__edx), "=a"(__eax) - : "c"(__register) - : "%ecx", "%edx", "%eax"); + __asm__ ("rdmsr" : "=d"(__edx), "=a"(__eax) : "c"(__register)); return (((unsigned __int64)__edx) << 32) | (unsigned __int64)__eax; } static __inline__ unsigned long __attribute__((always_inline, __nodebug__)) __readcr3(void) { - unsigned long value; - __asm__ __volatile__("mov %%cr3, %0" : "=q"(value)); - return value; + unsigned long __cr3_val; + __asm__ __volatile__ ("mov %%cr3, %0" : "=q"(__cr3_val) : : "memory"); + return __cr3_val; } static __inline__ void __attribute__((always_inline, __nodebug__)) -__writecr3(unsigned int Data) { - __asm__("mov %0, %%cr3" : : "q"(Data) : "memory"); +__writecr3(unsigned int __cr3_val) { + __asm__ ("mov %0, %%cr3" : : "q"(__cr3_val) : "memory"); } #ifdef __cplusplus -- 2.40.0