From 52a5bf8663459a9714f8d01a318e24ccd06508d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Doru=20Bl=C3=A2nzeanu?= Date: Thu, 24 Jul 2025 16:25:36 +0300 Subject: [PATCH 1/2] Re-export macros in hyperlight_guest_tracing for ease of use MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Doru Blânzeanu --- Cargo.lock | 4 +- src/hyperlight_guest/Cargo.toml | 5 +- src/hyperlight_guest/src/exit.rs | 16 ++--- .../src/guest_handle/host_comm.rs | 14 ++--- src/hyperlight_guest/src/guest_handle/io.rs | 8 +-- src/hyperlight_guest_bin/Cargo.toml | 5 +- .../src/exceptions/gdt.rs | 2 +- .../src/exceptions/handler.rs | 4 +- .../src/exceptions/idt.rs | 2 +- .../src/exceptions/idtr.rs | 2 +- .../src/guest_function/call.rs | 10 ++-- src/hyperlight_guest_bin/src/lib.rs | 2 +- src/hyperlight_guest_bin/src/paging.rs | 1 + src/hyperlight_guest_tracing/Cargo.toml | 1 + src/hyperlight_guest_tracing/src/lib.rs | 4 ++ src/hyperlight_guest_tracing_macro/Cargo.toml | 1 - src/hyperlight_guest_tracing_macro/src/lib.rs | 60 +++++++++---------- .../rust_guests/callbackguest/Cargo.lock | 4 +- src/tests/rust_guests/dummyguest/Cargo.lock | 4 +- src/tests/rust_guests/simpleguest/Cargo.lock | 4 +- src/tests/rust_guests/witguest/Cargo.lock | 4 +- 21 files changed, 75 insertions(+), 82 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 15c2068da..6f3b94fd4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1390,7 +1390,6 @@ dependencies = [ "anyhow", "hyperlight-common", "hyperlight-guest-tracing", - "hyperlight-guest-tracing-macro", "serde_json", ] @@ -1405,7 +1404,6 @@ dependencies = [ "hyperlight-common", "hyperlight-guest", "hyperlight-guest-tracing", - "hyperlight-guest-tracing-macro", "log", "spin 0.10.0", ] @@ -1415,6 +1413,7 @@ name = "hyperlight-guest-tracing" version = "0.7.0" dependencies = [ "hyperlight-common", + "hyperlight-guest-tracing-macro", "spin 0.10.0", ] @@ -1422,7 +1421,6 @@ dependencies = [ name = "hyperlight-guest-tracing-macro" version = "0.7.0" dependencies = [ - "hyperlight-guest-tracing", "proc-macro2", "quote", "syn", diff --git a/src/hyperlight_guest/Cargo.toml b/src/hyperlight_guest/Cargo.toml index d55aa4f92..5788bedc6 100644 --- a/src/hyperlight_guest/Cargo.toml +++ b/src/hyperlight_guest/Cargo.toml @@ -15,9 +15,8 @@ Provides only the essential building blocks for interacting with the host enviro anyhow = { version = "1.0.98", default-features = false } serde_json = { version = "1.0", default-features = false, features = ["alloc"] } hyperlight-common = { workspace = true } -hyperlight-guest-tracing = { workspace = true, optional = true } -hyperlight-guest-tracing-macro = { workspace = true} +hyperlight-guest-tracing = { workspace = true } [features] default = [] -trace_guest = ["dep:hyperlight-guest-tracing"] +trace_guest = [] diff --git a/src/hyperlight_guest/src/exit.rs b/src/hyperlight_guest/src/exit.rs index 42a9cc0fd..715086c7b 100644 --- a/src/hyperlight_guest/src/exit.rs +++ b/src/hyperlight_guest/src/exit.rs @@ -21,22 +21,22 @@ use hyperlight_common::outb::OutBAction; /// Halt the execution of the guest and returns control to the host. #[inline(never)] -#[hyperlight_guest_tracing_macro::trace_function] +#[hyperlight_guest_tracing::trace_function] pub fn halt() { // Ensure all tracing data is flushed before halting - hyperlight_guest_tracing_macro::flush!(); + hyperlight_guest_tracing::flush!(); unsafe { asm!("hlt", options(nostack)) } } /// Exits the VM with an Abort OUT action and code 0. #[unsafe(no_mangle)] -#[hyperlight_guest_tracing_macro::trace_function] +#[hyperlight_guest_tracing::trace_function] pub extern "C" fn abort() -> ! { abort_with_code(&[0, 0xFF]) } /// Exits the VM with an Abort OUT action and a specific code. -#[hyperlight_guest_tracing_macro::trace_function] +#[hyperlight_guest_tracing::trace_function] pub fn abort_with_code(code: &[u8]) -> ! { outb(OutBAction::Abort as u16, code); outb(OutBAction::Abort as u16, &[0xFF]); // send abort terminator (if not included in code) @@ -47,7 +47,7 @@ pub fn abort_with_code(code: &[u8]) -> ! { /// /// # Safety /// This function is unsafe because it dereferences a raw pointer. -#[hyperlight_guest_tracing_macro::trace_function] +#[hyperlight_guest_tracing::trace_function] pub unsafe fn abort_with_code_and_message(code: &[u8], message_ptr: *const c_char) -> ! { unsafe { // Step 1: Send abort code (typically 1 byte, but `code` allows flexibility) @@ -68,10 +68,10 @@ pub unsafe fn abort_with_code_and_message(code: &[u8], message_ptr: *const c_cha } /// OUT bytes to the host through multiple exits. -#[hyperlight_guest_tracing_macro::trace_function] +#[hyperlight_guest_tracing::trace_function] pub(crate) fn outb(port: u16, data: &[u8]) { // Ensure all tracing data is flushed before sending OUT bytes - hyperlight_guest_tracing_macro::flush!(); + hyperlight_guest_tracing::flush!(); unsafe { let mut i = 0; while i < data.len() { @@ -88,7 +88,7 @@ pub(crate) fn outb(port: u16, data: &[u8]) { } /// OUT function for sending a 32-bit value to the host. -#[hyperlight_guest_tracing_macro::trace_function] +#[hyperlight_guest_tracing::trace_function] pub(crate) unsafe fn out32(port: u16, val: u32) { unsafe { asm!("out dx, eax", in("dx") port, in("eax") val, options(preserves_flags, nomem, nostack)); diff --git a/src/hyperlight_guest/src/guest_handle/host_comm.rs b/src/hyperlight_guest/src/guest_handle/host_comm.rs index d5cf57ffa..5719417ab 100644 --- a/src/hyperlight_guest/src/guest_handle/host_comm.rs +++ b/src/hyperlight_guest/src/guest_handle/host_comm.rs @@ -35,7 +35,7 @@ use crate::exit::out32; impl GuestHandle { /// Get user memory region as bytes. - #[hyperlight_guest_tracing_macro::trace_function] + #[hyperlight_guest_tracing::trace_function] pub fn read_n_bytes_from_user_memory(&self, num: u64) -> Result> { let peb_ptr = self.peb().unwrap(); let user_memory_region_ptr = unsafe { (*peb_ptr).init_data.ptr as *mut u8 }; @@ -64,7 +64,7 @@ impl GuestHandle { /// /// When calling `call_host_function`, this function is called /// internally to get the return value. - #[hyperlight_guest_tracing_macro::trace_function] + #[hyperlight_guest_tracing::trace_function] pub fn get_host_return_value>(&self) -> Result { let return_value = self .try_pop_shared_input_data_into::() @@ -85,7 +85,7 @@ impl GuestHandle { /// /// Note: The function return value must be obtained by calling /// `get_host_return_value`. - #[hyperlight_guest_tracing_macro::trace_function] + #[hyperlight_guest_tracing::trace_function] pub fn call_host_function_without_returning_result( &self, function_name: &str, @@ -117,7 +117,7 @@ impl GuestHandle { /// sends it to the host, and then retrieves the return value. /// /// The return value is deserialized into the specified type `T`. - #[hyperlight_guest_tracing_macro::trace_function] + #[hyperlight_guest_tracing::trace_function] pub fn call_host_function>( &self, function_name: &str, @@ -128,7 +128,7 @@ impl GuestHandle { self.get_host_return_value::() } - #[hyperlight_guest_tracing_macro::trace_function] + #[hyperlight_guest_tracing::trace_function] pub fn get_host_function_details(&self) -> HostFunctionDetails { let peb_ptr = self.peb().unwrap(); let host_function_details_buffer = @@ -145,7 +145,7 @@ impl GuestHandle { } /// Write an error to the shared output data buffer. - #[hyperlight_guest_tracing_macro::trace_function] + #[hyperlight_guest_tracing::trace_function] pub fn write_error(&self, error_code: ErrorCode, message: Option<&str>) { let guest_error: GuestError = GuestError::new( error_code, @@ -161,7 +161,7 @@ impl GuestHandle { } /// Log a message with the specified log level, source, caller, source file, and line number. - #[hyperlight_guest_tracing_macro::trace_function] + #[hyperlight_guest_tracing::trace_function] pub fn log_message( &self, log_level: LogLevel, diff --git a/src/hyperlight_guest/src/guest_handle/io.rs b/src/hyperlight_guest/src/guest_handle/io.rs index 4654f0001..759c88880 100644 --- a/src/hyperlight_guest/src/guest_handle/io.rs +++ b/src/hyperlight_guest/src/guest_handle/io.rs @@ -27,7 +27,7 @@ use crate::error::{HyperlightGuestError, Result}; impl GuestHandle { /// Pops the top element from the shared input data buffer and returns it as a T - #[hyperlight_guest_tracing_macro::trace_function] + #[hyperlight_guest_tracing::trace_function] pub fn try_pop_shared_input_data_into(&self) -> Result where T: for<'a> TryFrom<&'a [u8]>, @@ -69,7 +69,7 @@ impl GuestHandle { let buffer = &idb[last_element_offset_rel as usize..]; // convert the buffer to T - let type_t = hyperlight_guest_tracing_macro::trace!( + let type_t = hyperlight_guest_tracing::trace!( "convert buffer", match T::try_from(buffer) { Ok(t) => Ok(t), @@ -92,7 +92,7 @@ impl GuestHandle { } /// Pushes the given data onto the shared output data buffer. - #[hyperlight_guest_tracing_macro::trace_function] + #[hyperlight_guest_tracing::trace_function] pub fn push_shared_output_data(&self, data: Vec) -> Result<()> { let peb_ptr = self.peb().unwrap(); let output_stack_size = unsafe { (*peb_ptr).output_stack.size as usize }; @@ -138,7 +138,7 @@ impl GuestHandle { } // write the actual data - hyperlight_guest_tracing_macro::trace!("copy data", { + hyperlight_guest_tracing::trace!("copy data", { odb[stack_ptr_rel as usize..stack_ptr_rel as usize + data.len()].copy_from_slice(&data); }); diff --git a/src/hyperlight_guest_bin/Cargo.toml b/src/hyperlight_guest_bin/Cargo.toml index 90e80bff9..83ac2a454 100644 --- a/src/hyperlight_guest_bin/Cargo.toml +++ b/src/hyperlight_guest_bin/Cargo.toml @@ -17,14 +17,13 @@ and third-party code used by our C-API needed to build a native hyperlight-guest default = ["libc", "printf"] libc = [] # compile musl libc printf = [ "libc" ] # compile printf -trace_guest = ["hyperlight-common/trace_guest", "dep:hyperlight-guest-tracing", "hyperlight-guest/trace_guest"] +trace_guest = ["hyperlight-common/trace_guest", "hyperlight-guest/trace_guest"] mem_profile = ["hyperlight-common/unwind_guest","hyperlight-common/mem_profile"] [dependencies] hyperlight-guest = { workspace = true, default-features = false } hyperlight-common = { workspace = true, default-features = false } -hyperlight-guest-tracing = { workspace = true, optional = true } -hyperlight-guest-tracing-macro = { workspace = true } +hyperlight-guest-tracing = { workspace = true } buddy_system_allocator = "0.11.0" log = { version = "0.4", default-features = false } spin = "0.10.0" diff --git a/src/hyperlight_guest_bin/src/exceptions/gdt.rs b/src/hyperlight_guest_bin/src/exceptions/gdt.rs index 0da032321..38bdf183e 100644 --- a/src/hyperlight_guest_bin/src/exceptions/gdt.rs +++ b/src/hyperlight_guest_bin/src/exceptions/gdt.rs @@ -72,7 +72,7 @@ struct GdtPointer { } /// Load the GDT -#[hyperlight_guest_tracing_macro::trace_function] +#[hyperlight_guest_tracing::trace_function] pub unsafe fn load_gdt() { unsafe { let gdt_ptr = GdtPointer { diff --git a/src/hyperlight_guest_bin/src/exceptions/handler.rs b/src/hyperlight_guest_bin/src/exceptions/handler.rs index b2cae2c4f..838cd582b 100644 --- a/src/hyperlight_guest_bin/src/exceptions/handler.rs +++ b/src/hyperlight_guest_bin/src/exceptions/handler.rs @@ -69,7 +69,7 @@ pub extern "C" fn hl_exception_handler( // call, which generates a warning because of the `abort_with_code_and_message` call which does // not return. // This is manually added to avoid the warning. - hyperlight_guest_tracing_macro::trace!("> hl_exception_handler"); + hyperlight_guest_tracing::trace!("> hl_exception_handler"); let ctx = stack_pointer as *mut Context; let exn_info = (stack_pointer + size_of::() as u64) as *mut ExceptionInfo; @@ -101,7 +101,7 @@ pub extern "C" fn hl_exception_handler( )(exception_number, exn_info, ctx, page_fault_address) } { - hyperlight_guest_tracing_macro::trace!("< hl_exception_handler"); + hyperlight_guest_tracing::trace!("< hl_exception_handler"); return; } } diff --git a/src/hyperlight_guest_bin/src/exceptions/idt.rs b/src/hyperlight_guest_bin/src/exceptions/idt.rs index 820e96861..91364cd95 100644 --- a/src/hyperlight_guest_bin/src/exceptions/idt.rs +++ b/src/hyperlight_guest_bin/src/exceptions/idt.rs @@ -71,7 +71,7 @@ impl IdtEntry { // Architectures Software Developer's Manual). pub(crate) static mut IDT: [IdtEntry; 256] = unsafe { core::mem::zeroed() }; -#[hyperlight_guest_tracing_macro::trace_function] +#[hyperlight_guest_tracing::trace_function] pub(crate) fn init_idt() { set_idt_entry(Exception::DivideByZero as usize, _do_excp0); // Divide by zero set_idt_entry(Exception::Debug as usize, _do_excp1); // Debug diff --git a/src/hyperlight_guest_bin/src/exceptions/idtr.rs b/src/hyperlight_guest_bin/src/exceptions/idtr.rs index 0d020f1e8..e79fb5dcf 100644 --- a/src/hyperlight_guest_bin/src/exceptions/idtr.rs +++ b/src/hyperlight_guest_bin/src/exceptions/idtr.rs @@ -40,7 +40,7 @@ impl Idtr { } } -#[hyperlight_guest_tracing_macro::trace_function] +#[hyperlight_guest_tracing::trace_function] pub(crate) unsafe fn load_idt() { unsafe { init_idt(); diff --git a/src/hyperlight_guest_bin/src/guest_function/call.rs b/src/hyperlight_guest_bin/src/guest_function/call.rs index 376b0cf35..3d55a9f5e 100644 --- a/src/hyperlight_guest_bin/src/guest_function/call.rs +++ b/src/hyperlight_guest_bin/src/guest_function/call.rs @@ -27,7 +27,7 @@ use crate::{GUEST_HANDLE, REGISTERED_GUEST_FUNCTIONS}; type GuestFunc = fn(&FunctionCall) -> Result>; -#[hyperlight_guest_tracing_macro::trace_function] +#[hyperlight_guest_tracing::trace_function] pub(crate) fn call_guest_function(function_call: FunctionCall) -> Result> { // Validate this is a Guest Function Call if function_call.function_call_type() != FunctionCallType::Guest { @@ -62,7 +62,7 @@ pub(crate) fn call_guest_function(function_call: FunctionCall) -> Result core::mem::transmute::(function_pointer) }; - hyperlight_guest_tracing_macro::trace!("guest_function", p_function(&function_call)) + hyperlight_guest_tracing::trace!("guest_function", p_function(&function_call)) } else { // The given function is not registered. The guest should implement a function called guest_dispatch_function to handle this. @@ -73,7 +73,7 @@ pub(crate) fn call_guest_function(function_call: FunctionCall) -> Result fn guest_dispatch_function(function_call: FunctionCall) -> Result>; } - hyperlight_guest_tracing_macro::trace!("default guest function", unsafe { + hyperlight_guest_tracing::trace!("default guest function", unsafe { guest_dispatch_function(function_call) }) } @@ -83,7 +83,7 @@ pub(crate) fn call_guest_function(function_call: FunctionCall) -> Result // and we will leak memory as the epilogue will not be called as halt() is not going to return. #[unsafe(no_mangle)] #[inline(never)] -#[hyperlight_guest_tracing_macro::trace_function] +#[hyperlight_guest_tracing::trace_function] fn internal_dispatch_function() -> Result<()> { let handle = unsafe { GUEST_HANDLE }; @@ -104,7 +104,7 @@ fn internal_dispatch_function() -> Result<()> { // This is implemented as a separate function to make sure that epilogue in the internal_dispatch_function is called before the halt() // which if it were included in the internal_dispatch_function cause the epilogue to not be called because the halt() would not return // when running in the hypervisor. -#[hyperlight_guest_tracing_macro::trace_function] +#[hyperlight_guest_tracing::trace_function] pub(crate) extern "C" fn dispatch_function() { // The hyperlight host likes to use one partition and reset it in // various ways; if that has happened, there might stale TLB diff --git a/src/hyperlight_guest_bin/src/lib.rs b/src/hyperlight_guest_bin/src/lib.rs index 9d8a2c35e..fa5e3a6f5 100644 --- a/src/hyperlight_guest_bin/src/lib.rs +++ b/src/hyperlight_guest_bin/src/lib.rs @@ -32,7 +32,7 @@ use hyperlight_common::mem::HyperlightPEB; use hyperlight_common::outb::OutBAction; use hyperlight_guest::exit::{abort_with_code_and_message, halt}; use hyperlight_guest::guest_handle::handle::GuestHandle; -use hyperlight_guest_tracing_macro::{trace, trace_function}; +use hyperlight_guest_tracing::{trace, trace_function}; use log::LevelFilter; use spin::Once; diff --git a/src/hyperlight_guest_bin/src/paging.rs b/src/hyperlight_guest_bin/src/paging.rs index 749900349..a5a3d9f26 100644 --- a/src/hyperlight_guest_bin/src/paging.rs +++ b/src/hyperlight_guest_bin/src/paging.rs @@ -61,6 +61,7 @@ struct MapResponse { /// as such do not use concurrently with any other page table operations /// - TLB invalidation is not performed, /// if previously-unmapped ranges are not being mapped, TLB invalidation may need to be performed afterwards. +#[hyperlight_guest_tracing::trace_function] pub unsafe fn map_region(phys_base: u64, virt_base: *mut u8, len: u64) { let mut pml4_base: u64; unsafe { diff --git a/src/hyperlight_guest_tracing/Cargo.toml b/src/hyperlight_guest_tracing/Cargo.toml index e77144eaa..873f9e37d 100644 --- a/src/hyperlight_guest_tracing/Cargo.toml +++ b/src/hyperlight_guest_tracing/Cargo.toml @@ -11,6 +11,7 @@ description = """Provides the tracing functionality for the hyperlight guest.""" [dependencies] hyperlight-common = { workspace = true, default-features = false, features = ["trace_guest"] } +hyperlight-guest-tracing-macro = { workspace = true } spin = "0.10.0" [lints] diff --git a/src/hyperlight_guest_tracing/src/lib.rs b/src/hyperlight_guest_tracing/src/lib.rs index 8d7ae0e6a..bcf4ee4dd 100644 --- a/src/hyperlight_guest_tracing/src/lib.rs +++ b/src/hyperlight_guest_tracing/src/lib.rs @@ -36,6 +36,10 @@ const MAX_NO_OF_ENTRIES: usize = 32; /// Maximum length of a trace message in bytes. pub const MAX_TRACE_MSG_LEN: usize = 64; +/// Re-export the tracing macros +/// This allows users to use the macros without needing to import them explicitly. +pub use hyperlight_guest_tracing_macro::*; + #[derive(Debug, Copy, Clone)] /// Represents a trace record of a guest with a number of cycles and a message. pub struct TraceRecord { diff --git a/src/hyperlight_guest_tracing_macro/Cargo.toml b/src/hyperlight_guest_tracing_macro/Cargo.toml index 89522c1de..6e749ac20 100644 --- a/src/hyperlight_guest_tracing_macro/Cargo.toml +++ b/src/hyperlight_guest_tracing_macro/Cargo.toml @@ -10,7 +10,6 @@ readme.workspace = true description = """Provides the tracing macros for the hyperlight guest, enabling structured logging and tracing capabilities.""" [dependencies] -hyperlight-guest-tracing = { workspace = true } proc-macro2 = "1.0" quote = "1.0.40" syn = { version = "2.0.104", features = ["full"] } diff --git a/src/hyperlight_guest_tracing_macro/src/lib.rs b/src/hyperlight_guest_tracing_macro/src/lib.rs index 53f0ef817..24b790864 100644 --- a/src/hyperlight_guest_tracing_macro/src/lib.rs +++ b/src/hyperlight_guest_tracing_macro/src/lib.rs @@ -48,15 +48,6 @@ pub fn trace_function(_attr: TokenStream, item: TokenStream) -> TokenStream { let entry_msg = format!("> {}", fn_name_str); let exit_msg = format!("< {}", fn_name_str); - if entry_msg.len() > hyperlight_guest_tracing::MAX_TRACE_MSG_LEN - || exit_msg.len() > hyperlight_guest_tracing::MAX_TRACE_MSG_LEN - { - panic!( - "Trace messages must not exceed {} bytes in length.", - hyperlight_guest_tracing::MAX_TRACE_MSG_LEN - ); - } - let expanded = match fn_output { syn::ReturnType::Default => { // No return value (unit) @@ -64,11 +55,16 @@ pub fn trace_function(_attr: TokenStream, item: TokenStream) -> TokenStream { #(#fn_attrs)* #fn_vis #fn_sig { #[cfg(feature = "trace_guest")] - hyperlight_guest_tracing::create_trace_record(#entry_msg); + const _: () = assert!( + #entry_msg.len() <= hyperlight_guest_tracing::MAX_TRACE_MSG_LEN, + "Trace message exceeds the maximum bytes length", + ); + #[cfg(feature = "trace_guest")] + ::hyperlight_guest_tracing::create_trace_record(#entry_msg); // Call the original function body #fn_block #[cfg(feature = "trace_guest")] - hyperlight_guest_tracing::create_trace_record(#exit_msg); + ::hyperlight_guest_tracing::create_trace_record(#exit_msg); } } } @@ -78,10 +74,15 @@ pub fn trace_function(_attr: TokenStream, item: TokenStream) -> TokenStream { #(#fn_attrs)* #fn_vis #fn_sig { #[cfg(feature = "trace_guest")] - hyperlight_guest_tracing::create_trace_record(concat!("> ", #fn_name_str)); + const _: () = assert!( + #entry_msg.len() <= hyperlight_guest_tracing::MAX_TRACE_MSG_LEN, + "Trace message exceeds the maximum bytes length", + ); + #[cfg(feature = "trace_guest")] + ::hyperlight_guest_tracing::create_trace_record(#entry_msg); let __trace_result = (|| #fn_block )(); #[cfg(feature = "trace_guest")] - hyperlight_guest_tracing::create_trace_record(concat!("< ", #fn_name_str)); + ::hyperlight_guest_tracing::create_trace_record(#exit_msg); __trace_result } } @@ -103,17 +104,6 @@ impl syn::parse::Parse for TraceMacroInput { if !matches!(message, syn::Lit::Str(_)) { return Err(input.error("first argument to trace! must be a string literal")); } - if let syn::Lit::Str(ref lit_str) = message { - if lit_str.value().is_empty() { - return Err(input.error("trace message must not be empty")); - } - if lit_str.value().len() > hyperlight_guest_tracing::MAX_TRACE_MSG_LEN { - return Err(input.error(format!( - "trace message must not exceed {} bytes", - hyperlight_guest_tracing::MAX_TRACE_MSG_LEN - ))); - } - } let statement = if input.peek(syn::Token![,]) { let _: syn::Token![,] = input.parse()?; @@ -207,15 +197,20 @@ pub fn trace(input: TokenStream) -> TokenStream { _ => unreachable!(), }; if let Some(statement) = parsed.statement { - let entry = format!("+ {}", trace_message); - let exit = format!("- {}", trace_message); + let entry_msg = format!("+ {}", trace_message); + let exit_msg = format!("- {}", trace_message); let expanded = quote! { { #[cfg(feature = "trace_guest")] - hyperlight_guest_tracing::create_trace_record(#entry); + const _: () = assert!( + #entry_msg.len() <= hyperlight_guest_tracing::MAX_TRACE_MSG_LEN, + "Trace message exceeds the maximum bytes length", + ); + #[cfg(feature = "trace_guest")] + ::hyperlight_guest_tracing::create_trace_record(#entry_msg); let __trace_result = #statement; #[cfg(feature = "trace_guest")] - hyperlight_guest_tracing::create_trace_record(#exit); + ::hyperlight_guest_tracing::create_trace_record(#exit_msg); __trace_result } }; @@ -224,7 +219,12 @@ pub fn trace(input: TokenStream) -> TokenStream { let expanded = quote! { { #[cfg(feature = "trace_guest")] - hyperlight_guest_tracing::create_trace_record(#trace_message); + const _: () = assert!( + #trace_message.len() <= hyperlight_guest_tracing::MAX_TRACE_MSG_LEN, + "Trace message exceeds the maximum bytes length", + ); + #[cfg(feature = "trace_guest")] + ::hyperlight_guest_tracing::create_trace_record(#trace_message); } }; TokenStream::from(expanded) @@ -242,7 +242,7 @@ pub fn flush(_input: TokenStream) -> TokenStream { let expanded = quote! { { #[cfg(feature = "trace_guest")] - hyperlight_guest_tracing::flush_trace_buffer(); + ::hyperlight_guest_tracing::flush_trace_buffer(); } }; diff --git a/src/tests/rust_guests/callbackguest/Cargo.lock b/src/tests/rust_guests/callbackguest/Cargo.lock index 075c49f42..24c80469e 100644 --- a/src/tests/rust_guests/callbackguest/Cargo.lock +++ b/src/tests/rust_guests/callbackguest/Cargo.lock @@ -86,7 +86,6 @@ dependencies = [ "anyhow", "hyperlight-common", "hyperlight-guest-tracing", - "hyperlight-guest-tracing-macro", "serde_json", ] @@ -101,7 +100,6 @@ dependencies = [ "hyperlight-common", "hyperlight-guest", "hyperlight-guest-tracing", - "hyperlight-guest-tracing-macro", "log", "spin 0.10.0", ] @@ -111,6 +109,7 @@ name = "hyperlight-guest-tracing" version = "0.7.0" dependencies = [ "hyperlight-common", + "hyperlight-guest-tracing-macro", "spin 0.10.0", ] @@ -118,7 +117,6 @@ dependencies = [ name = "hyperlight-guest-tracing-macro" version = "0.7.0" dependencies = [ - "hyperlight-guest-tracing", "proc-macro2", "quote", "syn", diff --git a/src/tests/rust_guests/dummyguest/Cargo.lock b/src/tests/rust_guests/dummyguest/Cargo.lock index 3b7a713a7..f1c9d9e55 100644 --- a/src/tests/rust_guests/dummyguest/Cargo.lock +++ b/src/tests/rust_guests/dummyguest/Cargo.lock @@ -85,7 +85,6 @@ dependencies = [ "anyhow", "hyperlight-common", "hyperlight-guest-tracing", - "hyperlight-guest-tracing-macro", "serde_json", ] @@ -100,7 +99,6 @@ dependencies = [ "hyperlight-common", "hyperlight-guest", "hyperlight-guest-tracing", - "hyperlight-guest-tracing-macro", "log", "spin 0.10.0", ] @@ -110,6 +108,7 @@ name = "hyperlight-guest-tracing" version = "0.7.0" dependencies = [ "hyperlight-common", + "hyperlight-guest-tracing-macro", "spin 0.10.0", ] @@ -117,7 +116,6 @@ dependencies = [ name = "hyperlight-guest-tracing-macro" version = "0.7.0" dependencies = [ - "hyperlight-guest-tracing", "proc-macro2", "quote", "syn", diff --git a/src/tests/rust_guests/simpleguest/Cargo.lock b/src/tests/rust_guests/simpleguest/Cargo.lock index 3cd9fe849..07672d6f1 100644 --- a/src/tests/rust_guests/simpleguest/Cargo.lock +++ b/src/tests/rust_guests/simpleguest/Cargo.lock @@ -77,7 +77,6 @@ dependencies = [ "anyhow", "hyperlight-common", "hyperlight-guest-tracing", - "hyperlight-guest-tracing-macro", "serde_json", ] @@ -92,7 +91,6 @@ dependencies = [ "hyperlight-common", "hyperlight-guest", "hyperlight-guest-tracing", - "hyperlight-guest-tracing-macro", "log", "spin 0.10.0", ] @@ -102,6 +100,7 @@ name = "hyperlight-guest-tracing" version = "0.7.0" dependencies = [ "hyperlight-common", + "hyperlight-guest-tracing-macro", "spin 0.10.0", ] @@ -109,7 +108,6 @@ dependencies = [ name = "hyperlight-guest-tracing-macro" version = "0.7.0" dependencies = [ - "hyperlight-guest-tracing", "proc-macro2", "quote", "syn", diff --git a/src/tests/rust_guests/witguest/Cargo.lock b/src/tests/rust_guests/witguest/Cargo.lock index ddd6f659e..ee578fe9b 100644 --- a/src/tests/rust_guests/witguest/Cargo.lock +++ b/src/tests/rust_guests/witguest/Cargo.lock @@ -220,7 +220,6 @@ dependencies = [ "anyhow", "hyperlight-common", "hyperlight-guest-tracing", - "hyperlight-guest-tracing-macro", "serde_json", ] @@ -235,7 +234,6 @@ dependencies = [ "hyperlight-common", "hyperlight-guest", "hyperlight-guest-tracing", - "hyperlight-guest-tracing-macro", "log", "spin 0.10.0", ] @@ -245,6 +243,7 @@ name = "hyperlight-guest-tracing" version = "0.7.0" dependencies = [ "hyperlight-common", + "hyperlight-guest-tracing-macro", "spin 0.10.0", ] @@ -252,7 +251,6 @@ dependencies = [ name = "hyperlight-guest-tracing-macro" version = "0.7.0" dependencies = [ - "hyperlight-guest-tracing", "proc-macro2", "quote", "syn", From 330dca0d086eb3f02c681c5d1a2610415454fdc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Doru=20Bl=C3=A2nzeanu?= Date: Wed, 30 Jul 2025 17:56:35 +0300 Subject: [PATCH 2/2] update Cargo.toml to reflect latest versions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Doru Blânzeanu --- src/tests/rust_guests/witguest/Cargo.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/tests/rust_guests/witguest/Cargo.lock b/src/tests/rust_guests/witguest/Cargo.lock index ee578fe9b..2ecd6119f 100644 --- a/src/tests/rust_guests/witguest/Cargo.lock +++ b/src/tests/rust_guests/witguest/Cargo.lock @@ -357,9 +357,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", @@ -520,9 +520,9 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "wasmparser" -version = "0.235.0" +version = "0.236.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "161296c618fa2d63f6ed5fffd1112937e803cb9ec71b32b01a76321555660917" +checksum = "16d1eee846a705f6f3cb9d7b9f79b54583810f1fb57a1e3aea76d1742db2e3d2" dependencies = [ "bitflags", "hashbrown",