]> git.proxmox.com Git - mirror_edk2.git/blob - InOsEmuPkg/Library/PeiEmuPeCoffExtraActionLib/PeiEmuPeCoffExtraActionLib.c
Add InOsEmuPkg. Like UnixPkg and Nt32Pkg, but EFI code can be common and does not...
[mirror_edk2.git] / InOsEmuPkg / Library / PeiEmuPeCoffExtraActionLib / PeiEmuPeCoffExtraActionLib.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 PEI 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 #include <PiPei.h>
18 #include <Ppi/EmuThunk.h>
19 #include <Protocol/EmuThunk.h>
20
21 #include <Library/PeCoffLib.h>
22 #include <Library/PeiServicesLib.h>
23 #include <Library/DebugLib.h>
24 #include <Library/BaseLib.h>
25 #include <Library/PeCoffExtraActionLib.h>
26
27 //
28 // Cache of UnixThunk protocol
29 //
30 EMU_THUNK_PROTOCOL *mThunk = NULL;
31
32 /**
33 The function caches the pointer of the Unix thunk functions
34 It will ASSERT() if Unix thunk ppi is not installed.
35
36 @retval EFI_SUCCESS WinNT thunk protocol is found and cached.
37
38 **/
39 EFI_STATUS
40 EFIAPI
41 EmuPeCoffGetThunkStucture (
42 )
43 {
44 EMU_THUNK_PPI *ThunkPpi;
45 EFI_STATUS Status;
46
47
48 //
49 // Locate Unix ThunkPpi for retrieving standard output handle
50 //
51 Status = PeiServicesLocatePpi (
52 &gEmuThunkPpiGuid,
53 0,
54 NULL,
55 (VOID **) &ThunkPpi
56 );
57 ASSERT_EFI_ERROR (Status);
58
59 mThunk = (EMU_THUNK_PROTOCOL *) ThunkPpi->Thunk ();
60
61 return EFI_SUCCESS;
62 }
63
64 /**
65 Performs additional actions after a PE/COFF image has been loaded and relocated.
66
67 If ImageContext is NULL, then ASSERT().
68
69 @param ImageContext Pointer to the image context structure that describes the
70 PE/COFF image that has already been loaded and relocated.
71
72 **/
73 VOID
74 EFIAPI
75 PeCoffLoaderRelocateImageExtraAction (
76 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
77 )
78 {
79 if (mThunk == NULL) {
80 EmuPeCoffGetThunkStucture ();
81 }
82 mThunk->PeCoffRelocateImageExtraAction (ImageContext);
83 }
84
85
86 /**
87 Performs additional actions just before a PE/COFF image is unloaded. Any resources
88 that were allocated by PeCoffLoaderRelocateImageExtraAction() must be freed.
89
90 If ImageContext is NULL, then ASSERT().
91
92 @param ImageContext Pointer to the image context structure that describes the
93 PE/COFF image that is being unloaded.
94
95 **/
96 VOID
97 EFIAPI
98 PeCoffLoaderUnloadImageExtraAction (
99 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
100 )
101 {
102 if (mThunk == NULL) {
103 EmuPeCoffGetThunkStucture ();
104 }
105 mThunk->PeCoffUnloadImageExtraAction (ImageContext);
106 }