summaryrefslogtreecommitdiffstats
path: root/testing/open-vm-tools/checkvm-pie-safety.patch
blob: 5a879c94b786e001d60bded66268776bd0c56193 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
From: Gordon Malm <gengor@gentoo.org>

Make inline asm PIC-safe (do not clobber ebx).

Thanks and credit to Anthony Basile for all his help and testing.

Reference: http://bugs.gentoo.org/200376

--- a/checkvm/checkvm.c
+++ b/checkvm/checkvm.c
@@ -79,8 +79,16 @@
 {
    uint32 eax, ebx, ecx, edx;
    
-   __asm__ volatile("inl (%%dx)" :
-   	            "=a"(eax), "=c"(ecx), "=d"(edx), "=b"(ebx) :
+   __asm__ volatile(
+#if defined __PIC__ && !vm_x86_64 // %ebx is reserved by the compiler.
+		    "movl %%ebx, %3    \n\t"
+		    "inl (%%dx)        \n\t"
+		    "xchgl %%ebx, %3   \n\t" :
+		    "=a"(eax), "=c"(ecx), "=d"(edx), "=r"(ebx) :
+#else
+		    "inl (%%dx)" :
+		    "=a"(eax), "=c"(ecx), "=d"(edx), "=b"(ebx) :
+#endif
 		    "0"(BDOOR_MAGIC), "1"(BDOOR_CMD_GETVERSION),
 		    "2"(BDOOR_PORT) : "memory");
    version[0] = eax;
@@ -96,8 +104,16 @@
 {
    uint32 eax, ebx, ecx, edx;
    
-   __asm__ volatile("inl (%%dx)" :
-   	            "=a"(eax), "=c"(ecx), "=d"(edx), "=b"(ebx) :
+   __asm__ volatile(
+#if defined __PIC__ && !vm_x86_64 // %ebx is reserved by the compiler.
+		    "movl %%ebx, %3    \n\t"
+		    "inl (%%dx)        \n\t"
+		    "xchgl %%ebx, %3   \n\t" :
+		    "=a"(eax), "=c"(ecx), "=d"(edx), "=r"(ebx) :
+#else
+		    "inl (%%dx)" :
+		    "=a"(eax), "=c"(ecx), "=d"(edx), "=b"(ebx) :
+#endif
 		    "0"(BDOOR_MAGIC), "1"(BDOOR_CMD_GETHWVERSION),
 		    "2"(BDOOR_PORT) : "memory");
    *hwVersion = eax;
@@ -112,8 +128,16 @@
 {
    uint32 eax, ebx, ecx, edx;
    
-   __asm__ volatile("inl (%%dx)" :
-   		    "=a"(eax), "=c"(ecx), "=d"(edx), "=b"(ebx) :
+   __asm__ volatile(
+#if defined __PIC__ && !vm_x86_64 // %ebx is reserved by the compiler.
+		    "movl %%ebx, %3    \n\t"
+		    "inl (%%dx)        \n\t"
+		    "xchgl %%ebx, %3   \n\t" :
+		    "=a"(eax), "=c"(ecx), "=d"(edx), "=r"(ebx) :
+#else
+		    "inl (%%dx)" :
+		    "=a"(eax), "=c"(ecx), "=d"(edx), "=b"(ebx) :
+#endif
 		    "0"(BDOOR_MAGIC), "1"(BDOOR_CMD_GETSCREENSIZE),
 		    "2"(BDOOR_PORT) : "memory");
    *screensize = eax;