diff options
author | qhuang8 <qhuang8@6f19259b-4bc3-4df7-8a09-765794883524> | 2009-03-05 09:15:30 +0000 |
---|---|---|
committer | qhuang8 <qhuang8@6f19259b-4bc3-4df7-8a09-765794883524> | 2009-03-05 09:15:30 +0000 |
commit | ffdd18bb458468e86f360b16c461dad08f099592 (patch) | |
tree | 91e3bfe4170ea8f7f987f5cde2ac297c4efd8e7d /Nt32Pkg | |
parent | 6bfc419e7070acf51caf37c2d8264b04afd5949b (diff) | |
download | edk2-platforms-ffdd18bb458468e86f360b16c461dad08f099592.tar.xz |
Remove PeRemove PeiPeCoffLoader.h and gPeiPeCoffLoaderGuid, and Add PeCoffExtraActionLib class and instances.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@7807 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'Nt32Pkg')
-rw-r--r-- | Nt32Pkg/Library/DxeNt32PeCoffExtraActionLib/DxeNt32PeCoffExtraActionLib.c | 380 | ||||
-rw-r--r-- | Nt32Pkg/Library/DxeNt32PeCoffExtraActionLib/DxeNt32PeCoffExtraActionLib.inf (renamed from Nt32Pkg/Library/DxeNt32PeCoffLib/DxeNt32PeCoffLib.inf) | 22 | ||||
-rw-r--r-- | Nt32Pkg/Library/DxeNt32PeCoffLib/DxeNt32PeCoffLib.c | 225 | ||||
-rw-r--r-- | Nt32Pkg/Library/PeiCoreNt32PeCoffLib/PeiCoreNt32PeCoffLib.c | 262 | ||||
-rw-r--r-- | Nt32Pkg/Library/PeiCoreNt32PeCoffLib/PeiCoreNt32PeCoffLib.inf | 49 | ||||
-rw-r--r-- | Nt32Pkg/Library/PeiNt32PeCoffExtraActionLib/PeiNt32PeCoffExtraActionLib.c | 251 | ||||
-rw-r--r-- | Nt32Pkg/Library/PeiNt32PeCoffExtraActionLib/PeiNt32PeCoffExtraActionLib.inf (renamed from Nt32Pkg/Library/PeiNt32PeCoffLib/PeiNt32PeCoffLib.inf) | 23 | ||||
-rw-r--r-- | Nt32Pkg/Library/PeiNt32PeCoffLib/PeiNt32PeCoffLib.c | 255 | ||||
-rw-r--r-- | Nt32Pkg/Nt32Pkg.dsc | 10 | ||||
-rw-r--r-- | Nt32Pkg/Sec/SecMain.c | 188 | ||||
-rw-r--r-- | Nt32Pkg/Sec/SecMain.h | 33 | ||||
-rw-r--r-- | Nt32Pkg/Sec/SecMain.inf | 3 |
12 files changed, 668 insertions, 1033 deletions
diff --git a/Nt32Pkg/Library/DxeNt32PeCoffExtraActionLib/DxeNt32PeCoffExtraActionLib.c b/Nt32Pkg/Library/DxeNt32PeCoffExtraActionLib/DxeNt32PeCoffExtraActionLib.c new file mode 100644 index 0000000000..24284ba0e1 --- /dev/null +++ b/Nt32Pkg/Library/DxeNt32PeCoffExtraActionLib/DxeNt32PeCoffExtraActionLib.c @@ -0,0 +1,380 @@ +/**@file
+
+Copyright (c) 2006, Intel Corporation
+All rights reserved. This program and the accompanying materials
+are licensed and made available under the terms and conditions of the BSD License
+which accompanies this distribution. The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+Module Name:
+
+ PeiNt32PeCoffExtraActionLib.c
+
+Abstract:
+
+ Provides services to perform additional actions to relocate and unload
+ PE/Coff image for NT32 environment specific purpose such as souce level debug.
+ This version only works for DXE phase
+
+
+**/
+//
+// The package level header files this module uses
+//
+#include <FrameworkDxe.h>
+#include <FrameworkModuleDxe.h>
+#include <WinNtDxe.h>
+
+//
+// The protocols, PPI and GUID defintions for this module
+//
+#include <Protocol/WinNtThunk.h>
+
+#include <Library/PeCoffLib.h>
+#include <Library/PeiServicesLib.h>
+
+#include <Library/BaseLib.h>
+#include <Library/DebugLib.h>
+#include <Library/HobLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/PeCoffExtraActionLib.h>
+
+#define MAX_PDB_NAME_TO_MOD_HANDLE_ARRAY_SIZE 0x100
+
+typedef struct {
+ CHAR8 *PdbPointer;
+ VOID *ModHandle;
+} PDB_NAME_TO_MOD_HANDLE;
+
+
+//
+// Cache of WinNtThunk protocol
+//
+EFI_WIN_NT_THUNK_PROTOCOL *mWinNt = NULL;
+
+//
+// An Array to hold the ModHandle
+//
+PDB_NAME_TO_MOD_HANDLE *mPdbNameModHandleArray = NULL;
+UINTN mPdbNameModHandleArraySize = 0;
+
+
+/**
+ The constructor function gets the pointer of the WinNT thunk functions
+ It will ASSERT() if NT thunk protocol is not installed.
+
+ @retval EFI_SUCCESS WinNT thunk protocol is found and cached.
+
+**/
+EFI_STATUS
+EFIAPI
+DxeNt32PeCoffLibExtraActionConstructor (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ EFI_HOB_GUID_TYPE *GuidHob;
+
+ //
+ // Retrieve WinNtThunkProtocol from GUID'ed HOB
+ //
+ GuidHob = GetFirstGuidHob (&gEfiWinNtThunkProtocolGuid);
+ ASSERT (GuidHob != NULL);
+ mWinNt = (EFI_WIN_NT_THUNK_PROTOCOL *)(*(UINTN *)(GET_GUID_HOB_DATA (GuidHob)));
+ ASSERT (mWinNt != NULL);
+
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Convert the passed in Ascii string to Unicode.
+
+ This function Convert the passed in Ascii string to Unicode.Optionally return
+ the length of the strings..
+
+ @param AsciiString Pointer to an AscII string
+ @param StrLen Length of string
+
+ @return Pointer to malloc'ed Unicode version of Ascii
+
+**/
+CHAR16 *
+AsciiToUnicode (
+ IN CHAR8 *Ascii,
+ IN UINTN *StrLen OPTIONAL
+ )
+{
+ UINTN Index;
+ CHAR16 *Unicode;
+
+ //
+ // Allocate a buffer for unicode string
+ //
+ for (Index = 0; Ascii[Index] != '\0'; Index++)
+ ;
+ Unicode = mWinNt->HeapAlloc ( mWinNt->GetProcessHeap (),
+ HEAP_ZERO_MEMORY,
+ ((Index + 1) * sizeof (CHAR16))
+ );
+ if (Unicode == NULL) {
+ return NULL;
+ }
+
+ for (Index = 0; Ascii[Index] != '\0'; Index++) {
+ Unicode[Index] = (CHAR16) Ascii[Index];
+ }
+
+ Unicode[Index] = '\0';
+
+ if (StrLen != NULL) {
+ *StrLen = Index;
+ }
+
+ return Unicode;
+}
+/**
+ Store the ModHandle in an array indexed by the Pdb File name.
+ The ModHandle is needed to unload the image.
+
+
+ @param ImageContext - Input data returned from PE Laoder Library. Used to find the
+ .PDB file name of the PE Image.
+ @param ModHandle - Returned from LoadLibraryEx() and stored for call to
+ FreeLibrary().
+
+ @return return EFI_SUCCESS when ModHandle was stored.
+
+--*/
+EFI_STATUS
+AddModHandle (
+ IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext,
+ IN VOID *ModHandle
+ )
+
+{
+ UINTN Index;
+ PDB_NAME_TO_MOD_HANDLE *Array;
+ UINTN PreviousSize;
+ PDB_NAME_TO_MOD_HANDLE *TempArray;
+
+ Array = mPdbNameModHandleArray;
+ for (Index = 0; Index < mPdbNameModHandleArraySize; Index++, Array++) {
+ if (Array->PdbPointer == NULL) {
+ //
+ // Make a copy of the stirng and store the ModHandle
+ //
+ Array->PdbPointer = mWinNt->HeapAlloc ( mWinNt->GetProcessHeap (),
+ HEAP_ZERO_MEMORY,
+ AsciiStrLen (ImageContext->PdbPointer) + 1
+ );
+
+ ASSERT (Array->PdbPointer != NULL);
+
+ AsciiStrCpy (Array->PdbPointer, ImageContext->PdbPointer);
+ Array->ModHandle = ModHandle;
+ return EFI_SUCCESS;
+ }
+ }
+
+ //
+ // No free space in mPdbNameModHandleArray so grow it by
+ // MAX_PDB_NAME_TO_MOD_HANDLE_ARRAY_SIZE entires.
+ //
+ PreviousSize = mPdbNameModHandleArraySize * sizeof (PDB_NAME_TO_MOD_HANDLE);
+ mPdbNameModHandleArraySize += MAX_PDB_NAME_TO_MOD_HANDLE_ARRAY_SIZE;
+ //
+ // re-allocate a new buffer and copy the old values to the new locaiton.
+ //
+ TempArray = mWinNt->HeapAlloc ( mWinNt->GetProcessHeap (),
+ HEAP_ZERO_MEMORY,
+ mPdbNameModHandleArraySize * sizeof (PDB_NAME_TO_MOD_HANDLE)
+ );
+
+ CopyMem ((VOID *) (UINTN) TempArray, (VOID *) (UINTN)mPdbNameModHandleArray, PreviousSize);
+
+ mWinNt->HeapFree (mWinNt->GetProcessHeap (), 0, mPdbNameModHandleArray);
+
+ mPdbNameModHandleArray = TempArray;
+ if (mPdbNameModHandleArray == NULL) {
+ ASSERT (FALSE);
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+
+ return AddModHandle (ImageContext, ModHandle);
+}
+/**
+ Return the ModHandle and delete the entry in the array.
+
+
+ @param ImageContext - Input data returned from PE Laoder Library. Used to find the
+ .PDB file name of the PE Image.
+
+ @return
+ ModHandle - ModHandle assoicated with ImageContext is returned
+ NULL - No ModHandle associated with ImageContext
+
+**/
+VOID *
+RemoveModeHandle (
+ IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
+ )
+{
+ UINTN Index;
+ PDB_NAME_TO_MOD_HANDLE *Array;
+
+ if (ImageContext->PdbPointer == NULL) {
+ //
+ // If no PDB pointer there is no ModHandle so return NULL
+ //
+ return NULL;
+ }
+
+ Array = mPdbNameModHandleArray;
+ for (Index = 0; Index < mPdbNameModHandleArraySize; Index++, Array++) {
+ if ((Array->PdbPointer != NULL) && (AsciiStrCmp(Array->PdbPointer, ImageContext->PdbPointer) == 0)) {
+ //
+ // If you find a match return it and delete the entry
+ //
+ mWinNt->HeapFree (mWinNt->GetProcessHeap (), 0, Array->PdbPointer);
+ Array->PdbPointer = NULL;
+ return Array->ModHandle;
+ }
+ }
+
+ return NULL;
+}
+
+/**
+ Applies additional actions to relocate fixups to a PE/COFF image.
+
+ Generally this function is called after sucessfully Applying relocation fixups
+ to a PE/COFF image for some specicial purpose.
+ As a example, For NT32 emulator, the function should be implemented and called
+ to support source level debug.
+
+ @param ImageContext Pointer to the image context structure that describes the PE/COFF
+ image that is being relocated.
+
+**/
+VOID
+EFIAPI
+PeCoffLoaderRelocateImageExtraAction (
+ IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
+ )
+{
+ VOID *DllEntryPoint;
+ CHAR16 *DllFileName;
+ HMODULE Library;
+ UINTN Index;
+
+ //
+ // If we load our own PE COFF images the Windows debugger can not source
+ // level debug our code. If a valid PDB pointer exists usw it to load
+ // the *.dll file as a library using Windows* APIs. This allows
+ // source level debug. The image is still loaded and reloaced
+ // in the Framework memory space like on a real system (by the code above),
+ // but the entry point points into the DLL loaded by the code bellow.
+ //
+
+ DllEntryPoint = NULL;
+
+ //
+ // Load the DLL if it's not an EBC image.
+ //
+ if ((ImageContext->PdbPointer != NULL) &&
+ (ImageContext->Machine != EFI_IMAGE_MACHINE_EBC)) {
+ //
+ // Convert filename from ASCII to Unicode
+ //
+ DllFileName = AsciiToUnicode (ImageContext->PdbPointer, &Index);
+
+ //
+ // Check that we have a valid filename
+ //
+ if (Index < 5 || DllFileName[Index - 4] != '.') {
+ mWinNt->HeapFree (mWinNt->GetProcessHeap (), 0, DllFileName);
+
+ //
+ // Never return an error if PeCoffLoaderRelocateImage() succeeded.
+ // The image will run, but we just can't source level debug. If we
+ // return an error the image will not run.
+ //
+ return;
+ }
+ //
+ // Replace .PDB with .DLL on the filename
+ //
+ DllFileName[Index - 3] = 'D';
+ DllFileName[Index - 2] = 'L';
+ DllFileName[Index - 1] = 'L';
+
+ //
+ // Load the .DLL file into the user process's address space for source
+ // level debug
+ //
+ Library = mWinNt->LoadLibraryEx (DllFileName, NULL, DONT_RESOLVE_DLL_REFERENCES);
+ if (Library != NULL) {
+ //
+ // InitializeDriver is the entry point we put in all our EFI DLL's. The
+ // DONT_RESOLVE_DLL_REFERENCES argument to LoadLIbraryEx() supresses the
+ // normal DLL entry point of DllMain, and prevents other modules that are
+ // referenced in side the DllFileName from being loaded. There is no error
+ // checking as the we can point to the PE32 image loaded by Tiano. This
+ // step is only needed for source level debuging
+ //
+ DllEntryPoint = (VOID *) (UINTN) mWinNt->GetProcAddress (Library, "InitializeDriver");
+
+ }
+
+ if ((Library != NULL) && (DllEntryPoint != NULL)) {
+ AddModHandle (ImageContext, Library);
+ ImageContext->EntryPoint = (EFI_PHYSICAL_ADDRESS) (UINTN) DllEntryPoint;
+ DEBUG ((EFI_D_INFO, "LoadLibraryEx (%s,\n NULL, DONT_RESOLVE_DLL_REFERENCES)\n", DllFileName));
+ } else {
+ DEBUG ((EFI_D_ERROR, "WARNING: No source level debug %s. \n", DllFileName));
+ }
+
+ mWinNt->HeapFree (mWinNt->GetProcessHeap (), 0, DllFileName);
+ }
+
+ //
+ // Never return an error if PeCoffLoaderRelocateImage() succeeded.
+ // The image will run, but we just can't source level debug. If we
+ // return an error the image will not run.
+ //
+ return;
+}
+
+/**
+ Unloads a loaded PE/COFF image from memory and releases its taken resource.
+
+ Releases any environment specific resources that were allocated when the image
+ specified by ImageContext was loaded using PeCoffLoaderLoadImage().
+ For NT32 emulator, the PE/COFF image loaded by system needs to release.
+ For real platform, the PE/COFF image loaded by Core doesn't needs to be unloaded,
+
+ If ImageContext is NULL, then ASSERT().
+
+ @param ImageContext Pointer to the image context structure that describes the PE/COFF
+ image to be unloaded.
+
+**/
+VOID
+EFIAPI
+PeCoffLoaderUnloadImageExtraAction (
+ IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
+ )
+{
+ VOID *ModHandle;
+
+ ModHandle = RemoveModeHandle (ImageContext);
+ if (ModHandle != NULL) {
+ mWinNt->FreeLibrary (ModHandle);
+ }
+ return;
+}
\ No newline at end of file diff --git a/Nt32Pkg/Library/DxeNt32PeCoffLib/DxeNt32PeCoffLib.inf b/Nt32Pkg/Library/DxeNt32PeCoffExtraActionLib/DxeNt32PeCoffExtraActionLib.inf index 185e30ef0c..cd0d8b32bf 100644 --- a/Nt32Pkg/Library/DxeNt32PeCoffLib/DxeNt32PeCoffLib.inf +++ b/Nt32Pkg/Library/DxeNt32PeCoffExtraActionLib/DxeNt32PeCoffExtraActionLib.inf @@ -1,5 +1,5 @@ #/** @file
-# PeCoff libary for Dxe modules that run NT32 emulator.
+# PeCoff extra action libary for DXE phase that run NT32 emulator.
#
# Lib to provide memory journal status code reporting Routines
# Copyright (c) 2007, Intel Corporation
@@ -17,15 +17,15 @@ [Defines]
INF_VERSION = 0x00010005
- BASE_NAME = DxeNt32PeCoffLib
- FILE_GUID = 624571b0-4b69-40e3-bd13-78fae0e84270
+ BASE_NAME = DxeNt32PeCoffExtraActionLib
+ FILE_GUID = 23AF9A54-3D7C-444d-8318-E9CF752DA349
MODULE_TYPE = DXE_DRIVER
VERSION_STRING = 1.0
- LIBRARY_CLASS = PeCoffLib|DXE_CORE DXE_DRIVER
+ LIBRARY_CLASS = PeCoffExtraActionLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER UEFI_DRIVER
EDK_RELEASE_VERSION = 0x00020000
EFI_SPECIFICATION_VERSION = 0x00020000
- CONSTRUCTOR = DxeNt32PeCoffLibConstructor
+ CONSTRUCTOR = DxeNt32PeCoffLibExtraActionConstructor
#
# The following information is for reference only and not required by the build tools.
@@ -34,17 +34,19 @@ #
[Sources.common]
- DxeNt32PeCoffLib.c
+ DxeNt32PeCoffExtraActionLib.c
[Packages]
- MdePkg/MdePkg.dec
- MdeModulePkg/MdeModulePkg.dec
Nt32Pkg/Nt32Pkg.dec
+ MdePkg/MdePkg.dec
+ IntelFrameworkPkg/IntelFrameworkPkg.dec
+ IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec
[LibraryClasses]
DebugLib
HobLib
+ BaseMemoryLib
-[Guids]
- gEfiPeiPeCoffLoaderGuid # ALWAYS_CONSUMED
+[Protocols]
+ gEfiWinNtThunkProtocolGuid # ALWAYS_CONSUMED
diff --git a/Nt32Pkg/Library/DxeNt32PeCoffLib/DxeNt32PeCoffLib.c b/Nt32Pkg/Library/DxeNt32PeCoffLib/DxeNt32PeCoffLib.c deleted file mode 100644 index d8eb7c9436..0000000000 --- a/Nt32Pkg/Library/DxeNt32PeCoffLib/DxeNt32PeCoffLib.c +++ /dev/null @@ -1,225 +0,0 @@ -/**@file
-
-Copyright (c) 2006, Intel Corporation
-All rights reserved. This program and the accompanying materials
-are licensed and made available under the terms and conditions of the BSD License
-which accompanies this distribution. The full text of the license may be found at
-http://opensource.org/licenses/bsd-license.php
-
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-
-Module Name:
-
- DxeNt32PeCoffLib.c
-
-Abstract:
-
- Wrap the Nt32 PE/COFF loader with the PE COFF LOADER guid structure
- to produce PeCoff library class.
-
-
-**/
-
-#include <PiDxe.h>
-#include <Guid/PeiPeCoffLoader.h>
-#include <Library/DebugLib.h>
-#include <Library/PeCoffLib.h>
-#include <Library/HobLib.h>
-
-EFI_PEI_PE_COFF_LOADER_PROTOCOL *mPeiEfiPeiPeCoffLoader;
-
-/**
- The constructor function gets the pointer to PeCofferLoader guid structure
- from the guid data hob.
-
- It will ASSERT() if the guid hob of PeCofferLoader guid structure doesn't exist.
-
- @param ImageHandle The firmware allocated handle for the EFI image.
- @param SystemTable A pointer to the EFI System Table.
-
- @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
-
-**/
-EFI_STATUS
-EFIAPI
-DxeNt32PeCoffLibConstructor (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
- )
-{
- EFI_HOB_GUID_TYPE *GuidHob;
-
- //
- // Find guid data hob that contains PeCoffLoader guid structure.
- //
- GuidHob = GetFirstGuidHob (&gEfiPeiPeCoffLoaderGuid);
- ASSERT (GuidHob != NULL);
-
- //
- // Get PeCofferLoader guid structure from guid hob data.
- //
- mPeiEfiPeiPeCoffLoader = (EFI_PEI_PE_COFF_LOADER_PROTOCOL *)(*(UINTN *)(GET_GUID_HOB_DATA (GuidHob)));
-
- return EFI_SUCCESS;
-}
-
-/**
- Retrieves information about a PE/COFF image.
-
- Computes the PeCoffHeaderOffset, ImageAddress, ImageSize, DestinationAddress, CodeView,
- PdbPointer, RelocationsStripped, SectionAlignment, SizeOfHeaders, and DebugDirectoryEntryRva
- fields of the ImageContext structure. If ImageContext is NULL, then return RETURN_INVALID_PARAMETER.
- If the PE/COFF image accessed through the ImageRead service in the ImageContext structure is not
- a supported PE/COFF image type, then return RETURN_UNSUPPORTED. If any errors occur while
- computing the fields of ImageContext, then the error status is returned in the ImageError field of
- ImageContext.
-
- @param ImageContext Pointer to the image context structure that describes the PE/COFF
- image that needs to be examined by this function.
-
- @retval RETURN_SUCCESS The information on the PE/COFF image was collected.
- @retval RETURN_INVALID_PARAMETER ImageContext is NULL.
- @retval RETURN_UNSUPPORTED The PE/COFF image is not supported.
-
-**/
-RETURN_STATUS
-EFIAPI
-PeCoffLoaderGetImageInfo (
- IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
- )
-{
- return mPeiEfiPeiPeCoffLoader->GetImageInfo (mPeiEfiPeiPeCoffLoader, ImageContext);
-}
-
-/**
- Applies relocation fixups to a PE/COFF image that was loaded with PeCoffLoaderLoadImage().
-
- If the DestinationAddress field of ImageContext is 0, then use the ImageAddress field of
- ImageContext as the relocation base address. Otherwise, use the DestinationAddress field
- of ImageContext as the relocation base address. The caller must allocate the relocation
- fixup log buffer and fill in the FixupData field of ImageContext prior to calling this function.
- If ImageContext is NULL, then ASSERT().
-
- @param ImageContext Pointer to the image context structure that describes the PE/COFF
- image that is being relocated.
-
- @retval RETURN_SUCCESS The PE/COFF image was relocated.
- Extended status information is in the ImageError field of ImageContext.
- @retval RETURN_LOAD_ERROR The image in not a valid PE/COFF image.
- Extended status information is in the ImageError field of ImageContext.
- @retval RETURN_UNSUPPORTED A relocation record type is not supported.
- Extended status information is in the ImageError field of ImageContext.
-
-**/
-RETURN_STATUS
-EFIAPI
-PeCoffLoaderRelocateImage (
- IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
- )
-{
- return mPeiEfiPeiPeCoffLoader->RelocateImage (mPeiEfiPeiPeCoffLoader, ImageContext);
-}
-
-/**
- Loads a PE/COFF image into memory.
-
- Loads the PE/COFF image accessed through the ImageRead service of ImageContext into the buffer
- specified by the ImageAddress and ImageSize fields of ImageContext. The caller must allocate
- the load buffer and fill in the ImageAddress and ImageSize fields prior to calling this function.
- The EntryPoint, FixupDataSize, CodeView, and PdbPointer fields of ImageContext are computed.
- If ImageContext is NULL, then ASSERT().
-
- @param ImageContext Pointer to the image context structure that describes the PE/COFF
- image that is being loaded.
-
- @retval RETURN_SUCCESS The PE/COFF image was loaded into the buffer specified by
- the ImageAddress and ImageSize fields of ImageContext.
- Extended status information is in the ImageError field of ImageContext.
- @retval RETURN_BUFFER_TOO_SMALL The caller did not provide a large enough buffer.
- Extended status information is in the ImageError field of ImageContext.
- @retval RETURN_LOAD_ERROR The PE/COFF image is an EFI Runtime image with no relocations.
- Extended status information is in the ImageError field of ImageContext.
- @retval RETURN_INVALID_PARAMETER The image address is invalid.
- Extended status information is in the ImageError field of ImageContext.
-
-**/
-RETURN_STATUS
-EFIAPI
-PeCoffLoaderLoadImage (
- IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
- )
-{
- return mPeiEfiPeiPeCoffLoader->LoadImage (mPeiEfiPeiPeCoffLoader, ImageContext);
-}
-
-/**
- ImageRead function that operates on a memory buffer whos base is passed into
- FileHandle.
-
- @param FileHandle Ponter to baes of the input stream
- @param FileOffset Offset to the start of the buffer
- @param ReadSize Number of bytes to copy into the buffer
- @param Buffer Location to place results of read
-
- @retval RETURN_SUCCESS Data is read from FileOffset from the Handle into
- the buffer.
-**/
-RETURN_STATUS
-EFIAPI
-PeCoffLoaderImageReadFromMemory (
- IN VOID *FileHandle,
- IN UINTN FileOffset,
- IN OUT UINTN *ReadSize,
- OUT VOID *Buffer
- )
-{
- return RETURN_UNSUPPORTED;
-}
-
-
-/**
- Reapply fixups on a fixed up PE32/PE32+ image to allow virutal calling at EFI
- runtime.
-
- PE_COFF_LOADER_IMAGE_CONTEXT.FixupData stores information needed to reapply
- the fixups with a virtual mapping.
-
-
- @param ImageBase Base address of relocated image
- @param VirtImageBase Virtual mapping for ImageBase
- @param ImageSize Size of the image to relocate
- @param RelocationData Location to place results of read
-
-**/
-VOID
-EFIAPI
-PeCoffLoaderRelocateImageForRuntime (
- IN PHYSICAL_ADDRESS ImageBase,
- IN PHYSICAL_ADDRESS VirtImageBase,
- IN UINTN ImageSize,
- IN VOID *RelocationData
- )
-{
-}
-
-/**
- Unloads a loaded PE/COFF image from memory and releases its taken resource.
-
- For NT32 emulator, the PE/COFF image loaded by system needs to release.
- For real platform, the PE/COFF image loaded by Core doesn't needs to be unloaded,
- this function can simply return RETURN_SUCCESS.
-
- @param ImageContext Pointer to the image context structure that describes the PE/COFF
- image to be unloaded.
-
- @retval RETURN_SUCCESS The PE/COFF image was unloaded successfully.
-**/
-RETURN_STATUS
-EFIAPI
-PeCoffLoaderUnloadImage (
- IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
- )
-{
- return mPeiEfiPeiPeCoffLoader->UnloadImage (mPeiEfiPeiPeCoffLoader, ImageContext);
-}
diff --git a/Nt32Pkg/Library/PeiCoreNt32PeCoffLib/PeiCoreNt32PeCoffLib.c b/Nt32Pkg/Library/PeiCoreNt32PeCoffLib/PeiCoreNt32PeCoffLib.c deleted file mode 100644 index ea1276fec9..0000000000 --- a/Nt32Pkg/Library/PeiCoreNt32PeCoffLib/PeiCoreNt32PeCoffLib.c +++ /dev/null @@ -1,262 +0,0 @@ -/**@file
-
-Copyright (c) 2006, Intel Corporation
-All rights reserved. This program and the accompanying materials
-are licensed and made available under the terms and conditions of the BSD License
-which accompanies this distribution. The full text of the license may be found at
-http://opensource.org/licenses/bsd-license.php
-
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-
-Module Name:
-
- PeiCoreNt32PeCoffLib.c
-
-Abstract:
-
- Wrap the Nt32 PE/COFF loader with the PE COFF LOADER guid structure
- to produce PeCoff library class.
-
-
-**/
-
-#include <PiPei.h>
-#include <Guid/PeiPeCoffLoader.h>
-#include <Library/DebugLib.h>
-#include <Library/PeCoffLib.h>
-#include <Library/HobLib.h>
-#include <Library/PeiServicesLib.h>
-
-EFI_PEI_PE_COFF_LOADER_PROTOCOL *mPeiEfiPeiPeCoffLoader = NULL;
-
-/**
- The function caches the pointer of PeCofferLoader guid structure
- into the guid data hob.
-
- The funtion must be called after PeCofferLoader guid structure is installed.
- It will ASSERT() if PeCofferLoader guid structure is not installed.
-
- @retval EFI_SUCCESS PeCofferLoader guid structure is found.
-
-**/
-EFI_STATUS
-EFIAPI
-GetPeCoffLoaderStucture (
- )
-{
- EFI_STATUS Status;
- EFI_HOB_GUID_TYPE *GuidHob;
-
- Status = EFI_NOT_FOUND;
-
- //
- // Try to get guid data hob that contains PeCoffLoader guid structure.
- //
- GuidHob = GetFirstGuidHob (&gEfiPeiPeCoffLoaderGuid);
-
- if (GuidHob == NULL) {
- //
- // GuidHob is not ready, try to locate PeCoffLoader guid structure.
- //
- Status = PeiServicesLocatePpi (
- &gEfiPeiPeCoffLoaderGuid,
- 0,
- NULL,
- (VOID**)&mPeiEfiPeiPeCoffLoader
- );
-
- //
- // PeCofferLoader guid structure must be installed before this library runs.
- //
- ASSERT_EFI_ERROR (Status);
-
- //
- // Build guid data hob of PeCofferLoader guid structure for DXE module use.
- //
- BuildGuidDataHob (
- &gEfiPeiPeCoffLoaderGuid,
- (VOID *) &mPeiEfiPeiPeCoffLoader,
- sizeof (VOID *)
- );
- } else {
- //
- // Get PeCofferLoader guid structure directly from guid hob data.
- //
- mPeiEfiPeiPeCoffLoader = (EFI_PEI_PE_COFF_LOADER_PROTOCOL *)(*(UINTN *)(GET_GUID_HOB_DATA (GuidHob)));
- }
-
- return EFI_SUCCESS;
-}
-
-/**
- Retrieves information about a PE/COFF image.
-
- Computes the PeCoffHeaderOffset, ImageAddress, ImageSize, DestinationAddress, CodeView,
- PdbPointer, RelocationsStripped, SectionAlignment, SizeOfHeaders, and DebugDirectoryEntryRva
- fields of the ImageContext structure. If ImageContext is NULL, then return RETURN_INVALID_PARAMETER.
- If the PE/COFF image accessed through the ImageRead service in the ImageContext structure is not
- a supported PE/COFF image type, then return RETURN_UNSUPPORTED. If any errors occur while
- computing the fields of ImageContext, then the error status is returned in the ImageError field of
- ImageContext.
-
- @param ImageContext Pointer to the image context structure that describes the PE/COFF
- image that needs to be examined by this function.
-
- @retval RETURN_SUCCESS The information on the PE/COFF image was collected.
- @retval RETURN_INVALID_PARAMETER ImageContext is NULL.
- @retval RETURN_UNSUPPORTED The PE/COFF image is not supported.
-
-**/
-RETURN_STATUS
-EFIAPI
-PeCoffLoaderGetImageInfo (
- IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
- )
-{
- if (mPeiEfiPeiPeCoffLoader == NULL) {
- GetPeCoffLoaderStucture ();
- }
- return mPeiEfiPeiPeCoffLoader->GetImageInfo (mPeiEfiPeiPeCoffLoader, ImageContext);
-}
-
-/**
- Applies relocation fixups to a PE/COFF image that was loaded with PeCoffLoaderLoadImage().
-
- If the DestinationAddress field of ImageContext is 0, then use the ImageAddress field of
- ImageContext as the relocation base address. Otherwise, use the DestinationAddress field
- of ImageContext as the relocation base address. The caller must allocate the relocation
- fixup log buffer and fill in the FixupData field of ImageContext prior to calling this function.
- If ImageContext is NULL, then ASSERT().
-
- @param ImageContext Pointer to the image context structure that describes the PE/COFF
- image that is being relocated.
-
- @retval RETURN_SUCCESS The PE/COFF image was relocated.
- Extended status information is in the ImageError field of ImageContext.
- @retval RETURN_LOAD_ERROR The image in not a valid PE/COFF image.
- Extended status information is in the ImageError field of ImageContext.
- @retval RETURN_UNSUPPORTED A relocation record type is not supported.
- Extended status information is in the ImageError field of ImageContext.
-
-**/
-RETURN_STATUS
-EFIAPI
-PeCoffLoaderRelocateImage (
- IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
- )
-{
- if (mPeiEfiPeiPeCoffLoader == NULL) {
- GetPeCoffLoaderStucture ();
- }
- return mPeiEfiPeiPeCoffLoader->RelocateImage (mPeiEfiPeiPeCoffLoader, ImageContext);
-}
-
-/**
- Loads a PE/COFF image into memory.
-
- Loads the PE/COFF image accessed through the ImageRead service of ImageContext into the buffer
- specified by the ImageAddress and ImageSize fields of ImageContext. The caller must allocate
- the load buffer and fill in the ImageAddress and ImageSize fields prior to calling this function.
- The EntryPoint, FixupDataSize, CodeView, and PdbPointer fields of ImageContext are computed.
- If ImageContext is NULL, then ASSERT().
-
- @param ImageContext Pointer to the image context structure that describes the PE/COFF
- image that is being loaded.
-
- @retval RETURN_SUCCESS The PE/COFF image was loaded into the buffer specified by
- the ImageAddress and ImageSize fields of ImageContext.
- Extended status information is in the ImageError field of ImageContext.
- @retval RETURN_BUFFER_TOO_SMALL The caller did not provide a large enough buffer.
- Extended status information is in the ImageError field of ImageContext.
- @retval RETURN_LOAD_ERROR The PE/COFF image is an EFI Runtime image with no relocations.
- Extended status information is in the ImageError field of ImageContext.
- @retval RETURN_INVALID_PARAMETER The image address is invalid.
- Extended status information is in the ImageError field of ImageContext.
-
-**/
-RETURN_STATUS
-EFIAPI
-PeCoffLoaderLoadImage (
- IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
- )
-{
- if (mPeiEfiPeiPeCoffLoader == NULL) {
- GetPeCoffLoaderStucture ();
- }
- return mPeiEfiPeiPeCoffLoader->LoadImage (mPeiEfiPeiPeCoffLoader, ImageContext);
-}
-
-/**
- ImageRead function that operates on a memory buffer whos base is passed into
- FileHandle.
-
- @param FileHandle Ponter to baes of the input stream
- @param FileOffset Offset to the start of the buffer
- @param ReadSize Number of bytes to copy into the buffer
- @param Buffer Location to place results of read
-
- @retval RETURN_SUCCESS Data is read from FileOffset from the Handle into
- the buffer.
-**/
-RETURN_STATUS
-EFIAPI
-PeCoffLoaderImageReadFromMemory (
- IN VOID *FileHandle,
- IN UINTN FileOffset,
- IN OUT UINTN *ReadSize,
- OUT VOID *Buffer
- )
-{
- return RETURN_UNSUPPORTED;
-}
-
-
-/**
- Reapply fixups on a fixed up PE32/PE32+ image to allow virutal calling at EFI
- runtime.
-
- PE_COFF_LOADER_IMAGE_CONTEXT.FixupData stores information needed to reapply
- the fixups with a virtual mapping.
-
-
- @param ImageBase Base address of relocated image
- @param VirtImageBase Virtual mapping for ImageBase
- @param ImageSize Size of the image to relocate
- @param RelocationData Location to place results of read
-
-**/
-VOID
-EFIAPI
-PeCoffLoaderRelocateImageForRuntime (
- IN PHYSICAL_ADDRESS ImageBase,
- IN PHYSICAL_ADDRESS VirtImageBase,
- IN UINTN ImageSize,
- IN VOID *RelocationData
- )
-{
-}
-
-/**
- Unloads a loaded PE/COFF image from memory and releases its taken resource.
-
- For NT32 emulator, the PE/COFF image loaded by system needs to release.
- For real platform, the PE/COFF image loaded by Core doesn't needs to be unloaded,
- this function can simply return RETURN_SUCCESS.
-
- @param ImageContext Pointer to the image context structure that describes the PE/COFF
- image to be unloaded.
-
- @retval RETURN_SUCCESS The PE/COFF image was unloaded successfully.
-**/
-RETURN_STATUS
-EFIAPI
-PeCoffLoaderUnloadImage (
- IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
- )
-{
- if (mPeiEfiPeiPeCoffLoader == NULL) {
- GetPeCoffLoaderStucture ();
- }
- return mPeiEfiPeiPeCoffLoader->UnloadImage (mPeiEfiPeiPeCoffLoader, ImageContext);
-}
diff --git a/Nt32Pkg/Library/PeiCoreNt32PeCoffLib/PeiCoreNt32PeCoffLib.inf b/Nt32Pkg/Library/PeiCoreNt32PeCoffLib/PeiCoreNt32PeCoffLib.inf deleted file mode 100644 index cf69e4428e..0000000000 --- a/Nt32Pkg/Library/PeiCoreNt32PeCoffLib/PeiCoreNt32PeCoffLib.inf +++ /dev/null @@ -1,49 +0,0 @@ -#/** @file
-# PeCoff libary for PeiCore modules that run NT32 emulator.
-#
-# Lib to provide memory journal status code reporting Routines
-# Copyright (c) 2007, Intel Corporation
-# All rights reserved. This program and the accompanying materials
-# are licensed and made available under the terms and conditions of the BSD License
-# which accompanies this distribution. The full text of the license may be found at
-# http://opensource.org/licenses/bsd-license.php
-#
-# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-
-#
-#
-#**/
-
-[Defines]
- INF_VERSION = 0x00010005
- BASE_NAME = PeiCoreNt32PeCoffLib
- FILE_GUID = ef9fd7ee-3181-4b16-adc1-8615f88b58b8
- MODULE_TYPE = PEI_CORE
- VERSION_STRING = 1.0
- LIBRARY_CLASS = PeCoffLib|PEI_CORE
- EDK_RELEASE_VERSION = 0x00020000
- EFI_SPECIFICATION_VERSION = 0x00020000
-
-#
-# The following information is for reference only and not required by the build tools.
-#
-# VALID_ARCHITECTURES = IA32
-#
-
-[Sources.common]
- PeiCoreNt32PeCoffLib.c
-
-[Packages]
- MdePkg/MdePkg.dec
- MdeModulePkg/MdeModulePkg.dec
- Nt32Pkg/Nt32Pkg.dec
-
-[LibraryClasses]
- PeiServicesLib
- DebugLib
- HobLib
-
-[Guids]
- gEfiPeiPeCoffLoaderGuid # ALWAYS_CONSUMED
-
diff --git a/Nt32Pkg/Library/PeiNt32PeCoffExtraActionLib/PeiNt32PeCoffExtraActionLib.c b/Nt32Pkg/Library/PeiNt32PeCoffExtraActionLib/PeiNt32PeCoffExtraActionLib.c new file mode 100644 index 0000000000..d19b4a2652 --- /dev/null +++ b/Nt32Pkg/Library/PeiNt32PeCoffExtraActionLib/PeiNt32PeCoffExtraActionLib.c @@ -0,0 +1,251 @@ +/**@file
+
+Copyright (c) 2006, Intel Corporation
+All rights reserved. This program and the accompanying materials
+are licensed and made available under the terms and conditions of the BSD License
+which accompanies this distribution. The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+Module Name:
+
+ PeiNt32PeCoffExtraActionLib.c
+
+Abstract:
+
+ Provides services to perform additional actions to relocate and unload
+ PE/Coff image for NT32 environment specific purpose such as souce level debug.
+ This version only works for PEI phase
+
+
+**/
+//
+// The package level header files this module uses
+//
+#include <FrameworkPei.h>
+#include <FrameworkModulePei.h>
+#include <WinNtPeim.h>
+
+//
+// The protocols, PPI and GUID defintions for this module
+//
+#include <Ppi/NtThunk.h>
+
+#include <PiPei.h>
+#include <Library/PeCoffLib.h>
+#include <Library/PeiServicesLib.h>
+#include <Library/DebugLib.h>
+#include <Library/BaseLib.h>
+#include <Library/PeCoffExtraActionLib.h>
+
+//
+// Cache of WinNtThunk protocol
+//
+EFI_WIN_NT_THUNK_PROTOCOL *mWinNt = NULL;
+
+/**
+ The function caches the pointer of the WinNT thunk functions
+ It will ASSERT() if NT thunk ppi is not installed.
+
+ @retval EFI_SUCCESS WinNT thunk protocol is found and cached.
+
+**/
+EFI_STATUS
+EFIAPI
+Nt32PeCoffGetWinNtThunkStucture (
+ )
+{
+ PEI_NT_THUNK_PPI *NtThunkPpi;
+ EFI_STATUS Status;
+
+
+ //
+ // Locate NtThunkPpi for retrieving standard output handle
+ //
+ Status = PeiServicesLocatePpi (
+ &gPeiNtThunkPpiGuid,
+ 0,
+ NULL,
+ (VOID **) &NtThunkPpi
+ );
+
+ ASSERT_EFI_ERROR (Status);
+
+ mWinNt = (EFI_WIN_NT_THUNK_PROTOCOL *) NtThunkPpi->NtThunk ();
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Convert the passed in Ascii string to Unicode.
+
+ This function Convert the passed in Ascii string to Unicode.Optionally return
+ the length of the strings..
+
+ @param AsciiString Pointer to an AscII string
+ @param StrLen Length of string
+
+ @return Pointer to malloc'ed Unicode version of Ascii
+
+**/
+CHAR16 *
+AsciiToUnicode (
+ IN CHAR8 *Ascii,
+ IN UINTN *StrLen OPTIONAL
+ )
+{
+ UINTN Index;
+ CHAR16 *Unicode;
+
+ //
+ // Allocate a buffer for unicode string
+ //
+ for (Index = 0; Ascii[Index] != '\0'; Index++)
+ ;
+ Unicode = mWinNt->HeapAlloc ( mWinNt->GetProcessHeap (),
+ HEAP_ZERO_MEMORY,
+ ((Index + 1) * sizeof (CHAR16))
+ );
+ if (Unicode == NULL) {
+ return NULL;
+ }
+
+ for (Index = 0; Ascii[Index] != '\0'; Index++) {
+ Unicode[Index] = (CHAR16) Ascii[Index];
+ }
+
+ Unicode[Index] = '\0';
+
+ if (StrLen != NULL) {
+ *StrLen = Index;
+ }
+
+ return Unicode;
+}
+
+/**
+ Applies additional actions to relocate fixups to a PE/COFF image.
+
+ Generally this function is called after sucessfully Applying relocation fixups
+ to a PE/COFF image for some specicial purpose.
+ As a example, For NT32 emulator, the function should be implemented and called
+ to support source level debug.
+
+ @param ImageContext Pointer to the image context structure that describes the PE/COFF
+ image that is being relocated.
+
+**/
+VOID
+EFIAPI
+PeCoffLoaderRelocateImageExtraAction (
+ IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
+ )
+{
+ VOID *DllEntryPoint;
+ CHAR16 *DllFileName;
+ HMODULE Library;
+ UINTN Index;
+
+ if (mWinNt == NULL) {
+ Nt32PeCoffGetWinNtThunkStucture ();
+ }
+ //
+ // If we load our own PE COFF images the Windows debugger can not source
+ // level debug our code. If a valid PDB pointer exists usw it to load
+ // the *.dll file as a library using Windows* APIs. This allows
+ // source level debug. The image is still loaded and reloaced
+ // in the Framework memory space like on a real system (by the code above),
+ // but the entry point points into the DLL loaded by the code bellow.
+ //
+
+ DllEntryPoint = NULL;
+
+ //
+ // Load the DLL if it's not an EBC image.
+ //
+ if ((ImageContext->PdbPointer != NULL) &&
+ (ImageContext->Machine != EFI_IMAGE_MACHINE_EBC)) {
+ //
+ // Convert filename from ASCII to Unicode
+ //
+ DllFileName = AsciiToUnicode (ImageContext->PdbPointer, &Index);
+
+ //
+ // Check that we have a valid filename
+ //
+ if (Index < 5 || DllFileName[Index - 4] != '.') {
+ mWinNt->HeapFree (mWinNt->GetProcessHeap (), 0, DllFileName);
+
+ //
+ // Never return an error if PeCoffLoaderRelocateImage() succeeded.
+ // The image will run, but we just can't source level debug. If we
+ // return an error the image will not run.
+ //
+ return;
+ }
+ //
+ // Replace .PDB with .DLL on the filename
+ //
+ DllFileName[Index - 3] = 'D';
+ DllFileName[Index - 2] = 'L';
+ DllFileName[Index - 1] = 'L';
+
+ //
+ // Load the .DLL file into the user process's address space for source
+ // level debug
+ //
+ Library = mWinNt->LoadLibraryEx (DllFileName, NULL, DONT_RESOLVE_DLL_REFERENCES);
+ if (Library != NULL) {
+ //
+ // InitializeDriver is the entry point we put in all our EFI DLL's. The
+ // DONT_RESOLVE_DLL_REFERENCES argument to LoadLIbraryEx() supresses the
+ // normal DLL entry point of DllMain, and prevents other modules that are
+ // referenced in side the DllFileName from being loaded. There is no error
+ // checking as the we can point to the PE32 image loaded by Tiano. This
+ // step is only needed for source level debuging
+ //
+ DllEntryPoint = (VOID *) (UINTN) mWinNt->GetProcAddress (Library, "InitializeDriver");
+
+ }
+
+ if ((Library != NULL) && (DllEntryPoint != NULL)) {
+ ImageContext->EntryPoint = (EFI_PHYSICAL_ADDRESS) (UINTN) DllEntryPoint;
+ DEBUG ((EFI_D_INFO, "LoadLibraryEx (%s,\n NULL, DONT_RESOLVE_DLL_REFERENCES)\n", DllFileName));
+ } else {
+ DEBUG ((EFI_D_ERROR, "WARNING: No source level debug %s. \n", DllFileName));
+ }
+
+ mWinNt->HeapFree (mWinNt->GetProcessHeap (), 0, DllFileName);
+ }
+
+ //
+ // Never return an error if PeCoffLoaderRelocateImage() succeeded.
+ // The image will run, but we just can't source level debug. If we
+ // return an error the image will not run.
+ //
+ return;
+}
+
+/**
+ Unloads a loaded PE/COFF image from memory and releases its taken resource.
+
+ Releases any environment specific resources that were allocated when the image
+ specified by ImageContext was loaded using PeCoffLoaderLoadImage().
+ For NT32 emulator, the PE/COFF image loaded by system needs to release.
+ For real platform, the PE/COFF image loaded by Core doesn't needs to be unloaded,
+
+ If ImageContext is NULL, then ASSERT().
+
+ @param ImageContext Pointer to the image context structure that describes the PE/COFF
+ image to be unloaded.
+
+**/
+VOID
+EFIAPI
+PeCoffLoaderUnloadImageExtraAction (
+ IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
+ )
+{
+}
\ No newline at end of file diff --git a/Nt32Pkg/Library/PeiNt32PeCoffLib/PeiNt32PeCoffLib.inf b/Nt32Pkg/Library/PeiNt32PeCoffExtraActionLib/PeiNt32PeCoffExtraActionLib.inf index 9bfadfd6d7..8764ee803b 100644 --- a/Nt32Pkg/Library/PeiNt32PeCoffLib/PeiNt32PeCoffLib.inf +++ b/Nt32Pkg/Library/PeiNt32PeCoffExtraActionLib/PeiNt32PeCoffExtraActionLib.inf @@ -1,5 +1,5 @@ #/** @file
-# PeCoff libary for PEIM modules that run NT32 emulator.
+# PeCoff extra action libary for Pei phase that run NT32 emulator.
#
# Lib to provide memory journal status code reporting Routines
# Copyright (c) 2007, Intel Corporation
@@ -17,16 +17,14 @@ [Defines]
INF_VERSION = 0x00010005
- BASE_NAME = PeiNt32PeCoffLib
- FILE_GUID = 91404129-c58a-40bb-8a2b-f05bc05a961c
+ BASE_NAME = PeiNt32PeCoffExtraActionLib
+ FILE_GUID = 057C712A-84F0-4f4a-94CB-713EEF002E2F
MODULE_TYPE = PEIM
VERSION_STRING = 1.0
- LIBRARY_CLASS = PeCoffLib|PEIM
+ LIBRARY_CLASS = PeCoffExtraActionLib|PEI_CORE PEIM
EDK_RELEASE_VERSION = 0x00020000
EFI_SPECIFICATION_VERSION = 0x00020000
- CONSTRUCTOR = PeiNt32PeCoffLibConstructor
-
#
# The following information is for reference only and not required by the build tools.
#
@@ -34,17 +32,18 @@ #
[Sources.common]
- PeiNt32PeCoffLib.c
+ PeiNt32PeCoffExtraActionLib.c
[Packages]
MdePkg/MdePkg.dec
- MdeModulePkg/MdeModulePkg.dec
Nt32Pkg/Nt32Pkg.dec
+ IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec
+ IntelFrameworkPkg/IntelFrameworkPkg.dec
[LibraryClasses]
+ BaseLib
+ PeiServicesLib
DebugLib
- HobLib
-
-[Guids]
- gEfiPeiPeCoffLoaderGuid # ALWAYS_CONSUMED
+[Ppis]
+ gPeiNtThunkPpiGuid # PPI ALWAYS_CONSUMED
diff --git a/Nt32Pkg/Library/PeiNt32PeCoffLib/PeiNt32PeCoffLib.c b/Nt32Pkg/Library/PeiNt32PeCoffLib/PeiNt32PeCoffLib.c deleted file mode 100644 index 87ae3879a0..0000000000 --- a/Nt32Pkg/Library/PeiNt32PeCoffLib/PeiNt32PeCoffLib.c +++ /dev/null @@ -1,255 +0,0 @@ -/**@file
-
-Copyright (c) 2006, Intel Corporation
-All rights reserved. This program and the accompanying materials
-are licensed and made available under the terms and conditions of the BSD License
-which accompanies this distribution. The full text of the license may be found at
-http://opensource.org/licenses/bsd-license.php
-
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-
-Module Name:
-
- PeiNt32PeCoffLib.c
-
-Abstract:
-
- Wrap the Nt32 PE/COFF loader with the PE COFF LOADER guid structure
- to produce PeCoff library class.
-
-
-**/
-
-#include <PiPei.h>
-#include <Guid/PeiPeCoffLoader.h>
-#include <Library/DebugLib.h>
-#include <Library/PeCoffLib.h>
-#include <Library/HobLib.h>
-#include <Library/PeiServicesLib.h>
-
-EFI_PEI_PE_COFF_LOADER_PROTOCOL *mPeiEfiPeiPeCoffLoader;
-
-/**
- The constructor function caches the pointer of PeCofferLoader guid structure
- into the guid data hob.
-
- The constructor must be called after PeCofferLoader guid structure is installed.
- It will ASSERT() if PeCofferLoader guid structure is not installed.
-
- @param FileHandle Handle of the file being invoked.
- @param PeiServices Describes the list of possible PEI Services.
-
- @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
-
-**/
-EFI_STATUS
-EFIAPI
-PeiNt32PeCoffLibConstructor (
- IN EFI_PEI_FILE_HANDLE FileHandle,
- IN CONST EFI_PEI_SERVICES **PeiServices
- )
-{
- EFI_STATUS Status;
- EFI_HOB_GUID_TYPE *GuidHob;
-
- Status = EFI_NOT_FOUND;
-
- //
- // Try to get guid data hob that contains PeCoffLoader guid structure.
- //
- GuidHob = GetFirstGuidHob (&gEfiPeiPeCoffLoaderGuid);
-
- if (GuidHob == NULL) {
- //
- // GuidHob is not ready, try to locate PeCoffLoader guid structure.
- //
- Status = PeiServicesLocatePpi (
- &gEfiPeiPeCoffLoaderGuid,
- 0,
- NULL,
- (VOID**) &mPeiEfiPeiPeCoffLoader
- );
-
- //
- // PeCofferLoader guid structure must be installed before this library runs.
- //
- ASSERT_EFI_ERROR (Status);
-
- //
- // Build guid data hob of PeCofferLoader guid structure for DXE module use.
- //
- BuildGuidDataHob (
- &gEfiPeiPeCoffLoaderGuid,
- (VOID *) &mPeiEfiPeiPeCoffLoader,
- sizeof (VOID *)
- );
- } else {
- //
- // Get PeCofferLoader guid structure directly from guid hob data.
- //
- mPeiEfiPeiPeCoffLoader = (EFI_PEI_PE_COFF_LOADER_PROTOCOL *)(*(UINTN *)(GET_GUID_HOB_DATA (GuidHob)));
- }
-
- return EFI_SUCCESS;
-}
-
-/**
- Retrieves information about a PE/COFF image.
-
- Computes the PeCoffHeaderOffset, ImageAddress, ImageSize, DestinationAddress, CodeView,
- PdbPointer, RelocationsStripped, SectionAlignment, SizeOfHeaders, and DebugDirectoryEntryRva
- fields of the ImageContext structure. If ImageContext is NULL, then return RETURN_INVALID_PARAMETER.
- If the PE/COFF image accessed through the ImageRead service in the ImageContext structure is not
- a supported PE/COFF image type, then return RETURN_UNSUPPORTED. If any errors occur while
- computing the fields of ImageContext, then the error status is returned in the ImageError field of
- ImageContext.
-
- @param ImageContext Pointer to the image context structure that describes the PE/COFF
- image that needs to be examined by this function.
-
- @retval RETURN_SUCCESS The information on the PE/COFF image was collected.
- @retval RETURN_INVALID_PARAMETER ImageContext is NULL.
- @retval RETURN_UNSUPPORTED The PE/COFF image is not supported.
-
-**/
-RETURN_STATUS
-EFIAPI
-PeCoffLoaderGetImageInfo (
- IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
- )
-{
- return mPeiEfiPeiPeCoffLoader->GetImageInfo (mPeiEfiPeiPeCoffLoader, ImageContext);
-}
-
-/**
- Applies relocation fixups to a PE/COFF image that was loaded with PeCoffLoaderLoadImage().
-
- If the DestinationAddress field of ImageContext is 0, then use the ImageAddress field of
- ImageContext as the relocation base address. Otherwise, use the DestinationAddress field
- of ImageContext as the relocation base address. The caller must allocate the relocation
- fixup log buffer and fill in the FixupData field of ImageContext prior to calling this function.
- If ImageContext is NULL, then ASSERT().
-
- @param ImageContext Pointer to the image context structure that describes the PE/COFF
- image that is being relocated.
-
- @retval RETURN_SUCCESS The PE/COFF image was relocated.
- Extended status information is in the ImageError field of ImageContext.
- @retval RETURN_LOAD_ERROR The image in not a valid PE/COFF image.
- Extended status information is in the ImageError field of ImageContext.
- @retval RETURN_UNSUPPORTED A relocation record type is not supported.
- Extended status information is in the ImageError field of ImageContext.
-
-**/
-RETURN_STATUS
-EFIAPI
-PeCoffLoaderRelocateImage (
- IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
- )
-{
- return mPeiEfiPeiPeCoffLoader->RelocateImage (mPeiEfiPeiPeCoffLoader, ImageContext);
-}
-
-/**
- Loads a PE/COFF image into memory.
-
- Loads the PE/COFF image accessed through the ImageRead service of ImageContext into the buffer
- specified by the ImageAddress and ImageSize fields of ImageContext. The caller must allocate
- the load buffer and fill in the ImageAddress and ImageSize fields prior to calling this function.
- The EntryPoint, FixupDataSize, CodeView, and PdbPointer fields of ImageContext are computed.
- If ImageContext is NULL, then ASSERT().
-
- @param ImageContext Pointer to the image context structure that describes the PE/COFF
- image that is being loaded.
-
- @retval RETURN_SUCCESS The PE/COFF image was loaded into the buffer specified by
- the ImageAddress and ImageSize fields of ImageContext.
- Extended status information is in the ImageError field of ImageContext.
- @retval RETURN_BUFFER_TOO_SMALL The caller did not provide a large enough buffer.
- Extended status information is in the ImageError field of ImageContext.
- @retval RETURN_LOAD_ERROR The PE/COFF image is an EFI Runtime image with no relocations.
- Extended status information is in the ImageError field of ImageContext.
- @retval RETURN_INVALID_PARAMETER The image address is invalid.
- Extended status information is in the ImageError field of ImageContext.
-
-**/
-RETURN_STATUS
-EFIAPI
-PeCoffLoaderLoadImage (
- IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
- )
-{
- return mPeiEfiPeiPeCoffLoader->LoadImage (mPeiEfiPeiPeCoffLoader, ImageContext);
-}
-
-/**
- ImageRead function that operates on a memory buffer whos base is passed into
- FileHandle.
-
- @param FileHandle Ponter to baes of the input stream
- @param FileOffset Offset to the start of the buffer
- @param ReadSize Number of bytes to copy into the buffer
- @param Buffer Location to place results of read
-
- @retval RETURN_SUCCESS Data is read from FileOffset from the Handle into
- the buffer.
-**/
-RETURN_STATUS
-EFIAPI
-PeCoffLoaderImageReadFromMemory (
- IN VOID *FileHandle,
- IN UINTN FileOffset,
- IN OUT UINTN *ReadSize,
- OUT VOID *Buffer
- )
-{
- return RETURN_UNSUPPORTED;
-}
-
-
-/**
- Reapply fixups on a fixed up PE32/PE32+ image to allow virutal calling at EFI
- runtime.
-
- PE_COFF_LOADER_IMAGE_CONTEXT.FixupData stores information needed to reapply
- the fixups with a virtual mapping.
-
-
- @param ImageBase Base address of relocated image
- @param VirtImageBase Virtual mapping for ImageBase
- @param ImageSize Size of the image to relocate
- @param RelocationData Location to place results of read
-
-**/
-VOID
-EFIAPI
-PeCoffLoaderRelocateImageForRuntime (
- IN PHYSICAL_ADDRESS ImageBase,
- IN PHYSICAL_ADDRESS VirtImageBase,
- IN UINTN ImageSize,
- IN VOID *RelocationData
- )
-{
-}
-
-/**
- Unloads a loaded PE/COFF image from memory and releases its taken resource.
-
- For NT32 emulator, the PE/COFF image loaded by system needs to release.
- For real platform, the PE/COFF image loaded by Core doesn't needs to be unloaded,
- this function can simply return RETURN_SUCCESS.
-
- @param ImageContext Pointer to the image context structure that describes the PE/COFF
- image to be unloaded.
-
- @retval RETURN_SUCCESS The PE/COFF image was unloaded successfully.
-**/
-RETURN_STATUS
-EFIAPI
-PeCoffLoaderUnloadImage (
- IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
- )
-{
- return mPeiEfiPeiPeCoffLoader->UnloadImage (mPeiEfiPeiPeCoffLoader, ImageContext);
-}
diff --git a/Nt32Pkg/Nt32Pkg.dsc b/Nt32Pkg/Nt32Pkg.dsc index 033eada708..9f12d04ac1 100644 --- a/Nt32Pkg/Nt32Pkg.dsc +++ b/Nt32Pkg/Nt32Pkg.dsc @@ -59,6 +59,7 @@ CpuLib|MdePkg/Library/BaseCpuLib/BaseCpuLib.inf
PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibNull.inf
PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
+ PeCoffExtraActionLib|MdePkg/Library/PeCoffExtraActionLibNull/PeCoffExtraActionLibNull.inf
PciIncompatibleDeviceSupportLib|IntelFrameworkModulePkg/Library/PciIncompatibleDeviceSupportLib/PciIncompatibleDeviceSupportLib.inf
CacheMaintenanceLib|MdePkg/Library/BaseCacheMaintenanceLib/BaseCacheMaintenanceLib.inf
FvbServiceLib|MdeModulePkg/Library/EdkFvbServiceLib/EdkFvbServiceLib.inf
@@ -81,6 +82,7 @@ [LibraryClasses.common.USER_DEFINED]
DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf
+ PeCoffExtraActionLib|MdePkg/Library/PeCoffExtraActionLibNull/PeCoffExtraActionLibNull.inf
ReportStatusCodeLib|IntelFrameworkModulePkg/Library/PeiReportStatusCodeLib/PeiReportStatusCodeLib.inf
PeiServicesTablePointerLib|MdePkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf
OemHookStatusCodeLib|Nt32Pkg/Library/PeiNt32OemHookStatusCodeLib/PeiNt32OemHookStatusCodeLib.inf
@@ -98,7 +100,7 @@ UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf
DebugLib|IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/PeiDxeDebugLibReportStatusCode.inf
PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
- PeCoffLib|Nt32Pkg/Library/DxeNt32PeCoffLib/DxeNt32PeCoffLib.inf
+ PeCoffExtraActionLib|Nt32Pkg/Library/DxeNt32PeCoffExtraActionLib/DxeNt32PeCoffExtraActionLib.inf
ExtractGuidedSectionLib|MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.inf
[LibraryClasses.common.DXE_SMM_DRIVER]
@@ -130,7 +132,7 @@ OemHookStatusCodeLib|Nt32Pkg/Library/PeiNt32OemHookStatusCodeLib/PeiNt32OemHookStatusCodeLib.inf
PeCoffGetEntryPointLib|Nt32Pkg/Library/Nt32PeiPeCoffGetEntryPointLib/Nt32PeiPeCoffGetEntryPointLib.inf
DebugLib|IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/PeiDxeDebugLibReportStatusCode.inf
- PeCoffLib|Nt32Pkg/Library/PeiNt32PeCoffLib/PeiNt32PeCoffLib.inf
+ PeCoffExtraActionLib|Nt32Pkg/Library/PeiNt32PeCoffExtraActionLib/PeiNt32PeCoffExtraActionLib.inf
ExtractGuidedSectionLib|MdePkg/Library/PeiExtractGuidedSectionLib/PeiExtractGuidedSectionLib.inf
[LibraryClasses.common.PEI_CORE]
@@ -146,7 +148,7 @@ PeCoffGetEntryPointLib|Nt32Pkg/Library/Nt32PeiPeCoffGetEntryPointLib/Nt32PeiPeCoffGetEntryPointLib.inf
PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
DebugLib|IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/PeiDxeDebugLibReportStatusCode.inf
- PeCoffLib|Nt32Pkg/Library/PeiCoreNt32PeCoffLib/PeiCoreNt32PeCoffLib.inf
+ PeCoffExtraActionLib|Nt32Pkg/Library/PeiNt32PeCoffExtraActionLib/PeiNt32PeCoffExtraActionLib.inf
[LibraryClasses.common.DXE_RUNTIME_DRIVER]
UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf
@@ -164,6 +166,7 @@ WinNtLib|Nt32Pkg/Library/DxeWinNtLib/DxeWinNtLib.inf
OemHookStatusCodeLib|Nt32Pkg/Library/DxeNt32OemHookStatusCodeLib/DxeNt32OemHookStatusCodeLib.inf
DebugLib|IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/PeiDxeDebugLibReportStatusCode.inf
+ PeCoffExtraActionLib|Nt32Pkg/Library/DxeNt32PeCoffExtraActionLib/DxeNt32PeCoffExtraActionLib.inf
[LibraryClasses.common.UEFI_DRIVER]
UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf
@@ -184,6 +187,7 @@ IpIoLib|MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.inf
UdpIoLib|MdeModulePkg/Library/DxeUdpIoLib/DxeUdpIoLib.inf
DpcLib|MdeModulePkg/Library/DxeDpcLib/DxeDpcLib.inf
+ PeCoffExtraActionLib|Nt32Pkg/Library/DxeNt32PeCoffExtraActionLib/DxeNt32PeCoffExtraActionLib.inf
[LibraryClasses.common.DXE_DRIVER]
UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf
diff --git a/Nt32Pkg/Sec/SecMain.c b/Nt32Pkg/Sec/SecMain.c index e503ecf2c3..a63a814d3d 100644 --- a/Nt32Pkg/Sec/SecMain.c +++ b/Nt32Pkg/Sec/SecMain.c @@ -31,22 +31,6 @@ Abstract: #include "SecMain.h"
-//
-// Globals
-//
-EFI_PEI_PE_COFF_LOADER_PROTOCOL_INSTANCE mPeiEfiPeiPeCoffLoaderInstance = {
- {
- SecNt32PeCoffGetImageInfo,
- SecNt32PeCoffLoadImage,
- SecNt32PeCoffRelocateImage,
- SecNt32PeCoffUnloadimage
- },
- NULL
-};
-
-
-
-EFI_PEI_PE_COFF_LOADER_PROTOCOL *gPeiEfiPeiPeCoffLoader = &mPeiEfiPeiPeCoffLoaderInstance.PeCoff;
NT_PEI_LOAD_FILE_PPI mSecNtLoadFilePpi = { SecWinNtPeiLoadFile };
@@ -63,11 +47,6 @@ TEMPORARY_RAM_SUPPORT_PPI mSecTemporaryRamSupportPpi = {SecTempo EFI_PEI_PPI_DESCRIPTOR gPrivateDispatchTable[] = {
{
EFI_PEI_PPI_DESCRIPTOR_PPI,
- &gEfiPeiPeCoffLoaderGuid,
- NULL
- },
- {
- EFI_PEI_PPI_DESCRIPTOR_PPI,
&gNtPeiLoadFilePpiGuid,
&mSecNtLoadFilePpi
},
@@ -117,18 +96,16 @@ NT_FD_INFO *gFdInfo; UINTN gSystemMemoryCount = 0;
NT_SYSTEM_MEMORY *gSystemMemory;
-
-UINTN mPdbNameModHandleArraySize = 0;
-PDB_NAME_TO_MOD_HANDLE *mPdbNameModHandleArray = NULL;
-
-
VOID
EFIAPI
SecSwitchStack (
UINT32 TemporaryMemoryBase,
UINT32 PermenentMemoryBase
);
-
+EFI_STATUS
+SecNt32PeCoffRelocateImage (
+ IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
+ );
INTN
EFIAPI
main (
@@ -599,11 +576,6 @@ Returns: TopOfStack = ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);
//
- // Patch value in dispatch table values
- //
- gPrivateDispatchTable[0].Ppi = gPeiEfiPeiPeCoffLoader;
-
- //
// Bind this information into the SEC hand-off state
//
SecCoreData = (EFI_SEC_PEI_HAND_OFF*)(UINTN) TopOfStack;
@@ -750,7 +722,7 @@ Returns: ImageContext.ImageRead = (PE_COFF_LOADER_READ_FILE) SecImageRead;
- Status = gPeiEfiPeiPeCoffLoader->GetImageInfo (gPeiEfiPeiPeCoffLoader, &ImageContext);
+ Status = PeCoffLoaderGetImageInfo (&ImageContext);
if (EFI_ERROR (Status)) {
return Status;
}
@@ -768,12 +740,12 @@ Returns: ImageContext.ImageAddress += ImageContext.SectionAlignment;
ImageContext.ImageAddress &= ~(ImageContext.SectionAlignment - 1);
- Status = gPeiEfiPeiPeCoffLoader->LoadImage (gPeiEfiPeiPeCoffLoader, &ImageContext);
+ Status = PeCoffLoaderLoadImage (&ImageContext);
if (EFI_ERROR (Status)) {
return Status;
}
- Status = gPeiEfiPeiPeCoffLoader->RelocateImage (gPeiEfiPeiPeCoffLoader, &ImageContext);
+ Status = SecNt32PeCoffRelocateImage (&ImageContext);
if (EFI_ERROR (Status)) {
return Status;
}
@@ -943,138 +915,7 @@ Returns: EFI_STATUS
-AddModHandle (
- IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext,
- IN VOID *ModHandle
- )
-/*++
-
-Routine Description:
- Store the ModHandle in an array indexed by the Pdb File name.
- The ModHandle is needed to unload the image.
-
-Arguments:
- ImageContext - Input data returned from PE Laoder Library. Used to find the
- .PDB file name of the PE Image.
- ModHandle - Returned from LoadLibraryEx() and stored for call to
- FreeLibrary().
-
-Returns:
- EFI_SUCCESS - ModHandle was stored.
-
---*/
-{
- UINTN Index;
- PDB_NAME_TO_MOD_HANDLE *Array;
- UINTN PreviousSize;
-
-
- Array = mPdbNameModHandleArray;
- for (Index = 0; Index < mPdbNameModHandleArraySize; Index++, Array++) {
- if (Array->PdbPointer == NULL) {
- //
- // Make a copy of the stirng and store the ModHandle
- //
- Array->PdbPointer = malloc (strlen (ImageContext->PdbPointer) + 1);
- ASSERT (Array->PdbPointer != NULL);
-
- strcpy (Array->PdbPointer, ImageContext->PdbPointer);
- Array->ModHandle = ModHandle;
- return EFI_SUCCESS;
- }
- }
-
- //
- // No free space in mPdbNameModHandleArray so grow it by
- // MAX_PDB_NAME_TO_MOD_HANDLE_ARRAY_SIZE entires. realloc will
- // copy the old values to the new locaiton. But it does
- // not zero the new memory area.
- //
- PreviousSize = mPdbNameModHandleArraySize * sizeof (PDB_NAME_TO_MOD_HANDLE);
- mPdbNameModHandleArraySize += MAX_PDB_NAME_TO_MOD_HANDLE_ARRAY_SIZE;
-
- mPdbNameModHandleArray = realloc (mPdbNameModHandleArray, mPdbNameModHandleArraySize * sizeof (PDB_NAME_TO_MOD_HANDLE));
- if (mPdbNameModHandleArray == NULL) {
- ASSERT (FALSE);
- return EFI_OUT_OF_RESOURCES;
- }
-
- memset (mPdbNameModHandleArray + PreviousSize, 0, MAX_PDB_NAME_TO_MOD_HANDLE_ARRAY_SIZE * sizeof (PDB_NAME_TO_MOD_HANDLE));
-
- return AddModHandle (ImageContext, ModHandle);
-}
-
-
-VOID *
-RemoveModeHandle (
- IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
- )
-/*++
-
-Routine Description:
- Return the ModHandle and delete the entry in the array.
-
-Arguments:
- ImageContext - Input data returned from PE Laoder Library. Used to find the
- .PDB file name of the PE Image.
-
-Returns:
- ModHandle - ModHandle assoicated with ImageContext is returned
- NULL - No ModHandle associated with ImageContext
-
---*/
-{
- UINTN Index;
- PDB_NAME_TO_MOD_HANDLE *Array;
-
- if (ImageContext->PdbPointer == NULL) {
- //
- // If no PDB pointer there is no ModHandle so return NULL
- //
- return NULL;
- }
-
- Array = mPdbNameModHandleArray;
- for (Index = 0; Index < mPdbNameModHandleArraySize; Index++, Array++) {
- if ((Array->PdbPointer != NULL) && (strcmp(Array->PdbPointer, ImageContext->PdbPointer) == 0)) {
- //
- // If you find a match return it and delete the entry
- //
- free (Array->PdbPointer);
- Array->PdbPointer = NULL;
- return Array->ModHandle;
- }
- }
-
- return NULL;
-}
-
-
-
-EFI_STATUS
-EFIAPI
-SecNt32PeCoffGetImageInfo (
- IN EFI_PEI_PE_COFF_LOADER_PROTOCOL *This,
- IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
- )
-{
- return PeCoffLoaderGetImageInfo (ImageContext);
-}
-
-EFI_STATUS
-EFIAPI
-SecNt32PeCoffLoadImage (
- IN EFI_PEI_PE_COFF_LOADER_PROTOCOL *This,
- IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
- )
-{
- return PeCoffLoaderLoadImage (ImageContext);
-}
-
-EFI_STATUS
-EFIAPI
SecNt32PeCoffRelocateImage (
- IN EFI_PEI_PE_COFF_LOADER_PROTOCOL *This,
IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
)
{
@@ -1153,7 +994,6 @@ SecNt32PeCoffRelocateImage ( }
if ((Library != NULL) && (DllEntryPoint != NULL)) {
- AddModHandle (ImageContext, Library);
ImageContext->EntryPoint = (EFI_PHYSICAL_ADDRESS) (UINTN) DllEntryPoint;
wprintf (L"LoadLibraryEx (%s,\n NULL, DONT_RESOLVE_DLL_REFERENCES)\n", DllFileName);
} else {
@@ -1172,21 +1012,7 @@ SecNt32PeCoffRelocateImage ( }
-EFI_STATUS
-EFIAPI
-SecNt32PeCoffUnloadimage (
- IN EFI_PEI_PE_COFF_LOADER_PROTOCOL *This,
- IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
- )
-{
- VOID *ModHandle;
- ModHandle = RemoveModeHandle (ImageContext);
- if (ModHandle != NULL) {
- FreeLibrary (ModHandle);
- }
- return EFI_SUCCESS;
-}
VOID
_ModuleEntryPoint (
diff --git a/Nt32Pkg/Sec/SecMain.h b/Nt32Pkg/Sec/SecMain.h index c71f287c7c..f2db1aa22e 100644 --- a/Nt32Pkg/Sec/SecMain.h +++ b/Nt32Pkg/Sec/SecMain.h @@ -25,7 +25,6 @@ Abstract: #include <WinNtPeim.h>
#include <Library/BaseLib.h>
#include <Library/PeCoffLib.h>
-#include <Guid/PeiPeCoffLoader.h>
#include <Ppi/NtPeiLoadFile.h>
#include <Ppi/NtAutoscan.h>
#include <Ppi/NtThunk.h>
@@ -551,34 +550,6 @@ Returns: EFI_STATUS
EFIAPI
-SecNt32PeCoffGetImageInfo (
- IN EFI_PEI_PE_COFF_LOADER_PROTOCOL *This,
- IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
- );
-
-EFI_STATUS
-EFIAPI
-SecNt32PeCoffLoadImage (
- IN EFI_PEI_PE_COFF_LOADER_PROTOCOL *This,
- IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
- );
-
-EFI_STATUS
-EFIAPI
-SecNt32PeCoffRelocateImage (
- IN EFI_PEI_PE_COFF_LOADER_PROTOCOL *This,
- IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
- );
-
-EFI_STATUS
-EFIAPI
-SecNt32PeCoffUnloadimage (
- IN EFI_PEI_PE_COFF_LOADER_PROTOCOL *This,
- IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
- );
-
-EFI_STATUS
-EFIAPI
SecTemporaryRamSupport (
IN CONST EFI_PEI_SERVICES **PeiServices,
IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase,
@@ -586,9 +557,5 @@ SecTemporaryRamSupport ( IN UINTN CopySize
);
-typedef struct {
- EFI_PEI_PE_COFF_LOADER_PROTOCOL PeCoff;
- VOID *ModHandle;
-} EFI_PEI_PE_COFF_LOADER_PROTOCOL_INSTANCE;
extern EFI_WIN_NT_THUNK_PROTOCOL *gWinNt;
diff --git a/Nt32Pkg/Sec/SecMain.inf b/Nt32Pkg/Sec/SecMain.inf index 47c52dabf6..c5f6bacaf4 100644 --- a/Nt32Pkg/Sec/SecMain.inf +++ b/Nt32Pkg/Sec/SecMain.inf @@ -49,9 +49,6 @@ PeCoffLib
ReportStatusCodeLib
-[Guids]
- gEfiPeiPeCoffLoaderGuid # ALWAYS_PRODUCED
-
[Ppis]
gNtPeiLoadFilePpiGuid # PPI ALWAYS_PRODUCED
|