From nobody Mon May 6 18:06:41 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+78884+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+78884+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=posteo.de ARC-Seal: i=1; a=rsa-sha256; t=1628451637; cv=none; d=zohomail.com; s=zohoarc; b=S+5mwIaAiqKGpQjPTFbupg4vdlCedGm7clnm5Nai4ZKKqp6oWcEp+EsQEmofsD9SqfQEXX4r9adK32+QuIDNfEge/KKxdza2cMSepSotWxAbhuZlsIheihjWoVRN5xKumVgVOlTUOifnR92ghpJGPNmkJ2hnPymsvDZACvqsXZg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1628451637; h=Content-Type: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=2IWsoPIzx3xjriTrPCXoOqgJgWMH7o5luy1gtedsuCU=; b=G0FT9DP/ihL2GzmdMkAvNQtpQxIoWxYBO0FdMMzbzBuKlMaPlqS6lxkdsO8xdoeF/ivdkKWldcVihoUCRI1in8sHUYdq/Hqim78FquJaD9fOFqXVIzEqXkPK6goonV5V+mlULkbl5rN6Y+sCCa36oI2b7oAcOeFE6u8wcGSrym8= 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+78884+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1628451637695330.41975529280876; Sun, 8 Aug 2021 12:40:37 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id qh1oYY1788612xYHDr8pgcFv; Sun, 08 Aug 2021 12:40:37 -0700 X-Received: from mout01.posteo.de (mout01.posteo.de [185.67.36.65]) by mx.groups.io with SMTP id smtpd.web08.13630.1628451636463292927 for ; Sun, 08 Aug 2021 12:40:36 -0700 X-Received: from submission (posteo.de [89.146.220.130]) by mout01.posteo.de (Postfix) with ESMTPS id E4DAA240027 for ; Sun, 8 Aug 2021 21:40:34 +0200 (CEST) X-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4GjV1Z2jtLz6tmP; Sun, 8 Aug 2021 21:40:34 +0200 (CEST) From: =?UTF-8?B?TWFydmluIEjDpHVzZXI=?= To: devel@edk2.groups.io Cc: Jian J Wang , Hao A Wu , Dandan Bi , Liming Gao , Vitaly Cheptsov Subject: [edk2-devel] [PATCH] MdeModulePkg/DxeCore: Use the correct source for fixed load address Date: Sun, 8 Aug 2021 19:39:42 +0000 Message-Id: <4e949f3958183bed1b1a5db89ee5dd6d81d97cb1.1628359775.git.mhaeuser@posteo.de> In-Reply-To: <5df11a13422732b9c03c120775a2b4dd0a49182f.1628444003.git.mhaeuser@posteo.de> References: <5df11a13422732b9c03c120775a2b4dd0a49182f.1628444003.git.mhaeuser@posteo.de> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,mhaeuser@posteo.de X-Gm-Message-State: XYQToGoABdNQr3c8BmN1ykwyx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1628451637; bh=lfo9QIqbiP1R6PcY5hZSRVXWIXTx1wnlnpR2syazanc=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=i8aw7kpFzVRP3XgEIEQSPoYbk4WRt8WTiHFdhIPaj7yITOvk7j5xYSI6mmeC8VuJm9K jgotx+dbiA87xw0aFXuAhTtSMF4EPEECzQpi7PdwUqY6UIoUiZl31UXs4VWkfQZwvU8ID mNn/vg2j8OG1dgY81UMZ4pIIJMORdUkP4fI= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1628451639551100031 Content-Type: text/plain; charset="utf-8" The build tools write the fixed load address into the section header of the first non-code section. While PeiCore and PiSmmCore correctly load it from there, DxeCore uses ImageBase from the PE/COFF Optional Header instead. Align the behaviour of DxeCore with the other dispatchers. Cc: Jian J Wang Cc: Hao A Wu Cc: Dandan Bi Cc: Liming Gao Cc: Vitaly Cheptsov Signed-off-by: Marvin H=C3=A4user --- MdeModulePkg/Core/Dxe/Image/Image.c | 30 ++++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Image/Image.c b/MdeModulePkg/Core/Dxe/Im= age/Image.c index 641a5715b112..9455c2fa45ad 100644 --- a/MdeModulePkg/Core/Dxe/Image/Image.c +++ b/MdeModulePkg/Core/Dxe/Image/Image.c @@ -416,6 +416,7 @@ GetPeCoffImageFixLoadingAssignedAddress( EFI_STATUS Status; EFI_IMAGE_SECTION_HEADER SectionHeader; EFI_IMAGE_OPTIONAL_HEADER_UNION *ImgHdr; + EFI_PHYSICAL_ADDRESS FixLoadingAddress; UINT16 Index; UINTN Size; UINT16 NumberOfSections; @@ -468,24 +469,35 @@ GetPeCoffImageFixLoadingAssignedAddress( // ValueInSectionHeader =3D ReadUnaligned64((UINT64*)&SectionHeader.Po= interToRelocations); if (ValueInSectionHeader !=3D 0) { - // - // When the feature is configured as load module at fixed absolut= e address, the ImageAddress field of ImageContext - // hold the specified address. If the feature is configured as lo= ad module at fixed offset, ImageAddress hold an offset - // relative to top address - // - if ((INT64)PcdGet64(PcdLoadModuleAtFixAddressEnable) < 0) { - ImageContext->ImageAddress =3D gLoadModuleAtFixAddressConfigur= ationTable.DxeCodeTopAddress + (INT64)(INTN)ImageContext->ImageAddress; + if ((INT64)PcdGet64(PcdLoadModuleAtFixAddressEnable) > 0) { + // + // When LMFA feature is configured as Load Module at Fixed Abso= lute Address mode, PointerToRelocations & PointerToLineNumbers field + // hold the absolute address of image base running in memory + // + FixLoadingAddress =3D ValueInSectionHeader; + } else { + // + // When LMFA feature is configured as Load Module at Fixed offs= et mode, PointerToRelocations & PointerToLineNumbers field + // hold the offset relative to a platform-specific top address. + // + FixLoadingAddress =3D gLoadModuleAtFixAddressConfigurationTable= .DxeCodeTopAddress + ValueInSectionHeader; } // // Check if the memory range is available. // - Status =3D CheckAndMarkFixLoadingMemoryUsageBitMap (ImageContext-= >ImageAddress, (UINTN)(ImageContext->ImageSize + ImageContext->SectionAlign= ment)); + Status =3D CheckAndMarkFixLoadingMemoryUsageBitMap (FixLoadingAdd= ress, (UINTN)(ImageContext->ImageSize + ImageContext->SectionAlignment)); + if (!EFI_ERROR(Status)) { + // + // The assigned address is valid. Return the specified loading = address + // + ImageContext->ImageAddress =3D FixLoadingAddress; + } } break; } SectionHeaderOffset +=3D sizeof (EFI_IMAGE_SECTION_HEADER); } - DEBUG ((EFI_D_INFO|EFI_D_LOAD, "LOADING MODULE FIXED INFO: Loading modu= le at fixed address 0x%11p. Status =3D %r \n", (VOID *)(UINTN)(ImageContext= ->ImageAddress), Status)); + DEBUG ((EFI_D_INFO|EFI_D_LOAD, "LOADING MODULE FIXED INFO: Loading modu= le at fixed address 0x%11p. Status =3D %r \n", (VOID *)(UINTN)FixLoadingAdd= ress, Status)); return Status; } =20 --=20 2.31.1 -=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 (#78884): https://edk2.groups.io/g/devel/message/78884 Mute This Topic: https://groups.io/mt/84754057/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-