stackchk.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* Copyright 1995-1997,2000-2001,2006,2008,2010-2011,2014,2018
  2. Free Software Foundation, Inc.
  3. This file is part of Guile.
  4. Guile is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Lesser General Public License as published
  6. by the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. Guile is distributed in the hope that it will be useful, but WITHOUT
  9. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  11. License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with Guile. If not, see
  14. <https://www.gnu.org/licenses/>. */
  15. #ifdef HAVE_CONFIG_H
  16. # include <config.h>
  17. #endif
  18. #include "dynwind.h"
  19. #include "gsubr.h"
  20. #include "numbers.h"
  21. #include "ports.h"
  22. #include "threads.h"
  23. #include "stackchk.h"
  24. /* {Stack Checking}
  25. */
  26. int scm_stack_checking_enabled_p;
  27. long
  28. scm_stack_size (SCM_STACKITEM *start)
  29. {
  30. SCM_STACKITEM stack;
  31. #if SCM_STACK_GROWS_UP
  32. return &stack - start;
  33. #else
  34. return start - &stack;
  35. #endif /* SCM_STACK_GROWS_UP */
  36. }
  37. void
  38. scm_stack_report ()
  39. {
  40. SCM port = scm_current_error_port ();
  41. SCM_STACKITEM stack;
  42. scm_thread *thread = SCM_I_CURRENT_THREAD;
  43. scm_uintprint ((scm_stack_size (thread->continuation_base)
  44. * sizeof (SCM_STACKITEM)),
  45. 16, port);
  46. scm_puts (" of stack: 0x", port);
  47. scm_uintprint ((scm_t_bits) thread->continuation_base, 16, port);
  48. scm_puts (" - 0x", port);
  49. scm_uintprint ((scm_t_bits) &stack, 16, port);
  50. scm_puts ("\n", port);
  51. }
  52. SCM_DEFINE (scm_sys_get_stack_size, "%get-stack-size", 0, 0, 0,
  53. (),
  54. "Return the current thread's C stack size (in Scheme objects).")
  55. #define FUNC_NAME s_scm_sys_get_stack_size
  56. {
  57. return scm_from_long (scm_stack_size (SCM_I_CURRENT_THREAD->base));
  58. }
  59. #undef FUNC_NAME
  60. void
  61. scm_init_stackchk ()
  62. {
  63. #include "stackchk.x"
  64. }