This is the mail archive of the mailing list for the glibc project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

__curbrk (and &_end)

[ Please CC, I'm not subscribed ]


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, 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

$ cat getend.c
extern void _end;
void *
getend ()
{ return &_end; }

$ cat test.c
#include <stdio.h>
extern void _end;
main ()
{ printf ("%p\n%p\n", &_end, getend ()); }

$ gcc -shared getend.c -o
$ gcc test.c -o test -L. -lgetend
$ LD_LIBRARY_PATH=. ./test

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?


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)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]