forked from Bananymous/banan-os
Kernel: Panic wont print stacktrace if it has already paniced
This prevents stack trace dump to panic and loop
This commit is contained in:
parent
93abee9c7c
commit
aba82564f5
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
#include <kernel/Panic.h>
|
||||
|
||||
namespace Kernel::detail
|
||||
{
|
||||
bool g_paniced = false;
|
||||
}
|
Loading…
Reference in New Issue