X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FCore%2FDxe%2FMisc%2FPropertiesTable.c;h=a96d442fbc6458247f2f1aa9868bc0439618573d;hp=ebe70966db78fd9f32bdc84074c565b34072008c;hb=4a723ed258367471eac8b4ae32558f09ef65672e;hpb=82f0f411c7912de105d1484fd294bde8aacb6c1e diff --git a/MdeModulePkg/Core/Dxe/Misc/PropertiesTable.c b/MdeModulePkg/Core/Dxe/Misc/PropertiesTable.c index ebe70966db..a96d442fbc 100644 --- a/MdeModulePkg/Core/Dxe/Misc/PropertiesTable.c +++ b/MdeModulePkg/Core/Dxe/Misc/PropertiesTable.c @@ -1,7 +1,7 @@ /** @file UEFI PropertiesTable support -Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.
+Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -36,26 +36,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #define PREVIOUS_MEMORY_DESCRIPTOR(MemoryDescriptor, Size) \ ((EFI_MEMORY_DESCRIPTOR *)((UINT8 *)(MemoryDescriptor) - (Size))) -#define IMAGE_PROPERTIES_RECORD_CODE_SECTION_SIGNATURE SIGNATURE_32 ('I','P','R','C') - -typedef struct { - UINT32 Signature; - LIST_ENTRY Link; - EFI_PHYSICAL_ADDRESS CodeSegmentBase; - UINT64 CodeSegmentSize; -} IMAGE_PROPERTIES_RECORD_CODE_SECTION; - -#define IMAGE_PROPERTIES_RECORD_SIGNATURE SIGNATURE_32 ('I','P','R','D') - -typedef struct { - UINT32 Signature; - LIST_ENTRY Link; - EFI_PHYSICAL_ADDRESS ImageBase; - UINT64 ImageSize; - UINTN CodeSegmentCount; - LIST_ENTRY CodeSegmentList; -} IMAGE_PROPERTIES_RECORD; - #define IMAGE_PROPERTIES_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('I','P','P','D') typedef struct { @@ -82,6 +62,8 @@ EFI_LOCK mPropertiesTableLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_NOTI BOOLEAN mPropertiesTableEnable; +BOOLEAN mPropertiesTableEndOfDxe = FALSE; + // // Below functions are for MemoryMap // @@ -202,7 +184,6 @@ SortMemoryMap ( it is the size of new memory map after merge. @param DescriptorSize Size, in bytes, of an individual EFI_MEMORY_DESCRIPTOR. **/ -STATIC VOID MergeMemoryMap ( IN OUT EFI_MEMORY_DESCRIPTOR *MemoryMap, @@ -596,6 +577,11 @@ SplitRecord ( TempRecord.NumberOfPages = EfiSizeToPages (PhysicalEnd - PhysicalStart); } while ((ImageRecord != NULL) && (PhysicalStart < PhysicalEnd)); + // + // The logic in function SplitTable() ensures that TotalNewRecordCount will not be zero if the + // code reaches here. + // + ASSERT (TotalNewRecordCount != 0); return TotalNewRecordCount - 1; } @@ -758,7 +744,7 @@ SplitTable ( **/ EFI_STATUS EFIAPI -CoreGetMemoryMapPropertiesTable ( +CoreGetMemoryMapWithSeparatedImageSection ( IN OUT UINTN *MemoryMapSize, IN OUT EFI_MEMORY_DESCRIPTOR *MemoryMap, OUT UINTN *MapKey, @@ -790,6 +776,7 @@ CoreGetMemoryMapPropertiesTable ( if (Status == EFI_BUFFER_TOO_SMALL) { *MemoryMapSize = *MemoryMapSize + (*DescriptorSize) * AdditionalRecordCount; } else if (Status == EFI_SUCCESS) { + ASSERT (MemoryMap != NULL); if (OldMemoryMapSize - *MemoryMapSize < (*DescriptorSize) * AdditionalRecordCount) { *MemoryMapSize = *MemoryMapSize + (*DescriptorSize) * AdditionalRecordCount; // @@ -823,7 +810,7 @@ SetPropertiesTableSectionAlignment ( IN UINT32 SectionAlignment ) { - if (((SectionAlignment & (EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT - 1)) != 0) && + if (((SectionAlignment & (RUNTIME_PAGE_ALLOCATION_GRANULARITY - 1)) != 0) && ((mPropertiesTable.MemoryProtectionAttribute & EFI_PROPERTIES_RUNTIME_MEMORY_PROTECTION_NON_EXECUTABLE_PE_DATA) != 0)) { DEBUG ((EFI_D_VERBOSE, "SetPropertiesTableSectionAlignment - Clear\n")); mPropertiesTable.MemoryProtectionAttribute &= ~((UINT64)EFI_PROPERTIES_RUNTIME_MEMORY_PROTECTION_NON_EXECUTABLE_PE_DATA); @@ -863,7 +850,6 @@ SwapImageRecordCodeSection ( @param ImageRecord image record to be sorted **/ -STATIC VOID SortImageRecordCodeSection ( IN IMAGE_PROPERTIES_RECORD *ImageRecord @@ -914,7 +900,6 @@ SortImageRecordCodeSection ( @retval TRUE image record is valid @retval FALSE image record is invalid **/ -STATIC BOOLEAN IsImageRecordCodeSectionValid ( IN IMAGE_PROPERTIES_RECORD *ImageRecord @@ -1096,6 +1081,11 @@ InsertImageRecord ( DEBUG ((EFI_D_VERBOSE, "InsertImageRecord - 0x%x\n", RuntimeImage)); DEBUG ((EFI_D_VERBOSE, "InsertImageRecord - 0x%016lx - 0x%016lx\n", (EFI_PHYSICAL_ADDRESS)(UINTN)RuntimeImage->ImageBase, RuntimeImage->ImageSize)); + if (mPropertiesTableEndOfDxe) { + DEBUG ((DEBUG_INFO, "Do not insert runtime image record after EndOfDxe\n")); + return ; + } + ImageRecord = AllocatePool (sizeof(*ImageRecord)); if (ImageRecord == NULL) { return ; @@ -1157,9 +1147,9 @@ InsertImageRecord ( } SetPropertiesTableSectionAlignment (SectionAlignment); - if ((SectionAlignment & (EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT - 1)) != 0) { + if ((SectionAlignment & (RUNTIME_PAGE_ALLOCATION_GRANULARITY - 1)) != 0) { DEBUG ((EFI_D_WARN, "!!!!!!!! InsertImageRecord - Section Alignment(0x%x) is not %dK !!!!!!!!\n", - SectionAlignment, EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT >> 10)); + SectionAlignment, RUNTIME_PAGE_ALLOCATION_GRANULARITY >> 10)); PdbPointer = PeCoffLoaderGetPdbPointer ((VOID*) (UINTN) ImageAddress); if (PdbPointer != NULL) { DEBUG ((EFI_D_WARN, "!!!!!!!! Image - %a !!!!!!!!\n", PdbPointer)); @@ -1246,12 +1236,12 @@ InsertImageRecord ( InsertTailList (&mImagePropertiesPrivateData.ImageRecordList, &ImageRecord->Link); mImagePropertiesPrivateData.ImageRecordCount++; - SortImageRecord (); - if (mImagePropertiesPrivateData.CodeSegmentCountMax < ImageRecord->CodeSegmentCount) { mImagePropertiesPrivateData.CodeSegmentCountMax = ImageRecord->CodeSegmentCount; } + SortImageRecord (); + Finish: return ; } @@ -1313,6 +1303,11 @@ RemoveImageRecord ( DEBUG ((EFI_D_VERBOSE, "RemoveImageRecord - 0x%x\n", RuntimeImage)); DEBUG ((EFI_D_VERBOSE, "RemoveImageRecord - 0x%016lx - 0x%016lx\n", (EFI_PHYSICAL_ADDRESS)(UINTN)RuntimeImage->ImageBase, RuntimeImage->ImageSize)); + if (mPropertiesTableEndOfDxe) { + DEBUG ((DEBUG_INFO, "Do not remove runtime image record after EndOfDxe\n")); + return ; + } + ImageRecord = FindImageRecord ((EFI_PHYSICAL_ADDRESS)(UINTN)RuntimeImage->ImageBase, RuntimeImage->ImageSize); if (ImageRecord == NULL) { DEBUG ((EFI_D_ERROR, "!!!!!!!! ImageRecord not found !!!!!!!!\n")); @@ -1350,6 +1345,7 @@ InstallPropertiesTable ( VOID *Context ) { + mPropertiesTableEndOfDxe = TRUE; if (PcdGetBool (PcdPropertiesTableEnable)) { EFI_STATUS Status; @@ -1359,11 +1355,11 @@ InstallPropertiesTable ( DEBUG ((EFI_D_INFO, "MemoryProtectionAttribute - 0x%016lx\n", mPropertiesTable.MemoryProtectionAttribute)); if ((mPropertiesTable.MemoryProtectionAttribute & EFI_PROPERTIES_RUNTIME_MEMORY_PROTECTION_NON_EXECUTABLE_PE_DATA) == 0) { DEBUG ((EFI_D_ERROR, "MemoryProtectionAttribute NON_EXECUTABLE_PE_DATA is not set, ")); - DEBUG ((EFI_D_ERROR, "because Runtime Driver Section Alignment is not %dK.\n", EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT >> 10)); + DEBUG ((EFI_D_ERROR, "because Runtime Driver Section Alignment is not %dK.\n", RUNTIME_PAGE_ALLOCATION_GRANULARITY >> 10)); return ; } - gBS->GetMemoryMap = CoreGetMemoryMapPropertiesTable; + gBS->GetMemoryMap = CoreGetMemoryMapWithSeparatedImageSection; gBS->Hdr.CRC32 = 0; gBS->CalculateCrc32 ((UINT8 *)gBS, gBS->Hdr.HeaderSize, &gBS->Hdr.CRC32);