From: "Perry E. Metzger" <perry@piermont.com>
To: Frederic Perriot <fperriot@gmail.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] a bad value detector
Date: Fri, 4 May 2018 16:48:16 -0400 [thread overview]
Message-ID: <20180504164816.61724b3b@jabberwock.cb.piermont.com> (raw)
In-Reply-To: <CAFY7FBM5v0D-fcpxNEWqtja8uDuJHH+5Avj_u5i826HNxtkwkQ@mail.gmail.com>
On Wed, 2 May 2018 18:19:39 +0200 Frederic Perriot
<fperriot@gmail.com> wrote:
> Hello caml-list,
>
> I'd like to propose a detector to help in the detection of
> incorrect C bindings that do not follow the GC rules.
Once, I built a precise garbage collector for a language I'd
implemented in C. It was a simple Cheney collector with two
semispaces. I munmapped the unused semispace after each gc. In order
to debug C code that didn't properly register or protect GC roots, I
ran tests during every code change where I forced a collection after
every alloc -- this caused an almost immediate segfault in any C code
that was still pointing at the wrong semispace after the collection
because it would try to touch unmapped pages.
Generally I think tricks like this are a good idea. They allow one to
rapidly find code that doesn't correctly follow the rules at a fairly
low price. The only thing is you can only run such things while
testing because otherwise the performance hit is too high.
Perry
>
> The idea is rather simple:
>
> 1. after a minor collection, mprotect the pages of the minor heap to
> disallow reads and writes
> 2. install a SEGV handler to catch the ensuing faults
> 3. if the faulting address is above caml_young_ptr -
> Max_young_whsize, unprotect the page and carry on
> 4. otherwise, the program has no business accessing a value in the
> unallocated part of the minor heap, so let it crash
>
> I've hacked up a prototype that protects a single page at
> caml_young_start, and it catches the bug I mention in my other
> message entitled "an implicit GC rule".
>
> Such a change surely degrades performance, but maybe it would be
> useful as a runtime option available through CAMLRUNPARAM, to detect
> misbehaved C bindings.
>
> Does it sound like a viable technique?
>
> I'm curious to hear what you think.
>
> thanks,
> Frédéric Perriot
>
--
Perry E. Metzger perry@piermont.com
next prev parent reply other threads:[~2018-05-04 20:48 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-02 16:19 Frederic Perriot
2018-05-04 20:48 ` Perry E. Metzger [this message]
2018-05-09 8:39 ` Frederic Perriot
2018-05-11 5:54 ` Stijn Devriendt
2018-05-12 10:54 ` Frederic Perriot
2018-05-05 3:26 ` Chet Murthy
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180504164816.61724b3b@jabberwock.cb.piermont.com \
--to=perry@piermont.com \
--cc=caml-list@inria.fr \
--cc=fperriot@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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox