Page 1 of 1

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

Posted: Tue Jun 09, 2015 9:51 am
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?

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

Posted: Tue Jun 09, 2015 10:25 am
by jnc100
ConOut->OutputString has the potential to allocate memory.

Call GetMemoryMap immediately before ExitBootServices.

Regards,
John.

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

Posted: Tue Jun 09, 2015 8:34 pm
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.