njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 1 | |
| 2 | /*--------------------------------------------------------------------*/ |
| 3 | /*--- Code that is shared between MemCheck and AddrCheck. ---*/ |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 4 | /*--- mac_needs.c ---*/ |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 5 | /*--------------------------------------------------------------------*/ |
| 6 | |
| 7 | /* |
| 8 | This file is part of MemCheck, a heavyweight Valgrind skin for |
| 9 | detecting memory errors, and AddrCheck, a lightweight Valgrind skin |
| 10 | for detecting memory errors. |
| 11 | |
njn | 0e1b514 | 2003-04-15 14:58:06 +0000 | [diff] [blame] | 12 | Copyright (C) 2000-2003 Julian Seward |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 13 | jseward@acm.org |
| 14 | |
| 15 | This program is free software; you can redistribute it and/or |
| 16 | modify it under the terms of the GNU General Public License as |
| 17 | published by the Free Software Foundation; either version 2 of the |
| 18 | License, or (at your option) any later version. |
| 19 | |
| 20 | This program is distributed in the hope that it will be useful, but |
| 21 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 23 | General Public License for more details. |
| 24 | |
| 25 | You should have received a copy of the GNU General Public License |
| 26 | along with this program; if not, write to the Free Software |
| 27 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 28 | 02111-1307, USA. |
| 29 | |
| 30 | The GNU General Public License is contained in the file COPYING. |
| 31 | */ |
| 32 | |
| 33 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 34 | #include "mac_shared.h" |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 35 | |
njn | 47363ab | 2003-04-21 13:24:40 +0000 | [diff] [blame] | 36 | #include "memcheck.h" /* for VG_USERREQ__* */ |
| 37 | |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 38 | /*------------------------------------------------------------*/ |
| 39 | /*--- Defns ---*/ |
| 40 | /*------------------------------------------------------------*/ |
| 41 | |
| 42 | /* These many bytes below %ESP are considered addressible if we're |
| 43 | doing the --workaround-gcc296-bugs hack. */ |
| 44 | #define VG_GCC296_BUG_STACK_SLOP 1024 |
| 45 | |
| 46 | /*------------------------------------------------------------*/ |
| 47 | /*--- Command line options ---*/ |
| 48 | /*------------------------------------------------------------*/ |
| 49 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 50 | Bool MAC_(clo_partial_loads_ok) = True; |
| 51 | Int MAC_(clo_freelist_vol) = 1000000; |
| 52 | Bool MAC_(clo_leak_check) = False; |
| 53 | VgRes MAC_(clo_leak_resolution) = Vg_LowRes; |
| 54 | Bool MAC_(clo_show_reachable) = False; |
| 55 | Bool MAC_(clo_workaround_gcc296_bugs) = False; |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 56 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 57 | Bool MAC_(process_common_cmd_line_option)(Char* arg) |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 58 | { |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 59 | if (VG_CLO_STREQ(arg, "--partial-loads-ok=yes")) |
| 60 | MAC_(clo_partial_loads_ok) = True; |
| 61 | else if (VG_CLO_STREQ(arg, "--partial-loads-ok=no")) |
| 62 | MAC_(clo_partial_loads_ok) = False; |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 63 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 64 | else if (VG_CLO_STREQN(15, arg, "--freelist-vol=")) { |
| 65 | MAC_(clo_freelist_vol) = (Int)VG_(atoll)(&arg[15]); |
| 66 | if (MAC_(clo_freelist_vol) < 0) MAC_(clo_freelist_vol) = 0; |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 67 | } |
| 68 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 69 | else if (VG_CLO_STREQ(arg, "--leak-check=yes")) |
| 70 | MAC_(clo_leak_check) = True; |
| 71 | else if (VG_CLO_STREQ(arg, "--leak-check=no")) |
| 72 | MAC_(clo_leak_check) = False; |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 73 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 74 | else if (VG_CLO_STREQ(arg, "--leak-resolution=low")) |
| 75 | MAC_(clo_leak_resolution) = Vg_LowRes; |
| 76 | else if (VG_CLO_STREQ(arg, "--leak-resolution=med")) |
| 77 | MAC_(clo_leak_resolution) = Vg_MedRes; |
| 78 | else if (VG_CLO_STREQ(arg, "--leak-resolution=high")) |
| 79 | MAC_(clo_leak_resolution) = Vg_HighRes; |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 80 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 81 | else if (VG_CLO_STREQ(arg, "--show-reachable=yes")) |
| 82 | MAC_(clo_show_reachable) = True; |
| 83 | else if (VG_CLO_STREQ(arg, "--show-reachable=no")) |
| 84 | MAC_(clo_show_reachable) = False; |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 85 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 86 | else if (VG_CLO_STREQ(arg, "--workaround-gcc296-bugs=yes")) |
| 87 | MAC_(clo_workaround_gcc296_bugs) = True; |
| 88 | else if (VG_CLO_STREQ(arg, "--workaround-gcc296-bugs=no")) |
| 89 | MAC_(clo_workaround_gcc296_bugs) = False; |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 90 | |
| 91 | else |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 92 | return VG_(replacement_malloc_process_cmd_line_option)(arg); |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 93 | |
| 94 | return True; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 95 | } |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 96 | |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 97 | void MAC_(print_common_usage)(void) |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 98 | { |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 99 | VG_(printf)( |
| 100 | " --partial-loads-ok=no|yes too hard to explain here; see manual [yes]\n" |
| 101 | " --freelist-vol=<number> volume of freed blocks queue [1000000]\n" |
| 102 | " --leak-check=no|yes search for memory leaks at exit? [no]\n" |
| 103 | " --leak-resolution=low|med|high how much bt merging in leak check [low]\n" |
| 104 | " --show-reachable=no|yes show reachable blocks in leak check? [no]\n" |
| 105 | " --workaround-gcc296-bugs=no|yes self explanatory [no]\n" |
| 106 | ); |
| 107 | VG_(replacement_malloc_print_usage)(); |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 108 | } |
| 109 | |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 110 | void MAC_(print_common_debug_usage)(void) |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 111 | { |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 112 | VG_(replacement_malloc_print_debug_usage)(); |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | /*------------------------------------------------------------*/ |
| 116 | /*--- Comparing and printing errors ---*/ |
| 117 | /*------------------------------------------------------------*/ |
| 118 | |
| 119 | static __inline__ |
| 120 | void clear_AddrInfo ( AddrInfo* ai ) |
| 121 | { |
| 122 | ai->akind = Unknown; |
| 123 | ai->blksize = 0; |
| 124 | ai->rwoffset = 0; |
| 125 | ai->lastchange = NULL; |
| 126 | ai->stack_tid = VG_INVALID_THREADID; |
| 127 | ai->maybe_gcc = False; |
| 128 | } |
| 129 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 130 | void MAC_(clear_MAC_Error) ( MAC_Error* err_extra ) |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 131 | { |
| 132 | err_extra->axskind = ReadAxs; |
| 133 | err_extra->size = 0; |
| 134 | clear_AddrInfo ( &err_extra->addrinfo ); |
| 135 | err_extra->isWrite = False; |
| 136 | } |
| 137 | |
| 138 | __attribute__ ((unused)) |
| 139 | static Bool eq_AddrInfo ( VgRes res, AddrInfo* ai1, AddrInfo* ai2 ) |
| 140 | { |
| 141 | if (ai1->akind != Undescribed |
| 142 | && ai2->akind != Undescribed |
| 143 | && ai1->akind != ai2->akind) |
| 144 | return False; |
| 145 | if (ai1->akind == Freed || ai1->akind == Mallocd) { |
| 146 | if (ai1->blksize != ai2->blksize) |
| 147 | return False; |
| 148 | if (!VG_(eq_ExeContext)(res, ai1->lastchange, ai2->lastchange)) |
| 149 | return False; |
| 150 | } |
| 151 | return True; |
| 152 | } |
| 153 | |
| 154 | /* Compare error contexts, to detect duplicates. Note that if they |
| 155 | are otherwise the same, the faulting addrs and associated rwoffsets |
| 156 | are allowed to be different. */ |
| 157 | |
| 158 | Bool SK_(eq_SkinError) ( VgRes res, Error* e1, Error* e2 ) |
| 159 | { |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 160 | MAC_Error* e1_extra = VG_(get_error_extra)(e1); |
| 161 | MAC_Error* e2_extra = VG_(get_error_extra)(e2); |
njn | 7cc53a8 | 2002-11-19 16:19:32 +0000 | [diff] [blame] | 162 | |
| 163 | /* Guaranteed by calling function */ |
| 164 | sk_assert(VG_(get_error_kind)(e1) == VG_(get_error_kind)(e2)); |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 165 | |
| 166 | switch (VG_(get_error_kind)(e1)) { |
| 167 | case CoreMemErr: { |
| 168 | Char *e1s, *e2s; |
| 169 | if (e1_extra->isWrite != e2_extra->isWrite) return False; |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 170 | e1s = VG_(get_error_string)(e1); |
| 171 | e2s = VG_(get_error_string)(e2); |
| 172 | if (e1s == e2s) return True; |
| 173 | if (0 == VG_(strcmp)(e1s, e2s)) return True; |
| 174 | return False; |
| 175 | } |
| 176 | |
| 177 | case UserErr: |
| 178 | case ParamErr: |
| 179 | if (e1_extra->isWrite != e2_extra->isWrite) return False; |
| 180 | if (VG_(get_error_kind)(e1) == ParamErr |
| 181 | && 0 != VG_(strcmp)(VG_(get_error_string)(e1), |
| 182 | VG_(get_error_string)(e2))) return False; |
| 183 | return True; |
| 184 | |
| 185 | case FreeErr: |
| 186 | case FreeMismatchErr: |
| 187 | /* JRS 2002-Aug-26: comparing addrs seems overkill and can |
| 188 | cause excessive duplication of errors. Not even AddrErr |
| 189 | below does that. So don't compare either the .addr field |
| 190 | or the .addrinfo fields. */ |
| 191 | /* if (e1->addr != e2->addr) return False; */ |
| 192 | /* if (!eq_AddrInfo(res, &e1_extra->addrinfo, &e2_extra->addrinfo)) |
| 193 | return False; |
| 194 | */ |
| 195 | return True; |
| 196 | |
| 197 | case AddrErr: |
| 198 | /* if (e1_extra->axskind != e2_extra->axskind) return False; */ |
| 199 | if (e1_extra->size != e2_extra->size) return False; |
| 200 | /* |
| 201 | if (!eq_AddrInfo(res, &e1_extra->addrinfo, &e2_extra->addrinfo)) |
| 202 | return False; |
| 203 | */ |
| 204 | return True; |
| 205 | |
| 206 | case ValueErr: |
| 207 | if (e1_extra->size != e2_extra->size) return False; |
| 208 | return True; |
| 209 | |
njn | 34419c1 | 2003-05-02 17:24:29 +0000 | [diff] [blame^] | 210 | case OverlapErr: |
| 211 | return True; |
| 212 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 213 | case LeakErr: |
| 214 | VG_(skin_panic)("Shouldn't get LeakErr in SK_(eq_SkinError),\n" |
| 215 | "since it's handled with VG_(unique_error)()!"); |
| 216 | |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 217 | default: |
| 218 | VG_(printf)("Error:\n unknown error code %d\n", |
| 219 | VG_(get_error_kind)(e1)); |
| 220 | VG_(skin_panic)("unknown error code in SK_(eq_SkinError)"); |
| 221 | } |
| 222 | } |
| 223 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 224 | void MAC_(pp_AddrInfo) ( Addr a, AddrInfo* ai ) |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 225 | { |
| 226 | switch (ai->akind) { |
| 227 | case Stack: |
| 228 | VG_(message)(Vg_UserMsg, |
| 229 | " Address 0x%x is on thread %d's stack", |
| 230 | a, ai->stack_tid); |
| 231 | break; |
| 232 | case Unknown: |
| 233 | if (ai->maybe_gcc) { |
| 234 | VG_(message)(Vg_UserMsg, |
| 235 | " Address 0x%x is just below %%esp. Possibly a bug in GCC/G++", |
| 236 | a); |
| 237 | VG_(message)(Vg_UserMsg, |
| 238 | " v 2.96 or 3.0.X. To suppress, use: --workaround-gcc296-bugs=yes"); |
| 239 | } else { |
| 240 | VG_(message)(Vg_UserMsg, |
| 241 | " Address 0x%x is not stack'd, malloc'd or free'd", a); |
| 242 | } |
| 243 | break; |
sewardj | a81709d | 2002-12-28 12:55:48 +0000 | [diff] [blame] | 244 | case Freed: case Mallocd: case UserG: { |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 245 | UInt delta; |
| 246 | UChar* relative; |
| 247 | if (ai->rwoffset < 0) { |
| 248 | delta = (UInt)(- ai->rwoffset); |
| 249 | relative = "before"; |
| 250 | } else if (ai->rwoffset >= ai->blksize) { |
| 251 | delta = ai->rwoffset - ai->blksize; |
| 252 | relative = "after"; |
| 253 | } else { |
| 254 | delta = ai->rwoffset; |
| 255 | relative = "inside"; |
| 256 | } |
sewardj | a81709d | 2002-12-28 12:55:48 +0000 | [diff] [blame] | 257 | VG_(message)(Vg_UserMsg, |
| 258 | " Address 0x%x is %d bytes %s a block of size %d %s", |
| 259 | a, delta, relative, |
| 260 | ai->blksize, |
| 261 | ai->akind==Mallocd ? "alloc'd" |
| 262 | : ai->akind==Freed ? "free'd" |
| 263 | : "client-defined"); |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 264 | VG_(pp_ExeContext)(ai->lastchange); |
| 265 | break; |
| 266 | } |
| 267 | default: |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 268 | VG_(skin_panic)("MAC_(pp_AddrInfo)"); |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | /* This prints out the message for the error types where Memcheck and |
| 273 | Addrcheck have identical messages */ |
| 274 | void MAC_(pp_shared_SkinError) ( Error* err ) |
| 275 | { |
| 276 | MAC_Error* err_extra = VG_(get_error_extra)(err); |
| 277 | |
| 278 | switch (VG_(get_error_kind)(err)) { |
| 279 | case FreeErr: |
| 280 | VG_(message)(Vg_UserMsg,"Invalid free() / delete / delete[]"); |
| 281 | /* fall through */ |
| 282 | case FreeMismatchErr: |
| 283 | if (VG_(get_error_kind)(err) == FreeMismatchErr) |
| 284 | VG_(message)(Vg_UserMsg, |
| 285 | "Mismatched free() / delete / delete []"); |
| 286 | VG_(pp_ExeContext)( VG_(get_error_where)(err) ); |
| 287 | MAC_(pp_AddrInfo)(VG_(get_error_address)(err), &err_extra->addrinfo); |
| 288 | break; |
| 289 | |
| 290 | case LeakErr: { |
| 291 | /* Totally abusing the types of these spare fields... oh well. */ |
| 292 | UInt n_this_record = (UInt)VG_(get_error_address)(err); |
| 293 | UInt n_total_records = (UInt)VG_(get_error_string) (err); |
| 294 | |
| 295 | MAC_(pp_LeakError)(err_extra, n_this_record, n_total_records); |
| 296 | break; |
| 297 | } |
| 298 | |
| 299 | default: |
| 300 | VG_(printf)("Error:\n unknown Memcheck/Addrcheck error code %d\n", |
| 301 | VG_(get_error_kind)(err)); |
| 302 | VG_(skin_panic)("unknown error code in MAC_(pp_shared_SkinError)"); |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 303 | } |
| 304 | } |
| 305 | |
| 306 | /*------------------------------------------------------------*/ |
| 307 | /*--- Recording errors ---*/ |
| 308 | /*------------------------------------------------------------*/ |
| 309 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 310 | /* Additional description function for describe_addr(); used by |
| 311 | MemCheck for user blocks, which Addrcheck doesn't support. */ |
| 312 | Bool (*MAC_(describe_addr_supp)) ( Addr a, AddrInfo* ai ) = NULL; |
| 313 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 314 | /* Describe an address as best you can, for error messages, |
| 315 | putting the result in ai. */ |
| 316 | static void describe_addr ( Addr a, AddrInfo* ai ) |
| 317 | { |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 318 | MAC_Chunk* sc; |
| 319 | ThreadId tid; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 320 | |
| 321 | /* Nested functions, yeah. Need the lexical scoping of 'a'. */ |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 322 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 323 | /* Closure for searching thread stacks */ |
| 324 | Bool addr_is_in_bounds(Addr stack_min, Addr stack_max) |
| 325 | { |
| 326 | return (stack_min <= a && a <= stack_max); |
| 327 | } |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 328 | /* Closure for searching free'd list */ |
| 329 | Bool addr_is_in_MAC_Chunk(MAC_Chunk* mc) |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 330 | { |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 331 | return VG_(addr_is_in_block)( a, mc->data, mc->size ); |
| 332 | } |
| 333 | /* Closure for searching malloc'd lists */ |
| 334 | Bool addr_is_in_HashNode(VgHashNode* sh_ch) |
| 335 | { |
| 336 | return addr_is_in_MAC_Chunk( (MAC_Chunk*)sh_ch ); |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | /* Perhaps it's a user-def'd block ? (only check if requested, though) */ |
| 340 | if (NULL != MAC_(describe_addr_supp)) { |
| 341 | if (MAC_(describe_addr_supp)( a, ai )) |
| 342 | return; |
| 343 | } |
| 344 | /* Perhaps it's on a thread's stack? */ |
| 345 | tid = VG_(first_matching_thread_stack)(addr_is_in_bounds); |
| 346 | if (tid != VG_INVALID_THREADID) { |
| 347 | ai->akind = Stack; |
| 348 | ai->stack_tid = tid; |
| 349 | return; |
| 350 | } |
| 351 | /* Search for a recently freed block which might bracket it. */ |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 352 | sc = MAC_(first_matching_freed_MAC_Chunk)(addr_is_in_MAC_Chunk); |
| 353 | if (NULL != sc) { |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 354 | ai->akind = Freed; |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 355 | ai->blksize = sc->size; |
| 356 | ai->rwoffset = (Int)a - (Int)sc->data; |
| 357 | ai->lastchange = sc->where; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 358 | return; |
| 359 | } |
| 360 | /* Search for a currently malloc'd block which might bracket it. */ |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 361 | sc = (MAC_Chunk*)VG_(HT_first_match)(MAC_(malloc_list), addr_is_in_HashNode); |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 362 | if (NULL != sc) { |
| 363 | ai->akind = Mallocd; |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 364 | ai->blksize = sc->size; |
| 365 | ai->rwoffset = (Int)(a) - (Int)sc->data; |
| 366 | ai->lastchange = sc->where; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 367 | return; |
| 368 | } |
| 369 | /* Clueless ... */ |
| 370 | ai->akind = Unknown; |
| 371 | return; |
| 372 | } |
| 373 | |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 374 | /* Is this address within some small distance below %ESP? Used only |
| 375 | for the --workaround-gcc296-bugs kludge. */ |
| 376 | static Bool is_just_below_ESP( Addr esp, Addr aa ) |
| 377 | { |
| 378 | if ((UInt)esp > (UInt)aa |
| 379 | && ((UInt)esp - (UInt)aa) <= VG_GCC296_BUG_STACK_SLOP) |
| 380 | return True; |
| 381 | else |
| 382 | return False; |
| 383 | } |
| 384 | |
| 385 | /* This one called from generated code. */ |
| 386 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 387 | void MAC_(record_address_error) ( Addr a, Int size, Bool isWrite ) |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 388 | { |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 389 | MAC_Error err_extra; |
| 390 | Bool just_below_esp; |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 391 | |
| 392 | just_below_esp = is_just_below_ESP( VG_(get_stack_pointer)(), a ); |
| 393 | |
| 394 | /* If this is caused by an access immediately below %ESP, and the |
| 395 | user asks nicely, we just ignore it. */ |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 396 | if (MAC_(clo_workaround_gcc296_bugs) && just_below_esp) |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 397 | return; |
| 398 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 399 | MAC_(clear_MAC_Error)( &err_extra ); |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 400 | err_extra.axskind = isWrite ? WriteAxs : ReadAxs; |
| 401 | err_extra.size = size; |
| 402 | err_extra.addrinfo.akind = Undescribed; |
| 403 | err_extra.addrinfo.maybe_gcc = just_below_esp; |
| 404 | VG_(maybe_record_error)( NULL, AddrErr, a, /*s*/NULL, &err_extra ); |
| 405 | } |
| 406 | |
| 407 | /* These ones are called from non-generated code */ |
| 408 | |
| 409 | /* This is for memory errors in pthread functions, as opposed to pthread API |
| 410 | errors which are found by the core. */ |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 411 | void MAC_(record_core_mem_error) ( ThreadState* tst, Bool isWrite, Char* msg ) |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 412 | { |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 413 | MAC_Error err_extra; |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 414 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 415 | MAC_(clear_MAC_Error)( &err_extra ); |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 416 | err_extra.isWrite = isWrite; |
| 417 | VG_(maybe_record_error)( tst, CoreMemErr, /*addr*/0, msg, &err_extra ); |
| 418 | } |
| 419 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 420 | void MAC_(record_param_error) ( ThreadState* tst, Addr a, Bool isWrite, |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 421 | Char* msg ) |
| 422 | { |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 423 | MAC_Error err_extra; |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 424 | |
| 425 | sk_assert(NULL != tst); |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 426 | MAC_(clear_MAC_Error)( &err_extra ); |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 427 | err_extra.addrinfo.akind = Undescribed; |
| 428 | err_extra.isWrite = isWrite; |
| 429 | VG_(maybe_record_error)( tst, ParamErr, a, msg, &err_extra ); |
| 430 | } |
| 431 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 432 | void MAC_(record_jump_error) ( ThreadState* tst, Addr a ) |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 433 | { |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 434 | MAC_Error err_extra; |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 435 | |
| 436 | sk_assert(NULL != tst); |
| 437 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 438 | MAC_(clear_MAC_Error)( &err_extra ); |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 439 | err_extra.axskind = ExecAxs; |
| 440 | err_extra.addrinfo.akind = Undescribed; |
| 441 | VG_(maybe_record_error)( tst, AddrErr, a, /*s*/NULL, &err_extra ); |
| 442 | } |
| 443 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 444 | void MAC_(record_free_error) ( ThreadState* tst, Addr a ) |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 445 | { |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 446 | MAC_Error err_extra; |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 447 | |
| 448 | sk_assert(NULL != tst); |
| 449 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 450 | MAC_(clear_MAC_Error)( &err_extra ); |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 451 | err_extra.addrinfo.akind = Undescribed; |
| 452 | VG_(maybe_record_error)( tst, FreeErr, a, /*s*/NULL, &err_extra ); |
| 453 | } |
| 454 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 455 | void MAC_(record_freemismatch_error) ( ThreadState* tst, Addr a ) |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 456 | { |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 457 | MAC_Error err_extra; |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 458 | |
| 459 | sk_assert(NULL != tst); |
| 460 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 461 | MAC_(clear_MAC_Error)( &err_extra ); |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 462 | err_extra.addrinfo.akind = Undescribed; |
| 463 | VG_(maybe_record_error)( tst, FreeMismatchErr, a, /*s*/NULL, &err_extra ); |
| 464 | } |
| 465 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 466 | /* Updates the copy with address info if necessary (but not for LeakErrs). */ |
| 467 | UInt SK_(update_extra)( Error* err ) |
| 468 | { |
| 469 | MAC_Error* extra; |
| 470 | |
| 471 | /* Don't need to return the correct size -- LeakErrs are always shown with |
| 472 | VG_(unique_error)() so they're not copied anyway. */ |
| 473 | if (LeakErr == VG_(get_error_kind)(err)) |
| 474 | return 0; |
| 475 | |
| 476 | extra = (MAC_Error*)VG_(get_error_extra)(err); |
| 477 | |
| 478 | if (extra != NULL && Undescribed == extra->addrinfo.akind) { |
| 479 | describe_addr ( VG_(get_error_address)(err), &(extra->addrinfo) ); |
| 480 | } |
| 481 | |
| 482 | return sizeof(MAC_Error); |
| 483 | } |
| 484 | |
| 485 | |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 486 | /*------------------------------------------------------------*/ |
| 487 | /*--- Suppressions ---*/ |
| 488 | /*------------------------------------------------------------*/ |
| 489 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 490 | Bool MAC_(shared_recognised_suppression) ( Char* name, Supp* su ) |
| 491 | { |
| 492 | SuppKind skind; |
| 493 | |
| 494 | if (VG_STREQ(name, "Param")) skind = ParamSupp; |
| 495 | else if (VG_STREQ(name, "CoreMem")) skind = CoreMemSupp; |
| 496 | else if (VG_STREQ(name, "Addr1")) skind = Addr1Supp; |
| 497 | else if (VG_STREQ(name, "Addr2")) skind = Addr2Supp; |
| 498 | else if (VG_STREQ(name, "Addr4")) skind = Addr4Supp; |
| 499 | else if (VG_STREQ(name, "Addr8")) skind = Addr8Supp; |
| 500 | else if (VG_STREQ(name, "Free")) skind = FreeSupp; |
| 501 | else if (VG_STREQ(name, "Leak")) skind = LeakSupp; |
| 502 | else |
| 503 | return False; |
| 504 | |
| 505 | VG_(set_supp_kind)(su, skind); |
| 506 | return True; |
| 507 | } |
| 508 | |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 509 | Bool SK_(read_extra_suppression_info) ( Int fd, Char* buf, Int nBuf, Supp *su ) |
| 510 | { |
| 511 | Bool eof; |
| 512 | |
| 513 | if (VG_(get_supp_kind)(su) == ParamSupp) { |
| 514 | eof = VG_(get_line) ( fd, buf, nBuf ); |
| 515 | if (eof) return False; |
| 516 | VG_(set_supp_string)(su, VG_(strdup)(buf)); |
| 517 | } |
| 518 | return True; |
| 519 | } |
| 520 | |
sewardj | 99aac97 | 2002-12-26 01:53:45 +0000 | [diff] [blame] | 521 | Bool SK_(error_matches_suppression)(Error* err, Supp* su) |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 522 | { |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 523 | UInt su_size; |
| 524 | MAC_Error* err_extra = VG_(get_error_extra)(err); |
| 525 | ErrorKind ekind = VG_(get_error_kind )(err); |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 526 | |
| 527 | switch (VG_(get_supp_kind)(su)) { |
| 528 | case ParamSupp: |
| 529 | return (ekind == ParamErr |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 530 | && VG_STREQ(VG_(get_error_string)(err), |
| 531 | VG_(get_supp_string)(su))); |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 532 | |
| 533 | case CoreMemSupp: |
| 534 | return (ekind == CoreMemErr |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 535 | && VG_STREQ(VG_(get_error_string)(err), |
| 536 | VG_(get_supp_string)(su))); |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 537 | |
| 538 | case Value0Supp: su_size = 0; goto value_case; |
| 539 | case Value1Supp: su_size = 1; goto value_case; |
| 540 | case Value2Supp: su_size = 2; goto value_case; |
| 541 | case Value4Supp: su_size = 4; goto value_case; |
| 542 | case Value8Supp: su_size = 8; goto value_case; |
| 543 | value_case: |
| 544 | return (ekind == ValueErr && err_extra->size == su_size); |
| 545 | |
| 546 | case Addr1Supp: su_size = 1; goto addr_case; |
| 547 | case Addr2Supp: su_size = 2; goto addr_case; |
| 548 | case Addr4Supp: su_size = 4; goto addr_case; |
| 549 | case Addr8Supp: su_size = 8; goto addr_case; |
| 550 | addr_case: |
| 551 | return (ekind == AddrErr && err_extra->size == su_size); |
| 552 | |
| 553 | case FreeSupp: |
| 554 | return (ekind == FreeErr || ekind == FreeMismatchErr); |
| 555 | |
njn | 34419c1 | 2003-05-02 17:24:29 +0000 | [diff] [blame^] | 556 | case OverlapSupp: |
| 557 | return (ekind = OverlapErr); |
| 558 | |
sewardj | 4a19e2f | 2002-12-26 11:50:21 +0000 | [diff] [blame] | 559 | case LeakSupp: |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 560 | return (ekind == LeakErr); |
sewardj | 4a19e2f | 2002-12-26 11:50:21 +0000 | [diff] [blame] | 561 | |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 562 | default: |
| 563 | VG_(printf)("Error:\n" |
| 564 | " unknown suppression type %d\n", |
| 565 | VG_(get_supp_kind)(su)); |
| 566 | VG_(skin_panic)("unknown suppression type in " |
| 567 | "SK_(error_matches_suppression)"); |
| 568 | } |
| 569 | } |
| 570 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 571 | Char* SK_(get_error_name) ( Error* err ) |
| 572 | { |
| 573 | Char* s; |
| 574 | switch (VG_(get_error_kind)(err)) { |
| 575 | case ParamErr: return "Param"; |
| 576 | case UserErr: return NULL; /* Can't suppress User errors */ |
| 577 | case FreeMismatchErr: return "Free"; |
| 578 | case FreeErr: return "Free"; |
| 579 | case AddrErr: |
| 580 | switch ( ((MAC_Error*)VG_(get_error_extra)(err))->size ) { |
| 581 | case 1: return "Addr1"; |
| 582 | case 2: return "Addr2"; |
| 583 | case 4: return "Addr4"; |
| 584 | case 8: return "Addr8"; |
| 585 | default: VG_(skin_panic)("unexpected size for Addr"); |
| 586 | } |
| 587 | |
| 588 | case ValueErr: |
| 589 | switch ( ((MAC_Error*)VG_(get_error_extra)(err))->size ) { |
| 590 | case 0: return "Cond"; |
| 591 | case 1: return "Value1"; |
| 592 | case 2: return "Value2"; |
| 593 | case 4: return "Value4"; |
| 594 | case 8: return "Value8"; |
| 595 | default: VG_(skin_panic)("unexpected size for Value"); |
| 596 | } |
| 597 | case CoreMemErr: return "CoreMem"; |
njn | 34419c1 | 2003-05-02 17:24:29 +0000 | [diff] [blame^] | 598 | case OverlapErr: return "Overlap"; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 599 | case LeakErr: return "Leak"; |
| 600 | default: VG_(skin_panic)("get_error_name: unexpected type"); |
| 601 | } |
| 602 | VG_(printf)(s); |
| 603 | } |
| 604 | |
| 605 | void SK_(print_extra_suppression_info) ( Error* err ) |
| 606 | { |
| 607 | if (ParamErr == VG_(get_error_kind)(err)) { |
| 608 | VG_(printf)(" %s\n", VG_(get_error_string)(err)); |
| 609 | } |
| 610 | } |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 611 | |
| 612 | /*------------------------------------------------------------*/ |
| 613 | /*--- Crude profiling machinery. ---*/ |
| 614 | /*------------------------------------------------------------*/ |
| 615 | |
| 616 | /* Event index. If just the name of the fn is given, this means the |
| 617 | number of calls to the fn. Otherwise it is the specified event. |
| 618 | Ones marked 'M' are MemCheck only. Ones marked 'A' are AddrCheck only. |
| 619 | The rest are shared. |
| 620 | |
| 621 | 10 alloc_secondary_map |
| 622 | |
| 623 | 20 get_abit |
| 624 | M 21 get_vbyte |
| 625 | 22 set_abit |
| 626 | M 23 set_vbyte |
| 627 | 24 get_abits4_ALIGNED |
| 628 | M 25 get_vbytes4_ALIGNED |
| 629 | |
| 630 | 30 set_address_range_perms |
| 631 | 31 set_address_range_perms(lower byte loop) |
| 632 | 32 set_address_range_perms(quadword loop) |
| 633 | 33 set_address_range_perms(upper byte loop) |
| 634 | |
| 635 | 35 make_noaccess |
| 636 | 36 make_writable |
| 637 | 37 make_readable |
| 638 | A 38 make_accessible |
| 639 | |
| 640 | 40 copy_address_range_state |
| 641 | 41 copy_address_range_state(byte loop) |
| 642 | 42 check_writable |
| 643 | 43 check_writable(byte loop) |
| 644 | 44 check_readable |
| 645 | 45 check_readable(byte loop) |
| 646 | 46 check_readable_asciiz |
| 647 | 47 check_readable_asciiz(byte loop) |
| 648 | A 48 check_accessible |
| 649 | A 49 check_accessible(byte loop) |
| 650 | |
| 651 | 50 make_noaccess_aligned |
| 652 | 51 make_writable_aligned |
| 653 | |
| 654 | M 60 helperc_LOADV4 |
| 655 | M 61 helperc_STOREV4 |
| 656 | M 62 helperc_LOADV2 |
| 657 | M 63 helperc_STOREV2 |
| 658 | M 64 helperc_LOADV1 |
| 659 | M 65 helperc_STOREV1 |
| 660 | |
| 661 | A 66 helperc_ACCESS4 |
| 662 | A 67 helperc_ACCESS2 |
| 663 | A 68 helperc_ACCESS1 |
| 664 | |
| 665 | M 70 rim_rd_V4_SLOWLY |
| 666 | M 71 rim_wr_V4_SLOWLY |
| 667 | M 72 rim_rd_V2_SLOWLY |
| 668 | M 73 rim_wr_V2_SLOWLY |
| 669 | M 74 rim_rd_V1_SLOWLY |
| 670 | M 75 rim_wr_V1_SLOWLY |
| 671 | |
| 672 | A 76 ACCESS4_SLOWLY |
| 673 | A 77 ACCESS2_SLOWLY |
| 674 | A 78 ACCESS1_SLOWLY |
| 675 | |
| 676 | 80 fpu_read |
| 677 | 81 fpu_read aligned 4 |
| 678 | 82 fpu_read aligned 8 |
| 679 | 83 fpu_read 2 |
| 680 | 84 fpu_read 10/28/108 |
| 681 | |
| 682 | M 85 fpu_write |
| 683 | M 86 fpu_write aligned 4 |
| 684 | M 87 fpu_write aligned 8 |
| 685 | M 88 fpu_write 2 |
| 686 | M 89 fpu_write 10/28/108 |
| 687 | |
| 688 | 90 fpu_access |
| 689 | 91 fpu_access aligned 4 |
| 690 | 92 fpu_access aligned 8 |
| 691 | 93 fpu_access 2 |
| 692 | 94 fpu_access 10/28/108 |
| 693 | |
| 694 | 100 fpu_access_check_SLOWLY |
| 695 | 101 fpu_access_check_SLOWLY(byte loop) |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 696 | |
| 697 | 110 new_mem_stack_4 |
| 698 | 111 new_mem_stack_8 |
| 699 | 112 new_mem_stack_12 |
| 700 | 113 new_mem_stack_16 |
| 701 | 114 new_mem_stack_32 |
| 702 | 115 new_mem_stack |
| 703 | |
| 704 | 120 die_mem_stack_4 |
| 705 | 121 die_mem_stack_8 |
| 706 | 122 die_mem_stack_12 |
| 707 | 123 die_mem_stack_16 |
| 708 | 124 die_mem_stack_32 |
| 709 | 125 die_mem_stack |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 710 | */ |
| 711 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 712 | #ifdef MAC_PROFILE_MEMORY |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 713 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 714 | UInt MAC_(event_ctr)[N_PROF_EVENTS]; |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 715 | |
njn | b4aee05 | 2003-04-15 14:09:58 +0000 | [diff] [blame] | 716 | static void init_prof_mem ( void ) |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 717 | { |
| 718 | Int i; |
| 719 | for (i = 0; i < N_PROF_EVENTS; i++) |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 720 | MAC_(event_ctr)[i] = 0; |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 721 | } |
| 722 | |
njn | b4aee05 | 2003-04-15 14:09:58 +0000 | [diff] [blame] | 723 | static void done_prof_mem ( void ) |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 724 | { |
| 725 | Int i; |
| 726 | for (i = 0; i < N_PROF_EVENTS; i++) { |
| 727 | if ((i % 10) == 0) |
| 728 | VG_(printf)("\n"); |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 729 | if (MAC_(event_ctr)[i] > 0) |
| 730 | VG_(printf)( "prof mem event %2d: %d\n", i, MAC_(event_ctr)[i] ); |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 731 | } |
| 732 | VG_(printf)("\n"); |
| 733 | } |
| 734 | |
| 735 | #else |
| 736 | |
njn | b4aee05 | 2003-04-15 14:09:58 +0000 | [diff] [blame] | 737 | static void init_prof_mem ( void ) { } |
| 738 | static void done_prof_mem ( void ) { } |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 739 | |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 740 | #endif |
| 741 | |
| 742 | /*------------------------------------------------------------*/ |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 743 | /*--- Common initialisation + finalisation ---*/ |
| 744 | /*------------------------------------------------------------*/ |
| 745 | |
| 746 | void MAC_(common_pre_clo_init)(void) |
| 747 | { |
| 748 | MAC_(malloc_list) = VG_(HT_construct)(); |
| 749 | init_prof_mem(); |
| 750 | } |
| 751 | |
| 752 | void MAC_(common_fini)(void (*leak_check)(void)) |
| 753 | { |
| 754 | MAC_(print_malloc_stats)(); |
| 755 | |
| 756 | if (VG_(clo_verbosity) == 1) { |
| 757 | if (!MAC_(clo_leak_check)) |
| 758 | VG_(message)(Vg_UserMsg, |
| 759 | "For a detailed leak analysis, rerun with: --leak-check=yes"); |
| 760 | |
| 761 | VG_(message)(Vg_UserMsg, |
| 762 | "For counts of detected errors, rerun with: -v"); |
| 763 | } |
| 764 | if (MAC_(clo_leak_check)) leak_check(); |
| 765 | |
| 766 | done_prof_mem(); |
| 767 | } |
| 768 | |
| 769 | /*------------------------------------------------------------*/ |
njn | 47363ab | 2003-04-21 13:24:40 +0000 | [diff] [blame] | 770 | /*--- Common client request handling ---*/ |
| 771 | /*------------------------------------------------------------*/ |
| 772 | |
| 773 | Bool MAC_(handle_common_client_requests)(ThreadState* tst, UInt* arg, |
| 774 | UInt* ret ) |
| 775 | { |
| 776 | UInt** argp = (UInt**)arg; |
| 777 | |
| 778 | switch (arg[0]) { |
| 779 | case VG_USERREQ__COUNT_LEAKS: /* count leaked bytes */ |
| 780 | *argp[1] = MAC_(total_bytes_leaked); |
| 781 | *argp[2] = MAC_(total_bytes_dubious); |
| 782 | *argp[3] = MAC_(total_bytes_reachable); |
| 783 | *argp[4] = MAC_(total_bytes_suppressed); |
| 784 | *ret = 0; |
| 785 | return True; |
| 786 | |
| 787 | default: |
| 788 | return False; |
| 789 | } |
| 790 | } |
| 791 | |
| 792 | /*------------------------------------------------------------*/ |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 793 | /*--- Syscall wrappers ---*/ |
| 794 | /*------------------------------------------------------------*/ |
| 795 | |
| 796 | void* SK_(pre_syscall) ( ThreadId tid, UInt syscallno, Bool isBlocking ) |
| 797 | { |
| 798 | Int sane = SK_(cheap_sanity_check)(); |
| 799 | return (void*)sane; |
| 800 | } |
| 801 | |
| 802 | void SK_(post_syscall) ( ThreadId tid, UInt syscallno, |
| 803 | void* pre_result, Int res, Bool isBlocking ) |
| 804 | { |
| 805 | Int sane_before_call = (Int)pre_result; |
| 806 | Bool sane_after_call = SK_(cheap_sanity_check)(); |
| 807 | |
| 808 | if ((Int)sane_before_call && (!sane_after_call)) { |
| 809 | VG_(message)(Vg_DebugMsg, "post-syscall: "); |
| 810 | VG_(message)(Vg_DebugMsg, |
| 811 | "probable sanity check failure for syscall number %d\n", |
| 812 | syscallno ); |
| 813 | VG_(skin_panic)("aborting due to the above ... bye!"); |
| 814 | } |
| 815 | } |
| 816 | |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 817 | /*--------------------------------------------------------------------*/ |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 818 | /*--- end mac_needs.c ---*/ |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 819 | /*--------------------------------------------------------------------*/ |