From patchwork Sat Dec 26 17:45:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 41559 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 E5C123850405; Sat, 26 Dec 2020 17:45:36 +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 32F97386102C for ; Sat, 26 Dec 2020 17:45:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 32F97386102C 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 CD2234B0; Sat, 26 Dec 2020 18:45:31 +0100 (CET) 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 bQj0zj6sl5_m; Sat, 26 Dec 2020 18:45:31 +0100 (CET) Received: from function.youpi.perso.aquilenet.fr (2a01cb008800c5009eb6d0fffe88c3c7.ipv6.abo.wanadoo.fr [IPv6:2a01:cb00:8800:c500:9eb6:d0ff:fe88:c3c7]) by hera.aquilenet.fr (Postfix) with ESMTPSA id E2652CC; Sat, 26 Dec 2020 18:45:30 +0100 (CET) Received: from samy by function.youpi.perso.aquilenet.fr with local (Exim 4.94) (envelope-from ) id 1ktDdC-000ey4-93; Sat, 26 Dec 2020 18:45:30 +0100 From: Samuel Thibault To: libc-alpha@sourceware.org Subject: [hurd, commited] hurd: set sigaction for signal preemptors in arch-independent file Date: Sat, 26 Dec 2020 18:45:29 +0100 Message-Id: <20201226174529.157437-1-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 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" Instead of having the arch-specific trampoline setup code detect whether preemption happened or not, we'd rather pass it the sigaction. In the future, this may also allow to change sa_flags from post_signal(). --- hurd/hurd/signal.h | 3 ++- hurd/hurdsig.c | 22 ++++++++++++++++------ sysdeps/mach/hurd/i386/trampoline.c | 17 ++--------------- 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/hurd/hurd/signal.h b/hurd/hurd/signal.h index 2a0aa20b72..b31463ccfc 100644 --- a/hurd/hurd/signal.h +++ b/hurd/hurd/signal.h @@ -327,7 +327,8 @@ extern void _hurd_internal_post_signal (struct hurd_sigstate *ss, struct machine_thread_all_state; extern struct sigcontext * -_hurd_setup_sighandler (struct hurd_sigstate *ss, __sighandler_t handler, +_hurd_setup_sighandler (struct hurd_sigstate *ss, const struct sigaction *action, + __sighandler_t handler, int signo, struct hurd_signal_detail *detail, int rpc_wait, struct machine_thread_all_state *state); diff --git a/hurd/hurdsig.c b/hurd/hurdsig.c index 6fdbf383ee..dcc1da35e5 100644 --- a/hurd/hurdsig.c +++ b/hurd/hurdsig.c @@ -624,6 +624,13 @@ post_signal (struct hurd_sigstate *ss, enum { stop, ignore, core, term, handle } act; int ss_suspended; + /* sigaction for preemptors */ + struct sigaction preempt_sigaction = { + .sa_flags = SA_RESTART + }; + + struct sigaction *action; + /* Mark the signal as pending. */ void mark_pending (void) { @@ -780,12 +787,17 @@ post_signal (struct hurd_sigstate *ss, /* Ignore the signal altogether. */ act = ignore; else if (handler != SIG_ERR) - /* Run the preemption-provided handler. */ - act = handle; + { + /* Run the preemption-provided handler. */ + action = &preempt_sigaction; + act = handle; + } else { /* No preemption. Do normal handling. */ + action = & _hurd_sigstate_actions (ss) [signo]; + if (!untraced && __sigismember (&_hurdsig_traced, signo)) { /* We are being traced. Stop to tell the debugger of the signal. */ @@ -800,7 +812,7 @@ post_signal (struct hurd_sigstate *ss, return NULL; } - handler = _hurd_sigstate_actions (ss) [signo].sa_handler; + handler = action->sa_handler; if (handler == SIG_DFL) /* Figure out the default action for this signal. */ @@ -1072,7 +1084,7 @@ post_signal (struct hurd_sigstate *ss, /* Call the machine-dependent function to set the thread up to run the signal handler, and preserve its old context. */ - scp = _hurd_setup_sighandler (ss, handler, signo, detail, + scp = _hurd_setup_sighandler (ss, action, handler, signo, detail, wait_for_reply, &thread_state); if (scp == NULL) goto sigbomb; @@ -1111,8 +1123,6 @@ post_signal (struct hurd_sigstate *ss, } } - struct sigaction *action = & _hurd_sigstate_actions (ss) [signo]; - /* Backdoor extra argument to signal handler. */ scp->sc_error = detail->error; diff --git a/sysdeps/mach/hurd/i386/trampoline.c b/sysdeps/mach/hurd/i386/trampoline.c index 1777d0769d..a47bbe9667 100644 --- a/sysdeps/mach/hurd/i386/trampoline.c +++ b/sysdeps/mach/hurd/i386/trampoline.c @@ -80,7 +80,8 @@ static void fill_ucontext (ucontext_t *uc, const struct sigcontext *sc) } struct sigcontext * -_hurd_setup_sighandler (struct hurd_sigstate *ss, __sighandler_t handler, +_hurd_setup_sighandler (struct hurd_sigstate *ss, const struct sigaction *action, + __sighandler_t handler, int signo, struct hurd_signal_detail *detail, volatile int rpc_wait, struct machine_thread_all_state *state) @@ -90,7 +91,6 @@ _hurd_setup_sighandler (struct hurd_sigstate *ss, __sighandler_t handler, void firewall (void); extern const void _hurd_intr_rpc_msg_cx_sp; extern const void _hurd_intr_rpc_msg_sp_restored; - const struct sigaction *action; void *volatile sigsp; struct sigcontext *scp; struct @@ -123,11 +123,6 @@ _hurd_setup_sighandler (struct hurd_sigstate *ss, __sighandler_t handler, siginfo_t siginfo; } *stackframe; - /* sigaction for preemptors */ - static const struct sigaction legacy_sigaction = { - .sa_flags = SA_RESTART - }; - if (ss->context) { /* We have a previous sigcontext that sigreturn was about @@ -170,14 +165,6 @@ _hurd_setup_sighandler (struct hurd_sigstate *ss, __sighandler_t handler, the SP on sigreturn. */ state->basic.uesp = state->basic.ecx; - action = & _hurd_sigstate_actions (ss) [signo]; - if ( (action->sa_flags & SA_SIGINFO) - && handler != (__sighandler_t) action->sa_sigaction - || !(action->sa_flags & SA_SIGINFO) - && handler != action->sa_handler) - /* A signal preemptor took over, use legacy semantic. */ - action = &legacy_sigaction; - if ((action->sa_flags & SA_ONSTACK) && !(ss->sigaltstack.ss_flags & (SS_DISABLE|SS_ONSTACK))) {