This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Repeatable crash with CVS version of cygwin1 DLL


On Fri, Feb 20, 2004 at 10:02:38AM -0600, Cliff Geschke wrote:
>Are you trying to tell me that I can only call setjmp from the main
>program?

I don't recall saying that.  What I'm saying is that longjmp is always
supposed to be jumping to a location earlier in the call stack.

>I don't know what man page you are reading, but you are
>misunderstanding what it says.  Setjmp/longjmp does not trash (or is
>not supposed to trash) the call stack.  It can trash the auto variables
>in the local routine ("stack context") that contains the setjmp call,
>but that is not an issue here.

 From SUSv3:

"The longjmp() function shall restore the environment saved by the most
recent invocation of setjmp() in the same thread, with the corresponding
jmp_buf argument.  If there is no such invocation, or if the function
                                                      ^^^^^^^^^^^^^^^
containing the invocation of setjmp() has terminated execution in the
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
interim, or if the invocation of setjmp() was within the scope of an
^^^^^^^
identifier with variably modified type and execution has left that scope
in the interim, the behavior is undefined."
                ^^^^^^^^^^^^^^^^^^^^^^^^^

For instance, try the attached program on linux and you'll get a SEGV
because returning after the foo does not go to the right place.

This is basically what your test program seems to be doing.  It's possible
to get this to "work" by being very very careful with the stack but it
seems like fragile behavior to me.

For instance, the attached program "works" when there is no intervening
function call between the call to foo and the longjmp as can be
demonstrating by running the program with an argument.

cgf

Attachment: badlongjmp.c
Description: Text document

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]