From 999eb53364eb1d2ca194bae503938e6af94c3218 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Wed, 18 Sep 2024 00:56:02 +0300 Subject: [PATCH] Kernel: Release debug lock if its locked during kernel panic Also kernel panic now prints if it had lock --- kernel/include/kernel/Panic.h | 4 ++++ kernel/kernel/IDT.cpp | 2 ++ 2 files changed, 6 insertions(+) diff --git a/kernel/include/kernel/Panic.h b/kernel/include/kernel/Panic.h index ff70ceac83..45a05d490e 100644 --- a/kernel/include/kernel/Panic.h +++ b/kernel/include/kernel/Panic.h @@ -17,7 +17,11 @@ namespace Kernel static void panic_impl(const char* location, const char* message, Args&&... args) { asm volatile("cli"); + + const bool had_debug_lock = Debug::s_debug_lock.current_processor_has_lock(); derrorln("Kernel panic at {}", location); + if (had_debug_lock) + derrorln(" while having debug lock..."); derrorln(message, BAN::forward(args)...); if (!g_paniced) { diff --git a/kernel/kernel/IDT.cpp b/kernel/kernel/IDT.cpp index df5214fa43..98236ced4d 100644 --- a/kernel/kernel/IDT.cpp +++ b/kernel/kernel/IDT.cpp @@ -360,6 +360,8 @@ done: { if (g_paniced) { + while (Debug::s_debug_lock.current_processor_has_lock()) + Debug::s_debug_lock.unlock(InterruptState::Disabled); dprintln("Processor {} halted", Processor::current_id()); if (InterruptController::is_initialized()) InterruptController::get().broadcast_ipi();