Skip to main content

CopyingMemory

Struct CopyingMemory 

Source
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: u32

Heap base address (for sbrk).

§heap_top: u32

Current heap top.

§max_heap_pages: u32

Maximum heap pages (sbrk refuses beyond this).

Implementations§

Source§

impl CopyingMemory

Source

pub fn new() -> Self

Empty memory; no pages allocated.

Source

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.

Source

pub fn is_in_bounds(&self, addr: u32) -> bool

Returns true iff addr is within flat_mem.

Source

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.

Source

pub fn read_u8(&self, addr: u32) -> Option<u8>

Source

pub fn read_u16_le(&self, addr: u32) -> Option<u16>

Source

pub fn read_u32_le(&self, addr: u32) -> Option<u32>

Source

pub fn read_u64_le(&self, addr: u32) -> Option<u64>

Source

pub fn write_u8(&mut self, addr: u32, val: u8) -> bool

Source

pub fn write_u16_le(&mut self, addr: u32, val: u16) -> bool

Source

pub fn write_u32_le(&mut self, addr: u32, val: u32) -> bool

Source

pub fn write_u64_le(&mut self, addr: u32, val: u64) -> bool

Source

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.

  • start and size must each be multiples of PAGE_SIZE.
  • Grows flat_mem to cover start + size if necessary (newly-grown bytes are zero-initialized; their pages default to perm::NONE before this call sets them).
  • Sets pages in [start / PAGE_SIZE, (start + size) / PAGE_SIZE) to the permission byte for access.
  • If init is Some(bytes), copies bytes[..bytes.len() .min(size)] into flat_mem[start..]; the rest of the region remains zero-filled (matches the DataCap canonical form: trailing zeros are stripped from content, but the logical size may be larger).
Source

pub fn read(&self, addr: u32, len: usize) -> Result<Vec<u8>, MemAccess>

Read len bytes from addr. Returns Err on out-of-range.

Source

pub fn write(&mut self, addr: u32, data: &[u8]) -> Result<(), MemAccess>

Write data starting at addr. Returns Err on out-of-range or write-protected page. Writes are NOT rolled back on partial failure (test-only API).

Trait Implementations§

Source§

impl Clone for CopyingMemory

Source§

fn clone(&self) -> CopyingMemory

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CopyingMemory

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for CopyingMemory

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Memory for CopyingMemory

Source§

fn read_u8(&self, addr: u32) -> Option<u8>

Source§

fn read_u16_le(&self, addr: u32) -> Option<u16>

Source§

fn read_u32_le(&self, addr: u32) -> Option<u32>

Source§

fn read_u64_le(&self, addr: u32) -> Option<u64>

Source§

fn write_u8(&mut self, addr: u32, val: u8) -> bool

Source§

fn write_u16_le(&mut self, addr: u32, val: u16) -> bool

Source§

fn write_u32_le(&mut self, addr: u32, val: u32) -> bool

Source§

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>

Declare a mapped region. See CopyingMemory::map_region for the canonical semantics.
Source§

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.
Source§

fn read(&self, addr: u32, len: usize) -> Result<Vec<u8>, MemAccess>

Read dst.len() bytes starting at addr into dst.
Source§

fn write(&mut self, addr: u32, data: &[u8]) -> Result<(), MemAccess>

Write data.len() bytes starting at addr. Per-page perm checks apply; out-of-range or RO-page writes return Err.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.