Skip to content

Commit

Permalink
[NTOS:CC] Use CcpEnsureFileCacheResident where applicable
Browse files Browse the repository at this point in the history
  • Loading branch information
TAN-Gaming committed Nov 21, 2024
1 parent c693f8c commit 7c0290a
Showing 1 changed file with 18 additions and 22 deletions.
40 changes: 18 additions & 22 deletions ntoskrnl/cc/copy.c
Original file line number Diff line number Diff line change
Expand Up @@ -514,25 +514,25 @@ CcCopyRead (
/* Documented to ASSERT, but KMTests test this case... */
// ASSERT((FileOffset->QuadPart + Length) <= SharedCacheMap->FileSize.QuadPart);

if (!CcpEnsureFileCacheResident(SharedCacheMap, Wait, FALSE, FileOffset->QuadPart, Length))
{
ASSERT(!Wait);
return FALSE;
}

CurrentOffset = FileOffset->QuadPart;
while(CurrentOffset < ReadEnd)
{
Status = CcRosGetVacb(SharedCacheMap, CurrentOffset, &Vacb);
if (!NT_SUCCESS(Status))
{
ExRaiseStatus(Status);
return FALSE;
}

_SEH2_TRY
{
ULONG VacbOffset = CurrentOffset % VACB_MAPPING_GRANULARITY;
ULONG VacbLength = min(Length, VACB_MAPPING_GRANULARITY - VacbOffset);
SIZE_T CopyLength = VacbLength;

if (!CcRosEnsureVacbResident(Vacb, Wait, FALSE, VacbOffset, VacbLength))
return FALSE;

_SEH2_TRY
{
RtlCopyMemory(Buffer, (PUCHAR)Vacb->BaseAddress + VacbOffset, CopyLength);
Expand Down Expand Up @@ -619,6 +619,12 @@ CcCopyWrite (

ASSERT(WriteEnd <= SharedCacheMap->SectionSize.QuadPart);

if (!CcpEnsureFileCacheResident(SharedCacheMap, Wait, FALSE, FileOffset->QuadPart, Length))
{
ASSERT(!Wait);
return FALSE;
}

CurrentOffset = FileOffset->QuadPart;
while(CurrentOffset < WriteEnd)
{
Expand All @@ -627,18 +633,10 @@ CcCopyWrite (

Status = CcRosGetVacb(SharedCacheMap, CurrentOffset, &Vacb);
if (!NT_SUCCESS(Status))
{
ExRaiseStatus(Status);
return FALSE;
}

_SEH2_TRY
{
if (!CcRosEnsureVacbResident(Vacb, Wait, FALSE, VacbOffset, VacbLength))
{
return FALSE;
}

_SEH2_TRY
{
RtlCopyMemory((PVOID)((ULONG_PTR)Vacb->BaseAddress + VacbOffset), Buffer, VacbLength);
Expand Down Expand Up @@ -890,25 +888,23 @@ CcZeroData (

ASSERT(EndOffset->QuadPart <= SharedCacheMap->SectionSize.QuadPart);

if (!CcpEnsureFileCacheResident(SharedCacheMap, Wait, FALSE, StartOffset->QuadPart, Length))
{
ASSERT(!Wait);
return FALSE;
}

while(WriteOffset.QuadPart < EndOffset->QuadPart)
{
ULONG VacbOffset = WriteOffset.QuadPart % VACB_MAPPING_GRANULARITY;
ULONG VacbLength = min(Length, VACB_MAPPING_GRANULARITY - VacbOffset);

Status = CcRosGetVacb(SharedCacheMap, WriteOffset.QuadPart, &Vacb);
if (!NT_SUCCESS(Status))
{
ExRaiseStatus(Status);
return FALSE;
}

_SEH2_TRY
{
if (!CcRosEnsureVacbResident(Vacb, Wait, FALSE, VacbOffset, VacbLength))
{
return FALSE;
}

RtlZeroMemory((PVOID)((ULONG_PTR)Vacb->BaseAddress + VacbOffset), VacbLength);

WriteOffset.QuadPart += VacbLength;
Expand Down

0 comments on commit 7c0290a

Please sign in to comment.