diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 13:54:38 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 13:54:38 +0000 |
commit | 8c1ab65c0f548d20b7f177bdb736daaf603340e1 (patch) | |
tree | df55b7e75bf43f2bf500845b105afe3ac3a5157e /libc-top-half/musl/src/signal/sigtimedwait.c | |
parent | Initial commit. (diff) | |
download | wasi-libc-8c1ab65c0f548d20b7f177bdb736daaf603340e1.tar.xz wasi-libc-8c1ab65c0f548d20b7f177bdb736daaf603340e1.zip |
Adding upstream version 0.0~git20221206.8b7148f.upstream/0.0_git20221206.8b7148f
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'libc-top-half/musl/src/signal/sigtimedwait.c')
-rw-r--r-- | libc-top-half/musl/src/signal/sigtimedwait.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/libc-top-half/musl/src/signal/sigtimedwait.c b/libc-top-half/musl/src/signal/sigtimedwait.c new file mode 100644 index 0000000..1287174 --- /dev/null +++ b/libc-top-half/musl/src/signal/sigtimedwait.c @@ -0,0 +1,32 @@ +#include <signal.h> +#include <errno.h> +#include "syscall.h" + +#define IS32BIT(x) !((x)+0x80000000ULL>>32) +#define CLAMP(x) (int)(IS32BIT(x) ? (x) : 0x7fffffffU+((0ULL+(x))>>63)) + +static int do_sigtimedwait(const sigset_t *restrict mask, siginfo_t *restrict si, const struct timespec *restrict ts) +{ +#ifdef SYS_rt_sigtimedwait_time64 + time_t s = ts ? ts->tv_sec : 0; + long ns = ts ? ts->tv_nsec : 0; + int r = -ENOSYS; + if (SYS_rt_sigtimedwait == SYS_rt_sigtimedwait_time64 || !IS32BIT(s)) + r = __syscall_cp(SYS_rt_sigtimedwait_time64, mask, si, + ts ? ((long long[]){s, ns}) : 0, _NSIG/8); + if (SYS_rt_sigtimedwait == SYS_rt_sigtimedwait_time64 || r!=-ENOSYS) + return r; + return __syscall_cp(SYS_rt_sigtimedwait, mask, si, + ts ? ((long[]){CLAMP(s), ns}) : 0, _NSIG/8);; +#else + return __syscall_cp(SYS_rt_sigtimedwait, mask, si, ts, _NSIG/8); +#endif +} + +int sigtimedwait(const sigset_t *restrict mask, siginfo_t *restrict si, const struct timespec *restrict timeout) +{ + int ret; + do ret = do_sigtimedwait(mask, si, timeout); + while (ret==-EINTR); + return __syscall_ret(ret); +} |