pub fn is_supported() -> bool {
cfg!(target_os = "linux") && cpuid_pku_bit_set()
}
#[cfg(target_arch = "x86_64")]
fn cpuid_pku_bit_set() -> bool {
is_intel_cpu() && {
#[allow(
unused_unsafe,
reason = "rust is transitioning to `__cpuid` being a safe function"
)]
let result = unsafe { core::arch::x86_64::__cpuid(0x07) };
(result.ecx & 0b1000) != 0
}
}
#[cfg(not(target_arch = "x86_64"))]
fn cpuid_pku_bit_set() -> bool {
false
}
#[cfg(target_arch = "x86_64")]
fn is_intel_cpu() -> bool {
#[allow(unused_unsafe, reason = "see above about __cpuid")]
let result = unsafe { core::arch::x86_64::__cpuid(0) };
result.ebx == u32::from_le_bytes(*b"Genu")
&& result.edx == u32::from_le_bytes(*b"ineI")
&& result.ecx == u32::from_le_bytes(*b"ntel")
}