sparc64: Fix end-of-stack checking in save_stack_trace().
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / sparc64 / kernel / stacktrace.c
blobc5576e856b1312558df802fef3f9f5c68e1de80a
1 #include <linux/sched.h>
2 #include <linux/stacktrace.h>
3 #include <linux/thread_info.h>
4 #include <asm/ptrace.h>
5 #include <asm/stacktrace.h>
7 void save_stack_trace(struct stack_trace *trace)
9 unsigned long ksp, fp, thread_base;
10 struct thread_info *tp = task_thread_info(current);
12 stack_trace_flush();
14 __asm__ __volatile__(
15 "mov %%fp, %0"
16 : "=r" (ksp)
19 fp = ksp + STACK_BIAS;
20 thread_base = (unsigned long) tp;
21 do {
22 struct sparc_stackf *sf;
23 struct pt_regs *regs;
24 unsigned long pc;
26 /* Bogus frame pointer? */
27 if (fp < (thread_base + sizeof(struct thread_info)) ||
28 fp > (thread_base + THREAD_SIZE - sizeof(struct sparc_stackf)))
29 break;
31 sf = (struct sparc_stackf *) fp;
32 regs = (struct pt_regs *) (sf + 1);
34 if (((unsigned long)regs <=
35 (thread_base + THREAD_SIZE - sizeof(*regs))) &&
36 (regs->magic & ~0x1ff) == PT_REGS_MAGIC) {
37 if (!(regs->tstate & TSTATE_PRIV))
38 break;
39 pc = regs->tpc;
40 fp = regs->u_regs[UREG_I6] + STACK_BIAS;
41 } else {
42 pc = sf->callers_pc;
43 fp = (unsigned long)sf->fp + STACK_BIAS;
46 if (trace->skip > 0)
47 trace->skip--;
48 else
49 trace->entries[trace->nr_entries++] = pc;
50 } while (trace->nr_entries < trace->max_entries);