wasmtime

Trait CustomCodeMemory

Source
pub trait CustomCodeMemory: Send + Sync {
    // Required methods
    fn required_alignment(&self) -> usize;
    fn publish_executable(&self, ptr: *const u8, len: usize) -> Result<()>;
    fn unpublish_executable(&self, ptr: *const u8, len: usize) -> Result<()>;
}
Available on crate feature runtime only.
Expand description

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

Required Methods§

Source

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.

Source

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

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().

Source

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

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§