Struct risc0_binfmt::MemoryImage
source · pub struct MemoryImage {
pub pages: BTreeMap<u32, Vec<u8>>,
pub info: PageTableInfo,
pub pc: u32,
}
target_os="zkvm"
only.Expand description
An image of a zkVM guest’s memory
This is an image of the full memory state of the zkVM, including the data, text, inputs, page table, and system memory. In addition to the memory image proper, this includes some metadata about the page table.
Fields§
§pages: BTreeMap<u32, Vec<u8>>
Sparse memory image as a map from page index to page.
info: PageTableInfo
Metadata about the structure of the page table
pc: u32
Program Counter from Program entry point
Implementations§
source§impl MemoryImage
impl MemoryImage
sourcepub fn new(program: &Program, page_size: u32) -> Result<Self>
pub fn new(program: &Program, page_size: u32) -> Result<Self>
Construct the initial memory image for program
The result is a MemoryImage with the ELF of program
loaded (but
execution not yet begun), and with the page table Merkle tree
constructed.
sourcepub fn load_page(&self, page_idx: u32) -> Vec<u8>
pub fn load_page(&self, page_idx: u32) -> Vec<u8>
Load a page specified by page_idx. If no page is found, a zero page is returned.
sourcepub fn store_region_in_page(&mut self, addr: u32, bytes: &[u8])
pub fn store_region_in_page(&mut self, addr: u32, bytes: &[u8])
Writes the given byte array in this memory image at the given address. The caller is responsible for ensuring the bytes do not overlap a page boundary.
sourcepub fn load_region_in_page(&self, addr: u32, bytes: &mut [u8]) -> Result<()>
pub fn load_region_in_page(&self, addr: u32, bytes: &mut [u8]) -> Result<()>
Reads the given byte array in this memory image at the given address The caller is responsible for ensuring the bytes do not overlap a page boundary.
sourcepub fn hash_pages(&mut self)
pub fn hash_pages(&mut self)
Calculate and update the image merkle tree within this image.
sourcepub fn hash_pages_iter<I: Iterator<Item = u32>>(&mut self, iter: I)
pub fn hash_pages_iter<I: Iterator<Item = u32>>(&mut self, iter: I)
Calculate and update the image merkle tree within this image based on the supplied page indices.
sourcepub fn update_page(&mut self, page_idx: u32)
pub fn update_page(&mut self, page_idx: u32)
Calculate and update the image merkle tree within this image based on the supplied page index.
sourcepub fn compute_root_hash(&self) -> Digest
pub fn compute_root_hash(&self) -> Digest
Compute and return the root merkle entry of this image.
sourcepub fn compute_id(&self) -> Digest
pub fn compute_id(&self) -> Digest
Compute and return the ImageID of this image.
sourcepub fn get_system_state(&self) -> SystemState
pub fn get_system_state(&self) -> SystemState
Return the SystemState for this image.
Trait Implementations§
source§impl Clone for MemoryImage
impl Clone for MemoryImage
source§fn clone(&self) -> MemoryImage
fn clone(&self) -> MemoryImage
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more