From 4e328c2f7acc614084fd1b9e3d447f8bdeb34dab Mon Sep 17 00:00:00 2001 From: Drew Galbraith Date: Fri, 16 Jun 2023 01:52:55 -0700 Subject: [PATCH] Set RSP0 on context switch Previously we only set it on thread init which caused interrupts to stomp on the stack of the most recently started thread, potentially overwriting their cr3 and other variables and causing a crash. --- zion/scheduler/scheduler.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/zion/scheduler/scheduler.cpp b/zion/scheduler/scheduler.cpp index ee3cd5e..b274cc7 100644 --- a/zion/scheduler/scheduler.cpp +++ b/zion/scheduler/scheduler.cpp @@ -1,5 +1,6 @@ #include "scheduler/scheduler.h" +#include "common/gdt.h" #include "debug/debug.h" #include "lib/linked_list.h" #include "scheduler/process_manager.h" @@ -26,6 +27,7 @@ void Scheduler::SwapToCurrent(Thread& prev) { } current_thread_->SetState(Thread::RUNNING); + SetRsp0(current_thread_->Rsp0Start()); context_switch(prev.Rsp0Ptr(), current_thread_->Rsp0Ptr()); asm volatile("sti");