Re: byte alignment/dynamic memory from heap x64
- From: Mike L <MikeL@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 17 Sep 2007 09:50:01 -0700
Ivan,
Thank you very much for the education on this topic, it helped me resolve
and understand my problem.
Mike
"Ivan Brugiolo [MSFT]" wrote:
The 16-byte alignment for SLIST_HEADER applies only to x64/IA64, and, on.
those platforms,
pool allocations are always 16-bytes aligned.
As long as your structure is `casted` directly from the returned value from
ExAllocatePool[*],
and, you do not change the declaration of SLIST_HEADER in the WDK/DDK
headers,
the compiler will take care of that for you.
For example, this will prove the compiler right or wrong.
typedef struct _Align16 {
BYTE OneChar;
SLIST_HEADER Header;
} Align16;
C_ASSERT(FIELD_OFFSET(Align16,Header) == 0x10);
--
--
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of any included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
"Mike L" <MikeL@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:5211EC28-341F-4607-96C6-B7ACB0B2D103@xxxxxxxxxxxxxxxx
My IM driver uses SLIST_ENTRY and SLIST_HEADER(s) and they are declared in
a
struct and when my driver is loaded I dynamically allocate memory using
these
structs.
for example(not my real struct...)
struct X {
int y;
PNDIS_BUFFER pBuf;
....
SLIST_HEADER ListHeader;
SLIST_ENTRY ListEntry;
...
};
The documention for x64 states that SLIST_ENTRY and SLIST_HEADER must be
16
byte aligned.
How do I force this to happen ?
I have tried the below 3 methods( and with all 3 methods the byte
alignment
seems also to be 8 bytes instead of 16):
1) Method 1 - ExAllocatePoolWithTag with NonPagedPoolCacheAligned
2) Method 2 - pragma pack(push, 16)
3) __declspec(align(16)) - Documentation states that this will not work
for
dynamic memory from the heap, so I assume that is why it didn't work.
Any advice is appreciated, I might have a bug in my code for one of the
above methods, so I really just need someone to tell me how this is
normally
done and I can figure out the details. I saw another function
_align_memory, but did not want to link an NDIS driver to the c runtime
for
memory management, but maybe that is another alternative.
thanks,
Mike
- References:
- Re: byte alignment/dynamic memory from heap x64
- From: Ivan Brugiolo [MSFT]
- Re: byte alignment/dynamic memory from heap x64
- Prev by Date: Re: 10 Commandments for WDM driver Development
- Next by Date: Re: A bluescreen caused by tcpip.sys.
- Previous by thread: Re: byte alignment/dynamic memory from heap x64
- Next by thread: Re: byte alignment/dynamic memory from heap x64
- Index(es):
Relevant Pages
|