This is the mail archive of the libc-alpha@sourceware.org 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]

Re: overloading malloc is impossible


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.


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