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;
39 unsigned int no_sched_functions;
43 static int save_trace(struct stackframe *frame, void *d)
45 struct stack_trace_data *data = d;
46 struct stack_trace *trace = data->trace;
47 unsigned long addr = frame->lr;
49 if (data->no_sched_functions && in_sched_functions(addr))
56 trace->entries[trace->nr_entries++] = addr;
58 return trace->nr_entries >= trace->max_entries;
61 void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
63 struct stack_trace_data data;
64 unsigned long fp, base;
67 data.skip = trace->skip;
68 base = (unsigned long)task_stack_page(tsk);
73 * What guarantees do we have here that 'tsk'
74 * is not running on another CPU?
78 data.no_sched_functions = 1;
79 fp = thread_saved_fp(tsk);
82 data.no_sched_functions = 0;
83 asm("mov %0, fp" : "=r" (fp));
86 walk_stackframe(fp, base, base + THREAD_SIZE, save_trace, &data);
87 if (trace->nr_entries < trace->max_entries)
88 trace->entries[trace->nr_entries++] = ULONG_MAX;
91 void save_stack_trace(struct stack_trace *trace)
93 save_stack_trace_tsk(current, trace);
95 EXPORT_SYMBOL_GPL(save_stack_trace);