Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: XS Error: Segfault with B::HooksAtRuntime

by dave_the_m (Monsignor)
on Aug 07, 2022 at 12:52 UTC ( #11145995=note: print w/replies, xml ) Need Help??


in reply to Re: XS Error: Segfault with B::HooksAtRuntime
in thread XS Error: Segfault with B::HooksAtRuntime

I've now fully diagnosed the issue and have a small reproducible test case. The issue is the context stack being reallocated when deeply nests sub calls are made from after_runtime(), which is called from a destructor while exiting the eval scope from the require. That exiting code isn't expecting the context stack to be reallocated from under it. Normally when perl itself calls out to code from things like destructors, tied method calls etc, it uses a new temporary set of stacks (argument, context etc). after_runtime() needs to do something similar. This is achieved via the PUSHSTACKi() macro. Look at a distribution like Async-Interrupt for an example.

Here's the reproducible code. The recursive sub is called enough times to trigger a context stack grow/realloc.

------------------------- test.pl: use lib '.'; use Foo; ------------------------- Foo.pm: package Foo; use Bar; 1; ------------------------- Bar.pm: package Bar; use B::Hooks::AtRuntime 'after_runtime'; sub recurse { my $depth = shift; return if $depth < 0; recurse($depth -1); } sub import { after_runtime { recurse(20); } }
If this is run against a perl that has been built with -DDEBUGGING, you'll see the following assertion failure, which is Perl_cx_popeval() detecting that the current cx pointer has changed underneath it.
perl: inline.h:2921: Perl_cx_popeval: Assertion `CxTYPE(cx) == CXt_EVA +L' failed.

Dave.

Replies are listed 'Best First'.
Re^3: XS Error: Segfault with B::HooksAtRuntime
by Ovid (Cardinal) on Aug 08, 2022 at 07:04 UTC
      https://github.com/mauzo/B-Hooks-AtRuntime/issues/2

      Dave.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11145995]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2022-09-25 20:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer my indexes to start at:




    Results (116 votes). Check out past polls.

    Notices?