Skip to content
Open
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: 4 additions & 0 deletions Cargo.lock

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

6 changes: 0 additions & 6 deletions litebox/src/platform/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: zerocopy::FromBytes> = super::trivial_providers::TransparentConstPtr<T>;
type RawMutPointer<T: zerocopy::FromBytes + zerocopy::IntoBytes> =
Expand Down
36 changes: 1 addition & 35 deletions litebox/src/platform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
}

Expand Down Expand Up @@ -439,20 +419,6 @@ pub trait SystemTime: Send + Sync {
fn duration_since(&self, earlier: &Self) -> Result<core::time::Duration, core::time::Duration>;
}

/// 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
Expand Down
1 change: 1 addition & 0 deletions litebox_platform_linux_kernel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
11 changes: 2 additions & 9 deletions litebox_platform_linux_kernel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -207,12 +206,6 @@ impl<Host: HostInterface> RawMutex<Host> {
}
}

impl<Host: HostInterface> DebugLogProvider for LinuxKernel<Host> {
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);
Expand Down
5 changes: 2 additions & 3 deletions litebox_platform_linux_kernel/src/mm/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ use crate::{
},
host::mock::{MockHostInterface, MockKernel},
mm::{MemoryProvider, pgtable::PageTableAllocator},
mock_log_println,
};

use super::pgtable::PageTableImpl;
Expand All @@ -48,7 +47,7 @@ impl litebox::mm::allocator::MemoryProvider for MockKernel {
let end = Page::<Size4KiB>::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());
Expand Down Expand Up @@ -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
Expand Down
15 changes: 0 additions & 15 deletions litebox_platform_linux_userland/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> = litebox::platform::common_providers::userspace_pointers::UserMutPtr<
litebox::platform::common_providers::userspace_pointers::NoValidation,
T,
Expand Down
1 change: 1 addition & 0 deletions litebox_platform_lvbs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
13 changes: 3 additions & 10 deletions litebox_platform_lvbs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -1054,12 +1053,6 @@ impl<Host: HostInterface> RawMutex<Host> {
}
}

impl<Host: HostInterface> DebugLogProvider for LinuxKernel<Host> {
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);
Expand Down
5 changes: 2 additions & 3 deletions litebox_platform_lvbs/src/mm/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ use crate::{
},
host::mock::{MockHostInterface, MockKernel},
mm::{MemoryProvider, pgtable::PageTableAllocator},
mock_log_println,
};

use super::pgtable::PageTableImpl;
Expand All @@ -46,7 +45,7 @@ impl litebox::mm::allocator::MemoryProvider for MockKernel {
let end = Page::<Size4KiB>::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());
Expand Down Expand Up @@ -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
Expand Down
9 changes: 0 additions & 9 deletions litebox_platform_windows_userland/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> = litebox::platform::common_providers::userspace_pointers::UserConstPtr<
litebox::platform::common_providers::userspace_pointers::NoValidation,
T,
Expand Down
44 changes: 20 additions & 24 deletions litebox_runner_optee_on_linux_userland/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -134,28 +133,25 @@ fn handle_ta_command_output(params: &UteeParams) {
let ptr: UserConstPtr<u8> = 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
Expand Down
22 changes: 9 additions & 13 deletions litebox_runner_snp/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions litebox_shim_linux/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
5 changes: 1 addition & 4 deletions litebox_shim_linux/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,8 @@ impl<T: litebox::fs::FileSystem + Send + Sync + 'static> 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");
}
}

Expand Down
Loading