IN BOOLEAN NeedGuard\r
)\r
{\r
- EFI_STATUS Status;\r
- UINT64 Start;\r
- UINT64 NumberOfBytes;\r
- UINT64 End;\r
- UINT64 MaxAddress;\r
- UINTN Alignment;\r
+ EFI_STATUS Status;\r
+ UINT64 Start;\r
+ UINT64 NumberOfBytes;\r
+ UINT64 End;\r
+ UINT64 MaxAddress;\r
+ UINTN Alignment;\r
+ EFI_MEMORY_TYPE CheckType;\r
\r
if ((UINT32)Type >= MaxAllocateType) {\r
return EFI_INVALID_PARAMETER;\r
// if (Start + NumberOfBytes) rolls over 0 or\r
// if Start is above MAX_ALLOC_ADDRESS or\r
// if End is above MAX_ALLOC_ADDRESS,\r
+ // if Start..End overlaps any tracked MemoryTypeStatistics range\r
// return EFI_NOT_FOUND.\r
//\r
if (Type == AllocateAddress) {\r
(End > MaxAddress)) {\r
return EFI_NOT_FOUND;\r
}\r
+\r
+ //\r
+ // A driver is allowed to call AllocatePages using an AllocateAddress type. This type of\r
+ // AllocatePage request the exact physical address if it is not used. The existing code\r
+ // will allow this request even in 'special' pages. The problem with this is that the\r
+ // reason to have 'special' pages for OS hibernate/resume is defeated as memory is\r
+ // fragmented.\r
+ //\r
+\r
+ for (CheckType = (EFI_MEMORY_TYPE) 0; CheckType < EfiMaxMemoryType; CheckType++) {\r
+ if (MemoryType != CheckType &&\r
+ mMemoryTypeStatistics[CheckType].Special &&\r
+ mMemoryTypeStatistics[CheckType].NumberOfPages > 0) {\r
+ if (Start >= mMemoryTypeStatistics[CheckType].BaseAddress &&\r
+ Start <= mMemoryTypeStatistics[CheckType].MaximumAddress) {\r
+ return EFI_NOT_FOUND;\r
+ }\r
+ if (End >= mMemoryTypeStatistics[CheckType].BaseAddress &&\r
+ End <= mMemoryTypeStatistics[CheckType].MaximumAddress) {\r
+ return EFI_NOT_FOUND;\r
+ }\r
+ if (Start < mMemoryTypeStatistics[CheckType].BaseAddress &&\r
+ End > mMemoryTypeStatistics[CheckType].MaximumAddress) {\r
+ return EFI_NOT_FOUND;\r
+ }\r
+ }\r
+ }\r
}\r
\r
if (Type == AllocateMaxAddress) {\r