[uClinux-dev] Re: brk(2) and stack pointer

Shaun Jackman sjackman@gmail.com
Sun Apr 30 10:59:00 GMT 2006


On 4/29/06, David McCullough <david_mccullough@au.securecomputing.com> wrote:
> brk,  when implemented under uClinux only gives you access to a small
> amount of memory.  Typically that below the stack and above the BSS.
> The space you get is the slack space from the kernel allocator,  so it
> can be anything from none up.

When the brk is growing up towards the stack pointer, I was trying to
figure out when brk should stop giving out memory. Anything other than
"once you've reached the stack pointer" is an arbitrary limit.

> Typically,  brk is not used on uClinux systems,  though some malloc
> implementations have used it to get the absolute most out of the RAM,
> most tend to stick with mmap allocation,

That explains a lot, actually, about how uClinux manages the heap. The
bFLT executable format specifies a "stack space" allocation, but not a
"heap space" allocation. I assumed the "stack space" is the total
space allocated after the BSS, and that the brk and stack grow towards
each other, such that the "stack space" allocation was shared by the
heap and the stack. It makes more sense if the stack has exclusive
access to this space, and the heap is mmap'ed.

newlib's default malloc for embedded systems uses brk. I believe the
i386-linux malloc implementation can use mmap, but I don't have the
source in front of me at the moment.

Cheers,
Shaun


More information about the Newlib mailing list