summaryrefslogtreecommitdiff
path: root/Source/Kernel/TaskManager/Process.class.cpp
diff options
context:
space:
mode:
authorAlexis211 <alexis211@gmail.com>2009-08-29 13:39:06 +0200
committerAlexis211 <alexis211@gmail.com>2009-08-29 13:39:06 +0200
commitc92beeedda51487696ce476ee30604f22e7b2270 (patch)
tree29b89d31b0b35792e1ed2bc5861be0439e7e40d9 /Source/Kernel/TaskManager/Process.class.cpp
parent5deab22107fc38bd2bea19f07889b14c376754e0 (diff)
downloadMelon-c92beeedda51487696ce476ee30604f22e7b2270.tar.gz
Melon-c92beeedda51487696ce476ee30604f22e7b2270.zip
The Melon kernel now has support for simple multitasking
Diffstat (limited to 'Source/Kernel/TaskManager/Process.class.cpp')
-rw-r--r--Source/Kernel/TaskManager/Process.class.cpp85
1 files changed, 85 insertions, 0 deletions
diff --git a/Source/Kernel/TaskManager/Process.class.cpp b/Source/Kernel/TaskManager/Process.class.cpp
new file mode 100644
index 0000000..5330719
--- /dev/null
+++ b/Source/Kernel/TaskManager/Process.class.cpp
@@ -0,0 +1,85 @@
+#include "Process.class.h"
+#include <TaskManager/Task.ns.h>
+#include <MemoryManager/PhysMem.ns.h>
+
+Process::Process() { //Private constructor, does nothing
+}
+
+Process* Process::createKernel(String cmdline) {
+ Process* p = new Process();
+ p->m_pid = 0;
+ p->m_cmdline = cmdline;
+ p->m_retval = 0;
+ p->m_state = P_RUNNING;
+ p->m_pagedir = kernelPageDirectory;
+ p->m_uid = 0;
+ p->m_stacksstart = 0;
+
+ Thread* t = new Thread();
+ t->m_process = p;
+ t->m_state = T_RUNNING;
+ t->m_isKernel = true;
+ t->m_kernelStackFrame = 0;
+
+ p->registerThread(t);
+ Task::registerProcess(p);
+ Task::registerThread(t);
+
+ return p;
+}
+
+Process::Process(String cmdline, u32int uid) {
+ m_pid = Task::nextPid();
+ m_cmdline = cmdline;
+ m_retval = 0;
+ m_state = P_RUNNING;
+ m_pagedir = new PageDirectory(kernelPageDirectory);
+ m_uid = uid;
+ m_stacksstart = 0xC0000000;
+}
+
+Process::~Process() { //TODO : clean up process
+ exit(); //Kill all threads
+ delete m_pagedir;
+}
+
+u32int Process::stackAlloc() {
+ if (m_stacksstart < STACKSIZE) return 0;
+ for (u32int i = m_stacksstart - STACKSIZE; i < m_stacksstart; i += 0x1000) {
+ m_pagedir->allocFrame(i & 0xFFFFF000, true, true);
+ }
+ m_stacksstart -= STACKSIZE;
+ return m_stacksstart;
+}
+
+void Process::exit() {
+ while (!m_threads.empty()) {
+ delete m_threads.back();
+ m_threads.pop();
+ }
+ m_state = P_FINISHED;
+}
+
+void Process::registerThread(Thread* t) {
+ if (m_state != P_FINISHED)
+ m_threads.push(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) {
+ exit();
+ } else {
+ //Simply unregister thread
+ for (u32int i = 0; i < m_threads.size(); i++) {
+ if (m_threads[i] == thread) {
+ m_threads[i] = m_threads.back();
+ m_threads.pop();
+ }
+ }
+ }
+}
+
+PageDirectory* Process::getPagedir() {
+ return m_pagedir;
+}