From 25c83f0d0b8ae99e7aa237fdb19f1c60890adca9 Mon Sep 17 00:00:00 2001 From: The Tumultuous Unicorn Of Darkness Date: Sat, 27 Jul 2024 17:45:05 +0200 Subject: [PATCH] Provide raw for logical CPU 0 in cpuid_get_raw_data_core() even if set_cpu_affinity() is not supported On OpenBSD, set_cpu_affinity() is not supported, so cpuid_get_raw_data_core() always returns ERR_INVCNB. This commit allows to provide raw data for at least one CPU core. --- libcpuid/cpuid_main.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libcpuid/cpuid_main.c b/libcpuid/cpuid_main.c index 3f925d2..a2b882e 100644 --- a/libcpuid/cpuid_main.c +++ b/libcpuid/cpuid_main.c @@ -1320,9 +1320,12 @@ int cpuid_get_raw_data_core(struct cpu_raw_data_t* data, logical_cpu_t logical_c if (logical_cpu != (logical_cpu_t) -1) { debugf(2, "Getting raw dump for logical CPU %u\n", logical_cpu); - if (!set_cpu_affinity(logical_cpu)) - return cpuid_set_error(ERR_INVCNB); - affinity_saved = save_cpu_affinity(); + if (set_cpu_affinity(logical_cpu)) + affinity_saved = save_cpu_affinity(); + else + /* Never return ERR_INVCNB for logical CPU 0 (in case set_cpu_affinity() is not supported) */ + if (logical_cpu > 0) + return cpuid_set_error(ERR_INVCNB); } #if defined(PLATFORM_X86) || defined(PLATFORM_X64)