diff --git a/src/hyperlight_host/examples/chrome-tracing/main.rs b/src/hyperlight_host/examples/chrome-tracing/main.rs index e9c717101..dd25bbf9b 100644 --- a/src/hyperlight_host/examples/chrome-tracing/main.rs +++ b/src/hyperlight_host/examples/chrome-tracing/main.rs @@ -36,9 +36,6 @@ fn main() -> Result<()> { let usandbox = UninitializedSandbox::new(GuestBinary::FilePath(simple_guest_path), None, None, None)?; - // NOTE: if replacing MultiUseSandbox with SingleUseSandbox, the function call will take ~50x longer because the drop - // happens inside `call_guest_function_by_name` rather than at the end of of this `main` block. - let mut sbox = usandbox .evolve(Noop::::default()) .unwrap(); diff --git a/src/hyperlight_host/src/func/call_ctx.rs b/src/hyperlight_host/src/func/call_ctx.rs index dc1253c34..b6cf5bc2a 100644 --- a/src/hyperlight_host/src/func/call_ctx.rs +++ b/src/hyperlight_host/src/func/call_ctx.rs @@ -20,7 +20,7 @@ use hyperlight_common::flatbuffer_wrappers::function_types::{ use tracing::{instrument, Span}; use super::guest_dispatch::call_function_on_guest; -use crate::{MultiUseSandbox, Result, SingleUseSandbox}; +use crate::{MultiUseSandbox, Result}; /// A context for calling guest functions. /// /// Takes ownership of an existing `MultiUseSandbox`. @@ -99,100 +99,6 @@ impl MultiUseGuestCallContext { } } -/// A context for calling guest functions. Can only be created from an existing -/// `SingleUseSandbox`, and once created, guest functions against that sandbox -/// can be made from this until it is dropped. -#[derive(Debug)] -pub struct SingleUseGuestCallContext { - sbox: SingleUseSandbox, -} - -impl SingleUseGuestCallContext { - /// Take ownership of a `SingleUseSandbox` and - /// return a new `SingleUseGuestCallContext` instance. - /// - #[instrument(skip_all, parent = Span::current())] - pub(crate) fn start(sbox: SingleUseSandbox) -> Self { - Self { sbox } - } - - /// Call the guest function called `func_name` with the given arguments - /// `args`, and expect the return value have the same type as - /// `func_ret_type`. - /// - /// Once the call is complete, the 'SingleUseSandbox' will no longer be useable and a new one will need to be created. - /// - /// Rather than call this method directly, consider using the `call_guest_function_by_name` method on the `SingleUseSandbox` - - #[instrument(err(Debug),skip(self, args),parent = Span::current())] - pub(crate) fn call( - mut self, - func_name: &str, - func_ret_type: ReturnType, - args: Option>, - ) -> Result { - self.call_internal(func_name, func_ret_type, args) - } - - // Internal call function that takes a mutable reference to self - // This function allows a SingleUseMultiGuestCallContext to be used to make multiple calls to guest functions - // before it is no longer usable. - #[instrument(skip_all, parent = Span::current())] - fn call_internal( - &mut self, - func_name: &str, - func_ret_type: ReturnType, - args: Option>, - ) -> Result { - // We are guaranteed to be holding a lock now, since `self` can't - // exist without doing so. since GuestCallContext is effectively - // !Send (and !Sync), we also don't need to worry about - // synchronization - - call_function_on_guest(&mut self.sbox, func_name, func_ret_type, args) - } - - /// This function allows for a `SingleUseSandbox` to be used to make multiple calls to guest functions before it is dropped. - /// - /// The function is passed a callback function that it then callsd with a reference to a 'SingleUseMultiGuestCallContext' - /// that can be used to make multiple calls to guest functions. - /// - pub fn call_from_func< - Fn: FnOnce(&mut SingleUseMultiGuestCallContext) -> Result, - >( - self, - f: Fn, - ) -> Result { - let mut ctx = SingleUseMultiGuestCallContext::new(self); - f(&mut ctx) - } -} - -/// A context for making multiple calls to guest functions in a SingleUseSandbox. Can only be created -/// from an existing SingleUseGuestCallContext using the `call_using_closure` method. -/// Once created, calls to guest functions may be made through this context until it is dropped. -/// Once dropped the underlying `SingleUseGuestCallContext` and associated `SingleUseSandbox` will be dropped -pub struct SingleUseMultiGuestCallContext { - call_context: SingleUseGuestCallContext, -} - -impl SingleUseMultiGuestCallContext { - fn new(call_context: SingleUseGuestCallContext) -> Self { - Self { call_context } - } - - /// Call the guest function called `func_name` with the given arguments - pub fn call( - &mut self, - func_name: &str, - func_ret_type: ReturnType, - args: Option>, - ) -> Result { - self.call_context - .call_internal(func_name, func_ret_type, args) - } -} - #[cfg(test)] mod tests { use std::sync::mpsc::sync_channel; @@ -203,13 +109,9 @@ mod tests { }; use hyperlight_testing::simple_guest_as_string; - use crate::func::call_ctx::SingleUseMultiGuestCallContext; use crate::sandbox_state::sandbox::EvolvableSandbox; use crate::sandbox_state::transition::Noop; - use crate::{ - GuestBinary, HyperlightError, MultiUseSandbox, Result, SingleUseSandbox, - UninitializedSandbox, - }; + use crate::{GuestBinary, HyperlightError, MultiUseSandbox, Result, UninitializedSandbox}; fn new_uninit() -> Result { let path = simple_guest_as_string().map_err(|e| { @@ -218,68 +120,6 @@ mod tests { UninitializedSandbox::new(GuestBinary::FilePath(path), None, None, None) } - /// Test to create a `SingleUseSandbox`, then call several guest - /// functions sequentially. - #[test] - fn singleusesandbox_single_call() { - let calls = [ - ( - "StackAllocate", - ReturnType::Int, - Some(vec![ParameterValue::Int(1)]), - ReturnValue::Int(1), - ), - ( - "CallMalloc", - ReturnType::Int, - Some(vec![ParameterValue::Int(200)]), - ReturnValue::Int(200), - ), - ]; - - for call in calls.iter() { - let sbox: SingleUseSandbox = new_uninit().unwrap().evolve(Noop::default()).unwrap(); - let ctx = sbox.new_call_context(); - let res = ctx.call(call.0, call.1, call.2.clone()).unwrap(); - assert_eq!(call.3, res); - } - } - - #[test] - fn singleusesandbox_multi_call() { - let calls = [ - ( - "StackAllocate", - ReturnType::Int, - Some(vec![ParameterValue::Int(1)]), - ReturnValue::Int(1), - ), - ( - "CallMalloc", - ReturnType::Int, - Some(vec![ParameterValue::Int(200)]), - ReturnValue::Int(200), - ), - ]; - - let sbox: SingleUseSandbox = new_uninit().unwrap().evolve(Noop::default()).unwrap(); - let ctx = sbox.new_call_context(); - - let callback_closure = |ctx: &mut SingleUseMultiGuestCallContext| { - let mut res: ReturnValue = ReturnValue::Int(0); - for call in calls.iter() { - res = ctx - .call(call.0, call.1, call.2.clone()) - .expect("failed to call guest function"); - assert_eq!(call.3, res); - } - Ok(res) - }; - - let res = ctx.call_from_func(callback_closure).unwrap(); - assert_eq!(calls.last().unwrap().3, res); - } - /// Test to create a `MultiUseSandbox`, then call several guest functions /// on it across different threads. /// diff --git a/src/hyperlight_host/src/func/guest_dispatch.rs b/src/hyperlight_host/src/func/guest_dispatch.rs index 06a41396c..a1762699d 100644 --- a/src/hyperlight_host/src/func/guest_dispatch.rs +++ b/src/hyperlight_host/src/func/guest_dispatch.rs @@ -111,15 +111,13 @@ mod tests { use hyperlight_testing::{callback_guest_as_string, simple_guest_as_string}; use super::*; - use crate::func::call_ctx::{MultiUseGuestCallContext, SingleUseGuestCallContext}; + use crate::func::call_ctx::MultiUseGuestCallContext; use crate::func::host_functions::HostFunction0; use crate::sandbox::is_hypervisor_present; use crate::sandbox::uninitialized::GuestBinary; use crate::sandbox_state::sandbox::EvolvableSandbox; use crate::sandbox_state::transition::Noop; - use crate::{ - new_error, HyperlightError, MultiUseSandbox, Result, SingleUseSandbox, UninitializedSandbox, - }; + use crate::{new_error, HyperlightError, MultiUseSandbox, Result, UninitializedSandbox}; // simple function fn test_function0(_: MultiUseGuestCallContext) -> Result { @@ -129,7 +127,7 @@ mod tests { struct GuestStruct; // function that return type unsupported by the host - fn test_function1(_: SingleUseGuestCallContext) -> Result { + fn test_function1(_: MultiUseGuestCallContext) -> Result { Ok(GuestStruct) } @@ -246,7 +244,7 @@ mod tests { // test_function1 { let usbox = uninitialized_sandbox(); - let sandbox: SingleUseSandbox = usbox + let sandbox: MultiUseSandbox = usbox .evolve(Noop::default()) .expect("Failed to initialize sandbox"); let result = test_function1(sandbox.new_call_context()); diff --git a/src/hyperlight_host/src/lib.rs b/src/hyperlight_host/src/lib.rs index 2dac703fe..5921889d6 100644 --- a/src/hyperlight_host/src/lib.rs +++ b/src/hyperlight_host/src/lib.rs @@ -101,9 +101,6 @@ pub use sandbox::uninitialized::GuestBinary; pub use sandbox::MultiUseSandbox; /// The re-export for the `SandboxRunOptions` type pub use sandbox::SandboxRunOptions; -/// A sandbox that can be used at most once to call a guest function, and -/// then must be discarded. -pub use sandbox::SingleUseSandbox; /// The re-export for the `UninitializedSandbox` type pub use sandbox::UninitializedSandbox; diff --git a/src/hyperlight_host/src/sandbox/initialized_single_use.rs b/src/hyperlight_host/src/sandbox/initialized_single_use.rs deleted file mode 100644 index 27e5be0c5..000000000 --- a/src/hyperlight_host/src/sandbox/initialized_single_use.rs +++ /dev/null @@ -1,206 +0,0 @@ -/* -Copyright 2024 The Hyperlight Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -use hyperlight_common::flatbuffer_wrappers::function_types::{ - ParameterValue, ReturnType, ReturnValue, -}; -use tracing::{instrument, Span}; - -use super::{MemMgrWrapper, WrapperGetter}; -use crate::func::call_ctx::SingleUseGuestCallContext; -use crate::hypervisor::hypervisor_handler::HypervisorHandler; -use crate::mem::shared_mem::HostSharedMemory; -use crate::sandbox_state::sandbox::Sandbox; -use crate::Result; - -/// A sandbox implementation that supports calling no more than 1 guest -/// function -pub struct SingleUseSandbox { - pub(super) mem_mgr: MemMgrWrapper, - hv_handler: HypervisorHandler, -} - -// We need to implement drop to join the -// threads, because, otherwise, we will -// be leaking a thread with every -// sandbox that is dropped. This was initially -// caught by our benchmarks that created a ton of -// sandboxes and caused the system to run out of -// resources. Now, this is covered by the test: -// `create_1000_sandboxes`. -impl Drop for SingleUseSandbox { - fn drop(&mut self) { - match self.hv_handler.kill_hypervisor_handler_thread() { - Ok(_) => {} - Err(e) => { - log::error!("[POTENTIAL THREAD LEAK] Potentially failed to kill hypervisor handler thread when dropping MultiUseSandbox: {:?}", e); - } - } - } -} - -impl SingleUseSandbox { - /// Move an `UninitializedSandbox` into a new `SingleUseSandbox` instance. - /// - /// This function is not equivalent to doing an `evolve` from uninitialized - /// to initialized. It only copies values from `val` to the new returned - /// `SingleUseSandbox` instance, and does not execute any initialization - /// logic on the guest. We want to ensure that, when users request to - /// convert an `UninitializedSandbox` to a `SingleUseSandbox`, - /// initialization logic is always run, so we are purposely making this - /// function not publicly exposed. Finally, although it looks like it should be - /// in a `From` implementation, it is purposely not, because external - /// users would then see it and be able to use it. - #[instrument(skip_all, parent = Span::current(), level = "Trace")] - pub(super) fn from_uninit( - mgr: MemMgrWrapper, - hv_handler: HypervisorHandler, - ) -> SingleUseSandbox { - Self { - mem_mgr: mgr, - hv_handler, - } - } - - /// Create a new `SingleUseCallContext` . The main purpose of the - /// a SingleUseSandbox is to allow multiple calls to guest functions from within a callback function. - /// - /// Since this function consumes `self`, the returned - /// `SingleUseGuestCallContext` is guaranteed mutual exclusion for calling - /// functions within the sandbox. - /// - /// Since this is a `SingleUseSandbox`, the returned - /// context cannot be converted back into the original `SingleUseSandbox`. - /// When it's dropped, all the resources of the context and sandbox are - /// released at once. - /// - /// Example usage (compiled as a "no_run" doctest since the test binary - /// will not be found): - /// - /// ```no_run - /// use hyperlight_host::sandbox::{UninitializedSandbox, SingleUseSandbox}; - /// use hyperlight_common::flatbuffer_wrappers::function_types::{ReturnType, ParameterValue, ReturnValue}; - /// use hyperlight_host::sandbox_state::sandbox::EvolvableSandbox; - /// use hyperlight_host::sandbox_state::transition::Noop; - /// use hyperlight_host::GuestBinary; - /// - /// // First, create a new uninitialized sandbox, then evolve it to become - /// // an initialized, single-use one. - /// let u_sbox = UninitializedSandbox::new( - /// GuestBinary::FilePath("some_guest_binary".to_string()), - /// None, - /// None, - /// None, - /// ).unwrap(); - /// let sbox: SingleUseSandbox = u_sbox.evolve(Noop::default()).unwrap(); - /// // Next, create a new call context from the single-use sandbox. - /// // After this line, your code will not compile if you try to use the - /// // original `sbox` variable. - /// let mut ctx = sbox.new_call_context(); - /// - /// - /// // Create a closure to call multiple guest functions usings the contexts - /// // call_from-func method. Assues that the loaded binary - /// // ("some_guest_binary") has a function therein called "SomeGuestFunc" and another called "SomeOtherGuestFunc" - /// // that take a single integer argument and return an integer. - /// - /// - /// let result = ctx.call_from_func( |call_ctx| { - /// - /// match call_ctx.call( - /// "SomeGuestFunc", - /// ReturnType::Int, - /// Some(vec![ParameterValue::Int(1)]) - /// ) { - /// Ok(ReturnValue::Int(i)) => println!( - /// "got successful return value {}", - /// i, - /// ), - /// other => panic!( - /// "failed to get return value as expected ({:?})", - /// other, - /// ), - /// } - /// - /// match call_ctx.call( - /// "SomeOtherGuestFunc", - /// ReturnType::Int, - /// Some(vec![ParameterValue::Int(1)]) - /// ) { - /// Ok(ReturnValue::Int(i)) => println!( - /// "got successful return value {}", - /// i, - /// ), - /// other => panic!( - /// "failed to get return value as expected ({:?})", - /// other, - /// ), - /// } - /// - /// Ok(ReturnValue::Int(0)) - /// - /// }); - /// - /// // After the call context is dropped, the sandbox is also dropped. - /// ``` - #[instrument(skip_all, parent = Span::current())] - pub fn new_call_context(self) -> SingleUseGuestCallContext { - SingleUseGuestCallContext::start(self) - } - - /// Convenience for the following: - /// - /// `self.new_call_context().call(name, ret, args)` - #[instrument(err(Debug), skip(self, args), parent = Span::current())] - pub fn call_guest_function_by_name( - self, - name: &str, - ret: ReturnType, - args: Option>, - ) -> Result { - self.new_call_context().call(name, ret, args) - } -} - -impl WrapperGetter for SingleUseSandbox { - fn get_mgr_wrapper(&self) -> &MemMgrWrapper { - &self.mem_mgr - } - fn get_mgr_wrapper_mut(&mut self) -> &mut MemMgrWrapper { - &mut self.mem_mgr - } - fn get_hv_handler(&self) -> &HypervisorHandler { - &self.hv_handler - } - fn get_hv_handler_mut(&mut self) -> &mut HypervisorHandler { - &mut self.hv_handler - } -} - -impl Sandbox for SingleUseSandbox { - #[instrument(skip_all, parent = Span::current(), level = "Trace")] - fn check_stack_guard(&self) -> Result { - self.mem_mgr.check_stack_guard() - } -} - -impl std::fmt::Debug for SingleUseSandbox { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("SingleUseSandbox") - .field("stack_guard", &self.mem_mgr.get_stack_cookie()) - .finish() - } -} diff --git a/src/hyperlight_host/src/sandbox/mod.rs b/src/hyperlight_host/src/sandbox/mod.rs index baf1360cc..a8e70e995 100644 --- a/src/hyperlight_host/src/sandbox/mod.rs +++ b/src/hyperlight_host/src/sandbox/mod.rs @@ -23,9 +23,6 @@ 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 initialized sandboxes that can -/// call 0 or 1 guest functions, but no more -pub mod initialized_single_use; /// A container to leak, store and manage outb handlers for in-process /// executions. On non-in-process executions (e.g. windows without /// in-process mode turned on, or linux), the same container is just @@ -57,8 +54,6 @@ use std::collections::HashMap; pub use config::SandboxConfiguration; /// Re-export for the `MultiUseSandbox` type pub use initialized_multi_use::MultiUseSandbox; -/// Re-export for `SingleUseSandbox` type -pub use initialized_single_use::SingleUseSandbox; /// Re-export for `SandboxRunOptions` type pub use run_options::SandboxRunOptions; use tracing::{instrument, Span}; diff --git a/src/hyperlight_host/src/sandbox/run_options.rs b/src/hyperlight_host/src/sandbox/run_options.rs index f8fdf2150..29a7c5ddb 100644 --- a/src/hyperlight_host/src/sandbox/run_options.rs +++ b/src/hyperlight_host/src/sandbox/run_options.rs @@ -17,8 +17,7 @@ limitations under the License. use tracing::{instrument, Span}; /// Configuration options for setting up a new `UninitializedSandbox` and -/// subsequent inititialized sandboxes, including `MultiUseSandbox` and -/// `SingleUseSandbox`. +/// subsequent inititialized sandboxes, including `MultiUseSandbox`. /// /// A `SandboxRunOptions` instance must be created with either in-process /// or in-hypervisor execution mode, and then can optionally be augmented diff --git a/src/hyperlight_host/src/sandbox/uninitialized.rs b/src/hyperlight_host/src/sandbox/uninitialized.rs index 78997870e..7413ee965 100644 --- a/src/hyperlight_host/src/sandbox/uninitialized.rs +++ b/src/hyperlight_host/src/sandbox/uninitialized.rs @@ -25,7 +25,7 @@ use tracing::{instrument, Span}; use super::host_funcs::{default_writer_func, HostFuncsWrapper}; use super::mem_mgr::MemMgrWrapper; use super::run_options::SandboxRunOptions; -use super::uninitialized_evolve::{evolve_impl_multi_use, evolve_impl_single_use}; +use super::uninitialized_evolve::evolve_impl_multi_use; use crate::error::HyperlightError::GuestBinaryShouldBeAFile; use crate::func::host_functions::HostFunction1; use crate::mem::exe::ExeInfo; @@ -34,9 +34,7 @@ use crate::mem::shared_mem::ExclusiveSharedMemory; use crate::sandbox::SandboxConfiguration; use crate::sandbox_state::sandbox::EvolvableSandbox; use crate::sandbox_state::transition::Noop; -use crate::{ - log_build_details, log_then_return, new_error, MultiUseSandbox, Result, SingleUseSandbox, -}; +use crate::{log_build_details, log_then_return, new_error, MultiUseSandbox, Result}; /// A preliminary `Sandbox`, not yet ready to execute guest code. /// @@ -84,20 +82,6 @@ impl crate::sandbox_state::sandbox::Sandbox for UninitializedSandbox { } } -impl - EvolvableSandbox< - UninitializedSandbox, - SingleUseSandbox, - Noop, - > for UninitializedSandbox -{ - /// Evolve `self` to a `SingleUseSandbox` without any additional metadata. - #[instrument(err(Debug), skip_all, parent = Span::current(), level = "Trace")] - fn evolve(self, _: Noop) -> Result { - evolve_impl_single_use(self) - } -} - impl EvolvableSandbox< UninitializedSandbox, diff --git a/src/hyperlight_host/src/sandbox/uninitialized_evolve.rs b/src/hyperlight_host/src/sandbox/uninitialized_evolve.rs index 90dbd3ce8..ee48564f2 100644 --- a/src/hyperlight_host/src/sandbox/uninitialized_evolve.rs +++ b/src/hyperlight_host/src/sandbox/uninitialized_evolve.rs @@ -31,7 +31,7 @@ use crate::sandbox::mem_access::mem_access_handler_wrapper; use crate::sandbox::outb::outb_handler_wrapper; use crate::sandbox::{HostSharedMemory, MemMgrWrapper}; use crate::sandbox_state::sandbox::Sandbox; -use crate::{new_error, MultiUseSandbox, Result, SingleUseSandbox, UninitializedSandbox}; +use crate::{new_error, MultiUseSandbox, Result, UninitializedSandbox}; /// The implementation for evolving `UninitializedSandbox`es to /// `Sandbox`es. @@ -90,16 +90,6 @@ pub(super) fn evolve_impl_multi_use(u_sbox: UninitializedSandbox) -> Result Result { - evolve_impl(u_sbox, |_hf, hshm, hv_handler| { - // Its intentional not to snapshot state here. This is because - // single use sandboxes are not reusable and so there is no need - // to snapshot state as they cannot be devolved back to an uninitialized sandbox. - Ok(SingleUseSandbox::from_uninit(hshm, hv_handler)) - }) -} - #[instrument(err(Debug), skip_all, parent = Span::current(), level = "Trace")] fn hv_init( hshm: &MemMgrWrapper, diff --git a/src/hyperlight_host/src/sandbox_state/sandbox.rs b/src/hyperlight_host/src/sandbox_state/sandbox.rs index 258de8b2a..2ddde372b 100644 --- a/src/hyperlight_host/src/sandbox_state/sandbox.rs +++ b/src/hyperlight_host/src/sandbox_state/sandbox.rs @@ -43,7 +43,7 @@ pub trait Sandbox: Sized + Debug { /// `Ok(true)` in the same situation where the stack guard does match. /// - // NOTE: this is only needed for UninitializedSandbox, SingleUseSandbox, and MultiUseSandbox + // NOTE: this is only needed for UninitializedSandbox and MultiUseSandbox // Those are the only types that need implement this trait // The default implementation is provided so that types that implement Sandbox (e.g. JSSandbox) but do not need to implement this trait do not need to provide an implementation #[instrument(skip_all, parent = Span::current(), level= "Trace")] diff --git a/src/hyperlight_host/tests/integration_test.rs b/src/hyperlight_host/tests/integration_test.rs index a140ef904..7dfc5f2d2 100644 --- a/src/hyperlight_host/tests/integration_test.rs +++ b/src/hyperlight_host/tests/integration_test.rs @@ -22,7 +22,7 @@ use hyperlight_host::mem::memory_region::MemoryRegionFlags; use hyperlight_host::sandbox::SandboxConfiguration; use hyperlight_host::sandbox_state::sandbox::EvolvableSandbox; use hyperlight_host::sandbox_state::transition::Noop; -use hyperlight_host::{GuestBinary, HyperlightError, SingleUseSandbox, UninitializedSandbox}; +use hyperlight_host::{GuestBinary, HyperlightError, UninitializedSandbox}; use hyperlight_testing::{c_simple_guest_as_string, simple_guest_as_string}; pub mod common; // pub to disable dead_code warning @@ -33,7 +33,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, None, None); - let sbox1: SingleUseSandbox = uninit.unwrap().evolve(Noop::default()).unwrap(); + let mut sbox1 = uninit.unwrap().evolve(Noop::default()).unwrap(); let res = sbox1.call_guest_function_by_name( "PrintFourArgs", @@ -52,7 +52,7 @@ fn print_four_args_c_guest() { // Checks that guest can abort with a specific code. #[test] fn guest_abort() { - let sbox1: SingleUseSandbox = new_uninit().unwrap().evolve(Noop::default()).unwrap(); + let mut sbox1 = new_uninit().unwrap().evolve(Noop::default()).unwrap(); let error_code: u8 = 13; // this is arbitrary let res = sbox1 .call_guest_function_by_name( @@ -69,7 +69,7 @@ fn guest_abort() { #[test] fn guest_abort_with_context1() { - let sbox1: SingleUseSandbox = new_uninit().unwrap().evolve(Noop::default()).unwrap(); + let mut sbox1 = new_uninit().unwrap().evolve(Noop::default()).unwrap(); let res = sbox1 .call_guest_function_by_name( @@ -89,7 +89,7 @@ fn guest_abort_with_context1() { #[test] fn guest_abort_with_context2() { - let sbox1: SingleUseSandbox = new_uninit().unwrap().evolve(Noop::default()).unwrap(); + let mut sbox1 = new_uninit().unwrap().evolve(Noop::default()).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 @@ -147,7 +147,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, None, None); - let sbox1: SingleUseSandbox = uninit.unwrap().evolve(Noop::default()).unwrap(); + let mut sbox1 = uninit.unwrap().evolve(Noop::default()).unwrap(); let res = sbox1 .call_guest_function_by_name( @@ -168,7 +168,7 @@ fn guest_abort_c_guest() { #[test] fn guest_panic() { // this test is rust-specific - let sbox1: SingleUseSandbox = new_uninit_rust().unwrap().evolve(Noop::default()).unwrap(); + let mut sbox1 = new_uninit_rust().unwrap().evolve(Noop::default()).unwrap(); let res = sbox1 .call_guest_function_by_name( @@ -188,7 +188,7 @@ fn guest_panic() { #[test] fn guest_malloc() { // this test is rust-only - let sbox1: SingleUseSandbox = new_uninit_rust().unwrap().evolve(Noop::default()).unwrap(); + let mut sbox1 = new_uninit_rust().unwrap().evolve(Noop::default()).unwrap(); let size_to_allocate = 2000; let res = sbox1 @@ -203,7 +203,7 @@ fn guest_malloc() { #[test] fn guest_allocate_vec() { - let sbox1: SingleUseSandbox = new_uninit().unwrap().evolve(Noop::default()).unwrap(); + let mut sbox1 = new_uninit().unwrap().evolve(Noop::default()).unwrap(); let size_to_allocate = 2000; @@ -221,7 +221,7 @@ fn guest_allocate_vec() { // checks that malloc failures are captured correctly #[test] fn guest_malloc_abort() { - let sbox1: SingleUseSandbox = new_uninit_rust().unwrap().evolve(Noop::default()).unwrap(); + let mut sbox1 = new_uninit_rust().unwrap().evolve(Noop::default()).unwrap(); let size = 20000000; // some big number that should fail when allocated @@ -251,7 +251,7 @@ fn guest_malloc_abort() { None, ) .unwrap(); - let sbox2: SingleUseSandbox = uninit.evolve(Noop::default()).unwrap(); + let mut sbox2 = uninit.evolve(Noop::default()).unwrap(); let res = sbox2.call_guest_function_by_name( "CallMalloc", // uses the rust allocator to allocate a vector on heap @@ -269,7 +269,7 @@ fn guest_malloc_abort() { // checks that alloca works #[test] fn dynamic_stack_allocate() { - let sbox: SingleUseSandbox = new_uninit().unwrap().evolve(Noop::default()).unwrap(); + let mut sbox = new_uninit().unwrap().evolve(Noop::default()).unwrap(); let bytes = 10_000; // some low number that can be allocated on stack @@ -284,7 +284,7 @@ fn dynamic_stack_allocate() { // checks alloca fails with stackoverflow for large allocations #[test] fn dynamic_stack_allocate_overflow() { - let sbox1: SingleUseSandbox = new_uninit().unwrap().evolve(Noop::default()).unwrap(); + let mut sbox1 = new_uninit().unwrap().evolve(Noop::default()).unwrap(); // zero is handled as special case in guest, // will turn DEFAULT_GUEST_STACK_SIZE + 1 @@ -304,7 +304,7 @@ fn dynamic_stack_allocate_overflow() { // checks alloca fails with overflow when stack pointer overflows #[test] fn dynamic_stack_allocate_pointer_overflow() { - let sbox1: SingleUseSandbox = new_uninit_rust().unwrap().evolve(Noop::default()).unwrap(); + let mut sbox1 = new_uninit_rust().unwrap().evolve(Noop::default()).unwrap(); let bytes = 10 * 1024 * 1024; // 10Mb let res = sbox1 @@ -324,7 +324,7 @@ fn dynamic_stack_allocate_overflow_c_guest() { let path = c_simple_guest_as_string().unwrap(); let guest_path = GuestBinary::FilePath(path); let uninit = UninitializedSandbox::new(guest_path, None, None, None); - let sbox1: SingleUseSandbox = uninit.unwrap().evolve(Noop::default()).unwrap(); + let mut sbox1 = uninit.unwrap().evolve(Noop::default()).unwrap(); let bytes = 0; // zero is handled as special case in guest, will turn into large number @@ -342,7 +342,7 @@ fn dynamic_stack_allocate_overflow_c_guest() { // checks that a small buffer on stack works #[test] fn static_stack_allocate() { - let sbox1: SingleUseSandbox = new_uninit().unwrap().evolve(Noop::default()).unwrap(); + let mut sbox1 = new_uninit().unwrap().evolve(Noop::default()).unwrap(); let res = sbox1 .call_guest_function_by_name("SmallVar", ReturnType::Int, Some(Vec::new())) @@ -353,7 +353,7 @@ fn static_stack_allocate() { // checks that a huge buffer on stack fails with stackoverflow #[test] fn static_stack_allocate_overflow() { - let sbox1: SingleUseSandbox = new_uninit().unwrap().evolve(Noop::default()).unwrap(); + let mut sbox1 = new_uninit().unwrap().evolve(Noop::default()).unwrap(); let res = sbox1 .call_guest_function_by_name("LargeVar", ReturnType::Int, Some(Vec::new())) .unwrap_err(); @@ -363,7 +363,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 sbox1: SingleUseSandbox = new_uninit().unwrap().evolve(Noop::default()).unwrap(); + let mut sbox1 = new_uninit().unwrap().evolve(Noop::default()).unwrap(); let iterations = 1; @@ -397,7 +397,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 sbox1: SingleUseSandbox = new_uninit_rust().unwrap().evolve(Noop::default()).unwrap(); + let mut sbox1 = new_uninit_rust().unwrap().evolve(Noop::default()).unwrap(); let result = sbox1.call_guest_function_by_name( "test_write_raw_ptr", ReturnType::String, @@ -418,7 +418,7 @@ fn guard_page_check() { #[test] fn guard_page_check_2() { // this test is rust-guest only - let sbox1: SingleUseSandbox = new_uninit_rust().unwrap().evolve(Noop::default()).unwrap(); + let mut sbox1 = new_uninit_rust().unwrap().evolve(Noop::default()).unwrap(); let result = sbox1 .call_guest_function_by_name("InfiniteRecursion", ReturnType::Void, Some(vec![])) @@ -428,7 +428,7 @@ fn guard_page_check_2() { #[test] fn execute_on_stack() { - let sbox1: SingleUseSandbox = new_uninit().unwrap().evolve(Noop::default()).unwrap(); + let mut sbox1 = new_uninit().unwrap().evolve(Noop::default()).unwrap(); let result = sbox1 .call_guest_function_by_name("ExecuteOnStack", ReturnType::String, Some(vec![])) @@ -453,7 +453,7 @@ fn execute_on_stack() { #[test] #[ignore] // ran from Justfile because requires feature "executable_heap" fn execute_on_heap() { - let sbox1: SingleUseSandbox = new_uninit_rust().unwrap().evolve(Noop::default()).unwrap(); + let mut sbox1 = new_uninit_rust().unwrap().evolve(Noop::default()).unwrap(); let result = sbox1.call_guest_function_by_name("ExecuteOnHeap", ReturnType::String, Some(vec![])); @@ -478,7 +478,7 @@ fn execute_on_heap() { // checks that a recursive function with stack allocation eventually fails with stackoverflow #[test] fn recursive_stack_allocate_overflow() { - let sbox1: SingleUseSandbox = new_uninit().unwrap().evolve(Noop::default()).unwrap(); + let mut sbox1 = new_uninit().unwrap().evolve(Noop::default()).unwrap(); let iterations = 10; @@ -563,7 +563,7 @@ fn log_message() { fn log_test_messages() { for level in log::LevelFilter::iter() { - let sbox1: SingleUseSandbox = new_uninit().unwrap().evolve(Noop::default()).unwrap(); + let mut sbox1 = new_uninit().unwrap().evolve(Noop::default()).unwrap(); let message = format!("Hello from log_message level {}", level as i32); sbox1