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