home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / unix / programm / 3947 < prev    next >
Encoding:
Text File  |  1992-07-27  |  1.9 KB  |  44 lines

  1. Xref: sparky comp.unix.programmer:3947 comp.sys.sun.misc:3357 comp.unix.questions:9464 comp.unix.wizards:3331
  2. Path: sparky!uunet!cs.utexas.edu!ut-emx!tivoli!shasta!bjv
  3. From: bjv@shasta.tivoli.com (Brian Vetter)
  4. Newsgroups: comp.unix.programmer,comp.sys.sun.misc,comp.unix.questions,comp.unix.wizards
  5. Subject: register windows and setjmp/longjmp
  6. Message-ID: <2203@tivoli.UUCP>
  7. Date: 27 Jul 92 23:01:31 GMT
  8. Sender: news@tivoli.UUCP
  9. Followup-To: comp.unix.programmer
  10. Organization: TIVOLI Systems
  11. Lines: 31
  12.  
  13. I am working on a program that creates its own lightweight threads (must manage
  14. the stacks).  To detect stack overflow, I am using the mprotect() system
  15. call to create a guard page at the end of the stack.  Instead of just dumping
  16. core when the stack overflows, I want to exit the failed thread (the others
  17. get to keep running).
  18.  
  19. My idea is to use setjmp() at the beginning of each thread to provide a "place"
  20. to come back, and to call longjmp() from the bus error handler.  To do this,
  21. I have to have a separate signal stack (using sigstack() and sigvec()).
  22.  
  23. The guard page works (I get my bus error), but I can't unwind the stack
  24. using longjmp().  I'm doing this on a Sun4 (ELC), and I suspect that there
  25. is some register window weirdness going on.
  26.  
  27. The function calling setjmp gets control after the longjmp but it gets a
  28. bus error as soon as it returns to its caller.  The $i7 and $fp registers
  29. are foobar when the function calling setjmp() gets control.  I tried the
  30. #pragma unknown_control_flow for my function but it still doesn't get
  31. the correct $i7 and $fp.  (If I set them to their correct values by hand
  32. in the debugger, everything works ok).
  33.  
  34. After disassembling the setjmp/longjmp code in the library, I'm wondering
  35. how they ever work with long stack depths with the register windows.
  36.  
  37. Does anyone know what I'm doing incorrectly?  Or am I faced with a
  38. bug in SunOS (the rev. is 4.1.1)?
  39.  
  40. Thanks in advance for any help,
  41.  
  42. Brian Vetter
  43. bjv@tivoli.com
  44.