[mercury-users] Stack overflow detection?

Zoltan Somogyi zs at cs.mu.OZ.AU
Wed May 12 01:40:58 AEST 2004


On 11-May-2004, obo at ruk.cuni.cz <obo at ruk.cuni.cz> wrote:
> Would it be possible to detect stack overflow (both detstack and
> nondetstack) within Mercury? I.e. to let me wrap a critical part of my
> code with a try/2 and catch the exception?

At the moment, we catch stack overflow using one of two mechanisms in the low
level C backend.

The preferred mechanism is a "redzone", a zone at the end of each stack where
no access is allowed, an attempted access to which causes a SIGSEGV that
can be caught. The other mechanism is a probe at the time of allocation of
a stack frame to see if the stack has room for that stack frame.

The redzone mechanism could be adjusted to reserve a page for the exception
handler, but continuing after catching SIGSEGV is very dubious: operating
system support tends to not sufficiently documented; I wouldn't rely on it.
The stack probe approach should be relatively easy to extend to raise a
Mercury exception instead of aborting when running out of stack. However,
depending on what you want to do, the required functionality could be easier
to add as C code, which is trivial to call when the stack probe fails.

The high level backends use the native stack of the operating system;
if it isn't extended automatically as needed, the mechanisms to fix that fact
are operating system-dependent and outside our "jurisdiction".

> (Generally speaking, it would be better to redesign the code and run into
> the plain memory exhausted error later, but this is not worth the effort
> for my task, where I can simply reject all unnice examples.)

More information about exactly what you want to do would be useful in answering
your question.

Zoltan.
--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list