]> git.proxmox.com Git - mirror_edk2.git/commitdiff
StandaloneMmPkg/Core/Dispatcher: don't copy dispatched image twice
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Wed, 16 Jan 2019 20:22:34 +0000 (21:22 +0100)
committerArd Biesheuvel <ard.biesheuvel@linaro.org>
Mon, 21 Jan 2019 13:42:37 +0000 (14:42 +0100)
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>
Reviewed-by: Achin Gupta <achin.gupta@arm.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
StandaloneMmPkg/Core/Dispatcher.c

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