avoid Linux stack correction on non-main thread

This commit is contained in:
Matthew Flatt 2015-11-13 14:53:36 -07:00
parent ebd84546ca
commit 8ec17deed1

View File

@ -518,7 +518,7 @@ scheme_handle_stack_overflow(Scheme_Object *(*k)(void))
} }
#ifdef LINUX_FIND_STACK_BASE #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()) { if (bnd == scheme_get_primordial_thread_stack_base()) {
/* The address `base' might be far from the actual stack base /* The address `base' might be far from the actual stack base
if Exec Shield is enabled (in some versions)? Use if Exec Shield is enabled (in some versions)? Use
@ -553,7 +553,11 @@ static uintptr_t adjust_stack_base(uintptr_t bnd) {
break; break;
} }
/* printf("%p vs. %p: %d\n", (void*)bnd, (void*)p, p - bnd); */ /* printf("%p vs. %p: %d\n", (void*)bnd, (void*)p, p - bnd); */
if ((p > bnd) && ((p - lim) < bnd)) {
bnd = p; bnd = p;
} else {
/* bnd is too far from the expected range; on another thread? */
}
break; break;
} }
} }
@ -717,16 +721,16 @@ void scheme_init_stack_check()
getrlimit(RLIMIT_STACK, &rl); getrlimit(RLIMIT_STACK, &rl);
# ifdef LINUX_FIND_STACK_BASE
bnd = adjust_stack_base(bnd);
# endif
lim = (uintptr_t)rl.rlim_cur; lim = (uintptr_t)rl.rlim_cur;
# ifdef UNIX_STACK_MAXIMUM # ifdef UNIX_STACK_MAXIMUM
if (lim > UNIX_STACK_MAXIMUM) if (lim > UNIX_STACK_MAXIMUM)
lim = UNIX_STACK_MAXIMUM; lim = UNIX_STACK_MAXIMUM;
# endif # endif
# ifdef LINUX_FIND_STACK_BASE
bnd = adjust_stack_base(bnd, lim);
# endif
if (stack_grows_up) if (stack_grows_up)
bnd += (lim - STACK_SAFETY_MARGIN); bnd += (lim - STACK_SAFETY_MARGIN);
else else