| 1 | #define _GNU_SOURCE |
| 2 | #include <dlfcn.h> |
| 3 | #include <sys/types.h> |
| 4 | #include <stdio.h> |
| 5 | |
| 6 | #include "marker.h" |
| 7 | |
| 8 | void *(*plibc_malloc)(size_t size) = NULL; |
| 9 | |
| 10 | void *malloc(size_t size) |
| 11 | { |
| 12 | if(plibc_malloc == NULL) { |
| 13 | plibc_malloc = dlsym(RTLD_NEXT, "malloc"); |
| 14 | if(plibc_malloc == NULL) { |
| 15 | fprintf(stderr, "mallocwrap: unable to find malloc\n"); |
| 16 | return NULL; |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | trace_mark(ust, malloc, "%d", (int)size); |
| 21 | |
| 22 | fprintf(stderr, "mallocating size %d\n", size); |
| 23 | return plibc_malloc(size); |
| 24 | } |
| 25 | |
| 26 | MARKER_LIB |