From: Pierre-Marc Fournier Date: Tue, 17 Feb 2009 20:37:40 +0000 (-0500) Subject: ust: mallocwrap: add X-Git-Tag: v0.1~288 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=e541a28d5fdb3b64e972189458d7b2269d1603d4;p=ust.git ust: mallocwrap: add --- diff --git a/libmallocwrap/Makefile b/libmallocwrap/Makefile new file mode 100644 index 0000000..ac7ff69 --- /dev/null +++ b/libmallocwrap/Makefile @@ -0,0 +1,4 @@ +all: libmallocwrap.so + +libmallocwrap.so: mallocwrap.c + gcc -shared -fPIC -g -ldl -o libmallocwrap.so mallocwrap.c diff --git a/libmallocwrap/mallocwrap.c b/libmallocwrap/mallocwrap.c new file mode 100644 index 0000000..48dab0a --- /dev/null +++ b/libmallocwrap/mallocwrap.c @@ -0,0 +1,19 @@ +#define _GNU_SOURCE +#include +#include +#include + +void *(*plibc_malloc)(size_t size) = NULL; + +void *malloc(size_t size) +{ + if(plibc_malloc == NULL) { + plibc_malloc = dlsym(RTLD_NEXT, "malloc"); + if(plibc_malloc == NULL) { + fprintf(stderr, "mallocwrap: unable to find malloc\n"); + return NULL; + } + } + fprintf(stderr, "mallocating size %d\n", size); + return plibc_malloc(size); +}