diff options
-rw-r--r-- | libc/bionic/__errno.cpp | 4 | ||||
-rw-r--r-- | libc/bionic/pthread_internal.h | 2 | ||||
-rw-r--r-- | libc/private/bionic_tls.h | 3 |
3 files changed, 6 insertions, 3 deletions
diff --git a/libc/bionic/__errno.cpp b/libc/bionic/__errno.cpp index 32e7a5239..15089a449 100644 --- a/libc/bionic/__errno.cpp +++ b/libc/bionic/__errno.cpp @@ -29,8 +29,8 @@ #include <errno.h> #include <stdint.h> -#include "private/bionic_tls.h" +#include "pthread_internal.h" int* __errno() { - return reinterpret_cast<int*>(&(__get_tls()[TLS_SLOT_ERRNO])); + return &__get_thread()->errno_value; } diff --git a/libc/bionic/pthread_internal.h b/libc/bionic/pthread_internal.h index 2ebd2b4e5..4c13dcb75 100644 --- a/libc/bionic/pthread_internal.h +++ b/libc/bionic/pthread_internal.h @@ -145,6 +145,8 @@ class pthread_internal_t { bionic_tls* bionic_tls; + int errno_value; + // The thread pointer (__get_tls()) points at this field. This field must come last so that // an executable's TLS segment can be allocated at a fixed offset after the thread pointer. void* tls[BIONIC_TLS_SLOTS]; diff --git a/libc/private/bionic_tls.h b/libc/private/bionic_tls.h index 36e3d7b5a..da5a0e0b4 100644 --- a/libc/private/bionic_tls.h +++ b/libc/private/bionic_tls.h @@ -56,7 +56,8 @@ __BEGIN_DECLS enum { TLS_SLOT_SELF = 0, // The kernel requires this specific slot for x86. TLS_SLOT_THREAD_ID, - TLS_SLOT_ERRNO, + + // TLS slot 2 was used for errno but is now free. // These two aren't used by bionic itself, but allow the graphics code to // access TLS directly rather than using the pthread API. |