Struct GenericStaticKey

Source
pub struct GenericStaticKey<M: CodeManipulator, const S: bool> { /* private fields */ }
Expand description

Static key generic over code manipulator.

The M: CodeManipulator is required since when toggling the static key, the instructions recorded at associated jump entries need to be modified, which reside in .text section, which is a normally non-writable memory region. As a result, we need to change the protection of such memory region.

The const S: bool indicates the initial status of this key. This value is determined at compile time, and only affect the initial generation of branch layout. All subsequent manually disabling and enabling will not be affected by the initial status. The struct layout is also consistent with different initial status. As a result, it is safe to assign arbitrary status to the static key generic when using.

Implementations§

Source§

impl<M: CodeManipulator, const S: bool> GenericStaticKey<M, S>

Source

pub const fn initial_enabled(&self) -> bool

Whether initial status is true

Source

pub unsafe fn enable(&self)

Enable this static key (make the value to be true). Do nothing if current static key is already enabled.

§Safety

This method may be UB if called before global_init or called in parallel. Never call this method when there are multi-threads running. Spawn threads after this method is called. This method may manipulate code region memory protection, and if other threads are executing codes in the same code page, it may lead to unexpected behaviors.

Source

pub unsafe fn disable(&self)

Disable this static key (make the value to be false). Do nothing if current static key is already disabled.

§Safety

This method may be UB if called before global_init or called in parallel. Never call this method when there are multi-threads running. Spawn threads after this method is called. This method may manipulate code region memory protection, and if other threads are executing codes in the same code page, it may lead to unexpected behaviors.

Source

pub fn is_enabled(&self) -> bool

Get the current status of this static key

Auto Trait Implementations§

§

impl<M, const S: bool> !Freeze for GenericStaticKey<M, S>

§

impl<M, const S: bool> RefUnwindSafe for GenericStaticKey<M, S>
where M: RefUnwindSafe,

§

impl<M, const S: bool> Send for GenericStaticKey<M, S>
where M: Send,

§

impl<M, const S: bool> Sync for GenericStaticKey<M, S>
where M: Sync,

§

impl<M, const S: bool> Unpin for GenericStaticKey<M, S>
where M: Unpin,

§

impl<M, const S: bool> UnwindSafe for GenericStaticKey<M, S>
where M: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.