Hi,
In the volume filter driver, I get the data in IRP_MJ_WRITE and send them to user mode using TDI.In the user mode app I try to write the data in a file on the other volume, but it always stop just in the WriteFile function.Is that reentrancy?
thanks.
Not useful, perhaps [dinner beckons]- but when I have questions like this, I use a debugger and start testing such hypotheses [if there’s reentrancy, a breakpoint or three ought to tell me pretty quickly]. If there is a problem, now that I have a stack to look at I can at least ask more focused questions…
Thanks,
but I just want to know if I write to another volume, Is there any possibility to cause reentrancy?
I am afraid you are mixing up re-entrancy and concurrency…
For example, let’s say your code that runs at IRQL==PASSIVE_LEVEL calls IoCallDriver(), and interrupt occurs. ISR queues a DPC, which will be executed before control is returned to your code, and this DPC calls IoCallDriver() (this call has absolutely nothing to do with your driver). Both ISR and DPC routine will get executed in context of your thread - it has to process IoCallDriver() call made by DPC routine before it has a chance to return to processing the original call to IoCallDriver() . In such case we can say that IoCallDriver() was re-entered, although a client routine that called IoCallDriver() was not .
You situation is somehow different. When your IRP_MJ_WRITE handler sends data to the app, it executes in context of thread X, but when it processes IRP_MJ_WRITE that results from your app’s to to WriteFile(), it executes either in context of some other thread, or in context of the thread X *AFTER* the original call to IRP_MJ_WRITE handler that thread X processes returns control. Therefore, this is not re-entrancy but (possible) concurrency…
Anton Bassov
Thanks Bassov,
Yes maybe I mix the re-entrancy and concurrency…
I got the data in IRP_MJ_WRITE and insert it in a list in deviceExtension, in another system thread I get the data from the list and send them to user app using TDI.I create the system thread in AddDevice. In user app I get the data from TDI and write them to file.Is that the *concurrency*?
> Is that the *concurrency*?
As I told you already, concurrency meants two threads execute the same code simultaneously…
Therefore, it depends on whether IRP_MJ_WRITE finishes with the first IRP by the time the second one arrives…
Anton Bassov
Thanks,yes the second irp may arrive before the first one is finished.But how to fix it?
> Thanks,yes the second irp may arrive before the first one is finished. But how to fix it?
How to fix what??? Sorry, but we haven’t got enough info to make even a suggestion, let alone a definitive conclusion, about the reason for your problem. First of all, show us your code in IRP_MJ_WRITE handler, and let’s see wht you may possibly be doing the wrong way…
Anton Bassov
ok,
Here’s the code in my DispatchWrite:
NTSTATUS DispatchWrite(PDEVICE_OBJECT DeviceObject,PIRP Irp)
{
NTSTATUS status;
NTSTATUS orgIrpStatus;
PDEVICE_EXTENSION deviceExtension;
PIO_STACK_LOCATION pIrpStackLocation;
PBUF_NODE pBufNode = NULL;
deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
pIrpStackLocation = IoGetCurrentIrpStackLocation(Irp);
status = IoAcquireRemoveLock(&deviceExtension->RemoveLock, NULL);
status = NsFilterMakeBufNode(DeviceObject, Irp, &pBufNode);
ExInterlockedInsertTailList(
&deviceExtension->Buffer->BufferHead,
&(pBufNode->ListEntry),
&deviceExtension->BufferLock
);
KeSetEvent(&deviceExtension->RequestEvent,
IO_DISK_INCREMENT,
FALSE
);
IoSkipCurrentIrpStackLocation(Irp);
orgIrpStatus = IoCallDriver(deviceExtension->TargetDeviceObject, Irp);
IoReleaseRemoveLock(&deviceExtension->RemoveLock, NULL);
return orgIrpStatus;
}
In dispatchWrite I just put the data in a BufNode and set the RequestEvent to notify the sending thread…
ok, here’s the code in my DispatchWrite. I really don’t understand why I can’t write the data in file in user app…
Is that because the concurrency problem?
Any suggestion will be appreciated!