/* Allocates the number of pages specified by Pages of type EfiBootServicesData with an alignment specified by Alignment. If Pages is 0, then NULL is returned. If Alignment is not a power of two and Alignment is not zero, then ASSERT(). If there is no enough memory at the specified alignment available to satisfy the request, then NULL is returned. */
VOID* EFIAPI AllocateAlignedPages(IN UINTN Pages, IN UINTN Alignment)
/* Allocates the number of pages specified by Pages of type EfiBootServicesData with an alignment specified by Alignment. If Pages is 0, then NULL is returned. If Alignment is not a power of two and Alignment is not zero, then ASSERT(). If there is no enough memory at the specified alignment available to satisfy the request, then NULL is returned. */
VOID* EFIAPI AllocateAlignedPages(IN UINTN Pages, IN UINTN Alignment)
{
  VOID   *Memory;
  UINTN  AlignmentMask;
  ASSERT ((Alignment & (Alignment - 1)) == 0);
  if (Pages == 0) {
    return NULL;
  }
  ASSERT (Pages <= (MAX_ADDRESS - EFI_SIZE_TO_PAGES (Alignment)));
  Memory = (VOID *)(UINTN)AllocatePages (Pages + EFI_SIZE_TO_PAGES (Alignment));
  if (Memory == NULL) {
    return NULL;
  }
  if (Alignment == 0) {
    AlignmentMask = Alignment;
  } else {
    AlignmentMask = Alignment - 1;
  }
  return (VOID *)(UINTN)(((UINTN)Memory + AlignmentMask) & ~AlignmentMask);
}