njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 1 | |
| 2 | /*--------------------------------------------------------------------*/ |
| 3 | /*--- Replacements for malloc() et al, which run on the simulated ---*/ |
| 4 | /*--- CPU. vg_replace_malloc.c ---*/ |
| 5 | /*--------------------------------------------------------------------*/ |
| 6 | |
| 7 | /* |
| 8 | This file is part of Valgrind, an extensible x86 protected-mode |
| 9 | emulator for monitoring program execution on x86-Unixes. |
| 10 | |
nethercote | bb1c991 | 2004-01-04 16:43:23 +0000 | [diff] [blame] | 11 | Copyright (C) 2000-2004 Julian Seward |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 12 | jseward@acm.org |
| 13 | |
| 14 | This program is free software; you can redistribute it and/or |
| 15 | modify it under the terms of the GNU General Public License as |
| 16 | published by the Free Software Foundation; either version 2 of the |
| 17 | License, or (at your option) any later version. |
| 18 | |
| 19 | This program is distributed in the hope that it will be useful, but |
| 20 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 22 | General Public License for more details. |
| 23 | |
| 24 | You should have received a copy of the GNU General Public License |
| 25 | along with this program; if not, write to the Free Software |
| 26 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 27 | 02111-1307, USA. |
| 28 | |
| 29 | The GNU General Public License is contained in the file COPYING. |
| 30 | */ |
| 31 | |
| 32 | /* --------------------------------------------------------------------- |
| 33 | All the code in this file runs on the SIMULATED CPU. It is |
| 34 | intended for various reasons as drop-in replacements for malloc() |
| 35 | and friends. These functions have global visibility (obviously) and |
| 36 | have no prototypes in vg_include.h, since they are not intended to |
| 37 | be called from within Valgrind. |
| 38 | |
nethercote | 7cc9c23 | 2004-01-21 15:08:04 +0000 | [diff] [blame] | 39 | This file can be #included into a tool that wishes to know about |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 40 | calls to malloc(). It should define functions SK_(malloc) et al |
| 41 | that will be called. |
| 42 | ------------------------------------------------------------------ */ |
| 43 | |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 44 | #include "valgrind.h" /* for VALGRIND_NON_SIMD_CALL[12] */ |
nethercote | 851b0f6 | 2003-11-13 23:02:16 +0000 | [diff] [blame] | 45 | #include "vg_include.h" |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 46 | #include "vg_skin.h" |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 47 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 48 | /* Create an alias */ |
| 49 | #define ALIAS(ret, name, args, toname) \ |
| 50 | ret name args __attribute__((alias(#toname), visibility("protected"))) |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 51 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 52 | /* Declare a function, along with libc's various aliases */ |
| 53 | #define LIBALIAS(ret, name, args) \ |
| 54 | ALIAS(ret, __##name, args, name); \ |
| 55 | ALIAS(ret, __libc_##name, args, name); \ |
| 56 | ret name args |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 57 | |
| 58 | /*------------------------------------------------------------*/ |
| 59 | /*--- Replacing malloc() et al ---*/ |
| 60 | /*------------------------------------------------------------*/ |
| 61 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 62 | static struct vg_mallocfunc_info info; |
| 63 | static int init_done; |
| 64 | |
| 65 | /* Startup hook - called as init section */ |
| 66 | static void init(void) __attribute__((constructor)); |
| 67 | |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 68 | /* Below are new versions of malloc, __builtin_new, free, |
| 69 | __builtin_delete, calloc, realloc, memalign, and friends. |
| 70 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 71 | None of these functions are called directly - they are not meant to |
| 72 | be found by the dynamic linker. They get called because |
| 73 | vg_replace_malloc installs a bunch of code redirects which causes |
| 74 | Valgrind to use these functions rather than the ones they're |
| 75 | replacing. That said, we certainly don't mind if the linker finds |
| 76 | them, because it makes our life easier with respect to startup |
| 77 | initialization order (we can't guarantee that our init routine will |
| 78 | necessarily be called early enough to do the redirects before |
| 79 | someone wants to allocate). |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 80 | */ |
| 81 | |
| 82 | #define MALLOC_TRACE(format, args...) \ |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 83 | if (info.clo_trace_malloc) \ |
fitzhardinge | 7fae3e0 | 2003-10-31 07:13:41 +0000 | [diff] [blame] | 84 | VALGRIND_INTERNAL_PRINTF(format, ## args ) |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 85 | |
| 86 | #define MAYBE_SLOPPIFY(n) \ |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 87 | if (info.clo_sloppy_malloc) { \ |
| 88 | n = (n+3) & ~3; \ |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 89 | } |
| 90 | |
njn | d0eab5f | 2003-09-30 16:52:47 +0000 | [diff] [blame] | 91 | /* ALL calls to malloc() and friends wind up here. */ |
| 92 | #define ALLOC(fff, vgfff) \ |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 93 | LIBALIAS(void *, fff, (Int n)) \ |
njn | d0eab5f | 2003-09-30 16:52:47 +0000 | [diff] [blame] | 94 | { \ |
| 95 | void* v; \ |
| 96 | \ |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 97 | MALLOC_TRACE(#fff "(%d)", n ); \ |
njn | d0eab5f | 2003-09-30 16:52:47 +0000 | [diff] [blame] | 98 | MAYBE_SLOPPIFY(n); \ |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 99 | if (!init_done) init(); \ |
njn | d0eab5f | 2003-09-30 16:52:47 +0000 | [diff] [blame] | 100 | \ |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 101 | v = (void*)VALGRIND_NON_SIMD_CALL1( info.sk_##vgfff, n ); \ |
fitzhardinge | 7fae3e0 | 2003-10-31 07:13:41 +0000 | [diff] [blame] | 102 | MALLOC_TRACE(" = %p", v ); \ |
njn | d0eab5f | 2003-09-30 16:52:47 +0000 | [diff] [blame] | 103 | return v; \ |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 104 | } |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 105 | ALLOC( malloc, malloc ); |
| 106 | ALLOC( __builtin_new, __builtin_new ); |
| 107 | ALLOC( _Znwj, __builtin_new ); |
njn | 5cebf57 | 2003-10-09 15:40:38 +0000 | [diff] [blame] | 108 | |
| 109 | // operator new(unsigned, std::nothrow_t const&) |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 110 | ALLOC( _ZnwjRKSt9nothrow_t, __builtin_new ); |
njn | 5cebf57 | 2003-10-09 15:40:38 +0000 | [diff] [blame] | 111 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 112 | ALLOC( __builtin_vec_new, __builtin_vec_new ); |
| 113 | ALLOC( _Znaj, __builtin_vec_new ); |
njn | 5cebf57 | 2003-10-09 15:40:38 +0000 | [diff] [blame] | 114 | |
| 115 | // operator new[](unsigned, std::nothrow_t const& |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 116 | ALLOC( _ZnajRKSt9nothrow_t, __builtin_vec_new ); |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 117 | |
njn | d0eab5f | 2003-09-30 16:52:47 +0000 | [diff] [blame] | 118 | #define FREE(fff, vgfff) \ |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 119 | LIBALIAS(void, fff, (void *p)) \ |
njn | d0eab5f | 2003-09-30 16:52:47 +0000 | [diff] [blame] | 120 | { \ |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 121 | MALLOC_TRACE(#fff "(%p)", p ); \ |
njn | d0eab5f | 2003-09-30 16:52:47 +0000 | [diff] [blame] | 122 | if (p == NULL) \ |
| 123 | return; \ |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 124 | if (!init_done) init(); \ |
| 125 | (void)VALGRIND_NON_SIMD_CALL1( info.sk_##vgfff, p ); \ |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 126 | } |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 127 | FREE( free, free ); |
| 128 | FREE( __builtin_delete, __builtin_delete ); |
| 129 | FREE( _ZdlPv, __builtin_delete ); |
| 130 | FREE( __builtin_vec_delete, __builtin_vec_delete ); |
| 131 | FREE( _ZdaPv, __builtin_vec_delete ); |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 132 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 133 | LIBALIAS(void*, calloc, ( Int nmemb, Int size )) |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 134 | { |
| 135 | void* v; |
| 136 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 137 | MALLOC_TRACE("calloc(%d,%d)", nmemb, size ); |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 138 | MAYBE_SLOPPIFY(size); |
| 139 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 140 | if (!init_done) init(); |
| 141 | v = (void*)VALGRIND_NON_SIMD_CALL2( info.sk_calloc, nmemb, size ); |
fitzhardinge | 7fae3e0 | 2003-10-31 07:13:41 +0000 | [diff] [blame] | 142 | MALLOC_TRACE(" = %p", v ); |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 143 | return v; |
| 144 | } |
| 145 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 146 | LIBALIAS(void*, realloc, ( void* ptrV, Int new_size )) |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 147 | { |
| 148 | void* v; |
| 149 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 150 | MALLOC_TRACE("realloc(%p,%d)", ptrV, new_size ); |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 151 | MAYBE_SLOPPIFY(new_size); |
| 152 | |
| 153 | if (ptrV == NULL) |
| 154 | return malloc(new_size); |
| 155 | if (new_size <= 0) { |
| 156 | free(ptrV); |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 157 | if (info.clo_trace_malloc) |
| 158 | VALGRIND_INTERNAL_PRINTF(" = 0" ); |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 159 | return NULL; |
| 160 | } |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 161 | if (!init_done) init(); |
| 162 | v = (void*)VALGRIND_NON_SIMD_CALL2( info.sk_realloc, ptrV, new_size ); |
fitzhardinge | 7fae3e0 | 2003-10-31 07:13:41 +0000 | [diff] [blame] | 163 | MALLOC_TRACE(" = %p", v ); |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 164 | return v; |
| 165 | } |
| 166 | |
| 167 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 168 | LIBALIAS(void*, memalign, ( Int alignment, Int n )) |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 169 | { |
| 170 | void* v; |
| 171 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 172 | MALLOC_TRACE("memalign(al %d, size %d)", alignment, n ); |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 173 | MAYBE_SLOPPIFY(n); |
| 174 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 175 | if (!init_done) init(); |
| 176 | v = (void*)VALGRIND_NON_SIMD_CALL2( info.sk_memalign, alignment, n ); |
fitzhardinge | 7fae3e0 | 2003-10-31 07:13:41 +0000 | [diff] [blame] | 177 | MALLOC_TRACE(" = %p", v ); |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 178 | return v; |
| 179 | } |
| 180 | |
| 181 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 182 | LIBALIAS(void*, valloc, ( Int size )) |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 183 | { |
| 184 | return memalign(VKI_BYTES_PER_PAGE, size); |
| 185 | } |
| 186 | |
| 187 | |
| 188 | /* Various compatibility wrapper functions, for glibc and libstdc++. */ |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 189 | |
| 190 | /* Don't just alias free, otherwise people could get confused seeing |
| 191 | cfree rather than free in error output */ |
| 192 | LIBALIAS(void, cfree, ( void* p ) ) |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 193 | { |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 194 | free(p); |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 195 | } |
| 196 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 197 | LIBALIAS(int, mallopt, ( int cmd, int value )) |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 198 | { |
| 199 | /* In glibc-2.2.4, 1 denotes a successful return value for mallopt */ |
| 200 | return 1; |
| 201 | } |
| 202 | |
| 203 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 204 | LIBALIAS(int, posix_memalign, ( void **memptr, UInt alignment, UInt size )) |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 205 | { |
| 206 | void *mem; |
| 207 | |
mueller | 211d05d | 2003-11-28 00:15:57 +0000 | [diff] [blame] | 208 | /* Test whether the alignment argument is valid. It must be a power of |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 209 | two multiple of sizeof (void *). */ |
mueller | 211d05d | 2003-11-28 00:15:57 +0000 | [diff] [blame] | 210 | if (alignment % sizeof (void *) != 0 || (alignment & (alignment - 1)) != 0) |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 211 | return VKI_EINVAL /*22*/ /*EINVAL*/; |
| 212 | |
| 213 | mem = memalign (alignment, size); |
| 214 | |
| 215 | if (mem != NULL) { |
| 216 | *memptr = mem; |
| 217 | return 0; |
| 218 | } |
| 219 | |
| 220 | return VKI_ENOMEM /*12*/ /*ENOMEM*/; |
| 221 | } |
| 222 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 223 | LIBALIAS(int, malloc_usable_size, ( void* p )) |
njn | 8a6b6c0 | 2003-04-22 22:45:55 +0000 | [diff] [blame] | 224 | { |
| 225 | Int pszB; |
| 226 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 227 | MALLOC_TRACE("malloc_usable_size(%p)", p ); |
njn | 8a6b6c0 | 2003-04-22 22:45:55 +0000 | [diff] [blame] | 228 | if (NULL == p) |
| 229 | return 0; |
| 230 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 231 | if (!init_done) init(); |
| 232 | pszB = (Int)VALGRIND_NON_SIMD_CALL2( info.arena_payload_szB, |
| 233 | VG_AR_CLIENT, p ); |
fitzhardinge | 7fae3e0 | 2003-10-31 07:13:41 +0000 | [diff] [blame] | 234 | MALLOC_TRACE(" = %d", pszB ); |
njn | 8a6b6c0 | 2003-04-22 22:45:55 +0000 | [diff] [blame] | 235 | |
| 236 | return pszB; |
| 237 | } |
| 238 | |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 239 | |
| 240 | /* Bomb out if we get any of these. */ |
njn | 8a6b6c0 | 2003-04-22 22:45:55 +0000 | [diff] [blame] | 241 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 242 | extern void _exit(int); |
| 243 | |
| 244 | static void panic(const char *str) |
| 245 | { |
| 246 | VALGRIND_PRINTF_BACKTRACE("Program aborting because of call to %s", str); |
| 247 | |
| 248 | _exit(99); |
| 249 | *(int *)0 = 'x'; |
| 250 | } |
| 251 | |
| 252 | #define PANIC(x) \ |
| 253 | void x(void) \ |
| 254 | { \ |
| 255 | panic(#x); \ |
| 256 | } |
| 257 | |
| 258 | PANIC(pvalloc); |
| 259 | PANIC(malloc_stats); |
| 260 | PANIC(malloc_trim); |
| 261 | PANIC(malloc_get_state); |
| 262 | PANIC(malloc_set_state); |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 263 | |
| 264 | |
| 265 | /* Yet another ugly hack. Cannot include <malloc.h> because we |
| 266 | implement functions implemented there with different signatures. |
| 267 | This struct definition MUST match the system one. */ |
| 268 | |
| 269 | /* SVID2/XPG mallinfo structure */ |
| 270 | struct mallinfo { |
| 271 | int arena; /* total space allocated from system */ |
| 272 | int ordblks; /* number of non-inuse chunks */ |
| 273 | int smblks; /* unused -- always zero */ |
| 274 | int hblks; /* number of mmapped regions */ |
| 275 | int hblkhd; /* total space in mmapped regions */ |
| 276 | int usmblks; /* unused -- always zero */ |
| 277 | int fsmblks; /* unused -- always zero */ |
| 278 | int uordblks; /* total allocated space */ |
| 279 | int fordblks; /* total non-inuse space */ |
| 280 | int keepcost; /* top-most, releasable (via malloc_trim) space */ |
| 281 | }; |
| 282 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 283 | LIBALIAS(struct mallinfo, mallinfo, ( void )) |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 284 | { |
| 285 | /* Should really try to return something a bit more meaningful */ |
sewardj | 05bcdcb | 2003-05-18 10:05:38 +0000 | [diff] [blame] | 286 | UInt i; |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 287 | struct mallinfo mi; |
| 288 | UChar* pmi = (UChar*)(&mi); |
| 289 | for (i = 0; i < sizeof(mi); i++) |
| 290 | pmi[i] = 0; |
| 291 | return mi; |
| 292 | } |
| 293 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 294 | static const struct { |
| 295 | const Char *libname; |
| 296 | Addr func; |
| 297 | } replacements[] = |
| 298 | { |
| 299 | #define E(pfx, x) { pfx #x, (Addr)x } |
| 300 | #define R(x) E("", x), E("__libc_", x), E("__", x) |
| 301 | |
| 302 | /* alloc */ |
| 303 | R(malloc), |
| 304 | R(__builtin_new), |
| 305 | R(_Znwj), |
| 306 | R(_ZnwjRKSt9nothrow_t), /* operator new(unsigned, std::nothrow_t const&) */ |
| 307 | R(__builtin_vec_new), |
| 308 | R(_Znaj), |
| 309 | R(_ZnajRKSt9nothrow_t), /* operator new[](unsigned, std::nothrow_t const& */ |
| 310 | R(calloc), |
| 311 | R(realloc), |
| 312 | R(memalign), |
| 313 | R(valloc), |
| 314 | R(cfree), |
| 315 | R(posix_memalign), |
| 316 | |
| 317 | /* free */ |
| 318 | R(free), |
| 319 | R(__builtin_delete), |
| 320 | R(_ZdlPv), |
| 321 | R(__builtin_vec_delete), |
| 322 | R(_ZdaPv), |
| 323 | |
| 324 | /* misc */ |
| 325 | R(mallopt), |
| 326 | R(malloc_usable_size), |
| 327 | R(mallinfo), |
| 328 | |
| 329 | /* bad */ |
| 330 | R(pvalloc), |
| 331 | R(malloc_stats), |
| 332 | R(malloc_trim), |
| 333 | R(malloc_get_state), |
| 334 | R(malloc_set_state), |
| 335 | #undef R |
| 336 | #undef S |
| 337 | #undef E |
| 338 | }; |
| 339 | |
| 340 | /* All the code in here is unused until this function is called */ |
| 341 | |
| 342 | static void init(void) |
| 343 | { |
| 344 | int i; |
| 345 | int res; |
| 346 | |
| 347 | if (init_done) |
| 348 | return; |
| 349 | |
| 350 | init_done = 1; |
| 351 | |
| 352 | VALGRIND_MAGIC_SEQUENCE(res, -1, VG_USERREQ__GET_MALLOCFUNCS, &info, 0, 0, 0); |
| 353 | |
| 354 | for(i = 0; i < sizeof(replacements)/sizeof(*replacements); i++) { |
| 355 | #if 0 |
| 356 | /* doesn't seem much point - ld-linux.so will have already used |
| 357 | malloc/free before we run */ |
| 358 | VALGRIND_MAGIC_SEQUENCE(res, 0, VG_USERREQ__REGISTER_REDIRECT_ADDR, |
| 359 | "soname:ld-linux.so.2", replacements[i].libname, |
| 360 | replacements[i].func, 0); |
| 361 | #endif |
| 362 | VALGRIND_MAGIC_SEQUENCE(res, 0, VG_USERREQ__REGISTER_REDIRECT_ADDR, |
| 363 | "soname:libc.so.6", replacements[i].libname, |
| 364 | replacements[i].func, 0); |
| 365 | VALGRIND_MAGIC_SEQUENCE(res, 0, VG_USERREQ__REGISTER_REDIRECT_ADDR, |
| 366 | "soname:libstdc++*", replacements[i].libname, |
| 367 | replacements[i].func, 0); |
| 368 | } |
| 369 | } |
| 370 | |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 371 | /*--------------------------------------------------------------------*/ |
| 372 | /*--- end vg_replace_malloc.c ---*/ |
| 373 | /*--------------------------------------------------------------------*/ |