diff options
author | Rich Felker <dalias@aerifal.cx> | 2019-07-28 17:05:47 -0400 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2019-07-28 17:09:57 -0400 |
commit | 68c983919ecfa75a8216d93b85baaefcb7b6e51c (patch) | |
tree | 0179eebc6fef5bf503a6ddb20b24adf992e7ca82 /src | |
parent | 2ab90de7ac53317a63d999b3e26d44d66684464c (diff) | |
download | musl-68c983919ecfa75a8216d93b85baaefcb7b6e51c.zip musl-68c983919ecfa75a8216d93b85baaefcb7b6e51c.tar.gz musl-68c983919ecfa75a8216d93b85baaefcb7b6e51c.tar.bz2 |
sigtimedwait: add time64 syscall support, decouple 32-bit time_t
time64 syscall is used only if it's the only one defined for the arch,
or if the requested timeout length does not fit in 32 bits. on current
32-bit archs where time_t is a 32-bit type, this makes it statically
unreachable.
on 64-bit archs, there are only superficial changes to the code after
preprocessing. on current 32-bit archs, the timeout is passed via an
intermediate copy to remove the assumption that time_t is a 32-bit
type.
Diffstat (limited to 'src')
-rw-r--r-- | src/signal/sigtimedwait.c | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/src/signal/sigtimedwait.c b/src/signal/sigtimedwait.c index 7bcfe72..1287174 100644 --- a/src/signal/sigtimedwait.c +++ b/src/signal/sigtimedwait.c @@ -2,11 +2,31 @@ #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 = syscall_cp(SYS_rt_sigtimedwait, mask, - si, timeout, _NSIG/8); - while (ret<0 && errno==EINTR); - return ret; + do ret = do_sigtimedwait(mask, si, timeout); + while (ret==-EINTR); + return __syscall_ret(ret); } |