Alfred Agrell (@Alcaro) commented about dlls/ntdll/loader.c:
+ +static void *heap_alloc_aligned( unsigned size, unsigned align ) +{ + void *ptr; + DWORD_PTR mask = ((DWORD_PTR)1 << align) - 1; + + if ((ptr = RtlAllocateHeap( GetProcessHeap(), 0, size )) && ((DWORD_PTR)ptr & mask)) + { + void *new_ptr; + /* if block is not aligned, alloc a greater one which we can realign */ + + if (!(new_ptr = RtlReAllocateHeap( GetProcessHeap(), 0, ptr, mask + size ))) + RtlFreeHeap( GetProcessHeap(), 0, ptr ); + ptr = (void *)(((DWORD_PTR)new_ptr + mask) & ~mask); + } + return ptr; I'd vote make this function simply return both aligned and unaligned pointers, and have caller store them somewhere beside each other.
-- https://gitlab.winehq.org/wine/wine/-/merge_requests/7251#note_93469