diff --git a/Kernel/Task.cpp b/Kernel/Task.cpp index d4bc4621143..165a8144651 100644 --- a/Kernel/Task.cpp +++ b/Kernel/Task.cpp @@ -169,10 +169,26 @@ Task::Task(void (*e)(), const char* n, IPC::Handle h, RingLevel ring) Task::~Task() { + system.nprocess--; delete [] m_ldtEntries; m_ldtEntries = nullptr; } +void Task::taskDidCrash(Task* crashedTask) +{ + crashedTask->setState(Crashing); + s_tasks->remove(crashedTask); + + if (!scheduleNewTask()) { + kprintf("Task::taskDidCrash: Failed to schedule a new task :(\n"); + HANG; + } + + delete crashedTask; + + switchNow(); +} + void yield() { if (!current) { diff --git a/Kernel/Task.h b/Kernel/Task.h index 7b39f85f8d6..3498a950d07 100644 --- a/Kernel/Task.h +++ b/Kernel/Task.h @@ -95,6 +95,8 @@ public: static void initialize(); void setError(int); + static void taskDidCrash(Task*); + private: FileHandle* openFile(String&&); diff --git a/Kernel/i386.cpp b/Kernel/i386.cpp index 6e7368fab08..f455eaa8c92 100644 --- a/Kernel/i386.cpp +++ b/Kernel/i386.cpp @@ -84,13 +84,8 @@ void exception_13_handler() HANG; } - current->setState(Task::Crashing); - if (!scheduleNewTask()) { - kprintf("Failed to schedule a new task :(\n"); - HANG; - } - - switchNow(); + // NOTE: This will schedule a new task. + Task::taskDidCrash(current); } #define EH(i, msg) \