summaryrefslogtreecommitdiff
path: root/Source/Kernel/TaskManager
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Kernel/TaskManager')
-rw-r--r--Source/Kernel/TaskManager/Process.class.cpp2
-rw-r--r--Source/Kernel/TaskManager/Process.class.h2
-rw-r--r--Source/Kernel/TaskManager/Task.ns.cpp2
-rw-r--r--Source/Kernel/TaskManager/Thread.class.cpp17
-rw-r--r--Source/Kernel/TaskManager/Thread.class.h5
5 files changed, 17 insertions, 11 deletions
diff --git a/Source/Kernel/TaskManager/Process.class.cpp b/Source/Kernel/TaskManager/Process.class.cpp
index 3363ab0..13af4b9 100644
--- a/Source/Kernel/TaskManager/Process.class.cpp
+++ b/Source/Kernel/TaskManager/Process.class.cpp
@@ -68,7 +68,7 @@ void Process::registerThread(Thread* t) {
void Process::threadFinishes(Thread* thread, u32int retval) {
// If it is the main thread of the process, or if it pagefaulted
- if (thread == m_threads[0] or retval == 0x0FFFFF00) {
+ if (thread == m_threads[0] or retval == E_PAGEFAULT) {
exit();
} else {
//Simply unregister thread
diff --git a/Source/Kernel/TaskManager/Process.class.h b/Source/Kernel/TaskManager/Process.class.h
index 3b05f80..581d6b1 100644
--- a/Source/Kernel/TaskManager/Process.class.h
+++ b/Source/Kernel/TaskManager/Process.class.h
@@ -12,7 +12,7 @@
#define E_PAGEFAULT 0x0FFFFF00
#define E_ABORTED 0x0FFFFF01
-#define E_EXCEPTION 0x0FFFFF02
+#define E_UNHANDLED_EXCEPTION 0x0FFFFF02
#define STACKSIZE 4096 //Can change
diff --git a/Source/Kernel/TaskManager/Task.ns.cpp b/Source/Kernel/TaskManager/Task.ns.cpp
index 89e1b09..8a26133 100644
--- a/Source/Kernel/TaskManager/Task.ns.cpp
+++ b/Source/Kernel/TaskManager/Task.ns.cpp
@@ -55,7 +55,7 @@ void doSwitch() {
if (eip == 0x12345)
return;
- currentThread->setState(esp, ebp, eip);
+ if ((u32int)currentThread != 0xFFFFFFFF) currentThread->setState(esp, ebp, eip);
currentThread = nextThread();
currentProcess = currentThread->getProcess();
diff --git a/Source/Kernel/TaskManager/Thread.class.cpp b/Source/Kernel/TaskManager/Thread.class.cpp
index cc2f569..b5bb4e6 100644
--- a/Source/Kernel/TaskManager/Thread.class.cpp
+++ b/Source/Kernel/TaskManager/Thread.class.cpp
@@ -5,7 +5,8 @@
void runThread(Thread* thread, u32int (*entry_point)()) {
asm volatile("sti");
- thread->run(entry_point);
+ u32int ret = entry_point(); //Run !
+ asm volatile("mov %0, %%eax; int $66;" : : "r"(ret)); //Syscall for thread ending
}
Thread::Thread() { //Private constructor, does nothing
@@ -32,6 +33,7 @@ Thread::Thread(Process* process, u32int (*entry_point)()) {
}
Thread::~Thread() {
+ if (Task::currentThread == this) Task::currentThread = (Thread*)0xFFFFFFFF; //Signal that current thread is invalid
if (m_isKernel)
PageAlloc::free((void*)m_kernelStackFrame);
Task::unregisterThread(this);
@@ -57,17 +59,18 @@ void Thread::setup(u32int (*entry_point)(), u32int esp) {
}
void Thread::finish(u32int errcode) {
+ if (errcode == E_PAGEFAULT and m_isKernel) {
+ PANIC("Page fault in kernel thread !");
+ }
+ if (errcode == E_UNHANDLED_EXCEPTION and m_isKernel) {
+ PANIC("Unhandled exception in kernel thread !");
+ }
//Needs not set m_state to a finished state, either :
// - thread is unregistered from process and everywhere
// - errcode is an exception or this is main thread, process exits
m_process->threadFinishes(this, errcode);
}
-void Thread::run(u32int (*entry_point)()) {
- u32int ret = entry_point(); //Run !
- finish(ret);
-}
-
void Thread::setState(u32int esp, u32int ebp, u32int eip) {
m_esp = esp;
m_ebp = ebp;
@@ -88,7 +91,7 @@ void Thread::sleep(u32int msecs) {
}
void Thread::waitIRQ(u8int irq) {
- if (m_process->m_uid != 0) return;
+ if (!m_isKernel and !m_isRunningAnInterrupt) return;
m_state = T_IRQWAIT;
waitfor.m_irq = irq;
diff --git a/Source/Kernel/TaskManager/Thread.class.h b/Source/Kernel/TaskManager/Thread.class.h
index 62557db..63e5272 100644
--- a/Source/Kernel/TaskManager/Thread.class.h
+++ b/Source/Kernel/TaskManager/Thread.class.h
@@ -23,6 +23,7 @@ class Thread {
u8int m_irq; //An IRQ number
} waitfor;
+ bool m_isRunningAnInterrupt;
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
@@ -33,7 +34,6 @@ class Thread {
Thread(Process* process, u32int (*entry_point)());
~Thread();
void finish(u32int errcode); //Called by run() when thread returns, and by exception handler. Can also be called by the thread itself
- void run(u32int (*entry_point)());
void setState(u32int esp, u32int ebp, u32int eip);
u32int getEsp();
@@ -41,6 +41,9 @@ class Thread {
u32int getEip();
Process* getProcess();
+ inline void enterInterrupt() { m_isRunningAnInterrupt = true; }
+ inline void exitInterrupt() { m_isRunningAnInterrupt = false; }
+
void sleep(u32int msecs);
void waitIRQ(u8int irq);
bool runnable(); //Called by scheduler