Skip to content

Commit f0fa0c2

Browse files
committed
Document relaxed snapshot restore requirements
Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
1 parent 7d73f4e commit f0fa0c2

3 files changed

Lines changed: 55 additions & 72 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
1515
MSRs, on MSHV and WHP this is not enforced. by @ludfjig in https://github.com/hyperlight-dev/hyperlight/pull/991
1616
* **Breaking:** Filesystem paths are now represented using `PathBuf`. `GuestBinary::FilePath` now stores a `PathBuf` instead of a `String`, and `MultiUseSandbox::generate_crashdump_to_dir` accepts `Into<PathBuf>` instead of `Into<String>`. Callers passing a `String` to `GuestBinary::FilePath` must convert it using `.into()`.
1717
* Deprecate `MultiUseSandbox::poisoned` in favor of `MultiUseSandbox::status().is_poisoned()`.
18+
* `MultiUseSandbox::restore` has been made more flexible and now accepts snapshots from any guest binary or memory layout when host functions are compatible.
1819

1920
### Removed
2021

src/hyperlight_host/src/sandbox/initialized_multi_use.rs

Lines changed: 36 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,9 +1256,9 @@ mod tests {
12561256
use hyperlight_testing::sandbox_sizes::{LARGE_HEAP_SIZE, MEDIUM_HEAP_SIZE, SMALL_HEAP_SIZE};
12571257
use hyperlight_testing::{c_simple_guest_as_pathbuf, simple_guest_as_pathbuf};
12581258

1259+
use crate::func::host_functions::Registerable;
12591260
#[cfg(not(gdb))]
12601261
use crate::hypervisor::hyperlight_vm::{HyperlightVmError, test_support::VmOperation};
1261-
use crate::func::host_functions::Registerable;
12621262
use crate::mem::memory_region::{MemoryRegion, MemoryRegionFlags, MemoryRegionType};
12631263
use crate::mem::shared_mem::{ExclusiveSharedMemory, GuestSharedMemory, SharedMemory as _};
12641264
use crate::sandbox::SandboxConfiguration;
@@ -2590,13 +2590,11 @@ mod tests {
25902590
.unwrap()
25912591
.evolve()
25922592
.unwrap();
2593-
let mut target = UninitializedSandbox::new(
2594-
GuestBinary::FilePath(simple_guest_as_pathbuf()),
2595-
None,
2596-
)
2597-
.unwrap()
2598-
.evolve()
2599-
.unwrap();
2593+
let mut target =
2594+
UninitializedSandbox::new(GuestBinary::FilePath(simple_guest_as_pathbuf()), None)
2595+
.unwrap()
2596+
.evolve()
2597+
.unwrap();
26002598

26012599
assert_eq!(source.call::<i32>("StackAllocate", 256i32).unwrap(), 256);
26022600
assert_eq!(target.call::<i32>("AddToStatic", 17i32).unwrap(), 17);
@@ -2631,23 +2629,19 @@ mod tests {
26312629

26322630
#[test]
26332631
fn snapshot_restore_replaces_c_guest_with_rust_guest() {
2634-
let mut source = UninitializedSandbox::new(
2635-
GuestBinary::FilePath(simple_guest_as_pathbuf()),
2636-
None,
2637-
)
2638-
.unwrap()
2639-
.evolve()
2640-
.unwrap();
2632+
let mut source =
2633+
UninitializedSandbox::new(GuestBinary::FilePath(simple_guest_as_pathbuf()), None)
2634+
.unwrap()
2635+
.evolve()
2636+
.unwrap();
26412637
assert_eq!(source.call::<i32>("AddToStatic", 42i32).unwrap(), 42);
26422638
let snapshot = source.snapshot().unwrap();
26432639

2644-
let mut target = UninitializedSandbox::new(
2645-
GuestBinary::FilePath(c_simple_guest_as_pathbuf()),
2646-
None,
2647-
)
2648-
.unwrap()
2649-
.evolve()
2650-
.unwrap();
2640+
let mut target =
2641+
UninitializedSandbox::new(GuestBinary::FilePath(c_simple_guest_as_pathbuf()), None)
2642+
.unwrap()
2643+
.evolve()
2644+
.unwrap();
26512645
assert_eq!(target.call::<i32>("StackAllocate", 256i32).unwrap(), 256);
26522646

26532647
target.restore(snapshot).unwrap();
@@ -2663,33 +2657,27 @@ mod tests {
26632657

26642658
#[test]
26652659
fn snapshot_restore_alternates_c_and_rust_guests() {
2666-
let mut c_source = UninitializedSandbox::new(
2667-
GuestBinary::FilePath(c_simple_guest_as_pathbuf()),
2668-
None,
2669-
)
2670-
.unwrap()
2671-
.evolve()
2672-
.unwrap();
2660+
let mut c_source =
2661+
UninitializedSandbox::new(GuestBinary::FilePath(c_simple_guest_as_pathbuf()), None)
2662+
.unwrap()
2663+
.evolve()
2664+
.unwrap();
26732665
assert_eq!(c_source.call::<i32>("StackAllocate", 256i32).unwrap(), 256);
26742666
let c_snapshot = c_source.snapshot().unwrap();
26752667

2676-
let mut rust_source = UninitializedSandbox::new(
2677-
GuestBinary::FilePath(simple_guest_as_pathbuf()),
2678-
None,
2679-
)
2680-
.unwrap()
2681-
.evolve()
2682-
.unwrap();
2668+
let mut rust_source =
2669+
UninitializedSandbox::new(GuestBinary::FilePath(simple_guest_as_pathbuf()), None)
2670+
.unwrap()
2671+
.evolve()
2672+
.unwrap();
26832673
rust_source.call::<i32>("AddToStatic", 42i32).unwrap();
26842674
let rust_snapshot = rust_source.snapshot().unwrap();
26852675

2686-
let mut target = UninitializedSandbox::new(
2687-
GuestBinary::FilePath(c_simple_guest_as_pathbuf()),
2688-
None,
2689-
)
2690-
.unwrap()
2691-
.evolve()
2692-
.unwrap();
2676+
let mut target =
2677+
UninitializedSandbox::new(GuestBinary::FilePath(c_simple_guest_as_pathbuf()), None)
2678+
.unwrap()
2679+
.evolve()
2680+
.unwrap();
26932681
assert_eq!(target.call::<i32>("StackAllocate", 256i32).unwrap(), 256);
26942682

26952683
target.restore(rust_snapshot).unwrap();
@@ -2744,13 +2732,11 @@ mod tests {
27442732

27452733
#[test]
27462734
fn snapshot_restore_recovers_poison_with_different_guest() {
2747-
let mut source = UninitializedSandbox::new(
2748-
GuestBinary::FilePath(c_simple_guest_as_pathbuf()),
2749-
None,
2750-
)
2751-
.unwrap()
2752-
.evolve()
2753-
.unwrap();
2735+
let mut source =
2736+
UninitializedSandbox::new(GuestBinary::FilePath(c_simple_guest_as_pathbuf()), None)
2737+
.unwrap()
2738+
.evolve()
2739+
.unwrap();
27542740
let snapshot = source.snapshot().unwrap();
27552741

27562742
let path = simple_guest_as_pathbuf();

src/hyperlight_host/tests/wit_test.rs

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ use std::sync::{Arc, Mutex};
1919

2020
use hyperlight_common::resource::BorrowedResourceGuard;
2121
use hyperlight_host::{GuestBinary, MultiUseSandbox, UninitializedSandbox};
22-
use hyperlight_testing::{c_simple_guest_as_pathbuf, simple_guest_as_pathbuf, wit_guest_as_pathbuf};
22+
use hyperlight_testing::{
23+
c_simple_guest_as_pathbuf, simple_guest_as_pathbuf, wit_guest_as_pathbuf,
24+
};
2325

2426
extern crate alloc;
2527
mod bindings {
@@ -361,13 +363,11 @@ mod wit_test {
361363

362364
#[test]
363365
fn restore_rust_and_c_snapshots_replace_wit_guest() {
364-
let mut rust_source = UninitializedSandbox::new(
365-
GuestBinary::FilePath(simple_guest_as_pathbuf()),
366-
None,
367-
)
368-
.unwrap()
369-
.evolve()
370-
.unwrap();
366+
let mut rust_source =
367+
UninitializedSandbox::new(GuestBinary::FilePath(simple_guest_as_pathbuf()), None)
368+
.unwrap()
369+
.evolve()
370+
.unwrap();
371371
assert_eq!(rust_source.call::<i32>("AddToStatic", 42i32).unwrap(), 42);
372372
let rust_snapshot = rust_source.snapshot().unwrap();
373373

@@ -381,13 +381,11 @@ mod wit_test {
381381
rust_target.sb.restore(rust_snapshot).unwrap();
382382
assert_eq!(rust_target.sb.call::<i32>("GetStatic", ()).unwrap(), 42);
383383

384-
let mut c_source = UninitializedSandbox::new(
385-
GuestBinary::FilePath(c_simple_guest_as_pathbuf()),
386-
None,
387-
)
388-
.unwrap()
389-
.evolve()
390-
.unwrap();
384+
let mut c_source =
385+
UninitializedSandbox::new(GuestBinary::FilePath(c_simple_guest_as_pathbuf()), None)
386+
.unwrap()
387+
.evolve()
388+
.unwrap();
391389
assert_eq!(c_source.call::<i32>("StackAllocate", 256i32).unwrap(), 256);
392390
let c_snapshot = c_source.snapshot().unwrap();
393391

@@ -407,13 +405,11 @@ mod wit_test {
407405

408406
#[test]
409407
fn restore_chain_replaces_each_guest() {
410-
let mut rust_source = UninitializedSandbox::new(
411-
GuestBinary::FilePath(simple_guest_as_pathbuf()),
412-
None,
413-
)
414-
.unwrap()
415-
.evolve()
416-
.unwrap();
408+
let mut rust_source =
409+
UninitializedSandbox::new(GuestBinary::FilePath(simple_guest_as_pathbuf()), None)
410+
.unwrap()
411+
.evolve()
412+
.unwrap();
417413
assert_eq!(rust_source.call::<i32>("AddToStatic", 42i32).unwrap(), 42);
418414
let rust_snapshot = rust_source.snapshot().unwrap();
419415

0 commit comments

Comments
 (0)