summaryrefslogtreecommitdiff
path: root/Tools/CCode/Source/PeiRebase/PeiRebaseExe.c
diff options
context:
space:
mode:
Diffstat (limited to 'Tools/CCode/Source/PeiRebase/PeiRebaseExe.c')
-rw-r--r--Tools/CCode/Source/PeiRebase/PeiRebaseExe.c36
1 files changed, 27 insertions, 9 deletions
diff --git a/Tools/CCode/Source/PeiRebase/PeiRebaseExe.c b/Tools/CCode/Source/PeiRebase/PeiRebaseExe.c
index 7519a55e48..5f7dfc25c7 100644
--- a/Tools/CCode/Source/PeiRebase/PeiRebaseExe.c
+++ b/Tools/CCode/Source/PeiRebase/PeiRebaseExe.c
@@ -545,7 +545,7 @@ Returns:
printf (" Where:\n");
printf (" InputFileName is the name of the EFI FV file to rebase.\n");
printf (" OutputFileName is the desired output file name.\n");
- printf (" BaseAddress is the FV base address to rebase agains.\n");
+ printf (" BaseAddress is the FV base address to rebase against.\n");
printf (" Argument pair may be in any order.\n\n");
}
@@ -749,14 +749,14 @@ Returns:
// Allocate a buffer for the image to be loaded into.
//
Pe32ImageSize = GetLength (CurrentPe32Section.Pe32Section->CommonHeader.Size) - sizeof (EFI_PE32_SECTION);
- MemoryImagePointer = (UINTN) (malloc (Pe32ImageSize + 0x1000));
+ MemoryImagePointer = (UINTN) (malloc (Pe32ImageSize + 0x10000));
if (MemoryImagePointer == 0) {
Error (NULL, 0, 0, "memory allocation failure", NULL);
return EFI_OUT_OF_RESOURCES;
}
- memset ((void *) MemoryImagePointer, 0, Pe32ImageSize + 0x1000);
- MemoryImagePointerAligned = (MemoryImagePointer + 0x0FFF) & (-1 << 12);
-
+ memset ((void *) MemoryImagePointer, 0, Pe32ImageSize + 0x10000);
+ MemoryImagePointerAligned = (MemoryImagePointer + 0x0FFFF) & (-1 << 16);
+
ImageContext.ImageAddress = MemoryImagePointerAligned;
@@ -766,6 +766,24 @@ Returns:
free ((VOID *) MemoryImagePointer);
return Status;
}
+
+ //
+ // Check if section-alignment and file-alignment match or not
+ //
+ if (!(ImageContext.IsTeImage)) {
+ PeHdr = (EFI_IMAGE_NT_HEADERS *)((UINTN)ImageContext.ImageAddress +
+ ImageContext.PeCoffHeaderOffset);
+ if (PeHdr->OptionalHeader.SectionAlignment != PeHdr->OptionalHeader.FileAlignment) {
+ Error (NULL, 0, 0, "Section-Alignment and File-Alignment does not match", FileGuidString);
+ free ((VOID *) MemoryImagePointer);
+ return EFI_ABORTED;
+ }
+ }
+ else {
+ //
+ // BUGBUG: TE Image Header lack section-alignment and file-alignment info
+ //
+ }
ImageContext.DestinationAddress = NewPe32BaseAddress;
Status = PeCoffLoaderRelocateImage (&ImageContext);
@@ -1060,15 +1078,15 @@ Returns:
//
// Allocate a buffer for the image to be loaded into.
//
- MemoryImagePointer = (UINTN) (malloc (Pe32ImageSize + 0x1000));
+ MemoryImagePointer = (UINTN) (malloc (Pe32ImageSize + 0x10000));
if (MemoryImagePointer == 0) {
Error (NULL, 0, 0, "memory allocation error on rebase of TE image", FileGuidString);
free (TEBuffer);
return EFI_OUT_OF_RESOURCES;
}
- memset ((void *) MemoryImagePointer, 0, Pe32ImageSize + 0x1000);
- MemoryImagePointerAligned = (MemoryImagePointer + 0x0FFF) & (-1 << 12);
-
+ memset ((void *) MemoryImagePointer, 0, Pe32ImageSize + 0x10000);
+ MemoryImagePointerAligned = (MemoryImagePointer + 0x0FFFF) & (-1 << 16);
+
ImageContext.ImageAddress = MemoryImagePointerAligned;
Status = PeCoffLoaderLoadImage (&ImageContext);