From 1b92fe36b4140b56b05fb3873b2fb02875c1a981 Mon Sep 17 00:00:00 2001 From: apio Date: Sun, 18 Dec 2022 18:43:17 +0100 Subject: [PATCH] Store the stack inside a thread --- kernel/src/thread/Scheduler.cpp | 4 ++++ kernel/src/thread/Thread.h | 3 +++ luna/include/luna/Stack.h | 1 + 3 files changed, 8 insertions(+) diff --git a/kernel/src/thread/Scheduler.cpp b/kernel/src/thread/Scheduler.cpp index 225a9505..bba4f6d9 100644 --- a/kernel/src/thread/Scheduler.cpp +++ b/kernel/src/thread/Scheduler.cpp @@ -29,6 +29,8 @@ namespace Scheduler Stack idle_stack{idle_stack_vm, ARCH_PAGE_SIZE}; g_idle.set_sp(idle_stack.top()); + g_idle.stack = idle_stack; + kinfoln("CREATED IDLE THREAD: id %lu with ip %lx and sp %lx", g_idle.id, g_idle.ip(), g_idle.sp()); g_current = &g_idle; @@ -56,6 +58,8 @@ namespace Scheduler Stack thread_stack{thread_stack_vm, ARCH_PAGE_SIZE * 4}; thread->set_sp(thread_stack.top()); + thread->stack = thread_stack; + g_threads.append(thread); kinfoln("CREATED THREAD: id %lu with ip %lx and sp %lx", thread->id, thread->ip(), thread->sp()); diff --git a/kernel/src/thread/Thread.h b/kernel/src/thread/Thread.h index 514d51ba..43d40007 100644 --- a/kernel/src/thread/Thread.h +++ b/kernel/src/thread/Thread.h @@ -2,6 +2,7 @@ #include #include +#include #ifdef ARCH_X86_64 #include "arch/x86_64/CPU.h" @@ -29,6 +30,8 @@ struct Thread : public DoublyLinkedListNode u64 ticks_left; u64 sleep_ticks_left; + Stack stack; + ThreadState state = ThreadState::Runnable; bool is_idle() diff --git a/luna/include/luna/Stack.h b/luna/include/luna/Stack.h index 7870402c..d1a73f0d 100644 --- a/luna/include/luna/Stack.h +++ b/luna/include/luna/Stack.h @@ -3,6 +3,7 @@ struct Stack { + Stack() = default; Stack(u64 base, usize bytes); u64 bottom()