MiCombineAllPhysicalMemory
VOID __fastcall MiCombineAllPhysicalMemory(INT64 a1, INT16 DX){
__int64 *v2;
__int64 v3;
__int64 v4;
int v5;
__int64 v6;
unsigned int v7;
__int64 v8;
unsigned int v9;
unsigned __int64 v10;
__int64 *v11;
__int64 *v12;
__int64 *v13;
unsigned __int64 Mask;
struct _GROUP_AFFINITY *p_PreviousAffinity;
unsigned int v16;
unsigned int v17;
_PHYSICAL_MEMORY_RUN *v18;
unsigned __int64 *p_PageCount;
unsigned __int64 v20;
__int64 v21;
char *v22;
MMPTE *PteAddress;
int v24;
__int64 v25;
int PfnPageSizeIndexUnsynchronized;
unsigned __int64 v27;
void *UltraMapping;
_QWORD *v29;
_QWORD *v30;
_MI_PAGE_COMBINING_SUPPORT *v31;
int v32;
int v33;
bool v34;
INT64 a5;
int v36;
unsigned int v37;
unsigned int InputPfn;
int v40;
char v41[12];
_PHYSICAL_MEMORY_RUN *v42;
unsigned __int64 *v43;
_MI_PAGE_COMBINING_SUPPORT *Pcs;
INT64 v45;
__int64 *v46;
struct _GROUP_AFFINITY Affinity;
UINT64 a3;
_QWORD *a2;
_PHYSICAL_MEMORY_DESCRIPTOR *Memory;
_PHYSICAL_MEMORY_RUN *v51;
__int64 v52;
_ETHREAD *CurrentThread;
__int64 *v54;
__int64 v55;
__int128 v56;
struct _GROUP_AFFINITY PreviousAffinity;
v2 = *(__int64 **)a1;
v3 = a1;
v4 = *(_QWORD *)(a1 + 8);
v5 = 0;
v6 = **(_QWORD **)a1;
v7 = *(_DWORD *)(a1 + 60);
v8 = *(_QWORD *)(a1 + 24);
a2 = *(_QWORD **)(a1 + 16);
Affinity = 0i64;
Pcs = (_MI_PAGE_COMBINING_SUPPORT *)v2;
PreviousAffinity = 0i64;
v52 = v4;
v56 = 0i64;
InputPfn = v7;
v36 = 0;
CurrentThread = (_ETHREAD *)KeGetCurrentThread();
v55 = v6;
Memory = MiReferencePageRuns((_MI_PARTITION *)v6, 1ui64);
v40 = 0;
*(_QWORD *)&v41[4] = Memory->NumberOfRuns;
v51 = &Memory->Run[*(_QWORD *)&v41[4]];
KeQueryAffinityThread((__int64)CurrentThread, (__int64)&v56);
v9 = 0;
if( !KeNumberNodes )
goto LABEL_58;
while( 1 )
{
v10 = *(_QWORD *)(4544i64 * v9 + *(_QWORD *)(v6 + 16) + 4176);
if( v10 >= 0x10 )
break;
LABEL_53:
if( ++v9 == (unsigned __int16)KeNumberNodes )
goto LABEL_56;
}
a3 = (40 * v10 + 4095) & 0xFFFFFFFFFFFFF000ui64;
v11 = (__int64 *)MiAllocateCrcList((_MI_PARTITION **)v2, v7, &a3);
v46 = v11;
v12 = v11;
if( !v11 )
goto LABEL_56;
v13 = v11;
v54 = &v11[5 * (a3 / 0x28)];
KeQueryNodeActiveDpcGangAffinity(v9, &Affinity, 0i64);
Mask = Affinity.Mask;
if( Affinity.Group == WORD4(v56) )
{
if( (Affinity.Mask & (unsigned __int64)v56) != 0 )
Mask = Affinity.Mask & v56;
Affinity.Mask = Mask;
}
if( Mask )
{
if( v40 )
{
p_PreviousAffinity = 0i64;
}
else
{
v40 = 1;
p_PreviousAffinity = &PreviousAffinity;
}
KeSetSystemGroupAffinityThread(&Affinity, p_PreviousAffinity);
}
v16 = *(_DWORD *)&v41[4];
v37 = 0;
v17 = 0;
if( !*(_DWORD *)&v41[4] )
goto LABEL_51;
v18 = v51;
p_PageCount = &Memory->Run[0].PageCount;
v43 = &Memory->Run[0].PageCount;
v42 = v51;
LABEL_15:
if( LODWORD(v18->BasePage) != v9 )
goto LABEL_46;
v20 = *p_PageCount;
v21 = *(p_PageCount - 1) - 1;
v22 = (char *)MmGetPfnDb() + 48 * v21;
if( !*p_PageCount )
goto LABEL_45;
PteAddress = 0i64;
LABEL_18:
if( (!v52 || !*(_DWORD *)(v52 + 4)) && (*((_DWORD *)CurrentThread + 324) & 1) == 0 )
{
v22 += 48;
++v21;
while( 1 )
{
v24 = v22[34] & 7;
LODWORD(v45) = 0;
v25 = 1i64;
*(_DWORD *)v41 = v24;
if( (*((_QWORD *)v22 + 5) & 0x1000000000i64) != 0 )
{
PfnPageSizeIndexUnsynchronized = MiGetPfnPageSizeIndexUnsynchronized((INT64)v22, (INT64 *)v41, &v45);
if( PfnPageSizeIndexUnsynchronized != -1 )
{
v25 = MiLargePageSizes[PfnPageSizeIndexUnsynchronized];
goto LABEL_27;
}
v24 = *(_DWORD *)v41;
}
if( v24 > 1 )
{
if( !(unsigned int)MiCombineCandidate(Pcs, (_MMPFN *)InputPfn) )
goto LABEL_39;
if( !PteAddress )
{
v3 = a1;
UltraMapping = (void *)MiGetUltraMapping((unsigned __int64 *)(a1 + 208), 3u, 1i64, 0);
PteAddress = MiGetPteAddress(UltraMapping);
if( !PteAddress )
{
v36 = -1073741670;
goto LABEL_44;
}
}
v29 = a2;
v30 = a2;
v31 = Pcs;
LODWORD(a5) = 0;
a2[9] = PteAddress;
v30[8] = v22;
MiMapArbitraryPage(v31, v30, InputPfn, 0i64, a5);
if( v32 )
{
if( (v22[34] & 7) == 6 )
++*(_QWORD *)(v8 + 16);
else
++*(_QWORD *)(v8 + 24);
v33 = MiPerformCombineScan(a1, (INT64)v29, 0i64, v13);
MiReleaseArbitraryPage((INT64)a2);
v34 = v33 == 1;
PteAddress = 0i64;
v3 = a1;
if( v34 )
{
v13[1] = v21;
v13[2] = 0i64;
v13[4] = 0i64;
v13 += 5;
if( v13 == v54 )
{
MiProcessCrcList(a1, v46, ((char *)v13 - (char *)v46) / 40, v9);
v13 = v46;
}
}
}
else
{
LABEL_39:
v3 = a1;
}
if( --v20 )
goto LABEL_18;
LABEL_44:
p_PageCount = v43;
v18 = v42;
v17 = v37;
v16 = *(_DWORD *)&v41[4];
LABEL_45:
if( v36 < 0 )
{
LABEL_47:
v5 = v36;
goto LABEL_48;
}
LABEL_46:
++v17;
v18 = (_PHYSICAL_MEMORY_RUN *)((char *)v18 + 8);
p_PageCount += 2;
v37 = v17;
v42 = v18;
v43 = p_PageCount;
if( v17 >= v16 )
goto LABEL_47;
goto LABEL_15;
}
LABEL_27:
v27 = v25 - (v21 & (v25 - 1));
if( v27 >= v20 )
{
v3 = a1;
goto LABEL_44;
}
v21 += v27;
v20 -= v27;
v22 += 48 * v27;
}
}
v5 = -1073741248;
v36 = -1073741248;
LABEL_48:
v12 = v46;
if( v13 != v46 )
MiProcessCrcList(v3, v46, ((char *)v13 - (char *)v46) / 40, v9);
v7 = InputPfn;
v2 = (__int64 *)Pcs;
LABEL_51:
ExFreePoolWithTag(v12, 0);
if( v5 >= 0 )
{
v6 = v55;
goto LABEL_53;
}
LABEL_56:
if( v40 == 1 )
KeRevertToUserGroupAffinityThread(&PreviousAffinity);
LABEL_58:
MiDereferencePageRuns(Memory);
}Referenced by:
MiCombineIdenticalPages