Do not allocate new objects at machine stack overflow

This commit is contained in:
Nobuyoshi Nakada 2025-04-24 11:01:42 +09:00
parent cb1ea54bbf
commit 5dc155351a
No known key found for this signature in database
GPG Key ID: 3582D74E1FEE4465
Notes: git 2025-04-24 08:29:46 +00:00
3 changed files with 10 additions and 9 deletions

View File

@ -856,7 +856,7 @@ check_stack_overflow(int sig, const uintptr_t addr, const ucontext_t *ctx)
ec->tag = ec->tag->prev; ec->tag = ec->tag->prev;
} }
reset_sigmask(sig); reset_sigmask(sig);
rb_ec_stack_overflow(ec, crit); rb_ec_stack_overflow(ec, crit + 1);
} }
} }
# else # else
@ -867,7 +867,7 @@ check_stack_overflow(int sig, const void *addr)
rb_thread_t *th = GET_THREAD(); rb_thread_t *th = GET_THREAD();
if (ruby_stack_overflowed_p(th, addr)) { if (ruby_stack_overflowed_p(th, addr)) {
reset_sigmask(sig); reset_sigmask(sig);
rb_ec_stack_overflow(th->ec, FALSE); rb_ec_stack_overflow(th->ec, 1);
} }
} }
# endif # endif

View File

@ -381,7 +381,7 @@ stack_check(rb_execution_context_t *ec)
if (!rb_ec_raised_p(ec, RAISED_STACKOVERFLOW) && if (!rb_ec_raised_p(ec, RAISED_STACKOVERFLOW) &&
rb_ec_stack_check(ec)) { rb_ec_stack_check(ec)) {
rb_ec_raised_set(ec, RAISED_STACKOVERFLOW); rb_ec_raised_set(ec, RAISED_STACKOVERFLOW);
rb_ec_stack_overflow(ec, FALSE); rb_ec_stack_overflow(ec, 0);
} }
} }

View File

@ -79,22 +79,23 @@ vm_stackoverflow(void)
} }
NORETURN(void rb_ec_stack_overflow(rb_execution_context_t *ec, int crit)); NORETURN(void rb_ec_stack_overflow(rb_execution_context_t *ec, int crit));
/* critical level
* 0: VM stack overflow or about to machine stack overflow
* 1: machine stack overflow but may be recoverable
* 2: fatal machine stack overflow
*/
void void
rb_ec_stack_overflow(rb_execution_context_t *ec, int crit) rb_ec_stack_overflow(rb_execution_context_t *ec, int crit)
{ {
if (rb_during_gc()) { if (rb_during_gc()) {
rb_bug("system stack overflow during GC. Faulty native extension?"); rb_bug("system stack overflow during GC. Faulty native extension?");
} }
if (crit) { if (crit > 1) {
ec->raised_flag = RAISED_STACKOVERFLOW; ec->raised_flag = RAISED_STACKOVERFLOW;
ec->errinfo = rb_ec_vm_ptr(ec)->special_exceptions[ruby_error_stackfatal]; ec->errinfo = rb_ec_vm_ptr(ec)->special_exceptions[ruby_error_stackfatal];
EC_JUMP_TAG(ec, TAG_RAISE); EC_JUMP_TAG(ec, TAG_RAISE);
} }
#ifdef USE_SIGALTSTACK ec_stack_overflow(ec, crit == 0);
ec_stack_overflow(ec, TRUE);
#else
ec_stack_overflow(ec, FALSE);
#endif
} }
static inline void stack_check(rb_execution_context_t *ec); static inline void stack_check(rb_execution_context_t *ec);