Merge "Revert "HACK: linker: check for handle==0xffffffff on LP64""
diff --git a/benchmarks/benchmark_main.cpp b/benchmarks/benchmark_main.cpp
index f8e85bb..d60670b 100644
--- a/benchmarks/benchmark_main.cpp
+++ b/benchmarks/benchmark_main.cpp
@@ -32,6 +32,7 @@
 typedef std::map<std::string, ::testing::Benchmark*> BenchmarkMap;
 typedef BenchmarkMap::iterator BenchmarkMapIt;
 static BenchmarkMap g_benchmarks;
+static int g_name_column_width = 20;
 
 static int Round(int n) {
   int base = 1;
@@ -164,7 +165,7 @@
     snprintf(full_name, sizeof(full_name), "%s", name_);
   }
 
-  printf("%-20s %10d %10" PRId64 "%s\n", full_name,
+  printf("%-*s %10d %10" PRId64 "%s\n", g_name_column_width, full_name,
          iterations, g_benchmark_total_time_ns/iterations, throughput);
   fflush(stdout);
 }
@@ -194,12 +195,17 @@
     exit(EXIT_FAILURE);
   }
 
+  for (BenchmarkMapIt it = g_benchmarks.begin(); it != g_benchmarks.end(); ++it) {
+    int name_width = static_cast<int>(strlen(it->second->Name()));
+    g_name_column_width = std::max(g_name_column_width, name_width);
+  }
+
   bool need_header = true;
   for (BenchmarkMapIt it = g_benchmarks.begin(); it != g_benchmarks.end(); ++it) {
     ::testing::Benchmark* b = it->second;
     if (b->ShouldRun(argc, argv)) {
       if (need_header) {
-        printf("%-20s %10s %10s\n", "", "iterations", "ns/op");
+        printf("%-*s %10s %10s\n", g_name_column_width, "", "iterations", "ns/op");
         fflush(stdout);
         need_header = false;
       }
diff --git a/benchmarks/math_benchmark.cpp b/benchmarks/math_benchmark.cpp
index 3602de4..a9748cd 100644
--- a/benchmarks/math_benchmark.cpp
+++ b/benchmarks/math_benchmark.cpp
@@ -16,6 +16,7 @@
 
 #include "benchmark.h"
 
+#include <fenv.h>
 #include <math.h>
 
 // Avoid optimization.
@@ -113,10 +114,49 @@
 }
 BENCHMARK(BM_math_isinf_ZERO);
 
+static void BM_math_sin_fast(int iters) {
+  StartBenchmarkTiming();
 
+  d = 1.0;
+  for (int i = 0; i < iters; ++i) {
+    d += sin(d);
+  }
 
+  StopBenchmarkTiming();
+}
+BENCHMARK(BM_math_sin_fast);
 
+static void BM_math_sin_feupdateenv(int iters) {
+  StartBenchmarkTiming();
 
+  d = 1.0;
+  for (int i = 0; i < iters; ++i) {
+    fenv_t __libc_save_rm;
+    feholdexcept(&__libc_save_rm);
+    fesetround(FE_TONEAREST);
+    d += sin(d);
+    feupdateenv(&__libc_save_rm);
+  }
+
+  StopBenchmarkTiming();
+}
+BENCHMARK(BM_math_sin_feupdateenv);
+
+static void BM_math_sin_fesetenv(int iters) {
+  StartBenchmarkTiming();
+
+  d = 1.0;
+  for (int i = 0; i < iters; ++i) {
+    fenv_t __libc_save_rm;
+    feholdexcept(&__libc_save_rm);
+    fesetround(FE_TONEAREST);
+    d += sin(d);
+    fesetenv(&__libc_save_rm);
+  }
+
+  StopBenchmarkTiming();
+}
+BENCHMARK(BM_math_sin_fesetenv);
 
 static void BM_math_fpclassify_NORMAL(int iters) {
   StartBenchmarkTiming();
diff --git a/benchmarks/pthread_benchmark.cpp b/benchmarks/pthread_benchmark.cpp
index 621fcb6..c010dd2 100644
--- a/benchmarks/pthread_benchmark.cpp
+++ b/benchmarks/pthread_benchmark.cpp
@@ -18,11 +18,14 @@
 
 #include <pthread.h>
 
+// Stop GCC optimizing out our pure function.
+/* Must not be static! */ pthread_t (*pthread_self_fp)() = pthread_self;
+
 static void BM_pthread_self(int iters) {
   StartBenchmarkTiming();
 
   for (int i = 0; i < iters; ++i) {
-    pthread_self();
+    pthread_self_fp();
   }
 
   StopBenchmarkTiming();
diff --git a/benchmarks/time_benchmark.cpp b/benchmarks/time_benchmark.cpp
index 75132e5..3bf8c07 100644
--- a/benchmarks/time_benchmark.cpp
+++ b/benchmarks/time_benchmark.cpp
@@ -35,4 +35,17 @@
   StopBenchmarkTiming();
 }
 BENCHMARK(BM_time_localtime_tz);
+
 #endif
+
+static void BM_time_clock_gettime(int iters) {
+  StartBenchmarkTiming();
+
+  struct timespec t;
+  for (int i = 0; i < iters; ++i) {
+    clock_gettime(CLOCK_MONOTONIC, &t);
+  }
+
+  StopBenchmarkTiming();
+}
+BENCHMARK(BM_time_clock_gettime);
diff --git a/benchmarks/unistd_benchmark.cpp b/benchmarks/unistd_benchmark.cpp
index 12b788a..7e2ac30 100644
--- a/benchmarks/unistd_benchmark.cpp
+++ b/benchmarks/unistd_benchmark.cpp
@@ -16,6 +16,7 @@
 
 #include "benchmark.h"
 
+#include <sys/syscall.h>
 #include <unistd.h>
 
 static void BM_unistd_getpid(int iters) {
@@ -29,13 +30,38 @@
 }
 BENCHMARK(BM_unistd_getpid);
 
+static void BM_unistd_getpid_syscall(int iters) {
+  StartBenchmarkTiming();
+
+  for (int i = 0; i < iters; ++i) {
+    syscall(__NR_getpid);
+  }
+
+  StopBenchmarkTiming();
+}
+BENCHMARK(BM_unistd_getpid_syscall);
+
+// Stop GCC optimizing out our pure function.
+/* Must not be static! */ pid_t (*gettid_fp)() = gettid;
+
 static void BM_unistd_gettid(int iters) {
   StartBenchmarkTiming();
 
   for (int i = 0; i < iters; ++i) {
-    gettid();
+    gettid_fp();
   }
 
   StopBenchmarkTiming();
 }
 BENCHMARK(BM_unistd_gettid);
+
+static void BM_unistd_gettid_syscall(int iters) {
+  StartBenchmarkTiming();
+
+  for (int i = 0; i < iters; ++i) {
+    syscall(__NR_gettid);
+  }
+
+  StopBenchmarkTiming();
+}
+BENCHMARK(BM_unistd_gettid_syscall);
diff --git a/libc/Android.mk b/libc/Android.mk
index 77c77c8..c1a3dff 100644
--- a/libc/Android.mk
+++ b/libc/Android.mk
@@ -43,9 +43,7 @@
     bionic/err.c \
     bionic/ether_aton.c \
     bionic/ether_ntoa.c \
-    bionic/ftime.c \
     bionic/fts.c \
-    bionic/getdtablesize.c \
     bionic/gethostname.c \
     bionic/getpriority.c \
     bionic/getpt.c \
@@ -54,7 +52,6 @@
     bionic/initgroups.c \
     bionic/ioctl.c \
     bionic/isatty.c \
-    bionic/md5.c \
     bionic/memmem.c \
     bionic/pathconf.c \
     bionic/ptsname.c \
@@ -130,6 +127,7 @@
     bionic/getauxval.cpp \
     bionic/getcwd.cpp \
     bionic/getpgrp.cpp \
+    bionic/getpid.cpp \
     bionic/gettid.cpp \
     bionic/inotify_init.cpp \
     bionic/lchown.cpp \
@@ -219,11 +217,12 @@
     bionic/system_properties.cpp \
     bionic/tdestroy.cpp \
     bionic/termios.cpp \
-    bionic/thread_atexit.cpp \
+    bionic/thread_private.cpp \
     bionic/tmpfile.cpp \
     bionic/umount.cpp \
     bionic/unlink.cpp \
     bionic/utimes.cpp \
+    bionic/vfork.cpp \
     bionic/wait.cpp \
     bionic/wchar.cpp \
     bionic/wctype.cpp \
@@ -264,17 +263,14 @@
     upstream-freebsd/lib/libc/string/wmemset.c \
 
 libc_upstream_netbsd_src_files := \
-    upstream-netbsd/common/lib/libc/hash/sha1/sha1.c \
+    upstream-netbsd/common/lib/libc/stdlib/random.c \
     upstream-netbsd/lib/libc/gen/ftw.c \
     upstream-netbsd/lib/libc/gen/nftw.c \
     upstream-netbsd/lib/libc/gen/nice.c \
     upstream-netbsd/lib/libc/gen/popen.c \
     upstream-netbsd/lib/libc/gen/psignal.c \
-    upstream-netbsd/lib/libc/gen/setjmperr.c \
     upstream-netbsd/lib/libc/gen/utime.c \
     upstream-netbsd/lib/libc/gen/utmp.c \
-    upstream-netbsd/lib/libc/isc/ev_streams.c \
-    upstream-netbsd/lib/libc/isc/ev_timers.c \
     upstream-netbsd/lib/libc/regex/regcomp.c \
     upstream-netbsd/lib/libc/regex/regerror.c \
     upstream-netbsd/lib/libc/regex/regexec.c \
@@ -291,6 +287,8 @@
     upstream-netbsd/lib/libc/stdlib/mrand48.c \
     upstream-netbsd/lib/libc/stdlib/nrand48.c \
     upstream-netbsd/lib/libc/stdlib/_rand48.c \
+    upstream-netbsd/lib/libc/stdlib/rand.c \
+    upstream-netbsd/lib/libc/stdlib/rand_r.c \
     upstream-netbsd/lib/libc/stdlib/seed48.c \
     upstream-netbsd/lib/libc/stdlib/srand48.c \
     upstream-netbsd/lib/libc/stdlib/tdelete.c \
@@ -419,7 +417,6 @@
     upstream-openbsd/lib/libc/stdio/putc.c \
     upstream-openbsd/lib/libc/stdio/putchar.c \
     upstream-openbsd/lib/libc/stdio/puts.c \
-    upstream-openbsd/lib/libc/stdio/putw.c \
     upstream-openbsd/lib/libc/stdio/putwc.c \
     upstream-openbsd/lib/libc/stdio/putwchar.c \
     upstream-openbsd/lib/libc/stdio/refill.c \
@@ -481,7 +478,6 @@
     upstream-openbsd/lib/libc/string/strtok.c \
     upstream-openbsd/lib/libc/string/wcslcpy.c \
     upstream-openbsd/lib/libc/string/wcsstr.c \
-    upstream-openbsd/lib/libc/string/wcswcs.c \
     upstream-openbsd/lib/libc/string/wcswidth.c \
 
 libc_arch_static_src_files := \
@@ -505,7 +501,7 @@
 
 ifeq ($(MALLOC_IMPL),jemalloc)
   libc_common_cflags += -DUSE_JEMALLOC
-  libc_malloc_src := bionic/jemalloc.cpp
+  libc_malloc_src := bionic/jemalloc_wrapper.cpp
 else
   libc_common_cflags += -DUSE_DLMALLOC
   libc_malloc_src := bionic/dlmalloc.c
@@ -589,7 +585,10 @@
 # tzcode doesn't include wcsftime, so we use the OpenBSD one.
 LOCAL_SRC_FILES += upstream-openbsd/lib/libc/time/wcsftime.c
 
-LOCAL_CFLAGS := $(libc_common_cflags)
+LOCAL_CFLAGS := $(libc_common_cflags) \
+    -fvisibility=hidden \
+    -Werror \
+
 # Don't use ridiculous amounts of stack.
 LOCAL_CFLAGS += -DALL_STATE
 # Include tzsetwall, timelocal, timegm, time2posix, and posix2time.
@@ -601,6 +600,7 @@
 # Include timezone and daylight globals.
 LOCAL_CFLAGS += -DUSG_COMPAT=1
 LOCAL_CFLAGS += -DNO_RUN_TIME_WARNINGS_ABOUT_YEAR_2000_PROBLEMS_THANK_YOU
+LOCAL_CFLAGS += -Dlint
 
 LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
 LOCAL_CPPFLAGS := $(libc_common_cppflags)
@@ -619,15 +619,21 @@
 
 include $(CLEAR_VARS)
 
-LOCAL_SRC_FILES := $(call all-c-files-under,dns)
+LOCAL_SRC_FILES := \
+    $(call all-c-files-under,dns) \
+    upstream-netbsd/lib/libc/isc/ev_streams.c \
+    upstream-netbsd/lib/libc/isc/ev_timers.c \
+
 LOCAL_CFLAGS := \
     $(libc_common_cflags) \
     -DANDROID_CHANGES \
     -DINET6 \
+    -fvisibility=hidden \
     -I$(LOCAL_PATH)/dns/include \
     -I$(LOCAL_PATH)/private \
     -I$(LOCAL_PATH)/upstream-netbsd/lib/libc/include \
-    -include upstream-netbsd/android/include/netbsd-compat.h \
+    -I$(LOCAL_PATH)/upstream-netbsd/android/include \
+    -include netbsd-compat.h \
 #    -Werror \
 
 LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
@@ -697,6 +703,7 @@
 LOCAL_SYSTEM_SHARED_LIBRARIES :=
 
 $(eval $(call patch-up-arch-specific-flags,LOCAL_CFLAGS,libc_common_cflags))
+$(eval $(call patch-up-arch-specific-flags,LOCAL_SRC_FILES,libc_netbsd_src_files))
 include $(BUILD_STATIC_LIBRARY)
 
 
diff --git a/libc/SYSCALLS.TXT b/libc/SYSCALLS.TXT
index 584c1ae..b4c8134 100644
--- a/libc/SYSCALLS.TXT
+++ b/libc/SYSCALLS.TXT
@@ -77,7 +77,6 @@
 int     setgroups:setgroups32(int, const gid_t*)   arm,x86
 int     setgroups:setgroups(int, const gid_t*)     arm64,mips,mips64,x86_64
 int     setpgid(pid_t, pid_t)  all
-pid_t   vfork(void)  arm
 int     setregid:setregid32(gid_t, gid_t)  arm,x86
 int     setregid:setregid(gid_t, gid_t)    arm64,mips,mips64,x86_64
 int     chroot(const char*)  all
@@ -98,7 +97,7 @@
 ssize_t     pwrite64(int, void*, size_t, off64_t) arm,mips,x86
 ssize_t     pwrite64|pwrite(int, void*, size_t, off_t) arm64,mips64,x86_64
 int         close(int)                      all
-pid_t       getpid()    all
+pid_t       __getpid:getpid()  all
 int         munmap(void*, size_t)  all
 void*       mremap(void*, size_t, size_t, unsigned long)  all
 int         msync(const void*, size_t, int)    all
@@ -129,12 +128,7 @@
 ssize_t     flistxattr(int, char*, size_t) all
 int         fremovexattr(int, const char*) all
 
-# mips64 doesn't have getdents64 until 3.10 kernels.
-# We need this special-case hack as long as we need to support mips64 on older kernels.
-# The currently-available Debian qemu image is on a 3.2 kernel.
-int getdents:getdents64(unsigned int, struct dirent*, unsigned int)   arm,arm64,mips,x86,x86_64
-int __getdents64:getdents64(unsigned int, struct dirent*, unsigned int)   mips64
-int __getdents:getdents(unsigned int, void*, unsigned int)   mips64
+int __getdents64:getdents64(unsigned int, struct dirent*, unsigned int)   arm,arm64,mips,mips64,x86,x86_64
 
 int __openat:openat(int, const char*, int, mode_t) all
 int faccessat(int, const char*, int, int)  all
@@ -281,10 +275,6 @@
 int __sched_getaffinity:sched_getaffinity(pid_t pid, size_t setsize, cpu_set_t* set)  all
 int __getcpu:getcpu(unsigned*, unsigned*, void*) all
 
-# io priorities
-int ioprio_set(int which, int who, int ioprio) all
-int ioprio_get(int which, int who) all
-
 # other
 int     uname(struct utsname*)  all
 mode_t  umask(mode_t)  all
@@ -295,6 +285,10 @@
 int     sysinfo(struct sysinfo*)  all
 int     personality(unsigned long)  all
 
+ssize_t tee(int, int, size_t, unsigned int)  all
+ssize_t splice(int, off64_t*, int, off64_t*, size_t, unsigned int)  all
+ssize_t vmsplice(int, const struct iovec*, size_t, unsigned int)  all
+
 int epoll_create1(int)  all
 int epoll_ctl(int, int op, int, struct epoll_event*)  all
 int __epoll_pwait:epoll_pwait(int, struct epoll_event*, int, int, const sigset_t*, size_t)  all
diff --git a/libc/arch-arm/arm.mk b/libc/arch-arm/arm.mk
index 7c423ab..47e436c 100644
--- a/libc/arch-arm/arm.mk
+++ b/libc/arch-arm/arm.mk
@@ -5,13 +5,13 @@
     bionic/legacy_32_bit_support.cpp \
     bionic/ndk_cruft.cpp \
     bionic/time64.c \
+    upstream-openbsd/lib/libc/stdio/putw.c \
 
 # These are shared by all the 32-bit targets, but not the 64-bit ones.
 libc_bionic_src_files_arm := \
     bionic/mmap.cpp
 
 libc_common_src_files_arm += \
-    bionic/index.cpp \
     bionic/memchr.c \
     bionic/memrchr.c \
     bionic/strchr.cpp \
@@ -56,7 +56,6 @@
     arch-arm/bionic/_exit_with_stack_teardown.S \
     arch-arm/bionic/__get_sp.S \
     arch-arm/bionic/libgcc_compat.c \
-    arch-arm/bionic/memcmp16.S \
     arch-arm/bionic/memcmp.S \
     arch-arm/bionic/_setjmp.S \
     arch-arm/bionic/setjmp.S \
@@ -66,6 +65,9 @@
 libc_arch_static_src_files_arm := arch-arm/bionic/exidx_static.c
 libc_arch_dynamic_src_files_arm := arch-arm/bionic/exidx_dynamic.c
 
+libc_netbsd_src_files_arm := \
+    upstream-netbsd/common/lib/libc/hash/sha1/sha1.c \
+
 ## CPU variant specific source files
 ifeq ($(strip $(TARGET_$(my_2nd_arch_prefix)CPU_VARIANT)),)
   $(warning TARGET_$(my_2nd_arch_prefix)ARCH is arm, but TARGET_$(my_2nd_arch_prefix)CPU_VARIANT is not defined)
diff --git a/libc/arch-arm/bionic/__bionic_clone.S b/libc/arch-arm/bionic/__bionic_clone.S
index 2643ae0..48f2f98 100644
--- a/libc/arch-arm/bionic/__bionic_clone.S
+++ b/libc/arch-arm/bionic/__bionic_clone.S
@@ -60,10 +60,10 @@
     b       __set_errno
 
 1:  # The child.
-    # Setting lr to 0 will make the unwinder stop at __bionic_clone_entry
+    # Setting lr to 0 will make the unwinder stop at __start_thread
     mov    lr, #0
     ldr    r0, [sp, #-4]
     ldr    r1, [sp, #-8]
-    b      __bionic_clone_entry
+    b      __start_thread
 END(__bionic_clone)
 .hidden __bionic_clone
diff --git a/libc/arch-arm/bionic/memcmp16.S b/libc/arch-arm/bionic/memcmp16.S
deleted file mode 100644
index 3f2f2f1..0000000
--- a/libc/arch-arm/bionic/memcmp16.S
+++ /dev/null
@@ -1,234 +0,0 @@
-/*
- * Copyright (C) 2008 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 <machine/cpu-features.h>
-#include <private/bionic_asm.h>
-
-/*
- * Optimized memcmp16() for ARM9.
- * This would not be optimal on XScale or ARM11, where more prefetching
- * and use of pld will be needed.
- * The 2 major optimzations here are
- * (1) The main loop compares 16 bytes at a time
- * (2) The loads are scheduled in a way they won't stall
- */
-
-ENTRY(__memcmp16)
-        pld         [r0, #0]
-        pld         [r1, #0]
-
-        /* take of the case where length is nul or the buffers are the same */
-        cmp         r0, r1
-        cmpne       r2, #0
-        moveq       r0, #0
-        bxeq        lr
-
-        /* since r0 hold the result, move the first source
-         * pointer somewhere else
-         */
-
-        mov         r3, r0
-
-         /* make sure we have at least 12 words, this simplify things below
-          * and avoid some overhead for small blocks
-          */
-
-        cmp         r2, #12
-        bpl         0f
-
-        /* small blocks (less then 12 words) */
-        pld         [r0, #32]
-        pld         [r1, #32]
-
-1:      ldrh        r0, [r3], #2
-        ldrh        ip, [r1], #2
-        subs        r0, r0, ip
-        bxne        lr
-        subs        r2, r2, #1
-        bne         1b
-        bx          lr
-
-
-        /* save registers */
-0:      stmfd       sp!, {r4, lr}
-        .cfi_def_cfa_offset 8
-        .cfi_rel_offset r4, 0
-        .cfi_rel_offset lr, 4
-
-        /* align first pointer to word boundary */
-        tst         r3, #2
-        beq         0f
-
-        ldrh        r0, [r3], #2
-        ldrh        ip, [r1], #2
-        sub         r2, r2, #1
-        subs        r0, r0, ip
-        /* restore registers and return */
-        ldmnefd     sp!, {r4, lr}
-        bxne        lr
-
-
-0:      /* here the first pointer is aligned, and we have at least 3 words
-         * to process.
-         */
-
-        /* see if the pointers are congruent */
-        eor         r0, r3, r1
-        ands        r0, r0, #2
-        bne         5f
-
-        /* congruent case, 16 half-words per iteration
-         * We need to make sure there are at least 16+2 words left
-         * because we effectively read ahead one long word, and we could
-         * read past the buffer (and segfault) if we're not careful.
-         */
-
-        ldr         ip, [r1]
-        subs        r2, r2, #(16 + 2)
-        bmi         1f
-
-0:
-        pld         [r3, #64]
-        pld         [r1, #64]
-        ldr         r0, [r3], #4
-        ldr         lr, [r1, #4]!
-        eors        r0, r0, ip
-        ldreq       r0, [r3], #4
-        ldreq       ip, [r1, #4]!
-        eoreqs      r0, r0, lr
-        ldreq       r0, [r3], #4
-        ldreq       lr, [r1, #4]!
-        eoreqs      r0, r0, ip
-        ldreq       r0, [r3], #4
-        ldreq       ip, [r1, #4]!
-        eoreqs      r0, r0, lr
-        ldreq       r0, [r3], #4
-        ldreq       lr, [r1, #4]!
-        eoreqs      r0, r0, ip
-        ldreq       r0, [r3], #4
-        ldreq       ip, [r1, #4]!
-        eoreqs      r0, r0, lr
-        ldreq       r0, [r3], #4
-        ldreq       lr, [r1, #4]!
-        eoreqs      r0, r0, ip
-        ldreq       r0, [r3], #4
-        ldreq       ip, [r1, #4]!
-        eoreqs      r0, r0, lr
-        bne         2f
-        subs        r2, r2, #16
-        bhs         0b
-
-        /* do we have at least 2 words left? */
-1:      adds        r2, r2, #(16 - 2 + 2)
-        bmi         4f
-
-        /* finish off 2 words at a time */
-3:      ldr         r0, [r3], #4
-        ldr         ip, [r1], #4
-        eors        r0, r0, ip
-        bne         2f
-        subs        r2, r2, #2
-        bhs         3b
-
-        /* are we done? */
-4:      adds        r2, r2, #2
-        bne         8f
-        /* restore registers and return */
-        mov         r0, #0
-        ldmfd       sp!, {r4, lr}
-        bx          lr
-
-2:      /* the last 2 words are different, restart them */
-        ldrh        r0, [r3, #-4]
-        ldrh        ip, [r1, #-4]
-        subs        r0, r0, ip
-        ldreqh      r0, [r3, #-2]
-        ldreqh      ip, [r1, #-2]
-        subeqs      r0, r0, ip
-        /* restore registers and return */
-        ldmfd       sp!, {r4, lr}
-        bx          lr
-
-        /* process the last few words */
-8:      ldrh        r0, [r3], #2
-        ldrh        ip, [r1], #2
-        subs        r0, r0, ip
-        bne         9f
-        subs        r2, r2, #1
-        bne         8b
-
-9:      /* restore registers and return */
-        ldmfd       sp!, {r4, lr}
-        bx          lr
-
-
-5:      /*************** non-congruent case ***************/
-
-        /* align the unaligned pointer */
-        bic         r1, r1, #3
-        ldr         lr, [r1], #4
-        sub         r2, r2, #8
-
-6:
-        pld         [r3, #64]
-        pld         [r1, #64]
-        mov         ip, lr, lsr #16
-        ldr         lr, [r1], #4
-        ldr         r0, [r3], #4
-        orr         ip, ip, lr, lsl #16
-        eors        r0, r0, ip
-        moveq       ip, lr, lsr #16
-        ldreq       lr, [r1], #4
-        ldreq       r0, [r3], #4
-        orreq       ip, ip, lr, lsl #16
-        eoreqs      r0, r0, ip
-        moveq       ip, lr, lsr #16
-        ldreq       lr, [r1], #4
-        ldreq       r0, [r3], #4
-        orreq       ip, ip, lr, lsl #16
-        eoreqs      r0, r0, ip
-        moveq       ip, lr, lsr #16
-        ldreq       lr, [r1], #4
-        ldreq       r0, [r3], #4
-        orreq       ip, ip, lr, lsl #16
-        eoreqs      r0, r0, ip
-        bne         7f
-        subs        r2, r2, #8
-        bhs         6b
-        sub         r1, r1, #2
-        /* are we done? */
-        adds        r2, r2, #8
-        moveq       r0, #0
-        beq         9b
-        /* finish off the remaining bytes */
-        b           8b
-
-7:      /* fix up the 2 pointers and fallthrough... */
-        sub         r1, r1, #2
-        b           2b
-END(__memcmp16)
diff --git a/libc/arch-arm/syscalls/getdents.S b/libc/arch-arm/syscalls/__getdents64.S
similarity index 86%
rename from libc/arch-arm/syscalls/getdents.S
rename to libc/arch-arm/syscalls/__getdents64.S
index 8f0e81a..c3d5e5b 100644
--- a/libc/arch-arm/syscalls/getdents.S
+++ b/libc/arch-arm/syscalls/__getdents64.S
@@ -2,7 +2,7 @@
 
 #include <private/bionic_asm.h>
 
-ENTRY(getdents)
+ENTRY(__getdents64)
     mov     ip, r7
     ldr     r7, =__NR_getdents64
     swi     #0
@@ -11,4 +11,4 @@
     bxls    lr
     neg     r0, r0
     b       __set_errno
-END(getdents)
+END(__getdents64)
diff --git a/libc/arch-arm/syscalls/getpid.S b/libc/arch-arm/syscalls/__getpid.S
similarity index 89%
rename from libc/arch-arm/syscalls/getpid.S
rename to libc/arch-arm/syscalls/__getpid.S
index 10bcb8e..eedc33a 100644
--- a/libc/arch-arm/syscalls/getpid.S
+++ b/libc/arch-arm/syscalls/__getpid.S
@@ -2,7 +2,7 @@
 
 #include <private/bionic_asm.h>
 
-ENTRY(getpid)
+ENTRY(__getpid)
     mov     ip, r7
     ldr     r7, =__NR_getpid
     swi     #0
@@ -11,4 +11,4 @@
     bxls    lr
     neg     r0, r0
     b       __set_errno
-END(getpid)
+END(__getpid)
diff --git a/libc/arch-arm/syscalls/ioprio_get.S b/libc/arch-arm/syscalls/ioprio_get.S
deleted file mode 100644
index 19e04ed..0000000
--- a/libc/arch-arm/syscalls/ioprio_get.S
+++ /dev/null
@@ -1,14 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(ioprio_get)
-    mov     ip, r7
-    ldr     r7, =__NR_ioprio_get
-    swi     #0
-    mov     r7, ip
-    cmn     r0, #(MAX_ERRNO + 1)
-    bxls    lr
-    neg     r0, r0
-    b       __set_errno
-END(ioprio_get)
diff --git a/libc/arch-arm/syscalls/ioprio_set.S b/libc/arch-arm/syscalls/ioprio_set.S
deleted file mode 100644
index 9b94efb..0000000
--- a/libc/arch-arm/syscalls/ioprio_set.S
+++ /dev/null
@@ -1,14 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(ioprio_set)
-    mov     ip, r7
-    ldr     r7, =__NR_ioprio_set
-    swi     #0
-    mov     r7, ip
-    cmn     r0, #(MAX_ERRNO + 1)
-    bxls    lr
-    neg     r0, r0
-    b       __set_errno
-END(ioprio_set)
diff --git a/libc/arch-arm/syscalls/splice.S b/libc/arch-arm/syscalls/splice.S
new file mode 100644
index 0000000..782ba6c
--- /dev/null
+++ b/libc/arch-arm/syscalls/splice.S
@@ -0,0 +1,22 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(splice)
+    mov     ip, sp
+    stmfd   sp!, {r4, r5, r6, r7}
+    .cfi_def_cfa_offset 16
+    .cfi_rel_offset r4, 0
+    .cfi_rel_offset r5, 4
+    .cfi_rel_offset r6, 8
+    .cfi_rel_offset r7, 12
+    ldmfd   ip, {r4, r5, r6}
+    ldr     r7, =__NR_splice
+    swi     #0
+    ldmfd   sp!, {r4, r5, r6, r7}
+    .cfi_def_cfa_offset 0
+    cmn     r0, #(MAX_ERRNO + 1)
+    bxls    lr
+    neg     r0, r0
+    b       __set_errno
+END(splice)
diff --git a/libc/arch-arm/syscalls/vfork.S b/libc/arch-arm/syscalls/tee.S
similarity index 81%
rename from libc/arch-arm/syscalls/vfork.S
rename to libc/arch-arm/syscalls/tee.S
index e12fba5..9174617 100644
--- a/libc/arch-arm/syscalls/vfork.S
+++ b/libc/arch-arm/syscalls/tee.S
@@ -2,13 +2,13 @@
 
 #include <private/bionic_asm.h>
 
-ENTRY(vfork)
+ENTRY(tee)
     mov     ip, r7
-    ldr     r7, =__NR_vfork
+    ldr     r7, =__NR_tee
     swi     #0
     mov     r7, ip
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
     b       __set_errno
-END(vfork)
+END(tee)
diff --git a/libc/arch-arm/syscalls/getdents.S b/libc/arch-arm/syscalls/vmsplice.S
similarity index 78%
copy from libc/arch-arm/syscalls/getdents.S
copy to libc/arch-arm/syscalls/vmsplice.S
index 8f0e81a..3b89623 100644
--- a/libc/arch-arm/syscalls/getdents.S
+++ b/libc/arch-arm/syscalls/vmsplice.S
@@ -2,13 +2,13 @@
 
 #include <private/bionic_asm.h>
 
-ENTRY(getdents)
+ENTRY(vmsplice)
     mov     ip, r7
-    ldr     r7, =__NR_getdents64
+    ldr     r7, =__NR_vmsplice
     swi     #0
     mov     r7, ip
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
     b       __set_errno
-END(getdents)
+END(vmsplice)
diff --git a/libc/arch-arm64/arm64.mk b/libc/arch-arm64/arm64.mk
index 62974b6..87f954a 100644
--- a/libc/arch-arm64/arm64.mk
+++ b/libc/arch-arm64/arm64.mk
@@ -1,11 +1,8 @@
 # arm64 specific configs
 
 libc_common_src_files_arm64 := \
-    bionic/index.cpp \
     bionic/memchr.c \
-    bionic/__memcmp16.cpp \
     bionic/memrchr.c \
-    bionic/strchr.cpp \
     bionic/strrchr.cpp \
     upstream-freebsd/lib/libc/string/wcscat.c \
     upstream-freebsd/lib/libc/string/wcschr.c \
@@ -17,7 +14,6 @@
     upstream-openbsd/lib/libc/string/stpcpy.c \
     upstream-openbsd/lib/libc/string/stpncpy.c \
     upstream-openbsd/lib/libc/string/strcat.c \
-    upstream-openbsd/lib/libc/string/strcpy.c \
     upstream-openbsd/lib/libc/string/strlcat.c \
     upstream-openbsd/lib/libc/string/strlcpy.c \
     upstream-openbsd/lib/libc/string/strncat.c \
@@ -42,7 +38,6 @@
     arch-arm64/bionic/__set_tls.c \
     arch-arm64/bionic/sigsetjmp.S \
     arch-arm64/bionic/syscall.S \
-    arch-arm64/bionic/vfork.S \
 
 
 libc_crt_target_cflags_arm64 := \
@@ -60,7 +55,7 @@
 endif
 cpu_variant_mk := $(LOCAL_PATH)/arch-arm64/$(TARGET_CPU_VARIANT)/$(TARGET_CPU_VARIANT).mk
 ifeq ($(wildcard $(cpu_variant_mk)),)
-$(error "TARGET_CPU_VARIANT not set or set to an unknown value. Possible values are generic, generic-neon. Use generic for devices that do not have a CPU similar to any of the supported cpu variants.")
+$(error "TARGET_CPU_VARIANT not set or set to an unknown value. Possible values are generic, generic-neon, denver64. Use generic for devices that do not have a CPU similar to any of the supported cpu variants.")
 endif
 include $(cpu_variant_mk)
 libc_common_additional_dependencies += $(cpu_variank_mk)
diff --git a/libc/arch-arm64/bionic/__bionic_clone.S b/libc/arch-arm64/bionic/__bionic_clone.S
index d3c0374..74db4b5 100644
--- a/libc/arch-arm64/bionic/__bionic_clone.S
+++ b/libc/arch-arm64/bionic/__bionic_clone.S
@@ -31,12 +31,6 @@
 // pid_t __bionic_clone(int flags, void* child_stack, pid_t* parent_tid, void* tls, pid_t* child_tid, int (*fn)(void*), void* arg);
 
 ENTRY(__bionic_clone)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     # Copy 'fn' and 'arg' onto the child stack.
     stp     x5, x6, [x1, #-16]
 
@@ -47,11 +41,6 @@
     # Are we the child?
     cbz     x0, .L_bc_child
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     # Set errno if something went wrong.
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
@@ -62,10 +51,10 @@
 .L_bc_child:
     # We're in the child now. Set the end of the frame record chain...
     mov     x29, xzr
-    # Setting x30 to 0 will make the unwinder stop at __bionic_clone_entry
+    # Setting x30 to 0 will make the unwinder stop at __start_thread
     mov     x30, xzr
-    # ...and call __bionic_clone_entry with the 'fn' and 'arg' we stored on the child stack.
+    # ...and call __start_thread with the 'fn' and 'arg' we stored on the child stack.
     ldp     x0, x1, [sp, #-16]
-    b       __bionic_clone_entry
+    b       __start_thread
 END(__bionic_clone)
 .hidden __bionic_clone
diff --git a/libc/arch-arm64/bionic/syscall.S b/libc/arch-arm64/bionic/syscall.S
index 42e8883..658af78 100644
--- a/libc/arch-arm64/bionic/syscall.S
+++ b/libc/arch-arm64/bionic/syscall.S
@@ -29,13 +29,6 @@
 #include <private/bionic_asm.h>
 
 ENTRY(syscall)
-    /* create AAPCS frame pointer */
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     /* Move syscall No. from x0 to x8 */
     mov     x8, x0
     /* Move syscall parameters from x1 thru x6 to x0 thru x5 */
@@ -47,11 +40,6 @@
     mov     x5, x6
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     /* check if syscall returned successfully */
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
diff --git a/libc/arch-arm64/bionic/vfork.S b/libc/arch-arm64/bionic/vfork.S
deleted file mode 100644
index c700623..0000000
--- a/libc/arch-arm64/bionic/vfork.S
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (C) 2013 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_asm.h>
-#include <asm/signal.h>
-#include <linux/sched.h>
-
-ENTRY(vfork)
-    mov     x0, #(CLONE_VM | CLONE_VFORK | SIGCHLD)
-    mov     x1, xzr
-    mov     x2, xzr
-    mov     x3, xzr
-    mov     x4, xzr
-
-    mov     x8, __NR_clone
-    svc     #0
-
-    cmn     x0, #(MAX_ERRNO + 1)
-    cneg    x0, x0, hi
-    b.hi    __set_errno
-
-    ret
-END(vfork)
diff --git a/libc/arch-arm64/denver64/bionic/memcpy.S b/libc/arch-arm64/denver64/bionic/memcpy.S
new file mode 100644
index 0000000..700f0d0
--- /dev/null
+++ b/libc/arch-arm64/denver64/bionic/memcpy.S
@@ -0,0 +1,205 @@
+/* Copyright (c) 2012, Linaro Limited
+   All rights reserved.
+   Copyright (c) 2014, NVIDIA Corporation.  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.
+       * Neither the name of the Linaro 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 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
+   HOLDER 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.
+*/
+
+/* Assumptions:
+ *
+ * denver, ARMv8-a, AArch64
+ * Unaligned accesses
+ *
+ */
+
+#include <private/bionic_asm.h>
+
+#define dstin	x0
+#define src	x1
+#define count	x2
+#define tmp1	x3
+#define tmp1w	w3
+#define tmp2	x4
+#define tmp2w	w4
+#define tmp3	x5
+#define tmp3w	w5
+#define dst	x6
+
+#define A_l	x7
+#define A_h	x8
+#define B_l	x9
+#define B_h	x10
+#define C_l	x11
+#define C_h	x12
+#define D_l	x13
+#define D_h	x14
+
+#define QA_l	q0
+#define QA_h	q1
+#define QB_l	q2
+#define QB_h	q3
+
+ENTRY(memcpy)
+
+	mov	dst, dstin
+	cmp	count, #64
+	b.ge	.Lcpy_not_short
+	cmp	count, #15
+	b.le	.Ltail15tiny
+
+	/* Deal with small copies quickly by dropping straight into the
+	 * exit block.  */
+.Ltail63:
+	/* Copy up to 48 bytes of data.  At this point we only need the
+	 * bottom 6 bits of count to be accurate.  */
+	ands	tmp1, count, #0x30
+	b.eq	.Ltail15
+	add	dst, dst, tmp1
+	add	src, src, tmp1
+	cmp	tmp1w, #0x20
+	b.eq	1f
+	b.lt	2f
+	ldp	A_l, A_h, [src, #-48]
+	stp	A_l, A_h, [dst, #-48]
+1:
+	ldp	A_l, A_h, [src, #-32]
+	stp	A_l, A_h, [dst, #-32]
+2:
+	ldp	A_l, A_h, [src, #-16]
+	stp	A_l, A_h, [dst, #-16]
+
+.Ltail15:
+	ands	count, count, #15
+	beq	1f
+	add	src, src, count
+	ldp	A_l, A_h, [src, #-16]
+	add	dst, dst, count
+	stp	A_l, A_h, [dst, #-16]
+1:
+	ret
+
+.Ltail15tiny:
+	/* Copy up to 15 bytes of data.  Does not assume additional data
+	   being copied.  */
+	tbz	count, #3, 1f
+	ldr	tmp1, [src], #8
+	str	tmp1, [dst], #8
+1:
+	tbz	count, #2, 1f
+	ldr	tmp1w, [src], #4
+	str	tmp1w, [dst], #4
+1:
+	tbz	count, #1, 1f
+	ldrh	tmp1w, [src], #2
+	strh	tmp1w, [dst], #2
+1:
+	tbz	count, #0, 1f
+	ldrb	tmp1w, [src]
+	strb	tmp1w, [dst]
+1:
+	ret
+
+.Lcpy_not_short:
+	/* We don't much care about the alignment of DST, but we want SRC
+	 * to be 128-bit (16 byte) aligned so that we don't cross cache line
+	 * boundaries on both loads and stores.  */
+	neg	tmp2, src
+	ands	tmp2, tmp2, #15		/* Bytes to reach alignment.  */
+	b.eq	2f
+	sub	count, count, tmp2
+	/* Copy more data than needed; it's faster than jumping
+	 * around copying sub-Quadword quantities.  We know that
+	 * it can't overrun.  */
+	ldp	A_l, A_h, [src]
+	add	src, src, tmp2
+	stp	A_l, A_h, [dst]
+	add	dst, dst, tmp2
+	/* There may be less than 63 bytes to go now.  */
+	cmp	count, #63
+	b.le	.Ltail63
+2:
+	subs	count, count, #128
+	b.ge	.Lcpy_body_large
+	/* Less than 128 bytes to copy, so handle 64 here and then jump
+	 * to the tail.  */
+	ldp	QA_l, QA_h, [src]
+	ldp	QB_l, QB_h, [src, #32]
+	stp	QA_l, QA_h, [dst]
+	stp	QB_l, QB_h, [dst, #32]
+	tst	count, #0x3f
+	add	src, src, #64
+	add	dst, dst, #64
+	b.ne	.Ltail63
+	ret
+
+	/* Critical loop.  Start at a new cache line boundary.  Assuming
+	 * 64 bytes per line this ensures the entire loop is in one line.  */
+	.p2align 6
+.Lcpy_body_large:
+	cmp	count, 65536
+	bhi	.Lcpy_body_huge
+	/* There are at least 128 bytes to copy.  */
+	ldp	QA_l, QA_h, [src, #0]
+	sub	dst, dst, #32		/* Pre-bias.  */
+	ldp	QB_l, QB_h, [src, #32]!	/* src += 64 - Pre-bias.  */
+1:
+	stp	QA_l, QA_h, [dst, #32]
+	ldp	QA_l, QA_h, [src, #32]
+	stp	QB_l, QB_h, [dst, #64]!
+	ldp	QB_l, QB_h, [src, #64]!
+
+	subs	count, count, #64
+	b.ge	1b
+
+	stp	QA_l, QA_h, [dst, #32]
+	stp	QB_l, QB_h, [dst, #64]
+	add	src, src, #32
+	add	dst, dst, #64 + 32
+	tst	count, #0x3f
+	b.ne	.Ltail63
+	ret
+.Lcpy_body_huge:
+	/* There are at least 128 bytes to copy.  */
+	ldp	QA_l, QA_h, [src, #0]
+	sub	dst, dst, #32		/* Pre-bias.  */
+	ldp	QB_l, QB_h, [src, #32]!
+1:
+	stnp	QA_l, QA_h, [dst, #32]
+	stnp	QB_l, QB_h, [dst, #64]
+	ldp	QA_l, QA_h, [src, #32]
+	ldp	QB_l, QB_h, [src, #64]!
+	add	dst, dst, #64
+
+	subs	count, count, #64
+	b.ge	1b
+
+	stnp	QA_l, QA_h, [dst, #32]
+	stnp	QB_l, QB_h, [dst, #64]
+	add	src, src, #32
+	add	dst, dst, #64 + 32
+	tst	count, #0x3f
+	b.ne	.Ltail63
+	ret
+
+END(memcpy)
diff --git a/libc/arch-arm64/denver64/bionic/memset.S b/libc/arch-arm64/denver64/bionic/memset.S
new file mode 100644
index 0000000..9127d89
--- /dev/null
+++ b/libc/arch-arm64/denver64/bionic/memset.S
@@ -0,0 +1,271 @@
+/* Copyright (c) 2012, Linaro Limited
+   All rights reserved.
+   Copyright (c) 2014, NVIDIA Corporation.  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.
+       * Neither the name of the Linaro 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 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
+   HOLDER 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.
+*/
+
+/* Assumptions:
+ *
+ * denver, ARMv8-a, AArch64
+ * Unaligned accesses
+ *
+ */
+
+#include <private/bionic_asm.h>
+
+/* By default we assume that the DC instruction can be used to zero
+   data blocks more efficiently.  In some circumstances this might be
+   unsafe, for example in an asymmetric multiprocessor environment with
+   different DC clear lengths (neither the upper nor lower lengths are
+   safe to use).  The feature can be disabled by defining DONT_USE_DC.
+
+   If code may be run in a virtualized environment, then define
+   MAYBE_VIRT.  This will cause the code to cache the system register
+   values rather than re-reading them each call.  */
+
+#define dstin		x0
+#define val		w1
+#define count		x2
+#define tmp1		x3
+#define tmp1w		w3
+#define tmp2		x4
+#define tmp2w		w4
+#define zva_len_x	x5
+#define zva_len		w5
+#define zva_bits_x	x6
+
+#define A_l		x7
+#define A_lw		w7
+#define dst		x8
+#define tmp3w		w9
+
+#define QA_l		q0
+
+ENTRY(memset)
+
+	mov	dst, dstin		/* Preserve return value.  */
+	ands	A_lw, val, #255
+#ifndef DONT_USE_DC
+#	b.eq	.Lzero_mem
+#endif
+	orr	A_lw, A_lw, A_lw, lsl #8
+	orr	A_lw, A_lw, A_lw, lsl #16
+	orr	A_l, A_l, A_l, lsl #32
+.Ltail_maybe_long:
+	cmp	count, #256
+	b.ge	.Lnot_short
+.Ltail_maybe_tiny:
+	cmp	count, #15
+	b.le	.Ltail15tiny
+.Ltail255:
+	ands	tmp1, count, #0xC0
+	b.eq	.Ltail63
+	dup	v0.4s, A_lw
+	cmp	tmp1w, #0x80
+	b.eq	1f
+	b.lt	2f
+	stp	QA_l, QA_l, [dst], #32
+	stp	QA_l, QA_l, [dst], #32
+1:
+	stp	QA_l, QA_l, [dst], #32
+	stp	QA_l, QA_l, [dst], #32
+2:
+	stp	QA_l, QA_l, [dst], #32
+	stp	QA_l, QA_l, [dst], #32
+.Ltail63:
+	ands	tmp1, count, #0x30
+	b.eq	.Ltail15
+	add	dst, dst, tmp1
+	cmp	tmp1w, #0x20
+	b.eq	1f
+	b.lt	2f
+	stp	A_l, A_l, [dst, #-48]
+1:
+	stp	A_l, A_l, [dst, #-32]
+2:
+	stp	A_l, A_l, [dst, #-16]
+
+.Ltail15:
+	and	count, count, #15
+	add	dst, dst, count
+	stp	A_l, A_l, [dst, #-16]	/* Repeat some/all of last store. */
+	ret
+
+.Ltail15tiny:
+	/* Set up to 15 bytes.  Does not assume earlier memory
+	   being set.  */
+	tbz	count, #3, 1f
+	str	A_l, [dst], #8
+1:
+	tbz	count, #2, 1f
+	str	A_lw, [dst], #4
+1:
+	tbz	count, #1, 1f
+	strh	A_lw, [dst], #2
+1:
+	tbz	count, #0, 1f
+	strb	A_lw, [dst]
+1:
+	ret
+
+	/* Critical loop.  Start at a new cache line boundary.  Assuming
+	 * 64 bytes per line, this ensures the entire loop is in one line.  */
+	.p2align 6
+.Lnot_short:
+	dup	v0.4s, A_lw
+	neg	tmp2, dst
+	ands	tmp2, tmp2, #15
+	b.eq	2f
+	/* Bring DST to 128-bit (16-byte) alignment.  We know that there's
+	 * more than that to set, so we simply store 16 bytes and advance by
+	 * the amount required to reach alignment.  */
+	sub	count, count, tmp2
+	stp	A_l, A_l, [dst]
+	add	dst, dst, tmp2
+	/* There may be less than 63 bytes to go now.  */
+	cmp	count, #255
+	b.le	.Ltail255
+2:
+	cmp	count, #2097152
+	b.gt	3f
+1:
+	sub	count, count, #256
+2:
+	stp	QA_l, QA_l, [dst], #32
+	stp	QA_l, QA_l, [dst], #32
+	stp	QA_l, QA_l, [dst], #32
+	stp	QA_l, QA_l, [dst], #32
+	stp	QA_l, QA_l, [dst], #32
+	stp	QA_l, QA_l, [dst], #32
+	stp	QA_l, QA_l, [dst], #32
+	stp	QA_l, QA_l, [dst], #32
+	subs	count, count, #256
+	b.ge	2b
+	tst	count, #0xff
+	b.ne	.Ltail255
+	ret
+3:
+	sub	count, count, #64
+4:
+	subs	count, count, #64
+	stnp	QA_l, QA_l, [dst]
+	stnp	QA_l, QA_l, [dst, #32]
+	add	dst, dst, #64
+	b.ge	4b
+	tst	count, #0x3f
+	b.ne	.Ltail63
+	ret
+
+#ifndef DONT_USE_DC
+	/* For zeroing memory, check to see if we can use the ZVA feature to
+	 * zero entire 'cache' lines.  */
+.Lzero_mem:
+	mov	A_l, #0
+	cmp	count, #63
+	b.le	.Ltail_maybe_tiny
+	neg	tmp2, dst
+	ands	tmp2, tmp2, #15
+	b.eq	1f
+	sub	count, count, tmp2
+	stp	A_l, A_l, [dst]
+	add	dst, dst, tmp2
+	cmp	count, #63
+	b.le	.Ltail63
+1:
+	/* For zeroing small amounts of memory, it's not worth setting up
+	 * the line-clear code.  */
+	cmp	count, #128
+	b.lt	.Lnot_short
+#ifdef MAYBE_VIRT
+	/* For efficiency when virtualized, we cache the ZVA capability.  */
+	adrp	tmp2, .Lcache_clear
+	ldr	zva_len, [tmp2, #:lo12:.Lcache_clear]
+	tbnz	zva_len, #31, .Lnot_short
+	cbnz	zva_len, .Lzero_by_line
+	mrs	tmp1, dczid_el0
+	tbz	tmp1, #4, 1f
+	/* ZVA not available.  Remember this for next time.  */
+	mov	zva_len, #~0
+	str	zva_len, [tmp2, #:lo12:.Lcache_clear]
+	b	.Lnot_short
+1:
+	mov	tmp3w, #4
+	and	zva_len, tmp1w, #15	/* Safety: other bits reserved.  */
+	lsl	zva_len, tmp3w, zva_len
+	str	zva_len, [tmp2, #:lo12:.Lcache_clear]
+#else
+	mrs	tmp1, dczid_el0
+	tbnz	tmp1, #4, .Lnot_short
+	mov	tmp3w, #4
+	and	zva_len, tmp1w, #15	/* Safety: other bits reserved.  */
+	lsl	zva_len, tmp3w, zva_len
+#endif
+
+.Lzero_by_line:
+	/* Compute how far we need to go to become suitably aligned.  We're
+	 * already at quad-word alignment.  */
+	cmp	count, zva_len_x
+	b.lt	.Lnot_short		/* Not enough to reach alignment.  */
+	sub	zva_bits_x, zva_len_x, #1
+	neg	tmp2, dst
+	ands	tmp2, tmp2, zva_bits_x
+	b.eq	1f			/* Already aligned.  */
+	/* Not aligned, check that there's enough to copy after alignment.  */
+	sub	tmp1, count, tmp2
+	cmp	tmp1, #64
+	ccmp	tmp1, zva_len_x, #8, ge	/* NZCV=0b1000 */
+	b.lt	.Lnot_short
+	/* We know that there's at least 64 bytes to zero and that it's safe
+	 * to overrun by 64 bytes.  */
+	mov	count, tmp1
+2:
+	stp	A_l, A_l, [dst]
+	stp	A_l, A_l, [dst, #16]
+	stp	A_l, A_l, [dst, #32]
+	subs	tmp2, tmp2, #64
+	stp	A_l, A_l, [dst, #48]
+	add	dst, dst, #64
+	b.ge	2b
+	/* We've overrun a bit, so adjust dst downwards.  */
+	add	dst, dst, tmp2
+1:
+	sub	count, count, zva_len_x
+3:
+	dc	zva, dst
+	add	dst, dst, zva_len_x
+	subs	count, count, zva_len_x
+	b.ge	3b
+	ands	count, count, zva_bits_x
+	b.ne	.Ltail_maybe_long
+	ret
+END(memset)
+
+#ifdef MAYBE_VIRT
+	.bss
+	.p2align 2
+.Lcache_clear:
+	.space 4
+#endif
+#endif /* DONT_USE_DC */
diff --git a/libc/arch-arm64/denver64/denver64.mk b/libc/arch-arm64/denver64/denver64.mk
new file mode 100644
index 0000000..9f3de2d
--- /dev/null
+++ b/libc/arch-arm64/denver64/denver64.mk
@@ -0,0 +1,12 @@
+libc_bionic_src_files_arm64 += \
+    arch-arm64/generic/bionic/memcmp.S \
+    arch-arm64/denver64/bionic/memcpy.S \
+    arch-arm64/generic/bionic/memmove.S \
+    arch-arm64/denver64/bionic/memset.S \
+    arch-arm64/generic/bionic/strchr.S \
+    arch-arm64/generic/bionic/strcmp.S \
+    arch-arm64/generic/bionic/strcpy.S \
+    arch-arm64/generic/bionic/strlen.S \
+    arch-arm64/generic/bionic/strncmp.S \
+    arch-arm64/generic/bionic/strnlen.S \
+    arch-arm64/generic/bionic/wmemmove.S
diff --git a/libc/arch-arm64/generic-neon/generic-neon.mk b/libc/arch-arm64/generic-neon/generic-neon.mk
index 2cbe3cf..b464d96 100644
--- a/libc/arch-arm64/generic-neon/generic-neon.mk
+++ b/libc/arch-arm64/generic-neon/generic-neon.mk
@@ -2,7 +2,9 @@
     arch-arm64/generic/bionic/memcmp.S \
     arch-arm64/generic/bionic/memmove.S \
     arch-arm64/generic/bionic/memset.S \
+    arch-arm64/generic/bionic/strchr.S \
     arch-arm64/generic/bionic/strcmp.S \
+    arch-arm64/generic/bionic/strcpy.S \
     arch-arm64/generic/bionic/strlen.S \
     arch-arm64/generic/bionic/strncmp.S \
     arch-arm64/generic/bionic/strnlen.S \
diff --git a/libc/arch-arm64/generic/bionic/strchr.S b/libc/arch-arm64/generic/bionic/strchr.S
new file mode 100644
index 0000000..158eaf7
--- /dev/null
+++ b/libc/arch-arm64/generic/bionic/strchr.S
@@ -0,0 +1,153 @@
+/*
+   strchr - find a character in a string
+
+   Copyright (c) 2014, ARM Limited
+   All rights Reserved.
+   Copyright (c) 2014, Linaro Ltd.
+
+   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.
+       * Neither the name of the company 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 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
+   HOLDER 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.  */
+
+/* Assumptions:
+ *
+ * ARMv8-a, AArch64
+ * Neon Available.
+ */
+
+#include <private/bionic_asm.h>
+
+/* Arguments and results.  */
+#define srcin		x0
+#define chrin		w1
+
+#define result		x0
+
+#define src		x2
+#define	tmp1		x3
+#define wtmp2		w4
+#define tmp3		x5
+
+#define vrepchr		v0
+#define vdata1		v1
+#define vdata2		v2
+#define vhas_nul1	v3
+#define vhas_nul2	v4
+#define vhas_chr1	v5
+#define vhas_chr2	v6
+#define vrepmask_0	v7
+#define vrepmask_c	v16
+#define vend1		v17
+#define vend2		v18
+
+/* Core algorithm.
+
+   For each 32-byte hunk we calculate a 64-bit syndrome value, with
+   two bits per byte (LSB is always in bits 0 and 1, for both big
+   and little-endian systems).  For each tuple, bit 0 is set iff
+   the relevant byte matched the requested character; bit 1 is set
+   iff the relevant byte matched the NUL end of string (we trigger
+   off bit0 for the special case of looking for NUL).  Since the bits
+   in the syndrome reflect exactly the order in which things occur
+   in the original string a count_trailing_zeros() operation will
+   identify exactly which byte is causing the termination, and why.  */
+
+/* Locals and temporaries.  */
+
+ENTRY(strchr)
+	/* Magic constant 0x40100401 to allow us to identify which lane
+	   matches the requested byte.  Magic constant 0x80200802 used
+	   similarly for NUL termination.  */
+	mov	wtmp2, #0x0401
+	movk	wtmp2, #0x4010, lsl #16
+	dup	vrepchr.16b, chrin
+	bic	src, srcin, #31		/* Work with aligned 32-byte hunks.  */
+	dup	vrepmask_c.4s, wtmp2
+	ands	tmp1, srcin, #31
+	add	vrepmask_0.4s, vrepmask_c.4s, vrepmask_c.4s /* equiv: lsl #1 */
+	b.eq	.Lloop
+
+	/* Input string is not 32-byte aligned.  Rather than forcing
+	   the padding bytes to a safe value, we calculate the syndrome
+	   for all the bytes, but then mask off those bits of the
+	   syndrome that are related to the padding.  */
+	ld1	{vdata1.16b, vdata2.16b}, [src], #32
+	neg	tmp1, tmp1
+	cmeq	vhas_nul1.16b, vdata1.16b, #0
+	cmeq	vhas_chr1.16b, vdata1.16b, vrepchr.16b
+	cmeq	vhas_nul2.16b, vdata2.16b, #0
+	cmeq	vhas_chr2.16b, vdata2.16b, vrepchr.16b
+	and	vhas_nul1.16b, vhas_nul1.16b, vrepmask_0.16b
+	and	vhas_nul2.16b, vhas_nul2.16b, vrepmask_0.16b
+	and	vhas_chr1.16b, vhas_chr1.16b, vrepmask_c.16b
+	and	vhas_chr2.16b, vhas_chr2.16b, vrepmask_c.16b
+	orr	vend1.16b, vhas_nul1.16b, vhas_chr1.16b
+	orr	vend2.16b, vhas_nul2.16b, vhas_chr2.16b
+	lsl	tmp1, tmp1, #1
+	addp	vend1.16b, vend1.16b, vend2.16b		// 256->128
+	mov	tmp3, #~0
+	addp	vend1.16b, vend1.16b, vend2.16b		// 128->64
+	lsr	tmp1, tmp3, tmp1
+
+	mov	tmp3, vend1.2d[0]
+	bic	tmp1, tmp3, tmp1	// Mask padding bits.
+	cbnz	tmp1, .Ltail
+
+.Lloop:
+	ld1	{vdata1.16b, vdata2.16b}, [src], #32
+	cmeq	vhas_nul1.16b, vdata1.16b, #0
+	cmeq	vhas_chr1.16b, vdata1.16b, vrepchr.16b
+	cmeq	vhas_nul2.16b, vdata2.16b, #0
+	cmeq	vhas_chr2.16b, vdata2.16b, vrepchr.16b
+	/* Use a fast check for the termination condition.  */
+	orr	vend1.16b, vhas_nul1.16b, vhas_chr1.16b
+	orr	vend2.16b, vhas_nul2.16b, vhas_chr2.16b
+	orr	vend1.16b, vend1.16b, vend2.16b
+	addp	vend1.2d, vend1.2d, vend1.2d
+	mov	tmp1, vend1.2d[0]
+	cbz	tmp1, .Lloop
+
+	/* Termination condition found.  Now need to establish exactly why
+	   we terminated.  */
+	and	vhas_nul1.16b, vhas_nul1.16b, vrepmask_0.16b
+	and	vhas_nul2.16b, vhas_nul2.16b, vrepmask_0.16b
+	and	vhas_chr1.16b, vhas_chr1.16b, vrepmask_c.16b
+	and	vhas_chr2.16b, vhas_chr2.16b, vrepmask_c.16b
+	orr	vend1.16b, vhas_nul1.16b, vhas_chr1.16b
+	orr	vend2.16b, vhas_nul2.16b, vhas_chr2.16b
+	addp	vend1.16b, vend1.16b, vend2.16b		// 256->128
+	addp	vend1.16b, vend1.16b, vend2.16b		// 128->64
+
+	mov	tmp1, vend1.2d[0]
+.Ltail:
+	/* Count the trailing zeros, by bit reversing...  */
+	rbit	tmp1, tmp1
+	/* Re-bias source.  */
+	sub	src, src, #32
+	clz	tmp1, tmp1	/* And counting the leading zeros.  */
+	/* Tmp1 is even if the target charager was found first.  Otherwise
+	   we've found the end of string and we weren't looking for NUL.  */
+	tst	tmp1, #1
+	add	result, src, tmp1, lsr #1
+	csel	result, result, xzr, eq
+	ret
+END(strchr)
diff --git a/libc/arch-arm64/generic/bionic/strcpy.S b/libc/arch-arm64/generic/bionic/strcpy.S
new file mode 100644
index 0000000..b15e06d
--- /dev/null
+++ b/libc/arch-arm64/generic/bionic/strcpy.S
@@ -0,0 +1,193 @@
+/*
+ * Copyright (C) 2014 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.
+ */
+/* Copyright (c) 2014, Linaro Limited
+   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.
+       * Neither the name of the Linaro 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 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
+   HOLDER 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.
+*/
+
+/* Assumptions:
+ *
+ * ARMv8-a, AArch64
+ */
+
+#include <private/bionic_asm.h>
+
+/* Arguments and results.  */
+#define dstin       x0
+#define src         x1
+
+/* Locals and temporaries.  */
+#define dst         x2
+#define data1       x3
+#define data1_w     w3
+#define data2       x4
+#define data2_w     w4
+#define has_nul1    x5
+#define has_nul1_w  w5
+#define has_nul2    x6
+#define tmp1        x7
+#define tmp2        x8
+#define tmp3        x9
+#define tmp4        x10
+#define zeroones    x11
+#define zeroones_w  w11
+#define pos         x12
+
+#define REP8_01 0x0101010101010101
+#define REP8_7f 0x7f7f7f7f7f7f7f7f
+#define REP8_80 0x8080808080808080
+
+ENTRY(strcpy)
+    mov     zeroones, #REP8_01
+    mov     dst, dstin
+    ands    tmp1, src, #15
+    b.ne    .Lmisaligned
+    // NUL detection works on the principle that (X - 1) & (~X) & 0x80
+    // (=> (X - 1) & ~(X | 0x7f)) is non-zero iff a byte is zero, and
+    // can be done in parallel across the entire word.
+    // The inner loop deals with two Dwords at a time.  This has a
+    // slightly higher start-up cost, but we should win quite quickly,
+    // especially on cores with a high number of issue slots per
+    // cycle, as we get much better parallelism out of the operations.
+.Lloop:
+    ldp     data1, data2, [src], #16
+    sub     tmp1, data1, zeroones
+    orr     tmp2, data1, #REP8_7f
+    bic     has_nul1, tmp1, tmp2
+    cbnz    has_nul1, .Lnul_in_data1
+    sub     tmp3, data2, zeroones
+    orr     tmp4, data2, #REP8_7f
+    bic     has_nul2, tmp3, tmp4
+    cbnz    has_nul2, .Lnul_in_data2
+    // No NUL in either register, copy it in a single instruction.
+    stp     data1, data2, [dst], #16
+    b       .Lloop
+
+.Lnul_in_data1:
+    rev     has_nul1, has_nul1
+    clz     pos, has_nul1
+    add     tmp1, pos, #0x8
+
+    tbz     tmp1, #6, 1f
+    str     data1, [dst]
+    ret
+1:
+    tbz     tmp1, #5, 1f
+    str     data1_w, [dst], #4
+    lsr     data1, data1, #32
+1:
+    tbz     tmp1, #4, 1f
+    strh    data1_w, [dst], #2
+    lsr     data1, data1, #16
+1:
+    tbz     tmp1, #3, 1f
+    strb    data1_w, [dst]
+1:
+    ret
+
+.Lnul_in_data2:
+    str     data1, [dst], #8
+    rev     has_nul2, has_nul2
+    clz     pos, has_nul2
+    add     tmp1, pos, #0x8
+
+    tbz     tmp1, #6, 1f
+    str     data2, [dst]
+    ret
+1:
+    tbz     tmp1, #5, 1f
+    str     data2_w, [dst], #4
+    lsr     data2, data2, #32
+1:
+    tbz     tmp1, #4, 1f
+    strh    data2_w, [dst], #2
+    lsr     data2, data2, #16
+1:
+    tbz     tmp1, #3, 1f
+    strb    data2_w, [dst]
+1:
+    ret
+
+.Lmisaligned:
+    tbz     src, #0, 1f
+    ldrb    data1_w, [src], #1
+    strb    data1_w, [dst], #1
+    cbnz    data1_w, 1f
+    ret
+1:
+    tbz     src, #1, 1f
+    ldrb    data1_w, [src], #1
+    strb    data1_w, [dst], #1
+    cbz     data1_w, .Ldone
+    ldrb    data2_w, [src], #1
+    strb    data2_w, [dst], #1
+    cbnz    data2_w, 1f
+.Ldone:
+    ret
+1:
+    tbz     src, #2, 1f
+    ldr     data1_w, [src], #4
+    // Check for a zero.
+    sub     has_nul1_w, data1_w, zeroones_w
+    bic     has_nul1_w, has_nul1_w, data1_w
+    ands    has_nul1_w, has_nul1_w, #0x80808080
+    b.ne    .Lnul_in_data1
+    str     data1_w, [dst], #4
+1:
+    tbz     src, #3, .Lloop
+    ldr     data1, [src], #8
+    // Check for a zero.
+    sub     tmp1, data1, zeroones
+    orr     tmp2, data1, #REP8_7f
+    bics    has_nul1, tmp1, tmp2
+    b.ne    .Lnul_in_data1
+    str     data1, [dst], #8
+    b       .Lloop
+END(strcpy)
diff --git a/libc/arch-arm64/generic/generic.mk b/libc/arch-arm64/generic/generic.mk
index e10cf66..2aed7e1 100644
--- a/libc/arch-arm64/generic/generic.mk
+++ b/libc/arch-arm64/generic/generic.mk
@@ -3,7 +3,9 @@
     arch-arm64/generic/bionic/memcpy.S \
     arch-arm64/generic/bionic/memmove.S \
     arch-arm64/generic/bionic/memset.S \
+    arch-arm64/generic/bionic/strchr.S \
     arch-arm64/generic/bionic/strcmp.S \
+    arch-arm64/generic/bionic/strcpy.S \
     arch-arm64/generic/bionic/strlen.S \
     arch-arm64/generic/bionic/strncmp.S \
     arch-arm64/generic/bionic/strnlen.S \
diff --git a/libc/arch-arm64/syscalls/__accept4.S b/libc/arch-arm64/syscalls/__accept4.S
index 34f2c52..1c2a674 100644
--- a/libc/arch-arm64/syscalls/__accept4.S
+++ b/libc/arch-arm64/syscalls/__accept4.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(__accept4)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_accept4
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/__brk.S b/libc/arch-arm64/syscalls/__brk.S
index fb63fb9..85ed767 100644
--- a/libc/arch-arm64/syscalls/__brk.S
+++ b/libc/arch-arm64/syscalls/__brk.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(__brk)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_brk
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/__connect.S b/libc/arch-arm64/syscalls/__connect.S
index e578ccc..0d664f0 100644
--- a/libc/arch-arm64/syscalls/__connect.S
+++ b/libc/arch-arm64/syscalls/__connect.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(__connect)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_connect
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/__epoll_pwait.S b/libc/arch-arm64/syscalls/__epoll_pwait.S
index 57b01c2..45275c0 100644
--- a/libc/arch-arm64/syscalls/__epoll_pwait.S
+++ b/libc/arch-arm64/syscalls/__epoll_pwait.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(__epoll_pwait)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_epoll_pwait
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/__exit.S b/libc/arch-arm64/syscalls/__exit.S
index 8600b13..e358513 100644
--- a/libc/arch-arm64/syscalls/__exit.S
+++ b/libc/arch-arm64/syscalls/__exit.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(__exit)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_exit
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/__getcpu.S b/libc/arch-arm64/syscalls/__getcpu.S
index e81ba23..5e4368f 100644
--- a/libc/arch-arm64/syscalls/__getcpu.S
+++ b/libc/arch-arm64/syscalls/__getcpu.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(__getcpu)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_getcpu
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/__getcwd.S b/libc/arch-arm64/syscalls/__getcwd.S
index fc48f80..bd4fbaa 100644
--- a/libc/arch-arm64/syscalls/__getcwd.S
+++ b/libc/arch-arm64/syscalls/__getcwd.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(__getcwd)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_getcwd
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/__getdents64.S b/libc/arch-arm64/syscalls/__getdents64.S
new file mode 100644
index 0000000..bf0f9a4
--- /dev/null
+++ b/libc/arch-arm64/syscalls/__getdents64.S
@@ -0,0 +1,15 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__getdents64)
+    mov     x8, __NR_getdents64
+    svc     #0
+
+    cmn     x0, #(MAX_ERRNO + 1)
+    cneg    x0, x0, hi
+    b.hi    __set_errno
+
+    ret
+END(__getdents64)
+.hidden __getdents64
diff --git a/libc/arch-arm64/syscalls/__getpid.S b/libc/arch-arm64/syscalls/__getpid.S
new file mode 100644
index 0000000..c3003c3
--- /dev/null
+++ b/libc/arch-arm64/syscalls/__getpid.S
@@ -0,0 +1,15 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__getpid)
+    mov     x8, __NR_getpid
+    svc     #0
+
+    cmn     x0, #(MAX_ERRNO + 1)
+    cneg    x0, x0, hi
+    b.hi    __set_errno
+
+    ret
+END(__getpid)
+.hidden __getpid
diff --git a/libc/arch-arm64/syscalls/__getpriority.S b/libc/arch-arm64/syscalls/__getpriority.S
index 486ea8f..57ceabf 100644
--- a/libc/arch-arm64/syscalls/__getpriority.S
+++ b/libc/arch-arm64/syscalls/__getpriority.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(__getpriority)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_getpriority
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/__ioctl.S b/libc/arch-arm64/syscalls/__ioctl.S
index 30ff73c..f632555 100644
--- a/libc/arch-arm64/syscalls/__ioctl.S
+++ b/libc/arch-arm64/syscalls/__ioctl.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(__ioctl)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_ioctl
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/__openat.S b/libc/arch-arm64/syscalls/__openat.S
index 22e2f6a..e1b0da3 100644
--- a/libc/arch-arm64/syscalls/__openat.S
+++ b/libc/arch-arm64/syscalls/__openat.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(__openat)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_openat
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/__ppoll.S b/libc/arch-arm64/syscalls/__ppoll.S
index 1739dea..31e5578 100644
--- a/libc/arch-arm64/syscalls/__ppoll.S
+++ b/libc/arch-arm64/syscalls/__ppoll.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(__ppoll)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_ppoll
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/__pselect6.S b/libc/arch-arm64/syscalls/__pselect6.S
index 2770164..b0e4770 100644
--- a/libc/arch-arm64/syscalls/__pselect6.S
+++ b/libc/arch-arm64/syscalls/__pselect6.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(__pselect6)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_pselect6
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/__ptrace.S b/libc/arch-arm64/syscalls/__ptrace.S
index 3746530..054bb6f 100644
--- a/libc/arch-arm64/syscalls/__ptrace.S
+++ b/libc/arch-arm64/syscalls/__ptrace.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(__ptrace)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_ptrace
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/__reboot.S b/libc/arch-arm64/syscalls/__reboot.S
index b1ea418..e24553c 100644
--- a/libc/arch-arm64/syscalls/__reboot.S
+++ b/libc/arch-arm64/syscalls/__reboot.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(__reboot)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_reboot
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/__rt_sigaction.S b/libc/arch-arm64/syscalls/__rt_sigaction.S
index 33e07cb..3d84544 100644
--- a/libc/arch-arm64/syscalls/__rt_sigaction.S
+++ b/libc/arch-arm64/syscalls/__rt_sigaction.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(__rt_sigaction)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_rt_sigaction
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/__rt_sigpending.S b/libc/arch-arm64/syscalls/__rt_sigpending.S
index fa6812e..60f0a10 100644
--- a/libc/arch-arm64/syscalls/__rt_sigpending.S
+++ b/libc/arch-arm64/syscalls/__rt_sigpending.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(__rt_sigpending)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_rt_sigpending
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/__rt_sigprocmask.S b/libc/arch-arm64/syscalls/__rt_sigprocmask.S
index 537f8bd..7f5b3ac 100644
--- a/libc/arch-arm64/syscalls/__rt_sigprocmask.S
+++ b/libc/arch-arm64/syscalls/__rt_sigprocmask.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(__rt_sigprocmask)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_rt_sigprocmask
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/__rt_sigsuspend.S b/libc/arch-arm64/syscalls/__rt_sigsuspend.S
index b8a99c6..08b1197 100644
--- a/libc/arch-arm64/syscalls/__rt_sigsuspend.S
+++ b/libc/arch-arm64/syscalls/__rt_sigsuspend.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(__rt_sigsuspend)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_rt_sigsuspend
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/__rt_sigtimedwait.S b/libc/arch-arm64/syscalls/__rt_sigtimedwait.S
index 869442c..8bc9a7a 100644
--- a/libc/arch-arm64/syscalls/__rt_sigtimedwait.S
+++ b/libc/arch-arm64/syscalls/__rt_sigtimedwait.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(__rt_sigtimedwait)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_rt_sigtimedwait
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/__sched_getaffinity.S b/libc/arch-arm64/syscalls/__sched_getaffinity.S
index 8ca23d4..c0d392c 100644
--- a/libc/arch-arm64/syscalls/__sched_getaffinity.S
+++ b/libc/arch-arm64/syscalls/__sched_getaffinity.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(__sched_getaffinity)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_sched_getaffinity
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/__set_tid_address.S b/libc/arch-arm64/syscalls/__set_tid_address.S
index 5514aed..296c907 100644
--- a/libc/arch-arm64/syscalls/__set_tid_address.S
+++ b/libc/arch-arm64/syscalls/__set_tid_address.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(__set_tid_address)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_set_tid_address
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/__signalfd4.S b/libc/arch-arm64/syscalls/__signalfd4.S
index ea49fc5..3932003 100644
--- a/libc/arch-arm64/syscalls/__signalfd4.S
+++ b/libc/arch-arm64/syscalls/__signalfd4.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(__signalfd4)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_signalfd4
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/__socket.S b/libc/arch-arm64/syscalls/__socket.S
index f96a1ab..db7f2aa 100644
--- a/libc/arch-arm64/syscalls/__socket.S
+++ b/libc/arch-arm64/syscalls/__socket.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(__socket)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_socket
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/__timer_create.S b/libc/arch-arm64/syscalls/__timer_create.S
index 87183b4..a5e69e3 100644
--- a/libc/arch-arm64/syscalls/__timer_create.S
+++ b/libc/arch-arm64/syscalls/__timer_create.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(__timer_create)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_timer_create
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/__timer_delete.S b/libc/arch-arm64/syscalls/__timer_delete.S
index c21ec4f..44a7481 100644
--- a/libc/arch-arm64/syscalls/__timer_delete.S
+++ b/libc/arch-arm64/syscalls/__timer_delete.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(__timer_delete)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_timer_delete
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/__timer_getoverrun.S b/libc/arch-arm64/syscalls/__timer_getoverrun.S
index 47f1ef9..e1d959a 100644
--- a/libc/arch-arm64/syscalls/__timer_getoverrun.S
+++ b/libc/arch-arm64/syscalls/__timer_getoverrun.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(__timer_getoverrun)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_timer_getoverrun
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/__timer_gettime.S b/libc/arch-arm64/syscalls/__timer_gettime.S
index 4eaa655..7632290 100644
--- a/libc/arch-arm64/syscalls/__timer_gettime.S
+++ b/libc/arch-arm64/syscalls/__timer_gettime.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(__timer_gettime)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_timer_gettime
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/__timer_settime.S b/libc/arch-arm64/syscalls/__timer_settime.S
index aef0cc4..92e4a76 100644
--- a/libc/arch-arm64/syscalls/__timer_settime.S
+++ b/libc/arch-arm64/syscalls/__timer_settime.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(__timer_settime)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_timer_settime
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/__waitid.S b/libc/arch-arm64/syscalls/__waitid.S
index 6d9e940..9267239 100644
--- a/libc/arch-arm64/syscalls/__waitid.S
+++ b/libc/arch-arm64/syscalls/__waitid.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(__waitid)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_waitid
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/_exit.S b/libc/arch-arm64/syscalls/_exit.S
index 37d1499..38b073b 100644
--- a/libc/arch-arm64/syscalls/_exit.S
+++ b/libc/arch-arm64/syscalls/_exit.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(_exit)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_exit_group
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/acct.S b/libc/arch-arm64/syscalls/acct.S
index f391cd8..15e3086 100644
--- a/libc/arch-arm64/syscalls/acct.S
+++ b/libc/arch-arm64/syscalls/acct.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(acct)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_acct
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/bind.S b/libc/arch-arm64/syscalls/bind.S
index 10dd01f..b3925db 100644
--- a/libc/arch-arm64/syscalls/bind.S
+++ b/libc/arch-arm64/syscalls/bind.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(bind)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_bind
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/capget.S b/libc/arch-arm64/syscalls/capget.S
index d01dc47..b897e5d 100644
--- a/libc/arch-arm64/syscalls/capget.S
+++ b/libc/arch-arm64/syscalls/capget.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(capget)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_capget
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/capset.S b/libc/arch-arm64/syscalls/capset.S
index c4ed92e..1d94aa3 100644
--- a/libc/arch-arm64/syscalls/capset.S
+++ b/libc/arch-arm64/syscalls/capset.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(capset)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_capset
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/chdir.S b/libc/arch-arm64/syscalls/chdir.S
index 6f1baf0..a7bf6c2 100644
--- a/libc/arch-arm64/syscalls/chdir.S
+++ b/libc/arch-arm64/syscalls/chdir.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(chdir)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_chdir
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/chroot.S b/libc/arch-arm64/syscalls/chroot.S
index b15f04a..98bd5d1 100644
--- a/libc/arch-arm64/syscalls/chroot.S
+++ b/libc/arch-arm64/syscalls/chroot.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(chroot)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_chroot
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/clock_getres.S b/libc/arch-arm64/syscalls/clock_getres.S
index b18c10b..b6e7e56 100644
--- a/libc/arch-arm64/syscalls/clock_getres.S
+++ b/libc/arch-arm64/syscalls/clock_getres.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(clock_getres)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_clock_getres
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/clock_gettime.S b/libc/arch-arm64/syscalls/clock_gettime.S
index b3518c1..ffdde57 100644
--- a/libc/arch-arm64/syscalls/clock_gettime.S
+++ b/libc/arch-arm64/syscalls/clock_gettime.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(clock_gettime)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_clock_gettime
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/clock_nanosleep.S b/libc/arch-arm64/syscalls/clock_nanosleep.S
index eddf6f1..b64ff68 100644
--- a/libc/arch-arm64/syscalls/clock_nanosleep.S
+++ b/libc/arch-arm64/syscalls/clock_nanosleep.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(clock_nanosleep)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_clock_nanosleep
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/clock_settime.S b/libc/arch-arm64/syscalls/clock_settime.S
index c6ba5c0..adc1680 100644
--- a/libc/arch-arm64/syscalls/clock_settime.S
+++ b/libc/arch-arm64/syscalls/clock_settime.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(clock_settime)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_clock_settime
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/close.S b/libc/arch-arm64/syscalls/close.S
index a623895..b4b72d9 100644
--- a/libc/arch-arm64/syscalls/close.S
+++ b/libc/arch-arm64/syscalls/close.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(close)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_close
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/delete_module.S b/libc/arch-arm64/syscalls/delete_module.S
index a57517d..ed51847 100644
--- a/libc/arch-arm64/syscalls/delete_module.S
+++ b/libc/arch-arm64/syscalls/delete_module.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(delete_module)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_delete_module
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/dup.S b/libc/arch-arm64/syscalls/dup.S
index b7e04ed..9584c51 100644
--- a/libc/arch-arm64/syscalls/dup.S
+++ b/libc/arch-arm64/syscalls/dup.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(dup)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_dup
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/dup3.S b/libc/arch-arm64/syscalls/dup3.S
index fada63d..e303fba 100644
--- a/libc/arch-arm64/syscalls/dup3.S
+++ b/libc/arch-arm64/syscalls/dup3.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(dup3)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_dup3
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/epoll_create1.S b/libc/arch-arm64/syscalls/epoll_create1.S
index 94990bf..4ca8bfa 100644
--- a/libc/arch-arm64/syscalls/epoll_create1.S
+++ b/libc/arch-arm64/syscalls/epoll_create1.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(epoll_create1)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_epoll_create1
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/epoll_ctl.S b/libc/arch-arm64/syscalls/epoll_ctl.S
index ea6f735..c1c0dba 100644
--- a/libc/arch-arm64/syscalls/epoll_ctl.S
+++ b/libc/arch-arm64/syscalls/epoll_ctl.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(epoll_ctl)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_epoll_ctl
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/eventfd.S b/libc/arch-arm64/syscalls/eventfd.S
index afa88b3..ace608e 100644
--- a/libc/arch-arm64/syscalls/eventfd.S
+++ b/libc/arch-arm64/syscalls/eventfd.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(eventfd)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_eventfd2
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/execve.S b/libc/arch-arm64/syscalls/execve.S
index 031b6d4..ab0cb57 100644
--- a/libc/arch-arm64/syscalls/execve.S
+++ b/libc/arch-arm64/syscalls/execve.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(execve)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_execve
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/faccessat.S b/libc/arch-arm64/syscalls/faccessat.S
index cebbf18..30a3852 100644
--- a/libc/arch-arm64/syscalls/faccessat.S
+++ b/libc/arch-arm64/syscalls/faccessat.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(faccessat)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_faccessat
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/fallocate.S b/libc/arch-arm64/syscalls/fallocate.S
index 94832aa..3092b34 100644
--- a/libc/arch-arm64/syscalls/fallocate.S
+++ b/libc/arch-arm64/syscalls/fallocate.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(fallocate)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_fallocate
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/fchdir.S b/libc/arch-arm64/syscalls/fchdir.S
index afba3c1..f7687f8 100644
--- a/libc/arch-arm64/syscalls/fchdir.S
+++ b/libc/arch-arm64/syscalls/fchdir.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(fchdir)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_fchdir
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/fchmod.S b/libc/arch-arm64/syscalls/fchmod.S
index 35f9dec..acc6718 100644
--- a/libc/arch-arm64/syscalls/fchmod.S
+++ b/libc/arch-arm64/syscalls/fchmod.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(fchmod)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_fchmod
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/fchmodat.S b/libc/arch-arm64/syscalls/fchmodat.S
index 59bfb8a..23c2fd5 100644
--- a/libc/arch-arm64/syscalls/fchmodat.S
+++ b/libc/arch-arm64/syscalls/fchmodat.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(fchmodat)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_fchmodat
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/fchown.S b/libc/arch-arm64/syscalls/fchown.S
index 2294187..8e9db62 100644
--- a/libc/arch-arm64/syscalls/fchown.S
+++ b/libc/arch-arm64/syscalls/fchown.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(fchown)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_fchown
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/fchownat.S b/libc/arch-arm64/syscalls/fchownat.S
index ff24187..3cf2c3d 100644
--- a/libc/arch-arm64/syscalls/fchownat.S
+++ b/libc/arch-arm64/syscalls/fchownat.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(fchownat)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_fchownat
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/fcntl.S b/libc/arch-arm64/syscalls/fcntl.S
index a9d6976..45eff74 100644
--- a/libc/arch-arm64/syscalls/fcntl.S
+++ b/libc/arch-arm64/syscalls/fcntl.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(fcntl)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_fcntl
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/fdatasync.S b/libc/arch-arm64/syscalls/fdatasync.S
index 4cf4de3..77b76c4 100644
--- a/libc/arch-arm64/syscalls/fdatasync.S
+++ b/libc/arch-arm64/syscalls/fdatasync.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(fdatasync)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_fdatasync
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/fgetxattr.S b/libc/arch-arm64/syscalls/fgetxattr.S
index 914ea7f..1f8edb6 100644
--- a/libc/arch-arm64/syscalls/fgetxattr.S
+++ b/libc/arch-arm64/syscalls/fgetxattr.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(fgetxattr)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_fgetxattr
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/flistxattr.S b/libc/arch-arm64/syscalls/flistxattr.S
index 2a64381..997529e 100644
--- a/libc/arch-arm64/syscalls/flistxattr.S
+++ b/libc/arch-arm64/syscalls/flistxattr.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(flistxattr)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_flistxattr
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/flock.S b/libc/arch-arm64/syscalls/flock.S
index 0d87233..0e1c3f5 100644
--- a/libc/arch-arm64/syscalls/flock.S
+++ b/libc/arch-arm64/syscalls/flock.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(flock)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_flock
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/fremovexattr.S b/libc/arch-arm64/syscalls/fremovexattr.S
index e2ef649..d43430f 100644
--- a/libc/arch-arm64/syscalls/fremovexattr.S
+++ b/libc/arch-arm64/syscalls/fremovexattr.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(fremovexattr)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_fremovexattr
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/fsetxattr.S b/libc/arch-arm64/syscalls/fsetxattr.S
index eb41951..f40f875 100644
--- a/libc/arch-arm64/syscalls/fsetxattr.S
+++ b/libc/arch-arm64/syscalls/fsetxattr.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(fsetxattr)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_fsetxattr
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/fstat64.S b/libc/arch-arm64/syscalls/fstat64.S
index ee0d9e7..9afe95b 100644
--- a/libc/arch-arm64/syscalls/fstat64.S
+++ b/libc/arch-arm64/syscalls/fstat64.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(fstat64)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_fstat
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/fstatat64.S b/libc/arch-arm64/syscalls/fstatat64.S
index 4ff3039..30efd3b 100644
--- a/libc/arch-arm64/syscalls/fstatat64.S
+++ b/libc/arch-arm64/syscalls/fstatat64.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(fstatat64)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_newfstatat
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/fstatfs64.S b/libc/arch-arm64/syscalls/fstatfs64.S
index b908b57..67ae67e 100644
--- a/libc/arch-arm64/syscalls/fstatfs64.S
+++ b/libc/arch-arm64/syscalls/fstatfs64.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(fstatfs64)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_fstatfs
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/fsync.S b/libc/arch-arm64/syscalls/fsync.S
index bac2e8b..e22589e 100644
--- a/libc/arch-arm64/syscalls/fsync.S
+++ b/libc/arch-arm64/syscalls/fsync.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(fsync)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_fsync
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/ftruncate.S b/libc/arch-arm64/syscalls/ftruncate.S
index ca4315a..b45a170 100644
--- a/libc/arch-arm64/syscalls/ftruncate.S
+++ b/libc/arch-arm64/syscalls/ftruncate.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(ftruncate)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_ftruncate
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/getdents.S b/libc/arch-arm64/syscalls/getdents.S
deleted file mode 100644
index 8cd3ca7..0000000
--- a/libc/arch-arm64/syscalls/getdents.S
+++ /dev/null
@@ -1,25 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(getdents)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
-    mov     x8, __NR_getdents64
-    svc     #0
-
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
-    cmn     x0, #(MAX_ERRNO + 1)
-    cneg    x0, x0, hi
-    b.hi    __set_errno
-
-    ret
-END(getdents)
diff --git a/libc/arch-arm64/syscalls/getegid.S b/libc/arch-arm64/syscalls/getegid.S
index 593f51d..675731c 100644
--- a/libc/arch-arm64/syscalls/getegid.S
+++ b/libc/arch-arm64/syscalls/getegid.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(getegid)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_getegid
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/geteuid.S b/libc/arch-arm64/syscalls/geteuid.S
index 845acbc..8d9461e 100644
--- a/libc/arch-arm64/syscalls/geteuid.S
+++ b/libc/arch-arm64/syscalls/geteuid.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(geteuid)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_geteuid
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/getgid.S b/libc/arch-arm64/syscalls/getgid.S
index 5f34355..4653fd8 100644
--- a/libc/arch-arm64/syscalls/getgid.S
+++ b/libc/arch-arm64/syscalls/getgid.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(getgid)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_getgid
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/getgroups.S b/libc/arch-arm64/syscalls/getgroups.S
index d0e2540..f22f1e9 100644
--- a/libc/arch-arm64/syscalls/getgroups.S
+++ b/libc/arch-arm64/syscalls/getgroups.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(getgroups)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_getgroups
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/getitimer.S b/libc/arch-arm64/syscalls/getitimer.S
index 2d4d541..25d0b38 100644
--- a/libc/arch-arm64/syscalls/getitimer.S
+++ b/libc/arch-arm64/syscalls/getitimer.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(getitimer)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_getitimer
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/getpeername.S b/libc/arch-arm64/syscalls/getpeername.S
index 1f64130..aefd0c5 100644
--- a/libc/arch-arm64/syscalls/getpeername.S
+++ b/libc/arch-arm64/syscalls/getpeername.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(getpeername)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_getpeername
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/getpgid.S b/libc/arch-arm64/syscalls/getpgid.S
index 01d876f..4c750fb 100644
--- a/libc/arch-arm64/syscalls/getpgid.S
+++ b/libc/arch-arm64/syscalls/getpgid.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(getpgid)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_getpgid
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/getpid.S b/libc/arch-arm64/syscalls/getpid.S
deleted file mode 100644
index 94b823c..0000000
--- a/libc/arch-arm64/syscalls/getpid.S
+++ /dev/null
@@ -1,25 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(getpid)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
-    mov     x8, __NR_getpid
-    svc     #0
-
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
-    cmn     x0, #(MAX_ERRNO + 1)
-    cneg    x0, x0, hi
-    b.hi    __set_errno
-
-    ret
-END(getpid)
diff --git a/libc/arch-arm64/syscalls/getppid.S b/libc/arch-arm64/syscalls/getppid.S
index 0a46878..540ecc4 100644
--- a/libc/arch-arm64/syscalls/getppid.S
+++ b/libc/arch-arm64/syscalls/getppid.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(getppid)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_getppid
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/getresgid.S b/libc/arch-arm64/syscalls/getresgid.S
index bc121fc..3ce5799 100644
--- a/libc/arch-arm64/syscalls/getresgid.S
+++ b/libc/arch-arm64/syscalls/getresgid.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(getresgid)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_getresgid
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/getresuid.S b/libc/arch-arm64/syscalls/getresuid.S
index 28cd9a4..56851cc 100644
--- a/libc/arch-arm64/syscalls/getresuid.S
+++ b/libc/arch-arm64/syscalls/getresuid.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(getresuid)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_getresuid
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/getrlimit.S b/libc/arch-arm64/syscalls/getrlimit.S
index aa966ca..1f74773 100644
--- a/libc/arch-arm64/syscalls/getrlimit.S
+++ b/libc/arch-arm64/syscalls/getrlimit.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(getrlimit)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_getrlimit
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/getrusage.S b/libc/arch-arm64/syscalls/getrusage.S
index aaaf3a2..8154e4a 100644
--- a/libc/arch-arm64/syscalls/getrusage.S
+++ b/libc/arch-arm64/syscalls/getrusage.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(getrusage)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_getrusage
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/getsid.S b/libc/arch-arm64/syscalls/getsid.S
index e75b7b4..f99623f 100644
--- a/libc/arch-arm64/syscalls/getsid.S
+++ b/libc/arch-arm64/syscalls/getsid.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(getsid)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_getsid
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/getsockname.S b/libc/arch-arm64/syscalls/getsockname.S
index 61e4b4b..e8bc006 100644
--- a/libc/arch-arm64/syscalls/getsockname.S
+++ b/libc/arch-arm64/syscalls/getsockname.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(getsockname)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_getsockname
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/getsockopt.S b/libc/arch-arm64/syscalls/getsockopt.S
index 3740df9..4559d1d 100644
--- a/libc/arch-arm64/syscalls/getsockopt.S
+++ b/libc/arch-arm64/syscalls/getsockopt.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(getsockopt)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_getsockopt
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/gettimeofday.S b/libc/arch-arm64/syscalls/gettimeofday.S
index a72ac91..3b6104b 100644
--- a/libc/arch-arm64/syscalls/gettimeofday.S
+++ b/libc/arch-arm64/syscalls/gettimeofday.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(gettimeofday)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_gettimeofday
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/getuid.S b/libc/arch-arm64/syscalls/getuid.S
index d749cc3..4e37d47 100644
--- a/libc/arch-arm64/syscalls/getuid.S
+++ b/libc/arch-arm64/syscalls/getuid.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(getuid)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_getuid
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/getxattr.S b/libc/arch-arm64/syscalls/getxattr.S
index 451eef5..3f69956 100644
--- a/libc/arch-arm64/syscalls/getxattr.S
+++ b/libc/arch-arm64/syscalls/getxattr.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(getxattr)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_getxattr
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/init_module.S b/libc/arch-arm64/syscalls/init_module.S
index 42ec765..cc1a0da 100644
--- a/libc/arch-arm64/syscalls/init_module.S
+++ b/libc/arch-arm64/syscalls/init_module.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(init_module)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_init_module
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/inotify_add_watch.S b/libc/arch-arm64/syscalls/inotify_add_watch.S
index 066816c..fbc8dd4 100644
--- a/libc/arch-arm64/syscalls/inotify_add_watch.S
+++ b/libc/arch-arm64/syscalls/inotify_add_watch.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(inotify_add_watch)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_inotify_add_watch
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/inotify_init1.S b/libc/arch-arm64/syscalls/inotify_init1.S
index d6bee8c..5726d0c 100644
--- a/libc/arch-arm64/syscalls/inotify_init1.S
+++ b/libc/arch-arm64/syscalls/inotify_init1.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(inotify_init1)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_inotify_init1
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/inotify_rm_watch.S b/libc/arch-arm64/syscalls/inotify_rm_watch.S
index ee9c70f..37eabcf 100644
--- a/libc/arch-arm64/syscalls/inotify_rm_watch.S
+++ b/libc/arch-arm64/syscalls/inotify_rm_watch.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(inotify_rm_watch)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_inotify_rm_watch
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/ioprio_get.S b/libc/arch-arm64/syscalls/ioprio_get.S
deleted file mode 100644
index 4a4a749..0000000
--- a/libc/arch-arm64/syscalls/ioprio_get.S
+++ /dev/null
@@ -1,25 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(ioprio_get)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
-    mov     x8, __NR_ioprio_get
-    svc     #0
-
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
-    cmn     x0, #(MAX_ERRNO + 1)
-    cneg    x0, x0, hi
-    b.hi    __set_errno
-
-    ret
-END(ioprio_get)
diff --git a/libc/arch-arm64/syscalls/ioprio_set.S b/libc/arch-arm64/syscalls/ioprio_set.S
deleted file mode 100644
index 8b48f12..0000000
--- a/libc/arch-arm64/syscalls/ioprio_set.S
+++ /dev/null
@@ -1,25 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(ioprio_set)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
-    mov     x8, __NR_ioprio_set
-    svc     #0
-
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
-    cmn     x0, #(MAX_ERRNO + 1)
-    cneg    x0, x0, hi
-    b.hi    __set_errno
-
-    ret
-END(ioprio_set)
diff --git a/libc/arch-arm64/syscalls/kill.S b/libc/arch-arm64/syscalls/kill.S
index 15c399b..7fc2c5a 100644
--- a/libc/arch-arm64/syscalls/kill.S
+++ b/libc/arch-arm64/syscalls/kill.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(kill)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_kill
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/klogctl.S b/libc/arch-arm64/syscalls/klogctl.S
index 1d161ec..abbee55 100644
--- a/libc/arch-arm64/syscalls/klogctl.S
+++ b/libc/arch-arm64/syscalls/klogctl.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(klogctl)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_syslog
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/lgetxattr.S b/libc/arch-arm64/syscalls/lgetxattr.S
index 2799285..e1a760c 100644
--- a/libc/arch-arm64/syscalls/lgetxattr.S
+++ b/libc/arch-arm64/syscalls/lgetxattr.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(lgetxattr)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_lgetxattr
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/linkat.S b/libc/arch-arm64/syscalls/linkat.S
index e65aa3f..c3e2cd8 100644
--- a/libc/arch-arm64/syscalls/linkat.S
+++ b/libc/arch-arm64/syscalls/linkat.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(linkat)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_linkat
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/listen.S b/libc/arch-arm64/syscalls/listen.S
index 44ae288..9b7be28 100644
--- a/libc/arch-arm64/syscalls/listen.S
+++ b/libc/arch-arm64/syscalls/listen.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(listen)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_listen
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/listxattr.S b/libc/arch-arm64/syscalls/listxattr.S
index b31d22c..a5e55c7 100644
--- a/libc/arch-arm64/syscalls/listxattr.S
+++ b/libc/arch-arm64/syscalls/listxattr.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(listxattr)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_listxattr
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/llistxattr.S b/libc/arch-arm64/syscalls/llistxattr.S
index fdcafde..447e208 100644
--- a/libc/arch-arm64/syscalls/llistxattr.S
+++ b/libc/arch-arm64/syscalls/llistxattr.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(llistxattr)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_llistxattr
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/lremovexattr.S b/libc/arch-arm64/syscalls/lremovexattr.S
index 741fa86..1f620db 100644
--- a/libc/arch-arm64/syscalls/lremovexattr.S
+++ b/libc/arch-arm64/syscalls/lremovexattr.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(lremovexattr)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_lremovexattr
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/lseek.S b/libc/arch-arm64/syscalls/lseek.S
index 3d16e75..1b858b2 100644
--- a/libc/arch-arm64/syscalls/lseek.S
+++ b/libc/arch-arm64/syscalls/lseek.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(lseek)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_lseek
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/lsetxattr.S b/libc/arch-arm64/syscalls/lsetxattr.S
index a7fe1df..8315bba 100644
--- a/libc/arch-arm64/syscalls/lsetxattr.S
+++ b/libc/arch-arm64/syscalls/lsetxattr.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(lsetxattr)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_lsetxattr
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/madvise.S b/libc/arch-arm64/syscalls/madvise.S
index 8eed274..17282c0 100644
--- a/libc/arch-arm64/syscalls/madvise.S
+++ b/libc/arch-arm64/syscalls/madvise.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(madvise)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_madvise
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/mincore.S b/libc/arch-arm64/syscalls/mincore.S
index 21dbe14..abdcf6c 100644
--- a/libc/arch-arm64/syscalls/mincore.S
+++ b/libc/arch-arm64/syscalls/mincore.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(mincore)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_mincore
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/mkdirat.S b/libc/arch-arm64/syscalls/mkdirat.S
index efd9786..d6bafca 100644
--- a/libc/arch-arm64/syscalls/mkdirat.S
+++ b/libc/arch-arm64/syscalls/mkdirat.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(mkdirat)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_mkdirat
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/mknodat.S b/libc/arch-arm64/syscalls/mknodat.S
index 1bf42d0..598e789 100644
--- a/libc/arch-arm64/syscalls/mknodat.S
+++ b/libc/arch-arm64/syscalls/mknodat.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(mknodat)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_mknodat
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/mlock.S b/libc/arch-arm64/syscalls/mlock.S
index e09e7fc..631ce02 100644
--- a/libc/arch-arm64/syscalls/mlock.S
+++ b/libc/arch-arm64/syscalls/mlock.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(mlock)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_mlock
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/mlockall.S b/libc/arch-arm64/syscalls/mlockall.S
index bfb2b60..42dac9e 100644
--- a/libc/arch-arm64/syscalls/mlockall.S
+++ b/libc/arch-arm64/syscalls/mlockall.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(mlockall)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_mlockall
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/mmap.S b/libc/arch-arm64/syscalls/mmap.S
index 437698a..da18e10 100644
--- a/libc/arch-arm64/syscalls/mmap.S
+++ b/libc/arch-arm64/syscalls/mmap.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(mmap)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_mmap
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/mount.S b/libc/arch-arm64/syscalls/mount.S
index 34170d8..c43a71f 100644
--- a/libc/arch-arm64/syscalls/mount.S
+++ b/libc/arch-arm64/syscalls/mount.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(mount)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_mount
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/mprotect.S b/libc/arch-arm64/syscalls/mprotect.S
index cdb4bc8..a7d26dd 100644
--- a/libc/arch-arm64/syscalls/mprotect.S
+++ b/libc/arch-arm64/syscalls/mprotect.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(mprotect)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_mprotect
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/mremap.S b/libc/arch-arm64/syscalls/mremap.S
index 605b39d..337bbae 100644
--- a/libc/arch-arm64/syscalls/mremap.S
+++ b/libc/arch-arm64/syscalls/mremap.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(mremap)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_mremap
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/msync.S b/libc/arch-arm64/syscalls/msync.S
index e511e86..c54797e 100644
--- a/libc/arch-arm64/syscalls/msync.S
+++ b/libc/arch-arm64/syscalls/msync.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(msync)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_msync
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/munlock.S b/libc/arch-arm64/syscalls/munlock.S
index f837c9c..b1ec016 100644
--- a/libc/arch-arm64/syscalls/munlock.S
+++ b/libc/arch-arm64/syscalls/munlock.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(munlock)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_munlock
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/munlockall.S b/libc/arch-arm64/syscalls/munlockall.S
index 93e9121..f9162a8 100644
--- a/libc/arch-arm64/syscalls/munlockall.S
+++ b/libc/arch-arm64/syscalls/munlockall.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(munlockall)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_munlockall
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/munmap.S b/libc/arch-arm64/syscalls/munmap.S
index f2b22bd..6bd5afe 100644
--- a/libc/arch-arm64/syscalls/munmap.S
+++ b/libc/arch-arm64/syscalls/munmap.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(munmap)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_munmap
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/nanosleep.S b/libc/arch-arm64/syscalls/nanosleep.S
index e33311a..c84accc 100644
--- a/libc/arch-arm64/syscalls/nanosleep.S
+++ b/libc/arch-arm64/syscalls/nanosleep.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(nanosleep)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_nanosleep
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/personality.S b/libc/arch-arm64/syscalls/personality.S
index c37cae2..02bcf9b 100644
--- a/libc/arch-arm64/syscalls/personality.S
+++ b/libc/arch-arm64/syscalls/personality.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(personality)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_personality
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/pipe2.S b/libc/arch-arm64/syscalls/pipe2.S
index ab2e259..f4da37d 100644
--- a/libc/arch-arm64/syscalls/pipe2.S
+++ b/libc/arch-arm64/syscalls/pipe2.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(pipe2)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_pipe2
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/prctl.S b/libc/arch-arm64/syscalls/prctl.S
index dd46fd4..2e6dca7 100644
--- a/libc/arch-arm64/syscalls/prctl.S
+++ b/libc/arch-arm64/syscalls/prctl.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(prctl)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_prctl
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/pread64.S b/libc/arch-arm64/syscalls/pread64.S
index ddc6c12..2aba596 100644
--- a/libc/arch-arm64/syscalls/pread64.S
+++ b/libc/arch-arm64/syscalls/pread64.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(pread64)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_pread64
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/prlimit64.S b/libc/arch-arm64/syscalls/prlimit64.S
index 39d31b0..a2173d9 100644
--- a/libc/arch-arm64/syscalls/prlimit64.S
+++ b/libc/arch-arm64/syscalls/prlimit64.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(prlimit64)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_prlimit64
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/pwrite64.S b/libc/arch-arm64/syscalls/pwrite64.S
index 81e2cf7..5674a7c 100644
--- a/libc/arch-arm64/syscalls/pwrite64.S
+++ b/libc/arch-arm64/syscalls/pwrite64.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(pwrite64)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_pwrite64
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/read.S b/libc/arch-arm64/syscalls/read.S
index c529576..906fb98 100644
--- a/libc/arch-arm64/syscalls/read.S
+++ b/libc/arch-arm64/syscalls/read.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(read)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_read
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/readahead.S b/libc/arch-arm64/syscalls/readahead.S
index e8394cc..2994b83 100644
--- a/libc/arch-arm64/syscalls/readahead.S
+++ b/libc/arch-arm64/syscalls/readahead.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(readahead)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_readahead
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/readlinkat.S b/libc/arch-arm64/syscalls/readlinkat.S
index d7cadcc..1782c94 100644
--- a/libc/arch-arm64/syscalls/readlinkat.S
+++ b/libc/arch-arm64/syscalls/readlinkat.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(readlinkat)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_readlinkat
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/readv.S b/libc/arch-arm64/syscalls/readv.S
index 98d0742..bc988d4 100644
--- a/libc/arch-arm64/syscalls/readv.S
+++ b/libc/arch-arm64/syscalls/readv.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(readv)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_readv
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/recvfrom.S b/libc/arch-arm64/syscalls/recvfrom.S
index 63181f1..16f97d5 100644
--- a/libc/arch-arm64/syscalls/recvfrom.S
+++ b/libc/arch-arm64/syscalls/recvfrom.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(recvfrom)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_recvfrom
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/recvmmsg.S b/libc/arch-arm64/syscalls/recvmmsg.S
index cb1fbfc..bd1495a 100644
--- a/libc/arch-arm64/syscalls/recvmmsg.S
+++ b/libc/arch-arm64/syscalls/recvmmsg.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(recvmmsg)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_recvmmsg
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/recvmsg.S b/libc/arch-arm64/syscalls/recvmsg.S
index 8a91a5f..c9b78c4 100644
--- a/libc/arch-arm64/syscalls/recvmsg.S
+++ b/libc/arch-arm64/syscalls/recvmsg.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(recvmsg)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_recvmsg
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/removexattr.S b/libc/arch-arm64/syscalls/removexattr.S
index 6fb557a..c12cc84 100644
--- a/libc/arch-arm64/syscalls/removexattr.S
+++ b/libc/arch-arm64/syscalls/removexattr.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(removexattr)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_removexattr
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/renameat.S b/libc/arch-arm64/syscalls/renameat.S
index e4efeb8..cf79472 100644
--- a/libc/arch-arm64/syscalls/renameat.S
+++ b/libc/arch-arm64/syscalls/renameat.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(renameat)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_renameat
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/sched_get_priority_max.S b/libc/arch-arm64/syscalls/sched_get_priority_max.S
index 74f919b..672d0ea 100644
--- a/libc/arch-arm64/syscalls/sched_get_priority_max.S
+++ b/libc/arch-arm64/syscalls/sched_get_priority_max.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(sched_get_priority_max)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_sched_get_priority_max
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/sched_get_priority_min.S b/libc/arch-arm64/syscalls/sched_get_priority_min.S
index d043b3b..f5cf1f3 100644
--- a/libc/arch-arm64/syscalls/sched_get_priority_min.S
+++ b/libc/arch-arm64/syscalls/sched_get_priority_min.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(sched_get_priority_min)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_sched_get_priority_min
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/sched_getparam.S b/libc/arch-arm64/syscalls/sched_getparam.S
index fedcec8..7ffe8fb 100644
--- a/libc/arch-arm64/syscalls/sched_getparam.S
+++ b/libc/arch-arm64/syscalls/sched_getparam.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(sched_getparam)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_sched_getparam
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/sched_getscheduler.S b/libc/arch-arm64/syscalls/sched_getscheduler.S
index 1225601..b69b8c0 100644
--- a/libc/arch-arm64/syscalls/sched_getscheduler.S
+++ b/libc/arch-arm64/syscalls/sched_getscheduler.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(sched_getscheduler)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_sched_getscheduler
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/sched_rr_get_interval.S b/libc/arch-arm64/syscalls/sched_rr_get_interval.S
index 796edda..0be14ba 100644
--- a/libc/arch-arm64/syscalls/sched_rr_get_interval.S
+++ b/libc/arch-arm64/syscalls/sched_rr_get_interval.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(sched_rr_get_interval)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_sched_rr_get_interval
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/sched_setaffinity.S b/libc/arch-arm64/syscalls/sched_setaffinity.S
index 2a7022d..f5cbc77 100644
--- a/libc/arch-arm64/syscalls/sched_setaffinity.S
+++ b/libc/arch-arm64/syscalls/sched_setaffinity.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(sched_setaffinity)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_sched_setaffinity
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/sched_setparam.S b/libc/arch-arm64/syscalls/sched_setparam.S
index dd82a10..cff64f5 100644
--- a/libc/arch-arm64/syscalls/sched_setparam.S
+++ b/libc/arch-arm64/syscalls/sched_setparam.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(sched_setparam)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_sched_setparam
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/sched_setscheduler.S b/libc/arch-arm64/syscalls/sched_setscheduler.S
index 25e1e36..31600a0 100644
--- a/libc/arch-arm64/syscalls/sched_setscheduler.S
+++ b/libc/arch-arm64/syscalls/sched_setscheduler.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(sched_setscheduler)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_sched_setscheduler
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/sched_yield.S b/libc/arch-arm64/syscalls/sched_yield.S
index cbee020..21ad601 100644
--- a/libc/arch-arm64/syscalls/sched_yield.S
+++ b/libc/arch-arm64/syscalls/sched_yield.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(sched_yield)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_sched_yield
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/sendfile.S b/libc/arch-arm64/syscalls/sendfile.S
index 1705d3c..db90caa 100644
--- a/libc/arch-arm64/syscalls/sendfile.S
+++ b/libc/arch-arm64/syscalls/sendfile.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(sendfile)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_sendfile
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/sendmmsg.S b/libc/arch-arm64/syscalls/sendmmsg.S
index 2277110..e85798a 100644
--- a/libc/arch-arm64/syscalls/sendmmsg.S
+++ b/libc/arch-arm64/syscalls/sendmmsg.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(sendmmsg)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_sendmmsg
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/sendmsg.S b/libc/arch-arm64/syscalls/sendmsg.S
index 96fcb9a..25eff84 100644
--- a/libc/arch-arm64/syscalls/sendmsg.S
+++ b/libc/arch-arm64/syscalls/sendmsg.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(sendmsg)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_sendmsg
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/sendto.S b/libc/arch-arm64/syscalls/sendto.S
index 67589ba..39e4e4e 100644
--- a/libc/arch-arm64/syscalls/sendto.S
+++ b/libc/arch-arm64/syscalls/sendto.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(sendto)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_sendto
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/setgid.S b/libc/arch-arm64/syscalls/setgid.S
index fbaa785..a9789f7 100644
--- a/libc/arch-arm64/syscalls/setgid.S
+++ b/libc/arch-arm64/syscalls/setgid.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(setgid)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_setgid
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/setgroups.S b/libc/arch-arm64/syscalls/setgroups.S
index 48035b6..ce9bf01 100644
--- a/libc/arch-arm64/syscalls/setgroups.S
+++ b/libc/arch-arm64/syscalls/setgroups.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(setgroups)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_setgroups
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/setitimer.S b/libc/arch-arm64/syscalls/setitimer.S
index 42af94b..d8e3d7e 100644
--- a/libc/arch-arm64/syscalls/setitimer.S
+++ b/libc/arch-arm64/syscalls/setitimer.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(setitimer)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_setitimer
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/setns.S b/libc/arch-arm64/syscalls/setns.S
index f695597..615f888 100644
--- a/libc/arch-arm64/syscalls/setns.S
+++ b/libc/arch-arm64/syscalls/setns.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(setns)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_setns
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/setpgid.S b/libc/arch-arm64/syscalls/setpgid.S
index 5653256..6015264 100644
--- a/libc/arch-arm64/syscalls/setpgid.S
+++ b/libc/arch-arm64/syscalls/setpgid.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(setpgid)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_setpgid
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/setpriority.S b/libc/arch-arm64/syscalls/setpriority.S
index 121bcaa..d2f517e 100644
--- a/libc/arch-arm64/syscalls/setpriority.S
+++ b/libc/arch-arm64/syscalls/setpriority.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(setpriority)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_setpriority
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/setregid.S b/libc/arch-arm64/syscalls/setregid.S
index 6389551..7b333bf 100644
--- a/libc/arch-arm64/syscalls/setregid.S
+++ b/libc/arch-arm64/syscalls/setregid.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(setregid)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_setregid
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/setresgid.S b/libc/arch-arm64/syscalls/setresgid.S
index bf78249..39504bd 100644
--- a/libc/arch-arm64/syscalls/setresgid.S
+++ b/libc/arch-arm64/syscalls/setresgid.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(setresgid)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_setresgid
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/setresuid.S b/libc/arch-arm64/syscalls/setresuid.S
index 83200da..5acbffd 100644
--- a/libc/arch-arm64/syscalls/setresuid.S
+++ b/libc/arch-arm64/syscalls/setresuid.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(setresuid)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_setresuid
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/setreuid.S b/libc/arch-arm64/syscalls/setreuid.S
index 2253eec..63630d6 100644
--- a/libc/arch-arm64/syscalls/setreuid.S
+++ b/libc/arch-arm64/syscalls/setreuid.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(setreuid)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_setreuid
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/setrlimit.S b/libc/arch-arm64/syscalls/setrlimit.S
index 034ae36..f9f56a6 100644
--- a/libc/arch-arm64/syscalls/setrlimit.S
+++ b/libc/arch-arm64/syscalls/setrlimit.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(setrlimit)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_setrlimit
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/setsid.S b/libc/arch-arm64/syscalls/setsid.S
index 64123df..04c28e3 100644
--- a/libc/arch-arm64/syscalls/setsid.S
+++ b/libc/arch-arm64/syscalls/setsid.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(setsid)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_setsid
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/setsockopt.S b/libc/arch-arm64/syscalls/setsockopt.S
index fe8da22..0ebc6d0 100644
--- a/libc/arch-arm64/syscalls/setsockopt.S
+++ b/libc/arch-arm64/syscalls/setsockopt.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(setsockopt)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_setsockopt
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/settimeofday.S b/libc/arch-arm64/syscalls/settimeofday.S
index 50debf9..474e40d 100644
--- a/libc/arch-arm64/syscalls/settimeofday.S
+++ b/libc/arch-arm64/syscalls/settimeofday.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(settimeofday)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_settimeofday
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/setuid.S b/libc/arch-arm64/syscalls/setuid.S
index 0a9adbe..fe52921 100644
--- a/libc/arch-arm64/syscalls/setuid.S
+++ b/libc/arch-arm64/syscalls/setuid.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(setuid)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_setuid
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/setxattr.S b/libc/arch-arm64/syscalls/setxattr.S
index ebfd607..8d0b415 100644
--- a/libc/arch-arm64/syscalls/setxattr.S
+++ b/libc/arch-arm64/syscalls/setxattr.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(setxattr)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_setxattr
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/shutdown.S b/libc/arch-arm64/syscalls/shutdown.S
index 6e878d6..e35cdea 100644
--- a/libc/arch-arm64/syscalls/shutdown.S
+++ b/libc/arch-arm64/syscalls/shutdown.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(shutdown)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_shutdown
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/sigaltstack.S b/libc/arch-arm64/syscalls/sigaltstack.S
index 46794d4..6a38203 100644
--- a/libc/arch-arm64/syscalls/sigaltstack.S
+++ b/libc/arch-arm64/syscalls/sigaltstack.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(sigaltstack)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_sigaltstack
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/socketpair.S b/libc/arch-arm64/syscalls/socketpair.S
index c42ff24..dcd7223 100644
--- a/libc/arch-arm64/syscalls/socketpair.S
+++ b/libc/arch-arm64/syscalls/socketpair.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(socketpair)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_socketpair
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/splice.S b/libc/arch-arm64/syscalls/splice.S
new file mode 100644
index 0000000..103805a
--- /dev/null
+++ b/libc/arch-arm64/syscalls/splice.S
@@ -0,0 +1,14 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(splice)
+    mov     x8, __NR_splice
+    svc     #0
+
+    cmn     x0, #(MAX_ERRNO + 1)
+    cneg    x0, x0, hi
+    b.hi    __set_errno
+
+    ret
+END(splice)
diff --git a/libc/arch-arm64/syscalls/statfs64.S b/libc/arch-arm64/syscalls/statfs64.S
index 66662ee..55633c1 100644
--- a/libc/arch-arm64/syscalls/statfs64.S
+++ b/libc/arch-arm64/syscalls/statfs64.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(statfs64)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_statfs
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/swapoff.S b/libc/arch-arm64/syscalls/swapoff.S
index 1d465b0..dcef4af 100644
--- a/libc/arch-arm64/syscalls/swapoff.S
+++ b/libc/arch-arm64/syscalls/swapoff.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(swapoff)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_swapoff
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/swapon.S b/libc/arch-arm64/syscalls/swapon.S
index 7e5f850..aef7627 100644
--- a/libc/arch-arm64/syscalls/swapon.S
+++ b/libc/arch-arm64/syscalls/swapon.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(swapon)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_swapon
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/symlinkat.S b/libc/arch-arm64/syscalls/symlinkat.S
index 0081cf2..9830865 100644
--- a/libc/arch-arm64/syscalls/symlinkat.S
+++ b/libc/arch-arm64/syscalls/symlinkat.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(symlinkat)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_symlinkat
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/sync.S b/libc/arch-arm64/syscalls/sync.S
index 67bc554..3ef0460 100644
--- a/libc/arch-arm64/syscalls/sync.S
+++ b/libc/arch-arm64/syscalls/sync.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(sync)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_sync
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/sysinfo.S b/libc/arch-arm64/syscalls/sysinfo.S
index 0797a39..7dbe152 100644
--- a/libc/arch-arm64/syscalls/sysinfo.S
+++ b/libc/arch-arm64/syscalls/sysinfo.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(sysinfo)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_sysinfo
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/tee.S b/libc/arch-arm64/syscalls/tee.S
new file mode 100644
index 0000000..d730076
--- /dev/null
+++ b/libc/arch-arm64/syscalls/tee.S
@@ -0,0 +1,14 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(tee)
+    mov     x8, __NR_tee
+    svc     #0
+
+    cmn     x0, #(MAX_ERRNO + 1)
+    cneg    x0, x0, hi
+    b.hi    __set_errno
+
+    ret
+END(tee)
diff --git a/libc/arch-arm64/syscalls/tgkill.S b/libc/arch-arm64/syscalls/tgkill.S
index 9366c70..477c477 100644
--- a/libc/arch-arm64/syscalls/tgkill.S
+++ b/libc/arch-arm64/syscalls/tgkill.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(tgkill)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_tgkill
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/timerfd_create.S b/libc/arch-arm64/syscalls/timerfd_create.S
index 1e9d2e3..83b5910 100644
--- a/libc/arch-arm64/syscalls/timerfd_create.S
+++ b/libc/arch-arm64/syscalls/timerfd_create.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(timerfd_create)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_timerfd_create
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/timerfd_gettime.S b/libc/arch-arm64/syscalls/timerfd_gettime.S
index 56d7f96..253cb79 100644
--- a/libc/arch-arm64/syscalls/timerfd_gettime.S
+++ b/libc/arch-arm64/syscalls/timerfd_gettime.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(timerfd_gettime)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_timerfd_gettime
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/timerfd_settime.S b/libc/arch-arm64/syscalls/timerfd_settime.S
index 29af0f1..8872481 100644
--- a/libc/arch-arm64/syscalls/timerfd_settime.S
+++ b/libc/arch-arm64/syscalls/timerfd_settime.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(timerfd_settime)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_timerfd_settime
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/times.S b/libc/arch-arm64/syscalls/times.S
index 9487186..33c7d55 100644
--- a/libc/arch-arm64/syscalls/times.S
+++ b/libc/arch-arm64/syscalls/times.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(times)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_times
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/truncate.S b/libc/arch-arm64/syscalls/truncate.S
index 3bbe356..f15253b 100644
--- a/libc/arch-arm64/syscalls/truncate.S
+++ b/libc/arch-arm64/syscalls/truncate.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(truncate)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_truncate
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/umask.S b/libc/arch-arm64/syscalls/umask.S
index ca72092..8b907b4 100644
--- a/libc/arch-arm64/syscalls/umask.S
+++ b/libc/arch-arm64/syscalls/umask.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(umask)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_umask
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/umount2.S b/libc/arch-arm64/syscalls/umount2.S
index a959625..5646dba 100644
--- a/libc/arch-arm64/syscalls/umount2.S
+++ b/libc/arch-arm64/syscalls/umount2.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(umount2)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_umount2
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/uname.S b/libc/arch-arm64/syscalls/uname.S
index 2f87563..09ec096 100644
--- a/libc/arch-arm64/syscalls/uname.S
+++ b/libc/arch-arm64/syscalls/uname.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(uname)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_uname
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/unlinkat.S b/libc/arch-arm64/syscalls/unlinkat.S
index 0025726..992f675 100644
--- a/libc/arch-arm64/syscalls/unlinkat.S
+++ b/libc/arch-arm64/syscalls/unlinkat.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(unlinkat)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_unlinkat
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/unshare.S b/libc/arch-arm64/syscalls/unshare.S
index 55462b4..1062dcd 100644
--- a/libc/arch-arm64/syscalls/unshare.S
+++ b/libc/arch-arm64/syscalls/unshare.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(unshare)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_unshare
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/utimensat.S b/libc/arch-arm64/syscalls/utimensat.S
index aa5cfbf..8a25ed6 100644
--- a/libc/arch-arm64/syscalls/utimensat.S
+++ b/libc/arch-arm64/syscalls/utimensat.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(utimensat)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_utimensat
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/vmsplice.S b/libc/arch-arm64/syscalls/vmsplice.S
new file mode 100644
index 0000000..b4bec3f
--- /dev/null
+++ b/libc/arch-arm64/syscalls/vmsplice.S
@@ -0,0 +1,14 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(vmsplice)
+    mov     x8, __NR_vmsplice
+    svc     #0
+
+    cmn     x0, #(MAX_ERRNO + 1)
+    cneg    x0, x0, hi
+    b.hi    __set_errno
+
+    ret
+END(vmsplice)
diff --git a/libc/arch-arm64/syscalls/wait4.S b/libc/arch-arm64/syscalls/wait4.S
index 93183e5..a0d5d62 100644
--- a/libc/arch-arm64/syscalls/wait4.S
+++ b/libc/arch-arm64/syscalls/wait4.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(wait4)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_wait4
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/write.S b/libc/arch-arm64/syscalls/write.S
index b7288d1..d64552e 100644
--- a/libc/arch-arm64/syscalls/write.S
+++ b/libc/arch-arm64/syscalls/write.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(write)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_write
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-arm64/syscalls/writev.S b/libc/arch-arm64/syscalls/writev.S
index 13af454..45d5c8d 100644
--- a/libc/arch-arm64/syscalls/writev.S
+++ b/libc/arch-arm64/syscalls/writev.S
@@ -3,20 +3,9 @@
 #include <private/bionic_asm.h>
 
 ENTRY(writev)
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, __NR_writev
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
diff --git a/libc/arch-mips/bionic/__bionic_clone.S b/libc/arch-mips/bionic/__bionic_clone.S
index 7b138ae..4b4498d 100644
--- a/libc/arch-mips/bionic/__bionic_clone.S
+++ b/libc/arch-mips/bionic/__bionic_clone.S
@@ -60,8 +60,8 @@
         lw	a0,0(sp)	#  fn
         lw	a1,4(sp)	#  arg
 
-	# void __bionic_clone_entry(int (*func)(void*), void *arg)
-        la	t9,__bionic_clone_entry
+	# void __start_thread(int (*func)(void*), void *arg)
+        la	t9,__start_thread
         j	t9
 
 .L__error_bc:
diff --git a/libc/arch-mips/bionic/memcmp16.S b/libc/arch-mips/bionic/memcmp16.S
deleted file mode 100644
index f9d14a9..0000000
--- a/libc/arch-mips/bionic/memcmp16.S
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (C) 2008 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_asm.h>
-
-// u4 __memcmp16(const u2*, const u2*, size_t);
-ENTRY(__memcmp16)
-	li	t0,0
-	li	t1,0
-	beqz	a2,done		/* 0 length string */ 
-	beq	a0,a1,done		/* strings are identical */
-
-	/* Unoptimised... */
-1:	lhu	t0,0(a0)
-	lhu	t1,0(a1)
-	addu	a1,2
-	bne	t0,t1,done
-	addu	a0,2
-	subu	a2,1
-	bnez	a2,1b
-
-done:
-	subu	v0,t0,t1
-	j	ra
-END(__memcmp16)
diff --git a/libc/arch-mips/bionic/vfork.S b/libc/arch-mips/bionic/vfork.S
deleted file mode 100644
index 96de69e..0000000
--- a/libc/arch-mips/bionic/vfork.S
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (C) 2008 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_asm.h>
-#include <linux/sched.h>
-
-// TODO: mips' uapi signal.h is missing #ifndef __ASSEMBLY__.
-// #include <asm/signal.h>
-#define SIGCHLD 18
-
-ENTRY(vfork)
-	.set	noreorder
-	.cpload	t9
-
-	li	a0, (CLONE_VM | CLONE_VFORK | SIGCHLD)
-	li	a1, 0
-	li	a2, 0
-	li	a3, 0
-	subu	sp, 8
-	sw	$0, 16(sp)
-	li	v0, __NR_clone
-	syscall
-	addu	sp, 8
-	bnez	a3, 1f
-	 move	a0, v0
-
-	j	ra
-	 nop
-1:
-	la	t9, __set_errno
-	j	t9
-	 nop
-END(vfork)
diff --git a/libc/arch-mips/mips.mk b/libc/arch-mips/mips.mk
index 0244712..0a3718b 100644
--- a/libc/arch-mips/mips.mk
+++ b/libc/arch-mips/mips.mk
@@ -5,13 +5,13 @@
     bionic/legacy_32_bit_support.cpp \
     bionic/ndk_cruft.cpp \
     bionic/time64.c \
+    upstream-openbsd/lib/libc/stdio/putw.c \
 
 # These are shared by all the 32-bit targets, but not the 64-bit ones.
 libc_bionic_src_files_mips += \
      bionic/mmap.cpp
 
 libc_common_src_files_mips += \
-    bionic/index.cpp \
     bionic/memchr.c \
     bionic/memcmp.c \
     bionic/memmove.c \
@@ -60,16 +60,16 @@
     arch-mips/bionic/cacheflush.cpp \
     arch-mips/bionic/_exit_with_stack_teardown.S \
     arch-mips/bionic/__get_sp.S \
-    arch-mips/bionic/memcmp16.S \
     arch-mips/bionic/_setjmp.S \
     arch-mips/bionic/setjmp.S \
     arch-mips/bionic/sigsetjmp.S \
     arch-mips/bionic/syscall.S \
-    arch-mips/bionic/vfork.S \
     arch-mips/string/memcpy.S \
     arch-mips/string/memset.S \
     arch-mips/string/mips_strlen.c \
 
+libc_netbsd_src_files_mips := \
+    upstream-netbsd/common/lib/libc/hash/sha1/sha1.c \
 
 libc_crt_target_cflags_mips := \
     $($(my_2nd_arch_prefix)TARGET_GLOBAL_CFLAGS) \
diff --git a/libc/arch-mips/syscalls/getdents.S b/libc/arch-mips/syscalls/__getdents64.S
similarity index 87%
rename from libc/arch-mips/syscalls/getdents.S
rename to libc/arch-mips/syscalls/__getdents64.S
index ce92886..136b408 100644
--- a/libc/arch-mips/syscalls/getdents.S
+++ b/libc/arch-mips/syscalls/__getdents64.S
@@ -2,7 +2,7 @@
 
 #include <private/bionic_asm.h>
 
-ENTRY(getdents)
+ENTRY(__getdents64)
     .set noreorder
     .cpload t9
     li v0, __NR_getdents64
@@ -16,4 +16,4 @@
     j t9
     nop
     .set reorder
-END(getdents)
+END(__getdents64)
diff --git a/libc/arch-mips/syscalls/getpid.S b/libc/arch-mips/syscalls/__getpid.S
similarity index 89%
rename from libc/arch-mips/syscalls/getpid.S
rename to libc/arch-mips/syscalls/__getpid.S
index a053f5b..52cf6f4 100644
--- a/libc/arch-mips/syscalls/getpid.S
+++ b/libc/arch-mips/syscalls/__getpid.S
@@ -2,7 +2,7 @@
 
 #include <private/bionic_asm.h>
 
-ENTRY(getpid)
+ENTRY(__getpid)
     .set noreorder
     .cpload t9
     li v0, __NR_getpid
@@ -16,4 +16,4 @@
     j t9
     nop
     .set reorder
-END(getpid)
+END(__getpid)
diff --git a/libc/arch-mips/syscalls/ioprio_get.S b/libc/arch-mips/syscalls/ioprio_get.S
deleted file mode 100644
index fbc8b17..0000000
--- a/libc/arch-mips/syscalls/ioprio_get.S
+++ /dev/null
@@ -1,19 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(ioprio_get)
-    .set noreorder
-    .cpload t9
-    li v0, __NR_ioprio_get
-    syscall
-    bnez a3, 1f
-    move a0, v0
-    j ra
-    nop
-1:
-    la t9,__set_errno
-    j t9
-    nop
-    .set reorder
-END(ioprio_get)
diff --git a/libc/arch-mips/syscalls/ioprio_set.S b/libc/arch-mips/syscalls/ioprio_set.S
deleted file mode 100644
index d0320ed..0000000
--- a/libc/arch-mips/syscalls/ioprio_set.S
+++ /dev/null
@@ -1,19 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(ioprio_set)
-    .set noreorder
-    .cpload t9
-    li v0, __NR_ioprio_set
-    syscall
-    bnez a3, 1f
-    move a0, v0
-    j ra
-    nop
-1:
-    la t9,__set_errno
-    j t9
-    nop
-    .set reorder
-END(ioprio_set)
diff --git a/libc/arch-mips/syscalls/getpid.S b/libc/arch-mips/syscalls/splice.S
similarity index 82%
copy from libc/arch-mips/syscalls/getpid.S
copy to libc/arch-mips/syscalls/splice.S
index a053f5b..d344a6c 100644
--- a/libc/arch-mips/syscalls/getpid.S
+++ b/libc/arch-mips/syscalls/splice.S
@@ -2,10 +2,10 @@
 
 #include <private/bionic_asm.h>
 
-ENTRY(getpid)
+ENTRY(splice)
     .set noreorder
     .cpload t9
-    li v0, __NR_getpid
+    li v0, __NR_splice
     syscall
     bnez a3, 1f
     move a0, v0
@@ -16,4 +16,4 @@
     j t9
     nop
     .set reorder
-END(getpid)
+END(splice)
diff --git a/libc/arch-mips/syscalls/getpid.S b/libc/arch-mips/syscalls/tee.S
similarity index 82%
copy from libc/arch-mips/syscalls/getpid.S
copy to libc/arch-mips/syscalls/tee.S
index a053f5b..e51732d 100644
--- a/libc/arch-mips/syscalls/getpid.S
+++ b/libc/arch-mips/syscalls/tee.S
@@ -2,10 +2,10 @@
 
 #include <private/bionic_asm.h>
 
-ENTRY(getpid)
+ENTRY(tee)
     .set noreorder
     .cpload t9
-    li v0, __NR_getpid
+    li v0, __NR_tee
     syscall
     bnez a3, 1f
     move a0, v0
@@ -16,4 +16,4 @@
     j t9
     nop
     .set reorder
-END(getpid)
+END(tee)
diff --git a/libc/arch-mips/syscalls/getpid.S b/libc/arch-mips/syscalls/vmsplice.S
similarity index 80%
copy from libc/arch-mips/syscalls/getpid.S
copy to libc/arch-mips/syscalls/vmsplice.S
index a053f5b..24da515 100644
--- a/libc/arch-mips/syscalls/getpid.S
+++ b/libc/arch-mips/syscalls/vmsplice.S
@@ -2,10 +2,10 @@
 
 #include <private/bionic_asm.h>
 
-ENTRY(getpid)
+ENTRY(vmsplice)
     .set noreorder
     .cpload t9
-    li v0, __NR_getpid
+    li v0, __NR_vmsplice
     syscall
     bnez a3, 1f
     move a0, v0
@@ -16,4 +16,4 @@
     j t9
     nop
     .set reorder
-END(getpid)
+END(vmsplice)
diff --git a/libc/arch-mips64/bionic/__bionic_clone.S b/libc/arch-mips64/bionic/__bionic_clone.S
index 8687906..4f053f9 100644
--- a/libc/arch-mips64/bionic/__bionic_clone.S
+++ b/libc/arch-mips64/bionic/__bionic_clone.S
@@ -78,10 +78,10 @@
 	# Clear return address in child so we don't unwind further.
 	li	ra,0
 
-	# void __bionic_clone_entry(int (*func)(void*), void *arg)
+	# void __start_thread(int (*func)(void*), void *arg)
 	PTR_L	a0,FRAME_FN(sp)		#  fn
 	PTR_L	a1,FRAME_ARG(sp)	#  arg
-	LA	t9,__bionic_clone_entry
+	LA	t9,__start_thread
 	RESTORE_GP64
 	/*
 	 * For O32 etc the child stack must have space for a0..a3 to be stored
diff --git a/libc/arch-mips64/bionic/getdents.cpp b/libc/arch-mips64/bionic/getdents.cpp
deleted file mode 100644
index 66a61ec..0000000
--- a/libc/arch-mips64/bionic/getdents.cpp
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Copyright (C) 2014 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.
- */
-
-/*
- * The MIPS64 getdents64() system call is only present in 3.10+ kernels.
- * If the getdents64() system call is not available fall back to using
- * getdents() and modify the result to be compatible with getdents64().
- */
-
-#include <dirent.h>
-
-#include <errno.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-
-/* The mips_getdents type is 64bit clean */
-struct mips_dirent {
-        uint64_t d_ino;     /* Inode number */
-        uint64_t d_off;     /* Offset to next mips_dirent */
-        uint16_t d_reclen;  /* Length of this mips_dirent */
-        char     d_name[];  /* Filename (null-terminated) */
-                            /* length is actually (d_reclen - 2 -
-                               offsetof(struct mips_dirent, d_name) */
-        // char  pad;       /* Zero padding byte */
-        // char  d_type;    /* File type (only since Linux 2.6.4; offset is (d_reclen - 1)) */
-};
-
-extern "C" int __getdents64(unsigned int fd, struct dirent *dirp, unsigned int count);
-extern "C" int __getdents(unsigned int fd, struct mips_dirent *dirp, unsigned int count);
-int getdents(unsigned int fd, struct dirent *dirp, unsigned int count)
-{
-        int r;
-        int oerrno = errno;
-
-        /* Use getdents64() if it is available */
-        r = __getdents64(fd, dirp, count);
-        if (r >= 0 || errno != ENOSYS)
-                return r;
-
-        /* Fallback to getdents() */
-        errno = oerrno;
-        r = __getdents(fd, (struct mips_dirent *)dirp, count);
-        if (r > 0) {
-                char *p;
-                char type;
-                union dirents {
-                        struct mips_dirent m;
-                        struct dirent d;
-                } *u;
-
-                p = (char *)dirp;
-                do {
-                        u = (union dirents *)p;
-
-                        /* This should not happen, but just in case... */
-                        if (p + u->m.d_reclen > (char *)dirp + r)
-                                break;
-
-                        /* shuffle the dirent */
-                        type = *(p + u->m.d_reclen - 1);
-                        memmove(u->d.d_name, u->m.d_name,
-                                u->m.d_reclen - 2 - offsetof(struct mips_dirent, d_name) + 1);
-                        u->d.d_type = type;
-
-                        p += u->m.d_reclen;
-                } while (p < (char *)dirp + r);
-        }
-        return r;
-}
diff --git a/libc/arch-mips64/bionic/memcmp16.S b/libc/arch-mips64/bionic/memcmp16.S
deleted file mode 100644
index 1c58c1b..0000000
--- a/libc/arch-mips64/bionic/memcmp16.S
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (C) 2008 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.
- */
-	.text
-
-#include <private/bionic_asm.h>
-
-/*
- * u4 __memcmp16(const u2* s0, const u2* s1, size_t count);
- */
-LEAF(__memcmp16,0)
-	move	t0,$0
-	move	t1,$0
-	beqz	a2,.L_done		/* 0 length string */
-	beq	a0,a1,.L_done		/* strings are identical */
-
-	/* Unoptimised... */
-1:	lhu	t0,0(a0)
-	lhu	t1,0(a1)
-	PTR_ADDU a1,2
-	bne	t0,t1,.L_done
-	PTR_ADDU a0,2
-	SUBU	a2,1
-	bnez	a2,1b
-
-.L_done:
-	SUBU	v0,t0,t1
-	j	ra
-	END(__memcmp16)
diff --git a/libc/arch-mips64/bionic/vfork.S b/libc/arch-mips64/bionic/vfork.S
deleted file mode 100644
index 911a264..0000000
--- a/libc/arch-mips64/bionic/vfork.S
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright (C) 2008 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_asm.h>
-#include <linux/sched.h>
-
-// TODO: mips' uapi signal.h is missing #ifndef __ASSEMBLY__.
-// #include <asm/signal.h>
-#define SIGCHLD 18
-
-	.text
-
-#if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32)
-FRAMESZ		=	MKFSIZ(5,0)
-#else
-FRAMESZ		=	MKFSIZ(0,0)
-#endif
-
-LEAF(vfork,FRAMESZ)
-#if FRAMESZ!=0
-	PTR_SUBU sp, FRAMESZ
-#endif
-	SETUP_GP64(a5, vfork)
-	LI	a0, (CLONE_VM | CLONE_VFORK | SIGCHLD)
-	move	a1, $0
-	move	a2, $0
-	move	a3, $0
-#if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32)
-	REG_S	$0, 4*REGSZ(sp)
-#else
-	move	a4, $0
-#endif
-	LI	v0, __NR_clone
-	syscall
-#if FRAMESZ!=0
-	PTR_ADDU sp,FRAMESZ
-#endif
-	move	a0, v0
-	bnez	a3, 1f
-	RESTORE_GP64
-	j	ra
-1:
-	LA	t9,__set_errno
-	RESTORE_GP64
-	j	t9
-	END(vfork)
diff --git a/libc/arch-mips64/mips64.mk b/libc/arch-mips64/mips64.mk
index 9a24c61..6f7a928 100644
--- a/libc/arch-mips64/mips64.mk
+++ b/libc/arch-mips64/mips64.mk
@@ -1,7 +1,6 @@
 # mips64 specific configs
 
 libc_common_src_files_mips64 := \
-    bionic/index.cpp \
     bionic/memchr.c \
     bionic/memcmp.c \
     bionic/memmove.c \
@@ -43,13 +42,10 @@
     arch-mips64/bionic/__bionic_clone.S \
     arch-mips64/bionic/_exit_with_stack_teardown.S \
     arch-mips64/bionic/__get_sp.S \
-    arch-mips64/bionic/getdents.cpp \
-    arch-mips64/bionic/memcmp16.S \
     arch-mips64/bionic/_setjmp.S \
     arch-mips64/bionic/setjmp.S \
     arch-mips64/bionic/sigsetjmp.S \
     arch-mips64/bionic/syscall.S \
-    arch-mips64/bionic/vfork.S \
 
 # FIXME TODO
 ## libc_bionic_src_files_mips64 += arch-mips64/string/memcpy.S
diff --git a/libc/arch-mips64/syscalls/__getdents.S b/libc/arch-mips64/syscalls/__getdents.S
deleted file mode 100644
index 0a70a72..0000000
--- a/libc/arch-mips64/syscalls/__getdents.S
+++ /dev/null
@@ -1,26 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(__getdents)
-    .set push
-    .set noreorder
-    li v0, __NR_getdents
-    syscall
-    bnez a3, 1f
-    move a0, v0
-    j ra
-    nop
-1:
-    move t0, ra
-    bal     2f
-    nop
-2:
-    .cpsetup ra, t1, 2b
-    LA t9,__set_errno
-    .cpreturn
-    j t9
-    move ra, t0
-    .set pop
-END(__getdents)
-.hidden __getdents
diff --git a/libc/arch-mips64/syscalls/getpid.S b/libc/arch-mips64/syscalls/__getpid.S
similarity index 87%
rename from libc/arch-mips64/syscalls/getpid.S
rename to libc/arch-mips64/syscalls/__getpid.S
index 3b457b5..0977ff0 100644
--- a/libc/arch-mips64/syscalls/getpid.S
+++ b/libc/arch-mips64/syscalls/__getpid.S
@@ -2,7 +2,7 @@
 
 #include <private/bionic_asm.h>
 
-ENTRY(getpid)
+ENTRY(__getpid)
     .set push
     .set noreorder
     li v0, __NR_getpid
@@ -22,4 +22,5 @@
     j t9
     move ra, t0
     .set pop
-END(getpid)
+END(__getpid)
+.hidden __getpid
diff --git a/libc/arch-mips64/syscalls/ioprio_get.S b/libc/arch-mips64/syscalls/ioprio_get.S
deleted file mode 100644
index 711890c..0000000
--- a/libc/arch-mips64/syscalls/ioprio_get.S
+++ /dev/null
@@ -1,25 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(ioprio_get)
-    .set push
-    .set noreorder
-    li v0, __NR_ioprio_get
-    syscall
-    bnez a3, 1f
-    move a0, v0
-    j ra
-    nop
-1:
-    move t0, ra
-    bal     2f
-    nop
-2:
-    .cpsetup ra, t1, 2b
-    LA t9,__set_errno
-    .cpreturn
-    j t9
-    move ra, t0
-    .set pop
-END(ioprio_get)
diff --git a/libc/arch-mips64/syscalls/ioprio_set.S b/libc/arch-mips64/syscalls/ioprio_set.S
deleted file mode 100644
index 738403a..0000000
--- a/libc/arch-mips64/syscalls/ioprio_set.S
+++ /dev/null
@@ -1,25 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(ioprio_set)
-    .set push
-    .set noreorder
-    li v0, __NR_ioprio_set
-    syscall
-    bnez a3, 1f
-    move a0, v0
-    j ra
-    nop
-1:
-    move t0, ra
-    bal     2f
-    nop
-2:
-    .cpsetup ra, t1, 2b
-    LA t9,__set_errno
-    .cpreturn
-    j t9
-    move ra, t0
-    .set pop
-END(ioprio_set)
diff --git a/libc/arch-mips64/syscalls/getpid.S b/libc/arch-mips64/syscalls/splice.S
similarity index 86%
copy from libc/arch-mips64/syscalls/getpid.S
copy to libc/arch-mips64/syscalls/splice.S
index 3b457b5..d626904 100644
--- a/libc/arch-mips64/syscalls/getpid.S
+++ b/libc/arch-mips64/syscalls/splice.S
@@ -2,10 +2,10 @@
 
 #include <private/bionic_asm.h>
 
-ENTRY(getpid)
+ENTRY(splice)
     .set push
     .set noreorder
-    li v0, __NR_getpid
+    li v0, __NR_splice
     syscall
     bnez a3, 1f
     move a0, v0
@@ -22,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-END(getpid)
+END(splice)
diff --git a/libc/arch-mips64/syscalls/getpid.S b/libc/arch-mips64/syscalls/tee.S
similarity index 86%
copy from libc/arch-mips64/syscalls/getpid.S
copy to libc/arch-mips64/syscalls/tee.S
index 3b457b5..429700c 100644
--- a/libc/arch-mips64/syscalls/getpid.S
+++ b/libc/arch-mips64/syscalls/tee.S
@@ -2,10 +2,10 @@
 
 #include <private/bionic_asm.h>
 
-ENTRY(getpid)
+ENTRY(tee)
     .set push
     .set noreorder
-    li v0, __NR_getpid
+    li v0, __NR_tee
     syscall
     bnez a3, 1f
     move a0, v0
@@ -22,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-END(getpid)
+END(tee)
diff --git a/libc/arch-mips64/syscalls/getpid.S b/libc/arch-mips64/syscalls/vmsplice.S
similarity index 85%
copy from libc/arch-mips64/syscalls/getpid.S
copy to libc/arch-mips64/syscalls/vmsplice.S
index 3b457b5..aa03585 100644
--- a/libc/arch-mips64/syscalls/getpid.S
+++ b/libc/arch-mips64/syscalls/vmsplice.S
@@ -2,10 +2,10 @@
 
 #include <private/bionic_asm.h>
 
-ENTRY(getpid)
+ENTRY(vmsplice)
     .set push
     .set noreorder
-    li v0, __NR_getpid
+    li v0, __NR_vmsplice
     syscall
     bnez a3, 1f
     move a0, v0
@@ -22,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-END(getpid)
+END(vmsplice)
diff --git a/libc/arch-x86/atom/atom.mk b/libc/arch-x86/atom/atom.mk
index bf408b4..3f28fb2 100644
--- a/libc/arch-x86/atom/atom.mk
+++ b/libc/arch-x86/atom/atom.mk
@@ -1,6 +1,5 @@
 libc_bionic_src_files_x86 += \
     arch-x86/atom/string/sse2-bzero-atom.S \
-    arch-x86/atom/string/sse2-index-atom.S \
     arch-x86/atom/string/sse2-memchr-atom.S \
     arch-x86/atom/string/sse2-memrchr-atom.S \
     arch-x86/atom/string/sse2-memset-atom.S \
@@ -14,7 +13,6 @@
     arch-x86/atom/string/sse2-wcscmp-atom.S \
     arch-x86/atom/string/ssse3-bcopy-atom.S \
     arch-x86/atom/string/ssse3-memcmp-atom.S \
-    arch-x86/atom/string/ssse3-memcmp16-atom.S \
     arch-x86/atom/string/ssse3-memcpy-atom.S \
     arch-x86/atom/string/ssse3-memmove-atom.S \
     arch-x86/atom/string/ssse3-strcat-atom.S \
diff --git a/libc/arch-x86/atom/string/sse2-index-atom.S b/libc/arch-x86/atom/string/sse2-index-atom.S
deleted file mode 100644
index d51e1d4..0000000
--- a/libc/arch-x86/atom/string/sse2-index-atom.S
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
-Copyright (c) 2011, Intel Corporation
-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.
-
-    * Neither the name of Intel Corporation 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 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.
-*/
-
-#define strchr  index
-#include "sse2-strchr-atom.S"
diff --git a/libc/arch-x86/atom/string/ssse3-memcmp16-atom.S b/libc/arch-x86/atom/string/ssse3-memcmp16-atom.S
deleted file mode 100644
index 1be8f3d..0000000
--- a/libc/arch-x86/atom/string/ssse3-memcmp16-atom.S
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
-Copyright (c) 2013, Intel Corporation
-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.
-
-    * Neither the name of Intel Corporation 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 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.
-*/
-
-#define MEMCMP  __memcmp16
-
-/* int __memcmp16(const unsigned short *ptr1, const unsigned short *ptr2, size_t n); */
-
-#define USE_UTF16
-#define USE_AS_MEMCMP16 1
-#include "ssse3-memcmp-atom.S"
diff --git a/libc/arch-x86/bionic/__bionic_clone.S b/libc/arch-x86/bionic/__bionic_clone.S
index 7c972de..917dc68 100644
--- a/libc/arch-x86/bionic/__bionic_clone.S
+++ b/libc/arch-x86/bionic/__bionic_clone.S
@@ -25,8 +25,8 @@
         int     $0x80
 
         # Check result.
-        cmpl    $0, %eax
-        je      .L_bc_child
+        testl    %eax, %eax
+        jz      .L_bc_child
         jg      .L_bc_parent
 
         # An error occurred, so set errno and return -1.
@@ -34,17 +34,16 @@
         pushl   %eax
         call    __set_errno
         addl    $4, %esp
-        orl     $-1, %eax
         jmp     .L_bc_return
 
 .L_bc_child:
         # We don't want anyone to unwind past this point.
         .cfi_undefined %eip
-        call    __bionic_clone_entry
+        call    __start_thread
         hlt
 
 .L_bc_parent:
-        # we're the parent; nothing to do.
+        # We're the parent; nothing to do.
 .L_bc_return:
         popl    %edi
         popl    %esi
diff --git a/libc/arch-x86/bionic/syscall.S b/libc/arch-x86/bionic/syscall.S
index 0178f41..8e76c4e 100644
--- a/libc/arch-x86/bionic/syscall.S
+++ b/libc/arch-x86/bionic/syscall.S
@@ -40,7 +40,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     # Restore the callee save registers.
     pop    %ebp
diff --git a/libc/arch-x86/bionic/vfork.S b/libc/arch-x86/bionic/vfork.S
deleted file mode 100644
index ec6f6ca..0000000
--- a/libc/arch-x86/bionic/vfork.S
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright (C) 2008 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_asm.h>
-
-// This custom code preserves the return address across the system call.
-
-ENTRY(vfork)
-  popl    %ecx  // Grab the return address.
-  movl    $__NR_vfork, %eax
-  int     $0x80
-  cmpl    $-MAX_ERRNO, %eax
-  jb      1f
-  negl    %eax
-  pushl   %eax
-  call    __set_errno
-  orl     $-1, %eax
-1:
-    jmp     *%ecx  // Jump to the stored return address.
-END(vfork)
diff --git a/libc/arch-x86/generic/generic.mk b/libc/arch-x86/generic/generic.mk
index c8b40ee..4aee5dc 100644
--- a/libc/arch-x86/generic/generic.mk
+++ b/libc/arch-x86/generic/generic.mk
@@ -1,5 +1,4 @@
 libc_bionic_src_files_x86 += \
-    arch-x86/atom/string/sse2-index-atom.S \
     arch-x86/atom/string/sse2-memchr-atom.S \
     arch-x86/atom/string/sse2-memrchr-atom.S \
     arch-x86/atom/string/sse2-strchr-atom.S \
@@ -28,7 +27,6 @@
     arch-x86/atom/string/ssse3-strcmp-atom.S \
     arch-x86/atom/string/ssse3-strncmp-atom.S \
     arch-x86/atom/string/ssse3-strcat-atom.S \
-    arch-x86/atom/string/ssse3-memcmp16-atom.S \
     arch-x86/atom/string/ssse3-wcscat-atom.S \
     arch-x86/atom/string/ssse3-wcscpy-atom.S
 else
@@ -36,7 +34,6 @@
     arch-x86/generic/string/strcmp.S \
     arch-x86/generic/string/strncmp.S \
     arch-x86/generic/string/strcat.S \
-    bionic/__memcmp16.cpp \
     upstream-freebsd/lib/libc/string/wcscpy.c \
     upstream-freebsd/lib/libc/string/wcscat.c \
     upstream-openbsd/lib/libc/string/strlcat.c \
diff --git a/libc/arch-x86/silvermont/silvermont.mk b/libc/arch-x86/silvermont/silvermont.mk
index b951ad5..176bee3 100644
--- a/libc/arch-x86/silvermont/silvermont.mk
+++ b/libc/arch-x86/silvermont/silvermont.mk
@@ -17,7 +17,6 @@
     arch-x86/atom/string/sse2-memrchr-atom.S \
     arch-x86/atom/string/sse2-strchr-atom.S \
     arch-x86/atom/string/sse2-strrchr-atom.S \
-    arch-x86/atom/string/sse2-index-atom.S \
     arch-x86/atom/string/sse2-strnlen-atom.S \
     arch-x86/atom/string/sse2-wcschr-atom.S \
     arch-x86/atom/string/sse2-wcsrchr-atom.S \
@@ -29,6 +28,5 @@
     arch-x86/atom/string/ssse3-strcmp-atom.S \
     arch-x86/atom/string/ssse3-strncmp-atom.S \
     arch-x86/atom/string/ssse3-strcat-atom.S \
-    arch-x86/atom/string/ssse3-memcmp16-atom.S \
     arch-x86/atom/string/ssse3-wcscat-atom.S \
     arch-x86/atom/string/ssse3-wcscpy-atom.S
diff --git a/libc/arch-x86/silvermont/string/sse2-memmove-slm.S b/libc/arch-x86/silvermont/string/sse2-memmove-slm.S
index 79a0a36..b971f0b 100644
--- a/libc/arch-x86/silvermont/string/sse2-memmove-slm.S
+++ b/libc/arch-x86/silvermont/string/sse2-memmove-slm.S
@@ -74,13 +74,13 @@
 #endif
 
 #ifdef USE_AS_BCOPY
-# define SRC           PARMS
-# define DEST          SRC+4
-# define LEN           DEST+4
+# define SRC		PARMS
+# define DEST		SRC+4
+# define LEN		DEST+4
 #else
-# define DEST          PARMS
-# define SRC           DEST+4
-# define LEN           SRC+4
+# define DEST		PARMS
+# define SRC		DEST+4
+# define LEN		SRC+4
 #endif
 
 #define CFI_PUSH(REG)		\
@@ -109,15 +109,15 @@
 /* Check whether we should copy backward or forward.  */
 	cmp	%eax, %edx
 	je	L(mm_return)
-	ja	L(mm_len_0_or_more_backward)
+	jg	L(mm_len_0_or_more_backward)
 
 /* Now do checks for lengths. We do [0..16], [0..32], [0..64], [0..128]
 	separately.  */
 	cmp	$16, %ecx
 	jbe	L(mm_len_0_16_bytes_forward)
 
-	cmpl    $32, %ecx
-	jg	L(mm_len_32_or_more_forward)
+	cmpl	$32, %ecx
+	ja	L(mm_len_32_or_more_forward)
 
 /* Copy [0..32] and return.  */
 	movdqu	(%eax), %xmm0
@@ -127,8 +127,8 @@
 	jmp	L(mm_return)
 
 L(mm_len_32_or_more_forward):
-	cmpl    $64, %ecx
-	jg	L(mm_len_64_or_more_forward)
+	cmpl	$64, %ecx
+	ja	L(mm_len_64_or_more_forward)
 
 /* Copy [0..64] and return.  */
 	movdqu	(%eax), %xmm0
@@ -142,8 +142,8 @@
 	jmp	L(mm_return)
 
 L(mm_len_64_or_more_forward):
-	cmpl    $128, %ecx
-	jg	L(mm_len_128_or_more_forward)
+	cmpl	$128, %ecx
+	ja	L(mm_len_128_or_more_forward)
 
 /* Copy [0..128] and return.  */
 	movdqu	(%eax), %xmm0
@@ -165,72 +165,66 @@
 	jmp	L(mm_return)
 
 L(mm_len_128_or_more_forward):
-
-	cmp     $SHARED_CACHE_SIZE_HALF, %ecx
-	jae     L(mm_large_page_forward)
-
 	PUSH (%esi)
 	PUSH (%edi)
-	movl	%eax, %esi
-	movl	%edx, %edi
 
 /* Aligning the address of destination.  */
-	movdqu	(%esi), %xmm0
-	movdqu	16(%esi), %xmm1
-	movdqu	32(%esi), %xmm2
-	movdqu	48(%esi), %xmm3
+	movdqu	(%eax), %xmm0
+	movdqu	16(%eax), %xmm1
+	movdqu	32(%eax), %xmm2
+	movdqu	48(%eax), %xmm3
 
-	leal	64(%edi), %edx
-	andl	$-64, %edx
+	leal	64(%edx), %edi
+	andl	$-64, %edi
+	subl	%edx, %eax
 
-	movl	%esi, %eax
-	subl	%edi, %eax
+	movdqu	(%eax, %edi), %xmm4
+	movdqu	16(%eax, %edi), %xmm5
+	movdqu	32(%eax, %edi), %xmm6
+	movdqu	48(%eax, %edi), %xmm7
 
-	movdqu	(%edx, %eax), %xmm4
-	movdqu	16(%edx, %eax), %xmm5
-	movdqu	32(%edx, %eax), %xmm6
-	movdqu	48(%edx, %eax), %xmm7
+	movdqu	%xmm0, (%edx)
+	movdqu	%xmm1, 16(%edx)
+	movdqu	%xmm2, 32(%edx)
+	movdqu	%xmm3, 48(%edx)
+	movdqa	%xmm4, (%edi)
+	movaps	%xmm5, 16(%edi)
+	movaps	%xmm6, 32(%edi)
+	movaps	%xmm7, 48(%edi)
+	addl	$64, %edi
 
-	movdqu	%xmm0, (%edi)
-	movdqu	%xmm1, 16(%edi)
-	movdqu	%xmm2, 32(%edi)
-	movdqu	%xmm3, 48(%edi)
-	movdqa	%xmm4, (%edx)
-	movdqa	%xmm5, 16(%edx)
-	movdqa	%xmm6, 32(%edx)
-	movdqa	%xmm7, 48(%edx)
-	addl	$64, %edx
-
-	leal	(%edi, %ecx), %ebx
+	leal	(%edx, %ecx), %ebx
 	andl	$-64, %ebx
-
-	cmp	%edx, %ebx
+	cmp	%edi, %ebx
 	jbe	L(mm_copy_remaining_forward)
 
+	cmp	$SHARED_CACHE_SIZE_HALF, %ecx
+	jae	L(mm_large_page_loop_forward)
+
 	.p2align 4
 L(mm_main_loop_forward):
 
-	prefetcht0 128(%edx, %eax)
+	prefetcht0 128(%eax, %edi)
 
-	movdqu	(%edx, %eax), %xmm0
-	movdqu	16(%edx, %eax), %xmm1
-	movdqu	32(%edx, %eax), %xmm2
-	movdqu	48(%edx, %eax), %xmm3
-	movdqa	%xmm0, (%edx)
-	movdqa	%xmm1, 16(%edx)
-	movdqa	%xmm2, 32(%edx)
-	movdqa	%xmm3, 48(%edx)
-	leal	64(%edx), %edx
-	cmp	%edx, %ebx
+	movdqu	(%eax, %edi), %xmm0
+	movdqu	16(%eax, %edi), %xmm1
+	movdqu	32(%eax, %edi), %xmm2
+	movdqu	48(%eax, %edi), %xmm3
+	movdqa	%xmm0, (%edi)
+	movaps	%xmm1, 16(%edi)
+	movaps	%xmm2, 32(%edi)
+	movaps	%xmm3, 48(%edi)
+	leal	64(%edi), %edi
+	cmp	%edi, %ebx
 	ja	L(mm_main_loop_forward)
 
 L(mm_copy_remaining_forward):
-	addl	%edi, %ecx
-	subl	%edx, %ecx
-/* We copied all up till %edx position in the dst.
+	addl	%edx, %ecx
+	subl	%edi, %ecx
+/* We copied all up till %edi position in the dst.
 	In %ecx now is how many bytes are left to copy.
 	Now we need to advance %esi. */
-	leal	(%edx, %eax), %esi
+	leal	(%edi, %eax), %esi
 
 L(mm_remaining_0_64_bytes_forward):
 	cmp	$32, %ecx
@@ -251,8 +245,8 @@
 	ja	L(mm_remaining_3_4_bytes_forward)
 	movzbl	-1(%esi,%ecx), %eax
 	movzbl	(%esi), %ebx
-	movb	%al, -1(%edx,%ecx)
-	movb	%bl, (%edx)
+	movb	%al, -1(%edi,%ecx)
+	movb	%bl, (%edi)
 	jmp	L(mm_return_pop_all)
 
 L(mm_remaining_33_64_bytes_forward):
@@ -260,40 +254,39 @@
 	movdqu	16(%esi), %xmm1
 	movdqu	-32(%esi, %ecx), %xmm2
 	movdqu	-16(%esi, %ecx), %xmm3
-	movdqu	%xmm0, (%edx)
-	movdqu	%xmm1, 16(%edx)
-	movdqu	%xmm2, -32(%edx, %ecx)
-	movdqu	%xmm3, -16(%edx, %ecx)
+	movdqu	%xmm0, (%edi)
+	movdqu	%xmm1, 16(%edi)
+	movdqu	%xmm2, -32(%edi, %ecx)
+	movdqu	%xmm3, -16(%edi, %ecx)
 	jmp	L(mm_return_pop_all)
 
 L(mm_remaining_17_32_bytes_forward):
 	movdqu	(%esi), %xmm0
 	movdqu	-16(%esi, %ecx), %xmm1
-	movdqu	%xmm0, (%edx)
-	movdqu	%xmm1, -16(%edx, %ecx)
-	jmp	L(mm_return_pop_all)
-
-L(mm_remaining_3_4_bytes_forward):
-	movzwl	-2(%esi,%ecx), %eax
-	movzwl	(%esi), %ebx
-	movw	%ax, -2(%edx,%ecx)
-	movw	%bx, (%edx)
-	jmp	L(mm_return_pop_all)
-
-L(mm_remaining_5_8_bytes_forward):
-	movl	(%esi), %eax
-	movl	-4(%esi,%ecx), %ebx
-	movl	%eax, (%edx)
-	movl	%ebx, -4(%edx,%ecx)
+	movdqu	%xmm0, (%edi)
+	movdqu	%xmm1, -16(%edi, %ecx)
 	jmp	L(mm_return_pop_all)
 
 L(mm_remaining_9_16_bytes_forward):
 	movq	(%esi), %xmm0
 	movq	-8(%esi, %ecx), %xmm1
-	movq	%xmm0, (%edx)
-	movq	%xmm1, -8(%edx, %ecx)
+	movq	%xmm0, (%edi)
+	movq	%xmm1, -8(%edi, %ecx)
 	jmp	L(mm_return_pop_all)
 
+L(mm_remaining_5_8_bytes_forward):
+	movl	(%esi), %eax
+	movl	-4(%esi,%ecx), %ebx
+	movl	%eax, (%edi)
+	movl	%ebx, -4(%edi,%ecx)
+	jmp	L(mm_return_pop_all)
+
+L(mm_remaining_3_4_bytes_forward):
+	movzwl	-2(%esi,%ecx), %eax
+	movzwl	(%esi), %ebx
+	movw	%ax, -2(%edi,%ecx)
+	movw	%bx, (%edi)
+	jmp	L(mm_return_pop_all)
 
 L(mm_len_0_16_bytes_forward):
 	testb	$24, %cl
@@ -334,15 +327,20 @@
 	movq	%xmm1, -8(%edx, %ecx)
 	jmp	L(mm_return)
 
+L(mm_recalc_len):
+/* Compute in %ecx how many bytes are left to copy after
+	the main loop stops.  */
+	movl	%ebx, %ecx
+	subl	%edx, %ecx
 /* The code for copying backwards.  */
 L(mm_len_0_or_more_backward):
 
-/* Now do checks for lengths. We do [0..16], [0..32], [0..64], [0..128]
+/* Now do checks for lengths. We do [0..16], [16..32], [32..64], [64..128]
 	separately.  */
 	cmp	$16, %ecx
 	jbe	L(mm_len_0_16_bytes_backward)
 
-	cmpl    $32, %ecx
+	cmpl	$32, %ecx
 	jg	L(mm_len_32_or_more_backward)
 
 /* Copy [0..32] and return.  */
@@ -353,7 +351,7 @@
 	jmp	L(mm_return)
 
 L(mm_len_32_or_more_backward):
-	cmpl    $64, %ecx
+	cmpl	$64, %ecx
 	jg	L(mm_len_64_or_more_backward)
 
 /* Copy [0..64] and return.  */
@@ -368,7 +366,7 @@
 	jmp	L(mm_return)
 
 L(mm_len_64_or_more_backward):
-	cmpl    $128, %ecx
+	cmpl	$128, %ecx
 	jg	L(mm_len_128_or_more_backward)
 
 /* Copy [0..128] and return.  */
@@ -391,10 +389,6 @@
 	jmp	L(mm_return)
 
 L(mm_len_128_or_more_backward):
-
-	cmp     $SHARED_CACHE_SIZE_HALF, %ecx
-	jae     L(mm_large_page_backward)
-
 	PUSH (%esi)
 	PUSH (%edi)
 
@@ -429,17 +423,11 @@
 	leal	64(%edx), %ebx
 	andl	$-64, %ebx
 
-/* Compute in %ecx how many bytes are left to copy after
-	the main loop stops.  */
-	movl	%ebx, %ecx
-	subl	%edx, %ecx
-
 	cmp	%edi, %ebx
-	jb	L(mm_main_loop_backward)
+	jae	L(mm_main_loop_backward_end)
 
-	POP (%edi)
-	POP (%esi)
-	jmp	L(mm_len_0_or_more_backward)
+	cmp	$SHARED_CACHE_SIZE_HALF, %ecx
+	jae	L(mm_large_page_loop_backward)
 
 	.p2align 4
 L(mm_main_loop_backward):
@@ -457,9 +445,10 @@
 	leal	-64(%edi), %edi
 	cmp	%edi, %ebx
 	jb	L(mm_main_loop_backward)
+L(mm_main_loop_backward_end):
 	POP (%edi)
 	POP (%esi)
-	jmp	L(mm_len_0_or_more_backward)
+	jmp	L(mm_recalc_len)
 
 /* Copy [0..16] and return.  */
 L(mm_len_0_16_bytes_backward):
@@ -508,151 +497,30 @@
 	RETURN
 
 L(mm_return_pop_all):
-	movl	%edi, %eax
+	movl	%edx, %eax
 	POP (%edi)
 	POP (%esi)
 	RETURN
 
 /* Big length copy forward part.  */
 
-L(mm_large_page_forward):
-/* Aligning the address of destination. We need to save
-	16 bits from the source in order not to overwrite them.  */
-
-	PUSH (%esi)
-	PUSH (%edi)
-	movl	%eax, %esi
-	movl	%edx, %edi
-
-	movdqu	(%esi), %xmm0
-	movdqu	16(%esi), %xmm1
-	movdqu	32(%esi), %xmm2
-	movdqu	48(%esi), %xmm3
-
-	leal	64(%edi), %edx
-	andl	$-64, %edx
-
-	movl	%esi, %eax
-	subl	%edi, %eax
-
-	movdqu	(%edx, %eax), %xmm4
-	movdqu	16(%edx, %eax), %xmm5
-	movdqu	32(%edx, %eax), %xmm6
-	movdqu	48(%edx, %eax), %xmm7
-
-	movdqu	%xmm0, (%edi)
-	movdqu	%xmm1, 16(%edi)
-	movdqu	%xmm2, 32(%edi)
-	movdqu	%xmm3, 48(%edi)
-	movntdq	%xmm4, (%edx)
-	movntdq	%xmm5, 16(%edx)
-	movntdq	%xmm6, 32(%edx)
-	movntdq	%xmm7, 48(%edx)
-	addl	$64, %edx
-
-	leal	(%edi, %ecx), %ebx
-	andl	$-128, %ebx
-
-	cmp	%edx, %ebx
-	jbe	L(mm_copy_remaining_forward)
-
 	.p2align 4
 L(mm_large_page_loop_forward):
-	movdqu	(%edx, %eax), %xmm0
-	movdqu	16(%edx, %eax), %xmm1
-	movdqu	32(%edx, %eax), %xmm2
-	movdqu	48(%edx, %eax), %xmm3
-	movdqu	64(%edx, %eax), %xmm4
-	movdqu	80(%edx, %eax), %xmm5
-	movdqu	96(%edx, %eax), %xmm6
-	movdqu	112(%edx, %eax), %xmm7
-	movntdq	%xmm0, (%edx)
-	movntdq	%xmm1, 16(%edx)
-	movntdq	%xmm2, 32(%edx)
-	movntdq	%xmm3, 48(%edx)
-	movntdq	%xmm4, 64(%edx)
-	movntdq	%xmm5, 80(%edx)
-	movntdq	%xmm6, 96(%edx)
-	movntdq	%xmm7, 112(%edx)
-	leal	128(%edx), %edx
-	cmp	%edx, %ebx
+	movdqu	(%eax, %edi), %xmm0
+	movdqu	16(%eax, %edi), %xmm1
+	movdqu	32(%eax, %edi), %xmm2
+	movdqu	48(%eax, %edi), %xmm3
+	movntdq	%xmm0, (%edi)
+	movntdq	%xmm1, 16(%edi)
+	movntdq	%xmm2, 32(%edi)
+	movntdq	%xmm3, 48(%edi)
+	leal	64(%edi), %edi
+	cmp	%edi, %ebx
 	ja	L(mm_large_page_loop_forward)
 	sfence
-
-	addl	%edi, %ecx
-	subl	%edx, %ecx
-/* We copied all up till %edx position in the dst.
-	In %ecx now is how many bytes are left to copy.
-	Now we need to advance %esi. */
-	leal	(%edx, %eax), %esi
-
-	cmp	$64, %ecx
-	jb	L(mm_remaining_0_64_bytes_forward)
-
-	movdqu	(%esi), %xmm0
-	movdqu	16(%esi), %xmm1
-	movdqu	32(%esi), %xmm2
-	movdqu	48(%esi), %xmm3
-	movdqu	-64(%esi, %ecx), %xmm4
-	movdqu	-48(%esi, %ecx), %xmm5
-	movdqu	-32(%esi, %ecx), %xmm6
-	movdqu	-16(%esi, %ecx), %xmm7
-	movdqu	%xmm0, (%edx)
-	movdqu	%xmm1, 16(%edx)
-	movdqu	%xmm2, 32(%edx)
-	movdqu	%xmm3, 48(%edx)
-	movdqu	%xmm4, -64(%edx, %ecx)
-	movdqu	%xmm5, -48(%edx, %ecx)
-	movdqu	%xmm6, -32(%edx, %ecx)
-	movdqu	%xmm7, -16(%edx, %ecx)
-	jmp	L(mm_return_pop_all)
-
+	jmp	L(mm_copy_remaining_forward)
 
 /* Big length copy backward part.  */
-L(mm_large_page_backward):
-/* Aligning the address of destination. We need to save
-	16 bits from the source in order not to overwrite them.  */
-
-	PUSH (%esi)
-	PUSH (%edi)
-
-	movdqu	-16(%eax, %ecx), %xmm0
-	movdqu	-32(%eax, %ecx), %xmm1
-	movdqu	-48(%eax, %ecx), %xmm2
-	movdqu	-64(%eax, %ecx), %xmm3
-
-	leal	(%edx, %ecx), %edi
-	andl	$-64, %edi
-
-	movl	%eax, %esi
-	subl	%edx, %esi
-
-	movdqu	-16(%edi, %esi), %xmm4
-	movdqu	-32(%edi, %esi), %xmm5
-	movdqu	-48(%edi, %esi), %xmm6
-	movdqu	-64(%edi, %esi), %xmm7
-
-	movdqu	%xmm0, -16(%edx, %ecx)
-	movdqu	%xmm1, -32(%edx, %ecx)
-	movdqu	%xmm2, -48(%edx, %ecx)
-	movdqu	%xmm3, -64(%edx, %ecx)
-	movntdq	%xmm4, -16(%edi)
-	movntdq	%xmm5, -32(%edi)
-	movntdq	%xmm6, -48(%edi)
-	movntdq	%xmm7, -64(%edi)
-	leal	-64(%edi), %edi
-
-	leal	128(%edx), %ebx
-	andl	$-64, %ebx
-
-/* Compute in %ecx how many bytes are left to copy after
-	the main loop stops.  */
-	movl	%ebx, %ecx
-	subl	%edx, %ecx
-
-	cmp	%edi, %ebx
-	jae	L(mm_len_0_or_more_backward)
-
 	.p2align 4
 L(mm_large_page_loop_backward):
 	movdqu	-64(%edi, %esi), %xmm0
@@ -666,8 +534,9 @@
 	leal	-64(%edi), %edi
 	cmp	%edi, %ebx
 	jb	L(mm_large_page_loop_backward)
+	sfence
 	POP (%edi)
 	POP (%esi)
-	jmp	L(mm_len_0_or_more_backward)
+	jmp	L(mm_recalc_len)
 
 END (MEMMOVE)
diff --git a/libc/arch-x86/syscalls/__accept4.S b/libc/arch-x86/syscalls/__accept4.S
index 18a76a1..2d9cc42 100644
--- a/libc/arch-x86/syscalls/__accept4.S
+++ b/libc/arch-x86/syscalls/__accept4.S
@@ -20,7 +20,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/__brk.S b/libc/arch-x86/syscalls/__brk.S
index 2439752..632dfcf 100644
--- a/libc/arch-x86/syscalls/__brk.S
+++ b/libc/arch-x86/syscalls/__brk.S
@@ -15,7 +15,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/__connect.S b/libc/arch-x86/syscalls/__connect.S
index 3149e8c..5ee4fbf 100644
--- a/libc/arch-x86/syscalls/__connect.S
+++ b/libc/arch-x86/syscalls/__connect.S
@@ -20,7 +20,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/__epoll_pwait.S b/libc/arch-x86/syscalls/__epoll_pwait.S
index 67545b1..641ca6d 100644
--- a/libc/arch-x86/syscalls/__epoll_pwait.S
+++ b/libc/arch-x86/syscalls/__epoll_pwait.S
@@ -35,7 +35,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebp
     popl    %edi
diff --git a/libc/arch-x86/syscalls/__exit.S b/libc/arch-x86/syscalls/__exit.S
index d768306..8578f56 100644
--- a/libc/arch-x86/syscalls/__exit.S
+++ b/libc/arch-x86/syscalls/__exit.S
@@ -15,7 +15,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/__fcntl64.S b/libc/arch-x86/syscalls/__fcntl64.S
index b2d5664..ef58d15 100644
--- a/libc/arch-x86/syscalls/__fcntl64.S
+++ b/libc/arch-x86/syscalls/__fcntl64.S
@@ -23,7 +23,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/__fstatfs64.S b/libc/arch-x86/syscalls/__fstatfs64.S
index d80ecc5..0ca3360 100644
--- a/libc/arch-x86/syscalls/__fstatfs64.S
+++ b/libc/arch-x86/syscalls/__fstatfs64.S
@@ -23,7 +23,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/__getcpu.S b/libc/arch-x86/syscalls/__getcpu.S
index 23ce3f0..b181877 100644
--- a/libc/arch-x86/syscalls/__getcpu.S
+++ b/libc/arch-x86/syscalls/__getcpu.S
@@ -23,7 +23,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/__getcwd.S b/libc/arch-x86/syscalls/__getcwd.S
index 5454d7a..b71ba0d 100644
--- a/libc/arch-x86/syscalls/__getcwd.S
+++ b/libc/arch-x86/syscalls/__getcwd.S
@@ -19,7 +19,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/getdents.S b/libc/arch-x86/syscalls/__getdents64.S
similarity index 91%
rename from libc/arch-x86/syscalls/getdents.S
rename to libc/arch-x86/syscalls/__getdents64.S
index 0b045b2..3fc8719 100644
--- a/libc/arch-x86/syscalls/getdents.S
+++ b/libc/arch-x86/syscalls/__getdents64.S
@@ -2,7 +2,7 @@
 
 #include <private/bionic_asm.h>
 
-ENTRY(getdents)
+ENTRY(__getdents64)
     pushl   %ebx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
@@ -23,10 +23,9 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
     popl    %ebx
     ret
-END(getdents)
+END(__getdents64)
diff --git a/libc/arch-x86/syscalls/getpid.S b/libc/arch-x86/syscalls/__getpid.S
similarity index 84%
rename from libc/arch-x86/syscalls/getpid.S
rename to libc/arch-x86/syscalls/__getpid.S
index cecaf74..f138d2f 100644
--- a/libc/arch-x86/syscalls/getpid.S
+++ b/libc/arch-x86/syscalls/__getpid.S
@@ -2,7 +2,7 @@
 
 #include <private/bionic_asm.h>
 
-ENTRY(getpid)
+ENTRY(__getpid)
     movl    $__NR_getpid, %eax
     int     $0x80
     cmpl    $-MAX_ERRNO, %eax
@@ -11,7 +11,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     ret
-END(getpid)
+END(__getpid)
diff --git a/libc/arch-x86/syscalls/__getpriority.S b/libc/arch-x86/syscalls/__getpriority.S
index 2d97f0d..103431d 100644
--- a/libc/arch-x86/syscalls/__getpriority.S
+++ b/libc/arch-x86/syscalls/__getpriority.S
@@ -19,7 +19,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/__ioctl.S b/libc/arch-x86/syscalls/__ioctl.S
index eb248fb..99d2d2c 100644
--- a/libc/arch-x86/syscalls/__ioctl.S
+++ b/libc/arch-x86/syscalls/__ioctl.S
@@ -23,7 +23,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/__llseek.S b/libc/arch-x86/syscalls/__llseek.S
index 7a1ea83..0cdb98a 100644
--- a/libc/arch-x86/syscalls/__llseek.S
+++ b/libc/arch-x86/syscalls/__llseek.S
@@ -31,7 +31,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edi
     popl    %esi
diff --git a/libc/arch-x86/syscalls/__mmap2.S b/libc/arch-x86/syscalls/__mmap2.S
index 603ee2b..47131ef 100644
--- a/libc/arch-x86/syscalls/__mmap2.S
+++ b/libc/arch-x86/syscalls/__mmap2.S
@@ -35,7 +35,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebp
     popl    %edi
diff --git a/libc/arch-x86/syscalls/__openat.S b/libc/arch-x86/syscalls/__openat.S
index a6db672..aec10e5 100644
--- a/libc/arch-x86/syscalls/__openat.S
+++ b/libc/arch-x86/syscalls/__openat.S
@@ -27,7 +27,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %esi
     popl    %edx
diff --git a/libc/arch-x86/syscalls/__ppoll.S b/libc/arch-x86/syscalls/__ppoll.S
index d8ac98a..92197b7 100644
--- a/libc/arch-x86/syscalls/__ppoll.S
+++ b/libc/arch-x86/syscalls/__ppoll.S
@@ -31,7 +31,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edi
     popl    %esi
diff --git a/libc/arch-x86/syscalls/__pselect6.S b/libc/arch-x86/syscalls/__pselect6.S
index 9c66a3c..38402f0 100644
--- a/libc/arch-x86/syscalls/__pselect6.S
+++ b/libc/arch-x86/syscalls/__pselect6.S
@@ -35,7 +35,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebp
     popl    %edi
diff --git a/libc/arch-x86/syscalls/__ptrace.S b/libc/arch-x86/syscalls/__ptrace.S
index 54e8221..cea5847 100644
--- a/libc/arch-x86/syscalls/__ptrace.S
+++ b/libc/arch-x86/syscalls/__ptrace.S
@@ -27,7 +27,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %esi
     popl    %edx
diff --git a/libc/arch-x86/syscalls/__reboot.S b/libc/arch-x86/syscalls/__reboot.S
index daea66e..4546994 100644
--- a/libc/arch-x86/syscalls/__reboot.S
+++ b/libc/arch-x86/syscalls/__reboot.S
@@ -27,7 +27,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %esi
     popl    %edx
diff --git a/libc/arch-x86/syscalls/__rt_sigaction.S b/libc/arch-x86/syscalls/__rt_sigaction.S
index d182a82..bfbe5ba 100644
--- a/libc/arch-x86/syscalls/__rt_sigaction.S
+++ b/libc/arch-x86/syscalls/__rt_sigaction.S
@@ -27,7 +27,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %esi
     popl    %edx
diff --git a/libc/arch-x86/syscalls/__rt_sigpending.S b/libc/arch-x86/syscalls/__rt_sigpending.S
index d83ccc0..dac478a 100644
--- a/libc/arch-x86/syscalls/__rt_sigpending.S
+++ b/libc/arch-x86/syscalls/__rt_sigpending.S
@@ -19,7 +19,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/__rt_sigprocmask.S b/libc/arch-x86/syscalls/__rt_sigprocmask.S
index 4ca9443..f112360 100644
--- a/libc/arch-x86/syscalls/__rt_sigprocmask.S
+++ b/libc/arch-x86/syscalls/__rt_sigprocmask.S
@@ -27,7 +27,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %esi
     popl    %edx
diff --git a/libc/arch-x86/syscalls/__rt_sigsuspend.S b/libc/arch-x86/syscalls/__rt_sigsuspend.S
index f1a4cf3..ef505c0 100644
--- a/libc/arch-x86/syscalls/__rt_sigsuspend.S
+++ b/libc/arch-x86/syscalls/__rt_sigsuspend.S
@@ -19,7 +19,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/__rt_sigtimedwait.S b/libc/arch-x86/syscalls/__rt_sigtimedwait.S
index 4fae0f7..d19c7db 100644
--- a/libc/arch-x86/syscalls/__rt_sigtimedwait.S
+++ b/libc/arch-x86/syscalls/__rt_sigtimedwait.S
@@ -27,7 +27,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %esi
     popl    %edx
diff --git a/libc/arch-x86/syscalls/__sched_getaffinity.S b/libc/arch-x86/syscalls/__sched_getaffinity.S
index bddbab5..e7cb8f1 100644
--- a/libc/arch-x86/syscalls/__sched_getaffinity.S
+++ b/libc/arch-x86/syscalls/__sched_getaffinity.S
@@ -23,7 +23,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/__set_thread_area.S b/libc/arch-x86/syscalls/__set_thread_area.S
index 0772ffe..dda23a0 100644
--- a/libc/arch-x86/syscalls/__set_thread_area.S
+++ b/libc/arch-x86/syscalls/__set_thread_area.S
@@ -15,7 +15,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/__set_tid_address.S b/libc/arch-x86/syscalls/__set_tid_address.S
index e61c2ac..1566d9a 100644
--- a/libc/arch-x86/syscalls/__set_tid_address.S
+++ b/libc/arch-x86/syscalls/__set_tid_address.S
@@ -15,7 +15,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/__sigaction.S b/libc/arch-x86/syscalls/__sigaction.S
index b4ca292..f1a51d2 100644
--- a/libc/arch-x86/syscalls/__sigaction.S
+++ b/libc/arch-x86/syscalls/__sigaction.S
@@ -23,7 +23,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/__signalfd4.S b/libc/arch-x86/syscalls/__signalfd4.S
index 1faafac..335e206 100644
--- a/libc/arch-x86/syscalls/__signalfd4.S
+++ b/libc/arch-x86/syscalls/__signalfd4.S
@@ -27,7 +27,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %esi
     popl    %edx
diff --git a/libc/arch-x86/syscalls/__socket.S b/libc/arch-x86/syscalls/__socket.S
index 2386b98..368680f 100644
--- a/libc/arch-x86/syscalls/__socket.S
+++ b/libc/arch-x86/syscalls/__socket.S
@@ -20,7 +20,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/__statfs64.S b/libc/arch-x86/syscalls/__statfs64.S
index 69dd87e..6bb9d99 100644
--- a/libc/arch-x86/syscalls/__statfs64.S
+++ b/libc/arch-x86/syscalls/__statfs64.S
@@ -23,7 +23,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/__timer_create.S b/libc/arch-x86/syscalls/__timer_create.S
index 520046f..3d28ae9 100644
--- a/libc/arch-x86/syscalls/__timer_create.S
+++ b/libc/arch-x86/syscalls/__timer_create.S
@@ -23,7 +23,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/__timer_delete.S b/libc/arch-x86/syscalls/__timer_delete.S
index 8fff727..7d64d6d 100644
--- a/libc/arch-x86/syscalls/__timer_delete.S
+++ b/libc/arch-x86/syscalls/__timer_delete.S
@@ -15,7 +15,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/__timer_getoverrun.S b/libc/arch-x86/syscalls/__timer_getoverrun.S
index 372625b..cb37765 100644
--- a/libc/arch-x86/syscalls/__timer_getoverrun.S
+++ b/libc/arch-x86/syscalls/__timer_getoverrun.S
@@ -15,7 +15,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/__timer_gettime.S b/libc/arch-x86/syscalls/__timer_gettime.S
index 9588bf7..5c43f4a 100644
--- a/libc/arch-x86/syscalls/__timer_gettime.S
+++ b/libc/arch-x86/syscalls/__timer_gettime.S
@@ -19,7 +19,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/__timer_settime.S b/libc/arch-x86/syscalls/__timer_settime.S
index 7b0ab43..da7c587 100644
--- a/libc/arch-x86/syscalls/__timer_settime.S
+++ b/libc/arch-x86/syscalls/__timer_settime.S
@@ -27,7 +27,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %esi
     popl    %edx
diff --git a/libc/arch-x86/syscalls/__waitid.S b/libc/arch-x86/syscalls/__waitid.S
index 7e63f8a..7e3ecdd 100644
--- a/libc/arch-x86/syscalls/__waitid.S
+++ b/libc/arch-x86/syscalls/__waitid.S
@@ -31,7 +31,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edi
     popl    %esi
diff --git a/libc/arch-x86/syscalls/_exit.S b/libc/arch-x86/syscalls/_exit.S
index 5b569b9..36e884a 100644
--- a/libc/arch-x86/syscalls/_exit.S
+++ b/libc/arch-x86/syscalls/_exit.S
@@ -15,7 +15,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/acct.S b/libc/arch-x86/syscalls/acct.S
index 7fa4508..a036114 100644
--- a/libc/arch-x86/syscalls/acct.S
+++ b/libc/arch-x86/syscalls/acct.S
@@ -15,7 +15,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/bind.S b/libc/arch-x86/syscalls/bind.S
index c99ada1..ab5a29e 100644
--- a/libc/arch-x86/syscalls/bind.S
+++ b/libc/arch-x86/syscalls/bind.S
@@ -20,7 +20,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/capget.S b/libc/arch-x86/syscalls/capget.S
index 82065cf..5441e49 100644
--- a/libc/arch-x86/syscalls/capget.S
+++ b/libc/arch-x86/syscalls/capget.S
@@ -19,7 +19,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/capset.S b/libc/arch-x86/syscalls/capset.S
index 8c9367f..d04e411 100644
--- a/libc/arch-x86/syscalls/capset.S
+++ b/libc/arch-x86/syscalls/capset.S
@@ -19,7 +19,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/chdir.S b/libc/arch-x86/syscalls/chdir.S
index 00986d4..d32a0bd 100644
--- a/libc/arch-x86/syscalls/chdir.S
+++ b/libc/arch-x86/syscalls/chdir.S
@@ -15,7 +15,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/chroot.S b/libc/arch-x86/syscalls/chroot.S
index cb8a099..63d7e00 100644
--- a/libc/arch-x86/syscalls/chroot.S
+++ b/libc/arch-x86/syscalls/chroot.S
@@ -15,7 +15,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/clock_getres.S b/libc/arch-x86/syscalls/clock_getres.S
index 5fef51a..321299c 100644
--- a/libc/arch-x86/syscalls/clock_getres.S
+++ b/libc/arch-x86/syscalls/clock_getres.S
@@ -19,7 +19,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/clock_gettime.S b/libc/arch-x86/syscalls/clock_gettime.S
index 4275edc..54f769a 100644
--- a/libc/arch-x86/syscalls/clock_gettime.S
+++ b/libc/arch-x86/syscalls/clock_gettime.S
@@ -19,7 +19,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/clock_nanosleep.S b/libc/arch-x86/syscalls/clock_nanosleep.S
index 1f0fcc6..ca961c0 100644
--- a/libc/arch-x86/syscalls/clock_nanosleep.S
+++ b/libc/arch-x86/syscalls/clock_nanosleep.S
@@ -27,7 +27,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %esi
     popl    %edx
diff --git a/libc/arch-x86/syscalls/clock_settime.S b/libc/arch-x86/syscalls/clock_settime.S
index 4f59a10..ab8c43e 100644
--- a/libc/arch-x86/syscalls/clock_settime.S
+++ b/libc/arch-x86/syscalls/clock_settime.S
@@ -19,7 +19,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/close.S b/libc/arch-x86/syscalls/close.S
index 3f4e034..0b3e73a 100644
--- a/libc/arch-x86/syscalls/close.S
+++ b/libc/arch-x86/syscalls/close.S
@@ -15,7 +15,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/delete_module.S b/libc/arch-x86/syscalls/delete_module.S
index 8923f46..757c8c1 100644
--- a/libc/arch-x86/syscalls/delete_module.S
+++ b/libc/arch-x86/syscalls/delete_module.S
@@ -19,7 +19,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/dup.S b/libc/arch-x86/syscalls/dup.S
index ed922de..64e1538 100644
--- a/libc/arch-x86/syscalls/dup.S
+++ b/libc/arch-x86/syscalls/dup.S
@@ -15,7 +15,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/dup3.S b/libc/arch-x86/syscalls/dup3.S
index d1a714d..a0ecd19 100644
--- a/libc/arch-x86/syscalls/dup3.S
+++ b/libc/arch-x86/syscalls/dup3.S
@@ -23,7 +23,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/epoll_create1.S b/libc/arch-x86/syscalls/epoll_create1.S
index 69ddd9b..5b6a1ba 100644
--- a/libc/arch-x86/syscalls/epoll_create1.S
+++ b/libc/arch-x86/syscalls/epoll_create1.S
@@ -15,7 +15,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/epoll_ctl.S b/libc/arch-x86/syscalls/epoll_ctl.S
index 2a50db8..3fd8acd 100644
--- a/libc/arch-x86/syscalls/epoll_ctl.S
+++ b/libc/arch-x86/syscalls/epoll_ctl.S
@@ -27,7 +27,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %esi
     popl    %edx
diff --git a/libc/arch-x86/syscalls/eventfd.S b/libc/arch-x86/syscalls/eventfd.S
index 48a07a2..55c5e6a 100644
--- a/libc/arch-x86/syscalls/eventfd.S
+++ b/libc/arch-x86/syscalls/eventfd.S
@@ -19,7 +19,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/execve.S b/libc/arch-x86/syscalls/execve.S
index 345b5a4..7ad54f7 100644
--- a/libc/arch-x86/syscalls/execve.S
+++ b/libc/arch-x86/syscalls/execve.S
@@ -23,7 +23,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/faccessat.S b/libc/arch-x86/syscalls/faccessat.S
index 1f340f7..115d645 100644
--- a/libc/arch-x86/syscalls/faccessat.S
+++ b/libc/arch-x86/syscalls/faccessat.S
@@ -27,7 +27,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %esi
     popl    %edx
diff --git a/libc/arch-x86/syscalls/fallocate64.S b/libc/arch-x86/syscalls/fallocate64.S
index be3d45b..f8bde62 100644
--- a/libc/arch-x86/syscalls/fallocate64.S
+++ b/libc/arch-x86/syscalls/fallocate64.S
@@ -35,7 +35,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebp
     popl    %edi
diff --git a/libc/arch-x86/syscalls/fchdir.S b/libc/arch-x86/syscalls/fchdir.S
index da95c0b..56e496c 100644
--- a/libc/arch-x86/syscalls/fchdir.S
+++ b/libc/arch-x86/syscalls/fchdir.S
@@ -15,7 +15,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/fchmod.S b/libc/arch-x86/syscalls/fchmod.S
index fe189f4..4badcea 100644
--- a/libc/arch-x86/syscalls/fchmod.S
+++ b/libc/arch-x86/syscalls/fchmod.S
@@ -19,7 +19,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/fchmodat.S b/libc/arch-x86/syscalls/fchmodat.S
index 794450b..552e85c 100644
--- a/libc/arch-x86/syscalls/fchmodat.S
+++ b/libc/arch-x86/syscalls/fchmodat.S
@@ -27,7 +27,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %esi
     popl    %edx
diff --git a/libc/arch-x86/syscalls/fchown.S b/libc/arch-x86/syscalls/fchown.S
index 5e82388..7e82637 100644
--- a/libc/arch-x86/syscalls/fchown.S
+++ b/libc/arch-x86/syscalls/fchown.S
@@ -23,7 +23,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/fchownat.S b/libc/arch-x86/syscalls/fchownat.S
index bfe61e9..de039d0 100644
--- a/libc/arch-x86/syscalls/fchownat.S
+++ b/libc/arch-x86/syscalls/fchownat.S
@@ -31,7 +31,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edi
     popl    %esi
diff --git a/libc/arch-x86/syscalls/fdatasync.S b/libc/arch-x86/syscalls/fdatasync.S
index 17846ce..fdb5578 100644
--- a/libc/arch-x86/syscalls/fdatasync.S
+++ b/libc/arch-x86/syscalls/fdatasync.S
@@ -15,7 +15,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/fgetxattr.S b/libc/arch-x86/syscalls/fgetxattr.S
index 335d298..3ed63d3 100644
--- a/libc/arch-x86/syscalls/fgetxattr.S
+++ b/libc/arch-x86/syscalls/fgetxattr.S
@@ -27,7 +27,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %esi
     popl    %edx
diff --git a/libc/arch-x86/syscalls/flistxattr.S b/libc/arch-x86/syscalls/flistxattr.S
index 5cab5ad..2840114 100644
--- a/libc/arch-x86/syscalls/flistxattr.S
+++ b/libc/arch-x86/syscalls/flistxattr.S
@@ -23,7 +23,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/flock.S b/libc/arch-x86/syscalls/flock.S
index 277dd2a..dc9ef02 100644
--- a/libc/arch-x86/syscalls/flock.S
+++ b/libc/arch-x86/syscalls/flock.S
@@ -19,7 +19,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/fremovexattr.S b/libc/arch-x86/syscalls/fremovexattr.S
index a60e031..1e77f82 100644
--- a/libc/arch-x86/syscalls/fremovexattr.S
+++ b/libc/arch-x86/syscalls/fremovexattr.S
@@ -19,7 +19,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/fsetxattr.S b/libc/arch-x86/syscalls/fsetxattr.S
index c4d4854..703a8d7 100644
--- a/libc/arch-x86/syscalls/fsetxattr.S
+++ b/libc/arch-x86/syscalls/fsetxattr.S
@@ -31,7 +31,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edi
     popl    %esi
diff --git a/libc/arch-x86/syscalls/fstat64.S b/libc/arch-x86/syscalls/fstat64.S
index 054f6de..970eeb1 100644
--- a/libc/arch-x86/syscalls/fstat64.S
+++ b/libc/arch-x86/syscalls/fstat64.S
@@ -19,7 +19,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/fstatat64.S b/libc/arch-x86/syscalls/fstatat64.S
index 928d071..476578d 100644
--- a/libc/arch-x86/syscalls/fstatat64.S
+++ b/libc/arch-x86/syscalls/fstatat64.S
@@ -27,7 +27,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %esi
     popl    %edx
diff --git a/libc/arch-x86/syscalls/fsync.S b/libc/arch-x86/syscalls/fsync.S
index f12d010..9fc84b7 100644
--- a/libc/arch-x86/syscalls/fsync.S
+++ b/libc/arch-x86/syscalls/fsync.S
@@ -15,7 +15,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/ftruncate.S b/libc/arch-x86/syscalls/ftruncate.S
index 062982c..6765d98 100644
--- a/libc/arch-x86/syscalls/ftruncate.S
+++ b/libc/arch-x86/syscalls/ftruncate.S
@@ -19,7 +19,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/ftruncate64.S b/libc/arch-x86/syscalls/ftruncate64.S
index 71920be..21e26ce 100644
--- a/libc/arch-x86/syscalls/ftruncate64.S
+++ b/libc/arch-x86/syscalls/ftruncate64.S
@@ -23,7 +23,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/getegid.S b/libc/arch-x86/syscalls/getegid.S
index 61e7839..445cd97 100644
--- a/libc/arch-x86/syscalls/getegid.S
+++ b/libc/arch-x86/syscalls/getegid.S
@@ -11,7 +11,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     ret
 END(getegid)
diff --git a/libc/arch-x86/syscalls/geteuid.S b/libc/arch-x86/syscalls/geteuid.S
index 80bcf7a..8290a93 100644
--- a/libc/arch-x86/syscalls/geteuid.S
+++ b/libc/arch-x86/syscalls/geteuid.S
@@ -11,7 +11,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     ret
 END(geteuid)
diff --git a/libc/arch-x86/syscalls/getgid.S b/libc/arch-x86/syscalls/getgid.S
index 87d31a7..d90767f 100644
--- a/libc/arch-x86/syscalls/getgid.S
+++ b/libc/arch-x86/syscalls/getgid.S
@@ -11,7 +11,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     ret
 END(getgid)
diff --git a/libc/arch-x86/syscalls/getgroups.S b/libc/arch-x86/syscalls/getgroups.S
index d9b7d80..d36c09c 100644
--- a/libc/arch-x86/syscalls/getgroups.S
+++ b/libc/arch-x86/syscalls/getgroups.S
@@ -19,7 +19,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/getitimer.S b/libc/arch-x86/syscalls/getitimer.S
index 8f3a0ee..ebf1260 100644
--- a/libc/arch-x86/syscalls/getitimer.S
+++ b/libc/arch-x86/syscalls/getitimer.S
@@ -19,7 +19,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/getpeername.S b/libc/arch-x86/syscalls/getpeername.S
index 1ea42a0..abecd4e 100644
--- a/libc/arch-x86/syscalls/getpeername.S
+++ b/libc/arch-x86/syscalls/getpeername.S
@@ -20,7 +20,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/getpgid.S b/libc/arch-x86/syscalls/getpgid.S
index 179c7db..e74ed3b 100644
--- a/libc/arch-x86/syscalls/getpgid.S
+++ b/libc/arch-x86/syscalls/getpgid.S
@@ -15,7 +15,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/getppid.S b/libc/arch-x86/syscalls/getppid.S
index b932044..025fa42 100644
--- a/libc/arch-x86/syscalls/getppid.S
+++ b/libc/arch-x86/syscalls/getppid.S
@@ -11,7 +11,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     ret
 END(getppid)
diff --git a/libc/arch-x86/syscalls/getresgid.S b/libc/arch-x86/syscalls/getresgid.S
index ce8d89a..fe08cdf 100644
--- a/libc/arch-x86/syscalls/getresgid.S
+++ b/libc/arch-x86/syscalls/getresgid.S
@@ -23,7 +23,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/getresuid.S b/libc/arch-x86/syscalls/getresuid.S
index f444d16..8e292fc 100644
--- a/libc/arch-x86/syscalls/getresuid.S
+++ b/libc/arch-x86/syscalls/getresuid.S
@@ -23,7 +23,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/getrlimit.S b/libc/arch-x86/syscalls/getrlimit.S
index 66f4e6f..fdb5a03 100644
--- a/libc/arch-x86/syscalls/getrlimit.S
+++ b/libc/arch-x86/syscalls/getrlimit.S
@@ -19,7 +19,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/getrusage.S b/libc/arch-x86/syscalls/getrusage.S
index 8d4fd7b..ae5f796 100644
--- a/libc/arch-x86/syscalls/getrusage.S
+++ b/libc/arch-x86/syscalls/getrusage.S
@@ -19,7 +19,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/getsid.S b/libc/arch-x86/syscalls/getsid.S
index 39e5551..e1dc87f 100644
--- a/libc/arch-x86/syscalls/getsid.S
+++ b/libc/arch-x86/syscalls/getsid.S
@@ -15,7 +15,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/getsockname.S b/libc/arch-x86/syscalls/getsockname.S
index ec0cc84..254b755 100644
--- a/libc/arch-x86/syscalls/getsockname.S
+++ b/libc/arch-x86/syscalls/getsockname.S
@@ -20,7 +20,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/getsockopt.S b/libc/arch-x86/syscalls/getsockopt.S
index cf109f1..2ef630c 100644
--- a/libc/arch-x86/syscalls/getsockopt.S
+++ b/libc/arch-x86/syscalls/getsockopt.S
@@ -20,7 +20,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/gettimeofday.S b/libc/arch-x86/syscalls/gettimeofday.S
index 801e7ab..709a17b 100644
--- a/libc/arch-x86/syscalls/gettimeofday.S
+++ b/libc/arch-x86/syscalls/gettimeofday.S
@@ -19,7 +19,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/getuid.S b/libc/arch-x86/syscalls/getuid.S
index e91305a..c375d30 100644
--- a/libc/arch-x86/syscalls/getuid.S
+++ b/libc/arch-x86/syscalls/getuid.S
@@ -11,7 +11,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     ret
 END(getuid)
diff --git a/libc/arch-x86/syscalls/getxattr.S b/libc/arch-x86/syscalls/getxattr.S
index 5bd1ab8..db9c9dd 100644
--- a/libc/arch-x86/syscalls/getxattr.S
+++ b/libc/arch-x86/syscalls/getxattr.S
@@ -27,7 +27,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %esi
     popl    %edx
diff --git a/libc/arch-x86/syscalls/init_module.S b/libc/arch-x86/syscalls/init_module.S
index 8afd644..543b31e 100644
--- a/libc/arch-x86/syscalls/init_module.S
+++ b/libc/arch-x86/syscalls/init_module.S
@@ -23,7 +23,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/inotify_add_watch.S b/libc/arch-x86/syscalls/inotify_add_watch.S
index 0de8f88..f58c6d1 100644
--- a/libc/arch-x86/syscalls/inotify_add_watch.S
+++ b/libc/arch-x86/syscalls/inotify_add_watch.S
@@ -23,7 +23,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/inotify_init1.S b/libc/arch-x86/syscalls/inotify_init1.S
index 0920618..2c7b100 100644
--- a/libc/arch-x86/syscalls/inotify_init1.S
+++ b/libc/arch-x86/syscalls/inotify_init1.S
@@ -15,7 +15,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/inotify_rm_watch.S b/libc/arch-x86/syscalls/inotify_rm_watch.S
index 37394c5..c453478 100644
--- a/libc/arch-x86/syscalls/inotify_rm_watch.S
+++ b/libc/arch-x86/syscalls/inotify_rm_watch.S
@@ -19,7 +19,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/ioprio_get.S b/libc/arch-x86/syscalls/ioprio_get.S
deleted file mode 100644
index ff78773..0000000
--- a/libc/arch-x86/syscalls/ioprio_get.S
+++ /dev/null
@@ -1,27 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(ioprio_get)
-    pushl   %ebx
-    .cfi_def_cfa_offset 8
-    .cfi_rel_offset ebx, 0
-    pushl   %ecx
-    .cfi_adjust_cfa_offset 4
-    .cfi_rel_offset ecx, 0
-    mov     12(%esp), %ebx
-    mov     16(%esp), %ecx
-    movl    $__NR_ioprio_get, %eax
-    int     $0x80
-    cmpl    $-MAX_ERRNO, %eax
-    jb      1f
-    negl    %eax
-    pushl   %eax
-    call    __set_errno
-    addl    $4, %esp
-    orl     $-1, %eax
-1:
-    popl    %ecx
-    popl    %ebx
-    ret
-END(ioprio_get)
diff --git a/libc/arch-x86/syscalls/ioprio_set.S b/libc/arch-x86/syscalls/ioprio_set.S
deleted file mode 100644
index 7a3e919..0000000
--- a/libc/arch-x86/syscalls/ioprio_set.S
+++ /dev/null
@@ -1,32 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(ioprio_set)
-    pushl   %ebx
-    .cfi_def_cfa_offset 8
-    .cfi_rel_offset ebx, 0
-    pushl   %ecx
-    .cfi_adjust_cfa_offset 4
-    .cfi_rel_offset ecx, 0
-    pushl   %edx
-    .cfi_adjust_cfa_offset 4
-    .cfi_rel_offset edx, 0
-    mov     16(%esp), %ebx
-    mov     20(%esp), %ecx
-    mov     24(%esp), %edx
-    movl    $__NR_ioprio_set, %eax
-    int     $0x80
-    cmpl    $-MAX_ERRNO, %eax
-    jb      1f
-    negl    %eax
-    pushl   %eax
-    call    __set_errno
-    addl    $4, %esp
-    orl     $-1, %eax
-1:
-    popl    %edx
-    popl    %ecx
-    popl    %ebx
-    ret
-END(ioprio_set)
diff --git a/libc/arch-x86/syscalls/kill.S b/libc/arch-x86/syscalls/kill.S
index fbf5fa8..0c1e24a 100644
--- a/libc/arch-x86/syscalls/kill.S
+++ b/libc/arch-x86/syscalls/kill.S
@@ -19,7 +19,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/klogctl.S b/libc/arch-x86/syscalls/klogctl.S
index 03f24b8..869324a 100644
--- a/libc/arch-x86/syscalls/klogctl.S
+++ b/libc/arch-x86/syscalls/klogctl.S
@@ -23,7 +23,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/lgetxattr.S b/libc/arch-x86/syscalls/lgetxattr.S
index 6ee2c55..3ed4f11 100644
--- a/libc/arch-x86/syscalls/lgetxattr.S
+++ b/libc/arch-x86/syscalls/lgetxattr.S
@@ -27,7 +27,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %esi
     popl    %edx
diff --git a/libc/arch-x86/syscalls/linkat.S b/libc/arch-x86/syscalls/linkat.S
index d9876eb..e0c7e5f 100644
--- a/libc/arch-x86/syscalls/linkat.S
+++ b/libc/arch-x86/syscalls/linkat.S
@@ -31,7 +31,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edi
     popl    %esi
diff --git a/libc/arch-x86/syscalls/listen.S b/libc/arch-x86/syscalls/listen.S
index b671b25..c65f970 100644
--- a/libc/arch-x86/syscalls/listen.S
+++ b/libc/arch-x86/syscalls/listen.S
@@ -20,7 +20,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/listxattr.S b/libc/arch-x86/syscalls/listxattr.S
index e86b82e..98a5114 100644
--- a/libc/arch-x86/syscalls/listxattr.S
+++ b/libc/arch-x86/syscalls/listxattr.S
@@ -23,7 +23,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/llistxattr.S b/libc/arch-x86/syscalls/llistxattr.S
index 8d13da8..a5ab636 100644
--- a/libc/arch-x86/syscalls/llistxattr.S
+++ b/libc/arch-x86/syscalls/llistxattr.S
@@ -23,7 +23,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/lremovexattr.S b/libc/arch-x86/syscalls/lremovexattr.S
index 9dab0a3..508abba 100644
--- a/libc/arch-x86/syscalls/lremovexattr.S
+++ b/libc/arch-x86/syscalls/lremovexattr.S
@@ -19,7 +19,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/lseek.S b/libc/arch-x86/syscalls/lseek.S
index 2d03f46..5f77831 100644
--- a/libc/arch-x86/syscalls/lseek.S
+++ b/libc/arch-x86/syscalls/lseek.S
@@ -23,7 +23,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/lsetxattr.S b/libc/arch-x86/syscalls/lsetxattr.S
index 1452298..d878684 100644
--- a/libc/arch-x86/syscalls/lsetxattr.S
+++ b/libc/arch-x86/syscalls/lsetxattr.S
@@ -31,7 +31,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edi
     popl    %esi
diff --git a/libc/arch-x86/syscalls/madvise.S b/libc/arch-x86/syscalls/madvise.S
index fd4af11..3e8c7fd 100644
--- a/libc/arch-x86/syscalls/madvise.S
+++ b/libc/arch-x86/syscalls/madvise.S
@@ -23,7 +23,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/mincore.S b/libc/arch-x86/syscalls/mincore.S
index 01eb519..7096f6c 100644
--- a/libc/arch-x86/syscalls/mincore.S
+++ b/libc/arch-x86/syscalls/mincore.S
@@ -23,7 +23,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/mkdirat.S b/libc/arch-x86/syscalls/mkdirat.S
index b022838..862a18c 100644
--- a/libc/arch-x86/syscalls/mkdirat.S
+++ b/libc/arch-x86/syscalls/mkdirat.S
@@ -23,7 +23,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/mknodat.S b/libc/arch-x86/syscalls/mknodat.S
index 233c0b2..e03ba42 100644
--- a/libc/arch-x86/syscalls/mknodat.S
+++ b/libc/arch-x86/syscalls/mknodat.S
@@ -27,7 +27,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %esi
     popl    %edx
diff --git a/libc/arch-x86/syscalls/mlock.S b/libc/arch-x86/syscalls/mlock.S
index fb4641f..f582f77 100644
--- a/libc/arch-x86/syscalls/mlock.S
+++ b/libc/arch-x86/syscalls/mlock.S
@@ -19,7 +19,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/mlockall.S b/libc/arch-x86/syscalls/mlockall.S
index 9403351..becca81 100644
--- a/libc/arch-x86/syscalls/mlockall.S
+++ b/libc/arch-x86/syscalls/mlockall.S
@@ -15,7 +15,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/mount.S b/libc/arch-x86/syscalls/mount.S
index d99f5f4..7be2811 100644
--- a/libc/arch-x86/syscalls/mount.S
+++ b/libc/arch-x86/syscalls/mount.S
@@ -31,7 +31,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edi
     popl    %esi
diff --git a/libc/arch-x86/syscalls/mprotect.S b/libc/arch-x86/syscalls/mprotect.S
index 3205f83..0516c45 100644
--- a/libc/arch-x86/syscalls/mprotect.S
+++ b/libc/arch-x86/syscalls/mprotect.S
@@ -23,7 +23,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/mremap.S b/libc/arch-x86/syscalls/mremap.S
index 2b20079..42e75ce 100644
--- a/libc/arch-x86/syscalls/mremap.S
+++ b/libc/arch-x86/syscalls/mremap.S
@@ -27,7 +27,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %esi
     popl    %edx
diff --git a/libc/arch-x86/syscalls/msync.S b/libc/arch-x86/syscalls/msync.S
index 339e381..66722f2 100644
--- a/libc/arch-x86/syscalls/msync.S
+++ b/libc/arch-x86/syscalls/msync.S
@@ -23,7 +23,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/munlock.S b/libc/arch-x86/syscalls/munlock.S
index 5fb29cb..2fc3aa7 100644
--- a/libc/arch-x86/syscalls/munlock.S
+++ b/libc/arch-x86/syscalls/munlock.S
@@ -19,7 +19,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/munlockall.S b/libc/arch-x86/syscalls/munlockall.S
index 238f812..1bc99ea 100644
--- a/libc/arch-x86/syscalls/munlockall.S
+++ b/libc/arch-x86/syscalls/munlockall.S
@@ -11,7 +11,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     ret
 END(munlockall)
diff --git a/libc/arch-x86/syscalls/munmap.S b/libc/arch-x86/syscalls/munmap.S
index 2d348db..878aae7 100644
--- a/libc/arch-x86/syscalls/munmap.S
+++ b/libc/arch-x86/syscalls/munmap.S
@@ -19,7 +19,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/nanosleep.S b/libc/arch-x86/syscalls/nanosleep.S
index 9d8ae9d..fe8af90 100644
--- a/libc/arch-x86/syscalls/nanosleep.S
+++ b/libc/arch-x86/syscalls/nanosleep.S
@@ -19,7 +19,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/personality.S b/libc/arch-x86/syscalls/personality.S
index 412bbed..8c8e0ff 100644
--- a/libc/arch-x86/syscalls/personality.S
+++ b/libc/arch-x86/syscalls/personality.S
@@ -15,7 +15,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/pipe2.S b/libc/arch-x86/syscalls/pipe2.S
index bfe03a2..99c4e8b 100644
--- a/libc/arch-x86/syscalls/pipe2.S
+++ b/libc/arch-x86/syscalls/pipe2.S
@@ -19,7 +19,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/prctl.S b/libc/arch-x86/syscalls/prctl.S
index fca343f..63ec899 100644
--- a/libc/arch-x86/syscalls/prctl.S
+++ b/libc/arch-x86/syscalls/prctl.S
@@ -31,7 +31,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edi
     popl    %esi
diff --git a/libc/arch-x86/syscalls/pread64.S b/libc/arch-x86/syscalls/pread64.S
index 6cf4e4b..6b3c8ad 100644
--- a/libc/arch-x86/syscalls/pread64.S
+++ b/libc/arch-x86/syscalls/pread64.S
@@ -31,7 +31,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edi
     popl    %esi
diff --git a/libc/arch-x86/syscalls/prlimit64.S b/libc/arch-x86/syscalls/prlimit64.S
index 65316a7..6aa875f 100644
--- a/libc/arch-x86/syscalls/prlimit64.S
+++ b/libc/arch-x86/syscalls/prlimit64.S
@@ -27,7 +27,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %esi
     popl    %edx
diff --git a/libc/arch-x86/syscalls/pwrite64.S b/libc/arch-x86/syscalls/pwrite64.S
index cccea8b..7d53095 100644
--- a/libc/arch-x86/syscalls/pwrite64.S
+++ b/libc/arch-x86/syscalls/pwrite64.S
@@ -31,7 +31,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edi
     popl    %esi
diff --git a/libc/arch-x86/syscalls/read.S b/libc/arch-x86/syscalls/read.S
index f80db31..9814c8f 100644
--- a/libc/arch-x86/syscalls/read.S
+++ b/libc/arch-x86/syscalls/read.S
@@ -23,7 +23,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/readahead.S b/libc/arch-x86/syscalls/readahead.S
index f53769a..49a17d0 100644
--- a/libc/arch-x86/syscalls/readahead.S
+++ b/libc/arch-x86/syscalls/readahead.S
@@ -27,7 +27,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %esi
     popl    %edx
diff --git a/libc/arch-x86/syscalls/readlinkat.S b/libc/arch-x86/syscalls/readlinkat.S
index 229dafe..1a161c0 100644
--- a/libc/arch-x86/syscalls/readlinkat.S
+++ b/libc/arch-x86/syscalls/readlinkat.S
@@ -27,7 +27,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %esi
     popl    %edx
diff --git a/libc/arch-x86/syscalls/readv.S b/libc/arch-x86/syscalls/readv.S
index 8cb01a0..8b5ff41 100644
--- a/libc/arch-x86/syscalls/readv.S
+++ b/libc/arch-x86/syscalls/readv.S
@@ -23,7 +23,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/recvfrom.S b/libc/arch-x86/syscalls/recvfrom.S
index dd99a09..53d08f6 100644
--- a/libc/arch-x86/syscalls/recvfrom.S
+++ b/libc/arch-x86/syscalls/recvfrom.S
@@ -20,7 +20,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/recvmmsg.S b/libc/arch-x86/syscalls/recvmmsg.S
index f916fcd..3ef8740 100644
--- a/libc/arch-x86/syscalls/recvmmsg.S
+++ b/libc/arch-x86/syscalls/recvmmsg.S
@@ -20,7 +20,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/recvmsg.S b/libc/arch-x86/syscalls/recvmsg.S
index 12dad28..150672d 100644
--- a/libc/arch-x86/syscalls/recvmsg.S
+++ b/libc/arch-x86/syscalls/recvmsg.S
@@ -20,7 +20,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/removexattr.S b/libc/arch-x86/syscalls/removexattr.S
index 3974a07..e7c55eb 100644
--- a/libc/arch-x86/syscalls/removexattr.S
+++ b/libc/arch-x86/syscalls/removexattr.S
@@ -19,7 +19,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/renameat.S b/libc/arch-x86/syscalls/renameat.S
index 2982f51..5dfe65f 100644
--- a/libc/arch-x86/syscalls/renameat.S
+++ b/libc/arch-x86/syscalls/renameat.S
@@ -27,7 +27,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %esi
     popl    %edx
diff --git a/libc/arch-x86/syscalls/sched_get_priority_max.S b/libc/arch-x86/syscalls/sched_get_priority_max.S
index 3205c72..d8debe2 100644
--- a/libc/arch-x86/syscalls/sched_get_priority_max.S
+++ b/libc/arch-x86/syscalls/sched_get_priority_max.S
@@ -15,7 +15,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/sched_get_priority_min.S b/libc/arch-x86/syscalls/sched_get_priority_min.S
index 39c4d2c..e9689fa 100644
--- a/libc/arch-x86/syscalls/sched_get_priority_min.S
+++ b/libc/arch-x86/syscalls/sched_get_priority_min.S
@@ -15,7 +15,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/sched_getparam.S b/libc/arch-x86/syscalls/sched_getparam.S
index 47cb4af..6b5e7c8 100644
--- a/libc/arch-x86/syscalls/sched_getparam.S
+++ b/libc/arch-x86/syscalls/sched_getparam.S
@@ -19,7 +19,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/sched_getscheduler.S b/libc/arch-x86/syscalls/sched_getscheduler.S
index 07fbe6b..a2c5746 100644
--- a/libc/arch-x86/syscalls/sched_getscheduler.S
+++ b/libc/arch-x86/syscalls/sched_getscheduler.S
@@ -15,7 +15,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/sched_rr_get_interval.S b/libc/arch-x86/syscalls/sched_rr_get_interval.S
index e7a1038..f8012f3 100644
--- a/libc/arch-x86/syscalls/sched_rr_get_interval.S
+++ b/libc/arch-x86/syscalls/sched_rr_get_interval.S
@@ -19,7 +19,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/sched_setaffinity.S b/libc/arch-x86/syscalls/sched_setaffinity.S
index bb35259..76013f9 100644
--- a/libc/arch-x86/syscalls/sched_setaffinity.S
+++ b/libc/arch-x86/syscalls/sched_setaffinity.S
@@ -23,7 +23,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/sched_setparam.S b/libc/arch-x86/syscalls/sched_setparam.S
index 3e93c4c..aca4bd9 100644
--- a/libc/arch-x86/syscalls/sched_setparam.S
+++ b/libc/arch-x86/syscalls/sched_setparam.S
@@ -19,7 +19,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/sched_setscheduler.S b/libc/arch-x86/syscalls/sched_setscheduler.S
index fcabf12..fad72c6 100644
--- a/libc/arch-x86/syscalls/sched_setscheduler.S
+++ b/libc/arch-x86/syscalls/sched_setscheduler.S
@@ -23,7 +23,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/sched_yield.S b/libc/arch-x86/syscalls/sched_yield.S
index a8b22e3..8b4a9be 100644
--- a/libc/arch-x86/syscalls/sched_yield.S
+++ b/libc/arch-x86/syscalls/sched_yield.S
@@ -15,7 +15,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/sendfile.S b/libc/arch-x86/syscalls/sendfile.S
index 30bf3ad..7bd86d0 100644
--- a/libc/arch-x86/syscalls/sendfile.S
+++ b/libc/arch-x86/syscalls/sendfile.S
@@ -27,7 +27,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %esi
     popl    %edx
diff --git a/libc/arch-x86/syscalls/sendfile64.S b/libc/arch-x86/syscalls/sendfile64.S
index 5a7f2bb..bd76043 100644
--- a/libc/arch-x86/syscalls/sendfile64.S
+++ b/libc/arch-x86/syscalls/sendfile64.S
@@ -27,7 +27,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %esi
     popl    %edx
diff --git a/libc/arch-x86/syscalls/sendmmsg.S b/libc/arch-x86/syscalls/sendmmsg.S
index 09a3292..4bc3c40 100644
--- a/libc/arch-x86/syscalls/sendmmsg.S
+++ b/libc/arch-x86/syscalls/sendmmsg.S
@@ -20,7 +20,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/sendmsg.S b/libc/arch-x86/syscalls/sendmsg.S
index eaf7fb3..eb8fc63 100644
--- a/libc/arch-x86/syscalls/sendmsg.S
+++ b/libc/arch-x86/syscalls/sendmsg.S
@@ -20,7 +20,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/sendto.S b/libc/arch-x86/syscalls/sendto.S
index 0cf5e0a..8cb72c8 100644
--- a/libc/arch-x86/syscalls/sendto.S
+++ b/libc/arch-x86/syscalls/sendto.S
@@ -20,7 +20,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/setgid.S b/libc/arch-x86/syscalls/setgid.S
index b0b7185..baa1b1a 100644
--- a/libc/arch-x86/syscalls/setgid.S
+++ b/libc/arch-x86/syscalls/setgid.S
@@ -15,7 +15,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/setgroups.S b/libc/arch-x86/syscalls/setgroups.S
index be227ca..364aaad 100644
--- a/libc/arch-x86/syscalls/setgroups.S
+++ b/libc/arch-x86/syscalls/setgroups.S
@@ -19,7 +19,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/setitimer.S b/libc/arch-x86/syscalls/setitimer.S
index 4a323da..409c4c6 100644
--- a/libc/arch-x86/syscalls/setitimer.S
+++ b/libc/arch-x86/syscalls/setitimer.S
@@ -23,7 +23,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/setns.S b/libc/arch-x86/syscalls/setns.S
index fa69b4a..ddbe758 100644
--- a/libc/arch-x86/syscalls/setns.S
+++ b/libc/arch-x86/syscalls/setns.S
@@ -19,7 +19,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/setpgid.S b/libc/arch-x86/syscalls/setpgid.S
index eba780c..ac1b12d 100644
--- a/libc/arch-x86/syscalls/setpgid.S
+++ b/libc/arch-x86/syscalls/setpgid.S
@@ -19,7 +19,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/setpriority.S b/libc/arch-x86/syscalls/setpriority.S
index 5ea0519..93c1e07 100644
--- a/libc/arch-x86/syscalls/setpriority.S
+++ b/libc/arch-x86/syscalls/setpriority.S
@@ -23,7 +23,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/setregid.S b/libc/arch-x86/syscalls/setregid.S
index ae5bfca..0ecfa9a 100644
--- a/libc/arch-x86/syscalls/setregid.S
+++ b/libc/arch-x86/syscalls/setregid.S
@@ -19,7 +19,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/setresgid.S b/libc/arch-x86/syscalls/setresgid.S
index 64b5f7e..a6914c4 100644
--- a/libc/arch-x86/syscalls/setresgid.S
+++ b/libc/arch-x86/syscalls/setresgid.S
@@ -23,7 +23,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/setresuid.S b/libc/arch-x86/syscalls/setresuid.S
index 2a29fa5..c33c1ca 100644
--- a/libc/arch-x86/syscalls/setresuid.S
+++ b/libc/arch-x86/syscalls/setresuid.S
@@ -23,7 +23,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/setreuid.S b/libc/arch-x86/syscalls/setreuid.S
index 200a83a..4244988 100644
--- a/libc/arch-x86/syscalls/setreuid.S
+++ b/libc/arch-x86/syscalls/setreuid.S
@@ -19,7 +19,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/setrlimit.S b/libc/arch-x86/syscalls/setrlimit.S
index 64a46c0..3e86504 100644
--- a/libc/arch-x86/syscalls/setrlimit.S
+++ b/libc/arch-x86/syscalls/setrlimit.S
@@ -19,7 +19,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/setsid.S b/libc/arch-x86/syscalls/setsid.S
index 382ad0c..398c110 100644
--- a/libc/arch-x86/syscalls/setsid.S
+++ b/libc/arch-x86/syscalls/setsid.S
@@ -11,7 +11,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     ret
 END(setsid)
diff --git a/libc/arch-x86/syscalls/setsockopt.S b/libc/arch-x86/syscalls/setsockopt.S
index e57c9d2..6ef168f 100644
--- a/libc/arch-x86/syscalls/setsockopt.S
+++ b/libc/arch-x86/syscalls/setsockopt.S
@@ -20,7 +20,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/settimeofday.S b/libc/arch-x86/syscalls/settimeofday.S
index 4b2eca9..37e11c5 100644
--- a/libc/arch-x86/syscalls/settimeofday.S
+++ b/libc/arch-x86/syscalls/settimeofday.S
@@ -19,7 +19,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/setuid.S b/libc/arch-x86/syscalls/setuid.S
index cf10ad6..fcea66d 100644
--- a/libc/arch-x86/syscalls/setuid.S
+++ b/libc/arch-x86/syscalls/setuid.S
@@ -15,7 +15,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/setxattr.S b/libc/arch-x86/syscalls/setxattr.S
index 5edba2d..d6473cd 100644
--- a/libc/arch-x86/syscalls/setxattr.S
+++ b/libc/arch-x86/syscalls/setxattr.S
@@ -31,7 +31,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edi
     popl    %esi
diff --git a/libc/arch-x86/syscalls/shutdown.S b/libc/arch-x86/syscalls/shutdown.S
index f1d606a..32fa17a 100644
--- a/libc/arch-x86/syscalls/shutdown.S
+++ b/libc/arch-x86/syscalls/shutdown.S
@@ -20,7 +20,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/sigaltstack.S b/libc/arch-x86/syscalls/sigaltstack.S
index 64872df..6882a78 100644
--- a/libc/arch-x86/syscalls/sigaltstack.S
+++ b/libc/arch-x86/syscalls/sigaltstack.S
@@ -19,7 +19,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/socketpair.S b/libc/arch-x86/syscalls/socketpair.S
index 4027752..945faa0 100644
--- a/libc/arch-x86/syscalls/socketpair.S
+++ b/libc/arch-x86/syscalls/socketpair.S
@@ -20,7 +20,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/splice.S b/libc/arch-x86/syscalls/splice.S
new file mode 100644
index 0000000..46e2312
--- /dev/null
+++ b/libc/arch-x86/syscalls/splice.S
@@ -0,0 +1,46 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(splice)
+    pushl   %ebx
+    .cfi_def_cfa_offset 8
+    .cfi_rel_offset ebx, 0
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
+    pushl   %esi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset esi, 0
+    pushl   %edi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edi, 0
+    pushl   %ebp
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ebp, 0
+    mov     28(%esp), %ebx
+    mov     32(%esp), %ecx
+    mov     36(%esp), %edx
+    mov     40(%esp), %esi
+    mov     44(%esp), %edi
+    mov     48(%esp), %ebp
+    movl    $__NR_splice, %eax
+    int     $0x80
+    cmpl    $-MAX_ERRNO, %eax
+    jb      1f
+    negl    %eax
+    pushl   %eax
+    call    __set_errno
+    addl    $4, %esp
+1:
+    popl    %ebp
+    popl    %edi
+    popl    %esi
+    popl    %edx
+    popl    %ecx
+    popl    %ebx
+    ret
+END(splice)
diff --git a/libc/arch-x86/syscalls/swapoff.S b/libc/arch-x86/syscalls/swapoff.S
index 1657e64..0e21033 100644
--- a/libc/arch-x86/syscalls/swapoff.S
+++ b/libc/arch-x86/syscalls/swapoff.S
@@ -15,7 +15,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/swapon.S b/libc/arch-x86/syscalls/swapon.S
index 16d0617..a4d5e03 100644
--- a/libc/arch-x86/syscalls/swapon.S
+++ b/libc/arch-x86/syscalls/swapon.S
@@ -19,7 +19,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/symlinkat.S b/libc/arch-x86/syscalls/symlinkat.S
index 78f9fa7..618f5d8 100644
--- a/libc/arch-x86/syscalls/symlinkat.S
+++ b/libc/arch-x86/syscalls/symlinkat.S
@@ -23,7 +23,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/sync.S b/libc/arch-x86/syscalls/sync.S
index a0cf66f..a1f1782 100644
--- a/libc/arch-x86/syscalls/sync.S
+++ b/libc/arch-x86/syscalls/sync.S
@@ -15,7 +15,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/sysinfo.S b/libc/arch-x86/syscalls/sysinfo.S
index 1619edb..c3eabb0 100644
--- a/libc/arch-x86/syscalls/sysinfo.S
+++ b/libc/arch-x86/syscalls/sysinfo.S
@@ -15,7 +15,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/getdents.S b/libc/arch-x86/syscalls/tee.S
similarity index 67%
copy from libc/arch-x86/syscalls/getdents.S
copy to libc/arch-x86/syscalls/tee.S
index 0b045b2..9422660 100644
--- a/libc/arch-x86/syscalls/getdents.S
+++ b/libc/arch-x86/syscalls/tee.S
@@ -2,7 +2,7 @@
 
 #include <private/bionic_asm.h>
 
-ENTRY(getdents)
+ENTRY(tee)
     pushl   %ebx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
@@ -12,10 +12,14 @@
     pushl   %edx
     .cfi_adjust_cfa_offset 4
     .cfi_rel_offset edx, 0
-    mov     16(%esp), %ebx
-    mov     20(%esp), %ecx
-    mov     24(%esp), %edx
-    movl    $__NR_getdents64, %eax
+    pushl   %esi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset esi, 0
+    mov     20(%esp), %ebx
+    mov     24(%esp), %ecx
+    mov     28(%esp), %edx
+    mov     32(%esp), %esi
+    movl    $__NR_tee, %eax
     int     $0x80
     cmpl    $-MAX_ERRNO, %eax
     jb      1f
@@ -23,10 +27,10 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
+    popl    %esi
     popl    %edx
     popl    %ecx
     popl    %ebx
     ret
-END(getdents)
+END(tee)
diff --git a/libc/arch-x86/syscalls/tgkill.S b/libc/arch-x86/syscalls/tgkill.S
index 69ffdf8..385827b 100644
--- a/libc/arch-x86/syscalls/tgkill.S
+++ b/libc/arch-x86/syscalls/tgkill.S
@@ -23,7 +23,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/timerfd_create.S b/libc/arch-x86/syscalls/timerfd_create.S
index c0bc5b5..343195e 100644
--- a/libc/arch-x86/syscalls/timerfd_create.S
+++ b/libc/arch-x86/syscalls/timerfd_create.S
@@ -19,7 +19,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/timerfd_gettime.S b/libc/arch-x86/syscalls/timerfd_gettime.S
index 5dd7ad7..9b3a314 100644
--- a/libc/arch-x86/syscalls/timerfd_gettime.S
+++ b/libc/arch-x86/syscalls/timerfd_gettime.S
@@ -19,7 +19,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/timerfd_settime.S b/libc/arch-x86/syscalls/timerfd_settime.S
index bb027df..819b723 100644
--- a/libc/arch-x86/syscalls/timerfd_settime.S
+++ b/libc/arch-x86/syscalls/timerfd_settime.S
@@ -27,7 +27,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %esi
     popl    %edx
diff --git a/libc/arch-x86/syscalls/times.S b/libc/arch-x86/syscalls/times.S
index 075750d..f5739d3 100644
--- a/libc/arch-x86/syscalls/times.S
+++ b/libc/arch-x86/syscalls/times.S
@@ -15,7 +15,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/truncate.S b/libc/arch-x86/syscalls/truncate.S
index 9270a53..427f95f 100644
--- a/libc/arch-x86/syscalls/truncate.S
+++ b/libc/arch-x86/syscalls/truncate.S
@@ -19,7 +19,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/truncate64.S b/libc/arch-x86/syscalls/truncate64.S
index 89c2c4a..2c49751 100644
--- a/libc/arch-x86/syscalls/truncate64.S
+++ b/libc/arch-x86/syscalls/truncate64.S
@@ -23,7 +23,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/umask.S b/libc/arch-x86/syscalls/umask.S
index 81df64d..3affc8d 100644
--- a/libc/arch-x86/syscalls/umask.S
+++ b/libc/arch-x86/syscalls/umask.S
@@ -15,7 +15,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/umount2.S b/libc/arch-x86/syscalls/umount2.S
index cd21623..d2b3549 100644
--- a/libc/arch-x86/syscalls/umount2.S
+++ b/libc/arch-x86/syscalls/umount2.S
@@ -19,7 +19,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/uname.S b/libc/arch-x86/syscalls/uname.S
index 9d65e85..e996805 100644
--- a/libc/arch-x86/syscalls/uname.S
+++ b/libc/arch-x86/syscalls/uname.S
@@ -15,7 +15,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/unlinkat.S b/libc/arch-x86/syscalls/unlinkat.S
index 68bf05b..6417d2b 100644
--- a/libc/arch-x86/syscalls/unlinkat.S
+++ b/libc/arch-x86/syscalls/unlinkat.S
@@ -23,7 +23,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/unshare.S b/libc/arch-x86/syscalls/unshare.S
index 7e48cb1..a289d4d 100644
--- a/libc/arch-x86/syscalls/unshare.S
+++ b/libc/arch-x86/syscalls/unshare.S
@@ -15,7 +15,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/utimensat.S b/libc/arch-x86/syscalls/utimensat.S
index 4b2a9b6..d8c9080 100644
--- a/libc/arch-x86/syscalls/utimensat.S
+++ b/libc/arch-x86/syscalls/utimensat.S
@@ -27,7 +27,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %esi
     popl    %edx
diff --git a/libc/arch-x86/syscalls/getdents.S b/libc/arch-x86/syscalls/vmsplice.S
similarity index 65%
copy from libc/arch-x86/syscalls/getdents.S
copy to libc/arch-x86/syscalls/vmsplice.S
index 0b045b2..2afba60 100644
--- a/libc/arch-x86/syscalls/getdents.S
+++ b/libc/arch-x86/syscalls/vmsplice.S
@@ -2,7 +2,7 @@
 
 #include <private/bionic_asm.h>
 
-ENTRY(getdents)
+ENTRY(vmsplice)
     pushl   %ebx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
@@ -12,10 +12,14 @@
     pushl   %edx
     .cfi_adjust_cfa_offset 4
     .cfi_rel_offset edx, 0
-    mov     16(%esp), %ebx
-    mov     20(%esp), %ecx
-    mov     24(%esp), %edx
-    movl    $__NR_getdents64, %eax
+    pushl   %esi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset esi, 0
+    mov     20(%esp), %ebx
+    mov     24(%esp), %ecx
+    mov     28(%esp), %edx
+    mov     32(%esp), %esi
+    movl    $__NR_vmsplice, %eax
     int     $0x80
     cmpl    $-MAX_ERRNO, %eax
     jb      1f
@@ -23,10 +27,10 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
+    popl    %esi
     popl    %edx
     popl    %ecx
     popl    %ebx
     ret
-END(getdents)
+END(vmsplice)
diff --git a/libc/arch-x86/syscalls/wait4.S b/libc/arch-x86/syscalls/wait4.S
index bd4bd50..fda75c0 100644
--- a/libc/arch-x86/syscalls/wait4.S
+++ b/libc/arch-x86/syscalls/wait4.S
@@ -27,7 +27,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %esi
     popl    %edx
diff --git a/libc/arch-x86/syscalls/write.S b/libc/arch-x86/syscalls/write.S
index a464196..115974e 100644
--- a/libc/arch-x86/syscalls/write.S
+++ b/libc/arch-x86/syscalls/write.S
@@ -23,7 +23,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/writev.S b/libc/arch-x86/syscalls/writev.S
index da9ae7c..77e5cd1 100644
--- a/libc/arch-x86/syscalls/writev.S
+++ b/libc/arch-x86/syscalls/writev.S
@@ -23,7 +23,6 @@
     pushl   %eax
     call    __set_errno
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/x86.mk b/libc/arch-x86/x86.mk
index d13a934..8aa2645 100644
--- a/libc/arch-x86/x86.mk
+++ b/libc/arch-x86/x86.mk
@@ -5,6 +5,7 @@
     bionic/legacy_32_bit_support.cpp \
     bionic/ndk_cruft.cpp \
     bionic/time64.c \
+    upstream-openbsd/lib/libc/stdio/putw.c \
 
 # Fortify implementations of libc functions.
 libc_common_src_files_x86 += \
@@ -30,7 +31,6 @@
     arch-x86/bionic/__set_tls.c \
     arch-x86/bionic/sigsetjmp.S \
     arch-x86/bionic/syscall.S \
-    arch-x86/bionic/vfork.S \
 
 ## ARCH variant specific source files
 arch_variant_mk := $(LOCAL_PATH)/arch-x86/$(TARGET_ARCH_VARIANT)/$(TARGET_ARCH_VARIANT).mk
@@ -40,6 +40,9 @@
 include $(arch_variant_mk)
 libc_common_additional_dependencies += $(arch_variant_mk)
 
+libc_netbsd_src_files_x86 := \
+    upstream-netbsd/common/lib/libc/hash/sha1/sha1.c \
+
 arch_variant_mk :=
 
 libc_crt_target_cflags_x86 := \
diff --git a/libc/arch-x86_64/bionic/__bionic_clone.S b/libc/arch-x86_64/bionic/__bionic_clone.S
index db7d05c..e0ce5a6 100644
--- a/libc/arch-x86_64/bionic/__bionic_clone.S
+++ b/libc/arch-x86_64/bionic/__bionic_clone.S
@@ -45,26 +45,33 @@
         # Make the system call.
         movl    $__NR_clone, %eax
         syscall
-        testl   %eax, %eax
-        jns     1f
+
+        # Check result.
+        testq   %rax, %rax
+        jz      .L_bc_child
+        jg      .L_bc_parent
 
         # An error occurred, set errno and return -1.
         negl    %eax
         movl    %eax, %edi
         call    __set_errno
-        orl     $-1, %eax
-        jmp     2f
-1:
-        jnz     2f
+        ret
 
-        # We're in the child now, so call __bionic_clone_entry
+.L_bc_child:
+        # We don't want anyone to unwind past this point.
+        .cfi_undefined %rip
+        .cfi_undefined %rbp
+
+        # We're in the child now, so call __start_thread
         # with the arguments from the child stack moved into
         # the appropriate registers.
         popq    %rdi  # fn
         popq    %rsi  # arg
-        call    __bionic_clone_entry
+        call    __start_thread
         hlt
-2:
+
+.L_bc_parent:
+        # We're the parent; nothing to do.
         ret
 END(__bionic_clone)
 .hidden __bionic_clone
diff --git a/libc/arch-x86_64/bionic/syscall.S b/libc/arch-x86_64/bionic/syscall.S
index a98a436..d5694cb 100644
--- a/libc/arch-x86_64/bionic/syscall.S
+++ b/libc/arch-x86_64/bionic/syscall.S
@@ -58,7 +58,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(syscall)
diff --git a/libc/arch-x86_64/bionic/vfork.S b/libc/arch-x86_64/bionic/vfork.S
deleted file mode 100644
index b323f30..0000000
--- a/libc/arch-x86_64/bionic/vfork.S
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (C) 2013 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_asm.h>
-
-// This custom code preserves the return address across the system call.
-
-ENTRY(vfork)
-  popq    %rdi  // Grab the return address.
-  movl    $__NR_vfork, %eax
-  syscall
-  pushq   %rdi  // Restore the return address.
-  cmpq    $-MAX_ERRNO, %rax
-  jb      1f
-  negl    %eax
-  movl    %eax, %edi
-  call    __set_errno
-  orq     $-1, %rax
-1:
-  ret
-END(vfork)
diff --git a/libc/arch-x86_64/string/sse2-memmove-slm.S b/libc/arch-x86_64/string/sse2-memmove-slm.S
index ee8440e..0dbffad 100644
--- a/libc/arch-x86_64/string/sse2-memmove-slm.S
+++ b/libc/arch-x86_64/string/sse2-memmove-slm.S
@@ -99,7 +99,7 @@
 /* Check whether we should copy backward or forward.  */
 	cmp	%rsi, %rdi
 	je	L(mm_return)
-	ja	L(mm_len_0_or_more_backward)
+	jg	L(mm_len_0_or_more_backward)
 
 /* Now do checks for lengths. We do [0..16], [0..32], [0..64], [0..128]
 	separately.  */
@@ -107,7 +107,7 @@
 	jbe	L(mm_len_0_16_bytes_forward)
 
 	cmp	$32, %rdx
-	jg	L(mm_len_32_or_more_forward)
+	ja	L(mm_len_32_or_more_forward)
 
 /* Copy [0..32] and return.  */
 	movdqu	(%rsi), %xmm0
@@ -118,7 +118,7 @@
 
 L(mm_len_32_or_more_forward):
 	cmp	$64, %rdx
-	jg	L(mm_len_64_or_more_forward)
+	ja	L(mm_len_64_or_more_forward)
 
 /* Copy [0..64] and return.  */
 	movdqu	(%rsi), %xmm0
@@ -133,7 +133,7 @@
 
 L(mm_len_64_or_more_forward):
 	cmp	$128, %rdx
-	jg	L(mm_len_128_or_more_forward)
+	ja	L(mm_len_128_or_more_forward)
 
 /* Copy [0..128] and return.  */
 	movdqu	(%rsi), %xmm0
@@ -155,13 +155,6 @@
 	jmp	L(mm_return)
 
 L(mm_len_128_or_more_forward):
-
-	cmp	$SHARED_CACHE_SIZE_HALF, %rdx
-	jae	L(mm_large_page_forward)
-
-	mov	%rsi, %r8  // copy src to r8
-	mov	%rdi, %r9  // copy dst to r9
-
 /* Aligning the address of destination.  */
 /*  save first unaligned 64 bytes */
 	movdqu	(%rsi), %xmm0
@@ -169,56 +162,57 @@
 	movdqu	32(%rsi), %xmm2
 	movdqu	48(%rsi), %xmm3
 
-	lea	64(%r9), %rdi
-	and	$-64, %rdi  /* rdi now aligned to next 64 byte boundary */
+	lea	64(%rdi), %r8
+	and	$-64, %r8  /* r8 now aligned to next 64 byte boundary */
+	sub	%rdi, %rsi /* rsi = src - dst = diff */
 
-	sub	%r9, %rsi /* rsi = src - dst = diff */
+	movdqu	(%r8, %rsi), %xmm4
+	movdqu	16(%r8, %rsi), %xmm5
+	movdqu	32(%r8, %rsi), %xmm6
+	movdqu	48(%r8, %rsi), %xmm7
 
-	movdqu	(%rdi, %rsi), %xmm4
-	movdqu	16(%rdi, %rsi), %xmm5
-	movdqu	32(%rdi, %rsi), %xmm6
-	movdqu	48(%rdi, %rsi), %xmm7
+	movdqu	%xmm0, (%rdi)
+	movdqu	%xmm1, 16(%rdi)
+	movdqu	%xmm2, 32(%rdi)
+	movdqu	%xmm3, 48(%rdi)
+	movdqa	%xmm4, (%r8)
+	movaps	%xmm5, 16(%r8)
+	movaps	%xmm6, 32(%r8)
+	movaps	%xmm7, 48(%r8)
+	add	$64, %r8
 
-	movdqu	%xmm0, (%r9)
-	movdqu	%xmm1, 16(%r9)
-	movdqu	%xmm2, 32(%r9)
-	movdqu	%xmm3, 48(%r9)
-	movdqa	%xmm4, (%rdi)
-	movdqa	%xmm5, 16(%rdi)
-	movdqa	%xmm6, 32(%rdi)
-	movdqa	%xmm7, 48(%rdi)
-	add	$64, %rdi
-
-	lea	(%r9, %rdx), %rbx
+	lea	(%rdi, %rdx), %rbx
 	and	$-64, %rbx
-
-	cmp	%rdi, %rbx
+	cmp	%r8, %rbx
 	jbe	L(mm_copy_remaining_forward)
 
+	cmp	$SHARED_CACHE_SIZE_HALF, %rdx
+	jae	L(mm_large_page_loop_forward)
+
 	.p2align 4
 L(mm_main_loop_forward):
 
-	prefetcht0 128(%rdi, %rsi)
+	prefetcht0 128(%r8, %rsi)
 
-	movdqu	(%rdi, %rsi), %xmm0
-	movdqu	16(%rdi, %rsi), %xmm1
-	movdqu	32(%rdi, %rsi), %xmm2
-	movdqu	48(%rdi, %rsi), %xmm3
-	movdqa	%xmm0, (%rdi)
-	movdqa	%xmm1, 16(%rdi)
-	movdqa	%xmm2, 32(%rdi)
-	movdqa	%xmm3, 48(%rdi)
-	lea	64(%rdi), %rdi
-	cmp	%rdi, %rbx
+	movdqu	(%r8, %rsi), %xmm0
+	movdqu	16(%r8, %rsi), %xmm1
+	movdqu	32(%r8, %rsi), %xmm2
+	movdqu	48(%r8, %rsi), %xmm3
+	movdqa	%xmm0, (%r8)
+	movaps	%xmm1, 16(%r8)
+	movaps	%xmm2, 32(%r8)
+	movaps	%xmm3, 48(%r8)
+	lea	64(%r8), %r8
+	cmp	%r8, %rbx
 	ja	L(mm_main_loop_forward)
 
 L(mm_copy_remaining_forward):
-	add	%r9, %rdx
-	sub	%rdi, %rdx
+	add	%rdi, %rdx
+	sub	%r8, %rdx
 /* We copied all up till %rdi position in the dst.
 	In %rdx now is how many bytes are left to copy.
 	Now we need to advance %r8. */
-	lea	(%rdi, %rsi), %r8
+	lea	(%r8, %rsi), %r9
 
 L(mm_remaining_0_64_bytes_forward):
 	cmp	$32, %rdx
@@ -237,49 +231,49 @@
 	cmpb	$2, %dl
 	.p2align 4,,1
 	ja	L(mm_remaining_3_4_bytes_forward)
-	movzbl	-1(%r8,%rdx), %esi
-	movzbl	(%r8), %ebx
-	movb	%sil, -1(%rdi,%rdx)
-	movb	%bl, (%rdi)
+	movzbl	-1(%r9,%rdx), %esi
+	movzbl	(%r9), %ebx
+	movb	%sil, -1(%r8,%rdx)
+	movb	%bl, (%r8)
 	jmp	L(mm_return)
 
 L(mm_remaining_33_64_bytes_forward):
-	movdqu	(%r8), %xmm0
-	movdqu	16(%r8), %xmm1
-	movdqu	-32(%r8, %rdx), %xmm2
-	movdqu	-16(%r8, %rdx), %xmm3
-	movdqu	%xmm0, (%rdi)
-	movdqu	%xmm1, 16(%rdi)
-	movdqu	%xmm2, -32(%rdi, %rdx)
-	movdqu	%xmm3, -16(%rdi, %rdx)
+	movdqu	(%r9), %xmm0
+	movdqu	16(%r9), %xmm1
+	movdqu	-32(%r9, %rdx), %xmm2
+	movdqu	-16(%r9, %rdx), %xmm3
+	movdqu	%xmm0, (%r8)
+	movdqu	%xmm1, 16(%r8)
+	movdqu	%xmm2, -32(%r8, %rdx)
+	movdqu	%xmm3, -16(%r8, %rdx)
 	jmp	L(mm_return)
 
 L(mm_remaining_17_32_bytes_forward):
-	movdqu	(%r8), %xmm0
-	movdqu	-16(%r8, %rdx), %xmm1
-	movdqu	%xmm0, (%rdi)
-	movdqu	%xmm1, -16(%rdi, %rdx)
-	jmp	L(mm_return)
-
-L(mm_remaining_3_4_bytes_forward):
-	movzwl	-2(%r8,%rdx), %esi
-	movzwl	(%r8), %ebx
-	movw	%si, -2(%rdi,%rdx)
-	movw	%bx, (%rdi)
+	movdqu	(%r9), %xmm0
+	movdqu	-16(%r9, %rdx), %xmm1
+	movdqu	%xmm0, (%r8)
+	movdqu	%xmm1, -16(%r8, %rdx)
 	jmp	L(mm_return)
 
 L(mm_remaining_5_8_bytes_forward):
-	movl	(%r8), %esi
-	movl	-4(%r8,%rdx), %ebx
-	movl	%esi, (%rdi)
-	movl	%ebx, -4(%rdi,%rdx)
+	movl	(%r9), %esi
+	movl	-4(%r9,%rdx), %ebx
+	movl	%esi, (%r8)
+	movl	%ebx, -4(%r8,%rdx)
 	jmp	L(mm_return)
 
 L(mm_remaining_9_16_bytes_forward):
-	mov	(%r8), %rsi
-	mov	-8(%r8, %rdx), %rbx
-	mov	%rsi, (%rdi)
-	mov	%rbx, -8(%rdi, %rdx)
+	mov	(%r9), %rsi
+	mov	-8(%r9, %rdx), %rbx
+	mov	%rsi, (%r8)
+	mov	%rbx, -8(%r8, %rdx)
+	jmp	L(mm_return)
+
+L(mm_remaining_3_4_bytes_forward):
+	movzwl	-2(%r9,%rdx), %esi
+	movzwl	(%r9), %ebx
+	movw	%si, -2(%r8,%rdx)
+	movw	%bx, (%r8)
 	jmp	L(mm_return)
 
 L(mm_len_0_16_bytes_forward):
@@ -321,16 +315,21 @@
 	mov	%rsi, -8(%rdi, %rdx)
 	jmp	L(mm_return)
 
+L(mm_recalc_len):
+/* Compute in %rdx how many bytes are left to copy after
+	the main loop stops.  */
+	mov 	%rbx, %rdx
+	sub 	%rdi, %rdx
 /* The code for copying backwards.  */
 L(mm_len_0_or_more_backward):
 
-/* Now do checks for lengths. We do [0..16], [0..32], [0..64], [0..128]
+/* Now do checks for lengths. We do [0..16], [16..32], [32..64], [64..128]
 	separately.  */
 	cmp	$16, %rdx
 	jbe	L(mm_len_0_16_bytes_backward)
 
 	cmp	$32, %rdx
-	jg	L(mm_len_32_or_more_backward)
+	ja	L(mm_len_32_or_more_backward)
 
 /* Copy [0..32] and return.  */
 	movdqu	(%rsi), %xmm0
@@ -341,7 +340,7 @@
 
 L(mm_len_32_or_more_backward):
 	cmp	$64, %rdx
-	jg	L(mm_len_64_or_more_backward)
+	ja	L(mm_len_64_or_more_backward)
 
 /* Copy [0..64] and return.  */
 	movdqu	(%rsi), %xmm0
@@ -356,7 +355,7 @@
 
 L(mm_len_64_or_more_backward):
 	cmp	$128, %rdx
-	jg	L(mm_len_128_or_more_backward)
+	ja	L(mm_len_128_or_more_backward)
 
 /* Copy [0..128] and return.  */
 	movdqu	(%rsi), %xmm0
@@ -378,10 +377,6 @@
 	jmp	L(mm_return)
 
 L(mm_len_128_or_more_backward):
-
-	cmp	$SHARED_CACHE_SIZE_HALF, %rdx
-	jae	L(mm_large_page_backward)
-
 /* Aligning the address of destination. We need to save
 	16 bits from the source in order not to overwrite them.  */
 	movdqu	-16(%rsi, %rdx), %xmm0
@@ -405,22 +400,19 @@
 	movdqu	%xmm2, -48(%rdi, %rdx)
 	movdqu	%xmm3, -64(%rdi, %rdx)
 	movdqa	%xmm4, -16(%r9)
-	movdqa	%xmm5, -32(%r9)
-	movdqa	%xmm6, -48(%r9)
-	movdqa	%xmm7, -64(%r9)
+	movaps	%xmm5, -32(%r9)
+	movaps	%xmm6, -48(%r9)
+	movaps	%xmm7, -64(%r9)
 	lea	-64(%r9), %r9
 
 	lea	64(%rdi), %rbx
 	and	$-64, %rbx
 
-/* Compute in %rdx how many bytes are left to copy after
-	the main loop stops.  */
-	mov 	%rbx, %rdx
-	sub 	%rdi, %rdx
-
 	cmp	%r9, %rbx
-	jb	L(mm_main_loop_backward)
-	jmp	L(mm_len_0_or_more_backward)
+	jae	L(mm_recalc_len)
+
+	cmp	$SHARED_CACHE_SIZE_HALF, %rdx
+	jae	L(mm_large_page_loop_backward)
 
 	.p2align 4
 L(mm_main_loop_backward):
@@ -432,13 +424,13 @@
 	movdqu	-32(%r9, %r8), %xmm2
 	movdqu	-16(%r9, %r8), %xmm3
 	movdqa	%xmm0, -64(%r9)
-	movdqa	%xmm1, -48(%r9)
-	movdqa	%xmm2, -32(%r9)
-	movdqa	%xmm3, -16(%r9)
+	movaps	%xmm1, -48(%r9)
+	movaps	%xmm2, -32(%r9)
+	movaps	%xmm3, -16(%r9)
 	lea	-64(%r9), %r9
 	cmp	%r9, %rbx
 	jb	L(mm_main_loop_backward)
-	jmp	L(mm_len_0_or_more_backward)
+	jmp	L(mm_recalc_len)
 
 /* Copy [0..16] and return.  */
 L(mm_len_0_16_bytes_backward):
@@ -485,138 +477,23 @@
 
 /* Big length copy forward part.  */
 
-L(mm_large_page_forward):
-/* Aligning the address of destination. We need to save
-	16 bits from the source in order not to overwrite them.  */
-
-	mov	%rsi, %r8
-	mov	%rdi, %r9
-
-	movdqu	(%rsi), %xmm0
-	movdqu	16(%rsi), %xmm1
-	movdqu	32(%rsi), %xmm2
-	movdqu	48(%rsi), %xmm3
-
-	lea	64(%r9), %rdi
-	and	$-64, %rdi      /* rdi = aligned dst */
-
-	sub	%r9, %rsi        /* rsi = diff */
-
-	movdqu	(%rdi, %rsi), %xmm4
-	movdqu	16(%rdi, %rsi), %xmm5
-	movdqu	32(%rdi, %rsi), %xmm6
-	movdqu	48(%rdi, %rsi), %xmm7
-
-	movdqu	%xmm0, (%r9)
-	movdqu	%xmm1, 16(%r9)
-	movdqu	%xmm2, 32(%r9)
-	movdqu	%xmm3, 48(%r9)
-	movntdq	%xmm4, (%rdi)
-	movntdq	%xmm5, 16(%rdi)
-	movntdq	%xmm6, 32(%rdi)
-	movntdq	%xmm7, 48(%rdi)
-	add	$64, %rdi
-
-	lea	(%r9, %rdx), %rbx
-	and	$-128, %rbx
-
-	cmp	%rdi, %rbx
-	jbe	L(mm_copy_remaining_forward)
-
 	.p2align 4
 L(mm_large_page_loop_forward):
-	movdqu	(%rdi, %rsi), %xmm0
-	movdqu	16(%rdi, %rsi), %xmm1
-	movdqu	32(%rdi, %rsi), %xmm2
-	movdqu	48(%rdi, %rsi), %xmm3
-	movdqu	64(%rdi, %rsi), %xmm4
-	movdqu	80(%rdi, %rsi), %xmm5
-	movdqu	96(%rdi, %rsi), %xmm6
-	movdqu	112(%rdi, %rsi), %xmm7
-	movntdq	%xmm0, (%rdi)
-	movntdq	%xmm1, 16(%rdi)
-	movntdq	%xmm2, 32(%rdi)
-	movntdq	%xmm3, 48(%rdi)
-	movntdq	%xmm4, 64(%rdi)
-	movntdq	%xmm5, 80(%rdi)
-	movntdq	%xmm6, 96(%rdi)
-	movntdq	%xmm7, 112(%rdi)
-	lea 	128(%rdi), %rdi
-	cmp	%rdi, %rbx
+	movdqu	(%r8, %rsi), %xmm0
+	movdqu	16(%r8, %rsi), %xmm1
+	movdqu	32(%r8, %rsi), %xmm2
+	movdqu	48(%r8, %rsi), %xmm3
+	movntdq	%xmm0, (%r8)
+	movntdq	%xmm1, 16(%r8)
+	movntdq	%xmm2, 32(%r8)
+	movntdq	%xmm3, 48(%r8)
+	lea 	64(%r8), %r8
+	cmp	%r8, %rbx
 	ja	L(mm_large_page_loop_forward)
 	sfence
-
-	add 	%r9, %rdx
-	sub 	%rdi, %rdx
-/* We copied all up till %rdi position in the dst.
-	In %rdx now is how many bytes are left to copy.
-	Now we need to advance %r8. */
-	lea 	(%rdi, %rsi), %r8
-
-	cmp	$64, %rdx
-	jb	L(mm_remaining_0_64_bytes_forward)
-
-	movdqu	(%r8), %xmm0
-	movdqu	16(%r8), %xmm1
-	movdqu	32(%r8), %xmm2
-	movdqu	48(%r8), %xmm3
-	movdqu	-64(%r8, %rdx), %xmm4
-	movdqu	-48(%r8, %rdx), %xmm5
-	movdqu	-32(%r8, %rdx), %xmm6
-	movdqu	-16(%r8, %rdx), %xmm7
-	movdqu	%xmm0, (%rdi)
-	movdqu	%xmm1, 16(%rdi)
-	movdqu	%xmm2, 32(%rdi)
-	movdqu	%xmm3, 48(%rdi)
-	movdqu	%xmm4, -64(%rdi, %rdx)
-	movdqu	%xmm5, -48(%rdi, %rdx)
-	movdqu	%xmm6, -32(%rdi, %rdx)
-	movdqu	%xmm7, -16(%rdi, %rdx)
-	jmp	L(mm_return)
-
+	jmp	L(mm_copy_remaining_forward)
 
 /* Big length copy backward part.  */
-L(mm_large_page_backward):
-/* Aligning the address of destination. We need to save
-	16 bits from the source in order not to overwrite them.  */
-
-	movdqu	-16(%rsi, %rdx), %xmm0
-	movdqu	-32(%rsi, %rdx), %xmm1
-	movdqu	-48(%rsi, %rdx), %xmm2
-	movdqu	-64(%rsi, %rdx), %xmm3
-
-	lea	(%rdi, %rdx), %r9
-	and	$-64, %r9
-
-	mov 	%rsi, %r8
-	sub 	%rdi, %r8
-
-	movdqu	-16(%r9, %r8), %xmm4
-	movdqu	-32(%r9, %r8), %xmm5
-	movdqu	-48(%r9, %r8), %xmm6
-	movdqu	-64(%r9, %r8), %xmm7
-
-	movdqu	%xmm0, -16(%rdi, %rdx)
-	movdqu	%xmm1, -32(%rdi, %rdx)
-	movdqu	%xmm2, -48(%rdi, %rdx)
-	movdqu	%xmm3, -64(%rdi, %rdx)
-	movntdq	%xmm4, -16(%r9)
-	movntdq	%xmm5, -32(%r9)
-	movntdq	%xmm6, -48(%r9)
-	movntdq	%xmm7, -64(%r9)
-	lea 	-64(%r9), %r9
-
-	lea 	128(%rdi), %rbx
-	and 	$-64, %rbx
-
-/* Compute in %rdx how many bytes are left to copy after
-	the main loop stops.  */
-	mov 	%rbx, %rdx
-	sub 	%rdi, %rdx
-
-	cmp	%r9, %rbx
-	jae	L(mm_len_0_or_more_backward)
-
 	.p2align 4
 L(mm_large_page_loop_backward):
 	movdqu	-64(%r9, %r8), %xmm0
@@ -630,6 +507,7 @@
 	lea 	-64(%r9), %r9
 	cmp	%r9, %rbx
 	jb	L(mm_large_page_loop_backward)
-	jmp	L(mm_len_0_or_more_backward)
+	sfence
+	jmp	L(mm_recalc_len)
 
 END (MEMMOVE)
diff --git a/libc/arch-x86_64/syscalls/__accept4.S b/libc/arch-x86_64/syscalls/__accept4.S
index cf4837f..375a78b 100644
--- a/libc/arch-x86_64/syscalls/__accept4.S
+++ b/libc/arch-x86_64/syscalls/__accept4.S
@@ -11,7 +11,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(__accept4)
diff --git a/libc/arch-x86_64/syscalls/__arch_prctl.S b/libc/arch-x86_64/syscalls/__arch_prctl.S
index ac5d96e..6c72a6c 100644
--- a/libc/arch-x86_64/syscalls/__arch_prctl.S
+++ b/libc/arch-x86_64/syscalls/__arch_prctl.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(__arch_prctl)
diff --git a/libc/arch-x86_64/syscalls/__brk.S b/libc/arch-x86_64/syscalls/__brk.S
index a69f404..18ebc10 100644
--- a/libc/arch-x86_64/syscalls/__brk.S
+++ b/libc/arch-x86_64/syscalls/__brk.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(__brk)
diff --git a/libc/arch-x86_64/syscalls/__connect.S b/libc/arch-x86_64/syscalls/__connect.S
index 288484e..a7d2e93 100644
--- a/libc/arch-x86_64/syscalls/__connect.S
+++ b/libc/arch-x86_64/syscalls/__connect.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(__connect)
diff --git a/libc/arch-x86_64/syscalls/__epoll_pwait.S b/libc/arch-x86_64/syscalls/__epoll_pwait.S
index 306e12e..4271b53 100644
--- a/libc/arch-x86_64/syscalls/__epoll_pwait.S
+++ b/libc/arch-x86_64/syscalls/__epoll_pwait.S
@@ -11,7 +11,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(__epoll_pwait)
diff --git a/libc/arch-x86_64/syscalls/__exit.S b/libc/arch-x86_64/syscalls/__exit.S
index af3ada4..bcbaffc 100644
--- a/libc/arch-x86_64/syscalls/__exit.S
+++ b/libc/arch-x86_64/syscalls/__exit.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(__exit)
diff --git a/libc/arch-x86_64/syscalls/__getcpu.S b/libc/arch-x86_64/syscalls/__getcpu.S
index 8650db4..c25f294 100644
--- a/libc/arch-x86_64/syscalls/__getcpu.S
+++ b/libc/arch-x86_64/syscalls/__getcpu.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(__getcpu)
diff --git a/libc/arch-x86_64/syscalls/__getcwd.S b/libc/arch-x86_64/syscalls/__getcwd.S
index c762804..1743838 100644
--- a/libc/arch-x86_64/syscalls/__getcwd.S
+++ b/libc/arch-x86_64/syscalls/__getcwd.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(__getcwd)
diff --git a/libc/arch-x86_64/syscalls/getdents.S b/libc/arch-x86_64/syscalls/__getdents64.S
similarity index 80%
rename from libc/arch-x86_64/syscalls/getdents.S
rename to libc/arch-x86_64/syscalls/__getdents64.S
index a47c26b..64f82fd 100644
--- a/libc/arch-x86_64/syscalls/getdents.S
+++ b/libc/arch-x86_64/syscalls/__getdents64.S
@@ -2,7 +2,7 @@
 
 #include <private/bionic_asm.h>
 
-ENTRY(getdents)
+ENTRY(__getdents64)
     movl    $__NR_getdents64, %eax
     syscall
     cmpq    $-MAX_ERRNO, %rax
@@ -10,7 +10,7 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
-END(getdents)
+END(__getdents64)
+.hidden __getdents64
diff --git a/libc/arch-x86_64/syscalls/getpid.S b/libc/arch-x86_64/syscalls/__getpid.S
similarity index 83%
rename from libc/arch-x86_64/syscalls/getpid.S
rename to libc/arch-x86_64/syscalls/__getpid.S
index 65b8df4..bd1bf1e 100644
--- a/libc/arch-x86_64/syscalls/getpid.S
+++ b/libc/arch-x86_64/syscalls/__getpid.S
@@ -2,7 +2,7 @@
 
 #include <private/bionic_asm.h>
 
-ENTRY(getpid)
+ENTRY(__getpid)
     movl    $__NR_getpid, %eax
     syscall
     cmpq    $-MAX_ERRNO, %rax
@@ -10,7 +10,7 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
-END(getpid)
+END(__getpid)
+.hidden __getpid
diff --git a/libc/arch-x86_64/syscalls/__getpriority.S b/libc/arch-x86_64/syscalls/__getpriority.S
index 8aaae8f..349f574 100644
--- a/libc/arch-x86_64/syscalls/__getpriority.S
+++ b/libc/arch-x86_64/syscalls/__getpriority.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(__getpriority)
diff --git a/libc/arch-x86_64/syscalls/__ioctl.S b/libc/arch-x86_64/syscalls/__ioctl.S
index 646d819..2775911 100644
--- a/libc/arch-x86_64/syscalls/__ioctl.S
+++ b/libc/arch-x86_64/syscalls/__ioctl.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(__ioctl)
diff --git a/libc/arch-x86_64/syscalls/__openat.S b/libc/arch-x86_64/syscalls/__openat.S
index e065cca..dce4c7c 100644
--- a/libc/arch-x86_64/syscalls/__openat.S
+++ b/libc/arch-x86_64/syscalls/__openat.S
@@ -11,7 +11,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(__openat)
diff --git a/libc/arch-x86_64/syscalls/__ppoll.S b/libc/arch-x86_64/syscalls/__ppoll.S
index 6edaa36..31ba7e9 100644
--- a/libc/arch-x86_64/syscalls/__ppoll.S
+++ b/libc/arch-x86_64/syscalls/__ppoll.S
@@ -11,7 +11,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(__ppoll)
diff --git a/libc/arch-x86_64/syscalls/__pselect6.S b/libc/arch-x86_64/syscalls/__pselect6.S
index a2aec7a..a212c4e 100644
--- a/libc/arch-x86_64/syscalls/__pselect6.S
+++ b/libc/arch-x86_64/syscalls/__pselect6.S
@@ -11,7 +11,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(__pselect6)
diff --git a/libc/arch-x86_64/syscalls/__ptrace.S b/libc/arch-x86_64/syscalls/__ptrace.S
index 8ec8ac1..0a64fee 100644
--- a/libc/arch-x86_64/syscalls/__ptrace.S
+++ b/libc/arch-x86_64/syscalls/__ptrace.S
@@ -11,7 +11,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(__ptrace)
diff --git a/libc/arch-x86_64/syscalls/__reboot.S b/libc/arch-x86_64/syscalls/__reboot.S
index 9b8ef70..398d078 100644
--- a/libc/arch-x86_64/syscalls/__reboot.S
+++ b/libc/arch-x86_64/syscalls/__reboot.S
@@ -11,7 +11,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(__reboot)
diff --git a/libc/arch-x86_64/syscalls/__rt_sigaction.S b/libc/arch-x86_64/syscalls/__rt_sigaction.S
index b038f6e..f146b02 100644
--- a/libc/arch-x86_64/syscalls/__rt_sigaction.S
+++ b/libc/arch-x86_64/syscalls/__rt_sigaction.S
@@ -11,7 +11,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(__rt_sigaction)
diff --git a/libc/arch-x86_64/syscalls/__rt_sigpending.S b/libc/arch-x86_64/syscalls/__rt_sigpending.S
index e0c50c1..9d1698b 100644
--- a/libc/arch-x86_64/syscalls/__rt_sigpending.S
+++ b/libc/arch-x86_64/syscalls/__rt_sigpending.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(__rt_sigpending)
diff --git a/libc/arch-x86_64/syscalls/__rt_sigprocmask.S b/libc/arch-x86_64/syscalls/__rt_sigprocmask.S
index 2a0ab5e..1ac9b81 100644
--- a/libc/arch-x86_64/syscalls/__rt_sigprocmask.S
+++ b/libc/arch-x86_64/syscalls/__rt_sigprocmask.S
@@ -11,7 +11,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(__rt_sigprocmask)
diff --git a/libc/arch-x86_64/syscalls/__rt_sigsuspend.S b/libc/arch-x86_64/syscalls/__rt_sigsuspend.S
index 6fa6565..1059f0b 100644
--- a/libc/arch-x86_64/syscalls/__rt_sigsuspend.S
+++ b/libc/arch-x86_64/syscalls/__rt_sigsuspend.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(__rt_sigsuspend)
diff --git a/libc/arch-x86_64/syscalls/__rt_sigtimedwait.S b/libc/arch-x86_64/syscalls/__rt_sigtimedwait.S
index 46ee04b..de2e4cb 100644
--- a/libc/arch-x86_64/syscalls/__rt_sigtimedwait.S
+++ b/libc/arch-x86_64/syscalls/__rt_sigtimedwait.S
@@ -11,7 +11,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(__rt_sigtimedwait)
diff --git a/libc/arch-x86_64/syscalls/__sched_getaffinity.S b/libc/arch-x86_64/syscalls/__sched_getaffinity.S
index 3707226..410954c 100644
--- a/libc/arch-x86_64/syscalls/__sched_getaffinity.S
+++ b/libc/arch-x86_64/syscalls/__sched_getaffinity.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(__sched_getaffinity)
diff --git a/libc/arch-x86_64/syscalls/__set_tid_address.S b/libc/arch-x86_64/syscalls/__set_tid_address.S
index 4a8f153..c59c8b8 100644
--- a/libc/arch-x86_64/syscalls/__set_tid_address.S
+++ b/libc/arch-x86_64/syscalls/__set_tid_address.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(__set_tid_address)
diff --git a/libc/arch-x86_64/syscalls/__signalfd4.S b/libc/arch-x86_64/syscalls/__signalfd4.S
index fafe371..6ddcf5a 100644
--- a/libc/arch-x86_64/syscalls/__signalfd4.S
+++ b/libc/arch-x86_64/syscalls/__signalfd4.S
@@ -11,7 +11,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(__signalfd4)
diff --git a/libc/arch-x86_64/syscalls/__socket.S b/libc/arch-x86_64/syscalls/__socket.S
index 67621fc..209e329 100644
--- a/libc/arch-x86_64/syscalls/__socket.S
+++ b/libc/arch-x86_64/syscalls/__socket.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(__socket)
diff --git a/libc/arch-x86_64/syscalls/__timer_create.S b/libc/arch-x86_64/syscalls/__timer_create.S
index 2f41c88..3450d2b 100644
--- a/libc/arch-x86_64/syscalls/__timer_create.S
+++ b/libc/arch-x86_64/syscalls/__timer_create.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(__timer_create)
diff --git a/libc/arch-x86_64/syscalls/__timer_delete.S b/libc/arch-x86_64/syscalls/__timer_delete.S
index 2009916..fd60a16 100644
--- a/libc/arch-x86_64/syscalls/__timer_delete.S
+++ b/libc/arch-x86_64/syscalls/__timer_delete.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(__timer_delete)
diff --git a/libc/arch-x86_64/syscalls/__timer_getoverrun.S b/libc/arch-x86_64/syscalls/__timer_getoverrun.S
index fe71efe..f5309a3 100644
--- a/libc/arch-x86_64/syscalls/__timer_getoverrun.S
+++ b/libc/arch-x86_64/syscalls/__timer_getoverrun.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(__timer_getoverrun)
diff --git a/libc/arch-x86_64/syscalls/__timer_gettime.S b/libc/arch-x86_64/syscalls/__timer_gettime.S
index 44fe2ff..7e2bc92 100644
--- a/libc/arch-x86_64/syscalls/__timer_gettime.S
+++ b/libc/arch-x86_64/syscalls/__timer_gettime.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(__timer_gettime)
diff --git a/libc/arch-x86_64/syscalls/__timer_settime.S b/libc/arch-x86_64/syscalls/__timer_settime.S
index 1240aa1..f5401a0 100644
--- a/libc/arch-x86_64/syscalls/__timer_settime.S
+++ b/libc/arch-x86_64/syscalls/__timer_settime.S
@@ -11,7 +11,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(__timer_settime)
diff --git a/libc/arch-x86_64/syscalls/__waitid.S b/libc/arch-x86_64/syscalls/__waitid.S
index 0d4fc58..229f20c 100644
--- a/libc/arch-x86_64/syscalls/__waitid.S
+++ b/libc/arch-x86_64/syscalls/__waitid.S
@@ -11,7 +11,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(__waitid)
diff --git a/libc/arch-x86_64/syscalls/_exit.S b/libc/arch-x86_64/syscalls/_exit.S
index 3c15897..9c80f00 100644
--- a/libc/arch-x86_64/syscalls/_exit.S
+++ b/libc/arch-x86_64/syscalls/_exit.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(_exit)
diff --git a/libc/arch-x86_64/syscalls/acct.S b/libc/arch-x86_64/syscalls/acct.S
index 59af17d..91ecf5b 100644
--- a/libc/arch-x86_64/syscalls/acct.S
+++ b/libc/arch-x86_64/syscalls/acct.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(acct)
diff --git a/libc/arch-x86_64/syscalls/bind.S b/libc/arch-x86_64/syscalls/bind.S
index 20dfa2d..5d426cb 100644
--- a/libc/arch-x86_64/syscalls/bind.S
+++ b/libc/arch-x86_64/syscalls/bind.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(bind)
diff --git a/libc/arch-x86_64/syscalls/capget.S b/libc/arch-x86_64/syscalls/capget.S
index 9cf73fb..d3d151e 100644
--- a/libc/arch-x86_64/syscalls/capget.S
+++ b/libc/arch-x86_64/syscalls/capget.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(capget)
diff --git a/libc/arch-x86_64/syscalls/capset.S b/libc/arch-x86_64/syscalls/capset.S
index f6cf2eb..421f156 100644
--- a/libc/arch-x86_64/syscalls/capset.S
+++ b/libc/arch-x86_64/syscalls/capset.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(capset)
diff --git a/libc/arch-x86_64/syscalls/chdir.S b/libc/arch-x86_64/syscalls/chdir.S
index a04f3aa..7a6f651 100644
--- a/libc/arch-x86_64/syscalls/chdir.S
+++ b/libc/arch-x86_64/syscalls/chdir.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(chdir)
diff --git a/libc/arch-x86_64/syscalls/chroot.S b/libc/arch-x86_64/syscalls/chroot.S
index 491086d..0f53fd9 100644
--- a/libc/arch-x86_64/syscalls/chroot.S
+++ b/libc/arch-x86_64/syscalls/chroot.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(chroot)
diff --git a/libc/arch-x86_64/syscalls/clock_getres.S b/libc/arch-x86_64/syscalls/clock_getres.S
index d1d491e..bad0d78 100644
--- a/libc/arch-x86_64/syscalls/clock_getres.S
+++ b/libc/arch-x86_64/syscalls/clock_getres.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(clock_getres)
diff --git a/libc/arch-x86_64/syscalls/clock_gettime.S b/libc/arch-x86_64/syscalls/clock_gettime.S
index 89ae616..20850c8 100644
--- a/libc/arch-x86_64/syscalls/clock_gettime.S
+++ b/libc/arch-x86_64/syscalls/clock_gettime.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(clock_gettime)
diff --git a/libc/arch-x86_64/syscalls/clock_nanosleep.S b/libc/arch-x86_64/syscalls/clock_nanosleep.S
index 3833113..2ef0d05 100644
--- a/libc/arch-x86_64/syscalls/clock_nanosleep.S
+++ b/libc/arch-x86_64/syscalls/clock_nanosleep.S
@@ -11,7 +11,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(clock_nanosleep)
diff --git a/libc/arch-x86_64/syscalls/clock_settime.S b/libc/arch-x86_64/syscalls/clock_settime.S
index 15b27aa..6a3b75b 100644
--- a/libc/arch-x86_64/syscalls/clock_settime.S
+++ b/libc/arch-x86_64/syscalls/clock_settime.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(clock_settime)
diff --git a/libc/arch-x86_64/syscalls/close.S b/libc/arch-x86_64/syscalls/close.S
index 361d82f..41c8403 100644
--- a/libc/arch-x86_64/syscalls/close.S
+++ b/libc/arch-x86_64/syscalls/close.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(close)
diff --git a/libc/arch-x86_64/syscalls/delete_module.S b/libc/arch-x86_64/syscalls/delete_module.S
index 33f2354..d3f3862 100644
--- a/libc/arch-x86_64/syscalls/delete_module.S
+++ b/libc/arch-x86_64/syscalls/delete_module.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(delete_module)
diff --git a/libc/arch-x86_64/syscalls/dup.S b/libc/arch-x86_64/syscalls/dup.S
index dfc0def..bf2ca51 100644
--- a/libc/arch-x86_64/syscalls/dup.S
+++ b/libc/arch-x86_64/syscalls/dup.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(dup)
diff --git a/libc/arch-x86_64/syscalls/dup3.S b/libc/arch-x86_64/syscalls/dup3.S
index dcb4155..f5c929c 100644
--- a/libc/arch-x86_64/syscalls/dup3.S
+++ b/libc/arch-x86_64/syscalls/dup3.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(dup3)
diff --git a/libc/arch-x86_64/syscalls/epoll_create1.S b/libc/arch-x86_64/syscalls/epoll_create1.S
index fa3c6d7..196a3c7 100644
--- a/libc/arch-x86_64/syscalls/epoll_create1.S
+++ b/libc/arch-x86_64/syscalls/epoll_create1.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(epoll_create1)
diff --git a/libc/arch-x86_64/syscalls/epoll_ctl.S b/libc/arch-x86_64/syscalls/epoll_ctl.S
index 72df97f..2a3517c 100644
--- a/libc/arch-x86_64/syscalls/epoll_ctl.S
+++ b/libc/arch-x86_64/syscalls/epoll_ctl.S
@@ -11,7 +11,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(epoll_ctl)
diff --git a/libc/arch-x86_64/syscalls/eventfd.S b/libc/arch-x86_64/syscalls/eventfd.S
index 99f585c..3ed4baf 100644
--- a/libc/arch-x86_64/syscalls/eventfd.S
+++ b/libc/arch-x86_64/syscalls/eventfd.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(eventfd)
diff --git a/libc/arch-x86_64/syscalls/execve.S b/libc/arch-x86_64/syscalls/execve.S
index ea89d7d..1fe29c7 100644
--- a/libc/arch-x86_64/syscalls/execve.S
+++ b/libc/arch-x86_64/syscalls/execve.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(execve)
diff --git a/libc/arch-x86_64/syscalls/faccessat.S b/libc/arch-x86_64/syscalls/faccessat.S
index 238a4e1..3ea905c 100644
--- a/libc/arch-x86_64/syscalls/faccessat.S
+++ b/libc/arch-x86_64/syscalls/faccessat.S
@@ -11,7 +11,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(faccessat)
diff --git a/libc/arch-x86_64/syscalls/fallocate.S b/libc/arch-x86_64/syscalls/fallocate.S
index 9ba36b9..abaa303 100644
--- a/libc/arch-x86_64/syscalls/fallocate.S
+++ b/libc/arch-x86_64/syscalls/fallocate.S
@@ -11,7 +11,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(fallocate)
diff --git a/libc/arch-x86_64/syscalls/fchdir.S b/libc/arch-x86_64/syscalls/fchdir.S
index da14edd..b01bb57 100644
--- a/libc/arch-x86_64/syscalls/fchdir.S
+++ b/libc/arch-x86_64/syscalls/fchdir.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(fchdir)
diff --git a/libc/arch-x86_64/syscalls/fchmod.S b/libc/arch-x86_64/syscalls/fchmod.S
index a6d15fc..868638f 100644
--- a/libc/arch-x86_64/syscalls/fchmod.S
+++ b/libc/arch-x86_64/syscalls/fchmod.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(fchmod)
diff --git a/libc/arch-x86_64/syscalls/fchmodat.S b/libc/arch-x86_64/syscalls/fchmodat.S
index daf71ab..e045a13 100644
--- a/libc/arch-x86_64/syscalls/fchmodat.S
+++ b/libc/arch-x86_64/syscalls/fchmodat.S
@@ -11,7 +11,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(fchmodat)
diff --git a/libc/arch-x86_64/syscalls/fchown.S b/libc/arch-x86_64/syscalls/fchown.S
index 8c68a15..9ba775b 100644
--- a/libc/arch-x86_64/syscalls/fchown.S
+++ b/libc/arch-x86_64/syscalls/fchown.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(fchown)
diff --git a/libc/arch-x86_64/syscalls/fchownat.S b/libc/arch-x86_64/syscalls/fchownat.S
index e5265dd..7789d2d 100644
--- a/libc/arch-x86_64/syscalls/fchownat.S
+++ b/libc/arch-x86_64/syscalls/fchownat.S
@@ -11,7 +11,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(fchownat)
diff --git a/libc/arch-x86_64/syscalls/fcntl.S b/libc/arch-x86_64/syscalls/fcntl.S
index c562385..a20d938 100644
--- a/libc/arch-x86_64/syscalls/fcntl.S
+++ b/libc/arch-x86_64/syscalls/fcntl.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(fcntl)
diff --git a/libc/arch-x86_64/syscalls/fdatasync.S b/libc/arch-x86_64/syscalls/fdatasync.S
index 3f9ee72..5ea8ebd 100644
--- a/libc/arch-x86_64/syscalls/fdatasync.S
+++ b/libc/arch-x86_64/syscalls/fdatasync.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(fdatasync)
diff --git a/libc/arch-x86_64/syscalls/fgetxattr.S b/libc/arch-x86_64/syscalls/fgetxattr.S
index 77f095b..096c30f 100644
--- a/libc/arch-x86_64/syscalls/fgetxattr.S
+++ b/libc/arch-x86_64/syscalls/fgetxattr.S
@@ -11,7 +11,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(fgetxattr)
diff --git a/libc/arch-x86_64/syscalls/flistxattr.S b/libc/arch-x86_64/syscalls/flistxattr.S
index cd39298..e0e5b8b 100644
--- a/libc/arch-x86_64/syscalls/flistxattr.S
+++ b/libc/arch-x86_64/syscalls/flistxattr.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(flistxattr)
diff --git a/libc/arch-x86_64/syscalls/flock.S b/libc/arch-x86_64/syscalls/flock.S
index af2dbef..981d86e 100644
--- a/libc/arch-x86_64/syscalls/flock.S
+++ b/libc/arch-x86_64/syscalls/flock.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(flock)
diff --git a/libc/arch-x86_64/syscalls/fremovexattr.S b/libc/arch-x86_64/syscalls/fremovexattr.S
index 4387563..655bdef 100644
--- a/libc/arch-x86_64/syscalls/fremovexattr.S
+++ b/libc/arch-x86_64/syscalls/fremovexattr.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(fremovexattr)
diff --git a/libc/arch-x86_64/syscalls/fsetxattr.S b/libc/arch-x86_64/syscalls/fsetxattr.S
index 610890c..fa2bddc 100644
--- a/libc/arch-x86_64/syscalls/fsetxattr.S
+++ b/libc/arch-x86_64/syscalls/fsetxattr.S
@@ -11,7 +11,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(fsetxattr)
diff --git a/libc/arch-x86_64/syscalls/fstat64.S b/libc/arch-x86_64/syscalls/fstat64.S
index 6abb146..9e7aa2d 100644
--- a/libc/arch-x86_64/syscalls/fstat64.S
+++ b/libc/arch-x86_64/syscalls/fstat64.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(fstat64)
diff --git a/libc/arch-x86_64/syscalls/fstatat64.S b/libc/arch-x86_64/syscalls/fstatat64.S
index b85506c..5418cd0 100644
--- a/libc/arch-x86_64/syscalls/fstatat64.S
+++ b/libc/arch-x86_64/syscalls/fstatat64.S
@@ -11,7 +11,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(fstatat64)
diff --git a/libc/arch-x86_64/syscalls/fstatfs64.S b/libc/arch-x86_64/syscalls/fstatfs64.S
index 983e6b7..ee2daa2 100644
--- a/libc/arch-x86_64/syscalls/fstatfs64.S
+++ b/libc/arch-x86_64/syscalls/fstatfs64.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(fstatfs64)
diff --git a/libc/arch-x86_64/syscalls/fsync.S b/libc/arch-x86_64/syscalls/fsync.S
index 0392620..12eabd3 100644
--- a/libc/arch-x86_64/syscalls/fsync.S
+++ b/libc/arch-x86_64/syscalls/fsync.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(fsync)
diff --git a/libc/arch-x86_64/syscalls/ftruncate.S b/libc/arch-x86_64/syscalls/ftruncate.S
index 437b3e2..11161a7 100644
--- a/libc/arch-x86_64/syscalls/ftruncate.S
+++ b/libc/arch-x86_64/syscalls/ftruncate.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(ftruncate)
diff --git a/libc/arch-x86_64/syscalls/getegid.S b/libc/arch-x86_64/syscalls/getegid.S
index c1b8fae..6f9c2a8 100644
--- a/libc/arch-x86_64/syscalls/getegid.S
+++ b/libc/arch-x86_64/syscalls/getegid.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(getegid)
diff --git a/libc/arch-x86_64/syscalls/geteuid.S b/libc/arch-x86_64/syscalls/geteuid.S
index f2f1035..88000ef 100644
--- a/libc/arch-x86_64/syscalls/geteuid.S
+++ b/libc/arch-x86_64/syscalls/geteuid.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(geteuid)
diff --git a/libc/arch-x86_64/syscalls/getgid.S b/libc/arch-x86_64/syscalls/getgid.S
index e9b38c7..8f8eaa6 100644
--- a/libc/arch-x86_64/syscalls/getgid.S
+++ b/libc/arch-x86_64/syscalls/getgid.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(getgid)
diff --git a/libc/arch-x86_64/syscalls/getgroups.S b/libc/arch-x86_64/syscalls/getgroups.S
index b12836e..5358a3e 100644
--- a/libc/arch-x86_64/syscalls/getgroups.S
+++ b/libc/arch-x86_64/syscalls/getgroups.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(getgroups)
diff --git a/libc/arch-x86_64/syscalls/getitimer.S b/libc/arch-x86_64/syscalls/getitimer.S
index 79484d1..b6a6e8e 100644
--- a/libc/arch-x86_64/syscalls/getitimer.S
+++ b/libc/arch-x86_64/syscalls/getitimer.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(getitimer)
diff --git a/libc/arch-x86_64/syscalls/getpeername.S b/libc/arch-x86_64/syscalls/getpeername.S
index a276cac..98e06fb 100644
--- a/libc/arch-x86_64/syscalls/getpeername.S
+++ b/libc/arch-x86_64/syscalls/getpeername.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(getpeername)
diff --git a/libc/arch-x86_64/syscalls/getpgid.S b/libc/arch-x86_64/syscalls/getpgid.S
index c2f5c09..158f14d 100644
--- a/libc/arch-x86_64/syscalls/getpgid.S
+++ b/libc/arch-x86_64/syscalls/getpgid.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(getpgid)
diff --git a/libc/arch-x86_64/syscalls/getppid.S b/libc/arch-x86_64/syscalls/getppid.S
index ce3dbda..e4853e0 100644
--- a/libc/arch-x86_64/syscalls/getppid.S
+++ b/libc/arch-x86_64/syscalls/getppid.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(getppid)
diff --git a/libc/arch-x86_64/syscalls/getresgid.S b/libc/arch-x86_64/syscalls/getresgid.S
index 0edc20a..d65fb13 100644
--- a/libc/arch-x86_64/syscalls/getresgid.S
+++ b/libc/arch-x86_64/syscalls/getresgid.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(getresgid)
diff --git a/libc/arch-x86_64/syscalls/getresuid.S b/libc/arch-x86_64/syscalls/getresuid.S
index b900c99..80d85c6 100644
--- a/libc/arch-x86_64/syscalls/getresuid.S
+++ b/libc/arch-x86_64/syscalls/getresuid.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(getresuid)
diff --git a/libc/arch-x86_64/syscalls/getrlimit.S b/libc/arch-x86_64/syscalls/getrlimit.S
index 6a9c9b6..ea0ca7d 100644
--- a/libc/arch-x86_64/syscalls/getrlimit.S
+++ b/libc/arch-x86_64/syscalls/getrlimit.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(getrlimit)
diff --git a/libc/arch-x86_64/syscalls/getrusage.S b/libc/arch-x86_64/syscalls/getrusage.S
index 210d586..7a60738 100644
--- a/libc/arch-x86_64/syscalls/getrusage.S
+++ b/libc/arch-x86_64/syscalls/getrusage.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(getrusage)
diff --git a/libc/arch-x86_64/syscalls/getsid.S b/libc/arch-x86_64/syscalls/getsid.S
index de3e3c0..75e3fad 100644
--- a/libc/arch-x86_64/syscalls/getsid.S
+++ b/libc/arch-x86_64/syscalls/getsid.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(getsid)
diff --git a/libc/arch-x86_64/syscalls/getsockname.S b/libc/arch-x86_64/syscalls/getsockname.S
index ccabf71..3c7c2f8 100644
--- a/libc/arch-x86_64/syscalls/getsockname.S
+++ b/libc/arch-x86_64/syscalls/getsockname.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(getsockname)
diff --git a/libc/arch-x86_64/syscalls/getsockopt.S b/libc/arch-x86_64/syscalls/getsockopt.S
index c4f456e..725757c 100644
--- a/libc/arch-x86_64/syscalls/getsockopt.S
+++ b/libc/arch-x86_64/syscalls/getsockopt.S
@@ -11,7 +11,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(getsockopt)
diff --git a/libc/arch-x86_64/syscalls/gettimeofday.S b/libc/arch-x86_64/syscalls/gettimeofday.S
index 261bb6e..4867c30 100644
--- a/libc/arch-x86_64/syscalls/gettimeofday.S
+++ b/libc/arch-x86_64/syscalls/gettimeofday.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(gettimeofday)
diff --git a/libc/arch-x86_64/syscalls/getuid.S b/libc/arch-x86_64/syscalls/getuid.S
index 4cb9efd..d7306e1 100644
--- a/libc/arch-x86_64/syscalls/getuid.S
+++ b/libc/arch-x86_64/syscalls/getuid.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(getuid)
diff --git a/libc/arch-x86_64/syscalls/getxattr.S b/libc/arch-x86_64/syscalls/getxattr.S
index 6bdb762..7c66b0e 100644
--- a/libc/arch-x86_64/syscalls/getxattr.S
+++ b/libc/arch-x86_64/syscalls/getxattr.S
@@ -11,7 +11,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(getxattr)
diff --git a/libc/arch-x86_64/syscalls/init_module.S b/libc/arch-x86_64/syscalls/init_module.S
index eb048c0..187f5a2 100644
--- a/libc/arch-x86_64/syscalls/init_module.S
+++ b/libc/arch-x86_64/syscalls/init_module.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(init_module)
diff --git a/libc/arch-x86_64/syscalls/inotify_add_watch.S b/libc/arch-x86_64/syscalls/inotify_add_watch.S
index 3e124e7..47e15ab 100644
--- a/libc/arch-x86_64/syscalls/inotify_add_watch.S
+++ b/libc/arch-x86_64/syscalls/inotify_add_watch.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(inotify_add_watch)
diff --git a/libc/arch-x86_64/syscalls/inotify_init1.S b/libc/arch-x86_64/syscalls/inotify_init1.S
index 8d82115..160b0d5 100644
--- a/libc/arch-x86_64/syscalls/inotify_init1.S
+++ b/libc/arch-x86_64/syscalls/inotify_init1.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(inotify_init1)
diff --git a/libc/arch-x86_64/syscalls/inotify_rm_watch.S b/libc/arch-x86_64/syscalls/inotify_rm_watch.S
index ece1510..4c5874e 100644
--- a/libc/arch-x86_64/syscalls/inotify_rm_watch.S
+++ b/libc/arch-x86_64/syscalls/inotify_rm_watch.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(inotify_rm_watch)
diff --git a/libc/arch-x86_64/syscalls/ioprio_get.S b/libc/arch-x86_64/syscalls/ioprio_get.S
deleted file mode 100644
index 48c1402..0000000
--- a/libc/arch-x86_64/syscalls/ioprio_get.S
+++ /dev/null
@@ -1,16 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(ioprio_get)
-    movl    $__NR_ioprio_get, %eax
-    syscall
-    cmpq    $-MAX_ERRNO, %rax
-    jb      1f
-    negl    %eax
-    movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
-1:
-    ret
-END(ioprio_get)
diff --git a/libc/arch-x86_64/syscalls/ioprio_set.S b/libc/arch-x86_64/syscalls/ioprio_set.S
deleted file mode 100644
index 4cdc8b3..0000000
--- a/libc/arch-x86_64/syscalls/ioprio_set.S
+++ /dev/null
@@ -1,16 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(ioprio_set)
-    movl    $__NR_ioprio_set, %eax
-    syscall
-    cmpq    $-MAX_ERRNO, %rax
-    jb      1f
-    negl    %eax
-    movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
-1:
-    ret
-END(ioprio_set)
diff --git a/libc/arch-x86_64/syscalls/kill.S b/libc/arch-x86_64/syscalls/kill.S
index 51ca35c..f234585 100644
--- a/libc/arch-x86_64/syscalls/kill.S
+++ b/libc/arch-x86_64/syscalls/kill.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(kill)
diff --git a/libc/arch-x86_64/syscalls/klogctl.S b/libc/arch-x86_64/syscalls/klogctl.S
index 8c0ccce..057b066 100644
--- a/libc/arch-x86_64/syscalls/klogctl.S
+++ b/libc/arch-x86_64/syscalls/klogctl.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(klogctl)
diff --git a/libc/arch-x86_64/syscalls/lgetxattr.S b/libc/arch-x86_64/syscalls/lgetxattr.S
index 6f195ea..525ee3b 100644
--- a/libc/arch-x86_64/syscalls/lgetxattr.S
+++ b/libc/arch-x86_64/syscalls/lgetxattr.S
@@ -11,7 +11,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(lgetxattr)
diff --git a/libc/arch-x86_64/syscalls/linkat.S b/libc/arch-x86_64/syscalls/linkat.S
index b9a2b14..815af86 100644
--- a/libc/arch-x86_64/syscalls/linkat.S
+++ b/libc/arch-x86_64/syscalls/linkat.S
@@ -11,7 +11,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(linkat)
diff --git a/libc/arch-x86_64/syscalls/listen.S b/libc/arch-x86_64/syscalls/listen.S
index 104b514..d3d7103 100644
--- a/libc/arch-x86_64/syscalls/listen.S
+++ b/libc/arch-x86_64/syscalls/listen.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(listen)
diff --git a/libc/arch-x86_64/syscalls/listxattr.S b/libc/arch-x86_64/syscalls/listxattr.S
index fe57e39..89fd63c 100644
--- a/libc/arch-x86_64/syscalls/listxattr.S
+++ b/libc/arch-x86_64/syscalls/listxattr.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(listxattr)
diff --git a/libc/arch-x86_64/syscalls/llistxattr.S b/libc/arch-x86_64/syscalls/llistxattr.S
index aa0a54d..cfff2e7 100644
--- a/libc/arch-x86_64/syscalls/llistxattr.S
+++ b/libc/arch-x86_64/syscalls/llistxattr.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(llistxattr)
diff --git a/libc/arch-x86_64/syscalls/lremovexattr.S b/libc/arch-x86_64/syscalls/lremovexattr.S
index 4b5ee65..0b6994a 100644
--- a/libc/arch-x86_64/syscalls/lremovexattr.S
+++ b/libc/arch-x86_64/syscalls/lremovexattr.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(lremovexattr)
diff --git a/libc/arch-x86_64/syscalls/lseek.S b/libc/arch-x86_64/syscalls/lseek.S
index cf19776..b2e8c16 100644
--- a/libc/arch-x86_64/syscalls/lseek.S
+++ b/libc/arch-x86_64/syscalls/lseek.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(lseek)
diff --git a/libc/arch-x86_64/syscalls/lsetxattr.S b/libc/arch-x86_64/syscalls/lsetxattr.S
index 67d93eb..fdaf98a 100644
--- a/libc/arch-x86_64/syscalls/lsetxattr.S
+++ b/libc/arch-x86_64/syscalls/lsetxattr.S
@@ -11,7 +11,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(lsetxattr)
diff --git a/libc/arch-x86_64/syscalls/madvise.S b/libc/arch-x86_64/syscalls/madvise.S
index e4ef923..3f567fd 100644
--- a/libc/arch-x86_64/syscalls/madvise.S
+++ b/libc/arch-x86_64/syscalls/madvise.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(madvise)
diff --git a/libc/arch-x86_64/syscalls/mincore.S b/libc/arch-x86_64/syscalls/mincore.S
index d92755c..e6b2521 100644
--- a/libc/arch-x86_64/syscalls/mincore.S
+++ b/libc/arch-x86_64/syscalls/mincore.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(mincore)
diff --git a/libc/arch-x86_64/syscalls/mkdirat.S b/libc/arch-x86_64/syscalls/mkdirat.S
index 9e5dbd6..abba2d5 100644
--- a/libc/arch-x86_64/syscalls/mkdirat.S
+++ b/libc/arch-x86_64/syscalls/mkdirat.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(mkdirat)
diff --git a/libc/arch-x86_64/syscalls/mknodat.S b/libc/arch-x86_64/syscalls/mknodat.S
index 49aac35..d3d78c9 100644
--- a/libc/arch-x86_64/syscalls/mknodat.S
+++ b/libc/arch-x86_64/syscalls/mknodat.S
@@ -11,7 +11,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(mknodat)
diff --git a/libc/arch-x86_64/syscalls/mlock.S b/libc/arch-x86_64/syscalls/mlock.S
index f0b0c6e..0c69eb7 100644
--- a/libc/arch-x86_64/syscalls/mlock.S
+++ b/libc/arch-x86_64/syscalls/mlock.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(mlock)
diff --git a/libc/arch-x86_64/syscalls/mlockall.S b/libc/arch-x86_64/syscalls/mlockall.S
index 420cb03..89ba9b6 100644
--- a/libc/arch-x86_64/syscalls/mlockall.S
+++ b/libc/arch-x86_64/syscalls/mlockall.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(mlockall)
diff --git a/libc/arch-x86_64/syscalls/mmap.S b/libc/arch-x86_64/syscalls/mmap.S
index 9c3fc0f..7b9f6e0 100644
--- a/libc/arch-x86_64/syscalls/mmap.S
+++ b/libc/arch-x86_64/syscalls/mmap.S
@@ -11,7 +11,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(mmap)
diff --git a/libc/arch-x86_64/syscalls/mount.S b/libc/arch-x86_64/syscalls/mount.S
index df488c3..04534c9 100644
--- a/libc/arch-x86_64/syscalls/mount.S
+++ b/libc/arch-x86_64/syscalls/mount.S
@@ -11,7 +11,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(mount)
diff --git a/libc/arch-x86_64/syscalls/mprotect.S b/libc/arch-x86_64/syscalls/mprotect.S
index 9ef61b5..d849bb1 100644
--- a/libc/arch-x86_64/syscalls/mprotect.S
+++ b/libc/arch-x86_64/syscalls/mprotect.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(mprotect)
diff --git a/libc/arch-x86_64/syscalls/mremap.S b/libc/arch-x86_64/syscalls/mremap.S
index 55e24bf..8af367e 100644
--- a/libc/arch-x86_64/syscalls/mremap.S
+++ b/libc/arch-x86_64/syscalls/mremap.S
@@ -11,7 +11,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(mremap)
diff --git a/libc/arch-x86_64/syscalls/msync.S b/libc/arch-x86_64/syscalls/msync.S
index 40524e3..c0ff0f9 100644
--- a/libc/arch-x86_64/syscalls/msync.S
+++ b/libc/arch-x86_64/syscalls/msync.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(msync)
diff --git a/libc/arch-x86_64/syscalls/munlock.S b/libc/arch-x86_64/syscalls/munlock.S
index b508259..d669f54 100644
--- a/libc/arch-x86_64/syscalls/munlock.S
+++ b/libc/arch-x86_64/syscalls/munlock.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(munlock)
diff --git a/libc/arch-x86_64/syscalls/munlockall.S b/libc/arch-x86_64/syscalls/munlockall.S
index 4314e2b..b7a9abc 100644
--- a/libc/arch-x86_64/syscalls/munlockall.S
+++ b/libc/arch-x86_64/syscalls/munlockall.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(munlockall)
diff --git a/libc/arch-x86_64/syscalls/munmap.S b/libc/arch-x86_64/syscalls/munmap.S
index 15d503c..4360bd0 100644
--- a/libc/arch-x86_64/syscalls/munmap.S
+++ b/libc/arch-x86_64/syscalls/munmap.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(munmap)
diff --git a/libc/arch-x86_64/syscalls/nanosleep.S b/libc/arch-x86_64/syscalls/nanosleep.S
index d303fcb..2eced5b 100644
--- a/libc/arch-x86_64/syscalls/nanosleep.S
+++ b/libc/arch-x86_64/syscalls/nanosleep.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(nanosleep)
diff --git a/libc/arch-x86_64/syscalls/personality.S b/libc/arch-x86_64/syscalls/personality.S
index 0379707..17ad7ee 100644
--- a/libc/arch-x86_64/syscalls/personality.S
+++ b/libc/arch-x86_64/syscalls/personality.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(personality)
diff --git a/libc/arch-x86_64/syscalls/pipe2.S b/libc/arch-x86_64/syscalls/pipe2.S
index d0a6768..83eb0a6 100644
--- a/libc/arch-x86_64/syscalls/pipe2.S
+++ b/libc/arch-x86_64/syscalls/pipe2.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(pipe2)
diff --git a/libc/arch-x86_64/syscalls/prctl.S b/libc/arch-x86_64/syscalls/prctl.S
index f7f561b..c79220d 100644
--- a/libc/arch-x86_64/syscalls/prctl.S
+++ b/libc/arch-x86_64/syscalls/prctl.S
@@ -11,7 +11,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(prctl)
diff --git a/libc/arch-x86_64/syscalls/pread64.S b/libc/arch-x86_64/syscalls/pread64.S
index 5828a06..1c4dc68 100644
--- a/libc/arch-x86_64/syscalls/pread64.S
+++ b/libc/arch-x86_64/syscalls/pread64.S
@@ -11,7 +11,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(pread64)
diff --git a/libc/arch-x86_64/syscalls/prlimit64.S b/libc/arch-x86_64/syscalls/prlimit64.S
index 12be53a..823feba 100644
--- a/libc/arch-x86_64/syscalls/prlimit64.S
+++ b/libc/arch-x86_64/syscalls/prlimit64.S
@@ -11,7 +11,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(prlimit64)
diff --git a/libc/arch-x86_64/syscalls/pwrite64.S b/libc/arch-x86_64/syscalls/pwrite64.S
index 1ada9d9..13bcb58 100644
--- a/libc/arch-x86_64/syscalls/pwrite64.S
+++ b/libc/arch-x86_64/syscalls/pwrite64.S
@@ -11,7 +11,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(pwrite64)
diff --git a/libc/arch-x86_64/syscalls/read.S b/libc/arch-x86_64/syscalls/read.S
index 0ff6c2a..400c87a 100644
--- a/libc/arch-x86_64/syscalls/read.S
+++ b/libc/arch-x86_64/syscalls/read.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(read)
diff --git a/libc/arch-x86_64/syscalls/readahead.S b/libc/arch-x86_64/syscalls/readahead.S
index a32c1c2..2a2978b 100644
--- a/libc/arch-x86_64/syscalls/readahead.S
+++ b/libc/arch-x86_64/syscalls/readahead.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(readahead)
diff --git a/libc/arch-x86_64/syscalls/readlinkat.S b/libc/arch-x86_64/syscalls/readlinkat.S
index a1c3ade..51d1f0c 100644
--- a/libc/arch-x86_64/syscalls/readlinkat.S
+++ b/libc/arch-x86_64/syscalls/readlinkat.S
@@ -11,7 +11,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(readlinkat)
diff --git a/libc/arch-x86_64/syscalls/readv.S b/libc/arch-x86_64/syscalls/readv.S
index a6f51cf..4199751 100644
--- a/libc/arch-x86_64/syscalls/readv.S
+++ b/libc/arch-x86_64/syscalls/readv.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(readv)
diff --git a/libc/arch-x86_64/syscalls/recvfrom.S b/libc/arch-x86_64/syscalls/recvfrom.S
index feb3a63..61ca1b2 100644
--- a/libc/arch-x86_64/syscalls/recvfrom.S
+++ b/libc/arch-x86_64/syscalls/recvfrom.S
@@ -11,7 +11,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(recvfrom)
diff --git a/libc/arch-x86_64/syscalls/recvmmsg.S b/libc/arch-x86_64/syscalls/recvmmsg.S
index 9da70e2..ce14ba5 100644
--- a/libc/arch-x86_64/syscalls/recvmmsg.S
+++ b/libc/arch-x86_64/syscalls/recvmmsg.S
@@ -11,7 +11,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(recvmmsg)
diff --git a/libc/arch-x86_64/syscalls/recvmsg.S b/libc/arch-x86_64/syscalls/recvmsg.S
index 6716aca..8655d07 100644
--- a/libc/arch-x86_64/syscalls/recvmsg.S
+++ b/libc/arch-x86_64/syscalls/recvmsg.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(recvmsg)
diff --git a/libc/arch-x86_64/syscalls/removexattr.S b/libc/arch-x86_64/syscalls/removexattr.S
index 89b2c4f..9736463 100644
--- a/libc/arch-x86_64/syscalls/removexattr.S
+++ b/libc/arch-x86_64/syscalls/removexattr.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(removexattr)
diff --git a/libc/arch-x86_64/syscalls/renameat.S b/libc/arch-x86_64/syscalls/renameat.S
index 9d69c3e..0be2ef9 100644
--- a/libc/arch-x86_64/syscalls/renameat.S
+++ b/libc/arch-x86_64/syscalls/renameat.S
@@ -11,7 +11,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(renameat)
diff --git a/libc/arch-x86_64/syscalls/sched_get_priority_max.S b/libc/arch-x86_64/syscalls/sched_get_priority_max.S
index 41b2d1d..0f92739 100644
--- a/libc/arch-x86_64/syscalls/sched_get_priority_max.S
+++ b/libc/arch-x86_64/syscalls/sched_get_priority_max.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(sched_get_priority_max)
diff --git a/libc/arch-x86_64/syscalls/sched_get_priority_min.S b/libc/arch-x86_64/syscalls/sched_get_priority_min.S
index 61b746f..8450e9d 100644
--- a/libc/arch-x86_64/syscalls/sched_get_priority_min.S
+++ b/libc/arch-x86_64/syscalls/sched_get_priority_min.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(sched_get_priority_min)
diff --git a/libc/arch-x86_64/syscalls/sched_getparam.S b/libc/arch-x86_64/syscalls/sched_getparam.S
index 23d34b2..a784640 100644
--- a/libc/arch-x86_64/syscalls/sched_getparam.S
+++ b/libc/arch-x86_64/syscalls/sched_getparam.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(sched_getparam)
diff --git a/libc/arch-x86_64/syscalls/sched_getscheduler.S b/libc/arch-x86_64/syscalls/sched_getscheduler.S
index 12f0ba0..090b322 100644
--- a/libc/arch-x86_64/syscalls/sched_getscheduler.S
+++ b/libc/arch-x86_64/syscalls/sched_getscheduler.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(sched_getscheduler)
diff --git a/libc/arch-x86_64/syscalls/sched_rr_get_interval.S b/libc/arch-x86_64/syscalls/sched_rr_get_interval.S
index 0ff852f..0977f2e 100644
--- a/libc/arch-x86_64/syscalls/sched_rr_get_interval.S
+++ b/libc/arch-x86_64/syscalls/sched_rr_get_interval.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(sched_rr_get_interval)
diff --git a/libc/arch-x86_64/syscalls/sched_setaffinity.S b/libc/arch-x86_64/syscalls/sched_setaffinity.S
index 250ecb6..af8e7a2 100644
--- a/libc/arch-x86_64/syscalls/sched_setaffinity.S
+++ b/libc/arch-x86_64/syscalls/sched_setaffinity.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(sched_setaffinity)
diff --git a/libc/arch-x86_64/syscalls/sched_setparam.S b/libc/arch-x86_64/syscalls/sched_setparam.S
index 30a7963..2964607 100644
--- a/libc/arch-x86_64/syscalls/sched_setparam.S
+++ b/libc/arch-x86_64/syscalls/sched_setparam.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(sched_setparam)
diff --git a/libc/arch-x86_64/syscalls/sched_setscheduler.S b/libc/arch-x86_64/syscalls/sched_setscheduler.S
index 137f9f0..333d1b8 100644
--- a/libc/arch-x86_64/syscalls/sched_setscheduler.S
+++ b/libc/arch-x86_64/syscalls/sched_setscheduler.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(sched_setscheduler)
diff --git a/libc/arch-x86_64/syscalls/sched_yield.S b/libc/arch-x86_64/syscalls/sched_yield.S
index 097c7dc..a972154 100644
--- a/libc/arch-x86_64/syscalls/sched_yield.S
+++ b/libc/arch-x86_64/syscalls/sched_yield.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(sched_yield)
diff --git a/libc/arch-x86_64/syscalls/sendfile.S b/libc/arch-x86_64/syscalls/sendfile.S
index 72e5de4..c1b6497 100644
--- a/libc/arch-x86_64/syscalls/sendfile.S
+++ b/libc/arch-x86_64/syscalls/sendfile.S
@@ -11,7 +11,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(sendfile)
diff --git a/libc/arch-x86_64/syscalls/sendmmsg.S b/libc/arch-x86_64/syscalls/sendmmsg.S
index 7407c12..940c0b6 100644
--- a/libc/arch-x86_64/syscalls/sendmmsg.S
+++ b/libc/arch-x86_64/syscalls/sendmmsg.S
@@ -11,7 +11,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(sendmmsg)
diff --git a/libc/arch-x86_64/syscalls/sendmsg.S b/libc/arch-x86_64/syscalls/sendmsg.S
index e56e58c..6d94bb6 100644
--- a/libc/arch-x86_64/syscalls/sendmsg.S
+++ b/libc/arch-x86_64/syscalls/sendmsg.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(sendmsg)
diff --git a/libc/arch-x86_64/syscalls/sendto.S b/libc/arch-x86_64/syscalls/sendto.S
index f0c14b0..bfe4636 100644
--- a/libc/arch-x86_64/syscalls/sendto.S
+++ b/libc/arch-x86_64/syscalls/sendto.S
@@ -11,7 +11,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(sendto)
diff --git a/libc/arch-x86_64/syscalls/setgid.S b/libc/arch-x86_64/syscalls/setgid.S
index abaf343..ef4fb31 100644
--- a/libc/arch-x86_64/syscalls/setgid.S
+++ b/libc/arch-x86_64/syscalls/setgid.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(setgid)
diff --git a/libc/arch-x86_64/syscalls/setgroups.S b/libc/arch-x86_64/syscalls/setgroups.S
index 4bbc7ec..65e6180 100644
--- a/libc/arch-x86_64/syscalls/setgroups.S
+++ b/libc/arch-x86_64/syscalls/setgroups.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(setgroups)
diff --git a/libc/arch-x86_64/syscalls/setitimer.S b/libc/arch-x86_64/syscalls/setitimer.S
index da81d0b..bee4996 100644
--- a/libc/arch-x86_64/syscalls/setitimer.S
+++ b/libc/arch-x86_64/syscalls/setitimer.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(setitimer)
diff --git a/libc/arch-x86_64/syscalls/setns.S b/libc/arch-x86_64/syscalls/setns.S
index bab147b..521769b 100644
--- a/libc/arch-x86_64/syscalls/setns.S
+++ b/libc/arch-x86_64/syscalls/setns.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(setns)
diff --git a/libc/arch-x86_64/syscalls/setpgid.S b/libc/arch-x86_64/syscalls/setpgid.S
index 6dfefa3..348612b 100644
--- a/libc/arch-x86_64/syscalls/setpgid.S
+++ b/libc/arch-x86_64/syscalls/setpgid.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(setpgid)
diff --git a/libc/arch-x86_64/syscalls/setpriority.S b/libc/arch-x86_64/syscalls/setpriority.S
index 89770e9..0940368 100644
--- a/libc/arch-x86_64/syscalls/setpriority.S
+++ b/libc/arch-x86_64/syscalls/setpriority.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(setpriority)
diff --git a/libc/arch-x86_64/syscalls/setregid.S b/libc/arch-x86_64/syscalls/setregid.S
index 9eaa7e9..0338ecf 100644
--- a/libc/arch-x86_64/syscalls/setregid.S
+++ b/libc/arch-x86_64/syscalls/setregid.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(setregid)
diff --git a/libc/arch-x86_64/syscalls/setresgid.S b/libc/arch-x86_64/syscalls/setresgid.S
index 95206b3..10e1244 100644
--- a/libc/arch-x86_64/syscalls/setresgid.S
+++ b/libc/arch-x86_64/syscalls/setresgid.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(setresgid)
diff --git a/libc/arch-x86_64/syscalls/setresuid.S b/libc/arch-x86_64/syscalls/setresuid.S
index c42dda9..229b11b 100644
--- a/libc/arch-x86_64/syscalls/setresuid.S
+++ b/libc/arch-x86_64/syscalls/setresuid.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(setresuid)
diff --git a/libc/arch-x86_64/syscalls/setreuid.S b/libc/arch-x86_64/syscalls/setreuid.S
index 935f751..e96e2d3 100644
--- a/libc/arch-x86_64/syscalls/setreuid.S
+++ b/libc/arch-x86_64/syscalls/setreuid.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(setreuid)
diff --git a/libc/arch-x86_64/syscalls/setrlimit.S b/libc/arch-x86_64/syscalls/setrlimit.S
index dd393ae..662587d 100644
--- a/libc/arch-x86_64/syscalls/setrlimit.S
+++ b/libc/arch-x86_64/syscalls/setrlimit.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(setrlimit)
diff --git a/libc/arch-x86_64/syscalls/setsid.S b/libc/arch-x86_64/syscalls/setsid.S
index 9c50a89..293ecf5 100644
--- a/libc/arch-x86_64/syscalls/setsid.S
+++ b/libc/arch-x86_64/syscalls/setsid.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(setsid)
diff --git a/libc/arch-x86_64/syscalls/setsockopt.S b/libc/arch-x86_64/syscalls/setsockopt.S
index 2332ec9..aee6613 100644
--- a/libc/arch-x86_64/syscalls/setsockopt.S
+++ b/libc/arch-x86_64/syscalls/setsockopt.S
@@ -11,7 +11,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(setsockopt)
diff --git a/libc/arch-x86_64/syscalls/settimeofday.S b/libc/arch-x86_64/syscalls/settimeofday.S
index 121c0b6..0d00c89 100644
--- a/libc/arch-x86_64/syscalls/settimeofday.S
+++ b/libc/arch-x86_64/syscalls/settimeofday.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(settimeofday)
diff --git a/libc/arch-x86_64/syscalls/setuid.S b/libc/arch-x86_64/syscalls/setuid.S
index f426705..19e2a10 100644
--- a/libc/arch-x86_64/syscalls/setuid.S
+++ b/libc/arch-x86_64/syscalls/setuid.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(setuid)
diff --git a/libc/arch-x86_64/syscalls/setxattr.S b/libc/arch-x86_64/syscalls/setxattr.S
index c02aa84..3e4d50b 100644
--- a/libc/arch-x86_64/syscalls/setxattr.S
+++ b/libc/arch-x86_64/syscalls/setxattr.S
@@ -11,7 +11,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(setxattr)
diff --git a/libc/arch-x86_64/syscalls/shutdown.S b/libc/arch-x86_64/syscalls/shutdown.S
index 96a65f8..346be33 100644
--- a/libc/arch-x86_64/syscalls/shutdown.S
+++ b/libc/arch-x86_64/syscalls/shutdown.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(shutdown)
diff --git a/libc/arch-x86_64/syscalls/sigaltstack.S b/libc/arch-x86_64/syscalls/sigaltstack.S
index 57dc41a..271fafc 100644
--- a/libc/arch-x86_64/syscalls/sigaltstack.S
+++ b/libc/arch-x86_64/syscalls/sigaltstack.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(sigaltstack)
diff --git a/libc/arch-x86_64/syscalls/socketpair.S b/libc/arch-x86_64/syscalls/socketpair.S
index 4e76e83..5466dc9 100644
--- a/libc/arch-x86_64/syscalls/socketpair.S
+++ b/libc/arch-x86_64/syscalls/socketpair.S
@@ -11,7 +11,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(socketpair)
diff --git a/libc/arch-x86_64/syscalls/getpid.S b/libc/arch-x86_64/syscalls/splice.S
similarity index 72%
copy from libc/arch-x86_64/syscalls/getpid.S
copy to libc/arch-x86_64/syscalls/splice.S
index 65b8df4..3c245a5 100644
--- a/libc/arch-x86_64/syscalls/getpid.S
+++ b/libc/arch-x86_64/syscalls/splice.S
@@ -2,15 +2,15 @@
 
 #include <private/bionic_asm.h>
 
-ENTRY(getpid)
-    movl    $__NR_getpid, %eax
+ENTRY(splice)
+    movq    %rcx, %r10
+    movl    $__NR_splice, %eax
     syscall
     cmpq    $-MAX_ERRNO, %rax
     jb      1f
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
-END(getpid)
+END(splice)
diff --git a/libc/arch-x86_64/syscalls/statfs64.S b/libc/arch-x86_64/syscalls/statfs64.S
index 9341d43..6a2637c 100644
--- a/libc/arch-x86_64/syscalls/statfs64.S
+++ b/libc/arch-x86_64/syscalls/statfs64.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(statfs64)
diff --git a/libc/arch-x86_64/syscalls/swapoff.S b/libc/arch-x86_64/syscalls/swapoff.S
index 2f2dafe..7e55758 100644
--- a/libc/arch-x86_64/syscalls/swapoff.S
+++ b/libc/arch-x86_64/syscalls/swapoff.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(swapoff)
diff --git a/libc/arch-x86_64/syscalls/swapon.S b/libc/arch-x86_64/syscalls/swapon.S
index 3db7921..d2f5f66 100644
--- a/libc/arch-x86_64/syscalls/swapon.S
+++ b/libc/arch-x86_64/syscalls/swapon.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(swapon)
diff --git a/libc/arch-x86_64/syscalls/symlinkat.S b/libc/arch-x86_64/syscalls/symlinkat.S
index 54b4d4e..5bbf1cb 100644
--- a/libc/arch-x86_64/syscalls/symlinkat.S
+++ b/libc/arch-x86_64/syscalls/symlinkat.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(symlinkat)
diff --git a/libc/arch-x86_64/syscalls/sync.S b/libc/arch-x86_64/syscalls/sync.S
index f58c788..9911715 100644
--- a/libc/arch-x86_64/syscalls/sync.S
+++ b/libc/arch-x86_64/syscalls/sync.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(sync)
diff --git a/libc/arch-x86_64/syscalls/sysinfo.S b/libc/arch-x86_64/syscalls/sysinfo.S
index d483693..104bb2c 100644
--- a/libc/arch-x86_64/syscalls/sysinfo.S
+++ b/libc/arch-x86_64/syscalls/sysinfo.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(sysinfo)
diff --git a/libc/arch-x86_64/syscalls/getpid.S b/libc/arch-x86_64/syscalls/tee.S
similarity index 72%
copy from libc/arch-x86_64/syscalls/getpid.S
copy to libc/arch-x86_64/syscalls/tee.S
index 65b8df4..ad5698c 100644
--- a/libc/arch-x86_64/syscalls/getpid.S
+++ b/libc/arch-x86_64/syscalls/tee.S
@@ -2,15 +2,15 @@
 
 #include <private/bionic_asm.h>
 
-ENTRY(getpid)
-    movl    $__NR_getpid, %eax
+ENTRY(tee)
+    movq    %rcx, %r10
+    movl    $__NR_tee, %eax
     syscall
     cmpq    $-MAX_ERRNO, %rax
     jb      1f
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
-END(getpid)
+END(tee)
diff --git a/libc/arch-x86_64/syscalls/tgkill.S b/libc/arch-x86_64/syscalls/tgkill.S
index 7d217b0..e3b9972 100644
--- a/libc/arch-x86_64/syscalls/tgkill.S
+++ b/libc/arch-x86_64/syscalls/tgkill.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(tgkill)
diff --git a/libc/arch-x86_64/syscalls/timerfd_create.S b/libc/arch-x86_64/syscalls/timerfd_create.S
index a518e4f..3f1b23a 100644
--- a/libc/arch-x86_64/syscalls/timerfd_create.S
+++ b/libc/arch-x86_64/syscalls/timerfd_create.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(timerfd_create)
diff --git a/libc/arch-x86_64/syscalls/timerfd_gettime.S b/libc/arch-x86_64/syscalls/timerfd_gettime.S
index 1d0853a..b1017ad 100644
--- a/libc/arch-x86_64/syscalls/timerfd_gettime.S
+++ b/libc/arch-x86_64/syscalls/timerfd_gettime.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(timerfd_gettime)
diff --git a/libc/arch-x86_64/syscalls/timerfd_settime.S b/libc/arch-x86_64/syscalls/timerfd_settime.S
index a23af4e..8610a1d 100644
--- a/libc/arch-x86_64/syscalls/timerfd_settime.S
+++ b/libc/arch-x86_64/syscalls/timerfd_settime.S
@@ -11,7 +11,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(timerfd_settime)
diff --git a/libc/arch-x86_64/syscalls/times.S b/libc/arch-x86_64/syscalls/times.S
index 520d062..07590b9 100644
--- a/libc/arch-x86_64/syscalls/times.S
+++ b/libc/arch-x86_64/syscalls/times.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(times)
diff --git a/libc/arch-x86_64/syscalls/truncate.S b/libc/arch-x86_64/syscalls/truncate.S
index dfb6687..db2121f 100644
--- a/libc/arch-x86_64/syscalls/truncate.S
+++ b/libc/arch-x86_64/syscalls/truncate.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(truncate)
diff --git a/libc/arch-x86_64/syscalls/umask.S b/libc/arch-x86_64/syscalls/umask.S
index 360ad71..badea76 100644
--- a/libc/arch-x86_64/syscalls/umask.S
+++ b/libc/arch-x86_64/syscalls/umask.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(umask)
diff --git a/libc/arch-x86_64/syscalls/umount2.S b/libc/arch-x86_64/syscalls/umount2.S
index e2de44b..93e6fa0 100644
--- a/libc/arch-x86_64/syscalls/umount2.S
+++ b/libc/arch-x86_64/syscalls/umount2.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(umount2)
diff --git a/libc/arch-x86_64/syscalls/uname.S b/libc/arch-x86_64/syscalls/uname.S
index 8ad40fa..4b0d1c5 100644
--- a/libc/arch-x86_64/syscalls/uname.S
+++ b/libc/arch-x86_64/syscalls/uname.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(uname)
diff --git a/libc/arch-x86_64/syscalls/unlinkat.S b/libc/arch-x86_64/syscalls/unlinkat.S
index 83bb59f..f322f7d 100644
--- a/libc/arch-x86_64/syscalls/unlinkat.S
+++ b/libc/arch-x86_64/syscalls/unlinkat.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(unlinkat)
diff --git a/libc/arch-x86_64/syscalls/unshare.S b/libc/arch-x86_64/syscalls/unshare.S
index 044af99..b5395c1 100644
--- a/libc/arch-x86_64/syscalls/unshare.S
+++ b/libc/arch-x86_64/syscalls/unshare.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(unshare)
diff --git a/libc/arch-x86_64/syscalls/utimensat.S b/libc/arch-x86_64/syscalls/utimensat.S
index 4d263ff..f90caf2 100644
--- a/libc/arch-x86_64/syscalls/utimensat.S
+++ b/libc/arch-x86_64/syscalls/utimensat.S
@@ -11,7 +11,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(utimensat)
diff --git a/libc/arch-x86_64/syscalls/getpid.S b/libc/arch-x86_64/syscalls/vmsplice.S
similarity index 71%
copy from libc/arch-x86_64/syscalls/getpid.S
copy to libc/arch-x86_64/syscalls/vmsplice.S
index 65b8df4..cc94cc6 100644
--- a/libc/arch-x86_64/syscalls/getpid.S
+++ b/libc/arch-x86_64/syscalls/vmsplice.S
@@ -2,15 +2,15 @@
 
 #include <private/bionic_asm.h>
 
-ENTRY(getpid)
-    movl    $__NR_getpid, %eax
+ENTRY(vmsplice)
+    movq    %rcx, %r10
+    movl    $__NR_vmsplice, %eax
     syscall
     cmpq    $-MAX_ERRNO, %rax
     jb      1f
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
-END(getpid)
+END(vmsplice)
diff --git a/libc/arch-x86_64/syscalls/wait4.S b/libc/arch-x86_64/syscalls/wait4.S
index 7de78ac..7948331 100644
--- a/libc/arch-x86_64/syscalls/wait4.S
+++ b/libc/arch-x86_64/syscalls/wait4.S
@@ -11,7 +11,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(wait4)
diff --git a/libc/arch-x86_64/syscalls/write.S b/libc/arch-x86_64/syscalls/write.S
index eab3904..7e3a563 100644
--- a/libc/arch-x86_64/syscalls/write.S
+++ b/libc/arch-x86_64/syscalls/write.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(write)
diff --git a/libc/arch-x86_64/syscalls/writev.S b/libc/arch-x86_64/syscalls/writev.S
index b21e3d6..5fc040a 100644
--- a/libc/arch-x86_64/syscalls/writev.S
+++ b/libc/arch-x86_64/syscalls/writev.S
@@ -10,7 +10,6 @@
     negl    %eax
     movl    %eax, %edi
     call    __set_errno
-    orq     $-1, %rax
 1:
     ret
 END(writev)
diff --git a/libc/arch-x86_64/x86_64.mk b/libc/arch-x86_64/x86_64.mk
index 2f0cf2d..234cf67 100644
--- a/libc/arch-x86_64/x86_64.mk
+++ b/libc/arch-x86_64/x86_64.mk
@@ -1,7 +1,6 @@
 # x86_64 specific configs
 
 libc_common_src_files_x86_64 := \
-    bionic/index.cpp \
     bionic/memchr.c \
     bionic/memrchr.c \
     bionic/strchr.cpp \
@@ -38,8 +37,6 @@
     arch-x86_64/bionic/__set_tls.c \
     arch-x86_64/bionic/sigsetjmp.S \
     arch-x86_64/bionic/syscall.S \
-    arch-x86_64/bionic/vfork.S \
-    bionic/__memcmp16.cpp \
 
 libc_bionic_src_files_x86_64 += \
     arch-x86_64/string/sse2-memcpy-slm.S \
diff --git a/libc/bionic/__memcmp16.cpp b/libc/bionic/__memcmp16.cpp
deleted file mode 100644
index eb3a08b..0000000
--- a/libc/bionic/__memcmp16.cpp
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
-Copyright (c) 2013 Intel Corporation
-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.
-
-    * Neither the name of Intel Corporation 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 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 <stddef.h>
-
-// Unoptimized version of __memcmp16.
-extern "C" int __memcmp16(const unsigned short* lhs, const unsigned short* rhs, size_t n) {
-  for (size_t i = 0; i < n; i++) {
-    if (*lhs != *rhs) {
-      return *lhs - *rhs;
-    }
-    lhs++;
-    rhs++;
-  }
-  return 0;
-}
diff --git a/libc/bionic/arc4random.c b/libc/bionic/arc4random.c
index 687030b..9bdf341 100644
--- a/libc/bionic/arc4random.c
+++ b/libc/bionic/arc4random.c
@@ -1,8 +1,9 @@
-/*      $OpenBSD: arc4random.c,v 1.19 2008/06/04 00:50:23 djm Exp $        */
+/*	$OpenBSD: arc4random.c,v 1.33 2014/06/13 18:58:58 deraadt Exp $	*/
 
 /*
  * Copyright (c) 1996, David Mazieres <dm@uun.org>
  * Copyright (c) 2008, Damien Miller <djm@openbsd.org>
+ * Copyright (c) 2013, Markus Friedl <markus@openbsd.org>
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -18,214 +19,236 @@
  */
 
 /*
- * Arc4 random number generator for OpenBSD.
- *
- * This code is derived from section 17.1 of Applied Cryptography,
- * second edition, which describes a stream cipher allegedly
- * compatible with RSA Labs "RC4" cipher (the actual description of
- * which is a trade secret).  The same algorithm is used as a stream
- * cipher called "arcfour" in Tatu Ylonen's ssh package.
- *
- * Here the stream cipher has been modified always to include the time
- * when initializing the state.  That makes it impossible to
- * regenerate the same random sequence twice, so this can't be used
- * for encryption, but will generate good random numbers.
- *
- * RC4 is a registered trademark of RSA Laboratories.
+ * ChaCha based random number generator for OpenBSD.
  */
 
 #include <fcntl.h>
 #include <limits.h>
 #include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
 #include <sys/types.h>
 #include <sys/param.h>
 #include <sys/time.h>
+#include <sys/mman.h>
+
+#if defined(__ANDROID__)
+#include <sys/stat.h>
+#include <linux/random.h>
+#include "private/libc_logging.h"
 #include "private/thread_private.h"
 
-/* BIONIC-BEGIN */
-/* this lock should protect the global variables in this file */
-static pthread_mutex_t  _arc4_lock = PTHREAD_MUTEX_INITIALIZER;
-#define  _ARC4_LOCK()      pthread_mutex_lock(&_arc4_lock)
-#define  _ARC4_UNLOCK()    pthread_mutex_unlock(&_arc4_lock)
-/* BIONIC-END */
+#define explicit_bzero(p, s) memset(p, 0, s)
+
+#undef MAP_ANON
+#define MAP_ANON (MAP_PRIVATE | MAP_ANONYMOUS)
+
+/*
+ * XXX Should be replaced with a proper entropy measure.
+ */
+static int
+gotdata(u_char *buf, size_t len)
+{
+	char	any_set = 0;
+	size_t	i;
+
+	for (i = 0; i < len; ++i)
+		any_set |= buf[i];
+	if (any_set == 0)
+		return -1;
+	return 0;
+}
+
+static int
+getentropy/*_urandom*/(u_char *buf, size_t len)
+{
+	int save_errno = errno;
+
+	int fd = TEMP_FAILURE_RETRY(open("/dev/urandom", O_RDONLY|O_CLOEXEC|O_NOFOLLOW, 0));
+	if (fd == -1) {
+		__libc_fatal("getentropy_urandom failed to open \"/dev/urandom\": %s",
+				strerror(errno));
+	}
+
+	/* Lightly verify that the device node looks sane */
+	struct stat st;
+	if (fstat(fd, &st) == -1 || !S_ISCHR(st.st_mode)) {
+		__libc_fatal("getentropy_urandom failed to fstat \"/dev/urandom\": %s",
+				strerror(errno));
+	}
+	int cnt;
+	if (ioctl(fd, RNDGETENTCNT, &cnt) == -1) {
+		__libc_fatal("getentropy_urandom failed to ioctl \"/dev/urandom\": %s",
+				strerror(errno));
+	}
+	for (size_t i = 0; i < len; ) {
+		size_t wanted = len - i;
+		ssize_t ret = TEMP_FAILURE_RETRY(read(fd, buf + i, wanted));
+
+		if (ret == -1) {
+			__libc_fatal("getentropy_urandom failed to read \"/dev/urandom\": %s",
+					strerror(errno));
+		}
+		i += ret;
+	}
+	close(fd);
+	if (gotdata(buf, len) == -1) {
+		__libc_fatal("getentropy_urandom failed to get enough entropy: %s",
+				strerror(errno));
+	}
+
+	errno = save_errno;
+	return 0;
+}
+#endif /* __ANDROID__ */
+
+#define KEYSTREAM_ONLY
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-parameter"
+#include "../upstream-openbsd/lib/libc/crypt/chacha_private.h"
+#pragma GCC diagnostic pop
 
 #ifdef __GNUC__
 #define inline __inline
-#else                           /* !__GNUC__ */
+#else				/* !__GNUC__ */
 #define inline
-#endif                          /* !__GNUC__ */
+#endif				/* !__GNUC__ */
 
-struct arc4_stream {
-        u_int8_t i;
-        u_int8_t j;
-        u_int8_t s[256];
-};
-
+#define KEYSZ	32
+#define IVSZ	8
+#define BLOCKSZ	64
+#define RSBUFSZ	(16*BLOCKSZ)
 static int rs_initialized;
-static struct arc4_stream rs;
-static pid_t arc4_stir_pid;
-static int arc4_count;
+static pid_t rs_stir_pid;
+static chacha_ctx *rs;		/* chacha context for random keystream */
+static u_char *rs_buf;		/* keystream blocks */
+static size_t rs_have;		/* valid bytes at end of rs_buf */
+static size_t rs_count;		/* bytes till reseed */
 
-static inline u_int8_t arc4_getbyte(void);
+static inline void _rs_rekey(u_char *dat, size_t datlen);
 
 static inline void
-arc4_init(void)
+_rs_init(u_char *buf, size_t n)
 {
-        int     n;
+	if (n < KEYSZ + IVSZ)
+		return;
 
-        for (n = 0; n < 256; n++)
-                rs.s[n] = n;
-        rs.i = 0;
-        rs.j = 0;
-}
+	if (rs == NULL && (rs = mmap(NULL, sizeof(*rs), PROT_READ|PROT_WRITE,
+	    MAP_ANON, -1, 0)) == MAP_FAILED)
+		abort();
+	if (rs_buf == NULL && (rs_buf = mmap(NULL, RSBUFSZ, PROT_READ|PROT_WRITE,
+	    MAP_ANON, -1, 0)) == MAP_FAILED)
+		abort();
 
-static inline void
-arc4_addrandom(u_char *dat, int datlen)
-{
-        int     n;
-        u_int8_t si;
-
-        rs.i--;
-        for (n = 0; n < 256; n++) {
-                rs.i = (rs.i + 1);
-                si = rs.s[rs.i];
-                rs.j = (rs.j + si + dat[n % datlen]);
-                rs.s[rs.i] = rs.s[rs.j];
-                rs.s[rs.j] = si;
-        }
-        rs.j = rs.i;
+	chacha_keysetup(rs, buf, KEYSZ * 8, 0);
+	chacha_ivsetup(rs, buf + KEYSZ);
 }
 
 static void
-arc4_stir(void)
+_rs_stir(void)
 {
-#if 1  /* BIONIC-BEGIN */
-	int     i, fd;
-	union {
-		struct timeval tv;
-		u_int rnd[128 / sizeof(u_int)];
-	}       rdat;
-	int	n;
+	u_char rnd[KEYSZ + IVSZ];
 
-        if (!rs_initialized) {
-                arc4_init();
-                rs_initialized = 1;
-        }
+	/* XXX */
+	(void) getentropy(rnd, sizeof rnd);
 
-	fd = open("/dev/urandom", O_RDONLY);
-	if (fd != -1) {
-		read(fd, rdat.rnd, sizeof(rdat.rnd));
-		close(fd);
-	}
-        else
-        {
-	    /* fd < 0 ?  Ah, what the heck. We'll just take
-	     * whatever was on the stack. just add a little more
-             * time-based randomness though
-             */
-            gettimeofday(&rdat.tv, NULL);
-        }
+	if (!rs_initialized) {
+		rs_initialized = 1;
+		_rs_init(rnd, sizeof(rnd));
+	} else
+		_rs_rekey(rnd, sizeof(rnd));
+	explicit_bzero(rnd, sizeof(rnd));
 
-        arc4_stir_pid = getpid();
-	arc4_addrandom((void *) &rdat, sizeof(rdat));
-#else  /* BIONIC-END */
-        int     i, mib[2];
-        size_t        len;
-        u_char rnd[128];
+	/* invalidate rs_buf */
+	rs_have = 0;
+	memset(rs_buf, 0, RSBUFSZ);
 
-        if (!rs_initialized) {
-                arc4_init();
-                rs_initialized = 1;
-        }
+	rs_count = 1600000;
+}
 
-        mib[0] = CTL_KERN;
-        mib[1] = KERN_ARND;
+static inline void
+_rs_stir_if_needed(size_t len)
+{
+	pid_t pid = getpid();
 
-        len = sizeof(rnd);
-        sysctl(mib, 2, rnd, &len, NULL, 0);
+	if (rs_count <= len || !rs_initialized || rs_stir_pid != pid) {
+		rs_stir_pid = pid;
+		_rs_stir();
+	} else
+		rs_count -= len;
+}
 
-        arc4_stir_pid = getpid();
-        arc4_addrandom(rnd, sizeof(rnd));
+static inline void
+_rs_rekey(u_char *dat, size_t datlen)
+{
+#ifndef KEYSTREAM_ONLY
+	memset(rs_buf, 0,RSBUFSZ);
 #endif
-        /*
-         * Discard early keystream, as per recommendations in:
-         * http://www.wisdom.weizmann.ac.il/~itsik/RC4/Papers/Rc4_ksa.ps
-         */
-        for (i = 0; i < 256; i++)
-                (void)arc4_getbyte();
-        arc4_count = 1600000;
+	/* fill rs_buf with the keystream */
+	chacha_encrypt_bytes(rs, rs_buf, rs_buf, RSBUFSZ);
+	/* mix in optional user provided data */
+	if (dat) {
+		size_t i, m;
+
+		m = MIN(datlen, KEYSZ + IVSZ);
+		for (i = 0; i < m; i++)
+			rs_buf[i] ^= dat[i];
+	}
+	/* immediately reinit for backtracking resistance */
+	_rs_init(rs_buf, KEYSZ + IVSZ);
+	memset(rs_buf, 0, KEYSZ + IVSZ);
+	rs_have = RSBUFSZ - KEYSZ - IVSZ;
 }
 
-static inline u_int8_t
-arc4_getbyte(void)
+static inline void
+_rs_random_buf(void *_buf, size_t n)
 {
-        u_int8_t si, sj;
+	u_char *buf = (u_char *)_buf;
+	size_t m;
 
-        rs.i = (rs.i + 1);
-        si = rs.s[rs.i];
-        rs.j = (rs.j + si);
-        sj = rs.s[rs.j];
-        rs.s[rs.i] = sj;
-        rs.s[rs.j] = si;
-        return (rs.s[(si + sj) & 0xff]);
+	_rs_stir_if_needed(n);
+	while (n > 0) {
+		if (rs_have > 0) {
+			m = MIN(n, rs_have);
+			memcpy(buf, rs_buf + RSBUFSZ - rs_have, m);
+			memset(rs_buf + RSBUFSZ - rs_have, 0, m);
+			buf += m;
+			n -= m;
+			rs_have -= m;
+		}
+		if (rs_have == 0)
+			_rs_rekey(NULL, 0);
+	}
 }
 
-static inline u_int32_t
-arc4_getword(void)
+static inline void
+_rs_random_u32(u_int32_t *val)
 {
-        u_int32_t val;
-        val = arc4_getbyte() << 24;
-        val |= arc4_getbyte() << 16;
-        val |= arc4_getbyte() << 8;
-        val |= arc4_getbyte();
-        return val;
-}
-
-void
-arc4random_stir(void)
-{
-        _ARC4_LOCK();
-        arc4_stir();
-        _ARC4_UNLOCK();
-}
-
-void
-arc4random_addrandom(u_char *dat, int datlen)
-{
-        _ARC4_LOCK();
-        if (!rs_initialized)
-                arc4_stir();
-        arc4_addrandom(dat, datlen);
-        _ARC4_UNLOCK();
+	_rs_stir_if_needed(sizeof(*val));
+	if (rs_have < sizeof(*val))
+		_rs_rekey(NULL, 0);
+	memcpy(val, rs_buf + RSBUFSZ - rs_have, sizeof(*val));
+	memset(rs_buf + RSBUFSZ - rs_have, 0, sizeof(*val));
+	rs_have -= sizeof(*val);
 }
 
 u_int32_t
 arc4random(void)
 {
-        u_int32_t val;
-        _ARC4_LOCK();
-        arc4_count -= 4;
-        if (arc4_count <= 0 || !rs_initialized || arc4_stir_pid != getpid())
-                arc4_stir();
-        val = arc4_getword();
-        _ARC4_UNLOCK();
-        return val;
+	u_int32_t val;
+
+	_ARC4_LOCK();
+	_rs_random_u32(&val);
+	_ARC4_UNLOCK();
+	return val;
 }
 
 void
-arc4random_buf(void *_buf, size_t n)
+arc4random_buf(void *buf, size_t n)
 {
-        u_char *buf = (u_char *)_buf;
-        _ARC4_LOCK();
-        if (!rs_initialized || arc4_stir_pid != getpid())
-                arc4_stir();
-        while (n--) {
-                if (--arc4_count <= 0)
-                        arc4_stir();
-                buf[n] = arc4_getbyte();
-        }
-        _ARC4_UNLOCK();
+	_ARC4_LOCK();
+	_rs_random_buf(buf, n);
+	_ARC4_UNLOCK();
 }
 
 /*
@@ -241,55 +264,25 @@
 u_int32_t
 arc4random_uniform(u_int32_t upper_bound)
 {
-        u_int32_t r, min;
+	u_int32_t r, min;
 
-        if (upper_bound < 2)
-                return 0;
+	if (upper_bound < 2)
+		return 0;
 
-#if (ULONG_MAX > 0xffffffffUL)
-        min = 0x100000000UL % upper_bound;
-#else
-        /* Calculate (2**32 % upper_bound) avoiding 64-bit math */
-        if (upper_bound > 0x80000000)
-                min = 1 + ~upper_bound;                /* 2**32 - upper_bound */
-        else {
-                /* (2**32 - (x * 2)) % x == 2**32 % x when x <= 2**31 */
-                min = ((0xffffffff - (upper_bound * 2)) + 1) % upper_bound;
-        }
-#endif
+	/* 2**32 % x == (2**32 - x) % x */
+	min = -upper_bound % upper_bound;
 
-        /*
-         * This could theoretically loop forever but each retry has
-         * p > 0.5 (worst case, usually far better) of selecting a
-         * number inside the range we need, so it should rarely need
-         * to re-roll.
-         */
-        for (;;) {
-                r = arc4random();
-                if (r >= min)
-                        break;
-        }
+	/*
+	 * This could theoretically loop forever but each retry has
+	 * p > 0.5 (worst case, usually far better) of selecting a
+	 * number inside the range we need, so it should rarely need
+	 * to re-roll.
+	 */
+	for (;;) {
+		r = arc4random();
+		if (r >= min)
+			break;
+	}
 
-        return r % upper_bound;
+	return r % upper_bound;
 }
-
-#if 0
-/*-------- Test code for i386 --------*/
-#include <stdio.h>
-#include <machine/pctr.h>
-int
-main(int argc, char **argv)
-{
-        const int iter = 1000000;
-        int     i;
-        pctrval v;
-
-        v = rdtsc();
-        for (i = 0; i < iter; i++)
-                arc4random();
-        v = rdtsc() - v;
-        v /= iter;
-
-        printf("%qd cycles\n", v);
-}
-#endif
diff --git a/libc/bionic/assert.cpp b/libc/bionic/assert.cpp
index ba67143..985fc38 100644
--- a/libc/bionic/assert.cpp
+++ b/libc/bionic/assert.cpp
@@ -34,10 +34,12 @@
 
 void __assert(const char* file, int line, const char* failed_expression) {
   __libc_fatal("%s:%d: assertion \"%s\" failed", file, line, failed_expression);
-  /* NOTREACHED */
 }
 
 void __assert2(const char* file, int line, const char* function, const char* failed_expression) {
   __libc_fatal("%s:%d: %s: assertion \"%s\" failed", file, line, function, failed_expression);
-  /* NOTREACHED */
+}
+
+extern "C" __LIBC_HIDDEN__ void longjmperror() {
+  __libc_fatal("longjmp botch");
 }
diff --git a/libc/bionic/clone.cpp b/libc/bionic/clone.cpp
index d38a422..0a0fdd5 100644
--- a/libc/bionic/clone.cpp
+++ b/libc/bionic/clone.cpp
@@ -31,11 +31,13 @@
 #include <stdlib.h>
 #include <stdarg.h>
 
+#include "pthread_internal.h"
+
 extern "C" pid_t __bionic_clone(uint32_t flags, void* child_stack, int* parent_tid, void* tls, int* child_tid, int (*fn)(void*), void* arg);
 extern "C" __noreturn void __exit(int status);
 
 // Called from the __bionic_clone assembler to call the thread function then exit.
-extern "C" __LIBC_HIDDEN__ void __bionic_clone_entry(int (*fn)(void*), void* arg) {
+extern "C" __LIBC_HIDDEN__ void __start_thread(int (*fn)(void*), void* arg) {
   int status = (*fn)(arg);
   __exit(status);
 }
@@ -64,5 +66,18 @@
   child_stack_addr &= ~0xf;
   child_stack = reinterpret_cast<void*>(child_stack_addr);
 
-  return __bionic_clone(flags, child_stack, parent_tid, new_tls, child_tid, fn, arg);
+  // Remember the parent pid and invalidate the cached value while we clone.
+  pthread_internal_t* self = __get_thread();
+  pid_t parent_pid = self->invalidate_cached_pid();
+
+  // Actually do the clone.
+  int clone_result = __bionic_clone(flags, child_stack, parent_tid, new_tls, child_tid, fn, arg);
+
+  // We're the parent, so put our known pid back in place.
+  // We leave the child without a cached pid, but:
+  // 1. pthread_create gives its children their own pthread_internal_t with the correct pid.
+  // 2. fork makes a clone system call directly.
+  // If any other cases become important, we could use a double trampoline like __pthread_start.
+  self->set_cached_pid(parent_pid);
+  return clone_result;
 }
diff --git a/libc/bionic/cmsg_nxthdr.cpp b/libc/bionic/cmsg_nxthdr.cpp
index 6f0a47c..8a2b33e 100644
--- a/libc/bionic/cmsg_nxthdr.cpp
+++ b/libc/bionic/cmsg_nxthdr.cpp
@@ -28,7 +28,7 @@
 
 #include <sys/socket.h>
 
-cmsghdr* cmsg_nxthdr(msghdr* msg, cmsghdr* cmsg) {
+cmsghdr* __cmsg_nxthdr(msghdr* msg, cmsghdr* cmsg) {
   cmsghdr* ptr;
   ptr = reinterpret_cast<cmsghdr*>(reinterpret_cast<char*>(cmsg) + CMSG_ALIGN(cmsg->cmsg_len));
   size_t len = reinterpret_cast<char*>(ptr+1) - reinterpret_cast<char*>(msg->msg_control);
@@ -37,3 +37,6 @@
   }
   return ptr;
 }
+
+// TODO: remove after NDK refresh.
+__weak_alias(cmsg_nxthdr, __cmsg_nxthdr);
diff --git a/libc/bionic/dirent.cpp b/libc/bionic/dirent.cpp
index 0f9b26a..7abc7f3 100644
--- a/libc/bionic/dirent.cpp
+++ b/libc/bionic/dirent.cpp
@@ -37,6 +37,8 @@
 #include "private/ErrnoRestorer.h"
 #include "private/ScopedPthreadMutexLocker.h"
 
+extern "C" int __getdents64(unsigned int, dirent*, unsigned int);
+
 struct DIR {
   int fd_;
   size_t available_bytes_;
@@ -81,7 +83,7 @@
 }
 
 static bool __fill_DIR(DIR* d) {
-  int rc = TEMP_FAILURE_RETRY(getdents(d->fd_, d->buff_, sizeof(d->buff_)));
+  int rc = TEMP_FAILURE_RETRY(__getdents64(d->fd_, d->buff_, sizeof(d->buff_)));
   if (rc <= 0) {
     return false;
   }
diff --git a/libc/bionic/fork.cpp b/libc/bionic/fork.cpp
index a0f98e4..6cfc736 100644
--- a/libc/bionic/fork.cpp
+++ b/libc/bionic/fork.cpp
@@ -31,19 +31,26 @@
 
 #include "pthread_internal.h"
 
+#define FORK_FLAGS (CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID | SIGCHLD)
+
 int fork() {
   __bionic_atfork_run_prepare();
 
   pthread_internal_t* self = __get_thread();
-  int flags = CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID | SIGCHLD;
+
+  // Remember the parent pid and invalidate the cached value while we fork.
+  pid_t parent_pid = self->invalidate_cached_pid();
+
 #if defined(__x86_64__) // sys_clone's last two arguments are flipped on x86-64.
-  int result = syscall(__NR_clone, flags, NULL, NULL, &(self->tid), NULL);
+  int result = syscall(__NR_clone, FORK_FLAGS, NULL, NULL, &(self->tid), NULL);
 #else
-  int result = syscall(__NR_clone, flags, NULL, NULL, NULL, &(self->tid));
+  int result = syscall(__NR_clone, FORK_FLAGS, NULL, NULL, NULL, &(self->tid));
 #endif
   if (result == 0) {
+    self->set_cached_pid(gettid());
     __bionic_atfork_run_child();
   } else {
+    self->set_cached_pid(parent_pid);
     __bionic_atfork_run_parent();
   }
   return result;
diff --git a/libc/bionic/ftime.c b/libc/bionic/ftime.c
deleted file mode 100644
index 6513593..0000000
--- a/libc/bionic/ftime.c
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (C) 2008 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 <sys/timeb.h>
-
-int ftime(struct timeb *tb)
-{
-    struct timeval  tv;
-    struct timezone tz;
-
-    if (gettimeofday (&tv, &tz) < 0)
-        return -1;
-
-    tb->time    = tv.tv_sec;
-    tb->millitm = (tv.tv_usec + 500) / 1000;
-
-    if (tb->millitm == 1000) {
-        ++tb->time;
-        tb->millitm = 0;
-    }
-    tb->timezone = tz.tz_minuteswest;
-    tb->dstflag  = tz.tz_dsttime;
-
-    return 0;
-}
diff --git a/libc/bionic/thread_atexit.cpp b/libc/bionic/getpid.cpp
similarity index 71%
copy from libc/bionic/thread_atexit.cpp
copy to libc/bionic/getpid.cpp
index 68c119d..a3d5b35 100644
--- a/libc/bionic/thread_atexit.cpp
+++ b/libc/bionic/getpid.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008 The Android Open Source Project
+ * Copyright (C) 2014 The Android Open Source Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -26,21 +26,22 @@
  * SUCH DAMAGE.
  */
 
-/* some simple glue used to make the BSD atexit code happy */
+#include <unistd.h>
 
-#include <pthread.h>
+#include "pthread_internal.h"
 
-static pthread_mutex_t g_atexit_lock = PTHREAD_MUTEX_INITIALIZER;
+extern "C" pid_t __getpid();
 
-__BEGIN_DECLS
-__LIBC_HIDDEN__ void _thread_atexit_lock();
-__LIBC_HIDDEN__ void _thread_atexit_unlock();
-__END_DECLS
+pid_t getpid() {
+  pthread_internal_t* self = __get_thread();
 
-void _thread_atexit_lock() {
-  pthread_mutex_lock(&g_atexit_lock);
-}
+  // Do we have a valid cached pid?
+  pid_t cached_pid;
+  if (__predict_true(self->get_cached_pid(&cached_pid))) {
+    return cached_pid;
+  }
 
-void _thread_atexit_unlock() {
-  pthread_mutex_unlock(&g_atexit_lock);
+  // We're still in the dynamic linker or we're in the middle of forking, so ask the kernel.
+  // We don't know whether it's safe to update the cached value, so don't try.
+  return __getpid();
 }
diff --git a/libc/bionic/jemalloc.cpp b/libc/bionic/jemalloc_wrapper.cpp
similarity index 77%
rename from libc/bionic/jemalloc.cpp
rename to libc/bionic/jemalloc_wrapper.cpp
index 625d789..d1fe960 100644
--- a/libc/bionic/jemalloc.cpp
+++ b/libc/bionic/jemalloc_wrapper.cpp
@@ -14,13 +14,19 @@
  * limitations under the License.
  */
 
+#include <sys/param.h>
 #include <unistd.h>
 
 #include "jemalloc.h"
+#include "private/bionic_macros.h"
 
 void* je_pvalloc(size_t bytes) {
   size_t pagesize = sysconf(_SC_PAGESIZE);
-  return je_memalign(pagesize, (bytes + pagesize - 1) & ~(pagesize - 1));
+  size_t size = BIONIC_ALIGN(bytes, pagesize);
+  if (size < bytes) {
+    return NULL;
+  }
+  return je_memalign(pagesize, size);
 }
 
 #ifdef je_memalign
@@ -31,11 +37,9 @@
 // but this is not true. Both glibc and dlmalloc round up to the next power
 // of 2, so we'll do the same.
 void* je_memalign_round_up_boundary(size_t boundary, size_t size) {
-  unsigned int power_of_2 = static_cast<unsigned int>(boundary);
-  if (power_of_2 != 0) {
-    power_of_2 = 1UL << (sizeof(unsigned int)*8 - 1 - __builtin_clz(power_of_2));
-    if (power_of_2 != boundary) {
-      boundary = power_of_2 << 1;
+  if (boundary != 0) {
+    if (!powerof2(boundary)) {
+      boundary = BIONIC_ROUND_UP_POWER_OF_2(boundary);
     }
   } else {
     boundary = 1;
diff --git a/libc/bionic/libc_init_common.cpp b/libc/bionic/libc_init_common.cpp
index abf2d36..fa61c3c 100644
--- a/libc/bionic/libc_init_common.cpp
+++ b/libc/bionic/libc_init_common.cpp
@@ -86,21 +86,24 @@
 void __libc_init_tls(KernelArgumentBlock& args) {
   __libc_auxv = args.auxv;
 
-  uintptr_t stack_top = (__get_sp() & ~(PAGE_SIZE - 1)) + PAGE_SIZE;
-  size_t stack_size = get_main_thread_stack_size();
-  uintptr_t stack_bottom = stack_top - stack_size;
-
   static void* tls[BIONIC_TLS_SLOTS];
   static pthread_internal_t main_thread;
   main_thread.tls = tls;
 
   // Tell the kernel to clear our tid field when we exit, so we're like any other pthread.
+  // As a side-effect, this tells us our pid (which is the same as the main thread's tid).
   main_thread.tid = __set_tid_address(&main_thread.tid);
+  main_thread.set_cached_pid(main_thread.tid);
 
-  // We already have a stack, and we don't want to free it up on exit (because things like
-  // environment variables with global scope live on it).
+  // Work out the extent of the main thread's stack.
+  uintptr_t stack_top = (__get_sp() & ~(PAGE_SIZE - 1)) + PAGE_SIZE;
+  size_t stack_size = get_main_thread_stack_size();
+  void* stack_bottom = reinterpret_cast<void*>(stack_top - stack_size);
+
+  // We don't want to free the main thread's stack even when the main thread exits
+  // because things like environment variables with global scope live on it.
   pthread_attr_init(&main_thread.attr);
-  pthread_attr_setstack(&main_thread.attr, (void*) stack_bottom, stack_size);
+  pthread_attr_setstack(&main_thread.attr, stack_bottom, stack_size);
   main_thread.attr.flags = PTHREAD_ATTR_FLAG_USER_ALLOCATED_STACK | PTHREAD_ATTR_FLAG_MAIN_THREAD;
 
   __init_thread(&main_thread, false);
diff --git a/libc/bionic/libc_init_common.h b/libc/bionic/libc_init_common.h
index 59dc7df..3032f99 100644
--- a/libc/bionic/libc_init_common.h
+++ b/libc/bionic/libc_init_common.h
@@ -43,14 +43,14 @@
 __noreturn void __libc_init(void* raw_args,
                             void (*onexit)(void),
                             int (*slingshot)(int, char**, char**),
-                            structors_array_t const * const structors);
-void __libc_fini(void* finit_array);
+                            structors_array_t const* const structors);
+__LIBC_HIDDEN__ void __libc_fini(void* finit_array);
 
 __END_DECLS
 
 #if defined(__cplusplus)
 class KernelArgumentBlock;
-void __LIBC_HIDDEN__ __libc_init_common(KernelArgumentBlock& args);
+__LIBC_HIDDEN__ void __libc_init_common(KernelArgumentBlock& args);
 #endif
 
 #endif
diff --git a/libc/bionic/malloc_debug_check.cpp b/libc/bionic/malloc_debug_check.cpp
index 2590ce7..e4e4c2e 100644
--- a/libc/bionic/malloc_debug_check.cpp
+++ b/libc/bionic/malloc_debug_check.cpp
@@ -38,6 +38,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/param.h>
 #include <sys/socket.h>
 #include <sys/system_properties.h>
 #include <sys/types.h>
@@ -47,14 +48,11 @@
 
 #include "debug_mapinfo.h"
 #include "debug_stacktrace.h"
-#include "private/libc_logging.h"
 #include "malloc_debug_common.h"
+#include "private/bionic_macros.h"
+#include "private/libc_logging.h"
 #include "private/ScopedPthreadMutexLocker.h"
 
-/* libc.debug.malloc.backlog */
-extern unsigned int g_malloc_debug_backlog;
-extern int g_malloc_debug_level;
-
 #define MAX_BACKTRACE_DEPTH 16
 #define ALLOCATION_TAG      0x1ee7d00d
 #define BACKLOG_TAG         0xbabecafe
@@ -120,6 +118,12 @@
 static hdr_t* backlog_head;
 static pthread_mutex_t backlog_lock = PTHREAD_MUTEX_INITIALIZER;
 
+// This variable is set to the value of property libc.debug.malloc.backlog.
+// It determines the size of the backlog we use to detect multiple frees.
+static unsigned g_malloc_debug_backlog = 100;
+
+__LIBC_HIDDEN__ HashTable* g_hash_table;
+
 static inline void init_front_guard(hdr_t* hdr) {
     memset(hdr->front_guard, FRONT_GUARD, FRONT_GUARD_LEN);
 }
@@ -324,14 +328,19 @@
     }
 }
 
-extern "C" void* chk_malloc(size_t size) {
+extern "C" void* chk_malloc(size_t bytes) {
 //  log_message("%s: %s\n", __FILE__, __FUNCTION__);
 
-    hdr_t* hdr = static_cast<hdr_t*>(Malloc(malloc)(sizeof(hdr_t) + size + sizeof(ftr_t)));
+    size_t size = sizeof(hdr_t) + bytes + sizeof(ftr_t);
+    if (size < bytes) { // Overflow
+        errno = ENOMEM;
+        return NULL;
+    }
+    hdr_t* hdr = static_cast<hdr_t*>(Malloc(malloc)(size));
     if (hdr) {
         hdr->base = hdr;
         hdr->bt_depth = get_backtrace(hdr->bt, MAX_BACKTRACE_DEPTH);
-        add(hdr, size);
+        add(hdr, bytes);
         return user(hdr);
     }
     return NULL;
@@ -343,8 +352,8 @@
     }
 
     // Make the alignment a power of two.
-    if (alignment & (alignment-1)) {
-        alignment = 1L << (31 - __builtin_clz(alignment));
+    if (!powerof2(alignment)) {
+        alignment = BIONIC_ROUND_UP_POWER_OF_2(alignment);
     }
 
     // here, alignment is at least MALLOC_ALIGNMENT<<1 bytes
@@ -409,15 +418,15 @@
     }
 }
 
-extern "C" void* chk_realloc(void* ptr, size_t size) {
+extern "C" void* chk_realloc(void* ptr, size_t bytes) {
 //  log_message("%s: %s\n", __FILE__, __FUNCTION__);
 
     if (!ptr) {
-        return chk_malloc(size);
+        return chk_malloc(bytes);
     }
 
 #ifdef REALLOC_ZERO_BYTES_FREE
-    if (!size) {
+    if (!bytes) {
         chk_free(ptr);
         return NULL;
     }
@@ -430,7 +439,7 @@
         int depth = get_backtrace(bt, MAX_BACKTRACE_DEPTH);
         if (hdr->tag == BACKLOG_TAG) {
             log_message("+++ REALLOCATION %p SIZE %d OF FREED MEMORY!\n",
-                       user(hdr), size, hdr->size);
+                       user(hdr), bytes, hdr->size);
             log_message("+++ ALLOCATION %p SIZE %d ALLOCATED HERE:\n",
                        user(hdr), hdr->size);
             log_backtrace(hdr->bt, hdr->bt_depth);
@@ -449,47 +458,54 @@
             del_from_backlog(hdr);
         } else {
             log_message("+++ REALLOCATION %p SIZE %d IS CORRUPTED OR NOT ALLOCATED VIA TRACKER!\n",
-                       user(hdr), size);
+                       user(hdr), bytes);
             log_backtrace(bt, depth);
             // just get a whole new allocation and leak the old one
-            return Malloc(realloc)(0, size);
-            // return realloc(user(hdr), size); // assuming it was allocated externally
+            return Malloc(realloc)(0, bytes);
+            // return realloc(user(hdr), bytes); // assuming it was allocated externally
         }
     }
 
+    size_t size = sizeof(hdr_t) + bytes + sizeof(ftr_t);
+    if (size < bytes) { // Overflow
+        errno = ENOMEM;
+        return NULL;
+    }
     if (hdr->base != hdr) {
         // An allocation from memalign, so create another allocation and
         // copy the data out.
-        void* newMem = Malloc(malloc)(sizeof(hdr_t) + size + sizeof(ftr_t));
-        if (newMem) {
-            memcpy(newMem, hdr, sizeof(hdr_t) + hdr->size);
-            Malloc(free)(hdr->base);
-            hdr = static_cast<hdr_t*>(newMem);
-        } else {
-            Malloc(free)(hdr->base);
-            hdr = NULL;
+        void* newMem = Malloc(malloc)(size);
+        if (newMem == NULL) {
+            return NULL;
         }
+        memcpy(newMem, hdr, sizeof(hdr_t) + hdr->size);
+        Malloc(free)(hdr->base);
+        hdr = static_cast<hdr_t*>(newMem);
     } else {
-        hdr = static_cast<hdr_t*>(Malloc(realloc)(hdr, sizeof(hdr_t) + size + sizeof(ftr_t)));
+        hdr = static_cast<hdr_t*>(Malloc(realloc)(hdr, size));
     }
     if (hdr) {
         hdr->base = hdr;
         hdr->bt_depth = get_backtrace(hdr->bt, MAX_BACKTRACE_DEPTH);
-        add(hdr, size);
+        add(hdr, bytes);
         return user(hdr);
     }
-
     return NULL;
 }
 
-extern "C" void* chk_calloc(int nmemb, size_t size) {
+extern "C" void* chk_calloc(size_t nmemb, size_t bytes) {
 //  log_message("%s: %s\n", __FILE__, __FUNCTION__);
-    size_t total_size = nmemb * size;
-    hdr_t* hdr = static_cast<hdr_t*>(Malloc(calloc)(1, sizeof(hdr_t) + total_size + sizeof(ftr_t)));
+    size_t total_bytes = nmemb * bytes;
+    size_t size = sizeof(hdr_t) + total_bytes + sizeof(ftr_t);
+    if (size < total_bytes || (nmemb && SIZE_MAX / nmemb < bytes)) { // Overflow
+        errno = ENOMEM;
+        return NULL;
+    }
+    hdr_t* hdr = static_cast<hdr_t*>(Malloc(calloc)(1, size));
     if (hdr) {
         hdr->base = hdr;
         hdr->bt_depth = get_backtrace(hdr->bt, MAX_BACKTRACE_DEPTH);
-        add(hdr, total_size);
+        add(hdr, total_bytes);
         return user(hdr);
     }
     return NULL;
@@ -507,12 +523,34 @@
     return hdr->size;
 }
 
-static void ReportMemoryLeaks() {
-  // We only track leaks at level 10.
-  if (g_malloc_debug_level != 10) {
-    return;
-  }
+extern "C" struct mallinfo chk_mallinfo() {
+  return Malloc(mallinfo)();
+}
 
+extern "C" int chk_posix_memalign(void** memptr, size_t alignment, size_t size) {
+  if (!powerof2(alignment)) {
+    return EINVAL;
+  }
+  int saved_errno = errno;
+  *memptr = chk_memalign(alignment, size);
+  errno = saved_errno;
+  return (*memptr != NULL) ? 0 : ENOMEM;
+}
+
+extern "C" void* chk_pvalloc(size_t bytes) {
+  size_t pagesize = sysconf(_SC_PAGESIZE);
+  size_t size = BIONIC_ALIGN(bytes, pagesize);
+  if (size < bytes) { // Overflow
+    return NULL;
+  }
+  return chk_memalign(pagesize, size);
+}
+
+extern "C" void* chk_valloc(size_t size) {
+  return chk_memalign(sysconf(_SC_PAGESIZE), size);
+}
+
+static void ReportMemoryLeaks() {
   // Use /proc/self/exe link to obtain the program name for logging
   // purposes. If it's not available, we set it to "<unknown>".
   char exe[PATH_MAX];
@@ -546,12 +584,23 @@
   }
 }
 
-extern "C" int malloc_debug_initialize() {
+extern "C" bool malloc_debug_initialize(HashTable* hash_table) {
+  g_hash_table = hash_table;
+
+  char debug_backlog[PROP_VALUE_MAX];
+  if (__system_property_get("libc.debug.malloc.backlog", debug_backlog)) {
+    g_malloc_debug_backlog = atoi(debug_backlog);
+    info_log("%s: setting backlog length to %d\n", getprogname(), g_malloc_debug_backlog);
+  }
+
   backtrace_startup();
-  return 0;
+  return true;
 }
 
-extern "C" void malloc_debug_finalize() {
-  ReportMemoryLeaks();
+extern "C" void malloc_debug_finalize(int malloc_debug_level) {
+  // We only track leaks at level 10.
+  if (malloc_debug_level == 10) {
+    ReportMemoryLeaks();
+  }
   backtrace_shutdown();
 }
diff --git a/libc/bionic/malloc_debug_common.cpp b/libc/bionic/malloc_debug_common.cpp
index db3f995..cbca160 100644
--- a/libc/bionic/malloc_debug_common.cpp
+++ b/libc/bionic/malloc_debug_common.cpp
@@ -26,19 +26,17 @@
  * SUCH DAMAGE.
  */
 
-/*
- * Contains definition of structures, global variables, and implementation of
- * routines that are used by malloc leak detection code and other components in
- * the system. The trick is that some components expect these data and
- * routines to be defined / implemented in libc.so library, regardless
- * whether or not MALLOC_LEAK_CHECK macro is defined. To make things even
- * more tricky, malloc leak detection code, implemented in
- * libc_malloc_debug.so also requires access to these variables and routines
- * (to fill allocation entry hash table, for example). So, all relevant
- * variables and routines are defined / implemented here and exported
- * to all, leak detection code and other components via dynamic (libc.so),
- * or static (libc.a) linking.
- */
+// Contains definition of structures, global variables, and implementation of
+// routines that are used by malloc leak detection code and other components in
+// the system. The trick is that some components expect these data and
+// routines to be defined / implemented in libc.so library, regardless
+// whether or not MALLOC_LEAK_CHECK macro is defined. To make things even
+// more tricky, malloc leak detection code, implemented in
+// libc_malloc_debug.so also requires access to these variables and routines
+// (to fill allocation entry hash table, for example). So, all relevant
+// variables and routines are defined / implemented here and exported
+// to all, leak detection code and other components via dynamic (libc.so),
+// or static (libc.a) linking.
 
 #include "malloc_debug_common.h"
 
@@ -48,475 +46,473 @@
 
 #include "private/ScopedPthreadMutexLocker.h"
 
-/*
- * In a VM process, this is set to 1 after fork()ing out of zygote.
- */
+// In a VM process, this is set to 1 after fork()ing out of zygote.
 int gMallocLeakZygoteChild = 0;
 
-__LIBC_HIDDEN__ pthread_mutex_t g_allocations_mutex = PTHREAD_MUTEX_INITIALIZER;
-__LIBC_HIDDEN__ HashTable g_hash_table;
+static HashTable g_hash_table;
+
+// Support for malloc debugging.
+// Table for dispatching malloc calls, initialized with default dispatchers.
+static const MallocDebug __libc_malloc_default_dispatch __attribute__((aligned(32))) = {
+  Malloc(calloc),
+  Malloc(free),
+  Malloc(mallinfo),
+  Malloc(malloc),
+  Malloc(malloc_usable_size),
+  Malloc(memalign),
+  Malloc(posix_memalign),
+#if defined(HAVE_DEPRECATED_MALLOC_FUNCS)
+  Malloc(pvalloc),
+#endif
+  Malloc(realloc),
+#if defined(HAVE_DEPRECATED_MALLOC_FUNCS)
+  Malloc(valloc),
+#endif
+};
+
+// Selector of dispatch table to use for dispatching malloc calls.
+// TODO: fix http://b/15432753 and make this static again.
+const MallocDebug* __libc_malloc_dispatch = &__libc_malloc_default_dispatch;
+
+// Handle to shared library where actual memory allocation is implemented.
+// This library is loaded and memory allocation calls are redirected there
+// when libc.debug.malloc environment variable contains value other than
+// zero:
+// 1  - For memory leak detections.
+// 5  - For filling allocated / freed memory with patterns defined by
+//      CHK_SENTINEL_VALUE, and CHK_FILL_FREE macros.
+// 10 - For adding pre-, and post- allocation stubs in order to detect
+//      buffer overruns.
+// Note that emulator's memory allocation instrumentation is not controlled by
+// libc.debug.malloc value, but rather by emulator, started with -memcheck
+// option. Note also, that if emulator has started with -memcheck option,
+// emulator's instrumented memory allocation will take over value saved in
+// libc.debug.malloc. In other words, if emulator has started with -memcheck
+// option, libc.debug.malloc value is ignored.
+// Actual functionality for debug levels 1-10 is implemented in
+// libc_malloc_debug_leak.so, while functionality for emulator's instrumented
+// allocations is implemented in libc_malloc_debug_qemu.so and can be run inside
+// the emulator only.
+#if !defined(LIBC_STATIC)
+static void* libc_malloc_impl_handle = NULL;
+#endif
+
+
+// The value of libc.debug.malloc.
+#if !defined(LIBC_STATIC)
+static int g_malloc_debug_level = 0;
+#endif
 
 // =============================================================================
 // output functions
 // =============================================================================
 
 static int hash_entry_compare(const void* arg1, const void* arg2) {
-    int result;
+  int result;
 
-    const HashEntry* e1 = *static_cast<HashEntry* const*>(arg1);
-    const HashEntry* e2 = *static_cast<HashEntry* const*>(arg2);
+  const HashEntry* e1 = *static_cast<HashEntry* const*>(arg1);
+  const HashEntry* e2 = *static_cast<HashEntry* const*>(arg2);
 
-    // if one or both arg pointers are null, deal gracefully
-    if (e1 == NULL) {
-        result = (e2 == NULL) ? 0 : 1;
-    } else if (e2 == NULL) {
-        result = -1;
+  // if one or both arg pointers are null, deal gracefully
+  if (e1 == NULL) {
+    result = (e2 == NULL) ? 0 : 1;
+  } else if (e2 == NULL) {
+    result = -1;
+  } else {
+    size_t nbAlloc1 = e1->allocations;
+    size_t nbAlloc2 = e2->allocations;
+    size_t size1 = e1->size & ~SIZE_FLAG_MASK;
+    size_t size2 = e2->size & ~SIZE_FLAG_MASK;
+    size_t alloc1 = nbAlloc1 * size1;
+    size_t alloc2 = nbAlloc2 * size2;
+
+    // sort in descending order by:
+    // 1) total size
+    // 2) number of allocations
+    //
+    // This is used for sorting, not determination of equality, so we don't
+    // need to compare the bit flags.
+    if (alloc1 > alloc2) {
+      result = -1;
+    } else if (alloc1 < alloc2) {
+      result = 1;
     } else {
-        size_t nbAlloc1 = e1->allocations;
-        size_t nbAlloc2 = e2->allocations;
-        size_t size1 = e1->size & ~SIZE_FLAG_MASK;
-        size_t size2 = e2->size & ~SIZE_FLAG_MASK;
-        size_t alloc1 = nbAlloc1 * size1;
-        size_t alloc2 = nbAlloc2 * size2;
-
-        // sort in descending order by:
-        // 1) total size
-        // 2) number of allocations
-        //
-        // This is used for sorting, not determination of equality, so we don't
-        // need to compare the bit flags.
-        if (alloc1 > alloc2) {
-            result = -1;
-        } else if (alloc1 < alloc2) {
-            result = 1;
-        } else {
-            if (nbAlloc1 > nbAlloc2) {
-                result = -1;
-            } else if (nbAlloc1 < nbAlloc2) {
-                result = 1;
-            } else {
-                result = 0;
-            }
-        }
+      if (nbAlloc1 > nbAlloc2) {
+        result = -1;
+      } else if (nbAlloc1 < nbAlloc2) {
+        result = 1;
+      } else {
+        result = 0;
+      }
     }
-    return result;
+  }
+  return result;
 }
 
-/*
- * Retrieve native heap information.
- *
- * "*info" is set to a buffer we allocate
- * "*overallSize" is set to the size of the "info" buffer
- * "*infoSize" is set to the size of a single entry
- * "*totalMemory" is set to the sum of all allocations we're tracking; does
- *   not include heap overhead
- * "*backtraceSize" is set to the maximum number of entries in the back trace
- */
+// Retrieve native heap information.
+//
+// "*info" is set to a buffer we allocate
+// "*overallSize" is set to the size of the "info" buffer
+// "*infoSize" is set to the size of a single entry
+// "*totalMemory" is set to the sum of all allocations we're tracking; does
+//   not include heap overhead
+// "*backtraceSize" is set to the maximum number of entries in the back trace
 
+// =============================================================================
 // Exported for use by ddms.
+// =============================================================================
 extern "C" void get_malloc_leak_info(uint8_t** info, size_t* overallSize,
-        size_t* infoSize, size_t* totalMemory, size_t* backtraceSize) {
-    // don't do anything if we have invalid arguments
-    if (info == NULL || overallSize == NULL || infoSize == NULL ||
-            totalMemory == NULL || backtraceSize == NULL) {
-        return;
+    size_t* infoSize, size_t* totalMemory, size_t* backtraceSize) {
+  // Don't do anything if we have invalid arguments.
+  if (info == NULL || overallSize == NULL || infoSize == NULL ||
+    totalMemory == NULL || backtraceSize == NULL) {
+    return;
+  }
+  *totalMemory = 0;
+
+  ScopedPthreadMutexLocker locker(&g_hash_table.lock);
+  if (g_hash_table.count == 0) {
+    *info = NULL;
+    *overallSize = 0;
+    *infoSize = 0;
+    *backtraceSize = 0;
+    return;
+  }
+
+  HashEntry** list = static_cast<HashEntry**>(Malloc(malloc)(sizeof(void*) * g_hash_table.count));
+
+  // Get the entries into an array to be sorted.
+  size_t index = 0;
+  for (size_t i = 0 ; i < HASHTABLE_SIZE ; ++i) {
+    HashEntry* entry = g_hash_table.slots[i];
+    while (entry != NULL) {
+      list[index] = entry;
+      *totalMemory = *totalMemory + ((entry->size & ~SIZE_FLAG_MASK) * entry->allocations);
+      index++;
+      entry = entry->next;
     }
-    *totalMemory = 0;
+  }
 
-    ScopedPthreadMutexLocker locker(&g_allocations_mutex);
+  // XXX: the protocol doesn't allow variable size for the stack trace (yet)
+  *infoSize = (sizeof(size_t) * 2) + (sizeof(uintptr_t) * BACKTRACE_SIZE);
+  *overallSize = *infoSize * g_hash_table.count;
+  *backtraceSize = BACKTRACE_SIZE;
 
-    if (g_hash_table.count == 0) {
-        *info = NULL;
-        *overallSize = 0;
-        *infoSize = 0;
-        *backtraceSize = 0;
-        return;
-    }
-
-    HashEntry** list = static_cast<HashEntry**>(Malloc(malloc)(sizeof(void*) * g_hash_table.count));
-
-    // get the entries into an array to be sorted
-    int index = 0;
-    for (size_t i = 0 ; i < HASHTABLE_SIZE ; ++i) {
-        HashEntry* entry = g_hash_table.slots[i];
-        while (entry != NULL) {
-            list[index] = entry;
-            *totalMemory = *totalMemory +
-                ((entry->size & ~SIZE_FLAG_MASK) * entry->allocations);
-            index++;
-            entry = entry->next;
-        }
-    }
-
-    // XXX: the protocol doesn't allow variable size for the stack trace (yet)
-    *infoSize = (sizeof(size_t) * 2) + (sizeof(uintptr_t) * BACKTRACE_SIZE);
-    *overallSize = *infoSize * g_hash_table.count;
-    *backtraceSize = BACKTRACE_SIZE;
-
-    // now get a byte array big enough for this
-    *info = static_cast<uint8_t*>(Malloc(malloc)(*overallSize));
-
-    if (*info == NULL) {
-        *overallSize = 0;
-        Malloc(free)(list);
-        return;
-    }
-
-    qsort(list, g_hash_table.count, sizeof(void*), hash_entry_compare);
-
-    uint8_t* head = *info;
-    const int count = g_hash_table.count;
-    for (int i = 0 ; i < count ; ++i) {
-        HashEntry* entry = list[i];
-        size_t entrySize = (sizeof(size_t) * 2) + (sizeof(uintptr_t) * entry->numEntries);
-        if (entrySize < *infoSize) {
-            /* we're writing less than a full entry, clear out the rest */
-            memset(head + entrySize, 0, *infoSize - entrySize);
-        } else {
-            /* make sure the amount we're copying doesn't exceed the limit */
-            entrySize = *infoSize;
-        }
-        memcpy(head, &(entry->size), entrySize);
-        head += *infoSize;
-    }
-
+  // now get a byte array big enough for this
+  *info = static_cast<uint8_t*>(Malloc(malloc)(*overallSize));
+  if (*info == NULL) {
+    *overallSize = 0;
     Malloc(free)(list);
+    return;
+  }
+
+  qsort(list, g_hash_table.count, sizeof(void*), hash_entry_compare);
+
+  uint8_t* head = *info;
+  const size_t count = g_hash_table.count;
+  for (size_t i = 0 ; i < count ; ++i) {
+    HashEntry* entry = list[i];
+    size_t entrySize = (sizeof(size_t) * 2) + (sizeof(uintptr_t) * entry->numEntries);
+    if (entrySize < *infoSize) {
+      // We're writing less than a full entry, clear out the rest.
+      memset(head + entrySize, 0, *infoSize - entrySize);
+    } else {
+      // Make sure the amount we're copying doesn't exceed the limit.
+      entrySize = *infoSize;
+    }
+    memcpy(head, &(entry->size), entrySize);
+    head += *infoSize;
+  }
+
+  Malloc(free)(list);
 }
 
-// Exported for use by ddms.
 extern "C" void free_malloc_leak_info(uint8_t* info) {
-    Malloc(free)(info);
+  Malloc(free)(info);
 }
 
-extern "C" struct mallinfo mallinfo() {
-    return Malloc(mallinfo)();
-}
-
-extern "C" void* valloc(size_t bytes) {
-    return Malloc(valloc)(bytes);
-}
-
-extern "C" void* pvalloc(size_t bytes) {
-    return Malloc(pvalloc)(bytes);
-}
-
-extern "C" int posix_memalign(void** memptr, size_t alignment, size_t size) {
-    return Malloc(posix_memalign)(memptr, alignment, size);
-}
-
-// Support for malloc debugging.
-// Table for dispatching malloc calls, initialized with default dispatchers.
-extern const MallocDebug __libc_malloc_default_dispatch;
-const MallocDebug __libc_malloc_default_dispatch __attribute__((aligned(32))) =
-{
-    Malloc(malloc), Malloc(free), Malloc(calloc), Malloc(realloc), Malloc(memalign), Malloc(malloc_usable_size),
-};
-
-/* Selector of dispatch table to use for dispatching malloc calls. */
-const MallocDebug* __libc_malloc_dispatch = &__libc_malloc_default_dispatch;
-
-extern "C" void* malloc(size_t bytes) {
-    return __libc_malloc_dispatch->malloc(bytes);
+// =============================================================================
+// Allocation functions
+// =============================================================================
+extern "C" void* calloc(size_t n_elements, size_t elem_size) {
+  return __libc_malloc_dispatch->calloc(n_elements, elem_size);
 }
 
 extern "C" void free(void* mem) {
-    __libc_malloc_dispatch->free(mem);
+  __libc_malloc_dispatch->free(mem);
 }
 
-extern "C" void* calloc(size_t n_elements, size_t elem_size) {
-    return __libc_malloc_dispatch->calloc(n_elements, elem_size);
+extern "C" struct mallinfo mallinfo() {
+  return __libc_malloc_dispatch->mallinfo();
 }
 
-extern "C" void* realloc(void* oldMem, size_t bytes) {
-    return __libc_malloc_dispatch->realloc(oldMem, bytes);
-}
-
-extern "C" void* memalign(size_t alignment, size_t bytes) {
-    return __libc_malloc_dispatch->memalign(alignment, bytes);
+extern "C" void* malloc(size_t bytes) {
+  return __libc_malloc_dispatch->malloc(bytes);
 }
 
 extern "C" size_t malloc_usable_size(const void* mem) {
-    return __libc_malloc_dispatch->malloc_usable_size(mem);
+  return __libc_malloc_dispatch->malloc_usable_size(mem);
 }
 
-/* We implement malloc debugging only in libc.so, so code below
- * must be excluded if we compile this file for static libc.a
- */
+extern "C" void* memalign(size_t alignment, size_t bytes) {
+  return __libc_malloc_dispatch->memalign(alignment, bytes);
+}
+
+extern "C" int posix_memalign(void** memptr, size_t alignment, size_t size) {
+  return __libc_malloc_dispatch->posix_memalign(memptr, alignment, size);
+}
+
+#if defined(HAVE_DEPRECATED_MALLOC_FUNCS)
+extern "C" void* pvalloc(size_t bytes) {
+  return __libc_malloc_dispatch->pvalloc(bytes);
+}
+#endif
+
+extern "C" void* realloc(void* oldMem, size_t bytes) {
+  return __libc_malloc_dispatch->realloc(oldMem, bytes);
+}
+
+#if defined(HAVE_DEPRECATED_MALLOC_FUNCS)
+extern "C" void* valloc(size_t bytes) {
+  return __libc_malloc_dispatch->valloc(bytes);
+}
+#endif
+
+// We implement malloc debugging only in libc.so, so the code below
+// must be excluded if we compile this file for static libc.a
 #ifndef LIBC_STATIC
 #include <sys/system_properties.h>
 #include <dlfcn.h>
 #include <stdio.h>
 #include "private/libc_logging.h"
 
-/* Table for dispatching malloc calls, depending on environment. */
-static MallocDebug g_malloc_dispatch_table __attribute__((aligned(32))) = {
-    Malloc(malloc), Malloc(free), Malloc(calloc), Malloc(realloc), Malloc(memalign), Malloc(malloc_usable_size)
-};
-
-extern const char* __progname;
-
-/* Handle to shared library where actual memory allocation is implemented.
- * This library is loaded and memory allocation calls are redirected there
- * when libc.debug.malloc environment variable contains value other than
- * zero:
- * 1  - For memory leak detections.
- * 5  - For filling allocated / freed memory with patterns defined by
- *      CHK_SENTINEL_VALUE, and CHK_FILL_FREE macros.
- * 10 - For adding pre-, and post- allocation stubs in order to detect
- *      buffer overruns.
- * Note that emulator's memory allocation instrumentation is not controlled by
- * libc.debug.malloc value, but rather by emulator, started with -memcheck
- * option. Note also, that if emulator has started with -memcheck option,
- * emulator's instrumented memory allocation will take over value saved in
- * libc.debug.malloc. In other words, if emulator has started with -memcheck
- * option, libc.debug.malloc value is ignored.
- * Actual functionality for debug levels 1-10 is implemented in
- * libc_malloc_debug_leak.so, while functionality for emultor's instrumented
- * allocations is implemented in libc_malloc_debug_qemu.so and can be run inside
- * the emulator only.
- */
-static void* libc_malloc_impl_handle = NULL;
-
-/* This variable is set to the value of property libc.debug.malloc.backlog,
- * when the value of libc.debug.malloc = 10.  It determines the size of the
- * backlog we use to detect multiple frees.  If the property is not set, the
- * backlog length defaults to BACKLOG_DEFAULT_LEN.
- */
-__LIBC_HIDDEN__ unsigned int g_malloc_debug_backlog;
-#define BACKLOG_DEFAULT_LEN 100
-
-/* The value of libc.debug.malloc. */
-__LIBC_HIDDEN__ int g_malloc_debug_level;
-
 template<typename FunctionType>
 static void InitMallocFunction(void* malloc_impl_handler, FunctionType* func, const char* prefix, const char* suffix) {
-    char symbol[128];
-    snprintf(symbol, sizeof(symbol), "%s_%s", prefix, suffix);
-    *func = reinterpret_cast<FunctionType>(dlsym(malloc_impl_handler, symbol));
-    if (*func == NULL) {
-        error_log("%s: dlsym(\"%s\") failed", __progname, symbol);
-    }
+  char symbol[128];
+  snprintf(symbol, sizeof(symbol), "%s_%s", prefix, suffix);
+  *func = reinterpret_cast<FunctionType>(dlsym(malloc_impl_handler, symbol));
+  if (*func == NULL) {
+    error_log("%s: dlsym(\"%s\") failed", getprogname(), symbol);
+  }
 }
 
 static void InitMalloc(void* malloc_impl_handler, MallocDebug* table, const char* prefix) {
-    __libc_format_log(ANDROID_LOG_INFO, "libc", "%s: using libc.debug.malloc %d (%s)\n",
-                      __progname, g_malloc_debug_level, prefix);
+  __libc_format_log(ANDROID_LOG_INFO, "libc", "%s: using libc.debug.malloc %d (%s)\n",
+                    getprogname(), g_malloc_debug_level, prefix);
 
-    InitMallocFunction<MallocDebugMalloc>(malloc_impl_handler, &table->malloc, prefix, "malloc");
-    InitMallocFunction<MallocDebugFree>(malloc_impl_handler, &table->free, prefix, "free");
-    InitMallocFunction<MallocDebugCalloc>(malloc_impl_handler, &table->calloc, prefix, "calloc");
-    InitMallocFunction<MallocDebugRealloc>(malloc_impl_handler, &table->realloc, prefix, "realloc");
-    InitMallocFunction<MallocDebugMemalign>(malloc_impl_handler, &table->memalign, prefix, "memalign");
-    InitMallocFunction<MallocDebugMallocUsableSize>(malloc_impl_handler, &table->malloc_usable_size, prefix, "malloc_usable_size");
+  InitMallocFunction<MallocDebugCalloc>(malloc_impl_handler, &table->calloc, prefix, "calloc");
+  InitMallocFunction<MallocDebugFree>(malloc_impl_handler, &table->free, prefix, "free");
+  InitMallocFunction<MallocDebugMallinfo>(malloc_impl_handler, &table->mallinfo, prefix, "mallinfo");
+  InitMallocFunction<MallocDebugMalloc>(malloc_impl_handler, &table->malloc, prefix, "malloc");
+  InitMallocFunction<MallocDebugMallocUsableSize>(malloc_impl_handler, &table->malloc_usable_size, prefix, "malloc_usable_size");
+  InitMallocFunction<MallocDebugMemalign>(malloc_impl_handler, &table->memalign, prefix, "memalign");
+  InitMallocFunction<MallocDebugPosixMemalign>(malloc_impl_handler, &table->posix_memalign, prefix, "posix_memalign");
+#if defined(HAVE_DEPRECATED_MALLOC_FUNCS)
+  InitMallocFunction<MallocDebugPvalloc>(malloc_impl_handler, &table->pvalloc, prefix, "pvalloc");
+#endif
+  InitMallocFunction<MallocDebugRealloc>(malloc_impl_handler, &table->realloc, prefix, "realloc");
+#if defined(HAVE_DEPRECATED_MALLOC_FUNCS)
+  InitMallocFunction<MallocDebugValloc>(malloc_impl_handler, &table->valloc, prefix, "valloc");
+#endif
 }
 
-/* Initializes memory allocation framework once per process. */
+// Initializes memory allocation framework once per process.
 static void malloc_init_impl() {
-    const char* so_name = NULL;
-    MallocDebugInit malloc_debug_initialize = NULL;
-    unsigned int qemu_running = 0;
-    unsigned int memcheck_enabled = 0;
-    char env[PROP_VALUE_MAX];
-    char memcheck_tracing[PROP_VALUE_MAX];
-    char debug_program[PROP_VALUE_MAX];
+  const char* so_name = NULL;
+  MallocDebugInit malloc_debug_initialize = NULL;
+  unsigned int qemu_running = 0;
+  unsigned int memcheck_enabled = 0;
+  char env[PROP_VALUE_MAX];
+  char memcheck_tracing[PROP_VALUE_MAX];
+  char debug_program[PROP_VALUE_MAX];
 
-    /* Get custom malloc debug level. Note that emulator started with
-     * memory checking option will have priority over debug level set in
-     * libc.debug.malloc system property. */
-    if (__system_property_get("ro.kernel.qemu", env) && atoi(env)) {
-        qemu_running = 1;
-        if (__system_property_get("ro.kernel.memcheck", memcheck_tracing)) {
-            if (memcheck_tracing[0] != '0') {
-                // Emulator has started with memory tracing enabled. Enforce it.
-                g_malloc_debug_level = 20;
-                memcheck_enabled = 1;
-            }
-        }
+  // Get custom malloc debug level. Note that emulator started with
+  // memory checking option will have priority over debug level set in
+  // libc.debug.malloc system property.
+  if (__system_property_get("ro.kernel.qemu", env) && atoi(env)) {
+    qemu_running = 1;
+    if (__system_property_get("ro.kernel.memcheck", memcheck_tracing)) {
+      if (memcheck_tracing[0] != '0') {
+        // Emulator has started with memory tracing enabled. Enforce it.
+        g_malloc_debug_level = 20;
+        memcheck_enabled = 1;
+      }
     }
+  }
 
-    /* If debug level has not been set by memcheck option in the emulator,
-     * lets grab it from libc.debug.malloc system property. */
-    if (g_malloc_debug_level == 0 && __system_property_get("libc.debug.malloc", env)) {
-        g_malloc_debug_level = atoi(env);
+  // If debug level has not been set by memcheck option in the emulator,
+  // lets grab it from libc.debug.malloc system property.
+  if (g_malloc_debug_level == 0 && __system_property_get("libc.debug.malloc", env)) {
+    g_malloc_debug_level = atoi(env);
+  }
+
+  // Debug level 0 means that we should use default allocation routines.
+  if (g_malloc_debug_level == 0) {
+    return;
+  }
+
+  // If libc.debug.malloc.program is set and is not a substring of progname,
+  // then exit.
+  if (__system_property_get("libc.debug.malloc.program", debug_program)) {
+    if (!strstr(getprogname(), debug_program)) {
+      return;
     }
+  }
 
-    /* Debug level 0 means that we should use default allocation routines. */
-    if (g_malloc_debug_level == 0) {
+  // mksh is way too leaky. http://b/7291287.
+  if (g_malloc_debug_level >= 10) {
+    if (strcmp(getprogname(), "sh") == 0 || strcmp(getprogname(), "/system/bin/sh") == 0) {
+      return;
+    }
+  }
+
+  // Choose the appropriate .so for the requested debug level.
+  switch (g_malloc_debug_level) {
+    case 1:
+    case 5:
+    case 10:
+      so_name = "libc_malloc_debug_leak.so";
+      break;
+    case 20:
+      // Quick check: debug level 20 can only be handled in emulator.
+      if (!qemu_running) {
+        error_log("%s: Debug level %d can only be set in emulator\n",
+                  getprogname(), g_malloc_debug_level);
         return;
-    }
-
-    /* If libc.debug.malloc.program is set and is not a substring of progname,
-     * then exit.
-     */
-    if (__system_property_get("libc.debug.malloc.program", debug_program)) {
-        if (!strstr(__progname, debug_program)) {
-            return;
-        }
-    }
-
-    // mksh is way too leaky. http://b/7291287.
-    if (g_malloc_debug_level >= 10) {
-        if (strcmp(__progname, "sh") == 0 || strcmp(__progname, "/system/bin/sh") == 0) {
-            return;
-        }
-    }
-
-    // Choose the appropriate .so for the requested debug level.
-    switch (g_malloc_debug_level) {
-        case 1:
-        case 5:
-        case 10: {
-            char debug_backlog[PROP_VALUE_MAX];
-            if (__system_property_get("libc.debug.malloc.backlog", debug_backlog)) {
-                g_malloc_debug_backlog = atoi(debug_backlog);
-                info_log("%s: setting backlog length to %d\n", __progname, g_malloc_debug_backlog);
-            }
-            if (g_malloc_debug_backlog == 0) {
-                g_malloc_debug_backlog = BACKLOG_DEFAULT_LEN;
-            }
-            so_name = "libc_malloc_debug_leak.so";
-            break;
-        }
-        case 20:
-            // Quick check: debug level 20 can only be handled in emulator.
-            if (!qemu_running) {
-                error_log("%s: Debug level %d can only be set in emulator\n",
-                          __progname, g_malloc_debug_level);
-                return;
-            }
-            // Make sure that memory checking has been enabled in emulator.
-            if (!memcheck_enabled) {
-                error_log("%s: Memory checking is not enabled in the emulator\n",
-                          __progname);
-                return;
-            }
-            so_name = "libc_malloc_debug_qemu.so";
-            break;
-        default:
-            error_log("%s: Debug level %d is unknown\n", __progname, g_malloc_debug_level);
-            return;
-    }
-
-    // Load .so that implements the required malloc debugging functionality.
-    void* malloc_impl_handle = dlopen(so_name, RTLD_LAZY);
-    if (malloc_impl_handle == NULL) {
-        error_log("%s: Missing module %s required for malloc debug level %d: %s",
-                  __progname, so_name, g_malloc_debug_level, dlerror());
+      }
+      // Make sure that memory checking has been enabled in emulator.
+      if (!memcheck_enabled) {
+        error_log("%s: Memory checking is not enabled in the emulator\n", getprogname());
         return;
+      }
+      so_name = "libc_malloc_debug_qemu.so";
+      break;
+    default:
+      error_log("%s: Debug level %d is unknown\n", getprogname(), g_malloc_debug_level);
+      return;
+  }
+
+  // Load .so that implements the required malloc debugging functionality.
+  void* malloc_impl_handle = dlopen(so_name, RTLD_LAZY);
+  if (malloc_impl_handle == NULL) {
+    error_log("%s: Missing module %s required for malloc debug level %d: %s",
+              getprogname(), so_name, g_malloc_debug_level, dlerror());
+    return;
+  }
+
+  // Initialize malloc debugging in the loaded module.
+  malloc_debug_initialize = reinterpret_cast<MallocDebugInit>(dlsym(malloc_impl_handle,
+                                                                    "malloc_debug_initialize"));
+  if (malloc_debug_initialize == NULL) {
+    error_log("%s: Initialization routine is not found in %s\n", getprogname(), so_name);
+    dlclose(malloc_impl_handle);
+    return;
+  }
+  if (malloc_debug_initialize(&g_hash_table) == -1) {
+    dlclose(malloc_impl_handle);
+    return;
+  }
+
+  if (g_malloc_debug_level == 20) {
+    // For memory checker we need to do extra initialization.
+    typedef int (*MemCheckInit)(int, const char*);
+    MemCheckInit memcheck_initialize =
+      reinterpret_cast<MemCheckInit>(dlsym(malloc_impl_handle, "memcheck_initialize"));
+    if (memcheck_initialize == NULL) {
+      error_log("%s: memcheck_initialize routine is not found in %s\n",
+                getprogname(), so_name);
+      dlclose(malloc_impl_handle);
+      return;
     }
 
-    // Initialize malloc debugging in the loaded module.
-    malloc_debug_initialize = reinterpret_cast<MallocDebugInit>(dlsym(malloc_impl_handle,
-                                                                      "malloc_debug_initialize"));
-    if (malloc_debug_initialize == NULL) {
-        error_log("%s: Initialization routine is not found in %s\n",
-                  __progname, so_name);
-        dlclose(malloc_impl_handle);
-        return;
+    if (memcheck_initialize(MALLOC_ALIGNMENT, memcheck_tracing)) {
+      dlclose(malloc_impl_handle);
+      return;
     }
-    if (malloc_debug_initialize() == -1) {
-        dlclose(malloc_impl_handle);
-        return;
-    }
+  }
 
-    if (g_malloc_debug_level == 20) {
-        // For memory checker we need to do extra initialization.
-        typedef int (*MemCheckInit)(int, const char*);
-        MemCheckInit memcheck_initialize =
-            reinterpret_cast<MemCheckInit>(dlsym(malloc_impl_handle,
-                                                 "memcheck_initialize"));
-        if (memcheck_initialize == NULL) {
-            error_log("%s: memcheck_initialize routine is not found in %s\n",
-                      __progname, so_name);
-            dlclose(malloc_impl_handle);
-            return;
-        }
+  // No need to init the dispatch table because we can only get
+  // here if debug level is 1, 5, 10, or 20.
+  static MallocDebug malloc_dispatch_table __attribute__((aligned(32)));
+  switch (g_malloc_debug_level) {
+    case 1:
+      InitMalloc(malloc_impl_handle, &malloc_dispatch_table, "leak");
+      break;
+    case 5:
+      InitMalloc(malloc_impl_handle, &malloc_dispatch_table, "fill");
+      break;
+    case 10:
+      InitMalloc(malloc_impl_handle, &malloc_dispatch_table, "chk");
+      break;
+    case 20:
+      InitMalloc(malloc_impl_handle, &malloc_dispatch_table, "qemu_instrumented");
+      break;
+    default:
+      break;
+  }
 
-        if (memcheck_initialize(MALLOC_ALIGNMENT, memcheck_tracing)) {
-            dlclose(malloc_impl_handle);
-            return;
-        }
-    }
-
-
-    // Initialize malloc dispatch table with appropriate routines.
-    switch (g_malloc_debug_level) {
-        case 1:
-            InitMalloc(malloc_impl_handle, &g_malloc_dispatch_table, "leak");
-            break;
-        case 5:
-            InitMalloc(malloc_impl_handle, &g_malloc_dispatch_table, "fill");
-            break;
-        case 10:
-            InitMalloc(malloc_impl_handle, &g_malloc_dispatch_table, "chk");
-            break;
-        case 20:
-            InitMalloc(malloc_impl_handle, &g_malloc_dispatch_table, "qemu_instrumented");
-            break;
-        default:
-            break;
-    }
-
-    // Make sure dispatch table is initialized
-    if ((g_malloc_dispatch_table.malloc == NULL) ||
-        (g_malloc_dispatch_table.free == NULL) ||
-        (g_malloc_dispatch_table.calloc == NULL) ||
-        (g_malloc_dispatch_table.realloc == NULL) ||
-        (g_malloc_dispatch_table.memalign == NULL) ||
-        (g_malloc_dispatch_table.malloc_usable_size == NULL)) {
-        error_log("%s: some symbols for libc.debug.malloc level %d were not found (see above)",
-                  __progname, g_malloc_debug_level);
-        dlclose(malloc_impl_handle);
-    } else {
-        __libc_malloc_dispatch = &g_malloc_dispatch_table;
-        libc_malloc_impl_handle = malloc_impl_handle;
-    }
+  // Make sure dispatch table is initialized
+  if ((malloc_dispatch_table.calloc == NULL) ||
+      (malloc_dispatch_table.free == NULL) ||
+      (malloc_dispatch_table.mallinfo == NULL) ||
+      (malloc_dispatch_table.malloc == NULL) ||
+      (malloc_dispatch_table.malloc_usable_size == NULL) ||
+      (malloc_dispatch_table.memalign == NULL) ||
+      (malloc_dispatch_table.posix_memalign == NULL) ||
+#if defined(HAVE_DEPRECATED_MALLOC_FUNCS)
+      (malloc_dispatch_table.pvalloc == NULL) ||
+#endif
+      (malloc_dispatch_table.realloc == NULL)
+#if defined(HAVE_DEPRECATED_MALLOC_FUNCS)
+      || (malloc_dispatch_table.valloc == NULL)
+#endif
+      ) {
+    error_log("%s: some symbols for libc.debug.malloc level %d were not found (see above)",
+              getprogname(), g_malloc_debug_level);
+    dlclose(malloc_impl_handle);
+  } else {
+    __libc_malloc_dispatch = &malloc_dispatch_table;
+    libc_malloc_impl_handle = malloc_impl_handle;
+  }
 }
 
 static void malloc_fini_impl() {
-    // Our BSD stdio implementation doesn't close the standard streams, it only flushes them.
-    // And it doesn't do that until its atexit handler (_cleanup) is run, and we run first!
-    // It's great that other unclosed FILE*s show up as malloc leaks, but we need to manually
-    // clean up the standard streams ourselves.
-    fclose(stdin);
-    fclose(stdout);
-    fclose(stderr);
+  // Our BSD stdio implementation doesn't close the standard streams, it only flushes them.
+  // And it doesn't do that until its atexit handler is run, and we run first!
+  // It's great that other unclosed FILE*s show up as malloc leaks, but we need to manually
+  // clean up the standard streams ourselves.
+  fclose(stdin);
+  fclose(stdout);
+  fclose(stderr);
 
-    if (libc_malloc_impl_handle != NULL) {
-        MallocDebugFini malloc_debug_finalize =
-            reinterpret_cast<MallocDebugFini>(dlsym(libc_malloc_impl_handle,
-                                                    "malloc_debug_finalize"));
-        if (malloc_debug_finalize != NULL) {
-            malloc_debug_finalize();
-        }
+  if (libc_malloc_impl_handle != NULL) {
+    MallocDebugFini malloc_debug_finalize =
+      reinterpret_cast<MallocDebugFini>(dlsym(libc_malloc_impl_handle, "malloc_debug_finalize"));
+    if (malloc_debug_finalize != NULL) {
+      malloc_debug_finalize(g_malloc_debug_level);
     }
+  }
 }
 
-static pthread_once_t  malloc_init_once_ctl = PTHREAD_ONCE_INIT;
-static pthread_once_t  malloc_fini_once_ctl = PTHREAD_ONCE_INIT;
-
 #endif  // !LIBC_STATIC
 
-/* Initializes memory allocation framework.
- * This routine is called from __libc_init routines implemented
- * in libc_init_static.c and libc_init_dynamic.c files.
- */
+// Initializes memory allocation framework.
+// This routine is called from __libc_init routines implemented
+// in libc_init_static.c and libc_init_dynamic.c files.
 extern "C" __LIBC_HIDDEN__ void malloc_debug_init() {
-    /* We need to initialize malloc iff we implement here custom
-     * malloc routines (i.e. USE_DL_PREFIX is defined) for libc.so */
-#if defined(USE_DL_PREFIX) && !defined(LIBC_STATIC)
-    if (pthread_once(&malloc_init_once_ctl, malloc_init_impl)) {
-        error_log("Unable to initialize malloc_debug component.");
-    }
-#endif  // USE_DL_PREFIX && !LIBC_STATIC
+#if !defined(LIBC_STATIC)
+  static pthread_once_t malloc_init_once_ctl = PTHREAD_ONCE_INIT;
+  if (pthread_once(&malloc_init_once_ctl, malloc_init_impl)) {
+    error_log("Unable to initialize malloc_debug component.");
+  }
+#endif  // !LIBC_STATIC
 }
 
 extern "C" __LIBC_HIDDEN__ void malloc_debug_fini() {
-    /* We need to finalize malloc iff we implement here custom
-     * malloc routines (i.e. USE_DL_PREFIX is defined) for libc.so */
-#if defined(USE_DL_PREFIX) && !defined(LIBC_STATIC)
-    if (pthread_once(&malloc_fini_once_ctl, malloc_fini_impl)) {
-        error_log("Unable to finalize malloc_debug component.");
-    }
-#endif  // USE_DL_PREFIX && !LIBC_STATIC
+#if !defined(LIBC_STATIC)
+  static pthread_once_t malloc_fini_once_ctl = PTHREAD_ONCE_INIT;
+  if (pthread_once(&malloc_fini_once_ctl, malloc_fini_impl)) {
+    error_log("Unable to finalize malloc_debug component.");
+  }
+#endif  // !LIBC_STATIC
 }
diff --git a/libc/bionic/malloc_debug_common.h b/libc/bionic/malloc_debug_common.h
index c1c3c89..fb2f03d 100644
--- a/libc/bionic/malloc_debug_common.h
+++ b/libc/bionic/malloc_debug_common.h
@@ -33,8 +33,11 @@
 #ifndef MALLOC_DEBUG_COMMON_H
 #define MALLOC_DEBUG_COMMON_H
 
+#include <pthread.h>
+#include <stdint.h>
 #include <stdlib.h>
 
+#include "private/bionic_config.h"
 #include "private/libc_logging.h"
 
 #define HASHTABLE_SIZE      1543
@@ -43,8 +46,6 @@
 #define SIZE_FLAG_ZYGOTE_CHILD  (1<<31)
 #define SIZE_FLAG_MASK          (SIZE_FLAG_ZYGOTE_CHILD)
 
-#define MAX_SIZE_T           (~(size_t)0)
-
 // This must match the alignment used by the malloc implementation.
 #ifndef MALLOC_ALIGNMENT
 #define MALLOC_ALIGNMENT ((size_t)(2 * sizeof(void *)))
@@ -77,40 +78,46 @@
 };
 
 struct HashTable {
+    pthread_mutex_t lock;
     size_t count;
     HashEntry* slots[HASHTABLE_SIZE];
 };
 
 /* Entry in malloc dispatch table. */
-typedef void* (*MallocDebugMalloc)(size_t);
-typedef void (*MallocDebugFree)(void*);
 typedef void* (*MallocDebugCalloc)(size_t, size_t);
-typedef void* (*MallocDebugRealloc)(void*, size_t);
-typedef void* (*MallocDebugMemalign)(size_t, size_t);
+typedef void (*MallocDebugFree)(void*);
+typedef struct mallinfo (*MallocDebugMallinfo)();
+typedef void* (*MallocDebugMalloc)(size_t);
 typedef size_t (*MallocDebugMallocUsableSize)(const void*);
+typedef void* (*MallocDebugMemalign)(size_t, size_t);
+typedef int (*MallocDebugPosixMemalign)(void**, size_t, size_t);
+#if defined(HAVE_DEPRECATED_MALLOC_FUNCS)
+typedef void* (*MallocDebugPvalloc)(size_t);
+#endif
+typedef void* (*MallocDebugRealloc)(void*, size_t);
+#if defined(HAVE_DEPRECATED_MALLOC_FUNCS)
+typedef void* (*MallocDebugValloc)(size_t);
+#endif
+
 struct MallocDebug {
-  MallocDebugMalloc malloc;
-  MallocDebugFree free;
   MallocDebugCalloc calloc;
-  MallocDebugRealloc realloc;
-  MallocDebugMemalign memalign;
+  MallocDebugFree free;
+  MallocDebugMallinfo mallinfo;
+  MallocDebugMalloc malloc;
   MallocDebugMallocUsableSize malloc_usable_size;
+  MallocDebugMemalign memalign;
+  MallocDebugPosixMemalign posix_memalign;
+#if defined(HAVE_DEPRECATED_MALLOC_FUNCS)
+  MallocDebugPvalloc pvalloc;
+#endif
+  MallocDebugRealloc realloc;
+#if defined(HAVE_DEPRECATED_MALLOC_FUNCS)
+  MallocDebugValloc valloc;
+#endif
 };
 
-/* Malloc debugging initialization and finalization routines.
- *
- * These routines must be implemented in .so modules that implement malloc
- * debugging. The are is called once per process from malloc_init_impl and
- * malloc_fini_impl respectively.
- *
- * They are implemented in bionic/libc/bionic/malloc_debug_common.c when malloc
- * debugging gets initialized for the process.
- *
- * MallocDebugInit returns:
- *    0 on success, -1 on failure.
- */
-typedef int (*MallocDebugInit)();
-typedef void (*MallocDebugFini)();
+typedef bool (*MallocDebugInit)(HashTable*);
+typedef void (*MallocDebugFini)(int);
 
 // =============================================================================
 // log functions
diff --git a/libc/bionic/malloc_debug_leak.cpp b/libc/bionic/malloc_debug_leak.cpp
index 035765f..308d40b 100644
--- a/libc/bionic/malloc_debug_leak.cpp
+++ b/libc/bionic/malloc_debug_leak.cpp
@@ -37,6 +37,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/param.h>
 #include <sys/select.h>
 #include <sys/socket.h>
 #include <sys/system_properties.h>
@@ -48,6 +49,7 @@
 #include "debug_stacktrace.h"
 #include "malloc_debug_common.h"
 
+#include "private/bionic_macros.h"
 #include "private/libc_logging.h"
 #include "private/ScopedPthreadMutexLocker.h"
 
@@ -58,10 +60,8 @@
 #error MALLOC_LEAK_CHECK is not defined.
 #endif  // !MALLOC_LEAK_CHECK
 
-// Global variables defined in malloc_debug_common.c
 extern int gMallocLeakZygoteChild;
-extern pthread_mutex_t g_allocations_mutex;
-extern HashTable g_hash_table;
+extern HashTable* g_hash_table;
 
 // =============================================================================
 // stack trace functions
@@ -137,7 +137,7 @@
         size |= SIZE_FLAG_ZYGOTE_CHILD;
     }
 
-    HashEntry* entry = find_entry(&g_hash_table, slot, backtrace, numEntries, size);
+    HashEntry* entry = find_entry(g_hash_table, slot, backtrace, numEntries, size);
 
     if (entry != NULL) {
         entry->allocations++;
@@ -150,58 +150,54 @@
         entry->allocations = 1;
         entry->slot = slot;
         entry->prev = NULL;
-        entry->next = g_hash_table.slots[slot];
+        entry->next = g_hash_table->slots[slot];
         entry->numEntries = numEntries;
         entry->size = size;
 
         memcpy(entry->backtrace, backtrace, numEntries * sizeof(uintptr_t));
 
-        g_hash_table.slots[slot] = entry;
+        g_hash_table->slots[slot] = entry;
 
         if (entry->next != NULL) {
             entry->next->prev = entry;
         }
 
         // we just added an entry, increase the size of the hashtable
-        g_hash_table.count++;
+        g_hash_table->count++;
     }
 
     return entry;
 }
 
 static int is_valid_entry(HashEntry* entry) {
-    if (entry != NULL) {
-        int i;
-        for (i = 0 ; i < HASHTABLE_SIZE ; i++) {
-            HashEntry* e1 = g_hash_table.slots[i];
-
-            while (e1 != NULL) {
-                if (e1 == entry) {
-                    return 1;
-                }
-
-                e1 = e1->next;
-            }
+  if (entry != NULL) {
+    for (size_t i = 0; i < HASHTABLE_SIZE; ++i) {
+      HashEntry* e1 = g_hash_table->slots[i];
+      while (e1 != NULL) {
+        if (e1 == entry) {
+          return 1;
         }
+        e1 = e1->next;
+      }
     }
-
-    return 0;
+  }
+  return 0;
 }
 
 static void remove_entry(HashEntry* entry) {
-    HashEntry* prev = entry->prev;
-    HashEntry* next = entry->next;
+  HashEntry* prev = entry->prev;
+  HashEntry* next = entry->next;
 
-    if (prev != NULL) entry->prev->next = next;
-    if (next != NULL) entry->next->prev = prev;
+  if (prev != NULL) entry->prev->next = next;
+  if (next != NULL) entry->next->prev = prev;
 
-    if (prev == NULL) {
-        // we are the head of the list. set the head to be next
-        g_hash_table.slots[entry->slot] = entry->next;
-    }
+  if (prev == NULL) {
+    // we are the head of the list. set the head to be next
+    g_hash_table->slots[entry->slot] = entry->next;
+  }
 
-    // we just removed and entry, decrease the size of the hashtable
-    g_hash_table.count--;
+  // we just removed and entry, decrease the size of the hashtable
+  g_hash_table->count--;
 }
 
 // =============================================================================
@@ -256,6 +252,33 @@
     return Malloc(malloc_usable_size)(mem);
 }
 
+extern "C" struct mallinfo fill_mallinfo() {
+  return Malloc(mallinfo)();
+}
+
+extern "C" int fill_posix_memalign(void** memptr, size_t alignment, size_t size) {
+  if (!powerof2(alignment)) {
+    return EINVAL;
+  }
+  int saved_errno = errno;
+  *memptr = fill_memalign(alignment, size);
+  errno = saved_errno;
+  return (*memptr != NULL) ? 0 : ENOMEM;
+}
+
+extern "C" void* fill_pvalloc(size_t bytes) {
+  size_t pagesize = sysconf(_SC_PAGESIZE);
+  size_t size = BIONIC_ALIGN(bytes, pagesize);
+  if (size < bytes) { // Overflow
+    return NULL;
+  }
+  return fill_memalign(pagesize, size);
+}
+
+extern "C" void* fill_valloc(size_t size) {
+  return fill_memalign(sysconf(_SC_PAGESIZE), size);
+}
+
 // =============================================================================
 // malloc leak functions
 // =============================================================================
@@ -271,12 +294,13 @@
 
     size_t size = bytes + sizeof(AllocationEntry);
     if (size < bytes) { // Overflow.
+        errno = ENOMEM;
         return NULL;
     }
 
     void* base = Malloc(malloc)(size);
     if (base != NULL) {
-        ScopedPthreadMutexLocker locker(&g_allocations_mutex);
+        ScopedPthreadMutexLocker locker(&g_hash_table->lock);
 
         uintptr_t backtrace[BACKTRACE_SIZE];
         size_t numEntries = get_backtrace(backtrace, BACKTRACE_SIZE);
@@ -294,43 +318,46 @@
 }
 
 extern "C" void leak_free(void* mem) {
-    if (mem != NULL) {
-        ScopedPthreadMutexLocker locker(&g_allocations_mutex);
+  if (mem == NULL) {
+    return;
+  }
 
-        // check the guard to make sure it is valid
-        AllocationEntry* header = to_header(mem);
+  ScopedPthreadMutexLocker locker(&g_hash_table->lock);
 
-        if (header->guard != GUARD) {
-            // could be a memaligned block
-            if (header->guard == MEMALIGN_GUARD) {
-                // For memaligned blocks, header->entry points to the memory
-                // allocated through leak_malloc.
-                header = to_header(header->entry);
-            }
-        }
+  // check the guard to make sure it is valid
+  AllocationEntry* header = to_header(mem);
 
-        if (header->guard == GUARD || is_valid_entry(header->entry)) {
-            // decrement the allocations
-            HashEntry* entry = header->entry;
-            entry->allocations--;
-            if (entry->allocations <= 0) {
-                remove_entry(entry);
-                Malloc(free)(entry);
-            }
-
-            // now free the memory!
-            Malloc(free)(header);
-        } else {
-            debug_log("WARNING bad header guard: '0x%x'! and invalid entry: %p\n",
-                    header->guard, header->entry);
-        }
+  if (header->guard != GUARD) {
+    // could be a memaligned block
+    if (header->guard == MEMALIGN_GUARD) {
+      // For memaligned blocks, header->entry points to the memory
+      // allocated through leak_malloc.
+      header = to_header(header->entry);
     }
+  }
+
+  if (header->guard == GUARD || is_valid_entry(header->entry)) {
+    // decrement the allocations
+    HashEntry* entry = header->entry;
+    entry->allocations--;
+    if (entry->allocations <= 0) {
+      remove_entry(entry);
+      Malloc(free)(entry);
+    }
+
+    // now free the memory!
+    Malloc(free)(header);
+  } else {
+    debug_log("WARNING bad header guard: '0x%x'! and invalid entry: %p\n",
+              header->guard, header->entry);
+  }
 }
 
 extern "C" void* leak_calloc(size_t n_elements, size_t elem_size) {
-    /* Fail on overflow - just to be safe even though this code runs only
-     * within the debugging C library, not the production one */
-    if (n_elements && MAX_SIZE_T / n_elements < elem_size) {
+    // Fail on overflow - just to be safe even though this code runs only
+    // within the debugging C library, not the production one.
+    if (n_elements && SIZE_MAX / n_elements < elem_size) {
+        errno = ENOMEM;
         return NULL;
     }
     size_t size = n_elements * elem_size;
@@ -354,6 +381,7 @@
     } else if (header->guard != GUARD) {
         debug_log("WARNING bad header guard: '0x%x'! and invalid entry: %p\n",
                    header->guard, header->entry);
+        errno = ENOMEM;
         return NULL;
     }
 
@@ -362,8 +390,8 @@
         size_t oldSize = header->entry->size & ~SIZE_FLAG_MASK;
         size_t copySize = (oldSize <= bytes) ? oldSize : bytes;
         memcpy(newMem, oldMem, copySize);
+        leak_free(oldMem);
     }
-    leak_free(oldMem);
 
     return newMem;
 }
@@ -375,8 +403,8 @@
     }
 
     // need to make sure it's a power of two
-    if (alignment & (alignment-1)) {
-        alignment = 1L << (31 - __builtin_clz(alignment));
+    if (!powerof2(alignment)) {
+        alignment = BIONIC_ROUND_UP_POWER_OF_2(alignment);
     }
 
     // here, alignment is at least MALLOC_ALIGNMENT<<1 bytes
@@ -432,3 +460,30 @@
     }
     return 0;
 }
+
+extern "C" struct mallinfo leak_mallinfo() {
+  return Malloc(mallinfo)();
+}
+
+extern "C" int leak_posix_memalign(void** memptr, size_t alignment, size_t size) {
+  if (!powerof2(alignment)) {
+    return EINVAL;
+  }
+  int saved_errno = errno;
+  *memptr = leak_memalign(alignment, size);
+  errno = saved_errno;
+  return (*memptr != NULL) ? 0 : ENOMEM;
+}
+
+extern "C" void* leak_pvalloc(size_t bytes) {
+  size_t pagesize = sysconf(_SC_PAGESIZE);
+  size_t size = BIONIC_ALIGN(bytes, pagesize);
+  if (size < bytes) { // Overflow
+    return NULL;
+  }
+  return leak_memalign(pagesize, size);
+}
+
+extern "C" void* leak_valloc(size_t size) {
+  return leak_memalign(sysconf(_SC_PAGESIZE), size);
+}
diff --git a/libc/bionic/malloc_debug_qemu.cpp b/libc/bionic/malloc_debug_qemu.cpp
index ac60c3b..fd5161a 100644
--- a/libc/bionic/malloc_debug_qemu.cpp
+++ b/libc/bionic/malloc_debug_qemu.cpp
@@ -47,11 +47,13 @@
 #include <stdio.h>
 #include <fcntl.h>
 #include <sys/mman.h>
+#include <sys/param.h>
 #include <pthread.h>
 #include <unistd.h>
 #include <errno.h>
-#include "private/libc_logging.h"
 #include "malloc_debug_common.h"
+#include "private/bionic_macros.h"
+#include "private/libc_logging.h"
 
 /* This file should be included into the build only when
  * MALLOC_QEMU_INSTRUMENT macro is defined. */
@@ -573,12 +575,16 @@
 // API routines
 // =============================================================================
 
-extern "C" void* qemu_instrumented_malloc(size_t bytes);
-extern "C" void  qemu_instrumented_free(void* mem);
-extern "C" void* qemu_instrumented_calloc(size_t n_elements, size_t elem_size);
-extern "C" void* qemu_instrumented_realloc(void* mem, size_t bytes);
-extern "C" void* qemu_instrumented_memalign(size_t alignment, size_t bytes);
-extern "C" size_t qemu_instrumented_malloc_usable_size(const void* mem);
+extern "C" void* qemu_instrumented_calloc(size_t, size_t);
+extern "C" void  qemu_instrumented_free(void*);
+extern "C" struct mallinfo qemu_instrumented_mallinfo();
+extern "C" void* qemu_instrumented_malloc(size_t);
+extern "C" size_t qemu_instrumented_malloc_usable_size(const void*);
+extern "C" void* qemu_instrumented_memalign(size_t, size_t);
+extern "C" int qemu_instrumented_posix_memalign(void**, size_t, size_t);
+extern "C" void* qemu_instrumented_pvalloc(size_t);
+extern "C" void* qemu_instrumented_realloc(void*, size_t);
+extern "C" void* qemu_instrumented_valloc(size_t);
 
 /* Initializes malloc debugging instrumentation for the emulator.
  * This routine is called from malloc_init_impl routine implemented in
@@ -589,7 +595,7 @@
  * Return:
  *  0 on success, or -1 on failure.
 */
-extern "C" int malloc_debug_initialize() {
+extern "C" bool malloc_debug_initialize(HashTable*) {
     /* We will be using emulator's magic page to report memory allocation
      * activities. In essence, what magic page does, it translates writes to
      * the memory mapped spaces into writes to an I/O port that emulator
@@ -598,7 +604,7 @@
     int fd = open("/dev/qemu_trace", O_RDWR);
     if (fd < 0) {
         error_log("Unable to open /dev/qemu_trace");
-        return -1;
+        return false;
     } else {
         qtrace = mmap(NULL, PAGESIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
         close(fd);
@@ -606,14 +612,13 @@
         if (qtrace == MAP_FAILED) {
             qtrace = NULL;
             error_log("Unable to mmap /dev/qemu_trace");
-            return -1;
+            return false;
         }
     }
 
     /* Cache pid of the process this library has been initialized for. */
     malloc_pid = getpid();
-
-    return 0;
+    return true;
 }
 
 /* Completes malloc debugging instrumentation for the emulator.
@@ -681,10 +686,17 @@
     desc.prefix_size = DEFAULT_PREFIX_SIZE;
     desc.requested_bytes = bytes;
     desc.suffix_size = DEFAULT_SUFFIX_SIZE;
-    desc.ptr = Malloc(malloc)(mallocdesc_alloc_size(&desc));
+    size_t size = mallocdesc_alloc_size(&desc);
+    if (size < bytes) { // Overflow
+        qemu_error_log("<libc_pid=%03u, pid=%03u> malloc: malloc(%zu) overflow caused failure.",
+                       malloc_pid, getpid(), bytes);
+        errno = ENOMEM;
+        return NULL;
+    }
+    desc.ptr = Malloc(malloc)(size);
     if (desc.ptr == NULL) {
-        qemu_error_log("<libc_pid=%03u, pid=%03u> malloc(%zd): malloc(%u) failed.",
-                  malloc_pid, getpid(), bytes, mallocdesc_alloc_size(&desc));
+        qemu_error_log("<libc_pid=%03u, pid=%03u> malloc(%zu): malloc(%zu) failed.",
+                       malloc_pid, getpid(), bytes, size);
         return NULL;
     }
 
@@ -693,12 +705,13 @@
         log_mdesc(error, &desc, "<libc_pid=%03u, pid=%03u>: malloc: notify_malloc failed for ",
                   malloc_pid, getpid());
         Malloc(free)(desc.ptr);
+        errno = ENOMEM;
         return NULL;
     } else {
 #if TEST_ACCESS_VIOLATIONS
         test_access_violation(&desc);
 #endif  // TEST_ACCESS_VIOLATIONS
-        log_mdesc(info, &desc, "+++ <libc_pid=%03u, pid=%03u> malloc(%zd) -> ",
+        log_mdesc(info, &desc, "+++ <libc_pid=%03u, pid=%03u> malloc(%zu) -> ",
                   malloc_pid, getpid(), bytes);
         return mallocdesc_user_ptr(&desc);
     }
@@ -755,13 +768,16 @@
     if (n_elements == 0 || elem_size == 0) {
         // Just let go zero bytes allocation.
         qemu_info_log("::: <libc_pid=%03u, pid=%03u>: Zero calloc redir to malloc",
-                 malloc_pid, getpid());
+                      malloc_pid, getpid());
         return qemu_instrumented_malloc(0);
     }
 
-    /* Fail on overflow - just to be safe even though this code runs only
-     * within the debugging C library, not the production one */
-    if (n_elements && MAX_SIZE_T / n_elements < elem_size) {
+    // Fail on overflow - just to be safe even though this code runs only
+    // within the debugging C library, not the production one.
+    if (n_elements && SIZE_MAX / n_elements < elem_size) {
+        qemu_error_log("<libc_pid=%03u, pid=%03u> calloc: calloc(%zu, %zu) overflow caused failure.",
+                       malloc_pid, getpid(), n_elements, elem_size);
+        errno = ENOMEM;
         return NULL;
     }
 
@@ -787,6 +803,12 @@
     }
     desc.requested_bytes = n_elements * elem_size;
     size_t total_size = desc.requested_bytes + desc.prefix_size + desc.suffix_size;
+    if (total_size < desc.requested_bytes) { // Overflow
+        qemu_error_log("<libc_pid=%03u, pid=%03u> calloc: calloc(%zu, %zu) overflow caused failure.",
+                       malloc_pid, getpid(), n_elements, elem_size);
+        errno = ENOMEM;
+        return NULL;
+    }
     size_t total_elements = total_size / elem_size;
     total_size %= elem_size;
     if (total_size != 0) {
@@ -796,22 +818,23 @@
     }
     desc.ptr = Malloc(calloc)(total_elements, elem_size);
     if (desc.ptr == NULL) {
-        error_log("<libc_pid=%03u, pid=%03u> calloc: calloc(%zd(%zd), %zd) (prx=%u, sfx=%u) failed.",
+        error_log("<libc_pid=%03u, pid=%03u> calloc: calloc(%zu(%zu), %zu) (prx=%u, sfx=%u) failed.",
                    malloc_pid, getpid(), n_elements, total_elements, elem_size,
                    desc.prefix_size, desc.suffix_size);
         return NULL;
     }
 
     if (notify_qemu_malloc(&desc)) {
-        log_mdesc(error, &desc, "<libc_pid=%03u, pid=%03u>: calloc(%zd(%zd), %zd): notify_malloc failed for ",
+        log_mdesc(error, &desc, "<libc_pid=%03u, pid=%03u>: calloc(%zu(%zu), %zu): notify_malloc failed for ",
                   malloc_pid, getpid(), n_elements, total_elements, elem_size);
         Malloc(free)(desc.ptr);
+        errno = ENOMEM;
         return NULL;
     } else {
 #if TEST_ACCESS_VIOLATIONS
         test_access_violation(&desc);
 #endif  // TEST_ACCESS_VIOLATIONS
-        log_mdesc(info, &desc, "### <libc_pid=%03u, pid=%03u> calloc(%zd(%zd), %zd) -> ",
+        log_mdesc(info, &desc, "### <libc_pid=%03u, pid=%03u> calloc(%zu(%zu), %zu) -> ",
                   malloc_pid, getpid(), n_elements, total_elements, elem_size);
         return mallocdesc_user_ptr(&desc);
     }
@@ -824,22 +847,17 @@
  * should not expect that pointer returned after shrinking will remain the same.
  */
 extern "C" void* qemu_instrumented_realloc(void* mem, size_t bytes) {
-    MallocDesc new_desc;
-    MallocDesc cur_desc;
-    size_t to_copy;
-    void* ret;
-
     if (mem == NULL) {
         // Nothing to realloc. just do regular malloc.
-        qemu_info_log("::: <libc_pid=%03u, pid=%03u>: realloc(%p, %zd) redir to malloc",
-                 malloc_pid, getpid(), mem, bytes);
+        qemu_info_log("::: <libc_pid=%03u, pid=%03u>: realloc(%p, %zu) redir to malloc",
+                      malloc_pid, getpid(), mem, bytes);
         return qemu_instrumented_malloc(bytes);
     }
 
     if (bytes == 0) {
         // This is a "free" condition.
-        qemu_info_log("::: <libc_pid=%03u, pid=%03u>: realloc(%p, %zd) redir to free and malloc",
-                 malloc_pid, getpid(), mem, bytes);
+        qemu_info_log("::: <libc_pid=%03u, pid=%03u>: realloc(%p, %zu) redir to free and malloc",
+                      malloc_pid, getpid(), mem, bytes);
         qemu_instrumented_free(mem);
 
         // This is what realloc does for a "free" realloc.
@@ -847,10 +865,12 @@
     }
 
     // Query emulator for the reallocating block information.
+    MallocDesc cur_desc;
     if (query_qemu_malloc_info(mem, &cur_desc, 2)) {
         // Note that this violation should be already caught in the emulator.
-        error_log("<libc_pid=%03u, pid=%03u>: realloc(%p, %zd) query_info failed.",
+        error_log("<libc_pid=%03u, pid=%03u>: realloc(%p, %zu) query_info failed.",
                   malloc_pid, getpid(), mem, bytes);
+        errno = ENOMEM;
         return NULL;
     }
 
@@ -862,8 +882,9 @@
      * for this memory block. Note that this violation should be already caught
      * in the emulator.*/
     if (mem != mallocdesc_user_ptr(&cur_desc)) {
-        log_mdesc(error, &cur_desc, "<libc_pid=%03u, pid=%03u>: realloc(%p, %zd) is invalid for ",
+        log_mdesc(error, &cur_desc, "<libc_pid=%03u, pid=%03u>: realloc(%p, %zu) is invalid for ",
                   malloc_pid, getpid(), mem, bytes);
+        errno = ENOMEM;
         return NULL;
     }
 
@@ -873,31 +894,38 @@
      * for this block that is stored in the emulator. */
 
     // Initialize descriptor for the new block.
+    MallocDesc new_desc;
     new_desc.prefix_size = DEFAULT_PREFIX_SIZE;
     new_desc.requested_bytes = bytes;
     new_desc.suffix_size = DEFAULT_SUFFIX_SIZE;
-    new_desc.ptr = Malloc(malloc)(mallocdesc_alloc_size(&new_desc));
-    if (new_desc.ptr == NULL) {
-        log_mdesc(error, &cur_desc, "<libc_pid=%03u, pid=%03u>: realloc(%p, %zd): malloc(%u) failed on ",
-                  malloc_pid, getpid(), mem, bytes,
-                  mallocdesc_alloc_size(&new_desc));
+    size_t new_size = mallocdesc_alloc_size(&new_desc);
+    if (new_size < bytes) { // Overflow
+        qemu_error_log("<libc_pid=%03u, pid=%03u>: realloc(%p, %zu): malloc(%zu) failed due to overflow",
+                       malloc_pid, getpid(), mem, bytes, new_size);
+        errno = ENOMEM;
         return NULL;
     }
-    ret = mallocdesc_user_ptr(&new_desc);
+    new_desc.ptr = Malloc(malloc)(new_size);
+    if (new_desc.ptr == NULL) {
+        log_mdesc(error, &cur_desc, "<libc_pid=%03u, pid=%03u>: realloc(%p, %zu): malloc(%zu) failed on ",
+                  malloc_pid, getpid(), mem, bytes, new_size);
+        return NULL;
+    }
+    void* new_mem = mallocdesc_user_ptr(&new_desc);
 
     // Copy user data from old block to the new one.
-    to_copy = bytes < cur_desc.requested_bytes ? bytes :
-                                                 cur_desc.requested_bytes;
+    size_t to_copy = bytes < cur_desc.requested_bytes ? bytes : cur_desc.requested_bytes;
     if (to_copy != 0) {
-        memcpy(ret, mallocdesc_user_ptr(&cur_desc), to_copy);
+        memcpy(new_mem, mallocdesc_user_ptr(&cur_desc), to_copy);
     }
 
     // Register new block with emulator.
     if (notify_qemu_malloc(&new_desc)) {
-        log_mdesc(error, &new_desc, "<libc_pid=%03u, pid=%03u>: realloc(%p, %zd) notify_malloc failed -> ",
+        log_mdesc(error, &new_desc, "<libc_pid=%03u, pid=%03u>: realloc(%p, %zu) notify_malloc failed -> ",
                   malloc_pid, getpid(), mem, bytes);
         log_mdesc(error, &cur_desc, "                                                                <- ");
         Malloc(free)(new_desc.ptr);
+        errno = ENOMEM;
         return NULL;
     }
 
@@ -907,21 +935,22 @@
 
     // Free old block.
     if (notify_qemu_free(mem)) {
-        log_mdesc(error, &cur_desc, "<libc_pid=%03u, pid=%03u>: realloc(%p, %zd): notify_free failed for ",
+        log_mdesc(error, &cur_desc, "<libc_pid=%03u, pid=%03u>: realloc(%p, %zu): notify_free failed for ",
                   malloc_pid, getpid(), mem, bytes);
         /* Since we registered new decriptor with the emulator, we need
          * to unregister it before freeing newly allocated block. */
         notify_qemu_free(mallocdesc_user_ptr(&new_desc));
         Malloc(free)(new_desc.ptr);
+        errno = ENOMEM;
         return NULL;
     }
     Malloc(free)(cur_desc.ptr);
 
-    log_mdesc(info, &new_desc, "=== <libc_pid=%03u, pid=%03u>: realloc(%p, %zd) -> ",
+    log_mdesc(info, &new_desc, "=== <libc_pid=%03u, pid=%03u>: realloc(%p, %zu) -> ",
               malloc_pid, getpid(), mem, bytes);
     log_mdesc(info, &cur_desc, "                                               <- ");
 
-    return ret;
+    return new_mem;
 }
 
 /* This routine serves as entry point for 'memalign'.
@@ -932,28 +961,38 @@
 
     if (bytes == 0) {
         // Just let go zero bytes allocation.
-        qemu_info_log("::: <libc_pid=%03u, pid=%03u>: memalign(%zx, %zd) redir to malloc",
+        qemu_info_log("::: <libc_pid=%03u, pid=%03u>: memalign(%zx, %zu) redir to malloc",
                  malloc_pid, getpid(), alignment, bytes);
         return qemu_instrumented_malloc(0);
     }
 
-    /* Prefix size for aligned allocation must be equal to the alignment used
-     * for allocation in order to ensure proper alignment of the returned
-     * pointer, in case that alignment requirement is greater than prefix
-     * size. */
-    desc.prefix_size = alignment > DEFAULT_PREFIX_SIZE ? alignment :
-                                                         DEFAULT_PREFIX_SIZE;
+    // Prefix size for aligned allocation must be equal to the alignment used
+    // for allocation in order to ensure proper alignment of the returned
+    // pointer. in case that alignment requirement is greater than prefix
+    // size.
+    if (alignment < DEFAULT_PREFIX_SIZE) {
+        alignment = DEFAULT_PREFIX_SIZE;
+    } else if (!powerof2(alignment)) {
+        alignment = BIONIC_ROUND_UP_POWER_OF_2(alignment);
+    }
+    desc.prefix_size = alignment;
     desc.requested_bytes = bytes;
     desc.suffix_size = DEFAULT_SUFFIX_SIZE;
-    desc.ptr = Malloc(memalign)(desc.prefix_size, mallocdesc_alloc_size(&desc));
+    size_t size = mallocdesc_alloc_size(&desc);
+    if (size < bytes) { // Overflow
+        qemu_error_log("<libc_pid=%03u, pid=%03u> memalign(%zx, %zu): malloc(%zu) failed due to overflow.",
+                       malloc_pid, getpid(), alignment, bytes, size);
+
+        return NULL;
+    }
+    desc.ptr = Malloc(memalign)(desc.prefix_size, size);
     if (desc.ptr == NULL) {
-        error_log("<libc_pid=%03u, pid=%03u> memalign(%zx, %zd): malloc(%u) failed.",
-                  malloc_pid, getpid(), alignment, bytes,
-                  mallocdesc_alloc_size(&desc));
+        error_log("<libc_pid=%03u, pid=%03u> memalign(%zx, %zu): malloc(%zu) failed.",
+                  malloc_pid, getpid(), alignment, bytes, size);
         return NULL;
     }
     if (notify_qemu_malloc(&desc)) {
-        log_mdesc(error, &desc, "<libc_pid=%03u, pid=%03u>: memalign(%zx, %zd): notify_malloc failed for ",
+        log_mdesc(error, &desc, "<libc_pid=%03u, pid=%03u>: memalign(%zx, %zu): notify_malloc failed for ",
                   malloc_pid, getpid(), alignment, bytes);
         Malloc(free)(desc.ptr);
         return NULL;
@@ -963,7 +1002,7 @@
     test_access_violation(&desc);
 #endif  // TEST_ACCESS_VIOLATIONS
 
-    log_mdesc(info, &desc, "@@@ <libc_pid=%03u, pid=%03u> memalign(%zx, %zd) -> ",
+    log_mdesc(info, &desc, "@@@ <libc_pid=%03u, pid=%03u> memalign(%zx, %zu) -> ",
               malloc_pid, getpid(), alignment, bytes);
     return mallocdesc_user_ptr(&desc);
 }
@@ -991,3 +1030,34 @@
     /* during instrumentation, we can't really report anything more than requested_bytes */
     return cur_desc.requested_bytes;
 }
+
+extern "C" struct mallinfo qemu_instrumented_mallinfo() {
+  return Malloc(mallinfo)();
+}
+
+extern "C" int qemu_instrumented_posix_memalign(void** memptr, size_t alignment, size_t size) {
+  if ((alignment & (alignment - 1)) != 0) {
+    qemu_error_log("<libc_pid=%03u, pid=%03u> posix_memalign(%p, %zu, %zu): invalid alignment.",
+                   malloc_pid, getpid(), memptr, alignment, size);
+    return EINVAL;
+  }
+  int saved_errno = errno;
+  *memptr = qemu_instrumented_memalign(alignment, size);
+  errno = saved_errno;
+  return (*memptr != NULL) ? 0 : ENOMEM;
+}
+
+extern "C" void* qemu_instrumented_pvalloc(size_t bytes) {
+  size_t pagesize = sysconf(_SC_PAGESIZE);
+  size_t size = BIONIC_ALIGN(bytes, pagesize);
+  if (size < bytes) { // Overflow
+    qemu_error_log("<libc_pid=%03u, pid=%03u> pvalloc(%zu): overflow (%zu).",
+                   malloc_pid, getpid(), bytes, size);
+    return NULL;
+  }
+  return qemu_instrumented_memalign(pagesize, size);
+}
+
+extern "C" void* qemu_instrumented_valloc(size_t size) {
+  return qemu_instrumented_memalign(sysconf(_SC_PAGESIZE), size);
+}
diff --git a/libc/bionic/md5.c b/libc/bionic/md5.c
deleted file mode 100644
index ba4aaed..0000000
--- a/libc/bionic/md5.c
+++ /dev/null
@@ -1,279 +0,0 @@
-/*
- * Copyright (c) 1995 - 2001 Kungliga Tekniska Högskolan
- * (Royal Institute of Technology, Stockholm, Sweden).
- * 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.
- * 
- * 3. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-
-__RCSID("$Heimdal: md5.c,v 1.15 2001/01/29 04:33:44 assar Exp $"
-        "$NetBSD: md5.c,v 1.1.1.4 2002/09/12 12:41:42 joda Exp $");
-#endif
-
-#include <endian.h>
-#include "md5.h"
-#include "hash.h"
-
-#define A m->counter[0]
-#define B m->counter[1]
-#define C m->counter[2]
-#define D m->counter[3]
-#define X data
-
-void
-MD5_Init (struct md5 *m)
-{
-  m->sz[0] = 0;
-  m->sz[1] = 0;
-  D = 0x10325476;
-  C = 0x98badcfe;
-  B = 0xefcdab89;
-  A = 0x67452301;
-}
-
-#define F(x,y,z) CRAYFIX((x & y) | (~x & z))
-#define G(x,y,z) CRAYFIX((x & z) | (y & ~z))
-#define H(x,y,z) (x ^ y ^ z)
-#define I(x,y,z) CRAYFIX(y ^ (x | ~z))
-
-#define DOIT(a,b,c,d,k,s,i,OP) \
-a = b + cshift(a + OP(b,c,d) + X[k] + (i), s)
-
-#define DO1(a,b,c,d,k,s,i) DOIT(a,b,c,d,k,s,i,F)
-#define DO2(a,b,c,d,k,s,i) DOIT(a,b,c,d,k,s,i,G)
-#define DO3(a,b,c,d,k,s,i) DOIT(a,b,c,d,k,s,i,H)
-#define DO4(a,b,c,d,k,s,i) DOIT(a,b,c,d,k,s,i,I)
-
-static inline void
-calc (struct md5 *m, u_int32_t *data)
-{
-  u_int32_t AA, BB, CC, DD;
-
-  AA = A;
-  BB = B;
-  CC = C;
-  DD = D;
-
-  /* Round 1 */
-
-  DO1(A,B,C,D,0,7,0xd76aa478);
-  DO1(D,A,B,C,1,12,0xe8c7b756);
-  DO1(C,D,A,B,2,17,0x242070db);
-  DO1(B,C,D,A,3,22,0xc1bdceee);
-
-  DO1(A,B,C,D,4,7,0xf57c0faf);
-  DO1(D,A,B,C,5,12,0x4787c62a);
-  DO1(C,D,A,B,6,17,0xa8304613);
-  DO1(B,C,D,A,7,22,0xfd469501);
-
-  DO1(A,B,C,D,8,7,0x698098d8);
-  DO1(D,A,B,C,9,12,0x8b44f7af);
-  DO1(C,D,A,B,10,17,0xffff5bb1);
-  DO1(B,C,D,A,11,22,0x895cd7be);
-
-  DO1(A,B,C,D,12,7,0x6b901122);
-  DO1(D,A,B,C,13,12,0xfd987193);
-  DO1(C,D,A,B,14,17,0xa679438e);
-  DO1(B,C,D,A,15,22,0x49b40821);
-
-  /* Round 2 */
-
-  DO2(A,B,C,D,1,5,0xf61e2562);
-  DO2(D,A,B,C,6,9,0xc040b340);
-  DO2(C,D,A,B,11,14,0x265e5a51);
-  DO2(B,C,D,A,0,20,0xe9b6c7aa);
-
-  DO2(A,B,C,D,5,5,0xd62f105d);
-  DO2(D,A,B,C,10,9,0x2441453);
-  DO2(C,D,A,B,15,14,0xd8a1e681);
-  DO2(B,C,D,A,4,20,0xe7d3fbc8);
-
-  DO2(A,B,C,D,9,5,0x21e1cde6);
-  DO2(D,A,B,C,14,9,0xc33707d6);
-  DO2(C,D,A,B,3,14,0xf4d50d87);
-  DO2(B,C,D,A,8,20,0x455a14ed);
-
-  DO2(A,B,C,D,13,5,0xa9e3e905);
-  DO2(D,A,B,C,2,9,0xfcefa3f8);
-  DO2(C,D,A,B,7,14,0x676f02d9);
-  DO2(B,C,D,A,12,20,0x8d2a4c8a);
-
-  /* Round 3 */
-
-  DO3(A,B,C,D,5,4,0xfffa3942);
-  DO3(D,A,B,C,8,11,0x8771f681);
-  DO3(C,D,A,B,11,16,0x6d9d6122);
-  DO3(B,C,D,A,14,23,0xfde5380c);
-
-  DO3(A,B,C,D,1,4,0xa4beea44);
-  DO3(D,A,B,C,4,11,0x4bdecfa9);
-  DO3(C,D,A,B,7,16,0xf6bb4b60);
-  DO3(B,C,D,A,10,23,0xbebfbc70);
-
-  DO3(A,B,C,D,13,4,0x289b7ec6);
-  DO3(D,A,B,C,0,11,0xeaa127fa);
-  DO3(C,D,A,B,3,16,0xd4ef3085);
-  DO3(B,C,D,A,6,23,0x4881d05);
-
-  DO3(A,B,C,D,9,4,0xd9d4d039);
-  DO3(D,A,B,C,12,11,0xe6db99e5);
-  DO3(C,D,A,B,15,16,0x1fa27cf8);
-  DO3(B,C,D,A,2,23,0xc4ac5665);
-
-  /* Round 4 */
-
-  DO4(A,B,C,D,0,6,0xf4292244);
-  DO4(D,A,B,C,7,10,0x432aff97);
-  DO4(C,D,A,B,14,15,0xab9423a7);
-  DO4(B,C,D,A,5,21,0xfc93a039);
-
-  DO4(A,B,C,D,12,6,0x655b59c3);
-  DO4(D,A,B,C,3,10,0x8f0ccc92);
-  DO4(C,D,A,B,10,15,0xffeff47d);
-  DO4(B,C,D,A,1,21,0x85845dd1);
-
-  DO4(A,B,C,D,8,6,0x6fa87e4f);
-  DO4(D,A,B,C,15,10,0xfe2ce6e0);
-  DO4(C,D,A,B,6,15,0xa3014314);
-  DO4(B,C,D,A,13,21,0x4e0811a1);
-
-  DO4(A,B,C,D,4,6,0xf7537e82);
-  DO4(D,A,B,C,11,10,0xbd3af235);
-  DO4(C,D,A,B,2,15,0x2ad7d2bb);
-  DO4(B,C,D,A,9,21,0xeb86d391);
-
-  A += AA;
-  B += BB;
-  C += CC;
-  D += DD;
-}
-
-/*
- * From `Performance analysis of MD5' by Joseph D. Touch <touch@isi.edu>
- */
-#if !defined(__BYTE_ORDER) || !defined (__BIG_ENDIAN)
-#error __BYTE_ORDER macros not defined
-#endif
-
-#if __BYTE_ORDER == __BIG_ENDIAN
-static inline u_int32_t
-swap_u_int32_t (u_int32_t t)
-{
-  u_int32_t temp1, temp2;
-
-  temp1   = cshift(t, 16);
-  temp2   = temp1 >> 8;
-  temp1  &= 0x00ff00ff;
-  temp2  &= 0x00ff00ff;
-  temp1 <<= 8;
-  return temp1 | temp2;
-}
-#endif
-
-struct x32{
-  unsigned int a:32;
-  unsigned int b:32;
-};
-
-void
-MD5_Update (struct md5 *m, const void *v, size_t len)
-{
-  const unsigned char *p = v;
-  size_t old_sz = m->sz[0];
-  size_t offset;
-
-  m->sz[0] += len * 8;
-  if (m->sz[0] < old_sz)
-      ++m->sz[1];
-  offset = (old_sz / 8)  % 64;
-  while(len > 0){
-    size_t l = min(len, 64 - offset);
-    memcpy(m->save + offset, p, l);
-    offset += l;
-    p += l;
-    len -= l;
-    if(offset == 64){
-#if __BYTE_ORDER == __BIG_ENDIAN
-      int i;
-      u_int32_t current[16];
-      struct x32 *u = (struct x32*)m->save;
-      for(i = 0; i < 8; i++){
-	current[2*i+0] = swap_u_int32_t(u[i].a);
-	current[2*i+1] = swap_u_int32_t(u[i].b);
-      }
-      calc(m, current);
-#else
-      calc(m, (u_int32_t*)m->save);
-#endif
-      offset = 0;
-    }
-  }
-}
-
-void
-MD5_Final (void *res, struct md5 *m)
-{
-  unsigned char zeros[72];
-  unsigned offset = (m->sz[0] / 8) % 64;
-  unsigned int dstart = (120 - offset - 1) % 64 + 1;
-
-  *zeros = 0x80;
-  memset (zeros + 1, 0, sizeof(zeros) - 1);
-  zeros[dstart+0] = (m->sz[0] >> 0) & 0xff;
-  zeros[dstart+1] = (m->sz[0] >> 8) & 0xff;
-  zeros[dstart+2] = (m->sz[0] >> 16) & 0xff;
-  zeros[dstart+3] = (m->sz[0] >> 24) & 0xff;
-  zeros[dstart+4] = (m->sz[1] >> 0) & 0xff;
-  zeros[dstart+5] = (m->sz[1] >> 8) & 0xff;
-  zeros[dstart+6] = (m->sz[1] >> 16) & 0xff;
-  zeros[dstart+7] = (m->sz[1] >> 24) & 0xff;
-  MD5_Update (m, zeros, dstart + 8);
-  {
-      int i;
-      unsigned char *r = (unsigned char *)res;
-
-      for (i = 0; i < 4; ++i) {
-	  r[4*i]   = m->counter[i] & 0xFF;
-	  r[4*i+1] = (m->counter[i] >> 8) & 0xFF;
-	  r[4*i+2] = (m->counter[i] >> 16) & 0xFF;
-	  r[4*i+3] = (m->counter[i] >> 24) & 0xFF;
-      }
-  }
-#if 0
-  {
-    int i;
-    u_int32_t *r = (u_int32_t *)res;
-
-    for (i = 0; i < 4; ++i)
-      r[i] = swap_u_int32_t (m->counter[i]);
-  }
-#endif
-}
diff --git a/libc/bionic/md5.h b/libc/bionic/md5.h
deleted file mode 100644
index a381994..0000000
--- a/libc/bionic/md5.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (c) 1995 - 2001 Kungliga Tekniska Högskolan
- * (Royal Institute of Technology, Stockholm, Sweden).
- * 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.
- * 
- * 3. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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.
- */
-
-/* $Heimdal: md5.h,v 1.8 2001/01/29 02:08:57 assar Exp $
-   $NetBSD: md5.h,v 1.1.1.4 2002/09/12 12:41:42 joda Exp $ */
-
-#include <stdlib.h>
-#include <sys/types.h>
-
-struct md5 {
-  unsigned int sz[2];
-  u_int32_t counter[4];
-  unsigned char save[64];
-};
-
-typedef struct md5 MD5_CTX;
-
-void MD5_Init (struct md5 *m);
-void MD5_Update (struct md5 *m, const void *p, size_t len);
-void MD5_Final (void *res, struct md5 *m); /* u_int32_t res[4] */
diff --git a/libc/bionic/ndk_cruft.cpp b/libc/bionic/ndk_cruft.cpp
index 1284b9a..e3e640a 100644
--- a/libc/bionic/ndk_cruft.cpp
+++ b/libc/bionic/ndk_cruft.cpp
@@ -30,16 +30,20 @@
 #if !defined(__LP64__)
 
 #include <ctype.h>
+#include <dirent.h>
 #include <inttypes.h>
 #include <pthread.h>
+#include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <sys/resource.h>
 #include <sys/syscall.h>
 #include <sys/time.h>
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <unistd.h>
+#include <wchar.h>
 
 // These were accidentally declared in <unistd.h> because we stupidly used to inline
 // getpagesize() and __getpageshift(). Needed for backwards compatibility with old NDK apps.
@@ -221,4 +225,81 @@
   return syscall(__NR_tkill, tid, sig);
 }
 
+extern "C" wchar_t* wcswcs(wchar_t* haystack, wchar_t* needle) {
+  return wcsstr(haystack, needle);
+}
+
+// This was removed from POSIX 2008.
+extern "C" sighandler_t bsd_signal(int signum, sighandler_t handler) {
+  return signal(signum, handler);
+}
+
+// sysv_signal() was never in POSIX.
+extern sighandler_t _signal(int signum, sighandler_t handler, int flags);
+extern "C" sighandler_t sysv_signal(int signum, sighandler_t handler) {
+  return _signal(signum, handler, SA_RESETHAND);
+}
+
+// This is a system call that was never in POSIX. Use readdir(3) instead.
+extern "C" int __getdents64(unsigned int, dirent*, unsigned int);
+extern "C" int getdents(unsigned int fd, dirent* dirp, unsigned int count) {
+  return __getdents64(fd, dirp, count);
+}
+
+// This is a BSDism that we never implemented correctly. Used by Firefox.
+extern "C" int issetugid() {
+  return 0;
+}
+
+// This was removed from POSIX 2004.
+extern "C" pid_t wait3(int* status, int options, struct rusage* rusage) {
+  return wait4(-1, status, options, rusage);
+}
+
+// This was removed from POSIX 2004.
+extern "C" int getdtablesize() {
+  struct rlimit r;
+
+  if (getrlimit(RLIMIT_NOFILE, &r) < 0) {
+    return sysconf(_SC_OPEN_MAX);
+  }
+
+  return r.rlim_cur;
+}
+
+// Only used by ftime, which was removed from POSIX.
+struct timeb {
+  time_t          time;
+  unsigned short  millitm;
+  short           timezone;
+  short           dstflag;
+};
+
+// This was removed from POSIX 2008.
+extern "C" int ftime(struct timeb* tb) {
+  struct timeval  tv;
+  struct timezone tz;
+
+  if (gettimeofday(&tv, &tz) < 0)
+    return -1;
+
+  tb->time    = tv.tv_sec;
+  tb->millitm = (tv.tv_usec + 500) / 1000;
+
+  if (tb->millitm == 1000) {
+    ++tb->time;
+    tb->millitm = 0;
+  }
+
+  tb->timezone = tz.tz_minuteswest;
+  tb->dstflag  = tz.tz_dsttime;
+
+  return 0;
+}
+
+// This was removed from POSIX 2008.
+extern "C" char* index(const char* str, int ch) {
+  return strchr(str, ch);
+}
+
 #endif
diff --git a/libc/bionic/pthread_create.cpp b/libc/bionic/pthread_create.cpp
index c4cb262..2ded22b 100644
--- a/libc/bionic/pthread_create.cpp
+++ b/libc/bionic/pthread_create.cpp
@@ -30,9 +30,11 @@
 
 #include <errno.h>
 #include <sys/mman.h>
+#include <unistd.h>
 
 #include "pthread_internal.h"
 
+#include "private/bionic_macros.h"
 #include "private/bionic_ssp.h"
 #include "private/bionic_tls.h"
 #include "private/libc_logging.h"
@@ -183,8 +185,8 @@
   }
 
   // Make sure the stack size and guard size are multiples of PAGE_SIZE.
-  thread->attr.stack_size = (thread->attr.stack_size + (PAGE_SIZE-1)) & ~(PAGE_SIZE-1);
-  thread->attr.guard_size = (thread->attr.guard_size + (PAGE_SIZE-1)) & ~(PAGE_SIZE-1);
+  thread->attr.stack_size = BIONIC_ALIGN(thread->attr.stack_size, PAGE_SIZE);
+  thread->attr.guard_size = BIONIC_ALIGN(thread->attr.guard_size, PAGE_SIZE);
 
   if (thread->attr.stack_base == NULL) {
     // The caller didn't provide a stack, so allocate one.
@@ -219,6 +221,8 @@
   thread->start_routine = start_routine;
   thread->start_routine_arg = arg;
 
+  thread->set_cached_pid(getpid());
+
   int flags = CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND | CLONE_THREAD | CLONE_SYSVSEM |
       CLONE_SETTLS | CLONE_PARENT_SETTID | CLONE_CHILD_CLEARTID;
   void* tls = thread->tls;
diff --git a/libc/bionic/pthread_internal.h b/libc/bionic/pthread_internal.h
index 490ae86..e05d15c 100644
--- a/libc/bionic/pthread_internal.h
+++ b/libc/bionic/pthread_internal.h
@@ -36,6 +36,26 @@
 
   pid_t tid;
 
+ private:
+  pid_t cached_pid_;
+
+ public:
+  pid_t invalidate_cached_pid() {
+    pid_t old_value;
+    get_cached_pid(&old_value);
+    set_cached_pid(0);
+    return old_value;
+  }
+
+  void set_cached_pid(pid_t value) {
+    cached_pid_ = value;
+  }
+
+  bool get_cached_pid(pid_t* cached_pid) {
+    *cached_pid = cached_pid_;
+    return (*cached_pid != 0);
+  }
+
   void** tls;
 
   pthread_attr_t attr;
diff --git a/libc/bionic/signal.cpp b/libc/bionic/signal.cpp
index 48b2e72..66d75bd 100644
--- a/libc/bionic/signal.cpp
+++ b/libc/bionic/signal.cpp
@@ -28,7 +28,12 @@
 
 #include <signal.h>
 
-static sighandler_t _signal(int signum, sighandler_t handler, int flags) {
+#ifdef __LP64__
+static
+#else
+__LIBC_HIDDEN__
+#endif
+sighandler_t _signal(int signum, sighandler_t handler, int flags) {
   struct sigaction sa;
   sigemptyset(&sa.sa_mask);
   sa.sa_handler = handler;
@@ -41,14 +46,6 @@
   return (sighandler_t) sa.sa_handler;
 }
 
-sighandler_t bsd_signal(int signum, sighandler_t handler) {
-  return _signal(signum, handler, SA_RESTART);
-}
-
-sighandler_t sysv_signal(int signum, sighandler_t handler) {
-  return _signal(signum, handler, SA_RESETHAND);
-}
-
 sighandler_t signal(int signum, sighandler_t handler) {
-  return bsd_signal(signum, handler);
+  return _signal(signum, handler, SA_RESTART);
 }
diff --git a/libc/bionic/system_properties.cpp b/libc/bionic/system_properties.cpp
index 7618586..a564c39 100644
--- a/libc/bionic/system_properties.cpp
+++ b/libc/bionic/system_properties.cpp
@@ -55,9 +55,6 @@
 #include "private/bionic_futex.h"
 #include "private/bionic_macros.h"
 
-#define ALIGN(x, a) (((x) + (a - 1)) & ~(a - 1))
-
-
 static const char property_service_socket[] = "/dev/socket/" PROP_SERVICE_NAME;
 
 
@@ -301,7 +298,7 @@
 static void *allocate_obj(const size_t size, uint32_t *const off)
 {
     prop_area *pa = __system_property_area__;
-    const size_t aligned = ALIGN(size, sizeof(uint32_t));
+    const size_t aligned = BIONIC_ALIGN(size, sizeof(uint32_t));
     if (pa->bytes_used + aligned > pa_data_size) {
         return NULL;
     }
diff --git a/libc/bionic/thread_atexit.cpp b/libc/bionic/thread_private.cpp
similarity index 84%
rename from libc/bionic/thread_atexit.cpp
rename to libc/bionic/thread_private.cpp
index 68c119d..1c04019 100644
--- a/libc/bionic/thread_atexit.cpp
+++ b/libc/bionic/thread_private.cpp
@@ -26,17 +26,13 @@
  * SUCH DAMAGE.
  */
 
-/* some simple glue used to make the BSD atexit code happy */
-
 #include <pthread.h>
+#include "private/thread_private.h"
+
+// Some simple glue used to make BSD code thread-safe.
 
 static pthread_mutex_t g_atexit_lock = PTHREAD_MUTEX_INITIALIZER;
 
-__BEGIN_DECLS
-__LIBC_HIDDEN__ void _thread_atexit_lock();
-__LIBC_HIDDEN__ void _thread_atexit_unlock();
-__END_DECLS
-
 void _thread_atexit_lock() {
   pthread_mutex_lock(&g_atexit_lock);
 }
@@ -44,3 +40,13 @@
 void _thread_atexit_unlock() {
   pthread_mutex_unlock(&g_atexit_lock);
 }
+
+static pthread_mutex_t g_arc4_lock = PTHREAD_MUTEX_INITIALIZER;
+
+void _thread_arc4_lock() {
+  pthread_mutex_lock(&g_arc4_lock);
+}
+
+void _thread_arc4_unlock() {
+  pthread_mutex_unlock(&g_arc4_lock);
+}
diff --git a/libc/bionic/getdtablesize.c b/libc/bionic/vfork.cpp
similarity index 83%
rename from libc/bionic/getdtablesize.c
rename to libc/bionic/vfork.cpp
index 91315a5..b706a7f 100644
--- a/libc/bionic/getdtablesize.c
+++ b/libc/bionic/vfork.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008 The Android Open Source Project
+ * Copyright (C) 2014 The Android Open Source Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -25,15 +25,11 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
-#include <sys/resource.h>
-#include <sys/sysconf.h>
 
-int getdtablesize()
-{
-    struct rlimit r;
+#include <unistd.h>
 
-    if (getrlimit(RLIMIT_NOFILE, &r) < 0) {
-        return sysconf(_SC_OPEN_MAX);
-    }
-    return r.rlim_cur;
+// vfork(2) was removed from POSIX 2008, but it's common enough that we can't
+// actually remove it entirely.
+extern "C" pid_t vfork(void) {
+  return fork();
 }
diff --git a/libc/bionic/wait.cpp b/libc/bionic/wait.cpp
index cd75c10..e5c93aa 100644
--- a/libc/bionic/wait.cpp
+++ b/libc/bionic/wait.cpp
@@ -35,10 +35,6 @@
   return wait4(-1, status, 0, NULL);
 }
 
-pid_t wait3(int* status, int options, struct rusage* rusage) {
-  return wait4(-1, status, options, rusage);
-}
-
 pid_t waitpid(pid_t pid, int* status, int options) {
   return wait4(pid, status, options, NULL);
 }
diff --git a/libc/dns/include/resolv_netid.h b/libc/dns/include/resolv_netid.h
index 991a0bf..bada18a 100644
--- a/libc/dns/include/resolv_netid.h
+++ b/libc/dns/include/resolv_netid.h
@@ -50,20 +50,27 @@
 
 struct addrinfo;
 
-struct hostent *android_gethostbyaddrfornet(const void *, socklen_t, int, unsigned, unsigned);
-struct hostent *android_gethostbyaddrfornet_proxy(const void *, socklen_t, int , unsigned);
-struct hostent *android_gethostbynamefornet(const char *, int, unsigned, unsigned);
+#define __used_in_netd __attribute__((visibility ("default")))
+
+struct hostent *android_gethostbyaddrfornet(const void *, socklen_t, int, unsigned, unsigned) __used_in_netd;
+struct hostent *android_gethostbynamefornet(const char *, int, unsigned, unsigned) __used_in_netd;
 int android_getaddrinfofornet(const char *, const char *, const struct addrinfo *, unsigned,
-		unsigned, struct addrinfo **);
-int android_getnameinfofornet(const struct sockaddr *, socklen_t, char *, size_t, char *, size_t,
-		 int, unsigned, unsigned);
+		unsigned, struct addrinfo **) __used_in_netd;
 
 /* set name servers for a network */
 extern void _resolv_set_nameservers_for_net(unsigned netid,
-    const char** servers, int numservers, const char *domains);
+    const char** servers, int numservers, const char *domains) __used_in_netd;
 
 /* flush the cache associated with a certain network */
-extern void _resolv_flush_cache_for_net(unsigned netid);
+extern void _resolv_flush_cache_for_net(unsigned netid) __used_in_netd;
+
+/* delete the cache associated with a certain network */
+extern void _resolv_delete_cache_for_net(unsigned netid) __used_in_netd;
+
+/* Internal use only. */
+struct hostent *android_gethostbyaddrfornet_proxy(const void *, socklen_t, int , unsigned);
+int android_getnameinfofornet(const struct sockaddr *, socklen_t, char *, size_t, char *, size_t,
+		 int, unsigned, unsigned);
 
 __END_DECLS
 
diff --git a/libc/dns/include/resolv_private.h b/libc/dns/include/resolv_private.h
index 8914fae..f4c67f3 100644
--- a/libc/dns/include/resolv_private.h
+++ b/libc/dns/include/resolv_private.h
@@ -60,6 +60,9 @@
 #include "resolv_static.h"
 #include <net/if.h>
 
+/* Despite this file's name, it's part of libresolv. On Android, that means it's part of libc :-( */
+#pragma GCC visibility push(default)
+
 /*
  * Revision information.  This is the release date in YYYYMMDD format.
  * It can change every day so the right thing to do with it is use it
@@ -279,8 +282,9 @@
 
 /* Things involving an internal (static) resolver context. */
 __BEGIN_DECLS
-extern struct __res_state *__res_get_state(void);
-extern void __res_put_state(struct __res_state *);
+
+__LIBC_HIDDEN__ extern struct __res_state *__res_get_state(void);
+__LIBC_HIDDEN__ extern void __res_put_state(struct __res_state *);
 
 #ifndef ANDROID_CHANGES
 /*
@@ -320,7 +324,7 @@
 void		p_query(const u_char *);
 void		res_close(void);
 int		res_init(void);
-int		res_opt(int, u_char *, int, int);
+__LIBC_HIDDEN__ int		res_opt(int, u_char *, int, int);
 int		res_isourserver(const struct sockaddr_in *);
 int		res_mkquery(int, const char *, int, int, const u_char *, int, const u_char *, u_char *, int);
 int		res_query(const char *, int, int, u_char *, int);
@@ -339,11 +343,11 @@
  * Make them go away if a client is including this
  *
  */
-extern const struct res_sym __p_key_syms[];
-extern const struct res_sym __p_cert_syms[];
+__LIBC_HIDDEN__ extern const struct res_sym __p_key_syms[];
+__LIBC_HIDDEN__ extern const struct res_sym __p_cert_syms[];
 extern const struct res_sym __p_class_syms[];
 extern const struct res_sym __p_type_syms[];
-extern const struct res_sym __p_rcode_syms[];
+__LIBC_HIDDEN__ extern const struct res_sym __p_rcode_syms[];
 #endif /* SHARED_LIBBIND */
 
 #ifndef ANDROID_CHANGES
@@ -434,7 +438,7 @@
 const char *	p_time(uint32_t);
 const char *	p_type(int);
 const char *	p_rcode(int);
-const char *	p_sockun(union res_sockaddr_union, char *, size_t);
+__LIBC_HIDDEN__ const char *	p_sockun(union res_sockaddr_union, char *, size_t);
 const u_char *	p_cdnname(const u_char *, const u_char *, int, FILE *);
 const u_char *	p_cdname(const u_char *, const u_char *, FILE *);
 const u_char *	p_fqnname(const u_char *, const u_char *,
@@ -448,12 +452,12 @@
 				     const u_char *);
 int		res_queriesmatch(const u_char *, const u_char *,
 				      const u_char *, const u_char *);
-const char *	p_section(int, int);
+__LIBC_HIDDEN__ const char *	p_section(int, int);
 /* Things involving a resolver context. */
 int		res_ninit(res_state);
 int		res_nisourserver(const res_state, const struct sockaddr_in *);
 void		fp_resstat(const res_state, FILE *);
-void		res_pquery(const res_state, const u_char *, int, FILE *);
+__LIBC_HIDDEN__ void		res_pquery(const res_state, const u_char *, int, FILE *);
 const char *	res_hostalias(const res_state, const char *, char *, size_t);
 int		res_nquery(res_state, const char *, int, int, u_char *, int);
 int		res_nsearch(res_state, const char *, int, int, u_char *, int);
@@ -471,29 +475,31 @@
 				      char *, size_t,
 				      union res_sockaddr_union *, int);
 void		res_nclose(res_state);
-int		res_nopt(res_state, int, u_char *, int, int);
+__LIBC_HIDDEN__ int		res_nopt(res_state, int, u_char *, int, int);
 void		res_send_setqhook(res_send_qhook);
 void		res_send_setrhook(res_send_rhook);
-int		__res_vinit(res_state, int);
+__LIBC_HIDDEN__ int		__res_vinit(res_state, int);
 void		res_destroyservicelist(void);
 const char *	res_servicename(uint16_t, const char *);
 const char *	res_protocolname(int);
 void		res_destroyprotolist(void);
 void		res_buildprotolist(void);
-const char *	res_get_nibblesuffix(res_state);
-const char *	res_get_nibblesuffix2(res_state);
-void		res_ndestroy(res_state);
-uint16_t	res_nametoclass(const char *, int *);
-uint16_t	res_nametotype(const char *, int *);
-void		res_setservers(res_state,
+__LIBC_HIDDEN__ const char *	res_get_nibblesuffix(res_state);
+__LIBC_HIDDEN__ const char *	res_get_nibblesuffix2(res_state);
+__LIBC_HIDDEN__ void		res_ndestroy(res_state);
+__LIBC_HIDDEN__ uint16_t	res_nametoclass(const char *, int *);
+__LIBC_HIDDEN__ uint16_t	res_nametotype(const char *, int *);
+__LIBC_HIDDEN__ void		res_setservers(res_state,
 				    const union res_sockaddr_union *, int);
-int		res_getservers(res_state,
+__LIBC_HIDDEN__ int		res_getservers(res_state,
 				    union res_sockaddr_union *, int);
 
-void res_setnetid(res_state, unsigned);
-void res_setmark(res_state, unsigned);
+__LIBC_HIDDEN__ void res_setnetid(res_state, unsigned);
+__LIBC_HIDDEN__ void res_setmark(res_state, unsigned);
 u_int  res_randomid(void);
 
 __END_DECLS
 
+#pragma GCC visibility pop
+
 #endif /* !_RESOLV_PRIVATE_H_ */
diff --git a/libc/include/dirent.h b/libc/include/dirent.h
index 71eb2e7..a849a61 100644
--- a/libc/include/dirent.h
+++ b/libc/include/dirent.h
@@ -75,7 +75,6 @@
 extern int alphasort64(const struct dirent64**, const struct dirent64**);
 extern int scandir(const char*, struct dirent***, int (*)(const struct dirent*), int (*)(const struct dirent**, const struct dirent**));
 extern int scandir64(const char*, struct dirent64***, int (*)(const struct dirent64*), int (*)(const struct dirent64**, const struct dirent64**));
-extern int getdents(unsigned int, struct dirent*, unsigned int);
 
 __END_DECLS
 
diff --git a/libc/include/errno.h b/libc/include/errno.h
index 2e5ce5f..1a36b7a 100644
--- a/libc/include/errno.h
+++ b/libc/include/errno.h
@@ -41,7 +41,7 @@
 #endif
 
 /* internal function returning the address of the thread-specific errno */
-extern volatile int*   __errno(void);
+extern volatile int* __errno(void) __pure2;
 
 /* a macro expanding to the errno l-value */
 #define  errno   (*__errno())
diff --git a/libc/include/fcntl.h b/libc/include/fcntl.h
index cd68154..4450bb6 100644
--- a/libc/include/fcntl.h
+++ b/libc/include/fcntl.h
@@ -33,6 +33,7 @@
 #include <sys/types.h>
 #include <linux/fadvise.h>
 #include <linux/fcntl.h>
+#include <linux/uio.h>
 #include <unistd.h>  /* this is not required, but makes client code much happier */
 
 __BEGIN_DECLS
@@ -51,9 +52,12 @@
 #define F_SETLKW64 F_SETLKW
 #endif
 
-#ifndef O_ASYNC
-#define O_ASYNC  FASYNC
-#endif
+#define O_ASYNC FASYNC
+
+#define SPLICE_F_MOVE 1
+#define SPLICE_F_NONBLOCK 2
+#define SPLICE_F_MORE 4
+#define SPLICE_F_GIFT 8
 
 #define SYNC_FILE_RANGE_WAIT_BEFORE 1
 #define SYNC_FILE_RANGE_WRITE 2
@@ -70,7 +74,10 @@
 extern int open64(const char*, int, ...);
 extern int posix_fallocate64(int, off64_t, off64_t);
 extern int posix_fallocate(int, off_t, off_t);
+extern ssize_t splice(int, off64_t*, int, off64_t*, size_t, unsigned int);
+extern ssize_t tee(int, int, size_t, unsigned int);
 extern int unlinkat(int, const char*, int);
+extern ssize_t vmsplice(int, const struct iovec*, size_t, unsigned int);
 
 #if defined(__BIONIC_FORTIFY)
 
diff --git a/libc/include/limits.h b/libc/include/limits.h
index dc45902..fb09657 100644
--- a/libc/include/limits.h
+++ b/libc/include/limits.h
@@ -112,7 +112,7 @@
 
 #define SSIZE_MAX LONG_MAX
 
-#define MB_LEN_MAX 6
+#define MB_LEN_MAX 4
 
 /* New code should use sysconf(_SC_PAGE_SIZE) instead. */
 #ifndef PAGE_SIZE
diff --git a/libc/include/malloc.h b/libc/include/malloc.h
index 9a4e324..e6ea276 100644
--- a/libc/include/malloc.h
+++ b/libc/include/malloc.h
@@ -35,9 +35,6 @@
 extern void* memalign(size_t alignment, size_t byte_count) __mallocfunc __wur __attribute__((alloc_size(2)));
 extern size_t malloc_usable_size(const void* p);
 
-extern void* valloc(size_t byte_count) __mallocfunc __wur __attribute__((alloc_size(1)));
-extern void* pvalloc(size_t byte_count) __mallocfunc __wur __attribute__((alloc_size(1)));
-
 #ifndef STRUCT_MALLINFO_DECLARED
 #define STRUCT_MALLINFO_DECLARED 1
 struct mallinfo {
diff --git a/libc/include/netdb.h b/libc/include/netdb.h
index ead5954..527d5c1 100644
--- a/libc/include/netdb.h
+++ b/libc/include/netdb.h
@@ -196,6 +196,8 @@
 #define	SCOPE_DELIMITER	'%'
 
 __BEGIN_DECLS
+#pragma GCC visibility push(default)
+
 /* BIONIC-BEGIN */
 #define  h_errno   (*__get_h_errno())
 int*  __get_h_errno(void);
@@ -245,6 +247,7 @@
 void setnetgrent(const char *);
 void setservent(int);
 
+#pragma GCC visibility pop
 __END_DECLS
 
 #endif /* !_NETDB_H_ */
diff --git a/libc/include/pthread.h b/libc/include/pthread.h
index 5c9b626..29caafc 100644
--- a/libc/include/pthread.h
+++ b/libc/include/pthread.h
@@ -226,7 +226,7 @@
 int pthread_rwlock_unlock(pthread_rwlock_t *rwlock) __nonnull((1));
 int pthread_rwlock_wrlock(pthread_rwlock_t*) __nonnull((1));
 
-pthread_t pthread_self(void);
+pthread_t pthread_self(void) __pure2;
 
 int pthread_setname_np(pthread_t, const char*) __nonnull((2));
 
diff --git a/libc/include/resolv.h b/libc/include/resolv.h
index 36b93ee..c8899ed 100644
--- a/libc/include/resolv.h
+++ b/libc/include/resolv.h
@@ -37,6 +37,7 @@
 #include <netinet/in.h>
 
 __BEGIN_DECLS
+#pragma GCC visibility push(default)
 
 struct res_state;
 
@@ -52,6 +53,7 @@
 extern int dn_comp(const char*, u_char*, int, u_char**, u_char**);
 extern int dn_expand(const u_char*, const u_char*, const u_char*, char*, int);
 
+#pragma GCC visibility pop
 __END_DECLS
 
 #endif /* _RESOLV_H_ */
diff --git a/libc/include/setjmp.h b/libc/include/setjmp.h
index 68fdcef..02b06f5 100644
--- a/libc/include/setjmp.h
+++ b/libc/include/setjmp.h
@@ -50,7 +50,6 @@
 
 int     _setjmp(jmp_buf);
 void    _longjmp(jmp_buf, int);
-void    longjmperror(void);
 
 int     setjmp(jmp_buf);
 void    longjmp(jmp_buf, int);
diff --git a/libc/include/signal.h b/libc/include/signal.h
index 45c1cda..f1849c5 100644
--- a/libc/include/signal.h
+++ b/libc/include/signal.h
@@ -34,6 +34,7 @@
 #include <limits.h>		/* For LONG_BIT */
 #include <string.h>		/* For memset() */
 #include <sys/types.h>
+#include <asm/sigcontext.h>
 
 #if defined(__LP64__) || defined(__mips__)
 /* For 64-bit (and mips), the kernel's struct sigaction doesn't match the POSIX one,
@@ -102,8 +103,6 @@
 extern int sigaction(int, const struct sigaction*, struct sigaction*);
 
 extern sighandler_t signal(int, sighandler_t);
-extern sighandler_t bsd_signal(int, sighandler_t);
-extern sighandler_t sysv_signal(int, sighandler_t);
 
 extern int siginterrupt(int, int);
 
diff --git a/libc/include/stdio.h b/libc/include/stdio.h
index 90f595c..e532de4 100644
--- a/libc/include/stdio.h
+++ b/libc/include/stdio.h
@@ -254,7 +254,9 @@
 int vdprintf(int, const char * __restrict, __va_list) __printflike(2, 0);
 
 #ifndef __AUDIT__
+#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L
 char* gets(char*) __warnattr("gets is very unsafe; consider using fgets");
+#endif
 int sprintf(char* __restrict, const char* __restrict, ...)
     __printflike(2, 3) __warnattr("sprintf is often misused; please use snprintf");
 char* tmpnam(char*) __warnattr("tmpnam possibly used unsafely; consider using mkstemp");
@@ -296,12 +298,10 @@
  */
 #if __BSD_VISIBLE || __POSIX_VISIBLE || __XPG_VISIBLE
 #define	L_ctermid	1024	/* size for ctermid(); PATH_MAX */
-#define L_cuserid	9	/* size for cuserid(); UT_NAMESIZE + 1 */
 
 __BEGIN_DECLS
 #if 0 /* MISSING FROM BIONIC */
 char	*ctermid(char *);
-char	*cuserid(char *);
 #endif /* MISSING */
 FILE	*fdopen(int, const char *);
 int	 fileno(FILE *);
@@ -339,8 +339,6 @@
 		__printflike(2, 3);
 char	*fgetln(FILE * __restrict, size_t * __restrict);
 int	 fpurge(FILE *);
-int	 getw(FILE *);
-int	 putw(int, FILE *);
 void	 setbuffer(FILE *, char *, int);
 int	 setlinebuf(FILE *);
 int	 vasprintf(char ** __restrict, const char * __restrict,
diff --git a/libc/include/stdlib.h b/libc/include/stdlib.h
index 834dcda..62b7a67 100644
--- a/libc/include/stdlib.h
+++ b/libc/include/stdlib.h
@@ -100,25 +100,27 @@
 extern double erand48(unsigned short xsubi[3]);
 extern double drand48(void);
 extern void srand48(long);
-extern unsigned int arc4random(void);
-extern void arc4random_stir(void);
-extern void arc4random_addrandom(unsigned char *, int);
+
+unsigned int arc4random(void);
+unsigned int arc4random_uniform(unsigned int);
+void arc4random_buf(void*, size_t);
 
 #define RAND_MAX 0x7fffffff
-static __inline__ int rand(void) {
-    return (int)lrand48();
-}
-static __inline__ void srand(unsigned int __s) {
-    srand48(__s);
-}
-static __inline__ long random(void)
-{
-    return lrand48();
-}
-static __inline__ void srandom(unsigned int __s)
-{
-    srand48(__s);
-}
+
+/* Work around x86/x86-64 libvpx build breakage caused by postproc_x86.c. */
+#if (defined(__i386__) || defined(__x86_64__)) && defined(rand)
+#undef rand
+#define __rand lrand48
+#endif
+
+int rand(void);
+int rand_r(unsigned int*);
+void srand(unsigned int);
+
+char* initstate(unsigned int, char*, size_t);
+long random(void);
+char* setstate(char*);
+void srandom(unsigned int);
 
 /* Basic PTY functions.  These only work if devpts is mounted! */
 
@@ -138,21 +140,21 @@
     int  rem;
 } div_t;
 
-extern div_t   div(int, int);
+extern div_t   div(int, int) __pure2;
 
 typedef struct {
     long int  quot;
     long int  rem;
 } ldiv_t;
 
-extern ldiv_t   ldiv(long, long);
+extern ldiv_t   ldiv(long, long) __pure2;
 
 typedef struct {
     long long int  quot;
     long long int  rem;
 } lldiv_t;
 
-extern lldiv_t   lldiv(long long, long long);
+extern lldiv_t   lldiv(long long, long long) __pure2;
 
 /* BSD compatibility. */
 extern const char* getprogname(void);
@@ -167,7 +169,7 @@
 extern int	wctomb(char *, wchar_t);
 extern size_t	wcstombs(char *, const wchar_t *, size_t);
 
-#define MB_CUR_MAX 1
+#define MB_CUR_MAX 4U
 
 #if 0 /* MISSING FROM BIONIC */
 extern int on_exit(void (*)(int, void *), void *);
diff --git a/libc/include/string.h b/libc/include/string.h
index c9ae03b..7727c0e 100644
--- a/libc/include/string.h
+++ b/libc/include/string.h
@@ -43,7 +43,6 @@
 extern void*  memset(void *, int, size_t);
 extern void*  memmem(const void *, size_t, const void *, size_t) __purefunc;
 
-extern char*  index(const char *, int) __purefunc;
 extern char*  strchr(const char *, int) __purefunc;
 extern char* __strchr_chk(const char *, int, size_t);
 
diff --git a/libc/include/strings.h b/libc/include/strings.h
index 8f5fec5..ae261cf 100644
--- a/libc/include/strings.h
+++ b/libc/include/strings.h
@@ -43,11 +43,18 @@
 #include <sys/cdefs.h>
 
 __BEGIN_DECLS
-#define bcopy(b1, b2, len) (void)(memmove((b2), (b1), (len)))
-#define bzero(b, len) (void)(memset((b), '\0', (len)))
+#if defined(__BIONIC_FORTIFY)
+#define bcopy(b1, b2, len) \
+  (void)(__builtin___memmove_chk((b2), (b1), (len), __bos0(b2)))
+#define bzero(b, len) \
+  (void)(__builtin___memset_chk((b), '\0', (len), __bos0(b)))
+#else
+#define bcopy(b1, b2, len) (void)(__builtin_memmove((b2), (b1), (len)))
+#define bzero(b, len) (void)(__builtin_memset((b), '\0', (len)))
+#endif
+
 
 int	 ffs(int);
-char	*index(const char *, int);
 int	 strcasecmp(const char *, const char *);
 int	 strncasecmp(const char *, const char *, size_t);
 
diff --git a/libc/include/sys/ioctl.h b/libc/include/sys/ioctl.h
index 49d452c..a1014dc 100644
--- a/libc/include/sys/ioctl.h
+++ b/libc/include/sys/ioctl.h
@@ -38,6 +38,7 @@
 #include <asm/ioctls.h>
 #include <asm/termbits.h>
 #include <sys/ioctl_compat.h>
+#include <linux/tty.h>
 
 __BEGIN_DECLS
 
diff --git a/libc/include/sys/socket.h b/libc/include/sys/socket.h
index 7edaac9..ae2f238 100644
--- a/libc/include/sys/socket.h
+++ b/libc/include/sys/socket.h
@@ -107,7 +107,7 @@
   int cmsg_type;
 };
 
-#define CMSG_NXTHDR(mhdr, cmsg) cmsg_nxthdr((mhdr), (cmsg))
+#define CMSG_NXTHDR(mhdr, cmsg) __cmsg_nxthdr((mhdr), (cmsg))
 #define CMSG_ALIGN(len) ( ((len)+sizeof(long)-1) & ~(sizeof(long)-1) )
 #define CMSG_DATA(cmsg) ((void*)((char*)(cmsg) + CMSG_ALIGN(sizeof(struct cmsghdr))))
 #define CMSG_SPACE(len) (CMSG_ALIGN(sizeof(struct cmsghdr)) + CMSG_ALIGN(len))
@@ -117,7 +117,7 @@
    ? (struct cmsghdr*) (msg)->msg_control : (struct cmsghdr*) NULL)
 #define CMSG_OK(mhdr, cmsg) ((cmsg)->cmsg_len >= sizeof(struct cmsghdr) &&   (cmsg)->cmsg_len <= (unsigned long)   ((mhdr)->msg_controllen -   ((char*)(cmsg) - (char*)(mhdr)->msg_control)))
 
-struct cmsghdr* cmsg_nxthdr(struct msghdr*, struct cmsghdr*);
+struct cmsghdr* __cmsg_nxthdr(struct msghdr*, struct cmsghdr*);
 
 #define SCM_RIGHTS 0x01
 #define SCM_CREDENTIALS 0x02
diff --git a/libc/include/sys/timeb.h b/libc/include/sys/timeb.h
deleted file mode 100644
index cf6f255..0000000
--- a/libc/include/sys/timeb.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (C) 2008 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.
- */
-#ifndef _SYS_TIMEB_H
-#define _SYS_TIMEB_H
-
-#include <sys/cdefs.h>
-#include <sys/time.h>
-
-__BEGIN_DECLS
-
-struct timeb {
-    time_t          time;
-    unsigned short  millitm;
-    short           timezone;
-    short           dstflag;
-};
-
-extern int  ftime(struct timeb*  timebuf);
-
-__END_DECLS
-
-#endif /* _SYS_TIMEB_H */
diff --git a/libc/include/sys/types.h b/libc/include/sys/types.h
index 9a76ad2..a5fa692 100644
--- a/libc/include/sys/types.h
+++ b/libc/include/sys/types.h
@@ -91,12 +91,17 @@
 typedef __time_t time_t;
 
 /* This historical accident means that we had a 32-bit off_t on 32-bit architectures. */
-#ifndef _OFF_T_DEFINED_
-#define _OFF_T_DEFINED_
+#if !defined(__LP64__)
 typedef __kernel_off_t off_t;
-#endif
 typedef __kernel_loff_t loff_t;
 typedef loff_t off64_t;
+#else
+/* We could re-use the LP32 definitions, but that would mean that although off_t and loff_t/off64_t
+ * would be the same size, they wouldn't actually be the same type, which can lead to warnings. */
+typedef __kernel_off_t off_t;
+typedef off_t loff_t;
+typedef loff_t off64_t;
+#endif
 
 /* while POSIX wants these in <sys/types.h>, we
  * declare then in <pthread.h> instead */
diff --git a/libc/include/sys/wait.h b/libc/include/sys/wait.h
index b30b7ec..8d9a5f6 100644
--- a/libc/include/sys/wait.h
+++ b/libc/include/sys/wait.h
@@ -47,7 +47,6 @@
 
 extern pid_t  wait(int *);
 extern pid_t  waitpid(pid_t, int *, int);
-extern pid_t  wait3(int *, int, struct rusage *);
 extern pid_t  wait4(pid_t, int *, int, struct rusage *);
 
 /* Posix states that idtype_t should be an enumeration type, but
diff --git a/libc/include/syslog.h b/libc/include/syslog.h
index 4677c14..a52e811 100644
--- a/libc/include/syslog.h
+++ b/libc/include/syslog.h
@@ -25,6 +25,7 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
+
 #ifndef _SYSLOG_H
 #define _SYSLOG_H
 
@@ -34,7 +35,6 @@
 
 __BEGIN_DECLS
 
-/* Alert levels */
 #define LOG_EMERG	0
 #define LOG_ALERT	1
 #define LOG_CRIT	2
@@ -47,8 +47,6 @@
 #define LOG_PRIMASK	7
 #define LOG_PRI(x)	((x) & LOG_PRIMASK)
 
-
-/* Facilities; not actually used */
 #define LOG_KERN	0000
 #define LOG_USER	0010
 #define LOG_MAIL	0020
@@ -73,30 +71,15 @@
 #define LOG_FACMASK	01770
 #define LOG_FAC(x)	(((x) >> 3) & (LOG_FACMASK >> 3))
 
-#define	LOG_MASK(pri)	(1 << (pri))		/* mask for one priority */
-#define	LOG_UPTO(pri)	((1 << ((pri)+1)) - 1)	/* all priorities through pri */
+#define LOG_MASK(pri) (1 << (pri))
+#define LOG_UPTO(pri) ((1 << ((pri)+1)) - 1)
 
-/* openlog() flags; only LOG_PID and LOG_PERROR supported */
-#define        LOG_PID         0x01    /* include pid with message */
-#define        LOG_CONS        0x02    /* write to console on logger error */
-#define        LOG_ODELAY      0x04    /* delay connection until syslog() */
-#define        LOG_NDELAY      0x08    /* open connection immediately */
-#define        LOG_NOWAIT      0x10    /* wait for child processes (unused on linux) */
-#define        LOG_PERROR      0x20    /* additional logging to stderr */
-
-/* BIONIC: the following definitions are from OpenBSD's sys/syslog.h
- */
-struct syslog_data {
-	int	log_file;
-        int	connected;
-        int	opened;
-        int	log_stat;
-        const char 	*log_tag;
-        int 	log_fac;
-        int 	log_mask;
-};
-
-#define SYSLOG_DATA_INIT {-1, 0, 0, 0, (const char *)0, LOG_USER, 0xff}
+#define LOG_PID    0x01    /* include pid with message */
+#define LOG_CONS   0x02    /* write to console on logger error */
+#define LOG_ODELAY 0x04    /* delay connection until syslog() */
+#define LOG_NDELAY 0x08    /* open connection immediately */
+#define LOG_NOWAIT 0x10    /* wait for child processes (unused on linux) */
+#define LOG_PERROR 0x20    /* additional logging to stderr */
 
 #define _PATH_LOG  "/dev/syslog"
 
@@ -105,11 +88,6 @@
 extern int	setlogmask(int);
 extern void	syslog(int, const char *, ...) __printflike(2, 3);
 extern void	vsyslog(int, const char *, va_list) __printflike(2, 0);
-extern void	closelog_r(struct syslog_data *);
-extern void	openlog_r(const char *, int, int, struct syslog_data *);
-extern int	setlogmask_r(int, struct syslog_data *);
-extern void	syslog_r(int, struct syslog_data *, const char *, ...) __printflike(3, 4);
-extern void	vsyslog_r(int, struct syslog_data *, const char *, va_list) __printflike(3, 0);
 
 __END_DECLS
 
diff --git a/libc/include/time.h b/libc/include/time.h
index 0f86fd3..0587a2d 100644
--- a/libc/include/time.h
+++ b/libc/include/time.h
@@ -36,9 +36,9 @@
 
 #define CLOCKS_PER_SEC 1000000
 
-extern char* tzname[];
-extern int daylight;
-extern long int timezone;
+extern char* tzname[] __LIBC_ABI_PUBLIC__;
+extern int daylight __LIBC_ABI_PUBLIC__;
+extern long int timezone __LIBC_ABI_PUBLIC__;
 
 struct sigevent;
 
@@ -58,44 +58,43 @@
 
 #define TM_ZONE tm_zone
 
-extern time_t time(time_t*);
-extern int nanosleep(const struct timespec*, struct timespec*);
+extern time_t time(time_t*) __LIBC_ABI_PUBLIC__;
+extern int nanosleep(const struct timespec*, struct timespec*) __LIBC_ABI_PUBLIC__;
 
-extern char* asctime(const struct tm*);
-extern char* asctime_r(const struct tm*, char*);
+extern char* asctime(const struct tm*) __LIBC_ABI_PUBLIC__;
+extern char* asctime_r(const struct tm*, char*) __LIBC_ABI_PUBLIC__;
 
-extern double difftime(time_t, time_t);
-extern time_t mktime(struct tm*);
+extern double difftime(time_t, time_t) __LIBC_ABI_PUBLIC__;
+extern time_t mktime(struct tm*) __LIBC_ABI_PUBLIC__;
 
-extern struct tm* localtime(const time_t*);
-extern struct tm* localtime_r(const time_t*, struct tm*);
+extern struct tm* localtime(const time_t*) __LIBC_ABI_PUBLIC__;
+extern struct tm* localtime_r(const time_t*, struct tm*) __LIBC_ABI_PUBLIC__;
 
-extern struct tm* gmtime(const time_t*);
-extern struct tm* gmtime_r(const time_t*, struct tm*);
+extern struct tm* gmtime(const time_t*) __LIBC_ABI_PUBLIC__;
+extern struct tm* gmtime_r(const time_t*, struct tm*) __LIBC_ABI_PUBLIC__;
 
-extern char* strptime(const char*, const char*, struct tm*);
-extern size_t strftime(char*, size_t, const char*, const struct tm*);
+extern char* strptime(const char*, const char*, struct tm*) __LIBC_ABI_PUBLIC__;
+extern size_t strftime(char*, size_t, const char*, const struct tm*) __LIBC_ABI_PUBLIC__;
 
-extern char* ctime(const time_t*);
-extern char* ctime_r(const time_t*, char*);
+extern char* ctime(const time_t*) __LIBC_ABI_PUBLIC__;
+extern char* ctime_r(const time_t*, char*) __LIBC_ABI_PUBLIC__;
 
-extern void tzset(void);
+extern void tzset(void) __LIBC_ABI_PUBLIC__;
 
-extern clock_t clock(void);
+extern clock_t clock(void) __LIBC_ABI_PUBLIC__;
 
-extern int clock_getres(int, struct timespec*);
-extern int clock_gettime(int, struct timespec*);
+extern int clock_getres(int, struct timespec*) __LIBC_ABI_PUBLIC__;
+extern int clock_gettime(int, struct timespec*) __LIBC_ABI_PUBLIC__;
 
-extern int timer_create(int, struct sigevent*, timer_t*);
-extern int timer_delete(timer_t);
-extern int timer_settime(timer_t, int, const struct itimerspec*, struct itimerspec*);
-extern int timer_gettime(timer_t, struct itimerspec*);
-extern int timer_getoverrun(timer_t);
+extern int timer_create(int, struct sigevent*, timer_t*) __LIBC_ABI_PUBLIC__;
+extern int timer_delete(timer_t) __LIBC_ABI_PUBLIC__;
+extern int timer_settime(timer_t, int, const struct itimerspec*, struct itimerspec*) __LIBC_ABI_PUBLIC__;
+extern int timer_gettime(timer_t, struct itimerspec*) __LIBC_ABI_PUBLIC__;
+extern int timer_getoverrun(timer_t) __LIBC_ABI_PUBLIC__;
 
-extern time_t timelocal(struct tm*);
-extern time_t timegm(struct tm*);
-extern time_t time2posix(time_t);
-extern time_t posix2time(time_t);
+/* Non-standard extensions that are in the BSDs and glibc. */
+extern time_t timelocal(struct tm*) __LIBC_ABI_PUBLIC__;
+extern time_t timegm(struct tm*) __LIBC_ABI_PUBLIC__;
 
 __END_DECLS
 
diff --git a/libc/include/unistd.h b/libc/include/unistd.h
index b4982cb..afe5f1a 100644
--- a/libc/include/unistd.h
+++ b/libc/include/unistd.h
@@ -54,7 +54,7 @@
 extern pid_t  fork(void);
 extern pid_t  vfork(void);
 extern pid_t  getpid(void);
-extern pid_t  gettid(void);
+extern pid_t  gettid(void) __pure2;
 extern pid_t  getpgid(pid_t);
 extern int    setpgid(pid_t, pid_t);
 extern pid_t  getppid(void);
@@ -164,8 +164,6 @@
 
 extern int gethostname(char *, size_t);
 
-extern int getdtablesize(void);
-
 extern void *__brk(void *);
 extern int brk(void *);
 extern void *sbrk(ptrdiff_t);
diff --git a/libc/include/wchar.h b/libc/include/wchar.h
index af7593f..014fed3 100644
--- a/libc/include/wchar.h
+++ b/libc/include/wchar.h
@@ -118,7 +118,7 @@
 extern int               wcscoll(const wchar_t *, const wchar_t *);
 extern wchar_t          *wcscpy(wchar_t *, const wchar_t *);
 extern size_t            wcscspn(const wchar_t *, const wchar_t *);
-extern size_t            wcsftime(wchar_t *, size_t, const wchar_t *, const struct tm *);
+extern size_t            wcsftime(wchar_t *, size_t, const wchar_t *, const struct tm *) __LIBC_ABI_PUBLIC__;
 extern size_t            wcslen(const wchar_t *);
 extern int               wcsncasecmp(const wchar_t *, const wchar_t *, size_t);
 extern wchar_t          *wcsncat(wchar_t *, const wchar_t *, size_t);
@@ -138,7 +138,6 @@
 extern long double wcstold(const wchar_t*, wchar_t**);
 extern unsigned long wcstoul(const wchar_t*, wchar_t**, int);
 extern unsigned long long wcstoull(const wchar_t*, wchar_t**, int);
-extern wchar_t          *wcswcs(const wchar_t *, const wchar_t *);
 extern int               wcswidth(const wchar_t *, size_t);
 extern size_t            wcsxfrm(wchar_t *, const wchar_t *, size_t);
 extern int               wctob(wint_t);
diff --git a/libc/kernel/README.TXT b/libc/kernel/README.TXT
index e4c11a1..0edbcc6 100644
--- a/libc/kernel/README.TXT
+++ b/libc/kernel/README.TXT
@@ -1,93 +1,47 @@
-Bionic comes with a set of 'clean' Linux kernel headers that can safely be
-included by userland applications and libraries without fear of hideous
-conflicts. for more information why this is needed, see the "RATIONALE"
-section at the end of this document.
+Bionic comes with a processed set of all of the uapi Linux kernel headers that
+can safely be included by userland applications and libraries.
 
-these clean headers are automatically generated by several scripts located
-in the 'bionic/kernel/tools' directory, which process a set of original
-and unmodified kernel headers in order to get rid of many annoying
+These clean headers are automatically generated by several scripts located
+in the 'bionic/kernel/tools' directory. The tools process the original
+unmodified kernel headers in order to get rid of many annoying
 declarations and constructs that usually result in compilation failure.
 
-the 'clean headers' only contain type and macro definitions, with the
+The 'clean headers' only contain type and macro definitions, with the
 exception of a couple static inline functions used for performance
-reason (e.g. optimized CPU-specific byte-swapping routines)
+reason (e.g. optimized CPU-specific byte-swapping routines).
 
-they can be included from C++, or when compiling code in strict ANSI mode.
-they can be also included before or after any Bionic C library header.
+They can be included from C++, or when compiling code in strict ANSI mode.
+They can be also included before or after any Bionic C library header.
 
-the generation process works as follows:
+Description of the directories involved in generating the parsed kernel headers:
 
   * 'external/kernel-headers/original/'
-    contains a set of kernel headers as normally found in the 'include'
-    directory of a normal Linux kernel source tree. note that this should
-    only contain the files that are really needed by Android (use
-    'find_headers.py' to find these automatically).
+    Contains the uapi kernel headers found in the android kernel. Note this
+    also includes the header files that are generated by building the kernel
+    sources.
 
-  * 'bionic/libc/kernel/common'
-    contains the non-arch-specific clean headers and directories
-    (e.g. linux, asm-generic and mtd)
+  * 'bionic/libc/kernel/uapi'
+    Contains the cleaned kernel headers and mirrors the directory structure
+    in 'external/kernel-headers/original/uapi/'.
 
-  * 'bionic/libc/kernel/arch-arm/'
-    contains the ARM-specific directory tree of clean headers.
+  * 'bionic/libc/kernel/tools'
+    Contains various Python and shell scripts used to get and re-generate
+    the headers.
 
-  * 'bionic/libc/kernel/arch-arm/asm'
-    contains the real ARM-specific headers
+The tools to get/parse the headers:
 
-  * 'bionic/libc/kernel/arch-x86'
-    'bionic/libc/kernel/arch-x86/asm'
-    similarly contains all headers and symlinks to be used on x86
-
-  * 'bionic/libc/kernel/tools' contains various Python and shell scripts used
-    to manage and re-generate the headers
-
-the tools you can use are:
-
-  * tools/find_users.py
-    scans a list of source files or directories and prints which ones do
-    include Linux headers.
-
-  * tools/find_headers.py
-    scans a list of source files or directories and recursively finds all
-    the original kernel headers they need.
+  * tools/generate_uapi_headers.sh
+    Checks out the android kernel and generates all uapi header files.
+    copies all the changed files into external/kernel-headers.
 
   * tools/clean_header.py
-    prints the clean version of a given kernel header. with the -u option,
+    Prints the clean version of a given kernel header. With the -u option,
     this will also update the corresponding clean header file if its
-    content has changed. you can also process more than one file with -u
+    content has changed. You can also process more than one file with -u.
 
   * tools/update_all.py
-    automatically update all clean headers from the content of 
-    'external/kernel-headers/original'. this is the script you're likely going to
-    run whenever you update the original headers.
-
-
-HOW TO BUILD BIONIC AND OTHER PROGRAMS WITH THE CLEAN HEADERS:
-==============================================================
-
-add bionic/kernel/common and bionic/kernel/arch-<yourarch> to your C
-include path. that should be enough. Note that Bionic will not compile properly 
-if you don't.
-
-
-HOW TO SUPPORT ANOTHER ARCHITECTURE:
-====================================
-
-see the content of tools/defaults.py, you will need to make a few updates
-here:
-
-  - add a new item to the 'kernel_archs' list of supported architectures
-
-  - add a proper definition for 'kernel_known_<arch>_statics' with
-    relevant definitions.
-
-  - update 'kernel_known_statics' to map "<arch>" to
-    'kernel_known_<arch>_statics'
-
-then, add the new architecture-specific headers to original/asm-<arch>.
-(please ensure that these are really needed, e.g. with tools/find_headers.py)
-
-finally, run tools/update_all.py
-
+    Automatically update all clean headers from the content of
+    'external/kernel-headers/original'.
 
 
 HOW TO UPDATE THE HEADERS WHEN NEEDED:
@@ -99,81 +53,13 @@
   NOT BREAK THE KERNEL <-> USER ABI, FOR EXAMPLE BY CHANGING THE SIZE
   OF A GIVEN TYPE. THIS TASK CANNOT BE EASILY AUTOMATED AT THE MOMENT
 
-copy any updated kernel header into the corresponding location under
-'bionic/kernel/original'.
+Grab the latest headers from the android kernel by running this command:
 
-for any new kernel header you want to add, first run tools/find_headers.py to be
-sure that it is really needed by the Android sources. then add it to
-'bionic/kernel/original'
+  bionic/kernel/tools/generate_uapi_headers.sh --download-kernel
 
-then, run tools/update_all.py to re-run the auto-cleaning
+Next, run this command to copy the parsed files to bionic/libc/kernel/uapi:
 
+  bionic/kernel/tools/update_all.py
 
-
-HOW THE CLEANUP PROCESS WORKS:
-==============================
-
-this section describes the action performed by the cleanup program(s) when they
-process the original kernel headers into clean ones:
-
-1. Optimize well-known macros (e.g. __KERNEL__, __KERNEL_STRICT_NAMES)
-
-    this pass gets rid of everything that is guarded by a well-known macro
-    definition. this means that a block like
-
-       #ifdef __KERNEL__
-       ....
-       #endif
-
-    will be totally omitted from the output. the optimizer is smart enough to
-    handle all complex C-preprocessor conditional expression appropriately.
-    this means that, for example:
-
-       #if defined(__KERNEL__) || defined(FOO)
-       ...
-       #endif
-
-    will be transformed into:
-
-       #ifdef FOO
-       ...
-       #endif
-
-    see tools/defaults.py for the list of well-known macros used in this pass,
-    in case you need to update it in the future.
-
-    note that this also remove any reference to a kernel-specific configuration
-    macro like CONFIG_FOO from the clean headers.
-
-
-2. remove variable and function declarations:
-
-  this pass scans non-directive text and only keeps things that look like a
-  typedef/struct/union/enum declaration. this allows to get rid of any variable
-  or function declaration that should only be used within the kernel anyway
-  (and which normally *should* be guarded in a #ifdef __KERNEL__ ... #endif
-  block, if the kernel writers were not so messy)
-
-  there are however a few exceptions: it is seldom useful to keep the definition
-  of some static inline functions performing very simple operations. a good
-  example is the optimized 32-bit byte-swap function found in
-  arch-arm/asm/byteorder.h
-
-  the list of exceptions is in tools/defaults.py in case you need to update it
-  in the future.
-
-  note that we do *not* remove macro definitions, including these macro that
-  perform a call to one of these kernel-header functions, or even define other
-  functions. we consider it safe since userland applications have no business
-  using them anyway.
-
-
-3. whitespace cleanup:
-
-  the final pass remove any comments and empty lines from the final headers.
-
-
-4. add a standard disclaimer:
-
-  prepended to each generated header, contains a message like
-  "do not edit directly - file was auto-generated by ...."
+After this, you will need to build/test the tree to make sure that these
+changes do not introduce any errors.
diff --git a/libc/kernel/tools/clean_header.py b/libc/kernel/tools/clean_header.py
index 238087b..6601817 100755
--- a/libc/kernel/tools/clean_header.py
+++ b/libc/kernel/tools/clean_header.py
@@ -1,5 +1,78 @@
 #!/usr/bin/env python
+
+#------------------------------------------------------------------------------
+# Description of the header clean process
+#------------------------------------------------------------------------------
+# Here is the list of actions performed by this script to clean the original
+# kernel headers.
 #
+# 1. Optimize well-known macros (e.g. __KERNEL__, __KERNEL_STRICT_NAMES)
+#
+#     This pass gets rid of everything that is guarded by a well-known macro
+#     definition. This means that a block like:
+#
+#        #ifdef __KERNEL__
+#        ....
+#        #endif
+#
+#     Will be totally omitted from the output. The optimizer is smart enough to
+#     handle all complex C-preprocessor conditional expression appropriately.
+#     This means that, for example:
+#
+#        #if defined(__KERNEL__) || defined(FOO)
+#        ...
+#        #endif
+#
+#     Will be transformed into:
+#
+#        #ifdef FOO
+#        ...
+#        #endif
+#
+#     See tools/defaults.py for the list of well-known macros used in this pass,
+#     in case you need to update it in the future.
+#
+#     Note that this also removes any reference to a kernel-specific
+#     configuration macro like CONFIG_FOO from the clean headers.
+#
+#
+# 2. Remove variable and function declarations:
+#
+#   This pass scans non-directive text and only keeps things that look like a
+#   typedef/struct/union/enum declaration. This allows us to get rid of any
+#   variables or function declarations that should only be used within the
+#   kernel anyway (and which normally *should* be guarded by an #ifdef
+#   __KERNEL__ ...  #endif block, if the kernel writers were not so messy).
+#
+#   There are, however, a few exceptions: it is seldom useful to keep the
+#   definition of some static inline functions performing very simple
+#   operations. A good example is the optimized 32-bit byte-swap function
+#   found in:
+#
+#     arch-arm/asm/byteorder.h
+#
+#   The list of exceptions is in tools/defaults.py in case you need to update
+#   it in the future.
+#
+#   Note that we do *not* remove macro definitions, including these macro that
+#   perform a call to one of these kernel-header functions, or even define other
+#   functions. We consider it safe since userland applications have no business
+#   using them anyway.
+#
+#
+# 3. Whitespace cleanup:
+#
+#   The final pass removes any comments and empty lines from the final headers.
+#
+#
+# 4. Add a standard disclaimer:
+#
+#   The message:
+#
+#   /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#
+#   Is prepended to each generated header.
+#------------------------------------------------------------------------------
 
 import sys, cpp, kernel, glob, os, re, getopt
 from defaults import *
diff --git a/libc/kernel/tools/defaults.py b/libc/kernel/tools/defaults.py
index 67ab702..2efd455 100644
--- a/libc/kernel/tools/defaults.py
+++ b/libc/kernel/tools/defaults.py
@@ -44,7 +44,11 @@
 kernel_default_arch_macros = {
     "arm": {"__ARMEB__": kCppUndefinedMacro, "__ARM_EABI__": "1"},
     "arm64": {},
-    "mips": {"CONFIG_32BIT":"1", "__MIPSEB__": kCppUndefinedMacro, "__MIPSEL__": "1"},
+    "mips": {"__MIPSEB__": kCppUndefinedMacro,
+             "__MIPSEL__": "1",
+             "CONFIG_32BIT": "_ABIO32",
+             "CONFIG_CPU_LITTLE_ENDIAN": "1",
+             "__SANE_USERSPACE_TYPES__": "1",},
     "x86": {},
     }
 
diff --git a/libc/kernel/tools/find_headers.py b/libc/kernel/tools/find_headers.py
deleted file mode 100755
index 9b3572a..0000000
--- a/libc/kernel/tools/find_headers.py
+++ /dev/null
@@ -1,170 +0,0 @@
-#!/usr/bin/env python
-#
-# this program is used to find source code that includes linux kernel headers directly
-# (e.g. with #include <linux/...> or #include <asm/...>)
-#
-# then it lists them on the standard output.
-
-import sys, cpp, glob, os, re, getopt, kernel
-from utils import *
-from defaults import *
-
-program_dir = find_program_dir()
-
-wanted_archs   = kernel_archs
-wanted_config  = None
-
-def usage():
-    print """\
-  usage:  find_headers.py [options] <kernel-root> (file|directory|@listfile)+
-
-     options:
-        -c <file>          specify .config file (none by default)
-
-        -a <archs>         used to specify an alternative list
-                           of architectures to support
-                           ('%s' by default)
-
-        -v                 enable verbose mode
-
-    this program is used to find all the kernel headers that are used
-    by a set of source files or directories containing them. the search
-    is recursive to find *all* required files.
-
-""" % ( string.join(kernel_archs,",") )
-    sys.exit(1)
-
-
-try:
-    optlist, args = getopt.getopt( sys.argv[1:], 'vc:d:a:k:' )
-except:
-    # unrecognized option
-    print "error: unrecognized option"
-    usage()
-
-for opt, arg in optlist:
-    if opt == '-a':
-        wanted_archs = string.split(arg,',')
-    elif opt == '-c':
-        wanted_config = arg
-    elif opt == '-v':
-        kernel.verboseSearch = 1
-        kernel.verboseFind   = 1
-        verbose = 1
-    else:
-        usage()
-
-if len(args) < 2:
-    usage()
-
-kernel_root = args[0]
-if not os.path.exists(kernel_root):
-    sys.stderr.write( "error: directory '%s' does not exist\n" % kernel_root )
-    sys.exit(1)
-
-if not os.path.isdir(kernel_root):
-    sys.stderr.write( "error: '%s' is not a directory\n" % kernel_root )
-    sys.exit(1)
-
-if not os.path.isdir(kernel_root+"/include/linux"):
-    sys.stderr.write( "error: '%s' does not have an 'include/linux' directory\n" % kernel_root )
-    sys.exit(1)
-
-if wanted_config:
-    if not os.path.exists(wanted_config):
-        sys.stderr.write( "error: file '%s' does not exist\n" % wanted_config )
-        sys.exit(1)
-
-    if not os.path.isfile(wanted_config):
-        sys.stderr.write( "error: '%s' is not a file\n" % wanted_config )
-        sys.exit(1)
-
-# find all architectures in the kernel tree
-archs   = []
-for archdir in os.listdir(kernel_root+"/arch"):
-    if os.path.exists("%s/arch/%s/include/asm" % (kernel_root, archdir)):
-        if verbose:
-            print "Found arch '%s'" % archdir
-        archs.append(archdir)
-
-# if we're using the 'kernel_headers' directory, there is only asm/
-# and no other asm-<arch> directories
-#
-in_kernel_headers = False
-if len(archs) == 0:
-    # this can happen when we're using the 'kernel_headers' directory
-    if os.path.isdir(kernel_root+"/asm"):
-        in_kernel_headers = True
-        archs = [ "arm", "mips"]
-
-# if the user has specified some architectures with -a <archs> ensure that
-# all those he wants are available from the kernel include tree
-if wanted_archs != None:
-    if in_kernel_headers and wanted_archs != [ "arm", "mips" ]:
-        sys.stderr.write( "error: when parsing kernel_headers, only 'arm' and 'mips' architectures are supported at the moment\n" )
-        sys.exit(1)
-    missing = []
-    for arch in wanted_archs:
-        if arch not in archs:
-            missing.append(arch)
-    if len(missing) > 0:
-        sys.stderr.write( "error: the following requested architectures are not in the kernel tree: " )
-        for a in missing:
-            sys.stderr.write( " %s" % a )
-        sys.stderr.write( "\n" )
-        sys.exit(1)
-
-    archs = wanted_archs
-
-# helper function used to walk the user files
-def parse_file(path, parser):
-    #print "parse %s" % path
-    parser.parseFile(path)
-
-
-# remove previous destination directory
-#destdir = "/tmp/bionic-kernel-headers/"
-#cleanup_dir(destdir)
-
-# try to read the config file
-try:
-    cparser = kernel.ConfigParser()
-    if wanted_config:
-        cparser.parseFile( wanted_config )
-except:
-    sys.stderr.write( "error: can't parse '%s'" % wanted_config )
-    sys.exit(1)
-
-kernel_config = cparser.getDefinitions()
-
-# first, obtain the list of kernel files used by our clients
-fparser = kernel.HeaderScanner()
-dir_excludes=[".repo","external/kernel-headers","ndk","out","prebuilt","bionic/libc/kernel","development/ndk","external/qemu/distrib"]
-walk_source_files( args[1:], parse_file, fparser, excludes=["./"+f for f in dir_excludes] )
-headers = fparser.getHeaders()
-files   = fparser.getFiles()
-
-# now recursively scan the kernel headers for additionnal sub-included headers
-hparser = kernel.KernelHeaderFinder(headers,archs,kernel_root,kernel_config)
-headers = hparser.scanForAllArchs()
-
-if 0:    # just for debugging
-    dumpHeaderUsers = False
-
-    print "the following %d headers:" % len(headers)
-    for h in sorted(headers):
-        if dumpHeaderUsers:
-            print "  %s (%s)" % (h, repr(hparser.getHeaderUsers(h)))
-        else:
-            print "  %s" % h
-
-    print "are used by the following %d files:" % len(files)
-    for f in sorted(files):
-        print "  %s" % f
-
-    sys.exit(0)
-
-for h in sorted(headers):
-    print "%s" % h
-
-sys.exit(0)
diff --git a/libc/kernel/tools/find_users.py b/libc/kernel/tools/find_users.py
deleted file mode 100755
index 5ee308c..0000000
--- a/libc/kernel/tools/find_users.py
+++ /dev/null
@@ -1,63 +0,0 @@
-#!/usr/bin/env python
-#
-# this program is used to find source code that includes linux kernel headers directly
-# (e.g. with #include <linux/...> or #include <asm/...>)
-#
-# then it lists
-
-import sys, cpp, glob, os, re, getopt
-import kernel
-from utils import *
-from defaults import *
-
-
-def usage():
-    print """\
-  usage:  find_users.py [-v] (file|directory|@listfile)+
-
-    this program is used to scan a list of files or directories for
-    sources that include kernel headers directly. the program prints
-    the list of said source files when it's done.
-
-    when scanning directories, only files matching the following
-    extension will be searched: .c .cpp .S .h
-
-    use -v to enable verbose output
-"""
-    sys.exit(1)
-
-
-try:
-    optlist, args = getopt.getopt( sys.argv[1:], 'v' )
-except:
-    # unrecognized option
-    print "error: unrecognized option"
-    usage()
-
-for opt, arg in optlist:
-    if opt == '-v':
-        kernel.verboseSearch = 1
-        kernel.verboseFind   = 1
-    else:
-        usage()
-
-if len(args) < 1:
-    usage()
-
-# helper function used to walk the user files
-def parse_file(path, parser):
-    parser.parseFile(path)
-
-
-# first, obtain the list of kernel files used by our clients
-# avoid parsing the 'kernel_headers' directory itself since we
-# use this program with the Android source tree by default.
-#
-fparser = kernel.HeaderScanner()
-walk_source_files( args, parse_file, fparser, excludes=["kernel_headers","original"] )
-files   = fparser.getFiles()
-
-for f in sorted(files):
-    print f
-
-sys.exit(0)
diff --git a/libc/kernel/uapi/asm-mips/asm/fcntl.h b/libc/kernel/uapi/asm-mips/asm/fcntl.h
index 4a9bf5c..e77f79a 100644
--- a/libc/kernel/uapi/asm-mips/asm/fcntl.h
+++ b/libc/kernel/uapi/asm-mips/asm/fcntl.h
@@ -46,19 +46,21 @@
 #define F_SETLKW64 35
 #endif
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#ifdef _ABIO32
 #include <linux/types.h>
 struct flock {
  short l_type;
- short l_whence;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ short l_whence;
  __kernel_off_t l_start;
  __kernel_off_t l_len;
  long l_sysid;
- __kernel_pid_t l_pid;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __kernel_pid_t l_pid;
  long pad[4];
 };
 #define HAVE_ARCH_STRUCT_FLOCK
-#include <asm-generic/fcntl.h>
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
+#include <asm-generic/fcntl.h>
+#endif
diff --git a/libc/kernel/uapi/asm-mips/asm/msgbuf.h b/libc/kernel/uapi/asm-mips/asm/msgbuf.h
index d81da73..624bddf 100644
--- a/libc/kernel/uapi/asm-mips/asm/msgbuf.h
+++ b/libc/kernel/uapi/asm-mips/asm/msgbuf.h
@@ -21,21 +21,29 @@
 struct msqid64_ds {
  struct ipc64_perm msg_perm;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- unsigned long __unused1;
  __kernel_time_t msg_stime;
- unsigned long __unused2;
- __kernel_time_t msg_rtime;
+#ifdef _ABIO32
+ unsigned long __unused1;
+#endif
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- unsigned long __unused3;
+ __kernel_time_t msg_rtime;
+#ifdef _ABIO32
+ unsigned long __unused2;
+#endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __kernel_time_t msg_ctime;
+#ifdef _ABIO32
+ unsigned long __unused3;
+#endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned long msg_cbytes;
  unsigned long msg_qnum;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned long msg_qbytes;
  __kernel_pid_t msg_lspid;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __kernel_pid_t msg_lrpid;
  unsigned long __unused4;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned long __unused5;
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
diff --git a/libc/kernel/uapi/asm-mips/asm/resource.h b/libc/kernel/uapi/asm-mips/asm/resource.h
index 8761697..ff7cfd5 100644
--- a/libc/kernel/uapi/asm-mips/asm/resource.h
+++ b/libc/kernel/uapi/asm-mips/asm/resource.h
@@ -24,7 +24,10 @@
 #define RLIMIT_RSS 7
 #define RLIMIT_NPROC 8
 #define RLIMIT_MEMLOCK 9
-#define RLIM_INFINITY 0x7fffffffUL
+#ifdef _ABIO32
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define RLIM_INFINITY 0x7fffffffUL
+#endif
 #include <asm-generic/resource.h>
 #endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/asm-mips/asm/siginfo.h b/libc/kernel/uapi/asm-mips/asm/siginfo.h
index 45b418a..4abc7af 100644
--- a/libc/kernel/uapi/asm-mips/asm/siginfo.h
+++ b/libc/kernel/uapi/asm-mips/asm/siginfo.h
@@ -24,80 +24,82 @@
 #define HAVE_ARCH_SIGINFO_T
 #define HAVE_ARCH_COPY_SIGINFO
 struct siginfo;
-#define __ARCH_SI_PREAMBLE_SIZE (3 * sizeof(int))
+#ifdef _ABIO32
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define __ARCH_SI_PREAMBLE_SIZE (3 * sizeof(int))
+#endif
 #ifdef __LP64__
 #define __ARCH_SI_PREAMBLE_SIZE (4 * sizeof(int))
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
 #include <asm-generic/siginfo.h>
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 typedef struct siginfo {
  int si_signo;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int si_code;
  int si_errno;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int __pad0[SI_MAX_SIZE / sizeof(int) - SI_PAD_SIZE - 3];
  union {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int _pad[SI_PAD_SIZE];
  struct {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  pid_t _pid;
  __ARCH_SI_UID_T _uid;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  } _kill;
  struct {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  timer_t _tid;
  int _overrun;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  char _pad[sizeof( __ARCH_SI_UID_T) - sizeof(int)];
  sigval_t _sigval;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int _sys_private;
  } _timer;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct {
  pid_t _pid;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __ARCH_SI_UID_T _uid;
  sigval_t _sigval;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  } _rt;
  struct {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  pid_t _pid;
  __ARCH_SI_UID_T _uid;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int _status;
  clock_t _utime;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  clock_t _stime;
  } _sigchld;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct {
  pid_t _pid;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  clock_t _utime;
  int _status;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  clock_t _stime;
  } _irix_sigchld;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct {
  void __user *_addr;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #ifdef __ARCH_SI_TRAPNO
  int _trapno;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
  short _addr_lsb;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  } _sigfault;
  struct {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __ARCH_SI_BAND_T _band;
  int _fd;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  } _sigpoll;
  } _sifields;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 } siginfo_t;
 #undef SI_ASYNCIO
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #undef SI_TIMER
 #undef SI_MESGQ
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SI_ASYNCIO -2
 #define SI_TIMER __SI_CODE(__SI_TIMER, -3)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SI_MESGQ __SI_CODE(__SI_MESGQ, -4)
 #endif
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/asm-mips/asm/types.h b/libc/kernel/uapi/asm-mips/asm/types.h
index 45fea6c..9ef7b7c 100644
--- a/libc/kernel/uapi/asm-mips/asm/types.h
+++ b/libc/kernel/uapi/asm-mips/asm/types.h
@@ -18,11 +18,6 @@
  ****************************************************************************/
 #ifndef _UAPI_ASM_TYPES_H
 #define _UAPI_ASM_TYPES_H
-#if _MIPS_SZLONG == 64
-#include <asm-generic/int-l64.h>
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#else
 #include <asm-generic/int-ll64.h>
 #endif
-#endif
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/include/sha1.h b/libc/private/bionic_config.h
similarity index 61%
copy from libc/include/sha1.h
copy to libc/private/bionic_config.h
index 7f6cf5d..0c9811c 100644
--- a/libc/include/sha1.h
+++ b/libc/private/bionic_config.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012 The Android Open Source Project
+ * Copyright (C) 2014 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.
@@ -14,10 +14,13 @@
  * limitations under the License.
  */
 
-#ifndef _SHA1_H_
-#define _SHA1_H_
+#ifndef _BIONIC_CONFIG_H_
+#define _BIONIC_CONFIG_H_
 
-#warning "include <sys/sha1.h> instead for better portability"
-#include <sys/sha1.h>
-
+// valloc(3) and pvalloc(3) were removed from POSIX 2004. We do not include them
+// for LP64, but the symbols remain in LP32 for binary compatibility.
+#if !defined(__LP64__)
+#define HAVE_DEPRECATED_MALLOC_FUNCS 1
 #endif
+
+#endif // _BIONIC_CONFIG_H_
diff --git a/libc/private/bionic_macros.h b/libc/private/bionic_macros.h
index 34da501..a3a6985 100644
--- a/libc/private/bionic_macros.h
+++ b/libc/private/bionic_macros.h
@@ -33,4 +33,10 @@
   TypeName();                                    \
   DISALLOW_COPY_AND_ASSIGN(TypeName)
 
+#define BIONIC_ALIGN(value, alignment) \
+  (((value) + (alignment) - 1) & ~((alignment) - 1))
+
+#define BIONIC_ROUND_UP_POWER_OF_2(value) \
+  (1UL << (sizeof(value) * 8 - 1 - __builtin_clz(value)))
+
 #endif // _BIONIC_MACROS_H_
diff --git a/libc/private/bionic_time.h b/libc/private/bionic_time.h
index 7c80f59..ca5c146 100644
--- a/libc/private/bionic_time.h
+++ b/libc/private/bionic_time.h
@@ -52,10 +52,11 @@
 
 /*
  * Note: you should consider these extensions deprecated and use managed code or icu4c instead.
+ * We'd like to hide them but they're currently still used in frameworks code.
  */
-extern size_t strftime_tz(char* s, size_t max, const char* format, const struct tm* tm, const struct strftime_locale* lc);
-extern time_t mktime_tz(struct tm* const tmp, char const* tz);
-extern void localtime_tz(const time_t* const timep, struct tm* tmp, const char* tz);
+extern size_t strftime_tz(char*, size_t, const char*, const struct tm*, const struct strftime_locale*);
+extern time_t mktime_tz(struct tm* const, char const*);
+extern void localtime_tz(const time_t* const, struct tm*, const char*);
 
 #endif /* _BIONIC_STRFTIME_TZ_DECLARED */
 
diff --git a/libc/private/bionic_tls.h b/libc/private/bionic_tls.h
index b52013f..56a61be 100644
--- a/libc/private/bionic_tls.h
+++ b/libc/private/bionic_tls.h
@@ -31,6 +31,7 @@
 
 #include <sys/cdefs.h>
 #include <sys/limits.h>
+#include "bionic_macros.h"
 #include "__get_tls.h"
 
 __BEGIN_DECLS
@@ -84,8 +85,6 @@
 #define BIONIC_TLS_RESERVED_SLOTS GLOBAL_INIT_THREAD_LOCAL_BUFFER_COUNT
 #endif
 
-#define BIONIC_ALIGN(x, a) (((x) + (a - 1)) & ~(a - 1))
-
 /*
  * Maximum number of elements in the TLS array.
  * This includes space for pthread keys and our own internal slots.
diff --git a/libc/private/thread_private.h b/libc/private/thread_private.h
index f731181..724808a 100644
--- a/libc/private/thread_private.h
+++ b/libc/private/thread_private.h
@@ -7,6 +7,8 @@
 
 #include <pthread.h>
 
+__BEGIN_DECLS
+
 /*
  * This file defines the thread library interface to libc.  Thread
  * libraries must implement the functions described here for proper
@@ -31,10 +33,18 @@
 #define _THREAD_PRIVATE_MUTEX_UNLOCK(name) \
 	pthread_mutex_unlock( &__THREAD_NAME(name)._private_lock )
 
-void	_thread_atexit_lock(void);
-void	_thread_atexit_unlock(void);
+__LIBC_HIDDEN__ void	_thread_atexit_lock(void);
+__LIBC_HIDDEN__ void	_thread_atexit_unlock(void);
 
 #define _ATEXIT_LOCK() _thread_atexit_lock()
 #define _ATEXIT_UNLOCK() _thread_atexit_unlock()
 
+__LIBC_HIDDEN__ void    _thread_arc4_lock(void);
+__LIBC_HIDDEN__ void    _thread_arc4_unlock(void);
+
+#define  _ARC4_LOCK() _thread_arc4_lock()
+#define  _ARC4_UNLOCK() _thread_arc4_unlock()
+
+__END_DECLS
+
 #endif /* _THREAD_PRIVATE_H_ */
diff --git a/libc/stdlib/atexit.c b/libc/stdlib/atexit.c
index c607206..05f2faa 100644
--- a/libc/stdlib/atexit.c
+++ b/libc/stdlib/atexit.c
@@ -37,7 +37,6 @@
 #include "atexit.h"
 #include "private/thread_private.h"
 
-int __atexit_invalid = 1;
 struct atexit *__atexit;
 
 /*
@@ -131,8 +130,6 @@
 		    sizeof(p->fns[0]);
 		p->next = __atexit;
 		__atexit = p;
-		if (__atexit_invalid)
-			__atexit_invalid = 0;
 	}
 	fnp = &p->fns[p->ind++];
 	fnp->cxa_func = func;
@@ -159,8 +156,6 @@
 	int n, pgsize = getpagesize(), original_ind;
 	static int call_depth;
 
-	if (__atexit_invalid)
-		return;
 	_ATEXIT_LOCK();
 	call_depth++;
 
diff --git a/libc/stdlib/atexit.h b/libc/stdlib/atexit.h
index 2e88ad6..b530ade 100644
--- a/libc/stdlib/atexit.h
+++ b/libc/stdlib/atexit.h
@@ -45,8 +45,7 @@
 
 __BEGIN_DECLS
 
-extern int __atexit_invalid;
-extern struct atexit *__atexit;		/* points to head of LIFO stack */
+__LIBC_HIDDEN__ extern struct atexit *__atexit;		/* points to head of LIFO stack */
 
 int	__cxa_atexit(void (*)(void *), void *, void *);
 void	__cxa_finalize(void *);
diff --git a/libc/tools/check-symbols-glibc.py b/libc/tools/check-symbols-glibc.py
index 913b20b..58a10e0 100755
--- a/libc/tools/check-symbols-glibc.py
+++ b/libc/tools/check-symbols-glibc.py
@@ -11,7 +11,6 @@
 arch = re.sub(r'.*/linux-x86/([^/]+)/.*', r'\1', toolchain)
 
 def GetSymbolsFromSo(so_file):
-
   # Example readelf output:
   #   264: 0001623c     4 FUNC    GLOBAL DEFAULT    8 cabsf
   #   266: 00016244     4 FUNC    GLOBAL DEFAULT    8 dremf
@@ -23,13 +22,13 @@
   symbols = set()
 
   for line in subprocess.check_output(['readelf', '--dyn-syms', '-W', so_file]).split('\n'):
-     if ' HIDDEN ' in line or ' UND ' in line:
-       continue
-     m = r.match(line)
-     if m:
-       symbol = m.group(2)
-       symbol = re.sub('@.*', '', symbol)
-       symbols.add(symbol)
+    if ' HIDDEN ' in line or ' UND ' in line:
+      continue
+    m = r.match(line)
+    if m:
+      symbol = m.group(2)
+      symbol = re.sub('@.*', '', symbol)
+      symbols.add(symbol)
 
   return symbols
 
@@ -46,9 +45,23 @@
     symbols = symbols | GetSymbolsFromSo(f)
   return symbols
 
+def MangleGlibcNameToBionic(name):
+  if name in glibc_to_bionic_names:
+    return glibc_to_bionic_names[name]
+  return name
+
+glibc_to_bionic_names = {
+  '__res_init': 'res_init',
+  '__res_mkquery': 'res_mkquery',
+  '__res_query': 'res_query',
+  '__res_search': 'res_search',
+}
+
 glibc = GetSymbolsFromSystemSo('libc.so.*', 'librt.so.*', 'libpthread.so.*', 'libresolv.so.*', 'libm.so.*')
 bionic = GetSymbolsFromAndroidSo('libc.so', 'libm.so')
 
+glibc = map(MangleGlibcNameToBionic, glibc)
+
 # bionic includes various BSD symbols to ease porting other BSD-licensed code.
 bsd_stuff = set([
   'basename_r',
@@ -96,7 +109,11 @@
 ])
 # Some standard stuff isn't yet in the versions of glibc we're using.
 std_stuff = set([
-  'at_quick_exit'
+  'at_quick_exit',
+  'c16rtomb',
+  'c32rtomb',
+  'mbrtoc16',
+  'mbrtoc32',
 ])
 # These have mangled names in glibc, with a macro taking the "obvious" name.
 weird_stuff = set([
diff --git a/libc/tools/gensyscalls.py b/libc/tools/gensyscalls.py
index 5e4ddc5..96583d6 100755
--- a/libc/tools/gensyscalls.py
+++ b/libc/tools/gensyscalls.py
@@ -95,20 +95,9 @@
 #
 
 arm64_call = syscall_stub_header + """\
-    stp     x29, x30, [sp, #-16]!
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset x29, 0
-    .cfi_rel_offset x30, 8
-    mov     x29,  sp
-
     mov     x8, %(__NR_name)s
     svc     #0
 
-    ldp     x29, x30, [sp], #16
-    .cfi_def_cfa_offset 0
-    .cfi_restore x29
-    .cfi_restore x30
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
     b.hi    __set_errno
@@ -183,7 +172,6 @@
     pushl   %%eax
     call    __set_errno
     addl    $4, %%esp
-    orl     $-1, %%eax
 1:
 """
 
@@ -205,7 +193,6 @@
     negl    %%eax
     movl    %%eax, %%edi
     call    __set_errno
-    orq     $-1, %%rax
 1:
     ret
 END(%(func)s)
diff --git a/libc/tzcode/localtime.c b/libc/tzcode/localtime.c
index c40569c..4dd7ab0 100644
--- a/libc/tzcode/localtime.c
+++ b/libc/tzcode/localtime.c
@@ -74,7 +74,7 @@
 #define WILDABBR    "   "
 #endif /* !defined WILDABBR */
 
-static char       wildabbr[] = WILDABBR;
+static const char       wildabbr[] = WILDABBR;
 
 static const char gmt[] = "GMT";
 
@@ -128,16 +128,16 @@
 };
 
 struct rule {
-    int          r_type; /* type of rule--see below */
+    int          r_type; /* type of rule; see below */
     int          r_day;  /* day number of rule */
     int          r_week; /* week number of rule */
     int          r_mon;  /* month number of rule */
     int_fast32_t r_time; /* transition time of rule */
 };
 
-#define JULIAN_DAY            0 /* Jn - Julian day */
-#define DAY_OF_YEAR           1 /* n - day of year */
-#define MONTH_NTH_DAY_OF_WEEK 2 /* Mm.n.d - month, week, day of week */
+#define JULIAN_DAY             0       /* Jn = Julian day */
+#define DAY_OF_YEAR            1       /* n = day of year */
+#define MONTH_NTH_DAY_OF_WEEK  2       /* Mm.n.d = month, week, day of week */
 
 /*
 ** Prototypes for static functions.
@@ -158,10 +158,10 @@
 static const char * getoffset(const char * strp, int_fast32_t * offsetp);
 static const char * getrule(const char * strp, struct rule * rulep);
 static void     gmtload(struct state * sp);
-static struct tm *  gmtsub(const time_t * timep, const int_fast32_t offset,
-                struct tm * tmp, const struct state * sp); // android-changed: added sp.
+static struct tm *  gmtsub(const time_t * timep, int_fast32_t offset,
+                struct tm * tmp, struct state * sp); // android-changed: added sp.
 static struct tm *  localsub(const time_t * timep, int_fast32_t offset,
-                struct tm * tmp, const struct state * sp); // android-changed: added sp.
+                struct tm * tmp, struct state * sp); // android-changed: added sp.
 static int      increment_overflow(int * number, int delta);
 static int      leaps_thru_end_of(int y) ATTRIBUTE_PURE;
 static int      increment_overflow32(int_fast32_t * number, int delta);
@@ -173,16 +173,16 @@
 static void     settzname(void);
 static time_t       time1(struct tm * tmp,
                 struct tm * (*funcp)(const time_t *,
-                int_fast32_t, struct tm *, const struct state *), // android-changed: added state*.
-                int_fast32_t offset, const struct state * sp); // android-changed: added sp.
-static time_t       time2(struct tm * const tmp,
-                struct tm * (*const funcp)(const time_t *,
-                int_fast32_t, struct tm*, const struct state *), // android-changed: added state*.
-                int_fast32_t offset, int * okayp, const struct state * sp); // android-changed: added sp.
+                int_fast32_t, struct tm *, struct state *), // android-changed: added state*.
+                int_fast32_t, struct state * sp); // android-changed: added sp.
+static time_t       time2(struct tm * tmp,
+                struct tm * (*funcp)(const time_t *,
+                int_fast32_t, struct tm*, struct state *), // android-changed: added state*.
+                int_fast32_t offset, int * okayp, struct state * sp); // android-changed: added sp.
 static time_t       time2sub(struct tm *tmp,
                 struct tm * (*funcp) (const time_t *,
-                int_fast32_t, struct tm*, const struct state *), // android-changed: added state*.
-                int_fast32_t offset, int * okayp, int do_norm_secs, const struct state * sp); // android-change: added sp.
+                int_fast32_t, struct tm*, struct state *), // android-changed: added state*.
+                int_fast32_t offset, int * okayp, int do_norm_secs, struct state * sp); // android-change: added sp.
 static struct tm *  timesub(const time_t * timep, int_fast32_t offset,
                 const struct state * sp, struct tm * tmp);
 static int      tmcomp(const struct tm * atmp,
@@ -217,8 +217,8 @@
 static int  gmt_is_set;
 
 char * tzname[2] = {
-    wildabbr,
-    wildabbr
+    (char *) wildabbr,
+    (char *) wildabbr
 };
 
 /*
@@ -270,8 +270,7 @@
     register struct state * const sp = lclptr;
     register int                  i;
 
-    tzname[0] = wildabbr;
-    tzname[1] = wildabbr;
+    tzname[0] = tzname[1] = (char *) wildabbr;
 #ifdef USG_COMPAT
     daylight = 0;
     timezone = 0;
@@ -279,12 +278,10 @@
 #ifdef ALTZONE
     altzone = 0;
 #endif /* defined ALTZONE */
-#ifdef ALL_STATE
     if (sp == NULL) {
-        tzname[0] = tzname[1] = gmt;
+        tzname[0] = tzname[1] = (char *) gmt;
         return;
     }
-#endif /* defined ALL_STATE */
     /*
     ** And to get the latest zone names into tzname. . .
     */
@@ -332,11 +329,11 @@
 }
 
 static int
-differ_by_repeat(const time_t t1, const time_t t0)
+differ_by_repeat(const time_t t1 __unused, const time_t t0 __unused)
 {
     if (TYPE_BIT(time_t) - TYPE_SIGNED(time_t) < SECSPERREPEAT_BITS)
         return 0;
-#if __LP64__ // 32-bit Android only has a signed 32-bit time_t; 64-bit Android is fixed.
+#if defined(__LP64__) // 32-bit Android only has a signed 32-bit time_t; 64-bit Android is fixed.
     return t1 - t0 == SECSPERREPEAT;
 #endif
 }
@@ -356,25 +353,50 @@
                       2 * sizeof *sp +
                       4 * TZ_MAX_TIMES];
     } u_t;
-#ifdef ALL_STATE
-    register u_t *        up;
+    union local_storage {
+        /*
+        ** Section 4.9.1 of the C standard says that
+        ** "FILENAME_MAX expands to an integral constant expression
+        ** that is the size needed for an array of char large enough
+        ** to hold the longest file name string that the implementation
+        ** guarantees can be opened."
+        */
+        //char            fullname[FILENAME_MAX + 1];
 
-    up = (u_t *) calloc(1, sizeof *up);
-    if (up == NULL)
+        /* The main part of the storage for this function.  */
+        struct {
+            u_t u;
+            struct state st;
+        } u;
+    };
+    //register char *fullname;
+    register u_t *up;
+    register union local_storage *lsp;
+#ifdef ALL_STATE
+    lsp = malloc(sizeof *lsp);
+    if (!lsp)
         return -1;
 #else /* !defined ALL_STATE */
-    u_t                   u;
-    register u_t * const  up = &u;
+    union local_storage ls;
+    lsp = &ls;
 #endif /* !defined ALL_STATE */
+    //fullname = lsp->fullname;
+    up = &lsp->u.u;
 
     sp->goback = sp->goahead = FALSE;
-    if (name == NULL && (name = TZDEFAULT) == NULL)
-        goto oops;
+
+    if (! name) {
+        name = TZDEFAULT;
+        if (! name)
+            goto oops;
+    }
+
     int toread;
     fid = __bionic_open_tzdata(name, &toread);
     if (fid < 0)
         goto oops;
-    nread = read(fid, up->buf, toread);
+
+    nread = read(fid, up->buf, sizeof up->buf);
     if (close(fid) < 0 || nread <= 0)
         goto oops;
     for (stored = 4; stored <= 8; stored *= 2) {
@@ -506,12 +528,9 @@
     if (doextend && nread > 2 &&
         up->buf[0] == '\n' && up->buf[nread - 1] == '\n' &&
         sp->typecnt + 2 <= TZ_MAX_TYPES) {
-            struct state * ts = malloc(sizeof *ts);
+            struct state    *ts = &lsp->u.st;
             register int result;
 
-            if (ts == NULL)
-                goto oops;
-
             up->buf[nread - 1] = '\0';
             result = tzparse(&up->buf[1], ts, FALSE);
             if (result == 0 && ts->typecnt == 2 &&
@@ -540,7 +559,6 @@
                     sp->ttis[sp->typecnt++] = ts->ttis[0];
                     sp->ttis[sp->typecnt++] = ts->ttis[1];
             }
-            free(ts);
     }
     if (sp->timecnt > 1) {
         for (i = 1; i < sp->timecnt; ++i)
@@ -712,10 +730,10 @@
     int num;
 
     /*
-    ** `HOURSPERDAY * DAYSPERWEEK - 1' allows quasi-Posix rules like
+    ** 'HOURSPERDAY * DAYSPERWEEK - 1' allows quasi-Posix rules like
     ** "M10.4.6/26", which does not conform to Posix,
     ** but which specifies the equivalent of
-    ** ``02:00 on the first Sunday on or after 23 Oct''.
+    ** "02:00 on the first Sunday on or after 23 Oct".
     */
     strp = getnum(strp, &num, 0, HOURSPERDAY * DAYSPERWEEK - 1);
     if (strp == NULL)
@@ -729,7 +747,7 @@
         *secsp += num * SECSPERMIN;
         if (*strp == ':') {
             ++strp;
-            /* `SECSPERMIN' allows for leap seconds. */
+            /* 'SECSPERMIN' allows for leap seconds. */
             strp = getnum(strp, &num, 0, SECSPERMIN);
             if (strp == NULL)
                 return NULL;
@@ -927,7 +945,6 @@
     register int         load_result;
     static struct ttinfo zttinfo;
 
-    INITIALIZE(dstname);
     stdname = name;
     if (lastditch) {
         stdlen = strlen(name);  /* length of standard zone name */
@@ -1005,6 +1022,7 @@
             sp->ttis[1].tt_gmtoff = -stdoffset;
             sp->ttis[1].tt_isdst = 0;
             sp->ttis[1].tt_abbrind = 0;
+            sp->defaulttype = 0;
             timecnt = 0;
             janfirst = 0;
             yearlim = EPOCH_YEAR + YEARSPERREPEAT;
@@ -1130,6 +1148,7 @@
             sp->ttis[1].tt_isdst = TRUE;
             sp->ttis[1].tt_abbrind = stdlen + 1;
             sp->typecnt = 2;
+            sp->defaulttype = 0;
         }
     } else {
         dstlen = 0;
@@ -1139,6 +1158,7 @@
         sp->ttis[0].tt_gmtoff = -stdoffset;
         sp->ttis[0].tt_isdst = 0;
         sp->ttis[0].tt_abbrind = 0;
+        sp->defaulttype = 0;
     }
     sp->charcnt = stdlen + 1;
     if (dstlen != 0)
@@ -1179,7 +1199,7 @@
 
 #ifdef ALL_STATE
     if (lclptr == NULL) {
-        lclptr = calloc(1, sizeof *lclptr);
+        lclptr = malloc(sizeof *lclptr);
         if (lclptr == NULL) {
             settzname();    /* all we can do */
             return;
@@ -1196,7 +1216,7 @@
 static void
 tzset_locked(void)
 {
-    register const char * name = NULL;
+    register const char * name;
 
     name = getenv("TZ");
 
@@ -1219,7 +1239,7 @@
 
 #ifdef ALL_STATE
     if (lclptr == NULL) {
-        lclptr = calloc(1, sizeof *lclptr);
+        lclptr = malloc(sizeof *lclptr);
         if (lclptr == NULL) {
             settzname();    /* all we can do */
             return;
@@ -1263,7 +1283,7 @@
 /*ARGSUSED*/
 static struct tm *
 localsub(const time_t * const timep, const int_fast32_t offset,
-         struct tm * const tmp, const struct state * sp) // android-changed: added sp.
+         struct tm * const tmp, struct state * sp) // android-changed: added sp.
 {
     register const struct ttinfo * ttisp;
     register int         i;
@@ -1275,10 +1295,8 @@
         sp = lclptr;
     }
     // END android-changed
-#ifdef ALL_STATE
     if (sp == NULL)
         return gmtsub(timep, offset, tmp, sp); // android-changed: added sp.
-#endif /* defined ALL_STATE */
     if ((sp->goback && t < sp->ats[0]) ||
         (sp->goahead && t > sp->ats[sp->timecnt - 1])) {
             time_t          newt = t;
@@ -1371,18 +1389,18 @@
 
 static struct tm *
 gmtsub(const time_t * const timep, const int_fast32_t offset,
-       struct tm *const tmp, const struct state * sp) // android-changed: added sp.
+       struct tm *const tmp, struct state * sp __unused) // android-changed: added sp.
 {
     register struct tm * result;
 
-    (void) sp; // android-added: unused.
-
     if (!gmt_is_set) {
-        gmt_is_set = TRUE;
 #ifdef ALL_STATE
-        gmtptr = calloc(1, sizeof *gmtptr);
-        if (gmtptr != NULL)
+        gmtptr = malloc(sizeof *gmtptr);
+        gmt_is_set = gmtptr != NULL;
+#else
+        gmt_is_set = TRUE;
 #endif /* defined ALL_STATE */
+        if (gmt_is_set)
             gmtload(gmtptr);
     }
     result = timesub(timep, offset, gmtptr, tmp);
@@ -1392,18 +1410,7 @@
     ** "UT+xxxx" or "UT-xxxx" if offset is non-zero,
     ** but this is no time for a treasure hunt.
     */
-    if (offset != 0)
-        tmp->TM_ZONE = wildabbr;
-    else {
-#ifdef ALL_STATE
-        if (gmtptr == NULL)
-            tmp->TM_ZONE = gmt;
-        else    tmp->TM_ZONE = gmtptr->chars;
-#endif /* defined ALL_STATE */
-#ifndef ALL_STATE
-        tmp->TM_ZONE = gmtptr->chars;
-#endif /* State Farm */
-    }
+    tmp->TM_ZONE = offset ? wildabbr : gmtptr ? gmtptr->chars : gmt;
 #endif /* defined TM_ZONE */
     return result;
 }
@@ -1430,6 +1437,16 @@
     return result;
 }
 
+#ifdef STD_INSPIRED
+
+struct tm *
+offtime(const time_t *const timep, const long offset)
+{
+    return gmtsub(timep, offset, &tmGlobal, NULL); // android-changed: extra parameter.
+}
+
+#endif /* defined STD_INSPIRED */
+
 /*
 ** Return the number of leap years through the end of the given year
 ** where, to make the math easy, the answer for year zero is defined as zero.
@@ -1459,12 +1476,7 @@
 
     corr = 0;
     hit = 0;
-#ifdef ALL_STATE
     i = (sp == NULL) ? 0 : sp->leapcnt;
-#endif /* defined ALL_STATE */
-#ifndef ALL_STATE
-    i = sp->leapcnt;
-#endif /* State Farm */
     while (--i >= 0) {
         lp = &sp->lsis[i];
         if (*timep >= lp->ls_trans) {
@@ -1699,10 +1711,10 @@
 
 static time_t
 time2sub(struct tm * const tmp,
-         struct tm *(*const funcp)(const time_t*, int_fast32_t, struct tm*, const struct state*),
+         struct tm *(*const funcp)(const time_t*, int_fast32_t, struct tm*, struct state*),
          const int_fast32_t offset,
          int * const okayp,
-         const int do_norm_secs, const struct state * sp) // android-changed: added sp
+         const int do_norm_secs, struct state * sp) // android-changed: added sp
 {
     register int          dir;
     register int          i, j;
@@ -1837,14 +1849,12 @@
         */
         // BEGIN android-changed: support user-supplied sp
         if (sp == NULL) {
-            sp = (const struct state *)
+            sp = (struct state *)
                 ((funcp == localsub) ? lclptr : gmtptr);
         }
         // END android-changed
-#ifdef ALL_STATE
         if (sp == NULL)
             return WRONG;
-#endif /* defined ALL_STATE */
         for (i = sp->typecnt - 1; i >= 0; --i) {
             if (sp->ttis[i].tt_isdst != yourtm.tm_isdst)
                 continue;
@@ -1880,9 +1890,9 @@
 
 static time_t
 time2(struct tm * const tmp,
-      struct tm * (*const funcp)(const time_t *, int_fast32_t, struct tm *, const struct state *), // android-changed: added sp.
+      struct tm * (*const funcp)(const time_t *, int_fast32_t, struct tm *, struct state *), // android-changed: added sp.
       const int_fast32_t offset,
-      int *const okayp, const struct state* sp) // android-changed: added sp.
+      int *const okayp, struct state* sp) // android-changed: added sp.
 {
     time_t t;
 
@@ -1897,16 +1907,16 @@
 
 static time_t
 time1(struct tm * const tmp,
-      struct tm * (* const funcp) (const time_t *, int_fast32_t, struct tm *, const struct state *), // android-changed: added sp.
-      const int_fast32_t offset, const struct state * sp) // android-changed: added sp.
+      struct tm * (* const funcp) (const time_t *, int_fast32_t, struct tm *, struct state *), // android-changed: added sp.
+      const int_fast32_t offset, struct state * sp) // android-changed: added sp.
 {
     register time_t t;
     register int    samei, otheri;
     register int    sameind, otherind;
     register int    i;
     register int    nseen;
-    int             seen[TZ_MAX_TYPES];
-    int             types[TZ_MAX_TYPES];
+    char            seen[TZ_MAX_TYPES];
+    unsigned char   types[TZ_MAX_TYPES];
     int             okay;
 
     if (tmp == NULL) {
@@ -1916,17 +1926,15 @@
     if (tmp->tm_isdst > 1)
         tmp->tm_isdst = 1;
     t = time2(tmp, funcp, offset, &okay, sp); // android-changed: added sp.
-#ifdef PCTS
-    /*
-    ** PCTS code courtesy Grant Sullivan.
-    */
     if (okay)
         return t;
     if (tmp->tm_isdst < 0)
+#ifdef PCTS
+        /*
+        ** POSIX Conformance Test Suite code courtesy Grant Sullivan.
+        */
         tmp->tm_isdst = 0;  /* reset to std and try again */
-#endif /* defined PCTS */
-#ifndef PCTS
-    if (okay || tmp->tm_isdst < 0)
+#else
         return t;
 #endif /* !defined PCTS */
     /*
@@ -1937,13 +1945,11 @@
     */
     // BEGIN android-changed: support user-supplied sp.
     if (sp == NULL) {
-        sp = (const struct state *) ((funcp == localsub) ?  lclptr : gmtptr);
+        sp = (struct state *) ((funcp == localsub) ?  lclptr : gmtptr);
     }
     // BEGIN android-changed
-#ifdef ALL_STATE
     if (sp == NULL)
         return WRONG;
-#endif /* defined ALL_STATE */
     for (i = 0; i < sp->typecnt; ++i)
         seen[i] = FALSE;
     nseen = 0;
@@ -2008,6 +2014,14 @@
     return result;
 }
 
+time_t
+timeoff(struct tm *const tmp, const long offset)
+{
+    if (tmp != NULL)
+        tmp->tm_isdst = 0;
+    return time1(tmp, gmtsub, offset, NULL); // android-changed: extra parameter.
+}
+
 #endif /* defined STD_INSPIRED */
 
 #ifdef CMUCS
@@ -2108,10 +2122,6 @@
 #include <stdint.h>
 #include <arpa/inet.h> // For ntohl(3).
 
-static int to_int(unsigned char* s) {
-  return (s[0] << 24) | (s[1] << 16) | (s[2] << 8) | s[3];
-}
-
 static int __bionic_open_tzdata_path(const char* path_prefix_variable, const char* path_suffix,
                                      const char* olson_id, int* data_size) {
   const char* path_prefix = getenv(path_prefix_variable);
@@ -2283,7 +2293,7 @@
 }
 
 // Non-standard API: mktime(3) but with an explicit timezone parameter.
-time_t mktime_tz(struct tm* const tmp, const char* tz) {
+time_t __attribute__((visibility("default"))) mktime_tz(struct tm* const tmp, const char* tz) {
   struct state* st = malloc(sizeof(*st));
   time_t return_value;
 
@@ -2300,7 +2310,7 @@
 }
 
 // Non-standard API: localtime(3) but with an explicit timezone parameter.
-void localtime_tz(const time_t* const timep, struct tm* tmp, const char* tz) {
+void __attribute__((visibility("default"))) localtime_tz(const time_t* const timep, struct tm* tmp, const char* tz) {
   struct state* st = malloc(sizeof(*st));
 
   if (st == NULL)
diff --git a/libc/tzcode/private.h b/libc/tzcode/private.h
index 4eb0ab6..c30c711 100644
--- a/libc/tzcode/private.h
+++ b/libc/tzcode/private.h
@@ -19,7 +19,7 @@
 
 /*
 ** Defaults for preprocessor symbols.
-** You can override these in your C compiler options, e.g. `-DHAVE_ADJTIME=0'.
+** You can override these in your C compiler options, e.g. '-DHAVE_ADJTIME=0'.
 */
 
 #ifndef HAVE_ADJTIME
@@ -62,9 +62,11 @@
 #define HAVE_UTMPX_H		0
 #endif /* !defined HAVE_UTMPX_H */
 
+#if !defined(__ANDROID__)
 #ifndef LOCALE_HOME
 #define LOCALE_HOME		"/usr/lib/locale"
 #endif /* !defined LOCALE_HOME */
+#endif // __ANDROID__
 
 #if HAVE_INCOMPATIBLE_CTIME_R
 #define asctime_r _incompatible_asctime_r
@@ -120,8 +122,9 @@
 */
 #ifndef HAVE_STDINT_H
 #define HAVE_STDINT_H \
-	(199901 <= __STDC_VERSION__ || \
-	2 < (__GLIBC__ + (0 < __GLIBC_MINOR__)))
+   (199901 <= __STDC_VERSION__ \
+    || 2 < __GLIBC__ + (1 <= __GLIBC_MINOR__)	\
+    || __CYGWIN__)
 #endif /* !defined HAVE_STDINT_H */
 
 #if HAVE_STDINT_H
@@ -205,6 +208,10 @@
 #define INT32_MIN (-1 - INT32_MAX)
 #endif /* !defined INT32_MIN */
 
+#ifndef SIZE_MAX
+#define SIZE_MAX ((size_t) -1)
+#endif
+
 #if 2 < __GNUC__ + (96 <= __GNUC_MINOR__)
 # define ATTRIBUTE_CONST __attribute__ ((const))
 # define ATTRIBUTE_PURE __attribute__ ((__pure__))
@@ -347,29 +354,15 @@
 ** INITIALIZE(x)
 */
 
-#ifndef GNUC_or_lint
 #ifdef lint
-#define GNUC_or_lint
-#endif /* defined lint */
-#ifndef lint
-#ifdef __GNUC__
-#define GNUC_or_lint
-#endif /* defined __GNUC__ */
-#endif /* !defined lint */
-#endif /* !defined GNUC_or_lint */
-
-#ifndef INITIALIZE
-#ifdef GNUC_or_lint
-#define INITIALIZE(x)	((x) = 0)
-#endif /* defined GNUC_or_lint */
-#ifndef GNUC_or_lint
-#define INITIALIZE(x)
-#endif /* !defined GNUC_or_lint */
-#endif /* !defined INITIALIZE */
+# define INITIALIZE(x)	((x) = 0)
+#else
+# define INITIALIZE(x)
+#endif
 
 /*
 ** For the benefit of GNU folk...
-** `_(MSGID)' uses the current locale's message library string for MSGID.
+** '_(MSGID)' uses the current locale's message library string for MSGID.
 ** The default is to use gettext if available, and use MSGID otherwise.
 */
 
@@ -381,9 +374,9 @@
 #endif /* !HAVE_GETTEXT */
 #endif /* !defined _ */
 
-#ifndef TZ_DOMAIN
-#define TZ_DOMAIN "tz"
-#endif /* !defined TZ_DOMAIN */
+#if !defined TZ_DOMAIN && defined TZ_DOMAINDIR
+# define TZ_DOMAIN "tz"
+#endif
 
 #if HAVE_INCOMPATIBLE_CTIME_R
 #undef asctime_r
diff --git a/libc/tzcode/strftime.c b/libc/tzcode/strftime.c
index 967629d..f996f48 100644
--- a/libc/tzcode/strftime.c
+++ b/libc/tzcode/strftime.c
@@ -1,12 +1,9 @@
-#ifndef lint
-#ifndef NOID
-static char elsieid[] = "@(#)strftime.c 8.1";
 /*
-** Based on the UCB version with the ID appearing below.
+** Based on the UCB version with the copyright notice and sccsid
+** appearing below.
+**
 ** This is ANSIish only when "multibyte character == plain character".
 */
-#endif /* !defined NOID */
-#endif /* !defined lint */
 
 #include "private.h"
 
@@ -22,35 +19,27 @@
 ** by the University of California, Berkeley. The name of the
 ** University may not be used to endorse or promote products derived
 ** from this software without specific prior written permission.
-** THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+** THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
 ** IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 ** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */
 
-#ifndef LIBC_SCCS
-#ifndef lint
-static const char   sccsid[] = "@(#)strftime.c  5.4 (Berkeley) 3/14/89";
-#endif /* !defined lint */
-#endif /* !defined LIBC_SCCS */
-
 #include "tzfile.h"
 #include "fcntl.h"
 #include "locale.h"
-#include <ctype.h>
+
+#if __ANDROID__
+/* Android: struct lc_time_T is defined as strftime_locale in "bionic_time.h" */
+#include "private/bionic_time.h"  /* for strftime_tz */
+#define  lc_time_T    strftime_locale
 #if defined(__LP64__)
 #define time64_t time_t
 #define mktime64 mktime
 #else
 #include <time64.h>
 #endif
-#include "private/bionic_time.h"  /* for strftime_tz */
-
-/* struct lc_time_T is now defined as strftime_locale
- * in <time.h>
- */
-#if 1
-#define  lc_time_T    strftime_locale
-#else
+#include <ctype.h>
+#else // not __ANDROID__
 struct lc_time_T {
     const char *    mon[MONSPERYEAR];
     const char *    month[MONSPERYEAR];
@@ -65,7 +54,15 @@
 };
 #endif
 
+#if LOCALE_HOME
+#include "sys/stat.h"
+static struct lc_time_T                localebuf;
+static struct lc_time_T *      _loc(void);
+#define Locale _loc()
+#endif /* defined LOCALE_HOME */
+#ifndef LOCALE_HOME
 #define Locale  (&C_time_locale)
+#endif /* !defined LOCALE_HOME */
 
 static const struct lc_time_T   C_time_locale = {
     {
@@ -147,7 +144,7 @@
 }
 
 size_t
-strftime_tz(s, maxsize, format, t, locale)
+__attribute__((visibility("default"))) strftime_tz(s, maxsize, format, t, locale)
 char * const        s;
 const size_t        maxsize;
 const char * const  format;
diff --git a/libc/unistd/syslog.c b/libc/unistd/syslog.c
index 7878475..339df68 100644
--- a/libc/unistd/syslog.c
+++ b/libc/unistd/syslog.c
@@ -44,6 +44,18 @@
 #include <unistd.h>
 #include <stdarg.h>
 
+struct syslog_data {
+  int log_file;
+  int connected;
+  int opened;
+  int log_stat;
+  const char* log_tag;
+  int log_fac;
+  int log_mask;
+};
+
+#define SYSLOG_DATA_INIT {-1, 0, 0, 0, (const char *)0, LOG_USER, 0xff}
+
 static struct syslog_data sdata = SYSLOG_DATA_INIT;
 
 extern const char	*__progname;		/* Program name, from crt0. */
@@ -51,6 +63,18 @@
 static void	disconnectlog_r(struct syslog_data *);	/* disconnect from syslogd */
 static void	connectlog_r(struct syslog_data *);	/* (re)connect to syslogd */
 
+#if defined(__LP64__)
+#define SYSLOG_R_VISIBILITY static
+#else
+#define SYSLOG_R_VISIBILITY extern
+#endif
+
+SYSLOG_R_VISIBILITY void closelog_r(struct syslog_data*);
+SYSLOG_R_VISIBILITY void openlog_r(const char*, int, int, struct syslog_data*);
+SYSLOG_R_VISIBILITY int setlogmask_r(int, struct syslog_data*);
+SYSLOG_R_VISIBILITY void syslog_r(int, struct syslog_data*, const char*, ...) __printflike(3, 4);
+SYSLOG_R_VISIBILITY void vsyslog_r(int, struct syslog_data*, const char*, va_list) __printflike(3, 0);
+
 /*
  * syslog, vsyslog --
  *	print message on log file; output is intended for syslogd(8).
@@ -157,7 +181,7 @@
 	prlen = snprintf(p, tbuf_left, "<%d>", pri);
 	DEC();
 
-	/* 
+	/*
 	 * syslogd will expand time automagically for reentrant case, and
 	 * for normal case, just do like before
 	 */
@@ -196,10 +220,10 @@
 			++fmt;
 			if (data == &sdata) {
 				prlen = snprintf(t, fmt_left, "%s",
-				    strerror(saved_errno)); 
+				    strerror(saved_errno));
 			} else {
 				prlen = snprintf(t, fmt_left, "Error %d",
-				    saved_errno); 
+				    saved_errno);
 			}
 			if (prlen < 0)
 				prlen = 0;
@@ -269,7 +293,7 @@
 	if (error == -1 && (data->log_stat & LOG_CONS) &&
 	    (fd = open(_PATH_CONSOLE, O_WRONLY|O_NONBLOCK, 0)) >= 0) {
 		struct iovec iov[2];
-		
+
 		p = strchr(tbuf, '>') + 1;
 		iov[0].iov_base = p;
 		iov[0].iov_len = cnt - (p - tbuf);
diff --git a/libc/upstream-dlmalloc/malloc.c b/libc/upstream-dlmalloc/malloc.c
index 3ef9b61..4362f49 100644
--- a/libc/upstream-dlmalloc/malloc.c
+++ b/libc/upstream-dlmalloc/malloc.c
@@ -5317,12 +5317,19 @@
   return dlmemalign(pagesz, bytes);
 }
 
+/* BEGIN android-changed: added overflow check */
 void* dlpvalloc(size_t bytes) {
   size_t pagesz;
+  size_t size;
   ensure_initialization();
   pagesz = mparams.page_size;
-  return dlmemalign(pagesz, (bytes + pagesz - SIZE_T_ONE) & ~(pagesz - SIZE_T_ONE));
+  size = (bytes + pagesz - SIZE_T_ONE) & ~(pagesz - SIZE_T_ONE);
+  if (size < bytes) {
+    return NULL;
+  }
+  return dlmemalign(pagesz, size);
 }
+/* END android-change */
 
 void** dlindependent_calloc(size_t n_elements, size_t elem_size,
                             void* chunks[]) {
diff --git a/libc/upstream-netbsd/android/include/rand48.h b/libc/upstream-netbsd/android/include/rand48.h
index 1ad8b0d..1279906 100644
--- a/libc/upstream-netbsd/android/include/rand48.h
+++ b/libc/upstream-netbsd/android/include/rand48.h
@@ -18,10 +18,10 @@
 
 #include <stdlib.h>
 
-extern void		__dorand48(unsigned short[3]);
-extern unsigned short	__rand48_seed[3];
-extern unsigned short	__rand48_mult[3];
-extern unsigned short	__rand48_add;
+__LIBC_HIDDEN__ void		__dorand48(unsigned short[3]);
+__LIBC_HIDDEN__ unsigned short	__rand48_seed[3];
+__LIBC_HIDDEN__ unsigned short	__rand48_mult[3];
+__LIBC_HIDDEN__ unsigned short	__rand48_add;
 
 #define	RAND48_SEED_0	(0x330e)
 #define	RAND48_SEED_1	(0xabcd)
diff --git a/libc/include/sys/sha1.h b/libc/upstream-netbsd/android/include/sys/sha1.h
similarity index 100%
rename from libc/include/sys/sha1.h
rename to libc/upstream-netbsd/android/include/sys/sha1.h
diff --git a/libc/upstream-netbsd/common/lib/libc/stdlib/random.c b/libc/upstream-netbsd/common/lib/libc/stdlib/random.c
new file mode 100644
index 0000000..e7503c7
--- /dev/null
+++ b/libc/upstream-netbsd/common/lib/libc/stdlib/random.c
@@ -0,0 +1,530 @@
+/*	$NetBSD: random.c,v 1.4 2014/06/12 20:59:46 christos Exp $	*/
+
+/*
+ * Copyright (c) 1983, 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.
+ * 3. 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(_KERNEL) && !defined(_STANDALONE)
+#include <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
+static char sccsid[] = "@(#)random.c	8.2 (Berkeley) 5/19/95";
+#else
+__RCSID("$NetBSD: random.c,v 1.4 2014/06/12 20:59:46 christos Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+#include "namespace.h"
+
+#include <assert.h>
+#include <errno.h>
+#include <stdlib.h>
+#include "reentrant.h"
+
+#ifdef __weak_alias
+__weak_alias(initstate,_initstate)
+__weak_alias(random,_random)
+__weak_alias(setstate,_setstate)
+__weak_alias(srandom,_srandom)
+#endif
+
+
+#ifdef _REENTRANT
+static mutex_t random_mutex = MUTEX_INITIALIZER;
+#endif
+#else
+#include <lib/libkern/libkern.h>
+#define mutex_lock(a)	(void)0
+#define mutex_unlock(a) (void)0
+#endif
+
+#ifndef SMALL_RANDOM
+static void srandom_unlocked(unsigned int);
+static long random_unlocked(void);
+
+#define USE_BETTER_RANDOM
+
+/*
+ * random.c:
+ *
+ * An improved random number generation package.  In addition to the standard
+ * rand()/srand() like interface, this package also has a special state info
+ * interface.  The initstate() routine is called with a seed, an array of
+ * bytes, and a count of how many bytes are being passed in; this array is
+ * then initialized to contain information for random number generation with
+ * that much state information.  Good sizes for the amount of state
+ * information are 32, 64, 128, and 256 bytes.  The state can be switched by
+ * calling the setstate() routine with the same array as was initiallized
+ * with initstate().  By default, the package runs with 128 bytes of state
+ * information and generates far better random numbers than a linear
+ * congruential generator.  If the amount of state information is less than
+ * 32 bytes, a simple linear congruential R.N.G. is used.
+ *
+ * Internally, the state information is treated as an array of ints; the
+ * zeroeth element of the array is the type of R.N.G. being used (small
+ * integer); the remainder of the array is the state information for the
+ * R.N.G.  Thus, 32 bytes of state information will give 7 ints worth of
+ * state information, which will allow a degree seven polynomial.  (Note:
+ * the zeroeth word of state information also has some other information
+ * stored in it -- see setstate() for details).
+ * 
+ * The random number generation technique is a linear feedback shift register
+ * approach, employing trinomials (since there are fewer terms to sum up that
+ * way).  In this approach, the least significant bit of all the numbers in
+ * the state table will act as a linear feedback shift register, and will
+ * have period 2^deg - 1 (where deg is the degree of the polynomial being
+ * used, assuming that the polynomial is irreducible and primitive).  The
+ * higher order bits will have longer periods, since their values are also
+ * influenced by pseudo-random carries out of the lower bits.  The total
+ * period of the generator is approximately deg*(2**deg - 1); thus doubling
+ * the amount of state information has a vast influence on the period of the
+ * generator.  Note: the deg*(2**deg - 1) is an approximation only good for
+ * large deg, when the period of the shift register is the dominant factor.
+ * With deg equal to seven, the period is actually much longer than the
+ * 7*(2**7 - 1) predicted by this formula.
+ *
+ * Modified 28 December 1994 by Jacob S. Rosenberg.
+ * The following changes have been made:
+ * All references to the type u_int have been changed to unsigned long.
+ * All references to type int have been changed to type long.  Other
+ * cleanups have been made as well.  A warning for both initstate and
+ * setstate has been inserted to the effect that on Sparc platforms
+ * the 'arg_state' variable must be forced to begin on word boundaries.
+ * This can be easily done by casting a long integer array to char *.
+ * The overall logic has been left STRICTLY alone.  This software was
+ * tested on both a VAX and Sun SpacsStation with exactly the same
+ * results.  The new version and the original give IDENTICAL results.
+ * The new version is somewhat faster than the original.  As the
+ * documentation says:  "By default, the package runs with 128 bytes of
+ * state information and generates far better random numbers than a linear
+ * congruential generator.  If the amount of state information is less than
+ * 32 bytes, a simple linear congruential R.N.G. is used."  For a buffer of
+ * 128 bytes, this new version runs about 19 percent faster and for a 16
+ * byte buffer it is about 5 percent faster.
+ *
+ * Modified 07 January 2002 by Jason R. Thorpe.
+ * The following changes have been made:
+ * All the references to "long" have been changed back to "int".  This
+ * fixes memory corruption problems on LP64 platforms.
+ */
+
+/*
+ * For each of the currently supported random number generators, we have a
+ * break value on the amount of state information (you need at least this
+ * many bytes of state info to support this random number generator), a degree
+ * for the polynomial (actually a trinomial) that the R.N.G. is based on, and
+ * the separation between the two lower order coefficients of the trinomial.
+ */
+#define	TYPE_0		0		/* linear congruential */
+#define	BREAK_0		8
+#define	DEG_0		0
+#define	SEP_0		0
+
+#define	TYPE_1		1		/* x**7 + x**3 + 1 */
+#define	BREAK_1		32
+#define	DEG_1		7
+#define	SEP_1		3
+
+#define	TYPE_2		2		/* x**15 + x + 1 */
+#define	BREAK_2		64
+#define	DEG_2		15
+#define	SEP_2		1
+
+#define	TYPE_3		3		/* x**31 + x**3 + 1 */
+#define	BREAK_3		128
+#define	DEG_3		31
+#define	SEP_3		3
+
+#define	TYPE_4		4		/* x**63 + x + 1 */
+#define	BREAK_4		256
+#define	DEG_4		63
+#define	SEP_4		1
+
+/*
+ * Array versions of the above information to make code run faster --
+ * relies on fact that TYPE_i == i.
+ */
+#define	MAX_TYPES	5		/* max number of types above */
+
+static const int degrees[MAX_TYPES] =	{ DEG_0, DEG_1, DEG_2, DEG_3, DEG_4 };
+static const int seps[MAX_TYPES] =	{ SEP_0, SEP_1, SEP_2, SEP_3, SEP_4 };
+
+/*
+ * Initially, everything is set up as if from:
+ *
+ *	initstate(1, &randtbl, 128);
+ *
+ * Note that this initialization takes advantage of the fact that srandom()
+ * advances the front and rear pointers 10*rand_deg times, and hence the
+ * rear pointer which starts at 0 will also end up at zero; thus the zeroeth
+ * element of the state information, which contains info about the current
+ * position of the rear pointer is just
+ *
+ *	MAX_TYPES * (rptr - state) + TYPE_3 == TYPE_3.
+ */
+
+/* LINTED */
+static int randtbl[DEG_3 + 1] = {
+	TYPE_3,
+#ifdef USE_BETTER_RANDOM
+	0x991539b1, 0x16a5bce3, 0x6774a4cd,
+	0x3e01511e, 0x4e508aaa, 0x61048c05,
+	0xf5500617, 0x846b7115, 0x6a19892c,
+	0x896a97af, 0xdb48f936, 0x14898454,
+	0x37ffd106, 0xb58bff9c, 0x59e17104,
+	0xcf918a49, 0x09378c83, 0x52c7a471,
+	0x8d293ea9, 0x1f4fc301, 0xc3db71be,
+	0x39b44e1c, 0xf8a44ef9, 0x4c8b80b1,
+	0x19edc328, 0x87bf4bdd, 0xc9b240e5,
+	0xe9ee4b1b, 0x4382aee7, 0x535b6b41,
+	0xf3bec5da,
+#else
+	0x9a319039, 0x32d9c024, 0x9b663182,
+	0x5da1f342, 0xde3b81e0, 0xdf0a6fb5,
+	0xf103bc02, 0x48f340fb, 0x7449e56b,
+	0xbeb1dbb0, 0xab5c5918, 0x946554fd,
+	0x8c2e680f, 0xeb3d799f, 0xb11ee0b7,
+	0x2d436b86, 0xda672e2a, 0x1588ca88,
+	0xe369735d, 0x904f35f7, 0xd7158fd6,
+	0x6fa6f051, 0x616e6b96, 0xac94efdc,
+	0x36413f93, 0xc622c298, 0xf5a42ab8,
+	0x8a88d77b, 0xf5ad9d0e, 0x8999220b,
+	0x27fb47b9,
+#endif /* USE_BETTER_RANDOM */
+};
+
+/*
+ * fptr and rptr are two pointers into the state info, a front and a rear
+ * pointer.  These two pointers are always rand_sep places aparts, as they
+ * cycle cyclically through the state information.  (Yes, this does mean we
+ * could get away with just one pointer, but the code for random() is more
+ * efficient this way).  The pointers are left positioned as they would be
+ * from the call
+ *
+ *	initstate(1, randtbl, 128);
+ *
+ * (The position of the rear pointer, rptr, is really 0 (as explained above
+ * in the initialization of randtbl) because the state table pointer is set
+ * to point to randtbl[1] (as explained below).
+ */
+static int *fptr = &randtbl[SEP_3 + 1];
+static int *rptr = &randtbl[1];
+
+/*
+ * The following things are the pointer to the state information table, the
+ * type of the current generator, the degree of the current polynomial being
+ * used, and the separation between the two pointers.  Note that for efficiency
+ * of random(), we remember the first location of the state information, not
+ * the zeroeth.  Hence it is valid to access state[-1], which is used to
+ * store the type of the R.N.G.  Also, we remember the last location, since
+ * this is more efficient than indexing every time to find the address of
+ * the last element to see if the front and rear pointers have wrapped.
+ */
+static int *state = &randtbl[1];
+static int rand_type = TYPE_3;
+static int rand_deg = DEG_3;
+static int rand_sep = SEP_3;
+static int *end_ptr = &randtbl[DEG_3 + 1];
+
+/*
+ * srandom:
+ *
+ * Initialize the random number generator based on the given seed.  If the
+ * type is the trivial no-state-information type, just remember the seed.
+ * Otherwise, initializes state[] based on the given "seed" via a linear
+ * congruential generator.  Then, the pointers are set to known locations
+ * that are exactly rand_sep places apart.  Lastly, it cycles the state
+ * information a given number of times to get rid of any initial dependencies
+ * introduced by the L.C.R.N.G.  Note that the initialization of randtbl[]
+ * for default usage relies on values produced by this routine.
+ */
+static void
+srandom_unlocked(unsigned int x)
+{
+	int i;
+
+	if (rand_type == TYPE_0)
+		state[0] = x;
+	else {
+		state[0] = x;
+		for (i = 1; i < rand_deg; i++) {
+#ifdef USE_BETTER_RANDOM
+			int x1, hi, lo, t;
+
+			/*
+			 * Compute x[n + 1] = (7^5 * x[n]) mod (2^31 - 1).
+			 * From "Random number generators: good ones are hard
+			 * to find", Park and Miller, Communications of the ACM,
+			 * vol. 31, no. 10,
+			 * October 1988, p. 1195.
+			 */
+			x1 = state[i - 1];
+			hi = x1 / 127773;
+			lo = x1 % 127773;
+			t = 16807 * lo - 2836 * hi;
+			if (t <= 0)
+				t += 0x7fffffff;
+			state[i] = t;
+#else
+			state[i] = 1103515245 * state[i - 1] + 12345;
+#endif /* USE_BETTER_RANDOM */
+		}
+		fptr = &state[rand_sep];
+		rptr = &state[0];
+		for (i = 0; i < 10 * rand_deg; i++)
+			(void)random_unlocked();
+	}
+}
+
+void
+srandom(unsigned int x)
+{
+
+	mutex_lock(&random_mutex);
+	srandom_unlocked(x);
+	mutex_unlock(&random_mutex);
+}
+
+/*
+ * initstate:
+ *
+ * Initialize the state information in the given array of n bytes for future
+ * random number generation.  Based on the number of bytes we are given, and
+ * the break values for the different R.N.G.'s, we choose the best (largest)
+ * one we can and set things up for it.  srandom() is then called to
+ * initialize the state information.
+ * 
+ * Note that on return from srandom(), we set state[-1] to be the type
+ * multiplexed with the current value of the rear pointer; this is so
+ * successive calls to initstate() won't lose this information and will be
+ * able to restart with setstate().
+ * 
+ * Note: the first thing we do is save the current state, if any, just like
+ * setstate() so that it doesn't matter when initstate is called.
+ *
+ * Returns a pointer to the old state.
+ *
+ * Note: The Sparc platform requires that arg_state begin on an int
+ * word boundary; otherwise a bus error will occur. Even so, lint will
+ * complain about mis-alignment, but you should disregard these messages.
+ */
+char *
+initstate(
+	unsigned int seed,		/* seed for R.N.G. */
+	char *arg_state,		/* pointer to state array */
+	size_t n)			/* # bytes of state info */
+{
+	void *ostate = (void *)(&state[-1]);
+	int *int_arg_state;
+
+	_DIAGASSERT(arg_state != NULL);
+
+	int_arg_state = (int *)(void *)arg_state;
+
+	mutex_lock(&random_mutex);
+	if (rand_type == TYPE_0)
+		state[-1] = rand_type;
+	else
+		state[-1] = MAX_TYPES * (int)(rptr - state) + rand_type;
+	if (n < BREAK_0) {
+		mutex_unlock(&random_mutex);
+		return (NULL);
+	} else if (n < BREAK_1) {
+		rand_type = TYPE_0;
+		rand_deg = DEG_0;
+		rand_sep = SEP_0;
+	} else if (n < BREAK_2) {
+		rand_type = TYPE_1;
+		rand_deg = DEG_1;
+		rand_sep = SEP_1;
+	} else if (n < BREAK_3) {
+		rand_type = TYPE_2;
+		rand_deg = DEG_2;
+		rand_sep = SEP_2;
+	} else if (n < BREAK_4) {
+		rand_type = TYPE_3;
+		rand_deg = DEG_3;
+		rand_sep = SEP_3;
+	} else {
+		rand_type = TYPE_4;
+		rand_deg = DEG_4;
+		rand_sep = SEP_4;
+	}
+	state = (int *) (int_arg_state + 1); /* first location */
+	end_ptr = &state[rand_deg];	/* must set end_ptr before srandom */
+	srandom_unlocked(seed);
+	if (rand_type == TYPE_0)
+		int_arg_state[0] = rand_type;
+	else
+		int_arg_state[0] = MAX_TYPES * (int)(rptr - state) + rand_type;
+	mutex_unlock(&random_mutex);
+	return((char *)ostate);
+}
+
+/*
+ * setstate:
+ *
+ * Restore the state from the given state array.
+ *
+ * Note: it is important that we also remember the locations of the pointers
+ * in the current state information, and restore the locations of the pointers
+ * from the old state information.  This is done by multiplexing the pointer
+ * location into the zeroeth word of the state information.
+ *
+ * Note that due to the order in which things are done, it is OK to call
+ * setstate() with the same state as the current state.
+ *
+ * Returns a pointer to the old state information.
+ *
+ * Note: The Sparc platform requires that arg_state begin on a long
+ * word boundary; otherwise a bus error will occur. Even so, lint will
+ * complain about mis-alignment, but you should disregard these messages.
+ */
+char *
+setstate(char *arg_state)		/* pointer to state array */
+{
+	int *new_state;
+	int type;
+	int rear;
+	void *ostate = (void *)(&state[-1]);
+
+	_DIAGASSERT(arg_state != NULL);
+
+	new_state = (int *)(void *)arg_state;
+	type = (int)(new_state[0] % MAX_TYPES);
+	rear = (int)(new_state[0] / MAX_TYPES);
+
+	mutex_lock(&random_mutex);
+	if (rand_type == TYPE_0)
+		state[-1] = rand_type;
+	else
+		state[-1] = MAX_TYPES * (int)(rptr - state) + rand_type;
+	switch(type) {
+	case TYPE_0:
+	case TYPE_1:
+	case TYPE_2:
+	case TYPE_3:
+	case TYPE_4:
+		rand_type = type;
+		rand_deg = degrees[type];
+		rand_sep = seps[type];
+		break;
+	default:
+		mutex_unlock(&random_mutex);
+		return (NULL);
+	}
+	state = (int *) (new_state + 1);
+	if (rand_type != TYPE_0) {
+		rptr = &state[rear];
+		fptr = &state[(rear + rand_sep) % rand_deg];
+	}
+	end_ptr = &state[rand_deg];		/* set end_ptr too */
+	mutex_unlock(&random_mutex);
+	return((char *)ostate);
+}
+
+/*
+ * random:
+ *
+ * If we are using the trivial TYPE_0 R.N.G., just do the old linear
+ * congruential bit.  Otherwise, we do our fancy trinomial stuff, which is
+ * the same in all the other cases due to all the global variables that have
+ * been set up.  The basic operation is to add the number at the rear pointer
+ * into the one at the front pointer.  Then both pointers are advanced to
+ * the next location cyclically in the table.  The value returned is the sum
+ * generated, reduced to 31 bits by throwing away the "least random" low bit.
+ *
+ * Note: the code takes advantage of the fact that both the front and
+ * rear pointers can't wrap on the same call by not testing the rear
+ * pointer if the front one has wrapped.
+ *
+ * Returns a 31-bit random number.
+ */
+static long
+random_unlocked(void)
+{
+	int i;
+	int *f, *r;
+
+	if (rand_type == TYPE_0) {
+		i = state[0];
+		state[0] = i = (i * 1103515245 + 12345) & 0x7fffffff;
+	} else {
+		/*
+		 * Use local variables rather than static variables for speed.
+		 */
+		f = fptr; r = rptr;
+		*f += *r;
+		/* chucking least random bit */
+		i = ((unsigned int)*f >> 1) & 0x7fffffff;
+		if (++f >= end_ptr) {
+			f = state;
+			++r;
+		}
+		else if (++r >= end_ptr) {
+			r = state;
+		}
+
+		fptr = f; rptr = r;
+	}
+	return(i);
+}
+
+long
+random(void)
+{
+	long r;
+
+	mutex_lock(&random_mutex);
+	r = random_unlocked();
+	mutex_unlock(&random_mutex);
+	return (r);
+}
+#else
+long
+random(void)
+{
+	static u_long randseed = 1;
+	long x, hi, lo, t;
+ 
+	/*
+	 * Compute x[n + 1] = (7^5 * x[n]) mod (2^31 - 1).
+	 * From "Random number generators: good ones are hard to find",
+	 * Park and Miller, Communications of the ACM, vol. 31, no. 10,
+	 * October 1988, p. 1195.
+	 */
+	x = randseed;
+	hi = x / 127773;
+	lo = x % 127773;
+	t = 16807 * lo - 2836 * hi;
+	if (t <= 0)
+		t += 0x7fffffff;
+	randseed = t;
+	return (t);
+}
+#endif /* SMALL_RANDOM */
diff --git a/libc/upstream-netbsd/lib/libc/gen/setjmperr.c b/libc/upstream-netbsd/lib/libc/stdlib/rand.c
similarity index 73%
rename from libc/upstream-netbsd/lib/libc/gen/setjmperr.c
rename to libc/upstream-netbsd/lib/libc/stdlib/rand.c
index 5b1432e..4909d14 100644
--- a/libc/upstream-netbsd/lib/libc/gen/setjmperr.c
+++ b/libc/upstream-netbsd/lib/libc/stdlib/rand.c
@@ -1,7 +1,7 @@
-/*	$NetBSD: setjmperr.c,v 1.8 2012/06/24 15:26:03 christos Exp $	*/
+/*	$NetBSD: rand.c,v 1.12 2012/06/25 22:32:45 abs Exp $	*/
 
-/*
- * Copyright (c) 1980, 1993
+/*-
+ * Copyright (c) 1990, 1993
  *	The Regents of the University of California.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -32,25 +32,26 @@
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
 #if 0
-static char sccsid[] = "@(#)setjmperr.c	8.1 (Berkeley) 6/4/93";
+static char sccsid[] = "@(#)rand.c	8.1 (Berkeley) 6/14/93";
 #else
-__RCSID("$NetBSD: setjmperr.c,v 1.8 2012/06/24 15:26:03 christos Exp $");
+__RCSID("$NetBSD: rand.c,v 1.12 2012/06/25 22:32:45 abs Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
-/*
- * This routine is called from longjmp() when an error occurs.
- * Programs that wish to exit gracefully from this error may
- * write their own versions.
- * If this routine returns, the program is aborted.
- */
+#include <sys/types.h>
+#include <stdlib.h>
 
-#include <setjmp.h>
-#include <unistd.h>
+static u_long next = 1;
+
+int
+rand(void)
+{
+	/* LINTED integer overflow */
+	return (int)((next = next * 1103515245 + 12345) % ((u_long)RAND_MAX + 1));
+}
 
 void
-longjmperror(void)
+srand(u_int seed)
 {
-#define	ERRMSG	"longjmp botch.\n"
-	(void)write(STDERR_FILENO, ERRMSG, sizeof(ERRMSG) - 1);
+	next = seed;
 }
diff --git a/libc/bionic/index.cpp b/libc/upstream-netbsd/lib/libc/stdlib/rand_r.c
similarity index 75%
rename from libc/bionic/index.cpp
rename to libc/upstream-netbsd/lib/libc/stdlib/rand_r.c
index cc22d81..272b2bd 100644
--- a/libc/bionic/index.cpp
+++ b/libc/upstream-netbsd/lib/libc/stdlib/rand_r.c
@@ -1,3 +1,5 @@
+/*	$NetBSD: rand_r.c,v 1.6 2012/06/25 22:32:45 abs Exp $	*/
+
 /*-
  * Copyright (c) 1990 The Regents of the University of California.
  * All rights reserved.
@@ -27,9 +29,23 @@
  * SUCH DAMAGE.
  */
 
-#undef _FORTIFY_SOURCE
-#include <string.h>
+#include <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
+static char *sccsid = "from: @(#)rand.c	5.6 (Berkeley) 6/24/91";
+#else
+__RCSID("$NetBSD: rand_r.c,v 1.6 2012/06/25 22:32:45 abs Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
 
-char* index(const char* p, int ch) {
-  return __strchr_chk(p, ch, __BIONIC_FORTIFY_UNKNOWN_SIZE);
+#include <assert.h>
+#include <errno.h>
+#include <stdlib.h>
+
+int
+rand_r(unsigned int *seed)
+{
+	_DIAGASSERT(seed != NULL);
+
+	return ((*seed = *seed * 1103515245 + 12345) & RAND_MAX);
 }
diff --git a/libc/upstream-openbsd/lib/libc/crypt/chacha_private.h b/libc/upstream-openbsd/lib/libc/crypt/chacha_private.h
new file mode 100644
index 0000000..7c3680f
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/crypt/chacha_private.h
@@ -0,0 +1,222 @@
+/*
+chacha-merged.c version 20080118
+D. J. Bernstein
+Public domain.
+*/
+
+/* $OpenBSD: chacha_private.h,v 1.2 2013/10/04 07:02:27 djm Exp $ */
+
+typedef unsigned char u8;
+typedef unsigned int u32;
+
+typedef struct
+{
+  u32 input[16]; /* could be compressed */
+} chacha_ctx;
+
+#define U8C(v) (v##U)
+#define U32C(v) (v##U)
+
+#define U8V(v) ((u8)(v) & U8C(0xFF))
+#define U32V(v) ((u32)(v) & U32C(0xFFFFFFFF))
+
+#define ROTL32(v, n) \
+  (U32V((v) << (n)) | ((v) >> (32 - (n))))
+
+#define U8TO32_LITTLE(p) \
+  (((u32)((p)[0])      ) | \
+   ((u32)((p)[1]) <<  8) | \
+   ((u32)((p)[2]) << 16) | \
+   ((u32)((p)[3]) << 24))
+
+#define U32TO8_LITTLE(p, v) \
+  do { \
+    (p)[0] = U8V((v)      ); \
+    (p)[1] = U8V((v) >>  8); \
+    (p)[2] = U8V((v) >> 16); \
+    (p)[3] = U8V((v) >> 24); \
+  } while (0)
+
+#define ROTATE(v,c) (ROTL32(v,c))
+#define XOR(v,w) ((v) ^ (w))
+#define PLUS(v,w) (U32V((v) + (w)))
+#define PLUSONE(v) (PLUS((v),1))
+
+#define QUARTERROUND(a,b,c,d) \
+  a = PLUS(a,b); d = ROTATE(XOR(d,a),16); \
+  c = PLUS(c,d); b = ROTATE(XOR(b,c),12); \
+  a = PLUS(a,b); d = ROTATE(XOR(d,a), 8); \
+  c = PLUS(c,d); b = ROTATE(XOR(b,c), 7);
+
+static const char sigma[16] = "expand 32-byte k";
+static const char tau[16] = "expand 16-byte k";
+
+static void
+chacha_keysetup(chacha_ctx *x,const u8 *k,u32 kbits,u32 ivbits)
+{
+  const char *constants;
+
+  x->input[4] = U8TO32_LITTLE(k + 0);
+  x->input[5] = U8TO32_LITTLE(k + 4);
+  x->input[6] = U8TO32_LITTLE(k + 8);
+  x->input[7] = U8TO32_LITTLE(k + 12);
+  if (kbits == 256) { /* recommended */
+    k += 16;
+    constants = sigma;
+  } else { /* kbits == 128 */
+    constants = tau;
+  }
+  x->input[8] = U8TO32_LITTLE(k + 0);
+  x->input[9] = U8TO32_LITTLE(k + 4);
+  x->input[10] = U8TO32_LITTLE(k + 8);
+  x->input[11] = U8TO32_LITTLE(k + 12);
+  x->input[0] = U8TO32_LITTLE(constants + 0);
+  x->input[1] = U8TO32_LITTLE(constants + 4);
+  x->input[2] = U8TO32_LITTLE(constants + 8);
+  x->input[3] = U8TO32_LITTLE(constants + 12);
+}
+
+static void
+chacha_ivsetup(chacha_ctx *x,const u8 *iv)
+{
+  x->input[12] = 0;
+  x->input[13] = 0;
+  x->input[14] = U8TO32_LITTLE(iv + 0);
+  x->input[15] = U8TO32_LITTLE(iv + 4);
+}
+
+static void
+chacha_encrypt_bytes(chacha_ctx *x,const u8 *m,u8 *c,u32 bytes)
+{
+  u32 x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15;
+  u32 j0, j1, j2, j3, j4, j5, j6, j7, j8, j9, j10, j11, j12, j13, j14, j15;
+  u8 *ctarget = NULL;
+  u8 tmp[64];
+  u_int i;
+
+  if (!bytes) return;
+
+  j0 = x->input[0];
+  j1 = x->input[1];
+  j2 = x->input[2];
+  j3 = x->input[3];
+  j4 = x->input[4];
+  j5 = x->input[5];
+  j6 = x->input[6];
+  j7 = x->input[7];
+  j8 = x->input[8];
+  j9 = x->input[9];
+  j10 = x->input[10];
+  j11 = x->input[11];
+  j12 = x->input[12];
+  j13 = x->input[13];
+  j14 = x->input[14];
+  j15 = x->input[15];
+
+  for (;;) {
+    if (bytes < 64) {
+      for (i = 0;i < bytes;++i) tmp[i] = m[i];
+      m = tmp;
+      ctarget = c;
+      c = tmp;
+    }
+    x0 = j0;
+    x1 = j1;
+    x2 = j2;
+    x3 = j3;
+    x4 = j4;
+    x5 = j5;
+    x6 = j6;
+    x7 = j7;
+    x8 = j8;
+    x9 = j9;
+    x10 = j10;
+    x11 = j11;
+    x12 = j12;
+    x13 = j13;
+    x14 = j14;
+    x15 = j15;
+    for (i = 20;i > 0;i -= 2) {
+      QUARTERROUND( x0, x4, x8,x12)
+      QUARTERROUND( x1, x5, x9,x13)
+      QUARTERROUND( x2, x6,x10,x14)
+      QUARTERROUND( x3, x7,x11,x15)
+      QUARTERROUND( x0, x5,x10,x15)
+      QUARTERROUND( x1, x6,x11,x12)
+      QUARTERROUND( x2, x7, x8,x13)
+      QUARTERROUND( x3, x4, x9,x14)
+    }
+    x0 = PLUS(x0,j0);
+    x1 = PLUS(x1,j1);
+    x2 = PLUS(x2,j2);
+    x3 = PLUS(x3,j3);
+    x4 = PLUS(x4,j4);
+    x5 = PLUS(x5,j5);
+    x6 = PLUS(x6,j6);
+    x7 = PLUS(x7,j7);
+    x8 = PLUS(x8,j8);
+    x9 = PLUS(x9,j9);
+    x10 = PLUS(x10,j10);
+    x11 = PLUS(x11,j11);
+    x12 = PLUS(x12,j12);
+    x13 = PLUS(x13,j13);
+    x14 = PLUS(x14,j14);
+    x15 = PLUS(x15,j15);
+
+#ifndef KEYSTREAM_ONLY
+    x0 = XOR(x0,U8TO32_LITTLE(m + 0));
+    x1 = XOR(x1,U8TO32_LITTLE(m + 4));
+    x2 = XOR(x2,U8TO32_LITTLE(m + 8));
+    x3 = XOR(x3,U8TO32_LITTLE(m + 12));
+    x4 = XOR(x4,U8TO32_LITTLE(m + 16));
+    x5 = XOR(x5,U8TO32_LITTLE(m + 20));
+    x6 = XOR(x6,U8TO32_LITTLE(m + 24));
+    x7 = XOR(x7,U8TO32_LITTLE(m + 28));
+    x8 = XOR(x8,U8TO32_LITTLE(m + 32));
+    x9 = XOR(x9,U8TO32_LITTLE(m + 36));
+    x10 = XOR(x10,U8TO32_LITTLE(m + 40));
+    x11 = XOR(x11,U8TO32_LITTLE(m + 44));
+    x12 = XOR(x12,U8TO32_LITTLE(m + 48));
+    x13 = XOR(x13,U8TO32_LITTLE(m + 52));
+    x14 = XOR(x14,U8TO32_LITTLE(m + 56));
+    x15 = XOR(x15,U8TO32_LITTLE(m + 60));
+#endif
+
+    j12 = PLUSONE(j12);
+    if (!j12) {
+      j13 = PLUSONE(j13);
+      /* stopping at 2^70 bytes per nonce is user's responsibility */
+    }
+
+    U32TO8_LITTLE(c + 0,x0);
+    U32TO8_LITTLE(c + 4,x1);
+    U32TO8_LITTLE(c + 8,x2);
+    U32TO8_LITTLE(c + 12,x3);
+    U32TO8_LITTLE(c + 16,x4);
+    U32TO8_LITTLE(c + 20,x5);
+    U32TO8_LITTLE(c + 24,x6);
+    U32TO8_LITTLE(c + 28,x7);
+    U32TO8_LITTLE(c + 32,x8);
+    U32TO8_LITTLE(c + 36,x9);
+    U32TO8_LITTLE(c + 40,x10);
+    U32TO8_LITTLE(c + 44,x11);
+    U32TO8_LITTLE(c + 48,x12);
+    U32TO8_LITTLE(c + 52,x13);
+    U32TO8_LITTLE(c + 56,x14);
+    U32TO8_LITTLE(c + 60,x15);
+
+    if (bytes <= 64) {
+      if (bytes < 64) {
+        for (i = 0;i < bytes;++i) ctarget[i] = c[i];
+      }
+      x->input[12] = j12;
+      x->input[13] = j13;
+      return;
+    }
+    bytes -= 64;
+    c += 64;
+#ifndef KEYSTREAM_ONLY
+    m += 64;
+#endif
+  }
+}
diff --git a/libc/upstream-openbsd/lib/libc/string/wcswcs.c b/libc/upstream-openbsd/lib/libc/string/wcswcs.c
deleted file mode 100644
index bd35605..0000000
--- a/libc/upstream-openbsd/lib/libc/string/wcswcs.c
+++ /dev/null
@@ -1,5 +0,0 @@
-/*	$OpenBSD: wcswcs.c,v 1.1 2005/04/13 16:35:58 espie Exp $	*/
-/* $NetBSD: wcswcs.c,v 1.1 2003/03/05 20:18:17 tshiozak Exp $ */
-
-#define WCSWCS
-#include "wcsstr.c"
diff --git a/libc/zoneinfo/tzdata b/libc/zoneinfo/tzdata
index b3c9444..a5ae1f6 100644
--- a/libc/zoneinfo/tzdata
+++ b/libc/zoneinfo/tzdata
Binary files differ
diff --git a/libm/Android.mk b/libm/Android.mk
index b67395f..90b4906 100644
--- a/libm/Android.mk
+++ b/libm/Android.mk
@@ -1,3 +1,4 @@
+ifneq ($(TARGET_USE_PRIVATE_LIBM),true)
 LOCAL_PATH:= $(call my-dir)
 
 # TODO: this comes from from upstream's libc, not libm, but it's an
@@ -291,3 +292,4 @@
 LOCAL_SYSTEM_SHARED_LIBRARIES := libc
 LOCAL_WHOLE_STATIC_LIBRARIES := libm
 include $(BUILD_SHARED_LIBRARY)
+endif
diff --git a/libm/amd64/fenv.c b/libm/amd64/fenv.c
index b058de2..4b24ff9 100755
--- a/libm/amd64/fenv.c
+++ b/libm/amd64/fenv.c
@@ -30,6 +30,15 @@
 #include <fenv.h>
 #include <machine/fpu.h>
 
+#define SSE_MASK_SHIFT 7
+
+/*
+ * The following symbol is simply the bitwise-inclusive OR of all floating-point
+ * rounding direction constants defined above.
+ */
+#define X87_ROUND_MASK  (FE_TONEAREST | FE_DOWNWARD | FE_UPWARD | FE_TOWARDZERO)
+#define SSE_ROUND_SHIFT 3
+
 /*
  * The following constant represents the default floating-point environment
  * (that is, the one installed at program startup) and has type pointer to
@@ -203,7 +212,7 @@
    */
   __asm__ __volatile__ ("fnstcw %0" : "=m" (control));
 
-  return (control & _X87_ROUND_MASK);
+  return (control & X87_ROUND_MASK);
 }
 
 /*
@@ -218,14 +227,14 @@
   unsigned int mxcsr;
 
   /* Check whether requested rounding direction is supported */
-  if (round & ~_X87_ROUND_MASK)
+  if (round & ~X87_ROUND_MASK)
     return (-1);
 
   /* Store the current x87 control word register */
   __asm__ __volatile__ ("fnstcw %0" : "=m" (control));
 
   /* Set the rounding direction */
-  control &= ~_X87_ROUND_MASK;
+  control &= ~X87_ROUND_MASK;
   control |= round;
 
   /* Load the x87 control word register */
@@ -233,8 +242,8 @@
 
   /* Same for the SSE environment */
   __asm__ __volatile__ ("stmxcsr %0" : "=m" (mxcsr));
-  mxcsr &= ~(_X87_ROUND_MASK << _SSE_ROUND_SHIFT);
-  mxcsr |= round << _SSE_ROUND_SHIFT;
+  mxcsr &= ~(X87_ROUND_MASK << SSE_ROUND_SHIFT);
+  mxcsr |= round << SSE_ROUND_SHIFT;
   __asm__ __volatile__ ("ldmxcsr %0" : : "m" (mxcsr));
 
   return (0);
@@ -291,7 +300,7 @@
   mxcsr &= ~FE_ALL_EXCEPT;
 
   /* Mask all exceptions */
-  mxcsr |= FE_ALL_EXCEPT << _SSE_MASK_SHIFT;
+  mxcsr |= FE_ALL_EXCEPT << SSE_MASK_SHIFT;
 
   /* Store the MXCSR register */
   __asm__ __volatile__ ("ldmxcsr %0" : : "m" (mxcsr));
@@ -362,11 +371,11 @@
   __asm__ __volatile__ ("fnstcw %0" : "=m" (control));
   __asm__ __volatile__ ("stmxcsr %0" : "=m" (mxcsr));
 
-  omask = ~(control | (mxcsr >> _SSE_MASK_SHIFT)) & FE_ALL_EXCEPT;
+  omask = ~(control | (mxcsr >> SSE_MASK_SHIFT)) & FE_ALL_EXCEPT;
   control &= ~mask;
   __asm__ __volatile__ ("fldcw %0" : : "m" (control));
 
-  mxcsr &= ~(mask << _SSE_MASK_SHIFT);
+  mxcsr &= ~(mask << SSE_MASK_SHIFT);
   __asm__ __volatile__ ("ldmxcsr %0" : : "m" (mxcsr));
 
   return (omask);
@@ -383,11 +392,11 @@
   __asm__ __volatile__ ("fnstcw %0" : "=m" (control));
   __asm__ __volatile__ ("stmxcsr %0" : "=m" (mxcsr));
 
-  omask = ~(control | (mxcsr >> _SSE_MASK_SHIFT)) & FE_ALL_EXCEPT;
+  omask = ~(control | (mxcsr >> SSE_MASK_SHIFT)) & FE_ALL_EXCEPT;
   control |= mask;
   __asm__ __volatile__ ("fldcw %0" : : "m" (control));
 
-  mxcsr |= mask << _SSE_MASK_SHIFT;
+  mxcsr |= mask << SSE_MASK_SHIFT;
   __asm__ __volatile__ ("ldmxcsr %0" : : "m" (mxcsr));
 
   return (omask);
diff --git a/libm/arm/fenv.c b/libm/arm/fenv.c
index a0108e8..2124730 100644
--- a/libm/arm/fenv.c
+++ b/libm/arm/fenv.c
@@ -28,10 +28,11 @@
 
 #include <fenv.h>
 
-/*
- * Hopefully the system ID byte is immutable, so it's valid to use
- * this as a default environment.
- */
+#define FPSCR_ENABLE_SHIFT 8
+#define FPSCR_ENABLE_MASK  (FE_ALL_EXCEPT << FPSCR_ENABLE_SHIFT)
+
+#define FPSCR_RMODE_SHIFT 22
+
 const fenv_t __fe_dfl_env = 0;
 
 int fegetenv(fenv_t* __envp) {
@@ -86,14 +87,14 @@
 int fegetround(void) {
   fenv_t _fpscr;
   fegetenv(&_fpscr);
-  return ((_fpscr >> _FPSCR_RMODE_SHIFT) & 0x3);
+  return ((_fpscr >> FPSCR_RMODE_SHIFT) & 0x3);
 }
 
 int fesetround(int __round) {
   fenv_t _fpscr;
   fegetenv(&_fpscr);
-  _fpscr &= ~(0x3 << _FPSCR_RMODE_SHIFT);
-  _fpscr |= (__round << _FPSCR_RMODE_SHIFT);
+  _fpscr &= ~(0x3 << FPSCR_RMODE_SHIFT);
+  _fpscr |= (__round << FPSCR_RMODE_SHIFT);
   fesetenv(&_fpscr);
   return 0;
 }
@@ -102,7 +103,7 @@
   fenv_t __env;
   fegetenv(&__env);
   *__envp = __env;
-  __env &= ~(FE_ALL_EXCEPT | _FPSCR_ENABLE_MASK);
+  __env &= ~(FE_ALL_EXCEPT | FPSCR_ENABLE_MASK);
   fesetenv(&__env);
   return 0;
 }
@@ -118,21 +119,21 @@
 int feenableexcept(int __mask) {
   fenv_t __old_fpscr, __new_fpscr;
   fegetenv(&__old_fpscr);
-  __new_fpscr = __old_fpscr | (__mask & FE_ALL_EXCEPT) << _FPSCR_ENABLE_SHIFT;
+  __new_fpscr = __old_fpscr | (__mask & FE_ALL_EXCEPT) << FPSCR_ENABLE_SHIFT;
   fesetenv(&__new_fpscr);
-  return ((__old_fpscr >> _FPSCR_ENABLE_SHIFT) & FE_ALL_EXCEPT);
+  return ((__old_fpscr >> FPSCR_ENABLE_SHIFT) & FE_ALL_EXCEPT);
 }
 
 int fedisableexcept(int __mask) {
   fenv_t __old_fpscr, __new_fpscr;
   fegetenv(&__old_fpscr);
-  __new_fpscr = __old_fpscr & ~((__mask & FE_ALL_EXCEPT) << _FPSCR_ENABLE_SHIFT);
+  __new_fpscr = __old_fpscr & ~((__mask & FE_ALL_EXCEPT) << FPSCR_ENABLE_SHIFT);
   fesetenv(&__new_fpscr);
-  return ((__old_fpscr >> _FPSCR_ENABLE_SHIFT) & FE_ALL_EXCEPT);
+  return ((__old_fpscr >> FPSCR_ENABLE_SHIFT) & FE_ALL_EXCEPT);
 }
 
 int fegetexcept(void) {
   fenv_t __fpscr;
   fegetenv(&__fpscr);
-  return ((__fpscr & _FPSCR_ENABLE_MASK) >> _FPSCR_ENABLE_SHIFT);
+  return ((__fpscr & FPSCR_ENABLE_MASK) >> FPSCR_ENABLE_SHIFT);
 }
diff --git a/libm/arm64/fenv.c b/libm/arm64/fenv.c
index 9db21ef..ce560a7 100644
--- a/libm/arm64/fenv.c
+++ b/libm/arm64/fenv.c
@@ -28,114 +28,168 @@
 
 #include <fenv.h>
 
-/*
- * Hopefully the system ID byte is immutable, so it's valid to use
- * this as a default environment.
- */
-const fenv_t __fe_dfl_env = 0;
+#define FPCR_EXCEPT_SHIFT 8
+#define FPCR_EXCEPT_MASK  (FE_ALL_EXCEPT << FPCR_EXCEPT_SHIFT)
 
-int fegetenv(fenv_t* __envp) {
-  fenv_t _fpcr, _fpsr;
-  __asm__ __volatile__("mrs %0,fpcr" : "=r" (_fpcr));
-  __asm__ __volatile__("mrs %0,fpsr" : "=r" (_fpsr));
-  *__envp = (_fpcr | _fpsr);
+#define FPCR_RMODE_SHIFT 22
+
+const fenv_t __fe_dfl_env = { 0 /* control */, 0 /* status */};
+
+typedef __uint32_t fpu_control_t;   // FPCR, Floating-point Control Register.
+typedef __uint32_t fpu_status_t;    // FPSR, Floating-point Status Register.
+
+#define __get_fpcr(__fpcr) __asm__ __volatile__("mrs %0,fpcr" : "=r" (__fpcr))
+#define __get_fpsr(__fpsr) __asm__ __volatile__("mrs %0,fpsr" : "=r" (__fpsr))
+#define __set_fpcr(__fpcr) __asm__ __volatile__("msr fpcr,%0" : :"ri" (__fpcr))
+#define __set_fpsr(__fpsr) __asm__ __volatile__("msr fpsr,%0" : :"ri" (__fpsr))
+
+int fegetenv(fenv_t* envp) {
+  __get_fpcr(envp->__control);
+  __get_fpsr(envp->__status);
   return 0;
 }
 
-int fesetenv(const fenv_t* __envp) {
-  fenv_t _fpcr = (*__envp & FPCR_MASK);
-  fenv_t _fpsr = (*__envp & FPSR_MASK);
-  __asm__ __volatile__("msr fpcr,%0" : :"ri" (_fpcr));
-  __asm__ __volatile__("msr fpsr,%0" : :"ri" (_fpsr));
+int fesetenv(const fenv_t* envp) {
+  fpu_control_t fpcr;
+
+  __get_fpcr(fpcr);
+  if (envp->__control != fpcr) {
+    __set_fpcr(envp->__control);
+  }
+  __set_fpsr(envp->__status);
   return 0;
 }
 
-int feclearexcept(int __excepts) {
-  fexcept_t __fpscr;
-  fegetenv(&__fpscr);
-  __fpscr &= ~__excepts;
-  fesetenv(&__fpscr);
+int feclearexcept(int excepts) {
+  fpu_status_t fpsr;
+
+  excepts &= FE_ALL_EXCEPT;
+  __get_fpsr(fpsr);
+  fpsr &= ~excepts;
+  __set_fpsr(fpsr);
   return 0;
 }
 
-int fegetexceptflag(fexcept_t* __flagp, int __excepts) {
-  fexcept_t __fpscr;
-  fegetenv(&__fpscr);
-  *__flagp = __fpscr & __excepts;
+int fegetexceptflag(fexcept_t* flagp, int excepts) {
+  fpu_status_t fpsr;
+
+  excepts &= FE_ALL_EXCEPT;
+  __get_fpsr(fpsr);
+  *flagp = fpsr & excepts;
   return 0;
 }
 
-int fesetexceptflag(const fexcept_t* __flagp, int __excepts) {
-  fexcept_t __fpscr;
-  fegetenv(&__fpscr);
-  __fpscr &= ~__excepts;
-  __fpscr |= *__flagp & __excepts;
-  fesetenv(&__fpscr);
+int fesetexceptflag(const fexcept_t* flagp, int excepts) {
+  fpu_status_t fpsr;
+
+  excepts &= FE_ALL_EXCEPT;
+  __get_fpsr(fpsr);
+  fpsr &= ~excepts;
+  fpsr |= *flagp & excepts;
+  __set_fpsr(fpsr);
   return 0;
 }
 
-int feraiseexcept(int __excepts) {
-  fexcept_t __ex = __excepts;
-  fesetexceptflag(&__ex, __excepts);
+int feraiseexcept(int excepts) {
+  fexcept_t ex = excepts;
+
+  fesetexceptflag(&ex, excepts);
   return 0;
 }
 
-int fetestexcept(int __excepts) {
-  fexcept_t __fpscr;
-  fegetenv(&__fpscr);
-  return (__fpscr & __excepts);
+int fetestexcept(int excepts) {
+  fpu_status_t fpsr;
+
+  excepts &= FE_ALL_EXCEPT;
+  __get_fpsr(fpsr);
+  return (fpsr & excepts);
 }
 
 int fegetround(void) {
-  fenv_t _fpscr;
-  fegetenv(&_fpscr);
-  return ((_fpscr >> _FPSCR_RMODE_SHIFT) & 0x3);
+  fpu_control_t fpcr;
+
+  __get_fpcr(fpcr);
+  return ((fpcr >> FPCR_RMODE_SHIFT) & FE_TOWARDZERO);
 }
 
-int fesetround(int __round) {
-  fenv_t _fpscr;
-  fegetenv(&_fpscr);
-  _fpscr &= ~(0x3 << _FPSCR_RMODE_SHIFT);
-  _fpscr |= (__round << _FPSCR_RMODE_SHIFT);
-  fesetenv(&_fpscr);
+int fesetround(int round) {
+  fpu_control_t fpcr, new_fpcr;
+
+  round &= FE_TOWARDZERO;
+  __get_fpcr(fpcr);
+  new_fpcr = fpcr & ~(FE_TOWARDZERO << FPCR_RMODE_SHIFT);
+  new_fpcr |= (round << FPCR_RMODE_SHIFT);
+  if (new_fpcr != fpcr) {
+    __set_fpcr(new_fpcr);
+  }
   return 0;
 }
 
-int feholdexcept(fenv_t* __envp) {
-  fenv_t __env;
-  fegetenv(&__env);
-  *__envp = __env;
-  __env &= ~(FE_ALL_EXCEPT | _FPSCR_ENABLE_MASK);
-  fesetenv(&__env);
+int feholdexcept(fenv_t* envp) {
+  fenv_t env;
+  fpu_status_t fpsr;
+  fpu_control_t fpcr, new_fpcr;
+
+  __get_fpsr(fpsr);
+  __get_fpcr(fpcr);
+  env.__status = fpsr;
+  env.__control = fpcr;
+  *envp = env;
+
+  // Set exceptions to untrapped.
+  new_fpcr = fpcr & ~(FE_ALL_EXCEPT << FPCR_EXCEPT_SHIFT);
+  if (new_fpcr != fpcr) {
+    __set_fpcr(new_fpcr);
+  }
+
+  // Clear all exceptions.
+  fpsr &= ~FE_ALL_EXCEPT;
+  __set_fpsr(fpsr);
   return 0;
 }
 
-int feupdateenv(const fenv_t* __envp) {
-  fexcept_t __fpscr;
-  fegetenv(&__fpscr);
-  fesetenv(__envp);
-  feraiseexcept(__fpscr & FE_ALL_EXCEPT);
+int feupdateenv(const fenv_t* envp) {
+  fpu_status_t fpsr;
+  fpu_control_t fpcr;
+
+  // Set FPU Control register.
+  __get_fpcr(fpcr);
+  if (envp->__control != fpcr) {
+    __set_fpcr(envp->__control);
+  }
+
+  // Set FPU Status register to status | currently raised exceptions.
+  __get_fpsr(fpsr);
+  fpsr = envp->__status | (fpsr & FE_ALL_EXCEPT);
+  __set_fpsr(fpsr);
   return 0;
 }
 
-int feenableexcept(int __mask) {
-  fenv_t __old_fpscr, __new_fpscr;
-  fegetenv(&__old_fpscr);
-  __new_fpscr = __old_fpscr | (__mask & FE_ALL_EXCEPT) << _FPSCR_ENABLE_SHIFT;
-  fesetenv(&__new_fpscr);
-  return ((__old_fpscr >> _FPSCR_ENABLE_SHIFT) & FE_ALL_EXCEPT);
+int feenableexcept(int mask) {
+  fpu_control_t old_fpcr, new_fpcr;
+
+  __get_fpcr(old_fpcr);
+  new_fpcr = old_fpcr | ((mask & FE_ALL_EXCEPT) << FPCR_EXCEPT_SHIFT);
+  if (new_fpcr != old_fpcr) {
+    __set_fpcr(new_fpcr);
+  }
+  return ((old_fpcr >> FPCR_EXCEPT_SHIFT) & FE_ALL_EXCEPT);
 }
 
-int fedisableexcept(int __mask) {
-  fenv_t __old_fpscr, __new_fpscr;
-  fegetenv(&__old_fpscr);
-  __new_fpscr = __old_fpscr & ~((__mask & FE_ALL_EXCEPT) << _FPSCR_ENABLE_SHIFT);
-  fesetenv(&__new_fpscr);
-  return ((__old_fpscr >> _FPSCR_ENABLE_SHIFT) & FE_ALL_EXCEPT);
+int fedisableexcept(int mask) {
+  fpu_control_t old_fpcr, new_fpcr;
+
+  __get_fpcr(old_fpcr);
+  new_fpcr = old_fpcr & ~((mask & FE_ALL_EXCEPT) << FPCR_EXCEPT_SHIFT);
+  if (new_fpcr != old_fpcr) {
+    __set_fpcr(new_fpcr);
+  }
+  return ((old_fpcr >> FPCR_EXCEPT_SHIFT) & FE_ALL_EXCEPT);
 }
 
 int fegetexcept(void) {
-  fenv_t __fpscr;
-  fegetenv(&__fpscr);
-  return ((__fpscr & _FPSCR_ENABLE_MASK) >> _FPSCR_ENABLE_SHIFT);
+  fpu_control_t fpcr;
+
+  __get_fpcr(fpcr);
+  return ((fpcr & FPCR_EXCEPT_MASK) >> FPCR_EXCEPT_SHIFT);
 }
diff --git a/libm/i387/fenv.c b/libm/i387/fenv.c
index 3ab9c58..f64f8dc 100644
--- a/libm/i387/fenv.c
+++ b/libm/i387/fenv.c
@@ -31,6 +31,8 @@
 #include "npx.h"
 #include "fenv.h"
 
+#define ROUND_MASK   (FE_TONEAREST | FE_DOWNWARD | FE_UPWARD | FE_TOWARDZERO)
+
 /*
  * As compared to the x87 control word, the SSE unit's control word
  * has the rounding control bits offset by 3 and the exception mask
@@ -327,7 +329,7 @@
    * unit on an Opteron 244.
    */
   __fnstcw(&control);
-  return (control & _ROUND_MASK);
+  return (control & ROUND_MASK);
 }
 
 int
@@ -336,16 +338,16 @@
   __uint32_t mxcsr;
   __uint16_t control;
 
-  if (round & ~_ROUND_MASK) {
+  if (round & ~ROUND_MASK) {
     return (-1);
   } else {
     __fnstcw(&control);
-    control &= ~_ROUND_MASK;
+    control &= ~ROUND_MASK;
     control |= round;
     __fldcw(control);
     if (__HAS_SSE()) {
       __stmxcsr(&mxcsr);
-      mxcsr &= ~(_ROUND_MASK << _SSE_ROUND_SHIFT);
+      mxcsr &= ~(ROUND_MASK << _SSE_ROUND_SHIFT);
       mxcsr |= round << _SSE_ROUND_SHIFT;
       __ldmxcsr(mxcsr);
     }
diff --git a/libm/include/amd64/machine/fenv.h b/libm/include/amd64/machine/fenv.h
index 79a4120..c2b25ed 100644
--- a/libm/include/amd64/machine/fenv.h
+++ b/libm/include/amd64/machine/fenv.h
@@ -51,7 +51,6 @@
  */
 #define FE_ALL_EXCEPT   (FE_INVALID | FE_DENORMAL | FE_DIVBYZERO | \
                          FE_OVERFLOW | FE_UNDERFLOW | FE_INEXACT)
-#define _SSE_MASK_SHIFT 7
 
 /*
  * Each symbol representing the rounding direction, expands to an integer
@@ -65,14 +64,6 @@
 #define FE_TOWARDZERO 0xc00
 
 /*
- * The following symbol is simply the bitwise-inclusive OR of all floating-point
- * rounding direction constants defined above.
- */
-#define _X87_ROUND_MASK  (FE_TONEAREST | FE_DOWNWARD | FE_UPWARD | \
-                          FE_TOWARDZERO)
-#define _SSE_ROUND_SHIFT 3
-
-/*
  * fenv_t represents the entire floating-point environment.
  */
 typedef struct {
diff --git a/libm/include/arm/machine/fenv.h b/libm/include/arm/machine/fenv.h
index d8749dd..0e483e3 100644
--- a/libm/include/arm/machine/fenv.h
+++ b/libm/include/arm/machine/fenv.h
@@ -52,17 +52,12 @@
 #define FE_ALL_EXCEPT (FE_DIVBYZERO | FE_INEXACT | FE_INVALID | \
                        FE_OVERFLOW | FE_UNDERFLOW)
 
-#define _FPSCR_ENABLE_SHIFT 8
-#define _FPSCR_ENABLE_MASK  (FE_ALL_EXCEPT << _FPSCR_ENABLE_SHIFT)
-
 /* Rounding modes. */
 #define FE_TONEAREST  0x0
 #define FE_UPWARD     0x1
 #define FE_DOWNWARD   0x2
 #define FE_TOWARDZERO 0x3
 
-#define _FPSCR_RMODE_SHIFT 22
-
 __END_DECLS
 
 #endif /* !_ARM_FENV_H_ */
diff --git a/libm/include/arm64/machine/fenv.h b/libm/include/arm64/machine/fenv.h
index 2efeee3..a8568b8 100644
--- a/libm/include/arm64/machine/fenv.h
+++ b/libm/include/arm64/machine/fenv.h
@@ -27,15 +27,44 @@
  */
 
 /*
- * Rewritten for Android.
+ * In ARMv8, AArch64 state, floating-point operation is controlled by:
  *
- * The ARM FPSCR (Floating-point Status and Control Register) described here:
- * http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0344b/Chdfafia.html
- * has been split into the FPCR (Floating-point Control Register) and FPSR
- * (Floating-point Status Register) on the ARMv8. These are described briefly in
- * "Procedure Call Standard for the ARM 64-bit Architecture"
- * http://infocenter.arm.com/help/topic/com.arm.doc.ihi0055a/IHI0055A_aapcs64.pdf
- * section 5.1.2 SIMD and Floating-Point Registers
+ *  * FPCR - 32Bit Floating-Point Control Register:
+ *      * [31:27] - Reserved, Res0;
+ *      * [26]    - AHP, Alternative half-precision control bit;
+ *      * [25]    - DN, Default NaN mode control bit;
+ *      * [24]    - FZ, Flush-to-zero mode control bit;
+ *      * [23:22] - RMode, Rounding Mode control field:
+ *            * 00  - Round to Nearest (RN) mode;
+ *            * 01  - Round towards Plus Infinity (RP) mode;
+ *            * 10  - Round towards Minus Infinity (RM) mode;
+ *            * 11  - Round towards Zero (RZ) mode.
+ *      * [21:20] - Stride, ignored during AArch64 execution;
+ *      * [19]    - Reserved, Res0;
+ *      * [18:16] - Len, ignored during AArch64 execution;
+ *      * [15]    - IDE, Input Denormal exception trap;
+ *      * [14:13] - Reserved, Res0;
+ *      * [12]    - IXE, Inexact exception trap;
+ *      * [11]    - UFE, Underflow exception trap;
+ *      * [10]    - OFE, Overflow exception trap;
+ *      * [9]     - DZE, Division by Zero exception;
+ *      * [8]     - IOE, Invalid Operation exception;
+ *      * [7:0]   - Reserved, Res0.
+ *
+ *  * FPSR - 32Bit Floating-Point Status Register:
+ *      * [31]    - N, Negative condition flag for AArch32 (AArch64 sets PSTATE.N);
+ *      * [30]    - Z, Zero condition flag for AArch32 (AArch64 sets PSTATE.Z);
+ *      * [29]    - C, Carry conditon flag for AArch32 (AArch64 sets PSTATE.C);
+ *      * [28]    - V, Overflow conditon flag for AArch32 (AArch64 sets PSTATE.V);
+ *      * [27]    - QC, Cumulative saturation bit, Advanced SIMD only;
+ *      * [26:8]  - Reserved, Res0;
+ *      * [7]     - IDC, Input Denormal cumulative exception;
+ *      * [6:5]   - Reserved, Res0;
+ *      * [4]     - IXC, Inexact cumulative exception;
+ *      * [3]     - UFC, Underflow cumulative exception;
+ *      * [2]     - OFC, Overflow cumulative exception;
+ *      * [1]     - DZC, Division by Zero cumulative exception;
+ *      * [0]     - IOC, Invalid Operation cumulative exception.
  */
 
 #ifndef _ARM64_FENV_H_
@@ -45,7 +74,11 @@
 
 __BEGIN_DECLS
 
-typedef __uint32_t fenv_t;
+typedef struct {
+  __uint32_t __control;     /* FPCR, Floating-point Control Register */
+  __uint32_t __status;      /* FPSR, Floating-point Status Register */
+} fenv_t;
+
 typedef __uint32_t fexcept_t;
 
 /* Exception flags. */
@@ -54,11 +87,9 @@
 #define FE_OVERFLOW   0x04
 #define FE_UNDERFLOW  0x08
 #define FE_INEXACT    0x10
+#define FE_DENORMAL   0x80
 #define FE_ALL_EXCEPT (FE_DIVBYZERO | FE_INEXACT | FE_INVALID | \
-                       FE_OVERFLOW | FE_UNDERFLOW)
-
-#define _FPSCR_ENABLE_SHIFT 8
-#define _FPSCR_ENABLE_MASK  (FE_ALL_EXCEPT << _FPSCR_ENABLE_SHIFT)
+                       FE_OVERFLOW | FE_UNDERFLOW | FE_DENORMAL)
 
 /* Rounding modes. */
 #define FE_TONEAREST  0x0
@@ -66,56 +97,6 @@
 #define FE_DOWNWARD   0x2
 #define FE_TOWARDZERO 0x3
 
-#define _FPSCR_RMODE_SHIFT 22
-
-#define FPCR_IOE    (1 << 8)
-#define FPCR_DZE    (1 << 9)
-#define FPCR_OFE    (1 << 10)
-#define FPCR_UFE    (1 << 11)
-#define FPCR_IXE    (1 << 12)
-#define FPCR_IDE    (1 << 15)
-#define FPCR_LEN    (7 << 16)
-#define FPCR_STRIDE (3 << 20)
-#define FPCR_RMODE  (3 << 22)
-#define FPCR_FZ     (1 << 24)
-#define FPCR_DN     (1 << 25)
-#define FPCR_AHP    (1 << 26)
-#define FPCR_MASK   (FPCR_IOE | \
-                     FPCR_DZE | \
-                     FPCR_OFE | \
-                     FPCR_UFE | \
-                     FPCR_IXE | \
-                     FPCR_IDE | \
-                     FPCR_LEN | \
-                     FPCR_STRIDE | \
-                     FPCR_RMODE | \
-                     FPCR_FZ | \
-                     FPCR_DN | \
-                     FPCR_AHP )
-
-#define FPSR_IOC    (1 << 0)
-#define FPSR_DZC    (1 << 1)
-#define FPSR_OFC    (1 << 2)
-#define FPSR_UFC    (1 << 3)
-#define FPSR_IXC    (1 << 4)
-#define FPSR_IDC    (1 << 7)
-#define FPSR_QC     (1 << 27)
-#define FPSR_V      (1 << 28)
-#define FPSR_C      (1 << 29)
-#define FPSR_Z      (1 << 30)
-#define FPSR_N      (1 << 31)
-#define FPSR_MASK   (FPSR_IOC | \
-                     FPSR_DZC | \
-                     FPSR_OFC | \
-                     FPSR_UFC | \
-                     FPSR_IXC | \
-                     FPSR_IDC | \
-                     FPSR_QC | \
-                     FPSR_V | \
-                     FPSR_C | \
-                     FPSR_Z | \
-                     FPSR_N )
-
 __END_DECLS
 
 #endif /* !_ARM64_FENV_H_ */
diff --git a/libm/include/i387/machine/fenv.h b/libm/include/i387/machine/fenv.h
index f3fabb6..de45add 100644
--- a/libm/include/i387/machine/fenv.h
+++ b/libm/include/i387/machine/fenv.h
@@ -63,8 +63,6 @@
 #define FE_DOWNWARD   0x0400
 #define FE_UPWARD     0x0800
 #define FE_TOWARDZERO 0x0c00
-#define _ROUND_MASK   (FE_TONEAREST | FE_DOWNWARD | \
-                       FE_UPWARD | FE_TOWARDZERO)
 
 __END_DECLS
 
diff --git a/libm/include/mips/machine/fenv.h b/libm/include/mips/machine/fenv.h
index 37f0f9c..689e1cb 100644
--- a/libm/include/mips/machine/fenv.h
+++ b/libm/include/mips/machine/fenv.h
@@ -87,19 +87,12 @@
 #define FE_ALL_EXCEPT (FE_DIVBYZERO | FE_INEXACT | \
                        FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW)
 
-#define _FCSR_CAUSE_SHIFT 10
-#define _ENABLE_SHIFT     5
-#define _FCSR_ENABLE_MASK (FE_ALL_EXCEPT << _ENABLE_SHIFT)
-
 /* Rounding modes */
 #define FE_TONEAREST  0x0000
 #define FE_TOWARDZERO 0x0001
 #define FE_UPWARD     0x0002
 #define FE_DOWNWARD   0x0003
 
-#define _FCSR_RMODE_SHIFT 0
-#define _FCSR_RMASK       0x3
-
 __END_DECLS
 
 #endif /* !_MIPS_FENV_H_ */
diff --git a/libm/mips/fenv.c b/libm/mips/fenv.c
index 893bc30..aacd526 100644
--- a/libm/mips/fenv.c
+++ b/libm/mips/fenv.c
@@ -28,6 +28,12 @@
 
 #include <fenv.h>
 
+#define FCSR_CAUSE_SHIFT 10
+#define FCSR_ENABLE_SHIFT 5
+#define FCSR_ENABLE_MASK (FE_ALL_EXCEPT << FCSR_ENABLE_SHIFT)
+
+#define FCSR_RMASK       0x3
+
 /*
  * Hopefully the system ID byte is immutable, so it's valid to use
  * this as a default environment.
@@ -55,7 +61,7 @@
   fexcept_t __fcsr;
   fegetenv(&__fcsr);
   __excepts &= FE_ALL_EXCEPT;
-  __fcsr &= ~(__excepts | (__excepts << _FCSR_CAUSE_SHIFT));
+  __fcsr &= ~(__excepts | (__excepts << FCSR_CAUSE_SHIFT));
   fesetenv(&__fcsr);
   return 0;
 }
@@ -84,7 +90,7 @@
   /* Ensure that flags are all legal */
   __excepts &= FE_ALL_EXCEPT;
   /* Cause bit needs to be set as well for generating the exception*/
-  __fcsr |= __excepts | (__excepts << _FCSR_CAUSE_SHIFT);
+  __fcsr |= __excepts | (__excepts << FCSR_CAUSE_SHIFT);
   fesetenv(&__fcsr);
   return 0;
 }
@@ -98,14 +104,14 @@
 int fegetround(void) {
   fenv_t _fcsr;
   fegetenv(&_fcsr);
-  return (_fcsr & _FCSR_RMASK);
+  return (_fcsr & FCSR_RMASK);
 }
 
 int fesetround(int __round) {
   fenv_t _fcsr;
   fegetenv(&_fcsr);
-  _fcsr &= ~_FCSR_RMASK;
-  _fcsr |= (__round & _FCSR_RMASK ) ;
+  _fcsr &= ~FCSR_RMASK;
+  _fcsr |= (__round & FCSR_RMASK);
   fesetenv(&_fcsr);
   return 0;
 }
@@ -114,7 +120,7 @@
   fenv_t __env;
   fegetenv(&__env);
   *__envp = __env;
-  __env &= ~(FE_ALL_EXCEPT | _FCSR_ENABLE_MASK);
+  __env &= ~(FE_ALL_EXCEPT | FCSR_ENABLE_MASK);
   fesetenv(&__env);
   return 0;
 }
@@ -130,21 +136,21 @@
 int feenableexcept(int __mask) {
   fenv_t __old_fcsr, __new_fcsr;
   fegetenv(&__old_fcsr);
-  __new_fcsr = __old_fcsr | (__mask & FE_ALL_EXCEPT) << _ENABLE_SHIFT;
+  __new_fcsr = __old_fcsr | (__mask & FE_ALL_EXCEPT) << FCSR_ENABLE_SHIFT;
   fesetenv(&__new_fcsr);
-  return ((__old_fcsr >> _ENABLE_SHIFT) & FE_ALL_EXCEPT);
+  return ((__old_fcsr >> FCSR_ENABLE_SHIFT) & FE_ALL_EXCEPT);
 }
 
 int fedisableexcept(int __mask) {
   fenv_t __old_fcsr, __new_fcsr;
   fegetenv(&__old_fcsr);
-  __new_fcsr = __old_fcsr & ~((__mask & FE_ALL_EXCEPT) << _ENABLE_SHIFT);
+  __new_fcsr = __old_fcsr & ~((__mask & FE_ALL_EXCEPT) << FCSR_ENABLE_SHIFT);
   fesetenv(&__new_fcsr);
-  return ((__old_fcsr >> _ENABLE_SHIFT) & FE_ALL_EXCEPT);
+  return ((__old_fcsr >> FCSR_ENABLE_SHIFT) & FE_ALL_EXCEPT);
 }
 
 int fegetexcept(void) {
   fenv_t __fcsr;
   fegetenv(&__fcsr);
-  return ((__fcsr & _FCSR_ENABLE_MASK) >> _ENABLE_SHIFT);
+  return ((__fcsr & FCSR_ENABLE_MASK) >> FCSR_ENABLE_SHIFT);
 }
diff --git a/libstdc++/include/cstdio b/libstdc++/include/cstdio
index 3c8b5c6..2948d85 100644
--- a/libstdc++/include/cstdio
+++ b/libstdc++/include/cstdio
@@ -63,7 +63,9 @@
 using ::fwrite;
 using ::getc;
 using ::getchar;
+#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L
 using ::gets;
+#endif
 using ::perror;
 using ::printf;
 using ::putc;
diff --git a/linker/Android.mk b/linker/Android.mk
index 811cf6e..68e801d 100644
--- a/linker/Android.mk
+++ b/linker/Android.mk
@@ -16,6 +16,7 @@
 LOCAL_SRC_FILES_x86     := arch/x86/begin.c
 LOCAL_SRC_FILES_x86_64  := arch/x86_64/begin.S
 LOCAL_SRC_FILES_mips    := arch/mips/begin.S
+LOCAL_SRC_FILES_mips64  := arch/mips64/begin.S
 
 LOCAL_LDFLAGS := \
     -shared \
diff --git a/linker/dlfcn.cpp b/linker/dlfcn.cpp
index f0b6c8a..529e20f 100644
--- a/linker/dlfcn.cpp
+++ b/linker/dlfcn.cpp
@@ -118,7 +118,7 @@
   if (sym != NULL) {
     unsigned bind = ELF_ST_BIND(sym->st_info);
 
-    if (bind == STB_GLOBAL && sym->st_shndx != 0) {
+    if ((bind == STB_GLOBAL || bind == STB_WEAK) && sym->st_shndx != 0) {
       return reinterpret_cast<void*>(sym->st_value + found->load_bias);
     }
 
diff --git a/linker/linker.cpp b/linker/linker.cpp
index a22233d..e202aaf 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -59,6 +59,7 @@
  *
  * open issues / todo:
  *
+ * - are we doing everything we should for ARM_COPY relocations?
  * - cleaner error reporting
  * - after linking, set as much stuff as possible to READONLY
  *   and NOEXEC
@@ -1037,17 +1038,52 @@
         break;
 
     case R_AARCH64_COPY:
-        /*
-         * ET_EXEC is not supported so this should not happen.
-         *
-         * http://infocenter.arm.com/help/topic/com.arm.doc.ihi0044d/IHI0044D_aaelf.pdf
-         *
-         * Section 4.7.1.10 "Dynamic relocations"
-         * R_AARCH64_COPY may only appear in executable objects where e_type is
-         * set to ET_EXEC.
-         */
-        DL_ERR("%s R_AARCH64_COPY relocations are not supported", si->name);
-        return -1;
+        if ((si->flags & FLAG_EXE) == 0) {
+            /*
+              * http://infocenter.arm.com/help/topic/com.arm.doc.ihi0044d/IHI0044D_aaelf.pdf
+              *
+              * Section 4.7.1.10 "Dynamic relocations"
+              * R_AARCH64_COPY may only appear in executable objects where e_type is
+              * set to ET_EXEC.
+              *
+              * FLAG_EXE is set for both ET_DYN and ET_EXEC executables.
+              * We should explicitly disallow ET_DYN executables from having
+              * R_AARCH64_COPY relocations.
+              */
+            DL_ERR("%s R_AARCH64_COPY relocations only supported for ET_EXEC", si->name);
+            return -1;
+        }
+        count_relocation(kRelocCopy);
+        MARK(rela->r_offset);
+        TRACE_TYPE(RELO, "RELO COPY %16llx <- %lld @ %16llx %s\n",
+                   reloc,
+                   s->st_size,
+                   (sym_addr + rela->r_addend),
+                   sym_name);
+        if (reloc == (sym_addr + rela->r_addend)) {
+            ElfW(Sym)* src = soinfo_do_lookup(NULL, sym_name, &lsi, needed);
+
+            if (src == NULL) {
+                DL_ERR("%s R_AARCH64_COPY relocation source cannot be resolved", si->name);
+                return -1;
+            }
+            if (lsi->has_DT_SYMBOLIC) {
+                DL_ERR("%s invalid R_AARCH64_COPY relocation against DT_SYMBOLIC shared "
+                       "library %s (built with -Bsymbolic?)", si->name, lsi->name);
+                return -1;
+            }
+            if (s->st_size < src->st_size) {
+                DL_ERR("%s R_AARCH64_COPY relocation size mismatch (%lld < %lld)",
+                       si->name, s->st_size, src->st_size);
+                return -1;
+            }
+            memcpy(reinterpret_cast<void*>(reloc),
+                   reinterpret_cast<void*>(src->st_value + lsi->load_bias), src->st_size);
+        } else {
+            DL_ERR("%s R_AARCH64_COPY relocation target cannot be resolved", si->name);
+            return -1;
+        }
+        break;
     case R_AARCH64_TLS_TPREL64:
         TRACE_TYPE(RELO, "RELO TLS_TPREL64 *** %16llx <- %16llx - %16llx\n",
                    reloc, (sym_addr + rela->r_addend), rela->r_offset);
@@ -1225,17 +1261,48 @@
             *reinterpret_cast<ElfW(Addr)*>(reloc) += sym_addr - rel->r_offset;
             break;
         case R_ARM_COPY:
-            /*
-             * ET_EXEC is not supported so this should not happen.
-             *
-             * http://infocenter.arm.com/help/topic/com.arm.doc.ihi0044d/IHI0044D_aaelf.pdf
-             *
-             * Section 4.7.1.10 "Dynamic relocations"
-             * R_ARM_COPY may only appear in executable objects where e_type is
-             * set to ET_EXEC.
-             */
-            DL_ERR("%s R_ARM_COPY relocations are not supported", si->name);
-            return -1;
+            if ((si->flags & FLAG_EXE) == 0) {
+                /*
+                 * http://infocenter.arm.com/help/topic/com.arm.doc.ihi0044d/IHI0044D_aaelf.pdf
+                 *
+                 * Section 4.7.1.10 "Dynamic relocations"
+                 * R_ARM_COPY may only appear in executable objects where e_type is
+                 * set to ET_EXEC.
+                 *
+                 * TODO: FLAG_EXE is set for both ET_DYN and ET_EXEC executables.
+                 * We should explicitly disallow ET_DYN executables from having
+                 * R_ARM_COPY relocations.
+                 */
+                DL_ERR("%s R_ARM_COPY relocations only supported for ET_EXEC", si->name);
+                return -1;
+            }
+            count_relocation(kRelocCopy);
+            MARK(rel->r_offset);
+            TRACE_TYPE(RELO, "RELO %08x <- %d @ %08x %s", reloc, s->st_size, sym_addr, sym_name);
+            if (reloc == sym_addr) {
+                ElfW(Sym)* src = soinfo_do_lookup(NULL, sym_name, &lsi, needed);
+
+                if (src == NULL) {
+                    DL_ERR("%s R_ARM_COPY relocation source cannot be resolved", si->name);
+                    return -1;
+                }
+                if (lsi->has_DT_SYMBOLIC) {
+                    DL_ERR("%s invalid R_ARM_COPY relocation against DT_SYMBOLIC shared "
+                           "library %s (built with -Bsymbolic?)", si->name, lsi->name);
+                    return -1;
+                }
+                if (s->st_size < src->st_size) {
+                    DL_ERR("%s R_ARM_COPY relocation size mismatch (%d < %d)",
+                           si->name, s->st_size, src->st_size);
+                    return -1;
+                }
+                memcpy(reinterpret_cast<void*>(reloc),
+                       reinterpret_cast<void*>(src->st_value + lsi->load_bias), src->st_size);
+            } else {
+                DL_ERR("%s R_ARM_COPY relocation target cannot be resolved", si->name);
+                return -1;
+            }
+            break;
 #elif defined(__i386__)
         case R_386_JMP_SLOT:
             count_relocation(kRelocAbsolute);
@@ -2105,11 +2172,13 @@
     si->dynamic = NULL;
     si->ref_count = 1;
 
+#if defined(__LP64__)
     ElfW(Ehdr)* elf_hdr = reinterpret_cast<ElfW(Ehdr)*>(si->base);
     if (elf_hdr->e_type != ET_DYN) {
         __libc_format_fd(2, "error: only position independent executables (PIE) are supported.\n");
         exit(EXIT_FAILURE);
     }
+#endif
 
     // Use LD_LIBRARY_PATH and LD_PRELOAD (but only if we aren't setuid/setgid).
     parse_LD_LIBRARY_PATH(ldpath_env);
diff --git a/tests/Android.build.mk b/tests/Android.build.mk
index c1a0f16..6433d55 100644
--- a/tests/Android.build.mk
+++ b/tests/Android.build.mk
@@ -18,20 +18,24 @@
 
 LOCAL_MODULE := $(module)
 LOCAL_MODULE_TAGS := $(module_tag)
+ifeq ($(build_type),host)
+# Always make host multilib
+LOCAL_MULTILIB := both
+else
 LOCAL_MULTILIB := $($(module)_multilib)
+endif
+
+ifneq ($(findstring LIBRARY, $(build_target)),LIBRARY)
 ifeq ($(LOCAL_MULTILIB),both)
     LOCAL_MODULE_STEM_32 := $(module)32
     LOCAL_MODULE_STEM_64 := $(module)64
 endif
+endif
 
 LOCAL_CLANG := $($(module)_clang_$(build_type))
 
 LOCAL_FORCE_STATIC_EXECUTABLE := $($(module)_force_static_executable)
 
-LOCAL_ADDITIONAL_DEPENDENCIES := \
-    $(LOCAL_PATH)/Android.mk \
-    $(LOCAL_PATH)/Android.build.mk \
-
 LOCAL_CFLAGS := \
     $(common_cflags) \
     $($(module)_cflags) \
diff --git a/tests/Android.mk b/tests/Android.mk
index 25f8b2b..47e6272 100644
--- a/tests/Android.mk
+++ b/tests/Android.mk
@@ -115,9 +115,18 @@
 libBionicStandardTests_cflags := \
     $(test_cflags) \
 
+ifeq ($(MALLOC_IMPL),jemalloc)
+  libBionicStandardTests_cflags += -DUSE_JEMALLOC
+else
+  libBionicStandardTests_cflags += -DUSE_DLMALLOC
+endif
+
 libBionicStandardTests_cppflags := \
     $(test_cppflags) \
 
+libBionicStandardTests_c_includes := \
+    bionic/libc \
+
 libBionicStandardTests_ldlibs_host := \
     -lrt \
 
@@ -224,102 +233,6 @@
 include $(LOCAL_PATH)/Android.build.mk
 
 # -----------------------------------------------------------------------------
-# Library used by dlfcn tests.
-# -----------------------------------------------------------------------------
-ifneq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),mips mips64))
-no-elf-hash-table-library_src_files := \
-    empty.cpp \
-
-no-elf-hash-table-library_ldflags := \
-    -Wl,--hash-style=gnu \
-
-module := no-elf-hash-table-library
-module_tag := optional
-build_type := target
-build_target := SHARED_LIBRARY
-include $(LOCAL_PATH)/Android.build.mk
-endif
-
-# -----------------------------------------------------------------------------
-# Library used by dlext tests - with/without GNU RELRO program header
-# -----------------------------------------------------------------------------
-libdlext_test_src_files := \
-    dlext_test_library.cpp \
-
-libdlext_test_ldflags := \
-    -Wl,-z,relro \
-
-module := libdlext_test
-module_tag := optional
-build_type := target
-build_target := SHARED_LIBRARY
-include $(LOCAL_PATH)/Android.build.mk
-
-# -----------------------------------------------------------------------------
-# create symlink to libdlext_test.so for symlink test
-# -----------------------------------------------------------------------------
-libdlext_origin := $(LOCAL_INSTALLED_MODULE)
-libdlext_sym := $(subst libdlext_test,libdlext_test_v2,$(libdlext_origin))
-$(libdlext_sym): $(libdlext_origin)
-	@echo "Symlink: $@ -> $(notdir $<)"
-	@mkdir -p $(dir $@)
-	$(hide) ln -sf $(notdir $<) $@
-
-ALL_MODULES := \
-  $(ALL_MODULES) $(libdlext_sym)
-
-ifneq ($(TARGET_2ND_ARCH),)
-# link 64 bit .so
-libdlext_origin := $(TARGET_OUT)/lib64/libdlext_test.so
-libdlext_sym := $(subst libdlext_test,libdlext_test_v2,$(libdlext_origin))
-$(libdlext_sym): $(libdlext_origin)
-	@echo "Symlink: $@ -> $(notdir $<)"
-	@mkdir -p $(dir $@)
-	$(hide) ln -sf $(notdir $<) $@
-
-ALL_MODULES := \
-  $(ALL_MODULES) $(libdlext_sym)
-endif
-
-libdlext_test_norelro_src_files := \
-    dlext_test_library.cpp \
-
-libdlext_test_norelro_ldflags := \
-    -Wl,-z,norelro \
-
-module := libdlext_test_norelro
-module_tag := optional
-build_type := target
-build_target := SHARED_LIBRARY
-include $(LOCAL_PATH)/Android.build.mk
-
-# -----------------------------------------------------------------------------
-# Library used by dlfcn tests
-# -----------------------------------------------------------------------------
-libtest_simple_src_files := \
-    dlopen_testlib_simple.cpp
-
-module := libtest_simple
-build_type := target
-build_target := SHARED_LIBRARY
-include $(LOCAL_PATH)/Android.build.mk
-
-
-# -----------------------------------------------------------------------------
-# Library used by atexit tests
-# -----------------------------------------------------------------------------
-
-libtest_atexit_src_files := \
-    atexit_testlib.cpp
-
-module := libtest_atexit
-build_target := SHARED_LIBRARY
-build_type := target
-include $(LOCAL_PATH)/Android.build.mk
-build_type := host
-include $(LOCAL_PATH)/Android.build.mk
-
-# -----------------------------------------------------------------------------
 # Tests for the device using bionic's .so. Run with:
 #   adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests
 # -----------------------------------------------------------------------------
@@ -379,7 +292,7 @@
 #   cd bionic/tests; mm bionic-unit-tests-glibc-run
 # -----------------------------------------------------------------------------
 
-ifeq ($(HOST_OS)-$(HOST_ARCH),linux-x86)
+ifeq ($(HOST_OS)-$(HOST_ARCH),$(filter $(HOST_OS)-$(HOST_ARCH),linux-x86 linux-x86_64))
 
 bionic-unit-tests-glibc_src_files := \
     atexit_test.cpp \
@@ -443,4 +356,5 @@
 
 endif # linux-x86
 
+include $(call first-makefiles-under,$(LOCAL_PATH))
 endif # !BUILD_TINY_ANDROID
diff --git a/tests/TemporaryFile.h b/tests/TemporaryFile.h
index a7b13b0..c4ee2d5 100644
--- a/tests/TemporaryFile.h
+++ b/tests/TemporaryFile.h
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#include <fcntl.h>
 #include <unistd.h>
 
 template<int (*mk_fn)(char*)>
@@ -39,6 +40,11 @@
     unlink(filename);
   }
 
+  void reopen() {
+    close(fd);
+    fd = open(filename, O_RDWR);
+  }
+
   int fd;
   char filename[1024];
 
diff --git a/tests/dlfcn_test.cpp b/tests/dlfcn_test.cpp
index 49cbb7d..8b89183 100644
--- a/tests/dlfcn_test.cpp
+++ b/tests/dlfcn_test.cpp
@@ -254,6 +254,18 @@
   ASSERT_TRUE(addr != NULL);
 }
 
+TEST(dlfcn, dlsym_weak_func) {
+  dlerror();
+  void* handle = dlopen("libtest_dlsym_weak_func.so",RTLD_NOW);
+  ASSERT_TRUE(handle != NULL);
+
+  int (*weak_func)();
+  weak_func = reinterpret_cast<int (*)()>(dlsym(handle, "weak_func"));
+  ASSERT_TRUE(weak_func != NULL) << "dlerror: " << dlerror();
+  EXPECT_EQ(42, weak_func());
+  dlclose(handle);
+}
+
 TEST(dlfcn, dlopen_symlink) {
   void* handle1 = dlopen("libdlext_test.so", RTLD_NOW);
   void* handle2 = dlopen("libdlext_test_v2.so", RTLD_NOW);
diff --git a/tests/fcntl_test.cpp b/tests/fcntl_test.cpp
index fb6b07e..5f20295 100644
--- a/tests/fcntl_test.cpp
+++ b/tests/fcntl_test.cpp
@@ -132,3 +132,87 @@
 
   close(fd);
 }
+
+TEST(fcntl, splice) {
+  int pipe_fds[2];
+  ASSERT_EQ(0, pipe(pipe_fds));
+
+  int in = open("/proc/cpuinfo", O_RDONLY);
+  ASSERT_NE(in, -1);
+
+  TemporaryFile tf;
+
+  ssize_t bytes_read = splice(in, 0, pipe_fds[1], NULL, 8*1024, SPLICE_F_MORE | SPLICE_F_MOVE);
+  ASSERT_NE(bytes_read, -1);
+
+  ssize_t bytes_written = splice(pipe_fds[0], NULL, tf.fd, 0, bytes_read, SPLICE_F_MORE | SPLICE_F_MOVE);
+  ASSERT_EQ(bytes_read, bytes_written);
+
+  close(pipe_fds[0]);
+  close(pipe_fds[1]);
+  close(in);
+}
+
+TEST(fcntl, vmsplice) {
+  int pipe_fds[2];
+  ASSERT_EQ(0, pipe(pipe_fds));
+
+  iovec v[2];
+  v[0].iov_base = const_cast<char*>("hello ");
+  v[0].iov_len = 6;
+  v[1].iov_base = const_cast<char*>("world\n");
+  v[1].iov_len = 6;
+  ssize_t bytes_written = vmsplice(pipe_fds[1], v, sizeof(v)/sizeof(iovec), 0);
+  ASSERT_EQ(v[0].iov_len + v[1].iov_len, static_cast<size_t>(bytes_written));
+  close(pipe_fds[1]);
+
+  char buf[BUFSIZ];
+  FILE* fp = fdopen(pipe_fds[0], "r");
+  ASSERT_TRUE(fp != NULL);
+  ASSERT_TRUE(fgets(buf, sizeof(buf), fp) != NULL);
+  fclose(fp);
+  ASSERT_STREQ("hello world\n", buf);
+}
+
+TEST(fcntl, tee) {
+  char expected[256];
+  FILE* expected_fp = fopen("/proc/version", "r");
+  ASSERT_TRUE(expected_fp != NULL);
+  ASSERT_TRUE(fgets(expected, sizeof(expected), expected_fp) != NULL);
+  fclose(expected_fp);
+
+  int pipe1[2];
+  ASSERT_EQ(0, pipe(pipe1));
+
+  int pipe2[2];
+  ASSERT_EQ(0, pipe(pipe2));
+
+  int in = open("/proc/version", O_RDONLY);
+  ASSERT_NE(in, -1);
+
+  // Write /proc/version into pipe1.
+  ssize_t bytes_read = splice(in, 0, pipe1[1], NULL, 8*1024, SPLICE_F_MORE | SPLICE_F_MOVE);
+  ASSERT_NE(bytes_read, -1);
+  close(pipe1[1]);
+
+  // Tee /proc/version from pipe1 into pipe2.
+  ssize_t bytes_teed = tee(pipe1[0], pipe2[1], SIZE_MAX, 0);
+  ASSERT_EQ(bytes_read, bytes_teed);
+  close(pipe2[1]);
+
+  // The out fds of both pipe1 and pipe2 should now contain /proc/version.
+  char buf1[BUFSIZ];
+  FILE* fp1 = fdopen(pipe1[0], "r");
+  ASSERT_TRUE(fp1 != NULL);
+  ASSERT_TRUE(fgets(buf1, sizeof(buf1), fp1) != NULL);
+  fclose(fp1);
+
+  char buf2[BUFSIZ];
+  FILE* fp2 = fdopen(pipe2[0], "r");
+  ASSERT_TRUE(fp2 != NULL);
+  ASSERT_TRUE(fgets(buf2, sizeof(buf2), fp2) != NULL);
+  fclose(fp2);
+
+  ASSERT_STREQ(expected, buf1);
+  ASSERT_STREQ(expected, buf2);
+}
diff --git a/tests/libs/Android.mk b/tests/libs/Android.mk
new file mode 100644
index 0000000..67ea562
--- /dev/null
+++ b/tests/libs/Android.mk
@@ -0,0 +1,117 @@
+#
+# Copyright (C) 2012 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.
+#
+
+LOCAL_PATH := $(call my-dir)
+TEST_PATH := $(LOCAL_PATH)/..
+
+# -----------------------------------------------------------------------------
+# Library used by dlfcn tests.
+# -----------------------------------------------------------------------------
+ifneq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),mips mips64))
+no-elf-hash-table-library_src_files := \
+    empty.cpp \
+
+no-elf-hash-table-library_ldflags := \
+    -Wl,--hash-style=gnu \
+
+module := no-elf-hash-table-library
+module_tag := optional
+build_type := target
+build_target := SHARED_LIBRARY
+include $(TEST_PATH)/Android.build.mk
+endif
+
+# -----------------------------------------------------------------------------
+# Library used by dlext tests - with GNU RELRO program header
+# -----------------------------------------------------------------------------
+libdlext_test_src_files := \
+    dlext_test_library.cpp \
+
+libdlext_test_ldflags := \
+    -Wl,-z,relro \
+
+module := libdlext_test
+module_tag := optional
+build_type := target
+build_target := SHARED_LIBRARY
+include $(TEST_PATH)/Android.build.mk
+
+# -----------------------------------------------------------------------------
+# create symlink to libdlext_test.so for symlink test
+# -----------------------------------------------------------------------------
+# Use = instead of := to defer the evaluation of $@
+$(LOCAL_INSTALLED_MODULE): PRIVATE_POST_INSTALL_CMD = \
+    $(hide) cd $(dir $@) && ln -sf $(notdir $@) libdlext_test_v2.so
+
+ifneq ($(TARGET_2ND_ARCH),)
+# link 64 bit .so
+$(TARGET_OUT)/lib64/libdlext_test.so: PRIVATE_POST_INSTALL_CMD = \
+    $(hide) cd $(dir $@) && ln -sf $(notdir $@) libdlext_test_v2.so
+endif
+
+# -----------------------------------------------------------------------------
+# Library used by dlext tests - without GNU RELRO program header
+# -----------------------------------------------------------------------------
+libdlext_test_norelro_src_files := \
+    dlext_test_library.cpp \
+
+libdlext_test_norelro_ldflags := \
+    -Wl,-z,norelro \
+
+module := libdlext_test_norelro
+module_tag := optional
+build_type := target
+build_target := SHARED_LIBRARY
+include $(TEST_PATH)/Android.build.mk
+
+# -----------------------------------------------------------------------------
+# Library used by dlfcn tests
+# -----------------------------------------------------------------------------
+libtest_simple_src_files := \
+    dlopen_testlib_simple.cpp
+
+module := libtest_simple
+build_type := target
+build_target := SHARED_LIBRARY
+include $(TEST_PATH)/Android.build.mk
+
+
+# -----------------------------------------------------------------------------
+# Library used by atexit tests
+# -----------------------------------------------------------------------------
+
+libtest_atexit_src_files := \
+    atexit_testlib.cpp
+
+module := libtest_atexit
+build_target := SHARED_LIBRARY
+build_type := target
+include $(TEST_PATH)/Android.build.mk
+build_type := host
+include $(TEST_PATH)/Android.build.mk
+
+# -----------------------------------------------------------------------------
+# Library with weak function
+# -----------------------------------------------------------------------------
+libtest_dlsym_weak_func_src_files := \
+    dlsym_weak_function.cpp
+
+module := libtest_dlsym_weak_func
+build_target := SHARED_LIBRARY
+build_type := target
+include $(TEST_PATH)/Android.build.mk
+build_type := host
+include $(TEST_PATH)/Android.build.mk
diff --git a/tests/atexit_testlib.cpp b/tests/libs/atexit_testlib.cpp
similarity index 100%
rename from tests/atexit_testlib.cpp
rename to tests/libs/atexit_testlib.cpp
diff --git a/tests/dlext_test_library.cpp b/tests/libs/dlext_test_library.cpp
similarity index 100%
rename from tests/dlext_test_library.cpp
rename to tests/libs/dlext_test_library.cpp
diff --git a/tests/dlopen_testlib_simple.cpp b/tests/libs/dlopen_testlib_simple.cpp
similarity index 100%
rename from tests/dlopen_testlib_simple.cpp
rename to tests/libs/dlopen_testlib_simple.cpp
diff --git a/libc/include/sha1.h b/tests/libs/dlsym_weak_function.cpp
similarity index 75%
rename from libc/include/sha1.h
rename to tests/libs/dlsym_weak_function.cpp
index 7f6cf5d..e38f2b8 100644
--- a/libc/include/sha1.h
+++ b/tests/libs/dlsym_weak_function.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012 The Android Open Source Project
+ * Copyright (C) 2014 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.
@@ -14,10 +14,7 @@
  * limitations under the License.
  */
 
-#ifndef _SHA1_H_
-#define _SHA1_H_
+extern "C" int __attribute__((weak)) weak_func() {
+  return 42;
+}
 
-#warning "include <sys/sha1.h> instead for better portability"
-#include <sys/sha1.h>
-
-#endif
diff --git a/tests/empty.cpp b/tests/libs/empty.cpp
similarity index 100%
rename from tests/empty.cpp
rename to tests/libs/empty.cpp
diff --git a/tests/malloc_test.cpp b/tests/malloc_test.cpp
index 12a5ffa..6b7a28b 100644
--- a/tests/malloc_test.cpp
+++ b/tests/malloc_test.cpp
@@ -16,18 +16,28 @@
 
 #include <gtest/gtest.h>
 
+#include <limits.h>
+#include <stdint.h>
 #include <stdlib.h>
 #include <malloc.h>
+#include <unistd.h>
+
+#include "private/bionic_config.h"
 
 TEST(malloc, malloc_std) {
   // Simple malloc test.
   void *ptr = malloc(100);
   ASSERT_TRUE(ptr != NULL);
   ASSERT_LE(100U, malloc_usable_size(ptr));
-
   free(ptr);
 }
 
+TEST(malloc, malloc_overflow) {
+  errno = 0;
+  ASSERT_EQ(NULL, malloc(SIZE_MAX));
+  ASSERT_EQ(ENOMEM, errno);
+}
+
 TEST(malloc, calloc_std) {
   // Simple calloc test.
   size_t alloc_len = 100;
@@ -37,24 +47,67 @@
   for (size_t i = 0; i < alloc_len; i++) {
     ASSERT_EQ(0, ptr[i]);
   }
-
   free(ptr);
 }
 
+TEST(malloc, calloc_illegal) {
+  errno = 0;
+  ASSERT_EQ(NULL, calloc(-1, 100));
+  ASSERT_EQ(ENOMEM, errno);
+}
+
+TEST(malloc, calloc_overflow) {
+  errno = 0;
+  ASSERT_EQ(NULL, calloc(1, SIZE_MAX));
+  ASSERT_EQ(ENOMEM, errno);
+  errno = 0;
+  ASSERT_EQ(NULL, calloc(SIZE_MAX, SIZE_MAX));
+  ASSERT_EQ(ENOMEM, errno);
+  errno = 0;
+  ASSERT_EQ(NULL, calloc(2, SIZE_MAX));
+  ASSERT_EQ(ENOMEM, errno);
+  errno = 0;
+  ASSERT_EQ(NULL, calloc(SIZE_MAX, 2));
+  ASSERT_EQ(ENOMEM, errno);
+}
+
 TEST(malloc, memalign_multiple) {
   // Memalign test where the alignment is any value.
   for (size_t i = 0; i <= 12; i++) {
     for (size_t alignment = 1 << i; alignment < (1U << (i+1)); alignment++) {
-      char *ptr = (char*)memalign(alignment, 100);
-      ASSERT_TRUE(ptr != NULL) << alignment;
-      ASSERT_LE(100U, malloc_usable_size(ptr));
-      ASSERT_EQ(0, (intptr_t)ptr % (1 << i));
-
+      char *ptr = reinterpret_cast<char*>(memalign(alignment, 100));
+      ASSERT_TRUE(ptr != NULL) << "Failed at alignment " << alignment;
+      ASSERT_LE(100U, malloc_usable_size(ptr)) << "Failed at alignment " << alignment;
+      ASSERT_EQ(0U, reinterpret_cast<uintptr_t>(ptr) % ((1U << i)))
+          << "Failed at alignment " << alignment;
       free(ptr);
     }
   }
 }
 
+TEST(malloc, memalign_overflow) {
+  ASSERT_EQ(NULL, memalign(4096, SIZE_MAX));
+}
+
+TEST(malloc, memalign_non_power2) {
+  void* ptr;
+  for (size_t align = 0; align <= 256; align++) {
+    ptr = memalign(align, 1024);
+    ASSERT_TRUE(ptr != NULL) << "Failed at align " << align;
+    free(ptr);
+  }
+}
+
+TEST(malloc, posix_memalign_non_power2) {
+  void* ptr;
+  ASSERT_EQ(EINVAL, posix_memalign(&ptr, 17, 1024));
+}
+
+TEST(malloc, posix_memalign_overflow) {
+  void* ptr;
+  ASSERT_NE(0, posix_memalign(&ptr, 16, SIZE_MAX));
+}
+
 TEST(malloc, memalign_realloc) {
   // Memalign and then realloc the pointer a couple of times.
   for (size_t alignment = 1; alignment <= 4096; alignment <<= 1) {
@@ -87,7 +140,6 @@
     for (size_t i = 0; i < 250; i++) {
       ASSERT_EQ(0x67, ptr[i]);
     }
-
     free(ptr);
   }
 }
@@ -105,7 +157,6 @@
   for (size_t i = 0; i < 100; i++) {
     ASSERT_EQ(67, ptr[i]);
   }
-
   free(ptr);
 }
 
@@ -122,7 +173,6 @@
   for (size_t i = 0; i < 100; i++) {
     ASSERT_EQ(67, ptr[i]);
   }
-
   free(ptr);
 }
 
@@ -161,9 +211,9 @@
   for (size_t i = 0; i < 150; i++) {
     ASSERT_EQ(0x23, ptr[i]);
   }
-
   free(ptr);
 }
+
 TEST(malloc, calloc_realloc_larger) {
   // Realloc to a larger size, calloc is used for the original allocation.
   char *ptr = (char *)calloc(1, 100);
@@ -176,7 +226,6 @@
   for (size_t i = 0; i < 100; i++) {
     ASSERT_EQ(0, ptr[i]);
   }
-
   free(ptr);
 }
 
@@ -192,7 +241,6 @@
   for (size_t i = 0; i < 100; i++) {
     ASSERT_EQ(0, ptr[i]);
   }
-
   free(ptr);
 }
 
@@ -230,21 +278,47 @@
   for (size_t i = 0; i < 150; i++) {
     ASSERT_EQ(0, ptr[i]);
   }
-
   free(ptr);
 }
 
-TEST(malloc, posix_memalign_non_power2) {
-  void* ptr;
-
-  ASSERT_EQ(EINVAL, posix_memalign(&ptr, 17, 1024));
+TEST(malloc, realloc_overflow) {
+  errno = 0;
+  ASSERT_EQ(NULL, realloc(NULL, SIZE_MAX));
+  ASSERT_EQ(ENOMEM, errno);
+  void* ptr = malloc(100);
+  ASSERT_TRUE(ptr != NULL);
+  errno = 0;
+  ASSERT_EQ(NULL, realloc(ptr, SIZE_MAX));
+  ASSERT_EQ(ENOMEM, errno);
+  free(ptr);
 }
 
-TEST(malloc, memalign_non_power2) {
-  void* ptr;
-  for (size_t align = 0; align <= 256; align++) {
-    ptr = memalign(align, 1024);
-    ASSERT_TRUE(ptr != NULL) << "Failed at align " << align;
-    free(ptr);
-  }
+#if defined(HAVE_DEPRECATED_MALLOC_FUNCS)
+extern "C" void* pvalloc(size_t);
+extern "C" void* valloc(size_t);
+
+TEST(malloc, pvalloc_std) {
+  size_t pagesize = sysconf(_SC_PAGESIZE);
+  void* ptr = pvalloc(100);
+  ASSERT_TRUE(ptr != NULL);
+  ASSERT_TRUE((reinterpret_cast<uintptr_t>(ptr) & (pagesize-1)) == 0);
+  ASSERT_LE(pagesize, malloc_usable_size(ptr));
+  free(ptr);
 }
+
+TEST(malloc, pvalloc_overflow) {
+  ASSERT_EQ(NULL, pvalloc(SIZE_MAX));
+}
+
+TEST(malloc, valloc_std) {
+  size_t pagesize = sysconf(_SC_PAGESIZE);
+  void* ptr = pvalloc(100);
+  ASSERT_TRUE(ptr != NULL);
+  ASSERT_TRUE((reinterpret_cast<uintptr_t>(ptr) & (pagesize-1)) == 0);
+  free(ptr);
+}
+
+TEST(malloc, valloc_overflow) {
+  ASSERT_EQ(NULL, valloc(SIZE_MAX));
+}
+#endif
diff --git a/tests/math_test.cpp b/tests/math_test.cpp
index b0d541a..b4f5b14 100644
--- a/tests/math_test.cpp
+++ b/tests/math_test.cpp
@@ -1295,3 +1295,18 @@
   float fr = frexpf(14.1f, &exp);
   ASSERT_FLOAT_EQ(14.1f, scalbnf(fr, exp));
 }
+
+TEST(math, exp2_STRICT_ALIGN_OpenBSD_bug) {
+  // OpenBSD/x86's libm had a bug here, but it was already fixed in FreeBSD:
+  // http://svnweb.FreeBSD.org/base/head/lib/msun/src/math_private.h?revision=240827&view=markup
+  ASSERT_DOUBLE_EQ(5.0, exp2(log2(5)));
+  ASSERT_FLOAT_EQ(5.0f, exp2f(log2f(5)));
+  ASSERT_DOUBLE_EQ(5.0L, exp2l(log2l(5)));
+}
+
+TEST(math, nextafterl_OpenBSD_bug) {
+  // OpenBSD/x86's libm had a bug here.
+  ASSERT_TRUE(nextafter(1.0, 0.0) - 1.0 < 0.0);
+  ASSERT_TRUE(nextafterf(1.0f, 0.0f) - 1.0f < 0.0f);
+  ASSERT_TRUE(nextafterl(1.0L, 0.0L) - 1.0L < 0.0L);
+}
diff --git a/tests/pthread_test.cpp b/tests/pthread_test.cpp
index 0f42d43..36da481 100644
--- a/tests/pthread_test.cpp
+++ b/tests/pthread_test.cpp
@@ -69,6 +69,19 @@
 #endif // __BIONIC__
 }
 
+TEST(pthread, pthread_key_delete) {
+  void* expected = reinterpret_cast<void*>(1234);
+  pthread_key_t key;
+  ASSERT_EQ(0, pthread_key_create(&key, NULL));
+  ASSERT_EQ(0, pthread_setspecific(key, expected));
+  ASSERT_EQ(expected, pthread_getspecific(key));
+  ASSERT_EQ(0, pthread_key_delete(key));
+  // After deletion, pthread_getspecific returns NULL.
+  ASSERT_EQ(NULL, pthread_getspecific(key));
+  // And you can't use pthread_setspecific with the deleted key.
+  ASSERT_EQ(EINVAL, pthread_setspecific(key, expected));
+}
+
 static void* IdFn(void* arg) {
   return arg;
 }
diff --git a/tests/stdio_test.cpp b/tests/stdio_test.cpp
index 0ff85bf..18dae9c 100644
--- a/tests/stdio_test.cpp
+++ b/tests/stdio_test.cpp
@@ -426,7 +426,26 @@
   EXPECT_STREQ("-0.000000", buf);
 }
 
+TEST(stdio, snprintf_utf8_15439554) {
+  // http://b/15439554
+  char buf[BUFSIZ];
+
+  // 1-byte character.
+  snprintf(buf, sizeof(buf), "%dx%d", 1, 2);
+  EXPECT_STREQ("1x2", buf);
+  // 2-byte character.
+  snprintf(buf, sizeof(buf), "%d\xc2\xa2%d", 1, 2);
+  EXPECT_STREQ("1¢2", buf);
+  // 3-byte character.
+  snprintf(buf, sizeof(buf), "%d\xe2\x82\xac%d", 1, 2);
+  EXPECT_STREQ("1€2", buf);
+  // 4-byte character.
+  snprintf(buf, sizeof(buf), "%d\xf0\xa4\xad\xa2%d", 1, 2);
+  EXPECT_STREQ("1𤭢2", buf);
+}
+
 TEST(stdio, fprintf_failures_7229520) {
+  // http://b/7229520
   FILE* fp;
 
   // Unbuffered case where the fprintf(3) itself fails.
@@ -513,10 +532,6 @@
 #endif
 
   errno = 0;
-  EXPECT_EQ(EOF, putw(1234, fp));
-  EXPECT_EQ(EBADF, errno);
-
-  errno = 0;
   EXPECT_EQ(0U, fwrite("hello", 1, 2, fp));
   EXPECT_EQ(EBADF, errno);
 
diff --git a/tests/stdlib_test.cpp b/tests/stdlib_test.cpp
index 978a60f..7c86d76 100644
--- a/tests/stdlib_test.cpp
+++ b/tests/stdlib_test.cpp
@@ -35,27 +35,34 @@
   EXPECT_DOUBLE_EQ(0.061637783047395089, drand48());
 }
 
-TEST(stdlib, lrand48_random_rand) {
+TEST(stdlib, lrand48) {
   srand48(0x01020304);
   EXPECT_EQ(1409163720, lrand48());
   EXPECT_EQ(397769746, lrand48());
   EXPECT_EQ(902267124, lrand48());
   EXPECT_EQ(132366131, lrand48());
+}
 
-#if defined(__BIONIC__)
-  // On bionic, random(3) is equivalent to lrand48...
+TEST(stdlib, random) {
   srandom(0x01020304);
-  EXPECT_EQ(1409163720, random());
-  EXPECT_EQ(397769746, random());
-  EXPECT_EQ(902267124, random());
-  EXPECT_EQ(132366131, random());
+  EXPECT_EQ(55436735, random());
+  EXPECT_EQ(1399865117, random());
+  EXPECT_EQ(2032643283, random());
+  EXPECT_EQ(571329216, random());
+}
 
-  // ...and rand(3) is the bottom 32 bits.
+TEST(stdlib, rand) {
   srand(0x01020304);
-  EXPECT_EQ(static_cast<int>(1409163720), rand());
-  EXPECT_EQ(static_cast<int>(397769746), rand());
-  EXPECT_EQ(static_cast<int>(902267124), rand());
-  EXPECT_EQ(static_cast<int>(132366131), rand());
+#if defined(__BIONIC__)
+  EXPECT_EQ(1675538669, rand());
+  EXPECT_EQ(1678228258, rand());
+  EXPECT_EQ(1352350131, rand());
+  EXPECT_EQ(824068976, rand());
+#else
+  EXPECT_EQ(55436735, rand());
+  EXPECT_EQ(1399865117, rand());
+  EXPECT_EQ(2032643283, rand());
+  EXPECT_EQ(571329216, rand());
 #endif
 }
 
diff --git a/tests/string_test.cpp b/tests/string_test.cpp
index f17e575..2ab60d7 100644
--- a/tests/string_test.cpp
+++ b/tests/string_test.cpp
@@ -17,6 +17,7 @@
 #include <gtest/gtest.h>
 
 #include <errno.h>
+#include <malloc.h>
 #include <math.h>
 #include <string.h>
 
@@ -143,9 +144,9 @@
     int max_alignment = 64;
 
     // TODO: fix the tests to not sometimes use twice their specified "MAX_LEN".
-    glob_ptr = reinterpret_cast<Character*>(valloc(2 * sizeof(Character) * MAX_LEN + max_alignment));
-    glob_ptr1 = reinterpret_cast<Character*>(valloc(2 * sizeof(Character) * MAX_LEN + max_alignment));
-    glob_ptr2 = reinterpret_cast<Character*>(valloc(2 * sizeof(Character) * MAX_LEN + max_alignment));
+    glob_ptr = reinterpret_cast<Character*>(memalign(sysconf(_SC_PAGESIZE), 2 * sizeof(Character) * MAX_LEN + max_alignment));
+    glob_ptr1 = reinterpret_cast<Character*>(memalign(sysconf(_SC_PAGESIZE), 2 * sizeof(Character) * MAX_LEN + max_alignment));
+    glob_ptr2 = reinterpret_cast<Character*>(memalign(sysconf(_SC_PAGESIZE), 2 * sizeof(Character) * MAX_LEN + max_alignment));
 
     InitLenArray();
 
@@ -789,37 +790,6 @@
   }
 }
 
-extern "C" int __memcmp16(const unsigned short *ptr1, const unsigned short *ptr2, size_t n);
-
-TEST(string, __memcmp16) {
-#if defined(__BIONIC__)
-  StringTestState<unsigned short> state(SMALL);
-
-  for (size_t i = 0; i < state.n; i++) {
-    for (size_t j = 0; j < POS_ITER; j++) {
-      state.NewIteration();
-
-      unsigned short mask = 0xffff;
-      unsigned short c1 = rand() & mask;
-      unsigned short c2 = rand() & mask;
-
-      std::fill(state.ptr1, state.ptr1 + state.MAX_LEN, c1);
-      std::fill(state.ptr2, state.ptr2 + state.MAX_LEN, c1);
-
-      int pos = (state.len[i] == 0) ? 0 : (random() % state.len[i]);
-      state.ptr2[pos] = c2;
-
-      int expected = (static_cast<unsigned short>(c1) - static_cast<unsigned short>(c2));
-      int actual = __memcmp16(state.ptr1, state.ptr2, (size_t) state.MAX_LEN);
-
-      ASSERT_EQ(expected, actual);
-    }
-  }
-#else // __BIONIC__
-  GTEST_LOG_(INFO) << "This test does nothing.\n";
-#endif // __BIONIC__
-}
-
 TEST(string, wmemcmp) {
   StringTestState<wchar_t> state(SMALL);
 
@@ -909,6 +879,35 @@
   }
 }
 
+TEST(string, memmove_cache_size) {
+  size_t len = 600000;
+  int max_alignment = 31;
+  int alignments[] = {0, 5, 11, 29, 30};
+  char* ptr = reinterpret_cast<char*>(malloc(sizeof(char) * len));
+  char* ptr1 = reinterpret_cast<char*>(malloc(2 * sizeof(char) * len));
+  char* glob_ptr2 = reinterpret_cast<char*>(malloc(2 * sizeof(char) * len + max_alignment));
+  size_t pos = 64;
+
+  ASSERT_TRUE(ptr != NULL);
+  ASSERT_TRUE(ptr1 != NULL);
+  ASSERT_TRUE(glob_ptr2 != NULL);
+
+  for (int i = 0; i < 5; i++) {
+    char* ptr2 = glob_ptr2 + alignments[i];
+    memset(ptr1, random() & 255, 2 * len);
+    memset(ptr1, random() & 255, len);
+    memcpy(ptr2, ptr1, 2 * len);
+    memcpy(ptr, ptr1, len);
+    memcpy(ptr1 + pos, ptr, len);
+
+    ASSERT_TRUE(memmove(ptr2 + pos, ptr, len) == ptr2 + pos);
+    ASSERT_EQ(0, memcmp(ptr2, ptr1, 2 * len));
+  }
+  free(ptr);
+  free(ptr1);
+  free(glob_ptr2);
+}
+
 static void verify_memmove(char* src_copy, char* dst, char* src, size_t size) {
   memset(dst, 0, size);
   memcpy(src, src_copy, size);
diff --git a/tests/sys_mman_test.cpp b/tests/sys_mman_test.cpp
index 6ac279f..75ccfa3 100644
--- a/tests/sys_mman_test.cpp
+++ b/tests/sys_mman_test.cpp
@@ -17,14 +17,158 @@
 #include <gtest/gtest.h>
 
 #include <sys/mman.h>
+#include <sys/types.h>
 #include <unistd.h>
 
-TEST(sys_mman, mmap_negative) {
-  off_t off = -sysconf(_SC_PAGE_SIZE); // Aligned but negative.
-  ASSERT_EQ(MAP_FAILED, mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, off));
+#include "TemporaryFile.h"
+
+TEST(sys_mman, mmap_std) {
+  void* map = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
+  ASSERT_NE(MAP_FAILED, map);
+  ASSERT_EQ(0, munmap(map, 4096));
 }
 
-TEST(sys_mman, mmap64_negative) {
-  off64_t off64 = -sysconf(_SC_PAGE_SIZE); // Aligned but negative.
-  ASSERT_EQ(MAP_FAILED, mmap64(NULL, 4096, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, off64));
+TEST(sys_mman, mmap64_std) {
+  void* map = mmap64(NULL, 4096, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
+  ASSERT_NE(MAP_FAILED, map);
+  ASSERT_EQ(0, munmap(map, 4096));
+}
+
+TEST(sys_mman, mmap_file_bad_offset) {
+  TemporaryFile tf;
+
+  void* map = mmap(NULL, 100, PROT_READ, MAP_SHARED, tf.fd, 1);
+  ASSERT_EQ(MAP_FAILED, map);
+}
+
+TEST(sys_mman, mmap64_file_bad_offset) {
+  TemporaryFile tf;
+
+  void* map = mmap64(NULL, 100, PROT_READ, MAP_SHARED, tf.fd, 1);
+  ASSERT_EQ(MAP_FAILED, map);
+}
+
+#define STR_SSIZE(str) static_cast<ssize_t>(sizeof(str))
+
+#define STRING_MSG  "012345678\nabcdefgh\n"
+#define INITIAL_MSG "000000000\n00000000\n"
+
+TEST(sys_mman, mmap_file_read) {
+  TemporaryFile tf;
+
+  ASSERT_EQ(STR_SSIZE(STRING_MSG), write(tf.fd, STRING_MSG, sizeof(STRING_MSG)));
+
+  void* map = mmap(NULL, sizeof(STRING_MSG), PROT_READ, MAP_SHARED, tf.fd, 0);
+  ASSERT_NE(MAP_FAILED, map);
+
+  char* data = reinterpret_cast<char*>(map);
+  ASSERT_STREQ(STRING_MSG, data);
+
+  ASSERT_EQ(0, munmap(map, sizeof(STRING_MSG)));
+}
+
+TEST(sys_mman, mmap_file_write) {
+  TemporaryFile tf;
+
+  ASSERT_EQ(STR_SSIZE(INITIAL_MSG), write(tf.fd, INITIAL_MSG, sizeof(INITIAL_MSG)));
+  lseek(tf.fd, 0, SEEK_SET);
+
+  void* map = mmap(NULL, sizeof(STRING_MSG), PROT_WRITE, MAP_SHARED, tf.fd, 0);
+  ASSERT_NE(MAP_FAILED, map);
+  close(tf.fd);
+
+  memcpy(map, STRING_MSG, sizeof(STRING_MSG));
+
+  ASSERT_EQ(0, munmap(map, sizeof(STRING_MSG)));
+
+  tf.reopen();
+  char buf[sizeof(STRING_MSG)];
+  memset(buf, 0, sizeof(STRING_MSG));
+  ASSERT_EQ(STR_SSIZE(STRING_MSG), read(tf.fd, buf, sizeof(STRING_MSG)));
+
+  ASSERT_STREQ(STRING_MSG, buf);
+}
+
+#define PAGE0_MSG "00PAGE00"
+#define PAGE1_MSG "111PAGE111"
+#define PAGE2_MSG "2222PAGE2222"
+#define END_MSG "E"
+
+TEST(sys_mman, mmap_file_read_at_offset) {
+  TemporaryFile tf;
+  size_t pagesize = sysconf(_SC_PAGESIZE);
+
+  // Create the file with three pages worth of data.
+  ASSERT_EQ(STR_SSIZE(PAGE0_MSG), write(tf.fd, PAGE0_MSG, sizeof(PAGE0_MSG)));
+  ASSERT_NE(-1, lseek(tf.fd, pagesize, SEEK_SET));
+  ASSERT_EQ(STR_SSIZE(PAGE1_MSG), write(tf.fd, PAGE1_MSG, sizeof(PAGE1_MSG)));
+  ASSERT_NE(-1, lseek(tf.fd, 2 * pagesize, SEEK_SET));
+  ASSERT_EQ(STR_SSIZE(PAGE2_MSG), write(tf.fd, PAGE2_MSG, sizeof(PAGE2_MSG)));
+  ASSERT_NE(-1, lseek(tf.fd, 3 * pagesize - sizeof(END_MSG), SEEK_SET));
+  ASSERT_EQ(STR_SSIZE(END_MSG), write(tf.fd, END_MSG, sizeof(END_MSG)));
+
+  ASSERT_NE(-1, lseek(tf.fd, 0, SEEK_SET));
+
+  void* map = mmap(NULL, pagesize, PROT_READ, MAP_SHARED, tf.fd, pagesize);
+  ASSERT_NE(MAP_FAILED, map);
+
+  char* data = reinterpret_cast<char*>(map);
+  ASSERT_STREQ(PAGE1_MSG, data);
+
+  ASSERT_EQ(0, munmap(map, pagesize));
+
+  map = mmap(NULL, pagesize, PROT_READ, MAP_SHARED, tf.fd, 2 * pagesize);
+  ASSERT_NE(MAP_FAILED, map);
+
+  data = reinterpret_cast<char*>(map);
+  ASSERT_STREQ(PAGE2_MSG, data);
+  ASSERT_STREQ(END_MSG, data+pagesize-sizeof(END_MSG));
+
+  ASSERT_EQ(0, munmap(map, pagesize));
+}
+
+#define NEWPAGE1_MSG "1NEW1PAGE1"
+#define NEWPAGE2_MSG "22NEW22PAGE22"
+
+TEST(sys_mman, mmap_file_write_at_offset) {
+  TemporaryFile tf;
+  size_t pagesize = sysconf(_SC_PAGESIZE);
+
+  // Create the file with three pages worth of data.
+  ASSERT_EQ(STR_SSIZE(PAGE0_MSG), write(tf.fd, PAGE0_MSG, sizeof(PAGE0_MSG)));
+  ASSERT_NE(-1, lseek(tf.fd, pagesize, SEEK_SET));
+  ASSERT_EQ(STR_SSIZE(PAGE1_MSG), write(tf.fd, PAGE1_MSG, sizeof(PAGE1_MSG)));
+  ASSERT_NE(-1, lseek(tf.fd, 2 * pagesize, SEEK_SET));
+  ASSERT_EQ(STR_SSIZE(PAGE2_MSG), write(tf.fd, PAGE2_MSG, sizeof(PAGE2_MSG)));
+  ASSERT_NE(-1, lseek(tf.fd, 3 * pagesize - sizeof(END_MSG), SEEK_SET));
+  ASSERT_EQ(STR_SSIZE(END_MSG), write(tf.fd, END_MSG, sizeof(END_MSG)));
+
+  ASSERT_NE(-1, lseek(tf.fd, 0, SEEK_SET));
+
+  void* map = mmap(NULL, pagesize, PROT_WRITE, MAP_SHARED, tf.fd, pagesize);
+  ASSERT_NE(MAP_FAILED, map);
+  close(tf.fd);
+
+  memcpy(map, NEWPAGE1_MSG, sizeof(NEWPAGE1_MSG));
+  ASSERT_EQ(0, munmap(map, pagesize));
+
+  tf.reopen();
+  map = mmap(NULL, pagesize, PROT_WRITE, MAP_SHARED, tf.fd, 2 * pagesize);
+  ASSERT_NE(MAP_FAILED, map);
+  close(tf.fd);
+
+  memcpy(map, NEWPAGE2_MSG, sizeof(NEWPAGE2_MSG));
+  ASSERT_EQ(0, munmap(map, pagesize));
+
+  tf.reopen();
+  char buf[pagesize];
+  ASSERT_EQ(static_cast<ssize_t>(pagesize), read(tf.fd, buf, pagesize));
+  ASSERT_STREQ(PAGE0_MSG, buf);
+  ASSERT_NE(-1, lseek(tf.fd, pagesize, SEEK_SET));
+  ASSERT_EQ(static_cast<ssize_t>(pagesize), read(tf.fd, buf, pagesize));
+  ASSERT_STREQ(NEWPAGE1_MSG, buf);
+  ASSERT_NE(-1, lseek(tf.fd, 2 * pagesize, SEEK_SET));
+  ASSERT_EQ(static_cast<ssize_t>(pagesize), read(tf.fd, buf, pagesize));
+  ASSERT_STREQ(NEWPAGE2_MSG, buf);
+  ASSERT_STREQ(END_MSG, buf+pagesize-sizeof(END_MSG));
 }
diff --git a/tests/uchar_test.cpp b/tests/uchar_test.cpp
index 5f230f0..eca3c5e 100644
--- a/tests/uchar_test.cpp
+++ b/tests/uchar_test.cpp
@@ -161,9 +161,9 @@
 #if HAVE_UCHAR
   char16_t out;
 
-  out = 'x';
+  out = L'x';
   ASSERT_EQ(0U, mbrtoc16(&out, "hello", 0, NULL));
-  ASSERT_EQ('x', out);
+  ASSERT_EQ(L'x', out);
 
   ASSERT_EQ(0U, mbrtoc16(&out, "hello", 0, NULL));
   ASSERT_EQ(0U, mbrtoc16(&out, "", 0, NULL));
@@ -324,14 +324,14 @@
 #if HAVE_UCHAR
   char32_t out[8];
 
-  out[0] = 'x';
+  out[0] = L'x';
   ASSERT_EQ(0U, mbrtoc32(out, "hello", 0, NULL));
-  ASSERT_EQ('x', out[0]);
+  ASSERT_EQ(static_cast<char32_t>(L'x'), out[0]);
 
   ASSERT_EQ(0U, mbrtoc32(out, "hello", 0, NULL));
   ASSERT_EQ(0U, mbrtoc32(out, "", 0, NULL));
   ASSERT_EQ(1U, mbrtoc32(out, "hello", 1, NULL));
-  ASSERT_EQ(L'h', out[0]);
+  ASSERT_EQ(static_cast<char32_t>(L'h'), out[0]);
 
   ASSERT_EQ(0U, mbrtoc32(NULL, "hello", 0, NULL));
   ASSERT_EQ(0U, mbrtoc32(NULL, "", 0, NULL));
@@ -344,7 +344,7 @@
 
   // 1-byte UTF-8.
   ASSERT_EQ(1U, mbrtoc32(out, "abcdef", 6, NULL));
-  ASSERT_EQ(L'a', out[0]);
+  ASSERT_EQ(static_cast<char32_t>(L'a'), out[0]);
   // 2-byte UTF-8.
   ASSERT_EQ(2U, mbrtoc32(out, "\xc2\xa2" "cdef", 6, NULL));
   ASSERT_EQ(static_cast<char32_t>(0x00a2), out[0]);
diff --git a/tests/unistd_test.cpp b/tests/unistd_test.cpp
index 6aa259a..58c9ad9 100644
--- a/tests/unistd_test.cpp
+++ b/tests/unistd_test.cpp
@@ -22,6 +22,7 @@
 #include <fcntl.h>
 #include <stdint.h>
 #include <unistd.h>
+#include <sys/syscall.h>
 #include <sys/types.h>
 #include <sys/wait.h>
 
@@ -379,3 +380,72 @@
 TEST(unistd, fsync) {
   TestFsyncFunction(fsync);
 }
+
+static void AssertGetPidCorrect() {
+  // The loop is just to make manual testing/debugging with strace easier.
+  pid_t getpid_syscall_result = syscall(__NR_getpid);
+  for (size_t i = 0; i < 128; ++i) {
+    ASSERT_EQ(getpid_syscall_result, getpid());
+  }
+}
+
+TEST(unistd, getpid_caching_and_fork) {
+  pid_t parent_pid = getpid();
+  ASSERT_EQ(syscall(__NR_getpid), parent_pid);
+
+  pid_t fork_result = fork();
+  ASSERT_NE(fork_result, -1);
+  if (fork_result == 0) {
+    // We're the child.
+    AssertGetPidCorrect();
+    ASSERT_EQ(parent_pid, getppid());
+    _exit(123);
+  } else {
+    // We're the parent.
+    ASSERT_EQ(parent_pid, getpid());
+
+    int status;
+    ASSERT_EQ(fork_result, waitpid(fork_result, &status, 0));
+    ASSERT_TRUE(WIFEXITED(status));
+    ASSERT_EQ(123, WEXITSTATUS(status));
+  }
+}
+
+static int GetPidCachingCloneStartRoutine(void*) {
+  AssertGetPidCorrect();
+  return 123;
+}
+
+TEST(unistd, getpid_caching_and_clone) {
+  pid_t parent_pid = getpid();
+  ASSERT_EQ(syscall(__NR_getpid), parent_pid);
+
+  void* child_stack[1024];
+  int clone_result = clone(GetPidCachingCloneStartRoutine, &child_stack[1024], CLONE_NEWNS | SIGCHLD, NULL);
+  ASSERT_NE(clone_result, -1);
+
+  ASSERT_EQ(parent_pid, getpid());
+
+  int status;
+  ASSERT_EQ(clone_result, waitpid(clone_result, &status, 0));
+  ASSERT_TRUE(WIFEXITED(status));
+  ASSERT_EQ(123, WEXITSTATUS(status));
+}
+
+static void* GetPidCachingPthreadStartRoutine(void*) {
+  AssertGetPidCorrect();
+  return NULL;
+}
+
+TEST(unistd, getpid_caching_and_pthread_create) {
+  pid_t parent_pid = getpid();
+
+  pthread_t t;
+  ASSERT_EQ(0, pthread_create(&t, NULL, GetPidCachingPthreadStartRoutine, NULL));
+
+  ASSERT_EQ(parent_pid, getpid());
+
+  void* result;
+  ASSERT_EQ(0, pthread_join(t, &result));
+  ASSERT_EQ(NULL, result);
+}
diff --git a/tests/wchar_test.cpp b/tests/wchar_test.cpp
index 5a250a2..a5f5f63 100644
--- a/tests/wchar_test.cpp
+++ b/tests/wchar_test.cpp
@@ -221,7 +221,7 @@
   ASSERT_LT(WCHAR_MIN, WCHAR_MAX);
 }
 
-TEST(wchar, wcsstr_wcswcs) {
+TEST(wchar, wcsstr) {
   const wchar_t* haystack = L"matches hello world, not the second hello world";
   const wchar_t* empty_needle = L"";
   const wchar_t* good_needle = L"ll";
@@ -230,10 +230,6 @@
   ASSERT_EQ(haystack, wcsstr(haystack, empty_needle));
   ASSERT_EQ(&haystack[10], wcsstr(haystack, good_needle));
   ASSERT_EQ(NULL, wcsstr(haystack, bad_needle));
-
-  ASSERT_EQ(haystack, wcswcs(haystack, empty_needle));
-  ASSERT_EQ(&haystack[10], wcswcs(haystack, good_needle));
-  ASSERT_EQ(NULL, wcswcs(haystack, bad_needle));
 }
 
 TEST(wchar, mbtowc) {
@@ -453,3 +449,32 @@
   wmemmove(wstr+5, wstr, sizeof(const_wstr)/sizeof(wchar_t) - 6);
   EXPECT_STREQ(L"This This is a test of something or other", wstr);
 }
+
+TEST(wchar, mbrtowc_15439554) {
+  // http://b/15439554
+  ASSERT_STREQ("C.UTF-8", setlocale(LC_CTYPE, "C.UTF-8"));
+  uselocale(LC_GLOBAL_LOCALE);
+
+  ASSERT_GE(static_cast<size_t>(MB_LEN_MAX), MB_CUR_MAX);
+  ASSERT_GE(MB_CUR_MAX, 4U);
+
+  wchar_t wc;
+  size_t n;
+
+  // 1-byte character.
+  n = mbrtowc(&wc, "x", MB_CUR_MAX, NULL);
+  EXPECT_EQ(1U, n);
+  EXPECT_EQ(L'x', wc);
+  // 2-byte character.
+  n = mbrtowc(&wc, "\xc2\xa2", MB_CUR_MAX, NULL);
+  EXPECT_EQ(2U, n);
+  EXPECT_EQ(L'¢', wc);
+  // 3-byte character.
+  n = mbrtowc(&wc, "\xe2\x82\xac", MB_CUR_MAX, NULL);
+  EXPECT_EQ(3U, n);
+  EXPECT_EQ(L'€', wc);
+  // 4-byte character.
+  n = mbrtowc(&wc, "\xf0\xa4\xad\xa2", MB_CUR_MAX, NULL);
+  EXPECT_EQ(4U, n);
+  EXPECT_EQ(L'𤭢', wc);
+}