From b0e80c6eda99190ec529dc19b444e8f14a0f32ab Mon Sep 17 00:00:00 2001 From: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com> Date: Wed, 23 Jul 2025 20:20:42 -0700 Subject: [PATCH 1/3] Bump hyperlight-host to new snapshot api Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com> --- Cargo.lock | 59 +++- Cargo.toml | 2 +- src/hyperlight_wasm/Cargo.toml | 3 +- src/hyperlight_wasm/src/lib.rs | 2 + .../src/sandbox/loaded_wasm_sandbox.rs | 75 +++-- .../src/sandbox/proto_wasm_sandbox.rs | 35 +-- .../src/sandbox/wasm_sandbox.rs | 141 ++++----- src/hyperlight_wasm_macro/Cargo.lock | 2 +- src/hyperlight_wasm_macro/Cargo.toml | 2 +- src/wasm_runtime/Cargo.lock | 277 +++++++++++++----- src/wasm_runtime/Cargo.toml | 6 +- src/wasm_runtime/src/platform.rs | 4 +- 12 files changed, 403 insertions(+), 205 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 26c0000..74290b8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1008,6 +1008,30 @@ dependencies = [ "pin-utils", ] +[[package]] +name = "gdbstub" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71d66e32caf5dd59f561be0143e413e01d651bd8498eb9aa0be8c482c81c8d31" +dependencies = [ + "bitflags 2.9.1", + "cfg-if", + "log", + "managed", + "num-traits", + "paste", +] + +[[package]] +name = "gdbstub_arch" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22dde0e1b68787036ccedd0b1ff6f953527a0e807e571fbe898975203027278f" +dependencies = [ + "gdbstub", + "num-traits", +] + [[package]] name = "generic-array" version = "0.14.7" @@ -1263,7 +1287,7 @@ dependencies = [ [[package]] name = "hyperlight-common" version = "0.7.0" -source = "git+https://github.com/hyperlight-dev/hyperlight?rev=ea6fa8f#ea6fa8f16dae2325d94af39eb6ac3b441b24dcac" +source = "git+https://github.com/hyperlight-dev/hyperlight?rev=172fcfa69b0f9064c7a0e48e512f8a86ae1fdbe1#172fcfa69b0f9064c7a0e48e512f8a86ae1fdbe1" dependencies = [ "anyhow", "flatbuffers", @@ -1275,7 +1299,7 @@ dependencies = [ [[package]] name = "hyperlight-component-macro" version = "0.7.0" -source = "git+https://github.com/hyperlight-dev/hyperlight?rev=b61265e4aa9e2ecf8d648b994022caeea0205352#b61265e4aa9e2ecf8d648b994022caeea0205352" +source = "git+https://github.com/hyperlight-dev/hyperlight?rev=172fcfa69b0f9064c7a0e48e512f8a86ae1fdbe1#172fcfa69b0f9064c7a0e48e512f8a86ae1fdbe1" dependencies = [ "env_logger", "hyperlight-component-util", @@ -1290,7 +1314,7 @@ dependencies = [ [[package]] name = "hyperlight-component-util" version = "0.7.0" -source = "git+https://github.com/hyperlight-dev/hyperlight?rev=b61265e4aa9e2ecf8d648b994022caeea0205352#b61265e4aa9e2ecf8d648b994022caeea0205352" +source = "git+https://github.com/hyperlight-dev/hyperlight?rev=172fcfa69b0f9064c7a0e48e512f8a86ae1fdbe1#172fcfa69b0f9064c7a0e48e512f8a86ae1fdbe1" dependencies = [ "itertools 0.14.0", "log", @@ -1304,16 +1328,19 @@ dependencies = [ [[package]] name = "hyperlight-host" version = "0.7.0" -source = "git+https://github.com/hyperlight-dev/hyperlight?rev=ea6fa8f#ea6fa8f16dae2325d94af39eb6ac3b441b24dcac" +source = "git+https://github.com/hyperlight-dev/hyperlight?rev=172fcfa69b0f9064c7a0e48e512f8a86ae1fdbe1#172fcfa69b0f9064c7a0e48e512f8a86ae1fdbe1" dependencies = [ "anyhow", "bitflags 2.9.1", + "blake3", "cfg-if", "cfg_aliases", "chrono", "crossbeam-channel", "elfcore", "flatbuffers", + "gdbstub", + "gdbstub_arch", "goblin", "hyperlight-common", "kvm-bindings", @@ -1337,6 +1364,7 @@ dependencies = [ "tracing", "tracing-core", "tracing-log", + "uuid", "vmm-sys-util", "windows", "windows-result", @@ -1758,6 +1786,12 @@ dependencies = [ "libc", ] +[[package]] +name = "managed" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ca88d725a0a943b096803bd34e73a4437208b6077654cc4ecb2947a5f91618d" + [[package]] name = "memchr" version = "2.7.5" @@ -2027,6 +2061,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "paste" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + [[package]] name = "percent-encoding" version = "2.3.1" @@ -3095,6 +3135,17 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" +[[package]] +name = "uuid" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3cf4199d1e5d15ddd86a694e4d0dffa9c323ce759fea589f00fef9d81cc1931d" +dependencies = [ + "getrandom 0.3.3", + "js-sys", + "wasm-bindgen", +] + [[package]] name = "valuable" version = "0.1.1" diff --git a/Cargo.toml b/Cargo.toml index 5db9026..0d3d43d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,4 +13,4 @@ repository = "https://github.com/hyperlight-dev/hyperlight-wasm" readme = "README.md" [workspace.dependencies] -hyperlight-host = { version = "0.7.0", git = "https://github.com/hyperlight-dev/hyperlight", rev = "ea6fa8f", default-features = false, features = ["executable_heap", "init-paging"] } +hyperlight-host = { version = "0.7.0", git = "https://github.com/hyperlight-dev/hyperlight", rev = "172fcfa69b0f9064c7a0e48e512f8a86ae1fdbe1", default-features = false, features = ["executable_heap", "init-paging"] } diff --git a/src/hyperlight_wasm/Cargo.toml b/src/hyperlight_wasm/Cargo.toml index 3cac134..0edd0b3 100644 --- a/src/hyperlight_wasm/Cargo.toml +++ b/src/hyperlight_wasm/Cargo.toml @@ -58,7 +58,7 @@ windows = { version = "0.61", features = ["Win32_System_Threading"] } page_size = "0.6.0" [dev-dependencies] -hyperlight-component-macro = { version = "0.7.0", git = "https://github.com/hyperlight-dev/hyperlight", rev = "b61265e4aa9e2ecf8d648b994022caeea0205352" } +hyperlight-component-macro = { version = "0.7.0", git = "https://github.com/hyperlight-dev/hyperlight", rev = "172fcfa69b0f9064c7a0e48e512f8a86ae1fdbe1" } examples_common = { path = "../examples_common" } criterion = { version = "0.7.0", features = ["html_reports"] } crossbeam-queue = "0.3" @@ -77,6 +77,7 @@ tar = "0.4.44" [features] default = ["function_call_metrics", "kvm", "mshv2"] +gdb = ["hyperlight-host/gdb"] function_call_metrics = ["hyperlight-host/function_call_metrics"] seccomp = ["hyperlight-host/seccomp"] print_debug = ["hyperlight-host/print_debug"] diff --git a/src/hyperlight_wasm/src/lib.rs b/src/hyperlight_wasm/src/lib.rs index f974da6..4a022e6 100644 --- a/src/hyperlight_wasm/src/lib.rs +++ b/src/hyperlight_wasm/src/lib.rs @@ -39,6 +39,8 @@ pub type Result = hyperlight_host::Result; pub use hyperlight_host::is_hypervisor_present; /// Create a generic HyperlightError pub use hyperlight_host::new_error; +// A snapshot of the memory of a sandbox at a given point in time. +pub use hyperlight_host::sandbox::snapshot::Snapshot; /// Get the build information for this version of hyperlight-wasm pub fn get_build_info() -> BuildInfo { diff --git a/src/hyperlight_wasm/src/sandbox/loaded_wasm_sandbox.rs b/src/hyperlight_wasm/src/sandbox/loaded_wasm_sandbox.rs index b90c62c..0a9d039 100644 --- a/src/hyperlight_wasm/src/sandbox/loaded_wasm_sandbox.rs +++ b/src/hyperlight_wasm/src/sandbox/loaded_wasm_sandbox.rs @@ -14,14 +14,14 @@ See the License for the specific language governing permissions and limitations under the License. */ +use std::fmt::Debug; use std::sync::Arc; use hyperlight_host::func::{ParameterTuple, SupportedReturnType}; // re-export the InterruptHandle trait as it's part of the public API pub use hyperlight_host::hypervisor::InterruptHandle; use hyperlight_host::sandbox::Callable; -use hyperlight_host::sandbox_state::sandbox::{DevolvableSandbox, Sandbox}; -use hyperlight_host::sandbox_state::transition::Noop; +use hyperlight_host::sandbox::snapshot::Snapshot; use hyperlight_host::{MultiUseSandbox, Result, log_then_return, new_error}; use super::metrics::METRIC_TOTAL_LOADED_WASM_SANDBOXES; @@ -37,16 +37,15 @@ use crate::sandbox::metrics::{METRIC_ACTIVE_LOADED_WASM_SANDBOXES, METRIC_SANDBO /// memory context. If you want to "reset" the memory context, create /// a new `LoadedWasmSandbox` -- either from another `WasmSandbox` or by /// calling `my_loaded_wasm_sandbox.devolve()?.evolve()?` -#[derive(Debug)] pub struct LoadedWasmSandbox { // inner is an Option as we need to take ownership of it // We implement drop on the LoadedWasmSandbox to decrement the count of Sandboxes when it is dropped // 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). + wasm_sandbox_snapshot: Snapshot, } -impl Sandbox for LoadedWasmSandbox {} - impl LoadedWasmSandbox { /// Call the function in the guest with the name `fn_name`, passing /// parameters `params`. @@ -64,17 +63,49 @@ impl LoadedWasmSandbox { None => log_then_return!("No inner MultiUseSandbox to call_guest_function"), } } + + /// Take a snapshot of the current state of the sandbox. + pub fn snapshot(&mut self) -> Result { + match &mut self.inner { + Some(inner) => inner.snapshot(), + None => log_then_return!("No inner MultiUseSandbox to snapshot"), + } + } + + /// Restore the state of the sandbox to the state captured in the given snapshot. + pub fn restore(&mut self, snapshot: &Snapshot) -> Result<()> { + match &mut self.inner { + Some(inner) => inner.restore(snapshot), + None => log_then_return!("No inner MultiUseSandbox to restore"), + } + } + /// unload the wasm module and return a `WasmSandbox` that can be used to load another module - pub fn unload_module(self) -> Result { - self.devolve(Noop::default()).inspect(|_| { - metrics::counter!(METRIC_SANDBOX_UNLOADS).increment(1); - }) + pub fn unload_module(mut self) -> Result { + self.inner + .as_mut() + .ok_or_else(|| new_error!("No inner MultiUseSandbox to unload"))? + .restore(&self.wasm_sandbox_snapshot)?; + + self.inner + .take() + .ok_or_else(|| new_error!("No inner MultiUseSandbox to unload")) + .and_then(WasmSandbox::new) + .inspect(|_| { + metrics::counter!(METRIC_SANDBOX_UNLOADS).increment(1); + }) } - pub(super) fn new(inner: MultiUseSandbox) -> Result { + pub(super) fn new( + inner: MultiUseSandbox, + wasm_sandbox_snapshot: Snapshot, + ) -> Result { metrics::gauge!(METRIC_ACTIVE_LOADED_WASM_SANDBOXES).increment(1); metrics::counter!(METRIC_TOTAL_LOADED_WASM_SANDBOXES).increment(1); - Ok(LoadedWasmSandbox { inner: Some(inner) }) + Ok(LoadedWasmSandbox { + inner: Some(inner), + wasm_sandbox_snapshot, + }) } /// Get a handle to the interrupt handler for this sandbox, @@ -100,26 +131,20 @@ impl Callable for LoadedWasmSandbox { } } -/// Capability to transform a `LoadedWasmSandbox` back down to a -/// `WasmSandbox` -impl DevolvableSandbox> - for LoadedWasmSandbox -{ - fn devolve(mut self, _: Noop) -> Result { - let new_inner: MultiUseSandbox = match self.inner.take() { - Some(inner) => inner.devolve(Noop::default())?, - None => log_then_return!("No inner MultiUseSandbox to devolve"), - }; - Ok(WasmSandbox::new(new_inner)) - } -} - impl Drop for LoadedWasmSandbox { fn drop(&mut self) { metrics::gauge!(METRIC_ACTIVE_LOADED_WASM_SANDBOXES).decrement(1); } } +impl Debug for LoadedWasmSandbox { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("LoadedWasmSandbox") + .field("inner", &self.inner) + .finish() + } +} + #[cfg(test)] mod tests { use std::sync::Arc; diff --git a/src/hyperlight_wasm/src/sandbox/proto_wasm_sandbox.rs b/src/hyperlight_wasm/src/sandbox/proto_wasm_sandbox.rs index 551096c..5202e18 100644 --- a/src/hyperlight_wasm/src/sandbox/proto_wasm_sandbox.rs +++ b/src/hyperlight_wasm/src/sandbox/proto_wasm_sandbox.rs @@ -14,15 +14,11 @@ See the License for the specific language governing permissions and limitations under the License. */ -use hyperlight_host::func::call_ctx::MultiUseGuestCallContext; use hyperlight_host::func::{HostFunction, ParameterTuple, Registerable, SupportedReturnType}; -use hyperlight_host::sandbox::Callable; #[cfg(all(feature = "seccomp", target_os = "linux"))] use hyperlight_host::sandbox::ExtraAllowedSyscall; use hyperlight_host::sandbox::config::SandboxConfiguration; -use hyperlight_host::sandbox_state::sandbox::{EvolvableSandbox, Sandbox}; -use hyperlight_host::sandbox_state::transition::{MultiUseContextCallback, Noop}; -use hyperlight_host::{GuestBinary, MultiUseSandbox, Result, UninitializedSandbox, new_error}; +use hyperlight_host::{GuestBinary, Result, UninitializedSandbox, new_error}; use super::metrics::{METRIC_ACTIVE_PROTO_WASM_SANDBOXES, METRIC_TOTAL_PROTO_WASM_SANDBOXES}; use super::sandbox_builder::SandboxBuilder; @@ -39,8 +35,6 @@ pub struct ProtoWasmSandbox { pub(super) inner: Option, } -impl Sandbox for ProtoWasmSandbox {} - impl Registerable for ProtoWasmSandbox { fn register_host_function( &mut self, @@ -95,27 +89,20 @@ 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 { - let multi_use_sandbox: MultiUseSandbox = match self.inner.take() { - Some(s) => s.evolve(Noop::default())?, + let mut sandbox = match self.inner.take() { + Some(s) => s.evolve()?, None => return Err(new_error!("No inner sandbox found.")), }; - let func = Box::new(move |call_ctx: &mut MultiUseGuestCallContext| { - let res: i32 = call_ctx.call("InitWasmRuntime", ())?; - if res != 0 { - return Err(new_error!( - "InitWasmRuntime Failed with error code {:?}", - res - )); - } - Ok(()) - }); - - let transition_func = MultiUseContextCallback::from(func); - - let new_sbox: MultiUseSandbox = multi_use_sandbox.evolve(transition_func)?; + let res: i32 = sandbox.call_guest_function_by_name("InitWasmRuntime", ())?; + if res != 0 { + return Err(new_error!( + "InitWasmRuntime Failed with error code {:?}", + res + )); + } - Ok(WasmSandbox::new(new_sbox)) + WasmSandbox::new(sandbox) } /// Register the given host function `host_func` with `self` under diff --git a/src/hyperlight_wasm/src/sandbox/wasm_sandbox.rs b/src/hyperlight_wasm/src/sandbox/wasm_sandbox.rs index ad382da..4aab631 100644 --- a/src/hyperlight_wasm/src/sandbox/wasm_sandbox.rs +++ b/src/hyperlight_wasm/src/sandbox/wasm_sandbox.rs @@ -16,11 +16,9 @@ limitations under the License. use std::path::Path; -use hyperlight_host::func::call_ctx::MultiUseGuestCallContext; use hyperlight_host::mem::memory_region::{MemoryRegion, MemoryRegionFlags, MemoryRegionType}; use hyperlight_host::sandbox::Callable; -use hyperlight_host::sandbox_state::sandbox::{EvolvableSandbox, Sandbox}; -use hyperlight_host::sandbox_state::transition::MultiUseContextCallback; +use hyperlight_host::sandbox::snapshot::Snapshot; use hyperlight_host::{MultiUseSandbox, Result, new_error}; use super::loaded_wasm_sandbox::LoadedWasmSandbox; @@ -39,20 +37,25 @@ pub struct WasmSandbox { // We implement drop on the WasmSandbox to decrement the count of Sandboxes when it is dropped // 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, + // 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, } -impl Sandbox for WasmSandbox {} - const MAPPED_BINARY_VA: u64 = 0x1_0000_0000u64; impl WasmSandbox { /// Create a new WasmSandBox from a `MultiUseSandbox`. /// This function should be used to create a new `WasmSandbox` from a ProtoWasmSandbox. /// The difference between this function and creating a `WasmSandbox` directly is that /// this function will increment the metrics for the number of `WasmSandbox`es in the system. - pub(super) fn new(inner: MultiUseSandbox) -> Self { + pub(super) fn new(mut inner: MultiUseSandbox) -> Result { + let snapshot = inner.snapshot()?; metrics::gauge!(METRIC_ACTIVE_WASM_SANDBOXES).increment(1); metrics::counter!(METRIC_TOTAL_WASM_SANDBOXES).increment(1); - WasmSandbox { inner: Some(inner) } + Ok(WasmSandbox { + inner: Some(inner), + snapshot: Some(snapshot), + }) } /// Load a Wasm module at the given path into the sandbox and return a `LoadedWasmSandbox` @@ -60,16 +63,20 @@ impl WasmSandbox { /// /// Before you can call guest functions in the sandbox, you must call /// this function and use the returned value to call guest functions. - pub fn load_module(self, file: impl AsRef) -> Result { - let func = Box::new(move |call_ctx: &mut MultiUseGuestCallContext| { - if let Ok(len) = call_ctx.map_file_cow(file.as_ref(), MAPPED_BINARY_VA) { - call_ctx.call("LoadWasmModulePhys", (MAPPED_BINARY_VA, len)) - } else { - let wasm_bytes = std::fs::read(file)?; - Self::load_module_from_buffer_transition_func(wasm_bytes)(call_ctx) - } - }); - self.load_module_inner(func) + pub fn load_module(mut self, file: impl AsRef) -> Result { + let inner = self + .inner + .as_mut() + .ok_or_else(|| new_error!("WasmSandbox is None"))?; + + if let Ok(len) = inner.map_file_cow(file.as_ref(), MAPPED_BINARY_VA) { + inner.call::<()>("LoadWasmModulePhys", (MAPPED_BINARY_VA, len))?; + } else { + let wasm_bytes = std::fs::read(file)?; + load_wasm_module_from_bytes(inner, wasm_bytes)?; + } + + self.finalize_module_load() } /// Load a Wasm module that is currently present in a buffer in @@ -84,45 +91,30 @@ impl WasmSandbox { /// of the region remains intact and is not written to until the /// produced LoadedWasmSandbox is discarded or devolved. pub unsafe fn load_module_by_mapping( - self, + mut self, base: *mut libc::c_void, len: usize, ) -> Result { - let func = Box::new(move |call_ctx: &mut MultiUseGuestCallContext| { - 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 { call_ctx.map_region(&rgn) } { - call_ctx.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() }; - Self::load_module_from_buffer_transition_func(wasm_bytes)(call_ctx) - } - }); - self.load_module_inner(func) - } - - // todo: take a slice rather than a vec (requires somewhat - // refactoring the flatbuffers stuff maybe) - fn load_module_from_buffer_transition_func( - buffer: Vec, - ) -> impl FnOnce(&mut MultiUseGuestCallContext) -> Result<()> { - move |call_ctx: &mut MultiUseGuestCallContext| { - let len = buffer.len() as i32; - let res: i32 = call_ctx.call("LoadWasmModule", (buffer, len))?; - if res != 0 { - return Err(new_error!( - "LoadWasmModule Failed with error code {:?}", - res - )); - } - Ok(()) + let inner = self + .inner + .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)?; } + + self.finalize_module_load() } /// Load a Wasm module from a buffer of bytes into the sandbox and return a `LoadedWasmSandbox` @@ -130,29 +122,44 @@ impl WasmSandbox { /// /// Before you can call guest functions in the sandbox, you must call /// this function and use the returned value to call guest functions. - pub fn load_module_from_buffer(self, buffer: &[u8]) -> Result { + pub fn load_module_from_buffer(mut self, buffer: &[u8]) -> Result { + let inner = self + .inner + .as_mut() + .ok_or_else(|| new_error!("WasmSandbox is None"))?; + // TODO: get rid of this clone - let func = Self::load_module_from_buffer_transition_func(buffer.to_vec()); + load_wasm_module_from_bytes(inner, buffer.to_vec())?; - self.load_module_inner(func) + self.finalize_module_load() } - fn load_module_inner Result<()>>( - mut self, - func: F, - ) -> Result { - let transition_func = MultiUseContextCallback::from(func); - match self.inner.take() { - Some(sbox) => { - let new_sbox: MultiUseSandbox = sbox.evolve(transition_func)?; - metrics::counter!(METRIC_SANDBOX_LOADS).increment(1); - LoadedWasmSandbox::new(new_sbox) - } - None => Err(new_error!("WasmSandbox is None, cannot load module")), + /// Helper function to finalize module loading and create LoadedWasmSandbox + fn finalize_module_load(mut self) -> Result { + metrics::counter!(METRIC_SANDBOX_LOADS).increment(1); + match (self.inner.take(), self.snapshot.take()) { + (Some(sandbox), Some(snapshot)) => LoadedWasmSandbox::new(sandbox, snapshot), + _ => Err(new_error!( + "WasmSandbox/snapshot is None, cannot load module" + )), } } } +fn load_wasm_module_from_bytes(inner: &mut MultiUseSandbox, wasm_bytes: Vec) -> Result<()> { + let res: i32 = inner.call( + "LoadWasmModule", + (wasm_bytes.clone(), wasm_bytes.len() as i32), + )?; + if res != 0 { + return Err(new_error!( + "LoadWasmModule Failed with error code {:?}", + res + )); + } + Ok(()) +} + impl std::fmt::Debug for WasmSandbox { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("WasmSandbox").finish() diff --git a/src/hyperlight_wasm_macro/Cargo.lock b/src/hyperlight_wasm_macro/Cargo.lock index 3b01b24..03e9b44 100644 --- a/src/hyperlight_wasm_macro/Cargo.lock +++ b/src/hyperlight_wasm_macro/Cargo.lock @@ -39,7 +39,7 @@ dependencies = [ [[package]] name = "hyperlight-component-util" version = "0.7.0" -source = "git+https://github.com/hyperlight-dev/hyperlight?rev=b61265e4aa9e2ecf8d648b994022caeea0205352#b61265e4aa9e2ecf8d648b994022caeea0205352" +source = "git+https://github.com/hyperlight-dev/hyperlight?rev=172fcfa69b0f9064c7a0e48e512f8a86ae1fdbe1#172fcfa69b0f9064c7a0e48e512f8a86ae1fdbe1" dependencies = [ "itertools", "log", diff --git a/src/hyperlight_wasm_macro/Cargo.toml b/src/hyperlight_wasm_macro/Cargo.toml index 3c2a2fc..516ffae 100644 --- a/src/hyperlight_wasm_macro/Cargo.toml +++ b/src/hyperlight_wasm_macro/Cargo.toml @@ -16,4 +16,4 @@ proc-macro2 = { version = "1.0.93" } syn = { version = "2.0.96" } itertools = { version = "0.14.0" } prettyplease = { version = "0.2.31" } -hyperlight-component-util = { version = "0.7.0", git = "https://github.com/hyperlight-dev/hyperlight", rev = "b61265e4aa9e2ecf8d648b994022caeea0205352" } +hyperlight-component-util = { version = "0.7.0", git = "https://github.com/hyperlight-dev/hyperlight", rev = "172fcfa69b0f9064c7a0e48e512f8a86ae1fdbe1" } diff --git a/src/wasm_runtime/Cargo.lock b/src/wasm_runtime/Cargo.lock index 4e9d307..b89c918 100644 --- a/src/wasm_runtime/Cargo.lock +++ b/src/wasm_runtime/Cargo.lock @@ -37,9 +37,9 @@ checksum = "dde20b3d026af13f561bdd0f15edf01fc734f0dafcedbaf42bba506a9517f223" [[package]] name = "autocfg" -version = "1.4.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" +checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" [[package]] name = "backtrace" @@ -53,7 +53,7 @@ dependencies = [ "miniz_oxide", "object", "rustc-demangle", - "windows-targets", + "windows-targets 0.52.6", ] [[package]] @@ -79,9 +79,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.18.1" +version = "3.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "793db76d6187cd04dff33004d8e6c9cc4e05cd330500379d2394209271b4aeee" +checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43" dependencies = [ "allocator-api2", ] @@ -126,9 +126,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.2.26" +version = "1.2.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956a5e21988b87f372569b66183b78babf23ebc2e744b733e4350a752c4dafac" +checksum = "deec109607ca693028562ed836a5f1c4b8bd77755c4e132fc5ce11b0b6211ae7" dependencies = [ "shlex", ] @@ -147,9 +147,12 @@ checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" [[package]] name = "cobs" -version = "0.2.3" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67ba02a97a2bd10f4b59b25c7973101c79642302776489e030cd13cdab09ed15" +checksum = "0fa961b519f0b462e3a3b4a34b64d119eeaca1d59af726fe450bbba07a9fc0a1" +dependencies = [ + "thiserror", +] [[package]] name = "cranelift-assembler-x64" @@ -290,9 +293,9 @@ checksum = "b530783809a55cb68d070e0de60cfbb3db0dc94c8850dd5725411422bedcf6bb" [[package]] name = "crc32fast" -version = "1.4.2" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" +checksum = "9481c1c90cbf2ac953f07c8d4a58aa3945c425b7185c9154d67a65e4230da511" dependencies = [ "cfg-if", ] @@ -343,12 +346,12 @@ checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" [[package]] name = "errno" -version = "0.3.12" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cea14ef9355e3beab063703aa9dab15afd25f0667c341310c1e5274bb1d0da18" +checksum = "778e2ac28f6c47af28e4907f13ffd1e1ddbd400980a9abd7c8df189bf578a5ad" dependencies = [ "libc", - "windows-sys 0.59.0", + "windows-sys 0.60.2", ] [[package]] @@ -576,9 +579,9 @@ dependencies = [ [[package]] name = "hyper-util" -version = "0.1.14" +version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc2fdfdbff08affe55bb779f33b053aa1fe5dd5b54c257343c17edfa55711bdb" +checksum = "8d9b05277c7e8da2c93a568989bb6207bef0112e8d17df7a6eda4a3cf143bc5e" dependencies = [ "base64", "bytes", @@ -592,7 +595,7 @@ dependencies = [ "libc", "percent-encoding", "pin-project-lite", - "socket2", + "socket2 0.6.0", "tokio", "tower-service", "tracing", @@ -601,7 +604,7 @@ dependencies = [ [[package]] name = "hyperlight-common" version = "0.7.0" -source = "git+https://github.com/hyperlight-dev/hyperlight?rev=ea6fa8f#ea6fa8f16dae2325d94af39eb6ac3b441b24dcac" +source = "git+https://github.com/hyperlight-dev/hyperlight?rev=172fcfa69b0f9064c7a0e48e512f8a86ae1fdbe1#172fcfa69b0f9064c7a0e48e512f8a86ae1fdbe1" dependencies = [ "anyhow", "flatbuffers", @@ -612,7 +615,7 @@ dependencies = [ [[package]] name = "hyperlight-component-util" version = "0.7.0" -source = "git+https://github.com/hyperlight-dev/hyperlight?rev=b61265e4aa9e2ecf8d648b994022caeea0205352#b61265e4aa9e2ecf8d648b994022caeea0205352" +source = "git+https://github.com/hyperlight-dev/hyperlight?rev=172fcfa69b0f9064c7a0e48e512f8a86ae1fdbe1#172fcfa69b0f9064c7a0e48e512f8a86ae1fdbe1" dependencies = [ "itertools", "log", @@ -626,17 +629,18 @@ dependencies = [ [[package]] name = "hyperlight-guest" version = "0.7.0" -source = "git+https://github.com/hyperlight-dev/hyperlight?rev=ea6fa8f#ea6fa8f16dae2325d94af39eb6ac3b441b24dcac" +source = "git+https://github.com/hyperlight-dev/hyperlight?rev=172fcfa69b0f9064c7a0e48e512f8a86ae1fdbe1#172fcfa69b0f9064c7a0e48e512f8a86ae1fdbe1" dependencies = [ "anyhow", "hyperlight-common", + "hyperlight-guest-tracing-macro", "serde_json", ] [[package]] name = "hyperlight-guest-bin" version = "0.7.0" -source = "git+https://github.com/hyperlight-dev/hyperlight?rev=ea6fa8f#ea6fa8f16dae2325d94af39eb6ac3b441b24dcac" +source = "git+https://github.com/hyperlight-dev/hyperlight?rev=172fcfa69b0f9064c7a0e48e512f8a86ae1fdbe1#172fcfa69b0f9064c7a0e48e512f8a86ae1fdbe1" dependencies = [ "buddy_system_allocator", "cc", @@ -644,10 +648,31 @@ dependencies = [ "glob", "hyperlight-common", "hyperlight-guest", + "hyperlight-guest-tracing-macro", "log", "spin 0.10.0", ] +[[package]] +name = "hyperlight-guest-tracing" +version = "0.7.0" +source = "git+https://github.com/hyperlight-dev/hyperlight?rev=172fcfa69b0f9064c7a0e48e512f8a86ae1fdbe1#172fcfa69b0f9064c7a0e48e512f8a86ae1fdbe1" +dependencies = [ + "hyperlight-common", + "spin 0.10.0", +] + +[[package]] +name = "hyperlight-guest-tracing-macro" +version = "0.7.0" +source = "git+https://github.com/hyperlight-dev/hyperlight?rev=172fcfa69b0f9064c7a0e48e512f8a86ae1fdbe1#172fcfa69b0f9064c7a0e48e512f8a86ae1fdbe1" +dependencies = [ + "hyperlight-guest-tracing", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "hyperlight-wasm-macro" version = "0.7.0" @@ -775,15 +800,26 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.9.0" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cea70ddb795996207ad57735b50c5982d8844f38ba9ee5f1aedcfb708a2aa11e" +checksum = "fe4cd85333e22411419a0bcae1297d25e58c9443848b11dc6a86fefe8c78a661" dependencies = [ "equivalent", "hashbrown", "serde", ] +[[package]] +name = "io-uring" +version = "0.7.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d93587f37623a1a17d94ef2bc9ada592f5465fe7732084ab7beefabe5c77c0c4" +dependencies = [ + "bitflags", + "cfg-if", + "libc", +] + [[package]] name = "ipnet" version = "2.11.0" @@ -833,9 +869,9 @@ checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2" [[package]] name = "libc" -version = "0.2.172" +version = "0.2.174" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa" +checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776" [[package]] name = "libm" @@ -879,18 +915,18 @@ checksum = "112b39cec0b298b6c1999fee3e31427f74f676e4cb9879ed1a121b43661a4154" [[package]] name = "mach2" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19b955cdeb2a02b9117f121ce63aa52d08ade45de53e48fe6a38b39c10f6f709" +checksum = "d640282b302c0bb0a2a8e0233ead9035e3bed871f0b7e81fe4a1ec829765db44" dependencies = [ "libc", ] [[package]] name = "memchr" -version = "2.7.4" +version = "2.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0" [[package]] name = "memfd" @@ -959,9 +995,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "postcard" -version = "1.1.1" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "170a2601f67cc9dba8edd8c4870b15f71a6a2dc196daec8c83f72b59dff628a8" +checksum = "6764c3b5dd454e283a30e6dfe78e9b31096d9e32036b5d1eaac7a6119ccb9a24" dependencies = [ "cobs", "embedded-io 0.4.0", @@ -989,9 +1025,9 @@ dependencies = [ [[package]] name = "prettyplease" -version = "0.2.35" +version = "0.2.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "061c1221631e079b26479d25bbf2275bfe5917ae8419cd7e34f13bfc2aa7539a" +checksum = "ff24dfcda44452b9816fff4cd4227e1bb73ff5a2f1bc1105aa92fb8565ce44d2" dependencies = [ "proc-macro2", "syn", @@ -1042,7 +1078,7 @@ dependencies = [ "quinn-udp", "rustc-hash", "rustls", - "socket2", + "socket2 0.5.10", "thiserror", "tokio", "tracing", @@ -1072,14 +1108,14 @@ dependencies = [ [[package]] name = "quinn-udp" -version = "0.5.12" +version = "0.5.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee4e529991f949c5e25755532370b8af5d114acae52326361d68d47af64aa842" +checksum = "fcebb1209ee276352ef14ff8732e24cc2b02bbac986cd74a4c81bcb2f9881970" dependencies = [ "cfg_aliases", "libc", "once_cell", - "socket2", + "socket2 0.5.10", "tracing", "windows-sys 0.59.0", ] @@ -1095,15 +1131,15 @@ dependencies = [ [[package]] name = "r-efi" -version = "5.2.0" +version = "5.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74765f6d916ee2faa39bc8e68e4f3ed8949b48cccdac59983d287a7cb71ce9c5" +checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" [[package]] name = "rand" -version = "0.9.1" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fbfd9d094a40bf3ae768db9361049ace4c0e04a4fd6b359518bd7b73a73dd97" +checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1" dependencies = [ "rand_chacha", "rand_core", @@ -1144,9 +1180,9 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.12.20" +version = "0.12.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eabf4c97d9130e2bf606614eb937e86edac8292eaa6f422f995d7e8de1eb1813" +checksum = "cbc931937e6ca3a06e3b6c0aa7841849b160a90351d6ab467a8b9b9959767531" dependencies = [ "base64", "bytes", @@ -1198,9 +1234,9 @@ dependencies = [ [[package]] name = "rustc-demangle" -version = "0.1.25" +version = "0.1.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "989e6739f80c4ad5b13e0fd7fe89531180375b18520cc8c82080e4dc4035b84f" +checksum = "56f7d92ca342cea22a06f2121d944b4fd82af56988c270852495420f961d4ace" [[package]] name = "rustc-hash" @@ -1232,9 +1268,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.27" +version = "0.23.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "730944ca083c1c233a75c09f199e973ca499344a2b7ba9e755c457e86fb4a321" +checksum = "c0ebcbd2f03de0fc1122ad9bb24b127a5a6cd51d72604a3f3c50ac459762b6cc" dependencies = [ "once_cell", "ring", @@ -1256,9 +1292,9 @@ dependencies = [ [[package]] name = "rustls-webpki" -version = "0.103.3" +version = "0.103.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4a72fe2bcf7a6ac6fd7d0b9e5cb68aeb7d4c0a0271730218b3e92d43b4eb435" +checksum = "0a17884ae0c1b773f1ccd2bd4a8c72f16da897310a98b0e84bf349ad5ead92fc" dependencies = [ "ring", "rustls-pki-types", @@ -1314,9 +1350,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.140" +version = "1.0.141" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373" +checksum = "30b9eff21ebe718216c6ec64e1d9ac57087aad11efc64e32002bce4a0d4c03d3" dependencies = [ "itoa", "memchr", @@ -1344,12 +1380,9 @@ checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" [[package]] name = "slab" -version = "0.4.9" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] +checksum = "04dc19736151f35336d325007ac991178d504a119863a2fcb3758cdb5e52c50d" [[package]] name = "smallvec" @@ -1370,6 +1403,16 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "socket2" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "233504af464074f9d066d7b5416c5f9b894a5862a6506e306f7b816cdd6f1807" +dependencies = [ + "libc", + "windows-sys 0.59.0", +] + [[package]] name = "spin" version = "0.9.8" @@ -1493,17 +1536,19 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.45.1" +version = "1.47.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75ef51a33ef1da925cea3e4eb122833cb377c61439ca401b770f54902b806779" +checksum = "43864ed400b6043a4757a25c7a64a8efde741aed79a056a2fb348a406701bb35" dependencies = [ "backtrace", "bytes", + "io-uring", "libc", "mio", "pin-project-lite", - "socket2", - "windows-sys 0.52.0", + "slab", + "socket2 0.6.0", + "windows-sys 0.59.0", ] [[package]] @@ -1977,9 +2022,9 @@ dependencies = [ [[package]] name = "webpki-roots" -version = "1.0.0" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2853738d1cc4f2da3a225c18ec6c3721abb31961096e9dbf5ab35fa88b19cfdb" +checksum = "7e8983c3ab33d6fb807cfcdad2491c4ea8cbc8ed839181c7dfd9c67c83e261b2" dependencies = [ "rustls-pki-types", ] @@ -2013,13 +2058,19 @@ dependencies = [ "wasmtime-internal-math", ] +[[package]] +name = "windows-link" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a" + [[package]] name = "windows-sys" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets", + "windows-targets 0.52.6", ] [[package]] @@ -2028,7 +2079,16 @@ version = "0.59.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" dependencies = [ - "windows-targets", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" +dependencies = [ + "windows-targets 0.53.3", ] [[package]] @@ -2037,14 +2097,31 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm 0.52.6", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.53.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5fe6031c4041849d7c496a8ded650796e7b6ecc19df1a431c1a363342e5dc91" +dependencies = [ + "windows-link", + "windows_aarch64_gnullvm 0.53.0", + "windows_aarch64_msvc 0.53.0", + "windows_i686_gnu 0.53.0", + "windows_i686_gnullvm 0.53.0", + "windows_i686_msvc 0.53.0", + "windows_x86_64_gnu 0.53.0", + "windows_x86_64_gnullvm 0.53.0", + "windows_x86_64_msvc 0.53.0", ] [[package]] @@ -2053,48 +2130,96 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86b8d5f90ddd19cb4a147a5fa63ca848db3df085e25fee3cc10b39b6eebae764" + [[package]] name = "windows_aarch64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" +[[package]] +name = "windows_aarch64_msvc" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7651a1f62a11b8cbd5e0d42526e55f2c99886c77e007179efff86c2b137e66c" + [[package]] name = "windows_i686_gnu" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" +[[package]] +name = "windows_i686_gnu" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1dc67659d35f387f5f6c479dc4e28f1d4bb90ddd1a5d3da2e5d97b42d6272c3" + [[package]] name = "windows_i686_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" +[[package]] +name = "windows_i686_gnullvm" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ce6ccbdedbf6d6354471319e781c0dfef054c81fbc7cf83f338a4296c0cae11" + [[package]] name = "windows_i686_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" +[[package]] +name = "windows_i686_msvc" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "581fee95406bb13382d2f65cd4a908ca7b1e4c2f1917f143ba16efe98a589b5d" + [[package]] name = "windows_x86_64_gnu" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" +[[package]] +name = "windows_x86_64_gnu" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e55b5ac9ea33f2fc1716d1742db15574fd6fc8dadc51caab1c16a3d3b4190ba" + [[package]] name = "windows_x86_64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a6e035dd0599267ce1ee132e51c27dd29437f63325753051e71dd9e42406c57" + [[package]] name = "windows_x86_64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +[[package]] +name = "windows_x86_64_msvc" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486" + [[package]] name = "wit-bindgen-rt" version = "0.39.0" @@ -2154,18 +2279,18 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.8.25" +version = "0.8.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1702d9583232ddb9174e01bb7c15a2ab8fb1bc6f227aa1233858c351a3ba0cb" +checksum = "1039dd0d3c310cf05de012d8a39ff557cb0d23087fd44cad61df08fc31907a2f" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.8.25" +version = "0.8.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28a6e20d751156648aa063f3800b706ee209a32c0b4d9f24be3d980b01be55ef" +checksum = "9ecf5b4cc5364572d7f4c329661bcc82724222973f2cab6f050a4e5c22f75181" dependencies = [ "proc-macro2", "quote", diff --git a/src/wasm_runtime/Cargo.toml b/src/wasm_runtime/Cargo.toml index 3c2fda6..adf0f68 100644 --- a/src/wasm_runtime/Cargo.toml +++ b/src/wasm_runtime/Cargo.toml @@ -11,9 +11,9 @@ doctest = false bench = false [dependencies] -hyperlight-common = { version = "0.7.0", git = "https://github.com/hyperlight-dev/hyperlight", rev = "ea6fa8f", default-features = false } -hyperlight-guest-bin = { version = "0.7.0", git = "https://github.com/hyperlight-dev/hyperlight", rev = "ea6fa8f", features = [ "printf" ] } -hyperlight-guest = { version = "0.7.0", git = "https://github.com/hyperlight-dev/hyperlight", rev = "ea6fa8f" } +hyperlight-common = { version = "0.7.0", git = "https://github.com/hyperlight-dev/hyperlight", rev = "172fcfa69b0f9064c7a0e48e512f8a86ae1fdbe1", default-features = false } +hyperlight-guest-bin = { version = "0.7.0", git = "https://github.com/hyperlight-dev/hyperlight", rev = "172fcfa69b0f9064c7a0e48e512f8a86ae1fdbe1", features = [ "printf" ] } +hyperlight-guest = { version = "0.7.0", git = "https://github.com/hyperlight-dev/hyperlight", rev = "172fcfa69b0f9064c7a0e48e512f8a86ae1fdbe1" } wasmtime = { version = "35.0.0", default-features = false, features = [ "runtime", "custom-virtual-memory", "custom-native-signals", "component-model" ] } hyperlight-wasm-macro = { path = "../hyperlight_wasm_macro" } spin = "0.9.8" diff --git a/src/wasm_runtime/src/platform.rs b/src/wasm_runtime/src/platform.rs index df15ede..bcd84cb 100644 --- a/src/wasm_runtime/src/platform.rs +++ b/src/wasm_runtime/src/platform.rs @@ -59,7 +59,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); + handler::HANDLERS[14].store(page_fault_handler as usize as u64, Ordering::Release); } // Wasmtime Embedding Interface @@ -155,7 +155,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); + handler::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 From 565d83e5a1d2bf8899fb0ed85f915042510da90f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Doru=20Bl=C3=A2nzeanu?= Date: Wed, 6 Aug 2025 10:17:07 +0300 Subject: [PATCH 2/3] [trace] Define tracing features for hyperlight-wasm crates - These features aim to enable the tracing generation for the hyperlight guests. --- Cargo.lock | 326 +++++++++++++++++---------- Cargo.toml | 2 +- src/hyperlight_wasm/Cargo.toml | 7 +- src/hyperlight_wasm/build.rs | 13 +- src/hyperlight_wasm_macro/Cargo.toml | 2 +- src/wasm_runtime/Cargo.lock | 50 ++-- src/wasm_runtime/Cargo.toml | 12 +- 7 files changed, 271 insertions(+), 141 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 74290b8..d63bb94 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,7 +8,7 @@ version = "0.24.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dfbe277e56a376000877090da837660b4427aad530e3028d44e0bffe4f89a1c1" dependencies = [ - "gimli", + "gimli 0.31.1", ] [[package]] @@ -26,7 +26,7 @@ dependencies = [ "cfg-if", "once_cell", "version_check", - "zerocopy 0.8.25", + "zerocopy 0.8.26", ] [[package]] @@ -158,15 +158,15 @@ checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" [[package]] name = "autocfg" -version = "1.4.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" +checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" [[package]] name = "aws-lc-rs" -version = "1.13.1" +version = "1.13.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93fcc8f365936c834db5514fc45aee5b1202d677e6b40e48468aaaa8183ca8c7" +checksum = "5c953fe1ba023e6b7730c0d4b031d06f267f23a46167dcbd40316644b10a17ba" dependencies = [ "aws-lc-sys", "zeroize", @@ -174,9 +174,9 @@ dependencies = [ [[package]] name = "aws-lc-sys" -version = "0.29.0" +version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61b1d86e7705efe1be1b569bab41d4fa1e14e220b60a160f78de2db687add079" +checksum = "dbfd150b5dbdb988bcc8fb1fe787eb6b7ee6180ca24da683b61ea5405f3d43ff" dependencies = [ "bindgen", "cc", @@ -285,9 +285,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.18.1" +version = "3.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "793db76d6187cd04dff33004d8e6c9cc4e05cd330500379d2394209271b4aeee" +checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43" dependencies = [ "allocator-api2", ] @@ -361,9 +361,9 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" [[package]] name = "cc" -version = "1.2.26" +version = "1.2.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956a5e21988b87f372569b66183b78babf23ebc2e744b733e4350a752c4dafac" +checksum = "c3a42d84bb6b69d3a8b3eaacf0d88f179e1929695e1ad012b6cf64d9caaa5fd2" dependencies = [ "jobserver", "libc", @@ -577,7 +577,7 @@ dependencies = [ "cranelift-control", "cranelift-entity", "cranelift-isle", - "gimli", + "gimli 0.31.1", "hashbrown", "log", "pulley-interpreter", @@ -664,9 +664,9 @@ checksum = "b530783809a55cb68d070e0de60cfbb3db0dc94c8850dd5725411422bedcf6bb" [[package]] name = "crc32fast" -version = "1.4.2" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" +checksum = "9481c1c90cbf2ac953f07c8d4a58aa3945c425b7185c9154d67a65e4230da511" dependencies = [ "cfg-if", ] @@ -749,9 +749,9 @@ checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" [[package]] name = "crunchy" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43da5946c66ffcc7745f48db692ffbb10a83bfe0afd96235c5c2a4fb23994929" +checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5" [[package]] name = "crypto-common" @@ -899,12 +899,12 @@ dependencies = [ [[package]] name = "errno" -version = "0.3.12" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cea14ef9355e3beab063703aa9dab15afd25f0667c341310c1e5274bb1d0da18" +checksum = "778e2ac28f6c47af28e4907f13ffd1e1ddbd400980a9abd7c8df189bf578a5ad" dependencies = [ "libc", - "windows-sys 0.59.0", + "windows-sys 0.60.2", ] [[package]] @@ -963,6 +963,20 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "framehop" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0586ca77af938ae3d66a103d3082ac997b432e82e65d644be6ad2fa340f582d" +dependencies = [ + "arrayvec", + "cfg-if", + "fallible-iterator", + "gimli 0.32.0", + "macho-unwind-info", + "pe-unwind-info", +] + [[package]] name = "fs_extra" version = "1.3.0" @@ -1076,6 +1090,16 @@ dependencies = [ "stable_deref_trait", ] +[[package]] +name = "gimli" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93563d740bc9ef04104f9ed6f86f1e3275c2cdafb95664e26584b9ca807a8ffe" +dependencies = [ + "fallible-iterator", + "stable_deref_trait", +] + [[package]] name = "git2" version = "0.20.2" @@ -1121,9 +1145,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.4.10" +version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9421a676d1b147b16b82c9225157dc629087ef8ec4d5e2960f9437a90dac0a5" +checksum = "17da50a276f1e01e0ba6c029e47b7100754904ee8a278f886546e98575380785" dependencies = [ "atomic-waker", "bytes", @@ -1265,9 +1289,9 @@ dependencies = [ [[package]] name = "hyper-util" -version = "0.1.14" +version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc2fdfdbff08affe55bb779f33b053aa1fe5dd5b54c257343c17edfa55711bdb" +checksum = "8d9b05277c7e8da2c93a568989bb6207bef0112e8d17df7a6eda4a3cf143bc5e" dependencies = [ "bytes", "futures-channel", @@ -1287,7 +1311,7 @@ dependencies = [ [[package]] name = "hyperlight-common" version = "0.7.0" -source = "git+https://github.com/hyperlight-dev/hyperlight?rev=172fcfa69b0f9064c7a0e48e512f8a86ae1fdbe1#172fcfa69b0f9064c7a0e48e512f8a86ae1fdbe1" +source = "git+https://github.com/hyperlight-dev/hyperlight?rev=652affb5811a524db8a9a5a232820fb2e7cda7f2#652affb5811a524db8a9a5a232820fb2e7cda7f2" dependencies = [ "anyhow", "flatbuffers", @@ -1299,7 +1323,7 @@ dependencies = [ [[package]] name = "hyperlight-component-macro" version = "0.7.0" -source = "git+https://github.com/hyperlight-dev/hyperlight?rev=172fcfa69b0f9064c7a0e48e512f8a86ae1fdbe1#172fcfa69b0f9064c7a0e48e512f8a86ae1fdbe1" +source = "git+https://github.com/hyperlight-dev/hyperlight?rev=652affb5811a524db8a9a5a232820fb2e7cda7f2#652affb5811a524db8a9a5a232820fb2e7cda7f2" dependencies = [ "env_logger", "hyperlight-component-util", @@ -1308,13 +1332,13 @@ dependencies = [ "proc-macro2", "quote", "syn", - "wasmparser", + "wasmparser 0.236.0", ] [[package]] name = "hyperlight-component-util" version = "0.7.0" -source = "git+https://github.com/hyperlight-dev/hyperlight?rev=172fcfa69b0f9064c7a0e48e512f8a86ae1fdbe1#172fcfa69b0f9064c7a0e48e512f8a86ae1fdbe1" +source = "git+https://github.com/hyperlight-dev/hyperlight?rev=652affb5811a524db8a9a5a232820fb2e7cda7f2#652affb5811a524db8a9a5a232820fb2e7cda7f2" dependencies = [ "itertools 0.14.0", "log", @@ -1322,13 +1346,33 @@ dependencies = [ "proc-macro2", "quote", "syn", - "wasmparser", + "wasmparser 0.236.0", +] + +[[package]] +name = "hyperlight-guest-tracing" +version = "0.7.0" +source = "git+https://github.com/hyperlight-dev/hyperlight?rev=652affb5811a524db8a9a5a232820fb2e7cda7f2#652affb5811a524db8a9a5a232820fb2e7cda7f2" +dependencies = [ + "hyperlight-common", + "hyperlight-guest-tracing-macro", + "spin", +] + +[[package]] +name = "hyperlight-guest-tracing-macro" +version = "0.7.0" +source = "git+https://github.com/hyperlight-dev/hyperlight?rev=652affb5811a524db8a9a5a232820fb2e7cda7f2#652affb5811a524db8a9a5a232820fb2e7cda7f2" +dependencies = [ + "proc-macro2", + "quote", + "syn", ] [[package]] name = "hyperlight-host" version = "0.7.0" -source = "git+https://github.com/hyperlight-dev/hyperlight?rev=172fcfa69b0f9064c7a0e48e512f8a86ae1fdbe1#172fcfa69b0f9064c7a0e48e512f8a86ae1fdbe1" +source = "git+https://github.com/hyperlight-dev/hyperlight?rev=652affb5811a524db8a9a5a232820fb2e7cda7f2#652affb5811a524db8a9a5a232820fb2e7cda7f2" dependencies = [ "anyhow", "bitflags 2.9.1", @@ -1338,11 +1382,14 @@ dependencies = [ "chrono", "crossbeam-channel", "elfcore", + "fallible-iterator", "flatbuffers", + "framehop", "gdbstub", "gdbstub_arch", "goblin", "hyperlight-common", + "hyperlight-guest-tracing", "kvm-bindings", "kvm-ioctls", "lazy_static", @@ -1395,7 +1442,7 @@ dependencies = [ "once_cell", "page_size", "tar", - "toml 0.9.4", + "toml 0.9.5", "tracing", "windows", ] @@ -1549,15 +1596,26 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.9.0" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cea70ddb795996207ad57735b50c5982d8844f38ba9ee5f1aedcfb708a2aa11e" +checksum = "fe4cd85333e22411419a0bcae1297d25e58c9443848b11dc6a86fefe8c78a661" dependencies = [ "equivalent", "hashbrown", "serde", ] +[[package]] +name = "io-uring" +version = "0.7.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d93587f37623a1a17d94ef2bc9ada592f5465fe7732084ab7beefabe5c77c0c4" +dependencies = [ + "bitflags 2.9.1", + "cfg-if", + "libc", +] + [[package]] name = "ipnet" version = "2.11.0" @@ -1694,9 +1752,9 @@ checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776" [[package]] name = "libgit2-sys" -version = "0.18.1+1.9.0" +version = "0.18.2+1.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1dcb20f84ffcdd825c7a311ae347cce604a6f084a767dec4a4929829645290e" +checksum = "1c42fe03df2bd3c53a3a9c7317ad91d80c81cd1fb0caec8d7cc4cd2bfa10c222" dependencies = [ "cc", "libc", @@ -1711,7 +1769,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "07033963ba89ebaf1584d767badaa2e8fcec21aedea6b8c0346d487d49c28667" dependencies = [ "cfg-if", - "windows-targets 0.53.2", + "windows-targets 0.53.3", ] [[package]] @@ -1722,9 +1780,9 @@ checksum = "f9fbbcab51052fe104eb5e5d351cf728d30a5be1fe14d9be8a3b097481fb97de" [[package]] name = "libredox" -version = "0.1.3" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" +checksum = "391290121bad3d37fbddad76d8f5d1c1c314cfc646d143d7e07a3086ddff0ce3" dependencies = [ "bitflags 2.9.1", "libc", @@ -1786,6 +1844,17 @@ dependencies = [ "libc", ] +[[package]] +name = "macho-unwind-info" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb4bdc8b0ce69932332cf76d24af69c3a155242af95c226b2ab6c2e371ed1149" +dependencies = [ + "thiserror 2.0.12", + "zerocopy 0.8.26", + "zerocopy-derive 0.8.26", +] + [[package]] name = "managed" version = "0.8.0" @@ -1905,7 +1974,7 @@ dependencies = [ "libc", "num_enum", "vmm-sys-util", - "zerocopy 0.8.25", + "zerocopy 0.8.26", ] [[package]] @@ -1973,18 +2042,19 @@ dependencies = [ [[package]] name = "num_enum" -version = "0.7.3" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e613fc340b2220f734a8595782c551f1250e969d87d3be1ae0579e8d4065179" +checksum = "a973b4e44ce6cad84ce69d797acf9a044532e4184c4f267913d1b546a0727b7a" dependencies = [ "num_enum_derive", + "rustversion", ] [[package]] name = "num_enum_derive" -version = "0.7.3" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af1844ef2428cc3e1cb900be36181049ef3d3193c63e43026cfe202983b27a56" +checksum = "77e878c846a8abae00dd069496dbe8751b16ac1c3d6bd2a7283a938e8228f90d" dependencies = [ "proc-macro2", "quote", @@ -2067,6 +2137,19 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" +[[package]] +name = "pe-unwind-info" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "500fa4cdeacd98997c5865e3d0d1cb8fe7e9d7d75ecc775e07989a433a9a9a59" +dependencies = [ + "arrayvec", + "bitflags 2.9.1", + "thiserror 2.0.12", + "zerocopy 0.8.26", + "zerocopy-derive 0.8.26", +] + [[package]] name = "percent-encoding" version = "2.3.1" @@ -2142,9 +2225,9 @@ dependencies = [ [[package]] name = "postcard" -version = "1.1.2" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c1de96e20f51df24ca73cafcc4690e044854d803259db27a00a461cb3b9d17a" +checksum = "6764c3b5dd454e283a30e6dfe78e9b31096d9e32036b5d1eaac7a6119ccb9a24" dependencies = [ "cobs", "embedded-io 0.4.0", @@ -2167,14 +2250,14 @@ version = "0.2.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" dependencies = [ - "zerocopy 0.8.25", + "zerocopy 0.8.26", ] [[package]] name = "prettyplease" -version = "0.2.35" +version = "0.2.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "061c1221631e079b26479d25bbf2275bfe5917ae8419cd7e34f13bfc2aa7539a" +checksum = "ff24dfcda44452b9816fff4cd4227e1bb73ff5a2f1bc1105aa92fb8565ce44d2" dependencies = [ "proc-macro2", "syn", @@ -2238,9 +2321,9 @@ dependencies = [ [[package]] name = "r-efi" -version = "5.2.0" +version = "5.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74765f6d916ee2faa39bc8e68e4f3ed8949b48cccdac59983d287a7cb71ce9c5" +checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" [[package]] name = "radix_trie" @@ -2254,9 +2337,9 @@ dependencies = [ [[package]] name = "rand" -version = "0.9.1" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fbfd9d094a40bf3ae768db9361049ace4c0e04a4fd6b359518bd7b73a73dd97" +checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1" dependencies = [ "rand_chacha", "rand_core", @@ -2321,18 +2404,18 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.5.13" +version = "0.5.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d04b7d0ee6b4a0207a0a7adb104d23ecb0b47d6beae7152d0fa34b692b29fd6" +checksum = "5407465600fb0548f1442edf71dd20683c6ed326200ace4b1ef0763521bb3b77" dependencies = [ "bitflags 2.9.1", ] [[package]] name = "redox_users" -version = "0.5.0" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd6f9d3d47bdd2ad6945c5015a226ec6155d0bcdfd8f7cd29f86b71f8de99d2b" +checksum = "a4e608c6638b9c18977b00b475ac1f28d14e84b27d8d42f70e0bf1e3dec127ac" dependencies = [ "getrandom 0.2.16", "libredox", @@ -2434,9 +2517,9 @@ dependencies = [ [[package]] name = "rustc-demangle" -version = "0.1.25" +version = "0.1.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "989e6739f80c4ad5b13e0fd7fe89531180375b18520cc8c82080e4dc4035b84f" +checksum = "56f7d92ca342cea22a06f2121d944b4fd82af56988c270852495420f961d4ace" [[package]] name = "rustc-hash" @@ -2474,22 +2557,22 @@ dependencies = [ [[package]] name = "rustix" -version = "1.0.7" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c71e83d6afe7ff64890ec6b71d6a69bb8a610ab78ce364b3352876bb4c801266" +checksum = "11181fbabf243db407ef8df94a6ce0b2f9a733bd8be4ad02b4eda9602296cac8" dependencies = [ "bitflags 2.9.1", "errno", "libc", "linux-raw-sys 0.9.4", - "windows-sys 0.59.0", + "windows-sys 0.60.2", ] [[package]] name = "rustls" -version = "0.23.27" +version = "0.23.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "730944ca083c1c233a75c09f199e973ca499344a2b7ba9e755c457e86fb4a321" +checksum = "c0ebcbd2f03de0fc1122ad9bb24b127a5a6cd51d72604a3f3c50ac459762b6cc" dependencies = [ "aws-lc-rs", "once_cell", @@ -2522,9 +2605,9 @@ dependencies = [ [[package]] name = "rustls-webpki" -version = "0.103.3" +version = "0.103.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4a72fe2bcf7a6ac6fd7d0b9e5cb68aeb7d4c0a0271730218b3e92d43b4eb435" +checksum = "0a17884ae0c1b773f1ccd2bd4a8c72f16da897310a98b0e84bf349ad5ead92fc" dependencies = [ "aws-lc-rs", "ring", @@ -2672,9 +2755,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.140" +version = "1.0.142" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373" +checksum = "030fedb782600dcbd6f02d479bf0d817ac3bb40d644745b769d6a96bc3afc5a7" dependencies = [ "itoa", "memchr", @@ -2747,12 +2830,9 @@ checksum = "c1e9a774a6c28142ac54bb25d25562e6bcf957493a184f15ad4eebccb23e410a" [[package]] name = "slab" -version = "0.4.9" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] +checksum = "04dc19736151f35336d325007ac991178d504a119863a2fcb3758cdb5e52c50d" [[package]] name = "smallvec" @@ -2765,12 +2845,12 @@ dependencies = [ [[package]] name = "socket2" -version = "0.5.10" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e22376abed350d73dd1cd119b57ffccad95b4e585a7cda43e286245ce23c0678" +checksum = "233504af464074f9d066d7b5416c5f9b894a5862a6506e306f7b816cdd6f1807" dependencies = [ "libc", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -2910,17 +2990,19 @@ dependencies = [ [[package]] name = "tokio" -version = "1.45.1" +version = "1.47.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75ef51a33ef1da925cea3e4eb122833cb377c61439ca401b770f54902b806779" +checksum = "89e49afdadebb872d3145a5638b59eb0691ea23e46ca484037cfab3b76b95038" dependencies = [ "backtrace", "bytes", + "io-uring", "libc", "mio", "pin-project-lite", + "slab", "socket2", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -2935,9 +3017,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.15" +version = "0.7.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66a539a9ad6d5d281510d5bd368c973d636c02dbf8a67300bfb6b950696ad7df" +checksum = "14307c986784f72ef81c89db7d9e28d6ac26d16213b109ea501696195e6e3ce5" dependencies = [ "bytes", "futures-core", @@ -2960,9 +3042,9 @@ dependencies = [ [[package]] name = "toml" -version = "0.9.4" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41ae868b5a0f67631c14589f7e250c1ea2c574ee5ba21c6c8dd4b1485705a5a1" +checksum = "75129e1dc5000bfbaa9fee9d1b21f974f9fbad9daec557a521ee6e080825f6e8" dependencies = [ "indexmap", "serde", @@ -3007,9 +3089,9 @@ dependencies = [ [[package]] name = "toml_parser" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97200572db069e74c512a14117b296ba0a80a30123fbbb5aa1f4a348f639ca30" +checksum = "b551886f449aa90d4fe2bdaa9f4a2577ad2dde302c61ecf262d80b116db95c10" dependencies = [ "winnow", ] @@ -3046,9 +3128,9 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.29" +version = "0.1.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b1ffbcf9c6f6b99d386e7444eb608ba646ae452a36b39737deb9663b610f662" +checksum = "81383ab64e72a7a8b8e13130c49e3dab29def6d0c7d76a03087b3cf71c5c6903" dependencies = [ "proc-macro2", "quote", @@ -3273,7 +3355,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3bc393c395cb621367ff02d854179882b9a351b4e0c93d1397e6090b53a5c2a" dependencies = [ "leb128fmt", - "wasmparser", + "wasmparser 0.235.0", ] [[package]] @@ -3289,6 +3371,19 @@ dependencies = [ "serde", ] +[[package]] +name = "wasmparser" +version = "0.236.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16d1eee846a705f6f3cb9d7b9f79b54583810f1fb57a1e3aea76d1742db2e3d2" +dependencies = [ + "bitflags 2.9.1", + "hashbrown", + "indexmap", + "semver", + "serde", +] + [[package]] name = "wasmprinter" version = "0.235.0" @@ -3297,7 +3392,7 @@ checksum = "75aa8e9076de6b9544e6dab4badada518cca0bf4966d35b131bbd057aed8fa0a" dependencies = [ "anyhow", "termcolor", - "wasmparser", + "wasmparser 0.235.0", ] [[package]] @@ -3323,13 +3418,13 @@ dependencies = [ "once_cell", "postcard", "pulley-interpreter", - "rustix 1.0.7", + "rustix 1.0.8", "semver", "serde", "serde_derive", "smallvec", "target-lexicon", - "wasmparser", + "wasmparser 0.235.0", "wasmtime-environ", "wasmtime-internal-asm-macros", "wasmtime-internal-component-macro", @@ -3354,7 +3449,7 @@ dependencies = [ "anyhow", "cranelift-bitset", "cranelift-entity", - "gimli", + "gimli 0.31.1", "indexmap", "log", "object", @@ -3365,7 +3460,7 @@ dependencies = [ "smallvec", "target-lexicon", "wasm-encoder", - "wasmparser", + "wasmparser 0.235.0", "wasmprinter", "wasmtime-internal-component-util", ] @@ -3413,7 +3508,7 @@ dependencies = [ "cranelift-entity", "cranelift-frontend", "cranelift-native", - "gimli", + "gimli 0.31.1", "itertools 0.14.0", "log", "object", @@ -3421,7 +3516,7 @@ dependencies = [ "smallvec", "target-lexicon", "thiserror 2.0.12", - "wasmparser", + "wasmparser 0.235.0", "wasmtime-environ", "wasmtime-internal-math", "wasmtime-internal-versioned-export-macros", @@ -3437,7 +3532,7 @@ dependencies = [ "cc", "cfg-if", "libc", - "rustix 1.0.7", + "rustix 1.0.8", "wasmtime-internal-asm-macros", "wasmtime-internal-versioned-export-macros", "windows-sys 0.59.0", @@ -3502,10 +3597,10 @@ checksum = "2012e7384c25b91aab2f1b6a1e1cbab9d0f199bbea06cc873597a3f047f05730" dependencies = [ "anyhow", "cranelift-codegen", - "gimli", + "gimli 0.31.1", "object", "target-lexicon", - "wasmparser", + "wasmparser 0.235.0", "wasmtime-environ", "wasmtime-internal-cranelift", "winch-codegen", @@ -3585,12 +3680,12 @@ dependencies = [ "anyhow", "cranelift-assembler-x64", "cranelift-codegen", - "gimli", + "gimli 0.31.1", "regalloc2", "smallvec", "target-lexicon", "thiserror 2.0.12", - "wasmparser", + "wasmparser 0.235.0", "wasmtime-environ", "wasmtime-internal-cranelift", "wasmtime-internal-math", @@ -3722,7 +3817,7 @@ version = "0.60.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" dependencies = [ - "windows-targets 0.53.2", + "windows-targets 0.53.3", ] [[package]] @@ -3743,10 +3838,11 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.53.2" +version = "0.53.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c66f69fcc9ce11da9966ddb31a40968cad001c5bedeb5c2b82ede4253ab48aef" +checksum = "d5fe6031c4041849d7c496a8ded650796e7b6ecc19df1a431c1a363342e5dc91" dependencies = [ + "windows-link", "windows_aarch64_gnullvm 0.53.0", "windows_aarch64_msvc 0.53.0", "windows_i686_gnu 0.53.0", @@ -3873,9 +3969,9 @@ checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486" [[package]] name = "winnow" -version = "0.7.11" +version = "0.7.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74c7b26e3480b707944fc872477815d29a8e429d2f93a1ce000f5fa84a15cbcd" +checksum = "f3edebf492c8125044983378ecb5766203ad3b4c2f7a922bd7dd207f6d443e95" dependencies = [ "memchr", ] @@ -3904,7 +4000,7 @@ dependencies = [ "serde_derive", "serde_json", "unicode-xid", - "wasmparser", + "wasmparser 0.235.0", ] [[package]] @@ -3915,12 +4011,12 @@ checksum = "ea2f10b9bb0928dfb1b42b65e1f9e36f7f54dbdf08457afefb38afcdec4fa2bb" [[package]] name = "xattr" -version = "1.5.0" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d65cbf2f12c15564212d48f4e3dfb87923d25d611f2aed18f4cb23f0413d89e" +checksum = "af3a19837351dc82ba89f8a125e22a3c475f05aba604acc023d62b2739ae2909" dependencies = [ "libc", - "rustix 1.0.7", + "rustix 1.0.8", ] [[package]] @@ -3959,11 +4055,11 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.8.25" +version = "0.8.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1702d9583232ddb9174e01bb7c15a2ab8fb1bc6f227aa1233858c351a3ba0cb" +checksum = "1039dd0d3c310cf05de012d8a39ff557cb0d23087fd44cad61df08fc31907a2f" dependencies = [ - "zerocopy-derive 0.8.25", + "zerocopy-derive 0.8.26", ] [[package]] @@ -3979,9 +4075,9 @@ dependencies = [ [[package]] name = "zerocopy-derive" -version = "0.8.25" +version = "0.8.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28a6e20d751156648aa063f3800b706ee209a32c0b4d9f24be3d980b01be55ef" +checksum = "9ecf5b4cc5364572d7f4c329661bcc82724222973f2cab6f050a4e5c22f75181" dependencies = [ "proc-macro2", "quote", @@ -4028,9 +4124,9 @@ dependencies = [ [[package]] name = "zerovec" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a05eb080e015ba39cc9e23bbe5e7fb04d5fb040350f99f34e338d5fdd294428" +checksum = "bdbb9122ea75b11bf96e7492afb723e8a7fbe12c67417aa95e7e3d18144d37cd" dependencies = [ "yoke", "zerofrom", diff --git a/Cargo.toml b/Cargo.toml index 0d3d43d..299cc41 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,4 +13,4 @@ repository = "https://github.com/hyperlight-dev/hyperlight-wasm" readme = "README.md" [workspace.dependencies] -hyperlight-host = { version = "0.7.0", git = "https://github.com/hyperlight-dev/hyperlight", rev = "172fcfa69b0f9064c7a0e48e512f8a86ae1fdbe1", default-features = false, features = ["executable_heap", "init-paging"] } +hyperlight-host = { version = "0.7.0", git = "https://github.com/hyperlight-dev/hyperlight", rev = "652affb5811a524db8a9a5a232820fb2e7cda7f2", default-features = false, features = ["executable_heap", "init-paging"] } diff --git a/src/hyperlight_wasm/Cargo.toml b/src/hyperlight_wasm/Cargo.toml index 0edd0b3..9dddc29 100644 --- a/src/hyperlight_wasm/Cargo.toml +++ b/src/hyperlight_wasm/Cargo.toml @@ -58,7 +58,7 @@ windows = { version = "0.61", features = ["Win32_System_Threading"] } page_size = "0.6.0" [dev-dependencies] -hyperlight-component-macro = { version = "0.7.0", git = "https://github.com/hyperlight-dev/hyperlight", rev = "172fcfa69b0f9064c7a0e48e512f8a86ae1fdbe1" } +hyperlight-component-macro = { version = "0.7.0", git = "https://github.com/hyperlight-dev/hyperlight", rev = "652affb5811a524db8a9a5a232820fb2e7cda7f2" } examples_common = { path = "../examples_common" } criterion = { version = "0.7.0", features = ["html_reports"] } crossbeam-queue = "0.3" @@ -76,11 +76,14 @@ goblin = "0.10.0" tar = "0.4.44" [features] -default = ["function_call_metrics", "kvm", "mshv2"] +default = ["function_call_metrics", "kvm", "mshv3"] gdb = ["hyperlight-host/gdb"] function_call_metrics = ["hyperlight-host/function_call_metrics"] seccomp = ["hyperlight-host/seccomp"] print_debug = ["hyperlight-host/print_debug"] +trace_guest = ["hyperlight-host/trace_guest"] +mem_profile = ["hyperlight-host/mem_profile"] +unwind_guest = ["hyperlight-host/unwind_guest"] crashdump = ["hyperlight-host/crashdump"] kvm = ["hyperlight-host/kvm"] mshv2 = ["hyperlight-host/mshv2"] diff --git a/src/hyperlight_wasm/build.rs b/src/hyperlight_wasm/build.rs index 7ed72a5..daab345 100644 --- a/src/hyperlight_wasm/build.rs +++ b/src/hyperlight_wasm/build.rs @@ -114,7 +114,7 @@ fn build_wasm_runtime() -> PathBuf { let mut env_vars = env::vars().collect::>(); env_vars.retain(|(key, _)| !key.starts_with("CARGO_")); - let cmd = cmd + let mut cmd = cmd .arg("build") .arg("--profile") .arg(cargo_profile) @@ -125,6 +125,17 @@ fn build_wasm_runtime() -> PathBuf { .env_clear() .envs(env_vars); + // If trace_guest feature is enabled, pass it as an argument to the build command + if env::var("CARGO_FEATURE_TRACE_GUEST").is_ok() { + cmd = cmd.arg("--features").arg("trace_guest"); + } + if env::var("CARGO_FEATURE_MEM_PROFILE").is_ok() { + cmd = cmd.arg("--features").arg("mem_profile"); + } + if env::var("CARGO_FEATURE_UNWIND_GUEST").is_ok() { + cmd = cmd.arg("--features").arg("unwind_guest"); + } + let status = cmd .status() .unwrap_or_else(|e| panic!("could not run cargo build: {}", e)); diff --git a/src/hyperlight_wasm_macro/Cargo.toml b/src/hyperlight_wasm_macro/Cargo.toml index 516ffae..5a506cb 100644 --- a/src/hyperlight_wasm_macro/Cargo.toml +++ b/src/hyperlight_wasm_macro/Cargo.toml @@ -16,4 +16,4 @@ proc-macro2 = { version = "1.0.93" } syn = { version = "2.0.96" } itertools = { version = "0.14.0" } prettyplease = { version = "0.2.31" } -hyperlight-component-util = { version = "0.7.0", git = "https://github.com/hyperlight-dev/hyperlight", rev = "172fcfa69b0f9064c7a0e48e512f8a86ae1fdbe1" } +hyperlight-component-util = { version = "0.7.0", git = "https://github.com/hyperlight-dev/hyperlight", rev = "652affb5811a524db8a9a5a232820fb2e7cda7f2" } diff --git a/src/wasm_runtime/Cargo.lock b/src/wasm_runtime/Cargo.lock index b89c918..fb6ac6a 100644 --- a/src/wasm_runtime/Cargo.lock +++ b/src/wasm_runtime/Cargo.lock @@ -604,7 +604,7 @@ dependencies = [ [[package]] name = "hyperlight-common" version = "0.7.0" -source = "git+https://github.com/hyperlight-dev/hyperlight?rev=172fcfa69b0f9064c7a0e48e512f8a86ae1fdbe1#172fcfa69b0f9064c7a0e48e512f8a86ae1fdbe1" +source = "git+https://github.com/hyperlight-dev/hyperlight?rev=652affb5811a524db8a9a5a232820fb2e7cda7f2#652affb5811a524db8a9a5a232820fb2e7cda7f2" dependencies = [ "anyhow", "flatbuffers", @@ -615,7 +615,7 @@ dependencies = [ [[package]] name = "hyperlight-component-util" version = "0.7.0" -source = "git+https://github.com/hyperlight-dev/hyperlight?rev=172fcfa69b0f9064c7a0e48e512f8a86ae1fdbe1#172fcfa69b0f9064c7a0e48e512f8a86ae1fdbe1" +source = "git+https://github.com/hyperlight-dev/hyperlight?branch=main#104f62a5fb63dac48457e5dec87b4bb780be5a0e" dependencies = [ "itertools", "log", @@ -623,24 +623,24 @@ dependencies = [ "proc-macro2", "quote", "syn", - "wasmparser", + "wasmparser 0.236.0", ] [[package]] name = "hyperlight-guest" version = "0.7.0" -source = "git+https://github.com/hyperlight-dev/hyperlight?rev=172fcfa69b0f9064c7a0e48e512f8a86ae1fdbe1#172fcfa69b0f9064c7a0e48e512f8a86ae1fdbe1" +source = "git+https://github.com/hyperlight-dev/hyperlight?rev=652affb5811a524db8a9a5a232820fb2e7cda7f2#652affb5811a524db8a9a5a232820fb2e7cda7f2" dependencies = [ "anyhow", "hyperlight-common", - "hyperlight-guest-tracing-macro", + "hyperlight-guest-tracing", "serde_json", ] [[package]] name = "hyperlight-guest-bin" version = "0.7.0" -source = "git+https://github.com/hyperlight-dev/hyperlight?rev=172fcfa69b0f9064c7a0e48e512f8a86ae1fdbe1#172fcfa69b0f9064c7a0e48e512f8a86ae1fdbe1" +source = "git+https://github.com/hyperlight-dev/hyperlight?rev=652affb5811a524db8a9a5a232820fb2e7cda7f2#652affb5811a524db8a9a5a232820fb2e7cda7f2" dependencies = [ "buddy_system_allocator", "cc", @@ -648,7 +648,7 @@ dependencies = [ "glob", "hyperlight-common", "hyperlight-guest", - "hyperlight-guest-tracing-macro", + "hyperlight-guest-tracing", "log", "spin 0.10.0", ] @@ -656,18 +656,18 @@ dependencies = [ [[package]] name = "hyperlight-guest-tracing" version = "0.7.0" -source = "git+https://github.com/hyperlight-dev/hyperlight?rev=172fcfa69b0f9064c7a0e48e512f8a86ae1fdbe1#172fcfa69b0f9064c7a0e48e512f8a86ae1fdbe1" +source = "git+https://github.com/hyperlight-dev/hyperlight?rev=652affb5811a524db8a9a5a232820fb2e7cda7f2#652affb5811a524db8a9a5a232820fb2e7cda7f2" dependencies = [ "hyperlight-common", + "hyperlight-guest-tracing-macro", "spin 0.10.0", ] [[package]] name = "hyperlight-guest-tracing-macro" version = "0.7.0" -source = "git+https://github.com/hyperlight-dev/hyperlight?rev=172fcfa69b0f9064c7a0e48e512f8a86ae1fdbe1#172fcfa69b0f9064c7a0e48e512f8a86ae1fdbe1" +source = "git+https://github.com/hyperlight-dev/hyperlight?rev=652affb5811a524db8a9a5a232820fb2e7cda7f2#652affb5811a524db8a9a5a232820fb2e7cda7f2" dependencies = [ - "hyperlight-guest-tracing", "proc-macro2", "quote", "syn", @@ -1768,7 +1768,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3bc393c395cb621367ff02d854179882b9a351b4e0c93d1397e6090b53a5c2a" dependencies = [ "leb128fmt", - "wasmparser", + "wasmparser 0.235.0", ] [[package]] @@ -1781,6 +1781,7 @@ dependencies = [ "hyperlight-common", "hyperlight-guest", "hyperlight-guest-bin", + "hyperlight-guest-tracing", "hyperlight-wasm-macro", "reqwest", "spin 0.9.8", @@ -1800,6 +1801,19 @@ dependencies = [ "serde", ] +[[package]] +name = "wasmparser" +version = "0.236.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16d1eee846a705f6f3cb9d7b9f79b54583810f1fb57a1e3aea76d1742db2e3d2" +dependencies = [ + "bitflags", + "hashbrown", + "indexmap", + "semver", + "serde", +] + [[package]] name = "wasmprinter" version = "0.235.0" @@ -1808,7 +1822,7 @@ checksum = "75aa8e9076de6b9544e6dab4badada518cca0bf4966d35b131bbd057aed8fa0a" dependencies = [ "anyhow", "termcolor", - "wasmparser", + "wasmparser 0.235.0", ] [[package]] @@ -1837,7 +1851,7 @@ dependencies = [ "serde_derive", "smallvec", "target-lexicon", - "wasmparser", + "wasmparser 0.235.0", "wasmtime-environ", "wasmtime-internal-asm-macros", "wasmtime-internal-component-macro", @@ -1871,7 +1885,7 @@ dependencies = [ "smallvec", "target-lexicon", "wasm-encoder", - "wasmparser", + "wasmparser 0.235.0", "wasmprinter", "wasmtime-internal-component-util", ] @@ -1927,7 +1941,7 @@ dependencies = [ "smallvec", "target-lexicon", "thiserror", - "wasmparser", + "wasmparser 0.235.0", "wasmtime-environ", "wasmtime-internal-math", "wasmtime-internal-versioned-export-macros", @@ -1982,7 +1996,7 @@ dependencies = [ "gimli", "object", "target-lexicon", - "wasmparser", + "wasmparser 0.235.0", "wasmtime-environ", "wasmtime-internal-cranelift", "winch-codegen", @@ -2052,7 +2066,7 @@ dependencies = [ "smallvec", "target-lexicon", "thiserror", - "wasmparser", + "wasmparser 0.235.0", "wasmtime-environ", "wasmtime-internal-cranelift", "wasmtime-internal-math", @@ -2244,7 +2258,7 @@ dependencies = [ "serde_derive", "serde_json", "unicode-xid", - "wasmparser", + "wasmparser 0.235.0", ] [[package]] diff --git a/src/wasm_runtime/Cargo.toml b/src/wasm_runtime/Cargo.toml index adf0f68..273aaa1 100644 --- a/src/wasm_runtime/Cargo.toml +++ b/src/wasm_runtime/Cargo.toml @@ -11,11 +11,12 @@ doctest = false bench = false [dependencies] -hyperlight-common = { version = "0.7.0", git = "https://github.com/hyperlight-dev/hyperlight", rev = "172fcfa69b0f9064c7a0e48e512f8a86ae1fdbe1", default-features = false } -hyperlight-guest-bin = { version = "0.7.0", git = "https://github.com/hyperlight-dev/hyperlight", rev = "172fcfa69b0f9064c7a0e48e512f8a86ae1fdbe1", features = [ "printf" ] } -hyperlight-guest = { version = "0.7.0", git = "https://github.com/hyperlight-dev/hyperlight", rev = "172fcfa69b0f9064c7a0e48e512f8a86ae1fdbe1" } +hyperlight-common = { version = "0.7.0", git = "https://github.com/hyperlight-dev/hyperlight", rev = "652affb5811a524db8a9a5a232820fb2e7cda7f2", default-features = false } +hyperlight-guest-bin = { version = "0.7.0", git = "https://github.com/hyperlight-dev/hyperlight", rev = "652affb5811a524db8a9a5a232820fb2e7cda7f2", features = [ "printf" ] } +hyperlight-guest = { version = "0.7.0", git = "https://github.com/hyperlight-dev/hyperlight", rev = "652affb5811a524db8a9a5a232820fb2e7cda7f2" } wasmtime = { version = "35.0.0", default-features = false, features = [ "runtime", "custom-virtual-memory", "custom-native-signals", "component-model" ] } hyperlight-wasm-macro = { path = "../hyperlight_wasm_macro" } +hyperlight-guest-tracing = { version = "0.7.0", git = "https://github.com/hyperlight-dev/hyperlight", rev = "652affb5811a524db8a9a5a232820fb2e7cda7f2" } spin = "0.9.8" [build-dependencies] @@ -25,3 +26,8 @@ cargo_metadata = "0.19" reqwest = {version = "0.12", default-features = false, features = ["blocking","rustls-tls"] } [workspace] # indicate that this crate is not part of any workspace + +[features] +trace_guest = ["hyperlight-common/trace_guest", "hyperlight-guest/trace_guest", "hyperlight-guest-bin/trace_guest", "hyperlight-guest-tracing/trace"] +mem_profile = ["hyperlight-guest-bin/mem_profile", "hyperlight-common/mem_profile"] +unwind_guest = ["hyperlight-common/unwind_guest"] From 70af69b178b00fd0c8ffe8b091335e1924cf8279 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Doru=20Bl=C3=A2nzeanu?= Date: Wed, 6 Aug 2025 10:21:26 +0300 Subject: [PATCH 3/3] [trace] Add instrumentation of hyperlight-wasm code - generate tracing records for `wasm_runtime` to produce timing information at runtime --- src/wasm_runtime/src/component.rs | 6 ++++++ src/wasm_runtime/src/hostfuncs.rs | 3 +++ src/wasm_runtime/src/marshal.rs | 8 ++++++++ src/wasm_runtime/src/module.rs | 5 +++++ src/wasm_runtime/src/platform.rs | 20 ++++++++++++++++++++ 5 files changed, 42 insertions(+) diff --git a/src/wasm_runtime/src/component.rs b/src/wasm_runtime/src/component.rs index c14f8cb..33cd8fe 100644 --- a/src/wasm_runtime/src/component.rs +++ b/src/wasm_runtime/src/component.rs @@ -43,10 +43,12 @@ static CUR_INSTANCE: Mutex> = Mutex::new(None); hyperlight_wasm_macro::wasm_guest_bindgen!(); // dummy for compatibility with the module loading approach +#[hyperlight_guest_tracing::trace_function] fn init_wasm_runtime(_function_call: &FunctionCall) -> Result> { Ok(get_flatbuffer_result::(0)) } +#[hyperlight_guest_tracing::trace_function] fn load_component_common(engine: &Engine, component: Component) -> Result<()> { let mut store = Store::new(engine, ()); let instance = (*CUR_LINKER.lock()) @@ -58,6 +60,7 @@ fn load_component_common(engine: &Engine, component: Component) -> Result<()> { Ok(()) } +#[hyperlight_guest_tracing::trace_function] fn load_wasm_module(function_call: &FunctionCall) -> Result> { if let ( ParameterValue::VecBytes(ref wasm_bytes), @@ -79,6 +82,7 @@ fn load_wasm_module(function_call: &FunctionCall) -> Result> { } } +#[hyperlight_guest_tracing::trace_function] 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], @@ -98,6 +102,7 @@ fn load_wasm_module_phys(function_call: &FunctionCall) -> Result> { } #[no_mangle] +#[hyperlight_guest_tracing::trace_function] pub extern "C" fn hyperlight_main() { platform::register_page_fault_handler(); @@ -131,6 +136,7 @@ pub extern "C" fn hyperlight_main() { } #[no_mangle] +#[hyperlight_guest_tracing::trace_function] pub fn guest_dispatch_function(function_call: FunctionCall) -> Result> { Err(HyperlightGuestError::new( ErrorCode::GuestFunctionNotFound, diff --git a/src/wasm_runtime/src/hostfuncs.rs b/src/wasm_runtime/src/hostfuncs.rs index 943d411..3a7dfce 100644 --- a/src/wasm_runtime/src/hostfuncs.rs +++ b/src/wasm_runtime/src/hostfuncs.rs @@ -36,6 +36,7 @@ pub(crate) fn get_host_function_details() -> HostFunctionDetails { hyperlight_guest_bin::host_comm::get_host_function_details() } +#[hyperlight_guest_tracing::trace_function] pub(crate) fn hostfunc_type(d: &HostFunctionDefinition, e: &Engine) -> Result { let mut params = Vec::new(); let mut last_was_vec = false; @@ -79,6 +80,7 @@ pub(crate) fn hostfunc_type(d: &HostFunctionDefinition, e: &Engine) -> Result, @@ -115,6 +117,7 @@ pub(crate) fn call( Ok(()) } +#[hyperlight_guest_tracing::trace_function] fn return_type_from_val(val: &ReturnValue) -> ReturnType { match val { ReturnValue::Int(_) => ReturnType::Int, diff --git a/src/wasm_runtime/src/marshal.rs b/src/wasm_runtime/src/marshal.rs index 3ce22c0..c330009 100644 --- a/src/wasm_runtime/src/marshal.rs +++ b/src/wasm_runtime/src/marshal.rs @@ -29,6 +29,7 @@ use hyperlight_common::flatbuffer_wrappers::util::get_flatbuffer_result; use hyperlight_guest::error::{HyperlightGuestError, Result}; use wasmtime::{AsContextMut, Extern, Val}; +#[hyperlight_guest_tracing::trace_function] fn malloc( ctx: &mut C, get_export: &impl Fn(&mut C, &str) -> Option, @@ -46,6 +47,7 @@ fn malloc( Ok(addr) } +#[hyperlight_guest_tracing::trace_function] fn write( ctx: &mut C, get_export: &impl Fn(&mut C, &str) -> Option, @@ -67,6 +69,7 @@ fn write( Ok(()) } +#[hyperlight_guest_tracing::trace_function] fn read( ctx: &mut C, get_export: &impl Fn(&mut C, &str) -> Option, @@ -88,6 +91,7 @@ fn read( Ok(()) } +#[hyperlight_guest_tracing::trace_function] fn read_cstr( ctx: &mut C, get_export: &impl Fn(&mut C, &str) -> Option, @@ -126,6 +130,7 @@ fn read_cstr( }) } +#[hyperlight_guest_tracing::trace_function] pub fn hl_param_to_val( mut ctx: C, get_export: impl Fn(&mut C, &str) -> Option, @@ -155,6 +160,7 @@ pub fn hl_param_to_val( } } +#[hyperlight_guest_tracing::trace_function] pub fn val_to_hl_result( mut ctx: C, get_export: impl Fn(&mut C, &str) -> Option, @@ -198,6 +204,7 @@ pub fn val_to_hl_result( } } +#[hyperlight_guest_tracing::trace_function] pub fn val_to_hl_param<'a, C: AsContextMut>( ctx: &mut C, get_export: impl Fn(&mut C, &str) -> Option, @@ -248,6 +255,7 @@ pub fn val_to_hl_param<'a, C: AsContextMut>( } } +#[hyperlight_guest_tracing::trace_function] pub fn hl_return_to_val( ctx: &mut C, get_export: impl Fn(&mut C, &str) -> Option, diff --git a/src/wasm_runtime/src/module.rs b/src/wasm_runtime/src/module.rs index c9aec48..b13b36f 100644 --- a/src/wasm_runtime/src/module.rs +++ b/src/wasm_runtime/src/module.rs @@ -39,6 +39,7 @@ static CUR_LINKER: Mutex>> = Mutex::new(None); static CUR_MODULE: Mutex> = Mutex::new(None); #[no_mangle] +#[hyperlight_guest_tracing::trace_function] pub fn guest_dispatch_function(function_call: &FunctionCall) -> Result> { let engine = CUR_ENGINE.lock(); let engine = engine.deref().as_ref().ok_or(HyperlightGuestError::new( @@ -87,6 +88,7 @@ pub fn guest_dispatch_function(function_call: &FunctionCall) -> Result> ) } +#[hyperlight_guest_tracing::trace_function] fn init_wasm_runtime() -> Result> { let mut config = Config::new(); config.with_custom_code_memory(Some(alloc::sync::Arc::new(platform::WasmtimeCodeMemory {}))); @@ -114,6 +116,7 @@ fn init_wasm_runtime() -> Result> { Ok(get_flatbuffer_result::(0)) } +#[hyperlight_guest_tracing::trace_function] fn load_wasm_module(function_call: &FunctionCall) -> Result> { if let ( ParameterValue::VecBytes(ref wasm_bytes), @@ -135,6 +138,7 @@ fn load_wasm_module(function_call: &FunctionCall) -> Result> { } } +#[hyperlight_guest_tracing::trace_function] 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], @@ -154,6 +158,7 @@ fn load_wasm_module_phys(function_call: &FunctionCall) -> Result> { #[no_mangle] #[allow(clippy::fn_to_numeric_cast)] // GuestFunctionDefinition expects a function pointer as i64 +#[hyperlight_guest_tracing::trace_function] pub extern "C" fn hyperlight_main() { platform::register_page_fault_handler(); diff --git a/src/wasm_runtime/src/platform.rs b/src/wasm_runtime/src/platform.rs index bcd84cb..78685a3 100644 --- a/src/wasm_runtime/src/platform.rs +++ b/src/wasm_runtime/src/platform.rs @@ -26,6 +26,8 @@ use hyperlight_guest_bin::paging; // we start at // 0x100_0000_0000 and go up from there static FIRST_VADDR: AtomicU64 = AtomicU64::new(0x100_0000_0000u64); + +#[hyperlight_guest_tracing::trace_function] fn page_fault_handler( _exception_number: u64, info: *mut handler::ExceptionInfo, @@ -54,6 +56,8 @@ fn page_fault_handler( } false } + +#[hyperlight_guest_tracing::trace_function] pub(crate) fn register_page_fault_handler() { // On amd64, vector 14 is #PF // See AMD64 Architecture Programmer's Manual, Volume 2 @@ -70,6 +74,7 @@ pub(crate) fn register_page_fault_handler() { * page-fault handling to hardcoded check if memory is in this region * (see above) */ #[no_mangle] +#[hyperlight_guest_tracing::trace_function] pub extern "C" fn wasmtime_mmap_new(_size: usize, _prot_flags: u32, ret: &mut *mut u8) -> i32 { if _size > 0x100_0000_0000 { panic!("wasmtime_mmap_{:x} {:x}", _size, _prot_flags); @@ -83,6 +88,7 @@ pub extern "C" fn wasmtime_mmap_new(_size: usize, _prot_flags: u32, ret: &mut *m * the same), or possibly for changing permissions, which will be a no-op * as we don't properly implement permissions at the moment. */ #[no_mangle] +#[hyperlight_guest_tracing::trace_function] pub extern "C" fn wasmtime_mmap_remap(addr: *mut u8, size: usize, prot_flags: u32) -> i32 { if size > 0x100_0000_0000 { panic!( @@ -94,12 +100,14 @@ pub extern "C" fn wasmtime_mmap_remap(addr: *mut u8, size: usize, prot_flags: u3 } #[no_mangle] +#[hyperlight_guest_tracing::trace_function] pub extern "C" fn wasmtime_munmap(_ptr: *mut u8, _size: usize) -> i32 { 0 } /* TODO: implement permissions properly */ #[no_mangle] +#[hyperlight_guest_tracing::trace_function] pub extern "C" fn wasmtime_mprotect(_ptr: *mut u8, _size: usize, prot_flags: u32) -> i32 { /* currently all memory is allocated RWX; we assume that * restricting to R or RX can be ignored */ @@ -110,6 +118,7 @@ pub extern "C" fn wasmtime_mprotect(_ptr: *mut u8, _size: usize, prot_flags: u32 } #[no_mangle] +#[hyperlight_guest_tracing::trace_function] pub extern "C" fn wasmtime_page_size() -> usize { unsafe { hyperlight_guest_bin::OS_PAGE_SIZE as usize } } @@ -118,6 +127,8 @@ pub extern "C" fn wasmtime_page_size() -> usize { type wasmtime_trap_handler_t = extern "C" fn(ip: usize, fp: usize, has_faulting_addr: bool, faulting_addr: usize); static WASMTIME_REQUESTED_TRAP_HANDLER: AtomicU64 = AtomicU64::new(0); + +#[hyperlight_guest_tracing::trace_function] fn wasmtime_trap_handler( exception_number: u64, info: *mut handler::ExceptionInfo, @@ -149,6 +160,7 @@ fn wasmtime_trap_handler( } #[no_mangle] +#[hyperlight_guest_tracing::trace_function] pub extern "C" fn wasmtime_init_traps(handler: wasmtime_trap_handler_t) -> i32 { WASMTIME_REQUESTED_TRAP_HANDLER.store(handler as usize as u64, Ordering::Relaxed); // On amd64, vector 6 is #UD @@ -168,6 +180,7 @@ pub extern "C" fn wasmtime_init_traps(handler: wasmtime_trap_handler_t) -> i32 { // The wasmtime_memory_image APIs are not yet supported. #[no_mangle] +#[hyperlight_guest_tracing::trace_function] pub extern "C" fn wasmtime_memory_image_new( _ptr: *const u8, _len: usize, @@ -178,6 +191,7 @@ pub extern "C" fn wasmtime_memory_image_new( } #[no_mangle] +#[hyperlight_guest_tracing::trace_function] pub extern "C" fn wasmtime_memory_image_map_at( _image: *mut c_void, _addr: *mut u8, @@ -189,6 +203,7 @@ pub extern "C" fn wasmtime_memory_image_map_at( } #[no_mangle] +#[hyperlight_guest_tracing::trace_function] pub extern "C" fn wasmtime_memory_image_free(_image: *mut c_void) { /* This should never be called because wasmtime_memory_image_new * returns NULL */ @@ -198,11 +213,15 @@ pub extern "C" fn wasmtime_memory_image_free(_image: *mut c_void) { /* Because we only have a single thread in the guest at the moment, we * don't need real thread-local storage. */ static FAKE_TLS: AtomicPtr = AtomicPtr::new(core::ptr::null_mut()); + #[no_mangle] +#[hyperlight_guest_tracing::trace_function] pub extern "C" fn wasmtime_tls_get() -> *mut u8 { FAKE_TLS.load(Ordering::Acquire) } + #[no_mangle] +#[hyperlight_guest_tracing::trace_function] pub extern "C" fn wasmtime_tls_set(ptr: *mut u8) { FAKE_TLS.store(ptr, Ordering::Release) } @@ -229,6 +248,7 @@ impl wasmtime::CustomCodeMemory for WasmtimeCodeMemory { } } +#[hyperlight_guest_tracing::trace_function] pub(crate) unsafe fn map_buffer(phys: u64, len: u64) -> NonNull<[u8]> { // TODO: Use a VA allocator let virt = phys as *mut u8;