Merge "Sync libm with upstream FreeBSD."
diff --git a/libc/SYSCALLS.TXT b/libc/SYSCALLS.TXT
index 7cf7a2d..33a8a61 100644
--- a/libc/SYSCALLS.TXT
+++ b/libc/SYSCALLS.TXT
@@ -113,6 +113,7 @@
 int         msync(const void*, size_t, int)    all
 int         mprotect(const void*, size_t, int)  all
 int         madvise(void*, size_t, int)  all
+int         process_madvise(int, const struct iovec*, size_t, int, unsigned int)     all
 int mlock(const void* addr, size_t len)    all
 int mlock2(const void* addr, size_t len, int flags)    all
 int         munlock(const void* addr, size_t len)   all
diff --git a/libc/bionic/libc_init_common.cpp b/libc/bionic/libc_init_common.cpp
index f2c3f1c..01cd2e5 100644
--- a/libc/bionic/libc_init_common.cpp
+++ b/libc/bionic/libc_init_common.cpp
@@ -87,6 +87,11 @@
 }
 
 void __libc_init_scudo() {
+  // Heap tagging level *must* be set before interacting with Scudo, otherwise
+  // the primary will be mapped with PROT_MTE even if MTE is is not enabled in
+  // this process.
+  SetDefaultHeapTaggingLevel();
+
 // TODO(b/158870657) make this unconditional when all devices support SCUDO.
 #if defined(USE_SCUDO)
 #if defined(SCUDO_PATTERN_FILL_CONTENTS)
@@ -95,7 +100,6 @@
   scudo_malloc_set_zero_contents(1);
 #endif
 #endif
-  SetDefaultHeapTaggingLevel();
 }
 
 __BIONIC_WEAK_FOR_NATIVE_BRIDGE
diff --git a/libc/include/sys/mman.h b/libc/include/sys/mman.h
index fe4ea7f..3b44dab 100644
--- a/libc/include/sys/mman.h
+++ b/libc/include/sys/mman.h
@@ -32,6 +32,7 @@
 #include <sys/types.h>
 #include <linux/memfd.h>
 #include <linux/mman.h>
+#include <linux/uio.h>
 
 __BEGIN_DECLS
 
@@ -161,6 +162,15 @@
  */
 int madvise(void* __addr, size_t __size, int __advice);
 
+/**
+ * [process_madvise(2)](http://man7.org/linux/man-pages/man2/process_madvise.2.html)
+ * works just like madvise(2) but applies to the process specified by the given
+ * PID file descriptor.
+ *
+ * Returns 0 on success, and returns -1 and sets `errno` on failure.
+ */
+int process_madvise(int __pid_fd, const struct iovec* __iov, size_t __count, int __advice, unsigned int __flags);
+
 #if defined(__USE_GNU)
 
 /**
diff --git a/libc/libc.map.txt b/libc/libc.map.txt
index a17a33f..f4f35ac 100644
--- a/libc/libc.map.txt
+++ b/libc/libc.map.txt
@@ -1552,12 +1552,13 @@
 
 LIBC_S { # introduced=S
   global:
-    ffsl;
-    ffsll;
     __libc_get_static_tls_bounds;
     __libc_register_thread_exit_callback;
     __libc_iterate_dynamic_tls;
     __libc_register_dynamic_tls_listeners;
+    ffsl;
+    ffsll;
+    process_madvise;
 } LIBC_R;
 
 LIBC_PRIVATE {
diff --git a/tests/Android.bp b/tests/Android.bp
index 678eae8..a6a930e 100644
--- a/tests/Android.bp
+++ b/tests/Android.bp
@@ -559,6 +559,7 @@
         "-U_FORTIFY_SOURCE",
     ],
     srcs: ["fortify_test_main.cpp"],
+    tidy: false,
     target: {
         host: {
             clang_cflags: ["-D__clang__"],
@@ -597,6 +598,7 @@
         "-D__clang_analyzer__",
     ],
     srcs: ["clang_fortify_tests.cpp"],
+    tidy: false,
 }
 
 cc_test_library {
@@ -638,6 +640,7 @@
         "-U_FORTIFY_SOURCE",
     ],
     srcs: ["clang_fortify_tests.cpp"],
+    tidy: false,
     target: {
         host: {
             clang_cflags: ["-D__clang__"],
diff --git a/tests/dlext_test.cpp b/tests/dlext_test.cpp
index 01bf8ab..e3caf0e 100644
--- a/tests/dlext_test.cpp
+++ b/tests/dlext_test.cpp
@@ -717,13 +717,12 @@
   uint64_t addr = reinterpret_cast<uint64_t>(ptr);
   std::string found_name = "<not found>";
 
-  EXPECT_TRUE(android::procinfo::ReadMapFile(
-      "/proc/self/maps",
-      [&](uint64_t start, uint64_t end, uint16_t, uint16_t, ino_t, const char* name) {
-        if (addr >= start && addr < end) {
-          found_name = name;
-        }
-      }));
+  EXPECT_TRUE(android::procinfo::ReadMapFile("/proc/self/maps",
+                                             [&](const android::procinfo::MapInfo& mapinfo) {
+                                               if (addr >= mapinfo.start && addr < mapinfo.end) {
+                                                 found_name = mapinfo.name;
+                                               }
+                                             }));
 
   return found_name;
 }
diff --git a/tests/make_fortify_compile_test.mk b/tests/make_fortify_compile_test.mk
index 8270f29..c36dfdd 100644
--- a/tests/make_fortify_compile_test.mk
+++ b/tests/make_fortify_compile_test.mk
@@ -9,6 +9,7 @@
 
 LOCAL_CLANG := true
 LOCAL_MODULE := bionic-compile-time-tests$(FORTIFY_LEVEL)-clang++
+LOCAL_TIDY := false
 LOCAL_CPPFLAGS := -Wall -Wno-error
 LOCAL_CPPFLAGS += -fno-color-diagnostics -ferror-limit=10000 -Xclang -verify
 LOCAL_CPPFLAGS += -DCOMPILATION_TESTS=1 -Wformat-nonliteral
diff --git a/tests/malloc_iterate_test.cpp b/tests/malloc_iterate_test.cpp
index 738a57b..e896c90 100644
--- a/tests/malloc_iterate_test.cpp
+++ b/tests/malloc_iterate_test.cpp
@@ -95,7 +95,8 @@
   test_data->total_allocated_bytes = 0;
 
   // Find all of the maps that are from the native allocator.
-  auto callback = [&](uint64_t start, uint64_t end, uint16_t, uint64_t, ino_t, const char* name) {
+  auto callback = [&](uint64_t start, uint64_t end, uint16_t, uint64_t, ino_t, const char* name,
+                      bool) {
     if (strcmp(name, "[anon:libc_malloc]") == 0 || strncmp(name, "[anon:scudo:", 12) == 0 ||
         strncmp(name, "[anon:GWP-ASan", 14) == 0) {
       malloc_iterate(start, end - start, SavePointers, test_data);
@@ -192,7 +193,8 @@
   TestDataType test_data = {};
 
   // Only attempt to get memory data for maps that are not from the native allocator.
-  auto callback = [&](uint64_t start, uint64_t end, uint16_t, uint64_t, ino_t, const char* name) {
+  auto callback = [&](uint64_t start, uint64_t end, uint16_t, uint64_t, ino_t, const char* name,
+                      bool) {
     if (strcmp(name, "[anon:libc_malloc]") != 0 && strncmp(name, "[anon:scudo:", 12) != 0 &&
         strncmp(name, "[anon:GWP-ASan", 14) != 0) {
       size_t total = test_data.total_allocated_bytes;
diff --git a/tests/time_test.cpp b/tests/time_test.cpp
index b1de0a4..93ba426 100644
--- a/tests/time_test.cpp
+++ b/tests/time_test.cpp
@@ -851,11 +851,11 @@
 }
 
 TEST(time, clock) {
-  // clock(3) is hard to test, but a 1s sleep should cost less than 5ms.
+  // clock(3) is hard to test, but a 1s sleep should cost less than 10ms.
   clock_t t0 = clock();
   sleep(1);
   clock_t t1 = clock();
-  ASSERT_LT(t1 - t0, 5 * (CLOCKS_PER_SEC / 1000));
+  ASSERT_LT(t1 - t0, 10 * (CLOCKS_PER_SEC / 1000));
 }
 
 static pid_t GetInvalidPid() {