diff mbox series

[edk2,v2,09/11] StandaloneMmPkg/Core/Dispatcher: don't copy dispatched image twice

Message ID 20190116202236.6977-10-ard.biesheuvel@linaro.org
State Accepted
Commit 877013d0a58f6baada8eb29665bdf36a61a946fa
Headers show
Series StandaloneMmPkg: assorted fixes and improvements | expand

Commit Message

Ard Biesheuvel Jan. 16, 2019, 8:22 p.m. UTC
The dispatcher uses the PE/COFF loader to load images into the heap,
but only does so after copying the entire image first, leading to
two copies being made for no good reason.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

---
 StandaloneMmPkg/Core/Dispatcher.c | 30 +-------------------
 1 file changed, 1 insertion(+), 29 deletions(-)

-- 
2.17.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Comments

Yao, Jiewen Jan. 18, 2019, 3:34 p.m. UTC | #1
Reviewed-by: Jiewen.yao@intel.com


> -----Original Message-----

> From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org]

> Sent: Wednesday, January 16, 2019 12:23 PM

> To: edk2-devel@lists.01.org

> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>; Achin Gupta

> <achin.gupta@arm.com>; Yao, Jiewen <jiewen.yao@intel.com>; Supreeth

> Venkatesh <supreeth.venkatesh@arm.com>; Leif Lindholm

> <leif.lindholm@linaro.org>; Jagadeesh Ujja <jagadeesh.ujja@arm.com>;

> Thomas Panakamattam Abraham <thomas.abraham@arm.com>; Sami

> Mujawar <Sami.Mujawar@arm.com>

> Subject: [PATCH v2 09/11] StandaloneMmPkg/Core/Dispatcher: don't copy

> dispatched image twice

> 

> The dispatcher uses the PE/COFF loader to load images into the heap,

> but only does so after copying the entire image first, leading to

> two copies being made for no good reason.

> 

> Contributed-under: TianoCore Contribution Agreement 1.1

> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

> ---

>  StandaloneMmPkg/Core/Dispatcher.c | 30 +-------------------

>  1 file changed, 1 insertion(+), 29 deletions(-)

> 

> diff --git a/StandaloneMmPkg/Core/Dispatcher.c

> b/StandaloneMmPkg/Core/Dispatcher.c

> index 8d009b4f80c1..8a2ad5118d92 100644

> --- a/StandaloneMmPkg/Core/Dispatcher.c

> +++ b/StandaloneMmPkg/Core/Dispatcher.c

> @@ -294,7 +294,6 @@ MmLoadImage (

>    IN OUT EFI_MM_DRIVER_ENTRY  *DriverEntry

>    )

>  {

> -  VOID                           *Buffer;

>    UINTN                          PageCount;

>    EFI_STATUS                     Status;

>    EFI_PHYSICAL_ADDRESS           DstBuffer;

> @@ -302,17 +301,12 @@ MmLoadImage (

> 

>    DEBUG ((DEBUG_INFO, "MmLoadImage - %g\n",

> &DriverEntry->FileName));

> 

> -  Buffer = AllocateCopyPool (DriverEntry->Pe32DataSize,

> DriverEntry->Pe32Data);

> -  if (Buffer == NULL) {

> -    return EFI_OUT_OF_RESOURCES;

> -  }

> -

>    Status               = EFI_SUCCESS;

> 

>    //

>    // Initialize ImageContext

>    //

> -  ImageContext.Handle = Buffer;

> +  ImageContext.Handle = DriverEntry->Pe32Data;

>    ImageContext.ImageRead = PeCoffLoaderImageReadFromMemory;

> 

>    //

> @@ -320,9 +314,6 @@ MmLoadImage (

>    //

>    Status = PeCoffLoaderGetImageInfo (&ImageContext);

>    if (EFI_ERROR (Status)) {

> -    if (Buffer != NULL) {

> -      MmFreePool (Buffer);

> -    }

>      return Status;

>    }

> 

> @@ -336,9 +327,6 @@ MmLoadImage (

>               &DstBuffer

>               );

>    if (EFI_ERROR (Status)) {

> -    if (Buffer != NULL) {

> -      MmFreePool (Buffer);

> -    }

>      return Status;

>    }

> 

> @@ -355,9 +343,6 @@ MmLoadImage (

>    //

>    Status = PeCoffLoaderLoadImage (&ImageContext);

>    if (EFI_ERROR (Status)) {

> -    if (Buffer != NULL) {

> -      MmFreePool (Buffer);

> -    }

>      MmFreePages (DstBuffer, PageCount);

>      return Status;

>    }

> @@ -367,9 +352,6 @@ MmLoadImage (

>    //

>    Status = PeCoffLoaderRelocateImage (&ImageContext);

>    if (EFI_ERROR (Status)) {

> -    if (Buffer != NULL) {

> -      MmFreePool (Buffer);

> -    }

>      MmFreePages (DstBuffer, PageCount);

>      return Status;

>    }

> @@ -393,9 +375,6 @@ MmLoadImage (

>                                                (VOID

> **)&DriverEntry->LoadedImage

>                                                );

>      if (EFI_ERROR (Status)) {

> -      if (Buffer != NULL) {

> -        MmFreePool (Buffer);

> -      }

>        MmFreePages (DstBuffer, PageCount);

>        return Status;

>      }

> @@ -482,13 +461,6 @@ MmLoadImage (

> 

>    DEBUG_CODE_END ();

> 

> -  //

> -  // Free buffer allocated by Fv->ReadSection.

> -  //

> -  // The UEFI Boot Services FreePool() function must be used because

> Fv->ReadSection

> -  // used the UEFI Boot Services AllocatePool() function

> -  //

> -  MmFreePool (Buffer);

>    return Status;

>  }

> 

> --

> 2.17.1


_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
diff mbox series

Patch

diff --git a/StandaloneMmPkg/Core/Dispatcher.c b/StandaloneMmPkg/Core/Dispatcher.c
index 8d009b4f80c1..8a2ad5118d92 100644
--- a/StandaloneMmPkg/Core/Dispatcher.c
+++ b/StandaloneMmPkg/Core/Dispatcher.c
@@ -294,7 +294,6 @@  MmLoadImage (
   IN OUT EFI_MM_DRIVER_ENTRY  *DriverEntry
   )
 {
-  VOID                           *Buffer;
   UINTN                          PageCount;
   EFI_STATUS                     Status;
   EFI_PHYSICAL_ADDRESS           DstBuffer;
@@ -302,17 +301,12 @@  MmLoadImage (
 
   DEBUG ((DEBUG_INFO, "MmLoadImage - %g\n", &DriverEntry->FileName));
 
-  Buffer = AllocateCopyPool (DriverEntry->Pe32DataSize, DriverEntry->Pe32Data);
-  if (Buffer == NULL) {
-    return EFI_OUT_OF_RESOURCES;
-  }
-
   Status               = EFI_SUCCESS;
 
   //
   // Initialize ImageContext
   //
-  ImageContext.Handle = Buffer;
+  ImageContext.Handle = DriverEntry->Pe32Data;
   ImageContext.ImageRead = PeCoffLoaderImageReadFromMemory;
 
   //
@@ -320,9 +314,6 @@  MmLoadImage (
   //
   Status = PeCoffLoaderGetImageInfo (&ImageContext);
   if (EFI_ERROR (Status)) {
-    if (Buffer != NULL) {
-      MmFreePool (Buffer);
-    }
     return Status;
   }
 
@@ -336,9 +327,6 @@  MmLoadImage (
              &DstBuffer
              );
   if (EFI_ERROR (Status)) {
-    if (Buffer != NULL) {
-      MmFreePool (Buffer);
-    }
     return Status;
   }
 
@@ -355,9 +343,6 @@  MmLoadImage (
   //
   Status = PeCoffLoaderLoadImage (&ImageContext);
   if (EFI_ERROR (Status)) {
-    if (Buffer != NULL) {
-      MmFreePool (Buffer);
-    }
     MmFreePages (DstBuffer, PageCount);
     return Status;
   }
@@ -367,9 +352,6 @@  MmLoadImage (
   //
   Status = PeCoffLoaderRelocateImage (&ImageContext);
   if (EFI_ERROR (Status)) {
-    if (Buffer != NULL) {
-      MmFreePool (Buffer);
-    }
     MmFreePages (DstBuffer, PageCount);
     return Status;
   }
@@ -393,9 +375,6 @@  MmLoadImage (
                                               (VOID **)&DriverEntry->LoadedImage
                                               );
     if (EFI_ERROR (Status)) {
-      if (Buffer != NULL) {
-        MmFreePool (Buffer);
-      }
       MmFreePages (DstBuffer, PageCount);
       return Status;
     }
@@ -482,13 +461,6 @@  MmLoadImage (
 
   DEBUG_CODE_END ();
 
-  //
-  // Free buffer allocated by Fv->ReadSection.
-  //
-  // The UEFI Boot Services FreePool() function must be used because Fv->ReadSection
-  // used the UEFI Boot Services AllocatePool() function
-  //
-  MmFreePool (Buffer);
   return Status;
 }