KeFreezeExecution

UINT8 __stdcall KeFreezeExecution(_KTRAP_FRAME *TrapFrame, _KEXCEPTION_FRAME *ExceptionFrame){
  __int16 v2; 
  bool v3; 
  unsigned __int8 CurrentIrql; 
  unsigned __int64 v5; 
  int v6; 
  CHAR v7; 
  unsigned int v8; 
  struct _KPRCB *CurrentPrcb; 
  __int64 v10; 
  int v11; 
  char v12; 
  __int64 v13; 
  LARGE_INTEGER v14; 
  unsigned __int64 v15; 
  unsigned int v17; 
  union _LARGE_INTEGER PerformanceFrequency; 
  __int128 v19; 
  __int64 v20; 
  _KAFFINITY_EX result; 
  int v22; 
  memset((INT64)&result, 0i64);
  v2 = v22;
  v17 = 0;
  v20 = 0i64;
  v19 = 0i64;
  PerformanceFrequency.QuadPart = 0i64;
  _disable();
  v3 = (v2 & 0x200) != 0;
  CurrentIrql = KeGetCurrentIrql();
  v5 = (unsigned int)LOBYTE(PerformanceFrequency.LowPart) + 15;
  __writecr8(v5);
  KiFreezeFlag = 4;
  if( ((unsigned __int8)v5 & (unsigned __int8)*((_DWORD *)KeGetCurrentPrcb() + 2914)) != 4 )
  {
LABEL_2:
    v6 = 500000;
    do
    {
      v7 = KxTryToAcquireSpinLock((volatile INT32 *)&KdDebuggerLock);
      if( v7 )
        break;
      if( KiFreezeExecutionLock )
        goto LABEL_2;
      KeStallExecutionProcessor(4u);
      --v6;
    }
    while( v6 );
    v8 = v7 != 0 ? 4 * (500000 - v6) : 0;
    KxAcquireSpinLock(&KiFreezeExecutionLock);
    if( v7 || (KiFreezeFlag & 1) == 0 )
      KdPortLocked = v7;
    else
      KiFreezeFlag |= 8u;
    if( v8 > KdDebuggerLockMaxWaitTime )
      KdDebuggerLockMaxWaitTime = v8;
    CurrentPrcb = KeGetCurrentPrcb();
    KiStartDebugAccumulation((__int64)CurrentPrcb);
    LOBYTE(v10) = 1;
    ((void(__fastcall *)(__int64, _QWORD))off_140C00738[0])(v10, 0i64);
    KiClockLatencyMeasurementEnabled = 0;
    if( (unsigned int)KeNumberProcessors_0 > 1 && !PoAllProcIntrDisabled )
    {
      KiFreezeOwner = CurrentPrcb;
      *((_DWORD *)CurrentPrcb + 2914) = 4;
      KiSetDebuggerOwner(CurrentPrcb);
      if( !KiFreezeTimeout || PpmNonInterruptibleCount )
        v11 = 20000;
      else
        v11 = 20000 * KiFreezeTimeout;
      *((_DWORD *)CurrentPrcb + 7928) = 1;
      KeCopyAffinityEx((__int64)&result, &KeActiveProcessors.Count);
      KeRemoveProcessorAffinityEx(&result.Count, *((_DWORD *)CurrentPrcb + 9));
      v12 = KiBugCheckActive;
      if( KiRecoveryInProgress )
        v12 = 0;
      KiSendFreeze(&result, (v12 & 3) != 3);
      *((_QWORD *)&v19 + 1) = result.Bitmap[0];
      *(_QWORD *)&v19 = &result;
LABEL_21:
      while( !(unsigned int)KeEnumerateNextProcessor(&v17, (unsigned __int16 **)&v19) )
      {
        v13 = (__int64)*(&KiProcessorBlock + v17);
        while( *(_DWORD *)(v13 + 11656) != 2 )
        {
          if( !v11 )
          {
            KiFreezeFlag |= 2u;
            goto LABEL_21;
          }
          KeStallExecutionProcessor(0x32u);
          --v11;
        }
      }
    }
    KiOldIrql = CurrentIrql;
    if( !PoAllProcIntrDisabled && RtlWriteTryAcquireTickLock() )
    {
      v14 = KeQueryPerformanceCounter(&PerformanceFrequency);
      v15 = *(_QWORD *)&KUSER_SHARED_DATA.InterruptTime.LowPart
          + 10000000 * (v14.QuadPart - KUSER_SHARED_DATA.BaselineInterruptTimeQpc) / PerformanceFrequency.LowPart;
      KUSER_SHARED_DATA.InterruptTime.High2Time = HIDWORD(v15);
      *(_QWORD *)&KUSER_SHARED_DATA.InterruptTime.LowPart = v15;
      if( KeMaximumIncrement )
      {
        KiTickOffset = KeMaximumIncrement * (v15 / KeMaximumIncrement + 1) - v15;
        KUSER_SHARED_DATA.TickCount.High2Time = (v15 / KeMaximumIncrement) >> 32;
        KUSER_SHARED_DATA.TickCountQuad = v15 / KeMaximumIncrement;
      }
      ++KUSER_SHARED_DATA.TimeUpdateLock;
    }
  }
  return v3;
}

Referenced by:

ExpWaitForBootDevices
KdEnterDebugger