PopCheckAndHandleThermalConditions

VOID __fastcall PopCheckAndHandleThermalConditions(_POP_THERMAL_ZONE *ThermalZone){
  _DEVICE_OBJECT *Device; 
  char v3; 
  char v4; 
  unsigned __int8 v5; 
  DEVICE_OBJECT *DeviceAttachmentBaseRefWithTag; 
  POWER_POLICY_DEVICE_TYPE v7; 
  unsigned __int8 ThermalStandby; 
  char v9; 
  UINT64 a5; 
  INT64 a3; 
  int v12; 
  INT64 a1[4]; 
  Device = ThermalZone->PolicyDevice.Device;
  v3 = 0;
  v4 = 0;
  memset(a1, 0, 24);
  if( ThermalZone->Policy.Critical && !ThermalZone->Critical )
  {
    v3 = 1;
    PopSqmThermalCriticalShutdown(ThermalZone);
    PopDiagTraceZoneCriticalTripPointExceeded(&ThermalZone->Info, Device);
    ThermalZone->Critical = 1;
  }
  if( ThermalZone->Policy.Hibernate )
  {
    v4 = 1;
    PopDiagTraceZoneS4TripPointExceeded(&ThermalZone->Info, Device);
    PopSqmThermalHibernate(ThermalZone);
  }
  else if( !v3 )
  {
    goto LABEL_4;
  }
  PopAcquirePolicyLock();
  if( v4 )
  {
    if( PopIsHibernateSupported(&PopCapabilities) )
    {
      PopThermalHibernateInitiated = 1;
      PopAcquireRwLockExclusive(&PopSystemThermalInfo);
      PopThermalStandbyEndTracking(2ui64);
      PopReleaseRwLock((UINT64)&PopSystemThermalInfo);
      v12 = 0;
      a3 = 0xC000000400000003ui64;
      a1[0] = 0x8000000001i64;
      *(_OWORD *)&a1[1] = 0i64;
      LODWORD(a5) = 1;
      PopExecutePowerAction((INT64)a1, 0i64, (INT64)&a3, 5i64, a5);
    }
    else
    {
      v3 = 1;
    }
  }
  if( v3 )
  {
    DeviceAttachmentBaseRefWithTag = IoGetDeviceAttachmentBaseRefWithTag(Device, 0x6D546F50ui64);
    PopThermalWriteShutdownToRegistry();
    if( DeviceAttachmentBaseRefWithTag )
      ObfDereferenceObjectWithTag(DeviceAttachmentBaseRefWithTag, 0x6D546F50ui64);
    if( !PopThermalCriticalShutdownInitiated )
    {
      PopAcquireRwLockExclusive(&PopSystemThermalInfo);
      PopThermalStandbyEndTracking(3ui64);
      PopReleaseRwLock((UINT64)&PopSystemThermalInfo);
      PopThermalCriticalShutdownInitiated = 1;
      if( PopThermalCriticalShutdownEnabled )
        PopCriticalShutdown(v7);
    }
  }
  PopReleasePolicyLock();
LABEL_4:
  v5 = ThermalZone->Policy.OverThrottled != 0;
  if( ThermalZone->OverThrottled != v5 )
  {
    ThermalZone->OverThrottled = v5;
    PopUpdateOverThrottledCount(ThermalZone, v5);
  }
  if( ThermalZone->ThermalStandby != ThermalZone->Policy.ThermalStandby )
  {
    PopDiagTraceThermalStandbyState(ThermalZone->PolicyDevice.Device, ThermalZone->Policy.ThermalStandby);
    PopAcquireRwLockExclusive(&PopSystemThermalInfo);
    ThermalStandby = ThermalZone->Policy.ThermalStandby;
    ThermalZone->ThermalStandby = ThermalStandby;
    if( ThermalStandby )
    {
      if( ++dword_140C22C54 == 1 )
      {
        FirstThermalStandby = 1;
        LODWORD(GenerationId) = GenerationId + 1;
        PopTraceCr3Tripped((unsigned int)GenerationId);
      }
      PopTraceZoneCr3Tripped((unsigned int)GenerationId, ThermalZone);
    }
    else
    {
      PopTraceZoneCr3Mitigated((unsigned int)GenerationId, ThermalZone);
      --dword_140C22C54;
    }
    if( dword_140C22C54 )
    {
      v9 = 1;
    }
    else
    {
      v9 = 0;
      PopThermalStandbyEndTracking(0i64);
      PopTraceCr3Mitigated((unsigned int)GenerationId);
      if( HIBYTE(word_140C22C50) )
      {
        PopThermalStandbyNotify(0);
        HIBYTE(word_140C22C50) = 0;
LABEL_34:
        PopReleaseRwLock((UINT64)&PopSystemThermalInfo);
        return;
      }
    }
    if( !v4 && v9 && (_BYTE)word_140C22C50 && !HIBYTE(word_140C22C50) )
    {
      PopThermalStandbyNotify(1u);
      word_140C22C50 = 256;
    }
    goto LABEL_34;
  }
}

Referenced by:

PopThermalWorker