KiInvalidOpcodeFault

VOID __stdcall KiInvalidOpcodeFault(INT64 SecurityDomain, UINT64 a2, UINT64 a3, UINT64 a4, CHAR a5){
  unsigned __int64 v5; 
  unsigned __int64 v6; 
  unsigned __int64 v7; 
  _M128A v8; 
  _M128A v9; 
  _M128A v10; 
  _M128A v11; 
  _M128A v12; 
  _M128A v13; 
  _KTRAP_FRAME *__shifted(_KTRAP_FRAME,0x80) TrapFrame; 
  _ETHREAD *CurrentThread; 
  unsigned __int8 BpbKernelSpecCtrl; 
  unsigned __int8 BpbState; 
  ULONG64 v18; 
  _QWORD *Object; 
  bool v20; 
  _ETHREAD *v21; 
  INT64 v22; 
  INT64 v23; 
  INT64 v24; 
  _ETHREAD *v25; 
  _ETHREAD *v26; 
  INT64 R9; 
  INT64 R8; 
  unsigned __int8 BpbUserSpecCtrl; 
  unsigned __int8 v30; 
  CHAR v33; 
  CHAR v34; 
  void *retaddr; 
  __int16 v36; 
  int v37; 
  void *v38; 
  __int16 v39; 

  TrapFrame = KeGetTrapFrame();
  ADJ(TrapFrame)->ExceptionActive = 1;
  ADJ(TrapFrame)->_Rax = v5;
  ADJ(TrapFrame)->_Rcx = SecurityDomain;
  ADJ(TrapFrame)->_Rdx = a2;
  ADJ(TrapFrame)->_R8 = a3;
  ADJ(TrapFrame)->_R9 = a4;
  ADJ(TrapFrame)->_R10 = v6;
  ADJ(TrapFrame)->_R11 = v7;
  if( (ADJ(TrapFrame)->SegCs & 1) != 0 )
  {
    if( (KiKvaShadow & 1) == 0 )
      __swapgs();
    _mm_lfence();
    CurrentThread = (_ETHREAD *)KeGetCurrentThread();
    SecurityDomain = CurrentThread->Tcb.Process->SecurityDomain;
    __writegsqword(0x270u, SecurityDomain);
    __writegsbyte(0x851u, KeGetPcr()->Prcb.BpbRetpolineExitSpecCtrl);
    LOBYTE(SecurityDomain) = KeGetPcr()->Prcb.BpbState;
    __writegsbyte(0x852u, SecurityDomain);
    BpbKernelSpecCtrl = KeGetPcr()->Prcb.BpbKernelSpecCtrl;
    if( KeGetPcr()->Prcb.BpbCurrentSpecCtrl != BpbKernelSpecCtrl )
    {
      __writegsbyte(0x27Au, BpbKernelSpecCtrl);
      SecurityDomain = 72i64;
      __writemsr(0x48u, BpbKernelSpecCtrl);
    }
    BpbState = KeGetPcr()->Prcb.BpbState;
    if( (BpbState & 8) != 0 )
    {
      SecurityDomain = 73i64;
      __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 )
    {
      SecurityDomain = 3221225730i64;
      v18 = __readmsr(0xC0000102);
      if( v18 >= MmUserProbeAddress )
        v18 = MmUserProbeAddress;
      if( CurrentThread->Tcb.Teb != (void *)v18 )
      {
        Object = CurrentThread->Tcb.WaitBlock[3].Object;
        CurrentThread->Tcb._bf_0 |= 0x100u;
        --CurrentThread->Tcb.SpecialApcDisable;
        Object[16] = v18;
      }
    }
    v20 = (CurrentThread->Tcb.gap0[3] & 3) == 0;
    LOWORD(ADJ(TrapFrame)->Dr7) = 0;
    if( !v20 )
      KiSaveDebugRegisterState();
  }
  else
  {
    _mm_lfence();
    if( (KeGetPcr()->Prcb.BpbState & 1) != 0 )
    {
      SecurityDomain = 72i64;
      __writemsr(0x48u, KeGetPcr()->Prcb.BpbCurrentSpecCtrl);
    }
    else
    {
      _mm_lfence();
    }
  }
  ADJ(TrapFrame)->_MxCsr = _mm_getcsr();
  _mm_setcsr(KeGetPcr()->Prcb._MxCsr);
  ADJ(TrapFrame)->_Xmm0 = v8;
  ADJ(TrapFrame)->_Xmm1 = v9;
  ADJ(TrapFrame)->_Xmm2 = v10;
  ADJ(TrapFrame)->_Xmm3 = v11;
  ADJ(TrapFrame)->_Xmm4 = v12;
  ADJ(TrapFrame)->_Xmm5 = v13;
  if( (_BYTE)KeSmapEnabled && (ADJ(TrapFrame)->SegCs & 1) != 0 )
    __stac();
  if( (ADJ(TrapFrame)->EFlags & 0x200) != 0 )
    _enable();
  v21 = (_ETHREAD *)KeGetCurrentThread();
  if( _bittest((const signed __int32 *)&v21->Tcb.116, 8u) && (ADJ(TrapFrame)->SegCs & 1) != 0 )
    KiUmsTrapEntry(SecurityDomain);
  KiExceptionDispatch(268435458i64, 0i64, (VOID *)ADJ(TrapFrame)->_Rip, (UINT64)v21, v33);
  _disable();
  if( (ADJ(TrapFrame)->SegCs & 1) == 0 )
  {
    _mm_setcsr(ADJ(TrapFrame)->_MxCsr);
    __iretq(retaddr, v36, v37, v38, v39);
  }
  if( (_BYTE)KeSmapEnabled )
    __stac();
  while( (KeGetCurrentThread()->ApcState.UserApcPendingAll & 3) != 0 )
  {
    __writecr8(1ui64);
    _enable();
    KiInitiateUserApc((_KTRAP_FRAME *)1);
    _disable();
    __writecr8(0i64);
  }
  if( (*((_BYTE *)&KeGetPcr()->Prcb.2 + 14) & 2) != 0 )
    KiUpdateStibpPairing(0i64);
  v25 = (_ETHREAD *)KeGetCurrentThread();
  if( (*(_DWORD *)v25->Tcb.gap0 & 0x8000000) != 0 )
    KiRestoreSetContextState((INT64)v25, v22, v23, v24, v34);
  v26 = (_ETHREAD *)KeGetCurrentThread();
  if( (*(_DWORD *)v26->Tcb.gap0 & 0x40010000) != 0 )
  {
    if( (v26->Tcb.gap0[2] & 1) != 0 )
    {
      KiCopyCounters(&v26->Tcb);
      v26 = (_ETHREAD *)KeGetCurrentThread();
    }
    if( (v26->Tcb.gap0[3] & 0x40) != 0 )
      KiUmsExit(1);
  }
  _mm_setcsr(ADJ(TrapFrame)->_MxCsr);
  if( LOWORD(ADJ(TrapFrame)->Dr7) )
    KiRestoreDebugRegisterState();
  R9 = ADJ(TrapFrame)->_R9;
  R8 = ADJ(TrapFrame)->_R8;
  __writegsbyte(0x853u, 0);
  BpbUserSpecCtrl = KeGetPcr()->Prcb.BpbUserSpecCtrl;
  if( KeGetPcr()->Prcb.BpbCurrentSpecCtrl != BpbUserSpecCtrl )
  {
    __writegsbyte(0x27Au, BpbUserSpecCtrl);
    __writemsr(0x48u, BpbUserSpecCtrl);
  }
  v30 = _bittestandreset16(MK_FP(__GS__, 632i64), 2u);
  if( v30 )
    __writemsr(0x49u, 1ui64);
  v30 = _bittestandreset16(MK_FP(__GS__, 632i64), 5u);
  if( v30 )
    __flush_rsb();
  if( (KiKvaShadow & 1) == 0 )
  {
    __swapgs();
    __iretq(retaddr, v36, v37, v38, v39);
  }
  KiKernelExit(ADJ(TrapFrame)->_Rcx, ADJ(TrapFrame)->_Rdx, R8, R9, a5);
}

Referenced by:

KiInvalidOpcodeFaultShadow