8 //INTERCEPT_PROTOTYPE(void, malloc, size_t size)
9 //INTERCEPT_TRACE("size %d", size)
10 //INTERCEPT_CALL_ARGS(size)
13 //#define INTERCEPT_FUNC(type, name, args...) \
14 //__I_FUNC_TYPE(type) \
15 //__I_FUNC_NAME(name) \
18 //#define INTERCEPT_TRACE(fmt, args...) \
19 //#define __I_TRACE_FMT fmt \
20 //#define __I_TRACE_ARGS args
22 //#define INTERCEPT_CALL_ARGS(args...) \
23 //#define __I_CALL_ARGS args
25 //#define INTERCEPT() \
26 //__I_FUNC_TYPE __I_FUNC_NAME(__I_FUNC_ARGS) \
28 // static __I_FUNC_TYPE (*plibc_ ## __I_FUNC_NAME)(args) = NULL; \
30 // if(plibc_ ## __I_FUNC_NAME == NULL) { \
31 // plibc_ ## __I_FUNC_NAME = dlsym(RTLD_NEXT, "malloc"); \
32 // if(plibc_ ## __I_FUNC_NAME == NULL) { \
33 // fprintf(stderr, "mallocwrap: unable to find malloc\n"); \
38 // trace_mark(ust, __I_FUNC_NAME, __I_TRACE_FMT, __I_TRACE_ARGS); \
40 // return plibc_ ## __I_FUNC_NAME (__I_CALL_ARGS); \
43 void *malloc(size_t size
)
45 static void *(*plibc_malloc
)(size_t size
) = NULL
;
49 if(plibc_malloc
== NULL
) {
50 plibc_malloc
= dlsym(RTLD_NEXT
, "malloc");
51 if(plibc_malloc
== NULL
) {
52 fprintf(stderr
, "mallocwrap: unable to find malloc\n");
57 retval
= plibc_malloc(size
);
59 trace_mark(ust
, malloc
, "size %d ptr %p", (int)size
, retval
);
66 static void *(*plibc_free
)(void *ptr
) = NULL
;
68 if(plibc_free
== NULL
) {
69 plibc_free
= dlsym(RTLD_NEXT
, "free");
70 if(plibc_free
== NULL
) {
71 fprintf(stderr
, "mallocwrap: unable to find free\n");
76 trace_mark(ust
, free
, "%p", ptr
);
78 return plibc_free(ptr
);
This page took 0.03162 seconds and 4 git commands to generate.