signal: return from ucontext context

This commit is contained in:
Matheus
2024-12-25 21:58:39 -03:00
parent 936180e228
commit 0ed09edb63
2 changed files with 42 additions and 0 deletions
+12
View File
@@ -3,6 +3,10 @@
#include <arch/cpu.h>
#include <logging.h>
#ifdef __x86_64__
#include <arch/msr.h>
#endif
// this expects CTX_SP to be pointing to the signal frame
__attribute__((noreturn)) void syscall_sigreturn(context_t *context) {
sigframe_t sigframe;
@@ -16,7 +20,15 @@ __attribute__((noreturn)) void syscall_sigreturn(context_t *context) {
signal_altstack(current_thread(), &sigframe.oldstack, NULL);
signal_changemask(current_thread(), SIG_SETMASK, &sigframe.oldmask, NULL);
arch_sigframe_get_context_from_mcontext(&sigframe);
__assert(ARCH_CONTEXT_ISUSER(&sigframe.context));
#ifdef __x86_64__
// XXX is this behavior correct? ucontext doesnt seem to save it on linux and so it will not be saved
sigframe.extracontext.gsbase = rdmsr(MSR_KERNELGSBASE);
sigframe.extracontext.fsbase = rdmsr(MSR_FSBASE);
#endif
memcpy(&current_thread()->extracontext, &sigframe.extracontext, sizeof(extracontext_t));
ARCH_CONTEXT_THREADLOAD(current_thread(), context);