As mentioned above by Nate, the ucontext
structure defined for use in kernel space does not match the ucontext
structure defined for use in user space. Therefore, it is not possible to simply copy them byte by byte. Instead, you can do this member by member:
void from_kernel(ucontext_t *context, const ucontext_t *stored_context)
{
context->uc_flags = stored_context->uc_flags;
context->uc_link = stored_context->uc_link;
memcpy(&context->uc_stack, &stored_context->uc_stack, sizeof(stack_t));
memcpy(&context->uc_mcontext, &stored_context->uc_mcontext, sizeof(mcontext_t));
memcpy(&context->uc_sigmask, &stored_context->uc_sigmask, sizeof(sigset_t));
}
, where:
Here is a link to a working example.