Struct ckb_vm::snapshot2::Snapshot2Context
source · pub struct Snapshot2Context<I: Clone + PartialEq, D: DataSource<I>> { /* private fields */ }
Implementations§
source§impl<I: Clone + PartialEq, D: DataSource<I>> Snapshot2Context<I, D>
impl<I: Clone + PartialEq, D: DataSource<I>> Snapshot2Context<I, D>
pub fn new(data_source: D) -> Self
sourcepub fn resume<M: SupportMachine>(
&mut self,
machine: &mut M,
snapshot: &Snapshot2<I>,
) -> Result<(), Error>
pub fn resume<M: SupportMachine>( &mut self, machine: &mut M, snapshot: &Snapshot2<I>, ) -> Result<(), Error>
Resume a previously suspended machine from snapshot.
pub fn load_data( &mut self, id: &I, offset: u64, length: u64, ) -> Result<(Bytes, u64), Error>
sourcepub fn store_bytes<M: SupportMachine>(
&mut self,
machine: &mut M,
addr: u64,
id: &I,
offset: u64,
length: u64,
size_addr: u64,
) -> Result<(u64, u64), Error>
pub fn store_bytes<M: SupportMachine>( &mut self, machine: &mut M, addr: u64, id: &I, offset: u64, length: u64, size_addr: u64, ) -> Result<(u64, u64), Error>
Similar to Memory::store_bytes, but this method also tracks memory
pages whose entire content comes from DataSource. It returns 2 values:
the actual written bytes, and the full length of data starting from offset,
but ignoring length
parameter.
sourcepub fn mark_program<M: SupportMachine>(
&mut self,
machine: &mut M,
metadata: &ProgramMetadata,
id: &I,
offset: u64,
) -> Result<(), Error>
pub fn mark_program<M: SupportMachine>( &mut self, machine: &mut M, metadata: &ProgramMetadata, id: &I, offset: u64, ) -> Result<(), Error>
Due to the design of ckb-vm right now, load_program function does not belong to SupportMachine yet. For Snapshot2Context to track memory pages from program in DataSource, we have to use the following steps now:
- use elf::parse_elf to generate ProgramMetadata
- use DefaultMachine::load_program_with_metadata to load the program
- Pass ProgramMetadata to this method so we can track memory pages from program, so as to further reduce the size of the generated snapshot.
One can also use the original DefaultMachine::load_program, and parse the ELF a second time to extract metadata for this method. However the above listed process saves us the time to parse the ELF again.
sourcepub fn make_snapshot<M: SupportMachine>(
&self,
machine: &mut M,
) -> Result<Snapshot2<I>, Error>
pub fn make_snapshot<M: SupportMachine>( &self, machine: &mut M, ) -> Result<Snapshot2<I>, Error>
Create a snapshot for the passed machine.
sourcepub fn track_pages<M: SupportMachine>(
&mut self,
machine: &mut M,
start: u64,
length: u64,
id: &I,
offset: u64,
) -> Result<(), Error>
pub fn track_pages<M: SupportMachine>( &mut self, machine: &mut M, start: u64, length: u64, id: &I, offset: u64, ) -> Result<(), Error>
The followings are only made public for advanced usages, but make sure to exercise more cautions when calling it!
pub fn untrack_pages<M: SupportMachine>( &mut self, machine: &mut M, start: u64, length: u64, ) -> Result<(), Error>
Trait Implementations§
source§impl<I: Clone + Clone + PartialEq, D: Clone + DataSource<I>> Clone for Snapshot2Context<I, D>
impl<I: Clone + Clone + PartialEq, D: Clone + DataSource<I>> Clone for Snapshot2Context<I, D>
source§fn clone(&self) -> Snapshot2Context<I, D>
fn clone(&self) -> Snapshot2Context<I, D>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more