home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / unix / programm / 4459 < prev    next >
Encoding:
Internet Message Format  |  1992-08-26  |  2.2 KB

  1. Xref: sparky comp.unix.programmer:4459 comp.unix.xenix.sco:2748
  2. Path: sparky!uunet!munnari.oz.au!bunyip.cc.uq.oz.au!kirk!lance!ptcburp!michi
  3. From: michi@ptcburp.ptcbu.oz.au (Michael Henning)
  4. Newsgroups: comp.unix.programmer,comp.unix.xenix.sco
  5. Subject: Re: Calling longjmp() from signal handler: portable?
  6. Message-ID: <1992Aug27.001005.22826@ptcburp.ptcbu.oz.au>
  7. Date: 27 Aug 92 00:10:05 GMT
  8. References: <2A9BCC57.640F@tct.com>
  9. Organization: Pyramid Technology Corporation
  10. Lines: 39
  11.  
  12. chip@tct.com (Chip Salzenberg) writes:
  13.  
  14. >In working on Smail 3, I've found that I need to interrupt a blocking
  15. >system call (a kernel locking primitive, to be precise).  Ron Karr
  16. >seems to think that calling longjmp() from a signal handler will work
  17. >with all known versions of UNIX, not just with BSD as I assumed.
  18.  
  19. >Is Ron right that longjmp() always works from signal handlers?  Or am
  20. >I correct that, for example, SCO Xenix sets up a separate stack frame
  21. >for signal handlers, so longjmp() won't work correctly?
  22.  
  23. From the setcontext(3C) man page on our V.4 system (Pyramid DC/OSx):
  24.  
  25. When a signal handler is executed, the current user context is saved
  26. and a new context is created by the kernel.  If the process leaves the
  27. signal handler via longjmp(3C) the original context will not be
  28. restored, and future calls to getcontext will not be reliable.  Signal
  29. handlers should use siglongjmp(3C) or setcontext instead.
  30.  
  31.  
  32. The man page for sigsetjmp(3C) says:
  33.  
  34. sigsetjmp saves the calling process's registers and stack environment
  35. [see sigaltstack(2)] in env (whose type, sigjmp_buf, is defined in the
  36. <setjmp.h> header file) for later use by siglongjmp. If savemask is
  37. non-zero, the calling process's signal mask [see sigprocmask(2)] and
  38. scheduling parameters [see priocntl(2)] are also saved. sigsetjmp
  39. returns the value 0.
  40.  
  41.  
  42. So, the answer is that if you haven't done anything strange with setcontext
  43. or sigaltstack, setjmp/longjmp should be OK, otherwise use sigsetjmp/siglongjmp.
  44.  
  45.                                 Michi.
  46. -- 
  47.       -m------- Michael Henning                 +61 75 950255
  48.     ---mmm----- Pyramid Technology              +61 75 722475 FAX
  49.   -----mmmmm--- Research Park, Bond University  michi@ptcburp.ptcbu.oz.au
  50. -------mmmmmmm- Gold Coast, Q 4229, AUSTRALIA   uunet!munnari!ptcburp.oz!michi
  51.