stacktrace.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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))
  25. break;
  26. sf = (struct sparc_stackf *) fp;
  27. regs = (struct pt_regs *) (sf + 1);
  28. if ((regs->magic & ~0x1ff) == PT_REGS_MAGIC) {
  29. if (!(regs->tstate & TSTATE_PRIV))
  30. break;
  31. pc = regs->tpc;
  32. fp = regs->u_regs[UREG_I6] + STACK_BIAS;
  33. } else {
  34. pc = sf->callers_pc;
  35. fp = (unsigned long)sf->fp + STACK_BIAS;
  36. }
  37. if (trace->skip > 0)
  38. trace->skip--;
  39. else
  40. trace->entries[trace->nr_entries++] = pc;
  41. } while (trace->nr_entries < trace->max_entries);
  42. }
  43. EXPORT_SYMBOL_GPL(save_stack_trace);