From patchwork Sun Jun 14 16:57:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 1308990 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 49lLJS2lyxz9sRK for ; Mon, 15 Jun 2020 02:58:32 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0B5D4395C85D; Sun, 14 Jun 2020 16:58:08 +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 A9DE3395C800 for ; Sun, 14 Jun 2020 16:58:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org A9DE3395C800 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 E296D33DC; Sun, 14 Jun 2020 18:58: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 vsmPYQvHRdhL; Sun, 14 Jun 2020 18:58:01 +0200 (CEST) Received: from function.home (unknown [IPv6:2a01:cb19:956:1b00:9eb6:d0ff:fe88:c3c7]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 2D1C233CB; Sun, 14 Jun 2020 18:57:58 +0200 (CEST) Received: from samy by function.home with local (Exim 4.94) (envelope-from ) id 1jkVxF-00HRMK-7H; Sun, 14 Jun 2020 18:57:57 +0200 From: Samuel Thibault To: libc-alpha@sourceware.org Subject: [hurd, commited 5/6] hurd: Make write and pwrite64 cancellation points Date: Sun, 14 Jun 2020 18:57:56 +0200 Message-Id: <20200614165757.4156687-6-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200614165757.4156687-1-samuel.thibault@ens-lyon.org> References: <20200614165757.4156687-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, KAM_SHORT, 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 variants. * sysdeps/mach/hurd/write.c (__libc_write): Call __write_nocancel surrounded by enabling async cancel, to replace implementation moved to... * sysdeps/mach/hurd/write_nocancel.c (__write_nocancel): ... here. * sysdeps/mach/hurd/pwrite64.c (__libc_pwrite64): Call __pwrite64_nocancel surrounded by enabling async cancel, to replace implementation moved to... * sysdeps/mach/hurd/pwrite64_nocancel.c (__pwrite64_nocancel): ... here. * sysdeps/mach/hurd/Makefile (sysdep_routines): Add write_nocancel and pwrite64_nocancel. * sysdeps/mach/hurd/not-cancel.h (__write_nocancel, __pwrite64_nocancel): Replace macros with prototypes with a hidden proto on libc. * sysdeps/mach/hurd/dl-sysdep.c (__write_nocancel): New alias, check that it is not hidden. * sysdeps/mach/hurd/Versions (libc.GLIBC_PRIVATE): Add __write_nocancel. (ld.GLIBC_PRIVATE): Add __write_nocancel. * sysdeps/mach/hurd/i386/localplt.data (__write_nocancel): Add reference. --- sysdeps/mach/hurd/Makefile | 2 +- sysdeps/mach/hurd/Versions | 2 ++ sysdeps/mach/hurd/dl-sysdep.c | 2 ++ sysdeps/mach/hurd/i386/localplt.data | 3 ++- sysdeps/mach/hurd/not-cancel.h | 10 ++++++-- sysdeps/mach/hurd/pwrite64.c | 16 ++++++------ sysdeps/mach/hurd/pwrite64_nocancel.c | 35 +++++++++++++++++++++++++++ sysdeps/mach/hurd/write.c | 13 +++++----- sysdeps/mach/hurd/write_nocancel.c | 30 +++++++++++++++++++++++ 9 files changed, 94 insertions(+), 19 deletions(-) create mode 100644 sysdeps/mach/hurd/pwrite64_nocancel.c create mode 100644 sysdeps/mach/hurd/write_nocancel.c diff --git a/sysdeps/mach/hurd/Makefile b/sysdeps/mach/hurd/Makefile index bf741058f5..8b74d3f002 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_nostatus read_nocancel \ - pread64_nocancel + pread64_nocancel write_nocancel pwrite64_nocancel endif ifeq ($(subdir),sunrpc) diff --git a/sysdeps/mach/hurd/Versions b/sysdeps/mach/hurd/Versions index ce873f33f6..d93ad1264e 100644 --- a/sysdeps/mach/hurd/Versions +++ b/sysdeps/mach/hurd/Versions @@ -11,6 +11,7 @@ libc { # Functions shared with the dynamic linker __access; __access_noerrno; __libc_read; __libc_write; __libc_lseek64; __read_nocancel; __pread64_nocancel; + __write_nocancel; __libc_lock_self0; __getcwd; _dl_init_first; @@ -51,6 +52,7 @@ ld { # functions that must be shared with libc __access; __access_noerrno; __libc_read; __libc_write; __libc_lseek64; __read_nocancel; __pread64_nocancel; + __write_nocancel; __libc_lock_self0; __getcwd; } } diff --git a/sysdeps/mach/hurd/dl-sysdep.c b/sysdeps/mach/hurd/dl-sysdep.c index 1626cd5928..a4eab4c08e 100644 --- a/sysdeps/mach/hurd/dl-sysdep.c +++ b/sysdeps/mach/hurd/dl-sysdep.c @@ -396,6 +396,7 @@ libc_hidden_weak (__read) weak_alias (__read, __read_nocancel) check_no_hidden(__write); +check_no_hidden(__write_nocancel); __ssize_t weak_function __write (int fd, const void *buf, size_t nbytes) { @@ -411,6 +412,7 @@ __write (int fd, const void *buf, size_t nbytes) return nwrote; } libc_hidden_weak (__write) + weak_alias (__write, __write_nocancel) /* This is only used for printing messages (see dl-misc.c). */ check_no_hidden(__writev); diff --git a/sysdeps/mach/hurd/i386/localplt.data b/sysdeps/mach/hurd/i386/localplt.data index c9f3ca66f9..66478dee7a 100644 --- a/sysdeps/mach/hurd/i386/localplt.data +++ b/sysdeps/mach/hurd/i386/localplt.data @@ -23,7 +23,8 @@ ld.so: __read ? ld.so: __read_nocancel ld.so: __pread64 ld.so: __pread64_nocancel -ld.so: __write +ld.so: __write ? +ld.so: __write_nocancel ld.so: __writev ld.so: __libc_lseek64 ld.so: __mmap diff --git a/sysdeps/mach/hurd/not-cancel.h b/sysdeps/mach/hurd/not-cancel.h index 8a8f5a9d3c..d2c3e20019 100644 --- a/sysdeps/mach/hurd/not-cancel.h +++ b/sysdeps/mach/hurd/not-cancel.h @@ -48,8 +48,12 @@ __typeof (__read) __read_nocancel; /* Non cancellable pread syscall (LFS version). */ __typeof (__pread64) __pread64_nocancel; -#define __write_nocancel(fd, buf, n) \ - __write (fd, buf, n) +/* Non cancellable write syscall. */ +__typeof (__write) __write_nocancel; + +/* Non cancellable pwrite syscall (LFS version). */ +__typeof (__pwrite64) __pwrite64_nocancel; + #define __writev_nocancel_nostatus(fd, iov, n) \ (void) __writev (fd, iov, n) # define __waitpid_nocancel(pid, stat_loc, options) \ @@ -60,6 +64,8 @@ __typeof (__pread64) __pread64_nocancel; #if IS_IN (libc) hidden_proto (__read_nocancel) hidden_proto (__pread64_nocancel) +hidden_proto (__write_nocancel) +hidden_proto (__pwrite64_nocancel) hidden_proto (__close_nocancel_nostatus) #endif diff --git a/sysdeps/mach/hurd/pwrite64.c b/sysdeps/mach/hurd/pwrite64.c index d4f3a83982..961b231394 100644 --- a/sysdeps/mach/hurd/pwrite64.c +++ b/sysdeps/mach/hurd/pwrite64.c @@ -17,19 +17,17 @@ License along with the GNU C Library; if not, see . */ -#include -#include -#include +#include +#include ssize_t __libc_pwrite64 (int fd, const void *buf, size_t nbytes, off64_t offset) { - error_t err; - if (offset < 0) - err = EINVAL; - else - err = HURD_FD_USE (fd, _hurd_fd_write (descriptor, buf, &nbytes, offset)); - return err ? __hurd_dfail (fd, err) : nbytes; + ssize_t ret; + int cancel_oldtype = LIBC_CANCEL_ASYNC(); + ret = __pwrite64_nocancel (fd, buf, nbytes, offset); + LIBC_CANCEL_RESET (cancel_oldtype); + return ret; } #ifndef __libc_pwrite64 diff --git a/sysdeps/mach/hurd/pwrite64_nocancel.c b/sysdeps/mach/hurd/pwrite64_nocancel.c new file mode 100644 index 0000000000..f6bdbbe0b1 --- /dev/null +++ b/sysdeps/mach/hurd/pwrite64_nocancel.c @@ -0,0 +1,35 @@ +/* Write block to given position in file without changing file pointer. + Hurd version. + Copyright (C) 2001-2020 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include + +ssize_t +__pwrite64_nocancel (int fd, const void *buf, size_t nbytes, off64_t offset) +{ + error_t err; + if (offset < 0) + err = EINVAL; + else + err = HURD_FD_USE (fd, _hurd_fd_write (descriptor, buf, &nbytes, offset)); + return err ? __hurd_dfail (fd, err) : nbytes; +} +libc_hidden_weak (__pwrite64_nocancel) diff --git a/sysdeps/mach/hurd/write.c b/sysdeps/mach/hurd/write.c index 9e1ade8801..0eea22be4b 100644 --- a/sysdeps/mach/hurd/write.c +++ b/sysdeps/mach/hurd/write.c @@ -15,16 +15,17 @@ License along with the GNU C Library; if not, see . */ -#include -#include -#include +#include +#include ssize_t __libc_write (int fd, const void *buf, size_t nbytes) { - error_t err = HURD_FD_USE (fd, _hurd_fd_write (descriptor, - buf, &nbytes, -1)); - return err ? __hurd_dfail (fd, err) : nbytes; + ssize_t ret; + int cancel_oldtype = LIBC_CANCEL_ASYNC(); + ret = __write_nocancel (fd, buf, nbytes); + LIBC_CANCEL_RESET (cancel_oldtype); + return ret; } libc_hidden_def (__libc_write) weak_alias (__libc_write, __write) diff --git a/sysdeps/mach/hurd/write_nocancel.c b/sysdeps/mach/hurd/write_nocancel.c new file mode 100644 index 0000000000..ab11c9cdd1 --- /dev/null +++ b/sysdeps/mach/hurd/write_nocancel.c @@ -0,0 +1,30 @@ +/* Copyright (C) 1991-2020 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include + +ssize_t +__write_nocancel (int fd, const void *buf, size_t nbytes) +{ + error_t err = HURD_FD_USE (fd, _hurd_fd_write (descriptor, + buf, &nbytes, -1)); + return err ? __hurd_dfail (fd, err) : nbytes; +} +libc_hidden_weak (__write_nocancel)