PpmInstallPlatformIdleStates
NTSTATUS __stdcall PpmInstallPlatformIdleStates(PLATFORM_IDLE_STATES *PlatformIdleStates){
PLATFORM_IDLE_STATES *v1;
char v2;
NTSTATUS v3;
unsigned int v4;
unsigned int v5;
unsigned int v6;
unsigned int v7;
_DWORD *v8;
int v9;
int v10;
unsigned int v11;
_PPM_IDLE_STATES *IdleStates;
_PPM_PLATFORM_STATES *v13;
unsigned int v14;
size_t v15;
size_t v16;
VOID **PoolWithTag;
_PLATFORM_IDLE_ACCOUNTING *v18;
_PPM_VETO_ENTRY *v19;
__int64 v20;
__int64 v21;
_LIST_ENTRY *p_VetoListHead;
unsigned int *v23;
__int64 v24;
_PPM_SELECTION_DEPENDENCY *v25;
_PPM_SELECTION_MENU_ENTRY *Entries;
_PPM_SELECTION_MENU_ENTRY *v27;
__int64 v28;
__int64 v29;
_UNICODE_STRING v30;
_PPM_SELECTION_MENU_ENTRY *v31;
__int64 v32;
unsigned int v33;
_PPM_SELECTION_DEPENDENCY *DependencyLists;
_PPM_IDLE_STATES *v35;
unsigned int ProcessorIdleCount;
unsigned int i;
_KPRCB *Prcb;
__int64 v39;
_PPM_IDLE_STATES *v40;
__int64 v41;
__int64 v42;
__int64 v43;
__int64 v44;
PLATFORM_IDLE_STATES *v45;
__int64 v46;
__int64 v47;
unsigned int v48;
_PPM_SELECTION_DEPENDENCY *v49;
__int64 v50;
unsigned int Count;
_PPM_SELECTION_MENU_ENTRY *v52;
__int64 v53;
unsigned int ProcessorIndexFromNumber;
_PPM_SELECTION_DEPENDENCY *v55;
__int64 v56;
int v57;
__int64 v58;
_PPM_SELECTION_MENU_ENTRY *v59;
unsigned int j;
__int64 v61;
_PPM_IDLE_STATES *v62;
unsigned int v63;
PLATFORM_IDLE_STATES *v64;
__int64 v65;
bool v66;
unsigned int v68;
unsigned int v69;
_PPM_SELECTION_MENU_ENTRY *v70;
_PPM_SELECTION_DEPENDENCY *v71;
unsigned int v73;
int v74;
_PPM_SELECTION_MENU_ENTRY *v75;
unsigned int v76;
unsigned int ProcessorNumber;
v1 = PlatformIdleStates;
PopAcquireRwLockExclusive((_POP_RW_LOCK *)((char *)&stru_140C23628 + 984));
v2 = 1;
if( PpmPlatformStates && !*((_BYTE *)v1 + 48) )
{
v3 = -1073741431;
LABEL_75:
PopReleaseRwLock((_POP_RW_LOCK *)((char *)&stru_140C23628 + 984));
return v3;
}
v4 = v1[1];
if( !v4 || v1[2] > v4 )
{
LABEL_5:
v3 = -1073741811;
goto LABEL_75;
}
PpmIdleUpdatePlatformDependencies((__int64)v1);
v5 = KeNumberProcessors_0;
v6 = 0;
v7 = v1[2];
v76 = KeNumberProcessors_0;
if( v7 )
{
v8 = v1 + 18;
while( *v8 <= (unsigned int)KeNumberProcessors_0 )
{
++v6;
v8 += 12;
if( v6 >= v7 )
goto LABEL_11;
}
goto LABEL_5;
}
LABEL_11:
v9 = 0;
v10 = 0;
if( v7 )
{
v11 = 0;
if( (_DWORD)KeNumberProcessors_0 )
{
while( 1 )
{
IdleStates = KeGetPrcb(v11)->PowerState.IdleStates;
if( !IdleStates )
goto LABEL_5;
v9 += IdleStates->ProcessorIdleCount;
if( ++v11 >= v5 )
{
v7 = v1[2];
break;
}
}
}
v9 = v7 * (v5 + v9);
v10 = v5 * v7;
}
v13 = (_PPM_PLATFORM_STATES *)PpmPlatformStates;
if( PpmPlatformStates )
{
if( *(_DWORD *)(PpmPlatformStates + 8) != v5
|| *(_DWORD *)PpmPlatformStates != v4
|| (LODWORD(Entries) = v7, *(_DWORD *)(PpmPlatformStates + 4) != 1) )
{
v3 = -1073741811;
goto LABEL_74;
}
}
else
{
v73 = (384 * v4 + 71) & 0xFFFFFFF8;
ProcessorNumber = v73 + 24 * v10;
v14 = ProcessorNumber + 24 * v9;
v69 = (4 * v4 + 15) & 0xFFFFFFF8;
v68 = (v14 + 1008 * v4 + 31) & 0xFFFFFFF8;
v15 = v68 + v5 * v69;
if( *(&stru_140CF2E80 + 972) )
v15 += (v4 * **(&stru_140CF2E80 + 972)) << 6;
v16 = v15;
PoolWithTag = ExAllocatePoolWithTag(0x204ui64, v15, 1766674512i64);
v13 = (_PPM_PLATFORM_STATES *)PoolWithTag;
if( !PoolWithTag )
{
v3 = -1073741670;
goto LABEL_75;
}
memset(PoolWithTag, 0i64, v16);
v13->StateCount = v4;
v13->InterfaceVersion = v1[2] != 0;
v13->ProcessorCount = v5;
v13->IdleTest = (unsigned int(__fastcall *)(void *, unsigned int, unsigned int))*((_QWORD *)v1 + 2);
v13->IdlePreExecute = (int(__fastcall *)(void *, unsigned int, unsigned int, unsigned int, unsigned int *))*((_QWORD *)v1 + 3);
v13->IdleComplete = (void(__fastcall *)(void *, unsigned int, unsigned int, unsigned int, unsigned int *))*((_QWORD *)v1 + 4);
v13->QueryPlatformStateResidency = (int(__fastcall *)(void *, _PROCESSOR_PLATFORM_STATE_RESIDENCIES *))*((_QWORD *)v1 + 5);
v18 = (_PLATFORM_IDLE_ACCOUNTING *)((char *)v13 + v14);
v13->Accounting = v18;
v18->StateCount = v4;
PpmResetPlatformIdleAccounting(v18);
v19 = (_PPM_VETO_ENTRY *)((char *)v13 + v68 + v5 * v69);
v20 = 0i64;
if( v1[1] )
{
do
{
v21 = v20;
v13->State[v20].Platform = 1;
KeQueryActiveProcessorAffinity((INT64)&v13->State[v20].Processors);
v13->State[v20].VetoAccounting.CsAccountingBlocks = 7;
p_VetoListHead = &v13->State[v20].VetoAccounting.VetoListHead;
p_VetoListHead->Blink = p_VetoListHead;
p_VetoListHead->Flink = p_VetoListHead;
if( PpmIdleDisableStatesAtBoot )
v13->State[v21].VetoAccounting.VetoPresent = 0x80000000;
v23 = (unsigned int *)*(&stru_140CF2E80 + 972);
if( *(&stru_140CF2E80 + 972) )
{
if( (_DWORD)v20 == v1[1] - 1 )
v13->State[v21].VetoAccounting.BlocksDrips = 1;
v13->State[v21].VetoAccounting.PreallocatedVetoCount = *v23;
v13->State[v21].VetoAccounting.PreallocatedVetoList = v19;
v19 += *v23;
*(unsigned __int64 *)((char *)&v13->State[0].Processors.Bitmap[126 * (unsigned int)v20 + 7] + v14) = (unsigned __int64)&v13->State[v21].VetoAccounting;
}
v20 = (unsigned int)(v20 + 1);
}
while( (unsigned int)v20 < v1[1] );
v5 = v76;
}
v24 = 0i64;
v25 = (_PPM_SELECTION_DEPENDENCY *)((char *)v13 + v73);
LODWORD(Entries) = v1[2];
v27 = (_PPM_SELECTION_MENU_ENTRY *)((char *)v13 + ProcessorNumber);
v70 = v27;
v74 = 0;
if( (_DWORD)Entries )
{
v28 = 24i64 * v5;
do
{
v29 = v24;
v30 = *(_UNICODE_STRING *)&v1[12 * v24 + 20];
v13->State[v29].DependencyLists = v25;
v25 = (_PPM_SELECTION_DEPENDENCY *)((char *)v25 + v28);
v13->State[v29].DependencyListCount = v5;
v71 = v25;
v13->State[v29].Name = v30;
if( v5 )
{
v31 = v70;
v32 = 0i64;
v33 = 0;
do
{
DependencyLists = v13->State[v29].DependencyLists;
v35 = KeGetPrcb(v33)->PowerState.IdleStates;
DependencyLists[v32++].Processor = v33++;
ProcessorIdleCount = v35->ProcessorIdleCount;
DependencyLists[v32 - 1].Menu.Entries = v31;
DependencyLists[v32 - 1].Menu.Count = ProcessorIdleCount;
v31 += v35->ProcessorIdleCount;
}
while( v33 < v5 );
v25 = v71;
LODWORD(v24) = v74;
v28 = 24i64 * v5;
v70 = v31;
v1 = PlatformIdleStates;
}
LODWORD(Entries) = v1[2];
v24 = (unsigned int)(v24 + 1);
v74 = v24;
}
while( (unsigned int)v24 < (unsigned int)Entries );
v27 = v70;
}
for( i = 0; i < v5; ++i )
{
Prcb = KeGetPrcb(i);
v39 = 0i64;
v40 = Prcb->PowerState.IdleStates;
v40->CoordinatedTracing = (_PERFINFO_PPM_STATE_SELECTION *)((char *)v13 + v68 + i * v69);
v40->CoordinatedMenu.Count = v1[2];
v40->CoordinatedMenu.Entries = v27;
Entries = (_PPM_SELECTION_MENU_ENTRY *)(unsigned int)v1[2];
v27 += (__int64)Entries;
if( (_DWORD)Entries )
{
do
{
v41 = v39;
v42 = (unsigned int)((_DWORD)Entries - v39 - 1);
Entries = v40->CoordinatedMenu.Entries;
Entries[v42].StateIndex = v39;
v39 = (unsigned int)(v39 + 1);
Entries[v42].Dependencies = v13->State[v41].DependencyListCount;
Entries[v42].DependencyList = v13->State[v41].DependencyLists;
LODWORD(Entries) = v1[2];
}
while( (unsigned int)v39 < (unsigned int)Entries );
}
}
}
v43 = 0i64;
if( (_DWORD)Entries )
{
do
{
v44 = 0i64;
v45 = &v1[12 * v43];
v46 = v43;
v13->State[v46].Latency = v45[16];
v13->State[v46].BreakEvenDuration = v45[17];
if( v45[18] )
{
do
{
v47 = *((_QWORD *)v45 + 12);
v48 = 0;
v49 = v13->State[v46].DependencyLists;
v50 = *(unsigned int *)(v47 + 8 * v44);
Count = v49[*(unsigned int *)(v47 + 8 * v44)].Menu.Count;
if( Count )
{
do
{
v52 = v49[v50].Menu.Entries;
v53 = Count - v48 - 1;
*(_OWORD *)&v52[v53].StrictDependency = 0i64;
v52[v53].DependencyList = 0i64;
v52[v53].StateIndex = v48;
if( !*((_BYTE *)v45 + 60) && v48 == *((unsigned __int8 *)v45 + 61) )
v52[Count - v48 - 1].InitiatingState = 1;
if( v48 >= *(unsigned __int8 *)(v47 + 8 * v44 + 4) )
{
v52[Count - v48 - 1].DependentState = 1;
if( !*(_BYTE *)(v47 + 8 * v44 + 6) )
v52[Count - v48 - 1].StrictDependency = 1;
}
Count = v49[v50].Menu.Count;
++v48;
}
while( v48 < Count );
}
v44 = (unsigned int)(v44 + 1);
}
while( (unsigned int)v44 < v45[18] );
}
if( *((_BYTE *)v45 + 60) )
{
ProcessorIndexFromNumber = KeGetProcessorIndexFromNumber((UINT16 *)v45 + 28);
v55 = v13->State[v46].DependencyLists;
v56 = ProcessorIndexFromNumber;
memset(v55[ProcessorIndexFromNumber].Menu.Entries, 0i64, 24 * v55[ProcessorIndexFromNumber].Menu.Count);
v57 = *((unsigned __int8 *)v45 + 61);
v58 = v55[v56].Menu.Count - v57 - 1;
v59 = v55[v56].Menu.Entries;
v59[v58].StateIndex = v57;
v59[v58].InitiatingState = 1;
}
v43 = (unsigned int)(v43 + 1);
}
while( (unsigned int)v43 < v1[2] );
v5 = v76;
}
for( j = 0; j < v5; ++j )
{
v61 = 0i64;
v62 = KeGetPrcb(j)->PowerState.IdleStates;
v63 = v62->CoordinatedMenu.Count;
if( v63 )
{
do
{
v64 = &v1[12 * v61 + 14];
v65 = v63 - (unsigned int)v61 - 1;
v75 = v62->CoordinatedMenu.Entries;
v66 = !*((_BYTE *)v64 + 4) || KeGetProcessorIndexFromNumber((UINT16 *)v64) == j;
v61 = (unsigned int)(v61 + 1);
v75[v65].InitiatingState = v66;
v63 = v62->CoordinatedMenu.Count;
}
while( (unsigned int)v61 < v63 );
}
}
if( !PpmPlatformStates )
{
PpmEnableCoordinatedIdleStates(v13, 0);
v2 = 0;
}
v3 = 0;
LABEL_74:
if( v2 )
goto LABEL_75;
return v3;
}Referenced by:
No references.