stackchk.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* Copyright (C) 1995,1996,1997, 2000, 2001, 2006, 2008, 2010, 2011, 2014 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 License
  5. * as published by the Free Software Foundation; either version 3 of
  6. * the License, or (at your option) any later version.
  7. *
  8. * This library is distributed in the hope that it will be useful, but
  9. * 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
  16. * 02110-1301 USA
  17. */
  18. #ifdef HAVE_CONFIG_H
  19. # include <config.h>
  20. #endif
  21. #include "libguile/_scm.h"
  22. #include "libguile/ports.h"
  23. #include "libguile/root.h"
  24. #include "libguile/threads.h"
  25. #include "libguile/dynwind.h"
  26. #include "libguile/stackchk.h"
  27. /* {Stack Checking}
  28. */
  29. int scm_stack_checking_enabled_p;
  30. long
  31. scm_stack_size (SCM_STACKITEM *start)
  32. {
  33. SCM_STACKITEM stack;
  34. #if SCM_STACK_GROWS_UP
  35. return &stack - start;
  36. #else
  37. return start - &stack;
  38. #endif /* SCM_STACK_GROWS_UP */
  39. }
  40. void
  41. scm_stack_report ()
  42. {
  43. SCM port = scm_current_error_port ();
  44. SCM_STACKITEM stack;
  45. scm_i_thread *thread = SCM_I_CURRENT_THREAD;
  46. scm_uintprint ((scm_stack_size (thread->continuation_base)
  47. * sizeof (SCM_STACKITEM)),
  48. 16, port);
  49. scm_puts_unlocked (" of stack: 0x", port);
  50. scm_uintprint ((scm_t_bits) thread->continuation_base, 16, port);
  51. scm_puts_unlocked (" - 0x", port);
  52. scm_uintprint ((scm_t_bits) &stack, 16, port);
  53. scm_puts_unlocked ("\n", port);
  54. }
  55. SCM_DEFINE (scm_sys_get_stack_size, "%get-stack-size", 0, 0, 0,
  56. (),
  57. "Return the current thread's C stack size (in Scheme objects).")
  58. #define FUNC_NAME s_scm_sys_get_stack_size
  59. {
  60. return scm_from_long (scm_stack_size (SCM_I_CURRENT_THREAD->base));
  61. }
  62. #undef FUNC_NAME
  63. void
  64. scm_init_stackchk ()
  65. {
  66. #include "libguile/stackchk.x"
  67. }
  68. /*
  69. Local Variables:
  70. c-file-style: "gnu"
  71. End:
  72. */