【问题标题】:IOCTL Driver SystemBuffer always NULLIOCTL 驱动程序 SystemBuffer 始终为 NULL
【发布时间】:2017-08-20 10:13:01
【问题描述】:

我有一个简单的结构,我想将它传递给我的驱动程序。这是结构:

typedef struct readStruct
{
  ...
} ReadStruct, *pRreadStruct;

这是我的用户模式应用程序:

DWORD dwReturn;
readStruct reader{ ... };

WriteFile(hDriver, (LPCVOID)&reader, sizeof(ReadStruct), &dwReturn, NULL);

这是我的驱动程序代码,它总是向 readStruct 返回 NULL。我做错了什么?

PIO_STACK_LOCATION pIoStackIrp = NULL;
pRreadStruct readStruct;

pIoStackIrp = IoGetCurrentIrpStackLocation(Irp);

DbgPrintEx(0, 0, "WriteBufferedIO\n");

if (pIoStackIrp)
{
    readStruct = (pRreadStruct)Irp->AssociatedIrp.SystemBuffer;
    if (readStruct)
    {
        // this is the place I never get into
        if (readStruct->ReadSize)
        {
            ReadMemOutputClient(readStruct);
        }
    }
}

【问题讨论】:

  • 你的设备使用的是缓冲 io 吗?你设置了DO_BUFFERED_IO 标志?只有在这种情况下,AssociatedIrp.SystemBuffer 才会指向用户缓冲区。还有IRP_MJ_WRITE 这不是IRP_MJ_DEVICE_CONTROL - 所以你的标题(有问题)与真正的问题不匹配
  • for IRP_MJ_WRITE - Irp->AssociatedIrp.SystemBuffer 指向系统提供缓冲区的指针,该缓冲区用作中间系统缓冲区,如果 DO_BUFFERED_IO 标志在 DeviceObject->Flags 中设置。否则,此成员设置为 NULL。
  • 为什么要在 C++ 中定义结构?现在您有三个名称(struct readStructreadStructReadStruct)都指向同一个类型。此外,我强烈建议不要将指针隐藏在 typedef 后面(并且 pRreadStruct 拼写错误)。
  • @RbMm 谢谢。坦率地说,我将它设置为 DO_DIRECT_IO,甚至没有查看 DriverEntry 例程,因为我认为问题出在我的示例代码中。如果您愿意,请回答,我可以接受它作为解决方案。
  • 我遇到了一个与此非常相似的问题,我正在使用 DO_BUFFERED_IO 宏与 PDRIVER_OBJECT->Flags 并使用 write 方法传递一个字符串。 SystemBuffer 始终为 NULLwriteDataBuffer = (PCHAR)Irp->AssociatedIrp.SystemBuffer;

标签: c++ windows struct driver ioctl


【解决方案1】:

DO_BUFFERED_IO标志应该在DeviceObject->Flags的DriverEntry中设置。

感谢@RbMm 用户指出这一点。

【讨论】:

    猜你喜欢
    • 2019-02-05
    • 2011-11-30
    • 1970-01-01
    • 2013-03-26
    • 2015-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多