Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The longjmp(3) man page on Unix says:</p> <blockquote> <p>The longjmp() routines may not be called after the routine which called the setjmp() routines returns</p> </blockquote> <p>I think it explains explains your concern that "<em>sometimes control never reachs BP1</em>". I don't think "<em>runs fine</em>" is reliable judgement. I'd rather expect it randomly runs fine and generally is messing up with stack.</p> <p>There are a few clear recommendations that should be taken into account while working mixing longjmp/setjmp with C++ exceptions in order to avoid crashes and undefined behaviour:</p> <ul> <li>Do not use setjmp/longjmp in C++ programs.</li> <li>If you use setjmp/longjmp functions in program where exceptions can occur, you are safe as long as they do not interact.</li> <li>Never longjmp in or out of try clause and catch clause.</li> <li>Never longjmp over point of initialization of automatic objects.</li> <li>Never longjmp pasy point of destruction automatic objects, especially if destructor is non-trivial.</li> <li>Never throw from signal handler.</li> <li>Never invoke longjmp from nested signal handler.</li> <li>Behaviour of longjmp from location X to location Y stays predictable and valid as long as if exception thrown at X and caught at X would have the same effect.</li> <li>If you mix setjmp/longjmp with exceptions, do not expect portability.</li> <li>Instead, refer to relevant details in documentation compiler you are using. For example, if you use Visual C++, read <a href="http://msdn.microsoft.com/en-us/library/yz2ez4as.aspx" rel="nofollow">Use setjmp/longjmp</a></li> </ul> <p>The question mentions dealing with legacy C code in programs written in C++. There has been an interesting discussion on sjlj issues in jpeg library during review of one of Boost libraries. The discussion was long but here is <a href="http://article.gmane.org/gmane.comp.lib.boost.devel/201425" rel="nofollow">essence with recommended options</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload