1 #include <linux/module.h>
2 #include <linux/sched.h>
3 #include <linux/stacktrace.h>
5 #include "stacktrace.h"
7 int walk_stackframe(unsigned long fp
, unsigned long low
, unsigned long high
,
8 int (*fn
)(struct stackframe
*, void *), void *data
)
10 struct stackframe
*frame
;
14 * Check current frame pointer is within bounds
16 if (fp
< (low
+ 12) || fp
+ 4 >= high
)
19 frame
= (struct stackframe
*)(fp
- 12);
25 * Update the low bound - the next frame must always
26 * be at a higher address than the current frame.
34 EXPORT_SYMBOL(walk_stackframe
);
36 #ifdef CONFIG_STACKTRACE
37 struct stack_trace_data
{
38 struct stack_trace
*trace
;
42 static int save_trace(struct stackframe
*frame
, void *d
)
44 struct stack_trace_data
*data
= d
;
45 struct stack_trace
*trace
= data
->trace
;
52 trace
->entries
[trace
->nr_entries
++] = frame
->lr
;
54 return trace
->nr_entries
>= trace
->max_entries
;
57 void save_stack_trace(struct stack_trace
*trace
)
59 struct stack_trace_data data
;
60 unsigned long fp
, base
;
63 data
.skip
= trace
->skip
;
64 base
= (unsigned long)task_stack_page(current
);
65 asm("mov %0, fp" : "=r" (fp
));
67 walk_stackframe(fp
, base
, base
+ THREAD_SIZE
, save_trace
, &data
);