[NTOS:MM] Implement turning working set shared lock to exclusive

This commit is contained in:
Jérôme Gardou 2021-02-23 17:21:26 +01:00 committed by Jérôme Gardou
parent cd085ac12f
commit 6b2f05f9dd

View file

@ -1398,6 +1398,46 @@ MiUnlockWorkingSetShared(
KeLeaveGuardedRegion();
}
FORCEINLINE
BOOLEAN
MiConvertSharedWorkingSetLockToExclusive(
_In_ PETHREAD Thread,
_In_ PMMSUPPORT Vm)
{
/* Sanity check: No exclusive lock. */
ASSERT(!Thread->OwnsProcessWorkingSetExclusive);
ASSERT(!Thread->OwnsSessionWorkingSetExclusive);
ASSERT(!Thread->OwnsSystemWorkingSetExclusive);
/* And it should have one and only one shared lock */
ASSERT((Thread->OwnsProcessWorkingSetShared + Thread->OwnsSessionWorkingSetShared + Thread->OwnsSystemWorkingSetShared) == 1);
/* Try. */
if (!ExConvertPushLockSharedToExclusive(&Vm->WorkingSetMutex))
return FALSE;
if (Vm == &MmSystemCacheWs)
{
ASSERT(Thread->OwnsSystemWorkingSetShared);
Thread->OwnsSystemWorkingSetShared = FALSE;
Thread->OwnsSystemWorkingSetExclusive = TRUE;
}
else if (Vm->Flags.SessionSpace)
{
ASSERT(Thread->OwnsSessionWorkingSetShared);
Thread->OwnsSessionWorkingSetShared = FALSE;
Thread->OwnsSessionWorkingSetExclusive = TRUE;
}
else
{
ASSERT(Thread->OwnsProcessWorkingSetShared);
Thread->OwnsProcessWorkingSetShared = FALSE;
Thread->OwnsProcessWorkingSetExclusive = TRUE;
}
return TRUE;
}
FORCEINLINE
VOID
MiUnlockProcessWorkingSetForFault(IN PEPROCESS Process,