]> git.hungrycats.org Git - linux/commitdiff
Stack overflow debugging support.
authorDavid S. Miller <davem@nuts.ninka.net>
Wed, 13 Mar 2002 11:08:29 +0000 (03:08 -0800)
committerDavid S. Miller <davem@nuts.ninka.net>
Wed, 13 Mar 2002 11:08:29 +0000 (03:08 -0800)
From Kanoj Sarcar.

arch/sparc64/Makefile
arch/sparc64/config.in
arch/sparc64/kernel/sparc64_ksyms.c
arch/sparc64/lib/Makefile
arch/sparc64/lib/mcount.S [new file with mode: 0644]
arch/sparc64/prom/Makefile

index fb2c66d0a3e32fb1ec4ca6648d313cda6c2e6901..fd20395da6c80f3ac4bb019ad7d7325eb5ee975b 100644 (file)
@@ -48,6 +48,11 @@ else
   AFLAGS += -m64 -mcpu=ultrasparc $(CC_UNDECL)
 endif
 
+ifeq ($(CONFIG_MCOUNT),y)
+  CFLAGS := $(subst -fomit-frame-pointer,,$(CFLAGS))
+  CFLAGS := $(CFLAGS) -pg
+endif
+
 LINKFLAGS = -T arch/sparc64/vmlinux.lds
 
 HEAD := arch/sparc64/kernel/head.o arch/sparc64/kernel/init_task.o
index ffe0cb1738ee107521c48e7592d721497d2463b3..ca9aad5a622e580c5bba1173365d0c5310e2ecb4 100644 (file)
@@ -289,6 +289,10 @@ if [ "$CONFIG_DEBUG_KERNEL" != "n" ]; then
    bool '  Verbose BUG() reporting (adds 70K)' CONFIG_DEBUG_BUGVERBOSE
    bool '  D-cache flush debugging' CONFIG_DEBUG_DCFLUSH
 fi
+bool 'Stack Overflow Detection Support' CONFIG_STACK_DEBUG
+if [ "$CONFIG_STACK_DEBUG" = "y" ] ; then
+   define_bool CONFIG_MCOUNT y
+fi
 
 endmenu
 
index 37e76a2442db27212ab7175a48881c0d8f974f76..250a4e2641d8f77ed7f1ea937fece7d9769aebcd 100644 (file)
@@ -139,6 +139,11 @@ EXPORT_SYMBOL(__global_sti);
 EXPORT_SYMBOL(__global_save_flags);
 EXPORT_SYMBOL(__global_restore_flags);
 
+#if defined(CONFIG_MCOUNT)
+extern void mcount(void);
+EXPORT_SYMBOL(mcount);
+#endif
+
 /* Per-CPU information table */
 EXPORT_SYMBOL(cpu_data);
 
index 7f8dc10535ba3fdac4437638325facf8c28d0ad0..f7c7329353f7215c343c8b68f18739ac04122a72 100644 (file)
@@ -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 \
         VIScsumcopyusr.o VISsave.o atomic.o rwlock.o bitops.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
diff --git a/arch/sparc64/lib/mcount.S b/arch/sparc64/lib/mcount.S
new file mode 100644 (file)
index 0000000..46f0085
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * 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
index 7387b9c24dfa46b31c779070f394f64397c9fa0c..736bcbaae88fed953f7fd061998ddbe0771139dc 100644 (file)
@@ -19,3 +19,6 @@ obj-y   := bootstr.o devops.o init.o memory.o misc.o \
        $(CC) $(AFLAGS) -ansi -c $< -o $*.o
 
 include $(TOPDIR)/Rules.make
+
+%.o: %.c
+       $(CC) $(subst -pg,,$(CFLAGS)) -c $<