tiny.machine.checkpoint.stream
Defined in checkpoint.
Moving a machine capture between processes, files, and hosts requires turning that capture into bytes.
API (7)
Actions
Public operations.
decodeDisjoint: Draws exactly one stream from the reader into empty storage and page-aligned memory that the caller owns.decodeHeader: Decodes one fixed 4096-byte header underexpected_root.encodeDisjoint: Checks the durable checkpoint first, then emits a header and the whole normalized memory behind it.encodeHeader: Encodes authenticated checkpoint metadata into one fixed 4096-byte header.
Types and contracts
Public types and contracts.
Error: The error set covers the framing, identity, alias, storage, and input-output failures of a checkpoint stream.
Values and defaults
Public values and defaults.
Source
Source: lib/machine/src/checkpoint/stream/codec.zig:35
zig
/// Draws exactly one stream from the reader into empty storage and page-aligned/// memory that the caller owns. The reader and its buffer sit outside both/// destinations. Framing, trailing data, a root mismatch, or failed/// authentication aborts the publication. An abort returns the claimed storage/// to empty, so the caller can try again with the same storage. The destination/// memory can hold received bytes after a failure. Success returns a handle/// borrowing the caller's storage and memory.pub fn decodeDisjoint( reader: *std.Io.Reader, expected_root: owner.Root, storage: *owner.Storage, ram: []align(owner.ram_alignment) u8,) Error!owner.Checkpoint { try validateSource(reader, storage, ram); var header_bytes_buffer: [header_bytes]u8 = undefined; try readExact(reader, &header_bytes_buffer); const decoded = try decode.header(&header_bytes_buffer, expected_root); var materialization = try owner.beginMaterialization(storage, ram); errdefer owner.abortMaterialization(&materialization); try readExact(reader, ram); var trailing: [1]u8 = undefined; if (try reader.readSliceShort(&trailing) != 0) return error.TrailingData; return owner.publishMaterialized( &materialization, decoded.material, expected_root, decoded.memory, );}Source: lib/machine/src/checkpoint/stream/codec.zig:16
zig
/// Checks the durable checkpoint first, then emits a header and the whole/// normalized memory behind it. The writer and its buffer sit outside the/// checkpoint handle, the storage behind it, and its memory. When input or/// output fails partway, the bytes already handed to the writer stay there.pub fn encodeDisjoint( checkpoint: *const owner.Checkpoint, writer: *std.Io.Writer,) Error!void { try validateSink(checkpoint, writer); const contents = try owner.inspect(checkpoint); var header_bytes_buffer: [header_bytes]u8 = undefined; encode.header(contents, &header_bytes_buffer); try writer.writeAll(&header_bytes_buffer); try writer.writeAll(checkpoint.ram);}Source: lib/machine/src/checkpoint/stream/decode.zig:17
zig
/// Decodes one fixed 4096-byte header under `expected_root`. The function/// validates the framing, the reserved ranges, the root fields, and the settled/// receipt. A decoded root other than `expected_root` returns/// `CheckpointRootMismatch`. The call returns the material and a memory digest,/// which the caller authenticates against the memory bytes that follow.pub fn header( input: *const [schema.header_bytes]u8, expected_root: owner.Root,) stream_types.Error!stream_types.Decoded { try validateEnvelope(input); try validateReserved(input); const root_value = try decodeRoot(input); if (!std.meta.eql(root_value, expected_root)) { return error.CheckpointRootMismatch; } const memory: owner.MemoryDigest = .{ .digest = digest(input, schema.MemoryLayout.digest_offset), }; try validateDigest(memory.digest); const receipt = try decodeSemantic(input); const cpu = decodeCpu(input); return .{ .material = .{ .profile = root_value.profile, .receipt = receipt, .cpu = cpu, .immutable_image = decodeImmutable(input, cpu), }, .memory = memory, };}Source: lib/machine/src/checkpoint/stream/encode.zig:15
zig
/// Encodes authenticated checkpoint metadata into one fixed 4096-byte header./// Callers supply the `Contents` that checkpoint inspection returned. The call/// starts from a zero-filled buffer, so every unused byte and every reserved/// range is zero. The function writes the envelope, the checkpoint root and/// memory digest, the settled receipt, the CPU restart frame, and the immutable/// image descriptor.pub fn header( contents: owner.Contents, output: *[schema.header_bytes]u8,) void { var encoded: [schema.header_bytes]u8 = @splat(0); encodeEnvelope(&encoded); encodeRoot(contents, &encoded); encodeSemantic(contents.material.receipt, &encoded); encodeCpu(contents.material.cpu, &encoded); encodeImmutable(contents.material.immutable_image, &encoded); output.* = encoded;}Source: lib/machine/src/checkpoint/stream/schema.zig:24
zig
pub const encoded_stream_bytes: u64 = 67_112_960;Source: lib/machine/src/checkpoint/stream/schema.zig:22
zig
pub const page_bytes: u32 = 4096;Source: lib/machine/src/checkpoint/stream/types.zig:8
zig
/// The error set covers the framing, identity, alias, storage, and input-output/// failures of a checkpoint stream. The set includes the reader and writer/// failures of the standard input-output interfaces and every durable/// checkpoint failure.pub const Error = error{ AbiVersionMismatch, BadMagic, CheckpointFormatMismatch, HeaderBytesMismatch, MetadataShapeMismatch, PageBytesMismatch, ReservedNonzero, SinkAliasesCheckpoint, SourceAliasesDestination, StreamBytesMismatch, TrailingData, TruncatedStream, UnsupportedFlags, UnsupportedVersion,} || std.Io.Reader.ShortError || std.Io.Writer.Error || owner.Error;Source: lib/machine/src/checkpoint/root.zig:89
zig
pub const stream = @import("stream/root.zig");Source: lib/machine/src/checkpoint/stream/root.zig
zig
//! Moving a machine capture between processes, files, and hosts requires//! turning that capture into bytes. 4096 contiguous bytes of a machine's//! memory, named by its zero-based index, form a *page*. The machine's fixed//! 67,108,864 bytes, addressed from zero and holding 16,384 pages, form its//! *memory*. A memory image whose page tables have been rewritten to their//! canonical form and whose boot frame, request ring, event ring, and kernel//! stack are zeroed is *normalized memory*. A checkpoint holding a complete//! normalized memory image in two caller-owned regions is a *durable//! checkpoint*. The calls here write one complete durable checkpoint as bytes//! and read one back. The fixed 67,112,960-byte encoding of one durable//! checkpoint, formed by 4096 leading bytes followed by all normalized memory,//! is the *checkpoint stream*. The stream's first 4096 bytes form the *header*.//!//! The digest binding one profile fingerprint to one state digest is the//! *checkpoint root*. The SHA-256 identity of a normalized memory image is the//! *memory digest*. The record of a stopped machine boundary with activation//! authority removed, so one guest state keeps one identity across runs, is the//! *settled receipt*. The ten register values a restarted machine begins with//! form the *CPU restart frame*. The kernel image's digest, the initial CPU//! state it admits, its entry offset, and up to four load ranges placing image//! bytes in memory form the *immutable image descriptor*. Header byte ranges//! the writer fills with zero and the reader requires to be zero are the//! *reserved bytes*. The header encodes the checkpoint root, the memory digest,//! the settled receipt, the CPU restart frame, and the immutable image//! descriptor in little-endian fields.//!//! A capture arriving as bytes comes from outside the reader's control, so//! every field it carries has to be checked before the capture is used. Two//! builds have to agree on the layout down to the byte, so the header states//! its own field widths and the reader compares each one.//!//! The caller-owned metadata region holding a publication status and the//! authenticated metadata behind it is the *checkpoint storage*. A reader that//! claimed the caller's storage and then failed would leave that storage//! unusable.//!//! Encoding verifies the checkpoint before it writes a byte.//!//! Decoding rejects a wrong magic value, version, header size, flag word,//! format, stream or memory byte count, page size, interface version, or field//! width. Decoding requires every reserved range to be zero. Decoding requires//! the header's checkpoint root to equal the root the caller expected, and it//! reads that root before the memory bytes arrive. Decoding rejects a stream//! that ends early and a stream with bytes after the memory image. The//! fixed-size values needed to recompute an identity and rebuild execution://! profile fingerprint, settled receipt, CPU restart frame, and immutable image//! descriptor, are the *material*. Decoding rejects material that fails its own//! verification, so a settled receipt that does not check out returns//! `CheckpointCorrupt`. Decoding rejects a reader whose object or buffer//! overlaps either destination.//!//! A publication claim held open while another source fills the memory,//! published only after the filled bytes authenticate, is a *materialization*.//! Decoding conducts that materialization across the caller's checkpoint//! storage and memory region, authenticating the bytes against the header's//! memory digest and checkpoint root. A failure after the claim aborts it and//! returns the storage to empty.const codec = @import("codec.zig");const decode = @import("decode.zig");const encode = @import("encode.zig");pub const Error = codec.Error;pub const decodeHeader = decode.header;pub const decodeDisjoint = codec.decodeDisjoint;pub const encodeHeader = encode.header;pub const encodeDisjoint = codec.encodeDisjoint;pub const header_bytes = codec.header_bytes;pub const stream_bytes = codec.stream_bytes;Complete call list for checkpoint.stream.decodeHeader
8 direct calls.
lib.machine.src.checkpoint.stream.decode.decodeCpu[function] — private source atlib/machine/src/checkpoint/stream/decode.zig:230in nearest public ownerlib.machine.src.checkpoint.stream.decodelib.machine.src.checkpoint.stream.decode.decodeImmutable[function] — private source atlib/machine/src/checkpoint/stream/decode.zig:246in nearest public ownerlib.machine.src.checkpoint.stream.decodelib.machine.src.checkpoint.stream.decode.decodeRoot[function] — private source atlib/machine/src/checkpoint/stream/decode.zig:122in nearest public ownerlib.machine.src.checkpoint.stream.decodelib.machine.src.checkpoint.stream.decode.decodeSemantic[function] — private source atlib/machine/src/checkpoint/stream/decode.zig:140in nearest public ownerlib.machine.src.checkpoint.stream.decodelib.machine.src.checkpoint.stream.decode.digest[function] — private source atlib/machine/src/checkpoint/stream/decode.zig:279in nearest public ownerlib.machine.src.checkpoint.stream.decodelib.machine.src.checkpoint.stream.decode.validateDigest[function] — private source atlib/machine/src/checkpoint/stream/decode.zig:286in nearest public ownerlib.machine.src.checkpoint.stream.decodelib.machine.src.checkpoint.stream.decode.validateEnvelope[function] — private source atlib/machine/src/checkpoint/stream/decode.zig:44in nearest public ownerlib.machine.src.checkpoint.stream.decodelib.machine.src.checkpoint.stream.decode.validateReserved[function] — private source atlib/machine/src/checkpoint/stream/decode.zig:101in nearest public ownerlib.machine.src.checkpoint.stream.decode
Audit
| Definitions | 8 |
|---|---|
| Public names | 8 |
| Members | 0 |
| Version | 26.7.0 |
| Revision | daab053ee433 |