diff options
author | Rich Felker <dalias@aerifal.cx> | 2012-12-07 22:33:11 -0500 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2012-12-07 22:33:11 -0500 |
commit | b8ccf8e46bab6ee9d63a6e392c3b33b9aa89255c (patch) | |
tree | 5507553d3354f4650d904df2e54829cf1b38181c /src | |
parent | 3ee67505fe50299d6df6e9bca894fd6b568669fb (diff) | |
download | musl-b8ccf8e46bab6ee9d63a6e392c3b33b9aa89255c.tar.gz musl-b8ccf8e46bab6ee9d63a6e392c3b33b9aa89255c.tar.bz2 musl-b8ccf8e46bab6ee9d63a6e392c3b33b9aa89255c.tar.xz musl-b8ccf8e46bab6ee9d63a6e392c3b33b9aa89255c.zip |
page-align initial brk value used by malloc in shared libc
this change fixes an obscure issue with some nonstandard kernels,
where the initial brk syscall returns a pointer just past the end of
bss rather than the beginning of a new page. in that case, the dynamic
linker has already reclaimed the space between the end of bss and the
page end for use by malloc, and memory corruption (allocating the same
memory twice) will occur when malloc again claims it on the first call
to brk.
Diffstat (limited to 'src')
-rw-r--r-- | src/malloc/malloc.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/malloc/malloc.c b/src/malloc/malloc.c index 88a31ae4..1a6d1493 100644 --- a/src/malloc/malloc.c +++ b/src/malloc/malloc.c @@ -196,7 +196,11 @@ static int init_malloc(size_t n) return 0; } - mal.brk = __brk(0) + 2*SIZE_ALIGN-1 & -SIZE_ALIGN; + mal.brk = __brk(0); +#ifdef SHARED + mal.brk = mal.brk + PAGE_SIZE-1 & -PAGE_SIZE; +#endif + mal.brk = mal.brk + 2*SIZE_ALIGN-1 & -SIZE_ALIGN; c = expand_heap(n); |