Question

I was browsing through the source of various setjmp and longjmp implementations and noticed that not all of the CPU registers are saved in the jmp_buf structure. After reviewing the AMD64 ABI, I noticed that only the callee-saved registers are saved.

I do not understand how the function state can be fully resumed when only some of the registers have been saved. Surely the unsaved registers must have been clobbered many times over and over until I call longjmp later on?

Everything works perfectly however, so there's definitely something that I don't understand. I was hoping someone could shed some light on this.

Thanks!

Was it helpful?

Solution

The setjmp function is a function like any other, and can therefore be assumed to clobber any caller-saved registers. As such, there's no need for it to save/restore those registers.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top