]>
Commit | Line | Data |
---|---|---|
398b646f | 1 | /**@file |
2 | ||
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 | |
8 | ||
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. | |
11 | ||
12 | Module Name: | |
13 | ||
14 | PeiUnixPeCoffExtraActionLib.c | |
15 | ||
16 | Abstract: | |
17 | ||
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 | |
21 | ||
22 | ||
23 | **/ | |
24 | ||
25 | #include <PiDxe.h>\r | |
26 | #include <Guid/StatusCodeDataTypeId.h>\r | |
27 | #include <UnixDxe.h> | |
28 | #include <Library/PeCoffLib.h> | |
29 | #include <Library/PeiServicesLib.h> | |
30 | ||
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> | |
36 | ||
37 | //\r | |
38 | // Cache of UnixThunk protocol \r | |
39 | //\r | |
40 | EFI_UNIX_THUNK_PROTOCOL *mUnix; | |
41 | ||
42 | ||
43 | /** | |
44 | The constructor function gets the pointer of the WinNT thunk functions | |
45 | It will ASSERT() if Unix thunk protocol is not installed. | |
46 | ||
47 | @retval EFI_SUCCESS Unix thunk protocol is found and cached. | |
48 | ||
49 | **/ | |
50 | EFI_STATUS | |
51 | EFIAPI | |
52 | DxeUnixPeCoffLibExtraActionConstructor ( | |
53 | IN EFI_HANDLE ImageHandle, | |
54 | IN EFI_SYSTEM_TABLE *SystemTable | |
55 | ) | |
56 | { | |
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 | |
67 | return EFI_SUCCESS; | |
68 | } | |
69 | ||
70 | /** | |
71 | Applies additional actions to relocate fixups to a PE/COFF image. | |
72 | ||
73 | Generally this function is called after sucessfully Applying relocation fixups | |
74 | to a PE/COFF image for some specicial purpose. | |
75 | ||
76 | @param ImageContext Pointer to the image context structure that describes the PE/COFF | |
77 | image that is being relocated. | |
78 | ||
79 | **/ | |
80 | VOID | |
81 | EFIAPI | |
82 | PeCoffLoaderRelocateImageExtraAction ( | |
83 | IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext | |
84 | ) | |
85 | { | |
86 | VOID * Handle;\r | |
87 | VOID * Entry;\r | |
88 | \r | |
89 | Handle = NULL;\r | |
90 | Entry = NULL; | |
91 | ||
92 | DEBUG ((EFI_D_ERROR, "Loading %s 0x%08lx - entry point 0x%08lx\n",\r | |
93 | ImageContext->PdbPointer,\r | |
94 | (UINTN)ImageContext->ImageAddress,\r | |
95 | (UINTN)ImageContext->EntryPoint));\r | |
96 | \r | |
97 | Handle = mUnix->Dlopen(ImageContext->PdbPointer, RTLD_NOW);\r | |
98 | \r | |
99 | if (Handle) {\r | |
100 | Entry = mUnix->Dlsym(Handle, "_ModuleEntryPoint");\r | |
101 | } else { | |
102 | DEBUG ((EFI_D_ERROR, "%s\n", mUnix->Dlerror()));\r | |
103 | }\r | |
104 | \r | |
105 | if (Entry != NULL) {\r | |
106 | ImageContext->EntryPoint = Entry; | |
107 | DEBUG ((EFI_D_ERROR, "Change %s Entrypoint to :0x%08lx\n", ImageContext->PdbPointer, Entry));\r | |
108 | }\r | |
109 | \r | |
110 | \r | |
111 | return; | |
112 | } | |
113 | ||
114 | /** | |
115 | Unloads a loaded PE/COFF image from memory and releases its taken resource. | |
116 | ||
117 | Releases any environment specific resources that were allocated when the image | |
118 | specified by ImageContext was loaded using PeCoffLoaderLoadImage(). | |
119 | ||
120 | If ImageContext is NULL, then ASSERT(). | |
121 | ||
122 | @param ImageContext Pointer to the image context structure that describes the PE/COFF | |
123 | image to be unloaded. | |
124 | ||
125 | **/ | |
126 | VOID | |
127 | EFIAPI | |
128 | PeCoffLoaderUnloadImageExtraAction ( | |
129 | IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext | |
130 | ) | |
131 | { | |
1664e0af | 132 | } |