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");