From f35a923dee58074abf1696117092f5970daabd5d Mon Sep 17 00:00:00 2001 From: ryan Date: Fri, 11 Jul 2025 19:51:47 -0400 Subject: [PATCH] add dmesg-y lines --- src/main.rs | 8 ++++++-- src/system/mod.rs | 10 ++++++++++ src/system/syscall.rs | 21 +++++++++++++++++++++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index b1b2fb2..b13d5b2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -74,6 +74,8 @@ fn init() -> Result<()> { init_console()?; + system::dmesg("EnclaveOS Booted"); + std::thread::sleep(std::time::Duration::from_secs(500)); /* @@ -110,11 +112,13 @@ fn init() -> Result<()> { } fn init_console() -> Result<(), result::CtxError> { - Ok(for (filename, mode, fd) in [ + for (filename, mode, fd) in [ ("/dev/console", "r", 0), ("/dev/console", "w", 1), ("/dev/console", "w", 2), ] { system::syscall::freopen(filename, mode, &fd)?; - }) + } + + Ok(()) } diff --git a/src/system/mod.rs b/src/system/mod.rs index 257dee7..cf30e03 100644 --- a/src/system/mod.rs +++ b/src/system/mod.rs @@ -4,6 +4,11 @@ use std::path::{Path, PathBuf}; pub mod syscall; +pub fn dmesg(value: impl std::fmt::Display) { + let timespec = syscall::clock_gettime(libc::CLOCK_BOOTTIME).unwrap(); + eprintln!("[{: >5}.{}]{value}", timespec.tv_sec, timespec.tv_nsec / 1000); +} + pub enum MountType { DevTmpFs, DevPts, @@ -62,6 +67,11 @@ impl Mount { } pub fn mount_self(&self) -> Result<()> { + dmesg(format!( + "Mounting {source} to {target}", + source = self.source.display(), + target = self.target.display() + )); syscall::mount( &self.source, &self.target, diff --git a/src/system/syscall.rs b/src/system/syscall.rs index a57a03b..55b2dc0 100644 --- a/src/system/syscall.rs +++ b/src/system/syscall.rs @@ -15,6 +15,27 @@ use std::{ path::Path, }; +pub fn clock_gettime(clock_id: libc::clockid_t) -> Result { + let mut t = libc::timespec { + tv_sec: 0, + tv_nsec: 0, + }; + + match unsafe { libc::clock_gettime(clock_id, std::ptr::from_mut(&mut t)) } { + 0 => Ok(t), + -1 => { + // at this point, Err(ctx_os_error()) is starting to seem appealing + ctx_os_error(format_args!("error calling clock_gettime({clock_id}, ...)")).map(|()| { + libc::timespec { + tv_sec: 0, + tv_nsec: 0, + } + }) + } + n => unreachable!("clock_gettime() syscall returned bad value: {n}"), + } +} + pub fn mount( src: impl AsRef, target: impl AsRef,