Newlib uses dlmalloc. dlmalloc does not use sbrk() directly, but rather through an abstraction called MORECORE. However, it depends on MORECORE having some rather peculiar characteristics, that pretty much can only be fulfilled by something approximating sbrk(). I have worked with Linux on ARM before, and I know that at least there, mmap() likes to return progressively lower addresses. If this happens with MORECORE, then many things will fail. For instance, malloc_extend_top() expects MORECORE to return an address larger than old_end, which is the end of the heap before that function was called. Leaving aside for the moment the issue of the invalid comparison, if MORECORE were just a wrapper around mmap(), addresses would not necessarily be monotonic. MORECORE(0) is expected to return the current break, and with a negative number it is expected to at least try to reduce the break. If sbrk() returns decreasing addresses, dlmalloc will start using addresses never allocated. If it returns discontinuous, but monotonically increasing addresses, then things might work out.
OSwhatever wrote:
Newlib is a very popular clib among embedded systems and it is hardly legacy.
Newlib contains tons of code to support compilers that don't know ANSI C yet. You were saying?
OSwhatever wrote:
It seems like it's mostly to allow concurrent calls to sbrk rather than non-continuous memory.
That is also my assessment, having read some of the code.