Hello all, I have been lurking on these lists for quite some time absorbing their wisdom and thus far I have not needed to ask any questions of my own because I can usually find the answer after some searching; however, I have found a problem that really perplexes me.
I have a driver which creates a file object. I have a userland program that can read from and write to this device without a problem. However, I have developed a Layered Service Provider (WinSock DLL) that needs to perform some of the same actions as the user land executable. What really perplexes me is that whenever I attempt to write to my driver from within the lsp.dll, it doesn’t work because, for some reason, the Irp->MdlAddress is NULL. I was wondering where I could begin looking for the source of the problem? I am so perplexed because both elements are technically in userland, so behavior shouldn’t be different.
I have pasted relevant portions of code for reference. Please let me know if I can provide any further details. Thank you!
In the driver:
NTSTATUS drvWrite(PDEVICE_OBJECT pDeviceObject, PIRP Irp)
{
NTSTATUS ntStatus = STATUS_UNSUCCESSFUL;
PIO_STACK_LOCATION pIoStackIrp = NULL;
PCHAR pWriteDataBuffer;
DbgPrint(“drvWrite called\n”);
pIoStackIrp = IoGetCurrentIrpStackLocation(Irp);
if(NULL != pIoStackIrp && NULL != Irp && NULL != Irp->MdlAddress)
{
pWriteDataBuffer = MmGetSystemAddressForMdlSafe(Irp->MdlAddress,NormalPagePriority);
…
}
In the LSP’s DllMain:
ghFile = CreateFile(“\\.\Driver”, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
if(!ghFile)
{
mydbgprint(“ERROR: Could not open Driver for writing!\n”);
}
In the LSP’s WriteLog:
if(ghFile)
{
if(!WriteFile(ghFile,p,dwSize,&dwBytes,NULL))
{
mydbgprint(“WriteLog: Error could not write to VMDriver! Error: 0x%08x\n”,GetLastError());
}
}
This always fails due to the fact that the actual driver code always has the NULL in the Irp->MdlAddress and this returns STATUS_UNSUCCESSFUL. I can post larger portions of my code, but I would prefer to not bog everyone down with a massive chunk of code.