refactor malloc's expand_heap to share with __simple_malloc
authorRich Felker <dalias@aerifal.cx>
Sun, 14 Jun 2015 01:59:02 +0000 (01:59 +0000)
committerRich Felker <dalias@aerifal.cx>
Sun, 14 Jun 2015 01:59:02 +0000 (01:59 +0000)
commite3bc22f1eff87b8f029a6ab31f1a269d69e4b053
treed0fc5ca6b5a1a5740f739a37ff5d8c7446fbfd9a
parent4ef9b828c1f39553a69e0635ac91f0fcadd6e8c6
refactor malloc's expand_heap to share with __simple_malloc

this extends the brk/stack collision protection added to full malloc
in commit 276904c2f6bde3a31a24ebfa201482601d18b4f9 to also protect the
__simple_malloc function used in static-linked programs that don't
reference the free function.

it also extends support for using mmap when brk fails, which full
malloc got in commit 5446303328adf4b4e36d9fba21848e6feb55fab4, to
__simple_malloc.

since __simple_malloc may expand the heap by arbitrarily large
increments, the stack collision detection is enhanced to detect
interval overlap rather than just proximity of a single address to the
stack. code size is increased a bit, but this is partly offset by the
sharing of code between the two malloc implementations, which due to
linking semantics, both get linked in a program that needs the full
malloc with realloc/free support.
src/malloc/expand_heap.c [new file with mode: 0644]
src/malloc/lite_malloc.c
src/malloc/malloc.c