From 2cf3c89a40f65992a1edbd01296fd13346a8add8 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Fri, 28 Nov 2014 03:20:31 +0100 Subject: [PATCH] fixed syntax errors and compiler warnings in new branch --- arch/x86/mm/page.c | 11 ++++++++--- kernel/tasks.c | 20 +++++++++++++++----- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/arch/x86/mm/page.c b/arch/x86/mm/page.c index ecb0029..af813a6 100644 --- a/arch/x86/mm/page.c +++ b/arch/x86/mm/page.c @@ -58,6 +58,12 @@ static size_t* self[PAGE_LEVELS] = { (size_t *) 0xFFFFF000 }; +/** An other self-reference for page_map_copy() */ +static size_t * other[PAGE_LEVELS] = { + (size_t *) 0xFF800000, + (size_t *) 0xFFFFE000 +}; + /* Addresses of child/parent tables */ #define CHILD(map, lvl, vpn) &map[lvl-1][vpn<>PAGE_MAP_BITS] @@ -184,9 +190,8 @@ int page_map_copy(size_t dest) if (BUILTIN_EXPECT(phyaddr, 0)) return -ENOMEM; - - new[lvl][vpn] = phyaddr; - new[lvl][vpn] |= self[lvl][vpn] & ~PAGE_MASK; + other[lvl][vpn] = phyaddr; + other[lvl][vpn] |= self[lvl][vpn] & ~PAGE_MASK; memcpy(CHILD(other, lvl, vpn), CHILD(self, lvl, vpn), PAGE_SIZE); diff --git a/kernel/tasks.c b/kernel/tasks.c index ed7d1d1..178f6f2 100644 --- a/kernel/tasks.c +++ b/kernel/tasks.c @@ -34,14 +34,17 @@ #include #include #include +#include + +#include /** @brief Array of task structures (aka PCB) * * A task's id will be its position in this array. */ static task_t task_table[MAX_TASKS] = { \ - [0] = {0, TASK_IDLE, NULL, NULL, 0, NULL, SPINLOCK_IRQSAVE_INIT, ATOMIC_INIT(0), NULL, NULL}, \ - [1 ... MAX_TASKS-1] = {0, TASK_INVALID, NULL, NULL, 0, NULL, SPINLOCK_IRQSAVE_INIT, ATOMIC_INIT(0), NULL, NULL}}; + [0] = {0, TASK_IDLE, NULL, NULL, 0, 0, SPINLOCK_IRQSAVE_INIT, ATOMIC_INIT(0), NULL, NULL}, \ + [1 ... MAX_TASKS-1] = {0, TASK_INVALID, NULL, NULL, 0, 0, SPINLOCK_IRQSAVE_INIT, ATOMIC_INIT(0), NULL, NULL}}; static spinlock_irqsave_t table_lock = SPINLOCK_IRQSAVE_INIT; @@ -118,6 +121,8 @@ static void NORETURN do_exit(int arg) kprintf("Terminate task: %u, return value %d\n", curr_task->id, arg); + page_map_drop(); + curr_task->status = TASK_FINISHED; reschedule(); @@ -194,13 +199,17 @@ static int create_task(tid_t* id, entry_point_t ep, void* arg, uint8_t prio) task_table[i].last_stack_pointer = NULL; task_table[i].stack = create_stack(i); task_table[i].prio = prio; - task_table[i].page_map = get_pages(1); - /** @todo: Check if get_pages(1) was successful */ spinlock_irqsave_init(&task_table[i].page_lock); atomic_int32_set(&task_table[i].user_usage, 0); - //page_map_copy(&task_table[i]); + /* Allocated new PGD or PML4 and copy page table */ + size_t map = get_pages(1); + if (BUILTIN_EXPECT(map, 0)) + goto out; + + page_map_copy(map); + task_table[i].page_map = map; if (id) *id = i; @@ -226,6 +235,7 @@ static int create_task(tid_t* id, entry_point_t ep, void* arg, uint8_t prio) } } +out: spinlock_irqsave_unlock(&table_lock); return ret;