:: commit 4dbc6831ad43f5e4fa86ca29bc82c03d5b0fa329

mintsuki <mintsuki@protonmail.com> — 2022-02-27 04:47

parents: 24a72f8d1e

efi: Do not fail on first ExitBootServices() attempt

diff --git a/common/lib/blib.c b/common/lib/blib.c
index 0e2ae840..175c5f97 100644
--- a/common/lib/blib.c
+++ b/common/lib/blib.c
@@ -189,18 +189,25 @@ bool efi_exit_boot_services(void) {
     if (status)
         goto fail;
 
+    size_t retries = 0;
+
+retry:
     status = gBS->GetMemoryMap(&efi_mmap_size, efi_mmap, &mmap_key, &efi_desc_size, &efi_desc_ver);
     if (status)
         goto fail;
 
     // Be gone, UEFI!
     status = gBS->ExitBootServices(efi_image_handle, mmap_key);
+    if (status) {
+        if (retries == 128) {
+            goto fail;
+        }
+        retries++;
+        goto retry;
+    }
 
     asm volatile ("cli" ::: "memory");
 
-    if (status)
-        goto fail;
-
     pmm_reclaim_uefi_mem();
 
     // Go through new EFI memmap and free up bootloader entries
tab: 248 wrap: offon