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/mm.h>
19#include <asm/ptrace.h>
20#include <asm/uaccess.h>
21
22#include "../kernel/stacktrace.h"
23
24static int report_trace(struct stackframe *frame, void *d)
25{
26 unsigned int *depth = d;
27
28 if (*depth) {
29 oprofile_add_trace(frame->lr);
30 (*depth)--;
31 }
32
33 return *depth == 0;
34}
35
36
37
38
39
40
41
42struct frame_tail {
43 struct frame_tail *fp;
44 unsigned long sp;
45 unsigned long lr;
46} __attribute__((packed));
47
48static struct frame_tail* user_backtrace(struct frame_tail *tail)
49{
50 struct frame_tail buftail[2];
51
52
53 if (!access_ok(VERIFY_READ, tail, sizeof(buftail)))
54 return NULL;
55 if (__copy_from_user_inatomic(buftail, tail, sizeof(buftail)))
56 return NULL;
57
58 oprofile_add_trace(buftail[0].lr);
59
60
61
62 if (tail >= buftail[0].fp)
63 return NULL;
64
65 return buftail[0].fp-1;
66}
67
68void arm_backtrace(struct pt_regs * const regs, unsigned int depth)
69{
70 struct frame_tail *tail = ((struct frame_tail *) regs->ARM_fp) - 1;
71
72 if (!user_mode(regs)) {
73 unsigned long base = ((unsigned long)regs) & ~(THREAD_SIZE - 1);
74 walk_stackframe(regs->ARM_fp, base, base + THREAD_SIZE,
75 report_trace, &depth);
76 return;
77 }
78
79 while (depth-- && tail && !((unsigned long) tail & 3))
80 tail = user_backtrace(tail);
81}
82