Release 4.11 arch/arm/kernel/stacktrace.c
#include <linux/export.h>
#include <linux/sched.h>
#include <linux/sched/debug.h>
#include <linux/stacktrace.h>
#include <asm/stacktrace.h>
#include <asm/traps.h>
#if defined(CONFIG_FRAME_POINTER) && !defined(CONFIG_ARM_UNWIND)
/*
* Unwind the current stack frame and store the new register values in the
* structure passed as argument. Unwinding is equivalent to a function return,
* hence the new PC value rather than LR should be used for backtrace.
*
* With framepointer enabled, a simple function prologue looks like this:
* mov ip, sp
* stmdb sp!, {fp, ip, lr, pc}
* sub fp, ip, #4
*
* A simple function epilogue looks like this:
* ldm sp, {fp, sp, pc}
*
* Note that with framepointer enabled, even the leaf functions have the same
* prologue and epilogue, therefore we can ignore the LR value in this case.
*/
int notrace unwind_frame(struct stackframe *frame)
{
unsigned long high, low;
unsigned long fp = frame->fp;
/* only go to a higher address on the stack */
low = frame->sp;
high = ALIGN(low, THREAD_SIZE);
/* check current frame pointer is within bounds */
if (fp < low + 12 || fp > high - 4)
return -EINVAL;
/* restore the registers from the stack frame */
frame->fp = *(unsigned long *)(fp - 12);
frame->sp = *(unsigned long *)(fp - 8);
frame->pc = *(unsigned long *)(fp - 4);
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Catalin Marinas | 77 | 68.75% | 1 | 20.00% |
Russell King | 31 | 27.68% | 2 | 40.00% |
Konstantin Khlebnikov | 3 | 2.68% | 1 | 20.00% |
Uwe Kleine-König | 1 | 0.89% | 1 | 20.00% |
Total | 112 | 100.00% | 5 | 100.00% |
#endif
void notrace walk_stackframe(struct stackframe *frame,
int (*fn)(struct stackframe *, void *), void *data)
{
while (1) {
int ret;
if (fn(frame, data))
break;
ret = unwind_frame(frame);
if (ret < 0)
break;
}
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Catalin Marinas | 45 | 72.58% | 1 | 33.33% |
Russell King | 16 | 25.81% | 1 | 33.33% |
Uwe Kleine-König | 1 | 1.61% | 1 | 33.33% |
Total | 62 | 100.00% | 3 | 100.00% |
EXPORT_SYMBOL(walk_stackframe);
#ifdef CONFIG_STACKTRACE
struct stack_trace_data {
struct stack_trace *trace;
unsigned long last_pc;
unsigned int no_sched_functions;
unsigned int skip;
};
static int save_trace(struct stackframe *frame, void *d)
{
struct stack_trace_data *data = d;
struct stack_trace *trace = data->trace;
struct pt_regs *regs;
unsigned long addr = frame->pc;
if (data->no_sched_functions && in_sched_functions(addr))
return 0;
if (data->skip) {
data->skip--;
return 0;
}
trace->entries[trace->nr_entries++] = addr;
if (trace->nr_entries >= trace->max_entries)
return 1;
/*
* in_exception_text() is designed to test if the PC is one of
* the functions which has an exception stack above it, but
* unfortunately what is in frame->pc is the return LR value,
* not the saved PC value. So, we need to track the previous
* frame PC value when doing this.
*/
addr = data->last_pc;
data->last_pc = frame->pc;
if (!in_exception_text(addr))
return 0;
regs = (struct pt_regs *)frame->sp;
trace->entries[trace->nr_entries++] = regs->ARM_pc;
return trace->nr_entries >= trace->max_entries;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Russell King | 136 | 85.53% | 2 | 50.00% |
Nico Pitre | 22 | 13.84% | 1 | 25.00% |
Catalin Marinas | 1 | 0.63% | 1 | 25.00% |
Total | 159 | 100.00% | 4 | 100.00% |
/* This must be noinline to so that our skip calculation works correctly */
static noinline void __save_stack_trace(struct task_struct *tsk,
struct stack_trace *trace, unsigned int nosched)
{
struct stack_trace_data data;
struct stackframe frame;
data.trace = trace;
data.last_pc = ULONG_MAX;
data.skip = trace->skip;
data.no_sched_functions = nosched;
if (tsk != current) {
#ifdef CONFIG_SMP
/*
* What guarantees do we have here that 'tsk' is not
* running on another CPU? For now, ignore it as we
* can't guarantee we won't explode.
*/
if (trace->nr_entries < trace->max_entries)
trace->entries[trace->nr_entries++] = ULONG_MAX;
return;
#else
frame.fp = thread_saved_fp(tsk);
frame.sp = thread_saved_sp(tsk);
frame.lr = 0; /* recovered from the stack */
frame.pc = thread_saved_pc(tsk);
#endif
} else {
/* We don't want this function nor the caller */
data.skip += 2;
frame.fp = (unsigned long)__builtin_frame_address(0);
frame.sp = current_stack_pointer;
frame.lr = (unsigned long)__builtin_return_address(0);
frame.pc = (unsigned long)__save_stack_trace;
}
walk_stackframe(&frame, save_trace, &data);
if (trace->nr_entries < trace->max_entries)
trace->entries[trace->nr_entries++] = ULONG_MAX;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Russell King | 86 | 40.38% | 4 | 50.00% |
Catalin Marinas | 72 | 33.80% | 1 | 12.50% |
Nico Pitre | 47 | 22.07% | 1 | 12.50% |
Lin Yongting | 7 | 3.29% | 1 | 12.50% |
Behan Webster | 1 | 0.47% | 1 | 12.50% |
Total | 213 | 100.00% | 8 | 100.00% |
void save_stack_trace_regs(struct pt_regs *regs, struct stack_trace *trace)
{
struct stack_trace_data data;
struct stackframe frame;
data.trace = trace;
data.skip = trace->skip;
data.no_sched_functions = 0;
frame.fp = regs->ARM_fp;
frame.sp = regs->ARM_sp;
frame.lr = regs->ARM_lr;
frame.pc = regs->ARM_pc;
walk_stackframe(&frame, save_trace, &data);
if (trace->nr_entries < trace->max_entries)
trace->entries[trace->nr_entries++] = ULONG_MAX;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Lin Yongting | 101 | 93.52% | 1 | 50.00% |
Nico Pitre | 7 | 6.48% | 1 | 50.00% |
Total | 108 | 100.00% | 2 | 100.00% |
void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
{
__save_stack_trace(tsk, trace, 1);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Russell King | 24 | 100.00% | 1 | 100.00% |
Total | 24 | 100.00% | 1 | 100.00% |
void save_stack_trace(struct stack_trace *trace)
{
__save_stack_trace(current, trace, 0);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Nico Pitre | 15 | 78.95% | 1 | 33.33% |
Russell King | 4 | 21.05% | 2 | 66.67% |
Total | 19 | 100.00% | 3 | 100.00% |
EXPORT_SYMBOL_GPL(save_stack_trace);
#endif
Overall Contributors
Person | Tokens | Prop | Commits | CommitProp |
Russell King | 332 | 43.23% | 5 | 33.33% |
Catalin Marinas | 211 | 27.47% | 1 | 6.67% |
Lin Yongting | 108 | 14.06% | 1 | 6.67% |
Nico Pitre | 95 | 12.37% | 1 | 6.67% |
Ingo Molnar | 8 | 1.04% | 2 | 13.33% |
Al Viro | 7 | 0.91% | 1 | 6.67% |
Konstantin Khlebnikov | 3 | 0.39% | 1 | 6.67% |
Uwe Kleine-König | 2 | 0.26% | 1 | 6.67% |
Behan Webster | 1 | 0.13% | 1 | 6.67% |
Paul Gortmaker | 1 | 0.13% | 1 | 6.67% |
Total | 768 | 100.00% | 15 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.