From 27f802831554f9531dc5131b96cd92167b3af136 Mon Sep 17 00:00:00 2001 From: Ashwin Naren Date: Wed, 14 Jan 2026 01:13:26 -0800 Subject: [PATCH] proper timeofday implementations --- src/arch/arm64/exceptions/syscall.rs | 6 +++++- src/clock/realtime.rs | 7 +++++++ src/clock/timeofday.rs | 12 ++++++++++-- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/arch/arm64/exceptions/syscall.rs b/src/arch/arm64/exceptions/syscall.rs index 33c2280..ddebf56 100644 --- a/src/arch/arm64/exceptions/syscall.rs +++ b/src/arch/arm64/exceptions/syscall.rs @@ -1,6 +1,9 @@ use crate::{ arch::{Arch, ArchImpl}, - clock::{gettime::sys_clock_gettime, timeofday::sys_gettimeofday}, + clock::{ + gettime::sys_clock_gettime, + timeofday::{sys_gettimeofday, sys_settimeofday}, + }, fs::{ dir::sys_getdents64, pipe::sys_pipe2, @@ -390,6 +393,7 @@ pub async fn handle_syscall() { 0xa6 => sys_umask(arg1 as _).map_err(|e| match e {}), 0xa7 => sys_prctl(arg1 as _, arg2).await, 0xa9 => sys_gettimeofday(TUA::from_value(arg1 as _), TUA::from_value(arg2 as _)).await, + 0xaa => sys_settimeofday(TUA::from_value(arg1 as _), TUA::from_value(arg2 as _)).await, 0xac => sys_getpid().map_err(|e| match e {}), 0xad => sys_getppid().map_err(|e| match e {}), 0xae => sys_getuid().map_err(|e| match e {}), diff --git a/src/clock/realtime.rs b/src/clock/realtime.rs index 712210d..837595a 100644 --- a/src/clock/realtime.rs +++ b/src/clock/realtime.rs @@ -18,5 +18,12 @@ pub fn date() -> Duration { } } +pub fn set_date(duration: Duration) { + if let Some(now) = now() { + let mut epoch_info = EPOCH_DURATION.lock_save_irq(); + *epoch_info = Some((duration, now)); + } +} + // Represents a known duration since the epoch at the assoicated instant. static EPOCH_DURATION: SpinLock> = SpinLock::new(None); diff --git a/src/clock/timeofday.rs b/src/clock/timeofday.rs index 415cd35..0381b29 100644 --- a/src/clock/timeofday.rs +++ b/src/clock/timeofday.rs @@ -1,5 +1,6 @@ use super::timespec::TimeSpec; -use crate::memory::uaccess::{UserCopyable, copy_to_user}; +use crate::clock::realtime::{date, set_date}; +use crate::memory::uaccess::{UserCopyable, copy_from_user, copy_to_user}; use core::time::Duration; use libkernel::{error::Result, memory::address::TUA}; @@ -12,7 +13,7 @@ pub struct TimeZone { unsafe impl UserCopyable for TimeZone {} pub async fn sys_gettimeofday(tv: TUA, tz: TUA) -> Result { - let time: TimeSpec = Duration::new(0, 0).into(); + let time: TimeSpec = date().into(); copy_to_user(tv, time).await?; @@ -29,3 +30,10 @@ pub async fn sys_gettimeofday(tv: TUA, tz: TUA) -> Result, _tz: TUA) -> Result { + let time: TimeSpec = copy_from_user(tv).await?; + let duration: Duration = time.into(); + set_date(duration); + Ok(0) +}