diff --git a/README.md b/README.md index 87bcda114..9bae75920 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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(); diff --git a/fuzz/fuzz_targets/guest_call.rs b/fuzz/fuzz_targets/guest_call.rs index bc0ff163f..1634669d4 100644 --- a/fuzz/fuzz_targets/guest_call.rs +++ b/fuzz/fuzz_targets/guest_call.rs @@ -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> = OnceLock::new(); +static SANDBOX: OnceLock> = 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. @@ -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(); }, diff --git a/fuzz/fuzz_targets/host_call.rs b/fuzz/fuzz_targets/host_call.rs index 5c72a98e5..252ead062 100644 --- a/fuzz/fuzz_targets/host_call.rs +++ b/fuzz/fuzz_targets/host_call.rs @@ -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> = OnceLock::new(); +static SANDBOX: OnceLock> = 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. @@ -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(); }, diff --git a/fuzz/fuzz_targets/host_print.rs b/fuzz/fuzz_targets/host_print.rs index c9c889e9e..67a3f311c 100644 --- a/fuzz/fuzz_targets/host_print.rs +++ b/fuzz/fuzz_targets/host_print.rs @@ -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> = OnceLock::new(); +static SANDBOX: OnceLock> = 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 @@ -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(); }, diff --git a/src/hyperlight_component_util/src/host.rs b/src/hyperlight_component_util/src/host.rs index b8a194dd2..22199b1e3 100644 --- a/src/hyperlight_component_util/src/host.rs +++ b/src/hyperlight_component_util/src/host.rs @@ -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 = #wrapper_name; + type Exports = #wrapper_name; fn instantiate(mut self, i: I) -> Self::Exports { let rts = register_host_functions(&mut self, i); - let sb = self.evolve().unwrap(); + let sb = self.init().unwrap(); #wrapper_name { sb, rt: rts, diff --git a/src/hyperlight_host/benches/benchmarks.rs b/src/hyperlight_host/benches/benchmarks.rs index 96cc7ecf0..f64580c28 100644 --- a/src/hyperlight_host/benches/benchmarks.rs +++ b/src/hyperlight_host/benches/benchmarks.rs @@ -16,9 +16,7 @@ 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 { @@ -26,8 +24,8 @@ fn create_uninit_sandbox() -> UninitializedSandbox { 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) { @@ -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 @@ -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 diff --git a/src/hyperlight_host/examples/func_ctx/main.rs b/src/hyperlight_host/examples/func_ctx/main.rs index 2692f9487..865451c48 100644 --- a/src/hyperlight_host/examples/func_ctx/main.rs +++ b/src/hyperlight_host/examples/func_ctx/main.rs @@ -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, diff --git a/src/hyperlight_host/examples/guest-debugging/main.rs b/src/hyperlight_host/examples/guest-debugging/main.rs index cc39b1705..67c0bfd83 100644 --- a/src/hyperlight_host/examples/guest-debugging/main.rs +++ b/src/hyperlight_host/examples/guest-debugging/main.rs @@ -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 { @@ -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 = diff --git a/src/hyperlight_host/examples/hello-world/main.rs b/src/hyperlight_host/examples/hello-world/main.rs index e8461954a..d0b8714c6 100644 --- a/src/hyperlight_host/examples/hello-world/main.rs +++ b/src/hyperlight_host/examples/hello-world/main.rs @@ -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 @@ -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(); diff --git a/src/hyperlight_host/examples/logging/main.rs b/src/hyperlight_host/examples/logging/main.rs index 470441e72..8b1fe4e9e 100644 --- a/src/hyperlight_host/examples/logging/main.rs +++ b/src/hyperlight_host/examples/logging/main.rs @@ -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 { @@ -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(); diff --git a/src/hyperlight_host/examples/metrics/main.rs b/src/hyperlight_host/examples/metrics/main.rs index 4328a3bfa..9abc07064 100644 --- a/src/hyperlight_host/examples/metrics/main.rs +++ b/src/hyperlight_host/examples/metrics/main.rs @@ -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 { @@ -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; diff --git a/src/hyperlight_host/examples/tracing-chrome/main.rs b/src/hyperlight_host/examples/tracing-chrome/main.rs index 259a37057..1e68ac36c 100644 --- a/src/hyperlight_host/examples/tracing-chrome/main.rs +++ b/src/hyperlight_host/examples/tracing-chrome/main.rs @@ -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(); diff --git a/src/hyperlight_host/examples/tracing-otlp/main.rs b/src/hyperlight_host/examples/tracing-otlp/main.rs index 69d318c1f..d346b0417 100644 --- a/src/hyperlight_host/examples/tracing-otlp/main.rs +++ b/src/hyperlight_host/examples/tracing-otlp/main.rs @@ -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 { diff --git a/src/hyperlight_host/examples/tracing-tracy/main.rs b/src/hyperlight_host/examples/tracing-tracy/main.rs index 03867f0d5..61901a827 100644 --- a/src/hyperlight_host/examples/tracing-tracy/main.rs +++ b/src/hyperlight_host/examples/tracing-tracy/main.rs @@ -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(); diff --git a/src/hyperlight_host/examples/tracing/main.rs b/src/hyperlight_host/examples/tracing/main.rs index 66020dcfa..7b3915c54 100644 --- a/src/hyperlight_host/examples/tracing/main.rs +++ b/src/hyperlight_host/examples/tracing/main.rs @@ -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 { @@ -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. diff --git a/src/hyperlight_host/src/hypervisor/mod.rs b/src/hyperlight_host/src/hypervisor/mod.rs index 53b721c7c..d25c5b34a 100644 --- a/src/hyperlight_host/src/hypervisor/mod.rs +++ b/src/hyperlight_host/src/hypervisor/mod.rs @@ -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}; diff --git a/src/hyperlight_host/src/lib.rs b/src/hyperlight_host/src/lib.rs index 9a32a9ecc..6531db1c9 100644 --- a/src/hyperlight_host/src/lib.rs +++ b/src/hyperlight_host/src/lib.rs @@ -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 //! @@ -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; +pub use sandbox::Sandbox; /// The re-export for the `UninitializedSandbox` type pub use sandbox::UninitializedSandbox; /// The re-export for the `is_hypervisor_present` type diff --git a/src/hyperlight_host/src/metrics/mod.rs b/src/hyperlight_host/src/metrics/mod.rs index a2f4026e5..990cd89d6 100644 --- a/src/hyperlight_host/src/metrics/mod.rs +++ b/src/hyperlight_host/src/metrics/mod.rs @@ -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 diff --git a/src/hyperlight_host/src/sandbox/mod.rs b/src/hyperlight_host/src/sandbox/mod.rs index 5b367cb6f..bec6e19a2 100644 --- a/src/hyperlight_host/src/sandbox/mod.rs +++ b/src/hyperlight_host/src/sandbox/mod.rs @@ -20,9 +20,6 @@ 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; @@ -30,12 +27,16 @@ pub(crate) mod mem_access; /// `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; @@ -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; @@ -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 @@ -269,7 +270,7 @@ mod tests { #[test] fn check_create_and_use_sandbox_on_different_threads() { let unintializedsandbox_queue = Arc::new(ArrayQueue::::new(10)); - let sandbox_queue = Arc::new(ArrayQueue::::new(10)); + let sandbox_queue = Arc::new(ArrayQueue::::new(10)); for i in 0..10 { let simple_guest_path = simple_guest_as_string().expect("Guest Binary Missing"); @@ -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) }); diff --git a/src/hyperlight_host/src/sandbox/initialized_multi_use.rs b/src/hyperlight_host/src/sandbox/sandbox.rs similarity index 93% rename from src/hyperlight_host/src/sandbox/initialized_multi_use.rs rename to src/hyperlight_host/src/sandbox/sandbox.rs index 7692a4379..575072c4d 100644 --- a/src/hyperlight_host/src/sandbox/initialized_multi_use.rs +++ b/src/hyperlight_host/src/sandbox/sandbox.rs @@ -53,7 +53,7 @@ static SANDBOX_ID_COUNTER: AtomicU64 = AtomicU64::new(0); /// /// Guest functions can be called repeatedly while maintaining state between calls. /// The sandbox supports creating snapshots and restoring to previous states. -pub struct MultiUseSandbox { +pub struct Sandbox { /// Unique identifier for this sandbox instance id: u64, // We need to keep a reference to the host functions, even if the compiler marks it as unused. The compiler cannot detect our dynamic usages of the host function in `HyperlightFunction::call`. @@ -65,10 +65,10 @@ pub struct MultiUseSandbox { dbg_mem_access_fn: DbgMemAccessHandlerWrapper, } -impl MultiUseSandbox { - /// Move an `UninitializedSandbox` into a new `MultiUseSandbox` instance. +impl Sandbox { + /// Move an `UninitializedSandbox` into a new `Sandbox` instance. /// - /// This function is not equivalent to doing an `evolve` from uninitialized + /// This function is not equivalent to doing an `init` from uninitialized /// to initialized, and is purposely not exposed publicly outside the crate /// (as a `From` implementation would be) #[instrument(skip_all, parent = Span::current(), level = "Trace")] @@ -78,7 +78,7 @@ impl MultiUseSandbox { vm: Box, dispatch_ptr: RawPtr, #[cfg(gdb)] dbg_mem_access_fn: DbgMemAccessHandlerWrapper, - ) -> MultiUseSandbox { + ) -> Sandbox { Self { id: SANDBOX_ID_COUNTER.fetch_add(1, Ordering::Relaxed), _host_funcs: host_funcs, @@ -98,12 +98,12 @@ impl MultiUseSandbox { /// # Examples /// /// ```no_run - /// # use hyperlight_host::{MultiUseSandbox, UninitializedSandbox, GuestBinary}; + /// # use hyperlight_host::{Sandbox, UninitializedSandbox, GuestBinary}; /// # fn example() -> Result<(), Box> { - /// let mut sandbox: MultiUseSandbox = UninitializedSandbox::new( + /// let mut sandbox: Sandbox = UninitializedSandbox::new( /// GuestBinary::FilePath("guest.bin".into()), /// None - /// )?.evolve()?; + /// )?.init()?; /// /// // Modify sandbox state /// sandbox.call_guest_function_by_name::("SetValue", 42)?; @@ -135,12 +135,12 @@ impl MultiUseSandbox { /// # Examples /// /// ```no_run - /// # use hyperlight_host::{MultiUseSandbox, UninitializedSandbox, GuestBinary}; + /// # use hyperlight_host::{Sandbox, UninitializedSandbox, GuestBinary}; /// # fn example() -> Result<(), Box> { - /// let mut sandbox: MultiUseSandbox = UninitializedSandbox::new( + /// let mut sandbox: Sandbox = UninitializedSandbox::new( /// GuestBinary::FilePath("guest.bin".into()), /// None - /// )?.evolve()?; + /// )?.init()?; /// /// // Take initial snapshot from this sandbox /// let snapshot = sandbox.snapshot()?; @@ -191,12 +191,12 @@ impl MultiUseSandbox { /// # Examples /// /// ```no_run - /// # use hyperlight_host::{MultiUseSandbox, UninitializedSandbox, GuestBinary}; + /// # use hyperlight_host::{Sandbox, UninitializedSandbox, GuestBinary}; /// # fn example() -> Result<(), Box> { - /// let mut sandbox: MultiUseSandbox = UninitializedSandbox::new( + /// let mut sandbox: Sandbox = UninitializedSandbox::new( /// GuestBinary::FilePath("guest.bin".into()), /// None - /// )?.evolve()?; + /// )?.init()?; /// /// // Call function with no arguments /// let result: i32 = sandbox.call_guest_function_by_name("GetCounter", ())?; @@ -362,14 +362,14 @@ impl MultiUseSandbox { /// # Examples /// /// ```no_run - /// # use hyperlight_host::{MultiUseSandbox, UninitializedSandbox, GuestBinary}; + /// # use hyperlight_host::{Sandbox, UninitializedSandbox, GuestBinary}; /// # use std::thread; /// # use std::time::Duration; /// # fn example() -> Result<(), Box> { - /// let mut sandbox: MultiUseSandbox = UninitializedSandbox::new( + /// let mut sandbox: Sandbox = UninitializedSandbox::new( /// GuestBinary::FilePath("guest.bin".into()), /// None - /// )?.evolve()?; + /// )?.init()?; /// /// // Get interrupt handle before starting long-running operation /// let interrupt_handle = sandbox.interrupt_handle(); @@ -391,7 +391,7 @@ impl MultiUseSandbox { } } -impl Callable for MultiUseSandbox { +impl Callable for Sandbox { fn call( &mut self, func_name: &str, @@ -401,7 +401,7 @@ impl Callable for MultiUseSandbox { } } -impl WrapperGetter for MultiUseSandbox { +impl WrapperGetter for Sandbox { fn get_mgr_wrapper(&self) -> &MemMgrWrapper { &self.mem_mgr } @@ -410,9 +410,9 @@ impl WrapperGetter for MultiUseSandbox { } } -impl std::fmt::Debug for MultiUseSandbox { +impl std::fmt::Debug for Sandbox { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("MultiUseSandbox") + f.debug_struct("Sandbox") .field("stack_guard", &self.mem_mgr.get_stack_cookie()) .finish() } @@ -430,7 +430,7 @@ mod tests { #[cfg(target_os = "linux")] use crate::mem::shared_mem::{ExclusiveSharedMemory, GuestSharedMemory, SharedMemory as _}; use crate::sandbox::{Callable, SandboxConfiguration}; - use crate::{GuestBinary, HyperlightError, MultiUseSandbox, Result, UninitializedSandbox}; + use crate::{GuestBinary, HyperlightError, Result, Sandbox, UninitializedSandbox}; // Tests to ensure that many (1000) function calls can be made in a call context with a small stack (1K) and heap(14K). // This test effectively ensures that the stack is being properly reset after each call and we are not leaking memory in the Guest. @@ -440,10 +440,10 @@ mod tests { cfg.set_heap_size(20 * 1024); cfg.set_stack_size(16 * 1024); - let mut sbox1: MultiUseSandbox = { + let mut sbox1: Sandbox = { let path = simple_guest_as_string().unwrap(); let u_sbox = UninitializedSandbox::new(GuestBinary::FilePath(path), Some(cfg)).unwrap(); - u_sbox.evolve() + u_sbox.init() } .unwrap(); @@ -451,10 +451,10 @@ mod tests { sbox1.call::("Echo", "hello".to_string()).unwrap(); } - let mut sbox2: MultiUseSandbox = { + let mut sbox2: Sandbox = { let path = simple_guest_as_string().unwrap(); let u_sbox = UninitializedSandbox::new(GuestBinary::FilePath(path), Some(cfg)).unwrap(); - u_sbox.evolve() + u_sbox.init() } .unwrap(); @@ -468,14 +468,14 @@ mod tests { } } - /// Tests that evolving from MultiUseSandbox to MultiUseSandbox creates a new state - /// and restoring a snapshot from before evolving restores the previous state + /// Tests that calling a guest function from a Sandbox mutates its state + /// and restoring a snapshot restores the previous state #[test] - fn snapshot_evolve_restore_handles_state_correctly() { - let mut sbox: MultiUseSandbox = { + fn snapshot_restore_resets_state_correctly() { + let mut sbox: Sandbox = { let path = simple_guest_as_string().unwrap(); let u_sbox = UninitializedSandbox::new(GuestBinary::FilePath(path), None).unwrap(); - u_sbox.evolve() + u_sbox.init() } .unwrap(); @@ -513,7 +513,7 @@ mod tests { usbox.register("MakeGetpidSyscall", make_get_pid_syscall)?; - let mut sbox: MultiUseSandbox = usbox.evolve()?; + let mut sbox: Sandbox = usbox.init()?; let res: Result = sbox.call_guest_function_by_name("ViolateSeccompFilters", ()); @@ -549,7 +549,7 @@ mod tests { )?; // ^^^ note, we are allowing SYS_getpid - let mut sbox: MultiUseSandbox = usbox.evolve()?; + let mut sbox: Sandbox = usbox.init()?; let res: Result = sbox.call_guest_function_by_name("ViolateSeccompFilters", ()); @@ -603,7 +603,7 @@ mod tests { .unwrap(); ubox.register("Openat_Hostfunc", make_openat_syscall)?; - let mut sbox = ubox.evolve().unwrap(); + let mut sbox = ubox.init().unwrap(); let host_func_result = sbox .call_guest_function_by_name::( "CallGivenParamlessHostFuncThatReturnsI64", @@ -633,7 +633,7 @@ mod tests { make_openat_syscall, [libc::SYS_openat], )?; - let mut sbox = ubox.evolve().unwrap(); + let mut sbox = ubox.init().unwrap(); let host_func_result = sbox .call_guest_function_by_name::( "CallGivenParamlessHostFuncThatReturnsI64", @@ -656,7 +656,7 @@ mod tests { ) .unwrap(); - let mut multi_use_sandbox: MultiUseSandbox = usbox.evolve().unwrap(); + let mut multi_use_sandbox: Sandbox = usbox.init().unwrap(); let res: Result<()> = multi_use_sandbox.call_guest_function_by_name("TriggerException", ()); @@ -696,7 +696,7 @@ mod tests { ) .unwrap(); - let mut multi_use_sandbox: MultiUseSandbox = usbox.evolve().unwrap(); + let mut multi_use_sandbox: Sandbox = usbox.init().unwrap(); let res: i32 = multi_use_sandbox .call_guest_function_by_name("GetStatic", ()) @@ -724,7 +724,7 @@ mod tests { None, ) .unwrap() - .evolve() + .init() .unwrap(); let expected = b"hello world"; @@ -760,7 +760,7 @@ mod tests { None, ) .unwrap() - .evolve() + .init() .unwrap(); let expected = &[0x90, 0x90, 0x90, 0xC3]; // NOOP slide to RET @@ -839,10 +839,10 @@ mod tests { #[test] #[cfg(target_os = "linux")] fn snapshot_restore_handles_remapping_correctly() { - let mut sbox: MultiUseSandbox = { + let mut sbox: Sandbox = { let path = simple_guest_as_string().unwrap(); let u_sbox = UninitializedSandbox::new(GuestBinary::FilePath(path), None).unwrap(); - u_sbox.evolve().unwrap() + u_sbox.init().unwrap() }; // 1. Take snapshot 1 with no additional regions mapped @@ -889,13 +889,13 @@ mod tests { let mut sandbox = { let path = simple_guest_as_string().unwrap(); let u_sbox = UninitializedSandbox::new(GuestBinary::FilePath(path), None).unwrap(); - u_sbox.evolve().unwrap() + u_sbox.init().unwrap() }; let mut sandbox2 = { let path = simple_guest_as_string().unwrap(); let u_sbox = UninitializedSandbox::new(GuestBinary::FilePath(path), None).unwrap(); - u_sbox.evolve().unwrap() + u_sbox.init().unwrap() }; assert_ne!(sandbox.id, sandbox2.id); @@ -911,7 +911,7 @@ mod tests { let sandbox3 = { let path = simple_guest_as_string().unwrap(); let u_sbox = UninitializedSandbox::new(GuestBinary::FilePath(path), None).unwrap(); - u_sbox.evolve().unwrap() + u_sbox.init().unwrap() }; assert_ne!(sandbox3.id, sandbox_id); } diff --git a/src/hyperlight_host/src/sandbox/snapshot.rs b/src/hyperlight_host/src/sandbox/snapshot.rs index e9e996e7a..4121145ed 100644 --- a/src/hyperlight_host/src/sandbox/snapshot.rs +++ b/src/hyperlight_host/src/sandbox/snapshot.rs @@ -16,7 +16,7 @@ limitations under the License. use crate::mem::shared_mem_snapshot::SharedMemorySnapshot; -/// A snapshot capturing the state of the memory in a `MultiUseSandbox`. +/// A snapshot capturing the state of the memory in a `Sandbox`. #[derive(Clone)] pub struct Snapshot { // TODO: Use Arc diff --git a/src/hyperlight_host/src/sandbox/uninitialized.rs b/src/hyperlight_host/src/sandbox/uninitialized.rs index 65e9d9a80..e71a12908 100644 --- a/src/hyperlight_host/src/sandbox/uninitialized.rs +++ b/src/hyperlight_host/src/sandbox/uninitialized.rs @@ -24,7 +24,7 @@ use tracing::{Span, instrument}; use super::host_funcs::{FunctionRegistry, default_writer_func}; use super::mem_mgr::MemMgrWrapper; -use super::uninitialized_evolve::evolve_impl_multi_use; +use super::uninitialized_init::init_impl_multi_use; use crate::func::host_functions::{HostFunction, register_host_function}; use crate::func::{ParameterTuple, SupportedReturnType}; #[cfg(feature = "build-metadata")] @@ -34,7 +34,7 @@ use crate::mem::memory_region::{DEFAULT_GUEST_BLOB_MEM_FLAGS, MemoryRegionFlags} use crate::mem::mgr::{STACK_COOKIE_LEN, SandboxMemoryManager}; use crate::mem::shared_mem::ExclusiveSharedMemory; use crate::sandbox::SandboxConfiguration; -use crate::{MultiUseSandbox, Result, new_error}; +use crate::{Result, Sandbox, new_error}; #[cfg(all(target_os = "linux", feature = "seccomp"))] const EXTRA_ALLOWED_SYSCALLS_FOR_WRITER_FUNC: &[super::ExtraAllowedSyscall] = &[ @@ -71,8 +71,8 @@ pub(crate) struct SandboxRuntimeConfig { /// - Register host functions that will be available to the guest /// - Configure sandbox settings before VM creation /// -/// The virtual machine is not created until you call [`evolve`](Self::evolve) to transform -/// this into an initialized [`MultiUseSandbox`]. +/// The virtual machine is not created until you call [`init`](Self::init) to transform +/// this into an initialized [`Sandbox`]. pub struct UninitializedSandbox { /// Registered host functions pub(crate) host_funcs: Arc>, @@ -97,11 +97,11 @@ impl UninitializedSandbox { /// Creates and initializes the virtual machine, transforming this into a ready-to-use sandbox. /// /// This method consumes the `UninitializedSandbox` and performs the final initialization - /// steps to create the underlying virtual machine. Once evolved, the resulting - /// [`MultiUseSandbox`] can execute guest code and handle function calls. + /// steps to create the underlying virtual machine. Once initialized, the resulting + /// [`Sandbox`] can execute guest code and handle function calls. #[instrument(err(Debug), skip_all, parent = Span::current(), level = "Trace")] - pub fn evolve(self) -> Result { - evolve_impl_multi_use(self) + pub fn init(self) -> Result { + init_impl_multi_use(self) } } @@ -170,7 +170,7 @@ impl UninitializedSandbox { /// The guest binary can be provided as either a file path or memory buffer. /// An optional configuration can customize memory sizes and sandbox settings. /// After creation, register host functions using [`register`](Self::register) - /// before calling [`evolve`](Self::evolve) to complete initialization and create the VM. + /// before calling [`init`](Self::init) to complete initialization and create the VM. #[instrument( err(Debug), skip(env), @@ -421,7 +421,7 @@ mod tests { use crate::sandbox::SandboxConfiguration; use crate::sandbox::uninitialized::{GuestBinary, GuestEnvironment}; - use crate::{MultiUseSandbox, Result, UninitializedSandbox, new_error}; + use crate::{Result, Sandbox, UninitializedSandbox, new_error}; #[test] fn test_load_extra_blob() { @@ -431,7 +431,7 @@ mod tests { GuestEnvironment::new(GuestBinary::FilePath(binary_path.clone()), Some(&buffer)); let uninitialized_sandbox = UninitializedSandbox::new(guest_env, None).unwrap(); - let mut sandbox: MultiUseSandbox = uninitialized_sandbox.evolve().unwrap(); + let mut sandbox: Sandbox = uninitialized_sandbox.init().unwrap(); let res = sandbox .call_guest_function_by_name::>("ReadFromUserMemory", (4u64, buffer.to_vec())) @@ -475,7 +475,7 @@ mod tests { // Get a Sandbox from an uninitialized sandbox without a call back function - let _sandbox: MultiUseSandbox = uninitialized_sandbox.evolve().unwrap(); + let _sandbox: Sandbox = uninitialized_sandbox.init().unwrap(); // Test with a valid guest binary buffer @@ -523,7 +523,7 @@ mod tests { usbox.register("test0", |arg: i32| Ok(arg + 1)).unwrap(); - let sandbox: Result = usbox.evolve(); + let sandbox: Result = usbox.init(); assert!(sandbox.is_ok()); let sandbox = sandbox.unwrap(); @@ -548,7 +548,7 @@ mod tests { usbox.register("test1", |a: i32, b: i32| Ok(a + b)).unwrap(); - let sandbox: Result = usbox.evolve(); + let sandbox: Result = usbox.init(); assert!(sandbox.is_ok()); let sandbox = sandbox.unwrap(); @@ -581,7 +581,7 @@ mod tests { }) .unwrap(); - let sandbox: Result = usbox.evolve(); + let sandbox: Result = usbox.init(); assert!(sandbox.is_ok()); let sandbox = sandbox.unwrap(); @@ -599,7 +599,7 @@ mod tests { // calling a function that doesn't exist { let usbox = uninitialized_sandbox(); - let sandbox: Result = usbox.evolve(); + let sandbox: Result = usbox.init(); assert!(sandbox.is_ok()); let sandbox = sandbox.unwrap(); @@ -780,7 +780,7 @@ mod tests { #[test] fn check_create_and_use_sandbox_on_different_threads() { let unintializedsandbox_queue = Arc::new(ArrayQueue::::new(10)); - let sandbox_queue = Arc::new(ArrayQueue::::new(10)); + let sandbox_queue = Arc::new(ArrayQueue::::new(10)); for i in 0..10 { let simple_guest_path = simple_guest_as_string().expect("Guest Binary Missing"); @@ -822,7 +822,7 @@ mod tests { .host_print(format!("Print from UninitializedSandbox on Thread {}\n", i)) .unwrap(); - let sandbox = uninitialized_sandbox.evolve().unwrap_or_else(|_| { + let sandbox = uninitialized_sandbox.init().unwrap_or_else(|_| { panic!("Failed to initialize UninitializedSandbox thread {}", i) }); @@ -1112,7 +1112,7 @@ mod tests { ); res.unwrap() }; - let _: Result = sbox.evolve(); + let _: Result = sbox.init(); let num_calls = TEST_LOGGER.num_log_calls(); diff --git a/src/hyperlight_host/src/sandbox/uninitialized_evolve.rs b/src/hyperlight_host/src/sandbox/uninitialized_init.rs similarity index 94% rename from src/hyperlight_host/src/sandbox/uninitialized_evolve.rs rename to src/hyperlight_host/src/sandbox/uninitialized_init.rs index 5db2722ef..296005a3c 100644 --- a/src/hyperlight_host/src/sandbox/uninitialized_evolve.rs +++ b/src/hyperlight_host/src/sandbox/uninitialized_init.rs @@ -43,9 +43,9 @@ use crate::sandbox::host_funcs::FunctionRegistry; use crate::sandbox::{HostSharedMemory, MemMgrWrapper}; #[cfg(target_os = "linux")] use crate::signal_handlers::setup_signal_handlers; -use crate::{MultiUseSandbox, Result, UninitializedSandbox, log_then_return, new_error}; +use crate::{Result, Sandbox, UninitializedSandbox, log_then_return, new_error}; -/// The implementation for evolving `UninitializedSandbox`es to +/// The implementation for initializing `UninitializedSandbox`es to /// `Sandbox`es. /// /// Note that `cb_opt`'s type has been carefully considered. @@ -57,7 +57,7 @@ use crate::{MultiUseSandbox, Result, UninitializedSandbox, log_then_return, new_ /// If this doesn't make sense, and you want to change this type, /// please reach out to a Hyperlight developer before making the change. #[instrument(err(Debug), skip_all, , parent = Span::current(), level = "Trace")] -fn evolve_impl( +fn init_impl( u_sbox: UninitializedSandbox, transform: TransformFunc, ) -> Result @@ -120,11 +120,11 @@ where } #[instrument(err(Debug), skip_all, parent = Span::current(), level = "Trace")] -pub(super) fn evolve_impl_multi_use(u_sbox: UninitializedSandbox) -> Result { - evolve_impl(u_sbox, |hf, hshm, vm, dispatch_ptr| { +pub(super) fn init_impl_multi_use(u_sbox: UninitializedSandbox) -> Result { + init_impl(u_sbox, |hf, hshm, vm, dispatch_ptr| { #[cfg(gdb)] let dbg_mem_wrapper = dbg_mem_access_handler_wrapper(hshm.clone()); - Ok(MultiUseSandbox::from_uninit( + Ok(Sandbox::from_uninit( hf, hshm, vm, @@ -275,12 +275,12 @@ pub(crate) fn set_up_hypervisor_partition( mod tests { use hyperlight_testing::{callback_guest_as_string, simple_guest_as_string}; - use super::evolve_impl_multi_use; + use super::init_impl_multi_use; use crate::UninitializedSandbox; use crate::sandbox::uninitialized::GuestBinary; #[test] - fn test_evolve() { + fn test_init() { let guest_bin_paths = vec![ simple_guest_as_string().unwrap(), callback_guest_as_string().unwrap(), @@ -289,7 +289,7 @@ mod tests { let u_sbox = UninitializedSandbox::new(GuestBinary::FilePath(guest_bin_path.clone()), None) .unwrap(); - evolve_impl_multi_use(u_sbox).unwrap(); + init_impl_multi_use(u_sbox).unwrap(); } } } diff --git a/src/hyperlight_host/tests/common/mod.rs b/src/hyperlight_host/tests/common/mod.rs index 39d08a3e5..4a321d958 100644 --- a/src/hyperlight_host/tests/common/mod.rs +++ b/src/hyperlight_host/tests/common/mod.rs @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ use hyperlight_host::func::HostFunction; -use hyperlight_host::{GuestBinary, MultiUseSandbox, Result, UninitializedSandbox}; +use hyperlight_host::{GuestBinary, Result, Sandbox, UninitializedSandbox}; use hyperlight_testing::{ c_callback_guest_as_string, c_simple_guest_as_string, callback_guest_as_string, simple_guest_as_string, @@ -40,7 +40,7 @@ pub fn new_uninit_rust() -> Result { pub fn get_simpleguest_sandboxes( writer: Option>, // An optional writer to make sure correct info is passed to the host printer -) -> Vec { +) -> Vec { let elf_path = get_c_or_rust_simpleguest_path(); let sandboxes = [ @@ -54,7 +54,7 @@ pub fn get_simpleguest_sandboxes( if let Some(writer) = writer.clone() { sandbox.register_print(writer).unwrap(); } - sandbox.evolve().unwrap() + sandbox.init().unwrap() }) .collect() } diff --git a/src/hyperlight_host/tests/integration_test.rs b/src/hyperlight_host/tests/integration_test.rs index 967d93c53..44a46cf4d 100644 --- a/src/hyperlight_host/tests/integration_test.rs +++ b/src/hyperlight_host/tests/integration_test.rs @@ -22,7 +22,7 @@ use std::time::Duration; use hyperlight_common::flatbuffer_wrappers::guest_error::ErrorCode; use hyperlight_common::mem::PAGE_SIZE; use hyperlight_host::sandbox::SandboxConfiguration; -use hyperlight_host::{GuestBinary, HyperlightError, MultiUseSandbox, UninitializedSandbox}; +use hyperlight_host::{GuestBinary, HyperlightError, Sandbox, UninitializedSandbox}; use hyperlight_testing::simplelogger::{LOGGER, SimpleLogger}; use hyperlight_testing::{ c_simple_guest_as_string, callback_guest_as_string, simple_guest_as_string, @@ -59,7 +59,7 @@ fn interrupt_host_call() { .register_with_extra_allowed_syscalls("Spin", spin, vec![libc::SYS_clock_nanosleep]) .unwrap(); - let mut sandbox: MultiUseSandbox = usbox.evolve().unwrap(); + let mut sandbox: Sandbox = usbox.init().unwrap(); let interrupt_handle = sandbox.interrupt_handle(); assert!(!interrupt_handle.dropped()); // not yet dropped @@ -81,7 +81,7 @@ fn interrupt_host_call() { /// Makes sure a running guest call can be interrupted by the host #[test] fn interrupt_in_progress_guest_call() { - let mut sbox1: MultiUseSandbox = new_uninit_rust().unwrap().evolve().unwrap(); + let mut sbox1: Sandbox = new_uninit_rust().unwrap().init().unwrap(); let barrier = Arc::new(Barrier::new(2)); let barrier2 = barrier.clone(); let interrupt_handle = sbox1.interrupt_handle(); @@ -116,7 +116,7 @@ fn interrupt_in_progress_guest_call() { /// Makes sure interrupting a vm before the guest call has started also prevents the guest call from being executed #[test] fn interrupt_guest_call_in_advance() { - let mut sbox1: MultiUseSandbox = new_uninit_rust().unwrap().evolve().unwrap(); + let mut sbox1: Sandbox = new_uninit_rust().unwrap().init().unwrap(); let barrier = Arc::new(Barrier::new(2)); let barrier2 = barrier.clone(); let interrupt_handle = sbox1.interrupt_handle(); @@ -158,9 +158,9 @@ fn interrupt_guest_call_in_advance() { /// all possible interleavings, but can hopefully increases confidence somewhat. #[test] fn interrupt_same_thread() { - let mut sbox1: MultiUseSandbox = new_uninit_rust().unwrap().evolve().unwrap(); - let mut sbox2: MultiUseSandbox = new_uninit_rust().unwrap().evolve().unwrap(); - let mut sbox3: MultiUseSandbox = new_uninit_rust().unwrap().evolve().unwrap(); + let mut sbox1: Sandbox = new_uninit_rust().unwrap().init().unwrap(); + let mut sbox2: Sandbox = new_uninit_rust().unwrap().init().unwrap(); + let mut sbox3: Sandbox = new_uninit_rust().unwrap().init().unwrap(); let barrier = Arc::new(Barrier::new(2)); let barrier2 = barrier.clone(); @@ -200,9 +200,9 @@ fn interrupt_same_thread() { /// Same test as above but with no per-iteration barrier, to get more possible interleavings. #[test] fn interrupt_same_thread_no_barrier() { - let mut sbox1: MultiUseSandbox = new_uninit_rust().unwrap().evolve().unwrap(); - let mut sbox2: MultiUseSandbox = new_uninit_rust().unwrap().evolve().unwrap(); - let mut sbox3: MultiUseSandbox = new_uninit_rust().unwrap().evolve().unwrap(); + let mut sbox1: Sandbox = new_uninit_rust().unwrap().init().unwrap(); + let mut sbox2: Sandbox = new_uninit_rust().unwrap().init().unwrap(); + let mut sbox3: Sandbox = new_uninit_rust().unwrap().init().unwrap(); let barrier = Arc::new(Barrier::new(2)); let barrier2 = barrier.clone(); @@ -246,8 +246,8 @@ fn interrupt_same_thread_no_barrier() { // and that anther sandbox on the original thread does not get incorrectly killed #[test] fn interrupt_moved_sandbox() { - let mut sbox1: MultiUseSandbox = new_uninit_rust().unwrap().evolve().unwrap(); - let mut sbox2: MultiUseSandbox = new_uninit_rust().unwrap().evolve().unwrap(); + let mut sbox1: Sandbox = new_uninit_rust().unwrap().init().unwrap(); + let mut sbox2: Sandbox = new_uninit_rust().unwrap().init().unwrap(); let interrupt_handle = sbox1.interrupt_handle(); let interrupt_handle2 = sbox2.interrupt_handle(); @@ -293,12 +293,12 @@ fn interrupt_custom_signal_no_and_retry_delay() { config.set_interrupt_vcpu_sigrtmin_offset(0).unwrap(); config.set_interrupt_retry_delay(Duration::from_secs(1)); - let mut sbox1: MultiUseSandbox = UninitializedSandbox::new( + let mut sbox1: Sandbox = UninitializedSandbox::new( GuestBinary::FilePath(simple_guest_as_string().unwrap()), Some(config), ) .unwrap() - .evolve() + .init() .unwrap(); let interrupt_handle = sbox1.interrupt_handle(); @@ -338,7 +338,7 @@ fn interrupt_spamming_host_call() { // do nothing }) .unwrap(); - let mut sbox1: MultiUseSandbox = uninit.evolve().unwrap(); + let mut sbox1: Sandbox = uninit.init().unwrap(); let interrupt_handle = sbox1.interrupt_handle(); @@ -367,7 +367,7 @@ fn print_four_args_c_guest() { let path = c_simple_guest_as_string().unwrap(); let guest_path = GuestBinary::FilePath(path); let uninit = UninitializedSandbox::new(guest_path, None); - let mut sbox1 = uninit.unwrap().evolve().unwrap(); + let mut sbox1 = uninit.unwrap().init().unwrap(); let res = sbox1.call_guest_function_by_name::( "PrintFourArgs", @@ -380,7 +380,7 @@ fn print_four_args_c_guest() { // Checks that guest can abort with a specific code. #[test] fn guest_abort() { - let mut sbox1 = new_uninit().unwrap().evolve().unwrap(); + let mut sbox1 = new_uninit().unwrap().init().unwrap(); let error_code: u8 = 13; // this is arbitrary let res = sbox1 .call_guest_function_by_name::<()>("GuestAbortWithCode", error_code as i32) @@ -393,7 +393,7 @@ fn guest_abort() { #[test] fn guest_abort_with_context1() { - let mut sbox1 = new_uninit().unwrap().evolve().unwrap(); + let mut sbox1 = new_uninit().unwrap().init().unwrap(); let res = sbox1 .call_guest_function_by_name::<()>("GuestAbortWithMessage", (25_i32, "Oh no".to_string())) @@ -406,7 +406,7 @@ fn guest_abort_with_context1() { #[test] fn guest_abort_with_context2() { - let mut sbox1 = new_uninit().unwrap().evolve().unwrap(); + let mut sbox1 = new_uninit().unwrap().init().unwrap(); // The buffer size for the panic context is 1024 bytes. // This test will see what happens if the panic message is longer than that @@ -460,7 +460,7 @@ fn guest_abort_c_guest() { let path = c_simple_guest_as_string().unwrap(); let guest_path = GuestBinary::FilePath(path); let uninit = UninitializedSandbox::new(guest_path, None); - let mut sbox1 = uninit.unwrap().evolve().unwrap(); + let mut sbox1 = uninit.unwrap().init().unwrap(); let res = sbox1 .call_guest_function_by_name::<()>( @@ -477,7 +477,7 @@ fn guest_abort_c_guest() { #[test] fn guest_panic() { // this test is rust-specific - let mut sbox1 = new_uninit_rust().unwrap().evolve().unwrap(); + let mut sbox1 = new_uninit_rust().unwrap().init().unwrap(); let res = sbox1 .call_guest_function_by_name::<()>("guest_panic", "Error... error...".to_string()) @@ -491,7 +491,7 @@ fn guest_panic() { #[test] fn guest_malloc() { // this test is rust-only - let mut sbox1 = new_uninit_rust().unwrap().evolve().unwrap(); + let mut sbox1 = new_uninit_rust().unwrap().init().unwrap(); let size_to_allocate = 2000_i32; sbox1 @@ -501,7 +501,7 @@ fn guest_malloc() { #[test] fn guest_allocate_vec() { - let mut sbox1 = new_uninit().unwrap().evolve().unwrap(); + let mut sbox1 = new_uninit().unwrap().init().unwrap(); let size_to_allocate = 2000_i32; @@ -518,7 +518,7 @@ fn guest_allocate_vec() { // checks that malloc failures are captured correctly #[test] fn guest_malloc_abort() { - let mut sbox1 = new_uninit_rust().unwrap().evolve().unwrap(); + let mut sbox1 = new_uninit_rust().unwrap().init().unwrap(); let size = 20000000_i32; // some big number that should fail when allocated @@ -542,7 +542,7 @@ fn guest_malloc_abort() { Some(cfg), ) .unwrap(); - let mut sbox2 = uninit.evolve().unwrap(); + let mut sbox2 = uninit.init().unwrap(); let res = sbox2.call_guest_function_by_name::( "CallMalloc", // uses the rust allocator to allocate a vector on heap @@ -562,7 +562,7 @@ fn dynamic_stack_allocate_c_guest() { let path = c_simple_guest_as_string().unwrap(); let guest_path = GuestBinary::FilePath(path); let uninit = UninitializedSandbox::new(guest_path, None); - let mut sbox1: MultiUseSandbox = uninit.unwrap().evolve().unwrap(); + let mut sbox1: Sandbox = uninit.unwrap().init().unwrap(); let res: i32 = sbox1 .call_guest_function_by_name("StackAllocate", 100_i32) @@ -578,7 +578,7 @@ fn dynamic_stack_allocate_c_guest() { // checks that a small buffer on stack works #[test] fn static_stack_allocate() { - let mut sbox1 = new_uninit().unwrap().evolve().unwrap(); + let mut sbox1 = new_uninit().unwrap().init().unwrap(); let res: i32 = sbox1.call_guest_function_by_name("SmallVar", ()).unwrap(); assert_eq!(res, 1024); @@ -587,7 +587,7 @@ fn static_stack_allocate() { // checks that a huge buffer on stack fails with stackoverflow #[test] fn static_stack_allocate_overflow() { - let mut sbox1 = new_uninit().unwrap().evolve().unwrap(); + let mut sbox1 = new_uninit().unwrap().init().unwrap(); let res = sbox1 .call_guest_function_by_name::("LargeVar", ()) .unwrap_err(); @@ -597,7 +597,7 @@ fn static_stack_allocate_overflow() { // checks that a recursive function with stack allocation works, (that chkstk can be called without overflowing) #[test] fn recursive_stack_allocate() { - let mut sbox1 = new_uninit().unwrap().evolve().unwrap(); + let mut sbox1 = new_uninit().unwrap().init().unwrap(); let iterations = 1_i32; @@ -627,7 +627,7 @@ fn guard_page_check() { for offset in offsets_from_page_guard_start { // we have to create a sandbox each iteration because can't reuse after MMIO error in release mode - let mut sbox1 = new_uninit_rust().unwrap().evolve().unwrap(); + let mut sbox1 = new_uninit_rust().unwrap().init().unwrap(); let result = sbox1.call_guest_function_by_name::("test_write_raw_ptr", offset); if guard_range.contains(&offset) { // should have failed @@ -644,7 +644,7 @@ fn guard_page_check() { #[test] fn guard_page_check_2() { // this test is rust-guest only - let mut sbox1 = new_uninit_rust().unwrap().evolve().unwrap(); + let mut sbox1 = new_uninit_rust().unwrap().init().unwrap(); let result = sbox1 .call_guest_function_by_name::<()>("InfiniteRecursion", ()) @@ -654,7 +654,7 @@ fn guard_page_check_2() { #[test] fn execute_on_stack() { - let mut sbox1 = new_uninit().unwrap().evolve().unwrap(); + let mut sbox1 = new_uninit().unwrap().init().unwrap(); let result = sbox1 .call_guest_function_by_name::("ExecuteOnStack", ()) @@ -670,7 +670,7 @@ fn execute_on_stack() { #[test] #[ignore] // ran from Justfile because requires feature "executable_heap" fn execute_on_heap() { - let mut sbox1 = new_uninit_rust().unwrap().evolve().unwrap(); + let mut sbox1 = new_uninit_rust().unwrap().init().unwrap(); let result = sbox1.call_guest_function_by_name::("ExecuteOnHeap", ()); println!("{:#?}", result); @@ -689,7 +689,7 @@ fn execute_on_heap() { // checks that a recursive function with stack allocation eventually fails with stackoverflow #[test] fn recursive_stack_allocate_overflow() { - let mut sbox1 = new_uninit().unwrap().evolve().unwrap(); + let mut sbox1 = new_uninit().unwrap().init().unwrap(); let iterations = 10_i32; @@ -764,7 +764,7 @@ fn log_test_messages(levelfilter: Option) { sbox.set_max_guest_log_level(levelfilter); } - let mut sbox1 = sbox.evolve().unwrap(); + let mut sbox1 = sbox.init().unwrap(); let message = format!("Hello from log_message level {}", level as i32); sbox1 diff --git a/src/hyperlight_host/tests/sandbox_host_tests.rs b/src/hyperlight_host/tests/sandbox_host_tests.rs index 7ca0ba5dc..37f9f156e 100644 --- a/src/hyperlight_host/tests/sandbox_host_tests.rs +++ b/src/hyperlight_host/tests/sandbox_host_tests.rs @@ -21,7 +21,7 @@ use std::sync::{Arc, Mutex}; use common::new_uninit; use hyperlight_host::sandbox::{Callable, SandboxConfiguration}; use hyperlight_host::{ - GuestBinary, HyperlightError, MultiUseSandbox, Result, UninitializedSandbox, new_error, + GuestBinary, HyperlightError, Result, Sandbox, UninitializedSandbox, new_error, }; use hyperlight_testing::simple_guest_as_string; #[cfg(target_os = "windows")] @@ -83,7 +83,7 @@ fn float_roundtrip() { f32::NAN, -f32::NAN, ]; - let mut sandbox: MultiUseSandbox = new_uninit().unwrap().evolve().unwrap(); + let mut sandbox: Sandbox = new_uninit().unwrap().init().unwrap(); for f in doubles.iter() { let res: f64 = sandbox .call_guest_function_by_name("EchoDouble", *f) @@ -330,7 +330,7 @@ fn callback_test_helper() -> Result<()> { })?; // call guest function that calls host function - let mut init_sandbox: MultiUseSandbox = sandbox.evolve()?; + let mut init_sandbox: Sandbox = sandbox.init()?; let msg = "Hello world"; init_sandbox.call_guest_function_by_name::("GuestMethod1", msg.to_string())?; @@ -372,7 +372,7 @@ fn host_function_error() -> Result<()> { })?; // call guest function that calls host function - let mut init_sandbox: MultiUseSandbox = sandbox.evolve()?; + let mut init_sandbox: Sandbox = sandbox.init()?; let msg = "Hello world"; let res = init_sandbox .call_guest_function_by_name::("GuestMethod1", msg.to_string()) diff --git a/src/hyperlight_host/tests/wit_test.rs b/src/hyperlight_host/tests/wit_test.rs index 8a12e1433..8ac2f8f62 100644 --- a/src/hyperlight_host/tests/wit_test.rs +++ b/src/hyperlight_host/tests/wit_test.rs @@ -18,7 +18,7 @@ limitations under the License. use std::sync::{Arc, Mutex}; use hyperlight_common::resource::BorrowedResourceGuard; -use hyperlight_host::{GuestBinary, MultiUseSandbox, UninitializedSandbox}; +use hyperlight_host::{GuestBinary, Sandbox, UninitializedSandbox}; use hyperlight_testing::wit_guest_as_string; extern crate alloc; @@ -280,7 +280,7 @@ impl test::wit::TestImports for Host { } } -fn sb() -> TestSandbox { +fn sb() -> TestSandbox { let path = wit_guest_as_string().unwrap(); let guest_path = GuestBinary::FilePath(path); let uninit = UninitializedSandbox::new(guest_path, None).unwrap();