summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2013-12-11 14:54:00 -0800
committerSteve Kondik <shade@chemlab.org>2014-01-17 00:22:13 -0800
commit53f15d0325feeaf7e58dc79fce4ddf55e0a64b7a (patch)
tree4447f423a938764c842e5901d29c0e37f4e51239
parent59306820664c85de2a1e42b35f72b79ce9e3c196 (diff)
downloadbionic-53f15d0325feeaf7e58dc79fce4ddf55e0a64b7a.tar.gz
bionic-53f15d0325feeaf7e58dc79fce4ddf55e0a64b7a.tar.bz2
bionic-53f15d0325feeaf7e58dc79fce4ddf55e0a64b7a.zip
Remove harmful attempts to be helpful in pthread_mutex functions.
Most callers won't check for EINVAL, so it's best to fail early. GCC takes the nonnull attribute as a guarantee that an argument won't be NULL, so these hacks were already ineffective, which is how we found that at least one commercial game was using NULL as if it's a mutex, but actually getting no-op behavior. Bug: 11971278 Change-Id: I89646e043d931778805a8b692e07a34d076ee6bf
-rw-r--r--libc/bionic/pthread.c25
1 files changed, 4 insertions, 21 deletions
diff --git a/libc/bionic/pthread.c b/libc/bionic/pthread.c
index 92e2c27f0..764e01d12 100644
--- a/libc/bionic/pthread.c
+++ b/libc/bionic/pthread.c
@@ -391,21 +391,16 @@ int pthread_mutexattr_getpshared(pthread_mutexattr_t *attr, int *pshared)
return 0;
}
-int pthread_mutex_init(pthread_mutex_t *mutex,
- const pthread_mutexattr_t *attr)
-{
- int value = 0;
-
- if (mutex == NULL)
- return EINVAL;
-
+int pthread_mutex_init(pthread_mutex_t* mutex, const pthread_mutexattr_t* attr) {
if (__predict_true(attr == NULL)) {
mutex->value = MUTEX_TYPE_BITS_NORMAL;
return 0;
}
- if ((*attr & MUTEXATTR_SHARED_MASK) != 0)
+ int value = 0;
+ if ((*attr & MUTEXATTR_SHARED_MASK) != 0) {
value |= MUTEX_SHARED_MASK;
+ }
switch (*attr & MUTEXATTR_TYPE_MASK) {
case PTHREAD_MUTEX_NORMAL:
@@ -582,9 +577,6 @@ int pthread_mutex_lock_impl(pthread_mutex_t *mutex)
{
int mvalue, mtype, tid, shared;
- if (__predict_false(mutex == NULL))
- return EINVAL;
-
mvalue = mutex->value;
mtype = (mvalue & MUTEX_TYPE_MASK);
shared = (mvalue & MUTEX_SHARED_MASK);
@@ -676,9 +668,6 @@ int pthread_mutex_unlock_impl(pthread_mutex_t *mutex)
{
int mvalue, mtype, tid, shared;
- if (__predict_false(mutex == NULL))
- return EINVAL;
-
mvalue = mutex->value;
mtype = (mvalue & MUTEX_TYPE_MASK);
shared = (mvalue & MUTEX_SHARED_MASK);
@@ -743,9 +732,6 @@ int pthread_mutex_trylock_impl(pthread_mutex_t *mutex)
{
int mvalue, mtype, tid, shared;
- if (__predict_false(mutex == NULL))
- return EINVAL;
-
mvalue = mutex->value;
mtype = (mvalue & MUTEX_TYPE_MASK);
shared = (mvalue & MUTEX_SHARED_MASK);
@@ -841,9 +827,6 @@ int pthread_mutex_lock_timeout_np_impl(pthread_mutex_t *mutex, unsigned msecs)
/* compute absolute expiration time */
__timespec_to_relative_msec(&abstime, msecs, clock);
- if (__predict_false(mutex == NULL))
- return EINVAL;
-
mvalue = mutex->value;
mtype = (mvalue & MUTEX_TYPE_MASK);
shared = (mvalue & MUTEX_SHARED_MASK);