On Thu, Jan 23, 2020 at 11:42:55AM +0000, Daniel P. Berrangé wrote:
Instead of relying on GNULIb's uname() impl, directly use the
Windows API for determining CPU architecture.
Signed-off-by: Daniel P. Berrangé <berrange(a)redhat.com>
---
src/util/virarch.c | 52 +++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 51 insertions(+), 1 deletion(-)
diff --git a/src/util/virarch.c b/src/util/virarch.c
index b132e178c3..553d21c97c 100644
--- a/src/util/virarch.c
+++ b/src/util/virarch.c
@@ -154,6 +159,50 @@ virArch virArchFromString(const char *archstr)
* uname 'machine' field, since this will canonicalize
* architecture names like 'amd64' into 'x86_64'.
*/
+#ifdef WIN32
+
+/*
+ * Missing in ming64 headers 6.0.0, but defined as '12' in:
+ *
+ *
https://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/ns-sysinfoa...
+ */
+# ifndef PROCESSOR_ARCHITECTURE_ARM64
+# define PROCESSOR_ARCHITECTURE_ARM64 12
+# endif
+
+virArch virArchFromHost(void)
+{
+ SYSTEM_INFO info;
+
+ GetSystemInfo(&info);
+
+ switch (info.wProcessorArchitecture) {
+ case PROCESSOR_ARCHITECTURE_AMD64:
+ return VIR_ARCH_X86_64;
+ case PROCESSOR_ARCHITECTURE_IA64:
+ return VIR_ARCH_ITANIUM;
+ case PROCESSOR_ARCHITECTURE_INTEL:
+ case PROCESSOR_ARCHITECTURE_IA32_ON_WIN64:
+ return VIR_ARCH_I686;
+ case PROCESSOR_ARCHITECTURE_MIPS:
+ return VIR_ARCH_MIPS;
+ case PROCESSOR_ARCHITECTURE_ALPHA:
+ return VIR_ARCH_ALPHA;
+ case PROCESSOR_ARCHITECTURE_PPC:
+ return VIR_ARCH_PPC;
+ case PROCESSOR_ARCHITECTURE_SHX:
+ return VIR_ARCH_SH4;
+ case PROCESSOR_ARCHITECTURE_ARM:
+ return VIR_ARCH_ARMV7L;
+ case PROCESSOR_ARCHITECTURE_ARM64:
+ return VIR_ARCH_AARCH64;
+ default:
+ VIR_WARN("Unknown host arch %d, report to libvir-list(a)redhat.com",
Just a tiny nit, I would wrap %d with single quotes to make it obvious
it's dynamic part of the error message.
Reviewed-by: Pavel Hrdina <phrdina(a)redhat.com>