From 92abedffec913fe7337117403c5e07185356c81b Mon Sep 17 00:00:00 2001 From: Alexis211 Date: Fri, 2 Oct 2009 22:51:28 +0200 Subject: The kernel shell is now in an independent class, KernelShell:: --- Source/Kernel/TaskManager/Process.class.cpp | 1 + Source/Kernel/TaskManager/Task.ns.cpp | 4 ++-- Source/Kernel/TaskManager/Thread.class.cpp | 18 ++++++++++-------- Source/Kernel/TaskManager/Thread.class.h | 8 +++++--- 4 files changed, 18 insertions(+), 13 deletions(-) (limited to 'Source/Kernel/TaskManager') diff --git a/Source/Kernel/TaskManager/Process.class.cpp b/Source/Kernel/TaskManager/Process.class.cpp index ec1fcc9..5a707cd 100644 --- a/Source/Kernel/TaskManager/Process.class.cpp +++ b/Source/Kernel/TaskManager/Process.class.cpp @@ -74,6 +74,7 @@ void Process::registerThread(Thread* t) { } void Process::threadFinishes(Thread* thread, u32int retval) { + delete thread; // If it is the main thread of the process, or if it pagefaulted if (thread == m_threads[0] or retval == E_PAGEFAULT) { exit(); diff --git a/Source/Kernel/TaskManager/Task.ns.cpp b/Source/Kernel/TaskManager/Task.ns.cpp index 3ee21de..b430f24 100644 --- a/Source/Kernel/TaskManager/Task.ns.cpp +++ b/Source/Kernel/TaskManager/Task.ns.cpp @@ -3,7 +3,7 @@ //From Task.wtf.asm extern "C" u32int read_eip(); -extern "C" u32int idle_task(); +extern "C" u32int idle_task(void*); namespace Task { @@ -22,7 +22,7 @@ void initialize(String cmdline, VirtualTerminal *vt) { threads.clear(); processes.clear(); currentProcess = Process::createKernel(cmdline, vt); - idleThread = new Thread(idle_task, true); + idleThread = new Thread(idle_task, 0, true); currentThread = threads[0]; currentThreadId = 0; asm volatile ("sti"); diff --git a/Source/Kernel/TaskManager/Thread.class.cpp b/Source/Kernel/TaskManager/Thread.class.cpp index de92f0c..43884d7 100644 --- a/Source/Kernel/TaskManager/Thread.class.cpp +++ b/Source/Kernel/TaskManager/Thread.class.cpp @@ -3,33 +3,33 @@ #include #include -void runThread(Thread* thread, u32int (*entry_point)()) { +void runThread(Thread* thread, void* data, thread_entry_t entry_point) { asm volatile("sti"); - u32int ret = entry_point(); //Run ! + u32int ret = entry_point(data); //Run ! asm volatile("mov %0, %%eax; int $66;" : : "r"(ret)); //Syscall for thread ending } Thread::Thread() { //Private constructor, does nothing } -Thread::Thread(u32int (*entry_point)(), bool iskernel) { +Thread::Thread(thread_entry_t entry_point, void* data, bool iskernel) { if (iskernel) { m_isKernel = true; u32int tmp; m_kernelStackFrame = (u32int)PageAlloc::alloc(&tmp); m_process = Task::getKernelProcess(); - setup(entry_point, m_kernelStackFrame + 0x1000); //A kernel stack always is 1 frame, meaning 0x1000 bytes + setup(entry_point, data, m_kernelStackFrame + 0x1000); //A kernel stack always is 1 frame, meaning 0x1000 bytes } else { m_isKernel = false; m_process = Task::currentProcess; - setup(entry_point, m_process->stackAlloc() + STACKSIZE); + setup(entry_point, data, m_process->stackAlloc() + STACKSIZE); } } -Thread::Thread(Process* process, u32int (*entry_point)()) { +Thread::Thread(Process* process, thread_entry_t entry_point, void* data) { m_isKernel = false; m_process = process; - setup(entry_point, m_process->stackAlloc() + STACKSIZE); + setup(entry_point, data, m_process->stackAlloc() + STACKSIZE); } Thread::~Thread() { @@ -40,12 +40,14 @@ Thread::~Thread() { //Don't unregister thread in process, it has probably already been done } -void Thread::setup(u32int (*entry_point)(), u32int esp) { +void Thread::setup(thread_entry_t entry_point, void* data, u32int esp) { //Pass function parameters for runThread() u32int *stack = (u32int*)esp; stack--; *stack = (u32int)entry_point; //Push entry point (function parameter) stack--; + *stack = (u32int)data; //Push data + stack--; *stack = (u32int)this; //Push object pointer stack--; *stack = 0; //Null return address diff --git a/Source/Kernel/TaskManager/Thread.class.h b/Source/Kernel/TaskManager/Thread.class.h index 7d7917b..dffc84a 100644 --- a/Source/Kernel/TaskManager/Thread.class.h +++ b/Source/Kernel/TaskManager/Thread.class.h @@ -9,6 +9,8 @@ #define T_SLEEPING 2 #define T_IRQWAIT 3 //This can only happen if process->uid == 0 (root) +typedef u32int(*thread_entry_t)(void*); + class Thread { friend class Process; //This might be useful @@ -27,11 +29,11 @@ class Thread { bool m_isKernel; //Says if stack is in kernel pagedir, and if thread should run in ring 0 u32int m_kernelStackFrame; //Used for allocating and freeing a frame used as a stack - void setup(u32int (*entry_point)(), u32int esp); //Sets up stack, called by both constructors + void setup(thread_entry_t entry_point, void* data, u32int esp); //Sets up stack, called by both constructors public: - Thread(u32int (*entry_point)(), bool iskernel = false); //Assumes process is current process, or is kprocess if isk - Thread(Process* process, u32int (*entry_point)()); + Thread(thread_entry_t entry_point, void* data, bool iskernel = false); //Assumes process is current process, or is kprocess if isk + Thread(Process* process, thread_entry_t entry_point, void* data); ~Thread(); void finish(u32int errcode); //Called by run() when thread returns, and by exception handler. Can also be called by the thread itself void handleException(registers_t regs, int no); -- cgit v1.2.3