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