KdDisableDebuggerWithLock

NTSTATUS __stdcall KdDisableDebuggerWithLock(UINT8 TakeLock){
  unsigned __int8 CurrentIrql; 
  int v3; 

  if( KdPitchDebugger )
    return -1073740972;
  if( KdBlockEnable )
    return -1073741790;
  CurrentIrql = KeGetCurrentIrql();
  __writecr8(2ui64);
  KxAcquireSpinLock(&KdDebuggerLock);
  if( KdDisableCount )
    goto LABEL_11;
  KdPreviouslyEnabled = (char)KdDebuggerEnabled;
  if( !(_BYTE)KdDebuggerEnabled || (v3 = KdpAllowDisable(), v3 >= 0) )
  {
    if( (_BYTE)KdDebuggerEnabled )
    {
      KdpSuspendAllBreakpoints();
      KUSER_SHARED_DATA.KdDebuggerEnabled = 0;
      dword_140C50A74 = 0;
      LOBYTE(KdDebuggerNotPresent) = 1;
      LOBYTE(KdDebuggerEnabled) = 0;
      KdPowerTransitionEx(1073741828i64, 0);
    }
LABEL_11:
    ++KdDisableCount;
    KxReleaseSpinLock(&KdDebuggerLock);
    v3 = 0;
    goto LABEL_12;
  }
  KxReleaseSpinLock(&KdDebuggerLock);
LABEL_12:
  __writecr8(CurrentIrql);
  return v3;
}

Referenced by:

KdDisableDebugger
KdInitSystem