2021-02-14 08:01:52 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2021-02-14 08:01:52 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <AK/Format.h>
|
2021-10-13 23:07:37 +00:00
|
|
|
#include <Kernel/Arch/Processor.h>
|
2022-10-04 00:05:54 +00:00
|
|
|
#if ARCH(X86_64)
|
2022-10-04 10:46:11 +00:00
|
|
|
# include <Kernel/Arch/x86_64/Shutdown.h>
|
2022-09-02 06:45:30 +00:00
|
|
|
#endif
|
2021-07-25 19:40:41 +00:00
|
|
|
#include <Kernel/CommandLine.h>
|
2021-02-14 08:01:52 +00:00
|
|
|
#include <Kernel/KSyms.h>
|
|
|
|
#include <Kernel/Panic.h>
|
2021-09-07 07:17:45 +00:00
|
|
|
#include <Kernel/Thread.h>
|
2021-02-14 08:01:52 +00:00
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
2021-07-26 18:34:43 +00:00
|
|
|
[[noreturn]] static void __shutdown()
|
2021-07-25 19:40:41 +00:00
|
|
|
{
|
2022-10-04 00:05:54 +00:00
|
|
|
#if ARCH(X86_64)
|
2022-09-02 06:45:30 +00:00
|
|
|
qemu_shutdown();
|
2022-09-02 07:17:55 +00:00
|
|
|
virtualbox_shutdown();
|
2022-09-02 06:45:30 +00:00
|
|
|
#endif
|
|
|
|
// Note: If we failed to invoke platform shutdown, we need to halt afterwards
|
|
|
|
// to ensure no further execution on any CPU still happens.
|
2021-07-26 18:34:43 +00:00
|
|
|
Processor::halt();
|
2021-07-25 19:40:41 +00:00
|
|
|
}
|
|
|
|
|
2022-04-01 17:58:27 +00:00
|
|
|
void __panic(char const* file, unsigned int line, char const* function)
|
2021-02-14 08:01:52 +00:00
|
|
|
{
|
2021-09-07 07:17:45 +00:00
|
|
|
// Avoid lock ranking checks on crashing paths, just try to get some debugging messages out.
|
2021-12-29 00:01:27 +00:00
|
|
|
auto* thread = Thread::current();
|
2021-09-07 07:17:45 +00:00
|
|
|
if (thread)
|
|
|
|
thread->set_crashing();
|
|
|
|
|
2021-04-16 19:58:51 +00:00
|
|
|
critical_dmesgln("at {}:{} in {}", file, line, function);
|
2021-08-04 15:52:14 +00:00
|
|
|
dump_backtrace(PrintToScreen::Yes);
|
2022-01-21 09:36:32 +00:00
|
|
|
if (!CommandLine::was_initialized())
|
|
|
|
Processor::halt();
|
2021-10-23 15:31:00 +00:00
|
|
|
switch (kernel_command_line().panic_mode()) {
|
|
|
|
case PanicMode::Shutdown:
|
2021-07-26 18:34:43 +00:00
|
|
|
__shutdown();
|
2021-10-23 15:31:00 +00:00
|
|
|
case PanicMode::Halt:
|
|
|
|
[[fallthrough]];
|
|
|
|
default:
|
2021-07-25 19:40:41 +00:00
|
|
|
Processor::halt();
|
2021-10-23 15:31:00 +00:00
|
|
|
}
|
2021-02-14 08:01:52 +00:00
|
|
|
}
|
|
|
|
}
|