]> git.proxmox.com Git - mirror_edk2.git/blob - EmulatorPkg/Library/DxeEmuPeCoffExtraActionLib/DxeEmuPeCoffExtraActionLib.c
EmulatorPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / EmulatorPkg / Library / DxeEmuPeCoffExtraActionLib / DxeEmuPeCoffExtraActionLib.c
1 /** @file
2 Provides services to perform additional actions to relocate and unload
3 PE/Coff image for Emu environment specific purpose such as souce level debug.
4 This version only works for DXE phase
5
6 Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>
7 Portions copyright (c) 2008 - 2011, Apple Inc. All rights reserved.<BR>
8 SPDX-License-Identifier: BSD-2-Clause-Patent
9
10 **/
11
12 #include <PiDxe.h>
13
14 #include <Protocol/EmuThunk.h>
15
16 #include <Library/PeCoffLib.h>
17 #include <Library/BaseLib.h>
18 #include <Library/DebugLib.h>
19 #include <Library/HobLib.h>
20 #include <Library/BaseMemoryLib.h>
21 #include <Library/PeCoffExtraActionLib.h>
22
23 //
24 // Cache of UnixThunk protocol
25 //
26 EMU_THUNK_PROTOCOL *mThunk = NULL;
27
28
29 /**
30 The constructor function gets the pointer of the WinNT thunk functions
31 It will ASSERT() if Unix thunk protocol is not installed.
32
33 @retval EFI_SUCCESS Unix thunk protocol is found and cached.
34
35 **/
36 EFI_STATUS
37 EFIAPI
38 DxeEmuPeCoffLibExtraActionConstructor (
39 IN EFI_HANDLE ImageHandle,
40 IN EFI_SYSTEM_TABLE *SystemTable
41 )
42 {
43 EFI_HOB_GUID_TYPE *GuidHob;
44
45 //
46 // Retrieve EmuThunkProtocol from GUID'ed HOB
47 //
48 GuidHob = GetFirstGuidHob (&gEmuThunkProtocolGuid);
49 ASSERT (GuidHob != NULL);
50 mThunk = (EMU_THUNK_PROTOCOL *)(*(UINTN *)(GET_GUID_HOB_DATA (GuidHob)));
51 ASSERT (mThunk != NULL);
52
53 return EFI_SUCCESS;
54 }
55
56 /**
57 Performs additional actions after a PE/COFF image has been loaded and relocated.
58
59 If ImageContext is NULL, then ASSERT().
60
61 @param ImageContext Pointer to the image context structure that describes the
62 PE/COFF image that has already been loaded and relocated.
63
64 **/
65 VOID
66 EFIAPI
67 PeCoffLoaderRelocateImageExtraAction (
68 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
69 )
70 {
71 if (mThunk != NULL) {
72 mThunk->PeCoffRelocateImageExtraAction (ImageContext);
73 }
74 }
75
76
77
78 /**
79 Performs additional actions just before a PE/COFF image is unloaded. Any resources
80 that were allocated by PeCoffLoaderRelocateImageExtraAction() must be freed.
81
82 If ImageContext is NULL, then ASSERT().
83
84 @param ImageContext Pointer to the image context structure that describes the
85 PE/COFF image that is being unloaded.
86
87 **/
88 VOID
89 EFIAPI
90 PeCoffLoaderUnloadImageExtraAction (
91 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
92 )
93 {
94 if (mThunk != NULL) {
95 mThunk->PeCoffUnloadImageExtraAction (ImageContext);
96 }
97 }