Forward and dont forget the bluescreen...

Hi!
I have what i guess is a simple problem when i know the solution…

I want to make a driver that takes an IRP and just “forwards” it to the serial port. (for now that would be enough to make me happy…)

My code…

Opening the serial port:

<…>
RtlInitUnicodeString(&com_port, L"\Device\Serial0");
status = IoGetDeviceObjectPointer( &com_port,
FILE_ALL_ACCESS,
&DeviceExtension->lowerFilObject,
&DeviceExtension->lowerDeviceObject);
<…>
lowerDevice = IoAttachDeviceToDeviceStack(DeviceObject,DeviceExtension->lowerDeviceObject);
<…>
DeviceExtension->lowerDeviceObject = lowerDevice;
<…>

With portmon I can see that this sends a “IRP_MJ_CREATE” to COM1.

My DispatchWrite:

NTSTATUS DispatchWrite(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp)
{
PDEVICE_EXTENTION MyDeviceExtension;

MyDeviceExtension = DeviceObject->DeviceExtension;

IoSkipCurrentIrpStackLocation(Irp);
return IoCallDriver(MyDeviceExtension->lowerDeviceObject,Irp);
}

I immidiatly get a BSOD when I try to write from my user space app:

hCOM=CreateFile(L"\\.\ABC0",GENERIC_WRITE | GENERIC_READ,0,NULL,OPEN_EXISTING,NULL,NULL);
wchar_t *data = L"ABCDEFGHIJ";
ULONG noofbytes;
WriteFile(hCOM,(LPCVOID)data,10,&noofbytes,NULL);
CloseHandle(hCOM);

The BSOD happens sometime after I call IoCallDriver and is caused by Page fault.

Why cant I use the “forward and forget” that everyone writes about in their examples?

With Regards

Mats Soderhall
###########################################

This message has been scanned by F-Secure Anti-Virus for Microsoft Exchange.
For more information, connect to http://www.f-secure.com/

Mats Söderhäll wrote:

Hi!
I have what i guess is a simple problem when i know the solution…

I want to make a driver that takes an IRP and just “forwards” it to the serial port. (for now that would be enough to make me happy…)

Have you made sure that your driver advertises the same I/O model as
your base driver? That is, DO_BUFFERED_IO or DO_DIRECT_IO? That could
cause this problem, if the IRP is coming in with a different buffering
model than what serial expects.

I immidiatly get a BSOD when I try to write from my user space app:

> hCOM=CreateFile(L"\\.\ABC0",GENERIC_WRITE | GENERIC_READ,0,NULL,OPEN_EXISTING,NULL,NULL);
> wchar_t *data = L"ABCDEFGHIJ";
> ULONG noofbytes;
> WriteFile(hCOM,(LPCVOID)data,10,&noofbytes,NULL);
> CloseHandle(hCOM);
>
>

It isn’t related to your problem, but are you aware that your string
actually consists of 20 bytes, not 10?


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.