From 53bf1ae3de48e50f511f15d5170d4ead6ca16d86 Mon Sep 17 00:00:00 2001 From: James Sturtevant Date: Tue, 24 Feb 2026 11:25:50 -0800 Subject: [PATCH 1/5] Remove host function definition region dependency Instead of using a shared memory region or a host function callback to provide host function definitions to the guest, the host now pushes the serialized definitions directly as a parameter to InitWasmRuntime. Signed-off-by: James Sturtevant --- CHANGELOG.md | 3 ++ Cargo.lock | 1 + Cargo.toml | 1 + src/hyperlight_wasm/Cargo.toml | 1 + .../src/sandbox/loaded_wasm_sandbox.rs | 23 +++++++++ .../src/sandbox/proto_wasm_sandbox.rs | 47 ++++++++++++++++++- .../src/sandbox/sandbox_builder.rs | 8 ---- src/wasm_runtime/src/hostfuncs.rs | 4 -- src/wasm_runtime/src/module.rs | 33 +++++++++++-- 9 files changed, 102 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e0792293..eca48d8b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ## [Prerelease] - Unreleased +### Changed +- **BREAKING CHANGE:** Removed `SandboxBuilder::with_function_definition_size`. Host function definitions are now pushed to the guest at runtime load time instead of using a separate memory region. (#388) + ## [v0.12.0] - 2025-12 ### Added diff --git a/Cargo.lock b/Cargo.lock index cb1c1fd9..e87483d8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1543,6 +1543,7 @@ dependencies = [ "env_logger", "examples_common", "goblin", + "hyperlight-common", "hyperlight-component-macro", "hyperlight-host", "junction", diff --git a/Cargo.toml b/Cargo.toml index b5ae1597..6959cb6e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,3 +14,4 @@ readme = "README.md" [workspace.dependencies] hyperlight-host = { version = "0.12.0", default-features = false, features = ["executable_heap", "init-paging"] } +hyperlight-common = { version = "0.12.0", default-features = false } diff --git a/src/hyperlight_wasm/Cargo.toml b/src/hyperlight_wasm/Cargo.toml index b091f863..a469c3d5 100644 --- a/src/hyperlight_wasm/Cargo.toml +++ b/src/hyperlight_wasm/Cargo.toml @@ -61,6 +61,7 @@ test = true [dependencies] hyperlight-host = { workspace = true } +hyperlight-common = { workspace = true } libc = { version = "0.2.182" } once_cell = "1.21.3" tracing = "0.1.44" diff --git a/src/hyperlight_wasm/src/sandbox/loaded_wasm_sandbox.rs b/src/hyperlight_wasm/src/sandbox/loaded_wasm_sandbox.rs index c926b989..30010878 100644 --- a/src/hyperlight_wasm/src/sandbox/loaded_wasm_sandbox.rs +++ b/src/hyperlight_wasm/src/sandbox/loaded_wasm_sandbox.rs @@ -425,6 +425,29 @@ mod tests { assert_eq!(r, 0); } + #[test] + fn test_load_module_fails_with_missing_host_function() { + // HostFunction.aot imports "HostFuncWithBufferAndLength" from "env". + // Loading it without registering that host function should fail + // at instantiation time (linker.instantiate) because the import + // cannot be satisfied. + let proto_wasm_sandbox = SandboxBuilder::new().build().unwrap(); + + let wasm_sandbox = proto_wasm_sandbox.load_runtime().unwrap(); + + let result: std::result::Result = { + let mod_path = get_wasm_module_path("HostFunction.aot").unwrap(); + wasm_sandbox.load_module(mod_path) + }; + + let err = result.unwrap_err(); + let err_msg = format!("{:?}", err); + assert!( + err_msg.contains("HostFuncWithBufferAndLength"), + "Error should mention the missing host function, got: {err_msg}" + ); + } + fn call_funcs( mut loaded_wasm_sandbox: LoadedWasmSandbox, iterations: i32, diff --git a/src/hyperlight_wasm/src/sandbox/proto_wasm_sandbox.rs b/src/hyperlight_wasm/src/sandbox/proto_wasm_sandbox.rs index 24a7a0f5..0d2e7eea 100644 --- a/src/hyperlight_wasm/src/sandbox/proto_wasm_sandbox.rs +++ b/src/hyperlight_wasm/src/sandbox/proto_wasm_sandbox.rs @@ -14,6 +14,9 @@ See the License for the specific language governing permissions and limitations under the License. */ +use hyperlight_common::flatbuffer_wrappers::function_types::{ParameterType, ReturnType}; +use hyperlight_common::flatbuffer_wrappers::host_function_definition::HostFunctionDefinition; +use hyperlight_common::flatbuffer_wrappers::host_function_details::HostFunctionDetails; use hyperlight_host::func::{HostFunction, ParameterTuple, Registerable, SupportedReturnType}; use hyperlight_host::sandbox::config::SandboxConfiguration; use hyperlight_host::{GuestBinary, Result, UninitializedSandbox, new_error}; @@ -31,6 +34,8 @@ use crate::build_info::BuildInfo; /// With that `WasmSandbox` you can load a Wasm module through the `load_module` method and get a `LoadedWasmSandbox` which can then execute functions defined in the Wasm module. pub struct ProtoWasmSandbox { pub(super) inner: Option, + /// Tracks registered host function definitions for pushing to the guest at load time + host_function_definitions: Vec, } impl Registerable for ProtoWasmSandbox { @@ -39,6 +44,13 @@ impl Registerable for ProtoWasmSandbox { name: &str, hf: impl Into>, ) -> Result<()> { + // Track the host function definition for pushing to guest at load time + self.host_function_definitions.push(HostFunctionDefinition { + function_name: name.to_string(), + parameter_types: Some(Args::TYPE.to_vec()), + return_type: Output::TYPE, + }); + self.inner .as_mut() .ok_or(new_error!("inner sandbox was none")) @@ -65,7 +77,18 @@ impl ProtoWasmSandbox { let inner = UninitializedSandbox::new(guest_binary, cfg)?; metrics::gauge!(METRIC_ACTIVE_PROTO_WASM_SANDBOXES).increment(1); metrics::counter!(METRIC_TOTAL_PROTO_WASM_SANDBOXES).increment(1); - Ok(Self { inner: Some(inner) }) + + // HostPrint is always registered by UninitializedSandbox, so include it by default + let host_function_definitions = vec![HostFunctionDefinition { + function_name: "HostPrint".to_string(), + parameter_types: Some(vec![ParameterType::String]), + return_type: ReturnType::Int, + }]; + + Ok(Self { + inner: Some(inner), + host_function_definitions, + }) } /// Load the Wasm runtime into the sandbox and return a `WasmSandbox` @@ -75,12 +98,22 @@ impl ProtoWasmSandbox { /// The returned `WasmSandbox` can be then be cached and used to load a different Wasm module. /// pub fn load_runtime(mut self) -> Result { + // Serialize host function definitions to push to the guest during InitWasmRuntime + let host_function_definitions = HostFunctionDetails { + host_functions: Some(std::mem::take(&mut self.host_function_definitions)), + }; + + let host_function_definitions_bytes: Vec = (&host_function_definitions) + .try_into() + .map_err(|e| new_error!("Failed to serialize host function details: {:?}", e))?; + let mut sandbox = match self.inner.take() { Some(s) => s.evolve()?, None => return Err(new_error!("No inner sandbox found.")), }; - let res: i32 = sandbox.call("InitWasmRuntime", ())?; + // Pass host function definitions to the guest as a parameter + let res: i32 = sandbox.call("InitWasmRuntime", (host_function_definitions_bytes,))?; if res != 0 { return Err(new_error!( "InitWasmRuntime Failed with error code {:?}", @@ -99,6 +132,13 @@ impl ProtoWasmSandbox { name: impl AsRef, host_func: impl Into>, ) -> Result<()> { + // Track the host function definition for pushing to guest at load time + self.host_function_definitions.push(HostFunctionDefinition { + function_name: name.as_ref().to_string(), + parameter_types: Some(Args::TYPE.to_vec()), + return_type: Output::TYPE, + }); + self.inner .as_mut() .ok_or(new_error!("inner sandbox was none"))? @@ -111,6 +151,9 @@ impl ProtoWasmSandbox { &mut self, print_func: impl Into>, ) -> Result<()> { + // HostPrint definition is already tracked from new() since + // UninitializedSandbox always registers a default HostPrint. + // This method only replaces the implementation, not the definition. self.inner .as_mut() .ok_or(new_error!("inner sandbox was none"))? diff --git a/src/hyperlight_wasm/src/sandbox/sandbox_builder.rs b/src/hyperlight_wasm/src/sandbox/sandbox_builder.rs index 0d2f7710..1c519f59 100644 --- a/src/hyperlight_wasm/src/sandbox/sandbox_builder.rs +++ b/src/hyperlight_wasm/src/sandbox/sandbox_builder.rs @@ -126,14 +126,6 @@ impl SandboxBuilder { self } - /// Set the size of the memory buffer that is made available - /// for serialising host function definitions the minimum value - /// is MIN_FUNCTION_DEFINITION_SIZE - pub fn with_function_definition_size(mut self, size: usize) -> Self { - self.config.set_host_function_definition_size(size); - self - } - /// Build the ProtoWasmSandbox pub fn build(self) -> Result { if !is_hypervisor_present() { diff --git a/src/wasm_runtime/src/hostfuncs.rs b/src/wasm_runtime/src/hostfuncs.rs index e468c557..ebf46df9 100644 --- a/src/wasm_runtime/src/hostfuncs.rs +++ b/src/wasm_runtime/src/hostfuncs.rs @@ -32,10 +32,6 @@ pub(crate) type HostFunctionDefinition = pub(crate) type HostFunctionDetails = hyperlight_common::flatbuffer_wrappers::host_function_details::HostFunctionDetails; -pub(crate) fn get_host_function_details() -> HostFunctionDetails { - hyperlight_guest_bin::host_comm::get_host_function_details() -} - pub(crate) fn hostfunc_type(d: &HostFunctionDefinition, e: &Engine) -> Result { let mut params = Vec::new(); let mut last_was_vec = false; diff --git a/src/wasm_runtime/src/module.rs b/src/wasm_runtime/src/module.rs index 195cf0ca..ba4fe082 100644 --- a/src/wasm_runtime/src/module.rs +++ b/src/wasm_runtime/src/module.rs @@ -96,7 +96,7 @@ pub fn guest_dispatch_function(function_call: FunctionCall) -> Result> { } #[instrument(skip_all, level = "Info")] -fn init_wasm_runtime() -> Result> { +fn init_wasm_runtime(function_call: &FunctionCall) -> Result> { let mut config = Config::new(); config.with_custom_code_memory(Some(alloc::sync::Arc::new(platform::WasmtimeCodeMemory {}))); #[cfg(gdb)] @@ -112,9 +112,32 @@ fn init_wasm_runtime() -> Result> { let mut linker = Linker::new(&engine); wasip1::register_handlers(&mut linker)?; - let hostfuncs = hostfuncs::get_host_function_details() - .host_functions - .unwrap_or_default(); + // Parse host function details pushed by the host as a parameter + let params = function_call.parameters.as_ref().ok_or_else(|| { + HyperlightGuestError::new( + ErrorCode::GuestFunctionParameterTypeMismatch, + "InitWasmRuntime: missing parameters".to_string(), + ) + })?; + + let bytes = match params.first() { + Some(ParameterValue::VecBytes(ref b)) => b, + _ => { + return Err(HyperlightGuestError::new( + ErrorCode::GuestFunctionParameterTypeMismatch, + "InitWasmRuntime: first parameter must be VecBytes".to_string(), + )) + } + }; + + let hfd: hostfuncs::HostFunctionDetails = bytes.as_slice().try_into().map_err(|e| { + HyperlightGuestError::new( + ErrorCode::GuestError, + alloc::format!("Failed to parse host function details: {:?}", e), + ) + })?; + let hostfuncs = hfd.host_functions.unwrap_or_default(); + for hostfunc in hostfuncs.iter() { let captured = hostfunc.clone(); linker.func_new( @@ -210,7 +233,7 @@ pub extern "C" fn hyperlight_main() { register_function(GuestFunctionDefinition::new( "InitWasmRuntime".to_string(), - vec![], + vec![ParameterType::VecBytes], ReturnType::Int, init_wasm_runtime as usize, )); From 011200186deffc9eeee6e3dbe44b538b1981d029 Mon Sep 17 00:00:00 2001 From: James Sturtevant Date: Tue, 24 Feb 2026 11:44:06 -0800 Subject: [PATCH 2/5] Add [workspace] to excluded packages for worktree compatibility rust_wasm_samples, hyperlight_wasm_macro, and component_sample were missing empty [workspace] tables in their Cargo.toml files. Without this, Cargo resolves to the main checkout's workspace root when run from a git worktree, causing 'believes it's in a workspace' errors. wasm_runtime already had this marker. Signed-off-by: James Sturtevant --- src/component_sample/Cargo.toml | 1 + src/hyperlight_wasm_macro/Cargo.toml | 2 ++ src/rust_wasm_samples/Cargo.toml | 2 ++ src/wasm_runtime/src/component.rs | 2 +- 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/component_sample/Cargo.toml b/src/component_sample/Cargo.toml index 43ebd181..8f305af4 100644 --- a/src/component_sample/Cargo.toml +++ b/src/component_sample/Cargo.toml @@ -18,3 +18,4 @@ world = "example" [package.metadata.component.target.dependencies] +[workspace] # indicate that this crate is not part of any workspace diff --git a/src/hyperlight_wasm_macro/Cargo.toml b/src/hyperlight_wasm_macro/Cargo.toml index 19716bb2..b44fde5e 100644 --- a/src/hyperlight_wasm_macro/Cargo.toml +++ b/src/hyperlight_wasm_macro/Cargo.toml @@ -17,3 +17,5 @@ syn = { version = "2.0.117" } itertools = { version = "0.14.0" } prettyplease = { version = "0.2.37" } hyperlight-component-util = { version = "0.12.0" } + +[workspace] # indicate that this crate is not part of any workspace diff --git a/src/rust_wasm_samples/Cargo.toml b/src/rust_wasm_samples/Cargo.toml index 383d2472..b5684eec 100644 --- a/src/rust_wasm_samples/Cargo.toml +++ b/src/rust_wasm_samples/Cargo.toml @@ -14,5 +14,7 @@ opt-level = 'z' strip = true +[workspace] # indicate that this crate is not part of any workspace + [dependencies] diff --git a/src/wasm_runtime/src/component.rs b/src/wasm_runtime/src/component.rs index de07296a..f6439c3f 100644 --- a/src/wasm_runtime/src/component.rs +++ b/src/wasm_runtime/src/component.rs @@ -130,7 +130,7 @@ pub extern "C" fn hyperlight_main() { register_function(GuestFunctionDefinition::new( "InitWasmRuntime".to_string(), - vec![], + vec![ParameterType::VecBytes], ReturnType::Int, init_wasm_runtime as usize, )); From 2610e46aafa92aef80d0701a19f3a05ef96d3aea Mon Sep 17 00:00:00 2001 From: James Sturtevant Date: Mon, 2 Mar 2026 17:59:05 -0800 Subject: [PATCH 3/5] Address feedback Signed-off-by: James Sturtevant --- .../src/sandbox/proto_wasm_sandbox.rs | 67 ++++++++++++------- src/wasm_runtime/src/module.rs | 8 ++- 2 files changed, 50 insertions(+), 25 deletions(-) diff --git a/src/hyperlight_wasm/src/sandbox/proto_wasm_sandbox.rs b/src/hyperlight_wasm/src/sandbox/proto_wasm_sandbox.rs index 0d2e7eea..91c5ec4b 100644 --- a/src/hyperlight_wasm/src/sandbox/proto_wasm_sandbox.rs +++ b/src/hyperlight_wasm/src/sandbox/proto_wasm_sandbox.rs @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +use std::collections::HashMap; + use hyperlight_common::flatbuffer_wrappers::function_types::{ParameterType, ReturnType}; use hyperlight_common::flatbuffer_wrappers::host_function_definition::HostFunctionDefinition; use hyperlight_common::flatbuffer_wrappers::host_function_details::HostFunctionDetails; @@ -34,8 +36,7 @@ use crate::build_info::BuildInfo; /// With that `WasmSandbox` you can load a Wasm module through the `load_module` method and get a `LoadedWasmSandbox` which can then execute functions defined in the Wasm module. pub struct ProtoWasmSandbox { pub(super) inner: Option, - /// Tracks registered host function definitions for pushing to the guest at load time - host_function_definitions: Vec, + host_function_definitions: HashMap, } impl Registerable for ProtoWasmSandbox { @@ -44,17 +45,15 @@ impl Registerable for ProtoWasmSandbox { name: &str, hf: impl Into>, ) -> Result<()> { - // Track the host function definition for pushing to guest at load time - self.host_function_definitions.push(HostFunctionDefinition { - function_name: name.to_string(), - parameter_types: Some(Args::TYPE.to_vec()), - return_type: Output::TYPE, - }); - self.inner .as_mut() .ok_or(new_error!("inner sandbox was none")) - .and_then(|sb| sb.register(name, hf)) + .and_then(|sb| sb.register(name, hf))?; + + // Track the host function definition for pushing to guest at load time. + // matching hyperlight-core's FunctionRegistry behavior. + self.track_host_function_definition(name, Args::TYPE, Output::TYPE); + Ok(()) } } @@ -79,11 +78,15 @@ impl ProtoWasmSandbox { metrics::counter!(METRIC_TOTAL_PROTO_WASM_SANDBOXES).increment(1); // HostPrint is always registered by UninitializedSandbox, so include it by default - let host_function_definitions = vec![HostFunctionDefinition { - function_name: "HostPrint".to_string(), - parameter_types: Some(vec![ParameterType::String]), - return_type: ReturnType::Int, - }]; + let mut host_function_definitions = HashMap::new(); + host_function_definitions.insert( + "HostPrint".to_string(), + HostFunctionDefinition { + function_name: "HostPrint".to_string(), + parameter_types: Some(vec![ParameterType::String]), + return_type: ReturnType::Int, + }, + ); Ok(Self { inner: Some(inner), @@ -100,7 +103,11 @@ impl ProtoWasmSandbox { pub fn load_runtime(mut self) -> Result { // Serialize host function definitions to push to the guest during InitWasmRuntime let host_function_definitions = HostFunctionDetails { - host_functions: Some(std::mem::take(&mut self.host_function_definitions)), + host_functions: Some( + std::mem::take(&mut self.host_function_definitions) + .into_values() + .collect(), + ), }; let host_function_definitions_bytes: Vec = (&host_function_definitions) @@ -132,17 +139,29 @@ impl ProtoWasmSandbox { name: impl AsRef, host_func: impl Into>, ) -> Result<()> { - // Track the host function definition for pushing to guest at load time - self.host_function_definitions.push(HostFunctionDefinition { - function_name: name.as_ref().to_string(), - parameter_types: Some(Args::TYPE.to_vec()), - return_type: Output::TYPE, - }); - self.inner .as_mut() .ok_or(new_error!("inner sandbox was none"))? - .register(name, host_func) + .register(&name, host_func)?; + + self.track_host_function_definition(name.as_ref(), Args::TYPE, Output::TYPE); + Ok(()) + } + + fn track_host_function_definition( + &mut self, + name: &str, + parameter_types: &[ParameterType], + return_type: ReturnType, + ) { + self.host_function_definitions.insert( + name.to_string(), + HostFunctionDefinition { + function_name: name.to_string(), + parameter_types: Some(parameter_types.to_vec()), + return_type, + }, + ); } /// Register the given host printing function `print_func` with `self`. diff --git a/src/wasm_runtime/src/module.rs b/src/wasm_runtime/src/module.rs index ba4fe082..0cd6819a 100644 --- a/src/wasm_runtime/src/module.rs +++ b/src/wasm_runtime/src/module.rs @@ -122,12 +122,18 @@ fn init_wasm_runtime(function_call: &FunctionCall) -> Result> { let bytes = match params.first() { Some(ParameterValue::VecBytes(ref b)) => b, - _ => { + Some(_) => { return Err(HyperlightGuestError::new( ErrorCode::GuestFunctionParameterTypeMismatch, "InitWasmRuntime: first parameter must be VecBytes".to_string(), )) } + None => { + return Err(HyperlightGuestError::new( + ErrorCode::GuestFunctionParameterTypeMismatch, + "InitWasmRuntime: expected 1 parameter, got 0".to_string(), + )) + } }; let hfd: hostfuncs::HostFunctionDetails = bytes.as_slice().try_into().map_err(|e| { From fdc9d14e31b6cf2ec7d9755ac8483bd8d5931c3b Mon Sep 17 00:00:00 2001 From: James Sturtevant Date: Fri, 6 Mar 2026 14:05:47 -0800 Subject: [PATCH 4/5] Upgrade to Hyperlight 0.13 Signed-off-by: James Sturtevant --- Cargo.lock | 213 +++++++++++------- Cargo.toml | 6 +- src/hyperlight_wasm/Cargo.toml | 2 +- .../examples/component_example/main.rs | 2 +- .../examples/helloworld/main.rs | 2 +- .../examples/interruption/main.rs | 2 +- .../src/sandbox/loaded_wasm_sandbox.rs | 10 +- .../src/sandbox/sandbox_builder.rs | 20 +- .../src/sandbox/wasm_sandbox.rs | 30 +-- src/hyperlight_wasm_macro/Cargo.lock | 87 +++++-- src/hyperlight_wasm_macro/Cargo.toml | 4 +- src/hyperlight_wasm_macro/src/lib.rs | 2 +- src/hyperlight_wasm_macro/src/wasmguest.rs | 4 +- src/wasm_runtime/Cargo.lock | 111 ++++----- src/wasm_runtime/Cargo.toml | 8 +- src/wasm_runtime/src/component.rs | 12 +- src/wasm_runtime/src/module.rs | 17 +- src/wasm_runtime/src/platform.rs | 34 ++- 18 files changed, 338 insertions(+), 228 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e87483d8..51a4e034 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -194,7 +194,7 @@ version = "0.72.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "993776b509cfb49c750f11b8f07a46fa23e0a1386ffc01fb1e7d343efc387895" dependencies = [ - "bitflags 2.10.0", + "bitflags 2.11.0", "cexpr", "clang-sys", "itertools 0.13.0", @@ -216,9 +216,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.10.0" +version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3" +checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af" [[package]] name = "blake3" @@ -231,7 +231,7 @@ dependencies = [ "cc", "cfg-if", "constant_time_eq", - "cpufeatures", + "cpufeatures 0.2.17", ] [[package]] @@ -331,7 +331,7 @@ dependencies = [ "serde", "serde-untagged", "serde-value", - "thiserror 2.0.17", + "thiserror 2.0.18", "toml 0.9.12+spec-1.1.0", "unicode-xid", "url", @@ -348,7 +348,7 @@ dependencies = [ "semver", "serde", "serde_json", - "thiserror 2.0.17", + "thiserror 2.0.18", ] [[package]] @@ -390,6 +390,17 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" +[[package]] +name = "chacha20" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f8d983286843e49675a4b7a2d174efe136dc93a18d69130dd18198a6c167601" +dependencies = [ + "cfg-if", + "cpufeatures 0.3.0", + "rand_core 0.10.0", +] + [[package]] name = "chrono" version = "0.4.44" @@ -496,7 +507,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fa961b519f0b462e3a3b4a34b64d119eeaca1d59af726fe450bbba07a9fc0a1" dependencies = [ - "thiserror 2.0.17", + "thiserror 2.0.18", ] [[package]] @@ -569,6 +580,15 @@ dependencies = [ "libc", ] +[[package]] +name = "cpufeatures" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b2a41393f66f16b0823bb79094d54ac5fbd34ab292ddafb9a0456ac9f87d201" +dependencies = [ + "libc", +] + [[package]] name = "cranelift-assembler-x64" version = "0.123.6" @@ -1000,11 +1020,11 @@ checksum = "52051878f80a721bb68ebfbc930e07b65ba72f2da88968ea5c06fd6ca3d3a127" [[package]] name = "flatbuffers" -version = "25.9.23" +version = "25.12.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09b6620799e7340ebd9968d2e0708eb82cf1971e9a16821e2091b6d6e475eed5" +checksum = "35f6839d7b3b98adde531effaf34f0c2badc6f4735d26fe74709d8e513a96ef3" dependencies = [ - "bitflags 2.10.0", + "bitflags 2.11.0", "rustc_version", ] @@ -1116,11 +1136,11 @@ dependencies = [ [[package]] name = "gdbstub" -version = "0.7.8" +version = "0.7.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72742d2b395902caf8a5d520d0dd3334ba6d1138938429200e58d5174e275f3f" +checksum = "6bf845b08f7c2ef3b5ad19f80779d43ae20d278652b91bb80adda65baf2d8ed6" dependencies = [ - "bitflags 2.10.0", + "bitflags 2.11.0", "cfg-if", "log", "managed", @@ -1180,6 +1200,7 @@ dependencies = [ "cfg-if", "libc", "r-efi", + "rand_core 0.10.0", "wasip2", "wasip3", ] @@ -1201,7 +1222,7 @@ version = "0.20.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7b88256088d75a56f8ecfa070513a775dd9107f6530ef14919dac831af9cfe2b" dependencies = [ - "bitflags 2.10.0", + "bitflags 2.11.0", "libc", "libgit2-sys", "log", @@ -1280,11 +1301,13 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.16.0" +version = "0.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5419bdc4f6a9207fbeba6d11b604d481addf78ecd10c11ad51e76c2f6482748d" +checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" dependencies = [ "foldhash 0.2.0", + "serde", + "serde_core", ] [[package]] @@ -1424,23 +1447,24 @@ dependencies = [ [[package]] name = "hyperlight-common" -version = "0.12.0" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98f80e9aba9fce2a899c9ff0c62dd39cd479fa2f22ef578faed1d510c5becf94" +checksum = "725ce602c72dce1d83a87f98f3731e7db62f5ca7e1a255eea875e9bad408766f" dependencies = [ "anyhow", "flatbuffers", "log", "spin", - "thiserror 2.0.17", + "thiserror 2.0.18", "tracing", + "tracing-core", ] [[package]] name = "hyperlight-component-macro" -version = "0.12.0" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f217d5bbb0d02c9aac81374c3161af2a3a46a5379a604b0799534762a534d75a" +checksum = "951465558e3104075650d27461cca83b9b25115b3bf68c5e9399068d12fa9885" dependencies = [ "env_logger", "hyperlight-component-util", @@ -1449,29 +1473,29 @@ dependencies = [ "proc-macro2", "quote", "syn", - "wasmparser 0.243.0", + "wasmparser 0.245.1", ] [[package]] name = "hyperlight-component-util" -version = "0.12.0" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9b3299460dc5f39d37b8233c9aad7fc52c9548d96a76d35cdcc4f4f49ff6662" +checksum = "41501638fd9877bd0c2e0cbbd20ea55d5a532f4e45a870d626de56da9795fc9a" dependencies = [ "itertools 0.14.0", - "log", "prettyplease", "proc-macro2", "quote", "syn", - "wasmparser 0.243.0", + "tracing", + "wasmparser 0.245.1", ] [[package]] name = "hyperlight-guest-tracing" -version = "0.12.0" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df0f8d1e992b03c778c6c144f94a81060384e823781c84fae6228cba230d449c" +checksum = "266a23a83726db78b114fd177bda2833df84e9e2894e460aed7c7da9a0967a5e" dependencies = [ "hyperlight-common", "spin", @@ -1481,12 +1505,12 @@ dependencies = [ [[package]] name = "hyperlight-host" -version = "0.12.0" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f81d712e88785e8860be6b33048fc2c9ad6637864aa50fe95d0037cfa50a4fb" +checksum = "d37f39e7660b0b2173a07595e2049aa6215d73e74757be653ab4da99445e9714" dependencies = [ "anyhow", - "bitflags 2.10.0", + "bitflags 2.11.0", "blake3", "cfg-if", "cfg_aliases", @@ -1509,12 +1533,12 @@ dependencies = [ "mshv-ioctls", "opentelemetry", "page_size", - "rand", + "rand 0.10.0", "rust-embed", "serde_json", "sha256", "termcolor", - "thiserror 2.0.17", + "thiserror 2.0.18", "tracing", "tracing-core", "tracing-log", @@ -1529,7 +1553,7 @@ dependencies = [ [[package]] name = "hyperlight-wasm" -version = "0.12.0" +version = "0.13.0" dependencies = [ "anyhow", "blake3", @@ -1571,7 +1595,7 @@ dependencies = [ [[package]] name = "hyperlight-wasm-aot" -version = "0.12.0" +version = "0.13.0" dependencies = [ "cargo-util-schemas", "cargo_metadata", @@ -1714,12 +1738,12 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.12.0" +version = "2.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6717a8d2a5a929a1a2eb43a12812498ed141a0bcfb7e8f7844fbdbe4303bba9f" +checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017" dependencies = [ "equivalent", - "hashbrown 0.16.0", + "hashbrown 0.16.1", "serde", "serde_core", ] @@ -1839,7 +1863,7 @@ version = "0.24.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "333f77a20344a448f3f70664918135fddeb804e938f28a99d685bd92926e0b19" dependencies = [ - "bitflags 2.10.0", + "bitflags 2.11.0", "kvm-bindings", "libc", "vmm-sys-util", @@ -1897,7 +1921,7 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "416f7e718bdb06000964960ffa43b4335ad4012ae8b99060261aa4a8088d5ccb" dependencies = [ - "bitflags 2.10.0", + "bitflags 2.11.0", "libc", "redox_syscall", ] @@ -2007,7 +2031,7 @@ dependencies = [ "metrics-util", "quanta", "rustls", - "thiserror 2.0.17", + "thiserror 2.0.18", "tokio", "tracing", ] @@ -2021,13 +2045,13 @@ dependencies = [ "aho-corasick", "crossbeam-epoch", "crossbeam-utils", - "hashbrown 0.16.0", + "hashbrown 0.16.1", "indexmap", "metrics", "ordered-float 5.1.0", "quanta", "radix_trie", - "rand", + "rand 0.9.2", "rand_xoshiro", "sketches-ddsketch", ] @@ -2069,7 +2093,7 @@ checksum = "748f59f22dccd910080a6315fc692bd04bd8c94ae2fc346957ec34b7d985eaa0" dependencies = [ "libc", "mshv-bindings", - "thiserror 2.0.17", + "thiserror 2.0.18", "vmm-sys-util", ] @@ -2197,7 +2221,7 @@ dependencies = [ "futures-sink", "js-sys", "pin-project-lite", - "thiserror 2.0.17", + "thiserror 2.0.18", "tracing", ] @@ -2227,7 +2251,7 @@ dependencies = [ "opentelemetry_sdk", "prost", "reqwest", - "thiserror 2.0.17", + "thiserror 2.0.18", "tokio", "tonic", ] @@ -2262,8 +2286,8 @@ dependencies = [ "futures-util", "opentelemetry", "percent-encoding", - "rand", - "thiserror 2.0.17", + "rand 0.9.2", + "thiserror 2.0.18", "tokio", "tokio-stream", ] @@ -2475,9 +2499,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.103" +version = "1.0.106" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8" +checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" dependencies = [ "unicode-ident", ] @@ -2545,9 +2569,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.42" +version = "1.0.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a338cc41d27e6cc6dce6cefc13a0729dfbb81c262b1f519331575dd80ef3067f" +checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924" dependencies = [ "proc-macro2", ] @@ -2575,7 +2599,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1" dependencies = [ "rand_chacha", - "rand_core", + "rand_core 0.9.3", +] + +[[package]] +name = "rand" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc266eb313df6c5c09c1c7b1fbe2510961e5bcd3add930c1e31f7ed9da0feff8" +dependencies = [ + "chacha20", + "getrandom 0.4.1", + "rand_core 0.10.0", ] [[package]] @@ -2585,7 +2620,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" dependencies = [ "ppv-lite86", - "rand_core", + "rand_core 0.9.3", ] [[package]] @@ -2597,13 +2632,19 @@ dependencies = [ "getrandom 0.3.4", ] +[[package]] +name = "rand_core" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c8d0fd677905edcbeedbf2edb6494d676f0e98d54d5cf9bda0b061cb8fb8aba" + [[package]] name = "rand_xoshiro" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f703f4665700daf5512dcca5f43afa6af89f09db47fb56be587f80636bda2d41" dependencies = [ - "rand_core", + "rand_core 0.9.3", ] [[package]] @@ -2612,7 +2653,7 @@ version = "11.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "498cd0dc59d73224351ee52a95fee0f1a617a2eae0e7d9d720cc622c73a54186" dependencies = [ - "bitflags 2.10.0", + "bitflags 2.11.0", ] [[package]] @@ -2641,7 +2682,7 @@ version = "0.5.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" dependencies = [ - "bitflags 2.10.0", + "bitflags 2.11.0", ] [[package]] @@ -2652,7 +2693,7 @@ checksum = "a4e608c6638b9c18977b00b475ac1f28d14e84b27d8d42f70e0bf1e3dec127ac" dependencies = [ "getrandom 0.2.16", "libredox", - "thiserror 2.0.17", + "thiserror 2.0.18", ] [[package]] @@ -2748,9 +2789,9 @@ dependencies = [ [[package]] name = "rust-embed" -version = "8.9.0" +version = "8.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "947d7f3fad52b283d261c4c99a084937e2fe492248cb9a68a8435a861b8798ca" +checksum = "04113cb9355a377d83f06ef1f0a45b8ab8cd7d8b1288160717d66df5c7988d27" dependencies = [ "rust-embed-impl", "rust-embed-utils", @@ -2803,7 +2844,7 @@ version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cd15f8a2c5551a84d56efdc1cd049089e409ac19a3072d5037a17fd70719ff3e" dependencies = [ - "bitflags 2.10.0", + "bitflags 2.11.0", "errno", "libc", "linux-raw-sys", @@ -2919,7 +2960,7 @@ version = "3.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3297343eaf830f66ede390ea39da1d462b6b0c1b000f420d0a83f898bbbe6ef" dependencies = [ - "bitflags 2.10.0", + "bitflags 2.11.0", "core-foundation", "core-foundation-sys", "libc", @@ -3039,7 +3080,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" dependencies = [ "cfg-if", - "cpufeatures", + "cpufeatures 0.2.17", "digest", ] @@ -3149,9 +3190,9 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "syn" -version = "2.0.111" +version = "2.0.117" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "390cc9a294ab71bdb1aa2e99d13be9c753cd2d7bd6560c77118597410c4d2e87" +checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99" dependencies = [ "proc-macro2", "quote", @@ -3215,11 +3256,11 @@ dependencies = [ [[package]] name = "thiserror" -version = "2.0.17" +version = "2.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f63587ca0f12b72a0600bcba1d40081f830876000bb46dd2337a3051618f4fc8" +checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" dependencies = [ - "thiserror-impl 2.0.17", + "thiserror-impl 2.0.18", ] [[package]] @@ -3235,9 +3276,9 @@ dependencies = [ [[package]] name = "thiserror-impl" -version = "2.0.17" +version = "2.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ff15c8ecd7de3849db632e14d18d2571fa09dfc5ed93479bc4485c7a517c913" +checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" dependencies = [ "proc-macro2", "quote", @@ -3456,7 +3497,7 @@ version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "adc82fd73de2a9722ac5da747f12383d2bfdb93591ee6c58486e0097890f05f2" dependencies = [ - "bitflags 2.10.0", + "bitflags 2.11.0", "bytes", "futures-util", "http", @@ -3522,7 +3563,7 @@ dependencies = [ "chrono", "serde", "smallvec", - "thiserror 2.0.17", + "thiserror 2.0.18", "tracing", "tracing-subscriber", "uuid", @@ -3818,7 +3859,7 @@ version = "0.236.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a9b1e81f3eb254cf7404a82cee6926a4a3ccc5aad80cc3d43608a070c67aa1d7" dependencies = [ - "bitflags 2.10.0", + "bitflags 2.11.0", "hashbrown 0.15.5", "indexmap", "semver", @@ -3827,27 +3868,27 @@ dependencies = [ [[package]] name = "wasmparser" -version = "0.243.0" +version = "0.244.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6d8db401b0528ec316dfbe579e6ab4152d61739cfe076706d2009127970159d" +checksum = "47b807c72e1bac69382b3a6fb3dbe8ea4c0ed87ff5629b8685ae6b9a611028fe" dependencies = [ - "bitflags 2.10.0", + "bitflags 2.11.0", "hashbrown 0.15.5", "indexmap", "semver", - "serde", ] [[package]] name = "wasmparser" -version = "0.244.0" +version = "0.245.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47b807c72e1bac69382b3a6fb3dbe8ea4c0ed87ff5629b8685ae6b9a611028fe" +checksum = "4f08c9adee0428b7bddf3890fc27e015ac4b761cc608c822667102b8bfd6995e" dependencies = [ - "bitflags 2.10.0", - "hashbrown 0.15.5", + "bitflags 2.11.0", + "hashbrown 0.16.1", "indexmap", "semver", + "serde", ] [[package]] @@ -3869,7 +3910,7 @@ checksum = "6a2f8736ddc86e03a9d0e4c477a37939cfc53cd1b052ee38a3133679b87ef830" dependencies = [ "addr2line", "anyhow", - "bitflags 2.10.0", + "bitflags 2.11.0", "bumpalo", "cc", "cfg-if", @@ -3982,7 +4023,7 @@ dependencies = [ "pulley-interpreter", "smallvec", "target-lexicon", - "thiserror 2.0.17", + "thiserror 2.0.18", "wasmparser 0.236.1", "wasmtime-environ", "wasmtime-internal-math", @@ -4090,7 +4131,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c28dc9efea511598c88564ac1974e0825c07d9c0de902dbf68f227431cd4ff8c" dependencies = [ "anyhow", - "bitflags 2.10.0", + "bitflags 2.11.0", "heck", "indexmap", "wit-parser 0.236.1", @@ -4172,7 +4213,7 @@ dependencies = [ "regalloc2", "smallvec", "target-lexicon", - "thiserror 2.0.17", + "thiserror 2.0.18", "wasmparser 0.236.1", "wasmtime-environ", "wasmtime-internal-cranelift", @@ -4530,7 +4571,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d66ea20e9553b30172b5e831994e35fbde2d165325bec84fc43dbf6f4eb9cb2" dependencies = [ "anyhow", - "bitflags 2.10.0", + "bitflags 2.11.0", "indexmap", "log", "serde", diff --git a/Cargo.toml b/Cargo.toml index 6959cb6e..f3741f38 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ exclude = [ "src/wasm_runtime", "src/rust_wasm_samples", "src/hyperlight_wasm_m resolver = "2" [workspace.package] -version = "0.12.0" +version = "0.13.0" edition = "2024" rust-version = "1.89" license = "Apache-2.0" @@ -13,5 +13,5 @@ repository = "https://github.com/hyperlight-dev/hyperlight-wasm" readme = "README.md" [workspace.dependencies] -hyperlight-host = { version = "0.12.0", default-features = false, features = ["executable_heap", "init-paging"] } -hyperlight-common = { version = "0.12.0", default-features = false } +hyperlight-host = { version = "0.13.0", default-features = false, features = ["executable_heap", "init-paging"] } +hyperlight-common = { version = "0.13.0", default-features = false } diff --git a/src/hyperlight_wasm/Cargo.toml b/src/hyperlight_wasm/Cargo.toml index a469c3d5..45e5f956 100644 --- a/src/hyperlight_wasm/Cargo.toml +++ b/src/hyperlight_wasm/Cargo.toml @@ -75,7 +75,7 @@ windows = { version = "0.62", features = ["Win32_System_Threading"] } page_size = "0.6.0" [dev-dependencies] -hyperlight-component-macro = { version = "0.12.0" } +hyperlight-component-macro = { version = "0.13.0" } examples_common = { path = "../examples_common" } criterion = { version = "0.8.2", features = ["html_reports"] } crossbeam-queue = "0.3" diff --git a/src/hyperlight_wasm/examples/component_example/main.rs b/src/hyperlight_wasm/examples/component_example/main.rs index ca0b6b65..39592feb 100644 --- a/src/hyperlight_wasm/examples/component_example/main.rs +++ b/src/hyperlight_wasm/examples/component_example/main.rs @@ -48,7 +48,7 @@ fn main() { let mut sb: hyperlight_wasm::ProtoWasmSandbox = hyperlight_wasm::SandboxBuilder::new() .with_guest_input_buffer_size(70000000) .with_guest_heap_size(200000000) - .with_guest_stack_size(100000000) + .with_guest_scratch_size(100 * 1024 * 1024) .build() .unwrap(); let rt = bindings::register_host_functions(&mut sb, state); diff --git a/src/hyperlight_wasm/examples/helloworld/main.rs b/src/hyperlight_wasm/examples/helloworld/main.rs index a5b55453..6b0f693c 100644 --- a/src/hyperlight_wasm/examples/helloworld/main.rs +++ b/src/hyperlight_wasm/examples/helloworld/main.rs @@ -112,7 +112,7 @@ fn main() -> Result<()> { "RoundToInt test case {idx} failed: got {}, expected {}", result, expected_result ); - loaded_wasm_sandbox.restore(&snapshot)? + loaded_wasm_sandbox.restore(snapshot.clone())? } Ok(()) } diff --git a/src/hyperlight_wasm/examples/interruption/main.rs b/src/hyperlight_wasm/examples/interruption/main.rs index 2d14d0d3..af5dd5f1 100644 --- a/src/hyperlight_wasm/examples/interruption/main.rs +++ b/src/hyperlight_wasm/examples/interruption/main.rs @@ -97,7 +97,7 @@ fn main() -> Result<()> { // Recovery option 1: Use restore() to recover the sandbox println!("\n7. Recovering sandbox using restore()..."); - loaded.restore(&snapshot)?; + loaded.restore(snapshot.clone())?; assert!(!loaded.is_poisoned()?); println!(" is_poisoned after restore: {}", loaded.is_poisoned()?); diff --git a/src/hyperlight_wasm/src/sandbox/loaded_wasm_sandbox.rs b/src/hyperlight_wasm/src/sandbox/loaded_wasm_sandbox.rs index 30010878..9f42647d 100644 --- a/src/hyperlight_wasm/src/sandbox/loaded_wasm_sandbox.rs +++ b/src/hyperlight_wasm/src/sandbox/loaded_wasm_sandbox.rs @@ -42,7 +42,7 @@ pub struct LoadedWasmSandbox { // because of this we cannot implement drop without making inner an Option (alternatively we could make MultiUseSandbox Copy but that would introduce other issues) inner: Option, // The state the sandbox was in before loading a wasm module. Used for transitioning back to a `WasmSandbox` (unloading the wasm module). - runtime_snapshot: Option, + runtime_snapshot: Option>, } impl LoadedWasmSandbox { @@ -86,7 +86,7 @@ impl LoadedWasmSandbox { /// Returns `Err(HyperlightError::PoisonedSandbox)` if the sandbox is in a /// poisoned state. Use [`restore()`](Self::restore) with a previously /// taken snapshot to recover before taking a new snapshot. - pub fn snapshot(&mut self) -> Result { + pub fn snapshot(&mut self) -> Result> { match &mut self.inner { Some(inner) => inner.snapshot(), None => log_then_return!("No inner MultiUseSandbox to snapshot"), @@ -105,7 +105,7 @@ impl LoadedWasmSandbox { /// 1. Clear the poisoned state /// 2. Reset memory to the snapshot state /// 3. Allow subsequent [`call_guest_function()`](Self::call_guest_function) calls to succeed - pub fn restore(&mut self, snapshot: &Snapshot) -> Result<()> { + pub fn restore(&mut self, snapshot: Arc) -> Result<()> { match &mut self.inner { Some(inner) => inner.restore(snapshot), None => log_then_return!("No inner MultiUseSandbox to restore"), @@ -135,7 +135,7 @@ impl LoadedWasmSandbox { pub(super) fn new( inner: MultiUseSandbox, - runtime_snapshot: Snapshot, + runtime_snapshot: Arc, ) -> Result { metrics::gauge!(METRIC_ACTIVE_LOADED_WASM_SANDBOXES).increment(1); metrics::counter!(METRIC_TOTAL_LOADED_WASM_SANDBOXES).increment(1); @@ -360,7 +360,7 @@ mod tests { #[test] fn test_call_guest_functions_with_custom_config_multiple_times() { let mut sandbox = SandboxBuilder::new() - .with_guest_stack_size(32 * 1024) + .with_guest_scratch_size(32 * 1024) .with_guest_heap_size(128 * 1024) .build() .unwrap(); diff --git a/src/hyperlight_wasm/src/sandbox/sandbox_builder.rs b/src/hyperlight_wasm/src/sandbox/sandbox_builder.rs index 1c519f59..f9b48004 100644 --- a/src/hyperlight_wasm/src/sandbox/sandbox_builder.rs +++ b/src/hyperlight_wasm/src/sandbox/sandbox_builder.rs @@ -22,7 +22,9 @@ use super::proto_wasm_sandbox::ProtoWasmSandbox; // use unreasonably large minimum stack/heap/input data sizes for now to // deal with the size of wasmtime/wasi-libc aot artifacts -pub const MIN_STACK_SIZE: u64 = 64 * 1024; +// use reasonably large minimum scratch/heap/input data sizes +// to deal with the size of wasmtime/wasi-libc aot artifacts +pub const MIN_SCRATCH_SIZE: usize = 2 * 1024 * 1024; pub const MIN_INPUT_DATA_SIZE: usize = 192 * 1024; pub const MIN_HEAP_SIZE: u64 = 1024 * 1024; @@ -39,6 +41,7 @@ impl SandboxBuilder { let mut config: SandboxConfiguration = Default::default(); config.set_input_data_size(MIN_INPUT_DATA_SIZE); config.set_heap_size(MIN_HEAP_SIZE); + config.set_scratch_size(MIN_SCRATCH_SIZE); Self { config, @@ -95,13 +98,14 @@ impl SandboxBuilder { self } - /// Set the guest stack size - /// This is the size of the stack that code executing in the guest can use. - /// If this value is too small then the guest will fail with a stack overflow error - /// The default value (and minimum) is set to the value of the MIN_STACK_SIZE const. - pub fn with_guest_stack_size(mut self, guest_stack_size: u64) -> Self { - if guest_stack_size > MIN_STACK_SIZE { - self.config.set_stack_size(guest_stack_size); + /// Set the guest scratch size in bytes. + /// The scratch region provides writable memory for the guest, including the + /// dynamically-sized stack. Increase this if your guest code needs deep + /// recursion or large local variables. + /// Values smaller than the default (288 KiB) are ignored. + pub fn with_guest_scratch_size(mut self, guest_scratch_size: usize) -> Self { + if guest_scratch_size > MIN_SCRATCH_SIZE { + self.config.set_scratch_size(guest_scratch_size); } self } diff --git a/src/hyperlight_wasm/src/sandbox/wasm_sandbox.rs b/src/hyperlight_wasm/src/sandbox/wasm_sandbox.rs index 074e5754..0dab32e6 100644 --- a/src/hyperlight_wasm/src/sandbox/wasm_sandbox.rs +++ b/src/hyperlight_wasm/src/sandbox/wasm_sandbox.rs @@ -15,8 +15,8 @@ limitations under the License. */ use std::path::Path; +use std::sync::Arc; -use hyperlight_host::mem::memory_region::{MemoryRegion, MemoryRegionFlags, MemoryRegionType}; use hyperlight_host::sandbox::snapshot::Snapshot; use hyperlight_host::{MultiUseSandbox, Result, new_error}; @@ -38,7 +38,7 @@ pub struct WasmSandbox { inner: Option, // Snapshot of state of an initial WasmSandbox (runtime loaded, but no guest module code loaded). // Used for LoadedWasmSandbox to be able restore state back to WasmSandbox - snapshot: Option, + snapshot: Option>, } const MAPPED_BINARY_VA: u64 = 0x1_0000_0000u64; @@ -61,8 +61,11 @@ impl WasmSandbox { /// for example when creating a `WasmSandbox` from a `LoadedWasmSandbox`, since /// the snapshot has already been created in that case. /// Expects a snapshot of the state where wasm runtime is loaded, but no guest module code is loaded. - pub(super) fn new_from_loaded(mut loaded: MultiUseSandbox, snapshot: Snapshot) -> Result { - loaded.restore(&snapshot)?; + pub(super) fn new_from_loaded( + mut loaded: MultiUseSandbox, + snapshot: Arc, + ) -> Result { + loaded.restore(snapshot.clone())?; metrics::gauge!(METRIC_ACTIVE_WASM_SANDBOXES).increment(1); metrics::counter!(METRIC_TOTAL_WASM_SANDBOXES).increment(1); Ok(WasmSandbox { @@ -113,19 +116,8 @@ impl WasmSandbox { .as_mut() .ok_or_else(|| new_error!("WasmSandbox is None"))?; - let guest_base: usize = MAPPED_BINARY_VA as usize; - let rgn = MemoryRegion { - host_region: base as usize..base.wrapping_add(len) as usize, - guest_region: guest_base..guest_base + len, - flags: MemoryRegionFlags::READ | MemoryRegionFlags::EXECUTE, - region_type: MemoryRegionType::Heap, - }; - if let Ok(()) = unsafe { inner.map_region(&rgn) } { - inner.call::<()>("LoadWasmModulePhys", (MAPPED_BINARY_VA, len as u64))?; - } else { - let wasm_bytes = unsafe { std::slice::from_raw_parts(base as *const u8, len).to_vec() }; - load_wasm_module_from_bytes(inner, wasm_bytes)?; - } + let wasm_bytes = unsafe { std::slice::from_raw_parts(base as *const u8, len).to_vec() }; + load_wasm_module_from_bytes(inner, wasm_bytes)?; self.finalize_module_load() } @@ -390,7 +382,7 @@ mod tests { assert!(loaded.is_poisoned()?, "Sandbox should be poisoned"); // Restore should recover the sandbox - loaded.restore(&snapshot)?; + loaded.restore(snapshot)?; assert!( !loaded.is_poisoned()?, @@ -526,7 +518,7 @@ mod tests { let builder = SandboxBuilder::new() .with_guest_input_buffer_size(0x8000) .with_guest_output_buffer_size(0x8000) - .with_guest_stack_size(0x2000) + .with_guest_scratch_size(0x2000) .with_guest_heap_size(0x100000); let mut sandboxes: Vec = Vec::new(); diff --git a/src/hyperlight_wasm_macro/Cargo.lock b/src/hyperlight_wasm_macro/Cargo.lock index db5bf9e7..cabc94db 100644 --- a/src/hyperlight_wasm_macro/Cargo.lock +++ b/src/hyperlight_wasm_macro/Cargo.lock @@ -22,38 +22,39 @@ checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" [[package]] name = "foldhash" -version = "0.1.5" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" +checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb" [[package]] name = "hashbrown" -version = "0.15.5" +version = "0.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" +checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" dependencies = [ "foldhash", "serde", + "serde_core", ] [[package]] name = "hyperlight-component-util" -version = "0.12.0" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9b3299460dc5f39d37b8233c9aad7fc52c9548d96a76d35cdcc4f4f49ff6662" +checksum = "41501638fd9877bd0c2e0cbbd20ea55d5a532f4e45a870d626de56da9795fc9a" dependencies = [ "itertools", - "log", "prettyplease", "proc-macro2", "quote", "syn", + "tracing", "wasmparser", ] [[package]] name = "hyperlight-wasm-macro" -version = "0.12.0" +version = "0.13.0" dependencies = [ "hyperlight-component-util", "itertools", @@ -65,13 +66,14 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.11.0" +version = "2.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2481980430f9f78649238835720ddccc57e52df14ffce1c6f37391d61b563e9" +checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017" dependencies = [ "equivalent", "hashbrown", "serde", + "serde_core", ] [[package]] @@ -89,6 +91,18 @@ version = "0.4.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" +[[package]] +name = "once_cell" +version = "1.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" + +[[package]] +name = "pin-project-lite" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" + [[package]] name = "prettyplease" version = "0.2.37" @@ -125,18 +139,27 @@ checksum = "56e6fa9c48d24d85fb3de5ad847117517440f6beceb7798af16b4a87d616b8d0" [[package]] name = "serde" -version = "1.0.219" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", +] + +[[package]] +name = "serde_core" +version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.219" +version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" dependencies = [ "proc-macro2", "quote", @@ -154,6 +177,38 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "tracing" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" +dependencies = [ + "log", + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" +dependencies = [ + "once_cell", +] + [[package]] name = "unicode-ident" version = "1.0.18" @@ -162,9 +217,9 @@ checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" [[package]] name = "wasmparser" -version = "0.243.0" +version = "0.245.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6d8db401b0528ec316dfbe579e6ab4152d61739cfe076706d2009127970159d" +checksum = "4f08c9adee0428b7bddf3890fc27e015ac4b761cc608c822667102b8bfd6995e" dependencies = [ "bitflags", "hashbrown", diff --git a/src/hyperlight_wasm_macro/Cargo.toml b/src/hyperlight_wasm_macro/Cargo.toml index b44fde5e..7c683f3e 100644 --- a/src/hyperlight_wasm_macro/Cargo.toml +++ b/src/hyperlight_wasm_macro/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hyperlight-wasm-macro" -version = "0.12.0" +version = "0.13.0" edition = "2024" description = """ Procedural macros to generate Hyperlight Wasm host and guest bindings from component types @@ -16,6 +16,6 @@ proc-macro2 = { version = "1.0.106" } syn = { version = "2.0.117" } itertools = { version = "0.14.0" } prettyplease = { version = "0.2.37" } -hyperlight-component-util = { version = "0.12.0" } +hyperlight-component-util = { version = "0.13.0" } [workspace] # indicate that this crate is not part of any workspace diff --git a/src/hyperlight_wasm_macro/src/lib.rs b/src/hyperlight_wasm_macro/src/lib.rs index 5ed3f8a2..1eb8765f 100644 --- a/src/hyperlight_wasm_macro/src/lib.rs +++ b/src/hyperlight_wasm_macro/src/lib.rs @@ -29,7 +29,7 @@ mod wasmguest; #[proc_macro] pub fn wasm_guest_bindgen(_: proc_macro::TokenStream) -> proc_macro::TokenStream { let path = std::env::var_os("WIT_WORLD").unwrap(); - util::read_wit_type_from_file(path, |kebab_name, ct| { + util::read_wit_type_from_file(path, None, |kebab_name, ct| { let decls = emit::run_state(true, true, |s| { // Emit type/trait definitions for all instances in the world rtypes::emit_toplevel(s, &kebab_name, ct); diff --git a/src/hyperlight_wasm_macro/src/wasmguest.rs b/src/hyperlight_wasm_macro/src/wasmguest.rs index ba188b61..1ba93341 100644 --- a/src/hyperlight_wasm_macro/src/wasmguest.rs +++ b/src/hyperlight_wasm_macro/src/wasmguest.rs @@ -166,7 +166,7 @@ fn emit_export_extern_decl<'b>( let (function_call, ret) = emit_wasm_function_call(s, &ft.result, pwts, pus); let marshal_result = emit_hl_marshal_result(s, ret.clone(), &ft.result); quote! { - fn #n(fc: &::hyperlight_common::flatbuffer_wrappers::function_call::FunctionCall) -> ::hyperlight_guest::error::Result<::alloc::vec::Vec> { + fn #n(fc: ::hyperlight_common::flatbuffer_wrappers::function_call::FunctionCall) -> ::hyperlight_guest::error::Result<::alloc::vec::Vec> { #(#pds)* let mut store = CUR_STORE.lock(); let mut store = store.as_mut().unwrap(); let instance = CUR_INSTANCE.lock(); let mut instance = instance.unwrap(); @@ -181,7 +181,7 @@ fn emit_export_extern_decl<'b>( #fname.to_string(), ::alloc::vec![#(#pts),*], ::hyperlight_common::flatbuffer_wrappers::function_types::ReturnType::VecBytes, - #n as usize + #n ) ); } diff --git a/src/wasm_runtime/Cargo.lock b/src/wasm_runtime/Cargo.lock index 3344952f..e767de31 100644 --- a/src/wasm_runtime/Cargo.lock +++ b/src/wasm_runtime/Cargo.lock @@ -10,9 +10,9 @@ checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" [[package]] name = "anyhow" -version = "1.0.100" +version = "1.0.102" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a23eb6b1614318a8071c9b2521f36b424b2c83db5eb3a0fead4a6c0809af6e61" +checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" [[package]] name = "arbitrary" @@ -40,11 +40,11 @@ checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3" [[package]] name = "buddy_system_allocator" -version = "0.11.0" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1a0108968a3a2dab95b089c0fc3f1afa7759aa5ebe6f1d86d206d6f7ba726eb" +checksum = "b672b945a3e4f4f40bfd4cd5ee07df9e796a42254ce7cd6d2599ad969244c44a" dependencies = [ - "spin 0.9.8", + "spin", ] [[package]] @@ -341,9 +341,9 @@ checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" [[package]] name = "flatbuffers" -version = "25.9.23" +version = "25.12.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09b6620799e7340ebd9968d2e0708eb82cf1971e9a16821e2091b6d6e475eed5" +checksum = "35f6839d7b3b98adde531effaf34f0c2badc6f4735d26fe74709d8e513a96ef3" dependencies = [ "bitflags", "rustc_version", @@ -355,6 +355,12 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" +[[package]] +name = "foldhash" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb" + [[package]] name = "form_urlencoded" version = "1.2.2" @@ -464,7 +470,7 @@ version = "0.15.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" dependencies = [ - "foldhash", + "foldhash 0.1.5", "serde", ] @@ -473,6 +479,11 @@ name = "hashbrown" version = "0.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" +dependencies = [ + "foldhash 0.2.0", + "serde", + "serde_core", +] [[package]] name = "heck" @@ -583,37 +594,38 @@ dependencies = [ [[package]] name = "hyperlight-common" -version = "0.12.0" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98f80e9aba9fce2a899c9ff0c62dd39cd479fa2f22ef578faed1d510c5becf94" +checksum = "725ce602c72dce1d83a87f98f3731e7db62f5ca7e1a255eea875e9bad408766f" dependencies = [ "anyhow", "flatbuffers", "log", - "spin 0.10.0", + "spin", "thiserror", + "tracing-core", ] [[package]] name = "hyperlight-component-util" -version = "0.12.0" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9b3299460dc5f39d37b8233c9aad7fc52c9548d96a76d35cdcc4f4f49ff6662" +checksum = "41501638fd9877bd0c2e0cbbd20ea55d5a532f4e45a870d626de56da9795fc9a" dependencies = [ "itertools", - "log", "prettyplease", "proc-macro2", "quote", "syn", - "wasmparser 0.243.0", + "tracing", + "wasmparser 0.245.1", ] [[package]] name = "hyperlight-guest" -version = "0.12.0" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc7f3cfaa19d263d4110b6f1d371ad778d544f4f30369be8eca79092bc868840" +checksum = "e9d3e421c1058a950dffaa414dd9e0348d21b18ec218cf2777752c436087bcb0" dependencies = [ "anyhow", "flatbuffers", @@ -625,9 +637,9 @@ dependencies = [ [[package]] name = "hyperlight-guest-bin" -version = "0.12.0" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "598a6f53bd1a356cff745af4b20e2e96ff9d4c956d13c52fd7981e91832291d8" +checksum = "ae0b7568c1df39e78f9ee844243ad722ef4990e46950232747e14460379a3930" dependencies = [ "buddy_system_allocator", "cc", @@ -640,15 +652,15 @@ dependencies = [ "hyperlight-guest-tracing", "linkme", "log", - "spin 0.10.0", + "spin", "tracing", ] [[package]] name = "hyperlight-guest-macro" -version = "0.12.0" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc0fec4e1154fe4368a5980101d532eede35c622532aaf83a03440d912d55217" +checksum = "f1d7915f27b534dc2c26e215f0372f80b34b172fb8d2507d0c0f0c4616259a42" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -658,19 +670,19 @@ dependencies = [ [[package]] name = "hyperlight-guest-tracing" -version = "0.12.0" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df0f8d1e992b03c778c6c144f94a81060384e823781c84fae6228cba230d449c" +checksum = "266a23a83726db78b114fd177bda2833df84e9e2894e460aed7c7da9a0967a5e" dependencies = [ "hyperlight-common", - "spin 0.10.0", + "spin", "tracing", "tracing-core", ] [[package]] name = "hyperlight-wasm-macro" -version = "0.12.0" +version = "0.13.0" dependencies = [ "hyperlight-component-util", "itertools", @@ -790,9 +802,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.12.1" +version = "2.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ad4bb2b565bca0645f4d68c5c9af97fba094e9791da685bf83cb5f3ce74acf2" +checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017" dependencies = [ "equivalent", "hashbrown 0.16.1", @@ -1025,9 +1037,9 @@ dependencies = [ [[package]] name = "proc-macro-crate" -version = "3.4.0" +version = "3.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "219cb19e96be00ab2e37d6e299658a0cfa83e52429179969b0f0121b4ac46983" +checksum = "e67ba7e9b2b56446f1d419b1d807906278ffa1a658a8a5d8a39dcb1f5a78614f" dependencies = [ "toml_edit", ] @@ -1408,15 +1420,6 @@ dependencies = [ "windows-sys 0.60.2", ] -[[package]] -name = "spin" -version = "0.9.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" -dependencies = [ - "lock_api", -] - [[package]] name = "spin" version = "0.10.0" @@ -1486,18 +1489,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "2.0.17" +version = "2.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f63587ca0f12b72a0600bcba1d40081f830876000bb46dd2337a3051618f4fc8" +checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "2.0.17" +version = "2.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ff15c8ecd7de3849db632e14d18d2571fa09dfc5ed93479bc4485c7a517c913" +checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" dependencies = [ "proc-macro2", "quote", @@ -1555,18 +1558,18 @@ dependencies = [ [[package]] name = "toml_datetime" -version = "0.7.3" +version = "1.0.0+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2cdb639ebbc97961c51720f858597f7f24c4fc295327923af55b74c3c724533" +checksum = "32c2555c699578a4f59f0cc68e5116c8d7cabbd45e1409b989d4be085b53f13e" dependencies = [ "serde_core", ] [[package]] name = "toml_edit" -version = "0.23.9" +version = "0.25.4+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d7cbc3b4b49633d57a0509303158ca50de80ae32c265093b24c414705807832" +checksum = "7193cbd0ce53dc966037f54351dbbcf0d5a642c7f0038c382ef9e677ce8c13f2" dependencies = [ "indexmap", "toml_datetime", @@ -1576,9 +1579,9 @@ dependencies = [ [[package]] name = "toml_parser" -version = "1.0.4" +version = "1.0.9+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0cbe268d35bdb4bb5a56a2de88d0ad0eb70af5384a99d648cd4b3d04039800e" +checksum = "702d4415e08923e7e1ef96cd5727c0dfed80b4d2fa25db9647fe5eb6f7c5a4c4" dependencies = [ "winnow", ] @@ -1796,7 +1799,7 @@ dependencies = [ [[package]] name = "wasm-runtime" -version = "0.12.0" +version = "0.13.0" dependencies = [ "cargo_metadata", "cc", @@ -1807,7 +1810,7 @@ dependencies = [ "hyperlight-guest-bin", "hyperlight-wasm-macro", "reqwest", - "spin 0.10.0", + "spin", "tracing", "wasmtime", ] @@ -1827,12 +1830,12 @@ dependencies = [ [[package]] name = "wasmparser" -version = "0.243.0" +version = "0.245.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6d8db401b0528ec316dfbe579e6ab4152d61739cfe076706d2009127970159d" +checksum = "4f08c9adee0428b7bddf3890fc27e015ac4b761cc608c822667102b8bfd6995e" dependencies = [ "bitflags", - "hashbrown 0.15.5", + "hashbrown 0.16.1", "indexmap", "semver", "serde", diff --git a/src/wasm_runtime/Cargo.toml b/src/wasm_runtime/Cargo.toml index 730c850a..e846e812 100644 --- a/src/wasm_runtime/Cargo.toml +++ b/src/wasm_runtime/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wasm-runtime" -version = "0.12.0" +version = "0.13.0" edition = "2021" [[bin]] @@ -11,9 +11,9 @@ doctest = false bench = false [dependencies] -hyperlight-common = { version = "0.12.0", default-features = false } -hyperlight-guest-bin = { version = "0.12.0", features = [ "printf" ] } -hyperlight-guest = { version = "0.12.0" } +hyperlight-common = { version = "0.13.0", default-features = false } +hyperlight-guest-bin = { version = "0.13.0", features = [ "printf" ] } +hyperlight-guest = { version = "0.13.0" } wasmtime = { version = "36.0.6", default-features = false, features = [ "runtime", "custom-virtual-memory", "custom-native-signals", "component-model" ] } hyperlight-wasm-macro = { path = "../hyperlight_wasm_macro" } spin = "0.10.0" diff --git a/src/wasm_runtime/src/component.rs b/src/wasm_runtime/src/component.rs index f6439c3f..05afe97c 100644 --- a/src/wasm_runtime/src/component.rs +++ b/src/wasm_runtime/src/component.rs @@ -45,7 +45,7 @@ hyperlight_wasm_macro::wasm_guest_bindgen!(); // dummy for compatibility with the module loading approach #[instrument(skip_all, level = "Info")] -fn init_wasm_runtime(_function_call: &FunctionCall) -> Result> { +fn init_wasm_runtime(_function_call: FunctionCall) -> Result> { Ok(get_flatbuffer_result::(0)) } @@ -62,7 +62,7 @@ fn load_component_common(engine: &Engine, component: Component) -> Result<()> { } #[instrument(skip_all, level = "Info")] -fn load_wasm_module(function_call: &FunctionCall) -> Result> { +fn load_wasm_module(function_call: FunctionCall) -> Result> { if let ( ParameterValue::VecBytes(ref wasm_bytes), ParameterValue::Int(ref _len), @@ -84,7 +84,7 @@ fn load_wasm_module(function_call: &FunctionCall) -> Result> { } #[instrument(skip_all, level = "Info")] -fn load_wasm_module_phys(function_call: &FunctionCall) -> Result> { +fn load_wasm_module_phys(function_call: FunctionCall) -> Result> { if let (ParameterValue::ULong(ref phys), ParameterValue::ULong(ref len), Some(ref engine)) = ( &function_call.parameters.as_ref().unwrap()[0], &function_call.parameters.as_ref().unwrap()[1], @@ -132,19 +132,19 @@ pub extern "C" fn hyperlight_main() { "InitWasmRuntime".to_string(), vec![ParameterType::VecBytes], ReturnType::Int, - init_wasm_runtime as usize, + init_wasm_runtime, )); register_function(GuestFunctionDefinition::new( "LoadWasmModule".to_string(), vec![ParameterType::VecBytes, ParameterType::Int], ReturnType::Int, - load_wasm_module as usize, + load_wasm_module, )); register_function(GuestFunctionDefinition::new( "LoadWasmModulePhys".to_string(), vec![ParameterType::ULong, ParameterType::ULong], ReturnType::Void, - load_wasm_module_phys as usize, + load_wasm_module_phys, )); } diff --git a/src/wasm_runtime/src/module.rs b/src/wasm_runtime/src/module.rs index 0cd6819a..fe198b9f 100644 --- a/src/wasm_runtime/src/module.rs +++ b/src/wasm_runtime/src/module.rs @@ -96,7 +96,7 @@ pub fn guest_dispatch_function(function_call: FunctionCall) -> Result> { } #[instrument(skip_all, level = "Info")] -fn init_wasm_runtime(function_call: &FunctionCall) -> Result> { +fn init_wasm_runtime(function_call: FunctionCall) -> Result> { let mut config = Config::new(); config.with_custom_code_memory(Some(alloc::sync::Arc::new(platform::WasmtimeCodeMemory {}))); #[cfg(gdb)] @@ -162,7 +162,7 @@ fn init_wasm_runtime(function_call: &FunctionCall) -> Result> { } #[instrument(skip_all, level = "Info")] -fn load_wasm_module(function_call: &FunctionCall) -> Result> { +fn load_wasm_module(function_call: FunctionCall) -> Result> { if let ( ParameterValue::VecBytes(ref wasm_bytes), ParameterValue::Int(ref _len), @@ -195,7 +195,7 @@ fn load_wasm_module(function_call: &FunctionCall) -> Result> { } #[instrument(skip_all, level = "Info")] -fn load_wasm_module_phys(function_call: &FunctionCall) -> Result> { +fn load_wasm_module_phys(function_call: FunctionCall) -> Result> { if let (ParameterValue::ULong(ref phys), ParameterValue::ULong(ref len), Some(ref engine)) = ( &function_call.parameters.as_ref().unwrap()[0], &function_call.parameters.as_ref().unwrap()[1], @@ -223,9 +223,8 @@ fn load_wasm_module_phys(function_call: &FunctionCall) -> Result> { } } -// GuestFunctionDefinition expects a function pointer as i64 +// GuestFunctionDefinition expects a function pointer #[no_mangle] -#[allow(clippy::fn_to_numeric_cast)] #[instrument(skip_all, level = "Info")] pub extern "C" fn hyperlight_main() { platform::register_page_fault_handler(); @@ -234,26 +233,26 @@ pub extern "C" fn hyperlight_main() { "PrintOutput".to_string(), vec![ParameterType::String], ReturnType::Int, - print_output_with_host_print as usize, + print_output_with_host_print, )); register_function(GuestFunctionDefinition::new( "InitWasmRuntime".to_string(), vec![ParameterType::VecBytes], ReturnType::Int, - init_wasm_runtime as usize, + init_wasm_runtime, )); register_function(GuestFunctionDefinition::new( "LoadWasmModule".to_string(), vec![ParameterType::VecBytes, ParameterType::Int], ReturnType::Int, - load_wasm_module as usize, + load_wasm_module, )); register_function(GuestFunctionDefinition::new( "LoadWasmModulePhys".to_string(), vec![ParameterType::ULong, ParameterType::ULong], ReturnType::Void, - load_wasm_module_phys as usize, + load_wasm_module_phys, )); } diff --git a/src/wasm_runtime/src/platform.rs b/src/wasm_runtime/src/platform.rs index bcd84cb7..ff6b660f 100644 --- a/src/wasm_runtime/src/platform.rs +++ b/src/wasm_runtime/src/platform.rs @@ -18,7 +18,8 @@ use core::ffi::c_void; use core::ptr::NonNull; use core::sync::atomic::{AtomicPtr, AtomicU64, Ordering}; -use hyperlight_guest_bin::exceptions::handler; +use hyperlight_common::vmem; +use hyperlight_guest_bin::exception::arch; use hyperlight_guest_bin::paging; // Extremely stupid virtual address allocator @@ -28,8 +29,8 @@ use hyperlight_guest_bin::paging; static FIRST_VADDR: AtomicU64 = AtomicU64::new(0x100_0000_0000u64); fn page_fault_handler( _exception_number: u64, - info: *mut handler::ExceptionInfo, - _ctx: *mut handler::Context, + info: *mut arch::ExceptionInfo, + _ctx: *mut arch::Context, page_fault_address: u64, ) -> bool { let error_code = unsafe { (&raw const (*info).error_code).read_volatile() }; @@ -41,12 +42,17 @@ fn page_fault_handler( // structure in hyperlight core if (error_code & 0x1) == 0x0 && page_fault_address >= 0x100_0000_0000u64 { unsafe { - let phys_page = paging::alloc_phys_pages(1); + let phys_page = hyperlight_guest::prim_alloc::alloc_phys_pages(1); let virt_base = (page_fault_address & !0xFFF) as *mut u8; paging::map_region( phys_page, virt_base, hyperlight_guest_bin::OS_PAGE_SIZE as u64, + vmem::MappingKind::Basic(vmem::BasicMapping { + readable: true, + writable: true, + executable: true, + }), ); virt_base.write_bytes(0u8, hyperlight_guest_bin::OS_PAGE_SIZE as usize); } @@ -59,7 +65,7 @@ pub(crate) fn register_page_fault_handler() { // See AMD64 Architecture Programmer's Manual, Volume 2 // §8.2 Vectors, p. 245 // Table 8-1: Interrupt Vector Source and Cause - handler::HANDLERS[14].store(page_fault_handler as usize as u64, Ordering::Release); + arch::HANDLERS[14].store(page_fault_handler as usize as u64, Ordering::Release); } // Wasmtime Embedding Interface @@ -120,8 +126,8 @@ type wasmtime_trap_handler_t = static WASMTIME_REQUESTED_TRAP_HANDLER: AtomicU64 = AtomicU64::new(0); fn wasmtime_trap_handler( exception_number: u64, - info: *mut handler::ExceptionInfo, - ctx: *mut handler::Context, + info: *mut arch::ExceptionInfo, + ctx: *mut arch::Context, _page_fault_address: u64, ) -> bool { let requested_handler = WASMTIME_REQUESTED_TRAP_HANDLER.load(Ordering::Relaxed); @@ -155,7 +161,7 @@ pub extern "C" fn wasmtime_init_traps(handler: wasmtime_trap_handler_t) -> i32 { // See AMD64 Architecture Programmer's Manual, Volume 2 // §8.2 Vectors, p. 245 // Table 8-1: Interrupt Vector Source and Cause - handler::HANDLERS[6].store(wasmtime_trap_handler as usize as u64, Ordering::Release); + arch::HANDLERS[6].store(wasmtime_trap_handler as usize as u64, Ordering::Release); // TODO: Add handlers for any other traps that wasmtime needs, // probably including at least some floating-point // exceptions @@ -233,7 +239,17 @@ pub(crate) unsafe fn map_buffer(phys: u64, len: u64) -> NonNull<[u8]> { // TODO: Use a VA allocator let virt = phys as *mut u8; unsafe { - paging::map_region(phys, virt, len); + paging::map_region( + phys, + virt, + len, + vmem::MappingKind::Basic(vmem::BasicMapping { + readable: true, + writable: true, + executable: true, + }), + ); + paging::barrier::first_valid_same_ctx(); NonNull::new_unchecked(core::ptr::slice_from_raw_parts_mut(virt, len as usize)) } } From 6cba4bd4ca13ab51c104229b42af11ea65bc7c77 Mon Sep 17 00:00:00 2001 From: James Sturtevant Date: Fri, 6 Mar 2026 14:49:52 -0800 Subject: [PATCH 5/5] Move the HostPrint Registration Signed-off-by: James Sturtevant --- .../src/sandbox/proto_wasm_sandbox.rs | 14 +------------- src/wasm_runtime/src/module.rs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/hyperlight_wasm/src/sandbox/proto_wasm_sandbox.rs b/src/hyperlight_wasm/src/sandbox/proto_wasm_sandbox.rs index 91c5ec4b..23b54769 100644 --- a/src/hyperlight_wasm/src/sandbox/proto_wasm_sandbox.rs +++ b/src/hyperlight_wasm/src/sandbox/proto_wasm_sandbox.rs @@ -77,17 +77,7 @@ impl ProtoWasmSandbox { metrics::gauge!(METRIC_ACTIVE_PROTO_WASM_SANDBOXES).increment(1); metrics::counter!(METRIC_TOTAL_PROTO_WASM_SANDBOXES).increment(1); - // HostPrint is always registered by UninitializedSandbox, so include it by default - let mut host_function_definitions = HashMap::new(); - host_function_definitions.insert( - "HostPrint".to_string(), - HostFunctionDefinition { - function_name: "HostPrint".to_string(), - parameter_types: Some(vec![ParameterType::String]), - return_type: ReturnType::Int, - }, - ); - + let host_function_definitions = HashMap::new(); Ok(Self { inner: Some(inner), host_function_definitions, @@ -170,8 +160,6 @@ impl ProtoWasmSandbox { &mut self, print_func: impl Into>, ) -> Result<()> { - // HostPrint definition is already tracked from new() since - // UninitializedSandbox always registers a default HostPrint. // This method only replaces the implementation, not the definition. self.inner .as_mut() diff --git a/src/wasm_runtime/src/module.rs b/src/wasm_runtime/src/module.rs index fe198b9f..c2b00564 100644 --- a/src/wasm_runtime/src/module.rs +++ b/src/wasm_runtime/src/module.rs @@ -155,6 +155,23 @@ fn init_wasm_runtime(function_call: FunctionCall) -> Result> { .map_err(|e| wasmtime::Error::msg(format!("{:?}", e))) }, )?; + + // Always register HostPrint + let host_print_def = hostfuncs::HostFunctionDefinition { + function_name: "HostPrint".to_string(), + parameter_types: Some(alloc::vec![ParameterType::String]), + return_type: ReturnType::Int, + }; + let captured = host_print_def.clone(); + linker.func_new( + "env", + "HostPrint", + hostfuncs::hostfunc_type(&host_print_def, &engine)?, + move |c, ps, rs| { + hostfuncs::call(&captured, c, ps, rs) + .map_err(|e| wasmtime::Error::msg(format!("{:?}", e))) + }, + )?; } *CUR_ENGINE.lock() = Some(engine); *CUR_LINKER.lock() = Some(linker);