git: 48fd084579af - main - rtld-elf: Pass TCB to allocate_module_tls to avoid re-getting

From: Jessica Clarke <jrtc27_at_FreeBSD.org>
Date: Thu, 29 May 2025 16:07:30 UTC
The branch main has been updated by jrtc27:

URL: https://cgit.FreeBSD.org/src/commit/?id=48fd084579af7604e934b827ef473194d3d5e3ba

commit 48fd084579af7604e934b827ef473194d3d5e3ba
Author:     Jessica Clarke <jrtc27@FreeBSD.org>
AuthorDate: 2025-05-29 16:07:02 +0000
Commit:     Jessica Clarke <jrtc27@FreeBSD.org>
CommitDate: 2025-05-29 16:07:02 +0000

    rtld-elf: Pass TCB to allocate_module_tls to avoid re-getting
    
    The only caller already has the current TCB to hand, so just pass it
    down rather than get it again. This also makes it clear in the caller
    that it depends on the (current) TCB, rather than being storage that
    could be assigned to any thread (concurrency issues aside).
    
    Reviewed by:    kib
    Differential Revision:  https://reviews.freebsd.org/D50594
---
 libexec/rtld-elf/rtld.c | 8 ++++----
 libexec/rtld-elf/rtld.h | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c
index 9758fa78bc1b..625e67941be3 100644
--- a/libexec/rtld-elf/rtld.c
+++ b/libexec/rtld-elf/rtld.c
@@ -5380,7 +5380,7 @@ tls_get_addr_slow(struct tcb *tcb, int index, size_t offset, bool locked)
 			wlock_acquire(rtld_bind_lock, &lockstate);
 		if (!dtv->dtv_slots[index - 1].dtvs_tls)
 			dtv->dtv_slots[index - 1].dtvs_tls =
-			    allocate_module_tls(index);
+			    allocate_module_tls(tcb, index);
 		if (!locked)
 			lock_release(rtld_bind_lock, &lockstate);
 	}
@@ -5665,7 +5665,7 @@ free_tls(void *tcb, size_t tcbsize __unused, size_t tcbalign)
  * Allocate TLS block for module with given index.
  */
 void *
-allocate_module_tls(int index)
+allocate_module_tls(struct tcb *tcb, int index)
 {
 	Obj_Entry *obj;
 	char *p;
@@ -5683,9 +5683,9 @@ allocate_module_tls(int index)
 
 	if (obj->tls_static) {
 #ifdef TLS_VARIANT_I
-		p = (char *)_tcb_get() + obj->tlsoffset;
+		p = (char *)tcb + obj->tlsoffset;
 #else
-		p = (char *)_tcb_get() - obj->tlsoffset;
+		p = (char *)tcb - obj->tlsoffset;
 #endif
 		return (p);
 	}
diff --git a/libexec/rtld-elf/rtld.h b/libexec/rtld-elf/rtld.h
index 378cb51d36c6..46473b92a637 100644
--- a/libexec/rtld-elf/rtld.h
+++ b/libexec/rtld-elf/rtld.h
@@ -418,7 +418,7 @@ int symlook_obj(SymLook *, const Obj_Entry *);
 void *tls_get_addr_common(struct tcb *tcb, int index, size_t offset);
 void *allocate_tls(Obj_Entry *, void *, size_t, size_t);
 void free_tls(void *, size_t, size_t);
-void *allocate_module_tls(int index);
+void *allocate_module_tls(struct tcb *tcb, int index);
 bool allocate_tls_offset(Obj_Entry *obj);
 void free_tls_offset(Obj_Entry *obj);
 const Ver_Entry *fetch_ventry(const Obj_Entry *obj, unsigned long);