X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdeModulePkg%2FCore%2FDxe%2FMisc%2FPropertiesTable.c;h=32497c1c0c695898c20e41640d1f32d9400b9d09;hb=4cb6375ca6ddf73577758a72b1464896c3eae767;hp=0232a3ce7d937dcb8ca2bd257e532fe72f6d3906;hpb=bc31c0c604fed97768bf39ad0d2e8182e3605709;p=mirror_edk2.git diff --git a/MdeModulePkg/Core/Dxe/Misc/PropertiesTable.c b/MdeModulePkg/Core/Dxe/Misc/PropertiesTable.c index 0232a3ce7d..32497c1c0c 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, Intel Corporation. All rights reserved.
+Copyright (c) 2015 - 2016, 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 @@ -80,6 +80,8 @@ EFI_PROPERTIES_TABLE mPropertiesTable = { EFI_LOCK mPropertiesTableLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_NOTIFY); +BOOLEAN mPropertiesTableEnable; + // // Below functions are for MemoryMap // @@ -221,14 +223,24 @@ MergeMemoryMap ( CopyMem (NewMemoryMapEntry, MemoryMapEntry, sizeof(EFI_MEMORY_DESCRIPTOR)); NextMemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, DescriptorSize); - MemoryBlockLength = (UINT64) (EfiPagesToSize (MemoryMapEntry->NumberOfPages)); - if (((UINTN)NextMemoryMapEntry < (UINTN)MemoryMapEnd) && - (MemoryMapEntry->Type == NextMemoryMapEntry->Type) && - (MemoryMapEntry->Attribute == NextMemoryMapEntry->Attribute) && - ((MemoryMapEntry->PhysicalStart + MemoryBlockLength) == NextMemoryMapEntry->PhysicalStart)) { - NewMemoryMapEntry->NumberOfPages += NextMemoryMapEntry->NumberOfPages; - MemoryMapEntry = NextMemoryMapEntry; - } + do { + MemoryBlockLength = (UINT64) (EfiPagesToSize (MemoryMapEntry->NumberOfPages)); + if (((UINTN)NextMemoryMapEntry < (UINTN)MemoryMapEnd) && + (MemoryMapEntry->Type == NextMemoryMapEntry->Type) && + (MemoryMapEntry->Attribute == NextMemoryMapEntry->Attribute) && + ((MemoryMapEntry->PhysicalStart + MemoryBlockLength) == NextMemoryMapEntry->PhysicalStart)) { + MemoryMapEntry->NumberOfPages += NextMemoryMapEntry->NumberOfPages; + if (NewMemoryMapEntry != MemoryMapEntry) { + NewMemoryMapEntry->NumberOfPages += NextMemoryMapEntry->NumberOfPages; + } + + NextMemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (NextMemoryMapEntry, DescriptorSize); + continue; + } else { + MemoryMapEntry = PREVIOUS_MEMORY_DESCRIPTOR (NextMemoryMapEntry, DescriptorSize); + break; + } + } while (TRUE); MemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, DescriptorSize); NewMemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (NewMemoryMapEntry, DescriptorSize); @@ -374,7 +386,11 @@ SetNewRecord ( // // DATA // - NewRecord->Type = EfiRuntimeServicesData; + if (!mPropertiesTableEnable) { + NewRecord->Type = TempRecord.Type; + } else { + NewRecord->Type = EfiRuntimeServicesData; + } NewRecord->PhysicalStart = TempRecord.PhysicalStart; NewRecord->VirtualStart = 0; NewRecord->NumberOfPages = EfiSizeToPages(ImageRecordCodeSection->CodeSegmentBase - NewRecord->PhysicalStart); @@ -387,7 +403,11 @@ SetNewRecord ( // // CODE // - NewRecord->Type = EfiRuntimeServicesCode; + if (!mPropertiesTableEnable) { + NewRecord->Type = TempRecord.Type; + } else { + NewRecord->Type = EfiRuntimeServicesCode; + } NewRecord->PhysicalStart = ImageRecordCodeSection->CodeSegmentBase; NewRecord->VirtualStart = 0; NewRecord->NumberOfPages = EfiSizeToPages(ImageRecordCodeSection->CodeSegmentSize); @@ -411,7 +431,11 @@ SetNewRecord ( // Final DATA // if (TempRecord.PhysicalStart < ImageEnd) { - NewRecord->Type = EfiRuntimeServicesData; + if (!mPropertiesTableEnable) { + NewRecord->Type = TempRecord.Type; + } else { + NewRecord->Type = EfiRuntimeServicesData; + } NewRecord->PhysicalStart = TempRecord.PhysicalStart; NewRecord->VirtualStart = 0; NewRecord->NumberOfPages = EfiSizeToPages (ImageEnd - TempRecord.PhysicalStart); @@ -493,6 +517,7 @@ SplitRecord ( UINT64 PhysicalEnd; UINTN NewRecordCount; UINTN TotalNewRecordCount; + BOOLEAN IsLastRecordData; if (MaxSplitRecordCount == 0) { CopyMem (NewRecord, OldRecord, DescriptorSize); @@ -520,7 +545,17 @@ SplitRecord ( // If this is still address in this record, need record. // NewRecord = PREVIOUS_MEMORY_DESCRIPTOR (NewRecord, DescriptorSize); - if (NewRecord->Type == EfiRuntimeServicesData) { + IsLastRecordData = FALSE; + if (!mPropertiesTableEnable) { + if ((NewRecord->Attribute & EFI_MEMORY_XP) != 0) { + IsLastRecordData = TRUE; + } + } else { + if (NewRecord->Type == EfiRuntimeServicesData) { + IsLastRecordData = TRUE; + } + } + if (IsLastRecordData) { // // Last record is DATA, just merge it. // @@ -530,7 +565,11 @@ SplitRecord ( // Last record is CODE, create a new DATA entry. // NewRecord = NEXT_MEMORY_DESCRIPTOR (NewRecord, DescriptorSize); - NewRecord->Type = EfiRuntimeServicesData; + if (!mPropertiesTableEnable) { + NewRecord->Type = TempRecord.Type; + } else { + NewRecord->Type = EfiRuntimeServicesData; + } NewRecord->PhysicalStart = TempRecord.PhysicalStart; NewRecord->VirtualStart = 0; NewRecord->NumberOfPages = TempRecord.NumberOfPages; @@ -686,7 +725,7 @@ SplitTable ( } /** - This function for GetMemoryMap() with properties table. + This function for GetMemoryMap() with properties table capability. It calls original GetMemoryMap() to get the original memory map information. Then plus the additional memory map entries for PE Code/Data seperation. @@ -717,7 +756,6 @@ SplitTable ( @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value. **/ -STATIC EFI_STATUS EFIAPI CoreGetMemoryMapPropertiesTable ( @@ -752,6 +790,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; // @@ -775,7 +814,7 @@ CoreGetMemoryMapPropertiesTable ( // /** - Set PropertiesTable accroding to PE/COFF image section alignment. + Set PropertiesTable according to PE/COFF image section alignment. @param SectionAlignment PE/COFF section alignment **/ @@ -785,10 +824,10 @@ SetPropertiesTableSectionAlignment ( IN UINT32 SectionAlignment ) { - if (((SectionAlignment & (SIZE_4KB - 1)) != 0) && + if (((SectionAlignment & (EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT - 1)) != 0) && ((mPropertiesTable.MemoryProtectionAttribute & EFI_PROPERTIES_RUNTIME_MEMORY_PROTECTION_NON_EXECUTABLE_PE_DATA) != 0)) { DEBUG ((EFI_D_VERBOSE, "SetPropertiesTableSectionAlignment - Clear\n")); - mPropertiesTable.MemoryProtectionAttribute &= ~EFI_PROPERTIES_RUNTIME_MEMORY_PROTECTION_NON_EXECUTABLE_PE_DATA; + mPropertiesTable.MemoryProtectionAttribute &= ~((UINT64)EFI_PROPERTIES_RUNTIME_MEMORY_PROTECTION_NON_EXECUTABLE_PE_DATA); gBS->GetMemoryMap = CoreGetMemoryMap; gBS->Hdr.CRC32 = 0; gBS->CalculateCrc32 ((UINT8 *)gBS, gBS->Hdr.HeaderSize, &gBS->Hdr.CRC32); @@ -1119,11 +1158,12 @@ InsertImageRecord ( } SetPropertiesTableSectionAlignment (SectionAlignment); - if ((SectionAlignment & (SIZE_4KB - 1)) != 0) { - DEBUG ((EFI_D_ERROR, "!!!!!!!! InsertImageRecord - Section Alignment(0x%x) is not 4K !!!!!!!!\n", SectionAlignment)); + if ((SectionAlignment & (EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT - 1)) != 0) { + DEBUG ((EFI_D_WARN, "!!!!!!!! InsertImageRecord - Section Alignment(0x%x) is not %dK !!!!!!!!\n", + SectionAlignment, EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT >> 10)); PdbPointer = PeCoffLoaderGetPdbPointer ((VOID*) (UINTN) ImageAddress); if (PdbPointer != NULL) { - DEBUG ((EFI_D_ERROR, "!!!!!!!! Image - %a !!!!!!!!\n", PdbPointer)); + DEBUG ((EFI_D_WARN, "!!!!!!!! Image - %a !!!!!!!!\n", PdbPointer)); } goto Finish; } @@ -1218,7 +1258,7 @@ Finish: } /** - Find image record accroding to image base and size. + Find image record according to image base and size. @param ImageBase Base of PE image @param ImageSize Size of PE image @@ -1319,6 +1359,8 @@ 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)); return ; } @@ -1329,6 +1371,8 @@ InstallPropertiesTable ( DEBUG ((EFI_D_VERBOSE, "Total Image Count - 0x%x\n", mImagePropertiesPrivateData.ImageRecordCount)); DEBUG ((EFI_D_VERBOSE, "Dump ImageRecord:\n")); DumpImageRecord (); + + mPropertiesTableEnable = TRUE; } }