1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:57:45 +00:00

Kernel: Send more specific signals when crashing due to CPU exceptions.

- For division by zero, send SIGFPE.
- For illegal instruction, send SIGILL.
- For the rest, default to SIGSEGV.
This commit is contained in:
Andreas Kling 2019-05-26 02:08:51 +02:00
parent 0fa098845f
commit 6ffcee9176
3 changed files with 17 additions and 9 deletions

View file

@ -720,14 +720,14 @@ void Process::sys$sigreturn()
ASSERT_NOT_REACHED();
}
void Process::crash()
void Process::crash(int signal)
{
ASSERT_INTERRUPTS_DISABLED();
ASSERT(!is_dead());
dump_backtrace();
m_termination_signal = SIGSEGV;
m_termination_signal = signal;
dump_regions();
ASSERT(is_ring3());
die();

View file

@ -13,6 +13,7 @@
#include <Kernel/UnixTypes.h>
#include <Kernel/Thread.h>
#include <Kernel/Lock.h>
#include <LibC/signal_numbers.h>
class ELFLoader;
class FileDescriptor;
@ -191,7 +192,7 @@ public:
static void initialize();
[[noreturn]] void crash();
[[noreturn]] void crash(int signal = SIGSEGV);
[[nodiscard]] static int reap(Process&);
const TTY* tty() const { return m_tty; }

View file

@ -167,19 +167,22 @@ void exception_6_handler(RegisterDump& regs)
kprintf("#UD with !current\n");
hang();
}
kprintf("%s invalid opcode: %u(%s)\n", current->process().is_ring0() ? "Kernel" : "Process", current->pid(), current->process().name().characters());
kprintf("%s Illegal instruction: %s(%u)\n",
current->process().is_ring0() ? "Kernel" : "Process",
current->process().name().characters(),
current->pid()
);
dump(regs);
dump_backtrace();
if (current->process().is_ring0()) {
kprintf("Oh shit, we've crashed in ring 0 :(\n");
hang();
}
hang();
current->process().crash();
current->process().crash(SIGILL);
}
// 7: FPU not available exception
@ -216,7 +219,11 @@ void exception_7_handler(RegisterDump& regs)
EH_ENTRY_NO_CODE(0);
void exception_0_handler(RegisterDump& regs)
{
kprintf("%s DIVIDE ERROR: %u(%s)\n", current->process().is_ring0() ? "Kernel" : "User", current->pid(), current->process().name().characters());
kprintf("%s Division by zero: %s(%u)\n",
current->process().is_ring0() ? "Kernel" : "User",
current->process().name().characters(),
current->pid()
);
dump(regs);
@ -225,7 +232,7 @@ void exception_0_handler(RegisterDump& regs)
hang();
}
current->process().crash();
current->process().crash(SIGFPE);
}