fix stderr locking and ferror semantics in getopt message printing
[musl] / src / env / __init_tls.c
index c80f052..ddc2a73 100644 (file)
@@ -11,17 +11,12 @@ int __init_tp(void *p)
 {
        pthread_t td = p;
        td->self = td;
-       if (__set_thread_area(TP_ADJ(p)) < 0)
-               return -1;
-       td->tid = td->pid = __syscall(SYS_set_tid_address, &td->tid);
-       td->errno_ptr = &td->errno_val;
-       /* Currently, both of these predicates depend in the same thing:
-        * successful initialization of the thread pointer. However, in
-        * the future, we may support setups where setting the thread
-        * pointer is possible but threads other than the main thread
-        * cannot work, so it's best to keep the predicates separate. */
+       int r = __set_thread_area(TP_ADJ(p));
+       if (r < 0) return -1;
+       if (!r) libc.can_do_threads = 1;
        libc.has_thread_pointer = 1;
-       libc.can_do_threads = 1;
+       td->tid = __syscall(SYS_set_tid_address, &td->tid);
+       td->locale = &libc.global_locale;
        return 0;
 }
 
@@ -59,13 +54,6 @@ void *__copy_tls(unsigned char *mem)
        return td;
 }
 
-void *__tls_get_addr(size_t *v)
-{
-       return (char *)__pthread_self()->dtv[1]+v[1];
-}
-
-void *__mmap(void *, size_t, int, int, int, off_t);
-
 #if ULONG_MAX == 0xffffffff
 typedef Elf32_Phdr Phdr;
 #else
@@ -103,12 +91,11 @@ void __init_tls(size_t *aux)
        libc.tls_size = 2*sizeof(void *)+T.size+T.align+sizeof(struct pthread);
 
        if (libc.tls_size > sizeof builtin_tls) {
+#ifndef SYS_mmap2
+#define SYS_mmap2 SYS_mmap
+#endif
                mem = (void *)__syscall(
-#ifdef SYS_mmap2
                        SYS_mmap2,
-#else
-                       SYS_mmap,
-#endif
                        0, libc.tls_size, PROT_READ|PROT_WRITE,
                        MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
                /* -4095...-1 cast to void * will crash on dereference anyway,