From patchwork Sun Apr 14 22:08:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Majewski X-Patchwork-Id: 32286 Received: (qmail 52459 invoked by alias); 14 Apr 2019 22:09:12 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 52345 invoked by uid 89); 14 Apr 2019 22:09:11 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-19.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 spammy= X-HELO: mail-out.m-online.net From: Lukasz Majewski To: libc-alpha@sourceware.org Cc: Paul Eggert , Joseph Myers , Lukasz Majewski Subject: [PATCH 5/6] y2038: linux: Provide __clock_gettime64 implementation Date: Mon, 15 Apr 2019 00:08:40 +0200 Message-Id: <20190414220841.20243-6-lukma@denx.de> In-Reply-To: <20190414220841.20243-1-lukma@denx.de> References: <20190414220841.20243-1-lukma@denx.de> This patch provides new __clock_gettime64 explicit 64 bit function for getting the value of specified clock ID. Moreover, a 32 bit version - __clock_gettime has been refactored to internally use __clock_gettime64. The __clock_gettime is now supposed to be used on 32 bit systems - hence the necessary checks and conversion to 64 bit type. After this change it is intrinsically Y2038 safe. The new 64 bit syscall (clock_gettime64) available from Linux 5.1+ has been used when applicable on 32 bit systems. The execution path on 64 bit systems has not been changed or affected in any way. Tests: - The code has been tested with x86_64/x86 (native compilation): make PARALLELMFLAGS="-j8" && make xcheck PARALLELMFLAGS="-j8" - 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 on kernels with and without 64 bit time support. No regressions were observed. * include/time.h (__clock_gettime64): Add __clock_gettime alias according to __TIMESIZE define * sysdeps/unix/sysv/linux/clock_gettime.c (__clock_gettime): Refactor this function to be used only on 32 bit machines as a wrapper on __clock_gettime64. * sysdeps/unix/sysv/linux/clock_gettime.c (__clock_gettime64): Add * sysdeps/unix/sysv/linux/clock_gettime.c (__clock_gettime64): Use clock_gettime64 kernel syscall (available from 5.1-rc1+ Linux) by 32 bit Y2038 safe systems --- include/time.h | 8 ++++++++ sysdeps/unix/sysv/linux/clock_gettime.c | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/include/time.h b/include/time.h index 20b9974078..7176ddbb84 100644 --- a/include/time.h +++ b/include/time.h @@ -133,6 +133,14 @@ libc_hidden_proto (__clock_settime64) #endif #if __TIMESIZE == 64 +# define __clock_gettime64 __clock_gettime +#else +extern int __clock_gettime64 (clockid_t clock_id, + struct __timespec64 *tp); +libc_hidden_proto (__clock_gettime64); +#endif + +#if __TIMESIZE == 64 # define __clock_getres64 __clock_getres #else extern int __clock_getres64 (clockid_t clock_id, diff --git a/sysdeps/unix/sysv/linux/clock_gettime.c b/sysdeps/unix/sysv/linux/clock_gettime.c index 5fc47fb7dc..fd94c6fec4 100644 --- a/sysdeps/unix/sysv/linux/clock_gettime.c +++ b/sysdeps/unix/sysv/linux/clock_gettime.c @@ -28,9 +28,40 @@ /* Get current value of CLOCK and store it in TP. */ int -__clock_gettime (clockid_t clock_id, struct timespec *tp) +__clock_gettime64 (clockid_t clock_id, struct __timespec64 *tp) { +#if defined (__TIMESIZE) && __TIMESIZE != 64 +# if defined __NR_clock_gettime64 + return INLINE_SYSCALL_CALL (clock_gettime64, clock_id, tp); +# else + struct timespec ts32; + int retval = INLINE_VSYSCALL (clock_gettime, 2, clock_id, &ts32); + if (! retval) + valid_timespec_to_timespec64(&ts32, tp); + + return retval; +# endif +#else return INLINE_VSYSCALL (clock_gettime, 2, clock_id, tp); +#endif } weak_alias (__clock_gettime, clock_gettime) libc_hidden_def (__clock_gettime) + +#if __TIMESIZE != 64 +int +__clock_gettime (clockid_t clock_id, struct timespec *tp) +{ + struct __timespec64 ts64; + int retval; + + retval = __clock_gettime64 (clock_id, &ts64); + if (! retval && ! timespec64_to_timespec (&ts64, tp)) + { + __set_errno (EOVERFLOW); + return -1; + } + + return retval; +} +#endif