1*eeb69571SMatthew Dillon 
2*eeb69571SMatthew Dillon #include "namespace.h"
3*eeb69571SMatthew Dillon #include <machine/tls.h>
4*eeb69571SMatthew Dillon #include <sys/mman.h>
5*eeb69571SMatthew Dillon #include <sys/queue.h>
6*eeb69571SMatthew Dillon #include <sys/stat.h>
7*eeb69571SMatthew Dillon #include <sys/types.h>
8*eeb69571SMatthew Dillon #include <errno.h>
9*eeb69571SMatthew Dillon #include <fcntl.h>
10*eeb69571SMatthew Dillon #include <limits.h>
11*eeb69571SMatthew Dillon #include <pthread.h>
12*eeb69571SMatthew Dillon #include <stdarg.h>
13*eeb69571SMatthew Dillon #include <stdlib.h>
14*eeb69571SMatthew Dillon #include <string.h>
15*eeb69571SMatthew Dillon #include <time.h>
16*eeb69571SMatthew Dillon #include <unistd.h>
17*eeb69571SMatthew Dillon #ifdef _PTHREADS_DEBUGGING
18*eeb69571SMatthew Dillon #include <stdio.h>
19*eeb69571SMatthew Dillon #endif
20*eeb69571SMatthew Dillon #include "un-namespace.h"
21*eeb69571SMatthew Dillon 
22*eeb69571SMatthew Dillon #include "thr_private.h"
23*eeb69571SMatthew Dillon void
24*eeb69571SMatthew Dillon _libthread_distribute_static_tls(size_t offset, void *src,
25*eeb69571SMatthew Dillon 				 size_t len, size_t total_len);
26*eeb69571SMatthew Dillon 
27*eeb69571SMatthew Dillon void
28*eeb69571SMatthew Dillon _libthread_distribute_static_tls(size_t offset, void *src,
29*eeb69571SMatthew Dillon 				 size_t len, size_t total_len)
30*eeb69571SMatthew Dillon {
31*eeb69571SMatthew Dillon 	struct pthread *curthread = tls_get_curthread();
32*eeb69571SMatthew Dillon 	struct pthread *td;
33*eeb69571SMatthew Dillon 	char *tlsbase;
34*eeb69571SMatthew Dillon 
35*eeb69571SMatthew Dillon 	THREAD_LIST_LOCK(curthread);
36*eeb69571SMatthew Dillon 	TAILQ_FOREACH(td, &_thread_list, tle) {
37*eeb69571SMatthew Dillon 		tlsbase = (char *)td->tcb - offset;
38*eeb69571SMatthew Dillon 		memcpy(tlsbase, src, len);
39*eeb69571SMatthew Dillon 		memset(tlsbase + len, 0, total_len - len);
40*eeb69571SMatthew Dillon 	}
41*eeb69571SMatthew Dillon 	THREAD_LIST_UNLOCK(curthread);
42*eeb69571SMatthew Dillon }
43*eeb69571SMatthew Dillon 
44*eeb69571SMatthew Dillon __strong_reference(_libthread_distribute_static_tls, _pthread_distribute_static_tls);
45