[Python-Dev] stack check on Unix: any suggestions?

Jack Jansen jack@oratrix.nl
Wed, 30 Aug 2000 13:53:32 +0200


A completely different way to go about getting the stacksize on Unix is by 
actually committing the space once in a while. Something like (typed in as I'm 
making it up):

STACK_INCREMENT=128000

prober() {
    char space[STACK_INCREMENT];

    space[0] = 1;
    /* or maybe for(i=0;i<STACK_INCREMENT; i+=PAGESIZE) or so */
    space[STACK_INCREMENT-1] = 1;
}

jmp_buf buf;
catcher() {
    longjmp(buf);
    return 1;
}

PyOS_CheckStack() {
    static char *known_safe;
    char *here;

    if (we-are-in-a-thread())
	go do different things;
    if ( &here > known_safe )
	return 1;
    keep-old-SIGSEGV-handler;
    if ( setjmp(buf) )
	return 0;
    signal(SIGSEGV, catcher);
    prober();
    restore-old-SIGSEGV-handler;
    known_safe = &here - (STACK_INCREMENT - PYOS_STACK_MARGIN);
    return 1;
}
--
Jack Jansen             | ++++ stop the execution of Mumia Abu-Jamal ++++
Jack.Jansen@oratrix.com | ++++ if you agree copy these lines to your sig ++++
www.oratrix.nl/~jack    | see http://www.xs4all.nl/~tank/spg-l/sigaction.htm