[Zion] Add a proc/thread cleanup thread for future use.

This commit is contained in:
Drew Galbraith 2023-11-24 15:04:03 -08:00
parent 8e4cd1562f
commit cb590c96b8
9 changed files with 95 additions and 0 deletions

View file

@ -6,6 +6,7 @@
#include "memory/kernel_vmm.h"
#include "memory/paging_util.h"
#include "object/process.h"
#include "scheduler/process_manager.h"
#include "scheduler/scheduler.h"
#define K_THREAD_DEBUG 0
@ -64,6 +65,10 @@ void Thread::Start(uint64_t entry, uint64_t arg1, uint64_t arg2) {
}
void Thread::Init() {
if (is_kernel_) {
((void (*)(void*))rip_)(reinterpret_cast<void*>(arg1_));
panic("Returned from kernel thread.");
}
#if K_THREAD_DEBUG
dbgln("Thread start.", pid(), id_);
#endif
@ -86,6 +91,7 @@ void Thread::Exit() {
panic("Thread::Exit called from [{}.{}] on [{}.{}]", curr_thread->pid(),
curr_thread->tid(), pid(), tid());
}
gProcMan->CleanupThread(curr_thread);
Cleanup();
process_.CheckState();
gScheduler->Yield();

View file

@ -45,6 +45,8 @@ class Thread : public KernelObject, public glcr::IntrusiveListNode<Thread> {
uint8_t* FxData() { return fx_data_; }
void SetKernel() { is_kernel_ = true; }
// Switches the thread's state to runnable and enqueues it.
void Start(uint64_t entry, uint64_t arg1, uint64_t arg2);
@ -75,6 +77,7 @@ class Thread : public KernelObject, public glcr::IntrusiveListNode<Thread> {
Process& process_;
uint64_t id_;
State state_ = CREATED;
bool is_kernel_ = false;
// Startup Context for the thread.
uint64_t rsp_;