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>
IN OUT EFI_MM_DRIVER_ENTRY *DriverEntry\r
)\r
{\r
IN OUT EFI_MM_DRIVER_ENTRY *DriverEntry\r
)\r
{\r
UINTN PageCount;\r
EFI_STATUS Status;\r
EFI_PHYSICAL_ADDRESS DstBuffer;\r
UINTN PageCount;\r
EFI_STATUS Status;\r
EFI_PHYSICAL_ADDRESS DstBuffer;\r
\r
DEBUG ((DEBUG_INFO, "MmLoadImage - %g\n", &DriverEntry->FileName));\r
\r
\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
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
ImageContext.ImageRead = PeCoffLoaderImageReadFromMemory;\r
\r
//\r
//\r
Status = PeCoffLoaderGetImageInfo (&ImageContext);\r
if (EFI_ERROR (Status)) {\r
//\r
Status = PeCoffLoaderGetImageInfo (&ImageContext);\r
if (EFI_ERROR (Status)) {\r
- if (Buffer != NULL) {\r
- MmFreePool (Buffer);\r
- }\r
&DstBuffer\r
);\r
if (EFI_ERROR (Status)) {\r
&DstBuffer\r
);\r
if (EFI_ERROR (Status)) {\r
- if (Buffer != NULL) {\r
- MmFreePool (Buffer);\r
- }\r
//\r
Status = PeCoffLoaderLoadImage (&ImageContext);\r
if (EFI_ERROR (Status)) {\r
//\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
MmFreePages (DstBuffer, PageCount);\r
return Status;\r
}\r
//\r
Status = PeCoffLoaderRelocateImage (&ImageContext);\r
if (EFI_ERROR (Status)) {\r
//\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
MmFreePages (DstBuffer, PageCount);\r
return Status;\r
}\r
(VOID **)&DriverEntry->LoadedImage\r
);\r
if (EFI_ERROR (Status)) {\r
(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
MmFreePages (DstBuffer, PageCount);\r
return Status;\r
}\r
\r
DEBUG_CODE_END ();\r
\r
\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