home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.sun.misc
- Path: sparky!uunet!haven.umd.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.110625.2410@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:06:25 GMT
- Lines: 64
-
-
- Does anybody know why the following program does not work on Sun computers.
- I tried it on Sparcstation 1 and on Sun3 machines.
- The program is intended to generate a stack overflow and to
- recover from it.
- The signal handler is installed on a special signal stack, so
- it should be no problem to enter the handler.
- The effect on a Sparc is that the program works with
- limit stacksize 1000
- but it does not work with
- limit stacksize 2000.
- Any comments are welcome.
-
- /* 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");}
- }
-
-
- Josef Templ
- templ@inf.ethz.ch
-