/* Pool allocation service. Before permanent memory is discovered, the pool will be allocated in the heap in temporary memory. Generally, the size of the heap in temporary memory does not exceed 64K, so the biggest pool size could be allocated is 64K. */
EFI_STATUS EFIAPI PeiAllocatePool(IN CONST EFI_PEI_SERVICES **PeiServices, IN UINTN Size, OUT VOID **Buffer)
/* Pool allocation service. Before permanent memory is discovered, the pool will be allocated in the heap in temporary memory. Generally, the size of the heap in temporary memory does not exceed 64K, so the biggest pool size could be allocated is 64K. */
EFI_STATUS EFIAPI PeiAllocatePool(IN CONST EFI_PEI_SERVICES **PeiServices, IN UINTN Size, OUT VOID **Buffer)
{
  EFI_STATUS           Status;
  EFI_HOB_MEMORY_POOL  *Hob;
  if (Size > (0xFFF8 - sizeof (EFI_HOB_MEMORY_POOL))) {
    return EFI_OUT_OF_RESOURCES;
  }
  Status = PeiServicesCreateHob (
             EFI_HOB_TYPE_MEMORY_POOL,
             (UINT16)(sizeof (EFI_HOB_MEMORY_POOL) + Size),
             (VOID **)&Hob
             );
  ASSERT_EFI_ERROR (Status);
  if (EFI_ERROR (Status)) {
    *Buffer = NULL;
  } else {
    *Buffer = Hob + 1;
  }
  return Status;
}