KeFreezeExecution

VOID __fastcall KeFreezeExecution(_KTRAP_FRAME *TrapFrame, _KEXCEPTION_FRAME *ExceptionFrame){
  unsigned __int8 CurrentIrql; 
  unsigned __int64 v3; 
  int v4; 
  CHAR v5; 
  unsigned int v6; 
  struct _KPRCB *CurrentPrcb; 
  __int64 v8; 
  int v9; 
  char v10; 
  int v11; 
  __int64 v12; 
  UINT64 v13; 
  unsigned __int64 v14; 
  UINT64 ProcIndex; 
  _LARGE_INTEGER PerformanceFrequency; 
  _KAFFINITY_ENUMERATION_CONTEXT Context; 
  _KAFFINITY_EX Dest; 

  memset(&Dest, 0i64, sizeof(Dest));
  LODWORD(ProcIndex) = 0;
  memset(&Context, 0, sizeof(Context));
  PerformanceFrequency.QuadPart = 0i64;
  _disable();
  CurrentIrql = KeGetCurrentIrql();
  v3 = (unsigned int)LOBYTE(PerformanceFrequency.anonymous_0.LowPart) + 15;
  __writecr8(v3);
  KiFreezeFlag = 4;
  if( ((unsigned __int8)v3 & (unsigned __int8)KeGetCurrentPrcb()->IpiFrozen) != 4 )
  {
LABEL_2:
    v4 = 500000;
    do
    {
      v5 = KxTryToAcquireSpinLock((INT32 *)&KdDebuggerLock);
      if( v5 )
        break;
      if( KiFreezeExecutionLock )
        goto LABEL_2;
      KeStallExecutionProcessor(4u);
      --v4;
    }
    while( v4 );
    v6 = v5 != 0 ? 4 * (500000 - v4) : 0;
    KxAcquireSpinLock(&KiFreezeExecutionLock);
    if( v5 || (KiFreezeFlag & 1) == 0 )
      KdPortLocked = v5;
    else
      KiFreezeFlag |= 8u;
    if( v6 > KdDebuggerLockMaxWaitTime )
      KdDebuggerLockMaxWaitTime = v6;
    CurrentPrcb = KeGetCurrentPrcb();
    KiStartDebugAccumulation(CurrentPrcb);
    LOBYTE(v8) = 1;
    ((void(__fastcall *)(__int64, _QWORD))off_140C00738[0])(v8, 0i64);
    KiClockLatencyMeasurementEnabled = 0;
    if( (unsigned int)KeNumberProcessors_0 > 1 && !PoAllProcIntrDisabled )
    {
      KiFreezeOwner = CurrentPrcb;
      CurrentPrcb->IpiFrozen = 4;
      KiSetDebuggerOwner(CurrentPrcb);
      if( !KiFreezeTimeout || *(&WheapErrorSourceTable + 235) )
        v9 = 20000;
      else
        v9 = 20000 * KiFreezeTimeout;
      CurrentPrcb->ClockKeepAlive = 1;
      KeCopyAffinityEx(&Dest, &KeActiveProcessors);
      KeRemoveProcessorAffinityEx(&Dest.Count, CurrentPrcb->Number);
      v10 = KiBugCheckActive;
      if( KiRecoveryInProgress )
        v10 = 0;
      KiSendFreeze(&Dest, (v10 & 3) != 3);
      Context.CurrentMask = Dest.Bitmap[0];
      Context.Affinity = &Dest;
LABEL_21:
      while( 1 )
      {
        KeEnumerateNextProcessor(&ProcIndex, &Context);
        if( v11 )
          break;
        v12 = (__int64)*(&KiProcessorBlock + (unsigned int)ProcIndex);
        while( *(_DWORD *)(v12 + 11656) != 2 )
        {
          if( !v9 )
          {
            KiFreezeFlag |= 2u;
            goto LABEL_21;
          }
          KeStallExecutionProcessor(0x32u);
          --v9;
        }
      }
    }
    KiOldIrql = CurrentIrql;
    if( !PoAllProcIntrDisabled && RtlWriteTryAcquireTickLock() )
    {
      v13 = KeQueryPerformanceCounter(&PerformanceFrequency);
      v14 = *(_QWORD *)&KUSER_SHARED_DATA.InterruptTime.LowPart
          + 10000000 * (v13 - KUSER_SHARED_DATA.BaselineInterruptTimeQpc) / PerformanceFrequency.anonymous_0.LowPart;
      KUSER_SHARED_DATA.InterruptTime.High2Time = HIDWORD(v14);
      *(_QWORD *)&KUSER_SHARED_DATA.InterruptTime.LowPart = v14;
      if( (_DWORD)KeMaximumIncrement )
      {
        KiTickOffset = KeMaximumIncrement * (v14 / (unsigned int)KeMaximumIncrement + 1) - v14;
        KUSER_SHARED_DATA.TickCount.High2Time = (v14 / (unsigned int)KeMaximumIncrement) >> 32;
        KUSER_SHARED_DATA.TickCountQuad = v14 / (unsigned int)KeMaximumIncrement;
      }
      ++KUSER_SHARED_DATA.TimeUpdateLock;
    }
  }
}

Referenced by:

ExpWaitForBootDevices
KdEnterDebugger