summaryrefslogtreecommitdiff
path: root/src/kernel/task/task.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/task/task.cpp')
-rw-r--r--src/kernel/task/task.cpp19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/kernel/task/task.cpp b/src/kernel/task/task.cpp
index 92820f9..3998bfe 100644
--- a/src/kernel/task/task.cpp
+++ b/src/kernel/task/task.cpp
@@ -20,7 +20,7 @@ extern "C" uint32_t read_eip();
extern "C" void task_idle(void*);
static uint32_t nextpid = 1;
-process *processes = 0, *kernel_process;
+process *processes = 0, *kernel_process = 0, *current_process = 0;
thread *current_thread = 0, *idle_thread = 0;
uint32_t tasking_tmpStack[KSTACKSIZE];
@@ -78,8 +78,9 @@ void schedule() {
current_thread = sched_dequeue();
ASSERT(current_thread != 0);
+ current_process = current_thread->process;
- pagedir_switch(current_thread->process->pagedir);
+ pagedir_switch(current_process->pagedir);
gdt_setKernelStack(((uint32_t)current_thread->kernelStack_addr) + current_thread->kernelStack_size);
@@ -135,8 +136,8 @@ void thread::wakeUp() {
/* Returns the privilege level of the current process. */
int proc_priv() {
- if (current_thread == 0 || current_thread->process == 0) return PL_UNKNOWN;
- return current_thread->process->privilege;
+ if (current_thread == 0 || current_process == 0) return PL_UNKNOWN;
+ return current_process->privilege;
}
/* For internal use only. Called by thread_exit_stackJmp on a stack that will not be deleted.
@@ -272,7 +273,7 @@ thread::thread(class process *proc, thread_entry entry_point, void *data, void *
}
/* Creates a new process. Creates a struct process and fills it up. */
-process::process(process* _parent, uint32_t _uid, uint32_t _privilege) {
+process::process(process* _parent, uint32_t _uid, uint32_t _privilege) : fd(12, 64) {
pid = (nextpid++);
uid = _uid;
thread_count = 0;
@@ -284,6 +285,8 @@ process::process(process* _parent, uint32_t _uid, uint32_t _privilege) {
data = 0;
dataseg = 0;
+ fd.add((node*)-1); // descriptor #0 must not be used
+
stack = 0;
if (privilege >= PL_USER) { //We are running in user mode
size_t stacksBottom = K_HIGHHALF_ADDR - 0x01000000;
@@ -338,7 +341,7 @@ static void process_delete(process *pr) {
}
size_t process_sbrk(size_t size) {
- process *p = current_thread->process;
+ process *p = current_process;
if (p->data == 0) return -1;
ASSERT(p->data < K_HIGHHALF_ADDR);
if (p->data + size >= K_HIGHHALF_ADDR) return -1;
@@ -378,9 +381,7 @@ size_t process_sbrk(size_t size) {
}
void process_brk(size_t ptr) {
- process *p = current_thread->process;
-
ASSERT(ptr < K_HIGHHALF_ADDR);
- process_sbrk(ptr - p->data);
+ process_sbrk(ptr - current_process->data);
}