I found this on the 4.4BSD UNIX man page for getrlimit:
A resource limit is specified as a soft limit and a hard limit. When a
soft limit is exceeded a process may receive a signal (for example, if
the cpu time or file size is exceeded), but it will be allowed to contin-
ue execution until it reaches the hard limit (or modifies its resource
limit). The rlimit structure is used to specify the hard and soft limits
on a resource,
struct rlimit {
quad_t rlim_cur; /* current (soft) limit */
quad_t rlim_max; /* hard limit */
};
...
The system refuses to extend the data or stack space when the limits
would be exceeded in the normal way: a break call fails if the data space
limit is reached. When the stack limit is reached, the process receives
a segmentation fault (SIGSEGV); if this signal is not caught by a handler
using the signal stack, this signal will kill the process.
Thus, if the soft stack limit is less than the hard, one should be able to
catch the SIGSEGV signal, and then try to enlarge the soft limit, throw a
Haskell exception, pick down the executing program, or whatever.
Otherwise, it seems reasonable to assume that the stack is in contiguous
memory, so you could try your method. If it doesn't work, you either get a
segmentation fault or a too early abortion.
The default stack size on PPC Mac's is 64 kB I recall (and on 68k, 16 kB or
something). I think the stack check is when only about a quarter of the
standard stack is left, or about 16 kB for RISC. The default stack we use
for Mac-Hugs is 1 MB, though.
Hans Aberg