From patchwork Sat Mar 15 21:40:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 107943 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 930023858C48 for ; Sat, 15 Mar 2025 21:40:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 930023858C48 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 A7BFC3858D35 for ; Sat, 15 Mar 2025 21:40:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A7BFC3858D35 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 ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A7BFC3858D35 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=140.77.166.138 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1742074814; cv=none; b=TkBcuOqh08N5U6NcuNr5n6yIbavprQvqfJiae36qunqrU5cnebF5VoAjAQnXOICN5ocY4AlWO39+9eRhPsk0PReTedlQ73rttLbr7VCPxJbkYt940vpjba5jJPi2vZcKJj22Zb76osfP3hRQsGb4Frz2XonbpZNpkEEjBvaDlv4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1742074814; c=relaxed/simple; bh=R1ziUdwyc4oS9zjvU/sotkb1ZB2hpifpB/ROH+FZTIw=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=E0/SxNWEUG4W7xFW+EqX3gbsc1Xd5uldw/KI30pmdL5tWLO69pl77LuNxVAdldaNIFX5IJz4gp/Q8wWzPd9meAU+D34dvSLGWxD5BQjElLdySnuQoQAXwyMePgZwfT4+kuJGhNH6ouJo6oRzFTfVe4DdSHWlVd04+Krt0tKOl4Q= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A7BFC3858D35 Received: from localhost (localhost [127.0.0.1]) by sonata.ens-lyon.org (Postfix) with ESMTP id A86C2A1E47; Sat, 15 Mar 2025 22:40:12 +0100 (CET) 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 akNdXGoEY9p8; Sat, 15 Mar 2025 22:40:12 +0100 (CET) Received: from begin.home (aamiens-653-1-40-48.w83-192.abo.wanadoo.fr [83.192.199.48]) (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 8B453A1DE1; Sat, 15 Mar 2025 22:40:12 +0100 (CET) Received: from samy by begin.home with local (Exim 4.98) (envelope-from ) id 1ttZEp-0000000GNs8-47sI; Sat, 15 Mar 2025 22:40:11 +0100 From: Samuel Thibault To: libc-alpha@sourceware.org Cc: Samuel Thibault , commit-hurd@gnu.org Subject: [hurd, commited] htl: Make pthread_setcanceltype / state a cancellation point Date: Sat, 15 Mar 2025 22:40:09 +0100 Message-ID: <20250315214009.3905005-1-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.47.2 MIME-Version: 1.0 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP, T_FILL_THIS_FORM_SHORT 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.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org as expected by tst-cancel32. --- htl/pt-setcancelstate.c | 8 ++++++++ htl/pt-setcanceltype.c | 5 +++++ sysdeps/htl/pthreadP.h | 8 ++++++++ 3 files changed, 21 insertions(+) diff --git a/htl/pt-setcancelstate.c b/htl/pt-setcancelstate.c index 6e09c260ea..0d5692e661 100644 --- a/htl/pt-setcancelstate.c +++ b/htl/pt-setcancelstate.c @@ -24,6 +24,7 @@ int __pthread_setcancelstate (int state, int *oldstate) { struct __pthread *p = _pthread_self (); + int cancelled; switch (state) { @@ -38,8 +39,15 @@ __pthread_setcancelstate (int state, int *oldstate) if (oldstate != NULL) *oldstate = p->cancel_state; p->cancel_state = state; + cancelled = (p->cancel_state == PTHREAD_CANCEL_ENABLE) && p->cancel_pending == 1 && (p->cancel_type == PTHREAD_CANCEL_ASYNCHRONOUS); + if (cancelled) + /* Do not achieve cancel when called again, notably from __pthread_exit itself. */ + p->cancel_pending = 2; __pthread_mutex_unlock (&p->cancel_lock); + if (cancelled && __pthread_exit) + __pthread_exit (PTHREAD_CANCELED); + return 0; } libc_hidden_def (__pthread_setcancelstate) diff --git a/htl/pt-setcanceltype.c b/htl/pt-setcanceltype.c index 0b76fbfbd6..b33931c468 100644 --- a/htl/pt-setcanceltype.c +++ b/htl/pt-setcanceltype.c @@ -24,6 +24,7 @@ int __pthread_setcanceltype (int type, int *oldtype) { struct __pthread *p = _pthread_self (); + int cancelled; switch (type) { @@ -38,8 +39,12 @@ __pthread_setcanceltype (int type, int *oldtype) if (oldtype != NULL) *oldtype = p->cancel_type; p->cancel_type = type; + cancelled = (p->cancel_state == PTHREAD_CANCEL_ENABLE) && p->cancel_pending && (p->cancel_type == PTHREAD_CANCEL_ASYNCHRONOUS); __pthread_mutex_unlock (&p->cancel_lock); + if (cancelled && __pthread_exit) + __pthread_exit (PTHREAD_CANCELED); + return 0; } libc_hidden_def (__pthread_setcanceltype) diff --git a/sysdeps/htl/pthreadP.h b/sysdeps/htl/pthreadP.h index 9479b9ef24..78ef4e7674 100644 --- a/sysdeps/htl/pthreadP.h +++ b/sysdeps/htl/pthreadP.h @@ -221,6 +221,14 @@ hidden_proto (__pthread_setspecific) hidden_proto (__pthread_get_cleanup_stack) #endif +#if !defined(__NO_WEAK_PTHREAD_ALIASES) && !IS_IN (libpthread) +# ifdef weak_extern +weak_extern (__pthread_exit) +# else +# pragma weak __pthread_exit +# endif +#endif + #define ASSERT_TYPE_SIZE(type, size) \ _Static_assert (sizeof (type) == size, \ "sizeof (" #type ") != " #size)