PopAssociateThermalRequest

NTSTATUS __stdcall PopAssociateThermalRequest(
        POP_COOLING_REQUEST *Request,
        _DEVICE_OBJECT *DeviceObject,
        UINT8 Protected){
  _POP_COOLING_EXTENSION *v6; 
  _DEVICE_OBJECT_POWER_EXTENSION *Dope; 
  VOID **PoolWithTag; 
  int v9; 
  _POP_COOLING_EXTENSION **v10; 
  _POP_COOLING_EXTENSION *CoolingExtension; 
  _LIST_ENTRY *p_RequestListHead; 
  POP_COOLING_REQUEST **Blink; 
  __int64 v14; 

  v6 = 0i64;
  Dope = PopGetDope(DeviceObject);
  if( !Dope )
    return -1073741670;
  PopAcquireRwLockExclusive(&PopCoolingExtensionLock);
  if( Dope->CoolingExtension )
    goto LABEL_9;
  PopReleaseRwLock(&PopCoolingExtensionLock);
  PoolWithTag = ExAllocatePoolWithTag(1ui64, 0x90ui64, 1819231056i64);
  v6 = (_POP_COOLING_EXTENSION *)PoolWithTag;
  if( !PoolWithTag )
    return -1073741670;
  memset(PoolWithTag, 0i64, 0x90u);
  v6->RequestListHead.Blink = &v6->RequestListHead;
  v6->RequestListHead.Flink = &v6->RequestListHead;
  v6->Lock.Thread = 0i64;
  v6->Lock.Lock._bf_0 = 0i64;
  v6->ThrottleLimit = 100;
  v6->DeviceObject = DeviceObject;
  v9 = PopAcquireCoolingInterface((POP_COOLING_EXTENSION *)v6);
  if( v9 >= 0 )
  {
    v6->Enabled = 1;
    if( !Protected || (v9 = PopRegisterCoolingExtensionProtection((POP_COOLING_EXTENSION *)v6), v9 >= 0) )
    {
      PopAcquireRwLockExclusive(&PopCoolingExtensionLock);
      if( !Dope->CoolingExtension )
      {
        v10 = (_POP_COOLING_EXTENSION **)qword_140C23098;
        if( *(__int64 **)qword_140C23098 != &PopCoolingExtensionList )
          goto LABEL_24;
        v6->Link.Flink = (_LIST_ENTRY *)&PopCoolingExtensionList;
        v6->Link.Blink = (_LIST_ENTRY *)v10;
        *v10 = v6;
        qword_140C23098 = (__int64)v6;
        Dope->CoolingExtension = v6;
        PopDiagTraceCoolingExtension((__int64)v6, (const _EVENT_DESCRIPTOR *)POP_ETW_EVENT_COOLING_EXTENSION_ADD);
        v6 = 0i64;
        Protected = 0;
      }
LABEL_9:
      if( Protected )
      {
        v9 = PopRegisterCoolingExtensionProtection((POP_COOLING_EXTENSION *)Dope->CoolingExtension);
        if( v9 < 0 )
        {
          PopReleaseRwLock(&PopCoolingExtensionLock);
          goto LABEL_16;
        }
      }
      PopAcquireRwLockExclusive(&Dope->CoolingExtension->Lock);
      CoolingExtension = Dope->CoolingExtension;
      *((_QWORD *)Request + 4) = CoolingExtension;
      p_RequestListHead = &CoolingExtension->RequestListHead;
      Blink = (POP_COOLING_REQUEST **)p_RequestListHead->Blink;
      if( *Blink == (POP_COOLING_REQUEST *)p_RequestListHead )
      {
        *((_QWORD *)Request + 1) = Blink;
        *(_QWORD *)Request = p_RequestListHead;
        *Blink = Request;
        p_RequestListHead->Blink = (_LIST_ENTRY *)Request;
        *((_BYTE *)Request + 18) = 1;
        PopDiagTraceThermalRequest(Request, POP_ETW_EVENT_THERMAL_REQUEST_ADD);
        v14 = *((_QWORD *)Request + 4);
        if( *(_QWORD *)(v14 + 136) )
        {
          PopThermalUpdateTelemetryClientCount(1u);
          v14 = *((_QWORD *)Request + 4);
        }
        if( *(_QWORD *)(v14 + 128) )
          *((_BYTE *)Request + 41) = 1;
        PopReleaseRwLock(&Dope->CoolingExtension->Lock);
        PopReleaseRwLock(&PopCoolingExtensionLock);
        v9 = 0;
        goto LABEL_16;
      }
LABEL_24:
      __fastfail(3u);
    }
  }
LABEL_16:
  if( v6 )
    PopCleanCoolingExtension(v6);
  return v9;
}

Referenced by:

PoCreateThermalRequest