diff --git a/Cargo.lock b/Cargo.lock index d535bc0e2..3fa47d5de 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1517,6 +1517,7 @@ dependencies = [ "bitflags 2.11.0", "litebox", "litebox_common_linux", + "litebox_util_log", "paste", "rangemap", "spin 0.9.8", @@ -1558,6 +1559,7 @@ dependencies = [ "libc", "litebox", "litebox_common_linux", + "litebox_util_log", "modular-bitfield", "num_enum", "object", @@ -1697,6 +1699,7 @@ dependencies = [ "litebox", "litebox_common_linux", "litebox_platform_multiplex", + "litebox_util_log", "once_cell", "ringbuf", "seq-macro", @@ -1720,6 +1723,7 @@ dependencies = [ "litebox_common_linux", "litebox_common_optee", "litebox_platform_multiplex", + "litebox_util_log", "num_enum", "once_cell", "spin 0.10.0", diff --git a/litebox/src/platform/mock.rs b/litebox/src/platform/mock.rs index 3a3297aa6..4bcb936eb 100644 --- a/litebox/src/platform/mock.rs +++ b/litebox/src/platform/mock.rs @@ -276,12 +276,6 @@ impl PunchthroughProvider for MockPlatform { } } -impl DebugLogProvider for MockPlatform { - fn debug_log_print(&self, msg: &str) { - std::eprintln!("{msg}"); - } -} - impl RawPointerProvider for MockPlatform { type RawConstPointer = super::trivial_providers::TransparentConstPtr; type RawMutPointer = diff --git a/litebox/src/platform/mod.rs b/litebox/src/platform/mod.rs index 983f20c84..13244683f 100644 --- a/litebox/src/platform/mod.rs +++ b/litebox/src/platform/mod.rs @@ -20,33 +20,13 @@ use zerocopy::{FromBytes, IntoBytes}; pub use page_mgmt::PageManagementProvider; -#[macro_export] -macro_rules! log_println { - ($platform:expr, $s:expr) => {{ - use $crate::platform::DebugLogProvider as _; - $platform.debug_log_print($s); - }}; - ($platform:expr, $($tt:tt)*) => {{ - use core::fmt::Write as _; - use $crate::platform::DebugLogProvider as _; - let mut t: arrayvec::ArrayString<8192> = arrayvec::ArrayString::new(); - writeln!(t, $($tt)*).unwrap(); - $platform.debug_log_print(&t); - }}; -} - /// A provider of a platform upon which LiteBox can execute. /// /// Ideally, a [`Provider`] is zero-sized, and only exists to provide access to functionality /// provided by it. _However_, most of the provided APIs within the provider act upon an `&self` to /// allow storage of any useful "globals" within it necessary. pub trait Provider: - RawMutexProvider - + IPInterfaceProvider - + TimeProvider - + PunchthroughProvider - + DebugLogProvider - + RawPointerProvider + RawMutexProvider + IPInterfaceProvider + TimeProvider + PunchthroughProvider + RawPointerProvider { } @@ -439,20 +419,6 @@ pub trait SystemTime: Send + Sync { fn duration_since(&self, earlier: &Self) -> Result; } -/// An interface to dumping debug output for tracing purposes. -pub trait DebugLogProvider { - /// Print `msg` to the debug log - /// - /// Newlines are *not* automatically appended to `msg`, thus the caller must make sure to - /// include newlines if necessary. - /// - /// One some platforms, this might be a slow/expensive operation, thus ideally callers of this - /// should prefer not making a large number of small prints to print a single logical message, - /// but instead should combine all strings part of a single logical message into a single - /// `debug_log_print` call. - fn debug_log_print(&self, msg: &str); -} - /// A common interface for raw pointers, aimed at usage in shims _above_ LiteBox. /// /// Essentially, these types indicate "user" pointers (which are allowed to be null). Platforms with diff --git a/litebox_platform_linux_kernel/Cargo.toml b/litebox_platform_linux_kernel/Cargo.toml index 2e6abc3f8..858cb655e 100644 --- a/litebox_platform_linux_kernel/Cargo.toml +++ b/litebox_platform_linux_kernel/Cargo.toml @@ -23,6 +23,7 @@ zerocopy = { version = "0.8", default-features = false, features = ["derive"] } x86_64 = { version = "0.15.2", default-features = false, features = ["instructions"] } [dev-dependencies] +litebox_util_log = { version = "0.1.0", path = "../litebox_util_log" } syscalls = { version = "0.6", default-features = false } [lints] diff --git a/litebox_platform_linux_kernel/src/lib.rs b/litebox_platform_linux_kernel/src/lib.rs index 12f6bc2d1..cc207d3da 100644 --- a/litebox_platform_linux_kernel/src/lib.rs +++ b/litebox_platform_linux_kernel/src/lib.rs @@ -13,9 +13,8 @@ use litebox::mm::linux::PageRange; use litebox::platform::RawPointerProvider; use litebox::platform::page_mgmt::FixedAddressBehavior; use litebox::platform::{ - DebugLogProvider, IPInterfaceProvider, ImmediatelyWokenUp, PageManagementProvider, Provider, - Punchthrough, PunchthroughProvider, PunchthroughToken, RawMutexProvider, TimeProvider, - UnblockedOrTimedOut, + IPInterfaceProvider, ImmediatelyWokenUp, PageManagementProvider, Provider, Punchthrough, + PunchthroughProvider, PunchthroughToken, RawMutexProvider, TimeProvider, UnblockedOrTimedOut, }; use litebox_common_linux::PunchthroughSyscall; use litebox_common_linux::errno::Errno; @@ -207,12 +206,6 @@ impl RawMutex { } } -impl DebugLogProvider for LinuxKernel { - fn debug_log_print(&self, msg: &str) { - Host::log(msg); - } -} - /// An implementation of [`litebox::platform::Instant`] #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] pub struct Instant(u64); diff --git a/litebox_platform_linux_kernel/src/mm/tests.rs b/litebox_platform_linux_kernel/src/mm/tests.rs index 3987b530b..c0872a897 100644 --- a/litebox_platform_linux_kernel/src/mm/tests.rs +++ b/litebox_platform_linux_kernel/src/mm/tests.rs @@ -29,7 +29,6 @@ use crate::{ }, host::mock::{MockHostInterface, MockKernel}, mm::{MemoryProvider, pgtable::PageTableAllocator}, - mock_log_println, }; use super::pgtable::PageTableImpl; @@ -48,7 +47,7 @@ impl litebox::mm::allocator::MemoryProvider for MockKernel { let end = Page::::from_start_address(VirtAddr::new((start + len) as _)).unwrap(); for page in Page::range(begin, end) { if mapping.is_full() { - mock_log_println!("MAPPING is OOM"); + litebox_util_log::error!("MAPPING is OOM"); panic!() } mapping.push(page.start_address()); @@ -86,7 +85,7 @@ impl super::MemoryProvider for MockKernel { assert!(va.is_some()); let va = *va.unwrap(); if va.is_null() { - mock_log_println!("Invalid PA"); + litebox_util_log::error!("Invalid PA"); panic!("Invalid PA"); } va diff --git a/litebox_platform_linux_userland/src/lib.rs b/litebox_platform_linux_userland/src/lib.rs index c3e60a83a..ebf054a77 100644 --- a/litebox_platform_linux_userland/src/lib.rs +++ b/litebox_platform_linux_userland/src/lib.rs @@ -1542,21 +1542,6 @@ impl litebox::platform::PunchthroughProvider for LinuxUserland { } } -impl litebox::platform::DebugLogProvider for LinuxUserland { - fn debug_log_print(&self, msg: &str) { - let _ = unsafe { - syscalls::syscall4( - syscalls::Sysno::write, - litebox_common_linux::STDERR_FILENO as usize, - msg.as_ptr() as usize, - msg.len(), - // Unused by the syscall but would be checked by Seccomp filter if enabled. - syscall_intercept::SYSCALL_ARG_MAGIC, - ) - }; - } -} - type UserMutPtr = litebox::platform::common_providers::userspace_pointers::UserMutPtr< litebox::platform::common_providers::userspace_pointers::NoValidation, T, diff --git a/litebox_platform_lvbs/Cargo.toml b/litebox_platform_lvbs/Cargo.toml index 41fe9aff1..85039a90a 100644 --- a/litebox_platform_lvbs/Cargo.toml +++ b/litebox_platform_lvbs/Cargo.toml @@ -38,6 +38,7 @@ x86_64 = { version = "0.15.2", default-features = false, features = ["instructio [dev-dependencies] libc = "0.2.177" +litebox_util_log = { version = "0.1.0", path = "../litebox_util_log" } [features] default = ["optee_syscall"] diff --git a/litebox_platform_lvbs/src/lib.rs b/litebox_platform_lvbs/src/lib.rs index 2487086d7..56914cd75 100644 --- a/litebox_platform_lvbs/src/lib.rs +++ b/litebox_platform_lvbs/src/lib.rs @@ -13,10 +13,9 @@ use core::{ }; use hashbrown::HashMap; use litebox::platform::{ - DebugLogProvider, IPInterfaceProvider, ImmediatelyWokenUp, PageManagementProvider, - Punchthrough, PunchthroughProvider, PunchthroughToken, RawMutex as _, RawMutexProvider, - RawPointerProvider, StdioProvider, TimeProvider, UnblockedOrTimedOut, - page_mgmt::DeallocationError, + IPInterfaceProvider, ImmediatelyWokenUp, PageManagementProvider, Punchthrough, + PunchthroughProvider, PunchthroughToken, RawMutex as _, RawMutexProvider, RawPointerProvider, + StdioProvider, TimeProvider, UnblockedOrTimedOut, page_mgmt::DeallocationError, }; use litebox::{ mm::linux::{PAGE_SIZE, PageRange}, @@ -1054,12 +1053,6 @@ impl RawMutex { } } -impl DebugLogProvider for LinuxKernel { - fn debug_log_print(&self, msg: &str) { - Host::log(msg); - } -} - /// An implementation of [`litebox::platform::Instant`] #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] pub struct Instant(u64); diff --git a/litebox_platform_lvbs/src/mm/tests.rs b/litebox_platform_lvbs/src/mm/tests.rs index 7dccc55e7..4db1d761e 100644 --- a/litebox_platform_lvbs/src/mm/tests.rs +++ b/litebox_platform_lvbs/src/mm/tests.rs @@ -27,7 +27,6 @@ use crate::{ }, host::mock::{MockHostInterface, MockKernel}, mm::{MemoryProvider, pgtable::PageTableAllocator}, - mock_log_println, }; use super::pgtable::PageTableImpl; @@ -46,7 +45,7 @@ impl litebox::mm::allocator::MemoryProvider for MockKernel { let end = Page::::from_start_address(VirtAddr::new((start + len) as _)).unwrap(); for page in Page::range(begin, end) { if mapping.is_full() { - mock_log_println!("MAPPING is OOM"); + litebox_util_log::error!("MAPPING is OOM"); panic!() } mapping.push(page.start_address()); @@ -88,7 +87,7 @@ impl super::MemoryProvider for MockKernel { assert!(va.is_some()); let va = *va.unwrap(); if va.is_null() { - mock_log_println!("Invalid PA"); + litebox_util_log::error!("Invalid PA"); panic!("Invalid PA"); } va diff --git a/litebox_platform_windows_userland/src/lib.rs b/litebox_platform_windows_userland/src/lib.rs index 9d827e057..396282544 100644 --- a/litebox_platform_windows_userland/src/lib.rs +++ b/litebox_platform_windows_userland/src/lib.rs @@ -1511,15 +1511,6 @@ impl litebox::platform::PunchthroughProvider for WindowsUserland { } } -impl litebox::platform::DebugLogProvider for WindowsUserland { - fn debug_log_print(&self, msg: &str) { - // TODO: Implement Windows debug logging - // For now, use standard error output - use std::io::Write; - let _ = std::io::stderr().write_all(msg.as_bytes()); - } -} - type UserConstPtr = litebox::platform::common_providers::userspace_pointers::UserConstPtr< litebox::platform::common_providers::userspace_pointers::NoValidation, T, diff --git a/litebox_runner_optee_on_linux_userland/src/tests.rs b/litebox_runner_optee_on_linux_userland/src/tests.rs index dd5073ea6..2645e7415 100644 --- a/litebox_runner_optee_on_linux_userland/src/tests.rs +++ b/litebox_runner_optee_on_linux_userland/src/tests.rs @@ -118,12 +118,11 @@ fn handle_ta_command_output(params: &UteeParams) { match param_type { TeeParamType::ValueOutput | TeeParamType::ValueInout => { if let Ok(Some((value_a, value_b))) = params.get_values(idx) { - litebox::log_println!( - litebox_platform_multiplex::platform(), - "output (index: {}): {:#x} {:#x}", - idx, - value_a, - value_b, + litebox_util_log::info!( + idx:% = idx, + value_a:% = format_args!("{:#x}", value_a), + value_b:% = format_args!("{:#x}", value_b); + "output" ); // TODO: return the outcome to VTL0 } @@ -134,28 +133,25 @@ fn handle_ta_command_output(params: &UteeParams) { let ptr: UserConstPtr = UserConstPtr::from_ptr(addr as *const u8); let slice = ptr.to_owned_slice(len).unwrap_or_default(); if slice.is_empty() { - litebox::log_println!( - litebox_platform_multiplex::platform(), - "output (index: {}): {:#x}", - idx, - addr + litebox_util_log::info!( + idx:% = idx, + addr:% = format_args!("{:#x}", addr); + "output" ); } else if slice.len() < 16 { - litebox::log_println!( - litebox_platform_multiplex::platform(), - "output (index: {}): {:#x} {:?}", - idx, - addr, - slice + litebox_util_log::info!( + idx:% = idx, + addr:% = format_args!("{:#x}", addr), + data:? = slice; + "output" ); } else { - litebox::log_println!( - litebox_platform_multiplex::platform(), - "output (index: {}): {:#x} {:?}... (total {} bytes)", - idx, - addr, - &slice[..16], - slice.len() + litebox_util_log::info!( + idx:% = idx, + addr:% = format_args!("{:#x}", addr), + data:? = &slice[..16], + total:% = slice.len(); + "output" ); } // TODO: return the outcome to VTL0 diff --git a/litebox_runner_snp/src/main.rs b/litebox_runner_snp/src/main.rs index 80529321e..a1a0f12d6 100644 --- a/litebox_runner_snp/src/main.rs +++ b/litebox_runner_snp/src/main.rs @@ -89,13 +89,12 @@ pub extern "C" fn page_fault_handler(pt_regs: &mut litebox_common_linux::PtRegs) } } - litebox::log_println!( - litebox_platform_multiplex::platform(), - "page fault at {} for {} with code {} failed: {}", - pt_regs.rip, - addr, - code, - e + litebox_util_log::error!( + rip:% = pt_regs.rip, + addr:% = addr, + code:% = code, + err:% = e; + "page fault failed" ); litebox_platform_multiplex::platform() .terminate(globals::SM_SEV_TERM_SET, globals::SM_TERM_EXCEPTION); @@ -163,7 +162,7 @@ pub extern "C" fn sandbox_process_init( ); let platform = litebox_platform_linux_kernel::host::snp::snp_impl::SnpLinuxKernel::new(pgd); #[cfg(debug_assertions)] - litebox::log_println!(platform, "sandbox_process_init called\n"); + litebox_util_log::debug!("sandbox_process_init called"); litebox_platform_multiplex::set_platform(platform); let shim_builder = litebox_shim_linux::LinuxShimBuilder::new(); @@ -258,7 +257,7 @@ pub extern "C" fn sandbox_process_init( { Ok(program) => program, Err(err) => { - litebox::log_println!(platform, "failed to load program: {}", err); + litebox_util_log::error!(err:% = err; "failed to load program"); litebox_platform_linux_kernel::host::snp::snp_impl::HostSnpInterface::terminate( globals::SM_SEV_TERM_SET, globals::SM_TERM_GENERAL, @@ -299,10 +298,7 @@ pub extern "C" fn sandbox_tun_read_write() { core::hint::spin_loop(); }; #[cfg(debug_assertions)] - litebox::log_println!( - litebox_platform_multiplex::platform(), - "sandbox_tun_read_write started\n" - ); + litebox_util_log::debug!("sandbox_tun_read_write started"); while !litebox_platform_linux_kernel::host::snp::snp_impl::all_threads_exited() { let _timeout = loop { match shim diff --git a/litebox_shim_linux/Cargo.toml b/litebox_shim_linux/Cargo.toml index 94d889a7f..c89fed9ed 100644 --- a/litebox_shim_linux/Cargo.toml +++ b/litebox_shim_linux/Cargo.toml @@ -10,6 +10,7 @@ bitflags = "2.9.0" litebox = { path = "../litebox/", version = "0.1.0" } litebox_common_linux = { path = "../litebox_common_linux/", version = "0.1.0" } litebox_platform_multiplex = { path = "../litebox_platform_multiplex/", version = "0.1.0", default-features = false } +litebox_util_log = { version = "0.1.0", path = "../litebox_util_log" } once_cell = { version = "1.20.2", default-features = false, features = ["alloc", "race"] } thiserror = { version = "2.0.6", default-features = false } syscalls = { version = "0.6", default-features = false } diff --git a/litebox_shim_linux/src/lib.rs b/litebox_shim_linux/src/lib.rs index 2834f7b72..0536e01df 100644 --- a/litebox_shim_linux/src/lib.rs +++ b/litebox_shim_linux/src/lib.rs @@ -70,11 +70,8 @@ impl ShimFS for T {} /// On debug builds, logs that the user attempted to use an unsupported feature. fn log_unsupported_fmt(args: core::fmt::Arguments<'_>) { - use litebox::platform::DebugLogProvider as _; - if cfg!(debug_assertions) { - let msg = alloc::format!("WARNING: unsupported: {args}\n"); - litebox_platform_multiplex::platform().debug_log_print(&msg); + litebox_util_log::warn!(feature:% = args; "unsupported"); } } diff --git a/litebox_shim_linux/src/syscalls/file.rs b/litebox_shim_linux/src/syscalls/file.rs index 03bf151ad..132f6d0e3 100644 --- a/litebox_shim_linux/src/syscalls/file.rs +++ b/litebox_shim_linux/src/syscalls/file.rs @@ -1441,10 +1441,7 @@ impl Task { |_file_fd| { // TODO: stdio NONBLOCK? #[cfg(debug_assertions)] - litebox::log_println!( - self.global.platform, - "Attempted to set non-blocking on raw fd; currently unimplemented" - ); + litebox_util_log::debug!("set non-blocking on raw fd unimplemented"); Ok(()) }, |socket_fd| { @@ -1569,7 +1566,7 @@ impl Task { )?, _ => { #[cfg(debug_assertions)] - litebox::log_println!(self.global.platform, "\n\n\n{:?}\n\n\n", arg); + litebox_util_log::debug!(arg:? = arg; "unhandled ioctl"); todo!() } } diff --git a/litebox_shim_linux/src/syscalls/process.rs b/litebox_shim_linux/src/syscalls/process.rs index 70f878cde..2eed4b677 100644 --- a/litebox_shim_linux/src/syscalls/process.rs +++ b/litebox_shim_linux/src/syscalls/process.rs @@ -775,7 +775,7 @@ impl Task { ) }; if let Err(err) = r { - litebox::log_println!(self.global.platform, "failed to spawn thread: {}", err); + litebox_util_log::error!(err:% = err; "failed to spawn thread"); // Treat all spawn errors as `ENOMEM`. `EAGAIN` and other errors are // for conditions the user can control (such as "in-shim" rlimit // violations). diff --git a/litebox_shim_linux/src/syscalls/signal/mod.rs b/litebox_shim_linux/src/syscalls/signal/mod.rs index e06825cf8..26176b5b4 100644 --- a/litebox_shim_linux/src/syscalls/signal/mod.rs +++ b/litebox_shim_linux/src/syscalls/signal/mod.rs @@ -584,12 +584,11 @@ impl Task { // STOP is not currently supported, so treat as // terminate. Core dumps are also not currently // supported. - litebox::log_println!( - self.global.platform, - "-- Fatal signal {:?}: terminating task {}:{}", - signal, - self.pid, - self.tid, + litebox_util_log::error!( + signal:? = signal, + pid:% = self.pid, + tid:% = self.tid; + "fatal signal: terminating task" ); self.exit_group(ExitStatus::Signal(signal)); } diff --git a/litebox_shim_optee/Cargo.toml b/litebox_shim_optee/Cargo.toml index 9bc43c2dd..fc261452a 100644 --- a/litebox_shim_optee/Cargo.toml +++ b/litebox_shim_optee/Cargo.toml @@ -13,6 +13,7 @@ litebox = { path = "../litebox/", version = "0.1.0" } litebox_common_linux = { path = "../litebox_common_linux/", version = "0.1.0" } litebox_common_optee = { path = "../litebox_common_optee/", version = "0.1.0" } litebox_platform_multiplex = { path = "../litebox_platform_multiplex/", version = "0.1.0", default-features = false } +litebox_util_log = { version = "0.1.0", path = "../litebox_util_log" } num_enum = { version = "0.7.3", default-features = false } once_cell = { version = "1.20.2", default-features = false, features = ["alloc", "race"] } spin = { version = "0.10.0", default-features = false, features = ["spin_mutex", "once"] } diff --git a/litebox_shim_optee/src/msg_handler.rs b/litebox_shim_optee/src/msg_handler.rs index 4ea51728c..e83cd54bb 100644 --- a/litebox_shim_optee/src/msg_handler.rs +++ b/litebox_shim_optee/src/msg_handler.rs @@ -179,10 +179,9 @@ pub fn handle_optee_smc_args( ) -> Result, OpteeSmcReturnCode> { let func_id = smc.func_id()?; #[cfg(debug_assertions)] - litebox::log_println!( - litebox_platform_multiplex::platform(), - "OP-TEE SMC Function: {:?}", - func_id + litebox_util_log::debug!( + func_id:? = func_id; + "OP-TEE SMC function" ); match func_id { OpteeSmcFunction::CallWithArg => { diff --git a/litebox_shim_optee/src/syscalls/ldelf.rs b/litebox_shim_optee/src/syscalls/ldelf.rs index 72f6a5ab4..2d9d179ba 100644 --- a/litebox_shim_optee/src/syscalls/ldelf.rs +++ b/litebox_shim_optee/src/syscalls/ldelf.rs @@ -34,13 +34,12 @@ impl Task { }; #[cfg(debug_assertions)] - litebox::log_println!( - self.global.platform, - "sys_map_zi: va {:#x} (addr {:#x}), num_bytes {}, flags {:#x}", - va.as_usize(), - addr, - num_bytes, - flags + litebox_util_log::debug!( + va:% = format_args!("{:#x}", va.as_usize()), + addr:% = format_args!("{:#x}", addr), + num_bytes:% = num_bytes, + flags:% = format_args!("{:#x}", flags); + "sys_map_zi" ); let accept_flags = LdelfMapFlags::LDELF_MAP_FLAG_SHAREABLE; @@ -94,11 +93,10 @@ impl Task { /// OP-TEE's syscall to open a TA binary. pub fn sys_open_bin(&self, ta_uuid: TeeUuid, handle: UserMutPtr) -> Result<(), TeeResult> { #[cfg(debug_assertions)] - litebox::log_println!( - self.global.platform, - "sys_open_bin: ta_uuid {:?}, handle {:#x}", - ta_uuid, - handle.as_usize() + litebox_util_log::debug!( + ta_uuid:? = ta_uuid, + handle:% = format_args!("{:#x}", handle.as_usize()); + "sys_open_bin" ); if self.global.get_ta_bin(&ta_uuid).is_none() { @@ -113,7 +111,7 @@ impl Task { /// OP-TEE's syscall to close a TA binary. pub fn sys_close_bin(&self, handle: u32) -> Result<(), TeeResult> { #[cfg(debug_assertions)] - litebox::log_println!(self.global.platform, "sys_close_bin: handle {}", handle); + litebox_util_log::debug!(handle:% = handle; "sys_close_bin"); if self.ta_handle_map.get(handle).is_none() { Err(TeeResult::BadParameters) @@ -140,17 +138,16 @@ impl Task { }; #[cfg(debug_assertions)] - litebox::log_println!( - self.global.platform, - "sys_map_bin: va {:#x} (addr {:#x}), num_bytes {}, handle {}, offs {}, pad_begin {}, pad_end {}, flags {:#x}", - va.as_usize(), - addr, - num_bytes, - handle, - offs, - pad_begin, - pad_end, - flags + litebox_util_log::debug!( + va:% = format_args!("{:#x}", va.as_usize()), + addr:% = format_args!("{:#x}", addr), + num_bytes:% = num_bytes, + handle:% = handle, + offs:% = offs, + pad_begin:% = pad_begin, + pad_end:% = pad_end, + flags:% = format_args!("{:#x}", flags); + "sys_map_bin" ); let accept_flags = LdelfMapFlags::LDELF_MAP_FLAG_SHAREABLE @@ -272,13 +269,12 @@ impl Task { handle: u32, ) -> Result<(), TeeResult> { #[cfg(debug_assertions)] - litebox::log_println!( - self.global.platform, - "sys_cp_from_bin: dst {:#x}, offs {}, num_bytes {}, handle {}", - dst, - offs, - num_bytes, - handle, + litebox_util_log::debug!( + dst:% = format_args!("{:#x}", dst), + offs:% = offs, + num_bytes:% = num_bytes, + handle:% = handle; + "sys_cp_from_bin" ); self.read_ta_bin(handle, UserMutPtr::from_usize(dst), offs, num_bytes) diff --git a/litebox_shim_optee/src/syscalls/pta.rs b/litebox_shim_optee/src/syscalls/pta.rs index 8a20135d8..0c1000b47 100644 --- a/litebox_shim_optee/src/syscalls/pta.rs +++ b/litebox_shim_optee/src/syscalls/pta.rs @@ -118,11 +118,10 @@ impl Task { // TODO: checks whether output is within the secure memory // TODO: derive a TA unique key using the hardware unique key (HUK), TA's UUID, and `extra_data` - litebox::log_println!( - self.global.platform, - "derive a key and store it in the secure memory (ptr: {:#x}, size: {})", - output_addr, - output_len + litebox_util_log::debug!( + ptr:% = format_args!("{:#x}", output_addr), + size:% = output_len; + "derive key into secure memory" ); // TODO: replace below with a secure key derivation function let mut key_buf = alloc::vec![0u8; output_len]; diff --git a/litebox_shim_optee/src/syscalls/tee.rs b/litebox_shim_optee/src/syscalls/tee.rs index 87bf14ce5..25e8f593a 100644 --- a/litebox_shim_optee/src/syscalls/tee.rs +++ b/litebox_shim_optee/src/syscalls/tee.rs @@ -38,7 +38,7 @@ impl Task { #[allow(clippy::unused_self)] pub fn sys_return(&self, ret: usize) -> usize { #[cfg(debug_assertions)] - litebox::log_println!(self.global.platform, "sys_return: ret {}", ret); + litebox_util_log::debug!(ret:% = ret; "sys_return"); ret } @@ -47,17 +47,25 @@ impl Task { /// /// Per OP-TEE OS behavior: when a TA panics, the kernel returns `TEE_ERROR_TARGET_DEAD` /// to the caller, regardless of the panic code. The panic code is logged for debugging. + #[expect( + clippy::unused_self, + reason = "self was used by the old platform-threaded logging API" + )] pub fn sys_panic(&self, code: usize) -> usize { - litebox::log_println!(self.global.platform, "TA panic with code {:#x}", code,); + litebox_util_log::error!(code:% = format_args!("{:#x}", code); "TA panic"); // Return TARGET_DEAD to match OP-TEE OS behavior litebox_common_optee::TeeResult::TargetDead as usize } /// A system call to print out a message. + #[expect( + clippy::unused_self, + reason = "self was used by the old platform-threaded logging API" + )] pub fn sys_log(&self, buf: &[u8]) -> Result<(), TeeResult> { let msg = core::str::from_utf8(buf).map_err(|_| TeeResult::BadFormat)?; - litebox::log_println!(self.global.platform, "{}", msg); + litebox_util_log::info!(msg:% = msg; "sys_log"); Ok(()) }