[ros-diffs] [arty] 44243: Clean up locking in section mapping. This fixes the bugcheck at failure. Prep work for fixing another problem re: relocating image sections.

arty at svn.reactos.org arty at svn.reactos.org
Fri Nov 20 19:49:23 CET 2009


Author: arty
Date: Fri Nov 20 19:49:23 2009
New Revision: 44243

URL: http://svn.reactos.org/svn/reactos?rev=44243&view=rev
Log:
Clean up locking in section mapping.  This fixes the bugcheck at failure.  Prep work for
fixing another problem re: relocating image sections.

Modified:
    branches/arty-newcc/ntoskrnl/mm/section/data.c
    branches/arty-newcc/ntoskrnl/mm/section/image.c

Modified: branches/arty-newcc/ntoskrnl/mm/section/data.c
URL: http://svn.reactos.org/svn/reactos/branches/arty-newcc/ntoskrnl/mm/section/data.c?rev=44243&r1=44242&r2=44243&view=diff
==============================================================================
--- branches/arty-newcc/ntoskrnl/mm/section/data.c [iso-8859-1] (original)
+++ branches/arty-newcc/ntoskrnl/mm/section/data.c [iso-8859-1] Fri Nov 20 19:49:23 2009
@@ -2878,7 +2878,9 @@
 
    if (Section->AllocationAttributes & SEC_IMAGE)
    {
+	   DPRINT1("Mapping as image: %wZ\n", &Section->FileObject->FileName);
 	   Status = MiMapImageFileSection(AddressSpace, Section, BaseAddress);
+	   DPRINT1("Mapping %x\n", Status);
    }
    else
    {
@@ -2886,18 +2888,21 @@
       if ((Protect & (PAGE_READWRITE|PAGE_EXECUTE_READWRITE)) &&
           !(Section->SectionPageProtection & (PAGE_READWRITE|PAGE_EXECUTE_READWRITE)))
       {
+         MmUnlockAddressSpace(AddressSpace);
          return STATUS_SECTION_PROTECTION;
       }
       /* check for read access */
       if ((Protect & (PAGE_READONLY|PAGE_WRITECOPY|PAGE_EXECUTE_READ|PAGE_EXECUTE_WRITECOPY)) &&
           !(Section->SectionPageProtection & (PAGE_READONLY|PAGE_READWRITE|PAGE_WRITECOPY|PAGE_EXECUTE_READ|PAGE_EXECUTE_READWRITE|PAGE_EXECUTE_WRITECOPY)))
       {
+         MmUnlockAddressSpace(AddressSpace);
          return STATUS_SECTION_PROTECTION;
       }
       /* check for execute access */
       if ((Protect & (PAGE_EXECUTE|PAGE_EXECUTE_READ|PAGE_EXECUTE_READWRITE|PAGE_EXECUTE_WRITECOPY)) &&
           !(Section->SectionPageProtection & (PAGE_EXECUTE|PAGE_EXECUTE_READ|PAGE_EXECUTE_READWRITE|PAGE_EXECUTE_WRITECOPY)))
       {
+         MmUnlockAddressSpace(AddressSpace);
          return STATUS_SECTION_PROTECTION;
       }
 
@@ -2933,6 +2938,7 @@
       }
 
       MmLockSectionSegment(Section->Segment);
+	  DPRINT1("Mapping as data\n");
       Status = MiMapViewOfSegment(AddressSpace,
                                   Section,
                                   Section->Segment,
@@ -2941,17 +2947,14 @@
                                   Protect,
                                   &ViewOffset,
                                   AllocationType & (MEM_TOP_DOWN|SEC_NO_CHANGE));
+	  DPRINT1("Status %x\n", Status);
       MmUnlockSectionSegment(Section->Segment);
-      if (!NT_SUCCESS(Status))
-      {
-         MmUnlockAddressSpace(AddressSpace);
-         return(Status);
-      }
-   }
-
+   }
+
+   DPRINT1("Unlock address space\n");
    MmUnlockAddressSpace(AddressSpace);
-
-   return(STATUS_SUCCESS);
+   DPRINT1("Done\n");
+   return(Status);
 }
 
 /*

Modified: branches/arty-newcc/ntoskrnl/mm/section/image.c
URL: http://svn.reactos.org/svn/reactos/branches/arty-newcc/ntoskrnl/mm/section/image.c?rev=44243&r1=44242&r2=44243&view=diff
==============================================================================
--- branches/arty-newcc/ntoskrnl/mm/section/image.c [iso-8859-1] (original)
+++ branches/arty-newcc/ntoskrnl/mm/section/image.c [iso-8859-1] Fri Nov 20 19:49:23 2009
@@ -1660,6 +1660,7 @@
 	ULONG NrSegments;
 	ULONG_PTR ImageBase;
 	ULONG ImageSize;
+	NTSTATUS Status = STATUS_SUCCESS;
 	PMM_IMAGE_SECTION_OBJECT ImageSectionObject;
 	PMM_SECTION_SEGMENT SectionSegments;
 	
@@ -1694,14 +1695,12 @@
 		/* Fail if the user requested a fixed base address. */
 		if ((*BaseAddress) != NULL)
 		{
-            MmUnlockAddressSpace(AddressSpace);
             return(STATUS_UNSUCCESSFUL);
 		}
 		/* Otherwise find a gap to map the image. */
 		ImageBase = (ULONG_PTR)MmFindGap(AddressSpace, PAGE_ROUND_UP(ImageSize), PAGE_SIZE, FALSE);
 		if (ImageBase == 0)
 		{
-            MmUnlockAddressSpace(AddressSpace);
             return(STATUS_UNSUCCESSFUL);
 		}
 	}
@@ -1710,7 +1709,6 @@
 	{
 		if (!(SectionSegments[i].Image.Characteristics & IMAGE_SCN_TYPE_NOLOAD))
 		{
-			NTSTATUS Status;
             PVOID SBaseAddress = (PVOID)
 				((char*)ImageBase + (ULONG_PTR)SectionSegments[i].Image.VirtualAddress);
             MmLockSectionSegment(&SectionSegments[i]);
@@ -1723,16 +1721,13 @@
                                         0,
                                         0);
             MmUnlockSectionSegment(&SectionSegments[i]);
-            if (!NT_SUCCESS(Status))
-            {
-				MmUnlockAddressSpace(AddressSpace);
-				return(Status);
-            }
 		}
 	}
 	
-	*BaseAddress = (PVOID)ImageBase;
-	return STATUS_SUCCESS;
+	if (NT_SUCCESS(Status))
+		*BaseAddress = (PVOID)ImageBase;
+
+	return Status;
 }
 
 VOID static




More information about the Ros-diffs mailing list