X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FCore%2FDxe%2FMisc%2FMemoryAttributesTable.c;h=35156aea14dda9faa86dbf9b6395be383d1ead9a;hp=c84146a8e8edec4f1296829823e6bd47f26c2f41;hb=d4731a98a3a5ddc2fed73d2998884f2cbee44ba9;hpb=98c4b005c87921646da53a1e3ac01c94cf87139a diff --git a/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c b/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c index c84146a8e8..35156aea14 100644 --- a/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c +++ b/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c @@ -62,7 +62,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. **/ EFI_STATUS EFIAPI -CoreGetMemoryMapPropertiesTable ( +CoreGetMemoryMapWithSeparatedImageSection ( IN OUT UINTN *MemoryMapSize, IN OUT EFI_MEMORY_DESCRIPTOR *MemoryMap, OUT UINTN *MapKey, @@ -71,20 +71,16 @@ CoreGetMemoryMapPropertiesTable ( ); extern EFI_PROPERTIES_TABLE mPropertiesTable; - -BOOLEAN mIsConstructingMemoryAttributesTable = FALSE; +EFI_MEMORY_ATTRIBUTES_TABLE *mMemoryAttributesTable = NULL; +BOOLEAN mMemoryAttributesTableReadyToBoot = FALSE; /** Install MemoryAttributesTable. - @param[in] Event The Event this notify function registered to. - @param[in] Context Pointer to the context data registered to the Event. **/ VOID -EFIAPI InstallMemoryAttributesTable ( - EFI_EVENT Event, - VOID *Context + VOID ) { UINTN MemoryMapSize; @@ -99,17 +95,32 @@ InstallMemoryAttributesTable ( EFI_MEMORY_ATTRIBUTES_TABLE *MemoryAttributesTable; EFI_MEMORY_DESCRIPTOR *MemoryAttributesEntry; + if (gMemoryMapTerminated) { + // + // Directly return after MemoryMap terminated. + // + return; + } + if ((mPropertiesTable.MemoryProtectionAttribute & EFI_PROPERTIES_RUNTIME_MEMORY_PROTECTION_NON_EXECUTABLE_PE_DATA) == 0) { DEBUG ((EFI_D_VERBOSE, "MemoryProtectionAttribute NON_EXECUTABLE_PE_DATA is not set, ")); - DEBUG ((EFI_D_VERBOSE, "because Runtime Driver Section Alignment is not %dK.\n", EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT >> 10)); + DEBUG ((EFI_D_VERBOSE, "because Runtime Driver Section Alignment is not %dK.\n", RUNTIME_PAGE_ALLOCATION_GRANULARITY >> 10)); return ; } - mIsConstructingMemoryAttributesTable = TRUE; + if (mMemoryAttributesTable == NULL) { + // + // InstallConfigurationTable here to occupy one entry for MemoryAttributesTable + // before GetMemoryMap below, as InstallConfigurationTable may allocate runtime + // memory for the new entry. + // + Status = gBS->InstallConfigurationTable (&gEfiMemoryAttributesTableGuid, (VOID *) (UINTN) MAX_ADDRESS); + ASSERT_EFI_ERROR (Status); + } MemoryMapSize = 0; MemoryMap = NULL; - Status = CoreGetMemoryMapPropertiesTable ( + Status = CoreGetMemoryMapWithSeparatedImageSection ( &MemoryMapSize, MemoryMap, &MapKey, @@ -122,7 +133,7 @@ InstallMemoryAttributesTable ( MemoryMap = AllocatePool (MemoryMapSize); ASSERT (MemoryMap != NULL); - Status = CoreGetMemoryMapPropertiesTable ( + Status = CoreGetMemoryMapWithSeparatedImageSection ( &MemoryMapSize, MemoryMap, &MapKey, @@ -178,11 +189,55 @@ InstallMemoryAttributesTable ( } MemoryMap = NEXT_MEMORY_DESCRIPTOR(MemoryMap, DescriptorSize); } + MemoryMap = MemoryMapStart; + FreePool (MemoryMap); + // + // Update configuratoin table for MemoryAttributesTable. + // Status = gBS->InstallConfigurationTable (&gEfiMemoryAttributesTableGuid, MemoryAttributesTable); ASSERT_EFI_ERROR (Status); - mIsConstructingMemoryAttributesTable = FALSE; + if (mMemoryAttributesTable != NULL) { + FreePool (mMemoryAttributesTable); + } + mMemoryAttributesTable = MemoryAttributesTable; +} + +/** + Install MemoryAttributesTable on memory allocation. + + @param[in] MemoryType EFI memory type. +**/ +VOID +InstallMemoryAttributesTableOnMemoryAllocation ( + IN EFI_MEMORY_TYPE MemoryType + ) +{ + // + // Install MemoryAttributesTable after ReadyToBoot on runtime memory allocation. + // + if (mMemoryAttributesTableReadyToBoot && + ((MemoryType == EfiRuntimeServicesCode) || (MemoryType == EfiRuntimeServicesData))) { + InstallMemoryAttributesTable (); + } +} + +/** + Install MemoryAttributesTable on ReadyToBoot. + + @param[in] Event The Event this notify function registered to. + @param[in] Context Pointer to the context data registered to the Event. +**/ +VOID +EFIAPI +InstallMemoryAttributesTableOnReadyToBoot ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + InstallMemoryAttributesTable (); + mMemoryAttributesTableReadyToBoot = TRUE; } /** @@ -198,17 +253,16 @@ CoreInitializeMemoryAttributesTable ( EFI_EVENT ReadyToBootEvent; // - // Construct the table at ReadyToBoot, because this should be - // last point to allocate RuntimeCode/RuntimeData. + // Construct the table at ReadyToBoot. // - Status = gBS->CreateEventEx ( - EVT_NOTIFY_SIGNAL, - TPL_NOTIFY, - InstallMemoryAttributesTable, - NULL, - &gEfiEventReadyToBootGuid, - &ReadyToBootEvent - ); + Status = CoreCreateEventInternal ( + EVT_NOTIFY_SIGNAL, + TPL_CALLBACK - 1, + InstallMemoryAttributesTableOnReadyToBoot, + NULL, + &gEfiEventReadyToBootGuid, + &ReadyToBootEvent + ); ASSERT_EFI_ERROR (Status); return ; }