Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions src/hyperlight_guest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
16 changes: 8 additions & 8 deletions src/hyperlight_guest/src/exit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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() {
Expand All @@ -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));
Expand Down
14 changes: 7 additions & 7 deletions src/hyperlight_guest/src/guest_handle/host_comm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<u8>> {
let peb_ptr = self.peb().unwrap();
let user_memory_region_ptr = unsafe { (*peb_ptr).init_data.ptr as *mut u8 };
Expand Down Expand Up @@ -64,7 +64,7 @@ impl GuestHandle {
///
/// When calling `call_host_function<T>`, 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<T: TryFrom<ReturnValue>>(&self) -> Result<T> {
let return_value = self
.try_pop_shared_input_data_into::<ReturnValue>()
Expand All @@ -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,
Expand Down Expand Up @@ -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<T: TryFrom<ReturnValue>>(
&self,
function_name: &str,
Expand All @@ -128,7 +128,7 @@ impl GuestHandle {
self.get_host_return_value::<T>()
}

#[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 =
Expand All @@ -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,
Expand All @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions src/hyperlight_guest/src/guest_handle/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(&self) -> Result<T>
where
T: for<'a> TryFrom<&'a [u8]>,
Expand Down Expand Up @@ -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),
Expand All @@ -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<u8>) -> Result<()> {
let peb_ptr = self.peb().unwrap();
let output_stack_size = unsafe { (*peb_ptr).output_stack.size as usize };
Expand Down Expand Up @@ -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);
});

Expand Down
5 changes: 2 additions & 3 deletions src/hyperlight_guest_bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/hyperlight_guest_bin/src/exceptions/gdt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/hyperlight_guest_bin/src/exceptions/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Context>() as u64) as *mut ExceptionInfo;
Expand Down Expand Up @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/hyperlight_guest_bin/src/exceptions/idt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/hyperlight_guest_bin/src/exceptions/idtr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
10 changes: 5 additions & 5 deletions src/hyperlight_guest_bin/src/guest_function/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use crate::{GUEST_HANDLE, REGISTERED_GUEST_FUNCTIONS};

type GuestFunc = fn(&FunctionCall) -> Result<Vec<u8>>;

#[hyperlight_guest_tracing_macro::trace_function]
#[hyperlight_guest_tracing::trace_function]
pub(crate) fn call_guest_function(function_call: FunctionCall) -> Result<Vec<u8>> {
// Validate this is a Guest Function Call
if function_call.function_call_type() != FunctionCallType::Guest {
Expand Down Expand Up @@ -62,7 +62,7 @@ pub(crate) fn call_guest_function(function_call: FunctionCall) -> Result<Vec<u8>
core::mem::transmute::<usize, GuestFunc>(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.

Expand All @@ -73,7 +73,7 @@ pub(crate) fn call_guest_function(function_call: FunctionCall) -> Result<Vec<u8>
fn guest_dispatch_function(function_call: FunctionCall) -> Result<Vec<u8>>;
}

hyperlight_guest_tracing_macro::trace!("default guest function", unsafe {
hyperlight_guest_tracing::trace!("default guest function", unsafe {
guest_dispatch_function(function_call)
})
}
Expand All @@ -83,7 +83,7 @@ pub(crate) fn call_guest_function(function_call: FunctionCall) -> Result<Vec<u8>
// 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 };

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/hyperlight_guest_bin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions src/hyperlight_guest_bin/src/paging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/hyperlight_guest_tracing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 4 additions & 0 deletions src/hyperlight_guest_tracing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion src/hyperlight_guest_tracing_macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
Loading
Loading