brk(2) trouble

Roland McGrath roland@redhat.com
Thu Nov 21 18:07:00 GMT 2002


> How brk(2) is supposed to be implemnted ?  And what's the semantics of
> "break" in a dynamically linked program anyway ?

The break follows the executable's data segment (i.e. the address of the
program's own _end), and the kernel puts mmap mappings like shared objects
far enough way to leave room for it to grow some.

On Linux, the implementation now does not initialize __curbrk to &_end.
Instead, it's uninitialized (or initialized to zero, for reasons that
aren't important to you) and sysdeps/generic/sbrk.c in this case calls
__brk(0) to set it from the kernel state before using the __curbrk value.

The Linux versions do not enforce a __minbrk value, so getting that
initialized is not an issue.  I think a brk(&_start) will just happily eat
your text and data mappings in Linux.



More information about the Libc-alpha mailing list