4 * @remark Copyright 2002 OProfile authors
5 * @remark Read the file COPYING
11 #include <linux/oprofile.h>
12 #include <linux/sched.h>
14 #include <asm/ptrace.h>
15 #include <asm/uaccess.h>
16 #include <asm/stacktrace.h>
18 static void backtrace_warning_symbol(void *data, char *msg,
24 static void backtrace_warning(void *data, char *msg)
29 static int backtrace_stack(void *data, char *name)
31 /* Yes, we want all stacks */
35 static void backtrace_address(void *data, unsigned long addr, int reliable)
37 unsigned int *depth = data;
40 oprofile_add_trace(addr);
43 static struct stacktrace_ops backtrace_ops = {
44 .warning = backtrace_warning,
45 .warning_symbol = backtrace_warning_symbol,
46 .stack = backtrace_stack,
47 .address = backtrace_address,
51 struct frame_head *bp;
53 } __attribute__((packed));
55 static struct frame_head *dump_user_backtrace(struct frame_head *head)
57 struct frame_head bufhead[2];
59 /* Also check accessibility of one struct frame_head beyond */
60 if (!access_ok(VERIFY_READ, head, sizeof(bufhead)))
62 if (__copy_from_user_inatomic(bufhead, head, sizeof(bufhead)))
65 oprofile_add_trace(bufhead[0].ret);
67 /* frame pointers should strictly progress back up the stack
68 * (towards higher addresses) */
69 if (head >= bufhead[0].bp)
76 x86_backtrace(struct pt_regs * const regs, unsigned int depth)
78 struct frame_head *head = (struct frame_head *)frame_pointer(regs);
79 unsigned long stack = kernel_trap_sp(regs);
81 if (!user_mode_vm(regs)) {
83 dump_trace(NULL, regs, (unsigned long *)stack, 0,
84 &backtrace_ops, &depth);
88 while (depth-- && head)
89 head = dump_user_backtrace(head);