KxDebugTrapOrFault

VOID __stdcall KxDebugTrapOrFault(INT64 a1, INT64 a2, INT64 a3, UINT64 a4){
  _ETHREAD *CurrentThread; 
  unsigned __int8 BpbKernelSpecCtrl; 
  unsigned __int8 BpbState; 
  ULONG64 v7; 
  _QWORD *Object; 
  INT64 v9; 
  __int16 v10; 
  int v11; 
  unsigned __int64 v12; 
  CHAR v13; 
  __int16 v14; 
  UINT64 v15; 
  VOID *retaddr; 
  char v17; 
  __int16 v18; 

  if( (v17 & 1) != 0 )
  {
    if( (KiKvaShadow & 1) == 0 )
      __swapgs();
    _mm_lfence();
    CurrentThread = (_ETHREAD *)KeGetCurrentThread();
    __writegsqword(0x270u, CurrentThread->Tcb.Process->SecurityDomain);
    __writegsbyte(0x851u, KeGetPcr()->Prcb.BpbRetpolineExitSpecCtrl);
    __writegsbyte(0x852u, KeGetPcr()->Prcb.BpbState);
    BpbKernelSpecCtrl = KeGetPcr()->Prcb.BpbKernelSpecCtrl;
    if( KeGetPcr()->Prcb.BpbCurrentSpecCtrl != BpbKernelSpecCtrl )
    {
      __writegsbyte(0x27Au, BpbKernelSpecCtrl);
      __writemsr(0x48u, BpbKernelSpecCtrl);
    }
    BpbState = KeGetPcr()->Prcb.BpbState;
    if( (BpbState & 8) != 0 )
    {
      __writemsr(0x49u, 1ui64);
      BpbState = KeGetPcr()->Prcb.BpbState;
    }
    if( (BpbState & 2) != 0 )
      __flush_rsb();
    _mm_lfence();
    __writegsbyte(0x853u, 0);
    if( (char)CurrentThread->Tcb.gap0[3] < 0 )
    {
      v7 = __readmsr(0xC0000102);
      if( v7 >= MmUserProbeAddress )
        v7 = MmUserProbeAddress;
      if( CurrentThread->Tcb.Teb != (void *)v7 )
      {
        Object = CurrentThread->Tcb.WaitBlock[3].Object;
        CurrentThread->Tcb._bf_0 |= 0x100u;
        --CurrentThread->Tcb.SpecialApcDisable;
        Object[16] = v7;
      }
    }
    v14 = 0;
    if( (CurrentThread->Tcb.gap0[3] & 3) != 0 )
      KiSaveDebugRegisterState();
  }
  else
  {
    _mm_lfence();
    if( (KeGetPcr()->Prcb.BpbState & 1) != 0 )
      __writemsr(0x48u, KeGetPcr()->Prcb.BpbCurrentSpecCtrl);
    else
      _mm_lfence();
  }
  _mm_getcsr();
  _mm_setcsr(KeGetPcr()->Prcb._MxCsr);
  if( (_BYTE)KeSmapEnabled && (v17 & 1) != 0 )
    __stac();
  if( (v18 & 0x200) != 0 )
    _enable();
  if( (KiCpuTracingFlags & 2) != 0 )
  {
    __writemsr(0x1D9u, __readmsr(0x1D9u) | 1);
    v9 = 0i64;
    goto LABEL_40;
  }
  v9 = 0i64;
  if( (v18 & 0x100) != 0 && (KeGetPcr()->Prcb.FeatureBits & 0x20000) != 0 )
  {
    if( (v17 & 1) != 0 )
    {
      if( (v14 & 0x200) != 0 && (v14 & 0x100) != 0 )
      {
        a4 = v15;
        if( v15 >= MmUserProbeAddress )
          a4 = MmUserProbeAddress;
        goto LABEL_39;
      }
    }
    else
    {
      v10 = __readdr(7u);
      if( (v10 & 0x200) != 0 && (v10 & 0x100) != 0 )
      {
        v11 = KiLastBranchTOSMSR;
        if( KiLastBranchTOSMSR )
        {
          v12 = __readmsr(KiLastBranchTOSMSR);
          v11 = v12;
        }
        a4 = __readmsr(v11 + KiLastBranchFromBaseMSR);
        __readmsr(v11 + KiLastBranchToBaseMSR);
LABEL_39:
        v9 = 2i64;
      }
    }
  }
LABEL_40:
  KiExceptionDispatch(2147483652i64, v9, retaddr, a4, v13);
}

Referenced by:

KiDebugTrapOrFault