From f62a878442e750780b72282aef15f69b241623a7 Mon Sep 17 00:00:00 2001 From: Godones Date: Wed, 30 Oct 2024 19:47:13 +0800 Subject: [PATCH] feat: add bare metal support --- src/os/mod.rs | 6 ++++++ src/os/none.rs | 31 +++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 src/os/none.rs diff --git a/src/os/mod.rs b/src/os/mod.rs index 131a528..f4c5164 100644 --- a/src/os/mod.rs +++ b/src/os/mod.rs @@ -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::*; diff --git a/src/os/none.rs b/src/os/none.rs new file mode 100644 index 0000000..0765177 --- /dev/null +++ b/src/os/none.rs @@ -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(addr: *mut c_void, data: &[u8; L]) { + core::ptr::copy_nonoverlapping(data.as_ptr(), addr.cast(), L); + } +}