From patchwork Fri May 19 14:47:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Bugaev X-Patchwork-Id: 69687 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 6F5773858C00 for ; Fri, 19 May 2023 14:47:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6F5773858C00 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1684507673; bh=3YNNbdC1ln5iP1GYUsOHMk1cREGOTVxSxd2gWOAKvrI=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=IL88idmYx4GgdQTOFlNBBcm8OAm+AXrTWctH2ADLcf/oMGYKdghkdnYj7XqTWkzEd HM/SoZolsx6FGIjHiH5T+g23csvaLYMYV7yl0bTSjfJdMHLTMmIe2Aqhh9IE4DtM44 uzu6WkJF6e8AdTdV8PR3/+GlyJy9eCQrQVdT47co= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) by sourceware.org (Postfix) with ESMTPS id 0A9F83858C41 for ; Fri, 19 May 2023 14:47:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0A9F83858C41 Received: by mail-lj1-x229.google.com with SMTP id 38308e7fff4ca-2af225e5b4bso11746221fa.3 for ; Fri, 19 May 2023 07:47:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684507647; x=1687099647; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3YNNbdC1ln5iP1GYUsOHMk1cREGOTVxSxd2gWOAKvrI=; b=aEX/iVX90qTzlzjku0vH1ZMa/Ufsi20tT5VF3ivt3LwOoAFvH0W6FLLti9K5e1JqU9 XlZCzXuBe3eaqLES/zI3RZO1TqdaOW+rvpgMmoyxMKjXZSv+A40jPYbEVY1fVGWe3jqI BtP7M+KG5+SB8MUXuy7uMRvWI6XwoW6wnNQub9YwDXEgLI8CKog/Re5CRD+vMEv5J4Qu bqZbN2DlRU9l55AFZ/gBxaDO7Bbg0ZWoFruSPSJKyiWISCzforT0NcZbpaDB3kFdnnRC Tk65Hwuq8zQRVleoZVGU5RHhmU0sgPZkWorpIIBQGetD+kFIU6+wSqrioJctE0kVAz0F YvyA== X-Gm-Message-State: AC+VfDyfBnIp0XbwNhQ61HxrlMnrflkT4CPLearaGV907whqeWBvdqgV rky+uBLdnRMIhxKZ6Rh7glwyGd3kOY4= X-Google-Smtp-Source: ACHHUZ6opuJfKpAIdg37BP+8vQ4L7lIeDD95nWvEARCLUSTB23MyJ0Zy7riFqukXQTmCZY5eOgEikA== X-Received: by 2002:a05:651c:22e:b0:2a7:8b35:8270 with SMTP id z14-20020a05651c022e00b002a78b358270mr850885ljn.35.1684507646889; Fri, 19 May 2023 07:47:26 -0700 (PDT) Received: from surface-pro-6.. ([194.190.106.50]) by smtp.gmail.com with ESMTPSA id u6-20020a2e9f06000000b002a774fb7923sm860960ljk.45.2023.05.19.07.47.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 May 2023 07:47:26 -0700 (PDT) To: libc-alpha@sourceware.org, bug-hurd@gnu.org Cc: Samuel Thibault , Joseph Myers Subject: [PATCH] hurd: Fix using interposable hurd_thread_self Date: Fri, 19 May 2023 17:47:24 +0300 Message-Id: <20230519144724.334179-1-bugaevc@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <33736439-2470-fe8e-d22f-5f6c444d2817@codesourcery.com> References: <33736439-2470-fe8e-d22f-5f6c444d2817@codesourcery.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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: , X-Patchwork-Original-From: Sergey Bugaev via Libc-alpha From: Sergey Bugaev Reply-To: Sergey Bugaev Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Create a private hidden __hurd_thread_self alias, and use that one. Fixes 2f8ecb58a59eb82c43214d000842d99644a662d1 "hurd: Fix x86_64 _hurd_tls_fork" and c7fcce38c83a2bb665ef5dc4981bf20c7e586123 "hurd: Make sure to not use tcb->self" Reported-by: Joseph Myers Signed-off-by: Sergey Bugaev --- This should hopefully fix it (but please test!); I have only checked that it builds on x86_64-gnu, and that _Fork now calls __GI___hurd_thread_self without the PLT, and that libpthread.so only references __hurd_thread_self@GLIBC_PRIVATE. hurd/Versions | 1 + hurd/thread-self.c | 5 ++++- sysdeps/hurd/include/hurd.h | 3 +++ sysdeps/mach/hurd/i386/htl/pt-setup.c | 2 +- sysdeps/mach/hurd/x86_64/htl/pt-setup.c | 2 +- sysdeps/mach/hurd/x86_64/tls.h | 7 +++++-- 6 files changed, 15 insertions(+), 5 deletions(-) diff --git a/hurd/Versions b/hurd/Versions index 3d8b412d..439e8abf 100644 --- a/hurd/Versions +++ b/hurd/Versions @@ -156,6 +156,7 @@ libc { __libc_open; __libc_close; # Used by libpthread. + __hurd_thread_self; _hurd_sigstate_set_global_rcv; _hurd_sigstate_lock; _hurd_sigstate_pending; diff --git a/hurd/thread-self.c b/hurd/thread-self.c index f3718165..af013503 100644 --- a/hurd/thread-self.c +++ b/hurd/thread-self.c @@ -19,7 +19,10 @@ #include thread_t -hurd_thread_self (void) +__hurd_thread_self (void) { return _hurd_self_sigstate ()->thread; } + +libc_hidden_def (__hurd_thread_self) +weak_alias (__hurd_thread_self, hurd_thread_self) diff --git a/sysdeps/hurd/include/hurd.h b/sysdeps/hurd/include/hurd.h index 7da9af26..5d904e0e 100644 --- a/sysdeps/hurd/include/hurd.h +++ b/sysdeps/hurd/include/hurd.h @@ -11,5 +11,8 @@ void _hurd_libc_proc_init (char **argv); libc_hidden_proto (_hurd_exec_paths) libc_hidden_proto (_hurd_init) libc_hidden_proto (_hurd_libc_proc_init) + +extern thread_t __hurd_thread_self (void); +libc_hidden_proto (__hurd_thread_self) #endif #endif diff --git a/sysdeps/mach/hurd/i386/htl/pt-setup.c b/sysdeps/mach/hurd/i386/htl/pt-setup.c index ba108b96..27e5c98b 100644 --- a/sysdeps/mach/hurd/i386/htl/pt-setup.c +++ b/sysdeps/mach/hurd/i386/htl/pt-setup.c @@ -79,7 +79,7 @@ __pthread_setup (struct __pthread *thread, { error_t err; - if (thread->kernel_thread == hurd_thread_self ()) + if (thread->kernel_thread == __hurd_thread_self ()) /* Fix up the TCB for the main thread. The C library has already installed a TCB, which we want to keep using. This TCB must not be freed so don't register it in the thread structure. On the diff --git a/sysdeps/mach/hurd/x86_64/htl/pt-setup.c b/sysdeps/mach/hurd/x86_64/htl/pt-setup.c index 7dc62912..8eebaf97 100644 --- a/sysdeps/mach/hurd/x86_64/htl/pt-setup.c +++ b/sysdeps/mach/hurd/x86_64/htl/pt-setup.c @@ -56,7 +56,7 @@ __pthread_setup (struct __pthread *thread, struct i386_thread_state state; struct i386_fsgs_base_state fsgs_state; - if (thread->kernel_thread == hurd_thread_self ()) + if (thread->kernel_thread == __hurd_thread_self ()) /* Fix up the TCB for the main thread. The C library has already installed a TCB, which we want to keep using. This TCB must not be freed so don't register it in the thread structure. On the diff --git a/sysdeps/mach/hurd/x86_64/tls.h b/sysdeps/mach/hurd/x86_64/tls.h index 468f703f..a5a49a47 100644 --- a/sysdeps/mach/hurd/x86_64/tls.h +++ b/sysdeps/mach/hurd/x86_64/tls.h @@ -132,6 +132,10 @@ THREAD_TCB (thread_t thread, ((descr)->pointer_guard \ = THREAD_GETMEM (THREAD_SELF, pointer_guard)) +/* From hurd.h, reproduced here to avoid a circular include. */ +extern thread_t __hurd_thread_self (void); +libc_hidden_proto (__hurd_thread_self) + /* Set up TLS in the new thread of a fork child, copying from the original. */ static inline kern_return_t __attribute__ ((unused)) _hurd_tls_fork (thread_t child, thread_t orig, @@ -141,8 +145,7 @@ _hurd_tls_fork (thread_t child, thread_t orig, struct i386_fsgs_base_state state; mach_msg_type_number_t state_count = i386_FSGS_BASE_STATE_COUNT; - extern thread_t hurd_thread_self (void); - if (orig != hurd_thread_self ()) + if (orig != __hurd_thread_self ()) { err = __thread_get_state (orig, i386_FSGS_BASE_STATE, (thread_state_t) &state,