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>

source

pub fn new(data_source: D) -> Self

source

pub fn resume<M: SupportMachine>( &mut self, machine: &mut M, snapshot: &Snapshot2<I>, ) -> Result<(), Error>

Resume a previously suspended machine from snapshot.

source

pub fn load_data( &mut self, id: &I, offset: u64, length: u64, ) -> Result<(Bytes, u64), Error>

source

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.

source

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:

  1. use elf::parse_elf to generate ProgramMetadata
  2. use DefaultMachine::load_program_with_metadata to load the program
  3. 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.

source

pub fn make_snapshot<M: SupportMachine>( &self, machine: &mut M, ) -> Result<Snapshot2<I>, Error>

Create a snapshot for the passed machine.

source

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!

source

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>

source§

fn clone(&self) -> Snapshot2Context<I, D>

Returns a copy 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<I: Debug + Clone + PartialEq, D: Debug + DataSource<I>> Debug for Snapshot2Context<I, D>

source§

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

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

impl<I: Clone + PartialEq, D: DataSource<I> + Default> Default for Snapshot2Context<I, D>

source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<I, D> Freeze for Snapshot2Context<I, D>
where D: Freeze,

§

impl<I, D> RefUnwindSafe for Snapshot2Context<I, D>

§

impl<I, D> Send for Snapshot2Context<I, D>
where D: Send, I: Send,

§

impl<I, D> Sync for Snapshot2Context<I, D>
where D: Sync, I: Sync,

§

impl<I, D> Unpin for Snapshot2Context<I, D>
where D: Unpin, I: Unpin,

§

impl<I, D> UnwindSafe for Snapshot2Context<I, D>
where D: UnwindSafe, I: UnwindSafe,

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> 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,

§

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>,

§

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>,

§

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.