ExecutableMemory

Struct ExecutableMemory 

Source
pub struct ExecutableMemory { /* private fields */ }
Expand description

executable memory region for trampolines

automatically freed when dropped

Implementations§

Source§

impl ExecutableMemory

Source

pub fn allocate_near(target: usize, size: usize) -> Result<Self>

allocate executable memory near a target address

tries to allocate within ±2GB of target for relative jumps. falls back to any available address if near allocation fails.

Source

pub fn allocate(size: usize) -> Result<Self>

allocate executable memory at any available address

Source

pub fn base(&self) -> usize

get base address

Source

pub fn size(&self) -> usize

get total allocated size

Source

pub fn used(&self) -> usize

get used bytes

Source

pub fn available(&self) -> usize

get available bytes

Source

pub fn write(&mut self, code: &[u8]) -> Result<usize>

write code to the memory region

returns the address where the code was written

Source

pub fn ptr_at(&self, offset: usize) -> *mut u8

get pointer at offset

Source

pub fn read_at(&self, offset: usize, len: usize) -> Result<&[u8]>

read bytes from offset

Source

pub fn contains(&self, addr: usize) -> bool

check if an address is within this memory region

Source

pub fn is_near(&self, target: usize) -> bool

check if this memory is within rel32 range of target

Source

pub fn flush_icache(&self) -> Result<()>

flush instruction cache for this region

Source

pub fn leak(self) -> *mut u8

take ownership without freeing

Trait Implementations§

Source§

impl Drop for ExecutableMemory

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for ExecutableMemory

Source§

impl Sync for ExecutableMemory

Auto Trait Implementations§

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.