Kernel: Panic wont print stacktrace if it has already paniced

This prevents stack trace dump to panic and loop
This commit is contained in:
Bananymous 2023-04-16 00:04:49 +03:00
parent 93abee9c7c
commit aba82564f5
3 changed files with 21 additions and 11 deletions

View File

@ -27,6 +27,7 @@ set(KERNEL_SOURCES
kernel/kernel.cpp kernel/kernel.cpp
kernel/Memory/Heap.cpp kernel/Memory/Heap.cpp
kernel/Memory/kmalloc.cpp kernel/Memory/kmalloc.cpp
kernel/Panic.cpp
kernel/PCI.cpp kernel/PCI.cpp
kernel/PIC.cpp kernel/PIC.cpp
kernel/PIT.cpp kernel/PIT.cpp

View File

@ -4,11 +4,11 @@
#define panic(...) detail::panic_impl(__FILE__, __LINE__, __VA_ARGS__) #define panic(...) detail::panic_impl(__FILE__, __LINE__, __VA_ARGS__)
namespace Kernel namespace Kernel::detail
{ {
namespace detail extern bool g_paniced;
{
template<typename... Args> template<typename... Args>
__attribute__((__noreturn__)) __attribute__((__noreturn__))
static void panic_impl(const char* file, int line, const char* message, Args... args) static void panic_impl(const char* file, int line, const char* message, Args... args)
@ -16,11 +16,14 @@ namespace Kernel
asm volatile("cli"); asm volatile("cli");
derrorln("Kernel panic at {}:{}", file, line); derrorln("Kernel panic at {}:{}", file, line);
derrorln(message, args...); derrorln(message, args...);
if (!g_paniced)
{
g_paniced = true;
Debug::dump_stack_trace(); Debug::dump_stack_trace();
}
for (;;) for (;;)
asm volatile("hlt"); asm volatile("hlt");
__builtin_unreachable(); __builtin_unreachable();
} }
}
} }

6
kernel/kernel/Panic.cpp Normal file
View File

@ -0,0 +1,6 @@
#include <kernel/Panic.h>
namespace Kernel::detail
{
bool g_paniced = false;
}