At 14.04 -0600 0-08-30, Alastair Reid wrote:
>> On UNIX it would be better if it sent Hugs a signal when stack memory start
>> running out; does anybody out there know of such a UNIX command?
>
>That'd be hard to deal with because the signal could happen on any
>stack write - the machine might be in an inconsistent state.
>(Potentially a problem for catching ctrl-C too.)
Anyway, when the size limit of the stack is reached, the process gets a
SIGILL (illegal instruction) signal; under 4.2BSD, this signal is not reset
when caught, and it causes a core dump. (So the signal exists, but can
probably not be used.)
>However, a little asking around suggested something which might work:
>
>1) Use getrlimit(RLIMIT_STACK, ...) to find out the maximum stack size.
>
>2) Estimate actual stack size when Hugs starts up. Let's guess it's
> 8kbytes (or whatever) and lets allow a bit of slop space (8k again?)
> at the other end of the stack so we don't have to check the stack on
> every function call.
>
> Now we can calculate the maximum/minimum stack address (depending
> on which direction the stack grows): rlimit_stack - 16kbytes
To me it looks as though getrlimit(RLIMIT_STACK, ...) will return the size
of the maximum stack, not an address. How do you get the actual size of the
current stack in a stack check? What is rlimit_stack here, and how do you
get hold of it?
>3) Insert a stack check at the start of "eval" (is that enough?).
No, I recall the stack check was put into a number of places (but not a
very large number of places). But this is not a problem, as they already
are in the code (a macro named STACK_CHECK or something). All you need to
do is to figure out the UNIX version of it.
> If it triggers, throw an exception that the programmer
> can catch in the IO monad. (See code for throwing pattern match
> exceptions for comparision.)
The problem is though that the situation is critical when the stack is low,
so having an exception might not make sense. But one could offer the
possibility of trying to reset the stack limit, and if that fails, the
ability to start a new program.
Hans Aberg