Merge "Revert "Load /dev/linker/ld.config.txt by default""
diff --git a/docs/native_allocator.md b/docs/native_allocator.md
index 7695470..adfa6ef 100644
--- a/docs/native_allocator.md
+++ b/docs/native_allocator.md
@@ -100,6 +100,19 @@
 The allocation tests are not meant to be complete, so it is expected
 that a native allocator will have its own set of tests that can be run.
 
+### Libmemunreachable Tests
+The libmemunreachable tests verify that the iterator functions are working
+properly.
+
+To run all of the tests:
+
+    adb shell /data/nativetest64/memunreachable_binder_test/memunreachable_binder_test
+    adb shell /data/nativetest/memunreachable_binder_test/memunreachable_binder_test
+    adb shell /data/nativetest64/memunreachable_test/memunreachable_test
+    adb shell /data/nativetest/memunreachable_test/memunreachable_test
+    adb shell /data/nativetest64/memunreachable_unit_test/memunreachable_unit_test
+    adb shell /data/nativetest/memunreachable_unit_test/memunreachable_unit_test
+
 ### CTS Entropy Test
 In addition to the bionic tests, there is also a CTS test that is designed
 to verify that the addresses returned by malloc are sufficiently randomized
diff --git a/libc/Android.bp b/libc/Android.bp
index 3e2ee1d..45c4569 100644
--- a/libc/Android.bp
+++ b/libc/Android.bp
@@ -271,8 +271,6 @@
     defaults: ["libc_defaults"],
     srcs: [
         "upstream-freebsd/lib/libc/gen/ldexp.c",
-        "upstream-freebsd/lib/libc/gen/sleep.c",
-        "upstream-freebsd/lib/libc/gen/usleep.c",
         "upstream-freebsd/lib/libc/stdlib/getopt_long.c",
         "upstream-freebsd/lib/libc/stdlib/hcreate.c",
         "upstream-freebsd/lib/libc/stdlib/hcreate_r.c",
@@ -1072,6 +1070,7 @@
         "bionic/atof.cpp",
         "bionic/bionic_allocator.cpp",
         "bionic/bionic_arc4random.cpp",
+        "bionic/bionic_call_ifunc_resolver.cpp",
         "bionic/bionic_futex.cpp",
         "bionic/bionic_netlink.cpp",
         "bionic/bionic_systrace.cpp",
@@ -1178,6 +1177,7 @@
         "bionic/sigaction.cpp",
         "bionic/signal.cpp",
         "bionic/sigprocmask.cpp",
+        "bionic/sleep.cpp",
         "bionic/spawn.cpp",
         "bionic/stat.cpp",
         "bionic/stdlib_l.cpp",
@@ -1212,6 +1212,7 @@
         "bionic/tmpfile.cpp",
         "bionic/umount.cpp",
         "bionic/unlink.cpp",
+        "bionic/usleep.cpp",
         "bionic/wait.cpp",
         "bionic/wchar.cpp",
         "bionic/wchar_l.cpp",
diff --git a/libc/bionic/bionic_call_ifunc_resolver.cpp b/libc/bionic/bionic_call_ifunc_resolver.cpp
new file mode 100644
index 0000000..8522835
--- /dev/null
+++ b/libc/bionic/bionic_call_ifunc_resolver.cpp
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include "private/bionic_call_ifunc_resolver.h"
+#include <sys/auxv.h>
+#include <sys/ifunc.h>
+
+ElfW(Addr) __bionic_call_ifunc_resolver(ElfW(Addr) resolver_addr) {
+#if defined(__aarch64__)
+  typedef ElfW(Addr) (*ifunc_resolver_t)(uint64_t, __ifunc_arg_t*);
+  static __ifunc_arg_t arg = { sizeof(__ifunc_arg_t), getauxval(AT_HWCAP), getauxval(AT_HWCAP2) };
+  return reinterpret_cast<ifunc_resolver_t>(resolver_addr)(arg._hwcap | _IFUNC_ARG_HWCAP, &arg);
+#elif defined(__arm__)
+  typedef ElfW(Addr) (*ifunc_resolver_t)(unsigned long);
+  static unsigned long hwcap = getauxval(AT_HWCAP);
+  return reinterpret_cast<ifunc_resolver_t>(resolver_addr)(hwcap);
+#else
+  typedef ElfW(Addr) (*ifunc_resolver_t)(void);
+  return reinterpret_cast<ifunc_resolver_t>(resolver_addr)();
+#endif
+}
diff --git a/libc/bionic/libc_init_static.cpp b/libc/bionic/libc_init_static.cpp
index b4bddce..0b74023 100644
--- a/libc/bionic/libc_init_static.cpp
+++ b/libc/bionic/libc_init_static.cpp
@@ -39,6 +39,7 @@
 #include "libc_init_common.h"
 #include "pthread_internal.h"
 
+#include "private/bionic_call_ifunc_resolver.h"
 #include "private/bionic_elf_tls.h"
 #include "private/bionic_globals.h"
 #include "private/bionic_macros.h"
@@ -81,11 +82,10 @@
     return;
   }
 
-  typedef ElfW(Addr) (*ifunc_resolver_t)(void);
   for (ElfW(Rela) *r = __rela_iplt_start; r != __rela_iplt_end; ++r) {
     ElfW(Addr)* offset = reinterpret_cast<ElfW(Addr)*>(r->r_offset);
     ElfW(Addr) resolver = r->r_addend;
-    *offset = reinterpret_cast<ifunc_resolver_t>(resolver)();
+    *offset = __bionic_call_ifunc_resolver(resolver);
   }
 }
 #else
@@ -103,11 +103,10 @@
     return;
   }
 
-  typedef ElfW(Addr) (*ifunc_resolver_t)(void);
   for (ElfW(Rel) *r = __rel_iplt_start; r != __rel_iplt_end; ++r) {
     ElfW(Addr)* offset = reinterpret_cast<ElfW(Addr)*>(r->r_offset);
     ElfW(Addr) resolver = *offset;
-    *offset = reinterpret_cast<ifunc_resolver_t>(resolver)();
+    *offset = __bionic_call_ifunc_resolver(resolver);
   }
 }
 #endif
diff --git a/libc/bionic/sleep.cpp b/libc/bionic/sleep.cpp
new file mode 100644
index 0000000..fcfd9b2
--- /dev/null
+++ b/libc/bionic/sleep.cpp
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <unistd.h>
+
+#include <time.h>
+
+unsigned sleep(unsigned s) {
+#if !defined(__LP64__)
+  // `s` is `unsigned`, but tv_sec is `int` on LP32.
+  if (s > INT_MAX) return s - INT_MAX + sleep(INT_MAX);
+#endif
+
+  timespec ts = {.tv_sec = static_cast<time_t>(s)};
+  return (nanosleep(&ts, &ts) == -1) ? ts.tv_sec : 0;
+}
diff --git a/libc/bionic/usleep.cpp b/libc/bionic/usleep.cpp
new file mode 100644
index 0000000..2204684
--- /dev/null
+++ b/libc/bionic/usleep.cpp
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <unistd.h>
+
+#include <time.h>
+
+int usleep(useconds_t us) {
+  timespec ts;
+  ts.tv_sec = us / 1000000;
+  ts.tv_nsec = (us % 1000000) * 1000;
+  return nanosleep(&ts, nullptr);
+}
diff --git a/libc/include/sys/ifunc.h b/libc/include/sys/ifunc.h
new file mode 100644
index 0000000..7fbca4a
--- /dev/null
+++ b/libc/include/sys/ifunc.h
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include <sys/cdefs.h>
+
+/**
+ * @file sys/ifunc.h
+ * @brief Declarations used for ifunc resolvers. Currently only meaningful for arm64.
+ */
+
+__BEGIN_DECLS
+
+#if defined(__aarch64__)
+
+/**
+ * Provides information about hardware capabilities to ifunc resolvers.
+ *
+ * Starting with API level 30, ifunc resolvers on arm64 are passed two arguments. The first is a
+ * uint64_t whose value is equal to getauxval(AT_HWCAP) | _IFUNC_ARG_HWCAP. The second is a pointer
+ * to a data structure of this type. Prior to API level 30, no arguments are passed to ifunc
+ * resolvers. Code that wishes to be compatible with prior API levels should not accept any
+ * arguments in the resolver.
+ */
+typedef struct __ifunc_arg_t {
+  /** Set to sizeof(__ifunc_arg_t). */
+  unsigned long _size;
+
+  /** Set to getauxval(AT_HWCAP). */
+  unsigned long _hwcap;
+
+  /** Set to getauxval(AT_HWCAP2). */
+  unsigned long _hwcap2;
+} __ifunc_arg_t;
+
+/**
+ * If this bit is set in the first argument to an ifunc resolver, indicates that the second argument
+ * is a pointer to a data structure of type __ifunc_arg_t. This bit is always set on Android
+ * starting with API level 30.
+ */
+#define _IFUNC_ARG_HWCAP (1ULL << 62)
+
+#endif
+
+__END_DECLS
diff --git a/libc/private/bionic_call_ifunc_resolver.h b/libc/private/bionic_call_ifunc_resolver.h
new file mode 100644
index 0000000..e0ea35b
--- /dev/null
+++ b/libc/private/bionic_call_ifunc_resolver.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include <link.h>
+#include <sys/cdefs.h>
+
+__LIBC_HIDDEN__ ElfW(Addr) __bionic_call_ifunc_resolver(ElfW(Addr) resolver_addr);
diff --git a/libc/upstream-freebsd/lib/libc/gen/sleep.c b/libc/upstream-freebsd/lib/libc/gen/sleep.c
deleted file mode 100644
index b807c2d..0000000
--- a/libc/upstream-freebsd/lib/libc/gen/sleep.c
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright (c) 1989, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)sleep.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "namespace.h"
-#include <errno.h>
-#include <limits.h>
-#include <time.h>
-#include <unistd.h>
-#include "un-namespace.h"
-
-unsigned int
-__sleep(unsigned int seconds)
-{
-	struct timespec time_to_sleep;
-	struct timespec time_remaining;
-
-	/*
-	 * Avoid overflow when `seconds' is huge.  This assumes that
-	 * the maximum value for a time_t is >= INT_MAX.
-	 */
-	if (seconds > INT_MAX)
-		return (seconds - INT_MAX + __sleep(INT_MAX));
-
-	time_to_sleep.tv_sec = seconds;
-	time_to_sleep.tv_nsec = 0;
-	if (_nanosleep(&time_to_sleep, &time_remaining) != -1)
-		return (0);
-	if (errno != EINTR)
-		return (seconds);		/* best guess */
-	return (time_remaining.tv_sec +
-		(time_remaining.tv_nsec != 0)); /* round up */
-}
-
-__weak_reference(__sleep, sleep);
-__weak_reference(__sleep, _sleep);
diff --git a/libc/upstream-freebsd/lib/libc/gen/usleep.c b/libc/upstream-freebsd/lib/libc/gen/usleep.c
deleted file mode 100644
index 7d6559b..0000000
--- a/libc/upstream-freebsd/lib/libc/gen/usleep.c
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (c) 1989, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)usleep.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "namespace.h"
-#include <time.h>
-#include <unistd.h>
-#include "un-namespace.h"
-
-int
-__usleep(useconds_t useconds)
-{
-	struct timespec time_to_sleep;
-
-	time_to_sleep.tv_nsec = (useconds % 1000000) * 1000;
-	time_to_sleep.tv_sec = useconds / 1000000;
-	return (_nanosleep(&time_to_sleep, NULL));
-}
-
-__weak_reference(__usleep, usleep);
-__weak_reference(__usleep, _usleep);
diff --git a/libc/upstream-freebsd/lib/libc/stdlib/hcreate.c b/libc/upstream-freebsd/lib/libc/stdlib/hcreate.c
index d512857..b175d34 100644
--- a/libc/upstream-freebsd/lib/libc/stdlib/hcreate.c
+++ b/libc/upstream-freebsd/lib/libc/stdlib/hcreate.c
@@ -1,4 +1,6 @@
 /*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
  * Copyright (c) 2015 Nuxi, https://nuxi.nl/
  *
  * Redistribution and use in source and binary forms, with or without
@@ -24,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/libc/stdlib/hcreate.c 292767 2015-12-27 07:50:11Z ed $");
+__FBSDID("$FreeBSD: head/lib/libc/stdlib/hcreate.c 326193 2017-11-25 17:12:48Z pfg $");
 
 #include <search.h>
 #include <stdbool.h>
diff --git a/libc/upstream-freebsd/lib/libc/string/wcpcpy.c b/libc/upstream-freebsd/lib/libc/string/wcpcpy.c
index df63d72..e040dba 100644
--- a/libc/upstream-freebsd/lib/libc/string/wcpcpy.c
+++ b/libc/upstream-freebsd/lib/libc/string/wcpcpy.c
@@ -1,4 +1,6 @@
-/*
+/*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
  * Copyright (c) 1999
  *	David E. O'Brien
  * Copyright (c) 1988, 1993
@@ -33,7 +35,7 @@
 static char sccsid[] = "@(#)strcpy.c	8.1 (Berkeley) 6/4/93";
 #endif /* LIBC_SCCS and not lint */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libc/string/wcpcpy.c 326025 2017-11-20 19:49:47Z pfg $");
 
 #include <wchar.h>
 
diff --git a/libc/upstream-freebsd/lib/libc/string/wcpncpy.c b/libc/upstream-freebsd/lib/libc/string/wcpncpy.c
index 87b361c..8bf6e87 100644
--- a/libc/upstream-freebsd/lib/libc/string/wcpncpy.c
+++ b/libc/upstream-freebsd/lib/libc/string/wcpncpy.c
@@ -1,4 +1,6 @@
 /*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
  * Copyright (c) 2009 David Schultz <das@FreeBSD.org>
  * All rights reserved.
  *
@@ -25,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libc/string/wcpncpy.c 326193 2017-11-25 17:12:48Z pfg $");
 
 #include <wchar.h>
 
diff --git a/libc/upstream-freebsd/lib/libc/string/wcscasecmp.c b/libc/upstream-freebsd/lib/libc/string/wcscasecmp.c
index 0143543..5bd468d 100644
--- a/libc/upstream-freebsd/lib/libc/string/wcscasecmp.c
+++ b/libc/upstream-freebsd/lib/libc/string/wcscasecmp.c
@@ -1,4 +1,6 @@
 /*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
  * Copyright (c) 2009 David Schultz <das@FreeBSD.org>
  * All rights reserved.
  *
@@ -25,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libc/string/wcscasecmp.c 326193 2017-11-25 17:12:48Z pfg $");
 
 #include <wchar.h>
 #include <wctype.h>
diff --git a/libc/upstream-freebsd/lib/libc/string/wcscat.c b/libc/upstream-freebsd/lib/libc/string/wcscat.c
index 7ae4e80..792f61e 100644
--- a/libc/upstream-freebsd/lib/libc/string/wcscat.c
+++ b/libc/upstream-freebsd/lib/libc/string/wcscat.c
@@ -1,4 +1,6 @@
 /*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
  * Copyright (c)1999 Citrus Project,
  * All rights reserved.
  *
@@ -32,7 +34,7 @@
 __RCSID("$NetBSD: wcscat.c,v 1.1 2000/12/23 23:14:36 itojun Exp $");
 #endif /* LIBC_SCCS and not lint */
 #endif
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libc/string/wcscat.c 326193 2017-11-25 17:12:48Z pfg $");
 
 #include <wchar.h>
 
diff --git a/libc/upstream-freebsd/lib/libc/string/wcschr.c b/libc/upstream-freebsd/lib/libc/string/wcschr.c
index 1df1fe6..ca740c0 100644
--- a/libc/upstream-freebsd/lib/libc/string/wcschr.c
+++ b/libc/upstream-freebsd/lib/libc/string/wcschr.c
@@ -1,4 +1,6 @@
 /*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
  * Copyright (c) 2002 Tim J. Robbins
  * All rights reserved.
  *
@@ -25,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libc/string/wcschr.c 326193 2017-11-25 17:12:48Z pfg $");
 
 #include <wchar.h>
 
diff --git a/libc/upstream-freebsd/lib/libc/string/wcscmp.c b/libc/upstream-freebsd/lib/libc/string/wcscmp.c
index c2abe4c..db01892 100644
--- a/libc/upstream-freebsd/lib/libc/string/wcscmp.c
+++ b/libc/upstream-freebsd/lib/libc/string/wcscmp.c
@@ -1,4 +1,6 @@
 /*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
  * Copyright (c) 1990, 1993
  *	The Regents of the University of California.  All rights reserved.
  *
@@ -37,7 +39,7 @@
 __RCSID("$NetBSD: wcscmp.c,v 1.3 2001/01/05 12:13:12 itojun Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libc/string/wcscmp.c 326025 2017-11-20 19:49:47Z pfg $");
 
 #include <wchar.h>
 
diff --git a/libc/upstream-freebsd/lib/libc/string/wcscpy.c b/libc/upstream-freebsd/lib/libc/string/wcscpy.c
index 0c6e1f2..a639e74 100644
--- a/libc/upstream-freebsd/lib/libc/string/wcscpy.c
+++ b/libc/upstream-freebsd/lib/libc/string/wcscpy.c
@@ -1,4 +1,6 @@
 /*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
  * Copyright (c)1999 Citrus Project,
  * All rights reserved.
  *
@@ -32,7 +34,7 @@
 __RCSID("$NetBSD: wcscpy.c,v 1.1 2000/12/23 23:14:36 itojun Exp $");
 #endif /* LIBC_SCCS and not lint */
 #endif
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libc/string/wcscpy.c 326193 2017-11-25 17:12:48Z pfg $");
 
 #include <wchar.h>
 
diff --git a/libc/upstream-freebsd/lib/libc/string/wcscspn.c b/libc/upstream-freebsd/lib/libc/string/wcscspn.c
index 7729dc8..8a7682f 100644
--- a/libc/upstream-freebsd/lib/libc/string/wcscspn.c
+++ b/libc/upstream-freebsd/lib/libc/string/wcscspn.c
@@ -1,4 +1,6 @@
 /*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
  * Copyright (c)1999 Citrus Project,
  * All rights reserved.
  *
@@ -32,7 +34,7 @@
 __RCSID("$NetBSD: wcscspn.c,v 1.1 2000/12/23 23:14:36 itojun Exp $");
 #endif /* LIBC_SCCS and not lint */
 #endif
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libc/string/wcscspn.c 326193 2017-11-25 17:12:48Z pfg $");
 
 #include <wchar.h>
 
diff --git a/libc/upstream-freebsd/lib/libc/string/wcsdup.c b/libc/upstream-freebsd/lib/libc/string/wcsdup.c
index 1e5db92..b97f766 100644
--- a/libc/upstream-freebsd/lib/libc/string/wcsdup.c
+++ b/libc/upstream-freebsd/lib/libc/string/wcsdup.c
@@ -1,4 +1,6 @@
 /*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
  * Copyright (c) 2005 Tim J. Robbins.
  * All rights reserved.
  *
@@ -25,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libc/string/wcsdup.c 326193 2017-11-25 17:12:48Z pfg $");
 
 #include <stdlib.h>
 #include <wchar.h>
diff --git a/libc/upstream-freebsd/lib/libc/string/wcslen.c b/libc/upstream-freebsd/lib/libc/string/wcslen.c
index ca3004e..c596825 100644
--- a/libc/upstream-freebsd/lib/libc/string/wcslen.c
+++ b/libc/upstream-freebsd/lib/libc/string/wcslen.c
@@ -1,4 +1,6 @@
 /*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
  * Copyright (c)1999 Citrus Project,
  * All rights reserved.
  *
@@ -32,7 +34,7 @@
 __RCSID("$NetBSD: wcslen.c,v 1.1 2000/12/23 23:14:36 itojun Exp $");
 #endif /* LIBC_SCCS and not lint */
 #endif
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libc/string/wcslen.c 326193 2017-11-25 17:12:48Z pfg $");
 
 #include <wchar.h>
 
diff --git a/libc/upstream-freebsd/lib/libc/string/wcsncasecmp.c b/libc/upstream-freebsd/lib/libc/string/wcsncasecmp.c
index a42d98c..a963444 100644
--- a/libc/upstream-freebsd/lib/libc/string/wcsncasecmp.c
+++ b/libc/upstream-freebsd/lib/libc/string/wcsncasecmp.c
@@ -1,4 +1,6 @@
 /*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
  * Copyright (c) 2009 David Schultz <das@FreeBSD.org>
  * All rights reserved.
  *
@@ -25,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libc/string/wcsncasecmp.c 326193 2017-11-25 17:12:48Z pfg $");
 
 #include <wchar.h>
 #include <wctype.h>
diff --git a/libc/upstream-freebsd/lib/libc/string/wcsncmp.c b/libc/upstream-freebsd/lib/libc/string/wcsncmp.c
index 8236d96..77b709c 100644
--- a/libc/upstream-freebsd/lib/libc/string/wcsncmp.c
+++ b/libc/upstream-freebsd/lib/libc/string/wcsncmp.c
@@ -1,4 +1,6 @@
-/*
+/*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
  * Copyright (c) 1989, 1993
  *	The Regents of the University of California.  All rights reserved.
  *
@@ -34,7 +36,7 @@
 __RCSID("$NetBSD: wcsncmp.c,v 1.3 2001/01/05 12:13:13 itojun Exp $");
 #endif /* LIBC_SCCS and not lint */
 #endif
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libc/string/wcsncmp.c 326025 2017-11-20 19:49:47Z pfg $");
 
 #include <wchar.h>
 
diff --git a/libc/upstream-freebsd/lib/libc/string/wcsncpy.c b/libc/upstream-freebsd/lib/libc/string/wcsncpy.c
index 215e9a1..4075ecc 100644
--- a/libc/upstream-freebsd/lib/libc/string/wcsncpy.c
+++ b/libc/upstream-freebsd/lib/libc/string/wcsncpy.c
@@ -1,4 +1,6 @@
 /*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
  * Copyright (c) 1990, 1993
  *	The Regents of the University of California.  All rights reserved.
  *
@@ -36,7 +38,7 @@
 #endif /* LIBC_SCCS and not lint */
 #endif
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libc/string/wcsncpy.c 326025 2017-11-20 19:49:47Z pfg $");
 
 #include <wchar.h>
 
diff --git a/libc/upstream-freebsd/lib/libc/string/wcsnlen.c b/libc/upstream-freebsd/lib/libc/string/wcsnlen.c
index f03cf76..271d341 100644
--- a/libc/upstream-freebsd/lib/libc/string/wcsnlen.c
+++ b/libc/upstream-freebsd/lib/libc/string/wcsnlen.c
@@ -1,4 +1,6 @@
 /*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
  * Copyright (c) 2009 David Schultz <das@FreeBSD.org>
  * All rights reserved.
  *
@@ -25,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libc/string/wcsnlen.c 326193 2017-11-25 17:12:48Z pfg $");
 
 #include <wchar.h>
 
diff --git a/libc/upstream-freebsd/lib/libc/string/wcspbrk.c b/libc/upstream-freebsd/lib/libc/string/wcspbrk.c
index 2ff71ba..63efb01 100644
--- a/libc/upstream-freebsd/lib/libc/string/wcspbrk.c
+++ b/libc/upstream-freebsd/lib/libc/string/wcspbrk.c
@@ -1,4 +1,6 @@
 /*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
  * Copyright (c)1999 Citrus Project,
  * All rights reserved.
  *
@@ -32,7 +34,7 @@
 __RCSID("$NetBSD: wcspbrk.c,v 1.1 2000/12/23 23:14:37 itojun Exp $");
 #endif /* LIBC_SCCS and not lint */
 #endif
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libc/string/wcspbrk.c 326193 2017-11-25 17:12:48Z pfg $");
 
 #include <wchar.h>
 
diff --git a/libc/upstream-freebsd/lib/libc/string/wcsrchr.c b/libc/upstream-freebsd/lib/libc/string/wcsrchr.c
index 37c81ec..97665ca 100644
--- a/libc/upstream-freebsd/lib/libc/string/wcsrchr.c
+++ b/libc/upstream-freebsd/lib/libc/string/wcsrchr.c
@@ -1,4 +1,6 @@
 /*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
  * Copyright (c) 2002 Tim J. Robbins
  * All rights reserved.
  *
@@ -25,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libc/string/wcsrchr.c 326193 2017-11-25 17:12:48Z pfg $");
 
 #include <wchar.h>
 
diff --git a/libc/upstream-freebsd/lib/libc/string/wcsspn.c b/libc/upstream-freebsd/lib/libc/string/wcsspn.c
index 6569206..b08a39e 100644
--- a/libc/upstream-freebsd/lib/libc/string/wcsspn.c
+++ b/libc/upstream-freebsd/lib/libc/string/wcsspn.c
@@ -1,4 +1,6 @@
 /*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
  * Copyright (c)1999 Citrus Project,
  * All rights reserved.
  *
@@ -32,7 +34,7 @@
 __RCSID("$NetBSD: wcsspn.c,v 1.1 2000/12/23 23:14:37 itojun Exp $");
 #endif /* LIBC_SCCS and not lint */
 #endif
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libc/string/wcsspn.c 326193 2017-11-25 17:12:48Z pfg $");
 
 #include <wchar.h>
 
diff --git a/libc/upstream-freebsd/lib/libc/string/wcsstr.c b/libc/upstream-freebsd/lib/libc/string/wcsstr.c
index ce598a6..4309025 100644
--- a/libc/upstream-freebsd/lib/libc/string/wcsstr.c
+++ b/libc/upstream-freebsd/lib/libc/string/wcsstr.c
@@ -1,4 +1,6 @@
 /*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
  * Copyright (c) 1990, 1993
  *	The Regents of the University of California.  All rights reserved.
  *
@@ -36,7 +38,7 @@
 #endif /* LIBC_SCCS and not lint */
 #endif
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libc/string/wcsstr.c 326025 2017-11-20 19:49:47Z pfg $");
 
 #include <wchar.h>
 
diff --git a/libc/upstream-freebsd/lib/libc/string/wcstok.c b/libc/upstream-freebsd/lib/libc/string/wcstok.c
index 441fbd4..8d62bf7 100644
--- a/libc/upstream-freebsd/lib/libc/string/wcstok.c
+++ b/libc/upstream-freebsd/lib/libc/string/wcstok.c
@@ -1,4 +1,6 @@
 /*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
  * Copyright (c) 1998 Softweyr LLC.  All rights reserved.
  *
  * strtok_r, from Berkeley strtok
@@ -33,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libc/string/wcstok.c 326025 2017-11-20 19:49:47Z pfg $");
 
 #include <wchar.h>
 
diff --git a/libc/upstream-freebsd/lib/libc/string/wmemchr.c b/libc/upstream-freebsd/lib/libc/string/wmemchr.c
index cab89c9..412a276 100644
--- a/libc/upstream-freebsd/lib/libc/string/wmemchr.c
+++ b/libc/upstream-freebsd/lib/libc/string/wmemchr.c
@@ -1,4 +1,6 @@
 /*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
  * Copyright (c)1999 Citrus Project,
  * All rights reserved.
  *
@@ -32,7 +34,7 @@
 __RCSID("$NetBSD: wmemchr.c,v 1.1 2000/12/23 23:14:37 itojun Exp $");
 #endif /* LIBC_SCCS and not lint */
 #endif
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libc/string/wmemchr.c 326193 2017-11-25 17:12:48Z pfg $");
 
 #include <wchar.h>
 
diff --git a/libc/upstream-freebsd/lib/libc/string/wmemcmp.c b/libc/upstream-freebsd/lib/libc/string/wmemcmp.c
index fdb1f98..c1e9f3c 100644
--- a/libc/upstream-freebsd/lib/libc/string/wmemcmp.c
+++ b/libc/upstream-freebsd/lib/libc/string/wmemcmp.c
@@ -1,4 +1,6 @@
 /*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
  * Copyright (c)1999 Citrus Project,
  * All rights reserved.
  *
@@ -32,7 +34,7 @@
 __RCSID("$NetBSD: wmemcmp.c,v 1.1 2000/12/23 23:14:37 itojun Exp $");
 #endif /* LIBC_SCCS and not lint */
 #endif
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libc/string/wmemcmp.c 326193 2017-11-25 17:12:48Z pfg $");
 
 #include <wchar.h>
 
diff --git a/libc/upstream-freebsd/lib/libc/string/wmemcpy.c b/libc/upstream-freebsd/lib/libc/string/wmemcpy.c
index c10770c..e0d6c04 100644
--- a/libc/upstream-freebsd/lib/libc/string/wmemcpy.c
+++ b/libc/upstream-freebsd/lib/libc/string/wmemcpy.c
@@ -1,4 +1,6 @@
 /*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
  * Copyright (c)1999 Citrus Project,
  * All rights reserved.
  *
@@ -32,7 +34,7 @@
 __RCSID("$NetBSD: wmemcpy.c,v 1.1 2000/12/23 23:14:37 itojun Exp $");
 #endif /* LIBC_SCCS and not lint */
 #endif
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libc/string/wmemcpy.c 326193 2017-11-25 17:12:48Z pfg $");
 
 #include <string.h>
 #include <wchar.h>
diff --git a/libc/upstream-freebsd/lib/libc/string/wmemmove.c b/libc/upstream-freebsd/lib/libc/string/wmemmove.c
index 05cfd10..b84c2c0 100644
--- a/libc/upstream-freebsd/lib/libc/string/wmemmove.c
+++ b/libc/upstream-freebsd/lib/libc/string/wmemmove.c
@@ -1,4 +1,6 @@
 /*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
  * Copyright (c)1999 Citrus Project,
  * All rights reserved.
  *
@@ -32,7 +34,7 @@
 __RCSID("$NetBSD: wmemmove.c,v 1.1 2000/12/23 23:14:37 itojun Exp $");
 #endif /* LIBC_SCCS and not lint */
 #endif
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libc/string/wmemmove.c 326193 2017-11-25 17:12:48Z pfg $");
 
 #include <string.h>
 #include <wchar.h>
diff --git a/libc/upstream-freebsd/lib/libc/string/wmemset.c b/libc/upstream-freebsd/lib/libc/string/wmemset.c
index 0e96356..d4d6308 100644
--- a/libc/upstream-freebsd/lib/libc/string/wmemset.c
+++ b/libc/upstream-freebsd/lib/libc/string/wmemset.c
@@ -1,4 +1,6 @@
 /*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
  * Copyright (c)1999 Citrus Project,
  * All rights reserved.
  *
@@ -32,7 +34,7 @@
 __RCSID("$NetBSD: wmemset.c,v 1.1 2000/12/23 23:14:37 itojun Exp $");
 #endif /* LIBC_SCCS and not lint */
 #endif
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libc/string/wmemset.c 326193 2017-11-25 17:12:48Z pfg $");
 
 #include <wchar.h>
 
diff --git a/libm/upstream-freebsd/lib/msun/src/e_exp.c b/libm/upstream-freebsd/lib/msun/src/e_exp.c
index 94c9769..dd88d3e 100644
--- a/libm/upstream-freebsd/lib/msun/src/e_exp.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_exp.c
@@ -11,7 +11,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/msun/src/e_exp.c 352710 2019-09-25 18:50:57Z dim $");
 
 /* __ieee754_exp(x)
  * Returns the exponential of x.
@@ -145,9 +145,9 @@
     /* x is now in primary range */
 	t  = x*x;
 	if(k >= -1021)
-	    INSERT_WORDS(twopk,0x3ff00000+(k<<20), 0);
+	    INSERT_WORDS(twopk,((u_int32_t)(0x3ff+k))<<20, 0);
 	else
-	    INSERT_WORDS(twopk,0x3ff00000+((k+1000)<<20), 0);
+	    INSERT_WORDS(twopk,((u_int32_t)(0x3ff+(k+1000)))<<20, 0);
 	c  = x - t*(P1+t*(P2+t*(P3+t*(P4+t*P5))));
 	if(k==0) 	return one-((x*c)/(c-2.0)-x); 
 	else 		y = one-((lo-(x*c)/(2.0-c))-hi);
diff --git a/libm/upstream-freebsd/lib/msun/src/e_expf.c b/libm/upstream-freebsd/lib/msun/src/e_expf.c
index b1fe2c5..aaf6d5f 100644
--- a/libm/upstream-freebsd/lib/msun/src/e_expf.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_expf.c
@@ -14,7 +14,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/msun/src/e_expf.c 352710 2019-09-25 18:50:57Z dim $");
 
 #include <float.h>
 
@@ -83,9 +83,9 @@
     /* x is now in primary range */
 	t  = x*x;
 	if(k >= -125)
-	    SET_FLOAT_WORD(twopk,0x3f800000+(k<<23));
+	    SET_FLOAT_WORD(twopk,((u_int32_t)(0x7f+k))<<23);
 	else
-	    SET_FLOAT_WORD(twopk,0x3f800000+((k+100)<<23));
+	    SET_FLOAT_WORD(twopk,((u_int32_t)(0x7f+(k+100)))<<23);
 	c  = x - t*(P1+t*P2);
 	if(k==0) 	return one-((x*c)/(c-(float)2.0)-x);
 	else 		y = one-((lo-(x*c)/((float)2.0-c))-hi);
diff --git a/libm/upstream-freebsd/lib/msun/src/e_j0.c b/libm/upstream-freebsd/lib/msun/src/e_j0.c
index 6bca542..a008b42 100644
--- a/libm/upstream-freebsd/lib/msun/src/e_j0.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_j0.c
@@ -11,7 +11,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/msun/src/e_j0.c 343023 2019-01-14 15:48:35Z pfg $");
+__FBSDID("$FreeBSD: head/lib/msun/src/e_j0.c 343953 2019-02-10 08:46:07Z peterj $");
 
 /* __ieee754_j0(x), __ieee754_y0(x)
  * Bessel function of the first and second kinds of order zero.
@@ -93,8 +93,7 @@
 	if(ix>=0x7ff00000) return one/(x*x);
 	x = fabs(x);
 	if(ix >= 0x40000000) {	/* |x| >= 2.0 */
-		s = sin(x);
-		c = cos(x);
+		sincos(x, &s, &c);
 		ss = s-c;
 		cc = s+c;
 		if(ix<0x7fe00000) {  /* Make sure x+x does not overflow. */
@@ -173,8 +172,7 @@
          *              sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x))
          * to compute the worse one.
          */
-                s = sin(x);
-                c = cos(x);
+                sincos(x, &s, &c);
                 ss = s-c;
                 cc = s+c;
 	/*
diff --git a/libm/upstream-freebsd/lib/msun/src/e_j0f.c b/libm/upstream-freebsd/lib/msun/src/e_j0f.c
index 714caac..495a5e5 100644
--- a/libm/upstream-freebsd/lib/msun/src/e_j0f.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_j0f.c
@@ -14,7 +14,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/msun/src/e_j0f.c 343023 2019-01-14 15:48:35Z pfg $");
+__FBSDID("$FreeBSD: head/lib/msun/src/e_j0f.c 343953 2019-02-10 08:46:07Z peterj $");
 
 /*
  * See e_j0.c for complete comments.
@@ -55,8 +55,7 @@
 	if(ix>=0x7f800000) return one/(x*x);
 	x = fabsf(x);
 	if(ix >= 0x40000000) {	/* |x| >= 2.0 */
-		s = sinf(x);
-		c = cosf(x);
+		sincosf(x, &s, &c);
 		ss = s-c;
 		cc = s+c;
 		if(ix<0x7f000000) {  /* Make sure x+x does not overflow. */
@@ -128,8 +127,7 @@
          *              sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x))
          * to compute the worse one.
          */
-                s = sinf(x);
-                c = cosf(x);
+                sincosf(x, &s, &c);
                 ss = s-c;
                 cc = s+c;
 	/*
diff --git a/libm/upstream-freebsd/lib/msun/src/e_j1.c b/libm/upstream-freebsd/lib/msun/src/e_j1.c
index 78bb329..6d1c41c 100644
--- a/libm/upstream-freebsd/lib/msun/src/e_j1.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_j1.c
@@ -11,7 +11,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/msun/src/e_j1.c 336089 2018-07-08 16:26:13Z markj $");
+__FBSDID("$FreeBSD: head/lib/msun/src/e_j1.c 343953 2019-02-10 08:46:07Z peterj $");
 
 /* __ieee754_j1(x), __ieee754_y1(x)
  * Bessel function of the first and second kinds of order zero.
@@ -94,8 +94,7 @@
 	if(ix>=0x7ff00000) return one/x;
 	y = fabs(x);
 	if(ix >= 0x40000000) {	/* |x| >= 2.0 */
-		s = sin(y);
-		c = cos(y);
+		sincos(y, &s, &c);
 		ss = -s-c;
 		cc = s-c;
 		if(ix<0x7fe00000) {  /* make sure y+y not overflow */
@@ -159,8 +158,7 @@
 	/* y1(x<0) = NaN and raise invalid exception. */
         if(hx<0) return vzero/vzero;
         if(ix >= 0x40000000) {  /* |x| >= 2.0 */
-                s = sin(x);
-                c = cos(x);
+                sincos(x, &s, &c);
                 ss = -s-c;
                 cc = s-c;
                 if(ix<0x7fe00000) {  /* make sure x+x not overflow */
diff --git a/libm/upstream-freebsd/lib/msun/src/e_j1f.c b/libm/upstream-freebsd/lib/msun/src/e_j1f.c
index 3abe201..31fc28a 100644
--- a/libm/upstream-freebsd/lib/msun/src/e_j1f.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_j1f.c
@@ -14,7 +14,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/msun/src/e_j1f.c 336089 2018-07-08 16:26:13Z markj $");
+__FBSDID("$FreeBSD: head/lib/msun/src/e_j1f.c 343953 2019-02-10 08:46:07Z peterj $");
 
 /*
  * See e_j1.c for complete comments.
@@ -56,8 +56,7 @@
 	if(ix>=0x7f800000) return one/x;
 	y = fabsf(x);
 	if(ix >= 0x40000000) {	/* |x| >= 2.0 */
-		s = sinf(y);
-		c = cosf(y);
+		sincosf(y, &s, &c);
 		ss = -s-c;
 		cc = s-c;
 		if(ix<0x7f000000) {  /* make sure y+y not overflow */
@@ -114,8 +113,7 @@
 	if(ix==0) return -one/vzero;
 	if(hx<0) return vzero/vzero;
         if(ix >= 0x40000000) {  /* |x| >= 2.0 */
-                s = sinf(x);
-                c = cosf(x);
+                sincosf(x, &s, &c);
                 ss = -s-c;
                 cc = s-c;
                 if(ix<0x7f000000) {  /* make sure x+x not overflow */
diff --git a/libm/upstream-freebsd/lib/msun/src/e_jn.c b/libm/upstream-freebsd/lib/msun/src/e_jn.c
index 58ec905..c039cf2 100644
--- a/libm/upstream-freebsd/lib/msun/src/e_jn.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_jn.c
@@ -11,7 +11,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/msun/src/e_jn.c 336089 2018-07-08 16:26:13Z markj $");
+__FBSDID("$FreeBSD: head/lib/msun/src/e_jn.c 343953 2019-02-10 08:46:07Z peterj $");
 
 /*
  * __ieee754_jn(n, x), __ieee754_yn(n, x)
@@ -54,7 +54,7 @@
 __ieee754_jn(int n, double x)
 {
 	int32_t i,hx,ix,lx, sgn;
-	double a, b, temp, di;
+	double a, b, c, s, temp, di;
 	double z, w;
 
     /* J(-n,x) = (-1)^n * J(n, x), J(n, -x) = (-1)^n * J(n, x)
@@ -91,11 +91,12 @@
      *		   2	-s+c		-c-s
      *		   3	 s+c		 c-s
      */
+		sincos(x, &s, &c);
 		switch(n&3) {
-		    case 0: temp =  cos(x)+sin(x); break;
-		    case 1: temp = -cos(x)+sin(x); break;
-		    case 2: temp = -cos(x)-sin(x); break;
-		    case 3: temp =  cos(x)-sin(x); break;
+		    case 0: temp =  c+s; break;
+		    case 1: temp = -c+s; break;
+		    case 2: temp = -c-s; break;
+		    case 3: temp =  c-s; break;
 		}
 		b = invsqrtpi*temp/sqrt(x);
 	    } else {
@@ -216,7 +217,7 @@
 {
 	int32_t i,hx,ix,lx;
 	int32_t sign;
-	double a, b, temp;
+	double a, b, c, s, temp;
 
 	EXTRACT_WORDS(hx,lx,x);
 	ix = 0x7fffffff&hx;
@@ -248,11 +249,12 @@
      *		   2	-s+c		-c-s
      *		   3	 s+c		 c-s
      */
+		sincos(x, &s, &c);
 		switch(n&3) {
-		    case 0: temp =  sin(x)-cos(x); break;
-		    case 1: temp = -sin(x)-cos(x); break;
-		    case 2: temp = -sin(x)+cos(x); break;
-		    case 3: temp =  sin(x)+cos(x); break;
+		    case 0: temp =  s-c; break;
+		    case 1: temp = -s-c; break;
+		    case 2: temp = -s+c; break;
+		    case 3: temp =  s+c; break;
 		}
 		b = invsqrtpi*temp/sqrt(x);
 	} else {
diff --git a/libm/upstream-freebsd/lib/msun/src/s_expm1.c b/libm/upstream-freebsd/lib/msun/src/s_expm1.c
index 37998a3..21256ce 100644
--- a/libm/upstream-freebsd/lib/msun/src/s_expm1.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_expm1.c
@@ -11,7 +11,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/msun/src/s_expm1.c 352710 2019-09-25 18:50:57Z dim $");
 
 /* expm1(x)
  * Returns exp(x)-1, the exponential of x minus 1.
@@ -188,7 +188,7 @@
 	e  = hxs*((r1-t)/(6.0 - x*t));
 	if(k==0) return x - (x*e-hxs);		/* c is 0 */
 	else {
-	    INSERT_WORDS(twopk,0x3ff00000+(k<<20),0);	/* 2^k */
+	    INSERT_WORDS(twopk,((u_int32_t)(0x3ff+k))<<20,0);	/* 2^k */
 	    e  = (x*(e-c)-c);
 	    e -= hxs;
 	    if(k== -1) return 0.5*(x-e)-0.5;
diff --git a/libm/upstream-freebsd/lib/msun/src/s_expm1f.c b/libm/upstream-freebsd/lib/msun/src/s_expm1f.c
index c0a3934..4d9ab36 100644
--- a/libm/upstream-freebsd/lib/msun/src/s_expm1f.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_expm1f.c
@@ -14,7 +14,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/msun/src/s_expm1f.c 352710 2019-09-25 18:50:57Z dim $");
 
 #include <float.h>
 
@@ -94,7 +94,7 @@
 	e  = hxs*((r1-t)/((float)6.0 - x*t));
 	if(k==0) return x - (x*e-hxs);		/* c is 0 */
 	else {
-	    SET_FLOAT_WORD(twopk,0x3f800000+(k<<23));	/* 2^k */
+	    SET_FLOAT_WORD(twopk,((u_int32_t)(0x7f+k))<<23);	/* 2^k */
 	    e  = (x*(e-c)-c);
 	    e -= hxs;
 	    if(k== -1) return (float)0.5*(x-e)-(float)0.5;
diff --git a/libm/upstream-freebsd/lib/msun/src/s_lround.c b/libm/upstream-freebsd/lib/msun/src/s_lround.c
index b6a25b7..ce2aee7 100644
--- a/libm/upstream-freebsd/lib/msun/src/s_lround.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_lround.c
@@ -32,7 +32,7 @@
 #include <math.h>
 
 #ifndef type
-__FBSDID("$FreeBSD: head/lib/msun/src/s_lround.c 326219 2017-11-26 02:00:33Z pfg $");
+__FBSDID("$FreeBSD: head/lib/msun/src/s_lround.c 353329 2019-10-08 21:39:51Z brooks $");
 #define type		double
 #define	roundit		round
 #define dtype		long
@@ -49,9 +49,9 @@
  * that everything is in range.  At compile time, INRANGE(x) should reduce to
  * two floating-point comparisons in the former case, or TRUE otherwise.
  */
-static const type dtype_min = DTYPE_MIN - 0.5;
-static const type dtype_max = DTYPE_MAX + 0.5;
-#define	INRANGE(x)	(dtype_max - DTYPE_MAX != 0.5 || \
+static const type dtype_min = (type)DTYPE_MIN - 0.5;
+static const type dtype_max = (type)DTYPE_MAX + 0.5;
+#define	INRANGE(x)	(dtype_max - (type)DTYPE_MAX != 0.5 || \
 			 ((x) > dtype_min && (x) < dtype_max))
 
 dtype
diff --git a/linker/linker.cpp b/linker/linker.cpp
index dec575b..c1bccfe 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -68,6 +68,7 @@
 #include "linker_tls.h"
 #include "linker_utils.h"
 
+#include "private/bionic_call_ifunc_resolver.h"
 #include "private/bionic_globals.h"
 #include "android-base/macros.h"
 #include "android-base/strings.h"
@@ -2690,11 +2691,9 @@
 ElfW(Addr) call_ifunc_resolver(ElfW(Addr) resolver_addr) {
   if (g_is_ldd) return 0;
 
-  typedef ElfW(Addr) (*ifunc_resolver_t)(void);
-  ifunc_resolver_t ifunc_resolver = reinterpret_cast<ifunc_resolver_t>(resolver_addr);
-  ElfW(Addr) ifunc_addr = ifunc_resolver();
+  ElfW(Addr) ifunc_addr = __bionic_call_ifunc_resolver(resolver_addr);
   TRACE_TYPE(RELO, "Called ifunc_resolver@%p. The result is %p",
-      ifunc_resolver, reinterpret_cast<void*>(ifunc_addr));
+      reinterpret_cast<void *>(resolver_addr), reinterpret_cast<void*>(ifunc_addr));
 
   return ifunc_addr;
 }
diff --git a/tests/Android.bp b/tests/Android.bp
index f0fe5e6..1755053 100644
--- a/tests/Android.bp
+++ b/tests/Android.bp
@@ -751,6 +751,33 @@
     ],
 }
 
+cc_test {
+    name: "bionic-stress-tests",
+    defaults: [
+        "bionic_tests_defaults",
+    ],
+
+    // For now, these tests run forever, so do not use the isolation framework.
+    isolated: false,
+
+    srcs: [
+        "malloc_stress_test.cpp",
+    ],
+
+    shared_libs: [
+        "libbase",
+    ],
+
+    target: {
+        android: {
+            static_libs: [
+                "libmeminfo",
+                "libprocinfo",
+            ],
+        },
+    },
+}
+
 // -----------------------------------------------------------------------------
 // Tests for the device linked against bionic's static library. Run with:
 //   adb shell /data/nativetest/bionic-unit-tests-static/bionic-unit-tests-static
diff --git a/tests/ifunc_test.cpp b/tests/ifunc_test.cpp
index 7ab5899..e69271f 100644
--- a/tests/ifunc_test.cpp
+++ b/tests/ifunc_test.cpp
@@ -16,12 +16,19 @@
 
 #include <gtest/gtest.h>
 
+#include <sys/auxv.h>
+#if defined(__BIONIC__)
+#include <sys/ifunc.h>
+#endif
+
+typedef int (*fn_ptr_t)();
+
 int ret42() {
   return 42;
 }
 
-extern "C" void* resolver() {
-  return (void*)ret42;
+extern "C" fn_ptr_t resolver() {
+  return ret42;
 }
 
 int ifunc() __attribute__((ifunc("resolver")));
@@ -29,3 +36,51 @@
 TEST(ifunc, function) {
   ASSERT_EQ(42, ifunc());
 }
+
+#if defined(__BIONIC__)
+
+#if defined(__aarch64__)
+
+static uint64_t g_hwcap;
+static __ifunc_arg_t g_arg;
+
+extern "C" fn_ptr_t hwcap_resolver(uint64_t hwcap, __ifunc_arg_t* arg) {
+  g_hwcap = hwcap;
+  g_arg = *arg;
+  return ret42;
+}
+
+#elif defined(__arm__)
+
+static unsigned long g_hwcap;
+
+extern "C" fn_ptr_t hwcap_resolver(unsigned long hwcap) {
+  g_hwcap = hwcap;
+  return ret42;
+}
+
+#else
+
+extern "C" fn_ptr_t hwcap_resolver() {
+  return ret42;
+}
+
+#endif
+
+int hwcap() __attribute__((ifunc("hwcap_resolver")));
+
+TEST(ifunc, hwcap) {
+  ASSERT_EQ(42, hwcap());
+
+#if defined(__aarch64__)
+  EXPECT_EQ(getauxval(AT_HWCAP) | _IFUNC_ARG_HWCAP, g_hwcap);
+
+  EXPECT_EQ(sizeof(__ifunc_arg_t), g_arg._size);
+  EXPECT_EQ(getauxval(AT_HWCAP), g_arg._hwcap);
+  EXPECT_EQ(getauxval(AT_HWCAP2), g_arg._hwcap2);
+#elif defined(__arm__)
+  EXPECT_EQ(getauxval(AT_HWCAP), g_hwcap);
+#endif
+}
+
+#endif  // defined(__BIONIC__)
diff --git a/tests/malloc_stress_test.cpp b/tests/malloc_stress_test.cpp
new file mode 100644
index 0000000..6c5cc06
--- /dev/null
+++ b/tests/malloc_stress_test.cpp
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gtest/gtest.h>
+
+#include <inttypes.h>
+#include <malloc.h>
+#include <limits.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <thread>
+#include <vector>
+
+#include <android-base/strings.h>
+#if defined(__BIONIC__)
+#include <meminfo/procmeminfo.h>
+#include <procinfo/process_map.h>
+#endif
+
+TEST(malloc_stress, multiple_threads_forever) {
+  constexpr size_t kMaxThreads = 256;
+  constexpr size_t kAllocSize = 4096;
+#if defined(__BIONIC__)
+  uint64_t rss_min = UINT64_MAX;
+  uint64_t rss_max = 0;
+  uint64_t vss_min = UINT64_MAX;
+  uint64_t vss_max = 0;
+  ASSERT_EQ(1, mallopt(M_DECAY_TIME, 1));
+#endif
+  uint64_t mallinfo_min = UINT64_MAX;
+  uint64_t mallinfo_max = 0;
+  for (size_t i = 0; ; i++) {
+    printf("Pass %zu\n", i);
+
+    std::vector<std::thread*> threads;
+    for (size_t i = 0; i < kMaxThreads; i++) {
+      threads.push_back(new std::thread([]() {
+        void* buf = malloc(4096);
+        if (buf == nullptr) {
+          printf("Failed to allocate memory\n");
+          _exit(1);
+        }
+        memset(buf, 0, kAllocSize);
+        sleep(1);
+        free(buf);
+      }));
+    }
+
+    for (auto thread : threads) {
+      thread->join();
+      delete thread;
+    }
+    threads.clear();
+
+#if defined(__BIONIC__)
+    android::meminfo::ProcMemInfo proc_mem(getpid());
+    const std::vector<android::meminfo::Vma>& maps = proc_mem.MapsWithoutUsageStats();
+    uint64_t rss_bytes = 0;
+    uint64_t vss_bytes = 0;
+    for (auto& vma : maps) {
+      if (vma.name == "[anon:libc_malloc]" || android::base::StartsWith(vma.name, "[anon:scudo:")) {
+        android::meminfo::Vma update_vma(vma);
+        ASSERT_TRUE(proc_mem.FillInVmaStats(update_vma));
+        rss_bytes += update_vma.usage.rss;
+        vss_bytes += update_vma.usage.vss;
+      }
+    }
+    if (rss_bytes < rss_min) {
+      rss_min = rss_bytes;
+    }
+    if (rss_bytes > rss_max) {
+      rss_max = rss_bytes;
+    }
+    if (vss_bytes < vss_min) {
+      vss_min = vss_bytes;
+    }
+    if (vss_bytes > vss_max) {
+      vss_max = vss_bytes;
+    }
+    printf("RSS %" PRIu64 " %0.2fMB\n", rss_bytes, rss_bytes / (1024.0 * 1024.0));
+    printf("  Min %" PRIu64 " %0.2fMB\n", rss_min, rss_min / (1024.0 * 1024.0));
+    printf("  Max %" PRIu64 " %0.2fMB\n", rss_max, rss_max / (1024.0 * 1024.0));
+    printf("VSS %" PRIu64 " %0.2f MB\n", vss_bytes, vss_bytes / (1024.0 * 1024.0));
+    printf("  Min %" PRIu64 " %0.2fMB\n", vss_min, vss_min / (1024.0 * 1024.0));
+    printf("  Max %" PRIu64 " %0.2fMB\n", vss_max, vss_max / (1024.0 * 1024.0));
+#endif
+
+    size_t mallinfo_bytes = mallinfo().uordblks;
+    if (mallinfo_bytes < mallinfo_min) {
+      mallinfo_min = mallinfo_bytes;
+    }
+    if (mallinfo_bytes > mallinfo_max) {
+      mallinfo_max = mallinfo_bytes;
+    }
+    printf("Allocated memory %zu %0.2fMB\n", mallinfo_bytes, mallinfo_bytes / (1024.0 * 1024.0));
+    printf("  Min %" PRIu64 " %0.2fMB\n", mallinfo_min, mallinfo_min / (1024.0 * 1024.0));
+    printf("  Max %" PRIu64 " %0.2fMB\n", mallinfo_max, mallinfo_max / (1024.0 * 1024.0));
+  }
+}
diff --git a/tests/signal_test.cpp b/tests/signal_test.cpp
index 1ae174a..6db7751 100644
--- a/tests/signal_test.cpp
+++ b/tests/signal_test.cpp
@@ -20,6 +20,7 @@
 #include <sys/types.h>
 #include <unistd.h>
 
+#include <chrono>
 #include <thread>
 
 #include <android-base/macros.h>
@@ -27,6 +28,8 @@
 
 #include "SignalUtils.h"
 
+using namespace std::chrono_literals;
+
 static int SIGNAL_MIN() {
   return 1; // Signals start at 1 (SIGHUP), not 0.
 }
@@ -753,12 +756,6 @@
   ASSERT_EQ(0, errno);
 }
 
-static int64_t NanoTime() {
-  timespec t;
-  clock_gettime(CLOCK_MONOTONIC, &t);
-  return static_cast<int64_t>(t.tv_sec) * 1000000000LL + t.tv_nsec;
-}
-
 TEST(signal, sigtimedwait_timeout) {
   // Block SIGALRM.
   sigset_t just_SIGALRM;
@@ -768,13 +765,14 @@
   ASSERT_EQ(0, sigprocmask(SIG_BLOCK, &just_SIGALRM, &original_set));
 
   // Wait timeout.
-  int64_t start_time = NanoTime();
+  auto t0 = std::chrono::steady_clock::now();
   siginfo_t info;
   timespec timeout = { .tv_sec = 0, .tv_nsec = 1000000 };
   errno = 0;
   ASSERT_EQ(-1, sigtimedwait(&just_SIGALRM, &info, &timeout));
   ASSERT_EQ(EAGAIN, errno);
-  ASSERT_GE(NanoTime() - start_time, 1000000);
+  auto t1 = std::chrono::steady_clock::now();
+  ASSERT_GE(t1-t0, 1000000ns);
 
   ASSERT_EQ(0, sigprocmask(SIG_SETMASK, &original_set, nullptr));
 }
diff --git a/tests/system_properties_test2.cpp b/tests/system_properties_test2.cpp
index c061faa..b9936dd 100644
--- a/tests/system_properties_test2.cpp
+++ b/tests/system_properties_test2.cpp
@@ -19,16 +19,16 @@
 #include <errno.h>
 #include <sys/wait.h>
 #include <unistd.h>
+
+#include <chrono>
 #include <sstream>
 #include <string>
 
 #if defined(__BIONIC__)
 #include <sys/system_properties.h>
-
-static uint64_t NanoTime() {
-  timespec now;
-  clock_gettime(CLOCK_MONOTONIC, &now);
-  return static_cast<uint64_t>(now.tv_sec) * UINT64_C(1000000000) + now.tv_nsec;
+int64_t NanoTime() {
+  auto t = std::chrono::time_point_cast<std::chrono::nanoseconds>(std::chrono::steady_clock::now());
+  return t.time_since_epoch().count();
 }
 #endif
 
diff --git a/tests/time_test.cpp b/tests/time_test.cpp
index 4e17242..378b4ac 100644
--- a/tests/time_test.cpp
+++ b/tests/time_test.cpp
@@ -24,13 +24,17 @@
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <unistd.h>
+
 #include <atomic>
+#include <chrono>
 
 #include "SignalUtils.h"
 #include "utils.h"
 
 #include "private/bionic_constants.h"
 
+using namespace std::chrono_literals;
+
 TEST(time, time) {
   // Acquire time
   time_t p1, t1 = time(&p1);
@@ -797,7 +801,7 @@
   ASSERT_EQ(EINVAL, errno);
 }
 
-TEST(time, clock_nanosleep) {
+TEST(time, clock_nanosleep_EINVAL) {
   timespec in;
   timespec out;
   ASSERT_EQ(EINVAL, clock_nanosleep(-1, 0, &in, &out));
@@ -810,6 +814,29 @@
   ASSERT_EQ(EINVAL, clock_nanosleep(CLOCK_THREAD_CPUTIME_ID, 0, &in, nullptr));
 }
 
+TEST(time, clock_nanosleep) {
+  auto t0 = std::chrono::steady_clock::now();
+  const timespec ts = {.tv_nsec = 5000000};
+  ASSERT_EQ(0, clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, nullptr));
+  auto t1 = std::chrono::steady_clock::now();
+  ASSERT_GE(t1-t0, 5000000ns);
+}
+
+TEST(time, nanosleep) {
+  auto t0 = std::chrono::steady_clock::now();
+  const timespec ts = {.tv_nsec = 5000000};
+  ASSERT_EQ(0, nanosleep(&ts, nullptr));
+  auto t1 = std::chrono::steady_clock::now();
+  ASSERT_GE(t1-t0, 5000000ns);
+}
+
+TEST(time, nanosleep_EINVAL) {
+  timespec ts = {.tv_sec = -1};
+  errno = 0;
+  ASSERT_EQ(-1, nanosleep(&ts, nullptr));
+  ASSERT_EQ(EINVAL, errno);
+}
+
 TEST(time, bug_31938693) {
   // User-visible symptoms in N:
   // http://b/31938693
diff --git a/tests/unistd_test.cpp b/tests/unistd_test.cpp
index 10c1710..99d92e6 100644
--- a/tests/unistd_test.cpp
+++ b/tests/unistd_test.cpp
@@ -33,6 +33,8 @@
 #include <sys/wait.h>
 #include <unistd.h>
 
+#include <chrono>
+
 #include <android-base/file.h>
 #include <android-base/strings.h>
 
@@ -46,6 +48,8 @@
 #define UNISTD_DEATHTEST unistd_DeathTest
 #endif
 
+using namespace std::chrono_literals;
+
 static void* get_brk() {
   return sbrk(0);
 }
@@ -1516,3 +1520,17 @@
   swab("hello", buf, -1);
   ASSERT_EQ('x', buf[0]);
 }
+
+TEST(UNISTD_TEST, usleep) {
+  auto t0 = std::chrono::steady_clock::now();
+  ASSERT_EQ(0, usleep(5000));
+  auto t1 = std::chrono::steady_clock::now();
+  ASSERT_GE(t1-t0, 5000us);
+}
+
+TEST(UNISTD_TEST, sleep) {
+  auto t0 = std::chrono::steady_clock::now();
+  ASSERT_EQ(0U, sleep(1));
+  auto t1 = std::chrono::steady_clock::now();
+  ASSERT_GE(t1-t0, 1s);
+}
diff --git a/tests/utils.h b/tests/utils.h
index fe41019..1f4cece 100644
--- a/tests/utils.h
+++ b/tests/utils.h
@@ -14,8 +14,7 @@
  * limitations under the License.
  */
 
-#ifndef __TEST_UTILS_H
-#define __TEST_UTILS_H
+#pragma once
 
 #include <dlfcn.h>
 #include <fcntl.h>
@@ -254,5 +253,3 @@
   std::string output_;
 };
 #endif
-
-#endif