Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

lkl: dispatch: add LklQueueRequest and LklDeQueueRequest

Signed-off-by: Lucian Adrian Grijincu <lucian.grijincu@gmail.com>
  • Loading branch information...
commit bc9eba3feb41455533b2657853371cafbcaff462 1 parent 4ec03e3
@luciang luciang authored
Showing with 66 additions and 6 deletions.
  1. +1 −0  include/ntkvfs.h
  2. +0 −6 src/create.c
  3. +65 −0 src/dispatch.c
View
1  include/ntkvfs.h
@@ -303,6 +303,7 @@ NTSTATUS LklVcbFini(IN PLKL_VCB vcb);
/*
* Dispatch routines
*/
+NTSTATUS LklQueueRequest(IN PLKL_IRP_CONTEXT IrpContext);
NTSTATUS LklFileSystemControl(IN PLKL_IRP_CONTEXT IrpContext);
NTSTATUS LklCreate(IN PLKL_IRP_CONTEXT IrpContext);
View
6 src/create.c
@@ -10,12 +10,6 @@ NTSTATUS LklCreateFile(IN PLKL_IRP_CONTEXT IrpContext, PLKL_VCB Vcb)
return STATUS_OBJECT_NAME_NOT_FOUND;
}
-NTSTATUS LklQueueRequest(IN PLKL_IRP_CONTEXT IrpContext)
-{
- LklCompleteIrpContext(IrpContext, STATUS_OBJECT_NAME_NOT_FOUND);
- return STATUS_OBJECT_NAME_NOT_FOUND;
-}
-
NTSTATUS LklCreate(IN PLKL_IRP_CONTEXT IrpContext)
{
NTSTATUS status = STATUS_OBJECT_NAME_NOT_FOUND;
View
65 src/dispatch.c
@@ -159,4 +159,69 @@ DDKAPI NTSTATUS LklVfsBuildRequest(IN PDEVICE_OBJECT device, IN PIRP Irp)
}
+/*
+ * Lock the Irp, all associated buffers (e.g. read/write user buffers)
+ * and mark the Irp as pending.
+ */
+VOID LklLockIrp(IN PLKL_IRP_CONTEXT IrpContext, IN PIRP Irp)
+{
+ if (!Irp)
+ return;
+ IoMarkIrpPending(Irp);
+}
+
+/*
+ * This runs as a work queue.
+ * It takes an IRP context and re-dispatches it.
+ *
+ * NOTE: This function will be called by the kernel: DDKAPI is
+ * mandatory for correct argument passing.
+ */
+DDKAPI VOID LklDeQueueRequest(IN PVOID Context)
+{
+ PLKL_IRP_CONTEXT IrpContext = (PLKL_IRP_CONTEXT) Context;
+
+ ASSERT(IrpContext);
+ ASSERT((IrpContext->Identifier.Type == ICX) &&
+ (IrpContext->Identifier.Size == sizeof(LKL_IRP_CONTEXT)));
+
+ FsRtlEnterFileSystem();
+
+ if (!IrpContext->IsTopLevel)
+ IoSetTopLevelIrp((PIRP) FSRTL_FSP_TOP_LEVEL_IRP);
+
+ LklDispatchRequest(IrpContext);
+
+ IoSetTopLevelIrp(NULL);
+
+ FsRtlExitFileSystem();
+}
+
+
+/*
+ * Lock the IRP and all asociated buffers, mark the IRP as pending and
+ * queue it for later processing.
+ */
+NTSTATUS LklQueueRequest(IN PLKL_IRP_CONTEXT IrpContext)
+{
+ ASSERT(IrpContext);
+
+ ASSERT((IrpContext->Identifier.Type == ICX) &&
+ (IrpContext->Identifier.Size == sizeof(LKL_IRP_CONTEXT)));
+
+ /* set the flags of "can wait" and "queued" */
+ SET_FLAG(IrpContext->Flags, IRP_CONTEXT_FLAG_WAIT);
+ SET_FLAG(IrpContext->Flags, IRP_CONTEXT_FLAG_REQUEUED);
+
+ /* make sure the buffer is kept valid in system context */
+ LklLockIrp(IrpContext, IrpContext->Irp);
+
+ /* initialize work item */
+ ExInitializeWorkItem(&IrpContext->WorkQueueItem,
+ LklDeQueueRequest, IrpContext);
+
+ /* dispatch the work item */
+ ExQueueWorkItem(&IrpContext->WorkQueueItem, CriticalWorkQueue);
+ return STATUS_PENDING;
+}
Please sign in to comment.
Something went wrong with that request. Please try again.