pub struct Smap(/* private fields */);Expand description
A helper type that provides SMAP related methods.
This type can only be instatiated if SMAP is supported by the CPU.
Implementations§
Source§impl Smap
impl Smap
Sourcepub fn new() -> Option<Self>
pub fn new() -> Option<Self>
Checks if the CPU supports SMAP and returns a Smap instance if
supported or None if not.
This function uses CPUID to determine if SMAP is supported by the CPU.
Note that this function does not check whether SMAP has be enabled in CR4.
Sourcepub const unsafe fn new_unchecked() -> Self
pub const unsafe fn new_unchecked() -> Self
Sourcepub fn is_enabled(self) -> bool
pub fn is_enabled(self) -> bool
Returns whether the RFlags::ALIGNMENT_CHECK flag is unset.
Note that SMAP also requires
Cr4Flags::SUPERVISOR_MODE_ACCESS_PREVENTION to be set. This
function does not check CR4 because doing so is much slower than just
checking the AC flag.
Sourcepub fn disable(self)
pub fn disable(self)
Disable SMAP access checks by setting RFlags::ALIGNMENT_CHECK using
the stac instruction.
This will do nothing if SMAP access checks are already disabled.
Sourcepub fn enable(self)
pub fn enable(self)
Enable SMAP access checks by clearing RFlags::ALIGNMENT_CHECK using
the clac instruction.
This will do nothing if SMAP access checks are already enabled.
Sourcepub fn without_smap<F, R>(self, f: F) -> Rwhere
F: FnOnce() -> R,
pub fn without_smap<F, R>(self, f: F) -> Rwhere
F: FnOnce() -> R,
Call a closure with SMAP disabled.
This function disables SMAP before calling the closure and restores the SMAP state afterwards.