njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 1 | |
| 2 | /*--------------------------------------------------------------------*/ |
| 3 | /*--- malloc/free wrappers for detecting errors and updating bits. ---*/ |
| 4 | /*--- mac_malloc_wrappers.c ---*/ |
| 5 | /*--------------------------------------------------------------------*/ |
| 6 | |
| 7 | /* |
nethercote | 137bc55 | 2003-11-14 17:47:54 +0000 | [diff] [blame] | 8 | This file is part of MemCheck, a heavyweight Valgrind tool for |
| 9 | detecting memory errors, and AddrCheck, a lightweight Valgrind tool |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 10 | for detecting memory errors. |
| 11 | |
njn | 5361242 | 2005-03-12 16:22:54 +0000 | [diff] [blame] | 12 | Copyright (C) 2000-2005 Julian Seward |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 13 | jseward@acm.org |
| 14 | |
| 15 | This program is free software; you can redistribute it and/or |
| 16 | modify it under the terms of the GNU General Public License as |
| 17 | published by the Free Software Foundation; either version 2 of the |
| 18 | License, or (at your option) any later version. |
| 19 | |
| 20 | This program is distributed in the hope that it will be useful, but |
| 21 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 23 | General Public License for more details. |
| 24 | |
| 25 | You should have received a copy of the GNU General Public License |
| 26 | along with this program; if not, write to the Free Software |
| 27 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 28 | 02111-1307, USA. |
| 29 | |
| 30 | The GNU General Public License is contained in the file COPYING. |
| 31 | */ |
| 32 | |
njn | c7561b9 | 2005-06-19 01:24:32 +0000 | [diff] [blame] | 33 | #include "pub_tool_basics.h" |
| 34 | #include "pub_tool_errormgr.h" // For mac_shared.h |
| 35 | #include "pub_tool_execontext.h" // For mac_shared.h |
| 36 | #include "pub_tool_hashtable.h" // For mac_shared.h |
njn | 97405b2 | 2005-06-02 03:39:33 +0000 | [diff] [blame] | 37 | #include "pub_tool_libcbase.h" |
njn | 132bfcc | 2005-06-04 19:16:06 +0000 | [diff] [blame] | 38 | #include "pub_tool_libcassert.h" |
njn | 36a20fa | 2005-06-03 03:08:39 +0000 | [diff] [blame] | 39 | #include "pub_tool_libcprint.h" |
njn | c7561b9 | 2005-06-19 01:24:32 +0000 | [diff] [blame] | 40 | #include "pub_tool_mallocfree.h" |
| 41 | #include "pub_tool_options.h" |
njn | c7561b9 | 2005-06-19 01:24:32 +0000 | [diff] [blame] | 42 | #include "pub_tool_replacemalloc.h" |
| 43 | #include "pub_tool_threadstate.h" |
| 44 | #include "mac_shared.h" |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 45 | |
| 46 | /*------------------------------------------------------------*/ |
| 47 | /*--- Defns ---*/ |
| 48 | /*------------------------------------------------------------*/ |
| 49 | |
| 50 | /* Stats ... */ |
nethercote | 7ac7f7b | 2004-11-02 12:36:02 +0000 | [diff] [blame] | 51 | static SizeT cmalloc_n_mallocs = 0; |
| 52 | static SizeT cmalloc_n_frees = 0; |
| 53 | static SizeT cmalloc_bs_mallocd = 0; |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 54 | |
nethercote | 7cc9c23 | 2004-01-21 15:08:04 +0000 | [diff] [blame] | 55 | /* Function pointers for the two tools to track interesting events. */ |
nethercote | 451eae9 | 2004-11-02 13:06:32 +0000 | [diff] [blame] | 56 | void (*MAC_(new_mem_heap)) ( Addr a, SizeT len, Bool is_inited ) = NULL; |
| 57 | void (*MAC_(ban_mem_heap)) ( Addr a, SizeT len ) = NULL; |
| 58 | void (*MAC_(die_mem_heap)) ( Addr a, SizeT len ) = NULL; |
| 59 | void (*MAC_(copy_mem_heap))( Addr from, Addr to, SizeT len ) = NULL; |
sewardj | ecf8e10 | 2003-07-12 12:11:39 +0000 | [diff] [blame] | 60 | |
| 61 | /* Function pointers for internal sanity checking. */ |
nethercote | 451eae9 | 2004-11-02 13:06:32 +0000 | [diff] [blame] | 62 | Bool (*MAC_(check_noaccess))( Addr a, SizeT len, Addr* bad_addr ) = NULL; |
sewardj | f9025f7 | 2003-07-12 01:41:24 +0000 | [diff] [blame] | 63 | |
| 64 | |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 65 | /*------------------------------------------------------------*/ |
| 66 | /*--- Tracking malloc'd and free'd blocks ---*/ |
| 67 | /*------------------------------------------------------------*/ |
| 68 | |
njn | 9a46324 | 2005-08-16 03:29:50 +0000 | [diff] [blame] | 69 | /* Record malloc'd blocks. */ |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 70 | VgHashTable MAC_(malloc_list) = NULL; |
rjwalsh | bc0bb83 | 2004-06-19 18:12:36 +0000 | [diff] [blame] | 71 | |
njn | 9a46324 | 2005-08-16 03:29:50 +0000 | [diff] [blame] | 72 | /* Memory pools. */ |
rjwalsh | bc0bb83 | 2004-06-19 18:12:36 +0000 | [diff] [blame] | 73 | VgHashTable MAC_(mempool_list) = NULL; |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 74 | |
| 75 | /* Records blocks after freeing. */ |
| 76 | static MAC_Chunk* freed_list_start = NULL; |
| 77 | static MAC_Chunk* freed_list_end = NULL; |
| 78 | static Int freed_list_volume = 0; |
| 79 | |
| 80 | /* Put a shadow chunk on the freed blocks queue, possibly freeing up |
| 81 | some of the oldest blocks in the queue at the same time. */ |
| 82 | static void add_to_freed_queue ( MAC_Chunk* mc ) |
| 83 | { |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 84 | /* Put it at the end of the freed list */ |
| 85 | if (freed_list_end == NULL) { |
njn | ca82cc0 | 2004-11-22 17:18:48 +0000 | [diff] [blame] | 86 | tl_assert(freed_list_start == NULL); |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 87 | freed_list_end = freed_list_start = mc; |
| 88 | freed_list_volume = mc->size; |
| 89 | } else { |
njn | ca82cc0 | 2004-11-22 17:18:48 +0000 | [diff] [blame] | 90 | tl_assert(freed_list_end->next == NULL); |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 91 | freed_list_end->next = mc; |
| 92 | freed_list_end = mc; |
| 93 | freed_list_volume += mc->size; |
| 94 | } |
| 95 | mc->next = NULL; |
| 96 | |
| 97 | /* Release enough of the oldest blocks to bring the free queue |
| 98 | volume below vg_clo_freelist_vol. */ |
| 99 | |
| 100 | while (freed_list_volume > MAC_(clo_freelist_vol)) { |
njn | 9a46324 | 2005-08-16 03:29:50 +0000 | [diff] [blame] | 101 | MAC_Chunk* mc1; |
| 102 | |
njn | ca82cc0 | 2004-11-22 17:18:48 +0000 | [diff] [blame] | 103 | tl_assert(freed_list_start != NULL); |
| 104 | tl_assert(freed_list_end != NULL); |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 105 | |
njn | 5cc5d7e | 2005-08-11 02:09:25 +0000 | [diff] [blame] | 106 | mc1 = freed_list_start; |
| 107 | freed_list_volume -= mc1->size; |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 108 | /* VG_(printf)("volume now %d\n", freed_list_volume); */ |
njn | ca82cc0 | 2004-11-22 17:18:48 +0000 | [diff] [blame] | 109 | tl_assert(freed_list_volume >= 0); |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 110 | |
| 111 | if (freed_list_start == freed_list_end) { |
| 112 | freed_list_start = freed_list_end = NULL; |
| 113 | } else { |
njn | 5cc5d7e | 2005-08-11 02:09:25 +0000 | [diff] [blame] | 114 | freed_list_start = mc1->next; |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 115 | } |
njn | 5cc5d7e | 2005-08-11 02:09:25 +0000 | [diff] [blame] | 116 | mc1->next = NULL; /* just paranoia */ |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 117 | |
| 118 | /* free MAC_Chunk */ |
njn | 5cc5d7e | 2005-08-11 02:09:25 +0000 | [diff] [blame] | 119 | VG_(cli_free) ( (void*)(mc1->data) ); |
| 120 | VG_(free) ( mc1 ); |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 121 | } |
| 122 | } |
| 123 | |
njn | 1d0cb0d | 2005-08-15 01:52:02 +0000 | [diff] [blame] | 124 | MAC_Chunk* MAC_(get_freed_list_head)(void) |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 125 | { |
njn | 1d0cb0d | 2005-08-15 01:52:02 +0000 | [diff] [blame] | 126 | return freed_list_start; |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 127 | } |
| 128 | |
njn | 1078545 | 2003-05-20 16:38:24 +0000 | [diff] [blame] | 129 | /* Allocate its shadow chunk, put it on the appropriate list. */ |
| 130 | static |
njn | 5cc5d7e | 2005-08-11 02:09:25 +0000 | [diff] [blame] | 131 | MAC_Chunk* create_MAC_Chunk ( ThreadId tid, Addr p, SizeT size, |
| 132 | MAC_AllocKind kind) |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 133 | { |
njn | 5cc5d7e | 2005-08-11 02:09:25 +0000 | [diff] [blame] | 134 | MAC_Chunk* mc = VG_(malloc)(sizeof(MAC_Chunk)); |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 135 | mc->data = p; |
| 136 | mc->size = size; |
| 137 | mc->allockind = kind; |
njn | d01fef7 | 2005-03-25 23:35:48 +0000 | [diff] [blame] | 138 | mc->where = VG_(record_ExeContext)(tid); |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 139 | |
njn | 9a46324 | 2005-08-16 03:29:50 +0000 | [diff] [blame] | 140 | /* Paranoia ... ensure the MAC_Chunk is off-limits to the client, so |
sewardj | ecf8e10 | 2003-07-12 12:11:39 +0000 | [diff] [blame] | 141 | the mc->data field isn't visible to the leak checker. If memory |
njn | 9a46324 | 2005-08-16 03:29:50 +0000 | [diff] [blame] | 142 | management is working correctly, any pointer returned by VG_(malloc) |
| 143 | should be noaccess as far as the client is concerned. */ |
sewardj | ecf8e10 | 2003-07-12 12:11:39 +0000 | [diff] [blame] | 144 | if (!MAC_(check_noaccess)( (Addr)mc, sizeof(MAC_Chunk), NULL )) { |
njn | 5cc5d7e | 2005-08-11 02:09:25 +0000 | [diff] [blame] | 145 | VG_(tool_panic)("create_MAC_Chunk: shadow area is accessible"); |
sewardj | ecf8e10 | 2003-07-12 12:11:39 +0000 | [diff] [blame] | 146 | } |
njn | 5cc5d7e | 2005-08-11 02:09:25 +0000 | [diff] [blame] | 147 | return mc; |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | /*------------------------------------------------------------*/ |
| 151 | /*--- client_malloc(), etc ---*/ |
| 152 | /*------------------------------------------------------------*/ |
| 153 | |
nethercote | 7ac7f7b | 2004-11-02 12:36:02 +0000 | [diff] [blame] | 154 | static Bool complain_about_silly_args(SizeT sizeB, Char* fn) |
| 155 | { |
| 156 | // Cast to a signed type to catch any unexpectedly negative args. We're |
| 157 | // assuming here that the size asked for is not greater than 2^31 bytes |
| 158 | // (for 32-bit platforms) or 2^63 bytes (for 64-bit platforms). |
| 159 | if ((SSizeT)sizeB < 0) { |
tom | c1bcf10 | 2005-10-13 15:29:39 +0000 | [diff] [blame] | 160 | VG_(message)(Vg_UserMsg, "Warning: silly arg (%ld) to %s()", |
| 161 | (SSizeT)sizeB, fn ); |
nethercote | 7ac7f7b | 2004-11-02 12:36:02 +0000 | [diff] [blame] | 162 | return True; |
| 163 | } |
| 164 | return False; |
| 165 | } |
| 166 | |
| 167 | static Bool complain_about_silly_args2(SizeT n, SizeT sizeB) |
| 168 | { |
| 169 | if ((SSizeT)n < 0 || (SSizeT)sizeB < 0) { |
tom | c1bcf10 | 2005-10-13 15:29:39 +0000 | [diff] [blame] | 170 | VG_(message)(Vg_UserMsg, "Warning: silly args (%ld,%ld) to calloc()", |
| 171 | (SSizeT)n, (SSizeT)sizeB); |
nethercote | 7ac7f7b | 2004-11-02 12:36:02 +0000 | [diff] [blame] | 172 | return True; |
| 173 | } |
| 174 | return False; |
| 175 | } |
| 176 | |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 177 | /* Allocate memory and note change in memory available */ |
njn | 1078545 | 2003-05-20 16:38:24 +0000 | [diff] [blame] | 178 | __inline__ |
sewardj | 2a99cf6 | 2004-11-24 10:44:19 +0000 | [diff] [blame] | 179 | void* MAC_(new_block) ( ThreadId tid, |
| 180 | Addr p, SizeT size, SizeT align, UInt rzB, |
nethercote | 57e36b3 | 2004-07-10 14:56:28 +0000 | [diff] [blame] | 181 | Bool is_zeroed, MAC_AllocKind kind, VgHashTable table) |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 182 | { |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 183 | cmalloc_n_mallocs ++; |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 184 | |
nethercote | 57e36b3 | 2004-07-10 14:56:28 +0000 | [diff] [blame] | 185 | // Allocate and zero if necessary |
| 186 | if (p) { |
njn | ca82cc0 | 2004-11-22 17:18:48 +0000 | [diff] [blame] | 187 | tl_assert(MAC_AllocCustom == kind); |
nethercote | 57e36b3 | 2004-07-10 14:56:28 +0000 | [diff] [blame] | 188 | } else { |
njn | ca82cc0 | 2004-11-22 17:18:48 +0000 | [diff] [blame] | 189 | tl_assert(MAC_AllocCustom != kind); |
nethercote | 57e36b3 | 2004-07-10 14:56:28 +0000 | [diff] [blame] | 190 | p = (Addr)VG_(cli_malloc)( align, size ); |
| 191 | if (!p) { |
nethercote | 57e36b3 | 2004-07-10 14:56:28 +0000 | [diff] [blame] | 192 | return NULL; |
| 193 | } |
| 194 | if (is_zeroed) VG_(memset)((void*)p, 0, size); |
| 195 | } |
| 196 | |
njn | 2a513bf | 2005-06-30 02:34:32 +0000 | [diff] [blame] | 197 | // Only update this stat if allocation succeeded. |
| 198 | cmalloc_bs_mallocd += size; |
| 199 | |
njn | 246a9d2 | 2005-08-14 06:24:20 +0000 | [diff] [blame] | 200 | VG_(HT_add_node)( table, create_MAC_Chunk(tid, p, size, kind) ); |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 201 | |
njn | 1078545 | 2003-05-20 16:38:24 +0000 | [diff] [blame] | 202 | MAC_(ban_mem_heap)( p-rzB, rzB ); |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 203 | MAC_(new_mem_heap)( p, size, is_zeroed ); |
njn | 1078545 | 2003-05-20 16:38:24 +0000 | [diff] [blame] | 204 | MAC_(ban_mem_heap)( p+size, rzB ); |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 205 | |
nethercote | 57e36b3 | 2004-07-10 14:56:28 +0000 | [diff] [blame] | 206 | return (void*)p; |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 207 | } |
| 208 | |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 209 | void* MAC_(malloc) ( ThreadId tid, SizeT n ) |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 210 | { |
nethercote | 7ac7f7b | 2004-11-02 12:36:02 +0000 | [diff] [blame] | 211 | if (complain_about_silly_args(n, "malloc")) { |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 212 | return NULL; |
| 213 | } else { |
sewardj | 2a99cf6 | 2004-11-24 10:44:19 +0000 | [diff] [blame] | 214 | return MAC_(new_block) ( tid, 0, n, VG_(clo_alignment), |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 215 | MAC_MALLOC_REDZONE_SZB, /*is_zeroed*/False, MAC_AllocMalloc, |
nethercote | 57e36b3 | 2004-07-10 14:56:28 +0000 | [diff] [blame] | 216 | MAC_(malloc_list)); |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 217 | } |
| 218 | } |
| 219 | |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 220 | void* MAC_(__builtin_new) ( ThreadId tid, SizeT n ) |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 221 | { |
nethercote | 7ac7f7b | 2004-11-02 12:36:02 +0000 | [diff] [blame] | 222 | if (complain_about_silly_args(n, "__builtin_new")) { |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 223 | return NULL; |
| 224 | } else { |
sewardj | 2a99cf6 | 2004-11-24 10:44:19 +0000 | [diff] [blame] | 225 | return MAC_(new_block) ( tid, 0, n, VG_(clo_alignment), |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 226 | MAC_MALLOC_REDZONE_SZB, /*is_zeroed*/False, MAC_AllocNew, |
nethercote | 57e36b3 | 2004-07-10 14:56:28 +0000 | [diff] [blame] | 227 | MAC_(malloc_list)); |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 228 | } |
| 229 | } |
| 230 | |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 231 | void* MAC_(__builtin_vec_new) ( ThreadId tid, SizeT n ) |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 232 | { |
nethercote | 7ac7f7b | 2004-11-02 12:36:02 +0000 | [diff] [blame] | 233 | if (complain_about_silly_args(n, "__builtin_vec_new")) { |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 234 | return NULL; |
| 235 | } else { |
sewardj | 2a99cf6 | 2004-11-24 10:44:19 +0000 | [diff] [blame] | 236 | return MAC_(new_block) ( tid, 0, n, VG_(clo_alignment), |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 237 | MAC_MALLOC_REDZONE_SZB, /*is_zeroed*/False, MAC_AllocNewVec, |
nethercote | 57e36b3 | 2004-07-10 14:56:28 +0000 | [diff] [blame] | 238 | MAC_(malloc_list)); |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 239 | } |
| 240 | } |
| 241 | |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 242 | void* MAC_(memalign) ( ThreadId tid, SizeT align, SizeT n ) |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 243 | { |
nethercote | 7ac7f7b | 2004-11-02 12:36:02 +0000 | [diff] [blame] | 244 | if (complain_about_silly_args(n, "memalign")) { |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 245 | return NULL; |
| 246 | } else { |
sewardj | 2a99cf6 | 2004-11-24 10:44:19 +0000 | [diff] [blame] | 247 | return MAC_(new_block) ( tid, 0, n, align, |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 248 | MAC_MALLOC_REDZONE_SZB, /*is_zeroed*/False, MAC_AllocMalloc, |
nethercote | 57e36b3 | 2004-07-10 14:56:28 +0000 | [diff] [blame] | 249 | MAC_(malloc_list)); |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 250 | } |
| 251 | } |
| 252 | |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 253 | void* MAC_(calloc) ( ThreadId tid, SizeT nmemb, SizeT size1 ) |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 254 | { |
nethercote | 7ac7f7b | 2004-11-02 12:36:02 +0000 | [diff] [blame] | 255 | if (complain_about_silly_args2(nmemb, size1)) { |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 256 | return NULL; |
| 257 | } else { |
sewardj | 2a99cf6 | 2004-11-24 10:44:19 +0000 | [diff] [blame] | 258 | return MAC_(new_block) ( tid, 0, nmemb*size1, VG_(clo_alignment), |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 259 | MAC_MALLOC_REDZONE_SZB, /*is_zeroed*/True, MAC_AllocMalloc, |
nethercote | 57e36b3 | 2004-07-10 14:56:28 +0000 | [diff] [blame] | 260 | MAC_(malloc_list)); |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 261 | } |
| 262 | } |
| 263 | |
| 264 | static |
njn | 34582fb | 2005-08-11 00:06:36 +0000 | [diff] [blame] | 265 | void die_and_free_mem ( ThreadId tid, MAC_Chunk* mc, SizeT rzB ) |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 266 | { |
| 267 | /* Note: ban redzones again -- just in case user de-banned them |
| 268 | with a client request... */ |
njn | 1078545 | 2003-05-20 16:38:24 +0000 | [diff] [blame] | 269 | MAC_(ban_mem_heap)( mc->data-rzB, rzB ); |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 270 | MAC_(die_mem_heap)( mc->data, mc->size ); |
njn | 1078545 | 2003-05-20 16:38:24 +0000 | [diff] [blame] | 271 | MAC_(ban_mem_heap)( mc->data+mc->size, rzB ); |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 272 | |
njn | 1078545 | 2003-05-20 16:38:24 +0000 | [diff] [blame] | 273 | /* Put it out of harm's way for a while, if not from a client request */ |
rjwalsh | bc0bb83 | 2004-06-19 18:12:36 +0000 | [diff] [blame] | 274 | if (MAC_AllocCustom != mc->allockind) { |
| 275 | /* Record where freed */ |
njn | d01fef7 | 2005-03-25 23:35:48 +0000 | [diff] [blame] | 276 | mc->where = VG_(record_ExeContext) ( tid ); |
njn | 1078545 | 2003-05-20 16:38:24 +0000 | [diff] [blame] | 277 | add_to_freed_queue ( mc ); |
njn | 4bd67b5 | 2005-08-11 00:47:10 +0000 | [diff] [blame] | 278 | } else { |
njn | 1078545 | 2003-05-20 16:38:24 +0000 | [diff] [blame] | 279 | VG_(free) ( mc ); |
njn | 4bd67b5 | 2005-08-11 00:47:10 +0000 | [diff] [blame] | 280 | } |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 281 | } |
| 282 | |
njn | 1078545 | 2003-05-20 16:38:24 +0000 | [diff] [blame] | 283 | __inline__ |
sewardj | 2a99cf6 | 2004-11-24 10:44:19 +0000 | [diff] [blame] | 284 | void MAC_(handle_free) ( ThreadId tid, Addr p, UInt rzB, MAC_AllocKind kind ) |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 285 | { |
njn | 5cc5d7e | 2005-08-11 02:09:25 +0000 | [diff] [blame] | 286 | MAC_Chunk* mc; |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 287 | |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 288 | cmalloc_n_frees++; |
| 289 | |
njn | 9a46324 | 2005-08-16 03:29:50 +0000 | [diff] [blame] | 290 | mc = VG_(HT_remove) ( MAC_(malloc_list), (UWord)p ); |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 291 | if (mc == NULL) { |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 292 | MAC_(record_free_error) ( tid, p ); |
njn | 9a46324 | 2005-08-16 03:29:50 +0000 | [diff] [blame] | 293 | } else { |
njn | a079365 | 2005-08-16 03:34:56 +0000 | [diff] [blame] | 294 | /* check if it is a matching free() / delete / delete [] */ |
njn | 9a46324 | 2005-08-16 03:29:50 +0000 | [diff] [blame] | 295 | if (kind != mc->allockind) { |
| 296 | MAC_(record_freemismatch_error) ( tid, p, mc ); |
| 297 | } |
| 298 | die_and_free_mem ( tid, mc, rzB ); |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 299 | } |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 300 | } |
| 301 | |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 302 | void MAC_(free) ( ThreadId tid, void* p ) |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 303 | { |
sewardj | 2a99cf6 | 2004-11-24 10:44:19 +0000 | [diff] [blame] | 304 | MAC_(handle_free)( |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 305 | tid, (Addr)p, MAC_MALLOC_REDZONE_SZB, MAC_AllocMalloc ); |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 306 | } |
| 307 | |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 308 | void MAC_(__builtin_delete) ( ThreadId tid, void* p ) |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 309 | { |
sewardj | 2a99cf6 | 2004-11-24 10:44:19 +0000 | [diff] [blame] | 310 | MAC_(handle_free)( |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 311 | tid, (Addr)p, MAC_MALLOC_REDZONE_SZB, MAC_AllocNew); |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 312 | } |
| 313 | |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 314 | void MAC_(__builtin_vec_delete) ( ThreadId tid, void* p ) |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 315 | { |
sewardj | 2a99cf6 | 2004-11-24 10:44:19 +0000 | [diff] [blame] | 316 | MAC_(handle_free)( |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 317 | tid, (Addr)p, MAC_MALLOC_REDZONE_SZB, MAC_AllocNewVec); |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 318 | } |
| 319 | |
njn | 5cc5d7e | 2005-08-11 02:09:25 +0000 | [diff] [blame] | 320 | void* MAC_(realloc) ( ThreadId tid, void* p_old, SizeT new_size ) |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 321 | { |
njn | 5cc5d7e | 2005-08-11 02:09:25 +0000 | [diff] [blame] | 322 | MAC_Chunk* mc; |
| 323 | void* p_new; |
| 324 | SizeT old_size; |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 325 | |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 326 | cmalloc_n_frees ++; |
| 327 | cmalloc_n_mallocs ++; |
| 328 | cmalloc_bs_mallocd += new_size; |
| 329 | |
nethercote | 7ac7f7b | 2004-11-02 12:36:02 +0000 | [diff] [blame] | 330 | if (complain_about_silly_args(new_size, "realloc")) |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 331 | return NULL; |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 332 | |
njn | 5cc5d7e | 2005-08-11 02:09:25 +0000 | [diff] [blame] | 333 | /* Remove the old block */ |
njn | 9a46324 | 2005-08-16 03:29:50 +0000 | [diff] [blame] | 334 | mc = VG_(HT_remove) ( MAC_(malloc_list), (UWord)p_old ); |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 335 | if (mc == NULL) { |
njn | 5cc5d7e | 2005-08-11 02:09:25 +0000 | [diff] [blame] | 336 | MAC_(record_free_error) ( tid, (Addr)p_old ); |
njn | 9a46324 | 2005-08-16 03:29:50 +0000 | [diff] [blame] | 337 | /* We return to the program regardless. */ |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 338 | return NULL; |
| 339 | } |
njn | 5cc5d7e | 2005-08-11 02:09:25 +0000 | [diff] [blame] | 340 | |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 341 | /* check if its a matching free() / delete / delete [] */ |
| 342 | if (MAC_AllocMalloc != mc->allockind) { |
| 343 | /* can not realloc a range that was allocated with new or new [] */ |
njn | 5cc5d7e | 2005-08-11 02:09:25 +0000 | [diff] [blame] | 344 | MAC_(record_freemismatch_error) ( tid, (Addr)p_old, mc ); |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 345 | /* but keep going anyway */ |
| 346 | } |
| 347 | |
njn | 5cc5d7e | 2005-08-11 02:09:25 +0000 | [diff] [blame] | 348 | old_size = mc->size; |
| 349 | |
| 350 | if (old_size == new_size) { |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 351 | /* size unchanged */ |
njn | d01fef7 | 2005-03-25 23:35:48 +0000 | [diff] [blame] | 352 | mc->where = VG_(record_ExeContext)(tid); |
njn | 5cc5d7e | 2005-08-11 02:09:25 +0000 | [diff] [blame] | 353 | p_new = p_old; |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 354 | |
njn | 5cc5d7e | 2005-08-11 02:09:25 +0000 | [diff] [blame] | 355 | } else if (old_size > new_size) { |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 356 | /* new size is smaller */ |
| 357 | MAC_(die_mem_heap)( mc->data+new_size, mc->size-new_size ); |
| 358 | mc->size = new_size; |
njn | d01fef7 | 2005-03-25 23:35:48 +0000 | [diff] [blame] | 359 | mc->where = VG_(record_ExeContext)(tid); |
njn | 5cc5d7e | 2005-08-11 02:09:25 +0000 | [diff] [blame] | 360 | p_new = p_old; |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 361 | |
| 362 | } else { |
| 363 | /* new size is bigger */ |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 364 | /* Get new memory */ |
njn | 5cc5d7e | 2005-08-11 02:09:25 +0000 | [diff] [blame] | 365 | Addr a_new = (Addr)VG_(cli_malloc)(VG_(clo_alignment), new_size); |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 366 | |
tom | 0cd42f0 | 2005-10-06 09:00:17 +0000 | [diff] [blame] | 367 | if (a_new) { |
| 368 | /* First half kept and copied, second half new, red zones as normal */ |
| 369 | MAC_(ban_mem_heap) ( a_new-MAC_MALLOC_REDZONE_SZB, MAC_MALLOC_REDZONE_SZB ); |
| 370 | MAC_(copy_mem_heap)( (Addr)p_old, a_new, mc->size ); |
| 371 | MAC_(new_mem_heap) ( a_new+mc->size, new_size-mc->size, /*init'd*/False ); |
| 372 | MAC_(ban_mem_heap) ( a_new+new_size, MAC_MALLOC_REDZONE_SZB ); |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 373 | |
tom | 0cd42f0 | 2005-10-06 09:00:17 +0000 | [diff] [blame] | 374 | /* Copy from old to new */ |
| 375 | VG_(memcpy)((void*)a_new, p_old, mc->size); |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 376 | |
tom | 0cd42f0 | 2005-10-06 09:00:17 +0000 | [diff] [blame] | 377 | /* Free old memory */ |
| 378 | /* Nb: we have to allocate a new MAC_Chunk for the new memory rather |
| 379 | than recycling the old one, so that any erroneous accesses to the |
| 380 | old memory are reported. */ |
| 381 | die_and_free_mem ( tid, mc, MAC_MALLOC_REDZONE_SZB ); |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 382 | |
tom | 0cd42f0 | 2005-10-06 09:00:17 +0000 | [diff] [blame] | 383 | // Allocate a new chunk. |
| 384 | mc = create_MAC_Chunk( tid, a_new, new_size, MAC_AllocMalloc ); |
| 385 | } |
| 386 | |
njn | 5cc5d7e | 2005-08-11 02:09:25 +0000 | [diff] [blame] | 387 | p_new = (void*)a_new; |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 388 | } |
njn | 5cc5d7e | 2005-08-11 02:09:25 +0000 | [diff] [blame] | 389 | |
| 390 | // Now insert the new mc (with a possibly new 'data' field) into |
| 391 | // malloc_list. If this realloc() did not increase the memory size, we |
| 392 | // will have removed and then re-added mc unnecessarily. But that's ok |
| 393 | // because shrinking a block with realloc() is (presumably) much rarer |
| 394 | // than growing it, and this way simplifies the growing case. |
njn | 246a9d2 | 2005-08-14 06:24:20 +0000 | [diff] [blame] | 395 | VG_(HT_add_node)( MAC_(malloc_list), mc ); |
njn | 5cc5d7e | 2005-08-11 02:09:25 +0000 | [diff] [blame] | 396 | |
njn | 5cc5d7e | 2005-08-11 02:09:25 +0000 | [diff] [blame] | 397 | return p_new; |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 398 | } |
| 399 | |
rjwalsh | bc0bb83 | 2004-06-19 18:12:36 +0000 | [diff] [blame] | 400 | /* Memory pool stuff. */ |
| 401 | |
| 402 | void MAC_(create_mempool)(Addr pool, UInt rzB, Bool is_zeroed) |
| 403 | { |
njn | 9a46324 | 2005-08-16 03:29:50 +0000 | [diff] [blame] | 404 | MAC_Mempool* mp = VG_(malloc)(sizeof(MAC_Mempool)); |
| 405 | mp->pool = pool; |
| 406 | mp->rzB = rzB; |
| 407 | mp->is_zeroed = is_zeroed; |
| 408 | mp->chunks = VG_(HT_construct)( 3001 ); // prime, not so big |
rjwalsh | bc0bb83 | 2004-06-19 18:12:36 +0000 | [diff] [blame] | 409 | |
| 410 | /* Paranoia ... ensure this area is off-limits to the client, so |
| 411 | the mp->data field isn't visible to the leak checker. If memory |
| 412 | management is working correctly, anything pointer returned by |
| 413 | VG_(malloc) should be noaccess as far as the client is |
| 414 | concerned. */ |
| 415 | if (!MAC_(check_noaccess)( (Addr)mp, sizeof(MAC_Mempool), NULL )) { |
njn | 6799325 | 2004-11-22 18:02:32 +0000 | [diff] [blame] | 416 | VG_(tool_panic)("MAC_(create_mempool): shadow area is accessible"); |
rjwalsh | bc0bb83 | 2004-06-19 18:12:36 +0000 | [diff] [blame] | 417 | } |
| 418 | |
njn | 246a9d2 | 2005-08-14 06:24:20 +0000 | [diff] [blame] | 419 | VG_(HT_add_node)( MAC_(mempool_list), mp ); |
rjwalsh | bc0bb83 | 2004-06-19 18:12:36 +0000 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | void MAC_(destroy_mempool)(Addr pool) |
| 423 | { |
njn | 1d0cb0d | 2005-08-15 01:52:02 +0000 | [diff] [blame] | 424 | MAC_Chunk* mc; |
thughes | 4ad52d0 | 2004-06-27 17:37:21 +0000 | [diff] [blame] | 425 | MAC_Mempool* mp; |
rjwalsh | bc0bb83 | 2004-06-19 18:12:36 +0000 | [diff] [blame] | 426 | |
njn | 1262727 | 2005-08-14 18:32:16 +0000 | [diff] [blame] | 427 | mp = VG_(HT_remove) ( MAC_(mempool_list), (UWord)pool ); |
rjwalsh | bc0bb83 | 2004-06-19 18:12:36 +0000 | [diff] [blame] | 428 | |
| 429 | if (mp == NULL) { |
sewardj | 76754cf | 2005-03-14 00:14:04 +0000 | [diff] [blame] | 430 | ThreadId tid = VG_(get_running_tid)(); |
rjwalsh | bc0bb83 | 2004-06-19 18:12:36 +0000 | [diff] [blame] | 431 | MAC_(record_illegal_mempool_error) ( tid, pool ); |
| 432 | return; |
| 433 | } |
| 434 | |
njn | 1d0cb0d | 2005-08-15 01:52:02 +0000 | [diff] [blame] | 435 | // Clean up the chunks, one by one |
| 436 | VG_(HT_ResetIter)(mp->chunks); |
| 437 | while ( (mc = VG_(HT_Next)(mp->chunks)) ) { |
| 438 | /* Note: ban redzones again -- just in case user de-banned them |
| 439 | with a client request... */ |
| 440 | MAC_(ban_mem_heap)(mc->data-mp->rzB, mp->rzB ); |
| 441 | MAC_(die_mem_heap)(mc->data, mc->size ); |
| 442 | MAC_(ban_mem_heap)(mc->data+mc->size, mp->rzB ); |
| 443 | } |
| 444 | // Destroy the chunk table |
rjwalsh | bc0bb83 | 2004-06-19 18:12:36 +0000 | [diff] [blame] | 445 | VG_(HT_destruct)(mp->chunks); |
| 446 | |
| 447 | VG_(free)(mp); |
| 448 | } |
| 449 | |
sewardj | 2a99cf6 | 2004-11-24 10:44:19 +0000 | [diff] [blame] | 450 | void MAC_(mempool_alloc)(ThreadId tid, Addr pool, Addr addr, SizeT size) |
rjwalsh | bc0bb83 | 2004-06-19 18:12:36 +0000 | [diff] [blame] | 451 | { |
njn | 9a46324 | 2005-08-16 03:29:50 +0000 | [diff] [blame] | 452 | MAC_Mempool* mp = VG_(HT_lookup) ( MAC_(mempool_list), (UWord)pool ); |
rjwalsh | bc0bb83 | 2004-06-19 18:12:36 +0000 | [diff] [blame] | 453 | |
| 454 | if (mp == NULL) { |
rjwalsh | bc0bb83 | 2004-06-19 18:12:36 +0000 | [diff] [blame] | 455 | MAC_(record_illegal_mempool_error) ( tid, pool ); |
njn | 9a46324 | 2005-08-16 03:29:50 +0000 | [diff] [blame] | 456 | } else { |
| 457 | MAC_(new_block)(tid, addr, size, /*ignored*/0, mp->rzB, mp->is_zeroed, |
| 458 | MAC_AllocCustom, mp->chunks); |
rjwalsh | bc0bb83 | 2004-06-19 18:12:36 +0000 | [diff] [blame] | 459 | } |
rjwalsh | bc0bb83 | 2004-06-19 18:12:36 +0000 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | void MAC_(mempool_free)(Addr pool, Addr addr) |
| 463 | { |
| 464 | MAC_Mempool* mp; |
rjwalsh | bc0bb83 | 2004-06-19 18:12:36 +0000 | [diff] [blame] | 465 | MAC_Chunk* mc; |
sewardj | 76754cf | 2005-03-14 00:14:04 +0000 | [diff] [blame] | 466 | ThreadId tid = VG_(get_running_tid)(); |
rjwalsh | bc0bb83 | 2004-06-19 18:12:36 +0000 | [diff] [blame] | 467 | |
njn | 1262727 | 2005-08-14 18:32:16 +0000 | [diff] [blame] | 468 | mp = VG_(HT_lookup)(MAC_(mempool_list), (UWord)pool); |
rjwalsh | bc0bb83 | 2004-06-19 18:12:36 +0000 | [diff] [blame] | 469 | if (mp == NULL) { |
| 470 | MAC_(record_illegal_mempool_error)(tid, pool); |
| 471 | return; |
| 472 | } |
| 473 | |
njn | 9a46324 | 2005-08-16 03:29:50 +0000 | [diff] [blame] | 474 | mc = VG_(HT_remove)(mp->chunks, (UWord)addr); |
rjwalsh | bc0bb83 | 2004-06-19 18:12:36 +0000 | [diff] [blame] | 475 | if (mc == NULL) { |
| 476 | MAC_(record_free_error)(tid, (Addr)addr); |
| 477 | return; |
| 478 | } |
| 479 | |
njn | 34582fb | 2005-08-11 00:06:36 +0000 | [diff] [blame] | 480 | die_and_free_mem ( tid, mc, mp->rzB ); |
rjwalsh | bc0bb83 | 2004-06-19 18:12:36 +0000 | [diff] [blame] | 481 | } |
| 482 | |
njn | 86f12dc | 2005-03-14 01:16:05 +0000 | [diff] [blame] | 483 | /*------------------------------------------------------------*/ |
| 484 | /*--- Statistics printing ---*/ |
| 485 | /*------------------------------------------------------------*/ |
| 486 | |
njn | 86f12dc | 2005-03-14 01:16:05 +0000 | [diff] [blame] | 487 | void MAC_(print_malloc_stats) ( void ) |
| 488 | { |
njn | 1d0cb0d | 2005-08-15 01:52:02 +0000 | [diff] [blame] | 489 | MAC_Chunk* mc; |
njn | 0fd92f4 | 2005-10-06 03:32:42 +0000 | [diff] [blame] | 490 | SizeT nblocks = 0; |
njn | 1d0cb0d | 2005-08-15 01:52:02 +0000 | [diff] [blame] | 491 | SizeT nbytes = 0; |
njn | 86f12dc | 2005-03-14 01:16:05 +0000 | [diff] [blame] | 492 | |
| 493 | if (VG_(clo_verbosity) == 0) |
| 494 | return; |
sewardj | 71bc3cb | 2005-05-19 00:25:45 +0000 | [diff] [blame] | 495 | if (VG_(clo_xml)) |
| 496 | return; |
njn | 86f12dc | 2005-03-14 01:16:05 +0000 | [diff] [blame] | 497 | |
| 498 | /* Count memory still in use. */ |
njn | 1d0cb0d | 2005-08-15 01:52:02 +0000 | [diff] [blame] | 499 | VG_(HT_ResetIter)(MAC_(malloc_list)); |
| 500 | while ( (mc = VG_(HT_Next)(MAC_(malloc_list))) ) { |
| 501 | nblocks++; |
| 502 | nbytes += mc->size; |
| 503 | } |
njn | 86f12dc | 2005-03-14 01:16:05 +0000 | [diff] [blame] | 504 | |
| 505 | VG_(message)(Vg_UserMsg, |
njn | 0fd92f4 | 2005-10-06 03:32:42 +0000 | [diff] [blame] | 506 | "malloc/free: in use at exit: %,lu bytes in %,lu blocks.", |
njn | 1d0cb0d | 2005-08-15 01:52:02 +0000 | [diff] [blame] | 507 | nbytes, nblocks); |
njn | 86f12dc | 2005-03-14 01:16:05 +0000 | [diff] [blame] | 508 | VG_(message)(Vg_UserMsg, |
njn | 0fd92f4 | 2005-10-06 03:32:42 +0000 | [diff] [blame] | 509 | "malloc/free: %,lu allocs, %,lu frees, %,lu bytes allocated.", |
njn | 86f12dc | 2005-03-14 01:16:05 +0000 | [diff] [blame] | 510 | cmalloc_n_mallocs, |
| 511 | cmalloc_n_frees, cmalloc_bs_mallocd); |
| 512 | if (VG_(clo_verbosity) > 1) |
| 513 | VG_(message)(Vg_UserMsg, ""); |
| 514 | } |
| 515 | |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 516 | /*--------------------------------------------------------------------*/ |
njn | 86f12dc | 2005-03-14 01:16:05 +0000 | [diff] [blame] | 517 | /*--- end ---*/ |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 518 | /*--------------------------------------------------------------------*/ |