Hey There,
If buffered I/O is being used and the
Parameters.DeviceIoControl.OutputBufferLength is > 0 while
Parameters.DeviceIoControl.InputBufferLength equals 0, the data should
be in AssociatedIrp.SystemBuffer. I create a variable IoBuffer that
equals AssociatedIrp.SystemBuffer and try to read the data in IoBuffer.
When this is executed, it generates a 0XC0000005 error, which is an
Access Violation Error. If the data should be there, what would cause
it to create that error?

Thanks,
Jay

Re: IoBuffer Causing Freeze by anton

anton
Mon Aug 07 17:03:16 CDT 2006

Hi mate

Could you please show us your code - I just wonder what you are doing
and how
you are doing it.

Anton Bassov

patelj27b@gmail.com wrote:
> Hey There,
> If buffered I/O is being used and the
> Parameters.DeviceIoControl.OutputBufferLength is > 0 while
> Parameters.DeviceIoControl.InputBufferLength equals 0, the data should
> be in AssociatedIrp.SystemBuffer. I create a variable IoBuffer that
> equals AssociatedIrp.SystemBuffer and try to read the data in IoBuffer.
> When this is executed, it generates a 0XC0000005 error, which is an
> Access Violation Error. If the data should be there, what would cause
> it to create that error?
>
> Thanks,
> Jay


Re: IoBuffer Causing Freeze by Don

Don
Mon Aug 07 17:05:30 CDT 2006

There is no data in the buffer until you put it there since your
InputBufferLength equals 0. You should be writing to the buffer, not
reading it.


--
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
http://www.windrvr.com
Remove StopSpam from the email to reply



<patelj27b@gmail.com> wrote in message
news:1154987157.944330.274450@b28g2000cwb.googlegroups.com...
> Hey There,
> If buffered I/O is being used and the
> Parameters.DeviceIoControl.OutputBufferLength is > 0 while
> Parameters.DeviceIoControl.InputBufferLength equals 0, the data should
> be in AssociatedIrp.SystemBuffer. I create a variable IoBuffer that
> equals AssociatedIrp.SystemBuffer and try to read the data in IoBuffer.
> When this is executed, it generates a 0XC0000005 error, which is an
> Access Violation Error. If the data should be there, what would cause
> it to create that error?
>
> Thanks,
> Jay
>



Re: IoBuffer Causing Freeze by anton

anton
Mon Aug 07 19:23:53 CDT 2006

Hi Don

> There is no data in the buffer until you put it there since your
> InputBufferLength equals 0. You should be writing to the buffer, not
> reading it.

It does not really matter - no matter what you do, you must be able to
access a system buffer without raising access violation. Therefore, we
need to see the what he does and how he does it - apparently, he has
made quite a few errors....

Anton Bassov


Don Burn wrote:
> There is no data in the buffer until you put it there since your
> InputBufferLength equals 0. You should be writing to the buffer, not
> reading it.
>
>
> --
> Don Burn (MVP, Windows DDK)
> Windows 2k/XP/2k3 Filesystem and Driver Consulting
> http://www.windrvr.com
> Remove StopSpam from the email to reply
>
>
>
> <patelj27b@gmail.com> wrote in message
> news:1154987157.944330.274450@b28g2000cwb.googlegroups.com...
> > Hey There,
> > If buffered I/O is being used and the
> > Parameters.DeviceIoControl.OutputBufferLength is > 0 while
> > Parameters.DeviceIoControl.InputBufferLength equals 0, the data should
> > be in AssociatedIrp.SystemBuffer. I create a variable IoBuffer that
> > equals AssociatedIrp.SystemBuffer and try to read the data in IoBuffer.
> > When this is executed, it generates a 0XC0000005 error, which is an
> > Access Violation Error. If the data should be there, what would cause
> > it to create that error?
> >
> > Thanks,
> > Jay
> >


Re: IoBuffer Causing Freeze by Jay

Jay
Tue Aug 08 09:10:16 CDT 2006

Hey There,
The offending code segments look like this:


NTSTATUS TDIIoControlInternal(PDEVICE_OBJECT DeviceObject, PIRP Irp)
{
NTSTATUS NtStatus = STATUS_SUCCESS;
PEXAMPLE_FILTER_EXTENSION pFilterDevContext =
(PEXAMPLE_FILTER_EXTENSION)DeviceObject->DeviceExtension;
PIO_STACK_LOCATION pIoStackIrp = NULL;
PVOID IoBuffer = NULL;
UCHAR tempVal;
PUCHAR pIoBuffer;
ULONG InputLength;
ULONG OutputLength;
unsigned int i;

UNREFERENCED_PARAMETER(i);
IoBuffer = Irp->AssociatedIrp.SystemBuffer;
pIoStackIrp = IoGetCurrentIrpStackLocation(Irp);
if(pIoStackIrp)
{
pIoBuffer = (PUCHAR)IoBuffer;
tempVal = *pIoBuffer;
InputLength =
pIoStackIrp->Parameters.DeviceIoControl.InputBufferLength;
OutputLength =
pIoStackIrp->Parameters.DeviceIoControl.OutputBufferLength;

if((OutputLength > 0) && (OutputLength < 1000))
{
DbgPrint("OutputLength = %d\n",OutputLength);

if(OutputLength > 100)
{
__try
{
ProbeForRead( IoBuffer, OutputLength, sizeof( UCHAR ) );
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
NtStatus = GetExceptionCode();
Irp->IoStatus.Status = NtStatus;
IoCompleteRequest( Irp, IO_NO_INCREMENT );
return NtStatus;
}
DbgPrint(("In If\n"));
for(i = 0;i < OutputLength;i++)
{
__try
{
DbgPrint("IoBuffer[%d]=%02x\n",i,pIoBuffer[i]);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
NtStatus = GetExceptionCode();
DbgPrint("****OutputLength= %d ****\n",OutputLength);
DbgPrint("****InputLength= %d ****\n",InputLength);
DbgPrint("*****Error = 0X%08X*****\n",NtStatus);
break;
}
}
}
}
}

IoSkipCurrentIrpStackLocation(Irp);
ASSERT(KeGetCurrentIrql() <= DISPATCH_LEVEL);
NtStatus = IoCallDriver(pFilterDevContext->pNextDeviceInChain, Irp);
return NtStatus;
}

Inside DriverEntry:

pDriverObject->MajorFunction[IRP_MJ_CLEANUP] = TDICleanUp;
pDriverObject->MajorFunction[IRP_MJ_CLOSE] = TDIClose;
pDriverObject->MajorFunction[IRP_MJ_CREATE] = TDICreate;
pDriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = TDIIoControl;
pDriverObject->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL] =
TDIIoControlInternal;
pDriverObject->MajorFunction[IRP_MJ_READ] = TDIRead;
pDriverObject->MajorFunction[IRP_MJ_WRITE] = TDIWrite;

pDriverObject->DriverUnload = TDIUnload;

pFilterDeviceContext =
(PEXAMPLE_FILTER_EXTENSION)pDeviceObject->DeviceExtension;

ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL);
currStatus = IoGetDeviceObjectPointer(
&usDeviceToFilter,FILE_READ_DATA,&pFileObject,&pNewDeviceObj);

if(currStatus != STATUS_SUCCESS)
{
DbgPrint("IoGetDeviceObjectPointer was not successful\n");
return currStatus;
}

ASSERT(KeGetCurrentIrql() <= DISPATCH_LEVEL);
pFilterDeviceContext->pNextDeviceInChain =
IoAttachDeviceToDeviceStack(pDeviceObject, pNewDeviceObj);
if(&pFilterDeviceContext->pNextDeviceInChain == NULL)
{
IoDeleteDevice(pDeviceObject);
}
else
{
pFilteredDevice = pFilterDeviceContext->pNextDeviceInChain;
pDeviceObject->Flags |= pFilteredDevice->Flags & (DO_BUFFERED_IO |
DO_DIRECT_IO);
pDeviceObject->DeviceType = pFilteredDevice->DeviceType;
pDeviceObject->Characteristics = pFilteredDevice->Characteristics;
//pDeviceObject->Flags |= DO_BUFFERED_IO;
pDeviceObject->Flags &= (~DO_DEVICE_INITIALIZING);

DbgPrint("Flag = 0x%08X\n",pDeviceObject->Flags);

}
IoCreateSymbolicLink(&usDosDeviceName, &usDriverName);



Any help would be greatly appreciated!

Thanks,
Jay

anton bassov wrote:
> Hi Don
>
> > There is no data in the buffer until you put it there since your
> > InputBufferLength equals 0. You should be writing to the buffer, not
> > reading it.
>
> It does not really matter - no matter what you do, you must be able to
> access a system buffer without raising access violation. Therefore, we
> need to see the what he does and how he does it - apparently, he has
> made quite a few errors....
>
> Anton Bassov
>
>
> Don Burn wrote:
> > There is no data in the buffer until you put it there since your
> > InputBufferLength equals 0. You should be writing to the buffer, not
> > reading it.
> >
> >
> > --
> > Don Burn (MVP, Windows DDK)
> > Windows 2k/XP/2k3 Filesystem and Driver Consulting
> > http://www.windrvr.com
> > Remove StopSpam from the email to reply
> >
> >
> >
> > <patelj27b@gmail.com> wrote in message
> > news:1154987157.944330.274450@b28g2000cwb.googlegroups.com...
> > > Hey There,
> > > If buffered I/O is being used and the
> > > Parameters.DeviceIoControl.OutputBufferLength is > 0 while
> > > Parameters.DeviceIoControl.InputBufferLength equals 0, the data should
> > > be in AssociatedIrp.SystemBuffer. I create a variable IoBuffer that
> > > equals AssociatedIrp.SystemBuffer and try to read the data in IoBuffer.
> > > When this is executed, it generates a 0XC0000005 error, which is an
> > > Access Violation Error. If the data should be there, what would cause
> > > it to create that error?
> > >
> > > Thanks,
> > > Jay
> > >


Re: IoBuffer Causing Freeze by anton

anton
Tue Aug 08 09:53:06 CDT 2006

Hi Jay

The answer is plain obvious - ProbeForRead() checks whether user-mode
buffer actually resides in the user portion of the address space, and,
if its does not, it raises STATUS_ACCESS_VIOLATION exception.
Irp->AssociatedIrp.SystemBuffer resides in the kernel address space.
Have you got any more questions why you get
STATUS_ACCESS_VIOLATION?????


However, the system gets frozen for totally different reason - you
complete IRP if status STATUS_ACCESS_VIOLATION got raised, so that
lower-level driver does not receive it. This is the reason for the
ACTUAL(!!!) freeze - if you forwarded IRP to the lower-level driver
even if STATUS_ACCESS_VIOLATION gets raised (after all, this exception
has nothing to do with lower-level drivers, don't you think????), you
would not freeze.


Furthermore, as Don have already pointed out, in order to check
whether buffer has any data to be read, you should check
Parameters.DeviceIoControl.InputBufferLength, rather than
Parameters.DeviceIoControl.OutputBufferLength



These are the bugs that I have noticed at the very first glance -
probably, there are few more left

Anton Bassov

Jay wrote:
> Hey There,
> The offending code segments look like this:
>
>
> NTSTATUS TDIIoControlInternal(PDEVICE_OBJECT DeviceObject, PIRP Irp)
> {
> NTSTATUS NtStatus = STATUS_SUCCESS;
> PEXAMPLE_FILTER_EXTENSION pFilterDevContext =
> (PEXAMPLE_FILTER_EXTENSION)DeviceObject->DeviceExtension;
> PIO_STACK_LOCATION pIoStackIrp = NULL;
> PVOID IoBuffer = NULL;
> UCHAR tempVal;
> PUCHAR pIoBuffer;
> ULONG InputLength;
> ULONG OutputLength;
> unsigned int i;
>
> UNREFERENCED_PARAMETER(i);
> IoBuffer = Irp->AssociatedIrp.SystemBuffer;
> pIoStackIrp = IoGetCurrentIrpStackLocation(Irp);
> if(pIoStackIrp)
> {
> pIoBuffer = (PUCHAR)IoBuffer;
> tempVal = *pIoBuffer;
> InputLength =
> pIoStackIrp->Parameters.DeviceIoControl.InputBufferLength;
> OutputLength =
> pIoStackIrp->Parameters.DeviceIoControl.OutputBufferLength;
>
> if((OutputLength > 0) && (OutputLength < 1000))
> {
> DbgPrint("OutputLength = %d\n",OutputLength);
>
> if(OutputLength > 100)
> {
> __try
> {
> ProbeForRead( IoBuffer, OutputLength, sizeof( UCHAR ) );
> }
> __except(EXCEPTION_EXECUTE_HANDLER)
> {
> NtStatus = GetExceptionCode();
> Irp->IoStatus.Status = NtStatus;
> IoCompleteRequest( Irp, IO_NO_INCREMENT );
> return NtStatus;
> }
> DbgPrint(("In If\n"));
> for(i = 0;i < OutputLength;i++)
> {
> __try
> {
> DbgPrint("IoBuffer[%d]=%02x\n",i,pIoBuffer[i]);
> }
> __except(EXCEPTION_EXECUTE_HANDLER)
> {
> NtStatus = GetExceptionCode();
> DbgPrint("****OutputLength= %d ****\n",OutputLength);
> DbgPrint("****InputLength= %d ****\n",InputLength);
> DbgPrint("*****Error = 0X%08X*****\n",NtStatus);
> break;
> }
> }
> }
> }
> }
>
> IoSkipCurrentIrpStackLocation(Irp);
> ASSERT(KeGetCurrentIrql() <= DISPATCH_LEVEL);
> NtStatus = IoCallDriver(pFilterDevContext->pNextDeviceInChain, Irp);
> return NtStatus;
> }
>
> Inside DriverEntry:
>
> pDriverObject->MajorFunction[IRP_MJ_CLEANUP] = TDICleanUp;
> pDriverObject->MajorFunction[IRP_MJ_CLOSE] = TDIClose;
> pDriverObject->MajorFunction[IRP_MJ_CREATE] = TDICreate;
> pDriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = TDIIoControl;
> pDriverObject->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL] =
> TDIIoControlInternal;
> pDriverObject->MajorFunction[IRP_MJ_READ] = TDIRead;
> pDriverObject->MajorFunction[IRP_MJ_WRITE] = TDIWrite;
>
> pDriverObject->DriverUnload = TDIUnload;
>
> pFilterDeviceContext =
> (PEXAMPLE_FILTER_EXTENSION)pDeviceObject->DeviceExtension;
>
> ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL);
> currStatus = IoGetDeviceObjectPointer(
> &usDeviceToFilter,FILE_READ_DATA,&pFileObject,&pNewDeviceObj);
>
> if(currStatus != STATUS_SUCCESS)
> {
> DbgPrint("IoGetDeviceObjectPointer was not successful\n");
> return currStatus;
> }
>
> ASSERT(KeGetCurrentIrql() <= DISPATCH_LEVEL);
> pFilterDeviceContext->pNextDeviceInChain =
> IoAttachDeviceToDeviceStack(pDeviceObject, pNewDeviceObj);
> if(&pFilterDeviceContext->pNextDeviceInChain == NULL)
> {
> IoDeleteDevice(pDeviceObject);
> }
> else
> {
> pFilteredDevice = pFilterDeviceContext->pNextDeviceInChain;
> pDeviceObject->Flags |= pFilteredDevice->Flags & (DO_BUFFERED_IO |
> DO_DIRECT_IO);
> pDeviceObject->DeviceType = pFilteredDevice->DeviceType;
> pDeviceObject->Characteristics = pFilteredDevice->Characteristics;
> //pDeviceObject->Flags |= DO_BUFFERED_IO;
> pDeviceObject->Flags &= (~DO_DEVICE_INITIALIZING);
>
> DbgPrint("Flag = 0x%08X\n",pDeviceObject->Flags);
>
> }
> IoCreateSymbolicLink(&usDosDeviceName, &usDriverName);
>
>
>
> Any help would be greatly appreciated!
>
> Thanks,
> Jay
>
> anton bassov wrote:
> > Hi Don
> >
> > > There is no data in the buffer until you put it there since your
> > > InputBufferLength equals 0. You should be writing to the buffer, not
> > > reading it.
> >
> > It does not really matter - no matter what you do, you must be able to
> > access a system buffer without raising access violation. Therefore, we
> > need to see the what he does and how he does it - apparently, he has
> > made quite a few errors....
> >
> > Anton Bassov
> >
> >
> > Don Burn wrote:
> > > There is no data in the buffer until you put it there since your
> > > InputBufferLength equals 0. You should be writing to the buffer, not
> > > reading it.
> > >
> > >
> > > --
> > > Don Burn (MVP, Windows DDK)
> > > Windows 2k/XP/2k3 Filesystem and Driver Consulting
> > > http://www.windrvr.com
> > > Remove StopSpam from the email to reply
> > >
> > >
> > >
> > > <patelj27b@gmail.com> wrote in message
> > > news:1154987157.944330.274450@b28g2000cwb.googlegroups.com...
> > > > Hey There,
> > > > If buffered I/O is being used and the
> > > > Parameters.DeviceIoControl.OutputBufferLength is > 0 while
> > > > Parameters.DeviceIoControl.InputBufferLength equals 0, the data should
> > > > be in AssociatedIrp.SystemBuffer. I create a variable IoBuffer that
> > > > equals AssociatedIrp.SystemBuffer and try to read the data in IoBuffer.
> > > > When this is executed, it generates a 0XC0000005 error, which is an
> > > > Access Violation Error. If the data should be there, what would cause
> > > > it to create that error?
> > > >
> > > > Thanks,
> > > > Jay
> > > >


Re: IoBuffer Causing Freeze by patelj27b

patelj27b
Tue Aug 08 10:06:29 CDT 2006

Mr. Bassov,
Thanks for the comments. The thing is, it was freezing before I
put in the ProbeForRead, and before I had the try-except block in
there. Also, I have this attached to the tcp stack through:

RtlInitUnicodeString(&usDeviceToFilter, L"\\Device\\Tcp");
currStatus = IoGetDeviceObjectPointer(
&usDeviceToFilter,FILE_READ_DATA,&pFileObject,&pNewDeviceObj);

So, when a web browser is used, the data is passed down, and the
OutputLength is large, while InputLength is 0. So, I would assume that
the data being sent down the stack is being specified by OutputLength.
Originally, the block looked like:

if(OutputLength > 100)
{
for(i = 0;i < OutputLength;i++)
{
DbgPrint("IoBuffer[%d]=%02x\n",i,pIoBuffer[i]);
}
}


and it would still freeze. Any ideas?

Thanks for all the help!
Jay





anton bassov wrote:
> Hi Jay
>
> The answer is plain obvious - ProbeForRead() checks whether user-mode
> buffer actually resides in the user portion of the address space, and,
> if its does not, it raises STATUS_ACCESS_VIOLATION exception.
> Irp->AssociatedIrp.SystemBuffer resides in the kernel address space.
> Have you got any more questions why you get
> STATUS_ACCESS_VIOLATION?????
>
>
> However, the system gets frozen for totally different reason - you
> complete IRP if status STATUS_ACCESS_VIOLATION got raised, so that
> lower-level driver does not receive it. This is the reason for the
> ACTUAL(!!!) freeze - if you forwarded IRP to the lower-level driver
> even if STATUS_ACCESS_VIOLATION gets raised (after all, this exception
> has nothing to do with lower-level drivers, don't you think????), you
> would not freeze.
>
>
> Furthermore, as Don have already pointed out, in order to check
> whether buffer has any data to be read, you should check
> Parameters.DeviceIoControl.InputBufferLength, rather than
> Parameters.DeviceIoControl.OutputBufferLength
>
>
>
> These are the bugs that I have noticed at the very first glance -
> probably, there are few more left
>
> Anton Bassov
>
> Jay wrote:
> > Hey There,
> > The offending code segments look like this:
> >
> >
> > NTSTATUS TDIIoControlInternal(PDEVICE_OBJECT DeviceObject, PIRP Irp)
> > {
> > NTSTATUS NtStatus = STATUS_SUCCESS;
> > PEXAMPLE_FILTER_EXTENSION pFilterDevContext =
> > (PEXAMPLE_FILTER_EXTENSION)DeviceObject->DeviceExtension;
> > PIO_STACK_LOCATION pIoStackIrp = NULL;
> > PVOID IoBuffer = NULL;
> > UCHAR tempVal;
> > PUCHAR pIoBuffer;
> > ULONG InputLength;
> > ULONG OutputLength;
> > unsigned int i;
> >
> > UNREFERENCED_PARAMETER(i);
> > IoBuffer = Irp->AssociatedIrp.SystemBuffer;
> > pIoStackIrp = IoGetCurrentIrpStackLocation(Irp);
> > if(pIoStackIrp)
> > {
> > pIoBuffer = (PUCHAR)IoBuffer;
> > tempVal = *pIoBuffer;
> > InputLength =
> > pIoStackIrp->Parameters.DeviceIoControl.InputBufferLength;
> > OutputLength =
> > pIoStackIrp->Parameters.DeviceIoControl.OutputBufferLength;
> >
> > if((OutputLength > 0) && (OutputLength < 1000))
> > {
> > DbgPrint("OutputLength = %d\n",OutputLength);
> >
> > if(OutputLength > 100)
> > {
> > __try
> > {
> > ProbeForRead( IoBuffer, OutputLength, sizeof( UCHAR ) );
> > }
> > __except(EXCEPTION_EXECUTE_HANDLER)
> > {
> > NtStatus = GetExceptionCode();
> > Irp->IoStatus.Status = NtStatus;
> > IoCompleteRequest( Irp, IO_NO_INCREMENT );
> > return NtStatus;
> > }
> > DbgPrint(("In If\n"));
> > for(i = 0;i < OutputLength;i++)
> > {
> > __try
> > {
> > DbgPrint("IoBuffer[%d]=%02x\n",i,pIoBuffer[i]);
> > }
> > __except(EXCEPTION_EXECUTE_HANDLER)
> > {
> > NtStatus = GetExceptionCode();
> > DbgPrint("****OutputLength= %d ****\n",OutputLength);
> > DbgPrint("****InputLength= %d ****\n",InputLength);
> > DbgPrint("*****Error = 0X%08X*****\n",NtStatus);
> > break;
> > }
> > }
> > }
> > }
> > }
> >
> > IoSkipCurrentIrpStackLocation(Irp);
> > ASSERT(KeGetCurrentIrql() <= DISPATCH_LEVEL);
> > NtStatus = IoCallDriver(pFilterDevContext->pNextDeviceInChain, Irp);
> > return NtStatus;
> > }
> >
> > Inside DriverEntry:
> >
> > pDriverObject->MajorFunction[IRP_MJ_CLEANUP] = TDICleanUp;
> > pDriverObject->MajorFunction[IRP_MJ_CLOSE] = TDIClose;
> > pDriverObject->MajorFunction[IRP_MJ_CREATE] = TDICreate;
> > pDriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = TDIIoControl;
> > pDriverObject->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL] =
> > TDIIoControlInternal;
> > pDriverObject->MajorFunction[IRP_MJ_READ] = TDIRead;
> > pDriverObject->MajorFunction[IRP_MJ_WRITE] = TDIWrite;
> >
> > pDriverObject->DriverUnload = TDIUnload;
> >
> > pFilterDeviceContext =
> > (PEXAMPLE_FILTER_EXTENSION)pDeviceObject->DeviceExtension;
> >
> > ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL);
> > currStatus = IoGetDeviceObjectPointer(
> > &usDeviceToFilter,FILE_READ_DATA,&pFileObject,&pNewDeviceObj);
> >
> > if(currStatus != STATUS_SUCCESS)
> > {
> > DbgPrint("IoGetDeviceObjectPointer was not successful\n");
> > return currStatus;
> > }
> >
> > ASSERT(KeGetCurrentIrql() <= DISPATCH_LEVEL);
> > pFilterDeviceContext->pNextDeviceInChain =
> > IoAttachDeviceToDeviceStack(pDeviceObject, pNewDeviceObj);
> > if(&pFilterDeviceContext->pNextDeviceInChain == NULL)
> > {
> > IoDeleteDevice(pDeviceObject);
> > }
> > else
> > {
> > pFilteredDevice = pFilterDeviceContext->pNextDeviceInChain;
> > pDeviceObject->Flags |= pFilteredDevice->Flags & (DO_BUFFERED_IO |
> > DO_DIRECT_IO);
> > pDeviceObject->DeviceType = pFilteredDevice->DeviceType;
> > pDeviceObject->Characteristics = pFilteredDevice->Characteristics;
> > //pDeviceObject->Flags |= DO_BUFFERED_IO;
> > pDeviceObject->Flags &= (~DO_DEVICE_INITIALIZING);
> >
> > DbgPrint("Flag = 0x%08X\n",pDeviceObject->Flags);
> >
> > }
> > IoCreateSymbolicLink(&usDosDeviceName, &usDriverName);
> >
> >
> >
> > Any help would be greatly appreciated!
> >
> > Thanks,
> > Jay
> >
> > anton bassov wrote:
> > > Hi Don
> > >
> > > > There is no data in the buffer until you put it there since your
> > > > InputBufferLength equals 0. You should be writing to the buffer, not
> > > > reading it.
> > >
> > > It does not really matter - no matter what you do, you must be able to
> > > access a system buffer without raising access violation. Therefore, we
> > > need to see the what he does and how he does it - apparently, he has
> > > made quite a few errors....
> > >
> > > Anton Bassov
> > >
> > >
> > > Don Burn wrote:
> > > > There is no data in the buffer until you put it there since your
> > > > InputBufferLength equals 0. You should be writing to the buffer, not
> > > > reading it.
> > > >
> > > >
> > > > --
> > > > Don Burn (MVP, Windows DDK)
> > > > Windows 2k/XP/2k3 Filesystem and Driver Consulting
> > > > http://www.windrvr.com
> > > > Remove StopSpam from the email to reply
> > > >
> > > >
> > > >
> > > > <patelj27b@gmail.com> wrote in message
> > > > news:1154987157.944330.274450@b28g2000cwb.googlegroups.com...
> > > > > Hey There,
> > > > > If buffered I/O is being used and the
> > > > > Parameters.DeviceIoControl.OutputBufferLength is > 0 while
> > > > > Parameters.DeviceIoControl.InputBufferLength equals 0, the data should
> > > > > be in AssociatedIrp.SystemBuffer. I create a variable IoBuffer that
> > > > > equals AssociatedIrp.SystemBuffer and try to read the data in IoBuffer.
> > > > > When this is executed, it generates a 0XC0000005 error, which is an
> > > > > Access Violation Error. If the data should be there, what would cause
> > > > > it to create that error?
> > > > >
> > > > > Thanks,
> > > > > Jay
> > > > >


Re: IoBuffer Causing Freeze by Alexander

Alexander
Tue Aug 08 10:24:07 CDT 2006

INTERNAL_DEVICE_CONTROL doesn't obey the same buffer rules as
DEVICE_CONTROL. Its stack location arguments are completely IOCTL-code
specific. They don't mean InputBufferLength, OutputBufferLength, etc.

"Jay" <patelj27b@gmail.com> wrote in message
news:1155046216.761725.144660@m73g2000cwd.googlegroups.com...
> Hey There,
> The offending code segments look like this:
>
>
> NTSTATUS TDIIoControlInternal(PDEVICE_OBJECT DeviceObject, PIRP Irp)
> {
> NTSTATUS NtStatus = STATUS_SUCCESS;
> PEXAMPLE_FILTER_EXTENSION pFilterDevContext =
> (PEXAMPLE_FILTER_EXTENSION)DeviceObject->DeviceExtension;
> PIO_STACK_LOCATION pIoStackIrp = NULL;
> PVOID IoBuffer = NULL;
> UCHAR tempVal;
> PUCHAR pIoBuffer;
> ULONG InputLength;
> ULONG OutputLength;
> unsigned int i;
>
> UNREFERENCED_PARAMETER(i);
> IoBuffer = Irp->AssociatedIrp.SystemBuffer;
> pIoStackIrp = IoGetCurrentIrpStackLocation(Irp);
> if(pIoStackIrp)
> {
> pIoBuffer = (PUCHAR)IoBuffer;
> tempVal = *pIoBuffer;
> InputLength =
> pIoStackIrp->Parameters.DeviceIoControl.InputBufferLength;
> OutputLength =
> pIoStackIrp->Parameters.DeviceIoControl.OutputBufferLength;
>
> if((OutputLength > 0) && (OutputLength < 1000))
> {
> DbgPrint("OutputLength = %d\n",OutputLength);
>
> if(OutputLength > 100)
> {
> __try
> {
> ProbeForRead( IoBuffer, OutputLength, sizeof( UCHAR ) );
> }
> __except(EXCEPTION_EXECUTE_HANDLER)
> {
> NtStatus = GetExceptionCode();
> Irp->IoStatus.Status = NtStatus;
> IoCompleteRequest( Irp, IO_NO_INCREMENT );
> return NtStatus;
> }
> DbgPrint(("In If\n"));
> for(i = 0;i < OutputLength;i++)
> {
> __try
> {
> DbgPrint("IoBuffer[%d]=%02x\n",i,pIoBuffer[i]);
> }
> __except(EXCEPTION_EXECUTE_HANDLER)
> {
> NtStatus = GetExceptionCode();
> DbgPrint("****OutputLength= %d ****\n",OutputLength);
> DbgPrint("****InputLength= %d ****\n",InputLength);
> DbgPrint("*****Error = 0X%08X*****\n",NtStatus);
> break;
> }
> }
> }
> }
> }
>
> IoSkipCurrentIrpStackLocation(Irp);
> ASSERT(KeGetCurrentIrql() <= DISPATCH_LEVEL);
> NtStatus = IoCallDriver(pFilterDevContext->pNextDeviceInChain, Irp);
> return NtStatus;
> }
>
> Inside DriverEntry:
>
> pDriverObject->MajorFunction[IRP_MJ_CLEANUP] = TDICleanUp;
> pDriverObject->MajorFunction[IRP_MJ_CLOSE] = TDIClose;
> pDriverObject->MajorFunction[IRP_MJ_CREATE] = TDICreate;
> pDriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = TDIIoControl;
> pDriverObject->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL] =
> TDIIoControlInternal;
> pDriverObject->MajorFunction[IRP_MJ_READ] = TDIRead;
> pDriverObject->MajorFunction[IRP_MJ_WRITE] = TDIWrite;
>
> pDriverObject->DriverUnload = TDIUnload;
>
> pFilterDeviceContext =
> (PEXAMPLE_FILTER_EXTENSION)pDeviceObject->DeviceExtension;
>
> ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL);
> currStatus = IoGetDeviceObjectPointer(
> &usDeviceToFilter,FILE_READ_DATA,&pFileObject,&pNewDeviceObj);
>
> if(currStatus != STATUS_SUCCESS)
> {
> DbgPrint("IoGetDeviceObjectPointer was not successful\n");
> return currStatus;
> }
>
> ASSERT(KeGetCurrentIrql() <= DISPATCH_LEVEL);
> pFilterDeviceContext->pNextDeviceInChain =
> IoAttachDeviceToDeviceStack(pDeviceObject, pNewDeviceObj);
> if(&pFilterDeviceContext->pNextDeviceInChain == NULL)
> {
> IoDeleteDevice(pDeviceObject);
> }
> else
> {
> pFilteredDevice = pFilterDeviceContext->pNextDeviceInChain;
> pDeviceObject->Flags |= pFilteredDevice->Flags & (DO_BUFFERED_IO |
> DO_DIRECT_IO);
> pDeviceObject->DeviceType = pFilteredDevice->DeviceType;
> pDeviceObject->Characteristics = pFilteredDevice->Characteristics;
> //pDeviceObject->Flags |= DO_BUFFERED_IO;
> pDeviceObject->Flags &= (~DO_DEVICE_INITIALIZING);
>
> DbgPrint("Flag = 0x%08X\n",pDeviceObject->Flags);
>
> }
> IoCreateSymbolicLink(&usDosDeviceName, &usDriverName);
>
>
>
> Any help would be greatly appreciated!
>
> Thanks,
> Jay
>
> anton bassov wrote:
>> Hi Don
>>
>> > There is no data in the buffer until you put it there since your
>> > InputBufferLength equals 0. You should be writing to the buffer, not
>> > reading it.
>>
>> It does not really matter - no matter what you do, you must be able to
>> access a system buffer without raising access violation. Therefore, we
>> need to see the what he does and how he does it - apparently, he has
>> made quite a few errors....
>>
>> Anton Bassov
>>
>>
>> Don Burn wrote:
>> > There is no data in the buffer until you put it there since your
>> > InputBufferLength equals 0. You should be writing to the buffer, not
>> > reading it.
>> >
>> >
>> > --
>> > Don Burn (MVP, Windows DDK)
>> > Windows 2k/XP/2k3 Filesystem and Driver Consulting
>> > http://www.windrvr.com
>> > Remove StopSpam from the email to reply
>> >
>> >
>> >
>> > <patelj27b@gmail.com> wrote in message
>> > news:1154987157.944330.274450@b28g2000cwb.googlegroups.com...
>> > > Hey There,
>> > > If buffered I/O is being used and the
>> > > Parameters.DeviceIoControl.OutputBufferLength is > 0 while
>> > > Parameters.DeviceIoControl.InputBufferLength equals 0, the data
>> > > should
>> > > be in AssociatedIrp.SystemBuffer. I create a variable IoBuffer that
>> > > equals AssociatedIrp.SystemBuffer and try to read the data in
>> > > IoBuffer.
>> > > When this is executed, it generates a 0XC0000005 error, which is an
>> > > Access Violation Error. If the data should be there, what would cause
>> > > it to create that error?
>> > >
>> > > Thanks,
>> > > Jay
>> > >
>



Re: IoBuffer Causing Freeze by patelj27b

patelj27b
Tue Aug 08 16:15:05 CDT 2006

Hey There,
I was looking at the IO Control Code that was part of
IO_STACK_LOCATION and looking at the different parts of it. The bits
that are for the Method are either set to 3 or 0. These values
correspond to either Buffered or Neither. The Major Code in the
IO_STACK_LOCATION is F (obviously for IRP_MJ_INTERNAL_DEVICE_CONTROL
) and the Minor Code can be either B, C, 7, 6, 2, or 1. With buffered,
I assume that means that the buffer is in AssociatedIrp.SystemBuffer.
With "Neither" I have seen it documented that the buffer would be at
Parameters.DeviceIoControl.Type3InputBuffer. Using these still give me
freezing. Any ideas anyone?

Thanks alot!
Jay

Alexander Grigoriev wrote:
> INTERNAL_DEVICE_CONTROL doesn't obey the same buffer rules as
> DEVICE_CONTROL. Its stack location arguments are completely IOCTL-code
> specific. They don't mean InputBufferLength, OutputBufferLength, etc.
>
> "Jay" <patelj27b@gmail.com> wrote in message
> news:1155046216.761725.144660@m73g2000cwd.googlegroups.com...
> > Hey There,
> > The offending code segments look like this:
> >
> >
> > NTSTATUS TDIIoControlInternal(PDEVICE_OBJECT DeviceObject, PIRP Irp)
> > {
> > NTSTATUS NtStatus = STATUS_SUCCESS;
> > PEXAMPLE_FILTER_EXTENSION pFilterDevContext =
> > (PEXAMPLE_FILTER_EXTENSION)DeviceObject->DeviceExtension;
> > PIO_STACK_LOCATION pIoStackIrp = NULL;
> > PVOID IoBuffer = NULL;
> > UCHAR tempVal;
> > PUCHAR pIoBuffer;
> > ULONG InputLength;
> > ULONG OutputLength;
> > unsigned int i;
> >
> > UNREFERENCED_PARAMETER(i);
> > IoBuffer = Irp->AssociatedIrp.SystemBuffer;
> > pIoStackIrp = IoGetCurrentIrpStackLocation(Irp);
> > if(pIoStackIrp)
> > {
> > pIoBuffer = (PUCHAR)IoBuffer;
> > tempVal = *pIoBuffer;
> > InputLength =
> > pIoStackIrp->Parameters.DeviceIoControl.InputBufferLength;
> > OutputLength =
> > pIoStackIrp->Parameters.DeviceIoControl.OutputBufferLength;
> >
> > if((OutputLength > 0) && (OutputLength < 1000))
> > {
> > DbgPrint("OutputLength = %d\n",OutputLength);
> >
> > if(OutputLength > 100)
> > {
> > __try
> > {
> > ProbeForRead( IoBuffer, OutputLength, sizeof( UCHAR ) );
> > }
> > __except(EXCEPTION_EXECUTE_HANDLER)
> > {
> > NtStatus = GetExceptionCode();
> > Irp->IoStatus.Status = NtStatus;
> > IoCompleteRequest( Irp, IO_NO_INCREMENT );
> > return NtStatus;
> > }
> > DbgPrint(("In If\n"));
> > for(i = 0;i < OutputLength;i++)
> > {
> > __try
> > {
> > DbgPrint("IoBuffer[%d]=%02x\n",i,pIoBuffer[i]);
> > }
> > __except(EXCEPTION_EXECUTE_HANDLER)
> > {
> > NtStatus = GetExceptionCode();
> > DbgPrint("****OutputLength= %d ****\n",OutputLength);
> > DbgPrint("****InputLength= %d ****\n",InputLength);
> > DbgPrint("*****Error = 0X%08X*****\n",NtStatus);
> > break;
> > }
> > }
> > }
> > }
> > }
> >
> > IoSkipCurrentIrpStackLocation(Irp);
> > ASSERT(KeGetCurrentIrql() <= DISPATCH_LEVEL);
> > NtStatus = IoCallDriver(pFilterDevContext->pNextDeviceInChain, Irp);
> > return NtStatus;
> > }
> >
> > Inside DriverEntry:
> >
> > pDriverObject->MajorFunction[IRP_MJ_CLEANUP] = TDICleanUp;
> > pDriverObject->MajorFunction[IRP_MJ_CLOSE] = TDIClose;
> > pDriverObject->MajorFunction[IRP_MJ_CREATE] = TDICreate;
> > pDriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = TDIIoControl;
> > pDriverObject->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL] =
> > TDIIoControlInternal;
> > pDriverObject->MajorFunction[IRP_MJ_READ] = TDIRead;
> > pDriverObject->MajorFunction[IRP_MJ_WRITE] = TDIWrite;
> >
> > pDriverObject->DriverUnload = TDIUnload;
> >
> > pFilterDeviceContext =
> > (PEXAMPLE_FILTER_EXTENSION)pDeviceObject->DeviceExtension;
> >
> > ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL);
> > currStatus = IoGetDeviceObjectPointer(
> > &usDeviceToFilter,FILE_READ_DATA,&pFileObject,&pNewDeviceObj);
> >
> > if(currStatus != STATUS_SUCCESS)
> > {
> > DbgPrint("IoGetDeviceObjectPointer was not successful\n");
> > return currStatus;
> > }
> >
> > ASSERT(KeGetCurrentIrql() <= DISPATCH_LEVEL);
> > pFilterDeviceContext->pNextDeviceInChain =
> > IoAttachDeviceToDeviceStack(pDeviceObject, pNewDeviceObj);
> > if(&pFilterDeviceContext->pNextDeviceInChain == NULL)
> > {
> > IoDeleteDevice(pDeviceObject);
> > }
> > else
> > {
> > pFilteredDevice = pFilterDeviceContext->pNextDeviceInChain;
> > pDeviceObject->Flags |= pFilteredDevice->Flags & (DO_BUFFERED_IO |
> > DO_DIRECT_IO);
> > pDeviceObject->DeviceType = pFilteredDevice->DeviceType;
> > pDeviceObject->Characteristics = pFilteredDevice->Characteristics;
> > //pDeviceObject->Flags |= DO_BUFFERED_IO;
> > pDeviceObject->Flags &= (~DO_DEVICE_INITIALIZING);
> >
> > DbgPrint("Flag = 0x%08X\n",pDeviceObject->Flags);
> >
> > }
> > IoCreateSymbolicLink(&usDosDeviceName, &usDriverName);
> >
> >
> >
> > Any help would be greatly appreciated!
> >
> > Thanks,
> > Jay
> >
> > anton bassov wrote:
> >> Hi Don
> >>
> >> > There is no data in the buffer until you put it there since your
> >> > InputBufferLength equals 0. You should be writing to the buffer, not
> >> > reading it.
> >>
> >> It does not really matter - no matter what you do, you must be able to
> >> access a system buffer without raising access violation. Therefore, we
> >> need to see the what he does and how he does it - apparently, he has
> >> made quite a few errors....
> >>
> >> Anton Bassov
> >>
> >>
> >> Don Burn wrote:
> >> > There is no data in the buffer until you put it there since your
> >> > InputBufferLength equals 0. You should be writing to the buffer, not
> >> > reading it.
> >> >
> >> >
> >> > --
> >> > Don Burn (MVP, Windows DDK)
> >> > Windows 2k/XP/2k3 Filesystem and Driver Consulting
> >> > http://www.windrvr.com
> >> > Remove StopSpam from the email to reply
> >> >
> >> >
> >> >
> >> > <patelj27b@gmail.com> wrote in message
> >> > news:1154987157.944330.274450@b28g2000cwb.googlegroups.com...
> >> > > Hey There,
> >> > > If buffered I/O is being used and the
> >> > > Parameters.DeviceIoControl.OutputBufferLength is > 0 while
> >> > > Parameters.DeviceIoControl.InputBufferLength equals 0, the data
> >> > > should
> >> > > be in AssociatedIrp.SystemBuffer. I create a variable IoBuffer that
> >> > > equals AssociatedIrp.SystemBuffer and try to read the data in
> >> > > IoBuffer.
> >> > > When this is executed, it generates a 0XC0000005 error, which is an
> >> > > Access Violation Error. If the data should be there, what would cause
> >> > > it to create that error?
> >> > >
> >> > > Thanks,
> >> > > Jay
> >> > >
> >


Re: IoBuffer Causing Freeze by Eliyas

Eliyas
Tue Aug 08 16:33:34 CDT 2006

Please take a little time to study the src\general\ioctl sample in the DDK.
It demonstrate how to define and use 4 different (buffered, direct-in,
direct-out, neither) types of ioctls, and how the input and output buffer
you provide in the call to DeviceIoControl is handled by the I/O manager and
presented to the driver.


--
-Eliyas
This posting is provided "AS IS" with no warranties, and confers no rights.
http://www.microsoft.com/whdc/driver/tips/default.mspx



Re: IoBuffer Causing Freeze by patelj27b

patelj27b
Tue Aug 08 16:44:36 CDT 2006

Hey There,
Thanks, and I will look into it in more detail. In that example
though, it just goes through IRP_MJ_DEVICE_CONTROL and not
IRP_MJ_INTERNAL_DEVICE_CONTROL. In that example, what would be te
difference between the two?

Thanks!
Jay



Eliyas Yakub [MSFT] wrote:
> Please take a little time to study the src\general\ioctl sample in the DDK.
> It demonstrate how to define and use 4 different (buffered, direct-in,
> direct-out, neither) types of ioctls, and how the input and output buffer
> you provide in the call to DeviceIoControl is handled by the I/O manager and
> presented to the driver.
>
>
> --
> -Eliyas
> This posting is provided "AS IS" with no warranties, and confers no rights.
> http://www.microsoft.com/whdc/driver/tips/default.mspx


Re: IoBuffer Causing Freeze by Eliyas

Eliyas
Tue Aug 08 18:26:13 CDT 2006

1) IRP_MJ_INTERNAL_DEVICE_CONTROL request can be sent only by a kernel-mode
module. It is meant for driver-to-driver communication. I/O manager will
never send an internal ioctl request to a driver due to an usermode action.

2) If you build an internal ioctl request using
IoBuildDeviceIoControlRequest then the I/O manager will handle the input and
output buffers (based on the IoControlCode buffer type) in the same way it
does for DeviceIoControl request.

0: kd> dt _IO_STACK_LOCATION Parameters.DeviceIoControl.
+0x004 Parameters :
+0x000 DeviceIoControl :
+0x000 OutputBufferLength : Uint4B
+0x004 InputBufferLength : Uint4B
+0x008 IoControlCode : Uint4B
+0x00c Type3InputBuffer : Ptr32 Void

3) If you build an internal ioctl request manually using IoAllocateIrp then
you can fill anything you want in the stack location parameters and send it
to the target driver. It's up to your driver and the target driver to
establish a mutual understanding of what each argument means. The I/O
manager will not interfere here.


0: kd> dt _IO_STACK_LOCATION Parameters.Other.
+0x004 Parameters :
+0x000 Others :
+0x000 Argument1 : Ptr32 Void
+0x004 Argument2 : Ptr32 Void
+0x008 Argument3 : Ptr32 Void
+0x00c Argument4 : Ptr32 Void

--
-Eliyas
This posting is provided "AS IS" with no warranties, and confers no rights.
http://www.microsoft.com/whdc/driver/tips/default.mspx



Re: IoBuffer Causing Freeze by anton

anton
Tue Aug 08 19:28:55 CDT 2006

Hi Jay

I have to repeat again - output buffer is the place where drivers
output data. Once you are on top of the stack and output buffer gets
filled by the lower-level driver, output buffer does not yet hold any
data at the time when you try to examine it. If you want to check data
in output buffer, you have to set IO completion routine before passing
IRP to the lower-level driver. By the time your completion routine gets
called, buffer will be already filled with data, so that you are able
to check it in IO completion routine.

In general, I would advise you to stop posting questions, and, instead,
read DDK documentation. This is an ABSOLUTE MUST - otherwise, you will
never learn anything . Everything you have asked us about in so far is
just fundamental DDK stuff, and DDK documentation provides not-so-bad
introduction to driver basics

Anton Bassov


patelj27b@gmail.com wrote:
> Mr. Bassov,
> Thanks for the comments. The thing is, it was freezing before I
> put in the ProbeForRead, and before I had the try-except block in
> there. Also, I have this attached to the tcp stack through:
>
> RtlInitUnicodeString(&usDeviceToFilter, L"\\Device\\Tcp");
> currStatus = IoGetDeviceObjectPointer(
> &usDeviceToFilter,FILE_READ_DATA,&pFileObject,&pNewDeviceObj);
>
> So, when a web browser is used, the data is passed down, and the
> OutputLength is large, while InputLength is 0. So, I would assume that
> the data being sent down the stack is being specified by OutputLength.
> Originally, the block looked like:
>
> if(OutputLength > 100)
> {
> for(i = 0;i < OutputLength;i++)
> {
> DbgPrint("IoBuffer[%d]=%02x\n",i,pIoBuffer[i]);
> }
> }
>
>
> and it would still freeze. Any ideas?
>
> Thanks for all the help!
> Jay
>
>
>
>
>
> anton bassov wrote:
> > Hi Jay
> >
> > The answer is plain obvious - ProbeForRead() checks whether user-mode
> > buffer actually resides in the user portion of the address space, and,
> > if its does not, it raises STATUS_ACCESS_VIOLATION exception.
> > Irp->AssociatedIrp.SystemBuffer resides in the kernel address space.
> > Have you got any more questions why you get
> > STATUS_ACCESS_VIOLATION?????
> >
> >
> > However, the system gets frozen for totally different reason - you
> > complete IRP if status STATUS_ACCESS_VIOLATION got raised, so that
> > lower-level driver does not receive it. This is the reason for the
> > ACTUAL(!!!) freeze - if you forwarded IRP to the lower-level driver
> > even if STATUS_ACCESS_VIOLATION gets raised (after all, this exception
> > has nothing to do with lower-level drivers, don't you think????), you
> > would not freeze.
> >
> >
> > Furthermore, as Don have already pointed out, in order to check
> > whether buffer has any data to be read, you should check
> > Parameters.DeviceIoControl.InputBufferLength, rather than
> > Parameters.DeviceIoControl.OutputBufferLength
> >
> >
> >
> > These are the bugs that I have noticed at the very first glance -
> > probably, there are few more left
> >
> > Anton Bassov
> >
> > Jay wrote:
> > > Hey There,
> > > The offending code segments look like this:
> > >
> > >
> > > NTSTATUS TDIIoControlInternal(PDEVICE_OBJECT DeviceObject, PIRP Irp)
> > > {
> > > NTSTATUS NtStatus = STATUS_SUCCESS;
> > > PEXAMPLE_FILTER_EXTENSION pFilterDevContext =
> > > (PEXAMPLE_FILTER_EXTENSION)DeviceObject->DeviceExtension;
> > > PIO_STACK_LOCATION pIoStackIrp = NULL;
> > > PVOID IoBuffer = NULL;
> > > UCHAR tempVal;
> > > PUCHAR pIoBuffer;
> > > ULONG InputLength;
> > > ULONG OutputLength;
> > > unsigned int i;
> > >
> > > UNREFERENCED_PARAMETER(i);
> > > IoBuffer = Irp->AssociatedIrp.SystemBuffer;
> > > pIoStackIrp = IoGetCurrentIrpStackLocation(Irp);
> > > if(pIoStackIrp)
> > > {
> > > pIoBuffer = (PUCHAR)IoBuffer;
> > > tempVal = *pIoBuffer;
> > > InputLength =
> > > pIoStackIrp->Parameters.DeviceIoControl.InputBufferLength;
> > > OutputLength =
> > > pIoStackIrp->Parameters.DeviceIoControl.OutputBufferLength;
> > >
> > > if((OutputLength > 0) && (OutputLength < 1000))
> > > {
> > > DbgPrint("OutputLength = %d\n",OutputLength);
> > >
> > > if(OutputLength > 100)
> > > {
> > > __try
> > > {
> > > ProbeForRead( IoBuffer, OutputLength, sizeof( UCHAR ) );
> > > }
> > > __except(EXCEPTION_EXECUTE_HANDLER)
> > > {
> > > NtStatus = GetExceptionCode();
> > > Irp->IoStatus.Status = NtStatus;
> > > IoCompleteRequest( Irp, IO_NO_INCREMENT );
> > > return NtStatus;
> > > }
> > > DbgPrint(("In If\n"));
> > > for(i = 0;i < OutputLength;i++)
> > > {
> > > __try
> > > {
> > > DbgPrint("IoBuffer[%d]=%02x\n",i,pIoBuffer[i]);
> > > }
> > > __except(EXCEPTION_EXECUTE_HANDLER)
> > > {
> > > NtStatus = GetExceptionCode();
> > > DbgPrint("****OutputLength= %d ****\n",OutputLength);
> > > DbgPrint("****InputLength= %d ****\n",InputLength);
> > > DbgPrint("*****Error = 0X%08X*****\n",NtStatus);
> > > break;
> > > }
> > > }
> > > }
> > > }
> > > }
> > >
> > > IoSkipCurrentIrpStackLocation(Irp);
> > > ASSERT(KeGetCurrentIrql() <= DISPATCH_LEVEL);
> > > NtStatus = IoCallDriver(pFilterDevContext->pNextDeviceInChain, Irp);
> > > return NtStatus;
> > > }
> > >
> > > Inside DriverEntry:
> > >
> > > pDriverObject->MajorFunction[IRP_MJ_CLEANUP] = TDICleanUp;
> > > pDriverObject->MajorFunction[IRP_MJ_CLOSE] = TDIClose;
> > > pDriverObject->MajorFunction[IRP_MJ_CREATE] = TDICreate;
> > > pDriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = TDIIoControl;
> > > pDriverObject->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL] =
> > > TDIIoControlInternal;
> > > pDriverObject->MajorFunction[IRP_MJ_READ] = TDIRead;
> > > pDriverObject->MajorFunction[IRP_MJ_WRITE] = TDIWrite;
> > >
> > > pDriverObject->DriverUnload = TDIUnload;
> > >
> > > pFilterDeviceContext =
> > > (PEXAMPLE_FILTER_EXTENSION)pDeviceObject->DeviceExtension;
> > >
> > > ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL);
> > > currStatus = IoGetDeviceObjectPointer(
> > > &usDeviceToFilter,FILE_READ_DATA,&pFileObject,&pNewDeviceObj);
> > >
> > > if(currStatus != STATUS_SUCCESS)
> > > {
> > > DbgPrint("IoGetDeviceObjectPointer was not successful\n");
> > > return currStatus;
> > > }
> > >
> > > ASSERT(KeGetCurrentIrql() <= DISPATCH_LEVEL);
> > > pFilterDeviceContext->pNextDeviceInChain =
> > > IoAttachDeviceToDeviceStack(pDeviceObject, pNewDeviceObj);
> > > if(&pFilterDeviceContext->pNextDeviceInChain == NULL)
> > > {
> > > IoDeleteDevice(pDeviceObject);
> > > }
> > > else
> > > {
> > > pFilteredDevice = pFilterDeviceContext->pNextDeviceInChain;
> > > pDeviceObject->Flags |= pFilteredDevice->Flags & (DO_BUFFERED_IO |
> > > DO_DIRECT_IO);
> > > pDeviceObject->DeviceType = pFilteredDevice->DeviceType;
> > > pDeviceObject->Characteristics = pFilteredDevice->Characteristics;
> > > //pDeviceObject->Flags |= DO_BUFFERED_IO;
> > > pDeviceObject->Flags &= (~DO_DEVICE_INITIALIZING);
> > >
> > > DbgPrint("Flag = 0x%08X\n",pDeviceObject->Flags);
> > >
> > > }
> > > IoCreateSymbolicLink(&usDosDeviceName, &usDriverName);
> > >
> > >
> > >
> > > Any help would be greatly appreciated!
> > >
> > > Thanks,
> > > Jay
> > >
> > > anton bassov wrote:
> > > > Hi Don
> > > >
> > > > > There is no data in the buffer until you put it there since your
> > > > > InputBufferLength equals 0. You should be writing to the buffer, not
> > > > > reading it.
> > > >
> > > > It does not really matter - no matter what you do, you must be able to
> > > > access a system buffer without raising access violation. Therefore, we
> > > > need to see the what he does and how he does it - apparently, he has
> > > > made quite a few errors....
> > > >
> > > > Anton Bassov
> > > >
> > > >
> > > > Don Burn wrote:
> > > > > There is no data in the buffer until you put it there since your
> > > > > InputBufferLength equals 0. You should be writing to the buffer, not
> > > > > reading it.
> > > > >
> > > > >
> > > > > --
> > > > > Don Burn (MVP, Windows DDK)
> > > > > Windows 2k/XP/2k3 Filesystem and Driver Consulting
> > > > > http://www.windrvr.com
> > > > > Remove StopSpam from the email to reply
> > > > >
> > > > >
> > > > >
> > > > > <patelj27b@gmail.com> wrote in message
> > > > > news:1154987157.944330.274450@b28g2000cwb.googlegroups.com...
> > > > > > Hey There,
> > > > > > If buffered I/O is being used and the
> > > > > > Parameters.DeviceIoControl.OutputBufferLength is > 0 while
> > > > > > Parameters.DeviceIoControl.InputBufferLength equals 0, the data should
> > > > > > be in AssociatedIrp.SystemBuffer. I create a variable IoBuffer that
> > > > > > equals AssociatedIrp.SystemBuffer and try to read the data in IoBuffer.
> > > > > > When this is executed, it generates a 0XC0000005 error, which is an
> > > > > > Access Violation Error. If the data should be there, what would cause
> > > > > > it to create that error?
> > > > > >
> > > > > > Thanks,
> > > > > > Jay
> > > > > >