MdePkg/UefiDebugLibStdErr: Make it runtime safe

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1416

After ExitBootServices, some pointer would be invalid such as
the Protocol pointer and gST. The function depend on those should
be prevent. So disable the related function while after
ExitBootServices.
Change the gST 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>
This commit is contained in:
Aaron Antone
2019-04-08 11:03:26 +08:00
committed by Liming Gao
parent 452702d0bc
commit e72920ec61
3 changed files with 140 additions and 52 deletions

View File

@@ -10,7 +10,6 @@
#include <Uefi.h>
#include <Library/DebugLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/PrintLib.h>
#include <Library/PcdLib.h>
#include <Library/BaseLib.h>
@@ -29,6 +28,8 @@
//
VA_LIST mVaListNull;
extern BOOLEAN mPostEBS;
extern EFI_SYSTEM_TABLE *mDebugST;
/**
Prints a debug message to the debug output device if the specified error level is enabled.
@@ -88,32 +89,34 @@ DebugPrintMarker (
{
CHAR16 Buffer[MAX_DEBUG_MESSAGE_LENGTH];
//
// If Format is NULL, then ASSERT().
//
ASSERT (Format != NULL);
if (!mPostEBS) {
//
// If Format is NULL, then ASSERT().
//
ASSERT (Format != NULL);
//
// Check driver debug mask value and global mask
//
if ((ErrorLevel & GetDebugPrintErrorLevel ()) == 0) {
return;
}
//
// Check driver debug mask value and global mask
//
if ((ErrorLevel & GetDebugPrintErrorLevel ()) == 0) {
return;
}
//
// Convert the DEBUG() message to a Unicode String
//
if (BaseListMarker == NULL) {
UnicodeVSPrintAsciiFormat (Buffer, MAX_DEBUG_MESSAGE_LENGTH, Format, VaListMarker);
} else {
UnicodeBSPrintAsciiFormat (Buffer, MAX_DEBUG_MESSAGE_LENGTH, Format, BaseListMarker);
}
//
// Convert the DEBUG() message to a Unicode String
//
if (BaseListMarker == NULL) {
UnicodeVSPrintAsciiFormat (Buffer, MAX_DEBUG_MESSAGE_LENGTH, Format, VaListMarker);
} else {
UnicodeBSPrintAsciiFormat (Buffer, MAX_DEBUG_MESSAGE_LENGTH, Format, BaseListMarker);
}
//
// Send the print string to the Standard Error device
//
if ((gST != NULL) && (gST->StdErr != NULL)) {
gST->StdErr->OutputString (gST->StdErr, Buffer);
//
// Send the print string to the Standard Error device
//
if ((mDebugST != NULL) && (mDebugST->StdErr != NULL)) {
mDebugST->StdErr->OutputString (mDebugST->StdErr, Buffer);
}
}
}
@@ -207,33 +210,35 @@ DebugAssert (
{
CHAR16 Buffer[MAX_DEBUG_MESSAGE_LENGTH];
//
// Generate the ASSERT() message in Unicode format
//
UnicodeSPrintAsciiFormat (
Buffer,
sizeof (Buffer),
"ASSERT [%a] %a(%d): %a\n",
gEfiCallerBaseName,
FileName,
LineNumber,
Description
);
if (!mPostEBS) {
//
// Generate the ASSERT() message in Unicode format
//
UnicodeSPrintAsciiFormat (
Buffer,
sizeof (Buffer),
"ASSERT [%a] %a(%d): %a\n",
gEfiCallerBaseName,
FileName,
LineNumber,
Description
);
//
// Send the print string to the Standard Error device
//
if ((gST != NULL) && (gST->StdErr != NULL)) {
gST->StdErr->OutputString (gST->StdErr, Buffer);
}
//
// Send the print string to the Standard Error device
//
if ((mDebugST != NULL) && (mDebugST->StdErr != NULL)) {
mDebugST->StdErr->OutputString (mDebugST->StdErr, Buffer);
}
//
// Generate a Breakpoint, DeadLoop, or NOP based on PCD settings
//
if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED) != 0) {
CpuBreakpoint ();
} else if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED) != 0) {
CpuDeadLoop ();
//
// Generate a Breakpoint, DeadLoop, or NOP based on PCD settings
//
if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED) != 0) {
CpuBreakpoint ();
} else if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED) != 0) {
CpuDeadLoop ();
}
}
}