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 88f60b5e41
commit 295a27f16a
3 changed files with 21 additions and 11 deletions

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();
}
}