From: "Mark Shinwell" <mshinwell@janestreet.com>
To: Michael Ekstrand <michael@elehack.net>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Native code stack overflow detection guarantees - followup
Date: Fri, 9 Jul 2010 09:46:26 +0100 [thread overview]
Message-ID: <20100709084626.GR29068@janestreet.com> (raw)
In-Reply-To: <20100709083906.GQ29068@janestreet.com>
On Fri, Jul 09, 2010 at 09:39:06AM +0100, Mark Shinwell wrote:
> On Thu, Jul 08, 2010 at 08:59:30PM -0400, Michael Ekstrand wrote:
> > Therefore, I am wondering: are there documented guarantees on which the
> > native code stack overflow behavior rests? Linux processes usually receive
> > a segmentation fault when they run out of stack space; is that guaranteed,
> > or is it simply the usual convenient behavior? What about for other
> > systems?
>
> I am not an expert on all the various cases which might arise during a case
> of stack overflow, but I believe on Linux it is exposed to userland as a
> segmentation fault. Exactly how this is exposed shouldn't be any different
> when executing Caml native-compiled code or C code, for example. In terms of
> Caml-specific behaviour (and assuming that the user's code does not itself
> alter the signal handling behaviour) then the runtime should catch the stack
> overflow via the SIGSEGV handler. The intuition behind what is supposed to
> happen next is as follows: if the faulting address was in the stack, and the
> program counter (PC) was "in your Caml program", then we produce a
> Stack_overflow exception. Otherwise we will just invoke the default signal
> action for the segmentation fault, which on Linux will terminate the program.
>
> (There are lots of functions in the runtime which could cause a stack
> overflow in the case of a bug in their own code; and it would probably be bad
> if those ended up with a Stack_overflow exception rather than a segfault.
> This seems to me to be at least one reason why you probably don't want to
> turn every segfault in the stack into a Stack_overflow exception; instead, we
> try to distinguish based on the PC.)
I should add that what I wrote was for Linux/x86. On other platforms the
behaviour may differ depending on what system support is available.
You need HAS_STACK_OVERFLOW_DETECTION (see the Caml configure script) set
to get any of this at all; and to have the distinguishing based on the
program counter location, you need CONTEXT_PC to have been defined
(see asmrun/signals_osdep.h in the Caml source).
Mark
next prev parent reply other threads:[~2010-07-09 8:46 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-09 0:59 Native code stack overflow detection guarantees Michael Ekstrand
2010-07-09 8:39 ` [Caml-list] " Mark Shinwell
2010-07-09 8:46 ` Mark Shinwell [this message]
2010-07-11 11:03 ` Goswin von Brederlow
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=20100709084626.GR29068@janestreet.com \
--to=mshinwell@janestreet.com \
--cc=caml-list@inria.fr \
--cc=michael@elehack.net \
/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