/* Internal Function. Allocate n pages from free page list at given address. */
UINTN InternalAllocAddress(IN OUT LIST_ENTRY *FreePageList, IN UINTN NumberOfPages, IN UINTN Address)
/* Internal Function. Allocate n pages from free page list at given address. */
UINTN InternalAllocAddress(IN OUT LIST_ENTRY *FreePageList, IN UINTN NumberOfPages, IN UINTN Address)
{
  UINTN           EndAddress;
  LIST_ENTRY      *Node;
  FREE_PAGE_LIST  *Pages;
  if ((Address & EFI_PAGE_MASK) != 0) {
    return ~Address;
  }
  EndAddress = Address + EFI_PAGES_TO_SIZE (NumberOfPages);
  for (Node = FreePageList->BackLink; Node != FreePageList; Node = Node->BackLink) {
    Pages = BASE_CR (Node, FREE_PAGE_LIST, Link);
    if ((UINTN)Pages <= Address) {
      if ((UINTN)Pages + EFI_PAGES_TO_SIZE (Pages->NumberOfPages) < EndAddress) {
        break;
      }
      return InternalAllocPagesOnOneNode (Pages, NumberOfPages, EndAddress);
    }
  }
  return ~Address;
}