Skip to content

Commit

Permalink
Fix for no_std
Browse files Browse the repository at this point in the history
  • Loading branch information
Evian-Zhang committed Jul 24, 2024
1 parent 5f1127d commit b1ca34e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
10 changes: 10 additions & 0 deletions src/code_manipulate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,13 @@ impl CodeManipulator for NixCodeManipulator {
.expect("Unable to restore code region to non-writable");
}
}

pub(crate) struct DummyCodeManipulator;

impl CodeManipulator for DummyCodeManipulator {
unsafe fn mark_code_region_writable(_addr: *const core::ffi::c_void, _length: usize) -> Self {
Self
}

unsafe fn restore_code_region_protect(&self) {}
}
11 changes: 6 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ pub type StaticFalseKey = StaticKey<false>;
// however, it seems a Rust bug to erase sections marked with "R" (retained). If we specify
// --print-gc-sections for linker options, it's strange that linker itself does not
// erase it. IT IS SO STRANGE.
define_static_key_false!(DUMMY_STATIC_KEY);
static mut DUMMY_STATIC_KEY: NoStdStaticKey<code_manipulate::DummyCodeManipulator, true> =
NoStdStaticKey::new(true);

impl<M: CodeManipulator, const S: bool> NoStdStaticKey<M, S> {
/// Whether initial status is `true`
Expand Down Expand Up @@ -172,8 +173,8 @@ impl<M: CodeManipulator, const S: bool> NoStdStaticKey<M, S> {
if static_branch_unlikely!(DUMMY_STATIC_KEY) {
return;
}
let jump_entry_start_addr = unsafe { core::ptr::addr_of_mut!(JUMP_ENTRY_START) };
let jump_entry_stop_addr = unsafe { core::ptr::addr_of_mut!(JUMP_ENTRY_STOP) };
let jump_entry_start_addr = core::ptr::addr_of_mut!(JUMP_ENTRY_START);
let jump_entry_stop_addr = core::ptr::addr_of_mut!(JUMP_ENTRY_STOP);
let jump_entry_len =
unsafe { jump_entry_stop_addr.offset_from(jump_entry_start_addr) as usize };
let jump_entries =
Expand Down Expand Up @@ -211,8 +212,8 @@ impl<M: CodeManipulator, const S: bool> NoStdStaticKey<M, S> {
/// Count of jump entries in __static_keys section. Note that
/// there will be several dummy jump entries inside this section.
pub fn jump_entries_count() {
let jump_entry_start_addr = unsafe { core::ptr::addr_of_mut!(JUMP_ENTRY_START) };
let jump_entry_stop_addr = unsafe { core::ptr::addr_of_mut!(JUMP_ENTRY_STOP) };
let jump_entry_start_addr = core::ptr::addr_of_mut!(JUMP_ENTRY_START);
let jump_entry_stop_addr = core::ptr::addr_of_mut!(JUMP_ENTRY_STOP);
unsafe { jump_entry_stop_addr.offset_from(jump_entry_start_addr) as usize };
}

Expand Down

0 comments on commit b1ca34e

Please sign in to comment.