REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1416 After ExitBootServices, some pointer would be invalid such as the Protocol pointer and gBS. The function depend on those should be prevent. So disable the related function while after ExitBootServices. Change the gBS to a internal one, because there will be a cycle consume between UefiBootServicesTableLib and DebugLib due to the library constructors. Also remove the SMM support for this instance. Cc: Michael D Kinney <michael.d.kinney@intel.com> Cc: Liming Gao <liming.gao@intel.com> Cc: Sean Brogan <sean.brogan@microsoft.com> Cc: Michael Turner <Michael.Turner@microsoft.com> Cc: Bret Barkelew <Bret.Barkelew@microsoft.com> Signed-off-by: Zhichao Gao <zhichao.gao@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com>
78 lines
2.0 KiB
C
78 lines
2.0 KiB
C
/** @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;
|
|
|
|
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->CreateEventEx (
|
|
EVT_NOTIFY_SIGNAL,
|
|
TPL_NOTIFY,
|
|
ExitBootServicesCallback,
|
|
NULL,
|
|
&gEfiEventExitBootServicesGuid,
|
|
&mExitBootServicesEvent
|
|
);
|
|
|
|
return EFI_SUCCESS;
|
|
}
|