Trait gear_core::memory::Memory

source ·
pub trait Memory<Context> {
    type GrowError: Debug;

    // Required methods
    fn grow(
        &self,
        ctx: &mut Context,
        pages: WasmPagesAmount,
    ) -> Result<(), Self::GrowError>;
    fn size(&self, ctx: &Context) -> WasmPagesAmount;
    fn write(
        &self,
        ctx: &mut Context,
        offset: u32,
        buffer: &[u8],
    ) -> Result<(), MemoryError>;
    fn read(
        &self,
        ctx: &Context,
        offset: u32,
        buffer: &mut [u8],
    ) -> Result<(), MemoryError>;
    unsafe fn get_buffer_host_addr_unsafe(&self, ctx: &Context) -> HostPointer;

    // Provided method
    fn get_buffer_host_addr(&self, ctx: &Context) -> Option<HostPointer> { ... }
}
Expand description

Backend wasm memory interface.

Required Associated Types§

source

type GrowError: Debug

Memory grow error.

Required Methods§

source

fn grow( &self, ctx: &mut Context, pages: WasmPagesAmount, ) -> Result<(), Self::GrowError>

Grow memory by number of pages.

source

fn size(&self, ctx: &Context) -> WasmPagesAmount

Return current size of the memory.

source

fn write( &self, ctx: &mut Context, offset: u32, buffer: &[u8], ) -> Result<(), MemoryError>

Set memory region at specific pointer.

source

fn read( &self, ctx: &Context, offset: u32, buffer: &mut [u8], ) -> Result<(), MemoryError>

Reads memory contents at the given offset into a buffer.

source

unsafe fn get_buffer_host_addr_unsafe(&self, ctx: &Context) -> HostPointer

Get buffer addr unsafe.

§Safety

If memory size is 0 then buffer addr can be garbage

Provided Methods§

source

fn get_buffer_host_addr(&self, ctx: &Context) -> Option<HostPointer>

Returns native addr of wasm memory buffer in wasm executor

Implementors§