From patchwork Wed Nov 21 18:39:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Desnoyers X-Patchwork-Id: 1001344 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-97437-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=efficios.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="s8lKQWVg"; dkim=pass (2048-bit key; unprotected) header.d=efficios.com header.i=@efficios.com header.b="p65KUlYY"; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 430WbC3jjkz9s3C for ; Thu, 22 Nov 2018 05:40:07 +1100 (AEDT) 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=XBqwLUS5I/n0Xxuq5+Ezuo1vmzx7OIy /88/u9AANBkFPxu5NU2Y1VFdXZsd6S/GSRAACcRkFEdEq4twLbSDweKqNKSOWYyw ONx11+NTNknsxQfoq8NZHJ5IxOYzQ+JodvQLzKi3gHpi3Ycqeo39Bkxa0kQ41lfA u0i6B+jA9NQ8= 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=p4k/YYWODMRxhOniPIY4vi6bHIE=; b=s8lKQ WVgDb/3cRYneYBKjFIu1wetzq2GGbwLWqzO5ltdR8BhUf7pbnbvSZAPp+xQDmeCe 5OhmcNkOHAp0UHVSXhIExlQ86eL0Mhbk9gZFzSjKjkMN++cMrv6e0fMFbGYsXJxm 0tukRYchipFnSv9rLdYTXX4miVrtCgBnhaBUV8= Received: (qmail 114732 invoked by alias); 21 Nov 2018 18:39:53 -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 Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 114690 invoked by uid 89); 21 Nov 2018 18:39:52 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail.efficios.com DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com E3B77133E99 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=default; t=1542825588; bh=FnvL95PqGaQ4YaTEtwgOx7cG2RylXQhy6uehRbN8sqc=; h=From:To:Date:Message-Id; b=p65KUlYY0XJ9kVFvmCIUhYu+L1pwG/P58AynPSzFl+/AMGWMxnSJFmsPEh2gEbryp u+ZKZiVDlfxjQRd9IJ4pyCa1gisDllzqmAYiyKvUAaJuL2rM4WVubx5gftSpPz4+sD jionfmYWiJEs2Z+rL90Nq+t+8/RRlOlddrA5t+05Uxcvtr5KDUvaqh3Yak5MA2GKwA IkQMddQdH8wK9LdqHtro6BrjlT6Jf830+gA4zzaOQm3UkkIRVjlGxywM6t0BXTzAt3 cz7ZyFh71q/GNGelVne+VJVu3jA9WItVOtPdAINC1KimMkhnSzHb+9bqCq4gxJ6A8U b8USGbhdethPw== From: Mathieu Desnoyers To: Carlos O'Donell Cc: Florian Weimer , Joseph Myers , Szabolcs Nagy , libc-alpha@sourceware.org, Mathieu Desnoyers Subject: [RFC PATCH v4 4/5] support record failure: allow use from constructor Date: Wed, 21 Nov 2018 13:39:35 -0500 Message-Id: <20181121183936.8176-4-mathieu.desnoyers@efficios.com> In-Reply-To: <20181121183936.8176-1-mathieu.desnoyers@efficios.com> References: <20181121183936.8176-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 CC: Carlos O'Donell CC: Florian Weimer CC: Joseph Myers CC: Szabolcs Nagy CC: libc-alpha@sourceware.org --- support/check.h | 3 +++ support/support_record_failure.c | 18 +++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/support/check.h b/support/check.h index e6765289f2..25aae52003 100644 --- a/support/check.h +++ b/support/check.h @@ -88,6 +88,9 @@ 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 356798f556..947551d2c8 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) {