- Status = CoreFreePages (Mem, NumberOfPages);\r
- ASSERT_EFI_ERROR (Status);\r
- if (EFI_ERROR(Status)) {\r
- return;\r
+ Status = CoreAllocatePages (\r
+ AllocateMaxAddress,\r
+ EfiBootServicesData,\r
+ RealPages,\r
+ &Memory\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ if (PcdGet64 (PcdMaxEfiSystemTablePointerAddress) != 0) {\r
+ DEBUG ((EFI_D_INFO, "Allocate memory for EFI_SYSTEM_TABLE_POINTER below PcdMaxEfiSystemTablePointerAddress failed. \\r
+ Retry to allocate memroy as close to the top of memory as feasible.\n"));\r
+ }\r
+ //\r
+ // If the initial memory allocation fails, then reattempt allocation\r
+ // as close to the top of memory as feasible.\r
+ //\r
+ Status = CoreAllocatePages (\r
+ AllocateAnyPages,\r
+ EfiBootServicesData,\r
+ RealPages,\r
+ &Memory\r
+ );\r
+ ASSERT_EFI_ERROR (Status);\r
+ if (EFI_ERROR (Status)) {\r
+ return;\r
+ }\r