summaryrefslogtreecommitdiff
path: root/Source/Kernel/TaskManager
diff options
context:
space:
mode:
authorAlexis211 <alexis211@gmail.com>2009-10-17 12:59:11 +0200
committerAlexis211 <alexis211@gmail.com>2009-10-17 12:59:11 +0200
commit45fcf4cc7ddacd93df2dd4d88ad31f6061e8d4a8 (patch)
tree4f1a3b3d301cded70af6ff9177d13b8a51f2d825 /Source/Kernel/TaskManager
parent54d76800cf8010434065556e12f693b101383d8b (diff)
parent82756b86977dc65468f6298787d8dca5634ac788 (diff)
downloadMelon-45fcf4cc7ddacd93df2dd4d88ad31f6061e8d4a8.tar.gz
Melon-45fcf4cc7ddacd93df2dd4d88ad31f6061e8d4a8.zip
Merge branch 'heap_class'
Conflicts: Source/Kernel/Melon.ke
Diffstat (limited to 'Source/Kernel/TaskManager')
-rw-r--r--Source/Kernel/TaskManager/Process.class.cpp23
-rw-r--r--Source/Kernel/TaskManager/Process.class.h14
-rw-r--r--Source/Kernel/TaskManager/Task.ns.cpp2
-rw-r--r--Source/Kernel/TaskManager/Thread.class.cpp4
4 files changed, 24 insertions, 19 deletions
diff --git a/Source/Kernel/TaskManager/Process.class.cpp b/Source/Kernel/TaskManager/Process.class.cpp
index 2706986..d7fba80 100644
--- a/Source/Kernel/TaskManager/Process.class.cpp
+++ b/Source/Kernel/TaskManager/Process.class.cpp
@@ -3,6 +3,10 @@
#include <MemoryManager/PhysMem.ns.h>
#include <VFS/File.class.h>
+namespace Mem {
+ extern Heap kheap;
+}
+
Process::Process() { //Private constructor, does nothing
}
@@ -14,7 +18,7 @@ Process* Process::createKernel(String cmdline, VirtualTerminal *vt) {
p->m_state = P_RUNNING;
p->m_pagedir = kernelPageDirectory;
p->m_uid = 0;
- p->m_stacksstart = 0;
+ p->m_userHeap = &Mem::kheap;
p->m_vt = vt;
Thread* t = new Thread();
@@ -35,24 +39,19 @@ Process::Process(String cmdline, u32int uid) {
m_cmdline = cmdline;
m_retval = 0;
m_state = P_RUNNING;
- m_pagedir = new PageDirectory(kernelPageDirectory);
m_uid = uid;
m_vt = Task::currProcess()->getVirtualTerminal();
- m_stacksstart = 0xC0000000;
+ //Create page directory and user heap
+ m_pagedir = new PageDirectory(kernelPageDirectory);
+ m_userHeap = new Heap();
+ u32int heapIdxSize = PhysMem::total() * 16 + 0x10000;
+ m_userHeap->create(USERHEAPSTART, USERHEAPINITSIZE + heapIdxSize, heapIdxSize, m_pagedir, true, true);
}
Process::~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;
+ delete m_userHeap;
}
void Process::exit() {
diff --git a/Source/Kernel/TaskManager/Process.class.h b/Source/Kernel/TaskManager/Process.class.h
index b975db1..ac9614e 100644
--- a/Source/Kernel/TaskManager/Process.class.h
+++ b/Source/Kernel/TaskManager/Process.class.h
@@ -5,6 +5,7 @@
#include <Library/Vector.class.h>
#include <Library/SimpleList.class.h>
#include <MemoryManager/PageDirectory.class.h>
+#include <MemoryManager/Heap.class.h>
#include <VTManager/VirtualTerminal.proto.h>
#define P_ZOMBIE 0
@@ -15,7 +16,10 @@
#define E_ABORTED 0x0FFFFF01
#define E_UNHANDLED_EXCEPTION 0x0FFFFF02
-#define STACKSIZE 4096 //Can change
+#define STACKSIZE 4096 //Could change
+
+#define USERHEAPINITSIZE 0x00010000 //Heap initially is 64k, but can grow
+#define USERHEAPSTART 0xB7000000 //Heap is at 0xB7000000, 128Mo before kernel space.
class Thread;
class File;
@@ -32,9 +36,10 @@ class Process {
u8int m_state; //Is one of P_* defined above
PageDirectory* m_pagedir;
u32int m_uid; //User ID
- u32int m_stacksstart;
VirtualTerminal *m_vt;
+ Heap *m_userHeap;
+
Vector<Thread*> m_threads;
SimpleList<File*> *m_fileDescriptors;
@@ -43,8 +48,9 @@ class Process {
Process(String cmdline, u32int uid);
~Process();
- u32int stackAlloc(); //Allocates pages for STACKSIZE bytes at end of app memory (just before 0xC0000000)
- void exit(); //Exits properly process by killing all threads
+ Heap& heap() { return *m_userHeap; }
+
+ void exit(); //Exits properly process by killing all threads and deleting file descriptors
void registerThread(Thread* t); //Called when a thread starts
void threadFinishes(Thread* thread, u32int retval); //Called when a thread finishes
diff --git a/Source/Kernel/TaskManager/Task.ns.cpp b/Source/Kernel/TaskManager/Task.ns.cpp
index 66eca94..a34f14f 100644
--- a/Source/Kernel/TaskManager/Task.ns.cpp
+++ b/Source/Kernel/TaskManager/Task.ns.cpp
@@ -3,7 +3,7 @@
#include <MemoryManager/PhysMem.ns.h>
#define INVALID_TASK_MAGIC 0xBEEFFEED
-#define TEMP_STACK_SIZE 128 //This must be big enough so that we can call all we need to call when a task finishes
+#define TEMP_STACK_SIZE 256 //This must be big enough so that we can call all we need to call when a task finishes
//From Task.wtf.asm
extern "C" u32int read_eip();
diff --git a/Source/Kernel/TaskManager/Thread.class.cpp b/Source/Kernel/TaskManager/Thread.class.cpp
index fe1d08e..20d6cd4 100644
--- a/Source/Kernel/TaskManager/Thread.class.cpp
+++ b/Source/Kernel/TaskManager/Thread.class.cpp
@@ -22,14 +22,14 @@ Thread::Thread(thread_entry_t entry_point, void* data, bool iskernel) {
} else {
m_isKernel = false;
m_process = Task::currProcess();
- setup(entry_point, data, m_process->stackAlloc() + STACKSIZE);
+ setup(entry_point, data, (u32int)(m_process->heap().alloc(STACKSIZE)) + STACKSIZE);
}
}
Thread::Thread(Process* process, thread_entry_t entry_point, void* data) {
m_isKernel = false;
m_process = process;
- setup(entry_point, data, m_process->stackAlloc() + STACKSIZE);
+ setup(entry_point, data, (u32int)(m_process->heap().alloc(STACKSIZE)) + STACKSIZE);
}
Thread::~Thread() {