CPUID modifies EAX, EBX, ECX and EDX, but the inline asm clobber list is
incomplete. Use the __get_cpuid() intrinsic instead.
Fixes rootfs_setup(r, argv) crashing due to impossible r != &rootfs due
to clobbered registers.
Assisted-by: qwen3.8-flash-next # finding the bug
---
tools/test-runner.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/tools/test-runner.c b/tools/test-runner.c
index 9eaf39d35..2de05e26d 100644
--- a/tools/test-runner.c
+++ b/tools/test-runner.c
@@ -33,6 +33,11 @@
#include <sys/param.h>
#include <sys/reboot.h>
+#if defined(__GNUC__) && (defined(__i386__) || defined(__amd64__))
+#include <cpuid.h>
+#define HAVE_GET_CPUID
+#endif
+
#include "bluetooth/bluetooth.h"
#include "bluetooth/hci.h"
#include "bluetooth/hci_lib.h"
@@ -306,12 +311,10 @@ static char *const qemu_envp[] = {
static void check_virtualization(void)
{
-#if defined(__GNUC__) && (defined(__i386__) || defined(__amd64__))
- uint32_t ecx;
+#ifdef HAVE_GET_CPUID
+ unsigned int eax, ebx, ecx, edx;
- __asm__ __volatile__("cpuid" : "=c" (ecx) : "a" (1) : "memory");
-
- if (!!(ecx & (1 << 5)))
+ if (__get_cpuid(1, &eax, &ebx, &ecx, &edx) && (ecx & (1 << 5)))
printf("Found support for Virtual Machine eXtensions\n");
#endif
}--
2.55.0