stacktrace.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include <linux/sched.h>
  2. #include <linux/stacktrace.h>
  3. #include <linux/thread_info.h>
  4. #include <linux/module.h>
  5. #include <asm/ptrace.h>
  6. #include <asm/stacktrace.h>
  7. void save_stack_trace(struct stack_trace *trace)
  8. {
  9. unsigned long ksp, fp, thread_base;
  10. struct thread_info *tp = task_thread_info(current);
  11. stack_trace_flush();
  12. __asm__ __volatile__(
  13. "mov %%fp, %0"
  14. : "=r" (ksp)
  15. );
  16. fp = ksp + STACK_BIAS;
  17. thread_base = (unsigned long) tp;
  18. do {
  19. struct sparc_stackf *sf;
  20. struct pt_regs *regs;
  21. unsigned long pc;
  22. /* Bogus frame pointer? */
  23. if (fp < (thread_base + sizeof(struct thread_info)) ||
  24. fp > (thread_base + THREAD_SIZE - sizeof(struct sparc_stackf)))
  25. break;
  26. sf = (struct sparc_stackf *) fp;
  27. regs = (struct pt_regs *) (sf + 1);
  28. if (((unsigned long)regs <=
  29. (thread_base + THREAD_SIZE - sizeof(*regs))) &&
  30. (regs->magic & ~0x1ff) == PT_REGS_MAGIC) {
  31. if (!(regs->tstate & TSTATE_PRIV))
  32. break;
  33. pc = regs->tpc;
  34. fp = regs->u_regs[UREG_I6] + STACK_BIAS;
  35. } else {
  36. pc = sf->callers_pc;
  37. fp = (unsigned long)sf->fp + STACK_BIAS;
  38. }
  39. if (trace->skip > 0)
  40. trace->skip--;
  41. else
  42. trace->entries[trace->nr_entries++] = pc;
  43. } while (trace->nr_entries < trace->max_entries);
  44. }
  45. EXPORT_SYMBOL_GPL(save_stack_trace);