]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleRuntime.c
MdeModulePkg/CapsuleLib: Add lib destructors to handle unclosed events
[mirror_edk2.git] / MdeModulePkg / Library / DxeCapsuleLibFmp / DxeCapsuleRuntime.c
index 880143905aa1f358b478d841e30dcd98a1fb1ee4..4725d531462cef7f5df9c8246d17e8e568055afb 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Capsule library runtime support.\r
 \r
-  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -26,8 +26,9 @@
 #include <Library/UefiRuntimeServicesTableLib.h>\r
 #include <Library/MemoryAllocationLib.h>\r
 \r
-extern EFI_SYSTEM_RESOURCE_TABLE *mEsrtTable;\r
-extern BOOLEAN                   mIsVirtualAddrConverted;\r
+EFI_SYSTEM_RESOURCE_TABLE *mEsrtTable                                     = NULL;\r
+BOOLEAN                   mIsVirtualAddrConverted                         = FALSE;\r
+EFI_EVENT                 mDxeRuntimeCapsuleLibVirtualAddressChangeEvent  = NULL;\r
 \r
 /**\r
   Convert EsrtTable physical address to virtual address.\r
@@ -92,21 +93,45 @@ DxeRuntimeCapsuleLibConstructor (
   )\r
 {\r
   EFI_STATUS     Status;\r
-  EFI_EVENT      Event;\r
 \r
   //\r
   // Make sure we can handle virtual address changes.\r
   //\r
-  Event = NULL;\r
   Status = gBS->CreateEventEx (\r
                   EVT_NOTIFY_SIGNAL,\r
                   TPL_NOTIFY,\r
                   DxeCapsuleLibVirtualAddressChangeEvent,\r
                   NULL,\r
                   &gEfiEventVirtualAddressChangeGuid,\r
-                  &Event\r
+                  &mDxeRuntimeCapsuleLibVirtualAddressChangeEvent\r
                   );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
   return EFI_SUCCESS;\r
 }\r
+\r
+/**\r
+  The destructor function closes the VirtualAddressChange event.\r
+\r
+  @param  ImageHandle   The firmware allocated handle for the EFI image.\r
+  @param  SystemTable   A pointer to the EFI System Table.\r
+\r
+  @retval EFI_SUCCESS   The destructor completed successfully.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+DxeRuntimeCapsuleLibDestructor (\r
+  IN EFI_HANDLE         ImageHandle,\r
+  IN EFI_SYSTEM_TABLE   *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS    Status;\r
+\r
+  //\r
+  // Close the VirtualAddressChange event.\r
+  //\r
+  Status = gBS->CloseEvent (mDxeRuntimeCapsuleLibVirtualAddressChangeEvent);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return EFI_SUCCESS;\r
+}\r