~/bend-docscommunity

src/vmm/snapfile.bend checks

raw source on the hub · import 0xd595fdc5ca98e64512c8df6e3130c270/src/vmm/snapfile.bend as Snapfile

3 imports
import Base
import ../lib/u64.bend as U
import ../lib/bytes.bend as B

Types

type Part source · line 56 · raw

Data

A part of the file: its offset and length.

type Layout source · line 61 · raw

Data

Where each part lies in the file: argv, the machine words, the GIC state and each vCPU's blob as (offset, length), and RAM's offset.

type Piece source · line 67 · raw

Data

One write of the plan the host carries out, at a file offset: bytes given here, or a part the host holds (the machine words, the GIC state, vCPU i's register blob, guest RAM, argv).

type Need source · line 77 · raw

Data

A step of reading a file's layout: read the u64 length at off next, the file is bad, or the layout is known.

Definitions

def Snapf.magic source · line 24 · raw

List<&2, U32>

def Snapf.max_cpus source · line 28 · raw

U32

def Snapf.max_args source · line 31 · raw

0xd595fdc5ca98e64512c8df6e3130c270/src/lib/u64.U64

def Snapf.max_words source · line 35 · raw

0xd595fdc5ca98e64512c8df6e3130c270/src/lib/u64.U64

def Snapf.max_gic source · line 39 · raw

0xd595fdc5ca98e64512c8df6e3130c270/src/lib/u64.U64

def Snapf.max_cpu source · line 43 · raw

0xd595fdc5ca98e64512c8df6e3130c270/src/lib/u64.U64

def Snapf.max_ram source · line 47 · raw

0xd595fdc5ca98e64512c8df6e3130c270/src/lib/u64.U64

def Snapf.len source · line 85 · raw

@-A:Data -> @+xs:List<&2, A> -> 0xd595fdc5ca98e64512c8df6e3130c270/src/lib/u64.U64

def Snapf.after source · line 89 · raw

@a:0xd595fdc5ca98e64512c8df6e3130c270/src/lib/u64.U64 -> @n:0xd595fdc5ca98e64512c8df6e3130c270/src/lib/u64.U64 -> 0xd595fdc5ca98e64512c8df6e3130c270/src/lib/u64.U64

a past b by n bytes and an 8-byte length prefix

def Snapf.within source · line 92 · raw

@+a:0xd595fdc5ca98e64512c8df6e3130c270/src/lib/u64.U64 -> @+max:0xd595fdc5ca98e64512c8df6e3130c270/src/lib/u64.U64 -> Bool

def Snapf.cpus_within source · line 95 · raw

@cs:List<&2, 0xd595fdc5ca98e64512c8df6e3130c270/src/lib/u64.U64> -> Bool

def Snapf.ram_ok source · line 102 · raw

@+ram:0xd595fdc5ca98e64512c8df6e3130c270/src/lib/u64.U64 -> Bool

def Snapf.head_bytes source · line 106 · raw

@h:Head -> List<&2, U32>

The header's 40 bytes.

def Head.nargs source · line 115 · raw

@h:Head -> 0xd595fdc5ca98e64512c8df6e3130c270/src/lib/u64.U64

def Head.ncpus source · line 120 · raw

@h:Head -> U32

def Snapf.words_at source · line 125 · raw

@+h:Head -> 0xd595fdc5ca98e64512c8df6e3130c270/src/lib/u64.U64

def Snapf.gic_at source · line 128 · raw

@+h:Head -> @+nw:0xd595fdc5ca98e64512c8df6e3130c270/src/lib/u64.U64 -> 0xd595fdc5ca98e64512c8df6e3130c270/src/lib/u64.U64

def Snapf.plan.cpus source · line 134 · raw

@cs:List<&2, 0xd595fdc5ca98e64512c8df6e3130c270/src/lib/u64.U64> -> @+i:U32 -> @+at:0xd595fdc5ca98e64512c8df6e3130c270/src/lib/u64.U64 -> List<&2, Piece>

The vCPU blobs from offset at: each one's length, then the blob; RAM at the next 16 KiB boundary after the last.

def Snapf.plan.pieces source · line 141 · raw

@+h:Head -> @+nwords:0xd595fdc5ca98e64512c8df6e3130c270/src/lib/u64.U64 -> @+ngic:0xd595fdc5ca98e64512c8df6e3130c270/src/lib/u64.U64 -> @cs:List<&2, 0xd595fdc5ca98e64512c8df6e3130c270/src/lib/u64.U64> -> List<&2, Piece>

def Snapf.plan.pick source · line 152 · raw

@ok:Bool -> @ps:List<&2, Piece> -> Maybe<&2, List<&2, Piece>>

def Snapf.plan source · line 162 · raw

@ver:U32 -> @base:0xd595fdc5ca98e64512c8df6e3130c270/src/lib/u64.U64 -> @+ram:0xd595fdc5ca98e64512c8df6e3130c270/src/lib/u64.U64 -> @+nargs:0xd595fdc5ca98e64512c8df6e3130c270/src/lib/u64.U64 -> @+nwords:0xd595fdc5ca98e64512c8df6e3130c270/src/lib/u64.U64 -> @+ngic:0xd595fdc5ca98e64512c8df6e3130c270/src/lib/u64.U64 -> @+cs:List<&2, 0xd595fdc5ca98e64512c8df6e3130c270/src/lib/u64.U64> -> Maybe<&2, List<&2, Piece>>

The writes of a snapshot of a VM with this hypervisor version, RAM base and size, argv length, machine word count, GIC state length and vCPU blob lengths; None when a loader would refuse the file.

def Snapf.word.got source · line 168 · raw

@m:Maybe<&2, U32> -> U32

def Snapf.word source · line 175 · raw

@+ws:List<&2, U32> -> @k:Nat -> U32

def Snapf.u64_at source · line 178 · raw

@+ws:List<&2, U32> -> @+k:Nat -> 0xd595fdc5ca98e64512c8df6e3130c270/src/lib/u64.U64

def Snapf.lens source · line 181 · raw

@ws:List<&2, U32> -> List<&2, 0xd595fdc5ca98e64512c8df6e3130c270/src/lib/u64.U64>

def Snapf.plan_of.pick source · line 188 · raw

@ok:Bool -> @p:Maybe<&2, List<&2, Piece>> -> Maybe<&2, List<&2, Piece>>

def Snapf.plan_of source · line 198 · raw

@+ws:List<&2, U32> -> Maybe<&2, List<&2, Piece>>

The plan for the sizes the host answers (Hvf.snap_save): [version, RAM base, RAM size, argv length, word count, GIC length (each hi, lo), vCPUs, then each vCPU's blob length (hi, lo)].

def Snapf.tmp source · line 210 · raw

@path:String -> String

A snapshot is written to a file of its own next to path, then renamed over path: a failed write leaves what path held (the host removes its file), and the snapshot a VM was restored from, whose RAM is mapped, can be replaced.

def Snapf.head.pick source · line 216 · raw

@ok:Bool -> @h:Head -> Maybe<&2, Head>

def Snapf.magic_is source · line 223 · raw

@a:List<&2, U32> -> @b:List<&2, U32> -> Bool

def Snapf.head source · line 233 · raw

@+ver:U32 -> @+bs:List<&2, U32> -> Maybe<&2, Head>

The first 40 bytes of a snapshot from a host whose version is ver.

def Snapf.need.cpus source · line 244 · raw

@left:Nat -> @lens:List<&2, 0xd595fdc5ca98e64512c8df6e3130c270/src/lib/u64.U64> -> @+h:Head -> @+nw:0xd595fdc5ca98e64512c8df6e3130c270/src/lib/u64.U64 -> @+ng:0xd595fdc5ca98e64512c8df6e3130c270/src/lib/u64.U64 -> @+at:0xd595fdc5ca98e64512c8df6e3130c270/src/lib/u64.U64 -> @acc:List<&2, Part> -> Need

The vCPU blobs: left more to read from at, with lens the lengths read so far past the GIC's (each within its bound, or the file is bad).

def Snapf.need.gic source · line 262 · raw

@rest:List<&2, 0xd595fdc5ca98e64512c8df6e3130c270/src/lib/u64.U64> -> @+h:Head -> @+nw:0xd595fdc5ca98e64512c8df6e3130c270/src/lib/u64.U64 -> Need

def Snapf.need source · line 273 · raw

@+h:Head -> @lens:List<&2, 0xd595fdc5ca98e64512c8df6e3130c270/src/lib/u64.U64> -> Need

What to read next, given the header and the length prefixes read so far (the machine words', the GIC's, then each vCPU's, in file order).

def Snapf.fits source · line 282 · raw

@l:Layout -> @+size:0xd595fdc5ca98e64512c8df6e3130c270/src/lib/u64.U64 -> Bool

The file holds all of RAM (it is mapped from the file: a short one would fault on the first touch past its end).

def Snapf.mem_mib source · line 290 · raw

@l:Layout -> U32

The machine a restore makes is the header's: its RAM (in MiB) and at least its vCPUs (a snapshot of a restored VM saves the restore's command line, which names neither), at the most the saved --cpus asked for.

def Snapf.cpus source · line 295 · raw

@l:Layout -> @+asked:U32 -> U32

def Snapf.agrees source · line 303 · raw

@l:Layout -> @+base:0xd595fdc5ca98e64512c8df6e3130c270/src/lib/u64.U64 -> Bool

The header describes a machine this host makes: RAM at base, a whole number of MiB below 2^40 (Snapf.head bounds it). A snapshot is a file from elsewhere: the host maps RAM by the header.

def Snapf.w64 source · line 311 · raw

@a:0xd595fdc5ca98e64512c8df6e3130c270/src/lib/u64.U64 -> List<&2, U32>

def Snapf.piece.wire source · line 319 · raw

@p:Piece -> List<&2, U32>

A piece for the host: [kind, offset hi, lo, ...]: 0 bytes (count, then the bytes), 1 the machine words, 2 the GIC state, 3 vCPU i's blob (i), 4 guest RAM, 5 argv.

def Snapf.pieces.wire source · line 334 · raw

@ps:List<&2, Piece> -> List<&2, U32>

def Snapf.cpus.wire source · line 344 · raw

@cs:List<&2, Part> -> List<&2, U32>

The host's load: [RAM base, RAM size, RAM offset, argv offset, argv length, words offset, words length in bytes, GIC offset, GIC length (each hi, lo), vCPUs, then per vCPU offset and length].

def Snapf.load.wire source · line 351 · raw

@l:Layout -> List<&2, U32>

def Snapf.version source · line 362 · raw

@+hv:U32 -> U32

The snapshot format each hypervisor writes and reads, from the host's fact (the first word Hvf.snap_save answers, the second of Hvf.snap_open's: 0 Hypervisor.framework, 1 KVM): version 1 holds Hypervisor.framework's register entries and hv_gic_state, version 2 KVM's register list and its vGIC replay. A snapshot restores only where its version is this host's; another hypervisor has no version (0, which no header carries).

def Snapf.sizes source · line 367 · raw

@ws:List<&2, U32> -> List<&2, U32>

The sizes Hvf.snap_save answers, with its hypervisor word made the format's version (Snapf.plan_of reads a version there).