Commit | Line | Data |
---|---|---|
dbb605f5 | 1 | /* Copyright (C) 1995,1996,1997, 2000, 2001, 2006, 2008 Free Software Foundation, Inc. |
0f2d19dd | 2 | * |
73be1d9e | 3 | * This library is free software; you can redistribute it and/or |
53befeb7 NJ |
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. | |
0f2d19dd | 7 | * |
53befeb7 NJ |
8 | * This library is distributed in the hope that it will be useful, but |
9 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
73be1d9e MV |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
11 | * Lesser General Public License for more details. | |
0f2d19dd | 12 | * |
73be1d9e MV |
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 | |
53befeb7 NJ |
15 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
16 | * 02110-1301 USA | |
73be1d9e | 17 | */ |
6e8d25a6 | 18 | |
6e8d25a6 | 19 | |
0f2d19dd | 20 | \f |
dbb605f5 LC |
21 | #ifdef HAVE_CONFIG_H |
22 | # include <config.h> | |
23 | #endif | |
0f2d19dd | 24 | |
a0599745 MD |
25 | #include "libguile/_scm.h" |
26 | #include "libguile/ports.h" | |
27 | #include "libguile/root.h" | |
d8b6e191 | 28 | #include "libguile/threads.h" |
0f2d19dd | 29 | |
a0599745 | 30 | #include "libguile/stackchk.h" |
0f2d19dd JB |
31 | \f |
32 | ||
33 | /* {Stack Checking} | |
34 | */ | |
35 | ||
39f1ef51 MD |
36 | #ifdef STACK_CHECKING |
37 | int scm_stack_checking_enabled_p; | |
0f2d19dd | 38 | |
523f5266 GH |
39 | SCM_SYMBOL (scm_stack_overflow_key, "stack-overflow"); |
40 | ||
0f2d19dd JB |
41 | void |
42 | scm_report_stack_overflow () | |
43 | { | |
39f1ef51 | 44 | scm_stack_checking_enabled_p = 0; |
01f61221 | 45 | scm_error (scm_stack_overflow_key, |
f5bf2977 GH |
46 | NULL, |
47 | "Stack overflow", | |
48 | SCM_BOOL_F, | |
49 | SCM_BOOL_F); | |
0f2d19dd JB |
50 | } |
51 | ||
52 | #endif | |
1cc91f1b | 53 | |
1be6b49c | 54 | long |
6e8d25a6 | 55 | scm_stack_size (SCM_STACKITEM *start) |
0f2d19dd JB |
56 | { |
57 | SCM_STACKITEM stack; | |
8dda3eea | 58 | #if SCM_STACK_GROWS_UP |
0f2d19dd JB |
59 | return &stack - start; |
60 | #else | |
61 | return start - &stack; | |
8dda3eea | 62 | #endif /* SCM_STACK_GROWS_UP */ |
0f2d19dd JB |
63 | } |
64 | ||
1cc91f1b | 65 | |
0f2d19dd JB |
66 | void |
67 | scm_stack_report () | |
0f2d19dd | 68 | { |
9de87eea | 69 | SCM port = scm_current_error_port (); |
0f2d19dd | 70 | SCM_STACKITEM stack; |
9de87eea MV |
71 | scm_i_thread *thread = SCM_I_CURRENT_THREAD; |
72 | ||
73 | scm_uintprint ((scm_stack_size (thread->continuation_base) | |
74 | * sizeof (SCM_STACKITEM)), | |
75 | 16, port); | |
76 | scm_puts (" of stack: 0x", port); | |
77 | scm_uintprint ((scm_t_bits) thread->continuation_base, 16, port); | |
78 | scm_puts (" - 0x", port); | |
79 | scm_uintprint ((scm_t_bits) &stack, 16, port); | |
80 | scm_puts ("\n", port); | |
0f2d19dd JB |
81 | } |
82 | ||
d8b6e191 NJ |
83 | |
84 | SCM_DEFINE (scm_sys_get_stack_size, "%get-stack-size", 0, 0, 0, | |
85 | (), | |
86 | "Return the current thread's C stack size (in Scheme objects).") | |
87 | #define FUNC_NAME s_scm_sys_get_stack_size | |
88 | { | |
89 | return scm_from_long (scm_stack_size (SCM_I_CURRENT_THREAD->base)); | |
90 | } | |
91 | #undef FUNC_NAME | |
92 | ||
93 | ||
0f2d19dd JB |
94 | void |
95 | scm_init_stackchk () | |
0f2d19dd | 96 | { |
a0599745 | 97 | #include "libguile/stackchk.x" |
0f2d19dd | 98 | } |
89e00824 ML |
99 | |
100 | /* | |
101 | Local Variables: | |
102 | c-file-style: "gnu" | |
103 | End: | |
104 | */ |