X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/fa57b4a05aa12d594f40e0894e0ac6f810a7095c..45e1f8b055043e54be35462852ab6649d634da7c:/lunaix-os/kernel/process/signal.c diff --git a/lunaix-os/kernel/process/signal.c b/lunaix-os/kernel/process/signal.c index 9a9a349..9e46976 100644 --- a/lunaix-os/kernel/process/signal.c +++ b/lunaix-os/kernel/process/signal.c @@ -1,6 +1,3 @@ -#include -#include -#include #include #include #include @@ -8,8 +5,13 @@ #include #include +#include + extern struct scheduler sched_ctx; /* kernel/sched.c */ +extern void +_exit(int status); + void __USER__ default_sighandler_term(int signum) { @@ -18,12 +20,12 @@ default_sighandler_term(int signum) void* default_handlers[_SIG_NUM] = { // TODO: 添加默认handler - [_SIGINT] = default_sighandler_term, [_SIGTERM] = default_sighandler_term, - [_SIGKILL] = default_sighandler_term, [_SIGSEGV] = default_sighandler_term, [_SIGINT] = default_sighandler_term, + [_SIGTERM] = default_sighandler_term, + [_SIGKILL] = default_sighandler_term, + [_SIGSEGV] = default_sighandler_term, }; -volatile struct proc_sigstate __temp_save; // Referenced in kernel/asm/x86/interrupt.S void* signal_dispatch() @@ -44,13 +46,17 @@ signal_dispatch() return 0; } + // TODO: SIG{INT|TERM|KILL|SEGV} should have highest priority. + // Terminate the process right here if any of unmaskable signal is + // set. + if (!__current->sig_handler[sig_selected] && !default_handlers[sig_selected]) { // 如果该信号没有handler,则忽略 return 0; } - uintptr_t ustack = __current->ustack_top & ~0xf; + ptr_t ustack = __current->ustack_top & ~0xf; if ((int)(ustack - USTACK_END) < (int)sizeof(struct proc_sig)) { // 用户栈没有空间存放信号上下文 @@ -80,6 +86,7 @@ signal_dispatch() 解决办法就是先吧intr_ctx拷贝到一个静态分配的区域里,然后再注入到用户栈。 */ + static volatile struct proc_sigstate __temp_save; __temp_save.proc_regs = __current->intr_ctx; memcpy(__temp_save.fxstate, __current->fxstate, 512); @@ -146,6 +153,9 @@ __DEFINE_LXSYSCALL1(int, sigreturn, struct proc_sig, *sig_ctx) __current->flags &= ~PROC_FINPAUSE; __SIGCLEAR(__current->sig_inprogress, sig_ctx->sig_num); schedule(); + + // never reach! + return 0; } __DEFINE_LXSYSCALL3(int,