In perl.git, the branch blead has been updated <http://perl5.git.perl.org/perl.git/commitdiff/d5910a3d38b3bf04d5da54f868438b2d8085a820?hp=6efb583a3779086d6dce2899767ca920f0eda754>
- Log ----------------------------------------------------------------- commit d5910a3d38b3bf04d5da54f868438b2d8085a820 Author: David Mitchell <[email protected]> Date: Mon Jul 3 14:20:42 2017 +0100 properly init si_stack_hwm It was being initialised when a new stack was pushed, but not for the main stack. This didn't matter most of the time as runops() would set it anyway, but perl -e 'INIT {}' was doing a call_sv() before/outside of any runops loop, so showed up in valgrind as uninitialised usage. M perl.c commit 9449f0d6ae2e0e6852c0b9be8be63c3525747345 Author: David Mitchell <[email protected]> Date: Mon Jul 3 13:43:27 2017 +0100 save si_stack_hwm across JMPENV_PUSH When continuing after an exception (JMPENV_PUSH() returns 3), restore the value of PL_curstackinfo->si_stack_hwm. This is a recently added variable on debugging builds that detects attempts to push stuff on the stack without extending it. After an exception its value may be invalid and trigger a false panic. M cop.h ----------------------------------------------------------------------- Summary of changes: cop.h | 18 ++++++++++++++++++ perl.c | 3 +++ 2 files changed, 21 insertions(+) diff --git a/cop.h b/cop.h index 2be8fb1e9d..be23b3dfcd 100644 --- a/cop.h +++ b/cop.h @@ -35,10 +35,25 @@ struct jmpenv { int je_ret; /* last exception thrown */ bool je_mustcatch; /* need to call longjmp()? */ U16 je_old_delaymagic; /* saved PL_delaymagic */ +#if defined DEBUGGING && !defined DEBUGGING_RE_ONLY + SSize_t je_old_stack_hwm; +#endif }; typedef struct jmpenv JMPENV; +#if defined DEBUGGING && !defined DEBUGGING_RE_ONLY +# define JE_OLD_STACK_HWM_zero PL_start_env.je_old_stack_hwm = 0 +# define JE_OLD_STACK_HWM_save(je) \ + (je).je_old_stack_hwm = PL_curstackinfo->si_stack_hwm +# define JE_OLD_STACK_HWM_restore(je) \ + PL_curstackinfo->si_stack_hwm = (je).je_old_stack_hwm +#else +# define JE_OLD_STACK_HWM_zero NOOP +# define JE_OLD_STACK_HWM_save(je) NOOP +# define JE_OLD_STACK_HWM_restore(je) NOOP +#endif + /* * How to build the first jmpenv. * @@ -57,6 +72,7 @@ typedef struct jmpenv JMPENV; PL_start_env.je_ret = -1; \ PL_start_env.je_mustcatch = TRUE; \ PL_start_env.je_old_delaymagic = 0; \ + JE_OLD_STACK_HWM_zero; \ } STMT_END /* @@ -102,7 +118,9 @@ typedef struct jmpenv JMPENV; Perl_deb(aTHX_ "JUMPENV_PUSH level=%d at %s:%d\n", \ i, __FILE__, __LINE__);}) \ cur_env.je_prev = PL_top_env; \ + JE_OLD_STACK_HWM_save(cur_env); \ cur_env.je_ret = PerlProc_setjmp(cur_env.je_buf, SCOPE_SAVES_SIGNAL_MASK); \ + JE_OLD_STACK_HWM_restore(cur_env); \ PL_top_env = &cur_env; \ cur_env.je_mustcatch = FALSE; \ cur_env.je_old_delaymagic = PL_delaymagic; \ diff --git a/perl.c b/perl.c index d7b0866dd0..3497043d79 100644 --- a/perl.c +++ b/perl.c @@ -4161,6 +4161,9 @@ Perl_init_stacks(pTHX) PL_curstackinfo = new_stackinfo(REASONABLE(128), REASONABLE(8192/sizeof(PERL_CONTEXT) - 1)); PL_curstackinfo->si_type = PERLSI_MAIN; +#if defined DEBUGGING && !defined DEBUGGING_RE_ONLY + PL_curstackinfo->si_stack_hwm = 0; +#endif PL_curstack = PL_curstackinfo->si_stack; PL_mainstack = PL_curstack; /* remember in case we switch stacks */ -- Perl5 Master Repository
