Skip to content

Commit

Permalink
Fixed build when native_cpuid is not avalible on target
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacDynamo authored and gz committed Mar 19, 2022
1 parent 128a591 commit f0da9d6
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ extern crate serde;
#[macro_use]
extern crate bitflags;

#[cfg_attr(any(all(target_arch = "x86", not(target_env = "sgx"), target_feature = "sse"), all(target_arch = "x86_64", not(target_env = "sgx"))), has_native_cpuid)]

/// Uses Rust's `cpuid` function from the `arch` module.
#[cfg(has_native_cpuid)]
pub mod native_cpuid {
use crate::CpuIdResult;

Expand Down Expand Up @@ -105,6 +108,7 @@ mod std {
///
/// First parameter is cpuid leaf (EAX register value),
/// second optional parameter is the subleaf (ECX register value).
#[cfg(has_native_cpuid)]
#[macro_export]
macro_rules! cpuid {
($eax:expr) => {
Expand Down Expand Up @@ -175,6 +179,7 @@ impl CpuIdReader {
}
}

#[cfg(has_native_cpuid)]
impl Default for CpuIdReader {
fn default() -> Self {
Self {
Expand Down Expand Up @@ -223,6 +228,7 @@ pub struct CpuId {
supported_extended_leafs: u32,
}

#[cfg(has_native_cpuid)]
impl Default for CpuId {
fn default() -> CpuId {
CpuId::with_cpuid_fn(native_cpuid::cpuid_count)
Expand Down Expand Up @@ -304,6 +310,7 @@ const EAX_SVM_FEATURES: u32 = 0x8000_000A;

impl CpuId {
/// Return new CpuId struct.
#[cfg(has_native_cpuid)]
pub fn new() -> Self {
Self::default()
}
Expand Down Expand Up @@ -5129,9 +5136,9 @@ impl SoCVendorInfo {
pub fn get_vendor_brand(&self) -> Option<SoCVendorBrand> {
// Leaf 17H is valid if MaxSOCID_Index >= 3.
if self.eax >= 3 {
let r1 = cpuid!(EAX_SOC_VENDOR_INFO, 1);
let r2 = cpuid!(EAX_SOC_VENDOR_INFO, 2);
let r3 = cpuid!(EAX_SOC_VENDOR_INFO, 3);
let r1 = self.read.cpuid2(EAX_SOC_VENDOR_INFO, 1);
let r2 = self.read.cpuid2(EAX_SOC_VENDOR_INFO, 2);
let r3 = self.read.cpuid2(EAX_SOC_VENDOR_INFO, 3);
Some(SoCVendorBrand { data: [r1, r2, r3] })
} else {
None
Expand Down

0 comments on commit f0da9d6

Please sign in to comment.