From 8ec17deed1a0dd237ffd20913c7d3341b93f79b2 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Fri, 13 Nov 2015 14:53:36 -0700 Subject: [PATCH] avoid Linux stack correction on non-main thread --- racket/src/racket/src/eval.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/racket/src/racket/src/eval.c b/racket/src/racket/src/eval.c index e7aa77c07a..7836194b31 100644 --- a/racket/src/racket/src/eval.c +++ b/racket/src/racket/src/eval.c @@ -518,7 +518,7 @@ scheme_handle_stack_overflow(Scheme_Object *(*k)(void)) } #ifdef LINUX_FIND_STACK_BASE -static uintptr_t adjust_stack_base(uintptr_t bnd) { +static uintptr_t adjust_stack_base(uintptr_t bnd, uintptr_t lim) { if (bnd == scheme_get_primordial_thread_stack_base()) { /* The address `base' might be far from the actual stack base if Exec Shield is enabled (in some versions)? Use @@ -553,7 +553,11 @@ static uintptr_t adjust_stack_base(uintptr_t bnd) { break; } /* printf("%p vs. %p: %d\n", (void*)bnd, (void*)p, p - bnd); */ - bnd = p; + if ((p > bnd) && ((p - lim) < bnd)) { + bnd = p; + } else { + /* bnd is too far from the expected range; on another thread? */ + } break; } } @@ -717,16 +721,16 @@ void scheme_init_stack_check() getrlimit(RLIMIT_STACK, &rl); -# ifdef LINUX_FIND_STACK_BASE - bnd = adjust_stack_base(bnd); -# endif - lim = (uintptr_t)rl.rlim_cur; # ifdef UNIX_STACK_MAXIMUM if (lim > UNIX_STACK_MAXIMUM) lim = UNIX_STACK_MAXIMUM; # endif +# ifdef LINUX_FIND_STACK_BASE + bnd = adjust_stack_base(bnd, lim); +# endif + if (stack_grows_up) bnd += (lim - STACK_SAFETY_MARGIN); else