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
diff --git a/libc/bionic/__errno.cpp b/libc/bionic/__errno.cpp
index 32e7a52..15089a4 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 2ebd2b4..4c13dcb 100644
--- a/libc/bionic/pthread_internal.h
+++ b/libc/bionic/pthread_internal.h
@@ -145,6 +145,8 @@
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 36e3d7b..da5a0e0 100644
--- a/libc/private/bionic_tls.h
+++ b/libc/private/bionic_tls.h
@@ -56,7 +56,8 @@
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.