3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14 PeiUnixPeCoffExtraActionLib.c
18 Provides services to perform additional actions to relocate and unload
19 PE/Coff image for UNIX environment specific purpose such as souce level debug.
20 This version only works for PEI phase
25 #include <Ppi/UnixThunk.h>
26 #include <FrameworkModuleBase.h>
28 #include <Library/PeCoffLib.h>
29 #include <Library/PeiServicesLib.h>
30 #include <Library/DebugLib.h>
31 #include <Library/BaseLib.h>
32 #include <Library/PeCoffExtraActionLib.h>
35 // Cache of UnixThunk protocol
37 EFI_UNIX_THUNK_PROTOCOL
*mUnix
= NULL
;
40 The function caches the pointer of the WinNT thunk functions
41 It will ASSERT() if Unix thunk ppi is not installed.
43 @retval EFI_SUCCESS WinNT thunk protocol is found and cached.
48 UnixPeCoffGetUnixThunkStucture (
51 PEI_UNIX_THUNK_PPI
*UnixThunkPpi
;
56 // Locate Unix ThunkPpi for retrieving standard output handle
58 Status
= PeiServicesLocatePpi (
59 &gPeiUnixThunkPpiGuid
,
62 (VOID
**) &UnixThunkPpi
65 ASSERT_EFI_ERROR (Status
);
67 mUnix
= (EFI_UNIX_THUNK_PROTOCOL
*) UnixThunkPpi
->UnixThunk ();
73 Applies additional actions to relocate fixups to a PE/COFF image.
75 Generally this function is called after sucessfully Applying relocation fixups
76 to a PE/COFF image for some specicial purpose.
78 @param ImageContext Pointer to the image context structure that describes the PE/COFF
79 image that is being relocated.
84 PeCoffLoaderRelocateImageExtraAction (
85 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
95 UnixPeCoffGetUnixThunkStucture ();
97 DEBUG ((EFI_D_ERROR
, "Loading %s 0x%08lx - entry point 0x%08lx\n",
98 ImageContext
->PdbPointer
,
99 (UINTN
)ImageContext
->ImageAddress
,
100 (UINTN
)ImageContext
->EntryPoint
));
102 Handle
= mUnix
->Dlopen (ImageContext
->PdbPointer
, RTLD_NOW
);
105 Entry
= mUnix
->Dlsym(Handle
, "_ModuleEntryPoint");
107 DEBUG ((EFI_D_ERROR
, "%s\n", mUnix
->Dlerror()));
111 ImageContext
->EntryPoint
= Entry
;
112 DEBUG ((EFI_D_ERROR
, "Change %s Entrypoint to :0x%08lx\n", ImageContext
->PdbPointer
, Entry
));
120 Unloads a loaded PE/COFF image from memory and releases its taken resource.
122 Releases any environment specific resources that were allocated when the image
123 specified by ImageContext was loaded using PeCoffLoaderLoadImage().
125 If ImageContext is NULL, then ASSERT().
127 @param ImageContext Pointer to the image context structure that describes the PE/COFF
128 image to be unloaded.
133 PeCoffLoaderUnloadImageExtraAction (
134 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext