From patchwork Mon Apr 21 18:02:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 110766 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 439CD3858CDB for ; Mon, 21 Apr 2025 18:03:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 439CD3858CDB X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from sonata.ens-lyon.org (domu-toccata.ens-lyon.fr [140.77.166.138]) by sourceware.org (Postfix) with ESMTPS id 6D4223858D37 for ; Mon, 21 Apr 2025 18:02:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6D4223858D37 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=ens-lyon.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=bounce.ens-lyon.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6D4223858D37 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=140.77.166.138 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1745258579; cv=none; b=QeHMcEraAlz77PkM9t/5Ea6Jmy5eFOv1YlE/HzYHvE2dvICpcfBdxaVBR+tssXEahVNGd2EnboY/MCDNAzAi0mKqgTFcoJBn1RZisuS9JpnJS/Qr/rF6LGHOnm5PBYhD4O4/9ivfByClnGoJHQ/4NUP5SBhdcJqegXQqVd9pZ1o= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1745258579; c=relaxed/simple; bh=zlmGxwiLuzUvRdidIXdNhD6k9Dq1mtt4xhzW0qVi7hk=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=JOSzlvuCkyZC9NtUE93rjAIWh+I7dcxuSLfCXDRKo9ZBPZkyOEee7N+wOpJ0gH2YCIQoysKuF3+/VE9smxkRiB+XOWSOH0NJjrBjTfBM+VviKUFdcL6oNVhnv4v2wVE3YVHcGqbumV7nckqCr0U0dKGo6/WcunH8py05d4cAPFE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6D4223858D37 Received: from localhost (localhost [127.0.0.1]) by sonata.ens-lyon.org (Postfix) with ESMTP id 9FDC9A493C; Mon, 21 Apr 2025 20:02:58 +0200 (CEST) Received: from sonata.ens-lyon.org ([127.0.0.1]) by localhost (sonata.ens-lyon.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Bx1sZgGr5m8b; Mon, 21 Apr 2025 20:02:58 +0200 (CEST) Received: from begin (aamiens-653-1-40-48.w83-192.abo.wanadoo.fr [83.192.199.48]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by sonata.ens-lyon.org (Postfix) with ESMTPSA id 83D86A4938; Mon, 21 Apr 2025 20:02:58 +0200 (CEST) Received: from samy by begin with local (Exim 4.98.2) (envelope-from ) id 1u6vTu-0000000Ebb6-0JoX; Mon, 21 Apr 2025 20:02:58 +0200 From: Samuel Thibault To: libc-alpha@sourceware.org Cc: Samuel Thibault , commit-hurd@gnu.org Subject: [hurd, commited] hurd: Clear FP exceptions before calling signal handler Date: Mon, 21 Apr 2025 20:02:57 +0200 Message-ID: <20250421180257.3481109-1-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.47.2 MIME-Version: 1.0 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_PASS, 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.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org This avoids SIGFPE handlers (or code longjmp-ed to) getting disturbed by the exception that generated it. Note: gcc's unwinding depends on the rpc_wait_trampoline/trampoline exact code, so we here avoid breaking it. --- sysdeps/mach/hurd/x86/trampoline.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/sysdeps/mach/hurd/x86/trampoline.c b/sysdeps/mach/hurd/x86/trampoline.c index 02510b178c..6f23c567da 100644 --- a/sysdeps/mach/hurd/x86/trampoline.c +++ b/sysdeps/mach/hurd/x86/trampoline.c @@ -461,7 +461,10 @@ _hurd_setup_sighandler (struct hurd_sigstate *ss, const struct sigaction *action - in gdb: gdb/i386-gnu-tdep.c gnu_sigtramp_code. */ #ifdef __x86_64__ -asm ("rpc_wait_trampoline:\n" +asm ("trampoline:\n" + "fnclex\n" /* Clear any pending exception. */ + "jmp _trampoline\n" + "rpc_wait_trampoline:\n" /* This is the entry point when we have an RPC reply message to receive before running the handler. The MACH_MSG_SEND bit has already been cleared in the OPTION argument in our %rsi. The interrupted user @@ -480,7 +483,7 @@ asm ("rpc_wait_trampoline:\n" /* Switch to the signal stack. */ "movq %rbx, %rsp\n" - "trampoline:\n" + "_trampoline:\n" /* Entry point for running the handler normally. The arguments to the handler function are on the top of the stack, same as in the i386 version: @@ -506,7 +509,10 @@ asm ("rpc_wait_trampoline:\n" "movq 16(%rsp), %rdi\n" "ret"); #else -asm ("rpc_wait_trampoline:\n"); +asm ("trampoline:\n" + "fnclex\n" /* Clear any pending exception. */ + "jmp _trampoline\n" + "rpc_wait_trampoline:\n"); /* This is the entry point when we have an RPC reply message to receive before running the handler. The MACH_MSG_SEND bit has already been cleared in the OPTION argument on our stack. The interrupted user @@ -526,7 +532,7 @@ asm (/* Retry the interrupted mach_msg system call. */ /* Switch to the signal stack. */ "movl %ebx, %esp\n"); - asm ("trampoline:\n"); +asm ("_trampoline:\n"); /* Entry point for running the handler normally. The arguments to the handler function are already on the top of the stack: