net: mediatek: fix non static symbol warnings
[linux/fpc-iii.git] / arch / mips / kernel / stacktrace.c
blob506021f62549d98c7bc8260b300c659fd0118834
1 /*
2 * Stack trace management functions
4 * Copyright (C) 2006 Atsushi Nemoto <anemo@mba.ocn.ne.jp>
5 */
6 #include <linux/sched.h>
7 #include <linux/stacktrace.h>
8 #include <linux/export.h>
9 #include <asm/stacktrace.h>
12 * Save stack-backtrace addresses into a stack_trace buffer:
14 static void save_raw_context_stack(struct stack_trace *trace,
15 unsigned long reg29, int savesched)
17 unsigned long *sp = (unsigned long *)reg29;
18 unsigned long addr;
20 while (!kstack_end(sp)) {
21 addr = *sp++;
22 if (__kernel_text_address(addr) &&
23 (savesched || !in_sched_functions(addr))) {
24 if (trace->skip > 0)
25 trace->skip--;
26 else
27 trace->entries[trace->nr_entries++] = addr;
28 if (trace->nr_entries >= trace->max_entries)
29 break;
34 static void save_context_stack(struct stack_trace *trace,
35 struct task_struct *tsk, struct pt_regs *regs, int savesched)
37 unsigned long sp = regs->regs[29];
38 #ifdef CONFIG_KALLSYMS
39 unsigned long ra = regs->regs[31];
40 unsigned long pc = regs->cp0_epc;
42 if (raw_show_trace || !__kernel_text_address(pc)) {
43 unsigned long stack_page =
44 (unsigned long)task_stack_page(tsk);
45 if (stack_page && sp >= stack_page &&
46 sp <= stack_page + THREAD_SIZE - 32)
47 save_raw_context_stack(trace, sp, savesched);
48 return;
50 do {
51 if (savesched || !in_sched_functions(pc)) {
52 if (trace->skip > 0)
53 trace->skip--;
54 else
55 trace->entries[trace->nr_entries++] = pc;
56 if (trace->nr_entries >= trace->max_entries)
57 break;
59 pc = unwind_stack(tsk, &sp, pc, &ra);
60 } while (pc);
61 #else
62 save_raw_context_stack(trace, sp, savesched);
63 #endif
67 * Save stack-backtrace addresses into a stack_trace buffer.
69 void save_stack_trace(struct stack_trace *trace)
71 save_stack_trace_tsk(current, trace);
73 EXPORT_SYMBOL_GPL(save_stack_trace);
75 void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
77 struct pt_regs dummyregs;
78 struct pt_regs *regs = &dummyregs;
80 WARN_ON(trace->nr_entries || !trace->max_entries);
82 if (tsk != current) {
83 regs->regs[29] = tsk->thread.reg29;
84 regs->regs[31] = 0;
85 regs->cp0_epc = tsk->thread.reg31;
86 } else
87 prepare_frametrace(regs);
88 save_context_stack(trace, tsk, regs, tsk == current);
90 EXPORT_SYMBOL_GPL(save_stack_trace_tsk);