Merge "Abort harder."
diff --git a/libc/Android.bp b/libc/Android.bp
index 2176ba6..05df811 100644
--- a/libc/Android.bp
+++ b/libc/Android.bp
@@ -4,7 +4,6 @@
     "bionic/ether_aton.c",
     "bionic/ether_ntoa.c",
     "bionic/fts.c",
-    "bionic/getpriority.c",
     "bionic/initgroups.c",
     "bionic/isatty.c",
     "bionic/pututline.c",
@@ -55,6 +54,7 @@
 // ========================================================
 cc_defaults {
     name: "libc_defaults",
+    defaults: ["linux_bionic_supported"],
     cflags: libc_common_flags,
     asflags: libc_common_flags,
     conlyflags: ["-std=gnu99"],
@@ -1255,6 +1255,7 @@
         "bionic/getpagesize.cpp",
         "bionic/getpgrp.cpp",
         "bionic/getpid.cpp",
+        "bionic/getpriority.cpp",
         "bionic/gettid.cpp",
         "bionic/__gnu_basename.cpp",
         "bionic/grp_pwd.cpp",
@@ -1772,6 +1773,7 @@
 
 cc_defaults {
     name: "crt_defaults",
+    defaults: ["linux_bionic_supported"],
 
     no_default_compiler_flags: true,
 
@@ -2006,10 +2008,21 @@
 // }
 
 ndk_headers {
-    name: "libc_linux",
-    from: "kernel/uapi/linux",
-    to: "linux",
-    srcs: ["kernel/uapi/linux/**/*.h"],
+    name: "libc_uapi",
+    from: "kernel/uapi",
+    to: "",
+    srcs: [
+        "kernel/uapi/asm-generic/**/*.h",
+        "kernel/uapi/drm/**/*.h",
+        "kernel/uapi/linux/**/*.h",
+        "kernel/uapi/misc/**/*.h",
+        "kernel/uapi/mtd/**/*.h",
+        "kernel/uapi/rdma/**/*.h",
+        "kernel/uapi/scsi/**/*.h",
+        "kernel/uapi/sound/**/*.h",
+        "kernel/uapi/video/**/*.h",
+        "kernel/uapi/xen/**/*.h",
+    ],
     license: "NOTICE",
 }
 
@@ -2022,14 +2035,6 @@
 }
 
 ndk_headers {
-    name: "libc_asm_generic",
-    from: "kernel/uapi/asm-generic",
-    to: "asm-generic",
-    srcs: ["kernel/uapi/asm-generic/**/*.h"],
-    license: "NOTICE",
-}
-
-ndk_headers {
     name: "libc_asm_arm",
     from: "kernel/uapi/asm-arm",
     to: "arm-linux-androideabi",
diff --git a/libc/SYSCALLS.TXT b/libc/SYSCALLS.TXT
index 42c8f01..f98cc61 100644
--- a/libc/SYSCALLS.TXT
+++ b/libc/SYSCALLS.TXT
@@ -62,8 +62,8 @@
 
 # <sys/resource.h>
 int getrusage(int, struct rusage*)  all
-int __getpriority:getpriority(int, int)  all
-int setpriority(int, int, int)   all
+int __getpriority:getpriority(int, id_t)  all
+int setpriority(int, id_t, int)   all
 # On LP64, rlimit and rlimit64 are the same.
 # On 32-bit systems we use prlimit64 to implement the rlimit64 functions.
 int getrlimit:ugetrlimit(int, struct rlimit*)  arm,x86
@@ -117,8 +117,8 @@
 int         munlockall()   all
 int         mincore(void*  start, size_t  length, unsigned char*  vec)   all
 int         __ioctl:ioctl(int, int, void*)  all
-int         readv(int, const struct iovec*, int)   all
-int         writev(int, const struct iovec*, int)  all
+ssize_t     readv(int, const struct iovec*, int)   all
+ssize_t     writev(int, const struct iovec*, int)  all
 int         __fcntl64:fcntl64(int, int, void*)  arm,mips,x86
 int         fcntl(int, int, void*)  arm64,mips64,x86_64
 int         flock(int, int)   all
diff --git a/libc/bionic/bionic_arc4random.cpp b/libc/bionic/bionic_arc4random.cpp
index 4ff18ab..ba3b4e1 100644
--- a/libc/bionic/bionic_arc4random.cpp
+++ b/libc/bionic/bionic_arc4random.cpp
@@ -29,6 +29,7 @@
 #include "private/bionic_arc4random.h"
 
 #include <errno.h>
+#include <stdatomic.h>
 #include <stdlib.h>
 #include <sys/auxv.h>
 #include <syscall.h>
@@ -37,17 +38,20 @@
 #include "private/KernelArgumentBlock.h"
 #include "private/libc_logging.h"
 
-void __libc_safe_arc4random_buf(void* buf, size_t n, KernelArgumentBlock& args) {
+bool __libc_arc4random_has_unlimited_entropy() {
   static bool have_urandom = access("/dev/urandom", R_OK) == 0;
-  static size_t at_random_bytes_consumed = 0;
+  return have_urandom;
+}
 
+void __libc_safe_arc4random_buf(void* buf, size_t n, KernelArgumentBlock& args) {
   // Only call arc4random_buf once we `have_urandom', since in getentropy_getrandom we may fallback
   // to use /dev/urandom, if the kernel entropy pool hasn't been initialized or not enough bytes
-  if (have_urandom) {
+  if (__libc_arc4random_has_unlimited_entropy()) {
     arc4random_buf(buf, n);
     return;
   }
 
+  static size_t at_random_bytes_consumed = 0;
   if (at_random_bytes_consumed + n > 16) {
     __libc_fatal("ran out of AT_RANDOM bytes, have %zu, requested %zu",
                  16 - at_random_bytes_consumed, n);
diff --git a/libc/bionic/getpriority.c b/libc/bionic/getpriority.cpp
similarity index 91%
rename from libc/bionic/getpriority.c
rename to libc/bionic/getpriority.cpp
index efc9d4e..7f0eb1c 100644
--- a/libc/bionic/getpriority.c
+++ b/libc/bionic/getpriority.cpp
@@ -25,13 +25,12 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
+
 #include <sys/resource.h>
 
-extern int __getpriority(int, int);
+extern "C" int __getpriority(int, id_t);
 
-int getpriority(int which, int who)
-{
+int getpriority(int which, id_t who) {
   int result = __getpriority(which, who);
-
-  return ( result < 0 ) ? result : 20-result;
+  return (result < 0) ? result : 20-result;
 }
diff --git a/libc/dns/net/getaddrinfo.c b/libc/dns/net/getaddrinfo.c
index 13000f7..c6f0d24 100644
--- a/libc/dns/net/getaddrinfo.c
+++ b/libc/dns/net/getaddrinfo.c
@@ -134,8 +134,10 @@
 };
 #endif
 
+#if defined(__ANDROID__)
 // This should be synchronized to ResponseCode.h
 static const int DnsProxyQueryResult = 222;
+#endif
 
 static const struct afd {
 	int a_af;
@@ -399,6 +401,7 @@
   return true;
 }
 
+#if defined(__ANDROID__)
 // Returns 0 on success, else returns on error.
 static int
 android_getaddrinfo_proxy(
@@ -555,6 +558,7 @@
 	}
 	return EAI_NODATA;
 }
+#endif
 
 int
 getaddrinfo(const char *hostname, const char *servname,
diff --git a/libc/include/sys/resource.h b/libc/include/sys/resource.h
index 248310e..7c43ca3 100644
--- a/libc/include/sys/resource.h
+++ b/libc/include/sys/resource.h
@@ -48,8 +48,8 @@
 int getrlimit64(int, struct rlimit64*) __INTRODUCED_IN(21);
 int setrlimit64(int, const struct rlimit64*) __INTRODUCED_IN(21);
 
-int getpriority(int, int);
-int setpriority(int, int, int);
+int getpriority(int, id_t);
+int setpriority(int, id_t, int);
 
 int getrusage(int, struct rusage*);
 
diff --git a/libc/include/sys/uio.h b/libc/include/sys/uio.h
index 7a009b4..0e56d7d 100644
--- a/libc/include/sys/uio.h
+++ b/libc/include/sys/uio.h
@@ -34,8 +34,8 @@
 
 __BEGIN_DECLS
 
-int readv(int, const struct iovec*, int);
-int writev(int, const struct iovec*, int);
+ssize_t readv(int, const struct iovec*, int);
+ssize_t writev(int, const struct iovec*, int);
 
 #if defined(__USE_GNU)
 #if defined(__USE_FILE_OFFSET64)
diff --git a/libc/include/unistd.h b/libc/include/unistd.h
index 1e239cd..cbdb438 100644
--- a/libc/include/unistd.h
+++ b/libc/include/unistd.h
@@ -148,7 +148,7 @@
 int lchown(const char* __path, uid_t __owner, gid_t __group);
 char* getcwd(char* __buf, size_t __size);
 
-int sync(void);
+void sync(void);
 
 int close(int __fd);
 
diff --git a/libc/private/bionic_arc4random.h b/libc/private/bionic_arc4random.h
index d26a4e7..b51f818 100644
--- a/libc/private/bionic_arc4random.h
+++ b/libc/private/bionic_arc4random.h
@@ -39,7 +39,12 @@
  * created yet. Provide a wrapper function that falls back to AT_RANDOM if
  * we don't have getrandom and /dev/urandom is missing.
  */
-
 void __libc_safe_arc4random_buf(void* buf, size_t n, KernelArgumentBlock& args);
 
+/*
+ * Return true if libc has an unlimited entropy source (something other than
+ * AT_RANDOM), and arc4random* calls will always succeed.
+ */
+bool __libc_arc4random_has_unlimited_entropy();
+
 #endif
diff --git a/libc/zoneinfo/tzdata b/libc/zoneinfo/tzdata
index ce00600..577ede6 100644
--- a/libc/zoneinfo/tzdata
+++ b/libc/zoneinfo/tzdata
Binary files differ
diff --git a/libdl/Android.bp b/libdl/Android.bp
index 273a887..9db3a94 100644
--- a/libdl/Android.bp
+++ b/libdl/Android.bp
@@ -2,6 +2,9 @@
 // libdl
 //
 cc_library {
+    name: "libdl",
+
+    defaults: ["linux_bionic_supported"],
 
     // NOTE: --exclude-libs=libgcc.a makes sure that any symbols libdl.so pulls from
     // libgcc.a are made static to libdl.so.  This in turn ensures that libraries that
@@ -46,8 +49,6 @@
     ],
     stl: "none",
 
-    name: "libdl",
-
     // NOTE: libdl needs __aeabi_unwind_cpp_pr0 from libgcc.a but libgcc.a needs a
     // few symbols from libc. Using --no-undefined here results in having to link
     // against libc creating a circular dependency which is removed and we end up
diff --git a/libm/Android.bp b/libm/Android.bp
index 11017f6..b1d88d5 100644
--- a/libm/Android.bp
+++ b/libm/Android.bp
@@ -5,6 +5,7 @@
 //
 cc_library {
     name: "libm",
+    defaults: ["linux_bionic_supported"],
 
     srcs: [
         "upstream-freebsd/lib/msun/bsdsrc/b_exp.c",
@@ -526,7 +527,7 @@
 
     native_coverage: bionic_coverage,
     sanitize: {
-        never: true,
+        address: false,
     },
     stl: "none",
 }
diff --git a/linker/Android.bp b/linker/Android.bp
index 4d770ac..5745d73 100644
--- a/linker/Android.bp
+++ b/linker/Android.bp
@@ -1,6 +1,7 @@
 cc_library_static {
     name: "liblinker_malloc",
     clang: true,
+    defaults: ["linux_bionic_supported"],
 
     srcs: [
         "linker_allocator.cpp",
@@ -13,6 +14,7 @@
 
 cc_binary {
     clang: true,
+    defaults: ["linux_bionic_supported"],
 
     srcs: [
         "dlfcn.cpp",
@@ -112,7 +114,6 @@
         "libbase",
         "libz",
         "liblog",
-        "libdebuggerd_client",
 
         // Important: The liblinker_malloc should be the last library in the list
         // to overwrite any other malloc implementations by other static libraries.
@@ -131,9 +132,15 @@
        },
     },
     target: {
+        android: {
+            static_libs: ["libdebuggerd_client"],
+        },
         android64: {
             cflags: ["-DTARGET_IS_64_BIT"],
         },
+        linux_bionic: {
+            cflags: ["-DTARGET_IS_64_BIT"],
+        },
     },
     compile_multilib: "both",
 
diff --git a/linker/linker_main.cpp b/linker/linker_main.cpp
index 2e98bf0..a8cc814 100644
--- a/linker/linker_main.cpp
+++ b/linker/linker_main.cpp
@@ -40,7 +40,9 @@
 
 #include "android-base/strings.h"
 #include "android-base/stringprintf.h"
+#ifdef __ANDROID__
 #include "debuggerd/client.h"
+#endif
 
 #include <vector>
 
@@ -217,6 +219,7 @@
   __system_properties_init(); // may use 'environ'
 
   // Register the debuggerd signal handler.
+#ifdef __ANDROID__
   debuggerd_callbacks_t callbacks = {
     .get_abort_message = []() {
       return g_abort_message;
@@ -224,6 +227,7 @@
     .post_dump = &notify_gdb_of_libraries,
   };
   debuggerd_init(&callbacks);
+#endif
 
   g_linker_logger.ResetState();