KiPreprocessFault

UINT8 __stdcall KiPreprocessFault(
        _EXCEPTION_RECORD *ExceptionRecord,
        _KEXCEPTION_FRAME *ExceptionFrame,
        _KTRAP_FRAME *TrapFrame,
        _CONTEXT *ContextRecord,
        CHAR PreviousMode){
  INT8 v6; 
  __int16 High; 
  INT64(*v9)(void); 
  void *v10; 
  bool v11; 
  unsigned int v12; 
  int v13; 
  __int64 v14; 
  UINT8 v15; 
  __int16 v17; 
  _ETHREAD *CurrentThread; 
  unsigned __int64 v19; 
  unsigned __int16 v20; 
  INT64 v21[11]; 
  __int64 v22; 
  UINT8 v23; 
  char v24; 
  v6 = (char)TrapFrame;
  memset((INT64)v21, 0i64);
  switch( ExceptionRecord->ExceptionCode )
  {
    case 0x10000001:
      v12 = 0x80000000;
      break;
    case 0x10000002:
      v12 = 0x40000000;
      ExceptionRecord->ExceptionCode = -1073741795;
      goto LABEL_10;
    case 0x10000003:
      v12 = 0x20000000;
      ExceptionRecord->ExceptionCode = -1073741676;
      goto LABEL_10;
    case 0x10000004:
LABEL_5:
      High = ExceptionFrame->Xmm6.High;
      if( High == 16 )
      {
        v9 = ExpInterlockedPopEntrySListFault;
        v10 = &ExpInterlockedPopEntrySListResume;
      }
      else
      {
        if( High != 51 )
          goto LABEL_8;
        v9 = (INT64(*)(void))KeUserPopEntrySListFault;
        v10 = (void *)KeUserPopEntrySListResume;
      }
      if( (INT64(*)(void))ExceptionFrame->Rbp != v9 )
      {
LABEL_8:
        v11 = ExceptionRecord->NumberParameters < 2;
        v12 = 0x10000000;
        ExceptionRecord->ExceptionCode = -1073741819;
        if( v11 || (ExceptionRecord->ExceptionInformation[0] & 8) == 0 )
          goto LABEL_10;
        if( v6 )
        {
          v12 = 0x8000000;
          goto LABEL_10;
        }
        return 0;
      }
      if( High != 16 )
      {
        CurrentThread = (_ETHREAD *)KeGetCurrentThread();
        v19 = ExceptionRecord->ExceptionInformation[1];
        if( v19 == *((_QWORD *)CurrentThread + 3) )
        {
          v20 = *((_WORD *)CurrentThread + 323);
          if( v20 > 0x400u )
          {
            *((_WORD *)CurrentThread + 323) = 0;
            goto LABEL_8;
          }
          v17 = v20 + 1;
        }
        else
        {
          *((_QWORD *)CurrentThread + 3) = v19;
          v17 = 0;
        }
        *((_WORD *)CurrentThread + 323) = v17;
      }
      ExceptionFrame->Rbp = (unsigned __int64)v10;
      return 1;
    case 0x10000006:
      if( (unsigned __int8)KiOpPreprocessSecureFault(ExceptionRecord, ExceptionFrame) )
        return 1;
      goto LABEL_5;
    case 0x10000007:
      v12 = 0x4000000;
      break;
    default:
      return 0;
  }
  ExceptionRecord->ExceptionCode = -1073741819;
LABEL_10:
  v13 = KiOpDecode((INT64)ExceptionRecord, (INT64)ExceptionFrame, v6, v12);
  if( v13 < 0 )
  {
    v14 = 0i64;
  }
  else
  {
    v14 = v22;
    if( v22 )
      v13 = (*(__int64(__fastcall **)(INT64 *))(v22 + 16))(v21);
  }
  v15 = 0;
  if( v13 < 0 || !v14 || (v15 = v23) == 0 )
  {
    if( v12 == 0x80000000 )
    {
      if( ExceptionRecord->ExceptionCode == -1073741819 && !v24 )
      {
        ExceptionRecord->ExceptionInformation[1] = -1i64;
        ExceptionRecord->NumberParameters = 2;
        ExceptionRecord->ExceptionInformation[0] = 0i64;
      }
    }
    else if( v12 == 0x8000000 && (int)KiCheckForAtlThunk((INT64)v21) >= 0 )
    {
      return v23;
    }
  }
  return v15;
}

Referenced by:

KiDispatchException