home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!spool.mu.edu!darwin.sura.net!Sirius.dfn.de!chx400!bernina!neptune!templ
- From: templ@inf.ethz.ch (Josef Templ)
- Subject: problem with signal handling
- Message-ID: <1992Sep10.111952.2596@neptune.inf.ethz.ch>
- Sender: news@neptune.inf.ethz.ch (Mr News)
- Nntp-Posting-Host: lillian-gw
- Organization: Dept. Informatik, Swiss Federal Institute of Technology (ETH)
- Date: Thu, 10 Sep 1992 11:19:52 GMT
- Lines: 67
-
- Does anybody know why the following program does not work
- as expected on Sun computers?
- It works fine e.g. on DECstation running Ultrix.
-
- The program is intended to generate a stack overflow,
- to enter a signal handler (catch the overflow), and
- to recover from the signal by means of a longjmp call.
- Surprisingly, it does work with
- limit stacksize 1000,
- but it does not work with
- limit stacksize 2000.
- Is there anything wrong with the program or with Sun's
- C compiler or with SunOS?
-
- /* stack.c J. Templ, 4.09.92,
- test program to find out how to recover from a stack overflow */
-
- #include <fcntl.h>
- #include <signal.h>
- #include <setjmp.h>
- #include <malloc.h>
-
- jmp_buf env;
-
- void SignalHandler(sig, code, scp, addr)
- int sig, code;
- struct sigcontext *scp;
- char *addr;
- {
- /* printf("in SignalHandler %d\n", sig); */
- longjmp(env, 1);
- }
-
- void GenStackOvfl() {
- GenStackOvfl();
- }
-
- void SetSignalStack() {
- struct sigstack ss;
- ss.ss_sp = (char*) (((int) malloc(100000)) + 100000 - 256);
- ss.ss_onstack = 0;
- sigstack(&ss, 0);
- }
-
- void InstallSignalHandler() {
- struct sigvec vec;
- vec.sv_handler = SignalHandler;
- vec.sv_mask = 0;
- vec.sv_flags = SV_ONSTACK;
- sigvec(SIGINT, &vec, 0);
- sigvec(SIGILL, &vec, 0);
- sigvec(SIGFPE, &vec, 0);
- sigvec(SIGBUS, &vec, 0);
- sigvec(SIGSEGV, &vec, 0);
- }
-
- main() {
- SetSignalStack(); InstallSignalHandler();
- if (setjmp(env) == 0) {printf("before signal\n"); GenStackOvfl();}
- else {printf("recovered from signal\n");}
- }
-
-
- Any comments are deeply appreciated.
- Josef Templ
- templ@inf.ethz.ch
-
-