diff options
author | Mitchell Horne <mhorne@FreeBSD.org> | 2020-06-03 18:44:51 +0000 |
---|---|---|
committer | Mitchell Horne <mhorne@FreeBSD.org> | 2020-06-03 18:44:51 +0000 |
commit | 4a14dfcc1110b35118d5be8054fecf59ffb83032 (patch) | |
tree | 8bf1574ccba91c926acbe0a05d32482ba8825e26 /MdePkg/Library/UefiDebugLibDebugPortProtocol/DebugLibConstructor.c | |
parent | 0499b37cea9ca98acfe36368e521ad36b7783f2d (diff) |
Notes
Diffstat (limited to 'MdePkg/Library/UefiDebugLibDebugPortProtocol/DebugLibConstructor.c')
-rw-r--r-- | MdePkg/Library/UefiDebugLibDebugPortProtocol/DebugLibConstructor.c | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/MdePkg/Library/UefiDebugLibDebugPortProtocol/DebugLibConstructor.c b/MdePkg/Library/UefiDebugLibDebugPortProtocol/DebugLibConstructor.c new file mode 100644 index 000000000000..1631c7e27f37 --- /dev/null +++ b/MdePkg/Library/UefiDebugLibDebugPortProtocol/DebugLibConstructor.c @@ -0,0 +1,99 @@ +/** @file + UEFI Dxe DebugLib constructor that prevent some debug service after ExitBootServices event, + because some pointer is nulled at that phase. + + Copyright (c) 2018, Microsoft Corporation + Copyright (c) 2015 - 2019, Intel Corporation. All rights reserved.<BR> + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include <Uefi.h> +#include <Library/BaseLib.h> +#include <Library/BaseMemoryLib.h> + +// +// BOOLEAN value to indicate if it is at the post ExitBootServices pahse +// +BOOLEAN mPostEBS = FALSE; + +static EFI_EVENT mExitBootServicesEvent; + +// +// Pointer to SystemTable +// This library instance may have a cycle consume with UefiBootServicesTableLib +// because of the constructors. +// +EFI_BOOT_SERVICES *mDebugBS; + +/** + This routine sets the mPostEBS for exit boot servies true + to prevent DebugPort protocol dereferences when the pointer is nulled. + + @param Event Event whose notification function is being invoked. + @param Context Pointer to the notification function's context. + +**/ +VOID +EFIAPI +ExitBootServicesCallback ( + EFI_EVENT Event, + VOID* Context + ) +{ + mPostEBS = TRUE; + return; +} + +/** + The constructor gets the pointers to boot services table. + And create a event to indicate it is after ExitBootServices. + + @param ImageHandle The firmware allocated handle for the EFI image. + @param SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS. + +**/ +EFI_STATUS +EFIAPI +DxeDebugLibConstructor( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + mDebugBS = SystemTable->BootServices; + + mDebugBS->CreateEvent ( + EVT_SIGNAL_EXIT_BOOT_SERVICES, + TPL_NOTIFY, + ExitBootServicesCallback, + NULL, + &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; +} |