Skip to content

Commit e9a13c4

Browse files
committed
feat!: replace shared-memory init data with virtqueue buffers
Remove the peb backed init-data region and APIs. Use retained virtqueue ByteChunks for startup data. After removing the init section PEB no longer contains any data so it can be removed as well. Signed-off-by: Tomasz Andrzejak <andreiltd@gmail.com>
1 parent a030884 commit e9a13c4

35 files changed

Lines changed: 283 additions & 757 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
44

55
## [Prerelease] - Unreleased
66

7+
### Changed
8+
* **Breaking:** Snapshots use ABI 10 and config schema v6. Guests must be rebuilt
9+
and existing snapshots regenerated. Guest entry takes the random seed, host
10+
page size, and log level.
11+
12+
### Removed
13+
* **Breaking:** `SandboxBuilder::init_data`, `GuestEnvironment`, `GuestBlob`,
14+
`GuestHandle`, `HyperlightPEB`, and `read_n_bytes_from_user_memory`.
15+
Pass startup data through a host function and retain its `ByteChunks` reply.
16+
`UninitializedSandbox::new` takes a `GuestBinary`.
17+
718
## [v0.19.0] - 2026-11-04
819

920
### Added

‎docs/how-to-build-a-hyperlight-guest-binary.md‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,20 @@ If you mix the manual form with `#[guest_function]`, registrations from the
119119
macro still happen automatically. Your `hyperlight_main` only needs to do
120120
whatever extra setup the macros do not cover.
121121

122+
### Startup data
123+
124+
Register a host function before `SandboxBuilder::build` or
125+
`UninitializedSandbox::evolve`. Call it from `hyperlight_main` and keep its
126+
`Vec<Bytes>` reply in guest state. Transport is ready before `hyperlight_main`.
127+
The reply's `ByteChunks` buffers remain valid across calls, snapshots,
128+
restores, and forks.
129+
130+
For data needed after startup, pass `Vec<Bytes>` to a guest function and retain
131+
it there. A `Vec<u8>` parameter or return value copies into guest-owned memory.
132+
Retained buffers occupy transport pool slots. Size the pools for retained data
133+
plus later calls, or copy large inputs into guest memory as you fetch chunks.
134+
Retained buffers do not provide custom page permissions.
135+
122136
### Troubleshooting
123137

124138
#### "duplicate lang item `panic_impl`" error

‎docs/snapshot-oci-format.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Four blob kinds per tag:
3232
* **manifest** (`application/vnd.oci.image.manifest.v1+json`). Tiny JSON
3333
pointer record selected via `index.json`. References one config,
3434
the snapshot blobs, and one transport layer by digest.
35-
* **config** (`application/vnd.hyperlight.snapshot.config.v5+json`). The
35+
* **config** (`application/vnd.hyperlight.snapshot.config.v6+json`). The
3636
snapshot descriptor: arch, hypervisor, CPU vendor, ABI version,
3737
resume address and captured registers, memory and transport layout,
3838
registered host functions, the start address, data length, and page-table

‎docs/snapshot-versioning.md‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ A snapshot carries four independently evolvable version markers:
1414
[src/hyperlight_host/src/sandbox/snapshot/file/media_types.rs](../src/hyperlight_host/src/sandbox/snapshot/file/media_types.rs)).
1515
This is what the host reads back from a snapshot: the `OutBAction`
1616
and `VmAction` port numbers, the virtqueue transport layout, the
17-
offset and size of each memory region (including the `HyperlightPEB`
18-
size), and the calling convention for guest function entry. A change
17+
offset and size of each memory region, and the calling convention for
18+
guest function entry. A change
1919
to any of these breaks older snapshots unless the loader adds a
2020
compat path.
2121
* **Snapshot blob encoding**, `MT_SNAPSHOT_V2`
@@ -27,16 +27,17 @@ A snapshot carries four independently evolvable version markers:
2727
(`application/vnd.hyperlight.snapshot.transport.v1`), aliased as
2828
`MT_TRANSPORT_CURRENT`. This is the binary encoding of canonical
2929
virtqueue state stored outside the memory layer.
30-
* **Config schema**, `MT_CONFIG_V5`
31-
(`application/vnd.hyperlight.snapshot.config.v5+json`), aliased as
30+
* **Config schema**, `MT_CONFIG_V6`
31+
(`application/vnd.hyperlight.snapshot.config.v6+json`), aliased as
3232
`MT_CONFIG_CURRENT`. This is the JSON shape of the config blob:
3333
field names, types, required vs optional, the descriptors the loader
3434
needs in order to reconstruct the sandbox (memory sizes, buffer
3535
sizes, `abi_version`, `hyperlight_version`, etc.). Renaming a field,
3636
changing its type, or adding a required field is a schema change and
3737
bumps this constant. Version 4 describes snapshot blobs, the blob with
3838
the page tables, and transport geometry, and requires a transport
39-
layer. Version 5 drops the heap size. Config v1 to v4 are incompatible
39+
layer. Version 5 drops the heap size. Version 6 contains code and scratch
40+
geometry without init-data fields. Config v1 to v5 are incompatible
4041
with the current ABI.
4142

4243
ABI 6 requires checkpoint readiness after guest initialization and permits
@@ -52,6 +53,9 @@ regenerated.
5253
ABI 9 removes the heap region from snapshot memory. Earlier snapshots must
5354
be regenerated.
5455

56+
ABI 10 contains no PEB or init-data region. Guest entry takes the random seed,
57+
host page size, and log level. Earlier snapshots must be regenerated.
58+
5559
The `OCI_LAYOUT_VERSION` constant is pinned by the OCI image-layout
5660
spec at `1.0.0`.
5761

@@ -83,7 +87,7 @@ Compile-time tripwires in
8387
[src/hyperlight_host/src/sandbox/snapshot/tripwires.rs](../src/hyperlight_host/src/sandbox/snapshot/tripwires.rs)
8488
hold a copy of every value that defines the format:
8589
`SNAPSHOT_ABI_VERSION`, the snapshot and config media-type strings, the
86-
OCI layout version, the `HyperlightPEB` size, every `OutBAction` and
90+
OCI layout version, every `OutBAction` and
8791
`VmAction` discriminant, and `BASE_ADDRESS`. If the source value
8892
drifts from the copy in `tripwires.rs`, the crate fails to compile.
8993

‎src/hyperlight_common/src/lib.rs‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ pub mod layout;
2424
// cbindgen:ignore
2525
pub mod log_level;
2626

27-
/// cbindgen:ignore
28-
pub mod mem;
29-
3027
/// cbindgen:ignore
3128
pub mod outb;
3229

‎src/hyperlight_common/src/mem.rs‎

Lines changed: 0 additions & 38 deletions
This file was deleted.

‎src/hyperlight_guest/src/guest_handle/handle.rs‎

Lines changed: 0 additions & 59 deletions
This file was deleted.

‎src/hyperlight_guest/src/lib.rs‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,3 @@ pub mod paging;
1919
pub mod prim_alloc;
2020
pub mod transport;
2121
pub mod types;
22-
23-
pub mod guest_handle {
24-
pub mod handle;
25-
}

‎src/hyperlight_guest_bin/src/arch/aarch64/mod.rs‎

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,16 @@ unsafe fn init_vbar() {
5656
/// Machine-specific initialisation; calls [`crate::generic_init`]
5757
/// once VBAR and the main stack have been set up
5858
#[unsafe(no_mangle)]
59-
pub extern "C" fn entrypoint(peb_address: u64, seed: u64, ops: u64, max_log_level: u64) -> ! {
59+
pub extern "C" fn entrypoint(seed: u64, ops: u64, max_log_level: u64) -> ! {
6060
unsafe {
6161
init_vbar();
6262
let stack_top = crate::init::init_stack();
63-
pivot_stack(peb_address, seed, ops, max_log_level, stack_top);
63+
pivot_stack(seed, ops, max_log_level, stack_top);
6464
}
6565
}
6666

6767
unsafe extern "C" {
68-
unsafe fn pivot_stack(
69-
peb_address: u64,
70-
seed: u64,
71-
ops: u64,
72-
max_log_level: u64,
73-
stack_top: u64,
74-
) -> !;
68+
unsafe fn pivot_stack(seed: u64, ops: u64, max_log_level: u64, stack_top: u64) -> !;
7569
}
7670

7771
core::arch::global_asm!("
@@ -83,7 +77,7 @@ core::arch::global_asm!("
8377
msr SPSel, #1\n
8478
mov sp, x5\n
8579
msr SPSel, #0\n
86-
mov sp, x4\n
80+
mov sp, x3\n
8781
bl {generic_init}\n
8882
ldr x1, ={hlt_addr}\n
8983
str x0, [x1]\n

‎src/hyperlight_guest_bin/src/arch/amd64/init.rs‎

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ unsafe fn init_tss(pc: *mut ProcCtrl) {
9494
/// Machine-specific initialisation; calls [`crate::generic_init`]
9595
/// once stack, CoW, etc have been set up.
9696
#[unsafe(no_mangle)]
97-
pub extern "C" fn entrypoint(peb_address: u64, seed: u64, ops: u64, max_log_level: u64) {
97+
pub extern "C" fn entrypoint(seed: u64, ops: u64, max_log_level: u64) {
9898
unsafe {
9999
// Allocate a VA for processor control structures which must
100100
// survive snapshotting at the same VA.
@@ -108,18 +108,12 @@ pub extern "C" fn entrypoint(peb_address: u64, seed: u64, ops: u64, max_log_leve
108108
// Architecture early init is complete! We pivot now to
109109
// executing on the main stack, and jump into generic
110110
// initialisation code in lib.rs
111-
pivot_stack(peb_address, seed, ops, max_log_level, stack_top);
111+
pivot_stack(seed, ops, max_log_level, stack_top);
112112
}
113113
}
114114

115115
unsafe extern "C" {
116-
unsafe fn pivot_stack(
117-
peb_address: u64,
118-
seed: u64,
119-
ops: u64,
120-
max_log_level: u64,
121-
stack_top: u64,
122-
) -> !;
116+
unsafe fn pivot_stack(seed: u64, ops: u64, max_log_level: u64, stack_top: u64) -> !;
123117
}
124118

125119
// Mark this as the bottom-most frame for debuggers:
@@ -135,7 +129,7 @@ core::arch::global_asm!("
135129
pivot_stack:\n
136130
.cfi_startproc\n
137131
.cfi_undefined rip\n
138-
mov rsp, r8\n
132+
mov rsp, rcx\n
139133
xor ebp, ebp\n
140134
call {generic_init}\n
141135
mov dx, {halt_port}\n

0 commit comments

Comments
 (0)