pub trait Memory {
// Required methods
fn read_u8(&self, addr: u32) -> Option<u8>;
fn read_u16_le(&self, addr: u32) -> Option<u16>;
fn read_u32_le(&self, addr: u32) -> Option<u32>;
fn read_u64_le(&self, addr: u32) -> Option<u64>;
fn write_u8(&mut self, addr: u32, val: u8) -> bool;
fn write_u16_le(&mut self, addr: u32, val: u16) -> bool;
fn write_u32_le(&mut self, addr: u32, val: u32) -> bool;
fn write_u64_le(&mut self, addr: u32, val: u64) -> bool;
fn map_region(
&mut self,
start: u64,
size: u64,
access: Access,
init: Option<&[u8]>,
) -> Result<(), MapError>;
fn perm_of(&self, addr: u32) -> u8;
fn read(&self, addr: u32, len: usize) -> Result<Vec<u8>, MemAccess>;
fn write(&mut self, addr: u32, data: &[u8]) -> Result<(), MemAccess>;
}Expand description
Memory backend abstraction.
The interpreter is generic over M: Memory so the same source
compiles for two substrates:
- Software-copy:
CopyingMemory(this module) — an owningVec<u8>with per-page permissions. Runs in-process. - Hardware-paged: a future bare-metal impl in
nub-arch-x86that maps PVM pages onto real CPU pages via the in-guest IDT + page tables.
Hot-path methods (read_u*/write_u*) return Option<T> or
bool to keep the interpreter loop branch-free. Implementations
should mark these #[inline] (or #[inline(always)]) — the
interpreter calls them through trait dispatch, and we want
monomorphisation to collapse to direct function calls.
Required Methods§
fn read_u8(&self, addr: u32) -> Option<u8>
fn read_u16_le(&self, addr: u32) -> Option<u16>
fn read_u32_le(&self, addr: u32) -> Option<u32>
fn read_u64_le(&self, addr: u32) -> Option<u64>
fn write_u8(&mut self, addr: u32, val: u8) -> bool
fn write_u16_le(&mut self, addr: u32, val: u16) -> bool
fn write_u32_le(&mut self, addr: u32, val: u32) -> bool
fn write_u64_le(&mut self, addr: u32, val: u64) -> bool
Sourcefn map_region(
&mut self,
start: u64,
size: u64,
access: Access,
init: Option<&[u8]>,
) -> Result<(), MapError>
fn map_region( &mut self, start: u64, size: u64, access: Access, init: Option<&[u8]>, ) -> Result<(), MapError>
Declare a mapped region. See CopyingMemory::map_region for
the canonical semantics.
Sourcefn perm_of(&self, addr: u32) -> u8
fn perm_of(&self, addr: u32) -> u8
Per-page permission byte for the page containing addr.
Returns perm::NONE if addr is out of range.