User mode code uses an overlapped call of DeviceIoControl to send an IOCTL
to my driver. This operation normally takes quite a long time to process. I
notice that DeviceIoControl is not returning immediately.
Do I need to mark the Irp as STATUS_PENDING in order for DeviceIoControl to
return?

Also, if I re-use the original Irp, and data is being passed back to the
User code, do I have to lock the buffer somehow?

Thanks in advance,
Dennis

Re: DeviceIoControl Usage by Don

Don
Wed Sep 22 08:17:42 CDT 2004

Comments inline:

"Dennis Burns" <dburns@rtessentials.com> wrote in message
news:%233Rv2OKoEHA.3252@TK2MSFTNGP14.phx.gbl...
> User mode code uses an overlapped call of DeviceIoControl to send an IOCTL
> to my driver. This operation normally takes quite a long time to process.
I
> notice that DeviceIoControl is not returning immediately.
> Do I need to mark the Irp as STATUS_PENDING in order for DeviceIoControl
to
> return?

Yes you need to mark the IRP as pending and return STATUS_PENDING.

> Also, if I re-use the original Irp, and data is being passed back to the
> User code, do I have to lock the buffer somehow?

What do you mean by reuse in this case? On the buffer what type of
buffering are you doing METHOD_BUFFERED is already in nonpaged memory.
METHOD_XX_DIRECT calls have a MDL, depending on your model you probably want
to lock the pages into menory. METHOD_NEITHER (which if at all possible
don't use, since it is too easy to have bugs), requires you process the
addresses yourself in the context of the calling process, which normally
means you better do all the locking and mapping in the DeviceIoControl
routine.


--
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Remove StopSpam from the email to reply



Re: DeviceIoControl Usage by Walter

Walter
Wed Sep 22 08:28:55 CDT 2004

Dennis Burns wrote:
> User mode code uses an overlapped call of DeviceIoControl to send an IOCTL
> to my driver. This operation normally takes quite a long time to process. I
> notice that DeviceIoControl is not returning immediately.
> Do I need to mark the Irp as STATUS_PENDING in order for DeviceIoControl to
> return?

Yes, but be sure to think exactly about this. You will call
IoMarkIrpPending and return STATUS_PENDING from your dispatch routine.
It's a mistake to set Irp->IoStatus.Status to STATUS_PENDING, which only
has meaning as a return code from a dispatch routine.

You should install a cancel routine for the IRP. You will have a
difficult race condition between the cancel and completion paths, for
which I suggest using the "pending IOCTL" support described in my book
(and built into GENERIC.SYS).

> Also, if I re-use the original Irp, and data is being passed back to the
> User code, do I have to lock the buffer somehow?

Not in a WDM driver. Buffer locking was required in 9x VxD drivers for
asynchronous IOCTLs, but not for WDM drivers in any environment.

--
Walter Oney, Consulting and Training
Basic and Advanced Driver Programming Seminars
Check out our schedule at http://www.oneysoft.com

Re: DeviceIoControl Usage by Dennis

Dennis
Wed Sep 22 08:53:19 CDT 2004

Hello Don,
Thanks (again) for your help. I really appreciate it.
I'm using METHOD_BUFFERED.
While on that note, why shouldn't we always be using METHOD_DIRECT, as long
as the user code does not need the original buffer until the Irp is
finished? My instincts tell me that this is the fastest and most efficient
in that it avoids creation of a new buffer, and (redundant) copying.
Best Regards,
Dennis


"Don Burn" <burn@stopspam.acm.org> wrote in message
news:10l2use4bjhhs8e@corp.supernews.com...
> Comments inline:
>
> "Dennis Burns" <dburns@rtessentials.com> wrote in message
> news:%233Rv2OKoEHA.3252@TK2MSFTNGP14.phx.gbl...
> > User mode code uses an overlapped call of DeviceIoControl to send an
IOCTL
> > to my driver. This operation normally takes quite a long time to
process.
> I
> > notice that DeviceIoControl is not returning immediately.
> > Do I need to mark the Irp as STATUS_PENDING in order for DeviceIoControl
> to
> > return?
>
> Yes you need to mark the IRP as pending and return STATUS_PENDING.
>
> > Also, if I re-use the original Irp, and data is being passed back to the
> > User code, do I have to lock the buffer somehow?
>
> What do you mean by reuse in this case? On the buffer what type of
> buffering are you doing METHOD_BUFFERED is already in nonpaged memory.
> METHOD_XX_DIRECT calls have a MDL, depending on your model you probably
want
> to lock the pages into menory. METHOD_NEITHER (which if at all possible
> don't use, since it is too easy to have bugs), requires you process the
> addresses yourself in the context of the calling process, which normally
> means you better do all the locking and mapping in the DeviceIoControl
> routine.
>
>
> --
> Don Burn (MVP, Windows DDK)
> Windows 2k/XP/2k3 Filesystem and Driver Consulting
> Remove StopSpam from the email to reply
>
>



Re: DeviceIoControl Usage by Don

Don
Wed Sep 22 09:00:15 CDT 2004

If the buffer is small METHOD_BUFFERED is best. As the buffer get bigger
the copy that occurs with this method overrides its advantages.
METHOD_XX_DIRECT has the overhead of setting up the mapping of a MDL, if the
buffer is small this overhead is greater than the copy of METHOD_BUFFERED.
METHOD_NEITHER has no setup and no copy, the problem here is that it is easy
to messup things by not doing all the required steps.


--
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Remove StopSpam from the email to reply

"Dennis Burns" <dburns@rtessentials.com> wrote in message
news:uqc$$tKoEHA.3968@TK2MSFTNGP11.phx.gbl...
> Hello Don,
> Thanks (again) for your help. I really appreciate it.
> I'm using METHOD_BUFFERED.
> While on that note, why shouldn't we always be using METHOD_DIRECT, as
long
> as the user code does not need the original buffer until the Irp is
> finished? My instincts tell me that this is the fastest and most efficient
> in that it avoids creation of a new buffer, and (redundant) copying.
> Best Regards,
> Dennis
>
>
> "Don Burn" <burn@stopspam.acm.org> wrote in message
> news:10l2use4bjhhs8e@corp.supernews.com...
> > Comments inline:
> >
> > "Dennis Burns" <dburns@rtessentials.com> wrote in message
> > news:%233Rv2OKoEHA.3252@TK2MSFTNGP14.phx.gbl...
> > > User mode code uses an overlapped call of DeviceIoControl to send an
> IOCTL
> > > to my driver. This operation normally takes quite a long time to
> process.
> > I
> > > notice that DeviceIoControl is not returning immediately.
> > > Do I need to mark the Irp as STATUS_PENDING in order for
DeviceIoControl
> > to
> > > return?
> >
> > Yes you need to mark the IRP as pending and return STATUS_PENDING.
> >
> > > Also, if I re-use the original Irp, and data is being passed back to
the
> > > User code, do I have to lock the buffer somehow?
> >
> > What do you mean by reuse in this case? On the buffer what type of
> > buffering are you doing METHOD_BUFFERED is already in nonpaged memory.
> > METHOD_XX_DIRECT calls have a MDL, depending on your model you probably
> want
> > to lock the pages into menory. METHOD_NEITHER (which if at all possible
> > don't use, since it is too easy to have bugs), requires you process the
> > addresses yourself in the context of the calling process, which normally
> > means you better do all the locking and mapping in the DeviceIoControl
> > routine.
> >
> >
> > --
> > Don Burn (MVP, Windows DDK)
> > Windows 2k/XP/2k3 Filesystem and Driver Consulting
> > Remove StopSpam from the email to reply
> >
> >
>
>



Re: DeviceIoControl Usage by Dennis

Dennis
Wed Sep 22 09:11:13 CDT 2004

Hello Walter,
Thanks a lot for your advice.
I've studied your book quite a bit, and my implementation uses your
generic.sys (I built my own version with a different name).
Should I use your GenericCacheControlRequest function for this?
I need to re-study this section carefully.
Best Regards,
Dennis

"Walter Oney" <waltoney@oneysoft.com> wrote in message
news:41517E17.9C0B6A64@oneysoft.com...
> Dennis Burns wrote:
> > User mode code uses an overlapped call of DeviceIoControl to send an
IOCTL
> > to my driver. This operation normally takes quite a long time to
process. I
> > notice that DeviceIoControl is not returning immediately.
> > Do I need to mark the Irp as STATUS_PENDING in order for DeviceIoControl
to
> > return?
>
> Yes, but be sure to think exactly about this. You will call
> IoMarkIrpPending and return STATUS_PENDING from your dispatch routine.
> It's a mistake to set Irp->IoStatus.Status to STATUS_PENDING, which only
> has meaning as a return code from a dispatch routine.
>
> You should install a cancel routine for the IRP. You will have a
> difficult race condition between the cancel and completion paths, for
> which I suggest using the "pending IOCTL" support described in my book
> (and built into GENERIC.SYS).
>
> > Also, if I re-use the original Irp, and data is being passed back to the
> > User code, do I have to lock the buffer somehow?
>
> Not in a WDM driver. Buffer locking was required in 9x VxD drivers for
> asynchronous IOCTLs, but not for WDM drivers in any environment.
>
> --
> Walter Oney, Consulting and Training
> Basic and Advanced Driver Programming Seminars
> Check out our schedule at http://www.oneysoft.com



Re: DeviceIoControl Usage by Dennis

Dennis
Wed Sep 22 09:30:31 CDT 2004

What if the buffer size is a constant, 1024 bytes? Would you consider this
large?


"Don Burn" <burn@stopspam.acm.org> wrote in message
news:10l31c7jtn3ane3@corp.supernews.com...
> If the buffer is small METHOD_BUFFERED is best. As the buffer get bigger
> the copy that occurs with this method overrides its advantages.
> METHOD_XX_DIRECT has the overhead of setting up the mapping of a MDL, if
the
> buffer is small this overhead is greater than the copy of METHOD_BUFFERED.
> METHOD_NEITHER has no setup and no copy, the problem here is that it is
easy
> to messup things by not doing all the required steps.
>
>
> --
> Don Burn (MVP, Windows DDK)
> Windows 2k/XP/2k3 Filesystem and Driver Consulting
> Remove StopSpam from the email to reply
>
> "Dennis Burns" <dburns@rtessentials.com> wrote in message
> news:uqc$$tKoEHA.3968@TK2MSFTNGP11.phx.gbl...
> > Hello Don,
> > Thanks (again) for your help. I really appreciate it.
> > I'm using METHOD_BUFFERED.
> > While on that note, why shouldn't we always be using METHOD_DIRECT, as
> long
> > as the user code does not need the original buffer until the Irp is
> > finished? My instincts tell me that this is the fastest and most
efficient
> > in that it avoids creation of a new buffer, and (redundant) copying.
> > Best Regards,
> > Dennis
> >
> >
> > "Don Burn" <burn@stopspam.acm.org> wrote in message
> > news:10l2use4bjhhs8e@corp.supernews.com...
> > > Comments inline:
> > >
> > > "Dennis Burns" <dburns@rtessentials.com> wrote in message
> > > news:%233Rv2OKoEHA.3252@TK2MSFTNGP14.phx.gbl...
> > > > User mode code uses an overlapped call of DeviceIoControl to send an
> > IOCTL
> > > > to my driver. This operation normally takes quite a long time to
> > process.
> > > I
> > > > notice that DeviceIoControl is not returning immediately.
> > > > Do I need to mark the Irp as STATUS_PENDING in order for
> DeviceIoControl
> > > to
> > > > return?
> > >
> > > Yes you need to mark the IRP as pending and return STATUS_PENDING.
> > >
> > > > Also, if I re-use the original Irp, and data is being passed back to
> the
> > > > User code, do I have to lock the buffer somehow?
> > >
> > > What do you mean by reuse in this case? On the buffer what type of
> > > buffering are you doing METHOD_BUFFERED is already in nonpaged memory.
> > > METHOD_XX_DIRECT calls have a MDL, depending on your model you
probably
> > want
> > > to lock the pages into menory. METHOD_NEITHER (which if at all
possible
> > > don't use, since it is too easy to have bugs), requires you process
the
> > > addresses yourself in the context of the calling process, which
normally
> > > means you better do all the locking and mapping in the DeviceIoControl
> > > routine.
> > >
> > >
> > > --
> > > Don Burn (MVP, Windows DDK)
> > > Windows 2k/XP/2k3 Filesystem and Driver Consulting
> > > Remove StopSpam from the email to reply
> > >
> > >
> >
> >
>
>



Re: DeviceIoControl Usage by Don

Don
Wed Sep 22 09:48:47 CDT 2004

I take the approach of large > 4096, but that is my opinion. Your mileage
may vary.


--
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Remove StopSpam from the email to reply

"Dennis Burns" <dburns@rtessentials.com> wrote in message
news:%23jEXyCLoEHA.3788@TK2MSFTNGP10.phx.gbl...
> What if the buffer size is a constant, 1024 bytes? Would you consider this
> large?
>
>
> "Don Burn" <burn@stopspam.acm.org> wrote in message
> news:10l31c7jtn3ane3@corp.supernews.com...
> > If the buffer is small METHOD_BUFFERED is best. As the buffer get
bigger
> > the copy that occurs with this method overrides its advantages.
> > METHOD_XX_DIRECT has the overhead of setting up the mapping of a MDL, if
> the
> > buffer is small this overhead is greater than the copy of
METHOD_BUFFERED.
> > METHOD_NEITHER has no setup and no copy, the problem here is that it is
> easy
> > to messup things by not doing all the required steps.
> >
> >
> > --
> > Don Burn (MVP, Windows DDK)
> > Windows 2k/XP/2k3 Filesystem and Driver Consulting
> > Remove StopSpam from the email to reply
> >
> > "Dennis Burns" <dburns@rtessentials.com> wrote in message
> > news:uqc$$tKoEHA.3968@TK2MSFTNGP11.phx.gbl...
> > > Hello Don,
> > > Thanks (again) for your help. I really appreciate it.
> > > I'm using METHOD_BUFFERED.
> > > While on that note, why shouldn't we always be using METHOD_DIRECT, as
> > long
> > > as the user code does not need the original buffer until the Irp is
> > > finished? My instincts tell me that this is the fastest and most
> efficient
> > > in that it avoids creation of a new buffer, and (redundant) copying.
> > > Best Regards,
> > > Dennis
> > >
> > >
> > > "Don Burn" <burn@stopspam.acm.org> wrote in message
> > > news:10l2use4bjhhs8e@corp.supernews.com...
> > > > Comments inline:
> > > >
> > > > "Dennis Burns" <dburns@rtessentials.com> wrote in message
> > > > news:%233Rv2OKoEHA.3252@TK2MSFTNGP14.phx.gbl...
> > > > > User mode code uses an overlapped call of DeviceIoControl to send
an
> > > IOCTL
> > > > > to my driver. This operation normally takes quite a long time to
> > > process.
> > > > I
> > > > > notice that DeviceIoControl is not returning immediately.
> > > > > Do I need to mark the Irp as STATUS_PENDING in order for
> > DeviceIoControl
> > > > to
> > > > > return?
> > > >
> > > > Yes you need to mark the IRP as pending and return STATUS_PENDING.
> > > >
> > > > > Also, if I re-use the original Irp, and data is being passed back
to
> > the
> > > > > User code, do I have to lock the buffer somehow?
> > > >
> > > > What do you mean by reuse in this case? On the buffer what type of
> > > > buffering are you doing METHOD_BUFFERED is already in nonpaged
memory.
> > > > METHOD_XX_DIRECT calls have a MDL, depending on your model you
> probably
> > > want
> > > > to lock the pages into menory. METHOD_NEITHER (which if at all
> possible
> > > > don't use, since it is too easy to have bugs), requires you process
> the
> > > > addresses yourself in the context of the calling process, which
> normally
> > > > means you better do all the locking and mapping in the
DeviceIoControl
> > > > routine.
> > > >
> > > >
> > > > --
> > > > Don Burn (MVP, Windows DDK)
> > > > Windows 2k/XP/2k3 Filesystem and Driver Consulting
> > > > Remove StopSpam from the email to reply
> > > >
> > > >
> > >
> > >
> >
> >
>
>



Re: DeviceIoControl Usage by Dennis

Dennis
Wed Sep 22 09:57:51 CDT 2004

Thank again for the help.
Where do I send the holiday fruit basket?
Dennis

"Don Burn" <burn@stopspam.acm.org> wrote in message
news:10l3477o2hgb73f@corp.supernews.com...
> I take the approach of large > 4096, but that is my opinion. Your mileage
> may vary.
>
>
> --
> Don Burn (MVP, Windows DDK)
> Windows 2k/XP/2k3 Filesystem and Driver Consulting
> Remove StopSpam from the email to reply
>
> "Dennis Burns" <dburns@rtessentials.com> wrote in message
> news:%23jEXyCLoEHA.3788@TK2MSFTNGP10.phx.gbl...
> > What if the buffer size is a constant, 1024 bytes? Would you consider
this
> > large?
> >
> >
> > "Don Burn" <burn@stopspam.acm.org> wrote in message
> > news:10l31c7jtn3ane3@corp.supernews.com...
> > > If the buffer is small METHOD_BUFFERED is best. As the buffer get
> bigger
> > > the copy that occurs with this method overrides its advantages.
> > > METHOD_XX_DIRECT has the overhead of setting up the mapping of a MDL,
if
> > the
> > > buffer is small this overhead is greater than the copy of
> METHOD_BUFFERED.
> > > METHOD_NEITHER has no setup and no copy, the problem here is that it
is
> > easy
> > > to messup things by not doing all the required steps.
> > >
> > >
> > > --
> > > Don Burn (MVP, Windows DDK)
> > > Windows 2k/XP/2k3 Filesystem and Driver Consulting
> > > Remove StopSpam from the email to reply
> > >
> > > "Dennis Burns" <dburns@rtessentials.com> wrote in message
> > > news:uqc$$tKoEHA.3968@TK2MSFTNGP11.phx.gbl...
> > > > Hello Don,
> > > > Thanks (again) for your help. I really appreciate it.
> > > > I'm using METHOD_BUFFERED.
> > > > While on that note, why shouldn't we always be using METHOD_DIRECT,
as
> > > long
> > > > as the user code does not need the original buffer until the Irp is
> > > > finished? My instincts tell me that this is the fastest and most
> > efficient
> > > > in that it avoids creation of a new buffer, and (redundant) copying.
> > > > Best Regards,
> > > > Dennis
> > > >
> > > >
> > > > "Don Burn" <burn@stopspam.acm.org> wrote in message
> > > > news:10l2use4bjhhs8e@corp.supernews.com...
> > > > > Comments inline:
> > > > >
> > > > > "Dennis Burns" <dburns@rtessentials.com> wrote in message
> > > > > news:%233Rv2OKoEHA.3252@TK2MSFTNGP14.phx.gbl...
> > > > > > User mode code uses an overlapped call of DeviceIoControl to
send
> an
> > > > IOCTL
> > > > > > to my driver. This operation normally takes quite a long time to
> > > > process.
> > > > > I
> > > > > > notice that DeviceIoControl is not returning immediately.
> > > > > > Do I need to mark the Irp as STATUS_PENDING in order for
> > > DeviceIoControl
> > > > > to
> > > > > > return?
> > > > >
> > > > > Yes you need to mark the IRP as pending and return STATUS_PENDING.
> > > > >
> > > > > > Also, if I re-use the original Irp, and data is being passed
back
> to
> > > the
> > > > > > User code, do I have to lock the buffer somehow?
> > > > >
> > > > > What do you mean by reuse in this case? On the buffer what type
of
> > > > > buffering are you doing METHOD_BUFFERED is already in nonpaged
> memory.
> > > > > METHOD_XX_DIRECT calls have a MDL, depending on your model you
> > probably
> > > > want
> > > > > to lock the pages into menory. METHOD_NEITHER (which if at all
> > possible
> > > > > don't use, since it is too easy to have bugs), requires you
process
> > the
> > > > > addresses yourself in the context of the calling process, which
> > normally
> > > > > means you better do all the locking and mapping in the
> DeviceIoControl
> > > > > routine.
> > > > >
> > > > >
> > > > > --
> > > > > Don Burn (MVP, Windows DDK)
> > > > > Windows 2k/XP/2k3 Filesystem and Driver Consulting
> > > > > Remove StopSpam from the email to reply
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>



Re: DeviceIoControl Usage by Don

Don
Wed Sep 22 11:33:34 CDT 2004

No problem for the help, for fruit basket instead send referrals.
Seriously, many of the people who respond to the questions on the various
newsgroups are consultants, if you feel we have helped and you encounter
someone who needs a consultant recommend the folks who helped you.


--
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Remove StopSpam from the email to reply

"Dennis Burns" <dburns@rtessentials.com> wrote in message
news:uZQ9DSLoEHA.2304@TK2MSFTNGP14.phx.gbl...
> Thank again for the help.
> Where do I send the holiday fruit basket?
> Dennis
>



Re: DeviceIoControl Usage by Maxim

Maxim
Wed Sep 22 23:42:27 CDT 2004

> notice that DeviceIoControl is not returning immediately.
> Do I need to mark the Irp as STATUS_PENDING in order for DeviceIoControl to
> return?

Exactly.

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