From 15cbeadc1c6b4041d9eac475824d4c8b58360f50 Mon Sep 17 00:00:00 2001 From: Weidong Cui Date: Mon, 6 Apr 2026 20:50:55 -0700 Subject: [PATCH] Misc cleanup: pub(crate) mock fields, log_println allow, current_processor_number, stdin guard Small independent cleanups: - Make MockInstant::time and MockSystemTime::time pub(crate) so tests in other modules can construct instances with specific values. - Add #[allow(unused_imports)] to log_println! macro use-statements to suppress warnings when the macro is invoked in contexts where the import is redundant. - Add SystemInfoProvider::current_processor_number() default method returning 0, for platforms that don't expose processor topology. - Add empty-buffer early return in MockPlatform::read_from_stdin() to avoid unnecessarily consuming queued input on zero-length reads. --- litebox/src/platform/mock.rs | 7 +++++-- litebox/src/platform/mod.rs | 12 ++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/litebox/src/platform/mock.rs b/litebox/src/platform/mock.rs index 3a3297aa6..332d41440 100644 --- a/litebox/src/platform/mock.rs +++ b/litebox/src/platform/mock.rs @@ -210,7 +210,7 @@ impl IPInterfaceProvider for MockPlatform { #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] pub(crate) struct MockInstant { - time: u64, + pub(crate) time: u64, } impl Instant for MockInstant { @@ -230,7 +230,7 @@ impl Instant for MockInstant { } pub(crate) struct MockSystemTime { - time: u64, + pub(crate) time: u64, } impl SystemTime for MockSystemTime { @@ -290,6 +290,9 @@ impl RawPointerProvider for MockPlatform { impl StdioProvider for MockPlatform { fn read_from_stdin(&self, buf: &mut [u8]) -> Result { + if buf.is_empty() { + return Ok(0); + } let Some(front) = self.stdin_queue.write().unwrap().pop_front() else { return Err(StdioReadError::Closed); }; diff --git a/litebox/src/platform/mod.rs b/litebox/src/platform/mod.rs index 983f20c84..4fa88066e 100644 --- a/litebox/src/platform/mod.rs +++ b/litebox/src/platform/mod.rs @@ -23,11 +23,13 @@ pub use page_mgmt::PageManagementProvider; #[macro_export] macro_rules! log_println { ($platform:expr, $s:expr) => {{ + #[allow(unused_imports)] use $crate::platform::DebugLogProvider as _; $platform.debug_log_print($s); }}; ($platform:expr, $($tt:tt)*) => {{ use core::fmt::Write as _; + #[allow(unused_imports)] use $crate::platform::DebugLogProvider as _; let mut t: arrayvec::ArrayString<8192> = arrayvec::ArrayString::new(); writeln!(t, $($tt)*).unwrap(); @@ -666,6 +668,16 @@ pub trait SystemInfoProvider { /// Return `Some(address)` if the VDSO is available on the platform, or `None` /// if the platform does not support or provide a VDSO. fn get_vdso_address(&self) -> Option; + + /// Returns the current processor number, used to emulate `getcpu`-family + /// syscalls and related VDSO interfaces. + /// + /// Platforms that do not expose a stable processor identifier, or that + /// virtualize CPU topology, may return `0`. Callers arrive in subsequent + /// stacked PRs. + fn current_processor_number(&self) -> u32 { + 0 + } } /// A provider for thread-local storage.