method_neither ioctl

I have an ioctl which is method_neither. The way i have to process it is that I mark the irp as pending and let a passive thread do the work. Now what I do is

  1. use buffer from irp->parameters.deviceiocontrol.type3inputbuffer

  2. use IoAllocateMdl and allocate mdl for it. ioallocatemdl(type3inputbuffer,len,false,false,pirp);

  3. MmProbeAndLockPages locks the irp’s mdladdress.

  4. userBuffer = MmGetSystemAddressForMdlSafe(pIrp->MdlAddress, NormalPagePriority);

  5. pIrp->Tail.Overlay.DriverContext[0] = userBuffer;

  6. finally use the buffer pointer in the passive thread

Now my question is when do I use the
MmUnlockPages and what am i needed to do in iocompletion routine. IO manager will expect the output in ? Irp->UserBuffer .

Kindly advice!

xxxxx@yahoo.com wrote:

I have an ioctl which is method_neither. The way i have to process it is that I mark the irp as pending and let a passive thread do the work. Now what I do is

  1. use buffer from irp->parameters.deviceiocontrol.type3inputbuffer

  2. use IoAllocateMdl and allocate mdl for it. ioallocatemdl(type3inputbuffer,len,false,false,pirp);

  3. MmProbeAndLockPages locks the irp’s mdladdress.

  4. userBuffer = MmGetSystemAddressForMdlSafe(pIrp->MdlAddress, NormalPagePriority);

  5. pIrp->Tail.Overlay.DriverContext[0] = userBuffer;

  6. finally use the buffer pointer in the passive thread

Now my question is when do I use the
MmUnlockPages and what am i needed to do in iocompletion routine. IO manager will expect the output in ? Irp->UserBuffer .

The IO manager doesn’t expect anything. If your user’s request
specified an input buffer, it will be in Type3InputBuffer. If your
user’s request specified an output buffer, it will be in
Irp->UserBuffer. If you need BOTH buffers, then you have to probe and
lock BOTH addresses. Note that the terms “input” and “output” are
really meaningless here. You can do I/O in either direction to either
buffer.

You should unlock the pages when you are through with them.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

It was not clear from you description, but you need to probe and lock in the dispatch routine in the context of the app, not in your deferred thread.

Why are you using method neithere in the first place?

d

dent from a phpne with no keynoard

-----Original Message-----
From: Tim Roberts
Sent: September 09, 2010 2:54 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] method_neither ioctl

xxxxx@yahoo.com wrote:
> I have an ioctl which is method_neither. The way i have to process it is that I mark the irp as pending and let a passive thread do the work. Now what I do is
>
> 1) use buffer from irp->parameters.deviceiocontrol.type3inputbuffer
> 2) use IoAllocateMdl and allocate mdl for it. ioallocatemdl(type3inputbuffer,len,false,false,pirp);
> 3) MmProbeAndLockPages locks the irp’s mdladdress.
>
> 4) userBuffer = MmGetSystemAddressForMdlSafe(pIrp->MdlAddress, NormalPagePriority);
> 5) pIrp->Tail.Overlay.DriverContext[0] = userBuffer;
> 5) finally use the buffer pointer in the passive thread
>
> Now my question is when do I use the
> MmUnlockPages and what am i needed to do in iocompletion routine. IO manager will expect the output in ? Irp->UserBuffer .

The IO manager doesn’t expect anything. If your user’s request
specified an input buffer, it will be in Type3InputBuffer. If your
user’s request specified an output buffer, it will be in
Irp->UserBuffer. If you need BOTH buffers, then you have to probe and
lock BOTH addresses. Note that the terms “input” and “output” are
really meaningless here. You can do I/O in either direction to either
buffer.

You should unlock the pages when you are through with them.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

>I have an ioctl which is method_neither. The way i have to process it is that I mark the irp as pending

and let a passive thread do the work.

Now my question is when do I use the MmUnlockPages and what am i needed to do
in iocompletion routine.

Actually, I don’t really understand what you are asking about. IoCompletion routine gets registered by a driver of device X that sends IRP to device Y (they may be either in the same stack or in a different one -it does not really matter in context of this question), and it gets done before passing IRP to device Y’s driver. When driver Y completes IRP by calling IoCompleteRequest() IoCompletion routine gets invoked. Therefore, a driver that registers a completion routine with IRP is not the same one that actually completes it (unless it returns STATUS_MORE_PROCESSING_REQUIRED from a completion routine, of course - in such case it has to call IoCompleteRequest() with a given IRP once again at some point).

Are you acting as a driver X or as a driver Y ??? The first part of your question suggests the former, but the second one suggests the latter…

Anton Bassov

Hi guys…
I do the locking and mdl thingy in the dispatch thread… very much the context of the user thread… I am a layer in a device stack and until recently we were using buffered method. but some changing conditions forced us to use the neither and now I am implementing the fix…
So before I complete the request in the deferred thread do i undo the locking and free the mdl etc?

What forced you go to use method neither?

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@yahoo.com
Sent: Thursday, September 09, 2010 4:47 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] method_neither ioctl

Hi guys…
I do the locking and mdl thingy in the dispatch thread… very much the context of the user thread… I am a layer in a device stack and until recently we were using buffered method. but some changing conditions forced us to use the neither and now I am implementing the fix…
So before I complete the request in the deferred thread do i undo the locking and free the mdl etc?


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Hi Doron,
We used the ioctl for some purposes but for other cases we were just pass through… the lower drivers needed bigger buffers for the “pass throughs” and looks like method_neither was the option suggested by microsoft… We dont need it but now some specific scenarios that came to us, come method_neither to us…

the driver above has a completion routine attached… we don’t have a completion routine… now the upper layers will change the completion routines to handle the “neither” case.
I’m not sure how they will do it…
If they check the irp->userbuffer… will I have to copy the mdls to the userbuffer before calling completion routine…
I’m just a little confused about the completion contexts and am reading osr’s article about it which is very helpful…

xxxxx@yahoo.com wrote:

Hi Doron,
We used the ioctl for some purposes but for other cases we were just pass through… the lower drivers needed bigger buffers for the “pass throughs” and looks like method_neither was the option suggested by microsoft…

Microsoft never suggests METHOD_NEITHER. That’s the worst of the four
possible options.

If your requests are less than a few dozen Kbytes, just stick with
METHOD_BUFFERED. Otherwise, METHOD_IN_DIRECT or METHOD_OUT_DIRECT is
the way.

the driver above has a completion routine attached… we don’t have a completion routine… now the upper layers will change the completion routines to handle the “neither” case.
I’m not sure how they will do it…
If they check the irp->userbuffer… will I have to copy the mdls to the userbuffer before calling completion routine…

Do your requests need to have both an input buffer and an output
buffer? Only YOU know what your requests really do. If the app expects
the results in an output buffer that is different from the input buffer,
then you have to put the results in Irp->UserBuffer.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.