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
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
12 #include <Ppi/EmuThunk.h>
13 #include <Protocol/EmuThunk.h>
15 #include <Library/PeCoffLib.h>
16 #include <Library/PeiServicesLib.h>
17 #include <Library/DebugLib.h>
18 #include <Library/BaseLib.h>
19 #include <Library/PeCoffExtraActionLib.h>
20 #include <Library/EmuMagicPageLib.h>
23 // Cache of UnixThunk protocol
25 EMU_THUNK_PROTOCOL
*mThunk
= NULL
;
28 The function caches the pointer of the Unix thunk functions
29 It will ASSERT() if Unix thunk ppi is not installed.
31 @retval EFI_SUCCESS WinNT thunk protocol is found and cached.
36 EmuPeCoffGetThunkStucture (
39 EMU_THUNK_PPI
*ThunkPpi
;
44 // Locate Unix ThunkPpi for retrieving standard output handle
46 Status
= PeiServicesLocatePpi (
52 ASSERT_EFI_ERROR (Status
);
54 EMU_MAGIC_PAGE()->Thunk
= (EMU_THUNK_PROTOCOL
*) ThunkPpi
->Thunk ();
60 Performs additional actions after a PE/COFF image has been loaded and relocated.
62 If ImageContext is NULL, then ASSERT().
64 @param ImageContext Pointer to the image context structure that describes the
65 PE/COFF image that has already been loaded and relocated.
70 PeCoffLoaderRelocateImageExtraAction (
71 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
74 if (EMU_MAGIC_PAGE()->Thunk
== NULL
) {
75 EmuPeCoffGetThunkStucture ();
77 EMU_MAGIC_PAGE()->Thunk
->PeCoffRelocateImageExtraAction (ImageContext
);
82 Performs additional actions just before a PE/COFF image is unloaded. Any resources
83 that were allocated by PeCoffLoaderRelocateImageExtraAction() must be freed.
85 If ImageContext is NULL, then ASSERT().
87 @param ImageContext Pointer to the image context structure that describes the
88 PE/COFF image that is being unloaded.
93 PeCoffLoaderUnloadImageExtraAction (
94 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
97 if (EMU_MAGIC_PAGE()->Thunk
== NULL
) {
98 EmuPeCoffGetThunkStucture ();
100 EMU_MAGIC_PAGE()->Thunk
->PeCoffUnloadImageExtraAction (ImageContext
);