Note that there are some explanatory texts on larger screens.

plurals
  1. POWho enforces dwShareMode on CreateFile? The OS or the Driver?
    primarykey
    data
    text
    <p>I have a Windows application that interacts with some hardware. A handle to the hardware is opened with CreateFile, and we control the hardware using DeviceIoControl.</p> <p>I'm attempting to update an application which uses this hardware to open the hardware in an exclusive mode, so that other programs can't access the hardware at the same time (the hardware has mutable state that I can't have changed out from under me). I do this by passing 0 as the dwShareMode parameter to CreateFile. After making this change, I am still able to run two separate instances of my application. Both calls to CreateFile in both processes are successful. Neither returns INVALID_HANDLE_VALUE.</p> <p>I believe one of several things is happening, and I'm asking for help narrowing the problem down.</p> <ol> <li>I badly misunderstand the dwShareMode parameter</li> <li><s>dwShareMode doesn't have any effect on DeviceIoControl - only ReadFile or WriteFile</s></li> <li>The driver itself is somehow responsible for respecting the dwShareMode parameter and our driver is written badly. This, sadly, isn't totally unheard of.</li> </ol> <p><strong>Edit</strong> Option 2 is nonsense. dwShareMode should prevent the 2nd CreateFile from happening, DeviceIoControl has nothing to do with it. It must be option #1 or option #3</p> <p><strong>The Question:</strong></p> <p>Is the device driver responsible for looking at the dwShareMode parameter, and rejecting requests if someone has already opened a handle without sharing, or is the OS responsible?</p> <p>If the device driver is responsible, then I'm going to assume #3 is happening. If the OS is responsible, then it must be #1.</p> <p><strong>Some additional Clues:</strong> <a href="http://msdn.microsoft.com/en-us/library/windows/hardware/ff550729%28v=vs.85%29.aspx" rel="nofollow">IRP_MJ_CREATE</a> documentation suggests that the sharing mode does indeed get passed down to the device driver</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload