PIO Hello World example

I am trying to create a basic “hello world” example of
“Programmed I/O. In my drivers read entry point I have
the following synopsis of the code.

====> Kernel Code
UserBuffer = MmGetSystemAddressForMdlSafe(
Irp->MdlAddress, NormalPagePriority );
RtlCopyMemory( UserBuffer, tmp, TIME_SIZE );
KeFlushIoBuffers(Irp->MdlAddress, FALSE, TRUE);
IoCompleteRequest(Irp, IO_NO_INCREMENT);

// When I view the code in the UserBufffer at this
point its contents are OK.

=====> User Code

DriverHandle = CreateFile(“\\.\Test_Driver”,
GENERIC_READ|GENERIC_WRITE, 0, 0, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, 0);

ReadFile( DriverHandle, (unsigned char*)Time_Array,
TIME_SIZE, &BytesRead, NULL );

When I get the data back into the user space
application it is corrupted. I realize this is pretty
trivial stuff but any comments would be appreciated.
Am I missing something?
Cheers
Dave Sharp


Find your next car at http://autos.yahoo.ca

Your code doesn’t set Irp.IoStatus.Information? As this seems to be a
direct IO operation, that might not matter, but it is wrong. The
KeFlushIoBuffers routine generally does nothing, but it is harmless and
you are supposed to call it. Using RtlCopyMemory for PIO is technically
wrong, you are supposed to use the HAL READ_REGISTER_BUFFER_U* routines
instead.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Dave B. Sharp
Sent: Thursday, December 01, 2005 3:30 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] PIO Hello World example

I am trying to create a basic “hello world” example of
"Programmed I/O. In my drivers read entry point I have
the following synopsis of the code.

====> Kernel Code
UserBuffer = MmGetSystemAddressForMdlSafe(
Irp->MdlAddress, NormalPagePriority );
RtlCopyMemory( UserBuffer, tmp, TIME_SIZE );
KeFlushIoBuffers(Irp->MdlAddress, FALSE, TRUE);
IoCompleteRequest(Irp, IO_NO_INCREMENT);

// When I view the code in the UserBufffer at this
point its contents are OK.

=====> User Code

DriverHandle = CreateFile(“\\.\Test_Driver”,
GENERIC_READ|GENERIC_WRITE, 0, 0, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, 0);

ReadFile( DriverHandle, (unsigned char*)Time_Array,
TIME_SIZE, &BytesRead, NULL );

When I get the data back into the user space
application it is corrupted. I realize this is pretty
trivial stuff but any comments would be appreciated.
Am I missing something?
Cheers
Dave Sharp


Find your next car at http://autos.yahoo.ca


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@stratus.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

Did you set the Irp->IoStatus.Information to the
number of bytes you wish to return to the upper layer?

You don’t have to flush io buffer in this case.

Good luck!

Calvin Guan (Windows DDK MVP)
NetXtreme Longhorn Miniport Prime
Broadcom Corp. www.broadcom.com

— “Dave B. Sharp” wrote:

> I am trying to create a basic “hello world” example
> of
> “Programmed I/O. In my drivers read entry point I
> have
> the following synopsis of the code.
>
> ====> Kernel Code
> UserBuffer = MmGetSystemAddressForMdlSafe(
> Irp->MdlAddress, NormalPagePriority );
> RtlCopyMemory( UserBuffer, tmp, TIME_SIZE );
> KeFlushIoBuffers(Irp->MdlAddress, FALSE, TRUE);
> IoCompleteRequest(Irp, IO_NO_INCREMENT);
>
> // When I view the code in the UserBufffer at this
> point its contents are OK.
>
> =====> User Code
>
> DriverHandle = CreateFile(“\\.\Test_Driver”,
> GENERIC_READ|GENERIC_WRITE, 0, 0, OPEN_EXISTING,
> FILE_ATTRIBUTE_NORMAL, 0);
>
> ReadFile( DriverHandle, (unsigned char*)Time_Array,
> TIME_SIZE, &BytesRead, NULL );
>
> When I get the data back into the user space
> application it is corrupted. I realize this is
> pretty
> trivial stuff but any comments would be appreciated.
> Am I missing something?
> Cheers
> Dave Sharp
>
>
>
>
>
>
>
>
>
>

>
> Find your next car at http://autos.yahoo.ca
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as:
> xxxxx@yahoo.ca
> To unsubscribe send a blank email to
> xxxxx@lists.osr.com
>


Find your next car at http://autos.yahoo.ca

Thanx Mark,
Sorry, I do set the IoStatus.Information, I forgot to
include the line.
Right now I am just trying to get a proof of concept
for Direct IO without touching any hardware, thus the
RtlCopyMemory.
Cheers
Dave

— “Roddy, Mark” wrote:

> Your code doesn’t set Irp.IoStatus.Information? As
> this seems to be a
> direct IO operation, that might not matter, but it
> is wrong. The
> KeFlushIoBuffers routine generally does nothing, but
> it is harmless and
> you are supposed to call it. Using RtlCopyMemory for
> PIO is technically
> wrong, you are supposed to use the HAL
> READ_REGISTER_BUFFER_U* routines
> instead.
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf
> Of Dave B. Sharp
> Sent: Thursday, December 01, 2005 3:30 PM
> To: Windows System Software Devs Interest List
> Subject: [ntdev] PIO Hello World example
>
> I am trying to create a basic “hello world” example
> of
> “Programmed I/O. In my drivers read entry point I
> have
> the following synopsis of the code.
>
> ====> Kernel Code
> UserBuffer = MmGetSystemAddressForMdlSafe(
> Irp->MdlAddress, NormalPagePriority );
> RtlCopyMemory( UserBuffer, tmp, TIME_SIZE );
> KeFlushIoBuffers(Irp->MdlAddress, FALSE, TRUE);
> IoCompleteRequest(Irp, IO_NO_INCREMENT);
>
> // When I view the code in the UserBufffer at this
> point its contents are OK.
>
> =====> User Code
>
> DriverHandle = CreateFile(”\\.\Test_Driver",
> GENERIC_READ|GENERIC_WRITE, 0, 0, OPEN_EXISTING,
> FILE_ATTRIBUTE_NORMAL, 0);
>
> ReadFile( DriverHandle, (unsigned char*)Time_Array,
> TIME_SIZE, &BytesRead, NULL );
>
> When I get the data back into the user space
> application it is corrupted. I realize this is
> pretty
> trivial stuff but any comments would be appreciated.
> Am I missing something?
> Cheers
> Dave Sharp
>
>
>
>
>
>
>
>
>
>

>
> Find your next car at http://autos.yahoo.ca
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as:
> xxxxx@stratus.com
> To unsubscribe send a blank email to
> xxxxx@lists.osr.com
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: unknown
> lmsubst tag argument: ‘’
> To unsubscribe send a blank email to
> xxxxx@lists.osr.com
>


Find your next car at http://autos.yahoo.ca

Well then define “corrupted”. Some of the data is there? The buffer is
random garbage? Have you set the buffer contents to a known pattern
before the read so that you can determine if it has actually been
modified?

More stupid questions: the device is set for direct IO, right?

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Dave B. Sharp
Sent: Thursday, December 01, 2005 4:13 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] PIO Hello World example

Thanx Mark,
Sorry, I do set the IoStatus.Information, I forgot to
include the line.
Right now I am just trying to get a proof of concept
for Direct IO without touching any hardware, thus the
RtlCopyMemory.
Cheers
Dave

— “Roddy, Mark” wrote:

> Your code doesn’t set Irp.IoStatus.Information? As
> this seems to be a
> direct IO operation, that might not matter, but it
> is wrong. The
> KeFlushIoBuffers routine generally does nothing, but
> it is harmless and
> you are supposed to call it. Using RtlCopyMemory for
> PIO is technically
> wrong, you are supposed to use the HAL
> READ_REGISTER_BUFFER_U* routines
> instead.
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf
> Of Dave B. Sharp
> Sent: Thursday, December 01, 2005 3:30 PM
> To: Windows System Software Devs Interest List
> Subject: [ntdev] PIO Hello World example
>
> I am trying to create a basic “hello world” example
> of
> “Programmed I/O. In my drivers read entry point I
> have
> the following synopsis of the code.
>
> ====> Kernel Code
> UserBuffer = MmGetSystemAddressForMdlSafe(
> Irp->MdlAddress, NormalPagePriority );
> RtlCopyMemory( UserBuffer, tmp, TIME_SIZE );
> KeFlushIoBuffers(Irp->MdlAddress, FALSE, TRUE);
> IoCompleteRequest(Irp, IO_NO_INCREMENT);
>
> // When I view the code in the UserBufffer at this
> point its contents are OK.
>
> =====> User Code
>
> DriverHandle = CreateFile(”\\.\Test_Driver",
> GENERIC_READ|GENERIC_WRITE, 0, 0, OPEN_EXISTING,
> FILE_ATTRIBUTE_NORMAL, 0);
>
> ReadFile( DriverHandle, (unsigned char*)Time_Array,
> TIME_SIZE, &BytesRead, NULL );
>
> When I get the data back into the user space
> application it is corrupted. I realize this is
> pretty
> trivial stuff but any comments would be appreciated.
> Am I missing something?
> Cheers
> Dave Sharp
>
>
>
>
>
>
>
>
>
>

>
> Find your next car at http://autos.yahoo.ca
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as:
> xxxxx@stratus.com
> To unsubscribe send a blank email to
> xxxxx@lists.osr.com
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: unknown
> lmsubst tag argument: ‘’
> To unsubscribe send a blank email to
> xxxxx@lists.osr.com
>


Find your next car at http://autos.yahoo.ca


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@stratus.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

I have put in a known pattern at the kernel level and
there is nothing decernable when it gets back to the
user level. The device is set for direct IO,

— “Roddy, Mark” wrote:

> Well then define “corrupted”. Some of the data is
> there? The buffer is
> random garbage? Have you set the buffer contents to
> a known pattern
> before the read so that you can determine if it has
> actually been
> modified?
>
> More stupid questions: the device is set for direct
> IO, right?
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf
> Of Dave B. Sharp
> Sent: Thursday, December 01, 2005 4:13 PM
> To: Windows System Software Devs Interest List
> Subject: RE: [ntdev] PIO Hello World example
>
> Thanx Mark,
> Sorry, I do set the IoStatus.Information, I forgot
> to
> include the line.
> Right now I am just trying to get a proof of concept
> for Direct IO without touching any hardware, thus
> the
> RtlCopyMemory.
> Cheers
> Dave
>
> — “Roddy, Mark” wrote:
>
> > Your code doesn’t set Irp.IoStatus.Information? As
> > this seems to be a
> > direct IO operation, that might not matter, but it
> > is wrong. The
> > KeFlushIoBuffers routine generally does nothing,
> but
> > it is harmless and
> > you are supposed to call it. Using RtlCopyMemory
> for
> > PIO is technically
> > wrong, you are supposed to use the HAL
> > READ_REGISTER_BUFFER_U* routines
> > instead.
> >
> > -----Original Message-----
> > From: xxxxx@lists.osr.com
> > [mailto:xxxxx@lists.osr.com] On
> Behalf
> > Of Dave B. Sharp
> > Sent: Thursday, December 01, 2005 3:30 PM
> > To: Windows System Software Devs Interest List
> > Subject: [ntdev] PIO Hello World example
> >
> > I am trying to create a basic “hello world”
> example
> > of
> > “Programmed I/O. In my drivers read entry point I
> > have
> > the following synopsis of the code.
> >
> > ====> Kernel Code
> > UserBuffer = MmGetSystemAddressForMdlSafe(
> > Irp->MdlAddress, NormalPagePriority );
> > RtlCopyMemory( UserBuffer, tmp, TIME_SIZE );
> > KeFlushIoBuffers(Irp->MdlAddress, FALSE,
> TRUE);
> > IoCompleteRequest(Irp, IO_NO_INCREMENT);
> >
> > // When I view the code in the UserBufffer at this
> > point its contents are OK.
> >
> > =====> User Code
> >
> > DriverHandle = CreateFile(”\\.\Test_Driver",
> > GENERIC_READ|GENERIC_WRITE, 0, 0, OPEN_EXISTING,
> > FILE_ATTRIBUTE_NORMAL, 0);
> >
> > ReadFile( DriverHandle, (unsigned
> char*)Time_Array,
> > TIME_SIZE, &BytesRead, NULL );
> >
> > When I get the data back into the user space
> > application it is corrupted. I realize this is
> > pretty
> > trivial stuff but any comments would be
> appreciated.
> > Am I missing something?
> > Cheers
> > Dave Sharp
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
>

> >
> > Find your next car at http://autos.yahoo.ca
> >
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
> > http://www.osronline.com/article.cfm?id=256
> >
> > You are currently subscribed to ntdev as:
> > xxxxx@stratus.com
> > To unsubscribe send a blank email to
> > xxxxx@lists.osr.com
> >
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
> > http://www.osronline.com/article.cfm?id=256
> >
> > You are currently subscribed to ntdev as: unknown
> > lmsubst tag argument: ‘’
> > To unsubscribe send a blank email to
> > xxxxx@lists.osr.com
> >
>
>
>
>
>
>
>
>

>
> Find your next car at http://autos.yahoo.ca
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as:
> xxxxx@stratus.com
> To unsubscribe send a blank email to
> xxxxx@lists.osr.com
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: unknown
> lmsubst tag argument: ‘’
> To unsubscribe send a blank email to
> xxxxx@lists.osr.com
>

__________________________________________________________
Find your next car at http://autos.yahoo.ca

I did set the Irp->IoStatus.Information to the number
of bytes and I flushed just to make sure.
Thanx
Dave

— Calvin Guan wrote:

> Did you set the Irp->IoStatus.Information to the
> number of bytes you wish to return to the upper
> layer?
>
> You don’t have to flush io buffer in this case.
>
> Good luck!
>
> Calvin Guan (Windows DDK MVP)
> NetXtreme Longhorn Miniport Prime
> Broadcom Corp. www.broadcom.com
>
>
>
> — “Dave B. Sharp” wrote:
>
> > I am trying to create a basic “hello world”
> example
> > of
> > “Programmed I/O. In my drivers read entry point I
> > have
> > the following synopsis of the code.
> >
> > ====> Kernel Code
> > UserBuffer = MmGetSystemAddressForMdlSafe(
> > Irp->MdlAddress, NormalPagePriority );
> > RtlCopyMemory( UserBuffer, tmp, TIME_SIZE );
> > KeFlushIoBuffers(Irp->MdlAddress, FALSE,
> TRUE);
> > IoCompleteRequest(Irp, IO_NO_INCREMENT);
> >
> > // When I view the code in the UserBufffer at this
> > point its contents are OK.
> >
> > =====> User Code
> >
> > DriverHandle = CreateFile(“\\.\Test_Driver”,
> > GENERIC_READ|GENERIC_WRITE, 0, 0, OPEN_EXISTING,
> > FILE_ATTRIBUTE_NORMAL, 0);
> >
> > ReadFile( DriverHandle, (unsigned
> char*)Time_Array,
> > TIME_SIZE, &BytesRead, NULL );
> >
> > When I get the data back into the user space
> > application it is corrupted. I realize this is
> > pretty
> > trivial stuff but any comments would be
> appreciated.
> > Am I missing something?
> > Cheers
> > Dave Sharp
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
>

> >
> > Find your next car at http://autos.yahoo.ca
> >
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
> > http://www.osronline.com/article.cfm?id=256
> >
> > You are currently subscribed to ntdev as:
> > xxxxx@yahoo.ca
> > To unsubscribe send a blank email to
> > xxxxx@lists.osr.com
> >
>
>
>
>
>
>
>
>

>
> Find your next car at http://autos.yahoo.ca
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as:
> xxxxx@yahoo.ca
> To unsubscribe send a blank email to
> xxxxx@lists.osr.com
>

__________________________________________________________
Find your next car at http://autos.yahoo.ca