home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / os / os9 / 1201 < prev    next >
Encoding:
Internet Message Format  |  1992-09-02  |  3.4 KB

  1. Path: sparky!uunet!mcsun!uknet!daresbury!gjm
  2. From: gjm@gserv1.dl.ac.uk (g.j.milne)
  3. Newsgroups: comp.os.os9
  4. Subject: Re: Strange problem with setjmp()/longjmp()
  5. Message-ID: <1992Sep3.091732.14255@gserv1.dl.ac.uk>
  6. Date: 3 Sep 92 09:17:32 GMT
  7. References: <v1O85FG@keihh.hanse.de>
  8. Sender: news@gserv1.dl.ac.uk (netnews)
  9. Reply-To: gjm@gserv1.dl.ac.uk
  10. Organization: Daresbury Laboratory, UK
  11. Lines: 60
  12.  
  13. In article <87473@netnews.upenn.edu> mark@ginger.biophys.upenn.edu (Mark Elliott) writes:
  14. >    I am programming in OS-9 v2.3 and cannot get setjmp()/longjmp() to
  15. >behave. I would like my signal handling routine to call longjmp() to branch
  16. >to a location in my main() routine as set by setjmp(). The branch occurs, but
  17. >shortly there after I get a Bus Trap error. The curious thing is that the
  18. >Bus Trap error occurs a different places in the code, even in subroutines
  19. >that have been successfully executed several times since the branch.
  20. >    I know that this sounds like a pure programming error in my code (it
  21. >probably is!) but I have made every attempt to figure it out. My question is:
  22. >
  23. >>********************************************************************************
  24. >>Does any one out there know about some known problem/bug with setjmp()/longjmp()?
  25. >>********************************************************************************
  26.  
  27. The problem is due to OS9 executing an F$RTE at the end of the signal
  28. handling routine. Unlike UNIX the interrupt handling routine for an OS9
  29. program is "special" which is why the routine uses 70 bytes on the
  30. user's stack when it is called (registers and state information being
  31. saved) and why it should (usually) set a flag and then return.
  32.  
  33. The OS9 technical manual states (OS9 System Calls - F$Icpt) that "the
  34. intercept routine should be short and fast, setting a flag in the
  35. processes's data area. Avoid complicated system calls (such I/O)". I'm
  36. sure that most people would agree that longjmp() is a "complicated"
  37. system call (or at least resembles one) and should not be called from
  38. an intercept routine.
  39.  
  40. If you disassemble the intercept() function you get the following
  41. code:
  42.  
  43. intercep            >4E550000         link.w a5,#0
  44. _sigint+0x4         >48E76080         movem.l d1-d2/a0,-(a7)
  45. _sigint+0x8         >41FA0012         lea.l _sigint+0x1C(pc),a0
  46. _sigint+0xC         >2D408072         move.l d0,_srqsiz+0x4(a6)
  47. _sigint+0x10        >6602             bne.b _sigint+0x14->
  48. _sigint+0x12        >2040             movea.l d0,a0
  49. _sigint+0x14        >4E400009         os9 F$Icpt
  50. _sigint+0x18        >600000A2         bra.w _sysret
  51. _sigint+0x1C        >2001             move.l d1,d0
  52. _sigint+0x1E        >206E8072         movea.l _srqsiz+0x4(a6),a0
  53. _sigint+0x22        >4E90             jsr (a0)
  54. _sigint+0x24        >4E40001E         os9 F$RTE
  55.  
  56. Intercept() is the routine that installs the signal handling routine.
  57. Note, the entry point to the user's routine is stored at
  58. _srqsiz+0x4(a6).
  59.  
  60. The "real" intercept routine is entered at _sigint+0x1C. Here d1 (which
  61. contains the signal code) is copied into d0 so that it is the first
  62. agrument of a C routine; the stored entry point is then loaded into a0
  63. (movea.l _srqsiz+0x4(a6),a0) and the routine jumps to that routine.
  64. Once that routine exists, an F$RTE is executed to "fix-up" the user's
  65. stack.
  66.  
  67. Ciao.
  68.  
  69. Gordon
  70. S.E.R.C. Daresbury Laboratory, Warrington, WA4 4AD, United Kingdom.
  71. e-mail     : g.j.milne@dl.ac.uk (INTERNET)  g.j.milne@uk.ac.daresbury (JANET)
  72. Opinions expressed are my own, not necessarily those of my employer!
  73.