MmAdjustWorkingSetSizeEx
INT64 __fastcall MmAdjustWorkingSetSizeEx(UINT64 a1, UINT64 a2, INT64 a3, CHAR a4, INT64 a5, BYTE *a6){
int v8;
ULONG_PTR v9;
_ETHREAD *CurrentThread;
INT64 CurrentMultiplexedVm;
INT64 *SharedVm;
WORK_QUEUE_TYPE v13;
PVOID v14;
UINT64 v15;
UINT64 v16;
WORK_QUEUE_TYPE v17;
struct _KPRCB *v18;
int v19;
unsigned __int64 v20;
UINT64 v21;
__int64 v22;
unsigned __int64 v23;
int v24;
int v25;
__int64 v27;
INT64 v28;
ULONG_PTR *v29;
struct _KPRCB *CurrentPrcb;
__int64 v31;
bool v32;
signed __int32 v33;
ULONG_PTR *v34;
__int64 v35;
signed __int32 v36;
UINT64 v37;
ULONG_PTR *v38;
UINT64 v39;
__int64 v40;
struct _KLOCK_QUEUE_HANDLE LockHandle;
__int128 v42;
__int64 v43;
KIRQL v44;
__int16 v46;
v43 = 0i64;
v8 = a3;
v9 = 0i64;
memset(&LockHandle, 0, sizeof(LockHandle));
*a6 = 0;
v42 = 0i64;
CurrentThread = (_ETHREAD *)KeGetCurrentThread();
if( !(_DWORD)a3 )
{
v9 = *((_QWORD *)CurrentThread + 23);
CurrentMultiplexedVm = v9 + 1664;
LABEL_3:
if( a1 == -1i64 && a2 == -1i64 )
return MiEmptyWorkingSetInitiate(CurrentMultiplexedVm, 0, 0i64, -1i64);
v38 = *(ULONG_PTR **)(qword_140C4E388 + 8i64 * *(unsigned __int16 *)(CurrentMultiplexedVm + 174));
SharedVm = MiGetSharedVm(CurrentMultiplexedVm);
v44 = ExAcquireSpinLockExclusive((PEX_SPIN_LOCK)SharedVm);
*((_DWORD *)SharedVm + 1) = 0;
*(_QWORD *)&v42 = 0i64;
*((_QWORD *)&v42 + 1) = MiGetSharedVm(CurrentMultiplexedVm) + 8;
KxAcquireQueuedSpinLock((PIO_WORKITEM)&v42, *((PIO_WORKITEM_ROUTINE *)&v42 + 1), v13, v14);
if( !v8 && (*(_DWORD *)(v9 + 1124) & 0x20) != 0 )
{
v19 = -1073741558;
goto LABEL_29;
}
if( a1 )
v15 = a1 >> 12;
else
v15 = *(_QWORD *)(CurrentMultiplexedVm + 112);
v37 = v15;
if( a2 )
v16 = a2 >> 12;
else
v16 = *(_QWORD *)(CurrentMultiplexedVm + 152);
v39 = v16;
v19 = MiCheckWsLimits(CurrentMultiplexedVm, &v37, &v39, a5, 0);
if( (v19 & 0xC0000000) == -1073741824 )
goto LABEL_29;
v20 = *(_QWORD *)(CurrentMultiplexedVm + 112);
v21 = v37;
v22 = *(_QWORD *)(CurrentMultiplexedVm + 16);
v40 = v22;
if( v37 > v20 )
{
v23 = v37 - v20;
*a6 = 1;
if( !a4 )
{
v19 = -1073741727;
goto LABEL_29;
}
if( !v8 )
{
v19 = PsChargeProcessQuota(v9, v22, v23);
if( v19 < 0 )
goto LABEL_29;
}
if( !(unsigned int)MiChargeResident(v38, v23, 512i64) )
{
if( !v8 )
PsReturnProcessQuota(v9, v27, v23);
v19 = -1073741670;
goto LABEL_29;
}
v22 = v40;
}
else
{
v23 = v20 - v37;
if( v37 < *(_QWORD *)(v22 + 32) )
{
v19 = -1073741748;
goto LABEL_29;
}
}
if( v39 < *(_QWORD *)(CurrentMultiplexedVm + 120) )
{
if( *(_QWORD *)(v22 + 32) + 6i64 >= v39 )
{
v19 = -1073741748;
if( *a6 == 1 )
{
if( !v8 )
PsReturnProcessQuota(v9, v22, v23);
v29 = v38;
if( v38 == &MiSystemPartition )
{
CurrentPrcb = KeGetCurrentPrcb();
v31 = *((int *)CurrentPrcb + 8391);
if( (_DWORD)v31 != -1 )
{
if( v23 + v31 <= 0x100 )
{
do
{
if( v23 >= 0x80000 )
break;
v33 = _InterlockedCompareExchange((volatile signed __int32 *)CurrentPrcb + 8391, v23 + v31, v31);
v32 = (_DWORD)v31 == v33;
LODWORD(v31) = v33;
if( v32 )
goto LABEL_29;
}
while( v33 != -1 && v23 + v33 <= 0x100 );
}
if( (int)v31 > 192
&& (_DWORD)v31 != -1
&& (_DWORD)v31 == _InterlockedCompareExchange((volatile signed __int32 *)CurrentPrcb + 8391, 192, v31) )
{
v23 += (int)v31 - 192;
}
v29 = v38;
}
}
if( v23 )
_InterlockedExchangeAdd64((volatile signed __int64 *)v29 + 896, v23);
}
goto LABEL_29;
}
*(_BYTE *)(CurrentMultiplexedVm + 187) |= 0x10u;
}
if( !*a6 && v23 )
{
if( !v8 )
PsReturnProcessQuota(v9, v22, v23);
v34 = v38;
if( v38 == &MiSystemPartition )
{
v18 = KeGetCurrentPrcb();
v17 = -1;
v35 = *((int *)v18 + 8391);
if( (_DWORD)v35 != -1 )
{
if( v23 + v35 <= 0x100 )
{
do
{
if( v23 >= 0x80000 )
break;
v36 = _InterlockedCompareExchange((volatile signed __int32 *)v18 + 8391, v23 + v35, v35);
v32 = (_DWORD)v35 == v36;
LODWORD(v35) = v36;
if( v32 )
goto LABEL_88;
}
while( v36 != -1 && v23 + v36 <= 0x100 );
}
if( (int)v35 > 192
&& (_DWORD)v35 != -1
&& (_DWORD)v35 == _InterlockedCompareExchange((volatile signed __int32 *)v18 + 8391, 192, v35) )
{
v23 += (int)v35 - 192;
}
v34 = v38;
}
v21 = v37;
}
if( v23 )
{
_InterlockedExchangeAdd64((volatile signed __int64 *)v34 + 896, v23);
LABEL_88:
v21 = v37;
}
}
*(_QWORD *)(CurrentMultiplexedVm + 152) = v39;
*(_QWORD *)(CurrentMultiplexedVm + 112) = v21;
if( !(_DWORD)a5 )
{
LABEL_29:
KeReleaseInStackQueuedSpinLockFromDpcLevel((_KLOCK_QUEUE_HANDLE *)&v42);
MiUnlockWorkingSetExclusive(CurrentMultiplexedVm, v44);
return(unsigned int)v19;
}
v24 = 0;
LockHandle.LockQueue.Next = 0i64;
LockHandle.LockQueue.Lock = &WorkerRoutine;
KxAcquireQueuedSpinLock((PIO_WORKITEM)&LockHandle, (PIO_WORKITEM_ROUTINE)&WorkerRoutine, v17, v18);
v25 = *(_DWORD *)(CurrentMultiplexedVm + 184);
v46 = v25;
if( (a5 & 4) != 0 )
{
LOBYTE(v25) = v25 | 0x80;
}
else
{
if( (a5 & 8) == 0 )
goto LABEL_23;
LOBYTE(v25) = v25 & 0x7F;
}
v24 = 1;
LOBYTE(v46) = v25;
LABEL_23:
if( (a5 & 1) != 0 )
{
LOBYTE(v46) = v25 | 0x40;
}
else
{
if( (a5 & 2) != 0 )
{
v24 = 1;
LOBYTE(v46) = v25 & 0xBF;
}
if( !v24 )
goto LABEL_28;
}
*(_WORD *)(CurrentMultiplexedVm + 184) = v46;
LABEL_28:
KeReleaseInStackQueuedSpinLockFromDpcLevel(&LockHandle);
goto LABEL_29;
}
if( (_DWORD)a3 == 2 )
{
CurrentMultiplexedVm = MiGetCurrentMultiplexedVm();
if( CurrentMultiplexedVm )
goto LABEL_3;
}
else
{
v28 = (unsigned int)(a3 - 3);
if( (_DWORD)a3 == 3 )
{
v28 = 2i64;
LABEL_43:
CurrentMultiplexedVm = (INT64)MiGetAnyMultiplexedVm(v28);
goto LABEL_3;
}
if( (_DWORD)a3 == 4 )
goto LABEL_43;
}
return 3221225713i64;
}Referenced by:
MmAdjustWorkingSetSize
NtSetSystemInformation
PspSetQuotaLimits
SmKmVirtualLockContextIncreaseWsMin
SmKmVirtualLockCtxMemoryUnlocked