about summary refs log tree commit diff
path: root/htl
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2020-06-07 23:27:46 +0000
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2020-06-07 23:36:40 +0000
commitaf27fabe405c757d372b106c8aa383a386a4a79e (patch)
treecd019d303cfa25d12637c46c4bd109f82e819032 /htl
parent3944c61bdf5d1530d0576a396eb3e2f9a4d6caff (diff)
downloadglibc-af27fabe405c757d372b106c8aa383a386a4a79e.tar.gz
glibc-af27fabe405c757d372b106c8aa383a386a4a79e.tar.xz
glibc-af27fabe405c757d372b106c8aa383a386a4a79e.zip
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.
Diffstat (limited to 'htl')
-rw-r--r--htl/pt-alloc.c29
1 files changed, 29 insertions, 0 deletions
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);
+}