http://bugs.winehq.org/show_bug.cgi?id=9878
--- Comment #27 from Allan Tong actong88@gmail.com 2007-10-19 22:06:15 --- Created an attachment (id=8670) --> (http://bugs.winehq.org/attachment.cgi?id=8670) alignment patch
HL2 is requesting exactly 2MiB = 2097152 bytes. I tried allocating a bigger buffer but that didn't seem to do anything.
The attached patch is a hack that hopefully should illustrate what I'm seeing with respect to the alignment. It creates a new heap flag HEAP_TESTALIGN that when passed to HeapAlloc, will cause it to return a buffer aligned to a 16-byte boundary (actually it only does that if it has to create a new subheap, but that should be good enough for this problem). The alignment is done by adjusting the size of the subheap and the subheap header.
Actually the simplest patch would be to just add 8 bytes to the SUBHEAP structure in ntdll/heap.c, but the attached patch isolates the problem to the heap allocation in CreateVertexBuffer. In either case, I no longer get the crash in HL2.
You can adjust the padding by changing the value of ALIGN_PADDING in ntdll/heap.c. I've found that values of 8, 24, and 40 work, while values of 0, 16, 32, and 48 will cause the crash. The first set all cause the first block in the subheap to be aligned on a 16-byte boundary.