stacktrace.c 889 B

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