https://git.reactos.org/?p=reactos.git;a=commitdiff;h=e980efebd4efe53a596cab313e825160c6bf76fb

commit e980efebd4efe53a596cab313e825160c6bf76fb
Author:     Jérôme Gardou <[email protected]>
AuthorDate: Fri Oct 23 17:27:47 2020 +0200
Commit:     Jérôme Gardou <[email protected]>
CommitDate: Wed Feb 3 09:41:21 2021 +0100

    [NTOSKRNL] Store the MM_IMAGE_SECTION_OBJECT pointer in SECTION::Segment
---
 ntoskrnl/include/internal/mm.h |  2 --
 ntoskrnl/mm/ARM3/section.c     |  8 +++++++-
 ntoskrnl/mm/ARM3/sysldr.c      | 20 ++++++++++----------
 ntoskrnl/mm/section.c          | 21 ++++++++++-----------
 4 files changed, 27 insertions(+), 24 deletions(-)

diff --git a/ntoskrnl/include/internal/mm.h b/ntoskrnl/include/internal/mm.h
index a7affb0a49c..760b514de4a 100644
--- a/ntoskrnl/include/internal/mm.h
+++ b/ntoskrnl/include/internal/mm.h
@@ -200,8 +200,6 @@ typedef struct _ROS_SECTION_OBJECT
 {
     SECTION;
     PFILE_OBJECT FileObject;
-
-    PMM_IMAGE_SECTION_OBJECT ImageSection;
 } ROS_SECTION_OBJECT, *PROS_SECTION_OBJECT;
 
 #define MA_GetStartingAddress(_MemoryArea) ((_MemoryArea)->VadNode.StartingVpn 
<< PAGE_SHIFT)
diff --git a/ntoskrnl/mm/ARM3/section.c b/ntoskrnl/mm/ARM3/section.c
index 58d261e5476..81ecdc9f8dc 100644
--- a/ntoskrnl/mm/ARM3/section.c
+++ b/ntoskrnl/mm/ARM3/section.c
@@ -1789,8 +1789,14 @@ MmGetImageInformation (OUT PSECTION_IMAGE_INFORMATION 
ImageInformation)
     ASSERT(SectionObject != NULL);
     ASSERT(MiIsRosSectionObject(SectionObject) == TRUE);
 
+    if (SectionObject->u.Flags.Image == 0)
+    {
+        RtlZeroMemory(ImageInformation, sizeof(*ImageInformation));
+        return;
+    }
+
     /* Return the image information */
-    *ImageInformation = 
((PROS_SECTION_OBJECT)SectionObject)->ImageSection->ImageInformation;
+    *ImageInformation = 
((PMM_IMAGE_SECTION_OBJECT)SectionObject->Segment)->ImageInformation;
 }
 
 NTSTATUS
diff --git a/ntoskrnl/mm/ARM3/sysldr.c b/ntoskrnl/mm/ARM3/sysldr.c
index 811defcde8b..0ebcae75e29 100644
--- a/ntoskrnl/mm/ARM3/sysldr.c
+++ b/ntoskrnl/mm/ARM3/sysldr.c
@@ -81,13 +81,13 @@ MiCacheImageSymbols(IN PVOID BaseAddress)
 
 NTSTATUS
 NTAPI
-MiLoadImageSection(IN OUT PVOID *SectionPtr,
-                   OUT PVOID *ImageBase,
-                   IN PUNICODE_STRING FileName,
-                   IN BOOLEAN SessionLoad,
-                   IN PLDR_DATA_TABLE_ENTRY LdrEntry)
+MiLoadImageSection(_Inout_ PSECTION *SectionPtr,
+                   _Out_ PVOID *ImageBase,
+                   _In_ PUNICODE_STRING FileName,
+                   _In_ BOOLEAN SessionLoad,
+                   _In_ PLDR_DATA_TABLE_ENTRY LdrEntry)
 {
-    PROS_SECTION_OBJECT Section = *SectionPtr;
+    PSECTION Section = *SectionPtr;
     NTSTATUS Status;
     PEPROCESS Process;
     PVOID Base = NULL;
@@ -158,7 +158,7 @@ MiLoadImageSection(IN OUT PVOID *SectionPtr,
     }
 
     /* Reserve system PTEs needed */
-    PteCount = 
ROUND_TO_PAGES(Section->ImageSection->ImageInformation.ImageFileSize) >> 
PAGE_SHIFT;
+    PteCount = 
ROUND_TO_PAGES(((PMM_IMAGE_SECTION_OBJECT)Section->Segment)->ImageInformation.ImageFileSize)
 >> PAGE_SHIFT;
     PointerPte = MiReserveSystemPtes(PteCount, SystemPteSpace);
     if (!PointerPte)
     {
@@ -2837,7 +2837,7 @@ MmLoadSystemImage(IN PUNICODE_STRING FileName,
     PWCHAR MissingDriverName;
     HANDLE SectionHandle;
     ACCESS_MASK DesiredAccess;
-    PVOID Section = NULL;
+    PSECTION Section = NULL;
     BOOLEAN LockOwned = FALSE;
     PLIST_ENTRY NextEntry;
     IMAGE_INFO ImageInfo;
@@ -3054,7 +3054,7 @@ LoaderScan:
                                            SECTION_MAP_EXECUTE,
                                            MmSectionObjectType,
                                            KernelMode,
-                                           &Section,
+                                           (PVOID*)&Section,
                                            NULL);
         ZwClose(SectionHandle);
         if (!NT_SUCCESS(Status)) goto Quickie;
@@ -3085,7 +3085,7 @@ LoaderScan:
     ASSERT(Status != STATUS_ALREADY_COMMITTED);
 
     /* Get the size of the driver */
-    DriverSize = 
((PROS_SECTION_OBJECT)Section)->ImageSection->ImageInformation.ImageFileSize;
+    DriverSize = 
((PMM_IMAGE_SECTION_OBJECT)Section->Segment)->ImageInformation.ImageFileSize;
 
     /* Make sure we're not being loaded into session space */
     if (!Flags)
diff --git a/ntoskrnl/mm/section.c b/ntoskrnl/mm/section.c
index 59b6a22ec36..73711677d41 100644
--- a/ntoskrnl/mm/section.c
+++ b/ntoskrnl/mm/section.c
@@ -2633,7 +2633,7 @@ MmpFreePageFileSegment(PMM_SECTION_SEGMENT Segment)
 VOID NTAPI
 MmpDeleteSection(PVOID ObjectBody)
 {
-    PROS_SECTION_OBJECT Section = (PROS_SECTION_OBJECT)ObjectBody;
+    PROS_SECTION_OBJECT Section = ObjectBody;
 
     /* Check if it's an ARM3, or ReactOS section */
     if (!MiIsRosSectionObject(Section))
@@ -2656,11 +2656,11 @@ MmpDeleteSection(PVOID ObjectBody)
          * until the image section is properly initialized we shouldn't
          * process further here.
          */
-        if (Section->ImageSection == NULL)
+        if (Section->Segment == NULL)
             return;
 
-        SectionSegments = Section->ImageSection->Segments;
-        NrSegments = Section->ImageSection->NrSegments;
+        SectionSegments = 
((PMM_IMAGE_SECTION_OBJECT)Section->Segment)->Segments;
+        NrSegments = ((PMM_IMAGE_SECTION_OBJECT)Section->Segment)->NrSegments;
 
         for (i = 0; i < NrSegments; i++)
         {
@@ -3763,7 +3763,7 @@ MmCreateImageSection(PROS_SECTION_OBJECT *SectionObject,
             return(Status);
         }
 
-        Section->ImageSection = ImageSectionObject;
+        Section->Segment = (PSEGMENT)ImageSectionObject;
         ASSERT(ImageSectionObject->Segments);
 
         /*
@@ -3788,7 +3788,7 @@ MmCreateImageSection(PROS_SECTION_OBJECT *SectionObject,
             ExFreePool(ImageSectionObject->Segments);
             ExFreePool(ImageSectionObject);
             ImageSectionObject = 
FileObject->SectionObjectPointer->ImageSectionObject;
-            Section->ImageSection = ImageSectionObject;
+            Section->Segment = (PSEGMENT)ImageSectionObject;
             SectionSegments = ImageSectionObject->Segments;
 
             for (i = 0; i < ImageSectionObject->NrSegments; i++)
@@ -3813,7 +3813,7 @@ MmCreateImageSection(PROS_SECTION_OBJECT *SectionObject,
         }
 
         ImageSectionObject = 
FileObject->SectionObjectPointer->ImageSectionObject;
-        Section->ImageSection = ImageSectionObject;
+        Section->Segment = (PSEGMENT)ImageSectionObject;
         SectionSegments = ImageSectionObject->Segments;
 
         /*
@@ -4114,7 +4114,7 @@ MiRosUnmapViewOfSection(IN PEPROCESS Process,
         PMM_SECTION_SEGMENT Segment;
 
         Segment = MemoryArea->SectionData.Segment;
-        ImageSectionObject = Section->ImageSection;
+        ImageSectionObject = ((PMM_IMAGE_SECTION_OBJECT)Section->Segment);
         SectionSegments = ImageSectionObject->Segments;
         NrSegments = ImageSectionObject->NrSegments;
 
@@ -4314,8 +4314,7 @@ NtQuerySection(
                 {
                     if (RosSection->u.Flags.Image)
                     {
-                        PMM_IMAGE_SECTION_OBJECT ImageSectionObject;
-                        ImageSectionObject = RosSection->ImageSection;
+                        PMM_IMAGE_SECTION_OBJECT ImageSectionObject = 
((PMM_IMAGE_SECTION_OBJECT)Section->Segment);
 
                         *Sii = ImageSectionObject->ImageInformation;
                     }
@@ -4504,7 +4503,7 @@ MmMapViewOfSection(IN PVOID SectionObject,
         PMM_IMAGE_SECTION_OBJECT ImageSectionObject;
         PMM_SECTION_SEGMENT SectionSegments;
 
-        ImageSectionObject = Section->ImageSection;
+        ImageSectionObject = ((PMM_IMAGE_SECTION_OBJECT)Section->Segment);
         SectionSegments = ImageSectionObject->Segments;
         NrSegments = ImageSectionObject->NrSegments;
 

Reply via email to