about summary refs log tree commit diff
path: root/src/env
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2012-10-04 20:04:13 -0400
committerRich Felker <dalias@aerifal.cx>2012-10-04 20:04:13 -0400
commitbc6a35fb7b02f068b901f22a56559996395cfd3b (patch)
tree6d96b2475c1912259cb3c3b1510e96805febb561 /src/env
parent8431d7972fd9be0fdcaff8516316d748e81724bb (diff)
downloadmusl-bc6a35fb7b02f068b901f22a56559996395cfd3b.tar.gz
musl-bc6a35fb7b02f068b901f22a56559996395cfd3b.tar.xz
musl-bc6a35fb7b02f068b901f22a56559996395cfd3b.zip
partial TLS support for dynamic-linked programs
only TLS in the main program is supported so far; TLS defined in
shared libraries will not work yet.
Diffstat (limited to 'src/env')
-rw-r--r--src/env/__init_tls.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/env/__init_tls.c b/src/env/__init_tls.c
index 4a840cf2..aff388bd 100644
--- a/src/env/__init_tls.c
+++ b/src/env/__init_tls.c
@@ -7,13 +7,14 @@
 #ifndef SHARED
 
 static void *image;
-static size_t len, bss, align;
+static size_t len, size, align;
 
 void *__copy_tls(unsigned char *mem, size_t cnt)
 {
+	mem += -size & (4*sizeof(size_t)-1);
 	mem += ((uintptr_t)image - (uintptr_t)mem) & (align-1);
 	memcpy(mem, image, len);
-	return mem + len + bss;
+	return mem + size;
 }
 
 static void *simple(void *p)
@@ -53,13 +54,12 @@ void __init_tls(size_t *auxv)
 	}
 	if (!tls_phdr) return;
 
-	libc.tls_size = len+bss+align+4*sizeof(size_t)+sizeof(struct pthread);
+	libc.tls_size = size+align+8*sizeof(size_t)+sizeof(struct pthread);
 
 	image = (void *)(base + tls_phdr->p_vaddr);
 	len = tls_phdr->p_filesz;
-	bss = tls_phdr->p_memsz - len;
+	size = tls_phdr->p_memsz;
 	align = tls_phdr->p_align;
-	if (align < 4*sizeof(size_t)) align = 4*sizeof(size_t);
 	mem = __mmap(0, libc.tls_size, PROT_READ|PROT_WRITE,
 		MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
 	if (mem == MAP_FAILED) a_crash();