2 #include <linux/sched.h>
5 #include <asm/ptrace.h>
6 #include <asm/stacktrace.h>
8 #include <linux/kernel.h>
9 #include <asm/sections.h>
18 static inline int get_mem(
unsigned long addr,
unsigned long *
result)
20 unsigned long *
address = (
unsigned long *) addr;
71 static inline int unwind_user_frame(
struct stackframe *old_frame,
72 const unsigned int max_instr_check)
76 size_t stack_size = 0;
79 if (old_frame->
pc == 0 || old_frame->
sp == 0 || old_frame->
ra == 0)
82 for (addr = new_frame.
pc; (addr + max_instr_check > new_frame.
pc)
83 && (!ra_offset || !stack_size); --addr) {
86 if (get_mem(addr, (
unsigned long *) &ip))
89 if (is_sp_move_ins(&ip)) {
90 int stack_adjustment = ip.
i_format.simmediate;
91 if (stack_adjustment > 0)
95 stack_size = (unsigned) stack_adjustment;
96 }
else if (is_ra_save_ins(&ip)) {
97 int ra_slot = ip.
i_format.simmediate;
102 }
else if (is_end_of_function_marker(&ip))
106 if (!ra_offset || !stack_size)
110 new_frame.
ra = old_frame->
sp + ra_offset;
111 if (get_mem(new_frame.
ra, &(new_frame.
ra)))
116 new_frame.
sp = old_frame->
sp + stack_size;
117 if (get_mem(new_frame.
sp, &(new_frame.
sp)))
121 if (new_frame.
sp > old_frame->
sp)
124 new_frame.
pc = old_frame->
ra;
125 *old_frame = new_frame;
130 static inline void do_user_backtrace(
unsigned long low_addr,
134 const unsigned int max_instr_check = 512;
135 const unsigned long high_addr = low_addr +
THREAD_SIZE;
137 while (depth-- && !unwind_user_frame(frame, max_instr_check)) {
139 if (frame->
sp < low_addr || frame->
sp > high_addr)
144 #ifndef CONFIG_KALLSYMS
145 static inline void do_kernel_backtrace(
unsigned long low_addr,
147 unsigned int depth) { }
149 static inline void do_kernel_backtrace(
unsigned long low_addr,
153 while (depth-- && frame->
pc) {
154 frame->
pc = unwind_stack_by_address(low_addr,
167 .ra = regs->
regs[31] };
169 const unsigned long low_addr =
ALIGN(frame.
sp, THREAD_SIZE);
172 do_user_backtrace(low_addr, &frame, depth);
174 do_kernel_backtrace(low_addr, &frame, depth);