Skip to content

Commit

Permalink
initial upload
Browse files Browse the repository at this point in the history
  • Loading branch information
TaylorBeebe committed Apr 23, 2024
1 parent 0d5e4ef commit 68ba891
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c
Original file line number Diff line number Diff line change
Expand Up @@ -466,18 +466,26 @@ EnforceMemoryMapAttribute (
MemoryMapEntry = MemoryMap;
MemoryMapEnd = (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)MemoryMap + MemoryMapSize);
while ((UINTN)MemoryMapEntry < (UINTN)MemoryMapEnd) {
switch (MemoryMapEntry->Type) {
case EfiRuntimeServicesCode:
// do nothing
break;
case EfiRuntimeServicesData:
case EfiMemoryMappedIO:
case EfiMemoryMappedIOPortSpace:
MemoryMapEntry->Attribute |= EFI_MEMORY_XP;
break;
case EfiReservedMemoryType:
case EfiACPIMemoryNVS:
break;
// MU_CHANGE [BEGIN]: Set the attributes for EfiRuntimeServicesCode Regions
if ((MemoryMapEntry->Attribute & EFI_MEMORY_ACCESS_MASK) == 0) {
switch (MemoryMapEntry->Type) {
case EfiRuntimeServicesCode:
// If at this point the attributes have not been set on an EfiRuntimeServicesCode
// region, the memory range must not contain a loaded image. It's possible these
// non-image EfiRuntimeServicesCode regions are part of the unused memory bucket.
// It could also be that this region was explicitly allocated outside of the PE
// loader but the UEFI spec requires that all EfiRuntimeServicesCode regions contain
// EFI modules. In either case, set the attributes to RO and XP.
MemoryMapEntry->Attribute |= (EFI_MEMORY_RO | EFI_MEMORY_XP);
break;
case EfiRuntimeServicesData:
MemoryMapEntry->Attribute |= EFI_MEMORY_XP;
break;
default:
break;
}

// MU_CHANGE [END]
}

MemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, DescriptorSize);
Expand Down

0 comments on commit 68ba891

Please sign in to comment.