njn | c953984 | 2002-10-02 13:26:35 +0000 | [diff] [blame^] | 1 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 2 | /*--------------------------------------------------------------------*/ |
| 3 | /*--- A header file for all parts of the MemCheck skin. ---*/ |
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 | /* |
njn | c953984 | 2002-10-02 13:26:35 +0000 | [diff] [blame^] | 8 | This file is part of MemCheck, a heavyweight Valgrind skin for |
| 9 | detecting memory errors. |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 10 | |
| 11 | Copyright (C) 2000-2002 Julian Seward |
| 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 | |
| 35 | #include "vg_skin.h" |
| 36 | |
| 37 | /* UCode extension for efficient memory checking operations */ |
| 38 | typedef |
| 39 | enum { |
| 40 | /* uinstrs which are not needed for mere translation of x86 code, |
| 41 | only for instrumentation of it. */ |
| 42 | LOADV = DUMMY_FINAL_UOPCODE + 1, |
| 43 | STOREV, |
| 44 | GETV, |
| 45 | PUTV, |
| 46 | TESTV, |
| 47 | SETV, |
| 48 | /* Get/set the v-bit (and it is only one bit) for the simulated |
| 49 | %eflags register. */ |
| 50 | GETVF, |
| 51 | PUTVF, |
| 52 | |
| 53 | /* Do a unary or binary tag op. Only for post-instrumented |
| 54 | code. For TAG1, first and only arg is a TempReg, and is both |
| 55 | arg and result reg. For TAG2, first arg is src, second is |
| 56 | dst, in the normal way; both are TempRegs. In both cases, |
| 57 | 3rd arg is a RiCHelper with a Lit16 tag. This indicates |
| 58 | which tag op to do. */ |
| 59 | TAG1, |
| 60 | TAG2 |
| 61 | } |
| 62 | MemCheckOpcode; |
| 63 | |
| 64 | |
| 65 | /* Lists the names of value-tag operations used in instrumented |
| 66 | code. These are the third argument to TAG1 and TAG2 uinsns. */ |
| 67 | typedef |
| 68 | enum { |
| 69 | /* Unary. */ |
| 70 | Tag_PCast40, Tag_PCast20, Tag_PCast10, |
| 71 | Tag_PCast01, Tag_PCast02, Tag_PCast04, |
| 72 | |
| 73 | Tag_PCast14, Tag_PCast12, Tag_PCast11, |
| 74 | |
| 75 | Tag_Left4, Tag_Left2, Tag_Left1, |
| 76 | |
| 77 | Tag_SWiden14, Tag_SWiden24, Tag_SWiden12, |
| 78 | Tag_ZWiden14, Tag_ZWiden24, Tag_ZWiden12, |
| 79 | |
| 80 | /* Binary; 1st is rd; 2nd is rd+wr */ |
| 81 | Tag_UifU4, Tag_UifU2, Tag_UifU1, Tag_UifU0, |
| 82 | Tag_DifD4, Tag_DifD2, Tag_DifD1, |
| 83 | |
| 84 | Tag_ImproveAND4_TQ, Tag_ImproveAND2_TQ, Tag_ImproveAND1_TQ, |
| 85 | Tag_ImproveOR4_TQ, Tag_ImproveOR2_TQ, Tag_ImproveOR1_TQ, |
| 86 | Tag_DebugFn |
| 87 | } |
| 88 | TagOp; |
| 89 | |
| 90 | /* The classification of a faulting address. */ |
| 91 | typedef |
| 92 | enum { Undescribed, /* as-yet unclassified */ |
| 93 | Stack, |
| 94 | Unknown, /* classification yielded nothing useful */ |
| 95 | Freed, Mallocd, |
| 96 | UserG, UserS |
| 97 | } |
| 98 | AddrKind; |
| 99 | |
| 100 | /* Records info about a faulting address. */ |
| 101 | typedef |
| 102 | struct { |
| 103 | /* ALL */ |
| 104 | AddrKind akind; |
| 105 | /* Freed, Mallocd */ |
| 106 | Int blksize; |
| 107 | /* Freed, Mallocd */ |
| 108 | Int rwoffset; |
| 109 | /* Freed, Mallocd */ |
| 110 | ExeContext* lastchange; |
| 111 | /* Stack */ |
| 112 | ThreadId stack_tid; |
| 113 | /* True if is just-below %esp -- could be a gcc bug. */ |
| 114 | Bool maybe_gcc; |
| 115 | } |
| 116 | AddrInfo; |
| 117 | |
| 118 | |
| 119 | /*------------------------------------------------------------*/ |
| 120 | /*--- Skin-specific command line options + defaults ---*/ |
| 121 | /*------------------------------------------------------------*/ |
| 122 | |
| 123 | /* Allow loads from partially-valid addresses? default: YES */ |
| 124 | extern Bool SK_(clo_partial_loads_ok); |
| 125 | |
| 126 | /* Max volume of the freed blocks queue. */ |
| 127 | extern Int SK_(clo_freelist_vol); |
| 128 | |
| 129 | /* Do leak check at exit? default: NO */ |
| 130 | extern Bool SK_(clo_leak_check); |
| 131 | |
| 132 | /* How closely should we compare ExeContexts in leak records? default: 2 */ |
| 133 | extern VgRes SK_(clo_leak_resolution); |
| 134 | |
| 135 | /* In leak check, show reachable-but-not-freed blocks? default: NO */ |
| 136 | extern Bool SK_(clo_show_reachable); |
| 137 | |
| 138 | /* Assume accesses immediately below %esp are due to gcc-2.96 bugs. |
| 139 | * default: NO*/ |
| 140 | extern Bool SK_(clo_workaround_gcc296_bugs); |
| 141 | |
| 142 | /* Shall we V-check addrs? (they are always A checked too) default: YES */ |
| 143 | extern Bool SK_(clo_check_addrVs); |
| 144 | |
| 145 | /* DEBUG: clean up instrumented code? default: YES */ |
| 146 | extern Bool SK_(clo_cleanup); |
| 147 | |
| 148 | |
| 149 | /*------------------------------------------------------------*/ |
| 150 | /*--- Functions ---*/ |
| 151 | /*------------------------------------------------------------*/ |
| 152 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 153 | /* Functions defined in vg_memcheck_helpers.S */ |
| 154 | extern void SK_(helper_value_check4_fail) ( void ); |
| 155 | extern void SK_(helper_value_check2_fail) ( void ); |
| 156 | extern void SK_(helper_value_check1_fail) ( void ); |
| 157 | extern void SK_(helper_value_check0_fail) ( void ); |
| 158 | |
| 159 | /* Functions defined in vg_memcheck.c */ |
| 160 | extern void SK_(helperc_STOREV4) ( UInt, Addr ); |
| 161 | extern void SK_(helperc_STOREV2) ( UInt, Addr ); |
| 162 | extern void SK_(helperc_STOREV1) ( UInt, Addr ); |
| 163 | |
| 164 | extern UInt SK_(helperc_LOADV1) ( Addr ); |
| 165 | extern UInt SK_(helperc_LOADV2) ( Addr ); |
| 166 | extern UInt SK_(helperc_LOADV4) ( Addr ); |
| 167 | |
| 168 | extern void SK_(fpu_write_check) ( Addr addr, Int size ); |
| 169 | extern void SK_(fpu_read_check) ( Addr addr, Int size ); |
| 170 | |
| 171 | extern ShadowChunk* SK_(any_matching_freed_ShadowChunks) |
| 172 | ( Bool (*p) ( ShadowChunk* ) ); |
| 173 | |
| 174 | /* For client requests */ |
| 175 | extern void SK_(make_noaccess) ( Addr a, UInt len ); |
| 176 | extern void SK_(make_readable) ( Addr a, UInt len ); |
| 177 | extern void SK_(make_writable) ( Addr a, UInt len ); |
| 178 | |
| 179 | extern Bool SK_(check_writable) ( Addr a, UInt len, Addr* bad_addr ); |
| 180 | extern Bool SK_(check_readable) ( Addr a, UInt len, Addr* bad_addr ); |
| 181 | |
| 182 | extern void SK_(detect_memory_leaks) ( void ); |
| 183 | |
| 184 | |
| 185 | /* Functions defined in vg_memcheck_clientreqs.c */ |
| 186 | extern Bool SK_(client_perm_maybe_describe)( Addr a, AddrInfo* ai ); |
| 187 | extern void SK_(delete_client_stack_blocks_following_ESP_change) ( void ); |
| 188 | extern void SK_(show_client_block_stats) ( void ); |
| 189 | |
| 190 | /* Functions defined in vg_memcheck_errcontext.c */ |
| 191 | extern void SK_(record_value_error) ( Int size ); |
| 192 | extern void SK_(record_address_error) ( Addr a, Int size, Bool isWrite ); |
| 193 | extern void SK_(record_core_mem_error) ( ThreadState* tst, Bool isWrite, |
| 194 | Char* s ); |
| 195 | extern void SK_(record_param_error) ( ThreadState* tst, Addr a, |
| 196 | Bool isWriteLack, Char* msg ); |
| 197 | extern void SK_(record_jump_error) ( ThreadState* tst, Addr a ); |
| 198 | extern void SK_(record_free_error) ( ThreadState* tst, Addr a ); |
| 199 | extern void SK_(record_freemismatch_error)( ThreadState* tst, Addr a ); |
| 200 | extern void SK_(record_user_error) ( ThreadState* tst, Addr a, |
| 201 | Bool isWrite ); |
| 202 | |
| 203 | #endif |
| 204 | |
| 205 | /*--------------------------------------------------------------------*/ |
njn25 | cac76cb | 2002-09-23 11:21:57 +0000 | [diff] [blame] | 206 | /*--- end mc_include.h ---*/ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 207 | /*--------------------------------------------------------------------*/ |
| 208 | |