Why does ExitBootServices() fails if I don't alllocate

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
mpiechotka
Posts: 5
Joined: Tue Jun 09, 2015 9:34 am
Libera.chat IRC: mpiechotka

Why does ExitBootServices() fails if I don't alllocate

Post by mpiechotka »

Hi,
I decided to play a bit with UEFI but I got stuck. When I attempt to call ExitBootServices() I got the EFI_INVALID_PARAMETER even though I don't allocate memory. Despite reading the spec I cannot figure out what might be wrong.

The error persists even if I simplify the code:

Code: Select all

EFI_STATUS efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
{
    EFI_STATUS Status;
    UINTN DescriptorsSize;
    EFI_MEMORY_DESCRIPTOR Descriptors[64];
    UINTN MapKey;
    UINTN DescriptorSize;
    UINT32 DescriptorVersion;

    ST = SystemTable;

    DescriptorsSize = sizeof(Descriptors);
    Status = ST->BootServices->GetMemoryMap(&DescriptorsSize, Descriptors, &MapKey, &DescriptorSize, &DescriptorVersion);
    if (EFI_ERROR(Status))
       return Status;

    Status = ST->ConOut->OutputString(ST->ConOut, L"ABOUT TO EXIT\n\r");
    if (EFI_ERROR(Status))
       return Status;

    Status = ST->BootServices->ExitBootServices(ImageHandle, MapKey);
    if (EFI_ERROR(Status)) {
      Status = ST->ConOut->OutputString(ST->ConOut, L"FAILED\n\r");
      Status = ST->ConIn->Reset(ST->ConIn, FALSE);
      while ((Status = ST->ConIn->ReadKeyStroke(ST->ConIn, &Key)) == EFI_NOT_READY) ;
    }
 
    return Status;
}
What am I missing from specification?
jnc100
Member
Member
Posts: 775
Joined: Mon Apr 09, 2007 12:10 pm
Location: London, UK
Contact:

Re: Why does ExitBootServices() fails if I don't alllocate

Post by jnc100 »

ConOut->OutputString has the potential to allocate memory.

Call GetMemoryMap immediately before ExitBootServices.

Regards,
John.
mpiechotka
Posts: 5
Joined: Tue Jun 09, 2015 9:34 am
Libera.chat IRC: mpiechotka

Re: Why does ExitBootServices() fails if I don't alllocate

Post by mpiechotka »

jnc100 wrote:ConOut->OutputString has the potential to allocate memory.

Call GetMemoryMap immediately before ExitBootServices.

Regards,
John.
Thanks - I feel stupid. I don't know why I assumed that if it is not written that it can it cannot.
Post Reply