MiCombineAllPhysicalMemory
NTSTATUS __stdcall MiCombineAllPhysicalMemory(_MI_COMBINE_CONTROL_BLOCK *CombineControlBlock){
_MI_PAGE_COMBINING_SUPPORT *v1;
_MI_COMBINE_CONTROL_BLOCK *v2;
__int64 v3;
NTSTATUS v4;
__int64 v5;
unsigned int v6;
__int64 v7;
unsigned int v8;
unsigned __int64 v9;
_MI_PAGE_CRCS *v10;
void *v11;
char *v12;
unsigned __int64 Mask;
_GROUP_AFFINITY *p_PreviousAffinity;
unsigned int v15;
unsigned int v16;
_PHYSICAL_MEMORY_RUN *v17;
unsigned __int64 *p_PageCount;
unsigned __int64 v19;
__int64 v20;
_MMPFN *v21;
_MMPTE *PteAddress;
int v23;
__int64 v24;
NTSTATUS PfnPageSizeIndexUnsynchronized;
unsigned __int64 v26;
VOID *v27;
_MI_ARBITRARY_PAGE_MAP *v28;
_MI_ARBITRARY_PAGE_MAP *v29;
_MI_PAGE_COMBINING_SUPPORT *v30;
NTSTATUS v31;
bool v32;
unsigned __int64 v33;
unsigned __int64 v34;
int v36;
unsigned int v37;
_MI_COMBINE_CANDIDATE InputPfn;
int v40;
char a2[12];
_PHYSICAL_MEMORY_RUN *v42;
unsigned __int64 *v43;
_MI_PAGE_COMBINING_SUPPORT *Pcs;
INT64 a3;
VOID *CrcList;
_GROUP_AFFINITY Affinity;
unsigned __int64 v48;
_MI_ARBITRARY_PAGE_MAP *PageMap;
PHYSICAL_MEMORY_DESCRIPTOR *Memory;
_PHYSICAL_MEMORY_RUN *v51;
__int64 v52;
_ETHREAD *CurrentThread;
_MI_PAGE_CRCS *v54;
__int64 v55;
_GROUP_AFFINITY GroupAffinity;
_GROUP_AFFINITY PreviousAffinity;
v1 = *(_MI_PAGE_COMBINING_SUPPORT **)CombineControlBlock;
v2 = CombineControlBlock;
v3 = *((_QWORD *)CombineControlBlock + 1);
v4 = 0;
v5 = **(_QWORD **)CombineControlBlock;
v6 = CombineControlBlock[15];
v7 = *((_QWORD *)CombineControlBlock + 3);
PageMap = (_MI_ARBITRARY_PAGE_MAP *)*((_QWORD *)CombineControlBlock + 2);
Affinity = 0i64;
Pcs = v1;
PreviousAffinity = 0i64;
v52 = v3;
GroupAffinity = 0i64;
InputPfn = v6;
v36 = 0;
CurrentThread = (_ETHREAD *)KeGetCurrentThread();
v55 = v5;
Memory = MiReferencePageRuns((ULONG_PTR *)v5, 1ui64);
v40 = 0;
*(_QWORD *)&a2[4] = Memory->NumberOfRuns;
v51 = &Memory->Run[*(_QWORD *)&a2[4]];
KeQueryAffinityThread(&CurrentThread->Tcb, &GroupAffinity);
v8 = 0;
if( !KeNumberNodes )
goto LABEL_59;
while( 1 )
{
v9 = *(_QWORD *)(4544i64 * v8 + *(_QWORD *)(v5 + 16) + 4176);
if( v9 < 0x10 )
goto LABEL_53;
v48 = (40 * v9 + 4095) & 0xFFFFFFFFFFFFF000ui64;
v10 = MiAllocateCrcList(v1, (UINT64 *)v6);
CrcList = v10;
v11 = v10;
if( !v10 )
break;
v12 = (char *)v10;
v54 = &v10[10 * (v48 / 0x28)];
KeQueryNodeActiveDpcGangAffinity(v8, &Affinity, 0i64);
Mask = Affinity.Mask;
if( Affinity.Group == GroupAffinity.Group )
{
if( (Affinity.Mask & GroupAffinity.Mask) != 0 )
Mask = Affinity.Mask & GroupAffinity.Mask;
Affinity.Mask = Mask;
}
if( Mask )
{
if( v40 )
{
p_PreviousAffinity = 0i64;
}
else
{
v40 = 1;
p_PreviousAffinity = &PreviousAffinity;
}
KeSetSystemGroupAffinityThread(&Affinity, p_PreviousAffinity);
}
v15 = *(_DWORD *)&a2[4];
v37 = 0;
v16 = 0;
if( !*(_DWORD *)&a2[4] )
goto LABEL_51;
v17 = v51;
p_PageCount = &Memory->Run[0].PageCount;
v43 = &Memory->Run[0].PageCount;
v42 = v51;
LABEL_15:
if( LODWORD(v17->BasePage) != v8 )
goto LABEL_46;
v19 = *p_PageCount;
v20 = *(p_PageCount - 1) - 1;
v21 = &MmGetPfnDb()[v20];
if( !*p_PageCount )
goto LABEL_45;
PteAddress = 0i64;
LABEL_18:
if( (!v52 || !*(_DWORD *)(v52 + 4)) && (CurrentThread->CrossThreadFlags & 1) == 0 )
{
++v21;
++v20;
while( 1 )
{
v23 = *(_BYTE *)(&v21->u3 + 1) & 7;
LODWORD(a3) = 0;
v24 = 1i64;
*(_DWORD *)a2 = v23;
if( (v21->u4._bf_0 & 0x1000000000i64) != 0 )
{
PfnPageSizeIndexUnsynchronized = MiGetPfnPageSizeIndexUnsynchronized(v21, (INT64 *)a2, &a3);
if( PfnPageSizeIndexUnsynchronized != -1 )
{
v24 = MiLargePageSizes[PfnPageSizeIndexUnsynchronized];
goto LABEL_27;
}
v23 = *(_DWORD *)a2;
}
if( v23 > 1 )
{
if( MiCombineCandidate(Pcs, (_MMPFN *)(unsigned int)InputPfn) == MiCombineNone )
goto LABEL_39;
if( !PteAddress )
{
v2 = CombineControlBlock;
MiGetUltraMapping(CombineControlBlock + 52, 3i64);
PteAddress = MiGetPteAddress(v27);
if( !PteAddress )
{
v36 = -1073741670;
goto LABEL_44;
}
}
v28 = PageMap;
v29 = PageMap;
v30 = Pcs;
*((_QWORD *)PageMap + 9) = PteAddress;
*((_QWORD *)v29 + 8) = v21;
if( MiMapArbitraryPage(v30, v29, InputPfn, 0i64) )
{
if( (*(_BYTE *)(&v21->u3 + 1) & 7) == 6 )
++*(_QWORD *)(v7 + 16);
else
++*(_QWORD *)(v7 + 24);
v31 = MiPerformCombineScan(CombineControlBlock, v28, 0i64);
MiReleaseArbitraryPage(PageMap);
v32 = v31 == 1;
PteAddress = 0i64;
v2 = CombineControlBlock;
if( v32 )
{
*((_QWORD *)v12 + 1) = v20;
*((_QWORD *)v12 + 2) = 0i64;
*((_QWORD *)v12 + 4) = 0i64;
v12 += 40;
if( v12 == (char *)v54 )
{
v33 = (__int64)((unsigned __int128)((v12 - (_BYTE *)CrcList) * (__int128)0x6666666666666667i64) >> 64) >> 4;
MiProcessCrcList(CombineControlBlock, CrcList, v33 + (v33 >> 63), v8);
v12 = (char *)CrcList;
}
}
}
else
{
LABEL_39:
v2 = CombineControlBlock;
}
if( --v19 )
goto LABEL_18;
LABEL_44:
p_PageCount = v43;
v17 = v42;
v16 = v37;
v15 = *(_DWORD *)&a2[4];
LABEL_45:
if( v36 < 0 )
{
LABEL_47:
v4 = v36;
goto LABEL_48;
}
LABEL_46:
++v16;
v17 = (_PHYSICAL_MEMORY_RUN *)((char *)v17 + 8);
p_PageCount += 2;
v37 = v16;
v42 = v17;
v43 = p_PageCount;
if( v16 >= v15 )
goto LABEL_47;
goto LABEL_15;
}
LABEL_27:
v26 = v24 - (v20 & (v24 - 1));
if( v26 >= v19 )
{
v2 = CombineControlBlock;
goto LABEL_44;
}
v20 += v26;
v19 -= v26;
v21 += v26;
}
}
v4 = -1073741248;
v36 = -1073741248;
LABEL_48:
v11 = CrcList;
if( v12 != CrcList )
{
v34 = (__int64)((unsigned __int128)((v12 - (_BYTE *)CrcList) * (__int128)0x6666666666666667i64) >> 64) >> 4;
MiProcessCrcList(v2, CrcList, v34 + (v34 >> 63), v8);
}
v6 = InputPfn;
v1 = Pcs;
LABEL_51:
ExFreePoolWithTag(v11, 0);
if( v4 < 0 )
goto LABEL_57;
v5 = v55;
LABEL_53:
if( ++v8 == (unsigned __int16)KeNumberNodes )
goto LABEL_57;
}
v4 = -1073741670;
LABEL_57:
if( v40 == 1 )
KeRevertToUserGroupAffinityThread(&PreviousAffinity);
LABEL_59:
MiDereferencePageRuns(Memory);
return v4;
}Referenced by:
MiCombineIdenticalPages