From 37754cdef681dde87f74ece0712e7c93b18ee368 Mon Sep 17 00:00:00 2001 From: Ryan Prichard Date: Fri, 7 Dec 2018 01:47:00 -0800 Subject: [PATCH] Move errno to a pthread_internal_t field. This change is intended to allow native-bridge to use independent TLS memory for host and guest environments, while still sharing a thread-local errno between the two. Bug: http://b/78026329 Test: bionic unit tests Change-Id: I838cd321e159add60760bc12a8aa7e9ddc960c33 Merged-In: I838cd321e159add60760bc12a8aa7e9ddc960c33 (cherry picked from commit a9c7c55462392a6b974761831744f6d80ca162df) --- libc/bionic/__errno.cpp | 4 ++-- libc/bionic/pthread_internal.h | 2 ++ 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 #include -#include "private/bionic_tls.h" +#include "pthread_internal.h" int* __errno() { - return reinterpret_cast(&(__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.