https://git.reactos.org/?p=reactos.git;a=commitdiff;h=7f47f032969cac0eaaf32…
commit 7f47f032969cac0eaaf3246a3e0ae9da3008aeb1
Author: Jérôme Gardou <jerome.gardou(a)reactos.org>
AuthorDate: Wed Dec 2 12:27:32 2020 +0100
Commit: Jérôme Gardou <jerome.gardou(a)reactos.org>
CommitDate: Wed Feb 3 09:41:22 2021 +0100
[NTOS:CC] Rewrite the non-cached path of CcZeroData
---
ntoskrnl/cc/copy.c | 35 +++++++++++++++++++----------------
1 file changed, 19 insertions(+), 16 deletions(-)
diff --git a/ntoskrnl/cc/copy.c b/ntoskrnl/cc/copy.c
index 5bb14cc210a..ced4271fc9b 100644
--- a/ntoskrnl/cc/copy.c
+++ b/ntoskrnl/cc/copy.c
@@ -759,25 +759,25 @@ CcZeroData (
PMDL Mdl;
ULONG i;
ULONG CurrentLength;
+ PPFN_NUMBER PfnArray;
- Mdl = _alloca(MmSizeOfMdl(NULL, MAX_ZERO_LENGTH));
+ /* Setup our Mdl */
+ Mdl = IoAllocateMdl(NULL, min(Length, MAX_ZERO_LENGTH), FALSE, FALSE, NULL);
+ if (!Mdl)
+ ExRaiseStatus(STATUS_INSUFFICIENT_RESOURCES);
+ PfnArray = MmGetMdlPfnArray(Mdl);
+ for (i = 0; i < BYTES_TO_PAGES(Mdl->ByteCount); i++)
+ PfnArray[i] = CcZeroPage;
+ Mdl->MdlFlags |= MDL_PAGES_LOCKED;
+
+ /* Perform the write sequencially */
while (Length > 0)
{
- if (Length + WriteOffset.QuadPart % PAGE_SIZE > MAX_ZERO_LENGTH)
- {
- CurrentLength = MAX_ZERO_LENGTH - WriteOffset.QuadPart % PAGE_SIZE;
- }
- else
- {
- CurrentLength = Length;
- }
- MmInitializeMdl(Mdl, (PVOID)(ULONG_PTR)WriteOffset.QuadPart, CurrentLength);
- Mdl->MdlFlags |= MDL_PAGES_LOCKED;
- for (i = 0; i < ((Mdl->Size - sizeof(MDL)) / sizeof(ULONG)); i++)
- {
- ((PPFN_NUMBER)(Mdl + 1))[i] = CcZeroPage;
- }
+ CurrentLength = min(Length, MAX_ZERO_LENGTH);
+
+ Mdl->ByteCount = CurrentLength;
+
KeInitializeEvent(&Event, NotificationEvent, FALSE);
Status = IoSynchronousPageWrite(FileObject, Mdl, &WriteOffset,
&Event, &Iosb);
if (Status == STATUS_PENDING)
@@ -791,12 +791,15 @@ CcZeroData (
}
if (!NT_SUCCESS(Status))
{
- return FALSE;
+ IoFreeMdl(Mdl);
+ ExRaiseStatus(Status);
}
WriteOffset.QuadPart += CurrentLength;
Length -= CurrentLength;
}
+ IoFreeMdl(Mdl);
+
return TRUE;
}