/* Allocates the number of 4KB pages of type '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 remaining to satisfy the request, then NULL is returned. */
VOID* EFIAPI AllocatePeiAccessiblePages(IN EFI_MEMORY_TYPE MemoryType, IN UINTN Pages)
/* Allocates the number of 4KB pages of type '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 remaining to satisfy the request, then NULL is returned. */
VOID* EFIAPI AllocatePeiAccessiblePages(IN EFI_MEMORY_TYPE MemoryType, IN UINTN Pages)
{
  EFI_STATUS                  Status;
  EFI_ALLOCATE_TYPE           AllocType;
  EFI_PHYSICAL_ADDRESS        Memory;
  EFI_HOB_HANDOFF_INFO_TABLE  *PhitHob;
  if (Pages == 0) {
    return NULL;
  }
  AllocType = AllocateAnyPages;
  PhitHob = (EFI_HOB_HANDOFF_INFO_TABLE *)GetHobList ();
  if (PhitHob->EfiFreeMemoryTop <= MAX_UINT32) {
    AllocType = AllocateMaxAddress;
    Memory    = MAX_UINT32;
  }
  Status = gBS->AllocatePages (AllocType, MemoryType, Pages, &Memory);
  if (EFI_ERROR (Status)) {
    return NULL;
  }
  return (VOID *)(UINTN)Memory;
}