From 60d68b74e1677510de0fb565750492960dedbe3a Mon Sep 17 00:00:00 2001 From: apio Date: Mon, 10 Jul 2023 20:30:37 +0200 Subject: [PATCH] kernel: Define a good set of default signals Most of these have POSIX-defined numbers. --- kernel/src/thread/Thread.cpp | 25 ++++++++++++++++++++----- libc/include/bits/signal.h | 18 +++++++++++++++++- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/kernel/src/thread/Thread.cpp b/kernel/src/thread/Thread.cpp index 6031fc55..d9b239a5 100644 --- a/kernel/src/thread/Thread.cpp +++ b/kernel/src/thread/Thread.cpp @@ -4,6 +4,7 @@ #include "thread/Scheduler.h" #include #include +#include #include #include #include @@ -106,26 +107,40 @@ enum class DefaultSignalAction }; static constexpr DefaultSignalAction default_actions[] = { - DefaultSignalAction::Terminate // SIGABRT + DefaultSignalAction::Terminate, // SIGHUP + DefaultSignalAction::Terminate, // SIGINT + DefaultSignalAction::Terminate, // SIGQUIT (dump core) + DefaultSignalAction::Terminate, // SIGILL (dump core) + DefaultSignalAction::Terminate, // SIGTRAP (dump core) + DefaultSignalAction::Terminate, // SIGABRT (dump core) + DefaultSignalAction::Ignore, // SIGCHLD + DefaultSignalAction::Terminate, // SIGFPE (dump core) + DefaultSignalAction::Terminate, // SIGKILL + DefaultSignalAction::Terminate, // SIGSTOP (FIXME: Support stopping and continuing) + DefaultSignalAction::Terminate, // SIGSEGV (dump core) + DefaultSignalAction::Ignore, // SIGCONT (FIXME: Support stopping and continuing) + DefaultSignalAction::Terminate, // SIGPIPE + DefaultSignalAction::Terminate, // SIGALRM + DefaultSignalAction::Terminate, // SIGTERM }; void Thread::process_pending_signals(Registers* current_regs) { for (int i = 0; i < NSIG; i++) { - if (signal_mask & (1 << i)) continue; + int signo = i + 1; + if (signo != SIGKILL && signo != SIGSTOP && signal_mask & (1 << i)) continue; if (pending_signals & (1 << i)) { - int signo = i + 1; pending_signals &= ~(1 << i); kinfoln("signal: executing signal %d for thread %ld", signo, id); auto handler = signal_handlers[i]; - if (handler.sa_handler == SIG_IGN) + if (signo != SIGKILL && signo != SIGSTOP && handler.sa_handler == SIG_IGN) { kinfoln("signal: ignoring signal (handler=SIG_IGN)"); return; } - if (handler.sa_handler == SIG_DFL) + if (handler.sa_handler == SIG_DFL || signo == SIGKILL || signo == SIGSTOP) { default_signal: if (id == 1) diff --git a/libc/include/bits/signal.h b/libc/include/bits/signal.h index c562c5a8..9cc47724 100644 --- a/libc/include/bits/signal.h +++ b/libc/include/bits/signal.h @@ -18,9 +18,25 @@ struct sigaction void* __sa_sigreturn = nullptr; }; +// The signals with explicit numbers have portable signal numbers. enum __signals { - SIGABRT = 1, + SIGHUP = 1, + SIGINT = 2, + SIGQUIT = 3, + SIGILL = 4, + SIGTRAP = 5, + SIGABRT = 6, + SIGCHLD, + SIGFPE = 8, + SIGKILL = 9, + SIGSTOP, + SIGSEGV = 11, + SIGCONT, + SIGPIPE = 13, + SIGALRM = 14, + SIGTERM = 15, + // FIXME: Add the remaining signals. __NSIG, };