public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Ard Biesheuvel <ard.biesheuvel@linaro.org>
To: edk2-devel@lists.01.org
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>,
	Achin Gupta <achin.gupta@arm.com>,
	Jiewen Yao <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
Date: Wed, 16 Jan 2019 21:22:34 +0100	[thread overview]
Message-ID: <20190116202236.6977-10-ard.biesheuvel@linaro.org> (raw)
In-Reply-To: <20190116202236.6977-1-ard.biesheuvel@linaro.org>

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



  parent reply	other threads:[~2019-01-16 20:22 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-16 20:22 [PATCH v2 00/11] StandaloneMmPkg: assorted fixes and improvements Ard Biesheuvel
2019-01-16 20:22 ` [PATCH v2 01/11] StandaloneMmPkg: add HobLib implementation for MM_STANDALONE modules Ard Biesheuvel
2019-01-18 15:24   ` Yao, Jiewen
2019-01-16 20:22 ` [PATCH v2 02/11] StandaloneMmPkg: add MM_STANDALONE MemoryAllocationLib implementation Ard Biesheuvel
2019-01-18 15:23   ` Yao, Jiewen
2019-01-16 20:22 ` [PATCH v2 03/11] StandaloneMmPkg/StandaloneMmCoreHobLib: restrict to MM_CORE_STANDALONE Ard Biesheuvel
2019-01-18 15:24   ` Yao, Jiewen
2019-01-16 20:22 ` [PATCH v2 04/11] StandaloneMmPkg/StandaloneMmCpu: fix typo Standlone -> Standalone Ard Biesheuvel
2019-01-16 20:22 ` [PATCH v2 05/11] StandaloneMmPkg/StandaloneMmCoreEntryPoint: add missing SerialPortLib ref Ard Biesheuvel
2019-01-18 15:27   ` Yao, Jiewen
2019-01-18 15:31     ` Ard Biesheuvel
2019-01-18 15:33       ` Yao, Jiewen
2019-01-16 20:22 ` [PATCH v2 06/11] StandaloneMmPkg/StandaloneMmCoreEntryPoint: use %a modifier for ASCII strings Ard Biesheuvel
2019-01-16 20:22 ` [PATCH v2 07/11] StandaloneMmPkg/StandaloneMmCoreEntryPoint: remove bogus ASSERT_EFI_ERROR()s Ard Biesheuvel
2019-01-16 20:22 ` [PATCH v2 08/11] StandaloneMmPkg/StandaloneMmPeCoffExtraActionLib: ignore runtime attribute Ard Biesheuvel
2019-01-16 20:22 ` Ard Biesheuvel [this message]
2019-01-18 15:34   ` [PATCH v2 09/11] StandaloneMmPkg/Core/Dispatcher: don't copy dispatched image twice Yao, Jiewen
2019-01-16 20:22 ` [PATCH v2 10/11] StandaloneMmPkg/StandaloneMmCoreEntryPoint: permit the use of TE images Ard Biesheuvel
2019-01-16 20:22 ` [PATCH v2 11/11] StandaloneMmPkg/Core: permit encapsulated firmware volumes Ard Biesheuvel
2019-01-18 15:39   ` Yao, Jiewen
2019-01-18 15:41     ` Ard Biesheuvel
2019-01-18 15:49       ` Yao, Jiewen
2019-01-18  9:26 ` [PATCH v2 00/11] StandaloneMmPkg: assorted fixes and improvements Achin Gupta
2019-01-18 15:41   ` Yao, Jiewen
2019-01-21 14:39     ` Ard Biesheuvel

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=20190116202236.6977-10-ard.biesheuvel@linaro.org \
    --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