MiRebuildLargePage
UINT64 __stdcall MiRebuildLargePage(_MI_PARTITION *Partition, UINT64 NodeNumber){
unsigned int v2;
UINT64 v3;
__int64 v4;
UINT64 v5;
__int64 v7;
unsigned __int8 *v8;
__int64 v9;
PHYSICAL_MEMORY_DESCRIPTOR *v10;
UINT64 v11;
UINT64 v12;
PHYSICAL_MEMORY_DESCRIPTOR *PhysicalMemoryBlock;
unsigned int v14;
__int64 v15;
int v16;
char *v17;
unsigned __int8 CurrentIrql;
UINT64 inserted;
struct _KPRCB *CurrentPrcb;
__int64 v21;
bool v22;
signed __int32 v23;
unsigned int v24;
unsigned __int64 v25;
unsigned int v26;
__int64 v27;
__int64 v28;
__int64 *v29;
_QWORD *v30;
__int64 v31;
__int64 v32;
__int64 v33;
UINT64 i;
int v35;
UINT64 HighestPhysicalPage;
UINT64 PreferredNode;
UINT64 PreferredChannel;
UINT64 Flags;
INT64 NumberOfPages;
UINT64 v42;
PHYSICAL_MEMORY_DESCRIPTOR *v43;
int v44;
_QWORD *v45;
ULONG_PTR v46;
INT64 a1[2];
__int64 v48;
_ETHREAD *CurrentThread;
unsigned __int8 *v50;
unsigned int v51;
unsigned int v52;
unsigned int v53;
UINT64 v54;
v54 = v3;
v53 = v2;
v4 = (unsigned int)NodeNumber;
v5 = 0i64;
v48 = 0i64;
v7 = (unsigned int)MmNumberOfChannels;
v8 = 0i64;
v51 = MmNumberOfChannels;
v9 = v2;
v44 = NodeNumber;
*(_OWORD *)a1 = 0i64;
CurrentThread = (_ETHREAD *)KeGetCurrentThread();
v42 = 0i64;
v10 = MiReferencePageRuns(Partition, 1ui64);
v11 = ::HighestPhysicalPage;
v12 = MiLargePageSizes[v9];
PhysicalMemoryBlock = v10;
v14 = 0;
v43 = v10;
v15 = *((_QWORD *)Partition + 2) + 4544 * v4;
v45 = (_QWORD *)v15;
v46 = ::HighestPhysicalPage;
v52 = 0;
if( (unsigned int)v7 > 1 )
{
v8 = (unsigned __int8 *)(v15 + 4313);
v14 = *(unsigned __int8 *)(v15 + 4313);
v52 = v14;
}
v50 = &v8[v7];
if( v8 != &v8[v7] )
{
while( (*((_DWORD *)CurrentThread + 324) & 1) == 0 )
{
NumberOfPages = MiFindRebuildCandidate(Partition, (unsigned int)v4, v14, v12, v11, PhysicalMemoryBlock);
if( NumberOfPages == -1 )
goto LABEL_44;
v16 = 1082130432;
if( v12 == 512 )
{
v16 = 1115684864;
}
else if( v12 == 16 )
{
v16 = 1098907648;
}
LODWORD(Flags) = v16;
LODWORD(PreferredChannel) = v52;
LODWORD(PreferredNode) = v4;
if( (int)MiFindContiguousPages(
Partition,
NumberOfPages,
NumberOfPages + v12 - 1,
v12,
v12,
MiCached,
PreferredNode,
PreferredChannel,
Flags,
0i64) >= 0 )
{
if( v12 >= 0x200 )
{
LODWORD(HighestPhysicalPage) = 1;
MiUpdateLargePageBitMap((UINT64)Partition, NumberOfPages, v12, 0i64, HighestPhysicalPage);
}
MiConvertSmallPageRangeToLarge(NumberOfPages, v53);
v17 = (char *)MmGetPfnDb() + 48 * NumberOfPages;
CurrentIrql = KeGetCurrentIrql();
__writecr8(2ui64);
MiLockPageAtDpc((INT64)v17);
a1[0] = NumberOfPages;
a1[1] = 1i64;
v48 = 2i64;
inserted = MiInsertLargePageInNodeList((INT64)a1);
__writecr8(CurrentIrql);
MiReturnCommit(Partition, inserted);
if( Partition == (_MI_PARTITION *)&MiSystemPartition )
{
CurrentPrcb = KeGetCurrentPrcb();
v21 = *((int *)CurrentPrcb + 8391);
if( (_DWORD)v21 != -1 )
{
do
{
if( inserted + v21 > 0x100 || inserted >= 0x80000 )
break;
v23 = _InterlockedCompareExchange((volatile signed __int32 *)CurrentPrcb + 8391, inserted + v21, v21);
v22 = (_DWORD)v21 == v23;
v21 = v23;
if( v22 )
goto LABEL_26;
}
while( v23 != -1 );
if( (int)v21 > 192
&& (_DWORD)v21 != -1
&& (_DWORD)v21 == _InterlockedCompareExchange((volatile signed __int32 *)CurrentPrcb + 8391, 192, v21) )
{
inserted += (int)v21 - 192;
}
}
}
if( inserted )
_InterlockedExchangeAdd64((volatile signed __int64 *)Partition + 896, inserted);
LABEL_26:
v5 += v12;
v42 = v5;
if( v5 >= v54 )
{
LABEL_39:
PhysicalMemoryBlock = v43;
break;
}
}
v24 = MmNumberOfChannels;
v25 = 0i64;
v26 = 0;
if( MmNumberOfChannels )
{
do
v25 += MiNodeFreeZeroPages(v45, v26++, 0);
while( v26 < v24 );
LODWORD(v4) = v44;
}
if( v12 > 0x10 )
{
v27 = 0i64;
v28 = v53 + 1;
if( (unsigned int)v28 <= 2 )
{
v29 = &MiLargePageSizes[v28];
v30 = &v45[134 * (unsigned int)v28];
v31 = (unsigned int)(3 - v28);
do
{
v32 = *v30 + v30[1];
v30 += 134;
v33 = *v29++ * v32;
v27 += v33;
--v31;
}
while( v31 );
}
v25 += v27;
}
LODWORD(v7) = v51;
if( v25 >= 0x1000 )
{
v5 = v42;
}
else
{
for( i = 0i64; (unsigned int)i < v51; i = (unsigned int)(v35 + 1) )
v25 += MiGetNodeStandbyPageCount(Partition, (unsigned int)v4, i);
v5 = v42;
if( v25 < v54 - v42 + 0x8000 )
goto LABEL_39;
}
if( !NumberOfPages )
{
LABEL_44:
++v8;
if( (unsigned int)v7 <= 1 )
{
v14 = v52;
}
else
{
v14 = *v8;
v52 = v14;
}
PhysicalMemoryBlock = v43;
v11 = v46;
if( v8 == v50 )
break;
}
else
{
v14 = v52;
v11 = NumberOfPages - 1;
PhysicalMemoryBlock = v43;
v46 = NumberOfPages - 1;
}
}
}
MiDereferencePageRunsEx((INT64)PhysicalMemoryBlock, 1i64);
return v5;
}Referenced by:
MiRebuildLargePages
MmBuildLargePages
MmManagePartitionCreateLargePages