Re: [edk2] [PATCH 1/2] MdeModulePkg/CapsuleLib: Add lib destructors to handle unclosed events

2017-03-09 Thread Yao, Jiewen
Reviewed-by: jiewen@intel.com

> -Original Message-
> From: Wu, Hao A
> Sent: Friday, March 10, 2017 2:07 PM
> To: edk2-devel@lists.01.org
> Cc: Wu, Hao A ; Yao, Jiewen 
> Subject: [PATCH 1/2] MdeModulePkg/CapsuleLib: Add lib destructors to handle
> unclosed events
> 
> Cc: Jiewen Yao 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Hao Wu 
> ---
>  MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c  | 37
> +---
>  MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.inf|  3 +-
>  MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleRuntime.c  | 33
> ++---
>  MdeModulePkg/Library/DxeCapsuleLibFmp/DxeRuntimeCapsuleLib.inf |  4
> ++-
>  4 files changed, 66 insertions(+), 11 deletions(-)
> 
> diff --git a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c
> b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c
> index 7f500a96eb..a892892ccd 100644
> --- a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c
> +++ b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c
> @@ -47,9 +47,11 @@
>  #include 
>  #include 
> 
> -EFI_SYSTEM_RESOURCE_TABLE *mEsrtTable  = NULL;
> -BOOLEAN   mIsVirtualAddrConverted  = FALSE;
> -BOOLEAN   mDxeCapsuleLibEndOfDxe   = FALSE;
> +EFI_SYSTEM_RESOURCE_TABLE *mEsrtTable
> = NULL;
> +BOOLEAN   mIsVirtualAddrConverted
> = FALSE;
> +BOOLEAN   mDxeCapsuleLibEndOfDxe
> = FALSE;
> +EFI_EVENT mDxeCapsuleLibEndOfDxeEvent
> = NULL;
> +EFI_EVENT
> mDxeRuntimeCapsuleLibVirtualAddressChangeEvent  = NULL;
> 
>  /**
>Initialize capsule related variables.
> @@ -1654,7 +1656,6 @@ DxeCapsuleLibConstructor (
>IN EFI_SYSTEM_TABLE   *SystemTable
>)
>  {
> -  EFI_EVENT EndOfDxeEvent;
>EFI_STATUSStatus;
> 
>Status = gBS->CreateEventEx (
> @@ -1663,7 +1664,7 @@ DxeCapsuleLibConstructor (
>DxeCapsuleLibEndOfDxe,
>NULL,
>,
> -  
> +  
>);
>ASSERT_EFI_ERROR (Status);
> 
> @@ -1671,3 +1672,29 @@ DxeCapsuleLibConstructor (
> 
>return EFI_SUCCESS;
>  }
> +
> +/**
> +  The destructor function closes the End of DXE 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 completed successfully.
> +**/
> +EFI_STATUS
> +EFIAPI
> +DxeCapsuleLibDestructor (
> +  IN EFI_HANDLE ImageHandle,
> +  IN EFI_SYSTEM_TABLE   *SystemTable
> +  )
> +{
> +  EFI_STATUSStatus;
> +
> +  //
> +  // Close the End of DXE event.
> +  //
> +  Status = gBS->CloseEvent (mDxeCapsuleLibEndOfDxeEvent);
> +  ASSERT_EFI_ERROR (Status);
> +
> +  return EFI_SUCCESS;
> +}
> diff --git a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.inf
> b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.inf
> index 5e437dc418..a6cf54cb6b 100644
> --- a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.inf
> +++ b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.inf
> @@ -3,7 +3,7 @@
>  #
>  #  Capsule library instance for DXE_DRIVER module types.
>  #
> -#  Copyright (c) 2016, Intel Corporation. All rights reserved.
> +#  Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.
>  #  This program and the accompanying materials
>  #  are licensed and made available under the terms and conditions of the BSD
> License
>  #  which accompanies this distribution.  The full text of the license may be
> found at
> @@ -23,6 +23,7 @@
>VERSION_STRING = 1.0
>LIBRARY_CLASS  = CapsuleLib|DXE_DRIVER
> UEFI_APPLICATION
>CONSTRUCTOR= DxeCapsuleLibConstructor
> +  DESTRUCTOR = DxeCapsuleLibDestructor
> 
>  #
>  # The following information is for reference only and not required by the 
> build
> tools.
> diff --git a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleRuntime.c
> b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleRuntime.c
> index 880143905a..513aa533e1 100644
> --- a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleRuntime.c
> +++ b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleRuntime.c
> @@ -1,7 +1,7 @@
>  /** @file
>Capsule library runtime support.
> 
> -  Copyright (c) 2016, Intel Corporation. All rights reserved.
> +  Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.
>This program and the accompanying materials
>are licensed and made available under the terms and conditions of the BSD
> License
>which accompanies this distribution.  The full text of the license may be
> found at
> @@ -28,6 +28,7 @@
> 
>  extern EFI_SYSTEM_RESOURCE_TABLE *mEsrtTable;
>  extern BOOLEAN   mIsVirtualAddrConverted;
> +extern EFI_EVENT
> 

[edk2] [PATCH 1/2] MdeModulePkg/CapsuleLib: Add lib destructors to handle unclosed events

2017-03-09 Thread Hao Wu
Cc: Jiewen Yao 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hao Wu 
---
 MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c  | 37 
+---
 MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.inf|  3 +-
 MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleRuntime.c  | 33 
++---
 MdeModulePkg/Library/DxeCapsuleLibFmp/DxeRuntimeCapsuleLib.inf |  4 ++-
 4 files changed, 66 insertions(+), 11 deletions(-)

diff --git a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c 
b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c
index 7f500a96eb..a892892ccd 100644
--- a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c
+++ b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c
@@ -47,9 +47,11 @@
 #include 
 #include 
 
-EFI_SYSTEM_RESOURCE_TABLE *mEsrtTable  = NULL;
-BOOLEAN   mIsVirtualAddrConverted  = FALSE;
-BOOLEAN   mDxeCapsuleLibEndOfDxe   = FALSE;
+EFI_SYSTEM_RESOURCE_TABLE *mEsrtTable = 
NULL;
+BOOLEAN   mIsVirtualAddrConverted = 
FALSE;
+BOOLEAN   mDxeCapsuleLibEndOfDxe  = 
FALSE;
+EFI_EVENT mDxeCapsuleLibEndOfDxeEvent = 
NULL;
+EFI_EVENT mDxeRuntimeCapsuleLibVirtualAddressChangeEvent  = 
NULL;
 
 /**
   Initialize capsule related variables.
@@ -1654,7 +1656,6 @@ DxeCapsuleLibConstructor (
   IN EFI_SYSTEM_TABLE   *SystemTable
   )
 {
-  EFI_EVENT EndOfDxeEvent;
   EFI_STATUSStatus;
 
   Status = gBS->CreateEventEx (
@@ -1663,7 +1664,7 @@ DxeCapsuleLibConstructor (
   DxeCapsuleLibEndOfDxe,
   NULL,
   ,
-  
+  
   );
   ASSERT_EFI_ERROR (Status);
 
@@ -1671,3 +1672,29 @@ DxeCapsuleLibConstructor (
 
   return EFI_SUCCESS;
 }
+
+/**
+  The destructor function closes the End of DXE 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 completed successfully.
+**/
+EFI_STATUS
+EFIAPI
+DxeCapsuleLibDestructor (
+  IN EFI_HANDLE ImageHandle,
+  IN EFI_SYSTEM_TABLE   *SystemTable
+  )
+{
+  EFI_STATUSStatus;
+
+  //
+  // Close the End of DXE event.
+  //
+  Status = gBS->CloseEvent (mDxeCapsuleLibEndOfDxeEvent);
+  ASSERT_EFI_ERROR (Status);
+
+  return EFI_SUCCESS;
+}
diff --git a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.inf 
b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.inf
index 5e437dc418..a6cf54cb6b 100644
--- a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.inf
+++ b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.inf
@@ -3,7 +3,7 @@
 #
 #  Capsule library instance for DXE_DRIVER module types.
 #
-#  Copyright (c) 2016, Intel Corporation. All rights reserved.
+#  Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.
 #  This program and the accompanying materials
 #  are licensed and made available under the terms and conditions of the BSD 
License
 #  which accompanies this distribution.  The full text of the license may be 
found at
@@ -23,6 +23,7 @@
   VERSION_STRING = 1.0
   LIBRARY_CLASS  = CapsuleLib|DXE_DRIVER UEFI_APPLICATION
   CONSTRUCTOR= DxeCapsuleLibConstructor
+  DESTRUCTOR = DxeCapsuleLibDestructor
 
 #
 # The following information is for reference only and not required by the 
build tools.
diff --git a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleRuntime.c 
b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleRuntime.c
index 880143905a..513aa533e1 100644
--- a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleRuntime.c
+++ b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleRuntime.c
@@ -1,7 +1,7 @@
 /** @file
   Capsule library runtime support.
 
-  Copyright (c) 2016, Intel Corporation. All rights reserved.
+  Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD 
License
   which accompanies this distribution.  The full text of the license may be 
found at
@@ -28,6 +28,7 @@
 
 extern EFI_SYSTEM_RESOURCE_TABLE *mEsrtTable;
 extern BOOLEAN   mIsVirtualAddrConverted;
+extern EFI_EVENT 
mDxeRuntimeCapsuleLibVirtualAddressChangeEvent;
 
 /**
   Convert EsrtTable physical address to virtual address.
@@ -92,21 +93,45 @@ DxeRuntimeCapsuleLibConstructor (
   )
 {
   EFI_STATUS Status;
-  EFI_EVENT  Event;
 
   //
   // Make sure we can handle virtual address changes.
   //
-  Event = NULL;
   Status = gBS->CreateEventEx (
   EVT_NOTIFY_SIGNAL,
   TPL_NOTIFY,