]>
Commit | Line | Data |
---|---|---|
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 | |
6 | Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r | |
7 | Portions copyright (c) 2008 - 2011, Apple Inc. All rights reserved.<BR>\r | |
8 | This program and the accompanying materials\r | |
9 | are licensed and made available under the terms and conditions of the BSD License\r | |
10 | which accompanies this distribution. The full text of the license may be found at\r | |
11 | http://opensource.org/licenses/bsd-license.php\r | |
12 | \r | |
13 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
14 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
15 | \r | |
16 | **/\r | |
17 | #include <PiPei.h>\r | |
18 | #include <Ppi/EmuThunk.h>\r | |
19 | #include <Protocol/EmuThunk.h>\r | |
20 | \r | |
21 | #include <Library/PeCoffLib.h>\r | |
22 | #include <Library/PeiServicesLib.h>\r | |
23 | #include <Library/DebugLib.h>\r | |
24 | #include <Library/BaseLib.h>\r | |
25 | #include <Library/PeCoffExtraActionLib.h>\r | |
946bfba2 | 26 | #include <Library/EmuMagicPageLib.h>\r |
949f388f | 27 | \r |
28 | //\r | |
d18d8a1d | 29 | // Cache of UnixThunk protocol\r |
949f388f | 30 | //\r |
31 | EMU_THUNK_PROTOCOL *mThunk = NULL;\r | |
32 | \r | |
33 | /**\r | |
34 | The function caches the pointer of the Unix thunk functions\r | |
35 | It will ASSERT() if Unix thunk ppi is not installed.\r | |
36 | \r | |
37 | @retval EFI_SUCCESS WinNT thunk protocol is found and cached.\r | |
38 | \r | |
39 | **/\r | |
40 | EFI_STATUS\r | |
41 | EFIAPI\r | |
42 | EmuPeCoffGetThunkStucture (\r | |
43 | )\r | |
44 | {\r | |
45 | EMU_THUNK_PPI *ThunkPpi;\r | |
46 | EFI_STATUS Status;\r | |
47 | \r | |
d18d8a1d | 48 | \r |
949f388f | 49 | //\r |
50 | // Locate Unix ThunkPpi for retrieving standard output handle\r | |
51 | //\r | |
52 | Status = PeiServicesLocatePpi (\r | |
53 | &gEmuThunkPpiGuid,\r | |
54 | 0,\r | |
55 | NULL,\r | |
56 | (VOID **) &ThunkPpi\r | |
57 | );\r | |
58 | ASSERT_EFI_ERROR (Status);\r | |
59 | \r | |
946bfba2 | 60 | EMU_MAGIC_PAGE()->Thunk = (EMU_THUNK_PROTOCOL *) ThunkPpi->Thunk ();\r |
949f388f | 61 | \r |
62 | return EFI_SUCCESS;\r | |
63 | }\r | |
64 | \r | |
65 | /**\r | |
66 | Performs additional actions after a PE/COFF image has been loaded and relocated.\r | |
67 | \r | |
68 | If ImageContext is NULL, then ASSERT().\r | |
69 | \r | |
70 | @param ImageContext Pointer to the image context structure that describes the\r | |
71 | PE/COFF image that has already been loaded and relocated.\r | |
72 | \r | |
73 | **/\r | |
74 | VOID\r | |
75 | EFIAPI\r | |
76 | PeCoffLoaderRelocateImageExtraAction (\r | |
77 | IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r | |
78 | )\r | |
79 | {\r | |
946bfba2 | 80 | if (EMU_MAGIC_PAGE()->Thunk == NULL) {\r |
949f388f | 81 | EmuPeCoffGetThunkStucture ();\r |
82 | }\r | |
946bfba2 | 83 | EMU_MAGIC_PAGE()->Thunk->PeCoffRelocateImageExtraAction (ImageContext);\r |
949f388f | 84 | }\r |
85 | \r | |
86 | \r | |
87 | /**\r | |
88 | Performs additional actions just before a PE/COFF image is unloaded. Any resources\r | |
89 | that were allocated by PeCoffLoaderRelocateImageExtraAction() must be freed.\r | |
d18d8a1d | 90 | \r |
949f388f | 91 | If ImageContext is NULL, then ASSERT().\r |
d18d8a1d | 92 | \r |
949f388f | 93 | @param ImageContext Pointer to the image context structure that describes the\r |
94 | PE/COFF image that is being unloaded.\r | |
95 | \r | |
96 | **/\r | |
97 | VOID\r | |
98 | EFIAPI\r | |
99 | PeCoffLoaderUnloadImageExtraAction (\r | |
100 | IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r | |
101 | )\r | |
102 | {\r | |
946bfba2 | 103 | if (EMU_MAGIC_PAGE()->Thunk == NULL) {\r |
949f388f | 104 | EmuPeCoffGetThunkStucture ();\r |
105 | }\r | |
946bfba2 | 106 | EMU_MAGIC_PAGE()->Thunk->PeCoffUnloadImageExtraAction (ImageContext);\r |
949f388f | 107 | }\r |