Merge "bionic: fix assorted static analyzer warnings"
diff --git a/libc/include/pthread.h b/libc/include/pthread.h
index 20b6c5b..7dec3cc 100644
--- a/libc/include/pthread.h
+++ b/libc/include/pthread.h
@@ -162,14 +162,22 @@
 
 #if defined(__LP32__) && __ANDROID_API__ < 21
 /*
- * Cruft for supporting old API levels. Pre-L we didn't have
- * pthread_mutex_timedlock, instead we had pthread_mutex_lock_timeout_np. NDK
- * users targeting pre-L still need this, but anyone targeting L or newer (or
- * LP64 code) should just use pthread_mutex_timedlock.
+ * Cruft for supporting old API levels. Pre-L we didn't have the proper POSIX
+ * APIs for things, but instead had some locally grown, artisan equivalents.
+ * Keep exposing the old prototypes on old API levels so we don't regress
+ * functionality.
  *
- * https://github.com/android-ndk/ndk/issues/420
+ * See the following bugs:
+ *  * https://github.com/android-ndk/ndk/issues/420
+ *  * https://github.com/android-ndk/ndk/issues/423
+ *  * https://stackoverflow.com/q/44580542/632035
  */
+
 int pthread_mutex_lock_timeout_np(pthread_mutex_t* mutex, unsigned msecs);
+int pthread_cond_timeout_np(pthread_cond_t* cond, pthread_mutex_t* mutex, unsigned msecs);
+int pthread_cond_timedwait_monotonic_np(pthread_cond_t*, pthread_mutex_t*, const struct timespec*);
+int pthread_cond_timedwait_relative_np(pthread_cond_t* cond, pthread_mutex_t* mutex,
+                                       const struct timespec* reltime);
 #endif
 
 int pthread_once(pthread_once_t* _Nonnull, void (* _Nonnull init_routine)(void));
diff --git a/libc/private/CFIShadow.h b/libc/private/CFIShadow.h
index 26351db..9f980f8 100644
--- a/libc/private/CFIShadow.h
+++ b/libc/private/CFIShadow.h
@@ -62,7 +62,7 @@
   static constexpr uintptr_t kCfiCheckAlign = 1UL << kCfiCheckGranularity;  // 4K
 
 #if defined(__aarch64__)
-  static constexpr uintptr_t kMaxTargetAddr = 0x7fffffffff;
+  static constexpr uintptr_t kMaxTargetAddr = 0xffffffffffff;
 #elif defined (__LP64__)
   static constexpr uintptr_t kMaxTargetAddr = 0x7fffffffffff;
 #else
diff --git a/tests/dlfcn_test.cpp b/tests/dlfcn_test.cpp
index 5d3985f..1e2b6c9 100644
--- a/tests/dlfcn_test.cpp
+++ b/tests/dlfcn_test.cpp
@@ -1271,6 +1271,21 @@
   dlclose(handle);
 }
 
+TEST(dlfcn, dt_runpath_absolute_path) {
+  std::string libpath = get_testlib_root() + "/libtest_dt_runpath_d.so";
+  void* handle = dlopen(libpath.c_str(), RTLD_NOW);
+  ASSERT_TRUE(handle != nullptr) << dlerror();
+
+  typedef void *(* dlopen_b_fn)();
+  dlopen_b_fn fn = (dlopen_b_fn)dlsym(handle, "dlopen_b");
+  ASSERT_TRUE(fn != nullptr) << dlerror();
+
+  void *p = fn();
+  ASSERT_TRUE(p != nullptr);
+
+  dlclose(handle);
+}
+
 TEST(dlfcn, RTLD_macros) {
 #if !defined(RTLD_LOCAL)
 #error no RTLD_LOCAL
@@ -1368,21 +1383,6 @@
 
 #endif //  defined(__arm__)
 
-TEST(dlfcn, dt_runpath_absolute_path) {
-  std::string libpath = get_testlib_root() + "/libtest_dt_runpath_d.so";
-  void* handle = dlopen(libpath.c_str(), RTLD_NOW);
-  ASSERT_TRUE(handle != nullptr) << dlerror();
-
-  typedef void *(* dlopen_b_fn)();
-  dlopen_b_fn fn = (dlopen_b_fn)dlsym(handle, "dlopen_b");
-  ASSERT_TRUE(fn != nullptr) << dlerror();
-
-  void *p = fn();
-  ASSERT_TRUE(p != nullptr);
-
-  dlclose(handle);
-}
-
 TEST(dlfcn, dlopen_invalid_rw_load_segment) {
   const std::string libpath = get_testlib_root() +
                               "/" + kPrebuiltElfDir +