[edk2-devel][Patch 3/3] MdePkg/UefiDebugLibStdErr: Add destructor to CloseEvent

Xu, Wei6 wei6.xu at intel.com
Fri Jul 26 03:10:55 UTC 2019


REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2012

When driver is unloaded, the ExitBootSerivesEvent must be closed at
the same time. Otherwise exception will occur when ExitBootServices.

Cc: Michael D Kinney <michael.d.kinney at intel.com>
Cc: Liming Gao <liming.gao at intel.com>
Signed-off-by: Wei6 Xu <wei6.xu at intel.com>
---
 .../UefiDebugLibStdErr/DebugLibConstructor.c       | 23 ++++++++++++++++++++++
 .../UefiDebugLibStdErr/UefiDebugLibStdErr.inf      |  1 +
 2 files changed, 24 insertions(+)

diff --git a/MdePkg/Library/UefiDebugLibStdErr/DebugLibConstructor.c b/MdePkg/Library/UefiDebugLibStdErr/DebugLibConstructor.c
index 8005370372..ed73f92818 100644
--- a/MdePkg/Library/UefiDebugLibStdErr/DebugLibConstructor.c
+++ b/MdePkg/Library/UefiDebugLibStdErr/DebugLibConstructor.c
@@ -73,5 +73,28 @@ DxeDebugLibConstructor(
                                 &mExitBootServicesEvent
                                 );
 
   return EFI_SUCCESS;
 }
+
+/**
+  The destructor closes Exit Boot Services Event.
+
+  @param  ImageHandle   The firmware allocated handle for the EFI image.
+  @param  SystemTable   A pointer to the EFI System Table.
+
+  @retval EFI_SUCCESS   The destructor always returns EFI_SUCCESS.
+
+**/
+EFI_STATUS
+EFIAPI
+DxeDebugLibDestructor(
+  IN EFI_HANDLE                 ImageHandle,
+  IN EFI_SYSTEM_TABLE           *SystemTable
+  )
+{
+  if (mExitBootServicesEvent != NULL) {
+    SystemTable->BootServices->CloseEvent (mExitBootServicesEvent);
+  }
+
+  return EFI_SUCCESS;
+}
diff --git a/MdePkg/Library/UefiDebugLibStdErr/UefiDebugLibStdErr.inf b/MdePkg/Library/UefiDebugLibStdErr/UefiDebugLibStdErr.inf
index deaa3427f6..11f7594626 100644
--- a/MdePkg/Library/UefiDebugLibStdErr/UefiDebugLibStdErr.inf
+++ b/MdePkg/Library/UefiDebugLibStdErr/UefiDebugLibStdErr.inf
@@ -20,10 +20,11 @@
   MODULE_TYPE                    = UEFI_DRIVER
   VERSION_STRING                 = 1.0
   LIBRARY_CLASS                  = DebugLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER UEFI_APPLICATION UEFI_DRIVER
 
   CONSTRUCTOR                    = DxeDebugLibConstructor
+  DESTRUCTOR                     = DxeDebugLibDestructor
 
 #
 #  VALID_ARCHITECTURES           = IA32 X64 EBC
 #
 
-- 
2.16.2.windows.1


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#44435): https://edk2.groups.io/g/devel/message/44435
Mute This Topic: https://groups.io/mt/32605741/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-




More information about the edk2-devel-archive mailing list