From 6a029c340ab21dc88bf320eaf92c8dbecad23652 Mon Sep 17 00:00:00 2001 From: Matthew Leach Date: Tue, 25 Nov 2025 16:43:37 +0000 Subject: [PATCH] syscall: gettimeofday: impement Provide a dummy implementation of sys_gettimeofday --- etc/syscalls_linux_aarch64.md | 2 +- src/arch/arm64/exceptions/syscall.rs | 3 ++- src/clock/mod.rs | 1 + src/clock/timeofday.rs | 31 ++++++++++++++++++++++++++++ 4 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 src/clock/timeofday.rs diff --git a/etc/syscalls_linux_aarch64.md b/etc/syscalls_linux_aarch64.md index d4a83bd..b7e5cf0 100644 --- a/etc/syscalls_linux_aarch64.md +++ b/etc/syscalls_linux_aarch64.md @@ -169,7 +169,7 @@ | 0xa6 (166) | umask | (int mask) | __arm64_sys_umask | true | | 0xa7 (167) | prctl | (int option, unsigned long arg2, unsigned long arg3, unsigned long arg4, unsigned long arg5) | __arm64_sys_prctl | false | | 0xa8 (168) | getcpu | (unsigned *cpup, unsigned *nodep, struct getcpu_cache *unused) | __arm64_sys_getcpu | false | -| 0xa9 (169) | gettimeofday | (struct __kernel_old_timeval *tv, struct timezone *tz) | __arm64_sys_gettimeofday | false | +| 0xa9 (169) | gettimeofday | (struct __kernel_old_timeval *tv, struct timezone *tz) | __arm64_sys_gettimeofday | dummy | | 0xaa (170) | settimeofday | (struct __kernel_old_timeval *tv, struct timezone *tz) | __arm64_sys_settimeofday | false | | 0xab (171) | adjtimex | (struct __kernel_timex *txc_p) | __arm64_sys_adjtimex | false | | 0xac (172) | getpid | () | __arm64_sys_getpid | true | diff --git a/src/arch/arm64/exceptions/syscall.rs b/src/arch/arm64/exceptions/syscall.rs index 7be3fdf..bce7050 100644 --- a/src/arch/arm64/exceptions/syscall.rs +++ b/src/arch/arm64/exceptions/syscall.rs @@ -1,7 +1,7 @@ use crate::kernel::power::sys_reboot; use crate::{ arch::{Arch, ArchImpl}, - clock::gettime::sys_clock_gettime, + clock::{gettime::sys_clock_gettime, timeofday::sys_gettimeofday}, fs::{ dir::sys_getdents64, pipe::sys_pipe2, @@ -210,6 +210,7 @@ pub async fn handle_syscall() { 0x9b => sys_getpgid(arg1 as _), 0xa0 => sys_uname(TUA::from_value(arg1 as _)).await, 0xa6 => sys_umask(arg1 as _).map_err(|e| match e {}), + 0xa9 => sys_gettimeofday(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/mod.rs b/src/clock/mod.rs index 605a70b..58ef00d 100644 --- a/src/clock/mod.rs +++ b/src/clock/mod.rs @@ -1,3 +1,4 @@ pub mod gettime; pub mod realtime; +pub mod timeofday; pub mod timespec; diff --git a/src/clock/timeofday.rs b/src/clock/timeofday.rs new file mode 100644 index 0000000..415cd35 --- /dev/null +++ b/src/clock/timeofday.rs @@ -0,0 +1,31 @@ +use super::timespec::TimeSpec; +use crate::memory::uaccess::{UserCopyable, copy_to_user}; +use core::time::Duration; +use libkernel::{error::Result, memory::address::TUA}; + +#[derive(Copy, Clone)] +pub struct TimeZone { + _tz_minuteswest: i32, + _tz_dsttime: i32, +} + +unsafe impl UserCopyable for TimeZone {} + +pub async fn sys_gettimeofday(tv: TUA, tz: TUA) -> Result { + let time: TimeSpec = Duration::new(0, 0).into(); + + copy_to_user(tv, time).await?; + + if !tz.is_null() { + copy_to_user( + tz, + TimeZone { + _tz_minuteswest: 0, + _tz_dsttime: 0, + }, + ) + .await?; + } + + Ok(0) +}