https://git.reactos.org/?p=reactos.git;a=commitdiff;h=91a4e62376d1dbd5d7e15…
commit 91a4e62376d1dbd5d7e155f2a86bb4b468649a24
Author: Jérôme Gardou <jerome.gardou(a)reactos.org>
AuthorDate: Wed Jan 27 16:28:45 2021 +0100
Commit: Jérôme Gardou <jerome.gardou(a)reactos.org>
CommitDate: Wed Feb 3 09:41:23 2021 +0100
[NTOS:MM] Improve MmCanFileBeTruncated
---
ntoskrnl/mm/section.c | 42 ++++++++++++------------------------------
1 file changed, 12 insertions(+), 30 deletions(-)
diff --git a/ntoskrnl/mm/section.c b/ntoskrnl/mm/section.c
index 524b282f606..16767458bce 100644
--- a/ntoskrnl/mm/section.c
+++ b/ntoskrnl/mm/section.c
@@ -4077,54 +4077,36 @@ BOOLEAN NTAPI
MmCanFileBeTruncated (IN PSECTION_OBJECT_POINTERS SectionObjectPointer,
IN PLARGE_INTEGER NewFileSize)
{
- KIRQL OldIrql = MiAcquirePfnLock();
BOOLEAN Ret;
PMM_SECTION_SEGMENT Segment;
-CheckSectionPointer:
/* Check whether an ImageSectionObject exists */
if (SectionObjectPointer->ImageSectionObject != NULL)
{
DPRINT1("ERROR: File can't be truncated because it has an image section\n");
- MiReleasePfnLock(OldIrql);
-
return FALSE;
}
- Segment = (PMM_SECTION_SEGMENT)SectionObjectPointer->DataSectionObject;
- /* Wait for it to be created/deleted properly */
- while (Segment && (Segment->SegFlags & (MM_SEGMENT_INCREATE | MM_SEGMENT_INDELETE)))
+ Segment = MiGrabDataSection(SectionObjectPointer);
+ if (!Segment)
{
- LARGE_INTEGER ShortTime;
-
- ShortTime.QuadPart = -10 * 100 * 1000;
-
- /* Bad luck. Wait a bit for the operation to finish */
- MiReleasePfnLock(OldIrql);
- KeDelayExecutionThread(KernelMode, FALSE, &ShortTime);
- OldIrql = MiAcquirePfnLock();
- goto CheckSectionPointer;
+ /* There is no data section. It's fine to do anything. */
+ return TRUE;
}
- if (Segment)
+ MmLockSectionSegment(Segment);
+ if ((Segment->SectionCount == 1) && (SectionObjectPointer->SharedCacheMap != NULL))
{
- if ((Segment->SectionCount == 1) && (SectionObjectPointer->SharedCacheMap != NULL))
- {
- /* If the cache is the only one holding a reference to the segment, then it's fine to resize */
- Ret = TRUE;
- }
- else
- {
- /* We can't shrink, but we can extend */
- Ret = NewFileSize->QuadPart >= Segment->RawLength.QuadPart;
- }
+ /* If the cache is the only one holding a reference to the segment, then it's fine to resize */
+ Ret = TRUE;
}
else
{
- Ret = TRUE;
+ /* We can't shrink, but we can extend */
+ Ret = NewFileSize->QuadPart >= Segment->RawLength.QuadPart;
}
-
- MiReleasePfnLock(OldIrql);
+ MmUnlockSectionSegment(Segment);
+ MmDereferenceSegment(Segment);
DPRINT("FIXME: didn't check for outstanding write probes\n");