Skip to main content

DataCap

Struct DataCap 

Source
pub struct DataCap {
    pub backing: Arc<PageSlab>,
    pub overlay: BTreeMap<u32, PageSlot>,
}
Expand description

Data cap: an Arc-shared immutable PageSlab backing plus a copy-on-write overlay of modified pages. The cap identity (when flushed) is the flat size-scaled { size, pages } merkle (see the module docs).

Fields§

§backing: Arc<PageSlab>

Immutable backing, shared across a MGMT_COPY lineage by Arc.

§overlay: BTreeMap<u32, PageSlot>

Copy-on-write modified pages (absolute page index → page). Empty for a clean / settled cap. A present entry shadows the backing; zero-writes are stored explicitly (a present PageSlot::Loaded) so they shadow a possibly-nonzero backing page.

Implementations§

Source§

impl DataCap

Source

pub fn empty() -> Self

An empty DataCap: logical size 0, no pages, no overlay.

Source

pub fn content_len(&self) -> u64

Total logical content size in bytes (always a PAGE_SIZE multiple).

Source

pub fn page_count(&self) -> usize

Number of logical pages.

Source

pub fn is_dirty(&self, i: usize) -> bool

Is page i overlaid (CoW’d)? A page is dirty iff it is present in the overlay (Empty slots / absent entries are clean — defer to the backing).

Source

pub fn page_slot(&self, i: usize) -> &PageSlot

Borrow the effective page slot at absolute page index i: the overlay page if dirty, else the backing page. Both engines resolve a page’s physical address from the returned PageSlot::Loaded slab.

Source

pub fn page_at(&self, off: u64) -> PageResolution<'_>

Resolve the effective page containing byte offset off (need not be page-aligned). Both engines call this so their materialized page contents are identical.

Source

pub fn copy_into(&self, start: u64, out: &mut [u8])

Copy out.len() logical bytes starting at byte offset start into out (effective content), fully defining every byte: materialized pages are copied; Zero pages read as zero.

§Panics

Panics on a PageResolution::Missing page — elided content known only by hash is not zero, and the recompiler hard-faults on it; silently zero-filling would fork consensus. V1 never mints Missing.

Source

pub fn put_page(&mut self, off: u64, content: &[u8])

Overwrite the backing page containing absolute offset off with up to PAGE_SIZE content bytes (zero-padded tail), canonically. This is the construction / settle primitive (it mutates the backing via Arc::make_mut, so it is O(slab) on a shared backing — only use it while building a fresh cap). Copy-on-write during execution goes through write_page (the overlay) instead.

Panics (debug) if off >= self.content_len().

Source

pub fn write_page(&mut self, off: u64, content: &[u8])

Copy-on-write the overlay page containing absolute offset off with up to PAGE_SIZE content bytes (zero-padded tail). The page is stored explicitly as a present Loaded slab — even all-zero content — so it shadows the backing. This is the execution write boundary.

Panics (debug) if off >= self.content_len().

Source

pub fn insert_overlay_page(&mut self, p: u32, slot: PageSlot)

Insert an already-built overlay page slot at absolute page index p (move, no copy). The slab is page-aligned by construction; used by the engines’ CoW path to hand a freshly-written page to the cap directly.

Source

pub fn place_shared(&mut self, dst_off: u64, src: &DataCap)

Place every effective page of src into this cap’s backing starting at absolute byte offset dst_off (page-aligned): backing page dst_off/PAGE_SIZE + i becomes a clone of src.page_slot(i) — an Arc refcount bump, not a byte copy. Pages beyond this cap’s extent are dropped (clamped, mirroring the interpreter’s off < extent fold guard).

This is the page-sharing instance-memory composer: a fresh Instance mem built by placing an Image’s mapped Cap::Data sources shares those sources’ physical pages, so N sub-VMs spawned from one Image all map the same read-only frames and each CoWs (into its overlay) only the pages it writes — the shared backing is never mutated. Effective bytes are identical to the copying put_page fold; only the allocation is shared.

Source

pub fn flush(&self) -> DataCap

Fold the overlay into a fresh, clean (overlay-empty) DataCap whose hash_tree_root is defined. Clones the backing and folds every overlaid page in via the canonical backing CoW. This is the settle / content- address primitive (it replaces the old DataViewCap::settle).

Source

pub fn from_bytes(content: &[u8]) -> Self

Build a DataCap from contiguous content, sized to the next page boundary (at least one page). All-zero pages become PageSlot::Empty.

Source

pub fn from_bytes_sized(content: &[u8], target_size: u64) -> Self

Build a DataCap from content with a logical size of at least target_size (rounded up to a page boundary, minimum one page). content fills the low bytes; the remainder is zero (sparse). The cap is clean (empty overlay).

Source

pub fn from_sparse_pages<'a>( size: u64, pages: impl IntoIterator<Item = (u32, &'a [u8])>, ) -> Self

Build a clean (overlay-free) DataCap from sparse named pages over a logical size. See PageSlab::from_sparse_pages. This is the decode target for crate::image::DataDesc::to_data_cap; the result is byte- and hash-identical to a contiguous Self::from_bytes_sized of equivalent logical content.

Trait Implementations§

Source§

impl Archive for DataCap
where Arc<PageSlab>: Archive, BTreeMap<u32, PageSlot>: Archive,

Source§

const COPY_OPTIMIZATION: CopyOptimization<Self>

An optimization flag that allows the bytes of this type to be copied directly to a writer instead of calling serialize. Read more
Source§

type Archived = ArchivedDataCap

The archived representation of this type. Read more
Source§

type Resolver = DataCapResolver

The resolver for this type. It must contain all the additional information from serializing needed to make the archived type from the normal type.
Source§

fn resolve(&self, resolver: Self::Resolver, out: Place<Self::Archived>)

Creates the archived version of this value at the given position and writes it to the given output. Read more
Source§

impl Clone for DataCap

Source§

fn clone(&self) -> DataCap

Returns a duplicate 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 Debug for DataCap

Source§

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

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

impl<__D: Fallible + ?Sized> Deserialize<DataCap, __D> for Archived<DataCap>
where Arc<PageSlab>: Archive, <Arc<PageSlab> as Archive>::Archived: Deserialize<Arc<PageSlab>, __D>, BTreeMap<u32, PageSlot>: Archive, <BTreeMap<u32, PageSlot> as Archive>::Archived: Deserialize<BTreeMap<u32, PageSlot>, __D>,

Source§

fn deserialize( &self, deserializer: &mut __D, ) -> Result<DataCap, <__D as Fallible>::Error>

Deserializes using the given deserializer
Source§

impl HashTreeRoot for DataCap

Source§

fn hash_tree_root<D: Digest<OutputSize = U32>>(&self) -> [u8; 32]

Compute the hash tree root using D as the underlying hash.
Source§

impl<__S: Fallible + ?Sized> Serialize<__S> for DataCap
where Arc<PageSlab>: Serialize<__S>, BTreeMap<u32, PageSlot>: Serialize<__S>,

Source§

fn serialize( &self, serializer: &mut __S, ) -> Result<<Self as Archive>::Resolver, <__S as Fallible>::Error>

Writes the dependencies for the object and returns a resolver that can create the archived type.

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
§

impl<T> ArchivePointee for T

§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
§

impl<T> ArchiveUnsized for T
where T: Archive,

§

type Archived = <T as Archive>::Archived

The archived counterpart of this type. Unlike Archive, it may be unsized. Read more
§

fn archived_metadata( &self, ) -> <<T as ArchiveUnsized>::Archived as ArchivePointee>::ArchivedMetadata

Creates the archived version of the metadata for this value.
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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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.

§

impl<T> LayoutRaw for T

§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
§

impl<T> Pointee for T

§

type Metadata = ()

The metadata type for pointers and references to this type.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T, S> SerializeUnsized<S> for T
where T: Serialize<S>, S: Fallible + Writer + ?Sized,

§

fn serialize_unsized( &self, serializer: &mut S, ) -> Result<usize, <S as Fallible>::Error>

Writes the object and returns the position of the archived type.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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

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.