Allow memcheck to take account of VGA_STACK_REDZONE_SIZE -- that is,
account for the fact that on amd64 (really, on amd64-linux) the area
up to 128 bytes below the stack pointer is accessible. This meant
moving the definitions of VGA_STACK_REDZONE_SIZE to tool-visible
places.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@3546 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/NOTES.txt b/NOTES.txt
index b4c3179..7c8b7fe 100644
--- a/NOTES.txt
+++ b/NOTES.txt
@@ -1,4 +1,14 @@
+23 Apr 05 (memcheck-on-amd64 notes)
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+If a thread is given an initial stack with address range [lo .. hi],
+we need to tell memcheck that the area [lo - VGA_STACK_REDZONE_SIZE
+.. hi] is valid, rather than just [lo .. hi] as has been the case on
+x86-only systems. However, am not sure where to look for the
+call into memcheck that states the new stack area.
+
+
9 Apr 05 (starting work on memcheck for 32/64-bit and big/little endian)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* get rid of memcheck/mc_asm.h and include/tool_asm.h. I think
diff --git a/coregrind/amd64/core_arch.h b/coregrind/amd64/core_arch.h
index 5fdefd3..f2296f8 100644
--- a/coregrind/amd64/core_arch.h
+++ b/coregrind/amd64/core_arch.h
@@ -76,9 +76,6 @@
asm("movq %%rbp, %0" : "=r" (lval)); \
} while (0)
-// On AMD64, it's ok to access up to 128 bytes below %rsp.
-// The signal handler needs to know this.
-#define VGA_STACK_REDZONE_SIZE 128
/* ---------------------------------------------------------------------
Architecture-specific part of a ThreadState
diff --git a/coregrind/x86/core_arch.h b/coregrind/x86/core_arch.h
index 69c23c9..c2d2186 100644
--- a/coregrind/x86/core_arch.h
+++ b/coregrind/x86/core_arch.h
@@ -76,10 +76,6 @@
asm("movl %%ebp, %0" : "=r" (ebp)); \
} while (0)
-// On X86, any access below %esp is illegal.
-// The signal handler needs to know this.
-#define VGA_STACK_REDZONE_SIZE 0
-
//extern const Char VG_(helper_wrapper_before)[]; /* in dispatch.S */
//extern const Char VG_(helper_wrapper_return)[]; /* in dispatch.S */
diff --git a/include/amd64/tool_arch.h b/include/amd64/tool_arch.h
index 5acac5a..3531fb2 100644
--- a/include/amd64/tool_arch.h
+++ b/include/amd64/tool_arch.h
@@ -30,15 +30,20 @@
#ifndef __AMD64_TOOL_ARCH_H
#define __AMD64_TOOL_ARCH_H
-/*====================================================================*/
-/*=== Registers, etc ===*/
-/*====================================================================*/
-#define VGA_REGPARM(n)
+#define VGA_REGPARM(n) /* */
+
#define VGA_MIN_INSTR_SIZE 1
#define VGA_MAX_INSTR_SIZE 16
+
+/* How many bytes below the stack pointer are validly addressible?
+ On amd64, the answer is: 128.
+*/
+#define VGA_STACK_REDZONE_SIZE 128
+
+
#endif // __AMD64_TOOL_ARCH_H
/*--------------------------------------------------------------------*/
diff --git a/include/x86/tool_arch.h b/include/x86/tool_arch.h
index 7c7d952..1159c4f 100644
--- a/include/x86/tool_arch.h
+++ b/include/x86/tool_arch.h
@@ -30,16 +30,20 @@
#ifndef __X86_TOOL_ARCH_H
#define __X86_TOOL_ARCH_H
-/*====================================================================*/
-/*=== Registers, etc ===*/
-/*====================================================================*/
#define VGA_REGPARM(n) __attribute__((regparm(n)))
+
#define VGA_MIN_INSTR_SIZE 1
#define VGA_MAX_INSTR_SIZE 16
+/* How many bytes below the stack pointer are validly addressible?
+ On x86, the answer is: none.
+*/
+#define VGA_STACK_REDZONE_SIZE 0
+
+
#endif // __X86_TOOL_ARCH_H
/*--------------------------------------------------------------------*/
diff --git a/memcheck/mac_shared.h b/memcheck/mac_shared.h
index c49e2b9..8aa9322 100644
--- a/memcheck/mac_shared.h
+++ b/memcheck/mac_shared.h
@@ -437,163 +437,163 @@
factoring, rather than eg. using function pointers.
*/
-#define SP_UPDATE_HANDLERS(ALIGNED4_NEW, ALIGNED4_DIE, \
- ALIGNED8_NEW, ALIGNED8_DIE, \
- UNALIGNED_NEW, UNALIGNED_DIE) \
- \
-void VGA_REGPARM(1) MAC_(new_mem_stack_4)(Addr new_SP) \
-{ \
- PROF_EVENT(110, "new_mem_stack_4"); \
- if (VG_IS_4_ALIGNED(new_SP)) { \
- ALIGNED4_NEW ( new_SP ); \
- } else { \
- UNALIGNED_NEW ( new_SP, 4 ); \
- } \
-} \
- \
-void VGA_REGPARM(1) MAC_(die_mem_stack_4)(Addr new_SP) \
-{ \
- PROF_EVENT(120, "die_mem_stack_4"); \
- if (VG_IS_4_ALIGNED(new_SP)) { \
- ALIGNED4_DIE ( new_SP-4 ); \
- } else { \
- UNALIGNED_DIE ( new_SP-4, 4 ); \
- } \
-} \
- \
-void VGA_REGPARM(1) MAC_(new_mem_stack_8)(Addr new_SP) \
-{ \
- PROF_EVENT(111, "new_mem_stack_8"); \
- if (VG_IS_8_ALIGNED(new_SP)) { \
- ALIGNED8_NEW ( new_SP ); \
- } else if (VG_IS_4_ALIGNED(new_SP)) { \
- ALIGNED4_NEW ( new_SP ); \
- ALIGNED4_NEW ( new_SP+4 ); \
- } else { \
- UNALIGNED_NEW ( new_SP, 8 ); \
- } \
-} \
- \
-void VGA_REGPARM(1) MAC_(die_mem_stack_8)(Addr new_SP) \
-{ \
- PROF_EVENT(121, "die_mem_stack_8"); \
- if (VG_IS_8_ALIGNED(new_SP)) { \
- ALIGNED8_DIE ( new_SP-8 ); \
- } else if (VG_IS_4_ALIGNED(new_SP)) { \
- ALIGNED4_DIE ( new_SP-8 ); \
- ALIGNED4_DIE ( new_SP-4 ); \
- } else { \
- UNALIGNED_DIE ( new_SP-8, 8 ); \
- } \
-} \
- \
-void VGA_REGPARM(1) MAC_(new_mem_stack_12)(Addr new_SP) \
-{ \
- PROF_EVENT(112, "new_mem_stack_12"); \
- if (VG_IS_8_ALIGNED(new_SP)) { \
- ALIGNED8_NEW ( new_SP ); \
- ALIGNED4_NEW ( new_SP+8 ); \
- } else if (VG_IS_4_ALIGNED(new_SP)) { \
- ALIGNED4_NEW ( new_SP ); \
- ALIGNED8_NEW ( new_SP+4 ); \
- } else { \
- UNALIGNED_NEW ( new_SP, 12 ); \
- } \
-} \
- \
-void VGA_REGPARM(1) MAC_(die_mem_stack_12)(Addr new_SP) \
-{ \
- PROF_EVENT(122, "die_mem_stack_12"); \
- /* Note the -12 in the test */ \
- if (VG_IS_8_ALIGNED(new_SP-12)) { \
- ALIGNED8_DIE ( new_SP-12 ); \
- ALIGNED4_DIE ( new_SP-4 ); \
- } else if (VG_IS_4_ALIGNED(new_SP)) { \
- ALIGNED4_DIE ( new_SP-12 ); \
- ALIGNED8_DIE ( new_SP-8 ); \
- } else { \
- UNALIGNED_DIE ( new_SP-12, 12 ); \
- } \
-} \
- \
-void VGA_REGPARM(1) MAC_(new_mem_stack_16)(Addr new_SP) \
-{ \
- PROF_EVENT(113, "new_mem_stack_16"); \
- if (VG_IS_8_ALIGNED(new_SP)) { \
- ALIGNED8_NEW ( new_SP ); \
- ALIGNED8_NEW ( new_SP+8 ); \
- } else if (VG_IS_4_ALIGNED(new_SP)) { \
- ALIGNED4_NEW ( new_SP ); \
- ALIGNED8_NEW ( new_SP+4 ); \
- ALIGNED4_NEW ( new_SP+12 ); \
- } else { \
- UNALIGNED_NEW ( new_SP, 16 ); \
- } \
-} \
- \
-void VGA_REGPARM(1) MAC_(die_mem_stack_16)(Addr new_SP) \
-{ \
- PROF_EVENT(123, "die_mem_stack_16"); \
- if (VG_IS_8_ALIGNED(new_SP)) { \
- ALIGNED8_DIE ( new_SP-16 ); \
- ALIGNED8_DIE ( new_SP-8 ); \
- } else if (VG_IS_4_ALIGNED(new_SP)) { \
- ALIGNED4_DIE ( new_SP-16 ); \
- ALIGNED8_DIE ( new_SP-12 ); \
- ALIGNED4_DIE ( new_SP-4 ); \
- } else { \
- UNALIGNED_DIE ( new_SP-16, 16 ); \
- } \
-} \
- \
-void VGA_REGPARM(1) MAC_(new_mem_stack_32)(Addr new_SP) \
-{ \
- PROF_EVENT(114, "new_mem_stack_32"); \
- if (VG_IS_8_ALIGNED(new_SP)) { \
- ALIGNED8_NEW ( new_SP ); \
- ALIGNED8_NEW ( new_SP+8 ); \
- ALIGNED8_NEW ( new_SP+16 ); \
- ALIGNED8_NEW ( new_SP+24 ); \
- } else if (VG_IS_4_ALIGNED(new_SP)) { \
- ALIGNED4_NEW ( new_SP ); \
- ALIGNED8_NEW ( new_SP+4 ); \
- ALIGNED8_NEW ( new_SP+12 ); \
- ALIGNED8_NEW ( new_SP+20 ); \
- ALIGNED4_NEW ( new_SP+28 ); \
- } else { \
- UNALIGNED_NEW ( new_SP, 32 ); \
- } \
-} \
- \
-void VGA_REGPARM(1) MAC_(die_mem_stack_32)(Addr new_SP) \
-{ \
- PROF_EVENT(124, "die_mem_stack_32"); \
- if (VG_IS_8_ALIGNED(new_SP)) { \
- ALIGNED8_DIE ( new_SP-32 ); \
- ALIGNED8_DIE ( new_SP-24 ); \
- ALIGNED8_DIE ( new_SP-16 ); \
- ALIGNED8_DIE ( new_SP- 8 ); \
- } else if (VG_IS_4_ALIGNED(new_SP)) { \
- ALIGNED4_DIE ( new_SP-32 ); \
- ALIGNED8_DIE ( new_SP-28 ); \
- ALIGNED8_DIE ( new_SP-20 ); \
- ALIGNED8_DIE ( new_SP-12 ); \
- ALIGNED4_DIE ( new_SP-4 ); \
- } else { \
- UNALIGNED_DIE ( new_SP-32, 32 ); \
- } \
-} \
- \
-void MAC_(new_mem_stack) ( Addr a, SizeT len ) \
-{ \
- PROF_EVENT(115, "new_mem_stack"); \
- UNALIGNED_NEW ( a, len ); \
-} \
- \
-void MAC_(die_mem_stack) ( Addr a, SizeT len ) \
-{ \
- PROF_EVENT(125, "die_mem_stack"); \
- UNALIGNED_DIE ( a, len ); \
+#define SP_UPDATE_HANDLERS(ALIGNED4_NEW, ALIGNED4_DIE, \
+ ALIGNED8_NEW, ALIGNED8_DIE, \
+ UNALIGNED_NEW, UNALIGNED_DIE) \
+ \
+void VGA_REGPARM(1) MAC_(new_mem_stack_4)(Addr new_SP) \
+{ \
+ PROF_EVENT(110, "new_mem_stack_4"); \
+ if (VG_IS_4_ALIGNED(new_SP)) { \
+ ALIGNED4_NEW ( -VGA_STACK_REDZONE_SIZE + new_SP ); \
+ } else { \
+ UNALIGNED_NEW ( -VGA_STACK_REDZONE_SIZE + new_SP, 4 ); \
+ } \
+} \
+ \
+void VGA_REGPARM(1) MAC_(die_mem_stack_4)(Addr new_SP) \
+{ \
+ PROF_EVENT(120, "die_mem_stack_4"); \
+ if (VG_IS_4_ALIGNED(new_SP)) { \
+ ALIGNED4_DIE ( -VGA_STACK_REDZONE_SIZE + new_SP-4 ); \
+ } else { \
+ UNALIGNED_DIE ( -VGA_STACK_REDZONE_SIZE + new_SP-4, 4 ); \
+ } \
+} \
+ \
+void VGA_REGPARM(1) MAC_(new_mem_stack_8)(Addr new_SP) \
+{ \
+ PROF_EVENT(111, "new_mem_stack_8"); \
+ if (VG_IS_8_ALIGNED(new_SP)) { \
+ ALIGNED8_NEW ( -VGA_STACK_REDZONE_SIZE + new_SP ); \
+ } else if (VG_IS_4_ALIGNED(new_SP)) { \
+ ALIGNED4_NEW ( -VGA_STACK_REDZONE_SIZE + new_SP ); \
+ ALIGNED4_NEW ( -VGA_STACK_REDZONE_SIZE + new_SP+4 ); \
+ } else { \
+ UNALIGNED_NEW ( -VGA_STACK_REDZONE_SIZE + new_SP, 8 ); \
+ } \
+} \
+ \
+void VGA_REGPARM(1) MAC_(die_mem_stack_8)(Addr new_SP) \
+{ \
+ PROF_EVENT(121, "die_mem_stack_8"); \
+ if (VG_IS_8_ALIGNED(new_SP)) { \
+ ALIGNED8_DIE ( -VGA_STACK_REDZONE_SIZE + new_SP-8 ); \
+ } else if (VG_IS_4_ALIGNED(new_SP)) { \
+ ALIGNED4_DIE ( -VGA_STACK_REDZONE_SIZE + new_SP-8 ); \
+ ALIGNED4_DIE ( -VGA_STACK_REDZONE_SIZE + new_SP-4 ); \
+ } else { \
+ UNALIGNED_DIE ( -VGA_STACK_REDZONE_SIZE + new_SP-8, 8 ); \
+ } \
+} \
+ \
+void VGA_REGPARM(1) MAC_(new_mem_stack_12)(Addr new_SP) \
+{ \
+ PROF_EVENT(112, "new_mem_stack_12"); \
+ if (VG_IS_8_ALIGNED(new_SP)) { \
+ ALIGNED8_NEW ( -VGA_STACK_REDZONE_SIZE + new_SP ); \
+ ALIGNED4_NEW ( -VGA_STACK_REDZONE_SIZE + new_SP+8 ); \
+ } else if (VG_IS_4_ALIGNED(new_SP)) { \
+ ALIGNED4_NEW ( -VGA_STACK_REDZONE_SIZE + new_SP ); \
+ ALIGNED8_NEW ( -VGA_STACK_REDZONE_SIZE + new_SP+4 ); \
+ } else { \
+ UNALIGNED_NEW ( -VGA_STACK_REDZONE_SIZE + new_SP, 12 ); \
+ } \
+} \
+ \
+void VGA_REGPARM(1) MAC_(die_mem_stack_12)(Addr new_SP) \
+{ \
+ PROF_EVENT(122, "die_mem_stack_12"); \
+ /* Note the -12 in the test */ \
+ if (VG_IS_8_ALIGNED(new_SP-12)) { \
+ ALIGNED8_DIE ( -VGA_STACK_REDZONE_SIZE + new_SP-12 ); \
+ ALIGNED4_DIE ( -VGA_STACK_REDZONE_SIZE + new_SP-4 ); \
+ } else if (VG_IS_4_ALIGNED(new_SP)) { \
+ ALIGNED4_DIE ( -VGA_STACK_REDZONE_SIZE + new_SP-12 ); \
+ ALIGNED8_DIE ( -VGA_STACK_REDZONE_SIZE + new_SP-8 ); \
+ } else { \
+ UNALIGNED_DIE ( -VGA_STACK_REDZONE_SIZE + new_SP-12, 12 ); \
+ } \
+} \
+ \
+void VGA_REGPARM(1) MAC_(new_mem_stack_16)(Addr new_SP) \
+{ \
+ PROF_EVENT(113, "new_mem_stack_16"); \
+ if (VG_IS_8_ALIGNED(new_SP)) { \
+ ALIGNED8_NEW ( -VGA_STACK_REDZONE_SIZE + new_SP ); \
+ ALIGNED8_NEW ( -VGA_STACK_REDZONE_SIZE + new_SP+8 ); \
+ } else if (VG_IS_4_ALIGNED(new_SP)) { \
+ ALIGNED4_NEW ( -VGA_STACK_REDZONE_SIZE + new_SP ); \
+ ALIGNED8_NEW ( -VGA_STACK_REDZONE_SIZE + new_SP+4 ); \
+ ALIGNED4_NEW ( -VGA_STACK_REDZONE_SIZE + new_SP+12 ); \
+ } else { \
+ UNALIGNED_NEW ( -VGA_STACK_REDZONE_SIZE + new_SP, 16 ); \
+ } \
+} \
+ \
+void VGA_REGPARM(1) MAC_(die_mem_stack_16)(Addr new_SP) \
+{ \
+ PROF_EVENT(123, "die_mem_stack_16"); \
+ if (VG_IS_8_ALIGNED(new_SP)) { \
+ ALIGNED8_DIE ( -VGA_STACK_REDZONE_SIZE + new_SP-16 ); \
+ ALIGNED8_DIE ( -VGA_STACK_REDZONE_SIZE + new_SP-8 ); \
+ } else if (VG_IS_4_ALIGNED(new_SP)) { \
+ ALIGNED4_DIE ( -VGA_STACK_REDZONE_SIZE + new_SP-16 ); \
+ ALIGNED8_DIE ( -VGA_STACK_REDZONE_SIZE + new_SP-12 ); \
+ ALIGNED4_DIE ( -VGA_STACK_REDZONE_SIZE + new_SP-4 ); \
+ } else { \
+ UNALIGNED_DIE ( -VGA_STACK_REDZONE_SIZE + new_SP-16, 16 ); \
+ } \
+} \
+ \
+void VGA_REGPARM(1) MAC_(new_mem_stack_32)(Addr new_SP) \
+{ \
+ PROF_EVENT(114, "new_mem_stack_32"); \
+ if (VG_IS_8_ALIGNED(new_SP)) { \
+ ALIGNED8_NEW ( -VGA_STACK_REDZONE_SIZE + new_SP ); \
+ ALIGNED8_NEW ( -VGA_STACK_REDZONE_SIZE + new_SP+8 ); \
+ ALIGNED8_NEW ( -VGA_STACK_REDZONE_SIZE + new_SP+16 ); \
+ ALIGNED8_NEW ( -VGA_STACK_REDZONE_SIZE + new_SP+24 ); \
+ } else if (VG_IS_4_ALIGNED(new_SP)) { \
+ ALIGNED4_NEW ( -VGA_STACK_REDZONE_SIZE + new_SP ); \
+ ALIGNED8_NEW ( -VGA_STACK_REDZONE_SIZE + new_SP+4 ); \
+ ALIGNED8_NEW ( -VGA_STACK_REDZONE_SIZE + new_SP+12 ); \
+ ALIGNED8_NEW ( -VGA_STACK_REDZONE_SIZE + new_SP+20 ); \
+ ALIGNED4_NEW ( -VGA_STACK_REDZONE_SIZE + new_SP+28 ); \
+ } else { \
+ UNALIGNED_NEW ( -VGA_STACK_REDZONE_SIZE + new_SP, 32 ); \
+ } \
+} \
+ \
+void VGA_REGPARM(1) MAC_(die_mem_stack_32)(Addr new_SP) \
+{ \
+ PROF_EVENT(124, "die_mem_stack_32"); \
+ if (VG_IS_8_ALIGNED(new_SP)) { \
+ ALIGNED8_DIE ( -VGA_STACK_REDZONE_SIZE + new_SP-32 ); \
+ ALIGNED8_DIE ( -VGA_STACK_REDZONE_SIZE + new_SP-24 ); \
+ ALIGNED8_DIE ( -VGA_STACK_REDZONE_SIZE + new_SP-16 ); \
+ ALIGNED8_DIE ( -VGA_STACK_REDZONE_SIZE + new_SP- 8 ); \
+ } else if (VG_IS_4_ALIGNED(new_SP)) { \
+ ALIGNED4_DIE ( -VGA_STACK_REDZONE_SIZE + new_SP-32 ); \
+ ALIGNED8_DIE ( -VGA_STACK_REDZONE_SIZE + new_SP-28 ); \
+ ALIGNED8_DIE ( -VGA_STACK_REDZONE_SIZE + new_SP-20 ); \
+ ALIGNED8_DIE ( -VGA_STACK_REDZONE_SIZE + new_SP-12 ); \
+ ALIGNED4_DIE ( -VGA_STACK_REDZONE_SIZE + new_SP-4 ); \
+ } else { \
+ UNALIGNED_DIE ( -VGA_STACK_REDZONE_SIZE + new_SP-32, 32 ); \
+ } \
+} \
+ \
+void MAC_(new_mem_stack) ( Addr a, SizeT len ) \
+{ \
+ PROF_EVENT(115, "new_mem_stack"); \
+ UNALIGNED_NEW ( -VGA_STACK_REDZONE_SIZE + a, len ); \
+} \
+ \
+void MAC_(die_mem_stack) ( Addr a, SizeT len ) \
+{ \
+ PROF_EVENT(125, "die_mem_stack"); \
+ UNALIGNED_DIE ( -VGA_STACK_REDZONE_SIZE + a, len ); \
}
#endif /* __MAC_SHARED_H */