]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
boot: Detect nested assertions
authorJan Janssen <medhefgo@web.de>
Fri, 10 Mar 2023 08:12:05 +0000 (09:12 +0100)
committerJan Janssen <medhefgo@web.de>
Fri, 17 Mar 2023 09:35:29 +0000 (10:35 +0100)
src/boot/efi/log.c

index 9cbbb3a9337a7aa3db19ec7e77959cd39c67a36a..b805f5d0840fb8bf5a9508a8b9f56287f4a584e4 100644 (file)
@@ -10,8 +10,23 @@ _noreturn_ static void freeze(void) {
                 BS->Stall(60 * 1000 * 1000);
 }
 
+_noreturn_ static void panic(const char16_t *message) {
+        if (ST->ConOut->Mode->CursorColumn > 0)
+                ST->ConOut->OutputString(ST->ConOut, (char16_t *) u"\r\n");
+        ST->ConOut->SetAttribute(ST->ConOut, EFI_TEXT_ATTR(EFI_LIGHTRED, EFI_BLACK));
+        ST->ConOut->OutputString(ST->ConOut, (char16_t *) message);
+        freeze();
+}
+
 void efi_assert(const char *expr, const char *file, unsigned line, const char *function) {
-        log_error("systemd-boot assertion '%s' failed at %s:%u@%s. Halting.", expr, file, line, function);
+        static bool asserting = false;
+
+        /* Let's be paranoid. */
+        if (asserting)
+                panic(u"systemd-boot: Nested assertion failure, halting.");
+
+        asserting = true;
+        log_error("systemd-boot: Assertion '%s' failed at %s:%u@%s, halting.", expr, file, line, function);
         freeze();
 }
 
@@ -48,12 +63,10 @@ void log_wait(void) {
 /* These override the (weak) div0 handlers from libgcc as they would otherwise call raise() instead. */
 
 _used_ _noreturn_ int __aeabi_idiv0(int return_value) {
-        log_error("Division by zero.");
-        freeze();
+        panic(u"systemd-boot: Division by zero, halting.");
 }
 
 _used_ _noreturn_ long long __aeabi_ldiv0(long long return_value) {
-        log_error("Division by zero.");
-        freeze();
+        panic(u"systemd-boot: Division by zero, halting.");
 }
 #endif