Commit b0cb83ba authored by David S. Miller's avatar David S. Miller

Stack overflow debugging support.

From Kanoj Sarcar.
parent 3da06a3a
...@@ -48,6 +48,11 @@ else ...@@ -48,6 +48,11 @@ else
AFLAGS += -m64 -mcpu=ultrasparc $(CC_UNDECL) AFLAGS += -m64 -mcpu=ultrasparc $(CC_UNDECL)
endif endif
ifeq ($(CONFIG_MCOUNT),y)
CFLAGS := $(subst -fomit-frame-pointer,,$(CFLAGS))
CFLAGS := $(CFLAGS) -pg
endif
LINKFLAGS = -T arch/sparc64/vmlinux.lds LINKFLAGS = -T arch/sparc64/vmlinux.lds
HEAD := arch/sparc64/kernel/head.o arch/sparc64/kernel/init_task.o HEAD := arch/sparc64/kernel/head.o arch/sparc64/kernel/init_task.o
......
...@@ -289,6 +289,10 @@ if [ "$CONFIG_DEBUG_KERNEL" != "n" ]; then ...@@ -289,6 +289,10 @@ if [ "$CONFIG_DEBUG_KERNEL" != "n" ]; then
bool ' Verbose BUG() reporting (adds 70K)' CONFIG_DEBUG_BUGVERBOSE bool ' Verbose BUG() reporting (adds 70K)' CONFIG_DEBUG_BUGVERBOSE
bool ' D-cache flush debugging' CONFIG_DEBUG_DCFLUSH bool ' D-cache flush debugging' CONFIG_DEBUG_DCFLUSH
fi fi
bool 'Stack Overflow Detection Support' CONFIG_STACK_DEBUG
if [ "$CONFIG_STACK_DEBUG" = "y" ] ; then
define_bool CONFIG_MCOUNT y
fi
endmenu endmenu
......
...@@ -139,6 +139,11 @@ EXPORT_SYMBOL(__global_sti); ...@@ -139,6 +139,11 @@ EXPORT_SYMBOL(__global_sti);
EXPORT_SYMBOL(__global_save_flags); EXPORT_SYMBOL(__global_save_flags);
EXPORT_SYMBOL(__global_restore_flags); EXPORT_SYMBOL(__global_restore_flags);
#if defined(CONFIG_MCOUNT)
extern void mcount(void);
EXPORT_SYMBOL(mcount);
#endif
/* Per-CPU information table */ /* Per-CPU information table */
EXPORT_SYMBOL(cpu_data); EXPORT_SYMBOL(cpu_data);
......
...@@ -16,6 +16,6 @@ obj-y := PeeCeeI.o blockops.o debuglocks.o strlen.o strncmp.o \ ...@@ -16,6 +16,6 @@ obj-y := PeeCeeI.o blockops.o debuglocks.o strlen.o strncmp.o \
VIScopy.o VISbzero.o VISmemset.o VIScsum.o VIScsumcopy.o \ VIScopy.o VISbzero.o VISmemset.o VIScsum.o VIScsumcopy.o \
VIScsumcopyusr.o VISsave.o atomic.o rwlock.o bitops.o \ VIScsumcopyusr.o VISsave.o atomic.o rwlock.o bitops.o \
dec_and_lock.o U3memcpy.o U3copy_from_user.o U3copy_to_user.o \ dec_and_lock.o U3memcpy.o U3copy_from_user.o U3copy_to_user.o \
U3copy_in_user.o U3copy_in_user.o mcount.o
include $(TOPDIR)/Rules.make include $(TOPDIR)/Rules.make
/*
* Copyright (C) 2000 Anton Blanchard (anton@linuxcare.com)
*
* This file implements mcount(), which is used to collect profiling data.
* This can also be tweaked for kernel stack overflow detection.
*/
#include <linux/config.h>
#include <linux/linkage.h>
#include <asm/ptrace.h>
#include <asm/thread_info.h>
/*
* This is the main variant and is called by C code. GCC's -pg option
* automatically instruments every C function with a call to this.
*/
#ifdef CONFIG_STACK_DEBUG
#define OVSTACKSIZE 4096 /* lets hope this is enough */
.data
.align 8
panicstring:
.asciz "Stack overflow\n"
.align 8
ovstack:
.skip OVSTACKSIZE
#endif
.text
.align 32
.globl mcount
mcount:
#ifdef CONFIG_STACK_DEBUG
/*
* Check whether %sp is dangerously low.
*/
add %g6, (TI_FPREGS + 256 + 192), %g5! where does task_struct+frame end?
sub %g5, STACK_BIAS, %g5
cmp %sp, %g5
bg,pt %xcc, 1f
sethi %hi(panicstring), %g5
sethi %hi(ovstack), %g7 ! cant move to panic stack fast enough
or %g7, %lo(ovstack), %g7
add %g7, OVSTACKSIZE, %g7
sub %g7, STACK_BIAS, %g7
mov %g7, %sp
call prom_printf
or %g5, %lo(panicstring), %o0
call prom_halt
nop
#endif
1: retl
nop
...@@ -19,3 +19,6 @@ obj-y := bootstr.o devops.o init.o memory.o misc.o \ ...@@ -19,3 +19,6 @@ obj-y := bootstr.o devops.o init.o memory.o misc.o \
$(CC) $(AFLAGS) -ansi -c $< -o $*.o $(CC) $(AFLAGS) -ansi -c $< -o $*.o
include $(TOPDIR)/Rules.make include $(TOPDIR)/Rules.make
%.o: %.c
$(CC) $(subst -pg,,$(CFLAGS)) -c $<
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment