ust: mallocwrap: add
authorPierre-Marc Fournier <pierre-marc.fournier@polymtl.ca>
Tue, 17 Feb 2009 20:37:40 +0000 (15:37 -0500)
committerPierre-Marc Fournier <pierre-marc.fournier@polymtl.ca>
Tue, 17 Feb 2009 20:37:40 +0000 (15:37 -0500)
libmallocwrap/Makefile [new file with mode: 0644]
libmallocwrap/mallocwrap.c [new file with mode: 0644]

diff --git a/libmallocwrap/Makefile b/libmallocwrap/Makefile
new file mode 100644 (file)
index 0000000..ac7ff69
--- /dev/null
@@ -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 (file)
index 0000000..48dab0a
--- /dev/null
@@ -0,0 +1,19 @@
+#define _GNU_SOURCE
+#include <dlfcn.h>
+#include <sys/types.h>
+#include <stdio.h>
+
+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);
+}
This page took 0.024249 seconds and 4 git commands to generate.