blob: 91921d22c560f30b5daa0d3b2d9b47c2747b24e3 [file] [log] [blame]
njnc9539842002-10-02 13:26:35 +00001
njn25e49d8e72002-09-23 09:36:25 +00002/*--------------------------------------------------------------------*/
nethercote137bc552003-11-14 17:47:54 +00003/*--- A header file for all parts of the MemCheck tool. ---*/
njn25cac76cb2002-09-23 11:21:57 +00004/*--- mc_include.h ---*/
njn25e49d8e72002-09-23 09:36:25 +00005/*--------------------------------------------------------------------*/
6
7/*
nethercote137bc552003-11-14 17:47:54 +00008 This file is part of MemCheck, a heavyweight Valgrind tool for
njnc9539842002-10-02 13:26:35 +00009 detecting memory errors.
njn25e49d8e72002-09-23 09:36:25 +000010
sewardjec062e82011-10-23 07:32:08 +000011 Copyright (C) 2000-2011 Julian Seward
njn25e49d8e72002-09-23 09:36:25 +000012 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
njn25cac76cb2002-09-23 11:21:57 +000032#ifndef __MC_INCLUDE_H
33#define __MC_INCLUDE_H
njn25e49d8e72002-09-23 09:36:25 +000034
njn44acd3e2005-05-13 21:39:45 +000035#define MC_(str) VGAPPEND(vgMemCheck_,str)
njn25e49d8e72002-09-23 09:36:25 +000036
sewardj7ce71662008-05-02 10:33:15 +000037
38/* This is a private header file for use only within the
39 memcheck/ directory. */
40
njn25e49d8e72002-09-23 09:36:25 +000041/*------------------------------------------------------------*/
njn1d0825f2006-03-27 11:37:07 +000042/*--- Tracking the heap ---*/
njn43c799e2003-04-08 00:08:52 +000043/*------------------------------------------------------------*/
44
njn1d0825f2006-03-27 11:37:07 +000045/* 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. */
49typedef
50 enum {
51 MC_AllocMalloc = 0,
52 MC_AllocNew = 1,
53 MC_AllocNewVec = 2,
54 MC_AllocCustom = 3
55 }
56 MC_AllocKind;
57
njn8225cc02009-03-09 22:52:24 +000058/* This describes a heap block. Nb: first two fields must match core's
59 * VgHashNode. */
njn1d0825f2006-03-27 11:37:07 +000060typedef
61 struct _MC_Chunk {
62 struct _MC_Chunk* next;
njn8225cc02009-03-09 22:52:24 +000063 Addr data; // Address of the actual block.
64 SizeT szB : (sizeof(SizeT)*8)-2; // Size requested; 30 or 62 bits.
65 MC_AllocKind allockind : 2; // Which operation did the allocation.
66 ExeContext* where; // Where it was allocated.
njn1d0825f2006-03-27 11:37:07 +000067 }
68 MC_Chunk;
69
70/* Memory pool. Nb: first two fields must match core's VgHashNode. */
71typedef
72 struct _MC_Mempool {
73 struct _MC_Mempool* next;
74 Addr pool; // pool identifier
75 SizeT rzB; // pool red-zone size
76 Bool is_zeroed; // allocations from this pool are zeroed
77 VgHashTable chunks; // chunks associated with this pool
78 }
79 MC_Mempool;
80
81
sewardj56adc352008-05-02 11:25:17 +000082void* MC_(new_block) ( ThreadId tid,
njn1dcee092009-02-24 03:07:37 +000083 Addr p, SizeT size, SizeT align,
sewardj56adc352008-05-02 11:25:17 +000084 Bool is_zeroed, MC_AllocKind kind,
85 VgHashTable table);
86void MC_(handle_free) ( ThreadId tid,
87 Addr p, UInt rzB, MC_AllocKind kind );
njn1d0825f2006-03-27 11:37:07 +000088
sewardj56adc352008-05-02 11:25:17 +000089void MC_(create_mempool) ( Addr pool, UInt rzB, Bool is_zeroed );
90void MC_(destroy_mempool) ( Addr pool );
91void MC_(mempool_alloc) ( ThreadId tid, Addr pool,
92 Addr addr, SizeT size );
93void MC_(mempool_free) ( Addr pool, Addr addr );
94void MC_(mempool_trim) ( Addr pool, Addr addr, SizeT size );
95void MC_(move_mempool) ( Addr poolA, Addr poolB );
96void MC_(mempool_change) ( Addr pool, Addr addrA, Addr addrB, SizeT size );
97Bool MC_(mempool_exists) ( Addr pool );
njn1d0825f2006-03-27 11:37:07 +000098
sewardj403d8aa2011-10-22 19:48:57 +000099/* Searches for a recently freed block which might bracket Addr a.
100 Return the MC_Chunk* for this block or NULL if no bracketting block
101 is found. */
102MC_Chunk* MC_(get_freed_block_bracketting)( Addr a );
njn1d0825f2006-03-27 11:37:07 +0000103
philippe6643e962012-01-17 21:16:30 +0000104/* For efficient pooled alloc/free of the MC_Chunk. */
105extern PoolAlloc* MC_(chunk_poolalloc);
106
njnb965efb2009-08-10 07:36:54 +0000107/* For tracking malloc'd blocks. Nb: it's quite important that it's a
108 VgHashTable, because VgHashTable allows duplicate keys without complaint.
109 This can occur if a user marks a malloc() block as also a custom block with
110 MALLOCLIKE_BLOCK. */
sewardj505a8192008-07-18 20:15:46 +0000111extern VgHashTable MC_(malloc_list);
njn1d0825f2006-03-27 11:37:07 +0000112
113/* For tracking memory pools. */
sewardj505a8192008-07-18 20:15:46 +0000114extern VgHashTable MC_(mempool_list);
njn1d0825f2006-03-27 11:37:07 +0000115
116/* Shadow memory functions */
sewardj56adc352008-05-02 11:25:17 +0000117Bool MC_(check_mem_is_noaccess)( Addr a, SizeT len, Addr* bad_addr );
118void MC_(make_mem_noaccess) ( Addr a, SizeT len );
119void MC_(make_mem_undefined_w_otag)( Addr a, SizeT len, UInt otag );
120void MC_(make_mem_defined) ( Addr a, SizeT len );
121void MC_(copy_address_range_state) ( Addr src, Addr dst, SizeT len );
njn1d0825f2006-03-27 11:37:07 +0000122
sewardj56adc352008-05-02 11:25:17 +0000123void MC_(print_malloc_stats) ( void );
philippea22f59d2012-01-26 23:13:52 +0000124/* nr of free operations done */
125SizeT MC_(get_cmalloc_n_frees) ( void );
njn1d0825f2006-03-27 11:37:07 +0000126
sewardj56adc352008-05-02 11:25:17 +0000127void* MC_(malloc) ( ThreadId tid, SizeT n );
128void* MC_(__builtin_new) ( ThreadId tid, SizeT n );
129void* MC_(__builtin_vec_new) ( ThreadId tid, SizeT n );
130void* MC_(memalign) ( ThreadId tid, SizeT align, SizeT n );
131void* MC_(calloc) ( ThreadId tid, SizeT nmemb, SizeT size1 );
132void MC_(free) ( ThreadId tid, void* p );
133void MC_(__builtin_delete) ( ThreadId tid, void* p );
134void MC_(__builtin_vec_delete) ( ThreadId tid, void* p );
135void* MC_(realloc) ( ThreadId tid, void* p, SizeT new_size );
njn8b140de2009-02-17 04:31:18 +0000136SizeT MC_(malloc_usable_size) ( ThreadId tid, void* p );
sewardj56adc352008-05-02 11:25:17 +0000137
bart91347382011-03-25 20:07:25 +0000138void MC_(handle_resizeInPlace)(ThreadId tid, Addr p,
139 SizeT oldSizeB, SizeT newSizeB, SizeT rzB);
140
njn43c799e2003-04-08 00:08:52 +0000141
sewardj7cf4e6b2008-05-01 20:24:26 +0000142/*------------------------------------------------------------*/
143/*--- Origin tracking translate-time support ---*/
144/*------------------------------------------------------------*/
145
146/* See detailed comments in mc_machine.c. */
sewardj7cf4e6b2008-05-01 20:24:26 +0000147Int MC_(get_otrack_shadow_offset) ( Int offset, Int szB );
sewardj7cf4e6b2008-05-01 20:24:26 +0000148IRType MC_(get_otrack_reg_array_equiv_int_type) ( IRRegArray* arr );
149
150/* Constants which are used as the lowest 2 bits in origin tags.
151
152 An origin tag comprises an upper 30-bit ECU field and a lower 2-bit
153 'kind' field. The ECU field is a number given out by m_execontext
154 and has a 1-1 mapping with ExeContext*s. An ECU can be used
155 directly as an origin tag (otag), but in fact we want to put
156 additional information 'kind' field to indicate roughly where the
157 tag came from. This helps print more understandable error messages
158 for the user -- it has no other purpose.
159
160 Hence the following 2-bit constants are needed for 'kind' field.
161
162 To summarise:
163
164 * Both ECUs and origin tags are represented as 32-bit words
165
166 * m_execontext and the core-tool interface deal purely in ECUs.
167 They have no knowledge of origin tags - that is a purely
168 Memcheck-internal matter.
169
170 * all valid ECUs have the lowest 2 bits zero and at least
171 one of the upper 30 bits nonzero (see VG_(is_plausible_ECU))
172
173 * to convert from an ECU to an otag, OR in one of the MC_OKIND_
174 constants below
175
176 * to convert an otag back to an ECU, AND it with ~3
177*/
178
179#define MC_OKIND_UNKNOWN 0 /* unknown origin */
180#define MC_OKIND_HEAP 1 /* this is a heap origin */
181#define MC_OKIND_STACK 2 /* this is a stack origin */
182#define MC_OKIND_USER 3 /* arises from user-supplied client req */
183
njn43c799e2003-04-08 00:08:52 +0000184
185/*------------------------------------------------------------*/
njn1d0825f2006-03-27 11:37:07 +0000186/*--- Profiling of memory events ---*/
187/*------------------------------------------------------------*/
188
189/* Define to collect detailed performance info. */
190/* #define MC_PROFILE_MEMORY */
191
192#ifdef MC_PROFILE_MEMORY
193# define N_PROF_EVENTS 500
194
sewardj56adc352008-05-02 11:25:17 +0000195UInt MC_(event_ctr)[N_PROF_EVENTS];
196HChar* MC_(event_ctr_name)[N_PROF_EVENTS];
njn1d0825f2006-03-27 11:37:07 +0000197
198# define PROF_EVENT(ev, name) \
199 do { tl_assert((ev) >= 0 && (ev) < N_PROF_EVENTS); \
200 /* crude and inaccurate check to ensure the same */ \
201 /* event isn't being used with > 1 name */ \
202 if (MC_(event_ctr_name)[ev]) \
203 tl_assert(name == MC_(event_ctr_name)[ev]); \
204 MC_(event_ctr)[ev]++; \
205 MC_(event_ctr_name)[ev] = (name); \
206 } while (False);
207
208#else
209
210# define PROF_EVENT(ev, name) /* */
211
212#endif /* MC_PROFILE_MEMORY */
213
214
215/*------------------------------------------------------------*/
216/*--- V and A bits (Victoria & Albert ?) ---*/
217/*------------------------------------------------------------*/
218
219/* The number of entries in the primary map can be altered. However
220 we hardwire the assumption that each secondary map covers precisely
221 64k of address space. */
222#define SM_SIZE 65536 /* DO NOT CHANGE */
223#define SM_MASK (SM_SIZE-1) /* DO NOT CHANGE */
224
225#define V_BIT_DEFINED 0
226#define V_BIT_UNDEFINED 1
227
228#define V_BITS8_DEFINED 0
229#define V_BITS8_UNDEFINED 0xFF
230
231#define V_BITS16_DEFINED 0
232#define V_BITS16_UNDEFINED 0xFFFF
233
234#define V_BITS32_DEFINED 0
235#define V_BITS32_UNDEFINED 0xFFFFFFFF
236
237#define V_BITS64_DEFINED 0ULL
238#define V_BITS64_UNDEFINED 0xFFFFFFFFFFFFFFFFULL
239
240
241/*------------------------------------------------------------*/
242/*--- Leak checking ---*/
243/*------------------------------------------------------------*/
244
njn718d3b12006-12-16 00:54:12 +0000245typedef
246 enum {
njn29a5c012009-05-06 06:15:55 +0000247 // Nb: the order is important -- it dictates the order of loss records
248 // of equal sizes.
249 Reachable =0, // Definitely reachable from root-set.
250 Possible =1, // Possibly reachable from root-set; involves at
njn8225cc02009-03-09 22:52:24 +0000251 // least one interior-pointer along the way.
njn29a5c012009-05-06 06:15:55 +0000252 IndirectLeak =2, // Leaked, but reachable from another leaked block
253 // (be it Unreached or IndirectLeak).
254 Unreached =3, // Not reached, ie. leaked.
255 // (At best, only reachable from itself via a cycle.)
njn718d3b12006-12-16 00:54:12 +0000256 }
257 Reachedness;
258
philippea22f59d2012-01-26 23:13:52 +0000259
njn1d0825f2006-03-27 11:37:07 +0000260/* For VALGRIND_COUNT_LEAKS client request */
sewardj505a8192008-07-18 20:15:46 +0000261extern SizeT MC_(bytes_leaked);
262extern SizeT MC_(bytes_indirect);
263extern SizeT MC_(bytes_dubious);
264extern SizeT MC_(bytes_reachable);
265extern SizeT MC_(bytes_suppressed);
njn1d0825f2006-03-27 11:37:07 +0000266
njn8df80b22009-03-02 05:11:06 +0000267/* For VALGRIND_COUNT_LEAK_BLOCKS client request */
268extern SizeT MC_(blocks_leaked);
269extern SizeT MC_(blocks_indirect);
270extern SizeT MC_(blocks_dubious);
271extern SizeT MC_(blocks_reachable);
272extern SizeT MC_(blocks_suppressed);
273
njn1d0825f2006-03-27 11:37:07 +0000274typedef
275 enum {
276 LC_Off,
277 LC_Summary,
278 LC_Full,
279 }
280 LeakCheckMode;
281
sewardjc8bd1df2011-06-26 12:41:33 +0000282typedef
283 enum {
284 LCD_Any, // output all loss records, whatever the delta
285 LCD_Increased, // output loss records with an increase in size or blocks
286 LCD_Changed, // output loss records with an increase or
287 //decrease in size or blocks
288 }
289 LeakCheckDeltaMode;
290
njn29a5c012009-05-06 06:15:55 +0000291/* When a LossRecord is put into an OSet, these elements represent the key. */
292typedef
293 struct _LossRecordKey {
294 Reachedness state; // LC_Extra.state value shared by all blocks.
295 ExeContext* allocated_at; // Where they were allocated.
296 }
297 LossRecordKey;
298
njnb7a4e2e2009-05-01 00:30:43 +0000299/* A loss record, used for generating err msgs. Multiple leaked blocks can be
300 * merged into a single loss record if they have the same state and similar
301 * enough allocation points (controlled by --leak-resolution). */
njn718d3b12006-12-16 00:54:12 +0000302typedef
303 struct _LossRecord {
njn29a5c012009-05-06 06:15:55 +0000304 LossRecordKey key; // Key, when used in an OSet.
305 SizeT szB; // Sum of all MC_Chunk.szB values.
306 SizeT indirect_szB; // Sum of all LC_Extra.indirect_szB values.
307 UInt num_blocks; // Number of blocks represented by the record.
sewardjc8bd1df2011-06-26 12:41:33 +0000308 SizeT old_szB; // old_* values are the values found during the
309 SizeT old_indirect_szB; // previous leak search. old_* values are used to
310 UInt old_num_blocks; // output only the changed/new loss records
njn718d3b12006-12-16 00:54:12 +0000311 }
312 LossRecord;
313
sewardjc8bd1df2011-06-26 12:41:33 +0000314typedef
315 struct _LeakCheckParams {
316 LeakCheckMode mode;
317 Bool show_reachable;
318 Bool show_possibly_lost;
319 LeakCheckDeltaMode deltamode;
philippe84234902012-01-14 13:53:13 +0000320 UInt max_loss_records_output; // limit on the nr of loss records output.
sewardjc8bd1df2011-06-26 12:41:33 +0000321 Bool requested_by_monitor_command; // True when requested by gdb/vgdb.
322 }
323 LeakCheckParams;
324
philippe84234902012-01-14 13:53:13 +0000325void MC_(detect_memory_leaks) ( ThreadId tid, LeakCheckParams * lcp);
sewardjc8bd1df2011-06-26 12:41:33 +0000326
327// maintains the lcp.deltamode given in the last call to detect_memory_leaks
328extern LeakCheckDeltaMode MC_(detect_memory_leaks_last_delta_mode);
329
philippea22f59d2012-01-26 23:13:52 +0000330// prints the list of blocks corresponding to the given loss_record_nr.
331// Returns True if loss_record_nr identifies a correct loss record from last leak search.
332// Returns False otherwise.
333Bool MC_(print_block_list) ( UInt loss_record_nr);
334
335// Prints the addresses/registers/... at which a pointer to
336// the given range [address, address+szB[ is found.
337void MC_(who_points_at) ( Addr address, SizeT szB);
338
sewardj30b3eca2011-06-28 08:20:39 +0000339// if delta_mode == LCD_Any, prints in buf an empty string
sewardjc8bd1df2011-06-26 12:41:33 +0000340// otherwise prints a delta in the layout " (+%'lu)" or " (-%'lu)"
341extern char * MC_(snprintf_delta) (char * buf, Int size,
342 SizeT current_val, SizeT old_val,
343 LeakCheckDeltaMode delta_mode);
344
njn8225cc02009-03-09 22:52:24 +0000345
346Bool MC_(is_valid_aligned_word) ( Addr a );
347Bool MC_(is_within_valid_secondary) ( Addr a );
njn1d0825f2006-03-27 11:37:07 +0000348
philippea22f59d2012-01-26 23:13:52 +0000349// Prints as user msg a description of the given loss record.
350void MC_(pp_LossRecord)(UInt n_this_record, UInt n_total_records,
351 LossRecord* l);
njn718d3b12006-12-16 00:54:12 +0000352
353
354/*------------------------------------------------------------*/
355/*--- Errors and suppressions ---*/
356/*------------------------------------------------------------*/
357
sewardj7ce71662008-05-02 10:33:15 +0000358/* Did we show to the user, any errors for which an uninitialised
359 value origin could have been collected (but wasn't) ? If yes,
360 then, at the end of the run, print a 1 line message advising that a
361 rerun with --track-origins=yes might help. */
sewardj505a8192008-07-18 20:15:46 +0000362extern Bool MC_(any_value_errors);
sewardj7ce71662008-05-02 10:33:15 +0000363
364/* Standard functions for error and suppressions as required by the
365 core/tool iface */
sewardj6b523cd2009-07-15 14:49:40 +0000366Bool MC_(eq_Error) ( VgRes res, Error* e1, Error* e2 );
367void MC_(before_pp_Error) ( Error* err );
368void MC_(pp_Error) ( Error* err );
369UInt MC_(update_Error_extra) ( Error* err );
sewardj7ce71662008-05-02 10:33:15 +0000370
371Bool MC_(is_recognised_suppression) ( Char* name, Supp* su );
372
njn35db56c2009-07-24 07:38:29 +0000373Bool MC_(read_extra_suppression_info) ( Int fd, Char** buf,
374 SizeT* nBuf, Supp *su );
sewardj7ce71662008-05-02 10:33:15 +0000375
376Bool MC_(error_matches_suppression) ( Error* err, Supp* su );
377
sewardj588adef2009-08-15 22:41:51 +0000378Bool MC_(get_extra_suppression_info) ( Error* err,
379 /*OUT*/Char* buf, Int nBuf );
sewardj7ce71662008-05-02 10:33:15 +0000380
381Char* MC_(get_error_name) ( Error* err );
382
383/* Recording of errors */
384void MC_(record_address_error) ( ThreadId tid, Addr a, Int szB,
385 Bool isWrite );
386void MC_(record_cond_error) ( ThreadId tid, UInt otag );
387void MC_(record_value_error) ( ThreadId tid, Int szB, UInt otag );
388void MC_(record_jump_error) ( ThreadId tid, Addr a );
389
390void MC_(record_free_error) ( ThreadId tid, Addr a );
391void MC_(record_illegal_mempool_error) ( ThreadId tid, Addr a );
392void MC_(record_freemismatch_error) ( ThreadId tid, MC_Chunk* mc );
393
394void MC_(record_overlap_error) ( ThreadId tid, Char* function,
395 Addr src, Addr dst, SizeT szB );
njn1dcee092009-02-24 03:07:37 +0000396void MC_(record_core_mem_error) ( ThreadId tid, Char* msg );
sewardj7ce71662008-05-02 10:33:15 +0000397void MC_(record_regparam_error) ( ThreadId tid, Char* msg, UInt otag );
398void MC_(record_memparam_error) ( ThreadId tid, Addr a,
399 Bool isAddrErr, Char* msg, UInt otag );
400void MC_(record_user_error) ( ThreadId tid, Addr a,
401 Bool isAddrErr, UInt otag );
402
403Bool MC_(record_leak_error) ( ThreadId tid,
404 UInt n_this_record,
405 UInt n_total_records,
406 LossRecord* lossRecord,
njn18afe5d2009-08-10 08:25:39 +0000407 Bool print_record,
408 Bool count_error );
sewardj7ce71662008-05-02 10:33:15 +0000409
sewardj3b290482011-05-06 21:02:55 +0000410/* prints a description of address a */
411void MC_(pp_describe_addr) (Addr a);
412
sewardj7ce71662008-05-02 10:33:15 +0000413/* Is this address in a user-specified "ignored range" ? */
414Bool MC_(in_ignored_range) ( Addr a );
415
416
417/*------------------------------------------------------------*/
418/*--- Client blocks ---*/
419/*------------------------------------------------------------*/
420
421/* Describes a client block. See mc_main.c. An unused block has
422 start == size == 0. */
423typedef
424 struct {
425 Addr start;
426 SizeT size;
427 ExeContext* where;
428 Char* desc;
429 }
430 CGenBlock;
431
432/* Get access to the client block array. */
433void MC_(get_ClientBlock_array)( /*OUT*/CGenBlock** blocks,
434 /*OUT*/UWord* nBlocks );
435
njn718d3b12006-12-16 00:54:12 +0000436
njn1d0825f2006-03-27 11:37:07 +0000437/*------------------------------------------------------------*/
438/*--- Command line options + defaults ---*/
439/*------------------------------------------------------------*/
440
441/* Allow loads from partially-valid addresses? default: YES */
sewardj505a8192008-07-18 20:15:46 +0000442extern Bool MC_(clo_partial_loads_ok);
njn1d0825f2006-03-27 11:37:07 +0000443
444/* Max volume of the freed blocks queue. */
sewardj505a8192008-07-18 20:15:46 +0000445extern Long MC_(clo_freelist_vol);
njn1d0825f2006-03-27 11:37:07 +0000446
sewardj403d8aa2011-10-22 19:48:57 +0000447/* Blocks with a size >= MC_(clo_freelist_big_blocks) will be put
448 in the "big block" freed blocks queue. */
449extern Long MC_(clo_freelist_big_blocks);
450
njn1d0825f2006-03-27 11:37:07 +0000451/* Do leak check at exit? default: NO */
sewardj505a8192008-07-18 20:15:46 +0000452extern LeakCheckMode MC_(clo_leak_check);
njn1d0825f2006-03-27 11:37:07 +0000453
454/* How closely should we compare ExeContexts in leak records? default: 2 */
sewardj505a8192008-07-18 20:15:46 +0000455extern VgRes MC_(clo_leak_resolution);
njn1d0825f2006-03-27 11:37:07 +0000456
457/* In leak check, show reachable-but-not-freed blocks? default: NO */
sewardj505a8192008-07-18 20:15:46 +0000458extern Bool MC_(clo_show_reachable);
njn1d0825f2006-03-27 11:37:07 +0000459
bart3cedf572010-08-26 10:56:27 +0000460/* In leak check, show possibly-lost blocks? default: YES */
461extern Bool MC_(clo_show_possibly_lost);
462
njn1d0825f2006-03-27 11:37:07 +0000463/* Assume accesses immediately below %esp are due to gcc-2.96 bugs.
464 * default: NO */
sewardj505a8192008-07-18 20:15:46 +0000465extern Bool MC_(clo_workaround_gcc296_bugs);
njn1d0825f2006-03-27 11:37:07 +0000466
sewardjeb0fa932007-11-30 21:41:40 +0000467/* Fill malloc-d/free-d client blocks with a specific value? -1 if
468 not, else 0x00 .. 0xFF indicating the fill value to use. Can be
469 useful for causing programs with bad heap corruption to fail in
470 more repeatable ways. Note that malloc-filled and free-filled
471 areas are still undefined and noaccess respectively. This merely
472 causes them to contain the specified values. */
sewardj505a8192008-07-18 20:15:46 +0000473extern Int MC_(clo_malloc_fill);
474extern Int MC_(clo_free_fill);
sewardjeb0fa932007-11-30 21:41:40 +0000475
sewardj7cf4e6b2008-05-01 20:24:26 +0000476/* Indicates the level of instrumentation/checking done by Memcheck.
477
478 1 = No undefined value checking, Addrcheck-style behaviour only:
479 only address checking is done. This is faster but finds fewer
480 errors. Note that although Addrcheck had 1 bit per byte
481 overhead vs the old Memcheck's 9 bits per byte, with this mode
482 and compressed V bits, no memory is saved with this mode --
483 it's still 2 bits per byte overhead. This is a little wasteful
484 -- it could be done with 1 bit per byte -- but lets us reuse
485 the many shadow memory access functions. Note that in this
486 mode neither the secondary V bit table nor the origin-tag cache
487 are used.
488
489 2 = Address checking and Undefined value checking are performed,
490 but origins are not tracked. So the origin-tag cache is not
491 used in this mode. This setting is the default and corresponds
492 to the "normal" Memcheck behaviour that has shipped for years.
493
494 3 = Address checking, undefined value checking, and origins for
495 undefined values are tracked.
496
497 The default is 2.
498*/
sewardj505a8192008-07-18 20:15:46 +0000499extern Int MC_(clo_mc_level);
sewardj7cf4e6b2008-05-01 20:24:26 +0000500
njn1d0825f2006-03-27 11:37:07 +0000501
502/*------------------------------------------------------------*/
503/*--- Instrumentation ---*/
njn25e49d8e72002-09-23 09:36:25 +0000504/*------------------------------------------------------------*/
505
njn66fe05a2003-07-22 09:12:33 +0000506/* Functions defined in mc_main.c */
sewardj95448072004-11-22 20:19:51 +0000507
sewardj7cf4e6b2008-05-01 20:24:26 +0000508/* For the fail_w_o functions, the UWord arg is actually the 32-bit
509 origin tag and should really be UInt, but to be simple and safe
510 considering it's called from generated code, just claim it to be a
511 UWord. */
sewardj56adc352008-05-02 11:25:17 +0000512VG_REGPARM(2) void MC_(helperc_value_checkN_fail_w_o) ( HWord, UWord );
513VG_REGPARM(1) void MC_(helperc_value_check8_fail_w_o) ( UWord );
514VG_REGPARM(1) void MC_(helperc_value_check4_fail_w_o) ( UWord );
515VG_REGPARM(1) void MC_(helperc_value_check1_fail_w_o) ( UWord );
516VG_REGPARM(1) void MC_(helperc_value_check0_fail_w_o) ( UWord );
sewardj7cf4e6b2008-05-01 20:24:26 +0000517
518/* And call these ones instead to report an uninitialised value error
519 but with no origin available. */
sewardj56adc352008-05-02 11:25:17 +0000520VG_REGPARM(1) void MC_(helperc_value_checkN_fail_no_o) ( HWord );
521VG_REGPARM(0) void MC_(helperc_value_check8_fail_no_o) ( void );
522VG_REGPARM(0) void MC_(helperc_value_check4_fail_no_o) ( void );
523VG_REGPARM(0) void MC_(helperc_value_check1_fail_no_o) ( void );
524VG_REGPARM(0) void MC_(helperc_value_check0_fail_no_o) ( void );
sewardj7cf4e6b2008-05-01 20:24:26 +0000525
526/* V-bits load/store helpers */
sewardj56adc352008-05-02 11:25:17 +0000527VG_REGPARM(1) void MC_(helperc_STOREV64be) ( Addr, ULong );
528VG_REGPARM(1) void MC_(helperc_STOREV64le) ( Addr, ULong );
529VG_REGPARM(2) void MC_(helperc_STOREV32be) ( Addr, UWord );
530VG_REGPARM(2) void MC_(helperc_STOREV32le) ( Addr, UWord );
531VG_REGPARM(2) void MC_(helperc_STOREV16be) ( Addr, UWord );
532VG_REGPARM(2) void MC_(helperc_STOREV16le) ( Addr, UWord );
533VG_REGPARM(2) void MC_(helperc_STOREV8) ( Addr, UWord );
sewardj95448072004-11-22 20:19:51 +0000534
sewardj56adc352008-05-02 11:25:17 +0000535VG_REGPARM(1) ULong MC_(helperc_LOADV64be) ( Addr );
536VG_REGPARM(1) ULong MC_(helperc_LOADV64le) ( Addr );
537VG_REGPARM(1) UWord MC_(helperc_LOADV32be) ( Addr );
538VG_REGPARM(1) UWord MC_(helperc_LOADV32le) ( Addr );
539VG_REGPARM(1) UWord MC_(helperc_LOADV16be) ( Addr );
540VG_REGPARM(1) UWord MC_(helperc_LOADV16le) ( Addr );
541VG_REGPARM(1) UWord MC_(helperc_LOADV8) ( Addr );
njn25e49d8e72002-09-23 09:36:25 +0000542
sewardj56adc352008-05-02 11:25:17 +0000543void MC_(helperc_MAKE_STACK_UNINIT) ( Addr base, UWord len,
544 Addr nia );
sewardj7cf4e6b2008-05-01 20:24:26 +0000545
546/* Origin tag load/store helpers */
547VG_REGPARM(2) void MC_(helperc_b_store1) ( Addr a, UWord d32 );
548VG_REGPARM(2) void MC_(helperc_b_store2) ( Addr a, UWord d32 );
549VG_REGPARM(2) void MC_(helperc_b_store4) ( Addr a, UWord d32 );
550VG_REGPARM(2) void MC_(helperc_b_store8) ( Addr a, UWord d32 );
551VG_REGPARM(2) void MC_(helperc_b_store16)( Addr a, UWord d32 );
552VG_REGPARM(1) UWord MC_(helperc_b_load1) ( Addr a );
553VG_REGPARM(1) UWord MC_(helperc_b_load2) ( Addr a );
554VG_REGPARM(1) UWord MC_(helperc_b_load4) ( Addr a );
555VG_REGPARM(1) UWord MC_(helperc_b_load8) ( Addr a );
556VG_REGPARM(1) UWord MC_(helperc_b_load16)( Addr a );
sewardj826ec492005-05-12 18:05:00 +0000557
njn51d827b2005-05-09 01:02:08 +0000558/* Functions defined in mc_translate.c */
sewardj0b9d74a2006-12-24 02:24:11 +0000559IRSB* MC_(instrument) ( VgCallbackClosure* closure,
560 IRSB* bb_in,
sewardj461df9c2006-01-17 02:06:39 +0000561 VexGuestLayout* layout,
562 VexGuestExtents* vge,
sewardj4ba057c2005-10-18 12:04:18 +0000563 IRType gWordTy, IRType hWordTy );
sewardj8d61eb12005-07-08 09:46:53 +0000564
sewardj81651dc2007-08-28 06:05:20 +0000565IRSB* MC_(final_tidy) ( IRSB* );
566
sewardj8d61eb12005-07-08 09:46:53 +0000567#endif /* ndef __MC_INCLUDE_H */
njn25e49d8e72002-09-23 09:36:25 +0000568
569/*--------------------------------------------------------------------*/
nethercote8b76fe52004-11-08 19:20:09 +0000570/*--- end ---*/
njn25e49d8e72002-09-23 09:36:25 +0000571/*--------------------------------------------------------------------*/