Skip to content

Commit a110461

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

3 files changed

Lines changed: 54 additions & 71 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: 35 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2267,13 +2267,11 @@ mod tests {
22672267
.unwrap()
22682268
.evolve()
22692269
.unwrap();
2270-
let mut target = UninitializedSandbox::new(
2271-
GuestBinary::FilePath(simple_guest_as_pathbuf()),
2272-
None,
2273-
)
2274-
.unwrap()
2275-
.evolve()
2276-
.unwrap();
2270+
let mut target =
2271+
UninitializedSandbox::new(GuestBinary::FilePath(simple_guest_as_pathbuf()), None)
2272+
.unwrap()
2273+
.evolve()
2274+
.unwrap();
22772275

22782276
assert_eq!(source.call::<i32>("StackAllocate", 256i32).unwrap(), 256);
22792277
assert_eq!(target.call::<i32>("AddToStatic", 17i32).unwrap(), 17);
@@ -2308,23 +2306,19 @@ mod tests {
23082306

23092307
#[test]
23102308
fn snapshot_restore_replaces_c_guest_with_rust_guest() {
2311-
let mut source = UninitializedSandbox::new(
2312-
GuestBinary::FilePath(simple_guest_as_pathbuf()),
2313-
None,
2314-
)
2315-
.unwrap()
2316-
.evolve()
2317-
.unwrap();
2309+
let mut source =
2310+
UninitializedSandbox::new(GuestBinary::FilePath(simple_guest_as_pathbuf()), None)
2311+
.unwrap()
2312+
.evolve()
2313+
.unwrap();
23182314
assert_eq!(source.call::<i32>("AddToStatic", 42i32).unwrap(), 42);
23192315
let snapshot = source.snapshot().unwrap();
23202316

2321-
let mut target = UninitializedSandbox::new(
2322-
GuestBinary::FilePath(c_simple_guest_as_pathbuf()),
2323-
None,
2324-
)
2325-
.unwrap()
2326-
.evolve()
2327-
.unwrap();
2317+
let mut target =
2318+
UninitializedSandbox::new(GuestBinary::FilePath(c_simple_guest_as_pathbuf()), None)
2319+
.unwrap()
2320+
.evolve()
2321+
.unwrap();
23282322
assert_eq!(target.call::<i32>("StackAllocate", 256i32).unwrap(), 256);
23292323

23302324
target.restore(snapshot).unwrap();
@@ -2340,33 +2334,27 @@ mod tests {
23402334

23412335
#[test]
23422336
fn snapshot_restore_alternates_c_and_rust_guests() {
2343-
let mut c_source = UninitializedSandbox::new(
2344-
GuestBinary::FilePath(c_simple_guest_as_pathbuf()),
2345-
None,
2346-
)
2347-
.unwrap()
2348-
.evolve()
2349-
.unwrap();
2337+
let mut c_source =
2338+
UninitializedSandbox::new(GuestBinary::FilePath(c_simple_guest_as_pathbuf()), None)
2339+
.unwrap()
2340+
.evolve()
2341+
.unwrap();
23502342
assert_eq!(c_source.call::<i32>("StackAllocate", 256i32).unwrap(), 256);
23512343
let c_snapshot = c_source.snapshot().unwrap();
23522344

2353-
let mut rust_source = UninitializedSandbox::new(
2354-
GuestBinary::FilePath(simple_guest_as_pathbuf()),
2355-
None,
2356-
)
2357-
.unwrap()
2358-
.evolve()
2359-
.unwrap();
2345+
let mut rust_source =
2346+
UninitializedSandbox::new(GuestBinary::FilePath(simple_guest_as_pathbuf()), None)
2347+
.unwrap()
2348+
.evolve()
2349+
.unwrap();
23602350
rust_source.call::<i32>("AddToStatic", 42i32).unwrap();
23612351
let rust_snapshot = rust_source.snapshot().unwrap();
23622352

2363-
let mut target = UninitializedSandbox::new(
2364-
GuestBinary::FilePath(c_simple_guest_as_pathbuf()),
2365-
None,
2366-
)
2367-
.unwrap()
2368-
.evolve()
2369-
.unwrap();
2353+
let mut target =
2354+
UninitializedSandbox::new(GuestBinary::FilePath(c_simple_guest_as_pathbuf()), None)
2355+
.unwrap()
2356+
.evolve()
2357+
.unwrap();
23702358
assert_eq!(target.call::<i32>("StackAllocate", 256i32).unwrap(), 256);
23712359

23722360
target.restore(rust_snapshot).unwrap();
@@ -2421,13 +2409,11 @@ mod tests {
24212409

24222410
#[test]
24232411
fn snapshot_restore_recovers_poison_with_different_guest() {
2424-
let mut source = UninitializedSandbox::new(
2425-
GuestBinary::FilePath(c_simple_guest_as_pathbuf()),
2426-
None,
2427-
)
2428-
.unwrap()
2429-
.evolve()
2430-
.unwrap();
2412+
let mut source =
2413+
UninitializedSandbox::new(GuestBinary::FilePath(c_simple_guest_as_pathbuf()), None)
2414+
.unwrap()
2415+
.evolve()
2416+
.unwrap();
24312417
let snapshot = source.snapshot().unwrap();
24322418

24332419
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)