Skip to main content

Snapshot

Struct Snapshot 

Source
pub struct Snapshot { /* private fields */ }
Expand description

A wrapper around a SharedMemory reference and a snapshot of the memory therein

Implementations§

Source§

impl Snapshot

Source

pub fn save(&self, path: impl AsRef<Path>, tag: &OciTag) -> Result<OciDigest>

Save this snapshot into an OCI Image Layout directory on disk. The saved snapshot can be loaded later with Snapshot::load.

Returns the OciDigest of the manifest that was written, which Snapshot::load accepts as a stable handle to this exact snapshot.

§path

The OCI Image Layout directory to write to. The directory at path is created if absent. Its parent directory must exist.

If path holds no OCI layout, a new one is created. If it holds one, this snapshot is added alongside the others. If path holds something that is not a readable OCI layout, the call fails and the directory is left unchanged.

§tag

A standard OCI tag that names this snapshot within the layout. Snapshot::load can load the snapshot back by this tag.

A tag points to one snapshot at a time. If the layout has a snapshot under this tag, the tag is moved to the new snapshot. The old snapshot’s data stays on disk, reachable by its digest but not by this tag. Snapshots under other tags are untouched.

§Portability

Snapshot images are bound to the specific CPU architecture, hypervisor, and CPU vendor that the snapshot was created on. For example, a snapshot taken on an Intel x86_64 host with KVM can only be loaded on an Intel x86_64 host running KVM. Loading on any other host is rejected. A future version may relax this binding once a wider compatibility set is proven safe.

§Compatibility

While Hyperlight is at version 0.x.y the on-disk format is not stable. A snapshot written by one Hyperlight version is not guaranteed to load on a different Hyperlight version. An incompatible snapshot is always rejected at load time with a clear error. It can never load and then misbehave once the guest is running. Any release that breaks the format is called out in the Hyperlight changelog.

§Examples
let mut sandbox: MultiUseSandbox = UninitializedSandbox::new(
    GuestBinary::FilePath("guest.bin".into()),
    None,
)?.evolve()?;

// Capture the initialized state and write it to an OCI layout on disk.
let snapshot = sandbox.snapshot()?;
let tag = OciTag::new("latest")?;
let digest = snapshot.save("./guest_snapshot", &tag)?;
Source

pub fn load( path: impl AsRef<Path>, reference: impl Into<OciReference>, ) -> Result<Self>

Load a snapshot from an OCI Image Layout directory produced by Snapshot::save.

§path

The OCI Image Layout directory to read from. It must hold a readable OCI layout containing at least one Hyperlight snapshot.

§reference

Determines which snapshot in the layout to load, given as either an OciTag or an OciDigest. Loading fails if no snapshot in the layout has the given tag or digest.

§Portability

Snapshot images are bound to the specific CPU architecture, hypervisor, and CPU vendor that the snapshot was created on. For example, a snapshot taken on an Intel x86_64 host with KVM can only be loaded on an Intel x86_64 host running KVM. Loading on any other host is rejected. A future version may relax this binding once a wider compatibility set is proven safe.

§Compatibility

While Hyperlight is at version 0.x.y the on-disk format is not stable. A snapshot written by one Hyperlight version is not guaranteed to load on a different Hyperlight version. An incompatible snapshot is always rejected at load time with a clear error. It can never load and then misbehave once the guest is running. Any release that breaks the format is called out in the Hyperlight changelog.

§Verification

This method does not check the manifest, config, or snapshot blobs against their recorded sha256 digests. Load only from a layout you trust.

To check the digests on load at the expense of some performance, use Snapshot::checked_load.

§File-mutation hazard

The snapshot blob stays memory-mapped while the returned Snapshot or any sandbox built from it is alive. The existing blob files in the layout at path must not be overwritten, truncated, or deleted while the mapping is live. Doing so can corrupt guest memory and can lead to undefined behavior.

§Examples
let tag = OciTag::new("latest")?;
let snapshot = Arc::new(Snapshot::load("./guest_snapshot", tag)?);
let mut sandbox = MultiUseSandbox::from_snapshot(snapshot, HostFunctions::default(), None)?;
let result: String = sandbox.call("Echo", "hello".to_string())?;
Source

pub fn checked_load( path: impl AsRef<Path>, reference: impl Into<OciReference>, ) -> Result<Self>

Loads a snapshot like Snapshot::load. See its rustdoc for path, reference, portability, and the file-mutation hazard. This method additionally checks the manifest, config, and snapshot blobs against their recorded sha256 digests before use, at the expense of some performance.

§Trust

A digest check does not prove the bytes are authentic. Anyone who edits a blob can recompute its digest to match, so a hostile layout passes the check. Load only from a source you trust.

Trait Implementations§

Source§

impl AsRef<Snapshot> for Snapshot

Source§

fn as_ref(&self) -> &Self

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl TableReadOps for Snapshot

Source§

type TableAddr = u64

The type of table addresses
Source§

fn entry_addr(addr: u64, offset: u64) -> u64

Offset the table address by the given offset in bytes. Read more
Source§

unsafe fn read_entry(&self, addr: u64) -> PageTableEntry

Read a u64 from the given address, used to read existing page table entries Read more
Source§

fn to_phys(addr: u64) -> PhysAddr

Convert an abstract table address to a concrete physical address (u64) which can be e.g. written into a page table entry
Source§

fn from_phys(addr: PhysAddr) -> u64

Convert a concrete physical address (u64) which may have been e.g. read from a page table entry back into an abstract table address
Source§

fn root_table(&self) -> u64

Return the address of the root page table

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more