X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fenv%2F__init_tls.c;h=a93141ed36a8d7d06d73100304a068f94a8011bc;hb=9532ae1318201d66b235a618df16aac0b3386630;hp=80044960d454220420d5376749f36b18dce6d07a;hpb=9e2d820a555e150df462f88c901fcbe25d692a8b;p=musl diff --git a/src/env/__init_tls.c b/src/env/__init_tls.c index 80044960..a93141ed 100644 --- a/src/env/__init_tls.c +++ b/src/env/__init_tls.c @@ -1,3 +1,4 @@ +#define SYSCALL_NO_TLS 1 #include #include #include @@ -8,6 +9,8 @@ #include "atomic.h" #include "syscall.h" +volatile int __thread_list_lock; + int __init_tp(void *p) { pthread_t td = p; @@ -15,10 +18,12 @@ int __init_tp(void *p) int r = __set_thread_area(TP_ADJ(p)); if (r < 0) return -1; if (!r) libc.can_do_threads = 1; - td->join_futex = -1; - td->tid = __syscall(SYS_set_tid_address, &td->join_futex); + td->detach_state = DT_JOINABLE; + td->tid = __syscall(SYS_set_tid_address, &__thread_list_lock); td->locale = &libc.global_locale; td->robust_list.head = &td->robust_list.head; + td->sysinfo = __sysinfo; + td->next = td->prev = td; return 0; } @@ -36,33 +41,33 @@ void *__copy_tls(unsigned char *mem) pthread_t td; struct tls_module *p; size_t i; - void **dtv; + uintptr_t *dtv; #ifdef TLS_ABOVE_TP - dtv = (void **)(mem + libc.tls_size) - (libc.tls_cnt + 1); + dtv = (uintptr_t*)(mem + libc.tls_size) - (libc.tls_cnt + 1); mem += -((uintptr_t)mem + sizeof(struct pthread)) & (libc.tls_align-1); td = (pthread_t)mem; mem += sizeof(struct pthread); for (i=1, p=libc.tls_head; p; i++, p=p->next) { - dtv[i] = mem + p->offset; - memcpy(dtv[i], p->image, p->len); + dtv[i] = (uintptr_t)(mem + p->offset) + DTP_OFFSET; + memcpy(mem + p->offset, p->image, p->len); } #else - dtv = (void **)mem; + dtv = (uintptr_t *)mem; mem += libc.tls_size - sizeof(struct pthread); mem -= (uintptr_t)mem & (libc.tls_align-1); td = (pthread_t)mem; for (i=1, p=libc.tls_head; p; i++, p=p->next) { - dtv[i] = mem - p->offset; - memcpy(dtv[i], p->image, p->len); + dtv[i] = (uintptr_t)(mem - p->offset) + DTP_OFFSET; + memcpy(mem - p->offset, p->image, p->len); } #endif - dtv[0] = (void *)libc.tls_cnt; - td->dtv = td->dtv_copy = dtv; + dtv[0] = libc.tls_cnt; + td->dtv = dtv; return td; } @@ -72,8 +77,7 @@ typedef Elf32_Phdr Phdr; typedef Elf64_Phdr Phdr; #endif -__attribute__((__weak__, __visibility__("hidden"))) -extern const size_t _DYNAMIC[]; +extern weak hidden const size_t _DYNAMIC[]; static void static_init_tls(size_t *aux) { @@ -91,6 +95,11 @@ static void static_init_tls(size_t *aux) base = (size_t)_DYNAMIC - phdr->p_vaddr; if (phdr->p_type == PT_TLS) tls_phdr = phdr; + if (phdr->p_type == PT_GNU_STACK && + phdr->p_memsz > __default_stacksize) + __default_stacksize = + phdr->p_memsz < DEFAULT_STACK_MAX ? + phdr->p_memsz : DEFAULT_STACK_MAX; } if (tls_phdr) { @@ -104,13 +113,20 @@ static void static_init_tls(size_t *aux) main_tls.size += (-main_tls.size - (uintptr_t)main_tls.image) & (main_tls.align-1); - if (main_tls.align < MIN_TLS_ALIGN) main_tls.align = MIN_TLS_ALIGN; -#ifndef TLS_ABOVE_TP +#ifdef TLS_ABOVE_TP + main_tls.offset = GAP_ABOVE_TP; + main_tls.offset += (-GAP_ABOVE_TP + (uintptr_t)main_tls.image) + & (main_tls.align-1); +#else main_tls.offset = main_tls.size; #endif + if (main_tls.align < MIN_TLS_ALIGN) main_tls.align = MIN_TLS_ALIGN; libc.tls_align = main_tls.align; libc.tls_size = 2*sizeof(void *) + sizeof(struct pthread) +#ifdef TLS_ABOVE_TP + + main_tls.offset +#endif + main_tls.size + main_tls.align + MIN_TLS_ALIGN-1 & -MIN_TLS_ALIGN;