Event not set after call to GetOverlappedResult

Hi,
I’ve written a driver for a usb device that (partially) emulates several
serial ports.

It works well with HyperTerminal and Terminal, but not with a custom
application that uses TurboPower’s ASyncPro com port components. I’ve
traced into the ASyncPro component to see that it calls WaitCommEvent for
RXCHAR, CTS, DSR, RLSD, BREAK, ERR, and RING, and then calls
GetOverlappedResult to wait for the event.

My driver pends the IOCTL_SERIAL_WAIT_ON_MASK device control IRP, and when
it receives data from the device at a later time, completes it, setting
the RXCHAR bit in the returned event word. However, I can see that at the
completion of the application’s GetOverlappedResult the event mask
specified in the WaitCommEvent call is still 0.

The odd thing is that Terminal (I don’t have the source for it), also uses
WaitCommEvent calls (since I see my driver handling
IOCTL_SERIAL_WAIT_ON_MASK). Terminal only waits on the RXCHAR event.

Also, I built TurboPower’s TermDemo sample program, and it accessed my
device with no problems, again using IOCTL_SERIAL_WAIT_ON_MASK.

I’m stumped as to how to proceed with debugging this problem. Any
suggestions would be greatly appreciated.

Thanks,
Linda

Make sure that you call IoMarkIrpPending in the path that you pend the
IRP and that you return STATUS_PENDING when doing so. They must go hand
in hand, if you call IoMarkIrpPending you *must* return STATUS_PENDING.

Also, for IRPs that you didn’t create (ie received them in a dispatch
routine) that you are sending down the stack that you do the following
in the completion routine before allowing the irp to continue up the
stack.

if (Irp->PendingReturned) {
IoMarkIrpPending(Irp);
}

If you do this in your completion routine for IRPs you allocated
yourself, you will be corrupting memory with the IoMarkIrpPending call
(it touches memory in the current irp stack location which is
nonexistent).

Also, most importantly, enable the driver verifier on your driver(s).
It is usually very good at finding IRP pending bugs.

D

This posting is provided “AS IS” with no warranties, and confers no
rights

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Linda Marcellus
Sent: Wednesday, July 09, 2003 4:25 PM
To: NT Developers Interest List
Subject: [ntdev] Event not set after call to GetOverlappedResult

Hi,
I’ve written a driver for a usb device that (partially) emulates several
serial ports.

It works well with HyperTerminal and Terminal, but not with a custom
application that uses TurboPower’s ASyncPro com port components. I’ve
traced into the ASyncPro component to see that it calls WaitCommEvent
for
RXCHAR, CTS, DSR, RLSD, BREAK, ERR, and RING, and then calls
GetOverlappedResult to wait for the event.

My driver pends the IOCTL_SERIAL_WAIT_ON_MASK device control IRP, and
when
it receives data from the device at a later time, completes it, setting
the RXCHAR bit in the returned event word. However, I can see that at
the
completion of the application’s GetOverlappedResult the event mask
specified in the WaitCommEvent call is still 0.

The odd thing is that Terminal (I don’t have the source for it), also
uses
WaitCommEvent calls (since I see my driver handling
IOCTL_SERIAL_WAIT_ON_MASK). Terminal only waits on the RXCHAR event.

Also, I built TurboPower’s TermDemo sample program, and it accessed my
device with no problems, again using IOCTL_SERIAL_WAIT_ON_MASK.

I’m stumped as to how to proceed with debugging this problem. Any
suggestions would be greatly appreciated.

Thanks,
Linda


You are currently subscribed to ntdev as: xxxxx@windows.microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

> Also, for IRPs that you didn’t create (ie received them in a
dispatch

routine) that you are sending down the stack that you do the
following
in the completion routine before allowing the irp to continue up the
stack.

if (Irp->PendingReturned) {
IoMarkIrpPending(Irp);
}

This is not needed if the completion routine returns
STATUS_MORE_PROCESSING_REQUIRED, but necessary is it returns
STATUS_SUCCESS.

Max

Thank you, Doron, for your quick reply, and for the advice (I have been
using DriverVerifier, and it has been very useful).

In the dispatch routine, I call IoMarkIrpPending( Irp ) and return
STATUS_PENDING.

In the completion routine, I complete the Irp as follows:

PIO_STACK_LOCATION stack = IoGetCurrentIrpStackLocation ( Irp );
PULONG WaitMask = (ULONG *) Irp->AssociatedIrp.SystemBuffer;
*WaitMask = EventMask;

Irp->IoStatus.Status = STATUS_SUCCESS;
Irp->IoStatus.Information = 0;

IoCompleteRequest ( Irp, IO_NO_INCREMENT );

I have added debug output to my driver, and have seen that the RXCHAR bit
is set in the EventMask returned. As an aside, I tried setting a
breakpoint (using windbg) in the completion routine so I could examine the
Irp, but the target pc freezes (as expected) and windbg on the host pc
doesn’t seem to get control. (…sigh…)

Linda

1.) Your completion routine is not doing the mandatory:

If (Irp->PendingReturned) {
IoMarkIrpPending(Irp);
}

2.) The statement: Irp->IoStatus.Information = 0; is an error, it ought to
be
Irp->IoStatus.Information = sizeof(ULONG);

=====================
Mark Roddy
Hollis Technology Solutions
www.hollistech.com
xxxxx@hollistech.com

-----Original Message-----
From: Linda Marcellus [mailto:xxxxx@novatel.ca]
Sent: Thursday, July 10, 2003 12:18 PM
To: NT Developers Interest List
Subject: [ntdev] RE: Event not set after call to GetOverlappedResult

Thank you, Doron, for your quick reply, and for the advice (I have been
using DriverVerifier, and it has been very useful).

In the dispatch routine, I call IoMarkIrpPending( Irp ) and return
STATUS_PENDING.

In the completion routine, I complete the Irp as follows:

PIO_STACK_LOCATION stack = IoGetCurrentIrpStackLocation ( Irp );
PULONG WaitMask = (ULONG *) Irp->AssociatedIrp.SystemBuffer;
*WaitMask = EventMask;

Irp->IoStatus.Status = STATUS_SUCCESS;
Irp->IoStatus.Information = 0;

IoCompleteRequest ( Irp, IO_NO_INCREMENT );

I have added debug output to my driver, and have seen that the RXCHAR bit is
set in the EventMask returned. As an aside, I tried setting a breakpoint
(using windbg) in the completion routine so I could examine the Irp, but the
target pc freezes (as expected) and windbg on the host pc
doesn’t seem to get control. (…sigh…)

Linda


You are currently subscribed to ntdev as: xxxxx@stratus.com To
unsubscribe send a blank email to xxxxx@lists.osr.com

If this is indeed the completion routine for Irp, then it should not be
calling IoCompleteRequest on Irp. It should return any status other
than STATUS_MORE_PROCESSING_REQUIRED and the IO system will continue
completing it for you.

-p

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Roddy, Mark
Sent: Thursday, July 10, 2003 9:26 AM
To: NT Developers Interest List
Subject: [ntdev] RE: Event not set after call to GetOverlappedResult

1.) Your completion routine is not doing the mandatory:

If (Irp->PendingReturned) {
IoMarkIrpPending(Irp);
}

2.) The statement: Irp->IoStatus.Information = 0; is an error, it ought
to be
Irp->IoStatus.Information = sizeof(ULONG);

=====================
Mark Roddy
Hollis Technology Solutions
www.hollistech.com
xxxxx@hollistech.com

-----Original Message-----
From: Linda Marcellus [mailto:xxxxx@novatel.ca]
Sent: Thursday, July 10, 2003 12:18 PM
To: NT Developers Interest List
Subject: [ntdev] RE: Event not set after call to GetOverlappedResult

Thank you, Doron, for your quick reply, and for the advice (I have been
using DriverVerifier, and it has been very useful).

In the dispatch routine, I call IoMarkIrpPending( Irp ) and return
STATUS_PENDING.

In the completion routine, I complete the Irp as follows:

PIO_STACK_LOCATION stack = IoGetCurrentIrpStackLocation ( Irp );
PULONG WaitMask = (ULONG *) Irp->AssociatedIrp.SystemBuffer;
*WaitMask = EventMask;

Irp->IoStatus.Status = STATUS_SUCCESS;
Irp->IoStatus.Information = 0;

IoCompleteRequest ( Irp, IO_NO_INCREMENT );

I have added debug output to my driver, and have seen that the RXCHAR
bit is
set in the EventMask returned. As an aside, I tried setting a
breakpoint
(using windbg) in the completion routine so I could examine the Irp, but
the
target pc freezes (as expected) and windbg on the host pc
doesn’t seem to get control. (…sigh…)

Linda


You are currently subscribed to ntdev as: xxxxx@stratus.com To
unsubscribe send a blank email to xxxxx@lists.osr.com


You are currently subscribed to ntdev as: xxxxx@microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

Yup, that would be error number 3) :slight_smile:

=====================
Mark Roddy
Hollis Technology Solutions
www.hollistech.com
xxxxx@hollistech.com

-----Original Message-----
From: Peter Wieland [mailto:xxxxx@windows.microsoft.com]
Sent: Thursday, July 10, 2003 12:33 PM
To: NT Developers Interest List
Subject: [ntdev] RE: Event not set after call to GetOverlappedResult

If this is indeed the completion routine for Irp, then it should not be
calling IoCompleteRequest on Irp. It should return any status other than
STATUS_MORE_PROCESSING_REQUIRED and the IO system will continue completing
it for you.

-p

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Roddy, Mark
Sent: Thursday, July 10, 2003 9:26 AM
To: NT Developers Interest List
Subject: [ntdev] RE: Event not set after call to GetOverlappedResult

1.) Your completion routine is not doing the mandatory:

If (Irp->PendingReturned) {
IoMarkIrpPending(Irp);
}

2.) The statement: Irp->IoStatus.Information = 0; is an error, it ought to
be
Irp->IoStatus.Information = sizeof(ULONG);

=====================
Mark Roddy
Hollis Technology Solutions
www.hollistech.com
xxxxx@hollistech.com

-----Original Message-----
From: Linda Marcellus [mailto:xxxxx@novatel.ca]
Sent: Thursday, July 10, 2003 12:18 PM
To: NT Developers Interest List
Subject: [ntdev] RE: Event not set after call to GetOverlappedResult

Thank you, Doron, for your quick reply, and for the advice (I have been
using DriverVerifier, and it has been very useful).

In the dispatch routine, I call IoMarkIrpPending( Irp ) and return
STATUS_PENDING.

In the completion routine, I complete the Irp as follows:

PIO_STACK_LOCATION stack = IoGetCurrentIrpStackLocation ( Irp );
PULONG WaitMask = (ULONG *) Irp->AssociatedIrp.SystemBuffer;
*WaitMask = EventMask;

Irp->IoStatus.Status = STATUS_SUCCESS;
Irp->IoStatus.Information = 0;

IoCompleteRequest ( Irp, IO_NO_INCREMENT );

I have added debug output to my driver, and have seen that the RXCHAR bit is
set in the EventMask returned. As an aside, I tried setting a breakpoint
(using windbg) in the completion routine so I could examine the Irp, but the
target pc freezes (as expected) and windbg on the host pc
doesn’t seem to get control. (…sigh…)

Linda


You are currently subscribed to ntdev as: xxxxx@stratus.com To
unsubscribe send a blank email to xxxxx@lists.osr.com


You are currently subscribed to ntdev as: xxxxx@microsoft.com To
unsubscribe send a blank email to xxxxx@lists.osr.com


You are currently subscribed to ntdev as: xxxxx@stratus.com To
unsubscribe send a blank email to xxxxx@lists.osr.com

Sorry. I misspoke. This is not a completion routine. It is the routine
I use to complete the Irp.
Linda

If this is indeed the completion routine for Irp, then it should not be
calling IoCompleteRequest on Irp. It should return any status other
than STATUS_MORE_PROCESSING_REQUIRED and the IO system will continue
completing it for you.

-p=20

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Roddy, Mark
Sent: Thursday, July 10, 2003 9:26 AM
To: NT Developers Interest List
Subject: [ntdev] RE: Event not set after call to GetOverlappedResult

1.) Your completion routine is not doing the mandatory:

If (Irp->PendingReturned) {
IoMarkIrpPending(Irp);
}

2.) The statement: Irp->IoStatus.Information =3D 0; is an error, it =
ought
to be
Irp->IoStatus.Information =3D sizeof(ULONG);

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
Mark Roddy
Hollis Technology Solutions
www.hollistech.com
xxxxx@hollistech.com

-----Original Message-----
From: Linda Marcellus [mailto:xxxxx@novatel.ca]
Sent: Thursday, July 10, 2003 12:18 PM
To: NT Developers Interest List
Subject: [ntdev] RE: Event not set after call to GetOverlappedResult

Thank you, Doron, for your quick reply, and for the advice (I have been
using DriverVerifier, and it has been very useful).

In the dispatch routine, I call IoMarkIrpPending( Irp ) and return
STATUS_PENDING.

In the completion routine, I complete the Irp as follows:

PIO_STACK_LOCATION stack =3D IoGetCurrentIrpStackLocation ( Irp );
PULONG WaitMask =3D (ULONG *) Irp->AssociatedIrp.SystemBuffer;
*WaitMask =3D EventMask;
=20
Irp->IoStatus.Status =3D STATUS_SUCCESS;
Irp->IoStatus.Information =3D 0;

IoCompleteRequest ( Irp, IO_NO_INCREMENT );

I have added debug output to my driver, and have seen that the RXCHAR
bit is
set in the EventMask returned. As an aside, I tried setting a
breakpoint
(using windbg) in the completion routine so I could examine the Irp, but
the
target pc freezes (as expected) and windbg on the host pc
doesn’t seem to get control. (…sigh…)

Linda


You are currently subscribed to ntdev as: xxxxx@stratus.com To
unsubscribe send a blank email to xxxxx@lists.osr.com


You are currently subscribed to ntdev as: xxxxx@microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

Thanks Mark!

For some reason, I thought the documentation said the information member
was supposed to be set to zero. I double-checked, and sure enough, it’s
supposed to be sizeof(ULONG), and now that it is, things are working much
better!

Linda

1.) Your completion routine is not doing the mandatory:

If (Irp->PendingReturned) {
IoMarkIrpPending(Irp);
}

2.) The statement: Irp->IoStatus.Information = 0; is an error, it ought to
be
Irp->IoStatus.Information = sizeof(ULONG);

=====================
Mark Roddy
Hollis Technology Solutions
www.hollistech.com
xxxxx@hollistech.com

-----Original Message-----
From: Linda Marcellus [mailto:xxxxx@novatel.ca]
Sent: Thursday, July 10, 2003 12:18 PM
To: NT Developers Interest List
Subject: [ntdev] RE: Event not set after call to GetOverlappedResult

Thank you, Doron, for your quick reply, and for the advice (I have been
using DriverVerifier, and it has been very useful).

In the dispatch routine, I call IoMarkIrpPending( Irp ) and return
STATUS_PENDING.

In the completion routine, I complete the Irp as follows:

PIO_STACK_LOCATION stack = IoGetCurrentIrpStackLocation ( Irp );
PULONG WaitMask = (ULONG *) Irp->AssociatedIrp.SystemBuffer;
*WaitMask = EventMask;

Irp->IoStatus.Status = STATUS_SUCCESS;
Irp->IoStatus.Information = 0;

IoCompleteRequest ( Irp, IO_NO_INCREMENT );

I have added debug output to my driver, and have seen that the RXCHAR bit is
set in the EventMask returned. As an aside, I tried setting a breakpoint
(using windbg) in the completion routine so I could examine the Irp, but the
target pc freezes (as expected) and windbg on the host pc
doesn’t seem to get control. (…sigh…)

Linda


You are currently subscribed to ntdev as: xxxxx@stratus.com To
unsubscribe send a blank email to xxxxx@lists.osr.com