[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Avoid C stack overflow
From: |
Dmitry Antipov |
Subject: |
Re: Avoid C stack overflow |
Date: |
Fri, 14 Mar 2014 15:27:46 +0400 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 |
On 03/14/2014 10:59 AM, Paul Eggert wrote:
Good point, I forgot about the stack-scanning problem.
After reading http://gcc.gnu.org/wiki/SplitStacks and
looking into libgcc sources, this looks reasonably simple:
=== modified file 'src/alloc.c'
--- src/alloc.c 2014-02-28 21:45:34 +0000
+++ src/alloc.c 2014-03-14 11:17:42 +0000
@@ -4866,11 +4866,30 @@
#endif /* not GC_SAVE_REGISTERS_ON_STACK */
#endif /* not HAVE___BUILTIN_UNWIND_INIT */
+#ifdef SPLIT_STACK
+
+ /* This assumes gcc >= 4.6.0 with -fsplit-stack
+ and corresponding support in libgcc. */
+ {
+ size_t stack_size;
+ extern void * __splitstack_find (void *, void *, size_t *,
+ void **, void **, void **);
+ void *next_segment = NULL, *next_sp = NULL, *initial_sp = NULL, *stack;
+
+ while ((stack = __splitstack_find (next_segment, next_sp, &stack_size,
+ &next_segment, &next_sp, &initial_sp)))
+ mark_memory (stack, (char *) stack + stack_size);
+ }
+
+#else /* not SPLIT_STACK */
+
/* This assumes that the stack is a contiguous region in memory. If
that's not the case, something has to be done here to iterate
over the stack segments. */
mark_memory (stack_base, end);
+#endif /* SPLIT_STACK */
+
/* Allow for marking a secondary stack, like the register stack on the
ia64. */
#ifdef GC_MARK_SECONDARY_STACK
After compiling with CPPFLAGS='-DSPLIT_STACK' and CFLAGS='-O0 -fsplit-stack
-g3',
I even got the binary which doesn't crash immediately (but do it somewhat
later, after a long byte-compile run :-().
Dmitry
- Avoid C stack overflow, Dmitry Antipov, 2014/03/13
- Re: Avoid C stack overflow, Eli Zaretskii, 2014/03/13
- Re: Avoid C stack overflow, Paul Eggert, 2014/03/13
- Re: Avoid C stack overflow, Eli Zaretskii, 2014/03/13
- Re: Avoid C stack overflow, Dmitry Antipov, 2014/03/14
- Re: Avoid C stack overflow, Paul Eggert, 2014/03/14
- Re: Avoid C stack overflow,
Dmitry Antipov <=
- Re: Avoid C stack overflow, Stefan Monnier, 2014/03/14
- Re: Avoid C stack overflow, Paul Eggert, 2014/03/14
- Re: Avoid C stack overflow, Stefan, 2014/03/14
- Re: Avoid C stack overflow, Stephen J. Turnbull, 2014/03/14