// If we are in EFI 1.10 compatability mode no event groups will be\r
// found and nothing will happen we we call this function. These events\r
// will get signaled but since a lock is held around the call to this\r
- // function the notificaiton events will only be called after this funciton\r
+ // function the notificaiton events will only be called after this function\r
// returns and the lock is released.\r
//\r
CoreNotifySignalList (&gEfiEventMemoryMapChangeGuid);\r
{\r
EFI_STATUS Status;\r
UINT64 Start;\r
+ UINT64 NumberOfBytes;\r
+ UINT64 End;\r
UINT64 MaxAddress;\r
UINTN Alignment;\r
\r
//\r
MaxAddress = MAX_ADDRESS;\r
\r
+ //\r
+ // Check for Type AllocateAddress,\r
+ // if NumberOfPages is 0 or\r
+ // if (NumberOfPages << EFI_PAGE_SHIFT) is above MAX_ADDRESS or\r
+ // if (Start + NumberOfBytes) rolls over 0 or\r
+ // if Start is above MAX_ADDRESS or\r
+ // if End is above MAX_ADDRESS,\r
+ // return EFI_NOT_FOUND.\r
+ //\r
+ if (Type == AllocateAddress) {\r
+ if ((NumberOfPages == 0) ||\r
+ (NumberOfPages > RShiftU64 (MaxAddress, EFI_PAGE_SHIFT))) {\r
+ return EFI_NOT_FOUND;\r
+ }\r
+ NumberOfBytes = LShiftU64 (NumberOfPages, EFI_PAGE_SHIFT);\r
+ End = Start + NumberOfBytes - 1;\r
+\r
+ if ((Start >= End) ||\r
+ (Start > MaxAddress) || \r
+ (End > MaxAddress)) {\r
+ return EFI_NOT_FOUND;\r
+ }\r
+ }\r
+\r
if (Type == AllocateMaxAddress) {\r
MaxAddress = Start;\r
}\r
\r
Status = CoreInternalAllocatePages (Type, MemoryType, NumberOfPages, Memory);\r
if (!EFI_ERROR (Status)) {\r
- CoreUpdateProfile ((EFI_PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS (0), MemoryProfileActionAllocatePages, MemoryType, EFI_PAGES_TO_SIZE (NumberOfPages), (VOID *) (UINTN) *Memory);\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
}\r
return Status;\r
}\r
\r
@param Memory Base address of memory being freed\r
@param NumberOfPages The number of pages to free\r
+ @param MemoryType Pointer to memory type\r
\r
@retval EFI_NOT_FOUND Could not find the entry that covers the range\r
@retval EFI_INVALID_PARAMETER Address not aligned\r
EFIAPI\r
CoreInternalFreePages (\r
IN EFI_PHYSICAL_ADDRESS Memory,\r
- IN UINTN NumberOfPages\r
+ IN UINTN NumberOfPages,\r
+ OUT EFI_MEMORY_TYPE *MemoryType OPTIONAL\r
)\r
{\r
EFI_STATUS Status;\r
NumberOfPages += EFI_SIZE_TO_PAGES (Alignment) - 1;\r
NumberOfPages &= ~(EFI_SIZE_TO_PAGES (Alignment) - 1);\r
\r
+ if (MemoryType != NULL) {\r
+ *MemoryType = Entry->Type;\r
+ }\r
+\r
Status = CoreConvertPages (Memory, NumberOfPages, EfiConventionalMemory);\r
\r
if (EFI_ERROR (Status)) {\r
IN UINTN NumberOfPages\r
)\r
{\r
- EFI_STATUS Status;\r
+ EFI_STATUS Status;\r
+ EFI_MEMORY_TYPE MemoryType;\r
\r
- Status = CoreInternalFreePages (Memory, NumberOfPages);\r
+ Status = CoreInternalFreePages (Memory, NumberOfPages, &MemoryType);\r
if (!EFI_ERROR (Status)) {\r
- CoreUpdateProfile ((EFI_PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS (0), MemoryProfileActionFreePages, (EFI_MEMORY_TYPE) 0, EFI_PAGES_TO_SIZE (NumberOfPages), (VOID *) (UINTN) Memory);\r
+ CoreUpdateProfile (\r
+ (EFI_PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS (0),\r
+ MemoryProfileActionFreePages,\r
+ MemoryType,\r
+ EFI_PAGES_TO_SIZE (NumberOfPages),\r
+ (VOID *) (UINTN) Memory,\r
+ NULL\r
+ );\r
+ InstallMemoryAttributesTableOnMemoryAllocation (MemoryType);\r
}\r
return Status;\r
}\r