[NTOS:IO]
[reactos.git] / reactos / ntoskrnl / io / iomgr / irp.c
index 2e25a40..f768c76 100644 (file)
 #define NDEBUG
 #include <debug.h>
 
-/* Undefine some macros we implement here */
-#undef IoCallDriver
-#undef IoCompleteRequest
-
 PIRP IopDeadIrp;
 
 /* PRIVATE FUNCTIONS  ********************************************************/
@@ -269,8 +265,8 @@ IopCompleteRequest(IN PKAPC Apc,
             (Irp->IoStatus.Information == IO_REPARSE_TAG_MOUNT_POINT))
         {
             /* We should never get this yet */
-            DPRINT1("Reparse support not yet present!\n");
-            while (TRUE);
+            UNIMPLEMENTED_DBGBREAK("Reparse support not yet present!\n");
+            return;
         }
     }
 
@@ -595,18 +591,18 @@ IoAllocateIrp(IN CCHAR StackSize,
         /* Check if we should charge quota */
         if (ChargeQuota)
         {
-            /* Irp = ExAllocatePoolWithQuotaTag(NonPagedPool, Size, TAG_IRP); */
-            /* FIXME */
-            Irp = ExAllocatePoolWithTag(NonPagedPool, Size, TAG_IRP);
+            Irp = ExAllocatePoolWithQuotaTag(NonPagedPool | POOL_QUOTA_FAIL_INSTEAD_OF_RAISE,
+                                             Size,
+                                             TAG_IRP);
         }
         else
         {
-            /* Allocate the IRP With no Quota charge */
+            /* Allocate the IRP with no quota charge */
             Irp = ExAllocatePoolWithTag(NonPagedPool, Size, TAG_IRP);
         }
 
         /* Make sure it was sucessful */
-        if (!Irp) return(NULL);
+        if (!Irp) return NULL;
     }
     else
     {
@@ -629,6 +625,40 @@ IoAllocateIrp(IN CCHAR StackSize,
     return Irp;
 }
 
+/*
+ * @implemented
+ */
+PIRP
+NTAPI
+IopAllocateIrpMustSucceed(IN CCHAR StackSize)
+{
+    LONG i;
+    PIRP Irp;
+    LARGE_INTEGER Sleep;
+
+    /* Try to get an IRP */
+    Irp = IoAllocateIrp(StackSize, FALSE);
+    if (Irp)
+        return Irp;
+
+    /* If we fail, start looping till we may get one */
+    i = LONG_MAX;
+    do {
+        i--;
+
+        /* First, sleep for 10ms */
+        Sleep.QuadPart = -10 * 1000 * 10;;
+        KeDelayExecutionThread(KernelMode, FALSE, &Sleep);
+
+        /* Then, retry allocation */
+        Irp = IoAllocateIrp(StackSize, FALSE);
+        if (Irp)
+            return Irp;
+    } while (i > 0);
+
+    return Irp;
+}
+
 /*
  * @implemented
  */
@@ -1099,6 +1129,7 @@ IoCancelThreadIo(IN PETHREAD Thread)
 /*
  * @implemented
  */
+#undef IoCallDriver
 NTSTATUS
 NTAPI
 IoCallDriver(IN PDEVICE_OBJECT DeviceObject,
@@ -1108,9 +1139,12 @@ IoCallDriver(IN PDEVICE_OBJECT DeviceObject,
     return IofCallDriver(DeviceObject, Irp);
 }
 
+#define IoCallDriver IofCallDriver
+
 /*
  * @implemented
  */
+#undef IoCompleteRequest
 VOID
 NTAPI
 IoCompleteRequest(IN PIRP Irp,
@@ -1120,6 +1154,8 @@ IoCompleteRequest(IN PIRP Irp,
     IofCompleteRequest(Irp, PriorityBoost);
 }
 
+#define IoCompleteRequest IofCompleteRequest
+
 /*
  * @implemented
  */
@@ -1370,8 +1406,7 @@ IofCompleteRequest(IN PIRP Irp,
                              PriorityBoost);
 #else
             /* Not implemented yet. */
-            DPRINT1("Not supported!\n");
-            while (TRUE);
+            UNIMPLEMENTED_DBGBREAK("Not supported!\n");
 #endif
         }
 
@@ -1613,7 +1648,14 @@ IoGetRequestorProcess(IN PIRP Irp)
     /* Return the requestor process */
     if (Irp->Tail.Overlay.Thread)
     {
-        return Irp->Tail.Overlay.Thread->ThreadsProcess;
+        if (Irp->ApcEnvironment == OriginalApcEnvironment)
+        {
+            return Irp->Tail.Overlay.Thread->ThreadsProcess;
+        }
+        else if (Irp->ApcEnvironment == AttachedApcEnvironment)
+        {
+            return (PEPROCESS)Irp->Tail.Overlay.Thread->Tcb.ApcState.Process;
+        }
     }
 
     return NULL;
@@ -1629,10 +1671,8 @@ IoGetRequestorProcessId(IN PIRP Irp)
     PEPROCESS Process;
 
     /* Return the requestor process' id */
-    if ((Process = IoGetRequestorProcess(Irp)))
-    {
-        return PtrToUlong(Process->UniqueProcessId);
-    }
+    Process = IoGetRequestorProcess(Irp);
+    if (Process) return PtrToUlong(Process->UniqueProcessId);
 
     return 0;
 }
@@ -1648,9 +1688,10 @@ IoGetRequestorSessionId(IN PIRP Irp,
     PEPROCESS Process;
 
     /* Return the session */
-    if ((Process = IoGetRequestorProcess(Irp)))
+    if (Irp->Tail.Overlay.Thread)
     {
-        *pSessionId = Process->Session;
+        Process = Irp->Tail.Overlay.Thread->ThreadsProcess;
+        *pSessionId = MmGetSessionId(Process);
         return STATUS_SUCCESS;
     }
 
@@ -1832,7 +1873,7 @@ NTAPI
 IoIs32bitProcess(
     IN PIRP Irp OPTIONAL)
 {
-#pragma message "IoIs32bitProcess is hardcoded to FALSE"
+    UNIMPLEMENTED;
     return FALSE;
 }
 #endif