svn commit: r262545 - stable/9/libexec/rtld-elf
David Xu
davidxu at FreeBSD.org
Thu Feb 27 02:41:42 UTC 2014
Author: davidxu
Date: Thu Feb 27 02:41:41 2014
New Revision: 262545
URL: http://svnweb.freebsd.org/changeset/base/262545
Log:
MFC r262277:
malloc_aligned() may not leave enough space for pointer to allocated memory,
saving the pointer will overwrite bytes belongs to another memory block
unexpectly, to fix the problem, use (allocated address + sizeof(void *)) as
initial value, and slip to next aligned address, so maximum extra bytes is
sizeof(void *) + align - 1.
Tested by: Andre Albsmeier < mail at ma17 dot ata dot myota dot orgndre >
MFC r262334:
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.
Modified:
stable/9/libexec/rtld-elf/xmalloc.c
Directory Properties:
stable/9/ (props changed)
stable/9/libexec/rtld-elf/ (props changed)
Modified: stable/9/libexec/rtld-elf/xmalloc.c
==============================================================================
--- stable/9/libexec/rtld-elf/xmalloc.c Thu Feb 27 02:36:09 2014 (r262544)
+++ stable/9/libexec/rtld-elf/xmalloc.c Thu Feb 27 02:41:41 2014 (r262545)
@@ -72,14 +72,12 @@ void *
malloc_aligned(size_t size, size_t align)
{
void *mem, *res;
- uintptr_t x;
- size_t asize, r;
- r = round(sizeof(void *), align);
- asize = round(size, align) + r;
- mem = xmalloc(asize);
- x = (uintptr_t)mem;
- res = (void *)round(x, align);
+ if (align < sizeof(void *))
+ align = sizeof(void *);
+
+ mem = xmalloc(size + sizeof(void *) + align - 1);
+ res = (void *)round((uintptr_t)mem + sizeof(void *), align);
*(void **)((uintptr_t)res - sizeof(void *)) = mem;
return (res);
}
More information about the svn-src-stable-9
mailing list