From nobody Tue Feb 10 06:52:21 2026 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+105364+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+105364+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1685355448; cv=none; d=zohomail.com; s=zohoarc; b=mfGmRbTR5Wju3lV1IsCxv7J0R0+MiuvMddy5k98mFT+06BW2f2/npOdBNZq+GU/NfaYnrxYvfeAy8V2cHMqQ5xGl5G8ksPG5MreG/MeE7Lin6+nGbZ2LlX+TQK36ABviZPo+0hann1xN4QX8/e3ZGKQq+lwPisVzDpMfEs0GW5M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685355448; 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=tgCL3hKgDvxyBacRcvpVgDFCtHag5JtMai21cMVkQ2g=; b=Ol18g2ahsu4t7PW0H9M+qUugIX0UTbqNS+9EPQRmFHaVr2jOOIlSCeBJ/a9JXFM+iMHBByQBr5cFbjKBwpZiQOQGnX5ARhHpuP3G8OiyAKHk1muJ1/RPxqjjkwEpfHs7TMAdveavYM0FKhrVE9n+ePYlIP8dS0hVY7aiYYp9zks= 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+105364+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 1685355448126409.8286302826175; Mon, 29 May 2023 03:17:28 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id fXSlYY1788612xWy5pDuiFDc; Mon, 29 May 2023 03:17:27 -0700 X-Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web11.46671.1685355444391069298 for ; Mon, 29 May 2023 03:17:24 -0700 X-Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E126F613EA; Mon, 29 May 2023 10:17:23 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id E293EC433A0; Mon, 29 May 2023 10:17:20 +0000 (UTC) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Ray Ni , Jiewen Yao , Gerd Hoffmann , Taylor Beebe , Oliver Smith-Denny , Dandan Bi , Liming Gao , "Kinney, Michael D" , Leif Lindholm , Michael Kubacki Subject: [edk2-devel] [RFC PATCH 02/11] MdeModulePkg/DxeCore: Remove unused DstBuffer arg from LoadImage Date: Mon, 29 May 2023 12:16:56 +0200 Message-Id: <20230529101705.2476949-3-ardb@kernel.org> In-Reply-To: <20230529101705.2476949-1-ardb@kernel.org> References: <20230529101705.2476949-1-ardb@kernel.org> 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,ardb@kernel.org X-Gm-Message-State: 7uVA9i6qhHRk9e4jhhLceCFRx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1685355447; bh=ESxEnSmuYXwl1YM+X7iRFYDw5dKy6XzEMGjrlRl1MiQ=; h=Cc:Date:From:Reply-To:Subject:To; b=EIMiNQU8JcpPfqJJmuNX0r9WgA9okkYUa7c7uIM0vmLdYdQUxBpnrv0JovT6WElSqFG ka/bLqm4fic3X9fBS4MczPGfCKUhOLX2PvcLhGtMHNUuyAJ8dl3QSMIfVlr281WKEJUAv oI+nb9P+4jVdg5CNrumfJi9l7xZ7xvKlR3s= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1685355449881100005 Content-Type: text/plain; charset="utf-8" The DstBuffer and NumberOfPages arguments to CoreLoadImageCommon () are never set by its only caller CoreLoadImage() so let's drop them from the prototype. Signed-off-by: Ard Biesheuvel Reviewed-by: Ray Ni --- MdeModulePkg/Core/Dxe/Image/Image.c | 174 +++++++------------- 1 file changed, 56 insertions(+), 118 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Image/Image.c b/MdeModulePkg/Core/Dxe/Im= age/Image.c index 2f2dfe5d0496dc4f..6625d0cd0ff82107 100644 --- a/MdeModulePkg/Core/Dxe/Image/Image.c +++ b/MdeModulePkg/Core/Dxe/Image/Image.c @@ -559,7 +559,6 @@ CoreIsImageTypeSupported ( boot selection. @param Pe32Handle The handle of PE32 image @param Image PE image to be loaded - @param DstBuffer The buffer to store the image @param Attribute The bit mask of attributes to set for th= e load PE image =20 @@ -570,17 +569,16 @@ CoreIsImageTypeSupported ( @retval EFI_BUFFER_TOO_SMALL Buffer for image is too small =20 **/ +STATIC EFI_STATUS CoreLoadPeImage ( IN BOOLEAN BootPolicy, IN VOID *Pe32Handle, IN LOADED_IMAGE_PRIVATE_DATA *Image, - IN EFI_PHYSICAL_ADDRESS DstBuffer OPTIONAL, IN UINT32 Attribute ) { EFI_STATUS Status; - BOOLEAN DstBufAlocated; UINTN Size; =20 ZeroMem (&Image->ImageContext, sizeof (Image->ImageContext)); @@ -633,99 +631,67 @@ CoreLoadPeImage ( } =20 // - // Allocate memory of the correct memory type aligned on the required im= age boundary + // Allocate Destination Buffer as caller did not pass it in // - DstBufAlocated =3D FALSE; - if (DstBuffer =3D=3D 0) { - // - // Allocate Destination Buffer as caller did not pass it in - // =20 - if (Image->ImageContext.SectionAlignment > EFI_PAGE_SIZE) { - Size =3D (UINTN)Image->ImageContext.ImageSize + Image->ImageContext.= SectionAlignment; - } else { - Size =3D (UINTN)Image->ImageContext.ImageSize; - } + if (Image->ImageContext.SectionAlignment > EFI_PAGE_SIZE) { + Size =3D (UINTN)Image->ImageContext.ImageSize + Image->ImageContext.Se= ctionAlignment; + } else { + Size =3D (UINTN)Image->ImageContext.ImageSize; + } =20 - Image->NumberOfPages =3D EFI_SIZE_TO_PAGES (Size); + Image->NumberOfPages =3D EFI_SIZE_TO_PAGES (Size); =20 - // - // If the image relocations have not been stripped, then load at any a= ddress. - // Otherwise load at the address at which it was linked. - // - // Memory below 1MB should be treated reserved for CSM and there shoul= d be - // no modules whose preferred load addresses are below 1MB. - // - Status =3D EFI_OUT_OF_RESOURCES; - // - // If Loading Module At Fixed Address feature is enabled, the module s= hould be loaded to - // a specified address. - // - if (PcdGet64 (PcdLoadModuleAtFixAddressEnable) !=3D 0 ) { - Status =3D GetPeCoffImageFixLoadingAssignedAddress (&(Image->ImageCo= ntext)); - - if (EFI_ERROR (Status)) { - // - // If the code memory is not ready, invoke CoreAllocatePage with A= llocateAnyPages to load the driver. - // - DEBUG ((DEBUG_INFO|DEBUG_LOAD, "LOADING MODULE FIXED ERROR: Loadin= g module at fixed address failed since specified memory is not available.\n= ")); - - Status =3D CoreAllocatePages ( - AllocateAnyPages, - (EFI_MEMORY_TYPE)(Image->ImageContext.ImageCodeMemoryTy= pe), - Image->NumberOfPages, - &Image->ImageContext.ImageAddress - ); - } - } else { - if ((Image->ImageContext.ImageAddress >=3D 0x100000) || Image->Image= Context.RelocationsStripped) { - Status =3D CoreAllocatePages ( - AllocateAddress, - (EFI_MEMORY_TYPE)(Image->ImageContext.ImageCodeMemoryTy= pe), - Image->NumberOfPages, - &Image->ImageContext.ImageAddress - ); - } - - if (EFI_ERROR (Status) && !Image->ImageContext.RelocationsStripped) { - Status =3D CoreAllocatePages ( - AllocateAnyPages, - (EFI_MEMORY_TYPE)(Image->ImageContext.ImageCodeMemoryTy= pe), - Image->NumberOfPages, - &Image->ImageContext.ImageAddress - ); - } - } + // + // If the image relocations have not been stripped, then load at any add= ress. + // Otherwise load at the address at which it was linked. + // + // Memory below 1MB should be treated reserved for CSM and there should = be + // no modules whose preferred load addresses are below 1MB. + // + Status =3D EFI_OUT_OF_RESOURCES; + // + // If Loading Module At Fixed Address feature is enabled, the module sho= uld be loaded to + // a specified address. + // + if (PcdGet64 (PcdLoadModuleAtFixAddressEnable) !=3D 0 ) { + Status =3D GetPeCoffImageFixLoadingAssignedAddress (&(Image->ImageCont= ext)); =20 if (EFI_ERROR (Status)) { - return Status; - } + // + // If the code memory is not ready, invoke CoreAllocatePage with All= ocateAnyPages to load the driver. + // + DEBUG ((DEBUG_INFO|DEBUG_LOAD, "LOADING MODULE FIXED ERROR: Loading = module at fixed address failed since specified memory is not available.\n")= ); =20 - DstBufAlocated =3D TRUE; + Status =3D CoreAllocatePages ( + AllocateAnyPages, + (EFI_MEMORY_TYPE)(Image->ImageContext.ImageCodeMemoryType= ), + Image->NumberOfPages, + &Image->ImageContext.ImageAddress + ); + } } else { - // - // Caller provided the destination buffer - // - - if (Image->ImageContext.RelocationsStripped && (Image->ImageContext.Im= ageAddress !=3D DstBuffer)) { - // - // If the image relocations were stripped, and the caller provided a - // destination buffer address that does not match the address that t= he - // image is linked at, then the image cannot be loaded. - // - return EFI_INVALID_PARAMETER; + if ((Image->ImageContext.ImageAddress >=3D 0x100000) || Image->ImageCo= ntext.RelocationsStripped) { + Status =3D CoreAllocatePages ( + AllocateAddress, + (EFI_MEMORY_TYPE)(Image->ImageContext.ImageCodeMemoryType= ), + Image->NumberOfPages, + &Image->ImageContext.ImageAddress + ); } =20 - if ((Image->NumberOfPages !=3D 0) && - (Image->NumberOfPages < - (EFI_SIZE_TO_PAGES ((UINTN)Image->ImageContext.ImageSize + Image-= >ImageContext.SectionAlignment)))) - { - Image->NumberOfPages =3D EFI_SIZE_TO_PAGES ((UINTN)Image->ImageConte= xt.ImageSize + Image->ImageContext.SectionAlignment); - return EFI_BUFFER_TOO_SMALL; + if (EFI_ERROR (Status) && !Image->ImageContext.RelocationsStripped) { + Status =3D CoreAllocatePages ( + AllocateAnyPages, + (EFI_MEMORY_TYPE)(Image->ImageContext.ImageCodeMemoryType= ), + Image->NumberOfPages, + &Image->ImageContext.ImageAddress + ); } + } =20 - Image->NumberOfPages =3D EFI_SIZE_TO_PAGES ((UINTN)Image->= ImageContext.ImageSize + Image->ImageContext.SectionAlignment); - Image->ImageContext.ImageAddress =3D DstBuffer; + if (EFI_ERROR (Status)) { + return Status; } =20 Image->ImageBasePage =3D Image->ImageContext.ImageAddress; @@ -875,12 +841,9 @@ CoreLoadPeImage ( // // Free memory. // - - if (DstBufAlocated) { - CoreFreePages (Image->ImageContext.ImageAddress, Image->NumberOfPages); - Image->ImageContext.ImageAddress =3D 0; - Image->ImageBasePage =3D 0; - } + CoreFreePages (Image->ImageContext.ImageAddress, Image->NumberOfPages); + Image->ImageContext.ImageAddress =3D 0; + Image->ImageBasePage =3D 0; =20 if (Image->ImageContext.FixupData !=3D NULL) { CoreFreePool (Image->ImageContext.FixupData); @@ -1094,12 +1057,6 @@ CoreUnloadAndCloseImage ( @param SourceBuffer If not NULL, a pointer to the memory loc= ation containing a copy of the image to be loa= ded. @param SourceSize The size in bytes of SourceBuffer. - @param DstBuffer The buffer to store the image - @param NumberOfPages If not NULL, it inputs a pointer to the = page - number of DstBuffer and outputs a pointe= r to - the page number of the image. If this nu= mber is - not enough, return EFI_BUFFER_TOO_SMALL= and - this parameter contains the required num= ber. @param ImageHandle Pointer to the returned image handle tha= t is created when the image is successfully l= oaded. @param Attribute The bit mask of attributes to set for th= e load @@ -1132,8 +1089,6 @@ CoreLoadImageCommon ( IN EFI_DEVICE_PATH_PROTOCOL *FilePath, IN VOID *SourceBuffer OPTIONAL, IN UINTN SourceSize, - IN EFI_PHYSICAL_ADDRESS DstBuffer OPTIONAL, - IN OUT UINTN *NumberOfPages OPTIONAL, OUT EFI_HANDLE *ImageHandle, IN UINT32 Attribute ) @@ -1342,12 +1297,7 @@ CoreLoadImageCommon ( Image->Info.Revision =3D EFI_LOADED_IMAGE_PROTOCOL_REVISION; Image->Info.FilePath =3D DuplicateDevicePath (FilePath); Image->Info.ParentHandle =3D ParentImageHandle; - - if (NumberOfPages !=3D NULL) { - Image->NumberOfPages =3D *NumberOfPages; - } else { - Image->NumberOfPages =3D 0; - } + Image->NumberOfPages =3D 0; =20 // // Install the protocol interfaces for this image @@ -1367,21 +1317,11 @@ CoreLoadImageCommon ( // // Load the image. // - Status =3D CoreLoadPeImage (BootPolicy, &FHand, Image, DstBuffer, Attrib= ute); + Status =3D CoreLoadPeImage (BootPolicy, &FHand, Image, Attribute); if (EFI_ERROR (Status)) { - if ((Status =3D=3D EFI_BUFFER_TOO_SMALL) || (Status =3D=3D EFI_OUT_OF_= RESOURCES)) { - if (NumberOfPages !=3D NULL) { - *NumberOfPages =3D Image->NumberOfPages; - } - } - goto Done; } =20 - if (NumberOfPages !=3D NULL) { - *NumberOfPages =3D Image->NumberOfPages; - } - // // Register the image in the Debug Image Info Table if the attribute is = set // @@ -1473,7 +1413,7 @@ CoreLoadImageCommon ( // if (EFI_ERROR (Status)) { if (Image !=3D NULL) { - CoreUnloadAndCloseImage (Image, (BOOLEAN)(DstBuffer =3D=3D 0)); + CoreUnloadAndCloseImage (Image, TRUE); Image =3D NULL; } } else if (EFI_ERROR (SecurityStatus)) { @@ -1546,8 +1486,6 @@ CoreLoadImage ( FilePath, SourceBuffer, SourceSize, - (EFI_PHYSICAL_ADDRESS)(UINTN)NULL, - NULL, ImageHandle, EFI_LOAD_PE_IMAGE_ATTRIBUTE_RUNTIME_REGISTRATION | EFI_LOAD_P= E_IMAGE_ATTRIBUTE_DEBUG_IMAGE_INFO_TABLE_REGISTRATION ); --=20 2.39.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 (#105364): https://edk2.groups.io/g/devel/message/105364 Mute This Topic: https://groups.io/mt/99197134/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-