From patchwork Sun Apr 14 22:08:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Majewski X-Patchwork-Id: 1085397 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-101370-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="Wd5dUX76"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44j5QK29sNz9s4V for ; Mon, 15 Apr 2019 08:09:29 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=dHIzI57RtAj9Z7hQ4JzLb5F+AZd0mRn IpGdaroaumqdy8Ltnkude2Qs/tv8HH6+qdKrqkU2UBLqOJoHDh2mcwVIAJnuBu6K RZZkUVPvk39L0BzfpwJGzK3ySqLPWoUzU+goJAbDaxQK2EQ1wzKjir+b1MYSa4G6 4APtmj68Z/lA= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references; s=default; bh=naexYpow0bzdj+KWQKACORQEHs0=; b=Wd5dU X76vvabG92l2Hcnt268wcVXSjCIGhK09IhHdywGsqm2PPrMkbcoWt4ICeucS/r/f j5X0nJ/jUQDaSkZ5uJsVUdIU/Qd/of9g52JcQ8xGh/3pXxKOMFDssO0H/62mkvAY pVkMiiVKmrG5hPRW/m0M+s7l6wNLl+wqCVRv8g= Received: (qmail 51880 invoked by alias); 14 Apr 2019 22:09:09 -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 51792 invoked by uid 89); 14 Apr 2019 22:09:09 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.9 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=moreover, refactor, east, 1911 X-HELO: mail-out.m-online.net From: Lukasz Majewski To: libc-alpha@sourceware.org Cc: Paul Eggert , Joseph Myers , Lukasz Majewski Subject: [PATCH 3/6] y2038: linux: Provide __clock_settime64 implementation Date: Mon, 15 Apr 2019 00:08:38 +0200 Message-Id: <20190414220841.20243-4-lukma@denx.de> In-Reply-To: <20190414220841.20243-1-lukma@denx.de> References: <20190414220841.20243-1-lukma@denx.de> This patch provides new __clock_settime64 explicit 64 bit function for setting the time. Moreover, a 32 bit version - __clock_settime has been refactored to internally use __clock_settime64. The __clock_settime 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_settime64) 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_settime64): Add __clock_settime alias according to __TIMESIZE define * sysdeps/unix/sysv/linux/clock_settime.c (__clock_settime): Refactor this function to be used only on 32 bit machines as a wrapper on __clock_settime64. * sysdeps/unix/sysv/linux/clock_settime.c (__clock_settime64): Add * sysdeps/unix/sysv/linux/clock_settime.c (__clock_settime64): Use clock_settime64 kernel syscall (available from 5.1-rc1+ Linux) by 32 bit Y2038 safe systems --- include/time.h | 8 ++++++++ sysdeps/unix/sysv/linux/clock_settime.c | 34 ++++++++++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/include/time.h b/include/time.h index 9eed500cf1..33eee8eb9a 100644 --- a/include/time.h +++ b/include/time.h @@ -124,6 +124,14 @@ extern __time64_t __timegm64 (struct tm *__tp) __THROW; libc_hidden_proto (__timegm64) #endif +#if __TIMESIZE == 64 +# define __clock_settime64 __clock_settime +#else +extern int __clock_settime64 (clockid_t clock_id, + const struct __timespec64 *tp); +libc_hidden_proto (__clock_settime64) +#endif + /* Compute the `struct tm' representation of T, offset OFFSET seconds east of UTC, and store year, yday, mon, mday, wday, hour, min, sec into *TP. diff --git a/sysdeps/unix/sysv/linux/clock_settime.c b/sysdeps/unix/sysv/linux/clock_settime.c index d837e3019c..a1ea1cac28 100644 --- a/sysdeps/unix/sysv/linux/clock_settime.c +++ b/sysdeps/unix/sysv/linux/clock_settime.c @@ -19,11 +19,9 @@ #include #include -#include "kernel-posix-cpu-timers.h" - /* Set CLOCK to value TP. */ int -__clock_settime (clockid_t clock_id, const struct timespec *tp) +__clock_settime64 (clockid_t clock_id, const struct __timespec64 *tp) { /* Make sure the time cvalue is OK. */ if (tp->tv_nsec < 0 || tp->tv_nsec >= 1000000000) @@ -32,6 +30,36 @@ __clock_settime (clockid_t clock_id, const struct timespec *tp) return -1; } +#if defined (__TIMESIZE) && __TIMESIZE != 64 +# if defined __NR_clock_settime64 + /* Make sure that passed __timespec64 struct pad is 0. */ + struct __timespec64 ts = *tp; + ts.tv_pad = 0; + return INLINE_SYSCALL_CALL (clock_settime64, clock_id, &ts); +# else + struct timespec ts32; + valid_timespec64_to_timespec(tp, &ts32); + return INLINE_SYSCALL_CALL (clock_settime, clock_id, &ts32); +# endif +#else return INLINE_SYSCALL_CALL (clock_settime, clock_id, tp); +#endif } weak_alias (__clock_settime, clock_settime) + +#if __TIMESIZE != 64 +int +__clock_settime (clockid_t clock_id, const struct timespec *tp) +{ + struct __timespec64 ts64; + + if (! in_time_t_range (tp->tv_sec)) + { + __set_errno (EOVERFLOW); + return -1; + } + + valid_timespec_to_timespec64 (tp, &ts64); + return __clock_settime64 (clock_id, &ts64); +} +#endif