From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Pip Cet via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#75322: SAFE_ALLOCA assumed to root Lisp_Objects/SSDATA(string) Date: Sat, 04 Jan 2025 11:41:20 +0000 Message-ID: <87wmfahko1.fsf@protonmail.com> References: <87jzbbke6u.fsf@protonmail.com> <87msg7iq0o.fsf@protonmail.com> <86ed1jf1tp.fsf@gnu.org> <865xmugawr.fsf@gnu.org> Reply-To: Pip Cet Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="21803"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Gerd =?UTF-8?Q?M=C3=B6llmann?= , 75322@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jan 04 12:42:25 2025 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tU2Xw-0005Vx-Ok for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 04 Jan 2025 12:42:24 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tU2Xd-0001Ab-Rq; Sat, 04 Jan 2025 06:42:06 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tU2Xb-00019n-Mj for bug-gnu-emacs@gnu.org; Sat, 04 Jan 2025 06:42:03 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tU2Xa-0002Kn-E7 for bug-gnu-emacs@gnu.org; Sat, 04 Jan 2025 06:42:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:References:In-Reply-To:From:Date:To:Subject; bh=BhEn2VJy5mfMjVHogLuM8l8xH5oemSwpYf/mt97mL0c=; b=l07zKbXznf0AMUW6+HbWiXzXbvqB8C2Q1g2vyMQMhk0qpa2x25pzlgxXH/onEHocV1KYXJLQMHNQvmaS7HHE9DUrHEXKTU5LHNkRDgeAjBI6zsDJTcV80xGWzIp7gy1WwsnBITAAIHanKSWRbmCkW9S65sWbTXjiNNK/RinhFp2QI9AiRlGZ95e632Z6MNizc8y1f/tlLe56omPbQu4vKTUbVe5XCKjITFbIpxTzFbhh1ZiKNXEVHX3ZbcisXfFmCX/FDBY3ZYLRQsyed4yV5zIUIGHg9Y12qteRflGxgAq4cAs4MHN0NORFPPzieVTKln+93AVcF31vL/J23C9vcw==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tU2Xa-00037O-8x for bug-gnu-emacs@gnu.org; Sat, 04 Jan 2025 06:42:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Pip Cet Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 04 Jan 2025 11:42:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 75322 X-GNU-PR-Package: emacs Original-Received: via spool by 75322-submit@debbugs.gnu.org id=B75322.173599089411937 (code B ref 75322); Sat, 04 Jan 2025 11:42:02 +0000 Original-Received: (at 75322) by debbugs.gnu.org; 4 Jan 2025 11:41:34 +0000 Original-Received: from localhost ([127.0.0.1]:53648 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tU2X7-00036S-Q7 for submit@debbugs.gnu.org; Sat, 04 Jan 2025 06:41:34 -0500 Original-Received: from mail-4316.protonmail.ch ([185.70.43.16]:48763) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1tU2X5-000362-Fn for 75322@debbugs.gnu.org; Sat, 04 Jan 2025 06:41:32 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1735990884; x=1736250084; bh=BhEn2VJy5mfMjVHogLuM8l8xH5oemSwpYf/mt97mL0c=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post; b=YCIED69fmRQGWU0ssoVgr98DyLbJw4ERU2mqZH4uDJxZHw0vxD0wfzPJiuCQw18eZ 5yWeAQXJKoihDX/Oanepm8/ldlgzo93AVeapg2v8VgrxZ4fjNFPYtO7GezTXcE1Xhd WCHZxjgYp9ofHDWUbd4qucceCEPXxjrM8sdZ47/zdG0JGJv13Kms6kavbS/T541wcF OHlxkw0K2zBSp/5wQF4CLjNNBtISbGdVfRXqnwm8Z5S4raVaLqvZgxRMTZ00+TIbQ1 kcH6HLOiDy571rrxBPazBWPAmS7P3g/We6P2KESDK32/tWmSJhv6dNKasMsQlEZd5Z 6bysyHw530a/Q== In-Reply-To: <865xmugawr.fsf@gnu.org> Feedback-ID: 112775352:user:proton X-Pm-Message-ID: 59ff7b8a13b462cd7c1e323f068beb9dfcc2eaf5 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:298370 Archived-At: "Eli Zaretskii" writes: >> From: Gerd M=C3=B6llmann >> Cc: pipcet@protonmail.com, 75322@debbugs.gnu.org >> Date: Sat, 04 Jan 2025 09:47:43 +0100 >> >> Eli Zaretskii writes: >> >> > Let's discuss this on a case by case basis. Not all uses of alloca >> > are the same or have the same requirements and restrictions. >> >> Okay. For the SDATA case, I find Pip's commit does the right thing. It >> uses xstrdup for the strings and makes sure these are freed later by >> registering them in one of the special specpdl entries that exist for >> that purpose (record_unwind_protect_ptr). Works with both GCs, is always >> safe, I don't see disadvantages, and we don't have to check if GC runs >> or not and compact strings (old) or moves string data around (igc). > > The disadvantage is to xstrdup strings when that is not needed. It > increases memory pressure and also costs some CPU time. Not very > significant disadvantage, admittedly, but still. If this is needed, > it's a small price to pay, but if it isn't needed, it's a waste. It's easier to xstrdup rather than figure out which no-GC assumptions are in the subprocess code, which of them are valid (probably not all of them, considering Fexpand_file_name), and how to document them in a way that doesn't turn this area of code into more of a minefield than it is already :-) > So let's see if we agree that it is indeed needed. The way to do that > is to explain how GC could happen while the code which assembles the > environment in make_environment_block and the code in emacs_spawn > afterwards run. Note that we block SIGCHLD and block input while > emacs_spawn runs. I'm not going to explain "how GC could happen" in the MPS case: GC can strike at any time. For traditional GC, if we want to change the code as little as possible, we could indeed try to establish no-GC assumptions, but we don't have to: we can simply start with correct but slow code and maybe drop a note to the usual suspects that there is optimization potential here. >> For the Lisp_Object cases, I strongly suspect that these cases are an >> oversight and were left over when SAFE_ALLOCA_LISP was introduced. The >> reason for introducing SAFE_ALLOCA_LISP is, IMO, what Pip said (old GC): >> to make sure that the Lisp_Objects are marked, via specpdl stack entries >> again, when the specpdl stack(s) are marked. Not doing that looks >> definitely wrong. Replacing the other ALLOCA macros that are currently >> used for holding Lisp_Objects with SAFE_ALLOCA_LISP would solve things >> for both GCs. > > Can we first identify those cases, so that we could discuss the > specific codes in question? TBH, if there is a single bug caused by an incorrect SAFE_ALLOCA which should be a SAFE_ALLOCA_LISP, I think that's reason enough to modify SAFE_ALLOCA to conservatively scan any xmalloc'd memory it uses. No performance impact as this case is nonexistent in practice. Pip