changed %s to %a to print correct ascii string.
[edk2.git] / UnixPkg / Library / PeiUnixPeCoffExtraActionLib / PeiUnixPeCoffExtraActionLib.c
blob579553c4e3ead4a6efd49f4b34258d44c87c7ce7
1 /**@file
3 Copyright (c) 2006 - 2009, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 Module Name:
14 PeiUnixPeCoffExtraActionLib.c
16 Abstract:
18 Provides services to perform additional actions to relocate and unload
19 PE/Coff image for UNIX environment specific purpose such as souce level debug.
20 This version only works for PEI phase
23 **/
24 #include <PiPei.h>
25 #include <Ppi/UnixThunk.h>
26 #include <FrameworkModuleBase.h>
28 #include <Library/PeCoffLib.h>
29 #include <Library/PeiServicesLib.h>
30 #include <Library/DebugLib.h>
31 #include <Library/BaseLib.h>
32 #include <Library/PeCoffExtraActionLib.h>
35 // Cache of UnixThunk protocol
37 EFI_UNIX_THUNK_PROTOCOL *mUnix = NULL;
39 /**
40 The function caches the pointer of the WinNT thunk functions
41 It will ASSERT() if Unix thunk ppi is not installed.
43 @retval EFI_SUCCESS WinNT thunk protocol is found and cached.
45 **/
46 EFI_STATUS
47 EFIAPI
48 UnixPeCoffGetUnixThunkStucture (
51 PEI_UNIX_THUNK_PPI *UnixThunkPpi;
52 EFI_STATUS Status;
56 // Locate Unix ThunkPpi for retrieving standard output handle
58 Status = PeiServicesLocatePpi (
59 &gPeiUnixThunkPpiGuid,
61 NULL,
62 (VOID **) &UnixThunkPpi
65 ASSERT_EFI_ERROR (Status);
67 mUnix = (EFI_UNIX_THUNK_PROTOCOL *) UnixThunkPpi->UnixThunk ();
69 return EFI_SUCCESS;
72 /**
73 Performs additional actions after a PE/COFF image has been loaded and relocated.
75 If ImageContext is NULL, then ASSERT().
77 @param ImageContext Pointer to the image context structure that describes the
78 PE/COFF image that has already been loaded and relocated.
80 **/
81 VOID
82 EFIAPI
83 PeCoffLoaderRelocateImageExtraAction (
84 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
87 VOID * Handle;
88 VOID * Entry;
90 ASSERT (ImageContext != NULL);
92 Handle = NULL;
93 Entry = NULL;
95 if (mUnix == NULL) {
96 UnixPeCoffGetUnixThunkStucture ();
98 DEBUG ((EFI_D_ERROR, "Loading %a 0x%08lx - entry point 0x%08lx\n",
99 ImageContext->PdbPointer,
100 (UINTN)ImageContext->ImageAddress,
101 (UINTN)ImageContext->EntryPoint));
103 Handle = mUnix->Dlopen (ImageContext->PdbPointer, RTLD_NOW);
105 if (Handle) {
106 Entry = mUnix->Dlsym(Handle, "_ModuleEntryPoint");
107 } else {
108 DEBUG ((EFI_D_ERROR, "%a\n", mUnix->Dlerror()));
111 if (Entry != NULL) {
112 ImageContext->EntryPoint = Entry;
113 DEBUG ((EFI_D_ERROR, "Change %a Entrypoint to :0x%08lx\n", ImageContext->PdbPointer, Entry));
117 return;
121 Performs additional actions just before a PE/COFF image is unloaded. Any resources
122 that were allocated by PeCoffLoaderRelocateImageExtraAction() must be freed.
124 If ImageContext is NULL, then ASSERT().
126 @param ImageContext Pointer to the image context structure that describes the
127 PE/COFF image that is being unloaded.
130 VOID
131 EFIAPI
132 PeCoffLoaderUnloadImageExtraAction (
133 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
136 ASSERT (ImageContext != NULL);