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 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
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.
18 #include <Ppi/EmuThunk.h>
19 #include <Protocol/EmuThunk.h>
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>
29 // Cache of UnixThunk protocol
31 EMU_THUNK_PROTOCOL
*mThunk
= NULL
;
34 The function caches the pointer of the Unix thunk functions
35 It will ASSERT() if Unix thunk ppi is not installed.
37 @retval EFI_SUCCESS WinNT thunk protocol is found and cached.
42 EmuPeCoffGetThunkStucture (
45 EMU_THUNK_PPI
*ThunkPpi
;
50 // Locate Unix ThunkPpi for retrieving standard output handle
52 Status
= PeiServicesLocatePpi (
58 ASSERT_EFI_ERROR (Status
);
60 EMU_MAGIC_PAGE()->Thunk
= (EMU_THUNK_PROTOCOL
*) ThunkPpi
->Thunk ();
66 Performs additional actions after a PE/COFF image has been loaded and relocated.
68 If ImageContext is NULL, then ASSERT().
70 @param ImageContext Pointer to the image context structure that describes the
71 PE/COFF image that has already been loaded and relocated.
76 PeCoffLoaderRelocateImageExtraAction (
77 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
80 if (EMU_MAGIC_PAGE()->Thunk
== NULL
) {
81 EmuPeCoffGetThunkStucture ();
83 EMU_MAGIC_PAGE()->Thunk
->PeCoffRelocateImageExtraAction (ImageContext
);
88 Performs additional actions just before a PE/COFF image is unloaded. Any resources
89 that were allocated by PeCoffLoaderRelocateImageExtraAction() must be freed.
91 If ImageContext is NULL, then ASSERT().
93 @param ImageContext Pointer to the image context structure that describes the
94 PE/COFF image that is being unloaded.
99 PeCoffLoaderUnloadImageExtraAction (
100 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
103 if (EMU_MAGIC_PAGE()->Thunk
== NULL
) {
104 EmuPeCoffGetThunkStucture ();
106 EMU_MAGIC_PAGE()->Thunk
->PeCoffUnloadImageExtraAction (ImageContext
);