Problem with IRP and Processing data problem

Hi,

I’m developing a virtual port com driver, and i have some questions:

1 - when i need pending an IRP, i use a global variable (ex. pIrpData) to save IRP.

IoMarkIrpPending(pIrp);
pIrpData = pIrp;
return STATUS_PENDING;

And later i complete IRP (pIrpData).

This is working, but don´t seem the best way to do it, and i’m afraid in the future this can be a problem . Suggestions??

2 - there is a situation, that i make one connection through my virtual port, then the driver catch this connection and send data to user application, while the user application is processing the data if i send a new request to connect to virtual port before user application complete processing the pc restart. How can prevent this?

Sorry my English and thanks in advance.

Cheers.

The usual method is to have a LIST_ENTRY queue in your DeviceExtension and put the pending IRP in that queue. If you can guarantee that no more that one IRP will be pending at any time, a pointer variable can replace the LIST_ENTRY. See the “Singly- and Doubly-Linked Lists” section in the WDK docs. You can use the Tail.Overlay.ListEntry field for queing IRPs. You also need to consider cancel processing whenever you queue IRPs in your driver.

Finally, you should consider using the driver framework for new development.

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@gmail.com
Sent: Monday, July 30, 2007 7:19 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Problem with IRP and Processing data problem

Hi,

I’m developing a virtual port com driver, and i have some questions:

1 - when i need pending an IRP, i use a global variable (ex. pIrpData) to save IRP.

IoMarkIrpPending(pIrp);
pIrpData = pIrp;
return STATUS_PENDING;

And later i complete IRP (pIrpData).

This is working, but don?t seem the best way to do it, and i’m afraid in the future this can be a problem . Suggestions??

2 - there is a situation, that i make one connection through my virtual port, then the driver catch this connection and send data to user application, while the user application is processing the data if i send a new request to connect to virtual port before user application complete processing the pc restart. How can prevent this?

Sorry my English and thanks in advance.

Cheers.


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

Thanks for the quick answer :slight_smile:

In my case i receive one IRP each time, so i think to leave as it is.

About second question, i’m still with same error. If somehow i compel the driver refuse receive interrupts in interval time, but how??

> If somehow i compel the driver refuse receive interrupts in interval time, but how??

No, you don’t really want to do something like that…

You just have to make sure that all your driver’s access to shared resources is synchronized.
The way it can be done depends on IRQL that your code may run at. If your code is guaranteed to run at IRQL< DPC level, you can afford “conventional” synchronization techniques, because you can wait. If your code may run at DPC level, the only way to provide synchronization is to use a “normal” spinlock, and if you synchronize with ISR you need either an interrupt spinlock (available only on XP and above) or KeSynchronizeExecution() call…

Anton Bassov

>This is working, but don´t seem the best way to do it, and i’m afraid in the
future

this can be a problem . Suggestions??

Use the queue instead of a global for 1 IRP.


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

Hello again,

Still with same problem…

I try synchronization without luck.

I try explain my problem in more detail:

First i pending an IRP in Major Function IRP_MJ_READ when an application (user mode) do ReadFile

IRP_MJ_READ:
IoMarkIrpPending(pIrp);
pIrpPendingData = pIrp;
return STATUS_PENDING;

then, in function dispacthcreate (IRP_MJ_CREATE) i access to my application (user mode) do this:

IRP_MJ_CREATE:
IoCompleteRequest(pIrpPendingData, IO_NO_INCREMENT);

then, when my application do all work, make again ReadFile and IRP is pending again.

The problem is when i send data to application the application is processing during some seconds, and if i send data in this interval of time the PC boots

If someone have an idea how resolve this, please answer :slight_smile:

Best regards,

Marco Grácio

Marco Gracio wrote:

First i pending an IRP in Major Function IRP_MJ_READ when an
application (user mode) do ReadFile

IRP_MJ_READ:
IoMarkIrpPending(pIrp);
pIrpPendingData = pIrp;
return STATUS_PENDING;

You said this is a virtual COM port driver. If this is the approach you are taking, it is totally wrong for at least the following reasons:

  1. Always pending read IRPs will get you in trouble with software which expects read IRPs to be completed in the dispatch routine under certain circumstances.

  2. It is entirely possible for usermode applications to pend (and expect them to stay pended) multiple read IRPs at your driver. If you are failing the previous one you tucked away in your device extension when a new IRP comes in, or worse, just losing it forever, you are going to have big problems.

  3. As someone else said, cancellation is also going to be a problem if you store IRPs this way.