simplify errno implementation
authorRich Felker <dalias@aerifal.cx>
Tue, 10 Jun 2014 08:49:49 +0000 (04:49 -0400)
committerRich Felker <dalias@aerifal.cx>
Tue, 10 Jun 2014 08:49:49 +0000 (04:49 -0400)
the motivation for the errno_ptr field in the thread structure, which
this commit removes, was to allow the main thread's errno to keep its
address when lazy thread pointer initialization was used. &errno was
evaluated prior to setting up the thread pointer and stored in
errno_ptr for the main thread; subsequently created threads would have
errno_ptr pointing to their own errno_val in the thread structure.

since lazy initialization was removed, there is no need for this extra
level of indirection; __errno_location can simply return the address
of the thread's errno_val directly. this does cause &errno to change,
but the change happens before entry to application code, and thus is
not observable.

src/env/__init_tls.c
src/errno/__errno_location.c
src/internal/pthread_impl.h
src/thread/pthread_create.c

index e1a2b61..f7eab8d 100644 (file)
@@ -16,7 +16,6 @@ int __init_tp(void *p)
        if (!r) libc.can_do_threads = 1;
        libc.has_thread_pointer = 1;
        td->tid = td->pid = __syscall(SYS_set_tid_address, &td->tid);
-       td->errno_ptr = &td->errno_val;
        return 0;
 }
 
index 8419107..49654ef 100644 (file)
@@ -3,6 +3,6 @@
 int *__errno_location(void)
 {
        static int e;
-       if (libc.has_thread_pointer) return __pthread_self()->errno_ptr;
+       if (libc.has_thread_pointer) return &__pthread_self()->errno_val;
        return &e;
 }
index 2e910b3..650e811 100644 (file)
@@ -18,7 +18,7 @@ struct pthread {
        uintptr_t sysinfo;
        uintptr_t canary;
        pid_t tid, pid;
-       int tsd_used, errno_val, *errno_ptr;
+       int tsd_used, errno_val;
        volatile int cancel, canceldisable, cancelasync;
        int detached;
        unsigned char *map_base;
index 7a2f172..e9c8160 100644 (file)
@@ -201,7 +201,6 @@ int pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict attrp
        new->stack = stack;
        new->stack_size = stack - stack_limit;
        new->pid = self->pid;
-       new->errno_ptr = &new->errno_val;
        new->start = entry;
        new->start_arg = arg;
        new->self = new;