[NTOSKRNL] Stubplement CcPinMappedData() and simplify CcPinRead()
authorPierre Schweitzer <pierre@reactos.org>
Sun, 26 Aug 2018 19:49:05 +0000 (21:49 +0200)
committerPierre Schweitzer <pierre@reactos.org>
Sun, 26 Aug 2018 20:05:11 +0000 (22:05 +0200)
It's based on the code that was in CcPinRead() implementation. This
made no sense to have CcPinMappedData() doing nothing while implementing
everything in CcPinRead(). Indeed, drivers (starting with MS drivers)
can map data first and pin it afterwards with CcPinMappedData(). It was
leading to incorrect behavior with our previous noop implementation.

ntoskrnl/cc/pin.c

index 2d48a27..8b99b8c 100644 (file)
@@ -161,6 +161,7 @@ CcPinMappedData (
     IN ULONG Flags,
     OUT        PVOID * Bcb)
 {
+    PINTERNAL_BCB iBcb;
     PROS_SHARED_CACHE_MAP SharedCacheMap;
 
     CCTRACE(CC_API_DEBUG, "FileOffset=%p FileOffset=%p Length=%lu Flags=0x%lx\n",
@@ -174,7 +175,21 @@ CcPinMappedData (
     ASSERT(SharedCacheMap);
     ASSERT(SharedCacheMap->PinAccess);
 
-    /* no-op for current implementation. */
+    iBcb = *Bcb;
+    ASSERT(iBcb->Pinned == FALSE);
+
+    iBcb->Pinned = TRUE;
+    iBcb->Vacb->PinCount++;
+
+    if (Flags & PIN_EXCLUSIVE)
+    {
+        ExAcquireResourceExclusiveLite(&iBcb->Lock, TRUE);
+    }
+    else
+    {
+        ExAcquireResourceSharedLite(&iBcb->Lock, TRUE);
+    }
+
     return TRUE;
 }
 
@@ -191,8 +206,6 @@ CcPinRead (
     OUT        PVOID * Bcb,
     OUT        PVOID * Buffer)
 {
-    PINTERNAL_BCB iBcb;
-
     CCTRACE(CC_API_DEBUG, "FileOffset=%p FileOffset=%p Length=%lu Flags=0x%lx\n",
         FileObject, FileOffset, Length, Flags);
 
@@ -205,32 +218,20 @@ CcPinRead (
         ++CcPinReadNoWait;
     }
 
-    if (CcMapData(FileObject, FileOffset, Length, Flags, Bcb, Buffer))
+    /* Map first */
+    if (!CcMapData(FileObject, FileOffset, Length, Flags, Bcb, Buffer))
     {
-        if (CcPinMappedData(FileObject, FileOffset, Length, Flags, Bcb))
-        {
-            iBcb = *Bcb;
-
-            ASSERT(iBcb->Pinned == FALSE);
-
-            iBcb->Pinned = TRUE;
-            iBcb->Vacb->PinCount++;
-
-            if (Flags & PIN_EXCLUSIVE)
-            {
-                ExAcquireResourceExclusiveLite(&iBcb->Lock, TRUE);
-            }
-            else
-            {
-                ExAcquireResourceSharedLite(&iBcb->Lock, TRUE);
-            }
+        return FALSE;
+    }
 
-            return TRUE;
-        }
-        else
-            CcUnpinData(*Bcb);
+    /* Pin then */
+    if (!CcPinMappedData(FileObject, FileOffset, Length, Flags, Bcb))
+    {
+        CcUnpinData(*Bcb);
+        return FALSE;
     }
-    return FALSE;
+
+    return TRUE;
 }
 
 /*