dispatch write buffered method

Guys, i am still confuse to write the dispatchwrite/read both buffered and direct io. The example that i see in WDK pcdrv is confusing me. After searching in internet i found one understandable example from code project. So, now i try to implement dispatch write in buffered method first. I already map the?memory of pcicard using mmmapiospace and save it in device extension->regsbase. I want to write in offset of 4200 bytes, and since i am using ushort then i think the offset should be 2100.
When i run it, it gives me wrong result and when i try to debug it, it makes bsod. Could you please tell me, what is wrong with the code? Thank you.
?
NTSTATUS DispatchWrite(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp)
{
??? PVOID???Buf;?//Buffer provided by user program
??? ULONG???BufLen; //Buffer length for user provided buffer
??? LONGLONG???Offset;?//Buffer Offset
??? PVOID???DataBuf; //Buffer provided by Driver
??? ULONG???DataLen; //Buffer length for Driver Data Buffer
??? ULONG???ByteTransferred = 4;
??? PIO_STACK_LOCATION??stack;
??? PFDO_DATA???devExt;
??? NTSTATUS???status = STATUS_SUCCESS;
???
??? //Get I/o Stack Location & Device Extension
??? stack?= IoGetCurrentIrpStackLocation(Irp);
??? devExt?= (PFDO_DATA)DeviceObject->DeviceExtension;
??? //Get User Input Buffer & Length
??? BufLen?= stack->Parameters.Write.Length;
??? Offset?= stack->Parameters.Read.ByteOffset.QuadPart;
??? Buf??= (PUSHORT)(Irp->AssociatedIrp.SystemBuffer) + Offset;
??? IoAcquireRemoveLock(&devExt->RmLock, Irp);
??? ByteTransferred = BufLen;
??? RtlZeroMemory(((USHORT *)devExt->RegsBase) + 2100,ByteTransferred);
??? RtlCopyMemory(((USHORT *)devExt->RegsBase) + 2100,Buf,ByteTransferred);
??? IoReleaseRemoveLock(&devExt->RmLock, Irp);
???
?Irp->IoStatus.Status = status;
?Irp->IoStatus.Information = ByteTransferred;
?IoCompleteRequest(Irp,IO_NO_INCREMENT);
???
??? return status;
}

?

Something wrong this your code. If you use BUFFER_IO you need get a length of buffer by calling
stack->Parameters.DeviceIoControl.InputBufferLength for input buffer
and call stack->Parameters.DeviceIoControl.OutputBufferLength for output buffer

Igor Sharovar

Something else though as it is a write routine.

On Wednesday, September 16, 2009, wrote:

Something wrong this your code. If you use BUFFER_IO ?you need get a length of buffer by calling
?stack->Parameters.DeviceIoControl.InputBufferLength for input buffer
and call stack->Parameters.DeviceIoControl.OutputBufferLength for output buffer

Igor Sharovar


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer


Mark Roddy

Technically you should be using the Hal register buffer routines
instead of rtlcopy, but that is probably not your problem.

When you wrote that it gives you the wrong results, what did you mean?
And, what bsod? Using the debugger should not cause a crash unless you
used it to stomp over stack or memory.

On Wednesday, September 16, 2009, sahrizal sofian
wrote:
> Guys, i am still confuse to write the dispatchwrite/read both buffered and direct io. The example that i see in WDK pcdrv is confusing me. After searching in internet i found one understandable example from code project. So, now i try to implement dispatch write in buffered method first. I already map the?memory of pcicard using mmmapiospace and save it in device extension->regsbase. I want to write in offset of 4200 bytes, and since i am using ushort then i think the offset should be 2100.
> When i run it, it gives me wrong result and when i try to debug it, it makes bsod. Could you please tell me, what is wrong with the code? Thank you.
>
> NTSTATUS DispatchWrite(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp)
> {
> ??? PVOID???Buf;?//Buffer provided by user program
> ??? ULONG???BufLen; //Buffer length for user provided buffer
> ??? LONGLONG???Offset;?//Buffer Offset
> ??? PVOID???DataBuf; //Buffer provided by Driver
> ??? ULONG???DataLen; //Buffer length for Driver Data Buffer
> ??? ULONG???ByteTransferred = 4;
> ??? PIO_STACK_LOCATION??stack;
> ??? PFDO_DATA???devExt;
> ??? NTSTATUS???status = STATUS_SUCCESS;
>
> ??? //Get I/o Stack Location & Device Extension
> ??? stack?= IoGetCurrentIrpStackLocation(Irp);
> ??? devExt?= (PFDO_DATA)DeviceObject->DeviceExtension;
> ??? //Get User Input Buffer & Length
> ??? BufLen?= stack->Parameters.Write.Length;
> ??? Offset?= stack->Parameters.Read.ByteOffset.QuadPart;
> ??? Buf??= (PUSHORT)(Irp->AssociatedIrp.SystemBuffer) + Offset;
> ??? IoAcquireRemoveLock(&devExt->RmLock, Irp);
> ??? ByteTransferred = BufLen;
> ??? RtlZeroMemory(((USHORT *)devExt->RegsBase) + 2100,ByteTransferred);
> ??? RtlCopyMemory(((USHORT *)devExt->RegsBase) + 2100,Buf,ByteTransferred);
> ??? IoReleaseRemoveLock(&devExt->RmLock, Irp);
>
> ?Irp->IoStatus.Status = status;
> ?Irp->IoStatus.Information = ByteTransferred;
> ?IoCompleteRequest(Irp,IO_NO_INCREMENT);
>
> ??? return status;
> }
>
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer


Mark Roddy

If i debug with windbg, it gives me bsod, which is the line to ioRealeaseRemoveLock. I don’t know why, so temporary i don’t use lock and it gives no bsod when i debug it.
?
About the wrong result, there is a strange thing. I make a user application that call the driver. The application write and read in the same address. The output after running the program is not the same (wrong). But when i add a code inside the driver to know what the value after writing (using hal routines read_register_ushort), it gives me the right value. I don’t know why…

— On Wed, 9/16/09, Mark Roddy wrote:

From: Mark Roddy
Subject: [ntdev] dispatch write buffered method
To: “Windows System Software Devs Interest List”
Date: Wednesday, September 16, 2009, 12:40 PM

Technically you should be using the Hal register buffer routines
instead of rtlcopy, but that is probably not your problem.

When you wrote that it gives you the wrong results, what did you mean?
And, what bsod? Using the debugger should not cause a crash unless you
used it to stomp over stack or memory.

On Wednesday, September 16, 2009, sahrizal sofian
wrote:
> Guys, i am still confuse to write the dispatchwrite/read both buffered and direct io. The example that i see in WDK pcdrv is confusing me. After searching in internet i found one understandable example from code project. So, now i try to implement dispatch write in buffered method first. I already map the?memory of pcicard using mmmapiospace and save it in device extension->regsbase. I want to write in offset of 4200 bytes, and since i am using ushort then i think the offset should be 2100.
> When i run it, it gives me wrong result and when i try to debug it, it makes bsod. Could you please tell me, what is wrong with the code? Thank you.
>
> NTSTATUS DispatchWrite(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp)
> {
> ??? PVOID???Buf;?//Buffer provided by user program
> ??? ULONG???BufLen; //Buffer length for user provided buffer
> ??? LONGLONG???Offset;?//Buffer Offset
> ??? PVOID???DataBuf; //Buffer provided by Driver
> ??? ULONG???DataLen; //Buffer length for Driver Data Buffer
> ??? ULONG???ByteTransferred = 4;
> ??? PIO_STACK_LOCATION??stack;
> ??? PFDO_DATA???devExt;
> ??? NTSTATUS???status = STATUS_SUCCESS;
>
> ??? //Get I/o Stack Location & Device Extension
> ??? stack?= IoGetCurrentIrpStackLocation(Irp);
> ??? devExt?= (PFDO_DATA)DeviceObject->DeviceExtension;
> ??? //Get User Input Buffer & Length
> ??? BufLen?= stack->Parameters.Write.Length;
> ??? Offset?= stack->Parameters.Read.ByteOffset.QuadPart;
> ??? Buf??= (PUSHORT)(Irp->AssociatedIrp.SystemBuffer) + Offset;
> ??? IoAcquireRemoveLock(&devExt->RmLock, Irp);
> ??? ByteTransferred = BufLen;
> ??? RtlZeroMemory(((USHORT *)devExt->RegsBase) + 2100,ByteTransferred);
> ??? RtlCopyMemory(((USHORT *)devExt->RegsBase) + 2100,Buf,ByteTransferred);
> ??? IoReleaseRemoveLock(&devExt->RmLock, Irp);
>
> ?Irp->IoStatus.Status = status;
> ?Irp->IoStatus.Information = ByteTransferred;
> ?IoCompleteRequest(Irp,IO_NO_INCREMENT);
>
> ??? return status;
> }
>
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer


Mark Roddy


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Yes, you are right, i should use hal routines not the rtl routines. Thank you.

— On Wed, 9/16/09, Mark Roddy wrote:

From: Mark Roddy
Subject: [ntdev] dispatch write buffered method
To: “Windows System Software Devs Interest List”
Date: Wednesday, September 16, 2009, 12:40 PM

Technically you should be using the Hal register buffer routines
instead of rtlcopy, but that is probably not your problem.

When you wrote that it gives you the wrong results, what did you mean?
And, what bsod? Using the debugger should not cause a crash unless you
used it to stomp over stack or memory.

On Wednesday, September 16, 2009, sahrizal sofian
wrote:
> Guys, i am still confuse to write the dispatchwrite/read both buffered and direct io. The example that i see in WDK pcdrv is confusing me. After searching in internet i found one understandable example from code project. So, now i try to implement dispatch write in buffered method first. I already map the?memory of pcicard using mmmapiospace and save it in device extension->regsbase. I want to write in offset of 4200 bytes, and since i am using ushort then i think the offset should be 2100.
> When i run it, it gives me wrong result and when i try to debug it, it makes bsod. Could you please tell me, what is wrong with the code? Thank you.
>
> NTSTATUS DispatchWrite(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp)
> {
> ??? PVOID???Buf;?//Buffer provided by user program
> ??? ULONG???BufLen; //Buffer length for user provided buffer
> ??? LONGLONG???Offset;?//Buffer Offset
> ??? PVOID???DataBuf; //Buffer provided by Driver
> ??? ULONG???DataLen; //Buffer length for Driver Data Buffer
> ??? ULONG???ByteTransferred = 4;
> ??? PIO_STACK_LOCATION??stack;
> ??? PFDO_DATA???devExt;
> ??? NTSTATUS???status = STATUS_SUCCESS;
>
> ??? //Get I/o Stack Location & Device Extension
> ??? stack?= IoGetCurrentIrpStackLocation(Irp);
> ??? devExt?= (PFDO_DATA)DeviceObject->DeviceExtension;
> ??? //Get User Input Buffer & Length
> ??? BufLen?= stack->Parameters.Write.Length;
> ??? Offset?= stack->Parameters.Read.ByteOffset.QuadPart;
> ??? Buf??= (PUSHORT)(Irp->AssociatedIrp.SystemBuffer) + Offset;
> ??? IoAcquireRemoveLock(&devExt->RmLock, Irp);
> ??? ByteTransferred = BufLen;
> ??? RtlZeroMemory(((USHORT *)devExt->RegsBase) + 2100,ByteTransferred);
> ??? RtlCopyMemory(((USHORT *)devExt->RegsBase) + 2100,Buf,ByteTransferred);
> ??? IoReleaseRemoveLock(&devExt->RmLock, Irp);
>
> ?Irp->IoStatus.Status = status;
> ?Irp->IoStatus.Information = ByteTransferred;
> ?IoCompleteRequest(Irp,IO_NO_INCREMENT);
>
> ??? return status;
> }
>
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer


Mark Roddy


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

So that implies that your read routine is wrong.
Mark Roddy

On Wed, Sep 16, 2009 at 12:58 PM, sahrizal sofian
wrote:

> If i debug with windbg, it gives me bsod, which is the line to
> ioRealeaseRemoveLock. I don’t know why, so temporary i don’t use lock and it
> gives no bsod when i debug it.
>
> About the wrong result, there is a strange thing. I make a user application
> that call the driver. The application write and read in the same address.
> The output after running the program is not the same (wrong). But when i add
> a code inside the driver to know what the value after writing (using hal
> routines read_register_ushort), it gives me the right value. I don’t know
> why…
>
> — On Wed, 9/16/09, Mark Roddy wrote:
>
>
> From: Mark Roddy
> Subject: [ntdev] dispatch write buffered method
> To: “Windows System Software Devs Interest List”
> Date: Wednesday, September 16, 2009, 12:40 PM
>
>
> Technically you should be using the Hal register buffer routines
> instead of rtlcopy, but that is probably not your problem.
>
> When you wrote that it gives you the wrong results, what did you mean?
> And, what bsod? Using the debugger should not cause a crash unless you
> used it to stomp over stack or memory.
>
> On Wednesday, September 16, 2009, sahrizal sofian
> >
> wrote:
> > Guys, i am still confuse to write the dispatchwrite/read both buffered
> and direct io. The example that i see in WDK pcdrv is confusing me. After
> searching in internet i found one understandable example from code project.
> So, now i try to implement dispatch write in buffered method first. I
> already map the memory of pcicard using mmmapiospace and save it in device
> extension->regsbase. I want to write in offset of 4200 bytes, and since i am
> using ushort then i think the offset should be 2100.
> > When i run it, it gives me wrong result and when i try to debug it, it
> makes bsod. Could you please tell me, what is wrong with the code? Thank
> you.
> >
> > NTSTATUS DispatchWrite(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp)
> > {
> > PVOID Buf; //Buffer provided by user program
> > ULONG BufLen; //Buffer length for user provided buffer
> > LONGLONG Offset; //Buffer Offset
> > PVOID DataBuf; //Buffer provided by Driver
> > ULONG DataLen; //Buffer length for Driver Data Buffer
> > ULONG ByteTransferred = 4;
> > PIO_STACK_LOCATION stack;
> > PFDO_DATA devExt;
> > NTSTATUS status = STATUS_SUCCESS;
> >
> > //Get I/o Stack Location & Device Extension
> > stack = IoGetCurrentIrpStackLocation(Irp);
> > devExt = (PFDO_DATA)DeviceObject->DeviceExtension;
> > //Get User Input Buffer & Length
> > BufLen = stack->Parameters.Write.Length;
> > Offset = stack->Parameters.Read.ByteOffset.QuadPart;
> > Buf = (PUSHORT)(Irp->AssociatedIrp.SystemBuffer) + Offset;
> > IoAcquireRemoveLock(&devExt->RmLock, Irp);
> > ByteTransferred = BufLen;
> > RtlZeroMemory(((USHORT *)devExt->RegsBase) + 2100,ByteTransferred);
> > RtlCopyMemory(((USHORT *)devExt->RegsBase) +
> 2100,Buf,ByteTransferred);
> > IoReleaseRemoveLock(&devExt->RmLock, Irp);
> >
> > Irp->IoStatus.Status = status;
> > Irp->IoStatus.Information = ByteTransferred;
> > IoCompleteRequest(Irp,IO_NO_INCREMENT);
> >
> > return status;
> > }
> >
> >
> > —
> > NTDEV is sponsored by OSR
> >
> > For our schedule of WDF, WDM, debugging and other seminars visit:
> > http://www.osr.com/seminars
> >
> > To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
>
> –
> Mark Roddy
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
>
> — NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and
> other seminars visit: http://www.osr.com/seminars To unsubscribe, visit
> the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer

Here’s a thought: Is it full duplex or half duplex? If it’s full duplex
then you could quite possibly be receiving while you’re writing which can
easily bugger up a data buffer if you are using a common buffer for both
sides. If you are using METHOD_BUFFERED use separate buffers for READ and
WRITE, though the best is METHOD_DIRECT and specify separate IN and OUT
buffers.

Gary G. Little

H (952) 223-1349

C (952) 454-4629

xxxxx@comcast.net

From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Mark Roddy
Sent: Wednesday, September 16, 2009 12:17 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] dispatch write buffered method

So that implies that your read routine is wrong.

Mark Roddy

On Wed, Sep 16, 2009 at 12:58 PM, sahrizal sofian
wrote:

If i debug with windbg, it gives me bsod, which is the line to
ioRealeaseRemoveLock. I don’t know why, so temporary i don’t use lock and it
gives no bsod when i debug it.

About the wrong result, there is a strange thing. I make a user application
that call the driver. The application write and read in the same address.
The output after running the program is not the same (wrong). But when i add
a code inside the driver to know what the value after writing (using hal
routines read_register_ushort), it gives me the right value. I don’t know
why…

— On Wed, 9/16/09, Mark Roddy wrote:

From: Mark Roddy
Subject: [ntdev] dispatch write buffered method
To: “Windows System Software Devs Interest List”
Date: Wednesday, September 16, 2009, 12:40 PM

Technically you should be using the Hal register buffer routines
instead of rtlcopy, but that is probably not your problem.

When you wrote that it gives you the wrong results, what did you mean?
And, what bsod? Using the debugger should not cause a crash unless you
used it to stomp over stack or memory.

On Wednesday, September 16, 2009, sahrizal sofian
http: >
wrote:
> Guys, i am still confuse to write the dispatchwrite/read both buffered and
direct io. The example that i see in WDK pcdrv is confusing me. After
searching in internet i found one understandable example from code project.
So, now i try to implement dispatch write in buffered method first. I
already map the memory of pcicard using mmmapiospace and save it in device
extension->regsbase. I want to write in offset of 4200 bytes, and since i am
using ushort then i think the offset should be 2100.
> When i run it, it gives me wrong result and when i try to debug it, it
makes bsod. Could you please tell me, what is wrong with the code? Thank
you.
>
> NTSTATUS DispatchWrite(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp)
> {
> PVOID Buf; //Buffer provided by user program
> ULONG BufLen; //Buffer length for user provided buffer
> LONGLONG Offset; //Buffer Offset
> PVOID DataBuf; //Buffer provided by Driver
> ULONG DataLen; //Buffer length for Driver Data Buffer
> ULONG ByteTransferred = 4;
> PIO_STACK_LOCATION stack;
> PFDO_DATA devExt;
> NTSTATUS status = STATUS_SUCCESS;
>
> //Get I/o Stack Location & Device Extension
> stack = IoGetCurrentIrpStackLocation(Irp);
> devExt = (PFDO_DATA)DeviceObject->DeviceExtension;
> //Get User Input Buffer & Length
> BufLen = stack->Parameters.Write.Length;
> Offset = stack->Parameters.Read.ByteOffset.QuadPart;
> Buf = (PUSHORT)(Irp->AssociatedIrp.SystemBuffer) + Offset;
> IoAcquireRemoveLock(&devExt->RmLock, Irp);
> ByteTransferred = BufLen;
> RtlZeroMemory(((USHORT *)devExt->RegsBase) + 2100,ByteTransferred);
> RtlCopyMemory(((USHORT *)devExt->RegsBase) +
2100,Buf,ByteTransferred);
> IoReleaseRemoveLock(&devExt->RmLock, Irp);
>
> Irp->IoStatus.Status = status;
> Irp->IoStatus.Information = ByteTransferred;
> IoCompleteRequest(Irp,IO_NO_INCREMENT);
>
> return status;
> }
>
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer


Mark Roddy


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

— NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and
other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the
List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

— NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and
other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the
List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

Information from ESET Smart Security, version of virus signature
database 4430 (20090916)


The message was checked by ESET Smart Security.

http://www.eset.com</http:>

Yes, i have changed from using rtl routines into using hal routine. I compile the test application that call the readfile&writefile using WDK and using Visual Studio. The exe file that is compiled from WDK gives the correct result, for example if i write 60, it will read 60 also. But if i run the exe file compilation code of Visula Studio, it gives the wrong result. So whathever i write, when it reads the value is 52428. I don’t why, in fact, it is the same code.
?
And, about the bsod, it is IRQL_NOT_LESS_OR_EQUAL. Do i have to add PAGED_CODE() inside the function of DispatchRead or DispatchWrite to make sure that the IRQL is below Dispatch_Level?
Thanks
?
Regards
Sofian

— On Wed, 9/16/09, Mark Roddy wrote:

From: Mark Roddy
Subject: Re: [ntdev] dispatch write buffered method
To: “Windows System Software Devs Interest List”
Date: Wednesday, September 16, 2009, 1:16 PM

So that implies that your read routine is wrong.

Mark Roddy

On Wed, Sep 16, 2009 at 12:58 PM, sahrizal sofian wrote:

If i debug with windbg, it gives me bsod, which is the line to ioRealeaseRemoveLock. I don’t know why, so temporary i don’t use lock and it gives no bsod when i debug it.
?
About the wrong result, there is a strange thing. I make a user application that call the driver. The application write and read in the same address. The output after running the program is not the same (wrong). But when i add a code inside the driver to know what the value after writing (using hal routines read_register_ushort), it gives me the right value. I don’t know why…

— On Wed, 9/16/09, Mark Roddy wrote:

From: Mark Roddy
Subject: [ntdev] dispatch write buffered method
To: “Windows System Software Devs Interest List”
Date: Wednesday, September 16, 2009, 12:40 PM

Technically you should be using the Hal register buffer routines
instead of rtlcopy, but that is probably not your problem.

When you wrote that it gives you the wrong results, what did you mean?
And, what bsod? Using the debugger should not cause a crash unless you
used it to stomp over stack or memory.

On Wednesday, September 16, 2009, sahrizal sofian
wrote:
> Guys, i am still confuse to write the dispatchwrite/read both buffered and direct io. The example that i see in WDK pcdrv is confusing me. After searching in internet i found one understandable example from code project. So, now i try to implement dispatch write in buffered method first. I already map the?memory of pcicard using mmmapiospace and save it in device extension->regsbase. I want to write in offset of 4200 bytes, and since i am using ushort then i think the offset should be 2100.
> When i run it, it gives me wrong result and when i try to debug it, it makes bsod. Could you please tell me, what is wrong with the code? Thank you.
>
> NTSTATUS DispatchWrite(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp)
> {
> ??? PVOID???Buf;?//Buffer provided by user program
> ??? ULONG???BufLen; //Buffer length for user provided buffer
> ??? LONGLONG???Offset;?//Buffer Offset
> ??? PVOID???DataBuf; //Buffer provided by Driver
> ??? ULONG???DataLen; //Buffer length for Driver Data Buffer
> ??? ULONG???ByteTransferred = 4;
> ??? PIO_STACK_LOCATION??stack;
> ??? PFDO_DATA???devExt;
> ??? NTSTATUS???status = STATUS_SUCCESS;
>
> ??? //Get I/o Stack Location & Device Extension
> ??? stack?= IoGetCurrentIrpStackLocation(Irp);
> ??? devExt?= (PFDO_DATA)DeviceObject->DeviceExtension;
> ??? //Get User Input Buffer & Length
> ??? BufLen?= stack->Parameters.Write.Length;
> ??? Offset?= stack->Parameters.Read.ByteOffset.QuadPart;
> ??? Buf??= (PUSHORT)(Irp->AssociatedIrp.SystemBuffer) + Offset;
> ??? IoAcquireRemoveLock(&devExt->RmLock, Irp);
> ??? ByteTransferred = BufLen;
> ??? RtlZeroMemory(((USHORT *)devExt->RegsBase) + 2100,ByteTransferred);
> ??? RtlCopyMemory(((USHORT *)devExt->RegsBase) + 2100,Buf,ByteTransferred);
> ??? IoReleaseRemoveLock(&devExt->RmLock, Irp);
>
> ?Irp->IoStatus.Status = status;
> ?Irp->IoStatus.Information = ByteTransferred;
> ?IoCompleteRequest(Irp,IO_NO_INCREMENT);
>
> ??? return status;
> }
>
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer


Mark Roddy


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

— NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer
— NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

>And, about the bsod, it is IRQL_NOT_LESS_OR_EQUAL.

Invalid pointer deref at >= DISPATCH


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

sahrizal sofian wrote:

Yes, i have changed from using rtl routines into using hal routine. I
compile the test application that call the readfile&writefile using
WDK and using Visual Studio. The exe file that is compiled from WDK
gives the correct result, for example if i write 60, it will read 60
also. But if i run the exe file compilation code of Visula Studio, it
gives the wrong result. So whathever i write, when it reads the value
is 52428. I don’t why, in fact, it is the same code.

Did you ever try looking at that number in hex? 52428 is 0xCCCC. That’s
the value that Visual C++ uses to fill uninitialized memory. You have
an uninitialized variable in there somewhere.

And, about the bsod, it is IRQL_NOT_LESS_OR_EQUAL. Do i have to add
PAGED_CODE() inside the function of DispatchRead or DispatchWrite to
make sure that the IRQL is below Dispatch_Level?

If you need DispatchRead or DispatchWrite to be at PASSIVE_LEVEL, then
you can certainly add PAGED_CODE() inside the function. However, that
won’t change the IRQL at which the function is called. All that will do
is change your BSOD to an assertion failure. If that is your issue, you
need to chase down WHY your dispatch routines are being called at a
raised IRQL.


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