This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: overloading malloc is impossible
- From: Wolfram Gloger <wmglo at dent dot med dot uni-muenchen dot de>
- To: john dot r dot moser at gmail dot com
- Cc: libc-alpha at sourceware dot org
- Date: 28 Aug 2006 09:34:49 -0000
- Subject: Re: overloading malloc is impossible
- References: <1156726348.30132.4.camel@localhost>
Hi,
> I have no idea why this isn't working; but I'm trying to replace the
> glibc allocator with something else via an LD_PRELOAD.
This should work, but it isn't easy. Maybe try the hooks first.
> As a preliminary
> step, I've decided to do something simple: LD_PRELOAD something that
> calls straight mmap() and see if it works.
You have:
#define PAGE_ALIGN(x) (4096 + x & ~4095)
^ ^ parentheses missing
...
PAGE_ALIGN(size + sizeof(size_t)) // oops!
...
return addr + sizeof(size_t);
That last one returns addresses aligned at 4, unsuitable for double
precision floats.
I didn't look much further..
> No idea why, but 'ls' works, 'find' fails, 'xclock' works, and
> 'gcalctool' fails. Most anything fails really. I know the approach is
> crude, but it's not broken. Is there some secret trick to replacing
> glibc's allocator?
You have to provide thread-safety for all but trivial programs. That
involves not only locking, but also pthread_atfork() hooks.
Maybe take a look at "Electric Fence". Last I checked, admittedly
a long time ago, that worked as an LD_PRELOAD shared library.
Regards,
Wolfram.