DxeEmuPeCoffExtraActionLib.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 DXE 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 <PiDxe.h>
  10. #include <Protocol/EmuThunk.h>
  11. #include <Library/PeCoffLib.h>
  12. #include <Library/BaseLib.h>
  13. #include <Library/DebugLib.h>
  14. #include <Library/HobLib.h>
  15. #include <Library/BaseMemoryLib.h>
  16. #include <Library/PeCoffExtraActionLib.h>
  17. //
  18. // Cache of UnixThunk protocol
  19. //
  20. EMU_THUNK_PROTOCOL *mThunk = NULL;
  21. /**
  22. The constructor function gets the pointer of the WinNT thunk functions
  23. It will ASSERT() if Unix thunk protocol is not installed.
  24. @retval EFI_SUCCESS Unix thunk protocol is found and cached.
  25. **/
  26. EFI_STATUS
  27. EFIAPI
  28. DxeEmuPeCoffLibExtraActionConstructor (
  29. IN EFI_HANDLE ImageHandle,
  30. IN EFI_SYSTEM_TABLE *SystemTable
  31. )
  32. {
  33. EFI_HOB_GUID_TYPE *GuidHob;
  34. //
  35. // Retrieve EmuThunkProtocol from GUID'ed HOB
  36. //
  37. GuidHob = GetFirstGuidHob (&gEmuThunkProtocolGuid);
  38. ASSERT (GuidHob != NULL);
  39. mThunk = (EMU_THUNK_PROTOCOL *)(*(UINTN *)(GET_GUID_HOB_DATA (GuidHob)));
  40. ASSERT (mThunk != NULL);
  41. return EFI_SUCCESS;
  42. }
  43. /**
  44. Performs additional actions after a PE/COFF image has been loaded and relocated.
  45. If ImageContext is NULL, then ASSERT().
  46. @param ImageContext Pointer to the image context structure that describes the
  47. PE/COFF image that has already been loaded and relocated.
  48. **/
  49. VOID
  50. EFIAPI
  51. PeCoffLoaderRelocateImageExtraAction (
  52. IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
  53. )
  54. {
  55. if (mThunk != NULL) {
  56. mThunk->PeCoffRelocateImageExtraAction (ImageContext);
  57. }
  58. }
  59. /**
  60. Performs additional actions just before a PE/COFF image is unloaded. Any resources
  61. that were allocated by PeCoffLoaderRelocateImageExtraAction() must be freed.
  62. If ImageContext is NULL, then ASSERT().
  63. @param ImageContext Pointer to the image context structure that describes the
  64. PE/COFF image that is being unloaded.
  65. **/
  66. VOID
  67. EFIAPI
  68. PeCoffLoaderUnloadImageExtraAction (
  69. IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
  70. )
  71. {
  72. if (mThunk != NULL) {
  73. mThunk->PeCoffUnloadImageExtraAction (ImageContext);
  74. }
  75. }