wiggle::wasmtime_crate

Trait CustomCodeMemory

pub trait CustomCodeMemory: Send + Sync {
    // Required methods
    fn required_alignment(&self) -> usize;
    fn publish_executable(
        &self,
        ptr: *const u8,
        len: usize,
    ) -> Result<(), Error>;
    fn unpublish_executable(
        &self,
        ptr: *const u8,
        len: usize,
    ) -> Result<(), Error>;
}
Expand description

Interface implemented by an embedder to provide custom implementations of code-memory protection and execute permissions.

Required Methods§

fn required_alignment(&self) -> usize

The minimal alignment granularity for an address region that can be made executable.

Wasmtime does not assume the system page size for this because custom code-memory protection can be used when all other uses of virtual memory are disabled.

fn publish_executable(&self, ptr: *const u8, len: usize) -> Result<(), Error>

Publish a region of memory as executable.

This should update permissions from the default RW (readable/writable but not executable) to RX (readable/executable but not writable), enforcing W^X discipline.

If the platform requires any data/instruction coherence action, that should be performed as part of this hook as well.

ptr and ptr.offset(len) are guaranteed to be aligned as per required_alignment().

fn unpublish_executable(&self, ptr: *const u8, len: usize) -> Result<(), Error>

Unpublish a region of memory.

This should perform the opposite effect of make_executable, switching a range of memory back from RX (readable/executable) to RW (readable/writable). It is guaranteed that no code is running anymore from this region.

ptr and ptr.offset(len) are guaranteed to be aligned as per required_alignment().

Implementors§