From fe1c4e013554c17ec1e796c60e80d765db2939f0 Mon Sep 17 00:00:00 2001 From: auronandace Date: Sun, 5 Jul 2026 10:50:57 +0100 Subject: [PATCH] add descriptions to sleep and nanosleep --- Cargo.toml | 2 +- src/header/time/mod.rs | 14 ++++++++++++++ src/header/unistd/mod.rs | 12 ++++++++++-- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7c2f1471ad..4891f6a806 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,7 +38,7 @@ ptr_as_ptr = "warn" # TODO review occurrences ptr_cast_constness = "warn" # TODO review occurrences ref_as_ptr = "warn" # TODO review occurrences upper_case_acronyms = "allow" # TODO review occurrences -zero_ptr = "warn" # must allow on public constants due to cbindgen issue +zero_ptr = "deny" # must allow on public constants due to cbindgen issue [workspace.lints.rust] dangling_pointers_from_temporaries = "deny" diff --git a/src/header/time/mod.rs b/src/header/time/mod.rs index 0c9636a1cb..89819f1905 100644 --- a/src/header/time/mod.rs +++ b/src/header/time/mod.rs @@ -485,7 +485,21 @@ pub unsafe extern "C" fn mktime(timeptr: *mut tm) -> time_t { timestamp } +// FIXME seems redox-rt sys posix_nanosleep calls wrapper which disables signals /// See . +/// +/// Causes the current thread to be suspended from execution until either the +/// time interval specified by `rqtp` has elapsed or a signal is delivered to +/// the calling thread, and its action is to invoke a signal-catching function +/// or to terminate the process. +/// +/// Has no effect on the action or blockage of any signal. +/// +/// Upon success, returns `0`. Upon failure, returns `-1` and sets errno to +/// indicate the error. If `rmtp` is non-NULL and `nanosleep()` is interrupted +/// by a signal, returns `-1` and updates `rmtp` to contain the requested time +/// minus the actually elapsed time. If `rmtp` is NULL the remaining time is +/// not returned. #[unsafe(no_mangle)] pub unsafe extern "C" fn nanosleep(rqtp: *const timespec, rmtp: *mut timespec) -> c_int { unsafe { Sys::nanosleep(rqtp, rmtp) } diff --git a/src/header/unistd/mod.rs b/src/header/unistd/mod.rs index 9628f84095..cc717d4278 100644 --- a/src/header/unistd/mod.rs +++ b/src/header/unistd/mod.rs @@ -1047,6 +1047,14 @@ pub extern "C" fn setuid(uid: uid_t) -> c_int { } /// See . +/// +/// Causes the calling thread to be suspended from execution until either the +/// number of realtime seconds by the specified argument `seconds` has elapsed +/// or a signal is delivered to the calling thread and its action is to invoke +/// a signal-catching function or to terminate the process. +/// +/// Upon success, returns `0`. Upon interruption by a signal, returns the +/// unslept amount in seconds. #[unsafe(no_mangle)] pub extern "C" fn sleep(seconds: c_uint) -> c_uint { let rqtp = timespec { @@ -1062,8 +1070,8 @@ pub extern "C" fn sleep(seconds: c_uint) -> c_uint { // If sleep() returns due to delivery of a signal, the return value shall be the "unslept" amount // (the requested time minus the time actually slept) in seconds. match unsafe { Sys::nanosleep(&raw const rqtp, &raw mut rmtp) } { - Err(Errno(EINTR)) => rmtp.tv_sec as c_uint, - r => 0, + Err(Errno(_)) => rmtp.tv_sec as c_uint, + _ => 0, } }