njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 1 | |
| 2 | /*--------------------------------------------------------------------*/ |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 3 | /*--- Declarations shared between Memcheck and Addrcheck. ---*/ |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 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 | |
njn | 5361242 | 2005-03-12 16:22:54 +0000 | [diff] [blame] | 12 | Copyright (C) 2000-2005 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 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 39 | #define MAC_(str) VGAPPEND(vgMAC_,str) |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 40 | |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 41 | /*------------------------------------------------------------*/ |
| 42 | /*--- Errors and suppressions ---*/ |
| 43 | /*------------------------------------------------------------*/ |
| 44 | |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 45 | /* The classification of a faulting address. */ |
| 46 | typedef |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 47 | enum { |
nethercote | 8b76fe5 | 2004-11-08 19:20:09 +0000 | [diff] [blame] | 48 | Undescribed, // as-yet unclassified |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 49 | Stack, |
nethercote | 8b76fe5 | 2004-11-08 19:20:09 +0000 | [diff] [blame] | 50 | Unknown, // classification yielded nothing useful |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 51 | Freed, Mallocd, |
nethercote | 8b76fe5 | 2004-11-08 19:20:09 +0000 | [diff] [blame] | 52 | UserG, // in a user-defined block |
| 53 | Mempool, // in a mempool |
| 54 | Register, // in a register; for Param errors only |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 55 | } |
| 56 | AddrKind; |
| 57 | |
| 58 | /* Records info about a faulting address. */ |
| 59 | typedef |
nethercote | 05675c8 | 2004-08-04 10:37:49 +0000 | [diff] [blame] | 60 | struct { // Used by: |
| 61 | AddrKind akind; // ALL |
nethercote | 928a5f7 | 2004-11-03 18:10:37 +0000 | [diff] [blame] | 62 | SizeT blksize; // Freed, Mallocd |
nethercote | 8b76fe5 | 2004-11-08 19:20:09 +0000 | [diff] [blame] | 63 | OffT rwoffset; // Freed, Mallocd |
nethercote | 05675c8 | 2004-08-04 10:37:49 +0000 | [diff] [blame] | 64 | ExeContext* lastchange; // Freed, Mallocd |
| 65 | ThreadId stack_tid; // Stack |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 66 | const Char *desc; // UserG |
nethercote | 05675c8 | 2004-08-04 10:37:49 +0000 | [diff] [blame] | 67 | Bool maybe_gcc; // True if just below %esp -- could be a gcc bug. |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 68 | } |
| 69 | AddrInfo; |
| 70 | |
| 71 | typedef |
| 72 | enum { |
nethercote | 05675c8 | 2004-08-04 10:37:49 +0000 | [diff] [blame] | 73 | ParamSupp, // Bad syscall params |
| 74 | CoreMemSupp, // Memory errors in core (pthread ops, signal handling) |
| 75 | |
| 76 | // Use of invalid values of given size (MemCheck only) |
njn | c061666 | 2003-06-12 09:58:41 +0000 | [diff] [blame] | 77 | Value0Supp, Value1Supp, Value2Supp, Value4Supp, Value8Supp, Value16Supp, |
nethercote | 05675c8 | 2004-08-04 10:37:49 +0000 | [diff] [blame] | 78 | |
| 79 | // Invalid read/write attempt at given size |
njn | c061666 | 2003-06-12 09:58:41 +0000 | [diff] [blame] | 80 | Addr1Supp, Addr2Supp, Addr4Supp, Addr8Supp, Addr16Supp, |
nethercote | 05675c8 | 2004-08-04 10:37:49 +0000 | [diff] [blame] | 81 | |
| 82 | FreeSupp, // Invalid or mismatching free |
| 83 | OverlapSupp, // Overlapping blocks in memcpy(), strcpy(), etc |
| 84 | LeakSupp, // Something to be suppressed in a leak check. |
| 85 | MempoolSupp, // Memory pool suppression. |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 86 | } |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 87 | MAC_SuppKind; |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 88 | |
| 89 | /* What kind of error it is. */ |
| 90 | typedef |
| 91 | enum { ValueErr, /* Memcheck only */ |
| 92 | CoreMemErr, |
| 93 | AddrErr, |
| 94 | ParamErr, UserErr, /* behaves like an anonymous ParamErr */ |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 95 | FreeErr, FreeMismatchErr, |
njn | 7201b2a | 2003-08-19 12:16:05 +0000 | [diff] [blame] | 96 | OverlapErr, |
rjwalsh | bc0bb83 | 2004-06-19 18:12:36 +0000 | [diff] [blame] | 97 | LeakErr, |
| 98 | IllegalMempoolErr, |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 99 | } |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 100 | MAC_ErrorKind; |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 101 | |
| 102 | /* What kind of memory access is involved in the error? */ |
| 103 | typedef |
| 104 | enum { ReadAxs, WriteAxs, ExecAxs } |
| 105 | AxsKind; |
| 106 | |
| 107 | /* Extra context for memory errors */ |
| 108 | typedef |
nethercote | 05675c8 | 2004-08-04 10:37:49 +0000 | [diff] [blame] | 109 | struct { // Used by: |
| 110 | AxsKind axskind; // AddrErr |
| 111 | Int size; // AddrErr, ValueErr |
| 112 | AddrInfo addrinfo; // {Addr,Free,FreeMismatch,Param,User}Err |
nethercote | 8b76fe5 | 2004-11-08 19:20:09 +0000 | [diff] [blame] | 113 | Bool isUnaddr; // {CoreMem,Param,User}Err |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 114 | } |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 115 | MAC_Error; |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 116 | |
njn | b6cae9f | 2003-09-04 20:50:47 +0000 | [diff] [blame] | 117 | /* Extra info for overlap errors */ |
| 118 | typedef |
| 119 | struct { |
| 120 | Addr src; |
| 121 | Addr dst; |
| 122 | Int len; // -1 if unused |
| 123 | } |
| 124 | OverlapExtra; |
| 125 | |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 126 | /* For malloc()/new/new[] vs. free()/delete/delete[] mismatch checking. */ |
| 127 | typedef |
| 128 | enum { |
| 129 | MAC_AllocMalloc = 0, |
| 130 | MAC_AllocNew = 1, |
njn | 1078545 | 2003-05-20 16:38:24 +0000 | [diff] [blame] | 131 | MAC_AllocNewVec = 2, |
| 132 | MAC_AllocCustom = 3 |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 133 | } |
| 134 | MAC_AllocKind; |
| 135 | |
| 136 | /* Nb: first two fields must match core's VgHashNode. */ |
| 137 | typedef |
| 138 | struct _MAC_Chunk { |
| 139 | struct _MAC_Chunk* next; |
nethercote | 05675c8 | 2004-08-04 10:37:49 +0000 | [diff] [blame] | 140 | Addr data; // ptr to actual block |
njn | b729e0d | 2004-12-01 00:19:38 +0000 | [diff] [blame] | 141 | SizeT size : (sizeof(UWord)*8)-2; // size requested; 30 or 62 bits |
nethercote | 05675c8 | 2004-08-04 10:37:49 +0000 | [diff] [blame] | 142 | MAC_AllocKind allockind : 2; // which wrapper did the allocation |
| 143 | ExeContext* where; // where it was allocated |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 144 | } |
| 145 | MAC_Chunk; |
| 146 | |
rjwalsh | bc0bb83 | 2004-06-19 18:12:36 +0000 | [diff] [blame] | 147 | /* Memory pool. Nb: first two fields must match core's VgHashNode. */ |
| 148 | typedef |
| 149 | struct _MAC_Mempool { |
| 150 | struct _MAC_Mempool* next; |
nethercote | 05675c8 | 2004-08-04 10:37:49 +0000 | [diff] [blame] | 151 | Addr pool; // pool identifier |
njn | b729e0d | 2004-12-01 00:19:38 +0000 | [diff] [blame] | 152 | SizeT rzB; // pool red-zone size |
nethercote | 05675c8 | 2004-08-04 10:37:49 +0000 | [diff] [blame] | 153 | Bool is_zeroed; // allocations from this pool are zeroed |
| 154 | VgHashTable chunks; // chunks associated with this pool |
rjwalsh | bc0bb83 | 2004-06-19 18:12:36 +0000 | [diff] [blame] | 155 | } |
| 156 | MAC_Mempool; |
| 157 | |
| 158 | |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 159 | /*------------------------------------------------------------*/ |
nethercote | 7cc9c23 | 2004-01-21 15:08:04 +0000 | [diff] [blame] | 160 | /*--- Profiling of tools and memory events ---*/ |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 161 | /*------------------------------------------------------------*/ |
| 162 | |
| 163 | typedef |
| 164 | enum { |
| 165 | VgpCheckMem = VgpFini+1, |
| 166 | VgpSetMem, |
| 167 | VgpESPAdj |
| 168 | } |
nethercote | 7cc9c23 | 2004-01-21 15:08:04 +0000 | [diff] [blame] | 169 | VgpToolCC; |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 170 | |
| 171 | /* Define to collect detailed performance info. */ |
sewardj | 23eb2fd | 2005-04-22 16:29:19 +0000 | [diff] [blame] | 172 | /* #define MAC_PROFILE_MEMORY */ |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 173 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 174 | #ifdef MAC_PROFILE_MEMORY |
sewardj | c1a2cda | 2005-04-21 17:34:00 +0000 | [diff] [blame] | 175 | # define N_PROF_EVENTS 500 |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 176 | |
sewardj | c1a2cda | 2005-04-21 17:34:00 +0000 | [diff] [blame] | 177 | extern UInt MAC_(event_ctr)[N_PROF_EVENTS]; |
| 178 | extern HChar* MAC_(event_ctr_name)[N_PROF_EVENTS]; |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 179 | |
sewardj | c1a2cda | 2005-04-21 17:34:00 +0000 | [diff] [blame] | 180 | # define PROF_EVENT(ev, name) \ |
| 181 | do { tl_assert((ev) >= 0 && (ev) < N_PROF_EVENTS); \ |
| 182 | /* crude and inaccurate check to ensure the same */ \ |
| 183 | /* event isn't being used with > 1 name */ \ |
| 184 | if (MAC_(event_ctr_name)[ev]) \ |
| 185 | tl_assert(name == MAC_(event_ctr_name)[ev]); \ |
| 186 | MAC_(event_ctr)[ev]++; \ |
| 187 | MAC_(event_ctr_name)[ev] = (name); \ |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 188 | } while (False); |
| 189 | |
| 190 | #else |
| 191 | |
sewardj | c1a2cda | 2005-04-21 17:34:00 +0000 | [diff] [blame] | 192 | # define PROF_EVENT(ev, name) /* */ |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 193 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 194 | #endif /* MAC_PROFILE_MEMORY */ |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 195 | |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 196 | |
sewardj | 23eb2fd | 2005-04-22 16:29:19 +0000 | [diff] [blame] | 197 | /*------------------------------------------------------------*/ |
| 198 | /*--- V and A bits (Victoria & Albert ?) ---*/ |
| 199 | /*------------------------------------------------------------*/ |
| 200 | |
| 201 | /* expand 1 bit -> 8 */ |
| 202 | #define BIT_TO_BYTE(b) ((~(((UChar)(b) & 1) - 1)) & 0xFF) |
| 203 | |
sewardj | 05fe85e | 2005-04-27 22:46:36 +0000 | [diff] [blame] | 204 | /* The number of entries in the primary map can be altered. However |
| 205 | we hardwire the assumption that each secondary map covers precisely |
| 206 | 64k of address space. */ |
| 207 | #define SECONDARY_SIZE 65536 /* DO NOT CHANGE */ |
| 208 | #define SECONDARY_MASK (SECONDARY_SIZE-1) /* DO NOT CHANGE */ |
| 209 | |
sewardj | 45d94cc | 2005-04-20 14:44:11 +0000 | [diff] [blame] | 210 | //zz #define SECONDARY_SHIFT 16 |
| 211 | //zz #define SECONDARY_SIZE (1 << SECONDARY_SHIFT) |
| 212 | //zz #define SECONDARY_MASK (SECONDARY_SIZE - 1) |
| 213 | //zz |
| 214 | //zz #define PRIMARY_SIZE (1 << (32 - SECONDARY_SHIFT)) |
| 215 | //zz |
| 216 | //zz #define SM_OFF(addr) ((addr) & SECONDARY_MASK) |
| 217 | //zz #define PM_IDX(addr) ((addr) >> SECONDARY_SHIFT) |
| 218 | /* |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 219 | #define IS_DISTINGUISHED_SM(smap) \ |
| 220 | ((smap) >= &distinguished_secondary_maps[0] && \ |
| 221 | (smap) < &distinguished_secondary_maps[N_SECONDARY_MAPS]) |
| 222 | |
| 223 | #define IS_DISTINGUISHED(addr) (IS_DISTINGUISHED_SM(primary_map[PM_IDX(addr)])) |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 224 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 225 | #define ENSURE_MAPPABLE(addr,caller) \ |
| 226 | do { \ |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 227 | if (IS_DISTINGUISHED(addr)) { \ |
| 228 | primary_map[PM_IDX(addr)] = alloc_secondary_map(caller, primary_map[PM_IDX(addr)]); \ |
sewardj | 45d94cc | 2005-04-20 14:44:11 +0000 | [diff] [blame] | 229 | if (0) VG_(printf)("new 2map because of %p\n", addr); \ |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 230 | } \ |
sewardj | 45d94cc | 2005-04-20 14:44:11 +0000 | [diff] [blame] | 231 | } while(0) |
| 232 | */ |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 233 | |
| 234 | #define BITARR_SET(aaa_p,iii_p) \ |
| 235 | do { \ |
sewardj | 45d94cc | 2005-04-20 14:44:11 +0000 | [diff] [blame] | 236 | UWord iii = (UWord)iii_p; \ |
| 237 | UChar* aaa = (UChar*)aaa_p; \ |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 238 | aaa[iii >> 3] |= (1 << (iii & 7)); \ |
| 239 | } while (0) |
| 240 | |
| 241 | #define BITARR_CLEAR(aaa_p,iii_p) \ |
| 242 | do { \ |
sewardj | 45d94cc | 2005-04-20 14:44:11 +0000 | [diff] [blame] | 243 | UWord iii = (UWord)iii_p; \ |
| 244 | UChar* aaa = (UChar*)aaa_p; \ |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 245 | aaa[iii >> 3] &= ~(1 << (iii & 7)); \ |
| 246 | } while (0) |
| 247 | |
| 248 | #define BITARR_TEST(aaa_p,iii_p) \ |
sewardj | 45d94cc | 2005-04-20 14:44:11 +0000 | [diff] [blame] | 249 | (0 != (((UChar*)aaa_p)[ ((UWord)iii_p) >> 3 ] \ |
| 250 | & (1 << (((UWord)iii_p) & 7)))) \ |
| 251 | |
| 252 | static inline |
| 253 | void write_bit_array ( UChar* arr, UWord idx, UWord bit ) |
| 254 | { |
| 255 | UWord shift = idx & 7; |
| 256 | idx >>= 3; |
| 257 | bit &= 1; |
| 258 | arr[idx] = (arr[idx] & ~(1<<shift)) | (bit << shift); |
| 259 | } |
| 260 | |
| 261 | static inline |
| 262 | UWord read_bit_array ( UChar* arr, UWord idx ) |
| 263 | { |
| 264 | UWord shift = idx & 7; |
| 265 | idx >>= 3; |
| 266 | return 1 & (arr[idx] >> shift); |
| 267 | } |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 268 | |
| 269 | |
sewardj | 45d94cc | 2005-04-20 14:44:11 +0000 | [diff] [blame] | 270 | #define VGM_BIT_VALID 0 |
| 271 | #define VGM_BIT_INVALID 1 |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 272 | |
sewardj | 45d94cc | 2005-04-20 14:44:11 +0000 | [diff] [blame] | 273 | #define VGM_NIBBLE_VALID 0 |
| 274 | #define VGM_NIBBLE_INVALID 0xF |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 275 | |
sewardj | 45d94cc | 2005-04-20 14:44:11 +0000 | [diff] [blame] | 276 | #define VGM_BYTE_VALID 0 |
| 277 | #define VGM_BYTE_INVALID 0xFF |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 278 | |
sewardj | 45d94cc | 2005-04-20 14:44:11 +0000 | [diff] [blame] | 279 | #define VGM_WORD32_VALID 0 |
| 280 | #define VGM_WORD32_INVALID 0xFFFFFFFF |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 281 | |
sewardj | 45d94cc | 2005-04-20 14:44:11 +0000 | [diff] [blame] | 282 | #define VGM_WORD64_VALID 0ULL |
| 283 | #define VGM_WORD64_INVALID 0xFFFFFFFFFFFFFFFFULL |
| 284 | |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 285 | |
| 286 | /*------------------------------------------------------------*/ |
| 287 | /*--- Command line options + defaults ---*/ |
| 288 | /*------------------------------------------------------------*/ |
| 289 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 290 | /* Memcheck defines a couple more. */ |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 291 | |
| 292 | /* Allow loads from partially-valid addresses? default: YES */ |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 293 | extern Bool MAC_(clo_partial_loads_ok); |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 294 | |
| 295 | /* Max volume of the freed blocks queue. */ |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 296 | extern Int MAC_(clo_freelist_vol); |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 297 | |
| 298 | /* Do leak check at exit? default: NO */ |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 299 | typedef |
| 300 | enum { |
| 301 | LC_Off, |
| 302 | LC_Summary, |
| 303 | LC_Full, |
| 304 | } |
| 305 | LeakCheckMode; |
| 306 | |
| 307 | extern LeakCheckMode MAC_(clo_leak_check); |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 308 | |
| 309 | /* How closely should we compare ExeContexts in leak records? default: 2 */ |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 310 | extern VgRes MAC_(clo_leak_resolution); |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 311 | |
| 312 | /* In leak check, show reachable-but-not-freed blocks? default: NO */ |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 313 | extern Bool MAC_(clo_show_reachable); |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 314 | |
| 315 | /* Assume accesses immediately below %esp are due to gcc-2.96 bugs. |
| 316 | * default: NO*/ |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 317 | extern Bool MAC_(clo_workaround_gcc296_bugs); |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 318 | |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 319 | extern Bool MAC_(process_common_cmd_line_option) ( Char* arg ); |
| 320 | extern void MAC_(print_common_usage) ( void ); |
| 321 | extern void MAC_(print_common_debug_usage) ( void ); |
| 322 | |
njn | 8a97c6d | 2005-03-31 04:37:24 +0000 | [diff] [blame] | 323 | /* We want a 16B redzone on heap blocks for Addrcheck and Memcheck */ |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 324 | #define MAC_MALLOC_REDZONE_SZB 16 |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 325 | |
| 326 | /*------------------------------------------------------------*/ |
| 327 | /*--- Variables ---*/ |
| 328 | /*------------------------------------------------------------*/ |
| 329 | |
| 330 | /* For tracking malloc'd blocks */ |
| 331 | extern VgHashTable MAC_(malloc_list); |
| 332 | |
rjwalsh | bc0bb83 | 2004-06-19 18:12:36 +0000 | [diff] [blame] | 333 | /* For tracking memory pools. */ |
| 334 | extern VgHashTable MAC_(mempool_list); |
| 335 | |
nethercote | 7cc9c23 | 2004-01-21 15:08:04 +0000 | [diff] [blame] | 336 | /* Function pointers for the two tools to track interesting events. */ |
nethercote | 451eae9 | 2004-11-02 13:06:32 +0000 | [diff] [blame] | 337 | extern void (*MAC_(new_mem_heap)) ( Addr a, SizeT len, Bool is_inited ); |
| 338 | extern void (*MAC_(ban_mem_heap)) ( Addr a, SizeT len ); |
| 339 | extern void (*MAC_(die_mem_heap)) ( Addr a, SizeT len ); |
| 340 | extern void (*MAC_(copy_mem_heap))( Addr from, Addr to, SizeT len ); |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 341 | |
sewardj | ecf8e10 | 2003-07-12 12:11:39 +0000 | [diff] [blame] | 342 | /* Function pointers for internal sanity checking. */ |
nethercote | 451eae9 | 2004-11-02 13:06:32 +0000 | [diff] [blame] | 343 | extern Bool (*MAC_(check_noaccess))( Addr a, SizeT len, Addr* bad_addr ); |
sewardj | ecf8e10 | 2003-07-12 12:11:39 +0000 | [diff] [blame] | 344 | |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 345 | /* Used in describe_addr() */ |
| 346 | extern Bool (*MAC_(describe_addr_supp)) ( Addr a, AddrInfo* ai ); |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 347 | |
njn | 47363ab | 2003-04-21 13:24:40 +0000 | [diff] [blame] | 348 | /* For VALGRIND_COUNT_LEAKS client request */ |
njn | e8b5c05 | 2003-07-22 22:03:58 +0000 | [diff] [blame] | 349 | extern Int MAC_(bytes_leaked); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 350 | extern Int MAC_(bytes_indirect); |
njn | e8b5c05 | 2003-07-22 22:03:58 +0000 | [diff] [blame] | 351 | extern Int MAC_(bytes_dubious); |
| 352 | extern Int MAC_(bytes_reachable); |
| 353 | extern Int MAC_(bytes_suppressed); |
sewardj | 99aac97 | 2002-12-26 01:53:45 +0000 | [diff] [blame] | 354 | |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 355 | /*------------------------------------------------------------*/ |
| 356 | /*--- Functions ---*/ |
| 357 | /*------------------------------------------------------------*/ |
| 358 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 359 | extern void MAC_(pp_AddrInfo) ( Addr a, AddrInfo* ai ); |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 360 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 361 | extern void MAC_(clear_MAC_Error) ( MAC_Error* err_extra ); |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 362 | |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 363 | extern Bool MAC_(eq_Error) ( VgRes res, Error* e1, Error* e2 ); |
| 364 | extern UInt MAC_(update_extra)( Error* err ); |
| 365 | extern Bool MAC_(read_extra_suppression_info) ( Int fd, Char* buf, Int nBuf, Supp *su ); |
| 366 | extern Bool MAC_(error_matches_suppression)(Error* err, Supp* su); |
| 367 | extern Char* MAC_(get_error_name) ( Error* err ); |
| 368 | extern void MAC_(print_extra_suppression_info) ( Error* err ); |
| 369 | |
| 370 | extern Bool MAC_(shared_recognised_suppression) ( Char* name, Supp* su ); |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 371 | |
sewardj | 2a99cf6 | 2004-11-24 10:44:19 +0000 | [diff] [blame] | 372 | extern void* MAC_(new_block) ( ThreadId tid, |
| 373 | Addr p, SizeT size, SizeT align, UInt rzB, |
nethercote | 57e36b3 | 2004-07-10 14:56:28 +0000 | [diff] [blame] | 374 | Bool is_zeroed, MAC_AllocKind kind, |
| 375 | VgHashTable table); |
sewardj | 2a99cf6 | 2004-11-24 10:44:19 +0000 | [diff] [blame] | 376 | |
| 377 | extern void MAC_(handle_free) ( ThreadId tid, |
| 378 | Addr p, UInt rzB, MAC_AllocKind kind ); |
njn | 1078545 | 2003-05-20 16:38:24 +0000 | [diff] [blame] | 379 | |
rjwalsh | bc0bb83 | 2004-06-19 18:12:36 +0000 | [diff] [blame] | 380 | extern void MAC_(create_mempool)(Addr pool, UInt rzB, Bool is_zeroed); |
sewardj | 2a99cf6 | 2004-11-24 10:44:19 +0000 | [diff] [blame] | 381 | |
rjwalsh | bc0bb83 | 2004-06-19 18:12:36 +0000 | [diff] [blame] | 382 | extern void MAC_(destroy_mempool)(Addr pool); |
sewardj | 2a99cf6 | 2004-11-24 10:44:19 +0000 | [diff] [blame] | 383 | |
| 384 | extern void MAC_(mempool_alloc)(ThreadId tid, |
| 385 | Addr pool, Addr addr, SizeT size); |
| 386 | |
rjwalsh | bc0bb83 | 2004-06-19 18:12:36 +0000 | [diff] [blame] | 387 | extern void MAC_(mempool_free)(Addr pool, Addr addr); |
| 388 | |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 389 | extern void MAC_(record_address_error) ( ThreadId tid, Addr a, |
sewardj | af48a60 | 2003-07-06 00:54:47 +0000 | [diff] [blame] | 390 | Int size, Bool isWrite ); |
nethercote | 8b76fe5 | 2004-11-08 19:20:09 +0000 | [diff] [blame] | 391 | extern void MAC_(record_core_mem_error) ( ThreadId tid, Bool isUnaddr, |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 392 | Char* s ); |
nethercote | 8b76fe5 | 2004-11-08 19:20:09 +0000 | [diff] [blame] | 393 | extern void MAC_(record_param_error) ( ThreadId tid, Addr a, Bool isReg, |
| 394 | Bool isUnaddr, Char* msg ); |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 395 | extern void MAC_(record_jump_error) ( ThreadId tid, Addr a ); |
| 396 | extern void MAC_(record_free_error) ( ThreadId tid, Addr a ); |
| 397 | extern void MAC_(record_freemismatch_error)( ThreadId tid, Addr a ); |
sewardj | 2a99cf6 | 2004-11-24 10:44:19 +0000 | [diff] [blame] | 398 | extern void MAC_(record_overlap_error) ( ThreadId tid, |
| 399 | Char* function, OverlapExtra* oe ); |
rjwalsh | bc0bb83 | 2004-06-19 18:12:36 +0000 | [diff] [blame] | 400 | extern void MAC_(record_illegal_mempool_error) ( ThreadId tid, Addr pool ); |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 401 | |
njn | b126f73 | 2004-11-22 17:57:07 +0000 | [diff] [blame] | 402 | extern void MAC_(pp_shared_Error) ( Error* err); |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 403 | |
thughes | 4ad52d0 | 2004-06-27 17:37:21 +0000 | [diff] [blame] | 404 | extern MAC_Chunk* MAC_(first_matching_freed_MAC_Chunk)( Bool (*p)(MAC_Chunk*, void*), void* d ); |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 405 | |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 406 | extern void MAC_(common_pre_clo_init) ( void ); |
njn | b8dca86 | 2005-03-14 02:42:44 +0000 | [diff] [blame] | 407 | extern void MAC_(common_fini) ( void (*leak_check)(ThreadId tid, |
| 408 | LeakCheckMode mode) ); |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 409 | |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 410 | extern Bool MAC_(handle_common_client_requests) ( ThreadId tid, |
nethercote | d1b64b2 | 2004-11-04 18:22:28 +0000 | [diff] [blame] | 411 | UWord* arg_block, UWord* ret ); |
njn | 47363ab | 2003-04-21 13:24:40 +0000 | [diff] [blame] | 412 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 413 | /* For leak checking */ |
njn | 0297703 | 2005-05-17 04:00:11 +0000 | [diff] [blame] | 414 | extern void MAC_(pp_LeakError)(void* extra); |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 415 | |
njn | 86f12dc | 2005-03-14 01:16:05 +0000 | [diff] [blame] | 416 | extern void MAC_(print_malloc_stats) ( void ); |
| 417 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 418 | extern void MAC_(do_detect_memory_leaks) ( |
njn | b8dca86 | 2005-03-14 02:42:44 +0000 | [diff] [blame] | 419 | ThreadId tid, LeakCheckMode mode, |
sewardj | 05fe85e | 2005-04-27 22:46:36 +0000 | [diff] [blame] | 420 | Bool (*is_within_valid_secondary) ( Addr ), |
| 421 | Bool (*is_valid_aligned_word) ( Addr ) |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 422 | ); |
| 423 | |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 424 | extern VG_REGPARM(1) void MAC_(new_mem_stack_4) ( Addr old_ESP ); |
| 425 | extern VG_REGPARM(1) void MAC_(die_mem_stack_4) ( Addr old_ESP ); |
| 426 | extern VG_REGPARM(1) void MAC_(new_mem_stack_8) ( Addr old_ESP ); |
| 427 | extern VG_REGPARM(1) void MAC_(die_mem_stack_8) ( Addr old_ESP ); |
| 428 | extern VG_REGPARM(1) void MAC_(new_mem_stack_12) ( Addr old_ESP ); |
| 429 | extern VG_REGPARM(1) void MAC_(die_mem_stack_12) ( Addr old_ESP ); |
| 430 | extern VG_REGPARM(1) void MAC_(new_mem_stack_16) ( Addr old_ESP ); |
| 431 | extern VG_REGPARM(1) void MAC_(die_mem_stack_16) ( Addr old_ESP ); |
| 432 | extern VG_REGPARM(1) void MAC_(new_mem_stack_32) ( Addr old_ESP ); |
| 433 | extern VG_REGPARM(1) void MAC_(die_mem_stack_32) ( Addr old_ESP ); |
| 434 | extern void MAC_(die_mem_stack) ( Addr a, SizeT len); |
| 435 | extern void MAC_(new_mem_stack) ( Addr a, SizeT len); |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 436 | |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 437 | extern void* MAC_(malloc) ( ThreadId tid, SizeT n ); |
| 438 | extern void* MAC_(__builtin_new) ( ThreadId tid, SizeT n ); |
| 439 | extern void* MAC_(__builtin_vec_new) ( ThreadId tid, SizeT n ); |
| 440 | extern void* MAC_(memalign) ( ThreadId tid, SizeT align, SizeT n ); |
| 441 | extern void* MAC_(calloc) ( ThreadId tid, SizeT nmemb, SizeT size1 ); |
| 442 | extern void MAC_(free) ( ThreadId tid, void* p ); |
| 443 | extern void MAC_(__builtin_delete) ( ThreadId tid, void* p ); |
| 444 | extern void MAC_(__builtin_vec_delete) ( ThreadId tid, void* p ); |
| 445 | extern void* MAC_(realloc) ( ThreadId tid, void* p, SizeT new_size ); |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 446 | |
| 447 | /*------------------------------------------------------------*/ |
| 448 | /*--- Stack pointer adjustment ---*/ |
| 449 | /*------------------------------------------------------------*/ |
| 450 | |
| 451 | /* Some noble preprocessor abuse, to enable Memcheck and Addrcheck to |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 452 | share this code, but call different functions. |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 453 | |
| 454 | Note that this code is executed very frequently and must be highly |
| 455 | optimised, which is why I resort to the preprocessor to achieve the |
sewardj | 45d94cc | 2005-04-20 14:44:11 +0000 | [diff] [blame] | 456 | factoring, rather than eg. using function pointers. |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 457 | */ |
| 458 | |
sewardj | 045a405 | 2005-04-23 22:42:27 +0000 | [diff] [blame] | 459 | #define SP_UPDATE_HANDLERS(ALIGNED4_NEW, ALIGNED4_DIE, \ |
| 460 | ALIGNED8_NEW, ALIGNED8_DIE, \ |
| 461 | UNALIGNED_NEW, UNALIGNED_DIE) \ |
| 462 | \ |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 463 | void VG_REGPARM(1) MAC_(new_mem_stack_4)(Addr new_SP) \ |
sewardj | 045a405 | 2005-04-23 22:42:27 +0000 | [diff] [blame] | 464 | { \ |
| 465 | PROF_EVENT(110, "new_mem_stack_4"); \ |
| 466 | if (VG_IS_4_ALIGNED(new_SP)) { \ |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 467 | ALIGNED4_NEW ( -VG_STACK_REDZONE_SZB + new_SP ); \ |
sewardj | 045a405 | 2005-04-23 22:42:27 +0000 | [diff] [blame] | 468 | } else { \ |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 469 | UNALIGNED_NEW ( -VG_STACK_REDZONE_SZB + new_SP, 4 ); \ |
sewardj | 045a405 | 2005-04-23 22:42:27 +0000 | [diff] [blame] | 470 | } \ |
| 471 | } \ |
| 472 | \ |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 473 | void VG_REGPARM(1) MAC_(die_mem_stack_4)(Addr new_SP) \ |
sewardj | 045a405 | 2005-04-23 22:42:27 +0000 | [diff] [blame] | 474 | { \ |
| 475 | PROF_EVENT(120, "die_mem_stack_4"); \ |
| 476 | if (VG_IS_4_ALIGNED(new_SP)) { \ |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 477 | ALIGNED4_DIE ( -VG_STACK_REDZONE_SZB + new_SP-4 ); \ |
sewardj | 045a405 | 2005-04-23 22:42:27 +0000 | [diff] [blame] | 478 | } else { \ |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 479 | UNALIGNED_DIE ( -VG_STACK_REDZONE_SZB + new_SP-4, 4 ); \ |
sewardj | 045a405 | 2005-04-23 22:42:27 +0000 | [diff] [blame] | 480 | } \ |
| 481 | } \ |
| 482 | \ |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 483 | void VG_REGPARM(1) MAC_(new_mem_stack_8)(Addr new_SP) \ |
sewardj | 045a405 | 2005-04-23 22:42:27 +0000 | [diff] [blame] | 484 | { \ |
| 485 | PROF_EVENT(111, "new_mem_stack_8"); \ |
| 486 | if (VG_IS_8_ALIGNED(new_SP)) { \ |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 487 | ALIGNED8_NEW ( -VG_STACK_REDZONE_SZB + new_SP ); \ |
sewardj | 045a405 | 2005-04-23 22:42:27 +0000 | [diff] [blame] | 488 | } else if (VG_IS_4_ALIGNED(new_SP)) { \ |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 489 | ALIGNED4_NEW ( -VG_STACK_REDZONE_SZB + new_SP ); \ |
| 490 | ALIGNED4_NEW ( -VG_STACK_REDZONE_SZB + new_SP+4 ); \ |
sewardj | 045a405 | 2005-04-23 22:42:27 +0000 | [diff] [blame] | 491 | } else { \ |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 492 | UNALIGNED_NEW ( -VG_STACK_REDZONE_SZB + new_SP, 8 ); \ |
sewardj | 045a405 | 2005-04-23 22:42:27 +0000 | [diff] [blame] | 493 | } \ |
| 494 | } \ |
| 495 | \ |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 496 | void VG_REGPARM(1) MAC_(die_mem_stack_8)(Addr new_SP) \ |
sewardj | 045a405 | 2005-04-23 22:42:27 +0000 | [diff] [blame] | 497 | { \ |
| 498 | PROF_EVENT(121, "die_mem_stack_8"); \ |
| 499 | if (VG_IS_8_ALIGNED(new_SP)) { \ |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 500 | ALIGNED8_DIE ( -VG_STACK_REDZONE_SZB + new_SP-8 ); \ |
sewardj | 045a405 | 2005-04-23 22:42:27 +0000 | [diff] [blame] | 501 | } else if (VG_IS_4_ALIGNED(new_SP)) { \ |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 502 | ALIGNED4_DIE ( -VG_STACK_REDZONE_SZB + new_SP-8 ); \ |
| 503 | ALIGNED4_DIE ( -VG_STACK_REDZONE_SZB + new_SP-4 ); \ |
sewardj | 045a405 | 2005-04-23 22:42:27 +0000 | [diff] [blame] | 504 | } else { \ |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 505 | UNALIGNED_DIE ( -VG_STACK_REDZONE_SZB + new_SP-8, 8 ); \ |
sewardj | 045a405 | 2005-04-23 22:42:27 +0000 | [diff] [blame] | 506 | } \ |
| 507 | } \ |
| 508 | \ |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 509 | void VG_REGPARM(1) MAC_(new_mem_stack_12)(Addr new_SP) \ |
sewardj | 045a405 | 2005-04-23 22:42:27 +0000 | [diff] [blame] | 510 | { \ |
| 511 | PROF_EVENT(112, "new_mem_stack_12"); \ |
| 512 | if (VG_IS_8_ALIGNED(new_SP)) { \ |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 513 | ALIGNED8_NEW ( -VG_STACK_REDZONE_SZB + new_SP ); \ |
| 514 | ALIGNED4_NEW ( -VG_STACK_REDZONE_SZB + new_SP+8 ); \ |
sewardj | 045a405 | 2005-04-23 22:42:27 +0000 | [diff] [blame] | 515 | } else if (VG_IS_4_ALIGNED(new_SP)) { \ |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 516 | ALIGNED4_NEW ( -VG_STACK_REDZONE_SZB + new_SP ); \ |
| 517 | ALIGNED8_NEW ( -VG_STACK_REDZONE_SZB + new_SP+4 ); \ |
sewardj | 045a405 | 2005-04-23 22:42:27 +0000 | [diff] [blame] | 518 | } else { \ |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 519 | UNALIGNED_NEW ( -VG_STACK_REDZONE_SZB + new_SP, 12 ); \ |
sewardj | 045a405 | 2005-04-23 22:42:27 +0000 | [diff] [blame] | 520 | } \ |
| 521 | } \ |
| 522 | \ |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 523 | void VG_REGPARM(1) MAC_(die_mem_stack_12)(Addr new_SP) \ |
sewardj | 045a405 | 2005-04-23 22:42:27 +0000 | [diff] [blame] | 524 | { \ |
| 525 | PROF_EVENT(122, "die_mem_stack_12"); \ |
| 526 | /* Note the -12 in the test */ \ |
| 527 | if (VG_IS_8_ALIGNED(new_SP-12)) { \ |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 528 | ALIGNED8_DIE ( -VG_STACK_REDZONE_SZB + new_SP-12 ); \ |
| 529 | ALIGNED4_DIE ( -VG_STACK_REDZONE_SZB + new_SP-4 ); \ |
sewardj | 045a405 | 2005-04-23 22:42:27 +0000 | [diff] [blame] | 530 | } else if (VG_IS_4_ALIGNED(new_SP)) { \ |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 531 | ALIGNED4_DIE ( -VG_STACK_REDZONE_SZB + new_SP-12 ); \ |
| 532 | ALIGNED8_DIE ( -VG_STACK_REDZONE_SZB + new_SP-8 ); \ |
sewardj | 045a405 | 2005-04-23 22:42:27 +0000 | [diff] [blame] | 533 | } else { \ |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 534 | UNALIGNED_DIE ( -VG_STACK_REDZONE_SZB + new_SP-12, 12 ); \ |
sewardj | 045a405 | 2005-04-23 22:42:27 +0000 | [diff] [blame] | 535 | } \ |
| 536 | } \ |
| 537 | \ |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 538 | void VG_REGPARM(1) MAC_(new_mem_stack_16)(Addr new_SP) \ |
sewardj | 045a405 | 2005-04-23 22:42:27 +0000 | [diff] [blame] | 539 | { \ |
| 540 | PROF_EVENT(113, "new_mem_stack_16"); \ |
| 541 | if (VG_IS_8_ALIGNED(new_SP)) { \ |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 542 | ALIGNED8_NEW ( -VG_STACK_REDZONE_SZB + new_SP ); \ |
| 543 | ALIGNED8_NEW ( -VG_STACK_REDZONE_SZB + new_SP+8 ); \ |
sewardj | 045a405 | 2005-04-23 22:42:27 +0000 | [diff] [blame] | 544 | } else if (VG_IS_4_ALIGNED(new_SP)) { \ |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 545 | ALIGNED4_NEW ( -VG_STACK_REDZONE_SZB + new_SP ); \ |
| 546 | ALIGNED8_NEW ( -VG_STACK_REDZONE_SZB + new_SP+4 ); \ |
| 547 | ALIGNED4_NEW ( -VG_STACK_REDZONE_SZB + new_SP+12 ); \ |
sewardj | 045a405 | 2005-04-23 22:42:27 +0000 | [diff] [blame] | 548 | } else { \ |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 549 | UNALIGNED_NEW ( -VG_STACK_REDZONE_SZB + new_SP, 16 ); \ |
sewardj | 045a405 | 2005-04-23 22:42:27 +0000 | [diff] [blame] | 550 | } \ |
| 551 | } \ |
| 552 | \ |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 553 | void VG_REGPARM(1) MAC_(die_mem_stack_16)(Addr new_SP) \ |
sewardj | 045a405 | 2005-04-23 22:42:27 +0000 | [diff] [blame] | 554 | { \ |
| 555 | PROF_EVENT(123, "die_mem_stack_16"); \ |
| 556 | if (VG_IS_8_ALIGNED(new_SP)) { \ |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 557 | ALIGNED8_DIE ( -VG_STACK_REDZONE_SZB + new_SP-16 ); \ |
| 558 | ALIGNED8_DIE ( -VG_STACK_REDZONE_SZB + new_SP-8 ); \ |
sewardj | 045a405 | 2005-04-23 22:42:27 +0000 | [diff] [blame] | 559 | } else if (VG_IS_4_ALIGNED(new_SP)) { \ |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 560 | ALIGNED4_DIE ( -VG_STACK_REDZONE_SZB + new_SP-16 ); \ |
| 561 | ALIGNED8_DIE ( -VG_STACK_REDZONE_SZB + new_SP-12 ); \ |
| 562 | ALIGNED4_DIE ( -VG_STACK_REDZONE_SZB + new_SP-4 ); \ |
sewardj | 045a405 | 2005-04-23 22:42:27 +0000 | [diff] [blame] | 563 | } else { \ |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 564 | UNALIGNED_DIE ( -VG_STACK_REDZONE_SZB + new_SP-16, 16 ); \ |
sewardj | 045a405 | 2005-04-23 22:42:27 +0000 | [diff] [blame] | 565 | } \ |
| 566 | } \ |
| 567 | \ |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 568 | void VG_REGPARM(1) MAC_(new_mem_stack_32)(Addr new_SP) \ |
sewardj | 045a405 | 2005-04-23 22:42:27 +0000 | [diff] [blame] | 569 | { \ |
| 570 | PROF_EVENT(114, "new_mem_stack_32"); \ |
| 571 | if (VG_IS_8_ALIGNED(new_SP)) { \ |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 572 | ALIGNED8_NEW ( -VG_STACK_REDZONE_SZB + new_SP ); \ |
| 573 | ALIGNED8_NEW ( -VG_STACK_REDZONE_SZB + new_SP+8 ); \ |
| 574 | ALIGNED8_NEW ( -VG_STACK_REDZONE_SZB + new_SP+16 ); \ |
| 575 | ALIGNED8_NEW ( -VG_STACK_REDZONE_SZB + new_SP+24 ); \ |
sewardj | 045a405 | 2005-04-23 22:42:27 +0000 | [diff] [blame] | 576 | } else if (VG_IS_4_ALIGNED(new_SP)) { \ |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 577 | ALIGNED4_NEW ( -VG_STACK_REDZONE_SZB + new_SP ); \ |
| 578 | ALIGNED8_NEW ( -VG_STACK_REDZONE_SZB + new_SP+4 ); \ |
| 579 | ALIGNED8_NEW ( -VG_STACK_REDZONE_SZB + new_SP+12 ); \ |
| 580 | ALIGNED8_NEW ( -VG_STACK_REDZONE_SZB + new_SP+20 ); \ |
| 581 | ALIGNED4_NEW ( -VG_STACK_REDZONE_SZB + new_SP+28 ); \ |
sewardj | 045a405 | 2005-04-23 22:42:27 +0000 | [diff] [blame] | 582 | } else { \ |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 583 | UNALIGNED_NEW ( -VG_STACK_REDZONE_SZB + new_SP, 32 ); \ |
sewardj | 045a405 | 2005-04-23 22:42:27 +0000 | [diff] [blame] | 584 | } \ |
| 585 | } \ |
| 586 | \ |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 587 | void VG_REGPARM(1) MAC_(die_mem_stack_32)(Addr new_SP) \ |
sewardj | 045a405 | 2005-04-23 22:42:27 +0000 | [diff] [blame] | 588 | { \ |
| 589 | PROF_EVENT(124, "die_mem_stack_32"); \ |
| 590 | if (VG_IS_8_ALIGNED(new_SP)) { \ |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 591 | ALIGNED8_DIE ( -VG_STACK_REDZONE_SZB + new_SP-32 ); \ |
| 592 | ALIGNED8_DIE ( -VG_STACK_REDZONE_SZB + new_SP-24 ); \ |
| 593 | ALIGNED8_DIE ( -VG_STACK_REDZONE_SZB + new_SP-16 ); \ |
| 594 | ALIGNED8_DIE ( -VG_STACK_REDZONE_SZB + new_SP- 8 ); \ |
sewardj | 045a405 | 2005-04-23 22:42:27 +0000 | [diff] [blame] | 595 | } else if (VG_IS_4_ALIGNED(new_SP)) { \ |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 596 | ALIGNED4_DIE ( -VG_STACK_REDZONE_SZB + new_SP-32 ); \ |
| 597 | ALIGNED8_DIE ( -VG_STACK_REDZONE_SZB + new_SP-28 ); \ |
| 598 | ALIGNED8_DIE ( -VG_STACK_REDZONE_SZB + new_SP-20 ); \ |
| 599 | ALIGNED8_DIE ( -VG_STACK_REDZONE_SZB + new_SP-12 ); \ |
| 600 | ALIGNED4_DIE ( -VG_STACK_REDZONE_SZB + new_SP-4 ); \ |
sewardj | 045a405 | 2005-04-23 22:42:27 +0000 | [diff] [blame] | 601 | } else { \ |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 602 | UNALIGNED_DIE ( -VG_STACK_REDZONE_SZB + new_SP-32, 32 ); \ |
sewardj | 045a405 | 2005-04-23 22:42:27 +0000 | [diff] [blame] | 603 | } \ |
| 604 | } \ |
| 605 | \ |
| 606 | void MAC_(new_mem_stack) ( Addr a, SizeT len ) \ |
| 607 | { \ |
| 608 | PROF_EVENT(115, "new_mem_stack"); \ |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 609 | UNALIGNED_NEW ( -VG_STACK_REDZONE_SZB + a, len ); \ |
sewardj | 045a405 | 2005-04-23 22:42:27 +0000 | [diff] [blame] | 610 | } \ |
| 611 | \ |
| 612 | void MAC_(die_mem_stack) ( Addr a, SizeT len ) \ |
| 613 | { \ |
| 614 | PROF_EVENT(125, "die_mem_stack"); \ |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 615 | UNALIGNED_DIE ( -VG_STACK_REDZONE_SZB + a, len ); \ |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 616 | } |
| 617 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 618 | #endif /* __MAC_SHARED_H */ |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 619 | |
| 620 | /*--------------------------------------------------------------------*/ |
njn | c7561b9 | 2005-06-19 01:24:32 +0000 | [diff] [blame] | 621 | /*--- end ---*/ |
njn | 5c004e4 | 2002-11-18 11:04:50 +0000 | [diff] [blame] | 622 | /*--------------------------------------------------------------------*/ |