From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id A8D191F506 for ; Thu, 15 Sep 2022 20:33:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1663274012; bh=fUlaPd+zD1DDMZCVgu2neOSJwJVxQuibuohks+9mXHg=; h=From:To:Subject:Date:From; b=obUVNTvU5NY9v7PQbtJ5PfjMnMneZYhnBDDYwbt/ROGzeAY1UxQObPmto1IipgNTv lGluydZioLB4+5I7HHJoVr53m5NrxjDviQce+qjiaTzbLD0uOpvbGUK0/0zfmdXgKY EbngTxWJ6AwxJqGiiFtZUK3gnK6LDZnvQOsVn2Ko= From: Eric Wong To: mwrap-perl@80x24.org Subject: [PATCH] do not access aTHR when in a non-Perl process Date: Thu, 15 Sep 2022 20:31:59 +0000 Message-Id: <20220915203159.2253027-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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);