]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/BasePeCoffLib/BasePeCoff.c
OVMF: Align PE images in ROM, and strip relocations were possible.
[mirror_edk2.git] / MdePkg / Library / BasePeCoffLib / BasePeCoff.c
index fcdf0c6647c7cdcc066aa9d1142ae6a515d454ce..eeabbb24bc301abf962f4c9b9520abdf2c98604d 100644 (file)
@@ -2,7 +2,8 @@
   Base PE/COFF loader supports loading any PE32/PE32+ or TE image, but\r
   only supports relocating IA32, x64, IPF, and EBC images.\r
 \r
-  Copyright (c) 2006 - 2008, Intel Corporation\r
+  Copyright (c) 2006 - 2008, Intel Corporation<BR>\r
+  Portions copyright (c) 2008-2009 Apple Inc. All rights reserved.<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
@@ -495,6 +496,10 @@ PeCoffLoaderImageAddress (
     \r
   If ImageContext is NULL, then ASSERT().\r
 \r
+  Note that if the platform does not maintain coherency between the instruction cache(s) and the data\r
+  cache(s) in hardware, then the caller is responsible for performing cache maintenance operations\r
+  prior to transferring control to a PE/COFF image that is loaded using this library.\r
+\r
   @param  ImageContext        Pointer to the image context structure that describes the PE/COFF\r
                               image that is being relocated.\r
 \r
@@ -543,7 +548,7 @@ PeCoffLoaderRelocateImage (
   if (ImageContext->RelocationsStripped) {\r
     // Applies additional environment specific actions to relocate fixups \r
     // to a PE/COFF image if needed\r
-    PeCoffLoaderRelocateImageExtraAction (ImageContext);       \r
+    PeCoffLoaderRelocateImageExtraAction (ImageContext);  \r
     return RETURN_SUCCESS;\r
   }\r
 \r
@@ -761,6 +766,10 @@ PeCoffLoaderRelocateImage (
   \r
   If ImageContext is NULL, then ASSERT().\r
 \r
+  Note that if the platform does not maintain coherency between the instruction cache(s) and the data\r
+  cache(s) in hardware, then the caller is responsible for performing cache maintenance operations\r
+  prior to transferring control to a PE/COFF image that is loaded using this library.\r
+\r
   @param  ImageContext              Pointer to the image context structure that describes the PE/COFF\r
                                     image that is being loaded.\r
 \r
@@ -916,6 +925,14 @@ PeCoffLoaderLoadImage (
   //\r
   Section = FirstSection;\r
   for (Index = 0, MaxEnd = NULL; Index < NumberOfSections; Index++) {\r
+    //\r
+    // Read the section\r
+    //\r
+    Size = (UINTN) Section->Misc.VirtualSize;\r
+    if ((Size == 0) || (Size > Section->SizeOfRawData)) {\r
+      Size = (UINTN) Section->SizeOfRawData;\r
+    }\r
+\r
     //\r
     // Compute sections address\r
     //\r
@@ -926,9 +943,9 @@ PeCoffLoaderLoadImage (
             );\r
 \r
     //\r
-    // If the base start or end address resolved to 0, then fail.\r
+    // If the size of the section is non-zero and the base address or end address resolved to 0, then fail.\r
     //\r
-    if ((Base == NULL) || (End == NULL)) {\r
+    if ((Size > 0) && ((Base == NULL) || (End == NULL))) {\r
       ImageContext->ImageError = IMAGE_ERROR_SECTION_NOT_LOADED;\r
       return RETURN_LOAD_ERROR;\r
     }\r
@@ -942,14 +959,6 @@ PeCoffLoaderLoadImage (
       MaxEnd = End;\r
     }\r
 \r
-    //\r
-    // Read the section\r
-    //\r
-    Size = (UINTN) Section->Misc.VirtualSize;\r
-    if ((Size == 0) || (Size > Section->SizeOfRawData)) {\r
-      Size = (UINTN) Section->SizeOfRawData;\r
-    }\r
-\r
     if (Section->SizeOfRawData > 0) {\r
       if (!(ImageContext->IsTeImage)) {\r
         Status = ImageContext->ImageRead (\r
@@ -1144,6 +1153,10 @@ PeCoffLoaderLoadImage (
           ImageContext->PdbPointer = (CHAR8 *)ImageContext->CodeView + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_RSDS_ENTRY);\r
           break;\r
 \r
+        case CODEVIEW_SIGNATURE_MTOC:\r
+          ImageContext->PdbPointer = (CHAR8 *)ImageContext->CodeView + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_MTOC_ENTRY);\r
+          break;\r
+\r
         default:\r
           break;\r
         }\r
@@ -1231,6 +1244,10 @@ PeCoffLoaderLoadImage (
   to the FiuxupData buffer from the PE_COFF_LOADER_IMAGE_CONTEXT structure \r
   after this PE/COFF image was relocated with PeCoffLoaderRelocateImage().\r
 \r
+  Note that if the platform does not maintain coherency between the instruction cache(s) and the data\r
+  cache(s) in hardware, then the caller is responsible for performing cache maintenance operations\r
+  prior to transferring control to a PE/COFF image that is loaded using this library.\r
+\r
   @param  ImageBase          Base address of a PE/COFF image that has been loaded \r
                              and relocated into system memory.\r
   @param  VirtImageBase      The request virtual address that the PE/COFF image is to\r