#[allow(unused_macros)]
macro_rules! layout {
($t:ty, size = $size:expr, align = $align:expr) => {
const _: () = assert!(
::core::mem::size_of::<$t>() == $size && ::core::mem::align_of::<$t>() == $align,
concat!(
"layout of ",
stringify!($t),
" differs from the platform headers"
),
);
};
}
#[cfg(test)]
#[allow(unused_macros)]
macro_rules! same_layout {
($ours:ty, $theirs:ty $(, $a:ident $(. $an:ident)* => $b:ident $(. $bn:ident)*)* $(,)?) => {
const _: () = {
assert!(::core::mem::size_of::<$ours>() == ::core::mem::size_of::<$theirs>(),
concat!("size of ", stringify!($ours)));
assert!(::core::mem::align_of::<$ours>() == ::core::mem::align_of::<$theirs>(),
concat!("alignment of ", stringify!($ours)));
$(assert!(
::core::mem::offset_of!($ours, $a $(. $an)*)
== ::core::mem::offset_of!($theirs, $b $(. $bn)*),
concat!("offset of ", stringify!($ours), ".", stringify!($a $(. $an)*))
);)*
};
};
(prefix $ours:ty, $theirs:ty $(, $a:ident => $b:ident)* $(,)?) => {
const _: () = {
assert!(::core::mem::size_of::<$ours>() <= ::core::mem::size_of::<$theirs>(),
concat!("size of ", stringify!($ours)));
$(assert!(
::core::mem::offset_of!($ours, $a) == ::core::mem::offset_of!($theirs, $b),
concat!("offset of ", stringify!($ours), ".", stringify!($a))
);)*
};
};
}
mod detection;
mod environment;
mod pending;
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[allow(unsafe_code)]
mod x86;
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
pub(crate) use x86::invariant_tsc as x86_invariant_tsc;
#[cfg(any(
all(
any(target_os = "linux", target_os = "android"),
target_pointer_width = "64"
),
all(
target_os = "linux",
target_env = "gnu",
any(target_arch = "x86", target_arch = "arm")
)
))]
#[allow(unsafe_code)]
mod linux;
#[cfg(any(
all(
any(target_os = "linux", target_os = "android"),
target_pointer_width = "64"
),
all(
target_os = "linux",
target_env = "gnu",
any(target_arch = "x86", target_arch = "arm")
)
))]
pub(crate) use linux::*;
#[cfg(all(
any(target_os = "macos", target_os = "ios"),
target_pointer_width = "64"
))]
#[allow(unsafe_code)]
mod apple;
#[cfg(all(
any(target_os = "macos", target_os = "ios"),
target_pointer_width = "64"
))]
pub(crate) use apple::*;
#[cfg(windows)]
#[allow(unsafe_code)]
mod windows;
#[cfg(windows)]
pub(crate) use windows::*;
#[cfg(all(target_os = "freebsd", target_pointer_width = "64"))]
#[allow(unsafe_code)]
mod freebsd;
#[cfg(all(target_os = "freebsd", target_pointer_width = "64"))]
pub(crate) use freebsd::*;
#[cfg(not(any(
all(
any(target_os = "linux", target_os = "android"),
target_pointer_width = "64"
),
all(
target_os = "linux",
target_env = "gnu",
any(target_arch = "x86", target_arch = "arm")
),
all(
any(target_os = "macos", target_os = "ios"),
target_pointer_width = "64"
),
all(target_os = "freebsd", target_pointer_width = "64"),
windows
)))]
mod unsupported;
#[cfg(not(any(
all(
any(target_os = "linux", target_os = "android"),
target_pointer_width = "64"
),
all(
target_os = "linux",
target_env = "gnu",
any(target_arch = "x86", target_arch = "arm")
),
all(
any(target_os = "macos", target_os = "ios"),
target_pointer_width = "64"
),
all(target_os = "freebsd", target_pointer_width = "64"),
windows
)))]
pub(crate) use unsupported::*;
use crate::{cpu::Vendor, os::Source};
#[derive(Clone, Debug, PartialEq, Eq)]
pub(crate) struct OsFacts {
pub(crate) name: String,
pub(crate) version: Option<String>,
pub(crate) kernel: String,
pub(crate) distro: String,
pub(crate) distro_id: String,
pub(crate) release: Option<ReleaseFacts>,
pub(crate) edition: Option<String>,
pub(crate) codename: Option<String>,
pub(crate) name_source: Source,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub(crate) struct ReleaseFacts {
pub(crate) id: Option<String>,
pub(crate) id_like: Vec<String>,
pub(crate) name: Option<String>,
pub(crate) pretty_name: Option<String>,
pub(crate) version: Option<String>,
pub(crate) version_id: Option<String>,
pub(crate) codename: Option<String>,
pub(crate) variant_id: Option<String>,
pub(crate) build_id: Option<String>,
pub(crate) source: Source,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub(crate) struct CpuIdentity {
pub(crate) raw_name: Option<String>,
pub(crate) name: Option<String>,
pub(crate) vendor: Vendor,
}
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub(crate) struct TopologyFacts {
pub(crate) topology: crate::cpu::Topology,
pub(crate) caches: Vec<crate::cpu::Cache>,
pub(crate) numa: Vec<crate::cpu::NumaNode>,
}
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub(crate) struct HardwareFacts {
pub(crate) model_vendor: Option<String>,
pub(crate) model_name: Option<String>,
pub(crate) model_family: Option<String>,
pub(crate) firmware_kind: Option<crate::host::FirmwareKind>,
pub(crate) firmware_vendor: Option<String>,
pub(crate) firmware_version: Option<String>,
pub(crate) firmware_date: Option<String>,
pub(crate) board_vendor: Option<String>,
pub(crate) board_name: Option<String>,
pub(crate) board_version: Option<String>,
}
#[cfg(feature = "guard")]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) struct FsKind {
pub(crate) name: &'static str,
pub(crate) network: bool,
}