summaryrefslogtreecommitdiff
path: root/InOsEmuPkg/Unix
diff options
context:
space:
mode:
authorjljusten <jljusten@6f19259b-4bc3-4df7-8a09-765794883524>2011-05-15 17:23:04 +0000
committerjljusten <jljusten@6f19259b-4bc3-4df7-8a09-765794883524>2011-05-15 17:23:04 +0000
commit0ede3853bcc042f4b1897a8783995d71888addbb (patch)
treea1ee70eaf499dff8fa334ea20464659046a093ff /InOsEmuPkg/Unix
parent7d6cc7101587bc80380708ba8ec1d8889df884c3 (diff)
downloadedk2-platforms-0ede3853bcc042f4b1897a8783995d71888addbb.tar.xz
InOsEmuPkg/Unix: Rebase firmware SEC image
Apply PE/COFF relocation to SEC image within the firmware volume so it will be able to run at the address that it was loaded. Signed-off-by: jljusten git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11650 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'InOsEmuPkg/Unix')
-rw-r--r--InOsEmuPkg/Unix/Sec/SecMain.c66
1 files changed, 59 insertions, 7 deletions
diff --git a/InOsEmuPkg/Unix/Sec/SecMain.c b/InOsEmuPkg/Unix/Sec/SecMain.c
index b67a9f1ca1..a1d73e8cb8 100644
--- a/InOsEmuPkg/Unix/Sec/SecMain.c
+++ b/InOsEmuPkg/Unix/Sec/SecMain.c
@@ -553,16 +553,29 @@ SecPeCoffGetEntryPoint (
{
EFI_STATUS Status;
PE_COFF_LOADER_IMAGE_CONTEXT ImageContext;
-
- ImageContext.ImageAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)Pe32Data;
- ImageContext.SizeOfHeaders = PeCoffGetSizeOfHeaders (Pe32Data);
- ImageContext.PdbPointer = PeCoffLoaderGetPdbPointer (Pe32Data);
- Status = PeCoffLoaderGetEntryPoint (Pe32Data, EntryPoint);
- if (!EFI_ERROR (Status)) {
+
+ ZeroMem (&ImageContext, sizeof (ImageContext));
+ ImageContext.Handle = Pe32Data;
+ ImageContext.ImageRead = (PE_COFF_LOADER_READ_FILE) SecImageRead;
+
+ Status = PeCoffLoaderGetImageInfo (&ImageContext);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ //
+ // Relocate image to match the address where it resides
+ //
+ ImageContext.ImageAddress = Pe32Data;
+ Status = PeCoffLoaderLoadImage (&ImageContext);
+ if (EFI_ERROR (Status)) {
return Status;
}
- ImageContext.EntryPoint = (UINTN)EntryPoint;
+ Status = PeCoffLoaderRelocateImage (&ImageContext);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
// On Unix a dlopen is done that will change the entry point
SecPeCoffRelocateImageExtraAction (&ImageContext);
@@ -655,6 +668,45 @@ CountSeperatorsInString (
}
+EFI_STATUS
+EFIAPI
+SecImageRead (
+ IN VOID *FileHandle,
+ IN UINTN FileOffset,
+ IN OUT UINTN *ReadSize,
+ OUT VOID *Buffer
+ )
+/*++
+
+Routine Description:
+ Support routine for the PE/COFF Loader that reads a buffer from a PE/COFF file
+
+Arguments:
+ FileHandle - The handle to the PE/COFF file
+ FileOffset - The offset, in bytes, into the file to read
+ ReadSize - The number of bytes to read from the file starting at FileOffset
+ Buffer - A pointer to the buffer to read the data into.
+
+Returns:
+ EFI_SUCCESS - ReadSize bytes of data were read into Buffer from the PE/COFF file starting at FileOffset
+
+**/
+{
+ CHAR8 *Destination8;
+ CHAR8 *Source8;
+ UINTN Length;
+
+ Destination8 = Buffer;
+ Source8 = (CHAR8 *) ((UINTN) FileHandle + FileOffset);
+ Length = *ReadSize;
+ while (Length--) {
+ *(Destination8++) = *(Source8++);
+ }
+
+ return EFI_SUCCESS;
+}
+
+
/*++
Routine Description: