The functions in <ucontext.h>
do exactly this, and setcontext()
is what you want in particular. This function is implemented in GLIBC, and the source file for it can be found in various places on the internet.
Casually looking over the assembly, it basically recovers the floating point context, and then recovers all the other registers.