From patchwork Mon Sep 7 21:41:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Majewski X-Patchwork-Id: 40366 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 797F9386F039; Mon, 7 Sep 2020 21:41:51 +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 6BBC43861035 for ; Mon, 7 Sep 2020 21:41:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 6BBC43861035 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 4BlhZ03W1Hz1rsMj; Mon, 7 Sep 2020 23:41:44 +0200 (CEST) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 4BlhZ01qgjz1qvK5; Mon, 7 Sep 2020 23:41:44 +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 H-KdxbmEthGD; Mon, 7 Sep 2020 23:41:41 +0200 (CEST) X-Auth-Info: OGikQTCArvtL/PKD8qId2G3ZAwKs+45nTQDOQ0zpfF8= 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; Mon, 7 Sep 2020 23:41:41 +0200 (CEST) From: Lukasz Majewski To: Joseph Myers , Paul Eggert , Adhemerval Zanella Subject: [PATCH] y2038: nptl: Convert sem_{clock|timed}wait to support 64 bit time Date: Mon, 7 Sep 2020 23:41:19 +0200 Message-Id: <20200907214119.23613-1-lukma@denx.de> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-Spam-Status: No, score=-17.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, 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 , Stepan Golosunov , Alistair Francis Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" The sem_clockwait and sem_timedwait have been converted to support 64 bit time. This change reuses futex_abstimed_wait_cancelable64 function introduced earlier. The sem_{clock|timed}wait only accepts absolute time. Moreover, there is no need to check for NULL passed as *abstime pointer to the syscalls as both calls have exported symbols marked with __nonull attribute for abstime. For systems with __TIMESIZE != 64 && __WORDSIZE == 32: - Conversion from 32 bit time to 64 bit struct __timespec64 was necessary - Redirection to __sem_{clock|timed}wait64 will provide support for 64 bit time 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 __sem_{clock|timed}wait64 and __sem_{clock|timed}wait. Reviewed-by: Adhemerval Zanella --- nptl/sem_clockwait.c | 20 +++++++++++++++++--- nptl/sem_timedwait.c | 20 +++++++++++++++++--- nptl/sem_wait.c | 5 +++-- nptl/sem_waitcommon.c | 12 ++++++------ nptl/semaphoreP.h | 13 +++++++++++++ 5 files changed, 56 insertions(+), 14 deletions(-) diff --git a/nptl/sem_clockwait.c b/nptl/sem_clockwait.c index b9bae75183..1b93f00054 100644 --- a/nptl/sem_clockwait.c +++ b/nptl/sem_clockwait.c @@ -19,11 +19,12 @@ . */ #include +#include "semaphoreP.h" #include "sem_waitcommon.c" int -sem_clockwait (sem_t *sem, clockid_t clockid, - const struct timespec *abstime) +__sem_clockwait64 (sem_t *sem, clockid_t clockid, + const struct __timespec64 *abstime) { /* Check that supplied clockid is one we support, even if we don't end up waiting. */ @@ -42,5 +43,18 @@ sem_clockwait (sem_t *sem, clockid_t clockid, if (__new_sem_wait_fast ((struct new_sem *) sem, 0) == 0) return 0; else - return __new_sem_wait_slow ((struct new_sem *) sem, clockid, abstime); + return __new_sem_wait_slow64 ((struct new_sem *) sem, clockid, abstime); } + +#if __TIMESIZE != 64 +libpthread_hidden_def (__sem_clockwait64) + +int +__sem_clockwait (sem_t *sem, clockid_t clockid, const struct timespec *abstime) +{ + struct __timespec64 ts64 = valid_timespec_to_timespec64 (*abstime); + + return __sem_clockwait64 (sem, clockid, &ts64); +} +#endif +weak_alias (__sem_clockwait, sem_clockwait) diff --git a/nptl/sem_timedwait.c b/nptl/sem_timedwait.c index 99c11bf20e..5d054c950d 100644 --- a/nptl/sem_timedwait.c +++ b/nptl/sem_timedwait.c @@ -18,12 +18,13 @@ . */ #include +#include "semaphoreP.h" #include "sem_waitcommon.c" /* This is in a separate file because because sem_timedwait is only provided if __USE_XOPEN2K is defined. */ int -sem_timedwait (sem_t *sem, const struct timespec *abstime) +__sem_timedwait64 (sem_t *sem, const struct __timespec64 *abstime) { if (! valid_nanoseconds (abstime->tv_nsec)) { @@ -37,6 +38,19 @@ sem_timedwait (sem_t *sem, const struct timespec *abstime) if (__new_sem_wait_fast ((struct new_sem *) sem, 0) == 0) return 0; else - return __new_sem_wait_slow ((struct new_sem *) sem, - CLOCK_REALTIME, abstime); + return __new_sem_wait_slow64 ((struct new_sem *) sem, + CLOCK_REALTIME, abstime); } + +#if __TIMESIZE != 64 +libpthread_hidden_def (__sem_timedwait64) + +int +__sem_timedwait (sem_t *sem, const struct timespec *abstime) +{ + struct __timespec64 ts64 = valid_timespec_to_timespec64 (*abstime); + + return __sem_timedwait64 (sem, &ts64); +} +#endif +weak_alias (__sem_timedwait, sem_timedwait) diff --git a/nptl/sem_wait.c b/nptl/sem_wait.c index 171716fdbc..9374e0aaf6 100644 --- a/nptl/sem_wait.c +++ b/nptl/sem_wait.c @@ -18,6 +18,7 @@ . */ #include /* lll_futex* used by the old code. */ +#include "semaphoreP.h" #include "sem_waitcommon.c" int @@ -39,8 +40,8 @@ __new_sem_wait (sem_t *sem) if (__new_sem_wait_fast ((struct new_sem *) sem, 0) == 0) return 0; else - return __new_sem_wait_slow ((struct new_sem *) sem, - CLOCK_REALTIME, NULL); + return __new_sem_wait_slow64 ((struct new_sem *) sem, + CLOCK_REALTIME, NULL); } versioned_symbol (libpthread, __new_sem_wait, sem_wait, GLIBC_2_1); diff --git a/nptl/sem_waitcommon.c b/nptl/sem_waitcommon.c index 5a6d2643ee..6dd4eb97cb 100644 --- a/nptl/sem_waitcommon.c +++ b/nptl/sem_waitcommon.c @@ -104,18 +104,18 @@ __sem_wait_cleanup (void *arg) static int __attribute__ ((noinline)) do_futex_wait (struct new_sem *sem, clockid_t clockid, - const struct timespec *abstime) + const struct __timespec64 *abstime) { int err; #if __HAVE_64B_ATOMICS - err = futex_abstimed_wait_cancelable ( + err = __futex_abstimed_wait_cancelable64 ( (unsigned int *) &sem->data + SEM_VALUE_OFFSET, 0, clockid, abstime, sem->private); #else - err = futex_abstimed_wait_cancelable (&sem->value, SEM_NWAITERS_MASK, - clockid, abstime, sem->private); + err = __futex_abstimed_wait_cancelable64 (&sem->value, SEM_NWAITERS_MASK, + clockid, abstime, sem->private); #endif return err; @@ -162,8 +162,8 @@ __new_sem_wait_fast (struct new_sem *sem, int definitive_result) /* Slow path that blocks. */ static int __attribute__ ((noinline)) -__new_sem_wait_slow (struct new_sem *sem, clockid_t clockid, - const struct timespec *abstime) +__new_sem_wait_slow64 (struct new_sem *sem, clockid_t clockid, + const struct __timespec64 *abstime) { int err = 0; diff --git a/nptl/semaphoreP.h b/nptl/semaphoreP.h index e7e1c9763f..f25ba329d7 100644 --- a/nptl/semaphoreP.h +++ b/nptl/semaphoreP.h @@ -52,3 +52,16 @@ extern int __new_sem_wait (sem_t *sem); extern int __old_sem_wait (sem_t *sem); extern int __new_sem_trywait (sem_t *sem); extern int __new_sem_getvalue (sem_t *sem, int *sval); + +#if __TIMESIZE == 64 +# define __sem_clockwait64 __sem_clockwait +# define __sem_timedwait64 __sem_timedwait +#else +extern int +__sem_clockwait64 (sem_t *sem, clockid_t clockid, + const struct __timespec64 *abstime); +libpthread_hidden_proto (__sem_clockwait64) +extern int +__sem_timedwait64 (sem_t *sem, const struct __timespec64 *abstime); +libpthread_hidden_proto (__sem_timedwait64) +#endif