home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / os / os9 / 1216 < prev    next >
Encoding:
Text File  |  1992-09-09  |  2.4 KB  |  123 lines

  1. Newsgroups: comp.os.os9
  2. Path: sparky!uunet!mcrware!dibble
  3. From: dibble@microware.com (Peter Dibble)
  4. Subject: Re: Strange problem with setjmp()/longjmp() in OS9
  5. Message-ID: <1992Sep9.165549.15410@microware.com>
  6. Sender: news@microware.com
  7. Nntp-Posting-Host: seldon
  8. Organization: Microware Systems Corp., Des Moines, Iowa
  9. References: <87473@netnews.upenn.edu> <v1O85FG@keihh.hanse.de>
  10. Date: Wed, 9 Sep 1992 16:55:49 GMT
  11. Lines: 110
  12.  
  13. I've tried to reproduce the setjmp()/longjmp from a signal
  14. handler problem.  I can't.
  15.  
  16. I put some code that should test longjmps from intercept routines 
  17. at the end of this message.
  18.  
  19. It doesn't fail.  Did I fail to build a test that does the right (wrong) 
  20. thing? Or is it failing to fail because I'm using the very latest
  21. (not shipping) kernel... or maybe there's something about
  22. the MVME167...
  23.  
  24. I tested a lot of code that longjmp()'s out of intercept routines in
  25. the process of writing Insights 2nd edition.  Since I was using
  26. a Micro-20 and the production kernel for that work I suspect that
  27. my test program is missing the problem.
  28.  
  29. /*
  30.     Torture long jumps out of signal intercept routines.
  31. */
  32. #include <stdio.h>
  33. #include <setjmp.h>
  34. #include <signal.h>
  35. #define ALARM_SIGNAL    5
  36. #define ALARM_INTERVAL    3 /* ticks */
  37. #define LIMIT    1000.0
  38. #define RDEPTH    50
  39.  
  40. jmp_buf env;
  41.  
  42. SigCatch(Sig)
  43. int Sig;
  44. {
  45.     if(Sig == ALARM_SIGNAL){
  46.         longjmp(env, 1);
  47.     }
  48.     if(Sig == SIGQUIT)
  49.         Done();
  50. }
  51.  
  52. int alm_id;
  53. int Child;
  54.  
  55. Done()
  56. {
  57.     int Code;
  58.     
  59.     alm_delete(alm_id);
  60.     kill(Child, SIGQUIT);
  61.     wait(&Code);
  62.     exit(0);
  63. }
  64.     
  65. main(argc, argv)
  66. int argc;
  67. char **argv;
  68. {
  69.     double f;
  70.     static char *eatargs[] = {"eatfpu", NULL};
  71.     extern char **environ;
  72.     extern int os9fork();
  73.     
  74.     Arguments(argc-1, argv+1);
  75.     intercept(SigCatch);
  76.     Child = os9exec(os9fork, eatargs[0], eatargs, environ, 0, 0);
  77.     alm_id = alm_cycle(ALARM_SIGNAL, ALARM_INTERVAL);
  78.     f = 0.0;
  79.     if(setjmp(env) != 0){
  80.         f += .33;
  81.         sigmask(-1); /* unmask signals */
  82.         write(1, "!", 1);
  83.     }
  84.         
  85.     for(; f<LIMIT; f += .01){
  86.         exercise(1);
  87.     }
  88.     Done();
  89. }
  90.         
  91. exercise(n)
  92. int n;
  93. {
  94.     int *x;
  95.     if(n == RDEPTH)
  96.         return;
  97.     x = &Child;
  98.     exercise(n+1);
  99. }
  100.     
  101. Arguments(argc, argv)
  102. int argc;
  103. char **argv;
  104. {
  105.     if(argc > 0){
  106.         Usage();
  107.         exit(0);
  108.     }
  109. }
  110.  
  111. Usage()
  112. {
  113.     static char *msg[] = {
  114.         "sigjmp exercises longjmp()'s out of signal intercept",
  115.         "routines.  It starts eatfpu then runs a cyclic alarm",
  116.         "to trigger the signal intercept routine which longjmps",
  117.         "to a recursive routine",
  118.         NULL};
  119.     char **ptr;
  120.     for(ptr=msg; *ptr != NULL; ++ptr)
  121.         printf("%s\n", *ptr);
  122. }
  123.