kernel: Define a good set of default signals

Most of these have POSIX-defined numbers.
This commit is contained in:
apio 2023-07-10 20:30:37 +02:00
parent cde467ee46
commit 60d68b74e1
Signed by: apio
GPG Key ID: B8A7D06E42258954
2 changed files with 37 additions and 6 deletions

View File

@ -4,6 +4,7 @@
#include "thread/Scheduler.h"
#include <bits/atfile.h>
#include <bits/open-flags.h>
#include <bits/signal.h>
#include <bits/waitpid.h>
#include <luna/Alloc.h>
#include <luna/Atomic.h>
@ -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)

View File

@ -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,
};