From patchwork Sun Jun 28 20:03:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 1318655 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ens-lyon.org Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49w1l34564z9s6w for ; Mon, 29 Jun 2020 06:03:11 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8A055389040A; Sun, 28 Jun 2020 20:03:07 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from hera.aquilenet.fr (hera.aquilenet.fr [IPv6:2a0c:e300::1]) by sourceware.org (Postfix) with ESMTPS id 982183851C0A for ; Sun, 28 Jun 2020 20:03:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 982183851C0A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=ens-lyon.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=samuel.thibault@ens-lyon.org Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 688F6186F; Sun, 28 Jun 2020 22:03:03 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id AlNijAvmjeN1; Sun, 28 Jun 2020 22:03:02 +0200 (CEST) Received: from function (lfbn-bor-1-797-11.w86-234.abo.wanadoo.fr [86.234.239.11]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 837728C9; Sun, 28 Jun 2020 22:03:02 +0200 (CEST) Received: from samy by function with local (Exim 4.94) (envelope-from ) id 1jpdW0-002p4g-PX; Sun, 28 Jun 2020 22:03:00 +0200 From: Samuel Thibault To: libc-alpha@sourceware.org Subject: [hurd,commited] hurd: Make fcntl(F_SETLKW*) cancellation points Date: Sun, 28 Jun 2020 22:03:00 +0200 Message-Id: <20200628200300.672945-1-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_NEUTRAL, 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: commit-hurd@gnu.org Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" and add _nocancel variant. * sysdeps/mach/hurd/Makefile [io] (sysdep_routines): Add fcntl_nocancel. * sysdeps/mach/hurd/fcntl.c [NOCANCEL]: Include . [!NOCANCEL]: Include . (__libc_fcntl) [!NOCANCEL]: Surround __file_record_lock call with enabling async cancel, and use HURD_FD_PORT_USE_CANCEL instead of HURD_FD_PORT_USE. * sysdeps/mach/hurd/fcntl_nocancel.c: New file, defines __fcntl_nocancel by including fcntl.c. * sysdeps/mach/hurd/not-cancel.h (__fcntl64_nocancel): Replace macro with __fcntl_nocancel declaration with hidden proto, and make __fcntl64_nocancel call __fcntl_nocancel. --- sysdeps/mach/hurd/Makefile | 2 +- sysdeps/mach/hurd/fcntl.c | 38 ++++++++++++++++++++++++++---- sysdeps/mach/hurd/fcntl_nocancel.c | 3 +++ sysdeps/mach/hurd/not-cancel.h | 9 ++++--- 4 files changed, 44 insertions(+), 8 deletions(-) create mode 100644 sysdeps/mach/hurd/fcntl_nocancel.c diff --git a/sysdeps/mach/hurd/Makefile b/sysdeps/mach/hurd/Makefile index a1ca034175..9c53db3783 100644 --- a/sysdeps/mach/hurd/Makefile +++ b/sysdeps/mach/hurd/Makefile @@ -197,7 +197,7 @@ endif ifeq (io, $(subdir)) sysdep_routines += f_setlk close_nocancel close_nocancel_nostatus \ - open_nocancel openat_nocancel read_nocancel \ + fcntl_nocancel open_nocancel openat_nocancel read_nocancel \ pread64_nocancel write_nocancel pwrite64_nocancel \ wait4_nocancel endif diff --git a/sysdeps/mach/hurd/fcntl.c b/sysdeps/mach/hurd/fcntl.c index 95b0ebff0f..564d9dcd23 100644 --- a/sysdeps/mach/hurd/fcntl.c +++ b/sysdeps/mach/hurd/fcntl.c @@ -21,6 +21,11 @@ #include #include #include /* XXX for LOCK_* */ +#ifdef NOCANCEL +#include +#else +#include +#endif #include "f_setlk.h" /* Perform file control operations on FD. */ @@ -155,8 +160,19 @@ __libc_fcntl (int fd, int cmd, ...) .l_pid = fl->l_pid }; - err = HURD_FD_PORT_USE (d, __file_record_lock (port, cmd, &fl64, - MACH_PORT_NULL, MACH_MSG_TYPE_MAKE_SEND)); +#ifndef NOCANCEL + if (cmd == F_SETLKW64) + { + int cancel_oldtype = LIBC_CANCEL_ASYNC(); + err = HURD_FD_PORT_USE_CANCEL (d, __file_record_lock (port, cmd, + &fl64, MACH_PORT_NULL, + MACH_MSG_TYPE_MAKE_SEND)); + LIBC_CANCEL_RESET (cancel_oldtype); + } + else +#endif + err = HURD_FD_PORT_USE (d, __file_record_lock (port, cmd, &fl64, + MACH_PORT_NULL, MACH_MSG_TYPE_MAKE_SEND)); /* XXX: To remove once file_record_lock RPC is settled. */ if (err == EMIG_BAD_ID || err == EOPNOTSUPP) @@ -207,8 +223,19 @@ __libc_fcntl (int fd, int cmd, ...) { struct flock64 *fl = va_arg (ap, struct flock64 *); - err = HURD_FD_PORT_USE (d, __file_record_lock (port, cmd, fl, - MACH_PORT_NULL, MACH_MSG_TYPE_MAKE_SEND)); +#ifndef NOCANCEL + if (cmd == F_SETLKW64) + { + int cancel_oldtype = LIBC_CANCEL_ASYNC(); + err = HURD_FD_PORT_USE_CANCEL (d, __file_record_lock (port, cmd, + fl, MACH_PORT_NULL, + MACH_MSG_TYPE_MAKE_SEND)); + LIBC_CANCEL_RESET (cancel_oldtype); + } + else +#endif + err = HURD_FD_PORT_USE (d, __file_record_lock (port, cmd, fl, + MACH_PORT_NULL, MACH_MSG_TYPE_MAKE_SEND)); /* XXX: To remove once file_record_lock RPC is settled. */ if (err == EMIG_BAD_ID || err == EOPNOTSUPP) @@ -263,6 +290,8 @@ __libc_fcntl (int fd, int cmd, ...) return result; } libc_hidden_def (__libc_fcntl) + +#ifndef NOCANCEL weak_alias (__libc_fcntl, __fcntl) libc_hidden_weak (__fcntl) weak_alias (__libc_fcntl, fcntl) @@ -272,3 +301,4 @@ libc_hidden_def (__libc_fcntl64) weak_alias (__libc_fcntl64, __fcntl64) libc_hidden_weak (__fcntl64) weak_alias (__fcntl64, fcntl64) +#endif diff --git a/sysdeps/mach/hurd/fcntl_nocancel.c b/sysdeps/mach/hurd/fcntl_nocancel.c new file mode 100644 index 0000000000..8913405409 --- /dev/null +++ b/sysdeps/mach/hurd/fcntl_nocancel.c @@ -0,0 +1,3 @@ +#define NOCANCEL +#define __libc_fcntl __fcntl_nocancel +#include diff --git a/sysdeps/mach/hurd/not-cancel.h b/sysdeps/mach/hurd/not-cancel.h index 69cd781f68..94b731c080 100644 --- a/sysdeps/mach/hurd/not-cancel.h +++ b/sysdeps/mach/hurd/not-cancel.h @@ -69,9 +69,11 @@ __typeof (__wait4) __wait4_nocancel; # define __waitpid_nocancel(pid, stat_loc, options) \ __wait4_nocancel (pid, stat_loc, options, NULL) -/* For now we have none. Map the name to the normal functions. */ -#define __fcntl64_nocancel(fd, cmd, ...) \ - __fcntl64 (fd, cmd, __VA_ARGS__) +/* Non cancellable fcntl syscall. */ +__typeof (__fcntl) __fcntl_nocancel; +/* fcntl64 is just the same as fcntl for us. */ +#define __fcntl64_nocancel(...) \ + __fcntl_nocancel (__VA_ARGS__) #if IS_IN (libc) hidden_proto (__close_nocancel) @@ -85,6 +87,7 @@ hidden_proto (__pwrite64_nocancel) hidden_proto (__writev_nocancel) hidden_proto (__writev_nocancel_nostatus) hidden_proto (__wait4_nocancel) +hidden_proto (__fcntl_nocancel) #endif #endif /* NOT_CANCEL_H */