1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:08:11 +00:00

Kernel: Dispatch handle-able signals instead of crashing if possible

This matches the behaviour of the other *nixs and allows processes to
try and recover from such signals in userland.
This commit is contained in:
Idan Horowitz 2021-11-30 01:07:59 +02:00
parent f415218afe
commit 40f64d7379
5 changed files with 23 additions and 10 deletions

View file

@ -215,10 +215,16 @@ static void dump(const RegisterState& regs)
void handle_crash(RegisterState const& regs, char const* description, int signal, bool out_of_memory)
{
if (!Process::has_current())
PANIC("{} with !current", description);
auto* current_thread = Thread::current();
if (!current_thread)
PANIC("{} with !Thread::current()", description);
auto& process = Process::current();
if (!current_thread->should_ignore_signal(signal) && !current_thread->is_signal_masked(signal)) {
current_thread->send_urgent_signal_to_self(signal);
return;
}
auto& process = current_thread->process();
// If a process crashed while inspecting another process,
// make sure we switch back to the right page tables.
@ -316,7 +322,7 @@ void page_fault_handler(TrapFrame* trap)
VirtualAddress userspace_sp = VirtualAddress { regs.userspace_sp() };
if (!faulted_in_kernel && !MM.validate_user_stack(current_thread->process().address_space(), userspace_sp)) {
dbgln("Invalid stack pointer: {}", userspace_sp);
handle_crash(regs, "Bad stack on page fault", SIGSEGV);
return handle_crash(regs, "Bad stack on page fault", SIGSEGV);
}
if (fault_address >= (FlatPtr)&start_of_ro_after_init && fault_address < (FlatPtr)&end_of_ro_after_init) {
@ -417,7 +423,7 @@ void page_fault_handler(TrapFrame* trap)
}
}
handle_crash(regs, "Page Fault", SIGSEGV, response == PageFaultResponse::OutOfMemory);
return handle_crash(regs, "Page Fault", SIGSEGV, response == PageFaultResponse::OutOfMemory);
} else if (response == PageFaultResponse::Continue) {
dbgln_if(PAGE_FAULT_DEBUG, "Continuing after resolved page fault");
} else {