MiFindLargePageMemory
VOID __fastcall MiFindLargePageMemory(
INT64 a1,
UINT64 a2,
UINT64 a3,
UINT64 a4,
UINT64 ProtectionMask,
CHAR a6,
RTL_BALANCED_NODE **a7){
unsigned int v7;
UINT64 v8;
_MI_PFN_CACHE_ATTRIBUTE v9;
UINT64 v10;
_QWORD *v11;
int v12;
unsigned int LargestPageIndex;
unsigned __int64 SizeInPages;
_QWORD *v15;
bool v16;
RTL_BALANCED_NODE *v17;
RTL_BALANCED_NODE *v18;
UINT64 PreferredNode;
UINT64 PreferredChannel;
UINT64 Flags;
_MI_PFN_CACHE_ATTRIBUTE CacheAttribute;
INT64 v25[2];
__int128 v26;
__int128 v27;
v7 = a2;
*(_OWORD *)v25 = 0i64;
v8 = a3;
v26 = 0i64;
v27 = 0i64;
if( (unsigned int)MiSufficientAvailablePages(a1, a3 + 160) && (unsigned int)MiCreateColorAnchors((INT64)v25, v7) )
{
v9 = (unsigned int)MiProtectionToCacheAttribute((unsigned int)ProtectionMask);
v10 = HighestPhysicalPage;
v11 = 0i64;
CacheAttribute = v9;
v12 = 0;
HIDWORD(v25[1]) = v9;
LargestPageIndex = MiGetLargestPageIndex();
if( LargestPageIndex < 3 )
{
do
{
SizeInPages = MiLargePageSizes[LargestPageIndex];
if( v8 >= SizeInPages )
{
if( SizeInPages < a4 )
break;
if( !v11 )
{
LODWORD(v15) = MiAllocatePool((struct _SLIST_ENTRY *)0x40);
v11 = v15;
if( !v15 )
goto LABEL_25;
}
LODWORD(Flags) = 1611661312;
LODWORD(PreferredChannel) = 0x80000000;
LODWORD(PreferredNode) = v7;
if( (int)MiFindContiguousPages(
(_MI_PARTITION *)a1,
SizeInPages,
v10,
SizeInPages,
SizeInPages,
CacheAttribute,
PreferredNode,
PreferredChannel,
Flags,
0i64) >= 0 )
{
v8 -= SizeInPages;
if( (a6 & 2) == 0
&& (unsigned int)MiUpdateLargePagePfns((INT64)v25, 0i64, SizeInPages, (unsigned int)CacheAttribute) == 1 )
{
v12 = 1;
}
v16 = 0;
*v11 = 0i64;
v11[1] = SizeInPages;
*((_BYTE *)v11 + 16) = 1;
v17 = *a7;
if( *a7 )
{
while( 1 )
{
if( v17[-1].Children[0] )
{
v18 = v17->Children[0];
if( !v17->Children[0] )
break;
}
else
{
v18 = v17->Children[1];
if( !v18 )
{
v16 = 1;
break;
}
}
v17 = v18;
}
}
RtlAvlInsertNodeEx((unsigned __int64 *)a7, (__int64)v17, v16, v11 + 3);
v11 = 0i64;
if( !v8 )
goto LABEL_25;
v10 = -1i64;
if( SizeInPages != -1i64 )
continue;
}
}
v10 = HighestPhysicalPage;
++LargestPageIndex;
}
while( LargestPageIndex < 3 );
if( v11 )
ExFreePoolWithTag(v11, 0);
LABEL_25:
if( v12 )
MiZeroInParallel((INT64)v25);
}
MiDeleteColorAnchors((INT64)v25);
}
}Referenced by:
MiAllocateLargeZeroPages