]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Dxe/Image/Image.c
check the usage of %d,%x,%ld,%lx and so on in debug print statement.
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / Image / Image.c
index ff22c9b0f5c3932f22aaffab1723570beb59ef01..36893d9650ad38119ed7fa07aa66c619430503a0 100644 (file)
@@ -1,6 +1,7 @@
-/*++\r
+/** @file\r
+  Core image handling services to load and unload PeImage.\r
 \r
-Copyright (c) 2006 - 2007, Intel Corporation\r
+Copyright (c) 2006 - 2008, Intel Corporation. <BR>\r
 All rights reserved. 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
@@ -9,21 +10,14 @@ http://opensource.org/licenses/bsd-license.php
 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
-Module Name:\r
+**/\r
 \r
-  Image.c\r
+#include "DxeMain.h"\r
+#include "Image.h"\r
 \r
-Abstract:\r
-\r
-  Core image handling services\r
-\r
---*/\r
-\r
-#include <DxeMain.h>\r
 //\r
 // Module Globals\r
 //\r
-\r
 LOADED_IMAGE_PRIVATE_DATA  *mCurrentImage = NULL;\r
 \r
 LOAD_PE32_IMAGE_PRIVATE_DATA  mLoadPe32PrivateData = {\r
@@ -78,26 +72,20 @@ LOADED_IMAGE_PRIVATE_DATA mCorePrivateImage  = {
 };\r
 \r
 \r
-EFI_STATUS\r
-CoreInitializeImageServices (\r
-  IN  VOID *HobStart\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
 \r
+/**\r
   Add the Image Services to EFI Boot Services Table and install the protocol\r
   interfaces for this image.\r
 \r
-Arguments:\r
-\r
-  HobStart        - The HOB to initialize\r
+  @param  HobStart                The HOB to initialize\r
 \r
-Returns:\r
+  @return Status code.\r
 \r
-  Status code.\r
-\r
---*/\r
+**/\r
+EFI_STATUS\r
+CoreInitializeImageServices (\r
+  IN  VOID *HobStart\r
+  )\r
 {\r
   EFI_STATUS                        Status;\r
   LOADED_IMAGE_PRIVATE_DATA         *Image;\r
@@ -167,41 +155,37 @@ Returns:
            );\r
 }\r
 \r
+\r
+/**\r
+  Loads, relocates, and invokes a PE/COFF image\r
+\r
+  @param  BootPolicy              If TRUE, indicates that the request originates\r
+                                  from the boot manager, and that the boot\r
+                                  manager is attempting to load FilePath as a\r
+                                  boot selection.\r
+  @param  Pe32Handle              The handle of PE32 image\r
+  @param  Image                   PE image to be loaded\r
+  @param  DstBuffer               The buffer to store the image\r
+  @param  EntryPoint              A pointer to the entry point\r
+  @param  Attribute               The bit mask of attributes to set for the load\r
+                                  PE image\r
+\r
+  @retval EFI_SUCCESS             The file was loaded, relocated, and invoked\r
+  @retval EFI_OUT_OF_RESOURCES    There was not enough memory to load and\r
+                                  relocate the PE/COFF file\r
+  @retval EFI_INVALID_PARAMETER   Invalid parameter\r
+  @retval EFI_BUFFER_TOO_SMALL    Buffer for image is too small\r
+\r
+**/\r
 EFI_STATUS\r
 CoreLoadPeImage (\r
-  IN BOOLEAN                     BootPolicy,  \r
+  IN BOOLEAN                     BootPolicy,\r
   IN VOID                        *Pe32Handle,\r
   IN LOADED_IMAGE_PRIVATE_DATA   *Image,\r
   IN EFI_PHYSICAL_ADDRESS        DstBuffer    OPTIONAL,\r
   OUT EFI_PHYSICAL_ADDRESS       *EntryPoint  OPTIONAL,\r
   IN  UINT32                     Attribute\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Loads, relocates, and invokes a PE/COFF image\r
-\r
-Arguments:\r
-  BootPolicy       - If TRUE, indicates that the request originates from the boot manager,\r
-                     and that the boot manager is attempting to load FilePath as a boot selection.\r
-  Pe32Handle       - The handle of PE32 image\r
-  Image            - PE image to be loaded\r
-  DstBuffer        - The buffer to store the image\r
-  EntryPoint       - A pointer to the entry point\r
-  Attribute        - The bit mask of attributes to set for the load PE image\r
-\r
-Returns:\r
-\r
-  EFI_SUCCESS          - The file was loaded, relocated, and invoked\r
-\r
-  EFI_OUT_OF_RESOURCES - There was not enough memory to load and relocate the PE/COFF file\r
-\r
-  EFI_INVALID_PARAMETER - Invalid parameter\r
-\r
-  EFI_BUFFER_TOO_SMALL  - Buffer for image is too small\r
-\r
---*/\r
 {\r
   EFI_STATUS                Status;\r
   BOOLEAN                   DstBufAlocated;\r
@@ -233,7 +217,7 @@ Returns:
       return EFI_UNSUPPORTED;\r
     }\r
   }\r
-  \r
+\r
   //\r
   // Set EFI memory type based on ImageType\r
   //\r
@@ -331,9 +315,11 @@ Returns:
   }\r
 \r
   Image->ImageBasePage = Image->ImageContext.ImageAddress;\r
-  Image->ImageContext.ImageAddress =\r
-      (Image->ImageContext.ImageAddress + Image->ImageContext.SectionAlignment - 1) &\r
-      ~((UINTN)Image->ImageContext.SectionAlignment - 1);\r
+  if (!Image->ImageContext.IsTeImage) {\r
+         Image->ImageContext.ImageAddress =\r
+             (Image->ImageContext.ImageAddress + Image->ImageContext.SectionAlignment - 1) &\r
+             ~((UINTN)Image->ImageContext.SectionAlignment - 1);\r
+  }\r
 \r
   //\r
   // Load the image from the file into the allocated memory\r
@@ -348,9 +334,9 @@ Returns:
   // is used to relocate the image when SetVirtualAddressMap() is called. The\r
   // relocation is done by the Runtime AP.\r
   //\r
-  if (Attribute & EFI_LOAD_PE_IMAGE_ATTRIBUTE_RUNTIME_REGISTRATION) {\r
+  if ((Attribute & EFI_LOAD_PE_IMAGE_ATTRIBUTE_RUNTIME_REGISTRATION) != 0) {\r
     if (Image->ImageContext.ImageType == EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER) {\r
-      Image->ImageContext.FixupData = CoreAllocateRuntimePool ((UINTN)(Image->ImageContext.FixupDataSize));\r
+      Image->ImageContext.FixupData = AllocateRuntimePool ((UINTN)(Image->ImageContext.FixupDataSize));\r
       if (Image->ImageContext.FixupData == NULL) {\r
         Status = EFI_OUT_OF_RESOURCES;\r
         goto Done;\r
@@ -413,6 +399,7 @@ Returns:
     //\r
     Status = CoreLocateProtocol (&gEfiEbcProtocolGuid, NULL, (VOID **)&Image->Ebc);\r
     if (EFI_ERROR(Status)) {\r
+      DEBUG ((DEBUG_LOAD | DEBUG_ERROR, "CoreLoadPeImage: There is no EBC interpreter for an EBC image.\n"));\r
       goto Done;\r
     }\r
 \r
@@ -432,8 +419,8 @@ Returns:
     Status = Image->Ebc->CreateThunk (\r
                            Image->Ebc,\r
                            Image->Handle,\r
-                           (VOID *)(UINTN)Image->ImageContext.EntryPoint,\r
-                           (VOID **)&Image->EntryPoint\r
+                           (VOID *)(UINTN) Image->ImageContext.EntryPoint,\r
+                           (VOID **) &Image->EntryPoint\r
                            );\r
     if (EFI_ERROR(Status)) {\r
       goto Done;\r
@@ -448,12 +435,12 @@ Returns:
   Image->Info.ImageSize     = Image->ImageContext.ImageSize;\r
   Image->Info.ImageCodeType = (EFI_MEMORY_TYPE) (Image->ImageContext.ImageCodeMemoryType);\r
   Image->Info.ImageDataType = (EFI_MEMORY_TYPE) (Image->ImageContext.ImageDataMemoryType);\r
-  if (Attribute & EFI_LOAD_PE_IMAGE_ATTRIBUTE_RUNTIME_REGISTRATION) {\r
+  if ((Attribute & EFI_LOAD_PE_IMAGE_ATTRIBUTE_RUNTIME_REGISTRATION) != 0) {\r
     if (Image->ImageContext.ImageType == EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER) {\r
       //\r
       // Make a list off all the RT images so we can let the RT AP know about them.\r
       //\r
-      Image->RuntimeData = CoreAllocateRuntimePool (sizeof(EFI_RUNTIME_IMAGE_ENTRY));\r
+      Image->RuntimeData = AllocateRuntimePool (sizeof(EFI_RUNTIME_IMAGE_ENTRY));\r
       if (Image->RuntimeData == NULL) {\r
         goto Done;\r
       }\r
@@ -481,22 +468,14 @@ Returns:
     UINTN Index;\r
     UINTN StartIndex;\r
     CHAR8 EfiFileName[256];\r
-    \r
-    if (Image->ImageContext.Machine != IMAGE_FILE_MACHINE_IA64) {\r
-      DEBUG ((EFI_D_INFO | EFI_D_LOAD, \r
-              "Loading driver at 0x%10p EntryPoint=0x%10p ", \r
-              (VOID *)(UINTN)Image->ImageContext.ImageAddress, \r
-              (VOID *)(UINTN)Image->ImageContext.EntryPoint));\r
-    } else {\r
-      //\r
-      // For IPF Image, the real entry point should be print.\r
-      //      \r
-      DEBUG ((EFI_D_INFO | EFI_D_LOAD, \r
-              "Loading driver at 0x%10p EntryPoint=0x%10p ", \r
-              (VOID *)(UINTN)Image->ImageContext.ImageAddress, \r
-              (VOID *)(UINTN)(*(UINT64 *)(UINTN)Image->ImageContext.EntryPoint)));\r
-    }\r
-    \r
+\r
+\r
+    DEBUG ((DEBUG_INFO | DEBUG_LOAD,\r
+           "Loading driver at 0x%11p EntryPoint=0x%11p ",\r
+           (VOID *)(UINTN) Image->ImageContext.ImageAddress,\r
+           FUNCTION_ENTRY_POINT (Image->ImageContext.EntryPoint)));\r
+\r
+\r
     //\r
     // Print Module Name by Pdb file path\r
     //\r
@@ -523,9 +502,9 @@ Returns:
           break;\r
         }\r
       }\r
-      DEBUG ((EFI_D_INFO | EFI_D_LOAD, "%a", EfiFileName)); // &Image->ImageContext.PdbPointer[StartIndex]));\r
+      DEBUG ((DEBUG_INFO | DEBUG_LOAD, "%a", EfiFileName)); // &Image->ImageContext.PdbPointer[StartIndex]));\r
     }\r
-    DEBUG ((EFI_D_INFO | EFI_D_LOAD, "\n"));\r
+    DEBUG ((DEBUG_INFO | DEBUG_LOAD, "\n"));\r
 \r
   DEBUG_CODE_END ();\r
 \r
@@ -549,25 +528,19 @@ Done:
 }\r
 \r
 \r
-LOADED_IMAGE_PRIVATE_DATA *\r
-CoreLoadedImageInfo (\r
-  IN EFI_HANDLE  ImageHandle\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
 \r
+/**\r
   Get the image's private data from its handle.\r
 \r
-Arguments:\r
-\r
-  ImageHandle     - The image handle\r
+  @param  ImageHandle             The image handle\r
 \r
-Returns:\r
+  @return Return the image private data associated with ImageHandle.\r
 \r
-  Return the image private data associated with ImageHandle.\r
-\r
---*/\r
+**/\r
+LOADED_IMAGE_PRIVATE_DATA *\r
+CoreLoadedImageInfo (\r
+  IN EFI_HANDLE  ImageHandle\r
+  )\r
 {\r
   EFI_STATUS                 Status;\r
   EFI_LOADED_IMAGE_PROTOCOL  *LoadedImage;\r
@@ -581,14 +554,191 @@ Returns:
   if (!EFI_ERROR (Status)) {\r
     Image = LOADED_IMAGE_PRIVATE_DATA_FROM_THIS (LoadedImage);\r
   } else {\r
-    DEBUG ((EFI_D_LOAD, "CoreLoadedImageInfo: Not an ImageHandle %x\n", ImageHandle));\r
+    DEBUG ((DEBUG_LOAD, "CoreLoadedImageInfo: Not an ImageHandle %p\n", ImageHandle));\r
     Image = NULL;\r
   }\r
 \r
   return Image;\r
 }\r
 \r
-STATIC\r
+\r
+/**\r
+  Unloads EFI image from memory.\r
+\r
+  @param  Image                   EFI image\r
+  @param  FreePage                Free allocated pages\r
+\r
+**/\r
+VOID\r
+CoreUnloadAndCloseImage (\r
+  IN LOADED_IMAGE_PRIVATE_DATA  *Image,\r
+  IN BOOLEAN                    FreePage\r
+  )\r
+{\r
+  EFI_STATUS                          Status;\r
+  UINTN                               HandleCount;\r
+  EFI_HANDLE                          *HandleBuffer;\r
+  UINTN                               HandleIndex;\r
+  EFI_GUID                            **ProtocolGuidArray;\r
+  UINTN                               ArrayCount;\r
+  UINTN                               ProtocolIndex;\r
+  EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfo;\r
+  UINTN                               OpenInfoCount;\r
+  UINTN                               OpenInfoIndex;\r
+\r
+  if (Image->Ebc != NULL) {\r
+    //\r
+    // If EBC protocol exists we must perform cleanups for this image.\r
+    //\r
+    Image->Ebc->UnloadImage (Image->Ebc, Image->Handle);\r
+  }\r
+\r
+  //\r
+  // Unload image, free Image->ImageContext->ModHandle\r
+  //\r
+  PeCoffLoaderUnloadImage (&Image->ImageContext);\r
+\r
+  //\r
+  // Free our references to the image handle\r
+  //\r
+  if (Image->Handle != NULL) {\r
+\r
+    Status = CoreLocateHandleBuffer (\r
+               AllHandles,\r
+               NULL,\r
+               NULL,\r
+               &HandleCount,\r
+               &HandleBuffer\r
+               );\r
+    if (!EFI_ERROR (Status)) {\r
+      for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {\r
+        Status = CoreProtocolsPerHandle (\r
+                   HandleBuffer[HandleIndex],\r
+                   &ProtocolGuidArray,\r
+                   &ArrayCount\r
+                   );\r
+        if (!EFI_ERROR (Status)) {\r
+          for (ProtocolIndex = 0; ProtocolIndex < ArrayCount; ProtocolIndex++) {\r
+            Status = CoreOpenProtocolInformation (\r
+                       HandleBuffer[HandleIndex],\r
+                       ProtocolGuidArray[ProtocolIndex],\r
+                       &OpenInfo,\r
+                       &OpenInfoCount\r
+                       );\r
+            if (!EFI_ERROR (Status)) {\r
+              for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) {\r
+                if (OpenInfo[OpenInfoIndex].AgentHandle == Image->Handle) {\r
+                  Status = CoreCloseProtocol (\r
+                             HandleBuffer[HandleIndex],\r
+                             ProtocolGuidArray[ProtocolIndex],\r
+                             Image->Handle,\r
+                             OpenInfo[OpenInfoIndex].ControllerHandle\r
+                             );\r
+                }\r
+              }\r
+              if (OpenInfo != NULL) {\r
+                CoreFreePool(OpenInfo);\r
+              }\r
+            }\r
+          }\r
+          if (ProtocolGuidArray != NULL) {\r
+            CoreFreePool(ProtocolGuidArray);\r
+          }\r
+        }\r
+      }\r
+      if (HandleBuffer != NULL) {\r
+        CoreFreePool (HandleBuffer);\r
+      }\r
+    }\r
+\r
+    CoreRemoveDebugImageInfoEntry (Image->Handle);\r
+\r
+    Status = CoreUninstallProtocolInterface (\r
+               Image->Handle,\r
+               &gEfiLoadedImageDevicePathProtocolGuid,\r
+               Image->LoadedImageDevicePath\r
+               );\r
+\r
+    Status = CoreUninstallProtocolInterface (\r
+               Image->Handle,\r
+               &gEfiLoadedImageProtocolGuid,\r
+               &Image->Info\r
+               );\r
+\r
+  }\r
+\r
+  if (Image->RuntimeData != NULL) {\r
+    if (Image->RuntimeData->Link.ForwardLink != NULL) {\r
+      //\r
+      // Remove the Image from the Runtime Image list as we are about to Free it!\r
+      //\r
+      RemoveEntryList (&Image->RuntimeData->Link);\r
+    }\r
+    CoreFreePool (Image->RuntimeData);\r
+  }\r
+\r
+  //\r
+  // Free the Image from memory\r
+  //\r
+  if ((Image->ImageBasePage != 0) && FreePage) {\r
+    CoreFreePages (Image->ImageBasePage, Image->NumberOfPages);\r
+  }\r
+\r
+  //\r
+  // Done with the Image structure\r
+  //\r
+  if (Image->Info.FilePath != NULL) {\r
+    CoreFreePool (Image->Info.FilePath);\r
+  }\r
+\r
+  if (Image->LoadedImageDevicePath != NULL) {\r
+    CoreFreePool (Image->LoadedImageDevicePath);\r
+  }\r
+\r
+  if (Image->FixupData != NULL) {\r
+    CoreFreePool (Image->FixupData);\r
+  }\r
+\r
+  CoreFreePool (Image);\r
+}\r
+\r
+\r
+/**\r
+  Loads an EFI image into memory and returns a handle to the image.\r
+\r
+  @param  BootPolicy              If TRUE, indicates that the request originates\r
+                                  from the boot manager, and that the boot\r
+                                  manager is attempting to load FilePath as a\r
+                                  boot selection.\r
+  @param  ParentImageHandle       The caller's image handle.\r
+  @param  FilePath                The specific file path from which the image is\r
+                                  loaded.\r
+  @param  SourceBuffer            If not NULL, a pointer to the memory location\r
+                                  containing a copy of the image to be loaded.\r
+  @param  SourceSize              The size in bytes of SourceBuffer.\r
+  @param  DstBuffer               The buffer to store the image\r
+  @param  NumberOfPages           If not NULL, it inputs a pointer to the page\r
+                                  number of DstBuffer and outputs a pointer to\r
+                                  the page number of the image. If this number is\r
+                                  not enough,  return EFI_BUFFER_TOO_SMALL and\r
+                                  this parameter contains the required number.\r
+  @param  ImageHandle             Pointer to the returned image handle that is\r
+                                  created when the image is successfully loaded.\r
+  @param  EntryPoint              A pointer to the entry point\r
+  @param  Attribute               The bit mask of attributes to set for the load\r
+                                  PE image\r
+\r
+  @retval EFI_SUCCESS             The image was loaded into memory.\r
+  @retval EFI_NOT_FOUND           The FilePath was not found.\r
+  @retval EFI_INVALID_PARAMETER   One of the parameters has an invalid value.\r
+  @retval EFI_BUFFER_TOO_SMALL    The buffer is too small\r
+  @retval EFI_UNSUPPORTED         The image type is not supported, or the device\r
+                                  path cannot be parsed to locate the proper\r
+                                  protocol for loading the file.\r
+  @retval EFI_OUT_OF_RESOURCES    Image was not loaded due to insufficient\r
+                                  resources.\r
+\r
+**/\r
 EFI_STATUS\r
 CoreLoadImageCommon (\r
   IN  BOOLEAN                          BootPolicy,\r
@@ -602,40 +752,6 @@ CoreLoadImageCommon (
   OUT EFI_PHYSICAL_ADDRESS             *EntryPoint         OPTIONAL,\r
   IN  UINT32                           Attribute\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Loads an EFI image into memory and returns a handle to the image.\r
-\r
-Arguments:\r
-\r
-  BootPolicy          - If TRUE, indicates that the request originates from the boot manager,\r
-                        and that the boot manager is attempting to load FilePath as a boot selection.\r
-  ParentImageHandle   - The caller's image handle.\r
-  FilePath            - The specific file path from which the image is loaded.\r
-  SourceBuffer        - If not NULL, a pointer to the memory location containing a copy of\r
-                        the image to be loaded.\r
-  SourceSize          - The size in bytes of SourceBuffer.\r
-  DstBuffer           - The buffer to store the image\r
-  NumberOfPages       - If not NULL, a pointer to the image's page number, if this number\r
-                        is not enough, return EFI_BUFFER_TOO_SMALL and this parameter contain\r
-                        the required number.\r
-  ImageHandle         - Pointer to the returned image handle that is created when the image\r
-                        is successfully loaded.\r
-  EntryPoint          - A pointer to the entry point\r
-  Attribute           - The bit mask of attributes to set for the load PE image\r
-\r
-Returns:\r
-\r
-  EFI_SUCCESS            - The image was loaded into memory.\r
-  EFI_NOT_FOUND          - The FilePath was not found.\r
-  EFI_INVALID_PARAMETER  - One of the parameters has an invalid value.\r
-  EFI_BUFFER_TOO_SMALL   - The buffer is too small\r
-  EFI_UNSUPPORTED        - The image type is not supported, or the device path cannot be\r
-                           parsed to locate the proper protocol for loading the file.\r
-  EFI_OUT_OF_RESOURCES   - Image was not loaded due to insufficient resources.\r
---*/\r
 {\r
   LOADED_IMAGE_PRIVATE_DATA  *Image;\r
   LOADED_IMAGE_PRIVATE_DATA  *ParentImage;\r
@@ -662,7 +778,7 @@ Returns:
 \r
   ParentImage = CoreLoadedImageInfo (ParentImageHandle);\r
   if (ParentImage == NULL) {\r
-    DEBUG((EFI_D_LOAD|EFI_D_ERROR, "LoadImageEx: Parent handle not an image handle\n"));\r
+    DEBUG((DEBUG_LOAD|DEBUG_ERROR, "LoadImageEx: Parent handle not an image handle\n"));\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -706,7 +822,7 @@ Returns:
   //\r
   // Allocate a new image structure\r
   //\r
-  Image = CoreAllocateZeroBootServicesPool (sizeof(LOADED_IMAGE_PRIVATE_DATA));\r
+  Image = AllocateZeroPool (sizeof(LOADED_IMAGE_PRIVATE_DATA));\r
   if (Image == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
@@ -717,8 +833,8 @@ Returns:
   FilePath = OriginalFilePath;\r
   Status = CoreHandleProtocol (DeviceHandle, &gEfiDevicePathProtocolGuid, (VOID **)&HandleFilePath);\r
   if (!EFI_ERROR (Status)) {\r
-    FilePathSize = CoreDevicePathSize (HandleFilePath) - sizeof(EFI_DEVICE_PATH_PROTOCOL);\r
-    FilePath = (EFI_DEVICE_PATH_PROTOCOL *) ( ((UINT8 *)FilePath) + FilePathSize );\r
+    FilePathSize = GetDevicePathSize (HandleFilePath) - sizeof(EFI_DEVICE_PATH_PROTOCOL);\r
+    FilePath = (EFI_DEVICE_PATH_PROTOCOL *) (((UINT8 *)FilePath) + FilePathSize );\r
   }\r
 \r
   //\r
@@ -727,8 +843,8 @@ Returns:
   Image->Signature         = LOADED_IMAGE_PRIVATE_DATA_SIGNATURE;\r
   Image->Info.SystemTable  = gDxeCoreST;\r
   Image->Info.DeviceHandle = DeviceHandle;\r
-  Image->Info.Revision     = EFI_LOADED_IMAGE_INFORMATION_REVISION;\r
-  Image->Info.FilePath     = CoreDuplicateDevicePath (FilePath);\r
+  Image->Info.Revision     = EFI_LOADED_IMAGE_PROTOCOL_REVISION;\r
+  Image->Info.FilePath     = DuplicateDevicePath (FilePath);\r
   Image->Info.ParentHandle = ParentImageHandle;\r
 \r
 \r
@@ -766,10 +882,14 @@ Returns:
     goto Done;\r
   }\r
 \r
+  if (NumberOfPages != NULL) {\r
+    *NumberOfPages = Image->NumberOfPages;\r
+  }\r
+\r
   //\r
   // Register the image in the Debug Image Info Table if the attribute is set\r
   //\r
-  if (Attribute & EFI_LOAD_PE_IMAGE_ATTRIBUTE_DEBUG_IMAGE_INFO_TABLE_REGISTRATION) {\r
+  if ((Attribute & EFI_LOAD_PE_IMAGE_ATTRIBUTE_DEBUG_IMAGE_INFO_TABLE_REGISTRATION) != 0) {\r
     CoreNewDebugImageInfoEntry (EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL, &Image->Info, Image->Handle);\r
   }\r
 \r
@@ -791,7 +911,7 @@ Returns:
   // otherwise Loaded Image Device Path Protocol is installed with a NULL interface pointer.\r
   //\r
   if (OriginalFilePath != NULL) {\r
-    Image->LoadedImageDevicePath = CoreDuplicateDevicePath (OriginalFilePath);\r
+    Image->LoadedImageDevicePath = DuplicateDevicePath (OriginalFilePath);\r
   }\r
 \r
   //\r
@@ -838,6 +958,33 @@ Done:
 \r
 \r
 \r
+\r
+/**\r
+  Loads an EFI image into memory and returns a handle to the image.\r
+\r
+  @param  BootPolicy              If TRUE, indicates that the request originates\r
+                                  from the boot manager, and that the boot\r
+                                  manager is attempting to load FilePath as a\r
+                                  boot selection.\r
+  @param  ParentImageHandle       The caller's image handle.\r
+  @param  FilePath                The specific file path from which the image is\r
+                                  loaded.\r
+  @param  SourceBuffer            If not NULL, a pointer to the memory location\r
+                                  containing a copy of the image to be loaded.\r
+  @param  SourceSize              The size in bytes of SourceBuffer.\r
+  @param  ImageHandle             Pointer to the returned image handle that is\r
+                                  created when the image is successfully loaded.\r
+\r
+  @retval EFI_SUCCESS             The image was loaded into memory.\r
+  @retval EFI_NOT_FOUND           The FilePath was not found.\r
+  @retval EFI_INVALID_PARAMETER   One of the parameters has an invalid value.\r
+  @retval EFI_UNSUPPORTED         The image type is not supported, or the device\r
+                                  path cannot be parsed to locate the proper\r
+                                  protocol for loading the file.\r
+  @retval EFI_OUT_OF_RESOURCES    Image was not loaded due to insufficient\r
+                                  resources.\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 CoreLoadImage (\r
@@ -848,37 +995,14 @@ CoreLoadImage (
   IN UINTN                      SourceSize,\r
   OUT EFI_HANDLE                *ImageHandle\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Loads an EFI image into memory and returns a handle to the image.\r
-\r
-Arguments:\r
-\r
-  BootPolicy          - If TRUE, indicates that the request originates from the boot manager,\r
-                        and that the boot manager is attempting to load FilePath as a boot selection.\r
-  ParentImageHandle   - The caller's image handle.\r
-  FilePath            - The specific file path from which the image is loaded.\r
-  SourceBuffer        - If not NULL, a pointer to the memory location containing a copy of\r
-                        the image to be loaded.\r
-  SourceSize          - The size in bytes of SourceBuffer.\r
-  ImageHandle         - Pointer to the returned image handle that is created when the image\r
-                        is successfully loaded.\r
-\r
-Returns:\r
-\r
-  EFI_SUCCESS            - The image was loaded into memory.\r
-  EFI_NOT_FOUND          - The FilePath was not found.\r
-  EFI_INVALID_PARAMETER  - One of the parameters has an invalid value.\r
-  EFI_UNSUPPORTED        - The image type is not supported, or the device path cannot be\r
-                           parsed to locate the proper protocol for loading the file.\r
-  EFI_OUT_OF_RESOURCES   - Image was not loaded due to insufficient resources.\r
---*/\r
 {\r
   EFI_STATUS    Status;\r
+  UINT64        Tick;\r
 \r
-  PERF_START (NULL, "LoadImage", NULL, 0);\r
+  Tick = 0;\r
+  PERF_CODE (\r
+    Tick = GetPerformanceCounter ();\r
+  );\r
 \r
   Status = CoreLoadImageCommon (\r
              BootPolicy,\r
@@ -893,12 +1017,43 @@ Returns:
              EFI_LOAD_PE_IMAGE_ATTRIBUTE_RUNTIME_REGISTRATION | EFI_LOAD_PE_IMAGE_ATTRIBUTE_DEBUG_IMAGE_INFO_TABLE_REGISTRATION\r
              );\r
 \r
-  PERF_END (NULL, "LoadImage", NULL, 0);\r
+  PERF_START (*ImageHandle, LOAD_IMAGE_TOK, NULL, Tick);\r
+  PERF_END (*ImageHandle, LOAD_IMAGE_TOK, NULL, 0);\r
 \r
   return Status;\r
 }\r
 \r
 \r
+\r
+/**\r
+  Loads an EFI image into memory and returns a handle to the image with extended parameters.\r
+\r
+  @param  This                    Calling context\r
+  @param  ParentImageHandle       The caller's image handle.\r
+  @param  FilePath                The specific file path from which the image is\r
+                                  loaded.\r
+  @param  SourceBuffer            If not NULL, a pointer to the memory location\r
+                                  containing a copy of the image to be loaded.\r
+  @param  SourceSize              The size in bytes of SourceBuffer.\r
+  @param  DstBuffer               The buffer to store the image.\r
+  @param  NumberOfPages           For input, specifies the space size of the\r
+                                  image by caller if not NULL. For output,\r
+                                  specifies the actual space size needed.\r
+  @param  ImageHandle             Image handle for output.\r
+  @param  EntryPoint              Image entry point for output.\r
+  @param  Attribute               The bit mask of attributes to set for the load\r
+                                  PE image.\r
+\r
+  @retval EFI_SUCCESS             The image was loaded into memory.\r
+  @retval EFI_NOT_FOUND           The FilePath was not found.\r
+  @retval EFI_INVALID_PARAMETER   One of the parameters has an invalid value.\r
+  @retval EFI_UNSUPPORTED         The image type is not supported, or the device\r
+                                  path cannot be parsed to locate the proper\r
+                                  protocol for loading the file.\r
+  @retval EFI_OUT_OF_RESOURCES    Image was not loaded due to insufficient\r
+                                  resources.\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 CoreLoadImageEx (\r
@@ -913,36 +1068,6 @@ CoreLoadImageEx (
   OUT EFI_PHYSICAL_ADDRESS             *EntryPoint         OPTIONAL,\r
   IN  UINT32                           Attribute\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Loads an EFI image into memory and returns a handle to the image with extended parameters.\r
-\r
-Arguments:\r
-\r
-  This                - Calling context\r
-  ParentImageHandle   - The caller's image handle.\r
-  FilePath            - The specific file path from which the image is loaded.\r
-  SourceBuffer        - If not NULL, a pointer to the memory location containing a copy of\r
-                        the image to be loaded.\r
-  SourceSize          - The size in bytes of SourceBuffer.\r
-  DstBuffer           - The buffer to store the image.\r
-  NumberOfPages       - For input, specifies the space size of the image by caller if not NULL.\r
-                        For output, specifies the actual space size needed.\r
-  ImageHandle         - Image handle for output.\r
-  EntryPoint          - Image entry point for output.\r
-  Attribute           - The bit mask of attributes to set for the load PE image.\r
-\r
-Returns:\r
-\r
-  EFI_SUCCESS            - The image was loaded into memory.\r
-  EFI_NOT_FOUND          - The FilePath was not found.\r
-  EFI_INVALID_PARAMETER  - One of the parameters has an invalid value.\r
-  EFI_UNSUPPORTED        - The image type is not supported, or the device path cannot be\r
-                           parsed to locate the proper protocol for loading the file.\r
-  EFI_OUT_OF_RESOURCES   - Image was not loaded due to insufficient resources.\r
---*/\r
 {\r
   return CoreLoadImageCommon (\r
            TRUE,\r
@@ -958,6 +1083,25 @@ Returns:
            );\r
 }\r
 \r
+\r
+/**\r
+  Transfer control to a loaded image's entry point.\r
+\r
+  @param  ImageHandle             Handle of image to be started.\r
+  @param  ExitDataSize            Pointer of the size to ExitData\r
+  @param  ExitData                Pointer to a pointer to a data buffer that\r
+                                  includes a Null-terminated Unicode string,\r
+                                  optionally followed by additional binary data.\r
+                                  The string is a description that the caller may\r
+                                  use to further indicate the reason for the\r
+                                  image's exit.\r
+\r
+  @retval EFI_INVALID_PARAMETER   Invalid parameter\r
+  @retval EFI_OUT_OF_RESOURCES    No enough buffer to allocate\r
+  @retval EFI_SUCCESS             Successfully transfer control to the image's\r
+                                  entry point.\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 CoreStartImage (\r
@@ -965,32 +1109,6 @@ CoreStartImage (
   OUT UINTN      *ExitDataSize,\r
   OUT CHAR16     **ExitData  OPTIONAL\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Transfer control to a loaded image's entry point.\r
-\r
-Arguments:\r
-\r
-  ImageHandle     - Handle of image to be started.\r
-\r
-  ExitDataSize    - Pointer of the size to ExitData\r
-\r
-  ExitData        - Pointer to a pointer to a data buffer that includes a Null-terminated\r
-                    Unicode string, optionally followed by additional binary data. The string\r
-                    is a description that the caller may use to further indicate the reason for\r
-                    the image's exit.\r
-\r
-Returns:\r
-\r
-  EFI_INVALID_PARAMETER     - Invalid parameter\r
-\r
-  EFI_OUT_OF_RESOURCES       - No enough buffer to allocate\r
-\r
-  EFI_SUCCESS               - Successfully transfer control to the image's entry point.\r
-\r
---*/\r
 {\r
   EFI_STATUS                    Status;\r
   LOADED_IMAGE_PRIVATE_DATA     *Image;\r
@@ -999,7 +1117,7 @@ Returns:
   UINTN                         SetJumpFlag;\r
 \r
   Image = CoreLoadedImageInfo (ImageHandle);\r
-  if (Image == NULL_HANDLE  ||  Image->Started) {\r
+  if (Image == NULL  ||  Image->Started) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -1024,7 +1142,7 @@ Returns:
   // JumpContext must be aligned on a CPU specific boundary.\r
   // Overallocate the buffer and force the required alignment\r
   //\r
-  Image->JumpBuffer = CoreAllocateBootServicesPool (sizeof (BASE_LIBRARY_JUMP_BUFFER) + BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT);\r
+  Image->JumpBuffer = AllocatePool (sizeof (BASE_LIBRARY_JUMP_BUFFER) + BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT);\r
   if (Image->JumpBuffer == NULL) {\r
     PERF_END (ImageHandle, START_IMAGE_TOK, NULL, 0);\r
     return EFI_OUT_OF_RESOURCES;\r
@@ -1036,7 +1154,7 @@ Returns:
   // The initial call to SetJump() must always return 0.\r
   // Subsequent calls to LongJump() cause a non-zero value to be returned by SetJump().\r
   //\r
-  if (!SetJumpFlag) {\r
+  if (SetJumpFlag == 0) {\r
     //\r
     // Call the image's entry point\r
     //\r
@@ -1050,7 +1168,7 @@ Returns:
     //\r
     DEBUG_CODE_BEGIN ();\r
       if (EFI_ERROR (Image->Status)) {\r
-        DEBUG ((EFI_D_ERROR, "Error: Image at %10p start failed: %r\n", Image->Info.ImageBase, Image->Status));\r
+        DEBUG ((DEBUG_ERROR, "Error: Image at %11p start failed: %r\n", Image->Info.ImageBase, Image->Status));\r
       }\r
     DEBUG_CODE_END ();\r
 \r
@@ -1084,16 +1202,11 @@ Returns:
   DEBUG_CODE_BEGIN ();\r
     if (Image->ExitDataSize != 0 || Image->ExitData != NULL) {\r
 \r
-      DEBUG (\r
-        (EFI_D_LOAD,\r
-        "StartImage: ExitDataSize %d, ExitData %x",\r
-                            Image->ExitDataSize,\r
-        Image->ExitData)\r
-        );\r
+      DEBUG ((DEBUG_LOAD, "StartImage: ExitDataSize %d, ExitData %p", (UINT32)Image->ExitDataSize, Image->ExitData));\r
       if (Image->ExitData != NULL) {\r
-        DEBUG ((EFI_D_LOAD, " (%hs)", Image->ExitData));\r
+        DEBUG ((DEBUG_LOAD, " (%hs)", Image->ExitData));\r
       }\r
-      DEBUG ((EFI_D_LOAD, "\n"));\r
+      DEBUG ((DEBUG_LOAD, "\n"));\r
     }\r
   DEBUG_CODE_END ();\r
 \r
@@ -1131,158 +1244,29 @@ Returns:
   return Status;\r
 }\r
 \r
+/**\r
+  Terminates the currently loaded EFI image and returns control to boot services.\r
 \r
-VOID\r
-CoreUnloadAndCloseImage (\r
-  IN LOADED_IMAGE_PRIVATE_DATA  *Image,\r
-  IN BOOLEAN                    FreePage\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Unloads EFI image from memory.\r
-\r
-Arguments:\r
-\r
-  Image      - EFI image\r
-  FreePage   - Free allocated pages\r
-\r
-Returns:\r
-\r
-  None\r
-\r
---*/\r
-{\r
-  EFI_STATUS                          Status;\r
-  UINTN                               HandleCount;\r
-  EFI_HANDLE                          *HandleBuffer;\r
-  UINTN                               HandleIndex;\r
-  EFI_GUID                            **ProtocolGuidArray;\r
-  UINTN                               ArrayCount;\r
-  UINTN                               ProtocolIndex;\r
-  EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfo;\r
-  UINTN                               OpenInfoCount;\r
-  UINTN                               OpenInfoIndex;\r
-\r
-  if (Image->Ebc != NULL) {\r
-    //\r
-    // If EBC protocol exists we must perform cleanups for this image.\r
-    //\r
-    Image->Ebc->UnloadImage (Image->Ebc, Image->Handle);\r
-  }\r
-\r
-  //\r
-  // Unload image, free Image->ImageContext->ModHandle\r
-  //\r
-  PeCoffLoaderUnloadImage (&Image->ImageContext);\r
-\r
-  //\r
-  // Free our references to the image handle\r
-  //\r
-  if (Image->Handle != NULL_HANDLE) {\r
-\r
-    Status = CoreLocateHandleBuffer (\r
-               AllHandles,\r
-               NULL,\r
-               NULL,\r
-               &HandleCount,\r
-               &HandleBuffer\r
-               );\r
-    if (!EFI_ERROR (Status)) {\r
-      for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {\r
-        Status = CoreProtocolsPerHandle (\r
-                   HandleBuffer[HandleIndex],\r
-                   &ProtocolGuidArray,\r
-                   &ArrayCount\r
-                   );\r
-        if (!EFI_ERROR (Status)) {\r
-          for (ProtocolIndex = 0; ProtocolIndex < ArrayCount; ProtocolIndex++) {\r
-            Status = CoreOpenProtocolInformation (\r
-                       HandleBuffer[HandleIndex],\r
-                       ProtocolGuidArray[ProtocolIndex],\r
-                       &OpenInfo,\r
-                       &OpenInfoCount\r
-                       );\r
-            if (!EFI_ERROR (Status)) {\r
-              for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) {\r
-                if (OpenInfo[OpenInfoIndex].AgentHandle == Image->Handle) {\r
-                  Status = CoreCloseProtocol (\r
-                             HandleBuffer[HandleIndex],\r
-                             ProtocolGuidArray[ProtocolIndex],\r
-                             Image->Handle,\r
-                             OpenInfo[OpenInfoIndex].ControllerHandle\r
-                             );\r
-                }\r
-              }\r
-              if (OpenInfo != NULL) {\r
-                CoreFreePool(OpenInfo);\r
-              }\r
-            }\r
-          }\r
-          if (ProtocolGuidArray != NULL) {\r
-            CoreFreePool(ProtocolGuidArray);\r
-          }\r
-        }\r
-      }\r
-      if (HandleBuffer != NULL) {\r
-        CoreFreePool (HandleBuffer);\r
-      }\r
-    }\r
-\r
-    CoreRemoveDebugImageInfoEntry (Image->Handle);\r
-\r
-    Status = CoreUninstallProtocolInterface (\r
-               Image->Handle,\r
-               &gEfiLoadedImageDevicePathProtocolGuid,\r
-               Image->LoadedImageDevicePath\r
-               );\r
-\r
-    Status = CoreUninstallProtocolInterface (\r
-               Image->Handle,\r
-               &gEfiLoadedImageProtocolGuid,\r
-               &Image->Info\r
-               );\r
-\r
-  }\r
-\r
-  if (Image->RuntimeData != NULL) {\r
-    if (Image->RuntimeData->Link.ForwardLink != NULL) {\r
-      //\r
-      // Remove the Image from the Runtime Image list as we are about to Free it!\r
-      //\r
-      RemoveEntryList (&Image->RuntimeData->Link);\r
-    }\r
-    CoreFreePool (Image->RuntimeData);\r
-  }\r
-\r
-  //\r
-  // Free the Image from memory\r
-  //\r
-  if ((Image->ImageBasePage != 0) && FreePage) {\r
-    CoreFreePages (Image->ImageBasePage, Image->NumberOfPages);\r
-  }\r
-\r
-  //\r
-  // Done with the Image structure\r
-  //\r
-  if (Image->Info.FilePath != NULL) {\r
-    CoreFreePool (Image->Info.FilePath);\r
-  }\r
-\r
-  if (Image->LoadedImageDevicePath != NULL) {\r
-    CoreFreePool (Image->LoadedImageDevicePath);\r
-  }\r
-\r
-  if (Image->FixupData != NULL) {\r
-    CoreFreePool (Image->FixupData);\r
-  }\r
-\r
-  CoreFreePool (Image);\r
-}\r
-\r
-\r
-\r
+  @param  ImageHandle             Handle that identifies the image. This\r
+                                  parameter is passed to the image on entry.\r
+  @param  Status                  The image's exit code.\r
+  @param  ExitDataSize            The size, in bytes, of ExitData. Ignored if\r
+                                  ExitStatus is EFI_SUCCESS.\r
+  @param  ExitData                Pointer to a data buffer that includes a\r
+                                  Null-terminated Unicode string, optionally\r
+                                  followed by additional binary data. The string\r
+                                  is a description that the caller may use to\r
+                                  further indicate the reason for the image's\r
+                                  exit.\r
+\r
+  @retval EFI_INVALID_PARAMETER   Image handle is NULL or it is not current\r
+                                  image.\r
+  @retval EFI_SUCCESS             Successfully terminates the currently loaded\r
+                                  EFI image.\r
+  @retval EFI_ACCESS_DENIED       Should never reach there.\r
+  @retval EFI_OUT_OF_RESOURCES    Could not allocate pool\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 CoreExit (\r
@@ -1291,35 +1275,6 @@ CoreExit (
   IN UINTN       ExitDataSize,\r
   IN CHAR16      *ExitData  OPTIONAL\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Terminates the currently loaded EFI image and returns control to boot services.\r
-\r
-Arguments:\r
-\r
-  ImageHandle       - Handle that identifies the image. This parameter is passed to the image\r
-                      on entry.\r
-  Status            - The image's exit code.\r
-  ExitDataSize      - The size, in bytes, of ExitData. Ignored if ExitStatus is\r
-                      EFI_SUCCESS.\r
-  ExitData          - Pointer to a data buffer that includes a Null-terminated Unicode string,\r
-                      optionally followed by additional binary data. The string is a\r
-                      description that the caller may use to further indicate the reason for\r
-                      the image's exit.\r
-\r
-Returns:\r
-\r
-  EFI_INVALID_PARAMETER     - Image handle is NULL or it is not current image.\r
-\r
-  EFI_SUCCESS               - Successfully terminates the currently loaded EFI image.\r
-\r
-  EFI_ACCESS_DENIED         - Should never reach there.\r
-\r
-  EFI_OUT_OF_RESOURCES      - Could not allocate pool\r
-\r
---*/\r
 {\r
   LOADED_IMAGE_PRIVATE_DATA  *Image;\r
   EFI_TPL                    OldTpl;\r
@@ -1327,11 +1282,11 @@ Returns:
   //\r
   // Prevent possible reentrance to this function\r
   // for the same ImageHandle\r
-  // \r
-  OldTpl = CoreRaiseTpl (TPL_NOTIFY); \r
\r
+  //\r
+  OldTpl = CoreRaiseTpl (TPL_NOTIFY);\r
+\r
   Image = CoreLoadedImageInfo (ImageHandle);\r
-  if (Image == NULL_HANDLE) {\r
+  if (Image == NULL) {\r
     Status = EFI_INVALID_PARAMETER;\r
     goto Done;\r
   }\r
@@ -1349,7 +1304,7 @@ Returns:
   // Image has been started, verify this image can exit\r
   //\r
   if (Image != mCurrentImage) {\r
-    DEBUG ((EFI_D_LOAD|EFI_D_ERROR, "Exit: Image is not exitable image\n"));\r
+    DEBUG ((DEBUG_LOAD|DEBUG_ERROR, "Exit: Image is not exitable image\n"));\r
     Status = EFI_INVALID_PARAMETER;\r
     goto Done;\r
   }\r
@@ -1364,7 +1319,7 @@ Returns:
   //\r
   if (ExitData != NULL) {\r
     Image->ExitDataSize = ExitDataSize;\r
-    Image->ExitData = CoreAllocateBootServicesPool (Image->ExitDataSize);\r
+    Image->ExitData = AllocatePool (Image->ExitDataSize);\r
     if (Image->ExitData == NULL) {\r
       Status = EFI_OUT_OF_RESOURCES;\r
       goto Done;\r
@@ -1390,39 +1345,28 @@ Done:
 \r
 \r
 \r
-EFI_STATUS\r
-EFIAPI\r
-CoreUnloadImage (\r
-  IN EFI_HANDLE  ImageHandle\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
 \r
+/**\r
   Unloads an image.\r
 \r
-Arguments:\r
+  @param  ImageHandle             Handle that identifies the image to be\r
+                                  unloaded.\r
 \r
-  ImageHandle           - Handle that identifies the image to be unloaded.\r
+  @retval EFI_SUCCESS             The image has been unloaded.\r
+  @retval EFI_UNSUPPORTED         The image has been sarted, and does not support\r
+                                  unload.\r
+  @retval EFI_INVALID_PARAMPETER  ImageHandle is not a valid image handle.\r
 \r
-Returns:\r
-\r
- EFI_SUCCESS            - The image has been unloaded.\r
- EFI_UNSUPPORTED        - The image has been sarted, and does not support unload.\r
- EFI_INVALID_PARAMPETER - ImageHandle is not a valid image handle.\r
-\r
---*/\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+CoreUnloadImage (\r
+  IN EFI_HANDLE  ImageHandle\r
+  )\r
 {\r
   EFI_STATUS                 Status;\r
   LOADED_IMAGE_PRIVATE_DATA  *Image;\r
-  EFI_TPL                    OldTpl;\r
 \r
-  //\r
-  // Prevent possible reentrance to this function\r
-  // for the same ImageHandle\r
-  // \r
-  OldTpl = CoreRaiseTpl (TPL_NOTIFY);\r
\r
   Image = CoreLoadedImageInfo (ImageHandle);\r
   if (Image == NULL ) {\r
     //\r
@@ -1457,38 +1401,28 @@ Returns:
   }\r
 \r
 Done:\r
-  CoreRestoreTpl (OldTpl);\r
   return Status;\r
 }\r
 \r
 \r
+\r
+/**\r
+  Unload the specified image.\r
+\r
+  @param  This                    Indicates the calling context.\r
+  @param  ImageHandle             The specified image handle.\r
+\r
+  @retval EFI_INVALID_PARAMETER   Image handle is NULL.\r
+  @retval EFI_UNSUPPORTED         Attempt to unload an unsupported image.\r
+  @retval EFI_SUCCESS             Image successfully unloaded.\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 CoreUnloadImageEx (\r
   IN EFI_PE32_IMAGE_PROTOCOL  *This,\r
   IN EFI_HANDLE                         ImageHandle\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Unload the specified image.\r
-\r
-Arguments:\r
-\r
-  This              - Indicates the calling context.\r
-\r
-  ImageHandle       - The specified image handle.\r
-\r
-Returns:\r
-\r
-  EFI_INVALID_PARAMETER       - Image handle is NULL.\r
-\r
-  EFI_UNSUPPORTED             - Attempt to unload an unsupported image.\r
-\r
-  EFI_SUCCESS                 - Image successfully unloaded.\r
-\r
---*/\r
 {\r
   return CoreUnloadImage (ImageHandle);\r
 }\r