about summary refs log tree commit diff
path: root/sysdeps/mach/hurd/x86_64
diff options
context:
space:
mode:
authorSergey Bugaev <bugaevc@gmail.com>2023-04-20 21:42:19 +0300
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2023-04-21 03:02:04 +0200
commit8e78a2e1d166411a1243e505d036e85e4a7ff17f (patch)
treea5d270f3baad166aeed81481a5b39ce71b18497c /sysdeps/mach/hurd/x86_64
parent88cc282a9a694d3c4f3636d6d518f9f0dac76b73 (diff)
downloadglibc-8e78a2e1d166411a1243e505d036e85e4a7ff17f.tar.gz
glibc-8e78a2e1d166411a1243e505d036e85e4a7ff17f.tar.xz
glibc-8e78a2e1d166411a1243e505d036e85e4a7ff17f.zip
hurd: Don't migrate reply port into __init1_tcbhead
Properly differentiate between setting up the real TLS with
TLS_INIT_TP, and setting up the early TLS (__init1_tcbhead) in static
builds. In the latter case, don't yet migrate the reply port into the
TCB, and don't yet set __libc_tls_initialized to 1.

This also lets us move the __init1_desc assignment inside
_hurd_tls_init ().

Fixes cd019ddd892e182277fadd6aedccc57fa3923c8d
"hurd: Don't leak __hurd_reply_port0"

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
Diffstat (limited to 'sysdeps/mach/hurd/x86_64')
-rw-r--r--sysdeps/mach/hurd/x86_64/tls.h11
1 files changed, 6 insertions, 5 deletions
diff --git a/sysdeps/mach/hurd/x86_64/tls.h b/sysdeps/mach/hurd/x86_64/tls.h
index 2b7135f635..1274723a9d 100644
--- a/sysdeps/mach/hurd/x86_64/tls.h
+++ b/sysdeps/mach/hurd/x86_64/tls.h
@@ -173,7 +173,7 @@ extern unsigned char __libc_tls_initialized;
 #  define __LIBC_NO_TLS() __builtin_expect (!__libc_tls_initialized, 0)
 
 static inline bool __attribute__ ((unused))
-_hurd_tls_init (tcbhead_t *tcb)
+_hurd_tls_init (tcbhead_t *tcb, bool full)
 {
   error_t err;
   thread_t self = __mach_thread_self ();
@@ -181,11 +181,12 @@ _hurd_tls_init (tcbhead_t *tcb)
 
   /* We always at least start the sigthread anyway.  */
   tcb->multiple_threads = 1;
-  /* Take over the reply port we've been using.  */
-  tcb->reply_port = __hurd_reply_port0;
+  if (full)
+    /* Take over the reply port we've been using.  */
+    tcb->reply_port = __hurd_reply_port0;
 
   err = _hurd_tls_new (self, tcb);
-  if (err == 0)
+  if (err == 0 && full)
     {
       __libc_tls_initialized = 1;
       /* This port is now owned by the TCB.  */
@@ -195,7 +196,7 @@ _hurd_tls_init (tcbhead_t *tcb)
   return err == 0;
 }
 
-#  define TLS_INIT_TP(descr) _hurd_tls_init ((tcbhead_t *) (descr))
+#  define TLS_INIT_TP(descr) _hurd_tls_init ((tcbhead_t *) (descr), 1)
 # else /* defined (SHARED) && !IS_IN (rtld) */
 #  define __LIBC_NO_TLS() 0
 # endif