njn | c953984 | 2002-10-02 13:26:35 +0000 | [diff] [blame] | 1 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 2 | /*--------------------------------------------------------------------*/ |
nethercote | 137bc55 | 2003-11-14 17:47:54 +0000 | [diff] [blame] | 3 | /*--- A header file for all parts of the MemCheck tool. ---*/ |
njn25 | cac76cb | 2002-09-23 11:21:57 +0000 | [diff] [blame] | 4 | /*--- mc_include.h ---*/ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 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 |
njn | c953984 | 2002-10-02 13:26:35 +0000 | [diff] [blame] | 9 | detecting memory errors. |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 10 | |
sewardj | 4d474d0 | 2008-02-11 11:34:59 +0000 | [diff] [blame] | 11 | Copyright (C) 2000-2008 Julian Seward |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +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 | |
njn25 | cac76cb | 2002-09-23 11:21:57 +0000 | [diff] [blame] | 32 | #ifndef __MC_INCLUDE_H |
| 33 | #define __MC_INCLUDE_H |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 34 | |
njn | 44acd3e | 2005-05-13 21:39:45 +0000 | [diff] [blame] | 35 | #define MC_(str) VGAPPEND(vgMemCheck_,str) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 36 | |
sewardj | 7ce7166 | 2008-05-02 10:33:15 +0000 | [diff] [blame] | 37 | |
| 38 | /* This is a private header file for use only within the |
| 39 | memcheck/ directory. */ |
| 40 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 41 | /*------------------------------------------------------------*/ |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 42 | /*--- Tracking the heap ---*/ |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 43 | /*------------------------------------------------------------*/ |
| 44 | |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 45 | /* We want at least a 16B redzone on client heap blocks for Memcheck */ |
| 46 | #define MC_MALLOC_REDZONE_SZB 16 |
| 47 | |
| 48 | /* For malloc()/new/new[] vs. free()/delete/delete[] mismatch checking. */ |
| 49 | typedef |
| 50 | enum { |
| 51 | MC_AllocMalloc = 0, |
| 52 | MC_AllocNew = 1, |
| 53 | MC_AllocNewVec = 2, |
| 54 | MC_AllocCustom = 3 |
| 55 | } |
| 56 | MC_AllocKind; |
| 57 | |
| 58 | /* Nb: first two fields must match core's VgHashNode. */ |
| 59 | typedef |
| 60 | struct _MC_Chunk { |
| 61 | struct _MC_Chunk* next; |
| 62 | Addr data; // ptr to actual block |
njn | 718d3b1 | 2006-12-16 00:54:12 +0000 | [diff] [blame] | 63 | SizeT szB : (sizeof(UWord)*8)-2; // size requested; 30 or 62 bits |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 64 | MC_AllocKind allockind : 2; // which wrapper did the allocation |
| 65 | ExeContext* where; // where it was allocated |
| 66 | } |
| 67 | MC_Chunk; |
| 68 | |
| 69 | /* Memory pool. Nb: first two fields must match core's VgHashNode. */ |
| 70 | typedef |
| 71 | struct _MC_Mempool { |
| 72 | struct _MC_Mempool* next; |
| 73 | Addr pool; // pool identifier |
| 74 | SizeT rzB; // pool red-zone size |
| 75 | Bool is_zeroed; // allocations from this pool are zeroed |
| 76 | VgHashTable chunks; // chunks associated with this pool |
| 77 | } |
| 78 | MC_Mempool; |
| 79 | |
| 80 | |
sewardj | 56adc35 | 2008-05-02 11:25:17 +0000 | [diff] [blame] | 81 | void* MC_(new_block) ( ThreadId tid, |
| 82 | Addr p, SizeT size, SizeT align, UInt rzB, |
| 83 | Bool is_zeroed, MC_AllocKind kind, |
| 84 | VgHashTable table); |
| 85 | void MC_(handle_free) ( ThreadId tid, |
| 86 | Addr p, UInt rzB, MC_AllocKind kind ); |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 87 | |
sewardj | 56adc35 | 2008-05-02 11:25:17 +0000 | [diff] [blame] | 88 | void MC_(create_mempool) ( Addr pool, UInt rzB, Bool is_zeroed ); |
| 89 | void MC_(destroy_mempool) ( Addr pool ); |
| 90 | void MC_(mempool_alloc) ( ThreadId tid, Addr pool, |
| 91 | Addr addr, SizeT size ); |
| 92 | void MC_(mempool_free) ( Addr pool, Addr addr ); |
| 93 | void MC_(mempool_trim) ( Addr pool, Addr addr, SizeT size ); |
| 94 | void MC_(move_mempool) ( Addr poolA, Addr poolB ); |
| 95 | void MC_(mempool_change) ( Addr pool, Addr addrA, Addr addrB, SizeT size ); |
| 96 | Bool MC_(mempool_exists) ( Addr pool ); |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 97 | |
sewardj | 56adc35 | 2008-05-02 11:25:17 +0000 | [diff] [blame] | 98 | MC_Chunk* MC_(get_freed_list_head)( void ); |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 99 | |
| 100 | /* For tracking malloc'd blocks */ |
sewardj | 505a819 | 2008-07-18 20:15:46 +0000 | [diff] [blame] | 101 | extern VgHashTable MC_(malloc_list); |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 102 | |
| 103 | /* For tracking memory pools. */ |
sewardj | 505a819 | 2008-07-18 20:15:46 +0000 | [diff] [blame] | 104 | extern VgHashTable MC_(mempool_list); |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 105 | |
| 106 | /* Shadow memory functions */ |
sewardj | 56adc35 | 2008-05-02 11:25:17 +0000 | [diff] [blame] | 107 | Bool MC_(check_mem_is_noaccess)( Addr a, SizeT len, Addr* bad_addr ); |
| 108 | void MC_(make_mem_noaccess) ( Addr a, SizeT len ); |
| 109 | void MC_(make_mem_undefined_w_otag)( Addr a, SizeT len, UInt otag ); |
| 110 | void MC_(make_mem_defined) ( Addr a, SizeT len ); |
| 111 | void MC_(copy_address_range_state) ( Addr src, Addr dst, SizeT len ); |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 112 | |
sewardj | 56adc35 | 2008-05-02 11:25:17 +0000 | [diff] [blame] | 113 | void MC_(print_malloc_stats) ( void ); |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 114 | |
sewardj | 56adc35 | 2008-05-02 11:25:17 +0000 | [diff] [blame] | 115 | void* MC_(malloc) ( ThreadId tid, SizeT n ); |
| 116 | void* MC_(__builtin_new) ( ThreadId tid, SizeT n ); |
| 117 | void* MC_(__builtin_vec_new) ( ThreadId tid, SizeT n ); |
| 118 | void* MC_(memalign) ( ThreadId tid, SizeT align, SizeT n ); |
| 119 | void* MC_(calloc) ( ThreadId tid, SizeT nmemb, SizeT size1 ); |
| 120 | void MC_(free) ( ThreadId tid, void* p ); |
| 121 | void MC_(__builtin_delete) ( ThreadId tid, void* p ); |
| 122 | void MC_(__builtin_vec_delete) ( ThreadId tid, void* p ); |
| 123 | void* MC_(realloc) ( ThreadId tid, void* p, SizeT new_size ); |
njn | 8b140de | 2009-02-17 04:31:18 +0000 | [diff] [blame] | 124 | SizeT MC_(malloc_usable_size) ( ThreadId tid, void* p ); |
sewardj | 56adc35 | 2008-05-02 11:25:17 +0000 | [diff] [blame] | 125 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 126 | |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 127 | /*------------------------------------------------------------*/ |
| 128 | /*--- Origin tracking translate-time support ---*/ |
| 129 | /*------------------------------------------------------------*/ |
| 130 | |
| 131 | /* See detailed comments in mc_machine.c. */ |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 132 | Int MC_(get_otrack_shadow_offset) ( Int offset, Int szB ); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 133 | IRType MC_(get_otrack_reg_array_equiv_int_type) ( IRRegArray* arr ); |
| 134 | |
| 135 | /* Constants which are used as the lowest 2 bits in origin tags. |
| 136 | |
| 137 | An origin tag comprises an upper 30-bit ECU field and a lower 2-bit |
| 138 | 'kind' field. The ECU field is a number given out by m_execontext |
| 139 | and has a 1-1 mapping with ExeContext*s. An ECU can be used |
| 140 | directly as an origin tag (otag), but in fact we want to put |
| 141 | additional information 'kind' field to indicate roughly where the |
| 142 | tag came from. This helps print more understandable error messages |
| 143 | for the user -- it has no other purpose. |
| 144 | |
| 145 | Hence the following 2-bit constants are needed for 'kind' field. |
| 146 | |
| 147 | To summarise: |
| 148 | |
| 149 | * Both ECUs and origin tags are represented as 32-bit words |
| 150 | |
| 151 | * m_execontext and the core-tool interface deal purely in ECUs. |
| 152 | They have no knowledge of origin tags - that is a purely |
| 153 | Memcheck-internal matter. |
| 154 | |
| 155 | * all valid ECUs have the lowest 2 bits zero and at least |
| 156 | one of the upper 30 bits nonzero (see VG_(is_plausible_ECU)) |
| 157 | |
| 158 | * to convert from an ECU to an otag, OR in one of the MC_OKIND_ |
| 159 | constants below |
| 160 | |
| 161 | * to convert an otag back to an ECU, AND it with ~3 |
| 162 | */ |
| 163 | |
| 164 | #define MC_OKIND_UNKNOWN 0 /* unknown origin */ |
| 165 | #define MC_OKIND_HEAP 1 /* this is a heap origin */ |
| 166 | #define MC_OKIND_STACK 2 /* this is a stack origin */ |
| 167 | #define MC_OKIND_USER 3 /* arises from user-supplied client req */ |
| 168 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 169 | |
| 170 | /*------------------------------------------------------------*/ |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 171 | /*--- Profiling of memory events ---*/ |
| 172 | /*------------------------------------------------------------*/ |
| 173 | |
| 174 | /* Define to collect detailed performance info. */ |
| 175 | /* #define MC_PROFILE_MEMORY */ |
| 176 | |
| 177 | #ifdef MC_PROFILE_MEMORY |
| 178 | # define N_PROF_EVENTS 500 |
| 179 | |
sewardj | 56adc35 | 2008-05-02 11:25:17 +0000 | [diff] [blame] | 180 | UInt MC_(event_ctr)[N_PROF_EVENTS]; |
| 181 | HChar* MC_(event_ctr_name)[N_PROF_EVENTS]; |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 182 | |
| 183 | # define PROF_EVENT(ev, name) \ |
| 184 | do { tl_assert((ev) >= 0 && (ev) < N_PROF_EVENTS); \ |
| 185 | /* crude and inaccurate check to ensure the same */ \ |
| 186 | /* event isn't being used with > 1 name */ \ |
| 187 | if (MC_(event_ctr_name)[ev]) \ |
| 188 | tl_assert(name == MC_(event_ctr_name)[ev]); \ |
| 189 | MC_(event_ctr)[ev]++; \ |
| 190 | MC_(event_ctr_name)[ev] = (name); \ |
| 191 | } while (False); |
| 192 | |
| 193 | #else |
| 194 | |
| 195 | # define PROF_EVENT(ev, name) /* */ |
| 196 | |
| 197 | #endif /* MC_PROFILE_MEMORY */ |
| 198 | |
| 199 | |
| 200 | /*------------------------------------------------------------*/ |
| 201 | /*--- V and A bits (Victoria & Albert ?) ---*/ |
| 202 | /*------------------------------------------------------------*/ |
| 203 | |
| 204 | /* The number of entries in the primary map can be altered. However |
| 205 | we hardwire the assumption that each secondary map covers precisely |
| 206 | 64k of address space. */ |
| 207 | #define SM_SIZE 65536 /* DO NOT CHANGE */ |
| 208 | #define SM_MASK (SM_SIZE-1) /* DO NOT CHANGE */ |
| 209 | |
| 210 | #define V_BIT_DEFINED 0 |
| 211 | #define V_BIT_UNDEFINED 1 |
| 212 | |
| 213 | #define V_BITS8_DEFINED 0 |
| 214 | #define V_BITS8_UNDEFINED 0xFF |
| 215 | |
| 216 | #define V_BITS16_DEFINED 0 |
| 217 | #define V_BITS16_UNDEFINED 0xFFFF |
| 218 | |
| 219 | #define V_BITS32_DEFINED 0 |
| 220 | #define V_BITS32_UNDEFINED 0xFFFFFFFF |
| 221 | |
| 222 | #define V_BITS64_DEFINED 0ULL |
| 223 | #define V_BITS64_UNDEFINED 0xFFFFFFFFFFFFFFFFULL |
| 224 | |
| 225 | |
| 226 | /*------------------------------------------------------------*/ |
| 227 | /*--- Leak checking ---*/ |
| 228 | /*------------------------------------------------------------*/ |
| 229 | |
njn | 718d3b1 | 2006-12-16 00:54:12 +0000 | [diff] [blame] | 230 | /* A block is either |
| 231 | -- Proper-ly reached; a pointer to its start has been found |
| 232 | -- Interior-ly reached; only an interior pointer to it has been found |
| 233 | -- Unreached; so far, no pointers to any part of it have been found. |
| 234 | -- IndirectLeak; leaked, but referred to by another leaked block |
| 235 | */ |
| 236 | typedef |
| 237 | enum { |
| 238 | Unreached =0, |
| 239 | IndirectLeak =1, |
| 240 | Interior =2, |
| 241 | Proper =3 |
| 242 | } |
| 243 | Reachedness; |
| 244 | |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 245 | /* For VALGRIND_COUNT_LEAKS client request */ |
sewardj | 505a819 | 2008-07-18 20:15:46 +0000 | [diff] [blame] | 246 | extern SizeT MC_(bytes_leaked); |
| 247 | extern SizeT MC_(bytes_indirect); |
| 248 | extern SizeT MC_(bytes_dubious); |
| 249 | extern SizeT MC_(bytes_reachable); |
| 250 | extern SizeT MC_(bytes_suppressed); |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 251 | |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 252 | typedef |
| 253 | enum { |
| 254 | LC_Off, |
| 255 | LC_Summary, |
| 256 | LC_Full, |
| 257 | } |
| 258 | LeakCheckMode; |
| 259 | |
njn | 718d3b1 | 2006-12-16 00:54:12 +0000 | [diff] [blame] | 260 | /* A block record, used for generating err msgs. */ |
| 261 | typedef |
| 262 | struct _LossRecord { |
| 263 | struct _LossRecord* next; |
| 264 | /* Where these lost blocks were allocated. */ |
| 265 | ExeContext* allocated_at; |
| 266 | /* Their reachability. */ |
| 267 | Reachedness loss_mode; |
| 268 | /* Number of blocks and total # bytes involved. */ |
| 269 | SizeT total_bytes; |
| 270 | SizeT indirect_bytes; |
| 271 | UInt num_blocks; |
| 272 | } |
| 273 | LossRecord; |
| 274 | |
sewardj | 56adc35 | 2008-05-02 11:25:17 +0000 | [diff] [blame] | 275 | void MC_(do_detect_memory_leaks) ( |
| 276 | ThreadId tid, LeakCheckMode mode, |
| 277 | Bool (*is_within_valid_secondary) ( Addr ), |
| 278 | Bool (*is_valid_aligned_word) ( Addr ) |
| 279 | ); |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 280 | |
sewardj | 56adc35 | 2008-05-02 11:25:17 +0000 | [diff] [blame] | 281 | void MC_(pp_LeakError)(UInt n_this_record, UInt n_total_records, |
| 282 | LossRecord* l); |
njn | 718d3b1 | 2006-12-16 00:54:12 +0000 | [diff] [blame] | 283 | |
| 284 | |
| 285 | /*------------------------------------------------------------*/ |
| 286 | /*--- Errors and suppressions ---*/ |
| 287 | /*------------------------------------------------------------*/ |
| 288 | |
sewardj | 7ce7166 | 2008-05-02 10:33:15 +0000 | [diff] [blame] | 289 | /* Did we show to the user, any errors for which an uninitialised |
| 290 | value origin could have been collected (but wasn't) ? If yes, |
| 291 | then, at the end of the run, print a 1 line message advising that a |
| 292 | rerun with --track-origins=yes might help. */ |
sewardj | 505a819 | 2008-07-18 20:15:46 +0000 | [diff] [blame] | 293 | extern Bool MC_(any_value_errors); |
sewardj | 7ce7166 | 2008-05-02 10:33:15 +0000 | [diff] [blame] | 294 | |
| 295 | /* Standard functions for error and suppressions as required by the |
| 296 | core/tool iface */ |
| 297 | Bool MC_(eq_Error) ( VgRes res, Error* e1, Error* e2 ); |
| 298 | void MC_(pp_Error) ( Error* err ); |
| 299 | UInt MC_(update_Error_extra)( Error* err ); |
| 300 | |
| 301 | Bool MC_(is_recognised_suppression) ( Char* name, Supp* su ); |
| 302 | |
| 303 | Bool MC_(read_extra_suppression_info) ( Int fd, Char* buf, |
| 304 | Int nBuf, Supp *su ); |
| 305 | |
| 306 | Bool MC_(error_matches_suppression) ( Error* err, Supp* su ); |
| 307 | |
| 308 | void MC_(print_extra_suppression_info) ( Error* err ); |
| 309 | |
| 310 | Char* MC_(get_error_name) ( Error* err ); |
| 311 | |
| 312 | /* Recording of errors */ |
| 313 | void MC_(record_address_error) ( ThreadId tid, Addr a, Int szB, |
| 314 | Bool isWrite ); |
| 315 | void MC_(record_cond_error) ( ThreadId tid, UInt otag ); |
| 316 | void MC_(record_value_error) ( ThreadId tid, Int szB, UInt otag ); |
| 317 | void MC_(record_jump_error) ( ThreadId tid, Addr a ); |
| 318 | |
| 319 | void MC_(record_free_error) ( ThreadId tid, Addr a ); |
| 320 | void MC_(record_illegal_mempool_error) ( ThreadId tid, Addr a ); |
| 321 | void MC_(record_freemismatch_error) ( ThreadId tid, MC_Chunk* mc ); |
| 322 | |
| 323 | void MC_(record_overlap_error) ( ThreadId tid, Char* function, |
| 324 | Addr src, Addr dst, SizeT szB ); |
| 325 | void MC_(record_core_mem_error) ( ThreadId tid, Bool isAddrErr, Char* msg ); |
| 326 | void MC_(record_regparam_error) ( ThreadId tid, Char* msg, UInt otag ); |
| 327 | void MC_(record_memparam_error) ( ThreadId tid, Addr a, |
| 328 | Bool isAddrErr, Char* msg, UInt otag ); |
| 329 | void MC_(record_user_error) ( ThreadId tid, Addr a, |
| 330 | Bool isAddrErr, UInt otag ); |
| 331 | |
| 332 | Bool MC_(record_leak_error) ( ThreadId tid, |
| 333 | UInt n_this_record, |
| 334 | UInt n_total_records, |
| 335 | LossRecord* lossRecord, |
| 336 | Bool print_record ); |
| 337 | |
| 338 | /* Is this address in a user-specified "ignored range" ? */ |
| 339 | Bool MC_(in_ignored_range) ( Addr a ); |
| 340 | |
| 341 | |
| 342 | /*------------------------------------------------------------*/ |
| 343 | /*--- Client blocks ---*/ |
| 344 | /*------------------------------------------------------------*/ |
| 345 | |
| 346 | /* Describes a client block. See mc_main.c. An unused block has |
| 347 | start == size == 0. */ |
| 348 | typedef |
| 349 | struct { |
| 350 | Addr start; |
| 351 | SizeT size; |
| 352 | ExeContext* where; |
| 353 | Char* desc; |
| 354 | } |
| 355 | CGenBlock; |
| 356 | |
| 357 | /* Get access to the client block array. */ |
| 358 | void MC_(get_ClientBlock_array)( /*OUT*/CGenBlock** blocks, |
| 359 | /*OUT*/UWord* nBlocks ); |
| 360 | |
njn | 718d3b1 | 2006-12-16 00:54:12 +0000 | [diff] [blame] | 361 | |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 362 | /*------------------------------------------------------------*/ |
| 363 | /*--- Command line options + defaults ---*/ |
| 364 | /*------------------------------------------------------------*/ |
| 365 | |
| 366 | /* Allow loads from partially-valid addresses? default: YES */ |
sewardj | 505a819 | 2008-07-18 20:15:46 +0000 | [diff] [blame] | 367 | extern Bool MC_(clo_partial_loads_ok); |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 368 | |
| 369 | /* Max volume of the freed blocks queue. */ |
sewardj | 505a819 | 2008-07-18 20:15:46 +0000 | [diff] [blame] | 370 | extern Long MC_(clo_freelist_vol); |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 371 | |
| 372 | /* Do leak check at exit? default: NO */ |
sewardj | 505a819 | 2008-07-18 20:15:46 +0000 | [diff] [blame] | 373 | extern LeakCheckMode MC_(clo_leak_check); |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 374 | |
| 375 | /* How closely should we compare ExeContexts in leak records? default: 2 */ |
sewardj | 505a819 | 2008-07-18 20:15:46 +0000 | [diff] [blame] | 376 | extern VgRes MC_(clo_leak_resolution); |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 377 | |
| 378 | /* In leak check, show reachable-but-not-freed blocks? default: NO */ |
sewardj | 505a819 | 2008-07-18 20:15:46 +0000 | [diff] [blame] | 379 | extern Bool MC_(clo_show_reachable); |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 380 | |
| 381 | /* Assume accesses immediately below %esp are due to gcc-2.96 bugs. |
| 382 | * default: NO */ |
sewardj | 505a819 | 2008-07-18 20:15:46 +0000 | [diff] [blame] | 383 | extern Bool MC_(clo_workaround_gcc296_bugs); |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 384 | |
sewardj | eb0fa93 | 2007-11-30 21:41:40 +0000 | [diff] [blame] | 385 | /* Fill malloc-d/free-d client blocks with a specific value? -1 if |
| 386 | not, else 0x00 .. 0xFF indicating the fill value to use. Can be |
| 387 | useful for causing programs with bad heap corruption to fail in |
| 388 | more repeatable ways. Note that malloc-filled and free-filled |
| 389 | areas are still undefined and noaccess respectively. This merely |
| 390 | causes them to contain the specified values. */ |
sewardj | 505a819 | 2008-07-18 20:15:46 +0000 | [diff] [blame] | 391 | extern Int MC_(clo_malloc_fill); |
| 392 | extern Int MC_(clo_free_fill); |
sewardj | eb0fa93 | 2007-11-30 21:41:40 +0000 | [diff] [blame] | 393 | |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 394 | /* Indicates the level of instrumentation/checking done by Memcheck. |
| 395 | |
| 396 | 1 = No undefined value checking, Addrcheck-style behaviour only: |
| 397 | only address checking is done. This is faster but finds fewer |
| 398 | errors. Note that although Addrcheck had 1 bit per byte |
| 399 | overhead vs the old Memcheck's 9 bits per byte, with this mode |
| 400 | and compressed V bits, no memory is saved with this mode -- |
| 401 | it's still 2 bits per byte overhead. This is a little wasteful |
| 402 | -- it could be done with 1 bit per byte -- but lets us reuse |
| 403 | the many shadow memory access functions. Note that in this |
| 404 | mode neither the secondary V bit table nor the origin-tag cache |
| 405 | are used. |
| 406 | |
| 407 | 2 = Address checking and Undefined value checking are performed, |
| 408 | but origins are not tracked. So the origin-tag cache is not |
| 409 | used in this mode. This setting is the default and corresponds |
| 410 | to the "normal" Memcheck behaviour that has shipped for years. |
| 411 | |
| 412 | 3 = Address checking, undefined value checking, and origins for |
| 413 | undefined values are tracked. |
| 414 | |
| 415 | The default is 2. |
| 416 | */ |
sewardj | 505a819 | 2008-07-18 20:15:46 +0000 | [diff] [blame] | 417 | extern Int MC_(clo_mc_level); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 418 | |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 419 | |
| 420 | /*------------------------------------------------------------*/ |
| 421 | /*--- Instrumentation ---*/ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 422 | /*------------------------------------------------------------*/ |
| 423 | |
njn | 66fe05a | 2003-07-22 09:12:33 +0000 | [diff] [blame] | 424 | /* Functions defined in mc_main.c */ |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 425 | |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 426 | /* For the fail_w_o functions, the UWord arg is actually the 32-bit |
| 427 | origin tag and should really be UInt, but to be simple and safe |
| 428 | considering it's called from generated code, just claim it to be a |
| 429 | UWord. */ |
sewardj | 56adc35 | 2008-05-02 11:25:17 +0000 | [diff] [blame] | 430 | VG_REGPARM(2) void MC_(helperc_value_checkN_fail_w_o) ( HWord, UWord ); |
| 431 | VG_REGPARM(1) void MC_(helperc_value_check8_fail_w_o) ( UWord ); |
| 432 | VG_REGPARM(1) void MC_(helperc_value_check4_fail_w_o) ( UWord ); |
| 433 | VG_REGPARM(1) void MC_(helperc_value_check1_fail_w_o) ( UWord ); |
| 434 | VG_REGPARM(1) void MC_(helperc_value_check0_fail_w_o) ( UWord ); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 435 | |
| 436 | /* And call these ones instead to report an uninitialised value error |
| 437 | but with no origin available. */ |
sewardj | 56adc35 | 2008-05-02 11:25:17 +0000 | [diff] [blame] | 438 | VG_REGPARM(1) void MC_(helperc_value_checkN_fail_no_o) ( HWord ); |
| 439 | VG_REGPARM(0) void MC_(helperc_value_check8_fail_no_o) ( void ); |
| 440 | VG_REGPARM(0) void MC_(helperc_value_check4_fail_no_o) ( void ); |
| 441 | VG_REGPARM(0) void MC_(helperc_value_check1_fail_no_o) ( void ); |
| 442 | VG_REGPARM(0) void MC_(helperc_value_check0_fail_no_o) ( void ); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 443 | |
| 444 | /* V-bits load/store helpers */ |
sewardj | 56adc35 | 2008-05-02 11:25:17 +0000 | [diff] [blame] | 445 | VG_REGPARM(1) void MC_(helperc_STOREV64be) ( Addr, ULong ); |
| 446 | VG_REGPARM(1) void MC_(helperc_STOREV64le) ( Addr, ULong ); |
| 447 | VG_REGPARM(2) void MC_(helperc_STOREV32be) ( Addr, UWord ); |
| 448 | VG_REGPARM(2) void MC_(helperc_STOREV32le) ( Addr, UWord ); |
| 449 | VG_REGPARM(2) void MC_(helperc_STOREV16be) ( Addr, UWord ); |
| 450 | VG_REGPARM(2) void MC_(helperc_STOREV16le) ( Addr, UWord ); |
| 451 | VG_REGPARM(2) void MC_(helperc_STOREV8) ( Addr, UWord ); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 452 | |
sewardj | 56adc35 | 2008-05-02 11:25:17 +0000 | [diff] [blame] | 453 | VG_REGPARM(1) ULong MC_(helperc_LOADV64be) ( Addr ); |
| 454 | VG_REGPARM(1) ULong MC_(helperc_LOADV64le) ( Addr ); |
| 455 | VG_REGPARM(1) UWord MC_(helperc_LOADV32be) ( Addr ); |
| 456 | VG_REGPARM(1) UWord MC_(helperc_LOADV32le) ( Addr ); |
| 457 | VG_REGPARM(1) UWord MC_(helperc_LOADV16be) ( Addr ); |
| 458 | VG_REGPARM(1) UWord MC_(helperc_LOADV16le) ( Addr ); |
| 459 | VG_REGPARM(1) UWord MC_(helperc_LOADV8) ( Addr ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 460 | |
sewardj | 56adc35 | 2008-05-02 11:25:17 +0000 | [diff] [blame] | 461 | void MC_(helperc_MAKE_STACK_UNINIT) ( Addr base, UWord len, |
| 462 | Addr nia ); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 463 | |
| 464 | /* Origin tag load/store helpers */ |
| 465 | VG_REGPARM(2) void MC_(helperc_b_store1) ( Addr a, UWord d32 ); |
| 466 | VG_REGPARM(2) void MC_(helperc_b_store2) ( Addr a, UWord d32 ); |
| 467 | VG_REGPARM(2) void MC_(helperc_b_store4) ( Addr a, UWord d32 ); |
| 468 | VG_REGPARM(2) void MC_(helperc_b_store8) ( Addr a, UWord d32 ); |
| 469 | VG_REGPARM(2) void MC_(helperc_b_store16)( Addr a, UWord d32 ); |
| 470 | VG_REGPARM(1) UWord MC_(helperc_b_load1) ( Addr a ); |
| 471 | VG_REGPARM(1) UWord MC_(helperc_b_load2) ( Addr a ); |
| 472 | VG_REGPARM(1) UWord MC_(helperc_b_load4) ( Addr a ); |
| 473 | VG_REGPARM(1) UWord MC_(helperc_b_load8) ( Addr a ); |
| 474 | VG_REGPARM(1) UWord MC_(helperc_b_load16)( Addr a ); |
sewardj | 826ec49 | 2005-05-12 18:05:00 +0000 | [diff] [blame] | 475 | |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 476 | /* Functions defined in mc_translate.c */ |
sewardj | 0b9d74a | 2006-12-24 02:24:11 +0000 | [diff] [blame] | 477 | IRSB* MC_(instrument) ( VgCallbackClosure* closure, |
| 478 | IRSB* bb_in, |
sewardj | 461df9c | 2006-01-17 02:06:39 +0000 | [diff] [blame] | 479 | VexGuestLayout* layout, |
| 480 | VexGuestExtents* vge, |
sewardj | 4ba057c | 2005-10-18 12:04:18 +0000 | [diff] [blame] | 481 | IRType gWordTy, IRType hWordTy ); |
sewardj | 8d61eb1 | 2005-07-08 09:46:53 +0000 | [diff] [blame] | 482 | |
sewardj | 81651dc | 2007-08-28 06:05:20 +0000 | [diff] [blame] | 483 | IRSB* MC_(final_tidy) ( IRSB* ); |
| 484 | |
sewardj | 8d61eb1 | 2005-07-08 09:46:53 +0000 | [diff] [blame] | 485 | #endif /* ndef __MC_INCLUDE_H */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 486 | |
| 487 | /*--------------------------------------------------------------------*/ |
nethercote | 8b76fe5 | 2004-11-08 19:20:09 +0000 | [diff] [blame] | 488 | /*--- end ---*/ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 489 | /*--------------------------------------------------------------------*/ |