Skip to content

Commit

Permalink
feat: add bare metal support
Browse files Browse the repository at this point in the history
  • Loading branch information
Godones authored and Evian-Zhang committed Oct 30, 2024
1 parent 7d2ab8f commit 8526b17
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/os/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@ pub use macos::*;
mod windows;
#[cfg(target_os = "windows")]
pub use windows::*;

#[cfg(target_os = "none")]
mod none;

#[cfg(target_os = "none")]
pub use none::*;
31 changes: 31 additions & 0 deletions src/os/none.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//! Other OS-specific implementations
use crate::{code_manipulate::CodeManipulator, JumpEntry};
use core::ffi::c_void;

/// Name and attribute of section storing jump entries
#[doc(hidden)]
#[macro_export]
macro_rules! os_static_key_sec_name_attr {
() => {
"__static_keys, \"awR\""
};
}

extern "Rust" {
/// Address of this static is the start address of __static_keys section
#[link_name = "__start___static_keys"]
pub static mut JUMP_ENTRY_START: JumpEntry;
/// Address of this static is the end address of __static_keys section (excluded)
#[link_name = "__stop___static_keys"]
pub static mut JUMP_ENTRY_STOP: JumpEntry;
}

/// Arch-specific [`CodeManipulator`] using [`libc`] with `mprotect`.
pub struct ArchCodeManipulator;

impl CodeManipulator for crate::os::ArchCodeManipulator {
unsafe fn write_code<const L: usize>(addr: *mut c_void, data: &[u8; L]) {
core::ptr::copy_nonoverlapping(data.as_ptr(), addr.cast(), L);
}
}

0 comments on commit 8526b17

Please sign in to comment.