On Wed, Oct 29, 2025, at 17:02, Thomas Weißschuh wrote:
> Make sure to always use the 64-bit safe system calls
> in preparation for 64-bit time_t on 32-bit architectures.
>
> Also prevent issues on kernels which disable CONFIG_COMPAT_32BIT_TIME
> and therefore don't provide the 32-bit system calls anymore.
>
> Signed-off-by: Thomas Weißschuh <[email protected]>

Thanks for working on this!

> -#if defined(__NR_ppoll)
> -     struct timespec t;
> +#if defined(__NR_ppoll_time64)
> +     struct __kernel_timespec t;
> 
>       if (timeout >= 0) {
>               t.tv_sec  = timeout / 1000;
>               t.tv_nsec = (timeout % 1000) * 1000000;
>       }
> -     return my_syscall5(__NR_ppoll, fds, nfds, (timeout >= 0) ? &t : NULL, 
> NULL, 0);
> +     return my_syscall5(__NR_ppoll_time64, fds, nfds, (timeout >= 0) ? &t 

This looks good to me.

> -#elif defined(__NR_ppoll_time64)
> -     struct __kernel_timespec t;
> : NULL, NULL, 0);
> +#elif defined(__NR_ppoll)
> +     struct timespec t;
> 
>       if (timeout >= 0) {
>               t.tv_sec  = timeout / 1000;
>               t.tv_nsec = (timeout % 1000) * 1000000;
>       }

This is not wrong, but for consistency, I would use
__kernel_old_timespec with the old syscall macros, rather
than the nolibc-defined type.

A different approach would be to rely on timespec/timeval/time_t
to always use the 64-bit types and then just pick the time64
macros on 32-bit vs the old macros on 64-bit builds.

> -     return my_syscall5(__NR_ppoll_time64, fds, nfds, (timeout >= 0) ? &t 
> : NULL, NULL, 0);
> +     return my_syscall5(__NR_ppoll, fds, nfds, (timeout >= 0) ? &t : NULL, 
> NULL, 0);
>  #else
>       return my_syscall3(__NR_poll, fds, nfds, timeout);
>  #endif

I would think that we can remove the final #else clause here
and just use the __NR_ppoll case as #else. It would also make
sense to change the first #if to check for a 32-bit ABI.

> diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h
> index e91b7d947161..10c517a38f86 100644
> --- a/tools/include/nolibc/sys.h
> +++ b/tools/include/nolibc/sys.h
> @@ -772,22 +772,22 @@ int sys_select(int nfds, fd_set *rfds, fd_set 
> *wfds, fd_set *efds, struct timeva
>       return my_syscall5(__NR__newselect, nfds, rfds, wfds, efds, timeout);
>  #elif defined(__NR_select)
>       return my_syscall5(__NR_select, nfds, rfds, wfds, efds, timeout);
> -#elif defined(__NR_pselect6)
> -     struct timespec t;
> +#elif defined(__NR_pselect6_time64)
> +     struct __kernel_timespec t;

These probably need to be flipped around, so that
__NR_pselect6_time64/__NR_pselect6 comes first because the other
ones use the wrong type on 32-bit targets.

Probably also do the same thing here with the #ifdef checking
the architecture instead of the syscall macro.

       Arnd

Reply via email to