The getcontext/swapcontext/setcontext functions save (restore) the RDI/RSI/RDX/RCX/R8/R9 registers for the current (target) context. However, according to the SysV x86-64 ABI these registers are not required to be preserved across function calls. I think that these registers shall be restored only for the first call of the context created via the makecontext().