From patchwork Wed Mar 1 16:23:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Bugaev X-Patchwork-Id: 1750139 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=KRx2nbBq; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PRfhF735Dz1yWy for ; Thu, 2 Mar 2023 03:24:29 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 55E1938582A1 for ; Wed, 1 Mar 2023 16:24:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 55E1938582A1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1677687867; bh=2LaS2dprSq/EnTuoQWAMoWNJBkal3U7kbCWK8NJpaF4=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=KRx2nbBq9M5i3g0Ft3JpBPJxJk4DY5g4RqPVp2VSrC5M8zt/bVJaIo0ZPSYVEDKAG vI559yT0zZ4fluyMt922mKlgx77Hlpte6NjE858lls02JBCzOOGdnn6tOi6J6ssUzO QTcWKNXOkm8uI0Vam+Q7PJBPdgrj4JoBYKeFISUo= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-lj1-x233.google.com (mail-lj1-x233.google.com [IPv6:2a00:1450:4864:20::233]) by sourceware.org (Postfix) with ESMTPS id 2C7F03850871 for ; Wed, 1 Mar 2023 16:24:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2C7F03850871 Received: by mail-lj1-x233.google.com with SMTP id y14so14580620ljq.4 for ; Wed, 01 Mar 2023 08:24:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677687844; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2LaS2dprSq/EnTuoQWAMoWNJBkal3U7kbCWK8NJpaF4=; b=i71sJyYp4tjdaG+fFysARfM4qmu9pMHxnwXUwXCpGGm3Ic9LCjnpxlPZl9wdGzGlQF fsAP/Q9n90zSHdsoBXxFwtP9du5CgfkbqDvn8tJFSOEsmhhzBxrH9HHsEJbNQidIHwaq RgxxmqZdD0Y1xKV9v4kTNsoy+CLxGrI/sEu55gesck2UObvY5KFz3Pnp4Emgsb0no81Z QjNxhQv0Djm9ErGhPvcvPUTFV3SH0YQZ/fwUFJ1SHwUc2P4DUwx8CkITaQiyQiKpXTWe bgOIn/pIGxpVh9OGtRuHe2KaKkPTceiHefBPd+8Q6AulgprjR/5TKflBrm3lw707/wRc 6sXg== X-Gm-Message-State: AO0yUKW8H6Bt3pbDsPYiGzozOMiXRBu3X/eJzGuYpUDEjLdtCu/L5Hww o4SOGteOIc5nGgmB6olLOOu4+iiayvw= X-Google-Smtp-Source: AK7set9xGhw/tojW1dukIykegw263k9dQqD2SU/Vm/j1zyV5tGFPWLGlTaR8ap/fScbnLbFkQ98wNA== X-Received: by 2002:a2e:a0d4:0:b0:295:a716:cb12 with SMTP id f20-20020a2ea0d4000000b00295a716cb12mr2112799ljm.30.1677687844362; Wed, 01 Mar 2023 08:24:04 -0800 (PST) Received: from surface-pro-6.. ([194.190.106.50]) by smtp.gmail.com with ESMTPSA id p6-20020a2ea4c6000000b002934fce87bfsm1703626ljm.108.2023.03.01.08.24.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Mar 2023 08:24:03 -0800 (PST) To: Samuel Thibault , bug-hurd@gnu.org, libc-alpha@sourceware.org Cc: Sergey Bugaev Subject: [PATCH 1/2] hurd: Remove the ecx kludge Date: Wed, 1 Mar 2023 19:23:54 +0300 Message-Id: <20230301162355.426887-1-bugaevc@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230301092421.x6derf2if5tc3u5u@begin> References: <20230301092421.x6derf2if5tc3u5u@begin> MIME-Version: 1.0 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: , X-Patchwork-Original-From: Sergey Bugaev via Libc-alpha From: Sergey Bugaev Reply-To: Sergey Bugaev Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" "We don't need it any more" The INTR_MSG_TRAP macro in intr-msg.h used to play little trick with the stack pointer: it would temporarily save the "real" stack pointer into ecx, while setting esp to point to just before the message buffer, and then invoke the mach_msg trap. This way, INTR_MSG_TRAP reused the on-stack arguments laid out for the containing call of _hurd_intr_rpc_mach_msg (), passing them to the mach_msg trap directly. This, however, required special support in hurdsig.c and trampoline.c, since they now had to recognize when a thread is inside the piece of code where esp doesn't point to the real tip of the stack, and handle this situation specially. Commit 1d20f33ff4fb634310f27493b7b87d0b20f4a0b0 has removed the actual temporary change of esp by actually re-pushing mach_msg arguments onto the stack, and popping them back at end. It did not, however, deal with the rest of "the ecx kludge" code in other files, resulting in potential crashes if a signal arrives in the middle of pushing arguments onto the stack. Fix that by removing "the ecx kludge". Instead, when we want a thread to skip the RPC, but cannot make just make it jump to after the trap since it's not done adjusting the stack yet, set the SYSRETURN register to MACH_SEND_INTERRUPTED (as we do anyway), and rely on the thread itself for detecting this case and skipping the RPC. This simplifies things somewhat and paves the way for a future x86_64 port of this code. Signed-off-by: Sergey Bugaev --- hurd/hurdsig.c | 18 +++++++++---- sysdeps/mach/hurd/i386/intr-msg.h | 40 +++++++++++++---------------- sysdeps/mach/hurd/i386/trampoline.c | 21 --------------- 3 files changed, 31 insertions(+), 48 deletions(-) diff --git a/hurd/hurdsig.c b/hurd/hurdsig.c index ea79ffb5..5ff0a91f 100644 --- a/hurd/hurdsig.c +++ b/hurd/hurdsig.c @@ -415,6 +415,7 @@ _hurdsig_abort_rpcs (struct hurd_sigstate *ss, int signo, int sigthread, void (*reply) (void)) { extern const void _hurd_intr_rpc_msg_about_to; + extern const void _hurd_intr_rpc_msg_setup_done; extern const void _hurd_intr_rpc_msg_in_trap; mach_port_t rcv_port = MACH_PORT_NULL; mach_port_t intr_port; @@ -434,11 +435,18 @@ _hurdsig_abort_rpcs (struct hurd_sigstate *ss, int signo, int sigthread, && state->basic.PC < (uintptr_t) &_hurd_intr_rpc_msg_in_trap) { /* The thread is about to do the RPC, but hasn't yet entered - mach_msg. Mutate the thread's state so it knows not to try - the RPC. */ - INTR_MSG_BACK_OUT (&state->basic); - MACHINE_THREAD_STATE_SET_PC (&state->basic, - &_hurd_intr_rpc_msg_in_trap); + mach_msg. Importantly, it may have already checked ss->cancel for + the last time before doing the RPC, so setting that is not enough + to make it not enter mach_msg. Instead, mutate the thread's state + so it knows not to try the RPC. + + If the thread is past _hurd_intr_rpc_msg_setup_done, just make it + jump to after the trap, since we know it's safe to do so. Otherwise, + we know that the thread is yet to check for the MACH_SEND_INTERRUPTED + value we set below, and will skip the trap by itself. */ + if (state->basic.PC >= (uintptr_t) &_hurd_intr_rpc_msg_setup_done) + MACHINE_THREAD_STATE_SET_PC (&state->basic, + &_hurd_intr_rpc_msg_in_trap); state->basic.SYSRETURN = MACH_SEND_INTERRUPTED; *state_change = 1; } diff --git a/sysdeps/mach/hurd/i386/intr-msg.h b/sysdeps/mach/hurd/i386/intr-msg.h index 29cb4620..21088fa8 100644 --- a/sysdeps/mach/hurd/i386/intr-msg.h +++ b/sysdeps/mach/hurd/i386/intr-msg.h @@ -25,10 +25,13 @@ ({ \ error_t err; \ asm (".globl _hurd_intr_rpc_msg_about_to\n" \ - ".globl _hurd_intr_rpc_msg_cx_sp\n" \ - ".globl _hurd_intr_rpc_msg_do_trap\n" \ + ".globl _hurd_intr_rpc_msg_setup_done\n" \ ".globl _hurd_intr_rpc_msg_in_trap\n" \ - ".globl _hurd_intr_rpc_msg_sp_restored\n" \ + /* Clear eax before we do the check for cancel below. This is to + detect eax being set to non-zero (actually MACH_SEND_INTERRUPTED) + from the outside (namely, _hurdsig_abort_rpcs), which signals us + to skip the trap we were about to enter. */ \ + " xorl %0, %0\n" \ "_hurd_intr_rpc_msg_about_to:" \ /* We need to make a last check of cancel, in case we got interrupted right before _hurd_intr_rpc_msg_about_to. */ \ @@ -36,10 +39,10 @@ " jz _hurd_intr_rpc_msg_do\n" \ /* We got interrupted, note so and return EINTR. */ \ " movl $0, %3\n" \ - " movl %6, %%eax\n" \ + " movl %6, %0\n" \ " jmp _hurd_intr_rpc_msg_sp_restored\n" \ "_hurd_intr_rpc_msg_do:" \ - /* Ok, push the mach_msg_trap arguments. */ \ + /* Ok, push the mach_msg_trap arguments and a fake return address. */ \ " pushl 24(%4)\n" \ " pushl %2\n" \ " pushl 16(%4)\n" \ @@ -48,9 +51,14 @@ " pushl %1\n" \ " pushl (%4)\n" \ " pushl $0\n" \ - /* TODO: remove this ecx kludge, we don't need it any more */ \ - " movl %%esp, %%ecx\n" \ - "_hurd_intr_rpc_msg_cx_sp: movl $-25, %%eax\n" \ + "_hurd_intr_rpc_msg_setup_done:" \ + /* From here on, it is safe to make us jump over the syscall. Now + check if we have been told to skip the syscall while running + the above. */ \ + " test %0, %0\n" \ + " jnz _hurd_intr_rpc_msg_in_trap\n" \ + /* Do the actual syscall. */ \ + " movl $-25, %%eax\n" \ "_hurd_intr_rpc_msg_do_trap: lcall $7, $0 # status in %0\n" \ "_hurd_intr_rpc_msg_in_trap:" \ /* Ok, clean the arguments and update OPTION and TIMEOUT. */ \ @@ -60,22 +68,10 @@ " popl %2\n" \ " addl $4, %%esp\n" \ "_hurd_intr_rpc_msg_sp_restored:" \ - : "=a" (err), "+r" (option), "+r" (timeout), "=m" (*intr_port_p) \ - : "r" (&msg), "m" (*cancel_p), "i" (EINTR) \ - : "ecx"); \ + : "=&a" (err), "+r" (option), "+r" (timeout), "=m" (*intr_port_p) \ + : "r" (&msg), "m" (*cancel_p), "i" (EINTR)); \ err; \ }) - - -static void inline -INTR_MSG_BACK_OUT (struct i386_thread_state *state) -{ - extern const void _hurd_intr_rpc_msg_cx_sp; - if (state->eip >= (natural_t) &_hurd_intr_rpc_msg_cx_sp) - state->uesp = state->ecx; - else - state->ecx = state->uesp; -} #include "hurdfault.h" diff --git a/sysdeps/mach/hurd/i386/trampoline.c b/sysdeps/mach/hurd/i386/trampoline.c index 42c9d732..8f481e79 100644 --- a/sysdeps/mach/hurd/i386/trampoline.c +++ b/sysdeps/mach/hurd/i386/trampoline.c @@ -89,8 +89,6 @@ _hurd_setup_sighandler (struct hurd_sigstate *ss, const struct sigaction *action void trampoline (void); void rpc_wait_trampoline (void); void firewall (void); - extern const void _hurd_intr_rpc_msg_cx_sp; - extern const void _hurd_intr_rpc_msg_sp_restored; void *volatile sigsp; struct sigcontext *scp; struct @@ -146,25 +144,6 @@ _hurd_setup_sighandler (struct hurd_sigstate *ss, const struct sigaction *action interrupted RPC frame. */ state->basic.esp = state->basic.uesp; - /* This code has intimate knowledge of the special mach_msg system call - done in intr-msg.c; that code does (see intr-msg.h): - movl %esp, %ecx - leal ARGS, %esp - _hurd_intr_rpc_msg_cx_sp: movl $-25, %eax - _hurd_intr_rpc_msg_do_trap: lcall $7, $0 - _hurd_intr_rpc_msg_in_trap: movl %ecx, %esp - _hurd_intr_rpc_msg_sp_restored: - We must check for the window during which %esp points at the - mach_msg arguments. The space below until %ecx is used by - the _hurd_intr_rpc_mach_msg frame, and must not be clobbered. */ - if (state->basic.eip >= (int) &_hurd_intr_rpc_msg_cx_sp - && state->basic.eip < (int) &_hurd_intr_rpc_msg_sp_restored) - /* The SP now points at the mach_msg args, but there is more stack - space used below it. The real SP is saved in %ecx; we must push the - new frame below there (if not on the altstack), and restore that value as - the SP on sigreturn. */ - state->basic.uesp = state->basic.ecx; - if ((action->sa_flags & SA_ONSTACK) && !(ss->sigaltstack.ss_flags & (SS_DISABLE|SS_ONSTACK))) { From patchwork Wed Mar 1 16:23:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Bugaev X-Patchwork-Id: 1750140 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=qsPkEy+a; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PRfhG16m6z245t for ; Thu, 2 Mar 2023 03:24:30 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8735138515FF for ; Wed, 1 Mar 2023 16:24:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8735138515FF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1677687867; bh=5Jj5vt0yqWJu92FBHxUuuLiff5v7a15NVQtRlvmAXnU=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=qsPkEy+aemfsYYDmdm5qhEnjNDoP54hWDEjvulrqsoGJPBIHksQJ0chqk0dpLYiA5 j6sLupy8glNcdZU+JJBMwnK2xBXNI5hiRicYf7/jsL/++6Rib5ewqj9jAqQYcOaYmQ DnVdzX4mKddXNA+0h7lMepfiBLCdotVNcsAKmanc= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-lj1-x230.google.com (mail-lj1-x230.google.com [IPv6:2a00:1450:4864:20::230]) by sourceware.org (Postfix) with ESMTPS id 975D93850877 for ; Wed, 1 Mar 2023 16:24:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 975D93850877 Received: by mail-lj1-x230.google.com with SMTP id by8so14557431ljb.7 for ; Wed, 01 Mar 2023 08:24:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677687846; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5Jj5vt0yqWJu92FBHxUuuLiff5v7a15NVQtRlvmAXnU=; b=724I5nHOEElNq3/hNrL53Lwp4RknYSKAZmGdLRlUCR8fsKcQnC6LukHI5jrL0VqICz 3drCPqG40hSVchccdCXpJbYKc58glqIgs01MMHgQPe4B7DTSEHXqNJCpqhMx6lxZIgyz am/7CqEuRt1ikrEunYFeueB61piEVkVtRrQc37YlJTHZV+ui14gqx1JbewTrFpue4fxb iqDVYu8mgbPhZxlTAaklf50NTYdXDoeJLTEmTufueqKG6asfmJukTTfrWZcqpACCyHJe bGz10nlH+HEyzqopRoKV+3Hb9YJzJaMSIERcuPIuB74BJNbiB9zodfyEdi8kmTfIY1we VQmQ== X-Gm-Message-State: AO0yUKW7MTjm6yZ1h63p6W85yLFQWe9+W+sUR4YNRCLDBBc3vekprSzR QhUkqq3F7WihuKnD52nuZY6oQ1nWz9E= X-Google-Smtp-Source: AK7set/UI1zs2htN4/Mv3+F5iwrXX1deWLJLu0EhRUJgwaoMe+7aRp8vEHFBdzmUExSNiANgAKqqIg== X-Received: by 2002:a2e:c49:0:b0:295:a542:8b47 with SMTP id o9-20020a2e0c49000000b00295a5428b47mr2106857ljd.8.1677687845939; Wed, 01 Mar 2023 08:24:05 -0800 (PST) Received: from surface-pro-6.. ([194.190.106.50]) by smtp.gmail.com with ESMTPSA id p6-20020a2ea4c6000000b002934fce87bfsm1703626ljm.108.2023.03.01.08.24.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Mar 2023 08:24:05 -0800 (PST) To: Samuel Thibault , bug-hurd@gnu.org, libc-alpha@sourceware.org Cc: Sergey Bugaev Subject: [PATCH 2/2] hurd: Fix some broken indentation Date: Wed, 1 Mar 2023 19:23:55 +0300 Message-Id: <20230301162355.426887-2-bugaevc@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230301162355.426887-1-bugaevc@gmail.com> References: <20230301092421.x6derf2if5tc3u5u@begin> <20230301162355.426887-1-bugaevc@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: , X-Patchwork-Original-From: Sergey Bugaev via Libc-alpha From: Sergey Bugaev Reply-To: Sergey Bugaev Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" Also, fix a couple of typos. No functional change. Signed-off-by: Sergey Bugaev --- hurd/hurdsig.c | 101 +++++++++++++++++++++++++------------------------ 1 file changed, 51 insertions(+), 50 deletions(-) diff --git a/hurd/hurdsig.c b/hurd/hurdsig.c index 5ff0a91f..85bd46b5 100644 --- a/hurd/hurdsig.c +++ b/hurd/hurdsig.c @@ -202,7 +202,7 @@ _hurd_sigstate_unlock (struct hurd_sigstate *ss) } libc_hidden_def (_hurd_sigstate_set_global_rcv) -/* Retreive a thread's full set of pending signals, including the global +/* Retrieve a thread's full set of pending signals, including the global ones if appropriate. SS must be locked. */ sigset_t _hurd_sigstate_pending (const struct hurd_sigstate *ss) @@ -233,7 +233,7 @@ sigstate_clear_pending (struct hurd_sigstate *ss, int signo) libc_hidden_def (_hurd_sigstate_lock) libc_hidden_def (_hurd_sigstate_unlock) -/* Retreive a thread's action vector. SS must be locked. */ +/* Retrieve a thread's action vector. SS must be locked. */ struct sigaction * _hurd_sigstate_actions (struct hurd_sigstate *ss) { @@ -451,54 +451,55 @@ _hurdsig_abort_rpcs (struct hurd_sigstate *ss, int signo, int sigthread, *state_change = 1; } else if (state->basic.PC == (uintptr_t) &_hurd_intr_rpc_msg_in_trap - /* The thread was blocked in the system call. After thread_abort, - the return value register indicates what state the RPC was in - when interrupted. */ - && state->basic.SYSRETURN == MACH_RCV_INTERRUPTED) - { - /* The RPC request message was sent and the thread was waiting for - the reply message; now the message receive has been aborted, so - the mach_msg call will return MACH_RCV_INTERRUPTED. We must tell - the server to interrupt the pending operation. The thread must - wait for the reply message before running the signal handler (to - guarantee that the operation has finished being interrupted), so - our nonzero return tells the trampoline code to finish the message - receive operation before running the handler. */ - - mach_port_t *reply = interrupted_reply_port_location (ss->thread, - state, - sigthread); - error_t err = __interrupt_operation (intr_port, _hurdsig_interrupt_timeout); - - if (err) - { - if (reply) - { - /* The interrupt didn't work. - Destroy the receive right the thread is blocked on. */ - __mach_port_destroy (__mach_task_self (), *reply); - *reply = MACH_PORT_NULL; - } - - /* The system call return value register now contains - MACH_RCV_INTERRUPTED; when mach_msg resumes, it will retry the - call. Since we have just destroyed the receive right, the - retry will fail with MACH_RCV_INVALID_NAME. Instead, just - change the return value here to EINTR so mach_msg will not - retry and the EINTR error code will propagate up. */ - state->basic.SYSRETURN = EINTR; - *state_change = 1; - } - else if (reply) - rcv_port = *reply; - - /* All threads whose RPCs were interrupted by the interrupt_operation - call above will retry their RPCs unless we clear SS->intr_port. - So we clear it for the thread taking a signal when SA_RESTART is - clear, so that its call returns EINTR. */ - if (! signo || !(_hurd_sigstate_actions (ss) [signo].sa_flags & SA_RESTART)) - ss->intr_port = MACH_PORT_NULL; - } + /* The thread was blocked in the system call. After thread_abort, + the return value register indicates what state the RPC was in + when interrupted. */ + && state->basic.SYSRETURN == MACH_RCV_INTERRUPTED) + { + /* The RPC request message was sent and the thread was waiting for the + reply message; now the message receive has been aborted, so the + mach_msg call will return MACH_RCV_INTERRUPTED. We must tell the + server to interrupt the pending operation. The thread must wait for + the reply message before running the signal handler (to guarantee that + the operation has finished being interrupted), so our nonzero return + tells the trampoline code to finish the message receive operation + before running the handler. */ + + mach_port_t *reply = interrupted_reply_port_location (ss->thread, + state, + sigthread); + error_t err = __interrupt_operation (intr_port, + _hurdsig_interrupt_timeout); + + if (err) + { + if (reply) + { + /* The interrupt didn't work. + Destroy the receive right the thread is blocked on. */ + __mach_port_destroy (__mach_task_self (), *reply); + *reply = MACH_PORT_NULL; + } + + /* The system call return value register now contains + MACH_RCV_INTERRUPTED; when mach_msg resumes, it will retry the + call. Since we have just destroyed the receive right, the retry + will fail with MACH_RCV_INVALID_NAME. Instead, just change the + return value here to EINTR so mach_msg will not retry and the + EINTR error code will propagate up. */ + state->basic.SYSRETURN = EINTR; + *state_change = 1; + } + else if (reply) + rcv_port = *reply; + + /* All threads whose RPCs were interrupted by the interrupt_operation + call above will retry their RPCs unless we clear SS->intr_port. So we + clear it for the thread taking a signal when SA_RESTART is clear, so + that its call returns EINTR. */ + if (! signo || !(_hurd_sigstate_actions (ss) [signo].sa_flags & SA_RESTART)) + ss->intr_port = MACH_PORT_NULL; + } return rcv_port; }