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: AS31976 209.132.180.0/23 X-Spam-Status: No, score=-4.1 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 371701F463 for ; Mon, 6 Jan 2020 15:58:50 +0000 (UTC) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=vQkpZRbazwQ/jBja8HdcChVGrrLLZkR kZj9CVwwgOpNFAOJtYZVHB4W21zQC1oMCzPiIYXlvwcBRnaNRydG2hj4KCmUqgPC r4hz9Q4mg8NhHXoLpi6+W9xqWgJfYNun7Vw8lZ6ggYyVnGk/P2/qzw+pTvRUsAxO 2GyyqMRuWjtA= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references; s=default; bh=lA60dTiXVVo9RrDmJ/MZfK5d4F0=; b=wlH02 fYqqxdSEL/x0Jv9P83vguZc3UTmPbOMQPR6UnIz1WhxhUJ4fLlC08SIwRRNUXK0v WD8E2HHv/Y4DMVKAdXd8QEUFRGbL1rXMF3ALzl5V7jrCKwKURpE36dzYecHocfnk PUBBFnH5Q2XChh/FQxFvaXPOgsN0f0vsKY4Buo= Received: (qmail 95874 invoked by alias); 6 Jan 2020 15:57:35 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Received: (qmail 95795 invoked by uid 89); 6 Jan 2020 15:57:34 -0000 Authentication-Results: sourceware.org; auth=none X-HELO: mail.efficios.com DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com BFFF31EA1DD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=default; t=1578326241; bh=XUyhqOnJK2L8XoVFKJpGbZ+shMeWtDqnDGuoYxu7m74=; h=From:To:Date:Message-Id; b=ZR7lICG/lE62f48B3PXP2lH6DEzqawC9WAK5UI5pTmFakFrvLXzjE/c8tlcD49DLn QPDBdsJveHjFBEskeJ7ZYDRoo9Sl02VZnDtPmyN/fRyOKYy8aJDKNtLhdLmsBdFk70 AOwJzOqKEQ2n5Zcd4hS1ZwjX2F8crqqNpWVAElREhgoDdbUibUtJ7qach549pGf1BI O7kCQPD/kI7tvKoqbap6PQMvHOuU083HlYl8mbV8r5uptMakf54ckdI/5zSBUv+4Hp 3MhkcVG+wDWUfMSY1mcGQ0PMTtDDyngRPkffw0hflOI7/3HG66YaB7iRL2NIRqlDxT suHvqp8fUVoLA== From: Mathieu Desnoyers To: Carlos O'Donell Cc: Florian Weimer , Joseph Myers , Szabolcs Nagy , libc-alpha@sourceware.org, Mathieu Desnoyers Subject: [RFC PATCH glibc 11/13] support record failure: allow use from constructor Date: Mon, 6 Jan 2020 10:57:11 -0500 Message-Id: <20200106155713.397-12-mathieu.desnoyers@efficios.com> In-Reply-To: <20200106155713.397-1-mathieu.desnoyers@efficios.com> References: <20200106155713.397-1-mathieu.desnoyers@efficios.com> 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 e95f4ae91b..630d263c81 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 9df679c4cc..8b9e97d882 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) { -- 2.17.1