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