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/Memory/Heap.cpp
kernel/Memory/kmalloc.cpp
kernel/Panic.cpp
kernel/PCI.cpp
kernel/PIC.cpp
kernel/PIT.cpp

View File

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