From c9f924940a954b0f558319e1df95c1c2d71e2dfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Gardou?= Date: Fri, 23 Oct 2020 16:44:24 +0200 Subject: [PATCH] [NTOSKRNL/MM] Get rid of useless members of MEMORY_AREA struct --- ntoskrnl/include/internal/mm.h | 20 +++----- ntoskrnl/mm/ARM3/section.c | 4 +- ntoskrnl/mm/rmap.c | 12 ++--- ntoskrnl/mm/section.c | 90 +++++++++++++++++----------------- 4 files changed, 60 insertions(+), 66 deletions(-) diff --git a/ntoskrnl/include/internal/mm.h b/ntoskrnl/include/internal/mm.h index 4ca7e6717aa..4bb6d1a60ca 100644 --- a/ntoskrnl/include/internal/mm.h +++ b/ntoskrnl/include/internal/mm.h @@ -217,20 +217,14 @@ typedef struct _MEMORY_AREA BOOLEAN DeleteInProgress; ULONG Magic; PVOID Vad; - union + + struct { - struct - { - PROS_SECTION_OBJECT Section; - LARGE_INTEGER ViewOffset; - PMM_SECTION_SEGMENT Segment; - LIST_ENTRY RegionListHead; - } SectionData; - struct - { - LIST_ENTRY RegionListHead; - } VirtualMemoryData; - } Data; + PROS_SECTION_OBJECT Section; + LARGE_INTEGER ViewOffset; + PMM_SECTION_SEGMENT Segment; + LIST_ENTRY RegionListHead; + } SectionData; } MEMORY_AREA, *PMEMORY_AREA; typedef struct _MM_RMAP_ENTRY diff --git a/ntoskrnl/mm/ARM3/section.c b/ntoskrnl/mm/ARM3/section.c index 1090a8dfada..58d261e5476 100644 --- a/ntoskrnl/mm/ARM3/section.c +++ b/ntoskrnl/mm/ARM3/section.c @@ -1661,7 +1661,7 @@ MiGetFileObjectForSectionAddress( if (MemoryArea->Type == MEMORY_AREA_SECTION_VIEW) { /* Get the section pointer to the SECTION_OBJECT */ - Section = MemoryArea->Data.SectionData.Section; + Section = MemoryArea->SectionData.Section; *FileObject = Section->FileObject; } else @@ -1739,7 +1739,7 @@ MiGetFileObjectForVad( if (MemoryArea->Type == MEMORY_AREA_SECTION_VIEW) { /* Get the section pointer to the SECTION_OBJECT */ - Section = MemoryArea->Data.SectionData.Section; + Section = MemoryArea->SectionData.Section; FileObject = Section->FileObject; } else diff --git a/ntoskrnl/mm/rmap.c b/ntoskrnl/mm/rmap.c index 9fea631dd09..9f5938d7496 100644 --- a/ntoskrnl/mm/rmap.c +++ b/ntoskrnl/mm/rmap.c @@ -132,19 +132,19 @@ MmPageOutPhysicalAddress(PFN_NUMBER Page) if (Type == MEMORY_AREA_SECTION_VIEW) { ULONG_PTR Entry; - Offset = MemoryArea->Data.SectionData.ViewOffset.QuadPart + + Offset = MemoryArea->SectionData.ViewOffset.QuadPart + ((ULONG_PTR)Address - MA_GetStartingAddress(MemoryArea)); - MmLockSectionSegment(MemoryArea->Data.SectionData.Segment); + MmLockSectionSegment(MemoryArea->SectionData.Segment); /* * Get or create a pageop */ - Entry = MmGetPageEntrySectionSegment(MemoryArea->Data.SectionData.Segment, + Entry = MmGetPageEntrySectionSegment(MemoryArea->SectionData.Segment, (PLARGE_INTEGER)&Offset); if (Entry && MM_IS_WAIT_PTE(Entry)) { - MmUnlockSectionSegment(MemoryArea->Data.SectionData.Segment); + MmUnlockSectionSegment(MemoryArea->SectionData.Segment); MmUnlockAddressSpace(AddressSpace); if (Address < MmSystemRangeStart) { @@ -154,12 +154,12 @@ MmPageOutPhysicalAddress(PFN_NUMBER Page) return(STATUS_UNSUCCESSFUL); } - MmSetPageEntrySectionSegment(MemoryArea->Data.SectionData.Segment, (PLARGE_INTEGER)&Offset, MAKE_SWAP_SSE(MM_WAIT_ENTRY)); + MmSetPageEntrySectionSegment(MemoryArea->SectionData.Segment, (PLARGE_INTEGER)&Offset, MAKE_SWAP_SSE(MM_WAIT_ENTRY)); /* * Release locks now we have a page op. */ - MmUnlockSectionSegment(MemoryArea->Data.SectionData.Segment); + MmUnlockSectionSegment(MemoryArea->SectionData.Segment); MmUnlockAddressSpace(AddressSpace); /* diff --git a/ntoskrnl/mm/section.c b/ntoskrnl/mm/section.c index 32ee1f48786..91ef5133849 100644 --- a/ntoskrnl/mm/section.c +++ b/ntoskrnl/mm/section.c @@ -1043,12 +1043,12 @@ BOOLEAN MiIsPageFromCache(PMEMORY_AREA MemoryArea, LONGLONG SegOffset) { #ifndef NEWCC - if (!(MemoryArea->Data.SectionData.Segment->Image.Characteristics & IMAGE_SCN_MEM_SHARED)) + if (!(MemoryArea->SectionData.Segment->Image.Characteristics & IMAGE_SCN_MEM_SHARED)) { PROS_SHARED_CACHE_MAP SharedCacheMap; PROS_VACB Vacb; - SharedCacheMap = MemoryArea->Data.SectionData.Section->FileObject->SectionObjectPointer->SharedCacheMap; - Vacb = CcRosLookupVacb(SharedCacheMap, SegOffset + MemoryArea->Data.SectionData.Segment->Image.FileOffset); + SharedCacheMap = MemoryArea->SectionData.Section->FileObject->SectionObjectPointer->SharedCacheMap; + Vacb = CcRosLookupVacb(SharedCacheMap, SegOffset + MemoryArea->SectionData.Segment->Image.FileOffset); if (Vacb) { CcRosReleaseVacb(SharedCacheMap, Vacb, Vacb->Valid, FALSE, TRUE); @@ -1106,11 +1106,11 @@ MiReadPage(PMEMORY_AREA MemoryArea, BOOLEAN IsImageSection; LONGLONG Length; - FileObject = MemoryArea->Data.SectionData.Section->FileObject; + FileObject = MemoryArea->SectionData.Section->FileObject; SharedCacheMap = FileObject->SectionObjectPointer->SharedCacheMap; - RawLength = MemoryArea->Data.SectionData.Segment->RawLength.QuadPart; - FileOffset = SegOffset + MemoryArea->Data.SectionData.Segment->Image.FileOffset; - IsImageSection = MemoryArea->Data.SectionData.Section->u.Flags.Image; + RawLength = MemoryArea->SectionData.Segment->RawLength.QuadPart; + FileOffset = SegOffset + MemoryArea->SectionData.Segment->Image.FileOffset; + IsImageSection = MemoryArea->SectionData.Section->u.Flags.Image; ASSERT(SharedCacheMap); @@ -1123,7 +1123,7 @@ MiReadPage(PMEMORY_AREA MemoryArea, */ if (((FileOffset % PAGE_SIZE) == 0) && ((SegOffset + PAGE_SIZE <= RawLength) || !IsImageSection) && - !(MemoryArea->Data.SectionData.Segment->Image.Characteristics & IMAGE_SCN_MEM_SHARED)) + !(MemoryArea->SectionData.Segment->Image.Characteristics & IMAGE_SCN_MEM_SHARED)) { /* @@ -1282,9 +1282,9 @@ MiReadPage(PMEMORY_AREA MemoryArea, RtlZeroMemory(&Resources, sizeof(MM_REQUIRED_RESOURCES)); - Resources.Context = MemoryArea->Data.SectionData.Section->FileObject; + Resources.Context = MemoryArea->SectionData.Section->FileObject; Resources.FileOffset.QuadPart = SegOffset + - MemoryArea->Data.SectionData.Segment->Image.FileOffset; + MemoryArea->SectionData.Segment->Image.FileOffset; Resources.Consumer = MC_USER; Resources.Amount = PAGE_SIZE; @@ -1313,7 +1313,7 @@ MmAlterViewAttributes(PMMSUPPORT AddressSpace, MemoryArea = MmLocateMemoryAreaByAddress(AddressSpace, BaseAddress); ASSERT(MemoryArea != NULL); - Segment = MemoryArea->Data.SectionData.Segment; + Segment = MemoryArea->SectionData.Segment; MmLockSectionSegment(Segment); if ((Segment->WriteCopy) && @@ -1351,7 +1351,7 @@ MmAlterViewAttributes(PMMSUPPORT AddressSpace, PFN_NUMBER Page; Offset.QuadPart = (ULONG_PTR)Address - MA_GetStartingAddress(MemoryArea) - + MemoryArea->Data.SectionData.ViewOffset.QuadPart; + + MemoryArea->SectionData.ViewOffset.QuadPart; Entry = MmGetPageEntrySectionSegment(Segment, &Offset); /* * An MM_WAIT_ENTRY is ok in this case... It'll just count as @@ -1423,12 +1423,12 @@ MmNotPresentFaultSectionView(PMMSUPPORT AddressSpace, PAddress = MM_ROUND_DOWN(Address, PAGE_SIZE); Offset.QuadPart = (ULONG_PTR)PAddress - MA_GetStartingAddress(MemoryArea) - + MemoryArea->Data.SectionData.ViewOffset.QuadPart; + + MemoryArea->SectionData.ViewOffset.QuadPart; - Segment = MemoryArea->Data.SectionData.Segment; - Section = MemoryArea->Data.SectionData.Section; + Segment = MemoryArea->SectionData.Segment; + Section = MemoryArea->SectionData.Section; Region = MmFindRegion((PVOID)MA_GetStartingAddress(MemoryArea), - &MemoryArea->Data.SectionData.RegionListHead, + &MemoryArea->SectionData.RegionListHead, Address, NULL); ASSERT(Region != NULL); @@ -1442,7 +1442,7 @@ MmNotPresentFaultSectionView(PMMSUPPORT AddressSpace, { /* Remove it */ Status = MmAlterRegion(AddressSpace, (PVOID)MA_GetStartingAddress(MemoryArea), - &MemoryArea->Data.SectionData.RegionListHead, + &MemoryArea->SectionData.RegionListHead, Address, PAGE_SIZE, Region->Type, Region->Protect & ~PAGE_GUARD, MmAlterViewAttributes); @@ -1844,12 +1844,12 @@ MmAccessFaultSectionView(PMMSUPPORT AddressSpace, */ PAddress = MM_ROUND_DOWN(Address, PAGE_SIZE); Offset.QuadPart = (ULONG_PTR)PAddress - MA_GetStartingAddress(MemoryArea) - + MemoryArea->Data.SectionData.ViewOffset.QuadPart; + + MemoryArea->SectionData.ViewOffset.QuadPart; - Segment = MemoryArea->Data.SectionData.Segment; - Section = MemoryArea->Data.SectionData.Section; + Segment = MemoryArea->SectionData.Segment; + Section = MemoryArea->SectionData.Section; Region = MmFindRegion((PVOID)MA_GetStartingAddress(MemoryArea), - &MemoryArea->Data.SectionData.RegionListHead, + &MemoryArea->SectionData.RegionListHead, Address, NULL); ASSERT(Region != NULL); @@ -1997,13 +1997,13 @@ MmPageOutSectionView(PMMSUPPORT AddressSpace, /* * Get the segment and section. */ - Context.Segment = MemoryArea->Data.SectionData.Segment; - Context.Section = MemoryArea->Data.SectionData.Section; + Context.Segment = MemoryArea->SectionData.Segment; + Context.Section = MemoryArea->SectionData.Section; Context.SectionEntry = Entry; Context.CallingProcess = Process; Context.Offset.QuadPart = (ULONG_PTR)Address - MA_GetStartingAddress(MemoryArea) - + MemoryArea->Data.SectionData.ViewOffset.QuadPart; + + MemoryArea->SectionData.ViewOffset.QuadPart; DirectMapped = FALSE; @@ -2383,13 +2383,13 @@ MmWritePageSectionView(PMMSUPPORT AddressSpace, Address = (PVOID)PAGE_ROUND_DOWN(Address); Offset.QuadPart = (ULONG_PTR)Address - MA_GetStartingAddress(MemoryArea) - + MemoryArea->Data.SectionData.ViewOffset.QuadPart; + + MemoryArea->SectionData.ViewOffset.QuadPart; /* * Get the segment and section. */ - Segment = MemoryArea->Data.SectionData.Segment; - Section = MemoryArea->Data.SectionData.Section; + Segment = MemoryArea->SectionData.Segment; + Section = MemoryArea->SectionData.Section; IsImageSection = Section->u.Flags.Image; FileObject = Section->FileObject; @@ -2528,7 +2528,7 @@ MmProtectSectionView(PMMSUPPORT AddressSpace, Length = (ULONG)MaxLength; Region = MmFindRegion((PVOID)MA_GetStartingAddress(MemoryArea), - &MemoryArea->Data.SectionData.RegionListHead, + &MemoryArea->SectionData.RegionListHead, BaseAddress, NULL); ASSERT(Region != NULL); @@ -2540,7 +2540,7 @@ MmProtectSectionView(PMMSUPPORT AddressSpace, *OldProtect = Region->Protect; Status = MmAlterRegion(AddressSpace, (PVOID)MA_GetStartingAddress(MemoryArea), - &MemoryArea->Data.SectionData.RegionListHead, + &MemoryArea->SectionData.RegionListHead, BaseAddress, Length, Region->Type, Protect, MmAlterViewAttributes); @@ -2559,17 +2559,17 @@ MmQuerySectionView(PMEMORY_AREA MemoryArea, PMM_SECTION_SEGMENT Segment; Region = MmFindRegion((PVOID)MA_GetStartingAddress(MemoryArea), - &MemoryArea->Data.SectionData.RegionListHead, + &MemoryArea->SectionData.RegionListHead, Address, &RegionBaseAddress); if (Region == NULL) { return STATUS_UNSUCCESSFUL; } - Section = MemoryArea->Data.SectionData.Section; + Section = MemoryArea->SectionData.Section; if (Section->u.Flags.Image) { - Segment = MemoryArea->Data.SectionData.Segment; + Segment = MemoryArea->SectionData.Segment; Info->AllocationBase = (PUCHAR)MA_GetStartingAddress(MemoryArea) - Segment->Image.VirtualAddress; Info->Type = MEM_IMAGE; } @@ -3899,15 +3899,15 @@ MmMapViewOfSegment(PMMSUPPORT AddressSpace, ObReferenceObject((PVOID)Section); - MArea->Data.SectionData.Segment = Segment; - MArea->Data.SectionData.Section = Section; - MArea->Data.SectionData.ViewOffset.QuadPart = ViewOffset; + MArea->SectionData.Segment = Segment; + MArea->SectionData.Section = Section; + MArea->SectionData.ViewOffset.QuadPart = ViewOffset; if (Section->u.Flags.Image) { MArea->VadNode.u.VadFlags.VadType = VadImageMap; } - MmInitializeRegion(&MArea->Data.SectionData.RegionListHead, + MmInitializeRegion(&MArea->SectionData.RegionListHead, ViewSize, 0, Protect); return(STATUS_SUCCESS); @@ -3936,10 +3936,10 @@ MmFreeSectionPage(PVOID Context, MEMORY_AREA* MemoryArea, PVOID Address, Address = (PVOID)PAGE_ROUND_DOWN(Address); Offset.QuadPart = ((ULONG_PTR)Address - MA_GetStartingAddress(MemoryArea)) + - MemoryArea->Data.SectionData.ViewOffset.QuadPart; + MemoryArea->SectionData.ViewOffset.QuadPart; - Section = MemoryArea->Data.SectionData.Section; - Segment = MemoryArea->Data.SectionData.Segment; + Section = MemoryArea->SectionData.Section; + Segment = MemoryArea->SectionData.Segment; Entry = MmGetPageEntrySectionSegment(Segment, &Offset); while (Entry && MM_IS_WAIT_PTE(Entry)) @@ -3963,7 +3963,7 @@ MmFreeSectionPage(PVOID Context, MEMORY_AREA* MemoryArea, PVOID Address, if (Page == PFN_FROM_SSE(Entry) && Dirty) { #ifndef NEWCC - FileObject = MemoryArea->Data.SectionData.Section->FileObject; + FileObject = MemoryArea->SectionData.Section->FileObject; SharedCacheMap = FileObject->SectionObjectPointer->SharedCacheMap; CcRosMarkDirtyFile(SharedCacheMap, Offset.QuadPart + Segment->Image.FileOffset); #endif @@ -4022,8 +4022,8 @@ MmUnmapViewOfSegment(PMMSUPPORT AddressSpace, return(STATUS_UNSUCCESSFUL); } - Section = MemoryArea->Data.SectionData.Section; - Segment = MemoryArea->Data.SectionData.Segment; + Section = MemoryArea->SectionData.Section; + Segment = MemoryArea->SectionData.Segment; #ifdef NEWCC if (Segment->Flags & MM_DATAFILE_SEGMENT) @@ -4040,7 +4040,7 @@ MmUnmapViewOfSegment(PMMSUPPORT AddressSpace, MmLockSectionSegment(Segment); - RegionListHead = &MemoryArea->Data.SectionData.RegionListHead; + RegionListHead = &MemoryArea->SectionData.RegionListHead; while (!IsListEmpty(RegionListHead)) { CurrentEntry = RemoveHeadList(RegionListHead); @@ -4103,7 +4103,7 @@ MiRosUnmapViewOfSection(IN PEPROCESS Process, return STATUS_NOT_MAPPED_VIEW; } - Section = MemoryArea->Data.SectionData.Section; + Section = MemoryArea->SectionData.Section; if ((Section != NULL) && Section->u.Flags.Image) { @@ -4113,7 +4113,7 @@ MiRosUnmapViewOfSection(IN PEPROCESS Process, PMM_SECTION_SEGMENT SectionSegments; PMM_SECTION_SEGMENT Segment; - Segment = MemoryArea->Data.SectionData.Segment; + Segment = MemoryArea->SectionData.Segment; ImageSectionObject = Section->ImageSection; SectionSegments = ImageSectionObject->Segments; NrSegments = ImageSectionObject->NrSegments;