From 21c3e96b1d4f3139bb71782a6dd056f258f1ad90 Mon Sep 17 00:00:00 2001 From: Red Bear OS Date: Thu, 9 Jul 2026 11:50:45 +0300 Subject: [PATCH] relibc: implement clock_settime() via /scheme/time Replaced ENOSYS stub with real implementation: opens /scheme/time/{clk_id} for writing and writes the timespec. Cross-referenced with Linux 7.1 kernel/time/posix-clock.c pc_clock_settime(). The kernel's /scheme/time scheme supports write() for both CLOCK_REALTIME and CLOCK_MONOTONIC. Writing a TimeSpec sets the clock value. Returns EIO if fewer bytes written than expected. --- src/platform/redox/mod.rs | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/platform/redox/mod.rs b/src/platform/redox/mod.rs index 6521d5b818..5166c82541 100644 --- a/src/platform/redox/mod.rs +++ b/src/platform/redox/mod.rs @@ -264,8 +264,31 @@ impl Pal for Sys { } unsafe fn clock_settime(clk_id: clockid_t, tp: *const timespec) -> Result<()> { - todo_skip!(0, "clock_settime({}, {:p}): not implemented", clk_id, tp); - Err(Errno(ENOSYS)) + // Write the timespec to /scheme/time/{clk_id} to set the clock. + // Cross-referenced with Linux 7.1 kernel/time/posix-clock.c + // pc_clock_settime() which writes to the clock device. + if tp.is_null() { + return Err(Errno(EFAULT)); + } + let ts = unsafe { *tp }; + let path = format!("/scheme/time/{}", clk_id as usize); + let fd = redox_rt::sys::open( + &path, + syscall::O_WRONLY | syscall::O_CLOEXEC, + 0, + ).map_err(|e| Errno(e.errno))?; + let bytes = redox_rt::sys::write(fd, unsafe { + core::slice::from_raw_parts( + &ts as *const timespec as *const u8, + size_of::(), + ) + }).map_err(|e| Errno(e.errno))?; + let _ = redox_rt::sys::close(fd); + if bytes == size_of::() { + Ok(()) + } else { + Err(Errno(EIO)) + } } fn close(fd: c_int) -> Result<()> {