From nobody Tue May 21 00:40:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+57133+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+57133+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1586448596; cv=none; d=zohomail.com; s=zohoarc; b=IrntA2cFWnHPWr6vhIr5c5lF/BTctASVAJjvU+tawpfZ7RXxYfzNQjw6CzPDvXHfEGw5UIUB9Y3z0SOw6Ta8zUIJsc6YDPVK4zkKySpAuRfuHMGcwqzbWGtMpCUp5VTq3bNz6wuZszar5RPj8kUUH97Jq1vSfy4ACTa6IueGxKk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1586448596; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=XgKLjwZPYNbUgSUDiezi0+OvBMrZAtwxoKgfQyyE3CQ=; b=jkVDXFCtio3md0/fkE3YLfuXFDhjDKaSaGBgxNg4G0fzBVikFkAeg2tK4bOBm2WPitc29lvcFgpkzco9rHIERLu7ErDRDjokoOiZlpnAQT7fxqEPwECrt/N7VcGwYrh26s1AyPVN3ionnJqtC+kwMusgUZqN29JatqeG+xZeh3U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+57133+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1586448596185138.99972730808406; Thu, 9 Apr 2020 09:09:56 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id u2PdYY1788612xLA7FcK3vFl; Thu, 09 Apr 2020 09:09:55 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.12473.1586448595090282830 for ; Thu, 09 Apr 2020 09:09:55 -0700 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id BDF867FA; Thu, 9 Apr 2020 09:09:54 -0700 (PDT) X-Received: from e123331-lin.home (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id F06263F52E; Thu, 9 Apr 2020 09:09:53 -0700 (PDT) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: jian.j.wang@intel.com, hao.a.wu@intel.com, Ard Biesheuvel Subject: [edk2-devel] [PATCH 1/2] MdeModulePkg/DxeCore/Image: make local functions STATIC Date: Thu, 9 Apr 2020 18:09:47 +0200 Message-Id: <20200409160948.23427-2-ard.biesheuvel@arm.com> In-Reply-To: <20200409160948.23427-1-ard.biesheuvel@arm.com> References: <20200409160948.23427-1-ard.biesheuvel@arm.com> Precedence: Bulk List-Unsubscribe: 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,ard.biesheuvel@arm.com X-Gm-Message-State: ERTw80kdHiwZVzR68GYIL9I5x1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1586448595; bh=SbYPOKNW0ZQJRhkfGpLWK18O7Yb8KTo6UCgYw9X+2eU=; h=Cc:Date:From:Reply-To:Subject:To; b=c6TKgjt2eEwb2HdRnfndMGYnAX9Y55GY1+snNwkS73fkeuLEbw6Zt7XB+hQnonGRf6C U/wZhhmc0/fz2l9te2gfA7ffIf87/xXHUnvbiZuTci399enwgJCvaRQCdnjsED+EwaE5N 4I1Q2iHZGBA7jD3HFS6M3OgML77OMyowfS4= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Use static linkage for functions that are only used locally, to help the compiler optimize away unused code in non-LTO builds. Signed-off-by: Ard Biesheuvel Reviewed-by: Bret Barkelew --- MdeModulePkg/Core/Dxe/Image/Image.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/MdeModulePkg/Core/Dxe/Image/Image.c b/MdeModulePkg/Core/Dxe/Im= age/Image.c index d86da89ee704..aae2c1eaa516 100644 --- a/MdeModulePkg/Core/Dxe/Image/Image.c +++ b/MdeModulePkg/Core/Dxe/Image/Image.c @@ -86,6 +86,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED MACHINE_TYPE_INFO mMachine= TypeInfo[] =3D { =20 UINT16 mDxeCoreImageMachineType =3D 0; =20 +#ifndef MDEPKG_NDEBUG /** Return machine type name. =20 @@ -93,6 +94,7 @@ UINT16 mDxeCoreImageMachineType =3D 0; =20 @return machine type name **/ +STATIC CHAR16 * GetMachineTypeName ( UINT16 MachineType @@ -108,6 +110,7 @@ GetMachineTypeName ( =20 return L""; } +#endif =20 /** Notification event handler registered by CoreInitializeImageServices () = to @@ -286,6 +289,7 @@ CoreInitializeImageServices ( into buffer. =20 **/ +STATIC EFI_STATUS EFIAPI CoreReadImageFile ( @@ -334,6 +338,7 @@ CoreReadImageFile ( @retval EFI_SUCCESS The memory range the image will be load= ed in is available @retval EFI_NOT_FOUND The memory range the image will be load= ed in is not available **/ +STATIC EFI_STATUS CheckAndMarkFixLoadingMemoryUsageBitMap ( IN EFI_PHYSICAL_ADDRESS ImageBase, @@ -407,6 +412,7 @@ CheckAndMarkFixLoadingMemoryUsageBitMap ( @retval EFI_NOT_FOUND The image has no assigned fixed loadin= g address. =20 **/ +STATIC EFI_STATUS GetPeCoffImageFixLoadingAssignedAddress( IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext @@ -552,6 +558,7 @@ CoreIsImageTypeSupported ( @retval EFI_BUFFER_TOO_SMALL Buffer for image is too small =20 **/ +STATIC EFI_STATUS CoreLoadPeImage ( IN BOOLEAN BootPolicy, @@ -877,6 +884,7 @@ CoreLoadPeImage ( @return Return the image private data associated with ImageHandle. =20 **/ +STATIC LOADED_IMAGE_PRIVATE_DATA * CoreLoadedImageInfo ( IN EFI_HANDLE ImageHandle @@ -909,6 +917,7 @@ CoreLoadedImageInfo ( @param FreePage Free allocated pages =20 **/ +STATIC VOID CoreUnloadAndCloseImage ( IN LOADED_IMAGE_PRIVATE_DATA *Image, @@ -1105,6 +1114,7 @@ CoreUnloadAndCloseImage ( platform policy specifies that the image= should not be started. =20 **/ +STATIC EFI_STATUS CoreLoadImageCommon ( IN BOOLEAN BootPolicy, --=20 2.17.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 (#57133): https://edk2.groups.io/g/devel/message/57133 Mute This Topic: https://groups.io/mt/72900048/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 Tue May 21 00:40:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+57134+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+57134+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1586448597; cv=none; d=zohomail.com; s=zohoarc; b=DgAWen4cYAlKNhD/vYtDe9DHq+zGEozTrAf+q+JFLozxIblogd+8uSpR+9/dRxy6d8KoJ8R1ttAZLHT8nZaKjuAYHnNHjkrpcz51fNTYgDoF8pSwXwuXK4r91Q9S/X3Gp5wIb7YwqOR19DCSfcyApKQAyHG921ayWzU/OKIyqmU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1586448597; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=bj5S54GUX9geCK+cVt93bfEs2uk5E5zXV4rinL8GB6E=; b=nh7NDNMnAYy0gqI47iLBB7L/aHdPvlmJImYicrrlqfL9vXSz+LL99VXbBCRYRRT1LY0nNEQ2ox2DF3otLfbWTbwa53o7B4DUv/bpyHFDWXuHV91R4b6rTyzZvJ4qkyFQG9AvfB3Til3WtGDKFpZAQWefpJnT2lRjgMS4M+Qsp3E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+57134+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1586448597138205.06677353050316; Thu, 9 Apr 2020 09:09:57 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id w3HQYY1788612xw4JogS32P3; Thu, 09 Apr 2020 09:09:56 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.12483.1586448596224368446 for ; Thu, 09 Apr 2020 09:09:56 -0700 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id CA2D41063; Thu, 9 Apr 2020 09:09:55 -0700 (PDT) X-Received: from e123331-lin.home (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 077BE3F52E; Thu, 9 Apr 2020 09:09:54 -0700 (PDT) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: jian.j.wang@intel.com, hao.a.wu@intel.com, Ard Biesheuvel Subject: [edk2-devel] [PATCH 2/2] MdeModulePkg/DxeCore/Image: remove unused function arguments Date: Thu, 9 Apr 2020 18:09:48 +0200 Message-Id: <20200409160948.23427-3-ard.biesheuvel@arm.com> In-Reply-To: <20200409160948.23427-1-ard.biesheuvel@arm.com> References: <20200409160948.23427-1-ard.biesheuvel@arm.com> Precedence: Bulk List-Unsubscribe: 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,ard.biesheuvel@arm.com X-Gm-Message-State: UDMOHwFyvRODDaZSZhF7UA1Sx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1586448596; bh=hwhhAueeu9oDhnrkAEFj6QpyyTK/Cvjl7O1X/dGFDys=; h=Cc:Date:From:Reply-To:Subject:To; b=GjaivheIPCphzOYkR/C2ShaIf0RkV25oFMlZGEh3pAjKEH+sE91NCgXCoIJW22Uy056 m8EWzmBbDbqP4JTs+qbH6MSSAynnkMYa8atfMCtVbNTr01RfE38mbx+BRpFiTPvYr9hBJ f+4rVau58O6wff9ygksoxRaN6hAf6qa+skA= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Image.c defines a CoreLoadImageCommon() function that has some arguments that are marked OPTIONAL. The function only has a single caller living in the same file, and it does not pass any arguments for these OPTIONAL arguments. So let's simplify the code, and remove these arguments and all the transitive conditional dependencies on them. Signed-off-by: Ard Biesheuvel Reviewed-by: Bret Barkelew --- NOTE: this patch was generated with the -w option, to suppress indentation changes from cluttering the diff. MdeModulePkg/Core/Dxe/Image/Image.c | 81 ++------------------ 1 file changed, 7 insertions(+), 74 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Image/Image.c b/MdeModulePkg/Core/Dxe/Im= age/Image.c index aae2c1eaa516..9fdde87f2df3 100644 --- a/MdeModulePkg/Core/Dxe/Image/Image.c +++ b/MdeModulePkg/Core/Dxe/Image/Image.c @@ -564,13 +564,10 @@ CoreLoadPeImage ( IN BOOLEAN BootPolicy, IN VOID *Pe32Handle, IN LOADED_IMAGE_PRIVATE_DATA *Image, - IN EFI_PHYSICAL_ADDRESS DstBuffer OPTIONAL, - OUT EFI_PHYSICAL_ADDRESS *EntryPoint OPTIONAL, IN UINT32 Attribute ) { EFI_STATUS Status; - BOOLEAN DstBufAlocated; UINTN Size; =20 ZeroMem (&Image->ImageContext, sizeof (Image->ImageContext)); @@ -619,15 +616,6 @@ CoreLoadPeImage ( return EFI_UNSUPPORTED; } =20 - // - // Allocate memory of the correct memory type aligned on the required im= age boundary - // - DstBufAlocated =3D FALSE; - if (DstBuffer =3D=3D 0) { - // - // Allocate Destination Buffer as caller did not pass it in - // - if (Image->ImageContext.SectionAlignment > EFI_PAGE_SIZE) { Size =3D (UINTN)Image->ImageContext.ImageSize + Image->ImageContext.Se= ctionAlignment; } else { @@ -685,31 +673,6 @@ CoreLoadPeImage ( if (EFI_ERROR (Status)) { return Status; } - DstBufAlocated =3D TRUE; - } 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->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; - } - - Image->NumberOfPages =3D EFI_SIZE_TO_PAGES ((UINTN)Image->ImageContext= .ImageSize + Image->ImageContext.SectionAlignment); - Image->ImageContext.ImageAddress =3D DstBuffer; - } =20 Image->ImageBasePage =3D Image->ImageContext.ImageAddress; if (!Image->ImageContext.IsTeImage) { @@ -790,13 +753,6 @@ CoreLoadPeImage ( } } =20 - // - // Fill in the entry point of the image if it is available - // - if (EntryPoint !=3D NULL) { - *EntryPoint =3D Image->ImageContext.EntryPoint; - } - // // Print the load address and the PDB file name if it is available // @@ -861,11 +817,9 @@ CoreLoadPeImage ( // Free memory. // =20 - if (DstBufAlocated) { 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); @@ -920,8 +874,7 @@ CoreLoadedImageInfo ( STATIC VOID CoreUnloadAndCloseImage ( - IN LOADED_IMAGE_PRIVATE_DATA *Image, - IN BOOLEAN FreePage + IN LOADED_IMAGE_PRIVATE_DATA *Image ) { EFI_STATUS Status; @@ -1047,7 +1000,7 @@ CoreUnloadAndCloseImage ( // // Free the Image from memory // - if ((Image->ImageBasePage !=3D 0) && FreePage) { + if ((Image->ImageBasePage !=3D 0)) { CoreFreePages (Image->ImageBasePage, Image->NumberOfPages); } =20 @@ -1122,10 +1075,7 @@ 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, - OUT EFI_PHYSICAL_ADDRESS *EntryPoint OPTIONAL, IN UINT32 Attribute ) { @@ -1330,12 +1280,7 @@ CoreLoadImageCommon ( Image->Info.FilePath =3D DuplicateDevicePath (FilePath); Image->Info.ParentHandle =3D ParentImageHandle; =20 - - if (NumberOfPages !=3D NULL) { - Image->NumberOfPages =3D *NumberOfPages ; - } else { Image->NumberOfPages =3D 0 ; - } =20 // // Install the protocol interfaces for this image @@ -1355,20 +1300,11 @@ CoreLoadImageCommon ( // // Load the image. If EntryPoint is Null, it will not be set. // - Status =3D CoreLoadPeImage (BootPolicy, &FHand, Image, DstBuffer, EntryP= oint, Attribute); + 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 // @@ -1448,7 +1384,7 @@ CoreLoadImageCommon ( // if (EFI_ERROR (Status)) { if (Image !=3D NULL) { - CoreUnloadAndCloseImage (Image, (BOOLEAN)(DstBuffer =3D=3D 0)); + CoreUnloadAndCloseImage (Image); Image =3D NULL; } } else if (EFI_ERROR (SecurityStatus)) { @@ -1524,10 +1460,7 @@ CoreLoadImage ( FilePath, SourceBuffer, SourceSize, - (EFI_PHYSICAL_ADDRESS) (UINTN) NULL, - NULL, ImageHandle, - NULL, EFI_LOAD_PE_IMAGE_ATTRIBUTE_RUNTIME_REGISTRATION | EFI_LOAD_P= E_IMAGE_ATTRIBUTE_DEBUG_IMAGE_INFO_TABLE_REGISTRATION ); =20 @@ -1744,7 +1677,7 @@ CoreStartImage ( // unload it // if (EFI_ERROR (Image->Status) || Image->Type =3D=3D EFI_IMAGE_SUBSYSTEM_= EFI_APPLICATION) { - CoreUnloadAndCloseImage (Image, TRUE); + CoreUnloadAndCloseImage (Image); // // ImageHandle may be invalid after the image is unloaded, so use NULL= handle to record perf log. // @@ -1809,7 +1742,7 @@ CoreExit ( // // The image has not been started so just free its resources // - CoreUnloadAndCloseImage (Image, TRUE); + CoreUnloadAndCloseImage (Image); Status =3D EFI_SUCCESS; goto Done; } @@ -1911,7 +1844,7 @@ CoreUnloadImage ( // // if the Image was not started or Unloaded O.K. then clean up // - CoreUnloadAndCloseImage (Image, TRUE); + CoreUnloadAndCloseImage (Image); } =20 Done: --=20 2.17.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 (#57134): https://edk2.groups.io/g/devel/message/57134 Mute This Topic: https://groups.io/mt/72900049/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-