Panic.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/Format.h>
  7. #include <Kernel/Arch/Processor.h>
  8. #if ARCH(X86_64)
  9. # include <Kernel/Arch/x86_64/Shutdown.h>
  10. #elif ARCH(AARCH64)
  11. # include <Kernel/Arch/aarch64/RPi/Watchdog.h>
  12. #endif
  13. #include <Kernel/CommandLine.h>
  14. #include <Kernel/KSyms.h>
  15. #include <Kernel/Panic.h>
  16. #include <Kernel/Thread.h>
  17. namespace Kernel {
  18. [[noreturn]] static void __shutdown()
  19. {
  20. #if ARCH(X86_64)
  21. qemu_shutdown();
  22. virtualbox_shutdown();
  23. #elif ARCH(AARCH64)
  24. RPi::Watchdog::the().system_shutdown();
  25. #endif
  26. // Note: If we failed to invoke platform shutdown, we need to halt afterwards
  27. // to ensure no further execution on any CPU still happens.
  28. Processor::halt();
  29. }
  30. void __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. critical_dmesgln("at {}:{} in {}", file, line, function);
  37. dump_backtrace(PrintToScreen::Yes);
  38. if (!CommandLine::was_initialized())
  39. Processor::halt();
  40. switch (kernel_command_line().panic_mode()) {
  41. case PanicMode::Shutdown:
  42. __shutdown();
  43. case PanicMode::Halt:
  44. [[fallthrough]];
  45. default:
  46. Processor::halt();
  47. }
  48. }
  49. }