diff options
author | Adhemerval Zanella <adhemerval.zanella@linaro.org> | 2021-06-16 09:58:29 -0300 |
---|---|---|
committer | Adhemerval Zanella <adhemerval.zanella@linaro.org> | 2021-06-22 12:09:52 -0300 |
commit | dafab287b4d5dea1918f6471dc8bf74bff029133 (patch) | |
tree | eacd79430abf83bd758d75f3712b0602d2766460 /sysdeps/unix/sysv/linux/sigtimedwait.c | |
parent | 1faff2701163c76bad9bce76d644d13bce3e290a (diff) | |
download | glibc-dafab287b4d5dea1918f6471dc8bf74bff029133.zip glibc-dafab287b4d5dea1918f6471dc8bf74bff029133.tar.gz glibc-dafab287b4d5dea1918f6471dc8bf74bff029133.tar.bz2 |
linux: Only use 64-bit syscall if required for sigtimedwait
For !__ASSUME_TIME64_SYSCALLS there is no need to issue a 64-bit syscall
if the provided timeout fits in a 32-bit one. The 64-bit usage should
be rare since the timeout is a relative one.
Checked on i686-linux-gnu on a 4.15 kernel and on a 5.11 kernel
(with and without --enable-kernel=5.1) and on x86_64-linux-gnu.
Reviewed-by: Lukasz Majewski <lukma@denx.de>
Diffstat (limited to 'sysdeps/unix/sysv/linux/sigtimedwait.c')
-rw-r--r-- | sysdeps/unix/sysv/linux/sigtimedwait.c | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/sysdeps/unix/sysv/linux/sigtimedwait.c b/sysdeps/unix/sysv/linux/sigtimedwait.c index 25ed0ad..607381a 100644 --- a/sysdeps/unix/sysv/linux/sigtimedwait.c +++ b/sysdeps/unix/sysv/linux/sigtimedwait.c @@ -25,20 +25,27 @@ __sigtimedwait64 (const sigset_t *set, siginfo_t *info, #ifndef __NR_rt_sigtimedwait_time64 # define __NR_rt_sigtimedwait_time64 __NR_rt_sigtimedwait #endif - int result = SYSCALL_CANCEL (rt_sigtimedwait_time64, set, info, timeout, - __NSIG_BYTES); -#ifndef __ASSUME_TIME64_SYSCALLS - if (result != 0 && errno == ENOSYS) + int result; +#ifdef __ASSUME_TIME64_SYSCALLS + result = SYSCALL_CANCEL (rt_sigtimedwait_time64, set, info, timeout, + __NSIG_BYTES); +#else + bool need_time64 = timeout != NULL && !in_time_t_range (timeout->tv_sec); + if (need_time64) + { + result = SYSCALL_CANCEL (rt_sigtimedwait_time64, set, info, timeout, + __NSIG_BYTES); + if (result == 0 || errno != ENOSYS) + return result; + __set_errno (EOVERFLOW); + return -1; + } + else { struct timespec ts32, *pts32 = NULL; if (timeout != NULL) { - if (! in_time_t_range (timeout->tv_sec)) - { - __set_errno (EINVAL); - return -1; - } ts32 = valid_timespec64_to_timespec (*timeout); pts32 = &ts32; } |