Serenity Operating System
at master 50 lines 1.3 kB view raw
1/* 2 * Copyright (c) 2021, Andreas Kling <kling@serenityos.org> 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7#include <AK/Format.h> 8#include <Kernel/Arch/Processor.h> 9#if ARCH(X86_64) 10# include <Kernel/Arch/x86_64/Shutdown.h> 11#endif 12#include <Kernel/CommandLine.h> 13#include <Kernel/KSyms.h> 14#include <Kernel/Panic.h> 15#include <Kernel/Thread.h> 16 17namespace Kernel { 18 19[[noreturn]] static void __shutdown() 20{ 21#if ARCH(X86_64) 22 qemu_shutdown(); 23 virtualbox_shutdown(); 24#endif 25 // Note: If we failed to invoke platform shutdown, we need to halt afterwards 26 // to ensure no further execution on any CPU still happens. 27 Processor::halt(); 28} 29 30void __panic(char const* file, unsigned int line, char const* function) 31{ 32 // Avoid lock ranking checks on crashing paths, just try to get some debugging messages out. 33 auto* thread = Thread::current(); 34 if (thread) 35 thread->set_crashing(); 36 37 critical_dmesgln("at {}:{} in {}", file, line, function); 38 dump_backtrace(PrintToScreen::Yes); 39 if (!CommandLine::was_initialized()) 40 Processor::halt(); 41 switch (kernel_command_line().panic_mode()) { 42 case PanicMode::Shutdown: 43 __shutdown(); 44 case PanicMode::Halt: 45 [[fallthrough]]; 46 default: 47 Processor::halt(); 48 } 49} 50}