From patchwork Tue Jul 7 15:08:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Majewski X-Patchwork-Id: 39938 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 2E74138618F9; Tue, 7 Jul 2020 15:08:56 +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.9]) by sourceware.org (Postfix) with ESMTPS id B227A38618D4 for ; Tue, 7 Jul 2020 15:08:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B227A38618D4 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 4B1QnF6SMNz1qskn; Tue, 7 Jul 2020 17:08:49 +0200 (CEST) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 4B1QnF5v9nz1r573; Tue, 7 Jul 2020 17:08:49 +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 6LOpc5eDy-nA; Tue, 7 Jul 2020 17:08:48 +0200 (CEST) X-Auth-Info: 4pD5ejFFO4CrCt21esZvn46abUz47k5fGpZrKNXEd/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:47 +0200 (CEST) From: Lukasz Majewski To: Joseph Myers , Paul Eggert , Adhemerval Zanella Subject: [RFC 03/10] y2038: Convert __lll_futex* functions to use futex_time64 when available Date: Tue, 7 Jul 2020 17:08:20 +0200 Message-Id: <20200707150827.20899-4-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.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, 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" As the 'futex' syscall is wrapped with a C preprocessor macros, it was necessary to provide new set of those to replace call it with Y2038 safe 'futex_time64' syscall. The current code expand wrapper's arguments as __VA_ARGS__ when more than three arguments are passed. For the conversion it was necessary to also have 'timeout' explicitly passed, and hence the introduction of lll_futex_syscall_time64_4 and lll_futex_syscall_time64 functions. The former expects exactly 4 arguments - timeout is the last one. Signed-off-by: Lukasz Majewski --- sysdeps/nptl/lowlevellock-futex.h | 80 ++++++++++++++++++++++++++++--- sysdeps/nptl/lowlevellock.h | 2 +- 2 files changed, 75 insertions(+), 7 deletions(-) diff --git a/sysdeps/nptl/lowlevellock-futex.h b/sysdeps/nptl/lowlevellock-futex.h index 2209ca76a1..a686773db4 100644 --- a/sysdeps/nptl/lowlevellock-futex.h +++ b/sysdeps/nptl/lowlevellock-futex.h @@ -65,14 +65,82 @@ (((fl) | FUTEX_PRIVATE_FLAG) ^ (private)) # endif -# define lll_futex_syscall(nargs, futexp, op, ...) \ +# define __lll_futex_syscall(nargs, futexp, op, ...) \ ({ \ - long int __ret = INTERNAL_SYSCALL (futex, nargs, futexp, op, \ + long int __ret = INTERNAL_SYSCALL (futex, nargs, futexp, op, \ __VA_ARGS__); \ (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (__ret)) \ ? -INTERNAL_SYSCALL_ERRNO (__ret) : 0); \ }) +# define __lll_futex_syscall64(nargs, futexp, op, ...) \ + ({ \ + long int __ret = INTERNAL_SYSCALL (futex_time64, nargs, futexp, op, \ + __VA_ARGS__); \ + (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (__ret)) \ + ? -INTERNAL_SYSCALL_ERRNO (__ret) : 0); \ + }) + +# ifdef __ASSUME_TIME64_SYSCALLS +# ifndef __NR_futex_time64 +# define __NR_futex_time64 __NR_futex +# endif +# define lll_futex_syscall(nargs, futexp, op, ...) \ + __lll_futex_syscall64(nargs, futexp, op, __VA_ARGS__) +# define lll_futex_syscall_time64_4(nargs, futexp, op, val, timeout)\ + __lll_futex_syscall64(nargs, futexp, op, val, timeout) +# define lll_futex_syscall_time64(nargs, futexp, op, val, timeout, ...)\ + __lll_futex_syscall64(nargs, futexp, op, val, timeout, __VA_ARGS__) +# else +inline static long int +__lll_futex_syscall_time_check (long int __ret, const struct __timespec64 *t) +{ + if (! (__ret == 0 || errno != ENOSYS)) + if (t != NULL && ! in_time_t_range (t->tv_sec)) + __ret = ({ errno = (EOVERFLOW); -1l; }); + return __ret; +} +# define lll_futex_syscall(nargs, futexp, op, ...) \ + ({ \ + long int __ret = \ + __lll_futex_syscall64(nargs, futexp, op, __VA_ARGS__); \ + if (! (__ret == 0 || errno != ENOSYS)) \ + __ret = \ + __lll_futex_syscall(nargs, futexp, op, __VA_ARGS__); \ + __ret; \ + }) + +# define lll_futex_syscall_time64(nargs, futexp, op, val, timeout, ...)\ + ({ \ + struct timespec __ts32; \ + if (timeout != NULL) \ + __ts32 = valid_timespec64_to_timespec (*((struct __timespec64*) timeout)); \ + long int __ret = \ + __lll_futex_syscall64(nargs, futexp, op, val, timeout,\ + __VA_ARGS__); \ + __ret = __lll_futex_syscall_time_check (__ret, timeout); \ + if (__ret != 0) \ + __ret = __lll_futex_syscall(nargs, futexp, op, val, \ + timeout != NULL ? &__ts32 : NULL, \ + __VA_ARGS__); \ + __ret; \ + }) + +# define lll_futex_syscall_time64_4(nargs, futexp, op, val, timeout)\ + ({ \ + struct timespec __ts32; \ + if (timeout != NULL) \ + __ts32 = valid_timespec64_to_timespec (*((struct __timespec64*) timeout)); \ + long int __ret = \ + __lll_futex_syscall64(nargs, futexp, op, val, timeout); \ + __ret = __lll_futex_syscall_time_check (__ret, timeout); \ + if (__ret != 0) \ + __ret = __lll_futex_syscall(nargs, futexp, op, val, \ + timeout != NULL ? &__ts32 : NULL); \ + __ret; \ + }) + +# endif /* For most of these macros, the return value is never really used. Nevertheless, the protocol is that each one returns a negated errno code for failure or zero for success. (Note that the corresponding @@ -85,7 +153,7 @@ lll_futex_timed_wait (futexp, val, NULL, private) # define lll_futex_timed_wait(futexp, val, timeout, private) \ - lll_futex_syscall (4, futexp, \ + lll_futex_syscall_time64_4 (4, futexp, \ __lll_private_flag (FUTEX_WAIT, private), \ val, timeout) @@ -107,7 +175,7 @@ const int op = \ __lll_private_flag (FUTEX_WAIT_BITSET | clockbit, private); \ \ - __ret = lll_futex_syscall (6, futexp, op, val, \ + __ret = lll_futex_syscall_time64 (6, futexp, op, val, \ timeout, NULL /* Unused. */, \ FUTEX_BITSET_MATCH_ANY); \ } \ @@ -118,7 +186,7 @@ /* Wake up up to NR waiters on FUTEXP. */ # define lll_futex_wake(futexp, nr, private) \ - lll_futex_syscall (4, futexp, \ + lll_futex_syscall_time64_4 (4, futexp, \ __lll_private_flag (FUTEX_WAKE, private), nr, 0) /* Wake up up to NR_WAKE waiters on FUTEXP. Move up to NR_MOVE of the @@ -159,7 +227,7 @@ /* Like lll_futex_wait_requeue_pi, but with a timeout. */ # define lll_futex_timed_wait_requeue_pi(futexp, val, timeout, clockbit, \ mutex, private) \ - lll_futex_syscall (5, futexp, \ + lll_futex_syscall_time64 (5, futexp, \ __lll_private_flag (FUTEX_WAIT_REQUEUE_PI \ | (clockbit), private), \ val, timeout, mutex) diff --git a/sysdeps/nptl/lowlevellock.h b/sysdeps/nptl/lowlevellock.h index 68b3be8819..864152e609 100644 --- a/sysdeps/nptl/lowlevellock.h +++ b/sysdeps/nptl/lowlevellock.h @@ -123,7 +123,7 @@ extern void __lll_lock_wait (int *futex, int private) attribute_hidden; extern int __lll_clocklock_wait (int *futex, int val, clockid_t, - const struct timespec *, + const struct __timespec64 *, int private) attribute_hidden; #define lll_timedwait(futex, val, clockid, abstime, private) \