Re: [glib] malloc and bdwgc

Am 07.01.2016 um 12:26 schrieb 张海:
Yes, but glib is the only one I'm using now.

Still I don't know how to make GC_malloc() call the original malloc()
if I'm using LD_PRELOAD or the wrapper function and dlsym way.

Just now I found I've misread
, and that such replacement can possibly be done in a single-threaded
environment, because the hook is done with a global function pointer
variable initialization and it seems that the function is called
before memory allocation initialization

However as in
, there are nasty race conditions for such hook. And my program needs

Are there any other way around?

You can simply implement malloc() and friends in your application, then the linker shouldn't resolve calls to the libc implementation. If you need to call the original malloc() from that you can use secondary names / aliases (__libc_malloc() etc). If the latter does not work for your C library then you can alternatively access them by dlopen(RTLD_NEXT, "malloc");

That said, the above is probably only portable on Unix systems. It should be race free as well.

Best regards

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]