From a471243f83e6662550f954301865ac53d7a2acba Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Fri, 28 Nov 2014 01:42:41 +0100 Subject: [PATCH] added first version of userspace fork/kill support to new branch --- arch/x86/mm/page.c | 3 +-- include/eduos/tasks_types.h | 8 ++++++++ kernel/tasks.c | 15 ++++++++++++--- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/arch/x86/mm/page.c b/arch/x86/mm/page.c index a090d96..9dd1e99 100644 --- a/arch/x86/mm/page.c +++ b/arch/x86/mm/page.c @@ -175,7 +175,6 @@ int page_unmap(size_t viraddr, size_t npages) return 0; } -/* @todo: complete int page_map_drop() { void traverse(int lvl, long vpn) { @@ -246,7 +245,7 @@ int page_map_copy(size_t dest) spinlock_unlock(&kslock); return 0; -}*/ +} void page_fault_handler(struct state *s) { diff --git a/include/eduos/tasks_types.h b/include/eduos/tasks_types.h index c122c40..4185283 100644 --- a/include/eduos/tasks_types.h +++ b/include/eduos/tasks_types.h @@ -39,7 +39,9 @@ #include #include + #include +#include #ifdef __cplusplus extern "C" { @@ -73,6 +75,12 @@ typedef struct task { void* stack; /// Task priority uint8_t prio; + /// Physical address of root page table + size_t page_map; + /// Lock for page tables + spinlock_irqsave_t page_lock; + /// usage in number of pages (including page map tables) + atomic_int32_t user_usage; /// next task in the queue struct task* next; /// previous task in the queue diff --git a/kernel/tasks.c b/kernel/tasks.c index 4fdb0df..ed7d1d1 100644 --- a/kernel/tasks.c +++ b/kernel/tasks.c @@ -40,8 +40,8 @@ * 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, NULL}, \ - [1 ... MAX_TASKS-1] = {0, TASK_INVALID, NULL, NULL, 0, NULL, NULL}}; + [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}}; static spinlock_irqsave_t table_lock = SPINLOCK_IRQSAVE_INIT; @@ -53,7 +53,7 @@ extern const void boot_stack; /** @brief helper function for the assembly code to determine the current task * @return Pointer to the task_t structure of current task */ -task_t* get_current_task(void) +task_t* get_current_task(void) { return current_task; } @@ -160,6 +160,8 @@ void NORETURN abort(void) { } /** @brief Create a task with a specific entry point + * + * @todo Dont aquire table_lock for the whole task creation. * * @param id Pointer to a tid_t struct were the id shall be set * @param ep Pointer to the function the task shall start with @@ -192,6 +194,13 @@ 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]); if (id) *id = i;