pub struct BasicMemory<const BASE_ADDR: u64, const SIZE: usize> { /* private fields */ }Expand description
Basic memory implementation.
Flat structure, no rwx protections, no alignment requirements. It uses stack, so for larger allocation it’ll need to be boxed (zero-initialized is fine) or a custom implementation to be used.
BASE_ADDR + SIZE must fit into u64, meaning the memory region can’t wrap around or end at
the very end of the address space, which is checked at compile time. This is what allows an
address below BASE_ADDR to be recognized by the bounds check that follows the subtraction of
the base address rather than by a check of its own.
This implementation is intentionally basic and correct, but not the most performant. It is possible to have a more efficient implementation that skips certain checks by placing additional constraints on the program.
This works for simpler cases, while a more sophisticated implementation might prevent certain memory from being writable, supporting actual virtual memory with dynamically allocated memory pages, etc.
Implementations§
Source§impl<const BASE_ADDR: u64, const SIZE: usize> BasicMemory<BASE_ADDR, SIZE>
impl<const BASE_ADDR: u64, const SIZE: usize> BasicMemory<BASE_ADDR, SIZE>
pub fn new_boxed() -> Box<Self>
Sourcepub const fn get_mut_bytes(
&mut self,
address: u64,
size: usize,
) -> Result<&mut [u8], VirtualMemoryError>
pub const fn get_mut_bytes( &mut self, address: u64, size: usize, ) -> Result<&mut [u8], VirtualMemoryError>
Get a mutable slice of memory.
This is primarily useful for setting up the program and should not be used beyond that.
Trait Implementations§
Source§impl<const BASE_ADDR: u64, const SIZE: usize> Clone for BasicMemory<BASE_ADDR, SIZE>
impl<const BASE_ADDR: u64, const SIZE: usize> Clone for BasicMemory<BASE_ADDR, SIZE>
Source§fn clone(&self) -> BasicMemory<BASE_ADDR, SIZE>
fn clone(&self) -> BasicMemory<BASE_ADDR, SIZE>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more