IntelFrameworkModulePkg/Csm: Add code to bypass NULL pointer detection
Legacy has to access interrupt vector, BDA, etc. located in memory between 0-4095. To allow as much code as possible to be monitored by NULL pointer detection, we add code to temporarily disable this feature right before those memory access and enable it again afterwards. Cc: Star Zeng <star.zeng@intel.com> Cc: Eric Dong <eric.dong@intel.com> Cc: Jiewen Yao <jiewen.yao@intel.com> Cc: Michael Kinney <michael.d.kinney@intel.com> Cc: Ayellet Wolman <ayellet.wolman@intel.com> Suggested-by: Ayellet Wolman <ayellet.wolman@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jian J Wang <jian.j.wang@intel.com> Reviewed-by: Jiewen Yao <jiewen.yao@intel.com> Reviewed-by: Star Zeng <star.zeng@intel.com>
This commit is contained in:
@@ -1732,6 +1732,98 @@ CheckKeyboardConnect (
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Disable NULL pointer detection
|
||||
*/
|
||||
VOID
|
||||
DisableNullDetection (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EFI_GCD_MEMORY_SPACE_DESCRIPTOR Desc;
|
||||
|
||||
if ((PcdGet8 (PcdNullPointerDetectionPropertyMask) & BIT0) == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Check current capabilities and attributes
|
||||
//
|
||||
Status = gDS->GetMemorySpaceDescriptor (0, &Desc);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
|
||||
//
|
||||
// Try to add EFI_MEMORY_RP support if necessary
|
||||
//
|
||||
if ((Desc.Capabilities & EFI_MEMORY_RP) == 0) {
|
||||
Desc.Capabilities |= EFI_MEMORY_RP;
|
||||
Status = gDS->SetMemorySpaceCapabilities (0, EFI_PAGES_TO_SIZE(1),
|
||||
Desc.Capabilities);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
if (EFI_ERROR (Status)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Don't bother if EFI_MEMORY_RP is already cleared.
|
||||
//
|
||||
if ((Desc.Attributes & EFI_MEMORY_RP) != 0) {
|
||||
Desc.Attributes &= ~EFI_MEMORY_RP;
|
||||
Status = gDS->SetMemorySpaceAttributes (0, EFI_PAGES_TO_SIZE(1),
|
||||
Desc.Attributes);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
} else {
|
||||
DEBUG ((DEBUG_WARN, "!!! Page 0 is supposed to be disabled !!!\r\n"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Enable NULL pointer detection
|
||||
*/
|
||||
VOID
|
||||
EnableNullDetection (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EFI_GCD_MEMORY_SPACE_DESCRIPTOR Desc;
|
||||
|
||||
if ((PcdGet8 (PcdNullPointerDetectionPropertyMask) & BIT0) == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Check current capabilities and attributes
|
||||
//
|
||||
Status = gDS->GetMemorySpaceDescriptor (0, &Desc);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
|
||||
//
|
||||
// Try to add EFI_MEMORY_RP support if necessary
|
||||
//
|
||||
if ((Desc.Capabilities & EFI_MEMORY_RP) == 0) {
|
||||
Desc.Capabilities |= EFI_MEMORY_RP;
|
||||
Status = gDS->SetMemorySpaceCapabilities (0, EFI_PAGES_TO_SIZE(1),
|
||||
Desc.Capabilities);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
if (EFI_ERROR (Status)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Don't bother if EFI_MEMORY_RP is already set.
|
||||
//
|
||||
if ((Desc.Attributes & EFI_MEMORY_RP) == 0) {
|
||||
Desc.Attributes |= EFI_MEMORY_RP;
|
||||
Status = gDS->SetMemorySpaceAttributes (0, EFI_PAGES_TO_SIZE(1),
|
||||
Desc.Attributes);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Timer event handler: read a series of key stroke from 8042
|
||||
and put them into memory key buffer.
|
||||
@@ -1839,6 +1931,11 @@ BiosKeyboardTimerHandler (
|
||||
// 0 Right Shift pressed
|
||||
|
||||
|
||||
//
|
||||
// Disable NULL pointer detection temporarily
|
||||
//
|
||||
DisableNullDetection ();
|
||||
|
||||
//
|
||||
// Clear the CTRL and ALT BDA flag
|
||||
//
|
||||
@@ -1916,6 +2013,10 @@ BiosKeyboardTimerHandler (
|
||||
KbFlag1 &= ~0x0C;
|
||||
*((UINT8 *) (UINTN) 0x417) = KbFlag1;
|
||||
|
||||
//
|
||||
// Restore NULL pointer detection
|
||||
//
|
||||
EnableNullDetection ();
|
||||
|
||||
//
|
||||
// Output EFI input key and shift/toggle state
|
||||
|
@@ -18,6 +18,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
|
||||
#include <FrameworkDxe.h>
|
||||
#include <Pi/PiDxeCis.h>
|
||||
|
||||
#include <Guid/StatusCodeDataTypeId.h>
|
||||
#include <Protocol/SimpleTextIn.h>
|
||||
@@ -33,6 +34,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#include <Library/ReportStatusCodeLib.h>
|
||||
#include <Library/UefiDriverEntryPoint.h>
|
||||
#include <Library/UefiBootServicesTableLib.h>
|
||||
#include <Library/DxeServicesTableLib.h>
|
||||
#include <Library/MemoryAllocationLib.h>
|
||||
#include <Library/BaseLib.h>
|
||||
#include <Library/PcdLib.h>
|
||||
|
@@ -60,6 +60,7 @@
|
||||
DebugLib
|
||||
BaseLib
|
||||
PcdLib
|
||||
DxeServicesTableLib
|
||||
|
||||
[Protocols]
|
||||
gEfiIsaIoProtocolGuid ## TO_START
|
||||
@@ -73,6 +74,7 @@
|
||||
|
||||
[Pcd]
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdFastPS2Detection ## SOMETIMES_CONSUMES
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdNullPointerDetectionPropertyMask ## CONSUMES
|
||||
|
||||
[UserExtensions.TianoCore."ExtraFiles"]
|
||||
KeyboardDxeExtra.uni
|
||||
|
Reference in New Issue
Block a user