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<()>;
}
runtime
only.Expand description
Interface implemented by an embedder to provide custom implementations of code-memory protection and execute permissions.
Required Methods§
Sourcefn required_alignment(&self) -> usize
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.
Sourcefn publish_executable(&self, ptr: *const u8, len: usize) -> Result<()>
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()
.
Sourcefn unpublish_executable(&self, ptr: *const u8, len: usize) -> Result<()>
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()
.