Question about IRP in TDI_EVENT_RECEIVE - Theres a hole in the bucket dear Liza!

I am a little confused. Seems like I have read conflicting information about TDI_EVENT_RECEIVE processing which leaves me not knowing which way to turn. So which of the following is inaccurate:

  1. if the BytesIndicated is less than BytesAvailable in the TDI_EVENT_RECEIVE method then a TDI_RECEIVE IRP should best be returned in the last parmeter to then receive the remaining data not taken.
  2. TdiBuildInternalDeviceControlIrp followed by TdiBuildReceive will build such an IRP
  3. But TdiBuildDeviceControlIrp actually calls IoBuildDeviceIoControlRequest
  4. IoBuildDeviceIoControlRequest must be running at passive level and cannot be reused (IoReuseIrp).
  5. Therefore the TDI_RECEIVE IRPs must be prebuilt in anticipation of being needed in the TDI_EVENT_RECEIVE.
    6! So they must be prebuilt, but they can’t be reused. So what gives when I quickly run out of prebuilt IRPs needed in TDI_EVENT_RECEIVE which runs at dispatch IRQL so I can’t rebuild anymore and cannot reused the existing ones.
    There’s a hole in the bucket Dear Liza.

> -----Original Message-----

From: xxxxx@lists.osr.com [mailto:bounce-293283-
xxxxx@lists.osr.com] On Behalf Of xxxxx@swbell.net
Sent: Wednesday, July 11, 2007 12:01 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Question about IRP in TDI_EVENT_RECEIVE - Theres a
hole in the bucket dear Liza!

I am a little confused. Seems like I have read conflicting information
about TDI_EVENT_RECEIVE processing which leaves me not knowing which
way to turn. So which of the following is inaccurate:

  1. if the BytesIndicated is less than BytesAvailable in the
    TDI_EVENT_RECEIVE method then a TDI_RECEIVE IRP should best be returned
    in the last parmeter to then receive the remaining data not taken.
  2. TdiBuildInternalDeviceControlIrp followed by TdiBuildReceive will
    build such an IRP
  3. But TdiBuildDeviceControlIrp actually calls
    IoBuildDeviceIoControlRequest
  4. IoBuildDeviceIoControlRequest must be running at passive level and
    cannot be reused (IoReuseIrp).
  5. Therefore the TDI_RECEIVE IRPs must be prebuilt in anticipation of
    being needed in the TDI_EVENT_RECEIVE.
    6! So they must be prebuilt, but they can’t be reused. So what gives
    when I quickly run out of prebuilt IRPs needed in TDI_EVENT_RECEIVE
    which runs at dispatch IRQL so I can’t rebuild anymore and cannot
    reused the existing ones.
    There’s a hole in the bucket Dear Liza.
    [PCAUSA] Don’t use TdiBuildInternalDeviceControlIrp. Instead, study the use of IoAllocateIrp and use of other TdiBuild MACROS that can initialize the IRP.

You will see that the limitations on IoAllocateIrp are less restrictive concerning IRQL.

Good luck,

Thomas F. Divine
http://www.pcausa.com


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

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

To underscore what Thomas has indicated:

TdiBuildInternalDeviceControlIrp() uses IoBuildDeviceIoControlRequest()
which creates a ‘threaded IRP’ (an IRP associated with the thread that
allocated it). This is almost never what you want for TDI requests
generated by another driver, often in an arbitrary thread context.

Use IoAllocateIrp() and ‘roll-your-own’ TDI IRPs, even when you will
pre-allocate them (and especially) if you plan to re-use them.

Good Luck,
Dave Cattley

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Thomas F. Divine
Sent: Wednesday, July 11, 2007 1:24 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Question about IRP in TDI_EVENT_RECEIVE - Theres a hole
in the bucket dear Liza!

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:bounce-293283-
xxxxx@lists.osr.com] On Behalf Of xxxxx@swbell.net
Sent: Wednesday, July 11, 2007 12:01 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Question about IRP in TDI_EVENT_RECEIVE - Theres a
hole in the bucket dear Liza!

I am a little confused. Seems like I have read conflicting information
about TDI_EVENT_RECEIVE processing which leaves me not knowing which
way to turn. So which of the following is inaccurate:

  1. if the BytesIndicated is less than BytesAvailable in the
    TDI_EVENT_RECEIVE method then a TDI_RECEIVE IRP should best be
    returned in the last parmeter to then receive the remaining data not
    taken.
  2. TdiBuildInternalDeviceControlIrp followed by TdiBuildReceive will
    build such an IRP 3. But TdiBuildDeviceControlIrp actually calls
    IoBuildDeviceIoControlRequest 4. IoBuildDeviceIoControlRequest must be
    running at passive level and cannot be reused (IoReuseIrp).
  3. Therefore the TDI_RECEIVE IRPs must be prebuilt in anticipation of
    being needed in the TDI_EVENT_RECEIVE.
    6! So they must be prebuilt, but they can’t be reused. So what gives
    when I quickly run out of prebuilt IRPs needed in TDI_EVENT_RECEIVE
    which runs at dispatch IRQL so I can’t rebuild anymore and cannot
    reused the existing ones.
    There’s a hole in the bucket Dear Liza.
    [PCAUSA] Don’t use TdiBuildInternalDeviceControlIrp. Instead, study the use
    of IoAllocateIrp and use of other TdiBuild MACROS that can initialize the
    IRP.

You will see that the limitations on IoAllocateIrp are less restrictive
concerning IRQL.

Good luck,

Thomas F. Divine
http://www.pcausa.com


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

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


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

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

Thanks for the information! I will proceed with that. Thanks again!

I have a positive experience of abandoning TdiBuildInternalDeviceControlIrp
and using IoAllocateIrp instead. Just fill the request the same way as the
TdiBuildInternalDeviceControlIrp macro does this.


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

wrote in message news:xxxxx@ntdev…
> I am a little confused. Seems like I have read conflicting information about
TDI_EVENT_RECEIVE processing which leaves me not knowing which way to turn. So
which of the following is inaccurate:
>
> 1. if the BytesIndicated is less than BytesAvailable in the TDI_EVENT_RECEIVE
method then a TDI_RECEIVE IRP should best be returned in the last parmeter to
then receive the remaining data not taken.
> 2. TdiBuildInternalDeviceControlIrp followed by TdiBuildReceive will build
such an IRP
> 3. But TdiBuildDeviceControlIrp actually calls IoBuildDeviceIoControlRequest
> 4. IoBuildDeviceIoControlRequest must be running at passive level and cannot
be reused (IoReuseIrp).
> 5. Therefore the TDI_RECEIVE IRPs must be prebuilt in anticipation of being
needed in the TDI_EVENT_RECEIVE.
> 6! So they must be prebuilt, but they can’t be reused. So what gives when I
quickly run out of prebuilt IRPs needed in TDI_EVENT_RECEIVE which runs at
dispatch IRQL so I can’t rebuild anymore and cannot reused the existing ones.
> There’s a hole in the bucket Dear Liza.
>