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