aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEthan Chen <intervigil@gmail.com>2018-09-25 00:11:05 -0700
committerAli B <abittin@gmail.com>2019-11-01 13:00:55 +0300
commitd07f2672ffaea2202233d347e22c57f992f51f8c (patch)
treeb1d8fc13af2d6bdc362cea66d1dbe01c7e63c97b
parentdc33ecf97929dd8b3a2039cafcab0d2e17a5857c (diff)
Actually restore pre-P mutex behaviorq10.0-r9rebase
Apps built against versions < P may not actually expect the EBUSY return code, and may crash or otherwise misbehave. Check for target SDK versions earlier than P when performing the IsMutexDestroyed check so any invocation of HandleUsingDestroyedMutex is bypassed and pre-P mutex behavior is restored. See 9e989f12d1186231d97dac6d038db7955acebdf3 for the change that introduced this new behavior. [aviraxp: Update for P: s/bionic_get_application_target_sdk_version/android_get_application_target_sdk_version Remove inline keyword for IsMutexDestroyed()] Change-Id: I45f8882c9527c63eed1ef5820a5004b8958d58ea
-rw-r--r--libc/bionic/pthread_mutex.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/libc/bionic/pthread_mutex.cpp b/libc/bionic/pthread_mutex.cpp
index 6f1cf1367..478b31f8e 100644
--- a/libc/bionic/pthread_mutex.cpp
+++ b/libc/bionic/pthread_mutex.cpp
@@ -784,16 +784,21 @@ static int MutexLockWithTimeout(pthread_mutex_internal_t* mutex, bool use_realti
} // namespace NonPI
static inline __always_inline bool IsMutexDestroyed(uint16_t mutex_state) {
- return mutex_state == 0xffff;
+ // Checking for mutex destruction is a P-specific behavior. Bypass the
+ // check if the SDK version precedes P, so that no change in behavior
+ // that may cause crashes is introduced.
+ if (android_get_application_target_sdk_version() >= __ANDROID_API_P__) {
+ return mutex_state == 0xffff;
+ } else {
+ return false;
+ }
}
// Inlining this function in pthread_mutex_lock() adds the cost of stack frame instructions on
// ARM64. So make it noinline.
static int __attribute__((noinline)) HandleUsingDestroyedMutex(pthread_mutex_t* mutex,
const char* function_name) {
- if (android_get_application_target_sdk_version() >= __ANDROID_API_P__) {
- __fortify_fatal("%s called on a destroyed mutex (%p)", function_name, mutex);
- }
+ __fortify_fatal("%s called on a destroyed mutex (%p)", function_name, mutex);
return EBUSY;
}