]>
Commit | Line | Data |
---|---|---|
398b646f | 1 | /**@file |
2 | ||
8c8f3dcb | 3 | Copyright (c) 2006 - 2009, Intel Corporation |
398b646f | 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 | /** | |
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 | |
398b646f | 77 | |
78 | **/ | |
79 | VOID | |
80 | EFIAPI | |
81 | PeCoffLoaderRelocateImageExtraAction ( | |
82 | IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext | |
83 | ) | |
84 | { | |
85 | VOID * Handle;\r | |
86 | VOID * Entry;\r | |
87 | \r | |
6cb6f078 | 88 | ASSERT (ImageContext != NULL);\r |
89 | \r | |
398b646f | 90 | Handle = NULL;\r |
91 | Entry = NULL; | |
92 | ||
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 | |
102 | } else { | |
8c8f3dcb | 103 | DEBUG ((EFI_D_ERROR, "%a\n", mUnix->Dlerror()));\r |
398b646f | 104 | }\r |
105 | \r | |
106 | if (Entry != NULL) {\r | |
107 | ImageContext->EntryPoint = Entry; | |
8c8f3dcb | 108 | DEBUG ((EFI_D_ERROR, "Change %a Entrypoint to :0x%08lx\n", ImageContext->PdbPointer, Entry));\r |
398b646f | 109 | }\r |
110 | \r | |
111 | \r | |
112 | return; | |
113 | } | |
114 | ||
115 | /** | |
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 | |
398b646f | 123 | |
124 | **/ | |
125 | VOID | |
126 | EFIAPI | |
127 | PeCoffLoaderUnloadImageExtraAction ( | |
128 | IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext | |
129 | ) | |
130 | { | |
6cb6f078 | 131 | ASSERT (ImageContext != NULL);\r |
1664e0af | 132 | } |