blob: 4a5014c98bf9dcb30a392b38e24ade6caabb7ce4 [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
nethercote46063202004-09-02 08:51:43 +000039#include "tool.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
nethercote05675c82004-08-04 10:37:49 +000061 struct { // Used by:
62 AddrKind akind; // ALL
63 Int blksize; // Freed, Mallocd
64 Int rwoffset; // Freed, Mallocd
65 ExeContext* lastchange; // Freed, Mallocd
66 ThreadId stack_tid; // Stack
67 Bool maybe_gcc; // True if just below %esp -- could be a gcc bug.
njn5c004e42002-11-18 11:04:50 +000068 }
69 AddrInfo;
70
71typedef
72 enum {
nethercote05675c82004-08-04 10:37:49 +000073 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)
njnc0616662003-06-12 09:58:41 +000077 Value0Supp, Value1Supp, Value2Supp, Value4Supp, Value8Supp, Value16Supp,
nethercote05675c82004-08-04 10:37:49 +000078
79 // Invalid read/write attempt at given size
njnc0616662003-06-12 09:58:41 +000080 Addr1Supp, Addr2Supp, Addr4Supp, Addr8Supp, Addr16Supp,
nethercote05675c82004-08-04 10:37:49 +000081
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.
njn5c004e42002-11-18 11:04:50 +000086 }
njn43c799e2003-04-08 00:08:52 +000087 MAC_SuppKind;
njn5c004e42002-11-18 11:04:50 +000088
89/* What kind of error it is. */
90typedef
91 enum { ValueErr, /* Memcheck only */
92 CoreMemErr,
93 AddrErr,
94 ParamErr, UserErr, /* behaves like an anonymous ParamErr */
njn43c799e2003-04-08 00:08:52 +000095 FreeErr, FreeMismatchErr,
njn7201b2a2003-08-19 12:16:05 +000096 OverlapErr,
rjwalshbc0bb832004-06-19 18:12:36 +000097 LeakErr,
98 IllegalMempoolErr,
njn5c004e42002-11-18 11:04:50 +000099 }
njn43c799e2003-04-08 00:08:52 +0000100 MAC_ErrorKind;
njn5c004e42002-11-18 11:04:50 +0000101
102/* What kind of memory access is involved in the error? */
103typedef
104 enum { ReadAxs, WriteAxs, ExecAxs }
105 AxsKind;
106
107/* Extra context for memory errors */
108typedef
nethercote05675c82004-08-04 10:37:49 +0000109 struct { // Used by:
110 AxsKind axskind; // AddrErr
111 Int size; // AddrErr, ValueErr
112 AddrInfo addrinfo; // {Addr,Free,FreeMismatch,Param,User}Err
113 Bool isWrite; // ParamErr, UserErr, CoreMemErr
njn5c004e42002-11-18 11:04:50 +0000114 }
njn43c799e2003-04-08 00:08:52 +0000115 MAC_Error;
njn5c004e42002-11-18 11:04:50 +0000116
njnb6cae9f2003-09-04 20:50:47 +0000117/* Extra info for overlap errors */
118typedef
119 struct {
120 Addr src;
121 Addr dst;
122 Int len; // -1 if unused
123 }
124 OverlapExtra;
125
njn3e884182003-04-15 13:03:23 +0000126/* For malloc()/new/new[] vs. free()/delete/delete[] mismatch checking. */
127typedef
128 enum {
129 MAC_AllocMalloc = 0,
130 MAC_AllocNew = 1,
njn10785452003-05-20 16:38:24 +0000131 MAC_AllocNewVec = 2,
132 MAC_AllocCustom = 3
njn3e884182003-04-15 13:03:23 +0000133 }
134 MAC_AllocKind;
135
136/* Nb: first two fields must match core's VgHashNode. */
137typedef
138 struct _MAC_Chunk {
139 struct _MAC_Chunk* next;
nethercote05675c82004-08-04 10:37:49 +0000140 Addr data; // ptr to actual block
141 UInt size : 30; // size requested
142 MAC_AllocKind allockind : 2; // which wrapper did the allocation
143 ExeContext* where; // where it was allocated
njn3e884182003-04-15 13:03:23 +0000144 }
145 MAC_Chunk;
146
rjwalshbc0bb832004-06-19 18:12:36 +0000147/* Memory pool. Nb: first two fields must match core's VgHashNode. */
148typedef
149 struct _MAC_Mempool {
150 struct _MAC_Mempool* next;
nethercote05675c82004-08-04 10:37:49 +0000151 Addr pool; // pool identifier
152 UInt rzB; // pool red-zone size
153 Bool is_zeroed; // allocations from this pool are zeroed
154 VgHashTable chunks; // chunks associated with this pool
rjwalshbc0bb832004-06-19 18:12:36 +0000155 }
156 MAC_Mempool;
157
158
njn9b007f62003-04-07 14:40:25 +0000159/*------------------------------------------------------------*/
nethercote7cc9c232004-01-21 15:08:04 +0000160/*--- Profiling of tools and memory events ---*/
njn9b007f62003-04-07 14:40:25 +0000161/*------------------------------------------------------------*/
162
163typedef
164 enum {
165 VgpCheckMem = VgpFini+1,
166 VgpSetMem,
167 VgpESPAdj
168 }
nethercote7cc9c232004-01-21 15:08:04 +0000169 VgpToolCC;
njn9b007f62003-04-07 14:40:25 +0000170
171/* Define to collect detailed performance info. */
njn43c799e2003-04-08 00:08:52 +0000172/* #define MAC_PROFILE_MEMORY */
njn5c004e42002-11-18 11:04:50 +0000173
njn43c799e2003-04-08 00:08:52 +0000174#ifdef MAC_PROFILE_MEMORY
njn9b007f62003-04-07 14:40:25 +0000175# define N_PROF_EVENTS 150
njn5c004e42002-11-18 11:04:50 +0000176
njn43c799e2003-04-08 00:08:52 +0000177extern UInt MAC_(event_ctr)[N_PROF_EVENTS];
njn9b007f62003-04-07 14:40:25 +0000178
njn43c799e2003-04-08 00:08:52 +0000179# define PROF_EVENT(ev) \
180 do { sk_assert((ev) >= 0 && (ev) < N_PROF_EVENTS); \
181 MAC_(event_ctr)[ev]++; \
njn5c004e42002-11-18 11:04:50 +0000182 } while (False);
183
184#else
185
njn9b007f62003-04-07 14:40:25 +0000186# define PROF_EVENT(ev) /* */
njn5c004e42002-11-18 11:04:50 +0000187
njn43c799e2003-04-08 00:08:52 +0000188#endif /* MAC_PROFILE_MEMORY */
njn5c004e42002-11-18 11:04:50 +0000189
njn9b007f62003-04-07 14:40:25 +0000190/*------------------------------------------------------------*/
191/*--- V and A bits ---*/
192/*------------------------------------------------------------*/
193
njn5c004e42002-11-18 11:04:50 +0000194#define IS_DISTINGUISHED_SM(smap) \
195 ((smap) == &distinguished_secondary_map)
196
njn43c799e2003-04-08 00:08:52 +0000197#define ENSURE_MAPPABLE(addr,caller) \
198 do { \
njn5c004e42002-11-18 11:04:50 +0000199 if (IS_DISTINGUISHED_SM(primary_map[(addr) >> 16])) { \
200 primary_map[(addr) >> 16] = alloc_secondary_map(caller); \
njn43c799e2003-04-08 00:08:52 +0000201 /* VG_(printf)("new 2map because of %p\n", addr); */ \
202 } \
njn5c004e42002-11-18 11:04:50 +0000203 } while(0)
204
205#define BITARR_SET(aaa_p,iii_p) \
206 do { \
207 UInt iii = (UInt)iii_p; \
208 UChar* aaa = (UChar*)aaa_p; \
209 aaa[iii >> 3] |= (1 << (iii & 7)); \
210 } while (0)
211
212#define BITARR_CLEAR(aaa_p,iii_p) \
213 do { \
214 UInt iii = (UInt)iii_p; \
215 UChar* aaa = (UChar*)aaa_p; \
216 aaa[iii >> 3] &= ~(1 << (iii & 7)); \
217 } while (0)
218
219#define BITARR_TEST(aaa_p,iii_p) \
220 (0 != (((UChar*)aaa_p)[ ((UInt)iii_p) >> 3 ] \
221 & (1 << (((UInt)iii_p) & 7)))) \
222
223
224#define VGM_BIT_VALID 0
225#define VGM_BIT_INVALID 1
226
227#define VGM_NIBBLE_VALID 0
228#define VGM_NIBBLE_INVALID 0xF
229
230#define VGM_BYTE_VALID 0
231#define VGM_BYTE_INVALID 0xFF
232
233#define VGM_WORD_VALID 0
234#define VGM_WORD_INVALID 0xFFFFFFFF
235
236#define VGM_EFLAGS_VALID 0xFFFFFFFE
237#define VGM_EFLAGS_INVALID 0xFFFFFFFF /* not used */
238
239/*------------------------------------------------------------*/
240/*--- Command line options + defaults ---*/
241/*------------------------------------------------------------*/
242
njn43c799e2003-04-08 00:08:52 +0000243/* Memcheck defines a couple more. */
njn5c004e42002-11-18 11:04:50 +0000244
245/* Allow loads from partially-valid addresses? default: YES */
njn43c799e2003-04-08 00:08:52 +0000246extern Bool MAC_(clo_partial_loads_ok);
njn5c004e42002-11-18 11:04:50 +0000247
248/* Max volume of the freed blocks queue. */
njn43c799e2003-04-08 00:08:52 +0000249extern Int MAC_(clo_freelist_vol);
njn5c004e42002-11-18 11:04:50 +0000250
251/* Do leak check at exit? default: NO */
njn43c799e2003-04-08 00:08:52 +0000252extern Bool MAC_(clo_leak_check);
njn5c004e42002-11-18 11:04:50 +0000253
254/* How closely should we compare ExeContexts in leak records? default: 2 */
njn43c799e2003-04-08 00:08:52 +0000255extern VgRes MAC_(clo_leak_resolution);
njn5c004e42002-11-18 11:04:50 +0000256
257/* In leak check, show reachable-but-not-freed blocks? default: NO */
njn43c799e2003-04-08 00:08:52 +0000258extern Bool MAC_(clo_show_reachable);
njn5c004e42002-11-18 11:04:50 +0000259
260/* Assume accesses immediately below %esp are due to gcc-2.96 bugs.
261 * default: NO*/
njn43c799e2003-04-08 00:08:52 +0000262extern Bool MAC_(clo_workaround_gcc296_bugs);
njn5c004e42002-11-18 11:04:50 +0000263
njn3e884182003-04-15 13:03:23 +0000264extern Bool MAC_(process_common_cmd_line_option) ( Char* arg );
265extern void MAC_(print_common_usage) ( void );
266extern void MAC_(print_common_debug_usage) ( void );
267
268
269/*------------------------------------------------------------*/
270/*--- Variables ---*/
271/*------------------------------------------------------------*/
272
273/* For tracking malloc'd blocks */
274extern VgHashTable MAC_(malloc_list);
275
rjwalshbc0bb832004-06-19 18:12:36 +0000276/* For tracking memory pools. */
277extern VgHashTable MAC_(mempool_list);
278
nethercote7cc9c232004-01-21 15:08:04 +0000279/* Function pointers for the two tools to track interesting events. */
njn3e884182003-04-15 13:03:23 +0000280extern void (*MAC_(new_mem_heap)) ( Addr a, UInt len, Bool is_inited );
281extern void (*MAC_(ban_mem_heap)) ( Addr a, UInt len );
282extern void (*MAC_(die_mem_heap)) ( Addr a, UInt len );
283extern void (*MAC_(copy_mem_heap))( Addr from, Addr to, UInt len );
284
sewardjecf8e102003-07-12 12:11:39 +0000285/* Function pointers for internal sanity checking. */
286extern Bool (*MAC_(check_noaccess))( Addr a, UInt len, Addr* bad_addr );
287
njn3e884182003-04-15 13:03:23 +0000288/* Used in describe_addr() */
289extern Bool (*MAC_(describe_addr_supp)) ( Addr a, AddrInfo* ai );
njn5c004e42002-11-18 11:04:50 +0000290
njn47363ab2003-04-21 13:24:40 +0000291/* For VALGRIND_COUNT_LEAKS client request */
njne8b5c052003-07-22 22:03:58 +0000292extern Int MAC_(bytes_leaked);
293extern Int MAC_(bytes_dubious);
294extern Int MAC_(bytes_reachable);
295extern Int MAC_(bytes_suppressed);
sewardj99aac972002-12-26 01:53:45 +0000296
njn5c004e42002-11-18 11:04:50 +0000297/*------------------------------------------------------------*/
298/*--- Functions ---*/
299/*------------------------------------------------------------*/
300
njn43c799e2003-04-08 00:08:52 +0000301extern void MAC_(pp_AddrInfo) ( Addr a, AddrInfo* ai );
njn5c004e42002-11-18 11:04:50 +0000302
njn43c799e2003-04-08 00:08:52 +0000303extern void MAC_(clear_MAC_Error) ( MAC_Error* err_extra );
njn5c004e42002-11-18 11:04:50 +0000304
njn43c799e2003-04-08 00:08:52 +0000305extern Bool MAC_(shared_recognised_suppression) ( Char* name, Supp* su );
njn5c004e42002-11-18 11:04:50 +0000306
nethercote57e36b32004-07-10 14:56:28 +0000307extern void* MAC_(new_block) ( Addr p, UInt size, UInt align, UInt rzB,
308 Bool is_zeroed, MAC_AllocKind kind,
309 VgHashTable table);
njn72718642003-07-24 08:45:32 +0000310extern void MAC_(handle_free) ( Addr p, UInt rzB, MAC_AllocKind kind );
njn10785452003-05-20 16:38:24 +0000311
rjwalshbc0bb832004-06-19 18:12:36 +0000312extern void MAC_(create_mempool)(Addr pool, UInt rzB, Bool is_zeroed);
313extern void MAC_(destroy_mempool)(Addr pool);
314extern void MAC_(mempool_alloc)(Addr pool, Addr addr, UInt size);
315extern void MAC_(mempool_free)(Addr pool, Addr addr);
316
njn72718642003-07-24 08:45:32 +0000317extern void MAC_(record_address_error) ( ThreadId tid, Addr a,
sewardjaf48a602003-07-06 00:54:47 +0000318 Int size, Bool isWrite );
njn72718642003-07-24 08:45:32 +0000319extern void MAC_(record_core_mem_error) ( ThreadId tid, Bool isWrite,
njn43c799e2003-04-08 00:08:52 +0000320 Char* s );
njn72718642003-07-24 08:45:32 +0000321extern void MAC_(record_param_error) ( ThreadId tid, Addr a,
njn43c799e2003-04-08 00:08:52 +0000322 Bool isWriteLack, Char* msg );
njn72718642003-07-24 08:45:32 +0000323extern void MAC_(record_jump_error) ( ThreadId tid, Addr a );
324extern void MAC_(record_free_error) ( ThreadId tid, Addr a );
325extern void MAC_(record_freemismatch_error)( ThreadId tid, Addr a );
njnb6cae9f2003-09-04 20:50:47 +0000326extern void MAC_(record_overlap_error) ( Char* function, OverlapExtra* oe );
rjwalshbc0bb832004-06-19 18:12:36 +0000327extern void MAC_(record_illegal_mempool_error) ( ThreadId tid, Addr pool );
njn5c004e42002-11-18 11:04:50 +0000328
njn43c799e2003-04-08 00:08:52 +0000329extern void MAC_(pp_shared_SkinError) ( Error* err);
330
thughes4ad52d02004-06-27 17:37:21 +0000331extern MAC_Chunk* MAC_(first_matching_freed_MAC_Chunk)( Bool (*p)(MAC_Chunk*, void*), void* d );
njn43c799e2003-04-08 00:08:52 +0000332
njn3e884182003-04-15 13:03:23 +0000333extern void MAC_(common_pre_clo_init) ( void );
334extern void MAC_(common_fini) ( void (*leak_check)(void) );
335
njn72718642003-07-24 08:45:32 +0000336extern Bool MAC_(handle_common_client_requests) ( ThreadId tid,
337 UInt* arg_block, UInt* ret );
njn47363ab2003-04-21 13:24:40 +0000338
njn3e884182003-04-15 13:03:23 +0000339extern void MAC_(print_malloc_stats) ( void );
njn43c799e2003-04-08 00:08:52 +0000340
341/* For leak checking */
342extern void MAC_(pp_LeakError)(void* vl, UInt n_this_record,
343 UInt n_total_records);
344
345extern void MAC_(do_detect_memory_leaks) (
346 Bool is_valid_64k_chunk ( UInt ),
347 Bool is_valid_address ( Addr )
348 );
349
nethercoteeec46302004-08-23 15:06:23 +0000350extern REGPARM(1) void MAC_(new_mem_stack_4) ( Addr old_ESP );
351extern REGPARM(1) void MAC_(die_mem_stack_4) ( Addr old_ESP );
352extern REGPARM(1) void MAC_(new_mem_stack_8) ( Addr old_ESP );
353extern REGPARM(1) void MAC_(die_mem_stack_8) ( Addr old_ESP );
354extern REGPARM(1) void MAC_(new_mem_stack_12) ( Addr old_ESP );
355extern REGPARM(1) void MAC_(die_mem_stack_12) ( Addr old_ESP );
356extern REGPARM(1) void MAC_(new_mem_stack_16) ( Addr old_ESP );
357extern REGPARM(1) void MAC_(die_mem_stack_16) ( Addr old_ESP );
358extern REGPARM(1) void MAC_(new_mem_stack_32) ( Addr old_ESP );
359extern REGPARM(1) void MAC_(die_mem_stack_32) ( Addr old_ESP );
360extern void MAC_(die_mem_stack) ( Addr a, UInt len);
361extern void MAC_(new_mem_stack) ( Addr a, UInt len);
njn9b007f62003-04-07 14:40:25 +0000362
363
364/*------------------------------------------------------------*/
365/*--- Stack pointer adjustment ---*/
366/*------------------------------------------------------------*/
367
368/* Some noble preprocessor abuse, to enable Memcheck and Addrcheck to
njn3e884182003-04-15 13:03:23 +0000369 share this code, but call different functions.
njn9b007f62003-04-07 14:40:25 +0000370
371 Note that this code is executed very frequently and must be highly
372 optimised, which is why I resort to the preprocessor to achieve the
373 factoring, rather than eg. using function pointers.
374*/
375
376#define ESP_UPDATE_HANDLERS(ALIGNED4_NEW, ALIGNED4_DIE, \
377 ALIGNED8_NEW, ALIGNED8_DIE, \
378 UNALIGNED_NEW, UNALIGNED_DIE) \
379 \
nethercoteeec46302004-08-23 15:06:23 +0000380void REGPARM(1) MAC_(new_mem_stack_4)(Addr new_ESP) \
njn9b007f62003-04-07 14:40:25 +0000381{ \
382 PROF_EVENT(110); \
383 if (IS_ALIGNED4_ADDR(new_ESP)) { \
384 ALIGNED4_NEW ( new_ESP ); \
385 } else { \
386 UNALIGNED_NEW ( new_ESP, 4 ); \
387 } \
388} \
389 \
nethercoteeec46302004-08-23 15:06:23 +0000390void REGPARM(1) MAC_(die_mem_stack_4)(Addr new_ESP) \
njn9b007f62003-04-07 14:40:25 +0000391{ \
392 PROF_EVENT(120); \
393 if (IS_ALIGNED4_ADDR(new_ESP)) { \
394 ALIGNED4_DIE ( new_ESP-4 ); \
395 } else { \
396 UNALIGNED_DIE ( new_ESP-4, 4 ); \
397 } \
398} \
399 \
nethercoteeec46302004-08-23 15:06:23 +0000400void REGPARM(1) MAC_(new_mem_stack_8)(Addr new_ESP) \
njn9b007f62003-04-07 14:40:25 +0000401{ \
402 PROF_EVENT(111); \
403 if (IS_ALIGNED8_ADDR(new_ESP)) { \
404 ALIGNED8_NEW ( new_ESP ); \
405 } else if (IS_ALIGNED4_ADDR(new_ESP)) { \
406 ALIGNED4_NEW ( new_ESP ); \
407 ALIGNED4_NEW ( new_ESP+4 ); \
408 } else { \
409 UNALIGNED_NEW ( new_ESP, 8 ); \
410 } \
411} \
412 \
nethercoteeec46302004-08-23 15:06:23 +0000413void REGPARM(1) MAC_(die_mem_stack_8)(Addr new_ESP) \
njn9b007f62003-04-07 14:40:25 +0000414{ \
415 PROF_EVENT(121); \
416 if (IS_ALIGNED8_ADDR(new_ESP)) { \
417 ALIGNED8_DIE ( new_ESP-8 ); \
418 } else if (IS_ALIGNED4_ADDR(new_ESP)) { \
419 ALIGNED4_DIE ( new_ESP-8 ); \
420 ALIGNED4_DIE ( new_ESP-4 ); \
421 } else { \
422 UNALIGNED_DIE ( new_ESP-8, 8 ); \
423 } \
424} \
425 \
nethercoteeec46302004-08-23 15:06:23 +0000426void REGPARM(1) MAC_(new_mem_stack_12)(Addr new_ESP) \
njn9b007f62003-04-07 14:40:25 +0000427{ \
428 PROF_EVENT(112); \
429 if (IS_ALIGNED8_ADDR(new_ESP)) { \
430 ALIGNED8_NEW ( new_ESP ); \
431 ALIGNED4_NEW ( new_ESP+8 ); \
432 } else if (IS_ALIGNED4_ADDR(new_ESP)) { \
433 ALIGNED4_NEW ( new_ESP ); \
434 ALIGNED8_NEW ( new_ESP+4 ); \
435 } else { \
436 UNALIGNED_NEW ( new_ESP, 12 ); \
437 } \
438} \
439 \
nethercoteeec46302004-08-23 15:06:23 +0000440void REGPARM(1) MAC_(die_mem_stack_12)(Addr new_ESP) \
njn9b007f62003-04-07 14:40:25 +0000441{ \
442 PROF_EVENT(122); \
443 /* Note the -12 in the test */ \
444 if (IS_ALIGNED8_ADDR(new_ESP-12)) { \
445 ALIGNED8_DIE ( new_ESP-12 ); \
446 ALIGNED4_DIE ( new_ESP-4 ); \
447 } else if (IS_ALIGNED4_ADDR(new_ESP)) { \
448 ALIGNED4_DIE ( new_ESP-12 ); \
449 ALIGNED8_DIE ( new_ESP-8 ); \
450 } else { \
451 UNALIGNED_DIE ( new_ESP-12, 12 ); \
452 } \
453} \
454 \
nethercoteeec46302004-08-23 15:06:23 +0000455void REGPARM(1) MAC_(new_mem_stack_16)(Addr new_ESP) \
njn9b007f62003-04-07 14:40:25 +0000456{ \
457 PROF_EVENT(113); \
458 if (IS_ALIGNED8_ADDR(new_ESP)) { \
459 ALIGNED8_NEW ( new_ESP ); \
460 ALIGNED8_NEW ( new_ESP+8 ); \
461 } else if (IS_ALIGNED4_ADDR(new_ESP)) { \
462 ALIGNED4_NEW ( new_ESP ); \
463 ALIGNED8_NEW ( new_ESP+4 ); \
464 ALIGNED4_NEW ( new_ESP+12 ); \
465 } else { \
466 UNALIGNED_NEW ( new_ESP, 16 ); \
467 } \
468} \
469 \
nethercoteeec46302004-08-23 15:06:23 +0000470void REGPARM(1) MAC_(die_mem_stack_16)(Addr new_ESP) \
njn9b007f62003-04-07 14:40:25 +0000471{ \
472 PROF_EVENT(123); \
473 if (IS_ALIGNED8_ADDR(new_ESP)) { \
474 ALIGNED8_DIE ( new_ESP-16 ); \
475 ALIGNED8_DIE ( new_ESP-8 ); \
476 } else if (IS_ALIGNED4_ADDR(new_ESP)) { \
477 ALIGNED4_DIE ( new_ESP-16 ); \
478 ALIGNED8_DIE ( new_ESP-12 ); \
479 ALIGNED4_DIE ( new_ESP-4 ); \
480 } else { \
481 UNALIGNED_DIE ( new_ESP-16, 16 ); \
482 } \
483} \
484 \
nethercoteeec46302004-08-23 15:06:23 +0000485void REGPARM(1) MAC_(new_mem_stack_32)(Addr new_ESP) \
njn9b007f62003-04-07 14:40:25 +0000486{ \
487 PROF_EVENT(114); \
488 if (IS_ALIGNED8_ADDR(new_ESP)) { \
489 ALIGNED8_NEW ( new_ESP ); \
490 ALIGNED8_NEW ( new_ESP+8 ); \
491 ALIGNED8_NEW ( new_ESP+16 ); \
492 ALIGNED8_NEW ( new_ESP+24 ); \
493 } else if (IS_ALIGNED4_ADDR(new_ESP)) { \
494 ALIGNED4_NEW ( new_ESP ); \
495 ALIGNED8_NEW ( new_ESP+4 ); \
496 ALIGNED8_NEW ( new_ESP+12 ); \
497 ALIGNED8_NEW ( new_ESP+20 ); \
498 ALIGNED4_NEW ( new_ESP+28 ); \
499 } else { \
500 UNALIGNED_NEW ( new_ESP, 32 ); \
501 } \
502} \
503 \
nethercoteeec46302004-08-23 15:06:23 +0000504void REGPARM(1) MAC_(die_mem_stack_32)(Addr new_ESP) \
njn9b007f62003-04-07 14:40:25 +0000505{ \
506 PROF_EVENT(124); \
507 if (IS_ALIGNED8_ADDR(new_ESP)) { \
508 ALIGNED8_DIE ( new_ESP-32 ); \
509 ALIGNED8_DIE ( new_ESP-24 ); \
510 ALIGNED8_DIE ( new_ESP-16 ); \
511 ALIGNED8_DIE ( new_ESP- 8 ); \
512 } else if (IS_ALIGNED4_ADDR(new_ESP)) { \
513 ALIGNED4_DIE ( new_ESP-32 ); \
514 ALIGNED8_DIE ( new_ESP-28 ); \
515 ALIGNED8_DIE ( new_ESP-20 ); \
516 ALIGNED8_DIE ( new_ESP-12 ); \
517 ALIGNED4_DIE ( new_ESP-4 ); \
518 } else { \
519 UNALIGNED_DIE ( new_ESP-32, 32 ); \
520 } \
521} \
522 \
njn43c799e2003-04-08 00:08:52 +0000523void MAC_(new_mem_stack) ( Addr a, UInt len ) \
njn9b007f62003-04-07 14:40:25 +0000524{ \
525 PROF_EVENT(115); \
526 UNALIGNED_NEW ( a, len ); \
527} \
528 \
njn43c799e2003-04-08 00:08:52 +0000529void MAC_(die_mem_stack) ( Addr a, UInt len ) \
njn9b007f62003-04-07 14:40:25 +0000530{ \
531 PROF_EVENT(125); \
532 UNALIGNED_DIE ( a, len ); \
533}
534
njn43c799e2003-04-08 00:08:52 +0000535#endif /* __MAC_SHARED_H */
njn5c004e42002-11-18 11:04:50 +0000536
537/*--------------------------------------------------------------------*/
njn43c799e2003-04-08 00:08:52 +0000538/*--- end mac_shared.h ---*/
njn5c004e42002-11-18 11:04:50 +0000539/*--------------------------------------------------------------------*/