diff options
author | Pekka Enberg <penberg@kernel.org> | 2013-03-26 10:23:06 +0200 |
---|---|---|
committer | Pekka Enberg <penberg@kernel.org> | 2013-03-26 11:32:44 +0200 |
commit | 40aaad4d35ba7afd21348115fb59cf8fd4aa1694 (patch) | |
tree | 5d5da30fe4c06a2e655cecf4b3364a9fdb3ae734 | |
parent | bd9d9e6c42b313038b24510051ed8b735b98412e (diff) | |
download | jato-40aaad4d35ba7afd21348115fb59cf8fd4aa1694.tar.gz |
x86: Stack alignment debug check
Add stack alignment check to stack debugging that is enabled by the
"-Xdebug:stack" command line option.
Signed-off-by: Pekka Enberg <penberg@kernel.org>
-rw-r--r-- | arch/x86/Makefile_32 | 1 | ||||
-rw-r--r-- | arch/x86/Makefile_64 | 1 | ||||
-rw-r--r-- | arch/x86/debug.c | 20 | ||||
-rw-r--r-- | include/arch/debug.h | 6 | ||||
-rw-r--r-- | jit/trampoline.c | 5 |
5 files changed, 33 insertions, 0 deletions
diff --git a/arch/x86/Makefile_32 b/arch/x86/Makefile_32 index 033c9f40..2ecb3f1a 100644 --- a/arch/x86/Makefile_32 +++ b/arch/x86/Makefile_32 @@ -2,6 +2,7 @@ ARCH_OBJS = \ arch/x86/args.o \ arch/x86/call.o \ arch/x86/cmpxchg_32.o \ + arch/x86/debug.o \ arch/x86/disassemble.o \ arch/x86/emit_32.o \ arch/x86/encode.o \ diff --git a/arch/x86/Makefile_64 b/arch/x86/Makefile_64 index 42427cf4..668757cc 100644 --- a/arch/x86/Makefile_64 +++ b/arch/x86/Makefile_64 @@ -4,6 +4,7 @@ ARCH_LIBS = -L/usr/lib64/libffi -lffi ARCH_OBJS = \ arch/x86/args.o \ arch/x86/call.o \ + arch/x86/debug.o \ arch/x86/disassemble.o \ arch/x86/emit_64.o \ arch/x86/encode.o \ diff --git a/arch/x86/debug.c b/arch/x86/debug.c new file mode 100644 index 00000000..6c8d9a6a --- /dev/null +++ b/arch/x86/debug.c @@ -0,0 +1,20 @@ +#include "arch/debug.h" + +#include "arch/stack-frame.h" + +#include <stdlib.h> +#include <stdio.h> + +void check_stack_align(void) +{ +#ifdef CONFIG_X86_32 + register unsigned long fp __asm__("ebp"); +#else + register unsigned long fp __asm__("rbp"); +#endif + + if (fp % X86_STACK_ALIGN != 0) { + fprintf(stderr, "Error: stack is %lu bytes misaligned.\n", fp % X86_STACK_ALIGN); + abort(); + } +} diff --git a/include/arch/debug.h b/include/arch/debug.h new file mode 100644 index 00000000..3d5e5e3c --- /dev/null +++ b/include/arch/debug.h @@ -0,0 +1,6 @@ +#ifndef JATO_ARCH_DEBUG_H +#define JATO_ARCH_DEBUG_H + +void check_stack_align(void); + +#endif diff --git a/jit/trampoline.c b/jit/trampoline.c index 95dd4f93..5329b4c2 100644 --- a/jit/trampoline.c +++ b/jit/trampoline.c @@ -25,11 +25,13 @@ */ #include "arch/memory.h" +#include "arch/debug.h" #include "jit/compiler.h" #include "jit/cu-mapping.h" #include "jit/emit-code.h" #include "jit/exception.h" +#include "jit/debug.h" #include "vm/stack-trace.h" #include "vm/natives.h" @@ -97,6 +99,9 @@ void *jit_magic_trampoline(struct compilation_unit *cu) unsigned long state; void *ret; + if (opt_debug_stack) + check_stack_align(); + if (opt_trace_magic_trampoline) trace_magic_trampoline(cu); |