diff options
author | Mike Frysinger | 2014-08-06 00:59:50 +0200 |
---|---|---|
committer | Karel Zak | 2014-08-11 14:51:53 +0200 |
commit | 7845b91dbc7690064a2be6df690e4aaba728fb04 (patch) | |
tree | 9c5658f201b1bb621c3b768be1b443e1d2b78d3c /sys-utils/lscpu.c | |
parent | zramctl: improve option combination error messaging (diff) | |
download | kernel-qcow2-util-linux-7845b91dbc7690064a2be6df690e4aaba728fb04.tar.gz kernel-qcow2-util-linux-7845b91dbc7690064a2be6df690e4aaba728fb04.tar.xz kernel-qcow2-util-linux-7845b91dbc7690064a2be6df690e4aaba728fb04.zip |
lscpu: clean up vmware inline asm
This code is not PIC clean which means it fails to build on hardened
32bit x86 systems (i.e. building as PIE).
While here, optimize the existing cpuid logic slightly.
URL: https://bugs.gentoo.org/518936
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Diffstat (limited to 'sys-utils/lscpu.c')
-rw-r--r-- | sys-utils/lscpu.c | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c index 062dff501..9965eeb65 100644 --- a/sys-utils/lscpu.c +++ b/sys-utils/lscpu.c @@ -546,10 +546,9 @@ cpuid(unsigned int op, unsigned int *eax, unsigned int *ebx, __asm__( #if defined(__PIC__) && defined(__i386__) /* x86 PIC cannot clobber ebx -- gcc bitches */ - "pushl %%ebx;" + "xchg %%ebx, %%esi;" "cpuid;" - "movl %%ebx, %%esi;" - "popl %%ebx;" + "xchg %%esi, %%ebx;" : "=S" (*ebx), #else "cpuid;" @@ -656,12 +655,29 @@ read_hypervisor_powerpc(struct lscpu_desc *desc) #define VMWARE_BDOOR_PORT 0x5658 #define VMWARE_BDOOR_CMD_GETVERSION 10 -#define VMWARE_BDOOR(eax, ebx, ecx, edx) \ - __asm__("inl (%%dx), %%eax" : \ - "=a"(eax), "=c"(ecx), "=d"(edx), "=b"(ebx) : \ - "0"(VMWARE_BDOOR_MAGIC), "1"(VMWARE_BDOOR_CMD_GETVERSION), \ - "2"(VMWARE_BDOOR_PORT), "3"(0) : \ - "memory"); +static inline +void vmware_bdoor(uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx) +{ + __asm__( +#if defined(__PIC__) && defined(__i386__) + /* x86 PIC cannot clobber ebx -- gcc bitches */ + "xchg %%ebx, %%esi;" + "inl (%%dx), %%eax;" + "xchg %%esi, %%ebx;" + : "=S" (*ebx), +#else + "inl (%%dx), %%eax;" + : "=b" (*ebx), +#endif + "=a" (*eax), + "=c" (*ecx), + "=d" (*edx) + : "0" (VMWARE_BDOOR_MAGIC), + "1" (VMWARE_BDOOR_CMD_GETVERSION), + "2" (VMWARE_BDOOR_PORT), + "3" (0) + : "memory"); +} static jmp_buf segv_handler_env; @@ -697,7 +713,7 @@ is_vmware_platform(void) if (sigaction(SIGSEGV, &act, &oact)) err(EXIT_FAILURE, _("error: can not set signal handler")); - VMWARE_BDOOR(eax, ebx, ecx, edx); + vmware_bdoor(&eax, &ebx, &ecx, &edx); if (sigaction(SIGSEGV, &oact, NULL)) err(EXIT_FAILURE, _("error: can not restore signal handler")); |