Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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>
  • Loading branch information...
commit 40aaad4d35ba7afd21348115fb59cf8fd4aa1694 1 parent bd9d9e6
@penberg authored
View
1  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 \
View
1  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 \
View
20 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();
+ }
+}
View
6 include/arch/debug.h
@@ -0,0 +1,6 @@
+#ifndef JATO_ARCH_DEBUG_H
+#define JATO_ARCH_DEBUG_H
+
+void check_stack_align(void);
+
+#endif
View
5 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);
Please sign in to comment.
Something went wrong with that request. Please try again.