public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Marvin Häuser" <mhaeuser@posteo.de>
To: devel@edk2.groups.io
Cc: Jian J Wang <jian.j.wang@intel.com>,
	Hao A Wu <hao.a.wu@intel.com>, Dandan Bi <dandan.bi@intel.com>,
	Liming Gao <gaoliming@byosoft.com.cn>,
	Vitaly Cheptsov <vit9696@protonmail.com>
Subject: [PATCH 2/5] MdeModulePkg/DxeCore: Align fixed-address error behaviour
Date: Sat, 21 Aug 2021 19:55:49 +0000	[thread overview]
Message-ID: <b92878e01ae4ac19c4372e82c48d507904386dba.1629575593.git.mhaeuser@posteo.de> (raw)
In-Reply-To: <6baa44c6ee3ead5e4ffdefd5fdd3961323c323d0.1629575593.git.mhaeuser@posteo.de>

Update the control flow to take the same actions for failed
fixed-address loading as if the feature was disabled. This allows
Images to still be loaded to their preferred address in the case of
a mismatch between fixed-address and preferred address, and also
ensures correct handling of stripped relocations.

Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Dandan Bi <dandan.bi@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Vitaly Cheptsov <vit9696@protonmail.com>
Signed-off-by: Marvin Häuser <mhaeuser@posteo.de>
---
 MdeModulePkg/Core/Dxe/Image/Image.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/MdeModulePkg/Core/Dxe/Image/Image.c b/MdeModulePkg/Core/Dxe/Image/Image.c
index 641a5715b112..0a1def0572bc 100644
--- a/MdeModulePkg/Core/Dxe/Image/Image.c
+++ b/MdeModulePkg/Core/Dxe/Image/Image.c
@@ -565,6 +565,7 @@ CoreLoadPeImage (
   EFI_STATUS                Status;
   BOOLEAN                   DstBufAlocated;
   UINTN                     Size;
+  PHYSICAL_ADDRESS          PreferredAddress;
 
   ZeroMem (&Image->ImageContext, sizeof (Image->ImageContext));
 
@@ -642,6 +643,8 @@ CoreLoadPeImage (
     // a specified address.
     //
     if (PcdGet64(PcdLoadModuleAtFixAddressEnable) != 0 ) {
+      PreferredAddress = Image->ImageContext.ImageAddress;
+
       Status = GetPeCoffImageFixLoadingAssignedAddress (&(Image->ImageContext));
 
       if (EFI_ERROR (Status))  {
@@ -649,15 +652,10 @@ CoreLoadPeImage (
           // If the code memory is not ready, invoke CoreAllocatePage with AllocateAnyPages to load the driver.
           //
           DEBUG ((EFI_D_INFO|EFI_D_LOAD, "LOADING MODULE FIXED ERROR: Loading module at fixed address failed since specified memory is not available.\n"));
-
-          Status = CoreAllocatePages (
-                     AllocateAnyPages,
-                     (EFI_MEMORY_TYPE) (Image->ImageContext.ImageCodeMemoryType),
-                     Image->NumberOfPages,
-                     &Image->ImageContext.ImageAddress
-                     );
+          Image->ImageContext.ImageAddress = PreferredAddress;
       }
-    } else {
+    }
+    if (EFI_ERROR (Status)) {
       if (Image->ImageContext.ImageAddress >= 0x100000 || Image->ImageContext.RelocationsStripped) {
         Status = CoreAllocatePages (
                    AllocateAddress,
-- 
2.31.1


  reply	other threads:[~2021-08-21 19:56 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-21 19:55 [PATCH 0/3] Update GDB and RVCT symbols loading to use the Image base address Marvin Häuser
2021-08-21 19:55 ` [PATCH 1/3] EmulatorPkg: Use Image base address for GDB symbols loading Marvin Häuser
2021-08-21 19:55 ` [PATCH 1/1] MdeModulePkg: Move PiSmmCoreMemoryAllocationLib into PiSmmCore Marvin Häuser
2021-09-01  4:21   ` Ni, Ray
2021-09-01  7:17     ` Marvin Häuser
2021-09-02 10:53       ` Ni, Ray
2021-09-02 13:22         ` [edk2-devel] " Marvin Häuser
2021-09-03  1:29           ` 回复: " gaoliming
2021-08-21 19:55 ` [PATCH 1/5] MdeModulePkg/PeiCore: Align fixed-address error behaviour Marvin Häuser
2021-08-21 19:55   ` Marvin Häuser [this message]
2021-08-21 19:55   ` [PATCH 3/5] MdeModulePkg/DxeCore: Check for fixed-address Image relocations Marvin Häuser
2021-08-21 19:55   ` [PATCH 4/5] MdeModulePkg/PiSmmIpl: Disallow stripped " Marvin Häuser
2021-08-21 19:55   ` [PATCH 5/5] MdeModulePkg/PiSmmCore: " Marvin Häuser
2021-08-21 20:10   ` [edk2-devel] [PATCH 1/5] MdeModulePkg/PeiCore: Align fixed-address error behaviour Marvin Häuser
2021-08-22  9:28     ` Marvin Häuser
2021-08-21 19:55 ` [PATCH 2/3] ArmPkg: Use Image base address for GDB symbols loading Marvin Häuser
2021-08-21 19:55 ` [PATCH 3/3] ArmPkg: Use Image base address for RVCT " Marvin Häuser

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b92878e01ae4ac19c4372e82c48d507904386dba.1629575593.git.mhaeuser@posteo.de \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox