/* Allocates the number of pages of MemoryType and returns a pointer to the allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL is returned. If there is not enough memory availble to satisfy the request, then NULL is returned. */
VOID* EFIAPI AllocatePages(IN UINTN Pages)
/* Allocates the number of pages of MemoryType and returns a pointer to the allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL is returned. If there is not enough memory availble to satisfy the request, then NULL is returned. */
VOID* EFIAPI AllocatePages(IN UINTN Pages)
{
  EFI_PEI_HOB_POINTERS        Hob;
  EFI_PHYSICAL_ADDRESS        Offset;
  EFI_HOB_HANDOFF_INFO_TABLE  *HobTable;
  Hob.Raw  = GetHobList ();
  HobTable = Hob.HandoffInformationTable;
  if (Pages == 0) {
    return NULL;
  }
  Offset = HobTable->EfiFreeMemoryTop & EFI_PAGE_MASK;
  if (Offset != 0) {
    HobTable->EfiFreeMemoryTop -= Offset;
  }
  if (HobTable->EfiFreeMemoryTop - ((Pages * EFI_PAGE_SIZE) + sizeof (EFI_HOB_MEMORY_ALLOCATION)) < HobTable->EfiFreeMemoryBottom) {
    return NULL;
  }
  HobTable->EfiFreeMemoryTop -= Pages * EFI_PAGE_SIZE;
  BuildMemoryAllocationHob (HobTable->EfiFreeMemoryTop, Pages * EFI_PAGE_SIZE, EfiBootServicesData);
  return (VOID *)(UINTN)HobTable->EfiFreeMemoryTop;
}