stacktrace.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Stacktrace support for Hexagon
  3. *
  4. * Copyright (c) 2010-2011, The Linux Foundation. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 and
  8. * only version 2 as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  18. * 02110-1301, USA.
  19. */
  20. #include <linux/sched.h>
  21. #include <linux/stacktrace.h>
  22. #include <linux/thread_info.h>
  23. #include <linux/module.h>
  24. register unsigned long current_frame_pointer asm("r30");
  25. struct stackframe {
  26. unsigned long fp;
  27. unsigned long rets;
  28. };
  29. /*
  30. * Save stack-backtrace addresses into a stack_trace buffer.
  31. */
  32. void save_stack_trace(struct stack_trace *trace)
  33. {
  34. unsigned long low, high;
  35. unsigned long fp;
  36. struct stackframe *frame;
  37. int skip = trace->skip;
  38. low = (unsigned long)task_stack_page(current);
  39. high = low + THREAD_SIZE;
  40. fp = current_frame_pointer;
  41. while (fp >= low && fp <= (high - sizeof(*frame))) {
  42. frame = (struct stackframe *)fp;
  43. if (skip) {
  44. skip--;
  45. } else {
  46. trace->entries[trace->nr_entries++] = frame->rets;
  47. if (trace->nr_entries >= trace->max_entries)
  48. break;
  49. }
  50. /*
  51. * The next frame must be at a higher address than the
  52. * current frame.
  53. */
  54. low = fp + sizeof(*frame);
  55. fp = frame->fp;
  56. }
  57. }
  58. EXPORT_SYMBOL_GPL(save_stack_trace);