home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.os.os9
- Path: sparky!uunet!mcrware!dibble
- From: dibble@microware.com (Peter Dibble)
- Subject: Re: Strange problem with setjmp()/longjmp() in OS9
- Message-ID: <1992Sep9.165549.15410@microware.com>
- Sender: news@microware.com
- Nntp-Posting-Host: seldon
- Organization: Microware Systems Corp., Des Moines, Iowa
- References: <87473@netnews.upenn.edu> <v1O85FG@keihh.hanse.de>
- Date: Wed, 9 Sep 1992 16:55:49 GMT
- Lines: 110
-
- I've tried to reproduce the setjmp()/longjmp from a signal
- handler problem. I can't.
-
- I put some code that should test longjmps from intercept routines
- at the end of this message.
-
- It doesn't fail. Did I fail to build a test that does the right (wrong)
- thing? Or is it failing to fail because I'm using the very latest
- (not shipping) kernel... or maybe there's something about
- the MVME167...
-
- I tested a lot of code that longjmp()'s out of intercept routines in
- the process of writing Insights 2nd edition. Since I was using
- a Micro-20 and the production kernel for that work I suspect that
- my test program is missing the problem.
-
- /*
- Torture long jumps out of signal intercept routines.
- */
- #include <stdio.h>
- #include <setjmp.h>
- #include <signal.h>
- #define ALARM_SIGNAL 5
- #define ALARM_INTERVAL 3 /* ticks */
- #define LIMIT 1000.0
- #define RDEPTH 50
-
- jmp_buf env;
-
- SigCatch(Sig)
- int Sig;
- {
- if(Sig == ALARM_SIGNAL){
- longjmp(env, 1);
- }
- if(Sig == SIGQUIT)
- Done();
- }
-
- int alm_id;
- int Child;
-
- Done()
- {
- int Code;
-
- alm_delete(alm_id);
- kill(Child, SIGQUIT);
- wait(&Code);
- exit(0);
- }
-
- main(argc, argv)
- int argc;
- char **argv;
- {
- double f;
- static char *eatargs[] = {"eatfpu", NULL};
- extern char **environ;
- extern int os9fork();
-
- Arguments(argc-1, argv+1);
- intercept(SigCatch);
- Child = os9exec(os9fork, eatargs[0], eatargs, environ, 0, 0);
- alm_id = alm_cycle(ALARM_SIGNAL, ALARM_INTERVAL);
- f = 0.0;
- if(setjmp(env) != 0){
- f += .33;
- sigmask(-1); /* unmask signals */
- write(1, "!", 1);
- }
-
- for(; f<LIMIT; f += .01){
- exercise(1);
- }
- Done();
- }
-
- exercise(n)
- int n;
- {
- int *x;
- if(n == RDEPTH)
- return;
- x = &Child;
- exercise(n+1);
- }
-
- Arguments(argc, argv)
- int argc;
- char **argv;
- {
- if(argc > 0){
- Usage();
- exit(0);
- }
- }
-
- Usage()
- {
- static char *msg[] = {
- "sigjmp exercises longjmp()'s out of signal intercept",
- "routines. It starts eatfpu then runs a cyclic alarm",
- "to trigger the signal intercept routine which longjmps",
- "to a recursive routine",
- NULL};
- char **ptr;
- for(ptr=msg; *ptr != NULL; ++ptr)
- printf("%s\n", *ptr);
- }
-