I think Alon is correct here: longjmp is only legal up the stack.  At
least, my reading of the spec agrees with Alon's argument:

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

217) For example, by executing a return statement or because another
longjmp call has caused a
transfer to a setjmp invocation in a function earlier in the set of nested
calls.

On Tue, Jun 10, 2014 at 8:23 PM, Nikos Chantziaras <[email protected]> wrote:

> It's not undefined behavior. You can save stack contexts at any point and
> jump to them. Coroutines and threads can be implemented with this.
>
> Unwinding the stack due to an exception, which only goes up the stack, is
> only one use case of longjmp.
>
>
>
> On 11/06/14 02:06, Alon Zakai wrote:
>
>> You can use longjmp only to unwind the stack. I believe that to jump the
>> in the other direction is undefined behavior, and we don't support it -
>> a very different model would be needed for that.
>>
>> - Alon
>>
>>
>>
>> On Tue, Jun 10, 2014 at 8:07 AM, Stanislav Tsukrov
>> <[email protected]
>> <mailto:[email protected]>> wrote:
>>
>>     Is there a way to jump with longjmp to a setjmp-point outside of the
>>     current stack?
>>
>>     As far I can see longjmp is implemented with exceptions, so the
>>     jump-point must be upwards on the current stack.
>>     Any way to jump "down"?
>>
>>     --
>>     You received this message because you are subscribed to the Google
>>     Groups "emscripten-discuss" group.
>>     To unsubscribe from this group and stop receiving emails from it,
>>     send an email to
>>     [email protected]
>>     <mailto:[email protected]>.
>>
>>     For more options, visit https://groups.google.com/d/optout.
>>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "emscripten-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Chad Austin
Technical Director, IMVU
http://engineering.imvu.com <http://www.imvu.com/members/Chad/>
http://chadaustin.me

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to