/** @file\r
Core image handling services to load and unload PeImage.\r
\r
-Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>\r
This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
which accompanies this distribution. The full text of the license may be found at\r
Image->RuntimeData->RelocationData = Image->ImageContext.FixupData;\r
Image->RuntimeData->Handle = Image->Handle;\r
InsertTailList (&gRuntime->ImageHead, &Image->RuntimeData->Link);\r
+ InsertImageRecord (Image->RuntimeData);\r
}\r
}\r
\r
UINTN OpenInfoCount;\r
UINTN OpenInfoIndex;\r
\r
+ HandleBuffer = NULL;\r
+ ProtocolGuidArray = NULL;\r
+\r
+ if (Image->Started) {\r
+ UnregisterMemoryProfileImage (Image);\r
+ }\r
+\r
if (Image->Ebc != NULL) {\r
//\r
// If EBC protocol exists we must perform cleanups for this image.\r
// Remove the Image from the Runtime Image list as we are about to Free it!\r
//\r
RemoveEntryList (&Image->RuntimeData->Link);\r
+ RemoveImageRecord (Image->RuntimeData);\r
}\r
CoreFreePool (Image->RuntimeData);\r
}\r
UINT32 AuthenticationStatus;\r
EFI_DEVICE_PATH_PROTOCOL *OriginalFilePath;\r
EFI_DEVICE_PATH_PROTOCOL *HandleFilePath;\r
+ EFI_DEVICE_PATH_PROTOCOL *InputFilePath;\r
+ EFI_DEVICE_PATH_PROTOCOL *Node;\r
UINTN FilePathSize;\r
BOOLEAN ImageIsFromFv;\r
+ BOOLEAN ImageIsFromLoadFile;\r
\r
SecurityStatus = EFI_SUCCESS;\r
\r
ZeroMem (&FHand, sizeof (IMAGE_FILE_HANDLE));\r
FHand.Signature = IMAGE_FILE_HANDLE_SIGNATURE;\r
OriginalFilePath = FilePath;\r
+ InputFilePath = FilePath;\r
HandleFilePath = FilePath;\r
DeviceHandle = NULL;\r
Status = EFI_SUCCESS;\r
AuthenticationStatus = 0;\r
- ImageIsFromFv = FALSE;\r
+ ImageIsFromFv = FALSE;\r
+ ImageIsFromLoadFile = FALSE;\r
\r
//\r
// If the caller passed a copy of the file, then just use it\r
if (FilePath == NULL) {\r
return EFI_INVALID_PARAMETER;\r
}\r
+\r
+ //\r
+ // Try to get the image device handle by checking the match protocol.\r
+ //\r
+ Node = NULL;\r
+ Status = CoreLocateDevicePath (&gEfiFirmwareVolume2ProtocolGuid, &HandleFilePath, &DeviceHandle);\r
+ if (!EFI_ERROR (Status)) {\r
+ ImageIsFromFv = TRUE;\r
+ } else {\r
+ HandleFilePath = FilePath;\r
+ Status = CoreLocateDevicePath (&gEfiSimpleFileSystemProtocolGuid, &HandleFilePath, &DeviceHandle);\r
+ if (EFI_ERROR (Status)) {\r
+ if (!BootPolicy) {\r
+ HandleFilePath = FilePath;\r
+ Status = CoreLocateDevicePath (&gEfiLoadFile2ProtocolGuid, &HandleFilePath, &DeviceHandle);\r
+ }\r
+ if (EFI_ERROR (Status)) {\r
+ HandleFilePath = FilePath;\r
+ Status = CoreLocateDevicePath (&gEfiLoadFileProtocolGuid, &HandleFilePath, &DeviceHandle);\r
+ if (!EFI_ERROR (Status)) {\r
+ ImageIsFromLoadFile = TRUE;\r
+ Node = HandleFilePath;\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
//\r
// Get the source file buffer by its device path.\r
//\r
if (FHand.Source == NULL) {\r
Status = EFI_NOT_FOUND;\r
} else {\r
- //\r
- // Try to get the image device handle by checking the match protocol.\r
- //\r
FHand.FreeBuffer = TRUE;\r
- Status = CoreLocateDevicePath (&gEfiFirmwareVolume2ProtocolGuid, &HandleFilePath, &DeviceHandle);\r
- if (!EFI_ERROR (Status)) {\r
- ImageIsFromFv = TRUE;\r
- } else {\r
- HandleFilePath = FilePath;\r
- Status = CoreLocateDevicePath (&gEfiSimpleFileSystemProtocolGuid, &HandleFilePath, &DeviceHandle);\r
- if (EFI_ERROR (Status)) {\r
- if (!BootPolicy) {\r
- HandleFilePath = FilePath;\r
- Status = CoreLocateDevicePath (&gEfiLoadFile2ProtocolGuid, &HandleFilePath, &DeviceHandle);\r
- }\r
- if (EFI_ERROR (Status)) {\r
- HandleFilePath = FilePath;\r
- Status = CoreLocateDevicePath (&gEfiLoadFileProtocolGuid, &HandleFilePath, &DeviceHandle);\r
- }\r
- }\r
+ if (ImageIsFromLoadFile) {\r
+ //\r
+ // LoadFile () may cause the device path of the Handle be updated.\r
+ //\r
+ OriginalFilePath = AppendDevicePath (DevicePathFromHandle (DeviceHandle), Node);\r
}\r
}\r
}\r
if (FHand.FreeBuffer) {\r
CoreFreePool (FHand.Source);\r
}\r
+ if (OriginalFilePath != InputFilePath) {\r
+ CoreFreePool (OriginalFilePath);\r
+ }\r
\r
//\r
// There was an error. If there's an Image structure, free it\r
// Subsequent calls to LongJump() cause a non-zero value to be returned by SetJump().\r
//\r
if (SetJumpFlag == 0) {\r
+ RegisterMemoryProfileImage (Image, (Image->ImageContext.ImageType == EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION ? EFI_FV_FILETYPE_APPLICATION : EFI_FV_FILETYPE_DRIVER));\r
//\r
// Call the image's entry point\r
//\r