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.w...@intel.com>
Cc: Hao A Wu <hao.a...@intel.com>
Cc: Dandan Bi <dandan...@intel.com>
Cc: Liming Gao <gaolim...@byosoft.com.cn>
Cc: Vitaly Cheptsov <vit9...@protonmail.com>
Signed-off-by: Marvin Häuser <mhaeu...@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



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#79677): https://edk2.groups.io/g/devel/message/79677
Mute This Topic: https://groups.io/mt/85048615/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-


Reply via email to