From: Roman Suzi Newsgroups: comp.os.msdos.djgpp Subject: Re: General Protection Fault interception vs. Checking stack Date: Sat, 08 Nov 97 09:40:38 +0300 Distribution: su Organization: unknown Message-ID: Sender: news-service AT sampo DOT karelia DOT ru Reply-To: nuser AT rsuzi DOT pgu DOT karelia DOT ru Lines: 70 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Hi! Nate Eldredge (was it in private letter?) wrote: This example worked for me under both CWSDPMI r3 and Windows 3.1. #include #include void handler(int sig) { printf("Received signal %d\n",sig); fflush(stdout); /* clean up */ exit(1); /* or whatever else */ } int main(void) { signal(SIGSEGV,handler); /* Overflow the stack */ alloca(1000000); /* Touch the stack to cause a fault */ printf("This isn't going to work"); return 0; } Running it prints "Received signal 291", which is evidently SIGSEGV. Yes, the example works. And this one doesn't under the same circumstances (dont optimize to preserve recursion!): #include #include void handler(int sig) { fprintf(stderr, "Received signal %d\n",sig); fflush(stderr); exit(1); /* or whatever else */ } /* deeply recursive */ int myproc(int a, double t) { if (a<0) return 1; else return myproc(a-1, a+0.23); } int main(void) { signal(SIGSEGV,handler); /* Overflow the stack with recursive calls */ myproc(1000000, 23.4); printf("No stack overflow."); return 0; } -- -- * -- -- Roman A. Suzi * Petrozavodsk Karelia Russia -- -- http://sampo.karelia.ru/~rnd --