Hi

Lets say I'm in PASSIVE IRQL in a dispatch function.
I mark my irp as pending. Later, I create a workitem that receives the
irp as a context and do some work in it. In the end of the workitem's
function, I complete the IRP.
Back to the dispatch routine - after allocating and queuing the
workitem, I return STATUS_PENDING.

Now, because I'm in PASSIVE level, there can be a context switch from
my dispatch routine to my workitem's function, so it will run and
complete the irp, before I return STATUS_PENDING from the dispatch
routine. (it means that when I return STATUS_PENDING, the irp is
already completed!)

Is there a problem with the above scenario? And if so, how should I
handle it?

Re: IoCompleteRequest() from WorkItem by Maxim

Maxim
Wed Mar 08 14:20:46 CST 2006

> Now, because I'm in PASSIVE level, there can be a context switch from
> my dispatch routine to my workitem's function, so it will run and
> complete the irp, before I return STATUS_PENDING from the dispatch
> routine. (it means that when I return STATUS_PENDING, the irp is
> already completed!)
>
> Is there a problem with the above scenario?

No problems. Just call IoMarkIrpPending before creating a work item.

--
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
maxim@storagecraft.com
http://www.storagecraft.com


RE: IoCompleteRequest() from WorkItem by pavel_a

pavel_a
Wed Mar 08 17:58:26 CST 2006

"zedy1984@gmail.com" wrote:
> Hi
>
> Lets say I'm in PASSIVE IRQL in a dispatch function.
> I mark my irp as pending. Later, I create a workitem that receives the
> irp as a context and do some work in it. In the end of the workitem's
> function, I complete the IRP.
> Back to the dispatch routine - after allocating and queuing the
> workitem, I return STATUS_PENDING.
>
> Now, because I'm in PASSIVE level, there can be a context switch from
> my dispatch routine to my workitem's function, so it will run and
> complete the irp, before I return STATUS_PENDING from the dispatch
> routine. (it means that when I return STATUS_PENDING, the irp is
> already completed!)
>
> Is there a problem with the above scenario? And if so, how should I
> handle it?

Yes, this is a race condition.
You need to prevent the work item from completing the irp at least until you
mark it pending. Otherwise you can touch the irp after it is completed and
destroyed.

--PA