From patchwork Sat Mar 14 23:05:52 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 131749 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 566294C900C8 for ; Sat, 14 Mar 2026 23:06:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 566294C900C8 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 C56374BAE7C6 for ; Sat, 14 Mar 2026 23:05:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C56374BAE7C6 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 C56374BAE7C6 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=1773529556; cv=none; b=CNTdoZT7cOcvmOHvv5HVApDaWPVftrOJOBbx1uipd1+XUwWmfz1HbsAT0wFL+xsEUzbAxi1t/NiiIhYO22IGFWPamQCxf+keBbP6spzNI1itCEhASwCTvvpDkLkkkwl5bwmLapk5DVmGjJ/I71l7cxddLZLdWWPoKpnM6Nybl68= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1773529556; c=relaxed/simple; bh=LxFqAQQAHauXB/tkGfc7lps9tWQDC5U/VCp1OyhiAvU=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=jh1I5ixeNg60QO55eTmOKwM0qxkNct+pUAna9fOEeooXIxfbekJYsGmk1cuAots34E/OAVCczzNGi4eRCIz5CcEluJqkkcUD2Cb/vD0cBjFQ/enA1wg2BqqO/F1/xwcYBWJkWNFJbXPJy1NwAeJCST6FoylBPJaSBCz2dkQ72SU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C56374BAE7C6 Received: from localhost (localhost [127.0.0.1]) by sonata.ens-lyon.org (Postfix) with ESMTP id A426EA1AE6; Sun, 15 Mar 2026 00:05:55 +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 GUK2zC9cpE4E; Sun, 15 Mar 2026 00:05:55 +0100 (CET) Received: from end (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 2D9E1A19CF; Sun, 15 Mar 2026 00:05:54 +0100 (CET) Received: from samy by end with local (Exim 4.99.1) (envelope-from ) id 1w1Y3N-0000000Gbee-3Yaa; Sun, 15 Mar 2026 00:05:53 +0100 From: Samuel Thibault To: libc-alpha@sourceware.org Cc: Samuel Thibault , commit-hurd@gnu.org Subject: [hurd,commited 1/2] mach: Add __mach_rwlock_* Date: Sun, 15 Mar 2026 00:05:52 +0100 Message-ID: <20260314230553.3957622-2-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260314230553.3957622-1-samuel.thibault@ens-lyon.org> References: <20260314230553.3957622-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, 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 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 We cannot use pthread_rwlock for these until we have reimplemented pthread_rwlock with gsync, so fork __libc_rwlock off for now. --- htl/pt-alloc.c | 18 +++++++++--------- htl/pt-create.c | 4 ++-- htl/pt-internal.h | 8 ++++---- sysdeps/generic/ldsodefs.h | 2 +- sysdeps/htl/dl-support.c | 2 +- sysdeps/htl/dl-thread_gscope_wait.c | 4 ++-- sysdeps/htl/pt-key-delete.c | 4 ++-- sysdeps/mach/hurd/getrandom.c | 14 +++++++------- sysdeps/mach/libc-lock.h | 12 +++++++++++- 9 files changed, 39 insertions(+), 29 deletions(-) diff --git a/htl/pt-alloc.c b/htl/pt-alloc.c index 257f7250d8..53833d3f20 100644 --- a/htl/pt-alloc.c +++ b/htl/pt-alloc.c @@ -125,7 +125,7 @@ __pthread_alloc (struct __pthread **pthread) } retry: - __libc_rwlock_wrlock (GL (dl_pthread_threads_lock)); + __mach_rwlock_wrlock (GL (dl_pthread_threads_lock)); if (GL (dl_pthread_num_threads) < __pthread_max_threads) { @@ -134,7 +134,7 @@ retry: new->thread = 1 + GL (dl_pthread_num_threads)++; GL (dl_pthread_threads)[new->thread - 1] = NULL; - __libc_rwlock_unlock (GL (dl_pthread_threads_lock)); + __mach_rwlock_unlock (GL (dl_pthread_threads_lock)); *pthread = new; return 0; @@ -143,7 +143,7 @@ retry: else if (GL (dl_pthread_num_threads) >= PTHREAD_THREADS_MAX) { /* We have reached the limit on the number of threads per process. */ - __libc_rwlock_unlock (GL (dl_pthread_threads_lock)); + __mach_rwlock_unlock (GL (dl_pthread_threads_lock)); free (new); return EAGAIN; @@ -155,7 +155,7 @@ retry: memory allocation, since that's a potentially blocking operation. */ max_threads = __pthread_max_threads; - __libc_rwlock_unlock (GL (dl_pthread_threads_lock)); + __mach_rwlock_unlock (GL (dl_pthread_threads_lock)); /* Allocate a new lookup table that's twice as large. */ new_max_threads @@ -167,13 +167,13 @@ retry: return ENOMEM; } - __libc_rwlock_wrlock (GL (dl_pthread_threads_lock)); + __mach_rwlock_wrlock (GL (dl_pthread_threads_lock)); /* Check if nobody else has already enlarged the table. */ if (max_threads != __pthread_max_threads) { /* Yep, they did. */ - __libc_rwlock_unlock (GL (dl_pthread_threads_lock)); + __mach_rwlock_unlock (GL (dl_pthread_threads_lock)); /* Free the newly allocated table and try again to allocate a slot. */ free (threads); @@ -196,7 +196,7 @@ retry: new->thread = 1 + GL (dl_pthread_num_threads)++; GL (dl_pthread_threads)[new->thread - 1] = NULL; - __libc_rwlock_unlock (GL (dl_pthread_threads_lock)); + __mach_rwlock_unlock (GL (dl_pthread_threads_lock)); free (old_threads); @@ -211,7 +211,7 @@ __pthread_init_static_tls (struct link_map *map) { int i; - __libc_rwlock_wrlock (GL (dl_pthread_threads_lock)); + __mach_rwlock_wrlock (GL (dl_pthread_threads_lock)); for (i = 0; i < GL (dl_pthread_num_threads); ++i) { struct __pthread *t = GL (dl_pthread_threads)[i]; @@ -231,6 +231,6 @@ __pthread_init_static_tls (struct link_map *map) memset (__mempcpy (dest, map->l_tls_initimage, map->l_tls_initimage_size), '\0', map->l_tls_blocksize - map->l_tls_initimage_size); } - __libc_rwlock_unlock (GL (dl_pthread_threads_lock)); + __mach_rwlock_unlock (GL (dl_pthread_threads_lock)); } libc_hidden_def (__pthread_init_static_tls) diff --git a/htl/pt-create.c b/htl/pt-create.c index 2a43285372..a66b6ebdcf 100644 --- a/htl/pt-create.c +++ b/htl/pt-create.c @@ -240,9 +240,9 @@ __pthread_create_internal (struct __pthread **thread, could use __thread_setid, however, we only lock for reading as no other thread should be using this entry (we also assume that the store is atomic). */ - __libc_rwlock_rdlock (GL (dl_pthread_threads_lock)); + __mach_rwlock_rdlock (GL (dl_pthread_threads_lock)); GL (dl_pthread_threads)[pthread->thread - 1] = pthread; - __libc_rwlock_unlock (GL (dl_pthread_threads_lock)); + __mach_rwlock_unlock (GL (dl_pthread_threads_lock)); /* At this point it is possible to guess our pthread ID. We have to make sure that all functions taking a pthread_t argument can diff --git a/htl/pt-internal.h b/htl/pt-internal.h index 5a3104830c..e662a8d951 100644 --- a/htl/pt-internal.h +++ b/htl/pt-internal.h @@ -178,16 +178,16 @@ libc_hidden_proto (__pthread_max_threads) #define __pthread_getid(thread) \ ({ struct __pthread *__t = NULL; \ - __libc_rwlock_rdlock (GL (dl_pthread_threads_lock)); \ + __mach_rwlock_rdlock (GL (dl_pthread_threads_lock)); \ if (thread <= __pthread_max_threads) \ __t = GL (dl_pthread_threads)[thread - 1]; \ - __libc_rwlock_unlock (GL (dl_pthread_threads_lock)); \ + __mach_rwlock_unlock (GL (dl_pthread_threads_lock)); \ __t; }) #define __pthread_setid(thread, pthread) \ - __libc_rwlock_wrlock (GL (dl_pthread_threads_lock)); \ + __mach_rwlock_wrlock (GL (dl_pthread_threads_lock)); \ GL (dl_pthread_threads)[thread - 1] = pthread; \ - __libc_rwlock_unlock (GL (dl_pthread_threads_lock)); + __mach_rwlock_unlock (GL (dl_pthread_threads_lock)); /* Similar to pthread_self, but returns the thread descriptor instead of the thread ID. */ diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h index 76afc5df7d..46a7119b3a 100644 --- a/sysdeps/generic/ldsodefs.h +++ b/sysdeps/generic/ldsodefs.h @@ -478,7 +478,7 @@ struct rtld_global /* Array of __pthread structures and its lock. */ EXTERN struct __pthread **_dl_pthread_threads; - __libc_rwlock_define (EXTERN, _dl_pthread_threads_lock) + __mach_rwlock_define (EXTERN, _dl_pthread_threads_lock) #endif #ifdef SHARED }; diff --git a/sysdeps/htl/dl-support.c b/sysdeps/htl/dl-support.c index 0c1edf2bbd..5b07a8f67b 100644 --- a/sysdeps/htl/dl-support.c +++ b/sysdeps/htl/dl-support.c @@ -20,4 +20,4 @@ int _dl_pthread_num_threads; struct __pthread **_dl_pthread_threads; -__libc_rwlock_define_initialized (, _dl_pthread_threads_lock) +__mach_rwlock_define_initialized (, _dl_pthread_threads_lock) diff --git a/sysdeps/htl/dl-thread_gscope_wait.c b/sysdeps/htl/dl-thread_gscope_wait.c index 095618eac1..d8428d4491 100644 --- a/sysdeps/htl/dl-thread_gscope_wait.c +++ b/sysdeps/htl/dl-thread_gscope_wait.c @@ -39,7 +39,7 @@ __thread_gscope_wait (void) struct __pthread *t; int *gscope_flagp; - __libc_rwlock_rdlock (GL (dl_pthread_threads_lock)); + __mach_rwlock_rdlock (GL (dl_pthread_threads_lock)); /* Iterate over the list of threads. */ for (i = 0; i < GL (dl_pthread_num_threads); ++i) @@ -63,5 +63,5 @@ __thread_gscope_wait (void) while (*gscope_flagp == THREAD_GSCOPE_FLAG_WAIT); } - __libc_rwlock_unlock (GL (dl_pthread_threads_lock)); + __mach_rwlock_unlock (GL (dl_pthread_threads_lock)); } diff --git a/sysdeps/htl/pt-key-delete.c b/sysdeps/htl/pt-key-delete.c index 018a021ee1..88f5e33b01 100644 --- a/sysdeps/htl/pt-key-delete.c +++ b/sysdeps/htl/pt-key-delete.c @@ -41,7 +41,7 @@ __pthread_key_delete (pthread_key_t key) __pthread_key_destructors[key] = PTHREAD_KEY_INVALID; __pthread_key_invalid_count++; - __libc_rwlock_rdlock (GL (dl_pthread_threads_lock)); + __mach_rwlock_rdlock (GL (dl_pthread_threads_lock)); for (i = 0; i < GL (dl_pthread_num_threads); ++i) { struct __pthread *t; @@ -64,7 +64,7 @@ __pthread_key_delete (pthread_key_t key) t->thread_specifics[key] = 0; } } - __libc_rwlock_unlock (GL (dl_pthread_threads_lock)); + __mach_rwlock_unlock (GL (dl_pthread_threads_lock)); } __pthread_mutex_unlock (&__pthread_key_lock); diff --git a/sysdeps/mach/hurd/getrandom.c b/sysdeps/mach/hurd/getrandom.c index 6647a0f778..a3fde4dc59 100644 --- a/sysdeps/mach/hurd/getrandom.c +++ b/sysdeps/mach/hurd/getrandom.c @@ -20,7 +20,7 @@ #include #include -__libc_rwlock_define_initialized (static, lock); +__mach_rwlock_define_initialized (static, lock); static file_t random_server, random_server_nonblock, urandom_server, urandom_server_nonblock; @@ -75,14 +75,14 @@ __getrandom (void *buffer, size_t length, unsigned int flags) return length; again: - __libc_rwlock_rdlock (lock); + __mach_rwlock_rdlock (lock); server = *cached_server; if (MACH_PORT_VALID (server)) /* Attempt to read some random data using this port. */ err = __io_read (server, &data, &nread, -1, length); else err = MACH_SEND_INVALID_DEST; - __libc_rwlock_unlock (lock); + __mach_rwlock_unlock (lock); if (err == MACH_SEND_INVALID_DEST || err == MIG_SERVER_DIED) { @@ -92,13 +92,13 @@ again: /* Slow path: the cached port didn't work, or there was no cached port in the first place. */ - __libc_rwlock_wrlock (lock); + __mach_rwlock_wrlock (lock); server = *cached_server; if (server != oldserver) { /* Someone else must have refetched the port while we were waiting for the lock. */ - __libc_rwlock_unlock (lock); + __mach_rwlock_unlock (lock); goto again; } @@ -111,7 +111,7 @@ again: MACH_PORT_RIGHT_SEND, &urefs); if (!err && urefs > 0) { - __libc_rwlock_unlock (lock); + __mach_rwlock_unlock (lock); goto again; } @@ -121,7 +121,7 @@ again: server = *cached_server = __file_name_lookup (random_source, open_flags, 0); - __libc_rwlock_unlock (lock); + __mach_rwlock_unlock (lock); if (!MACH_PORT_VALID (server)) { if (errno == ENOENT) diff --git a/sysdeps/mach/libc-lock.h b/sysdeps/mach/libc-lock.h index 236a24ad80..ddeae544f4 100644 --- a/sysdeps/mach/libc-lock.h +++ b/sysdeps/mach/libc-lock.h @@ -145,7 +145,17 @@ typedef struct __libc_lock_recursive_opaque__ __libc_lock_recursive_t; #define __rtld_lock_unlock_recursive(NAME) \ __libc_lock_unlock_recursive (NAME) -/* XXX for now */ +/* XXX for now, waiting for a futex-based pthread_rwlock implementation */ +#define __mach_rwlock_define __libc_lock_define +#define __mach_rwlock_define_initialized __libc_lock_define_initialized +#define __mach_rwlock_init __libc_lock_init +#define __mach_rwlock_fini __libc_lock_fini +#define __mach_rwlock_rdlock __libc_lock_lock +#define __mach_rwlock_wrlock __libc_lock_lock +#define __mach_rwlock_tryrdlock __libc_lock_trylock +#define __mach_rwlock_trywrlock __libc_lock_trylock +#define __mach_rwlock_unlock __libc_lock_unlock + #define __libc_rwlock_define __libc_lock_define #define __libc_rwlock_define_initialized __libc_lock_define_initialized #define __libc_rwlock_init __libc_lock_init