aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'arch/arm/kernel')
-rw-r--r--arch/arm/kernel/Makefile4
-rw-r--r--arch/arm/kernel/stacktrace.c73
-rw-r--r--arch/arm/kernel/stacktrace.h9
3 files changed, 84 insertions, 2 deletions
diff --git a/arch/arm/kernel/Makefile b/arch/arm/kernel/Makefile
index bb28087bf818..593b56509f4f 100644
--- a/arch/arm/kernel/Makefile
+++ b/arch/arm/kernel/Makefile
@@ -7,8 +7,8 @@ AFLAGS_head.o := -DTEXT_OFFSET=$(TEXT_OFFSET)
7# Object file lists. 7# Object file lists.
8 8
9obj-y := compat.o entry-armv.o entry-common.o irq.o \ 9obj-y := compat.o entry-armv.o entry-common.o irq.o \
10 process.o ptrace.o semaphore.o setup.o signal.o sys_arm.o \ 10 process.o ptrace.o semaphore.o setup.o signal.o \
11 time.o traps.o 11 sys_arm.o stacktrace.o time.o traps.o
12 12
13obj-$(CONFIG_ISA_DMA_API) += dma.o 13obj-$(CONFIG_ISA_DMA_API) += dma.o
14obj-$(CONFIG_ARCH_ACORN) += ecard.o 14obj-$(CONFIG_ARCH_ACORN) += ecard.o
diff --git a/arch/arm/kernel/stacktrace.c b/arch/arm/kernel/stacktrace.c
new file mode 100644
index 000000000000..77ef35efaa8d
--- /dev/null
+++ b/arch/arm/kernel/stacktrace.c
@@ -0,0 +1,73 @@
1#include <linux/sched.h>
2#include <linux/stacktrace.h>
3
4#include "stacktrace.h"
5
6int walk_stackframe(unsigned long fp, unsigned long low, unsigned long high,
7 int (*fn)(struct stackframe *, void *), void *data)
8{
9 struct stackframe *frame;
10
11 do {
12 /*
13 * Check current frame pointer is within bounds
14 */
15 if ((fp - 12) < low || fp + 4 >= high)
16 break;
17
18 frame = (struct stackframe *)(fp - 12);
19
20 if (fn(frame, data))
21 break;
22
23 /*
24 * Update the low bound - the next frame must always
25 * be at a higher address than the current frame.
26 */
27 low = fp + 4;
28 fp = frame->fp;
29 } while (fp);
30
31 return 0;
32}
33
34#ifdef CONFIG_STACKTRACE
35struct stack_trace_data {
36 struct stack_trace *trace;
37 unsigned int skip;
38};
39
40static int save_trace(struct stackframe *frame, void *d)
41{
42 struct stack_trace_data *data = d;
43 struct stack_trace *trace = data->trace;
44
45 if (data->skip) {
46 data->skip--;
47 return 0;
48 }
49
50 trace->entries[trace->nr_entries++] = frame->lr;
51
52 return trace->nr_entries >= trace->max_entries;
53}
54
55void save_stack_trace(struct stack_trace *trace, struct task_struct *task)
56{
57 struct stack_trace_data data;
58 unsigned long fp, base;
59
60 data.trace = trace;
61 data.skip = trace->skip;
62
63 if (task) {
64 base = (unsigned long)task_stack_page(task);
65 fp = 0; /* FIXME */
66 } else {
67 base = (unsigned long)task_stack_page(current);
68 asm("mov %0, fp" : "=r" (fp));
69 }
70
71 walk_stackframe(fp, base, base + THREAD_SIZE, save_trace, &data);
72}
73#endif
diff --git a/arch/arm/kernel/stacktrace.h b/arch/arm/kernel/stacktrace.h
new file mode 100644
index 000000000000..e9fd20cb5662
--- /dev/null
+++ b/arch/arm/kernel/stacktrace.h
@@ -0,0 +1,9 @@
1struct stackframe {
2 unsigned long fp;
3 unsigned long sp;
4 unsigned long lr;
5 unsigned long pc;
6};
7
8int walk_stackframe(unsigned long fp, unsigned long low, unsigned long high,
9 int (*fn)(struct stackframe *, void *), void *data);