blob: f9f07bfa026159b0f65960b1ff4480996254e3a2 [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
sewardj03f8d3f2012-08-05 15:46:46 +000011 Copyright (C) 2000-2012 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
philipped99c26a2012-07-31 22:17:28 +000045/* By default, we want at least a 16B redzone on client heap blocks
46 for Memcheck.
47 The default can be modified by --redzone-size. */
48#define MC_MALLOC_DEFAULT_REDZONE_SZB 16
49// effective redzone, as (possibly) modified by --redzone-size:
50extern SizeT MC_(Malloc_Redzone_SzB);
njn1d0825f2006-03-27 11:37:07 +000051
52/* For malloc()/new/new[] vs. free()/delete/delete[] mismatch checking. */
53typedef
54 enum {
55 MC_AllocMalloc = 0,
56 MC_AllocNew = 1,
57 MC_AllocNewVec = 2,
58 MC_AllocCustom = 3
59 }
60 MC_AllocKind;
61
njn8225cc02009-03-09 22:52:24 +000062/* This describes a heap block. Nb: first two fields must match core's
63 * VgHashNode. */
njn1d0825f2006-03-27 11:37:07 +000064typedef
65 struct _MC_Chunk {
66 struct _MC_Chunk* next;
njn8225cc02009-03-09 22:52:24 +000067 Addr data; // Address of the actual block.
68 SizeT szB : (sizeof(SizeT)*8)-2; // Size requested; 30 or 62 bits.
69 MC_AllocKind allockind : 2; // Which operation did the allocation.
70 ExeContext* where; // Where it was allocated.
njn1d0825f2006-03-27 11:37:07 +000071 }
72 MC_Chunk;
73
74/* Memory pool. Nb: first two fields must match core's VgHashNode. */
75typedef
76 struct _MC_Mempool {
77 struct _MC_Mempool* next;
78 Addr pool; // pool identifier
79 SizeT rzB; // pool red-zone size
80 Bool is_zeroed; // allocations from this pool are zeroed
81 VgHashTable chunks; // chunks associated with this pool
82 }
83 MC_Mempool;
84
85
sewardj56adc352008-05-02 11:25:17 +000086void* MC_(new_block) ( ThreadId tid,
njn1dcee092009-02-24 03:07:37 +000087 Addr p, SizeT size, SizeT align,
sewardj56adc352008-05-02 11:25:17 +000088 Bool is_zeroed, MC_AllocKind kind,
89 VgHashTable table);
90void MC_(handle_free) ( ThreadId tid,
91 Addr p, UInt rzB, MC_AllocKind kind );
njn1d0825f2006-03-27 11:37:07 +000092
sewardj56adc352008-05-02 11:25:17 +000093void MC_(create_mempool) ( Addr pool, UInt rzB, Bool is_zeroed );
94void MC_(destroy_mempool) ( Addr pool );
95void MC_(mempool_alloc) ( ThreadId tid, Addr pool,
96 Addr addr, SizeT size );
97void MC_(mempool_free) ( Addr pool, Addr addr );
98void MC_(mempool_trim) ( Addr pool, Addr addr, SizeT size );
99void MC_(move_mempool) ( Addr poolA, Addr poolB );
100void MC_(mempool_change) ( Addr pool, Addr addrA, Addr addrB, SizeT size );
101Bool MC_(mempool_exists) ( Addr pool );
njn1d0825f2006-03-27 11:37:07 +0000102
sewardj403d8aa2011-10-22 19:48:57 +0000103/* Searches for a recently freed block which might bracket Addr a.
104 Return the MC_Chunk* for this block or NULL if no bracketting block
105 is found. */
106MC_Chunk* MC_(get_freed_block_bracketting)( Addr a );
njn1d0825f2006-03-27 11:37:07 +0000107
philippe6643e962012-01-17 21:16:30 +0000108/* For efficient pooled alloc/free of the MC_Chunk. */
109extern PoolAlloc* MC_(chunk_poolalloc);
110
njnb965efb2009-08-10 07:36:54 +0000111/* For tracking malloc'd blocks. Nb: it's quite important that it's a
112 VgHashTable, because VgHashTable allows duplicate keys without complaint.
113 This can occur if a user marks a malloc() block as also a custom block with
114 MALLOCLIKE_BLOCK. */
sewardj505a8192008-07-18 20:15:46 +0000115extern VgHashTable MC_(malloc_list);
njn1d0825f2006-03-27 11:37:07 +0000116
117/* For tracking memory pools. */
sewardj505a8192008-07-18 20:15:46 +0000118extern VgHashTable MC_(mempool_list);
njn1d0825f2006-03-27 11:37:07 +0000119
120/* Shadow memory functions */
sewardj56adc352008-05-02 11:25:17 +0000121Bool MC_(check_mem_is_noaccess)( Addr a, SizeT len, Addr* bad_addr );
122void MC_(make_mem_noaccess) ( Addr a, SizeT len );
123void MC_(make_mem_undefined_w_otag)( Addr a, SizeT len, UInt otag );
124void MC_(make_mem_defined) ( Addr a, SizeT len );
125void MC_(copy_address_range_state) ( Addr src, Addr dst, SizeT len );
njn1d0825f2006-03-27 11:37:07 +0000126
sewardj56adc352008-05-02 11:25:17 +0000127void MC_(print_malloc_stats) ( void );
philippea22f59d2012-01-26 23:13:52 +0000128/* nr of free operations done */
129SizeT MC_(get_cmalloc_n_frees) ( void );
njn1d0825f2006-03-27 11:37:07 +0000130
sewardj56adc352008-05-02 11:25:17 +0000131void* MC_(malloc) ( ThreadId tid, SizeT n );
132void* MC_(__builtin_new) ( ThreadId tid, SizeT n );
133void* MC_(__builtin_vec_new) ( ThreadId tid, SizeT n );
134void* MC_(memalign) ( ThreadId tid, SizeT align, SizeT n );
135void* MC_(calloc) ( ThreadId tid, SizeT nmemb, SizeT size1 );
136void MC_(free) ( ThreadId tid, void* p );
137void MC_(__builtin_delete) ( ThreadId tid, void* p );
138void MC_(__builtin_vec_delete) ( ThreadId tid, void* p );
139void* MC_(realloc) ( ThreadId tid, void* p, SizeT new_size );
njn8b140de2009-02-17 04:31:18 +0000140SizeT MC_(malloc_usable_size) ( ThreadId tid, void* p );
sewardj56adc352008-05-02 11:25:17 +0000141
bart91347382011-03-25 20:07:25 +0000142void MC_(handle_resizeInPlace)(ThreadId tid, Addr p,
143 SizeT oldSizeB, SizeT newSizeB, SizeT rzB);
144
njn43c799e2003-04-08 00:08:52 +0000145
sewardj7cf4e6b2008-05-01 20:24:26 +0000146/*------------------------------------------------------------*/
147/*--- Origin tracking translate-time support ---*/
148/*------------------------------------------------------------*/
149
150/* See detailed comments in mc_machine.c. */
sewardj7cf4e6b2008-05-01 20:24:26 +0000151Int MC_(get_otrack_shadow_offset) ( Int offset, Int szB );
sewardj7cf4e6b2008-05-01 20:24:26 +0000152IRType MC_(get_otrack_reg_array_equiv_int_type) ( IRRegArray* arr );
153
154/* Constants which are used as the lowest 2 bits in origin tags.
155
156 An origin tag comprises an upper 30-bit ECU field and a lower 2-bit
157 'kind' field. The ECU field is a number given out by m_execontext
158 and has a 1-1 mapping with ExeContext*s. An ECU can be used
159 directly as an origin tag (otag), but in fact we want to put
160 additional information 'kind' field to indicate roughly where the
161 tag came from. This helps print more understandable error messages
162 for the user -- it has no other purpose.
163
164 Hence the following 2-bit constants are needed for 'kind' field.
165
166 To summarise:
167
168 * Both ECUs and origin tags are represented as 32-bit words
169
170 * m_execontext and the core-tool interface deal purely in ECUs.
171 They have no knowledge of origin tags - that is a purely
172 Memcheck-internal matter.
173
174 * all valid ECUs have the lowest 2 bits zero and at least
175 one of the upper 30 bits nonzero (see VG_(is_plausible_ECU))
176
177 * to convert from an ECU to an otag, OR in one of the MC_OKIND_
178 constants below
179
180 * to convert an otag back to an ECU, AND it with ~3
181*/
182
183#define MC_OKIND_UNKNOWN 0 /* unknown origin */
184#define MC_OKIND_HEAP 1 /* this is a heap origin */
185#define MC_OKIND_STACK 2 /* this is a stack origin */
186#define MC_OKIND_USER 3 /* arises from user-supplied client req */
187
njn43c799e2003-04-08 00:08:52 +0000188
189/*------------------------------------------------------------*/
njn1d0825f2006-03-27 11:37:07 +0000190/*--- Profiling of memory events ---*/
191/*------------------------------------------------------------*/
192
193/* Define to collect detailed performance info. */
194/* #define MC_PROFILE_MEMORY */
195
196#ifdef MC_PROFILE_MEMORY
197# define N_PROF_EVENTS 500
198
sewardj56adc352008-05-02 11:25:17 +0000199UInt MC_(event_ctr)[N_PROF_EVENTS];
200HChar* MC_(event_ctr_name)[N_PROF_EVENTS];
njn1d0825f2006-03-27 11:37:07 +0000201
202# define PROF_EVENT(ev, name) \
203 do { tl_assert((ev) >= 0 && (ev) < N_PROF_EVENTS); \
204 /* crude and inaccurate check to ensure the same */ \
205 /* event isn't being used with > 1 name */ \
206 if (MC_(event_ctr_name)[ev]) \
207 tl_assert(name == MC_(event_ctr_name)[ev]); \
208 MC_(event_ctr)[ev]++; \
209 MC_(event_ctr_name)[ev] = (name); \
210 } while (False);
211
212#else
213
214# define PROF_EVENT(ev, name) /* */
215
216#endif /* MC_PROFILE_MEMORY */
217
218
219/*------------------------------------------------------------*/
220/*--- V and A bits (Victoria & Albert ?) ---*/
221/*------------------------------------------------------------*/
222
223/* The number of entries in the primary map can be altered. However
224 we hardwire the assumption that each secondary map covers precisely
225 64k of address space. */
226#define SM_SIZE 65536 /* DO NOT CHANGE */
227#define SM_MASK (SM_SIZE-1) /* DO NOT CHANGE */
228
229#define V_BIT_DEFINED 0
230#define V_BIT_UNDEFINED 1
231
232#define V_BITS8_DEFINED 0
233#define V_BITS8_UNDEFINED 0xFF
234
235#define V_BITS16_DEFINED 0
236#define V_BITS16_UNDEFINED 0xFFFF
237
238#define V_BITS32_DEFINED 0
239#define V_BITS32_UNDEFINED 0xFFFFFFFF
240
241#define V_BITS64_DEFINED 0ULL
242#define V_BITS64_UNDEFINED 0xFFFFFFFFFFFFFFFFULL
243
244
245/*------------------------------------------------------------*/
246/*--- Leak checking ---*/
247/*------------------------------------------------------------*/
248
njn718d3b12006-12-16 00:54:12 +0000249typedef
250 enum {
njn29a5c012009-05-06 06:15:55 +0000251 // Nb: the order is important -- it dictates the order of loss records
252 // of equal sizes.
253 Reachable =0, // Definitely reachable from root-set.
254 Possible =1, // Possibly reachable from root-set; involves at
njn8225cc02009-03-09 22:52:24 +0000255 // least one interior-pointer along the way.
njn29a5c012009-05-06 06:15:55 +0000256 IndirectLeak =2, // Leaked, but reachable from another leaked block
257 // (be it Unreached or IndirectLeak).
258 Unreached =3, // Not reached, ie. leaked.
259 // (At best, only reachable from itself via a cycle.)
njn718d3b12006-12-16 00:54:12 +0000260 }
261 Reachedness;
262
philippe2193a7c2012-12-08 17:54:16 +0000263// Build mask to check or set Reachedness r membership
264#define R2S(r) (1 << (r))
265// Reachedness r is member of the Set s ?
266#define RiS(r,s) ((s) & R2S(r))
267// A set with all Reachedness:
268#define RallS \
269 (R2S(Reachable) | R2S(Possible) | R2S(IndirectLeak) | R2S(Unreached))
philippea22f59d2012-01-26 23:13:52 +0000270
njn1d0825f2006-03-27 11:37:07 +0000271/* For VALGRIND_COUNT_LEAKS client request */
sewardj505a8192008-07-18 20:15:46 +0000272extern SizeT MC_(bytes_leaked);
273extern SizeT MC_(bytes_indirect);
274extern SizeT MC_(bytes_dubious);
275extern SizeT MC_(bytes_reachable);
276extern SizeT MC_(bytes_suppressed);
njn1d0825f2006-03-27 11:37:07 +0000277
njn8df80b22009-03-02 05:11:06 +0000278/* For VALGRIND_COUNT_LEAK_BLOCKS client request */
279extern SizeT MC_(blocks_leaked);
280extern SizeT MC_(blocks_indirect);
281extern SizeT MC_(blocks_dubious);
282extern SizeT MC_(blocks_reachable);
283extern SizeT MC_(blocks_suppressed);
284
njn1d0825f2006-03-27 11:37:07 +0000285typedef
286 enum {
287 LC_Off,
288 LC_Summary,
289 LC_Full,
290 }
291 LeakCheckMode;
292
sewardjc8bd1df2011-06-26 12:41:33 +0000293typedef
294 enum {
295 LCD_Any, // output all loss records, whatever the delta
296 LCD_Increased, // output loss records with an increase in size or blocks
297 LCD_Changed, // output loss records with an increase or
298 //decrease in size or blocks
299 }
300 LeakCheckDeltaMode;
301
njn29a5c012009-05-06 06:15:55 +0000302/* When a LossRecord is put into an OSet, these elements represent the key. */
303typedef
304 struct _LossRecordKey {
305 Reachedness state; // LC_Extra.state value shared by all blocks.
306 ExeContext* allocated_at; // Where they were allocated.
307 }
308 LossRecordKey;
309
njnb7a4e2e2009-05-01 00:30:43 +0000310/* A loss record, used for generating err msgs. Multiple leaked blocks can be
311 * merged into a single loss record if they have the same state and similar
312 * enough allocation points (controlled by --leak-resolution). */
njn718d3b12006-12-16 00:54:12 +0000313typedef
314 struct _LossRecord {
njn29a5c012009-05-06 06:15:55 +0000315 LossRecordKey key; // Key, when used in an OSet.
316 SizeT szB; // Sum of all MC_Chunk.szB values.
317 SizeT indirect_szB; // Sum of all LC_Extra.indirect_szB values.
318 UInt num_blocks; // Number of blocks represented by the record.
sewardjc8bd1df2011-06-26 12:41:33 +0000319 SizeT old_szB; // old_* values are the values found during the
320 SizeT old_indirect_szB; // previous leak search. old_* values are used to
321 UInt old_num_blocks; // output only the changed/new loss records
njn718d3b12006-12-16 00:54:12 +0000322 }
323 LossRecord;
324
sewardjc8bd1df2011-06-26 12:41:33 +0000325typedef
326 struct _LeakCheckParams {
327 LeakCheckMode mode;
philippe2193a7c2012-12-08 17:54:16 +0000328 UInt show_leak_kinds;
329 UInt errors_for_leak_kinds;
sewardjc8bd1df2011-06-26 12:41:33 +0000330 LeakCheckDeltaMode deltamode;
philippe84234902012-01-14 13:53:13 +0000331 UInt max_loss_records_output; // limit on the nr of loss records output.
sewardjc8bd1df2011-06-26 12:41:33 +0000332 Bool requested_by_monitor_command; // True when requested by gdb/vgdb.
333 }
334 LeakCheckParams;
335
philippe84234902012-01-14 13:53:13 +0000336void MC_(detect_memory_leaks) ( ThreadId tid, LeakCheckParams * lcp);
sewardjc8bd1df2011-06-26 12:41:33 +0000337
338// maintains the lcp.deltamode given in the last call to detect_memory_leaks
339extern LeakCheckDeltaMode MC_(detect_memory_leaks_last_delta_mode);
340
philippea22f59d2012-01-26 23:13:52 +0000341// prints the list of blocks corresponding to the given loss_record_nr.
342// Returns True if loss_record_nr identifies a correct loss record from last leak search.
343// Returns False otherwise.
344Bool MC_(print_block_list) ( UInt loss_record_nr);
345
346// Prints the addresses/registers/... at which a pointer to
347// the given range [address, address+szB[ is found.
348void MC_(who_points_at) ( Addr address, SizeT szB);
349
sewardj30b3eca2011-06-28 08:20:39 +0000350// if delta_mode == LCD_Any, prints in buf an empty string
sewardjc8bd1df2011-06-26 12:41:33 +0000351// otherwise prints a delta in the layout " (+%'lu)" or " (-%'lu)"
floriandbb35842012-10-27 18:39:11 +0000352extern HChar * MC_(snprintf_delta) (HChar * buf, Int size,
353 SizeT current_val, SizeT old_val,
354 LeakCheckDeltaMode delta_mode);
sewardjc8bd1df2011-06-26 12:41:33 +0000355
njn8225cc02009-03-09 22:52:24 +0000356
357Bool MC_(is_valid_aligned_word) ( Addr a );
358Bool MC_(is_within_valid_secondary) ( Addr a );
njn1d0825f2006-03-27 11:37:07 +0000359
philippea22f59d2012-01-26 23:13:52 +0000360// Prints as user msg a description of the given loss record.
361void MC_(pp_LossRecord)(UInt n_this_record, UInt n_total_records,
362 LossRecord* l);
njn718d3b12006-12-16 00:54:12 +0000363
364
365/*------------------------------------------------------------*/
366/*--- Errors and suppressions ---*/
367/*------------------------------------------------------------*/
368
sewardj7ce71662008-05-02 10:33:15 +0000369/* Did we show to the user, any errors for which an uninitialised
370 value origin could have been collected (but wasn't) ? If yes,
371 then, at the end of the run, print a 1 line message advising that a
372 rerun with --track-origins=yes might help. */
sewardj505a8192008-07-18 20:15:46 +0000373extern Bool MC_(any_value_errors);
sewardj7ce71662008-05-02 10:33:15 +0000374
375/* Standard functions for error and suppressions as required by the
376 core/tool iface */
sewardj6b523cd2009-07-15 14:49:40 +0000377Bool MC_(eq_Error) ( VgRes res, Error* e1, Error* e2 );
378void MC_(before_pp_Error) ( Error* err );
379void MC_(pp_Error) ( Error* err );
380UInt MC_(update_Error_extra) ( Error* err );
sewardj7ce71662008-05-02 10:33:15 +0000381
florian19f91bb2012-11-10 22:29:54 +0000382Bool MC_(is_recognised_suppression) ( const HChar* name, Supp* su );
sewardj7ce71662008-05-02 10:33:15 +0000383
florian19f91bb2012-11-10 22:29:54 +0000384Bool MC_(read_extra_suppression_info) ( Int fd, HChar** buf,
njn35db56c2009-07-24 07:38:29 +0000385 SizeT* nBuf, Supp *su );
sewardj7ce71662008-05-02 10:33:15 +0000386
387Bool MC_(error_matches_suppression) ( Error* err, Supp* su );
388
sewardj588adef2009-08-15 22:41:51 +0000389Bool MC_(get_extra_suppression_info) ( Error* err,
floriandbb35842012-10-27 18:39:11 +0000390 /*OUT*/HChar* buf, Int nBuf );
sewardj7ce71662008-05-02 10:33:15 +0000391
floriane543f302012-10-21 19:43:43 +0000392const HChar* MC_(get_error_name) ( Error* err );
sewardj7ce71662008-05-02 10:33:15 +0000393
394/* Recording of errors */
395void MC_(record_address_error) ( ThreadId tid, Addr a, Int szB,
396 Bool isWrite );
397void MC_(record_cond_error) ( ThreadId tid, UInt otag );
398void MC_(record_value_error) ( ThreadId tid, Int szB, UInt otag );
399void MC_(record_jump_error) ( ThreadId tid, Addr a );
400
401void MC_(record_free_error) ( ThreadId tid, Addr a );
402void MC_(record_illegal_mempool_error) ( ThreadId tid, Addr a );
403void MC_(record_freemismatch_error) ( ThreadId tid, MC_Chunk* mc );
404
floriane543f302012-10-21 19:43:43 +0000405void MC_(record_overlap_error) ( ThreadId tid, const HChar* function,
sewardj7ce71662008-05-02 10:33:15 +0000406 Addr src, Addr dst, SizeT szB );
floriane543f302012-10-21 19:43:43 +0000407void MC_(record_core_mem_error) ( ThreadId tid, const HChar* msg );
408void MC_(record_regparam_error) ( ThreadId tid, const HChar* msg, UInt otag );
sewardj7ce71662008-05-02 10:33:15 +0000409void MC_(record_memparam_error) ( ThreadId tid, Addr a,
floriane543f302012-10-21 19:43:43 +0000410 Bool isAddrErr, const HChar* msg, UInt otag );
sewardj7ce71662008-05-02 10:33:15 +0000411void MC_(record_user_error) ( ThreadId tid, Addr a,
412 Bool isAddrErr, UInt otag );
413
414Bool MC_(record_leak_error) ( ThreadId tid,
415 UInt n_this_record,
416 UInt n_total_records,
417 LossRecord* lossRecord,
njn18afe5d2009-08-10 08:25:39 +0000418 Bool print_record,
419 Bool count_error );
sewardj7ce71662008-05-02 10:33:15 +0000420
philippe2193a7c2012-12-08 17:54:16 +0000421/* Parses a set of leak kinds (separated by ,).
422 and give the resulting set in *lks.
423 If parsing is succesful, returns True and *lks contains the resulting set.
424 else return False. */
425extern Bool MC_(parse_leak_kinds) ( const HChar* str0, UInt* lks );
426
sewardj3b290482011-05-06 21:02:55 +0000427/* prints a description of address a */
428void MC_(pp_describe_addr) (Addr a);
429
sewardj7ce71662008-05-02 10:33:15 +0000430/* Is this address in a user-specified "ignored range" ? */
431Bool MC_(in_ignored_range) ( Addr a );
432
433
434/*------------------------------------------------------------*/
435/*--- Client blocks ---*/
436/*------------------------------------------------------------*/
437
438/* Describes a client block. See mc_main.c. An unused block has
439 start == size == 0. */
440typedef
441 struct {
442 Addr start;
443 SizeT size;
444 ExeContext* where;
floriana5f894c2012-10-21 03:43:20 +0000445 HChar* desc;
sewardj7ce71662008-05-02 10:33:15 +0000446 }
447 CGenBlock;
448
449/* Get access to the client block array. */
450void MC_(get_ClientBlock_array)( /*OUT*/CGenBlock** blocks,
451 /*OUT*/UWord* nBlocks );
452
njn718d3b12006-12-16 00:54:12 +0000453
njn1d0825f2006-03-27 11:37:07 +0000454/*------------------------------------------------------------*/
455/*--- Command line options + defaults ---*/
456/*------------------------------------------------------------*/
457
458/* Allow loads from partially-valid addresses? default: YES */
sewardj505a8192008-07-18 20:15:46 +0000459extern Bool MC_(clo_partial_loads_ok);
njn1d0825f2006-03-27 11:37:07 +0000460
461/* Max volume of the freed blocks queue. */
sewardj505a8192008-07-18 20:15:46 +0000462extern Long MC_(clo_freelist_vol);
njn1d0825f2006-03-27 11:37:07 +0000463
sewardj403d8aa2011-10-22 19:48:57 +0000464/* Blocks with a size >= MC_(clo_freelist_big_blocks) will be put
465 in the "big block" freed blocks queue. */
466extern Long MC_(clo_freelist_big_blocks);
467
njn1d0825f2006-03-27 11:37:07 +0000468/* Do leak check at exit? default: NO */
sewardj505a8192008-07-18 20:15:46 +0000469extern LeakCheckMode MC_(clo_leak_check);
njn1d0825f2006-03-27 11:37:07 +0000470
471/* How closely should we compare ExeContexts in leak records? default: 2 */
sewardj505a8192008-07-18 20:15:46 +0000472extern VgRes MC_(clo_leak_resolution);
njn1d0825f2006-03-27 11:37:07 +0000473
philippe2193a7c2012-12-08 17:54:16 +0000474/* In leak check, show loss records if their R2S(reachedness) is set.
475 Default : R2S(Possible) | R2S(Unreached). */
476extern UInt MC_(clo_show_leak_kinds);
njn1d0825f2006-03-27 11:37:07 +0000477
philippe2193a7c2012-12-08 17:54:16 +0000478/* In leak check, a loss record is an error if its R2S(reachedness) is set.
479 Default : R2S(Possible) | R2S(Unreached). */
480extern UInt MC_(clo_errors_for_leak_kinds);
bart3cedf572010-08-26 10:56:27 +0000481
njn1d0825f2006-03-27 11:37:07 +0000482/* Assume accesses immediately below %esp are due to gcc-2.96 bugs.
483 * default: NO */
sewardj505a8192008-07-18 20:15:46 +0000484extern Bool MC_(clo_workaround_gcc296_bugs);
njn1d0825f2006-03-27 11:37:07 +0000485
sewardjeb0fa932007-11-30 21:41:40 +0000486/* Fill malloc-d/free-d client blocks with a specific value? -1 if
487 not, else 0x00 .. 0xFF indicating the fill value to use. Can be
488 useful for causing programs with bad heap corruption to fail in
489 more repeatable ways. Note that malloc-filled and free-filled
490 areas are still undefined and noaccess respectively. This merely
491 causes them to contain the specified values. */
sewardj505a8192008-07-18 20:15:46 +0000492extern Int MC_(clo_malloc_fill);
493extern Int MC_(clo_free_fill);
sewardjeb0fa932007-11-30 21:41:40 +0000494
sewardj7cf4e6b2008-05-01 20:24:26 +0000495/* Indicates the level of instrumentation/checking done by Memcheck.
496
497 1 = No undefined value checking, Addrcheck-style behaviour only:
498 only address checking is done. This is faster but finds fewer
499 errors. Note that although Addrcheck had 1 bit per byte
500 overhead vs the old Memcheck's 9 bits per byte, with this mode
501 and compressed V bits, no memory is saved with this mode --
502 it's still 2 bits per byte overhead. This is a little wasteful
503 -- it could be done with 1 bit per byte -- but lets us reuse
504 the many shadow memory access functions. Note that in this
505 mode neither the secondary V bit table nor the origin-tag cache
506 are used.
507
508 2 = Address checking and Undefined value checking are performed,
509 but origins are not tracked. So the origin-tag cache is not
510 used in this mode. This setting is the default and corresponds
511 to the "normal" Memcheck behaviour that has shipped for years.
512
513 3 = Address checking, undefined value checking, and origins for
514 undefined values are tracked.
515
516 The default is 2.
517*/
sewardj505a8192008-07-18 20:15:46 +0000518extern Int MC_(clo_mc_level);
sewardj7cf4e6b2008-05-01 20:24:26 +0000519
njn1d0825f2006-03-27 11:37:07 +0000520
521/*------------------------------------------------------------*/
522/*--- Instrumentation ---*/
njn25e49d8e72002-09-23 09:36:25 +0000523/*------------------------------------------------------------*/
524
njn66fe05a2003-07-22 09:12:33 +0000525/* Functions defined in mc_main.c */
sewardj95448072004-11-22 20:19:51 +0000526
sewardj7cf4e6b2008-05-01 20:24:26 +0000527/* For the fail_w_o functions, the UWord arg is actually the 32-bit
528 origin tag and should really be UInt, but to be simple and safe
529 considering it's called from generated code, just claim it to be a
530 UWord. */
sewardj56adc352008-05-02 11:25:17 +0000531VG_REGPARM(2) void MC_(helperc_value_checkN_fail_w_o) ( HWord, UWord );
532VG_REGPARM(1) void MC_(helperc_value_check8_fail_w_o) ( UWord );
533VG_REGPARM(1) void MC_(helperc_value_check4_fail_w_o) ( UWord );
534VG_REGPARM(1) void MC_(helperc_value_check1_fail_w_o) ( UWord );
535VG_REGPARM(1) void MC_(helperc_value_check0_fail_w_o) ( UWord );
sewardj7cf4e6b2008-05-01 20:24:26 +0000536
537/* And call these ones instead to report an uninitialised value error
538 but with no origin available. */
sewardj56adc352008-05-02 11:25:17 +0000539VG_REGPARM(1) void MC_(helperc_value_checkN_fail_no_o) ( HWord );
540VG_REGPARM(0) void MC_(helperc_value_check8_fail_no_o) ( void );
541VG_REGPARM(0) void MC_(helperc_value_check4_fail_no_o) ( void );
542VG_REGPARM(0) void MC_(helperc_value_check1_fail_no_o) ( void );
543VG_REGPARM(0) void MC_(helperc_value_check0_fail_no_o) ( void );
sewardj7cf4e6b2008-05-01 20:24:26 +0000544
545/* V-bits load/store helpers */
sewardj56adc352008-05-02 11:25:17 +0000546VG_REGPARM(1) void MC_(helperc_STOREV64be) ( Addr, ULong );
547VG_REGPARM(1) void MC_(helperc_STOREV64le) ( Addr, ULong );
548VG_REGPARM(2) void MC_(helperc_STOREV32be) ( Addr, UWord );
549VG_REGPARM(2) void MC_(helperc_STOREV32le) ( Addr, UWord );
550VG_REGPARM(2) void MC_(helperc_STOREV16be) ( Addr, UWord );
551VG_REGPARM(2) void MC_(helperc_STOREV16le) ( Addr, UWord );
552VG_REGPARM(2) void MC_(helperc_STOREV8) ( Addr, UWord );
sewardj95448072004-11-22 20:19:51 +0000553
sewardj56adc352008-05-02 11:25:17 +0000554VG_REGPARM(1) ULong MC_(helperc_LOADV64be) ( Addr );
555VG_REGPARM(1) ULong MC_(helperc_LOADV64le) ( Addr );
556VG_REGPARM(1) UWord MC_(helperc_LOADV32be) ( Addr );
557VG_REGPARM(1) UWord MC_(helperc_LOADV32le) ( Addr );
558VG_REGPARM(1) UWord MC_(helperc_LOADV16be) ( Addr );
559VG_REGPARM(1) UWord MC_(helperc_LOADV16le) ( Addr );
560VG_REGPARM(1) UWord MC_(helperc_LOADV8) ( Addr );
njn25e49d8e72002-09-23 09:36:25 +0000561
sewardj56adc352008-05-02 11:25:17 +0000562void MC_(helperc_MAKE_STACK_UNINIT) ( Addr base, UWord len,
563 Addr nia );
sewardj7cf4e6b2008-05-01 20:24:26 +0000564
565/* Origin tag load/store helpers */
566VG_REGPARM(2) void MC_(helperc_b_store1) ( Addr a, UWord d32 );
567VG_REGPARM(2) void MC_(helperc_b_store2) ( Addr a, UWord d32 );
568VG_REGPARM(2) void MC_(helperc_b_store4) ( Addr a, UWord d32 );
569VG_REGPARM(2) void MC_(helperc_b_store8) ( Addr a, UWord d32 );
570VG_REGPARM(2) void MC_(helperc_b_store16)( Addr a, UWord d32 );
sewardj45fa9f42012-05-21 10:18:10 +0000571VG_REGPARM(2) void MC_(helperc_b_store32)( Addr a, UWord d32 );
sewardj7cf4e6b2008-05-01 20:24:26 +0000572VG_REGPARM(1) UWord MC_(helperc_b_load1) ( Addr a );
573VG_REGPARM(1) UWord MC_(helperc_b_load2) ( Addr a );
574VG_REGPARM(1) UWord MC_(helperc_b_load4) ( Addr a );
575VG_REGPARM(1) UWord MC_(helperc_b_load8) ( Addr a );
576VG_REGPARM(1) UWord MC_(helperc_b_load16)( Addr a );
sewardj45fa9f42012-05-21 10:18:10 +0000577VG_REGPARM(1) UWord MC_(helperc_b_load32)( Addr a );
sewardj826ec492005-05-12 18:05:00 +0000578
njn51d827b2005-05-09 01:02:08 +0000579/* Functions defined in mc_translate.c */
sewardj0b9d74a2006-12-24 02:24:11 +0000580IRSB* MC_(instrument) ( VgCallbackClosure* closure,
581 IRSB* bb_in,
sewardj461df9c2006-01-17 02:06:39 +0000582 VexGuestLayout* layout,
583 VexGuestExtents* vge,
florianca503be2012-10-07 21:59:42 +0000584 VexArchInfo* archinfo_host,
sewardj4ba057c2005-10-18 12:04:18 +0000585 IRType gWordTy, IRType hWordTy );
sewardj8d61eb12005-07-08 09:46:53 +0000586
sewardj81651dc2007-08-28 06:05:20 +0000587IRSB* MC_(final_tidy) ( IRSB* );
588
sewardj8d61eb12005-07-08 09:46:53 +0000589#endif /* ndef __MC_INCLUDE_H */
njn25e49d8e72002-09-23 09:36:25 +0000590
591/*--------------------------------------------------------------------*/
nethercote8b76fe52004-11-08 19:20:09 +0000592/*--- end ---*/
njn25e49d8e72002-09-23 09:36:25 +0000593/*--------------------------------------------------------------------*/