diff --git a/Kernel/i386.cpp b/Kernel/i386.cpp index 2554b1b352..22caeb0c43 100644 --- a/Kernel/i386.cpp +++ b/Kernel/i386.cpp @@ -447,3 +447,10 @@ void handleIRQ() s_irqHandler[irq]->handleIRQ(); PIC::eoi(irq); } + +void __assertion_failed(const char* msg, const char* file, unsigned line, const char* func) +{ + asm volatile("cli"); + kprintf("ASSERTION FAILED: %s\n%s:%u in %s\n", msg, file, line, func); + asm volatile("hlt"); +} diff --git a/Kernel/kassert.h b/Kernel/kassert.h index cd858bca70..8a13ac1dd5 100644 --- a/Kernel/kassert.h +++ b/Kernel/kassert.h @@ -3,8 +3,10 @@ #include "kprintf.h" #include "i386.h" +void __assertion_failed(const char* msg, const char* file, unsigned line, const char* func) NORETURN; + +#define ASSERT(expr) (static_cast(expr) ? (void)0 : __assertion_failed(#expr, __FILE__, __LINE__, __PRETTY_FUNCTION__)) #define CRASH() do { asm volatile("ud2"); } while(0) -#define ASSERT(x) do { if (!(x)) { asm volatile("cli"); kprintf("ASSERTION FAILED: " #x "\n%s:%u in %s\n", __FILE__, __LINE__, __PRETTY_FUNCTION__); CRASH(); } } while(0) #define RELEASE_ASSERT(x) do { if (!(x)) CRASH(); } while(0) #define ASSERT_NOT_REACHED() ASSERT(false) #define ASSERT_INTERRUPTS_DISABLED() ASSERT(!(cpuFlags() & 0x200))