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

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

More Info on Driver Writing and Debugging


The free OSR Learning Library has more than 50 articles on a wide variety of topics about writing and debugging device drivers and Minifilters. From introductory level to advanced. All the articles have been recently reviewed and updated, and are written using the clear and definitive style you've come to expect from OSR over the years.


Check out The OSR Learning Library at: https://www.osr.com/osr-learning-library/


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,489

    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,893

    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,893

    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
OSR has suspended in-person seminars due to the Covid-19 outbreak. But, don't miss your training! Attend via the internet instead!
Kernel Debugging 30 Mar 2020 OSR Seminar Space
Developing Minifilters 15 Jun 2020 LIVE ONLINE
Writing WDF Drivers 22 June 2020 LIVE ONLINE
Internals & Software Drivers 28 Sept 2020 Dulles, VA