Deadlock with CloseHandle

Hello,
I’am writing a WDM driver for Windows 2000 to interface a custom PCI card
and I have 2 questions:

  1. Is there any way two do simultaneously a ReadFile and a WriteFile
    without opening two handles (CreateFile). The IO manager seems to queue
    (the dispatch routines in the driver are not called) the write/write
    operation while previous read/write operation is not terminated. In my
    driver, the read and the write must be blocking and a read must be
    absolutely executed at the same time as the write operation.

  2. My big problem: when I want to quit my application, I call CloseHandle
    on both my handle but again the IO manager seems to block my request. The
    Cleanup dispatch routine and the CloseHandle dispatch routine are not
    called. It is only when the read or the write terminates that the
    dispatchers are called. But I understand well, it is the goal of the
    cleanup routine to terminated the pending IRP. How can I do this is my
    dispatcher is never called ?

Note: My DispatchReadWrite routine call IoMarkIrpPending() and return
STATUS_PENDING. I do not use the start IO. I have my own queue (one for the
read and one for the write operations). The processing is done in a ISR and
the IRP are terminated in a DpcForIsr.

Thanks for you help !!

Yves

  1. In my opinion, the simplest way to get pending reads and writes with
    the same handle is to either have your application open two threads (they
    can share the handle) or open your device overlapped, create two overlapped
    structures, and issue two reads one right after the other and then wait for
    completion on both of them.

  2. While there is pending I/O the DispatchClose routine will not be
    called. Are you setting up your cancel routines for the IRPs? Also, you
    can call CancelIO from user mode, but then the handle must have been opened
    for overlapped operation.

Shaun

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Yves Godin
Sent: Wednesday, October 30, 2002 8:23 PM
To: NT Developers Interest List
Subject: [ntdev] Deadlock with CloseHandle

Hello,
I’am writing a WDM driver for Windows 2000 to interface a custom PCI card
and I have 2 questions:

  1. Is there any way two do simultaneously a ReadFile and a WriteFile
    without opening two handles (CreateFile). The IO manager seems to queue
    (the dispatch routines in the driver are not called) the write/write
    operation while previous read/write operation is not terminated. In my
    driver, the read and the write must be blocking and a read must be
    absolutely executed at the same time as the write operation.

  2. My big problem: when I want to quit my application, I call CloseHandle
    on both my handle but again the IO manager seems to block my request. The
    Cleanup dispatch routine and the CloseHandle dispatch routine are not
    called. It is only when the read or the write terminates that the
    dispatchers are called. But I understand well, it is the goal of the
    cleanup routine to terminated the pending IRP. How can I do this is my
    dispatcher is never called ?

Note: My DispatchReadWrite routine call IoMarkIrpPending() and return
STATUS_PENDING. I do not use the start IO. I have my own queue (one for the
read and one for the write operations). The processing is done in a ISR and
the IRP are terminated in a DpcForIsr.

Thanks for you help !!

Yves


You are currently subscribed to ntdev as: xxxxx@tenpennies.com
To unsubscribe send a blank email to %%email.unsub%%

I/O acquires the file-object lock when you do synchronous i/o on
reads/writes/cleanup etc., and releases it only when it completes so
this is working exactly as designed. This has nothing to do with drivers
returning pending or otherwise -
If the app opened the handle for ‘overlapped i/o’, I/O would not
synchronize i/o to that file object.
Ravi

-----Original Message-----
From: Yves Godin [mailto:xxxxx@lyre.qc.ca]
Sent: Wednesday, October 30, 2002 8:23 PM
To: NT Developers Interest List
Subject: [ntdev] Deadlock with CloseHandle

Hello,
I’am writing a WDM driver for Windows 2000 to interface a custom
PCI card and I have 2 questions:

  1. Is there any way two do simultaneously a ReadFile and a WriteFile
    without opening two handles (CreateFile). The IO manager seems to queue
    (the dispatch routines in the driver are not called) the write/write
    operation while previous read/write operation is not terminated. In my
    driver, the read and the write must be blocking and a read must be
    absolutely executed at the same time as the write operation.

  2. My big problem: when I want to quit my application, I call
    CloseHandle on both my handle but again the IO manager seems to block my
    request. The Cleanup dispatch routine and the CloseHandle dispatch
    routine are not called. It is only when the read or the write terminates
    that the dispatchers are called. But I understand well, it is the goal
    of the cleanup routine to terminated the pending IRP. How can I do this
    is my dispatcher is never called ?

Note: My DispatchReadWrite routine call IoMarkIrpPending() and return
STATUS_PENDING. I do not use the start IO. I have my own queue (one for
the read and one for the write operations). The processing is done in a
ISR and the IRP are terminated in a DpcForIsr.

Thanks for you help !!

Yves


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

> 1. Is there any way two do simultaneously a ReadFile and a WriteFile

without opening two handles (CreateFile). The IO manager seems to
queue
(the dispatch routines in the driver are not called) the write/write
operation while previous read/write operation is not terminated. In
my

Use overlapped IO to get rid of this.

Max

See the answers below :

  1. Is there any way two do simultaneously a ReadFile and a WriteFile
    without opening two handles (CreateFile). The IO manager seems to queue
    (the dispatch routines in the driver are not called) the write/write
    operation while previous read/write operation is not terminated. In my
    driver, the read and the write must be blocking and a read must be
    absolutely executed at the same time as the write operation.

>>> Open the Device first using CreateFile with OVERLAPPED operation flag
.Open two threads in the Application one for read and one for write . Pass
the Device Handle to the threads , so that you can use it for ReadFile and
WriteFile calls . Wait for overlapped event in each thread after calling
WriteFile or ReadFile call. You can keep the WriteFile and ReadFile calls in
a while loop which is waiting for thread termination flag .

  1. My big problem: when I want to quit my application, I call CloseHandle
    on both my handle but again the IO manager seems to block my request. The
    Cleanup dispatch routine and the CloseHandle dispatch routine are not
    called. It is only when the read or the write terminates that the
    dispatchers are called. But I understand well, it is the goal of the
    cleanup routine to terminated the pending IRP. How can I do this is my
    dispatcher is never called ?

>>> When you call CloseHandle , then you will definitely receive
DispatchCleanUp IRP, in that you need to cancel all the queued IRP’s in the
queue managed by your driver.Once you don’t have any pending IRP’s , then
you will automatically receive IRP_MJ_CLOSE IRP in your driver. I believe
you are setting a cancel routine for each IRP before queueing . Upon
receiving an error for ReadFile or WriteFile call which are waiting for
completion, at that time check whether you can send any new request or not .
Before calling CloseHandle have some kind of event mechanism , so that you
will not continue to send the requests anymore from each thread.

Srinivasa

if you want multiple IO requests on a file handle you need to open it
for overlapped operations. This means you’ll need to provide an
overlapped structure with each request which contains the offset for the
operation - the IO system no longer the current file position for you in
this case.

if you want to be able to close the handle while IO is outstanding you
need to support cancellation. Once your outstanding IO is cancelled the
cleanup and close requests will be sent.

-p

-----Original Message-----
From: Yves Godin [mailto:xxxxx@lyre.qc.ca]
Sent: Wednesday, October 30, 2002 8:23 PM
To: NT Developers Interest List
Subject: [ntdev] Deadlock with CloseHandle

Hello,
I’am writing a WDM driver for Windows 2000 to interface a custom
PCI card and I have 2 questions:

  1. Is there any way two do simultaneously a ReadFile and a WriteFile
    without opening two handles (CreateFile). The IO manager seems to queue
    (the dispatch routines in the driver are not called) the write/write
    operation while previous read/write operation is not terminated. In my
    driver, the read and the write must be blocking and a read must be
    absolutely executed at the same time as the write operation.

  2. My big problem: when I want to quit my application, I call
    CloseHandle on both my handle but again the IO manager seems to block my
    request. The Cleanup dispatch routine and the CloseHandle dispatch
    routine are not called. It is only when the read or the write terminates
    that the dispatchers are called. But I understand well, it is the goal
    of the cleanup routine to terminated the pending IRP. How can I do this
    is my dispatcher is never called ?

Note: My DispatchReadWrite routine call IoMarkIrpPending() and return
STATUS_PENDING. I do not use the start IO. I have my own queue (one for
the read and one for the write operations). The processing is done in a
ISR and the IRP are terminated in a DpcForIsr.

Thanks for you help !!

Yves


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