1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd. */
4 #include <linux/sched/debug.h>
5 #include <linux/sched/task_stack.h>
6 #include <linux/stacktrace.h>
7 #include <linux/ftrace.h>
9 void save_stack_trace(struct stack_trace
*trace
)
11 save_stack_trace_tsk(current
, trace
);
13 EXPORT_SYMBOL_GPL(save_stack_trace
);
15 void save_stack_trace_tsk(struct task_struct
*tsk
, struct stack_trace
*trace
)
17 unsigned long *fp
, *stack_start
, *stack_end
;
19 int skip
= trace
->skip
;
24 asm volatile("mov %0, r8\n":"=r"(fp
));
27 fp
= (unsigned long *)thread_saved_fp(tsk
);
31 addr
= (unsigned long) fp
& THREAD_MASK
;
32 stack_start
= (unsigned long *) addr
;
33 stack_end
= (unsigned long *) (addr
+ THREAD_SIZE
);
35 while (fp
> stack_start
&& fp
< stack_end
) {
36 unsigned long lpp
, fpp
;
40 if (!__kernel_text_address(lpp
))
43 lpp
= ftrace_graph_ret_addr(tsk
, &graph_idx
, lpp
, NULL
);
45 if (savesched
|| !in_sched_functions(lpp
)) {
49 trace
->entries
[trace
->nr_entries
++] = lpp
;
50 if (trace
->nr_entries
>= trace
->max_entries
)
54 fp
= (unsigned long *)fpp
;
57 EXPORT_SYMBOL_GPL(save_stack_trace_tsk
);