summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Prichard <rprichard@google.com>2018-12-07 01:47:00 -0800
committerRyan Prichard <rprichard@google.com>2018-12-11 12:59:23 -0800
commit37754cdef681dde87f74ece0712e7c93b18ee368 (patch)
tree2e94cb9012c50e2a6315f08994ff983e0095c15a
parent8b475e598d6c1252271849e41fb0e30e105a0ab3 (diff)
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)
-rw-r--r--libc/bionic/__errno.cpp4
-rw-r--r--libc/bionic/pthread_internal.h2
-rw-r--r--libc/private/bionic_tls.h3
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.