Skip to content
Merged
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
24 changes: 16 additions & 8 deletions crates/runtime/src/mpk/pkru.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,24 @@ pub fn write(pkru: u32) {
}
}

/// Check the `ECX.PKU` flag (bit 3) of the `07h` `CPUID` leaf; see the
/// Intel Software Development Manual, vol 3a, section 2.7.
/// Check the `ECX.PKU` flag (bit 3) of the `07h` `CPUID` leaf; see the Intel
/// Software Development Manual, vol 3a, section 2.7. This flag is only set on
/// Intel CPUs, so this function also checks the `CPUID` vendor string.
pub fn has_cpuid_bit_set() -> bool {
// TODO: disable MPK support until the following issue is resolved:
// https://github.com/bytecodealliance/wasmtime/issues/7445
if true {
return false;
}
let result = unsafe { std::arch::x86_64::__cpuid(0x07) };
(result.ecx & 0b100) != 0
is_intel_cpu() && (result.ecx & 0b100) != 0
}

/// Check the `CPUID` vendor string for `GenuineIntel`; see the Intel Software
/// Development Manual, vol 2a, `CPUID` description.
pub fn is_intel_cpu() -> bool {
// To read the CPU vendor string, we pass 0 in EAX and read 12 ASCII bytes
// from EBX, EDX, and ECX (in that order).
let result = unsafe { std::arch::x86_64::__cpuid(0) };
// Then we check if the vendor string matches "GenuineIntel".
result.ebx == u32::from_le_bytes(*b"Genu")
&& result.edx == u32::from_le_bytes(*b"ineI")
&& result.ecx == u32::from_le_bytes(*b"ntel")
}

#[cfg(test)]
Expand Down