]> git.proxmox.com Git - mirror_edk2.git/blame - InOsEmuPkg/Library/DxeEmuPeCoffExtraActionLib/DxeEmuPeCoffExtraActionLib.c
Add InOsEmuPkg. Like UnixPkg and Nt32Pkg, but EFI code can be common and does not...
[mirror_edk2.git] / InOsEmuPkg / Library / DxeEmuPeCoffExtraActionLib / DxeEmuPeCoffExtraActionLib.c
CommitLineData
949f388f 1/** @file\r
2 Provides services to perform additional actions to relocate and unload\r
3 PE/Coff image for Emu environment specific purpose such as souce level debug.\r
4 This version only works for DXE phase \r
5\r
6Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
7Portions copyright (c) 2008 - 2011, Apple Inc. All rights reserved.<BR>\r
8This program and the accompanying materials\r
9are licensed and made available under the terms and conditions of the BSD License\r
10which accompanies this distribution. The full text of the license may be found at\r
11http://opensource.org/licenses/bsd-license.php\r
12\r
13THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
14WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
15\r
16**/\r
17\r
18#include <PiDxe.h>\r
19\r
20#include <Protocol/EmuThunk.h>\r
21\r
22#include <Library/PeCoffLib.h>\r
23#include <Library/BaseLib.h>\r
24#include <Library/DebugLib.h>\r
25#include <Library/HobLib.h>\r
26#include <Library/BaseMemoryLib.h>\r
27#include <Library/PeCoffExtraActionLib.h>\r
28\r
29//\r
30// Cache of UnixThunk protocol \r
31//\r
32EMU_THUNK_PROTOCOL *mThunk = NULL;\r
33\r
34\r
35/**\r
36 The constructor function gets the pointer of the WinNT thunk functions\r
37 It will ASSERT() if Unix thunk protocol is not installed.\r
38\r
39 @retval EFI_SUCCESS Unix thunk protocol is found and cached.\r
40\r
41**/\r
42EFI_STATUS\r
43EFIAPI\r
44DxeEmuPeCoffLibExtraActionConstructor (\r
45 IN EFI_HANDLE ImageHandle,\r
46 IN EFI_SYSTEM_TABLE *SystemTable\r
47 )\r
48{\r
49 EFI_HOB_GUID_TYPE *GuidHob;\r
50\r
51 //\r
52 // Retrieve EmuThunkProtocol from GUID'ed HOB\r
53 //\r
54 GuidHob = GetFirstGuidHob (&gEmuThunkProtocolGuid);\r
55 ASSERT (GuidHob != NULL);\r
56 mThunk = (EMU_THUNK_PROTOCOL *)(*(UINTN *)(GET_GUID_HOB_DATA (GuidHob)));\r
57 ASSERT (mThunk != NULL);\r
58\r
59 return EFI_SUCCESS;\r
60}\r
61\r
62/**\r
63 Performs additional actions after a PE/COFF image has been loaded and relocated.\r
64\r
65 If ImageContext is NULL, then ASSERT().\r
66\r
67 @param ImageContext Pointer to the image context structure that describes the\r
68 PE/COFF image that has already been loaded and relocated.\r
69\r
70**/\r
71VOID\r
72EFIAPI\r
73PeCoffLoaderRelocateImageExtraAction (\r
74 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r
75 )\r
76{\r
77 if (mThunk != NULL) {\r
78 mThunk->PeCoffRelocateImageExtraAction (ImageContext);\r
79 }\r
80}\r
81\r
82\r
83\r
84/**\r
85 Performs additional actions just before a PE/COFF image is unloaded. Any resources\r
86 that were allocated by PeCoffLoaderRelocateImageExtraAction() must be freed.\r
87 \r
88 If ImageContext is NULL, then ASSERT().\r
89 \r
90 @param ImageContext Pointer to the image context structure that describes the\r
91 PE/COFF image that is being unloaded.\r
92\r
93**/\r
94VOID\r
95EFIAPI\r
96PeCoffLoaderUnloadImageExtraAction (\r
97 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r
98 )\r
99{\r
100 if (mThunk != NULL) {\r
101 mThunk->PeCoffUnloadImageExtraAction (ImageContext);\r
102 }\r
103}\r