+/**\r
+ Allocates pages from the memory map.\r
+\r
+ @param Type The type of allocation to perform\r
+ @param MemoryType The type of memory to turn the allocated pages\r
+ into\r
+ @param NumberOfPages The number of pages to allocate\r
+ @param Memory A pointer to receive the base allocated memory\r
+ address\r
+\r
+ @return Status. On success, Memory is filled in with the base address allocated\r
+ @retval EFI_INVALID_PARAMETER Parameters violate checking rules defined in\r
+ spec.\r
+ @retval EFI_NOT_FOUND Could not allocate pages match the requirement.\r
+ @retval EFI_OUT_OF_RESOURCES No enough pages to allocate.\r
+ @retval EFI_SUCCESS Pages successfully allocated.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+CoreAllocatePages (\r
+ IN EFI_ALLOCATE_TYPE Type,\r
+ IN EFI_MEMORY_TYPE MemoryType,\r
+ IN UINTN NumberOfPages,\r
+ OUT EFI_PHYSICAL_ADDRESS *Memory\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ BOOLEAN NeedGuard;\r
+\r
+ NeedGuard = IsPageTypeToGuard (MemoryType, Type) && !mOnGuarding;\r
+ Status = CoreInternalAllocatePages (Type, MemoryType, NumberOfPages, Memory,\r
+ NeedGuard);\r
+ if (!EFI_ERROR (Status)) {\r
+ CoreUpdateProfile (\r
+ (EFI_PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS (0),\r
+ MemoryProfileActionAllocatePages,\r
+ MemoryType,\r
+ EFI_PAGES_TO_SIZE (NumberOfPages),\r
+ (VOID *) (UINTN) *Memory,\r
+ NULL\r
+ );\r
+ InstallMemoryAttributesTableOnMemoryAllocation (MemoryType);\r
+ ApplyMemoryProtectionPolicy (EfiConventionalMemory, MemoryType, *Memory,\r
+ EFI_PAGES_TO_SIZE (NumberOfPages));\r
+ }\r
+ return Status;\r
+}\r