Commit graph

102 commits

Author SHA1 Message Date
Elliott Hughes
c3f114037d <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
2013-10-31 12:31:16 -07:00
Elliott Hughes
2b6e43e00e Explain the sigprocmask in pthread_exit.
Also remove the SIGSEGV special case, which was probably because
hand-written __exit_with_stack_teardown stubs used to try to cause
SIGSEGV if the exit system call returned (which it never does, so
that dead code disappeared).

Also move the sigprocmask into the only case where it's necessary ---
the one where we unmap the stack that would be used by a signal
handler.

Change-Id: Ie40d20c1ae2f5e7125131b6b492cba7a2c6d08e9
2013-10-29 16:11:06 -07:00
Elliott Hughes
6b53c2349a Fix the exit syscall stub's name.
I've left the exit_group syscall as _exit because otherwise we'd have to
convince the compiler that our _exit (which just calls __exit_group) is
actually "noreturn", and it seems like that would be less clean than just
cutting out the middleman.

We'll just have to trust ourselves not to add anything to SYSCALLS.TXT
that ought to be private but that only has a single leading underscore.
Hopefully we can manage that.

Change-Id: Iac47faea9f516186e1774381846c54cafabc4354
2013-10-24 22:41:50 -07:00
Elliott Hughes
11952073af Remove dependencies on obsolete __ARCH_WANT_SYSCALL_DEPRECATED system calls.
(aarch64 kernels don't have these system calls.)

Change-Id: I6f64075aa412f71520f2df71c3d69b647f91c1ca
2013-10-24 15:48:32 -07:00
Serban Constantinescu
7f70c9b64e AArch64: Fix uses of stack size for 32/64bit libc builds
This patch fixes stack size uses to size_t.

Change-Id: I0671c85ddb1c1aceaf9440a7c73c21fe528653fa
Signed-off-by: Serban Constantinescu <serban.constantinescu@arm.com>
2013-10-22 12:01:29 -07:00
Elliott Hughes
eb847bc866 Fix x86_64 build, clean up intermediate libraries.
The x86_64 build was failing because clone.S had a call to __thread_entry which
was being added to a different intermediate .a on the way to making libc.so,
and the linker couldn't guarantee statically that such a relocation would be
possible.

  ld: error: out/target/product/generic_x86_64/obj/STATIC_LIBRARIES/libc_common_intermediates/libc_common.a(clone.o): requires dynamic R_X86_64_PC32 reloc against '__thread_entry' which may overflow at runtime; recompile with -fPIC

This patch addresses that by ensuring that the caller and callee end up in the
same intermediate .a. While I'm here, I've tried to clean up some of the mess
that led to this situation too. In particular, this removes libc/private/ from
the default include path (except for the DNS code), and splits out the DNS
code into its own library (since it's a weird special case of upstream NetBSD
code that's diverged so heavily it's unlikely ever to get back in sync).

There's more cleanup of the DNS situation possible, but this is definitely a
step in the right direction, and it's more than enough to get x86_64 building
cleanly.

Change-Id: I00425a7245b7a2573df16cc38798187d0729e7c4
2013-10-09 16:00:17 -07:00
Elliott Hughes
c4c6e192ac pthread_exit should call __NR_exit with status 0.
We shouldn't have been passing the bottom 32 bits of the address used
for pthread_join to the kernel.

Change-Id: I487e5002d60c27adba51173719213abbee0f183f
2013-10-08 14:48:05 -07:00
Elliott Hughes
a97cc5b458 Clean up the x86 and x86_64 _exit_with_stack_teardown implementations.
Change-Id: I4bcbbc53893612bd94643ef07722becb00f91792
2013-10-07 10:25:11 -07:00
Elliott Hughes
84114c8dd5 Improve stack overflow diagnostics (take 2).
This reverts commits eb1b07469f and
d14dc3b87f, and fixes the bug where
we were calling mmap (which might cause errno to be set) before
__set_tls (which is required to implement errno).

Bug: 8557703
Change-Id: I2c36d00240c56e156e1bb430d8c22a73a068b70c
2013-07-17 13:33:19 -07:00
Guang Zhu
eb1b07469f Revert "Clean up our alternate signal stacks."
This reverts commit 5cf87951ab.

Change-Id: Idd6ca7d80a018755da3bd315d91193723ce7f3bf
2013-07-17 03:16:04 +00:00
Elliott Hughes
5cf87951ab Clean up our alternate signal stacks.
Bug: 8557703
Change-Id: Ie93901dd1c29e9d3bf795b0f0400616d9ef08f75
2013-07-16 14:35:52 -07:00
Elliott Hughes
d4e753fea9 Clean up __builtin_expect usage.
Also remove some dead code; our malloc debugging doesn't use this
any more.

Change-Id: Id69cf182371f5f37d40b5bbd08f2744ade286e66
2013-07-16 12:45:46 -07:00
msg555
0f020d18b1 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
2013-06-12 17:30:58 -07:00
Elliott Hughes
9d23e04c43 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
2013-02-19 12:21:41 -08:00
Elliott Hughes
40eabe24e4 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
2013-02-15 12:08:59 -08:00
Elliott Hughes
fb7eb5e07f Simplify __stack_chk_fail, and fix it so we get debuggerd stack traces.
Bug: 2487269
Change-Id: Iec5e470fc22cd9108404f634a9d4baa2c7b7f58f
2013-02-14 14:37:34 -08:00
Elliott Hughes
4b4a882428 Clean up pthread_create.
Bug: 3461078
Change-Id: I082122a86d7692cd58f4145539241be026258ee0
2013-02-12 17:15:59 -08:00
Elliott Hughes
6d33918207 Simplify pthread_create, using more public API.
Change-Id: I08e65ba88ed01436223e4e528631c9e41ec0e7f4
2013-02-12 16:36:04 -08:00
Elliott Hughes
3e898476c7 Revert "Revert "More pthreads cleanup.""
This reverts commit 6f94de3ca4

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

Change-Id: Ia7d25ba3995219ed6e686463dbba80c95cc831ca
2013-02-12 15:27:18 -08:00
Elliott Hughes
6f94de3ca4 Revert "More pthreads cleanup."
This reverts commit 2a1bb4e646

Change-Id: Ia443d0748015c8e9fc3121e40e68258616767b51
2013-02-12 06:06:22 +00:00
Elliott Hughes
2a1bb4e646 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
2013-02-11 14:56:39 -08:00
Elliott Hughes
44b53ad681 Revert "Revert "Pull the pthread_key_t functions out of pthread.c.""
This reverts commit 6260553d48

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

Change-Id: I6cddd9857c31facc05636e8221505b3d2344cb75
2013-02-11 12:20:33 -08:00
Elliott Hughes
6260553d48 Revert "Pull the pthread_key_t functions out of pthread.c."
This reverts commit ad59322ae4

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

Change-Id: I46be626c5269d60fb1ced9862f2ebaa380b4e0af
2013-02-11 20:18:16 +00:00
Elliott Hughes
ad59322ae4 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
2013-02-11 12:00:48 -08:00
Elliott Hughes
d3920b3a99 Switch to using AT_RANDOM for the stack guards.
Bug: 7959813
Change-Id: I8db4b8912ba649bfe668c6f22aa44690ddd401a2
2013-02-08 11:16:13 -08:00
Elliott Hughes
1e980b6bc8 Fix the duplication in the debugging code.
We had two copies of the backtrace code, and two copies of the
libcorkscrew /proc/pid/maps code. This patch gets us down to one.

We also had hacks so we could log in the malloc debugging code.
This patch pulls the non-allocating "printf" code out of the
dynamic linker so everyone can share.

This patch also makes the leak diagnostics easier to read, and
makes it possible to paste them directly into the 'stack' tool (by
using relative PCs).

This patch also fixes the stdio standard stream leak that was
causing a leak warning every time tf_daemon ran.

Bug: 7291287
Change-Id: I66e4083ac2c5606c8d2737cb45c8ac8a32c7cfe8
2013-01-18 22:20:06 -08:00
Wink Saville
a12c54454f Fix unused warnings in pthread.c
Change-Id: I0287aadb825fd8cda29dc976bce55d75a1279fc5
2013-01-10 16:30:22 -08:00
Elliott Hughes
c5d028fc91 Only have one copy of the kernel_sigset_t hack, and add more tests.
Change-Id: I377522fcba6fb4b5fd2754ab15b091014bd7c16f
2013-01-10 14:42:14 -08:00
Elliott Hughes
4a9e837840 Reduce the exposure of the __set_errno implementation detail.
Change-Id: I395e1b46a9491e34fc53e71853e932ea90b3d1cc
2012-11-30 12:05:18 -08:00
Elliott Hughes
4f251bee5d 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
2012-11-01 17:27:07 -07:00
Sergey Melnikov
10ce96944e 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>
2012-10-29 11:31:26 -07:00
Elliott Hughes
14f19592ae Fix the pthread_join on self error case.
We should return EDEADLK, not deadlock the calling thread.

Change-Id: I1243483f709c11b2a60e41142725c54c7dbfcbc9
2012-10-29 10:19:44 -07:00
Xi Wang
ae8eb74675 Fix a potential NULL pointer dereference in _init_thread().
The first NULL pointer check against `attr' suggests that `attr' can
be NULL.  Then later `attr' is directly dereferenced, suggesting the
opposite.

    if (attr == NULL) {
        ...
    } else {
        ...
    }
    ...
    if (attr->stack_base == ...) { ... }

The public API pthread_create(3) allows NULL, and interprets it as "default".
Our implementation actually swaps in a pointer to the global default
pthread_attr_t, so we don't need any NULL checks in _init_thread. (The other
internal caller passes its own pthread_attr_t.)

Change-Id: I0a4e79b83f5989249556a07eed1f2887e96c915e
Signed-off-by: Xi Wang <xi.wang@gmail.com>
2012-10-29 08:22:13 -07:00
Elliott Hughes
ad88a08631 Per-thread -fstack-protector guards for x86.
Based on a pair of patches from Intel:

  https://android-review.googlesource.com/#/c/43909/
  https://android-review.googlesource.com/#/c/44903/

For x86, this patch supports _both_ the global that ARM/MIPS use
and the per-thread TLS entry (%gs:20) that GCC uses by default. This
lets us support binaries built with any x86 toolchain (right now,
the NDK is emitting x86 code that uses the global).

I've also extended the original tests to cover ARM/MIPS too, and
be a little more thorough for x86.

Change-Id: I02f279a80c6b626aecad449771dec91df235ad01
2012-10-25 12:04:03 -07:00
Elliott Hughes
5419b94747 Make dlerror(3) thread-safe.
I gave up trying to use the usual thread-local buffer idiom; calls to
calloc(3) and free(3) from any of the "dl" functions -- which live in
the dynamic linker -- end up resolving to the dynamic linker's stubs.
I tried to work around that, but was just making things more complicated.
This alternative costs us a well-known TLS slot (instead of the
dynamically-allocated TLS slot we'd have used otherwise, so no difference
there), plus an extra buffer inside every pthread_internal_t.

Bug: 5404023
Change-Id: Ie9614edd05b6d1eeaf7bf9172792d616c6361767
2012-10-16 17:58:17 -07:00
Dave Burke
88f1ea8f82 Make pthread_create more forgiving of invalid sched_policy.
Bug: 7005326

(cherry-pick of e58303249b9e799a4fe84c5a2dfe71518441a6ec.)

Change-Id: Ie81494e0f6a71caa6fd9fabbcfc47a23077554d6
2012-09-18 16:55:24 -07:00
Elliott Hughes
bfeab1bbe7 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
2012-09-05 17:47:37 -07:00
Jurijs Oniscuks
2932f04832 Fix race condition in pthread_create()
Save thread id to *thread_out before new
thread is allowed to run else there's a
risk that the thread has finished and
been deleted when *thread_out is assigned.

Change-Id: I6b84c61a8df06840877d4ab036f26feace3192d8
2012-08-17 16:18:32 -07:00
Elliott Hughes
eab2889e66 am fd955033: Merge "pthread: Invalidate stale stack pointers on pthread_exit()"
* commit 'fd95503347acba5c52d669a186ad2b161338a8a7':
  pthread: Invalidate stale stack pointers on pthread_exit()
2012-05-09 12:53:16 -07:00
Bjorn Andersson
0753dc653e pthread: Invalidate stale stack pointers on pthread_exit()
A call to pthread_key_delete() after pthread_exit() have unmapped the stack of a thread
but before the ongoing pthread_join() have finished executing will result in an access
to unmapped memory.
Avoid this by invalidating the stack_base and tls pointers during pthread_exit().

This is based on the investigation and proprosed solution by
Srinavasa Nagaraju <srinavasa.x.nagaraju@sonyericsson.com>

Change-Id: I145fb5d57930e91b00f1609d7b2cd16a55d5b3a9
2012-05-08 17:43:57 -07:00
Elliott Hughes
9c3eca7bce resolved conflicts for merge of 6cf3c7c5 to jb-dev-plus-aosp
Change-Id: Ib22a8ae1ef63bf9b9c82ce6e22afd188ba7c2806
2012-05-08 13:26:28 -07:00
Pierre Peiffer
d0c884d359 Let pthread_create fail if schedparam can't be set
The creation of a thread succeeds even if the requested scheduling
parameters can not be set. This is not POSIX compliant, and even
worse, it leads to a wrong behavior. Let pthread_create() fail in this
case.

Change-Id: Ice66e2a720975c6bde9fe86c2cf8f649533a169c
Signed-off-by: Christian Bejram <christian.bejram@stericsson.com>
2012-05-08 10:54:51 -07:00
Evgeniy Stepanov
1a78fbb5c8 Initialize TLS before any application code is run.
Since e19d702b8e, dlsym and friends use recursive mutexes that
require the current thread id, which is not available before the libc
constructor. This prevents us from using dlsym() in .preinit_array.

This change moves TLS initialization from libc constructor to the earliest
possible point - immediately after linker itself is relocated. As a result,
pthread_internal_t for the initial thread is available from the start.

As a bonus, values stored in TLS in .preinit_array are not lost when libc is
initialized.

Change-Id: Iee5a710ee000173bff63e924adeb4a4c600c1e2d
2012-04-13 00:08:11 +04:00
Jean-Baptiste Queru
faca92f2f1 Handle pthread-related changes (mutex/atfork)
First commit:

Revert "Revert "am be741d47: am 2f460fbe: am 73b5cad9: Merge "bionic: Fix wrong kernel_id in pthread descriptor after fork()"""

This reverts commit 06823da2f0.

Second commit:

bionic: fix atfork hanlder_mutex deadlock

This cherry-picks commit 34e89c232d

After applying the kernel_id fix, the system refused to boot up and we
got following crash log:
I/DEBUG   (  113): pid: 618, tid: 618  >>> org.simalliance.openmobileapi.service:remote <<<
I/DEBUG   (  113): signal 16 (SIGSTKFLT), code -6 (?), fault addr --------
I/DEBUG   (  113):  eax fffffe00  ebx b77de994  ecx 00000080  edx 00724002
I/DEBUG   (  113):  esi 00000000  edi 00004000
I/DEBUG   (  113):  xcs 00000073  xds 0000007b  xes 0000007b  xfs 00000000 xss 0000007b
I/DEBUG   (  113):  eip b7761351  ebp bfdf3de8  esp bfdf3dc4  flags 00000202
I/DEBUG   (  113):     #00  eip: 00015351  /system/lib/libc.so
I/DEBUG   (  113):     #01  eip: 0000d13c  /system/lib/libc.so (pthread_mutex_lock)
I/DEBUG   (  113):     #02  eip: 00077b48  /system/lib/libc.so (__bionic_atfork_run_prepare)
I/DEBUG   (  113):     #03  eip: 00052cdb  /system/lib/libc.so (fork)
I/DEBUG   (  113):     #04  eip: 0009ae91  /system/lib/libdvm.so (_Z18dvmOptimizeDexFileillPKcjjb)
I/DEBUG   (  113):     #05  eip: 000819d6  /system/lib/libdvm.so (_Z14dvmJarFileOpenPKcS0_PP7JarFileb)
I/DEBUG   (  113):     #06  eip: 000b175e  /system/lib/libdvm.so (_ZL40Dalvik_dalvik_system_DexFile_openDexFilePKjP6JValue)
I/DEBUG   (  113):     #07  eip: 0011fb94  /system/lib/libdvm.so

Root cause:
The atfork uses the mutex handler_mutex to protect the atfork_head. The
parent will call __bionic_atfork_run_prepare() to lock the handler_mutex,
and need both the parent and child to unlock their own copy of handler_mutex
after fork. At that time, the owner of hanlder_mutex is set as the parent.
If we apply the kernel_id fix, then the child's kernel_id will be set as
child's tid.
The handler_mutex is a recursive lock, and pthread_mutex_unlock(&hander_mutex)
will fail because the mutex owner is the parent, while the current tid
(__get_thread()->kernel_id) is child, not matched with the mutex owner.
At that time, the handler_mutex is left in lock state.If the child wants to
fork other process after than, then it will try to lock handler_mutex, and
then be deadlocked.

Fix:
Since the child has its own copy of vm space from the the parent, the
child space's handler_mutex should be reset to the initialized state.

Change-Id: I3907dd9a153418fb78862f2aa6d0302c375d9e27
Signed-off-by: Jack Ren <jack.ren@intel.com>
Signed-off-by: Chenyang Du <chenyang.du@intel.com>
Signed-off-by: Bruce Beare <bruce.j.beare@intel.com>

Change-Id: Ic8072f366a877443a60fe215f3c00b3df5a259c8
2012-03-26 15:38:59 -07:00
Guang Zhu
06823da2f0 Revert "am be741d47: am 2f460fbe: am 73b5cad9: Merge "bionic: Fix wrong kernel_id in pthread descriptor after fork()""
This reverts commit 76d56cf4a9, reversing
changes made to c59ba4595b.

Bug: 6157577
2012-03-12 22:05:36 -07:00
Elliott Hughes
76d56cf4a9 am be741d47: am 2f460fbe: am 73b5cad9: Merge "bionic: Fix wrong kernel_id in pthread descriptor after fork()"
* commit 'be741d472868a8ffcb455588f18cda889b0f465c':
  bionic: Fix wrong kernel_id in pthread descriptor after fork()
2012-03-12 17:12:35 -07:00
Jack Ren
d8bc6e7119 bionic: Fix wrong kernel_id in pthread descriptor after fork()
After forking, the kernel_id field in the phtread_internal_t returned by pthread_self()
is incorrect --- it's the tid from the parent, not the new tid of the
child.

The root cause is that: currently the kernel_id is set by
_init_thread(), which is called in 2 cases:
(1) called by __libc_init_common(). That happens when the execv( ) is
called after fork( ). But when the zygote tries to fork the android
application, the child application doesn't call execv( ), instread, it
tries to call the Java main method directly.
(2) called by pthread_create(). That happens when a new thread is
created.

For the lead thread which is the thread created by fork(), it should
call execv() but it doesn't, as described in (1) above. So its kernel_id
will inherit the parent's kernel_id.

Fixed it in this patch.

Change-Id: I63513e82af40ec5fe51fbb69456b1843e4bc0fc7
Signed-off-by: Chenyang Du <chenyang.du@intel.com>
Signed-off-by: Jack Ren <jack.ren@intel.com>
Signed-off-by: Bruce Beare <bruce.j.beare@intel.com>
2012-03-12 23:14:56 +08:00
David 'Digit' Turner
e1414aa96b libc: remove global lock from recursive mutex implementation.
This optimization improves the performance of recursive locks
drastically. When running the thread_stress program on a Xoom,
the total time to perform all operations goes from 1500 ms to
500 ms on average after this change is pushed to the device.

Change-Id: I5d9407a9191bdefdaccff7e7edefc096ebba9a9d
2012-01-30 10:13:41 +01:00
David 'Digit' Turner
b57db7581c libc: Fix recursive mutex lock implementation.
This fixes a bug that was introduced in the latest pthread optimization.
It happens when a recursive lock is contented by several threads. The main
issue was that the atomic counter increment in _recursive_increment() could
be annihilated by a non-conditional write in pthread_mutex_lock() used to
update the value's lower bits to indicate contention.

This patch re-introduces the use of the global recursive lock in
_recursive_increment(). This will hit performance, but a future patch
will be provided to remove it from the source code.

Change-Id: Ie22069d376cebf2e7d613ba00b6871567f333544
2012-01-24 13:20:38 +01:00
Mathias Agopian
7c0c379372 implement pthread mutex deadlock detection
this works by building a directed graph of acquired
pthread mutexes and making sure there are no loops in
that graph.

this feature is enabled with:

    setprop debug.libc.pthread 1

when a potential deadlock is detected, a large warning is
output to the log with appropriate back traces.

currently disabled at compile-time. set PTHREAD_DEBUG_ENABLED=1
to enable.

Change-Id: I916eed2319599e8aaf8f229d3f18a8ddbec3aa8a
2011-12-09 14:38:57 -08:00