mirror of https://github.com/acidanthera/audk.git
Fix logic error on SectionAlignment calculation.
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
This commit is contained in:
parent
4c75d0531b
commit
81338070fe
|
@ -1115,6 +1115,7 @@ InsertImageRecord (
|
||||||
IMAGE_PROPERTIES_RECORD *ImageRecord;
|
IMAGE_PROPERTIES_RECORD *ImageRecord;
|
||||||
CHAR8 *PdbPointer;
|
CHAR8 *PdbPointer;
|
||||||
IMAGE_PROPERTIES_RECORD_CODE_SECTION *ImageRecordCodeSection;
|
IMAGE_PROPERTIES_RECORD_CODE_SECTION *ImageRecordCodeSection;
|
||||||
|
UINT16 Magic;
|
||||||
|
|
||||||
DEBUG ((EFI_D_VERBOSE, "InsertImageRecord - 0x%x\n", RuntimeImage));
|
DEBUG ((EFI_D_VERBOSE, "InsertImageRecord - 0x%x\n", RuntimeImage));
|
||||||
DEBUG ((EFI_D_VERBOSE, "InsertImageRecord - 0x%016lx - 0x%016lx\n", (EFI_PHYSICAL_ADDRESS)(UINTN)RuntimeImage->ImageBase, RuntimeImage->ImageSize));
|
DEBUG ((EFI_D_VERBOSE, "InsertImageRecord - 0x%016lx - 0x%016lx\n", (EFI_PHYSICAL_ADDRESS)(UINTN)RuntimeImage->ImageBase, RuntimeImage->ImageSize));
|
||||||
|
@ -1152,13 +1153,12 @@ InsertImageRecord (
|
||||||
Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINT8 *) (UINTN) ImageAddress + PeCoffHeaderOffset);
|
Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINT8 *) (UINTN) ImageAddress + PeCoffHeaderOffset);
|
||||||
if (Hdr.Pe32->Signature != EFI_IMAGE_NT_SIGNATURE) {
|
if (Hdr.Pe32->Signature != EFI_IMAGE_NT_SIGNATURE) {
|
||||||
DEBUG ((EFI_D_VERBOSE, "Hdr.Pe32->Signature invalid - 0x%x\n", Hdr.Pe32->Signature));
|
DEBUG ((EFI_D_VERBOSE, "Hdr.Pe32->Signature invalid - 0x%x\n", Hdr.Pe32->Signature));
|
||||||
// It might be image in SMM.
|
// It might be image in SMM.
|
||||||
goto Finish;
|
goto Finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Measuring PE/COFF Image Header;
|
// Get SectionAlignment
|
||||||
// But CheckSum field and SECURITY data directory (certificate) are excluded
|
|
||||||
//
|
//
|
||||||
if (Hdr.Pe32->FileHeader.Machine == IMAGE_FILE_MACHINE_IA64 && Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
|
if (Hdr.Pe32->FileHeader.Machine == IMAGE_FILE_MACHINE_IA64 && Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
|
||||||
//
|
//
|
||||||
|
@ -1167,11 +1167,16 @@ InsertImageRecord (
|
||||||
// Magic value in the OptionalHeader is EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC
|
// Magic value in the OptionalHeader is EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC
|
||||||
// then override the magic value to EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC
|
// then override the magic value to EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC
|
||||||
//
|
//
|
||||||
SectionAlignment = Hdr.Pe32->OptionalHeader.SectionAlignment;
|
Magic = EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC;
|
||||||
} else {
|
} else {
|
||||||
//
|
//
|
||||||
// Get the magic value from the PE/COFF Optional Header
|
// Get the magic value from the PE/COFF Optional Header
|
||||||
//
|
//
|
||||||
|
Magic = Hdr.Pe32->OptionalHeader.Magic;
|
||||||
|
}
|
||||||
|
if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
|
||||||
|
SectionAlignment = Hdr.Pe32->OptionalHeader.SectionAlignment;
|
||||||
|
} else {
|
||||||
SectionAlignment = Hdr.Pe32Plus->OptionalHeader.SectionAlignment;
|
SectionAlignment = Hdr.Pe32Plus->OptionalHeader.SectionAlignment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue