home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / sys / sun / misc / 4164 < prev    next >
Encoding:
Text File  |  1992-09-10  |  1.9 KB  |  76 lines

  1. Newsgroups: comp.sys.sun.misc
  2. Path: sparky!uunet!haven.umd.edu!darwin.sura.net!Sirius.dfn.de!chx400!bernina!neptune!templ
  3. From: templ@inf.ethz.ch (Josef Templ)
  4. Subject: problem with signal handling
  5. Message-ID: <1992Sep10.110625.2410@neptune.inf.ethz.ch>
  6. Sender: news@neptune.inf.ethz.ch (Mr News)
  7. Nntp-Posting-Host: lillian-gw
  8. Organization: Dept. Informatik, Swiss Federal Institute of Technology (ETH)
  9. Date: Thu, 10 Sep 1992 11:06:25 GMT
  10. Lines: 64
  11.  
  12.  
  13. Does anybody know why the following program does not work on Sun computers.
  14. I tried it on Sparcstation 1 and on Sun3 machines.
  15. The program is intended to generate a stack overflow and to
  16. recover from it.
  17. The signal handler is installed on a special signal stack, so
  18. it should be no problem to enter the handler.
  19. The effect on a Sparc is that the program works with
  20. limit stacksize 1000
  21. but it does not work with
  22. limit stacksize 2000.
  23. Any comments are welcome.
  24.  
  25. /* stack.c    J. Templ, 4.09.92,
  26. test program to find out how to recover from a stack overflow */
  27.  
  28. #include <fcntl.h>
  29. #include <signal.h>
  30. #include <setjmp.h>
  31. #include <malloc.h>
  32.  
  33. jmp_buf env;
  34.  
  35. void SignalHandler(sig, code, scp, addr) 
  36.     int sig, code;
  37.     struct sigcontext *scp;
  38.     char *addr;
  39. {
  40. /*    printf("in SignalHandler %d\n", sig); */
  41.     longjmp(env, 1);
  42. }
  43.  
  44. void GenStackOvfl() {
  45.     GenStackOvfl();
  46. }
  47.  
  48. void SetSignalStack() {
  49.     struct sigstack ss;
  50.     ss.ss_sp = (char*) (((int) malloc(100000)) + 100000 - 256);
  51.     ss.ss_onstack = 0;
  52.     sigstack(&ss, 0);
  53. }
  54.  
  55. void InstallSignalHandler() {
  56.     struct sigvec vec;
  57.     vec.sv_handler = SignalHandler;
  58.     vec.sv_mask = 0;
  59.     vec.sv_flags = SV_ONSTACK;
  60.     sigvec(SIGINT, &vec, 0);
  61.     sigvec(SIGILL, &vec, 0);
  62.     sigvec(SIGFPE, &vec, 0);
  63.     sigvec(SIGBUS, &vec, 0);
  64.     sigvec(SIGSEGV, &vec, 0);
  65. }
  66.  
  67. main() {
  68.     SetSignalStack(); InstallSignalHandler();
  69.     if (setjmp(env) == 0) {printf("before signal\n"); GenStackOvfl();}
  70.     else {printf("recovered from signal\n");}
  71. }
  72.  
  73.  
  74. Josef Templ
  75. templ@inf.ethz.ch
  76.