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>
impl<M: CodeManipulator, const S: bool> GenericStaticKey<M, S>
Sourcepub const fn initial_enabled(&self) -> bool
pub const fn initial_enabled(&self) -> bool
Whether initial status is true
Sourcepub unsafe fn enable(&self)
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.
Sourcepub unsafe fn disable(&self)
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.
Sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Get the current status of this static key