From patchwork Wed Mar 27 08:52:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Majewski X-Patchwork-Id: 32004 Received: (qmail 17222 invoked by alias); 27 Mar 2019 08:52:43 -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 17124 invoked by uid 89); 27 Mar 2019 08:52:43 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-19.5 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, Joseph Myers Cc: Paul Eggert , Zack Weinberg , Lukasz Majewski Subject: [RFC 7/7] y2038: Introduce support for clock_settime() being Y2038 safe Date: Wed, 27 Mar 2019 09:52:10 +0100 Message-Id: <20190327085210.22019-8-lukma@denx.de> In-Reply-To: <20190327085210.22019-1-lukma@denx.de> References: <20190327085210.22019-1-lukma@denx.de> This patch introduces the Y2038 specific code to make clock_settime()/ __clock_settime64() Y2038 safe on 32 bit systems. * include/time.h: Remove libc_hidden_proto (__clock_settime64) - make the __clock_settime64 publicly available for Y2038 safe system * sysdeps/unix/sysv/linux/clock_settime.c: Use clock_settime64 kernel syscall (available from 5.1-rc1+ Linux) by 32 bit Y2038 safe systems * time/time.h: Redirect clock_settime call to __clock_settime64 on 32 bit Y2038 safe systems --- include/time.h | 4 +++- sysdeps/unix/sysv/linux/clock_settime.c | 11 +++++++++++ time/time.h | 9 +++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/include/time.h b/include/time.h index c8c0a6936e..25ddb70377 100644 --- a/include/time.h +++ b/include/time.h @@ -107,7 +107,9 @@ libc_hidden_proto (__timegm64) #else extern int __clock_settime64 (clockid_t clock_id, const struct __timespec64 *tp); -libc_hidden_proto (__clock_settime64) +/* For Y2038 safe system the __clock_settime64 needs to be a visible + symbol as a replacement for Y2038 unsafe clock_settime() +*/ #endif /* Compute the `struct tm' representation of T, diff --git a/sysdeps/unix/sysv/linux/clock_settime.c b/sysdeps/unix/sysv/linux/clock_settime.c index 5b7ab7fcb3..3fcce623c9 100644 --- a/sysdeps/unix/sysv/linux/clock_settime.c +++ b/sysdeps/unix/sysv/linux/clock_settime.c @@ -29,6 +29,17 @@ __clock_settime64 (clockid_t clock_id, const struct __timespec64 *tp) return -1; } +/* For being Y2038 safe we check if __TIMESIZE != 64 and run the + 64 bit syscall only when supported by the kernel. + As __clock_settime64() may be also called by 32 bit machine (not Y2038 + safe) - in case of error - the default kernel syscall (clock_settime) + is executed */ +#if defined __NR_clock_settime64 && defined __TIMESIZE != 64 + int retval = INLINE_SYSCALL_CALL (clock_settime64, clock_id, tp); + if (! retval) + return retval; +#endif + return INLINE_SYSCALL_CALL (clock_settime, clock_id, tp); } diff --git a/time/time.h b/time/time.h index cba6d15260..c9c8aeccfa 100644 --- a/time/time.h +++ b/time/time.h @@ -222,6 +222,15 @@ extern int clock_gettime (clockid_t __clock_id, struct timespec *__tp) __THROW; extern int clock_settime (clockid_t __clock_id, const struct timespec *__tp) __THROW; +#ifdef __USE_TIME_BITS64 +# if defined(__REDIRECT) +extern int __REDIRECT (clock_settime, (clockid_t __clock_id, const struct + timespec *__tp), __clock_settime64) __THROW; +# else +# define clock_settime __clock_settime64 +# endif +#endif + # ifdef __USE_XOPEN2K /* High-resolution sleep with the specified clock.