failure to get a file handle when multiple user programs involved.

Hello

I am reading “The windows 2000 Device Driver Book” by Art Baker and Jerry
Lozano. I am at the point where I have built the loopback driver and I
have installed it on my target machine. I also have a host machine which
allows me to run WinDbg so that I can get DbgPrint output from the driver.
Everything works ok when I run one copy of the user land test program. It
writes a buffer to the device driver and then reads back the same buffer.

However, when I more than one copy of the user land test program
simulataneously, I often get “Failed to obtain file handle to Device: LBK1
with Win32 error code: 5” which corresponds to Access is Denied. This is
generated when the test program attempts to CreateFile the device.

By default, the test code has the CreateFile share mode parameter set to
0. I added SHARE_READ | SHARE_WRITE but it still fails with this error
code. Any idea how to fix this? I’m only trying to read/write
simulataneosly because his book says that is a good test.

JD

Hi John,

you are setting the execlusive flag of “IoCreateDevice” as TRUE, because of that you are gettin the problem of not opening the multiple handles to the same device. Just set it as FALSE u will get the success in opening device handle and all.

 

Good Luck,


From: John F Davis

>Reply-To: “Windows System Software Devs Interest List”
>To: “Windows System Software Devs Interest List”
>Subject: [ntdev] failure to get a file handle when multiple user programs involved.
>Date: Mon, 19 Jan 2004 17:59:04 -0500
>
>Hello
>
>I am reading “The windows 2000 Device Driver Book” by Art Baker and Jerry
>Lozano. I am at the point where I have built the loopback driver and I
>have installed it on my target machine. I also have a host machine which
>allows me to run WinDbg so that I can get DbgPrint output from the driver.
> Everything works ok when I run one copy of the user land test program. It
>writes a buffer to the device driver and then reads back the same buffer.
>
>However, when I more than one copy of the user land test program
>simulataneously, I often get “Failed to obtain file handle to Device: LBK1
>with Win32 error code: 5” which corresponds to Access is Denied. This is
>generated when the test program attempts to CreateFile the device.
>
>By default, the test code has the CreateFile share mode parameter set to
>0. I added SHARE_READ | SHARE_WRITE but it still fails with this error
>code. Any idea how to fix this? I’m only trying to read/write
>simulataneosly because his book says that is a good test.
>
>JD
>
>—
>Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256
>
>You are currently subscribed to ntdev as: xxxxx@hotmail.com
>To unsubscribe send a blank email to xxxxx@lists.osr.com


Marriage? Join BharatMatrimony.com and get married.

Hello Yatindra,

You are correct, but it just leads to more questions.

From the help:
Exclusive
Reserved for system use. Drivers set this parameter to FALSE.

So, why would the author set this to True?

On a related note, once I tried this code using FALSE, it worked until I
got this sequence:
Ch 7 Driver - DispatchCreate
Ch 7 Driver - DispatchCreate
Ch 7 Driver - DispatchWrite
Ch 7 Driver - DispatchWrite
Ch 7 Driver - DispatchRead
Ch 7 Driver - DispatchClose
Ch 7 Driver - DispatchRead

The error seemed that it tried to free the buffer twice. You can see that
it tried to do a read twice without an interleaving write.

Here is the stack trace:
BAD_POOL_CALLER (c2)
The current thread is making a bad pool request. Typically this is at a
bad IRQL level or double freeing the same allocation, etc.
Arguments:
Arg1: 00000040, Attempt to free usermode address to kernel pool
Arg2: 00000000, Starting address
Arg3: 80000000, Start of system address space
Arg4: 00000000, 0

Debugging Details:

***** Kernel symbols are WRONG. Please fix symbols to do analysis.

DEFAULT_BUCKET_ID: DRIVER_FAULT

BUGCHECK_STR: 0xC2

LAST_CONTROL_TRANSFER: from 805008cb to 8052a488

STACK_TEXT:
WARNING: Stack unwind information not available. Following frames may be
wrong.
bed6d810 805008cb 00000003 00000000 8054a740
nt!DbgBreakPointWithStatus+0x4
bed6db9c 8054049a 000000c2 00000040 00000000 nt!KeBugCheckEx+0x169
bed6dbd8 8053f43a 00000000 81f3f7a8 00000000 nt!ExFreePoolWithTag+0x1134
bed6dc04 8053f2e2 00000000 00000000 eb970825 nt!ExFreePoolWithTag+0xd4
bed6dc3c 804f3b8b 81efdc70 81e15108 81e15108 nt!ExFreePool+0xb
bed6dc64 8056d71b 81efdc70 81e15108 81f3c708
nt!IoBuildSynchronousFsdRequest+0x8f
bed6dd38 80539691 000003d4 00000000 00000000 nt!NtReadFile+0x364
bed6dd64 00000000 00000000 00000000 00000000
nt!ExReleaseResourceForThread+0xbd5

So, I wonder if there is a way to keep track of the buffers? Any hints?
Anything I should look at? I’m thinking I should pass an id in for the
write and then pass
an id in for the read. The read only returns buffers associated with the
write and only free’s the same buffer.

JD

“yatindra vaishnav”
Sent by: xxxxx@lists.osr.com
01/20/2004 07:11 AM
Please respond to “Windows System Software Devs Interest List”

To: “Windows System Software Devs Interest List”

cc:
Subject: RE: [ntdev] failure to get a file handle when
multiple user programs involved.

Hi John,

you are setting the execlusive flag of “IoCreateDevice” as TRUE, because
of that you are gettin the problem of not opening the multiple handles to
the same device. Just set it as FALSE u will get the success in opening
device handle and all.

Good Luck,


>From: John F Davis
>Reply-To: “Windows System Software Devs Interest List”
>To: “Windows System Software Devs Interest List”
>Subject: [ntdev] failure to get a file handle when multiple user programs
involved.
>Date: Mon, 19 Jan 2004 17:59:04 -0500
>
>Hello
>
>I am reading “The windows 2000 Device Driver Book” by Art Baker and Jerry

>Lozano. I am at the point where I have built the loopback driver and I
>have installed it on my target machine. I also have a host machine which

>allows me to run WinDbg so that I can get DbgPrint output from the
driver.
> Everything works ok when I run one copy of the user land test program.
It
>writes a buffer to the device driver and then reads back the same buffer.

>
>However, when I more than one copy of the user land test program
>simulataneously, I often get “Failed to obtain file handle to Device:
LBK1
>with Win32 error code: 5” which corresponds to Access is Denied. This is

>generated when the test program attempts to CreateFile the device.
>
>By default, the test code has the CreateFile share mode parameter set to
>0. I added SHARE_READ | SHARE_WRITE but it still fails with this error
>code. Any idea how to fix this? I’m only trying to read/write
>simulataneosly because his book says that is a good test.
>
>JD
>
>—
>Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
>You are currently subscribed to ntdev as: xxxxx@hotmail.com
>To unsubscribe send a blank email to xxxxx@lists.osr.com

Marriage? Join BharatMatrimony.com and get married. —
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

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

Well in the current documentation it states:

Indicates whether the device object represents an exclusive device. That is,
only one handle at a time can send I/O requests to the corresponding device
object. If the underlying device supports overlapped I/O, multiple threads
of the same process can send requests through a single handle.

This is not a “system only” parameter, it reflects how you driver and device
are to be used.

Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting

----- Original Message -----
From: “John F Davis”
To: “Windows System Software Devs Interest List”
Sent: Tuesday, January 20, 2004 9:41 AM
Subject: RE: [ntdev] failure to get a file handle when multiple user
programs involved.

> Hello Yatindra,
>
>
> You are correct, but it just leads to more questions.
>
> From the help:
> Exclusive
> Reserved for system use. Drivers set this parameter to FALSE.
>
> So, why would the author set this to True?
>

Hello Don,

Hmm. I wonder how I am getting out of date info. I am using DDK
2600.1106. My help page for “Kernel-Mode Driver Architecture: Windows
DDK” IoCreateDevice says “Built on Wednesday, July 24, 2002” at the bottom
of the page.

“Don Burn”
Sent by: xxxxx@lists.osr.com
01/20/2004 09:50 AM
Please respond to “Windows System Software Devs Interest List”

To: “Windows System Software Devs Interest List”

cc:
Subject: Re: [ntdev] failure to get a file handle when
multiple user programs involved.

Well in the current documentation it states:

Indicates whether the device object represents an exclusive device. That
is,
only one handle at a time can send I/O requests to the corresponding
device
object. If the underlying device supports overlapped I/O, multiple threads
of the same process can send requests through a single handle.

This is not a “system only” parameter, it reflects how you driver and
device
are to be used.

Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting

----- Original Message -----
From: “John F Davis”
To: “Windows System Software Devs Interest List”
Sent: Tuesday, January 20, 2004 9:41 AM
Subject: RE: [ntdev] failure to get a file handle when multiple user
programs involved.

> Hello Yatindra,
>
>
> You are correct, but it just leads to more questions.
>
> From the help:
> Exclusive
> Reserved for system use. Drivers set this parameter to FALSE.
>
> So, why would the author set this to True?
>


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

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

John,

It was my mistake, that was the first XP DDK, the 2003 DDK does state
things your way, but then contradicts on IoCreateDeviceSecure. This looks
like a Microsoft Documentation BUG to me.

Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting

----- Original Message -----
From: “John F Davis”
To: “Windows System Software Devs Interest List”
Sent: Tuesday, January 20, 2004 10:12 AM
Subject: Re: [ntdev] failure to get a file handle when multiple user
programs involved.

> Hello Don,
>
> Hmm. I wonder how I am getting out of date info. I am using DDK
> 2600.1106. My help page for “Kernel-Mode Driver Architecture: Windows
> DDK” IoCreateDevice says “Built on Wednesday, July 24, 2002” at the bottom
> of the page.
>
>
>
>
> “Don Burn”
> Sent by: xxxxx@lists.osr.com
> 01/20/2004 09:50 AM
> Please respond to “Windows System Software Devs Interest List”
>
> To: “Windows System Software Devs Interest List”
>
> cc:
> Subject: Re: [ntdev] failure to get a file handle when
> multiple user programs involved.
>
>
> Well in the current documentation it states:
>
> Indicates whether the device object represents an exclusive device. That
> is,
> only one handle at a time can send I/O requests to the corresponding
> device
> object. If the underlying device supports overlapped I/O, multiple threads
> of the same process can send requests through a single handle.
>
>
> This is not a “system only” parameter, it reflects how you driver and
> device
> are to be used.
>
> Don Burn (MVP, Windows DDK)
> Windows 2k/XP/2k3 Filesystem and Driver Consulting
>
> ----- Original Message -----
> From: “John F Davis”
> To: “Windows System Software Devs Interest List”
> Sent: Tuesday, January 20, 2004 9:41 AM
> Subject: RE: [ntdev] failure to get a file handle when multiple user
> programs involved.
>
>
> > Hello Yatindra,
> >
> >
> > You are correct, but it just leads to more questions.
> >
> > From the help:
> > Exclusive
> > Reserved for system use. Drivers set this parameter to FALSE.
> >
> > So, why would the author set this to True?
> >
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: johndavi@us.ibm.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@acm.org
> To unsubscribe send a blank email to xxxxx@lists.osr.com

Hi John,

The reason of setting true is, this book is for learning not for development. And for making other to understand the thing is the better way. The crash is happened because the multiple users have not been taken care in the code out in the sample.

 

Good Luck,



From: John F Davis

>Reply-To: “Windows System Software Devs Interest List”
>To: “Windows System Software Devs Interest List”
>Subject: RE: [ntdev] failure to get a file handle when multiple user programs involved.
>Date: Tue, 20 Jan 2004 09:41:40 -0500
>
>Hello Yatindra,
>
>
>You are correct, but it just leads to more questions.
>
>From the help:
>Exclusive
>Reserved for system use. Drivers set this parameter to FALSE.
>
>So, why would the author set this to True?
>
>On a related note, once I tried this code using FALSE, it worked until I
>got this sequence:
>Ch 7 Driver - DispatchCreate
>Ch 7 Driver - DispatchCreate
>Ch 7 Driver - DispatchWrite
>Ch 7 Driver - DispatchWrite
>Ch 7 Driver - DispatchRead
>Ch 7 Driver - DispatchClose
>Ch 7 Driver - DispatchRead
>
>The error seemed that it tried to free the buffer twice. You can see that
>it tried to do a read twice without an interleaving write.
>
>Here is the stack trace:
>BAD_POOL_CALLER (c2)
>The current thread is making a bad pool request. Typically this is at a
>bad IRQL level or double freeing the same allocation, etc.
>Arguments:
>Arg1: 00000040, Attempt to free usermode address to kernel pool
>Arg2: 00000000, Starting address
>Arg3: 80000000, Start of system address space
>Arg4: 00000000, 0
>
>Debugging Details:
>------------------
>
> ***** Kernel symbols are WRONG. Please fix symbols to do analysis.
>
>
>DEFAULT_BUCKET_ID: DRIVER_FAULT
>
>BUGCHECK_STR: 0xC2
>
>LAST_CONTROL_TRANSFER: from 805008cb to 8052a488
>
>STACK_TEXT:
>WARNING: Stack unwind information not available. Following frames may be
>wrong.
>bed6d810 805008cb 00000003 00000000 8054a740
>nt!DbgBreakPointWithStatus+0x4
>bed6db9c 8054049a 000000c2 00000040 00000000 nt!KeBugCheckEx+0x169
>bed6dbd8 8053f43a 00000000 81f3f7a8 00000000 nt!ExFreePoolWithTag+0x1134
>bed6dc04 8053f2e2 00000000 00000000 eb970825 nt!ExFreePoolWithTag+0xd4
>bed6dc3c 804f3b8b 81efdc70 81e15108 81e15108 nt!ExFreePool+0xb
>bed6dc64 8056d71b 81efdc70 81e15108 81f3c708
>nt!IoBuildSynchronousFsdRequest+0x8f
>bed6dd38 80539691 000003d4 00000000 00000000 nt!NtReadFile+0x364
>bed6dd64 00000000 00000000 00000000 00000000
>nt!ExReleaseResourceForThread+0xbd5
>
>So, I wonder if there is a way to keep track of the buffers? Any hints?
>Anything I should look at? I’m thinking I should pass an id in for the
>write and then pass
>an id in for the read. The read only returns buffers associated with the
>write and only free’s the same buffer.
>
>JD
>
>
>
>
>
>
>“yatindra vaishnav”
>Sent by: xxxxx@lists.osr.com
>01/20/2004 07:11 AM
>Please respond to “Windows System Software Devs Interest List”
>
> To: “Windows System Software Devs Interest List”
>
> cc:
> Subject: RE: [ntdev] failure to get a file handle when
>multiple user programs involved.
>
>
>
>
>Hi John,
>
>you are setting the execlusive flag of “IoCreateDevice” as TRUE, because
>of that you are gettin the problem of not opening the multiple handles to
>the same device. Just set it as FALSE u will get the success in opening
>device handle and all.
>
>
>
>Good Luck,
>
>
> >From: John F Davis
> >Reply-To: “Windows System Software Devs Interest List”
> >To: “Windows System Software Devs Interest List”
> >Subject: [ntdev] failure to get a file handle when multiple user programs
>involved.
> >Date: Mon, 19 Jan 2004 17:59:04 -0500
> >
> >Hello
> >
> >I am reading “The windows 2000 Device Driver Book” by Art Baker and Jerry
>
> >Lozano. I am at the point where I have built the loopback driver and I
> >have installed it on my target machine. I also have a host machine which
>
> >allows me to run WinDbg so that I can get DbgPrint output from the
>driver.
> > Everything works ok when I run one copy of the user land test program.
>It
> >writes a buffer to the device driver and then reads back the same buffer.
>
> >
> >However, when I more than one copy of the user land test program
> >simulataneously, I often get “Failed to obtain file handle to Device:
>LBK1
> >with Win32 error code: 5” which corresponds to Access is Denied. This is
>
> >generated when the test program attempts to CreateFile the device.
> >
> >By default, the test code has the CreateFile share mode parameter set to
> >0. I added SHARE_READ | SHARE_WRITE but it still fails with this error
> >code. Any idea how to fix this? I’m only trying to read/write
> >simulataneosly because his book says that is a good test.
> >
> >JD
> >
> >—
> >Questions? First check the Kernel Driver FAQ at
>http://www.osronline.com/article.cfm?id=256
> >
> >You are currently subscribed to ntdev as: xxxxx@hotmail.com
> >To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
>Marriage? Join BharatMatrimony.com and get married. —
>Questions? First check the Kernel Driver FAQ at
>http://www.osronline.com/article.cfm?id=256
>
>You are currently subscribed to ntdev as: johndavi@us.ibm.com
>To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
>—
>Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256
>
>You are currently subscribed to ntdev as: xxxxx@hotmail.com
>To unsubscribe send a blank email to xxxxx@lists.osr.com


Get head-hunted by 10,000 recruiters. Post your CV on naukri.com today.