public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc] htl: Fix tls initialization for already-created threads
@ 2020-06-08  0:05 Samuel Thibault
  0 siblings, 0 replies; only message in thread
From: Samuel Thibault @ 2020-06-08  0:05 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=af27fabe405c757d372b106c8aa383a386a4a79e

commit af27fabe405c757d372b106c8aa383a386a4a79e
Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date:   Sun Jun 7 23:27:46 2020 +0000

    htl: Fix tls initialization for already-created threads
    
    * sysdeps/htl/pthreadP.h: Include <link.h>
    (__pthread_init_static_tls): New prototype.
    * htl/pt-alloc.c (__pthread_init_static_tls): New function.
    * sysdeps/mach/hurd/htl/pt-sysdep.c (_init_routine): Initialize tcb
    field of initial thread. Set GL(dl_init_static_tls) to
    &__pthread_init_static_tls.

Diff:
---
 htl/pt-alloc.c                    | 29 +++++++++++++++++++++++++++++
 sysdeps/htl/pthreadP.h            |  3 +++
 sysdeps/mach/hurd/htl/pt-sysdep.c |  3 +++
 3 files changed, 35 insertions(+)

diff --git a/htl/pt-alloc.c b/htl/pt-alloc.c
index 4e6fa52c4a..d4426bb2e3 100644
--- a/htl/pt-alloc.c
+++ b/htl/pt-alloc.c
@@ -212,3 +212,32 @@ retry:
   *pthread = new;
   return 0;
 }
+
+void
+attribute_hidden
+__pthread_init_static_tls (struct link_map *map)
+{
+  int i;
+
+  __pthread_rwlock_wrlock (&__pthread_threads_lock);
+  for (i = 0; i < __pthread_num_threads; ++i)
+    {
+      struct __pthread *t = __pthread_threads[i];
+
+      if (t == NULL)
+	continue;
+
+# if TLS_TCB_AT_TP
+      void *dest = (char *) t->tcb - map->l_tls_offset;
+# elif TLS_DTV_AT_TP
+      void *dest = (char *) t->tcb + map->l_tls_offset + TLS_PRE_TCB_SIZE;
+# else
+#  error "Either TLS_TCB_AT_TP or TLS_DTV_AT_TP must be defined"
+# endif
+
+      /* Initialize the memory.  */
+      memset (__mempcpy (dest, map->l_tls_initimage, map->l_tls_initimage_size),
+	      '\0', map->l_tls_blocksize - map->l_tls_initimage_size);
+    }
+  __pthread_rwlock_unlock (&__pthread_threads_lock);
+}
diff --git a/sysdeps/htl/pthreadP.h b/sysdeps/htl/pthreadP.h
index 7486c9383e..0eb969ea1a 100644
--- a/sysdeps/htl/pthreadP.h
+++ b/sysdeps/htl/pthreadP.h
@@ -22,10 +22,13 @@
 #define __PTHREAD_HTL
 
 #include <pthread.h>
+#include <link.h>
 
 /* Attribute to indicate thread creation was issued from C11 thrd_create.  */
 #define ATTR_C11_THREAD ((void*)(uintptr_t)-1)
 
+extern void __pthread_init_static_tls (struct link_map *) attribute_hidden;
+
 /* These represent the interface used by glibc itself.  */
 
 extern pthread_t __pthread_self (void);
diff --git a/sysdeps/mach/hurd/htl/pt-sysdep.c b/sysdeps/mach/hurd/htl/pt-sysdep.c
index 84d191475d..0963b44878 100644
--- a/sysdeps/mach/hurd/htl/pt-sysdep.c
+++ b/sysdeps/mach/hurd/htl/pt-sysdep.c
@@ -77,6 +77,7 @@ _init_routine (void *stack)
      to the new stack.  Pretend it wasn't allocated so that it remains
      valid if the main thread terminates.  */
   thread->stack = 0;
+  thread->tcb = THREAD_SELF;
 
 #ifndef PAGESIZE
   __pthread_default_attr.__guardsize = __vm_page_size;
@@ -91,6 +92,8 @@ _init_routine (void *stack)
 
   __pthread_atfork (NULL, NULL, reset_pthread_total);
 
+  GL(dl_init_static_tls) = &__pthread_init_static_tls;
+
   /* Make MiG code thread aware.  */
   __mig_init (thread->stackaddr);


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-06-08  0:05 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-08  0:05 [glibc] htl: Fix tls initialization for already-created threads Samuel Thibault

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).