Skip to main content

Memory

Trait Memory 

Source
pub trait Memory {
    // Required methods
    fn size(&self) -> u64;
    fn grow(&self, pages: u64) -> i64;
    fn read(&self, offset: u64, bytes: &mut [u8]);
    fn write(&self, offset: u64, bytes: &[u8]);

    // Provided method
    unsafe fn read_unsafe(&self, offset: u64, dst: *mut u8, count: usize) { ... }
}
Expand description

Memory

Page-addressed backing for Storage. Growth returns the previous page count, or -1 without changing memory. Successful growth adds zero-filled pages. Reads and writes must reject the complete out-of-bounds range before IO. Implementing this trait alone does not grant allocation authority.

Required Methods§

Source

fn size(&self) -> u64

Current extent in 65,536-byte pages.

Source

fn grow(&self, pages: u64) -> i64

Add zero-filled pages, or return -1 on refusal.

Source

fn read(&self, offset: u64, bytes: &mut [u8])

Read an admitted byte range.

Source

fn write(&self, offset: u64, bytes: &[u8])

Write an admitted byte range. Native writes need not be transactional.

Provided Methods§

Source

unsafe fn read_unsafe(&self, offset: u64, dst: *mut u8, count: usize)

Read into a potentially uninitialized destination, following ICSS’s hook.

Every implementation must initialize all count bytes on successful return. A failed read may leave a partially initialized destination. The default supports existing backings through Self::read; overrides can avoid zeroing bytes that backing IO will overwrite.

§Safety

The caller must provide an exclusive writable count-byte range valid for a Rust slice. It must not overlap this memory’s state or read source.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Memory for RefCell<Vec<u8>>

Source§

fn size(&self) -> u64

Source§

fn grow(&self, pages: u64) -> i64

Source§

fn read(&self, offset: u64, bytes: &mut [u8])

Source§

unsafe fn read_unsafe(&self, offset: u64, dst: *mut u8, count: usize)

Source§

fn write(&self, offset: u64, bytes: &[u8])

Source§

impl<M: Memory + ?Sized> Memory for &M

Source§

fn size(&self) -> u64

Source§

fn grow(&self, pages: u64) -> i64

Source§

fn read(&self, offset: u64, bytes: &mut [u8])

Source§

unsafe fn read_unsafe(&self, offset: u64, dst: *mut u8, count: usize)

Source§

fn write(&self, offset: u64, bytes: &[u8])

Source§

impl<M: Memory + ?Sized> Memory for Rc<M>

Source§

fn size(&self) -> u64

Source§

fn grow(&self, pages: u64) -> i64

Source§

fn read(&self, offset: u64, bytes: &mut [u8])

Source§

unsafe fn read_unsafe(&self, offset: u64, dst: *mut u8, count: usize)

Source§

fn write(&self, offset: u64, bytes: &[u8])

Implementors§