stackchk.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #ifndef SCM_STACKCHK_H
  2. #define SCM_STACKCHK_H
  3. /* Copyright 1995-1996,1998,2000,2003,2006,2008-2011,2014,2018
  4. Free Software Foundation, Inc.
  5. This file is part of Guile.
  6. Guile is free software: you can redistribute it and/or modify it
  7. under the terms of the GNU Lesser General Public License as published
  8. by the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Guile is distributed in the hope that it will be useful, but WITHOUT
  11. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  13. License for more details.
  14. You should have received a copy of the GNU Lesser General Public
  15. License along with Guile. If not, see
  16. <https://www.gnu.org/licenses/>. */
  17. #include "libguile/continuations.h"
  18. #include "libguile/debug.h"
  19. /* With debug options we have the possibility to disable stack checking.
  20. */
  21. #define SCM_STACK_CHECKING_P SCM_STACK_LIMIT
  22. #if defined BUILDING_LIBGUILE
  23. #include "libguile/private-options.h"
  24. # if SCM_STACK_GROWS_UP
  25. # define SCM_STACK_OVERFLOW_P(s)\
  26. ((SCM_STACK_PTR (s) - SCM_I_CURRENT_THREAD->base) > SCM_STACK_LIMIT)
  27. # else
  28. # define SCM_STACK_OVERFLOW_P(s)\
  29. ((SCM_I_CURRENT_THREAD->base - SCM_STACK_PTR (s)) > SCM_STACK_LIMIT)
  30. # endif
  31. # define SCM_CHECK_STACK\
  32. {\
  33. SCM_STACKITEM stack;\
  34. if (SCM_STACK_OVERFLOW_P (&stack) && scm_stack_checking_enabled_p)\
  35. scm_report_stack_overflow ();\
  36. }
  37. #else
  38. # define SCM_CHECK_STACK /**/
  39. #endif
  40. SCM_API int scm_stack_checking_enabled_p;
  41. SCM_API long scm_stack_size (SCM_STACKITEM *start);
  42. SCM_API void scm_stack_report (void);
  43. SCM_API SCM scm_sys_get_stack_size (void);
  44. SCM_INTERNAL void scm_init_stackchk (void);
  45. #endif /* SCM_STACKCHK_H */