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