1
0

heap_scan_stack.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Generic stack scanning function
  3. *
  4. * This currently only scans the last 32 levels of the current stack.
  5. */
  6. #ifdef __GNUC__
  7. #include "private.h"
  8. #include "node.h"
  9. /*--------------------------------------------------------- */
  10. void lub_heap_scan_stack(void)
  11. {
  12. char *start, *end;
  13. #define FRAME_ADDRESS(n) \
  14. { \
  15. char *fn = __builtin_return_address(n); \
  16. if(!fn || (fn > lub_heap_data_start)) \
  17. { \
  18. break; \
  19. } \
  20. end = __builtin_frame_address(n); \
  21. } \
  22. start = end = __builtin_frame_address(0);
  23. do {
  24. FRAME_ADDRESS(0);
  25. FRAME_ADDRESS(1);
  26. FRAME_ADDRESS(2);
  27. FRAME_ADDRESS(3);
  28. FRAME_ADDRESS(4);
  29. FRAME_ADDRESS(5);
  30. FRAME_ADDRESS(6);
  31. FRAME_ADDRESS(7);
  32. FRAME_ADDRESS(8);
  33. FRAME_ADDRESS(9);
  34. FRAME_ADDRESS(10);
  35. FRAME_ADDRESS(11);
  36. FRAME_ADDRESS(12);
  37. FRAME_ADDRESS(13);
  38. FRAME_ADDRESS(14);
  39. FRAME_ADDRESS(15);
  40. FRAME_ADDRESS(16);
  41. FRAME_ADDRESS(17);
  42. FRAME_ADDRESS(18);
  43. FRAME_ADDRESS(19);
  44. FRAME_ADDRESS(20);
  45. FRAME_ADDRESS(21);
  46. FRAME_ADDRESS(22);
  47. FRAME_ADDRESS(23);
  48. FRAME_ADDRESS(24);
  49. FRAME_ADDRESS(25);
  50. FRAME_ADDRESS(26);
  51. FRAME_ADDRESS(27);
  52. FRAME_ADDRESS(28);
  53. FRAME_ADDRESS(29);
  54. FRAME_ADDRESS(30);
  55. FRAME_ADDRESS(31);
  56. } while (0);
  57. /* now scan the memory */
  58. lub_heap_scan_memory(start, end - start);
  59. }
  60. /*--------------------------------------------------------- */
  61. #else /* not __GNUC__ */
  62. #warning "Generic stack scanning not implemented for non-GCC compiler..."
  63. #endif /* not __GNUC__ */