loader.efi: fix panic() after BS off

panic() is using multiple services - attempting to read
keyboard, accessing time functions and finally, exiting the loader.

Protect all the accessed listed above. Note, when BS are off,
we really can not just exit the loader, we only can reboot.

MFC after:	1 week
This commit is contained in:
Toomas Soome 2021-09-08 03:14:51 +03:00
parent 6d25ea6d96
commit a2e02d9d8e
4 changed files with 15 additions and 4 deletions

View File

@ -438,7 +438,7 @@ VOID
IN EFI_STATUS ResetStatus,
IN UINTN DataSize,
IN CHAR16 *ResetData OPTIONAL
);
) __dead2;
typedef
EFI_STATUS

View File

@ -33,5 +33,6 @@ __FBSDID("$FreeBSD$");
void
delay(int usecs)
{
BS->Stall(usecs);
if (boot_services_active)
BS->Stall(usecs);
}

View File

@ -1362,6 +1362,9 @@ efi_cons_getchar(void)
if ((c = keybuf_getchar()) != 0)
return (c);
if (!boot_services_active)
return (-1);
key_pending = 0;
if (coninex == NULL) {
@ -1383,6 +1386,9 @@ efi_cons_poll(void)
if (keybuf_ischar() || key_pending)
return (1);
if (!boot_services_active)
return (0);
/*
* Some EFI implementation (u-boot for example) do not support
* WaitForKey().

View File

@ -40,8 +40,12 @@ void
efi_exit(EFI_STATUS exit_code)
{
BS->FreePages(heap, EFI_SIZE_TO_PAGES(heapsize));
BS->Exit(IH, exit_code, 0, NULL);
if (boot_services_active) {
BS->FreePages(heap, EFI_SIZE_TO_PAGES(heapsize));
BS->Exit(IH, exit_code, 0, NULL);
} else {
RS->ResetSystem(EfiResetCold, EFI_SUCCESS, 0, NULL);
}
}
void