Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/cpuid/src/brand_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,18 @@ impl BrandString {

/// Creates a brand string, initialized from the CPUID leaves 0x80000002 through 0x80000004
/// of the host CPU.
#[allow(unused_unsafe)]
pub fn from_host_cpuid() -> Result<Self, Error> {
let mut this = Self::new();
let mut cpuid_regs = host_cpuid(0x8000_0000);
let mut cpuid_regs = unsafe { host_cpuid(0x8000_0000) };

if cpuid_regs.eax < 0x8000_0004 {
// Brand string not supported by the host CPU
return Err(Error::NotSupported);
}

for leaf in 0x8000_0002..=0x8000_0004 {
cpuid_regs = host_cpuid(leaf);
cpuid_regs = unsafe { host_cpuid(leaf) };
this.set_reg_for_leaf(leaf, Reg::EAX, cpuid_regs.eax);
this.set_reg_for_leaf(leaf, Reg::EBX, cpuid_regs.ebx);
this.set_reg_for_leaf(leaf, Reg::ECX, cpuid_regs.ecx);
Expand Down
5 changes: 3 additions & 2 deletions src/cpuid/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub enum Error {
}

#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[allow(unused_unsafe)]
pub fn get_cpuid(function: u32, count: u32) -> Result<CpuidResult, Error> {
// TODO: replace with validation based on `has_cpuid()` when it becomes stable:
// https://doc.rust-lang.org/core/arch/x86/fn.has_cpuid.html
Expand All @@ -35,15 +36,15 @@ pub fn get_cpuid(function: u32, count: u32) -> Result<CpuidResult, Error> {
}

// this is safe because the host supports the `cpuid` instruction
let max_function = __get_cpuid_max(function & leaf_0x80000000::LEAF_NUM).0;
let max_function = unsafe { __get_cpuid_max(function & leaf_0x80000000::LEAF_NUM).0 };
if function > max_function {
return Err(Error::InvalidParameters(format!(
"Function not supported: 0x{function:x}"
)));
}

// this is safe because the host supports the `cpuid` instruction
let entry = __cpuid_count(function, count);
let entry = unsafe { __cpuid_count(function, count) };
if entry.eax == 0 && entry.ebx == 0 && entry.ecx == 0 && entry.edx == 0 {
return Err(Error::InvalidParameters(format!("Invalid count: {count}")));
}
Expand Down
Loading