From patchwork Sun Oct 17 22:51:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 46315 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 7FF633857C48 for ; Sun, 17 Oct 2021 22:52:03 +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 2FA213858D28 for ; Sun, 17 Oct 2021 22:51:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2FA213858D28 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=ens-lyon.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=ens-lyon.org Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 1C39A188; Mon, 18 Oct 2021 00:51:49 +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 1MretotWZjxn; Mon, 18 Oct 2021 00:51:48 +0200 (CEST) Received: from begin (unknown [IPv6:2a01:cb19:956:1b00:de41:a9ff:fe47:ec49]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 20922E7; Mon, 18 Oct 2021 00:51:48 +0200 (CEST) Received: from samy by begin with local (Exim 4.95) (envelope-from ) id 1mcF0N-00A9Xv-2A; Mon, 18 Oct 2021 00:51:47 +0200 From: Samuel Thibault To: libc-alpha@sourceware.org Subject: [hurd,commited] hurd: Fix intr-msg parameter/stack kludge Date: Mon, 18 Oct 2021 00:51:45 +0200 Message-Id: <20211017225145.2419968-1-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 X-Spamd-Bar: ++++ X-Rspamd-Server: hera Authentication-Results: hera.aquilenet.fr; none X-Rspamd-Queue-Id: 1C39A188 X-Spamd-Result: default: False [4.90 / 15.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; R_MISSING_CHARSET(2.50)[]; BROKEN_CONTENT_TYPE(1.50)[]; RCVD_COUNT_THREE(0.00)[3]; MID_CONTAINS_FROM(1.00)[]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_LAST(0.00)[] X-Spam-Status: No, score=-11.7 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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" INTR_MSG_TRAP was tinkering with esp to make it point to _hurd_intr_rpc_mach_msg's parameters, and notably use (&msg)[-1] which is meaningless in C. Instead, just push the parameters on the stack, which also avoids leaving local variables of _hurd_intr_rpc_mach_msg below esp. We now also properly express that OPTION and TIMEOUT may be updated during the trap call. --- sysdeps/mach/hurd/i386/intr-msg.h | 49 ++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/sysdeps/mach/hurd/i386/intr-msg.h b/sysdeps/mach/hurd/i386/intr-msg.h index bd94aaf65f..ac3e5c07ed 100644 --- a/sysdeps/mach/hurd/i386/intr-msg.h +++ b/sysdeps/mach/hurd/i386/intr-msg.h @@ -21,8 +21,6 @@ to indicate that the signal thread might mutate them as part of sending us to a signal handler. */ -/* After _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. */ #define INTR_MSG_TRAP(msg, option, send_size, rcv_size, rcv_name, timeout, notify, cancel_p, intr_port_p) \ ({ \ error_t err; \ @@ -31,21 +29,52 @@ ".globl _hurd_intr_rpc_msg_do_trap\n" \ ".globl _hurd_intr_rpc_msg_in_trap\n" \ ".globl _hurd_intr_rpc_msg_sp_restored\n" \ - "_hurd_intr_rpc_msg_about_to: cmpl $0, %5\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. */ \ + " cmpl $0, %5\n" \ " jz _hurd_intr_rpc_msg_do\n" \ + /* We got interrupted, note so and return EINTR. */ \ " movl $0, %3\n" \ " movl %6, %%eax\n" \ " jmp _hurd_intr_rpc_msg_sp_restored\n" \ - "_hurd_intr_rpc_msg_do: movl %%esp, %%ecx\n" \ - " .cfi_def_cfa_register %%ecx\n" \ - " leal %4, %%esp\n" \ + "_hurd_intr_rpc_msg_do:" \ + /* Ok, push the mach_msg_trap arguments. */ \ + " pushl 24(%4)\n" \ + " .cfi_adjust_cfa_offset 4\n" \ + " pushl %2\n" \ + " .cfi_adjust_cfa_offset 4\n" \ + " pushl 16(%4)\n" \ + " .cfi_adjust_cfa_offset 4\n" \ + " pushl 12(%4)\n" \ + " .cfi_adjust_cfa_offset 4\n" \ + " pushl 8(%4)\n" \ + " .cfi_adjust_cfa_offset 4\n" \ + " pushl %1\n" \ + " .cfi_adjust_cfa_offset 4\n" \ + " pushl (%4)\n" \ + " .cfi_adjust_cfa_offset 4\n" \ + " pushl $0\n" \ + " .cfi_adjust_cfa_offset 4\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_do_trap: lcall $7, $0 # status in %0\n" \ - "_hurd_intr_rpc_msg_in_trap: movl %%ecx, %%esp\n" \ - " .cfi_def_cfa_register %%esp\n" \ + "_hurd_intr_rpc_msg_in_trap:" \ + /* Ok, clean the arguments and update OPTION and TIMEOUT. */ \ + " addl $8, %%esp\n" \ + " .cfi_adjust_cfa_offset -8\n" \ + " popl %1\n" \ + " .cfi_adjust_cfa_offset -4\n" \ + " addl $12, %%esp\n" \ + " .cfi_adjust_cfa_offset -12\n" \ + " popl %2\n" \ + " .cfi_adjust_cfa_offset -4\n" \ + " addl $4, %%esp\n" \ + " .cfi_adjust_cfa_offset -4\n" \ "_hurd_intr_rpc_msg_sp_restored:" \ - : "=a" (err), "+m" (option), "+m" (timeout), "=m" (*intr_port_p) \ - : "m" ((&msg)[-1]), "m" (*cancel_p), "i" (EINTR) \ + : "=a" (err), "+r" (option), "+r" (timeout), "=m" (*intr_port_p) \ + : "r" (&msg), "m" (*cancel_p), "i" (EINTR) \ : "ecx"); \ err; \ })