]> git.proxmox.com Git - mirror_edk2.git/blame - UnixPkg/Library/DxeUnixPeCoffExtraActionLib/DxeUnixPeCoffExtraActionLib.c
Remove extra #includes where possible to make build more efficient
[mirror_edk2.git] / UnixPkg / Library / DxeUnixPeCoffExtraActionLib / DxeUnixPeCoffExtraActionLib.c
CommitLineData
bac49e77 1/**@file\r
2\r
3Copyright (c) 2006 - 2009, Intel Corporation\r
4All rights reserved. This program and the accompanying materials\r
5are licensed and made available under the terms and conditions of the BSD License\r
6which accompanies this distribution. The full text of the license may be found at\r
7http://opensource.org/licenses/bsd-license.php\r
8\r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11\r
12Module Name:\r
13\r
14 PeiUnixPeCoffExtraActionLib.c\r
15\r
16Abstract:\r
17\r
18 Provides services to perform additional actions to relocate and unload\r
19 PE/Coff image for Unix environment specific purpose such as souce level debug.\r
20 This version only works for DXE phase \r
21\r
22\r
23**/\r
24\r
25#include <FrameworkDxe.h>\r
398b646f 26#include <Guid/StatusCodeDataTypeId.h>\r
bac49e77 27#include <UnixDxe.h>\r
28#include <Library/PeCoffLib.h>\r
29#include <Library/PeiServicesLib.h>\r
30\r
31#include <Library/BaseLib.h>\r
32#include <Library/DebugLib.h>\r
33#include <Library/HobLib.h>\r
34#include <Library/BaseMemoryLib.h>\r
35#include <Library/PeCoffExtraActionLib.h>\r
36\r
398b646f 37//\r
38// Cache of UnixThunk protocol \r
39//\r
bac49e77 40EFI_UNIX_THUNK_PROTOCOL *mUnix;\r
41\r
42\r
43/**\r
44 The constructor function gets the pointer of the WinNT thunk functions\r
45 It will ASSERT() if Unix thunk protocol is not installed.\r
46\r
47 @retval EFI_SUCCESS Unix thunk protocol is found and cached.\r
48\r
49**/\r
50EFI_STATUS\r
51EFIAPI\r
52DxeUnixPeCoffLibExtraActionConstructor (\r
53 IN EFI_HANDLE ImageHandle,\r
54 IN EFI_SYSTEM_TABLE *SystemTable\r
55 )\r
56{\r
398b646f 57 EFI_HOB_GUID_TYPE *GuidHob;\r
58\r
59 //\r
60 // Retrieve UnixThunkProtocol from GUID'ed HOB\r
61 //\r
62 GuidHob = GetFirstGuidHob (&gEfiUnixThunkProtocolGuid);\r
63 ASSERT (GuidHob != NULL);\r
64 mUnix = (EFI_UNIX_THUNK_PROTOCOL *)(*(UINTN *)(GET_GUID_HOB_DATA (GuidHob)));\r
65 ASSERT (mUnix != NULL);\r
66\r
bac49e77 67 return EFI_SUCCESS;\r
68}\r
69\r
70/**\r
6cb6f078 71 Performs additional actions after a PE/COFF image has been loaded and relocated.\r
72\r
73 If ImageContext is NULL, then ASSERT().\r
74\r
75 @param ImageContext Pointer to the image context structure that describes the\r
76 PE/COFF image that has already been loaded and relocated.\r
bac49e77 77\r
78**/\r
79VOID\r
80EFIAPI\r
81PeCoffLoaderRelocateImageExtraAction (\r
82 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r
83 )\r
84{\r
398b646f 85 VOID * Handle;\r
86 VOID * Entry;\r
87\r
6cb6f078 88 ASSERT (ImageContext != NULL);\r
89\r
398b646f 90 Handle = NULL;\r
bac49e77 91 Entry = NULL;\r
92 \r
8c8f3dcb 93 DEBUG ((EFI_D_ERROR, "Loading %a 0x%08lx - entry point 0x%08lx\n",\r
398b646f 94 ImageContext->PdbPointer,\r
95 (UINTN)ImageContext->ImageAddress,\r
96 (UINTN)ImageContext->EntryPoint));\r
97\r
98 Handle = mUnix->Dlopen(ImageContext->PdbPointer, RTLD_NOW);\r
99 \r
100 if (Handle) {\r
101 Entry = mUnix->Dlsym(Handle, "_ModuleEntryPoint");\r
bac49e77 102 } else {\r
8c8f3dcb 103 DEBUG ((EFI_D_ERROR, "%a\n", mUnix->Dlerror()));\r
398b646f 104 }\r
105 \r
106 if (Entry != NULL) {\r
bac49e77 107 ImageContext->EntryPoint = Entry;\r
8c8f3dcb 108 DEBUG ((EFI_D_ERROR, "Change %a Entrypoint to :0x%08lx\n", ImageContext->PdbPointer, Entry));\r
398b646f 109 }\r
110\r
111\r
bac49e77 112 return;\r
113 } \r
114\r
115/**\r
6cb6f078 116 Performs additional actions just before a PE/COFF image is unloaded. Any resources\r
117 that were allocated by PeCoffLoaderRelocateImageExtraAction() must be freed.\r
118 \r
119 If ImageContext is NULL, then ASSERT().\r
120 \r
121 @param ImageContext Pointer to the image context structure that describes the\r
122 PE/COFF image that is being unloaded.\r
bac49e77 123\r
124**/\r
125VOID\r
126EFIAPI\r
127PeCoffLoaderUnloadImageExtraAction (\r
128 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r
129 )\r
130{\r
6cb6f078 131 ASSERT (ImageContext != NULL);\r
bac49e77 132}\r