On x86_64 Linux, with:
#include <ucontext.h>
#include <setjmp.h>
#include <signal.h>
#include <stdio.h>
int main(void)
{
#define PRSZ(X) printf("sizeof(" #X ")=%zu\n", sizeof(X))
PRSZ(ucontext_t); //contains mcontext_t, stack_t, sigset_t, and on glibc this struct _libc_fpstate
PRSZ(mcontext_t);
PRSZ(stack_t);
PRSZ(sigset_t);
//PRSZ(struct _libc_fpstate); //512
PRSZ(sigjmp_buf); //contains sigset_t
}
I get:
sizeof(ucontext_t)=936
sizeof(mcontext_t)=256
sizeof(stack_t)=24
sizeof(sigset_t)=128
sizeof(sigjmp_buf)=200
Why is ucontext_t so much larger than sigjmp_buf and mcontext_t so much larger than sizeof(sigjmp_buf)-sizeof(sigset_t)?
I thought (sig)longjmp could be used to restore context from a (sig)jmp_buf just the same as setcontext could be used to restore context form ucontext_t, but much more context is saved and restored in the latter case.
What extra things does setcontext do compared to siglongjmp?