[ros-diffs] [arty] 35993: Fix permissions for section handle reference. Fix double alloc of MDL (spotted by stefan100) Streamline CcFlushCache and default success.

arty at svn.reactos.org arty at svn.reactos.org
Sat Sep 6 18:58:49 CEST 2008


Author: arty
Date: Sat Sep  6 11:58:48 2008
New Revision: 35993

URL: http://svn.reactos.org/svn/reactos?rev=35993&view=rev
Log:
Fix permissions for section handle reference.
Fix double alloc of MDL (spotted by stefan100)
Streamline CcFlushCache and default success.

Modified:
    branches/arty-newcc/ntoskrnl/cache/cachesub.c
    branches/arty-newcc/ntoskrnl/mm/section.c

Modified: branches/arty-newcc/ntoskrnl/cache/cachesub.c
URL: http://svn.reactos.org/svn/reactos/branches/arty-newcc/ntoskrnl/cache/cachesub.c?rev=35993&r1=35992&r2=35993&view=diff
==============================================================================
--- branches/arty-newcc/ntoskrnl/cache/cachesub.c [iso-8859-1] (original)
+++ branches/arty-newcc/ntoskrnl/cache/cachesub.c [iso-8859-1] Sat Sep  6 11:58:48 2008
@@ -205,66 +205,73 @@
              IN ULONG Length,
              OUT OPTIONAL PIO_STATUS_BLOCK IoStatus)
 {
-	PCHAR BufPage, BufStart;
-	PVOID Buffer;
-	PNOCC_BCB Bcb;
-	LARGE_INTEGER ToWrite = *FileOffset;
-	IO_STATUS_BLOCK IOSB;
-	PNOCC_CACHE_MAP Map = (PNOCC_CACHE_MAP)SectionObjectPointer->SharedCacheMap;
-
-	if (!SectionObjectPointer->SharedCacheMap)
-	{
-	    if (IoStatus)
-	    {
-		IoStatus->Status = STATUS_SUCCESS;
-		IoStatus->Information = 0;
-	    }
-	    return;
-	}
-
-	BOOLEAN Result = CcpMapData
-		(Map,
-		 FileOffset,
-		 Length,
-		 PIN_WAIT,
-		 (PVOID *)&Bcb,
-		 &Buffer);
-
-	/* Don't flush a pinned bcb, because we'll disturb the locked-ness
-	 * of the pages.  Figured out how to do this right. */
-	if (!Result || Bcb->Pinned || !Bcb->Dirty) return;
-	
-	BufStart = (PCHAR)PAGE_ROUND_DOWN(((ULONG_PTR)Buffer));
-	ToWrite.LowPart = PAGE_ROUND_DOWN(FileOffset->LowPart);
-
-	DPRINT
-	    ("CcpSimpleWrite: [%wZ] %x:%d\n", 
-	     &Bcb->FileObject->FileName,
-	     Buffer,
-	     Bcb->Length);
-
-	for (BufPage = BufStart;
-	     BufPage < BufStart + PAGE_ROUND_UP(Length);
-	     BufPage += PAGE_SIZE)
-	{
-	    CcpSimpleWrite(Bcb->FileObject, &ToWrite, BufPage, &IOSB);
-	    ToWrite.QuadPart += PAGE_SIZE;
-	}
-
-	Bcb->Dirty = FALSE;
-
-	DPRINT("Page Write: %08x\n", IOSB.Status);
-
-	if (IoStatus && NT_SUCCESS(IOSB.Status))
-	{
-	    IoStatus->Status = STATUS_SUCCESS;
-	    IoStatus->Information = Length;
-	}
-	else if (IoStatus)
-	{
-	    IoStatus->Status = IOSB.Status;
-	    IoStatus->Information = 0;
-	}
+    BOOLEAN Result;
+    PCHAR BufPage, BufStart;
+    PVOID Buffer;
+    PNOCC_BCB Bcb;
+    LARGE_INTEGER ToWrite = *FileOffset;
+    IO_STATUS_BLOCK IOSB;
+    PNOCC_CACHE_MAP Map = (PNOCC_CACHE_MAP)SectionObjectPointer->SharedCacheMap;
+    
+    if (IoStatus)
+    {
+	IoStatus->Status = STATUS_SUCCESS;
+	IoStatus->Information = 0;
+    }
+
+    if (!SectionObjectPointer->SharedCacheMap)
+    {
+	DPRINT("Attempt to flush a non-cached file section\n");
+	return;
+    }
+    
+    Result = CcpMapData
+	(Map,
+	 FileOffset,
+	 Length,
+	 0,
+	 (PVOID *)&Bcb,
+	 &Buffer);
+
+    if (!Result) 
+    {
+	DPRINT("The requested section wasn't mapped, therefore doesn't need to be flushed\n");
+	return;
+    }
+    
+    /* Don't flush a pinned bcb, because we'll disturb the locked-ness
+     * of the pages.  Figured out how to do this right. */
+    if (Bcb->Pinned || !Bcb->Dirty) 
+    {
+	DPRINT("Bailing because the area is pinned or not dirty\n");
+	return;
+    }
+    
+    BufStart = (PCHAR)PAGE_ROUND_DOWN(((ULONG_PTR)Buffer));
+    ToWrite.LowPart = PAGE_ROUND_DOWN(FileOffset->LowPart);
+    
+    DPRINT
+	("CcpSimpleWrite: [%wZ] %x:%d\n", 
+	 &Bcb->FileObject->FileName,
+	 Buffer,
+	 Bcb->Length);
+    
+    for (BufPage = BufStart;
+	 BufPage < BufStart + PAGE_ROUND_UP(Length);
+	 BufPage += PAGE_SIZE)
+    {
+	CcpSimpleWrite(Bcb->FileObject, &ToWrite, BufPage, &IOSB);
+	ToWrite.QuadPart += PAGE_SIZE;
+    }
+    
+    Bcb->Dirty = FALSE;
+    
+    DPRINT("Page Write: %08x\n", IOSB.Status);
+
+    if (IoStatus)
+    {
+	*IoStatus = IOSB;
+    }
 }
 
 BOOLEAN

Modified: branches/arty-newcc/ntoskrnl/mm/section.c
URL: http://svn.reactos.org/svn/reactos/branches/arty-newcc/ntoskrnl/mm/section.c?rev=35993&r1=35992&r2=35993&view=diff
==============================================================================
--- branches/arty-newcc/ntoskrnl/mm/section.c [iso-8859-1] (original)
+++ branches/arty-newcc/ntoskrnl/mm/section.c [iso-8859-1] Sat Sep  6 11:58:48 2008
@@ -45,7 +45,7 @@
 /* INCLUDES *****************************************************************/
 
 #include <ntoskrnl.h>
-#define NDEBUG
+//#define NDEBUG
 #include <internal/debug.h>
 #include <reactos/exeformat.h>
 
@@ -159,8 +159,6 @@
 
     _SEH_TRY
     {
-	/* Allocate an MDL */
-	Mdl = IoAllocateMdl(Buffer, Length, FALSE, TRUE, NULL);
 	MmProbeAndLockPages(Mdl, KernelMode, IoWriteAccess);
     }
     _SEH_HANDLE
@@ -4914,13 +4912,20 @@
 	return STATUS_INVALID_PAGE_PROTECTION;
     }
     
-    if ((DesiredAccess == SECTION_ALL_ACCESS ||
-	 (DesiredAccess & SECTION_MAP_WRITE)) &&
-	(Protection == PAGE_READWRITE ||
-	 Protection == PAGE_EXECUTE_READWRITE))
-	FileAccess = FILE_GENERIC_WRITE;
+    if (((DesiredAccess == SECTION_ALL_ACCESS ||
+	  (DesiredAccess & SECTION_MAP_WRITE)) &&
+	 (Protection == PAGE_READWRITE ||
+	  Protection == PAGE_EXECUTE_READWRITE)) &&
+	!(AllocationAttributes & SEC_IMAGE))
+    {
+	DPRINT("Creating a section with WRITE access\n");
+	FileAccess = FILE_READ_DATA | FILE_WRITE_DATA;
+    }
     else 
-	FileAccess = FILE_GENERIC_READ;
+    {
+	DPRINT("Creating a section with READ access\n");
+	FileAccess = FILE_READ_DATA;
+    }
     
     /*
      * Reference the file handle



More information about the Ros-diffs mailing list