From patchwork Wed Nov 11 20:43:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 41021 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 B136B3833021; Wed, 11 Nov 2020 20:43:26 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from hera.aquilenet.fr (hera.aquilenet.fr [IPv6:2a0c:e300::1]) by sourceware.org (Postfix) with ESMTPS id D5F0C383302F for ; Wed, 11 Nov 2020 20:43:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D5F0C383302F 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 011EADB4; Wed, 11 Nov 2020 21:43:24 +0100 (CET) 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 D8QvC6iUMWQP; Wed, 11 Nov 2020 21:43:23 +0100 (CET) Received: from function.youpi.perso.aquilenet.fr (lfbn-bor-1-56-204.w90-50.abo.wanadoo.fr [90.50.148.204]) by hera.aquilenet.fr (Postfix) with ESMTPSA id E04D0DB3; Wed, 11 Nov 2020 21:43:21 +0100 (CET) Received: from samy by function.youpi.perso.aquilenet.fr with local (Exim 4.94) (envelope-from ) id 1kcwxZ-002Unu-Qr; Wed, 11 Nov 2020 21:43:17 +0100 From: Samuel Thibault To: libc-alpha@sourceware.org Subject: [hurd, commited 2/4] htl: Keep thread signals blocked during its initialization Date: Wed, 11 Nov 2020 21:43:14 +0100 Message-Id: <20201111204316.595017-3-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201111204316.595017-1-samuel.thibault@ens-lyon.org> References: <20201111204316.595017-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 X-Spam-Status: No, score=-11.3 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" One may send signals immediately after creating a thread. We need to block them until the thread is ready to run signal handlers. --- htl/pt-create.c | 12 ++++++++++-- htl/pt-internal.h | 3 +++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/htl/pt-create.c b/htl/pt-create.c index 7ac875cbf7..9364c40453 100644 --- a/htl/pt-create.c +++ b/htl/pt-create.c @@ -46,6 +46,8 @@ unsigned int __pthread_total; static void entry_point (struct __pthread *self, void *(*start_routine) (void *), void *arg) { + int err; + ___pthread_self = self; __resp = &self->res_state; @@ -60,6 +62,10 @@ entry_point (struct __pthread *self, void *(*start_routine) (void *), void *arg) __pthread_startup (); + /* We can now unleash signals. */ + err = __pthread_sigstate (self, SIG_SETMASK, &self->init_sigset, 0, 0); + assert_perror (err); + if (self->c11) { /* The function pointer of the c11 thread start is cast to an incorrect @@ -201,11 +207,13 @@ __pthread_create_internal (struct __pthread **thread, shall be empty." If the currnet thread is not a pthread then we just inherit the process' sigmask. */ if (__pthread_num_threads == 1) - err = __sigprocmask (0, 0, &sigset); + err = __sigprocmask (0, 0, &pthread->init_sigset); else - err = __pthread_sigstate (_pthread_self (), 0, 0, &sigset, 0); + err = __pthread_sigstate (_pthread_self (), 0, 0, &pthread->init_sigset, 0); assert_perror (err); + /* But block the signals for now, until the thread is fully initialized. */ + __sigfillset (&sigset); err = __pthread_sigstate (pthread, SIG_SETMASK, &sigset, 0, 1); assert_perror (err); diff --git a/htl/pt-internal.h b/htl/pt-internal.h index e0baa6bcda..9dffa0e32e 100644 --- a/htl/pt-internal.h +++ b/htl/pt-internal.h @@ -102,6 +102,9 @@ struct __pthread /* Indicates whether is a C11 thread created by thrd_creat. */ bool c11; + /* Initial sigset for the thread. */ + sigset_t init_sigset; + /* Thread context. */ struct pthread_mcontext mcontext;