Revert "Revert "Lose the hand-written futex assembler.""
The problem with the original patch was that using syscall(3) means that
errno can be set, but pthread_create(3) was abusing the TLS errno slot as
a pthread_mutex_t for the thread startup handshake.
There was also a mistake in the check for syscall failures --- it should
have checked against -1 instead of 0 (not just because that's the default
idiom, but also here because futex(2) can legitimately return values > 0).
This patch stops abusing the TLS errno slot and adds a pthread_mutex_t to
pthread_internal_t instead. (Note that for LP64 sizeof(pthread_mutex_t) >
sizeof(uintptr_t), so we could potentially clobber other TLS slots too.)
I've also rewritten the LP32 compatibility stubs to directly reuse the
code from the .h file.
This reverts commit 75c55ff84e
.
Bug: 15195455
Change-Id: I6ffb13e5cf6a35d8f59f692d94192aae9ab4593d
This commit is contained in:
@@ -46,32 +46,27 @@ __BEGIN_DECLS
|
||||
** pre-allocated slot directly for performance reason).
|
||||
**/
|
||||
|
||||
/* Well-known TLS slots. What data goes in which slot is arbitrary unless otherwise noted. */
|
||||
// Well-known TLS slots. What data goes in which slot is arbitrary unless otherwise noted.
|
||||
enum {
|
||||
TLS_SLOT_SELF = 0, /* The kernel requires this specific slot for x86. */
|
||||
TLS_SLOT_SELF = 0, // The kernel requires this specific slot for x86.
|
||||
TLS_SLOT_THREAD_ID,
|
||||
TLS_SLOT_ERRNO,
|
||||
|
||||
/* 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
|
||||
* access TLS directly rather than using the pthread API. */
|
||||
// These two aren't used by bionic itself, but allow the graphics code to
|
||||
// access TLS directly rather than using the pthread API.
|
||||
TLS_SLOT_OPENGL_API = 3,
|
||||
TLS_SLOT_OPENGL = 4,
|
||||
|
||||
/* This slot is only used to pass information from the dynamic linker to
|
||||
* libc.so when the C library is loaded in to memory. The C runtime init
|
||||
* function will then clear it. Since its use is extremely temporary,
|
||||
* we reuse an existing location that isn't needed during libc startup. */
|
||||
// This slot is only used to pass information from the dynamic linker to
|
||||
// libc.so when the C library is loaded in to memory. The C runtime init
|
||||
// function will then clear it. Since its use is extremely temporary,
|
||||
// we reuse an existing location that isn't needed during libc startup.
|
||||
TLS_SLOT_BIONIC_PREINIT = TLS_SLOT_OPENGL_API,
|
||||
|
||||
TLS_SLOT_STACK_GUARD = 5, /* GCC requires this specific slot for x86. */
|
||||
TLS_SLOT_STACK_GUARD = 5, // GCC requires this specific slot for x86.
|
||||
TLS_SLOT_DLERROR,
|
||||
|
||||
TLS_SLOT_FIRST_USER_SLOT /* Must come last! */
|
||||
TLS_SLOT_FIRST_USER_SLOT // Must come last!
|
||||
};
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user