Brad
Brad

Reputation: 11515

UEFI LocateHandleBuffer always returns "Invalid Parameter"

Very simple UEFI program as such:

LocateHandleBuffer() always returns 8000000000000002 which is "Invalid Parameter. EFI docs say that the only reason for that should be if one of the two pointers I am passing are NULL, which they are clearly not.

It can't get much simpler than this. I originally tried with ByProtocol with a speicifc GUID - but it always fails with the same error.

Any idea what the issue could be?

#include <efi.h>
#include <efilib.h>

EFI_STATUS EFIAPI efi_main (EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) {

  EFI_STATUS Status;
  UINTN HandleCount;
  EFI_HANDLE *HandleBuffer;

  EFI_BOOT_SERVICES *gBS = SystemTable-> BootServices;

  InitializeLib(ImageHandle, SystemTable);
  Print(L"test2  built on " __DATE__ " at " __TIME__ "\n");
  Status = gBS->LocateHandleBuffer (
     AllHandles, NULL, NULL,
     &HandleCount, &HandleBuffer);
  Print(L"Test AllHandles returned status  %llx count %d\n",Status,HandleCount);
  return (Status);
}

Upvotes: 1

Views: 1343

Answers (1)

m4tx
m4tx

Reputation: 4511

Because GCC uses cdecl/SysV ABI as its default calling convention, and x86_64 UEFI requires Microsoft x64 calling convention to be used, there is a utility thunk in GNU EFI called uefi_call_wrapper. Basically what it does is that it takes a pointer to the function to be called, number of arguments and the parameters, and it calls this function using the proper convention. So, basically, instead of writing code like this:

Status = gBS->LocateHandleBuffer(
    AllHandles, NULL, NULL,
    &HandleCount, &HandleBuffer);

you should write something like this:

Status = uefi_call_wrapper(
    gBS->LocateHandleBuffer, 5,
    AllHandles, NULL, NULL,
    &HandleCount, &HandleBuffer);

Upvotes: 1

Related Questions