njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 1 | |
| 2 | /*--------------------------------------------------------------------*/ |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 3 | /*--- Declarations shared between MemCheck and AddrCheck. ---*/ |
| 4 | /*--- mac_shared.h ---*/ |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 5 | /*--------------------------------------------------------------------*/ |
| 6 | |
| 7 | /* |
nethercote | 137bc55 | 2003-11-14 17:47:54 +0000 | [diff] [blame] | 8 | This file is part of MemCheck, a heavyweight Valgrind tool for |
| 9 | detecting memory errors, and AddrCheck, a lightweight Valgrind tool |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 10 | for detecting memory errors. |
| 11 | |
nethercote | bb1c991 | 2004-01-04 16:43:23 +0000 | [diff] [blame] | 12 | Copyright (C) 2000-2004 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 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 33 | /* Note: This header contains the declarations shared between |
| 34 | Addrcheck and Memcheck, and is #included by both. */ |
| 35 | |
| 36 | #ifndef __MAC_SHARED_H |
| 37 | #define __MAC_SHARED_H |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 38 | |
| 39 | #include "vg_skin.h" |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 40 | |
| 41 | #define MAC_(str) VGAPPEND(vgMAC_,str) |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 42 | |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 43 | /*------------------------------------------------------------*/ |
| 44 | /*--- Errors and suppressions ---*/ |
| 45 | /*------------------------------------------------------------*/ |
| 46 | |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 47 | /* The classification of a faulting address. */ |
| 48 | typedef |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 49 | enum { |
| 50 | Undescribed, /* as-yet unclassified */ |
| 51 | Stack, |
| 52 | Unknown, /* classification yielded nothing useful */ |
| 53 | Freed, Mallocd, |
rjwalsh | bc0bb83 | 2004-06-19 18:12:36 +0000 | [diff] [blame^] | 54 | UserG, /* in a user-defined block; Addrcheck & Memcheck only */ |
| 55 | Mempool, /* in a mempool; Addrcheck & Memcheck only */ |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 56 | } |
| 57 | AddrKind; |
| 58 | |
| 59 | /* Records info about a faulting address. */ |
| 60 | typedef |
| 61 | struct { |
| 62 | /* ALL */ |
| 63 | AddrKind akind; |
| 64 | /* Freed, Mallocd */ |
| 65 | Int blksize; |
| 66 | /* Freed, Mallocd */ |
| 67 | Int rwoffset; |
| 68 | /* Freed, Mallocd */ |
| 69 | ExeContext* lastchange; |
| 70 | /* Stack */ |
| 71 | ThreadId stack_tid; |
| 72 | /* True if is just-below %esp -- could be a gcc bug. */ |
| 73 | Bool maybe_gcc; |
| 74 | } |
| 75 | AddrInfo; |
| 76 | |
| 77 | typedef |
| 78 | enum { |
| 79 | /* Bad syscall params */ |
| 80 | ParamSupp, |
| 81 | /* Memory errors in core (pthread ops, signal handling) */ |
| 82 | CoreMemSupp, |
| 83 | /* Use of invalid values of given size (MemCheck only) */ |
njn | c061666 | 2003-06-12 09:58:41 +0000 | [diff] [blame] | 84 | Value0Supp, Value1Supp, Value2Supp, Value4Supp, Value8Supp, Value16Supp, |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 85 | /* Invalid read/write attempt at given size */ |
njn | c061666 | 2003-06-12 09:58:41 +0000 | [diff] [blame] | 86 | Addr1Supp, Addr2Supp, Addr4Supp, Addr8Supp, Addr16Supp, |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 87 | /* Invalid or mismatching free */ |
sewardj | 99aac97 | 2002-12-26 01:53:45 +0000 | [diff] [blame] | 88 | FreeSupp, |
njn | 34419c1 | 2003-05-02 17:24:29 +0000 | [diff] [blame] | 89 | /* Overlapping blocks in memcpy(), strcpy(), etc */ |
| 90 | OverlapSupp, |
sewardj | 99aac97 | 2002-12-26 01:53:45 +0000 | [diff] [blame] | 91 | /* Something to be suppressed in a leak check. */ |
rjwalsh | bc0bb83 | 2004-06-19 18:12:36 +0000 | [diff] [blame^] | 92 | LeakSupp, |
| 93 | /* Memory pool suppression. */ |
| 94 | MempoolSupp, |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 95 | } |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 96 | MAC_SuppKind; |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 97 | |
| 98 | /* What kind of error it is. */ |
| 99 | typedef |
| 100 | enum { ValueErr, /* Memcheck only */ |
| 101 | CoreMemErr, |
| 102 | AddrErr, |
| 103 | ParamErr, UserErr, /* behaves like an anonymous ParamErr */ |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 104 | FreeErr, FreeMismatchErr, |
njn | 7201b2a | 2003-08-19 12:16:05 +0000 | [diff] [blame] | 105 | OverlapErr, |
rjwalsh | bc0bb83 | 2004-06-19 18:12:36 +0000 | [diff] [blame^] | 106 | LeakErr, |
| 107 | IllegalMempoolErr, |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 108 | } |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 109 | MAC_ErrorKind; |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 110 | |
| 111 | /* What kind of memory access is involved in the error? */ |
| 112 | typedef |
| 113 | enum { ReadAxs, WriteAxs, ExecAxs } |
| 114 | AxsKind; |
| 115 | |
| 116 | /* Extra context for memory errors */ |
| 117 | typedef |
| 118 | struct { |
| 119 | /* AddrErr */ |
| 120 | AxsKind axskind; |
| 121 | /* AddrErr, ValueErr */ |
| 122 | Int size; |
| 123 | /* AddrErr, FreeErr, FreeMismatchErr, ParamErr, UserErr */ |
| 124 | AddrInfo addrinfo; |
| 125 | /* ParamErr, UserErr, CoreMemErr */ |
| 126 | Bool isWrite; |
| 127 | } |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 128 | MAC_Error; |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 129 | |
njn | b6cae9f | 2003-09-04 20:50:47 +0000 | [diff] [blame] | 130 | /* Extra info for overlap errors */ |
| 131 | typedef |
| 132 | struct { |
| 133 | Addr src; |
| 134 | Addr dst; |
| 135 | Int len; // -1 if unused |
| 136 | } |
| 137 | OverlapExtra; |
| 138 | |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 139 | /* For malloc()/new/new[] vs. free()/delete/delete[] mismatch checking. */ |
| 140 | typedef |
| 141 | enum { |
| 142 | MAC_AllocMalloc = 0, |
| 143 | MAC_AllocNew = 1, |
njn | 1078545 | 2003-05-20 16:38:24 +0000 | [diff] [blame] | 144 | MAC_AllocNewVec = 2, |
| 145 | MAC_AllocCustom = 3 |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 146 | } |
| 147 | MAC_AllocKind; |
| 148 | |
| 149 | /* Nb: first two fields must match core's VgHashNode. */ |
| 150 | typedef |
| 151 | struct _MAC_Chunk { |
| 152 | struct _MAC_Chunk* next; |
| 153 | Addr data; /* ptr to actual block */ |
| 154 | UInt size : 30; /* size requested */ |
| 155 | MAC_AllocKind allockind : 2; /* which wrapper did the allocation */ |
| 156 | ExeContext* where; /* where it was allocated */ |
| 157 | } |
| 158 | MAC_Chunk; |
| 159 | |
rjwalsh | bc0bb83 | 2004-06-19 18:12:36 +0000 | [diff] [blame^] | 160 | /* Memory pool. Nb: first two fields must match core's VgHashNode. */ |
| 161 | typedef |
| 162 | struct _MAC_Mempool { |
| 163 | struct _MAC_Mempool* next; |
| 164 | Addr pool; /* pool identifier */ |
| 165 | UInt rzB; /* pool red-zone size */ |
| 166 | Bool is_zeroed; /* allocations from this pool are zeroed */ |
| 167 | VgHashTable chunks; /* chunks associated with this pool */ |
| 168 | } |
| 169 | MAC_Mempool; |
| 170 | |
| 171 | |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 172 | /*------------------------------------------------------------*/ |
nethercote | 7cc9c23 | 2004-01-21 15:08:04 +0000 | [diff] [blame] | 173 | /*--- Profiling of tools and memory events ---*/ |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 174 | /*------------------------------------------------------------*/ |
| 175 | |
| 176 | typedef |
| 177 | enum { |
| 178 | VgpCheckMem = VgpFini+1, |
| 179 | VgpSetMem, |
| 180 | VgpESPAdj |
| 181 | } |
nethercote | 7cc9c23 | 2004-01-21 15:08:04 +0000 | [diff] [blame] | 182 | VgpToolCC; |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 183 | |
| 184 | /* Define to collect detailed performance info. */ |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 185 | /* #define MAC_PROFILE_MEMORY */ |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 186 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 187 | #ifdef MAC_PROFILE_MEMORY |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 188 | # define N_PROF_EVENTS 150 |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 189 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 190 | extern UInt MAC_(event_ctr)[N_PROF_EVENTS]; |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 191 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 192 | # define PROF_EVENT(ev) \ |
| 193 | do { sk_assert((ev) >= 0 && (ev) < N_PROF_EVENTS); \ |
| 194 | MAC_(event_ctr)[ev]++; \ |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 195 | } while (False); |
| 196 | |
| 197 | #else |
| 198 | |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 199 | # define PROF_EVENT(ev) /* */ |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 200 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 201 | #endif /* MAC_PROFILE_MEMORY */ |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 202 | |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 203 | /*------------------------------------------------------------*/ |
| 204 | /*--- V and A bits ---*/ |
| 205 | /*------------------------------------------------------------*/ |
| 206 | |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 207 | #define IS_DISTINGUISHED_SM(smap) \ |
| 208 | ((smap) == &distinguished_secondary_map) |
| 209 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 210 | #define ENSURE_MAPPABLE(addr,caller) \ |
| 211 | do { \ |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 212 | if (IS_DISTINGUISHED_SM(primary_map[(addr) >> 16])) { \ |
| 213 | primary_map[(addr) >> 16] = alloc_secondary_map(caller); \ |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 214 | /* VG_(printf)("new 2map because of %p\n", addr); */ \ |
| 215 | } \ |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 216 | } while(0) |
| 217 | |
| 218 | #define BITARR_SET(aaa_p,iii_p) \ |
| 219 | do { \ |
| 220 | UInt iii = (UInt)iii_p; \ |
| 221 | UChar* aaa = (UChar*)aaa_p; \ |
| 222 | aaa[iii >> 3] |= (1 << (iii & 7)); \ |
| 223 | } while (0) |
| 224 | |
| 225 | #define BITARR_CLEAR(aaa_p,iii_p) \ |
| 226 | do { \ |
| 227 | UInt iii = (UInt)iii_p; \ |
| 228 | UChar* aaa = (UChar*)aaa_p; \ |
| 229 | aaa[iii >> 3] &= ~(1 << (iii & 7)); \ |
| 230 | } while (0) |
| 231 | |
| 232 | #define BITARR_TEST(aaa_p,iii_p) \ |
| 233 | (0 != (((UChar*)aaa_p)[ ((UInt)iii_p) >> 3 ] \ |
| 234 | & (1 << (((UInt)iii_p) & 7)))) \ |
| 235 | |
| 236 | |
| 237 | #define VGM_BIT_VALID 0 |
| 238 | #define VGM_BIT_INVALID 1 |
| 239 | |
| 240 | #define VGM_NIBBLE_VALID 0 |
| 241 | #define VGM_NIBBLE_INVALID 0xF |
| 242 | |
| 243 | #define VGM_BYTE_VALID 0 |
| 244 | #define VGM_BYTE_INVALID 0xFF |
| 245 | |
| 246 | #define VGM_WORD_VALID 0 |
| 247 | #define VGM_WORD_INVALID 0xFFFFFFFF |
| 248 | |
| 249 | #define VGM_EFLAGS_VALID 0xFFFFFFFE |
| 250 | #define VGM_EFLAGS_INVALID 0xFFFFFFFF /* not used */ |
| 251 | |
| 252 | /*------------------------------------------------------------*/ |
| 253 | /*--- Command line options + defaults ---*/ |
| 254 | /*------------------------------------------------------------*/ |
| 255 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 256 | /* Memcheck defines a couple more. */ |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 257 | |
| 258 | /* Allow loads from partially-valid addresses? default: YES */ |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 259 | extern Bool MAC_(clo_partial_loads_ok); |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 260 | |
| 261 | /* Max volume of the freed blocks queue. */ |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 262 | extern Int MAC_(clo_freelist_vol); |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 263 | |
| 264 | /* Do leak check at exit? default: NO */ |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 265 | extern Bool MAC_(clo_leak_check); |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 266 | |
| 267 | /* How closely should we compare ExeContexts in leak records? default: 2 */ |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 268 | extern VgRes MAC_(clo_leak_resolution); |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 269 | |
| 270 | /* In leak check, show reachable-but-not-freed blocks? default: NO */ |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 271 | extern Bool MAC_(clo_show_reachable); |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 272 | |
| 273 | /* Assume accesses immediately below %esp are due to gcc-2.96 bugs. |
| 274 | * default: NO*/ |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 275 | extern Bool MAC_(clo_workaround_gcc296_bugs); |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 276 | |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 277 | extern Bool MAC_(process_common_cmd_line_option) ( Char* arg ); |
| 278 | extern void MAC_(print_common_usage) ( void ); |
| 279 | extern void MAC_(print_common_debug_usage) ( void ); |
| 280 | |
| 281 | |
| 282 | /*------------------------------------------------------------*/ |
| 283 | /*--- Variables ---*/ |
| 284 | /*------------------------------------------------------------*/ |
| 285 | |
| 286 | /* For tracking malloc'd blocks */ |
| 287 | extern VgHashTable MAC_(malloc_list); |
| 288 | |
rjwalsh | bc0bb83 | 2004-06-19 18:12:36 +0000 | [diff] [blame^] | 289 | /* For tracking memory pools. */ |
| 290 | extern VgHashTable MAC_(mempool_list); |
| 291 | |
nethercote | 7cc9c23 | 2004-01-21 15:08:04 +0000 | [diff] [blame] | 292 | /* Function pointers for the two tools to track interesting events. */ |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 293 | extern void (*MAC_(new_mem_heap)) ( Addr a, UInt len, Bool is_inited ); |
| 294 | extern void (*MAC_(ban_mem_heap)) ( Addr a, UInt len ); |
| 295 | extern void (*MAC_(die_mem_heap)) ( Addr a, UInt len ); |
| 296 | extern void (*MAC_(copy_mem_heap))( Addr from, Addr to, UInt len ); |
| 297 | |
sewardj | ecf8e10 | 2003-07-12 12:11:39 +0000 | [diff] [blame] | 298 | /* Function pointers for internal sanity checking. */ |
| 299 | extern Bool (*MAC_(check_noaccess))( Addr a, UInt len, Addr* bad_addr ); |
| 300 | |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 301 | /* Used in describe_addr() */ |
| 302 | extern Bool (*MAC_(describe_addr_supp)) ( Addr a, AddrInfo* ai ); |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 303 | |
njn | 47363ab | 2003-04-21 13:24:40 +0000 | [diff] [blame] | 304 | /* For VALGRIND_COUNT_LEAKS client request */ |
njn | e8b5c05 | 2003-07-22 22:03:58 +0000 | [diff] [blame] | 305 | extern Int MAC_(bytes_leaked); |
| 306 | extern Int MAC_(bytes_dubious); |
| 307 | extern Int MAC_(bytes_reachable); |
| 308 | extern Int MAC_(bytes_suppressed); |
sewardj | 99aac97 | 2002-12-26 01:53:45 +0000 | [diff] [blame] | 309 | |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 310 | /*------------------------------------------------------------*/ |
| 311 | /*--- Functions ---*/ |
| 312 | /*------------------------------------------------------------*/ |
| 313 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 314 | extern void MAC_(pp_AddrInfo) ( Addr a, AddrInfo* ai ); |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 315 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 316 | extern void MAC_(clear_MAC_Error) ( MAC_Error* err_extra ); |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 317 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 318 | extern Bool MAC_(shared_recognised_suppression) ( Char* name, Supp* su ); |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 319 | |
rjwalsh | bc0bb83 | 2004-06-19 18:12:36 +0000 | [diff] [blame^] | 320 | extern MAC_Chunk* MAC_(new_block) ( Addr p, UInt size, UInt rzB, |
| 321 | Bool is_zeroed, MAC_AllocKind kind, |
| 322 | VgHashTable table); |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 323 | extern void MAC_(handle_free) ( Addr p, UInt rzB, MAC_AllocKind kind ); |
njn | 1078545 | 2003-05-20 16:38:24 +0000 | [diff] [blame] | 324 | |
rjwalsh | bc0bb83 | 2004-06-19 18:12:36 +0000 | [diff] [blame^] | 325 | extern void MAC_(create_mempool)(Addr pool, UInt rzB, Bool is_zeroed); |
| 326 | extern void MAC_(destroy_mempool)(Addr pool); |
| 327 | extern void MAC_(mempool_alloc)(Addr pool, Addr addr, UInt size); |
| 328 | extern void MAC_(mempool_free)(Addr pool, Addr addr); |
| 329 | |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 330 | extern void MAC_(record_address_error) ( ThreadId tid, Addr a, |
sewardj | af48a60 | 2003-07-06 00:54:47 +0000 | [diff] [blame] | 331 | Int size, Bool isWrite ); |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 332 | extern void MAC_(record_core_mem_error) ( ThreadId tid, Bool isWrite, |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 333 | Char* s ); |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 334 | extern void MAC_(record_param_error) ( ThreadId tid, Addr a, |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 335 | Bool isWriteLack, Char* msg ); |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 336 | extern void MAC_(record_jump_error) ( ThreadId tid, Addr a ); |
| 337 | extern void MAC_(record_free_error) ( ThreadId tid, Addr a ); |
| 338 | extern void MAC_(record_freemismatch_error)( ThreadId tid, Addr a ); |
njn | b6cae9f | 2003-09-04 20:50:47 +0000 | [diff] [blame] | 339 | extern void MAC_(record_overlap_error) ( Char* function, OverlapExtra* oe ); |
rjwalsh | bc0bb83 | 2004-06-19 18:12:36 +0000 | [diff] [blame^] | 340 | extern void MAC_(record_illegal_mempool_error) ( ThreadId tid, Addr pool ); |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 341 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 342 | extern void MAC_(pp_shared_SkinError) ( Error* err); |
| 343 | |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 344 | extern MAC_Chunk* MAC_(first_matching_freed_MAC_Chunk)( Bool (*p)(MAC_Chunk*) ); |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 345 | |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 346 | extern void MAC_(common_pre_clo_init) ( void ); |
| 347 | extern void MAC_(common_fini) ( void (*leak_check)(void) ); |
| 348 | |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 349 | extern Bool MAC_(handle_common_client_requests) ( ThreadId tid, |
| 350 | UInt* arg_block, UInt* ret ); |
njn | 47363ab | 2003-04-21 13:24:40 +0000 | [diff] [blame] | 351 | |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 352 | extern void MAC_(print_malloc_stats) ( void ); |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 353 | |
| 354 | /* For leak checking */ |
| 355 | extern void MAC_(pp_LeakError)(void* vl, UInt n_this_record, |
| 356 | UInt n_total_records); |
| 357 | |
| 358 | extern void MAC_(do_detect_memory_leaks) ( |
| 359 | Bool is_valid_64k_chunk ( UInt ), |
| 360 | Bool is_valid_address ( Addr ) |
| 361 | ); |
| 362 | |
| 363 | extern __attribute__((regparm(1))) void MAC_(new_mem_stack_4) ( Addr old_ESP ); |
| 364 | extern __attribute__((regparm(1))) void MAC_(die_mem_stack_4) ( Addr old_ESP ); |
| 365 | extern __attribute__((regparm(1))) void MAC_(new_mem_stack_8) ( Addr old_ESP ); |
| 366 | extern __attribute__((regparm(1))) void MAC_(die_mem_stack_8) ( Addr old_ESP ); |
| 367 | extern __attribute__((regparm(1))) void MAC_(new_mem_stack_12) ( Addr old_ESP ); |
| 368 | extern __attribute__((regparm(1))) void MAC_(die_mem_stack_12) ( Addr old_ESP ); |
| 369 | extern __attribute__((regparm(1))) void MAC_(new_mem_stack_16) ( Addr old_ESP ); |
| 370 | extern __attribute__((regparm(1))) void MAC_(die_mem_stack_16) ( Addr old_ESP ); |
| 371 | extern __attribute__((regparm(1))) void MAC_(new_mem_stack_32) ( Addr old_ESP ); |
| 372 | extern __attribute__((regparm(1))) void MAC_(die_mem_stack_32) ( Addr old_ESP ); |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 373 | extern void MAC_(die_mem_stack) ( Addr a, UInt len); |
| 374 | extern void MAC_(new_mem_stack) ( Addr a, UInt len); |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 375 | |
| 376 | |
| 377 | /*------------------------------------------------------------*/ |
| 378 | /*--- Stack pointer adjustment ---*/ |
| 379 | /*------------------------------------------------------------*/ |
| 380 | |
| 381 | /* Some noble preprocessor abuse, to enable Memcheck and Addrcheck to |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 382 | share this code, but call different functions. |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 383 | |
| 384 | Note that this code is executed very frequently and must be highly |
| 385 | optimised, which is why I resort to the preprocessor to achieve the |
| 386 | factoring, rather than eg. using function pointers. |
| 387 | */ |
| 388 | |
| 389 | #define ESP_UPDATE_HANDLERS(ALIGNED4_NEW, ALIGNED4_DIE, \ |
| 390 | ALIGNED8_NEW, ALIGNED8_DIE, \ |
| 391 | UNALIGNED_NEW, UNALIGNED_DIE) \ |
| 392 | \ |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 393 | void __attribute__((regparm(1))) MAC_(new_mem_stack_4)(Addr new_ESP) \ |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 394 | { \ |
| 395 | PROF_EVENT(110); \ |
| 396 | if (IS_ALIGNED4_ADDR(new_ESP)) { \ |
| 397 | ALIGNED4_NEW ( new_ESP ); \ |
| 398 | } else { \ |
| 399 | UNALIGNED_NEW ( new_ESP, 4 ); \ |
| 400 | } \ |
| 401 | } \ |
| 402 | \ |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 403 | void __attribute__((regparm(1))) MAC_(die_mem_stack_4)(Addr new_ESP) \ |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 404 | { \ |
| 405 | PROF_EVENT(120); \ |
| 406 | if (IS_ALIGNED4_ADDR(new_ESP)) { \ |
| 407 | ALIGNED4_DIE ( new_ESP-4 ); \ |
| 408 | } else { \ |
| 409 | UNALIGNED_DIE ( new_ESP-4, 4 ); \ |
| 410 | } \ |
| 411 | } \ |
| 412 | \ |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 413 | void __attribute__((regparm(1))) MAC_(new_mem_stack_8)(Addr new_ESP) \ |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 414 | { \ |
| 415 | PROF_EVENT(111); \ |
| 416 | if (IS_ALIGNED8_ADDR(new_ESP)) { \ |
| 417 | ALIGNED8_NEW ( new_ESP ); \ |
| 418 | } else if (IS_ALIGNED4_ADDR(new_ESP)) { \ |
| 419 | ALIGNED4_NEW ( new_ESP ); \ |
| 420 | ALIGNED4_NEW ( new_ESP+4 ); \ |
| 421 | } else { \ |
| 422 | UNALIGNED_NEW ( new_ESP, 8 ); \ |
| 423 | } \ |
| 424 | } \ |
| 425 | \ |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 426 | void __attribute__((regparm(1))) MAC_(die_mem_stack_8)(Addr new_ESP) \ |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 427 | { \ |
| 428 | PROF_EVENT(121); \ |
| 429 | if (IS_ALIGNED8_ADDR(new_ESP)) { \ |
| 430 | ALIGNED8_DIE ( new_ESP-8 ); \ |
| 431 | } else if (IS_ALIGNED4_ADDR(new_ESP)) { \ |
| 432 | ALIGNED4_DIE ( new_ESP-8 ); \ |
| 433 | ALIGNED4_DIE ( new_ESP-4 ); \ |
| 434 | } else { \ |
| 435 | UNALIGNED_DIE ( new_ESP-8, 8 ); \ |
| 436 | } \ |
| 437 | } \ |
| 438 | \ |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 439 | void __attribute__((regparm(1))) MAC_(new_mem_stack_12)(Addr new_ESP) \ |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 440 | { \ |
| 441 | PROF_EVENT(112); \ |
| 442 | if (IS_ALIGNED8_ADDR(new_ESP)) { \ |
| 443 | ALIGNED8_NEW ( new_ESP ); \ |
| 444 | ALIGNED4_NEW ( new_ESP+8 ); \ |
| 445 | } else if (IS_ALIGNED4_ADDR(new_ESP)) { \ |
| 446 | ALIGNED4_NEW ( new_ESP ); \ |
| 447 | ALIGNED8_NEW ( new_ESP+4 ); \ |
| 448 | } else { \ |
| 449 | UNALIGNED_NEW ( new_ESP, 12 ); \ |
| 450 | } \ |
| 451 | } \ |
| 452 | \ |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 453 | void __attribute__((regparm(1))) MAC_(die_mem_stack_12)(Addr new_ESP) \ |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 454 | { \ |
| 455 | PROF_EVENT(122); \ |
| 456 | /* Note the -12 in the test */ \ |
| 457 | if (IS_ALIGNED8_ADDR(new_ESP-12)) { \ |
| 458 | ALIGNED8_DIE ( new_ESP-12 ); \ |
| 459 | ALIGNED4_DIE ( new_ESP-4 ); \ |
| 460 | } else if (IS_ALIGNED4_ADDR(new_ESP)) { \ |
| 461 | ALIGNED4_DIE ( new_ESP-12 ); \ |
| 462 | ALIGNED8_DIE ( new_ESP-8 ); \ |
| 463 | } else { \ |
| 464 | UNALIGNED_DIE ( new_ESP-12, 12 ); \ |
| 465 | } \ |
| 466 | } \ |
| 467 | \ |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 468 | void __attribute__((regparm(1))) MAC_(new_mem_stack_16)(Addr new_ESP) \ |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 469 | { \ |
| 470 | PROF_EVENT(113); \ |
| 471 | if (IS_ALIGNED8_ADDR(new_ESP)) { \ |
| 472 | ALIGNED8_NEW ( new_ESP ); \ |
| 473 | ALIGNED8_NEW ( new_ESP+8 ); \ |
| 474 | } else if (IS_ALIGNED4_ADDR(new_ESP)) { \ |
| 475 | ALIGNED4_NEW ( new_ESP ); \ |
| 476 | ALIGNED8_NEW ( new_ESP+4 ); \ |
| 477 | ALIGNED4_NEW ( new_ESP+12 ); \ |
| 478 | } else { \ |
| 479 | UNALIGNED_NEW ( new_ESP, 16 ); \ |
| 480 | } \ |
| 481 | } \ |
| 482 | \ |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 483 | void __attribute__((regparm(1))) MAC_(die_mem_stack_16)(Addr new_ESP) \ |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 484 | { \ |
| 485 | PROF_EVENT(123); \ |
| 486 | if (IS_ALIGNED8_ADDR(new_ESP)) { \ |
| 487 | ALIGNED8_DIE ( new_ESP-16 ); \ |
| 488 | ALIGNED8_DIE ( new_ESP-8 ); \ |
| 489 | } else if (IS_ALIGNED4_ADDR(new_ESP)) { \ |
| 490 | ALIGNED4_DIE ( new_ESP-16 ); \ |
| 491 | ALIGNED8_DIE ( new_ESP-12 ); \ |
| 492 | ALIGNED4_DIE ( new_ESP-4 ); \ |
| 493 | } else { \ |
| 494 | UNALIGNED_DIE ( new_ESP-16, 16 ); \ |
| 495 | } \ |
| 496 | } \ |
| 497 | \ |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 498 | void __attribute__((regparm(1))) MAC_(new_mem_stack_32)(Addr new_ESP) \ |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 499 | { \ |
| 500 | PROF_EVENT(114); \ |
| 501 | if (IS_ALIGNED8_ADDR(new_ESP)) { \ |
| 502 | ALIGNED8_NEW ( new_ESP ); \ |
| 503 | ALIGNED8_NEW ( new_ESP+8 ); \ |
| 504 | ALIGNED8_NEW ( new_ESP+16 ); \ |
| 505 | ALIGNED8_NEW ( new_ESP+24 ); \ |
| 506 | } else if (IS_ALIGNED4_ADDR(new_ESP)) { \ |
| 507 | ALIGNED4_NEW ( new_ESP ); \ |
| 508 | ALIGNED8_NEW ( new_ESP+4 ); \ |
| 509 | ALIGNED8_NEW ( new_ESP+12 ); \ |
| 510 | ALIGNED8_NEW ( new_ESP+20 ); \ |
| 511 | ALIGNED4_NEW ( new_ESP+28 ); \ |
| 512 | } else { \ |
| 513 | UNALIGNED_NEW ( new_ESP, 32 ); \ |
| 514 | } \ |
| 515 | } \ |
| 516 | \ |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 517 | void __attribute__((regparm(1))) MAC_(die_mem_stack_32)(Addr new_ESP) \ |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 518 | { \ |
| 519 | PROF_EVENT(124); \ |
| 520 | if (IS_ALIGNED8_ADDR(new_ESP)) { \ |
| 521 | ALIGNED8_DIE ( new_ESP-32 ); \ |
| 522 | ALIGNED8_DIE ( new_ESP-24 ); \ |
| 523 | ALIGNED8_DIE ( new_ESP-16 ); \ |
| 524 | ALIGNED8_DIE ( new_ESP- 8 ); \ |
| 525 | } else if (IS_ALIGNED4_ADDR(new_ESP)) { \ |
| 526 | ALIGNED4_DIE ( new_ESP-32 ); \ |
| 527 | ALIGNED8_DIE ( new_ESP-28 ); \ |
| 528 | ALIGNED8_DIE ( new_ESP-20 ); \ |
| 529 | ALIGNED8_DIE ( new_ESP-12 ); \ |
| 530 | ALIGNED4_DIE ( new_ESP-4 ); \ |
| 531 | } else { \ |
| 532 | UNALIGNED_DIE ( new_ESP-32, 32 ); \ |
| 533 | } \ |
| 534 | } \ |
| 535 | \ |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 536 | void MAC_(new_mem_stack) ( Addr a, UInt len ) \ |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 537 | { \ |
| 538 | PROF_EVENT(115); \ |
| 539 | UNALIGNED_NEW ( a, len ); \ |
| 540 | } \ |
| 541 | \ |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 542 | void MAC_(die_mem_stack) ( Addr a, UInt len ) \ |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 543 | { \ |
| 544 | PROF_EVENT(125); \ |
| 545 | UNALIGNED_DIE ( a, len ); \ |
| 546 | } |
| 547 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 548 | #endif /* __MAC_SHARED_H */ |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 549 | |
| 550 | /*--------------------------------------------------------------------*/ |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 551 | /*--- end mac_shared.h ---*/ |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 552 | /*--------------------------------------------------------------------*/ |