From bb1a5fc74769301c0a792cb83d3fa0bda8a780cb Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Mon, 2 Mar 2015 23:30:16 +0100 Subject: Add prototypes for process management... --- src/kernel/user/process.c | 39 ++++++++++++++++++++++++++++++++++----- src/kernel/user/syscall.c | 5 ----- 2 files changed, 34 insertions(+), 10 deletions(-) (limited to 'src/kernel/user') diff --git a/src/kernel/user/process.c b/src/kernel/user/process.c index 3f8da08..649c801 100644 --- a/src/kernel/user/process.c +++ b/src/kernel/user/process.c @@ -17,6 +17,11 @@ process_t *current_process() { return 0; } +typedef struct { + proc_entry_t entry; + void *sp; +} setup_data_t; + // ============================== // // CREATING AND RUNNING PROCESSES // // ============================== // @@ -39,7 +44,7 @@ process_t *new_process(process_t *parent) { proc->last_ran = 0; proc->regions = 0; - proc->thread = 0; + proc->threads = 0; proc->pid = (next_pid++); proc->parent = parent; proc->next_fd = 1; @@ -54,13 +59,17 @@ error: return 0; } -static void run_user_code(void* entry) { +static void run_user_code(void* param) { + setup_data_t *d = (setup_data_t*)param; + process_t *proc = current_thread->proc; ASSERT(proc != 0); switch_pagedir(proc->pd); - void* esp = (void*)USERSTACK_ADDR + USERSTACK_SIZE; + void* esp = d->sp; + proc_entry_t entry = d->entry; + free(d); asm volatile(" \ cli; \ @@ -86,14 +95,34 @@ bool start_process(process_t *p, void* entry) { bool stack_ok = mmap(p, (void*)USERSTACK_ADDR, USERSTACK_SIZE, MM_READ | MM_WRITE); if (!stack_ok) return false; - thread_t *th = new_thread(run_user_code, entry); - if (th == 0) { + bool ok = process_new_thread(p, entry, (void*)USERSTACK_ADDR + USERSTACK_SIZE); + if (!ok) { munmap(p, (void*)USERSTACK_ADDR); return false; } + return true; +} + +bool process_new_thread(process_t *p, proc_entry_t entry, void* sp) { + setup_data_t *d = (setup_data_t*)malloc(sizeof(setup_data_t)); + d->entry = entry; + d->sp = sp; + + thread_t *th = new_thread(run_user_code, d); + if (th == 0) { + return false; + } + th->proc = p; th->user_ex_handler = proc_user_exception; + + { int st = enter_critical(CL_NOINT); // it's a bit complicated to use mutexes on process_t (TODO: think) + + th->next_in_proc = p->threads; + p->threads = th; + + exit_critical(st); } resume_thread(th); diff --git a/src/kernel/user/syscall.c b/src/kernel/user/syscall.c index 3041c6d..009903c 100644 --- a/src/kernel/user/syscall.c +++ b/src/kernel/user/syscall.c @@ -319,10 +319,6 @@ static uint32_t proc_wait_sc(sc_args_t args) { return -1; //TODO } -static uint32_t proc_wait_any_sc(sc_args_t args) { - return -1; //TODO -} - // ====================== // // SYSCALLS SETUP ROUTINE // // ====================== // @@ -365,7 +361,6 @@ void setup_syscall_table() { sc_handlers[SC_PROC_STATUS] = proc_status_sc; sc_handlers[SC_PROC_KILL] = proc_kill_sc; sc_handlers[SC_PROC_WAIT] = proc_wait_sc; - sc_handlers[SC_PROC_WAIT_ANY] = proc_wait_any_sc; } void syscall_handler(registers_t *regs) { -- cgit v1.2.3