stacktrace.c 813 B

12345678910111213141516171819202122232425262728293031323334353637
  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>
  6. void save_stack_trace(struct stack_trace *trace)
  7. {
  8. unsigned long ksp, fp, thread_base;
  9. struct thread_info *tp = task_thread_info(current);
  10. stack_trace_flush();
  11. __asm__ __volatile__(
  12. "mov %%fp, %0"
  13. : "=r" (ksp)
  14. );
  15. fp = ksp + STACK_BIAS;
  16. thread_base = (unsigned long) tp;
  17. do {
  18. struct reg_window *rw;
  19. /* Bogus frame pointer? */
  20. if (fp < (thread_base + sizeof(struct thread_info)) ||
  21. fp >= (thread_base + THREAD_SIZE))
  22. break;
  23. rw = (struct reg_window *) fp;
  24. if (trace->skip > 0)
  25. trace->skip--;
  26. else
  27. trace->entries[trace->nr_entries++] = rw->ins[7];
  28. fp = rw->ins[6] + STACK_BIAS;
  29. } while (trace->nr_entries < trace->max_entries);
  30. }