efi: Properly propagate exits after loading an image using chainloading; do not try to return from panics if boot services were exited

This commit is contained in:
mintsuki 2021-07-06 09:59:49 +02:00
parent eadee3e6cb
commit ae2d924c14
2 changed files with 22 additions and 9 deletions

View File

@ -26,13 +26,20 @@ __attribute__((noreturn)) void panic(const char *fmt, ...) {
print("System halted.");
rm_hcf();
#elif defined (uefi)
print("Press [ENTER] to return to firmware.");
while (getchar() != '\n');
fb_clear(&fbinfo);
if (efi_boot_services_exited == false) {
print("Press [ENTER] to return to firmware.");
while (getchar() != '\n');
fb_clear(&fbinfo);
// release all uefi memory and return to firmware
pmm_release_uefi_mem();
uefi_call_wrapper(gBS->Exit, 4, efi_image_handle, EFI_ABORTED, 0, NULL);
__builtin_unreachable();
// release all uefi memory and return to firmware
pmm_release_uefi_mem();
uefi_call_wrapper(gBS->Exit, 4, efi_image_handle, EFI_ABORTED, 0, NULL);
__builtin_unreachable();
} else {
print("System halted.");
for (;;) {
asm ("hlt");
}
}
#endif
}

View File

@ -189,9 +189,15 @@ void chainload(char *config) {
new_handle_loaded_image->DeviceHandle = loader_loaded_image->DeviceHandle;
status = uefi_call_wrapper(gBS->StartImage, 3, new_handle, NULL, NULL);
UINTN exit_data_size = 0;
CHAR16 *exit_data = NULL;
EFI_STATUS exit_status = uefi_call_wrapper(gBS->StartImage, 3,
new_handle, &exit_data_size, &exit_data);
status = uefi_call_wrapper(gBS->Exit, 4,
efi_image_handle, exit_status, exit_data_size, exit_data);
if (status) {
panic("chainload: StartImage failure (%x)", status);
panic("chainload: Exit failure (%x)", status);
}
__builtin_unreachable();