1 /* Copyright (C) 2009 Pierre-Marc Fournier
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 #include <sys/types.h>
23 #include <ust/marker.h>
26 INTERCEPT_PROTOTYPE(void, malloc
, size_t size
)
27 INTERCEPT_TRACE("size %d", size
)
28 INTERCEPT_CALL_ARGS(size
)
31 #define INTERCEPT_FUNC(type, name, args...) \
36 #define INTERCEPT_TRACE(fmt, args...) \
37 #define __I_TRACE_FMT fmt \
38 #define __I_TRACE_ARGS args
40 #define INTERCEPT_CALL_ARGS(args...) \
41 #define __I_CALL_ARGS args
44 __I_FUNC_TYPE __I_FUNC_NAME(__I_FUNC_ARGS) \
46 static __I_FUNC_TYPE (*plibc_ ## __I_FUNC_NAME)(args) = NULL; \
48 if(plibc_ ## __I_FUNC_NAME == NULL) { \
49 plibc_ ## __I_FUNC_NAME = dlsym(RTLD_NEXT, "malloc"); \
50 if(plibc_ ## __I_FUNC_NAME == NULL) { \
51 fprintf(stderr, "mallocwrap: unable to find malloc\n"); \
56 trace_mark(ust, __I_FUNC_NAME, __I_TRACE_FMT, __I_TRACE_ARGS); \
58 return plibc_ ## __I_FUNC_NAME (__I_CALL_ARGS); \
62 void *malloc(size_t size
)
64 static void *(*plibc_malloc
)(size_t size
) = NULL
;
68 if(plibc_malloc
== NULL
) {
69 plibc_malloc
= dlsym(RTLD_NEXT
, "malloc");
70 if(plibc_malloc
== NULL
) {
71 fprintf(stderr
, "mallocwrap: unable to find malloc\n");
76 retval
= plibc_malloc(size
);
78 trace_mark(ust
, malloc
, "size %d ptr %p", (int)size
, retval
);
85 static void *(*plibc_free
)(void *ptr
) = NULL
;
87 if(plibc_free
== NULL
) {
88 plibc_free
= dlsym(RTLD_NEXT
, "free");
89 if(plibc_free
== NULL
) {
90 fprintf(stderr
, "mallocwrap: unable to find free\n");
95 trace_mark(ust
, free
, "ptr %p", ptr
);
This page took 0.0335 seconds and 4 git commands to generate.