pub struct CopyingMemory {
pub flat_mem: Vec<u8>,
pub perms: Vec<u8>,
pub heap_base: u32,
pub heap_top: u32,
pub max_heap_pages: u32,
}Expand description
Address-space mapping for one execution context.
Flat-buffer layout matching v2 javm. The buffer’s length defines
the upper bound of valid addresses; per-page permissions live in
perms. Implements Memory via inherent-method delegation so
concrete callers don’t need to import the trait.
Fields§
§flat_mem: Vec<u8>Contiguous byte buffer covering 0..flat_mem.len().
perms: Vec<u8>One permission byte per PAGE_SIZE-page in flat_mem.
perms.len() == flat_mem.len() / PAGE_SIZE (rounded up).
heap_base: u32Heap base address (for sbrk).
heap_top: u32Current heap top.
max_heap_pages: u32Maximum heap pages (sbrk refuses beyond this).
Implementations§
Source§impl CopyingMemory
impl CopyingMemory
Sourcepub fn with_pages(n_pages: u32, default_perm: u8) -> Self
pub fn with_pages(n_pages: u32, default_perm: u8) -> Self
Construct with a pre-sized flat buffer (zero-initialized).
n_pages is the number of PAGE_SIZE-pages.
Sourcepub fn is_in_bounds(&self, addr: u32) -> bool
pub fn is_in_bounds(&self, addr: u32) -> bool
Returns true iff addr is within flat_mem.
Sourcepub fn perm_of(&self, addr: u32) -> u8
pub fn perm_of(&self, addr: u32) -> u8
Per-page permission for the page containing addr. Returns
perm::NONE if the address is out of range.
pub fn read_u8(&self, addr: u32) -> Option<u8>
pub fn read_u16_le(&self, addr: u32) -> Option<u16>
pub fn read_u32_le(&self, addr: u32) -> Option<u32>
pub fn read_u64_le(&self, addr: u32) -> Option<u64>
pub fn write_u8(&mut self, addr: u32, val: u8) -> bool
pub fn write_u16_le(&mut self, addr: u32, val: u16) -> bool
pub fn write_u32_le(&mut self, addr: u32, val: u32) -> bool
pub fn write_u64_le(&mut self, addr: u32, val: u64) -> bool
Sourcepub fn map_region(
&mut self,
start: u64,
size: u64,
access: Access,
init: Option<&[u8]>,
) -> Result<(), MapError>
pub fn map_region( &mut self, start: u64, size: u64, access: Access, init: Option<&[u8]>, ) -> Result<(), MapError>
Declare a mapped region at [start, start + size) with
per-page permissions access and optional initial bytes.
startandsizemust each be multiples ofPAGE_SIZE.- Grows
flat_memto coverstart + sizeif necessary (newly-grown bytes are zero-initialized; their pages default toperm::NONEbefore this call sets them). - Sets pages in
[start / PAGE_SIZE, (start + size) / PAGE_SIZE)to the permission byte foraccess. - If
initisSome(bytes), copiesbytes[..bytes.len() .min(size)]intoflat_mem[start..]; the rest of the region remains zero-filled (matches the DataCap canonical form: trailing zeros are stripped fromcontent, but the logicalsizemay be larger).
Trait Implementations§
Source§impl Clone for CopyingMemory
impl Clone for CopyingMemory
Source§fn clone(&self) -> CopyingMemory
fn clone(&self) -> CopyingMemory
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for CopyingMemory
impl Debug for CopyingMemory
Source§impl Default for CopyingMemory
impl Default for CopyingMemory
Source§impl Memory for CopyingMemory
impl Memory for CopyingMemory
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
Source§fn 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>
CopyingMemory::map_region for
the canonical semantics.