[RFC PATCH 2/4] support: test futex_time64 syscall instead of time32 one

Adhemerval Zanella Netto adhemerval.zanella@linaro.org
Wed Nov 11 12:09:12 GMT 2026



On 10/11/26 11:51, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> 
> The old futex syscall is optional and can be disabled in the kernel
> for 32-bit ABIs to force the use of time64 syscalls, which breaks the
> support_mutex_pi_monotonic() detection: Even on __TIMESIZE=64 architectures
> that always use the time64 syscalls, it may report false when __NR_futex
> is defined but turned off.
> 
> Flip the detection and default to futex_time64 with a fallback to
> futex for architectures that only have futex (64-bit ones plus x32).
> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  support/support_mutex_pi_monotonic.c | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/support/support_mutex_pi_monotonic.c b/support/support_mutex_pi_monotonic.c
> index cbcbd05165d4..8efcd7bd62b9 100644
> --- a/support/support_mutex_pi_monotonic.c
> +++ b/support/support_mutex_pi_monotonic.c
> @@ -24,11 +24,16 @@ bool
>  support_mutex_pi_monotonic (void)
>  {
>  #ifdef __linux__
> -# ifndef __NR_futex
> -#  define __NR_futex __NR_futex_time64
> +  int r = 0;
> +# if defined(__ASSUME_TIME64_SYSCALLS) && defined(__NR_futex_time64)
> +  r = syscall (__NR_futex_time64, &(unsigned int){0}, 13 /* FUTEX_LOCK_PI2  */,
> +		   0, NULL);
>  # endif
> -  int r = syscall (__NR_futex, &(unsigned int){0}, 13 /* FUTEX_LOCK_PI2  */,
> +# ifdef __NR_futex
> +  if (r != 0)
> +    r = syscall (__NR_futex, &(unsigned int){0}, 13 /* FUTEX_LOCK_PI2  */,
>  		   0, NULL);
> +# endif
>    return r == 0;
>  #else
>    return false;

This breaks the probe on every ABI without __NR_futex_time64, where 'r'
stays 0, the 'if (r != 0)' skips the only syscall, and the function always
returns true. They would start failing on 64-bit hosts with kernels
older than 5.14, which lack FUTEX_LOCK_PI2.

There is also no need for __ASSUME_TIME64_SYSCALLS here.  FUTEX_LOCK_PI2
is newer (5.14) than futex_time64 (5.1), so on a 32-bit ABI any kernel
that can answer 'yes' has futex_time64.


More information about the Libc-alpha mailing list