1 /* Copyright (C) 1995,1996,1997, 2000, 2001, 2006, 2008, 2010 Free Software Foundation, Inc.
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.
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.
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
25 #include "libguile/_scm.h"
26 #include "libguile/ports.h"
27 #include "libguile/root.h"
28 #include "libguile/threads.h"
29 #include "libguile/dynwind.h"
31 #include "libguile/stackchk.h"
38 int scm_stack_checking_enabled_p
;
40 SCM_SYMBOL (scm_stack_overflow_key
, "stack-overflow");
43 reset_scm_stack_checking_enabled_p (void *arg
)
45 scm_stack_checking_enabled_p
= (int)(scm_t_bits
)arg
;
49 scm_report_stack_overflow ()
51 scm_dynwind_begin (0); /* non-rewindable frame */
52 scm_dynwind_unwind_handler (reset_scm_stack_checking_enabled_p
,
53 (void*)(scm_t_bits
)scm_stack_checking_enabled_p
,
54 SCM_F_WIND_EXPLICITLY
);
56 scm_stack_checking_enabled_p
= 0;
58 scm_error (scm_stack_overflow_key
,
71 scm_stack_size (SCM_STACKITEM
*start
)
74 #if SCM_STACK_GROWS_UP
75 return &stack
- start
;
77 return start
- &stack
;
78 #endif /* SCM_STACK_GROWS_UP */
85 SCM port
= scm_current_error_port ();
87 scm_i_thread
*thread
= SCM_I_CURRENT_THREAD
;
89 scm_uintprint ((scm_stack_size (thread
->continuation_base
)
90 * sizeof (SCM_STACKITEM
)),
92 scm_puts (" of stack: 0x", port
);
93 scm_uintprint ((scm_t_bits
) thread
->continuation_base
, 16, port
);
94 scm_puts (" - 0x", port
);
95 scm_uintprint ((scm_t_bits
) &stack
, 16, port
);
96 scm_puts ("\n", port
);
100 SCM_DEFINE (scm_sys_get_stack_size
, "%get-stack-size", 0, 0, 0,
102 "Return the current thread's C stack size (in Scheme objects).")
103 #define FUNC_NAME s_scm_sys_get_stack_size
105 return scm_from_long (scm_stack_size (SCM_I_CURRENT_THREAD
->base
));
113 #include "libguile/stackchk.x"