Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results

Before Posting...
Please check out the Community Guidelines in the Announcements and Administration Category.

AlignmentMask of WORD gives DWORD aligned addresses in my Storport Miniport

Suresh_PatilSuresh_Patil Member Posts: 122

Hi,

In my storport miniport driver I am requesting a WORD alignment by setting ConfigInfo->AlignmentMask = 1.
With this I am expecting that all the physical addresses I get will be WORD aligned, i.e. last bit cleared to 0.
I just happened to check for incoming addresses, and noticed I am actually getting DWORD aligned addresses all the time (last 2 bits as 00b)!
Now of course all DWORD aligned addresses are WORD aligned too, but just curious to know the reason why I am not getting only a WORD aligned address, i.e. address ending with 10b.

Regards,
Suresh

Comments

  • Tim_RobertsTim_Roberts Member - All Emails Posts: 13,158

    I find to be a very odd question. You're getting what you asked for, but it hasn't brought you joy. ;)

    Most buffers are DWORD aligned, because the Visual C++ compiler aligns structures and variables to a 4-byte boundary by default, because Intel processors are more efficient with that. You really have to go out of your way to get a non-4-byte aligned buffer. Buffers allocated from the heap are often 32-byte aligned (although it depends on the size of the allocation).

    Tim Roberts, [email protected]
    Providenza & Boekelheide, Inc.

  • Suresh_PatilSuresh_Patil Member Posts: 122

    Thanks Tim! Well, I am joyful enough :-) but also skeptical that my code has apparently never been tested with a non-DWORD aligned address being passed to my driver. What if there is a bug lurking during processing of such addresses!
    (Of course an alternative would be to change the AlignmentMask to 3 to officially make it DWORD aligned and mask off that possibility.)

    I was wondering if there is any way (some tool or some setting) which can give me non-DWORD aligned address.

    Regards,
    Suresh

  • Peter_Viscarola_(OSR)Peter_Viscarola_(OSR) Administrator Posts: 7,505

    You're getting what you asked for, but it hasn't brought you joy

    Ah, the fate of the world, I'm afraid ;)

    P

    Peter Viscarola
    OSR
    @OSRDrivers

  • Peter_Viscarola_(OSR)Peter_Viscarola_(OSR) Administrator Posts: 7,505

    my code has apparently never been tested with a non-DWORD aligned address being passed to my driver. What if there is a bug lurking during processing of such addresses!

    Seriously? You're worrying about testing a scenario that doesn't matter. Think about it... what bug would there be in processing word-aligned but not dword-aligned addresses? If you want to make sure your hardware works with such addresses, well... fair enough... just hard-code one and test it yourself. Then you're done.

    Peter

    Peter Viscarola
    OSR
    @OSRDrivers

  • Suresh_PatilSuresh_Patil Member Posts: 122

    Thanks Peter. Actually one other post here (https://community.osr.com/discussion/291727) spooked me as the OP there is reporting that he is facing an issue with AlignmentMask of WORD but the issue goes away with QWORD.
    As I am also using WORD alignment I don't want to stumble upon something similar, especially in the field.

    Thanks for the tip of hard-coding the address. Will try that out.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Upcoming OSR Seminars
Writing WDF Drivers 21 Oct 2019 OSR Seminar Space & ONLINE
Internals & Software Drivers 18 Nov 2019 Dulles, VA
Kernel Debugging 30 Mar 2020 OSR Seminar Space
Developing Minifilters 27 Apr 2020 OSR Seminar Space & ONLINE