Trait FunctionContext

Source
pub trait FunctionContext {
    // Required methods
    fn read_memory_into(
        &self,
        address: Pointer<u8>,
        dest: &mut [u8],
    ) -> Result<()>;
    fn write_memory(&mut self, address: Pointer<u8>, data: &[u8]) -> Result<()>;
    fn allocate_memory(&mut self, size: WordSize) -> Result<Pointer<u8>>;
    fn deallocate_memory(&mut self, ptr: Pointer<u8>) -> Result<()>;
    fn sandbox(&mut self) -> &mut dyn Sandbox;

    // Provided method
    fn read_memory(
        &self,
        address: Pointer<u8>,
        size: WordSize,
    ) -> Result<Vec<u8>> { ... }
}
Expand description

Context used by Function to interact with the allocator and the memory of the wasm instance.

Required Methods§

Source

fn read_memory_into(&self, address: Pointer<u8>, dest: &mut [u8]) -> Result<()>

Read memory into the given dest buffer from address.

Source

fn write_memory(&mut self, address: Pointer<u8>, data: &[u8]) -> Result<()>

Write the given data at address into the memory.

Source

fn allocate_memory(&mut self, size: WordSize) -> Result<Pointer<u8>>

Allocate a memory instance of size bytes.

Source

fn deallocate_memory(&mut self, ptr: Pointer<u8>) -> Result<()>

Deallocate a given memory instance.

Source

fn sandbox(&mut self) -> &mut dyn Sandbox

Provides access to the sandbox.

Provided Methods§

Source

fn read_memory(&self, address: Pointer<u8>, size: WordSize) -> Result<Vec<u8>>

Read memory from address into a vector.

Trait Implementations§

Source§

impl ReadPrimitive<u32> for &mut dyn FunctionContext

Source§

fn read_primitive(&self, ptr: Pointer<u32>) -> Result<u32>

Read a primitive from the given memory location ptr.
Source§

impl ReadPrimitive<u64> for &mut dyn FunctionContext

Source§

fn read_primitive(&self, ptr: Pointer<u64>) -> Result<u64>

Read a primitive from the given memory location ptr.
Source§

impl WritePrimitive<u32> for &mut dyn FunctionContext

Source§

fn write_primitive(&mut self, ptr: Pointer<u32>, t: u32) -> Result<()>

Write the given value t to the given memory location ptr.
Source§

impl WritePrimitive<u64> for &mut dyn FunctionContext

Source§

fn write_primitive(&mut self, ptr: Pointer<u64>, t: u64) -> Result<()>

Write the given value t to the given memory location ptr.

Implementors§