From b9102619393b4702a6fd32efab6e74c18e338753 Mon Sep 17 00:00:00 2001 From: Matthias Kruk Date: Sun, 5 Jan 2020 16:50:48 +0900 Subject: [PATCH] Add process_get_sighandler() function --- kernel/core/process.c | 48 +++++++++++++++++++++++++++++++++------- kernel/include/process.h | 2 ++ 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/kernel/core/process.c b/kernel/core/process.c index 23335e2..3102317 100644 --- a/kernel/core/process.c +++ b/kernel/core/process.c @@ -497,7 +497,6 @@ int process_memcpy_ktop(process_t *proc, void *dst, void *src, u32_t bytes) { int ret_val; - dbg_printf("pg_dir_memcpy(%p, %p, NULL, %p, 0x%08x)\n", proc, dst, src, bytes); ret_val = pg_dir_memcpy(proc->p_pgdir, dst, NULL, src, bytes); return(ret_val); @@ -761,6 +760,7 @@ int process_signal_deliver(process_t *proc, int signal) } } } else { + dbg_printf("Signal to current task\n"); /* handle the signal in the current task */ task = task_get_current(); } @@ -779,16 +779,28 @@ int process_signal_deliver(process_t *proc, int signal) * we can use it without having to perform any translations. The usermode * stack will have to be translated though. */ - vesp3 = (u32_t*)kstk->prevesp; - ret_val = _pg_dir_vpxlate((struct pagedir*)task->t_pgdir, - (u32_t)vesp3, (u32_t*)&pesp3); - if(!ret_val) { - u32_t *parg0; - u32_t *peip; +// vesp3 = (u32_t*)kstk->prevesp; +// ret_val = _pg_dir_vpxlate((struct pagedir*)task->t_pgdir, +// (u32_t)vesp3, (u32_t*)&pesp3); - /* push the signal number and the return address on the userspace stack */ + if(!ret_val) { + /* + * The stack frame for the signal handler should look something like this: + * + * | ... | + * |-----| + * | EIP | + * | EBP | + * + * + * We need space for two registers and the stack frame of the signal + * handler. We will make use of process_memcpy_ktop() for simplicity's + * sake. + */ + /* ...and just return from the interrupt. Done. */ +#if 0 /* * pesp3, pesp3 - 1, and pesp3 - 2 may not be on the same page, which would * be an atrociously hard-to-find bug. @@ -837,6 +849,7 @@ int process_signal_deliver(process_t *proc, int signal) */ kstk->eip = (u32_t)proc->p_sighandler[signal]; kstk->prevesp -= (sizeof(kstk->prevesp) * 2); +#endif /* 0 */ } /* let the process continue execution */ @@ -857,24 +870,32 @@ cleanup: */ static void _sig_term(int sig) { + debug(__func__, strlen(__func__)); + _exit(sig); return; } static void _sig_ign(int sig) { + debug(__func__, strlen(__func__)); + /* do nothing */ return; } static void _sig_core(int sig) { + debug(__func__, strlen(__func__)); + _exit(sig); return; } static void _sig_stop(int sig) { + debug(__func__, strlen(__func__)); + /* * FIXME: Stop the process * - Change the process state @@ -889,6 +910,8 @@ static void _sig_stop(int sig) static void _sig_cont(int sig) { + debug(__func__, strlen(__func__)); + /* * FIXME: Continue the process * - Change its state back to a runnable state @@ -1012,3 +1035,12 @@ int process_task_foreach(process_t *proc, int (*func)(process_t*, task_t*, void* return(ret_val); } + +void* process_get_sighandler(process_t *proc, int signal) +{ + if(signal < 0 || signal > SIGMAX) { + return(NULL); + } + + return((void*)proc->p_sighandler[signal]); +} diff --git a/kernel/include/process.h b/kernel/include/process.h index c249709..ce2a108 100644 --- a/kernel/include/process.h +++ b/kernel/include/process.h @@ -48,6 +48,8 @@ int process_wait(pid_t); int process_signal(pid_t); int process_signal_deliver(process_t*, int); +void* process_get_sighandler(process_t*, int); + void* process_get_tasks(process_t*); pid_t process_get_id(process_t*); int process_exit(process_t*, int); -- 2.47.3