Re: segfault with dlsym(RTLD_NEXT, "func")

From: Branimir Maksimovic (bmaxa_at_eunet.yu)
Date: 10/23/05


Date: Sun, 23 Oct 2005 23:21:18 +0200


"Jirka Kosina" <jikos@jikos.cz> wrote in message
news:Pine.LNX.4.58.0510221821210.27074@twin.jikos.cz...
> On Sat, 22 Oct 2005 nirnimesh@gmail.com wrote:
>
>> void * malloc(size_t sz)
>> {
>> printf("start\n");
>> void *ptr;
>> void *(*real_malloc)(size_t);
>> real_malloc = (void * (*)(size_t))dlsym(RTLD_NEXT, "malloc");
>
> Are you sure that dlsym() doesn't call malloc() by itself?
>
> IMHO the better way for hooking the malloc()/free()/realloc()/...
> functions is to use the hooks provided by glibc. Read the chapter
> "3.2.2.10 Memory Allocation Hooks" in the glibc manual.
>

Problem is that malloc installs own atfork handlers that replace default
ones in
atfork time without checking that __free_hook, __malloc_hook is default one,
 and program fails if free is called at fork time, because free_atfork will
be called instead of real hook.
 Idon;t know if someone corrected that or not.

Greetings, Bane.



Relevant Pages

  • Re: segfault with dlsym(RTLD_NEXT, "func")
    ... >> Are you sure that dlsym() doesn't call mallocby itself? ... >> functions is to use the hooks provided by glibc. ... > Problem is that malloc installs own atfork handlers that replace default ...
    (comp.os.linux.development.system)
  • Re: overriding libc routines
    ... application calling some libc routines, for example, malloc, strlen ... Hooks for malloc is a start: ...
    (comp.os.linux.development.system)
  • Re: sigaction, fork, malloc, and futex
    ... > Your signal handler function is illegally calling non-reentrant functions. ... malloc() cannot be re-entered. ... > fprintf() ... I'm pretty sure the problem is in glibc. ...
    (Linux-Kernel)
  • Re: malloc blocked on Linux
    ... kernel version is largely irrelevant, what glibc version are you using? ... how did you come to the conclusion that it is blocked in malloc? ... In order to understand recursion you must first understand recursion. ...
    (comp.unix.questions)
  • Re: memory fragmentation with malloc
    ... malloc, released back to the C allocator with free, and libumem has ... improvements compared to glibc. ... During the libumem installation 2 shared libs were created: ... As I am not sure which of them is the right one for malloc replacement, ...
    (comp.unix.programmer)