unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: "Daniel Colascione" <dancol@dancol.org>
To: "Philipp Stephani" <p.stephani2@gmail.com>
Cc: "Basil L. Contovounesios" <contovob@tcd.ie>,
	34655@debbugs.gnu.org, Stefan Monnier <monnier@iro.umontreal.ca>
Subject: bug#34655: 26.1.92; Segfault in module with --module-assertions
Date: Thu, 21 Mar 2019 13:48:28 -0700	[thread overview]
Message-ID: <54c0397230795ccc3701339de617d887.squirrel@dancol.org> (raw)
In-Reply-To: <CAArVCkSwEBFaJeV3aC27PJGeOYExz_PeioV+qew1nGOpvEcmDg@mail.gmail.com>

> Am Do., 21. März 2019 um 21:14 Uhr schrieb Eli Zaretskii <eliz@gnu.org>:
>>
>> > From: Philipp Stephani <p.stephani2@gmail.com>
>> > Date: Thu, 21 Mar 2019 21:01:43 +0100
>> > Cc: Stefan Monnier <monnier@iro.umontreal.ca>, "Basil L.
>> Contovounesios" <contovob@tcd.ie>, 34655@debbugs.gnu.org,
>> >       Daniel Colascione <dancol@dancol.org>
>> >
>> > Am Do., 21. März 2019 um 20:50 Uhr schrieb Eli Zaretskii
>> <eliz@gnu.org>:
>> > >
>> > > > From: Philipp Stephani <p.stephani2@gmail.com>
>> > > > Date: Thu, 21 Mar 2019 20:37:24 +0100
>> > > > Cc: Stefan Monnier <monnier@iro.umontreal.ca>, "Basil L.
>> Contovounesios" <contovob@tcd.ie>, 34655@debbugs.gnu.org
>> > > >
>> > > > Let's go back to the known good state first, and then discuss how
>> to
>> > > > go from there.
>> > >
>> > > I don't see why that is better than discuss first and then go to
>> where
>> > > we decide to go.  It's not like Emacs 27 will be released any time
>> > > soon, so there's no rush.
>> >
>> > For one, it becomes harder and harder to revert commits the older they
>> > get. Also such discussions tend to turn into endless debates about the
>> > "perfect" solution until one side gives up, without improving
>> > anything. I strongly prefer fixing actual bugs that affect users in
>> > practice and then discussing (or not discussing) the gold-plating
>> > steps later.
>>
>> I also prefer fixing bugs (which is why I spent several hours looking
>> into Basil's crash, when no one else was replying to that bug report),
>> but this is a community project, so we should discuss first and act
>> later.  Especially when controversial issues are involved.
>
> Well, as you can see, these discussions seem to lead nowhere, and both
> bug#34655 and bug#31238 remain unfixed.
>
>>
>> > > > We can't get stack marking to work, even theoretically.
>> > > >
>> > > > A module is free to do
>> > > >
>> > > > emacs_value x = ...;
>> > > > uintptr_t y = ((uintrptr_t) x) ^ 0x123456u;
>> > > > (garbage-collect)
>> > > > emacs_value z = (emacs_value) (y ^ 0x123456u);
>> > > > ... use z ...
>> > > >
>> > > > During the garbage collection, x isn't on the stack anywhere
>> > >
>> > > Why do you think x isn't on the stack in this case?
>> >
>> > Because the compiler reused the stack slot for something else?
>>
>> How can it?  You are using the same pointer later.
>
> Assume I don't use x later, and only y is on the stack during GC.
>
>>  Garbage collection
>> cannot happen unless you call an Emacs function, such as Ffuncall.
>> Calling a function means that even if the pointer to a Lisp object was
>> in a register, it will be put on the stack when calling Emacs.
>
> No matter whether y here is in a register or on the stack, it's not a
> Lisp_Value, so the GC can't find it.
>
>>
>> > Because the module is written in a language that doesn't use the stack
>> > in a way that the garbage collector expects?
>>
>> Which language is that, and how can it use the emacs-module machinery?
>
> Go, for example. It uses green threads with its own stack management
> and calling conventions. The GC couldn't ever find such a stack.
>
>>
>> > > Moreover, emacs_value is actually a pointer to a Lisp object, so
>> this
>> > > object is also somewhere on the stack, right?
>>
>> No answer?
>
> An emacs_value in the current implementation *is* a Lisp_Object cast
> to emacs_value. If the emacs_value is not on the stack, then there's
> no way to find the Lisp_Object.
>
>>
>> > We do something very specific with the stack: we make sure that
>> > Lisp_Objects are never manipulated in a way similar to the above, and
>> > we use the C language.
>>
>> If worse comes to worst, we can request module writers to adhere to
>> the same discipline.  We already request them to do/not to do quite a
>> few extraordinary things.
>
> No we can't. Modules can contain arbitrary code and call arbitrary
> libraries, which we can't ever control. We need to work with
> everything that provides a C-compatible interface.

Modules can contain arbitrary code, but they don't have to do arbitrary
things with that code. Right now, the contract between modules and Emacs
is something like "any value that, I, Emacs, can't find on an
Emacs-findable thread is fair game for memory reclaimation." In practice,
that works okay most of the time, but if we have to deal with environments
that can't guarantee that Emacs values remain on the C stack, we can
extend the contract with something like "I, module, am handing you, Emacs,
an array of emacs_values, and in addition to my stack, you should check
this array before considering a value dead" --- that is, we could just
provide a way for a module to associate a bunch of additional GC roots
with a given context. Then something like Go could stick any temporary
Emacs values in this array.

Or we could just have these environments create permanent references.







  parent reply	other threads:[~2019-03-21 20:48 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-25 21:00 bug#34655: 26.1.92; Segfault in module with --module-assertions Basil L. Contovounesios
2019-02-26  2:59 ` Richard Stallman
2019-02-26 11:16   ` Basil L. Contovounesios
2019-02-26 15:27     ` Eli Zaretskii
2019-02-26 18:42       ` Basil L. Contovounesios
2019-02-27  4:10     ` Richard Stallman
2019-02-26 15:45 ` Eli Zaretskii
2019-03-17 16:38   ` Basil L. Contovounesios
2019-03-17 17:08     ` Eli Zaretskii
2019-03-17 23:52       ` Basil L. Contovounesios
2019-03-18 16:21         ` Eli Zaretskii
2019-03-18 16:58           ` Basil L. Contovounesios
2019-03-18 17:53             ` Eli Zaretskii
2019-03-21 16:11               ` Philipp Stephani
2019-03-21 17:00                 ` Eli Zaretskii
2019-03-21 18:28                   ` Philipp Stephani
2019-03-21 19:23                     ` Philipp Stephani
2019-03-21 19:34                       ` Eli Zaretskii
2019-03-21 21:29                       ` Basil L. Contovounesios
2019-03-22  7:11                         ` Eli Zaretskii
2019-03-21 19:27                     ` Eli Zaretskii
2019-03-21 19:37                       ` Philipp Stephani
2019-03-21 19:50                         ` Eli Zaretskii
2019-03-21 20:01                           ` Philipp Stephani
2019-03-21 20:14                             ` Eli Zaretskii
2019-03-21 20:26                               ` Philipp Stephani
2019-03-21 20:44                                 ` Eli Zaretskii
2019-03-21 20:48                                 ` Daniel Colascione [this message]
2019-03-22  8:17                                   ` Eli Zaretskii
2019-03-21 21:31                         ` Basil L. Contovounesios
2019-03-22  0:56                       ` Stefan Monnier
2019-03-22  8:16                         ` 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=54c0397230795ccc3701339de617d887.squirrel@dancol.org \
    --to=dancol@dancol.org \
    --cc=34655@debbugs.gnu.org \
    --cc=contovob@tcd.ie \
    --cc=monnier@iro.umontreal.ca \
    --cc=p.stephani2@gmail.com \
    /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).