Home | History | Annotate | Download | only in memcheck
      1 
      2 /*--------------------------------------------------------------------*/
      3 /*--- A header file for all parts of the MemCheck tool.            ---*/
      4 /*---                                                 mc_include.h ---*/
      5 /*--------------------------------------------------------------------*/
      6 
      7 /*
      8    This file is part of MemCheck, a heavyweight Valgrind tool for
      9    detecting memory errors.
     10 
     11    Copyright (C) 2000-2013 Julian Seward
     12       jseward (at) acm.org
     13 
     14    This program is free software; you can redistribute it and/or
     15    modify it under the terms of the GNU General Public License as
     16    published by the Free Software Foundation; either version 2 of the
     17    License, or (at your option) any later version.
     18 
     19    This program is distributed in the hope that it will be useful, but
     20    WITHOUT ANY WARRANTY; without even the implied warranty of
     21    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     22    General Public License for more details.
     23 
     24    You should have received a copy of the GNU General Public License
     25    along with this program; if not, write to the Free Software
     26    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
     27    02111-1307, USA.
     28 
     29    The GNU General Public License is contained in the file COPYING.
     30 */
     31 
     32 #ifndef __MC_INCLUDE_H
     33 #define __MC_INCLUDE_H
     34 
     35 #define MC_(str)    VGAPPEND(vgMemCheck_,str)
     36 
     37 
     38 /* This is a private header file for use only within the
     39    memcheck/ directory. */
     40 
     41 /*------------------------------------------------------------*/
     42 /*--- Tracking the heap                                    ---*/
     43 /*------------------------------------------------------------*/
     44 
     45 /* 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:
     50 extern SizeT MC_(Malloc_Redzone_SzB);
     51 
     52 /* For malloc()/new/new[] vs. free()/delete/delete[] mismatch checking. */
     53 typedef
     54    enum {
     55       MC_AllocMalloc = 0,
     56       MC_AllocNew    = 1,
     57       MC_AllocNewVec = 2,
     58       MC_AllocCustom = 3
     59    }
     60    MC_AllocKind;
     61 
     62 /* This describes a heap block. Nb: first two fields must match core's
     63  * VgHashNode. */
     64 typedef
     65    struct _MC_Chunk {
     66       struct _MC_Chunk* next;
     67       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[0];
     71       /* Variable-length array. The size depends on MC_(clo_keep_stacktraces).
     72          This array optionally stores the alloc and/or free stack trace. */
     73    }
     74    MC_Chunk;
     75 
     76 /* Returns the execontext where the MC_Chunk was allocated/freed.
     77    Returns VG_(null_ExeContext)() if the execontext has not been recorded (due
     78    to MC_(clo_keep_stacktraces) and/or because block not yet freed). */
     79 ExeContext* MC_(allocated_at) (MC_Chunk*);
     80 ExeContext* MC_(freed_at) (MC_Chunk*);
     81 
     82 /* Records and sets execontext according to MC_(clo_keep_stacktraces) */
     83 void  MC_(set_allocated_at) (ThreadId, MC_Chunk*);
     84 void  MC_(set_freed_at) (ThreadId, MC_Chunk*);
     85 
     86 /* number of pointers needed according to MC_(clo_keep_stacktraces). */
     87 UInt MC_(n_where_pointers) (void);
     88 
     89 /* Memory pool.  Nb: first two fields must match core's VgHashNode. */
     90 typedef
     91    struct _MC_Mempool {
     92       struct _MC_Mempool* next;
     93       Addr          pool;           // pool identifier
     94       SizeT         rzB;            // pool red-zone size
     95       Bool          is_zeroed;      // allocations from this pool are zeroed
     96       VgHashTable   chunks;         // chunks associated with this pool
     97    }
     98    MC_Mempool;
     99 
    100 
    101 void* MC_(new_block)  ( ThreadId tid,
    102                         Addr p, SizeT size, SizeT align,
    103                         Bool is_zeroed, MC_AllocKind kind,
    104                         VgHashTable table);
    105 void MC_(handle_free) ( ThreadId tid,
    106                         Addr p, UInt rzB, MC_AllocKind kind );
    107 
    108 void MC_(create_mempool)  ( Addr pool, UInt rzB, Bool is_zeroed );
    109 void MC_(destroy_mempool) ( Addr pool );
    110 void MC_(mempool_alloc)   ( ThreadId tid, Addr pool,
    111                             Addr addr, SizeT size );
    112 void MC_(mempool_free)    ( Addr pool, Addr addr );
    113 void MC_(mempool_trim)    ( Addr pool, Addr addr, SizeT size );
    114 void MC_(move_mempool)    ( Addr poolA, Addr poolB );
    115 void MC_(mempool_change)  ( Addr pool, Addr addrA, Addr addrB, SizeT size );
    116 Bool MC_(mempool_exists)  ( Addr pool );
    117 
    118 /* Searches for a recently freed block which might bracket Addr a.
    119    Return the MC_Chunk* for this block or NULL if no bracketting block
    120    is found. */
    121 MC_Chunk* MC_(get_freed_block_bracketting)( Addr a );
    122 
    123 /* For efficient pooled alloc/free of the MC_Chunk. */
    124 extern PoolAlloc* MC_(chunk_poolalloc);
    125 
    126 /* For tracking malloc'd blocks.  Nb: it's quite important that it's a
    127    VgHashTable, because VgHashTable allows duplicate keys without complaint.
    128    This can occur if a user marks a malloc() block as also a custom block with
    129    MALLOCLIKE_BLOCK. */
    130 extern VgHashTable MC_(malloc_list);
    131 
    132 /* For tracking memory pools. */
    133 extern VgHashTable MC_(mempool_list);
    134 
    135 /* Shadow memory functions */
    136 Bool MC_(check_mem_is_noaccess)( Addr a, SizeT len, Addr* bad_addr );
    137 void MC_(make_mem_noaccess)        ( Addr a, SizeT len );
    138 void MC_(make_mem_undefined_w_otag)( Addr a, SizeT len, UInt otag );
    139 void MC_(make_mem_defined)         ( Addr a, SizeT len );
    140 void MC_(copy_address_range_state) ( Addr src, Addr dst, SizeT len );
    141 
    142 void MC_(print_malloc_stats) ( void );
    143 /* nr of free operations done */
    144 SizeT MC_(get_cmalloc_n_frees) ( void );
    145 
    146 void* MC_(malloc)               ( ThreadId tid, SizeT n );
    147 void* MC_(__builtin_new)        ( ThreadId tid, SizeT n );
    148 void* MC_(__builtin_vec_new)    ( ThreadId tid, SizeT n );
    149 void* MC_(memalign)             ( ThreadId tid, SizeT align, SizeT n );
    150 void* MC_(calloc)               ( ThreadId tid, SizeT nmemb, SizeT size1 );
    151 void  MC_(free)                 ( ThreadId tid, void* p );
    152 void  MC_(__builtin_delete)     ( ThreadId tid, void* p );
    153 void  MC_(__builtin_vec_delete) ( ThreadId tid, void* p );
    154 void* MC_(realloc)              ( ThreadId tid, void* p, SizeT new_size );
    155 SizeT MC_(malloc_usable_size)   ( ThreadId tid, void* p );
    156 
    157 void MC_(handle_resizeInPlace)(ThreadId tid, Addr p,
    158                                SizeT oldSizeB, SizeT newSizeB, SizeT rzB);
    159 
    160 
    161 /*------------------------------------------------------------*/
    162 /*--- Origin tracking translate-time support               ---*/
    163 /*------------------------------------------------------------*/
    164 
    165 /* See detailed comments in mc_machine.c. */
    166 Int MC_(get_otrack_shadow_offset) ( Int offset, Int szB );
    167 IRType MC_(get_otrack_reg_array_equiv_int_type) ( IRRegArray* arr );
    168 
    169 /* Constants which are used as the lowest 2 bits in origin tags.
    170 
    171    An origin tag comprises an upper 30-bit ECU field and a lower 2-bit
    172    'kind' field.  The ECU field is a number given out by m_execontext
    173    and has a 1-1 mapping with ExeContext*s.  An ECU can be used
    174    directly as an origin tag (otag), but in fact we want to put
    175    additional information 'kind' field to indicate roughly where the
    176    tag came from.  This helps print more understandable error messages
    177    for the user -- it has no other purpose.
    178 
    179    Hence the following 2-bit constants are needed for 'kind' field.
    180 
    181    To summarise:
    182 
    183    * Both ECUs and origin tags are represented as 32-bit words
    184 
    185    * m_execontext and the core-tool interface deal purely in ECUs.
    186      They have no knowledge of origin tags - that is a purely
    187      Memcheck-internal matter.
    188 
    189    * all valid ECUs have the lowest 2 bits zero and at least
    190      one of the upper 30 bits nonzero (see VG_(is_plausible_ECU))
    191 
    192    * to convert from an ECU to an otag, OR in one of the MC_OKIND_
    193      constants below
    194 
    195    * to convert an otag back to an ECU, AND it with ~3
    196 */
    197 
    198 #define MC_OKIND_UNKNOWN  0  /* unknown origin */
    199 #define MC_OKIND_HEAP     1  /* this is a heap origin */
    200 #define MC_OKIND_STACK    2  /* this is a stack origin */
    201 #define MC_OKIND_USER     3  /* arises from user-supplied client req */
    202 
    203 
    204 /*------------------------------------------------------------*/
    205 /*--- Profiling of memory events                           ---*/
    206 /*------------------------------------------------------------*/
    207 
    208 /* Define to collect detailed performance info. */
    209 /* #define MC_PROFILE_MEMORY */
    210 
    211 #ifdef MC_PROFILE_MEMORY
    212 #  define N_PROF_EVENTS 500
    213 
    214 UInt   MC_(event_ctr)[N_PROF_EVENTS];
    215 HChar* MC_(event_ctr_name)[N_PROF_EVENTS];
    216 
    217 #  define PROF_EVENT(ev, name)                                \
    218    do { tl_assert((ev) >= 0 && (ev) < N_PROF_EVENTS);         \
    219         /* crude and inaccurate check to ensure the same */   \
    220         /* event isn't being used with > 1 name */            \
    221         if (MC_(event_ctr_name)[ev])                         \
    222            tl_assert(name == MC_(event_ctr_name)[ev]);       \
    223         MC_(event_ctr)[ev]++;                                \
    224         MC_(event_ctr_name)[ev] = (name);                    \
    225    } while (False);
    226 
    227 #else
    228 
    229 #  define PROF_EVENT(ev, name) /* */
    230 
    231 #endif   /* MC_PROFILE_MEMORY */
    232 
    233 
    234 /*------------------------------------------------------------*/
    235 /*--- V and A bits (Victoria & Albert ?)                   ---*/
    236 /*------------------------------------------------------------*/
    237 
    238 /* The number of entries in the primary map can be altered.  However
    239    we hardwire the assumption that each secondary map covers precisely
    240    64k of address space. */
    241 #define SM_SIZE 65536            /* DO NOT CHANGE */
    242 #define SM_MASK (SM_SIZE-1)      /* DO NOT CHANGE */
    243 
    244 #define V_BIT_DEFINED         0
    245 #define V_BIT_UNDEFINED       1
    246 
    247 #define V_BITS8_DEFINED       0
    248 #define V_BITS8_UNDEFINED     0xFF
    249 
    250 #define V_BITS16_DEFINED      0
    251 #define V_BITS16_UNDEFINED    0xFFFF
    252 
    253 #define V_BITS32_DEFINED      0
    254 #define V_BITS32_UNDEFINED    0xFFFFFFFF
    255 
    256 #define V_BITS64_DEFINED      0ULL
    257 #define V_BITS64_UNDEFINED    0xFFFFFFFFFFFFFFFFULL
    258 
    259 
    260 /*------------------------------------------------------------*/
    261 /*--- Leak checking                                        ---*/
    262 /*------------------------------------------------------------*/
    263 
    264 typedef
    265    enum {
    266       // Nb: the order is important -- it dictates the order of loss records
    267       // of equal sizes.
    268       Reachable    =0,  // Definitely reachable from root-set.
    269       Possible     =1,  // Possibly reachable from root-set;  involves at
    270                         //   least one interior-pointer along the way.
    271       IndirectLeak =2,  // Leaked, but reachable from another leaked block
    272                         //   (be it Unreached or IndirectLeak).
    273       Unreached    =3,  // Not reached, ie. leaked.
    274                         //   (At best, only reachable from itself via a cycle.)
    275   }
    276   Reachedness;
    277 
    278 // Build mask to check or set Reachedness r membership
    279 #define R2S(r) (1 << (r))
    280 // Reachedness r is member of the Set s ?
    281 #define RiS(r,s) ((s) & R2S(r))
    282 // A set with all Reachedness:
    283 #define RallS \
    284    (R2S(Reachable) | R2S(Possible) | R2S(IndirectLeak) | R2S(Unreached))
    285 
    286 /* For VALGRIND_COUNT_LEAKS client request */
    287 extern SizeT MC_(bytes_leaked);
    288 extern SizeT MC_(bytes_indirect);
    289 extern SizeT MC_(bytes_dubious);
    290 extern SizeT MC_(bytes_reachable);
    291 extern SizeT MC_(bytes_suppressed);
    292 
    293 /* For VALGRIND_COUNT_LEAK_BLOCKS client request */
    294 extern SizeT MC_(blocks_leaked);
    295 extern SizeT MC_(blocks_indirect);
    296 extern SizeT MC_(blocks_dubious);
    297 extern SizeT MC_(blocks_reachable);
    298 extern SizeT MC_(blocks_suppressed);
    299 
    300 typedef
    301    enum {
    302       LC_Off,
    303       LC_Summary,
    304       LC_Full,
    305    }
    306    LeakCheckMode;
    307 
    308 typedef
    309    enum {
    310       LCD_Any,       // output all loss records, whatever the delta
    311       LCD_Increased, // output loss records with an increase in size or blocks
    312       LCD_Changed,   // output loss records with an increase or
    313                      //decrease in size or blocks
    314    }
    315    LeakCheckDeltaMode;
    316 
    317 /* When a LossRecord is put into an OSet, these elements represent the key. */
    318 typedef
    319    struct _LossRecordKey {
    320       Reachedness  state;        // LC_Extra.state value shared by all blocks.
    321       ExeContext*  allocated_at; // Where they were allocated.
    322    }
    323    LossRecordKey;
    324 
    325 /* A loss record, used for generating err msgs.  Multiple leaked blocks can be
    326  * merged into a single loss record if they have the same state and similar
    327  * enough allocation points (controlled by --leak-resolution). */
    328 typedef
    329    struct _LossRecord {
    330       LossRecordKey key;  // Key, when used in an OSet.
    331       SizeT szB;          // Sum of all MC_Chunk.szB values.
    332       SizeT indirect_szB; // Sum of all LC_Extra.indirect_szB values.
    333       UInt  num_blocks;   // Number of blocks represented by the record.
    334       SizeT old_szB;          // old_* values are the values found during the
    335       SizeT old_indirect_szB; // previous leak search. old_* values are used to
    336       UInt  old_num_blocks;   // output only the changed/new loss records
    337    }
    338    LossRecord;
    339 
    340 typedef
    341    struct _LeakCheckParams {
    342       LeakCheckMode mode;
    343       UInt show_leak_kinds;
    344       UInt errors_for_leak_kinds;
    345       UInt heuristics;
    346       LeakCheckDeltaMode deltamode;
    347       UInt max_loss_records_output; // limit on the nr of loss records output.
    348       Bool requested_by_monitor_command; // True when requested by gdb/vgdb.
    349    }
    350    LeakCheckParams;
    351 
    352 void MC_(detect_memory_leaks) ( ThreadId tid, LeakCheckParams * lcp);
    353 
    354 // Each time a leak search is done, the leak search generation
    355 // MC_(leak_search_gen) is incremented.
    356 extern UInt MC_(leak_search_gen);
    357 
    358 // maintains the lcp.deltamode given in the last call to detect_memory_leaks
    359 extern LeakCheckDeltaMode MC_(detect_memory_leaks_last_delta_mode);
    360 
    361 // prints the list of blocks corresponding to the given loss_record_nr.
    362 // Returns True if loss_record_nr identifies a correct loss record from last
    363 // leak search, returns False otherwise.
    364 Bool MC_(print_block_list) ( UInt loss_record_nr);
    365 
    366 // Prints the addresses/registers/... at which a pointer to
    367 // the given range [address, address+szB[ is found.
    368 void MC_(who_points_at) ( Addr address, SizeT szB);
    369 
    370 // if delta_mode == LCD_Any, prints in buf an empty string
    371 // otherwise prints a delta in the layout  " (+%'lu)" or " (-%'lu)"
    372 extern HChar * MC_(snprintf_delta) (HChar * buf, Int size,
    373                                     SizeT current_val, SizeT old_val,
    374                                     LeakCheckDeltaMode delta_mode);
    375 
    376 
    377 Bool MC_(is_valid_aligned_word)     ( Addr a );
    378 Bool MC_(is_within_valid_secondary) ( Addr a );
    379 
    380 // Prints as user msg a description of the given loss record.
    381 void MC_(pp_LossRecord)(UInt n_this_record, UInt n_total_records,
    382                         LossRecord* l);
    383 
    384 
    385 /*------------------------------------------------------------*/
    386 /*--- Errors and suppressions                              ---*/
    387 /*------------------------------------------------------------*/
    388 
    389 /* Did we show to the user, any errors for which an uninitialised
    390    value origin could have been collected (but wasn't) ?  If yes,
    391    then, at the end of the run, print a 1 line message advising that a
    392    rerun with --track-origins=yes might help. */
    393 extern Bool MC_(any_value_errors);
    394 
    395 /* Standard functions for error and suppressions as required by the
    396    core/tool iface */
    397 Bool MC_(eq_Error)           ( VgRes res, Error* e1, Error* e2 );
    398 void MC_(before_pp_Error)    ( Error* err );
    399 void MC_(pp_Error)           ( Error* err );
    400 UInt MC_(update_Error_extra) ( Error* err );
    401 
    402 Bool MC_(is_recognised_suppression) ( const HChar* name, Supp* su );
    403 
    404 Bool MC_(read_extra_suppression_info) ( Int fd, HChar** buf,
    405                                         SizeT* nBuf, Int* lineno, Supp *su );
    406 
    407 Bool MC_(error_matches_suppression) ( Error* err, Supp* su );
    408 
    409 Bool MC_(get_extra_suppression_info) ( Error* err,
    410                                        /*OUT*/HChar* buf, Int nBuf );
    411 Bool MC_(print_extra_suppression_use) ( Supp* su,
    412                                         /*OUT*/HChar* buf, Int nBuf );
    413 void MC_(update_extra_suppression_use) ( Error* err, Supp* su );
    414 
    415 const HChar* MC_(get_error_name) ( Error* err );
    416 
    417 /* Recording of errors */
    418 void MC_(record_address_error) ( ThreadId tid, Addr a, Int szB,
    419                                  Bool isWrite );
    420 void MC_(record_cond_error)    ( ThreadId tid, UInt otag );
    421 void MC_(record_value_error)   ( ThreadId tid, Int szB, UInt otag );
    422 void MC_(record_jump_error)    ( ThreadId tid, Addr a );
    423 
    424 void MC_(record_free_error)            ( ThreadId tid, Addr a );
    425 void MC_(record_illegal_mempool_error) ( ThreadId tid, Addr a );
    426 void MC_(record_freemismatch_error)    ( ThreadId tid, MC_Chunk* mc );
    427 
    428 void MC_(record_overlap_error)  ( ThreadId tid, const HChar* function,
    429                                   Addr src, Addr dst, SizeT szB );
    430 void MC_(record_core_mem_error) ( ThreadId tid, const HChar* msg );
    431 void MC_(record_regparam_error) ( ThreadId tid, const HChar* msg, UInt otag );
    432 void MC_(record_memparam_error) ( ThreadId tid, Addr a,
    433                                   Bool isAddrErr, const HChar* msg, UInt otag );
    434 void MC_(record_user_error)     ( ThreadId tid, Addr a,
    435                                   Bool isAddrErr, UInt otag );
    436 
    437 Bool MC_(record_leak_error)     ( ThreadId tid,
    438                                   UInt n_this_record,
    439                                   UInt n_total_records,
    440                                   LossRecord* lossRecord,
    441                                   Bool print_record,
    442                                   Bool count_error );
    443 
    444 /* Parses a set of leak kinds (separated by ,).
    445    and give the resulting set in *lks.
    446    If parsing is succesful, returns True and *lks contains the resulting set.
    447    else return False. */
    448 extern Bool MC_(parse_leak_kinds) ( const HChar* str0, UInt* lks );
    449 
    450 /* prints a description of address a */
    451 void MC_(pp_describe_addr) (Addr a);
    452 
    453 /* Is this address in a user-specified "ignored range" ? */
    454 Bool MC_(in_ignored_range) ( Addr a );
    455 
    456 
    457 /*------------------------------------------------------------*/
    458 /*--- Client blocks                                        ---*/
    459 /*------------------------------------------------------------*/
    460 
    461 /* Describes a client block.  See mc_main.c.  An unused block has
    462    start == size == 0.  */
    463 typedef
    464    struct {
    465       Addr        start;
    466       SizeT       size;
    467       ExeContext* where;
    468       HChar*      desc;
    469    }
    470    CGenBlock;
    471 
    472 /* Get access to the client block array. */
    473 void MC_(get_ClientBlock_array)( /*OUT*/CGenBlock** blocks,
    474                                  /*OUT*/UWord* nBlocks );
    475 
    476 
    477 /*------------------------------------------------------------*/
    478 /*--- Command line options + defaults                      ---*/
    479 /*------------------------------------------------------------*/
    480 
    481 /* Allow loads from partially-valid addresses?  default: YES */
    482 extern Bool MC_(clo_partial_loads_ok);
    483 
    484 /* Max volume of the freed blocks queue. */
    485 extern Long MC_(clo_freelist_vol);
    486 
    487 /* Blocks with a size >= MC_(clo_freelist_big_blocks) will be put
    488    in the "big block" freed blocks queue. */
    489 extern Long MC_(clo_freelist_big_blocks);
    490 
    491 /* Do leak check at exit?  default: NO */
    492 extern LeakCheckMode MC_(clo_leak_check);
    493 
    494 /* How closely should we compare ExeContexts in leak records? default: 2 */
    495 extern VgRes MC_(clo_leak_resolution);
    496 
    497 /* In leak check, show loss records if their R2S(reachedness) is set.
    498    Default : R2S(Possible) | R2S(Unreached). */
    499 extern UInt MC_(clo_show_leak_kinds);
    500 
    501 /* In leak check, a loss record is an error if its R2S(reachedness) is set.
    502    Default : R2S(Possible) | R2S(Unreached). */
    503 extern UInt MC_(clo_errors_for_leak_kinds);
    504 
    505 /* Various leak check heuristics which can be activated/deactivated. */
    506 typedef
    507    enum {
    508       LchNone                =0,
    509       // no heuristic.
    510       LchStdString           =1,
    511       // Consider interior pointer pointing at the array of char in a
    512       // std::string as reachable.
    513       LchNewArray            =2,
    514       // Consider interior pointer pointing at second word of a new[] array as
    515       // reachable. Such interior pointers are used for arrays whose elements
    516       // have a destructor.
    517       LchMultipleInheritance =3,
    518       // Conside interior pointer pointing just after what looks a vtable
    519       // as reachable.
    520   }
    521   LeakCheckHeuristic;
    522 
    523 // Nr of heuristics, including the LchNone heuristic.
    524 #define N_LEAK_CHECK_HEURISTICS 4
    525 
    526 // Build mask to check or set Heuristic h membership
    527 #define H2S(h) (1 << (h))
    528 // CppHeuristic h is member of the Set s ?
    529 #define HiS(h,s) ((s) & R2S(h))
    530 // A set with all Heuristics:
    531 #define HallS \
    532    (H2S(LchStdString) | H2S(LchNewArray) | H2S(LchMultipleInheritance))
    533 
    534 /* Heuristics set to use for the leak search.
    535    Default : no heuristic. */
    536 extern UInt MC_(clo_leak_check_heuristics);
    537 
    538 /* Assume accesses immediately below %esp are due to gcc-2.96 bugs.
    539  * default: NO */
    540 extern Bool MC_(clo_workaround_gcc296_bugs);
    541 
    542 /* Fill malloc-d/free-d client blocks with a specific value?  -1 if
    543    not, else 0x00 .. 0xFF indicating the fill value to use.  Can be
    544    useful for causing programs with bad heap corruption to fail in
    545    more repeatable ways.  Note that malloc-filled and free-filled
    546    areas are still undefined and noaccess respectively.  This merely
    547    causes them to contain the specified values. */
    548 extern Int MC_(clo_malloc_fill);
    549 extern Int MC_(clo_free_fill);
    550 
    551 /* Which stack trace(s) to keep for malloc'd/free'd client blocks?
    552    For each client block, the stack traces where it was allocated
    553    and/or freed are optionally kept depending on MC_(clo_keep_stacktraces). */
    554 typedef
    555    enum {                 // keep alloc stack trace ?  keep free stack trace ?
    556       KS_none,            // never                     never
    557       KS_alloc,           // always                    never
    558       KS_free,            // never                     always
    559       KS_alloc_then_free, // when still malloc'd       when free'd
    560       KS_alloc_and_free,  // always                    always
    561    }
    562    KeepStacktraces;
    563 extern KeepStacktraces MC_(clo_keep_stacktraces);
    564 
    565 /* Indicates the level of instrumentation/checking done by Memcheck.
    566 
    567    1 = No undefined value checking, Addrcheck-style behaviour only:
    568        only address checking is done.  This is faster but finds fewer
    569        errors.  Note that although Addrcheck had 1 bit per byte
    570        overhead vs the old Memcheck's 9 bits per byte, with this mode
    571        and compressed V bits, no memory is saved with this mode --
    572        it's still 2 bits per byte overhead.  This is a little wasteful
    573        -- it could be done with 1 bit per byte -- but lets us reuse
    574        the many shadow memory access functions.  Note that in this
    575        mode neither the secondary V bit table nor the origin-tag cache
    576        are used.
    577 
    578    2 = Address checking and Undefined value checking are performed,
    579        but origins are not tracked.  So the origin-tag cache is not
    580        used in this mode.  This setting is the default and corresponds
    581        to the "normal" Memcheck behaviour that has shipped for years.
    582 
    583    3 = Address checking, undefined value checking, and origins for
    584        undefined values are tracked.
    585 
    586    The default is 2.
    587 */
    588 extern Int MC_(clo_mc_level);
    589 
    590 
    591 /*------------------------------------------------------------*/
    592 /*--- Instrumentation                                      ---*/
    593 /*------------------------------------------------------------*/
    594 
    595 /* Functions defined in mc_main.c */
    596 
    597 /* For the fail_w_o functions, the UWord arg is actually the 32-bit
    598    origin tag and should really be UInt, but to be simple and safe
    599    considering it's called from generated code, just claim it to be a
    600    UWord. */
    601 VG_REGPARM(2) void MC_(helperc_value_checkN_fail_w_o) ( HWord, UWord );
    602 VG_REGPARM(1) void MC_(helperc_value_check8_fail_w_o) ( UWord );
    603 VG_REGPARM(1) void MC_(helperc_value_check4_fail_w_o) ( UWord );
    604 VG_REGPARM(1) void MC_(helperc_value_check1_fail_w_o) ( UWord );
    605 VG_REGPARM(1) void MC_(helperc_value_check0_fail_w_o) ( UWord );
    606 
    607 /* And call these ones instead to report an uninitialised value error
    608    but with no origin available. */
    609 VG_REGPARM(1) void MC_(helperc_value_checkN_fail_no_o) ( HWord );
    610 VG_REGPARM(0) void MC_(helperc_value_check8_fail_no_o) ( void );
    611 VG_REGPARM(0) void MC_(helperc_value_check4_fail_no_o) ( void );
    612 VG_REGPARM(0) void MC_(helperc_value_check1_fail_no_o) ( void );
    613 VG_REGPARM(0) void MC_(helperc_value_check0_fail_no_o) ( void );
    614 
    615 /* V-bits load/store helpers */
    616 VG_REGPARM(1) void MC_(helperc_STOREV64be) ( Addr, ULong );
    617 VG_REGPARM(1) void MC_(helperc_STOREV64le) ( Addr, ULong );
    618 VG_REGPARM(2) void MC_(helperc_STOREV32be) ( Addr, UWord );
    619 VG_REGPARM(2) void MC_(helperc_STOREV32le) ( Addr, UWord );
    620 VG_REGPARM(2) void MC_(helperc_STOREV16be) ( Addr, UWord );
    621 VG_REGPARM(2) void MC_(helperc_STOREV16le) ( Addr, UWord );
    622 VG_REGPARM(2) void MC_(helperc_STOREV8)    ( Addr, UWord );
    623 
    624 VG_REGPARM(2) void  MC_(helperc_LOADV256be) ( /*OUT*/V256*, Addr );
    625 VG_REGPARM(2) void  MC_(helperc_LOADV256le) ( /*OUT*/V256*, Addr );
    626 VG_REGPARM(2) void  MC_(helperc_LOADV128be) ( /*OUT*/V128*, Addr );
    627 VG_REGPARM(2) void  MC_(helperc_LOADV128le) ( /*OUT*/V128*, Addr );
    628 VG_REGPARM(1) ULong MC_(helperc_LOADV64be)  ( Addr );
    629 VG_REGPARM(1) ULong MC_(helperc_LOADV64le)  ( Addr );
    630 VG_REGPARM(1) UWord MC_(helperc_LOADV32be)  ( Addr );
    631 VG_REGPARM(1) UWord MC_(helperc_LOADV32le)  ( Addr );
    632 VG_REGPARM(1) UWord MC_(helperc_LOADV16be)  ( Addr );
    633 VG_REGPARM(1) UWord MC_(helperc_LOADV16le)  ( Addr );
    634 VG_REGPARM(1) UWord MC_(helperc_LOADV8)     ( Addr );
    635 
    636 void MC_(helperc_MAKE_STACK_UNINIT) ( Addr base, UWord len,
    637                                                  Addr nia );
    638 
    639 /* Origin tag load/store helpers */
    640 VG_REGPARM(2) void  MC_(helperc_b_store1) ( Addr a, UWord d32 );
    641 VG_REGPARM(2) void  MC_(helperc_b_store2) ( Addr a, UWord d32 );
    642 VG_REGPARM(2) void  MC_(helperc_b_store4) ( Addr a, UWord d32 );
    643 VG_REGPARM(2) void  MC_(helperc_b_store8) ( Addr a, UWord d32 );
    644 VG_REGPARM(2) void  MC_(helperc_b_store16)( Addr a, UWord d32 );
    645 VG_REGPARM(2) void  MC_(helperc_b_store32)( Addr a, UWord d32 );
    646 VG_REGPARM(1) UWord MC_(helperc_b_load1) ( Addr a );
    647 VG_REGPARM(1) UWord MC_(helperc_b_load2) ( Addr a );
    648 VG_REGPARM(1) UWord MC_(helperc_b_load4) ( Addr a );
    649 VG_REGPARM(1) UWord MC_(helperc_b_load8) ( Addr a );
    650 VG_REGPARM(1) UWord MC_(helperc_b_load16)( Addr a );
    651 VG_REGPARM(1) UWord MC_(helperc_b_load32)( Addr a );
    652 
    653 /* Functions defined in mc_translate.c */
    654 IRSB* MC_(instrument) ( VgCallbackClosure* closure,
    655                         IRSB* bb_in,
    656                         VexGuestLayout* layout,
    657                         VexGuestExtents* vge,
    658                         VexArchInfo* archinfo_host,
    659                         IRType gWordTy, IRType hWordTy );
    660 
    661 IRSB* MC_(final_tidy) ( IRSB* );
    662 
    663 #endif /* ndef __MC_INCLUDE_H */
    664 
    665 /*--------------------------------------------------------------------*/
    666 /*--- end                                                          ---*/
    667 /*--------------------------------------------------------------------*/
    668