about my Irp cancel

Hi eyebody,
Thank you very much for your replay.In fact, I want to develop a
socket lib with TDI.In my receive routine, I build a tdi receive irp with
TdiBuildReceive API.I sepcified a TIME_OUT value, so I want to cancel the
receive IRP when time out occured. I wonder how can i do that?Can the
following code work correctly?

Irp = TdiBuildInternalDeviceControlIrp(…);
TdiBuildReceive(Irp, &event, …);
status = IoCallDriver(TcpDevice, Irp);
if(status == STATUS_PENDING) {
ret = KeWaitForSingleObject(&event, …);
if(ret == STATUS_TIMEOUT) {
IoCancelIrp(Irp);
}
}
By the way, I use TCP to transter data.

Why not just use TdiBuildSetEventHandler instead and let TDI notify you when
a receive message is available?

At any rate, you have a race condition with your completion handler. However
as you own the IRP in question, and assuming that the same code segment you
describe below is also tasked with disposing the IRP, it is not the case
that the IRP in question is going to get deallocated or reallocated
underneath you. The problem instead is has the IRP already completed and if
so is it safe to call IoCancelIrp on a completed IRP. Assume for now that
this is safe. Assume also that TDI underneath you will respect the
cancellation and will complete the IRP. Consequently your completion routine
either has already run by the time you call IoCancelIrp or will run after
you call IoCancelIrp. Your code can simply call KeWaitForSingleObject again
after calling IoCancelIrp, this time without a timeout (infinite wait) and
dispose of the IRP when the second call to KeWaitForSingleObject completes.

So the real problem is can IoCancelIrp be safely called after your
completion routine is run? I think it can, as basically it is using a safe
interlocked operation to fetch the cancel routine for the IRP, which will be
null if your completion handler has already run, but driver verifier may
have a different opinion.

=====================
Mark Roddy DDK MVP
Windows 2003/XP/2000 Consulting
Hollis Technology Solutions 603-321-1032
www.hollistech.com


From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of ??
Sent: Monday, July 03, 2006 10:42 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] about my Irp cancel

Hi eyebody,
Thank you very much for your replay.In fact, I want to develop a
socket lib with TDI.In my receive routine, I build a tdi receive irp with
TdiBuildReceive API.I sepcified a TIME_OUT value, so I want to cancel the
receive IRP when time out occured. I wonder how can i do that?Can the
following code work correctly?

Irp = TdiBuildInternalDeviceControlIrp(…);
TdiBuildReceive(Irp, &event, …);
status = IoCallDriver(TcpDevice, Irp);
if(status == STATUS_PENDING) {
ret = KeWaitForSingleObject(&event, …);
if(ret == STATUS_TIMEOUT) {
IoCancelIrp(Irp);
}
}
By the way, I use TCP to transter data.
— 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

It is safe to touch after the completion routine has run if and only if the completion routine returns STATUS_MORE_PROCESSING_REQUIRED *AND* does not call IoCompleteRequest/IoFreeIrp. If you do both, the irp’s completion is suspend and the underlying memory for the PIRP is still valid. IoCancelIrp requires that the PIRP memory be valid, the current stack location is not a consideration.

d


From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Mark Roddy
Sent: Tuesday, July 04, 2006 8:38 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] about my Irp cancel

Why not just use TdiBuildSetEventHandler instead and let TDI notify you when a receive message is available?
?
At any rate, you have a race condition with your completion handler. However as you own the IRP in question, and assuming that the same code segment you describe below is also tasked with disposing the IRP, it is not the case that the IRP in question is going to get deallocated or reallocated underneath you. The problem instead is has the IRP already completed and if so is it safe to call IoCancelIrp on a completed IRP.? Assume for now that this is safe. Assume also that TDI underneath you will respect the cancellation and will complete the IRP. Consequently your completion routine either has already run by the time you call IoCancelIrp or will run after you call IoCancelIrp. Your code can simply call KeWaitForSingleObject again after calling IoCancelIrp, this time without a timeout (infinite wait) and dispose of the IRP when the second call to KeWaitForSingleObject completes.
?
?
So the real problem is can IoCancelIrp be safely called after your completion routine is run? I think it can, as basically it is using? a safe interlocked operation to fetch the cancel routine for the IRP, which will be null if your completion handler has already run, but driver verifier may have a different opinion.

Mark Roddy DDK MVP
Windows 2003/XP/2000 Consulting
Hollis Technology Solutions 603-321-1032
www.hollistech.com
?


From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of ??
Sent: Monday, July 03, 2006 10:42 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] about my Irp cancel
Hi eyebody,
??? Thank you very much for your replay.In fact, I want to develop a socket lib with TDI.In my?receive routine, I build a tdi receive irp with TdiBuildReceive API.I sepcified a TIME_OUT value, so I want to cancel the receive IRP when time out occured. I wonder how can i do that?Can the following code work correctly?
?
??? Irp = TdiBuildInternalDeviceControlIrp(…);
??? TdiBuildReceive(Irp, &event, …);
??? status = IoCallDriver(TcpDevice, Irp);
??? if(status == STATUS_PENDING) {
??? ret = KeWaitForSingleObject(&event, …);
??? if(ret == STATUS_TIMEOUT) {
??? IoCancelIrp(Irp);
???}
???}
??? By the way, I use TCP to transter data.
— 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

This has been done and the software is public. Note check out the necessary
copywrites before you use. Search for Httpdisk and this is a Bo Branten
project. Enjoy!

-William Michael Jones

“Doron Holan” wrote in message
news:xxxxx@ntdev…
It is safe to touch after the completion routine has run if and only if the
completion routine returns STATUS_MORE_PROCESSING_REQUIRED AND does not
call IoCompleteRequest/IoFreeIrp. If you do both, the irp’s completion is
suspend and the underlying memory for the PIRP is still valid. IoCancelIrp
requires that the PIRP memory be valid, the current stack location is not a
consideration.

d


From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Mark Roddy
Sent: Tuesday, July 04, 2006 8:38 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] about my Irp cancel

Why not just use TdiBuildSetEventHandler instead and let TDI notify you when
a receive message is available?

At any rate, you have a race condition with your completion handler. However
as you own the IRP in question, and assuming that the same code segment you
describe below is also tasked with disposing the IRP, it is not the case
that the IRP in question is going to get deallocated or reallocated
underneath you. The problem instead is has the IRP already completed and if
so is it safe to call IoCancelIrp on a completed IRP. Assume for now that
this is safe. Assume also that TDI underneath you will respect the
cancellation and will complete the IRP. Consequently your completion routine
either has already run by the time you call IoCancelIrp or will run after
you call IoCancelIrp. Your code can simply call KeWaitForSingleObject again
after calling IoCancelIrp, this time without a timeout (infinite wait) and
dispose of the IRP when the second call to KeWaitForSingleObject completes.

So the real problem is can IoCancelIrp be safely called after your
completion routine is run? I think it can, as basically it is using a safe
interlocked operation to fetch the cancel routine for the IRP, which will be
null if your completion handler has already run, but driver verifier may
have a different opinion.
=====================
Mark Roddy DDK MVP
Windows 2003/XP/2000 Consulting
Hollis Technology Solutions 603-321-1032
www.hollistech.com


From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of ??
Sent: Monday, July 03, 2006 10:42 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] about my Irp cancel
Hi eyebody,
Thank you very much for your replay.In fact, I want to develop a socket lib
with TDI.In my receive routine, I build a tdi receive irp with
TdiBuildReceive API.I sepcified a TIME_OUT value, so I want to cancel the
receive IRP when time out occured. I wonder how can i do that?Can the
following code work correctly?

Irp = TdiBuildInternalDeviceControlIrp(…);
TdiBuildReceive(Irp, &event, …);
status = IoCallDriver(TcpDevice, Irp);
if(status == STATUS_PENDING) {
ret = KeWaitForSingleObject(&event, …);
if(ret == STATUS_TIMEOUT) {
IoCancelIrp(Irp);
}
}
By the way, I use TCP to transter data.
— 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

Argh. Expect outburst from Mr. Burn.

=====================
Mark Roddy DDK MVP
Windows 2003/XP/2000 Consulting
Hollis Technology Solutions 603-321-1032
www.hollistech.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
William Michael Jones
Sent: Wednesday, July 05, 2006 2:37 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] about my Irp cancel

This has been done and the software is public. Note check
out the necessary copywrites before you use. Search for
Httpdisk and this is a Bo Branten project. Enjoy!

-William Michael Jones

“Doron Holan” wrote in message
> news:xxxxx@ntdev…
> It is safe to touch after the completion routine has run if
> and only if the completion routine returns
> STATUS_MORE_PROCESSING_REQUIRED AND does not call
> IoCompleteRequest/IoFreeIrp. If you do both, the irp’s
> completion is suspend and the underlying memory for the PIRP
> is still valid. IoCancelIrp requires that the PIRP memory be
> valid, the current stack location is not a consideration.
>
> d
>
>
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Mark Roddy
> Sent: Tuesday, July 04, 2006 8:38 AM
> To: Windows System Software Devs Interest List
> Subject: RE: [ntdev] about my Irp cancel
>
> Why not just use TdiBuildSetEventHandler instead and let TDI
> notify you when a receive message is available?
>
> At any rate, you have a race condition with your completion
> handler. However as you own the IRP in question, and assuming
> that the same code segment you describe below is also tasked
> with disposing the IRP, it is not the case that the IRP in
> question is going to get deallocated or reallocated
> underneath you. The problem instead is has the IRP already
> completed and if so is it safe to call IoCancelIrp on a
> completed IRP. Assume for now that this is safe. Assume also
> that TDI underneath you will respect the cancellation and
> will complete the IRP. Consequently your completion routine
> either has already run by the time you call IoCancelIrp or
> will run after you call IoCancelIrp. Your code can simply
> call KeWaitForSingleObject again after calling IoCancelIrp,
> this time without a timeout (infinite wait) and dispose of
> the IRP when the second call to KeWaitForSingleObject completes.
>
>
> So the real problem is can IoCancelIrp be safely called after
> your completion routine is run? I think it can, as basically
> it is using a safe interlocked operation to fetch the cancel
> routine for the IRP, which will be null if your completion
> handler has already run, but driver verifier may have a
> different opinion.
> =====================
> Mark Roddy DDK MVP
> Windows 2003/XP/2000 Consulting
> Hollis Technology Solutions 603-321-1032 www.hollistech.com
>
>
>

> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of ??
> Sent: Monday, July 03, 2006 10:42 PM
> To: Windows System Software Devs Interest List
> Subject: [ntdev] about my Irp cancel
> Hi eyebody,
> Thank you very much for your replay.In fact, I want to
> develop a socket lib with TDI.In my receive routine, I build
> a tdi receive irp with TdiBuildReceive API.I sepcified a
> TIME_OUT value, so I want to cancel the receive IRP when time
> out occured. I wonder how can i do that?Can the following
> code work correctly?
>
> Irp = TdiBuildInternalDeviceControlIrp(…);
> TdiBuildReceive(Irp, &event, …);
> status = IoCallDriver(TcpDevice, Irp);
> if(status == STATUS_PENDING) {
> ret = KeWaitForSingleObject(&event, …); if(ret ==
> STATUS_TIMEOUT) { IoCancelIrp(Irp); } } By the way, I use TCP
> to transter data.
> — 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
>
>
>
> —
> 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
>

I thought the developer said the following below:
“I want to develop a socket lib with TDI.”
That is why I suggested looking at the Bo Branten project. I have not used
it so if I am wrong may Don Burn correct me.

William Michael Jones “Mike”

“William Michael Jones” wrote in message
news:xxxxx@ntdev…
> This has been done and the software is public. Note check out the
> necessary copywrites before you use. Search for Httpdisk and this is a Bo
> Branten project. Enjoy!
>
> -William Michael Jones
>
> “Doron Holan” wrote in message
> news:xxxxx@ntdev…
> It is safe to touch after the completion routine has run if and only if
> the completion routine returns STATUS_MORE_PROCESSING_REQUIRED AND does
> not call IoCompleteRequest/IoFreeIrp. If you do both, the irp’s
> completion is suspend and the underlying memory for the PIRP is still
> valid. IoCancelIrp requires that the PIRP memory be valid, the current
> stack location is not a consideration.
>
> d
>
>
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Mark Roddy
> Sent: Tuesday, July 04, 2006 8:38 AM
> To: Windows System Software Devs Interest List
> Subject: RE: [ntdev] about my Irp cancel
>
> Why not just use TdiBuildSetEventHandler instead and let TDI notify you
> when a receive message is available?
>
> At any rate, you have a race condition with your completion handler.
> However as you own the IRP in question, and assuming that the same code
> segment you describe below is also tasked with disposing the IRP, it is
> not the case that the IRP in question is going to get deallocated or
> reallocated underneath you. The problem instead is has the IRP already
> completed and if so is it safe to call IoCancelIrp on a completed IRP.
> Assume for now that this is safe. Assume also that TDI underneath you will
> respect the cancellation and will complete the IRP. Consequently your
> completion routine either has already run by the time you call IoCancelIrp
> or will run after you call IoCancelIrp. Your code can simply call
> KeWaitForSingleObject again after calling IoCancelIrp, this time without a
> timeout (infinite wait) and dispose of the IRP when the second call to
> KeWaitForSingleObject completes.
>
>
> So the real problem is can IoCancelIrp be safely called after your
> completion routine is run? I think it can, as basically it is using a safe
> interlocked operation to fetch the cancel routine for the IRP, which will
> be null if your completion handler has already run, but driver verifier
> may have a different opinion.
> =====================
> Mark Roddy DDK MVP
> Windows 2003/XP/2000 Consulting
> Hollis Technology Solutions 603-321-1032
> www.hollistech.com
>
>
>

> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of ??
> Sent: Monday, July 03, 2006 10:42 PM
> To: Windows System Software Devs Interest List
> Subject: [ntdev] about my Irp cancel
> Hi eyebody,
> Thank you very much for your replay.In fact, I want to develop a socket
> lib with TDI.In my receive routine, I build a tdi receive irp with
> TdiBuildReceive API.I sepcified a TIME_OUT value, so I want to cancel the
> receive IRP when time out occured. I wonder how can i do that?Can the
> following code work correctly?
>
> Irp = TdiBuildInternalDeviceControlIrp(…);
> TdiBuildReceive(Irp, &event, …);
> status = IoCallDriver(TcpDevice, Irp);
> if(status == STATUS_PENDING) {
> ret = KeWaitForSingleObject(&event, …);
> if(ret == STATUS_TIMEOUT) {
> IoCancelIrp(Irp);
> }
> }
> By the way, I use TCP to transter data.
> — 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
>
>
>

You might want to search this list to see what I am referring to.

=====================
Mark Roddy DDK MVP
Windows 2003/XP/2000 Consulting
Hollis Technology Solutions 603-321-1032
www.hollistech.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
William Michael Jones
Sent: Wednesday, July 05, 2006 3:53 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] about my Irp cancel

I thought the developer said the following below:
“I want to develop a socket lib with TDI.”
That is why I suggested looking at the Bo Branten project. I
have not used it so if I am wrong may Don Burn correct me.

William Michael Jones “Mike”

“William Michael Jones” wrote in
> message news:xxxxx@ntdev…
> > This has been done and the software is public. Note check out the
> > necessary copywrites before you use. Search for Httpdisk
> and this is
> > a Bo Branten project. Enjoy!
> >
> > -William Michael Jones
> >
> > “Doron Holan” wrote in message
> > news:xxxxx@ntdev…
> > It is safe to touch after the completion routine has run if
> and only
> > if the completion routine returns STATUS_MORE_PROCESSING_REQUIRED
> > AND does not call IoCompleteRequest/IoFreeIrp. If you do
> both, the
> > irp’s completion is suspend and the underlying memory for
> the PIRP is
> > still valid. IoCancelIrp requires that the PIRP memory be
> valid, the
> > current stack location is not a consideration.
> >
> > d
> >
> >
> > From: xxxxx@lists.osr.com
> > [mailto:xxxxx@lists.osr.com] On Behalf Of Mark Roddy
> > Sent: Tuesday, July 04, 2006 8:38 AM
> > To: Windows System Software Devs Interest List
> > Subject: RE: [ntdev] about my Irp cancel
> >
> > Why not just use TdiBuildSetEventHandler instead and let TDI notify
> > you when a receive message is available?
> >
> > At any rate, you have a race condition with your completion
> handler.
> > However as you own the IRP in question, and assuming that the same
> > code segment you describe below is also tasked with
> disposing the IRP,
> > it is not the case that the IRP in question is going to get
> > deallocated or reallocated underneath you. The problem
> instead is has
> > the IRP already completed and if so is it safe to call
> IoCancelIrp on a completed IRP.
> > Assume for now that this is safe. Assume also that TDI
> underneath you
> > will respect the cancellation and will complete the IRP.
> Consequently
> > your completion routine either has already run by the time you call
> > IoCancelIrp or will run after you call IoCancelIrp. Your code can
> > simply call KeWaitForSingleObject again after calling IoCancelIrp,
> > this time without a timeout (infinite wait) and dispose of the IRP
> > when the second call to KeWaitForSingleObject completes.
> >
> >
> > So the real problem is can IoCancelIrp be safely called after your
> > completion routine is run? I think it can, as basically it
> is using a
> > safe interlocked operation to fetch the cancel routine for the IRP,
> > which will be null if your completion handler has already run, but
> > driver verifier may have a different opinion.
> > =====================
> > Mark Roddy DDK MVP
> > Windows 2003/XP/2000 Consulting
> > Hollis Technology Solutions 603-321-1032 www.hollistech.com
> >
> >
> >

> > From: xxxxx@lists.osr.com
> > [mailto:xxxxx@lists.osr.com] On Behalf Of ??
> > Sent: Monday, July 03, 2006 10:42 PM
> > To: Windows System Software Devs Interest List
> > Subject: [ntdev] about my Irp cancel
> > Hi eyebody,
> > Thank you very much for your replay.In fact, I want to
> develop a socket
> > lib with TDI.In my receive routine, I build a tdi receive irp with
> > TdiBuildReceive API.I sepcified a TIME_OUT value, so I want
> to cancel the
> > receive IRP when time out occured. I wonder how can i do
> that?Can the
> > following code work correctly?
> >
> > Irp = TdiBuildInternalDeviceControlIrp(…);
> > TdiBuildReceive(Irp, &event, …);
> > status = IoCallDriver(TcpDevice, Irp);
> > if(status == STATUS_PENDING) {
> > ret = KeWaitForSingleObject(&event, …);
> > if(ret == STATUS_TIMEOUT) {
> > IoCancelIrp(Irp);
> > }
> > }
> > By the way, I use TCP to transter data.
> > — 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
> >
> >
> >
>
>
>
> —
> 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
>