From 4a14cb87cad30bb15bb906e579089109874f3071 Mon Sep 17 00:00:00 2001 From: Lukasz Majewski Date: Mon, 20 Jul 2020 15:50:12 +0200 Subject: y2038: nptl: Convert pthread_{clock|timed}join_np to support 64 bit time The pthread_clockjoin_np and pthread_timedjoin_np have been converted to support 64 bit time. This change introduces new futex_timed_wait_cancel64 function in ./sysdeps/nptl/futex-internal.h, which uses futex_time64 where possible and tries to replace low-level preprocessor macros from lowlevellock-futex.h The pthread_{timed|clock}join_np only accept absolute time. Moreover, there is no need to check for NULL passed as *abstime pointer as clockwait_tid() always passes struct __timespec64. For systems with __TIMESIZE != 64 && __WORDSIZE == 32: - Conversions between 64 bit time to 32 bit are necessary - Redirection to __pthread_{clock|timed}join_np64 will provide support for 64 bit time Build tests: ./src/scripts/build-many-glibcs.py glibcs Run-time tests: - Run specific tests on ARM/x86 32bit systems (qemu): https://github.com/lmajewski/meta-y2038 and run tests: https://github.com/lmajewski/y2038-tests/commits/master Above tests were performed with Y2038 redirection applied as well as without to test the proper usage of both __pthread_{timed|clock}join_np64 and __pthread_{timed|clock}join_np. Reviewed-by: Adhemerval Zanella Reviewed-by: Alistair Francis --- sysdeps/nptl/futex-internal.h | 52 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'sysdeps/nptl/futex-internal.h') diff --git a/sysdeps/nptl/futex-internal.h b/sysdeps/nptl/futex-internal.h index d622122ddc..159aae82dc 100644 --- a/sysdeps/nptl/futex-internal.h +++ b/sysdeps/nptl/futex-internal.h @@ -467,4 +467,56 @@ futex_unlock_pi (unsigned int *futex_word, int private) } } +#ifndef __NR_futex_time64 +# define __NR_futex_time64 __NR_futex +#endif + +static __always_inline int +futex_timed_wait_cancel64 (pid_t *tidp, pid_t tid, + const struct __timespec64 *timeout, int private) +{ + int err = INTERNAL_SYSCALL_CANCEL (futex_time64, tidp, + __lll_private_flag + (FUTEX_WAIT, private), tid, timeout); +#ifndef __ASSUME_TIME64_SYSCALLS + if (err == -ENOSYS) + { + if (in_time_t_range (timeout->tv_sec)) + { + struct timespec ts32 = valid_timespec64_to_timespec (*timeout); + + err = INTERNAL_SYSCALL_CANCEL (futex, tidp, + __lll_private_flag (FUTEX_WAIT, + private), + tid, &ts32); + } + else + err = -EOVERFLOW; + } +#endif + switch (err) + { + case 0: + case -EAGAIN: + case -EINTR: + case -ETIMEDOUT: + case -EDEADLK: + case -ENOSYS: + case -EOVERFLOW: /* Passed absolute timeout uses 64 bit time_t type, but + underlying kernel does not support 64 bit time_t futex + syscalls. */ + case -EPERM: /* The caller is not allowed to attach itself to the futex. + Used to check if PI futexes are supported by the + kernel. */ + return -err; + + case -EINVAL: /* Either due to wrong alignment or due to the timeout not + being normalized. Must have been caused by a glibc or + application bug. */ + case -EFAULT: /* Must have been caused by a glibc or application bug. */ + /* No other errors are documented at this time. */ + default: + futex_fatal_error (); + } +} #endif /* futex-internal.h */ -- cgit 1.4.1