From patchwork Thu Mar 26 15:56:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Desnoyers X-Patchwork-Id: 38625 Return-Path: X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail.efficios.com (mail.efficios.com [167.114.26.124]) by sourceware.org (Postfix) with ESMTPS id C1031385F020 for ; Thu, 26 Mar 2020 15:57:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org C1031385F020 Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 7BCE7277D42; Thu, 26 Mar 2020 11:57:05 -0400 (EDT) Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id hiA2Vs_1JuF1; Thu, 26 Mar 2020 11:57:05 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id A6B11277D40; Thu, 26 Mar 2020 11:57:00 -0400 (EDT) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com A6B11277D40 X-Virus-Scanned: amavisd-new at efficios.com Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id ahnDqlBYAei3; Thu, 26 Mar 2020 11:57:00 -0400 (EDT) Received: from localhost.localdomain (192-222-181-218.qc.cable.ebox.net [192.222.181.218]) by mail.efficios.com (Postfix) with ESMTPSA id 42FB9277D3F; Thu, 26 Mar 2020 11:56:58 -0400 (EDT) From: Mathieu Desnoyers To: Carlos O'Donell Cc: Florian Weimer , Joseph Myers , Szabolcs Nagy , libc-alpha@sourceware.org, Mathieu Desnoyers Subject: [PATCH glibc 7/9] support record failure: allow use from constructor Date: Thu, 26 Mar 2020 11:56:31 -0400 Message-Id: <20200326155633.18236-8-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200326155633.18236-1-mathieu.desnoyers@efficios.com> References: <20200326155633.18236-1-mathieu.desnoyers@efficios.com> X-Spam-Status: No, score=-30.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 26 Mar 2020 15:57:06 -0000 Expose support_record_failure_init () so constructors can explicitly initialize the record failure API. This is preferred to lazy initialization at first use, because lazy initialization does not cover use in constructors within forked children processes (forked from parent constructor). Signed-off-by: Mathieu Desnoyers Reviewed-by: Carlos O'Donell CC: Carlos O'Donell CC: Florian Weimer CC: Joseph Myers CC: Szabolcs Nagy CC: libc-alpha@sourceware.org --- support/check.h | 4 ++++ support/support_record_failure.c | 18 +++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/support/check.h b/support/check.h index 77d1d1e14d..902cea6878 100644 --- a/support/check.h +++ b/support/check.h @@ -88,6 +88,10 @@ void support_test_verify_exit_impl (int status, const char *file, int line, does not support reporting failures from a DSO. */ void support_record_failure (void); +/* Initialize record failure. Calling this is only needed when + recording failures from constructors. */ +void support_record_failure_init (void); + /* Static assertion, under a common name for both C++ and C11. */ #ifdef __cplusplus # define support_static_assert static_assert diff --git a/support/support_record_failure.c b/support/support_record_failure.c index f766c06236..957572f487 100644 --- a/support/support_record_failure.c +++ b/support/support_record_failure.c @@ -32,8 +32,12 @@ zero, the failure of a test can be detected. The init constructor function below puts *state on a shared - annonymous mapping, so that failure reports from subprocesses - propagate to the parent process. */ + anonymous mapping, so that failure reports from subprocesses + propagate to the parent process. + + support_record_failure_init is exposed so it can be called explicitly + in case this API needs to be used from a constructor. */ + struct test_failures { unsigned int counter; @@ -41,10 +45,14 @@ struct test_failures }; static struct test_failures *state; -static __attribute__ ((constructor)) void -init (void) +__attribute__ ((constructor)) void +support_record_failure_init (void) { - void *ptr = mmap (NULL, sizeof (*state), PROT_READ | PROT_WRITE, + void *ptr; + + if (state != NULL) + return; + ptr = mmap (NULL, sizeof (*state), PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED, -1, 0); if (ptr == MAP_FAILED) {