KiFreezeTargetExecution

VOID __stdcall KiFreezeTargetExecution(_KTRAP_FRAME *TrapFrame, _KTRAP_FRAME *ExceptionFrame){
  __int16 v4; 
  bool v5; 
  unsigned __int8 CurrentIrql; 
  struct _KPRCB *CurrentPrcb; 
  __int64 v8; 
  volatile signed __int32 *SchedulerAssist; 
  __int64 v10; 
  volatile signed __int32 *v11; 
  unsigned __int64 v12; 
  unsigned __int64 v13; 
  _EXCEPTION_RECORD ExceptionRecord; 
  int v15; 

  memset(&ExceptionRecord, 0i64, sizeof(ExceptionRecord));
  if( KiFreezeExecutionLock || KiFreezeLockBackup || (KiBugCheckActive & 3) != 0 )
  {
    if( ViVerifierEnabled )
      VfStopBranchTracing();
    v4 = v15;
    _disable();
    v5 = (v4 & 0x200) != 0;
    CurrentIrql = KeGetCurrentIrql();
    __writecr8(0xFui64);
    CurrentPrcb = KeGetCurrentPrcb();
    KeSaveSupervisorState(
      (INT64)CurrentPrcb->ExtendedSupervisorState,
      KUSER_SHARED_DATA.XState.EnabledSupervisorFeatures | 0x100);
    KiStartDebugAccumulation(CurrentPrcb);
    CurrentPrcb->IpiFrozen = 2;
    LOBYTE(v8) = 1;
    ((void(__fastcall *)(__int64, _QWORD))off_140C00738[0])(v8, 0i64);
    if( TrapFrame )
    {
      KiSaveProcessorState(TrapFrame, ExceptionFrame);
    }
    else
    {
      RtlCaptureContext(CurrentPrcb->Context);
      KiSaveProcessorControlState(&CurrentPrcb->ProcessorState);
    }
    SchedulerAssist = (volatile signed __int32 *)CurrentPrcb->SchedulerAssist;
    if( SchedulerAssist )
      _InterlockedOr(SchedulerAssist, 0x20000u);
    KeQueryPerformanceCounter(0i64);
    while( (CurrentPrcb->IpiFrozen & 0xF) == 2 )
    {
      if( CurrentPrcb == (struct _KPRCB *)KiDebuggerOwner )
      {
        memset(&ExceptionRecord, 0i64, sizeof(ExceptionRecord));
        ExceptionRecord.ExceptionCode = -2147483641;
        ExceptionRecord.ExceptionRecord = &ExceptionRecord;
        ExceptionRecord.ExceptionAddress = (void *)CurrentPrcb->Context->_Rip;
        if( KdpReportExceptionStateChange(&ExceptionRecord, (_FILETIME *)CurrentPrcb->Context, 0) != 3 )
          KiSetDebuggerOwner(KiFreezeOwner);
      }
      KiCheckStall(CurrentPrcb, 1u);
    }
    v11 = (volatile signed __int32 *)CurrentPrcb->SchedulerAssist;
    if( v11 )
      _InterlockedAnd(v11, 0xFFFDFFFF);
    LOBYTE(v10) = KiResumeForReboot;
    ((void(__fastcall *)(_QWORD, __int64))off_140C00738[0])(0i64, v10);
    if( TrapFrame )
      KiRestoreProcessorState(TrapFrame);
    else
      KiRestoreProcessorControlState(&CurrentPrcb->ProcessorState);
    v12 = __readcr4();
    if( (v12 & 0x20080) != 0 )
    {
      __writecr4(v12 ^ 0x80);
      __writecr4(v12);
    }
    else
    {
      v13 = __readcr3();
      __writecr3(v13);
    }
    CurrentPrcb->IpiFrozen = 0;
    KiEndDebugAccumulation(CurrentPrcb);
    KeRestoreSupervisorState(
      (INT64)CurrentPrcb->ExtendedSupervisorState,
      KUSER_SHARED_DATA.XState.EnabledSupervisorFeatures | 0x100);
    __writecr8(CurrentIrql);
    if( v5 )
      _enable();
    if( ViVerifierEnabled )
      VfStartBranchTracing();
  }
}

Referenced by:

KiCheckForFreezeExecution