From patchwork Tue Jul 7 15:08:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Majewski X-Patchwork-Id: 39940 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 55712386190E; Tue, 7 Jul 2020 15:09:00 +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 [212.18.0.10]) by sourceware.org (Postfix) with ESMTPS id 89EF9385EC56 for ; Tue, 7 Jul 2020 15:08:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 89EF9385EC56 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 4B1QnP3vkHz1rxb9; Tue, 7 Jul 2020 17:08:57 +0200 (CEST) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 4B1QnP2r1vz1r574; Tue, 7 Jul 2020 17:08:57 +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 hi3TMsBUOc2G; Tue, 7 Jul 2020 17:08:55 +0200 (CEST) X-Auth-Info: WYt8PdfF6aO3NXLkKS2yCCCfUy+O2iHGRq1e6uRDk/Y= 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; Tue, 7 Jul 2020 17:08:55 +0200 (CEST) From: Lukasz Majewski To: Joseph Myers , Paul Eggert , Adhemerval Zanella Subject: [RFC 06/10] y2038: Convert sem_{timed|clock}wait to support 64 bit timeout Date: Tue, 7 Jul 2020 17:08:23 +0200 Message-Id: <20200707150827.20899-7-lukma@denx.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200707150827.20899-1-lukma@denx.de> References: <20200707150827.20899-1-lukma@denx.de> MIME-Version: 1.0 X-Spam-Status: No, score=-20.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, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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 conversion was to: - Replace struct timespec with struct __timespec64 - Provide aliases to __sem_* functions - Introduce Y2038 safe versions of __sem_timedwait64 and __sem_clockwait64 --- nptl/sem_clockwait.c | 21 +++++++++++++++++++-- nptl/sem_timedwait.c | 18 +++++++++++++++++- nptl/sem_waitcommon.c | 4 ++-- nptl/semaphoreP.h | 12 ++++++++++++ 4 files changed, 50 insertions(+), 5 deletions(-) diff --git a/nptl/sem_clockwait.c b/nptl/sem_clockwait.c index b9bae75183..86ce18ee2b 100644 --- a/nptl/sem_clockwait.c +++ b/nptl/sem_clockwait.c @@ -20,10 +20,11 @@ #include #include "sem_waitcommon.c" +#include "semaphoreP.h" 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. */ @@ -44,3 +45,19 @@ sem_clockwait (sem_t *sem, clockid_t clockid, else return __new_sem_wait_slow ((struct new_sem *) sem, clockid, abstime); } + +#if __TIMESIZE != 64 +libc_hidden_def (__sem_timedwait64) + +int +__sem_clockwait (sem_t *sem, clockid_t clockid, + const struct timespec *abstime) +{ + struct __timespec64 ts64; + if (abstime != NULL) + ts64 = valid_timespec_to_timespec64 (*abstime); + + return __sem_clockwait64 (sem, clockid, abstime != NULL ? &ts64 : NULL); +} +#endif +weak_alias (__sem_clockwait, sem_clockwait) diff --git a/nptl/sem_timedwait.c b/nptl/sem_timedwait.c index 99c11bf20e..0ffb56ec67 100644 --- a/nptl/sem_timedwait.c +++ b/nptl/sem_timedwait.c @@ -19,11 +19,12 @@ #include #include "sem_waitcommon.c" +#include "semaphoreP.h" /* 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)) { @@ -40,3 +41,18 @@ sem_timedwait (sem_t *sem, const struct timespec *abstime) return __new_sem_wait_slow ((struct new_sem *) sem, CLOCK_REALTIME, abstime); } + +#if __TIMESIZE != 64 +libc_hidden_def (__sem_timedwait64) + +int +__sem_timedwait (sem_t *sem, const struct timespec *abstime) +{ + struct __timespec64 ts64; + if (abstime != NULL) + ts64 = valid_timespec_to_timespec64 (*abstime); + + return __sem_timedwait64 (sem, abstime != NULL ? &ts64 : NULL); +} +#endif +weak_alias (__sem_timedwait, sem_timedwait) diff --git a/nptl/sem_waitcommon.c b/nptl/sem_waitcommon.c index 5a6d2643ee..7fdc084d53 100644 --- a/nptl/sem_waitcommon.c +++ b/nptl/sem_waitcommon.c @@ -104,7 +104,7 @@ __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; @@ -163,7 +163,7 @@ __new_sem_wait_fast (struct new_sem *sem, int definitive_result) static int __attribute__ ((noinline)) __new_sem_wait_slow (struct new_sem *sem, clockid_t clockid, - const struct timespec *abstime) + const struct __timespec64 *abstime) { int err = 0; diff --git a/nptl/semaphoreP.h b/nptl/semaphoreP.h index e7e1c9763f..9023ea5573 100644 --- a/nptl/semaphoreP.h +++ b/nptl/semaphoreP.h @@ -17,6 +17,7 @@ . */ #include +#include #include "pthreadP.h" #define SEM_SHM_PREFIX "sem." @@ -52,3 +53,14 @@ 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_timedwait64 __sem_timedwait +# define __sem_clockwait64 __sem_clockwait +#else +extern int __sem_timedwait64 (sem_t *sem, const struct __timespec64 *abstime); +libc_hidden_proto (__sem_timedwait64) +extern int __sem_clockwait64 (sem_t *sem, clockid_t clockid, + const struct __timespec64 *abstime); +libc_hidden_proto (__sem_clockwait64) +#endif