Skip to main content

Mem

Type Alias Mem 

Source
pub type Mem = CopyingMemory;
Expand description

Compatibility alias for the pre-trait name. Consumers can keep writing Mem; new code should prefer CopyingMemory (when the concrete impl is wanted) or be generic over M: Memory.

Aliased Type§

pub struct Mem {
    pub base: u32,
    pub flat_mem: Vec<u8>,
    pub perms: Vec<u8>,
    pub mat_state: Vec<u8>,
    pub code_base: u32,
    pub code_top: u32,
    pub heap_base: u32,
    pub heap_top: u32,
    pub max_heap_pages: u32,
}

Fields§

§base: u32

Base guest address flat_mem[0] corresponds to. Guest address addr indexes flat_mem[addr - base]; accesses below base (or past the buffer) fault. Lets the buffer cover only the high data region [DATA_BASE, …) without allocating the [0, DATA_BASE) null-guard hole — matching the recompiler’s page table, which leaves that range unmapped. 0 for the addr-0-based memories used in unit tests.

§flat_mem: Vec<u8>

Contiguous byte buffer covering [base, base + 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). Indexed by page relative to base.

§mat_state: Vec<u8>

Category-#3 per-page materialization state (crate::mat::PageState as a u8), one byte per page, kept the same length as perms. Software first-touch accounting: a never-touched page is NotPresent; the first read pages it in, the first write CoWs it. The interpreter’s #3 charge is kind-independent (the only kind-sensitive case — a write to a pinned page — is already gated by the perm::RW write check), so no per-page PageKind is kept; the recompiler tracks kinds itself for page sourcing.

§code_base: u32

Guest VA base of the read-only CODE region (PinnedCapRo). Guest data loads (PIC auipc+load) of the program’s own bytecode page it in on first read (read-only page-in is charged eagerly at the CALL, not at this fault, but a PIC read still records residency), identical to the recompiler. code_top == code_base (the default) means no code region is declared — code reads then skip #3 (unit tests).

§code_top: u32

Exclusive top of the code region, page-rounded: code_base + round_up(code_len). The last code page’s zero-padded tail is readable (matching the recompiler, which maps whole pages).

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