From 180bf843b93c5ff9d16bbe8917ee8192fe675bf6 Mon Sep 17 00:00:00 2001 From: Daniel Kouchekinia Date: Mon, 23 Mar 2026 14:42:05 -0700 Subject: [PATCH] Add unsafe CPUID support This change adds unsafe wrappers with `#[allow(unused_unsafe)]` around calls to __cpuid and __cpuid_count to simultaneously support Rust <= 1.93 toolchains that consider __cpuid unsafe and Rust >= 1.94 (or >= nightly-2025-12-27) toolchains that consider __cpuid safe. --- src/hal.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/hal.rs b/src/hal.rs index b7a969f..116fb95 100644 --- a/src/hal.rs +++ b/src/hal.rs @@ -212,11 +212,27 @@ impl Hal for X64Hal { } fn asm_cpuid(&self, function: u32) -> CpuidResult { - __cpuid(function) + // SAFETY: The `cpuid` instruction is guaranteed to be supported on all x86_64 processors. + // + // `#[allow(unused_unsafe)]` is used here to simultaneously support Rust <= 1.93 toolchains + // that consider __cpuid unsafe and Rust >= 1.94 (or >= nightly-2025-12-27) toolchains that + // consider __cpuid safe. + #[allow(unused_unsafe)] + unsafe { + __cpuid(function) + } } fn asm_cpuid_ex(&self, function: u32, sub_function: u32) -> CpuidResult { - __cpuid_count(function, sub_function) + // SAFETY: The `cpuid` instruction is guaranteed to be supported on all x86_64 processors. + // + // `#[allow(unused_unsafe)]` is used here to simultaneously support Rust <= 1.93 toolchains + // that consider __cpuid_count unsafe and Rust >= 1.94 (or >= nightly-2025-12-27) toolchains + // that consider __cpuid_count safe. + #[allow(unused_unsafe)] + unsafe { + __cpuid_count(function, sub_function) + } } }