/* * Copyright (c) 2026, Apollo Telephone Laboratories. * Provided under the BSD-3 clause. */ #include EFI_STATUS SBootGetMemmap(OUT PLATFORM_MEMMAP *Map) { EFI_STATUS Status; if (Map == NULL) { return EFI_INVALID_PARAMETER; } Map->Map = NULL; Map->MapSize = 0; Map->MapKey = 0; Map->DescriptorSize = 0; Map->DescriptorVersion = 0; Status = uefi_call_wrapper( gBS->GetMemoryMap, 5, &Map->MapSize, Map->Map, &Map->MapKey, &Map->DescriptorSize, &Map->DescriptorVersion ); Map->Map = AllocatePool(Map->MapSize); if (Map->Map == NULL) { return EFI_OUT_OF_RESOURCES; } /* * We have to call this twice as the act of allocating memory * alters the memory map. */ for (UINTN Idx = 0; Idx < 2; ++Idx) { Status = uefi_call_wrapper( gBS->GetMemoryMap, 5, &Map->MapSize, Map->Map, &Map->MapKey, &Map->DescriptorSize, &Map->DescriptorVersion ); if (!EFI_ERROR(Status)) { break; } } if (EFI_ERROR(Status)) { Print(L"fatal: failed to get memory map\n"); } return EFI_SUCCESS; }