1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 10:27:35 +00:00

Kernel: Share code between all the exceptions that cause process crash.

This commit is contained in:
Andreas Kling 2019-06-25 05:55:18 +02:00
parent 583606a2b1
commit 048705e1c2

View file

@ -157,16 +157,16 @@ static void dump(const DumpType& regs)
} }
} }
// 6: Invalid Opcode template<typename RegisterDumpType>
EH_ENTRY_NO_CODE(6); static void handle_crash(RegisterDumpType& regs, const char* description, int signal)
void exception_6_handler(RegisterDump& regs)
{ {
if (!current) { if (!current) {
kprintf("#UD with !current\n"); kprintf("%s with !current\n", description);
hang(); hang();
} }
kprintf("%s Illegal instruction: %s(%u)\n", kprintf("CRASH: %s %s: %s(%u)\n",
description,
current->process().is_ring0() ? "Kernel" : "Process", current->process().is_ring0() ? "Kernel" : "Process",
current->process().name().characters(), current->process().name().characters(),
current->pid()); current->pid());
@ -179,7 +179,25 @@ void exception_6_handler(RegisterDump& regs)
hang(); hang();
} }
current->process().crash(SIGILL, regs.eip); current->process().crash(signal, regs.eip);
}
EH_ENTRY_NO_CODE(6);
void exception_6_handler(RegisterDump& regs)
{
handle_crash(regs, "Illegal instruction", SIGILL);
}
EH_ENTRY_NO_CODE(0);
void exception_0_handler(RegisterDump& regs)
{
handle_crash(regs, "Division by zero", SIGFPE);
}
EH_ENTRY(13);
void exception_13_handler(RegisterDumpWithExceptionCode& regs)
{
handle_crash(regs, "General protection fault", SIGSEGV);
} }
// 7: FPU not available exception // 7: FPU not available exception
@ -212,43 +230,6 @@ void exception_7_handler(RegisterDump& regs)
#endif #endif
} }
// 0: Divide error
EH_ENTRY_NO_CODE(0);
void exception_0_handler(RegisterDump& regs)
{
kprintf("%s Division by zero: %s(%u)\n",
current->process().is_ring0() ? "Kernel" : "User",
current->process().name().characters(),
current->pid());
dump(regs);
if (current->process().is_ring0()) {
kprintf("Oh shit, we've crashed in ring 0 :(\n");
dump_backtrace();
hang();
}
current->process().crash(SIGFPE, regs.eip);
}
// 13: General Protection Fault
EH_ENTRY(13);
void exception_13_handler(RegisterDumpWithExceptionCode& regs)
{
kprintf("%s GPF: %u(%s)\n", current->process().is_ring0() ? "Kernel" : "User", current->pid(), current->process().name().characters());
dump(regs);
if (current->process().is_ring0()) {
kprintf("Oh shit, we've crashed in ring 0 :(\n");
dump_backtrace();
hang();
}
current->process().crash(SIGSEGV, regs.eip);
}
// 14: Page Fault // 14: Page Fault
EH_ENTRY(14); EH_ENTRY(14);
void exception_14_handler(RegisterDumpWithExceptionCode& regs) void exception_14_handler(RegisterDumpWithExceptionCode& regs)
@ -298,8 +279,7 @@ void exception_14_handler(RegisterDumpWithExceptionCode& regs)
dbgprintf("\033[33;1mNote: Address %p looks like a possible nullptr dereference\033[0m\n", fault_address); dbgprintf("\033[33;1mNote: Address %p looks like a possible nullptr dereference\033[0m\n", fault_address);
} }
dump(regs); handle_crash(regs, "Page Fault", SIGSEGV);
current->process().crash(SIGSEGV, regs.eip);
} else if (response == PageFaultResponse::Continue) { } else if (response == PageFaultResponse::Continue) {
#ifdef PAGE_FAULT_DEBUG #ifdef PAGE_FAULT_DEBUG
dbgprintf("Continuing after resolved page fault\n"); dbgprintf("Continuing after resolved page fault\n");