* [PATCH] do not access aTHR when in a non-Perl process
@ 2022-09-15 20:31 Eric Wong
0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2022-09-15 20:31 UTC (permalink / raw)
To: mwrap-perl
This is needed to avoid segfaults in non-Perl processes
such as `cmake'.
Fixes: 3197316f33fdc5d4 "create the `totals' rculfhash as early as possible"
---
Mwrap.xs | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/Mwrap.xs b/Mwrap.xs
index 092aaf4..31e9394 100644
--- a/Mwrap.xs
+++ b/Mwrap.xs
@@ -344,18 +344,20 @@ update_stats_rcu_lock(size_t *generation, size_t size, uintptr_t caller)
struct src_loc *k, *ret = 0;
static const size_t xlen = sizeof(caller);
char *dst;
- const COP *cop;
+ const COP *cop = NULL;
struct cds_lfht *t = CMM_LOAD_SHARED(totals);
if (caa_unlikely(!t)) return 0;
if (locating++) goto out; /* do not recurse into another *alloc */
*generation = uatomic_add_return(&total_bytes_inc, size);
+ if (&PL_thr_key) { /* are we even in a Perl process? */
#ifdef PERL_IMPLICIT_CONTEXT
- cop = aTHX ? PL_curcop : 0;
+ if (aTHX) cop = PL_curcop;
#else
- cop = &locating == root_locating ? PL_curcop : 0;
+ if (&locating == root_locating) cop = PL_curcop;
#endif
+ }
rcu_read_lock();
if (cop) {
const char *ptr = OutCopFILE(cop);
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2022-09-15 20:33 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-15 20:31 [PATCH] do not access aTHR when in a non-Perl process Eric Wong
Code repositories for project(s) associated with this public inbox
https://80x24.org/mwrap-perl.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).