X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FCore%2FPiSmmCore%2FMemoryAttributesTable.c;h=157beb1e67ff3f994e20f87923b2dcc2dca119bc;hp=eba938e2a92b8334b7b4f7f89556eeacc31274b3;hb=05cfd73f011f67541cf4add560ab213daa8a99ed;hpb=11ee1bc93dfb590ae0c9bd0f0400b8591ad21525 diff --git a/MdeModulePkg/Core/PiSmmCore/MemoryAttributesTable.c b/MdeModulePkg/Core/PiSmmCore/MemoryAttributesTable.c index eba938e2a9..157beb1e67 100644 --- a/MdeModulePkg/Core/PiSmmCore/MemoryAttributesTable.c +++ b/MdeModulePkg/Core/PiSmmCore/MemoryAttributesTable.c @@ -114,34 +114,6 @@ EfiSizeToPages ( return RShiftU64 (Size, EFI_PAGE_SHIFT) + ((((UINTN)Size) & EFI_PAGE_MASK) ? 1 : 0); } -/** - Check the consistency of Smm memory attributes table. - - @param[in] MemoryAttributesTable PI SMM memory attributes table -**/ -VOID -SmmMemoryAttributesTableConsistencyCheck ( - IN EDKII_PI_SMM_MEMORY_ATTRIBUTES_TABLE *MemoryAttributesTable - ) -{ - EFI_MEMORY_DESCRIPTOR *MemoryMap; - UINTN MemoryMapEntryCount; - UINTN DescriptorSize; - UINTN Index; - UINT64 Address; - - Address = 0; - MemoryMapEntryCount = MemoryAttributesTable->NumberOfEntries; - DescriptorSize = MemoryAttributesTable->DescriptorSize; - MemoryMap = (EFI_MEMORY_DESCRIPTOR *)(MemoryAttributesTable + 1); - for (Index = 0; Index < MemoryMapEntryCount; Index++) { - if (Address != 0) { - ASSERT (Address == MemoryMap->PhysicalStart); - } - Address = MemoryMap->PhysicalStart + EfiPagesToSize(MemoryMap->NumberOfPages); - MemoryMap = NEXT_MEMORY_DESCRIPTOR(MemoryMap, DescriptorSize); - } -} /** Sort memory map entries based upon PhysicalStart, from low to high. @@ -785,7 +757,7 @@ SmmCoreGetMemoryMapMemoryAttributesTable ( // /** - Set MemoryProtectionAttribute accroding to PE/COFF image section alignment. + Set MemoryProtectionAttribute according to PE/COFF image section alignment. @param[in] SectionAlignment PE/COFF section alignment **/ @@ -795,7 +767,7 @@ SetMemoryAttributesTableSectionAlignment ( IN UINT32 SectionAlignment ) { - if (((SectionAlignment & (EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT - 1)) != 0) && + if (((SectionAlignment & (RUNTIME_PAGE_ALLOCATION_GRANULARITY - 1)) != 0) && ((mMemoryProtectionAttribute & EFI_MEMORY_ATTRIBUTES_RUNTIME_MEMORY_PROTECTION_NON_EXECUTABLE_PE_DATA) != 0)) { DEBUG ((DEBUG_VERBOSE, "SMM SetMemoryAttributesTableSectionAlignment - Clear\n")); mMemoryProtectionAttribute &= ~((UINT64)EFI_MEMORY_ATTRIBUTES_RUNTIME_MEMORY_PROTECTION_NON_EXECUTABLE_PE_DATA); @@ -1060,7 +1032,6 @@ SmmInsertImageRecord ( IMAGE_PROPERTIES_RECORD *ImageRecord; CHAR8 *PdbPointer; IMAGE_PROPERTIES_RECORD_CODE_SECTION *ImageRecordCodeSection; - UINT16 Magic; DEBUG ((DEBUG_VERBOSE, "SMM InsertImageRecord - 0x%x\n", DriverEntry)); DEBUG ((DEBUG_VERBOSE, "SMM InsertImageRecord - 0x%016lx - 0x%08x\n", DriverEntry->ImageBuffer, DriverEntry->NumberOfPage)); @@ -1104,30 +1075,16 @@ SmmInsertImageRecord ( // // Get SectionAlignment // - if (Hdr.Pe32->FileHeader.Machine == IMAGE_FILE_MACHINE_IA64 && Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { - // - // NOTE: Some versions of Linux ELILO for Itanium have an incorrect magic value - // in the PE/COFF Header. If the MachineType is Itanium(IA64) and the - // Magic value in the OptionalHeader is EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC - // then override the magic value to EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC - // - Magic = EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC; - } else { - // - // Get the magic value from the PE/COFF Optional Header - // - Magic = Hdr.Pe32->OptionalHeader.Magic; - } - if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { + if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { SectionAlignment = Hdr.Pe32->OptionalHeader.SectionAlignment; } else { SectionAlignment = Hdr.Pe32Plus->OptionalHeader.SectionAlignment; } SetMemoryAttributesTableSectionAlignment (SectionAlignment); - if ((SectionAlignment & (EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT - 1)) != 0) { + if ((SectionAlignment & (RUNTIME_PAGE_ALLOCATION_GRANULARITY - 1)) != 0) { DEBUG ((DEBUG_WARN, "SMM !!!!!!!! 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 ((DEBUG_WARN, "SMM !!!!!!!! Image - %a !!!!!!!!\n", PdbPointer)); @@ -1214,95 +1171,16 @@ SmmInsertImageRecord ( InsertTailList (&mImagePropertiesPrivateData.ImageRecordList, &ImageRecord->Link); mImagePropertiesPrivateData.ImageRecordCount++; - SortImageRecord (); - if (mImagePropertiesPrivateData.CodeSegmentCountMax < ImageRecord->CodeSegmentCount) { mImagePropertiesPrivateData.CodeSegmentCountMax = ImageRecord->CodeSegmentCount; } + SortImageRecord (); + Finish: return ; } -/** - Find image record accroding to image base and size. - - @param[in] ImageBase Base of PE image - @param[in] ImageSize Size of PE image - - @return image record -**/ -STATIC -IMAGE_PROPERTIES_RECORD * -FindImageRecord ( - IN EFI_PHYSICAL_ADDRESS ImageBase, - IN UINT64 ImageSize - ) -{ - IMAGE_PROPERTIES_RECORD *ImageRecord; - LIST_ENTRY *ImageRecordLink; - LIST_ENTRY *ImageRecordList; - - ImageRecordList = &mImagePropertiesPrivateData.ImageRecordList; - - for (ImageRecordLink = ImageRecordList->ForwardLink; - ImageRecordLink != ImageRecordList; - ImageRecordLink = ImageRecordLink->ForwardLink) { - ImageRecord = CR ( - ImageRecordLink, - IMAGE_PROPERTIES_RECORD, - Link, - IMAGE_PROPERTIES_RECORD_SIGNATURE - ); - - if ((ImageBase == ImageRecord->ImageBase) && - (ImageSize == ImageRecord->ImageSize)) { - return ImageRecord; - } - } - - return NULL; -} - -/** - Remove Image record. - - @param[in] DriverEntry Driver information -**/ -VOID -SmmRemoveImageRecord ( - IN EFI_SMM_DRIVER_ENTRY *DriverEntry - ) -{ - IMAGE_PROPERTIES_RECORD *ImageRecord; - LIST_ENTRY *CodeSegmentListHead; - IMAGE_PROPERTIES_RECORD_CODE_SECTION *ImageRecordCodeSection; - - DEBUG ((DEBUG_VERBOSE, "SMM RemoveImageRecord - 0x%x\n", DriverEntry)); - DEBUG ((DEBUG_VERBOSE, "SMM RemoveImageRecord - 0x%016lx - 0x%016lx\n", DriverEntry->ImageBuffer, DriverEntry->NumberOfPage)); - - ImageRecord = FindImageRecord (DriverEntry->ImageBuffer, EfiPagesToSize(DriverEntry->NumberOfPage)); - if (ImageRecord == NULL) { - DEBUG ((DEBUG_ERROR, "SMM !!!!!!!! ImageRecord not found !!!!!!!!\n")); - return ; - } - - CodeSegmentListHead = &ImageRecord->CodeSegmentList; - while (!IsListEmpty (CodeSegmentListHead)) { - ImageRecordCodeSection = CR ( - CodeSegmentListHead->ForwardLink, - IMAGE_PROPERTIES_RECORD_CODE_SECTION, - Link, - IMAGE_PROPERTIES_RECORD_CODE_SECTION_SIGNATURE - ); - RemoveEntryList (&ImageRecordCodeSection->Link); - FreePool (ImageRecordCodeSection); - } - - RemoveEntryList (&ImageRecord->Link); - FreePool (ImageRecord); - mImagePropertiesPrivateData.ImageRecordCount--; -} /** Publish MemoryAttributesTable to SMM configuration table. @@ -1386,30 +1264,6 @@ PublishMemoryAttributesTable ( ASSERT_EFI_ERROR (Status); } -/** - This function returns if image is inside SMRAM. - - @param[in] LoadedImage LoadedImage protocol instance for an image. - - @retval TRUE the image is inside SMRAM. - @retval FALSE the image is outside SMRAM. -**/ -BOOLEAN -IsImageInsideSmram ( - IN EFI_LOADED_IMAGE_PROTOCOL *LoadedImage - ) -{ - UINTN Index; - - for (Index = 0; Index < mFullSmramRangeCount; Index++) { - if ((mFullSmramRanges[Index].PhysicalStart <= (UINTN)LoadedImage->ImageBase)&& - (mFullSmramRanges[Index].PhysicalStart + mFullSmramRanges[Index].PhysicalSize >= (UINTN)LoadedImage->ImageBase + LoadedImage->ImageSize)) { - return TRUE; - } - } - - return FALSE; -} /** This function installs all SMM image record information.