* [edk2-devel][Patch 0/3] Add destructor to CloseEvent
@ 2019-07-26 3:10 Xu, Wei6
2019-07-26 3:10 ` [edk2-devel][Patch 1/3] MdePkg/UefiDebugLibConOut: " Xu, Wei6
` (3 more replies)
0 siblings, 4 replies; 9+ messages in thread
From: Xu, Wei6 @ 2019-07-26 3:10 UTC (permalink / raw)
To: devel; +Cc: Michael D Kinney, Liming Gao
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2012
This patch set adds missing destructor for following libraries:
MdePkg\Library\UefiDebugLibStdErr
MdePkg\Library\UefiDebugLibConOut
MdePkg\Library\UefiDebugLibDebugPortProtocol
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@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Wei6 Xu (3):
MdePkg/UefiDebugLibConOut: Add destructor to CloseEvent
MdePkg/UefiDebugLibDebugPortProtocol: Add destructor to CloseEvent
MdePkg/UefiDebugLibStdErr: Add destructor to CloseEvent
.../UefiDebugLibConOut/DebugLibConstructor.c | 23 ++++++++++++++++++++++
.../UefiDebugLibConOut/UefiDebugLibConOut.inf | 1 +
.../DebugLibConstructor.c | 23 ++++++++++++++++++++++
.../UefiDebugLibDebugPortProtocol.inf | 1 +
.../UefiDebugLibStdErr/DebugLibConstructor.c | 23 ++++++++++++++++++++++
.../UefiDebugLibStdErr/UefiDebugLibStdErr.inf | 1 +
6 files changed, 72 insertions(+)
--
2.16.2.windows.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* [edk2-devel][Patch 1/3] MdePkg/UefiDebugLibConOut: Add destructor to CloseEvent
2019-07-26 3:10 [edk2-devel][Patch 0/3] Add destructor to CloseEvent Xu, Wei6
@ 2019-07-26 3:10 ` Xu, Wei6
2019-07-29 14:38 ` Philippe Mathieu-Daudé
2019-07-26 3:10 ` [edk2-devel][Patch 2/3] MdePkg/UefiDebugLibDebugPortProtocol: " Xu, Wei6
` (2 subsequent siblings)
3 siblings, 1 reply; 9+ messages in thread
From: Xu, Wei6 @ 2019-07-26 3:10 UTC (permalink / raw)
To: devel; +Cc: Michael D Kinney, Liming Gao
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@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Signed-off-by: Wei6 Xu <wei6.xu@intel.com>
---
.../UefiDebugLibConOut/DebugLibConstructor.c | 23 ++++++++++++++++++++++
.../UefiDebugLibConOut/UefiDebugLibConOut.inf | 1 +
2 files changed, 24 insertions(+)
diff --git a/MdePkg/Library/UefiDebugLibConOut/DebugLibConstructor.c b/MdePkg/Library/UefiDebugLibConOut/DebugLibConstructor.c
index 8005370372..ed73f92818 100644
--- a/MdePkg/Library/UefiDebugLibConOut/DebugLibConstructor.c
+++ b/MdePkg/Library/UefiDebugLibConOut/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/UefiDebugLibConOut/UefiDebugLibConOut.inf b/MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf
index 4c279a5bf2..b577d52ac6 100644
--- a/MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf
+++ b/MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.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
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [edk2-devel][Patch 2/3] MdePkg/UefiDebugLibDebugPortProtocol: Add destructor to CloseEvent
2019-07-26 3:10 [edk2-devel][Patch 0/3] Add destructor to CloseEvent Xu, Wei6
2019-07-26 3:10 ` [edk2-devel][Patch 1/3] MdePkg/UefiDebugLibConOut: " Xu, Wei6
@ 2019-07-26 3:10 ` Xu, Wei6
2019-07-26 3:10 ` [edk2-devel][Patch 3/3] MdePkg/UefiDebugLibStdErr: " Xu, Wei6
2019-07-26 8:28 ` [edk2-devel][Patch 0/3] " Liming Gao
3 siblings, 0 replies; 9+ messages in thread
From: Xu, Wei6 @ 2019-07-26 3:10 UTC (permalink / raw)
To: devel; +Cc: Michael D Kinney, Liming Gao
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@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Signed-off-by: Wei6 Xu <wei6.xu@intel.com>
---
.../DebugLibConstructor.c | 23 ++++++++++++++++++++++
.../UefiDebugLibDebugPortProtocol.inf | 1 +
2 files changed, 24 insertions(+)
diff --git a/MdePkg/Library/UefiDebugLibDebugPortProtocol/DebugLibConstructor.c b/MdePkg/Library/UefiDebugLibDebugPortProtocol/DebugLibConstructor.c
index de60d339a8..6ea0912f2b 100644
--- a/MdePkg/Library/UefiDebugLibDebugPortProtocol/DebugLibConstructor.c
+++ b/MdePkg/Library/UefiDebugLibDebugPortProtocol/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/UefiDebugLibDebugPortProtocol/UefiDebugLibDebugPortProtocol.inf b/MdePkg/Library/UefiDebugLibDebugPortProtocol/UefiDebugLibDebugPortProtocol.inf
index 10a8f2a857..ff09a12ce4 100644
--- a/MdePkg/Library/UefiDebugLibDebugPortProtocol/UefiDebugLibDebugPortProtocol.inf
+++ b/MdePkg/Library/UefiDebugLibDebugPortProtocol/UefiDebugLibDebugPortProtocol.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
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [edk2-devel][Patch 3/3] MdePkg/UefiDebugLibStdErr: Add destructor to CloseEvent
2019-07-26 3:10 [edk2-devel][Patch 0/3] Add destructor to CloseEvent Xu, Wei6
2019-07-26 3:10 ` [edk2-devel][Patch 1/3] MdePkg/UefiDebugLibConOut: " Xu, Wei6
2019-07-26 3:10 ` [edk2-devel][Patch 2/3] MdePkg/UefiDebugLibDebugPortProtocol: " Xu, Wei6
@ 2019-07-26 3:10 ` Xu, Wei6
2019-07-26 8:28 ` [edk2-devel][Patch 0/3] " Liming Gao
3 siblings, 0 replies; 9+ messages in thread
From: Xu, Wei6 @ 2019-07-26 3:10 UTC (permalink / raw)
To: devel; +Cc: Michael D Kinney, Liming Gao
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@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Signed-off-by: Wei6 Xu <wei6.xu@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
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [edk2-devel][Patch 0/3] Add destructor to CloseEvent
2019-07-26 3:10 [edk2-devel][Patch 0/3] Add destructor to CloseEvent Xu, Wei6
` (2 preceding siblings ...)
2019-07-26 3:10 ` [edk2-devel][Patch 3/3] MdePkg/UefiDebugLibStdErr: " Xu, Wei6
@ 2019-07-26 8:28 ` Liming Gao
3 siblings, 0 replies; 9+ messages in thread
From: Liming Gao @ 2019-07-26 8:28 UTC (permalink / raw)
To: Xu, Wei6, devel@edk2.groups.io; +Cc: Kinney, Michael D
Thanks for your fix. The patch set is good.
Reviewed-by: Liming Gao <liming.gao@intel.com>
>-----Original Message-----
>From: Xu, Wei6
>Sent: Friday, July 26, 2019 11:11 AM
>To: devel@edk2.groups.io
>Cc: Kinney, Michael D <michael.d.kinney@intel.com>; Gao, Liming
><liming.gao@intel.com>
>Subject: [edk2-devel][Patch 0/3] Add destructor to CloseEvent
>
>REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2012
>
>This patch set adds missing destructor for following libraries:
>MdePkg\Library\UefiDebugLibStdErr
>MdePkg\Library\UefiDebugLibConOut
>MdePkg\Library\UefiDebugLibDebugPortProtocol
>
>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@intel.com>
>Cc: Liming Gao <liming.gao@intel.com>
>
>Wei6 Xu (3):
> MdePkg/UefiDebugLibConOut: Add destructor to CloseEvent
> MdePkg/UefiDebugLibDebugPortProtocol: Add destructor to CloseEvent
> MdePkg/UefiDebugLibStdErr: Add destructor to CloseEvent
>
> .../UefiDebugLibConOut/DebugLibConstructor.c | 23
>++++++++++++++++++++++
> .../UefiDebugLibConOut/UefiDebugLibConOut.inf | 1 +
> .../DebugLibConstructor.c | 23 ++++++++++++++++++++++
> .../UefiDebugLibDebugPortProtocol.inf | 1 +
> .../UefiDebugLibStdErr/DebugLibConstructor.c | 23
>++++++++++++++++++++++
> .../UefiDebugLibStdErr/UefiDebugLibStdErr.inf | 1 +
> 6 files changed, 72 insertions(+)
>
>--
>2.16.2.windows.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [edk2-devel][Patch 1/3] MdePkg/UefiDebugLibConOut: Add destructor to CloseEvent
2019-07-26 3:10 ` [edk2-devel][Patch 1/3] MdePkg/UefiDebugLibConOut: " Xu, Wei6
@ 2019-07-29 14:38 ` Philippe Mathieu-Daudé
2019-07-29 16:09 ` Laszlo Ersek
0 siblings, 1 reply; 9+ messages in thread
From: Philippe Mathieu-Daudé @ 2019-07-29 14:38 UTC (permalink / raw)
To: devel, wei6.xu; +Cc: Michael D Kinney, Liming Gao
Hi,
On 7/26/19 5:10 AM, Xu, Wei6 wrote:
> 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@intel.com>
> Cc: Liming Gao <liming.gao@intel.com>
> Signed-off-by: Wei6 Xu <wei6.xu@intel.com>
> ---
> .../UefiDebugLibConOut/DebugLibConstructor.c | 23 ++++++++++++++++++++++
> .../UefiDebugLibConOut/UefiDebugLibConOut.inf | 1 +
> 2 files changed, 24 insertions(+)
>
> diff --git a/MdePkg/Library/UefiDebugLibConOut/DebugLibConstructor.c b/MdePkg/Library/UefiDebugLibConOut/DebugLibConstructor.c
> index 8005370372..ed73f92818 100644
> --- a/MdePkg/Library/UefiDebugLibConOut/DebugLibConstructor.c
> +++ b/MdePkg/Library/UefiDebugLibConOut/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);
> + }
Is it OK to let mDebugST (pointer to SystemTable) initialized?
> +
> + return EFI_SUCCESS;
> +}
> diff --git a/MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf b/MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf
> index 4c279a5bf2..b577d52ac6 100644
> --- a/MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf
> +++ b/MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.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
> #
>
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [edk2-devel][Patch 1/3] MdePkg/UefiDebugLibConOut: Add destructor to CloseEvent
2019-07-29 14:38 ` Philippe Mathieu-Daudé
@ 2019-07-29 16:09 ` Laszlo Ersek
2019-07-29 17:48 ` Philippe Mathieu-Daudé
0 siblings, 1 reply; 9+ messages in thread
From: Laszlo Ersek @ 2019-07-29 16:09 UTC (permalink / raw)
To: devel, philmd, wei6.xu; +Cc: Michael D Kinney, Liming Gao
On 07/29/19 16:38, Philippe Mathieu-Daudé wrote:
> Hi,
>
> On 7/26/19 5:10 AM, Xu, Wei6 wrote:
>> 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@intel.com>
>> Cc: Liming Gao <liming.gao@intel.com>
>> Signed-off-by: Wei6 Xu <wei6.xu@intel.com>
>> ---
>> .../UefiDebugLibConOut/DebugLibConstructor.c | 23 ++++++++++++++++++++++
>> .../UefiDebugLibConOut/UefiDebugLibConOut.inf | 1 +
>> 2 files changed, 24 insertions(+)
>>
>> diff --git a/MdePkg/Library/UefiDebugLibConOut/DebugLibConstructor.c b/MdePkg/Library/UefiDebugLibConOut/DebugLibConstructor.c
>> index 8005370372..ed73f92818 100644
>> --- a/MdePkg/Library/UefiDebugLibConOut/DebugLibConstructor.c
>> +++ b/MdePkg/Library/UefiDebugLibConOut/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);
>> + }
>
> Is it OK to let mDebugST (pointer to SystemTable) initialized?
Yes, ignoring "mDebugST" in this function should be.
"mDebugST" is a global variable (= an object with file scope and static
storage duration) defined in
"MdePkg/Library/UefiDebugLibConOut/DebugLibConstructor.c".
The library instance (for which the destructor function is being added)
is linked into driver and application modules. The destructor function
is invoked whenever the driver or application is about to be unloaded
from memory. As part of the unloading, the ExitBootServices()
notification function -- which was automatically registered via the
constructor function when the driver or application started up -- must
be de-registered, otherwise the platform firmware will be left with a
dangling callback pointer. That's what the CloseEvent() above takes care
of. But it's OK to ignore "mDebugST" altogether, as the memory that
"mDebugST" lives inside is about to be reclaimed by the platform
firmware anyway.
The library destructor is invoked:
- when a UEFI application exits (with success or failure), by returning
from its entry point function, or by calling the Exit() boot service
- when a UEFI driver exits with failure (hence it will be unloaded
automatically)
- when a UEFI driver exited with success (hence staying resident), and
it supports unloading, and now another agent is unloading it with the
UnloadImage() boot service (such as the UEFI shell with the "unload"
command, IIRC).
Thanks
Laszlo
>
>> +
>> + return EFI_SUCCESS;
>> +}
>> diff --git a/MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf b/MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf
>> index 4c279a5bf2..b577d52ac6 100644
>> --- a/MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf
>> +++ b/MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.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
>> #
>>
>>
>
>
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [edk2-devel][Patch 1/3] MdePkg/UefiDebugLibConOut: Add destructor to CloseEvent
2019-07-29 16:09 ` Laszlo Ersek
@ 2019-07-29 17:48 ` Philippe Mathieu-Daudé
2019-07-30 1:17 ` Liming Gao
0 siblings, 1 reply; 9+ messages in thread
From: Philippe Mathieu-Daudé @ 2019-07-29 17:48 UTC (permalink / raw)
To: Laszlo Ersek, devel, wei6.xu; +Cc: Michael D Kinney, Liming Gao
On 7/29/19 6:09 PM, Laszlo Ersek wrote:
> On 07/29/19 16:38, Philippe Mathieu-Daudé wrote:
>> Hi,
>>
>> On 7/26/19 5:10 AM, Xu, Wei6 wrote:
>>> 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@intel.com>
>>> Cc: Liming Gao <liming.gao@intel.com>
>>> Signed-off-by: Wei6 Xu <wei6.xu@intel.com>
>>> ---
>>> .../UefiDebugLibConOut/DebugLibConstructor.c | 23 ++++++++++++++++++++++
>>> .../UefiDebugLibConOut/UefiDebugLibConOut.inf | 1 +
>>> 2 files changed, 24 insertions(+)
>>>
>>> diff --git a/MdePkg/Library/UefiDebugLibConOut/DebugLibConstructor.c b/MdePkg/Library/UefiDebugLibConOut/DebugLibConstructor.c
>>> index 8005370372..ed73f92818 100644
>>> --- a/MdePkg/Library/UefiDebugLibConOut/DebugLibConstructor.c
>>> +++ b/MdePkg/Library/UefiDebugLibConOut/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);
>>> + }
>>
>> Is it OK to let mDebugST (pointer to SystemTable) initialized?
>
> Yes, ignoring "mDebugST" in this function should be.
>
> "mDebugST" is a global variable (= an object with file scope and static
> storage duration) defined in
> "MdePkg/Library/UefiDebugLibConOut/DebugLibConstructor.c".
>
> The library instance (for which the destructor function is being added)
> is linked into driver and application modules. The destructor function
> is invoked whenever the driver or application is about to be unloaded
> from memory. As part of the unloading, the ExitBootServices()
> notification function -- which was automatically registered via the
> constructor function when the driver or application started up -- must
> be de-registered, otherwise the platform firmware will be left with a
> dangling callback pointer. That's what the CloseEvent() above takes care
> of. But it's OK to ignore "mDebugST" altogether, as the memory that
> "mDebugST" lives inside is about to be reclaimed by the platform
> firmware anyway.
>
> The library destructor is invoked:
> - when a UEFI application exits (with success or failure), by returning
> from its entry point function, or by calling the Exit() boot service
>
> - when a UEFI driver exits with failure (hence it will be unloaded
> automatically)
>
> - when a UEFI driver exited with success (hence staying resident), and
> it supports unloading, and now another agent is unloading it with the
> UnloadImage() boot service (such as the UEFI shell with the "unload"
> command, IIRC).
Thanks Laszlo for the explanations!
I noticed (late) this series is already pushed (commits
e92bdcb3ecbf..28bc6992400) so it doesn't require review anymore.
BTW Liming the author name seems incorrect: Wei6 Xu and Xu, Wei6.
>>> +
>>> + return EFI_SUCCESS;
>>> +}
>>> diff --git a/MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf b/MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf
>>> index 4c279a5bf2..b577d52ac6 100644
>>> --- a/MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf
>>> +++ b/MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.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
>>> #
>>>
>>>
>>
>>
>>
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [edk2-devel][Patch 1/3] MdePkg/UefiDebugLibConOut: Add destructor to CloseEvent
2019-07-29 17:48 ` Philippe Mathieu-Daudé
@ 2019-07-30 1:17 ` Liming Gao
0 siblings, 0 replies; 9+ messages in thread
From: Liming Gao @ 2019-07-30 1:17 UTC (permalink / raw)
To: devel@edk2.groups.io, philmd@redhat.com, Laszlo Ersek, Xu, Wei6
Cc: Kinney, Michael D
Philippe:
> -----Original Message-----
> From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of Philippe Mathieu-Daudé
> Sent: Tuesday, July 30, 2019 1:49 AM
> To: Laszlo Ersek <lersek@redhat.com>; devel@edk2.groups.io; Xu, Wei6 <wei6.xu@intel.com>
> Cc: Kinney, Michael D <michael.d.kinney@intel.com>; Gao, Liming <liming.gao@intel.com>
> Subject: Re: [edk2-devel][Patch 1/3] MdePkg/UefiDebugLibConOut: Add destructor to CloseEvent
>
> On 7/29/19 6:09 PM, Laszlo Ersek wrote:
> > On 07/29/19 16:38, Philippe Mathieu-Daudé wrote:
> >> Hi,
> >>
> >> On 7/26/19 5:10 AM, Xu, Wei6 wrote:
> >>> 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@intel.com>
> >>> Cc: Liming Gao <liming.gao@intel.com>
> >>> Signed-off-by: Wei6 Xu <wei6.xu@intel.com>
> >>> ---
> >>> .../UefiDebugLibConOut/DebugLibConstructor.c | 23 ++++++++++++++++++++++
> >>> .../UefiDebugLibConOut/UefiDebugLibConOut.inf | 1 +
> >>> 2 files changed, 24 insertions(+)
> >>>
> >>> diff --git a/MdePkg/Library/UefiDebugLibConOut/DebugLibConstructor.c
> b/MdePkg/Library/UefiDebugLibConOut/DebugLibConstructor.c
> >>> index 8005370372..ed73f92818 100644
> >>> --- a/MdePkg/Library/UefiDebugLibConOut/DebugLibConstructor.c
> >>> +++ b/MdePkg/Library/UefiDebugLibConOut/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);
> >>> + }
> >>
> >> Is it OK to let mDebugST (pointer to SystemTable) initialized?
> >
> > Yes, ignoring "mDebugST" in this function should be.
> >
> > "mDebugST" is a global variable (= an object with file scope and static
> > storage duration) defined in
> > "MdePkg/Library/UefiDebugLibConOut/DebugLibConstructor.c".
> >
> > The library instance (for which the destructor function is being added)
> > is linked into driver and application modules. The destructor function
> > is invoked whenever the driver or application is about to be unloaded
> > from memory. As part of the unloading, the ExitBootServices()
> > notification function -- which was automatically registered via the
> > constructor function when the driver or application started up -- must
> > be de-registered, otherwise the platform firmware will be left with a
> > dangling callback pointer. That's what the CloseEvent() above takes care
> > of. But it's OK to ignore "mDebugST" altogether, as the memory that
> > "mDebugST" lives inside is about to be reclaimed by the platform
> > firmware anyway.
> >
> > The library destructor is invoked:
> > - when a UEFI application exits (with success or failure), by returning
> > from its entry point function, or by calling the Exit() boot service
> >
> > - when a UEFI driver exits with failure (hence it will be unloaded
> > automatically)
> >
> > - when a UEFI driver exited with success (hence staying resident), and
> > it supports unloading, and now another agent is unloading it with the
> > UnloadImage() boot service (such as the UEFI shell with the "unload"
> > command, IIRC).
>
> Thanks Laszlo for the explanations!
>
> I noticed (late) this series is already pushed (commits
> e92bdcb3ecbf..28bc6992400) so it doesn't require review anymore.
Sorry, I forget to send the mail to say I have pushed these serials.
These changes are clear to me.
>
> BTW Liming the author name seems incorrect: Wei6 Xu and Xu, Wei6.
>
Seemly, the author doesn't configure his name in the consistent way.
Author name may be Wei Xu.
Thanks
Liming
> >>> +
> >>> + return EFI_SUCCESS;
> >>> +}
> >>> diff --git a/MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf
> b/MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf
> >>> index 4c279a5bf2..b577d52ac6 100644
> >>> --- a/MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf
> >>> +++ b/MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.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
> >>> #
> >>>
> >>>
> >>
> >>
> >>
> >
>
>
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2019-07-30 1:17 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-07-26 3:10 [edk2-devel][Patch 0/3] Add destructor to CloseEvent Xu, Wei6
2019-07-26 3:10 ` [edk2-devel][Patch 1/3] MdePkg/UefiDebugLibConOut: " Xu, Wei6
2019-07-29 14:38 ` Philippe Mathieu-Daudé
2019-07-29 16:09 ` Laszlo Ersek
2019-07-29 17:48 ` Philippe Mathieu-Daudé
2019-07-30 1:17 ` Liming Gao
2019-07-26 3:10 ` [edk2-devel][Patch 2/3] MdePkg/UefiDebugLibDebugPortProtocol: " Xu, Wei6
2019-07-26 3:10 ` [edk2-devel][Patch 3/3] MdePkg/UefiDebugLibStdErr: " Xu, Wei6
2019-07-26 8:28 ` [edk2-devel][Patch 0/3] " Liming Gao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox