Re: byte alignment/dynamic memory from heap x64

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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






.



Relevant Pages

  • Marshaling problem - passing structs with pointers cross process
    ... struct passed into the xxx_Write and xxx_Read functions. ... LocalAlloc) to reserve memory and get back an IntPtr, ... address held in pData, it's the right data I wish to pass. ... On the driver side, the struct is also just fine, a, b, len and pData are ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: [PATCH 2.6.31 try 2] ehca: Tolerate dynamic memory operations and huge pages
    ... This patch implements toleration of dynamic memory operations and 16 GB ... memory operations that happened before the driver was loaded. ... if (ret) { ... +struct ehca_dir_bmap { ...
    (Linux-Kernel)
  • Re: byte alignment/dynamic memory from heap x64
    ... The 16-byte alignment for SLIST_HEADER applies only to x64/IA64, and, on ... pool allocations are always 16-bytes aligned. ... struct and when my driver is loaded I dynamically allocate memory using ... dynamic memory from the heap, so I assume that is why it didn't work. ...
    (microsoft.public.development.device.drivers)
  • [PATCH v2] v4l2_device/v4l2_subdev: final (?) version
    ... +Overview of the V4L2 driver framework ... +1) A struct for each device instance containing the device state. ... +of which only a handful of ops are commonly implemented, ... +may be NULL if the subdev driver does not support anything from that category. ...
    (Linux-Kernel)
  • [PATCH] [TRIVIAL] Fixing occurrences of "the the "
    ... Registering a driver using platform_driver_probeworks just like ... Free all pages associated with DMA buffers, the buffers and pages lists, and ... * hw - Struct containing variables accessed by shared code ... * This option is used to tune the the maximum retransmission attempts ...
    (Linux-Kernel)