PpmInstallCoordinatedIdleStates
NTSTATUS __stdcall PpmInstallCoordinatedIdleStates(_COORDINATED_IDLE_STATES *CoordinatedIdleStates){
_COORDINATED_IDLE_STATES *v1;
char v2;
int updated;
__int64 v4;
unsigned int v5;
int v6;
int v7;
_DWORD *v8;
__int64 v9;
int v10;
int v11;
_PPM_PLATFORM_STATES *v12;
unsigned int v13;
unsigned int v14;
size_t v15;
size_t v16;
VOID **PoolWithTag;
_PLATFORM_IDLE_ACCOUNTING *v18;
__int64 v19;
_PPM_VETO_ENTRY *i;
__int64 v21;
_LIST_ENTRY *p_VetoListHead;
unsigned int *v23;
_PPM_SELECTION_MENU_ENTRY *v24;
char *v25;
_DWORD *v26;
__int64 v27;
char *v28;
_KAFFINITY_EX *p_Processors;
__int64 v30;
__int64 v31;
__int64 v32;
unsigned int v33;
unsigned int *v34;
_KPRCB *Prcb;
unsigned int v36;
_PPM_IDLE_STATES *IdleStates;
_PPM_SELECTION_DEPENDENCY **p_DependencyLists;
_PPM_SELECTION_MENU_ENTRY *Entries;
__int64 v40;
_PPM_SELECTION_DEPENDENCY *v41;
unsigned int *p_BreakEvenDuration;
_COORDINATED_IDLE_STATES *v43;
__int64 v44;
__int64 v45;
__int64 v46;
__int64 v47;
__int64 v48;
__int64 v49;
unsigned int v50;
__int64 v51;
__int64 v52;
__int64 v53;
int v54;
__int64 v55;
_PPM_SELECTION_DEPENDENCY *DependencyLists;
unsigned int j;
unsigned int v58;
_PPM_IDLE_STATES *k;
UINT8 v60;
__int64 v61;
__int64 v62;
unsigned int v64;
int v65;
int v66;
unsigned int v67;
unsigned int v69;
size_t v70;
unsigned int v71;
v1 = CoordinatedIdleStates;
PopAcquireRwLockExclusive((_POP_RW_LOCK *)((char *)&stru_140C23628 + 984));
v2 = 1;
if( PpmPlatformStates && !*((_BYTE *)v1 + 40) )
{
updated = -1073741431;
LABEL_51:
PopReleaseRwLock((_POP_RW_LOCK *)((char *)&stru_140C23628 + 984));
return updated;
}
updated = PpmIdleUpdateCoordinatedDependencies(v1);
if( updated < 0 )
goto LABEL_51;
v4 = (unsigned int)*v1;
v67 = v4;
if( !(_DWORD)v4 )
{
updated = -1073741811;
goto LABEL_51;
}
v5 = KeNumberProcessors_0;
v6 = 0;
v69 = KeNumberProcessors_0;
v7 = KeNumberProcessors_0 * v4;
v8 = v1 + 62;
v9 = (unsigned int)*v1;
do
{
v10 = v8[1];
v6 += v10;
v11 = *v8 * v10;
v8 += 56;
v7 += v11;
--v9;
}
while( v9 );
v12 = (_PPM_PLATFORM_STATES *)PpmPlatformStates;
if( PpmPlatformStates )
{
if( *(_DWORD *)(PpmPlatformStates + 8) != (_DWORD)KeNumberProcessors_0
|| *(_QWORD *)PpmPlatformStates != ((unsigned int)v4 | 0x100000000i64) )
{
updated = -1073741811;
goto LABEL_50;
}
}
else
{
v13 = (384 * v4 + 71) & 0xFFFFFFF8;
v71 = v13 + 24 * v6;
v64 = v71 + 24 * v7;
v14 = (v64 + 4 * KeNumberProcessors_0 * v4 + 7) & 0xFFFFFFF8;
v65 = (4 * v4 + 15) & 0xFFFFFFF8;
v15 = ((v14 + 1008 * v4 + 31) & 0xFFFFFFF8) + KeNumberProcessors_0 * v65;
v66 = (v14 + 1008 * v4 + 31) & 0xFFFFFFF8;
v70 = v15;
if( *(&stru_140CF2E80 + 972) )
v15 += ((_DWORD)v4 * **(&stru_140CF2E80 + 972)) << 6;
v16 = v15;
PoolWithTag = ExAllocatePoolWithTag(0x204ui64, v15, 1766674512i64);
v12 = (_PPM_PLATFORM_STATES *)PoolWithTag;
if( !PoolWithTag )
{
updated = -1073741670;
goto LABEL_51;
}
memset(PoolWithTag, 0i64, v16);
v12->StateCount = v4;
v12->InterfaceVersion = 1;
v12->CoordinatedInterface = 1;
v12->ProcessorCount = v5;
v12->IdleTest = (unsigned int(__fastcall *)(void *, unsigned int, unsigned int))*((_QWORD *)v1 + 1);
v12->IdlePreExecute = (int(__fastcall *)(void *, unsigned int, unsigned int, unsigned int, unsigned int *))*((_QWORD *)v1 + 2);
v12->IdleComplete = (void(__fastcall *)(void *, unsigned int, unsigned int, unsigned int, unsigned int *))*((_QWORD *)v1 + 3);
v12->QueryPlatformStateResidency = (int(__fastcall *)(void *, _PROCESSOR_PLATFORM_STATE_RESIDENCIES *))*((_QWORD *)v1 + 4);
v18 = (_PLATFORM_IDLE_ACCOUNTING *)((char *)v12 + v14);
v12->Accounting = v18;
v18->StateCount = v4;
PpmResetPlatformIdleAccounting(v18);
v19 = 0i64;
for( i = (_PPM_VETO_ENTRY *)((char *)v12 + v70); (unsigned int)v19 < *v1; v19 = (unsigned int)(v19 + 1) )
{
v21 = v19;
p_VetoListHead = &v12->State[v19].VetoAccounting.VetoListHead;
p_VetoListHead->Blink = p_VetoListHead;
p_VetoListHead->Flink = p_VetoListHead;
v12->State[v19].VetoAccounting.CsAccountingBlocks = 7;
if( PpmIdleDisableStatesAtBoot )
v12->State[v21].VetoAccounting.VetoPresent = 0x80000000;
v23 = (unsigned int *)*(&stru_140CF2E80 + 972);
if( *(&stru_140CF2E80 + 972) )
{
if( (_DWORD)v19 == *v1 - 1 )
v12->State[v21].VetoAccounting.BlocksDrips = 1;
v12->State[v21].VetoAccounting.PreallocatedVetoCount = *v23;
v12->State[v21].VetoAccounting.PreallocatedVetoList = i;
i += *v23;
v18->State[(unsigned int)v19].SelectionStatistics.PreVetoAccounting = &v12->State[v21].VetoAccounting;
}
}
v24 = (_PPM_SELECTION_MENU_ENTRY *)((char *)v12 + v71);
v25 = (char *)v12 + v13;
v26 = v1 + 63;
v27 = v4;
v28 = v25;
p_Processors = &v12->State[0].Processors;
do
{
*(_OWORD *)&p_Processors[1].Count = *(_OWORD *)(v26 - 9);
p_Processors[-1].Bitmap[12] = *(_QWORD *)(v26 - 5);
KeCopyAffinityEx(p_Processors, (_KAFFINITY_EX *)(v26 - 51));
v30 = 0i64;
HIDWORD(p_Processors[-1].Bitmap[19]) = *v26;
p_Processors[1].Bitmap[1] = (unsigned __int64)v28;
v31 = (unsigned int)*v26;
v28 += 24 * v31;
if( (_DWORD)v31 )
{
do
{
v32 = 3 * v30;
v30 = (unsigned int)(v30 + 1);
*(_QWORD *)(p_Processors[1].Bitmap[1] + 8 * v32 + 16) = v24;
v24 += (unsigned int)*(v26 - 1);
}
while( (unsigned int)v30 < *v26 );
}
v26 += 56;
p_Processors = (_KAFFINITY_EX *)((char *)p_Processors + 384);
--v27;
}
while( v27 );
v1 = CoordinatedIdleStates;
v33 = 0;
v34 = (unsigned int *)((char *)&v12->StateCount + v64);
if( v69 )
{
do
{
Prcb = KeGetPrcb(v33);
v36 = 0;
IdleStates = Prcb->PowerState.IdleStates;
IdleStates->CoordinatedMenu.Entries = v24;
v24 += v4;
IdleStates->CoordinatedSelection.Selection = v34;
v34 += v4;
IdleStates->CoordinatedMenu.Count = v4;
IdleStates->CoordinatedTracing = (_PERFINFO_PPM_STATE_SELECTION *)((char *)v12 + v66 + v33 * v65);
IdleStates->CoordinatedSelection.MaximumStates = v4;
p_DependencyLists = &v12->State[0].DependencyLists;
do
{
Entries = IdleStates->CoordinatedMenu.Entries;
v40 = (unsigned int)v4 - v36 - 1;
Entries[v40].StateIndex = v36++;
Entries[v40].Dependencies = *((_DWORD *)p_DependencyLists - 47);
v41 = *p_DependencyLists;
p_DependencyLists += 48;
Entries[v40].DependencyList = v41;
}
while( v36 < (unsigned int)v4 );
++v33;
}
while( v33 < v69 );
v1 = CoordinatedIdleStates;
}
}
p_BreakEvenDuration = &v12->State[0].BreakEvenDuration;
v43 = v1 + 61;
v44 = v4;
do
{
v45 = 0i64;
*(p_BreakEvenDuration - 1) = *(v43 - 1);
*p_BreakEvenDuration = *v43;
for( *((_BYTE *)p_BreakEvenDuration + 45) = *((_BYTE *)v43 + 12);
(unsigned int)v45 < v43[2];
v45 = (unsigned int)(v45 + 1) )
{
v46 = *(_QWORD *)(p_BreakEvenDuration + 59);
v47 = 3 * v45;
v48 = 0i64;
v49 = *(_QWORD *)(v43 + 5) + 16i64 * (unsigned int)v45;
*(_DWORD *)(v46 + 8 * v47) = *(_DWORD *)v49;
*(_DWORD *)(v46 + 8 * v47 + 8) = *(_DWORD *)(v49 + 4);
v50 = *(_DWORD *)(v49 + 4);
if( v50 )
{
do
{
v51 = *(_QWORD *)(v49 + 8);
v52 = *(_QWORD *)(v46 + 24 * v45 + 16);
v53 = 3i64 * (v50 - (unsigned int)v48 - 1);
v54 = *(unsigned __int8 *)(v51 + 4 * v48);
*(_DWORD *)(v52 + 8 * v53 + 4) = v54;
*(_BYTE *)(v52 + 8 * v53) = *(_BYTE *)(v51 + 4 * v48 + 1) == 0;
*(_BYTE *)(v52 + 8 * v53 + 1) = *(_BYTE *)(v51 + 4 * v48 + 2);
*(_BYTE *)(v52 + 8 * v53 + 2) = *(_BYTE *)(v51 + 4 * v48 + 3);
if( *(_DWORD *)(v46 + 24 * v45) == -1 )
{
v55 = (unsigned __int8)v54;
*(_DWORD *)(v52 + 8 * v53 + 8) = v12->State[v55].DependencyListCount;
DependencyLists = v12->State[v55].DependencyLists;
}
else
{
*(_DWORD *)(v52 + 8 * v53 + 8) = 0;
DependencyLists = 0i64;
}
*(_QWORD *)(v52 + 8 * v53 + 16) = DependencyLists;
v48 = (unsigned int)(v48 + 1);
v50 = *(_DWORD *)(v49 + 4);
}
while( (unsigned int)v48 < v50 );
}
}
p_BreakEvenDuration += 96;
v43 += 56;
--v44;
}
while( v44 );
for( j = 0; j < v69; ++j )
{
v58 = 0;
for( k = KeGetPrcb(j)->PowerState.IdleStates; v58 < v67; *(_BYTE *)(v61 + 8 * v62 + 1) = v60 )
{
v60 = PpmCheckCoordinatedStateInitiator(
j,
k->CoordinatedMenu.Entries[v67 - v58 - 1].Dependencies,
k->CoordinatedMenu.Entries[v67 - v58 - 1].DependencyList);
++v58;
}
}
if( !PpmPlatformStates )
{
PpmEnableCoordinatedIdleStates(v12, 1u);
v2 = 0;
}
updated = 0;
LABEL_50:
if( v2 )
goto LABEL_51;
return updated;
}Referenced by:
No references.