History log of /bionic/tests/pthread_test.cpp
Revision Date Author Comments
0eed2827ed707f22c6901f70a167b005a2ade262 22-Mar-2016 Yabin Cui <yabinc@google.com> Fix pthread.pthread_barrier_smoke test.

pthread_barrier_smoke test uses WaitUntilThreadSleep() to wait until
BarrierTestHelper threads sleep in pthread_barrier_wait(). But this
is flaky as there a two futex_wait places in pthread_barrier_wait.
This patch modifies this test to avoid using WaitUntilThreadSleep().

Bug: 27780937
Bug: 27811377
Change-Id: I4c36b82cce9345d5088f8854b289dc5bf7a08e8c
(cherry picked from commit 81d2797e33d6f95c0b79e20ae8a04f2a4f3841cc)
d323e435b180d96efae369447351de485936e7f8 08-Mar-2016 Yabin Cui <yabinc@google.com> Adjust test to let it pass on libhoudini.

When using libhoudini to run arm code on x86 platforms, we can't
assume the main thread allocates local variables at the stack
declared by kernel.

(cherry picked from commit 61e4d461e5c1c5108fdfe2a9f1edec6717e7461e)

Bug: http://b/27815309
Change-Id: Ic714a8e633a0bb6e85b38ee0e01e3439d0a0cea5
ec9b56ee2e3ddd5b475e9804f42f65e8b71486bd 08-Mar-2016 Yabin Cui <yabinc@google.com> Adjust test to let it pass on libhoudini.

When using libhoudini to run arm code on x86 platforms, we can't
assume the main thread allocates local variables at the stack
declared by kernel.

(cherry picked from commit 61e4d461e5c1c5108fdfe2a9f1edec6717e7461e)

Bug: http://b/27815309
Change-Id: Ic714a8e633a0bb6e85b38ee0e01e3439d0a0cea5
33697a0c43c48e15c3bcf018138b9b837d0099cd 26-Jan-2016 Elliott Hughes <enh@google.com> Factor out the waiting for children in bionic tests.

Change-Id: I4a1e51b6920b33dc892d447f5bd6d10f1cb2704a
d31d4c1cc65ab878c32927259fcc7ac744f7cc52 15-Dec-2015 Elliott Hughes <enh@google.com> Add a few missing pthread tests.

This seems to be all that's tested by system/extras/tests/bionic that isn't
already better tested here.

Change-Id: Id0aa985cefd4047a6007ba9804f541069d9e92ed
76144aaa6397fe9e16893882cf59c5c9c0684a66 19-Nov-2015 Yabin Cui <yabinc@google.com> Change _stdio_handles_locking into _caller_handles_locking.

It is reported by tsan that funlockfile() can unlock an unlocked mutex.
It happens when printf() is called before fopen() or other stdio stuff.
As FLOCKFILE(fp) is called before __sinit(), _stdio_handles_locking is false,
and _FLOCK(fp) will not be locked. But then cantwrite(fp) in __vfprintf()
calls__sinit(), which makes _stdio_handles_locking become true, and
FUNLOCKFILE(fp) unlocks _FLOCK(fp).

Change _stdio_handles_locking into _caller_handles_locking,
so __sinit() won't change its value. Add test due to my previous fault.

Bug: 25392375
Change-Id: I483e3c3cdb28da65e62f1fd9615bf58c5403b4dd
c9a659c57b256001fd63f9825bde69e660c2655b 06-Nov-2015 Yabin Cui <yabinc@google.com> Use FUTEX_WAIT_BITSET to avoid converting timeouts.

Add unittests for pthread APIs with timeout parameter.

Bug: 17569991

Change-Id: I6b3b9b2feae03680654cd64c3112ce7644632c87
fe3a83a9343f0e4ff654f09ef8ffc8a773c7c105 18-Nov-2015 Yabin Cui <yabinc@google.com> Implement pthread spin.

In order to run tsan unit tests, we need to support pthread spin APIs.

Bug: 18623621
Bug: 25392375
Change-Id: Icbb4a74e72e467824b3715982a01600031868e29
a36158a77d904aa65f50d5950b7608ef8fa3210f 17-Nov-2015 Yabin Cui <yabinc@google.com> Fix pthread_test according to tsan report.

1. Fix leak threads and data races related to spin_flag.
2. Increase stack size to run under tsan.

This doesn't pass all pthread tests, as some tests are used
to run intentionally in race situations.

Bug: 25392375
Change-Id: Icfba3e141e7170abd890809586e89b99adc8bd02
e7c2fffa16eccecfd43d99516751a43776f5f609 06-Nov-2015 Yabin Cui <yabinc@google.com> Implement pthread barrier.

Bug: 24341262
Change-Id: I5472549e5d7545c1c3f0bef78235f545557b9630
f208361b2b7c00b1decefa4bdb7115338649686b 11-Nov-2015 Elliott Hughes <enh@google.com> Clean up pthread_gettid_np test.

Change-Id: I0fad26c7824981bfa3ad3a8a0b28a1984062dcd1
de1246202a229efe555170a7c5803510f5975658 10-Nov-2015 Junjie Hu <junjie.hu@mediatek.com> Fix potential race condition on CTS TC pthread_gettid_np

Root cause:
If start_routine thread exits before pthread_gettid_np is invokded, the "tid" field
will be cleared so that pthread_gettid_np will get "0" (which is cleared by kernel,
due to the flag "CLONE_CHILD_CLEARTID" is set while calling clone system call inside
pthread_create).

Proposed patch:
Use a mutex to guarantee pthread_gettid_np will be invoked and returned before the
start_routine exits

Signed-off-by: Junjie Hu <junjie.hu@mediatek.com>

Change-Id: I22411f1b0f7446d76a0373cef4ccec858fac7018
(cherry picked from commit 4f8010293506d4e08d184e66bf4af44ef3483611)
4f8010293506d4e08d184e66bf4af44ef3483611 10-Nov-2015 Junjie Hu <junjie.hu@mediatek.com> Fix potential race condition on CTS TC pthread_gettid_np

Root cause:
If start_routine thread exits before pthread_gettid_np is invokded, the "tid" field
will be cleared so that pthread_gettid_np will get "0" (which is cleared by kernel,
due to the flag "CLONE_CHILD_CLEARTID" is set while calling clone system call inside
pthread_create).

Proposed patch:
Use a mutex to guarantee pthread_gettid_np will be invoked and returned before the
start_routine exits

Signed-off-by: Junjie Hu <junjie.hu@mediatek.com>

Change-Id: I22411f1b0f7446d76a0373cef4ccec858fac7018
0b2acdfcc99ecf3ff36fc6337e14b171170f38cf 03-Oct-2015 Elliott Hughes <enh@google.com> Use const auto& in for loops.

Change-Id: Ic437c59797ee4e7dc38291da35c72d827bc89c8d
01030c24b0e3ace1b4cdaf415354e2f315f4f3a9 22-Sep-2015 Yabin Cui <yabinc@google.com> Increase alternative signal stack size on 64-bit devices.

Bug: 23041777
Bug: 24187462
Change-Id: I7d84c0cc775a74753a3e8e101169c0fb5dbf7437
15dfd63aba596f95f2478bfca36b91f69ed7f9b3 23-Sep-2015 Elliott Hughes <enh@google.com> Fix another duplicate maps parser.

Change-Id: Icb69f59ffbd0d5de7f727142260fae152d36a904
0dec2289211dd75e2dd99e4aad84ece845e69864 23-Sep-2015 Elliott Hughes <enh@google.com> Clean up /proc/<pid>/maps sscanfs.

sscanf will swallow whitespace for us.

Change-Id: I59931cbad00f0144fd33ed4749ac0aaad15e6de6
33ac04a215a70d2f39f1ddec1bba5a42c0fd8bee 22-Sep-2015 Yabin Cui <yabinc@google.com> Increase alternative signal stack size on 64-bit devices.

Bug: 23041777
Bug: 24187462
Change-Id: I7d84c0cc775a74753a3e8e101169c0fb5dbf7437
569333293aeefbe792826cd59140dc23704018c4 11-Sep-2015 Mor-sarid, Nitzan <nitzan.mor-sarid@intel.com> Fix the way to get main thread stack start address.

For previous way to get the stack using the [stack] string from
/proc/self/task/<pid>/maps is not enough. On x86/x86_64, if an
alternative signal stack is used while a task switch happens,
the [stack] indicator may no longer be correct.

Instead, stack_start from /proc/self/stat which is always inside
the main stack, is used to find the main stack in /proc/self/maps.

Change-Id: Ieb010e71518b57560d541cd3b3563e5aa9660750
Signed-off-by: Nitzan Mor-sarid <nitzan.mor-sarid@intel.com>
Signed-off-by: Mingwei Shi <mingwei.shi@intel.com>
60907c7f4ec788def8741e4efb933eafb6560eaa 10-Jun-2015 Christopher Ferris <cferris@google.com> Allow NULL in pthread_mutex_lock/unlock.

The pthread_mutex_lock and pthread_mutex_unlock were allowed to
fail silently on L 32 bit devices when passed a NULL. We changed
this to a crash on 32 bit devices, but there are still games that make
these calls and are not likely to be updated. Therefore, once again
allow NULL to be passed in on 32 bit devices.

Bug: 19995172
(cherry picked from commit 511cfd9dc8cb41bca4920687c7d816ee916ee8e5)

Change-Id: I159a99a941cff94297ef3fffda7075f8ef1ae252
511cfd9dc8cb41bca4920687c7d816ee916ee8e5 10-Jun-2015 Christopher Ferris <cferris@google.com> Allow NULL in pthread_mutex_lock/unlock.

The pthread_mutex_lock and pthread_mutex_unlock were allowed to
fail silently on L 32 bit devices when passed a NULL. We changed
this to a crash on 32 bit devices, but there are still games that make
these calls and are not likely to be updated. Therefore, once again
allow NULL to be passed in on 32 bit devices.

Bug: 19995172
Change-Id: If7e8860075ecd63c0064d80f64e226fad7bd3c26
b0c6f2dba2dc7b1604e00d0d553ac7f38f719049 20-May-2015 Yabin Cui <yabinc@google.com> Fix pthread_attr_getstack__main_thread failure on glibc.

Move test of bionic specific implementation into bionic ifdef.

Bug: 19805726
Change-Id: Idf369b16e7f41f060c75b0aaf34e05cf3c161aa9
2b5c2285c0679190b90b954d5e71f7ee8698adba 08-May-2015 Yabin Cui <yabinc@google.com> Remove pthread_detach_no_leak test.

This test has lost its purpose as we are using mmap/munmap for pthread_internal_t. And it is a flaky test.

Bug: 21205574
Bug: 20860440
Change-Id: I7cbb6bc3fd8a2ca430415beab5ee27a856ce4ea7
(cherry picked from commit 2957cc5f1043adf0b9c0f1cdfff2d408952e40f5)
2957cc5f1043adf0b9c0f1cdfff2d408952e40f5 08-May-2015 Yabin Cui <yabinc@google.com> Remove pthread_detach_no_leak test.

This test has lost its purpose as we are using mmap/munmap for pthread_internal_t. And it is a flaky test.

Bug: 20860440
Change-Id: I7cbb6bc3fd8a2ca430415beab5ee27a856ce4ea7
a60fd09e2692e17c8bfa210d3cb64b490aea4c9d 06-May-2015 Dmitriy Ivanov <dimitry@google.com> Move pthread_atfork_dlclose test out of static lib

Bug: http://b/20858755
Change-Id: I0d84e8b43dc33902d75af18db6b7c8e0b619d718
(cherry picked from commit 5624a6a1e52ff959b0f88765d38f190700422773)
5624a6a1e52ff959b0f88765d38f190700422773 06-May-2015 Dmitriy Ivanov <dimitry@google.com> Move pthread_atfork_dlclose test out of static lib

Bug: http://b/20858755
Change-Id: I0d84e8b43dc33902d75af18db6b7c8e0b619d718
d1aea30b2ade504550f7bb7996c808b9af1c415d 25-Apr-2015 Elliott Hughes <enh@google.com> Fix POSIX timer thread naming.

Spencer Low points out that we never actually set a name because the constant
part of the string was longer than the kernel's maximum, and the kernel
rejects long names rather than truncate.

Shorten the fixed part of the string while still keeping it meaningful. 9999
POSIX timers should be enough for any process...

Bug: https://code.google.com/p/android/issues/detail?id=170089
Change-Id: Ic05f07584c1eac160743519091a540ebbf8d7eb1
ea295f68f1fae7c701baaa717f67296659d567ac 21-Nov-2014 Dmitriy Ivanov <dimitry@google.com> Unregister pthread_atfork handlers on dlclose()

Bug: http://b/20339788
Change-Id: I874c87faa377645fa9e0752f4fc166d81fd9ef7e
094f58fb2a57d1ed5736ae3588bf0355618f915b 24-Apr-2015 Dimitry Ivanov <dimitry@google.com> Revert "Unregister pthread_atfork handlers on dlclose()"

The visibility control in pthread_atfork.h is incorrect.
It breaks 64bit libc.so by hiding pthread_atfork.

This reverts commit 6df122f8528f9b9fcf7dfea14ae98b0ef66274e1.

Change-Id: I21e4b344d500c6f6de0ccb7420b916c4e233dd34
6df122f8528f9b9fcf7dfea14ae98b0ef66274e1 21-Nov-2014 Dmitriy Ivanov <dimitry@google.com> Unregister pthread_atfork handlers on dlclose()

Change-Id: I326fdf6bb06bed12743f08980b5c69d849c015b8
5ddbb3f936ee44555a46020239e49ab45109a806 06-Mar-2015 Yabin Cui <yabinc@google.com> Prevent using static-allocated pthread keys before creation.

Bug: 19993460

Change-Id: I244dea7f5df3c8384f88aa48d635348fafc9cbaf
76615dae93c18ac890e167c547a08c0228709a33 17-Mar-2015 Yabin Cui <yabinc@google.com> Provide writer preference option in rwlock.

Previous implementation of rwlock contains four atomic variables, which
is hard to maintain and change. So I make following changes in this CL:

1. Add pending flags in rwlock.state, so we don't need to synchronize
between different atomic variables. Using compare_and_swap operations
on rwlock.state is enough for all state change.

2. Add pending_lock to protect readers/writers waiting and wake up
operations. As waiting/wakeup is not performance critical, using a
lock is easier to maintain.

3. Add writer preference option.

4. Add unit tests for rwlock.

Bug: 19109156

Change-Id: Idcaa58d695ea401d64445610b465ac5cff23ec7c
f796985923e2d8308e00ed9567f36546dafb98d7 03-Apr-2015 Yabin Cui <yabinc@google.com> Fix bug for recursive/errorcheck mutex on 32-bit devices.

Bug: 19216648
Change-Id: I3b43b2d18d25b9bde352da1e35f9568133dec7cf
e69c24543db577d8b219ab74b0ba7566e0f13b38 14-Feb-2015 Yabin Cui <yabinc@google.com> Refactor pthread_mutex to support 32-bit owner_tid on 64-bit devices.

Bug: 19216648
Change-Id: I765ecacc9036659c766f5d1f6600e1a65364199b
6170693e28dd72a1517c267f3f62b3f37477b8bb 31-Mar-2015 Elliott Hughes <enh@google.com> Make ThreadLocalBuffer a class rather than a macro.

Bug: 19995392
Change-Id: I497c512648fbe66257da3fb3bcd5c9911f983705
220b99bdc1c5f51825ac2a87062bc05fe3e0d722 26-Mar-2015 Yabin Cui <yabinc@google.com> Revert "Cause Fatal error when invalid pthread_id is detected."

Some code like in https://buganizer.corp.google.com/u/0/issues/19942911 need to change first.

This reverts commit 03324780aae9ff28c8acf52debf0ea39120e5ab8.

Change-Id: I13ff1e5b3d0672bae9cde234ffba32fbbf33d338
17393b06bab9cb3e95d0f466a56c746de19b8eee 21-Mar-2015 Yabin Cui <yabinc@google.com> Hide internal of pthread_mutex_t.

Bug: 19249079
Change-Id: Iffb79c8d861b698d474f212dc80c638fc2cf1620
03324780aae9ff28c8acf52debf0ea39120e5ab8 25-Mar-2015 Yabin Cui <yabinc@google.com> Cause Fatal error when invalid pthread_id is detected.

This is a patch testing whether we can use abort() instead of
returning ESRCH for invalid pthread ids. It is an intermediate
step to remove g_thread_list/g_thread_list_lock.

Bug: 19636317
Change-Id: Idd8e4a346c7ce91e1be0c2ebcb78ce51c0d0a31d
b58457221364eaad039c2c49a42626b725e980d5 17-Mar-2015 Yabin Cui <yabinc@google.com> Add test for pthread types alignment check.

Bug: 19249079
Change-Id: I83c4f0d11ec5d82a346ae0057d02a92bb1d519e8
bbb0432a33787f1a627abb396fe343a7943ac7bc 19-Mar-2015 Yabin Cui <yabinc@google.com> Return EINVAL when calling pthread_detach for joined thread.

Change-Id: I717015132187e087e0ad485284a13c8801e25e77
cb0443c0fa07e4c049f426e3041894df522732df 16-Mar-2015 Dmitriy Ivanov <dimitry@google.com> Remove obsolete test_isolated wrapper function

We already run all of our tests in isolated mode.

Change-Id: I8236baa302b1026a9b4a1c33a4aa65e223771bc7
32651b8e8e453391c7aaca47cd885e94d54d0bf4 14-Mar-2015 Yabin Cui <yabinc@google.com> Hide content of pthread_cond_t in pthread_cond_internal_t.

Bug: 19249079
Change-Id: I6f55af30bcd6211ce71630c6cacbef0e1663dcee
5b8e7cd957f9380e93c3aee84962d157fe0bc526 05-Mar-2015 Yabin Cui <yabinc@google.com> Remove duplication in pthread_mutex.cpp.

Also add unit tests about thread woken up by pthread_mutex_unlock.

Bug: 19216648

Change-Id: I8bde8105b00186c52a2f41d92458ae4a5eb90426
08ee8d2030fbc73c4c144e819dd68806b0351cbe 12-Feb-2015 Yabin Cui <yabinc@google.com> Switch pthread_rwlock_t to stdatomic.

Bug: 19099838
Change-Id: Ie82967a60b5cec61a8bdd1e0e4a03738d01944f8
140f3678f0f21eeda5916e9b8de87b93fd660a61 03-Feb-2015 Yabin Cui <yabinc@google.com> Add test about pthread_mutex_t owner tid limit.

Bug: 19216648
Change-Id: I7b12955bdcad31c13bf8ec2740ff88ba15223ec0
19e246dda6772ffc532b1762cd7870d6c3b01c12 18-Dec-2014 Yabin Cui <yabinc@google.com> Fix possible leak in pthread_detach.

If pthread_detach() is called while the thread is in pthread_exit(),
it takes the risk that no one can free the pthread_internal_t.
So I add PTHREAD_ATTR_FLAG_ZOMBIE to detect this, maybe very rare, but
both glibc and netbsd libpthread have similar function.

Change-Id: Iaa15f651903b8ca07aaa7bd4de46ff14a2f93835
917d390510e442b9b030d54992ebf41cc1e7f853 08-Jan-2015 Yabin Cui <yabinc@google.com> Make pthread stack size match real range.

Bug: 18908062
Change-Id: I7037ac8273ebe54dd19b1561c7a376819049124c
6a7aaf46759db32c6ed0eb953a4a230dc96af0d9 23-Dec-2014 Yabin Cui <yabinc@google.com> Reserve enough user request stack space in pthread_create.

Bug: 18830897
Change-Id: I1ba4aaeaf66a7ff99c5d82ad45469011171b0a3b
6c238f2926e69a950f0671ae5519584c20d84196 12-Dec-2014 Yabin Cui <yabinc@google.com> Fix pthread key num calculation.

Bug: 18723085
Change-Id: Iba2c834b350e4cdba0b2d771b221560a3e5df952
634816055f51c536d24dea30dfe930b7fe2fa603 02-Dec-2014 Yabin Cui <yabinc@google.com> support _POSIX_REALTIME_SIGNALS

Bug: 18489947
Change-Id: I2e834d68bc10ca5fc7ebde047b517a3074179475
0864d8bc47d57a3e63c1444dad1e263dd310d64f 21-Nov-2014 Dmitriy Ivanov <dimitry@google.com> Rename test_forked -> test_isolated

Change-Id: Ie72627e986c159832cbd3635d8ff5b1af3d5b1eb
00e37818a704fdd3d5f6a59022eff3a29b03bcce 21-Nov-2014 Dmitriy Ivanov <dimitry@google.com> Add test_forked() option

Executing test via test_forked() allows us to
avoid undesired global state changes in tests like
atexit, dlopen(.., RTLD_NODELETE) and similar.

Change-Id: I118cdf009269ab5dd7b117c9b61dafa47de2a011
68d98d832b7935ed5be23836c481a14f00b19ef1 13-Nov-2014 Elliott Hughes <enh@google.com> Assume glibc >= 2.15.

This catches one trivial difference between us and glibc --- the error
returned by pthread_setname_np for an invalid pthread_t.

Change-Id: If4c21e22107c6488333d11184f8005f8669096c2
9df70403d95f5cfe6824e38a9a6c35f9b9bbc76a 06-Nov-2014 Yabin Cui <yabinc@google.com> make all bionic death tests not dumpable

Bug: 18067305

Change-Id: Ia1ecacf47eddecc9bc58aaac779e0c218f463179
ed29e858d09906bc28e79d919af1d09f0538a464 27-Oct-2014 Elliott Hughes <enh@google.com> pthread_setname_np appears in glibc 2.12.

And our emulator kernels are now new enough to not require a workaround.

Change-Id: Id56c983dbfd8abc69f72a78411a5502391941dfc
4199695657e9500db14ab40392e3715db1826002 25-Sep-2014 Derek Xue <derek.xue@linaro.org> bionic tests: migrate test for mutex type from system/extras

Migrate the test about pthread mutex type in file
system/extras/tests/bionic/libc/bionic/test_mutex.c
to the new place
bionic/tests/pthread_test.cpp
in the gtest format.

Change-Id: I6aab10170ccad5b9a4892d52dba2403876c86659
Signed-off-by: Yongqin Liu <yongqin.liu@linaro.org>
ef1306d77718cc74a8df5673a15649dea317571d 09-Sep-2014 Dmitriy Ivanov <dimitry@google.com> Refactoring: C++11 style DISABLE_ bionic marcos

Enable the -std=gnu++11 flag for libstdc++ static and
dynamic libs.

ScopeGuard uses DISABLE_ macros instead of '= delete';

(cherry picked from commit d9ff7226613014056c9edd79a68dc5af939107a0)

Change-Id: If2573d080770e18b36b56106f2369f7bb682cd3c
c4bcc75f094206f3a6af767a5f6033ad44253b70 30-Sep-2014 Dan Albert <danalbert@google.com> Clean up the pthread key tests.

The previous pthread_key_create_many test was really
pthread_key_create_all, which has proven very difficult to test
correctly (because it is affected by any other parts of the system using
pthread keys, and that can vary with test ordering). It also tested
expected values of PTHREAD_KEYS_MAX and the associated sysconf() value,
rather than those being in their own test.

Instead, split this test into a few distinct tests:

* pthread.pthread_keys_max
* pthread._SC_THREAD_KEYS_MAX_big_enough_for_POSIX
* pthread.pthread_key_many_distinct
* We actually didn't have a test to ensure that the keys we were
creating were distinct.
* pthread.pthread_key_EAGAIN
* Make sure pthread_key_create() will _eventually_ fail with
EAGAIN, not at a (sometimes incorrectly) predetermined maximum.

Change-Id: Iff1e4fdcc02404094bde0418122c64c227cf1702
34c987a6dd6816eff98bc25f627659550c2338dc 23-Sep-2014 Elliott Hughes <enh@google.com> Test pthread_cleanup_push(3)/pthread_cleanup_pop(3).

Change-Id: I5a623fa1e1da55f11d51f3a9bdfa0627698c486f
8fb639ca9118a6522723d0bc09db59b432a803a9 12-Sep-2014 Elliott Hughes <enh@google.com> Add a test for pthread_gettid_np.

Bug: 17475191
Change-Id: I8c6a2f4ceba2d24a77ae9a21269edce523aea421
d9ff7226613014056c9edd79a68dc5af939107a0 09-Sep-2014 Dmitriy Ivanov <dimitry@google.com> Refactoring: C++11 style DISABLE_ bionic marcos

Enable the -std=gnu++11 flag for libstdc++ static and
dynamic libs.

ScopeGuard uses DISABLE_ macros instead of '= delete';

Change-Id: I07e21b306f95fffd49345f7fa136cfdac61e0225
5beddb7d642524ecb6655ab2823caf2add679917 05-Sep-2014 Elliott Hughes <enh@google.com> Fix pthread_attr_getstack__main_thread.

There were two problems here:

* This would fail when run with unlimited stack, because it didn't know
that bionic reports unlimited stacks as 8MiB.

* This would leave RLIMIT_STACK small, causing failures to exec (so the
popen and system tests would fail).

(cherry-pick of 27a9aed81978af792cb06035a1619c8141a5fb5b plus the
new ScopeGuard.h from a3ad450a2e3fb6b3fe359683b247eba20896f646.)

Bug: 17394276
Change-Id: I5b92dc64ca089400223b2d9a3743e9b9d57c1bc2
27a9aed81978af792cb06035a1619c8141a5fb5b 05-Sep-2014 Elliott Hughes <enh@google.com> Fix pthread_attr_getstack__main_thread.

There were two problems here:

* This would fail when run with unlimited stack, because it didn't know
that bionic reports unlimited stacks as 8MiB.

* This would leave RLIMIT_STACK small, causing failures to exec (so the
popen and system tests would fail).

Change-Id: I5b92dc64ca089400223b2d9a3743e9b9d57c1bc2
1d53ae2a01df5c85d23b01e44880103e118712f3 03-Sep-2014 Dan Albert <danalbert@google.com> Prevent a few test pthread keys from leaking.

Bug: 17358010
Change-Id: Ie718dc215ddfd431650295a1630c1b1716760c3d
67f1f3b171ecd5f68f51465bbe4b8c8440bb6b2e 28-Aug-2014 Elliott Hughes <enh@google.com> Have pthread_attr_getstack for the main thread report RLIMIT_STACK...

...rather than just what's already mapped in. This seems somewhat
contrary to POSIX's "All pages within the stack described by stackaddr
and stacksize shall be both readable and writable by the thread", but
it's what glibc does.

Bug: 17111575

(cherry picked from commit 9e4ffa7032eaab308876b8e3da86b05c3c613878)

Change-Id: I73f219a569917b2e4546c09436d7ef5231facc07
9e4ffa7032eaab308876b8e3da86b05c3c613878 28-Aug-2014 Elliott Hughes <enh@google.com> Have pthread_attr_getstack for the main thread report RLIMIT_STACK...

...rather than just what's already mapped in. This seems somewhat
contrary to POSIX's "All pages within the stack described by stackaddr
and stacksize shall be both readable and writable by the thread", but
it's what glibc does.

Bug: 17111575
Change-Id: If9e2dfad9a603c0d0615a8123aacda4946e95b2c
642182341018b282148280a7bdb771493e15bd7d 26-Aug-2014 Elliott Hughes <enh@google.com> Fix pthread_getattr_np for the main thread.

On most architectures the kernel subtracts a random offset to the stack
pointer in create_elf_tables by calling arch_align_stack before writing
the auxval table and so on. On all but x86 this doesn't cause a problem
because the random offset is less than a page, but on x86 it's up to two
pages. This means that our old technique of rounding the stack pointer
doesn't work. (Our old implementation of that technique was wrong too.)

It's also incorrect to assume that the main thread's stack base and size
are constant. Likewise to assume that the main thread has a guard page.
The main thread is not like other threads.

This patch switches to reading /proc/self/maps (and checking RLIMIT_STACK)
whenever we're asked.

Bug: 17111575
Signed-off-by: Fengwei Yin <fengwei.yin@intel.com>

(cherry picked from commit 57b7a6110e7e8b446fc23cce4765ff625ee0a105)

Change-Id: I87e679ee1c0db8092f2d1221c8e7c1461545c5a4
57b7a6110e7e8b446fc23cce4765ff625ee0a105 26-Aug-2014 Elliott Hughes <enh@google.com> Fix pthread_getattr_np for the main thread.

On most architectures the kernel subtracts a random offset to the stack
pointer in create_elf_tables by calling arch_align_stack before writing
the auxval table and so on. On all but x86 this doesn't cause a problem
because the random offset is less than a page, but on x86 it's up to two
pages. This means that our old technique of rounding the stack pointer
doesn't work. (Our old implementation of that technique was wrong too.)

It's also incorrect to assume that the main thread's stack base and size
are constant. Likewise to assume that the main thread has a guard page.
The main thread is not like other threads.

This patch switches to reading /proc/self/maps (and checking RLIMIT_STACK)
whenever we're asked.

Bug: 17111575
Signed-off-by: Fengwei Yin <fengwei.yin@intel.com>
Change-Id: I1d4dbffe7bc7bda1d353c3a295dbf68d29f63158
18d93f2793fad393b6aa6eae6afe1054958339d5 06-Aug-2014 Christopher Ferris <cferris@google.com> Do a second key cleanup in pthread_exit.

During pthread_exit, the keys are cleaned. Unfortunately, a call to
free occurs after the cleanup and the memory for some of the keys
is recreated when using jemalloc. The solution is to do the key
cleanup twice.

Also, modify the pthread_detach__leak test to be less flaky
when run on a jemalloc system.

Bug: 16513133
Change-Id: Ic17e8344bdc1ba053c4f5b6d827a4c19c57860c1
e380960813bbb6e05d820eb75885556a1c4bf6ac 06-Aug-2014 Christopher Ferris <cferris@google.com> Do a second key cleanup in pthread_exit.

During pthread_exit, the keys are cleaned. Unfortunately, a call to
free occurs after the cleanup and the memory for some of the keys
is recreated when using jemalloc. The solution is to do the key
cleanup twice.

Also, modify the pthread_detach__leak test to be less flaky
when run on a jemalloc system.

Bug: 16513133

(cherry picked from commit 18d93f2793fad393b6aa6eae6afe1054958339d5)

Change-Id: Idb32e7f9b09e2c088d256ed9eb881df80c81ff8e
11bf8a3025a7b5aee891c521255a7db1860e5b12 30-Jul-2014 Elliott Hughes <enh@google.com> Only wipe TLS for user-supplied stacks.

Bug: 16667988

(cherry picked from commit 40a521744825b6060960c296d5fb3da4c6593d94)

Change-Id: I7550fa47b76e643323aa3e2a53529e393c829e47
40a521744825b6060960c296d5fb3da4c6593d94 30-Jul-2014 Elliott Hughes <enh@google.com> Only wipe TLS for user-supplied stacks.

Bug: 16667988
Change-Id: Id180ab2bc6713e1612386120a306db5bbf1d6046
ebb770f90d9a8d7f75a9d8b0e6a96ded96c617af 25-Jun-2014 Elliott Hughes <enh@google.com> Add a new pthread_key_delete test.

Bug: https://code.google.com/p/android/issues/detail?id=66813
Change-Id: Ida87bc1fb15a73a08c223a7099456d9f049cd3c5
92687e41bcf108957944dafa80a9bfda219bfb0f 22-May-2014 Calin Juravle <calin@google.com> Cleaned up pthread rwlocks implementation.

- used underscore_style_for_vars
- extracted time related functionality into a function
- cleaned up style
- removed unused fields from pthread_rwlock_t on LP64
- changed reservation in pthread_rwlock_t so that the size of the
structure equals glibc version

Bug: 8133149

Change-Id: I84ad3918678dc7f5e6b3db9b7e9b0899d3abe9cd
76f352eec12d8938101e5ae33429c72797c3aa23 19-May-2014 Calin Juravle <calin@google.com> Mutex-free implementation of pthread_rwlock

Bug: 8133149
Change-Id: Id6775010d95f2634b173daa55d87a59a3cf4131b
3694ec6c4b644064f7e00b898cd11e138e4f6c09 14-May-2014 Elliott Hughes <enh@google.com> Add a regression test for a long-fixed pthread_once bug.

Bug: 1934122
Change-Id: Iae09baedc2c6ed4036521e51718fe9d015bc56b9
1728b2396591853345507a063ed6075dfd251706 14-May-2014 Elliott Hughes <enh@google.com> Switch to g_ for globals.

That's what the Google style guide recommends, and we're starting
to get a mix.

Change-Id: Ib0c53a890bb5deed5c679e887541a715faea91fc
954cf0d4e2669f91194b45f484152e47efa4f6c7 09-May-2014 Elliott Hughes <enh@google.com> Hide the __bionic_clone and __bionic_clone_entry implementation details.

clone(2) is the public symbol.

Also switch a test from __bionic_clone to clone; testing public API
means the test now works on glibc too.

Change-Id: If59def26a00c3afadb8a6cf9442094c35a59ffde
04620a3cd7bdea0d1b421c8772ba3f06839bbe9c 08-Mar-2014 Elliott Hughes <enh@google.com> Fix pthread_detach for already-exited threads.

Change-Id: I2bf7f41234d93b226132a4c51705f4186f4961c3
Reported-by: Paresh Nakhe <pnakhe@codeaurora.org>
4b558f50a42c97d461f1dede5aaaae490ea99e2e 05-Mar-2014 Elliott Hughes <enh@google.com> Rewrite the POSIX timer functions.

This is a much simpler implementation that lets the kernel
do as much as possible.

Co-authored-by: Jörgen Strand <jorgen.strand@sonymobile.com>
Co-authored-by: Snild Dolkow <snild.dolkow@sonymobile.com>
Change-Id: Iad19f155de977667aea09410266d54e63e8a26bf
0e714a5b41451e84c5ded93a42c9a4b0a9440691 04-Mar-2014 Elliott Hughes <enh@google.com> Implement POSIX pthread_mutex_timedlock.

This replaces the non-standard pthread_mutex_lock_timeout_np, which we have
to keep around on LP32 for binary compatibility.

Change-Id: I098dc7cd38369f0c1bec1fac35687fbd27392e00
51e6cb33e3d7c2f44864d356a2a8e66317688f55 03-Mar-2014 Narayan Kamath <narayan@google.com> Implement pthread_condattr_{get,set}clock.

We only support CLOCK_REALTIME and CLOCK_MONOTONIC for now,
so we us a single bit from pthread_cond_t->value to denote
the clock type. Note that this reduces the width of the counter
to 30 bits, but this should be large enough for all practical
purposes.

bug: 13232338

Change-Id: I857e7da64b3ecbb23eeac7c9f3fbd460f60231bd
f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6d 21-Dec-2013 Christopher Ferris <cferris@google.com> Make sure that the same tests are on all platforms.

In order to be able to generate a list of tests for cts, the same set of
tests must exist across all platforms. This CL adds empty tests where a
test was conditionally compiled out.

This CL creates a single library libBionicTests that includes all of
the tests found in bionic-unit-tests-static.

Also fix a few missing include files in some test files.

Tested by running and compiling the tests for every platform and
verifying the same number of tests are on each platform.

Change-Id: I9989d4bfebb0f9c409a0ce7e87169299eac605a2
718a5b5495ae7726aabd2f8a748da9f391d12b98 29-Jan-2014 Elliott Hughes <enh@google.com> Fix pthread_test to work with gtest 1.7.0.

Now we're building it correctly configured, gtest takes a couple of
TLS slots for itself.

Change-Id: I1c2c4e9e5f9c6e2e2e6ecd1214cfc16a5af5afed
dd00364807020a244aa8be4f3481f7ec0fefcc79 04-Jan-2014 Chris Dearman <chris.dearman@imgtec.com> Pass a valid stack pointer to __bionic_clone in pthread.__bionic_clone

__bionic_clone modifies the child stack before cloning so the stack
pointer should be valid. The test is expecting an EINVAL error to be
generated from the incorrect flags: CLONE_THREAD set without
CLONE_SIGHAND.

Change-Id: Ic02192081f6f52df6f03d9810efa82d923247a11
1887621de8a48eece8a05f2400ddd783b9833147 12-Dec-2013 Elliott Hughes <enh@google.com> PTHREAD_KEYS_MAX cleanup.

I fixed this bug a while back, but didn't remove it from the list,
could have added a better test, and could have written clearer code
that didn't require a comment.

Change-Id: Iebdf0f9a54537a7d5cbca254a5967b1543061f3d
877ec6d90418ff1d6597147d355a2229fdffae7e 16-Nov-2013 Elliott Hughes <enh@google.com> 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
70b24b1cc2a1a4436b1fea3f8b76616fdcb27224 15-Nov-2013 Elliott Hughes <enh@google.com> Switch pthread_create over to __bionic_clone.

Bug: 8206355
Bug: 11693195
Change-Id: I04aadbc36c87e1b7e33324b9a930a1e441fbfed6
c3f114037dbf028896310609fd28cf2b3da99c4d 30-Oct-2013 Elliott Hughes <enh@google.com> <pthread.h> fixes and pthread cleanup.

<pthread.h> was missing nonnull attributes, noreturn on pthread_exit,
and had incorrect cv qualifiers for several standard functions.

I've also marked the non-standard stuff (where I count glibc rather
than POSIX as "standard") so we can revisit this cruft for LP64 and
try to ensure we're compatible with glibc.

I've also broken out the pthread_cond* functions into a new file.

I've made the remaining pthread files (plus ptrace) part of the bionic code
and fixed all the warnings.

I've added a few more smoke tests for chunks of untested pthread functionality.

We no longer need the libc_static_common_src_files hack for any of the
pthread implementation because we long since stripped out the rest of
the armv5 support, and this hack was just to ensure that __get_tls in libc.a
went via the kernel if necessary.

This patch also finishes the job of breaking up the pthread.c monolith, and
adds a handful of new tests.

Change-Id: Idc0ae7f5d8aa65989598acd4c01a874fe21582c7
c7e9b2331771e5e87c34a8ee3dc6cc41d35b02fe 17-Oct-2013 Elliott Hughes <enh@google.com> Fix sigaction(3) for 64-bit.

Also clean up <signal.h> and revert the hacks that were necessary
for 64-bit in linker/debugger.cpp until now.

Change-Id: I3b0554ca8a49ee1c97cda086ce2c1954ebc11892
19e62325c268a668692e2b65fde2284079f369aa 15-Oct-2013 Elliott Hughes <enh@google.com> Clean up the sigprocmask/pthread_sigmask implementation.

Let's have both use rt_sigprocmask, like in glibc. The 64-bit ABIs
can share the same code as the 32-bit ABIs.

Also, let's test the return side of these calls, not just the
setting.

Bug: 11069919
Change-Id: I11da99f85b5b481870943c520d05ec929b15eddb
5b9310e502003e584bcb3a028ca3db7aa4d3f01b 03-Oct-2013 Elliott Hughes <enh@google.com> Fix 32-bit issues in tests, and add a trivial test for the FD_* macros.

Change-Id: Ia3f21ce1f0ed9236527fe44d36ccb7de6bf63113
e9e10c13ff3fdb7104aafd0707b2c851851c9d1f 15-Aug-2013 Jeff Hao <jeffhao@google.com> Fix pthread_getcpuclockid.

clock_gettime was returning EINVAL for the values
produced by pthread_getcpuclockid.

Bug: 10346183

(cherry picked from commit 9b06cc3c1b2c4e2b08582f3fc9393a05aa589766)

Change-Id: Ib81a7024c218a4502f256c3002b9030e2aaa278d
9b06cc3c1b2c4e2b08582f3fc9393a05aa589766 15-Aug-2013 Jeff Hao <jeffhao@google.com> Fix pthread_getcpuclockid.

clock_gettime was returning EINVAL for the values
produced by pthread_getcpuclockid.

Bug: 10346183
Change-Id: Iabe643d7d46110bb311a0367aa0fc737f653208e
b95cf0d23a1db3b7c37bd98b0c86196796c9b029 15-Jul-2013 Elliott Hughes <enh@google.com> Fix pthread_getattr_np, pthread_attr_setguardsize, and pthread_attr_setstacksize.

pthread_getattr_np was reporting the values supplied to us, not the values we
actually used, which is kinda the whole point of pthread_getattr_np.

pthread_attr_setguardsize and pthread_attr_setstacksize were reporting EINVAL
for any size that wasn't a multiple of the system page size. This is
unnecessary. We can just round like POSIX suggests and glibc already does.

Also improve the error reporting for pthread_create failures.

Change-Id: I7ebc518628a8a1161ec72e111def911d500bba71
0f020d18b138e24b1fe34074808e07ac412f35a4 06-Jun-2013 msg555 <msg555@gmail.com> Handles spurious wake-ups in pthread_join()

Removed 'join_count' from pthread_internal_t and switched to using the flag
PTHREAD_ATTR_FLAG_JOINED to indicate if a thread is being joined. Combined with
a switch to a while loop in pthread_join, this fixes spurious wake-ups but
prevents a thread from being joined multiple times. This is fine for
two reasons:

1) The pthread_join specification allows for undefined behavior when multiple
threads try to join a single thread.

2) There is no thread safe way to allow multiple threads to join a single
thread with the pthread interface. The second thread calling pthread_join
could be pre-empted until the thread is destroyed and its handle reused for
a different thread. Therefore multi-join is always an error.

Bug: https://code.google.com/p/android/issues/detail?id=52255
Change-Id: I8b6784d47620ffdcdbfb14524e7402e21d46c5f7
a41ba2f0bfc4fce1ce8f06a9c289102c440c929d 22-Mar-2013 Elliott Hughes <enh@google.com> Fix pthread_setname_np's behavior on invalid pthread_ts.

Change-Id: I0a154beaab4d164ac812f2564d12e4d79b80a8e8
fae89fc4042ee4c360842234dfda7831c313bd44 21-Feb-2013 Elliott Hughes <enh@google.com> Fix raise(3) so it works in signal handlers.

We could special-case raise(3) in non-threaded programs, but the more
conservative course is to make pthread_kill(3) work in signal handlers
at the cost of a race shared by other C libraries.

Change-Id: I59fb23d03bdabf403435e731704b33acdf3e0234
9d23e04c43dbb8480bea8be28b8a2f37423bec49 16-Feb-2013 Elliott Hughes <enh@google.com> Fix pthreads functions that should return ESRCH.

imgtec pointed out that pthread_kill(3) was broken, but most of the
other functions that ought to return ESRCH for invalid/exited threads
were equally broken.

Change-Id: I96347f6195549aee0c72dc39063e6c5d06d2e01f
40eabe24e4e3ae8ebe437f1f4e43cf39cbba2e9e 15-Feb-2013 Elliott Hughes <enh@google.com> Fix the pthread_setname_np test.

Fix the pthread_setname_np test to take into account that emulator kernels are
so old that they don't support setting the name of other threads.

The CLONE_DETACHED thread is obsolete since 2.5 kernels.

Rename kernel_id to tid.

Fix the signature of __pthread_clone.

Clean up the clone and pthread_setname_np implementations slightly.

Change-Id: I16c2ff8845b67530544bbda9aa6618058603066d
7fd803cdfa873c01138dcbd614ec92418169b1c2 15-Feb-2013 Elliott Hughes <enh@google.com> Fix the stack protector death test.

Now __stack_chk_fail calls abort(3) directly, we terminate with
SIGSEGV rather than SIGABRT. (Because of the workaround for the
debuggerd lossage in the abort(3) implementation, which was the
motivation for switching __stack_chk_fail over to abort(3).)

Also clarify the comment on the weird pthread death test, so it
doesn't get copied and pasted onto real death tests.

Change-Id: Ie832eaded61359c99e7a10db65e28f35e8f63eed
9701d4b7018ea50f57601eaec5f8f6731a7c6510 13-Feb-2013 Elliott Hughes <enh@google.com> Give up trying to build the pthread_setname_np tests for glibc.

Looks like using /usr/bin/g++ isn't enough on some of our older
build servers.

Change-Id: Id7681fb164eb6324b10050f6bb237393e95b41e9
3e898476c7230b60a0f76968e64ff25f475b48c0 12-Feb-2013 Elliott Hughes <enh@google.com> Revert "Revert "More pthreads cleanup.""

This reverts commit 6f94de3ca49e4ea147b1c59e5818fa175846518f

(Doesn't try to increase the number of TLS slots; that leads to
an inability to boot. Adds more tests.)

Change-Id: Ia7d25ba3995219ed6e686463dbba80c95cc831ca
6f94de3ca49e4ea147b1c59e5818fa175846518f 12-Feb-2013 Elliott Hughes <enh@google.com> Revert "More pthreads cleanup."

This reverts commit 2a1bb4e64677b9abbc17173c79768ed494565047

Change-Id: Ia443d0748015c8e9fc3121e40e68258616767b51
5e3fc43ddeada547a155c6f561a12ff0b16e02d3 12-Feb-2013 Elliott Hughes <enh@google.com> Fix __pthread_clone on ARM to set errno on failure.

MIPS and x86 appear to have been correct already.

(Also fix unit tests that ASSERT_EQ with errno so that the
arguments are in the retarded junit order.)

Bug: 3461078
Change-Id: I2418ea98927b56e15b4ba9cfec97f5e7094c6291
2a1bb4e64677b9abbc17173c79768ed494565047 11-Feb-2013 Elliott Hughes <enh@google.com> More pthreads cleanup.

POSIX says pthread_create returns EAGAIN, not ENOMEM.

Also pull pthread_attr_t functions into their own file.

Also pull pthread_setname_np into its own file.

Also remove unnecessary #includes from pthread_key.cpp.

Also account for those pthread keys used internally by bionic,
so they don't count against the number of keys available to user
code. (They do with glibc, but glibc's limit is the much more
generous 1024.)

Also factor out the common errno-restoring idiom to reduce gotos.

Bug: 6702535
Change-Id: I555e66efffcf2c1b5a2873569e91489156efca42
44b53ad6818de344e0b499ad8fdbb21fcb0ff2b6 11-Feb-2013 Elliott Hughes <enh@google.com> Revert "Revert "Pull the pthread_key_t functions out of pthread.c.""

This reverts commit 6260553d48f6fd87ca220270bea8bafdde5726ec

(Removing the accidental libm/Android.mk change.)

Change-Id: I6cddd9857c31facc05636e8221505b3d2344cb75
6260553d48f6fd87ca220270bea8bafdde5726ec 11-Feb-2013 Elliott Hughes <enh@google.com> Revert "Pull the pthread_key_t functions out of pthread.c."

This reverts commit ad59322ae432d11ff36dcf046016af8cfe45fbe4

somehow my unfinished libm/Android.mk change got into here.

Change-Id: I46be626c5269d60fb1ced9862f2ebaa380b4e0af
ad59322ae432d11ff36dcf046016af8cfe45fbe4 09-Feb-2013 Elliott Hughes <enh@google.com> Pull the pthread_key_t functions out of pthread.c.

This was originally motivated by noticing that we were setting the
wrong bits for the well-known tls entries. That was a harmless bug
because none of the well-known tls entries has a destructor, but
it's best not to leave land mines lying around.

Also add some missing POSIX constants, a new test, and fix
pthread_key_create's return value when we hit the limit.

Change-Id: Ife26ea2f4b40865308e8410ec803b20bcc3e0ed1
c5d028fc913de84a781bd61084bf7ae2182fd48e 10-Jan-2013 Elliott Hughes <enh@google.com> Only have one copy of the kernel_sigset_t hack, and add more tests.

Change-Id: I377522fcba6fb4b5fd2754ab15b091014bd7c16f
4f251bee5d51228217c1bf4dfc9219f3058bd3ed 02-Nov-2012 Elliott Hughes <enh@google.com> Don't corrupt the thread list if the main thread exits.

...and don't pass a non-heap pointer to free(3), either.

This patch replaces the "node** prev" with the clearer "node* prev"
style and fixes the null pointer dereference in the old code. That's
not sufficient to fix the reporter's bug, though. The pthread_internal_t*
for the main thread isn't heap-allocated --- __libc_init_tls causes a
pointer to a statically-allocated pthread_internal_t to be added to
the thread list.

Bug: http://code.google.com/p/android/issues/detail?id=37410
Change-Id: I112b7f22782fc789d58f9c783f7b323bda8fb8b7
10ce96944eaea4c459392952652fdb24742c9c29 26-Oct-2012 Sergey Melnikov <sergey.melnikov@intel.com> Fix bug in pthread_join, pthread_exit, pthread_detach

pthread_no_op_detach_after_join test from bionic-unit-tests hangs
on x86 emulator. There is a race in the pthread_join, pthread_exit,
pthread_detach functions:
- pthread_join waits for the non-detached thread
- pthread_detach sets the detached flag on that thread
- the thread executes pthread_exit which just kills the now-detached
thread, without sending the join notification.

This patch improves the test so it fails on ARM too, and modifies
pthread_detach to behave more like glibc, not setting the detach state if
called on a thread that's already being joined (but not returning an error).

Change-Id: I87dc688221ce979ef5178753dd63d01ac0b108e6
Signed-off-by: Sergey Melnikov <sergey.melnikov@intel.com>
14f19592ae7c819855052bcebc79de87069c2954 29-Oct-2012 Elliott Hughes <enh@google.com> Fix the pthread_join on self error case.

We should return EDEADLK, not deadlock the calling thread.

Change-Id: I1243483f709c11b2a60e41142725c54c7dbfcbc9
4d014e15b44d3e8d1b0189bc9bb7b0d0685e5af8 08-Sep-2012 Elliott Hughes <enh@google.com> Add more pthreads tests.

Someone reported a bug if pthread_detach is called while a pthread_join is
already in progress, but I'm unable to reproduce it. Keep the tests I wrote,
though.

Change-Id: I3d71450bbbb5345f2cb213dc56310ec020d528cc
bfeab1bbe7e8d0c08b7e3f46aedab64e3b2bf706 06-Sep-2012 Elliott Hughes <enh@google.com> Don't corrupt the thread list in static executables.

Several previous changes conspired to make a mess of the thread list
in static binaries. This was most obvious when trying to call
pthread_key_delete(3) on the main thread.

Bug: http://code.google.com/p/android/issues/detail?id=36893
Change-Id: I2a2f553114d8fb40533c481252b410c10656da2e