mirror of
https://sourceware.org/git/glibc.git
synced 2025-08-01 10:06:57 +03:00
Define in_int32_t_range to check if the 64 bit time_t syscall should be used
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. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
This commit is contained in:
committed by
Adhemerval Zanella
parent
94628de778
commit
a9acb7b39e
@ -347,12 +347,20 @@ libc_hidden_proto (__time64)
|
|||||||
/* Check whether T fits in int32_t, assume all usages are for
|
/* Check whether T fits in int32_t, assume all usages are for
|
||||||
sizeof(time_t) == 32. */
|
sizeof(time_t) == 32. */
|
||||||
static inline bool
|
static inline bool
|
||||||
in_time_t_range (__time64_t t)
|
in_int32_t_range (__time64_t t)
|
||||||
{
|
{
|
||||||
int32_t s = t;
|
int32_t s = t;
|
||||||
return s == t;
|
return s == t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Check whether T fits in time_t. */
|
||||||
|
static inline bool
|
||||||
|
in_time_t_range (__time64_t t)
|
||||||
|
{
|
||||||
|
time_t s = t;
|
||||||
|
return s == t;
|
||||||
|
}
|
||||||
|
|
||||||
/* Convert a known valid struct timeval into a struct __timespec64. */
|
/* Convert a known valid struct timeval into a struct __timespec64. */
|
||||||
static inline struct __timespec64
|
static inline struct __timespec64
|
||||||
valid_timeval_to_timespec64 (const struct timeval tv)
|
valid_timeval_to_timespec64 (const struct timeval tv)
|
||||||
|
@ -87,7 +87,7 @@ __futex_abstimed_wait_common (unsigned int* futex_word,
|
|||||||
err = __futex_abstimed_wait_common64 (futex_word, expected, op, abstime,
|
err = __futex_abstimed_wait_common64 (futex_word, expected, op, abstime,
|
||||||
private, cancel);
|
private, cancel);
|
||||||
#else
|
#else
|
||||||
bool need_time64 = abstime != NULL && !in_time_t_range (abstime->tv_sec);
|
bool need_time64 = abstime != NULL && !in_int32_t_range (abstime->tv_sec);
|
||||||
if (need_time64)
|
if (need_time64)
|
||||||
{
|
{
|
||||||
err = __futex_abstimed_wait_common64 (futex_word, expected, op, abstime,
|
err = __futex_abstimed_wait_common64 (futex_word, expected, op, abstime,
|
||||||
@ -162,7 +162,7 @@ __futex_lock_pi64 (int *futex_word, clockid_t clockid,
|
|||||||
# ifdef __ASSUME_TIME64_SYSCALLS
|
# ifdef __ASSUME_TIME64_SYSCALLS
|
||||||
err = INTERNAL_SYSCALL_CALL (futex_time64, futex_word, op_pi, 0, abstime);
|
err = INTERNAL_SYSCALL_CALL (futex_time64, futex_word, op_pi, 0, abstime);
|
||||||
# else
|
# else
|
||||||
bool need_time64 = abstime != NULL && !in_time_t_range (abstime->tv_sec);
|
bool need_time64 = abstime != NULL && !in_int32_t_range (abstime->tv_sec);
|
||||||
if (need_time64)
|
if (need_time64)
|
||||||
err = INTERNAL_SYSCALL_CALL (futex_time64, futex_word, op_pi, 0, abstime);
|
err = INTERNAL_SYSCALL_CALL (futex_time64, futex_word, op_pi, 0, abstime);
|
||||||
else
|
else
|
||||||
|
@ -35,7 +35,7 @@ __clock_adjtime64 (const clockid_t clock_id, struct __timex64 *tx64)
|
|||||||
return r;
|
return r;
|
||||||
|
|
||||||
if (tx64->modes & ADJ_SETOFFSET
|
if (tx64->modes & ADJ_SETOFFSET
|
||||||
&& ! in_time_t_range (tx64->time.tv_sec))
|
&& ! in_int32_t_range (tx64->time.tv_sec))
|
||||||
{
|
{
|
||||||
__set_errno (EOVERFLOW);
|
__set_errno (EOVERFLOW);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -48,7 +48,7 @@ __clock_nanosleep_time64 (clockid_t clock_id, int flags,
|
|||||||
r = INTERNAL_SYSCALL_CANCEL (clock_nanosleep_time64, clock_id, flags, req,
|
r = INTERNAL_SYSCALL_CANCEL (clock_nanosleep_time64, clock_id, flags, req,
|
||||||
rem);
|
rem);
|
||||||
#else
|
#else
|
||||||
if (!in_time_t_range (req->tv_sec))
|
if (!in_int32_t_range (req->tv_sec))
|
||||||
{
|
{
|
||||||
r = INTERNAL_SYSCALL_CANCEL (clock_nanosleep_time64, clock_id, flags,
|
r = INTERNAL_SYSCALL_CANCEL (clock_nanosleep_time64, clock_id, flags,
|
||||||
req, rem);
|
req, rem);
|
||||||
|
@ -41,7 +41,7 @@ __clock_settime64 (clockid_t clock_id, const struct __timespec64 *tp)
|
|||||||
if (ret == 0 || errno != ENOSYS)
|
if (ret == 0 || errno != ENOSYS)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
if (! in_time_t_range (tp->tv_sec))
|
if (! in_int32_t_range (tp->tv_sec))
|
||||||
{
|
{
|
||||||
__set_errno (EOVERFLOW);
|
__set_errno (EOVERFLOW);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -36,7 +36,7 @@ ___mq_timedreceive_time64 (mqd_t mqdes, char *__restrict msg_ptr, size_t msg_len
|
|||||||
msg_prio, abs_timeout);
|
msg_prio, abs_timeout);
|
||||||
#else
|
#else
|
||||||
bool need_time64 = abs_timeout != NULL
|
bool need_time64 = abs_timeout != NULL
|
||||||
&& !in_time_t_range (abs_timeout->tv_sec);
|
&& !in_int32_t_range (abs_timeout->tv_sec);
|
||||||
if (need_time64)
|
if (need_time64)
|
||||||
{
|
{
|
||||||
int r = SYSCALL_CANCEL (mq_timedreceive_time64, mqdes, msg_ptr, msg_len,
|
int r = SYSCALL_CANCEL (mq_timedreceive_time64, mqdes, msg_ptr, msg_len,
|
||||||
|
@ -36,7 +36,7 @@ ___mq_timedsend_time64 (mqd_t mqdes, const char *msg_ptr, size_t msg_len,
|
|||||||
msg_prio, abs_timeout);
|
msg_prio, abs_timeout);
|
||||||
#else
|
#else
|
||||||
bool need_time64 = abs_timeout != NULL
|
bool need_time64 = abs_timeout != NULL
|
||||||
&& !in_time_t_range (abs_timeout->tv_sec);
|
&& !in_int32_t_range (abs_timeout->tv_sec);
|
||||||
if (need_time64)
|
if (need_time64)
|
||||||
{
|
{
|
||||||
int r = SYSCALL_CANCEL (mq_timedsend_time64, mqdes, msg_ptr, msg_len,
|
int r = SYSCALL_CANCEL (mq_timedsend_time64, mqdes, msg_ptr, msg_len,
|
||||||
|
@ -43,7 +43,7 @@ __ppoll64 (struct pollfd *fds, nfds_t nfds, const struct __timespec64 *timeout,
|
|||||||
__NSIG_BYTES);
|
__NSIG_BYTES);
|
||||||
#else
|
#else
|
||||||
int ret;
|
int ret;
|
||||||
bool need_time64 = timeout != NULL && !in_time_t_range (timeout->tv_sec);
|
bool need_time64 = timeout != NULL && !in_int32_t_range (timeout->tv_sec);
|
||||||
if (need_time64)
|
if (need_time64)
|
||||||
{
|
{
|
||||||
ret = SYSCALL_CANCEL (ppoll_time64, fds, nfds, timeout, sigmask,
|
ret = SYSCALL_CANCEL (ppoll_time64, fds, nfds, timeout, sigmask,
|
||||||
|
@ -56,7 +56,7 @@ __pselect64 (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
|
|||||||
return pselect64_syscall (nfds, readfds, writefds, exceptfds, timeout,
|
return pselect64_syscall (nfds, readfds, writefds, exceptfds, timeout,
|
||||||
sigmask);
|
sigmask);
|
||||||
#else
|
#else
|
||||||
bool need_time64 = timeout != NULL && !in_time_t_range (timeout->tv_sec);
|
bool need_time64 = timeout != NULL && !in_int32_t_range (timeout->tv_sec);
|
||||||
if (need_time64)
|
if (need_time64)
|
||||||
{
|
{
|
||||||
int r = pselect64_syscall (nfds, readfds, writefds, exceptfds, timeout,
|
int r = pselect64_syscall (nfds, readfds, writefds, exceptfds, timeout,
|
||||||
|
@ -35,7 +35,7 @@ recvmmsg_syscall (int fd, struct mmsghdr *vmessages, unsigned int vlen,
|
|||||||
struct timespec ts32, *pts32 = NULL;
|
struct timespec ts32, *pts32 = NULL;
|
||||||
if (timeout != NULL)
|
if (timeout != NULL)
|
||||||
{
|
{
|
||||||
if (! in_time_t_range (timeout->tv_sec))
|
if (! in_int32_t_range (timeout->tv_sec))
|
||||||
{
|
{
|
||||||
__set_errno (EINVAL);
|
__set_errno (EINVAL);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -72,7 +72,7 @@ __select64 (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
|
|||||||
TIMESPEC_TO_TIMEVAL (timeout, pts64);
|
TIMESPEC_TO_TIMEVAL (timeout, pts64);
|
||||||
return r;
|
return r;
|
||||||
#else
|
#else
|
||||||
bool need_time64 = timeout != NULL && !in_time_t_range (timeout->tv_sec);
|
bool need_time64 = timeout != NULL && !in_int32_t_range (timeout->tv_sec);
|
||||||
if (need_time64)
|
if (need_time64)
|
||||||
{
|
{
|
||||||
int r = SYSCALL_CANCEL (pselect6_time64, nfds, readfds, writefds,
|
int r = SYSCALL_CANCEL (pselect6_time64, nfds, readfds, writefds,
|
||||||
|
@ -42,7 +42,7 @@ __semtimedop64 (int semid, struct sembuf *sops, size_t nsops,
|
|||||||
#ifdef __ASSUME_TIME64_SYSCALLS
|
#ifdef __ASSUME_TIME64_SYSCALLS
|
||||||
return semtimedop_syscall (semid, sops, nsops, timeout);
|
return semtimedop_syscall (semid, sops, nsops, timeout);
|
||||||
#else
|
#else
|
||||||
bool need_time64 = timeout != NULL && !in_time_t_range (timeout->tv_sec);
|
bool need_time64 = timeout != NULL && !in_int32_t_range (timeout->tv_sec);
|
||||||
if (need_time64)
|
if (need_time64)
|
||||||
{
|
{
|
||||||
int r = semtimedop_syscall (semid, sops, nsops, timeout);
|
int r = semtimedop_syscall (semid, sops, nsops, timeout);
|
||||||
|
@ -32,8 +32,8 @@ __setitimer64 (__itimer_which_t which,
|
|||||||
#else
|
#else
|
||||||
struct __itimerval32 new_value_32;
|
struct __itimerval32 new_value_32;
|
||||||
|
|
||||||
if (! in_time_t_range (new_value->it_interval.tv_sec)
|
if (! in_int32_t_range (new_value->it_interval.tv_sec)
|
||||||
|| ! in_time_t_range (new_value->it_value.tv_sec))
|
|| ! in_int32_t_range (new_value->it_value.tv_sec))
|
||||||
{
|
{
|
||||||
__set_errno (EOVERFLOW);
|
__set_errno (EOVERFLOW);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -54,7 +54,7 @@ setsockopt32 (int fd, int level, int optname, const void *optval,
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct __timeval64 *tv64 = (struct __timeval64 *) optval;
|
struct __timeval64 *tv64 = (struct __timeval64 *) optval;
|
||||||
if (! in_time_t_range (tv64->tv_sec))
|
if (! in_int32_t_range (tv64->tv_sec))
|
||||||
{
|
{
|
||||||
__set_errno (EOVERFLOW);
|
__set_errno (EOVERFLOW);
|
||||||
break;
|
break;
|
||||||
|
@ -31,7 +31,7 @@ __sigtimedwait64 (const sigset_t *set, siginfo_t *info,
|
|||||||
result = SYSCALL_CANCEL (rt_sigtimedwait_time64, set, info, timeout,
|
result = SYSCALL_CANCEL (rt_sigtimedwait_time64, set, info, timeout,
|
||||||
__NSIG_BYTES);
|
__NSIG_BYTES);
|
||||||
#else
|
#else
|
||||||
bool need_time64 = timeout != NULL && !in_time_t_range (timeout->tv_sec);
|
bool need_time64 = timeout != NULL && !in_int32_t_range (timeout->tv_sec);
|
||||||
if (need_time64)
|
if (need_time64)
|
||||||
{
|
{
|
||||||
result = SYSCALL_CANCEL (rt_sigtimedwait_time64, set, info, timeout,
|
result = SYSCALL_CANCEL (rt_sigtimedwait_time64, set, info, timeout,
|
||||||
|
@ -46,8 +46,8 @@ ___timer_settime64 (timer_t timerid, int flags,
|
|||||||
# endif
|
# endif
|
||||||
struct itimerspec its32, oits32;
|
struct itimerspec its32, oits32;
|
||||||
|
|
||||||
if (! in_time_t_range ((value->it_value).tv_sec)
|
if (! in_int32_t_range ((value->it_value).tv_sec)
|
||||||
|| ! in_time_t_range ((value->it_interval).tv_sec))
|
|| ! in_int32_t_range ((value->it_interval).tv_sec))
|
||||||
{
|
{
|
||||||
__set_errno (EOVERFLOW);
|
__set_errno (EOVERFLOW);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -33,8 +33,8 @@ __timerfd_settime64 (int fd, int flags, const struct __itimerspec64 *value,
|
|||||||
#ifdef __ASSUME_TIME64_SYSCALLS
|
#ifdef __ASSUME_TIME64_SYSCALLS
|
||||||
return INLINE_SYSCALL_CALL (timerfd_settime64, fd, flags, value, ovalue);
|
return INLINE_SYSCALL_CALL (timerfd_settime64, fd, flags, value, ovalue);
|
||||||
#else
|
#else
|
||||||
bool need_time64 = !in_time_t_range (value->it_value.tv_sec)
|
bool need_time64 = !in_int32_t_range (value->it_value.tv_sec)
|
||||||
|| !in_time_t_range (value->it_interval.tv_sec);
|
|| !in_int32_t_range (value->it_interval.tv_sec);
|
||||||
if (need_time64)
|
if (need_time64)
|
||||||
{
|
{
|
||||||
int r = INLINE_SYSCALL_CALL (timerfd_settime64, fd, flags, value,
|
int r = INLINE_SYSCALL_CALL (timerfd_settime64, fd, flags, value,
|
||||||
|
@ -41,9 +41,9 @@ __utimensat64_helper (int fd, const char *file,
|
|||||||
|
|
||||||
bool need_time64 = tsp64 != NULL
|
bool need_time64 = tsp64 != NULL
|
||||||
&& ((!TS_SPECIAL (tsp64[0])
|
&& ((!TS_SPECIAL (tsp64[0])
|
||||||
&& !in_time_t_range (tsp64[0].tv_sec))
|
&& !in_int32_t_range (tsp64[0].tv_sec))
|
||||||
|| (!TS_SPECIAL (tsp64[1])
|
|| (!TS_SPECIAL (tsp64[1])
|
||||||
&& !in_time_t_range (tsp64[1].tv_sec)));
|
&& !in_int32_t_range (tsp64[1].tv_sec)));
|
||||||
if (need_time64)
|
if (need_time64)
|
||||||
{
|
{
|
||||||
int r = INLINE_SYSCALL_CALL (utimensat_time64, fd, file, &tsp64[0],
|
int r = INLINE_SYSCALL_CALL (utimensat_time64, fd, file, &tsp64[0],
|
||||||
|
Reference in New Issue
Block a user