Merge "Statically linked executables should honor AT_SECURE."
diff --git a/libc/bionic/pthread_mutex.cpp b/libc/bionic/pthread_mutex.cpp
index 4fec753..851fc3d 100644
--- a/libc/bionic/pthread_mutex.cpp
+++ b/libc/bionic/pthread_mutex.cpp
@@ -501,6 +501,12 @@
}
int pthread_mutex_lock(pthread_mutex_t* mutex_interface) {
+#if !defined(__LP64__)
+ if (mutex_interface == NULL) {
+ return EINVAL;
+ }
+#endif
+
pthread_mutex_internal_t* mutex = __get_internal_mutex(mutex_interface);
uint16_t old_state = atomic_load_explicit(&mutex->state, memory_order_relaxed);
@@ -516,6 +522,12 @@
}
int pthread_mutex_unlock(pthread_mutex_t* mutex_interface) {
+#if !defined(__LP64__)
+ if (mutex_interface == NULL) {
+ return EINVAL;
+ }
+#endif
+
pthread_mutex_internal_t* mutex = __get_internal_mutex(mutex_interface);
uint16_t old_state = atomic_load_explicit(&mutex->state, memory_order_relaxed);
diff --git a/libc/include/pthread.h b/libc/include/pthread.h
index 26d68e4..260ae5b 100644
--- a/libc/include/pthread.h
+++ b/libc/include/pthread.h
@@ -176,10 +176,18 @@
int pthread_mutex_destroy(pthread_mutex_t*) __nonnull((1));
int pthread_mutex_init(pthread_mutex_t*, const pthread_mutexattr_t*) __nonnull((1));
+#if !defined(__LP64__)
+int pthread_mutex_lock(pthread_mutex_t*) /* __nonnull((1)) */;
+#else
int pthread_mutex_lock(pthread_mutex_t*) __nonnull((1));
+#endif
int pthread_mutex_timedlock(pthread_mutex_t*, const struct timespec*) __nonnull((1, 2));
int pthread_mutex_trylock(pthread_mutex_t*) __nonnull((1));
+#if !defined(__LP4__)
+int pthread_mutex_unlock(pthread_mutex_t*) /* __nonnull((1)) */;
+#else
int pthread_mutex_unlock(pthread_mutex_t*) __nonnull((1));
+#endif
int pthread_once(pthread_once_t*, void (*)(void)) __nonnull((1, 2));
diff --git a/linker/linker.cpp b/linker/linker.cpp
index 143320b..b5ebc1e 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -2783,17 +2783,6 @@
}
}
- // second pass - parse entries relying on strtab
- for (ElfW(Dyn)* d = dynamic; d->d_tag != DT_NULL; ++d) {
- if (d->d_tag == DT_SONAME) {
- soname_ = get_string(d->d_un.d_val);
-#if defined(__work_around_b_19059885__)
- strlcpy(old_name_, soname_, sizeof(old_name_));
-#endif
- break;
- }
- }
-
DEBUG("si->base = %p, si->strtab = %p, si->symtab = %p",
reinterpret_cast<void*>(base), strtab_, symtab_);
@@ -2816,6 +2805,17 @@
return false;
}
+ // second pass - parse entries relying on strtab
+ for (ElfW(Dyn)* d = dynamic; d->d_tag != DT_NULL; ++d) {
+ if (d->d_tag == DT_SONAME) {
+ soname_ = get_string(d->d_un.d_val);
+#if defined(__work_around_b_19059885__)
+ strlcpy(old_name_, soname_, sizeof(old_name_));
+#endif
+ break;
+ }
+ }
+
// Before M release linker was using basename in place of soname.
// In the case when dt_soname is absent some apps stop working
// because they can't find dt_needed library by soname.
diff --git a/tests/pthread_test.cpp b/tests/pthread_test.cpp
index e55ed37..eeb1541 100644
--- a/tests/pthread_test.cpp
+++ b/tests/pthread_test.cpp
@@ -1537,3 +1537,37 @@
GTEST_LOG_(INFO) << "This test tests bionic implementation details.";
#endif
}
+
+TEST(pthread, pthread_mutex_lock_null_32) {
+#if defined(__BIONIC__) && !defined(__LP64__)
+ ASSERT_EQ(EINVAL, pthread_mutex_lock(NULL));
+#else
+ GTEST_LOG_(INFO) << "This test tests bionic implementation details on 32 bit devices.";
+#endif
+}
+
+TEST(pthread, pthread_mutex_unlock_null_32) {
+#if defined(__BIONIC__) && !defined(__LP64__)
+ ASSERT_EQ(EINVAL, pthread_mutex_unlock(NULL));
+#else
+ GTEST_LOG_(INFO) << "This test tests bionic implementation details on 32 bit devices.";
+#endif
+}
+
+TEST_F(pthread_DeathTest, pthread_mutex_lock_null_64) {
+#if defined(__BIONIC__) && defined(__LP64__)
+ pthread_mutex_t* null_value = nullptr;
+ ASSERT_EXIT(pthread_mutex_lock(null_value), testing::KilledBySignal(SIGSEGV), "");
+#else
+ GTEST_LOG_(INFO) << "This test tests bionic implementation details on 64 bit devices.";
+#endif
+}
+
+TEST_F(pthread_DeathTest, pthread_mutex_unlock_null_64) {
+#if defined(__BIONIC__) && defined(__LP64__)
+ pthread_mutex_t* null_value = nullptr;
+ ASSERT_EXIT(pthread_mutex_unlock(null_value), testing::KilledBySignal(SIGSEGV), "");
+#else
+ GTEST_LOG_(INFO) << "This test tests bionic implementation details on 64 bit devices.";
+#endif
+}