Increase alignment to size of pointer if the alignment is too small.

Some modules do not align data at least to size of pointer, they uses a
smaller alignment, but our pointer should be aligned to its native
boundary, otherwise on some platforms, hardware alignment checking
will cause bus error.
This commit is contained in:
David Xu 2014-02-22 11:06:48 +00:00
parent 8c91e67c8c
commit eab68f795a

View File

@ -73,10 +73,8 @@ malloc_aligned(size_t size, size_t align)
{
void *mem, *res;
if (align & (sizeof(void *) -1)) {
rtld_fdputstr(STDERR_FILENO, "Invalid alignment\n");
_exit(1);
}
if (align < sizeof(void *))
align = sizeof(void *);
mem = xmalloc(size + sizeof(void *) + align - 1);
res = (void *)round((uintptr_t)mem + sizeof(void *), align);