//\r
CoreAddRange (MemType, Start, RangeEnd, Attribute);\r
if (ChangingType && (MemType == EfiConventionalMemory)) {\r
+ //\r
+ // Avoid calling DEBUG_CLEAR_MEMORY() for an address of 0 because this\r
+ // macro will ASSERT() if address is 0. Instead, CoreAddRange() guarantees\r
+ // that the page starting at address 0 is always filled with zeros.\r
+ //\r
if (Start == 0) {\r
- //\r
- // Avoid calling DEBUG_CLEAR_MEMORY() for an address of 0 because this\r
- // macro will ASSERT() if address is 0. Instead, CoreAddRange()\r
- // guarantees that the page starting at address 0 is always filled\r
- // with zeros.\r
- //\r
if (RangeEnd > EFI_PAGE_SIZE) {\r
DEBUG_CLEAR_MEMORY ((VOID *)(UINTN) EFI_PAGE_SIZE, (UINTN) (RangeEnd - EFI_PAGE_SIZE + 1));\r
}\r
} else {\r
- //\r
- // If Heap Guard is enabled, the page at the top and/or bottom of\r
- // this memory block to free might be inaccessible. Skipping them\r
- // to avoid page fault exception.\r
- //\r
- UINT64 StartToClear;\r
- UINT64 EndToClear;\r
-\r
- StartToClear = Start;\r
- EndToClear = RangeEnd;\r
- if (PcdGet8 (PcdHeapGuardPropertyMask) & (BIT1|BIT0)) {\r
- if (IsGuardPage(StartToClear)) {\r
- StartToClear += EFI_PAGE_SIZE;\r
- }\r
- if (IsGuardPage (EndToClear)) {\r
- EndToClear -= EFI_PAGE_SIZE;\r
- }\r
- ASSERT (EndToClear > StartToClear);\r
- }\r
-\r
- DEBUG_CLEAR_MEMORY(\r
- (VOID *)(UINTN)StartToClear,\r
- (UINTN)(EndToClear - StartToClear + 1)\r
- );\r
+ DEBUG_CLEAR_MEMORY ((VOID *)(UINTN) Start, (UINTN) (RangeEnd - Start + 1));\r
}\r
}\r
\r
\r
Done:\r
CoreReleaseMemoryLock ();\r
- if (IsGuarded) {\r
- UnsetGuardForMemory(Memory, NumberOfPages);\r
- }\r
return Status;\r
}\r
\r
EFI_GCD_MAP_ENTRY MergeGcdMapEntry;\r
EFI_MEMORY_TYPE Type;\r
EFI_MEMORY_DESCRIPTOR *MemoryMapStart;\r
+ EFI_MEMORY_DESCRIPTOR *MemoryMapEnd;\r
\r
//\r
// Make sure the parameters are valid\r
//\r
BufferSize = ((UINT8 *)MemoryMap - (UINT8 *)MemoryMapStart);\r
\r
+ //\r
+ // Note: Some OSs will treat EFI_MEMORY_DESCRIPTOR.Attribute as really\r
+ // set attributes and change memory paging attribute accordingly.\r
+ // But current EFI_MEMORY_DESCRIPTOR.Attribute is assigned by\r
+ // value from Capabilities in GCD memory map. This might cause\r
+ // boot problems. Clearing all paging related capabilities can\r
+ // workaround it. Following code is supposed to be removed once\r
+ // the usage of EFI_MEMORY_DESCRIPTOR.Attribute is clarified in\r
+ // UEFI spec and adopted by both EDK-II Core and all supported\r
+ // OSs.\r
+ //\r
+ MemoryMapEnd = MemoryMap;\r
+ MemoryMap = MemoryMapStart;\r
+ while (MemoryMap < MemoryMapEnd) {\r
+ MemoryMap->Attribute &= ~(UINT64)(EFI_MEMORY_RP | EFI_MEMORY_RO |\r
+ EFI_MEMORY_XP);\r
+ MemoryMap = NEXT_MEMORY_DESCRIPTOR (MemoryMap, Size);\r
+ }\r
+ MergeMemoryMap (MemoryMapStart, &BufferSize, Size);\r
+ MemoryMapEnd = (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)MemoryMapStart + BufferSize);\r
+\r
Status = EFI_SUCCESS;\r
\r
Done:\r