I have written my own setjmp/longjmp which fits my needs, as shown below. I tested it on 32 bit systems and it works good. I save and restore registers eax, ebx, ecx, edi, esi, esp, ebp and eip for that purpose.
However, I know, this would not be enough for a 64 bit system. First of all, I think I need to replace registers eX with rX. Secondly, I think I need to save the 8 extra registers found in x86-64 bit, which are r8, r9, r10, r11, r12, r13, r14, r15. Would that be enough, or do I need to do more?
#define MY_SETJMP(n) __asm__ __volatile__ ("movl %eax, regax"#n";" \
"movl %ebx, regbx"#n";" \
"movl %ecx, regcx"#n";" \
"movl %edi, regdi"#n";" \
"movl %esi, regsi"#n";" \
"movl %esp, regsp"#n";" \
"movl %ebp, regbp"#n";" \
"call next"#n";" \
"next"#n": pop regip"#n";" \
"addl $6, regip"#n";" \
)
#define MY_LONGJMP(n) __asm__ __volatile__ ("movl regax"#n", %eax;" \
"movl regbx"#n", %ebx;" \
"movl regcx"#n", %ecx;" \
"movl regdi"#n", %edi;" \
"movl regsi"#n", %esi;" \
"movl regsp"#n", %esp;" \
"movl regbp"#n", %ebp;" \
"jmp *regip"#n";" \
)