stackchk.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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/threads.h"
  24. #include "libguile/dynwind.h"
  25. #include "libguile/stackchk.h"
  26. /* {Stack Checking}
  27. */
  28. int scm_stack_checking_enabled_p;
  29. long
  30. scm_stack_size (SCM_STACKITEM *start)
  31. {
  32. SCM_STACKITEM stack;
  33. #if SCM_STACK_GROWS_UP
  34. return &stack - start;
  35. #else
  36. return start - &stack;
  37. #endif /* SCM_STACK_GROWS_UP */
  38. }
  39. void
  40. scm_stack_report ()
  41. {
  42. SCM port = scm_current_error_port ();
  43. SCM_STACKITEM stack;
  44. scm_i_thread *thread = SCM_I_CURRENT_THREAD;
  45. scm_uintprint ((scm_stack_size (thread->continuation_base)
  46. * sizeof (SCM_STACKITEM)),
  47. 16, port);
  48. scm_puts (" of stack: 0x", port);
  49. scm_uintprint ((scm_t_bits) thread->continuation_base, 16, port);
  50. scm_puts (" - 0x", port);
  51. scm_uintprint ((scm_t_bits) &stack, 16, port);
  52. scm_puts ("\n", port);
  53. }
  54. SCM_DEFINE (scm_sys_get_stack_size, "%get-stack-size", 0, 0, 0,
  55. (),
  56. "Return the current thread's C stack size (in Scheme objects).")
  57. #define FUNC_NAME s_scm_sys_get_stack_size
  58. {
  59. return scm_from_long (scm_stack_size (SCM_I_CURRENT_THREAD->base));
  60. }
  61. #undef FUNC_NAME
  62. void
  63. scm_init_stackchk ()
  64. {
  65. #include "libguile/stackchk.x"
  66. }
  67. /*
  68. Local Variables:
  69. c-file-style: "gnu"
  70. End:
  71. */