Skip to content

Commit a5fda11

Browse files
committed
host: switch to disk_snapshot_copy (PR #1373, PAGE_READONLY)
Signed-off-by: danbugs <danilochiarlone@gmail.com>
1 parent 8b9d519 commit a5fda11

3 files changed

Lines changed: 58 additions & 40 deletions

File tree

host/Cargo.lock

Lines changed: 43 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

host/Cargo.toml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,9 @@ name = "pyhl"
2727
path = "src/bin/pyhl.rs"
2828

2929
[dependencies]
30-
# Point at danbugs/hyperlight snapshot-to-disk, which is upstream main
31-
# (the map_file_cow unaligned fix landed there) plus a squashed port of
3230
# hyperlight-dev/hyperlight#1373 — Ludvig's Snapshot::to_file/from_file
33-
# feature. We use it to persist a warmed-up sandbox on `pyhl setup` and
34-
# load it directly on every `pyhl run`, avoiding evolve + warmup per
35-
# invocation.
36-
hyperlight-host = { git = "https://github.com/danbugs/hyperlight", branch = "snapshot-to-disk", features = ["executable_heap", "hw-interrupts"] }
31+
# Uses PAGE_READONLY mapping (no host commit charge per VM).
32+
hyperlight-host = { git = "https://github.com/hyperlight-dev/hyperlight", branch = "disk_snapshot_copy", features = ["executable_heap", "hw-interrupts"] }
3733
clap = { version = "4", features = ["derive", "env"] }
3834
anyhow = "1"
3935
memmap2 = "0.9"

host/src/lib.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ use hyperlight_host::func::Registerable;
6464
use hyperlight_host::sandbox::snapshot::Snapshot;
6565
use hyperlight_host::sandbox::uninitialized::GuestEnvironment;
6666
use hyperlight_host::sandbox::SandboxConfiguration;
67-
use hyperlight_host::{GuestBinary, MultiUseSandbox, UninitializedSandbox};
67+
use hyperlight_host::{GuestBinary, HostFunctions, MultiUseSandbox, UninitializedSandbox};
6868
use std::collections::HashMap;
6969
use std::path::Path;
7070
use std::sync::Arc;
@@ -1402,22 +1402,26 @@ impl Sandbox {
14021402
pub fn from_snapshot_file_with<P: AsRef<Path>>(path: P, preopens: &[Preopen]) -> Result<Self> {
14031403
let loaded = Snapshot::from_file_unchecked(path.as_ref())?;
14041404
let arc = Arc::new(loaded);
1405-
let mut inner = MultiUseSandbox::from_snapshot(arc.clone())?;
14061405

1407-
// Wire up the fs_* tool handlers against the caller's preopens.
1408-
// The snapshot was warmed up with hostfs already mounted, so the
1409-
// guest will route fs_* calls through __dispatch → the FsRouter
1410-
// we install here.
1406+
let mut host_funcs = HostFunctions::default();
14111407
if !preopens.is_empty() {
14121408
if let Some(tools) = build_tools(None, preopens)? {
14131409
let tools = Arc::new(tools);
14141410
let tools_ref = tools.clone();
1415-
inner.register_host_function("__dispatch", move |payload: Vec<u8>| -> Vec<u8> {
1416-
tools_ref.dispatch(&payload)
1417-
})?;
1411+
host_funcs.register_host_function(
1412+
"__dispatch",
1413+
move |payload: Vec<u8>| -> Vec<u8> { tools_ref.dispatch(&payload) },
1414+
)?;
14181415
}
1416+
} else {
1417+
host_funcs.register_host_function(
1418+
"__dispatch",
1419+
|_payload: Vec<u8>| -> Vec<u8> { Vec::new() },
1420+
)?;
14191421
}
14201422

1423+
let inner = MultiUseSandbox::from_snapshot(arc.clone(), host_funcs, None)?;
1424+
14211425
Ok(Self {
14221426
inner,
14231427
snapshot: Some(arc),

0 commit comments

Comments
 (0)