blob: d574203b955992374a429901c339de86c6d6b7c3 [file] [log] [blame]
njn5c004e42002-11-18 11:04:50 +00001
2/*--------------------------------------------------------------------*/
njn43c799e2003-04-08 00:08:52 +00003/*--- Declarations shared between MemCheck and AddrCheck. ---*/
4/*--- mac_shared.h ---*/
njn5c004e42002-11-18 11:04:50 +00005/*--------------------------------------------------------------------*/
6
7/*
nethercote137bc552003-11-14 17:47:54 +00008 This file is part of MemCheck, a heavyweight Valgrind tool for
9 detecting memory errors, and AddrCheck, a lightweight Valgrind tool
njn5c004e42002-11-18 11:04:50 +000010 for detecting memory errors.
11
nethercotebb1c9912004-01-04 16:43:23 +000012 Copyright (C) 2000-2004 Julian Seward
njn5c004e42002-11-18 11:04:50 +000013 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
njn43c799e2003-04-08 00:08:52 +000033/* 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
njn5c004e42002-11-18 11:04:50 +000038
39#include "vg_skin.h"
njn43c799e2003-04-08 00:08:52 +000040
41#define MAC_(str) VGAPPEND(vgMAC_,str)
njn5c004e42002-11-18 11:04:50 +000042
njn9b007f62003-04-07 14:40:25 +000043/*------------------------------------------------------------*/
44/*--- Errors and suppressions ---*/
45/*------------------------------------------------------------*/
46
njn5c004e42002-11-18 11:04:50 +000047/* The classification of a faulting address. */
48typedef
njn43c799e2003-04-08 00:08:52 +000049 enum {
50 Undescribed, /* as-yet unclassified */
51 Stack,
52 Unknown, /* classification yielded nothing useful */
53 Freed, Mallocd,
rjwalshbc0bb832004-06-19 18:12:36 +000054 UserG, /* in a user-defined block; Addrcheck & Memcheck only */
55 Mempool, /* in a mempool; Addrcheck & Memcheck only */
njn5c004e42002-11-18 11:04:50 +000056 }
57 AddrKind;
58
59/* Records info about a faulting address. */
60typedef
61 struct {
62 /* ALL */
63 AddrKind akind;
64 /* Freed, Mallocd */
65 Int blksize;
66 /* Freed, Mallocd */
67 Int rwoffset;
68 /* Freed, Mallocd */
69 ExeContext* lastchange;
70 /* Stack */
71 ThreadId stack_tid;
72 /* True if is just-below %esp -- could be a gcc bug. */
73 Bool maybe_gcc;
74 }
75 AddrInfo;
76
77typedef
78 enum {
79 /* Bad syscall params */
80 ParamSupp,
81 /* Memory errors in core (pthread ops, signal handling) */
82 CoreMemSupp,
83 /* Use of invalid values of given size (MemCheck only) */
njnc0616662003-06-12 09:58:41 +000084 Value0Supp, Value1Supp, Value2Supp, Value4Supp, Value8Supp, Value16Supp,
njn5c004e42002-11-18 11:04:50 +000085 /* Invalid read/write attempt at given size */
njnc0616662003-06-12 09:58:41 +000086 Addr1Supp, Addr2Supp, Addr4Supp, Addr8Supp, Addr16Supp,
njn5c004e42002-11-18 11:04:50 +000087 /* Invalid or mismatching free */
sewardj99aac972002-12-26 01:53:45 +000088 FreeSupp,
njn34419c12003-05-02 17:24:29 +000089 /* Overlapping blocks in memcpy(), strcpy(), etc */
90 OverlapSupp,
sewardj99aac972002-12-26 01:53:45 +000091 /* Something to be suppressed in a leak check. */
rjwalshbc0bb832004-06-19 18:12:36 +000092 LeakSupp,
93 /* Memory pool suppression. */
94 MempoolSupp,
njn5c004e42002-11-18 11:04:50 +000095 }
njn43c799e2003-04-08 00:08:52 +000096 MAC_SuppKind;
njn5c004e42002-11-18 11:04:50 +000097
98/* What kind of error it is. */
99typedef
100 enum { ValueErr, /* Memcheck only */
101 CoreMemErr,
102 AddrErr,
103 ParamErr, UserErr, /* behaves like an anonymous ParamErr */
njn43c799e2003-04-08 00:08:52 +0000104 FreeErr, FreeMismatchErr,
njn7201b2a2003-08-19 12:16:05 +0000105 OverlapErr,
rjwalshbc0bb832004-06-19 18:12:36 +0000106 LeakErr,
107 IllegalMempoolErr,
njn5c004e42002-11-18 11:04:50 +0000108 }
njn43c799e2003-04-08 00:08:52 +0000109 MAC_ErrorKind;
njn5c004e42002-11-18 11:04:50 +0000110
111/* What kind of memory access is involved in the error? */
112typedef
113 enum { ReadAxs, WriteAxs, ExecAxs }
114 AxsKind;
115
116/* Extra context for memory errors */
117typedef
118 struct {
119 /* AddrErr */
120 AxsKind axskind;
121 /* AddrErr, ValueErr */
122 Int size;
123 /* AddrErr, FreeErr, FreeMismatchErr, ParamErr, UserErr */
124 AddrInfo addrinfo;
125 /* ParamErr, UserErr, CoreMemErr */
126 Bool isWrite;
127 }
njn43c799e2003-04-08 00:08:52 +0000128 MAC_Error;
njn5c004e42002-11-18 11:04:50 +0000129
njnb6cae9f2003-09-04 20:50:47 +0000130/* Extra info for overlap errors */
131typedef
132 struct {
133 Addr src;
134 Addr dst;
135 Int len; // -1 if unused
136 }
137 OverlapExtra;
138
njn3e884182003-04-15 13:03:23 +0000139/* For malloc()/new/new[] vs. free()/delete/delete[] mismatch checking. */
140typedef
141 enum {
142 MAC_AllocMalloc = 0,
143 MAC_AllocNew = 1,
njn10785452003-05-20 16:38:24 +0000144 MAC_AllocNewVec = 2,
145 MAC_AllocCustom = 3
njn3e884182003-04-15 13:03:23 +0000146 }
147 MAC_AllocKind;
148
149/* Nb: first two fields must match core's VgHashNode. */
150typedef
151 struct _MAC_Chunk {
152 struct _MAC_Chunk* next;
153 Addr data; /* ptr to actual block */
154 UInt size : 30; /* size requested */
155 MAC_AllocKind allockind : 2; /* which wrapper did the allocation */
156 ExeContext* where; /* where it was allocated */
157 }
158 MAC_Chunk;
159
rjwalshbc0bb832004-06-19 18:12:36 +0000160/* Memory pool. Nb: first two fields must match core's VgHashNode. */
161typedef
162 struct _MAC_Mempool {
163 struct _MAC_Mempool* next;
164 Addr pool; /* pool identifier */
165 UInt rzB; /* pool red-zone size */
166 Bool is_zeroed; /* allocations from this pool are zeroed */
167 VgHashTable chunks; /* chunks associated with this pool */
168 }
169 MAC_Mempool;
170
171
njn9b007f62003-04-07 14:40:25 +0000172/*------------------------------------------------------------*/
nethercote7cc9c232004-01-21 15:08:04 +0000173/*--- Profiling of tools and memory events ---*/
njn9b007f62003-04-07 14:40:25 +0000174/*------------------------------------------------------------*/
175
176typedef
177 enum {
178 VgpCheckMem = VgpFini+1,
179 VgpSetMem,
180 VgpESPAdj
181 }
nethercote7cc9c232004-01-21 15:08:04 +0000182 VgpToolCC;
njn9b007f62003-04-07 14:40:25 +0000183
184/* Define to collect detailed performance info. */
njn43c799e2003-04-08 00:08:52 +0000185/* #define MAC_PROFILE_MEMORY */
njn5c004e42002-11-18 11:04:50 +0000186
njn43c799e2003-04-08 00:08:52 +0000187#ifdef MAC_PROFILE_MEMORY
njn9b007f62003-04-07 14:40:25 +0000188# define N_PROF_EVENTS 150
njn5c004e42002-11-18 11:04:50 +0000189
njn43c799e2003-04-08 00:08:52 +0000190extern UInt MAC_(event_ctr)[N_PROF_EVENTS];
njn9b007f62003-04-07 14:40:25 +0000191
njn43c799e2003-04-08 00:08:52 +0000192# define PROF_EVENT(ev) \
193 do { sk_assert((ev) >= 0 && (ev) < N_PROF_EVENTS); \
194 MAC_(event_ctr)[ev]++; \
njn5c004e42002-11-18 11:04:50 +0000195 } while (False);
196
197#else
198
njn9b007f62003-04-07 14:40:25 +0000199# define PROF_EVENT(ev) /* */
njn5c004e42002-11-18 11:04:50 +0000200
njn43c799e2003-04-08 00:08:52 +0000201#endif /* MAC_PROFILE_MEMORY */
njn5c004e42002-11-18 11:04:50 +0000202
njn9b007f62003-04-07 14:40:25 +0000203/*------------------------------------------------------------*/
204/*--- V and A bits ---*/
205/*------------------------------------------------------------*/
206
njn5c004e42002-11-18 11:04:50 +0000207#define IS_DISTINGUISHED_SM(smap) \
208 ((smap) == &distinguished_secondary_map)
209
njn43c799e2003-04-08 00:08:52 +0000210#define ENSURE_MAPPABLE(addr,caller) \
211 do { \
njn5c004e42002-11-18 11:04:50 +0000212 if (IS_DISTINGUISHED_SM(primary_map[(addr) >> 16])) { \
213 primary_map[(addr) >> 16] = alloc_secondary_map(caller); \
njn43c799e2003-04-08 00:08:52 +0000214 /* VG_(printf)("new 2map because of %p\n", addr); */ \
215 } \
njn5c004e42002-11-18 11:04:50 +0000216 } while(0)
217
218#define BITARR_SET(aaa_p,iii_p) \
219 do { \
220 UInt iii = (UInt)iii_p; \
221 UChar* aaa = (UChar*)aaa_p; \
222 aaa[iii >> 3] |= (1 << (iii & 7)); \
223 } while (0)
224
225#define BITARR_CLEAR(aaa_p,iii_p) \
226 do { \
227 UInt iii = (UInt)iii_p; \
228 UChar* aaa = (UChar*)aaa_p; \
229 aaa[iii >> 3] &= ~(1 << (iii & 7)); \
230 } while (0)
231
232#define BITARR_TEST(aaa_p,iii_p) \
233 (0 != (((UChar*)aaa_p)[ ((UInt)iii_p) >> 3 ] \
234 & (1 << (((UInt)iii_p) & 7)))) \
235
236
237#define VGM_BIT_VALID 0
238#define VGM_BIT_INVALID 1
239
240#define VGM_NIBBLE_VALID 0
241#define VGM_NIBBLE_INVALID 0xF
242
243#define VGM_BYTE_VALID 0
244#define VGM_BYTE_INVALID 0xFF
245
246#define VGM_WORD_VALID 0
247#define VGM_WORD_INVALID 0xFFFFFFFF
248
249#define VGM_EFLAGS_VALID 0xFFFFFFFE
250#define VGM_EFLAGS_INVALID 0xFFFFFFFF /* not used */
251
252/*------------------------------------------------------------*/
253/*--- Command line options + defaults ---*/
254/*------------------------------------------------------------*/
255
njn43c799e2003-04-08 00:08:52 +0000256/* Memcheck defines a couple more. */
njn5c004e42002-11-18 11:04:50 +0000257
258/* Allow loads from partially-valid addresses? default: YES */
njn43c799e2003-04-08 00:08:52 +0000259extern Bool MAC_(clo_partial_loads_ok);
njn5c004e42002-11-18 11:04:50 +0000260
261/* Max volume of the freed blocks queue. */
njn43c799e2003-04-08 00:08:52 +0000262extern Int MAC_(clo_freelist_vol);
njn5c004e42002-11-18 11:04:50 +0000263
264/* Do leak check at exit? default: NO */
njn43c799e2003-04-08 00:08:52 +0000265extern Bool MAC_(clo_leak_check);
njn5c004e42002-11-18 11:04:50 +0000266
267/* How closely should we compare ExeContexts in leak records? default: 2 */
njn43c799e2003-04-08 00:08:52 +0000268extern VgRes MAC_(clo_leak_resolution);
njn5c004e42002-11-18 11:04:50 +0000269
270/* In leak check, show reachable-but-not-freed blocks? default: NO */
njn43c799e2003-04-08 00:08:52 +0000271extern Bool MAC_(clo_show_reachable);
njn5c004e42002-11-18 11:04:50 +0000272
273/* Assume accesses immediately below %esp are due to gcc-2.96 bugs.
274 * default: NO*/
njn43c799e2003-04-08 00:08:52 +0000275extern Bool MAC_(clo_workaround_gcc296_bugs);
njn5c004e42002-11-18 11:04:50 +0000276
njn3e884182003-04-15 13:03:23 +0000277extern Bool MAC_(process_common_cmd_line_option) ( Char* arg );
278extern void MAC_(print_common_usage) ( void );
279extern void MAC_(print_common_debug_usage) ( void );
280
281
282/*------------------------------------------------------------*/
283/*--- Variables ---*/
284/*------------------------------------------------------------*/
285
286/* For tracking malloc'd blocks */
287extern VgHashTable MAC_(malloc_list);
288
rjwalshbc0bb832004-06-19 18:12:36 +0000289/* For tracking memory pools. */
290extern VgHashTable MAC_(mempool_list);
291
nethercote7cc9c232004-01-21 15:08:04 +0000292/* Function pointers for the two tools to track interesting events. */
njn3e884182003-04-15 13:03:23 +0000293extern void (*MAC_(new_mem_heap)) ( Addr a, UInt len, Bool is_inited );
294extern void (*MAC_(ban_mem_heap)) ( Addr a, UInt len );
295extern void (*MAC_(die_mem_heap)) ( Addr a, UInt len );
296extern void (*MAC_(copy_mem_heap))( Addr from, Addr to, UInt len );
297
sewardjecf8e102003-07-12 12:11:39 +0000298/* Function pointers for internal sanity checking. */
299extern Bool (*MAC_(check_noaccess))( Addr a, UInt len, Addr* bad_addr );
300
njn3e884182003-04-15 13:03:23 +0000301/* Used in describe_addr() */
302extern Bool (*MAC_(describe_addr_supp)) ( Addr a, AddrInfo* ai );
njn5c004e42002-11-18 11:04:50 +0000303
njn47363ab2003-04-21 13:24:40 +0000304/* For VALGRIND_COUNT_LEAKS client request */
njne8b5c052003-07-22 22:03:58 +0000305extern Int MAC_(bytes_leaked);
306extern Int MAC_(bytes_dubious);
307extern Int MAC_(bytes_reachable);
308extern Int MAC_(bytes_suppressed);
sewardj99aac972002-12-26 01:53:45 +0000309
njn5c004e42002-11-18 11:04:50 +0000310/*------------------------------------------------------------*/
311/*--- Functions ---*/
312/*------------------------------------------------------------*/
313
njn43c799e2003-04-08 00:08:52 +0000314extern void MAC_(pp_AddrInfo) ( Addr a, AddrInfo* ai );
njn5c004e42002-11-18 11:04:50 +0000315
njn43c799e2003-04-08 00:08:52 +0000316extern void MAC_(clear_MAC_Error) ( MAC_Error* err_extra );
njn5c004e42002-11-18 11:04:50 +0000317
njn43c799e2003-04-08 00:08:52 +0000318extern Bool MAC_(shared_recognised_suppression) ( Char* name, Supp* su );
njn5c004e42002-11-18 11:04:50 +0000319
rjwalshbc0bb832004-06-19 18:12:36 +0000320extern MAC_Chunk* MAC_(new_block) ( Addr p, UInt size, UInt rzB,
321 Bool is_zeroed, MAC_AllocKind kind,
322 VgHashTable table);
njn72718642003-07-24 08:45:32 +0000323extern void MAC_(handle_free) ( Addr p, UInt rzB, MAC_AllocKind kind );
njn10785452003-05-20 16:38:24 +0000324
rjwalshbc0bb832004-06-19 18:12:36 +0000325extern void MAC_(create_mempool)(Addr pool, UInt rzB, Bool is_zeroed);
326extern void MAC_(destroy_mempool)(Addr pool);
327extern void MAC_(mempool_alloc)(Addr pool, Addr addr, UInt size);
328extern void MAC_(mempool_free)(Addr pool, Addr addr);
329
njn72718642003-07-24 08:45:32 +0000330extern void MAC_(record_address_error) ( ThreadId tid, Addr a,
sewardjaf48a602003-07-06 00:54:47 +0000331 Int size, Bool isWrite );
njn72718642003-07-24 08:45:32 +0000332extern void MAC_(record_core_mem_error) ( ThreadId tid, Bool isWrite,
njn43c799e2003-04-08 00:08:52 +0000333 Char* s );
njn72718642003-07-24 08:45:32 +0000334extern void MAC_(record_param_error) ( ThreadId tid, Addr a,
njn43c799e2003-04-08 00:08:52 +0000335 Bool isWriteLack, Char* msg );
njn72718642003-07-24 08:45:32 +0000336extern void MAC_(record_jump_error) ( ThreadId tid, Addr a );
337extern void MAC_(record_free_error) ( ThreadId tid, Addr a );
338extern void MAC_(record_freemismatch_error)( ThreadId tid, Addr a );
njnb6cae9f2003-09-04 20:50:47 +0000339extern void MAC_(record_overlap_error) ( Char* function, OverlapExtra* oe );
rjwalshbc0bb832004-06-19 18:12:36 +0000340extern void MAC_(record_illegal_mempool_error) ( ThreadId tid, Addr pool );
njn5c004e42002-11-18 11:04:50 +0000341
njn43c799e2003-04-08 00:08:52 +0000342extern void MAC_(pp_shared_SkinError) ( Error* err);
343
thughes4ad52d02004-06-27 17:37:21 +0000344extern MAC_Chunk* MAC_(first_matching_freed_MAC_Chunk)( Bool (*p)(MAC_Chunk*, void*), void* d );
njn43c799e2003-04-08 00:08:52 +0000345
njn3e884182003-04-15 13:03:23 +0000346extern void MAC_(common_pre_clo_init) ( void );
347extern void MAC_(common_fini) ( void (*leak_check)(void) );
348
njn72718642003-07-24 08:45:32 +0000349extern Bool MAC_(handle_common_client_requests) ( ThreadId tid,
350 UInt* arg_block, UInt* ret );
njn47363ab2003-04-21 13:24:40 +0000351
njn3e884182003-04-15 13:03:23 +0000352extern void MAC_(print_malloc_stats) ( void );
njn43c799e2003-04-08 00:08:52 +0000353
354/* For leak checking */
355extern void MAC_(pp_LeakError)(void* vl, UInt n_this_record,
356 UInt n_total_records);
357
358extern void MAC_(do_detect_memory_leaks) (
359 Bool is_valid_64k_chunk ( UInt ),
360 Bool is_valid_address ( Addr )
361 );
362
363extern __attribute__((regparm(1))) void MAC_(new_mem_stack_4) ( Addr old_ESP );
364extern __attribute__((regparm(1))) void MAC_(die_mem_stack_4) ( Addr old_ESP );
365extern __attribute__((regparm(1))) void MAC_(new_mem_stack_8) ( Addr old_ESP );
366extern __attribute__((regparm(1))) void MAC_(die_mem_stack_8) ( Addr old_ESP );
367extern __attribute__((regparm(1))) void MAC_(new_mem_stack_12) ( Addr old_ESP );
368extern __attribute__((regparm(1))) void MAC_(die_mem_stack_12) ( Addr old_ESP );
369extern __attribute__((regparm(1))) void MAC_(new_mem_stack_16) ( Addr old_ESP );
370extern __attribute__((regparm(1))) void MAC_(die_mem_stack_16) ( Addr old_ESP );
371extern __attribute__((regparm(1))) void MAC_(new_mem_stack_32) ( Addr old_ESP );
372extern __attribute__((regparm(1))) void MAC_(die_mem_stack_32) ( Addr old_ESP );
njn3e884182003-04-15 13:03:23 +0000373extern void MAC_(die_mem_stack) ( Addr a, UInt len);
374extern void MAC_(new_mem_stack) ( Addr a, UInt len);
njn9b007f62003-04-07 14:40:25 +0000375
376
377/*------------------------------------------------------------*/
378/*--- Stack pointer adjustment ---*/
379/*------------------------------------------------------------*/
380
381/* Some noble preprocessor abuse, to enable Memcheck and Addrcheck to
njn3e884182003-04-15 13:03:23 +0000382 share this code, but call different functions.
njn9b007f62003-04-07 14:40:25 +0000383
384 Note that this code is executed very frequently and must be highly
385 optimised, which is why I resort to the preprocessor to achieve the
386 factoring, rather than eg. using function pointers.
387*/
388
389#define ESP_UPDATE_HANDLERS(ALIGNED4_NEW, ALIGNED4_DIE, \
390 ALIGNED8_NEW, ALIGNED8_DIE, \
391 UNALIGNED_NEW, UNALIGNED_DIE) \
392 \
njn43c799e2003-04-08 00:08:52 +0000393void __attribute__((regparm(1))) MAC_(new_mem_stack_4)(Addr new_ESP) \
njn9b007f62003-04-07 14:40:25 +0000394{ \
395 PROF_EVENT(110); \
396 if (IS_ALIGNED4_ADDR(new_ESP)) { \
397 ALIGNED4_NEW ( new_ESP ); \
398 } else { \
399 UNALIGNED_NEW ( new_ESP, 4 ); \
400 } \
401} \
402 \
njn43c799e2003-04-08 00:08:52 +0000403void __attribute__((regparm(1))) MAC_(die_mem_stack_4)(Addr new_ESP) \
njn9b007f62003-04-07 14:40:25 +0000404{ \
405 PROF_EVENT(120); \
406 if (IS_ALIGNED4_ADDR(new_ESP)) { \
407 ALIGNED4_DIE ( new_ESP-4 ); \
408 } else { \
409 UNALIGNED_DIE ( new_ESP-4, 4 ); \
410 } \
411} \
412 \
njn43c799e2003-04-08 00:08:52 +0000413void __attribute__((regparm(1))) MAC_(new_mem_stack_8)(Addr new_ESP) \
njn9b007f62003-04-07 14:40:25 +0000414{ \
415 PROF_EVENT(111); \
416 if (IS_ALIGNED8_ADDR(new_ESP)) { \
417 ALIGNED8_NEW ( new_ESP ); \
418 } else if (IS_ALIGNED4_ADDR(new_ESP)) { \
419 ALIGNED4_NEW ( new_ESP ); \
420 ALIGNED4_NEW ( new_ESP+4 ); \
421 } else { \
422 UNALIGNED_NEW ( new_ESP, 8 ); \
423 } \
424} \
425 \
njn43c799e2003-04-08 00:08:52 +0000426void __attribute__((regparm(1))) MAC_(die_mem_stack_8)(Addr new_ESP) \
njn9b007f62003-04-07 14:40:25 +0000427{ \
428 PROF_EVENT(121); \
429 if (IS_ALIGNED8_ADDR(new_ESP)) { \
430 ALIGNED8_DIE ( new_ESP-8 ); \
431 } else if (IS_ALIGNED4_ADDR(new_ESP)) { \
432 ALIGNED4_DIE ( new_ESP-8 ); \
433 ALIGNED4_DIE ( new_ESP-4 ); \
434 } else { \
435 UNALIGNED_DIE ( new_ESP-8, 8 ); \
436 } \
437} \
438 \
njn43c799e2003-04-08 00:08:52 +0000439void __attribute__((regparm(1))) MAC_(new_mem_stack_12)(Addr new_ESP) \
njn9b007f62003-04-07 14:40:25 +0000440{ \
441 PROF_EVENT(112); \
442 if (IS_ALIGNED8_ADDR(new_ESP)) { \
443 ALIGNED8_NEW ( new_ESP ); \
444 ALIGNED4_NEW ( new_ESP+8 ); \
445 } else if (IS_ALIGNED4_ADDR(new_ESP)) { \
446 ALIGNED4_NEW ( new_ESP ); \
447 ALIGNED8_NEW ( new_ESP+4 ); \
448 } else { \
449 UNALIGNED_NEW ( new_ESP, 12 ); \
450 } \
451} \
452 \
njn43c799e2003-04-08 00:08:52 +0000453void __attribute__((regparm(1))) MAC_(die_mem_stack_12)(Addr new_ESP) \
njn9b007f62003-04-07 14:40:25 +0000454{ \
455 PROF_EVENT(122); \
456 /* Note the -12 in the test */ \
457 if (IS_ALIGNED8_ADDR(new_ESP-12)) { \
458 ALIGNED8_DIE ( new_ESP-12 ); \
459 ALIGNED4_DIE ( new_ESP-4 ); \
460 } else if (IS_ALIGNED4_ADDR(new_ESP)) { \
461 ALIGNED4_DIE ( new_ESP-12 ); \
462 ALIGNED8_DIE ( new_ESP-8 ); \
463 } else { \
464 UNALIGNED_DIE ( new_ESP-12, 12 ); \
465 } \
466} \
467 \
njn43c799e2003-04-08 00:08:52 +0000468void __attribute__((regparm(1))) MAC_(new_mem_stack_16)(Addr new_ESP) \
njn9b007f62003-04-07 14:40:25 +0000469{ \
470 PROF_EVENT(113); \
471 if (IS_ALIGNED8_ADDR(new_ESP)) { \
472 ALIGNED8_NEW ( new_ESP ); \
473 ALIGNED8_NEW ( new_ESP+8 ); \
474 } else if (IS_ALIGNED4_ADDR(new_ESP)) { \
475 ALIGNED4_NEW ( new_ESP ); \
476 ALIGNED8_NEW ( new_ESP+4 ); \
477 ALIGNED4_NEW ( new_ESP+12 ); \
478 } else { \
479 UNALIGNED_NEW ( new_ESP, 16 ); \
480 } \
481} \
482 \
njn43c799e2003-04-08 00:08:52 +0000483void __attribute__((regparm(1))) MAC_(die_mem_stack_16)(Addr new_ESP) \
njn9b007f62003-04-07 14:40:25 +0000484{ \
485 PROF_EVENT(123); \
486 if (IS_ALIGNED8_ADDR(new_ESP)) { \
487 ALIGNED8_DIE ( new_ESP-16 ); \
488 ALIGNED8_DIE ( new_ESP-8 ); \
489 } else if (IS_ALIGNED4_ADDR(new_ESP)) { \
490 ALIGNED4_DIE ( new_ESP-16 ); \
491 ALIGNED8_DIE ( new_ESP-12 ); \
492 ALIGNED4_DIE ( new_ESP-4 ); \
493 } else { \
494 UNALIGNED_DIE ( new_ESP-16, 16 ); \
495 } \
496} \
497 \
njn43c799e2003-04-08 00:08:52 +0000498void __attribute__((regparm(1))) MAC_(new_mem_stack_32)(Addr new_ESP) \
njn9b007f62003-04-07 14:40:25 +0000499{ \
500 PROF_EVENT(114); \
501 if (IS_ALIGNED8_ADDR(new_ESP)) { \
502 ALIGNED8_NEW ( new_ESP ); \
503 ALIGNED8_NEW ( new_ESP+8 ); \
504 ALIGNED8_NEW ( new_ESP+16 ); \
505 ALIGNED8_NEW ( new_ESP+24 ); \
506 } else if (IS_ALIGNED4_ADDR(new_ESP)) { \
507 ALIGNED4_NEW ( new_ESP ); \
508 ALIGNED8_NEW ( new_ESP+4 ); \
509 ALIGNED8_NEW ( new_ESP+12 ); \
510 ALIGNED8_NEW ( new_ESP+20 ); \
511 ALIGNED4_NEW ( new_ESP+28 ); \
512 } else { \
513 UNALIGNED_NEW ( new_ESP, 32 ); \
514 } \
515} \
516 \
njn43c799e2003-04-08 00:08:52 +0000517void __attribute__((regparm(1))) MAC_(die_mem_stack_32)(Addr new_ESP) \
njn9b007f62003-04-07 14:40:25 +0000518{ \
519 PROF_EVENT(124); \
520 if (IS_ALIGNED8_ADDR(new_ESP)) { \
521 ALIGNED8_DIE ( new_ESP-32 ); \
522 ALIGNED8_DIE ( new_ESP-24 ); \
523 ALIGNED8_DIE ( new_ESP-16 ); \
524 ALIGNED8_DIE ( new_ESP- 8 ); \
525 } else if (IS_ALIGNED4_ADDR(new_ESP)) { \
526 ALIGNED4_DIE ( new_ESP-32 ); \
527 ALIGNED8_DIE ( new_ESP-28 ); \
528 ALIGNED8_DIE ( new_ESP-20 ); \
529 ALIGNED8_DIE ( new_ESP-12 ); \
530 ALIGNED4_DIE ( new_ESP-4 ); \
531 } else { \
532 UNALIGNED_DIE ( new_ESP-32, 32 ); \
533 } \
534} \
535 \
njn43c799e2003-04-08 00:08:52 +0000536void MAC_(new_mem_stack) ( Addr a, UInt len ) \
njn9b007f62003-04-07 14:40:25 +0000537{ \
538 PROF_EVENT(115); \
539 UNALIGNED_NEW ( a, len ); \
540} \
541 \
njn43c799e2003-04-08 00:08:52 +0000542void MAC_(die_mem_stack) ( Addr a, UInt len ) \
njn9b007f62003-04-07 14:40:25 +0000543{ \
544 PROF_EVENT(125); \
545 UNALIGNED_DIE ( a, len ); \
546}
547
njn43c799e2003-04-08 00:08:52 +0000548#endif /* __MAC_SHARED_H */
njn5c004e42002-11-18 11:04:50 +0000549
550/*--------------------------------------------------------------------*/
njn43c799e2003-04-08 00:08:52 +0000551/*--- end mac_shared.h ---*/
njn5c004e42002-11-18 11:04:50 +0000552/*--------------------------------------------------------------------*/