[PATCH v3] Define in_int32_t_range to check if the 64 bit time_t syscall should be used

Arnd Bergmann arnd@arndb.de
Tue Nov 8 10:39:26 GMT 2022


On Tue, Nov 8, 2022, at 05:49, YunQiang Su wrote:
> Currently glibc uses in_time_t_range to detects time_t overflow,
> and if it occurs fallbacks to 64 bit syscall version.
>
> The function name is confusing because internally time_t might be
> either 32 bits or 64 bits (depending on __TIMESIZE).
>
> This patch refactors the in_time_t_range by replacing it with
> in_int32_t_range for the case to check if the 64 bit time_t syscall
> should be used.
>
> The in_time_t range is used to detect overflow of the
> syscall return value.

It looks like the fallback logic has another flaw, I don't
see how this works on kernels with COMPAT_32BIT_TIME disabled,
as these only have the time64 syscalls available.

I think for the syscall wrappers implementing the time64
interfaces, there should not be any in_time_t_range()
check, but instead they can just call the time64 syscall
first and only fall back to the time32 version if that
fails with ENOSYS on pre-5.1 kernels. As a side-effect that
would also make it slightly faster on modern kernels
(skipping the pointless range check), at the cost of
being a bit slower on old kernels that require the fallback.

    Arnd


More information about the Libc-alpha mailing list