git: 3703f95c6fca - main - libc: Use struct tcb * rather than uintptr_t ** for the tcb
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 07 May 2025 19:22:10 UTC
The branch main has been updated by jrtc27:
URL: https://cgit.FreeBSD.org/src/commit/?id=3703f95c6fcaede56bb1d62c4ac00b933e2eb887
commit 3703f95c6fcaede56bb1d62c4ac00b933e2eb887
Author: Jessica Clarke <jrtc27@FreeBSD.org>
AuthorDate: 2025-05-07 19:20:10 +0000
Commit: Jessica Clarke <jrtc27@FreeBSD.org>
CommitDate: 2025-05-07 19:20:10 +0000
libc: Use struct tcb * rather than uintptr_t ** for the tcb
This lets us access via named struct members rather than magic
hard-coded indices.
Reviewed by: kib
Differential Revision: https://reviews.freebsd.org/D50228
---
lib/libc/gen/tls.c | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/lib/libc/gen/tls.c b/lib/libc/gen/tls.c
index 9772c99833d5..5b6970ad3905 100644
--- a/lib/libc/gen/tls.c
+++ b/lib/libc/gen/tls.c
@@ -201,10 +201,8 @@ void
__libc_free_tls(void *tcb, size_t tcbsize, size_t tcbalign __unused)
{
uintptr_t *dtv;
- uintptr_t **tls;
- tls = (uintptr_t **)tcb;
- dtv = tls[0];
+ dtv = ((struct tcb *)tcb)->tcb_dtv;
__je_bootstrap_free(dtv);
libc_free_aligned(get_tls_block_ptr(tcb, tcbsize));
}
@@ -232,7 +230,8 @@ __libc_free_tls(void *tcb, size_t tcbsize, size_t tcbalign __unused)
void *
__libc_allocate_tls(void *oldtcb, size_t tcbsize, size_t tcbalign)
{
- uintptr_t *dtv, **tcb;
+ uintptr_t *dtv;
+ struct tcb *tcb;
char *tls_block, *tls;
size_t extra_size, maxalign, post_size, pre_size, tls_block_size;
@@ -261,7 +260,7 @@ __libc_allocate_tls(void *oldtcb, size_t tcbsize, size_t tcbalign)
abort();
}
memset(tls_block, 0, tls_block_size);
- tcb = (uintptr_t **)(tls_block + pre_size + extra_size);
+ tcb = (struct tcb *)(tls_block + pre_size + extra_size);
tls = (char *)tcb + TLS_TCB_SIZE + post_size;
if (oldtcb != NULL) {
@@ -270,7 +269,7 @@ __libc_allocate_tls(void *oldtcb, size_t tcbsize, size_t tcbalign)
libc_free_aligned(oldtcb);
/* Adjust the DTV. */
- dtv = tcb[0];
+ dtv = tcb->tcb_dtv;
dtv[2] = (uintptr_t)tls;
} else {
dtv = __je_bootstrap_malloc(3 * sizeof(uintptr_t));
@@ -279,7 +278,7 @@ __libc_allocate_tls(void *oldtcb, size_t tcbsize, size_t tcbalign)
abort();
}
/* Build the DTV. */
- tcb[0] = dtv;
+ tcb->tcb_dtv = dtv;
dtv[0] = 1; /* Generation. */
dtv[1] = 1; /* Segments count. */
dtv[2] = (uintptr_t)tls;
@@ -312,7 +311,7 @@ __libc_free_tls(void *tcb, size_t tcbsize __unused, size_t tcbalign)
tcbalign = MAX(tcbalign, libc_tls_init_align);
size = roundup2(libc_tls_static_space, tcbalign);
- dtv = ((uintptr_t **)tcb)[1];
+ dtv = ((struct tcb *)tcb)->tcb_dtv;
tlsend = (uintptr_t)tcb;
tlsstart = tlsend - size;
libc_free_aligned((void*)tlsstart);
@@ -327,7 +326,8 @@ __libc_allocate_tls(void *oldtcb, size_t tcbsize, size_t tcbalign)
{
size_t size;
char *tls_block, *tls;
- uintptr_t *dtv, **tcb;
+ uintptr_t *dtv;
+ struct tcb *tcb;
tcbalign = MAX(tcbalign, libc_tls_init_align);
size = roundup2(libc_tls_static_space, tcbalign);
@@ -346,10 +346,10 @@ __libc_allocate_tls(void *oldtcb, size_t tcbsize, size_t tcbalign)
abort();
}
- tcb = (uintptr_t **)(tls_block + size);
+ tcb = (struct tcb *)(tls_block + size);
tls = (char *)tcb - libc_tls_static_space;
- tcb[0] = (uintptr_t *)tcb;
- tcb[1] = dtv;
+ tcb->tcb_self = tcb;
+ tcb->tcb_dtv = dtv;
dtv[0] = 1;
dtv[1] = 1;