PopCheckAndHandleThermalConditions

VOID __stdcall PopCheckAndHandleThermalConditions(_POP_THERMAL_ZONE *ThermalZone){
  _DEVICE_OBJECT *v1; 
  char v3; 
  char v4; 
  UINT8 v5; 
  _DEVICE_OBJECT *DeviceAttachmentBaseRefWithTag; 
  POWER_POLICY_DEVICE_TYPE v7; 
  char v8; 
  char v9; 
  POWER_ACTION_POLICY ActionPolicy; 
  _POP_ACTION_TRIGGER Trigger; 

  v1 = (_DEVICE_OBJECT *)*((_QWORD *)ThermalZone + 6);
  v3 = 0;
  v4 = 0;
  memset(&Trigger, 0, sizeof(Trigger));
  if( *((_BYTE *)ThermalZone + 210) && !*((_BYTE *)ThermalZone + 71) )
  {
    v3 = 1;
    PopSqmThermalCriticalShutdown(ThermalZone);
    PopDiagTraceZoneCriticalTripPointExceeded((_THERMAL_INFORMATION_EX *)((char *)ThermalZone + 112), v1);
    *((_BYTE *)ThermalZone + 71) = 1;
  }
  if( *((_BYTE *)ThermalZone + 209) )
  {
    v4 = 1;
    PopDiagTraceZoneS4TripPointExceeded((_THERMAL_INFORMATION_EX *)((char *)ThermalZone + 112), v1);
    PopSqmThermalHibernate(ThermalZone);
  }
  else if( !v3 )
  {
    goto LABEL_4;
  }
  PopAcquirePolicyLock();
  if( v4 )
  {
    if( PopIsHibernateSupported((_BYTE *)&stru_140C23628 + 2072) )
    {
      PopThermalHibernateInitiated = 1;
      PopAcquireRwLockExclusive(&PopSystemThermalInfo);
      PopThermalStandbyEndTracking(2ui64);
      PopReleaseRwLock(&PopSystemThermalInfo);
      ActionPolicy.EventCode = 0;
      ActionPolicy.Action = PowerActionHibernate;
      ActionPolicy.Flags = -1073741820;
      Trigger.Type = PolicyDeviceThermalZone;
      Trigger.Flags = 128;
      *(_OWORD *)&Trigger.Wait = 0i64;
      PopExecutePowerAction(
        &Trigger,
        0i64,
        &ActionPolicy,
        PowerSystemHibernate,
        SubstituteLightestOverallDownwardBounded);
    }
    else
    {
      v3 = 1;
    }
  }
  if( v3 )
  {
    DeviceAttachmentBaseRefWithTag = IoGetDeviceAttachmentBaseRefWithTag(v1, 0x6D546F50ui64);
    PopThermalWriteShutdownToRegistry();
    if( DeviceAttachmentBaseRefWithTag )
      ObfDereferenceObjectWithTag(DeviceAttachmentBaseRefWithTag, 0x6D546F50ui64);
    if( !PopThermalCriticalShutdownInitiated )
    {
      PopAcquireRwLockExclusive(&PopSystemThermalInfo);
      PopThermalStandbyEndTracking(3ui64);
      PopReleaseRwLock(&PopSystemThermalInfo);
      PopThermalCriticalShutdownInitiated = 1;
      if( PopThermalCriticalShutdownEnabled )
        PopCriticalShutdown(v7);
    }
  }
  PopReleasePolicyLock();
LABEL_4:
  v5 = *((_BYTE *)ThermalZone + 224) != 0;
  if( *((_BYTE *)ThermalZone + 73) != v5 )
  {
    *((_BYTE *)ThermalZone + 73) = v5;
    PopUpdateOverThrottledCount(ThermalZone, v5);
  }
  if( *((_BYTE *)ThermalZone + 72) != *((_BYTE *)ThermalZone + 211) )
  {
    PopDiagTraceThermalStandbyState(*((_DEVICE_OBJECT **)ThermalZone + 6), *((unsigned __int8 *)ThermalZone + 211));
    PopAcquireRwLockExclusive(&PopSystemThermalInfo);
    v8 = *((_BYTE *)ThermalZone + 211);
    *((_BYTE *)ThermalZone + 72) = v8;
    if( v8 )
    {
      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(&PopSystemThermalInfo);
        return;
      }
    }
    if( !v4 && v9 && (_BYTE)word_140C22C50 && !HIBYTE(word_140C22C50) )
    {
      PopThermalStandbyNotify(1u);
      word_140C22C50 = 256;
    }
    goto LABEL_34;
  }
}

Referenced by:

PopThermalWorker