[NTOSKRNL:CC] CcMapDataForOverwrite

Implemented CcMapDataForOverwrite
This commit is contained in:
Dibyamartanda Samanta 2024-08-07 10:38:18 +02:00 committed by CodingWorkshop Signing Team
parent ddda3559c6
commit d7ee2f9afc
Signed by: CodingWorkshop Signing Team
GPG Key ID: 6DC88369C82795D2

View File

@ -60,6 +60,68 @@ CcAllocateObcb(
return NewObcb; return NewObcb;
} }
VOID
VECTORCALL
CcMapDataForOverwrite(
PFILE_OBJECT FileObject,
PLARGE_INTEGER FileOffset,
ULONG Length,
PVOID *Bcb,
PVOID *Buffer)
{
NTSTATUS status = STATUS_SUCCESS;
PETHREAD currentThread = nullptr;
PSHARED_CACHE_MAP sharedCacheMap = nullptre;
ULONG pageCount = {0};
PVOID outBcb = nullptr;
PVOID localBuffer = nullptr;
ULONG savedState = {0};
ULONG readClusterSize = {0};
pageCount = (Length >> PAGE_SHIFT) + (((FileOffset->LowPart & PAGE_OFFSET) + 4095 + (Length & PAGE_OFFSET)) >> PAGE_SHIFT);
currentThread = (PETHREAD)KeGetCurrentThread();
sharedCacheMap = (PSHARED_CACHE_MAP)FileObject->SectionObjectPointer->SharedCacheMap;
if ((sharedCacheMap->Flags & 0x20000) == 0)
{
SpinLockGuard lockGuard(LockQueueMasterLock);
sharedCacheMap->Flags |= 0x20000;
}
savedState = currentThread->CacheManagerActive + 2 * currentThread->ReadClusterSize;
readClusterSize = currentThread->ReadClusterSize;
CcMapDataCommon(FileObject, FileOffset, Length, TRUE, &outBcb, &localBuffer);
auto SystemCacheAddress = *localBuffer;
ULONG remainingPages = pageCount;
while (remainingPages)
{
currentThread->CacheManagerActive = 1;
if (--remainingPages > readClusterSize)
{
currentThread->ReadClusterSize = (remainingPages > 0xF) ? 15 : remainingPages;
}
if (!MmCheckCachedPageState(SystemCacheAddress,true))
{
MmCheckCachedPageState(SystemCacheAddress,false);
}
SystemCacheAddress += 4096;
}
currentThread->CacheManagerActive = savedState & 1;
currentThread->ReadClusterSize = savedState >> 1;
*Bcb = outBcb;
*Buffer = localBuffer;
}
VOID VOID
NTAPI NTAPI
CcSetDirtyPinnedData( CcSetDirtyPinnedData(