Fix logic error on SectionAlignment calculation.
authorYao, Jiewen <Jiewen.yao@intel.com>
Wed, 10 Jun 2015 00:26:48 +0000 (00:26 +0000)
committerjyao1 <jyao1@Edk2>
Wed, 10 Jun 2015 00:26:48 +0000 (00:26 +0000)
The correct logic should be:
  - The SectionAlignment is got from Magic number.
  - The Magic number is got from PE header and machine type.
The original code mix them.

Contributed-under: TianoCore Contribution Agreement 1.0

Signed-off-by: "Yao, Jiewen" <Jiewen.yao@intel.com>
Reviewed-by: "Ard Biesheuvel" <ard.biesheuvel@linaro.org>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@17603 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Core/Dxe/Misc/PropertiesTable.c

index 813ca48..3515993 100644 (file)
@@ -1115,6 +1115,7 @@ InsertImageRecord (
   IMAGE_PROPERTIES_RECORD              *ImageRecord;\r
   CHAR8                                *PdbPointer;\r
   IMAGE_PROPERTIES_RECORD_CODE_SECTION *ImageRecordCodeSection;\r
+  UINT16                               Magic;\r
 \r
   DEBUG ((EFI_D_VERBOSE, "InsertImageRecord - 0x%x\n", RuntimeImage));\r
   DEBUG ((EFI_D_VERBOSE, "InsertImageRecord - 0x%016lx - 0x%016lx\n", (EFI_PHYSICAL_ADDRESS)(UINTN)RuntimeImage->ImageBase, RuntimeImage->ImageSize));\r
@@ -1152,13 +1153,12 @@ InsertImageRecord (
   Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINT8 *) (UINTN) ImageAddress + PeCoffHeaderOffset);\r
   if (Hdr.Pe32->Signature != EFI_IMAGE_NT_SIGNATURE) {\r
     DEBUG ((EFI_D_VERBOSE, "Hdr.Pe32->Signature invalid - 0x%x\n", Hdr.Pe32->Signature));\r
-       // It might be image in SMM.\r
+    // It might be image in SMM.\r
     goto Finish;\r
   }\r
 \r
   //\r
-  // Measuring PE/COFF Image Header;\r
-  // But CheckSum field and SECURITY data directory (certificate) are excluded\r
+  // Get SectionAlignment\r
   //\r
   if (Hdr.Pe32->FileHeader.Machine == IMAGE_FILE_MACHINE_IA64 && Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {\r
     //\r
@@ -1167,11 +1167,16 @@ InsertImageRecord (
     //       Magic value in the OptionalHeader is EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC\r
     //       then override the magic value to EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC\r
     //\r
-    SectionAlignment  = Hdr.Pe32->OptionalHeader.SectionAlignment;\r
+    Magic = EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC;\r
   } else {\r
     //\r
     // Get the magic value from the PE/COFF Optional Header\r
     //\r
+    Magic = Hdr.Pe32->OptionalHeader.Magic;\r
+  }\r
+  if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {\r
+    SectionAlignment  = Hdr.Pe32->OptionalHeader.SectionAlignment;\r
+  } else {\r
     SectionAlignment  = Hdr.Pe32Plus->OptionalHeader.SectionAlignment;\r
   }\r
 \r