1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#include <linux/oprofile.h>
17#include <linux/sched.h>
18#include <linux/kallsyms.h>
19#include <linux/mm.h>
20#include <asm/unwinder.h>
21#include <asm/ptrace.h>
22#include <linux/uaccess.h>
23#include <asm/sections.h>
24#include <asm/stacktrace.h>
25
26static int backtrace_stack(void *data, char *name)
27{
28
29 return 0;
30}
31
32static void backtrace_address(void *data, unsigned long addr, int reliable)
33{
34 unsigned int *depth = data;
35
36 if ((*depth)--)
37 oprofile_add_trace(addr);
38}
39
40static struct stacktrace_ops backtrace_ops = {
41 .stack = backtrace_stack,
42 .address = backtrace_address,
43};
44
45
46static int backtrace_limit = 20;
47
48static unsigned long *
49user_backtrace(unsigned long *stackaddr, struct pt_regs *regs)
50{
51 unsigned long buf_stack;
52
53
54 if (!access_ok(stackaddr, sizeof(unsigned long)))
55 return NULL;
56
57 if (__copy_from_user_inatomic(&buf_stack, stackaddr, sizeof(unsigned long)))
58 return NULL;
59
60
61 if (buf_stack & 3)
62 return NULL;
63
64 oprofile_add_trace(buf_stack);
65
66 stackaddr++;
67
68 return stackaddr;
69}
70
71void sh_backtrace(struct pt_regs * const regs, unsigned int depth)
72{
73 unsigned long *stackaddr;
74
75
76
77
78 if (depth > backtrace_limit)
79 depth = backtrace_limit;
80
81 stackaddr = (unsigned long *)kernel_stack_pointer(regs);
82 if (!user_mode(regs)) {
83 if (depth)
84 unwind_stack(NULL, regs, stackaddr,
85 &backtrace_ops, &depth);
86 return;
87 }
88
89 while (depth-- && (stackaddr != NULL))
90 stackaddr = user_backtrace(stackaddr, regs);
91}
92