summaryrefslogtreecommitdiffstats
path: root/libc/private/bionic_tls.h
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2013-11-15 17:40:18 -0800
committerElliott Hughes <enh@google.com>2013-11-18 19:48:11 -0800
commit877ec6d90418ff1d6597147d355a2229fdffae7e (patch)
treee475221a7fbff1564ad37548e920333c49cc5873 /libc/private/bionic_tls.h
parentf246c589d66e5dc0e3cddc3c37261fb0e3fc67e9 (diff)
downloadbionic-877ec6d90418ff1d6597147d355a2229fdffae7e.zip
bionic-877ec6d90418ff1d6597147d355a2229fdffae7e.tar.gz
bionic-877ec6d90418ff1d6597147d355a2229fdffae7e.tar.bz2
Fix pthread_join.
Let the kernel keep pthread_internal_t::tid updated, including across forks and for the main thread. This then lets us fix pthread_join to only return after the thread has really exited. Also fix the thread attributes of the main thread so we don't unmap the main thread's stack (which is really owned by the dynamic linker and contains things like environment variables), which fixes crashes when joining with an exited main thread and also fixes problems reported publicly with accessing environment variables after the main thread exits (for which I've added a new unit test). In passing I also fixed a bug where if the clone(2) inside pthread_create(3) fails, we'd unmap the child's stack and TLS (which contains the mutex) and then try to unlock the mutex. Boom! It wasn't until after I'd uploaded the fix for this that I came across a new public bug reporting this exact failure. Bug: 8206355 Bug: 11693195 Bug: https://code.google.com/p/android/issues/detail?id=57421 Bug: https://code.google.com/p/android/issues/detail?id=62392 Change-Id: I2af9cf6e8ae510a67256ad93cad891794ed0580b
Diffstat (limited to 'libc/private/bionic_tls.h')
-rw-r--r--libc/private/bionic_tls.h4
1 files changed, 3 insertions, 1 deletions
diff --git a/libc/private/bionic_tls.h b/libc/private/bionic_tls.h
index 094c71c..ff13fdb 100644
--- a/libc/private/bionic_tls.h
+++ b/libc/private/bionic_tls.h
@@ -51,7 +51,9 @@ enum {
TLS_SLOT_THREAD_ID,
TLS_SLOT_ERRNO,
- /* This slot is used when starting a new thread, before any code that needs errno runs. */
+ /* This slot in the child's TLS is used to synchronize the parent and child
+ * during thread initialization. The child finishes with this mutex before
+ * running any code that can set errno, so we can reuse the errno slot. */
TLS_SLOT_START_MUTEX = TLS_SLOT_ERRNO,
/* These two aren't used by bionic itself, but allow the graphics code to