kernel: add xsave support

This commit is contained in:
monkuous
2025-11-15 23:20:05 +01:00
parent 4024c42af1
commit d301ec6955
8 changed files with 190 additions and 61 deletions
+9 -14
View File
@@ -9,31 +9,26 @@
// this expects CTX_SP to be pointing to the signal frame
__attribute__((noreturn)) void syscall_sigreturn(context_t *context) {
sigframe_t sigframe;
int error = usercopy_fromuser(&sigframe, (void *)CTX_SP(context), sizeof(sigframe_t));
if (error || ARCH_CONTEXT_ISUSER(&sigframe.context) == false) {
sigframe_t *sigframe = __builtin_alloca(ARCH_SIGFRAME_SIZE);
int error = usercopy_fromuser(sigframe, (void *)CTX_SP(context), ARCH_SIGFRAME_SIZE);
if (error || ARCH_CONTEXT_ISUSER(&sigframe->context) == false) {
printf("syscall_sigreturn: bad return stack or bad return information\n");
proc_terminate(SIGSEGV);
}
interrupt_set(false);
signal_altstack(current_thread(), &sigframe.oldstack, NULL);
signal_changemask(current_thread(), SIG_SETMASK, &sigframe.oldmask, NULL);
signal_altstack(current_thread(), &sigframe->oldstack, NULL);
signal_changemask(current_thread(), SIG_SETMASK, &sigframe->oldmask, NULL);
arch_sigframe_get_context_from_mcontext(&sigframe);
arch_sigframe_get_context_from_mcontext(sigframe);
__assert(ARCH_CONTEXT_ISUSER(&sigframe.context));
__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_extracontext_copy(&current_thread()->extracontext, &sigframe->extracontext);
ARCH_CONTEXT_THREADLOAD(current_thread(), context);
interrupt_set(true);
arch_context_switch(&sigframe.context);
arch_context_switch(&sigframe->context);
// if we were to return normally, CTX_RET and CTX_ERRNO would be corrupted,
// so we will manually call arch_context_switch, which will jump to the right userland code