From patchwork Mon Jan 21 21:35:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Desnoyers X-Patchwork-Id: 31142 Received: (qmail 120289 invoked by alias); 21 Jan 2019 21:35:40 -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 120272 invoked by uid 89); 21 Jan 2019 21:35:39 -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=processes, Hx-languages-length:2511 X-HELO: mail.efficios.com DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com 85B48B4FD6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=default; t=1548106535; bh=Y9fljxGenEDFJcR2l6UzzKhcPSiDdjUeVx3LMVgR9p4=; h=From:To:Date:Message-Id; b=OktFk6f2Tw05PXaSmtZRBCZF3W5tRQNUuF/GoD6E6IGuuDsTSxgrWKMK31j1TSUpq 0zKjgsw+WY8Mzo8rMCdMq2Q87REapWgHqTQkZvO1HGupvFm1tkWy/OZCTDf0+4SJVO B1soXYtmxJsgJjaMwkz0mnpM265uxYbumGdt6kn73x1b/hXxwooS/fXkSsbZeN9oB1 XG8lR3smH4Na61h6+Pm/hI8u2x6SBswvoTVdscZ1run7jHjtn3Czeg7BrhZOfAHRFd Gr5z7PoF9obiYCQ04CaRl75w8OGFoSc6KnWf4r20Jk1K5AWm4yqqMjiZwz9cDwRM0x Hnz/AhUQdMV9A== From: Mathieu Desnoyers To: Carlos O'Donell Cc: Florian Weimer , Joseph Myers , Szabolcs Nagy , libc-alpha@sourceware.org, Mathieu Desnoyers Subject: [RFC PATCH glibc 3/4] support record failure: allow use from constructor Date: Mon, 21 Jan 2019 16:35:29 -0500 Message-Id: <20190121213530.23803-3-mathieu.desnoyers@efficios.com> In-Reply-To: <20190121213530.23803-1-mathieu.desnoyers@efficios.com> References: <20190121213530.23803-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 | 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 e6765289f2..9ccd73884c 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 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) {