From patchwork Mon Jun 29 00:32:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 1318696 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 49w7k86ln5z9sQx for ; Mon, 29 Jun 2020 10:32:48 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 42872388E82D; Mon, 29 Jun 2020 00:32:34 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from hera.aquilenet.fr (hera.aquilenet.fr [185.233.100.1]) by sourceware.org (Postfix) with ESMTPS id CA8733840C0F for ; Mon, 29 Jun 2020 00:32:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org CA8733840C0F 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 BC87F199E; Mon, 29 Jun 2020 02:32:29 +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 Jz0O6uK5JsgW; Mon, 29 Jun 2020 02:32:28 +0200 (CEST) Received: from function (unknown [IPv6:2a01:cb19:956:1b00:9eb6:d0ff:fe88:c3c7]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 37A8219A6; Mon, 29 Jun 2020 02:32:26 +0200 (CEST) Received: from samy by function with local (Exim 4.94) (envelope-from ) id 1jphid-003Kjb-43; Mon, 29 Jun 2020 02:32:19 +0200 From: Samuel Thibault To: libc-alpha@sourceware.org Subject: [hurd,commited 2/3] hurd: Add remaining cancelation points Date: Mon, 29 Jun 2020 02:32:17 +0200 Message-Id: <20200629003218.794639-3-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200629003218.794639-1-samuel.thibault@ens-lyon.org> References: <20200629003218.794639-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 X-Spam-Status: No, score=-11.0 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" * hurd/hurdselect.c: Include . (_hurd_select): Surround call to __mach_msg with enabling async cancel. * sysdeps/mach/hurd/accept4.c: Include . (__libc_accept4): Surround call to __socket_accept with enabling async cancel, and use HURD_DPORT_USE_CANCEL instead of HURD_DPORT_USE. * sysdeps/mach/hurd/connect.c: Include . (__connect): Surround call to __file_name_lookup and __socket_connect with enabling async cancel, and use HURD_DPORT_USE_CANCEL instead of HURD_DPORT_USE. * sysdeps/mach/hurd/fdatasync.c: Include . (fdatasync): Surround call to __file_sync with enabling async cancel, and use HURD_DPORT_USE_CANCEL instead of HURD_DPORT_USE. * sysdeps/mach/hurd/fsync.c: Include . (fsync): Surround call to __file_sync with enabling async cancel, and use HURD_DPORT_USE_CANCEL instead of HURD_DPORT_USE. * sysdeps/mach/hurd/ioctl.c: Include . (__ioctl): When request is TIOCDRAIN, surround call to send_rpc with enabling async cancel, and use HURD_DPORT_USE_CANCEL instead of HURD_DPORT_USE. * sysdeps/mach/hurd/msync.c: Include . (msync): Surround call to __vm_object_sync with enabling async cancel. * sysdeps/mach/hurd/sigsuspend.c: Include . (__sigsuspend): Surround call to __mach_msg with enabling async cancel. * sysdeps/mach/hurd/sigwait.c: Include . (__sigwait): Surround wait code with enabling async cancel. * sysdeps/mach/msync.c: Include . (msync): Surround call to __vm_msync with enabling async cancel. * sysdeps/mach/sleep.c: Include . (__sleep): Surround call to __mach_msg with enabling async cancel. * sysdeps/mach/usleep.c: Include . (usleep): Surround call to __vm_msync with enabling async cancel. --- hurd/hurdselect.c | 5 +++++ sysdeps/mach/hurd/accept4.c | 7 ++++++- sysdeps/mach/hurd/connect.c | 11 +++++++++-- sysdeps/mach/hurd/fdatasync.c | 8 +++++++- sysdeps/mach/hurd/fsync.c | 8 +++++++- sysdeps/mach/hurd/ioctl.c | 11 ++++++++++- sysdeps/mach/hurd/msync.c | 4 ++++ sysdeps/mach/hurd/sigsuspend.c | 5 +++++ sysdeps/mach/hurd/sigwait.c | 4 ++++ sysdeps/mach/msync.c | 9 +++++++-- sysdeps/mach/sleep.c | 4 ++++ sysdeps/mach/usleep.c | 4 ++++ 12 files changed, 72 insertions(+), 8 deletions(-) diff --git a/hurd/hurdselect.c b/hurd/hurdselect.c index 69a415c02c..8da0ccf282 100644 --- a/hurd/hurdselect.c +++ b/hurd/hurdselect.c @@ -28,6 +28,7 @@ #include #include #include +#include /* All user select types. */ #define SELECT_ALL (SELECT_READ | SELECT_WRITE | SELECT_URG) @@ -432,11 +433,14 @@ _hurd_select (int nfds, to = MACH_MSG_TIMEOUT_NONE; } + int cancel_oldtype = LIBC_CANCEL_ASYNC(); while ((msgerr = __mach_msg (&msg.head, MACH_RCV_MSG | MACH_RCV_INTERRUPT | options, 0, sizeof msg, portset, to, MACH_PORT_NULL)) == MACH_MSG_SUCCESS) { + LIBC_CANCEL_RESET (cancel_oldtype); + /* We got a message. Decode it. */ #ifdef MACH_MSG_TYPE_BIT const union typeword inttype = @@ -527,6 +531,7 @@ _hurd_select (int nfds, options |= MACH_RCV_TIMEOUT; } } + LIBC_CANCEL_RESET (cancel_oldtype); if (msgerr == MACH_RCV_INTERRUPTED) /* Interruption on our side (e.g. signal reception). */ diff --git a/sysdeps/mach/hurd/accept4.c b/sysdeps/mach/hurd/accept4.c index 639f159951..2da7a8b032 100644 --- a/sysdeps/mach/hurd/accept4.c +++ b/sysdeps/mach/hurd/accept4.c @@ -24,6 +24,7 @@ #include #include #include +#include /* Await a connection on socket FD. When a connection arrives, open a new socket to communicate with it, @@ -41,13 +42,17 @@ __libc_accept4 (int fd, __SOCKADDR_ARG addrarg, socklen_t *addr_len, int flags) char *buf = (char *) addr; mach_msg_type_number_t buflen; int type; + int cancel_oldtype; flags = sock_to_o_flags (flags); if (flags & ~(O_CLOEXEC | O_NONBLOCK)) return __hurd_fail (EINVAL); - if (err = HURD_DPORT_USE (fd, __socket_accept (port, &new, &aport))) + cancel_oldtype = LIBC_CANCEL_ASYNC(); + err = HURD_DPORT_USE_CANCEL (fd, __socket_accept (port, &new, &aport)); + LIBC_CANCEL_RESET (cancel_oldtype); + if (err) return __hurd_dfail (fd, err); if (addr != NULL) diff --git a/sysdeps/mach/hurd/connect.c b/sysdeps/mach/hurd/connect.c index b9b9fddf8b..2b03b879aa 100644 --- a/sysdeps/mach/hurd/connect.c +++ b/sysdeps/mach/hurd/connect.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "hurd/hurdsocket.h" /* Open a connection on socket FD to peer at ADDR (which LEN bytes long). @@ -34,13 +35,17 @@ __connect (int fd, __CONST_SOCKADDR_ARG addrarg, socklen_t len) error_t err; addr_port_t aport; const struct sockaddr_un *addr = addrarg.__sockaddr_un__; + int cancel_oldtype; if (addr->sun_family == AF_LOCAL) { char *name = _hurd_sun_path_dupa (addr, len); /* For the local domain, we must look up the name as a file and talk to it with the ifsock protocol. */ - file_t file = __file_name_lookup (name, 0, 0); + file_t file; + cancel_oldtype = LIBC_CANCEL_ASYNC(); + file = __file_name_lookup (name, 0, 0); + LIBC_CANCEL_RESET (cancel_oldtype); if (file == MACH_PORT_NULL) return -1; err = __ifsock_getsockaddr (file, &aport); @@ -54,7 +59,7 @@ __connect (int fd, __CONST_SOCKADDR_ARG addrarg, socklen_t len) else err = EIEIO; - err = HURD_DPORT_USE (fd, + err = HURD_DPORT_USE_CANCEL (fd, ({ if (err) err = __socket_create_address (port, @@ -63,7 +68,9 @@ __connect (int fd, __CONST_SOCKADDR_ARG addrarg, socklen_t len) &aport); if (! err) { + cancel_oldtype = LIBC_CANCEL_ASYNC(); err = __socket_connect (port, aport); + LIBC_CANCEL_RESET (cancel_oldtype); __mach_port_deallocate (__mach_task_self (), aport); } diff --git a/sysdeps/mach/hurd/fdatasync.c b/sysdeps/mach/hurd/fdatasync.c index 797fcf6a88..8ccda0a0b3 100644 --- a/sysdeps/mach/hurd/fdatasync.c +++ b/sysdeps/mach/hurd/fdatasync.c @@ -19,12 +19,18 @@ #include #include #include +#include /* Make all changes done to FD's file data actually appear on disk. */ int fdatasync (int fd) { - error_t err = HURD_DPORT_USE (fd, __file_sync (port, 1, 1)); + error_t err; + int cancel_oldtype; + + cancel_oldtype = LIBC_CANCEL_ASYNC(); + err = HURD_DPORT_USE_CANCEL (fd, __file_sync (port, 1, 1)); + LIBC_CANCEL_RESET (cancel_oldtype); if (err) { if (err == EOPNOTSUPP) diff --git a/sysdeps/mach/hurd/fsync.c b/sysdeps/mach/hurd/fsync.c index 85aa992db2..0b2a09dcf8 100644 --- a/sysdeps/mach/hurd/fsync.c +++ b/sysdeps/mach/hurd/fsync.c @@ -19,12 +19,18 @@ #include #include #include +#include /* Make all changes done to FD actually appear on disk. */ int fsync (int fd) { - error_t err = HURD_DPORT_USE (fd, __file_sync (port, 1, 0)); + error_t err; + int cancel_oldtype; + + cancel_oldtype = LIBC_CANCEL_ASYNC(); + err = HURD_DPORT_USE_CANCEL (fd, __file_sync (port, 1, 0)); + LIBC_CANCEL_RESET (cancel_oldtype); if (err) { if (err == EOPNOTSUPP) diff --git a/sysdeps/mach/hurd/ioctl.c b/sysdeps/mach/hurd/ioctl.c index a9a148f1e3..4c0e54b038 100644 --- a/sysdeps/mach/hurd/ioctl.c +++ b/sysdeps/mach/hurd/ioctl.c @@ -27,6 +27,7 @@ #include #include #include +#include #include @@ -269,7 +270,15 @@ __ioctl (int fd, unsigned long int request, ...) /* Marshal the arguments into the request message and make the RPC. This wrapper function handles EBACKGROUND returns, turning them into either SIGTTOU or EIO. */ - err = HURD_DPORT_USE (fd, _hurd_ctty_output (port, ctty, send_rpc)); + if (request == TIOCDRAIN) + { + /* This is a cancellation point. */ + int cancel_oldtype = LIBC_CANCEL_ASYNC(); + err = HURD_DPORT_USE_CANCEL (fd, _hurd_ctty_output (port, ctty, send_rpc)); + LIBC_CANCEL_RESET (cancel_oldtype); + } + else + err = HURD_DPORT_USE (fd, _hurd_ctty_output (port, ctty, send_rpc)); #ifdef MACH_MSG_TYPE_BIT t = (mach_msg_type_t *) msg.data; diff --git a/sysdeps/mach/hurd/msync.c b/sysdeps/mach/hurd/msync.c index cec467eb7f..1820190dbe 100644 --- a/sysdeps/mach/hurd/msync.c +++ b/sysdeps/mach/hurd/msync.c @@ -19,6 +19,7 @@ #include #include #include +#include #include @@ -44,6 +45,7 @@ msync (void *addr, size_t length, int flags) vm_offset_t offset; kern_return_t err; + int cancel_oldtype; if (flags & (MS_SYNC | MS_ASYNC) == (MS_SYNC | MS_ASYNC)) return __hurd_fail (EINVAL); @@ -77,8 +79,10 @@ msync (void *addr, size_t length, int flags) else sync_len = len; + cancel_oldtype = LIBC_CANCEL_ASYNC(); err = __vm_object_sync (obj, cur - begin + offset, sync_len, should_flush, 1, should_iosync); + LIBC_CANCEL_RESET (cancel_oldtype); __mach_port_deallocate (__mach_task_self (), obj); if (err) diff --git a/sysdeps/mach/hurd/sigsuspend.c b/sysdeps/mach/hurd/sigsuspend.c index 38f095ef09..ed98104dce 100644 --- a/sysdeps/mach/hurd/sigsuspend.c +++ b/sysdeps/mach/hurd/sigsuspend.c @@ -20,6 +20,7 @@ #include #include #include +#include /* Change the set of blocked signals to SET, wait until a signal arrives, and restore the set of blocked signals. */ @@ -30,6 +31,7 @@ __sigsuspend (const sigset_t *set) sigset_t newmask, oldmask, pending; mach_port_t wait; mach_msg_header_t msg; + int cancel_oldtype; if (set != NULL) /* Crash before locking. */ @@ -59,8 +61,11 @@ __sigsuspend (const sigset_t *set) __msg_sig_post (_hurd_msgport, 0, 0, __mach_task_self ()); /* Wait for the signal thread's message. */ + + cancel_oldtype = LIBC_CANCEL_ASYNC(); __mach_msg (&msg, MACH_RCV_MSG, 0, sizeof (msg), wait, MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL); + LIBC_CANCEL_RESET (cancel_oldtype); __mach_port_destroy (__mach_task_self (), wait); /* Restore the old mask and check for pending signals again. */ diff --git a/sysdeps/mach/hurd/sigwait.c b/sysdeps/mach/hurd/sigwait.c index 53d2110983..48ccaf05fe 100644 --- a/sysdeps/mach/hurd/sigwait.c +++ b/sysdeps/mach/hurd/sigwait.c @@ -21,6 +21,7 @@ #include #include #include +#include /* Select any of pending signals from SET or wait for any to arrive. */ int @@ -33,6 +34,7 @@ __sigwait (const sigset_t *set, int *sig) jmp_buf buf; mach_port_t wait; mach_msg_header_t msg; + int cancel_oldtype; sighandler_t preempt_fun (struct hurd_signal_preemptor *pe, @@ -71,6 +73,7 @@ __sigwait (const sigset_t *set, int *sig) __sigemptyset (&mask); ss = _hurd_self_sigstate (); + cancel_oldtype = LIBC_CANCEL_ASYNC(); _hurd_sigstate_lock (ss); /* See if one of these signals is currently pending. */ @@ -128,6 +131,7 @@ __sigwait (const sigset_t *set, int *sig) all_done: _hurd_sigstate_unlock (ss); + LIBC_CANCEL_RESET (cancel_oldtype); __mach_port_destroy (__mach_task_self (), wait); *sig = signo; diff --git a/sysdeps/mach/msync.c b/sysdeps/mach/msync.c index e36a564ef4..f72222b57b 100644 --- a/sysdeps/mach/msync.c +++ b/sysdeps/mach/msync.c @@ -20,6 +20,7 @@ #include #include #include +#include /* Some Mach variants have vm_msync and some don't. Those that have it define the VM_SYNC_* bits when we include . */ @@ -37,6 +38,7 @@ msync (void *addr, size_t len, int flags) { vm_sync_t sync_flags = 0; kern_return_t err; + int cancel_oldtype; if (flags & MS_SYNC) sync_flags |= VM_SYNC_SYNCHRONOUS; @@ -45,8 +47,11 @@ msync (void *addr, size_t len, int flags) if (flags & MS_INVALIDATE) sync_flags |= VM_SYNC_INVALIDATE; - if (err = __vm_msync (__mach_task_self (), - (vm_address_t) addr, (vm_size_t) len, sync_flags)) + cancel_oldtype = LIBC_CANCEL_ASYNC(); + err = __vm_msync (__mach_task_self (), + (vm_address_t) addr, (vm_size_t) len, sync_flags); + LIBC_CANCEL_RESET (cancel_oldtype); + if (err) { errno = err; return -1; diff --git a/sysdeps/mach/sleep.c b/sysdeps/mach/sleep.c index de58bd18c4..9de9de1ae9 100644 --- a/sysdeps/mach/sleep.c +++ b/sysdeps/mach/sleep.c @@ -19,6 +19,7 @@ #include #include #include +#include /* Make the process sleep for SECONDS seconds, or until a signal arrives and is not ignored. The function returns the number of seconds less @@ -30,12 +31,15 @@ __sleep (unsigned int seconds) { time_t before, after; mach_port_t recv; + int cancel_oldtype; recv = __mach_reply_port (); before = time_now (); + cancel_oldtype = LIBC_CANCEL_ASYNC(); (void) __mach_msg (NULL, MACH_RCV_MSG|MACH_RCV_TIMEOUT|MACH_RCV_INTERRUPT, 0, 0, recv, seconds * 1000, MACH_PORT_NULL); + LIBC_CANCEL_RESET (cancel_oldtype); after = time_now (); __mach_port_destroy (__mach_task_self (), recv); diff --git a/sysdeps/mach/usleep.c b/sysdeps/mach/usleep.c index d53eb04a51..75514b2e35 100644 --- a/sysdeps/mach/usleep.c +++ b/sysdeps/mach/usleep.c @@ -19,12 +19,14 @@ #include #include #include +#include /* Sleep USECONDS microseconds, or until a previously set timer goes off. */ int usleep (useconds_t useconds) { mach_port_t recv; + int cancel_oldtype; useconds_t useconds_up = useconds + 999; if (useconds_up < useconds) @@ -32,8 +34,10 @@ usleep (useconds_t useconds) recv = __mach_reply_port (); + cancel_oldtype = LIBC_CANCEL_ASYNC(); (void) __mach_msg (NULL, MACH_RCV_MSG|MACH_RCV_TIMEOUT|MACH_RCV_INTERRUPT, 0, 0, recv, useconds_up / 1000, MACH_PORT_NULL); + LIBC_CANCEL_RESET (cancel_oldtype); __mach_port_destroy (mach_task_self (), recv); return 0;