Skip to content

Commit fc66057

Browse files
jprendesCopilot
andcommitted
Move Sandbox into a private initialized module
The initialized module holds the initialized sandbox type. Sandbox, SandboxStatus and PtRootFinder are reached through hyperlight_host::Sandbox or hyperlight_host::sandbox. The module is private because every public item in it is already re-exported one level up. sandbox::initialized_multi_use stays as a deprecated facade so existing callers keep compiling. Keeping the type in a deprecated module is not an option. Module deprecation is inherited by the items defined inside it and follows them through re-exports, which would warn on every use of the canonical hyperlight_host::Sandbox path. The log tracing test pointed at sandbox/initialized.rs, a file that did not exist, so it took the "not found" path instead of testing an invalid binary as intended. It now reads the crate manifest, which always exists and is never a valid guest binary. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
1 parent 44463a9 commit fc66057

6 files changed

Lines changed: 31 additions & 26 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
1616
### Changed
1717
* `Sandbox` is the primary initialized sandbox type. `MultiUseSandbox` remains
1818
as a deprecated alias.
19+
* `Sandbox` lives in the private `sandbox::initialized` module and is reached
20+
through `hyperlight_host::Sandbox` or `hyperlight_host::sandbox::Sandbox`.
21+
`sandbox::initialized_multi_use` remains as a deprecated public path.
1922
* Support overriding the guest log level when building or restoring initialized
2023
snapshots.
2124
* `Snapshot::save` now writes the guest memory blob sparsely, skipping all-zero

‎Justfile‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -263,18 +263,18 @@ test-loom:
263263
test-isolated target=default-target features="" :
264264
{{ cargo-cmd }} test {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} {{ target-triple-flag }} -p hyperlight-host --lib -- sandbox::uninitialized::tests::test_log_trace --exact --ignored
265265
{{ cargo-cmd }} test {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} {{ target-triple-flag }} -p hyperlight-host --lib -- sandbox::outb::tests::test_log_emit_guest_log --exact --ignored
266-
{{ cargo-cmd }} test {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} {{ target-triple-flag }} -p hyperlight-host --lib -- sandbox::initialized_multi_use::tests::from_snapshot::max_guest_log_level_is_honored_from_snapshot --exact --ignored
267-
{{ cargo-cmd }} test {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} {{ target-triple-flag }} -p hyperlight-host --lib -- sandbox::initialized_multi_use::tests::from_snapshot::max_guest_log_level_overrides_initialized_snapshot --exact --ignored
268-
{{ cargo-cmd }} test {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} {{ target-triple-flag }} -p hyperlight-host --lib -- sandbox::initialized_multi_use::tests::from_snapshot::max_guest_log_level_setter_survives_restore --exact --ignored
269-
{{ cargo-cmd }} test {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} {{ target-triple-flag }} -p hyperlight-host --lib -- sandbox::initialized_multi_use::tests::from_snapshot::max_guest_log_level_can_be_disabled_and_reenabled --exact --ignored
270-
{{ cargo-cmd }} test {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} {{ target-triple-flag }} -p hyperlight-host --lib -- sandbox::initialized_multi_use::tests::from_snapshot::max_guest_log_level_can_be_enabled_after_off_init --exact --ignored
266+
{{ cargo-cmd }} test {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} {{ target-triple-flag }} -p hyperlight-host --lib -- sandbox::initialized::tests::from_snapshot::max_guest_log_level_is_honored_from_snapshot --exact --ignored
267+
{{ cargo-cmd }} test {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} {{ target-triple-flag }} -p hyperlight-host --lib -- sandbox::initialized::tests::from_snapshot::max_guest_log_level_overrides_initialized_snapshot --exact --ignored
268+
{{ cargo-cmd }} test {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} {{ target-triple-flag }} -p hyperlight-host --lib -- sandbox::initialized::tests::from_snapshot::max_guest_log_level_setter_survives_restore --exact --ignored
269+
{{ cargo-cmd }} test {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} {{ target-triple-flag }} -p hyperlight-host --lib -- sandbox::initialized::tests::from_snapshot::max_guest_log_level_can_be_disabled_and_reenabled --exact --ignored
270+
{{ cargo-cmd }} test {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} {{ target-triple-flag }} -p hyperlight-host --lib -- sandbox::initialized::tests::from_snapshot::max_guest_log_level_can_be_enabled_after_off_init --exact --ignored
271271
{{ cargo-cmd }} test {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} {{ target-triple-flag }} -p hyperlight-host --test integration_test -- log_message --exact --ignored
272272
@# CPU vendor check, gated to known CI runner hardware
273273
{{ cargo-cmd }} test {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} {{ target-triple-flag }} -p hyperlight-host --lib -- sandbox::snapshot::file::config::tests::cpu_vendor_current_is_recognized --exact --ignored
274274
@# Slow host-dependent MSR audit. Run once per x86_64 CI profile.
275-
{{ if features == "" { if hyperlight-target-arch == "x86_64" { cargo-cmd + " test --profile=" + (if target == "debug" { "dev" } else { target }) + " " + target-triple-flag + " -p hyperlight-host --lib -- sandbox::initialized_multi_use::tests::msr_tests::test_no_msr_leaks_across_restore_full_window_sweep --exact --ignored --nocapture" } else { "" } } else { "" } }}
275+
{{ if features == "" { if hyperlight-target-arch == "x86_64" { cargo-cmd + " test --profile=" + (if target == "debug" { "dev" } else { target }) + " " + target-triple-flag + " -p hyperlight-host --lib -- sandbox::initialized::tests::msr_tests::test_no_msr_leaks_across_restore_full_window_sweep --exact --ignored --nocapture" } else { "" } } else { "" } }}
276276
@# LAPIC-enabled MSHV can expose additional MSRs. Audit it once in debug.
277-
{{ if features == "mshv3,hw-interrupts" { if target == "debug" { if hyperlight-target-arch == "x86_64" { cargo-cmd + " test --no-default-features -F mshv3,hw-interrupts --profile=dev " + target-triple-flag + " -p hyperlight-host --lib -- sandbox::initialized_multi_use::tests::msr_tests::test_no_msr_leaks_across_restore_full_window_sweep --exact --ignored --nocapture" } else { "" } } else { "" } } else { "" } }}
277+
{{ if features == "mshv3,hw-interrupts" { if target == "debug" { if hyperlight-target-arch == "x86_64" { cargo-cmd + " test --no-default-features -F mshv3,hw-interrupts --profile=dev " + target-triple-flag + " -p hyperlight-host --lib -- sandbox::initialized::tests::msr_tests::test_no_msr_leaks_across_restore_full_window_sweep --exact --ignored --nocapture" } else { "" } } else { "" } } else { "" } }}
278278
@# metrics tests
279279
{{ cargo-cmd }} test {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F function_call_metrics," + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} {{ target-triple-flag }} -p hyperlight-host --lib -- metrics::tests::test_metrics_are_emitted --exact
280280

@@ -551,11 +551,11 @@ coverage-run hypervisor="kvm": ensure-cargo-llvm-cov
551551
# isolated tests (require running separately due to global state)
552552
cargo +{{nightly-toolchain}} test -p hyperlight-host --lib -- sandbox::uninitialized::tests::test_log_trace --exact --ignored
553553
cargo +{{nightly-toolchain}} test -p hyperlight-host --lib -- sandbox::outb::tests::test_log_emit_guest_log --exact --ignored
554-
cargo +{{nightly-toolchain}} test -p hyperlight-host --lib -- sandbox::initialized_multi_use::tests::from_snapshot::max_guest_log_level_is_honored_from_snapshot --exact --ignored
555-
cargo +{{nightly-toolchain}} test -p hyperlight-host --lib -- sandbox::initialized_multi_use::tests::from_snapshot::max_guest_log_level_overrides_initialized_snapshot --exact --ignored
556-
cargo +{{nightly-toolchain}} test -p hyperlight-host --lib -- sandbox::initialized_multi_use::tests::from_snapshot::max_guest_log_level_setter_survives_restore --exact --ignored
557-
cargo +{{nightly-toolchain}} test -p hyperlight-host --lib -- sandbox::initialized_multi_use::tests::from_snapshot::max_guest_log_level_can_be_disabled_and_reenabled --exact --ignored
558-
cargo +{{nightly-toolchain}} test -p hyperlight-host --lib -- sandbox::initialized_multi_use::tests::from_snapshot::max_guest_log_level_can_be_enabled_after_off_init --exact --ignored
554+
cargo +{{nightly-toolchain}} test -p hyperlight-host --lib -- sandbox::initialized::tests::from_snapshot::max_guest_log_level_is_honored_from_snapshot --exact --ignored
555+
cargo +{{nightly-toolchain}} test -p hyperlight-host --lib -- sandbox::initialized::tests::from_snapshot::max_guest_log_level_overrides_initialized_snapshot --exact --ignored
556+
cargo +{{nightly-toolchain}} test -p hyperlight-host --lib -- sandbox::initialized::tests::from_snapshot::max_guest_log_level_setter_survives_restore --exact --ignored
557+
cargo +{{nightly-toolchain}} test -p hyperlight-host --lib -- sandbox::initialized::tests::from_snapshot::max_guest_log_level_can_be_disabled_and_reenabled --exact --ignored
558+
cargo +{{nightly-toolchain}} test -p hyperlight-host --lib -- sandbox::initialized::tests::from_snapshot::max_guest_log_level_can_be_enabled_after_off_init --exact --ignored
559559
cargo +{{nightly-toolchain}} test -p hyperlight-host --test integration_test -- log_message --exact --ignored
560560
cargo +{{nightly-toolchain}} test -p hyperlight-host --no-default-features -F function_call_metrics,{{ if hypervisor == "mshv3" { "mshv3" } else { "kvm" } }} --lib -- metrics::tests::test_metrics_are_emitted --exact
561561

‎src/hyperlight_component_util/src/host.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ fn emit_component<'a, 'b, 'c>(s: &'c mut State<'a, 'b>, wn: WitName, ct: &'c Com
408408
#(#exports)*
409409
}
410410
impl #ns::#r#trait<::hyperlight_common::component::Positive> for ::hyperlight_host::sandbox::UninitializedSandbox {
411-
type Exports<I: #ns::#import_trait<::hyperlight_common::component::Negative> + ::std::marker::Send> = #wrapper_name<I, ::hyperlight_host::sandbox::initialized_multi_use::Sandbox>;
411+
type Exports<I: #ns::#import_trait<::hyperlight_common::component::Negative> + ::std::marker::Send> = #wrapper_name<I, ::hyperlight_host::sandbox::Sandbox>;
412412
fn instantiate<I: #ns::#import_trait<::hyperlight_common::component::Negative> + ::std::marker::Send + 'static>(mut self, i: I) -> <::hyperlight_common::component::Positive as ::hyperlight_common::component::Positivity>::CallResult<Self::Exports<I>> {
413413
let rts = register_host_functions(&mut self, i)?;
414414
let sb = self.evolve()?;
File renamed without changes.

‎src/hyperlight_host/src/sandbox/mod.rs‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@ pub(crate) mod file_mapping;
1111
pub(crate) mod host_funcs;
1212
/// Functionality for dealing with initialized sandboxes that can
1313
/// call 0 or more guest functions
14-
pub mod initialized_multi_use;
14+
mod initialized;
15+
/// Deprecated path for the items in the `initialized` module.
16+
#[deprecated(since = "0.17.0", note = "use hyperlight_host::sandbox")]
17+
pub mod initialized_multi_use {
18+
#[allow(deprecated)]
19+
pub use super::initialized::MultiUseSandbox;
20+
pub use super::initialized::{PtRootFinder, Sandbox, SandboxStatus};
21+
}
1522
pub(crate) mod outb;
1623
/// Functionality for creating uninitialized sandboxes, manipulating them,
1724
/// and converting them to initialized sandboxes.
@@ -36,9 +43,9 @@ pub use callable::Callable;
3643
pub use config::SandboxConfiguration;
3744
/// Re-export for the deprecated `MultiUseSandbox` name
3845
#[allow(deprecated)]
39-
pub use initialized_multi_use::MultiUseSandbox;
46+
pub use initialized::MultiUseSandbox;
4047
/// Re-export for the `Sandbox` type
41-
pub use initialized_multi_use::{PtRootFinder, Sandbox, SandboxStatus};
48+
pub use initialized::{PtRootFinder, Sandbox, SandboxStatus};
4249
/// Re-export for `GuestBinary` type
4350
pub use uninitialized::GuestBinary;
4451
/// Re-export for `UninitializedSandbox` type

‎src/hyperlight_host/src/sandbox/uninitialized.rs‎

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,12 +1051,11 @@ mod tests {
10511051
TEST_LOGGER.clear_log_calls();
10521052
TEST_LOGGER.set_max_level(log::LevelFilter::Info);
10531053

1054-
let mut valid_binary_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
1055-
valid_binary_path.push("src");
1056-
valid_binary_path.push("sandbox");
1057-
valid_binary_path.push("initialized.rs");
1054+
// An existing file that is never a valid guest binary.
1055+
let mut invalid_binary_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
1056+
invalid_binary_path.push("Cargo.toml");
10581057

1059-
let sbox = UninitializedSandbox::new(GuestBinary::FilePath(valid_binary_path), None);
1058+
let sbox = UninitializedSandbox::new(GuestBinary::FilePath(invalid_binary_path), None);
10601059
assert!(sbox.is_err());
10611060

10621061
// There should be 2 calls this time when we change to the log
@@ -1076,11 +1075,7 @@ mod tests {
10761075

10771076
let logcall = TEST_LOGGER.get_log_call(1).unwrap();
10781077
assert_eq!(Level::Error, logcall.level);
1079-
assert!(
1080-
logcall
1081-
.args
1082-
.starts_with("error=Error(\"GuestBinary not found:")
1083-
);
1078+
assert!(logcall.args.starts_with("error=PEFileProcessingFailure"));
10841079
assert_eq!("hyperlight_host::sandbox::uninitialized", logcall.target);
10851080
}
10861081
{

0 commit comments

Comments
 (0)