From: Eli Zaretskii <eliz@gnu.org>
To: Konstantin Kharlamov <hi-angel@yandex.ru>
Cc: 61960@debbugs.gnu.org
Subject: bug#61960: 30.0.50; Unexec build reliably crashes during loadup
Date: Sun, 02 Jul 2023 08:52:18 +0300 [thread overview]
Message-ID: <835y72q2r1.fsf@gnu.org> (raw)
In-Reply-To: <63f3de6f0cc0d015d2dcbcdd6adc95482dc0c6ad.camel@yandex.ru> (message from Konstantin Kharlamov on Sun, 02 Jul 2023 04:50:26 +0300)
> From: Konstantin Kharlamov <hi-angel@yandex.ru>
> Date: Sun, 02 Jul 2023 04:50:26 +0300
>
> I've found a diff that fixes the build, but whether it's okay is worth discussion:
>
> diff --git a/src/gmalloc.c b/src/gmalloc.c
> index e655d69f660..f49bb01e08b 100644
> --- a/src/gmalloc.c
> +++ b/src/gmalloc.c
> @@ -1704,7 +1704,7 @@ allocated_via_gmalloc (void *ptr)
> return false;
> size_t block = BLOCK (ptr);
> size_t blockmax = _heaplimit - 1;
> - return block <= blockmax && _heapinfo[block].busy.type != 0;
> + return block <= blockmax;
> }
>
> /* See the comments near the beginning of this file for explanations
>
> Here's what happens: Emacs uses internal stack-based allocator (apparently allocating
> with sbrk(), but I'm not sure) along with the system allocator. Whenever a memory is
> allocated from the internal allocator, you can't call `free()` on it.
>
> When Emacs wants to free memory, it calls `hybrid_free_1()`, which internally
> determines whether the `ptr` passed belongs to system heap or to Emacs
> stack. Determining in turn is done by `allocated_via_gmalloc()`.
>
> Emacs also keeps the lowest and highest boundary of this stack in variables
> `_heapbase` and `_heaplimit` accordingly (except the latter is measured in
> "blocks"). The code in diff `block <= blockmax` simply makes sure that the `ptr`
> passed is within the stack-allocated memory, which implies it can't be deallocated
> with `free()`
>
> There's a question though of the right-hand side that I remove, the
> `_heapinfo[block].busy.type != 0;`. Apparently the `type` should keep some memory
> info, and apparently there's a bug somewhere that screws it up. It is a bug worth
> fixing, although for some reason `rr replay` doesn't work for me with `temacs`
> (probably a bug in rr), and without reverse-execution tracking that down would be
> very hard.
>
> But I would argue that the right-hand side check has no value in this function,
> because to determine the source of allocation it's enough to just check whether `ptr`
> is in _heapbase .. _heaplimit range (barring the fact they're different units).
Thanks, but how do you explain that this code works as-is when the
BLOCK_ALIGN change is not used?
next prev parent reply other threads:[~2023-07-02 5:52 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-04 14:55 bug#61960: 30.0.50; Unexec build reliably crashes during loadup Eli Zaretskii
2023-03-04 19:50 ` Konstantin Kharlamov
2023-03-04 19:51 ` Konstantin Kharlamov
2023-03-04 20:05 ` Konstantin Kharlamov
2023-03-04 20:26 ` Konstantin Kharlamov
2023-03-05 5:52 ` Eli Zaretskii
[not found] ` <xjf4jr0xkar.fsf@ma.sdf.org>
2023-03-04 21:56 ` Konstantin Kharlamov
2023-03-04 22:00 ` Konstantin Kharlamov
2023-03-04 22:08 ` Konstantin Kharlamov
2023-03-04 23:38 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-03-05 5:59 ` Eli Zaretskii
[not found] ` <xjf7cvtx0q0.fsf@ma.sdf.org>
2023-03-06 18:29 ` Eli Zaretskii
2023-03-07 14:59 ` Andrea Corallo
2023-03-07 15:33 ` Eli Zaretskii
2023-03-11 7:22 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
[not found] ` <xjfpm9es4qe.fsf@ma.sdf.org>
2023-03-12 23:49 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
[not found] ` <xjf3566s29a.fsf@ma.sdf.org>
2023-03-15 13:56 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-03-15 14:26 ` Eli Zaretskii
2023-03-16 0:30 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-03-16 6:25 ` Eli Zaretskii
[not found] ` <xjfv8j2qe69.fsf@ma.sdf.org>
2023-03-16 0:33 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-03-16 6:26 ` Eli Zaretskii
2023-03-05 5:46 ` Eli Zaretskii
2023-07-02 1:50 ` Konstantin Kharlamov
2023-07-02 2:27 ` Konstantin Kharlamov
2023-07-02 5:52 ` Eli Zaretskii [this message]
2023-07-02 11:32 ` Konstantin Kharlamov
2023-07-02 11:54 ` Konstantin Kharlamov
2023-07-02 14:10 ` Konstantin Kharlamov
2023-07-21 16:09 ` Konstantin Kharlamov
2023-07-21 16:30 ` Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=835y72q2r1.fsf@gnu.org \
--to=eliz@gnu.org \
--cc=61960@debbugs.gnu.org \
--cc=hi-angel@yandex.ru \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).