KiFastFailDispatch

VOID __fastcall KiFastFailDispatch(INT64 a1, INT64 a2, INT64 a3, INT64 a4, CHAR a5){
  INT64 v5; 
  __int64 v6; 
  INT64 v7; 
  INT64 v8; 
  unsigned __int64 v9; 
  unsigned __int64 v10; 
  INT64 v11; 
  INT64 v12; 
  INT64 v13; 
  __int128 v14; 
  __int128 v15; 
  __int128 v16; 
  __int128 v17; 
  __int128 v18; 
  __int128 v19; 
  __int128 v20; 
  __int128 v21; 
  __int128 v22; 
  __int128 v23; 
  CHAR v24; 
  INT64 v25; 
  INT64 v26; 
  INT64 v27; 
  _ETHREAD *CurrentThread; 
  _KTHREAD *v29; 
  INT64 v30; 
  INT64 v31; 
  unsigned __int8 v32; 
  unsigned __int8 v33; 
  __int64 v36; 
  INT64 FirstChance; 
  INT64 v38; 
  INT64 v39[2]; 
  INT64 v40[2]; 
  INT64 v41[2]; 
  INT64 v42[2]; 
  INT64 v43[2]; 
  __int128 v44; 
  __int128 v45; 
  __int128 v46; 
  __int128 v47; 
  __int128 v48; 
  INT64 v49; 
  INT64 v50; 
  INT64 v51; 
  INT64 v52; 
  INT64 v53; 
  INT64 v54; 
  INT64 v55; 
  INT64 v56; 
  INT64 v57; 
  INT64 v58; 
  INT64 v59; 
  INT64 v60; 
  struct _EXCEPTION_RECORD ExceptionRecord; 
  void *retaddr; 
  __int16 v63; 
  int v64; 
  void *v65; 
  __int16 v66; 
  *(_OWORD *)v39 = v14;
  *(_OWORD *)v40 = v15;
  *(_OWORD *)v41 = v16;
  *(_OWORD *)v42 = v17;
  *(_OWORD *)v43 = v18;
  v44 = v19;
  v45 = v20;
  v46 = v21;
  v47 = v22;
  v48 = v23;
  v55 = v5;
  v56 = v7;
  v57 = v8;
  v58 = v11;
  v59 = v12;
  v60 = v13;
  if( _bittest((const signed __int32 *)KeGetCurrentThread() + 29, 8u) && (*(_BYTE *)(v6 + 240) & 1) != 0 )
    KiUmsExceptionEntry(
      a1,
      a2,
      a3,
      a4,
      FirstChance,
      v38,
      v39[0],
      v39[1],
      v40[0],
      v40[1],
      v41[0],
      v41[1],
      v42[0],
      v42[1],
      v43[0],
      v43[1],
      v44,
      *((INT64 *)&v44 + 1),
      v45,
      *((INT64 *)&v45 + 1),
      v46,
      *((INT64 *)&v46 + 1),
      v47,
      *((INT64 *)&v47 + 1),
      v48,
      *((INT64 *)&v48 + 1),
      v49,
      v50,
      v51,
      v52,
      v53,
      v54,
      v55,
      v56,
      v57,
      v58,
      v59,
      v60);
  ExceptionRecord.ExceptionCode = a1;
  ExceptionRecord.ExceptionFlags = 1;
  ExceptionRecord.ExceptionRecord = 0i64;
  ExceptionRecord.ExceptionAddress = (void *)a3;
  ExceptionRecord.NumberParameters = a2;
  ExceptionRecord.ExceptionInformation[0] = a4;
  ExceptionRecord.ExceptionInformation[1] = v9;
  ExceptionRecord.ExceptionInformation[2] = v10;
  v24 = *(_BYTE *)(v6 + 240) & 1;
  if( !v24 )
    KiBugCheckDispatch(0x139u, ExceptionRecord.ExceptionInformation[0], v6 - 128, (ULONG_PTR)&ExceptionRecord);
  KiDispatchException(&ExceptionRecord, (_KEXCEPTION_FRAME *)&v36, (_KTRAP_FRAME *)(v6 - 128), v24, 0);
  _disable();
  if( (*(_BYTE *)(v6 + 240) & 1) == 0 )
  {
    _mm_setcsr(*(_DWORD *)(v6 - 84));
    __iretq(retaddr, v63, v64, v65, v66);
  }
  if( (_BYTE)KeSmapEnabled )
    __stac();
  while( (*((_BYTE *)KeGetCurrentThread() + 194) & 3) != 0 )
  {
    __writecr8(1ui64);
    _enable();
    KiInitiateUserApc((_KTRAP_FRAME *)1);
    _disable();
    __writecr8(0i64);
  }
  if( (*((_BYTE *)KeGetPcr() + 638) & 2) != 0 )
    KiUpdateStibpPairing(0i64);
  CurrentThread = (_ETHREAD *)KeGetCurrentThread();
  if( (*(_DWORD *)CurrentThread & 0x8000000) != 0 )
    KiRestoreSetContextState((INT64)CurrentThread, v25, v26, v27, FirstChance);
  v29 = (_ETHREAD *)KeGetCurrentThread();
  if( (*(_DWORD *)v29 & 0x40010000) != 0 )
  {
    if( (*((_BYTE *)v29 + 2) & 1) != 0 )
    {
      KiCopyCounters((_KTHREAD *)v29);
      v29 = (_ETHREAD *)KeGetCurrentThread();
    }
    if( (*((_BYTE *)v29 + 3) & 0x40) != 0 )
      KiUmsExit(1);
  }
  _mm_setcsr(*(_DWORD *)(v6 - 84));
  if( *(_WORD *)(v6 + 128) )
    KiRestoreDebugRegisterState();
  v30 = *(_QWORD *)(v6 - 48);
  v31 = *(_QWORD *)(v6 - 56);
  __writegsbyte(0x853u, 0);
  v32 = *((_BYTE *)KeGetPcr() + 637);
  if( *((_BYTE *)KeGetPcr() + 634) != v32 )
  {
    __writegsbyte(0x27Au, v32);
    __writemsr(0x48u, v32);
  }
  v33 = _bittestandreset16(MK_FP(__GS__, 632i64), 2u);
  if( v33 )
    __writemsr(0x49u, 1ui64);
  v33 = _bittestandreset16(MK_FP(__GS__, 632i64), 5u);
  if( v33 )
    __flush_rsb();
  if( (KiKvaShadow & 1) == 0 )
  {
    __swapgs();
    __iretq(retaddr, v63, v64, v65, v66);
  }
  KiKernelExit(*(_QWORD *)(v6 - 72), *(_QWORD *)(v6 - 64), v31, v30, a5);
}

Referenced by:

KiBoundFault
KiControlProtectionFault
KiRaiseSecurityCheckFailure