Skip to content

Commit

Permalink
lkl: dispatch: add LklQueueRequest and LklDeQueueRequest
Browse files Browse the repository at this point in the history
Signed-off-by: Lucian Adrian Grijincu <lucian.grijincu@gmail.com>
  • Loading branch information
luciang committed Dec 29, 2009
1 parent 4ec03e3 commit bc9eba3
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 6 deletions.
1 change: 1 addition & 0 deletions include/ntkvfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 0 additions & 6 deletions src/create.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
65 changes: 65 additions & 0 deletions src/dispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit bc9eba3

Please sign in to comment.