stacktrace.c 777 B

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