Buffer Alignment Application/Driver.

Hi All,
I have a WDM function driver and my hardware has a alignment requirement of 4 bytes. Can the driver assume that if application allocated a DWORD aligned (address and size both aligned to DWORD boundary) buffers for its IO, the physical addresses that driver gets in SGL will always be DWORD aligned?

I have seen this happening but I am not sure I can count on it.
Any
– Ajitabh

Yes it will be the case that DWORD aligned in user space will be 4 byte
aligned in kernel space. But relying on a user space app to do things
correctly is never a great idea in a driver, so I hope you have a test
to see that the alignment requirements are met, and otherwise fail the
request.


Don Burn (MVP, Windows DKD)
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr

“Ajitabh Saxena” wrote in message
news:xxxxx@ntdev:

> Hi All,
> I have a WDM function driver and my hardware has a alignment requirement of 4 bytes. Can the driver assume that if application allocated a DWORD aligned (address and size both aligned to DWORD boundary) buffers for its IO, the physical addresses that driver gets in SGL will always be DWORD aligned?
>
> I have seen this happening but I am not sure I can count on it.
> Any
> – Ajitabh

Information from ESET Smart Security, version of virus
signature database 4852 (20100209)


The message was checked by ESET Smart Security.

http://www.eset.com

Ajitabh Saxena wrote:

I have a WDM function driver and my hardware has a alignment requirement of 4 bytes. Can the driver assume that if application allocated a DWORD aligned (address and size both aligned to DWORD boundary) buffers for its IO, the physical addresses that driver gets in SGL will always be DWORD aligned?

The lower 12 bits of the virtual and physical addresses are identical.
For any alignment less than or equal to 4k bytes, the alignment will be
the same.


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

Thanks Tim.
One more question for my understanding.

Are the lower 12 bits identical because of the 4K page size and the way the page tables are used for tranlating the virtual address to physical address? If the page size increases then I believe these bits will also increase. Correct?

–Aj

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Tim Roberts
Sent: Tuesday, February 09, 2010 12:24 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] Buffer Alignment Application/Driver.

Ajitabh Saxena wrote:

I have a WDM function driver and my hardware has a alignment requirement of 4 bytes. Can the driver assume that if application allocated a DWORD aligned (address and size both aligned to DWORD boundary) buffers for its IO, the physical addresses that driver gets in SGL will always be DWORD aligned?

The lower 12 bits of the virtual and physical addresses are identical.
For any alignment less than or equal to 4k bytes, the alignment will be
the same.


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


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

>driver assume that if application allocated a DWORD aligned (address and size both aligned to

DWORD boundary) buffers for its IO, the physical addresses that driver gets in SGL will always be
DWORD aligned?

Surely. DWORD-aligned pointer means DWORD-aligned in-page offset, which is what you need.


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

>tranlating the virtual address to physical address? If the page size increases then I believe these bits

will also increase. Correct?

Yes.


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