This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
__curbrk (and &_end)
- From: Robert Millan <zeratul2 at wanadoo dot es>
- To: libc-alpha at sources dot redhat dot com
- Cc: glibc-bsd-hackers at nongnu dot org
- Date: Mon, 16 Feb 2004 13:20:38 +0100
- Subject: __curbrk (and &_end)
- Organisation: free as in freedom
[ Please CC, I'm not subscribed ]
Hi!
Unlike Linux, kFreeBSD doesn't return the current break address through the
stack after running the SYS_break syscall.
Therefore, the brk() implementation cannot initialise __curbrk on that
platform (the expected behaviour would be that calling brk(0) when
__curbrk == 0 would initialise __curbrk to a sane value.)
I have attempted a solution in the lines of:
/* initialise the break */
if (__curbrk == 0)
__curbrk = &_end;
This solution works perfectly on staticaly-linked programs. However, it seems
that when &_end is used from libc.so, it contains the break address of libc
itself, not the running program.
I don't understand what makes it different, or how can I obtain the program's
break address from libc without changing the API. But I have done this simple
test:
$ cat getend.c
extern void _end;
void *
getend ()
{ return &_end; }
$ cat test.c
#include <stdio.h>
extern void _end;
int
main ()
{ printf ("%p\n%p\n", &_end, getend ()); }
$ gcc -shared getend.c -o libgetend.so
$ gcc test.c -o test -L. -lgetend
$ LD_LIBRARY_PATH=. ./test
0x8049710
0x8049710
And my test shared object returns the correct address. So my guess is it
must be possible to do the same in libc. Any hints?
Thanks.
--
Robert Millan
"[..] but the delight and pride of Aule is in the deed of making, and in the
thing made, and neither in possession nor in his own mastery; wherefore he
gives and hoards not, and is free from care, passing ever on to some new work."
-- J.R.R.T., Ainulindale (Silmarillion)