Windows NDIS Driver: Concurrent Read/Write on a single device (IRP_MJ_READ/WRITE)

做~自己de王妃 提交于 2019-12-01 12:59:34

问题


Starting with the ndisprot sample from Microsoft I try to write a NDIS protocol driver. From User space I try to read and write to the device simultaneous (out of two threads). Since I don't receive any packets, the ReadFile system call blocks. I'm not able to complete a WriteFile system call in this state.

CHAR            NdisProtDevice[] = "\\\\.\\\\NDISprot";
CHAR *          pNdisProtDevice = &NdisProtDevice[0];

this.iHandle = CreateFile(pNdisProtDevice,
            GENERIC_WRITE | GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);

// Blocks, because no frames arrive

bSuccess = (BOOLEAN)ReadFile(Handle,
                             (LPVOID)pReadBuf,
                             PacketLength,
                             &BytesRead,
                             NULL);

...
// Called some seconds later from another thread, while ReadFile still blocking...
bSuccess = (BOOLEAN)WriteFile(Handle,
                              pWriteBuf,
                              PacketLength,
                              &BytesWritten,
                              NULL); 

I added some debug messages and discovered that the driver function associated with IRP_MJ_WRITE (NdisprotWrite) gets not even called! Something between the user space application and the driver blocks concurrent access to the device \Device\NDISprot.

How can I concurrent Read and Write to the file?


回答1:


By default, you can only have one outstanding I/O request per usermode handle. Either open multiple handles, or open your one handle with FILE_FLAG_OVERLAPPED. (Once you use FILE_FLAG_OVERLAPPED, you also generally need to use OVERLAPPED structures - make sure you've got the gist of it by skimming this and this.)



来源:https://stackoverflow.com/questions/16608321/windows-ndis-driver-concurrent-read-write-on-a-single-device-irp-mj-read-write

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!