mirror of
https://github.com/reactos/reactos.git
synced 2025-08-03 20:25:39 +00:00
[NTOSKRNL] Store File Object in the segment instead of Section object
This commit is contained in:
parent
e980efebd4
commit
8b98ff66ea
3 changed files with 41 additions and 21 deletions
|
@ -166,8 +166,9 @@ typedef ULONG_PTR SWAPENTRY;
|
||||||
|
|
||||||
typedef struct _MM_SECTION_SEGMENT
|
typedef struct _MM_SECTION_SEGMENT
|
||||||
{
|
{
|
||||||
|
PFILE_OBJECT FileObject;
|
||||||
|
|
||||||
FAST_MUTEX Lock; /* lock which protects the page directory */
|
FAST_MUTEX Lock; /* lock which protects the page directory */
|
||||||
PFILE_OBJECT FileObject;
|
|
||||||
LARGE_INTEGER RawLength; /* length of the segment which is part of the mapped file */
|
LARGE_INTEGER RawLength; /* length of the segment which is part of the mapped file */
|
||||||
LARGE_INTEGER Length; /* absolute length of the segment */
|
LARGE_INTEGER Length; /* absolute length of the segment */
|
||||||
ULONG ReferenceCount;
|
ULONG ReferenceCount;
|
||||||
|
@ -190,6 +191,8 @@ typedef struct _MM_SECTION_SEGMENT
|
||||||
|
|
||||||
typedef struct _MM_IMAGE_SECTION_OBJECT
|
typedef struct _MM_IMAGE_SECTION_OBJECT
|
||||||
{
|
{
|
||||||
|
PFILE_OBJECT FileObject;
|
||||||
|
|
||||||
SECTION_IMAGE_INFORMATION ImageInformation;
|
SECTION_IMAGE_INFORMATION ImageInformation;
|
||||||
PVOID BasedAddress;
|
PVOID BasedAddress;
|
||||||
ULONG NrSegments;
|
ULONG NrSegments;
|
||||||
|
@ -199,7 +202,6 @@ typedef struct _MM_IMAGE_SECTION_OBJECT
|
||||||
typedef struct _ROS_SECTION_OBJECT
|
typedef struct _ROS_SECTION_OBJECT
|
||||||
{
|
{
|
||||||
SECTION;
|
SECTION;
|
||||||
PFILE_OBJECT FileObject;
|
|
||||||
} ROS_SECTION_OBJECT, *PROS_SECTION_OBJECT;
|
} ROS_SECTION_OBJECT, *PROS_SECTION_OBJECT;
|
||||||
|
|
||||||
#define MA_GetStartingAddress(_MemoryArea) ((_MemoryArea)->VadNode.StartingVpn << PAGE_SHIFT)
|
#define MA_GetStartingAddress(_MemoryArea) ((_MemoryArea)->VadNode.StartingVpn << PAGE_SHIFT)
|
||||||
|
|
|
@ -1662,7 +1662,7 @@ MiGetFileObjectForSectionAddress(
|
||||||
{
|
{
|
||||||
/* Get the section pointer to the SECTION_OBJECT */
|
/* Get the section pointer to the SECTION_OBJECT */
|
||||||
Section = MemoryArea->SectionData.Section;
|
Section = MemoryArea->SectionData.Section;
|
||||||
*FileObject = Section->FileObject;
|
*FileObject = ((PMM_SECTION_SEGMENT)Section->Segment)->FileObject;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1705,7 +1705,7 @@ PFILE_OBJECT
|
||||||
NTAPI
|
NTAPI
|
||||||
MmGetFileObjectForSection(IN PVOID SectionObject)
|
MmGetFileObjectForSection(IN PVOID SectionObject)
|
||||||
{
|
{
|
||||||
PSECTION Section;
|
PSECTION Section = SectionObject;
|
||||||
ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL);
|
ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL);
|
||||||
ASSERT(SectionObject != NULL);
|
ASSERT(SectionObject != NULL);
|
||||||
|
|
||||||
|
@ -1713,12 +1713,11 @@ MmGetFileObjectForSection(IN PVOID SectionObject)
|
||||||
if (MiIsRosSectionObject(SectionObject) == FALSE)
|
if (MiIsRosSectionObject(SectionObject) == FALSE)
|
||||||
{
|
{
|
||||||
/* Return the file pointer stored in the control area */
|
/* Return the file pointer stored in the control area */
|
||||||
Section = SectionObject;
|
|
||||||
return Section->Segment->ControlArea->FilePointer;
|
return Section->Segment->ControlArea->FilePointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return the file object */
|
/* Return the file object */
|
||||||
return ((PROS_SECTION_OBJECT)SectionObject)->FileObject;
|
return ((PMM_SECTION_SEGMENT)Section->Segment)->FileObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
|
@ -1740,7 +1739,7 @@ MiGetFileObjectForVad(
|
||||||
{
|
{
|
||||||
/* Get the section pointer to the SECTION_OBJECT */
|
/* Get the section pointer to the SECTION_OBJECT */
|
||||||
Section = MemoryArea->SectionData.Section;
|
Section = MemoryArea->SectionData.Section;
|
||||||
FileObject = Section->FileObject;
|
FileObject = ((PMM_SECTION_SEGMENT)Section->Segment)->FileObject;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -847,6 +847,7 @@ MmFreeSectionSegments(PFILE_OBJECT FileObject)
|
||||||
}
|
}
|
||||||
MmFreePageTablesSectionSegment(&SectionSegments[i], NULL);
|
MmFreePageTablesSectionSegment(&SectionSegments[i], NULL);
|
||||||
}
|
}
|
||||||
|
ObDereferenceObject(ImageSectionObject->FileObject);
|
||||||
ExFreePool(ImageSectionObject->Segments);
|
ExFreePool(ImageSectionObject->Segments);
|
||||||
ExFreePool(ImageSectionObject);
|
ExFreePool(ImageSectionObject);
|
||||||
FileObject->SectionObjectPointer->ImageSectionObject = NULL;
|
FileObject->SectionObjectPointer->ImageSectionObject = NULL;
|
||||||
|
@ -863,6 +864,7 @@ MmFreeSectionSegments(PFILE_OBJECT FileObject)
|
||||||
DPRINT1("Data segment still referenced\n");
|
DPRINT1("Data segment still referenced\n");
|
||||||
KeBugCheck(MEMORY_MANAGEMENT);
|
KeBugCheck(MEMORY_MANAGEMENT);
|
||||||
}
|
}
|
||||||
|
ObDereferenceObject(Segment->FileObject);
|
||||||
MmFreePageTablesSectionSegment(Segment, NULL);
|
MmFreePageTablesSectionSegment(Segment, NULL);
|
||||||
ExFreePool(Segment);
|
ExFreePool(Segment);
|
||||||
FileObject->SectionObjectPointer->DataSectionObject = NULL;
|
FileObject->SectionObjectPointer->DataSectionObject = NULL;
|
||||||
|
@ -941,7 +943,7 @@ MmUnsharePageEntrySectionSegment(PROS_SECTION_OBJECT Section,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Page = PFN_FROM_SSE(Entry);
|
Page = PFN_FROM_SSE(Entry);
|
||||||
FileObject = Section->FileObject;
|
FileObject = Segment->FileObject;
|
||||||
if (FileObject != NULL &&
|
if (FileObject != NULL &&
|
||||||
!(Segment->Image.Characteristics & IMAGE_SCN_MEM_SHARED))
|
!(Segment->Image.Characteristics & IMAGE_SCN_MEM_SHARED))
|
||||||
{
|
{
|
||||||
|
@ -1047,7 +1049,7 @@ BOOLEAN MiIsPageFromCache(PMEMORY_AREA MemoryArea,
|
||||||
{
|
{
|
||||||
PROS_SHARED_CACHE_MAP SharedCacheMap;
|
PROS_SHARED_CACHE_MAP SharedCacheMap;
|
||||||
PROS_VACB Vacb;
|
PROS_VACB Vacb;
|
||||||
SharedCacheMap = MemoryArea->SectionData.Section->FileObject->SectionObjectPointer->SharedCacheMap;
|
SharedCacheMap = MemoryArea->SectionData.Segment->FileObject->SectionObjectPointer->SharedCacheMap;
|
||||||
Vacb = CcRosLookupVacb(SharedCacheMap, SegOffset + MemoryArea->SectionData.Segment->Image.FileOffset);
|
Vacb = CcRosLookupVacb(SharedCacheMap, SegOffset + MemoryArea->SectionData.Segment->Image.FileOffset);
|
||||||
if (Vacb)
|
if (Vacb)
|
||||||
{
|
{
|
||||||
|
@ -1106,7 +1108,7 @@ MiReadPage(PMEMORY_AREA MemoryArea,
|
||||||
BOOLEAN IsImageSection;
|
BOOLEAN IsImageSection;
|
||||||
LONGLONG Length;
|
LONGLONG Length;
|
||||||
|
|
||||||
FileObject = MemoryArea->SectionData.Section->FileObject;
|
FileObject = MemoryArea->SectionData.Segment->FileObject;
|
||||||
SharedCacheMap = FileObject->SectionObjectPointer->SharedCacheMap;
|
SharedCacheMap = FileObject->SectionObjectPointer->SharedCacheMap;
|
||||||
RawLength = MemoryArea->SectionData.Segment->RawLength.QuadPart;
|
RawLength = MemoryArea->SectionData.Segment->RawLength.QuadPart;
|
||||||
FileOffset = SegOffset + MemoryArea->SectionData.Segment->Image.FileOffset;
|
FileOffset = SegOffset + MemoryArea->SectionData.Segment->Image.FileOffset;
|
||||||
|
@ -2012,7 +2014,7 @@ MmPageOutSectionView(PMMSUPPORT AddressSpace,
|
||||||
#ifndef NEWCC
|
#ifndef NEWCC
|
||||||
FileOffset = Context.Offset.QuadPart + Context.Segment->Image.FileOffset;
|
FileOffset = Context.Offset.QuadPart + Context.Segment->Image.FileOffset;
|
||||||
IsImageSection = Context.Section->u.Flags.Image;
|
IsImageSection = Context.Section->u.Flags.Image;
|
||||||
FileObject = Context.Section->FileObject;
|
FileObject = Context.Segment->FileObject;
|
||||||
|
|
||||||
if (FileObject != NULL &&
|
if (FileObject != NULL &&
|
||||||
!(Context.Segment->Image.Characteristics & IMAGE_SCN_MEM_SHARED))
|
!(Context.Segment->Image.Characteristics & IMAGE_SCN_MEM_SHARED))
|
||||||
|
@ -2392,7 +2394,7 @@ MmWritePageSectionView(PMMSUPPORT AddressSpace,
|
||||||
Section = MemoryArea->SectionData.Section;
|
Section = MemoryArea->SectionData.Section;
|
||||||
IsImageSection = Section->u.Flags.Image;
|
IsImageSection = Section->u.Flags.Image;
|
||||||
|
|
||||||
FileObject = Section->FileObject;
|
FileObject = Segment->FileObject;
|
||||||
DirectMapped = FALSE;
|
DirectMapped = FALSE;
|
||||||
if (FileObject != NULL &&
|
if (FileObject != NULL &&
|
||||||
!(Segment->Image.Characteristics & IMAGE_SCN_MEM_SHARED))
|
!(Segment->Image.Characteristics & IMAGE_SCN_MEM_SHARED))
|
||||||
|
@ -2709,13 +2711,16 @@ MmpDeleteSection(PVOID ObjectBody)
|
||||||
|
|
||||||
(void)InterlockedDecrementUL(&((PMM_SECTION_SEGMENT)Section->Segment)->ReferenceCount);
|
(void)InterlockedDecrementUL(&((PMM_SECTION_SEGMENT)Section->Segment)->ReferenceCount);
|
||||||
}
|
}
|
||||||
if (Section->FileObject != NULL)
|
|
||||||
|
if (Section->Segment)
|
||||||
{
|
{
|
||||||
#ifndef NEWCC
|
PMM_SECTION_SEGMENT Segment = (PMM_SECTION_SEGMENT)Section->Segment;
|
||||||
CcRosDereferenceCache(Section->FileObject);
|
if (Segment->FileObject != NULL)
|
||||||
#endif
|
{
|
||||||
ObDereferenceObject(Section->FileObject);
|
#ifndef NEWCC
|
||||||
Section->FileObject = NULL;
|
CcRosDereferenceCache(Segment->FileObject);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2986,6 +2991,7 @@ MmCreateDataFileSection(PROS_SECTION_OBJECT *SectionObject,
|
||||||
Section->Segment = (PSEGMENT)Segment;
|
Section->Segment = (PSEGMENT)Segment;
|
||||||
Segment->ReferenceCount = 1;
|
Segment->ReferenceCount = 1;
|
||||||
ExInitializeFastMutex(&Segment->Lock);
|
ExInitializeFastMutex(&Segment->Lock);
|
||||||
|
Segment->FileObject = FileObject;
|
||||||
/*
|
/*
|
||||||
* Set the lock before assigning the segment to the file object
|
* Set the lock before assigning the segment to the file object
|
||||||
*/
|
*/
|
||||||
|
@ -3029,9 +3035,12 @@ MmCreateDataFileSection(PROS_SECTION_OBJECT *SectionObject,
|
||||||
Segment->RawLength.QuadPart = MaximumSize.QuadPart;
|
Segment->RawLength.QuadPart = MaximumSize.QuadPart;
|
||||||
Segment->Length.QuadPart = PAGE_ROUND_UP(Segment->RawLength.QuadPart);
|
Segment->Length.QuadPart = PAGE_ROUND_UP(Segment->RawLength.QuadPart);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* We let the segment reference the file object */
|
||||||
|
ObDereferenceObject(FileObject);
|
||||||
|
FileObject = Segment->FileObject;
|
||||||
}
|
}
|
||||||
MmUnlockSectionSegment(Segment);
|
MmUnlockSectionSegment(Segment);
|
||||||
Section->FileObject = FileObject;
|
|
||||||
Section->SizeOfSection = MaximumSize;
|
Section->SizeOfSection = MaximumSize;
|
||||||
#ifndef NEWCC
|
#ifndef NEWCC
|
||||||
CcRosReferenceCache(FileObject);
|
CcRosReferenceCache(FileObject);
|
||||||
|
@ -3663,8 +3672,11 @@ ExeFmtpCreateImageSection(PFILE_OBJECT FileObject,
|
||||||
ExInitializeFastMutex(&ImageSectionObject->Segments[i].Lock);
|
ExInitializeFastMutex(&ImageSectionObject->Segments[i].Lock);
|
||||||
ImageSectionObject->Segments[i].ReferenceCount = 1;
|
ImageSectionObject->Segments[i].ReferenceCount = 1;
|
||||||
MiInitializeSectionPageTable(&ImageSectionObject->Segments[i]);
|
MiInitializeSectionPageTable(&ImageSectionObject->Segments[i]);
|
||||||
|
ImageSectionObject->Segments[i].FileObject = FileObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ImageSectionObject->FileObject = FileObject;
|
||||||
|
|
||||||
ASSERT(NT_SUCCESS(Status));
|
ASSERT(NT_SUCCESS(Status));
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
@ -3795,6 +3807,10 @@ MmCreateImageSection(PROS_SECTION_OBJECT *SectionObject,
|
||||||
{
|
{
|
||||||
(void)InterlockedIncrementUL(&SectionSegments[i].ReferenceCount);
|
(void)InterlockedIncrementUL(&SectionSegments[i].ReferenceCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* We let the Image Section Object hold the reference */
|
||||||
|
ObDereferenceObject(FileObject);
|
||||||
|
FileObject = ImageSectionObject->FileObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
Status = StatusExeFmt;
|
Status = StatusExeFmt;
|
||||||
|
@ -3824,9 +3840,12 @@ MmCreateImageSection(PROS_SECTION_OBJECT *SectionObject,
|
||||||
(void)InterlockedIncrementUL(&SectionSegments[i].ReferenceCount);
|
(void)InterlockedIncrementUL(&SectionSegments[i].ReferenceCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* We let the Image Section Object hold the reference */
|
||||||
|
ObDereferenceObject(FileObject);
|
||||||
|
FileObject = ImageSectionObject->FileObject;
|
||||||
|
|
||||||
Status = STATUS_SUCCESS;
|
Status = STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
Section->FileObject = FileObject;
|
|
||||||
#ifndef NEWCC
|
#ifndef NEWCC
|
||||||
CcRosReferenceCache(FileObject);
|
CcRosReferenceCache(FileObject);
|
||||||
#endif
|
#endif
|
||||||
|
@ -3963,7 +3982,7 @@ MmFreeSectionPage(PVOID Context, MEMORY_AREA* MemoryArea, PVOID Address,
|
||||||
if (Page == PFN_FROM_SSE(Entry) && Dirty)
|
if (Page == PFN_FROM_SSE(Entry) && Dirty)
|
||||||
{
|
{
|
||||||
#ifndef NEWCC
|
#ifndef NEWCC
|
||||||
FileObject = MemoryArea->SectionData.Section->FileObject;
|
FileObject = MemoryArea->SectionData.Segment->FileObject;
|
||||||
SharedCacheMap = FileObject->SectionObjectPointer->SharedCacheMap;
|
SharedCacheMap = FileObject->SectionObjectPointer->SharedCacheMap;
|
||||||
CcRosMarkDirtyFile(SharedCacheMap, Offset.QuadPart + Segment->Image.FileOffset);
|
CcRosMarkDirtyFile(SharedCacheMap, Offset.QuadPart + Segment->Image.FileOffset);
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue