From nobody Wed May 07 19:22:08 2025 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Zt4rw6ncJz5v9C0; Wed, 07 May 2025 19:22:08 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Zt4rw4q0gz49dt; Wed, 07 May 2025 19:22:08 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1746645728; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=mtrN1v+XUJieQgWjava2Jdq8r8v3NbEc/vcdSHkgUsg=; b=qX+es0hX9kFWBbLlUKPKpYIppRF1kFTTfgSM0B5hEXhsUwe8EjUo5Rf1qPGBkiC1jkC/6/ HXckI87U1/0zwn6u0NlvKMZLlye7qR/rv34ITxXexopq2hgElQz0ZWRrdwWDhEiNdQclof Yqow09eGBHIl6bbwc29zk4KXIK6Pgy/a8SAg1p6Y2w/jBOG61Tw6aPv4XMYaBnbHb+dThW y8tz5ri4x26ZQsZ5k2hxsVK+dpLA5ISqS+xh2nCz/CQGiEbuvh0wQ9+tSHQq6P+DthHhr9 NGKe5kJCORRQTLS4c8W31eykXg7gel01ogfITiVluFAWChPlr85kr5mjzIjJ0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1746645728; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=mtrN1v+XUJieQgWjava2Jdq8r8v3NbEc/vcdSHkgUsg=; b=ymCs9cINelYMmdjdInLN/kGPIS76opjzMf8KL2uHZfjLZV0pib4MUKUyrRW83VaAOOS421 MP/a1H9Bcsa3jHoe6Ae2w0Ht8MePP4VNNck6Xzoh8XIYC6TfnVI6qVXLuShPU4K2GVpFzj 14+l6xL3yAoUuljQoOuMb/vdN0dF6JFhBerF0oPcxabuVBs3WV0bvzGIIQnvPihM2/L5cJ 3B/mL5sVN5+ukwjXBbafLdFzvEKKTzgSFb3tBjdHKFQ1rNtW/jtA1jRbiHjG8R1dI28OKD r90r9AkXTt62t0SIOVJuv4h+xc0VmUB6afxfE57lqOyTk/sKX7D1VxRahB48Qg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1746645728; a=rsa-sha256; cv=none; b=uGeyTwxdJFlZDcCnkLtYgu2uPV/R/zpnCZ88mbWPQYtN6mbgr2wAk4ALZ1wT0Zs0oLB+c/ EA+RNLgzkm5zKz+1vf/5Io/N1eVmrCwKtKaPbzNo4ORhJPyp4cJMYCOGaIQ6Utc5a76pix he+ZKXcQuGQW1thCspui8YPsPBfAsLpJcmDedLEMN1CDeda4d01bGS3h9DrQrpss4CZjYS wB3sFvA48YAmnoL25EYE8e9uLKL8p2R1FJNwWcpzriDxoUHeNarwGfa+BagNwVhwdGf/bL VD8TwMZ2qB32Id1Vn70FufWEGqRNknL9/NE0xkBFia7Dpc9dJ8QHdgrYdXX8vQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Zt4rw4QqXzj9J; Wed, 07 May 2025 19:22:08 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 547JM8NY043026; Wed, 7 May 2025 19:22:08 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 547JM8Zr043023; Wed, 7 May 2025 19:22:08 GMT (envelope-from git) Date: Wed, 7 May 2025 19:22:08 GMT Message-Id: <202505071922.547JM8Zr043023@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Jessica Clarke Subject: git: 62dfddd083da - main - libc: Use variables more consistent with Variant I for Variant II TLS List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jrtc27 X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 62dfddd083dab8ed1b2d9dd390fa27d37d132416 Auto-Submitted: auto-generated The branch main has been updated by jrtc27: URL: https://cgit.FreeBSD.org/src/commit/?id=62dfddd083dab8ed1b2d9dd390fa27d37d132416 commit 62dfddd083dab8ed1b2d9dd390fa27d37d132416 Author: Jessica Clarke AuthorDate: 2025-05-07 19:20:00 +0000 Commit: Jessica Clarke CommitDate: 2025-05-07 19:20:00 +0000 libc: Use variables more consistent with Variant I for Variant II TLS Firstly, the first argument to __libc_allocate_tls is the old TCB (versus oldtls, which has less of a clear meaning), so rename it to oldtcb like Variant I. Secondly, segbase and oldsegbase are oriented towards what ends up in the segment registers, but that's not the main concern here, and those don't convey what they actually point to. Instead, rename segbase to tcb and change it to a uintptr_t **, and remove oldsegbase as it's always equal to oldtcb, again both matching Variant I. Finally, rename tls to tls_block, and add back a (different) tls variable rather than constantly recomputing tcb - libc_tls_static_space, again both matching Variant I. Whilst here, similarly fix the oldtls argument to be oldtcb in the PIC __libc_allocate_tls stub. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D50227 --- lib/libc/gen/tls.c | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/lib/libc/gen/tls.c b/lib/libc/gen/tls.c index ad6f43eb3534..9772c99833d5 100644 --- a/lib/libc/gen/tls.c +++ b/lib/libc/gen/tls.c @@ -323,62 +323,58 @@ __libc_free_tls(void *tcb, size_t tcbsize __unused, size_t tcbalign) * Allocate Static TLS using the Variant II method. */ void * -__libc_allocate_tls(void *oldtls, size_t tcbsize, size_t tcbalign) +__libc_allocate_tls(void *oldtcb, size_t tcbsize, size_t tcbalign) { size_t size; - char *tls; - uintptr_t *dtv; - uintptr_t segbase, oldsegbase; + char *tls_block, *tls; + uintptr_t *dtv, **tcb; tcbalign = MAX(tcbalign, libc_tls_init_align); size = roundup2(libc_tls_static_space, tcbalign); if (tcbsize < 2 * sizeof(uintptr_t)) tcbsize = 2 * sizeof(uintptr_t); - tls = libc_malloc_aligned(size + tcbsize, tcbalign); - if (tls == NULL) { + tls_block = libc_malloc_aligned(size + tcbsize, tcbalign); + if (tls_block == NULL) { tls_msg("__libc_allocate_tls: Out of memory.\n"); abort(); } - memset(tls, 0, size + tcbsize); + memset(tls_block, 0, size + tcbsize); dtv = __je_bootstrap_malloc(3 * sizeof(uintptr_t)); if (dtv == NULL) { tls_msg("__libc_allocate_tls: Out of memory.\n"); abort(); } - segbase = (uintptr_t)(tls + size); - ((uintptr_t *)segbase)[0] = segbase; - ((uintptr_t *)segbase)[1] = (uintptr_t)dtv; + tcb = (uintptr_t **)(tls_block + size); + tls = (char *)tcb - libc_tls_static_space; + tcb[0] = (uintptr_t *)tcb; + tcb[1] = dtv; dtv[0] = 1; dtv[1] = 1; - dtv[2] = segbase - libc_tls_static_space; + dtv[2] = (uintptr_t)tls; - if (oldtls) { + if (oldtcb != NULL) { /* * Copy the static TLS block over whole. */ - oldsegbase = (uintptr_t)oldtls; - memcpy((void *)(segbase - libc_tls_static_space), - (const void *)(oldsegbase - libc_tls_static_space), + memcpy(tls, (const char *)oldtcb - libc_tls_static_space, libc_tls_static_space); /* * We assume that this block was the one we created with * allocate_initial_tls(). */ - _rtld_free_tls(oldtls, 2 * sizeof(uintptr_t), + _rtld_free_tls(oldtcb, 2 * sizeof(uintptr_t), sizeof(uintptr_t)); } else { - memcpy((void *)(segbase - libc_tls_static_space), - libc_tls_init, libc_tls_init_size); - memset((void *)(segbase - libc_tls_static_space + - libc_tls_init_size), 0, + memcpy(tls, libc_tls_init, libc_tls_init_size); + memset(tls + libc_tls_init_size, 0, libc_tls_static_space - libc_tls_init_size); } - return (void*) segbase; + return (tcb); } #endif /* TLS_VARIANT_II */ @@ -386,7 +382,7 @@ __libc_allocate_tls(void *oldtls, size_t tcbsize, size_t tcbalign) #else void * -__libc_allocate_tls(void *oldtls __unused, size_t tcbsize __unused, +__libc_allocate_tls(void *oldtcb __unused, size_t tcbsize __unused, size_t tcbalign __unused) { return (0);