PeiEmuPeCoffExtraActionLib.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /** @file
  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
  5. Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>
  6. Portions copyright (c) 2008 - 2011, Apple Inc. All rights reserved.<BR>
  7. SPDX-License-Identifier: BSD-2-Clause-Patent
  8. **/
  9. #include <PiPei.h>
  10. #include <Ppi/EmuThunk.h>
  11. #include <Protocol/EmuThunk.h>
  12. #include <Library/PeCoffLib.h>
  13. #include <Library/PeiServicesLib.h>
  14. #include <Library/DebugLib.h>
  15. #include <Library/BaseLib.h>
  16. #include <Library/PeCoffExtraActionLib.h>
  17. #include <Library/EmuMagicPageLib.h>
  18. //
  19. // Cache of UnixThunk protocol
  20. //
  21. EMU_THUNK_PROTOCOL *mThunk = NULL;
  22. /**
  23. The function caches the pointer of the Unix thunk functions
  24. It will ASSERT() if Unix thunk ppi is not installed.
  25. @retval EFI_SUCCESS WinNT thunk protocol is found and cached.
  26. **/
  27. EFI_STATUS
  28. EFIAPI
  29. EmuPeCoffGetThunkStucture (
  30. )
  31. {
  32. EMU_THUNK_PPI *ThunkPpi;
  33. EFI_STATUS Status;
  34. //
  35. // Locate Unix ThunkPpi for retrieving standard output handle
  36. //
  37. Status = PeiServicesLocatePpi (
  38. &gEmuThunkPpiGuid,
  39. 0,
  40. NULL,
  41. (VOID **)&ThunkPpi
  42. );
  43. ASSERT_EFI_ERROR (Status);
  44. EMU_MAGIC_PAGE ()->Thunk = (EMU_THUNK_PROTOCOL *)ThunkPpi->Thunk ();
  45. return EFI_SUCCESS;
  46. }
  47. /**
  48. Performs additional actions after a PE/COFF image has been loaded and relocated.
  49. If ImageContext is NULL, then ASSERT().
  50. @param ImageContext Pointer to the image context structure that describes the
  51. PE/COFF image that has already been loaded and relocated.
  52. **/
  53. VOID
  54. EFIAPI
  55. PeCoffLoaderRelocateImageExtraAction (
  56. IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
  57. )
  58. {
  59. if (EMU_MAGIC_PAGE ()->Thunk == NULL) {
  60. EmuPeCoffGetThunkStucture ();
  61. }
  62. EMU_MAGIC_PAGE ()->Thunk->PeCoffRelocateImageExtraAction (ImageContext);
  63. }
  64. /**
  65. Performs additional actions just before a PE/COFF image is unloaded. Any resources
  66. that were allocated by PeCoffLoaderRelocateImageExtraAction() must be freed.
  67. If ImageContext is NULL, then ASSERT().
  68. @param ImageContext Pointer to the image context structure that describes the
  69. PE/COFF image that is being unloaded.
  70. **/
  71. VOID
  72. EFIAPI
  73. PeCoffLoaderUnloadImageExtraAction (
  74. IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
  75. )
  76. {
  77. if (EMU_MAGIC_PAGE ()->Thunk == NULL) {
  78. EmuPeCoffGetThunkStucture ();
  79. }
  80. EMU_MAGIC_PAGE ()->Thunk->PeCoffUnloadImageExtraAction (ImageContext);
  81. }