Update version to 0.16
[ust.git] / libustinstr-malloc / mallocwrap.c
CommitLineData
b27f8e75
MD
1/*
2 * Copyright (C) 2009 Pierre-Marc Fournier
c39c72ee
PMF
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
e541a28d
PMF
19#define _GNU_SOURCE
20#include <dlfcn.h>
21#include <sys/types.h>
22#include <stdio.h>
93d0f2ea 23#include <ust/marker.h>
fbd8191b 24
e541a28d
PMF
25void *malloc(size_t size)
26{
1c184644 27 static void *(*plibc_malloc)(size_t size) = NULL;
1c184644
PMF
28 void *retval;
29
b27f8e75 30 if (plibc_malloc == NULL) {
e541a28d 31 plibc_malloc = dlsym(RTLD_NEXT, "malloc");
b27f8e75 32 if (plibc_malloc == NULL) {
e541a28d
PMF
33 fprintf(stderr, "mallocwrap: unable to find malloc\n");
34 return NULL;
35 }
36 }
fbd8191b 37
1c184644
PMF
38 retval = plibc_malloc(size);
39
686debc3 40 ust_marker(malloc, "size %d ptr %p", (int)size, retval);
1c184644
PMF
41
42 return retval;
43}
44
45void free(void *ptr)
46{
47 static void *(*plibc_free)(void *ptr) = NULL;
48
b27f8e75 49 if (plibc_free == NULL) {
1c184644 50 plibc_free = dlsym(RTLD_NEXT, "free");
b27f8e75 51 if (plibc_free == NULL) {
1c184644 52 fprintf(stderr, "mallocwrap: unable to find free\n");
eb0f0951 53 return;
1c184644
PMF
54 }
55 }
56
686debc3 57 ust_marker(free, "ptr %p", ptr);
fbd8191b 58
eb0f0951 59 plibc_free(ptr);
e541a28d 60}
fbd8191b 61
b521931e 62UST_MARKER_LIB
This page took 0.036785 seconds and 4 git commands to generate.