David S. Miller | 10e2672 | 2006-11-16 13:38:57 -0800 | [diff] [blame] | 1 | #include <linux/sched.h> |
| 2 | #include <linux/stacktrace.h> |
| 3 | #include <linux/thread_info.h> |
| 4 | #include <asm/ptrace.h> |
| 5 | |
Christoph Hellwig | ab1b6f0 | 2007-05-08 00:23:29 -0700 | [diff] [blame] | 6 | void save_stack_trace(struct stack_trace *trace) |
David S. Miller | 10e2672 | 2006-11-16 13:38:57 -0800 | [diff] [blame] | 7 | { |
| 8 | unsigned long ksp, fp, thread_base; |
Christoph Hellwig | ab1b6f0 | 2007-05-08 00:23:29 -0700 | [diff] [blame] | 9 | struct thread_info *tp = task_thread_info(current); |
David S. Miller | 10e2672 | 2006-11-16 13:38:57 -0800 | [diff] [blame] | 10 | |
Christoph Hellwig | ab1b6f0 | 2007-05-08 00:23:29 -0700 | [diff] [blame] | 11 | flushw_all(); |
| 12 | __asm__ __volatile__( |
| 13 | "mov %%fp, %0" |
| 14 | : "=r" (ksp) |
| 15 | ); |
David S. Miller | 10e2672 | 2006-11-16 13:38:57 -0800 | [diff] [blame] | 16 | |
| 17 | fp = ksp + STACK_BIAS; |
| 18 | thread_base = (unsigned long) tp; |
| 19 | do { |
| 20 | struct reg_window *rw; |
| 21 | |
| 22 | /* Bogus frame pointer? */ |
| 23 | if (fp < (thread_base + sizeof(struct thread_info)) || |
| 24 | fp >= (thread_base + THREAD_SIZE)) |
| 25 | break; |
| 26 | |
| 27 | rw = (struct reg_window *) fp; |
| 28 | if (trace->skip > 0) |
| 29 | trace->skip--; |
| 30 | else |
| 31 | trace->entries[trace->nr_entries++] = rw->ins[7]; |
| 32 | |
| 33 | fp = rw->ins[6] + STACK_BIAS; |
| 34 | } while (trace->nr_entries < trace->max_entries); |
| 35 | } |