gear_core::memory

Trait 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§