Skip to content

Commit 06267cd

Browse files
authored
Re-export macros in hyperlight_guest_tracing (#734)
* Re-export macros in hyperlight_guest_tracing for ease of use Signed-off-by: Doru Blânzeanu <[email protected]> * update Cargo.toml to reflect latest versions Signed-off-by: Doru Blânzeanu <[email protected]> --------- Signed-off-by: Doru Blânzeanu <[email protected]>
1 parent f99e33f commit 06267cd

File tree

21 files changed

+75
-82
lines changed

21 files changed

+75
-82
lines changed

Cargo.lock

Lines changed: 1 addition & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/hyperlight_guest/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ Provides only the essential building blocks for interacting with the host enviro
1515
anyhow = { version = "1.0.98", default-features = false }
1616
serde_json = { version = "1.0", default-features = false, features = ["alloc"] }
1717
hyperlight-common = { workspace = true }
18-
hyperlight-guest-tracing = { workspace = true, optional = true }
19-
hyperlight-guest-tracing-macro = { workspace = true}
18+
hyperlight-guest-tracing = { workspace = true }
2019

2120
[features]
2221
default = []
23-
trace_guest = ["dep:hyperlight-guest-tracing"]
22+
trace_guest = []

src/hyperlight_guest/src/exit.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,22 @@ use hyperlight_common::outb::OutBAction;
2121

2222
/// Halt the execution of the guest and returns control to the host.
2323
#[inline(never)]
24-
#[hyperlight_guest_tracing_macro::trace_function]
24+
#[hyperlight_guest_tracing::trace_function]
2525
pub fn halt() {
2626
// Ensure all tracing data is flushed before halting
27-
hyperlight_guest_tracing_macro::flush!();
27+
hyperlight_guest_tracing::flush!();
2828
unsafe { asm!("hlt", options(nostack)) }
2929
}
3030

3131
/// Exits the VM with an Abort OUT action and code 0.
3232
#[unsafe(no_mangle)]
33-
#[hyperlight_guest_tracing_macro::trace_function]
33+
#[hyperlight_guest_tracing::trace_function]
3434
pub extern "C" fn abort() -> ! {
3535
abort_with_code(&[0, 0xFF])
3636
}
3737

3838
/// Exits the VM with an Abort OUT action and a specific code.
39-
#[hyperlight_guest_tracing_macro::trace_function]
39+
#[hyperlight_guest_tracing::trace_function]
4040
pub fn abort_with_code(code: &[u8]) -> ! {
4141
outb(OutBAction::Abort as u16, code);
4242
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]) -> ! {
4747
///
4848
/// # Safety
4949
/// This function is unsafe because it dereferences a raw pointer.
50-
#[hyperlight_guest_tracing_macro::trace_function]
50+
#[hyperlight_guest_tracing::trace_function]
5151
pub unsafe fn abort_with_code_and_message(code: &[u8], message_ptr: *const c_char) -> ! {
5252
unsafe {
5353
// 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
6868
}
6969

7070
/// OUT bytes to the host through multiple exits.
71-
#[hyperlight_guest_tracing_macro::trace_function]
71+
#[hyperlight_guest_tracing::trace_function]
7272
pub(crate) fn outb(port: u16, data: &[u8]) {
7373
// Ensure all tracing data is flushed before sending OUT bytes
74-
hyperlight_guest_tracing_macro::flush!();
74+
hyperlight_guest_tracing::flush!();
7575
unsafe {
7676
let mut i = 0;
7777
while i < data.len() {
@@ -88,7 +88,7 @@ pub(crate) fn outb(port: u16, data: &[u8]) {
8888
}
8989

9090
/// OUT function for sending a 32-bit value to the host.
91-
#[hyperlight_guest_tracing_macro::trace_function]
91+
#[hyperlight_guest_tracing::trace_function]
9292
pub(crate) unsafe fn out32(port: u16, val: u32) {
9393
unsafe {
9494
asm!("out dx, eax", in("dx") port, in("eax") val, options(preserves_flags, nomem, nostack));

src/hyperlight_guest/src/guest_handle/host_comm.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use crate::exit::out32;
3535

3636
impl GuestHandle {
3737
/// Get user memory region as bytes.
38-
#[hyperlight_guest_tracing_macro::trace_function]
38+
#[hyperlight_guest_tracing::trace_function]
3939
pub fn read_n_bytes_from_user_memory(&self, num: u64) -> Result<Vec<u8>> {
4040
let peb_ptr = self.peb().unwrap();
4141
let user_memory_region_ptr = unsafe { (*peb_ptr).init_data.ptr as *mut u8 };
@@ -64,7 +64,7 @@ impl GuestHandle {
6464
///
6565
/// When calling `call_host_function<T>`, this function is called
6666
/// internally to get the return value.
67-
#[hyperlight_guest_tracing_macro::trace_function]
67+
#[hyperlight_guest_tracing::trace_function]
6868
pub fn get_host_return_value<T: TryFrom<ReturnValue>>(&self) -> Result<T> {
6969
let return_value = self
7070
.try_pop_shared_input_data_into::<ReturnValue>()
@@ -85,7 +85,7 @@ impl GuestHandle {
8585
///
8686
/// Note: The function return value must be obtained by calling
8787
/// `get_host_return_value`.
88-
#[hyperlight_guest_tracing_macro::trace_function]
88+
#[hyperlight_guest_tracing::trace_function]
8989
pub fn call_host_function_without_returning_result(
9090
&self,
9191
function_name: &str,
@@ -117,7 +117,7 @@ impl GuestHandle {
117117
/// sends it to the host, and then retrieves the return value.
118118
///
119119
/// The return value is deserialized into the specified type `T`.
120-
#[hyperlight_guest_tracing_macro::trace_function]
120+
#[hyperlight_guest_tracing::trace_function]
121121
pub fn call_host_function<T: TryFrom<ReturnValue>>(
122122
&self,
123123
function_name: &str,
@@ -128,7 +128,7 @@ impl GuestHandle {
128128
self.get_host_return_value::<T>()
129129
}
130130

131-
#[hyperlight_guest_tracing_macro::trace_function]
131+
#[hyperlight_guest_tracing::trace_function]
132132
pub fn get_host_function_details(&self) -> HostFunctionDetails {
133133
let peb_ptr = self.peb().unwrap();
134134
let host_function_details_buffer =
@@ -145,7 +145,7 @@ impl GuestHandle {
145145
}
146146

147147
/// Write an error to the shared output data buffer.
148-
#[hyperlight_guest_tracing_macro::trace_function]
148+
#[hyperlight_guest_tracing::trace_function]
149149
pub fn write_error(&self, error_code: ErrorCode, message: Option<&str>) {
150150
let guest_error: GuestError = GuestError::new(
151151
error_code,
@@ -161,7 +161,7 @@ impl GuestHandle {
161161
}
162162

163163
/// Log a message with the specified log level, source, caller, source file, and line number.
164-
#[hyperlight_guest_tracing_macro::trace_function]
164+
#[hyperlight_guest_tracing::trace_function]
165165
pub fn log_message(
166166
&self,
167167
log_level: LogLevel,

src/hyperlight_guest/src/guest_handle/io.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use crate::error::{HyperlightGuestError, Result};
2727

2828
impl GuestHandle {
2929
/// Pops the top element from the shared input data buffer and returns it as a T
30-
#[hyperlight_guest_tracing_macro::trace_function]
30+
#[hyperlight_guest_tracing::trace_function]
3131
pub fn try_pop_shared_input_data_into<T>(&self) -> Result<T>
3232
where
3333
T: for<'a> TryFrom<&'a [u8]>,
@@ -69,7 +69,7 @@ impl GuestHandle {
6969
let buffer = &idb[last_element_offset_rel as usize..];
7070

7171
// convert the buffer to T
72-
let type_t = hyperlight_guest_tracing_macro::trace!(
72+
let type_t = hyperlight_guest_tracing::trace!(
7373
"convert buffer",
7474
match T::try_from(buffer) {
7575
Ok(t) => Ok(t),
@@ -92,7 +92,7 @@ impl GuestHandle {
9292
}
9393

9494
/// Pushes the given data onto the shared output data buffer.
95-
#[hyperlight_guest_tracing_macro::trace_function]
95+
#[hyperlight_guest_tracing::trace_function]
9696
pub fn push_shared_output_data(&self, data: Vec<u8>) -> Result<()> {
9797
let peb_ptr = self.peb().unwrap();
9898
let output_stack_size = unsafe { (*peb_ptr).output_stack.size as usize };
@@ -138,7 +138,7 @@ impl GuestHandle {
138138
}
139139

140140
// write the actual data
141-
hyperlight_guest_tracing_macro::trace!("copy data", {
141+
hyperlight_guest_tracing::trace!("copy data", {
142142
odb[stack_ptr_rel as usize..stack_ptr_rel as usize + data.len()].copy_from_slice(&data);
143143
});
144144

src/hyperlight_guest_bin/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@ and third-party code used by our C-API needed to build a native hyperlight-guest
1717
default = ["libc", "printf"]
1818
libc = [] # compile musl libc
1919
printf = [ "libc" ] # compile printf
20-
trace_guest = ["hyperlight-common/trace_guest", "dep:hyperlight-guest-tracing", "hyperlight-guest/trace_guest"]
20+
trace_guest = ["hyperlight-common/trace_guest", "hyperlight-guest/trace_guest"]
2121
mem_profile = ["hyperlight-common/unwind_guest","hyperlight-common/mem_profile"]
2222

2323
[dependencies]
2424
hyperlight-guest = { workspace = true, default-features = false }
2525
hyperlight-common = { workspace = true, default-features = false }
26-
hyperlight-guest-tracing = { workspace = true, optional = true }
27-
hyperlight-guest-tracing-macro = { workspace = true }
26+
hyperlight-guest-tracing = { workspace = true }
2827
buddy_system_allocator = "0.11.0"
2928
log = { version = "0.4", default-features = false }
3029
spin = "0.10.0"

src/hyperlight_guest_bin/src/exceptions/gdt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ struct GdtPointer {
7272
}
7373

7474
/// Load the GDT
75-
#[hyperlight_guest_tracing_macro::trace_function]
75+
#[hyperlight_guest_tracing::trace_function]
7676
pub unsafe fn load_gdt() {
7777
unsafe {
7878
let gdt_ptr = GdtPointer {

src/hyperlight_guest_bin/src/exceptions/handler.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ pub extern "C" fn hl_exception_handler(
6969
// call, which generates a warning because of the `abort_with_code_and_message` call which does
7070
// not return.
7171
// This is manually added to avoid the warning.
72-
hyperlight_guest_tracing_macro::trace!("> hl_exception_handler");
72+
hyperlight_guest_tracing::trace!("> hl_exception_handler");
7373

7474
let ctx = stack_pointer as *mut Context;
7575
let exn_info = (stack_pointer + size_of::<Context>() as u64) as *mut ExceptionInfo;
@@ -101,7 +101,7 @@ pub extern "C" fn hl_exception_handler(
101101
)(exception_number, exn_info, ctx, page_fault_address)
102102
}
103103
{
104-
hyperlight_guest_tracing_macro::trace!("< hl_exception_handler");
104+
hyperlight_guest_tracing::trace!("< hl_exception_handler");
105105
return;
106106
}
107107
}

src/hyperlight_guest_bin/src/exceptions/idt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl IdtEntry {
7171
// Architectures Software Developer's Manual).
7272
pub(crate) static mut IDT: [IdtEntry; 256] = unsafe { core::mem::zeroed() };
7373

74-
#[hyperlight_guest_tracing_macro::trace_function]
74+
#[hyperlight_guest_tracing::trace_function]
7575
pub(crate) fn init_idt() {
7676
set_idt_entry(Exception::DivideByZero as usize, _do_excp0); // Divide by zero
7777
set_idt_entry(Exception::Debug as usize, _do_excp1); // Debug

src/hyperlight_guest_bin/src/exceptions/idtr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl Idtr {
4040
}
4141
}
4242

43-
#[hyperlight_guest_tracing_macro::trace_function]
43+
#[hyperlight_guest_tracing::trace_function]
4444
pub(crate) unsafe fn load_idt() {
4545
unsafe {
4646
init_idt();

0 commit comments

Comments
 (0)