]>
git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - arch/metag/kernel/stacktrace.c
4f806d66a58c6bd041ab2e5306ef903e455265c1
1 #include <linux/export.h>
2 #include <linux/sched.h>
3 #include <linux/sched/debug.h>
4 #include <linux/stacktrace.h>
6 #include <asm/stacktrace.h>
8 #if defined(CONFIG_FRAME_POINTER)
10 #ifdef CONFIG_KALLSYMS
11 #include <linux/kallsyms.h>
12 #include <linux/module.h>
14 static unsigned long tbi_boing_addr
;
15 static unsigned long tbi_boing_size
;
17 static void tbi_boing_init(void)
19 /* We need to know where TBIBoingVec is and it's size */
22 char modname
[MODULE_NAME_LEN
];
23 char name
[KSYM_NAME_LEN
];
24 tbi_boing_addr
= kallsyms_lookup_name("___TBIBoingVec");
27 else if (!lookup_symbol_attrs(tbi_boing_addr
, &size
,
28 &offset
, modname
, name
))
29 tbi_boing_size
= size
;
33 #define ALIGN_DOWN(addr, size) ((addr)&(~((size)-1)))
36 * Unwind the current stack frame and store the new register values in the
37 * structure passed as argument. Unwinding is equivalent to a function return,
38 * hence the new PC value rather than LR should be used for backtrace.
40 int notrace
unwind_frame(struct stackframe
*frame
)
42 struct metag_frame
*fp
= (struct metag_frame
*)frame
->fp
;
52 #ifdef CONFIG_KALLSYMS
53 /* If we've reached TBIBoingVec then we're at an interrupt
54 * entry point or a syscall entry point. The frame pointer
55 * points to a pt_regs which can be used to continue tracing on
56 * the other side of the boing.
60 if (tbi_boing_size
&& lr
>= tbi_boing_addr
&&
61 lr
< tbi_boing_addr
+ tbi_boing_size
) {
62 struct pt_regs
*regs
= (struct pt_regs
*)fpnew
;
65 fpnew
= regs
->ctx
.AX
[1].U0
;
66 lr
= regs
->ctx
.DX
[4].U1
;
70 /* stack grows up, so frame pointers must decrease */
71 if (fpnew
< (ALIGN_DOWN((unsigned long)fp
, THREAD_SIZE
) +
72 sizeof(struct thread_info
)) || fpnew
>= (unsigned long)fp
)
75 /* restore the registers from the stack frame */
82 int notrace
unwind_frame(struct stackframe
*frame
)
84 struct metag_frame
*sp
= (struct metag_frame
*)frame
->sp
;
89 while (!kstack_end(sp
)) {
90 unsigned long addr
= sp
->lr
- 4;
93 if (__kernel_text_address(addr
)) {
94 frame
->sp
= (unsigned long)sp
;
103 void notrace
walk_stackframe(struct stackframe
*frame
,
104 int (*fn
)(struct stackframe
*, void *), void *data
)
111 ret
= unwind_frame(frame
);
116 EXPORT_SYMBOL(walk_stackframe
);
118 #ifdef CONFIG_STACKTRACE
119 struct stack_trace_data
{
120 struct stack_trace
*trace
;
121 unsigned int no_sched_functions
;
125 static int save_trace(struct stackframe
*frame
, void *d
)
127 struct stack_trace_data
*data
= d
;
128 struct stack_trace
*trace
= data
->trace
;
129 unsigned long addr
= frame
->pc
;
131 if (data
->no_sched_functions
&& in_sched_functions(addr
))
138 trace
->entries
[trace
->nr_entries
++] = addr
;
140 return trace
->nr_entries
>= trace
->max_entries
;
143 void save_stack_trace_tsk(struct task_struct
*tsk
, struct stack_trace
*trace
)
145 struct stack_trace_data data
;
146 struct stackframe frame
;
149 data
.skip
= trace
->skip
;
151 if (tsk
!= current
) {
154 * What guarantees do we have here that 'tsk' is not
155 * running on another CPU? For now, ignore it as we
156 * can't guarantee we won't explode.
158 if (trace
->nr_entries
< trace
->max_entries
)
159 trace
->entries
[trace
->nr_entries
++] = ULONG_MAX
;
162 data
.no_sched_functions
= 1;
163 frame
.fp
= thread_saved_fp(tsk
);
164 frame
.sp
= thread_saved_sp(tsk
);
165 frame
.lr
= 0; /* recovered from the stack */
166 frame
.pc
= thread_saved_pc(tsk
);
169 register unsigned long current_sp
asm ("A0StP");
171 data
.no_sched_functions
= 0;
172 frame
.fp
= (unsigned long)__builtin_frame_address(0);
173 frame
.sp
= current_sp
;
174 frame
.lr
= (unsigned long)__builtin_return_address(0);
175 frame
.pc
= (unsigned long)save_stack_trace_tsk
;
178 walk_stackframe(&frame
, save_trace
, &data
);
179 if (trace
->nr_entries
< trace
->max_entries
)
180 trace
->entries
[trace
->nr_entries
++] = ULONG_MAX
;
183 void save_stack_trace(struct stack_trace
*trace
)
185 save_stack_trace_tsk(current
, trace
);
187 EXPORT_SYMBOL_GPL(save_stack_trace
);