mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 15:48:12 +00:00
Kernel: Share CrashHandler.cpp between aarch64 and x86_64
This file contains no architecture specific code, so can be moved to the Kernel/ directory, and thus shared between aarch64 and x86_64.
This commit is contained in:
parent
7ba9bc6338
commit
816076f71a
3 changed files with 2 additions and 22 deletions
45
Kernel/CrashHandler.cpp
Normal file
45
Kernel/CrashHandler.cpp
Normal file
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <Kernel/Arch/CPU.h>
|
||||
#include <Kernel/Arch/RegisterState.h>
|
||||
|
||||
#include <Kernel/Panic.h>
|
||||
#include <Kernel/Process.h>
|
||||
#include <Kernel/Thread.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
void handle_crash(Kernel::RegisterState const& regs, char const* description, int signal, bool out_of_memory)
|
||||
{
|
||||
auto* current_thread = Thread::current();
|
||||
if (!current_thread)
|
||||
PANIC("{} with !Thread::current()", description);
|
||||
|
||||
auto crashed_in_kernel = regs.previous_mode() == ExecutionMode::Kernel;
|
||||
if (!crashed_in_kernel && current_thread->has_signal_handler(signal) && !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.
|
||||
Memory::MemoryManager::enter_process_address_space(process);
|
||||
|
||||
dmesgln("CRASH: CPU #{} {} in {}", Processor::current_id(), description, regs.previous_mode() == ExecutionMode::Kernel ? "kernel"sv : "userspace"sv);
|
||||
dump_registers(regs);
|
||||
|
||||
if (crashed_in_kernel) {
|
||||
process.address_space().with([&](auto& space) { space->dump_regions(); });
|
||||
PANIC("Crash in kernel");
|
||||
}
|
||||
|
||||
process.crash(signal, regs.ip(), out_of_memory);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue