From 8b4b684d6da2f2a3a885fc34ace202330e6806c5 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 4 Nov 2018 13:12:58 +0100 Subject: [PATCH] Move assertion failures out-of-line to reduce binary bloat. --- Kernel/i386.cpp | 7 +++++++ Kernel/kassert.h | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) 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))