MiGetPhysicalMemoryRanges
NTSTATUS __stdcall MiGetPhysicalMemoryRanges(_MI_PARTITION *Partition, INT8 a2){
_ETHREAD *CurrentThread;
__int64 v3;
unsigned int v4;
int v6;
PHYSICAL_MEMORY_DESCRIPTOR *v7;
PHYSICAL_MEMORY_DESCRIPTOR *v8;
unsigned __int64 v9;
char *v10;
_QWORD *Pool;
NTSTATUS v12;
_QWORD *v13;
unsigned __int64 *p_PageCount;
unsigned __int64 v15;
unsigned __int64 NumberOfPhysicalPages;
char *FileOnlyRanges;
__int64 v19;
char v20;
__int64 v21;
CurrentThread = (_ETHREAD *)KeGetCurrentThread();
v3 = 0i64;
v20 = 0;
v4 = a2;
v6 = a2 & 1;
if( (a2 & 1) != 0 || Partition != &Irp )
{
v20 = 1;
MiLockDynamicMemoryShared((INT64)Partition, (INT64)CurrentThread);
if( Partition != &Irp )
{
while( Partition->Vp.NumberOfPhysicalPages && !Partition->Core.MemoryRuns )
{
MiUnlockDynamicMemoryShared((INT64)Partition, (INT64)CurrentThread);
MiLockDynamicMemoryExclusive(Partition, CurrentThread);
NumberOfPhysicalPages = Partition->Vp.NumberOfPhysicalPages;
if( NumberOfPhysicalPages )
{
if( !Partition->Core.MemoryRuns )
{
MiMakePartitionMemoryBlock(Partition);
NumberOfPhysicalPages = Partition->Vp.NumberOfPhysicalPages;
}
if( NumberOfPhysicalPages && !Partition->Core.MemoryRuns )
{
MiUnlockDynamicMemoryExclusive(Partition, CurrentThread);
return 0;
}
}
MiUnlockDynamicMemoryExclusive(Partition, CurrentThread);
MiLockDynamicMemoryShared((INT64)Partition, (INT64)CurrentThread);
}
}
}
v7 = MiReferencePageRuns((ULONG_PTR *)&Partition->Core.PartitionId, 0i64);
v8 = v7;
if( v7 )
v9 = v7->NumberOfRuns & (unsigned __int64)-(__int64)(Partition->Vp.NumberOfPhysicalPages != 0);
else
v9 = 0i64;
v21 = 0i64;
v10 = 0i64;
if( v6 )
{
FileOnlyRanges = MiGetFileOnlyRanges((__int16 *)Partition, (VOID *)v4, &v21);
v3 = v21;
v10 = FileOnlyRanges;
}
Pool = MiAllocatePool(64i64, 16 * (v3 + v9 + 1), 0x68506D4Dui64);
v12 = (int)Pool;
if( Pool )
{
v13 = Pool;
if( v9 )
{
p_PageCount = &v8->Run[0].PageCount;
do
{
*v13 = *(p_PageCount - 1) << 12;
v15 = *p_PageCount;
p_PageCount += 2;
v13[1] = v15 << 12;
v13 += 2;
--v9;
}
while( v9 );
}
if( v3 )
{
v19 = 16 * v3;
memmove(v13, v10, v19);
v13 = (_QWORD *)((char *)v13 + v19);
}
*v13 = 0i64;
v13[1] = 0i64;
}
if( v20 )
MiUnlockDynamicMemoryShared((INT64)Partition, (INT64)CurrentThread);
if( v8 )
MiDereferencePageRuns(v8);
if( v10 )
ExFreePoolWithTag(v10, 0);
return v12;
}Referenced by:
MmGetPhysicalMemoryRangesEx2