From 82756b86977dc65468f6298787d8dca5634ac788 Mon Sep 17 00:00:00 2001 From: Alexis211 Date: Sat, 17 Oct 2009 12:54:48 +0200 Subject: Each Process now has a user heap. It will be used for transferring data from kernel to userland. --- Source/Kernel/TaskManager/Process.class.cpp | 23 +++++++++++------------ Source/Kernel/TaskManager/Process.class.h | 14 ++++++++++---- Source/Kernel/TaskManager/Task.ns.cpp | 2 +- Source/Kernel/TaskManager/Thread.class.cpp | 4 ++-- 4 files changed, 24 insertions(+), 19 deletions(-) (limited to 'Source/Kernel/TaskManager') 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 #include +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 #include #include +#include #include #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 m_threads; SimpleList *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 #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() { -- cgit v1.2.3