Merge pull request #155 from arihant2math/timeofday

Proper timeofday implementations
This commit is contained in:
Matthew Leach
2026-01-15 12:24:50 +00:00
committed by GitHub
3 changed files with 22 additions and 3 deletions

View File

@@ -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,
@@ -473,6 +476,7 @@ pub async fn handle_syscall() {
0xa6 => sys_umask(arg1 as _).map_err(|e| match e {}),
0xa7 => sys_prctl(arg1 as _, arg2, arg3).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 {}),

View File

@@ -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<Option<(Duration, Instant)>> = SpinLock::new(None);

View File

@@ -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<TimeSpec>, tz: TUA<TimeZone>) -> Result<usize> {
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<TimeSpec>, tz: TUA<TimeZone>) -> Result<us
Ok(0)
}
pub async fn sys_settimeofday(tv: TUA<TimeSpec>, _tz: TUA<TimeZone>) -> Result<usize> {
let time: TimeSpec = copy_from_user(tv).await?;
let duration: Duration = time.into();
set_date(duration);
Ok(0)
}