Skip to content

Rename MultiUseSandbox -> Sandbox, UninitializedSandbox::evolve -> UninitializedSandbox::init #762

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ It is followed by an example of a simple guest application using the Hyperlight
```rust
use std::thread;

use hyperlight_host::{MultiUseSandbox, UninitializedSandbox};
use hyperlight_host::{Sandbox, UninitializedSandbox};

fn main() -> hyperlight_host::Result<()> {
// Create an uninitialized sandbox with a guest binary
Expand All @@ -52,7 +52,7 @@ fn main() -> hyperlight_host::Result<()> {
// Note: This function is unused by the guest code below, it's just here for demonstration purposes

// Initialize sandbox to be able to call host functions
let mut multi_use_sandbox: MultiUseSandbox = uninitialized_sandbox.evolve()?;
let mut multi_use_sandbox = uninitialized_sandbox.init()?;

// Call a function in the guest
let message = "Hello, World! I am executing inside of a VM :)\n".to_string();
Expand Down
6 changes: 3 additions & 3 deletions fuzz/fuzz_targets/guest_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ use std::sync::{Mutex, OnceLock};

use hyperlight_host::func::{ParameterValue, ReturnType};
use hyperlight_host::sandbox::uninitialized::GuestBinary;
use hyperlight_host::{MultiUseSandbox, UninitializedSandbox};
use hyperlight_host::{Sandbox, UninitializedSandbox};
use hyperlight_testing::simple_guest_for_fuzzing_as_string;
use libfuzzer_sys::fuzz_target;
static SANDBOX: OnceLock<Mutex<MultiUseSandbox>> = OnceLock::new();
static SANDBOX: OnceLock<Mutex<Sandbox>> = OnceLock::new();

// This fuzz target tests all combinations of ReturnType and Parameters for `call_guest_function_by_name`.
// For fuzzing efficiency, we create one Sandbox and reuse it for all fuzzing iterations.
Expand All @@ -36,7 +36,7 @@ fuzz_target!(
)
.unwrap();

let mu_sbox: MultiUseSandbox = u_sbox.evolve().unwrap();
let mu_sbox: Sandbox = u_sbox.init().unwrap();
SANDBOX.set(Mutex::new(mu_sbox)).unwrap();
},

Expand Down
6 changes: 3 additions & 3 deletions fuzz/fuzz_targets/host_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ use std::sync::{Mutex, OnceLock};

use hyperlight_host::func::{ParameterValue, ReturnType};
use hyperlight_host::sandbox::uninitialized::GuestBinary;
use hyperlight_host::{HyperlightError, MultiUseSandbox, UninitializedSandbox};
use hyperlight_host::{HyperlightError, Sandbox, UninitializedSandbox};
use hyperlight_testing::simple_guest_for_fuzzing_as_string;
use libfuzzer_sys::fuzz_target;
static SANDBOX: OnceLock<Mutex<MultiUseSandbox>> = OnceLock::new();
static SANDBOX: OnceLock<Mutex<Sandbox>> = OnceLock::new();

// This fuzz target tests all combinations of ReturnType and Parameters for `call_guest_function_by_name`.
// For fuzzing efficiency, we create one Sandbox and reuse it for all fuzzing iterations.
Expand All @@ -35,7 +35,7 @@ fuzz_target!(
)
.unwrap();

let mu_sbox: MultiUseSandbox = u_sbox.evolve().unwrap();
let mu_sbox: Sandbox = u_sbox.init().unwrap();
SANDBOX.set(Mutex::new(mu_sbox)).unwrap();
},

Expand Down
6 changes: 3 additions & 3 deletions fuzz/fuzz_targets/host_print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
use std::sync::{Mutex, OnceLock};

use hyperlight_host::sandbox::uninitialized::GuestBinary;
use hyperlight_host::{MultiUseSandbox, UninitializedSandbox};
use hyperlight_host::{Sandbox, UninitializedSandbox};
use hyperlight_testing::simple_guest_for_fuzzing_as_string;
use libfuzzer_sys::{Corpus, fuzz_target};

static SANDBOX: OnceLock<Mutex<MultiUseSandbox>> = OnceLock::new();
static SANDBOX: OnceLock<Mutex<Sandbox>> = OnceLock::new();

// This fuzz target is used to test the HostPrint host function. We generate
// an arbitrary ParameterValue::String, which is passed to the guest, which passes
Expand All @@ -21,7 +21,7 @@ fuzz_target!(
)
.unwrap();

let mu_sbox: MultiUseSandbox = u_sbox.evolve().unwrap();
let mu_sbox: Sandbox = u_sbox.init().unwrap();
SANDBOX.set(Mutex::new(mu_sbox)).unwrap();
},

Expand Down
4 changes: 2 additions & 2 deletions src/hyperlight_component_util/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,10 +356,10 @@ fn emit_component<'a, 'b, 'c>(s: &'c mut State<'a, 'b>, wn: WitName, ct: &'c Com
#(#exports)*
}
impl #ns::#r#trait for ::hyperlight_host::sandbox::UninitializedSandbox {
type Exports<I: #ns::#import_trait + ::std::marker::Send> = #wrapper_name<I, ::hyperlight_host::sandbox::initialized_multi_use::MultiUseSandbox>;
type Exports<I: #ns::#import_trait + ::std::marker::Send> = #wrapper_name<I, ::hyperlight_host::sandbox::sandbox::Sandbox>;
fn instantiate<I: #ns::#import_trait + ::std::marker::Send + 'static>(mut self, i: I) -> Self::Exports<I> {
let rts = register_host_functions(&mut self, i);
let sb = self.evolve().unwrap();
let sb = self.init().unwrap();
#wrapper_name {
sb,
rt: rts,
Expand Down
12 changes: 5 additions & 7 deletions src/hyperlight_host/benches/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,16 @@ limitations under the License.

use criterion::{Criterion, criterion_group, criterion_main};
use hyperlight_host::GuestBinary;
use hyperlight_host::sandbox::{
Callable, MultiUseSandbox, SandboxConfiguration, UninitializedSandbox,
};
use hyperlight_host::sandbox::{Callable, Sandbox, SandboxConfiguration, UninitializedSandbox};
use hyperlight_testing::simple_guest_as_string;

fn create_uninit_sandbox() -> UninitializedSandbox {
let path = simple_guest_as_string().unwrap();
UninitializedSandbox::new(GuestBinary::FilePath(path), None).unwrap()
}

fn create_multiuse_sandbox() -> MultiUseSandbox {
create_uninit_sandbox().evolve().unwrap()
fn create_multiuse_sandbox() -> Sandbox {
create_uninit_sandbox().init().unwrap()
}

fn guest_call_benchmark(c: &mut Criterion) {
Expand Down Expand Up @@ -63,7 +61,7 @@ fn guest_call_benchmark(c: &mut Criterion) {
.register("HostAdd", |a: i32, b: i32| Ok(a + b))
.unwrap();

let mut multiuse_sandbox: MultiUseSandbox = uninitialized_sandbox.evolve().unwrap();
let mut multiuse_sandbox: Sandbox = uninitialized_sandbox.init().unwrap();

b.iter(|| {
multiuse_sandbox
Expand Down Expand Up @@ -95,7 +93,7 @@ fn guest_call_benchmark_large_param(c: &mut Criterion) {
Some(config),
)
.unwrap();
let mut sandbox = sandbox.evolve().unwrap();
let mut sandbox = sandbox.init().unwrap();

b.iter(|| {
sandbox
Expand Down
4 changes: 2 additions & 2 deletions src/hyperlight_host/examples/func_ctx/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ use hyperlight_host::sandbox::UninitializedSandbox;
use hyperlight_testing::simple_guest_as_string;

fn main() {
// create a new `MultiUseSandbox` configured to run the `simpleguest.exe`
// create a new `Sandbox` configured to run the `simpleguest.exe`
// test guest binary
let path = simple_guest_as_string().unwrap();
let mut sbox = UninitializedSandbox::new(GuestBinary::FilePath(path), None)
.unwrap()
.evolve()
.init()
.unwrap();

// Do several calls against a sandbox running the `simpleguest.exe` binary,
Expand Down
6 changes: 3 additions & 3 deletions src/hyperlight_host/examples/guest-debugging/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use std::thread;
use hyperlight_host::sandbox::SandboxConfiguration;
#[cfg(gdb)]
use hyperlight_host::sandbox::config::DebugInfo;
use hyperlight_host::{MultiUseSandbox, UninitializedSandbox};
use hyperlight_host::{Sandbox, UninitializedSandbox};

/// Build a sandbox configuration that enables GDB debugging when the `gdb` feature is enabled.
fn get_sandbox_cfg() -> Option<SandboxConfiguration> {
Expand Down Expand Up @@ -68,8 +68,8 @@ fn main() -> hyperlight_host::Result<()> {
// Note: This function is unused, it's just here for demonstration purposes

// Initialize sandboxes to be able to call host functions
let mut multi_use_sandbox_dbg: MultiUseSandbox = uninitialized_sandbox_dbg.evolve()?;
let mut multi_use_sandbox: MultiUseSandbox = uninitialized_sandbox.evolve()?;
let mut multi_use_sandbox_dbg: Sandbox = uninitialized_sandbox_dbg.init()?;
let mut multi_use_sandbox: Sandbox = uninitialized_sandbox.init()?;

// Call guest function
let message =
Expand Down
4 changes: 2 additions & 2 deletions src/hyperlight_host/examples/hello-world/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ limitations under the License.
#![allow(clippy::disallowed_macros)]
use std::thread;

use hyperlight_host::{MultiUseSandbox, UninitializedSandbox};
use hyperlight_host::{Sandbox, UninitializedSandbox};

fn main() -> hyperlight_host::Result<()> {
// Create an uninitialized sandbox with a guest binary
Expand All @@ -35,7 +35,7 @@ fn main() -> hyperlight_host::Result<()> {
// Note: This function is unused, it's just here for demonstration purposes

// Initialize sandbox to be able to call host functions
let mut multi_use_sandbox: MultiUseSandbox = uninitialized_sandbox.evolve()?;
let mut multi_use_sandbox: Sandbox = uninitialized_sandbox.init()?;

// Call guest function
let message = "Hello, World! I am executing inside of a VM :)\n".to_string();
Expand Down
4 changes: 2 additions & 2 deletions src/hyperlight_host/examples/logging/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn main() -> Result<()> {
usandbox.register_print(fn_writer)?;

// Initialize the sandbox.
let mut multiuse_sandbox = usandbox.evolve()?;
let mut multiuse_sandbox = usandbox.init()?;

// Call a guest function 5 times to generate some log entries.
for _ in 0..5 {
Expand Down Expand Up @@ -75,7 +75,7 @@ fn main() -> Result<()> {
UninitializedSandbox::new(GuestBinary::FilePath(hyperlight_guest_path.clone()), None)?;

// Initialize the sandbox.
let mut multiuse_sandbox = usandbox.evolve()?;
let mut multiuse_sandbox = usandbox.init()?;
let interrupt_handle = multiuse_sandbox.interrupt_handle();
let barrier = Arc::new(Barrier::new(2));
let barrier2 = barrier.clone();
Expand Down
4 changes: 2 additions & 2 deletions src/hyperlight_host/examples/metrics/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fn do_hyperlight_stuff() {
usandbox.register_print(fn_writer)?;

// Initialize the sandbox.
let mut multiuse_sandbox = usandbox.evolve().expect("Failed to evolve sandbox");
let mut multiuse_sandbox = usandbox.init().expect("Failed to init sandbox");

// Call a guest function 5 times to generate some metrics.
for _ in 0..5 {
Expand Down Expand Up @@ -87,7 +87,7 @@ fn do_hyperlight_stuff() {
.expect("Failed to create UninitializedSandbox");

// Initialize the sandbox.
let mut multiuse_sandbox = usandbox.evolve().expect("Failed to evolve sandbox");
let mut multiuse_sandbox = usandbox.init().expect("Failed to init sandbox");
let interrupt_handle = multiuse_sandbox.interrupt_handle();

const NUM_CALLS: i32 = 5;
Expand Down
2 changes: 1 addition & 1 deletion src/hyperlight_host/examples/tracing-chrome/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn main() -> Result<()> {
// Create a new sandbox.
let usandbox = UninitializedSandbox::new(GuestBinary::FilePath(simple_guest_path), None)?;

let mut sbox = usandbox.evolve().unwrap();
let mut sbox = usandbox.init().unwrap();

// do the function call
let current_time = std::time::Instant::now();
Expand Down
2 changes: 1 addition & 1 deletion src/hyperlight_host/examples/tracing-otlp/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ fn run_example(wait_input: bool) -> HyperlightResult<()> {
usandbox.register_print(fn_writer)?;

// Initialize the sandbox.
let mut multiuse_sandbox = usandbox.evolve()?;
let mut multiuse_sandbox = usandbox.init()?;

// Call a guest function 5 times to generate some log entries.
for _ in 0..5 {
Expand Down
2 changes: 1 addition & 1 deletion src/hyperlight_host/examples/tracing-tracy/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn main() -> Result<()> {
// Create a new sandbox.
let usandbox = UninitializedSandbox::new(GuestBinary::FilePath(simple_guest_path), None)?;

let mut sbox = usandbox.evolve().unwrap();
let mut sbox = usandbox.init().unwrap();

// do the function call
let current_time = std::time::Instant::now();
Expand Down
4 changes: 2 additions & 2 deletions src/hyperlight_host/examples/tracing/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ fn run_example() -> Result<()> {
usandbox.register_print(fn_writer)?;

// Initialize the sandbox.
let mut multiuse_sandbox = usandbox.evolve()?;
let mut multiuse_sandbox = usandbox.init()?;

// Call a guest function 5 times to generate some log entries.
for _ in 0..5 {
Expand Down Expand Up @@ -102,7 +102,7 @@ fn run_example() -> Result<()> {
UninitializedSandbox::new(GuestBinary::FilePath(hyperlight_guest_path.clone()), None)?;

// Initialize the sandbox.
let mut multiuse_sandbox = usandbox.evolve()?;
let mut multiuse_sandbox = usandbox.init()?;
let interrupt_handle = multiuse_sandbox.interrupt_handle();

// Call a function that gets cancelled by the host function 5 times to generate some log entries.
Expand Down
2 changes: 1 addition & 1 deletion src/hyperlight_host/src/hypervisor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ pub(crate) mod tests {
use crate::sandbox::uninitialized::GuestBinary;
#[cfg(any(crashdump, gdb))]
use crate::sandbox::uninitialized::SandboxRuntimeConfig;
use crate::sandbox::uninitialized_evolve::set_up_hypervisor_partition;
use crate::sandbox::uninitialized_init::set_up_hypervisor_partition;
use crate::sandbox::{SandboxConfiguration, UninitializedSandbox};
use crate::{Result, is_hypervisor_present, new_error};

Expand Down
4 changes: 2 additions & 2 deletions src/hyperlight_host/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ limitations under the License.
//! and host-guest communication.
//!
//! The primary entry points are [`UninitializedSandbox`] for initial setup and
//! [`MultiUseSandbox`] for executing guest functions.
//! [`Sandbox`] for executing guest functions.
//!
//! ## Guest Requirements
//!
Expand Down Expand Up @@ -92,7 +92,7 @@ pub use error::HyperlightError;
/// Re-export for `MemMgrWrapper` type
/// A sandbox that can call be used to make multiple calls to guest functions,
/// and otherwise reused multiple times
pub use sandbox::MultiUseSandbox;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can take this chance to remove these reexports? I'm not sure there is a reason to keep these?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opened #765 to see what we want to expose as our public API

pub use sandbox::Sandbox;
/// The re-export for the `UninitializedSandbox` type
pub use sandbox::UninitializedSandbox;
/// The re-export for the `is_hypervisor_present` type
Expand Down
2 changes: 1 addition & 1 deletion src/hyperlight_host/src/metrics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ mod tests {
)
.unwrap();

let mut multi = uninit.evolve().unwrap();
let mut multi = uninit.init().unwrap();
let interrupt_handle = multi.interrupt_handle();

// interrupt the guest function call to "Spin" after 1 second
Expand Down
19 changes: 10 additions & 9 deletions src/hyperlight_host/src/sandbox/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,23 @@ pub mod config;
pub(crate) mod host_funcs;
/// Functionality for dealing with `Sandbox`es that contain Hypervisors
pub(crate) mod hypervisor;
/// Functionality for dealing with initialized sandboxes that can
/// call 0 or more guest functions
pub mod initialized_multi_use;
/// Functionality for dealing with memory access from the VM guest
/// executable
pub(crate) mod mem_access;
/// Functionality for interacting with a sandbox's internally-stored
/// `SandboxMemoryManager`
pub(crate) mod mem_mgr;
pub(crate) mod outb;
/// Functionality for dealing with initialized sandboxes that can
/// call 0 or more guest functions
#[allow(clippy::module_inception)]
pub mod sandbox;
/// Functionality for creating uninitialized sandboxes, manipulating them,
/// and converting them to initialized sandboxes.
pub mod uninitialized;
/// Functionality for properly converting `UninitializedSandbox`es to
/// initialized `Sandbox`es.
pub(crate) mod uninitialized_evolve;
pub(crate) mod uninitialized_init;

/// Representation of a snapshot of a `Sandbox`.
pub mod snapshot;
Expand All @@ -54,8 +55,8 @@ pub use callable::Callable;
pub use config::SandboxConfiguration;
#[cfg(feature = "unwind_guest")]
use framehop::Unwinder;
/// Re-export for the `MultiUseSandbox` type
pub use initialized_multi_use::MultiUseSandbox;
/// Re-export for the `Sandbox` type
pub use sandbox::Sandbox;
use tracing::{Span, instrument};
/// Re-export for `GuestBinary` type
pub use uninitialized::GuestBinary;
Expand Down Expand Up @@ -245,7 +246,7 @@ mod tests {
use hyperlight_testing::simple_guest_as_string;

use crate::sandbox::uninitialized::GuestBinary;
use crate::{MultiUseSandbox, UninitializedSandbox, new_error};
use crate::{Sandbox, UninitializedSandbox, new_error};

#[test]
// TODO: add support for testing on WHP
Expand All @@ -269,7 +270,7 @@ mod tests {
#[test]
fn check_create_and_use_sandbox_on_different_threads() {
let unintializedsandbox_queue = Arc::new(ArrayQueue::<UninitializedSandbox>::new(10));
let sandbox_queue = Arc::new(ArrayQueue::<MultiUseSandbox>::new(10));
let sandbox_queue = Arc::new(ArrayQueue::<Sandbox>::new(10));

for i in 0..10 {
let simple_guest_path = simple_guest_as_string().expect("Guest Binary Missing");
Expand Down Expand Up @@ -305,7 +306,7 @@ mod tests {
))
.unwrap();

let sandbox = uninitialized_sandbox.evolve().unwrap_or_else(|_| {
let sandbox = uninitialized_sandbox.init().unwrap_or_else(|_| {
panic!("Failed to initialize UninitializedSandbox thread {}", i)
});

Expand Down
Loading
Loading