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