From nobody Mon May 13 00:36:34 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+107198+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+107198+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1690248928; cv=none; d=zohomail.com; s=zohoarc; b=fxUYGBZDS7LmMdV9PN1JU9s1vWaWR3eZyS/Ymt5cQXPWekLCOJQL4RudM5JHAs3NB9mle0B3HDlRRkPF8+8MKM8KwpyhiU9aRMOdaciMgiTo+gPODbeNlBjbzcjsqohkQ7bLQqyOX77Edile9bKuK37D1N/emHaYMIEHksNK78Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690248928; 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=Qlx3tMc+EN3aAzkiUSg5jV1QK/IevIKWwKJpXtRMtAc=; b=E6QpwZxA86WIy2kXDrJTEbgD3OZ7bf5NHKGljcbFPuWSJnzGbWHxaRuzdYdYRWXn1NVsqPfC366KBioW6qhDByRDk1rMkD4lvApAib0iAGhr52Q/lgSsXmlq28jmVhdWTgfIefr2LZOx/TsPEF3qnIdjjJ3BaYm9bVW10ks2pxc= 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+107198+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1690248928261315.3618438069286; Mon, 24 Jul 2023 18:35:28 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=6ehc5RuZGI3y7oqG/lx0poNaqUxSMwGB7yGQTaJjvbI=; 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-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1690248928; v=1; b=pKfGapZUcrwBChzdx1ysLxMgvCGsc02lsU4X8Y6nILiyWIGViWOqxjJsdPjhikRAnKppbhdt yeZQAnZmLl3/FpOniVHZ65WQs7BH6ke+VHYsY/s7SzUZ9e2Dj7AdrHWaOjbz9Yvf2KrncIGz2su pezXUZEWxkF+vWNS0VjOeuh4= X-Received: by 127.0.0.2 with SMTP id rtxlYY1788612x6PmweNME7Q; Mon, 24 Jul 2023 18:35:28 -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.web10.11283.1690248927380956588 for ; Mon, 24 Jul 2023 18:35:27 -0700 X-Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-1b9c368f4b5so39066785ad.0 for ; Mon, 24 Jul 2023 18:35:27 -0700 (PDT) X-Gm-Message-State: p4MxCJ2xyYlcJKrRFN1AoEqix1787277AA= X-Google-Smtp-Source: APBJJlHxlixOPZOGP4U5z6bGH153cY0fs6ytkR72/T6b6TU7SCz95DGOX8ixY1jrtyIVPTisYlXgLg== X-Received: by 2002:a17:902:f687:b0:1b4:5699:aac1 with SMTP id l7-20020a170902f68700b001b45699aac1mr1228820plg.12.1690248925804; Mon, 24 Jul 2023 18:35:25 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.230.135]) by smtp.gmail.com with ESMTPSA id f8-20020a170902ce8800b001b893b689a0sm9630868plg.84.2023.07.24.18.35.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jul 2023 18:35:25 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Jian J Wang , Liming Gao , Dandan Bi Subject: [edk2-devel] [PATCH v3 01/14] MdeModulePkg: Add ImagePropertiesRecordLib Date: Mon, 24 Jul 2023 18:35:00 -0700 Message-ID: <20230725013513.1403-2-t@taylorbeebe.com> In-Reply-To: <20230725013513.1403-1-t@taylorbeebe.com> References: <20230725013513.1403-1-t@taylorbeebe.com> MIME-Version: 1.0 Precedence: Bulk 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 List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1690248930467100003 Content-Type: text/plain; charset="utf-8" Create a library for manipulating image properties records. The library is currently blank and will be filled in a future patch to help with reviewer readability. Signed-off-by: Taylor Beebe Cc: Jian J Wang Cc: Liming Gao Cc: Dandan Bi --- MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.c = | 9 +++++++ MdeModulePkg/Include/Library/ImagePropertiesRecordLib.h = | 14 +++++++++++ MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.inf= | 25 ++++++++++++++++++++ MdeModulePkg/MdeModulePkg.dec = | 5 ++++ MdeModulePkg/MdeModulePkg.dsc = | 2 ++ 5 files changed, 55 insertions(+) diff --git a/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesR= ecordLib.c b/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesR= ecordLib.c new file mode 100644 index 000000000000..df7c54ebb793 --- /dev/null +++ b/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLi= b.c @@ -0,0 +1,9 @@ +/** @file + + Provides definitions and functionality for manipulating IMAGE_PROPERTIES= _RECORD. + + Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.
+ Copyright (c) Microsoft Corporation. + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ diff --git a/MdeModulePkg/Include/Library/ImagePropertiesRecordLib.h b/MdeM= odulePkg/Include/Library/ImagePropertiesRecordLib.h new file mode 100644 index 000000000000..728008a2e5bb --- /dev/null +++ b/MdeModulePkg/Include/Library/ImagePropertiesRecordLib.h @@ -0,0 +1,14 @@ +/** @file + + Provides definitions and functionality for manipulating IMAGE_PROPERTIES= _RECORD. + + Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.
+ Copyright (c) Microsoft Corporation. + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef IMAGE_PROPERTIES_RECORD_SUPPORT_LIB_H_ +#define IMAGE_PROPERTIES_RECORD_SUPPORT_LIB_H_ + +#endif diff --git a/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesR= ecordLib.inf b/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertie= sRecordLib.inf new file mode 100644 index 000000000000..b7e493056889 --- /dev/null +++ b/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLi= b.inf @@ -0,0 +1,25 @@ +## @file +# Provides definitions and functionality for manipulating +# IMAGE_PROPERTIES_RECORD. +# +# Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.
+# Copyright (c) Microsoft Corporation. +# 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 + + +[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 (#107198): https://edk2.groups.io/g/devel/message/107198 Mute This Topic: https://groups.io/mt/100342597/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 Mon May 13 00:36:34 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+107199+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+107199+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1690248928; cv=none; d=zohomail.com; s=zohoarc; b=Bla/HBr61GYYwtoIiCLmUjNphbB0PUHrw7dwZYf5GEUtDcSSLfrBmKIk+oeBOSE0q2nrCFKYunRl/In163x5inxW5k8OdL5R9G5rd5izff80TF2V5Pw0oRsGS1qB+ltVZIh/mu8QdG69MLIE51OQiIDOgIBtOX69Z+E+Ml0Wttk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690248928; 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=9RFGXHi/sXf3uVACmaugbhNI5MP/H3T1d8KRrs4OTBg=; b=l6Z2El/oPi0Y3juH1nygBD9t80y21XyAGD9RAYDn59Ec3SGK0spRTXQEnlRjfm/Zuvo/Vffy4FG1YeSK4vD+cZteZOmTta/ExLlNdLQe6XbEqQn4+9XYB6uuRruFcEun1CtAx64avMhiKuJx2KkW/GA6bfQS7jR1IqZU5epq89c= 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+107199+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1690248928640647.0485896469547; Mon, 24 Jul 2023 18:35:28 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=rZaWyiR4m15In56eHp/bX3kyj3YWNrs+PwQYLWlnIks=; 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-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1690248928; v=1; b=CYKnYXz21LO1fjMn/9ubr9y8OZuOqbObk/+sJQovrX3LPvKAGF3tuKuCjszfMNP6w9glvfSP DnBhTHT5yRYMyBMk89UCd3/1rHyMORq2IjzGyYRvK5pEh8oXeMBCCNEwy5kt6tcByo2ABVdFt9C xQ2QeZn3yGXoAgJzK2px0rXo= X-Received: by 127.0.0.2 with SMTP id UG3oYY1788612xGr2hYCOkSp; Mon, 24 Jul 2023 18:35:28 -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.web11.11420.1690248927637611264 for ; Mon, 24 Jul 2023 18:35:27 -0700 X-Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-1b9ecf0cb4cso28216245ad.2 for ; Mon, 24 Jul 2023 18:35:27 -0700 (PDT) X-Gm-Message-State: G2Drxp3I38dTmyYsLMQtXTOVx1787277AA= X-Google-Smtp-Source: APBJJlH73tCNH96tOgsVUkDTV/GF7xQhJlljDU1UZu6aapupxUYaDWX5ThG4wIeh/oxiqKvp9lmxQw== X-Received: by 2002:a17:902:b083:b0:1b1:9d43:ad4c with SMTP id p3-20020a170902b08300b001b19d43ad4cmr8772533plr.40.1690248926862; Mon, 24 Jul 2023 18:35:26 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.230.135]) by smtp.gmail.com with ESMTPSA id f8-20020a170902ce8800b001b893b689a0sm9630868plg.84.2023.07.24.18.35.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jul 2023 18:35:26 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Leif Lindholm , Sami Mujawar , Gerd Hoffmann Subject: [edk2-devel] [PATCH v3 02/14] ArmVirtPkg: Add ImagePropertiesRecordLib Instance Date: Mon, 24 Jul 2023 18:35:01 -0700 Message-ID: <20230725013513.1403-3-t@taylorbeebe.com> In-Reply-To: <20230725013513.1403-1-t@taylorbeebe.com> References: <20230725013513.1403-1-t@taylorbeebe.com> MIME-Version: 1.0 Precedence: Bulk 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 List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1690248930439100002 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 (#107199): https://edk2.groups.io/g/devel/message/107199 Mute This Topic: https://groups.io/mt/100342598/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 Mon May 13 00:36:34 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+107200+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+107200+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1690248929; cv=none; d=zohomail.com; s=zohoarc; b=Dqcd98WivEUpqX1cgXMqsZyfmd2wwZrER0V2YfRYbzidqRHsTuCrBj75YoUdqEVXJiu9pq7jj561TQrGQJKGPeAjvofe1u5NZWFfKq67WkrmkICe8R8HEI+kPTThDthUYcvsUeLaB3jHg0LzwYI94SIu3ZKhjL4IPPGB4uinHC8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690248929; 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=4+t681iPdNf7Kn8GcKRThTXpK4cVJGZ03jY8rrNRk94=; b=bbvTYtifoaCl3RbhkXPUpTXOh8gP3qk1kjQcc2B+DyDrMjE6lf6ZNS/pTcZFAOpSxY6Sikb4kPcmwKsFxla1MtciWMA9XZXNg6yN/TaOrdYuv/ZV9YsqehQPBKEZ2ZsCWZcO3Fi+rRMlwWAjewbyJqwrbteiCIg+hszWUbCEtlA= 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+107200+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1690248929276825.5881843706478; Mon, 24 Jul 2023 18:35:29 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=cRsblqxJh0m/Py9RKGvoXOyJrhLn+SlqATLyMOVnaHg=; 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-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1690248929; v=1; b=rKOpHocipoOD7/UWqNkm+pOrjZNG9VI1Z0tqivBcn2ksPgLO65bVuBb0d1uczZz50cnmKU/o NDyh4eyMsN4CAYMquEqwB+rZOzk/5N4Xl8v+Q8e3aEdXpwbXrYfj17qLsEFZhhjmse6GJsIQUmU 6liOSmyJGXktEFh0NqhjzMGI= X-Received: by 127.0.0.2 with SMTP id JbuzYY1788612xE2k9XKcsTD; Mon, 24 Jul 2023 18:35:29 -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.11421.1690248927965493050 for ; Mon, 24 Jul 2023 18:35:28 -0700 X-Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-1b8ad356f03so25482155ad.1 for ; Mon, 24 Jul 2023 18:35:27 -0700 (PDT) X-Gm-Message-State: snQ8AkihyZXOYKeOoPa2QG4rx1787277AA= X-Google-Smtp-Source: APBJJlFyy+dR9XNJGV6Uak0+3RcQOb9eTRH6eQ7KSJDu/UPVzEwfHyJIYKB3jv894o5Dc5ffDZOV+g== X-Received: by 2002:a17:903:11cc:b0:1ae:10bc:4ae8 with SMTP id q12-20020a17090311cc00b001ae10bc4ae8mr9002257plh.26.1690248927327; Mon, 24 Jul 2023 18:35:27 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.230.135]) by smtp.gmail.com with ESMTPSA id f8-20020a170902ce8800b001b893b689a0sm9630868plg.84.2023.07.24.18.35.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jul 2023 18:35:27 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Andrew Fish , Ray Ni Subject: [edk2-devel] [PATCH v3 03/14] EmulatorPkg: Add ImagePropertiesRecordLib Instance Date: Mon, 24 Jul 2023 18:35:02 -0700 Message-ID: <20230725013513.1403-4-t@taylorbeebe.com> In-Reply-To: <20230725013513.1403-1-t@taylorbeebe.com> References: <20230725013513.1403-1-t@taylorbeebe.com> MIME-Version: 1.0 Precedence: Bulk 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 List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1690248930426100001 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 (#107200): https://edk2.groups.io/g/devel/message/107200 Mute This Topic: https://groups.io/mt/100342599/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 Mon May 13 00:36:34 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+107201+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+107201+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1690248929; cv=none; d=zohomail.com; s=zohoarc; b=BGgfbsxgx0nY3TcqApw+sRmfURyl2vx6imFzINOzHRTLvfr3wh5EbFQw979HU1AXRyFDhE50RRNvZE0u9FHUVro8Q8tE/a48U8yR68xe2NeqgrIOiXRZeBKGMUjQDWc/fAGF5uwnA9kAZhg4JD6ecY1T2YRIRRXmTvvSSoVGKWM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690248929; 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=TjsoUvcG0JgxM6tGGCl4lOZhf/evA1qf/00+SkB9aeU=; b=Y+iavA3x3tUL0ES75LVKko2RNNsZ94ilH+6comB6AYw5HbXhjsmJ/vQeTqtePjeYxEZgi1CvCJrW9zCRXp8FwLk/7Kw7ERWLIy6mxG1/NRedDYp2w+8y6viihq3ROnSan/MRd5BdzGZrBWGr7zeuM1JxEq3MTcBuJnpbqAZOv7A= 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+107201+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1690248929792362.4924027657312; Mon, 24 Jul 2023 18:35:29 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=ZQlcpgpQK7DFPWWB7gGegMFZk2rCPifdTZsyOx7G46c=; 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-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1690248929; v=1; b=L0g5NkKe6hmGaFIAHhpqX8IJmk76kBHfPkXANFI5bUBGMUuKerPokZwH56OVJadHNTSEMfFF Lo/oElYCnfITDmVeTg78Kl1SMK4VzsGK3OB0e7n7/g5be16gOXaaJXxkUZvgW1067zDw0Hdcgiq sJmoVoTfpejJWcQwebEVr/WA= X-Received: by 127.0.0.2 with SMTP id hIqdYY1788612xiQWZEsLBJ8; Mon, 24 Jul 2023 18:35:29 -0700 X-Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by mx.groups.io with SMTP id smtpd.web10.11284.1690248928492985475 for ; Mon, 24 Jul 2023 18:35:28 -0700 X-Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-1bb893e6365so12990275ad.2 for ; Mon, 24 Jul 2023 18:35:28 -0700 (PDT) X-Gm-Message-State: H3BLpxZ2WTYAy9SfgoAPCD3cx1787277AA= X-Google-Smtp-Source: APBJJlGLgiYufQ+cIVSp2okbFibMNONIcZ//DPViEV8iFKvNjbAcTSKGMG/RI0Qns9lq1dud4DtW2Q== X-Received: by 2002:a17:902:d2c7:b0:1b5:5059:e733 with SMTP id n7-20020a170902d2c700b001b55059e733mr12023166plc.17.1690248927899; Mon, 24 Jul 2023 18:35:27 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.230.135]) by smtp.gmail.com with ESMTPSA id f8-20020a170902ce8800b001b893b689a0sm9630868plg.84.2023.07.24.18.35.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jul 2023 18:35:27 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Jiewen Yao , Jordan Justen , Gerd Hoffmann Subject: [edk2-devel] [PATCH v3 04/14] OvmfPkg: Add ImagePropertiesRecordLib Instance Date: Mon, 24 Jul 2023 18:35:03 -0700 Message-ID: <20230725013513.1403-5-t@taylorbeebe.com> In-Reply-To: <20230725013513.1403-1-t@taylorbeebe.com> References: <20230725013513.1403-1-t@taylorbeebe.com> MIME-Version: 1.0 Precedence: Bulk 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 List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1690248930471100004 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 (#107201): https://edk2.groups.io/g/devel/message/107201 Mute This Topic: https://groups.io/mt/100342600/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 Mon May 13 00:36:34 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+107202+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+107202+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1690248930; cv=none; d=zohomail.com; s=zohoarc; b=Z39rbrEGOTqceEZyJpsUzly+jU5chAVruJUToRz3rbJ5Njc+xOnjyIm2EHNV4Se9J9SOT2JHzTAgefujHnVHpMzx/rCGg1alisz6hsyERbzDWGDYEjSoc8a8rYnNuGsBkpo2TqRxRTJG7JKTlbTX1uba2a4s//ASAS3C0A0U1os= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690248930; 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=b1mi5SenSmZuMOfAdfijcYzFefwlvUncfRMd0YTcPGM=; b=EfEMXIObOZ9XVh6OBoFdTFCDMzMIvfcrLUy4yBXheEGAzMia+IMlfgNe2iglrrknv2l5iWL9uIX8MMxpqbvmY3gcUQqk9u5YcRJvblGKB630y/JNXxK2L5ngM9u1wuq7YvdpXcaIMkJn8IvEulRchgFShy2ROL2q+j9Fw+bE1bM= 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+107202+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1690248930157186.5890521429219; Mon, 24 Jul 2023 18:35:30 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=8Mu0VvqRy7n7R0VQkfsLF+Vioe3lIxtD23cNyUvF7Lc=; 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-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1690248929; v=1; b=aAiH2t9gzddJHbRAc8byO6li+kf3rW34QK27mnqrXX41fWc0ndKqNUXac5VxjhwI3Lyz3zX6 7zxZ2pdTUm6WRdu9XeNdk4StJNjyddW9TIOcbY55HqKk/Zoy006a5G1thbI3iNNfkoRkWljfEdH oUzhP+Eq50KyVdN/LdeRrHJ0= X-Received: by 127.0.0.2 with SMTP id mMjIYY1788612xRXIuRxE3LW; Mon, 24 Jul 2023 18:35:29 -0700 X-Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) by mx.groups.io with SMTP id smtpd.web11.11422.1690248929181980793 for ; Mon, 24 Jul 2023 18:35:29 -0700 X-Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-666e97fcc60so2824946b3a.3 for ; Mon, 24 Jul 2023 18:35:29 -0700 (PDT) X-Gm-Message-State: D4WhWAWigiVCD7UDbEiA7nZPx1787277AA= X-Google-Smtp-Source: APBJJlHs9qWZSTA+IjxwG78qljK6BO38KGZX1M2kxmL8rUAksEfAHhMhbPWCyu0AFx7iqJt6grG7zQ== X-Received: by 2002:a05:6a20:4c1a:b0:137:656b:1a7c with SMTP id fm26-20020a056a204c1a00b00137656b1a7cmr7999698pzb.46.1690248928396; Mon, 24 Jul 2023 18:35:28 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.230.135]) by smtp.gmail.com with ESMTPSA id f8-20020a170902ce8800b001b893b689a0sm9630868plg.84.2023.07.24.18.35.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jul 2023 18:35:28 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Guo Dong , Sean Rhodes , James Lu , Gua Guo Subject: [edk2-devel] [PATCH v3 05/14] UefiPayloadPkg: Add ImagePropertiesRecordLib Instance Date: Mon, 24 Jul 2023 18:35:04 -0700 Message-ID: <20230725013513.1403-6-t@taylorbeebe.com> In-Reply-To: <20230725013513.1403-1-t@taylorbeebe.com> References: <20230725013513.1403-1-t@taylorbeebe.com> MIME-Version: 1.0 Precedence: Bulk 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 List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1690248932715100025 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 (#107202): https://edk2.groups.io/g/devel/message/107202 Mute This Topic: https://groups.io/mt/100342601/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 Mon May 13 00:36:34 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+107203+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+107203+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1690248930; cv=none; d=zohomail.com; s=zohoarc; b=ij3B4rFoaibmvl/4DRPdZe1ak51HpjB6J6Ebvk1Bnce3L+UKWHvOT7xAertr1X0AMs3Pq7OxslQAGDJUsVySw1Z0UIQxitIhmo4Z5pb7gsBAd9/9yxtLyiboiUdIqiwYcDExQXumKQGCYUUf6IFaP+pGhsUOK/lTQUdeSi+O7Wo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690248930; 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=lnvjPkF6iRYf6aL/gArnsc94anSB0ikoxrsqm7qkSVo=; b=kNqyZRx4CDWVGd2EHz9hXclUuWI2PH7TCVPvvVENIwXp08sYeRjFWhfUbpSojgjoV8R9ytBhy78QsI5Awqafwb3HHSAnDCCDZoqaukKII7NE4XdWQ/Yb6WMBXl0zOFb4fklCrlwhq4C3B8Y5YatKcXGzx2UbGdrgAhJRokka3eo= 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+107203+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1690248930792272.13930717750293; Mon, 24 Jul 2023 18:35:30 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=kti2KiQDKghhw8mWsIwDshUAWSQLvVMSFLfO4khOLbc=; 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-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1690248930; v=1; b=FpbMDv5CaGTyxAXT34c48h/EaLg0l7k5vPr6NXGx8jTbQ1NS4pOPOcgeY8FMjjr3MpBs47le Em6+x10Jx5S+KKZXSIiXVUYSj1/sEJkuUFbZHkC7UFxqNIulquRN6re8w3a87GKEdDGimZPfH4p EOXF+HfNGk3/oyHGZz7xfVjU= X-Received: by 127.0.0.2 with SMTP id AtI4YY1788612xDIiLYm806L; Mon, 24 Jul 2023 18:35:30 -0700 X-Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) by mx.groups.io with SMTP id smtpd.web10.11287.1690248929745816556 for ; Mon, 24 Jul 2023 18:35:29 -0700 X-Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-1bb8a89b975so11209205ad.1 for ; Mon, 24 Jul 2023 18:35:29 -0700 (PDT) X-Gm-Message-State: Y1NjodlhomKrNgO749tiDGXSx1787277AA= X-Google-Smtp-Source: APBJJlGutSGlHy7kIIXoZZoXNeUIPktWLTWgQ3tqJA66Z1NqMJFNciTiZOHir0WG7ERWkDzEu8U6GQ== X-Received: by 2002:a17:903:2282:b0:1b8:897a:b3be with SMTP id b2-20020a170903228200b001b8897ab3bemr10899686plh.1.1690248928972; Mon, 24 Jul 2023 18:35:28 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.230.135]) by smtp.gmail.com with ESMTPSA id f8-20020a170902ce8800b001b893b689a0sm9630868plg.84.2023.07.24.18.35.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jul 2023 18:35:28 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Jian J Wang , Liming Gao , Dandan Bi Subject: [edk2-devel] [PATCH v3 06/14] MdeModulePkg: Update MemoryAttributesTable.c to Reduce Global Variable Use Date: Mon, 24 Jul 2023 18:35:05 -0700 Message-ID: <20230725013513.1403-7-t@taylorbeebe.com> In-Reply-To: <20230725013513.1403-1-t@taylorbeebe.com> References: <20230725013513.1403-1-t@taylorbeebe.com> MIME-Version: 1.0 Precedence: Bulk 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 List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1690248932750100026 Content-Type: text/plain; charset="utf-8" This patch updates MemoryAttributesTable.c to reduce reliance on global variables and allow some logic to move to a library. Signed-off-by: Taylor Beebe Cc: Jian J Wang Cc: Liming Gao Cc: Dandan Bi --- MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c | 102 +++++++++++------= --- 1 file changed, 54 insertions(+), 48 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c b/MdeModule= Pkg/Core/Dxe/Misc/MemoryAttributesTable.c index fd127ee167e1..64b0aa1ff5e5 100644 --- a/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c +++ b/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c @@ -541,8 +541,9 @@ EnforceMemoryMapAttribute ( /** Return the first image record, whose [ImageBase, ImageSize] covered by [= Buffer, Length]. =20 - @param Buffer Start Address - @param Length Address length + @param Buffer Start Address + @param Length Address length + @param ImageRecordList Image record list =20 @return first image record covered by [buffer, length] **/ @@ -550,14 +551,12 @@ STATIC IMAGE_PROPERTIES_RECORD * GetImageRecordByAddress ( IN EFI_PHYSICAL_ADDRESS Buffer, - IN UINT64 Length + IN UINT64 Length, + IN LIST_ENTRY *ImageRecordList ) { IMAGE_PROPERTIES_RECORD *ImageRecord; LIST_ENTRY *ImageRecordLink; - LIST_ENTRY *ImageRecordList; - - ImageRecordList =3D &mImagePropertiesPrivateData.ImageRecordList; =20 for (ImageRecordLink =3D ImageRecordList->ForwardLink; ImageRecordLink !=3D ImageRecordList; @@ -692,7 +691,8 @@ SetNewRecord ( STATIC UINTN GetMaxSplitRecordCount ( - IN EFI_MEMORY_DESCRIPTOR *OldRecord + IN EFI_MEMORY_DESCRIPTOR *OldRecord, + IN LIST_ENTRY *ImageRecordList ) { IMAGE_PROPERTIES_RECORD *ImageRecord; @@ -705,7 +705,7 @@ GetMaxSplitRecordCount ( PhysicalEnd =3D OldRecord->PhysicalStart + EfiPagesToSize (OldRecor= d->NumberOfPages); =20 do { - ImageRecord =3D GetImageRecordByAddress (PhysicalStart, PhysicalEnd - = PhysicalStart); + ImageRecord =3D GetImageRecordByAddress (PhysicalStart, PhysicalEnd - = PhysicalStart, ImageRecordList); if (ImageRecord =3D=3D NULL) { break; } @@ -725,13 +725,16 @@ GetMaxSplitRecordCount ( Split the memory map to new entries, according to one old entry, based upon PE code section and data section. =20 - @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. + @param OldRecord A pointer to one old memory map entr= y. + @param NewRecord A pointer to several new memory map = entries. + The caller gurantee the buffer size = be 1 + + (SplitRecordCount * DescriptorSize) = calculated + below. + @param MaxSplitRecordCount The max number of splitted entries + @param DescriptorSize Size, in bytes, of an individual EFI= _MEMORY_DESCRIPTOR. + @param ImageRecordList A list of IMAGE_PROPERTIES_RECORD en= tries used when searching + for an image record contained by the= memory range described in + the existing EFI memory map descript= or OldRecord =20 @retval 0 no entry is splitted. @return the real number of splitted record. @@ -742,7 +745,8 @@ SplitRecord ( IN EFI_MEMORY_DESCRIPTOR *OldRecord, IN OUT EFI_MEMORY_DESCRIPTOR *NewRecord, IN UINTN MaxSplitRecordCount, - IN UINTN DescriptorSize + IN UINTN DescriptorSize, + IN LIST_ENTRY *ImageRecordList ) { EFI_MEMORY_DESCRIPTOR TempRecord; @@ -770,7 +774,7 @@ SplitRecord ( =20 ImageRecord =3D NULL; do { - NewImageRecord =3D GetImageRecordByAddress (PhysicalStart, PhysicalEnd= - PhysicalStart); + NewImageRecord =3D GetImageRecordByAddress (PhysicalStart, PhysicalEnd= - PhysicalStart, ImageRecordList); if (NewImageRecord =3D=3D NULL) { // // No more image covered by this range, stop @@ -867,23 +871,29 @@ SplitRecord ( | Record Y | +---------------+ =20 - @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. + @param 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 MemoryMap A pointer to the buffer in which= firmware places + the current memory map. + @param DescriptorSize Size, in bytes, of an individual= EFI_MEMORY_DESCRIPTOR. + @param ImageRecordList A list of IMAGE_PROPERTIES_RECOR= D entries used when searching + for an image record contained by= the memory range described in + EFI memory map descriptors. + @param NumberOfAdditionalDescriptors The number of unused descriptors= at the end of the input MemoryMap. **/ STATIC VOID SplitTable ( IN OUT UINTN *MemoryMapSize, IN OUT EFI_MEMORY_DESCRIPTOR *MemoryMap, - IN UINTN DescriptorSize + IN UINTN DescriptorSize, + IN LIST_ENTRY *ImageRecordList, + IN UINTN NumberOfAdditionalDescriptors ) { INTN IndexOld; @@ -891,9 +901,6 @@ SplitTable ( UINTN MaxSplitRecordCount; UINTN RealSplitRecordCount; UINTN TotalSplitRecordCount; - UINTN AdditionalRecordCount; - - AdditionalRecordCount =3D (2 * mImagePropertiesPrivateData.CodeSegmentCo= untMax + 1) * mImagePropertiesPrivateData.ImageRecordCount; =20 TotalSplitRecordCount =3D 0; // @@ -903,9 +910,9 @@ SplitTable ( // // Let new record point to end of full MemoryMap buffer. // - IndexNew =3D ((*MemoryMapSize) / DescriptorSize) - 1 + AdditionalRecordC= ount; + IndexNew =3D ((*MemoryMapSize) / DescriptorSize) - 1 + NumberOfAdditiona= lDescriptors; for ( ; IndexOld >=3D 0; IndexOld--) { - MaxSplitRecordCount =3D GetMaxSplitRecordCount ((EFI_MEMORY_DESCRIPTOR= *)((UINT8 *)MemoryMap + IndexOld * DescriptorSize)); + MaxSplitRecordCount =3D GetMaxSplitRecordCount ((EFI_MEMORY_DESCRIPTOR= *)((UINT8 *)MemoryMap + IndexOld * DescriptorSize), ImageRecordList); // // Split this MemoryMap record // @@ -914,7 +921,8 @@ SplitTable ( (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)MemoryMap = + IndexOld * DescriptorSize), (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)MemoryMap = + IndexNew * DescriptorSize), MaxSplitRecordCount, - DescriptorSize + DescriptorSize, + ImageRecordList ); // // Adjust IndexNew according to real split. @@ -934,7 +942,7 @@ SplitTable ( // CopyMem ( MemoryMap, - (UINT8 *)MemoryMap + (AdditionalRecordCount - TotalSplitRecordCount) *= DescriptorSize, + (UINT8 *)MemoryMap + (NumberOfAdditionalDescriptors - TotalSplitRecord= Count) * DescriptorSize, (*MemoryMapSize) + TotalSplitRecordCount * DescriptorSize ); =20 @@ -1035,7 +1043,7 @@ CoreGetMemoryMapWithSeparatedImageSection ( // // Split PE code/data // - SplitTable (MemoryMapSize, MemoryMap, *DescriptorSize); + SplitTable (MemoryMapSize, MemoryMap, *DescriptorSize, &mImageProper= tiesPrivateData.ImageRecordList, AdditionalRecordCount); } } =20 @@ -1233,11 +1241,13 @@ SwapImageRecord ( =20 /** Sort image record based upon the ImageBase from low to high. + + @param ImageRecordList Image record list to be sorted **/ STATIC VOID SortImageRecord ( - VOID + IN LIST_ENTRY *ImageRecordList ) { IMAGE_PROPERTIES_RECORD *ImageRecord; @@ -1245,9 +1255,6 @@ SortImageRecord ( LIST_ENTRY *ImageRecordLink; LIST_ENTRY *NextImageRecordLink; LIST_ENTRY *ImageRecordEndLink; - LIST_ENTRY *ImageRecordList; - - ImageRecordList =3D &mImagePropertiesPrivateData.ImageRecordList; =20 ImageRecordLink =3D ImageRecordList->ForwardLink; NextImageRecordLink =3D ImageRecordLink->ForwardLink; @@ -1456,7 +1463,7 @@ InsertImageRecord ( mImagePropertiesPrivateData.CodeSegmentCountMax =3D ImageRecord->CodeS= egmentCount; } =20 - SortImageRecord (); + SortImageRecord (&mImagePropertiesPrivateData.ImageRecordList); =20 Finish: return; @@ -1465,8 +1472,9 @@ Finish: /** Find image record according to image base and size. =20 - @param ImageBase Base of PE image - @param ImageSize Size of PE image + @param ImageBase Base of PE image + @param ImageSize Size of PE image + @param ImageRecordList Image record list to be searched =20 @return image record **/ @@ -1474,14 +1482,12 @@ STATIC IMAGE_PROPERTIES_RECORD * FindImageRecord ( IN EFI_PHYSICAL_ADDRESS ImageBase, - IN UINT64 ImageSize + IN UINT64 ImageSize, + IN LIST_ENTRY *ImageRecordList ) { IMAGE_PROPERTIES_RECORD *ImageRecord; LIST_ENTRY *ImageRecordLink; - LIST_ENTRY *ImageRecordList; - - ImageRecordList =3D &mImagePropertiesPrivateData.ImageRecordList; =20 for (ImageRecordLink =3D ImageRecordList->ForwardLink; ImageRecordLink !=3D ImageRecordList; @@ -1526,7 +1532,7 @@ RemoveImageRecord ( return; } =20 - ImageRecord =3D FindImageRecord ((EFI_PHYSICAL_ADDRESS)(UINTN)RuntimeIma= ge->ImageBase, RuntimeImage->ImageSize); + ImageRecord =3D FindImageRecord ((EFI_PHYSICAL_ADDRESS)(UINTN)RuntimeIma= ge->ImageBase, RuntimeImage->ImageSize, &mImagePropertiesPrivateData.ImageR= ecordList); if (ImageRecord =3D=3D NULL) { DEBUG ((DEBUG_ERROR, "!!!!!!!! ImageRecord not found !!!!!!!!\n")); 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 (#107203): https://edk2.groups.io/g/devel/message/107203 Mute This Topic: https://groups.io/mt/100342602/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 Mon May 13 00:36:34 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+107204+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+107204+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1690248931; cv=none; d=zohomail.com; s=zohoarc; b=X4i42FA7fwsSOo19yXNf4sRqvMl2QC+Tqrks0gziO/Zcgl2dsBmLjM0Eq3Nq6CZtfbt02QaBrjo+US8kI6vMDWoJQx9Ajd8Iyjf6KzxMxLCVinvt77L6RqSZGJiUUmKkdAjnfPCuQhA6No2g4bSi6QwJvpAxDpTGezQazv4VoyA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690248931; 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=xo+PIKFda/EXhwMMu0PCjQDsyh9ZoxQ42fG+LaB/0dM=; b=eel+iWKcTTbaunaEUUNY5kekJmonmlIiHM90g0pqsWjOEmGmg2QV9D8kC9bAbK5TMxf7Y7Og+/3ByJZ+4Vf2m8JnzqAbKYsM5m7BfeI1U2niocMFWgTDqxQjGNHFHFkObkX5Mb/vqMBp8C9yMvopkxLOtISk/UrP1hmjMIXWs4M= 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+107204+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1690248931685795.5387753703244; Mon, 24 Jul 2023 18:35:31 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=1OW4idgmf5S2l6kSGPa2zeZ9HGhaeIDPemMgiKIVa6g=; 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-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1690248931; v=1; b=uj0CYOL3X+4144A6fXMTed4DwdHH9EOWDU25AFH6QxhliYrCXfTSSNlB2dWXlnfz+TX/+wTL e+3MvBvEGjrHacD5TdfcNGV06zcp6zgVpeCMaUHopoIv73a0SvwbJqu65/BOwevujrkMXz2bJEd hlK5tKzk9Lpg6uaX0X7VsW40= X-Received: by 127.0.0.2 with SMTP id mJZjYY1788612xzB90i5zOIQ; Mon, 24 Jul 2023 18:35:31 -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.web10.11288.1690248930591987479 for ; Mon, 24 Jul 2023 18:35:30 -0700 X-Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-1bb81809ca8so22229545ad.3 for ; Mon, 24 Jul 2023 18:35:30 -0700 (PDT) X-Gm-Message-State: PVPlGh8LH1vknxpImiwu2OJRx1787277AA= X-Google-Smtp-Source: APBJJlGCod26pgalK2HKrJ17g+OedZxbizaGYCyHF8+oBelJQUxGro53l5tpvhOap6a5mMWZVTHTwQ== X-Received: by 2002:a17:902:988b:b0:1b2:fa8:d9c9 with SMTP id s11-20020a170902988b00b001b20fa8d9c9mr10942223plp.49.1690248929729; Mon, 24 Jul 2023 18:35:29 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.230.135]) by smtp.gmail.com with ESMTPSA id f8-20020a170902ce8800b001b893b689a0sm9630868plg.84.2023.07.24.18.35.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jul 2023 18:35:29 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Jian J Wang , Liming Gao , Dandan Bi Subject: [edk2-devel] [PATCH v3 07/14] MdeModulePkg: Move Some DXE MAT Logic to ImagePropertiesRecordLib Date: Mon, 24 Jul 2023 18:35:06 -0700 Message-ID: <20230725013513.1403-8-t@taylorbeebe.com> In-Reply-To: <20230725013513.1403-1-t@taylorbeebe.com> References: <20230725013513.1403-1-t@taylorbeebe.com> MIME-Version: 1.0 Precedence: Bulk 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 List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1690248932515100021 Content-Type: text/plain; charset="utf-8" Move some DXE MAT logic to ImagePropertiesRecordLib to consolidate code and enable unit testability. Signed-off-by: Taylor Beebe Cc: Jian J Wang Cc: Liming Gao Cc: Dandan Bi --- MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c = | 774 +------------------- MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c = | 24 +- MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.c = | 770 +++++++++++++++++++ MdeModulePkg/Core/Dxe/DxeMain.h = | 20 - MdeModulePkg/Core/Dxe/DxeMain.inf = | 1 + MdeModulePkg/Include/Library/ImagePropertiesRecordLib.h = | 133 ++++ MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.inf= | 4 + 7 files changed, 921 insertions(+), 805 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c b/MdeModule= Pkg/Core/Dxe/Misc/MemoryAttributesTable.c index 64b0aa1ff5e5..51630f504ea1 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,434 +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 - @param ImageRecordList Image record list - - @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 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, - 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 OldRecord A pointer to one old memory map entr= y. - @param NewRecord A pointer to several new memory map = entries. - The caller gurantee the buffer size = be 1 + - (SplitRecordCount * DescriptorSize) = calculated - below. - @param MaxSplitRecordCount The max number of splitted entries - @param DescriptorSize Size, in bytes, of an individual EFI= _MEMORY_DESCRIPTOR. - @param ImageRecordList A list of IMAGE_PROPERTIES_RECORD en= tries used when searching - for an image record contained by the= memory range described in - the existing EFI memory map descript= or 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 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 MemoryMap A pointer to the buffer in which= firmware places - the current memory map. - @param DescriptorSize Size, in bytes, of an individual= EFI_MEMORY_DESCRIPTOR. - @param ImageRecordList A list of IMAGE_PROPERTIES_RECOR= D entries used when searching - for an image record contained by= the memory range described in - EFI memory map descriptors. - @param NumberOfAdditionalDescriptors The number of unused descriptors= at the end of the input MemoryMap. -**/ -STATIC -VOID -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); - - // - // 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 @@ -1044,6 +536,16 @@ CoreGetMemoryMapWithSeparatedImageSection ( // Split PE code/data // 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 @@ -1074,217 +576,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. - - @param ImageRecordList Image record list to be sorted -**/ -STATIC -VOID -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; - } -} - /** Insert image record. =20 @@ -1469,47 +760,6 @@ Finish: return; } =20 -/** - Find image record according to image base and size. - - @param ImageBase Base of PE image - @param ImageSize Size of PE image - @param ImageRecordList Image record list to be searched - - @return image record -**/ -STATIC -IMAGE_PROPERTIES_RECORD * -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; -} - /** Remove Image record. =20 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/Library/ImagePropertiesRecordLib/ImagePropertiesR= ecordLib.c b/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesR= ecordLib.c index df7c54ebb793..d942c7fef19a 100644 --- a/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLi= b.c +++ b/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLi= b.c @@ -7,3 +7,773 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ + +#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; +} + +/** + Return the first image record, whose [ImageBase, ImageSize] covered by [= Buffer, Length]. + + @param Buffer Start Address + @param Length Address length + @param ImageRecordList Image record list + + @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 OldRecord A pointer to one old memory map entry. + @param ImageRecordList A list of IMAGE_PROPERTIES_RECORD entries= used when searching + for an image record contained by the memo= ry range described in + the existing EFI memory map descriptor Ol= dRecord + + @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 OldRecord A pointer to one old memory map entr= y. + @param NewRecord A pointer to several new memory map = entries. + The caller gurantee the buffer size = be 1 + + (SplitRecordCount * DescriptorSize) = calculated + below. + @param MaxSplitRecordCount The max number of splitted entries + @param DescriptorSize Size, in bytes, of an individual EFI= _MEMORY_DESCRIPTOR. + @param ImageRecordList A list of IMAGE_PROPERTIES_RECORD en= tries used when searching + for an image record contained by the= memory range described in + the existing EFI memory map descript= or 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 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 MemoryMap A pointer to the buffer in which= firmware places + the current memory map. + @param DescriptorSize Size, in bytes, of an individual= EFI_MEMORY_DESCRIPTOR. + @param ImageRecordList A list of IMAGE_PROPERTIES_RECOR= D entries used when searching + for an image record contained by= the memory range described in + EFI memory map descriptors. + @param NumberOfAdditionalDescriptors The number of unused descriptors= 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; +} + +/** + 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 +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; + } +} + +/** + 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 image record based upon the ImageBase from low to high. + + @param ImageRecordList Image record list to be sorted +**/ +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; + } +} + +/** + Find image record according to image base and size. + + @param ImageBase Base of PE image + @param ImageSize Size of PE image + @param ImageRecordList Image record list to be searched + + @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/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/Include/Library/ImagePropertiesRecordLib.h b/MdeM= odulePkg/Include/Library/ImagePropertiesRecordLib.h index 728008a2e5bb..7321d99ef51b 100644 --- a/MdeModulePkg/Include/Library/ImagePropertiesRecordLib.h +++ b/MdeModulePkg/Include/Library/ImagePropertiesRecordLib.h @@ -11,4 +11,137 @@ #ifndef IMAGE_PROPERTIES_RECORD_SUPPORT_LIB_H_ #define IMAGE_PROPERTIES_RECORD_SUPPORT_LIB_H_ =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; + +/** + 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 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 MemoryMap A pointer to the buffer in which= firmware places + the current memory map. + @param DescriptorSize Size, in bytes, of an individual= EFI_MEMORY_DESCRIPTOR. + @param ImageRecordList A list of IMAGE_PROPERTIES_RECOR= D entries used when searching + for an image record contained by= the memory range described in + EFI memory map descriptors. + @param NumberOfAdditionalDescriptors The number of unused descriptors= 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 + ); + +/** + 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. + + @param ImageRecordList Image record list to be sorted +**/ +VOID +EFIAPI +SortImageRecord ( + IN LIST_ENTRY *ImageRecordList + ); + +/** + Find image record according to image base and size. + + @param ImageBase Base of PE image + @param ImageSize Size of PE image + @param ImageRecordList Image record list to be searched + + @return image record +**/ +IMAGE_PROPERTIES_RECORD * +EFIAPI +FindImageRecord ( + IN EFI_PHYSICAL_ADDRESS ImageBase, + IN UINT64 ImageSize, + IN LIST_ENTRY *ImageRecordList + ); + #endif diff --git a/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesR= ecordLib.inf b/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertie= sRecordLib.inf index b7e493056889..4c1466fc3336 100644 --- a/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLi= b.inf +++ b/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLi= b.inf @@ -19,6 +19,10 @@ [Defines] [Sources.common] ImagePropertiesRecordLib.c =20 +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib =20 [Packages] MdePkg/MdePkg.dec --=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 (#107204): https://edk2.groups.io/g/devel/message/107204 Mute This Topic: https://groups.io/mt/100342603/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 Mon May 13 00:36:34 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+107205+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+107205+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1690248932; cv=none; d=zohomail.com; s=zohoarc; b=Uj1cBt2s6aNZILOqSPe6cpvPcXaBT5x9gevkXj8C/zTN0ur1B/aMw1ul8hOBxkgdt0yA1BCSCAu7/z9k9/mSVfWtjYL22lIM+4Z6tPG/vNTBEdcCZxbITWgbJikCdGcbriLzHU/DW3YAqh8IUYyYSNPp+RItGd4MUKAvBVRteUo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690248932; 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=6LJFYLx3NVwad2Qg3zPg1XhiLcHbFSK96negQ/kx0oU=; b=Lz1RPwIPD4m+UOUsEfWVl4xHMNM8Cnm3MpOSupMoKZjoy5qw/WwgcrSfN6u58erb3FB/odDZWs0tZD5XvclVefjx9yWmdxtyN3DCSECpN8q39vrEOCh4VQuLEaO1rnIKe5JtQomqtP8Yj+D2ZJDnmRYw/HHKlDXM8JXg/JC4WVg= 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+107205+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1690248932296919.2881454765287; Mon, 24 Jul 2023 18:35:32 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=hiTeEcFaiER/Zke6VQtwPzOGlOIYB7az+hWTVAxIlgA=; 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-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1690248931; v=1; b=Jc8TFjBNGCLb2PKo1xIN3nKFhyajWzxACrSZiY+NTNUVka+0cy9HIQdEf4uFJr0ntnpJCSY3 DAwOb/whY/VEYARIDLtgu1ruBF26Akyfg05hid84edOhWEDCnKX6J2js0ceDV2MB9J12pIh1fS9 kDTMu+DqOHfJIuURIkWaqTn0= X-Received: by 127.0.0.2 with SMTP id 1XKoYY1788612xxyaExkk3h1; Mon, 24 Jul 2023 18:35:31 -0700 X-Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) by mx.groups.io with SMTP id smtpd.web11.11424.1690248931342461441 for ; Mon, 24 Jul 2023 18:35:31 -0700 X-Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-1b8ad8383faso38207935ad.0 for ; Mon, 24 Jul 2023 18:35:31 -0700 (PDT) X-Gm-Message-State: 1riGXK3tO0NfXJN53fdGAVvhx1787277AA= X-Google-Smtp-Source: APBJJlHyex4Tsr6VK9WMDlBozT/1xl0oLLHjvq9J5qEUgbLIdo6hbIMR+F1nMqZSnnt8HuSHGIqqYg== X-Received: by 2002:a17:902:c945:b0:1b8:6cbd:96f1 with SMTP id i5-20020a170902c94500b001b86cbd96f1mr15405150pla.66.1690248930563; Mon, 24 Jul 2023 18:35:30 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.230.135]) by smtp.gmail.com with ESMTPSA id f8-20020a170902ce8800b001b893b689a0sm9630868plg.84.2023.07.24.18.35.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jul 2023 18:35:30 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Jian J Wang , Liming Gao , Dandan Bi Subject: [edk2-devel] [PATCH v3 08/14] MdeModulePkg: Add ImagePropertiesRecordLib Host-Based Unit Test Date: Mon, 24 Jul 2023 18:35:07 -0700 Message-ID: <20230725013513.1403-9-t@taylorbeebe.com> In-Reply-To: <20230725013513.1403-1-t@taylorbeebe.com> References: <20230725013513.1403-1-t@taylorbeebe.com> MIME-Version: 1.0 Precedence: Bulk 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 List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1690248934503100035 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 (#107205): https://edk2.groups.io/g/devel/message/107205 Mute This Topic: https://groups.io/mt/100342604/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 Mon May 13 00:36:34 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+107206+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+107206+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1690248932; cv=none; d=zohomail.com; s=zohoarc; b=aL+6bVrnKn675YF6qnZltSBTtz2xqkaRyswoscknIU85Uopt8GMX4KaPheLzOxK9hn5430UmnzglNKCoplFkxB669ODNxp1Y01zAIH9Jpi1lg96oGw9z8wuUK33ZVTrDhEgO9f91E1/ogW3LAgBGyBGnDwhnIGOh8V+q1suU6O8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690248932; 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=mpd02IfkdUGhOtbxIh7nioS657Ff/7HxUzWfDzqu5Io=; b=XCne/PXnFh/uzIbhmI70zTs+zWeZvHLx+Nw+/oZ/dOvWFum68wJT6uJeLT/+QW6yfebEMOzgy5gTlRIg9ki4LoWljLjpkMELH51Nvot1JBSvpfuibFxbhhSbE4jwdQ51fdXMTy7ZdH+kD5fZwFMwspLZhf7Y/EMzRFaIe8pWL4Y= 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+107206+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1690248932750465.2180865502579; Mon, 24 Jul 2023 18:35:32 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=+5gV0KpLlRNCfmMmw3EBdQdYixgRss+yvvG9C3y4fmk=; 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-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1690248932; v=1; b=lYvm9PzVtH8L1aD7uTGZ+cqw41BYmA/u0hfcxeB2JqJUVjLAFVgDm5A8GUcwKujY9CzxBBlc v6Mr+NLaE/AWCHL5jCZ+eljLghayUvcp2+hsgex14X2FhfM8G+EJ0eNspuDaY+61+GBCgsl7Nac uzAB94sF0Dx+FeRnFSn3r2Sw= X-Received: by 127.0.0.2 with SMTP id jaJaYY1788612xuxCLFl2N0X; Mon, 24 Jul 2023 18:35:32 -0700 X-Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by mx.groups.io with SMTP id smtpd.web10.11290.1690248931894129978 for ; Mon, 24 Jul 2023 18:35:31 -0700 X-Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1bb893e6365so12990345ad.2 for ; Mon, 24 Jul 2023 18:35:31 -0700 (PDT) X-Gm-Message-State: XVHs78waV6Gk9Tpli2zL6g6Hx1787277AA= X-Google-Smtp-Source: APBJJlGNENB0sOM3w/NhLlpJ3RcgbgLgYu4QPe7QZMg1vVfKrZst1WpwSNzYs6rH/++NpxiCQfiKgA== X-Received: by 2002:a17:902:b114:b0:1b8:7483:d481 with SMTP id q20-20020a170902b11400b001b87483d481mr9602439plr.8.1690248931293; Mon, 24 Jul 2023 18:35:31 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.230.135]) by smtp.gmail.com with ESMTPSA id f8-20020a170902ce8800b001b893b689a0sm9630868plg.84.2023.07.24.18.35.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jul 2023 18:35:30 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Jian J Wang , Liming Gao , Dandan Bi Subject: [edk2-devel] [PATCH v3 09/14] MdeModulePkg: Fix Bugs in MAT Logic Date: Mon, 24 Jul 2023 18:35:08 -0700 Message-ID: <20230725013513.1403-10-t@taylorbeebe.com> In-Reply-To: <20230725013513.1403-1-t@taylorbeebe.com> References: <20230725013513.1403-1-t@taylorbeebe.com> MIME-Version: 1.0 Precedence: Bulk 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 List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1690248934472100034 Content-Type: text/plain; charset="utf-8" Fix the bugs in the 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/Core/Dxe/Misc/MemoryAttributesTable.c |= 2 +- MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.c |= 98 ++++++++++---------- 2 files changed, 49 insertions(+), 51 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c b/MdeModule= Pkg/Core/Dxe/Misc/MemoryAttributesTable.c index 51630f504ea1..af6c26244cc0 100644 --- a/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c +++ b/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c @@ -517,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); diff --git a/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesR= ecordLib.c b/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesR= ecordLib.c index d942c7fef19a..b079cc3503ee 100644 --- a/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLi= b.c +++ b/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLi= b.c @@ -277,7 +277,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 @@ -323,7 +323,6 @@ SplitRecord ( UINT64 PhysicalEnd; UINTN NewRecordCount; UINTN TotalNewRecordCount; - BOOLEAN IsLastRecordData; =20 if (MaxSplitRecordCount =3D=3D 0) { CopyMem (NewRecord, OldRecord, DescriptorSize); @@ -344,35 +343,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; @@ -380,6 +360,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 // @@ -465,11 +463,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. // @@ -477,7 +476,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); // @@ -491,16 +491,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 @@ -509,16 +507,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 (#107206): https://edk2.groups.io/g/devel/message/107206 Mute This Topic: https://groups.io/mt/100342605/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 Mon May 13 00:36:34 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+107207+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+107207+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1690248933; cv=none; d=zohomail.com; s=zohoarc; b=M4LDDoh2Sbyz0RAODmO0OW6OUYNf96Cy8beyicVLF9q+h40zTurg4sPVdEkdpVRdch+GuOmwzEO6/C5XLu/+t/JIAAfhcIihqkjpPebc+5dzie1Rh381gX6bkg6K4ZOT4aRvpmgUnfWFkCJIaUI+zjji51OaWwXlhFDcoIEyH1s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690248933; 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=fKbQ39XDd5NWtoXxnohSgxJgdPIqe8CAz3p/3VxtcgY=; b=d3Tk/aICUftXzbLEsMZNzmgKI9w47bUvsDfKsm/t/u1Xea7/dMYxomcfmlx5NKO3QhiMPsDyhoce9o7k8XiI/T+hvq81ICvTlYm20yPT3BVjCRs6XXfrAgKDR0UDx0dRyRJGnlCAkpKnllJdBB+nLobJaIVBJ0/oM12kxbyftSU= 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+107207+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1690248933274869.338899309986; Mon, 24 Jul 2023 18:35:33 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=+QH8aILv4/9xt3ZZWABzfy+HkI1+zFOQm6sy1zeLQIQ=; 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-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1690248933; v=1; b=tEn5HVLzCYH7VjrSp69Ktc64OyDUL2FENVQp22ygl1u9UAjCSKsiE41UZsBuPLhrhFl2EzIR Crh4iLEctGIEWvjkschldEdipZDvVepeL5o0zU1gHymF8i1nOY3rFN0ZCAIYzySu7473hea0ocL ujLfofARre7UV6mHnjkE6y+g= X-Received: by 127.0.0.2 with SMTP id RJQdYY1788612x1LF2DLLum4; Mon, 24 Jul 2023 18:35:33 -0700 X-Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by mx.groups.io with SMTP id smtpd.web10.11291.1690248932503992027 for ; Mon, 24 Jul 2023 18:35:32 -0700 X-Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-1b9c5e07c1bso38123715ad.2 for ; Mon, 24 Jul 2023 18:35:32 -0700 (PDT) X-Gm-Message-State: 8A4woGS55ullCQRPut367Lk5x1787277AA= X-Google-Smtp-Source: APBJJlGjsJeuLhq93PN5royEB8MlFV+BkK4pDqEtUzqp1C076V22sQzfz0fJBl/XunYWhH/U95eqNg== X-Received: by 2002:a17:902:d505:b0:1b6:76ee:190b with SMTP id b5-20020a170902d50500b001b676ee190bmr14449610plg.35.1690248931851; Mon, 24 Jul 2023 18:35:31 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.230.135]) by smtp.gmail.com with ESMTPSA id f8-20020a170902ce8800b001b893b689a0sm9630868plg.84.2023.07.24.18.35.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jul 2023 18:35:31 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Rahul Kumar , Gerd Hoffmann Subject: [edk2-devel] [PATCH v3 10/14] UefiCpuPkg: Use Attribute From SMM MemoryAttributesTable if Nonzero Date: Mon, 24 Jul 2023 18:35:09 -0700 Message-ID: <20230725013513.1403-11-t@taylorbeebe.com> In-Reply-To: <20230725013513.1403-1-t@taylorbeebe.com> References: <20230725013513.1403-1-t@taylorbeebe.com> MIME-Version: 1.0 Precedence: Bulk 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 List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1690248934453100033 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 (#107207): https://edk2.groups.io/g/devel/message/107207 Mute This Topic: https://groups.io/mt/100342606/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 Mon May 13 00:36:34 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+107208+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+107208+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1690248934; cv=none; d=zohomail.com; s=zohoarc; b=kXFll0zRfz0VHkwPg0UgL4TJizhACzgQ/3MKRlmVzWRwWFLmIopEgjMCsHlU2bc20qlCJNZm1p9rEE7MgfUCZvzpWwzq3ZPrXk088t09ELYVZEMlWc+Y8g2oB4cunSmaStZg+ENTDTQ6GU4mdQ6UTSsVvtcR+58diM/Lkii6D0Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690248934; 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=V+CgkEJZ7RRFQQCpyCV5r8D4bm70aCTN3kReVqFvb+k=; b=gleU3qELqvvMc88QehPhIMZuzRiljahL4/dqt0H5NinrSRE1bxOXSlmhtvJVWxB9xp9o+ILWikdaHrvTtx2svTqCJidZhXQ75i4XxE3KXS4VvXfvBq+yAd3PJ2NM5o0cWeXmZr9lWI3uAJbVCFd58ZhgYEbl5MoeM0Gmo1HFZTE= 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+107208+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1690248934304281.4293590137697; Mon, 24 Jul 2023 18:35:34 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=JpIYAJ9Iu6QYlRk2aQkUjjJr2+3y+fshSMScLKosgRg=; 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-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1690248934; v=1; b=mEgYetm7vhwIc/grfwMp/BZnaK2zgGp657N1oNCuZTqjBfw1xaLYppFOsDWDHM0hIqskjDr2 8T8JWO2QpvUdNajPdPlMF7dNzOK38JUDJntDuWPy4G70xVBIBygWQLY1i8DioCE2uJEdNEi9UFK ImD7JusaXH78Yid63bZT+dco= X-Received: by 127.0.0.2 with SMTP id irqAYY1788612xS0iHx1KIFK; Mon, 24 Jul 2023 18:35:34 -0700 X-Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) by mx.groups.io with SMTP id smtpd.web10.11292.1690248933511002510 for ; Mon, 24 Jul 2023 18:35:33 -0700 X-Received: by mail-pg1-f171.google.com with SMTP id 41be03b00d2f7-563643b2b4cso2490667a12.1 for ; Mon, 24 Jul 2023 18:35:33 -0700 (PDT) X-Gm-Message-State: 2fnhDyoCTB6AoNZZEZpLenL9x1787277AA= X-Google-Smtp-Source: APBJJlH97vSm8TNjN1xniW6PPOaDRcdRdDm5/8fdQVgV3VbyF4YknIOhdTtQ0A21TYpOGPL2Zqf69Q== X-Received: by 2002:a05:6a20:4311:b0:12e:7bd4:78f5 with SMTP id h17-20020a056a20431100b0012e7bd478f5mr10622526pzk.50.1690248932671; Mon, 24 Jul 2023 18:35:32 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.230.135]) by smtp.gmail.com with ESMTPSA id f8-20020a170902ce8800b001b893b689a0sm9630868plg.84.2023.07.24.18.35.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jul 2023 18:35:32 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Jian J Wang , Liming Gao , Dandan Bi Subject: [edk2-devel] [PATCH v3 11/14] MdeModulePkg: Transition SMM MAT Logic to Use ImagePropertiesRecordLib Date: Mon, 24 Jul 2023 18:35:10 -0700 Message-ID: <20230725013513.1403-12-t@taylorbeebe.com> In-Reply-To: <20230725013513.1403-1-t@taylorbeebe.com> References: <20230725013513.1403-1-t@taylorbeebe.com> MIME-Version: 1.0 Precedence: Bulk 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 List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1690248934504100036 Content-Type: text/plain; charset="utf-8" Now that the bugs are fixed in the MAT logic, we can remove the duplicate logic from PiSmmCore/MemoryAttributesTable.c and use ImagePropertiesRecordLib instead. Signed-off-by: Taylor Beebe Cc: Jian J Wang Cc: Liming Gao Cc: Dandan Bi --- MdeModulePkg/Core/PiSmmCore/MemoryAttributesTable.c |= 785 +------------------- MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.c |= 29 + MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf |= 1 + MdeModulePkg/Include/Library/ImagePropertiesRecordLib.h |= 11 + 4 files changed, 58 insertions(+), 768 deletions(-) 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/Library/ImagePropertiesRecordLib/ImagePropertiesR= ecordLib.c b/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesR= ecordLib.c index b079cc3503ee..eaef54464395 100644 --- a/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLi= b.c +++ b/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLi= b.c @@ -735,6 +735,35 @@ SortImageRecord ( } } =20 +/** + 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)); + } +} + /** Find image record according to image base and size. =20 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 diff --git a/MdeModulePkg/Include/Library/ImagePropertiesRecordLib.h b/MdeM= odulePkg/Include/Library/ImagePropertiesRecordLib.h index 7321d99ef51b..90e6a262463c 100644 --- a/MdeModulePkg/Include/Library/ImagePropertiesRecordLib.h +++ b/MdeModulePkg/Include/Library/ImagePropertiesRecordLib.h @@ -144,4 +144,15 @@ FindImageRecord ( IN LIST_ENTRY *ImageRecordList ); =20 +/** + Dump image record. + + @param[in] ImageRecordList A list of IMAGE_PROPERTIES_RECORD entries +**/ +VOID +EFIAPI +DumpImageRecord ( + IN LIST_ENTRY *ImageRecordList + ); + #endif --=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 (#107208): https://edk2.groups.io/g/devel/message/107208 Mute This Topic: https://groups.io/mt/100342607/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 Mon May 13 00:36:34 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+107209+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+107209+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1690248935; cv=none; d=zohomail.com; s=zohoarc; b=lBBVwLq+aOTQnGNBe5djyoka3BNyc09PvibgH/cRHIDOWOvIUczrspLe/rnrT6lvtaPHiVWaDe1rX1Yww64YdyBSnJp2K6pAWaQS6RCvV/cD5saW0ND6IecUB3Vbbmr/4m31VzCiCx2wSBNxhb51Snfz5/c739Qn3Vhs4pM2ylI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690248935; 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=+BtB9LLSNKXd0NDwyrMr+jtQlweaw+8hPDCGwa3/7mU=; b=cL7f8IT+6dpVXYXvAnmFlqsv9GNWvvu2gCES3bo/LsOAHv/EWKOccseVpnkwSmtzTlKCHKSGGjDb1N2FI29qUg/b2K0Qch29vbUGKFzHnnXkdQA1fXH67yVKbs4nfa+QeufjBja0/9zCC+7fpsNu1+eZSGhhwSpteqXx4TlY+cI= 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+107209+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1690248935006449.0740266669885; Mon, 24 Jul 2023 18:35:35 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=s6DxxicJJxP604XY63iMIzkB281v40/OJAltel4sQLM=; 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-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1690248934; v=1; b=c/NY/hghGS/r6DAGhR+PGiMdhZyt9Tm4UaEbvWeLuFWs82MHJ8CjawffMgIS1NTMgFjCqp+p XYqXD29rtFO33LerJvAsiLRC8VqXNMuZzsaRVjET08OzMr6Tp15nL1Pa5iZYPixJmStuo2QOOuQ LQcqV2FFRTw6ME6hM53LTh+Q= X-Received: by 127.0.0.2 with SMTP id lpTwYY1788612xnjSLUccJ05; Mon, 24 Jul 2023 18:35:34 -0700 X-Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) by mx.groups.io with SMTP id smtpd.web11.11428.1690248934168943002 for ; Mon, 24 Jul 2023 18:35:34 -0700 X-Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-1b8ad9eede0so40096345ad.1 for ; Mon, 24 Jul 2023 18:35:34 -0700 (PDT) X-Gm-Message-State: e4wEmJUH5QO6aJ7AXvdiHqZzx1787277AA= X-Google-Smtp-Source: APBJJlGsXmxaERLgKSkDv3ND+GZhyNvLh920nfP6p+LkgF0QIyAa+97t3P50TgwHqjcMdXF2PBx0Kg== X-Received: by 2002:a17:902:dac1:b0:1b8:a65f:b49d with SMTP id q1-20020a170902dac100b001b8a65fb49dmr15973680plx.12.1690248933474; Mon, 24 Jul 2023 18:35:33 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.230.135]) by smtp.gmail.com with ESMTPSA id f8-20020a170902ce8800b001b893b689a0sm9630868plg.84.2023.07.24.18.35.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jul 2023 18:35:33 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Jian J Wang , Liming Gao , Dandan Bi Subject: [edk2-devel] [PATCH v3 12/14] MdeModulePkg: Add Logic to Create/Delete Image Properties Records Date: Mon, 24 Jul 2023 18:35:11 -0700 Message-ID: <20230725013513.1403-13-t@taylorbeebe.com> In-Reply-To: <20230725013513.1403-1-t@taylorbeebe.com> References: <20230725013513.1403-1-t@taylorbeebe.com> MIME-Version: 1.0 Precedence: Bulk 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 List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1690248936539100046 Content-Type: text/plain; charset="utf-8" Add logic to create and delete image properties records. Where applicable, redirect existing code to use the new library. Signed-off-by: Taylor Beebe Cc: Jian J Wang Cc: Liming Gao Cc: Dandan Bi --- MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c = | 184 +++---------------- MdeModulePkg/Core/PiSmmCore/MemoryAttributesTable.c = | 166 +++-------------- MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.c = | 186 ++++++++++++++++++++ MdeModulePkg/Include/Library/ImagePropertiesRecordLib.h = | 39 ++++ MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.inf= | 1 + 5 files changed, 281 insertions(+), 295 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c b/MdeModule= Pkg/Core/Dxe/Misc/MemoryAttributesTable.c index af6c26244cc0..993db281062a 100644 --- a/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c +++ b/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c @@ -557,25 +557,6 @@ CoreGetMemoryMapWithSeparatedImageSection ( // Below functions are for ImageRecord // =20 -/** - Set MemoryAttributesTable according to PE/COFF image section alignment. - - @param SectionAlignment PE/COFF section alignment -**/ -STATIC -VOID -SetMemoryAttributesTableSectionAlignment ( - IN UINT32 SectionAlignment - ) -{ - if (((SectionAlignment & (RUNTIME_PAGE_ALLOCATION_GRANULARITY - 1)) !=3D= 0) && - mMemoryAttributesTableEnable) - { - DEBUG ((DEBUG_VERBOSE, "SetMemoryAttributesTableSectionAlignment - Cle= ar\n")); - mMemoryAttributesTableEnable =3D FALSE; - } -} - /** Insert image record. =20 @@ -586,20 +567,12 @@ InsertImageRecord ( IN EFI_RUNTIME_IMAGE_ENTRY *RuntimeImage ) { - VOID *ImageAddress; - EFI_IMAGE_DOS_HEADER *DosHdr; - UINT32 PeCoffHeaderOffset; - UINT32 SectionAlignment; - EFI_IMAGE_SECTION_HEADER *Section; - EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr; - UINT8 *Name; - UINTN Index; - IMAGE_PROPERTIES_RECORD *ImageRecord; - CHAR8 *PdbPointer; - IMAGE_PROPERTIES_RECORD_CODE_SECTION *ImageRecordCodeSection; + EFI_STATUS Status; + IMAGE_PROPERTIES_RECORD *ImageRecord; + CHAR8 *PdbPointer; + UINT32 RequiredAlignment; =20 DEBUG ((DEBUG_VERBOSE, "InsertImageRecord - 0x%x\n", RuntimeImage)); - DEBUG ((DEBUG_VERBOSE, "InsertImageRecord - 0x%016lx - 0x%016lx\n", (EFI= _PHYSICAL_ADDRESS)(UINTN)RuntimeImage->ImageBase, RuntimeImage->ImageSize)); =20 if (mMemoryAttributesTableEndOfDxe) { DEBUG ((DEBUG_INFO, "Do not insert runtime image record after EndOfDxe= \n")); @@ -611,139 +584,48 @@ InsertImageRecord ( return; } =20 - ImageRecord->Signature =3D IMAGE_PROPERTIES_RECORD_SIGNATURE; + InitializeListHead (&ImageRecord->Link); + InitializeListHead (&ImageRecord->CodeSegmentList); =20 - DEBUG ((DEBUG_VERBOSE, "ImageRecordCount - 0x%x\n", mImagePropertiesPriv= ateData.ImageRecordCount)); - - // - // Step 1: record whole region - // - ImageRecord->ImageBase =3D (EFI_PHYSICAL_ADDRESS)(UINTN)RuntimeImage->Im= ageBase; - ImageRecord->ImageSize =3D RuntimeImage->ImageSize; - - ImageAddress =3D RuntimeImage->ImageBase; - - PdbPointer =3D PeCoffLoaderGetPdbPointer ((VOID *)(UINTN)ImageAddress); + PdbPointer =3D PeCoffLoaderGetPdbPointer ((VOID *)(UINTN)RuntimeImage->I= mageBase); if (PdbPointer !=3D NULL) { DEBUG ((DEBUG_VERBOSE, " Image - %a\n", PdbPointer)); } =20 - // - // Check PE/COFF image - // - DosHdr =3D (EFI_IMAGE_DOS_HEADER *)(UINTN)ImageAddress; - PeCoffHeaderOffset =3D 0; - if (DosHdr->e_magic =3D=3D EFI_IMAGE_DOS_SIGNATURE) { - PeCoffHeaderOffset =3D DosHdr->e_lfanew; - } - - Hdr.Pe32 =3D (EFI_IMAGE_NT_HEADERS32 *)((UINT8 *)(UINTN)ImageAddress + P= eCoffHeaderOffset); - if (Hdr.Pe32->Signature !=3D EFI_IMAGE_NT_SIGNATURE) { - DEBUG ((DEBUG_VERBOSE, "Hdr.Pe32->Signature invalid - 0x%x\n", Hdr.Pe3= 2->Signature)); - // It might be image in SMM. - goto Finish; - } - - // - // Get SectionAlignment - // - if (Hdr.Pe32->OptionalHeader.Magic =3D=3D EFI_IMAGE_NT_OPTIONAL_HDR32_MA= GIC) { - SectionAlignment =3D Hdr.Pe32->OptionalHeader.SectionAlignment; - } else { - SectionAlignment =3D Hdr.Pe32Plus->OptionalHeader.SectionAlignment; - } - - SetMemoryAttributesTableSectionAlignment (SectionAlignment); - if ((SectionAlignment & (RUNTIME_PAGE_ALLOCATION_GRANULARITY - 1)) !=3D = 0) { - DEBUG (( - DEBUG_WARN, - "!!!!!!!! InsertImageRecord - Section Alignment(0x%x) is not %dK != !!!!!!!\n", - SectionAlignment, - RUNTIME_PAGE_ALLOCATION_GRANULARITY >> 10 - )); - PdbPointer =3D PeCoffLoaderGetPdbPointer ((VOID *)(UINTN)ImageAddress); - if (PdbPointer !=3D NULL) { - DEBUG ((DEBUG_WARN, "!!!!!!!! Image - %a !!!!!!!!\n", PdbPointer)); + RequiredAlignment =3D RUNTIME_PAGE_ALLOCATION_GRANULARITY; + Status =3D CreateImagePropertiesRecord ( + RuntimeImage->ImageBase, + RuntimeImage->ImageSize, + &RequiredAlignment, + ImageRecord + ); + + if (EFI_ERROR (Status)) { + if (Status =3D=3D EFI_ABORTED) { + mMemoryAttributesTableEnable =3D FALSE; } =20 + Status =3D EFI_ABORTED; goto Finish; } =20 - Section =3D (EFI_IMAGE_SECTION_HEADER *)( - (UINT8 *)(UINTN)ImageAddress + - PeCoffHeaderOffset + - sizeof (UINT32) + - sizeof (EFI_IMAGE_FILE_HEADER) + - Hdr.Pe32->FileHeader.SizeOfOption= alHeader - ); - ImageRecord->CodeSegmentCount =3D 0; - InitializeListHead (&ImageRecord->CodeSegmentList); - for (Index =3D 0; Index < Hdr.Pe32->FileHeader.NumberOfSections; Index++= ) { - Name =3D Section[Index].Name; - DEBUG (( - DEBUG_VERBOSE, - " Section - '%c%c%c%c%c%c%c%c'\n", - Name[0], - Name[1], - Name[2], - Name[3], - Name[4], - Name[5], - Name[6], - Name[7] - )); - - if ((Section[Index].Characteristics & EFI_IMAGE_SCN_CNT_CODE) !=3D 0) { - DEBUG ((DEBUG_VERBOSE, " VirtualSize - 0x%08x\n", Section[= Index].Misc.VirtualSize)); - DEBUG ((DEBUG_VERBOSE, " VirtualAddress - 0x%08x\n", Section[= Index].VirtualAddress)); - DEBUG ((DEBUG_VERBOSE, " SizeOfRawData - 0x%08x\n", Section[= Index].SizeOfRawData)); - DEBUG ((DEBUG_VERBOSE, " PointerToRawData - 0x%08x\n", Section[= Index].PointerToRawData)); - DEBUG ((DEBUG_VERBOSE, " PointerToRelocations - 0x%08x\n", Section[= Index].PointerToRelocations)); - DEBUG ((DEBUG_VERBOSE, " PointerToLinenumbers - 0x%08x\n", Section[= Index].PointerToLinenumbers)); - DEBUG ((DEBUG_VERBOSE, " NumberOfRelocations - 0x%08x\n", Section[= Index].NumberOfRelocations)); - DEBUG ((DEBUG_VERBOSE, " NumberOfLinenumbers - 0x%08x\n", Section[= Index].NumberOfLinenumbers)); - DEBUG ((DEBUG_VERBOSE, " Characteristics - 0x%08x\n", Section[= Index].Characteristics)); - - // - // Step 2: record code section - // - ImageRecordCodeSection =3D AllocatePool (sizeof (*ImageRecordCodeSec= tion)); - if (ImageRecordCodeSection =3D=3D NULL) { - return; - } - - ImageRecordCodeSection->Signature =3D IMAGE_PROPERTIES_RECORD_CODE_S= ECTION_SIGNATURE; - - ImageRecordCodeSection->CodeSegmentBase =3D (UINTN)ImageAddress + Se= ction[Index].VirtualAddress; - ImageRecordCodeSection->CodeSegmentSize =3D Section[Index].SizeOfRaw= Data; - - DEBUG ((DEBUG_VERBOSE, "ImageCode: 0x%016lx - 0x%016lx\n", ImageReco= rdCodeSection->CodeSegmentBase, ImageRecordCodeSection->CodeSegmentSize)); - - InsertTailList (&ImageRecord->CodeSegmentList, &ImageRecordCodeSecti= on->Link); - ImageRecord->CodeSegmentCount++; - } - } - if (ImageRecord->CodeSegmentCount =3D=3D 0) { - SetMemoryAttributesTableSectionAlignment (1); + mMemoryAttributesTableEnable =3D FALSE; DEBUG ((DEBUG_ERROR, "!!!!!!!! InsertImageRecord - CodeSegmentCount i= s 0 !!!!!!!!\n")); - PdbPointer =3D PeCoffLoaderGetPdbPointer ((VOID *)(UINTN)ImageAddress); if (PdbPointer !=3D NULL) { DEBUG ((DEBUG_ERROR, "!!!!!!!! Image - %a !!!!!!!!\n", PdbPointer)= ); } =20 + Status =3D EFI_ABORTED; goto Finish; } =20 - // - // Final - // - SortImageRecordCodeSection (ImageRecord); // // Check overlap all section in ImageBase/Size // if (!IsImageRecordCodeSectionValid (ImageRecord)) { DEBUG ((DEBUG_ERROR, "IsImageRecordCodeSectionValid - FAIL\n")); + Status =3D EFI_ABORTED; goto Finish; } =20 @@ -757,6 +639,10 @@ InsertImageRecord ( SortImageRecord (&mImagePropertiesPrivateData.ImageRecordList); =20 Finish: + if (EFI_ERROR (Status) && (ImageRecord !=3D NULL)) { + DeleteImagePropertiesRecord (ImageRecord); + } + return; } =20 @@ -770,9 +656,7 @@ RemoveImageRecord ( IN EFI_RUNTIME_IMAGE_ENTRY *RuntimeImage ) { - IMAGE_PROPERTIES_RECORD *ImageRecord; - LIST_ENTRY *CodeSegmentListHead; - IMAGE_PROPERTIES_RECORD_CODE_SECTION *ImageRecordCodeSection; + IMAGE_PROPERTIES_RECORD *ImageRecord; =20 DEBUG ((DEBUG_VERBOSE, "RemoveImageRecord - 0x%x\n", RuntimeImage)); DEBUG ((DEBUG_VERBOSE, "RemoveImageRecord - 0x%016lx - 0x%016lx\n", (EFI= _PHYSICAL_ADDRESS)(UINTN)RuntimeImage->ImageBase, RuntimeImage->ImageSize)); @@ -788,19 +672,7 @@ RemoveImageRecord ( return; } =20 - CodeSegmentListHead =3D &ImageRecord->CodeSegmentList; - while (!IsListEmpty (CodeSegmentListHead)) { - ImageRecordCodeSection =3D CR ( - CodeSegmentListHead->ForwardLink, - IMAGE_PROPERTIES_RECORD_CODE_SECTION, - Link, - IMAGE_PROPERTIES_RECORD_CODE_SECTION_SIGNAT= URE - ); - RemoveEntryList (&ImageRecordCodeSection->Link); - FreePool (ImageRecordCodeSection); - } + DeleteImagePropertiesRecord (ImageRecord); =20 - RemoveEntryList (&ImageRecord->Link); - FreePool (ImageRecord); mImagePropertiesPrivateData.ImageRecordCount--; } diff --git a/MdeModulePkg/Core/PiSmmCore/MemoryAttributesTable.c b/MdeModul= ePkg/Core/PiSmmCore/MemoryAttributesTable.c index 2e4aaddef4e5..03de9b2c5fff 100644 --- a/MdeModulePkg/Core/PiSmmCore/MemoryAttributesTable.c +++ b/MdeModulePkg/Core/PiSmmCore/MemoryAttributesTable.c @@ -251,25 +251,6 @@ SmmCoreGetMemoryMapMemoryAttributesTable ( // Below functions are for ImageRecord // =20 -/** - Set MemoryProtectionAttribute according to PE/COFF image section alignme= nt. - - @param[in] SectionAlignment PE/COFF section alignment -**/ -STATIC -VOID -SetMemoryAttributesTableSectionAlignment ( - IN UINT32 SectionAlignment - ) -{ - if (((SectionAlignment & (RUNTIME_PAGE_ALLOCATION_GRANULARITY - 1)) !=3D= 0) && - ((mMemoryProtectionAttribute & EFI_MEMORY_ATTRIBUTES_RUNTIME_MEMORY_= PROTECTION_NON_EXECUTABLE_PE_DATA) !=3D 0)) - { - DEBUG ((DEBUG_VERBOSE, "SMM SetMemoryAttributesTableSectionAlignment -= Clear\n")); - mMemoryProtectionAttribute &=3D ~((UINT64)EFI_MEMORY_ATTRIBUTES_RUNTIM= E_MEMORY_PROTECTION_NON_EXECUTABLE_PE_DATA); - } -} - /** Insert image record. =20 @@ -280,158 +261,61 @@ SmmInsertImageRecord ( IN EFI_SMM_DRIVER_ENTRY *DriverEntry ) { - VOID *ImageAddress; - EFI_IMAGE_DOS_HEADER *DosHdr; - UINT32 PeCoffHeaderOffset; - UINT32 SectionAlignment; - EFI_IMAGE_SECTION_HEADER *Section; - EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr; - UINT8 *Name; - UINTN Index; - IMAGE_PROPERTIES_RECORD *ImageRecord; - CHAR8 *PdbPointer; - IMAGE_PROPERTIES_RECORD_CODE_SECTION *ImageRecordCodeSection; + EFI_STATUS Status; + IMAGE_PROPERTIES_RECORD *ImageRecord; + CHAR8 *PdbPointer; + UINT32 RequiredAlignment; =20 DEBUG ((DEBUG_VERBOSE, "SMM InsertImageRecord - 0x%x\n", DriverEntry)); - DEBUG ((DEBUG_VERBOSE, "SMM InsertImageRecord - 0x%016lx - 0x%08x\n", Dr= iverEntry->ImageBuffer, DriverEntry->NumberOfPage)); =20 ImageRecord =3D AllocatePool (sizeof (*ImageRecord)); if (ImageRecord =3D=3D NULL) { return; } =20 - ImageRecord->Signature =3D IMAGE_PROPERTIES_RECORD_SIGNATURE; + InitializeListHead (&ImageRecord->Link); + InitializeListHead (&ImageRecord->CodeSegmentList); =20 - DEBUG ((DEBUG_VERBOSE, "SMM ImageRecordCount - 0x%x\n", mImageProperties= PrivateData.ImageRecordCount)); - - // - // Step 1: record whole region - // - ImageRecord->ImageBase =3D DriverEntry->ImageBuffer; - ImageRecord->ImageSize =3D LShiftU64 (DriverEntry->NumberOfPage, EFI_PAG= E_SHIFT); - - ImageAddress =3D (VOID *)(UINTN)DriverEntry->ImageBuffer; - - PdbPointer =3D PeCoffLoaderGetPdbPointer ((VOID *)(UINTN)ImageAddress); + PdbPointer =3D PeCoffLoaderGetPdbPointer ((VOID *)(UINTN)DriverEntry->Im= ageBuffer); if (PdbPointer !=3D NULL) { DEBUG ((DEBUG_VERBOSE, "SMM Image - %a\n", PdbPointer)); } =20 - // - // Check PE/COFF image - // - DosHdr =3D (EFI_IMAGE_DOS_HEADER *)(UINTN)ImageAddress; - PeCoffHeaderOffset =3D 0; - if (DosHdr->e_magic =3D=3D EFI_IMAGE_DOS_SIGNATURE) { - PeCoffHeaderOffset =3D DosHdr->e_lfanew; - } - - Hdr.Pe32 =3D (EFI_IMAGE_NT_HEADERS32 *)((UINT8 *)(UINTN)ImageAddress + P= eCoffHeaderOffset); - if (Hdr.Pe32->Signature !=3D EFI_IMAGE_NT_SIGNATURE) { - DEBUG ((DEBUG_VERBOSE, "SMM Hdr.Pe32->Signature invalid - 0x%x\n", Hdr= .Pe32->Signature)); - goto Finish; - } - - // - // Get SectionAlignment - // - if (Hdr.Pe32->OptionalHeader.Magic =3D=3D EFI_IMAGE_NT_OPTIONAL_HDR32_MA= GIC) { - SectionAlignment =3D Hdr.Pe32->OptionalHeader.SectionAlignment; - } else { - SectionAlignment =3D Hdr.Pe32Plus->OptionalHeader.SectionAlignment; - } - - SetMemoryAttributesTableSectionAlignment (SectionAlignment); - if ((SectionAlignment & (RUNTIME_PAGE_ALLOCATION_GRANULARITY - 1)) !=3D = 0) { - DEBUG (( - DEBUG_WARN, - "SMM !!!!!!!! InsertImageRecord - Section Alignment(0x%x) is not %d= K !!!!!!!!\n", - SectionAlignment, - RUNTIME_PAGE_ALLOCATION_GRANULARITY >> 10 - )); - PdbPointer =3D PeCoffLoaderGetPdbPointer ((VOID *)(UINTN)ImageAddress); - if (PdbPointer !=3D NULL) { - DEBUG ((DEBUG_WARN, "SMM !!!!!!!! Image - %a !!!!!!!!\n", PdbPoint= er)); + RequiredAlignment =3D RUNTIME_PAGE_ALLOCATION_GRANULARITY; + Status =3D CreateImagePropertiesRecord ( + (VOID *)(UINTN)DriverEntry->ImageBuffer, + LShiftU64 (DriverEntry->NumberOfPage, EFI_PAGE_SHI= FT), + &RequiredAlignment, + ImageRecord + ); + + if (EFI_ERROR (Status)) { + if (Status =3D=3D EFI_ABORTED) { + mMemoryProtectionAttribute &=3D + ~((UINT64)EFI_MEMORY_ATTRIBUTES_RUNTIME_MEMORY_PROTECTION_NON_EXEC= UTABLE_PE_DATA); } =20 goto Finish; } =20 - Section =3D (EFI_IMAGE_SECTION_HEADER *)( - (UINT8 *)(UINTN)ImageAddress + - PeCoffHeaderOffset + - sizeof (UINT32) + - sizeof (EFI_IMAGE_FILE_HEADER) + - Hdr.Pe32->FileHeader.SizeOfOption= alHeader - ); - ImageRecord->CodeSegmentCount =3D 0; - InitializeListHead (&ImageRecord->CodeSegmentList); - for (Index =3D 0; Index < Hdr.Pe32->FileHeader.NumberOfSections; Index++= ) { - Name =3D Section[Index].Name; - DEBUG (( - DEBUG_VERBOSE, - "SMM Section - '%c%c%c%c%c%c%c%c'\n", - Name[0], - Name[1], - Name[2], - Name[3], - Name[4], - Name[5], - Name[6], - Name[7] - )); - - if ((Section[Index].Characteristics & EFI_IMAGE_SCN_CNT_CODE) !=3D 0) { - DEBUG ((DEBUG_VERBOSE, "SMM VirtualSize - 0x%08x\n", Sect= ion[Index].Misc.VirtualSize)); - DEBUG ((DEBUG_VERBOSE, "SMM VirtualAddress - 0x%08x\n", Sect= ion[Index].VirtualAddress)); - DEBUG ((DEBUG_VERBOSE, "SMM SizeOfRawData - 0x%08x\n", Sect= ion[Index].SizeOfRawData)); - DEBUG ((DEBUG_VERBOSE, "SMM PointerToRawData - 0x%08x\n", Sect= ion[Index].PointerToRawData)); - DEBUG ((DEBUG_VERBOSE, "SMM PointerToRelocations - 0x%08x\n", Sect= ion[Index].PointerToRelocations)); - DEBUG ((DEBUG_VERBOSE, "SMM PointerToLinenumbers - 0x%08x\n", Sect= ion[Index].PointerToLinenumbers)); - DEBUG ((DEBUG_VERBOSE, "SMM NumberOfRelocations - 0x%08x\n", Sect= ion[Index].NumberOfRelocations)); - DEBUG ((DEBUG_VERBOSE, "SMM NumberOfLinenumbers - 0x%08x\n", Sect= ion[Index].NumberOfLinenumbers)); - DEBUG ((DEBUG_VERBOSE, "SMM Characteristics - 0x%08x\n", Sect= ion[Index].Characteristics)); - - // - // Step 2: record code section - // - ImageRecordCodeSection =3D AllocatePool (sizeof (*ImageRecordCodeSec= tion)); - if (ImageRecordCodeSection =3D=3D NULL) { - return; - } - - ImageRecordCodeSection->Signature =3D IMAGE_PROPERTIES_RECORD_CODE_S= ECTION_SIGNATURE; - - ImageRecordCodeSection->CodeSegmentBase =3D (UINTN)ImageAddress + Se= ction[Index].VirtualAddress; - ImageRecordCodeSection->CodeSegmentSize =3D Section[Index].SizeOfRaw= Data; - - DEBUG ((DEBUG_VERBOSE, "SMM ImageCode: 0x%016lx - 0x%016lx\n", Image= RecordCodeSection->CodeSegmentBase, ImageRecordCodeSection->CodeSegmentSize= )); - - InsertTailList (&ImageRecord->CodeSegmentList, &ImageRecordCodeSecti= on->Link); - ImageRecord->CodeSegmentCount++; - } - } - if (ImageRecord->CodeSegmentCount =3D=3D 0) { - SetMemoryAttributesTableSectionAlignment (1); + mMemoryProtectionAttribute &=3D + ~((UINT64)EFI_MEMORY_ATTRIBUTES_RUNTIME_MEMORY_PROTECTION_NON_EXECUT= ABLE_PE_DATA); DEBUG ((DEBUG_ERROR, "SMM !!!!!!!! InsertImageRecord - CodeSegmentCou= nt is 0 !!!!!!!!\n")); - PdbPointer =3D PeCoffLoaderGetPdbPointer ((VOID *)(UINTN)ImageAddress); if (PdbPointer !=3D NULL) { DEBUG ((DEBUG_ERROR, "SMM !!!!!!!! Image - %a !!!!!!!!\n", PdbPoin= ter)); } =20 + Status =3D EFI_ABORTED; goto Finish; } =20 - // - // Final - // - SortImageRecordCodeSection (ImageRecord); // // Check overlap all section in ImageBase/Size // if (!IsImageRecordCodeSectionValid (ImageRecord)) { DEBUG ((DEBUG_ERROR, "SMM IsImageRecordCodeSectionValid - FAIL\n")); + Status =3D EFI_ABORTED; goto Finish; } =20 @@ -445,6 +329,10 @@ SmmInsertImageRecord ( SortImageRecord (&mImagePropertiesPrivateData.ImageRecordList); =20 Finish: + if (EFI_ERROR (Status) && (ImageRecord !=3D NULL)) { + DeleteImagePropertiesRecord (ImageRecord); + } + return; } =20 diff --git a/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesR= ecordLib.c b/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesR= ecordLib.c index eaef54464395..9ac3afdaa202 100644 --- a/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLi= b.c +++ b/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLi= b.c @@ -13,6 +13,7 @@ #include #include #include +#include #include =20 #define PREVIOUS_MEMORY_DESCRIPTOR(MemoryDescriptor, Size) \ @@ -804,3 +805,188 @@ FindImageRecord ( =20 return NULL; } + +/** + Creates an IMAGE_PROPERTIES_RECORD from a loaded PE image. The PE/COFF h= eader will be found + and parsed to determine the number of code segments and their base addre= sses and sizes. + + @param[in] ImageBase Base of the PE image + @param[in] ImageSize Size of the PE image + @param[in] RequiredAlignment If non-NULL, the alignment speci= fied in the PE/COFF header + will be compared against this va= lue. + @param[out] ImageRecord On out, a populated image proper= ties record + + @retval EFI_INVALID_PARAMETER This function ImageBase or ImageReco= rd was NULL, or the + image located at ImageBase was not a= valid PE/COFF image + @retval EFI_OUT_OF_RESOURCES Failure to Allocate() + @retval EFI_ABORTED The input Alignment was non-NULL and= did not match the + alignment specified in the PE/COFF h= eader + @retval EFI_SUCCESS The image properties record was succ= essfully created +**/ +EFI_STATUS +EFIAPI +CreateImagePropertiesRecord ( + IN CONST VOID *ImageBase, + IN CONST UINT64 ImageSize, + IN CONST UINT32 *RequiredAlignment OPTIONAL, + OUT IMAGE_PROPERTIES_RECORD *ImageRecord + ) +{ + EFI_STATUS Status; + EFI_IMAGE_DOS_HEADER *DosHdr; + EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr; + EFI_IMAGE_SECTION_HEADER *Section; + IMAGE_PROPERTIES_RECORD_CODE_SECTION *ImageRecordCodeSection; + UINTN Index; + UINT8 *Name; + UINT32 SectionAlignment; + UINT32 PeCoffHeaderOffset; + + if ((ImageRecord =3D=3D NULL) || (ImageBase =3D=3D NULL)) { + return EFI_INVALID_PARAMETER; + } + + DEBUG (( + DEBUG_VERBOSE, + "Creating Image Properties Record: 0x%016lx - 0x%016lx\n", + (EFI_PHYSICAL_ADDRESS)(UINTN)ImageBase, + ImageSize + )); + + // + // Step 1: record whole region + // + Status =3D EFI_SUCCESS; + ImageRecord->Signature =3D IMAGE_PROPERTIES_RECORD_SIGNATURE; + ImageRecord->ImageBase =3D (EFI_PHYSICAL_ADDRESS)(UINTN)ImageBase; + ImageRecord->ImageSize =3D ImageSize; + ImageRecord->CodeSegmentCount =3D 0; + InitializeListHead (&ImageRecord->Link); + InitializeListHead (&ImageRecord->CodeSegmentList); + + // Check PE/COFF image + DosHdr =3D (EFI_IMAGE_DOS_HEADER *)(UINTN)ImageBase; + PeCoffHeaderOffset =3D 0; + if (DosHdr->e_magic =3D=3D EFI_IMAGE_DOS_SIGNATURE) { + PeCoffHeaderOffset =3D DosHdr->e_lfanew; + } + + Hdr.Pe32 =3D (EFI_IMAGE_NT_HEADERS32 *)((UINT8 *)(UINTN)ImageBase + PeCo= ffHeaderOffset); + if (Hdr.Pe32->Signature !=3D EFI_IMAGE_NT_SIGNATURE) { + DEBUG ((DEBUG_VERBOSE, "Hdr.Pe32->Signature invalid - 0x%x\n", Hdr.Pe3= 2->Signature)); + return EFI_INVALID_PARAMETER; + } + + // Get SectionAlignment + if (Hdr.Pe32->OptionalHeader.Magic =3D=3D EFI_IMAGE_NT_OPTIONAL_HDR32_MA= GIC) { + SectionAlignment =3D Hdr.Pe32->OptionalHeader.SectionAlignment; + } else { + SectionAlignment =3D Hdr.Pe32Plus->OptionalHeader.SectionAlignment; + } + + // Check RequiredAlignment + if ((RequiredAlignment !=3D NULL) && ((SectionAlignment & (*RequiredAlig= nment - 1)) !=3D 0)) { + DEBUG (( + DEBUG_WARN, + "!!!!!!!! Image Section Alignment(0x%x) does not match Required Ali= gnment (0x%x) !!!!!!!!\n", + SectionAlignment, + *RequiredAlignment + )); + + return EFI_ABORTED; + } + + Section =3D (EFI_IMAGE_SECTION_HEADER *)( + (UINT8 *)(UINTN)ImageBase + + PeCoffHeaderOffset + + sizeof (UINT32) + + sizeof (EFI_IMAGE_FILE_HEADER) + + Hdr.Pe32->FileHeader.SizeOfOption= alHeader + ); + for (Index =3D 0; Index < Hdr.Pe32->FileHeader.NumberOfSections; Index++= ) { + Name =3D Section[Index].Name; + DEBUG (( + DEBUG_VERBOSE, + " Section - '%c%c%c%c%c%c%c%c'\n", + Name[0], + Name[1], + Name[2], + Name[3], + Name[4], + Name[5], + Name[6], + Name[7] + )); + + if ((Section[Index].Characteristics & EFI_IMAGE_SCN_CNT_CODE) !=3D 0) { + DEBUG ((DEBUG_VERBOSE, " VirtualSize - 0x%08x\n", Section[= Index].Misc.VirtualSize)); + DEBUG ((DEBUG_VERBOSE, " VirtualAddress - 0x%08x\n", Section[= Index].VirtualAddress)); + DEBUG ((DEBUG_VERBOSE, " SizeOfRawData - 0x%08x\n", Section[= Index].SizeOfRawData)); + DEBUG ((DEBUG_VERBOSE, " PointerToRawData - 0x%08x\n", Section[= Index].PointerToRawData)); + DEBUG ((DEBUG_VERBOSE, " PointerToRelocations - 0x%08x\n", Section[= Index].PointerToRelocations)); + DEBUG ((DEBUG_VERBOSE, " PointerToLinenumbers - 0x%08x\n", Section[= Index].PointerToLinenumbers)); + DEBUG ((DEBUG_VERBOSE, " NumberOfRelocations - 0x%08x\n", Section[= Index].NumberOfRelocations)); + DEBUG ((DEBUG_VERBOSE, " NumberOfLinenumbers - 0x%08x\n", Section[= Index].NumberOfLinenumbers)); + DEBUG ((DEBUG_VERBOSE, " Characteristics - 0x%08x\n", Section[= Index].Characteristics)); + + // Record code section(s) + ImageRecordCodeSection =3D AllocatePool (sizeof (*ImageRecordCodeSec= tion)); + if (ImageRecordCodeSection =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + ImageRecordCodeSection->Signature =3D IMAGE_PROPERTIES_RECORD_CODE_S= ECTION_SIGNATURE; + + ImageRecordCodeSection->CodeSegmentBase =3D (UINTN)ImageBase + Secti= on[Index].VirtualAddress; + ImageRecordCodeSection->CodeSegmentSize =3D Section[Index].SizeOfRaw= Data; + + InsertTailList (&ImageRecord->CodeSegmentList, &ImageRecordCodeSecti= on->Link); + ImageRecord->CodeSegmentCount++; + } + } + + if (ImageRecord->CodeSegmentCount > 0) { + SortImageRecordCodeSection (ImageRecord); + } + + return Status; +} + +/** + Deleted an image properties record. The function will also call + RemoveEntryList() on each code segment and the input ImageRecord before + freeing each pool. + + @param[in] ImageRecord The IMAGE_PROPERTIES_RECORD to d= elete +**/ +VOID +EFIAPI +DeleteImagePropertiesRecord ( + IN IMAGE_PROPERTIES_RECORD *ImageRecord + ) +{ + LIST_ENTRY *CodeSegmentListHead; + IMAGE_PROPERTIES_RECORD_CODE_SECTION *ImageRecordCodeSection; + + if (ImageRecord =3D=3D NULL) { + return; + } + + CodeSegmentListHead =3D &ImageRecord->CodeSegmentList; + while (!IsListEmpty (CodeSegmentListHead)) { + ImageRecordCodeSection =3D CR ( + CodeSegmentListHead->ForwardLink, + IMAGE_PROPERTIES_RECORD_CODE_SECTION, + Link, + IMAGE_PROPERTIES_RECORD_CODE_SECTION_SIGNAT= URE + ); + RemoveEntryList (&ImageRecordCodeSection->Link); + FreePool (ImageRecordCodeSection); + } + + if (!IsListEmpty (&ImageRecord->Link)) { + RemoveEntryList (&ImageRecord->Link); + } + + FreePool (ImageRecord); +} diff --git a/MdeModulePkg/Include/Library/ImagePropertiesRecordLib.h b/MdeM= odulePkg/Include/Library/ImagePropertiesRecordLib.h index 90e6a262463c..99e030c988f3 100644 --- a/MdeModulePkg/Include/Library/ImagePropertiesRecordLib.h +++ b/MdeModulePkg/Include/Library/ImagePropertiesRecordLib.h @@ -155,4 +155,43 @@ DumpImageRecord ( IN LIST_ENTRY *ImageRecordList ); =20 +/** + Creates an IMAGE_PROPERTIES_RECORD from a loaded PE image. The PE/COFF h= eader will be found + and parsed to determine the number of code segments and their base addre= sses and sizes. + + @param[in] ImageBase Base of the PE image + @param[in] ImageSize Size of the PE image + @param[in] RequiredAlignment If non-NULL, the alignment speci= fied in the PE/COFF header + will be compared against this va= lue. + @param[out] ImageRecord On out, a populated image proper= ties record + + @retval EFI_INVALID_PARAMETER This function ImageBase or ImageReco= rd was NULL, or the + image located at ImageBase was not a= valid PE/COFF image + @retval EFI_OUT_OF_RESOURCES Failure to Allocate() + @retval EFI_ABORTED The input Alignment was non-NULL and= did not match the + alignment specified in the PE/COFF h= eader + @retval EFI_SUCCESS The image properties record was succ= essfully created +**/ +EFI_STATUS +EFIAPI +CreateImagePropertiesRecord ( + IN CONST VOID *ImageBase, + IN CONST UINT64 ImageSize, + IN CONST UINT32 *Alignment OPTIONAL, + OUT IMAGE_PROPERTIES_RECORD *ImageRecord + ); + +/** + Deleted an image properties record. The function will also call + RemoveEntryList() on each code segment and the input ImageRecord before + freeing each pool. + + @param[in] ImageRecord The IMAGE_PROPERTIES_RECORD to d= elete +**/ +VOID +EFIAPI +DeleteImagePropertiesRecord ( + IN IMAGE_PROPERTIES_RECORD *ImageRecord + ); + #endif diff --git a/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesR= ecordLib.inf b/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertie= sRecordLib.inf index 4c1466fc3336..cfe0c04b3b05 100644 --- a/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLi= b.inf +++ b/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLi= b.inf @@ -23,6 +23,7 @@ [LibraryClasses] BaseLib BaseMemoryLib DebugLib + MemoryAllocationLib =20 [Packages] MdePkg/MdePkg.dec --=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 (#107209): https://edk2.groups.io/g/devel/message/107209 Mute This Topic: https://groups.io/mt/100342608/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 Mon May 13 00:36:34 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+107210+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+107210+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1690248935; cv=none; d=zohomail.com; s=zohoarc; b=as7T/3FC41gWi2945gQ6Sam0CLAwzKXBMC54znQG1r/PtYRbJX2WiqE4JoEeIQHujWxvrx3zt1+bQ564c2Lsu4iIzMSp26iZEfEvQ1+RPDQlAqUBmaFj8ji27NfAU33tqYOajMV9N4zrKgldMrEmqj300dWCYXEKdrPVma30c+8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690248935; 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=EmocAyZ7Onci6QTQfLGsdIZNq5OedJDlOVm/hVKmW3g=; b=Chel6V140drufnf98QPPnHESnN4WV2B1Li8MtBmb1BGLclyWMJDWT+VLHy9f6LSnpmfRROo/yTipwrOlqejNocIWiSmPstPOnNTcoFENd0RUdT01Bk32VBIsvo78hvvvZwHL0aYMt8+LtwB3vDk2Wi8LuMvryklZwpsBfaafq6s= 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+107210+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 169024893588930.14131812626772; Mon, 24 Jul 2023 18:35:35 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=xVfU0nOqI8+/6D7rJk02P724/KwVmK3yZpaVQFFf9EI=; 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-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1690248935; v=1; b=n0z1hfci8nQ5IcINMN8xl3juP9LJr/MCrbAX0/L7QPJn+6eqaI9eO2Eb7TrXlyBhz9Vlwmjb 3I1sePws2+OIRrn9zYGOhp7vFzj4WWKCxcTX2gFKNwYQxybQGUt/kexTuePX0zPM4RJo6LcFMaL 2VdrBr8h1g78ym/xWiEtnevQ= X-Received: by 127.0.0.2 with SMTP id T0q2YY1788612xX1GWC0bu5E; Mon, 24 Jul 2023 18:35:35 -0700 X-Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) by mx.groups.io with SMTP id smtpd.web11.11430.1690248934966436817 for ; Mon, 24 Jul 2023 18:35:35 -0700 X-Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-1b89d47ffb6so25186045ad.2 for ; Mon, 24 Jul 2023 18:35:34 -0700 (PDT) X-Gm-Message-State: VvEes58h0RpGWLjd0ENiUEnDx1787277AA= X-Google-Smtp-Source: APBJJlGx/TdGBJF99Lb1eoXT9GVAmjy0QzpKqEvTShEdMBZTIJ7NXf5GEYcZngqYwLNnUcL4YtURog== X-Received: by 2002:a17:902:bd86:b0:1b8:3590:358a with SMTP id q6-20020a170902bd8600b001b83590358amr7606480pls.19.1690248934126; Mon, 24 Jul 2023 18:35:34 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.230.135]) by smtp.gmail.com with ESMTPSA id f8-20020a170902ce8800b001b893b689a0sm9630868plg.84.2023.07.24.18.35.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jul 2023 18:35:33 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Jian J Wang , Liming Gao , Dandan Bi Subject: [edk2-devel] [PATCH v3 13/14] MdeModulePkg: Update Function Headers in ImagePropertiesRecordLib Date: Mon, 24 Jul 2023 18:35:12 -0700 Message-ID: <20230725013513.1403-14-t@taylorbeebe.com> In-Reply-To: <20230725013513.1403-1-t@taylorbeebe.com> References: <20230725013513.1403-1-t@taylorbeebe.com> MIME-Version: 1.0 Precedence: Bulk 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 List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1690248936524100045 Content-Type: text/plain; charset="utf-8" Update function headers to clarify the contract of each function and improve readability. Signed-off-by: Taylor Beebe Cc: Jian J Wang Cc: Liming Gao Cc: Dandan Bi --- MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.c |= 220 ++++++++++---------- MdeModulePkg/Include/Library/ImagePropertiesRecordLib.h |= 114 +++++----- 2 files changed, 162 insertions(+), 172 deletions(-) diff --git a/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesR= ecordLib.c b/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesR= ecordLib.c index 9ac3afdaa202..0c96e4220964 100644 --- a/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLi= b.c +++ b/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLi= b.c @@ -23,14 +23,13 @@ ((EFI_MEMORY_DESCRIPTOR *)((UINT8 *)(MemoryDescriptor) + (Size))) =20 /** - Converts a number of EFI_PAGEs to a size in bytes. + Converts a number of pages to a size in bytes. =20 NOTE: Do not use EFI_PAGES_TO_SIZE because it handles UINTN only. =20 - @param Pages The number of EFI_PAGES. + @param[in] Pages The number of EFI_PAGES. =20 - @return The number of bytes associated with the number of EFI_PAGEs spe= cified - by Pages. + @retval The number of bytes associated with the input number of pages. **/ STATIC UINT64 @@ -46,10 +45,9 @@ EfiPagesToSize ( =20 NOTE: Do not use EFI_SIZE_TO_PAGES because it handles UINTN only. =20 - @param Size A size in bytes. + @param[in] Size A size in bytes. =20 - @return The number of EFI_PAGESs associated with the number of bytes sp= ecified - by Size. + @retval The number of pages associated with the input number of bytes. =20 **/ STATIC @@ -62,12 +60,12 @@ EfiSizeToPages ( } =20 /** - Sort memory map entries based upon PhysicalStart, from low to high. + Sort memory map entries based upon PhysicalStart from low to high. =20 - @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. + @param[in, out] MemoryMap A pointer to the buffer in which firmwar= e places + the current memory map. + @param[in] MemoryMapSize Size, in bytes, of the MemoryMap buffer. + @param[in] DescriptorSize Size, in bytes, of an individual EFI_MEM= ORY_DESCRIPTOR. **/ STATIC VOID @@ -106,11 +104,12 @@ SortMemoryMap ( /** Return the first image record, whose [ImageBase, ImageSize] covered by [= Buffer, Length]. =20 - @param Buffer Start Address - @param Length Address length - @param ImageRecordList Image record list + @param[in] Buffer Starting Address + @param[in] Length Length to check + @param[in] ImageRecordList A list of IMAGE_PROPERTIES_RECORD entries to= check against + the memory range Buffer -> Buffer + Length =20 - @return first image record covered by [buffer, length] + @retval The first image record covered by [Buffer, Length] **/ STATIC IMAGE_PROPERTIES_RECORD * @@ -145,17 +144,19 @@ GetImageRecordByAddress ( } =20 /** - Set the memory map to new entries, according to one old entry, - based upon PE code section and data section in image record + Break up the input OldRecord into multiple new records based on the code + and data sections in the input ImageRecord. =20 - @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. + @param[in] ImageRecord An IMAGE_PROPERTIES_RECORD whose Ima= geBase and + ImageSize is covered by by OldRecord. + @param[in, out] NewRecord A pointer to several new memory map = entries. + The caller gurantee the buffer size = be 1 + + (SplitRecordCount * DescriptorSize) = calculated + below. + @param[in] OldRecord A pointer to one old memory map entr= y. + @param[in] DescriptorSize The size, in bytes, of an individual= EFI_MEMORY_DESCRIPTOR. + + @retval The number of new descriptors created. **/ STATIC UINTN @@ -245,16 +246,16 @@ SetNewRecord ( } =20 /** - Return the max number of new splitted entries, according to one old entr= y, - based upon PE code section and data section. + Return the maximum number of new entries required to describe the code a= nd data sections + of all images covered by the input OldRecord. =20 - @param OldRecord A pointer to one old memory map entry. - @param ImageRecordList A list of IMAGE_PROPERTIES_RECORD entries= used when searching - for an image record contained by the memo= ry range described in - the existing EFI memory map descriptor Ol= dRecord + @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 by + OldRecord =20 - @retval 0 no entry need to be splitted. - @return the max number of new splitted entries + @retval The maximum number of new descriptors required to describe the = code and data sections + of all images covered by OldRecord. **/ STATIC UINTN @@ -290,22 +291,20 @@ GetMaxSplitRecordCount ( } =20 /** - Split the memory map to new entries, according to one old entry, - based upon PE code section and data section. + Split the memory map into new entries based upon the PE code and data se= ctions + in ImageRecordList covered by the input OldRecord. =20 - @param OldRecord A pointer to one old memory map entr= y. - @param NewRecord A pointer to several new memory map = entries. - The caller gurantee the buffer size = be 1 + - (SplitRecordCount * DescriptorSize) = calculated - below. - @param MaxSplitRecordCount The max number of splitted entries - @param DescriptorSize Size, in bytes, of an individual EFI= _MEMORY_DESCRIPTOR. - @param ImageRecordList A list of IMAGE_PROPERTIES_RECORD en= tries used when searching - for an image record contained by the= memory range described in - the existing EFI memory map descript= or OldRecord + @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 + (SplitRecordCount * DescriptorSi= ze). + @param[in] MaxSplitRecordCount The maximum number of entries po= st-split. + @param[in] DescriptorSize The size, in bytes, of an indivi= dual 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 =20 - @retval 0 no entry is splitted. - @return the real number of splitted record. + @retval The number of split entries. **/ STATIC UINTN @@ -403,54 +402,42 @@ SplitRecord ( } =20 /** - 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. + Split the original memory map and add more entries to describe PE code + and data sections for each image in the input ImageRecordList. =20 - NOTE: It assumes PE code/data section are page aligned. - NOTE: It assumes enough entry is prepared for new memory map. + NOTE: This function assumes PE code/data section are page aligned. + NOTE: This function assumes there are enough entries for the new memory = map. =20 - 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 | - +---------------+ + | | | | | | | | + | 4K PAGE | DATA | CODE | DATA | CODE | DATA | 4K PAGE | + | | | | | | | | + Assume the above memory region is the result of one split memory map des= criptor. It's unlikely + that a linker will orient an image this way, but the caller must assume = the worst case scenario. + This image layout example contains code sections oriented in a way that = maximizes the number of + descriptors which would be required to describe each section. To ensure = we have enough space + for every descriptor of the broken up memory map, the caller must assume= that every image will + have the maximum number of code sections oriented in a way which maximiz= es the number of data + sections with unrelated memory regions flanking each image within a sing= le descriptor. =20 - @param 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 MemoryMap A pointer to the buffer in which= firmware places - the current memory map. - @param DescriptorSize Size, in bytes, of an individual= EFI_MEMORY_DESCRIPTOR. - @param ImageRecordList A list of IMAGE_PROPERTIES_RECOR= D entries used when searching - for an image record contained by= the memory range described in - EFI memory map descriptors. - @param NumberOfAdditionalDescriptors The number of unused descriptors= at the end of the input MemoryMap. + Given an image record list, the caller should use the following formula = when allocating extra descriptors: + NumberOfAdditionalDescriptors =3D (MemoryMapSize / DescriptorSize) + + ((2 * + 3) * ) + + @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. + The formula in the descr= iption should be used to calculate this value. **/ VOID EFIAPI @@ -523,10 +510,10 @@ SplitTable ( } =20 /** - Swap two code sections in image record. + Swap two code sections in a single IMAGE_PROPERTIES_RECORD. =20 - @param FirstImageRecordCodeSection first code section in image record - @param SecondImageRecordCodeSection second code section in image reco= rd + @param[in] FirstImageRecordCodeSection The first code section + @param[in] SecondImageRecordCodeSection The second code section **/ STATIC VOID @@ -548,9 +535,9 @@ SwapImageRecordCodeSection ( } =20 /** - Sort code section in image record, based upon CodeSegmentBase from low t= o high. + Sort the code sections in the input ImageRecord based upon CodeSegmentBa= se from low to high. =20 - @param ImageRecord image record to be sorted + @param[in] ImageRecord IMAGE_PROPERTIES_RECORD to be sorted **/ VOID EFIAPI @@ -597,12 +584,15 @@ SortImageRecordCodeSection ( } =20 /** - Check if code section in image record is valid. + Check if the code sections in the input ImageRecord are valid. + The code sections are valid if they don't overlap, are contained + within the the ImageRecord's ImageBase and ImageSize, and are + contained within the MAX_ADDRESS. =20 - @param ImageRecord image record to be checked + @param[in] ImageRecord IMAGE_PROPERTIES_RECORD to be checked =20 - @retval TRUE image record is valid - @retval FALSE image record is invalid + @retval TRUE The code sections in the input ImageRecord are valid + @retval FALSE The code sections in the input ImageRecord are invalid **/ BOOLEAN EFIAPI @@ -662,8 +652,8 @@ IsImageRecordCodeSectionValid ( /** Swap two image records. =20 - @param FirstImageRecord first image record. - @param SecondImageRecord second image record. + @param[in] FirstImageRecord The first image record. + @param[in] SecondImageRecord The second image record. **/ STATIC VOID @@ -690,9 +680,9 @@ SwapImageRecord ( } =20 /** - Sort image record based upon the ImageBase from low to high. + Sort the input ImageRecordList based upon the ImageBase from low to high. =20 - @param ImageRecordList Image record list to be sorted + @param[in] ImageRecordList Image record list to be sorted **/ VOID EFIAPI @@ -739,7 +729,10 @@ SortImageRecord ( /** Dump image record. =20 - @param[in] ImageRecordList A list of IMAGE_PROPERTIES_RECORD entries +/** + Debug dumps the input list of IMAGE_PROPERTIES_RECORD structs + + @param[in] ImageRecordList Head of the IMAGE_PROPERTIES_RECORD list **/ VOID EFIAPI @@ -766,13 +759,16 @@ DumpImageRecord ( } =20 /** - Find image record according to image base and size. + Find image properties record according to image base and size in the + input ImageRecordList. =20 - @param ImageBase Base of PE image - @param ImageSize Size of PE image - @param ImageRecordList Image record list to be searched + @param[in] ImageBase Base of PE image + @param[in] ImageSize Size of PE image + @param[in] ImageRecordList Image record list to be searched =20 - @return image record + @retval NULL No IMAGE_PROPERTIES_RECORD matches ImageBase + and ImageSize in the input ImageRecordList + @retval Other The found IMAGE_PROPERTIES_RECORD **/ IMAGE_PROPERTIES_RECORD * EFIAPI diff --git a/MdeModulePkg/Include/Library/ImagePropertiesRecordLib.h b/MdeM= odulePkg/Include/Library/ImagePropertiesRecordLib.h index 99e030c988f3..107255d9e16d 100644 --- a/MdeModulePkg/Include/Library/ImagePropertiesRecordLib.h +++ b/MdeModulePkg/Include/Library/ImagePropertiesRecordLib.h @@ -32,54 +32,42 @@ typedef struct { } IMAGE_PROPERTIES_RECORD; =20 /** - 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. + Split the original memory map and add more entries to describe PE code + and data sections for each image in the input ImageRecordList. =20 - NOTE: It assumes PE code/data section are page aligned. - NOTE: It assumes enough entry is prepared for new memory map. + NOTE: This function assumes PE code/data section are page aligned. + NOTE: This function assumes there are enough entries for the new memory = map. =20 - 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 | - +---------------+ + | | | | | | | | + | 4K PAGE | DATA | CODE | DATA | CODE | DATA | 4K PAGE | + | | | | | | | | + Assume the above memory region is the result of one split memory map des= criptor. It's unlikely + that a linker will orient an image this way, but the caller must assume = the worst case scenario. + This image layout example contains code sections oriented in a way that = maximizes the number of + descriptors which would be required to describe each section. To ensure = we have enough space + for every descriptor of the broken up memory map, the caller must assume= that every image will + have the maximum number of code sections oriented in a way which maximiz= es the number of data + sections with unrelated memory regions flanking each image within a sing= le descriptor. =20 - @param 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 MemoryMap A pointer to the buffer in which= firmware places - the current memory map. - @param DescriptorSize Size, in bytes, of an individual= EFI_MEMORY_DESCRIPTOR. - @param ImageRecordList A list of IMAGE_PROPERTIES_RECOR= D entries used when searching - for an image record contained by= the memory range described in - EFI memory map descriptors. - @param NumberOfAdditionalDescriptors The number of unused descriptors= at the end of the input MemoryMap. + Given an image record list, the caller should use the following formula = when allocating extra descriptors: + NumberOfAdditionalDescriptors =3D (MemoryMapSize / DescriptorSize) + + ((2 * + 3) * ) + + @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. + The formula in the descr= iption should be used to calculate this value. **/ VOID EFIAPI @@ -92,9 +80,9 @@ SplitTable ( ); =20 /** - Sort code section in image record, based upon CodeSegmentBase from low t= o high. + Sort the code sections in the input ImageRecord based upon CodeSegmentBa= se from low to high. =20 - @param ImageRecord image record to be sorted + @param[in] ImageRecord IMAGE_PROPERTIES_RECORD to be sorted **/ VOID EFIAPI @@ -103,12 +91,15 @@ SortImageRecordCodeSection ( ); =20 /** - Check if code section in image record is valid. + Check if the code sections in the input ImageRecord are valid. + The code sections are valid if they don't overlap, are contained + within the the ImageRecord's ImageBase and ImageSize, and are + contained within the MAX_ADDRESS. =20 - @param ImageRecord image record to be checked + @param[in] ImageRecord IMAGE_PROPERTIES_RECORD to be checked =20 - @retval TRUE image record is valid - @retval FALSE image record is invalid + @retval TRUE The code sections in the input ImageRecord are valid + @retval FALSE The code sections in the input ImageRecord are invalid **/ BOOLEAN EFIAPI @@ -117,9 +108,9 @@ IsImageRecordCodeSectionValid ( ); =20 /** - Sort image record based upon the ImageBase from low to high. + Sort the input ImageRecordList based upon the ImageBase from low to high. =20 - @param ImageRecordList Image record list to be sorted + @param[in] ImageRecordList A list of IMAGE_PROPERTIES_RECORD entries **/ VOID EFIAPI @@ -128,13 +119,16 @@ SortImageRecord ( ); =20 /** - Find image record according to image base and size. + Find image properties record according to image base and size in the + input ImageRecordList. =20 - @param ImageBase Base of PE image - @param ImageSize Size of PE image - @param ImageRecordList Image record list to be searched + @param[in] ImageBase Base of PE image + @param[in] ImageSize Size of PE image + @param[in] ImageRecordList Image record list to be searched =20 - @return image record + @retval NULL No IMAGE_PROPERTIES_RECORD matches ImageBase + and ImageSize in the input ImageRecordList + @retval Other The found IMAGE_PROPERTIES_RECORD **/ IMAGE_PROPERTIES_RECORD * EFIAPI @@ -145,9 +139,9 @@ FindImageRecord ( ); =20 /** - Dump image record. + DEBUG dump the input ImageRecordList. =20 - @param[in] ImageRecordList A list of IMAGE_PROPERTIES_RECORD entries + @param[in] ImageRecordList Head of the IMAGE_PROPERTIES_RECORD list **/ VOID EFIAPI --=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 (#107210): https://edk2.groups.io/g/devel/message/107210 Mute This Topic: https://groups.io/mt/100342609/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 Mon May 13 00:36:34 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+107211+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+107211+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1690248936; cv=none; d=zohomail.com; s=zohoarc; b=J7Gv5i+8bqNA/IKkexdIoMpjG+dqkxK+8lVzfZqxt3vLi29znWQZswgMK8GMiAXJkFl1G7kX47IkP2XOqvm+uL9ZsyW6h0OKZVwWAp2dvVuW4rptHoxA936dFGPihtNyasppCBdXe4Vo3uxzGL6EPoBijIIwvEpETP9pFAad3uc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690248936; 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=7ktGZCmewj+G84ZrctT0FWV0c3SXscvUzWnwRREjnlc=; b=Uh1NokJFSH+11UT9dc9OfyuA0sDa51i9uhrqTsZPpow5wxdfr2IprzTgjNdr9PUxRoJ+ApG19g6RyYjo0rlat0kExl7QtLs5R51ECpflCAc9/100qiWYnvZOvmv8Uun9fpXD1xMKEMeCDCToTBoLLIycolhmSONNG6bZbSVBkSY= 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+107211+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1690248936399183.89886542704392; Mon, 24 Jul 2023 18:35:36 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=MaRp+y0n8HGQOvulhr4aMdVJC0ZLcX752sgY5GF0av8=; 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-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1690248936; v=1; b=c4wiBMdNTitaEbkjfa2yZ1dsHvEKPour/xLgeGZwdyuDKWgDfw6YlNtQerkFvHzHiG1hGX2l prFiET6FzPEzM6gs75LDJwJBMNnCwyXNisD3rkkEMIGQ8Urkv8KFZ+RHOWDxc+hgrA+1RQxQ+46 c3Skrz9KibfOjf64yLddyePU= X-Received: by 127.0.0.2 with SMTP id iqVHYY1788612x0k1fRTMIAs; Mon, 24 Jul 2023 18:35:36 -0700 X-Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.172]) by mx.groups.io with SMTP id smtpd.web10.11293.1690248935644661510 for ; Mon, 24 Jul 2023 18:35:35 -0700 X-Received: by mail-pg1-f172.google.com with SMTP id 41be03b00d2f7-56341268f2fso2498642a12.0 for ; Mon, 24 Jul 2023 18:35:35 -0700 (PDT) X-Gm-Message-State: p9hSUFHwYCX2Z0oeE3dtSSLFx1787277AA= X-Google-Smtp-Source: APBJJlHgpicaUD17LQ4i6QEp/op7BYC2Z8/mjcMfw7Ubr7kqY3wN+lvj57dKN8HeyfLxHyXq7iE1DQ== X-Received: by 2002:a05:6a21:6d98:b0:132:1e76:6f02 with SMTP id wl24-20020a056a216d9800b001321e766f02mr12427403pzb.34.1690248934817; Mon, 24 Jul 2023 18:35:34 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.230.135]) by smtp.gmail.com with ESMTPSA id f8-20020a170902ce8800b001b893b689a0sm9630868plg.84.2023.07.24.18.35.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jul 2023 18:35:34 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Jian J Wang , Liming Gao , Dandan Bi Subject: [edk2-devel] [PATCH v3 14/14] MdeModulePkg: Update DumpImageRecord() in ImagePropertiesRecordLib Date: Mon, 24 Jul 2023 18:35:13 -0700 Message-ID: <20230725013513.1403-15-t@taylorbeebe.com> In-Reply-To: <20230725013513.1403-1-t@taylorbeebe.com> References: <20230725013513.1403-1-t@taylorbeebe.com> MIME-Version: 1.0 Precedence: Bulk 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 List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1690248938530100054 Content-Type: text/plain; charset="utf-8" Update DumpImageRecord() to be DumpImageRecords(), and improve the debug output. The function will output at DEBUG_INFO instead, and the function will be run in DXE and SMM MAT logic when the MAT is installed at EndOfDxe on DEBUG builds. Signed-off-by: Taylor Beebe Cc: Jian J Wang Cc: Liming Gao Cc: Dandan Bi --- MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c = | 9 ++ MdeModulePkg/Core/PiSmmCore/MemoryAttributesTable.c = | 11 +- MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.c = | 131 +++++++++++++++++--- MdeModulePkg/Include/Library/ImagePropertiesRecordLib.h = | 2 +- MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.inf= | 1 + MdeModulePkg/Test/MdeModulePkgHostTest.dsc = | 1 + 6 files changed, 133 insertions(+), 22 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c b/MdeModule= Pkg/Core/Dxe/Misc/MemoryAttributesTable.c index 993db281062a..e9343a2c4ef1 100644 --- a/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c +++ b/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c @@ -284,6 +284,15 @@ InstallMemoryAttributesTableOnEndOfDxe ( { mMemoryAttributesTableEndOfDxe =3D TRUE; InstallMemoryAttributesTable (); + + DEBUG_CODE_BEGIN (); + if ( mImagePropertiesPrivateData.ImageRecordCount > 0) { + DEBUG ((DEBUG_INFO, "DXE - Total Runtime Image Count: 0x%x\n", mImageP= ropertiesPrivateData.ImageRecordCount)); + DEBUG ((DEBUG_INFO, "DXE - Dump Runtime Image Records:\n")); + DumpImageRecords (&mImagePropertiesPrivateData.ImageRecordList); + } + + DEBUG_CODE_END (); } =20 /** diff --git a/MdeModulePkg/Core/PiSmmCore/MemoryAttributesTable.c b/MdeModul= ePkg/Core/PiSmmCore/MemoryAttributesTable.c index 03de9b2c5fff..28fe74ecc421 100644 --- a/MdeModulePkg/Core/PiSmmCore/MemoryAttributesTable.c +++ b/MdeModulePkg/Core/PiSmmCore/MemoryAttributesTable.c @@ -496,9 +496,14 @@ SmmInstallMemoryAttributesTable ( return EFI_SUCCESS; } =20 - DEBUG ((DEBUG_VERBOSE, "SMM Total Image Count - 0x%x\n", mImagePropertie= sPrivateData.ImageRecordCount)); - DEBUG ((DEBUG_VERBOSE, "SMM Dump ImageRecord:\n")); - DumpImageRecord (&mImagePropertiesPrivateData.ImageRecordList); + DEBUG_CODE_BEGIN (); + if ( mImagePropertiesPrivateData.ImageRecordCount > 0) { + DEBUG ((DEBUG_INFO, "SMM - Total Runtime Image Count - 0x%x\n", mImage= PropertiesPrivateData.ImageRecordCount)); + DEBUG ((DEBUG_INFO, "SMM - Dump Runtime Image Records:\n")); + DumpImageRecords (&mImagePropertiesPrivateData.ImageRecordList); + } + + DEBUG_CODE_END (); =20 PublishMemoryAttributesTable (); =20 diff --git a/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesR= ecordLib.c b/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesR= ecordLib.c index 0c96e4220964..b025c9485c6c 100644 --- a/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLi= b.c +++ b/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLi= b.c @@ -14,6 +14,7 @@ #include #include #include +#include #include =20 #define PREVIOUS_MEMORY_DESCRIPTOR(MemoryDescriptor, Size) \ @@ -727,34 +728,128 @@ SortImageRecord ( } =20 /** - Dump image record. + Extract the .efi filename out of the input PDB. + + @param[in] PdbPointer Pointer to the PDB file path. + @param[out] EfiFileName Pointer to the .efi filename. + @param[in] EfiFileNameSize Size of the .efi filename buffer. +**/ +STATIC +VOID +GetFilename ( + IN CHAR8 *PdbPointer, + OUT CHAR8 *EfiFileName, + IN UINTN EfiFileNameSize + ) +{ + UINTN Index; + UINTN StartIndex; + + if ((PdbPointer =3D=3D NULL) || (EfiFileNameSize < 5)) { + return; + } + + // Print Module Name by Pdb file path. + StartIndex =3D 0; + for (Index =3D 0; PdbPointer[Index] !=3D 0; Index++) { + if ((PdbPointer[Index] =3D=3D '\\') || (PdbPointer[Index] =3D=3D '/'))= { + StartIndex =3D Index + 1; + } + } + + // Copy the PDB file name to EfiFileName and replace .pdb with .efi + for (Index =3D 0; Index < EfiFileNameSize - 4; Index++) { + EfiFileName[Index] =3D PdbPointer[Index + StartIndex]; + if (EfiFileName[Index] =3D=3D 0) { + EfiFileName[Index] =3D '.'; + } + + if (EfiFileName[Index] =3D=3D '.') { + EfiFileName[Index + 1] =3D 'e'; + EfiFileName[Index + 2] =3D 'f'; + EfiFileName[Index + 3] =3D 'i'; + EfiFileName[Index + 4] =3D 0; + break; + } + } + + if (Index =3D=3D sizeof (EfiFileName) - 4) { + EfiFileName[Index] =3D 0; + } +} =20 /** - Debug dumps the input list of IMAGE_PROPERTIES_RECORD structs + Debug dumps the input list of IMAGE_PROPERTIES_RECORD structs. =20 @param[in] ImageRecordList Head of the IMAGE_PROPERTIES_RECORD list **/ VOID EFIAPI -DumpImageRecord ( +DumpImageRecords ( 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)); + LIST_ENTRY *ImageRecordLink; + IMAGE_PROPERTIES_RECORD *CurrentImageRecord; + LIST_ENTRY *CodeSectionLink; + IMAGE_PROPERTIES_RECORD_CODE_SECTION *CurrentCodeSection; + CHAR8 *PdbPointer; + CHAR8 EfiFileName[256]; + + if (ImageRecordList =3D=3D NULL) { + return; + } + + ImageRecordLink =3D ImageRecordList->ForwardLink; + + while (ImageRecordLink !=3D ImageRecordList) { + CurrentImageRecord =3D CR ( + ImageRecordLink, + IMAGE_PROPERTIES_RECORD, + Link, + IMAGE_PROPERTIES_RECORD_SIGNATURE + ); + + PdbPointer =3D PeCoffLoaderGetPdbPointer ((VOID *)(UINTN)CurrentImageR= ecord->ImageBase); + if (PdbPointer !=3D NULL) { + GetFilename (PdbPointer, EfiFileName, sizeof (EfiFileName)); + DEBUG (( + DEBUG_INFO, + "%a: 0x%llx - 0x%llx\n", + EfiFileName, + CurrentImageRecord->ImageBase, + CurrentImageRecord->ImageBase + CurrentImageRecord->ImageSize + )); + } else { + DEBUG (( + DEBUG_INFO, + "Unknown Image: 0x%llx - 0x%llx\n", + CurrentImageRecord->ImageBase, + CurrentImageRecord->ImageBase + CurrentImageRecord->ImageSize + )); + } + + CodeSectionLink =3D CurrentImageRecord->CodeSegmentList.ForwardLink; + + while (CodeSectionLink !=3D &CurrentImageRecord->CodeSegmentList) { + CurrentCodeSection =3D CR ( + CodeSectionLink, + IMAGE_PROPERTIES_RECORD_CODE_SECTION, + Link, + IMAGE_PROPERTIES_RECORD_CODE_SECTION_SIGNATURE + ); + + DEBUG (( + DEBUG_INFO, + " Code Section: 0x%llx - 0x%llx\n", + CurrentCodeSection->CodeSegmentBase, + CurrentCodeSection->CodeSegmentBase + CurrentCodeSection->CodeSegm= entSize + )); + + CodeSectionLink =3D CodeSectionLink->ForwardLink; + } + + ImageRecordLink =3D ImageRecordLink->ForwardLink; } } =20 diff --git a/MdeModulePkg/Include/Library/ImagePropertiesRecordLib.h b/MdeM= odulePkg/Include/Library/ImagePropertiesRecordLib.h index 107255d9e16d..5ce38bcb3f83 100644 --- a/MdeModulePkg/Include/Library/ImagePropertiesRecordLib.h +++ b/MdeModulePkg/Include/Library/ImagePropertiesRecordLib.h @@ -145,7 +145,7 @@ FindImageRecord ( **/ VOID EFIAPI -DumpImageRecord ( +DumpImageRecords ( IN LIST_ENTRY *ImageRecordList ); =20 diff --git a/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesR= ecordLib.inf b/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertie= sRecordLib.inf index cfe0c04b3b05..1f82cc3e469c 100644 --- a/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLi= b.inf +++ b/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLi= b.inf @@ -24,6 +24,7 @@ [LibraryClasses] BaseMemoryLib DebugLib MemoryAllocationLib + PeCoffGetEntryPointLib =20 [Packages] MdePkg/MdePkg.dec diff --git a/MdeModulePkg/Test/MdeModulePkgHostTest.dsc b/MdeModulePkg/Test= /MdeModulePkgHostTest.dsc index 2b8cbb867a73..198cdd814fb9 100644 --- a/MdeModulePkg/Test/MdeModulePkgHostTest.dsc +++ b/MdeModulePkg/Test/MdeModulePkgHostTest.dsc @@ -57,6 +57,7 @@ [Components] MdeModulePkg/Library/ImagePropertiesRecordLib/UnitTest/ImagePropertiesRe= cordLibUnitTestHost.inf { ImagePropertiesRecordLib|MdeModulePkg/Library/ImagePropertiesRecordL= ib/ImagePropertiesRecordLib.inf + PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/Bas= ePeCoffGetEntryPointLib.inf } =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 (#107211): https://edk2.groups.io/g/devel/message/107211 Mute This Topic: https://groups.io/mt/100342610/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-