ruby-changes:46257
From: nobu <ko1@a...>
Date: Mon, 17 Apr 2017 09:10:51 +0900 (JST)
Subject: [ruby-changes:46257] nobu:r58374 (trunk): gc.c: PREVENT_STACK_OVERFLOW
nobu 2017-04-17 09:10:45 +0900 (Mon, 17 Apr 2017) New Revision: 58374 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58374 Log: gc.c: PREVENT_STACK_OVERFLOW * gc.c (PREVENT_STACK_OVERFLOW): define TRUE to try preventing stack overflow before actually happens. * gc.c (stack_check): parameterize thread pointer. Modified files: trunk/gc.c Index: gc.c =================================================================== --- gc.c (revision 58373) +++ gc.c (revision 58374) @@ -3937,12 +3937,18 @@ ruby_stack_length(VALUE **p) https://github.com/ruby/ruby/blob/trunk/gc.c#L3937 return STACK_LENGTH; } +#ifndef PREVENT_STACK_OVERFLOW #if !(defined(POSIX_SIGNAL) && defined(SIGSEGV) && defined(HAVE_SIGALTSTACK)) +# define PREVENT_STACK_OVERFLOW 1 +#else +# define PREVENT_STACK_OVERFLOW 0 +#endif +#endif +#if PREVENT_STACK_OVERFLOW static int -stack_check(int water_mark) +stack_check(rb_thread_t *th, int water_mark) { int ret; - rb_thread_t *th = GET_THREAD(); SET_STACK_END; ret = STACK_LENGTH > STACK_LEVEL_MAX - water_mark; #ifdef __ia64 @@ -3953,6 +3959,8 @@ stack_check(int water_mark) https://github.com/ruby/ruby/blob/trunk/gc.c#L3959 #endif return ret; } +#else +#define stack_check(th, water_mark) FALSE #endif #define STACKFRAME_FOR_CALL_CFUNC 512 @@ -3960,11 +3968,7 @@ stack_check(int water_mark) https://github.com/ruby/ruby/blob/trunk/gc.c#L3968 int ruby_stack_check(void) { -#if defined(POSIX_SIGNAL) && defined(SIGSEGV) && defined(HAVE_SIGALTSTACK) - return 0; -#else - return stack_check(STACKFRAME_FOR_CALL_CFUNC); -#endif + return stack_check(GET_THREAD(), STACKFRAME_FOR_CALL_CFUNC); } ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/