Can a DeviceIoControl block?

I have multiple threads that use the same HANDLE for a device object,
created by:
CreateFile(_T(…), GENERIC_READ | GENERIC_WRITE,
0, NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, NULL);

Now i noticed if a DeviceIoControl() of a thread blocks and waits for an event, other threads are blocked whenever they use DeviceIoControl, until the first thread finishes and returns to userspace.

Is this possible?

If the DRIVER blocks, then pending Requests also wait, right?

So, the answer to your question depends on how the driver is written.

Peter
OSR
@OSRDrivers

I’m talking about different ioctls on the same device.
One ioctl blocks, the other ioctl just changes a flag(no syncronization mechanism over there, nothing… no blocking)

Yet, the “not-blocking” ioctl is blocked.

>I’m talking about different ioctls on the same device.

The IOCTL function code doesn’t make any difference.

To repeat what I said in my previous reply: “the answer to your question depends on hiw the driver is written.”

Peter
OSR
@OSRDrivers

Sure it depends on how the driver is written…
Sure the IOCTL function code doesn’t make any difference…

…what might still make a difference though is the presence or absence of CreateFile parameter FILE_FLAG_OVERLAPPED

Marcel Ruedinger
datronicsoft

Marcel nailed it. The ioctl code and the driver architecture do not matter in this case. Without FILE_FLAG_OVERLAPPED in the CreateFile call, regardless of how the driver is written, the operating system will only allow one outstanding I/O operation at a time on that file handle. It doesn’t matter how many threads you have. All other calls will block until the first completes.

Good pickup, guys. I bet that?s it.

I foolishly assumed this want a user-mode issue!

Peter
OSR
@OSRDrivers

By design. You opened a synchronous/serialized handle. If you want multiple simultaneous io, open it with file flag overlapped.

Bent from my phone


From: xxxxx@lists.osr.com on behalf of xxxxx@gmail.com
Sent: Thursday, March 15, 2018 6:27:49 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Can a DeviceIoControl block?

I have multiple threads that use the same HANDLE for a device object,
created by:
CreateFile(_T(…), GENERIC_READ | GENERIC_WRITE,
0, NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, NULL);

Now i noticed if a DeviceIoControl() of a thread blocks and waits for an event, other threads are blocked whenever they use DeviceIoControl, until the first thread finishes and returns to userspace.

Is this possible?


NTDEV is sponsored by OSR

Visit the list online at: https:

MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
Details at https:

To unsubscribe, visit the List Server section of OSR Online at https:</https:></https:></https:>

This indeed solved the issue. FILE_FLAG_OVERLAPPED was missing, this allows me to simultaneously access the device file. Thanks!

FILE_FLAG_OVERLAPPED

https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858(v=vs.85).aspx

Sent from Mailhttps: for Windows 10

________________________________
From: xxxxx@lists.osr.com on behalf of xxxxx@gmail.com
Sent: Thursday, March 15, 2018 9:46:19 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Can a DeviceIoControl block?

I’m talking about different ioctls on the same device.
One ioctl blocks, the other ioctl just changes a flag(no syncronization mechanism over there, nothing… no blocking)

Yet, the “not-blocking” ioctl is blocked.


NTDEV is sponsored by OSR

Visit the list online at: http:

MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
Details at http:

To unsubscribe, visit the List Server section of OSR Online at http:</http:></http:></http:></https:>