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