pub enum Cap {
Instance(InstanceCap),
Image(ImageCap),
Data(DataCap),
CNode(CNodeCap),
Type(TypeCap),
}Expand description
One of the five v3 cap kinds.
SSZ note: the HashTreeRoot derive treats Cap as an SSZ
Union over the five variants. Each variant’s selector provides the
domain separation that the legacy byte-protocol kind tags
(0x10..0x50) provided; the per-variant root is computed by that
variant’s own HashTreeRoot impl. We do not derive Encode + Decode on Cap itself; caps move through the cache by direct
allocation and aren’t wire-transmitted at this layer.
Clone: the derived Clone recursively clones field-by-field.
Cap::Instance and Cap::CNode carry CapHashOrRef values; the
Ref(CapRef) arm Arc::clones the handle, so cloning a Cap
deep-bumps every nested instance reference. Drop is symmetric.
Variants§
Implementations§
Source§impl Cap
impl Cap
pub fn kind(&self) -> CapKind
Sourcepub fn data_inline(bytes: &[u8]) -> Self
pub fn data_inline(bytes: &[u8]) -> Self
Build a heap Cap::Data whose content is bytes padded up to
the next PAGE_SIZE boundary with
zeros. The backing allocation is page-aligned so the kernel
can later map the cap’s pages directly into a ring-3 PT.
DataCap.content_len() returns the padded length (always a
4 KiB-multiple). There is no separate logical-size field;
callers needing a shorter logical payload (e.g. variable-length
args) interpret the meaningful prefix themselves.
Sourcepub fn data_inline_with_size(bytes: &[u8], target_size: u64) -> Self
pub fn data_inline_with_size(bytes: &[u8], target_size: u64) -> Self
Build a heap Cap::Data whose backing buffer is at least
target_size bytes (rounded up to the next page boundary).
bytes is copied to the start of the buffer; the remainder is
zero-padded. Used by callers that need a cap matching a specific
MemoryMapping.size from an image manifest (e.g. genesis +
transpiler-emitted initial data).
If target_size < bytes.len(), the buffer is sized to fit
bytes (still page-multiple) — i.e. target_size is a floor,
not a ceiling.
Sourcepub fn image_from(image: &Image) -> Result<Self, ImageConvertError>
pub fn image_from(image: &Image) -> Result<Self, ImageConvertError>
Build a heap Cap::Image from a SCALE Image value. Pinned
and initial slot references are left empty; callers that need
them should drive super::image_cap::image_cap directly
with the already-resolved (slot, CapHash) pairs.
Sourcepub fn empty_cnode(size_log: u8) -> Result<Self, CapError>
pub fn empty_cnode(size_log: u8) -> Result<Self, CapError>
Build an empty heap Cap::CNode of 2^size_log slots. Rejects
size_log > 16.
Sourcepub fn image_with_slots(
image: &Image,
pinned_hashes: &[(SlotIdx, CapHash)],
initial_hashes: &[(SlotIdx, CapHash)],
) -> Result<Self, ImageConvertError>
pub fn image_with_slots( image: &Image, pinned_hashes: &[(SlotIdx, CapHash)], initial_hashes: &[(SlotIdx, CapHash)], ) -> Result<Self, ImageConvertError>
Build a heap Cap::Image from a SCALE Image plus the caller-resolved
pinned/initial slot CapHash pairs.
Wraps super::image_cap::image_cap with the Cap::Image
constructor. Use this when the caller has already
published (or knows the hashes of) the pinned/initial data blobs that
the image references.
Sourcepub fn instance_with_overlays(
image_hash_chain: CapHash,
image_hash: CapHash,
root_cnode: CapHash,
rw_overlays: &[(u32, &[u8])],
mem_size: u32,
regs: [u64; 13],
pc: u64,
gas_remaining: u64,
) -> Self
pub fn instance_with_overlays( image_hash_chain: CapHash, image_hash: CapHash, root_cnode: CapHash, rw_overlays: &[(u32, &[u8])], mem_size: u32, regs: [u64; 13], pc: u64, gas_remaining: u64, ) -> Self
Build a heap Cap::Instance directly from field values. Mirrors the
shape the old CacheDirectory::publish_instance_blob reconstructed
field-by-field but produces a Cap::Instance(InstanceCap)
the caller owns.
rw_overlays is the list of (start_va, bytes) overlays the
Instance carries — each becomes one RwOverlay entry.