From nobody Thu May 9 19:23:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+107067+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+107067+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1689811559; cv=none; d=zohomail.com; s=zohoarc; b=jtd5+cEFT4hQ53AGPokcWY15Bgm+Mi+GnRsj8NZex1wPwB0uW1bJC5NKkPGcDV7QufTd4HEd4NsPq6IecWFggEK2zxJXZ2NgySfHRAgfrY4fq1b3IXY38omIvfBo/80KcDvJifD1vY7C+/NEsoWUwRgIB9iCa5dDhEdlsVIfk+c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689811559; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=b1Co524nie7Xt/KjzThCUSTvyfa4WCqw8TrE7Is0XCc=; b=SZFHGkgc2oS7rGjafkKWQKN8En1MiwjfajwykmPdJWwzc5RFG69/JuyrP5BUF84cOTwupYxOxeZJdsehJiFCFvIHc2FpjgbmZsb20In6iQlMi0C26/ONeVe+aJjwfD2Zs94e57QJwgTgQvNsPAMDtV0RNiaNLOWULbZj+JS4e7c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+107067+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1689811559968445.52050314819724; Wed, 19 Jul 2023 17:05:59 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=dGfJYwW3xSHIBSYgc3PHxA+1zT02WTtzI3+ufvvdG1o=; c=relaxed/simple; d=groups.io; h=X-Received:X-Received:X-Received:X-Gm-Message-State:X-Google-Smtp-Source:X-Received:X-Received:From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:MIME-Version:Precedence:List-Unsubscribe:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:Content-Transfer-Encoding; s=20140610; t=1689811559; v=1; b=D8PD1Etgqz7glDrvOi0XsUvRnC38y9UDVrACTqIYDjNb7f7qHrL0XjsoEbFdIt8ysACfJoy8 yacvu9yVUJd1cjKBwB5ck8i7DKDjx2keKHQGER+z25hYG8hdvuysCfZKt29Mz5lDYDb2hf/go8w Bwm4ebaAWTmu9sfdW06m99g0= X-Received: by 127.0.0.2 with SMTP id O23IYY1788612x0a1iAvWVuJ; Wed, 19 Jul 2023 17:05:59 -0700 X-Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by mx.groups.io with SMTP id smtpd.web10.2232.1689811558957583443 for ; Wed, 19 Jul 2023 17:05:59 -0700 X-Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-1b9e93a538dso1186645ad.3 for ; Wed, 19 Jul 2023 17:05:58 -0700 (PDT) X-Gm-Message-State: NS398wcJ7wA7p1TzlsMjO51Kx1787277AA= X-Google-Smtp-Source: APBJJlHg8cZRn7Y3OqAJ16I+68dz2/Y7h49qoLgIdDCFaXRFElnsi6ooxWz+uco1fJJUZgn1pe095Q== X-Received: by 2002:a17:902:d4d1:b0:1b6:a99b:ceb1 with SMTP id o17-20020a170902d4d100b001b6a99bceb1mr19568635plg.50.1689811558055; Wed, 19 Jul 2023 17:05:58 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.230.135]) by smtp.gmail.com with ESMTPSA id jf10-20020a170903268a00b001b83e624eecsm4617286plb.81.2023.07.19.17.05.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jul 2023 17:05:57 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Jian J Wang , Liming Gao , Dandan Bi Subject: [edk2-devel] [PATCH v2 1/9] MdeModulePkg: Add ImagePropertiesRecordLib Date: Wed, 19 Jul 2023 17:05:36 -0700 Message-ID: <20230720000544.146-2-t@taylorbeebe.com> In-Reply-To: <20230720000544.146-1-t@taylorbeebe.com> References: <20230720000544.146-1-t@taylorbeebe.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,t@taylorbeebe.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1689811561653100008 Content-Type: text/plain; charset="utf-8" Create a library for manipulating image properties records. Image properties record logic is already present in both the SMM and UEFI MAT logic, and this is a copy of the UEFI MAT logic with added function arguments to remove dependencies on global variables. Signed-off-by: Taylor Beebe Cc: Jian J Wang Cc: Liming Gao Cc: Dandan Bi --- MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.c = | 807 ++++++++++++++++++++ MdeModulePkg/Include/Library/ImagePropertiesRecordLib.h = | 151 ++++ MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.inf= | 28 + MdeModulePkg/MdeModulePkg.dec = | 5 + MdeModulePkg/MdeModulePkg.dsc = | 2 + 5 files changed, 993 insertions(+) diff --git a/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesR= ecordLib.c b/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesR= ecordLib.c new file mode 100644 index 000000000000..46f4f401a4d5 --- /dev/null +++ b/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLi= b.c @@ -0,0 +1,807 @@ +/** @file + + Provides definitions and functionality for manipulating Image Properties= Records. + + Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include + +#include +#include +#include +#include + +#define PREVIOUS_MEMORY_DESCRIPTOR(MemoryDescriptor, Size) \ + ((EFI_MEMORY_DESCRIPTOR *)((UINT8 *)(MemoryDescriptor) - (Size))) + +#define NEXT_MEMORY_DESCRIPTOR(MemoryDescriptor, Size) \ + ((EFI_MEMORY_DESCRIPTOR *)((UINT8 *)(MemoryDescriptor) + (Size))) + +/** + Converts a number of EFI_PAGEs to a size in bytes. + + NOTE: Do not use EFI_PAGES_TO_SIZE because it handles UINTN only. + + @param Pages The number of EFI_PAGES. + + @return The number of bytes associated with the number of EFI_PAGEs spe= cified + by Pages. +**/ +STATIC +UINT64 +EfiPagesToSize ( + IN UINT64 Pages + ) +{ + return LShiftU64 (Pages, EFI_PAGE_SHIFT); +} + +/** + Converts a size, in bytes, to a number of EFI_PAGESs. + + NOTE: Do not use EFI_SIZE_TO_PAGES because it handles UINTN only. + + @param Size A size in bytes. + + @return The number of EFI_PAGESs associated with the number of bytes sp= ecified + by Size. + +**/ +STATIC +UINT64 +EfiSizeToPages ( + IN UINT64 Size + ) +{ + return RShiftU64 (Size, EFI_PAGE_SHIFT) + ((((UINTN)Size) & EFI_PAGE_MAS= K) ? 1 : 0); +} + +/** + Sort memory map entries based upon PhysicalStart, from low to high. + + @param MemoryMap A pointer to the buffer in which firmware= places + the current memory map. + @param MemoryMapSize Size, in bytes, of the MemoryMap buffer. + @param DescriptorSize Size, in bytes, of an individual EFI_MEMO= RY_DESCRIPTOR. +**/ +STATIC +VOID +SortMemoryMap ( + IN OUT EFI_MEMORY_DESCRIPTOR *MemoryMap, + IN UINTN MemoryMapSize, + IN UINTN DescriptorSize + ) +{ + EFI_MEMORY_DESCRIPTOR *MemoryMapEntry; + EFI_MEMORY_DESCRIPTOR *NextMemoryMapEntry; + EFI_MEMORY_DESCRIPTOR *MemoryMapEnd; + EFI_MEMORY_DESCRIPTOR TempMemoryMap; + + MemoryMapEntry =3D MemoryMap; + NextMemoryMapEntry =3D NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, Descripto= rSize); + MemoryMapEnd =3D (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)MemoryMap + Me= moryMapSize); + while (MemoryMapEntry < MemoryMapEnd) { + while (NextMemoryMapEntry < MemoryMapEnd) { + if (MemoryMapEntry->PhysicalStart > NextMemoryMapEntry->PhysicalStar= t) { + CopyMem (&TempMemoryMap, MemoryMapEntry, sizeof (EFI_MEMORY_DESCRI= PTOR)); + CopyMem (MemoryMapEntry, NextMemoryMapEntry, sizeof (EFI_MEMORY_DE= SCRIPTOR)); + CopyMem (NextMemoryMapEntry, &TempMemoryMap, sizeof (EFI_MEMORY_DE= SCRIPTOR)); + } + + NextMemoryMapEntry =3D NEXT_MEMORY_DESCRIPTOR (NextMemoryMapEntry, D= escriptorSize); + } + + MemoryMapEntry =3D NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, Descrip= torSize); + NextMemoryMapEntry =3D NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, Descrip= torSize); + } + + return; +} + +/** + Swap two code sections in image record. + + @param FirstImageRecordCodeSection first code section in image record + @param SecondImageRecordCodeSection second code section in image reco= rd +**/ +STATIC +VOID +SwapImageRecordCodeSection ( + IN IMAGE_PROPERTIES_RECORD_CODE_SECTION *FirstImageRecordCodeSection, + IN IMAGE_PROPERTIES_RECORD_CODE_SECTION *SecondImageRecordCodeSection + ) +{ + IMAGE_PROPERTIES_RECORD_CODE_SECTION TempImageRecordCodeSection; + + TempImageRecordCodeSection.CodeSegmentBase =3D FirstImageRecordCodeSecti= on->CodeSegmentBase; + TempImageRecordCodeSection.CodeSegmentSize =3D FirstImageRecordCodeSecti= on->CodeSegmentSize; + + FirstImageRecordCodeSection->CodeSegmentBase =3D SecondImageRecordCodeSe= ction->CodeSegmentBase; + FirstImageRecordCodeSection->CodeSegmentSize =3D SecondImageRecordCodeSe= ction->CodeSegmentSize; + + SecondImageRecordCodeSection->CodeSegmentBase =3D TempImageRecordCodeSec= tion.CodeSegmentBase; + SecondImageRecordCodeSection->CodeSegmentSize =3D TempImageRecordCodeSec= tion.CodeSegmentSize; +} + +/** + Check if code section in image record is valid. + + @param ImageRecord image record to be checked + + @retval TRUE image record is valid + @retval FALSE image record is invalid +**/ +BOOLEAN +EFIAPI +IsImageRecordCodeSectionValid ( + IN IMAGE_PROPERTIES_RECORD *ImageRecord + ) +{ + IMAGE_PROPERTIES_RECORD_CODE_SECTION *ImageRecordCodeSection; + IMAGE_PROPERTIES_RECORD_CODE_SECTION *LastImageRecordCodeSection; + LIST_ENTRY *ImageRecordCodeSectionLink; + LIST_ENTRY *ImageRecordCodeSectionEndLink; + LIST_ENTRY *ImageRecordCodeSectionList; + + DEBUG ((DEBUG_VERBOSE, "ImageCode SegmentCount - 0x%x\n", ImageRecord->C= odeSegmentCount)); + + ImageRecordCodeSectionList =3D &ImageRecord->CodeSegmentList; + + ImageRecordCodeSectionLink =3D ImageRecordCodeSectionList->ForwardLin= k; + ImageRecordCodeSectionEndLink =3D ImageRecordCodeSectionList; + LastImageRecordCodeSection =3D NULL; + while (ImageRecordCodeSectionLink !=3D ImageRecordCodeSectionEndLink) { + ImageRecordCodeSection =3D CR ( + ImageRecordCodeSectionLink, + IMAGE_PROPERTIES_RECORD_CODE_SECTION, + Link, + IMAGE_PROPERTIES_RECORD_CODE_SECTION_SIGNAT= URE + ); + if (ImageRecordCodeSection->CodeSegmentSize =3D=3D 0) { + return FALSE; + } + + if (ImageRecordCodeSection->CodeSegmentBase < ImageRecord->ImageBase) { + return FALSE; + } + + if (ImageRecordCodeSection->CodeSegmentBase >=3D MAX_ADDRESS - ImageRe= cordCodeSection->CodeSegmentSize) { + return FALSE; + } + + if ((ImageRecordCodeSection->CodeSegmentBase + ImageRecordCodeSection-= >CodeSegmentSize) > (ImageRecord->ImageBase + ImageRecord->ImageSize)) { + return FALSE; + } + + if (LastImageRecordCodeSection !=3D NULL) { + if ((LastImageRecordCodeSection->CodeSegmentBase + LastImageRecordCo= deSection->CodeSegmentSize) > ImageRecordCodeSection->CodeSegmentBase) { + return FALSE; + } + } + + LastImageRecordCodeSection =3D ImageRecordCodeSection; + ImageRecordCodeSectionLink =3D ImageRecordCodeSectionLink->ForwardLink; + } + + return TRUE; +} + +/** + Swap two image records. + + @param FirstImageRecord first image record. + @param SecondImageRecord second image record. +**/ +STATIC +VOID +SwapImageRecord ( + IN IMAGE_PROPERTIES_RECORD *FirstImageRecord, + IN IMAGE_PROPERTIES_RECORD *SecondImageRecord + ) +{ + IMAGE_PROPERTIES_RECORD TempImageRecord; + + TempImageRecord.ImageBase =3D FirstImageRecord->ImageBase; + TempImageRecord.ImageSize =3D FirstImageRecord->ImageSize; + TempImageRecord.CodeSegmentCount =3D FirstImageRecord->CodeSegmentCount; + + FirstImageRecord->ImageBase =3D SecondImageRecord->ImageBase; + FirstImageRecord->ImageSize =3D SecondImageRecord->ImageSize; + FirstImageRecord->CodeSegmentCount =3D SecondImageRecord->CodeSegmentCou= nt; + + SecondImageRecord->ImageBase =3D TempImageRecord.ImageBase; + SecondImageRecord->ImageSize =3D TempImageRecord.ImageSize; + SecondImageRecord->CodeSegmentCount =3D TempImageRecord.CodeSegmentCount; + + SwapListEntries (&FirstImageRecord->CodeSegmentList, &SecondImageRecord-= >CodeSegmentList); +} + +/** + Sort code section in image record, based upon CodeSegmentBase from low t= o high. + + @param ImageRecord image record to be sorted +**/ +VOID +EFIAPI +SortImageRecordCodeSection ( + IN IMAGE_PROPERTIES_RECORD *ImageRecord + ) +{ + IMAGE_PROPERTIES_RECORD_CODE_SECTION *ImageRecordCodeSection; + IMAGE_PROPERTIES_RECORD_CODE_SECTION *NextImageRecordCodeSection; + LIST_ENTRY *ImageRecordCodeSectionLink; + LIST_ENTRY *NextImageRecordCodeSectionLink; + LIST_ENTRY *ImageRecordCodeSectionEndLink; + LIST_ENTRY *ImageRecordCodeSectionList; + + ImageRecordCodeSectionList =3D &ImageRecord->CodeSegmentList; + + ImageRecordCodeSectionLink =3D ImageRecordCodeSectionList->ForwardLi= nk; + NextImageRecordCodeSectionLink =3D ImageRecordCodeSectionLink->ForwardLi= nk; + ImageRecordCodeSectionEndLink =3D ImageRecordCodeSectionList; + while (ImageRecordCodeSectionLink !=3D ImageRecordCodeSectionEndLink) { + ImageRecordCodeSection =3D CR ( + ImageRecordCodeSectionLink, + IMAGE_PROPERTIES_RECORD_CODE_SECTION, + Link, + IMAGE_PROPERTIES_RECORD_CODE_SECTION_SIGNAT= URE + ); + while (NextImageRecordCodeSectionLink !=3D ImageRecordCodeSectionEndLi= nk) { + NextImageRecordCodeSection =3D CR ( + NextImageRecordCodeSectionLink, + IMAGE_PROPERTIES_RECORD_CODE_SECTION, + Link, + IMAGE_PROPERTIES_RECORD_CODE_SECTION_= SIGNATURE + ); + if (ImageRecordCodeSection->CodeSegmentBase > NextImageRecordCodeSec= tion->CodeSegmentBase) { + SwapImageRecordCodeSection (ImageRecordCodeSection, NextImageRecor= dCodeSection); + } + + NextImageRecordCodeSectionLink =3D NextImageRecordCodeSectionLink->F= orwardLink; + } + + ImageRecordCodeSectionLink =3D ImageRecordCodeSectionLink->Forward= Link; + NextImageRecordCodeSectionLink =3D ImageRecordCodeSectionLink->Forward= Link; + } +} + +/** + Dump image record. + + @param[in] ImageRecordList A list of IMAGE_PROPERTIES_RECORD entries +**/ +VOID +EFIAPI +DumpImageRecord ( + IN LIST_ENTRY *ImageRecordList + ) +{ + IMAGE_PROPERTIES_RECORD *ImageRecord; + LIST_ENTRY *ImageRecordLink; + UINTN Index; + + for (ImageRecordLink =3D ImageRecordList->ForwardLink, Index =3D 0; + ImageRecordLink !=3D ImageRecordList; + ImageRecordLink =3D ImageRecordLink->ForwardLink, Index++) + { + ImageRecord =3D CR ( + ImageRecordLink, + IMAGE_PROPERTIES_RECORD, + Link, + IMAGE_PROPERTIES_RECORD_SIGNATURE + ); + DEBUG ((DEBUG_VERBOSE, "Image[%d]: 0x%016lx - 0x%016lx\n", Index, Imag= eRecord->ImageBase, ImageRecord->ImageSize)); + } +} + +/** + Sort image record based upon the ImageBase from low to high. + + @param[in] ImageRecordList A list of IMAGE_PROPERTIES_RECORD entries +**/ +VOID +EFIAPI +SortImageRecord ( + IN LIST_ENTRY *ImageRecordList + ) +{ + IMAGE_PROPERTIES_RECORD *ImageRecord; + IMAGE_PROPERTIES_RECORD *NextImageRecord; + LIST_ENTRY *ImageRecordLink; + LIST_ENTRY *NextImageRecordLink; + LIST_ENTRY *ImageRecordEndLink; + + ImageRecordLink =3D ImageRecordList->ForwardLink; + NextImageRecordLink =3D ImageRecordLink->ForwardLink; + ImageRecordEndLink =3D ImageRecordList; + while (ImageRecordLink !=3D ImageRecordEndLink) { + ImageRecord =3D CR ( + ImageRecordLink, + IMAGE_PROPERTIES_RECORD, + Link, + IMAGE_PROPERTIES_RECORD_SIGNATURE + ); + while (NextImageRecordLink !=3D ImageRecordEndLink) { + NextImageRecord =3D CR ( + NextImageRecordLink, + IMAGE_PROPERTIES_RECORD, + Link, + IMAGE_PROPERTIES_RECORD_SIGNATURE + ); + if (ImageRecord->ImageBase > NextImageRecord->ImageBase) { + SwapImageRecord (ImageRecord, NextImageRecord); + } + + NextImageRecordLink =3D NextImageRecordLink->ForwardLink; + } + + ImageRecordLink =3D ImageRecordLink->ForwardLink; + NextImageRecordLink =3D ImageRecordLink->ForwardLink; + } +} + +/** + Return the first image record, whose [ImageBase, ImageSize] covered by [= Buffer, Length]. + + @param[in] Buffer Start Address + @param[in] Length Address length + @param[in] ImageRecordList A list of IMAGE_PROPERTIES_RECORD entries to= check against + the memory range Buffer -> Buffer + Length + + @return first image record covered by [buffer, length] +**/ +STATIC +IMAGE_PROPERTIES_RECORD * +GetImageRecordByAddress ( + IN EFI_PHYSICAL_ADDRESS Buffer, + IN UINT64 Length, + IN LIST_ENTRY *ImageRecordList + ) +{ + IMAGE_PROPERTIES_RECORD *ImageRecord; + LIST_ENTRY *ImageRecordLink; + + for (ImageRecordLink =3D ImageRecordList->ForwardLink; + ImageRecordLink !=3D ImageRecordList; + ImageRecordLink =3D ImageRecordLink->ForwardLink) + { + ImageRecord =3D CR ( + ImageRecordLink, + IMAGE_PROPERTIES_RECORD, + Link, + IMAGE_PROPERTIES_RECORD_SIGNATURE + ); + + if ((Buffer <=3D ImageRecord->ImageBase) && + (Buffer + Length >=3D ImageRecord->ImageBase + ImageRecord->ImageS= ize)) + { + return ImageRecord; + } + } + + return NULL; +} + +/** + Set the memory map to new entries, according to one old entry, + based upon PE code section and data section in image record + + @param ImageRecord An image record whose [ImageBase, ImageSi= ze] covered + by old memory map entry. + @param NewRecord A pointer to several new memory map entri= es. + The caller gurantee the buffer size be 1 + + (SplitRecordCount * DescriptorSize) calcu= lated + below. + @param OldRecord A pointer to one old memory map entry. + @param DescriptorSize Size, in bytes, of an individual EFI_MEMO= RY_DESCRIPTOR. +**/ +STATIC +UINTN +SetNewRecord ( + IN IMAGE_PROPERTIES_RECORD *ImageRecord, + IN OUT EFI_MEMORY_DESCRIPTOR *NewRecord, + IN EFI_MEMORY_DESCRIPTOR *OldRecord, + IN UINTN DescriptorSize + ) +{ + EFI_MEMORY_DESCRIPTOR TempRecord; + IMAGE_PROPERTIES_RECORD_CODE_SECTION *ImageRecordCodeSection; + LIST_ENTRY *ImageRecordCodeSectionLink; + LIST_ENTRY *ImageRecordCodeSectionEndLink; + LIST_ENTRY *ImageRecordCodeSectionList; + UINTN NewRecordCount; + UINT64 PhysicalEnd; + UINT64 ImageEnd; + + CopyMem (&TempRecord, OldRecord, sizeof (EFI_MEMORY_DESCRIPTOR)); + PhysicalEnd =3D TempRecord.PhysicalStart + EfiPagesToSize (TempRecord= .NumberOfPages); + NewRecordCount =3D 0; + + ImageRecordCodeSectionList =3D &ImageRecord->CodeSegmentList; + + ImageRecordCodeSectionLink =3D ImageRecordCodeSectionList->ForwardLin= k; + ImageRecordCodeSectionEndLink =3D ImageRecordCodeSectionList; + while (ImageRecordCodeSectionLink !=3D ImageRecordCodeSectionEndLink) { + ImageRecordCodeSection =3D CR ( + ImageRecordCodeSectionLink, + IMAGE_PROPERTIES_RECORD_CODE_SECTION, + Link, + IMAGE_PROPERTIES_RECORD_CODE_SECTION_SIGNAT= URE + ); + ImageRecordCodeSectionLink =3D ImageRecordCodeSectionLink->ForwardLink; + + if (TempRecord.PhysicalStart <=3D ImageRecordCodeSection->CodeSegmentB= ase) { + // + // DATA + // + NewRecord->Type =3D TempRecord.Type; + NewRecord->PhysicalStart =3D TempRecord.PhysicalStart; + NewRecord->VirtualStart =3D 0; + NewRecord->NumberOfPages =3D EfiSizeToPages (ImageRecordCodeSection-= >CodeSegmentBase - NewRecord->PhysicalStart); + NewRecord->Attribute =3D TempRecord.Attribute | EFI_MEMORY_XP; + if (NewRecord->NumberOfPages !=3D 0) { + NewRecord =3D NEXT_MEMORY_DESCRIPTOR (NewRecord, DescriptorSize); + NewRecordCount++; + } + + // + // CODE + // + NewRecord->Type =3D TempRecord.Type; + NewRecord->PhysicalStart =3D ImageRecordCodeSection->CodeSegmentBase; + NewRecord->VirtualStart =3D 0; + NewRecord->NumberOfPages =3D EfiSizeToPages (ImageRecordCodeSection-= >CodeSegmentSize); + NewRecord->Attribute =3D (TempRecord.Attribute & (~EFI_MEMORY_XP= )) | EFI_MEMORY_RO; + if (NewRecord->NumberOfPages !=3D 0) { + NewRecord =3D NEXT_MEMORY_DESCRIPTOR (NewRecord, DescriptorSize); + NewRecordCount++; + } + + TempRecord.PhysicalStart =3D ImageRecordCodeSection->CodeSegmentBase= + EfiPagesToSize (EfiSizeToPages (ImageRecordCodeSection->CodeSegmentSize)= ); + TempRecord.NumberOfPages =3D EfiSizeToPages (PhysicalEnd - TempRecor= d.PhysicalStart); + if (TempRecord.NumberOfPages =3D=3D 0) { + break; + } + } + } + + ImageEnd =3D ImageRecord->ImageBase + ImageRecord->ImageSize; + + // + // Final DATA + // + if (TempRecord.PhysicalStart < ImageEnd) { + NewRecord->Type =3D TempRecord.Type; + NewRecord->PhysicalStart =3D TempRecord.PhysicalStart; + NewRecord->VirtualStart =3D 0; + NewRecord->NumberOfPages =3D EfiSizeToPages (ImageEnd - TempRecord.Phy= sicalStart); + NewRecord->Attribute =3D TempRecord.Attribute | EFI_MEMORY_XP; + NewRecordCount++; + } + + return NewRecordCount; +} + +/** + Return the max number of new splitted entries, according to one old entr= y, + based upon PE code section and data section. + + @param[in] OldRecord A pointer to one old memory map entry. + @param[in] ImageRecordList A list of IMAGE_PROPERTIES_RECORD entries = used when searching + for an image record contained by the memor= y range described in + the existing EFI memory map descriptor Old= Record + + @retval 0 no entry need to be splitted. + @return the max number of new splitted entries +**/ +STATIC +UINTN +GetMaxSplitRecordCount ( + IN EFI_MEMORY_DESCRIPTOR *OldRecord, + IN LIST_ENTRY *ImageRecordList + ) +{ + IMAGE_PROPERTIES_RECORD *ImageRecord; + UINTN SplitRecordCount; + UINT64 PhysicalStart; + UINT64 PhysicalEnd; + + SplitRecordCount =3D 0; + PhysicalStart =3D OldRecord->PhysicalStart; + PhysicalEnd =3D OldRecord->PhysicalStart + EfiPagesToSize (OldRecor= d->NumberOfPages); + + do { + ImageRecord =3D GetImageRecordByAddress (PhysicalStart, PhysicalEnd - = PhysicalStart, ImageRecordList); + if (ImageRecord =3D=3D NULL) { + break; + } + + SplitRecordCount +=3D (2 * ImageRecord->CodeSegmentCount + 1); + PhysicalStart =3D ImageRecord->ImageBase + ImageRecord->ImageSize; + } while ((ImageRecord !=3D NULL) && (PhysicalStart < PhysicalEnd)); + + if (SplitRecordCount !=3D 0) { + SplitRecordCount--; + } + + return SplitRecordCount; +} + +/** + Split the memory map to new entries, according to one old entry, + based upon PE code section and data section. + + @param[in] OldRecord A pointer to one old memory map = entry. + @param[in, out] NewRecord A pointer to several new memory = map entries. + The caller gurantee the buffer s= ize be 1 + + (SplitRecordCount * DescriptorSi= ze) calculated + below. + @param[in] MaxSplitRecordCount The max number of splitted entri= es + @param[in] DescriptorSize Size, in bytes, of an individual= EFI_MEMORY_DESCRIPTOR. + @param[in] ImageRecordList A list of IMAGE_PROPERTIES_RECOR= D entries used when searching + for an image record contained by= the memory range described in + the existing EFI memory map desc= riptor OldRecord + + @retval 0 no entry is splitted. + @return the real number of splitted record. +**/ +STATIC +UINTN +SplitRecord ( + IN EFI_MEMORY_DESCRIPTOR *OldRecord, + IN OUT EFI_MEMORY_DESCRIPTOR *NewRecord, + IN UINTN MaxSplitRecordCount, + IN UINTN DescriptorSize, + IN LIST_ENTRY *ImageRecordList + ) +{ + EFI_MEMORY_DESCRIPTOR TempRecord; + IMAGE_PROPERTIES_RECORD *ImageRecord; + IMAGE_PROPERTIES_RECORD *NewImageRecord; + UINT64 PhysicalStart; + UINT64 PhysicalEnd; + UINTN NewRecordCount; + UINTN TotalNewRecordCount; + BOOLEAN IsLastRecordData; + + if (MaxSplitRecordCount =3D=3D 0) { + CopyMem (NewRecord, OldRecord, DescriptorSize); + return 0; + } + + TotalNewRecordCount =3D 0; + + // + // Override previous record + // + CopyMem (&TempRecord, OldRecord, sizeof (EFI_MEMORY_DESCRIPTOR)); + PhysicalStart =3D TempRecord.PhysicalStart; + PhysicalEnd =3D TempRecord.PhysicalStart + EfiPagesToSize (TempRecord.= NumberOfPages); + + ImageRecord =3D NULL; + do { + NewImageRecord =3D GetImageRecordByAddress (PhysicalStart, PhysicalEnd= - PhysicalStart, ImageRecordList); + if (NewImageRecord =3D=3D NULL) { + // + // No more image covered by this range, stop + // + if ((PhysicalEnd > PhysicalStart) && (ImageRecord !=3D NULL)) { + // + // If this is still address in this record, need record. + // + NewRecord =3D PREVIOUS_MEMORY_DESCRIPTOR (NewRecord, Descri= ptorSize); + IsLastRecordData =3D FALSE; + if ((NewRecord->Attribute & EFI_MEMORY_XP) !=3D 0) { + IsLastRecordData =3D TRUE; + } + + if (IsLastRecordData) { + // + // Last record is DATA, just merge it. + // + NewRecord->NumberOfPages =3D EfiSizeToPages (PhysicalEnd - NewRe= cord->PhysicalStart); + } else { + // + // Last record is CODE, create a new DATA entry. + // + NewRecord =3D NEXT_MEMORY_DESCRIPTOR (NewRecord, = DescriptorSize); + NewRecord->Type =3D TempRecord.Type; + NewRecord->PhysicalStart =3D TempRecord.PhysicalStart; + NewRecord->VirtualStart =3D 0; + NewRecord->NumberOfPages =3D TempRecord.NumberOfPages; + NewRecord->Attribute =3D TempRecord.Attribute | EFI_MEMORY_X= P; + TotalNewRecordCount++; + } + } + + break; + } + + ImageRecord =3D NewImageRecord; + + // + // Set new record + // + NewRecordCount =3D SetNewRecord (ImageRecord, NewRecord, &TempRe= cord, DescriptorSize); + TotalNewRecordCount +=3D NewRecordCount; + NewRecord =3D (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)NewRecord = + NewRecordCount * DescriptorSize); + + // + // Update PhysicalStart, in order to exclude the image buffer already = splitted. + // + PhysicalStart =3D ImageRecord->ImageBase + ImageRecord->Ima= geSize; + TempRecord.PhysicalStart =3D PhysicalStart; + TempRecord.NumberOfPages =3D EfiSizeToPages (PhysicalEnd - PhysicalSta= rt); + } while ((ImageRecord !=3D NULL) && (PhysicalStart < PhysicalEnd)); + + // + // The logic in function SplitTable() ensures that TotalNewRecordCount w= ill not be zero if the + // code reaches here. + // + ASSERT (TotalNewRecordCount !=3D 0); + return TotalNewRecordCount - 1; +} + +/** + Split the original memory map, and add more entries to describe PE code = section and data section. + This function will set EfiRuntimeServicesData to be EFI_MEMORY_XP. + This function will merge entries with same attributes finally. + + NOTE: It assumes PE code/data section are page aligned. + NOTE: It assumes enough entry is prepared for new memory map. + + Split table: + +---------------+ + | Record X | + +---------------+ + | Record RtCode | + +---------------+ + | Record Y | + +---------------+ + =3D=3D> + +---------------+ + | Record X | + +---------------+ ---- + | Record RtData | | + +---------------+ | + | Record RtCode | |-> PE/COFF1 + +---------------+ | + | Record RtData | | + +---------------+ ---- + | Record RtData | | + +---------------+ | + | Record RtCode | |-> PE/COFF2 + +---------------+ | + | Record RtData | | + +---------------+ ---- + | Record Y | + +---------------+ + + @param[in, out] MemoryMapSize IN: The size, in bytes= , of the old memory map before the split. + OUT: The size, in bytes= , of the used descriptors of the split + memory map + @param[in, out] MemoryMap IN: A pointer to the b= uffer containing the current memory map. + This buffer must h= ave enough space to accomodate the "worst case" + scenario where eve= ry image in ImageRecordList needs a new descriptor + to describe its co= de and data sections. + OUT: A pointer to the u= pdated memory map with separated image section + descriptors. + @param[in] DescriptorSize The size, in bytes, of a= n individual EFI_MEMORY_DESCRIPTOR. + @param[in] ImageRecordList A list of IMAGE_PROPERTI= ES_RECORD entries used when searching + for an image record cont= ained by the memory range described in + EFI memory map descripto= rs. + @param[in] NumberOfAdditionalDescriptors The number of unused des= criptors at the end of the input MemoryMap. +**/ +VOID +EFIAPI +SplitTable ( + IN OUT UINTN *MemoryMapSize, + IN OUT EFI_MEMORY_DESCRIPTOR *MemoryMap, + IN UINTN DescriptorSize, + IN LIST_ENTRY *ImageRecordList, + IN UINTN NumberOfAdditionalDescriptors + ) +{ + INTN IndexOld; + INTN IndexNew; + UINTN MaxSplitRecordCount; + UINTN RealSplitRecordCount; + UINTN TotalSplitRecordCount; + + TotalSplitRecordCount =3D 0; + // + // Let old record point to end of valid MemoryMap buffer. + // + IndexOld =3D ((*MemoryMapSize) / DescriptorSize) - 1; + // + // Let new record point to end of full MemoryMap buffer. + // + IndexNew =3D ((*MemoryMapSize) / DescriptorSize) - 1 + NumberOfAdditiona= lDescriptors; + for ( ; IndexOld >=3D 0; IndexOld--) { + MaxSplitRecordCount =3D GetMaxSplitRecordCount ((EFI_MEMORY_DESCRIPTOR= *)((UINT8 *)MemoryMap + IndexOld * DescriptorSize), ImageRecordList); + // + // Split this MemoryMap record + // + IndexNew -=3D MaxSplitRecordCount; + RealSplitRecordCount =3D SplitRecord ( + (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)MemoryMap = + IndexOld * DescriptorSize), + (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)MemoryMap = + IndexNew * DescriptorSize), + MaxSplitRecordCount, + DescriptorSize, + ImageRecordList + ); + // + // Adjust IndexNew according to real split. + // + CopyMem ( + ((UINT8 *)MemoryMap + (IndexNew + MaxSplitRecordCount - RealSplitRec= ordCount) * DescriptorSize), + ((UINT8 *)MemoryMap + IndexNew * DescriptorSize), + RealSplitRecordCount * DescriptorSize + ); + IndexNew =3D IndexNew + MaxSplitRecordCount - RealSplitR= ecordCount; + TotalSplitRecordCount +=3D RealSplitRecordCount; + IndexNew--; + } + + // + // Move all records to the beginning. + // + CopyMem ( + MemoryMap, + (UINT8 *)MemoryMap + (NumberOfAdditionalDescriptors - TotalSplitRecord= Count) * DescriptorSize, + (*MemoryMapSize) + TotalSplitRecordCount * DescriptorSize + ); + + *MemoryMapSize =3D (*MemoryMapSize) + DescriptorSize * TotalSplitRecordC= ount; + + // + // Sort from low to high (Just in case) + // + SortMemoryMap (MemoryMap, *MemoryMapSize, DescriptorSize); + + return; +} + +/** + Find image record according to image base and size. + + @param[in] ImageBase Base of PE image + @param[in] ImageSize Size of PE image + @param[in] ImageRecordList A list of IMAGE_PROPERTIES_RECORD entries + + @return image record +**/ +IMAGE_PROPERTIES_RECORD * +EFIAPI +FindImageRecord ( + IN EFI_PHYSICAL_ADDRESS ImageBase, + IN UINT64 ImageSize, + IN LIST_ENTRY *ImageRecordList + ) +{ + IMAGE_PROPERTIES_RECORD *ImageRecord; + LIST_ENTRY *ImageRecordLink; + + for (ImageRecordLink =3D ImageRecordList->ForwardLink; + ImageRecordLink !=3D ImageRecordList; + ImageRecordLink =3D ImageRecordLink->ForwardLink) + { + ImageRecord =3D CR ( + ImageRecordLink, + IMAGE_PROPERTIES_RECORD, + Link, + IMAGE_PROPERTIES_RECORD_SIGNATURE + ); + + if ((ImageBase =3D=3D ImageRecord->ImageBase) && + (ImageSize =3D=3D ImageRecord->ImageSize)) + { + return ImageRecord; + } + } + + return NULL; +} diff --git a/MdeModulePkg/Include/Library/ImagePropertiesRecordLib.h b/MdeM= odulePkg/Include/Library/ImagePropertiesRecordLib.h new file mode 100644 index 000000000000..64bbf572d596 --- /dev/null +++ b/MdeModulePkg/Include/Library/ImagePropertiesRecordLib.h @@ -0,0 +1,151 @@ +/** @file + + Provides definitions and functionality for manipulating Image Properties= Records. + + Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef IMAGE_PROPERTIES_RECORD_SUPPORT_LIB_H_ +#define IMAGE_PROPERTIES_RECORD_SUPPORT_LIB_H_ + +#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; + +/** + Split the original memory map, and add more entries to describe PE code = section and data section. + This function will set EfiRuntimeServicesData to be EFI_MEMORY_XP. + This function will merge entries with same attributes finally. + + NOTE: It assumes PE code/data section are page aligned. + NOTE: It assumes enough entry is prepared for new memory map. + + Split table: + +---------------+ + | Record X | + +---------------+ + | Record RtCode | + +---------------+ + | Record Y | + +---------------+ + =3D=3D> + +---------------+ + | Record X | + +---------------+ ---- + | Record RtData | | + +---------------+ | + | Record RtCode | |-> PE/COFF1 + +---------------+ | + | Record RtData | | + +---------------+ ---- + | Record RtData | | + +---------------+ | + | Record RtCode | |-> PE/COFF2 + +---------------+ | + | Record RtData | | + +---------------+ ---- + | Record Y | + +---------------+ + + @param MemoryMapSize A pointer to the size, in bytes, of the + MemoryMap buffer. On input, this is the s= ize of + old MemoryMap before split. The actual bu= ffer + size of MemoryMap is MemoryMapSize + + (AdditionalRecordCount * DescriptorSize) = calculated + below. On output, it is the size of new M= emoryMap + after split. + @param MemoryMap A pointer to the buffer in which firmware= places + the current memory map. + @param DescriptorSize Size, in bytes, of an individual EFI_MEMO= RY_DESCRIPTOR. +**/ +VOID +EFIAPI +SplitTable ( + IN OUT UINTN *MemoryMapSize, + IN OUT EFI_MEMORY_DESCRIPTOR *MemoryMap, + IN UINTN DescriptorSize, + IN LIST_ENTRY *ImageRecordList, + IN UINTN NumberOfAdditionalDescriptors + ); + +/** + Sort code section in image record, based upon CodeSegmentBase from low t= o high. + + @param ImageRecord image record to be sorted +**/ +VOID +EFIAPI +SortImageRecordCodeSection ( + IN IMAGE_PROPERTIES_RECORD *ImageRecord + ); + +/** + Check if code section in image record is valid. + + @param ImageRecord image record to be checked + + @retval TRUE image record is valid + @retval FALSE image record is invalid +**/ +BOOLEAN +EFIAPI +IsImageRecordCodeSectionValid ( + IN IMAGE_PROPERTIES_RECORD *ImageRecord + ); + +/** + Sort image record based upon the ImageBase from low to high. +**/ +VOID +EFIAPI +SortImageRecord ( + IN LIST_ENTRY *ImageRecordList + ); + +/** + Find image record according to image base and size. + + @param[in] ImageBase Base of PE image + @param[in] ImageSize Size of PE image + @param[in] ImageRecordList A list of IMAGE_PROPERTIES_RECORD entries + + @return image record +**/ +IMAGE_PROPERTIES_RECORD * +EFIAPI +FindImageRecord ( + IN EFI_PHYSICAL_ADDRESS ImageBase, + IN UINT64 ImageSize, + IN LIST_ENTRY *ImageRecordList + ); + +/** + Dump image record. + + @param[in] ImageRecordList A list of IMAGE_PROPERTIES_RECORD entries +**/ +VOID +EFIAPI +DumpImageRecord ( + IN LIST_ENTRY *ImageRecordList + ); + +#endif diff --git a/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesR= ecordLib.inf b/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertie= sRecordLib.inf new file mode 100644 index 000000000000..9062d20eb48b --- /dev/null +++ b/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLi= b.inf @@ -0,0 +1,28 @@ +## @file +# Provides definitions and functionality for manipulating +# Image Properties Records. +# +# Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D ImagePropertiesRecordLib + FILE_GUID =3D 5CCA36C1-C430-4A90-8BF7-23D2719D5928 + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D ImagePropertiesRecordLib + +[Sources.common] + ImagePropertiesRecordLib.c + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec index 0ff058b0a9da..80df553b2a5f 100644 --- a/MdeModulePkg/MdeModulePkg.dec +++ b/MdeModulePkg/MdeModulePkg.dec @@ -164,6 +164,11 @@ [LibraryClasses] # VariableFlashInfoLib|Include/Library/VariableFlashInfoLib.h =20 + ## @libraryclass Memory Attribute Table support logic for tracking an= d reporting + # runtime images + # + ImagePropertiesRecordLib|Include/Library/ImagePropertiesRecordLib.h + [Guids] ## MdeModule package token space guid # Include/Guid/MdeModulePkgTokenSpace.h diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc index db3b5af53795..6444111b9214 100644 --- a/MdeModulePkg/MdeModulePkg.dsc +++ b/MdeModulePkg/MdeModulePkg.dsc @@ -96,6 +96,7 @@ [LibraryClasses] VarCheckLib|MdeModulePkg/Library/VarCheckLib/VarCheckLib.inf FileExplorerLib|MdeModulePkg/Library/FileExplorerLib/FileExplorerLib.inf NonDiscoverableDeviceRegistrationLib|MdeModulePkg/Library/NonDiscoverabl= eDeviceRegistrationLib/NonDiscoverableDeviceRegistrationLib.inf + ImagePropertiesRecordLib|MdeModulePkg/Library/ImagePropertiesRecordLib/I= magePropertiesRecordLib.inf =20 FmpAuthenticationLib|MdeModulePkg/Library/FmpAuthenticationLibNull/FmpAu= thenticationLibNull.inf CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf @@ -237,6 +238,7 @@ [Components] MdeModulePkg/Library/BaseHobLibNull/BaseHobLibNull.inf MdeModulePkg/Library/BaseMemoryAllocationLibNull/BaseMemoryAllocationLib= Null.inf MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.inf + MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.i= nf =20 MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf MdeModulePkg/Bus/Pci/PciSioSerialDxe/PciSioSerialDxe.inf --=20 2.41.0.windows.2 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#107067): https://edk2.groups.io/g/devel/message/107067 Mute This Topic: https://groups.io/mt/100246935/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Thu May 9 19:23:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+107068+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+107068+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1689811561; cv=none; d=zohomail.com; s=zohoarc; b=BOoCXqxY5miKIF+s8lQLQbg8lLATYKei3bEqHtBqIcbcu/BZlMNTXoFiRc6qyfK7h9fABKJNgmHYpbNJTHJe+pgUtOzx1jdYkOMmJQvhF4QkTXAz4ijCywZ5CFaRhM5Lm01t0kuG3/XG4z9eRPyb2hVhyd0smWRh3ATUZb65J0A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689811561; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=DbLJm4jO66uLgFvMu4J7m+TWQnmSUQGlNX0u0WvfhO0=; b=YaxVYO4fptjHTEmRIR0eYOk86pYUySE0Okd1HI72OXdYMutHaLTOc1RFzYrh67hdEM7n7X/9MMy3BWFeEDAi2DxnFqIrvkTkZGFF8F8JFy3o+D7J859MZRUZVdGNMHMH+rvrfGd06VZL+uUT6+p3R6asiF8YMAqQlAQ4KtdPbJo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+107068+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1689811561056179.05795078572487; Wed, 19 Jul 2023 17:06:01 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=fj2xnsYKkcYt+7KiFZkCOPiDhJh7YzC618B/X2EsTAc=; c=relaxed/simple; d=groups.io; h=X-Received:X-Received:X-Received:X-Gm-Message-State:X-Google-Smtp-Source:X-Received:X-Received:From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:MIME-Version:Precedence:List-Unsubscribe:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:Content-Transfer-Encoding; s=20140610; t=1689811560; v=1; b=OcGBjxx2akU7e7WnmDl9k3/MZtmt3hTljAjR0AGFqHwqnFth7j6vscVIPdeVyHsHcubw3Ooj hj2+BHxUalm2sn/W+ROpHXIuOoyeh5zVlgeYLoqFY3KTFAbFYZdwB9Kbu73jzovb8TErXBlqnP7 h+ZL00J9RXm9TcXTzwTu2Fic= X-Received: by 127.0.0.2 with SMTP id CCXOYY1788612xJqa9eBeDub; Wed, 19 Jul 2023 17:06:00 -0700 X-Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by mx.groups.io with SMTP id smtpd.web10.2233.1689811559910461450 for ; Wed, 19 Jul 2023 17:06:00 -0700 X-Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-1b9c5e07c1bso1419595ad.2 for ; Wed, 19 Jul 2023 17:05:59 -0700 (PDT) X-Gm-Message-State: O2BDBMqajen9ikHd9vqLMf6Gx1787277AA= X-Google-Smtp-Source: APBJJlFPbPfSM/A//NGMhVwZH0uS0tv/hK3pwMSoEqenZ95i2x/IhAMLLBPIx8r8TVYLXq7PDc5xVg== X-Received: by 2002:a17:902:e88d:b0:1b8:7e53:70f with SMTP id w13-20020a170902e88d00b001b87e53070fmr754636plg.27.1689811559058; Wed, 19 Jul 2023 17:05:59 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.230.135]) by smtp.gmail.com with ESMTPSA id jf10-20020a170903268a00b001b83e624eecsm4617286plb.81.2023.07.19.17.05.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jul 2023 17:05:58 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Jian J Wang , Liming Gao , Dandan Bi Subject: [edk2-devel] [PATCH v2 2/9] MdeModulePkg: Add ImagePropertiesRecordLib Host-Based Unit Test Date: Wed, 19 Jul 2023 17:05:37 -0700 Message-ID: <20230720000544.146-3-t@taylorbeebe.com> In-Reply-To: <20230720000544.146-1-t@taylorbeebe.com> References: <20230720000544.146-1-t@taylorbeebe.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,t@taylorbeebe.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1689811561655100009 Content-Type: text/plain; charset="utf-8" Create a host-based unit test for the ImagePropertiesRecordLib SplitTable() logic. This test has 4 cases which tests different potential image and memory map layouts. 3/4 of these tests fail with the logic in its current state to provide proof of the bugs in the current MAT logic. Signed-off-by: Taylor Beebe Cc: Jian J Wang Cc: Liming Gao Cc: Dandan Bi --- MdeModulePkg/Library/ImagePropertiesRecordLib/UnitTest/ImagePropertiesReco= rdLibUnitTestHost.c | 938 ++++++++++++++++++++ MdeModulePkg/Library/ImagePropertiesRecordLib/UnitTest/ImagePropertiesReco= rdLibUnitTestHost.inf | 35 + MdeModulePkg/Test/MdeModulePkgHostTest.dsc = | 5 + 3 files changed, 978 insertions(+) diff --git a/MdeModulePkg/Library/ImagePropertiesRecordLib/UnitTest/ImagePr= opertiesRecordLibUnitTestHost.c b/MdeModulePkg/Library/ImagePropertiesRecor= dLib/UnitTest/ImagePropertiesRecordLibUnitTestHost.c new file mode 100644 index 000000000000..8b0a55685ce3 --- /dev/null +++ b/MdeModulePkg/Library/ImagePropertiesRecordLib/UnitTest/ImagePropertie= sRecordLibUnitTestHost.c @@ -0,0 +1,938 @@ +/** @file + Unit tests the SplitTable() ImagePropertiesRecordLib Logic + + Copyright (C) Microsoft Corporation. + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#define UNIT_TEST_APP_NAME "Image Properties Record Lib Unit Test" +#define UNIT_TEST_APP_VERSION "1.0" + +#define NEXT_MEMORY_DESCRIPTOR(MemoryDescriptor, Size) \ + ((EFI_MEMORY_DESCRIPTOR *)((UINT8 *)(MemoryDescriptor) + (Size))) + +// The starting memory map will contain 6 entries +#define NUMBER_OF_MEMORY_MAP_DESCRIPTORS 6 + +// Each memory map descriptor will be the sizeof(EFI_MEMORY_DESCRIPTOR) in= stead of a nonstandard size +// to catch pointer math issues +#define DESCRIPTOR_SIZE sizeof(EFI_MEMORY_DESCRIPTOR) + +// Each memory map descriptor will describe 12 pages +#define BASE_DESCRIPTOR_NUMBER_OF_PAGES 0x0C + +// The size, in bytes, of each memory map descriptor range +#define BASE_DESCRIPTOR_ENTRY_SIZE (EFI_PAGES_TO_SIZE(BASE_DESCRIPTOR_NUM= BER_OF_PAGES)) + +// MACRO to get the starting address of a descriptor's described range bas= ed on the index of that descriptor +#define BASE_DESCRIPTOR_START_ADDRESS(DescriptorNumber) (DescriptorNumber= * BASE_DESCRIPTOR_ENTRY_SIZE) + +// Virtual start must be zero +#define BASE_DESCRIPTOR_VIRTUAL_START 0x0 + +// Size of the default memory map +#define BASE_MEMORY_MAP_SIZE (NUMBER_OF_MEMORY_MAP_DESCRIPTORS * DESCRIPT= OR_SIZE) + +// Number of images in each test case +#define NUMBER_OF_IMAGES_TO_SPLIT 3 + +// Maximum number of descriptors required for each image (None->Data->Code= ->Data->Code->Data->None) +#define MAX_DESCRIPTORS_PER_IMAGE 7 + +// Number of unused additional descriptors in the starting memory map buff= er which is used by the +// SplitTable() logic +#define NUMBER_OF_ADDITIONAL_DESCRIPTORS (NUMBER_OF_IMAGES_TO_SPLIT * MAX= _DESCRIPTORS_PER_IMAGE) + +// Size of the memory map with enough space for the starting descriptors a= nd the split descriptors +#define SPLIT_MEMORY_MAP_SIZE (BASE_MEMORY_MAP_SIZE + (NUMBER_OF_ADDITION= AL_DESCRIPTORS * DESCRIPTOR_SIZE)) + +typedef enum { + SectionTypeCode, + SectionTypeData, + SectionTypeNotFound +} SECTION_TYPE; + +typedef struct { + EFI_MEMORY_DESCRIPTOR *MemoryMap; + LIST_ENTRY ImageList; +} IMAGE_PROPERTIES_RECORD_HOST_TEST_CONTEXT; + +EFI_MEMORY_DESCRIPTOR BaseMemoryMap[] =3D { + { + EfiConventionalMemory, // Type + BASE_DESCRIPTOR_START_ADDRESS (0), // PhysicalStart + BASE_DESCRIPTOR_VIRTUAL_START, // VirtualStart + BASE_DESCRIPTOR_NUMBER_OF_PAGES, // Number of Pages + 0 // Attribute + }, + { + EfiConventionalMemory, // Type + BASE_DESCRIPTOR_START_ADDRESS (1), // PhysicalStart + BASE_DESCRIPTOR_VIRTUAL_START, // VirtualStart + BASE_DESCRIPTOR_NUMBER_OF_PAGES, // Number of Pages + 0 // Attribute + }, + { + EfiConventionalMemory, // Type + BASE_DESCRIPTOR_START_ADDRESS (2), // PhysicalStart + BASE_DESCRIPTOR_VIRTUAL_START, // VirtualStart + BASE_DESCRIPTOR_NUMBER_OF_PAGES, // Number of Pages + 0 // Attribute + }, + { + EfiConventionalMemory, // Type + BASE_DESCRIPTOR_START_ADDRESS (3), // PhysicalStart + BASE_DESCRIPTOR_VIRTUAL_START, // VirtualStart + BASE_DESCRIPTOR_NUMBER_OF_PAGES, // Number of Pages + 0 // Attribute + }, + { + EfiConventionalMemory, // Type + BASE_DESCRIPTOR_START_ADDRESS (4), // PhysicalStart + BASE_DESCRIPTOR_VIRTUAL_START, // VirtualStart + BASE_DESCRIPTOR_NUMBER_OF_PAGES, // Number of Pages + 0 // Attribute + }, + { + EfiConventionalMemory, // Type + BASE_DESCRIPTOR_START_ADDRESS (5), // PhysicalStart + BASE_DESCRIPTOR_VIRTUAL_START, // VirtualStart + BASE_DESCRIPTOR_NUMBER_OF_PAGES, // Number of Pages + 0 // Attribute + } +}; + +/** + Returns a bitmap where one bit is set for each section in the image list= . For example, if + there are 3 images and each image 3 sections the returned bitmap will be= 111111111. + + @param[in] ImageRecordList A list of IMAGE_PROPERTIES_RECORD entries + + @retval A bitmap such that the most significant bit is the number of sec= tions + in all images and every bit between 0 -> MSB is set + +**/ +STATIC +UINT64 +GetImageSectionBitmap ( + IN LIST_ENTRY *ImageRecordList + ) +{ + IMAGE_PROPERTIES_RECORD *ImageRecord; + IMAGE_PROPERTIES_RECORD_CODE_SECTION *ImageRecordCodeSection; + LIST_ENTRY *ImageRecordLink; + LIST_ENTRY *ImageRecordCodeSectionLink; + EFI_PHYSICAL_ADDRESS SectionBase; + UINT64 ReturnBitmap; + UINT64 Shift; + + if (ImageRecordList =3D=3D NULL) { + return 0; + } + + ReturnBitmap =3D 0; + Shift =3D 0; + + // Walk through each image record + for (ImageRecordLink =3D ImageRecordList->ForwardLink; + ImageRecordLink !=3D ImageRecordList; + ImageRecordLink =3D ImageRecordLink->ForwardLink) + { + ImageRecord =3D CR ( + ImageRecordLink, + IMAGE_PROPERTIES_RECORD, + Link, + IMAGE_PROPERTIES_RECORD_SIGNATURE + ); + + SectionBase =3D ImageRecord->ImageBase; + + // Walk through each code entry + for (ImageRecordCodeSectionLink =3D ImageRecord->CodeSegmentList.Forwa= rdLink; + ImageRecordCodeSectionLink !=3D &ImageRecord->CodeSegmentList; + ImageRecordCodeSectionLink =3D ImageRecordCodeSectionLink->Forwar= dLink) + { + ImageRecordCodeSection =3D CR ( + ImageRecordCodeSectionLink, + IMAGE_PROPERTIES_RECORD_CODE_SECTION, + Link, + IMAGE_PROPERTIES_RECORD_CODE_SECTION_SIGN= ATURE + ); + + // Check for data region before the code section base + if (SectionBase < ImageRecordCodeSection->CodeSegmentBase) { + ReturnBitmap |=3D LShiftU64 (1, Shift++); + } + + // Code section + ReturnBitmap |=3D LShiftU64 (1, Shift++); + SectionBase =3D ImageRecordCodeSection->CodeSegmentBase + ImageRec= ordCodeSection->CodeSegmentSize; + } + + // Check for data region after the previous code section + if (SectionBase < (ImageRecord->ImageBase + ImageRecord->ImageSize)) { + ReturnBitmap |=3D LShiftU64 (1, Shift++); + } + } + + return ReturnBitmap; +} + +/** + Searches the input image list for a section which exactly matches the me= mory range Buffer -> Buffer + Length. + + @param[in] Buffer Start Address to check + @param[in] Length Length to check + @param[out] Type The type of the section which corresponds w= ith the memory + range Buffer -> Buffer + Length (Code or Dat= a) or SectionTypeNotFound + if no image section matches the memory range + @param[in] ImageRecordList A list of IMAGE_PROPERTIES_RECORD entries to= check against + the memory range Buffer -> Buffer + Length + + @retval A bitmap with a single bit set (1 << Shift) where Shift correspo= nds with the number of sections inspected + in the image list before arriving at the section matching the me= mory range Buffer -> Buffer + Length +**/ +STATIC +UINT64 +MatchDescriptorToImageSection ( + IN EFI_PHYSICAL_ADDRESS Buffer, + IN UINT64 Length, + OUT SECTION_TYPE *Type, + IN LIST_ENTRY *ImageRecordList + ) +{ + IMAGE_PROPERTIES_RECORD *ImageRecord; + IMAGE_PROPERTIES_RECORD_CODE_SECTION *ImageRecordCodeSection; + LIST_ENTRY *ImageRecordLink; + LIST_ENTRY *ImageRecordCodeSectionLink; + EFI_PHYSICAL_ADDRESS SectionBase; + UINT8 Shift; + + Shift =3D 0; + + if (ImageRecordList =3D=3D NULL) { + return 1; + } + + // Walk through each image record + for (ImageRecordLink =3D ImageRecordList->ForwardLink; + ImageRecordLink !=3D ImageRecordList; + ImageRecordLink =3D ImageRecordLink->ForwardLink) + { + ImageRecord =3D CR ( + ImageRecordLink, + IMAGE_PROPERTIES_RECORD, + Link, + IMAGE_PROPERTIES_RECORD_SIGNATURE + ); + + SectionBase =3D ImageRecord->ImageBase; + + // Walk through each code entry + for (ImageRecordCodeSectionLink =3D ImageRecord->CodeSegmentList.Forwa= rdLink; + ImageRecordCodeSectionLink !=3D &ImageRecord->CodeSegmentList; + ImageRecordCodeSectionLink =3D ImageRecordCodeSectionLink->Forwar= dLink) + { + ImageRecordCodeSection =3D CR ( + ImageRecordCodeSectionLink, + IMAGE_PROPERTIES_RECORD_CODE_SECTION, + Link, + IMAGE_PROPERTIES_RECORD_CODE_SECTION_SIGN= ATURE + ); + + if (SectionBase < ImageRecordCodeSection->CodeSegmentBase) { + // Check the data region before the code section base + if ((Buffer =3D=3D SectionBase) && + (Length =3D=3D ImageRecordCodeSection->CodeSegmentBase - Secti= onBase)) + { + *Type =3D SectionTypeData; + return LShiftU64 (1, Shift); + } + + Shift++; + } + + // Check the code region + if ((Buffer =3D=3D ImageRecordCodeSection->CodeSegmentBase) && + (Length =3D=3D ImageRecordCodeSection->CodeSegmentSize)) + { + *Type =3D SectionTypeCode; + return LShiftU64 (1, Shift); + } + + Shift++; + SectionBase =3D ImageRecordCodeSection->CodeSegmentBase + ImageRecor= dCodeSection->CodeSegmentSize; + } + + // Check the data region after the code section + if (SectionBase < (ImageRecord->ImageBase + ImageRecord->ImageSize)) { + if ((Buffer =3D=3D SectionBase) && + (Length =3D=3D (ImageRecord->ImageBase + ImageRecord->ImageSize)= - SectionBase)) + { + *Type =3D SectionTypeData; + return LShiftU64 (1, Shift); + } + + Shift++; + } + } + + // No image sections match + *Type =3D SectionTypeNotFound; + return 0; +} + +/** + Walks through the input memory map and checks that every memory descript= or with an attribute matches + an image in ImageRecordList. + + @param[in] MemoryMapSize The size, in bytes, of t= he memory map + @param[in] MemoryMap A pointer to the buffer = containing the memory map + @param[in] ImageRecordList A list of IMAGE_PROPERTI= ES_RECORD entries + + @retval TRUE if all memory descriptors with attributes match an image se= ction and have the correct attributes + +**/ +STATIC +BOOLEAN +IsMemoryMapValid ( + IN UINTN MemoryMapSize, + IN EFI_MEMORY_DESCRIPTOR *MemoryMap, + IN LIST_ENTRY *ImageRecordList + ) +{ + UINT64 ImageSectionsBitmap; + UINT64 ReturnSectionBitmask; + UINT64 NumberOfDescriptors; + UINT8 Index; + SECTION_TYPE Type; + + Index =3D 0; + NumberOfDescriptors =3D MemoryMapSize / DESCRIPTOR_SIZE; + + UT_ASSERT_EQUAL (MemoryMapSize % DESCRIPTOR_SIZE, 0); + UT_ASSERT_NOT_NULL (MemoryMap); + UT_ASSERT_NOT_NULL (ImageRecordList); + + // The returned bitmap will have one bit is set for each section in the = image list. + // If there are 3 images and 3 sections each image, the resulting bitmap= will + // be 0000000000000000000000000000000000000000000000000000000111111111. = Flipping that bitmap + // results in 1111111111111111111111111111111111111111111111111111111000= 000000. The return value + // of each iteration through MatchDescriptorToImageSection() is one set = bit corrosponding to the number + // of sections before finding the section which matched the descriptor m= emory range which we + // OR with ImageSectionsBitmap. If, at the end of the loop, every bit in= ImageSectionsBitmap is set, + // we must have matched every image in ImageRecordList with a descriptor= in the memory map which has + // nonzero attributes. + ImageSectionsBitmap =3D ~GetImageSectionBitmap (ImageRecordList); + + // For each descriptor in the memory map + for ( ; Index < NumberOfDescriptors; Index++) { + if (MemoryMap[Index].Attribute !=3D 0) { + ReturnSectionBitmask =3D MatchDescriptorToImageSection ( + MemoryMap[Index].PhysicalStart, + EFI_PAGES_TO_SIZE (MemoryMap[Index].NumberO= fPages), + &Type, + ImageRecordList + ); + + // Make sure the attributes of the descriptor match the returned sec= tion type. + // DATA sections should have execution protection and CODE sections = should have + // write protection. + if ((Type =3D=3D SectionTypeNotFound) || + ((Type =3D=3D SectionTypeData) && (MemoryMap[Index].Attribute = =3D=3D EFI_MEMORY_RP)) || + ((Type =3D=3D SectionTypeCode) && (MemoryMap[Index].Attribute = =3D=3D EFI_MEMORY_XP))) + { + return FALSE; + } + + // If the bit associated with image found has already been set, then= there must be a duplicate + // in the memory map meaning it is invalid. + UT_ASSERT_EQUAL (ImageSectionsBitmap & ReturnSectionBitmask, 0); + + ImageSectionsBitmap |=3D ReturnSectionBitmask; + } + } + + // If every bit in ImageSectionsBitmap is set, the return value will be = TRUE + return !(~ImageSectionsBitmap); +} + +/** + Separate the image sections in the memory map and run a check to ensure = the output is valid. + + @param[in] Context Context containing the memory map and image record= pointers + + @retval TRUE if the memory map is split correctly +**/ +STATIC +BOOLEAN +SeparateAndCheck ( + IN IMAGE_PROPERTIES_RECORD_HOST_TEST_CONTEXT *Context + ) +{ + UINTN MemoryMapSize; + + MemoryMapSize =3D BASE_MEMORY_MAP_SIZE; + + // Separate the memory map so each image section has its own descriptor + SplitTable ( + &MemoryMapSize, + Context->MemoryMap, + DESCRIPTOR_SIZE, + &Context->ImageList, + NUMBER_OF_ADDITIONAL_DESCRIPTORS + ); + + // Ensure the updated memory map is valid + return IsMemoryMapValid (MemoryMapSize, Context->MemoryMap, &Context->Im= ageList); +} + +/** + Test the case where the image range contains multiple code sections and = does not perfectly align with + the existing memory descriptor. + + @param[in] Context Context containing the memory map and image record= pointers + + @retval UNIT_TEST_PASSED The Unit test has completed and th= e test + case was successful. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +MaxOutAdditionalDescriptors ( + IN UNIT_TEST_CONTEXT Context + ) +{ + IMAGE_PROPERTIES_RECORD *Image1; + IMAGE_PROPERTIES_RECORD *Image2; + IMAGE_PROPERTIES_RECORD *Image3; + IMAGE_PROPERTIES_RECORD_CODE_SECTION *CodeSectionInImage1; + IMAGE_PROPERTIES_RECORD_CODE_SECTION *CodeSectionInImage2; + IMAGE_PROPERTIES_RECORD_CODE_SECTION *CodeSectionInImage3; + IMAGE_PROPERTIES_RECORD_CODE_SECTION *AddCodeSectionInImage1; + IMAGE_PROPERTIES_RECORD_CODE_SECTION *AddCodeSectionInImage2; + IMAGE_PROPERTIES_RECORD_CODE_SECTION *AddCodeSectionInImage3; + IMAGE_PROPERTIES_RECORD_HOST_TEST_CONTEXT *TestContext; + + TestContext =3D (IMAGE_PROPERTIES_RECORD_HOST_TEST_CONTEXT *)Context; + + Image1 =3D CR (TestContext->ImageList.ForwardLink, IMAGE_PROPERTIES_RECO= RD, Link, IMAGE_PROPERTIES_RECORD_SIGNATURE); + Image2 =3D CR (Image1->Link.ForwardLink, IMAGE_PROPERTIES_RECORD, Link, = IMAGE_PROPERTIES_RECORD_SIGNATURE); + Image3 =3D CR (Image2->Link.ForwardLink, IMAGE_PROPERTIES_RECORD, Link, = IMAGE_PROPERTIES_RECORD_SIGNATURE); + + CodeSectionInImage1 =3D CR (Image1->CodeSegmentList.ForwardLink, IMAGE_P= ROPERTIES_RECORD_CODE_SECTION, Link, IMAGE_PROPERTIES_RECORD_CODE_SECTION_S= IGNATURE); + CodeSectionInImage2 =3D CR (Image2->CodeSegmentList.ForwardLink, IMAGE_P= ROPERTIES_RECORD_CODE_SECTION, Link, IMAGE_PROPERTIES_RECORD_CODE_SECTION_S= IGNATURE); + CodeSectionInImage3 =3D CR (Image3->CodeSegmentList.ForwardLink, IMAGE_P= ROPERTIES_RECORD_CODE_SECTION, Link, IMAGE_PROPERTIES_RECORD_CODE_SECTION_S= IGNATURE); + + /////////////// + // Descriptor 1 + /////////////// + // | | | | | | | | + // | 4K PAGE | DATA | CODE | DATA | CODE | DATA | 4K PAGE * 5 | + // | | | | | | | | + + Image1->ImageBase =3D BASE_DESCRIPTOR_START_ADDRESS (= 1) + EFI_PAGE_SIZE; + Image1->ImageSize =3D BASE_DESCRIPTOR_ENTRY_SIZE - EF= I_PAGE_SIZE - EFI_PAGE_SIZE; + Image1->CodeSegmentCount =3D 2; + CodeSectionInImage1->CodeSegmentBase =3D Image1->ImageBase + EFI_PAGE_SI= ZE; + CodeSectionInImage1->CodeSegmentSize =3D EFI_PAGE_SIZE; + TestContext->MemoryMap[1].Type =3D EfiBootServicesCode; + + AddCodeSectionInImage1 =3D AllocateZeroPool (sizeof (IM= AGE_PROPERTIES_RECORD_CODE_SECTION)); + AddCodeSectionInImage1->Signature =3D IMAGE_PROPERTIES_RECORD_CODE= _SECTION_SIGNATURE; + AddCodeSectionInImage1->CodeSegmentBase =3D CodeSectionInImage1->CodeSeg= mentBase + CodeSectionInImage1->CodeSegmentSize + EFI_PAGE_SIZE; + AddCodeSectionInImage1->CodeSegmentSize =3D EFI_PAGE_SIZE; + + InsertTailList (&Image1->CodeSegmentList, &AddCodeSectionInImage1->Link); + + /////////////// + // Descriptor 2 + /////////////// + // | | | | | | | | + // | 4K PAGE | DATA | CODE | DATA | CODE | DATA | 4K PAGE * 5 | + // | | | | | | | | + + Image2->ImageBase =3D BASE_DESCRIPTOR_START_ADDRESS (= 2) + EFI_PAGE_SIZE; + Image2->ImageSize =3D BASE_DESCRIPTOR_ENTRY_SIZE - EF= I_PAGE_SIZE - EFI_PAGE_SIZE; + Image2->CodeSegmentCount =3D 2; + CodeSectionInImage2->CodeSegmentBase =3D Image2->ImageBase + EFI_PAGE_SI= ZE; + CodeSectionInImage2->CodeSegmentSize =3D EFI_PAGE_SIZE; + TestContext->MemoryMap[2].Type =3D EfiLoaderCode; + + AddCodeSectionInImage2 =3D AllocateZeroPool (sizeof (IM= AGE_PROPERTIES_RECORD_CODE_SECTION)); + AddCodeSectionInImage2->Signature =3D IMAGE_PROPERTIES_RECORD_CODE= _SECTION_SIGNATURE; + AddCodeSectionInImage2->CodeSegmentBase =3D CodeSectionInImage2->CodeSeg= mentBase + CodeSectionInImage2->CodeSegmentSize + EFI_PAGE_SIZE; + AddCodeSectionInImage2->CodeSegmentSize =3D EFI_PAGE_SIZE; + + InsertTailList (&Image2->CodeSegmentList, &AddCodeSectionInImage2->Link); + + /////////////// + // Descriptor 3 + /////////////// + // | | | | | | | | + // | 4K PAGE | DATA | CODE | DATA | CODE | DATA | 4K PAGE * 5 | + // | | | | | | | | + + Image3->ImageBase =3D BASE_DESCRIPTOR_START_ADDRESS (= 3) + EFI_PAGE_SIZE; + Image3->ImageSize =3D BASE_DESCRIPTOR_ENTRY_SIZE - EF= I_PAGE_SIZE - EFI_PAGE_SIZE; + Image3->CodeSegmentCount =3D 2; + CodeSectionInImage3->CodeSegmentBase =3D Image3->ImageBase + EFI_PAGE_SI= ZE; + CodeSectionInImage3->CodeSegmentSize =3D EFI_PAGE_SIZE; + TestContext->MemoryMap[3].Type =3D EfiRuntimeServicesCode; + + AddCodeSectionInImage3 =3D AllocateZeroPool (sizeof (IM= AGE_PROPERTIES_RECORD_CODE_SECTION)); + AddCodeSectionInImage3->Signature =3D IMAGE_PROPERTIES_RECORD_CODE= _SECTION_SIGNATURE; + AddCodeSectionInImage3->CodeSegmentBase =3D CodeSectionInImage3->CodeSeg= mentBase + CodeSectionInImage3->CodeSegmentSize + EFI_PAGE_SIZE; + AddCodeSectionInImage3->CodeSegmentSize =3D EFI_PAGE_SIZE; + + InsertTailList (&Image3->CodeSegmentList, &AddCodeSectionInImage3->Link); + + UT_ASSERT_TRUE (SeparateAndCheck (TestContext)); + + return UNIT_TEST_PASSED; +} + +/** + Test the case where multiple image ranges lie within an existing memory = descriptor. + + @param[in] Context Context containing the memory map and image record= pointers + + @retval UNIT_TEST_PASSED The Unit test has completed and th= e test + case was successful. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +MultipleImagesInOneDescriptor ( + IN UNIT_TEST_CONTEXT Context + ) +{ + IMAGE_PROPERTIES_RECORD *Image1; + IMAGE_PROPERTIES_RECORD *Image2; + IMAGE_PROPERTIES_RECORD *Image3; + IMAGE_PROPERTIES_RECORD_CODE_SECTION *CodeSectionInImage1; + IMAGE_PROPERTIES_RECORD_CODE_SECTION *CodeSectionInImage2; + IMAGE_PROPERTIES_RECORD_CODE_SECTION *CodeSectionInImage3; + IMAGE_PROPERTIES_RECORD_HOST_TEST_CONTEXT *TestContext; + + TestContext =3D (IMAGE_PROPERTIES_RECORD_HOST_TEST_CONTEXT *)Context; + + Image1 =3D CR (TestContext->ImageList.ForwardLink, IMAGE_PROPERTIES_RECO= RD, Link, IMAGE_PROPERTIES_RECORD_SIGNATURE); + Image2 =3D CR (Image1->Link.ForwardLink, IMAGE_PROPERTIES_RECORD, Link, = IMAGE_PROPERTIES_RECORD_SIGNATURE); + Image3 =3D CR (Image2->Link.ForwardLink, IMAGE_PROPERTIES_RECORD, Link, = IMAGE_PROPERTIES_RECORD_SIGNATURE); + + CodeSectionInImage1 =3D CR (Image1->CodeSegmentList.ForwardLink, IMAGE_P= ROPERTIES_RECORD_CODE_SECTION, Link, IMAGE_PROPERTIES_RECORD_CODE_SECTION_S= IGNATURE); + CodeSectionInImage2 =3D CR (Image2->CodeSegmentList.ForwardLink, IMAGE_P= ROPERTIES_RECORD_CODE_SECTION, Link, IMAGE_PROPERTIES_RECORD_CODE_SECTION_S= IGNATURE); + CodeSectionInImage3 =3D CR (Image3->CodeSegmentList.ForwardLink, IMAGE_P= ROPERTIES_RECORD_CODE_SECTION, Link, IMAGE_PROPERTIES_RECORD_CODE_SECTION_S= IGNATURE); + + /////////////// + // Descriptor 1 + /////////////// + // | | | | | | | | | = | | | | + // | 4K PAGE | DATA | CODE | DATA | 4K PAGE | DATA | CODE | DATA | DATA = | CODE | DATA | 4K PAGE | + // | | | | | | | | | = | | | | + + Image1->ImageBase =3D BASE_DESCRIPTOR_START_ADDRESS (= 1) + EFI_PAGE_SIZE; + Image1->ImageSize =3D EFI_PAGES_TO_SIZE (3); + Image1->CodeSegmentCount =3D 1; + CodeSectionInImage1->CodeSegmentBase =3D Image1->ImageBase + EFI_PAGE_SI= ZE; + CodeSectionInImage1->CodeSegmentSize =3D EFI_PAGE_SIZE; + TestContext->MemoryMap[1].Type =3D EfiBootServicesCode; + + Image2->ImageBase =3D Image1->ImageBase + Image1->Ima= geSize + EFI_PAGE_SIZE; + Image2->ImageSize =3D EFI_PAGES_TO_SIZE (3); + Image2->CodeSegmentCount =3D 1; + CodeSectionInImage2->CodeSegmentBase =3D Image2->ImageBase + EFI_PAGE_SI= ZE; + CodeSectionInImage2->CodeSegmentSize =3D EFI_PAGE_SIZE; + + Image3->ImageBase =3D Image2->ImageBase + Image2->Ima= geSize; + Image3->ImageSize =3D EFI_PAGES_TO_SIZE (3); + Image3->CodeSegmentCount =3D 1; + CodeSectionInImage3->CodeSegmentBase =3D Image3->ImageBase + EFI_PAGE_SI= ZE; + CodeSectionInImage3->CodeSegmentSize =3D EFI_PAGE_SIZE; + + UT_ASSERT_TRUE (SeparateAndCheck (TestContext)); + + return UNIT_TEST_PASSED; +} + +/** + Test the case where all image ranges do not fit perfectly within an exis= ting memory descriptor. + + @param[in] Context Context containing the memory map and image record= pointers + + @retval UNIT_TEST_PASSED The Unit test has completed and th= e test + case was successful. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +ImagesDontFitDescriptors ( + IN UNIT_TEST_CONTEXT Context + ) +{ + IMAGE_PROPERTIES_RECORD *Image1; + IMAGE_PROPERTIES_RECORD *Image2; + IMAGE_PROPERTIES_RECORD *Image3; + IMAGE_PROPERTIES_RECORD_CODE_SECTION *CodeSectionInImage1; + IMAGE_PROPERTIES_RECORD_CODE_SECTION *CodeSectionInImage2; + IMAGE_PROPERTIES_RECORD_CODE_SECTION *CodeSectionInImage3; + IMAGE_PROPERTIES_RECORD_HOST_TEST_CONTEXT *TestContext; + + TestContext =3D (IMAGE_PROPERTIES_RECORD_HOST_TEST_CONTEXT *)Context; + + Image1 =3D CR (TestContext->ImageList.ForwardLink, IMAGE_PROPERTIES_RECO= RD, Link, IMAGE_PROPERTIES_RECORD_SIGNATURE); + Image2 =3D CR (Image1->Link.ForwardLink, IMAGE_PROPERTIES_RECORD, Link, = IMAGE_PROPERTIES_RECORD_SIGNATURE); + Image3 =3D CR (Image2->Link.ForwardLink, IMAGE_PROPERTIES_RECORD, Link, = IMAGE_PROPERTIES_RECORD_SIGNATURE); + + CodeSectionInImage1 =3D CR (Image1->CodeSegmentList.ForwardLink, IMAGE_P= ROPERTIES_RECORD_CODE_SECTION, Link, IMAGE_PROPERTIES_RECORD_CODE_SECTION_S= IGNATURE); + CodeSectionInImage2 =3D CR (Image2->CodeSegmentList.ForwardLink, IMAGE_P= ROPERTIES_RECORD_CODE_SECTION, Link, IMAGE_PROPERTIES_RECORD_CODE_SECTION_S= IGNATURE); + CodeSectionInImage3 =3D CR (Image3->CodeSegmentList.ForwardLink, IMAGE_P= ROPERTIES_RECORD_CODE_SECTION, Link, IMAGE_PROPERTIES_RECORD_CODE_SECTION_S= IGNATURE); + + /////////////// + // Descriptor 1 + /////////////// + // | | | | | + // | 4K PAGE | DATA | CODE * 2 | DATA * 8 | + // | | | | | + + Image1->ImageBase =3D BASE_DESCRIPTOR_START_ADDRESS (= 1) + EFI_PAGE_SIZE; + Image1->ImageSize =3D BASE_DESCRIPTOR_ENTRY_SIZE - EF= I_PAGE_SIZE; + Image1->CodeSegmentCount =3D 1; + CodeSectionInImage1->CodeSegmentBase =3D Image1->ImageBase + EFI_PAGE_SI= ZE; + CodeSectionInImage1->CodeSegmentSize =3D EFI_PAGES_TO_SIZE (2); + TestContext->MemoryMap[1].Type =3D EfiBootServicesCode; + + /////////////// + // Descriptor 3 + /////////////// + // | | | | | + // | DATA | CODE * 3 | DATA * 7 | 4K PAGE | + // | | | | | + + Image2->ImageBase =3D BASE_DESCRIPTOR_START_ADDRESS (= 3); + Image2->ImageSize =3D BASE_DESCRIPTOR_ENTRY_SIZE - EF= I_PAGE_SIZE; + Image2->CodeSegmentCount =3D 1; + CodeSectionInImage2->CodeSegmentBase =3D Image2->ImageBase + EFI_PAGE_SI= ZE; + CodeSectionInImage2->CodeSegmentSize =3D EFI_PAGES_TO_SIZE (3); + TestContext->MemoryMap[3].Type =3D EfiLoaderCode; + + /////////////// + // Descriptor 4 + /////////////// + // | | | | | | + // | 4K PAGE | DATA | CODE * 2 | DATA * 7 | 4K PAGE | + // | | | | | | + + Image3->ImageBase =3D BASE_DESCRIPTOR_START_ADDRESS (= 4) + EFI_PAGE_SIZE; + Image3->ImageSize =3D BASE_DESCRIPTOR_ENTRY_SIZE - EF= I_PAGE_SIZE - EFI_PAGE_SIZE; + Image3->CodeSegmentCount =3D 1; + CodeSectionInImage3->CodeSegmentBase =3D Image3->ImageBase + EFI_PAGE_SI= ZE; + CodeSectionInImage3->CodeSegmentSize =3D EFI_PAGES_TO_SIZE (2); + TestContext->MemoryMap[4].Type =3D EfiRuntimeServicesCode; + + UT_ASSERT_TRUE (SeparateAndCheck (TestContext)); + + return UNIT_TEST_PASSED; +} + +/** + Test the case where all image ranges fit perfectly within an existing me= mory descriptor. + + @param[in] Context Context containing the memory map and image record= pointers + + @retval UNIT_TEST_PASSED The Unit test has completed and th= e test + case was successful. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +ImagesFitDescriptors ( + IN UNIT_TEST_CONTEXT Context + ) +{ + IMAGE_PROPERTIES_RECORD *Image1; + IMAGE_PROPERTIES_RECORD *Image2; + IMAGE_PROPERTIES_RECORD *Image3; + IMAGE_PROPERTIES_RECORD_CODE_SECTION *CodeSectionInImage1; + IMAGE_PROPERTIES_RECORD_CODE_SECTION *CodeSectionInImage2; + IMAGE_PROPERTIES_RECORD_CODE_SECTION *CodeSectionInImage3; + IMAGE_PROPERTIES_RECORD_HOST_TEST_CONTEXT *TestContext; + + TestContext =3D (IMAGE_PROPERTIES_RECORD_HOST_TEST_CONTEXT *)Context; + + Image1 =3D CR (TestContext->ImageList.ForwardLink, IMAGE_PROPERTIES_RECO= RD, Link, IMAGE_PROPERTIES_RECORD_SIGNATURE); + Image2 =3D CR (Image1->Link.ForwardLink, IMAGE_PROPERTIES_RECORD, Link, = IMAGE_PROPERTIES_RECORD_SIGNATURE); + Image3 =3D CR (Image2->Link.ForwardLink, IMAGE_PROPERTIES_RECORD, Link, = IMAGE_PROPERTIES_RECORD_SIGNATURE); + + CodeSectionInImage1 =3D CR (Image1->CodeSegmentList.ForwardLink, IMAGE_P= ROPERTIES_RECORD_CODE_SECTION, Link, IMAGE_PROPERTIES_RECORD_CODE_SECTION_S= IGNATURE); + CodeSectionInImage2 =3D CR (Image2->CodeSegmentList.ForwardLink, IMAGE_P= ROPERTIES_RECORD_CODE_SECTION, Link, IMAGE_PROPERTIES_RECORD_CODE_SECTION_S= IGNATURE); + CodeSectionInImage3 =3D CR (Image3->CodeSegmentList.ForwardLink, IMAGE_P= ROPERTIES_RECORD_CODE_SECTION, Link, IMAGE_PROPERTIES_RECORD_CODE_SECTION_S= IGNATURE); + + /////////////// + // Descriptor 1 + /////////////// + // | | | | + // | DATA | CODE * 3 | DATA * 8 | + // | | | | + + Image1->ImageBase =3D BASE_DESCRIPTOR_START_ADDRESS (= 1); + Image1->ImageSize =3D BASE_DESCRIPTOR_ENTRY_SIZE; + Image1->CodeSegmentCount =3D 1; + CodeSectionInImage1->CodeSegmentBase =3D Image1->ImageBase + EFI_PAGE_SI= ZE; + CodeSectionInImage1->CodeSegmentSize =3D EFI_PAGES_TO_SIZE (3); + TestContext->MemoryMap[1].Type =3D EfiBootServicesCode; + + /////////////// + // Descriptor 2 + /////////////// + // | | | | + // | DATA | CODE * 4 | DATA * 7 | + // | | | | + + Image2->ImageBase =3D BASE_DESCRIPTOR_START_ADDRESS (= 2); + Image2->ImageSize =3D BASE_DESCRIPTOR_ENTRY_SIZE; + Image2->CodeSegmentCount =3D 1; + CodeSectionInImage2->CodeSegmentBase =3D Image2->ImageBase + EFI_PAGE_SI= ZE; + CodeSectionInImage2->CodeSegmentSize =3D EFI_PAGES_TO_SIZE (4); + TestContext->MemoryMap[2].Type =3D EfiLoaderCode; + + /////////////// + // Descriptor 3 + /////////////// + // | | | | + // | DATA | CODE * 3 | DATA * 8 | + // | | | | + + Image3->ImageBase =3D BASE_DESCRIPTOR_START_ADDRESS (= 3); + Image3->ImageSize =3D BASE_DESCRIPTOR_ENTRY_SIZE; + Image3->CodeSegmentCount =3D 1; + CodeSectionInImage3->CodeSegmentBase =3D Image3->ImageBase + EFI_PAGE_SI= ZE; + CodeSectionInImage3->CodeSegmentSize =3D EFI_PAGES_TO_SIZE (3); + TestContext->MemoryMap[3].Type =3D EfiRuntimeServicesCode; + + UT_ASSERT_TRUE (SeparateAndCheck (TestContext)); + + return UNIT_TEST_PASSED; +} + +/** + Free all allocated memory. + + @param[in] Context Context containing the memory map and image record= pointers +**/ +VOID +EFIAPI +TestCleanup ( + IN UNIT_TEST_CONTEXT Context + ) +{ + IMAGE_PROPERTIES_RECORD *ImageRecord; + IMAGE_PROPERTIES_RECORD_CODE_SECTION *ImageRecordCodeSection; + LIST_ENTRY *ImageRecordLink; + LIST_ENTRY *CodeSegmentListHead; + IMAGE_PROPERTIES_RECORD_HOST_TEST_CONTEXT *TestContext; + + TestContext =3D (IMAGE_PROPERTIES_RECORD_HOST_TEST_CONTEXT *)Context; + ImageRecordLink =3D &TestContext->ImageList; + + while (!IsListEmpty (ImageRecordLink)) { + ImageRecord =3D CR ( + ImageRecordLink->ForwardLink, + IMAGE_PROPERTIES_RECORD, + Link, + IMAGE_PROPERTIES_RECORD_SIGNATURE + ); + + CodeSegmentListHead =3D &ImageRecord->CodeSegmentList; + while (!IsListEmpty (CodeSegmentListHead)) { + ImageRecordCodeSection =3D CR ( + CodeSegmentListHead->ForwardLink, + IMAGE_PROPERTIES_RECORD_CODE_SECTION, + Link, + IMAGE_PROPERTIES_RECORD_CODE_SECTION_SIGN= ATURE + ); + RemoveEntryList (&ImageRecordCodeSection->Link); + FreePool (ImageRecordCodeSection); + } + + RemoveEntryList (&ImageRecord->Link); + FreePool (ImageRecord); + } + + if (TestContext->MemoryMap !=3D NULL) { + FreePool (TestContext->MemoryMap); + } +} + +/** + Create a generic image list with the proper signatures which will be cus= tomized for each test + and allocate the default memory map. + + @param[out] TestContext Context which will be passed to the test cases +**/ +STATIC +VOID +CreateBaseContextEntry ( + OUT IMAGE_PROPERTIES_RECORD_HOST_TEST_CONTEXT *TestContext + ) +{ + IMAGE_PROPERTIES_RECORD *Image1; + IMAGE_PROPERTIES_RECORD *Image2; + IMAGE_PROPERTIES_RECORD *Image3; + IMAGE_PROPERTIES_RECORD_CODE_SECTION *CodeSectionInImage1; + IMAGE_PROPERTIES_RECORD_CODE_SECTION *CodeSectionInImage2; + IMAGE_PROPERTIES_RECORD_CODE_SECTION *CodeSectionInImage3; + + InitializeListHead (&TestContext->ImageList); + + Image1 =3D AllocateZeroPool (sizeof (IMAGE_PROPERTIES_RECOR= D)); + CodeSectionInImage1 =3D AllocateZeroPool (sizeof (IMAGE_PROPERTIES_RECOR= D_CODE_SECTION)); + + Image1->Signature =3D IMAGE_PROPERTIES_RECORD_SIGNATURE; + CodeSectionInImage1->Signature =3D IMAGE_PROPERTIES_RECORD_CODE_SECTION_= SIGNATURE; + InitializeListHead (&Image1->CodeSegmentList); + + InsertTailList (&TestContext->ImageList, &Image1->Link); + InsertTailList (&Image1->CodeSegmentList, &CodeSectionInImage1->Link); + + Image2 =3D AllocateZeroPool (sizeof (IMAGE_PROPERTIES_RECOR= D)); + CodeSectionInImage2 =3D AllocateZeroPool (sizeof (IMAGE_PROPERTIES_RECOR= D_CODE_SECTION)); + + Image2->Signature =3D IMAGE_PROPERTIES_RECORD_SIGNATURE; + CodeSectionInImage2->Signature =3D IMAGE_PROPERTIES_RECORD_CODE_SECTION_= SIGNATURE; + InitializeListHead (&Image2->CodeSegmentList); + + InsertTailList (&TestContext->ImageList, &Image2->Link); + InsertTailList (&Image2->CodeSegmentList, &CodeSectionInImage2->Link); + + Image3 =3D AllocateZeroPool (sizeof (IMAGE_PROPERTIES_RECOR= D)); + CodeSectionInImage3 =3D AllocateZeroPool (sizeof (IMAGE_PROPERTIES_RECOR= D_CODE_SECTION)); + + Image3->Signature =3D IMAGE_PROPERTIES_RECORD_SIGNATURE; + CodeSectionInImage3->Signature =3D IMAGE_PROPERTIES_RECORD_CODE_SECTION_= SIGNATURE; + InitializeListHead (&Image3->CodeSegmentList); + + InsertTailList (&TestContext->ImageList, &Image3->Link); + InsertTailList (&Image3->CodeSegmentList, &CodeSectionInImage3->Link); + + TestContext->MemoryMap =3D AllocateZeroPool (SPLIT_MEMORY_MAP_SIZE); + CopyMem (TestContext->MemoryMap, &BaseMemoryMap, BASE_MEMORY_MAP_SIZE); + + return; +} + +/** + Initialze the unit test framework, suite, and unit tests. + + @retval EFI_SUCCESS All test cases were dispatched. + @retval EFI_OUT_OF_RESOURCES There are not enough resources available = to + initialize the unit tests. +**/ +STATIC +EFI_STATUS +EFIAPI +UnitTestingEntry ( + VOID + ) +{ + EFI_STATUS Status; + UNIT_TEST_FRAMEWORK_HANDLE Framework; + UNIT_TEST_SUITE_HANDLE ImagePropertiesRecordTests; + IMAGE_PROPERTIES_RECORD_HOST_TEST_CONTEXT *Context1; + IMAGE_PROPERTIES_RECORD_HOST_TEST_CONTEXT *Context2; + IMAGE_PROPERTIES_RECORD_HOST_TEST_CONTEXT *Context3; + IMAGE_PROPERTIES_RECORD_HOST_TEST_CONTEXT *Context4; + + DEBUG ((DEBUG_INFO, "%a v%a\n", UNIT_TEST_APP_NAME, UNIT_TEST_APP_VERSIO= N)); + + Framework =3D NULL; + + Context1 =3D (IMAGE_PROPERTIES_RECORD_HOST_TEST_CONTEXT *)AllocateZeroPo= ol (sizeof (IMAGE_PROPERTIES_RECORD_HOST_TEST_CONTEXT)); + Context2 =3D (IMAGE_PROPERTIES_RECORD_HOST_TEST_CONTEXT *)AllocateZeroPo= ol (sizeof (IMAGE_PROPERTIES_RECORD_HOST_TEST_CONTEXT)); + Context3 =3D (IMAGE_PROPERTIES_RECORD_HOST_TEST_CONTEXT *)AllocateZeroPo= ol (sizeof (IMAGE_PROPERTIES_RECORD_HOST_TEST_CONTEXT)); + Context4 =3D (IMAGE_PROPERTIES_RECORD_HOST_TEST_CONTEXT *)AllocateZeroPo= ol (sizeof (IMAGE_PROPERTIES_RECORD_HOST_TEST_CONTEXT)); + + CreateBaseContextEntry (Context1); + CreateBaseContextEntry (Context2); + CreateBaseContextEntry (Context3); + CreateBaseContextEntry (Context4); + + // + // Start setting up the test framework for running the tests. + // + Status =3D InitUnitTestFramework (&Framework, UNIT_TEST_APP_NAME, gEfiCa= llerBaseName, UNIT_TEST_APP_VERSION); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed in InitUnitTestFramework. Status =3D %r\n= ", Status)); + goto EXIT; + } + + // + // Populate the Unit Test Suite. + // + Status =3D CreateUnitTestSuite (&ImagePropertiesRecordTests, Framework, = "Image Properties Record Tests", "ImagePropertiesRecordLib.SplitTable", NUL= L, NULL); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed in CreateUnitTestSuite for the Image Prop= erties Record Tests\n")); + Status =3D EFI_OUT_OF_RESOURCES; + goto EXIT; + } + + // + // --------------Suite-----------Description--------------Name----------= Function--------Pre---Post-------------------Context----------- + // + AddTestCase (ImagePropertiesRecordTests, "All images fit perfectly into = existing descriptors", "ImagesFitDescriptors", ImagesFitDescriptors, NULL, = TestCleanup, Context1); + AddTestCase (ImagePropertiesRecordTests, "All images don't fit perfectly= into existing descriptors", "ImagesDontFitDescriptors", ImagesDontFitDescr= iptors, NULL, TestCleanup, Context2); + AddTestCase (ImagePropertiesRecordTests, "All Images are contined In sin= gle descriptor", "MultipleImagesInOneDescriptor", MultipleImagesInOneDescri= ptor, NULL, TestCleanup, Context3); + AddTestCase (ImagePropertiesRecordTests, "Multiple code sections each im= age", "MaxOutAdditionalDescriptors", MaxOutAdditionalDescriptors, NULL, Tes= tCleanup, Context4); + + // + // Execute the tests. + // + Status =3D RunAllTestSuites (Framework); + +EXIT: + if (Framework) { + FreeUnitTestFramework (Framework); + } + + return Status; +} + +/// +/// Avoid ECC error for function name that starts with lower case letter +/// +#define ImagePropertiesRecordLibUnitTestMain main + +/** + Standard POSIX C entry point for host based unit test execution. + + @param[in] Argc Number of arguments + @param[in] Argv Array of pointers to arguments + + @retval 0 Success + @retval other Error +**/ +INT32 +ImagePropertiesRecordLibUnitTestMain ( + IN INT32 Argc, + IN CHAR8 *Argv[] + ) +{ + return UnitTestingEntry (); +} diff --git a/MdeModulePkg/Library/ImagePropertiesRecordLib/UnitTest/ImagePr= opertiesRecordLibUnitTestHost.inf b/MdeModulePkg/Library/ImagePropertiesRec= ordLib/UnitTest/ImagePropertiesRecordLibUnitTestHost.inf new file mode 100644 index 000000000000..cbc64a14bde7 --- /dev/null +++ b/MdeModulePkg/Library/ImagePropertiesRecordLib/UnitTest/ImagePropertie= sRecordLibUnitTestHost.inf @@ -0,0 +1,35 @@ +## @file +# Unit tests the SplitTable() ImagePropertiesRecordLib Logic +# +# Copyright (C) Microsoft Corporation. +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION =3D 0x00010006 + BASE_NAME =3D ImagePropertiesRecordLibUnitTestHost + FILE_GUID =3D 45B39FAA-E25D-4724-A6F4-93C0C8588A80 + MODULE_TYPE =3D HOST_APPLICATION + VERSION_STRING =3D 1.0 + +# +# The following information is for reference only and not required by the = build tools. +# +# VALID_ARCHITECTURES =3D IA32 X64 AARCH64 +# + +[Sources] + ImagePropertiesRecordLibUnitTestHost.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + MemoryAllocationLib + UnitTestLib + ImagePropertiesRecordLib diff --git a/MdeModulePkg/Test/MdeModulePkgHostTest.dsc b/MdeModulePkg/Test= /MdeModulePkgHostTest.dsc index 8fb982a2703d..2b8cbb867a73 100644 --- a/MdeModulePkg/Test/MdeModulePkgHostTest.dsc +++ b/MdeModulePkg/Test/MdeModulePkgHostTest.dsc @@ -54,6 +54,11 @@ [Components] DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf } =20 + MdeModulePkg/Library/ImagePropertiesRecordLib/UnitTest/ImagePropertiesRe= cordLibUnitTestHost.inf { + + ImagePropertiesRecordLib|MdeModulePkg/Library/ImagePropertiesRecordL= ib/ImagePropertiesRecordLib.inf + } + # # Build HOST_APPLICATION Libraries # --=20 2.41.0.windows.2 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#107068): https://edk2.groups.io/g/devel/message/107068 Mute This Topic: https://groups.io/mt/100246936/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Thu May 9 19:23:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+107069+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+107069+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1689811561; cv=none; d=zohomail.com; s=zohoarc; b=RcTSb2BpbT0VRWsmTssxm3k15uknhfX17KPko9cFNDfV7ly0xXrttjBpLDeVzjK5dB+3q67jgjBzaEbj4usEz4rvSEv71RN3Ljfl+noj4wbKSceDA4aolPnoXwWuFUJGpqajz7TIwd52FSeIAfZIwdN/rfgXbKqr24MpkiUBBoI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689811561; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=5mOAagegdPcjdN5WyeE/1yLBgYGVXVJeSqTJFPUEkE4=; b=D88vU7UHY7gD48BliaHZmAeSd/M5MK4dXry9r4Ld0hsbMuoa9LzYaCe7e6gIkPgelMqi/1CB7Rp42xGeYFGzLBmlksMrmOE8q9BElW0Xe/fD1rjnY+W65ow9dTR9Ewd11GUjuuFhTBWyiIeACvxPjHc1QVZ+281glgLZtNhIrKk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+107069+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1689811561440337.9246909874229; Wed, 19 Jul 2023 17:06:01 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=zgR6imMPySLSEDd8+SjWyeM8/GtdEodWDaKpW0PBaBA=; c=relaxed/simple; d=groups.io; h=X-Received:X-Received:X-Received:X-Gm-Message-State:X-Google-Smtp-Source:X-Received:X-Received:From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:MIME-Version:Precedence:List-Unsubscribe:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:Content-Transfer-Encoding; s=20140610; t=1689811561; v=1; b=HCeSBHZdabC4vMCjq7cBzO5zAQV+zN/2akEG/CuCNTx7r0oE5kQLhLHnrOu5aeSFkK5REoBH dEYd1OmKj0IvMkAXUFfeJBl5MFUt9fBSPnf3rAmmPeLOnK4Nj2ARWuj2TBkj2ypBgRn3F/YkwJz VnRqcfKnvU3hv9pdZvapjOiw= X-Received: by 127.0.0.2 with SMTP id blyGYY1788612xWdnavKCMxf; Wed, 19 Jul 2023 17:06:01 -0700 X-Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by mx.groups.io with SMTP id smtpd.web10.2234.1689811560304137464 for ; Wed, 19 Jul 2023 17:06:00 -0700 X-Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-1b8a8154f9cso1825655ad.1 for ; Wed, 19 Jul 2023 17:06:00 -0700 (PDT) X-Gm-Message-State: tIIR2rwvNkByIsmNNrSh3SnQx1787277AA= X-Google-Smtp-Source: APBJJlEj1+FFcc57lKeQ7HWXJlEyanX37viDjePvc+OC6rS6txy1M77tAkvql+hNKqnFwWFaOSP6Yg== X-Received: by 2002:a17:903:32c4:b0:1b5:5162:53bd with SMTP id i4-20020a17090332c400b001b5516253bdmr4885593plr.33.1689811559611; Wed, 19 Jul 2023 17:05:59 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.230.135]) by smtp.gmail.com with ESMTPSA id jf10-20020a170903268a00b001b83e624eecsm4617286plb.81.2023.07.19.17.05.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jul 2023 17:05:59 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Jian J Wang , Liming Gao , Dandan Bi Subject: [edk2-devel] [PATCH v2 3/9] MdeModulePkg: Fix Bugs in MAT Logic Date: Wed, 19 Jul 2023 17:05:38 -0700 Message-ID: <20230720000544.146-4-t@taylorbeebe.com> In-Reply-To: <20230720000544.146-1-t@taylorbeebe.com> References: <20230720000544.146-1-t@taylorbeebe.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,t@taylorbeebe.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1689811563412100017 Content-Type: text/plain; charset="utf-8" Fix the bugs in ImagePropertiesRecordLib (which is a copy of the current UEFI MAT logic) before switching the UEFI and SMM MAT logic to use the new library. Signed-off-by: Taylor Beebe Cc: Jian J Wang Cc: Liming Gao Cc: Dandan Bi --- MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.c |= 98 ++++++++++---------- 1 file changed, 48 insertions(+), 50 deletions(-) diff --git a/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesR= ecordLib.c b/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesR= ecordLib.c index 46f4f401a4d5..a787e376b551 100644 --- a/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLi= b.c +++ b/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLi= b.c @@ -519,7 +519,7 @@ GetMaxSplitRecordCount ( break; } =20 - SplitRecordCount +=3D (2 * ImageRecord->CodeSegmentCount + 1); + SplitRecordCount +=3D (2 * ImageRecord->CodeSegmentCount + 3); PhysicalStart =3D ImageRecord->ImageBase + ImageRecord->ImageSize; } while ((ImageRecord !=3D NULL) && (PhysicalStart < PhysicalEnd)); =20 @@ -565,7 +565,6 @@ SplitRecord ( UINT64 PhysicalEnd; UINTN NewRecordCount; UINTN TotalNewRecordCount; - BOOLEAN IsLastRecordData; =20 if (MaxSplitRecordCount =3D=3D 0) { CopyMem (NewRecord, OldRecord, DescriptorSize); @@ -586,35 +585,16 @@ SplitRecord ( NewImageRecord =3D GetImageRecordByAddress (PhysicalStart, PhysicalEnd= - PhysicalStart, ImageRecordList); if (NewImageRecord =3D=3D NULL) { // - // No more image covered by this range, stop + // No more images cover this range, check if we've reached the end o= f the old descriptor. If not, + // add the remaining range to the new descriptor list. // - if ((PhysicalEnd > PhysicalStart) && (ImageRecord !=3D NULL)) { - // - // If this is still address in this record, need record. - // - NewRecord =3D PREVIOUS_MEMORY_DESCRIPTOR (NewRecord, Descri= ptorSize); - IsLastRecordData =3D FALSE; - if ((NewRecord->Attribute & EFI_MEMORY_XP) !=3D 0) { - IsLastRecordData =3D TRUE; - } - - if (IsLastRecordData) { - // - // Last record is DATA, just merge it. - // - NewRecord->NumberOfPages =3D EfiSizeToPages (PhysicalEnd - NewRe= cord->PhysicalStart); - } else { - // - // Last record is CODE, create a new DATA entry. - // - NewRecord =3D NEXT_MEMORY_DESCRIPTOR (NewRecord, = DescriptorSize); - NewRecord->Type =3D TempRecord.Type; - NewRecord->PhysicalStart =3D TempRecord.PhysicalStart; - NewRecord->VirtualStart =3D 0; - NewRecord->NumberOfPages =3D TempRecord.NumberOfPages; - NewRecord->Attribute =3D TempRecord.Attribute | EFI_MEMORY_X= P; - TotalNewRecordCount++; - } + if (PhysicalEnd > PhysicalStart) { + NewRecord->Type =3D TempRecord.Type; + NewRecord->PhysicalStart =3D PhysicalStart; + NewRecord->VirtualStart =3D 0; + NewRecord->NumberOfPages =3D EfiSizeToPages (PhysicalEnd - Physica= lStart); + NewRecord->Attribute =3D TempRecord.Attribute; + TotalNewRecordCount++; } =20 break; @@ -622,6 +602,24 @@ SplitRecord ( =20 ImageRecord =3D NewImageRecord; =20 + // + // Update PhysicalStart to exclude the portion before the image buffer + // + if (TempRecord.PhysicalStart < ImageRecord->ImageBase) { + NewRecord->Type =3D TempRecord.Type; + NewRecord->PhysicalStart =3D TempRecord.PhysicalStart; + NewRecord->VirtualStart =3D 0; + NewRecord->NumberOfPages =3D EfiSizeToPages (ImageRecord->ImageBase = - TempRecord.PhysicalStart); + NewRecord->Attribute =3D TempRecord.Attribute; + TotalNewRecordCount++; + + PhysicalStart =3D ImageRecord->ImageBase; + TempRecord.PhysicalStart =3D PhysicalStart; + TempRecord.NumberOfPages =3D EfiSizeToPages (PhysicalEnd - PhysicalS= tart); + + NewRecord =3D (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)NewRecord + Descrip= torSize); + } + // // Set new record // @@ -707,11 +705,12 @@ SplitTable ( { INTN IndexOld; INTN IndexNew; + INTN IndexNewStarting; UINTN MaxSplitRecordCount; UINTN RealSplitRecordCount; - UINTN TotalSplitRecordCount; + UINTN TotalSkippedRecords; =20 - TotalSplitRecordCount =3D 0; + TotalSkippedRecords =3D 0; // // Let old record point to end of valid MemoryMap buffer. // @@ -719,7 +718,8 @@ SplitTable ( // // Let new record point to end of full MemoryMap buffer. // - IndexNew =3D ((*MemoryMapSize) / DescriptorSize) - 1 + NumberOfAdditiona= lDescriptors; + IndexNew =3D ((*MemoryMapSize) / DescriptorSize) - 1 + NumberOfA= dditionalDescriptors; + IndexNewStarting =3D IndexNew; for ( ; IndexOld >=3D 0; IndexOld--) { MaxSplitRecordCount =3D GetMaxSplitRecordCount ((EFI_MEMORY_DESCRIPTOR= *)((UINT8 *)MemoryMap + IndexOld * DescriptorSize), ImageRecordList); // @@ -733,16 +733,14 @@ SplitTable ( DescriptorSize, ImageRecordList ); - // - // Adjust IndexNew according to real split. - // - CopyMem ( - ((UINT8 *)MemoryMap + (IndexNew + MaxSplitRecordCount - RealSplitRec= ordCount) * DescriptorSize), - ((UINT8 *)MemoryMap + IndexNew * DescriptorSize), - RealSplitRecordCount * DescriptorSize - ); - IndexNew =3D IndexNew + MaxSplitRecordCount - RealSplitR= ecordCount; - TotalSplitRecordCount +=3D RealSplitRecordCount; + + // If we didn't utilize all the extra allocated descriptor slots, set = the physical address of the unused slots + // to MAX_ADDRESS so they are moved to the bottom of the list when sor= ting. + for ( ; RealSplitRecordCount < MaxSplitRecordCount; RealSplitRecordCou= nt++) { + ((EFI_MEMORY_DESCRIPTOR *)((UINT8 *)MemoryMap + ((IndexNew + RealSpl= itRecordCount + 1) * DescriptorSize)))->PhysicalStart =3D MAX_ADDRESS; + TotalSkippedRecords++; + } + IndexNew--; } =20 @@ -751,16 +749,16 @@ SplitTable ( // CopyMem ( MemoryMap, - (UINT8 *)MemoryMap + (NumberOfAdditionalDescriptors - TotalSplitRecord= Count) * DescriptorSize, - (*MemoryMapSize) + TotalSplitRecordCount * DescriptorSize + (UINT8 *)MemoryMap + ((IndexNew + 1) * DescriptorSize), + (IndexNewStarting - IndexNew) * DescriptorSize ); =20 - *MemoryMapSize =3D (*MemoryMapSize) + DescriptorSize * TotalSplitRecordC= ount; + // + // Sort from low to high to filter out the MAX_ADDRESS records. + // + SortMemoryMap (MemoryMap, (IndexNewStarting - IndexNew) * DescriptorSize= , DescriptorSize); =20 - // - // Sort from low to high (Just in case) - // - SortMemoryMap (MemoryMap, *MemoryMapSize, DescriptorSize); + *MemoryMapSize =3D (IndexNewStarting - IndexNew - TotalSkippedRecords) *= DescriptorSize; =20 return; } --=20 2.41.0.windows.2 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#107069): https://edk2.groups.io/g/devel/message/107069 Mute This Topic: https://groups.io/mt/100246937/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Thu May 9 19:23:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+107070+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+107070+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1689811562; cv=none; d=zohomail.com; s=zohoarc; b=JcnUtEmYM2R9p6/WNwWLr39zgHLNW7t4rMOcnhFng364mMNZqtdPOhRfYhuU6W41co0qreAl3KMpGxgy1x4Xr0Der5pQQEnNvbfpCWN6AJ8UpdIXrKj/IC21Djva8jbEZXaRbzbKYPGYvPXyjEudgWa+9mXSOMQbl211zQgWimA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689811562; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=4q7aN7EZmf0CAqA27XLxCXNCgWmFJU3WUvG6uSE+rUU=; b=dPW3HbOqVR+OtQSImlObpAhNlG7hWY/gtzGgtRKXGqjdsjvvCNHpUKQ21AddofhGBYByRgltJsXw1/f79J9XoD4OUEjew0lZMP/KSE7ewTRGOLeMsClN1Uz3O+0MVC3sSMT7Sjx1AAzrbSdyGbNWEYsupjmbHhW9VM/goTriREU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+107070+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1689811562019807.345752131296; Wed, 19 Jul 2023 17:06:02 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=abMtXojwNJf697isPZmKDy1hQba3I6HKrBB6YdbcKDA=; c=relaxed/simple; d=groups.io; h=X-Received:X-Received:X-Received:X-Gm-Message-State:X-Google-Smtp-Source:X-Received:X-Received:From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:MIME-Version:Precedence:List-Unsubscribe:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:Content-Transfer-Encoding; s=20140610; t=1689811561; v=1; b=GM3NZ0FXwfgtfs9ueW6fBb9Or7q7BiY8daoiutQE9bIJaTMoOH3ClvRrBQXaUbDl6bJ385pG gLW7uGQg6bszIa1/wJWEDAyRlA3CjgtuXoNaBxXyS0Ne7UyRL091mMuuKJc8LvcFMLAlGzqdV9u iMDo5FzjgCX9/LOIazsrvLGE= X-Received: by 127.0.0.2 with SMTP id 5wTfYY1788612xp6PXgePEFr; Wed, 19 Jul 2023 17:06:01 -0700 X-Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by mx.groups.io with SMTP id smtpd.web11.2264.1689811561094231558 for ; Wed, 19 Jul 2023 17:06:01 -0700 X-Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-1b9c5e07c1bso1419755ad.2 for ; Wed, 19 Jul 2023 17:06:01 -0700 (PDT) X-Gm-Message-State: KKRLN4X29KLKn3zeExWZw2pbx1787277AA= X-Google-Smtp-Source: APBJJlFRWweGgPJ1+ZjAOBBoDsyfdTKnWsnjzPpq5LrIaWkEFPPRnS41ROn9kuaBuW8NLtKwzKeLLg== X-Received: by 2002:a17:902:d2c4:b0:1b8:6a09:9cf9 with SMTP id n4-20020a170902d2c400b001b86a099cf9mr970839plc.26.1689811560328; Wed, 19 Jul 2023 17:06:00 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.230.135]) by smtp.gmail.com with ESMTPSA id jf10-20020a170903268a00b001b83e624eecsm4617286plb.81.2023.07.19.17.05.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jul 2023 17:05:59 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Leif Lindholm , Sami Mujawar , Gerd Hoffmann Subject: [edk2-devel] [PATCH v2 4/9] ArmVirtPkg: Add ImagePropertiesRecordLib Instance Date: Wed, 19 Jul 2023 17:05:39 -0700 Message-ID: <20230720000544.146-5-t@taylorbeebe.com> In-Reply-To: <20230720000544.146-1-t@taylorbeebe.com> References: <20230720000544.146-1-t@taylorbeebe.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,t@taylorbeebe.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1689811563366100016 Content-Type: text/plain; charset="utf-8" Add an instance of ImagePropertiesRecordLib which will be used by the DXE Core. Signed-off-by: Taylor Beebe Cc: Ard Biesheuvel Cc: Leif Lindholm Cc: Sami Mujawar Cc: Gerd Hoffmann --- ArmVirtPkg/ArmVirt.dsc.inc | 1 + 1 file changed, 1 insertion(+) diff --git a/ArmVirtPkg/ArmVirt.dsc.inc b/ArmVirtPkg/ArmVirt.dsc.inc index 2443e8351c99..b299028b9f51 100644 --- a/ArmVirtPkg/ArmVirt.dsc.inc +++ b/ArmVirtPkg/ArmVirt.dsc.inc @@ -52,6 +52,7 @@ [LibraryClasses.common] IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicArmVirt.inf UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompres= sLib.inf CpuLib|MdePkg/Library/BaseCpuLib/BaseCpuLib.inf + ImagePropertiesRecordLib|MdeModulePkg/Library/ImagePropertiesRecordLib/I= magePropertiesRecordLib.inf =20 UefiLib|MdePkg/Library/UefiLib/UefiLib.inf HobLib|ArmVirtPkg/Library/ArmVirtDxeHobLib/ArmVirtDxeHobLib.inf --=20 2.41.0.windows.2 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#107070): https://edk2.groups.io/g/devel/message/107070 Mute This Topic: https://groups.io/mt/100246938/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Thu May 9 19:23:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+107071+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+107071+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1689811562; cv=none; d=zohomail.com; s=zohoarc; b=iUdraxBGvPjHuoGJjxlKBhqmi1YCMRT4W5aKqaaglWphqXr2sPpXJ7oiY4aZlX6N/YQ7VgC5RrHp/t0uKHW6QxKMueCpDZ8k3HU4VNO/Y35sekm0GPErsrpEx8t3noBTfrGr5uWXVDrXmauV0fuah/f2sGufZy0ze0PLxD0zspU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689811562; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=DwmIkZbMTe4Zr8loEX7LyjiHUog0mVrNLdkY0LuLWJY=; b=DQoPzWwABLcHsBAQEzqjAUgzbcuXKF+XQuI5ymQ/WruUVsXYZe6925jGv1r2mZQyoBtw/EwFasO7tBdNUh7OQ3A92DmWC9WvcB/w/u5w0mHzqrXqQev38sw3CPFhRThWyLyTK2HxEwRnO8F3rTf9O8BxAUqNCZ7xsEPHnX1fuQs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+107071+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1689811562717307.09156661630493; Wed, 19 Jul 2023 17:06:02 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=LwIByLuAL2EnqgrZWqkqAEQIR6V/C8bLNlk+kBoJY8M=; c=relaxed/simple; d=groups.io; h=X-Received:X-Received:X-Received:X-Gm-Message-State:X-Google-Smtp-Source:X-Received:X-Received:From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:MIME-Version:Precedence:List-Unsubscribe:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:Content-Transfer-Encoding; s=20140610; t=1689811562; v=1; b=ZvkYVL/vycIpL+NFBGozvWT5tWx4gpghBc4wD0cdz3zr8P5KRItmBeN2Rn8TVBKdZT0DntXJ Djqolej+JvPhh0DE5/qYHnKcp0exIFXwZdTOLIdEtlNiu2nXNtMRVDUTyeIpchJIbnakea+nyUp tkI3dBZNKOUVBRVRaKOCpvrU= X-Received: by 127.0.0.2 with SMTP id lrWtYY1788612xvpmDgX5PPV; Wed, 19 Jul 2023 17:06:02 -0700 X-Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) by mx.groups.io with SMTP id smtpd.web11.2265.1689811561970905461 for ; Wed, 19 Jul 2023 17:06:02 -0700 X-Received: by mail-pj1-f49.google.com with SMTP id 98e67ed59e1d1-263036d4bc3so101821a91.2 for ; Wed, 19 Jul 2023 17:06:01 -0700 (PDT) X-Gm-Message-State: tkyRAyebGF5PDjqR3RmKqNQfx1787277AA= X-Google-Smtp-Source: APBJJlEpwF23sYMPWMVY3bGxYRES+nyE5JS/TDemKaqKTi2V7mc2mghw97j9V8rJ/mXWFqlapJLiHw== X-Received: by 2002:a17:90b:4a51:b0:263:2495:c27f with SMTP id lb17-20020a17090b4a5100b002632495c27fmr662438pjb.15.1689811561396; Wed, 19 Jul 2023 17:06:01 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.230.135]) by smtp.gmail.com with ESMTPSA id jf10-20020a170903268a00b001b83e624eecsm4617286plb.81.2023.07.19.17.06.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jul 2023 17:06:00 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Andrew Fish , Ray Ni Subject: [edk2-devel] [PATCH v2 5/9] EmulatorPkg: Add ImagePropertiesRecordLib Instance Date: Wed, 19 Jul 2023 17:05:40 -0700 Message-ID: <20230720000544.146-6-t@taylorbeebe.com> In-Reply-To: <20230720000544.146-1-t@taylorbeebe.com> References: <20230720000544.146-1-t@taylorbeebe.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,t@taylorbeebe.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1689811563364100015 Content-Type: text/plain; charset="utf-8" Add an instance of ImagePropertiesRecordLib which will be used by the DXE Core. Signed-off-by: Taylor Beebe Cc: Andrew Fish Cc: Ray Ni --- EmulatorPkg/EmulatorPkg.dsc | 1 + 1 file changed, 1 insertion(+) diff --git a/EmulatorPkg/EmulatorPkg.dsc b/EmulatorPkg/EmulatorPkg.dsc index b44435d7e6ee..e18eeca884a5 100644 --- a/EmulatorPkg/EmulatorPkg.dsc +++ b/EmulatorPkg/EmulatorPkg.dsc @@ -126,6 +126,7 @@ [LibraryClasses] SortLib|MdeModulePkg/Library/BaseSortLib/BaseSortLib.inf ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf FileHandleLib|MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf + ImagePropertiesRecordLib|MdeModulePkg/Library/ImagePropertiesRecordLib/I= magePropertiesRecordLib.inf =20 !if $(SECURE_BOOT_ENABLE) =3D=3D TRUE RngLib|MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf --=20 2.41.0.windows.2 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#107071): https://edk2.groups.io/g/devel/message/107071 Mute This Topic: https://groups.io/mt/100246939/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Thu May 9 19:23:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+107072+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+107072+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1689811563; cv=none; d=zohomail.com; s=zohoarc; b=HYmNhCVbZfi2tZndLkSqK9agBjqIHSI7YOk6T7K7pyjrWEqayG8HXPRio5lQlK/qqZSSzPjzes4gtLJ/32zoEHCCfyVRZ40znaDA+mj2YXMJ/OGwwNanfZ0sW4uY7BjEPFSgwvKkApcYUYt5PPyl+8SMhCHrBhjmaa4MWp79xxI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689811563; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=f65rINqe9TdPyjJGpJj5opvKy7yPyn6TrzfvHalWPT4=; b=co1fDWJ+n+QlPtICPCXJ4ZARRC9Ec/xQ2prEJlYRn+lIlyZa9JoJdMISPknEwyLvJrixSTLZIQXdTXhNYjc+zfTAJxMouNgxU3kXltsNWvqg243bJVWgR/eOjK5yS94YEkGdBiFRnCNAqrai26A5Zmm3CTbQkiGEif2b5H7669s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+107072+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1689811563842677.5343047297459; Wed, 19 Jul 2023 17:06:03 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=zuLjVjDRcGYvW08yA+tsZS9OTSJ8dVUSHfDQx9GorD8=; c=relaxed/simple; d=groups.io; h=X-Received:X-Received:X-Received:X-Gm-Message-State:X-Google-Smtp-Source:X-Received:X-Received:From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:MIME-Version:Precedence:List-Unsubscribe:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:Content-Transfer-Encoding; s=20140610; t=1689811563; v=1; b=cw32DBV6HLowjAp/KOPKlPBIOc4ilgzLPw/8j+WDV24hP9AFT6mMmZsHbDT/f7BL9Uu5HCxX qOZ19tlgqpo/y0p6Weut1ZrmA2dHiHqLW+0cchPlikzuYvFt7nwGeykiGWXTwoOgy79WzQc1S+T 2oKXKy2z+3vbpJdeus+hYXBs= X-Received: by 127.0.0.2 with SMTP id 6USUYY1788612xGQX1vPGVVE; Wed, 19 Jul 2023 17:06:03 -0700 X-Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) by mx.groups.io with SMTP id smtpd.web11.2268.1689811562973477963 for ; Wed, 19 Jul 2023 17:06:03 -0700 X-Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-1b8b318c5cfso1477835ad.1 for ; Wed, 19 Jul 2023 17:06:02 -0700 (PDT) X-Gm-Message-State: 5aLv7WiTJqVgpfOPUzNoe47wx1787277AA= X-Google-Smtp-Source: APBJJlEmKCZ8nh9eHc2omoq7o4pOT86utEtAYyx+eZfLzpRtMBVSv1fm3kS9fxoIiYDPHT54hNc7nA== X-Received: by 2002:a17:902:850c:b0:1b8:30d8:bc49 with SMTP id bj12-20020a170902850c00b001b830d8bc49mr521737plb.45.1689811562308; Wed, 19 Jul 2023 17:06:02 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.230.135]) by smtp.gmail.com with ESMTPSA id jf10-20020a170903268a00b001b83e624eecsm4617286plb.81.2023.07.19.17.06.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jul 2023 17:06:01 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Jiewen Yao , Jordan Justen , Gerd Hoffmann Subject: [edk2-devel] [PATCH v2 6/9] OvmfPkg: Add ImagePropertiesRecordLib Instance Date: Wed, 19 Jul 2023 17:05:41 -0700 Message-ID: <20230720000544.146-7-t@taylorbeebe.com> In-Reply-To: <20230720000544.146-1-t@taylorbeebe.com> References: <20230720000544.146-1-t@taylorbeebe.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,t@taylorbeebe.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1689811565436100027 Content-Type: text/plain; charset="utf-8" Add an instance of ImagePropertiesRecordLib which will be used by the DXE Core. Signed-off-by: Taylor Beebe Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Jordan Justen Cc: Gerd Hoffmann --- OvmfPkg/AmdSev/AmdSevX64.dsc | 1 + OvmfPkg/Bhyve/BhyveX64.dsc | 1 + OvmfPkg/CloudHv/CloudHvX64.dsc | 1 + OvmfPkg/IntelTdx/IntelTdxX64.dsc | 1 + OvmfPkg/Microvm/MicrovmX64.dsc | 1 + OvmfPkg/OvmfPkgIa32.dsc | 1 + OvmfPkg/OvmfPkgIa32X64.dsc | 1 + OvmfPkg/OvmfPkgX64.dsc | 1 + OvmfPkg/OvmfXen.dsc | 1 + OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc | 1 + 10 files changed, 10 insertions(+) diff --git a/OvmfPkg/AmdSev/AmdSevX64.dsc b/OvmfPkg/AmdSev/AmdSevX64.dsc index 2c6ed7c9745f..e8c954a97956 100644 --- a/OvmfPkg/AmdSev/AmdSevX64.dsc +++ b/OvmfPkg/AmdSev/AmdSevX64.dsc @@ -171,6 +171,7 @@ [LibraryClasses] MemEncryptTdxLib|OvmfPkg/Library/BaseMemEncryptTdxLib/BaseMemEncryptTdxL= ib.inf PeiHardwareInfoLib|OvmfPkg/Library/HardwareInfoLib/PeiHardwareInfoLib.inf DxeHardwareInfoLib|OvmfPkg/Library/HardwareInfoLib/DxeHardwareInfoLib.inf + ImagePropertiesRecordLib|MdeModulePkg/Library/ImagePropertiesRecordLib/I= magePropertiesRecordLib.inf =20 !if $(SOURCE_DEBUG_ENABLE) =3D=3D TRUE PeCoffExtraActionLib|SourceLevelDebugPkg/Library/PeCoffExtraActionLibDeb= ug/PeCoffExtraActionLibDebug.inf diff --git a/OvmfPkg/Bhyve/BhyveX64.dsc b/OvmfPkg/Bhyve/BhyveX64.dsc index 7fa40998ae80..606e84ae1710 100644 --- a/OvmfPkg/Bhyve/BhyveX64.dsc +++ b/OvmfPkg/Bhyve/BhyveX64.dsc @@ -173,6 +173,7 @@ [LibraryClasses] MemEncryptTdxLib|OvmfPkg/Library/BaseMemEncryptTdxLib/BaseMemEncryptTdxL= ib.inf PeiHardwareInfoLib|OvmfPkg/Library/HardwareInfoLib/PeiHardwareInfoLib.inf DxeHardwareInfoLib|OvmfPkg/Library/HardwareInfoLib/DxeHardwareInfoLib.inf + ImagePropertiesRecordLib|MdeModulePkg/Library/ImagePropertiesRecordLib/I= magePropertiesRecordLib.inf =20 CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/Customize= dDisplayLib.inf FrameBufferBltLib|MdeModulePkg/Library/FrameBufferBltLib/FrameBufferBltL= ib.inf diff --git a/OvmfPkg/CloudHv/CloudHvX64.dsc b/OvmfPkg/CloudHv/CloudHvX64.dsc index e000deed9e4d..91816a10996f 100644 --- a/OvmfPkg/CloudHv/CloudHvX64.dsc +++ b/OvmfPkg/CloudHv/CloudHvX64.dsc @@ -182,6 +182,7 @@ [LibraryClasses] MemEncryptSevLib|OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLi= b.inf PeiHardwareInfoLib|OvmfPkg/Library/HardwareInfoLib/PeiHardwareInfoLib.inf DxeHardwareInfoLib|OvmfPkg/Library/HardwareInfoLib/DxeHardwareInfoLib.inf + ImagePropertiesRecordLib|MdeModulePkg/Library/ImagePropertiesRecordLib/I= magePropertiesRecordLib.inf !if $(SMM_REQUIRE) =3D=3D FALSE LockBoxLib|OvmfPkg/Library/LockBoxLib/LockBoxBaseLib.inf !endif diff --git a/OvmfPkg/IntelTdx/IntelTdxX64.dsc b/OvmfPkg/IntelTdx/IntelTdxX6= 4.dsc index 193657ff2d61..bee98e798717 100644 --- a/OvmfPkg/IntelTdx/IntelTdxX64.dsc +++ b/OvmfPkg/IntelTdx/IntelTdxX64.dsc @@ -171,6 +171,7 @@ [LibraryClasses] MemEncryptTdxLib|OvmfPkg/Library/BaseMemEncryptTdxLib/BaseMemEncryptTdxL= ib.inf PeiHardwareInfoLib|OvmfPkg/Library/HardwareInfoLib/PeiHardwareInfoLib.inf DxeHardwareInfoLib|OvmfPkg/Library/HardwareInfoLib/DxeHardwareInfoLib.inf + ImagePropertiesRecordLib|MdeModulePkg/Library/ImagePropertiesRecordLib/I= magePropertiesRecordLib.inf =20 LockBoxLib|OvmfPkg/Library/LockBoxLib/LockBoxBaseLib.inf CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/Customize= dDisplayLib.inf diff --git a/OvmfPkg/Microvm/MicrovmX64.dsc b/OvmfPkg/Microvm/MicrovmX64.dsc index 2f7585639374..38e0af6ae101 100644 --- a/OvmfPkg/Microvm/MicrovmX64.dsc +++ b/OvmfPkg/Microvm/MicrovmX64.dsc @@ -185,6 +185,7 @@ [LibraryClasses] MemEncryptTdxLib|OvmfPkg/Library/BaseMemEncryptTdxLib/BaseMemEncryptTdxL= ib.inf PeiHardwareInfoLib|OvmfPkg/Library/HardwareInfoLib/PeiHardwareInfoLib.inf DxeHardwareInfoLib|OvmfPkg/Library/HardwareInfoLib/DxeHardwareInfoLib.inf + ImagePropertiesRecordLib|MdeModulePkg/Library/ImagePropertiesRecordLib/I= magePropertiesRecordLib.inf =20 !if $(SOURCE_DEBUG_ENABLE) =3D=3D TRUE PeCoffExtraActionLib|SourceLevelDebugPkg/Library/PeCoffExtraActionLibDeb= ug/PeCoffExtraActionLibDebug.inf diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc index ed36935770f3..84807b3ffee9 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -187,6 +187,7 @@ [LibraryClasses] MemEncryptTdxLib|OvmfPkg/Library/BaseMemEncryptTdxLib/BaseMemEncryptTdxL= ibNull.inf PeiHardwareInfoLib|OvmfPkg/Library/HardwareInfoLib/PeiHardwareInfoLib.inf DxeHardwareInfoLib|OvmfPkg/Library/HardwareInfoLib/DxeHardwareInfoLib.inf + ImagePropertiesRecordLib|MdeModulePkg/Library/ImagePropertiesRecordLib/I= magePropertiesRecordLib.inf !if $(SMM_REQUIRE) =3D=3D FALSE LockBoxLib|OvmfPkg/Library/LockBoxLib/LockBoxBaseLib.inf !endif diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index 919315e4cb33..dc80edca1671 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -192,6 +192,7 @@ [LibraryClasses] MemEncryptTdxLib|OvmfPkg/Library/BaseMemEncryptTdxLib/BaseMemEncryptTdxL= ibNull.inf PeiHardwareInfoLib|OvmfPkg/Library/HardwareInfoLib/PeiHardwareInfoLib.inf DxeHardwareInfoLib|OvmfPkg/Library/HardwareInfoLib/DxeHardwareInfoLib.inf + ImagePropertiesRecordLib|MdeModulePkg/Library/ImagePropertiesRecordLib/I= magePropertiesRecordLib.inf !if $(SMM_REQUIRE) =3D=3D FALSE LockBoxLib|OvmfPkg/Library/LockBoxLib/LockBoxBaseLib.inf !endif diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index 823de0d0f9e0..82a97ca6d3df 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -204,6 +204,7 @@ [LibraryClasses] MemEncryptTdxLib|OvmfPkg/Library/BaseMemEncryptTdxLib/BaseMemEncryptTdxL= ib.inf PeiHardwareInfoLib|OvmfPkg/Library/HardwareInfoLib/PeiHardwareInfoLib.inf DxeHardwareInfoLib|OvmfPkg/Library/HardwareInfoLib/DxeHardwareInfoLib.inf + ImagePropertiesRecordLib|MdeModulePkg/Library/ImagePropertiesRecordLib/I= magePropertiesRecordLib.inf =20 !if $(SMM_REQUIRE) =3D=3D FALSE LockBoxLib|OvmfPkg/Library/LockBoxLib/LockBoxBaseLib.inf diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc index 210578c1d74d..17b622f34bf2 100644 --- a/OvmfPkg/OvmfXen.dsc +++ b/OvmfPkg/OvmfXen.dsc @@ -176,6 +176,7 @@ [LibraryClasses] MemEncryptTdxLib|OvmfPkg/Library/BaseMemEncryptTdxLib/BaseMemEncryptTdxL= ib.inf PeiHardwareInfoLib|OvmfPkg/Library/HardwareInfoLib/PeiHardwareInfoLib.inf DxeHardwareInfoLib|OvmfPkg/Library/HardwareInfoLib/DxeHardwareInfoLib.inf + ImagePropertiesRecordLib|MdeModulePkg/Library/ImagePropertiesRecordLib/I= magePropertiesRecordLib.inf =20 !if $(SOURCE_DEBUG_ENABLE) =3D=3D TRUE PeCoffExtraActionLib|SourceLevelDebugPkg/Library/PeCoffExtraActionLibDeb= ug/PeCoffExtraActionLibDebug.inf diff --git a/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc b/OvmfPkg/RiscVVirt/RiscVV= irtQemu.dsc index 34b2037824f1..f8b9479345d7 100644 --- a/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc +++ b/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc @@ -101,6 +101,7 @@ [LibraryClasses.common] PciHostBridgeUtilityLib|OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostB= ridgeUtilityLib.inf PeiHardwareInfoLib|OvmfPkg/Library/HardwareInfoLib/PeiHardwareInfoLib.inf PlatformHookLib|MdeModulePkg/Library/BasePlatformHookLibNull/BasePlatfor= mHookLibNull.inf + ImagePropertiesRecordLib|MdeModulePkg/Library/ImagePropertiesRecordLib/I= magePropertiesRecordLib.inf =20 !if $(TPM2_ENABLE) =3D=3D TRUE Tpm2CommandLib|SecurityPkg/Library/Tpm2CommandLib/Tpm2CommandLib.inf --=20 2.41.0.windows.2 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#107072): https://edk2.groups.io/g/devel/message/107072 Mute This Topic: https://groups.io/mt/100246940/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Thu May 9 19:23:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+107073+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+107073+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1689811564; cv=none; d=zohomail.com; s=zohoarc; b=NqR3G1p2T2fIYOucw6BkdLY3q/PQG24TvvinQxJDNmsbcUTR+jBKB5/bic2BB4ZS6bNzHB4qI3qQMpp61UiLSw+VcygaxB0oeYLA7osLex0+f7Mj2wi5msprBQSPG1rETMXxTzoV8sSYqrHwdxRCwRcXJSyWoMkUG4vNSd3gi/s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689811564; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=IqG/FbyGLAf8ejMo7gHQyYzrwr/lqMGNLCGzjxarxnw=; b=G43ylhjWYOVfrJBlxyWVWyaMqjmeirTw2IDnZwk8OtW0YSbgscDcArvLVOKUp5S2KIBMKsMNAfRZLADuPd0ZRwPEPBllDxbtwbA487PKwaBTYfTA8pzXL4qAm5a4GONMcTRwNQpAz46iwTqZhyM6R0FuzbLh0oQfW45ZJQ8lPaw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+107073+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1689811564622300.6253579782024; Wed, 19 Jul 2023 17:06:04 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=+VfCyOtu944RvYbWl7pC4UYnxd/EzT14CpjC7YdCvsk=; c=relaxed/simple; d=groups.io; h=X-Received:X-Received:X-Received:X-Gm-Message-State:X-Google-Smtp-Source:X-Received:X-Received:From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:MIME-Version:Precedence:List-Unsubscribe:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:Content-Transfer-Encoding; s=20140610; t=1689811564; v=1; b=FHGXxXOWF1fWRrAP6fqSz3rvq3DuNSHnD7fy79pIffs2T3W51khk/g/ckB3aFJL+29G60nTP sRLOUT0eq9Fo9U2tl0Wm5cfHfzCRm+xwmJAIZn78bYxUYNBlHY/LKp/T2/mQo/hfB9DXjRbtY+D Dea1HOQL5R1rVE6MVwOZv/ww= X-Received: by 127.0.0.2 with SMTP id hLcwYY1788612xMO2ASNtY1j; Wed, 19 Jul 2023 17:06:04 -0700 X-Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) by mx.groups.io with SMTP id smtpd.web10.2239.1689811563802518769 for ; Wed, 19 Jul 2023 17:06:03 -0700 X-Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-1b8b4748fe4so1367675ad.1 for ; Wed, 19 Jul 2023 17:06:03 -0700 (PDT) X-Gm-Message-State: jPfOedaEl1C29OPmD28byw0Fx1787277AA= X-Google-Smtp-Source: APBJJlFIgrYgRTMdExYrrjNLogX+1Xgesp3NU5YnH/XZu4sylRUnct2M97qvGXkas1KXrdYGfRaA7Q== X-Received: by 2002:a17:902:b190:b0:1b8:9b78:df44 with SMTP id s16-20020a170902b19000b001b89b78df44mr3526499plr.20.1689811562931; Wed, 19 Jul 2023 17:06:02 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.230.135]) by smtp.gmail.com with ESMTPSA id jf10-20020a170903268a00b001b83e624eecsm4617286plb.81.2023.07.19.17.06.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jul 2023 17:06:02 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Guo Dong , Sean Rhodes , James Lu , Gua Guo Subject: [edk2-devel] [PATCH v2 7/9] UefiPayloadPkg: Add ImagePropertiesRecordLib Instance Date: Wed, 19 Jul 2023 17:05:42 -0700 Message-ID: <20230720000544.146-8-t@taylorbeebe.com> In-Reply-To: <20230720000544.146-1-t@taylorbeebe.com> References: <20230720000544.146-1-t@taylorbeebe.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,t@taylorbeebe.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1689811565405100026 Content-Type: text/plain; charset="utf-8" Add an instance of ImagePropertiesRecordLib which will be used by the DXE Core. Signed-off-by: Taylor Beebe Cc: Guo Dong Cc: Sean Rhodes Cc: James Lu Cc: Gua Guo --- UefiPayloadPkg/UefiPayloadPkg.dsc | 1 + 1 file changed, 1 insertion(+) diff --git a/UefiPayloadPkg/UefiPayloadPkg.dsc b/UefiPayloadPkg/UefiPayload= Pkg.dsc index 47812048ddcf..8d237b23339a 100644 --- a/UefiPayloadPkg/UefiPayloadPkg.dsc +++ b/UefiPayloadPkg/UefiPayloadPkg.dsc @@ -277,6 +277,7 @@ [LibraryClasses] # DebugPrintErrorLevelLib|UefiPayloadPkg/Library/DebugPrintErrorLevelLibHo= b/DebugPrintErrorLevelLibHob.inf PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibN= ull.inf + ImagePropertiesRecordLib|MdeModulePkg/Library/ImagePropertiesRecordLib/I= magePropertiesRecordLib.inf !if $(SOURCE_DEBUG_ENABLE) =3D=3D TRUE PeCoffExtraActionLib|SourceLevelDebugPkg/Library/PeCoffExtraActionLibDeb= ug/PeCoffExtraActionLibDebug.inf DebugCommunicationLib|SourceLevelDebugPkg/Library/DebugCommunicationLibS= erialPort/DebugCommunicationLibSerialPort.inf --=20 2.41.0.windows.2 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#107073): https://edk2.groups.io/g/devel/message/107073 Mute This Topic: https://groups.io/mt/100246942/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Thu May 9 19:23:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+107074+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+107074+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1689811565; cv=none; d=zohomail.com; s=zohoarc; b=ANecm+zQVXAUMw2XM+K+bwHAZyFiI0rEek4Hkhj6xGZ6YCBp1HESYR9qJo86edmeJ1SAPEvlgxbFzdpCiMZraa3U4G8ijC/dOdUVaX8v3JS93JDNhVEmfJ7H0gbuhpY6mrV0ozt+WF+UqAroC8M9t0mPXEfNMmvwFLmhjRw5ZUE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689811565; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=uhpB9kPVXCSL48lYSQvbO5aytVTnfgHpIuA9LTndVb8=; b=EyhC2PCn1JfhApD+5a79tUc8D9ipC7iyDR5tR9Wgt7aC8Yrn39GCMijxycAzmuE/f/RPCkzo5stMK2qga5dIj3Y85y9FD5PeoeyK03nyIXq5uwyEVmaW01m0C9Mec6GpSc5VSs6yIgqNgMsldNy3J/wmPYHRyaodBXuTmXHhaGc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+107074+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1689811565222553.7429825407297; Wed, 19 Jul 2023 17:06:05 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=1pfAtpFEdm+weG+qsv8rj7xxLoxwLddg6F5eUWcGDtg=; c=relaxed/simple; d=groups.io; h=X-Received:X-Received:X-Received:X-Gm-Message-State:X-Google-Smtp-Source:X-Received:X-Received:From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:MIME-Version:Precedence:List-Unsubscribe:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:Content-Transfer-Encoding; s=20140610; t=1689811564; v=1; b=AqHD5/mMGfScRVKOhFDTWEPXRL8rXFBe2B8K5mQTr+WUEv9j7i0sUarWCsf6O6ugY/jP4a/i r0DvFM3dkByF6O2jZBs7kmhpwozaQAeh1o0JtjrZsbTdxRrrACmDpL3O6+eLArnaEO+EuKKnlnf 45R4UlgBQMjiaNcbnu3m3KDw= X-Received: by 127.0.0.2 with SMTP id lY58YY1788612x0BBUar6lJx; Wed, 19 Jul 2023 17:06:04 -0700 X-Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) by mx.groups.io with SMTP id smtpd.web10.2240.1689811564403910967 for ; Wed, 19 Jul 2023 17:06:04 -0700 X-Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-1bb1baf55f5so1713355ad.0 for ; Wed, 19 Jul 2023 17:06:04 -0700 (PDT) X-Gm-Message-State: 2pn9eAbDuXZFcmiPSmjBuQD0x1787277AA= X-Google-Smtp-Source: APBJJlHr8n8z6vkRD/jQTuGZXpMOS1Il1srG9dq5AaO51/HfAoAdzJ9gUPMACtoV7YoY5kzksb2gKg== X-Received: by 2002:a17:903:2310:b0:1b8:91ad:79e2 with SMTP id d16-20020a170903231000b001b891ad79e2mr22300929plh.3.1689811563760; Wed, 19 Jul 2023 17:06:03 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.230.135]) by smtp.gmail.com with ESMTPSA id jf10-20020a170903268a00b001b83e624eecsm4617286plb.81.2023.07.19.17.06.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jul 2023 17:06:03 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Rahul Kumar , Gerd Hoffmann Subject: [edk2-devel] [PATCH v2 8/9] UefiCpuPkg: Use Attribute From SMM MemoryAttributesTable if Nonzero Date: Wed, 19 Jul 2023 17:05:43 -0700 Message-ID: <20230720000544.146-9-t@taylorbeebe.com> In-Reply-To: <20230720000544.146-1-t@taylorbeebe.com> References: <20230720000544.146-1-t@taylorbeebe.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,t@taylorbeebe.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1689811567428100035 Content-Type: text/plain; charset="utf-8" The function EnforceMemoryMapAttribute() in the SMM MAT logic will ensure that the CODE and DATA memory types have the desired attributes. The consumer of the SMM MAT should only override the Attributes field in the MAT if it is nonzero. This also allows the UEFI and SMM MAT logic to use ImagePropertiesRecordLib instead of carrying two copies of the image properties record manipulation. Signed-off-by: Taylor Beebe Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Gerd Hoffmann --- UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c b/UefiCpuPk= g/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c index 6f498666157e..d302a9b0cbcf 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c @@ -1062,14 +1062,17 @@ SetMemMapAttributes ( MemoryMap =3D MemoryMapStart; for (Index =3D 0; Index < MemoryMapEntryCount; Index++) { DEBUG ((DEBUG_VERBOSE, "SetAttribute: Memory Entry - 0x%lx, 0x%x\n", M= emoryMap->PhysicalStart, MemoryMap->NumberOfPages)); - if (MemoryMap->Type =3D=3D EfiRuntimeServicesCode) { - MemoryAttribute =3D EFI_MEMORY_RO; - } else { - ASSERT ((MemoryMap->Type =3D=3D EfiRuntimeServicesData) || (MemoryMa= p->Type =3D=3D EfiConventionalMemory)); - // - // Set other type memory as NX. - // - MemoryAttribute =3D EFI_MEMORY_XP; + MemoryAttribute =3D MemoryMap->Attribute & EFI_MEMORY_ACCESS_MASK; + if (MemoryAttribute =3D=3D 0) { + if (MemoryMap->Type =3D=3D EfiRuntimeServicesCode) { + MemoryAttribute =3D EFI_MEMORY_RO; + } else { + ASSERT ((MemoryMap->Type =3D=3D EfiRuntimeServicesData) || (Memory= Map->Type =3D=3D EfiConventionalMemory)); + // + // Set other type memory as NX. + // + MemoryAttribute =3D EFI_MEMORY_XP; + } } =20 // --=20 2.41.0.windows.2 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#107074): https://edk2.groups.io/g/devel/message/107074 Mute This Topic: https://groups.io/mt/100246943/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Thu May 9 19:23:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+107075+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+107075+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1689811566; cv=none; d=zohomail.com; s=zohoarc; b=hwMNbS3hGn7JVCojvnrHwEn/YDYCZsdkau3oTnok4FwZ+Opn6vT0OLp2H1B+yIUB0sXRxTnQuR7cqXrOfi3EYphRGoHoyypoPVS+IhhiL2rMGXjYw9xdI7qcOEyYccdXqosej+eeC5DepJex9c4IWXd8neixh67UwpUsg3WYVaA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689811566; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=gR1U1GhcUKcj21C3WOWJwoUNBkOxk0yb2lUtlQvHaeI=; b=a8R8m6/XktyMPdjH0hZBLqKAYxG60o9YTBb1TueBcs/JPyjZob+HvaH8F8En9zcVcBS1czm/CYuDHQ/86MN0NXWCMORDgQ5Yb/IYU8bNCYgzm5I6TipSQZ0Mnjf7J4MNZoxp4mQTEKLuZMomr9gCzPth3vg3s0UfJ9ePyREm5ck= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+107075+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1689811566457980.4064792127299; Wed, 19 Jul 2023 17:06:06 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=nDEFe6B4nzPHAPXMtpg1Pa51DuV4nbj7oawUDN+g3lg=; c=relaxed/simple; d=groups.io; h=X-Received:X-Received:X-Received:X-Gm-Message-State:X-Google-Smtp-Source:X-Received:X-Received:From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:MIME-Version:Precedence:List-Unsubscribe:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:Content-Transfer-Encoding; s=20140610; t=1689811566; v=1; b=jrGYY3HjvB/DJ2WogNfu+FiQFE2QBwP4ZUsFwx5fxOFJoGQ5f+GD1f6d1SUQROF6fTMfxXN4 vuy4HLrEPA53KAVIx7OfspTCVsfM882X8MMwb3iB9nPGHJcQ7Xb7Qjx7e1jy6RWLYs/82ZYrTs7 hKqlnkEn0p7BHV/1j4shzQ6k= X-Received: by 127.0.0.2 with SMTP id 8uMiYY1788612xXisquWjJgr; Wed, 19 Jul 2023 17:06:06 -0700 X-Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by mx.groups.io with SMTP id smtpd.web11.2271.1689811565509598868 for ; Wed, 19 Jul 2023 17:06:05 -0700 X-Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-1b8ad9eede0so1562935ad.1 for ; Wed, 19 Jul 2023 17:06:05 -0700 (PDT) X-Gm-Message-State: 7mcBrSzNOIcQRlf4FjjckZf2x1787277AA= X-Google-Smtp-Source: APBJJlFKNu8sRxMuDVGR+g+hIM4LVMCX/MZ4RpW8OjwESJW23TjdgypIYd0T4K51wz2g6vN8+wEl2w== X-Received: by 2002:a17:902:d707:b0:1b9:cf52:2bcf with SMTP id w7-20020a170902d70700b001b9cf522bcfmr4348472ply.0.1689811564483; Wed, 19 Jul 2023 17:06:04 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.230.135]) by smtp.gmail.com with ESMTPSA id jf10-20020a170903268a00b001b83e624eecsm4617286plb.81.2023.07.19.17.06.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jul 2023 17:06:04 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Jian J Wang , Liming Gao , Dandan Bi Subject: [edk2-devel] [PATCH v2 9/9] MdeModulePkg: Update UEFI and SMM MAT Logic To Use ImagePropertiesRecordLib Date: Wed, 19 Jul 2023 17:05:44 -0700 Message-ID: <20230720000544.146-10-t@taylorbeebe.com> In-Reply-To: <20230720000544.146-1-t@taylorbeebe.com> References: <20230720000544.146-1-t@taylorbeebe.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,t@taylorbeebe.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1689811567498100036 Content-Type: text/plain; charset="utf-8" With the new ImagePropertiesRecordLib, UEFI and SMM no longer need to carry duplicate image properties record logic in their respective MAT implementations. Signed-off-by: Taylor Beebe Cc: Jian J Wang Cc: Liming Gao Cc: Dandan Bi --- MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c | 786 +---------------= ---- MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c | 24 +- MdeModulePkg/Core/PiSmmCore/MemoryAttributesTable.c | 785 +---------------= --- MdeModulePkg/Core/Dxe/DxeMain.h | 20 - MdeModulePkg/Core/Dxe/DxeMain.inf | 1 + MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf | 1 + 6 files changed, 46 insertions(+), 1571 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c b/MdeModule= Pkg/Core/Dxe/Misc/MemoryAttributesTable.c index fd127ee167e1..53aedf7d671e 100644 --- a/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c +++ b/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c @@ -14,6 +14,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #include +#include =20 #include =20 @@ -333,45 +334,6 @@ CoreInitializeMemoryAttributesTable ( // Below functions are for MemoryMap // =20 -/** - Converts a number of EFI_PAGEs to a size in bytes. - - NOTE: Do not use EFI_PAGES_TO_SIZE because it handles UINTN only. - - @param Pages The number of EFI_PAGES. - - @return The number of bytes associated with the number of EFI_PAGEs spe= cified - by Pages. -**/ -STATIC -UINT64 -EfiPagesToSize ( - IN UINT64 Pages - ) -{ - return LShiftU64 (Pages, EFI_PAGE_SHIFT); -} - -/** - Converts a size, in bytes, to a number of EFI_PAGESs. - - NOTE: Do not use EFI_SIZE_TO_PAGES because it handles UINTN only. - - @param Size A size in bytes. - - @return The number of EFI_PAGESs associated with the number of bytes sp= ecified - by Size. - -**/ -STATIC -UINT64 -EfiSizeToPages ( - IN UINT64 Size - ) -{ - return RShiftU64 (Size, EFI_PAGE_SHIFT) + ((((UINTN)Size) & EFI_PAGE_MAS= K) ? 1 : 0); -} - /** Acquire memory lock on mMemoryAttributesTableLock. **/ @@ -396,48 +358,6 @@ CoreReleasemMemoryAttributesTableLock ( CoreReleaseLock (&mMemoryAttributesTableLock); } =20 -/** - Sort memory map entries based upon PhysicalStart, from low to high. - - @param MemoryMap A pointer to the buffer in which firmware= places - the current memory map. - @param MemoryMapSize Size, in bytes, of the MemoryMap buffer. - @param DescriptorSize Size, in bytes, of an individual EFI_MEMO= RY_DESCRIPTOR. -**/ -STATIC -VOID -SortMemoryMap ( - IN OUT EFI_MEMORY_DESCRIPTOR *MemoryMap, - IN UINTN MemoryMapSize, - IN UINTN DescriptorSize - ) -{ - EFI_MEMORY_DESCRIPTOR *MemoryMapEntry; - EFI_MEMORY_DESCRIPTOR *NextMemoryMapEntry; - EFI_MEMORY_DESCRIPTOR *MemoryMapEnd; - EFI_MEMORY_DESCRIPTOR TempMemoryMap; - - MemoryMapEntry =3D MemoryMap; - NextMemoryMapEntry =3D NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, Descripto= rSize); - MemoryMapEnd =3D (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)MemoryMap + Me= moryMapSize); - while (MemoryMapEntry < MemoryMapEnd) { - while (NextMemoryMapEntry < MemoryMapEnd) { - if (MemoryMapEntry->PhysicalStart > NextMemoryMapEntry->PhysicalStar= t) { - CopyMem (&TempMemoryMap, MemoryMapEntry, sizeof (EFI_MEMORY_DESCRI= PTOR)); - CopyMem (MemoryMapEntry, NextMemoryMapEntry, sizeof (EFI_MEMORY_DE= SCRIPTOR)); - CopyMem (NextMemoryMapEntry, &TempMemoryMap, sizeof (EFI_MEMORY_DE= SCRIPTOR)); - } - - NextMemoryMapEntry =3D NEXT_MEMORY_DESCRIPTOR (NextMemoryMapEntry, D= escriptorSize); - } - - MemoryMapEntry =3D NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, Descrip= torSize); - NextMemoryMapEntry =3D NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, Descrip= torSize); - } - - return; -} - /** Merge continous memory map entries whose have same attributes. =20 @@ -471,7 +391,7 @@ MergeMemoryMap ( =20 do { MergeGuardPages (NewMemoryMapEntry, NextMemoryMapEntry->PhysicalStar= t); - MemoryBlockLength =3D (UINT64)(EfiPagesToSize (NewMemoryMapEntry->Nu= mberOfPages)); + MemoryBlockLength =3D LShiftU64 (NewMemoryMapEntry->NumberOfPages, E= FI_PAGE_SHIFT); if (((UINTN)NextMemoryMapEntry < (UINTN)MemoryMapEnd) && (NewMemoryMapEntry->Type =3D=3D NextMemoryMapEntry->Type) && (NewMemoryMapEntry->Attribute =3D=3D NextMemoryMapEntry->Attribu= te) && @@ -538,426 +458,6 @@ EnforceMemoryMapAttribute ( return; } =20 -/** - Return the first image record, whose [ImageBase, ImageSize] covered by [= Buffer, Length]. - - @param Buffer Start Address - @param Length Address length - - @return first image record covered by [buffer, length] -**/ -STATIC -IMAGE_PROPERTIES_RECORD * -GetImageRecordByAddress ( - IN EFI_PHYSICAL_ADDRESS Buffer, - IN UINT64 Length - ) -{ - IMAGE_PROPERTIES_RECORD *ImageRecord; - LIST_ENTRY *ImageRecordLink; - LIST_ENTRY *ImageRecordList; - - ImageRecordList =3D &mImagePropertiesPrivateData.ImageRecordList; - - for (ImageRecordLink =3D ImageRecordList->ForwardLink; - ImageRecordLink !=3D ImageRecordList; - ImageRecordLink =3D ImageRecordLink->ForwardLink) - { - ImageRecord =3D CR ( - ImageRecordLink, - IMAGE_PROPERTIES_RECORD, - Link, - IMAGE_PROPERTIES_RECORD_SIGNATURE - ); - - if ((Buffer <=3D ImageRecord->ImageBase) && - (Buffer + Length >=3D ImageRecord->ImageBase + ImageRecord->ImageS= ize)) - { - return ImageRecord; - } - } - - return NULL; -} - -/** - Set the memory map to new entries, according to one old entry, - based upon PE code section and data section in image record - - @param ImageRecord An image record whose [ImageBase, ImageSi= ze] covered - by old memory map entry. - @param NewRecord A pointer to several new memory map entri= es. - The caller gurantee the buffer size be 1 + - (SplitRecordCount * DescriptorSize) calcu= lated - below. - @param OldRecord A pointer to one old memory map entry. - @param DescriptorSize Size, in bytes, of an individual EFI_MEMO= RY_DESCRIPTOR. -**/ -STATIC -UINTN -SetNewRecord ( - IN IMAGE_PROPERTIES_RECORD *ImageRecord, - IN OUT EFI_MEMORY_DESCRIPTOR *NewRecord, - IN EFI_MEMORY_DESCRIPTOR *OldRecord, - IN UINTN DescriptorSize - ) -{ - EFI_MEMORY_DESCRIPTOR TempRecord; - IMAGE_PROPERTIES_RECORD_CODE_SECTION *ImageRecordCodeSection; - LIST_ENTRY *ImageRecordCodeSectionLink; - LIST_ENTRY *ImageRecordCodeSectionEndLink; - LIST_ENTRY *ImageRecordCodeSectionList; - UINTN NewRecordCount; - UINT64 PhysicalEnd; - UINT64 ImageEnd; - - CopyMem (&TempRecord, OldRecord, sizeof (EFI_MEMORY_DESCRIPTOR)); - PhysicalEnd =3D TempRecord.PhysicalStart + EfiPagesToSize (TempRecord= .NumberOfPages); - NewRecordCount =3D 0; - - ImageRecordCodeSectionList =3D &ImageRecord->CodeSegmentList; - - ImageRecordCodeSectionLink =3D ImageRecordCodeSectionList->ForwardLin= k; - ImageRecordCodeSectionEndLink =3D ImageRecordCodeSectionList; - while (ImageRecordCodeSectionLink !=3D ImageRecordCodeSectionEndLink) { - ImageRecordCodeSection =3D CR ( - ImageRecordCodeSectionLink, - IMAGE_PROPERTIES_RECORD_CODE_SECTION, - Link, - IMAGE_PROPERTIES_RECORD_CODE_SECTION_SIGNAT= URE - ); - ImageRecordCodeSectionLink =3D ImageRecordCodeSectionLink->ForwardLink; - - if (TempRecord.PhysicalStart <=3D ImageRecordCodeSection->CodeSegmentB= ase) { - // - // DATA - // - NewRecord->Type =3D TempRecord.Type; - NewRecord->PhysicalStart =3D TempRecord.PhysicalStart; - NewRecord->VirtualStart =3D 0; - NewRecord->NumberOfPages =3D EfiSizeToPages (ImageRecordCodeSection-= >CodeSegmentBase - NewRecord->PhysicalStart); - NewRecord->Attribute =3D TempRecord.Attribute | EFI_MEMORY_XP; - if (NewRecord->NumberOfPages !=3D 0) { - NewRecord =3D NEXT_MEMORY_DESCRIPTOR (NewRecord, DescriptorSize); - NewRecordCount++; - } - - // - // CODE - // - NewRecord->Type =3D TempRecord.Type; - NewRecord->PhysicalStart =3D ImageRecordCodeSection->CodeSegmentBase; - NewRecord->VirtualStart =3D 0; - NewRecord->NumberOfPages =3D EfiSizeToPages (ImageRecordCodeSection-= >CodeSegmentSize); - NewRecord->Attribute =3D (TempRecord.Attribute & (~EFI_MEMORY_XP= )) | EFI_MEMORY_RO; - if (NewRecord->NumberOfPages !=3D 0) { - NewRecord =3D NEXT_MEMORY_DESCRIPTOR (NewRecord, DescriptorSize); - NewRecordCount++; - } - - TempRecord.PhysicalStart =3D ImageRecordCodeSection->CodeSegmentBase= + EfiPagesToSize (EfiSizeToPages (ImageRecordCodeSection->CodeSegmentSize)= ); - TempRecord.NumberOfPages =3D EfiSizeToPages (PhysicalEnd - TempRecor= d.PhysicalStart); - if (TempRecord.NumberOfPages =3D=3D 0) { - break; - } - } - } - - ImageEnd =3D ImageRecord->ImageBase + ImageRecord->ImageSize; - - // - // Final DATA - // - if (TempRecord.PhysicalStart < ImageEnd) { - NewRecord->Type =3D TempRecord.Type; - NewRecord->PhysicalStart =3D TempRecord.PhysicalStart; - NewRecord->VirtualStart =3D 0; - NewRecord->NumberOfPages =3D EfiSizeToPages (ImageEnd - TempRecord.Phy= sicalStart); - NewRecord->Attribute =3D TempRecord.Attribute | EFI_MEMORY_XP; - NewRecordCount++; - } - - return NewRecordCount; -} - -/** - Return the max number of new splitted entries, according to one old entr= y, - based upon PE code section and data section. - - @param OldRecord A pointer to one old memory map entry. - - @retval 0 no entry need to be splitted. - @return the max number of new splitted entries -**/ -STATIC -UINTN -GetMaxSplitRecordCount ( - IN EFI_MEMORY_DESCRIPTOR *OldRecord - ) -{ - IMAGE_PROPERTIES_RECORD *ImageRecord; - UINTN SplitRecordCount; - UINT64 PhysicalStart; - UINT64 PhysicalEnd; - - SplitRecordCount =3D 0; - PhysicalStart =3D OldRecord->PhysicalStart; - PhysicalEnd =3D OldRecord->PhysicalStart + EfiPagesToSize (OldRecor= d->NumberOfPages); - - do { - ImageRecord =3D GetImageRecordByAddress (PhysicalStart, PhysicalEnd - = PhysicalStart); - if (ImageRecord =3D=3D NULL) { - break; - } - - SplitRecordCount +=3D (2 * ImageRecord->CodeSegmentCount + 1); - PhysicalStart =3D ImageRecord->ImageBase + ImageRecord->ImageSize; - } while ((ImageRecord !=3D NULL) && (PhysicalStart < PhysicalEnd)); - - if (SplitRecordCount !=3D 0) { - SplitRecordCount--; - } - - return SplitRecordCount; -} - -/** - Split the memory map to new entries, according to one old entry, - based upon PE code section and data section. - - @param OldRecord A pointer to one old memory map entry. - @param NewRecord A pointer to several new memory map entri= es. - The caller gurantee the buffer size be 1 + - (SplitRecordCount * DescriptorSize) calcu= lated - below. - @param MaxSplitRecordCount The max number of splitted entries - @param DescriptorSize Size, in bytes, of an individual EFI_MEMO= RY_DESCRIPTOR. - - @retval 0 no entry is splitted. - @return the real number of splitted record. -**/ -STATIC -UINTN -SplitRecord ( - IN EFI_MEMORY_DESCRIPTOR *OldRecord, - IN OUT EFI_MEMORY_DESCRIPTOR *NewRecord, - IN UINTN MaxSplitRecordCount, - IN UINTN DescriptorSize - ) -{ - EFI_MEMORY_DESCRIPTOR TempRecord; - IMAGE_PROPERTIES_RECORD *ImageRecord; - IMAGE_PROPERTIES_RECORD *NewImageRecord; - UINT64 PhysicalStart; - UINT64 PhysicalEnd; - UINTN NewRecordCount; - UINTN TotalNewRecordCount; - BOOLEAN IsLastRecordData; - - if (MaxSplitRecordCount =3D=3D 0) { - CopyMem (NewRecord, OldRecord, DescriptorSize); - return 0; - } - - TotalNewRecordCount =3D 0; - - // - // Override previous record - // - CopyMem (&TempRecord, OldRecord, sizeof (EFI_MEMORY_DESCRIPTOR)); - PhysicalStart =3D TempRecord.PhysicalStart; - PhysicalEnd =3D TempRecord.PhysicalStart + EfiPagesToSize (TempRecord.= NumberOfPages); - - ImageRecord =3D NULL; - do { - NewImageRecord =3D GetImageRecordByAddress (PhysicalStart, PhysicalEnd= - PhysicalStart); - if (NewImageRecord =3D=3D NULL) { - // - // No more image covered by this range, stop - // - if ((PhysicalEnd > PhysicalStart) && (ImageRecord !=3D NULL)) { - // - // If this is still address in this record, need record. - // - NewRecord =3D PREVIOUS_MEMORY_DESCRIPTOR (NewRecord, Descri= ptorSize); - IsLastRecordData =3D FALSE; - if ((NewRecord->Attribute & EFI_MEMORY_XP) !=3D 0) { - IsLastRecordData =3D TRUE; - } - - if (IsLastRecordData) { - // - // Last record is DATA, just merge it. - // - NewRecord->NumberOfPages =3D EfiSizeToPages (PhysicalEnd - NewRe= cord->PhysicalStart); - } else { - // - // Last record is CODE, create a new DATA entry. - // - NewRecord =3D NEXT_MEMORY_DESCRIPTOR (NewRecord, = DescriptorSize); - NewRecord->Type =3D TempRecord.Type; - NewRecord->PhysicalStart =3D TempRecord.PhysicalStart; - NewRecord->VirtualStart =3D 0; - NewRecord->NumberOfPages =3D TempRecord.NumberOfPages; - NewRecord->Attribute =3D TempRecord.Attribute | EFI_MEMORY_X= P; - TotalNewRecordCount++; - } - } - - break; - } - - ImageRecord =3D NewImageRecord; - - // - // Set new record - // - NewRecordCount =3D SetNewRecord (ImageRecord, NewRecord, &TempRe= cord, DescriptorSize); - TotalNewRecordCount +=3D NewRecordCount; - NewRecord =3D (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)NewRecord = + NewRecordCount * DescriptorSize); - - // - // Update PhysicalStart, in order to exclude the image buffer already = splitted. - // - PhysicalStart =3D ImageRecord->ImageBase + ImageRecord->Ima= geSize; - TempRecord.PhysicalStart =3D PhysicalStart; - TempRecord.NumberOfPages =3D EfiSizeToPages (PhysicalEnd - PhysicalSta= rt); - } while ((ImageRecord !=3D NULL) && (PhysicalStart < PhysicalEnd)); - - // - // The logic in function SplitTable() ensures that TotalNewRecordCount w= ill not be zero if the - // code reaches here. - // - ASSERT (TotalNewRecordCount !=3D 0); - return TotalNewRecordCount - 1; -} - -/** - Split the original memory map, and add more entries to describe PE code = section and data section. - This function will set EfiRuntimeServicesData to be EFI_MEMORY_XP. - This function will merge entries with same attributes finally. - - NOTE: It assumes PE code/data section are page aligned. - NOTE: It assumes enough entry is prepared for new memory map. - - Split table: - +---------------+ - | Record X | - +---------------+ - | Record RtCode | - +---------------+ - | Record Y | - +---------------+ - =3D=3D> - +---------------+ - | Record X | - +---------------+ ---- - | Record RtData | | - +---------------+ | - | Record RtCode | |-> PE/COFF1 - +---------------+ | - | Record RtData | | - +---------------+ ---- - | Record RtData | | - +---------------+ | - | Record RtCode | |-> PE/COFF2 - +---------------+ | - | Record RtData | | - +---------------+ ---- - | Record Y | - +---------------+ - - @param MemoryMapSize A pointer to the size, in bytes, of the - MemoryMap buffer. On input, this is the s= ize of - old MemoryMap before split. The actual bu= ffer - size of MemoryMap is MemoryMapSize + - (AdditionalRecordCount * DescriptorSize) = calculated - below. On output, it is the size of new M= emoryMap - after split. - @param MemoryMap A pointer to the buffer in which firmware= places - the current memory map. - @param DescriptorSize Size, in bytes, of an individual EFI_MEMO= RY_DESCRIPTOR. -**/ -STATIC -VOID -SplitTable ( - IN OUT UINTN *MemoryMapSize, - IN OUT EFI_MEMORY_DESCRIPTOR *MemoryMap, - IN UINTN DescriptorSize - ) -{ - INTN IndexOld; - INTN IndexNew; - UINTN MaxSplitRecordCount; - UINTN RealSplitRecordCount; - UINTN TotalSplitRecordCount; - UINTN AdditionalRecordCount; - - AdditionalRecordCount =3D (2 * mImagePropertiesPrivateData.CodeSegmentCo= untMax + 1) * mImagePropertiesPrivateData.ImageRecordCount; - - TotalSplitRecordCount =3D 0; - // - // Let old record point to end of valid MemoryMap buffer. - // - IndexOld =3D ((*MemoryMapSize) / DescriptorSize) - 1; - // - // Let new record point to end of full MemoryMap buffer. - // - IndexNew =3D ((*MemoryMapSize) / DescriptorSize) - 1 + AdditionalRecordC= ount; - for ( ; IndexOld >=3D 0; IndexOld--) { - MaxSplitRecordCount =3D GetMaxSplitRecordCount ((EFI_MEMORY_DESCRIPTOR= *)((UINT8 *)MemoryMap + IndexOld * DescriptorSize)); - // - // Split this MemoryMap record - // - IndexNew -=3D MaxSplitRecordCount; - RealSplitRecordCount =3D SplitRecord ( - (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)MemoryMap = + IndexOld * DescriptorSize), - (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)MemoryMap = + IndexNew * DescriptorSize), - MaxSplitRecordCount, - DescriptorSize - ); - // - // Adjust IndexNew according to real split. - // - CopyMem ( - ((UINT8 *)MemoryMap + (IndexNew + MaxSplitRecordCount - RealSplitRec= ordCount) * DescriptorSize), - ((UINT8 *)MemoryMap + IndexNew * DescriptorSize), - RealSplitRecordCount * DescriptorSize - ); - IndexNew =3D IndexNew + MaxSplitRecordCount - RealSplitR= ecordCount; - TotalSplitRecordCount +=3D RealSplitRecordCount; - IndexNew--; - } - - // - // Move all records to the beginning. - // - CopyMem ( - MemoryMap, - (UINT8 *)MemoryMap + (AdditionalRecordCount - TotalSplitRecordCount) *= DescriptorSize, - (*MemoryMapSize) + TotalSplitRecordCount * DescriptorSize - ); - - *MemoryMapSize =3D (*MemoryMapSize) + DescriptorSize * TotalSplitRecordC= ount; - - // - // Sort from low to high (Just in case) - // - SortMemoryMap (MemoryMap, *MemoryMapSize, DescriptorSize); - - // - // Set RuntimeData to XP - // - EnforceMemoryMapAttribute (MemoryMap, *MemoryMapSize, DescriptorSize); - - // - // Merge same type to save entry size - // - MergeMemoryMap (MemoryMap, MemoryMapSize, DescriptorSize); - - return; -} - /** This function for GetMemoryMap() with properties table capability. =20 @@ -1017,7 +517,7 @@ CoreGetMemoryMapWithSeparatedImageSection ( =20 CoreAcquiremMemoryAttributesTableLock (); =20 - AdditionalRecordCount =3D (2 * mImagePropertiesPrivateData.CodeSegmentCo= untMax + 1) * mImagePropertiesPrivateData.ImageRecordCount; + AdditionalRecordCount =3D (2 * mImagePropertiesPrivateData.CodeSegmentCo= untMax + 3) * mImagePropertiesPrivateData.ImageRecordCount; =20 OldMemoryMapSize =3D *MemoryMapSize; Status =3D CoreGetMemoryMap (MemoryMapSize, MemoryMap, MapKey,= DescriptorSize, DescriptorVersion); @@ -1035,7 +535,23 @@ CoreGetMemoryMapWithSeparatedImageSection ( // // Split PE code/data // - SplitTable (MemoryMapSize, MemoryMap, *DescriptorSize); + SplitTable ( + MemoryMapSize, + MemoryMap, + *DescriptorSize, + &mImagePropertiesPrivateData.ImageRecordList, + AdditionalRecordCount + ); + + // + // Set RuntimeData to XP + // + EnforceMemoryMapAttribute (MemoryMap, *MemoryMapSize, *DescriptorSiz= e); + + // + // Merge same type to save entry size + // + MergeMemoryMap (MemoryMap, MemoryMapSize, *DescriptorSize); } } =20 @@ -1066,218 +582,6 @@ SetMemoryAttributesTableSectionAlignment ( } } =20 -/** - Swap two code sections in image record. - - @param FirstImageRecordCodeSection first code section in image record - @param SecondImageRecordCodeSection second code section in image reco= rd -**/ -STATIC -VOID -SwapImageRecordCodeSection ( - IN IMAGE_PROPERTIES_RECORD_CODE_SECTION *FirstImageRecordCodeSection, - IN IMAGE_PROPERTIES_RECORD_CODE_SECTION *SecondImageRecordCodeSection - ) -{ - IMAGE_PROPERTIES_RECORD_CODE_SECTION TempImageRecordCodeSection; - - TempImageRecordCodeSection.CodeSegmentBase =3D FirstImageRecordCodeSecti= on->CodeSegmentBase; - TempImageRecordCodeSection.CodeSegmentSize =3D FirstImageRecordCodeSecti= on->CodeSegmentSize; - - FirstImageRecordCodeSection->CodeSegmentBase =3D SecondImageRecordCodeSe= ction->CodeSegmentBase; - FirstImageRecordCodeSection->CodeSegmentSize =3D SecondImageRecordCodeSe= ction->CodeSegmentSize; - - SecondImageRecordCodeSection->CodeSegmentBase =3D TempImageRecordCodeSec= tion.CodeSegmentBase; - SecondImageRecordCodeSection->CodeSegmentSize =3D TempImageRecordCodeSec= tion.CodeSegmentSize; -} - -/** - Sort code section in image record, based upon CodeSegmentBase from low t= o high. - - @param ImageRecord image record to be sorted -**/ -VOID -SortImageRecordCodeSection ( - IN IMAGE_PROPERTIES_RECORD *ImageRecord - ) -{ - IMAGE_PROPERTIES_RECORD_CODE_SECTION *ImageRecordCodeSection; - IMAGE_PROPERTIES_RECORD_CODE_SECTION *NextImageRecordCodeSection; - LIST_ENTRY *ImageRecordCodeSectionLink; - LIST_ENTRY *NextImageRecordCodeSectionLink; - LIST_ENTRY *ImageRecordCodeSectionEndLink; - LIST_ENTRY *ImageRecordCodeSectionList; - - ImageRecordCodeSectionList =3D &ImageRecord->CodeSegmentList; - - ImageRecordCodeSectionLink =3D ImageRecordCodeSectionList->ForwardLi= nk; - NextImageRecordCodeSectionLink =3D ImageRecordCodeSectionLink->ForwardLi= nk; - ImageRecordCodeSectionEndLink =3D ImageRecordCodeSectionList; - while (ImageRecordCodeSectionLink !=3D ImageRecordCodeSectionEndLink) { - ImageRecordCodeSection =3D CR ( - ImageRecordCodeSectionLink, - IMAGE_PROPERTIES_RECORD_CODE_SECTION, - Link, - IMAGE_PROPERTIES_RECORD_CODE_SECTION_SIGNAT= URE - ); - while (NextImageRecordCodeSectionLink !=3D ImageRecordCodeSectionEndLi= nk) { - NextImageRecordCodeSection =3D CR ( - NextImageRecordCodeSectionLink, - IMAGE_PROPERTIES_RECORD_CODE_SECTION, - Link, - IMAGE_PROPERTIES_RECORD_CODE_SECTION_= SIGNATURE - ); - if (ImageRecordCodeSection->CodeSegmentBase > NextImageRecordCodeSec= tion->CodeSegmentBase) { - SwapImageRecordCodeSection (ImageRecordCodeSection, NextImageRecor= dCodeSection); - } - - NextImageRecordCodeSectionLink =3D NextImageRecordCodeSectionLink->F= orwardLink; - } - - ImageRecordCodeSectionLink =3D ImageRecordCodeSectionLink->Forward= Link; - NextImageRecordCodeSectionLink =3D ImageRecordCodeSectionLink->Forward= Link; - } -} - -/** - Check if code section in image record is valid. - - @param ImageRecord image record to be checked - - @retval TRUE image record is valid - @retval FALSE image record is invalid -**/ -BOOLEAN -IsImageRecordCodeSectionValid ( - IN IMAGE_PROPERTIES_RECORD *ImageRecord - ) -{ - IMAGE_PROPERTIES_RECORD_CODE_SECTION *ImageRecordCodeSection; - IMAGE_PROPERTIES_RECORD_CODE_SECTION *LastImageRecordCodeSection; - LIST_ENTRY *ImageRecordCodeSectionLink; - LIST_ENTRY *ImageRecordCodeSectionEndLink; - LIST_ENTRY *ImageRecordCodeSectionList; - - DEBUG ((DEBUG_VERBOSE, "ImageCode SegmentCount - 0x%x\n", ImageRecord->C= odeSegmentCount)); - - ImageRecordCodeSectionList =3D &ImageRecord->CodeSegmentList; - - ImageRecordCodeSectionLink =3D ImageRecordCodeSectionList->ForwardLin= k; - ImageRecordCodeSectionEndLink =3D ImageRecordCodeSectionList; - LastImageRecordCodeSection =3D NULL; - while (ImageRecordCodeSectionLink !=3D ImageRecordCodeSectionEndLink) { - ImageRecordCodeSection =3D CR ( - ImageRecordCodeSectionLink, - IMAGE_PROPERTIES_RECORD_CODE_SECTION, - Link, - IMAGE_PROPERTIES_RECORD_CODE_SECTION_SIGNAT= URE - ); - if (ImageRecordCodeSection->CodeSegmentSize =3D=3D 0) { - return FALSE; - } - - if (ImageRecordCodeSection->CodeSegmentBase < ImageRecord->ImageBase) { - return FALSE; - } - - if (ImageRecordCodeSection->CodeSegmentBase >=3D MAX_ADDRESS - ImageRe= cordCodeSection->CodeSegmentSize) { - return FALSE; - } - - if ((ImageRecordCodeSection->CodeSegmentBase + ImageRecordCodeSection-= >CodeSegmentSize) > (ImageRecord->ImageBase + ImageRecord->ImageSize)) { - return FALSE; - } - - if (LastImageRecordCodeSection !=3D NULL) { - if ((LastImageRecordCodeSection->CodeSegmentBase + LastImageRecordCo= deSection->CodeSegmentSize) > ImageRecordCodeSection->CodeSegmentBase) { - return FALSE; - } - } - - LastImageRecordCodeSection =3D ImageRecordCodeSection; - ImageRecordCodeSectionLink =3D ImageRecordCodeSectionLink->ForwardLink; - } - - return TRUE; -} - -/** - Swap two image records. - - @param FirstImageRecord first image record. - @param SecondImageRecord second image record. -**/ -STATIC -VOID -SwapImageRecord ( - IN IMAGE_PROPERTIES_RECORD *FirstImageRecord, - IN IMAGE_PROPERTIES_RECORD *SecondImageRecord - ) -{ - IMAGE_PROPERTIES_RECORD TempImageRecord; - - TempImageRecord.ImageBase =3D FirstImageRecord->ImageBase; - TempImageRecord.ImageSize =3D FirstImageRecord->ImageSize; - TempImageRecord.CodeSegmentCount =3D FirstImageRecord->CodeSegmentCount; - - FirstImageRecord->ImageBase =3D SecondImageRecord->ImageBase; - FirstImageRecord->ImageSize =3D SecondImageRecord->ImageSize; - FirstImageRecord->CodeSegmentCount =3D SecondImageRecord->CodeSegmentCou= nt; - - SecondImageRecord->ImageBase =3D TempImageRecord.ImageBase; - SecondImageRecord->ImageSize =3D TempImageRecord.ImageSize; - SecondImageRecord->CodeSegmentCount =3D TempImageRecord.CodeSegmentCount; - - SwapListEntries (&FirstImageRecord->CodeSegmentList, &SecondImageRecord-= >CodeSegmentList); -} - -/** - Sort image record based upon the ImageBase from low to high. -**/ -STATIC -VOID -SortImageRecord ( - VOID - ) -{ - IMAGE_PROPERTIES_RECORD *ImageRecord; - IMAGE_PROPERTIES_RECORD *NextImageRecord; - LIST_ENTRY *ImageRecordLink; - LIST_ENTRY *NextImageRecordLink; - LIST_ENTRY *ImageRecordEndLink; - LIST_ENTRY *ImageRecordList; - - ImageRecordList =3D &mImagePropertiesPrivateData.ImageRecordList; - - ImageRecordLink =3D ImageRecordList->ForwardLink; - NextImageRecordLink =3D ImageRecordLink->ForwardLink; - ImageRecordEndLink =3D ImageRecordList; - while (ImageRecordLink !=3D ImageRecordEndLink) { - ImageRecord =3D CR ( - ImageRecordLink, - IMAGE_PROPERTIES_RECORD, - Link, - IMAGE_PROPERTIES_RECORD_SIGNATURE - ); - while (NextImageRecordLink !=3D ImageRecordEndLink) { - NextImageRecord =3D CR ( - NextImageRecordLink, - IMAGE_PROPERTIES_RECORD, - Link, - IMAGE_PROPERTIES_RECORD_SIGNATURE - ); - if (ImageRecord->ImageBase > NextImageRecord->ImageBase) { - SwapImageRecord (ImageRecord, NextImageRecord); - } - - NextImageRecordLink =3D NextImageRecordLink->ForwardLink; - } - - ImageRecordLink =3D ImageRecordLink->ForwardLink; - NextImageRecordLink =3D ImageRecordLink->ForwardLink; - } -} - /** Insert image record. =20 @@ -1456,54 +760,12 @@ InsertImageRecord ( mImagePropertiesPrivateData.CodeSegmentCountMax =3D ImageRecord->CodeS= egmentCount; } =20 - SortImageRecord (); + SortImageRecord (&mImagePropertiesPrivateData.ImageRecordList); =20 Finish: return; } =20 -/** - Find image record according to image base and size. - - @param ImageBase Base of PE image - @param 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 =3D &mImagePropertiesPrivateData.ImageRecordList; - - for (ImageRecordLink =3D ImageRecordList->ForwardLink; - ImageRecordLink !=3D ImageRecordList; - ImageRecordLink =3D ImageRecordLink->ForwardLink) - { - ImageRecord =3D CR ( - ImageRecordLink, - IMAGE_PROPERTIES_RECORD, - Link, - IMAGE_PROPERTIES_RECORD_SIGNATURE - ); - - if ((ImageBase =3D=3D ImageRecord->ImageBase) && - (ImageSize =3D=3D ImageRecord->ImageSize)) - { - return ImageRecord; - } - } - - return NULL; -} - /** Remove Image record. =20 @@ -1526,7 +788,11 @@ RemoveImageRecord ( return; } =20 - ImageRecord =3D FindImageRecord ((EFI_PHYSICAL_ADDRESS)(UINTN)RuntimeIma= ge->ImageBase, RuntimeImage->ImageSize); + ImageRecord =3D FindImageRecord ( + (EFI_PHYSICAL_ADDRESS)(UINTN)RuntimeImage->ImageBase, + RuntimeImage->ImageSize, + &mImagePropertiesPrivateData.ImageRecordList + ); if (ImageRecord =3D=3D NULL) { DEBUG ((DEBUG_ERROR, "!!!!!!!! ImageRecord not found !!!!!!!!\n")); return; diff --git a/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c b/MdeModulePkg/C= ore/Dxe/Misc/MemoryProtection.c index 7cc829b17402..977239d08afc 100644 --- a/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c +++ b/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c @@ -32,6 +32,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #include +#include =20 #include #include @@ -66,29 +67,6 @@ extern LIST_ENTRY mGcdMemorySpaceMap; =20 STATIC LIST_ENTRY mProtectedImageRecordList; =20 -/** - Sort code section in image record, based upon CodeSegmentBase from low t= o high. - - @param ImageRecord image record to be sorted -**/ -VOID -SortImageRecordCodeSection ( - IN IMAGE_PROPERTIES_RECORD *ImageRecord - ); - -/** - Check if code section in image record is valid. - - @param ImageRecord image record to be checked - - @retval TRUE image record is valid - @retval FALSE image record is invalid -**/ -BOOLEAN -IsImageRecordCodeSectionValid ( - IN IMAGE_PROPERTIES_RECORD *ImageRecord - ); - /** Get the image type. =20 diff --git a/MdeModulePkg/Core/PiSmmCore/MemoryAttributesTable.c b/MdeModul= ePkg/Core/PiSmmCore/MemoryAttributesTable.c index 394fdae50741..2e4aaddef4e5 100644 --- a/MdeModulePkg/Core/PiSmmCore/MemoryAttributesTable.c +++ b/MdeModulePkg/Core/PiSmmCore/MemoryAttributesTable.c @@ -14,6 +14,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #include +#include =20 #include #include @@ -25,26 +26,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #define PREVIOUS_MEMORY_DESCRIPTOR(MemoryDescriptor, Size) \ ((EFI_MEMORY_DESCRIPTOR *)((UINT8 *)(MemoryDescriptor) - (Size))) =20 -#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') =20 typedef struct { @@ -69,87 +50,6 @@ UINT64 mMemoryProtectionAttribute =3D EFI_MEMORY_ATTRIB= UTES_RUNTIME_MEMORY_PROTEC // Below functions are for MemoryMap // =20 -/** - Converts a number of EFI_PAGEs to a size in bytes. - - NOTE: Do not use EFI_PAGES_TO_SIZE because it handles UINTN only. - - @param[in] Pages The number of EFI_PAGES. - - @return The number of bytes associated with the number of EFI_PAGEs spe= cified - by Pages. -**/ -STATIC -UINT64 -EfiPagesToSize ( - IN UINT64 Pages - ) -{ - return LShiftU64 (Pages, EFI_PAGE_SHIFT); -} - -/** - Converts a size, in bytes, to a number of EFI_PAGESs. - - NOTE: Do not use EFI_SIZE_TO_PAGES because it handles UINTN only. - - @param[in] Size A size in bytes. - - @return The number of EFI_PAGESs associated with the number of bytes sp= ecified - by Size. - -**/ -STATIC -UINT64 -EfiSizeToPages ( - IN UINT64 Size - ) -{ - return RShiftU64 (Size, EFI_PAGE_SHIFT) + ((((UINTN)Size) & EFI_PAGE_MAS= K) ? 1 : 0); -} - -/** - Sort memory map entries based upon PhysicalStart, from low to high. - - @param[in,out] MemoryMap A pointer to the buffer in which firmw= are places - the current memory map. - @param[in] MemoryMapSize Size, in bytes, of the MemoryMap buffe= r. - @param[in] DescriptorSize Size, in bytes, of an individual EFI_M= EMORY_DESCRIPTOR. -**/ -STATIC -VOID -SortMemoryMap ( - IN OUT EFI_MEMORY_DESCRIPTOR *MemoryMap, - IN UINTN MemoryMapSize, - IN UINTN DescriptorSize - ) -{ - EFI_MEMORY_DESCRIPTOR *MemoryMapEntry; - EFI_MEMORY_DESCRIPTOR *NextMemoryMapEntry; - EFI_MEMORY_DESCRIPTOR *MemoryMapEnd; - EFI_MEMORY_DESCRIPTOR TempMemoryMap; - - MemoryMapEntry =3D MemoryMap; - NextMemoryMapEntry =3D NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, Descripto= rSize); - MemoryMapEnd =3D (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)MemoryMap + Me= moryMapSize); - while (MemoryMapEntry < MemoryMapEnd) { - while (NextMemoryMapEntry < MemoryMapEnd) { - if (MemoryMapEntry->PhysicalStart > NextMemoryMapEntry->PhysicalStar= t) { - CopyMem (&TempMemoryMap, MemoryMapEntry, sizeof (EFI_MEMORY_DESCRI= PTOR)); - CopyMem (MemoryMapEntry, NextMemoryMapEntry, sizeof (EFI_MEMORY_DE= SCRIPTOR)); - CopyMem (NextMemoryMapEntry, &TempMemoryMap, sizeof (EFI_MEMORY_DE= SCRIPTOR)); - } - - NextMemoryMapEntry =3D NEXT_MEMORY_DESCRIPTOR (NextMemoryMapEntry, D= escriptorSize); - } - - MemoryMapEntry =3D NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, Descrip= torSize); - NextMemoryMapEntry =3D NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, Descrip= torSize); - } - - return; -} - /** Merge continuous memory map entries whose have same attributes. =20 @@ -183,7 +83,7 @@ MergeMemoryMap ( NextMemoryMapEntry =3D NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, Descrip= torSize); =20 do { - MemoryBlockLength =3D (UINT64)(EfiPagesToSize (MemoryMapEntry->Numbe= rOfPages)); + MemoryBlockLength =3D LShiftU64 (MemoryMapEntry->NumberOfPages, EFI_= PAGE_SHIFT); if (((UINTN)NextMemoryMapEntry < (UINTN)MemoryMapEnd) && (MemoryMapEntry->Type =3D=3D NextMemoryMapEntry->Type) && (MemoryMapEntry->Attribute =3D=3D NextMemoryMapEntry->Attribute)= && @@ -254,423 +154,6 @@ EnforceMemoryMapAttribute ( return; } =20 -/** - Return the first image record, whose [ImageBase, ImageSize] covered by [= Buffer, Length]. - - @param[in] Buffer Start Address - @param[in] Length Address length - - @return first image record covered by [buffer, length] -**/ -STATIC -IMAGE_PROPERTIES_RECORD * -GetImageRecordByAddress ( - IN EFI_PHYSICAL_ADDRESS Buffer, - IN UINT64 Length - ) -{ - IMAGE_PROPERTIES_RECORD *ImageRecord; - LIST_ENTRY *ImageRecordLink; - LIST_ENTRY *ImageRecordList; - - ImageRecordList =3D &mImagePropertiesPrivateData.ImageRecordList; - - for (ImageRecordLink =3D ImageRecordList->ForwardLink; - ImageRecordLink !=3D ImageRecordList; - ImageRecordLink =3D ImageRecordLink->ForwardLink) - { - ImageRecord =3D CR ( - ImageRecordLink, - IMAGE_PROPERTIES_RECORD, - Link, - IMAGE_PROPERTIES_RECORD_SIGNATURE - ); - - if ((Buffer <=3D ImageRecord->ImageBase) && - (Buffer + Length >=3D ImageRecord->ImageBase + ImageRecord->ImageS= ize)) - { - return ImageRecord; - } - } - - return NULL; -} - -/** - Set the memory map to new entries, according to one old entry, - based upon PE code section and data section in image record - - @param[in] ImageRecord An image record whose [ImageBase= , ImageSize] covered - by old memory map entry. - @param[in, out] NewRecord A pointer to several new memory = map entries. - The caller guarantee the buffer = size be 1 + - (SplitRecordCount * DescriptorSi= ze) calculated - below. - @param[in] OldRecord A pointer to one old memory map = entry. - @param[in] DescriptorSize Size, in bytes, of an individual= EFI_MEMORY_DESCRIPTOR. -**/ -STATIC -UINTN -SetNewRecord ( - IN IMAGE_PROPERTIES_RECORD *ImageRecord, - IN OUT EFI_MEMORY_DESCRIPTOR *NewRecord, - IN EFI_MEMORY_DESCRIPTOR *OldRecord, - IN UINTN DescriptorSize - ) -{ - EFI_MEMORY_DESCRIPTOR TempRecord; - IMAGE_PROPERTIES_RECORD_CODE_SECTION *ImageRecordCodeSection; - LIST_ENTRY *ImageRecordCodeSectionLink; - LIST_ENTRY *ImageRecordCodeSectionEndLink; - LIST_ENTRY *ImageRecordCodeSectionList; - UINTN NewRecordCount; - UINT64 PhysicalEnd; - UINT64 ImageEnd; - - CopyMem (&TempRecord, OldRecord, sizeof (EFI_MEMORY_DESCRIPTOR)); - PhysicalEnd =3D TempRecord.PhysicalStart + EfiPagesToSize (TempRecord= .NumberOfPages); - NewRecordCount =3D 0; - - // - // Always create a new entry for non-PE image record - // - if (ImageRecord->ImageBase > TempRecord.PhysicalStart) { - NewRecord->Type =3D TempRecord.Type; - NewRecord->PhysicalStart =3D TempRecord.PhysicalStart; - NewRecord->VirtualStart =3D 0; - NewRecord->NumberOfPages =3D EfiSizeToPages (ImageRecord->ImageBase - = TempRecord.PhysicalStart); - NewRecord->Attribute =3D TempRecord.Attribute; - NewRecord =3D NEXT_MEMORY_DESCRIPTOR (NewRecord, Descri= ptorSize); - NewRecordCount++; - TempRecord.PhysicalStart =3D ImageRecord->ImageBase; - TempRecord.NumberOfPages =3D EfiSizeToPages (PhysicalEnd - TempRecord.= PhysicalStart); - } - - ImageRecordCodeSectionList =3D &ImageRecord->CodeSegmentList; - - ImageRecordCodeSectionLink =3D ImageRecordCodeSectionList->ForwardLin= k; - ImageRecordCodeSectionEndLink =3D ImageRecordCodeSectionList; - while (ImageRecordCodeSectionLink !=3D ImageRecordCodeSectionEndLink) { - ImageRecordCodeSection =3D CR ( - ImageRecordCodeSectionLink, - IMAGE_PROPERTIES_RECORD_CODE_SECTION, - Link, - IMAGE_PROPERTIES_RECORD_CODE_SECTION_SIGNAT= URE - ); - ImageRecordCodeSectionLink =3D ImageRecordCodeSectionLink->ForwardLink; - - if (TempRecord.PhysicalStart <=3D ImageRecordCodeSection->CodeSegmentB= ase) { - // - // DATA - // - NewRecord->Type =3D EfiRuntimeServicesData; - NewRecord->PhysicalStart =3D TempRecord.PhysicalStart; - NewRecord->VirtualStart =3D 0; - NewRecord->NumberOfPages =3D EfiSizeToPages (ImageRecordCodeSection-= >CodeSegmentBase - NewRecord->PhysicalStart); - NewRecord->Attribute =3D TempRecord.Attribute | EFI_MEMORY_XP; - if (NewRecord->NumberOfPages !=3D 0) { - NewRecord =3D NEXT_MEMORY_DESCRIPTOR (NewRecord, DescriptorSize); - NewRecordCount++; - } - - // - // CODE - // - NewRecord->Type =3D EfiRuntimeServicesCode; - NewRecord->PhysicalStart =3D ImageRecordCodeSection->CodeSegmentBase; - NewRecord->VirtualStart =3D 0; - NewRecord->NumberOfPages =3D EfiSizeToPages (ImageRecordCodeSection-= >CodeSegmentSize); - NewRecord->Attribute =3D (TempRecord.Attribute & (~EFI_MEMORY_XP= )) | EFI_MEMORY_RO; - if (NewRecord->NumberOfPages !=3D 0) { - NewRecord =3D NEXT_MEMORY_DESCRIPTOR (NewRecord, DescriptorSize); - NewRecordCount++; - } - - TempRecord.PhysicalStart =3D ImageRecordCodeSection->CodeSegmentBase= + EfiPagesToSize (EfiSizeToPages (ImageRecordCodeSection->CodeSegmentSize)= ); - TempRecord.NumberOfPages =3D EfiSizeToPages (PhysicalEnd - TempRecor= d.PhysicalStart); - if (TempRecord.NumberOfPages =3D=3D 0) { - break; - } - } - } - - ImageEnd =3D ImageRecord->ImageBase + ImageRecord->ImageSize; - - // - // Final DATA - // - if (TempRecord.PhysicalStart < ImageEnd) { - NewRecord->Type =3D EfiRuntimeServicesData; - NewRecord->PhysicalStart =3D TempRecord.PhysicalStart; - NewRecord->VirtualStart =3D 0; - NewRecord->NumberOfPages =3D EfiSizeToPages (ImageEnd - TempRecord.Phy= sicalStart); - NewRecord->Attribute =3D TempRecord.Attribute | EFI_MEMORY_XP; - NewRecordCount++; - } - - return NewRecordCount; -} - -/** - Return the max number of new splitted entries, according to one old entr= y, - based upon PE code section and data section. - - @param[in] OldRecord A pointer to one old memory map entry. - - @retval 0 no entry need to be splitted. - @return the max number of new splitted entries -**/ -STATIC -UINTN -GetMaxSplitRecordCount ( - IN EFI_MEMORY_DESCRIPTOR *OldRecord - ) -{ - IMAGE_PROPERTIES_RECORD *ImageRecord; - UINTN SplitRecordCount; - UINT64 PhysicalStart; - UINT64 PhysicalEnd; - - SplitRecordCount =3D 0; - PhysicalStart =3D OldRecord->PhysicalStart; - PhysicalEnd =3D OldRecord->PhysicalStart + EfiPagesToSize (OldRecor= d->NumberOfPages); - - do { - ImageRecord =3D GetImageRecordByAddress (PhysicalStart, PhysicalEnd - = PhysicalStart); - if (ImageRecord =3D=3D NULL) { - break; - } - - SplitRecordCount +=3D (2 * ImageRecord->CodeSegmentCount + 2); - PhysicalStart =3D ImageRecord->ImageBase + ImageRecord->ImageSize; - } while ((ImageRecord !=3D NULL) && (PhysicalStart < PhysicalEnd)); - - return SplitRecordCount; -} - -/** - Split the memory map to new entries, according to one old entry, - based upon PE code section and data section. - - @param[in] OldRecord A pointer to one old memory map = entry. - @param[in, out] NewRecord A pointer to several new memory = map entries. - The caller guarantee the buffer = size be 1 + - (SplitRecordCount * DescriptorSi= ze) calculated - below. - @param[in] MaxSplitRecordCount The max number of splitted entri= es - @param[in] DescriptorSize Size, in bytes, of an individual= EFI_MEMORY_DESCRIPTOR. - - @retval 0 no entry is splitted. - @return the real number of splitted record. -**/ -STATIC -UINTN -SplitRecord ( - IN EFI_MEMORY_DESCRIPTOR *OldRecord, - IN OUT EFI_MEMORY_DESCRIPTOR *NewRecord, - IN UINTN MaxSplitRecordCount, - IN UINTN DescriptorSize - ) -{ - EFI_MEMORY_DESCRIPTOR TempRecord; - IMAGE_PROPERTIES_RECORD *ImageRecord; - IMAGE_PROPERTIES_RECORD *NewImageRecord; - UINT64 PhysicalStart; - UINT64 PhysicalEnd; - UINTN NewRecordCount; - UINTN TotalNewRecordCount; - - if (MaxSplitRecordCount =3D=3D 0) { - CopyMem (NewRecord, OldRecord, DescriptorSize); - return 0; - } - - TotalNewRecordCount =3D 0; - - // - // Override previous record - // - CopyMem (&TempRecord, OldRecord, sizeof (EFI_MEMORY_DESCRIPTOR)); - PhysicalStart =3D TempRecord.PhysicalStart; - PhysicalEnd =3D TempRecord.PhysicalStart + EfiPagesToSize (TempRecord.= NumberOfPages); - - ImageRecord =3D NULL; - do { - NewImageRecord =3D GetImageRecordByAddress (PhysicalStart, PhysicalEnd= - PhysicalStart); - if (NewImageRecord =3D=3D NULL) { - // - // No more image covered by this range, stop - // - if (PhysicalEnd > PhysicalStart) { - // - // Always create a new entry for non-PE image record - // - NewRecord->Type =3D TempRecord.Type; - NewRecord->PhysicalStart =3D TempRecord.PhysicalStart; - NewRecord->VirtualStart =3D 0; - NewRecord->NumberOfPages =3D TempRecord.NumberOfPages; - NewRecord->Attribute =3D TempRecord.Attribute; - TotalNewRecordCount++; - } - - break; - } - - ImageRecord =3D NewImageRecord; - - // - // Set new record - // - NewRecordCount =3D SetNewRecord (ImageRecord, NewRecord, &TempRe= cord, DescriptorSize); - TotalNewRecordCount +=3D NewRecordCount; - NewRecord =3D (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)NewRecord = + NewRecordCount * DescriptorSize); - - // - // Update PhysicalStart, in order to exclude the image buffer already = splitted. - // - PhysicalStart =3D ImageRecord->ImageBase + ImageRecord->Ima= geSize; - TempRecord.PhysicalStart =3D PhysicalStart; - TempRecord.NumberOfPages =3D EfiSizeToPages (PhysicalEnd - PhysicalSta= rt); - } while ((ImageRecord !=3D NULL) && (PhysicalStart < PhysicalEnd)); - - return TotalNewRecordCount - 1; -} - -/** - Split the original memory map, and add more entries to describe PE code = section and data section. - This function will set EfiRuntimeServicesData to be EFI_MEMORY_XP. - This function will merge entries with same attributes finally. - - NOTE: It assumes PE code/data section are page aligned. - NOTE: It assumes enough entry is prepared for new memory map. - - Split table: - +---------------+ - | Record X | - +---------------+ - | Record RtCode | - +---------------+ - | Record Y | - +---------------+ - =3D=3D> - +---------------+ - | Record X | - +---------------+ - | Record RtCode | - +---------------+ ---- - | Record RtData | | - +---------------+ | - | Record RtCode | |-> PE/COFF1 - +---------------+ | - | Record RtData | | - +---------------+ ---- - | Record RtCode | - +---------------+ ---- - | Record RtData | | - +---------------+ | - | Record RtCode | |-> PE/COFF2 - +---------------+ | - | Record RtData | | - +---------------+ ---- - | Record RtCode | - +---------------+ - | Record Y | - +---------------+ - - @param[in, out] MemoryMapSize A pointer to the size, in bytes,= of the - MemoryMap buffer. On input, this= is the size of - old MemoryMap before split. The = actual buffer - size of MemoryMap is MemoryMapSi= ze + - (AdditionalRecordCount * Descrip= torSize) calculated - below. On output, it is the size= of new MemoryMap - after split. - @param[in, out] MemoryMap A pointer to the buffer in which= firmware places - the current memory map. - @param[in] DescriptorSize Size, in bytes, of an individual= EFI_MEMORY_DESCRIPTOR. -**/ -STATIC -VOID -SplitTable ( - IN OUT UINTN *MemoryMapSize, - IN OUT EFI_MEMORY_DESCRIPTOR *MemoryMap, - IN UINTN DescriptorSize - ) -{ - INTN IndexOld; - INTN IndexNew; - UINTN MaxSplitRecordCount; - UINTN RealSplitRecordCount; - UINTN TotalSplitRecordCount; - UINTN AdditionalRecordCount; - - AdditionalRecordCount =3D (2 * mImagePropertiesPrivateData.CodeSegmentCo= untMax + 2) * mImagePropertiesPrivateData.ImageRecordCount; - - TotalSplitRecordCount =3D 0; - // - // Let old record point to end of valid MemoryMap buffer. - // - IndexOld =3D ((*MemoryMapSize) / DescriptorSize) - 1; - // - // Let new record point to end of full MemoryMap buffer. - // - IndexNew =3D ((*MemoryMapSize) / DescriptorSize) - 1 + AdditionalRecordC= ount; - for ( ; IndexOld >=3D 0; IndexOld--) { - MaxSplitRecordCount =3D GetMaxSplitRecordCount ((EFI_MEMORY_DESCRIPTOR= *)((UINT8 *)MemoryMap + IndexOld * DescriptorSize)); - // - // Split this MemoryMap record - // - IndexNew -=3D MaxSplitRecordCount; - RealSplitRecordCount =3D SplitRecord ( - (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)MemoryMap = + IndexOld * DescriptorSize), - (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)MemoryMap = + IndexNew * DescriptorSize), - MaxSplitRecordCount, - DescriptorSize - ); - // - // Adjust IndexNew according to real split. - // - if (MaxSplitRecordCount !=3D RealSplitRecordCount) { - CopyMem ( - ((UINT8 *)MemoryMap + (IndexNew + MaxSplitRecordCount - RealSplitR= ecordCount) * DescriptorSize), - ((UINT8 *)MemoryMap + IndexNew * DescriptorSize), - (RealSplitRecordCount + 1) * DescriptorSize - ); - } - - IndexNew =3D IndexNew + MaxSplitRecordCount - RealSplitR= ecordCount; - TotalSplitRecordCount +=3D RealSplitRecordCount; - IndexNew--; - } - - // - // Move all records to the beginning. - // - CopyMem ( - MemoryMap, - (UINT8 *)MemoryMap + (AdditionalRecordCount - TotalSplitRecordCount) *= DescriptorSize, - (*MemoryMapSize) + TotalSplitRecordCount * DescriptorSize - ); - - *MemoryMapSize =3D (*MemoryMapSize) + DescriptorSize * TotalSplitRecordC= ount; - - // - // Sort from low to high (Just in case) - // - SortMemoryMap (MemoryMap, *MemoryMapSize, DescriptorSize); - - // - // Set RuntimeData to XP - // - EnforceMemoryMapAttribute (MemoryMap, *MemoryMapSize, DescriptorSize); - - // - // Merge same type to save entry size - // - MergeMemoryMap (MemoryMap, MemoryMapSize, DescriptorSize); - - return; -} - /** This function for GetMemoryMap() with memory attributes table. =20 @@ -729,7 +212,7 @@ SmmCoreGetMemoryMapMemoryAttributesTable ( return EFI_INVALID_PARAMETER; } =20 - AdditionalRecordCount =3D (2 * mImagePropertiesPrivateData.CodeSegmentCo= untMax + 2) * mImagePropertiesPrivateData.ImageRecordCount; + AdditionalRecordCount =3D (2 * mImagePropertiesPrivateData.CodeSegmentCo= untMax + 3) * mImagePropertiesPrivateData.ImageRecordCount; =20 OldMemoryMapSize =3D *MemoryMapSize; Status =3D SmmCoreGetMemoryMap (MemoryMapSize, MemoryMap, MapK= ey, DescriptorSize, DescriptorVersion); @@ -747,7 +230,17 @@ SmmCoreGetMemoryMapMemoryAttributesTable ( // Split PE code/data // ASSERT (MemoryMap !=3D NULL); - SplitTable (MemoryMapSize, MemoryMap, *DescriptorSize); + SplitTable (MemoryMapSize, MemoryMap, *DescriptorSize, &mImageProper= tiesPrivateData.ImageRecordList, AdditionalRecordCount); + + // + // Set RuntimeData to XP + // + EnforceMemoryMapAttribute (MemoryMap, *MemoryMapSize, *DescriptorSiz= e); + + // + // Merge same type to save entry size + // + MergeMemoryMap (MemoryMap, MemoryMapSize, *DescriptorSize); } } =20 @@ -777,250 +270,6 @@ SetMemoryAttributesTableSectionAlignment ( } } =20 -/** - Swap two code sections in image record. - - @param[in] FirstImageRecordCodeSection first code section in image r= ecord - @param[in] SecondImageRecordCodeSection second code section in image = record -**/ -STATIC -VOID -SwapImageRecordCodeSection ( - IN IMAGE_PROPERTIES_RECORD_CODE_SECTION *FirstImageRecordCodeSection, - IN IMAGE_PROPERTIES_RECORD_CODE_SECTION *SecondImageRecordCodeSection - ) -{ - IMAGE_PROPERTIES_RECORD_CODE_SECTION TempImageRecordCodeSection; - - TempImageRecordCodeSection.CodeSegmentBase =3D FirstImageRecordCodeSecti= on->CodeSegmentBase; - TempImageRecordCodeSection.CodeSegmentSize =3D FirstImageRecordCodeSecti= on->CodeSegmentSize; - - FirstImageRecordCodeSection->CodeSegmentBase =3D SecondImageRecordCodeSe= ction->CodeSegmentBase; - FirstImageRecordCodeSection->CodeSegmentSize =3D SecondImageRecordCodeSe= ction->CodeSegmentSize; - - SecondImageRecordCodeSection->CodeSegmentBase =3D TempImageRecordCodeSec= tion.CodeSegmentBase; - SecondImageRecordCodeSection->CodeSegmentSize =3D TempImageRecordCodeSec= tion.CodeSegmentSize; -} - -/** - Sort code section in image record, based upon CodeSegmentBase from low t= o high. - - @param[in] ImageRecord image record to be sorted -**/ -STATIC -VOID -SortImageRecordCodeSection ( - IN IMAGE_PROPERTIES_RECORD *ImageRecord - ) -{ - IMAGE_PROPERTIES_RECORD_CODE_SECTION *ImageRecordCodeSection; - IMAGE_PROPERTIES_RECORD_CODE_SECTION *NextImageRecordCodeSection; - LIST_ENTRY *ImageRecordCodeSectionLink; - LIST_ENTRY *NextImageRecordCodeSectionLink; - LIST_ENTRY *ImageRecordCodeSectionEndLink; - LIST_ENTRY *ImageRecordCodeSectionList; - - ImageRecordCodeSectionList =3D &ImageRecord->CodeSegmentList; - - ImageRecordCodeSectionLink =3D ImageRecordCodeSectionList->ForwardLi= nk; - NextImageRecordCodeSectionLink =3D ImageRecordCodeSectionLink->ForwardLi= nk; - ImageRecordCodeSectionEndLink =3D ImageRecordCodeSectionList; - while (ImageRecordCodeSectionLink !=3D ImageRecordCodeSectionEndLink) { - ImageRecordCodeSection =3D CR ( - ImageRecordCodeSectionLink, - IMAGE_PROPERTIES_RECORD_CODE_SECTION, - Link, - IMAGE_PROPERTIES_RECORD_CODE_SECTION_SIGNAT= URE - ); - while (NextImageRecordCodeSectionLink !=3D ImageRecordCodeSectionEndLi= nk) { - NextImageRecordCodeSection =3D CR ( - NextImageRecordCodeSectionLink, - IMAGE_PROPERTIES_RECORD_CODE_SECTION, - Link, - IMAGE_PROPERTIES_RECORD_CODE_SECTION_= SIGNATURE - ); - if (ImageRecordCodeSection->CodeSegmentBase > NextImageRecordCodeSec= tion->CodeSegmentBase) { - SwapImageRecordCodeSection (ImageRecordCodeSection, NextImageRecor= dCodeSection); - } - - NextImageRecordCodeSectionLink =3D NextImageRecordCodeSectionLink->F= orwardLink; - } - - ImageRecordCodeSectionLink =3D ImageRecordCodeSectionLink->Forward= Link; - NextImageRecordCodeSectionLink =3D ImageRecordCodeSectionLink->Forward= Link; - } -} - -/** - Check if code section in image record is valid. - - @param[in] ImageRecord image record to be checked - - @retval TRUE image record is valid - @retval FALSE image record is invalid -**/ -STATIC -BOOLEAN -IsImageRecordCodeSectionValid ( - IN IMAGE_PROPERTIES_RECORD *ImageRecord - ) -{ - IMAGE_PROPERTIES_RECORD_CODE_SECTION *ImageRecordCodeSection; - IMAGE_PROPERTIES_RECORD_CODE_SECTION *LastImageRecordCodeSection; - LIST_ENTRY *ImageRecordCodeSectionLink; - LIST_ENTRY *ImageRecordCodeSectionEndLink; - LIST_ENTRY *ImageRecordCodeSectionList; - - DEBUG ((DEBUG_VERBOSE, "SMM ImageCode SegmentCount - 0x%x\n", ImageRecor= d->CodeSegmentCount)); - - ImageRecordCodeSectionList =3D &ImageRecord->CodeSegmentList; - - ImageRecordCodeSectionLink =3D ImageRecordCodeSectionList->ForwardLin= k; - ImageRecordCodeSectionEndLink =3D ImageRecordCodeSectionList; - LastImageRecordCodeSection =3D NULL; - while (ImageRecordCodeSectionLink !=3D ImageRecordCodeSectionEndLink) { - ImageRecordCodeSection =3D CR ( - ImageRecordCodeSectionLink, - IMAGE_PROPERTIES_RECORD_CODE_SECTION, - Link, - IMAGE_PROPERTIES_RECORD_CODE_SECTION_SIGNAT= URE - ); - if (ImageRecordCodeSection->CodeSegmentSize =3D=3D 0) { - return FALSE; - } - - if (ImageRecordCodeSection->CodeSegmentBase < ImageRecord->ImageBase) { - return FALSE; - } - - if (ImageRecordCodeSection->CodeSegmentBase >=3D MAX_ADDRESS - ImageRe= cordCodeSection->CodeSegmentSize) { - return FALSE; - } - - if ((ImageRecordCodeSection->CodeSegmentBase + ImageRecordCodeSection-= >CodeSegmentSize) > (ImageRecord->ImageBase + ImageRecord->ImageSize)) { - return FALSE; - } - - if (LastImageRecordCodeSection !=3D NULL) { - if ((LastImageRecordCodeSection->CodeSegmentBase + LastImageRecordCo= deSection->CodeSegmentSize) > ImageRecordCodeSection->CodeSegmentBase) { - return FALSE; - } - } - - LastImageRecordCodeSection =3D ImageRecordCodeSection; - ImageRecordCodeSectionLink =3D ImageRecordCodeSectionLink->ForwardLink; - } - - return TRUE; -} - -/** - Swap two image records. - - @param[in] FirstImageRecord first image record. - @param[in] SecondImageRecord second image record. -**/ -STATIC -VOID -SwapImageRecord ( - IN IMAGE_PROPERTIES_RECORD *FirstImageRecord, - IN IMAGE_PROPERTIES_RECORD *SecondImageRecord - ) -{ - IMAGE_PROPERTIES_RECORD TempImageRecord; - - TempImageRecord.ImageBase =3D FirstImageRecord->ImageBase; - TempImageRecord.ImageSize =3D FirstImageRecord->ImageSize; - TempImageRecord.CodeSegmentCount =3D FirstImageRecord->CodeSegmentCount; - - FirstImageRecord->ImageBase =3D SecondImageRecord->ImageBase; - FirstImageRecord->ImageSize =3D SecondImageRecord->ImageSize; - FirstImageRecord->CodeSegmentCount =3D SecondImageRecord->CodeSegmentCou= nt; - - SecondImageRecord->ImageBase =3D TempImageRecord.ImageBase; - SecondImageRecord->ImageSize =3D TempImageRecord.ImageSize; - SecondImageRecord->CodeSegmentCount =3D TempImageRecord.CodeSegmentCount; - - SwapListEntries (&FirstImageRecord->CodeSegmentList, &SecondImageRecord-= >CodeSegmentList); -} - -/** - Sort image record based upon the ImageBase from low to high. -**/ -STATIC -VOID -SortImageRecord ( - VOID - ) -{ - IMAGE_PROPERTIES_RECORD *ImageRecord; - IMAGE_PROPERTIES_RECORD *NextImageRecord; - LIST_ENTRY *ImageRecordLink; - LIST_ENTRY *NextImageRecordLink; - LIST_ENTRY *ImageRecordEndLink; - LIST_ENTRY *ImageRecordList; - - ImageRecordList =3D &mImagePropertiesPrivateData.ImageRecordList; - - ImageRecordLink =3D ImageRecordList->ForwardLink; - NextImageRecordLink =3D ImageRecordLink->ForwardLink; - ImageRecordEndLink =3D ImageRecordList; - while (ImageRecordLink !=3D ImageRecordEndLink) { - ImageRecord =3D CR ( - ImageRecordLink, - IMAGE_PROPERTIES_RECORD, - Link, - IMAGE_PROPERTIES_RECORD_SIGNATURE - ); - while (NextImageRecordLink !=3D ImageRecordEndLink) { - NextImageRecord =3D CR ( - NextImageRecordLink, - IMAGE_PROPERTIES_RECORD, - Link, - IMAGE_PROPERTIES_RECORD_SIGNATURE - ); - if (ImageRecord->ImageBase > NextImageRecord->ImageBase) { - SwapImageRecord (ImageRecord, NextImageRecord); - } - - NextImageRecordLink =3D NextImageRecordLink->ForwardLink; - } - - ImageRecordLink =3D ImageRecordLink->ForwardLink; - NextImageRecordLink =3D ImageRecordLink->ForwardLink; - } -} - -/** - Dump image record. -**/ -STATIC -VOID -DumpImageRecord ( - VOID - ) -{ - IMAGE_PROPERTIES_RECORD *ImageRecord; - LIST_ENTRY *ImageRecordLink; - LIST_ENTRY *ImageRecordList; - UINTN Index; - - ImageRecordList =3D &mImagePropertiesPrivateData.ImageRecordList; - - for (ImageRecordLink =3D ImageRecordList->ForwardLink, Index =3D 0; - ImageRecordLink !=3D ImageRecordList; - ImageRecordLink =3D ImageRecordLink->ForwardLink, Index++) - { - ImageRecord =3D CR ( - ImageRecordLink, - IMAGE_PROPERTIES_RECORD, - Link, - IMAGE_PROPERTIES_RECORD_SIGNATURE - ); - DEBUG ((DEBUG_VERBOSE, "SMM Image[%d]: 0x%016lx - 0x%016lx\n", Index,= ImageRecord->ImageBase, ImageRecord->ImageSize)); - } -} - /** Insert image record. =20 @@ -1059,7 +308,7 @@ SmmInsertImageRecord ( // Step 1: record whole region // ImageRecord->ImageBase =3D DriverEntry->ImageBuffer; - ImageRecord->ImageSize =3D EfiPagesToSize (DriverEntry->NumberOfPage); + ImageRecord->ImageSize =3D LShiftU64 (DriverEntry->NumberOfPage, EFI_PAG= E_SHIFT); =20 ImageAddress =3D (VOID *)(UINTN)DriverEntry->ImageBuffer; =20 @@ -1193,7 +442,7 @@ SmmInsertImageRecord ( mImagePropertiesPrivateData.CodeSegmentCountMax =3D ImageRecord->CodeS= egmentCount; } =20 - SortImageRecord (); + SortImageRecord (&mImagePropertiesPrivateData.ImageRecordList); =20 Finish: return; @@ -1361,7 +610,7 @@ SmmInstallMemoryAttributesTable ( =20 DEBUG ((DEBUG_VERBOSE, "SMM Total Image Count - 0x%x\n", mImagePropertie= sPrivateData.ImageRecordCount)); DEBUG ((DEBUG_VERBOSE, "SMM Dump ImageRecord:\n")); - DumpImageRecord (); + DumpImageRecord (&mImagePropertiesPrivateData.ImageRecordList); =20 PublishMemoryAttributesTable (); =20 diff --git a/MdeModulePkg/Core/Dxe/DxeMain.h b/MdeModulePkg/Core/Dxe/DxeMai= n.h index 43daa037be44..86a7be2f5188 100644 --- a/MdeModulePkg/Core/Dxe/DxeMain.h +++ b/MdeModulePkg/Core/Dxe/DxeMain.h @@ -228,26 +228,6 @@ typedef struct { #define LOADED_IMAGE_PRIVATE_DATA_FROM_THIS(a) \ CR(a, LOADED_IMAGE_PRIVATE_DATA, Info, LOADED_IMAGE_PRIVATE_DATA= _SIGNATURE) =20 -#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; - // // DXE Core Global Variables // diff --git a/MdeModulePkg/Core/Dxe/DxeMain.inf b/MdeModulePkg/Core/Dxe/DxeM= ain.inf index 35d5bf0dee6f..c0aa37d118c5 100644 --- a/MdeModulePkg/Core/Dxe/DxeMain.inf +++ b/MdeModulePkg/Core/Dxe/DxeMain.inf @@ -94,6 +94,7 @@ [LibraryClasses] DebugAgentLib CpuExceptionHandlerLib PcdLib + ImagePropertiesRecordLib =20 [Guids] gEfiEventMemoryMapChangeGuid ## PRODUCES ##= Event diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf b/MdeModulePkg/Core/= PiSmmCore/PiSmmCore.inf index 3df44b38f13c..75a5934f0c1d 100644 --- a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf +++ b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf @@ -61,6 +61,7 @@ [LibraryClasses] HobLib SmmMemLib SafeIntLib + ImagePropertiesRecordLib =20 [Protocols] gEfiDxeSmmReadyToLockProtocolGuid ## UNDEFINED # SmiHandlerR= egister --=20 2.41.0.windows.2 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#107075): https://edk2.groups.io/g/devel/message/107075 Mute This Topic: https://groups.io/mt/100246944/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-