MiCombineIdenticalPages
NTSTATUS __stdcall MiCombineIdenticalPages(
_MI_PARTITION *Partition,
PVOID StopHandle,
UINT64 CombineFlags,
INT8 PreviousMode,
UINT64 *OutputPagesCombined){
_MI_COMBINE_CONTROL_BLOCK v6;
__int64 v7;
_ADAPTER_OBJECT *v8;
_ADAPTER_OBJECT *v9;
__int64 v10;
NTSTATUS v11;
NTSTATUS v12;
_ETHREAD *CurrentThread;
_MI_PAGE_COMBINING_SUPPORT *p_PageCombine;
unsigned int NextPageColor;
NTSTATUS v16;
NTSTATUS v18;
PVOID Object;
PVOID Process;
int v21[2];
_MI_PARTITION *v22;
_QWORD *v23;
_LIST_ENTRY v24;
_MI_COLOR_BASE ColorBase[4];
_MI_ARBITRARY_PAGE_MAP PageMap[20];
_MI_COMBINE_CONTROL_BLOCK CombineControlBlock[60];
__int128 v28;
__int128 v29;
_KAPC_STATE ApcState;
_QWORD *v31;
v22 = Partition;
v6 = CombineFlags;
v23 = v31;
v7 = PreviousMode;
memset(PageMap, 0i64, sizeof(PageMap));
v28 = 0i64;
v29 = 0i64;
memset(CombineControlBlock, 0i64, sizeof(CombineControlBlock));
*v31 = 0i64;
v8 = 0i64;
v9 = 0i64;
memset(&ApcState, 0, sizeof(ApcState));
if( (v6 & 0xFFFFFFFC) != 0 )
return -1073741583;
v10 = -1i64;
if( (v6 & 2) != 0 )
{
if( v7 )
v10 = v7;
v7 = v10;
}
else if( v7 )
{
return -1073741811;
}
if( (dword_140CFA178 & 1) != 0 )
return -1073741637;
if( !StopHandle
|| (Object = 0i64,
v11 = ObReferenceObjectByHandle(
StopHandle,
1ui64,
(_OBJECT_TYPE *)ExEventObjectType,
(INT8)OutputPagesCombined,
&Object,
0i64),
v9 = (_ADAPTER_OBJECT *)Object,
v12 = v11,
v11 >= 0) )
{
if( v7 )
{
Process = 0i64;
v18 = ObReferenceObjectByHandle(
(VOID *)v7,
0x18ui64,
(_OBJECT_TYPE *)PsProcessType,
(INT8)OutputPagesCombined,
&Process,
0i64);
v8 = (_ADAPTER_OBJECT *)Process;
v12 = v18;
if( v18 < 0 )
{
LABEL_14:
if( v8 )
{
KiUnstackDetachProcess(&ApcState, 0i64);
HalPutDmaAdapter(v8);
}
goto LABEL_16;
}
KiStackAttachProcess(Process, 0i64, &ApcState);
}
CurrentThread = (_ETHREAD *)KeGetCurrentThread();
p_PageCombine = &v22->PageCombine;
if( (v6 & 1) == 0 || v22 == &Irp )
{
--CurrentThread->Tcb.KernelApcDisable;
MiCombiningInProgress(p_PageCombine, PageMap, 1ui64);
v21[0] = 0;
v21[1] = -1;
v24 = *(_LIST_ENTRY *)((char *)&stru_140C4DB30 + 4008);
*(_QWORD *)&CombineControlBlock[10] = &v24;
*(_QWORD *)&CombineControlBlock[12] = v21;
*(_QWORD *)&CombineControlBlock[4] = PageMap;
*(_QWORD *)&CombineControlBlock[6] = &v28;
CombineControlBlock[14] = 2;
*(_QWORD *)CombineControlBlock = p_PageCombine;
*(_QWORD *)&CombineControlBlock[2] = v9;
CombineControlBlock[15] = v6;
*(_OWORD *)ColorBase = 0i64;
MiInitializePageColorBase(&KeGetCurrentThread()->ApcState.Process->Vm.Instance, 0i64, ColorBase);
NextPageColor = MiGetNextPageColor((INT64)ColorBase);
if( MiCreateUltraThreadContext((INT64)&CombineControlBlock[28], NextPageColor, 8i64) )
{
if( (v6 & 2) != 0 )
{
*(_QWORD *)&CombineControlBlock[8] = (char *)v8 + 1664;
v16 = MiCombineWorkingSet(CombineControlBlock);
}
else
{
*(_QWORD *)&CombineControlBlock[8] = 0i64;
v16 = MiCombineAllPhysicalMemory(CombineControlBlock);
}
v12 = v16;
MiDeleteUltraThreadContext((INT64)&CombineControlBlock[28]);
*v23 = v28;
_InterlockedIncrement((volatile signed __int32 *)&p_PageCombine->PageCombineStats.CombineScanCount);
_InterlockedExchangeAdd64(
(volatile signed __int64 *)&p_PageCombine->PageCombineStats.PagesCombined,
*((unsigned __int64 *)&v28 + 1));
_InterlockedExchangeAdd64((volatile signed __int64 *)&p_PageCombine->PageCombineStats, v29);
_InterlockedExchangeAdd64(
(volatile signed __int64 *)&p_PageCombine->PageCombineStats.PagesScannedStandby,
*((unsigned __int64 *)&v29 + 1));
}
else
{
v12 = -1073741670;
}
MiCombiningInProgress(p_PageCombine, PageMap, 0i64);
KeLeaveCriticalRegionThread(&CurrentThread->Tcb);
}
else
{
v12 = -1073741637;
}
goto LABEL_14;
}
LABEL_16:
if( v9 )
HalPutDmaAdapter(v9);
return v12;
}Referenced by:
MmCombineIdenticalPages
MmManagePartitionCombineMemory