This is the mail archive of the glibc-linux@ricardo.ecn.wfu.edu 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]

Re: Q: how to "wrap" malloc()


>>>>> Andrew Morton writes:

 > A little help, please:
 > I wish to intercept calls to malloc(), free(), etc.  After doing some
 > processing I wish to then call the standard versions.

 > This is for use in a general purpose memory-use-checker.

 > I do not wish to "#define malloc my_malloc".

 > I'd rather not use 'ld --wrap' for portability reasons.

 > I require that libc's internal calls to malloc() pass through my
 > front-ends.


 > I have tried dlopening libc.so.6 from within my own malloc(), plucking
 > out the symbols with dlsym() and calling those indirectly from within
 > the wrappers, but for non-trivial tests, this is getting a segfault
 > within "memcpy () from /lib/ld-linux.so.2".  I'm thinking this is
 > perhaps not the best way.

 > Is there a right way to do this?

Why not do it the other way round?  Check the manual for "Storage
Allocation Hooks".

Andreas
-- 
 Andreas Jaeger   
  SuSE Linux Labs aj@suse.de	
   private aj@arthur.rhein-neckar.de

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