[NTOSKRNL]
[reactos.git] / reactos / ntoskrnl / io / iomgr / irp.c
index e73d502..0863f58 100644 (file)
@@ -712,12 +712,11 @@ IoBuildAsynchronousFsdRequest(IN ULONG MajorFunction,
                                /* Free the IRP and its MDL */
                                IoFreeMdl(Irp->MdlAddress);
                                IoFreeIrp(Irp);
-                               Irp = NULL;
+
+                /* Fail */
+                               _SEH2_YIELD(return NULL);
                        }
                        _SEH2_END;
-               
-            /* This is how we know if we failed during the probe */
-            if (!Irp) return NULL;
         }
         else
         {
@@ -908,12 +907,11 @@ IoBuildDeviceIoControlRequest(IN ULONG IoControlCode,
                     /* Free the input buffer and IRP */
                     if (InputBuffer) ExFreePool(Irp->AssociatedIrp.SystemBuffer);
                     IoFreeIrp(Irp);
-                    Irp = NULL;
+
+                    /* Fail */
+                    _SEH2_YIELD(return NULL);
                 }
                 _SEH2_END;
-
-                /* This is how we know if probing failed */
-                if (!Irp) return NULL;
             }
             break;
 
@@ -1136,6 +1134,9 @@ IofCallDriver(IN PDEVICE_OBJECT DeviceObject,
     PDRIVER_OBJECT DriverObject;
     PIO_STACK_LOCATION StackPtr;
 
+    /* Make sure this is a valid IRP */
+    ASSERT(Irp->Type == IO_TYPE_IRP);
+
     /* Get the Driver Object */
     DriverObject = DeviceObject->DriverObject;
 
@@ -1213,16 +1214,18 @@ IofCompleteRequest(IN PIRP Irp,
     if (LastStackPtr->Control & SL_ERROR_RETURNED)
     {
         /* Get the error code */
-        ErrorCode = (NTSTATUS)LastStackPtr->Parameters.Others.Argument4;
+        ErrorCode = PtrToUlong(LastStackPtr->Parameters.Others.Argument4);
     }
 
-    /* Get the Current Stack and skip it */
+    /* Get the Current Stack */
     StackPtr = IoGetCurrentIrpStackLocation(Irp);
-    IoSkipCurrentIrpStackLocation(Irp);
 
     /* Loop the Stacks and complete the IRPs */
     do
     {
+        /* Skip current stack location */
+        IoSkipCurrentIrpStackLocation(Irp);
+
         /* Set Pending Returned */
         Irp->PendingReturned = StackPtr->Control & SL_PENDING_RETURNED;
 
@@ -1235,7 +1238,7 @@ IofCompleteRequest(IN PIRP Irp,
                 /* Update the error for the current stack */
                 ErrorCode = Irp->IoStatus.Status;
                 StackPtr->Control |= SL_ERROR_RETURNED;
-                LastStackPtr->Parameters.Others.Argument4 = (PVOID)ErrorCode;
+                LastStackPtr->Parameters.Others.Argument4 = UlongToPtr(ErrorCode);
                 LastStackPtr->Control |= SL_ERROR_RETURNED;
             }
         }
@@ -1285,10 +1288,9 @@ IofCompleteRequest(IN PIRP Irp,
             IopClearStackLocation(StackPtr);
         }
 
-        /* Move to next stack location and pointer */
-        IoSkipCurrentIrpStackLocation(Irp);
+        /* Move pointer to next stack location */
         StackPtr++;
-    } while (Irp->CurrentLocation <= (Irp->StackCount + 1));
+    } while (Irp->CurrentLocation <= Irp->StackCount);
 
     /* Check if the IRP is an associated IRP */
     if (Irp->Flags & IRP_ASSOCIATED_IRP)
@@ -1609,7 +1611,7 @@ NTAPI
 IoGetRequestorProcessId(IN PIRP Irp)
 {
     /* Return the requestor process' id */
-    return (ULONG)(IoGetRequestorProcess(Irp)->UniqueProcessId);
+    return PtrToUlong(IoGetRequestorProcess(Irp)->UniqueProcessId);
 }
 
 /*
@@ -1781,5 +1783,5 @@ NTAPI
 IoSetTopLevelIrp(IN PIRP Irp)
 {
     /* Set the IRP */
-    PsGetCurrentThread()->TopLevelIrp = (ULONG)Irp;
+    PsGetCurrentThread()->TopLevelIrp = (ULONG_PTR)Irp;
 }