diff options
Diffstat (limited to 'core/memmap.c')
| -rw-r--r-- | core/memmap.c | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/core/memmap.c b/core/memmap.c new file mode 100644 index 0000000..f02e538 --- /dev/null +++ b/core/memmap.c @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2026, Apollo Telephone Laboratories. + * Provided under the BSD-3 clause. + */ + +#include <sboot/memmap.h> + +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; +} |
