Windows NDIS驱动程序:在单个设备上并发读写(IRP_MJ_READ/WRITE) [英] Windows NDIS Driver: Concurrent Read/Write on a single device (IRP_MJ_READ/WRITE)

查看:601
本文介绍了Windows NDIS驱动程序:在单个设备上并发读写(IRP_MJ_READ/WRITE)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从Microsoft的ndisprot示例开始,我尝试编写NDIS协议驱动程序.从用户空间,我尝试同时读写设备(两个线程中).由于我没有收到任何数据包,因此ReadFile系统调用受阻.在这种状态下,我无法完成WriteFile系统调用.

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); 

我添加了一些调试消息,并发现甚至没有调用与IRP_MJ_WRITE(NdisprotWrite)相关的驱动程序功能!用户空间应用程序和驱动程序之间的某些内容阻止对设备\ Device \ NDISprot的并发访问.

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.

我如何同时读写文件?

推荐答案

默认情况下,每个用户模式句柄只能有一个未完成的I/O请求.打开多个句柄,或使用 FILE_FLAG_OVERLAPPED . (一旦使用FILE_FLAG_OVERLAPPED,通常还需要使用OVERLAPPED结构-通过略读.)

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.)

这篇关于Windows NDIS驱动程序:在单个设备上并发读写(IRP_MJ_READ/WRITE)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆