1 /* 2 * arch/sh/kernel/stacktrace.c 3 * 4 * Stack trace management functions 5 * 6 * Copyright (C) 2006 - 2008 Paul Mundt 7 * 8 * This file is subject to the terms and conditions of the GNU General Public 9 * License. See the file "COPYING" in the main directory of this archive 10 * for more details. 11 */ 12 #include <linux/sched.h> 13 #include <linux/stacktrace.h> 14 #include <linux/thread_info.h> 15 #include <linux/module.h> 16 #include <asm/ptrace.h> 17 #include <asm/stacktrace.h> 18 19 static void save_stack_warning(void *data, char *msg) 20 { 21 } 22 23 static void 24 save_stack_warning_symbol(void *data, char *msg, unsigned long symbol) 25 { 26 } 27 28 static int save_stack_stack(void *data, char *name) 29 { 30 return 0; 31 } 32 33 /* 34 * Save stack-backtrace addresses into a stack_trace buffer. 35 */ 36 static void save_stack_address(void *data, unsigned long addr, int reliable) 37 { 38 struct stack_trace *trace = data; 39 40 if (trace->skip > 0) { 41 trace->skip--; 42 return; 43 } 44 45 if (trace->nr_entries < trace->max_entries) 46 trace->entries[trace->nr_entries++] = addr; 47 } 48 49 static const struct stacktrace_ops save_stack_ops = { 50 .warning = save_stack_warning, 51 .warning_symbol = save_stack_warning_symbol, 52 .stack = save_stack_stack, 53 .address = save_stack_address, 54 }; 55 56 void save_stack_trace(struct stack_trace *trace) 57 { 58 unsigned long *sp = (unsigned long *)current_stack_pointer; 59 60 dump_trace(current, NULL, sp, &save_stack_ops, trace); 61 } 62 EXPORT_SYMBOL_GPL(save_stack_trace); 63 64 static void 65 save_stack_address_nosched(void *data, unsigned long addr, int reliable) 66 { 67 struct stack_trace *trace = (struct stack_trace *)data; 68 69 if (in_sched_functions(addr)) 70 return; 71 72 if (trace->skip > 0) { 73 trace->skip--; 74 return; 75 } 76 77 if (trace->nr_entries < trace->max_entries) 78 trace->entries[trace->nr_entries++] = addr; 79 } 80 81 static const struct stacktrace_ops save_stack_ops_nosched = { 82 .warning = save_stack_warning, 83 .warning_symbol = save_stack_warning_symbol, 84 .stack = save_stack_stack, 85 .address = save_stack_address_nosched, 86 }; 87 88 void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace) 89 { 90 unsigned long *sp = (unsigned long *)tsk->thread.sp; 91 92 dump_trace(current, NULL, sp, &save_stack_ops_nosched, trace); 93 } 94 EXPORT_SYMBOL_GPL(save_stack_trace_tsk); 95