/* Special handler for #DB exception, which will restore the page attributes (not-present). It should work with #PF handler which will set pages to 'present'. */
VOID EFIAPI DebugExceptionHandler(IN EFI_EXCEPTION_TYPE ExceptionType, IN EFI_SYSTEM_CONTEXT SystemContext)
/* Special handler for #DB exception, which will restore the page attributes (not-present). It should work with #PF handler which will set pages to 'present'. */
VOID EFIAPI DebugExceptionHandler(IN EFI_EXCEPTION_TYPE ExceptionType, IN EFI_SYSTEM_CONTEXT SystemContext)
{
  UINTN    CpuIndex;
  UINTN    PFEntry;
  BOOLEAN  IsWpEnabled;
  MpInitLibWhoAmI (&CpuIndex);
  IsWpEnabled = IsReadOnlyPageWriteProtected ();
  if (IsWpEnabled) {
    DisableReadOnlyPageWriteProtect ();
  }
  for (PFEntry = 0; PFEntry < mPFEntryCount[CpuIndex]; PFEntry++) {
    if (mLastPFEntryPointer[CpuIndex][PFEntry] != NULL) {
      *mLastPFEntryPointer[CpuIndex][PFEntry] &= ~(UINT64)IA32_PG_P;
    }
  }
  if (IsWpEnabled) {
    EnableReadOnlyPageWriteProtect ();
  }
  mPFEntryCount[CpuIndex] = 0;
  CpuFlushTlb ();
  if (mPagingContext.MachineType == IMAGE_FILE_MACHINE_I386) {
    SystemContext.SystemContextIa32->Eflags &= (UINT32) ~BIT8;
  } else {
    SystemContext.SystemContextX64->Rflags &= (UINT64) ~BIT8;
  }
}