From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mx.groups.io with SMTP id smtpd.web11.4124.1685429122885334885 for ; Mon, 29 May 2023 23:45:23 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=OuTxPIYC; spf=pass (domain: intel.com, ip: 134.134.136.100, mailfrom: ray.ni@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1685429122; x=1716965122; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=dj+X1TJGvPA+8CWtHryBQisLQI63cPHH6TaQiNSTptE=; b=OuTxPIYC7W/3u4NT1orL0TtiugRkJpcqcgviXTgPwLf/Ysxjyr6xGqeN PFFjC1zAUzzCCp1dbVvfkFlKjpgdIvcbNRHqkl496HB1WEu132yH63JkO fgmD0HrW1Ez1uqdbPovg3+ssr39FBWJfl/PIiEh5vHn5hjv/HxnB7mIFW LrVfRqPrA9l9U3yCyD12dajaVD/GwmfZd7yWF6Ha3SCOmdiaf9e4Z+Dad Rf9NBmgIEY7oIinexheDN3c5QRhNvIYhtJb9R3aDLMuxr9wpUDxrXZqZF 5AYTuv/1C0M49/DZaNjSfaQwI940JbklXhPNq7vWMGOus1VoCk9n/nyFy w==; X-IronPort-AV: E=McAfee;i="6600,9927,10725"; a="420590140" X-IronPort-AV: E=Sophos;i="6.00,203,1681196400"; d="scan'208";a="420590140" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 May 2023 23:45:22 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10725"; a="771407844" X-IronPort-AV: E=Sophos;i="6.00,203,1681196400"; d="scan'208";a="771407844" Received: from fmsmsx601.amr.corp.intel.com ([10.18.126.81]) by fmsmga008.fm.intel.com with ESMTP; 29 May 2023 23:45:21 -0700 Received: from fmsmsx611.amr.corp.intel.com (10.18.126.91) by fmsmsx601.amr.corp.intel.com (10.18.126.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Mon, 29 May 2023 23:45:21 -0700 Received: from fmsmsx610.amr.corp.intel.com (10.18.126.90) by fmsmsx611.amr.corp.intel.com (10.18.126.91) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Mon, 29 May 2023 23:45:21 -0700 Received: from fmsedg602.ED.cps.intel.com (10.1.192.136) by fmsmsx610.amr.corp.intel.com (10.18.126.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23 via Frontend Transport; Mon, 29 May 2023 23:45:21 -0700 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (104.47.55.175) by edgegateway.intel.com (192.55.55.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.23; Mon, 29 May 2023 23:45:20 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kdO/TDcJr3T14AipXCz4a0LELDlDgpaNk91CeXYrYDRQj65UwFNw6M5mM3+hDjZgyW0OSYlbgZe5DpUYY+WTDD9mjKXFw3J+Hu4c8ixLdx+/cNCGMGA+At+d357Jq3hDVoQyG68scZpWK9Jo5AYKJtQMEQxQOlSo9CmwFgCx/3HLg3d227N/QmXMlCrMEtj6GCrVbYA0eXQto/bKFfhSjqa68DW2MEEqnepVdFA4K8qdLk08S7WQXnzIeHYbQt74elLYVPYw2p7EQ23AiNKF9TDURNicfnpBAMjVWS9Al3eBwP+SS2uIn8aAgmqmpDWYesD9PWiysuUEYdTl7Qxoqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=lA6XULvdpql6mWl5waWgDxaFgEnaiUBou6fqJF/9t9Y=; b=KrrDDAS93jO6qB65Eha0lrsNVBNT3c7RCuPrFIjwXP6x/g4P9dwYNDGnPdjdI7vB+z3adb9CDH0tKU/rPoEKFJcgb9N0T+bijHmAAmcBbtr8t/AdwS14mJOdHrJe60jy/FLZAAvXI7hc4z3ymVBoA2ZWiA6TaVWvmuyudCCNWP0ZJcyyB1DM3DxjA8nUpdPruaOFDMVrc0dxXFsURZokes2dlJ2ivm+vq+xoxByhCgD3prPcFevbvkxOL1wxkN8Q04MhaAAka4dFrRzsKlE8oZseVexGR4XRS+RCV5O3nawC/YYKkSYDdPob9QZu7EBPCeHByO5JBv1DPLi9AvgSJA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Received: from MN6PR11MB8244.namprd11.prod.outlook.com (2603:10b6:208:470::14) by DM4PR11MB5996.namprd11.prod.outlook.com (2603:10b6:8:5f::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.23; Tue, 30 May 2023 06:45:18 +0000 Received: from MN6PR11MB8244.namprd11.prod.outlook.com ([fe80::892b:b8e6:bab7:635d]) by MN6PR11MB8244.namprd11.prod.outlook.com ([fe80::892b:b8e6:bab7:635d%5]) with mapi id 15.20.6433.018; Tue, 30 May 2023 06:45:18 +0000 From: "Ni, Ray" To: "devel@edk2.groups.io" , "ardb@kernel.org" CC: "Yao, Jiewen" , Gerd Hoffmann , Taylor Beebe , Oliver Smith-Denny , "Bi, Dandan" , "Gao, Liming" , "Kinney, Michael D" , Leif Lindholm , Michael Kubacki Subject: Re: [edk2-devel] [RFC PATCH 08/11] MdeModulePkg/DxeIpl: Relocate and remap XIP capable DXE drivers Thread-Topic: [edk2-devel] [RFC PATCH 08/11] MdeModulePkg/DxeIpl: Relocate and remap XIP capable DXE drivers Thread-Index: AQHZkhbWQSnL5GoyK0iPCRtt1cihe69yXbyQ Date: Tue, 30 May 2023 06:45:18 +0000 Message-ID: References: <20230529101705.2476949-1-ardb@kernel.org> <20230529101705.2476949-9-ardb@kernel.org> In-Reply-To: <20230529101705.2476949-9-ardb@kernel.org> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MN6PR11MB8244:EE_|DM4PR11MB5996:EE_ x-ms-office365-filtering-correlation-id: 4d8a2ed5-9863-409b-945c-08db60d96e93 x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: SWv9YAi4J3pZr9jmTt5oZ+7zqPcCXFzsRmEUvkvdlyMEp44j/Jqpvut9/6GrkMwjIHyOlf4dkzPG9YMazve7pF6byVAjWx1Kg9+LWbtANKBke9+oBBHAxiqC68recLog9ePaWOJOMxvTdIf2zzJRmCfomBpiCCYd8ZZLPJMcBZH2o1a7tNY0gwCXnkjEbS9+kuYmyR3L5pXvFKl/YfSt6GTnJcY2bCnHbl3J5BIXEvJYjKVLcgkRO5cDMsVpD/GcdTGz9dgtFd/2mcdHyH3/aFNLVjcHcdyVJI2S0+zjOhm5a2IQb4TrRAgDn4IUD6SkUn2Kv4Otxda1LjBtO9HX0YjrgwzO7dBEj+WZ+53D2qBV0V4KTaMt6fn2TlXdgb0uQphHie9XiTloPP/tdWTrbCO7yqW7q3XlMSb3xhqmCYVTc+dYk7o7awZfMO3e+wT0M8+OIwwzSUtwoTl5Mj0eU8acOWibtAW2OPrO8XPdsAIhV0bpIaeoliGRhzBd7dZ9uXCjw6ISoohBNSVpw1gcAspOs3AdEDu5zBBYMHMhXvCgej5EoQAWWmImnaGD1gco2GhlbUIgxTjxPfQ47n0qkMIamI7sjEvRuTpfEykadwRNdp9/Hx5uVA2Vgt3fyv/UV1wK2AlhA4ICkcJE1LHzRQ== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MN6PR11MB8244.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(396003)(366004)(346002)(136003)(39860400002)(376002)(451199021)(33656002)(86362001)(38070700005)(19627235002)(110136005)(54906003)(4326008)(316002)(76116006)(66946007)(66556008)(66476007)(66446008)(64756008)(478600001)(966005)(7696005)(71200400001)(55016003)(8936002)(8676002)(5660300002)(41300700001)(52536014)(2906002)(38100700002)(82960400001)(122000001)(53546011)(9686003)(6506007)(26005)(186003)(83380400001)(66899021);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?j9hVEaB4DXt/Q+b+28Ta5pyUDl1zlTrDTLzI5l2mSM0vM5Zb5sTNeVPUp8tM?= =?us-ascii?Q?eOBM0UJ3xiEoJMH8ZRzA28SgrWzaDCVDeKUp/lwNQuttj9jfjWMNgUQCaKml?= =?us-ascii?Q?yS5dfU4oPheMn6nAcKIsoSKmWo/dt1wGAAWhJfXru/z64aOf13MwDiUx2Muv?= =?us-ascii?Q?cq2b9mghcUhmU0AgyAjCUOSjyewaFm2OFyVVxkFYRkOFIcERfy5WlN8dGFu6?= =?us-ascii?Q?DvDaBcOsqKhTjAZoI35D8T/vMBqkG/0A1Q9vMIVepVahmHav3b+vPl+M3zMJ?= =?us-ascii?Q?OZYKqSJJ30803iew0UyKuXanovvI0ckd/f1dAm8COYjJi6o0Kx3Q+xiDvPca?= =?us-ascii?Q?0pqdeqjVslW96/SaV31rJwAOAsbFxnqYjvw8IxktfR5l3ON75Ajkf62oLnMV?= =?us-ascii?Q?MS2tX3llCIkEvfXsyxCGD3P4XPyU1RhSmlVKnBLUMCcHjExPHsE1vEkCg+jd?= =?us-ascii?Q?15AVfcikHULh/zo08bBVHpdLDxT2477aWH6uCdzbJ/lifYOT8tOaA2dfAJ+q?= =?us-ascii?Q?1t7wj9KwVayx/qtevsNuJyuWhukh8YIV7lTXc6A0vh6lV7DUyqQTgHjIi9Uz?= =?us-ascii?Q?qjNg3Yv6JYelslBCGdSIcFmOzRidTXubc0uzH+vZ+EsnQQ2gxkSyUwaF17b4?= =?us-ascii?Q?SuV8sXyy8XwTE3SBTtkUkFG/+zKq6c6vwL3wjT49kr277f2oLNGEUDF+SOUH?= =?us-ascii?Q?ofmuuk4x+O5RwajrCDkmKNYZLuFSKGfzkmvWrYlvKrJBMPCYp0JTqPNJ8veo?= =?us-ascii?Q?tezJkmA0oUGZiqy+ZI2tgIG0U2iiKc6dW9UmH4K+b3yWCVxoiOzNQEJZIOgo?= =?us-ascii?Q?ZedHHaNlr/dN2hkx4PBSwtR/zw3nmhi6UUfBjAujK4UwKv/xUh6vOTO7PlTX?= =?us-ascii?Q?HiJ9mzqUi2e1stvMJ2Tms1fSL1kqZN+vBV11gh1t0ZeNObXpY/ud87kUv3l1?= =?us-ascii?Q?oT3oLPUeBefKgWxRPO4kBooBfEeudSf795pda+SP6dznB3E8Wb5umqCWTCws?= =?us-ascii?Q?ywjjdq4Q+h6vPVGXut5dCywxsoClpyPZU/PPTXMSTQ2Ymm3mCNVFqWG+q20I?= =?us-ascii?Q?aBrgvMHUkr61ACZULveMyykGlYUDhdZRATUn1lGfr/wu+XtPMw/Fx1oYI1kZ?= =?us-ascii?Q?IyvIeX5tTfN8B71KbVq47483r9xNsi/WPscSVBJJMJtZkDUE5ivTPsN9rnIf?= =?us-ascii?Q?6l3KBE26Gsf+MsgcoDeYYfMiOeT+klT6qsWQvT/F0VoGwVTAvsb1GsqL0U4b?= =?us-ascii?Q?6ayYLJ4UNqHt1UzFrFDMjhQd6J6uYEdfG58IwumNvz1WAORXaR2VJayxM9fc?= =?us-ascii?Q?EIAMFPpNtYtAGikF/fYR7FWypyDCerG1gW8YBpcoLv/hdkFTwD72U0nCXPoc?= =?us-ascii?Q?H9h7MxYOqZssE+y5ET1ZfRPjWUrk7gDWu8UzXJ+kygcUiP3Qe20Ve4F7kwxy?= =?us-ascii?Q?caHhWFxlFMgwot6PIQyR9NGDRuihwj8W5PyusDaHPxr/VftdQYz/DMPx7ttX?= =?us-ascii?Q?jq0kIJp/y+65jp0PkWM6ba9k6Aw4TCdBJf6gbBBR7DbL+J0NnN8QTMYoFHgl?= =?us-ascii?Q?sTxuPxvMSCM+COIt4ig=3D?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MN6PR11MB8244.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4d8a2ed5-9863-409b-945c-08db60d96e93 X-MS-Exchange-CrossTenant-originalarrivaltime: 30 May 2023 06:45:18.1962 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: Raqw0hUPUYPPCSt2o+BM3j4NP0U47ZZZmjOP3g59KVcDFS5ZhB35ARoxbZlTKyXsITF6qz4uOLWp58fr7so1Eg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR11MB5996 Return-Path: ray.ni@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable 1. is it possible that a PE image sits in the right location but the Sectio= nAlignment is larger than FileAlignment so each section still needs to be c= opied to the aligned memory location? 2. PeCoffLoaderRelocateImage() might not be called for XIP=20 > -----Original Message----- > From: devel@edk2.groups.io On Behalf Of Ard > Biesheuvel > Sent: Monday, May 29, 2023 6:17 PM > To: devel@edk2.groups.io > Cc: Ard Biesheuvel ; Ni, Ray ; Yao, Ji= ewen > ; Gerd Hoffmann ; Taylor Beebe > ; Oliver Smith-Denny ; Bi, Dandan > ; Gao, Liming ; Kinney, > Michael D ; Leif Lindholm > ; Michael Kubacki > Subject: [edk2-devel] [RFC PATCH 08/11] MdeModulePkg/DxeIpl: Relocate and > remap XIP capable DXE drivers >=20 > Before handing over to the DXE core, iterate over all known FFS files > and find the ones that can execute in place. These files are then > relocated in place and mapped with restricted permissions, allowing the > DXE core to dispatch them without the need to perform any manipulation > of the file contents or the page table permissions. >=20 > Signed-off-by: Ard Biesheuvel > --- > MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf | 1 + > MdeModulePkg/Core/DxeIplPeim/DxeLoad.c | 196 ++++++++++++++++++++ > 2 files changed, 197 insertions(+) >=20 > diff --git a/MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf > b/MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf > index f1990eac77607854..60112100df78b396 100644 > --- a/MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf > +++ b/MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf > @@ -65,6 +65,7 @@ [LibraryClasses] > PeimEntryPoint >=20 > DebugLib >=20 > DebugAgentLib >=20 > + PeCoffLib >=20 > PeiServicesTablePointerLib >=20 > PerformanceLib >=20 >=20 >=20 > diff --git a/MdeModulePkg/Core/DxeIplPeim/DxeLoad.c > b/MdeModulePkg/Core/DxeIplPeim/DxeLoad.c > index 2c19f1a507baf34a..1f20db1faffbd1d2 100644 > --- a/MdeModulePkg/Core/DxeIplPeim/DxeLoad.c > +++ b/MdeModulePkg/Core/DxeIplPeim/DxeLoad.c > @@ -10,6 +10,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent >=20 >=20 > #include "DxeIpl.h" >=20 >=20 >=20 > +#include >=20 > +#include >=20 > + >=20 > // >=20 > // Module Globals used in the DXE to PEI hand off >=20 > // These must be module globals, so the stack can be switched >=20 > @@ -228,6 +231,197 @@ ValidateMemoryTypeInfoVariable ( > return TRUE; >=20 > } >=20 >=20 >=20 > +/** >=20 > + Support routine for the PE/COFF Loader that reads a buffer from a PE/C= OFF file. >=20 > + The function is used for XIP code to have optimized memory copy. >=20 > + >=20 > + @param FileHandle The handle to the PE/COFF file >=20 > + @param FileOffset The offset, in bytes, into the file to read >=20 > + @param ReadSize The number of bytes to read from the file start= ing at > FileOffset >=20 > + @param Buffer A pointer to the buffer to read the data into. >=20 > + >=20 > + @return EFI_SUCCESS ReadSize bytes of data were read into Buffer fr= om the >=20 > + PE/COFF file starting at FileOffset >=20 > + >=20 > +**/ >=20 > +STATIC >=20 > +EFI_STATUS >=20 > +EFIAPI >=20 > +PeiImageRead ( >=20 > + IN VOID *FileHandle, >=20 > + IN UINTN FileOffset, >=20 > + IN UINTN *ReadSize, >=20 > + OUT VOID *Buffer >=20 > + ) >=20 > +{ >=20 > + CHAR8 *Destination8; >=20 > + CHAR8 *Source8; >=20 > + >=20 > + Destination8 =3D Buffer; >=20 > + Source8 =3D (CHAR8 *)((UINTN)FileHandle + FileOffset); >=20 > + if (Destination8 !=3D Source8) { >=20 > + CopyMem (Destination8, Source8, *ReadSize); >=20 > + } >=20 > + >=20 > + return EFI_SUCCESS; >=20 > +} >=20 > + >=20 > +STATIC >=20 > +VOID >=20 > +RemapImage ( >=20 > + IN EDKII_MEMORY_ATTRIBUTE_PPI *MemoryPpi, >=20 > + IN CONST PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext >=20 > + ) >=20 > +{ >=20 > + EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr; >=20 > + EFI_IMAGE_SECTION_HEADER *Section; >=20 > + PHYSICAL_ADDRESS SectionAddress; >=20 > + EFI_STATUS Status; >=20 > + UINT64 Permissions; >=20 > + UINTN Index; >=20 > + >=20 > + if (MemoryPpi =3D=3D NULL) { >=20 > + return; >=20 > + } >=20 > + >=20 > + Hdr.Union =3D (EFI_IMAGE_OPTIONAL_HEADER_UNION *)((UINT8 > *)ImageContext->Handle + >=20 > + ImageContext->PeCoffHe= aderOffset); >=20 > + ASSERT (Hdr.Pe32->Signature =3D=3D EFI_IMAGE_NT_SIGNATURE); >=20 > + >=20 > + Section =3D (EFI_IMAGE_SECTION_HEADER *)((UINT8 *)Hdr.Union + sizeof > (UINT32) + >=20 > + sizeof (EFI_IMAGE_FILE_HEADER) = + >=20 > + Hdr.Pe32->FileHeader.SizeOfOpti= onalHeader >=20 > + ); >=20 > + >=20 > + for (Index =3D 0; Index < Hdr.Pe32->FileHeader.NumberOfSections; Index= ++) { >=20 > + SectionAddress =3D ImageContext->ImageAddress + > Section[Index].VirtualAddress; >=20 > + Permissions =3D 0; >=20 > + >=20 > + if ((Section[Index].Characteristics & EFI_IMAGE_SCN_MEM_WRITE) =3D= =3D 0) { >=20 > + Permissions |=3D EFI_MEMORY_RO; >=20 > + } >=20 > + >=20 > + if ((Section[Index].Characteristics & EFI_IMAGE_SCN_MEM_EXECUTE) =3D= =3D 0) { >=20 > + Permissions |=3D EFI_MEMORY_XP; >=20 > + } >=20 > + >=20 > + Status =3D MemoryPpi->SetPermissions ( >=20 > + MemoryPpi, >=20 > + SectionAddress, >=20 > + Section[Index].Misc.VirtualSize, >=20 > + Permissions, >=20 > + Permissions ^ EFI_MEMORY_RO ^ EFI_MEMORY_XP >=20 > + ); >=20 > + ASSERT_EFI_ERROR (Status); >=20 > + } >=20 > +} >=20 > + >=20 > +STATIC >=20 > +VOID >=20 > +RelocateAndRemapDriversInPlace ( >=20 > + VOID >=20 > + ) >=20 > +{ >=20 > + EFI_STATUS Status; >=20 > + UINTN Instance; >=20 > + EFI_PEI_FV_HANDLE VolumeHandle; >=20 > + EFI_PEI_FILE_HANDLE FileHandle; >=20 > + PE_COFF_LOADER_IMAGE_CONTEXT ImageContext; >=20 > + UINT32 AuthenticationState; >=20 > + EDKII_MEMORY_ATTRIBUTE_PPI *MemoryPpi; >=20 > + >=20 > + MemoryPpi =3D NULL; >=20 > + PeiServicesLocatePpi (&gEdkiiMemoryAttributePpiGuid, 0, NULL, (VOID > **)&MemoryPpi); >=20 > + >=20 > + Instance =3D 0; >=20 > + do { >=20 > + // >=20 > + // Traverse all firmware volume instances >=20 > + // >=20 > + Status =3D PeiServicesFfsFindNextVolume (Instance, &VolumeHandle); >=20 > + if (Status =3D=3D EFI_NOT_FOUND) { >=20 > + return; >=20 > + } >=20 > + >=20 > + ASSERT_EFI_ERROR (Status); >=20 > + >=20 > + FileHandle =3D NULL; >=20 > + do { >=20 > + Status =3D PeiServicesFfsFindNextFile ( >=20 > + EFI_FV_FILETYPE_DRIVER, >=20 > + VolumeHandle, >=20 > + &FileHandle); >=20 > + if (Status =3D=3D EFI_NOT_FOUND) { >=20 > + break; >=20 > + } >=20 > + >=20 > + ASSERT_EFI_ERROR (Status); >=20 > + >=20 > + ZeroMem (&ImageContext, sizeof (ImageContext)); >=20 > + >=20 > + Status =3D PeiServicesFfsFindSectionData3 ( >=20 > + EFI_SECTION_PE32, >=20 > + 0, >=20 > + FileHandle, >=20 > + &ImageContext.Handle, >=20 > + &AuthenticationState >=20 > + ); >=20 > + if (Status =3D=3D EFI_NOT_FOUND) { >=20 > + continue; >=20 > + } >=20 > + >=20 > + ASSERT_EFI_ERROR (Status); >=20 > + >=20 > + ImageContext.ImageRead =3D PeiImageRead; >=20 > + Status =3D PeCoffLoaderGetImageInfo (&ImageContext= ); >=20 > + if (EFI_ERROR (Status)) { >=20 > + ASSERT_EFI_ERROR (Status); >=20 > + continue; >=20 > + } >=20 > + >=20 > + ImageContext.ImageAddress =3D > (PHYSICAL_ADDRESS)(UINTN)ImageContext.Handle; >=20 > + if ((ImageContext.ImageAddress & (ImageContext.SectionAlignment - = 1)) !=3D > 0) { >=20 > + DEBUG ((DEBUG_VERBOSE, "%a: skip PE image at %p\n", __func__, > ImageContext.Handle)); >=20 > + continue; >=20 > + } >=20 > + >=20 > + DEBUG (( >=20 > + DEBUG_INFO, >=20 > + "%a: relocate PE image at %p for execution in place\n", >=20 > + __func__, >=20 > + ImageContext.Handle >=20 > + )); >=20 > + >=20 > + // >=20 > + // 'Load' the image in-place - this just performs a sanity check o= n >=20 > + // the PE metadata but does not actually move any data >=20 > + // >=20 > + Status =3D PeCoffLoaderLoadImage (&ImageContext); >=20 > + if (EFI_ERROR (Status)) { >=20 > + ASSERT_EFI_ERROR (Status); >=20 > + continue; >=20 > + } >=20 > + >=20 > + // >=20 > + // Relocate this driver in place >=20 > + // >=20 > + Status =3D PeCoffLoaderRelocateImage (&ImageContext); >=20 > + if (EFI_ERROR (Status)) { >=20 > + ASSERT_EFI_ERROR (Status); >=20 > + continue; >=20 > + } >=20 > + >=20 > + // >=20 > + // Apply section permissions to the page tables >=20 > + // >=20 > + RemapImage (MemoryPpi, &ImageContext); >=20 > + >=20 > + } while (TRUE); >=20 > + >=20 > + Instance++; >=20 > + } while (TRUE); >=20 > +} >=20 > + >=20 > /** >=20 > Main entry point to last PEIM. >=20 >=20 >=20 > @@ -436,6 +630,8 @@ DxeLoadCore ( > DxeCoreEntryPoint >=20 > ); >=20 >=20 >=20 > + RelocateAndRemapDriversInPlace (); >=20 > + >=20 > // >=20 > // Report Status Code EFI_SW_PEI_PC_HANDOFF_TO_NEXT >=20 > // >=20 > -- > 2.39.2 >=20 >=20 >=20 > -=3D-=3D-=3D-=3D-=3D-=3D > Groups.io Links: You receive all messages sent to this group. > View/Reply Online (#105370): https://edk2.groups.io/g/devel/message/10537= 0 > Mute This Topic: https://groups.io/mt/99197142/1712937 > Group Owner: devel+owner@edk2.groups.io > Unsubscribe: https://edk2.groups.io/g/devel/unsub [ray.ni@intel.com] > -=3D-=3D-=3D-=3D-=3D-=3D >=20