Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 43 additions & 25 deletions host/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 2 additions & 6 deletions host/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,9 @@ name = "pyhl"
path = "src/bin/pyhl.rs"

[dependencies]
# Point at danbugs/hyperlight snapshot-to-disk, which is upstream main
# (the map_file_cow unaligned fix landed there) plus a squashed port of
# hyperlight-dev/hyperlight#1373 — Ludvig's Snapshot::to_file/from_file
# feature. We use it to persist a warmed-up sandbox on `pyhl setup` and
# load it directly on every `pyhl run`, avoiding evolve + warmup per
# invocation.
hyperlight-host = { git = "https://github.com/danbugs/hyperlight", branch = "snapshot-to-disk", features = ["executable_heap", "hw-interrupts"] }
# Uses PAGE_READONLY mapping (no host commit charge per VM).
hyperlight-host = { git = "https://github.com/hyperlight-dev/hyperlight", branch = "disk_snapshot_copy", features = ["executable_heap", "hw-interrupts"] }
clap = { version = "4", features = ["derive", "env"] }
anyhow = "1"
memmap2 = "0.9"
Expand Down
21 changes: 12 additions & 9 deletions host/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ use hyperlight_host::func::Registerable;
use hyperlight_host::sandbox::snapshot::Snapshot;
use hyperlight_host::sandbox::uninitialized::GuestEnvironment;
use hyperlight_host::sandbox::SandboxConfiguration;
use hyperlight_host::{GuestBinary, MultiUseSandbox, UninitializedSandbox};
use hyperlight_host::{GuestBinary, HostFunctions, MultiUseSandbox, UninitializedSandbox};
use std::collections::HashMap;
use std::path::Path;
use std::sync::Arc;
Expand Down Expand Up @@ -1402,22 +1402,25 @@ impl Sandbox {
pub fn from_snapshot_file_with<P: AsRef<Path>>(path: P, preopens: &[Preopen]) -> Result<Self> {
let loaded = Snapshot::from_file_unchecked(path.as_ref())?;
let arc = Arc::new(loaded);
let mut inner = MultiUseSandbox::from_snapshot(arc.clone())?;

// Wire up the fs_* tool handlers against the caller's preopens.
// The snapshot was warmed up with hostfs already mounted, so the
// guest will route fs_* calls through __dispatch → the FsRouter
// we install here.
let mut host_funcs = HostFunctions::default();
if !preopens.is_empty() {
if let Some(tools) = build_tools(None, preopens)? {
let tools = Arc::new(tools);
let tools_ref = tools.clone();
inner.register_host_function("__dispatch", move |payload: Vec<u8>| -> Vec<u8> {
tools_ref.dispatch(&payload)
})?;
host_funcs
.register_host_function("__dispatch", move |payload: Vec<u8>| -> Vec<u8> {
tools_ref.dispatch(&payload)
})?;
}
} else {
host_funcs.register_host_function("__dispatch", |_payload: Vec<u8>| -> Vec<u8> {
Vec::new()
})?;
}

let inner = MultiUseSandbox::from_snapshot(arc.clone(), host_funcs, None)?;

Ok(Self {
inner,
snapshot: Some(arc),
Expand Down
Loading