Skip to content

Commit 7686a32

Browse files
mintsukiFlyGoat
authored andcommitted
Add logic to retry ExitBootServices() until success
1 parent 48f59f5 commit 7686a32

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/csmwrap.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,19 @@ EFI_STATUS efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
201201
efi_mmap_size += 4096;
202202
BS->AllocatePool(EfiLoaderData, efi_mmap_size, (void **)&efi_mmap);
203203
BS->GetMemoryMap(&efi_mmap_size, efi_mmap, &efi_mmap_key, &efi_desc_size, &efi_desc_ver);
204-
BS->ExitBootServices(ImageHandle, efi_mmap_key);
204+
205+
// It may take N amounts of ExitBootServices() calls to complete...
206+
// Cap at 128.
207+
for (size_t i = 0; i < 128; i++) {
208+
Status = BS->ExitBootServices(ImageHandle, efi_mmap_key);
209+
if (Status == EFI_SUCCESS) {
210+
break;
211+
}
212+
}
213+
if (Status != EFI_SUCCESS) {
214+
printf("Failed to exit boot services!");
215+
return Status;
216+
}
205217

206218
/* Disable external interrupts */
207219
asm volatile ("cli");

0 commit comments

Comments
 (0)