From patchwork Sun Jun 14 16:57:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 1308985 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ens-lyon.org Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49lLJ56S2Gz9sRk for ; Mon, 15 Jun 2020 02:58:13 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 35E0A395C401; Sun, 14 Jun 2020 16:58:04 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from hera.aquilenet.fr (hera.aquilenet.fr [185.233.100.1]) by sourceware.org (Postfix) with ESMTPS id BC902388B01D for ; Sun, 14 Jun 2020 16:58:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org BC902388B01D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=ens-lyon.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=samuel.thibault@ens-lyon.org Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 70CB833C4; Sun, 14 Jun 2020 18:58:00 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Tda2CrYZHXpf; Sun, 14 Jun 2020 18:57:58 +0200 (CEST) Received: from function.home (unknown [IPv6:2a01:cb19:956:1b00:9eb6:d0ff:fe88:c3c7]) by hera.aquilenet.fr (Postfix) with ESMTPSA id A0697330A; Sun, 14 Jun 2020 18:57:58 +0200 (CEST) Received: from samy by function.home with local (Exim 4.94) (envelope-from ) id 1jkVxF-00HRMG-5D; Sun, 14 Jun 2020 18:57:57 +0200 From: Samuel Thibault To: libc-alpha@sourceware.org Subject: [hurd, commited 3/6] htl: Move cleanup stack to variable shared between libc and pthread Date: Sun, 14 Jun 2020 18:57:54 +0200 Message-Id: <20200614165757.4156687-4-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200614165757.4156687-1-samuel.thibault@ens-lyon.org> References: <20200614165757.4156687-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_NEUTRAL, 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: , Cc: commit-hurd@gnu.org Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" If libpthread gets loaded dynamically, the stack needs to already contain the cleanup handlers of the main thread. * htl/libc_pthread_init.c (__pthread_cleanup_stack): New per-thread variable. * htl/Versions (libc): Add __pthread_cleanup_stack as private symbol. * htl/pt-internal.h (struct __pthread): Remove cancelation_handlers field. (__pthread_cleanup_stack): Add variable declaration. * htl/pt-alloc.c (initialize_pthread): Remove initialization of cancelation_handlers field. * htl/pt-cleanup.c (__pthread_get_cleanup_stack): Return the address of __pthread_cleanup_stack instead of that of the cancelation_handlers field. * htl/forward.c: Include . (dummy_list): Remove variable. (__pthread_get_cleanup_stack): Return the address of __pthread_cleanup_stack instead of that of dummy_list. --- htl/Versions | 1 + htl/forward.c | 4 ++-- htl/libc_pthread_init.c | 2 ++ htl/pt-alloc.c | 2 -- htl/pt-cleanup.c | 2 +- htl/pt-internal.h | 4 +++- 6 files changed, 9 insertions(+), 6 deletions(-) diff --git a/htl/Versions b/htl/Versions index fd9eefbaee..832cc5d814 100644 --- a/htl/Versions +++ b/htl/Versions @@ -29,6 +29,7 @@ libc { GLIBC_PRIVATE { __libc_alloca_cutoff; __libc_pthread_init; + __pthread_cleanup_stack; } } diff --git a/htl/forward.c b/htl/forward.c index dfb7b79327..544e7da058 100644 --- a/htl/forward.c +++ b/htl/forward.c @@ -23,6 +23,7 @@ #include #include #include +#include /* Pointers to the libc functions. */ struct pthread_functions __libc_pthread_functions attribute_hidden; @@ -140,6 +141,5 @@ strong_alias (__pthread_setcancelstate, pthread_setcancelstate); FORWARD (pthread_setcanceltype, (int type, int *oldtype), (type, oldtype), 0) -struct __pthread_cancelation_handler *dummy_list; FORWARD2 (__pthread_get_cleanup_stack, struct __pthread_cancelation_handler **, - (void), (), return &dummy_list); + (void), (), return &__pthread_cleanup_stack); diff --git a/htl/libc_pthread_init.c b/htl/libc_pthread_init.c index cee92f76ee..f617c4e0be 100644 --- a/htl/libc_pthread_init.c +++ b/htl/libc_pthread_init.c @@ -19,6 +19,8 @@ #include #include +__thread struct __pthread_cancelation_handler *__pthread_cleanup_stack; + void __libc_pthread_init (const struct pthread_functions *functions) { diff --git a/htl/pt-alloc.c b/htl/pt-alloc.c index d4426bb2e3..bf37aca729 100644 --- a/htl/pt-alloc.c +++ b/htl/pt-alloc.c @@ -65,8 +65,6 @@ initialize_pthread (struct __pthread *new) new->state_lock = (pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER; new->state_cond = (pthread_cond_t) PTHREAD_COND_INITIALIZER; - new->cancelation_handlers = 0; - memset (&new->res_state, '\0', sizeof (new->res_state)); new->tcb = NULL; diff --git a/htl/pt-cleanup.c b/htl/pt-cleanup.c index a9a7c95847..7e6149bda9 100644 --- a/htl/pt-cleanup.c +++ b/htl/pt-cleanup.c @@ -23,6 +23,6 @@ struct __pthread_cancelation_handler ** __pthread_get_cleanup_stack (void) { - return &_pthread_self ()->cancelation_handlers; + return &__pthread_cleanup_stack; } hidden_def(__pthread_get_cleanup_stack) diff --git a/htl/pt-internal.h b/htl/pt-internal.h index 918c207c3e..e0baa6bcda 100644 --- a/htl/pt-internal.h +++ b/htl/pt-internal.h @@ -81,7 +81,6 @@ struct __pthread int cancel_state; int cancel_type; int cancel_pending; - struct __pthread_cancelation_handler *cancelation_handlers; /* Thread stack. */ void *stackaddr; @@ -197,6 +196,9 @@ extern pthread_rwlock_t __pthread_threads_lock; #ifndef _pthread_self extern struct __pthread *_pthread_self (void); #endif + +/* Stores the stack of cleanup handlers for the thread. */ +extern __thread struct __pthread_cancelation_handler *__pthread_cleanup_stack; /* Initialize the pthreads library. */