Skip to content

Commit 8297af8

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

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
@@ -2271,13 +2271,11 @@ mod tests {
22712271
.unwrap()
22722272
.evolve()
22732273
.unwrap();
2274-
let mut target = UninitializedSandbox::new(
2275-
GuestBinary::FilePath(simple_guest_as_pathbuf()),
2276-
None,
2277-
)
2278-
.unwrap()
2279-
.evolve()
2280-
.unwrap();
2274+
let mut target =
2275+
UninitializedSandbox::new(GuestBinary::FilePath(simple_guest_as_pathbuf()), None)
2276+
.unwrap()
2277+
.evolve()
2278+
.unwrap();
22812279

22822280
assert_eq!(source.call::<i32>("StackAllocate", 256i32).unwrap(), 256);
22832281
assert_eq!(target.call::<i32>("AddToStatic", 17i32).unwrap(), 17);
@@ -2312,23 +2310,19 @@ mod tests {
23122310

23132311
#[test]
23142312
fn snapshot_restore_replaces_c_guest_with_rust_guest() {
2315-
let mut source = UninitializedSandbox::new(
2316-
GuestBinary::FilePath(simple_guest_as_pathbuf()),
2317-
None,
2318-
)
2319-
.unwrap()
2320-
.evolve()
2321-
.unwrap();
2313+
let mut source =
2314+
UninitializedSandbox::new(GuestBinary::FilePath(simple_guest_as_pathbuf()), None)
2315+
.unwrap()
2316+
.evolve()
2317+
.unwrap();
23222318
assert_eq!(source.call::<i32>("AddToStatic", 42i32).unwrap(), 42);
23232319
let snapshot = source.snapshot().unwrap();
23242320

2325-
let mut target = UninitializedSandbox::new(
2326-
GuestBinary::FilePath(c_simple_guest_as_pathbuf()),
2327-
None,
2328-
)
2329-
.unwrap()
2330-
.evolve()
2331-
.unwrap();
2321+
let mut target =
2322+
UninitializedSandbox::new(GuestBinary::FilePath(c_simple_guest_as_pathbuf()), None)
2323+
.unwrap()
2324+
.evolve()
2325+
.unwrap();
23322326
assert_eq!(target.call::<i32>("StackAllocate", 256i32).unwrap(), 256);
23332327

23342328
target.restore(snapshot).unwrap();
@@ -2344,33 +2338,27 @@ mod tests {
23442338

23452339
#[test]
23462340
fn snapshot_restore_alternates_c_and_rust_guests() {
2347-
let mut c_source = UninitializedSandbox::new(
2348-
GuestBinary::FilePath(c_simple_guest_as_pathbuf()),
2349-
None,
2350-
)
2351-
.unwrap()
2352-
.evolve()
2353-
.unwrap();
2341+
let mut c_source =
2342+
UninitializedSandbox::new(GuestBinary::FilePath(c_simple_guest_as_pathbuf()), None)
2343+
.unwrap()
2344+
.evolve()
2345+
.unwrap();
23542346
assert_eq!(c_source.call::<i32>("StackAllocate", 256i32).unwrap(), 256);
23552347
let c_snapshot = c_source.snapshot().unwrap();
23562348

2357-
let mut rust_source = UninitializedSandbox::new(
2358-
GuestBinary::FilePath(simple_guest_as_pathbuf()),
2359-
None,
2360-
)
2361-
.unwrap()
2362-
.evolve()
2363-
.unwrap();
2349+
let mut rust_source =
2350+
UninitializedSandbox::new(GuestBinary::FilePath(simple_guest_as_pathbuf()), None)
2351+
.unwrap()
2352+
.evolve()
2353+
.unwrap();
23642354
rust_source.call::<i32>("AddToStatic", 42i32).unwrap();
23652355
let rust_snapshot = rust_source.snapshot().unwrap();
23662356

2367-
let mut target = UninitializedSandbox::new(
2368-
GuestBinary::FilePath(c_simple_guest_as_pathbuf()),
2369-
None,
2370-
)
2371-
.unwrap()
2372-
.evolve()
2373-
.unwrap();
2357+
let mut target =
2358+
UninitializedSandbox::new(GuestBinary::FilePath(c_simple_guest_as_pathbuf()), None)
2359+
.unwrap()
2360+
.evolve()
2361+
.unwrap();
23742362
assert_eq!(target.call::<i32>("StackAllocate", 256i32).unwrap(), 256);
23752363

23762364
target.restore(rust_snapshot).unwrap();
@@ -2425,13 +2413,11 @@ mod tests {
24252413

24262414
#[test]
24272415
fn snapshot_restore_recovers_poison_with_different_guest() {
2428-
let mut source = UninitializedSandbox::new(
2429-
GuestBinary::FilePath(c_simple_guest_as_pathbuf()),
2430-
None,
2431-
)
2432-
.unwrap()
2433-
.evolve()
2434-
.unwrap();
2416+
let mut source =
2417+
UninitializedSandbox::new(GuestBinary::FilePath(c_simple_guest_as_pathbuf()), None)
2418+
.unwrap()
2419+
.evolve()
2420+
.unwrap();
24352421
let snapshot = source.snapshot().unwrap();
24362422

24372423
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
@@ -20,7 +20,9 @@ use std::sync::{Arc, Mutex};
2020
use hyperlight_common::component::{Negative, Positive};
2121
use hyperlight_common::resource::BorrowedResourceGuard;
2222
use hyperlight_host::{GuestBinary, MultiUseSandbox, UninitializedSandbox};
23-
use hyperlight_testing::{c_simple_guest_as_pathbuf, simple_guest_as_pathbuf, wit_guest_as_pathbuf};
23+
use hyperlight_testing::{
24+
c_simple_guest_as_pathbuf, simple_guest_as_pathbuf, wit_guest_as_pathbuf,
25+
};
2426

2527
extern crate alloc;
2628
mod bindings {
@@ -362,13 +364,11 @@ mod wit_test {
362364

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

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

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

@@ -408,13 +406,11 @@ mod wit_test {
408406

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

0 commit comments

Comments
 (0)