Nobody <> writes:
> On Wed, 12 Dec 2012 15:19:57 +0100, Johann Klammer wrote:
>
>> Doesn't the whole machine state have to be
>> saved/restored(registers/Fp/SSE/flags etc)?
>
> No.
>
>> What if the calling function was using some regs for local vars etc ?!...
>
> 7.13.2.1p3:
>
> All accessible objects have values as of the time longjmp was
> called, except that the values of objects of automatic storage
> duration that are local to the function containing the
> invocation of the corresponding setjmp macro that do not have
> volatile-qualified type and have been changed between the
> setjmp invocation and longjmp call are indeterminate.
>
> gcc will warn about such cases with e.g.:
>
> warning: variable 'foo' might be clobbered by 'longjmp' or 'vfork'
A herring was never redder.
> Typically, only the "essential" registers (program counter, stack pointer,
> frame pointer) are preserved. Registers holding local variables or
> intermediate results aren't required to be preserved (and usually aren't).
> [snip unrelated]
This is nonsense. Any register holding a live value at the time
of the call to setjmp must be preserved, and restored by longjmp.
Most commonly that will be most or all the registers.