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>
Reviewed-by: Achin Gupta <achin.gupta@arm.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
This commit is contained in:
Ard Biesheuvel 2019-01-16 21:22:34 +01:00
parent 77746e7080
commit 877013d0a5
1 changed files with 1 additions and 29 deletions

View File

@ -294,7 +294,6 @@ MmLoadImage (
IN OUT EFI_MM_DRIVER_ENTRY *DriverEntry IN OUT EFI_MM_DRIVER_ENTRY *DriverEntry
) )
{ {
VOID *Buffer;
UINTN PageCount; UINTN PageCount;
EFI_STATUS Status; EFI_STATUS Status;
EFI_PHYSICAL_ADDRESS DstBuffer; EFI_PHYSICAL_ADDRESS DstBuffer;
@ -302,17 +301,12 @@ MmLoadImage (
DEBUG ((DEBUG_INFO, "MmLoadImage - %g\n", &DriverEntry->FileName)); 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; Status = EFI_SUCCESS;
// //
// Initialize ImageContext // Initialize ImageContext
// //
ImageContext.Handle = Buffer; ImageContext.Handle = DriverEntry->Pe32Data;
ImageContext.ImageRead = PeCoffLoaderImageReadFromMemory; ImageContext.ImageRead = PeCoffLoaderImageReadFromMemory;
// //
@ -320,9 +314,6 @@ MmLoadImage (
// //
Status = PeCoffLoaderGetImageInfo (&ImageContext); Status = PeCoffLoaderGetImageInfo (&ImageContext);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
if (Buffer != NULL) {
MmFreePool (Buffer);
}
return Status; return Status;
} }
@ -336,9 +327,6 @@ MmLoadImage (
&DstBuffer &DstBuffer
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
if (Buffer != NULL) {
MmFreePool (Buffer);
}
return Status; return Status;
} }
@ -355,9 +343,6 @@ MmLoadImage (
// //
Status = PeCoffLoaderLoadImage (&ImageContext); Status = PeCoffLoaderLoadImage (&ImageContext);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
if (Buffer != NULL) {
MmFreePool (Buffer);
}
MmFreePages (DstBuffer, PageCount); MmFreePages (DstBuffer, PageCount);
return Status; return Status;
} }
@ -367,9 +352,6 @@ MmLoadImage (
// //
Status = PeCoffLoaderRelocateImage (&ImageContext); Status = PeCoffLoaderRelocateImage (&ImageContext);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
if (Buffer != NULL) {
MmFreePool (Buffer);
}
MmFreePages (DstBuffer, PageCount); MmFreePages (DstBuffer, PageCount);
return Status; return Status;
} }
@ -393,9 +375,6 @@ MmLoadImage (
(VOID **)&DriverEntry->LoadedImage (VOID **)&DriverEntry->LoadedImage
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
if (Buffer != NULL) {
MmFreePool (Buffer);
}
MmFreePages (DstBuffer, PageCount); MmFreePages (DstBuffer, PageCount);
return Status; return Status;
} }
@ -482,13 +461,6 @@ MmLoadImage (
DEBUG_CODE_END (); 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; return Status;
} }