3 Copyright (c) 2006 - 2009, 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 DXE phase
25 #include <FrameworkDxe.h>
26 #include <Guid/StatusCodeDataTypeId.h>
28 #include <Library/PeCoffLib.h>
31 #include <Library/BaseLib.h>
32 #include <Library/DebugLib.h>
33 #include <Library/HobLib.h>
34 #include <Library/BaseMemoryLib.h>
35 #include <Library/PeCoffExtraActionLib.h>
38 // Cache of UnixThunk protocol
40 EFI_UNIX_THUNK_PROTOCOL
*mUnix
;
44 The constructor function gets the pointer of the WinNT thunk functions
45 It will ASSERT() if Unix thunk protocol is not installed.
47 @retval EFI_SUCCESS Unix thunk protocol is found and cached.
52 DxeUnixPeCoffLibExtraActionConstructor (
53 IN EFI_HANDLE ImageHandle
,
54 IN EFI_SYSTEM_TABLE
*SystemTable
57 EFI_HOB_GUID_TYPE
*GuidHob
;
60 // Retrieve UnixThunkProtocol from GUID'ed HOB
62 GuidHob
= GetFirstGuidHob (&gEfiUnixThunkProtocolGuid
);
63 ASSERT (GuidHob
!= NULL
);
64 mUnix
= (EFI_UNIX_THUNK_PROTOCOL
*)(*(UINTN
*)(GET_GUID_HOB_DATA (GuidHob
)));
65 ASSERT (mUnix
!= NULL
);
71 Performs additional actions after a PE/COFF image has been loaded and relocated.
73 If ImageContext is NULL, then ASSERT().
75 @param ImageContext Pointer to the image context structure that describes the
76 PE/COFF image that has already been loaded and relocated.
81 PeCoffLoaderRelocateImageExtraAction (
82 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
88 ASSERT (ImageContext
!= NULL
);
93 DEBUG ((EFI_D_ERROR
, "Loading %a 0x%08lx - entry point 0x%08lx\n",
94 ImageContext
->PdbPointer
,
95 (UINTN
)ImageContext
->ImageAddress
,
96 (UINTN
)ImageContext
->EntryPoint
));
98 Handle
= mUnix
->Dlopen(ImageContext
->PdbPointer
, RTLD_NOW
);
101 Entry
= mUnix
->Dlsym(Handle
, "_ModuleEntryPoint");
103 DEBUG ((EFI_D_ERROR
, "%a\n", mUnix
->Dlerror()));
107 ImageContext
->EntryPoint
= Entry
;
108 DEBUG ((EFI_D_ERROR
, "Change %a Entrypoint to :0x%08lx\n", ImageContext
->PdbPointer
, Entry
));
116 Performs additional actions just before a PE/COFF image is unloaded. Any resources
117 that were allocated by PeCoffLoaderRelocateImageExtraAction() must be freed.
119 If ImageContext is NULL, then ASSERT().
121 @param ImageContext Pointer to the image context structure that describes the
122 PE/COFF image that is being unloaded.
127 PeCoffLoaderUnloadImageExtraAction (
128 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
131 ASSERT (ImageContext
!= NULL
);