From patchwork Fri May 8 14:56:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Majewski X-Patchwork-Id: 38940 X-Patchwork-Delegate: l.majewski@majess.pl Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 32F85397280A; Fri, 8 May 2020 14:57:13 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-out.m-online.net (mail-out.m-online.net [IPv6:2001:a60:0:28:0:1:25:1]) by sourceware.org (Postfix) with ESMTPS id 660B53851C1C for ; Fri, 8 May 2020 14:57:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 660B53851C1C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: sourceware.org; spf=none smtp.mailfrom=lukma@denx.de Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 49JYMT49W1z1rt4X; Fri, 8 May 2020 16:57:09 +0200 (CEST) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 49JYMT3R8Qz1r79j; Fri, 8 May 2020 16:57:09 +0200 (CEST) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id kh7lADTDGSIp; Fri, 8 May 2020 16:57:07 +0200 (CEST) X-Auth-Info: UJkdod8CUVf+SbeCjzwcfY5IwxVJjoj3W23V1XXOTJI= Received: from localhost.localdomain (85-222-111-42.dynamic.chello.pl [85.222.111.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPSA; Fri, 8 May 2020 16:57:07 +0200 (CEST) From: Lukasz Majewski To: Joseph Myers , Adhemerval Zanella Subject: [PATCH v2 6/7] y2038: linux: Provide __ntp_gettime64 implementation Date: Fri, 8 May 2020 16:56:39 +0200 Message-Id: <20200508145640.16336-7-lukma@denx.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200508145640.16336-1-lukma@denx.de> References: <20200508145640.16336-1-lukma@denx.de> MIME-Version: 1.0 X-Spam-Status: No, score=-22.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Florian Weimer , GNU C Library , Andreas Schwab , Alistair Francis Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" This patch provides new __ntp_gettime64 explicit 64 bit function for getting time parameters via NTP interface. Internally, the __clock_adjtime64 syscall is used instead of __adjtimex. This patch is necessary for having architectures with __WORDSIZE == 32 Y2038 safe. Moreover, a 32 bit version - __ntp_gettime has been refactored to internally use __ntp_gettime64. The __ntp_gettime is now supposed to be used on systems still supporting 32 bit time (__TIMESIZE != 64) - hence the necessary conversions between struct ntptimeval and 64 bit struct __ntptimeval64. Build tests: ./src/scripts/build-many-glibcs.py glibcs Run-time tests: - 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 Above tests were performed with Y2038 redirection applied as well as without to test the proper usage of both __ntp_gettime64 and __ntp_gettime. Reviewed-by: Adhemerval Zanella --- sysdeps/unix/sysv/linux/include/sys/timex.h | 4 ++++ sysdeps/unix/sysv/linux/ntp_gettime.c | 24 ++++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/sysdeps/unix/sysv/linux/include/sys/timex.h b/sysdeps/unix/sysv/linux/include/sys/timex.h index e762e03230..ef53515803 100644 --- a/sysdeps/unix/sysv/linux/include/sys/timex.h +++ b/sysdeps/unix/sysv/linux/include/sys/timex.h @@ -33,6 +33,7 @@ libc_hidden_proto (__adjtimex) # define __clock_adjtime64 __clock_adjtime # define ___adjtimex64 ___adjtimex # define __ntptimeval64 ntptimeval +# define __ntp_gettime64 __ntp_gettime # else struct __timex64 @@ -91,6 +92,9 @@ struct __ntptimeval64 long int __glibc_reserved3; long int __glibc_reserved4; }; +extern int __ntp_gettime64 (struct __ntptimeval64 *ntv); +libc_hidden_proto (__ntp_gettime64) + # endif /* Convert a known valid struct timex into a struct __timex64. */ diff --git a/sysdeps/unix/sysv/linux/ntp_gettime.c b/sysdeps/unix/sysv/linux/ntp_gettime.c index c8d6a197dc..21aeffadeb 100644 --- a/sysdeps/unix/sysv/linux/ntp_gettime.c +++ b/sysdeps/unix/sysv/linux/ntp_gettime.c @@ -17,6 +17,7 @@ #define ntp_gettime ntp_gettime_redirect +#include #include #undef ntp_gettime @@ -27,15 +28,32 @@ int -ntp_gettime (struct ntptimeval *ntv) +__ntp_gettime64 (struct __ntptimeval64 *ntv) { - struct timex tntx; + struct __timex64 tntx; int result; tntx.modes = 0; - result = __adjtimex (&tntx); + result = __clock_adjtime64 (CLOCK_REALTIME, &tntx); ntv->time = tntx.time; ntv->maxerror = tntx.maxerror; ntv->esterror = tntx.esterror; return result; } + +#if __TIMESIZE != 64 +libc_hidden_def (__ntp_gettime64) + +int +__ntp_gettime (struct ntptimeval *ntv) +{ + struct __ntptimeval64 ntv64; + int result; + + result = __ntp_gettime64 (&ntv64); + *ntv = valid_ntptimeval64_to_ntptimeval (ntv64); + + return result; +} +#endif +strong_alias (__ntp_gettime, ntp_gettime)