Branch: Tag:

2019-10-19

2019-10-19 13:14:44 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Runtime: Improved robustness of pike_throw().

During stack clean up the throw_value could get zapped by
various callbacks. Save it on entry of pike_throw(), and
restore it before the actual throw.

126:      PMOD_EXPORT DECLSPEC(noreturn) void pike_throw(void) ATTRIBUTE((noreturn))   { +  struct svalue save_throw_value; +  +  /* Save the value to be thrown in case error handlers etc below +  * call eg safe_apply() et al, or cause a thread switch to +  * code that does. +  */ +  move_svalue(&save_throw_value, &throw_value); +  mark_free_svalue(&throw_value); +    #ifdef TRACE_UNFINISHED_TYPE_FIELDS    accept_unfinished_type_fields++;   #endif
198:    Pike_fatal("Stack error in error.\n");   #endif    +  /* Note: The pop_n_elems below may trigger destruct callbacks being called +  * for objects having PROGRAM_DESTRUCT_IMMEDIATE. These may +  * in turn throw (caught) errors and zap throw_value. +  */    pop_n_elems(Pike_sp - Pike_interpreter.evaluator_stack - Pike_interpreter.recoveries->stack_pointer);    Pike_mark_sp = Pike_interpreter.mark_stack + Pike_interpreter.recoveries->mark_sp;    -  +  /* Move the value to be thrown back so that it can be caught. */ +  free_svalue(&throw_value); +  move_svalue(&throw_value, &save_throw_value); +    #if defined(DEBUG_MALLOC) && defined(PIKE_DEBUG)    /* This will tell us where the value was caught (I hope) */    if(REFCOUNTED_TYPE(TYPEOF(throw_value)))