Merge 36852, 37322, 37333, 37334, 43428, 43451, 44259, 46404 from amd64 branch.
[reactos.git] / reactos / ntoskrnl / io / iomgr / irp.c
index 76e0be0..a578e89 100644 (file)
@@ -1217,12 +1217,21 @@ IofCompleteRequest(IN PIRP Irp,
         ErrorCode = PtrToUlong(LastStackPtr->Parameters.Others.Argument4);
     }
 
-    /* Get the Current Stack and skip it */
-    StackPtr = IoGetCurrentIrpStackLocation(Irp);
-    IoSkipCurrentIrpStackLocation(Irp);
-
-    /* Loop the Stacks and complete the IRPs */
-    do
+    /*
+     * Start the loop with the current stack and point the IRP to the next stack
+     * and then keep incrementing the stack as we loop through. The IRP should
+     * always point to the next stack location w.r.t the one currently being
+     * analyzed, so completion routine code will see the appropriate value.
+     * Because of this, we must loop until the current stack location is +1 of
+     * the stack count, because when StackPtr is at the end, CurrentLocation is +1.
+     */
+    for (StackPtr = IoGetCurrentIrpStackLocation(Irp),
+         Irp->CurrentLocation++,
+         Irp->Tail.Overlay.CurrentStackLocation++;
+         Irp->CurrentLocation <= (Irp->StackCount + 1);
+         StackPtr++,
+         Irp->CurrentLocation++,
+         Irp->Tail.Overlay.CurrentStackLocation++)
     {
         /* Set Pending Returned */
         Irp->PendingReturned = StackPtr->Control & SL_PENDING_RETURNED;
@@ -1285,11 +1294,7 @@ IofCompleteRequest(IN PIRP Irp,
             /* Clear the stack location */
             IopClearStackLocation(StackPtr);
         }
-
-        /* Move to next stack location and pointer */
-        IoSkipCurrentIrpStackLocation(Irp);
-        StackPtr++;
-    } while (Irp->CurrentLocation <= (Irp->StackCount + 1));
+    }
 
     /* Check if the IRP is an associated IRP */
     if (Irp->Flags & IRP_ASSOCIATED_IRP)
@@ -1552,7 +1557,7 @@ IoFreeIrp(IN PIRP Irp)
         if (Irp)
         {
            InterlockedPushEntrySList(&List->L.ListHead,
-                                     (PSINGLE_LIST_ENTRY)Irp);
+                                     (PSLIST_ENTRY)Irp);
         }
     }
 }
@@ -1622,7 +1627,7 @@ IoGetRequestorSessionId(IN PIRP Irp,
                         OUT PULONG pSessionId)
 {
     /* Return the session */
-    *pSessionId = (ULONG_PTR)IoGetRequestorProcess(Irp)->Session;
+    *pSessionId = IoGetRequestorProcess(Irp)->Session;
     return STATUS_SUCCESS;
 }