Merge "Fix the type of u_ar0 in <sys/user.h>."
diff --git a/libc/bionic/pthread_mutex.cpp b/libc/bionic/pthread_mutex.cpp
index cbb6ef7..40f1ed2 100644
--- a/libc/bionic/pthread_mutex.cpp
+++ b/libc/bionic/pthread_mutex.cpp
@@ -578,15 +578,12 @@
 }
 
 int pthread_mutex_trylock(pthread_mutex_t* mutex) {
-    int mvalue, mtype, tid, shared;
+    int mvalue = mutex->value;
+    int mtype  = (mvalue & MUTEX_TYPE_MASK);
+    int shared = (mvalue & MUTEX_SHARED_MASK);
 
-    mvalue = mutex->value;
-    mtype  = (mvalue & MUTEX_TYPE_MASK);
-    shared = (mvalue & MUTEX_SHARED_MASK);
-
-    /* Handle common case first */
-    if ( __predict_true(mtype == MUTEX_TYPE_BITS_NORMAL) )
-    {
+    // Handle common case first.
+    if (__predict_true(mtype == MUTEX_TYPE_BITS_NORMAL)) {
         if (__bionic_cmpxchg(shared|MUTEX_STATE_BITS_UNLOCKED,
                              shared|MUTEX_STATE_BITS_LOCKED_UNCONTENDED,
                              &mutex->value) == 0) {
@@ -597,10 +594,14 @@
         return EBUSY;
     }
 
-    /* Do we already own this recursive or error-check mutex ? */
-    tid = __get_thread()->tid;
-    if ( tid == MUTEX_OWNER_FROM_BITS(mvalue) )
+    // Do we already own this recursive or error-check mutex?
+    pid_t tid = __get_thread()->tid;
+    if (tid == MUTEX_OWNER_FROM_BITS(mvalue)) {
+        if (mtype == MUTEX_TYPE_BITS_ERRORCHECK) {
+            return EBUSY;
+        }
         return _recursive_increment(mutex, mvalue, mtype);
+    }
 
     /* Same as pthread_mutex_lock, except that we don't want to wait, and
      * the only operation that can succeed is a single cmpxchg to acquire the
diff --git a/tests/Android.mk b/tests/Android.mk
index a5cea2e..f61f175 100644
--- a/tests/Android.mk
+++ b/tests/Android.mk
@@ -397,15 +397,16 @@
 # Make sure to create ANDROID_DATA/local/tmp if doesn't exist.
 # bionic itself should always work relative to ANDROID_DATA or ANDROID_ROOT.
 # BIONIC_TEST_FLAGS is either empty or it comes from the user.
-bionic-unit-tests-run-on-host: bionic-unit-tests $(TARGET_OUT_EXECUTABLES)/$(LINKER) $(TARGET_OUT_EXECUTABLES)/sh
-	if [ ! -d /system -o ! -d /system/bin ]; then \
-	  echo "Attempting to create /system/bin"; \
-	  sudo mkdir -p -m 0777 /system/bin; \
+bionic-unit-tests-run-on-host-prepare: $(TARGET_OUT_EXECUTABLES)/$(LINKER) $(TARGET_OUT_EXECUTABLES)/sh
+	if [ ! -d /system ]; then \
+	  echo "Attempting to create /system"; \
+	  sudo mkdir -p -m 0777 /system; \
 	fi
 	mkdir -p $(TARGET_OUT_DATA)/local/tmp
-	ln -fs `realpath $(TARGET_OUT_EXECUTABLES)/$(LINKER)` /system/bin
-	ln -fs `realpath $(TARGET_OUT_EXECUTABLES)/sh` /system/bin
+	ln -fs `realpath $(TARGET_OUT)/bin` /system/
 	ln -fs `realpath $(TARGET_OUT)/etc` /system/
+
+bionic-unit-tests-run-on-host: bionic-unit-tests bionic-unit-tests-run-on-host-prepare
 	ANDROID_DATA=$(TARGET_OUT_DATA) \
 	ANDROID_DNS_MODE=local \
 	ANDROID_ROOT=$(TARGET_OUT) \
@@ -415,15 +416,7 @@
 
 ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86_64))
 # add target to run lp32 tests
-bionic-unit-tests-run-on-host32: bionic-unit-tests_32 $(TARGET_OUT_EXECUTABLES)/$(LINKER) $(TARGET_OUT_EXECUTABLES)/sh
-	if [ ! -d /system -o ! -d /system/bin ]; then \
-	  echo "Attempting to create /system/bin"; \
-	  sudo mkdir -p -m 0777 /system/bin; \
-	fi
-	mkdir -p $(TARGET_OUT_DATA)/local/tmp
-	ln -fs `realpath $(TARGET_OUT_EXECUTABLES)/linker` /system/bin
-	ln -fs `realpath $(TARGET_OUT_EXECUTABLES)/sh` /system/bin
-	ln -fs `realpath $(TARGET_OUT)/etc` /system/
+bionic-unit-tests-run-on-host32: bionic-unit-tests_32 bionic-unit-tests-run-on-host-prepare
 	ANDROID_DATA=$(TARGET_OUT_DATA) \
 	ANDROID_DNS_MODE=local \
 	ANDROID_ROOT=$(TARGET_OUT) \