From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by sourceware.org (Postfix) with ESMTPS id CB2033851141 for ; Sun, 19 Mar 2023 15:11:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CB2033851141 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lf1-x130.google.com with SMTP id q16so1179204lfe.10 for ; Sun, 19 Mar 2023 08:11:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679238681; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2l1QBzJBEUQDTi5+VQORDYoRpQuSG+WDFSBo+XhNFDo=; b=ZjH+sF18YMxWmjlKPaRetaseezrG7yFL608KJt3npSwS2lcju8ed5jMXy7hFlWNOtx /0mg7rvnNqpbcVMC/xMJn2YKihK/89hO9B/6tfVl4c+A6fNqoghDUVpltQD8/uPfmfJA t2QhQpsui4kFaiaIxRB6vVi71RdhuruWedcJ1Em071o/KiydUzCozyVPjWvcP6O0r9Ss 5/XJ7ocuwsagoit7U7HiCHvMrKJS+RUmfjS+hKth5REpImqEZ+6y7pa0wGI4z2UB6Asj Zhp7DLg06w+M5DFs2/aDygFNy6X2A018NpemPzdMMrZLiINFwv9hSzCl3hIYZecq3haj rzwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679238681; 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=2l1QBzJBEUQDTi5+VQORDYoRpQuSG+WDFSBo+XhNFDo=; b=vwAt/eZDXxgboZpAOqWJQS2lsh9xrC7RV7QQ6tLjsQUVokfo0h0lvBVaq4PsMb/+hj 8WbBRYIFcJ0797oAOw7k8zNGaV3idAT16g+S8OzTHehv57eAdHr0rH5jag+ft7v5xhsM MyTLwLuMrGj6ufa7wvgFgwWeUWr31SZ//n1JRhpqEHToeIVVFn+Jfrdl8c5lc+JYJGxm toigsRlOxcFDju9YXtbSvB3Ok38+6jKJ+ISYXyZ7lazPYuyH3ju9Xnt6f85k1Y+0PGeV UPnduUAPGObbbVj+A4dQhsFX6lLvN6v5AfweXEzdve7cH4LykLgjNZu+0zuJAk7pGTuv kygQ== X-Gm-Message-State: AO0yUKUbIHtJPL5x0bTVBRJdhjat4zA6VyTZdAyMRuQ4hqK6vf+OBz22 fTXovy6O3oJ7CMIuibDFH6cTKBzwrmTL+w== X-Google-Smtp-Source: AK7set9VnWjVXH6O0lcH+ZYhGgjI5nTVZDSeI1yn3p/lQyzR3BuRm8dAZ+ofyO/VWgtQ4e6FIiU/kg== X-Received: by 2002:ac2:4145:0:b0:4b5:2cf4:cc1d with SMTP id c5-20020ac24145000000b004b52cf4cc1dmr5636325lfi.68.1679238681210; Sun, 19 Mar 2023 08:11:21 -0700 (PDT) Received: from surface-pro-6.. ([2a00:1370:818c:4a57:577a:76f4:df43:5e66]) by smtp.gmail.com with ESMTPSA id m19-20020ac24253000000b004e90dee5469sm1274089lfl.157.2023.03.19.08.11.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Mar 2023 08:11:20 -0700 (PDT) From: Sergey Bugaev To: libc-alpha@sourceware.org, bug-hurd@gnu.org Cc: Samuel Thibault , Sergey Bugaev Subject: [RFC PATCH glibc 26/34] hurd: Remove __hurd_local_reply_port Date: Sun, 19 Mar 2023 18:10:09 +0300 Message-Id: <20230319151017.531737-27-bugaevc@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230319151017.531737-1-bugaevc@gmail.com> References: <20230319151017.531737-1-bugaevc@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.5 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 autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Now that the signal code no longer accesses it, the only real user of it was mig-reply.c, so move the logic for managing the port there. If we're in SHARED and outside of rtld, we know that __LIBC_NO_TLS () always evaluates to 0, and a TLS reply port will always be used, not __hurd_reply_port0. Still, the compiler does not see that __hurd_reply_port0 is never used due to its address being taken. To deal with this, explicitly compile out __hurd_reply_port0 when we know we won't use it. Also, instead of accessing the port via THREAD_SELF->reply_port, this uses THREAD_GETMEM and THREAD_SETMEM directly, avoiding possible miscompilations. Signed-off-by: Sergey Bugaev --- hurd/hurd/threadvar.h | 7 ------ sysdeps/mach/hurd/mig-reply.c | 43 +++++++++++++++++++++++++++-------- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/hurd/hurd/threadvar.h b/hurd/hurd/threadvar.h index f5c6a278..c476d988 100644 --- a/hurd/hurd/threadvar.h +++ b/hurd/hurd/threadvar.h @@ -29,11 +29,4 @@ extern unsigned long int __hurd_sigthread_stack_base; extern unsigned long int __hurd_sigthread_stack_end; -/* Store the MiG reply port reply port until we enable TLS. */ -extern mach_port_t __hurd_reply_port0; - -/* This returns either the TLS reply port variable, or a single-thread variable - when TLS is not initialized yet. */ -#define __hurd_local_reply_port (*(__LIBC_NO_TLS () ? &__hurd_reply_port0 : &THREAD_SELF->reply_port)) - #endif /* hurd/threadvar.h */ diff --git a/sysdeps/mach/hurd/mig-reply.c b/sysdeps/mach/hurd/mig-reply.c index 33ff260e..d3c5a958 100644 --- a/sysdeps/mach/hurd/mig-reply.c +++ b/sysdeps/mach/hurd/mig-reply.c @@ -17,32 +17,55 @@ #include #include -#include +#include /* These functions are called by MiG-generated code. */ +#if !defined (SHARED) || IS_IN (rtld) mach_port_t __hurd_reply_port0; +#endif + +static mach_port_t +get_reply_port (void) +{ +#if !defined (SHARED) || IS_IN (rtld) + if (__LIBC_NO_TLS ()) + return __hurd_reply_port0; +#endif + return THREAD_GETMEM (THREAD_SELF, reply_port); +} + +static void +set_reply_port (mach_port_t port) +{ +#if !defined (SHARED) || IS_IN (rtld) + if (__LIBC_NO_TLS ()) + __hurd_reply_port0 = port; + else +#endif + THREAD_SETMEM (THREAD_SELF, reply_port, port); +} /* Called by MiG to get a reply port. */ mach_port_t __mig_get_reply_port (void) { - if (__hurd_local_reply_port == MACH_PORT_NULL - || (&__hurd_local_reply_port != &__hurd_reply_port0 - && __hurd_local_reply_port == __hurd_reply_port0)) - __hurd_local_reply_port = __mach_reply_port (); - - return __hurd_local_reply_port; + mach_port_t port = get_reply_port (); + if (__glibc_unlikely (port == MACH_PORT_NULL)) + { + port = __mach_reply_port (); + set_reply_port (port); + } + return port; } weak_alias (__mig_get_reply_port, mig_get_reply_port) libc_hidden_def (__mig_get_reply_port) /* Called by MiG to deallocate the reply port. */ void -__mig_dealloc_reply_port (mach_port_t arg) +__mig_dealloc_reply_port (mach_port_t port) { - mach_port_t port = __hurd_local_reply_port; - __hurd_local_reply_port = MACH_PORT_NULL; /* So the mod_refs RPC won't use it. */ + set_reply_port (MACH_PORT_NULL); /* So the mod_refs RPC won't use it. */ if (MACH_PORT_VALID (port)) __mach_port_mod_refs (__mach_task_self (), port, -- 2.39.2