]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - arch/x86/oprofile/backtrace.c
Merge branch 'for-linus' of git://git.o-hand.com/linux-rpurdie-leds
[linux-2.6-omap-h63xx.git] / arch / x86 / oprofile / backtrace.c
index c049ce414f010359c0c312e08c6bd903b683797d..04df67f8a7ba8f2f8c397832eec1b6fb0180ef8d 100644 (file)
 #include <linux/mm.h>
 #include <asm/ptrace.h>
 #include <asm/uaccess.h>
+#include <asm/stacktrace.h>
 
-struct frame_head {
-       struct frame_head * ebp;
-       unsigned long ret;
-} __attribute__((packed));
+static void backtrace_warning_symbol(void *data, char *msg,
+                                    unsigned long symbol)
+{
+       /* Ignore warnings */
+}
 
-static struct frame_head *
-dump_kernel_backtrace(struct frame_head * head)
+static void backtrace_warning(void *data, char *msg)
 {
-       oprofile_add_trace(head->ret);
+       /* Ignore warnings */
+}
 
-       /* frame pointers should strictly progress back up the stack
-        * (towards higher addresses) */
-       if (head >= head->ebp)
-               return NULL;
+static int backtrace_stack(void *data, char *name)
+{
+       /* Yes, we want all stacks */
+       return 0;
+}
 
-       return head->ebp;
+static void backtrace_address(void *data, unsigned long addr, int reliable)
+{
+       unsigned int *depth = data;
+
+       if ((*depth)--)
+               oprofile_add_trace(addr);
 }
 
-static struct frame_head *
-dump_user_backtrace(struct frame_head * head)
+static struct stacktrace_ops backtrace_ops = {
+       .warning = backtrace_warning,
+       .warning_symbol = backtrace_warning_symbol,
+       .stack = backtrace_stack,
+       .address = backtrace_address,
+};
+
+struct frame_head {
+       struct frame_head *bp;
+       unsigned long ret;
+} __attribute__((packed));
+
+static struct frame_head *dump_user_backtrace(struct frame_head *head)
 {
        struct frame_head bufhead[2];
 
@@ -47,78 +66,22 @@ dump_user_backtrace(struct frame_head * head)
 
        /* frame pointers should strictly progress back up the stack
         * (towards higher addresses) */
-       if (head >= bufhead[0].ebp)
+       if (head >= bufhead[0].bp)
                return NULL;
 
-       return bufhead[0].ebp;
-}
-
-/*
- * |             | /\ Higher addresses
- * |             |
- * --------------- stack base (address of current_thread_info)
- * | thread info |
- * .             .
- * |    stack    |
- * --------------- saved regs->ebp value if valid (frame_head address)
- * .             .
- * --------------- saved regs->rsp value if x86_64
- * |             |
- * --------------- struct pt_regs * stored on stack if 32-bit
- * |             |
- * .             .
- * |             |
- * --------------- %esp
- * |             |
- * |             | \/ Lower addresses
- *
- * Thus, regs (or regs->rsp for x86_64) <-> stack base restricts the
- * valid(ish) ebp values. Note: (1) for x86_64, NMI and several other
- * exceptions use special stacks, maintained by the interrupt stack table
- * (IST). These stacks are set up in trap_init() in
- * arch/x86_64/kernel/traps.c. Thus, for x86_64, regs now does not point
- * to the kernel stack; instead, it points to some location on the NMI
- * stack. On the other hand, regs->rsp is the stack pointer saved when the
- * NMI occurred. (2) For 32-bit, regs->esp is not valid because the
- * processor does not save %esp on the kernel stack when interrupts occur
- * in the kernel mode.
- */
-#ifdef CONFIG_FRAME_POINTER
-static int valid_kernel_stack(struct frame_head * head, struct pt_regs * regs)
-{
-       unsigned long headaddr = (unsigned long)head;
-#ifdef CONFIG_X86_64
-       unsigned long stack = (unsigned long)regs->rsp;
-#else
-       unsigned long stack = (unsigned long)regs;
-#endif
-       unsigned long stack_base = (stack & ~(THREAD_SIZE - 1)) + THREAD_SIZE;
-
-       return headaddr > stack && headaddr < stack_base;
+       return bufhead[0].bp;
 }
-#else
-/* without fp, it's just junk */
-static int valid_kernel_stack(struct frame_head * head, struct pt_regs * regs)
-{
-       return 0;
-}
-#endif
-
 
 void
 x86_backtrace(struct pt_regs * const regs, unsigned int depth)
 {
-       struct frame_head *head;
-
-#ifdef CONFIG_X86_64
-       head = (struct frame_head *)regs->rbp;
-#else
-       head = (struct frame_head *)regs->ebp;
-#endif
+       struct frame_head *head = (struct frame_head *)frame_pointer(regs);
+       unsigned long stack = kernel_trap_sp(regs);
 
        if (!user_mode_vm(regs)) {
-               while (depth-- && valid_kernel_stack(head, regs))
-                       head = dump_kernel_backtrace(head);
+               if (depth)
+                       dump_trace(NULL, regs, (unsigned long *)stack, 0,
+                                  &backtrace_ops, &depth);
                return;
        }