Hey there,
I most of the code of my simple driver that I am writing working,
with one exception. In the code below, when I uncomment the DbgPrint
statement that is commented out (the one that says
"DbgPrint("IoBuffer[%d]=%02x\n",i,(ULONG)IoBuffer[i]);" ) and put it
into the for loop, the machine freezes, but when take it out,
everything works fine. Any ideas as to why this is occurring?

Thanks!
Jay

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;
PUCHAR IoBuffer;
ULONG InputLength;
ULONG OutputLength;
ULONG i;

UNREFERENCED_PARAMETER(i);

pIoStackIrp = IoGetCurrentIrpStackLocation(Irp);
if(pIoStackIrp)
{
IoBuffer = Irp->AssociatedIrp.SystemBuffer;
InputLength =
pIoStackIrp->Parameters.DeviceIoControl.InputBufferLength;
OutputLength =
pIoStackIrp->Parameters.DeviceIoControl.OutputBufferLength;
if((OutputLength > 0) && (OutputLength < 1000))
{
DbgPrint("OutputLength = %d\n",OutputLength);
for(i = 0;i < OutputLength;i++)
DbgPrint("IoBuffer[%d]\n",i);
// DbgPrint("IoBuffer[%d]=%02x\n",i,(ULONG)IoBuffer[i]);
}
}
IoSkipCurrentIrpStackLocation(Irp);
ASSERT(KeGetCurrentIrql() <= DISPATCH_LEVEL);
NtStatus = IoCallDriver(pFilterDevContext->pNextDeviceInChain, Irp);
return NtStatus;
}

Re: Error Reading from Io by Thomas

Thomas
Fri Aug 04 10:33:44 CDT 2006

Use the debugger to examine IoBuffer, output length, etc. Then the machine
won't freeze. Instead, you can debug the problem.

It is not a great thing to post code for folks to examine if you haven't
already stepped through the code in the debugger yourself.

Thomas F. Divine, Windows DDK MVP

<patelj27b@gmail.com> wrote in message
news:1154704445.260416.59710@m73g2000cwd.googlegroups.com...
> Hey there,
> I most of the code of my simple driver that I am writing working,
> with one exception. In the code below, when I uncomment the DbgPrint
> statement that is commented out (the one that says
> "DbgPrint("IoBuffer[%d]=%02x\n",i,(ULONG)IoBuffer[i]);" ) and put it
> into the for loop, the machine freezes, but when take it out,
> everything works fine. Any ideas as to why this is occurring?
>
> Thanks!
> Jay
>
> 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;
> PUCHAR IoBuffer;
> ULONG InputLength;
> ULONG OutputLength;
> ULONG i;
>
> UNREFERENCED_PARAMETER(i);
>
> pIoStackIrp = IoGetCurrentIrpStackLocation(Irp);
> if(pIoStackIrp)
> {
> IoBuffer = Irp->AssociatedIrp.SystemBuffer;
> InputLength =
> pIoStackIrp->Parameters.DeviceIoControl.InputBufferLength;
> OutputLength =
> pIoStackIrp->Parameters.DeviceIoControl.OutputBufferLength;
> if((OutputLength > 0) && (OutputLength < 1000))
> {
> DbgPrint("OutputLength = %d\n",OutputLength);
> for(i = 0;i < OutputLength;i++)
> DbgPrint("IoBuffer[%d]\n",i);
> // DbgPrint("IoBuffer[%d]=%02x\n",i,(ULONG)IoBuffer[i]);
> }
> }
> IoSkipCurrentIrpStackLocation(Irp);
> ASSERT(KeGetCurrentIrql() <= DISPATCH_LEVEL);
> NtStatus = IoCallDriver(pFilterDevContext->pNextDeviceInChain, Irp);
> return NtStatus;
> }
>


Re: Error Reading from Io by Jay

Jay
Fri Aug 04 10:54:31 CDT 2006


Thomas F. Divine [DDK MVP] wrote:
> Use the debugger to examine IoBuffer, output length, etc. Then the machine
> won't freeze. Instead, you can debug the problem.
>
> It is not a great thing to post code for folks to examine if you haven't
> already stepped through the code in the debugger yourself.
>
> Thomas F. Divine, Windows DDK MVP
>
> <patelj27b@gmail.com> wrote in message
> news:1154704445.260416.59710@m73g2000cwd.googlegroups.com...
> > Hey there,
> > I most of the code of my simple driver that I am writing working,
> > with one exception. In the code below, when I uncomment the DbgPrint
> > statement that is commented out (the one that says
> > "DbgPrint("IoBuffer[%d]=%02x\n",i,(ULONG)IoBuffer[i]);" ) and put it
> > into the for loop, the machine freezes, but when take it out,
> > everything works fine. Any ideas as to why this is occurring?
> >
> > Thanks!
> > Jay
> >
> > 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;
> > PUCHAR IoBuffer;
> > ULONG InputLength;
> > ULONG OutputLength;
> > ULONG i;
> >
> > UNREFERENCED_PARAMETER(i);
> >
> > pIoStackIrp = IoGetCurrentIrpStackLocation(Irp);
> > if(pIoStackIrp)
> > {
> > IoBuffer = Irp->AssociatedIrp.SystemBuffer;
> > InputLength =
> > pIoStackIrp->Parameters.DeviceIoControl.InputBufferLength;
> > OutputLength =
> > pIoStackIrp->Parameters.DeviceIoControl.OutputBufferLength;
> > if((OutputLength > 0) && (OutputLength < 1000))
> > {
> > DbgPrint("OutputLength = %d\n",OutputLength);
> > for(i = 0;i < OutputLength;i++)
> > DbgPrint("IoBuffer[%d]\n",i);
> > // DbgPrint("IoBuffer[%d]=%02x\n",i,(ULONG)IoBuffer[i]);
> > }
> > }
> > IoSkipCurrentIrpStackLocation(Irp);
> > ASSERT(KeGetCurrentIrql() <= DISPATCH_LEVEL);
> > NtStatus = IoCallDriver(pFilterDevContext->pNextDeviceInChain, Irp);
> > return NtStatus;
> > }
> >

Mr. Divine,
If the machine crashes and creates a memory dump, then I can
examine it and see where it is going wrong with windbg. But when the
machine freezes, the only thing I can do is reboot the machine, and
comment out lines of code, see if that executes properly, then
uncomment portions to see which lines cause the problem. If there is a
way to debug a driver without going through that with windbg, I would
greatly appreciate the general directions on how to accomplish that.


Thanks!
Jay


Re: Error Reading from Io by Thomas

Thomas
Fri Aug 04 12:07:19 CDT 2006


"Jay" <patelj27b@gmail.com> wrote in message
news:1154706871.912206.131680@b28g2000cwb.googlegroups.com...
>
> Thomas F. Divine [DDK MVP] wrote:
>> Use the debugger to examine IoBuffer, output length, etc. Then the
>> machine
>> won't freeze. Instead, you can debug the problem.
>>
>> It is not a great thing to post code for folks to examine if you haven't
>> already stepped through the code in the debugger yourself.
>>
>> Thomas F. Divine, Windows DDK MVP
>>
>> <patelj27b@gmail.com> wrote in message
>> news:1154704445.260416.59710@m73g2000cwd.googlegroups.com...
>> > Hey there,
>> > I most of the code of my simple driver that I am writing working,
>> > with one exception. In the code below, when I uncomment the DbgPrint
>> > statement that is commented out (the one that says
>> > "DbgPrint("IoBuffer[%d]=%02x\n",i,(ULONG)IoBuffer[i]);" ) and put it
>> > into the for loop, the machine freezes, but when take it out,
>> > everything works fine. Any ideas as to why this is occurring?
>> >
>> > Thanks!
>> > Jay
>> >
>> > 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;
>> > PUCHAR IoBuffer;
>> > ULONG InputLength;
>> > ULONG OutputLength;
>> > ULONG i;
>> >
>> > UNREFERENCED_PARAMETER(i);
>> >
>> > pIoStackIrp = IoGetCurrentIrpStackLocation(Irp);
>> > if(pIoStackIrp)
>> > {
>> > IoBuffer = Irp->AssociatedIrp.SystemBuffer;
>> > InputLength =
>> > pIoStackIrp->Parameters.DeviceIoControl.InputBufferLength;
>> > OutputLength =
>> > pIoStackIrp->Parameters.DeviceIoControl.OutputBufferLength;
>> > if((OutputLength > 0) && (OutputLength < 1000))
>> > {
>> > DbgPrint("OutputLength = %d\n",OutputLength);
>> > for(i = 0;i < OutputLength;i++)
>> > DbgPrint("IoBuffer[%d]\n",i);
>> > // DbgPrint("IoBuffer[%d]=%02x\n",i,(ULONG)IoBuffer[i]);
>> > }
>> > }
>> > IoSkipCurrentIrpStackLocation(Irp);
>> > ASSERT(KeGetCurrentIrql() <= DISPATCH_LEVEL);
>> > NtStatus = IoCallDriver(pFilterDevContext->pNextDeviceInChain, Irp);
>> > return NtStatus;
>> > }
>> >
>
> Mr. Divine,
> If the machine crashes and creates a memory dump, then I can
> examine it and see where it is going wrong with windbg. But when the
> machine freezes, the only thing I can do is reboot the machine, and
> comment out lines of code, see if that executes properly, then
> uncomment portions to see which lines cause the problem. If there is a
> way to debug a driver without going through that with windbg, I would
> greatly appreciate the general directions on how to accomplish that.
>
>
> Thanks!
> Jay
The WinDbg Help file describes how to setup the debugger. You must have the
two machines, as specified.

If you do not have two machine debugger setup, then you will add many weeks
(perhaps months) to your development.

We try to be helpful on this list, but posting code here for review is not
replacement for the second machine that you must have to debug drivers.

Thomas F. Divine, Windows DDK MVP


Re: Error Reading from Io by Ian

Ian
Fri Aug 04 12:08:03 CDT 2006

On 04/08/2006 16:14, patelj27b@gmail.com wrote:
> Hey there,
> I most of the code of my simple driver that I am writing working,
> with one exception. In the code below, when I uncomment the DbgPrint
> statement that is commented out (the one that says
> "DbgPrint("IoBuffer[%d]=%02x\n",i,(ULONG)IoBuffer[i]);" ) and put it
> into the for loop, the machine freezes, but when take it out,
> everything works fine. Any ideas as to why this is occurring?

(snip)
> for(i = 0;i < OutputLength;i++)
> DbgPrint("IoBuffer[%d]\n",i);
> // DbgPrint("IoBuffer[%d]=%02x\n",i,(ULONG)IoBuffer[i]);

I notice you have no curly brackets in that for loop. Do you have
_exactly_ one of the two DbgPrint calls present at _all_ times? Best
stick the curly brackets in just in case!

Also, you don't need to cast IoBuffer[i] to ULONG, but it should be
harmless as ULONG is the same size as int.

Re: Error Reading from Io by Pavel

Pavel
Fri Aug 04 14:07:54 CDT 2006

"Ian Abbott" <ian@abbott.org> wrote in message news:eavuso$ig8$1$830fa7b3@news.demon.co.uk...
> (snip)
>> for(i = 0;i < OutputLength;i++)
>> DbgPrint("IoBuffer[%d]\n",i);
>> // DbgPrint("IoBuffer[%d]=%02x\n",i,(ULONG)IoBuffer[i]);
>
> I notice you have no curly brackets in that for loop. Do you have _exactly_ one of the two DbgPrint calls present at _all_
> times? Best stick the curly brackets in just in case!
>
> Also, you don't need to cast IoBuffer[i] to ULONG, but it should be harmless as ULONG is the same size as int.

In this case, this isn't relevant. Something is wrong with the pointer.

As others have noticed, the OP needs certain specific kernel skills.
There are subjects that one can learn in a few days - but unfortunately, this one is not among them. This is not an offence by
any means, just a known fact.

Rergards,
--PA