Kernel: Separate scheduler execution and stack loading

Not sure if this is actually needed, but this allows actual
executing function to be in clean environment
This commit is contained in:
Bananymous 2023-10-13 14:14:05 +03:00
parent cf4f5f64a5
commit 6b180da4e8
2 changed files with 20 additions and 1 deletions

View File

@ -31,6 +31,7 @@ namespace Kernel
static bool is_valid_tid(pid_t tid);
[[noreturn]] void execute_current_thread();
[[noreturn]] void _execute_current_thread();
[[noreturn]] void delete_current_process_and_thread();
private:

View File

@ -7,7 +7,10 @@
#include <kernel/Scheduler.h>
#include <kernel/Timer/PIT.h>
#if 1
#define SCHEDULER_VERIFY_STACK 1
#define SCHEDULER_VERIFY_INTERRUPT_STATE 1
#if SCHEDULER_VERIFY_INTERRUPT_STATE
#define VERIFY_STI() ASSERT(interrupts_enabled())
#define VERIFY_CLI() ASSERT(!interrupts_enabled())
#else
@ -202,6 +205,7 @@ namespace Kernel
delete thread;
execute_current_thread();
ASSERT_NOT_REACHED();
}
void Scheduler::execute_current_thread()
@ -210,6 +214,20 @@ namespace Kernel
load_temp_stack();
PageTable::kernel().load();
_execute_current_thread();
ASSERT_NOT_REACHED();
}
NEVER_INLINE void Scheduler::_execute_current_thread()
{
VERIFY_CLI();
#if SCHEDULER_VERIFY_STACK
vaddr_t rsp;
read_rsp(rsp);
ASSERT((vaddr_t)s_temp_stack <= rsp && rsp <= (vaddr_t)s_temp_stack + sizeof(s_temp_stack));
ASSERT(&PageTable::current() == &PageTable::kernel());
#endif
Thread* current = &current_thread();