stackchk.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* Copyright (C) 1995,1996,1997, 2000, 2001, 2006, 2008 Free Software Foundation, Inc.
  2. *
  3. * This library is free software; you can redistribute it and/or
  4. * modify it under the terms of the GNU Lesser General Public
  5. * License as published by the Free Software Foundation; either
  6. * version 2.1 of the License, or (at your option) any later version.
  7. *
  8. * This library is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * Lesser General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Lesser General Public
  14. * License along with this library; if not, write to the Free Software
  15. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  16. */
  17. #ifdef HAVE_CONFIG_H
  18. # include <config.h>
  19. #endif
  20. #include "libguile/_scm.h"
  21. #include "libguile/ports.h"
  22. #include "libguile/root.h"
  23. #include "libguile/threads.h"
  24. #include "libguile/stackchk.h"
  25. /* {Stack Checking}
  26. */
  27. #ifdef STACK_CHECKING
  28. int scm_stack_checking_enabled_p;
  29. SCM_SYMBOL (scm_stack_overflow_key, "stack-overflow");
  30. void
  31. scm_report_stack_overflow ()
  32. {
  33. scm_stack_checking_enabled_p = 0;
  34. scm_error (scm_stack_overflow_key,
  35. NULL,
  36. "Stack overflow",
  37. SCM_BOOL_F,
  38. SCM_BOOL_F);
  39. }
  40. #endif
  41. long
  42. scm_stack_size (SCM_STACKITEM *start)
  43. {
  44. SCM_STACKITEM stack;
  45. #if SCM_STACK_GROWS_UP
  46. return &stack - start;
  47. #else
  48. return start - &stack;
  49. #endif /* SCM_STACK_GROWS_UP */
  50. }
  51. void
  52. scm_stack_report ()
  53. {
  54. SCM port = scm_current_error_port ();
  55. SCM_STACKITEM stack;
  56. scm_i_thread *thread = SCM_I_CURRENT_THREAD;
  57. scm_uintprint ((scm_stack_size (thread->continuation_base)
  58. * sizeof (SCM_STACKITEM)),
  59. 16, port);
  60. scm_puts (" of stack: 0x", port);
  61. scm_uintprint ((scm_t_bits) thread->continuation_base, 16, port);
  62. scm_puts (" - 0x", port);
  63. scm_uintprint ((scm_t_bits) &stack, 16, port);
  64. scm_puts ("\n", port);
  65. }
  66. SCM_DEFINE (scm_sys_get_stack_size, "%get-stack-size", 0, 0, 0,
  67. (),
  68. "Return the current thread's C stack size (in Scheme objects).")
  69. #define FUNC_NAME s_scm_sys_get_stack_size
  70. {
  71. return scm_from_long (scm_stack_size (SCM_I_CURRENT_THREAD->base));
  72. }
  73. #undef FUNC_NAME
  74. void
  75. scm_init_stackchk ()
  76. {
  77. #include "libguile/stackchk.x"
  78. }
  79. /*
  80. Local Variables:
  81. c-file-style: "gnu"
  82. End:
  83. */