[NTOSKRNL/MM] Reduce use of MiIsRosSectionObject
authorJérôme Gardou <jerome.gardou@reactos.org>
Mon, 26 Oct 2020 10:23:42 +0000 (11:23 +0100)
committerJérôme Gardou <jerome.gardou@reactos.org>
Wed, 3 Feb 2021 08:41:21 +0000 (09:41 +0100)
ntoskrnl/mm/ARM3/section.c
ntoskrnl/mm/section.c

index 73c0e30..511f11a 100644 (file)
@@ -3716,7 +3716,7 @@ NtMapViewOfSection(IN HANDLE SectionHandle,
         return Status;
     }
 
-    if (MiIsRosSectionObject(Section) && Section->u.Flags.PhysicalMemory)
+    if (Section->u.Flags.PhysicalMemory)
     {
         if (PreviousMode == UserMode &&
             SafeSectionOffset.QuadPart + SafeViewSize > MmHighestPhysicalPage << PAGE_SHIFT)
@@ -3764,8 +3764,7 @@ NtMapViewOfSection(IN HANDLE SectionHandle,
     if (NT_SUCCESS(Status))
     {
         /* Check if this is an image for the current process */
-        if (MiIsRosSectionObject(Section) &&
-            (Section->u.Flags.Image) &&
+        if ((Section->u.Flags.Image) &&
             (Process == PsGetCurrentProcess()) &&
             (Status != STATUS_IMAGE_NOT_AT_BASE))
         {
index f43811e..5dd758f 100644 (file)
@@ -4279,131 +4279,98 @@ NtQuerySection(
         return Status;
     }
 
-    if (MiIsRosSectionObject(Section))
+    switch(SectionInformationClass)
     {
-        switch (SectionInformationClass)
+        case SectionBasicInformation:
         {
-            case SectionBasicInformation:
-            {
-                PSECTION_BASIC_INFORMATION Sbi = (PSECTION_BASIC_INFORMATION)SectionInformation;
+            SECTION_BASIC_INFORMATION Sbi;
 
-                _SEH2_TRY
-                {
-                    Sbi->Attributes = 0;
-                    if (Section->u.Flags.Image)
-                        Sbi->Attributes |= SEC_IMAGE;
-                    if (Section->u.Flags.File)
-                        Sbi->Attributes |= SEC_FILE;
-                    if (Section->u.Flags.NoChange)
-                        Sbi->Attributes |= SEC_NO_CHANGE;
-
-                    if (Section->u.Flags.Image)
-                    {
-                        Sbi->BaseAddress = 0;
-                        Sbi->Size.QuadPart = 0;
-                    }
-                    else
-                    {
-                        Sbi->BaseAddress = (PVOID)((PMM_SECTION_SEGMENT)Section->Segment)->Image.VirtualAddress;
-                        Sbi->Size.QuadPart = ((PMM_SECTION_SEGMENT)Section->Segment)->Length.QuadPart;
-                    }
+            Sbi.Size = Section->SizeOfSection;
+            Sbi.BaseAddress = (PVOID)Section->Address.StartingVpn;
 
-                    if (ResultLength != NULL)
-                    {
-                        *ResultLength = sizeof(SECTION_BASIC_INFORMATION);
-                    }
-                    Status = STATUS_SUCCESS;
-                }
-                _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
-                {
-                    Status = _SEH2_GetExceptionCode();
-                }
-                _SEH2_END;
+            Sbi.Attributes = 0;
+            if (Section->u.Flags.Commit)
+                Sbi.Attributes |= SEC_COMMIT;
+            if (Section->u.Flags.Reserve)
+                Sbi.Attributes |= SEC_RESERVE;
+            if (Section->u.Flags.File)
+                Sbi.Attributes |= SEC_FILE;
+            if (Section->u.Flags.Image)
+                Sbi.Attributes |= SEC_IMAGE;
 
-                break;
+            /* FIXME : Complete/test the list of flags passed back from NtCreateSection */
+
+            if (Section->u.Flags.Image)
+            {
+                Sbi.BaseAddress = 0;
+                Sbi.Size.QuadPart = 0;
+            }
+            else if (MiIsRosSectionObject(Section))
+            {
+                Sbi.BaseAddress = (PVOID)((PMM_SECTION_SEGMENT)Section->Segment)->Image.VirtualAddress;
+                Sbi.Size.QuadPart = ((PMM_SECTION_SEGMENT)Section->Segment)->Length.QuadPart;
+            }
+            else
+            {
+                DPRINT1("Unimplemented code path!");
             }
 
-            case SectionImageInformation:
+            _SEH2_TRY
+            {
+                *((SECTION_BASIC_INFORMATION*)SectionInformation) = Sbi;
+                if (ResultLength)
+                    *ResultLength = sizeof(Sbi);
+            }
+            _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
+            {
+                Status = _SEH2_GetExceptionCode();
+            }
+            _SEH2_END;
+            break;
+        }
+        case SectionImageInformation:
+        {
+            if (!Section->u.Flags.Image)
             {
-                PSECTION_IMAGE_INFORMATION Sii = (PSECTION_IMAGE_INFORMATION)SectionInformation;
+                Status = STATUS_SECTION_NOT_IMAGE;
+            }
+            else if (MiIsRosSectionObject(Section))
+            {
+                PMM_IMAGE_SECTION_OBJECT ImageSectionObject = ((PMM_IMAGE_SECTION_OBJECT)Section->Segment);
 
                 _SEH2_TRY
                 {
-                    if (Section->u.Flags.Image)
-                    {
-                        PMM_IMAGE_SECTION_OBJECT ImageSectionObject = ((PMM_IMAGE_SECTION_OBJECT)Section->Segment);
-
-                        *Sii = ImageSectionObject->ImageInformation;
-                    }
-
+                    PSECTION_IMAGE_INFORMATION Sii = (PSECTION_IMAGE_INFORMATION)SectionInformation;
+                    *Sii = ImageSectionObject->ImageInformation;
                     if (ResultLength != NULL)
-                    {
-                        *ResultLength = sizeof(SECTION_IMAGE_INFORMATION);
-                    }
-                    Status = STATUS_SUCCESS;
+                        *ResultLength = sizeof(*Sii);
                 }
                 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
                 {
                     Status = _SEH2_GetExceptionCode();
                 }
                 _SEH2_END;
-
-                break;
             }
-        }
-    }
-    else
-    {
-        switch(SectionInformationClass)
-        {
-            case SectionBasicInformation:
+            else
             {
-                SECTION_BASIC_INFORMATION Sbi;
-
-                Sbi.Size = Section->SizeOfSection;
-                Sbi.BaseAddress = (PVOID)Section->Address.StartingVpn;
-
-                Sbi.Attributes = 0;
-                if (Section->u.Flags.Image)
-                    Sbi.Attributes |= SEC_IMAGE;
-                if (Section->u.Flags.Commit)
-                    Sbi.Attributes |= SEC_COMMIT;
-                if (Section->u.Flags.Reserve)
-                    Sbi.Attributes |= SEC_RESERVE;
-                if (Section->u.Flags.File)
-                    Sbi.Attributes |= SEC_FILE;
-                if (Section->u.Flags.Image)
-                    Sbi.Attributes |= SEC_IMAGE;
-
-                /* FIXME : Complete/test the list of flags passed back from NtCreateSection */
-
                 _SEH2_TRY
                 {
-                    *((SECTION_BASIC_INFORMATION*)SectionInformation) = Sbi;
-                    if (ResultLength)
-                        *ResultLength = sizeof(Sbi);
+                    PSECTION_IMAGE_INFORMATION Sii = (PSECTION_IMAGE_INFORMATION)SectionInformation;
+                    *Sii = *Section->Segment->u2.ImageInformation;
+                    if (ResultLength != NULL)
+                        *ResultLength = sizeof(*Sii);
                 }
                 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
                 {
                     Status = _SEH2_GetExceptionCode();
                 }
                 _SEH2_END;
-                break;
-            }
-            case SectionImageInformation:
-            {
-                if (!Section->u.Flags.Image)
-                {
-                    Status = STATUS_SECTION_NOT_IMAGE;
-                }
-                else
-                {
-                    /* Currently not supported */
-                    ASSERT(FALSE);
-                }
-                break;
             }
+            break;
         }
+        default:
+            DPRINT1("Unknown SectionInformationClass: %d\n", SectionInformationClass);
+            Status = STATUS_NOT_SUPPORTED;
     }
 
     ObDereferenceObject(Section);