CreateFile with dwShareMode set to 0 returns multiple handles

We have a legacy NT driver and a PCI-x cardthat is being replaced with a kmdf driver and a PCIe card. With the legacy driver, when a call is made to CreateFile passing 0 for dwShareMode, a second call to create file fails, as it should. However, when a call is made to CreateFile to get a handle to the kmdf driver, also with dwShareMode set to 0, then another call is made to CreateFile, a handle is returned for the second call as well. Any ideas for what could cause this difference in behavior?

My_Handle = CreateFile(
“\\.\mydevice”, // format is \\.\
GENERIC_WRITE | GENERIC_READ, // access mode
0, // share mode
NULL, // security attributes
OPEN_EXISTING, // how to create
FILE_ATTRIBUTE_SYSTEM, // file attributes
NULL // handle to file att copy
);

Thanks,
Sherri

Sharing access is enforced by the driver. Not sure why the legacy driver enforced sharing, but you can enforce it on your own in your evtdevicefilecreate callback by using iocheckshareaccess and iosetshareaccess from wdm

d

tiny phone keyboard + fat thumbs = you do the muth

-----Original Message-----
From: xxxxx@yahoo.com
Sent: Tuesday, February 02, 2010 6:56 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] CreateFile with dwShareMode set to 0 returns multiple handles

We have a legacy NT driver and a PCI-x cardthat is being replaced with a kmdf driver and a PCIe card. With the legacy driver, when a call is made to CreateFile passing 0 for dwShareMode, a second call to create file fails, as it should. However, when a call is made to CreateFile to get a handle to the kmdf driver, also with dwShareMode set to 0, then another call is made to CreateFile, a handle is returned for the second call as well. Any ideas for what could cause this difference in behavior?

My_Handle = CreateFile(
“\\.\mydevice”, // format is \\.\
GENERIC_WRITE | GENERIC_READ, // access mode
0, // share mode
NULL, // security attributes
OPEN_EXISTING, // how to create
FILE_ATTRIBUTE_SYSTEM, // file attributes
NULL // handle to file att copy
);

Thanks,
Sherri


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

Doron,

Thanks very much for the response.

Sherri

If all you want to do is make the device exclusive so that only one handle can be opened (regardless of the share bits specified), just call WdfDeviceInitSetExclusive

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@yahoo.com
Sent: Tuesday, February 02, 2010 9:37 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] CreateFile with dwShareMode set to 0 returns multiple handles

Doron,

Thanks very much for the response.

Sherri


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

Doron,

Thanks again, this may actually make more sense for this situation.

Thanks,
Sherri