From patchwork Mon Aug 1 22:00:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 56475 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2A3223857C49 for ; Mon, 1 Aug 2022 22:01:03 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from sonata.ens-lyon.org (domu-toccata.ens-lyon.fr [140.77.166.138]) by sourceware.org (Postfix) with ESMTPS id A36413858023 for ; Mon, 1 Aug 2022 22:00:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A36413858023 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=ens-lyon.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=bounce.ens-lyon.org Received: from localhost (localhost [127.0.0.1]) by sonata.ens-lyon.org (Postfix) with ESMTP id A2E992012F; Tue, 2 Aug 2022 00:00:49 +0200 (CEST) Received: from sonata.ens-lyon.org ([127.0.0.1]) by localhost (sonata.ens-lyon.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id yJrMqOLh26qk; Tue, 2 Aug 2022 00:00:49 +0200 (CEST) Received: from begin (lfbn-bor-1-376-208.w109-215.abo.wanadoo.fr [109.215.91.208]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by sonata.ens-lyon.org (Postfix) with ESMTPSA id EF12D2012C; Tue, 2 Aug 2022 00:00:47 +0200 (CEST) Received: from samy by begin with local (Exim 4.96) (envelope-from ) id 1oIdSx-0049Ja-2V; Tue, 02 Aug 2022 00:00:47 +0200 From: Samuel Thibault To: libc-alpha@sourceware.org Subject: [hurd, commited] htl: Let pthread_self and cancellability called early Date: Tue, 2 Aug 2022 00:00:47 +0200 Message-Id: <20220801220047.989111-1-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: , Cc: commit-hurd@gnu.org Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" When applications redirect some functions they might get called before libpthread is fully initialized. They may still expected pthread_self and cancellable functions to work, so cope with such calls in that situation. --- htl/cancellation.c | 8 ++++++++ htl/pt-self.c | 8 +++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/htl/cancellation.c b/htl/cancellation.c index a5d5d2ac04..7d38944718 100644 --- a/htl/cancellation.c +++ b/htl/cancellation.c @@ -25,6 +25,10 @@ int __pthread_enable_asynccancel (void) struct __pthread *p = _pthread_self (); int oldtype; + if (___pthread_self == NULL) + /* We are not initialized yet, we can't be cancelled anyway. */ + return PTHREAD_CANCEL_DEFERRED; + __pthread_mutex_lock (&p->cancel_lock); oldtype = p->cancel_type; p->cancel_type = PTHREAD_CANCEL_ASYNCHRONOUS; @@ -39,6 +43,10 @@ void __pthread_disable_asynccancel (int oldtype) { struct __pthread *p = _pthread_self (); + if (___pthread_self == NULL) + /* We are not initialized yet, we can't be cancelled anyway. */ + return; + __pthread_mutex_lock (&p->cancel_lock); p->cancel_type = oldtype; __pthread_mutex_unlock (&p->cancel_lock); diff --git a/htl/pt-self.c b/htl/pt-self.c index 6fd3c98b82..e05ec69bf5 100644 --- a/htl/pt-self.c +++ b/htl/pt-self.c @@ -24,7 +24,13 @@ pthread_t __pthread_self (void) { - struct __pthread *self = _pthread_self (); + struct __pthread *self; + + if (___pthread_self == NULL) + /* We are not initialized yet, we are the first thread. */ + return 1; + + self = _pthread_self (); assert (self != NULL); return self->thread;