Merge "Reland "Retire GCC FORTIFY.""
diff --git a/benchmarks/bionic_benchmarks.cpp b/benchmarks/bionic_benchmarks.cpp
index e4c32fa..4a19fe1 100644
--- a/benchmarks/bionic_benchmarks.cpp
+++ b/benchmarks/bionic_benchmarks.cpp
@@ -78,12 +78,12 @@
 
 static struct option g_long_options[] =
 {
-  {"bionic_cpu", required_argument, 0, 'c'},
-  {"bionic_xml", required_argument, 0, 'x'},
-  {"bionic_iterations", required_argument, 0, 'i'},
-  {"bionic_extra", required_argument, 0, 'a'},
-  {"help", no_argument, 0, 'h'},
-  {0, 0, 0, 0},
+  {"bionic_cpu", required_argument, nullptr, 'c'},
+  {"bionic_xml", required_argument, nullptr, 'x'},
+  {"bionic_iterations", required_argument, nullptr, 'i'},
+  {"bionic_extra", required_argument, nullptr, 'a'},
+  {"help", no_argument, nullptr, 'h'},
+  {nullptr, 0, nullptr, 0},
 };
 
 typedef std::vector<std::vector<int64_t>> args_vector_t;
@@ -100,7 +100,7 @@
   int fake_argc = 2;
   char argv0[] = "bionic_benchmarks";
   char argv1[] = "--help";
-  char* fake_argv[3] {argv0, argv1, NULL};
+  char* fake_argv[3] {argv0, argv1, nullptr};
   benchmark::Initialize(&fake_argc, fake_argv);
   exit(1);
 }
@@ -132,7 +132,7 @@
       }
     }
   }
-  new_argv->push_back(0);
+  new_argv->push_back(nullptr);
 }
 
 bench_opts_t ParseOpts(int argc, char** argv) {
diff --git a/benchmarks/property_benchmark.cpp b/benchmarks/property_benchmark.cpp
index 17e37b0..9251a05 100644
--- a/benchmarks/property_benchmark.cpp
+++ b/benchmarks/property_benchmark.cpp
@@ -163,7 +163,7 @@
 
   size_t i = 0;
   while (state.KeepRunning()) {
-    pa.system_properties().Read(pinfo[i], 0, propvalue);
+    pa.system_properties().Read(pinfo[i], nullptr, propvalue);
     i = (i + 1) % nprops;
   }
 
diff --git a/benchmarks/pthread_benchmark.cpp b/benchmarks/pthread_benchmark.cpp
index c72736e..09654c8 100644
--- a/benchmarks/pthread_benchmark.cpp
+++ b/benchmarks/pthread_benchmark.cpp
@@ -31,7 +31,7 @@
 
 static void BM_pthread_getspecific(benchmark::State& state) {
   pthread_key_t key;
-  pthread_key_create(&key, NULL);
+  pthread_key_create(&key, nullptr);
 
   while (state.KeepRunning()) {
     pthread_getspecific(key);
@@ -43,10 +43,10 @@
 
 static void BM_pthread_setspecific(benchmark::State& state) {
   pthread_key_t key;
-  pthread_key_create(&key, NULL);
+  pthread_key_create(&key, nullptr);
 
   while (state.KeepRunning()) {
-    pthread_setspecific(key, NULL);
+    pthread_setspecific(key, nullptr);
   }
 
   pthread_key_delete(key);
@@ -147,7 +147,7 @@
 
 static void BM_pthread_rwlock_read(benchmark::State& state) {
   pthread_rwlock_t lock;
-  pthread_rwlock_init(&lock, NULL);
+  pthread_rwlock_init(&lock, nullptr);
 
   while (state.KeepRunning()) {
     pthread_rwlock_rdlock(&lock);
@@ -160,7 +160,7 @@
 
 static void BM_pthread_rwlock_write(benchmark::State& state) {
   pthread_rwlock_t lock;
-  pthread_rwlock_init(&lock, NULL);
+  pthread_rwlock_init(&lock, nullptr);
 
   while (state.KeepRunning()) {
     pthread_rwlock_wrlock(&lock);
@@ -172,42 +172,42 @@
 BIONIC_BENCHMARK(BM_pthread_rwlock_write);
 
 static void* IdleThread(void*) {
-  return NULL;
+  return nullptr;
 }
 
 static void BM_pthread_create(benchmark::State& state) {
   while (state.KeepRunning()) {
     pthread_t thread;
-    pthread_create(&thread, NULL, IdleThread, NULL);
+    pthread_create(&thread, nullptr, IdleThread, nullptr);
     state.PauseTiming();
-    pthread_join(thread, NULL);
+    pthread_join(thread, nullptr);
     state.ResumeTiming();
   }
 }
 BIONIC_BENCHMARK(BM_pthread_create);
 
 static void* RunThread(void*) {
-  return NULL;
+  return nullptr;
 }
 
 static void BM_pthread_create_and_run(benchmark::State& state) {
   while (state.KeepRunning()) {
     pthread_t thread;
-    pthread_create(&thread, NULL, RunThread, &state);
-    pthread_join(thread, NULL);
+    pthread_create(&thread, nullptr, RunThread, &state);
+    pthread_join(thread, nullptr);
   }
 }
 BIONIC_BENCHMARK(BM_pthread_create_and_run);
 
 static void* ExitThread(void*) {
-  pthread_exit(NULL);
+  pthread_exit(nullptr);
 }
 
 static void BM_pthread_exit_and_join(benchmark::State& state) {
   while (state.KeepRunning()) {
     pthread_t thread;
-    pthread_create(&thread, NULL, ExitThread, nullptr);
-    pthread_join(thread, NULL);
+    pthread_create(&thread, nullptr, ExitThread, nullptr);
+    pthread_join(thread, nullptr);
   }
 }
 BIONIC_BENCHMARK(BM_pthread_exit_and_join);
@@ -215,7 +215,7 @@
 static void BM_pthread_key_create(benchmark::State& state) {
   while (state.KeepRunning()) {
     pthread_key_t key;
-    pthread_key_create(&key, NULL);
+    pthread_key_create(&key, nullptr);
 
     state.PauseTiming();
     pthread_key_delete(key);
@@ -228,7 +228,7 @@
   while (state.KeepRunning()) {
     state.PauseTiming();
     pthread_key_t key;
-    pthread_key_create(&key, NULL);
+    pthread_key_create(&key, nullptr);
     state.ResumeTiming();
 
     pthread_key_delete(key);
diff --git a/benchmarks/semaphore_benchmark.cpp b/benchmarks/semaphore_benchmark.cpp
index a4aa7bb..ba89137 100644
--- a/benchmarks/semaphore_benchmark.cpp
+++ b/benchmarks/semaphore_benchmark.cpp
@@ -75,7 +75,7 @@
   while ((BM_semaphore_sem_post_running > 0) && !sem_wait(semaphore)) {
   }
   BM_semaphore_sem_post_running = -1;
-  return NULL;
+  return nullptr;
 }
 
 class SemaphoreFixture : public benchmark::Fixture {
diff --git a/benchmarks/stdio_benchmark.cpp b/benchmarks/stdio_benchmark.cpp
index 9c81e0f..21d9dc0 100644
--- a/benchmarks/stdio_benchmark.cpp
+++ b/benchmarks/stdio_benchmark.cpp
@@ -43,7 +43,7 @@
   char* buf = new char[chunk_size];
 
   if (!buffered) {
-    setvbuf(fp, 0, _IONBF, 0);
+    setvbuf(fp, nullptr, _IONBF, 0);
   }
 
   while (state.KeepRunning()) {
diff --git a/benchmarks/stdlib_benchmark.cpp b/benchmarks/stdlib_benchmark.cpp
index 24773de..880bc1d 100644
--- a/benchmarks/stdlib_benchmark.cpp
+++ b/benchmarks/stdlib_benchmark.cpp
@@ -111,7 +111,7 @@
 
   wchar_t wc = 0;
   while (state.KeepRunning()) {
-    for (j = 0; buf_aligned[j]; j+=mbrtowc(&wc, buf_aligned + j, 4, NULL)) {
+    for (j = 0; buf_aligned[j]; j+=mbrtowc(&wc, buf_aligned + j, 4, nullptr)) {
     }
   }
 
diff --git a/docs/libc_assembler.md b/docs/libc_assembler.md
new file mode 100644
index 0000000..44c0036
--- /dev/null
+++ b/docs/libc_assembler.md
@@ -0,0 +1,164 @@
+Validing libc Assembler Routines
+================================
+This document describes how to verify incoming assembler libc routines.
+
+## Quick Start
+* First, benchmark the previous version of the routine.
+* Update the routine, run the bionic unit tests to verify the routine doesn't
+have any bugs. See the [Testing](#Testing) section for details about how to
+verify that the routine is being properly tested.
+* Rerun the benchmarks using the updated image that uses the code for
+the new routine. See the [Performance](#Performance) section for details about
+benchmarking.
+* Verify that unwind information for new routine looks sane. See the [Unwind Info](#unwind-info) section for details about how to verify this.
+
+When benchmarking, it's best to verify on the latest Pixel device supported.
+Make sure that you benchmark both the big and little cores to verify that
+there is no major difference in performance on each.
+
+Benchmark 64 bit memcmp:
+
+    /data/benchmarktest64/bionic-benchmarks/bionic-benchmarks --bionic_xml=string.xml --benchmark_filter=memcmp
+
+Benchmark 32 bit memcmp:
+
+    /data/benchmarktest/bionic-benchmarks/bionic-benchmarks --bionic_xml=string.xml --benchmark_filter=memcmp
+
+Locking to a specific cpu:
+
+    /data/benchmarktest/bionic-benchmarks/bionic-benchmarks --bionic_cpu=2 --bionic_xml=string.xml --benchmark_filter=memcmp
+
+## Performance
+The bionic benchmarks are used to verify the performance of changes to
+routines. For most routines, there should already be benchmarks available.
+
+Building
+--------
+The bionic benchmarks are not built by default, they must be built separately
+and pushed on to the device. The commands below show how to do this.
+
+    mmma -j bionic/benchmarks
+    adb sync data
+
+Running
+-------
+There are two bionic benchmarks executables:
+
+    /data/benchmarktest64/bionic-benchmarks/bionic-benchmarks
+
+This is for 64 bit libc routines.
+
+    /data/benchmarktest/bionic-benchmarks/bionic-benchmarks
+
+This is for 32 bit libc routines.
+
+Here is an example of how the benchmark should be executed. For this
+command to work, you need to change directory to one of the above
+directories.
+
+    bionic-benchmarks --bionic_xml=string.xml --benchmark_filter=memcmp
+
+The last argument is the name of the one function that you want to
+benchmark.
+
+Almost all routines are already defined in the **string.xml** file in
+**bionic/benchmarks/suites**. Look at the examples in that file to see
+how to add a benchmark for a function that doesn't already exist.
+
+It can take a long time to run these tests since it attempts to test a
+large number of sizes and alignments.
+
+Results
+-------
+Bionic benchmarks is based on the [Google Benchmarks](https://github.com/google/benchmark)
+library. An example of the output looks like this:
+
+    Run on (8 X 1844 MHz CPU s)
+    CPU Caches:
+      L1 Data 32K (x8)
+      L1 Instruction 32K (x8)
+      L2 Unified 512K (x2)
+    ***WARNING*** CPU scaling is enabled, the benchmark real time measurements may be noisy and will incur extra overhead.
+    -------------------------------------------------------------------------------------------
+    Benchmark                                                    Time           CPU Iterations
+    -------------------------------------------------------------------------------------------
+    BM_string_memcmp/1/0/0                                       6 ns          6 ns  120776418   164.641MB/s
+    BM_string_memcmp/1/1/1                                       6 ns          6 ns  120856788   164.651MB/s
+
+The smaller the time, the better the performance.
+
+Caveats
+-------
+When running the benchmarks, CPU scaling is not normally enabled. This means
+that if the device does not get up to the maximum cpu frequency, the results
+can vary wildly. It's possible to lock the cpu to the maximum frequency, but
+is beyond the scope of this document. However, most of the benchmarks max
+out the cpu very quickly on Pixel devices, and don't affect the results.
+
+Another potential issue is that the device can overheat when running the
+benchmarks. To avoid this, you can run the device in a cool environment,
+or choose a device that is less likely to overheat. To detect these kind
+of issues, you can run a subset of the tests again. At the very least, it's
+always a good idea to rerun the suite a couple of times to verify that
+there isn't a high variation in the numbers.
+
+If you want to verify a single benchmark result, you can run a single test
+using a command like this:
+
+    bionic-benchmarks --bionic_xml=string.xml --benchmark_filter=BM_string_memcmp/1/1/0
+
+Where the argument to the filter argument is the name of the benchmark from
+the output. Sometimes this filter can still match multiple benchmarks, to
+guarantee that you only run the single benchmark, you can execute the benchmark
+like so:
+
+    bionic-benchmarks --bionic_xml=string.xml --benchmark_filter=BM_string_memcmp/1/1/0$
+
+NOTE: It is assumed that these commands are executed in adb as the shell user
+on device. If you are trying to run this using adb directly from a host
+machine, you might need to escape the special shell characters such as **$**.
+
+## Testing
+
+Run the bionic tests to verify that the new routines are valid. However,
+you should verify that there is coverage of the new routines. This is
+especially important if this is the first time a routine is assembler.
+
+Caveats
+-------
+When verifying an assembler routine that operates on buffer data (such as
+memcpy/strcpy), it's important to verify these corner cases:
+
+* Verify the routine does not read past the end of the buffers. Many
+assembler routines optimize by reading multipe bytes at a time and can
+read past the end. This kind of bug results in an infrequent and difficult to
+diagnosis crash.
+* Verify the routine handles unaligned buffers properly. Usually, a failure
+can result in an unaligned exception.
+* Verify the routine handles different sized buffers.
+
+If there are not sufficient tests for a new routine, there are a set of helper
+functions that can be used to verify the above corner cases. See the
+header **bionic/tests/buffer\_tests.h** for these routines and look at
+**bionic/tests/string\_test.cpp** for examples of how to use it.
+
+## Unwind Info
+It is also important to verify that the unwind information for these
+routines are properly set up. Here is a quick checklist of what to check:
+
+* Verify that all labels are of the format .LXXX, where XXX is any valid string
+for a label. If any other label is used, entries in the symbol table
+will be generated that include these labels. In that case, you will get
+an unwind with incorrect function information.
+* Verify that all places where pop/pushes or instructions that modify the
+sp in any way have corresponding cfi information. Along with this item,
+verify that when registers are pushed on the stack that there is cfi
+information indicating how to get the register.
+* Verify that only cfi directives are being used. This only matters for
+arm32, where it's possible to use ARM specific unwind directives.
+
+This list is not meant to be exhaustive, but a minimal set of items to verify
+before submitting a new libc assembler routine. There are difficult
+to verify unwind cases, such as around branches, where unwind information
+can be drastically different for the target of the branch and for the
+code after a branch instruction.
diff --git a/libc/Android.bp b/libc/Android.bp
index 44b0b68..1f95ce8 100644
--- a/libc/Android.bp
+++ b/libc/Android.bp
@@ -2152,3 +2152,227 @@
         "kernel/uapi/linux/input-event-codes.h",
     ],
 }
+
+// Generate a syscall name / number mapping. These objects are text files
+// (thanks to the -dD -E flags) and not binary files. They will then be
+// consumed by the genseccomp.py script and converted into C++ code.
+cc_defaults {
+    name: "libseccomp_gen_syscall_nrs_defaults",
+    recovery_available: true,
+    srcs: ["seccomp/gen_syscall_nrs.cpp"],
+    cflags: [
+        "-dD",
+        "-E",
+        "-Wall",
+        "-Werror",
+        "-nostdinc",
+    ],
+}
+
+cc_object {
+    name: "libseccomp_gen_syscall_nrs_arm",
+    defaults: ["libseccomp_gen_syscall_nrs_defaults"],
+    local_include_dirs: [
+        "kernel/uapi/asm-arm",
+        "kernel/uapi",
+    ],
+}
+
+cc_object {
+    name: "libseccomp_gen_syscall_nrs_arm64",
+    defaults: ["libseccomp_gen_syscall_nrs_defaults"],
+    local_include_dirs: [
+        "kernel/uapi/asm-arm64",
+        "kernel/uapi",
+    ],
+}
+
+cc_object {
+    name: "libseccomp_gen_syscall_nrs_x86",
+    defaults: ["libseccomp_gen_syscall_nrs_defaults"],
+    srcs: ["seccomp/gen_syscall_nrs_x86.cpp"],
+    exclude_srcs: ["seccomp/gen_syscall_nrs.cpp"],
+    local_include_dirs: [
+        "kernel/uapi/asm-x86",
+        "kernel/uapi",
+    ],
+}
+
+cc_object {
+    name: "libseccomp_gen_syscall_nrs_x86_64",
+    defaults: ["libseccomp_gen_syscall_nrs_defaults"],
+    srcs: ["seccomp/gen_syscall_nrs_x86_64.cpp"],
+    exclude_srcs: ["seccomp/gen_syscall_nrs.cpp"],
+    local_include_dirs: [
+        "kernel/uapi/asm-x86",
+        "kernel/uapi",
+    ],
+}
+
+cc_object {
+    name: "libseccomp_gen_syscall_nrs_mips",
+    defaults: ["libseccomp_gen_syscall_nrs_defaults"],
+    cflags: [
+        "-D_MIPS_SIM=_MIPS_SIM_ABI32",
+    ],
+    local_include_dirs: [
+        "kernel/uapi/asm-mips",
+        "kernel/uapi",
+    ],
+}
+
+cc_object {
+    name: "libseccomp_gen_syscall_nrs_mips64",
+    defaults: ["libseccomp_gen_syscall_nrs_defaults"],
+    cflags: [
+        "-D_MIPS_SIM=_MIPS_SIM_ABI64",
+    ],
+    local_include_dirs: [
+        "kernel/uapi/asm-mips",
+        "kernel/uapi",
+    ],
+}
+
+// Generate the C++ policy sources for app, system, and global seccomp-bpf
+// filters.
+python_binary_host {
+    name: "genseccomp",
+    main: "tools/genseccomp.py",
+
+    srcs: [
+        "tools/genseccomp.py",
+        "tools/gensyscalls.py",
+    ],
+
+    data: [
+        "kernel/uapi/**/*.h",
+    ],
+
+    version: {
+        py2: {
+            enabled: true,
+        },
+        py3: {
+            enabled: false,
+        },
+    },
+}
+
+cc_genrule {
+    name: "libseccomp_policy_app_sources",
+    recovery_available: true,
+    cmd: "$(location genseccomp) --out-dir=$(genDir) --name-modifier=app $(in)",
+
+    tools: [ "genseccomp" ],
+
+    srcs: [
+        "SYSCALLS.TXT",
+        "SECCOMP_WHITELIST_COMMON.TXT",
+        "SECCOMP_WHITELIST_APP.TXT",
+        "SECCOMP_BLACKLIST_COMMON.TXT",
+        "SECCOMP_BLACKLIST_APP.TXT",
+        ":libseccomp_gen_syscall_nrs_arm",
+        ":libseccomp_gen_syscall_nrs_arm64",
+        ":libseccomp_gen_syscall_nrs_mips",
+        ":libseccomp_gen_syscall_nrs_mips64",
+        ":libseccomp_gen_syscall_nrs_x86",
+        ":libseccomp_gen_syscall_nrs_x86_64",
+    ],
+
+    out: [
+        "arm64_app_policy.cpp",
+        "arm_app_policy.cpp",
+        "mips64_app_policy.cpp",
+        "mips_app_policy.cpp",
+        "x86_64_app_policy.cpp",
+        "x86_app_policy.cpp",
+    ],
+}
+
+cc_genrule {
+    name: "libseccomp_policy_system_sources",
+    recovery_available: true,
+    cmd: "$(location genseccomp) --out-dir=$(genDir) --name-modifier=system $(in)",
+
+    tools: [ "genseccomp" ],
+
+    srcs: [
+        "SYSCALLS.TXT",
+        "SECCOMP_WHITELIST_COMMON.TXT",
+        "SECCOMP_WHITELIST_SYSTEM.TXT",
+        "SECCOMP_BLACKLIST_COMMON.TXT",
+        ":libseccomp_gen_syscall_nrs_arm",
+        ":libseccomp_gen_syscall_nrs_arm64",
+        ":libseccomp_gen_syscall_nrs_mips",
+        ":libseccomp_gen_syscall_nrs_mips64",
+        ":libseccomp_gen_syscall_nrs_x86",
+        ":libseccomp_gen_syscall_nrs_x86_64",
+    ],
+
+    out: [
+        "arm64_system_policy.cpp",
+        "arm_system_policy.cpp",
+        "mips64_system_policy.cpp",
+        "mips_system_policy.cpp",
+        "x86_64_system_policy.cpp",
+        "x86_system_policy.cpp",
+    ],
+}
+
+cc_genrule {
+    name: "libseccomp_policy_global_sources",
+    recovery_available: true,
+    cmd: "$(location genseccomp) --out-dir=$(genDir) --name-modifier=global $(in)",
+
+    tools: [ "genseccomp" ],
+
+    srcs: [
+        "SYSCALLS.TXT",
+        "SECCOMP_WHITELIST_COMMON.TXT",
+        "SECCOMP_WHITELIST_SYSTEM.TXT",
+        "SECCOMP_WHITELIST_APP.TXT",
+        "SECCOMP_WHITELIST_GLOBAL.TXT",
+        "SECCOMP_BLACKLIST_COMMON.TXT",
+        ":libseccomp_gen_syscall_nrs_arm",
+        ":libseccomp_gen_syscall_nrs_arm64",
+        ":libseccomp_gen_syscall_nrs_mips",
+        ":libseccomp_gen_syscall_nrs_mips64",
+        ":libseccomp_gen_syscall_nrs_x86",
+        ":libseccomp_gen_syscall_nrs_x86_64",
+    ],
+
+    out: [
+        "arm64_global_policy.cpp",
+        "arm_global_policy.cpp",
+        "mips64_global_policy.cpp",
+        "mips_global_policy.cpp",
+        "x86_64_global_policy.cpp",
+        "x86_global_policy.cpp",
+    ],
+}
+
+cc_library {
+    name: "libseccomp_policy",
+    recovery_available: true,
+    generated_sources: [
+        "libseccomp_policy_app_sources",
+        "libseccomp_policy_global_sources",
+        "libseccomp_policy_system_sources",
+    ],
+
+    srcs: [
+        "seccomp/seccomp_policy.cpp",
+    ],
+
+    export_include_dirs: ["seccomp/include"],
+    cflags: [
+        "-Wall",
+        "-Werror",
+    ],
+    shared: {
+        shared_libs: ["libbase"],
+    },
+    static: {
+        static_libs: ["libbase"],
+    },
+}
diff --git a/libc/NOTICE b/libc/NOTICE
index 744f42b..486c615 100644
--- a/libc/NOTICE
+++ b/libc/NOTICE
@@ -3810,6 +3810,34 @@
 
 -------------------------------------------------------------------
 
+Copyright (c) 2003 Dag-Erling Smørgrav
+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
+   in this position and unchanged.
+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. The name of the author may not be used to endorse or promote products
+   derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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) 2003 David Schultz <das@FreeBSD.ORG>
 All rights reserved.
 
@@ -3935,6 +3963,32 @@
 
 -------------------------------------------------------------------
 
+Copyright (c) 2003, Steven G. Kargl
+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 unmodified, 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.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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) 2004 David Schultz <das@FreeBSD.ORG>
 All rights reserved.
 
@@ -3961,6 +4015,32 @@
 
 -------------------------------------------------------------------
 
+Copyright (c) 2004 Stefan Farfeleder
+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.
+
+THIS SOFTWARE IS PROVIDED BY AUTHOR 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 AUTHOR 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) 2004 by Internet Systems Consortium, Inc. ("ISC")
 Copyright (c) 1995,1999 by Internet Software Consortium.
 
@@ -4192,6 +4272,58 @@
 
 -------------------------------------------------------------------
 
+Copyright (c) 2005 Bruce D. Evans and Steven G. Kargl
+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 unmodified, 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.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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) 2005 David Schultz <das@FreeBSD.ORG>
+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.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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) 2005 Tim J. Robbins.
 All rights reserved.
 
@@ -4261,6 +4393,32 @@
 
 -------------------------------------------------------------------
 
+Copyright (c) 2005-2011 David Schultz <das@FreeBSD.ORG>
+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.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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) 2007 David Schultz
 All rights reserved.
 
@@ -4287,6 +4445,93 @@
 
 -------------------------------------------------------------------
 
+Copyright (c) 2007 David Schultz <das@FreeBSD.ORG>
+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.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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) 2007 David Schultz <das@FreeBSD.ORG>
+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.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
+
+Derived from s_modf.c, which has the following Copyright:
+====================================================
+Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+
+Developed at SunPro, a Sun Microsystems, Inc. business.
+Permission to use, copy, modify, and distribute this
+software is freely granted, provided that this notice
+is preserved.
+
+-------------------------------------------------------------------
+
+Copyright (c) 2007 Steven G. Kargl
+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 unmodified, 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.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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) 2007 The NetBSD Foundation, Inc.
 All rights reserved.
 
@@ -4415,6 +4660,32 @@
 
 -------------------------------------------------------------------
 
+Copyright (c) 2007-2008 David Schultz <das@FreeBSD.ORG>
+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.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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) 2007-2013 Bruce D. Evans
 All rights reserved.
 
@@ -4483,6 +4754,22 @@
 
 -------------------------------------------------------------------
 
+Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net>
+
+Permission to use, copy, modify, and distribute this software for any
+purpose with or without fee is hereby granted, provided that the above
+copyright notice and this permission notice appear in all copies.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+-------------------------------------------------------------------
+
 Copyright (c) 2008 Todd C. Miller <millert@openbsd.org>
 
 Permission to use, copy, modify, and distribute this software for any
@@ -4755,6 +5042,58 @@
 
 -------------------------------------------------------------------
 
+Copyright (c) 2011 David Schultz
+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 unmodified, 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.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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) 2011 David Schultz <das@FreeBSD.ORG>
+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.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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) 2011 Ed Schouten <ed@FreeBSD.org>
                    David Chisnall <theraven@FreeBSD.org>
 All rights reserved.
@@ -4945,6 +5284,32 @@
 -------------------------------------------------------------------
 
 Copyright (c) 2012 Stephen Montgomery-Smith <stephen@FreeBSD.ORG>
+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.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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) 2012 Stephen Montgomery-Smith <stephen@FreeBSD.ORG>
 Copyright (c) 2017 Mahdi Mokhtari <mmokhi@FreeBSD.org>
 All rights reserved.
 
@@ -5128,6 +5493,32 @@
 
 -------------------------------------------------------------------
 
+Copyright (c) 2013 Bruce D. Evans
+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 unmodified, 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.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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) 2013 The NetBSD Foundation, Inc.
 All rights reserved.
 
@@ -5682,521 +6073,6 @@
 
 -------------------------------------------------------------------
 
-SPDX-License-Identifier: BSD-2-Clause-FreeBSD
-
-Copyright (c) 2003, Steven G. Kargl
-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 unmodified, 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.
-
-THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
-
--------------------------------------------------------------------
-
-SPDX-License-Identifier: BSD-2-Clause-FreeBSD
-
-Copyright (c) 2004 David Schultz <das@FreeBSD.ORG>
-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.
-
-THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
-
--------------------------------------------------------------------
-
-SPDX-License-Identifier: BSD-2-Clause-FreeBSD
-
-Copyright (c) 2004 Stefan Farfeleder
-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.
-
-THIS SOFTWARE IS PROVIDED BY AUTHOR 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 AUTHOR 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.
-
--------------------------------------------------------------------
-
-SPDX-License-Identifier: BSD-2-Clause-FreeBSD
-
-Copyright (c) 2004-2005 David Schultz <das@FreeBSD.ORG>
-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.
-
-THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
-
--------------------------------------------------------------------
-
-SPDX-License-Identifier: BSD-2-Clause-FreeBSD
-
-Copyright (c) 2005 Bruce D. Evans and Steven G. Kargl
-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 unmodified, 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.
-
-THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
-
--------------------------------------------------------------------
-
-SPDX-License-Identifier: BSD-2-Clause-FreeBSD
-
-Copyright (c) 2005 David Schultz <das@FreeBSD.ORG>
-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.
-
-THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
-
--------------------------------------------------------------------
-
-SPDX-License-Identifier: BSD-2-Clause-FreeBSD
-
-Copyright (c) 2005-2008 David Schultz <das@FreeBSD.ORG>
-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.
-
-THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
-
--------------------------------------------------------------------
-
-SPDX-License-Identifier: BSD-2-Clause-FreeBSD
-
-Copyright (c) 2005-2011 David Schultz <das@FreeBSD.ORG>
-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.
-
-THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
-
--------------------------------------------------------------------
-
-SPDX-License-Identifier: BSD-2-Clause-FreeBSD
-
-Copyright (c) 2007 David Schultz
-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.
-
-THIS SOFTWARE IS PROVIDED BY AUTHOR 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 AUTHOR 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.
-
--------------------------------------------------------------------
-
-SPDX-License-Identifier: BSD-2-Clause-FreeBSD
-
-Copyright (c) 2007 David Schultz <das@FreeBSD.ORG>
-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.
-
-THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
-
--------------------------------------------------------------------
-
-SPDX-License-Identifier: BSD-2-Clause-FreeBSD
-
-Copyright (c) 2007 David Schultz <das@FreeBSD.ORG>
-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.
-
-THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
-
-Derived from s_modf.c, which has the following Copyright:
-====================================================
-Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
-
-Developed at SunPro, a Sun Microsystems, Inc. business.
-Permission to use, copy, modify, and distribute this
-software is freely granted, provided that this notice
-is preserved.
-
--------------------------------------------------------------------
-
-SPDX-License-Identifier: BSD-2-Clause-FreeBSD
-
-Copyright (c) 2007 Steven G. Kargl
-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 unmodified, 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.
-
-THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
-
--------------------------------------------------------------------
-
-SPDX-License-Identifier: BSD-2-Clause-FreeBSD
-
-Copyright (c) 2007-2008 David Schultz <das@FreeBSD.ORG>
-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.
-
-THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
-
--------------------------------------------------------------------
-
-SPDX-License-Identifier: BSD-2-Clause-FreeBSD
-
-Copyright (c) 2008 David Schultz <das@FreeBSD.ORG>
-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.
-
-THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
-
--------------------------------------------------------------------
-
-SPDX-License-Identifier: BSD-2-Clause-FreeBSD
-
-Copyright (c) 2011 David Schultz
-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 unmodified, 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.
-
-THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
-
--------------------------------------------------------------------
-
-SPDX-License-Identifier: BSD-2-Clause-FreeBSD
-
-Copyright (c) 2011 David Schultz <das@FreeBSD.ORG>
-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.
-
-THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
-
--------------------------------------------------------------------
-
-SPDX-License-Identifier: BSD-2-Clause-FreeBSD
-
-Copyright (c) 2012 Stephen Montgomery-Smith <stephen@FreeBSD.ORG>
-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.
-
-THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
-
--------------------------------------------------------------------
-
-SPDX-License-Identifier: BSD-3-Clause
-
-Copyright (c) 2003 Dag-Erling Smørgrav
-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
-   in this position and unchanged.
-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. The name of the author may not be used to endorse or promote products
-   derived from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 author of this software is David M. Gay.
 
 Copyright (C) 1998 by Lucent Technologies
diff --git a/libc/SECCOMP_WHITELIST_COMMON.TXT b/libc/SECCOMP_WHITELIST_COMMON.TXT
index 08a2c2b..60568e6 100644
--- a/libc/SECCOMP_WHITELIST_COMMON.TXT
+++ b/libc/SECCOMP_WHITELIST_COMMON.TXT
@@ -57,7 +57,7 @@
 # Needed by sanitizers (b/34606909)
 # 5 (__NR_open) and 195 (__NR_stat64) are also required, but they are
 # already allowed.
-ssize_t	readlink:readlink(const char *path, char *buf, size_t bufsiz)	arm,x86,mips
+ssize_t	readlink:readlink(const char *path, char *buf, size_t bufsiz)	arm,x86,x86_64,mips
 
 # Useful new syscalls which we don't yet use in bionic.
 int sched_getattr(pid_t pid, struct sched_attr* attr, unsigned int flags) all
diff --git a/libc/async_safe/async_safe_log.cpp b/libc/async_safe/async_safe_log.cpp
index c6b8b53..5f22c74 100644
--- a/libc/async_safe/async_safe_log.cpp
+++ b/libc/async_safe/async_safe_log.cpp
@@ -333,7 +333,7 @@
     if (c == 's') {
       /* string */
       str = va_arg(args, const char*);
-      if (str == NULL) {
+      if (str == nullptr) {
         str = "(null)";
       }
     } else if (c == 'c') {
diff --git a/libc/bionic/__cmsg_nxthdr.cpp b/libc/bionic/__cmsg_nxthdr.cpp
index f962788..354e17e 100644
--- a/libc/bionic/__cmsg_nxthdr.cpp
+++ b/libc/bionic/__cmsg_nxthdr.cpp
@@ -33,7 +33,7 @@
   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);
   if (len > msg->msg_controllen) {
-    return NULL;
+    return nullptr;
   }
   return ptr;
 }
diff --git a/libc/bionic/__gnu_basename.cpp b/libc/bionic/__gnu_basename.cpp
index 1eb3f65..f9f87a6 100644
--- a/libc/bionic/__gnu_basename.cpp
+++ b/libc/bionic/__gnu_basename.cpp
@@ -31,5 +31,5 @@
 
 extern "C" const char* __gnu_basename(const char* path) {
   const char* last_slash = strrchr(path, '/');
-  return (last_slash != NULL) ? last_slash + 1 : path;
+  return (last_slash != nullptr) ? last_slash + 1 : path;
 }
diff --git a/libc/bionic/atof.cpp b/libc/bionic/atof.cpp
index e77ccdd..c17deab 100644
--- a/libc/bionic/atof.cpp
+++ b/libc/bionic/atof.cpp
@@ -31,5 +31,5 @@
 double atof(const char* s) {
   // Despite the 'f' in the name, this returns a double and is
   // specified to be equivalent to strtod.
-  return strtod(s, NULL);
+  return strtod(s, nullptr);
 }
diff --git a/libc/bionic/brk.cpp b/libc/bionic/brk.cpp
index e1a4b05..566c33a 100644
--- a/libc/bionic/brk.cpp
+++ b/libc/bionic/brk.cpp
@@ -48,8 +48,8 @@
 
 void* sbrk(ptrdiff_t increment) {
   // Initialize __bionic_brk if necessary.
-  if (__bionic_brk == NULL) {
-    __bionic_brk = __brk(NULL);
+  if (__bionic_brk == nullptr) {
+    __bionic_brk = __brk(nullptr);
   }
 
   // Don't ask the kernel if we already know the answer.
diff --git a/libc/bionic/c16rtomb.cpp b/libc/bionic/c16rtomb.cpp
index 93749c6..2d6ae93 100644
--- a/libc/bionic/c16rtomb.cpp
+++ b/libc/bionic/c16rtomb.cpp
@@ -42,7 +42,7 @@
 
 size_t c16rtomb(char* s, char16_t c16, mbstate_t* ps) {
   static mbstate_t __private_state;
-  mbstate_t* state = (ps == NULL) ? &__private_state : ps;
+  mbstate_t* state = (ps == nullptr) ? &__private_state : ps;
   if (mbsinit(state)) {
     if (is_high_surrogate(c16)) {
       char32_t c32 = (c16 & ~0xd800) << 10;
@@ -62,6 +62,6 @@
     char32_t c32 = ((mbstate_get_byte(state, 3) << 16) |
                     (mbstate_get_byte(state, 2) << 8) |
                     (c16 & ~0xdc00)) + 0x10000;
-    return mbstate_reset_and_return(c32rtomb(s, c32, NULL), state);
+    return mbstate_reset_and_return(c32rtomb(s, c32, nullptr), state);
   }
 }
diff --git a/libc/bionic/c32rtomb.cpp b/libc/bionic/c32rtomb.cpp
index ebe9cd3..2909d8b 100644
--- a/libc/bionic/c32rtomb.cpp
+++ b/libc/bionic/c32rtomb.cpp
@@ -34,9 +34,9 @@
 
 size_t c32rtomb(char* s, char32_t c32, mbstate_t* ps) {
   static mbstate_t __private_state;
-  mbstate_t* state = (ps == NULL) ? &__private_state : ps;
+  mbstate_t* state = (ps == nullptr) ? &__private_state : ps;
 
-  if (s == NULL) {
+  if (s == nullptr) {
     // Equivalent to c32rtomb(buf, U'\0', ps).
     return mbstate_reset_and_return(1, state);
   }
diff --git a/libc/bionic/clearenv.cpp b/libc/bionic/clearenv.cpp
index c70cc3e..01c9c39 100644
--- a/libc/bionic/clearenv.cpp
+++ b/libc/bionic/clearenv.cpp
@@ -31,9 +31,9 @@
 
 int clearenv() {
   char** e = environ;
-  if (e != NULL) {
+  if (e != nullptr) {
     for (; *e; ++e) {
-      *e = NULL;
+      *e = nullptr;
     }
   }
   return 0;
diff --git a/libc/bionic/dirent.cpp b/libc/bionic/dirent.cpp
index 153e56a..8921ca0 100644
--- a/libc/bionic/dirent.cpp
+++ b/libc/bionic/dirent.cpp
@@ -68,15 +68,15 @@
 
 static DIR* __allocate_DIR(int fd) {
   DIR* d = reinterpret_cast<DIR*>(malloc(sizeof(DIR)));
-  if (d == NULL) {
-    return NULL;
+  if (d == nullptr) {
+    return nullptr;
   }
   d->fd_ = fd;
   android_fdsan_exchange_owner_tag(fd, 0, __get_dir_tag(d));
   d->available_bytes_ = 0;
-  d->next_ = NULL;
+  d->next_ = nullptr;
   d->current_pos_ = 0L;
-  pthread_mutex_init(&d->mutex_, NULL);
+  pthread_mutex_init(&d->mutex_, nullptr);
   return d;
 }
 
@@ -89,11 +89,11 @@
   // Is 'fd' actually a directory?
   struct stat sb;
   if (fstat(fd, &sb) == -1) {
-    return NULL;
+    return nullptr;
   }
   if (!S_ISDIR(sb.st_mode)) {
     errno = ENOTDIR;
-    return NULL;
+    return nullptr;
   }
 
   return __allocate_DIR(fd);
@@ -101,7 +101,7 @@
 
 DIR* opendir(const char* path) {
   int fd = open(path, O_CLOEXEC | O_DIRECTORY | O_RDONLY);
-  return (fd != -1) ? __allocate_DIR(fd) : NULL;
+  return (fd != -1) ? __allocate_DIR(fd) : nullptr;
 }
 
 static bool __fill_DIR(DIR* d) {
@@ -117,7 +117,7 @@
 
 static dirent* __readdir_locked(DIR* d) {
   if (d->available_bytes_ == 0 && !__fill_DIR(d)) {
-    return NULL;
+    return nullptr;
   }
 
   dirent* entry = d->next_;
@@ -141,17 +141,17 @@
 
   ErrnoRestorer errno_restorer;
 
-  *result = NULL;
+  *result = nullptr;
   errno = 0;
 
   ScopedPthreadMutexLocker locker(&d->mutex_);
 
   dirent* next = __readdir_locked(d);
-  if (errno != 0 && next == NULL) {
+  if (errno != 0 && next == nullptr) {
     return errno;
   }
 
-  if (next != NULL) {
+  if (next != nullptr) {
     memcpy(entry, next, next->d_reclen);
     *result = entry;
   }
@@ -160,7 +160,7 @@
 __strong_alias(readdir64_r, readdir_r);
 
 int closedir(DIR* d) {
-  if (d == NULL) {
+  if (d == nullptr) {
     errno = EINVAL;
     return -1;
   }
diff --git a/libc/bionic/error.cpp b/libc/bionic/error.cpp
index e8df0e0..a8adc1b 100644
--- a/libc/bionic/error.cpp
+++ b/libc/bionic/error.cpp
@@ -34,13 +34,13 @@
 #include <string.h>
 
 unsigned int error_message_count = 0;
-void (*error_print_progname)(void) = NULL;
+void (*error_print_progname)(void) = nullptr;
 int error_one_per_line = 0;
 
 static void __error_head() {
   ++error_message_count;
 
-  if (error_print_progname != NULL) {
+  if (error_print_progname != nullptr) {
     error_print_progname();
   } else {
     fflush(stdout);
@@ -77,7 +77,7 @@
   if (error_one_per_line) {
     static const char* last_file;
     static unsigned int last_line;
-    if (last_line == line && last_file != NULL && strcmp(last_file, file) == 0) {
+    if (last_line == line && last_file != nullptr && strcmp(last_file, file) == 0) {
       return;
     }
     last_file = file;
diff --git a/libc/bionic/fdsan.cpp b/libc/bionic/fdsan.cpp
index df369cc..43d8831 100644
--- a/libc/bionic/fdsan.cpp
+++ b/libc/bionic/fdsan.cpp
@@ -30,6 +30,7 @@
 
 #include <errno.h>
 #include <inttypes.h>
+#include <signal.h>
 #include <stdarg.h>
 #include <stdatomic.h>
 #include <string.h>
@@ -49,10 +50,65 @@
 
 static constexpr const char* kFdsanPropertyName = "debug.fdsan";
 
+template<size_t inline_fds>
+FdEntry* FdTableImpl<inline_fds>::at(size_t idx) {
+  if (idx < inline_fds) {
+    return &entries[idx];
+  }
+
+  // Try to create the overflow table ourselves.
+  FdTableOverflow* local_overflow = atomic_load(&overflow);
+  if (__predict_false(!local_overflow)) {
+    struct rlimit rlim = { .rlim_max = 32768 };
+    getrlimit(RLIMIT_NOFILE, &rlim);
+    rlim_t max = rlim.rlim_max;
+
+    if (max == RLIM_INFINITY) {
+      // This isn't actually possible (the kernel has a hard limit), but just
+      // in case...
+      max = 32768;
+    }
+
+    if (idx > max) {
+      // This can happen if an fd is created and then the rlimit is lowered.
+      // In this case, just return nullptr and ignore the fd.
+      return nullptr;
+    }
+
+    size_t required_count = max - inline_fds;
+    size_t required_size = sizeof(FdTableOverflow) + required_count * sizeof(FdEntry);
+    size_t aligned_size = __BIONIC_ALIGN(required_size, PAGE_SIZE);
+    size_t aligned_count = (aligned_size - sizeof(FdTableOverflow)) / sizeof(FdEntry);
+
+    void* allocation =
+        mmap(nullptr, aligned_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+    if (allocation == MAP_FAILED) {
+      async_safe_fatal("fdsan: mmap failed: %s", strerror(errno));
+    }
+
+    FdTableOverflow* new_overflow = reinterpret_cast<FdTableOverflow*>(allocation);
+    new_overflow->len = aligned_count;
+
+    if (atomic_compare_exchange_strong(&overflow, &local_overflow, new_overflow)) {
+      local_overflow = new_overflow;
+    } else {
+      // Someone beat us to it. Deallocate and use theirs.
+      munmap(allocation, aligned_size);
+    }
+  }
+
+  size_t offset = idx - inline_fds;
+  if (local_overflow->len < offset) {
+    return nullptr;
+  }
+  return &local_overflow->entries[offset];
+}
+
 void __libc_init_fdsan() {
+  constexpr auto default_level = ANDROID_FDSAN_ERROR_LEVEL_WARN_ONCE;
   const prop_info* pi = __system_property_find(kFdsanPropertyName);
   if (!pi) {
-    android_fdsan_set_error_level(ANDROID_FDSAN_ERROR_LEVEL_DISABLED);
+    android_fdsan_set_error_level(default_level);
     return;
   }
   __system_property_read_callback(
@@ -69,13 +125,13 @@
             async_safe_format_log(ANDROID_LOG_ERROR, "libc",
                                   "debug.fdsan set to unknown value '%s', disabling", value);
           }
-          android_fdsan_set_error_level(ANDROID_FDSAN_ERROR_LEVEL_DISABLED);
+          android_fdsan_set_error_level(default_level);
         }
       },
       nullptr);
 }
 
-static FdTable<128>* GetFdTable() {
+static FdTable* GetFdTable() {
   if (!__libc_shared_globals) {
     return nullptr;
   }
@@ -83,6 +139,11 @@
   return &__libc_shared_globals->fd_table;
 }
 
+// Exposed to the platform to allow crash_dump to print out the fd table.
+extern "C" void* android_fdsan_get_fd_table() {
+  return GetFdTable();
+}
+
 static FdEntry* GetFdEntry(int fd) {
   if (fd < 0) {
     return nullptr;
@@ -117,20 +178,26 @@
 
   va_list va;
   va_start(va, fmt);
-  async_safe_fatal_va_list("fdsan", fmt, va);
+  if (error_level == ANDROID_FDSAN_ERROR_LEVEL_FATAL) {
+    async_safe_fatal_va_list("fdsan", fmt, va);
+  } else {
+    async_safe_format_log_va_list(ANDROID_LOG_ERROR, "fdsan", fmt, va);
+  }
   va_end(va);
 
   switch (error_level) {
     case ANDROID_FDSAN_ERROR_LEVEL_WARN_ONCE:
       atomic_compare_exchange_strong(&fd_table->error_level, &error_level,
                                      ANDROID_FDSAN_ERROR_LEVEL_DISABLED);
+    case ANDROID_FDSAN_ERROR_LEVEL_WARN_ALWAYS:
+      // DEBUGGER_SIGNAL
+      raise(__SIGRTMIN + 3);
       break;
 
     case ANDROID_FDSAN_ERROR_LEVEL_FATAL:
       abort();
 
     case ANDROID_FDSAN_ERROR_LEVEL_DISABLED:
-    case ANDROID_FDSAN_ERROR_LEVEL_WARN_ALWAYS:
       break;
   }
 }
@@ -184,7 +251,8 @@
 }
 
 static uint64_t __tag_to_owner(uint64_t tag) {
-  return tag;
+  // Lop off the most significant byte and sign extend.
+  return static_cast<uint64_t>(static_cast<int64_t>(tag << 8) >> 8);
 }
 
 int android_fdsan_close_with_tag(int fd, uint64_t expected_tag) {
@@ -200,21 +268,23 @@
     const char* actual_type = __tag_to_type(tag);
     uint64_t actual_owner = __tag_to_owner(tag);
     if (expected_tag && tag) {
-      fdsan_error("attempted to close file descriptor %d, expected to be owned by %s 0x%" PRIx64
-                  ", actually owned by %s 0x%" PRIx64,
-                  fd, expected_type, expected_owner, actual_type, actual_owner);
+      fdsan_error(
+          "attempted to close file descriptor %d, "
+          "expected to be owned by %s 0x%" PRIx64 ", actually owned by %s 0x%" PRIx64,
+          fd, expected_type, expected_owner, actual_type, actual_owner);
     } else if (expected_tag && !tag) {
-      fdsan_error("attempted to close file descriptor %d, expected to be owned by %s 0x%" PRIx64
-                  ", actually unowned",
-                  fd, expected_type, expected_owner);
+      fdsan_error(
+          "attempted to close file descriptor %d, "
+          "expected to be owned by %s 0x%" PRIx64 ", actually unowned",
+          fd, expected_type, expected_owner);
     } else if (!expected_tag && tag) {
       fdsan_error(
-          "attempted to close file descriptor %d, expected to be unowned, actually owned by %s "
-          "0x%" PRIx64,
+          "attempted to close file descriptor %d, "
+          "expected to be unowned, actually owned by %s 0x%" PRIx64,
           fd, actual_type, actual_owner);
     } else if (!expected_tag && !tag) {
       // This should never happen: our CAS failed, but expected == actual?
-      async_safe_fatal("fdsan atomic_compare_exchange_strong failed unexpectedly");
+      async_safe_fatal("fdsan atomic_compare_exchange_strong failed unexpectedly while closing");
     }
   }
 
@@ -234,16 +304,26 @@
 
   uint64_t tag = expected_tag;
   if (!atomic_compare_exchange_strong(&fde->close_tag, &tag, new_tag)) {
-    if (expected_tag == 0) {
+    if (expected_tag && tag) {
       fdsan_error(
-          "failed to take ownership of already-owned file descriptor: fd %d is owned by %s "
-          "%" PRIx64,
-          fd, __tag_to_type(tag), __tag_to_owner(tag));
-    } else {
+          "failed to exchange ownership of file descriptor: fd %d is "
+          "owned by %s 0x%" PRIx64 ", was expected to be owned by %s 0x%" PRIx64,
+          fd, __tag_to_type(tag), __tag_to_owner(tag), __tag_to_type(expected_tag),
+          __tag_to_owner(expected_tag));
+    } else if (expected_tag && !tag) {
       fdsan_error(
-          "failed to exchange ownership of unowned file descriptor: expected fd %d to be owned "
-          "by %s %" PRIx64,
+          "failed to exchange ownership of file descriptor: fd %d is "
+          "unowned, was expected to be owned by %s 0x%" PRIx64,
           fd, __tag_to_type(expected_tag), __tag_to_owner(expected_tag));
+    } else if (!expected_tag && tag) {
+      fdsan_error(
+          "failed to exchange ownership of file descriptor: fd %d is "
+          "owned by %s 0x%" PRIx64 ", was expected to be unowned",
+          fd, __tag_to_type(tag), __tag_to_owner(tag));
+    } else if (!expected_tag && !tag) {
+      // This should never happen: our CAS failed, but expected == actual?
+      async_safe_fatal(
+          "fdsan atomic_compare_exchange_strong failed unexpectedly while exchanging owner tag");
     }
   }
 }
diff --git a/libc/bionic/fortify.cpp b/libc/bionic/fortify.cpp
index 3bd9e68..4b94573 100644
--- a/libc/bionic/fortify.cpp
+++ b/libc/bionic/fortify.cpp
@@ -290,7 +290,7 @@
       return const_cast<char*>(p);
     }
     if (*p == '\0') {
-      return NULL;
+      return nullptr;
     }
   }
 }
@@ -387,7 +387,7 @@
 }
 
 char* __strrchr_chk(const char* p, int ch, size_t s_len) {
-  for (const char* save = NULL;; ++p, s_len--) {
+  for (const char* save = nullptr;; ++p, s_len--) {
     if (s_len == 0) {
       __fortify_fatal("strrchr: prevented read past end of buffer");
     }
diff --git a/libc/bionic/futimens.cpp b/libc/bionic/futimens.cpp
index 1ca8eb5..03f7e38 100644
--- a/libc/bionic/futimens.cpp
+++ b/libc/bionic/futimens.cpp
@@ -30,5 +30,5 @@
 #include <sys/stat.h>
 
 int futimens(int fd, const struct timespec times[2]) {
-  return utimensat(fd, NULL, times, 0);
+  return utimensat(fd, nullptr, times, 0);
 }
diff --git a/libc/bionic/getauxval.cpp b/libc/bionic/getauxval.cpp
index 22922b9..607e89c 100644
--- a/libc/bionic/getauxval.cpp
+++ b/libc/bionic/getauxval.cpp
@@ -33,7 +33,7 @@
 #include <elf.h>
 #include <errno.h>
 
-__LIBC_HIDDEN__ ElfW(auxv_t)* __libc_auxv = NULL;
+__LIBC_HIDDEN__ ElfW(auxv_t)* __libc_auxv = nullptr;
 
 extern "C" unsigned long int getauxval(unsigned long int type) {
   for (ElfW(auxv_t)* v = __libc_auxv; v->a_type != AT_NULL; ++v) {
diff --git a/libc/bionic/getcwd.cpp b/libc/bionic/getcwd.cpp
index 8ead91f..c42d4d5 100644
--- a/libc/bionic/getcwd.cpp
+++ b/libc/bionic/getcwd.cpp
@@ -35,23 +35,23 @@
 
 char* getcwd(char* buf, size_t size) {
   // You can't specify size 0 unless you're asking us to allocate for you.
-  if (buf != NULL && size == 0) {
+  if (buf != nullptr && size == 0) {
     errno = EINVAL;
-    return NULL;
+    return nullptr;
   }
 
   // Allocate a buffer if necessary.
-  char* allocated_buf = NULL;
+  char* allocated_buf = nullptr;
   size_t allocated_size = size;
-  if (buf == NULL) {
+  if (buf == nullptr) {
     if (size == 0) {
       // The Linux kernel won't return more than a page, so translate size 0 to 4KiB.
       // TODO: if we need to support paths longer than that, we'll have to walk the tree ourselves.
       allocated_size = getpagesize();
     }
     buf = allocated_buf = static_cast<char*>(malloc(allocated_size));
-    if (buf == NULL) {
-      return NULL;
+    if (buf == nullptr) {
+      return nullptr;
     }
   }
 
@@ -60,11 +60,11 @@
   if (rc == -1) {
     free(allocated_buf);
     // __getcwd set errno.
-    return NULL;
+    return nullptr;
   }
 
   // If we allocated a whole page, only return as large an allocation as necessary.
-  if (allocated_buf != NULL) {
+  if (allocated_buf != nullptr) {
     if (size == 0) {
       buf = strdup(allocated_buf);
       free(allocated_buf);
diff --git a/libc/bionic/grp_pwd.cpp b/libc/bionic/grp_pwd.cpp
index 1de8fc5..136a098 100644
--- a/libc/bionic/grp_pwd.cpp
+++ b/libc/bionic/grp_pwd.cpp
@@ -83,7 +83,7 @@
   // getpwnam_r and getpwuid_r don't modify errno, but library calls we
   // make might.
   ErrnoRestorer errno_restorer;
-  *result = NULL;
+  *result = nullptr;
 
   // Our implementation of getpwnam(3) and getpwuid(3) use thread-local
   // storage, so we can call them as long as we copy everything out
@@ -92,7 +92,7 @@
 
   // POSIX allows failure to find a match to be considered a non-error.
   // Reporting success (0) but with *result NULL is glibc's behavior.
-  if (src == NULL) {
+  if (src == nullptr) {
     return (errno == ENOENT) ? 0 : errno;
   }
 
@@ -114,9 +114,9 @@
 
   // pw_passwd and pw_gecos are non-POSIX and unused (always NULL) in bionic.
   // Note: On LP32, we define pw_gecos to pw_passwd since they're both NULL.
-  dst->pw_passwd = NULL;
+  dst->pw_passwd = nullptr;
 #if defined(__LP64__)
-  dst->pw_gecos = NULL;
+  dst->pw_gecos = nullptr;
 #endif
 
   // Copy the integral fields.
@@ -134,7 +134,7 @@
 
 int getpwuid_r(uid_t uid, passwd* pwd,
                char* buf, size_t byte_count, passwd** result) {
-  return do_getpw_r(0, NULL, uid, pwd, buf, byte_count, result);
+  return do_getpw_r(0, nullptr, uid, pwd, buf, byte_count, result);
 }
 
 static passwd* android_iinfo_to_passwd(passwd_state_t* state,
@@ -169,7 +169,7 @@
       return android_iinfo_to_passwd(state, android_ids + n);
     }
   }
-  return NULL;
+  return nullptr;
 }
 
 static passwd* android_name_to_passwd(passwd_state_t* state, const char* name) {
@@ -178,7 +178,7 @@
       return android_iinfo_to_passwd(state, android_ids + n);
     }
   }
-  return NULL;
+  return nullptr;
 }
 
 static group* android_id_to_group(group_state_t* state, unsigned id) {
@@ -187,7 +187,7 @@
       return android_iinfo_to_group(state, android_ids + n);
     }
   }
-  return NULL;
+  return nullptr;
 }
 
 static group* android_name_to_group(group_state_t* state, const char* name) {
@@ -196,7 +196,7 @@
       return android_iinfo_to_group(state, android_ids + n);
     }
   }
-  return NULL;
+  return nullptr;
 }
 
 // These are a list of the reserved app ranges, and should never contain anything below
@@ -474,7 +474,7 @@
 static passwd* app_id_to_passwd(uid_t uid, passwd_state_t* state) {
   if (uid < AID_APP_START || !is_valid_app_id(uid)) {
     errno = ENOENT;
-    return NULL;
+    return nullptr;
   }
 
   print_app_name_from_uid(uid, state->name_buffer_, sizeof(state->name_buffer_));
@@ -502,7 +502,7 @@
 static group* app_id_to_group(gid_t gid, group_state_t* state) {
   if (gid < AID_APP_START || !is_valid_app_id(gid)) {
     errno = ENOENT;
-    return NULL;
+    return nullptr;
   }
 
   print_app_name_from_gid(gid, state->group_name_buffer_, sizeof(state->group_name_buffer_));
@@ -516,17 +516,17 @@
 
 passwd* getpwuid(uid_t uid) { // NOLINT: implementing bad function.
   passwd_state_t* state = get_passwd_tls_buffer();
-  if (state == NULL) {
-    return NULL;
+  if (state == nullptr) {
+    return nullptr;
   }
 
   passwd* pw = android_id_to_passwd(state, uid);
-  if (pw != NULL) {
+  if (pw != nullptr) {
     return pw;
   }
   // Handle OEM range.
   pw = oem_id_to_passwd(uid, state);
-  if (pw != NULL) {
+  if (pw != nullptr) {
     return pw;
   }
   return app_id_to_passwd(uid, state);
@@ -534,12 +534,12 @@
 
 passwd* getpwnam(const char* login) { // NOLINT: implementing bad function.
   passwd_state_t* state = get_passwd_tls_buffer();
-  if (state == NULL) {
-    return NULL;
+  if (state == nullptr) {
+    return nullptr;
   }
 
   passwd* pw = android_name_to_passwd(state, login);
-  if (pw != NULL) {
+  if (pw != nullptr) {
     return pw;
   }
 
@@ -551,7 +551,7 @@
 
   // Handle OEM range.
   pw = oem_id_to_passwd(oem_id_from_name(login), state);
-  if (pw != NULL) {
+  if (pw != nullptr) {
     return pw;
   }
   return app_id_to_passwd(app_id_from_name(login, false), state);
@@ -594,11 +594,11 @@
 
 passwd* getpwent() {
   passwd_state_t* state = get_passwd_tls_buffer();
-  if (state == NULL) {
-    return NULL;
+  if (state == nullptr) {
+    return nullptr;
   }
   if (state->getpwent_idx < 0) {
-    return NULL;
+    return nullptr;
   }
 
   size_t start = 0;
@@ -630,17 +630,17 @@
   }
 
   // We are not reporting u1_a* and higher or we will be here forever
-  return NULL;
+  return nullptr;
 }
 
 static group* getgrgid_internal(gid_t gid, group_state_t* state) {
   group* grp = android_id_to_group(state, gid);
-  if (grp != NULL) {
+  if (grp != nullptr) {
     return grp;
   }
   // Handle OEM range.
   grp = oem_id_to_group(gid, state);
-  if (grp != NULL) {
+  if (grp != nullptr) {
     return grp;
   }
   return app_id_to_group(gid, state);
@@ -648,15 +648,15 @@
 
 group* getgrgid(gid_t gid) { // NOLINT: implementing bad function.
   group_state_t* state = __group_state();
-  if (state == NULL) {
-    return NULL;
+  if (state == nullptr) {
+    return nullptr;
   }
   return getgrgid_internal(gid, state);
 }
 
 static group* getgrnam_internal(const char* name, group_state_t* state) {
   group* grp = android_name_to_group(state, name);
-  if (grp != NULL) {
+  if (grp != nullptr) {
     return grp;
   }
 
@@ -668,7 +668,7 @@
 
   // Handle OEM range.
   grp = oem_id_to_group(oem_id_from_name(name), state);
-  if (grp != NULL) {
+  if (grp != nullptr) {
     return grp;
   }
   return app_id_to_group(app_id_from_name(name, true), state);
@@ -676,8 +676,8 @@
 
 group* getgrnam(const char* name) { // NOLINT: implementing bad function.
   group_state_t* state = __group_state();
-  if (state == NULL) {
-    return NULL;
+  if (state == nullptr) {
+    return nullptr;
   }
   return getgrnam_internal(name, state);
 }
@@ -685,7 +685,7 @@
 static int getgroup_r(bool by_name, const char* name, gid_t gid, struct group* grp, char* buf,
                       size_t buflen, struct group** result) {
   ErrnoRestorer errno_restorer;
-  *result = NULL;
+  *result = nullptr;
   char* p = reinterpret_cast<char*>(
       __BIONIC_ALIGN(reinterpret_cast<uintptr_t>(buf), sizeof(uintptr_t)));
   if (p + sizeof(group_state_t) > buf + buflen) {
@@ -694,7 +694,7 @@
   group_state_t* state = reinterpret_cast<group_state_t*>(p);
   init_group_state(state);
   group* retval = (by_name ? getgrnam_internal(name, state) : getgrgid_internal(gid, state));
-  if (retval != NULL) {
+  if (retval != nullptr) {
     *grp = *retval;
     *result = grp;
     return 0;
@@ -703,7 +703,7 @@
 }
 
 int getgrgid_r(gid_t gid, struct group* grp, char* buf, size_t buflen, struct group** result) {
-  return getgroup_r(false, NULL, gid, grp, buf, buflen, result);
+  return getgroup_r(false, nullptr, gid, grp, buf, buflen, result);
 }
 
 int getgrnam_r(const char* name, struct group* grp, char* buf, size_t buflen,
@@ -724,11 +724,11 @@
 
 group* getgrent() {
   group_state_t* state = get_group_tls_buffer();
-  if (state == NULL) {
-    return NULL;
+  if (state == nullptr) {
+    return nullptr;
   }
   if (state->getgrent_idx < 0) {
-    return NULL;
+    return nullptr;
   }
 
   size_t start = 0;
@@ -766,5 +766,5 @@
   }
 
   // We are not reporting u1_a* and higher or we will be here forever
-  return NULL;
+  return nullptr;
 }
diff --git a/libc/bionic/jemalloc_wrapper.cpp b/libc/bionic/jemalloc_wrapper.cpp
index 19081a4..812884c 100644
--- a/libc/bionic/jemalloc_wrapper.cpp
+++ b/libc/bionic/jemalloc_wrapper.cpp
@@ -25,7 +25,7 @@
   size_t pagesize = getpagesize();
   size_t size = __BIONIC_ALIGN(bytes, pagesize);
   if (size < bytes) {
-    return NULL;
+    return nullptr;
   }
   return je_memalign(pagesize, size);
 }
diff --git a/libc/bionic/legacy_32_bit_support.cpp b/libc/bionic/legacy_32_bit_support.cpp
index ba59e8e..2de1bc7 100644
--- a/libc/bionic/legacy_32_bit_support.cpp
+++ b/libc/bionic/legacy_32_bit_support.cpp
@@ -104,12 +104,12 @@
 
 // There is no getrlimit64 system call, so we need to use prlimit64.
 int getrlimit64(int resource, rlimit64* limits64) {
-  return prlimit64(0, resource, NULL, limits64);
+  return prlimit64(0, resource, nullptr, limits64);
 }
 
 // There is no setrlimit64 system call, so we need to use prlimit64.
 int setrlimit64(int resource, const rlimit64* limits64) {
-  return prlimit64(0, resource, limits64, NULL);
+  return prlimit64(0, resource, limits64, nullptr);
 }
 
 // There is no prlimit system call, so we need to use prlimit64.
diff --git a/libc/bionic/libc_init_common.cpp b/libc/bionic/libc_init_common.cpp
index 5c54341..f943402 100644
--- a/libc/bionic/libc_init_common.cpp
+++ b/libc/bionic/libc_init_common.cpp
@@ -346,7 +346,7 @@
   const Dtor minus1 = reinterpret_cast<Dtor>(static_cast<uintptr_t>(-1));
 
   // Sanity check - first entry must be -1.
-  if (array == NULL || fini_array[0] != minus1) {
+  if (array == nullptr || fini_array[0] != minus1) {
     return;
   }
 
@@ -355,7 +355,7 @@
 
   // Count the number of destructors.
   int count = 0;
-  while (fini_array[count] != NULL) {
+  while (fini_array[count] != nullptr) {
     ++count;
   }
 
diff --git a/libc/bionic/libc_init_dynamic.cpp b/libc/bionic/libc_init_dynamic.cpp
index c5606fb..0def359 100644
--- a/libc/bionic/libc_init_dynamic.cpp
+++ b/libc/bionic/libc_init_dynamic.cpp
@@ -130,7 +130,7 @@
   // so we need to ensure that these are called when the program exits
   // normally.
   if (structors->fini_array) {
-    __cxa_atexit(__libc_fini,structors->fini_array,NULL);
+    __cxa_atexit(__libc_fini,structors->fini_array,nullptr);
   }
 
   exit(slingshot(args.argc, args.argv, args.envp));
diff --git a/libc/bionic/libc_init_static.cpp b/libc/bionic/libc_init_static.cpp
index 3828def..9eb574a 100644
--- a/libc/bionic/libc_init_static.cpp
+++ b/libc/bionic/libc_init_static.cpp
@@ -117,8 +117,8 @@
   // The executable may have its own destructors listed in its .fini_array
   // so we need to ensure that these are called when the program exits
   // normally.
-  if (structors->fini_array != NULL) {
-    __cxa_atexit(__libc_fini,structors->fini_array,NULL);
+  if (structors->fini_array != nullptr) {
+    __cxa_atexit(__libc_fini,structors->fini_array,nullptr);
   }
 
   exit(slingshot(args.argc, args.argv, args.envp));
diff --git a/libc/bionic/libgen.cpp b/libc/bionic/libgen.cpp
index 33b46a1..b952822 100644
--- a/libc/bionic/libgen.cpp
+++ b/libc/bionic/libgen.cpp
@@ -37,13 +37,13 @@
 #include "bionic/pthread_internal.h"
 
 static int __basename_r(const char* path, char* buffer, size_t buffer_size) {
-  const char* startp = NULL;
-  const char* endp = NULL;
+  const char* startp = nullptr;
+  const char* endp = nullptr;
   int len;
   int result;
 
   // Empty or NULL string gets treated as ".".
-  if (path == NULL || *path == '\0') {
+  if (path == nullptr || *path == '\0') {
     startp = ".";
     len = 1;
     goto Exit;
@@ -72,7 +72,7 @@
 
  Exit:
   result = len;
-  if (buffer == NULL) {
+  if (buffer == nullptr) {
     return result;
   }
   if (len > static_cast<int>(buffer_size) - 1) {
@@ -94,12 +94,12 @@
 }
 
 static int __dirname_r(const char* path, char* buffer, size_t buffer_size) {
-  const char* endp = NULL;
+  const char* endp = nullptr;
   int len;
   int result;
 
   // Empty or NULL string gets treated as ".".
-  if (path == NULL || *path == '\0') {
+  if (path == nullptr || *path == '\0') {
     path = ".";
     len = 1;
     goto Exit;
@@ -135,7 +135,7 @@
     errno = ENAMETOOLONG;
     return -1;
   }
-  if (buffer == NULL) {
+  if (buffer == nullptr) {
     return result;
   }
 
@@ -160,11 +160,11 @@
 char* basename(const char* path) {
   char* buf = __get_bionic_tls().basename_buf;
   int rc = __basename_r(path, buf, sizeof(__get_bionic_tls().basename_buf));
-  return (rc < 0) ? NULL : buf;
+  return (rc < 0) ? nullptr : buf;
 }
 
 char* dirname(const char* path) {
   char* buf = __get_bionic_tls().dirname_buf;
   int rc = __dirname_r(path, buf, sizeof(__get_bionic_tls().dirname_buf));
-  return (rc < 0) ? NULL : buf;
+  return (rc < 0) ? nullptr : buf;
 }
diff --git a/libc/bionic/locale.cpp b/libc/bionic/locale.cpp
index 08c9401..2a5bcab 100644
--- a/libc/bionic/locale.cpp
+++ b/libc/bionic/locale.cpp
@@ -70,7 +70,7 @@
 };
 
 size_t __ctype_get_mb_cur_max() {
-  locale_t l = uselocale(NULL);
+  locale_t l = uselocale(nullptr);
   if (l == LC_GLOBAL_LOCALE) {
     return __bionic_current_locale_is_utf8 ? 4 : 1;
   } else {
@@ -142,14 +142,14 @@
 
 locale_t newlocale(int category_mask, const char* locale_name, locale_t /*base*/) {
   // Are 'category_mask' and 'locale_name' valid?
-  if ((category_mask & ~LC_ALL_MASK) != 0 || locale_name == NULL) {
+  if ((category_mask & ~LC_ALL_MASK) != 0 || locale_name == nullptr) {
     errno = EINVAL;
-    return NULL;
+    return nullptr;
   }
 
   if (!__is_supported_locale(locale_name)) {
     errno = ENOENT;
-    return NULL;
+    return nullptr;
   }
 
   return new __locale_t(__is_utf8_locale(locale_name) ? 4 : 1);
@@ -159,15 +159,15 @@
   // Is 'category' valid?
   if (category < LC_CTYPE || category > LC_IDENTIFICATION) {
     errno = EINVAL;
-    return NULL;
+    return nullptr;
   }
 
   // Caller wants to set the locale rather than just query?
-  if (locale_name != NULL) {
+  if (locale_name != nullptr) {
     if (!__is_supported_locale(locale_name)) {
       // We don't support this locale.
       errno = ENOENT;
-      return NULL;
+      return nullptr;
     }
     __bionic_current_locale_is_utf8 = __is_utf8_locale(locale_name);
   }
@@ -187,11 +187,11 @@
   locale_t old_locale = *get_current_locale_ptr();
 
   // If this is the first call to uselocale(3) on this thread, we return LC_GLOBAL_LOCALE.
-  if (old_locale == NULL) {
+  if (old_locale == nullptr) {
     old_locale = LC_GLOBAL_LOCALE;
   }
 
-  if (new_locale != NULL) {
+  if (new_locale != nullptr) {
     *get_current_locale_ptr() = new_locale;
   }
 
diff --git a/libc/bionic/mbrtoc16.cpp b/libc/bionic/mbrtoc16.cpp
index 2180516..acea426 100644
--- a/libc/bionic/mbrtoc16.cpp
+++ b/libc/bionic/mbrtoc16.cpp
@@ -60,10 +60,10 @@
 
 size_t mbrtoc16(char16_t* pc16, const char* s, size_t n, mbstate_t* ps) {
   static mbstate_t __private_state;
-  mbstate_t* state = (ps == NULL) ? &__private_state : ps;
+  mbstate_t* state = (ps == nullptr) ? &__private_state : ps;
 
   char16_t __private_pc16;
-  if (pc16 == NULL) {
+  if (pc16 == nullptr) {
     pc16 = &__private_pc16;
   }
 
diff --git a/libc/bionic/mbrtoc32.cpp b/libc/bionic/mbrtoc32.cpp
index 88a077c..644e542 100644
--- a/libc/bionic/mbrtoc32.cpp
+++ b/libc/bionic/mbrtoc32.cpp
@@ -35,7 +35,7 @@
 
 size_t mbrtoc32(char32_t* pc32, const char* s, size_t n, mbstate_t* ps) {
   static mbstate_t __private_state;
-  mbstate_t* state = (ps == NULL) ? &__private_state : ps;
+  mbstate_t* state = (ps == nullptr) ? &__private_state : ps;
 
   // We should never get to a state which has all 4 bytes of the sequence set.
   // Full state verification is done when decoding the sequence (after we have
@@ -44,10 +44,10 @@
     return mbstate_reset_and_return_illegal(EINVAL, state);
   }
 
-  if (s == NULL) {
+  if (s == nullptr) {
     s = "";
     n = 1;
-    pc32 = NULL;
+    pc32 = nullptr;
   }
 
   if (n == 0) {
@@ -57,7 +57,7 @@
   uint8_t ch;
   if (mbsinit(state) && (((ch = static_cast<uint8_t>(*s)) & ~0x7f) == 0)) {
     // Fast path for plain ASCII characters.
-    if (pc32 != NULL) {
+    if (pc32 != nullptr) {
       *pc32 = ch;
     }
     return (ch != '\0' ? 1 : 0);
@@ -131,7 +131,7 @@
     // Malformed input; invalid code points.
     return mbstate_reset_and_return_illegal(EILSEQ, state);
   }
-  if (pc32 != NULL) {
+  if (pc32 != nullptr) {
     *pc32 = c32;
   }
   return mbstate_reset_and_return(c32 == U'\0' ? 0 : bytes_wanted, state);
diff --git a/libc/bionic/mntent.cpp b/libc/bionic/mntent.cpp
index 92284ce..6a12e78 100644
--- a/libc/bionic/mntent.cpp
+++ b/libc/bionic/mntent.cpp
@@ -38,7 +38,7 @@
 
 mntent* getmntent_r(FILE* fp, struct mntent* e, char* buf, int buf_len) {
   memset(e, 0, sizeof(*e));
-  while (fgets(buf, buf_len, fp) != NULL) {
+  while (fgets(buf, buf_len, fp) != nullptr) {
     // Entries look like "proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0".
     // That is: mnt_fsname mnt_dir mnt_type mnt_opts 0 0.
     int fsname0, fsname1, dir0, dir1, type0, type1, opts0, opts1;
@@ -60,7 +60,7 @@
       return e;
     }
   }
-  return NULL;
+  return nullptr;
 }
 
 FILE* setmntent(const char* path, const char* mode) {
@@ -68,7 +68,7 @@
 }
 
 int endmntent(FILE* fp) {
-  if (fp != NULL) {
+  if (fp != nullptr) {
     fclose(fp);
   }
   return 1;
diff --git a/libc/bionic/new.cpp b/libc/bionic/new.cpp
index 9499ff5..a0da2fb 100644
--- a/libc/bionic/new.cpp
+++ b/libc/bionic/new.cpp
@@ -25,7 +25,7 @@
 
 void* operator new(std::size_t size) {
     void* p = malloc(size);
-    if (p == NULL) {
+    if (p == nullptr) {
         async_safe_fatal("new failed to allocate %zu bytes", size);
     }
     return p;
@@ -33,7 +33,7 @@
 
 void* operator new[](std::size_t size) {
     void* p = malloc(size);
-    if (p == NULL) {
+    if (p == nullptr) {
         async_safe_fatal("new[] failed to allocate %zu bytes", size);
     }
     return p;
diff --git a/libc/bionic/posix_timers.cpp b/libc/bionic/posix_timers.cpp
index 47d6db0..f522516 100644
--- a/libc/bionic/posix_timers.cpp
+++ b/libc/bionic/posix_timers.cpp
@@ -92,7 +92,7 @@
     } else if (si.si_code == SI_TKILL) {
       // This signal was sent because someone wants us to exit.
       free(timer);
-      return NULL;
+      return nullptr;
     }
   }
 }
@@ -105,11 +105,11 @@
 // http://pubs.opengroup.org/onlinepubs/9699919799/functions/timer_create.html
 int timer_create(clockid_t clock_id, sigevent* evp, timer_t* timer_id) {
   PosixTimer* timer = reinterpret_cast<PosixTimer*>(malloc(sizeof(PosixTimer)));
-  if (timer == NULL) {
+  if (timer == nullptr) {
     return -1;
   }
 
-  timer->sigev_notify = (evp == NULL) ? SIGEV_SIGNAL : evp->sigev_notify;
+  timer->sigev_notify = (evp == nullptr) ? SIGEV_SIGNAL : evp->sigev_notify;
 
   // If not a SIGEV_THREAD timer, the kernel can handle it without our help.
   if (timer->sigev_notify != SIGEV_THREAD) {
@@ -128,7 +128,7 @@
   atomic_init(&timer->deleted, false);
 
   // Check arguments that the kernel doesn't care about but we do.
-  if (timer->callback == NULL) {
+  if (timer->callback == nullptr) {
     free(timer);
     errno = EINVAL;
     return -1;
@@ -136,7 +136,7 @@
 
   // Create this timer's thread.
   pthread_attr_t thread_attributes;
-  if (evp->sigev_notify_attributes == NULL) {
+  if (evp->sigev_notify_attributes == nullptr) {
     pthread_attr_init(&thread_attributes);
   } else {
     thread_attributes = *reinterpret_cast<pthread_attr_t*>(evp->sigev_notify_attributes);
diff --git a/libc/bionic/pthread_attr.cpp b/libc/bionic/pthread_attr.cpp
index 93177f1..3c4b169 100644
--- a/libc/bionic/pthread_attr.cpp
+++ b/libc/bionic/pthread_attr.cpp
@@ -43,7 +43,7 @@
 __BIONIC_WEAK_FOR_NATIVE_BRIDGE
 int pthread_attr_init(pthread_attr_t* attr) {
   attr->flags = 0;
-  attr->stack_base = NULL;
+  attr->stack_base = nullptr;
   attr->stack_size = PTHREAD_STACK_SIZE_DEFAULT;
   attr->guard_size = PTHREAD_GUARD_SIZE;
   attr->sched_policy = SCHED_NORMAL;
@@ -206,7 +206,7 @@
     async_safe_fatal("couldn't open /proc/self/maps: %s", strerror(errno));
   }
   char line[BUFSIZ];
-  while (fgets(line, sizeof(line), fp) != NULL) {
+  while (fgets(line, sizeof(line), fp) != nullptr) {
     uintptr_t lo, hi;
     if (sscanf(line, "%" SCNxPTR "-%" SCNxPTR, &lo, &hi) == 2) {
       if (lo <= startstack && startstack <= hi) {
diff --git a/libc/bionic/pthread_cond.cpp b/libc/bionic/pthread_cond.cpp
index a42506a..9f0f8fa 100644
--- a/libc/bionic/pthread_cond.cpp
+++ b/libc/bionic/pthread_cond.cpp
@@ -136,7 +136,7 @@
   pthread_cond_internal_t* cond = __get_internal_cond(cond_interface);
 
   unsigned int init_state = 0;
-  if (attr != NULL) {
+  if (attr != nullptr) {
     init_state = (*attr & COND_FLAGS_MASK);
   }
   atomic_init(&cond->state, init_state);
diff --git a/libc/bionic/pthread_create.cpp b/libc/bionic/pthread_create.cpp
index 21a707b..c95d400 100644
--- a/libc/bionic/pthread_create.cpp
+++ b/libc/bionic/pthread_create.cpp
@@ -88,7 +88,7 @@
 
 void __init_alternate_signal_stack(pthread_internal_t* thread) {
   // Create and set an alternate signal stack.
-  void* stack_base = mmap(NULL, SIGNAL_STACK_SIZE, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
+  void* stack_base = mmap(nullptr, SIGNAL_STACK_SIZE, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
   if (stack_base != MAP_FAILED) {
     // Create a guard to catch stack overflows in signal handlers.
     if (mprotect(stack_base, PTHREAD_GUARD_SIZE, PROT_NONE) == -1) {
@@ -99,7 +99,7 @@
     ss.ss_sp = reinterpret_cast<uint8_t*>(stack_base) + PTHREAD_GUARD_SIZE;
     ss.ss_size = SIGNAL_STACK_SIZE - PTHREAD_GUARD_SIZE;
     ss.ss_flags = 0;
-    sigaltstack(&ss, NULL);
+    sigaltstack(&ss, nullptr);
     thread->alternate_signal_stack = stack_base;
 
     // We can only use const static allocated string for mapped region name, as Android kernel
@@ -166,13 +166,13 @@
   // Create a new private anonymous map.
   int prot = PROT_READ | PROT_WRITE;
   int flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE;
-  void* space = mmap(NULL, mmap_size, prot, flags, -1, 0);
+  void* space = mmap(nullptr, mmap_size, prot, flags, -1, 0);
   if (space == MAP_FAILED) {
     async_safe_format_log(ANDROID_LOG_WARN,
                       "libc",
                       "pthread_create failed: couldn't allocate %zu-bytes mapped space: %s",
                       mmap_size, strerror(errno));
-    return NULL;
+    return nullptr;
   }
 
   // Stack is at the lower end of mapped space, stack guard region is at the lower end of stack.
@@ -182,7 +182,7 @@
                           "pthread_create failed: couldn't mprotect PROT_NONE %zu-byte stack guard region: %s",
                           stack_guard_size, strerror(errno));
     munmap(space, mmap_size);
-    return NULL;
+    return nullptr;
   }
   prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, space, stack_guard_size, "thread stack guard");
 
@@ -193,7 +193,7 @@
   size_t mmap_size;
   uint8_t* stack_top;
 
-  if (attr->stack_base == NULL) {
+  if (attr->stack_base == nullptr) {
     // The caller didn't provide a stack, so allocate one.
     // Make sure the stack size and guard size are multiples of PAGE_SIZE.
     if (__builtin_add_overflow(attr->stack_size, attr->guard_size, &mmap_size)) return EAGAIN;
@@ -201,7 +201,7 @@
     mmap_size = __BIONIC_ALIGN(mmap_size, PAGE_SIZE);
     attr->guard_size = __BIONIC_ALIGN(attr->guard_size, PAGE_SIZE);
     attr->stack_base = __create_thread_mapped_space(mmap_size, attr->guard_size);
-    if (attr->stack_base == NULL) {
+    if (attr->stack_base == nullptr) {
       return EAGAIN;
     }
     stack_top = reinterpret_cast<uint8_t*>(attr->stack_base) + mmap_size;
@@ -261,7 +261,7 @@
 // going to run user code on it. We swap out the user's start routine for this and take advantage
 // of the regular thread teardown to free up resources.
 static void* __do_nothing(void*) {
-  return NULL;
+  return nullptr;
 }
 
 
@@ -271,15 +271,15 @@
   ErrnoRestorer errno_restorer;
 
   pthread_attr_t thread_attr;
-  if (attr == NULL) {
+  if (attr == nullptr) {
     pthread_attr_init(&thread_attr);
   } else {
     thread_attr = *attr;
-    attr = NULL; // Prevent misuse below.
+    attr = nullptr; // Prevent misuse below.
   }
 
-  pthread_internal_t* thread = NULL;
-  void* child_stack = NULL;
+  pthread_internal_t* thread = nullptr;
+  void* child_stack = nullptr;
   int result = __allocate_thread(&thread_attr, &thread, &child_stack);
   if (result != 0) {
     return result;
diff --git a/libc/bionic/pthread_detach.cpp b/libc/bionic/pthread_detach.cpp
index 011e6c6..c2e4127 100644
--- a/libc/bionic/pthread_detach.cpp
+++ b/libc/bionic/pthread_detach.cpp
@@ -35,7 +35,7 @@
 __BIONIC_WEAK_FOR_NATIVE_BRIDGE
 int pthread_detach(pthread_t t) {
   pthread_internal_t* thread = __pthread_internal_find(t);
-  if (thread == NULL) {
+  if (thread == nullptr) {
     return ESRCH;
   }
 
@@ -48,7 +48,7 @@
     return 0;
   } else if (old_state == THREAD_EXITED_NOT_JOINED) {
     // Use pthread_join to clean it up.
-    return pthread_join(t, NULL);
+    return pthread_join(t, nullptr);
   }
   return EINVAL;
 }
diff --git a/libc/bionic/pthread_exit.cpp b/libc/bionic/pthread_exit.cpp
index f1b65fd..ac5d429 100644
--- a/libc/bionic/pthread_exit.cpp
+++ b/libc/bionic/pthread_exit.cpp
@@ -91,16 +91,16 @@
   // space (see pthread_key_delete).
   pthread_key_clean_all();
 
-  if (thread->alternate_signal_stack != NULL) {
+  if (thread->alternate_signal_stack != nullptr) {
     // Tell the kernel to stop using the alternate signal stack.
     stack_t ss;
     memset(&ss, 0, sizeof(ss));
     ss.ss_flags = SS_DISABLE;
-    sigaltstack(&ss, NULL);
+    sigaltstack(&ss, nullptr);
 
     // Free it.
     munmap(thread->alternate_signal_stack, SIGNAL_STACK_SIZE);
-    thread->alternate_signal_stack = NULL;
+    thread->alternate_signal_stack = nullptr;
   }
 
   ThreadJoinState old_state = THREAD_NOT_JOINED;
@@ -113,7 +113,7 @@
     // So we can free mapped space, which includes pthread_internal_t and thread stack.
     // First make sure that the kernel does not try to clear the tid field
     // because we'll have freed the memory before the thread actually exits.
-    __set_tid_address(NULL);
+    __set_tid_address(nullptr);
 
     // pthread_internal_t is freed below with stack, not here.
     __pthread_internal_remove(thread);
diff --git a/libc/bionic/pthread_join.cpp b/libc/bionic/pthread_join.cpp
index be76c20..9aad458 100644
--- a/libc/bionic/pthread_join.cpp
+++ b/libc/bionic/pthread_join.cpp
@@ -39,7 +39,7 @@
   }
 
   pthread_internal_t* thread = __pthread_internal_find(t);
-  if (thread == NULL) {
+  if (thread == nullptr) {
     return ESRCH;
   }
 
@@ -60,7 +60,7 @@
 
   // Wait for the thread to actually exit, if it hasn't already.
   while (*tid_ptr != 0) {
-    __futex_wait(tid_ptr, tid, NULL);
+    __futex_wait(tid_ptr, tid, nullptr);
   }
 
   if (return_value) {
diff --git a/libc/bionic/pthread_key.cpp b/libc/bionic/pthread_key.cpp
index baff9cc..f3878a6 100644
--- a/libc/bionic/pthread_key.cpp
+++ b/libc/bionic/pthread_key.cpp
@@ -79,7 +79,7 @@
     size_t called_destructor_count = 0;
     for (size_t i = 0; i < BIONIC_PTHREAD_KEY_COUNT; ++i) {
       uintptr_t seq = atomic_load_explicit(&key_map[i].seq, memory_order_relaxed);
-      if (SeqOfKeyInUse(seq) && seq == key_data[i].seq && key_data[i].data != NULL) {
+      if (SeqOfKeyInUse(seq) && seq == key_data[i].seq && key_data[i].data != nullptr) {
         // Other threads may be calling pthread_key_delete/pthread_key_create while current thread
         // is exiting. So we need to ensure we read the right key_destructor.
         // We can rely on a user-established happens-before relationship between the creation and
@@ -89,7 +89,7 @@
         // right key_destructor, or the sequence number must have changed when we reread it below.
         key_destructor_t key_destructor = reinterpret_cast<key_destructor_t>(
           atomic_load_explicit(&key_map[i].key_destructor, memory_order_relaxed));
-        if (key_destructor == NULL) {
+        if (key_destructor == nullptr) {
           continue;
         }
         atomic_thread_fence(memory_order_acquire);
@@ -102,7 +102,7 @@
         // We don't do this if 'key_destructor == NULL' just in case another destructor
         // function is responsible for manually releasing the corresponding data.
         void* data = key_data[i].data;
-        key_data[i].data = NULL;
+        key_data[i].data = nullptr;
 
         (*key_destructor)(data);
         ++called_destructor_count;
@@ -154,7 +154,7 @@
 __BIONIC_WEAK_FOR_NATIVE_BRIDGE
 void* pthread_getspecific(pthread_key_t key) {
   if (__predict_false(!KeyInValidRange(key))) {
-    return NULL;
+    return nullptr;
   }
   key &= ~KEY_VALID_FLAG;
   uintptr_t seq = atomic_load_explicit(&key_map[key].seq, memory_order_relaxed);
@@ -166,8 +166,8 @@
   }
   // We arrive here when current thread holds the seq of an deleted pthread key. So the
   // data is for the deleted pthread key, and should be cleared.
-  data->data = NULL;
-  return NULL;
+  data->data = nullptr;
+  return nullptr;
 }
 
 __BIONIC_WEAK_FOR_NATIVE_BRIDGE
diff --git a/libc/bionic/pthread_mutex.cpp b/libc/bionic/pthread_mutex.cpp
index 7f48972..fda0b93 100644
--- a/libc/bionic/pthread_mutex.cpp
+++ b/libc/bionic/pthread_mutex.cpp
@@ -502,7 +502,7 @@
 
     memset(mutex, 0, sizeof(pthread_mutex_internal_t));
 
-    if (__predict_true(attr == NULL)) {
+    if (__predict_true(attr == nullptr)) {
         atomic_init(&mutex->state, MUTEX_TYPE_BITS_NORMAL);
         return 0;
     }
@@ -800,7 +800,7 @@
     // Some apps depend on being able to pass NULL as a mutex and get EINVAL
     // back. Don't need to worry about it for LP64 since the ABI is brand new,
     // but keep compatibility for LP32. http://b/19995172.
-    if (mutex_interface == NULL) {
+    if (mutex_interface == nullptr) {
         return EINVAL;
     }
 #endif
@@ -834,7 +834,7 @@
     // Some apps depend on being able to pass NULL as a mutex and get EINVAL
     // back. Don't need to worry about it for LP64 since the ABI is brand new,
     // but keep compatibility for LP32. http://b/19995172.
-    if (mutex_interface == NULL) {
+    if (mutex_interface == nullptr) {
         return EINVAL;
     }
 #endif
diff --git a/libc/bionic/pthread_rwlock.cpp b/libc/bionic/pthread_rwlock.cpp
index 4f4c461..2b9be98 100644
--- a/libc/bionic/pthread_rwlock.cpp
+++ b/libc/bionic/pthread_rwlock.cpp
@@ -228,7 +228,7 @@
 
   memset(rwlock, 0, sizeof(pthread_rwlock_internal_t));
 
-  if (__predict_false(attr != NULL)) {
+  if (__predict_false(attr != nullptr)) {
     rwlock->pshared = __rwlockattr_getpshared(attr);
     int kind = __rwlockattr_getkind(attr);
     switch (kind) {
diff --git a/libc/bionic/pty.cpp b/libc/bionic/pty.cpp
index 599cbd2..71e14d9 100644
--- a/libc/bionic/pty.cpp
+++ b/libc/bionic/pty.cpp
@@ -55,11 +55,11 @@
   bionic_tls& tls = __get_bionic_tls();
   char* buf = tls.ptsname_buf;
   int error = ptsname_r(fd, buf, sizeof(tls.ptsname_buf));
-  return (error == 0) ? buf : NULL;
+  return (error == 0) ? buf : nullptr;
 }
 
 int ptsname_r(int fd, char* buf, size_t len) {
-  if (buf == NULL) {
+  if (buf == nullptr) {
     errno = EINVAL;
     return errno;
   }
@@ -82,11 +82,11 @@
   bionic_tls& tls = __get_bionic_tls();
   char* buf = tls.ttyname_buf;
   int error = ttyname_r(fd, buf, sizeof(tls.ttyname_buf));
-  return (error == 0) ? buf : NULL;
+  return (error == 0) ? buf : nullptr;
 }
 
 int ttyname_r(int fd, char* buf, size_t len) {
-  if (buf == NULL) {
+  if (buf == nullptr) {
     errno = EINVAL;
     return errno;
   }
@@ -124,7 +124,7 @@
   }
 
   char buf[32];
-  if (name == NULL) {
+  if (name == nullptr) {
     name = buf;
   }
   if (ptsname_r(*master, name, sizeof(buf)) != 0) {
@@ -138,10 +138,10 @@
     return -1;
   }
 
-  if (t != NULL) {
+  if (t != nullptr) {
     tcsetattr(*slave, TCSAFLUSH, t);
   }
-  if (ws != NULL) {
+  if (ws != nullptr) {
     ioctl(*slave, TIOCSWINSZ, ws);
   }
 
@@ -181,7 +181,7 @@
 int login_tty(int fd) {
   setsid();
 
-  if (ioctl(fd, TIOCSCTTY, NULL) == -1) {
+  if (ioctl(fd, TIOCSCTTY, nullptr) == -1) {
     return -1;
   }
 
diff --git a/libc/bionic/reboot.cpp b/libc/bionic/reboot.cpp
index 9cf4411..b0a1f97 100644
--- a/libc/bionic/reboot.cpp
+++ b/libc/bionic/reboot.cpp
@@ -32,5 +32,5 @@
 extern "C" int __reboot(int, int, int, void*);
 
 int reboot(int mode) {
-  return __reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, mode, NULL);
+  return __reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, mode, nullptr);
 }
diff --git a/libc/bionic/recv.cpp b/libc/bionic/recv.cpp
index 60f264d..32a7a72 100644
--- a/libc/bionic/recv.cpp
+++ b/libc/bionic/recv.cpp
@@ -29,5 +29,5 @@
 #include <sys/socket.h>
 
 ssize_t recv(int socket, void *buf, size_t len, int flags) {
-  return recvfrom(socket, buf, len, flags, NULL, 0);
+  return recvfrom(socket, buf, len, flags, nullptr, nullptr);
 }
diff --git a/libc/bionic/sched_getcpu.cpp b/libc/bionic/sched_getcpu.cpp
index 1f92e54..f245fba 100644
--- a/libc/bionic/sched_getcpu.cpp
+++ b/libc/bionic/sched_getcpu.cpp
@@ -33,7 +33,7 @@
 
 int sched_getcpu() {
   unsigned cpu;
-  int rc = __getcpu(&cpu, NULL, NULL);
+  int rc = __getcpu(&cpu, nullptr, nullptr);
   if (rc == -1) {
     return -1; // errno is already set.
   }
diff --git a/libc/bionic/send.cpp b/libc/bionic/send.cpp
index 2e5d457..7106c43 100644
--- a/libc/bionic/send.cpp
+++ b/libc/bionic/send.cpp
@@ -29,5 +29,5 @@
 #include <sys/socket.h>
 
 ssize_t send(int socket, const void* buf, size_t len, int flags) {
-  return sendto(socket, buf, len, flags, NULL, 0);
+  return sendto(socket, buf, len, flags, nullptr, 0);
 }
diff --git a/libc/bionic/sigaction.cpp b/libc/bionic/sigaction.cpp
index 41923cf..fb57d1c 100644
--- a/libc/bionic/sigaction.cpp
+++ b/libc/bionic/sigaction.cpp
@@ -40,7 +40,7 @@
 
 int sigaction(int signal, const struct sigaction* bionic_new_action, struct sigaction* bionic_old_action) {
   __kernel_sigaction kernel_new_action;
-  if (bionic_new_action != NULL) {
+  if (bionic_new_action != nullptr) {
     kernel_new_action.sa_flags = bionic_new_action->sa_flags;
     kernel_new_action.sa_handler = bionic_new_action->sa_handler;
     kernel_new_action.sa_mask = filter_reserved_signals(bionic_new_action->sa_mask);
@@ -62,11 +62,11 @@
 
   __kernel_sigaction kernel_old_action;
   int result = __rt_sigaction(signal,
-                              (bionic_new_action != NULL) ? &kernel_new_action : NULL,
-                              (bionic_old_action != NULL) ? &kernel_old_action : NULL,
+                              (bionic_new_action != nullptr) ? &kernel_new_action : nullptr,
+                              (bionic_old_action != nullptr) ? &kernel_old_action : nullptr,
                               sizeof(sigset_t));
 
-  if (bionic_old_action != NULL) {
+  if (bionic_old_action != nullptr) {
     bionic_old_action->sa_flags = kernel_old_action.sa_flags;
     bionic_old_action->sa_handler = kernel_old_action.sa_handler;
     bionic_old_action->sa_mask = kernel_old_action.sa_mask;
diff --git a/libc/bionic/strerror_r.cpp b/libc/bionic/strerror_r.cpp
index dad3fb3..1cf2abc 100644
--- a/libc/bionic/strerror_r.cpp
+++ b/libc/bionic/strerror_r.cpp
@@ -22,18 +22,18 @@
 };
 
 static const char* __code_string_lookup(const Pair* strings, int code) {
-  for (size_t i = 0; strings[i].msg != NULL; ++i) {
+  for (size_t i = 0; strings[i].msg != nullptr; ++i) {
     if (strings[i].code == code) {
       return strings[i].msg;
     }
   }
-  return NULL;
+  return nullptr;
 }
 
 static const Pair _sys_error_strings[] = {
 #define  __BIONIC_ERRDEF(x,y,z)  { x, z },
 #include "private/bionic_errdefs.h"
-  { 0, NULL }
+  { 0, nullptr }
 };
 
 extern "C" __LIBC_HIDDEN__ const char* __strerror_lookup(int error_number) {
@@ -43,7 +43,7 @@
 static const Pair _sys_signal_strings[] = {
 #define  __BIONIC_SIGDEF(signal_number, signal_description)  { signal_number, signal_description },
 #include "private/bionic_sigdefs.h"
-  { 0, NULL }
+  { 0, nullptr }
 };
 
 extern "C" __LIBC_HIDDEN__ const char* __strsignal_lookup(int signal_number) {
@@ -55,7 +55,7 @@
   size_t length;
 
   const char* error_name = __strerror_lookup(error_number);
-  if (error_name != NULL) {
+  if (error_name != nullptr) {
     length = strlcpy(buf, error_name, buf_len);
   } else {
     length = async_safe_format_buffer(buf, buf_len, "Unknown error %d", error_number);
@@ -76,7 +76,7 @@
 
 extern "C" __LIBC_HIDDEN__ const char* __strsignal(int signal_number, char* buf, size_t buf_len) {
   const char* signal_name = __strsignal_lookup(signal_number);
-  if (signal_name != NULL) {
+  if (signal_name != nullptr) {
     return signal_name;
   }
 
@@ -87,7 +87,7 @@
   }
   size_t length = snprintf(buf, buf_len, "%s signal %d", prefix, signal_number);
   if (length >= buf_len) {
-    return NULL;
+    return nullptr;
   }
   return buf;
 }
diff --git a/libc/bionic/strsignal.cpp b/libc/bionic/strsignal.cpp
index 81a8f95..1cdfec1 100644
--- a/libc/bionic/strsignal.cpp
+++ b/libc/bionic/strsignal.cpp
@@ -36,7 +36,7 @@
 char* strsignal(int signal_number) {
   // Just return the original constant in the easy cases.
   char* result = const_cast<char*>(__strsignal_lookup(signal_number));
-  if (result != NULL) {
+  if (result != nullptr) {
     return result;
   }
 
diff --git a/libc/bionic/sysinfo.cpp b/libc/bionic/sysinfo.cpp
index 947de95..1d1070e 100644
--- a/libc/bionic/sysinfo.cpp
+++ b/libc/bionic/sysinfo.cpp
@@ -53,7 +53,7 @@
 
   int result = 0;
   dirent* entry;
-  while ((entry = reader.ReadEntry()) != NULL) {
+  while ((entry = reader.ReadEntry()) != nullptr) {
     if (entry->d_type == DT_DIR && __matches_cpuN(entry->d_name)) {
       ++result;
     }
diff --git a/libc/bionic/syslog.cpp b/libc/bionic/syslog.cpp
index 9424573..d1a0c5b 100644
--- a/libc/bionic/syslog.cpp
+++ b/libc/bionic/syslog.cpp
@@ -21,11 +21,11 @@
 
 #include <async_safe/log.h>
 
-static const char* syslog_log_tag = NULL;
+static const char* syslog_log_tag = nullptr;
 static int syslog_priority_mask = 0xff;
 
 void closelog() {
-  syslog_log_tag = NULL;
+  syslog_log_tag = nullptr;
 }
 
 void openlog(const char* log_tag, int /*options*/, int /*facility*/) {
@@ -58,7 +58,7 @@
 
   // What's our log tag?
   const char* log_tag = syslog_log_tag;
-  if (log_tag == NULL) {
+  if (log_tag == nullptr) {
     log_tag = getprogname();
   }
 
@@ -78,7 +78,7 @@
   // glibc's printf family support %m directly, but our BSD-based one doesn't.
   // If the format string seems to contain "%m", rewrite it.
   const char* log_fmt = fmt;
-  if (strstr(fmt, "%m") != NULL) {
+  if (strstr(fmt, "%m") != nullptr) {
     size_t dst_len = 1024;
     char* dst = reinterpret_cast<char*>(malloc(dst_len));
     log_fmt = dst;
diff --git a/libc/bionic/system_property_api.cpp b/libc/bionic/system_property_api.cpp
index 10d1bb3..051bc4c 100644
--- a/libc/bionic/system_property_api.cpp
+++ b/libc/bionic/system_property_api.cpp
@@ -48,8 +48,6 @@
   return system_properties.Init(PROP_FILENAME) ? 0 : -1;
 }
 
-// This was previously for testing, but now that SystemProperties is its own testable class,
-// there is never a reason to call this function.
 __BIONIC_WEAK_FOR_NATIVE_BRIDGE
 int __system_property_set_filename(const char*) {
   return -1;
diff --git a/libc/bionic/tdestroy.cpp b/libc/bionic/tdestroy.cpp
index 2968ff9..6606c56 100644
--- a/libc/bionic/tdestroy.cpp
+++ b/libc/bionic/tdestroy.cpp
@@ -27,7 +27,7 @@
 // This is a GNU extension, not available from BSD.
 void tdestroy(void* root, void (*destroy_func)(void*)) {
   node_t* root_node = reinterpret_cast<node_t*>(root);
-  if (root_node == NULL) {
+  if (root_node == nullptr) {
     return;
   }
   if (root_node->llink) {
diff --git a/libc/bionic/tmpfile.cpp b/libc/bionic/tmpfile.cpp
index bda3566..4378e84 100644
--- a/libc/bionic/tmpfile.cpp
+++ b/libc/bionic/tmpfile.cpp
@@ -42,9 +42,9 @@
 #include "private/ScopedSignalBlocker.h"
 
 static FILE* __tmpfile_dir(const char* tmp_dir) {
-  char* path = NULL;
+  char* path = nullptr;
   if (asprintf(&path, "%s/tmp.XXXXXXXXXX", tmp_dir) == -1) {
-    return NULL;
+    return nullptr;
   }
 
   int fd;
@@ -53,7 +53,7 @@
     fd = mkstemp(path);
     if (fd == -1) {
       free(path);
-      return NULL;
+      return nullptr;
     }
 
     // Unlink the file now so that it's removed when closed.
@@ -67,20 +67,20 @@
     if (rc == -1) {
       ErrnoRestorer errno_restorer;
       close(fd);
-      return NULL;
+      return nullptr;
     }
   }
 
   // Turn the file descriptor into a FILE*.
   FILE* fp = fdopen(fd, "w+");
-  if (fp != NULL) {
+  if (fp != nullptr) {
     return fp;
   }
 
   // Failure. Clean up. We already unlinked, so we just need to close.
   ErrnoRestorer errno_restorer;
   close(fd);
-  return NULL;
+  return nullptr;
 }
 
 FILE* tmpfile() {
@@ -90,7 +90,7 @@
   // This means we can't do the usual trick of calling unlink before handing the file back.
 
   FILE* fp = __tmpfile_dir("/data/local/tmp");
-  if (fp == NULL) {
+  if (fp == nullptr) {
     // P_tmpdir is "/tmp/", but POSIX explicitly says that tmpdir(3) should try P_tmpdir before
     // giving up. This is potentially useful for bionic on the host anyway.
     fp = __tmpfile_dir(P_tmpdir);
diff --git a/libc/bionic/wait.cpp b/libc/bionic/wait.cpp
index e5c93aa..3e59f51 100644
--- a/libc/bionic/wait.cpp
+++ b/libc/bionic/wait.cpp
@@ -32,14 +32,14 @@
 extern "C" int __waitid(idtype_t which, id_t id, siginfo_t* info, int options, struct rusage* ru);
 
 pid_t wait(int* status) {
-  return wait4(-1, status, 0, NULL);
+  return wait4(-1, status, 0, nullptr);
 }
 
 pid_t waitpid(pid_t pid, int* status, int options) {
-  return wait4(pid, status, options, NULL);
+  return wait4(pid, status, options, nullptr);
 }
 
 int waitid(idtype_t which, id_t id, siginfo_t* info, int options) {
   // The system call takes an optional struct rusage that we don't need.
-  return __waitid(which, id, info, options, NULL);
+  return __waitid(which, id, info, options, nullptr);
 }
diff --git a/libc/bionic/wchar.cpp b/libc/bionic/wchar.cpp
index 62023d6..dabe824 100644
--- a/libc/bionic/wchar.cpp
+++ b/libc/bionic/wchar.cpp
@@ -54,12 +54,12 @@
 //
 
 int mbsinit(const mbstate_t* ps) {
-  return (ps == NULL || (*(reinterpret_cast<const uint32_t*>(ps->__seq)) == 0));
+  return (ps == nullptr || (*(reinterpret_cast<const uint32_t*>(ps->__seq)) == 0));
 }
 
 size_t mbrtowc(wchar_t* pwc, const char* s, size_t n, mbstate_t* ps) {
   static mbstate_t __private_state;
-  mbstate_t* state = (ps == NULL) ? &__private_state : ps;
+  mbstate_t* state = (ps == nullptr) ? &__private_state : ps;
 
   // Our wchar_t is UTF-32.
   return mbrtoc32(reinterpret_cast<char32_t*>(pwc), s, n, state);
@@ -67,7 +67,7 @@
 
 size_t mbsnrtowcs(wchar_t* dst, const char** src, size_t nmc, size_t len, mbstate_t* ps) {
   static mbstate_t __private_state;
-  mbstate_t* state = (ps == NULL) ? &__private_state : ps;
+  mbstate_t* state = (ps == nullptr) ? &__private_state : ps;
   size_t i, o, r;
 
   // The fast paths in the loops below are not safe if an ASCII
@@ -78,7 +78,7 @@
   }
 
   // Measure only?
-  if (dst == NULL) {
+  if (dst == nullptr) {
     for (i = o = 0; i < nmc; i += r, o++) {
       if (static_cast<uint8_t>((*src)[i]) < 0x80) {
         // Fast path for plain ASCII characters.
@@ -87,7 +87,7 @@
         }
         r = 1;
       } else {
-        r = mbrtowc(NULL, *src + i, nmc - i, state);
+        r = mbrtowc(nullptr, *src + i, nmc - i, state);
         if (r == __MB_ERR_ILLEGAL_SEQUENCE) {
           return mbstate_reset_and_return_illegal(EILSEQ, state);
         }
@@ -123,7 +123,7 @@
         return mbstate_reset_and_return_illegal(EILSEQ, state);
       }
       if (r == 0) {
-        *src = NULL;
+        *src = nullptr;
         return mbstate_reset_and_return(o, state);
       }
     }
@@ -138,7 +138,7 @@
 
 size_t wcrtomb(char* s, wchar_t wc, mbstate_t* ps) {
   static mbstate_t __private_state;
-  mbstate_t* state = (ps == NULL) ? &__private_state : ps;
+  mbstate_t* state = (ps == nullptr) ? &__private_state : ps;
 
   // Our wchar_t is UTF-32.
   return c32rtomb(s, static_cast<char32_t>(wc), state);
@@ -146,7 +146,7 @@
 
 size_t wcsnrtombs(char* dst, const wchar_t** src, size_t nwc, size_t len, mbstate_t* ps) {
   static mbstate_t __private_state;
-  mbstate_t* state = (ps == NULL) ? &__private_state : ps;
+  mbstate_t* state = (ps == nullptr) ? &__private_state : ps;
 
   if (!mbsinit(state)) {
     return mbstate_reset_and_return_illegal(EILSEQ, state);
@@ -154,7 +154,7 @@
 
   char buf[MB_LEN_MAX];
   size_t i, o, r;
-  if (dst == NULL) {
+  if (dst == nullptr) {
     for (i = o = 0; i < nwc; i++, o += r) {
       wchar_t wc = (*src)[i];
       if (static_cast<uint32_t>(wc) < 0x80) {
@@ -179,7 +179,7 @@
       // Fast path for plain ASCII characters.
       dst[o] = wc;
       if (wc == 0) {
-        *src = NULL;
+        *src = nullptr;
         return o;
       }
       r = 1;
diff --git a/libc/bionic/wcstod.cpp b/libc/bionic/wcstod.cpp
index 41a94fb..75a59f5 100644
--- a/libc/bionic/wcstod.cpp
+++ b/libc/bionic/wcstod.cpp
@@ -62,7 +62,7 @@
   f._bf._base = f._p = reinterpret_cast<unsigned char*>(ascii_str);
   f._bf._size = f._r = max_len;
   f._read = [](void*, char*, int) { return 0; }; // aka `eofread`, aka "no more data".
-  f._lb._base = NULL;
+  f._lb._base = nullptr;
 
   // Ask `parsefloat` to look at the same data more carefully.
 
diff --git a/libc/bionic/wctype.cpp b/libc/bionic/wctype.cpp
index 05b6e19..6e33b6c 100644
--- a/libc/bionic/wctype.cpp
+++ b/libc/bionic/wctype.cpp
@@ -155,7 +155,7 @@
 wctrans_t wctrans(const char* name) {
   if (strcmp(name, "tolower") == 0) return wctrans_tolower;
   if (strcmp(name, "toupper") == 0) return wctrans_toupper;
-  return 0;
+  return nullptr;
 }
 
 wctrans_t wctrans_l(const char* name, locale_t) {
diff --git a/libc/include/bits/elf_arm.h b/libc/include/bits/elf_arm.h
index 320feaf..08fe1d5 100644
--- a/libc/include/bits/elf_arm.h
+++ b/libc/include/bits/elf_arm.h
@@ -43,7 +43,8 @@
 #define R_ARM_THM_PC22		10
 #define R_ARM_THM_PC8		11
 #define R_ARM_AMP_VCALL9	12
-#define R_ARM_SWI24		13
+#define R_ARM_SWI24		13	/* obsolete static relocation */
+#define R_ARM_TLS_DESC		13	/* dynamic relocation */
 #define R_ARM_THM_SWI8		14
 #define R_ARM_XPC25		15
 #define R_ARM_THM_XPC22		16
diff --git a/libc/include/bits/elf_arm64.h b/libc/include/bits/elf_arm64.h
index acd9c70..d838c0b 100644
--- a/libc/include/bits/elf_arm64.h
+++ b/libc/include/bits/elf_arm64.h
@@ -83,8 +83,10 @@
 #define R_AARCH64_GLOB_DAT              1025    /* Create GOT entry.  */
 #define R_AARCH64_JUMP_SLOT             1026    /* Create PLT entry.  */
 #define R_AARCH64_RELATIVE              1027    /* Adjust by program base.  */
-#define R_AARCH64_TLS_TPREL64           1030
-#define R_AARCH64_TLS_DTPREL32          1031
+#define R_AARCH64_TLS_DTPREL64          1028    /* Module-relative offset. */
+#define R_AARCH64_TLS_DTPMOD64          1029    /* Module index. */
+#define R_AARCH64_TLS_TPREL64           1030    /* TP-relative offset. */
+#define R_AARCH64_TLSDESC               1031    /* 16-byte descriptor: resolver func + arg. */
 #define R_AARCH64_IRELATIVE             1032
 
 #endif /* _AARCH64_ELF_MACHDEP_H_ */
diff --git a/libc/include/math.h b/libc/include/math.h
index 57ca260..beb66a7 100644
--- a/libc/include/math.h
+++ b/libc/include/math.h
@@ -384,6 +384,9 @@
 float gammaf_r(float __x, int* __sign);
 float lgammaf_r(float __x, int* __sign);
 float significandf(float __x);
+void sincos(double __x, double* __sin, double* __cos);
+void sincosf(float __x, float* __sin, float* __cos);
+void sincosl(long double __x, long double* __sin, long double* __cos);
 #endif
 
 /* GNU extensions. */
@@ -402,9 +405,6 @@
 #define M_2_SQRTPIl     1.128379167095512573896158903121545172L /* 2/sqrt(pi) */
 #define M_SQRT2l        1.414213562373095048801688724209698079L /* sqrt(2) */
 #define M_SQRT1_2l      0.707106781186547524400844362104849039L /* 1/sqrt(2) */
-void sincos(double __x, double* __sin, double* __cos);
-void sincosf(float __x, float* __sin, float* __cos);
-void sincosl(long double __x, long double* __sin, long double* __cos);
 #endif
 
 __END_DECLS
diff --git a/libc/include/sys/_system_properties.h b/libc/include/sys/_system_properties.h
index 67beb9a..744a45b 100644
--- a/libc/include/sys/_system_properties.h
+++ b/libc/include/sys/_system_properties.h
@@ -58,8 +58,8 @@
 #define PROP_ERROR_SET_FAILED 0x0024
 
 /*
-** Map the property area from the specified filename.  This
-** method is for testing only.
+** This was previously for testing, but now that SystemProperties is its own testable class,
+** there is never a reason to call this function and its implementation simply returns -1.
 */
 int __system_property_set_filename(const char* __filename);
 
diff --git a/libc/include/sys/cdefs.h b/libc/include/sys/cdefs.h
index af2d03d..13ad4fe 100644
--- a/libc/include/sys/cdefs.h
+++ b/libc/include/sys/cdefs.h
@@ -94,7 +94,8 @@
 
 #if defined(__STDC__) || defined(__cplusplus)
 #define	__P(protos)	protos		/* full-blown ANSI C */
-#define	__CONCAT(x,y)	x ## y
+#define	__CONCAT1(x,y)	x ## y
+#define	__CONCAT(x,y)	__CONCAT1(x,y)
 #define	__STRING(x)	#x
 
 #if defined(__cplusplus)
diff --git a/libc/libc.arm.map b/libc/libc.arm.map
index 14e5784..6d39812 100644
--- a/libc/libc.arm.map
+++ b/libc/libc.arm.map
@@ -1646,7 +1646,7 @@
     wait3; # arm x86 mips
     wcswcs; # arm x86 mips
     write_malloc_leak_info;
-} LIBC_P;
+} LIBC_Q;
 
 LIBC_DEPRECATED {
   global:
@@ -1661,6 +1661,7 @@
     __system_property_area_init;
     __system_property_set_filename;
     __system_property_update;
+    android_fdsan_get_fd_table;
     android_net_res_stats_get_info_for_net;
     android_net_res_stats_aggregate;
     android_net_res_stats_get_usable_servers;
@@ -1668,4 +1669,4 @@
     malloc_disable;
     malloc_enable;
     malloc_iterate;
-} LIBC_P;
+} LIBC_Q;
diff --git a/libc/libc.arm64.map b/libc/libc.arm64.map
index 2f5c4ab..1cf48b1 100644
--- a/libc/libc.arm64.map
+++ b/libc/libc.arm64.map
@@ -1364,7 +1364,7 @@
     get_malloc_leak_info;
     gMallocLeakZygoteChild;
     write_malloc_leak_info;
-} LIBC_P;
+} LIBC_Q;
 
 LIBC_DEPRECATED {
   global:
@@ -1379,6 +1379,7 @@
     __system_property_area_init;
     __system_property_set_filename;
     __system_property_update;
+    android_fdsan_get_fd_table;
     android_net_res_stats_get_info_for_net;
     android_net_res_stats_aggregate;
     android_net_res_stats_get_usable_servers;
@@ -1386,4 +1387,4 @@
     malloc_disable;
     malloc_enable;
     malloc_iterate;
-} LIBC_P;
+} LIBC_Q;
diff --git a/libc/libc.map.txt b/libc/libc.map.txt
index b4262da..135206e 100644
--- a/libc/libc.map.txt
+++ b/libc/libc.map.txt
@@ -1672,7 +1672,7 @@
     wait3; # arm x86 mips
     wcswcs; # arm x86 mips
     write_malloc_leak_info;
-} LIBC_P;
+} LIBC_Q;
 
 LIBC_DEPRECATED {
   global:
@@ -1687,6 +1687,7 @@
     __system_property_area_init;
     __system_property_set_filename;
     __system_property_update;
+    android_fdsan_get_fd_table;
     android_net_res_stats_get_info_for_net;
     android_net_res_stats_aggregate;
     android_net_res_stats_get_usable_servers;
@@ -1694,4 +1695,4 @@
     malloc_disable;
     malloc_enable;
     malloc_iterate;
-} LIBC_P;
+} LIBC_Q;
diff --git a/libc/libc.mips.map b/libc/libc.mips.map
index 5e0b13f..a330a45 100644
--- a/libc/libc.mips.map
+++ b/libc/libc.mips.map
@@ -1487,7 +1487,7 @@
     wait3; # arm x86 mips
     wcswcs; # arm x86 mips
     write_malloc_leak_info;
-} LIBC_P;
+} LIBC_Q;
 
 LIBC_DEPRECATED {
   global:
@@ -1502,6 +1502,7 @@
     __system_property_area_init;
     __system_property_set_filename;
     __system_property_update;
+    android_fdsan_get_fd_table;
     android_net_res_stats_get_info_for_net;
     android_net_res_stats_aggregate;
     android_net_res_stats_get_usable_servers;
@@ -1509,4 +1510,4 @@
     malloc_disable;
     malloc_enable;
     malloc_iterate;
-} LIBC_P;
+} LIBC_Q;
diff --git a/libc/libc.mips64.map b/libc/libc.mips64.map
index 2f5c4ab..1cf48b1 100644
--- a/libc/libc.mips64.map
+++ b/libc/libc.mips64.map
@@ -1364,7 +1364,7 @@
     get_malloc_leak_info;
     gMallocLeakZygoteChild;
     write_malloc_leak_info;
-} LIBC_P;
+} LIBC_Q;
 
 LIBC_DEPRECATED {
   global:
@@ -1379,6 +1379,7 @@
     __system_property_area_init;
     __system_property_set_filename;
     __system_property_update;
+    android_fdsan_get_fd_table;
     android_net_res_stats_get_info_for_net;
     android_net_res_stats_aggregate;
     android_net_res_stats_get_usable_servers;
@@ -1386,4 +1387,4 @@
     malloc_disable;
     malloc_enable;
     malloc_iterate;
-} LIBC_P;
+} LIBC_Q;
diff --git a/libc/libc.x86.map b/libc/libc.x86.map
index 243af5b..7a2fe9a 100644
--- a/libc/libc.x86.map
+++ b/libc/libc.x86.map
@@ -1486,7 +1486,7 @@
     wait3; # arm x86 mips
     wcswcs; # arm x86 mips
     write_malloc_leak_info;
-} LIBC_P;
+} LIBC_Q;
 
 LIBC_DEPRECATED {
   global:
@@ -1501,6 +1501,7 @@
     __system_property_area_init;
     __system_property_set_filename;
     __system_property_update;
+    android_fdsan_get_fd_table;
     android_net_res_stats_get_info_for_net;
     android_net_res_stats_aggregate;
     android_net_res_stats_get_usable_servers;
@@ -1508,4 +1509,4 @@
     malloc_disable;
     malloc_enable;
     malloc_iterate;
-} LIBC_P;
+} LIBC_Q;
diff --git a/libc/libc.x86_64.map b/libc/libc.x86_64.map
index 2f5c4ab..1cf48b1 100644
--- a/libc/libc.x86_64.map
+++ b/libc/libc.x86_64.map
@@ -1364,7 +1364,7 @@
     get_malloc_leak_info;
     gMallocLeakZygoteChild;
     write_malloc_leak_info;
-} LIBC_P;
+} LIBC_Q;
 
 LIBC_DEPRECATED {
   global:
@@ -1379,6 +1379,7 @@
     __system_property_area_init;
     __system_property_set_filename;
     __system_property_update;
+    android_fdsan_get_fd_table;
     android_net_res_stats_get_info_for_net;
     android_net_res_stats_aggregate;
     android_net_res_stats_get_usable_servers;
@@ -1386,4 +1387,4 @@
     malloc_disable;
     malloc_enable;
     malloc_iterate;
-} LIBC_P;
+} LIBC_Q;
diff --git a/libc/malloc_debug/malloc_debug.cpp b/libc/malloc_debug/malloc_debug.cpp
index 2e3a0a3..9075a9c 100644
--- a/libc/malloc_debug/malloc_debug.cpp
+++ b/libc/malloc_debug/malloc_debug.cpp
@@ -284,7 +284,7 @@
   ScopedDisableDebugCalls disable;
 
   // Verify the arguments.
-  if (info == nullptr || overall_size == nullptr || info_size == NULL || total_memory == nullptr ||
+  if (info == nullptr || overall_size == nullptr || info_size == nullptr || total_memory == nullptr ||
       backtrace_size == nullptr) {
     error_log("get_malloc_leak_info: At least one invalid parameter.");
     return;
diff --git a/libc/private/KernelArgumentBlock.h b/libc/private/KernelArgumentBlock.h
index 5b6b77f..e05ceb9 100644
--- a/libc/private/KernelArgumentBlock.h
+++ b/libc/private/KernelArgumentBlock.h
@@ -42,7 +42,7 @@
     // Skip over all environment variable definitions to find the aux vector.
     // The end of the environment block is marked by a NULL pointer.
     char** p = envp;
-    while (*p != NULL) {
+    while (*p != nullptr) {
       ++p;
     }
     ++p; // Skip the NULL itself.
diff --git a/libc/private/ScopedReaddir.h b/libc/private/ScopedReaddir.h
index 3d77a40..1a59e1a 100644
--- a/libc/private/ScopedReaddir.h
+++ b/libc/private/ScopedReaddir.h
@@ -31,13 +31,13 @@
   }
 
   ~ScopedReaddir() {
-    if (dir_ != NULL) {
+    if (dir_ != nullptr) {
       closedir(dir_);
     }
   }
 
   bool IsBad() {
-    return dir_ == NULL;
+    return dir_ == nullptr;
   }
 
   dirent* ReadEntry() {
diff --git a/libc/private/bionic_fdsan.h b/libc/private/bionic_fdsan.h
index b93260b..de14cf8 100644
--- a/libc/private/bionic_fdsan.h
+++ b/libc/private/bionic_fdsan.h
@@ -38,8 +38,6 @@
 #include <sys/resource.h>
 #include <sys/user.h>
 
-#include <async_safe/log.h>
-
 struct FdEntry {
   _Atomic(uint64_t) close_tag;
 };
@@ -50,62 +48,14 @@
 };
 
 template <size_t inline_fds>
-struct FdTable {
+struct FdTableImpl {
+  uint32_t version;  // currently 0, and hopefully it'll stay that way.
   _Atomic(android_fdsan_error_level) error_level;
 
   FdEntry entries[inline_fds];
   _Atomic(FdTableOverflow*) overflow;
 
-  FdEntry* at(size_t idx) {
-    if (idx < inline_fds) {
-      return &entries[idx];
-    }
-
-    // Try to create the overflow table ourselves.
-    FdTableOverflow* local_overflow = atomic_load(&overflow);
-    if (__predict_false(!local_overflow)) {
-      struct rlimit rlim = { .rlim_max = 32768 };
-      getrlimit(RLIMIT_NOFILE, &rlim);
-      rlim_t max = rlim.rlim_max;
-
-      if (max == RLIM_INFINITY) {
-        // This isn't actually possible (the kernel has a hard limit), but just
-        // in case...
-        max = 32768;
-      }
-
-      if (idx > max) {
-        // This can happen if an fd is created and then the rlimit is lowered.
-        // In this case, just return nullptr and ignore the fd.
-        return nullptr;
-      }
-
-      size_t required_count = max - inline_fds;
-      size_t required_size = sizeof(FdTableOverflow) + required_count * sizeof(FdEntry);
-      size_t aligned_size = __BIONIC_ALIGN(required_size, PAGE_SIZE);
-      size_t aligned_count = (aligned_size - sizeof(FdTableOverflow)) / sizeof(FdEntry);
-
-      void* allocation =
-          mmap(nullptr, aligned_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
-      if (allocation == MAP_FAILED) {
-        async_safe_fatal("fdsan: mmap failed: %s", strerror(errno));
-      }
-
-      FdTableOverflow* new_overflow = reinterpret_cast<FdTableOverflow*>(allocation);
-      new_overflow->len = aligned_count;
-
-      if (atomic_compare_exchange_strong(&overflow, &local_overflow, new_overflow)) {
-        local_overflow = new_overflow;
-      } else {
-        // Someone beat us to it. Deallocate and use theirs.
-        munmap(allocation, aligned_size);
-      }
-    }
-
-    size_t offset = idx - inline_fds;
-    if (local_overflow->len < offset) {
-      return nullptr;
-    }
-    return &local_overflow->entries[offset];
-  }
+  FdEntry* at(size_t idx);
 };
+
+using FdTable = FdTableImpl<128>;
diff --git a/libc/private/bionic_futex.h b/libc/private/bionic_futex.h
index fd68007..b340690 100644
--- a/libc/private/bionic_futex.h
+++ b/libc/private/bionic_futex.h
@@ -51,11 +51,11 @@
 }
 
 static inline int __futex_wake(volatile void* ftx, int count) {
-  return __futex(ftx, FUTEX_WAKE, count, NULL, 0);
+  return __futex(ftx, FUTEX_WAKE, count, nullptr, 0);
 }
 
 static inline int __futex_wake_ex(volatile void* ftx, bool shared, int count) {
-  return __futex(ftx, shared ? FUTEX_WAKE : FUTEX_WAKE_PRIVATE, count, NULL, 0);
+  return __futex(ftx, shared ? FUTEX_WAKE : FUTEX_WAKE_PRIVATE, count, nullptr, 0);
 }
 
 static inline int __futex_wait(volatile void* ftx, int value, const timespec* timeout) {
diff --git a/libc/private/bionic_globals.h b/libc/private/bionic_globals.h
index e569209..eee33c9 100644
--- a/libc/private/bionic_globals.h
+++ b/libc/private/bionic_globals.h
@@ -46,7 +46,7 @@
 
 // Globals shared between the dynamic linker and libc.so.
 struct libc_shared_globals {
-  FdTable<128> fd_table;
+  FdTable fd_table;
 };
 
 __LIBC_HIDDEN__ extern libc_shared_globals* __libc_shared_globals;
diff --git a/libc/seccomp/Android.bp b/libc/seccomp/Android.bp
deleted file mode 100644
index ae99857..0000000
--- a/libc/seccomp/Android.bp
+++ /dev/null
@@ -1,35 +0,0 @@
-cc_library {
-    name: "libseccomp_policy",
-    srcs: [
-        "seccomp_policy.cpp",
-        "arm_app_policy.cpp",
-        "arm_global_policy.cpp",
-        "arm_system_policy.cpp",
-        "arm64_app_policy.cpp",
-        "arm64_global_policy.cpp",
-        "arm64_system_policy.cpp",
-        "x86_app_policy.cpp",
-        "x86_global_policy.cpp",
-        "x86_system_policy.cpp",
-        "x86_64_app_policy.cpp",
-        "x86_64_global_policy.cpp",
-        "x86_64_system_policy.cpp",
-        "mips_app_policy.cpp",
-        "mips_global_policy.cpp",
-        "mips_system_policy.cpp",
-        "mips64_app_policy.cpp",
-        "mips64_global_policy.cpp",
-        "mips64_system_policy.cpp",
-    ],
-    export_include_dirs: ["include"],
-    cflags: [
-        "-Wall",
-        "-Werror",
-    ],
-    shared: {
-        shared_libs: ["libbase"],
-    },
-    static: {
-        static_libs: ["libbase"],
-    },
-}
diff --git a/libc/seccomp/arm64_app_policy.cpp b/libc/seccomp/arm64_app_policy.cpp
deleted file mode 100644
index e3dab49..0000000
--- a/libc/seccomp/arm64_app_policy.cpp
+++ /dev/null
@@ -1,67 +0,0 @@
-// Autogenerated file - edit at your peril!!
-
-#include <linux/filter.h>
-#include <errno.h>
-
-#include "seccomp_bpfs.h"
-const sock_filter arm64_app_filter[] = {
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 0, 0, 56),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 153, 27, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 101, 13, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 52, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 41, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 19, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 18, 50, 49), //io_setup|io_destroy|io_submit|io_cancel|io_getevents|setxattr|lsetxattr|fsetxattr|getxattr|lgetxattr|fgetxattr|listxattr|llistxattr|flistxattr|removexattr|lremovexattr|fremovexattr|getcwd
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 39, 49, 48), //eventfd2|epoll_create1|epoll_ctl|epoll_pwait|dup|dup3|fcntl|inotify_init1|inotify_add_watch|inotify_rm_watch|ioctl|ioprio_set|ioprio_get|flock|mknodat|mkdirat|unlinkat|symlinkat|linkat|renameat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 43, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 42, 47, 46), //pivot_root
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 51, 46, 45), //statfs|fstatfs|truncate|ftruncate|fallocate|faccessat|chdir|fchdir
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 90, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 59, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 58, 43, 42), //fchmod|fchmodat|fchownat|fchown|openat|close
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 89, 42, 41), //pipe2|quotactl|getdents64|lseek|read|write|readv|writev|pread64|pwrite64|preadv|pwritev|sendfile|pselect6|ppoll|signalfd4|vmsplice|splice|tee|readlinkat|newfstatat|fstat|sync|fsync|fdatasync|sync_file_range|timerfd_create|timerfd_settime|timerfd_gettime|utimensat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 99, 41, 40), //capget|capset|personality|exit|exit_group|waitid|set_tid_address|unshare|futex
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 143, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 113, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 107, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 104, 37, 36), //nanosleep|getitimer|setitimer
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 112, 36, 35), //timer_create|timer_gettime|timer_getoverrun|timer_settime|timer_delete
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 117, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 116, 34, 33), //clock_gettime|clock_getres|clock_nanosleep
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 142, 33, 32), //ptrace|sched_setparam|sched_setscheduler|sched_getscheduler|sched_getparam|sched_setaffinity|sched_getaffinity|sched_yield|sched_get_priority_max|sched_get_priority_min|sched_rr_get_interval|restart_syscall|kill|tkill|tgkill|sigaltstack|rt_sigsuspend|rt_sigaction|rt_sigprocmask|rt_sigpending|rt_sigtimedwait|rt_sigqueueinfo|rt_sigreturn|setpriority|getpriority
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 150, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 147, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 144, 30, 29), //setregid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 149, 29, 28), //setresuid|getresuid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 151, 28, 27), //getresgid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 226, 13, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 198, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 163, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 160, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 159, 23, 22), //times|setpgid|getpgid|getsid|setsid|getgroups
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 161, 22, 21), //uname
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 172, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 170, 20, 19), //getrlimit|setrlimit|getrusage|umask|prctl|getcpu|gettimeofday
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 180, 19, 18), //getpid|getppid|getuid|geteuid|getgid|getegid|gettid|sysinfo
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 220, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 203, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 202, 16, 15), //socket|socketpair|bind|listen
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 217, 15, 14), //connect|getsockname|getpeername|sendto|recvfrom|setsockopt|getsockopt|shutdown|sendmsg|recvmsg|readahead|brk|munmap|mremap
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 224, 14, 13), //clone|execve|mmap|fadvise64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 274, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 260, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 240, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 234, 10, 9), //mprotect|msync|mlock|munlock|mlockall|munlockall|mincore|madvise
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 244, 9, 8), //rt_tgsigqueueinfo|perf_event_open|accept4|recvmmsg
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 267, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 262, 7, 6), //wait4|prlimit64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 272, 6, 5), //syncfs|setns|sendmmsg|process_vm_readv|process_vm_writev
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 284, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 281, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 280, 3, 2), //sched_setattr|sched_getattr|renameat2|seccomp|getrandom|memfd_create
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 282, 2, 1), //execveat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 288, 1, 0), //mlock2|copy_file_range|preadv2|pwritev2
-BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW),
-};
-
-const size_t arm64_app_filter_size = sizeof(arm64_app_filter) / sizeof(struct sock_filter);
diff --git a/libc/seccomp/arm64_global_policy.cpp b/libc/seccomp/arm64_global_policy.cpp
deleted file mode 100644
index 0a898de..0000000
--- a/libc/seccomp/arm64_global_policy.cpp
+++ /dev/null
@@ -1,41 +0,0 @@
-// Autogenerated file - edit at your peril!!
-
-#include <linux/filter.h>
-#include <errno.h>
-
-#include "seccomp_bpfs.h"
-const sock_filter arm64_global_filter[] = {
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 0, 0, 30),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 219, 15, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 101, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 43, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 19, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 18, 25, 24), //io_setup|io_destroy|io_submit|io_cancel|io_getevents|setxattr|lsetxattr|fsetxattr|getxattr|lgetxattr|fgetxattr|listxattr|llistxattr|flistxattr|removexattr|lremovexattr|fremovexattr|getcwd
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 42, 24, 23), //eventfd2|epoll_create1|epoll_ctl|epoll_pwait|dup|dup3|fcntl|inotify_init1|inotify_add_watch|inotify_rm_watch|ioctl|ioprio_set|ioprio_get|flock|mknodat|mkdirat|unlinkat|symlinkat|linkat|renameat|umount2|mount|pivot_root
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 59, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 58, 22, 21), //statfs|fstatfs|truncate|ftruncate|fallocate|faccessat|chdir|fchdir|chroot|fchmod|fchmodat|fchownat|fchown|openat|close
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 99, 21, 20), //pipe2|quotactl|getdents64|lseek|read|write|readv|writev|pread64|pwrite64|preadv|pwritev|sendfile|pselect6|ppoll|signalfd4|vmsplice|splice|tee|readlinkat|newfstatat|fstat|sync|fsync|fdatasync|sync_file_range|timerfd_create|timerfd_settime|timerfd_gettime|utimensat|acct|capget|capset|personality|exit|exit_group|waitid|set_tid_address|unshare|futex
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 198, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 105, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 104, 18, 17), //nanosleep|getitimer|setitimer
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 180, 17, 16), //init_module|delete_module|timer_create|timer_gettime|timer_getoverrun|timer_settime|timer_delete|clock_settime|clock_gettime|clock_getres|clock_nanosleep|syslog|ptrace|sched_setparam|sched_setscheduler|sched_getscheduler|sched_getparam|sched_setaffinity|sched_getaffinity|sched_yield|sched_get_priority_max|sched_get_priority_min|sched_rr_get_interval|restart_syscall|kill|tkill|tgkill|sigaltstack|rt_sigsuspend|rt_sigaction|rt_sigprocmask|rt_sigpending|rt_sigtimedwait|rt_sigqueueinfo|rt_sigreturn|setpriority|getpriority|reboot|setregid|setgid|setreuid|setuid|setresuid|getresuid|setresgid|getresgid|setfsuid|setfsgid|times|setpgid|getpgid|getsid|setsid|getgroups|setgroups|uname|sethostname|setdomainname|getrlimit|setrlimit|getrusage|umask|prctl|getcpu|gettimeofday|settimeofday|adjtimex|getpid|getppid|getuid|geteuid|getgid|getegid|gettid|sysinfo
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 203, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 202, 15, 14), //socket|socketpair|bind|listen
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 218, 14, 13), //connect|getsockname|getpeername|sendto|recvfrom|setsockopt|getsockopt|shutdown|sendmsg|recvmsg|readahead|brk|munmap|mremap|add_key
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 266, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 240, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 226, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 225, 10, 9), //keyctl|clone|execve|mmap|fadvise64|swapon
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 234, 9, 8), //mprotect|msync|mlock|munlock|mlockall|munlockall|mincore|madvise
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 260, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 244, 7, 6), //rt_tgsigqueueinfo|perf_event_open|accept4|recvmmsg
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 262, 6, 5), //wait4|prlimit64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 284, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 273, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 272, 3, 2), //clock_adjtime|syncfs|setns|sendmmsg|process_vm_readv|process_vm_writev
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 282, 2, 1), //finit_module|sched_setattr|sched_getattr|renameat2|seccomp|getrandom|memfd_create|bpf|execveat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 288, 1, 0), //mlock2|copy_file_range|preadv2|pwritev2
-BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW),
-};
-
-const size_t arm64_global_filter_size = sizeof(arm64_global_filter) / sizeof(struct sock_filter);
diff --git a/libc/seccomp/arm64_system_policy.cpp b/libc/seccomp/arm64_system_policy.cpp
deleted file mode 100644
index 51bf12d..0000000
--- a/libc/seccomp/arm64_system_policy.cpp
+++ /dev/null
@@ -1,41 +0,0 @@
-// Autogenerated file - edit at your peril!!
-
-#include <linux/filter.h>
-#include <errno.h>
-
-#include "seccomp_bpfs.h"
-const sock_filter arm64_system_filter[] = {
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 0, 0, 30),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 220, 15, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 101, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 43, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 19, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 18, 25, 24), //io_setup|io_destroy|io_submit|io_cancel|io_getevents|setxattr|lsetxattr|fsetxattr|getxattr|lgetxattr|fgetxattr|listxattr|llistxattr|flistxattr|removexattr|lremovexattr|fremovexattr|getcwd
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 42, 24, 23), //eventfd2|epoll_create1|epoll_ctl|epoll_pwait|dup|dup3|fcntl|inotify_init1|inotify_add_watch|inotify_rm_watch|ioctl|ioprio_set|ioprio_get|flock|mknodat|mkdirat|unlinkat|symlinkat|linkat|renameat|umount2|mount|pivot_root
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 59, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 58, 22, 21), //statfs|fstatfs|truncate|ftruncate|fallocate|faccessat|chdir|fchdir|chroot|fchmod|fchmodat|fchownat|fchown|openat|close
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 99, 21, 20), //pipe2|quotactl|getdents64|lseek|read|write|readv|writev|pread64|pwrite64|preadv|pwritev|sendfile|pselect6|ppoll|signalfd4|vmsplice|splice|tee|readlinkat|newfstatat|fstat|sync|fsync|fdatasync|sync_file_range|timerfd_create|timerfd_settime|timerfd_gettime|utimensat|acct|capget|capset|personality|exit|exit_group|waitid|set_tid_address|unshare|futex
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 198, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 105, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 104, 18, 17), //nanosleep|getitimer|setitimer
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 180, 17, 16), //init_module|delete_module|timer_create|timer_gettime|timer_getoverrun|timer_settime|timer_delete|clock_settime|clock_gettime|clock_getres|clock_nanosleep|syslog|ptrace|sched_setparam|sched_setscheduler|sched_getscheduler|sched_getparam|sched_setaffinity|sched_getaffinity|sched_yield|sched_get_priority_max|sched_get_priority_min|sched_rr_get_interval|restart_syscall|kill|tkill|tgkill|sigaltstack|rt_sigsuspend|rt_sigaction|rt_sigprocmask|rt_sigpending|rt_sigtimedwait|rt_sigqueueinfo|rt_sigreturn|setpriority|getpriority|reboot|setregid|setgid|setreuid|setuid|setresuid|getresuid|setresgid|getresgid|setfsuid|setfsgid|times|setpgid|getpgid|getsid|setsid|getgroups|setgroups|uname|sethostname|setdomainname|getrlimit|setrlimit|getrusage|umask|prctl|getcpu|gettimeofday|settimeofday|adjtimex|getpid|getppid|getuid|geteuid|getgid|getegid|gettid|sysinfo
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 203, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 202, 15, 14), //socket|socketpair|bind|listen
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 217, 14, 13), //connect|getsockname|getpeername|sendto|recvfrom|setsockopt|getsockopt|shutdown|sendmsg|recvmsg|readahead|brk|munmap|mremap
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 266, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 240, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 226, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 224, 10, 9), //clone|execve|mmap|fadvise64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 234, 9, 8), //mprotect|msync|mlock|munlock|mlockall|munlockall|mincore|madvise
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 260, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 244, 7, 6), //rt_tgsigqueueinfo|perf_event_open|accept4|recvmmsg
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 262, 6, 5), //wait4|prlimit64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 284, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 274, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 272, 3, 2), //clock_adjtime|syncfs|setns|sendmmsg|process_vm_readv|process_vm_writev
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 282, 2, 1), //sched_setattr|sched_getattr|renameat2|seccomp|getrandom|memfd_create|bpf|execveat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 288, 1, 0), //mlock2|copy_file_range|preadv2|pwritev2
-BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW),
-};
-
-const size_t arm64_system_filter_size = sizeof(arm64_system_filter) / sizeof(struct sock_filter);
diff --git a/libc/seccomp/arm_app_policy.cpp b/libc/seccomp/arm_app_policy.cpp
deleted file mode 100644
index ea9eb58..0000000
--- a/libc/seccomp/arm_app_policy.cpp
+++ /dev/null
@@ -1,139 +0,0 @@
-// Autogenerated file - edit at your peril!!
-
-#include <linux/filter.h>
-#include <errno.h>
-
-#include "seccomp_bpfs.h"
-const sock_filter arm_app_filter[] = {
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 0, 0, 128),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 172, 63, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 77, 31, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 41, 15, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 24, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 10, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 8, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 7, 121, 120), //restart_syscall|exit|fork|read|write|open|close
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 9, 120, 119), //creat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 19, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 13, 118, 117), //unlink|execve|chdir
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 21, 117, 116), //lseek|getpid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 33, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 26, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 25, 114, 113), //getuid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 27, 113, 112), //ptrace
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 36, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 34, 111, 110), //access
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 40, 110, 109), //sync|kill|rename|mkdir
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 60, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 54, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 45, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 44, 106, 105), //dup|pipe|times
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 46, 105, 104), //brk
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 57, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 56, 103, 102), //ioctl|fcntl
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 58, 102, 101), //setpgid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 66, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 63, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 61, 99, 98), //umask
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 65, 98, 97), //dup2|getppid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 75, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 68, 96, 95), //setsid|sigaction
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 76, 95, 94), //setrlimit
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 118, 15, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 96, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 91, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 85, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 79, 90, 89), //getrusage|gettimeofday
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 86, 89, 88), //readlink
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 94, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 93, 87, 86), //munmap|truncate
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 95, 86, 85), //fchmod
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 114, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 104, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 98, 83, 82), //getpriority|setpriority
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 106, 82, 81), //setitimer|getitimer
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 116, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 115, 80, 79), //wait4
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 117, 79, 78), //sysinfo
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 136, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 125, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 122, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 121, 75, 74), //fsync|sigreturn|clone
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 123, 74, 73), //uname
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 131, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 126, 72, 71), //mprotect
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 134, 71, 70), //quotactl|getpgid|fchdir
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 150, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 140, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 137, 68, 67), //personality
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 149, 67, 66), //_llseek|getdents|_newselect|flock|msync|readv|writev|getsid|fdatasync
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 168, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 164, 65, 64), //mlock|munlock|mlockall|munlockall|sched_setparam|sched_getparam|sched_setscheduler|sched_getscheduler|sched_yield|sched_get_priority_max|sched_get_priority_min|sched_rr_get_interval|nanosleep|mremap
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 169, 64, 63), //poll
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 290, 31, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 219, 15, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 204, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 190, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 183, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 182, 58, 57), //prctl|rt_sigreturn|rt_sigaction|rt_sigprocmask|rt_sigpending|rt_sigtimedwait|rt_sigqueueinfo|rt_sigsuspend|pread64|pwrite64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 188, 57, 56), //getcwd|capget|capset|sigaltstack|sendfile
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 199, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 198, 55, 54), //vfork|ugetrlimit|mmap2|truncate64|ftruncate64|stat64|lstat64|fstat64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 203, 54, 53), //getuid32|getgid32|geteuid32|getegid32
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 211, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 207, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 206, 51, 50), //setregid32|getgroups32
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 210, 50, 49), //fchown32|setresuid32|getresuid32
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 217, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 212, 48, 47), //getresgid32
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 218, 47, 46), //getdents64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 263, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 250, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 224, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 222, 43, 42), //mincore|madvise|fcntl64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 249, 42, 41), //gettid|readahead|setxattr|lsetxattr|fsetxattr|getxattr|lgetxattr|fgetxattr|listxattr|llistxattr|flistxattr|removexattr|lremovexattr|fremovexattr|tkill|sendfile64|futex|sched_setaffinity|sched_getaffinity|io_setup|io_destroy|io_getevents|io_submit|io_cancel|exit_group
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 256, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 254, 40, 39), //epoll_create|epoll_ctl|epoll_wait|remap_file_pages
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 262, 39, 38), //set_tid_address|timer_create|timer_settime|timer_gettime|timer_getoverrun|timer_delete
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 280, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 270, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 269, 36, 35), //clock_gettime|clock_getres|clock_nanosleep|statfs64|fstatfs64|tgkill
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 271, 35, 34), //arm_fadvise64_64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 286, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 285, 33, 32), //waitid|socket|bind|connect|listen
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 289, 32, 31), //getsockname|getpeername|socketpair
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 350, 15, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 327, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 316, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 292, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 291, 27, 26), //sendto
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 298, 26, 25), //recvfrom|shutdown|setsockopt|getsockopt|sendmsg|recvmsg
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 322, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 319, 24, 23), //inotify_init|inotify_add_watch|inotify_rm_watch
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 326, 23, 22), //openat|mkdirat|mknodat|fchownat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 345, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 340, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 338, 20, 19), //fstatat64|unlinkat|renameat|linkat|symlinkat|readlinkat|fchmodat|faccessat|pselect6|ppoll|unshare
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 344, 19, 18), //splice|sync_file_range2|tee|vmsplice
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 348, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 347, 17, 16), //getcpu|epoll_pwait
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 349, 16, 15), //utimensat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 387, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 373, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 369, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 367, 12, 11), //timerfd_create|eventfd|fallocate|timerfd_settime|timerfd_gettime|signalfd4|eventfd2|epoll_create1|dup3|pipe2|inotify_init1|preadv|pwritev|rt_tgsigqueueinfo|perf_event_open|recvmmsg|accept4
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 370, 11, 10), //prlimit64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 380, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 378, 9, 8), //syncfs|sendmmsg|setns|process_vm_readv|process_vm_writev
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 386, 8, 7), //sched_setattr|sched_getattr|renameat2|seccomp|getrandom|memfd_create
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 983042, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 390, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 388, 5, 4), //execveat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 394, 4, 3), //mlock2|copy_file_range|preadv2|pwritev2
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 983045, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 983043, 2, 1), //__ARM_NR_cacheflush
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 983046, 1, 0), //__ARM_NR_set_tls
-BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW),
-};
-
-const size_t arm_app_filter_size = sizeof(arm_app_filter) / sizeof(struct sock_filter);
diff --git a/libc/seccomp/arm_global_policy.cpp b/libc/seccomp/arm_global_policy.cpp
deleted file mode 100644
index ea158a5..0000000
--- a/libc/seccomp/arm_global_policy.cpp
+++ /dev/null
@@ -1,139 +0,0 @@
-// Autogenerated file - edit at your peril!!
-
-#include <linux/filter.h>
-#include <errno.h>
-
-#include "seccomp_bpfs.h"
-const sock_filter arm_global_filter[] = {
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 0, 0, 128),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 150, 63, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 74, 31, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 41, 15, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 24, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 10, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 8, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 7, 121, 120), //restart_syscall|exit|fork|read|write|open|close
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 9, 120, 119), //creat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 19, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 13, 118, 117), //unlink|execve|chdir
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 22, 117, 116), //lseek|getpid|mount
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 33, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 26, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 25, 114, 113), //getuid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 27, 113, 112), //ptrace
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 36, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 34, 111, 110), //access
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 40, 110, 109), //sync|kill|rename|mkdir
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 57, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 51, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 45, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 44, 106, 105), //dup|pipe|times
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 46, 105, 104), //brk
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 54, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 53, 103, 102), //acct|umount2
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 56, 102, 101), //ioctl|fcntl
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 63, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 60, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 58, 99, 98), //setpgid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 62, 98, 97), //umask|chroot
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 66, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 65, 96, 95), //dup2|getppid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 68, 95, 94), //setsid|sigaction
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 114, 15, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 91, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 85, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 77, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 76, 90, 89), //sethostname|setrlimit
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 80, 89, 88), //getrusage|gettimeofday|settimeofday
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 87, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 86, 87, 86), //readlink
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 89, 86, 85), //swapon|reboot
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 96, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 94, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 93, 83, 82), //munmap|truncate
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 95, 82, 81), //fchmod
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 103, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 98, 80, 79), //getpriority|setpriority
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 106, 79, 78), //syslog|setitimer|getitimer
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 128, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 118, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 116, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 115, 75, 74), //wait4
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 117, 74, 73), //sysinfo
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 124, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 123, 72, 71), //fsync|sigreturn|clone|setdomainname|uname
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 126, 71, 70), //adjtimex|mprotect
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 136, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 131, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 130, 68, 67), //init_module|delete_module
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 134, 67, 66), //quotactl|getpgid|fchdir
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 138, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 137, 65, 64), //personality
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 149, 64, 63), //setfsuid|setfsgid|_llseek|getdents|_newselect|flock|msync|readv|writev|getsid|fdatasync
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 292, 31, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 219, 15, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 190, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 172, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 168, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 164, 58, 57), //mlock|munlock|mlockall|munlockall|sched_setparam|sched_getparam|sched_setscheduler|sched_getscheduler|sched_yield|sched_get_priority_max|sched_get_priority_min|sched_rr_get_interval|nanosleep|mremap
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 169, 57, 56), //poll
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 183, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 182, 55, 54), //prctl|rt_sigreturn|rt_sigaction|rt_sigprocmask|rt_sigpending|rt_sigtimedwait|rt_sigqueueinfo|rt_sigsuspend|pread64|pwrite64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 188, 54, 53), //getcwd|capget|capset|sigaltstack|sendfile
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 213, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 199, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 198, 51, 50), //vfork|ugetrlimit|mmap2|truncate64|ftruncate64|stat64|lstat64|fstat64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 212, 50, 49), //getuid32|getgid32|geteuid32|getegid32|setreuid32|setregid32|getgroups32|setgroups32|fchown32|setresuid32|getresuid32|setresgid32|getresgid32
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 217, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 215, 48, 47), //setuid32|setgid32
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 218, 47, 46), //getdents64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 270, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 250, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 224, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 222, 43, 42), //mincore|madvise|fcntl64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 249, 42, 41), //gettid|readahead|setxattr|lsetxattr|fsetxattr|getxattr|lgetxattr|fgetxattr|listxattr|llistxattr|flistxattr|removexattr|lremovexattr|fremovexattr|tkill|sendfile64|futex|sched_setaffinity|sched_getaffinity|io_setup|io_destroy|io_getevents|io_submit|io_cancel|exit_group
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 256, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 254, 40, 39), //epoll_create|epoll_ctl|epoll_wait|remap_file_pages
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 269, 39, 38), //set_tid_address|timer_create|timer_settime|timer_gettime|timer_getoverrun|timer_delete|clock_settime|clock_gettime|clock_getres|clock_nanosleep|statfs64|fstatfs64|tgkill
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 286, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 280, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 271, 36, 35), //arm_fadvise64_64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 285, 35, 34), //waitid|socket|bind|connect|listen
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 290, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 289, 33, 32), //getsockname|getpeername|socketpair
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 291, 32, 31), //sendto
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 348, 15, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 322, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 311, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 309, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 298, 27, 26), //recvfrom|shutdown|setsockopt|getsockopt|sendmsg|recvmsg
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 310, 26, 25), //add_key
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 316, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 312, 24, 23), //keyctl
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 319, 23, 22), //inotify_init|inotify_add_watch|inotify_rm_watch
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 340, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 327, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 326, 20, 19), //openat|mkdirat|mknodat|fchownat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 338, 19, 18), //fstatat64|unlinkat|renameat|linkat|symlinkat|readlinkat|fchmodat|faccessat|pselect6|ppoll|unshare
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 345, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 344, 17, 16), //splice|sync_file_range2|tee|vmsplice
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 347, 16, 15), //getcpu|epoll_pwait
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 379, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 369, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 350, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 349, 12, 11), //utimensat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 367, 11, 10), //timerfd_create|eventfd|fallocate|timerfd_settime|timerfd_gettime|signalfd4|eventfd2|epoll_create1|dup3|pipe2|inotify_init1|preadv|pwritev|rt_tgsigqueueinfo|perf_event_open|recvmmsg|accept4
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 372, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 370, 9, 8), //prlimit64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 378, 8, 7), //clock_adjtime|syncfs|sendmmsg|setns|process_vm_readv|process_vm_writev
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 983042, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 390, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 388, 5, 4), //finit_module|sched_setattr|sched_getattr|renameat2|seccomp|getrandom|memfd_create|bpf|execveat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 394, 4, 3), //mlock2|copy_file_range|preadv2|pwritev2
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 983045, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 983043, 2, 1), //__ARM_NR_cacheflush
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 983046, 1, 0), //__ARM_NR_set_tls
-BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW),
-};
-
-const size_t arm_global_filter_size = sizeof(arm_global_filter) / sizeof(struct sock_filter);
diff --git a/libc/seccomp/arm_system_policy.cpp b/libc/seccomp/arm_system_policy.cpp
deleted file mode 100644
index 8887f4d..0000000
--- a/libc/seccomp/arm_system_policy.cpp
+++ /dev/null
@@ -1,139 +0,0 @@
-// Autogenerated file - edit at your peril!!
-
-#include <linux/filter.h>
-#include <errno.h>
-
-#include "seccomp_bpfs.h"
-const sock_filter arm_system_filter[] = {
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 0, 0, 128),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 143, 63, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 74, 31, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 43, 15, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 19, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 6, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 3, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 2, 121, 120), //restart_syscall|exit
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5, 120, 119), //read|write
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 11, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 7, 118, 117), //close
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 13, 117, 116), //execve|chdir
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 36, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 26, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 22, 114, 113), //lseek|getpid|mount
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 27, 113, 112), //ptrace
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 41, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 38, 111, 110), //sync|kill
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 42, 110, 109), //dup
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 57, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 51, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 45, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 44, 106, 105), //times
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 46, 105, 104), //brk
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 54, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 53, 103, 102), //acct|umount2
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 55, 102, 101), //ioctl
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 64, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 60, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 58, 99, 98), //setpgid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 62, 98, 97), //umask|chroot
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 66, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 65, 96, 95), //getppid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 68, 95, 94), //setsid|sigaction
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 114, 15, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 91, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 85, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 77, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 76, 90, 89), //sethostname|setrlimit
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 80, 89, 88), //getrusage|gettimeofday|settimeofday
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 88, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 86, 87, 86), //readlink
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 89, 86, 85), //reboot
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 96, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 94, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 93, 83, 82), //munmap|truncate
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 95, 82, 81), //fchmod
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 103, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 98, 80, 79), //getpriority|setpriority
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 106, 79, 78), //syslog|setitimer|getitimer
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 128, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 118, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 116, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 115, 75, 74), //wait4
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 117, 74, 73), //sysinfo
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 124, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 123, 72, 71), //fsync|sigreturn|clone|setdomainname|uname
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 126, 71, 70), //adjtimex|mprotect
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 136, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 131, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 130, 68, 67), //init_module|delete_module
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 134, 67, 66), //quotactl|getpgid|fchdir
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 138, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 137, 65, 64), //personality
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 141, 64, 63), //setfsuid|setfsgid|_llseek
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 290, 31, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 217, 15, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 190, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 172, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 150, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 149, 58, 57), //flock|msync|readv|writev|getsid|fdatasync
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 164, 57, 56), //mlock|munlock|mlockall|munlockall|sched_setparam|sched_getparam|sched_setscheduler|sched_getscheduler|sched_yield|sched_get_priority_max|sched_get_priority_min|sched_rr_get_interval|nanosleep|mremap
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 183, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 182, 55, 54), //prctl|rt_sigreturn|rt_sigaction|rt_sigprocmask|rt_sigpending|rt_sigtimedwait|rt_sigqueueinfo|rt_sigsuspend|pread64|pwrite64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 188, 54, 53), //getcwd|capget|capset|sigaltstack|sendfile
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 199, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 197, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 195, 51, 50), //vfork|ugetrlimit|mmap2|truncate64|ftruncate64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 198, 50, 49), //fstat64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 213, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 212, 48, 47), //getuid32|getgid32|geteuid32|getegid32|setreuid32|setregid32|getgroups32|setgroups32|fchown32|setresuid32|getresuid32|setresgid32|getresgid32
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 215, 47, 46), //setuid32|setgid32
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 256, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 224, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 219, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 218, 43, 42), //getdents64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 222, 42, 41), //mincore|madvise|fcntl64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 251, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 249, 40, 39), //gettid|readahead|setxattr|lsetxattr|fsetxattr|getxattr|lgetxattr|fgetxattr|listxattr|llistxattr|flistxattr|removexattr|lremovexattr|fremovexattr|tkill|sendfile64|futex|sched_setaffinity|sched_getaffinity|io_setup|io_destroy|io_getevents|io_submit|io_cancel|exit_group
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 252, 39, 38), //epoll_ctl
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 280, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 270, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 269, 36, 35), //set_tid_address|timer_create|timer_settime|timer_gettime|timer_getoverrun|timer_delete|clock_settime|clock_gettime|clock_getres|clock_nanosleep|statfs64|fstatfs64|tgkill
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 271, 35, 34), //arm_fadvise64_64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 286, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 285, 33, 32), //waitid|socket|bind|connect|listen
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 289, 32, 31), //getsockname|getpeername|socketpair
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 350, 15, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 327, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 317, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 292, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 291, 27, 26), //sendto
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 298, 26, 25), //recvfrom|shutdown|setsockopt|getsockopt|sendmsg|recvmsg
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 322, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 319, 24, 23), //inotify_add_watch|inotify_rm_watch
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 326, 23, 22), //openat|mkdirat|mknodat|fchownat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 345, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 340, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 338, 20, 19), //fstatat64|unlinkat|renameat|linkat|symlinkat|readlinkat|fchmodat|faccessat|pselect6|ppoll|unshare
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 344, 19, 18), //splice|sync_file_range2|tee|vmsplice
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 348, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 347, 17, 16), //getcpu|epoll_pwait
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 349, 16, 15), //utimensat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 380, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 369, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 352, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 351, 12, 11), //timerfd_create
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 367, 11, 10), //fallocate|timerfd_settime|timerfd_gettime|signalfd4|eventfd2|epoll_create1|dup3|pipe2|inotify_init1|preadv|pwritev|rt_tgsigqueueinfo|perf_event_open|recvmmsg|accept4
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 372, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 370, 9, 8), //prlimit64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 378, 8, 7), //clock_adjtime|syncfs|sendmmsg|setns|process_vm_readv|process_vm_writev
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 983042, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 390, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 388, 5, 4), //sched_setattr|sched_getattr|renameat2|seccomp|getrandom|memfd_create|bpf|execveat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 394, 4, 3), //mlock2|copy_file_range|preadv2|pwritev2
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 983045, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 983043, 2, 1), //__ARM_NR_cacheflush
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 983046, 1, 0), //__ARM_NR_set_tls
-BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW),
-};
-
-const size_t arm_system_filter_size = sizeof(arm_system_filter) / sizeof(struct sock_filter);
diff --git a/libc/seccomp/gen_syscall_nrs.cpp b/libc/seccomp/gen_syscall_nrs.cpp
new file mode 100644
index 0000000..89a7149
--- /dev/null
+++ b/libc/seccomp/gen_syscall_nrs.cpp
@@ -0,0 +1 @@
+#include <asm/unistd.h>
diff --git a/libc/seccomp/gen_syscall_nrs_x86.cpp b/libc/seccomp/gen_syscall_nrs_x86.cpp
new file mode 100644
index 0000000..fd213e2
--- /dev/null
+++ b/libc/seccomp/gen_syscall_nrs_x86.cpp
@@ -0,0 +1 @@
+#include <asm/unistd_32.h>
diff --git a/libc/seccomp/gen_syscall_nrs_x86_64.cpp b/libc/seccomp/gen_syscall_nrs_x86_64.cpp
new file mode 100644
index 0000000..6f8866f
--- /dev/null
+++ b/libc/seccomp/gen_syscall_nrs_x86_64.cpp
@@ -0,0 +1 @@
+#include <asm/unistd_64.h>
diff --git a/libc/seccomp/mips64_app_policy.cpp b/libc/seccomp/mips64_app_policy.cpp
deleted file mode 100644
index e5d69cf..0000000
--- a/libc/seccomp/mips64_app_policy.cpp
+++ /dev/null
@@ -1,109 +0,0 @@
-// Autogenerated file - edit at your peril!!
-
-#include <linux/filter.h>
-#include <errno.h>
-
-#include "seccomp_bpfs.h"
-const sock_filter mips64_app_filter[] = {
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5000, 0, 98),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5151, 49, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5091, 25, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5038, 13, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5023, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5005, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5003, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5002, 91, 90), //read|write
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5004, 90, 89), //close
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5008, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5006, 88, 87), //fstat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5020, 87, 86), //lseek|mmap|mprotect|munmap|brk|rt_sigaction|rt_sigprocmask|ioctl|pread64|pwrite64|readv|writev
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5034, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5031, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5028, 84, 83), //sched_yield|mremap|msync|mincore|madvise
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5032, 83, 82), //dup
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5037, 82, 81), //nanosleep|getitimer|setitimer
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5070, 5, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5057, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5043, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5042, 78, 77), //getpid|sendfile|socket|connect
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5056, 77, 76), //sendto|recvfrom|sendmsg|recvmsg|shutdown|bind|listen|getsockname|getpeername|socketpair|setsockopt|getsockopt|clone
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5062, 76, 75), //execve|exit|wait4|kill|uname
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5089, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5077, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5076, 73, 72), //fcntl|flock|fsync|fdatasync|truncate|ftruncate
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5080, 72, 71), //getcwd|chdir|fchdir
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5090, 71, 70), //fchmod
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5115, 11, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5105, 5, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5102, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5093, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5092, 66, 65), //fchown
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5101, 65, 64), //umask|gettimeofday|getrlimit|getrusage|sysinfo|times|ptrace|getuid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5103, 64, 63), //getgid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5112, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5110, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5109, 61, 60), //geteuid|getegid|setpgid|getppid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5111, 60, 59), //setsid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5114, 59, 58), //setregid|getgroups
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5132, 5, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5122, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5118, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5117, 55, 54), //setresuid|getresuid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5120, 54, 53), //getresgid|getpgid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5130, 53, 52), //getsid|capget|capset|rt_sigpending|rt_sigtimedwait|rt_sigqueueinfo|rt_sigsuspend|sigaltstack
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5137, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5134, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5133, 50, 49), //personality
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5136, 49, 48), //statfs|fstatfs
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5150, 48, 47), //getpriority|setpriority|sched_setparam|sched_getparam|sched_setscheduler|sched_getscheduler|sched_get_priority_max|sched_get_priority_min|sched_rr_get_interval|mlock|munlock|mlockall|munlockall
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5237, 23, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5194, 11, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5157, 5, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5155, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5153, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5152, 42, 41), //pivot_root
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5154, 41, 40), //prctl
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5156, 40, 39), //setrlimit
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5178, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5172, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5158, 37, 36), //sync
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5173, 36, 35), //quotactl
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5193, 35, 34), //gettid|readahead|setxattr|lsetxattr|fsetxattr|getxattr|lgetxattr|fgetxattr|listxattr|llistxattr|flistxattr|removexattr|lremovexattr|fremovexattr|tkill
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5211, 5, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5208, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5200, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5198, 31, 30), //futex|sched_setaffinity|sched_getaffinity|cacheflush
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5206, 30, 29), //io_setup|io_destroy|io_getevents|io_submit|io_cancel|exit_group
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5209, 29, 28), //epoll_ctl
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5222, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5215, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5214, 26, 25), //rt_sigreturn|set_tid_address|restart_syscall
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5221, 25, 24), //fadvise64|timer_create|timer_settime|timer_gettime|timer_getoverrun|timer_delete
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5226, 24, 23), //clock_gettime|clock_getres|clock_nanosleep|tgkill
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5279, 11, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5247, 5, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5244, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5242, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5238, 19, 18), //waitid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5243, 18, 17), //set_thread_area
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5246, 17, 16), //inotify_add_watch|inotify_rm_watch
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5271, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5252, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5251, 14, 13), //openat|mkdirat|mknodat|fchownat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5267, 13, 12), //newfstatat|unlinkat|renameat|linkat|symlinkat|readlinkat|fchmodat|faccessat|pselect6|ppoll|unshare|splice|sync_file_range|tee|vmsplice
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5276, 12, 11), //getcpu|epoll_pwait|ioprio_set|ioprio_get|utimensat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5308, 5, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5301, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5297, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5295, 8, 7), //fallocate|timerfd_create|timerfd_gettime|timerfd_settime|signalfd4|eventfd2|epoll_create1|dup3|pipe2|inotify_init1|preadv|pwritev|rt_tgsigqueueinfo|perf_event_open|accept4|recvmmsg
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5298, 7, 6), //prlimit64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5306, 6, 5), //syncfs|sendmmsg|setns|process_vm_readv|process_vm_writev
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5319, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5316, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5315, 3, 2), //getdents64|sched_setattr|sched_getattr|renameat2|seccomp|getrandom|memfd_create
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5317, 2, 1), //execveat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5323, 1, 0), //mlock2|copy_file_range|preadv2|pwritev2
-BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW),
-};
-
-const size_t mips64_app_filter_size = sizeof(mips64_app_filter) / sizeof(struct sock_filter);
diff --git a/libc/seccomp/mips64_global_policy.cpp b/libc/seccomp/mips64_global_policy.cpp
deleted file mode 100644
index 1084f7b..0000000
--- a/libc/seccomp/mips64_global_policy.cpp
+++ /dev/null
@@ -1,95 +0,0 @@
-// Autogenerated file - edit at your peril!!
-
-#include <linux/filter.h>
-#include <errno.h>
-
-#include "seccomp_bpfs.h"
-const sock_filter mips64_global_filter[] = {
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5000, 0, 84),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5164, 41, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5077, 21, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5034, 11, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5008, 5, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5005, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5003, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5002, 77, 76), //read|write
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5004, 76, 75), //close
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5006, 75, 74), //fstat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5031, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5023, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5020, 72, 71), //lseek|mmap|mprotect|munmap|brk|rt_sigaction|rt_sigprocmask|ioctl|pread64|pwrite64|readv|writev
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5028, 71, 70), //sched_yield|mremap|msync|mincore|madvise
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5032, 70, 69), //dup
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5057, 5, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5043, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5038, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5037, 66, 65), //nanosleep|getitimer|setitimer
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5042, 65, 64), //getpid|sendfile|socket|connect
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5056, 64, 63), //sendto|recvfrom|sendmsg|recvmsg|shutdown|bind|listen|getsockname|getpeername|socketpair|setsockopt|getsockopt|clone
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5070, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5062, 62, 61), //execve|exit|wait4|kill|uname
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5076, 61, 60), //fcntl|flock|fsync|fdatasync|truncate|ftruncate
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5132, 9, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5093, 5, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5091, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5089, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5080, 56, 55), //getcwd|chdir|fchdir
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5090, 55, 54), //fchmod
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5092, 54, 53), //fchown
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5110, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5109, 52, 51), //umask|gettimeofday|getrlimit|getrusage|sysinfo|times|ptrace|getuid|syslog|getgid|setuid|setgid|geteuid|getegid|setpgid|getppid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5130, 51, 50), //setsid|setreuid|setregid|getgroups|setgroups|setresuid|getresuid|setresgid|getresgid|getpgid|setfsuid|setfsgid|getsid|capget|capset|rt_sigpending|rt_sigtimedwait|rt_sigqueueinfo|rt_sigsuspend|sigaltstack
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5151, 5, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5137, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5134, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5133, 47, 46), //personality
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5136, 46, 45), //statfs|fstatfs
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5150, 45, 44), //getpriority|setpriority|sched_setparam|sched_getparam|sched_setscheduler|sched_getscheduler|sched_get_priority_max|sched_get_priority_min|sched_rr_get_interval|mlock|munlock|mlockall|munlockall
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5153, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5152, 43, 42), //pivot_root
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5163, 42, 41), //prctl|adjtimex|setrlimit|chroot|sync|acct|settimeofday|mount|umount2|swapon
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5241, 21, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5208, 11, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5178, 5, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5172, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5168, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5167, 36, 35), //reboot|sethostname|setdomainname
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5170, 35, 34), //init_module|delete_module
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5173, 34, 33), //quotactl
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5200, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5194, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5193, 31, 30), //gettid|readahead|setxattr|lsetxattr|fsetxattr|getxattr|lgetxattr|fgetxattr|listxattr|llistxattr|flistxattr|removexattr|lremovexattr|fremovexattr|tkill
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5198, 30, 29), //futex|sched_setaffinity|sched_getaffinity|cacheflush
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5206, 29, 28), //io_setup|io_destroy|io_getevents|io_submit|io_cancel|exit_group
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5237, 5, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5215, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5211, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5209, 25, 24), //epoll_ctl
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5214, 24, 23), //rt_sigreturn|set_tid_address|restart_syscall
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5226, 23, 22), //fadvise64|timer_create|timer_settime|timer_gettime|timer_getoverrun|timer_delete|clock_settime|clock_gettime|clock_getres|clock_nanosleep|tgkill
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5239, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5238, 21, 20), //waitid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5240, 20, 19), //add_key
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5279, 9, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5252, 5, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5247, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5244, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5243, 15, 14), //keyctl|set_thread_area
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5246, 14, 13), //inotify_add_watch|inotify_rm_watch
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5251, 13, 12), //openat|mkdirat|mknodat|fchownat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5271, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5267, 11, 10), //newfstatat|unlinkat|renameat|linkat|symlinkat|readlinkat|fchmodat|faccessat|pselect6|ppoll|unshare|splice|sync_file_range|tee|vmsplice
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5276, 10, 9), //getcpu|epoll_pwait|ioprio_set|ioprio_get|utimensat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5307, 5, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5300, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5297, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5295, 6, 5), //fallocate|timerfd_create|timerfd_gettime|timerfd_settime|signalfd4|eventfd2|epoll_create1|dup3|pipe2|inotify_init1|preadv|pwritev|rt_tgsigqueueinfo|perf_event_open|accept4|recvmmsg
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5298, 5, 4), //prlimit64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5306, 4, 3), //clock_adjtime|syncfs|sendmmsg|setns|process_vm_readv|process_vm_writev
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5319, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5317, 2, 1), //finit_module|getdents64|sched_setattr|sched_getattr|renameat2|seccomp|getrandom|memfd_create|bpf|execveat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5323, 1, 0), //mlock2|copy_file_range|preadv2|pwritev2
-BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW),
-};
-
-const size_t mips64_global_filter_size = sizeof(mips64_global_filter) / sizeof(struct sock_filter);
diff --git a/libc/seccomp/mips64_system_policy.cpp b/libc/seccomp/mips64_system_policy.cpp
deleted file mode 100644
index 6b76244..0000000
--- a/libc/seccomp/mips64_system_policy.cpp
+++ /dev/null
@@ -1,93 +0,0 @@
-// Autogenerated file - edit at your peril!!
-
-#include <linux/filter.h>
-#include <errno.h>
-
-#include "seccomp_bpfs.h"
-const sock_filter mips64_system_filter[] = {
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5000, 0, 82),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5164, 41, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5077, 21, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5034, 11, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5008, 5, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5005, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5003, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5002, 75, 74), //read|write
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5004, 74, 73), //close
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5006, 73, 72), //fstat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5031, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5023, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5020, 70, 69), //lseek|mmap|mprotect|munmap|brk|rt_sigaction|rt_sigprocmask|ioctl|pread64|pwrite64|readv|writev
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5028, 69, 68), //sched_yield|mremap|msync|mincore|madvise
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5032, 68, 67), //dup
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5057, 5, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5043, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5038, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5037, 64, 63), //nanosleep|getitimer|setitimer
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5042, 63, 62), //getpid|sendfile|socket|connect
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5056, 62, 61), //sendto|recvfrom|sendmsg|recvmsg|shutdown|bind|listen|getsockname|getpeername|socketpair|setsockopt|getsockopt|clone
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5070, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5062, 60, 59), //execve|exit|wait4|kill|uname
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5076, 59, 58), //fcntl|flock|fsync|fdatasync|truncate|ftruncate
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5132, 9, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5093, 5, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5091, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5089, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5080, 54, 53), //getcwd|chdir|fchdir
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5090, 53, 52), //fchmod
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5092, 52, 51), //fchown
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5110, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5109, 50, 49), //umask|gettimeofday|getrlimit|getrusage|sysinfo|times|ptrace|getuid|syslog|getgid|setuid|setgid|geteuid|getegid|setpgid|getppid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5130, 49, 48), //setsid|setreuid|setregid|getgroups|setgroups|setresuid|getresuid|setresgid|getresgid|getpgid|setfsuid|setfsgid|getsid|capget|capset|rt_sigpending|rt_sigtimedwait|rt_sigqueueinfo|rt_sigsuspend|sigaltstack
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5151, 5, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5137, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5134, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5133, 45, 44), //personality
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5136, 44, 43), //statfs|fstatfs
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5150, 43, 42), //getpriority|setpriority|sched_setparam|sched_getparam|sched_setscheduler|sched_getscheduler|sched_get_priority_max|sched_get_priority_min|sched_rr_get_interval|mlock|munlock|mlockall|munlockall
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5153, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5152, 41, 40), //pivot_root
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5162, 40, 39), //prctl|adjtimex|setrlimit|chroot|sync|acct|settimeofday|mount|umount2
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5242, 19, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5200, 9, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5178, 5, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5172, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5168, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5167, 34, 33), //reboot|sethostname|setdomainname
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5170, 33, 32), //init_module|delete_module
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5173, 32, 31), //quotactl
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5194, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5193, 30, 29), //gettid|readahead|setxattr|lsetxattr|fsetxattr|getxattr|lgetxattr|fgetxattr|listxattr|llistxattr|flistxattr|removexattr|lremovexattr|fremovexattr|tkill
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5198, 29, 28), //futex|sched_setaffinity|sched_getaffinity|cacheflush
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5215, 5, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5211, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5208, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5206, 25, 24), //io_setup|io_destroy|io_getevents|io_submit|io_cancel|exit_group
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5209, 24, 23), //epoll_ctl
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5214, 23, 22), //rt_sigreturn|set_tid_address|restart_syscall
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5237, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5226, 21, 20), //fadvise64|timer_create|timer_settime|timer_gettime|timer_getoverrun|timer_delete|clock_settime|clock_gettime|clock_getres|clock_nanosleep|tgkill
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5238, 20, 19), //waitid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5279, 9, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5252, 5, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5247, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5244, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5243, 15, 14), //set_thread_area
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5246, 14, 13), //inotify_add_watch|inotify_rm_watch
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5251, 13, 12), //openat|mkdirat|mknodat|fchownat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5271, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5267, 11, 10), //newfstatat|unlinkat|renameat|linkat|symlinkat|readlinkat|fchmodat|faccessat|pselect6|ppoll|unshare|splice|sync_file_range|tee|vmsplice
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5276, 10, 9), //getcpu|epoll_pwait|ioprio_set|ioprio_get|utimensat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5308, 5, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5300, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5297, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5295, 6, 5), //fallocate|timerfd_create|timerfd_gettime|timerfd_settime|signalfd4|eventfd2|epoll_create1|dup3|pipe2|inotify_init1|preadv|pwritev|rt_tgsigqueueinfo|perf_event_open|accept4|recvmmsg
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5298, 5, 4), //prlimit64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5306, 4, 3), //clock_adjtime|syncfs|sendmmsg|setns|process_vm_readv|process_vm_writev
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5319, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5317, 2, 1), //getdents64|sched_setattr|sched_getattr|renameat2|seccomp|getrandom|memfd_create|bpf|execveat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5323, 1, 0), //mlock2|copy_file_range|preadv2|pwritev2
-BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW),
-};
-
-const size_t mips64_system_filter_size = sizeof(mips64_system_filter) / sizeof(struct sock_filter);
diff --git a/libc/seccomp/mips_app_policy.cpp b/libc/seccomp/mips_app_policy.cpp
deleted file mode 100644
index c1ec0e2..0000000
--- a/libc/seccomp/mips_app_policy.cpp
+++ /dev/null
@@ -1,125 +0,0 @@
-// Autogenerated file - edit at your peril!!
-
-#include <linux/filter.h>
-#include <errno.h>
-
-#include "seccomp_bpfs.h"
-const sock_filter mips_app_filter[] = {
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4001, 0, 114),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4131, 57, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4063, 29, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4041, 15, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4024, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4010, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4008, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4007, 107, 106), //exit|fork|read|write|open|close
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4009, 106, 105), //creat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4019, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4013, 104, 103), //unlink|execve|chdir
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4021, 103, 102), //lseek|getpid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4033, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4026, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4025, 100, 99), //getuid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4027, 99, 98), //ptrace
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4036, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4034, 97, 96), //access
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4040, 96, 95), //sync|kill|rename|mkdir
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4054, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4047, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4045, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4044, 92, 91), //dup|pipe|times
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4046, 91, 90), //brk
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4049, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4048, 89, 88), //getgid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4051, 88, 87), //geteuid|getegid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4060, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4057, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4056, 85, 84), //ioctl|fcntl
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4058, 84, 83), //setpgid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4061, 83, 82), //umask
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4094, 13, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4080, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4071, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4066, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4065, 78, 77), //dup2|getppid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4068, 77, 76), //setsid|sigaction
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4075, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4072, 75, 74), //setregid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4079, 74, 73), //setrlimit|getrlimit|getrusage|gettimeofday
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4090, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4085, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4081, 71, 70), //getgroups
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4086, 70, 69), //readlink
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4093, 69, 68), //mmap|munmap|truncate
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4118, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4114, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4104, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4098, 65, 64), //fchmod|fchown|getpriority|setpriority
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4106, 64, 63), //setitimer|getitimer
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4116, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4115, 62, 61), //wait4
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4117, 61, 60), //sysinfo
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4125, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4122, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4121, 58, 57), //fsync|sigreturn|clone
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4123, 57, 56), //uname
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4126, 56, 55), //mprotect
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4248, 27, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4179, 13, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4154, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4140, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4136, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4134, 50, 49), //quotactl|getpgid|fchdir
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4137, 49, 48), //personality
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4151, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4148, 47, 46), //_llseek|getdents|_newselect|flock|msync|readv|writev|cacheflush
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4153, 46, 45), //getsid|fdatasync
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4176, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4169, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4168, 43, 42), //mlock|munlock|mlockall|munlockall|sched_setparam|sched_getparam|sched_setscheduler|sched_getscheduler|sched_yield|sched_get_priority_max|sched_get_priority_min|sched_rr_get_interval|nanosleep|mremap
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4175, 42, 41), //bind|connect|getpeername|getsockname|getsockopt|listen
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4178, 41, 40), //recvfrom|recvmsg
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4210, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4191, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4188, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4187, 37, 36), //sendmsg|sendto|setsockopt|shutdown|socket|socketpair|setresuid|getresuid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4189, 36, 35), //poll
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4203, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4202, 34, 33), //getresgid|prctl|rt_sigreturn|rt_sigaction|rt_sigprocmask|rt_sigpending|rt_sigtimedwait|rt_sigqueueinfo|rt_sigsuspend|pread64|pwrite64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4208, 33, 32), //getcwd|capget|capset|sigaltstack|sendfile
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4222, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4217, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4216, 30, 29), //mmap2|truncate64|ftruncate64|stat64|lstat64|fstat64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4221, 29, 28), //mincore|madvise|getdents64|fcntl64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4247, 28, 27), //gettid|readahead|setxattr|lsetxattr|fsetxattr|getxattr|lgetxattr|fgetxattr|listxattr|llistxattr|flistxattr|removexattr|lremovexattr|fremovexattr|tkill|sendfile64|futex|sched_setaffinity|sched_getaffinity|io_setup|io_destroy|io_getevents|io_submit|io_cancel|exit_group
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4316, 13, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4288, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4278, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4263, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4262, 23, 22), //epoll_create|epoll_ctl|epoll_wait|remap_file_pages|set_tid_address|restart_syscall|fadvise64|statfs64|fstatfs64|timer_create|timer_settime|timer_gettime|timer_getoverrun|timer_delete
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4267, 22, 21), //clock_gettime|clock_getres|clock_nanosleep|tgkill
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4283, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4279, 20, 19), //waitid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4287, 19, 18), //set_thread_area|inotify_init|inotify_add_watch|inotify_rm_watch
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4312, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4293, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4292, 16, 15), //openat|mkdirat|mknodat|fchownat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4308, 15, 14), //fstatat64|unlinkat|renameat|linkat|symlinkat|readlinkat|fchmodat|faccessat|pselect6|ppoll|unshare|splice|sync_file_range|tee|vmsplice
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4314, 14, 13), //getcpu|epoll_pwait
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4349, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4338, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4319, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4317, 10, 9), //utimensat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4336, 9, 8), //eventfd|fallocate|timerfd_create|timerfd_gettime|timerfd_settime|signalfd4|eventfd2|epoll_create1|dup3|pipe2|inotify_init1|preadv|pwritev|rt_tgsigqueueinfo|perf_event_open|accept4|recvmmsg
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4342, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4339, 7, 6), //prlimit64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4347, 6, 5), //syncfs|sendmmsg|setns|process_vm_readv|process_vm_writev
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4359, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4356, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4355, 3, 2), //sched_setattr|sched_getattr|renameat2|seccomp|getrandom|memfd_create
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4357, 2, 1), //execveat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4363, 1, 0), //mlock2|copy_file_range|preadv2|pwritev2
-BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW),
-};
-
-const size_t mips_app_filter_size = sizeof(mips_app_filter) / sizeof(struct sock_filter);
diff --git a/libc/seccomp/mips_global_policy.cpp b/libc/seccomp/mips_global_policy.cpp
deleted file mode 100644
index b193c09..0000000
--- a/libc/seccomp/mips_global_policy.cpp
+++ /dev/null
@@ -1,121 +0,0 @@
-// Autogenerated file - edit at your peril!!
-
-#include <linux/filter.h>
-#include <errno.h>
-
-#include "seccomp_bpfs.h"
-const sock_filter mips_global_filter[] = {
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4001, 0, 110),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4131, 55, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4063, 27, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4036, 13, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4023, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4010, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4008, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4007, 103, 102), //exit|fork|read|write|open|close
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4009, 102, 101), //creat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4019, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4013, 100, 99), //unlink|execve|chdir
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4022, 99, 98), //lseek|getpid|mount
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4033, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4026, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4025, 96, 95), //setuid|getuid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4027, 95, 94), //ptrace
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4034, 94, 93), //access
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4054, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4045, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4041, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4040, 90, 89), //sync|kill|rename|mkdir
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4044, 89, 88), //dup|pipe|times
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4049, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4048, 87, 86), //brk|setgid|getgid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4053, 86, 85), //geteuid|getegid|acct|umount2
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4060, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4057, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4056, 83, 82), //ioctl|fcntl
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4058, 82, 81), //setpgid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4062, 81, 80), //umask|chroot
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4094, 13, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4085, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4070, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4066, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4065, 76, 75), //dup2|getppid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4068, 75, 74), //setsid|sigaction
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4074, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4072, 73, 72), //setreuid|setregid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4082, 72, 71), //sethostname|setrlimit|getrlimit|getrusage|gettimeofday|settimeofday|getgroups|setgroups
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4090, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4087, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4086, 69, 68), //readlink
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4089, 68, 67), //swapon|reboot
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4093, 67, 66), //mmap|munmap|truncate
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4118, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4114, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4103, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4098, 63, 62), //fchmod|fchown|getpriority|setpriority
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4106, 62, 61), //syslog|setitimer|getitimer
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4116, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4115, 60, 59), //wait4
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4117, 59, 58), //sysinfo
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4128, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4124, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4123, 56, 55), //fsync|sigreturn|clone|setdomainname|uname
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4126, 55, 54), //adjtimex|mprotect
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4130, 54, 53), //init_module|delete_module
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4248, 27, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4179, 13, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4154, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4138, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4136, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4134, 48, 47), //quotactl|getpgid|fchdir
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4137, 47, 46), //personality
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4151, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4148, 45, 44), //setfsuid|setfsgid|_llseek|getdents|_newselect|flock|msync|readv|writev|cacheflush
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4153, 44, 43), //getsid|fdatasync
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4176, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4169, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4168, 41, 40), //mlock|munlock|mlockall|munlockall|sched_setparam|sched_getparam|sched_setscheduler|sched_getscheduler|sched_yield|sched_get_priority_max|sched_get_priority_min|sched_rr_get_interval|nanosleep|mremap
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4175, 40, 39), //bind|connect|getpeername|getsockname|getsockopt|listen
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4178, 39, 38), //recvfrom|recvmsg
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4210, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4190, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4188, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4187, 35, 34), //sendmsg|sendto|setsockopt|shutdown|socket|socketpair|setresuid|getresuid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4189, 34, 33), //poll
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4203, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4202, 32, 31), //setresgid|getresgid|prctl|rt_sigreturn|rt_sigaction|rt_sigprocmask|rt_sigpending|rt_sigtimedwait|rt_sigqueueinfo|rt_sigsuspend|pread64|pwrite64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4208, 31, 30), //getcwd|capget|capset|sigaltstack|sendfile
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4222, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4217, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4216, 28, 27), //mmap2|truncate64|ftruncate64|stat64|lstat64|fstat64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4221, 27, 26), //mincore|madvise|getdents64|fcntl64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4247, 26, 25), //gettid|readahead|setxattr|lsetxattr|fsetxattr|getxattr|lgetxattr|fgetxattr|listxattr|llistxattr|flistxattr|removexattr|lremovexattr|fremovexattr|tkill|sendfile64|futex|sched_setaffinity|sched_getaffinity|io_setup|io_destroy|io_getevents|io_submit|io_cancel|exit_group
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4316, 13, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4288, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4280, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4278, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4267, 21, 20), //epoll_create|epoll_ctl|epoll_wait|remap_file_pages|set_tid_address|restart_syscall|fadvise64|statfs64|fstatfs64|timer_create|timer_settime|timer_gettime|timer_getoverrun|timer_delete|clock_settime|clock_gettime|clock_getres|clock_nanosleep|tgkill
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4279, 20, 19), //waitid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4282, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4281, 18, 17), //add_key
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4287, 17, 16), //keyctl|set_thread_area|inotify_init|inotify_add_watch|inotify_rm_watch
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4312, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4293, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4292, 14, 13), //openat|mkdirat|mknodat|fchownat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4308, 13, 12), //fstatat64|unlinkat|renameat|linkat|symlinkat|readlinkat|fchmodat|faccessat|pselect6|ppoll|unshare|splice|sync_file_range|tee|vmsplice
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4314, 12, 11), //getcpu|epoll_pwait
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4341, 5, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4338, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4319, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4317, 8, 7), //utimensat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4336, 7, 6), //eventfd|fallocate|timerfd_create|timerfd_gettime|timerfd_settime|signalfd4|eventfd2|epoll_create1|dup3|pipe2|inotify_init1|preadv|pwritev|rt_tgsigqueueinfo|perf_event_open|accept4|recvmmsg
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4339, 6, 5), //prlimit64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4359, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4348, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4347, 3, 2), //clock_adjtime|syncfs|sendmmsg|setns|process_vm_readv|process_vm_writev
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4357, 2, 1), //finit_module|sched_setattr|sched_getattr|renameat2|seccomp|getrandom|memfd_create|bpf|execveat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4363, 1, 0), //mlock2|copy_file_range|preadv2|pwritev2
-BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW),
-};
-
-const size_t mips_global_filter_size = sizeof(mips_global_filter) / sizeof(struct sock_filter);
diff --git a/libc/seccomp/mips_system_policy.cpp b/libc/seccomp/mips_system_policy.cpp
deleted file mode 100644
index 32ed567..0000000
--- a/libc/seccomp/mips_system_policy.cpp
+++ /dev/null
@@ -1,127 +0,0 @@
-// Autogenerated file - edit at your peril!!
-
-#include <linux/filter.h>
-#include <errno.h>
-
-#include "seccomp_bpfs.h"
-const sock_filter mips_system_filter[] = {
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4001, 0, 116),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4131, 57, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4064, 29, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4041, 15, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4019, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4006, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4003, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4002, 109, 108), //exit
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4005, 108, 107), //read|write
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4011, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4007, 106, 105), //close
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4013, 105, 104), //execve|chdir
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4026, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4023, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4022, 102, 101), //lseek|getpid|mount
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4025, 101, 100), //setuid|getuid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4036, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4027, 99, 98), //ptrace
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4038, 98, 97), //sync|kill
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4054, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4045, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4043, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4042, 94, 93), //dup
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4044, 93, 92), //times
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4049, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4048, 91, 90), //brk|setgid|getgid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4053, 90, 89), //geteuid|getegid|acct|umount2
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4060, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4057, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4055, 87, 86), //ioctl
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4058, 86, 85), //setpgid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4062, 85, 84), //umask|chroot
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4094, 13, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4085, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4070, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4066, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4065, 80, 79), //getppid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4068, 79, 78), //setsid|sigaction
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4074, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4072, 77, 76), //setreuid|setregid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4082, 76, 75), //sethostname|setrlimit|getrlimit|getrusage|gettimeofday|settimeofday|getgroups|setgroups
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4091, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4088, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4086, 73, 72), //readlink
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4089, 72, 71), //reboot
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4093, 71, 70), //munmap|truncate
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4118, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4114, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4103, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4098, 67, 66), //fchmod|fchown|getpriority|setpriority
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4106, 66, 65), //syslog|setitimer|getitimer
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4116, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4115, 64, 63), //wait4
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4117, 63, 62), //sysinfo
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4128, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4124, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4123, 60, 59), //fsync|sigreturn|clone|setdomainname|uname
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4126, 59, 58), //adjtimex|mprotect
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4130, 58, 57), //init_module|delete_module
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4249, 29, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4179, 15, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4151, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4138, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4136, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4134, 52, 51), //quotactl|getpgid|fchdir
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4137, 51, 50), //personality
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4143, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4141, 49, 48), //setfsuid|setfsgid|_llseek
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4148, 48, 47), //flock|msync|readv|writev|cacheflush
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4169, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4154, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4153, 45, 44), //getsid|fdatasync
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4168, 44, 43), //mlock|munlock|mlockall|munlockall|sched_setparam|sched_getparam|sched_setscheduler|sched_getscheduler|sched_yield|sched_get_priority_max|sched_get_priority_min|sched_rr_get_interval|nanosleep|mremap
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4176, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4175, 42, 41), //bind|connect|getpeername|getsockname|getsockopt|listen
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4178, 41, 40), //recvfrom|recvmsg
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4215, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4203, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4190, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4187, 37, 36), //sendmsg|sendto|setsockopt|shutdown|socket|socketpair|setresuid|getresuid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4202, 36, 35), //setresgid|getresgid|prctl|rt_sigreturn|rt_sigaction|rt_sigprocmask|rt_sigpending|rt_sigtimedwait|rt_sigqueueinfo|rt_sigsuspend|pread64|pwrite64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4210, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4208, 34, 33), //getcwd|capget|capset|sigaltstack|sendfile
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4213, 33, 32), //mmap2|truncate64|ftruncate64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4222, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4217, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4216, 30, 29), //fstat64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4221, 29, 28), //mincore|madvise|getdents64|fcntl64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4247, 28, 27), //gettid|readahead|setxattr|lsetxattr|fsetxattr|getxattr|lgetxattr|fgetxattr|listxattr|llistxattr|flistxattr|removexattr|lremovexattr|fremovexattr|tkill|sendfile64|futex|sched_setaffinity|sched_getaffinity|io_setup|io_destroy|io_getevents|io_submit|io_cancel|exit_group
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4312, 13, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4285, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4278, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4252, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4250, 23, 22), //epoll_ctl
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4267, 22, 21), //set_tid_address|restart_syscall|fadvise64|statfs64|fstatfs64|timer_create|timer_settime|timer_gettime|timer_getoverrun|timer_delete|clock_settime|clock_gettime|clock_getres|clock_nanosleep|tgkill
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4283, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4279, 20, 19), //waitid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4284, 19, 18), //set_thread_area
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4293, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4288, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4287, 16, 15), //inotify_add_watch|inotify_rm_watch
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4292, 15, 14), //openat|mkdirat|mknodat|fchownat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4308, 14, 13), //fstatat64|unlinkat|renameat|linkat|symlinkat|readlinkat|fchmodat|faccessat|pselect6|ppoll|unshare|splice|sync_file_range|tee|vmsplice
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4341, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4320, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4316, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4314, 10, 9), //getcpu|epoll_pwait
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4317, 9, 8), //utimensat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4338, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4336, 7, 6), //fallocate|timerfd_create|timerfd_gettime|timerfd_settime|signalfd4|eventfd2|epoll_create1|dup3|pipe2|inotify_init1|preadv|pwritev|rt_tgsigqueueinfo|perf_event_open|accept4|recvmmsg
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4339, 6, 5), //prlimit64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4359, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4349, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4347, 3, 2), //clock_adjtime|syncfs|sendmmsg|setns|process_vm_readv|process_vm_writev
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4357, 2, 1), //sched_setattr|sched_getattr|renameat2|seccomp|getrandom|memfd_create|bpf|execveat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4363, 1, 0), //mlock2|copy_file_range|preadv2|pwritev2
-BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW),
-};
-
-const size_t mips_system_filter_size = sizeof(mips_system_filter) / sizeof(struct sock_filter);
diff --git a/libc/seccomp/x86_64_app_policy.cpp b/libc/seccomp/x86_64_app_policy.cpp
deleted file mode 100644
index 26a970f..0000000
--- a/libc/seccomp/x86_64_app_policy.cpp
+++ /dev/null
@@ -1,113 +0,0 @@
-// Autogenerated file - edit at your peril!!
-
-#include <linux/filter.h>
-#include <errno.h>
-
-#include "seccomp_bpfs.h"
-const sock_filter x86_64_app_filter[] = {
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 0, 0, 102),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 157, 51, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 93, 25, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 38, 13, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 24, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 3, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 2, 95, 94), //read|write
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4, 94, 93), //close
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 8, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 6, 92, 91), //fstat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 21, 91, 90), //lseek|mmap|mprotect|munmap|brk|rt_sigaction|rt_sigprocmask|rt_sigreturn|ioctl|pread64|pwrite64|readv|writev
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 35, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 32, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 29, 88, 87), //sched_yield|mremap|msync|mincore|madvise
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 33, 87, 86), //dup
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 37, 86, 85), //nanosleep|getitimer
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 72, 5, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 58, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 44, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 43, 82, 81), //setitimer|getpid|sendfile|socket|connect
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 57, 81, 80), //sendto|recvfrom|sendmsg|recvmsg|shutdown|bind|listen|getsockname|getpeername|socketpair|setsockopt|getsockopt|clone
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 64, 80, 79), //vfork|execve|exit|wait4|kill|uname
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 91, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 79, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 78, 77, 76), //fcntl|flock|fsync|fdatasync|truncate|ftruncate
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 82, 76, 75), //getcwd|chdir|fchdir
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 92, 75, 74), //fchmod
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 120, 13, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 112, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 104, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 95, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 94, 70, 69), //fchown
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 103, 69, 68), //umask|gettimeofday|getrlimit|getrusage|sysinfo|times|ptrace|getuid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 107, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 105, 67, 66), //getgid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 111, 66, 65), //geteuid|getegid|setpgid|getppid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 117, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 114, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 113, 63, 62), //setsid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 116, 62, 61), //setregid|getgroups
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 119, 61, 60), //setresuid|getresuid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 137, 5, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 135, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 124, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 122, 57, 56), //getresgid|getpgid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 132, 56, 55), //getsid|capget|capset|rt_sigpending|rt_sigtimedwait|rt_sigqueueinfo|rt_sigsuspend|sigaltstack
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 136, 55, 54), //personality
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 155, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 140, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 139, 52, 51), //statfs|fstatfs
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 153, 51, 50), //getpriority|setpriority|sched_setparam|sched_getparam|sched_setscheduler|sched_getscheduler|sched_get_priority_max|sched_get_priority_min|sched_rr_get_interval|mlock|munlock|mlockall|munlockall
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 156, 50, 49), //pivot_root
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 254, 25, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 217, 13, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 186, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 162, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 160, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 159, 44, 43), //prctl|arch_prctl
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 161, 43, 42), //setrlimit
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 179, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 163, 41, 40), //sync
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 180, 40, 39), //quotactl
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 206, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 202, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 201, 37, 36), //gettid|readahead|setxattr|lsetxattr|fsetxattr|getxattr|lgetxattr|fgetxattr|listxattr|llistxattr|flistxattr|removexattr|lremovexattr|fremovexattr|tkill
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 205, 36, 35), //futex|sched_setaffinity|sched_getaffinity
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 211, 35, 34), //io_setup|io_destroy|io_getevents|io_submit|io_cancel
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 233, 5, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 228, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 221, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 220, 31, 30), //getdents64|set_tid_address|restart_syscall
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 227, 30, 29), //fadvise64|timer_create|timer_settime|timer_gettime|timer_getoverrun|timer_delete
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 232, 29, 28), //clock_gettime|clock_getres|clock_nanosleep|exit_group
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 251, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 247, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 235, 26, 25), //epoll_ctl|tgkill
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 248, 25, 24), //waitid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 253, 24, 23), //ioprio_set|ioprio_get
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 285, 11, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 275, 5, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 262, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 257, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 256, 19, 18), //inotify_add_watch|inotify_rm_watch
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 261, 18, 17), //openat|mkdirat|mknodat|fchownat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 273, 17, 16), //newfstatat|unlinkat|renameat|linkat|symlinkat|readlinkat|fchmodat|faccessat|pselect6|ppoll|unshare
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 283, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 280, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 279, 14, 13), //splice|tee|sync_file_range|vmsplice
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 282, 13, 12), //utimensat|epoll_pwait
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 284, 12, 11), //timerfd_create
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 314, 5, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 306, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 302, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 300, 8, 7), //fallocate|timerfd_settime|timerfd_gettime|accept4|signalfd4|eventfd2|epoll_create1|dup3|pipe2|inotify_init1|preadv|pwritev|rt_tgsigqueueinfo|perf_event_open|recvmmsg
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 303, 7, 6), //prlimit64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 312, 6, 5), //syncfs|sendmmsg|setns|getcpu|process_vm_readv|process_vm_writev
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 325, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 322, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 320, 3, 2), //sched_setattr|sched_getattr|renameat2|seccomp|getrandom|memfd_create
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 323, 2, 1), //execveat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 329, 1, 0), //mlock2|copy_file_range|preadv2|pwritev2
-BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW),
-};
-
-const size_t x86_64_app_filter_size = sizeof(x86_64_app_filter) / sizeof(struct sock_filter);
diff --git a/libc/seccomp/x86_64_global_policy.cpp b/libc/seccomp/x86_64_global_policy.cpp
deleted file mode 100644
index 8142ce4..0000000
--- a/libc/seccomp/x86_64_global_policy.cpp
+++ /dev/null
@@ -1,99 +0,0 @@
-// Autogenerated file - edit at your peril!!
-
-#include <linux/filter.h>
-#include <errno.h>
-
-#include "seccomp_bpfs.h"
-const sock_filter x86_64_global_filter[] = {
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 0, 0, 88),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 175, 43, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 79, 21, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 35, 11, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 8, 5, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 3, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 2, 81, 80), //read|write
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4, 80, 79), //close
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 6, 79, 78), //fstat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 32, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 24, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 21, 76, 75), //lseek|mmap|mprotect|munmap|brk|rt_sigaction|rt_sigprocmask|rt_sigreturn|ioctl|pread64|pwrite64|readv|writev
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 29, 75, 74), //sched_yield|mremap|msync|mincore|madvise
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 33, 74, 73), //dup
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 58, 5, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 44, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 38, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 37, 70, 69), //nanosleep|getitimer
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 43, 69, 68), //setitimer|getpid|sendfile|socket|connect
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 57, 68, 67), //sendto|recvfrom|sendmsg|recvmsg|shutdown|bind|listen|getsockname|getpeername|socketpair|setsockopt|getsockopt|clone
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 72, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 64, 66, 65), //vfork|execve|exit|wait4|kill|uname
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 78, 65, 64), //fcntl|flock|fsync|fdatasync|truncate|ftruncate
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 137, 11, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 95, 5, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 93, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 91, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 82, 60, 59), //getcwd|chdir|fchdir
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 92, 59, 58), //fchmod
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 94, 58, 57), //fchown
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 135, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 112, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 111, 55, 54), //umask|gettimeofday|getrlimit|getrusage|sysinfo|times|ptrace|getuid|syslog|getgid|setuid|setgid|geteuid|getegid|setpgid|getppid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 132, 54, 53), //setsid|setreuid|setregid|getgroups|setgroups|setresuid|getresuid|setresgid|getresgid|getpgid|setfsuid|setfsgid|getsid|capget|capset|rt_sigpending|rt_sigtimedwait|rt_sigqueueinfo|rt_sigsuspend|sigaltstack
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 136, 53, 52), //personality
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 157, 5, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 155, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 140, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 139, 49, 48), //statfs|fstatfs
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 153, 48, 47), //getpriority|setpriority|sched_setparam|sched_getparam|sched_setscheduler|sched_getscheduler|sched_get_priority_max|sched_get_priority_min|sched_rr_get_interval|mlock|munlock|mlockall|munlockall
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 156, 47, 46), //pivot_root
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 169, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 168, 45, 44), //prctl|arch_prctl|adjtimex|setrlimit|chroot|sync|acct|settimeofday|mount|umount2|swapon
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 172, 44, 43), //reboot|sethostname|setdomainname
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 257, 21, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 221, 11, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 202, 5, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 186, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 179, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 177, 38, 37), //init_module|delete_module
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 180, 37, 36), //quotactl
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 201, 36, 35), //gettid|readahead|setxattr|lsetxattr|fsetxattr|getxattr|lgetxattr|fgetxattr|listxattr|llistxattr|flistxattr|removexattr|lremovexattr|fremovexattr|tkill
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 217, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 206, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 205, 33, 32), //futex|sched_setaffinity|sched_getaffinity
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 211, 32, 31), //io_setup|io_destroy|io_getevents|io_submit|io_cancel
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 220, 31, 30), //getdents64|set_tid_address|restart_syscall
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 250, 5, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 247, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 233, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 232, 27, 26), //fadvise64|timer_create|timer_settime|timer_gettime|timer_getoverrun|timer_delete|clock_settime|clock_gettime|clock_getres|clock_nanosleep|exit_group
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 235, 26, 25), //epoll_ctl|tgkill
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 249, 25, 24), //waitid|add_key
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 254, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 253, 23, 22), //keyctl|ioprio_set|ioprio_get
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 256, 22, 21), //inotify_add_watch|inotify_rm_watch
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 302, 11, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 280, 5, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 275, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 262, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 261, 17, 16), //openat|mkdirat|mknodat|fchownat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 273, 16, 15), //newfstatat|unlinkat|renameat|linkat|symlinkat|readlinkat|fchmodat|faccessat|pselect6|ppoll|unshare
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 279, 15, 14), //splice|tee|sync_file_range|vmsplice
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 285, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 283, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 282, 12, 11), //utimensat|epoll_pwait
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 284, 11, 10), //timerfd_create
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 300, 10, 9), //fallocate|timerfd_settime|timerfd_gettime|accept4|signalfd4|eventfd2|epoll_create1|dup3|pipe2|inotify_init1|preadv|pwritev|rt_tgsigqueueinfo|perf_event_open|recvmmsg
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 321, 5, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 313, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 305, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 303, 6, 5), //prlimit64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 312, 5, 4), //clock_adjtime|syncfs|sendmmsg|setns|getcpu|process_vm_readv|process_vm_writev
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 320, 4, 3), //finit_module|sched_setattr|sched_getattr|renameat2|seccomp|getrandom|memfd_create
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 325, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 323, 2, 1), //bpf|execveat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 329, 1, 0), //mlock2|copy_file_range|preadv2|pwritev2
-BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW),
-};
-
-const size_t x86_64_global_filter_size = sizeof(x86_64_global_filter) / sizeof(struct sock_filter);
diff --git a/libc/seccomp/x86_64_system_policy.cpp b/libc/seccomp/x86_64_system_policy.cpp
deleted file mode 100644
index 67859eb..0000000
--- a/libc/seccomp/x86_64_system_policy.cpp
+++ /dev/null
@@ -1,99 +0,0 @@
-// Autogenerated file - edit at your peril!!
-
-#include <linux/filter.h>
-#include <errno.h>
-
-#include "seccomp_bpfs.h"
-const sock_filter x86_64_system_filter[] = {
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 0, 0, 88),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 175, 43, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 79, 21, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 35, 11, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 8, 5, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 3, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 2, 81, 80), //read|write
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4, 80, 79), //close
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 6, 79, 78), //fstat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 32, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 24, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 21, 76, 75), //lseek|mmap|mprotect|munmap|brk|rt_sigaction|rt_sigprocmask|rt_sigreturn|ioctl|pread64|pwrite64|readv|writev
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 29, 75, 74), //sched_yield|mremap|msync|mincore|madvise
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 33, 74, 73), //dup
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 58, 5, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 44, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 38, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 37, 70, 69), //nanosleep|getitimer
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 43, 69, 68), //setitimer|getpid|sendfile|socket|connect
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 57, 68, 67), //sendto|recvfrom|sendmsg|recvmsg|shutdown|bind|listen|getsockname|getpeername|socketpair|setsockopt|getsockopt|clone
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 72, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 64, 66, 65), //vfork|execve|exit|wait4|kill|uname
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 78, 65, 64), //fcntl|flock|fsync|fdatasync|truncate|ftruncate
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 137, 11, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 95, 5, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 93, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 91, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 82, 60, 59), //getcwd|chdir|fchdir
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 92, 59, 58), //fchmod
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 94, 58, 57), //fchown
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 135, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 112, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 111, 55, 54), //umask|gettimeofday|getrlimit|getrusage|sysinfo|times|ptrace|getuid|syslog|getgid|setuid|setgid|geteuid|getegid|setpgid|getppid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 132, 54, 53), //setsid|setreuid|setregid|getgroups|setgroups|setresuid|getresuid|setresgid|getresgid|getpgid|setfsuid|setfsgid|getsid|capget|capset|rt_sigpending|rt_sigtimedwait|rt_sigqueueinfo|rt_sigsuspend|sigaltstack
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 136, 53, 52), //personality
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 157, 5, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 155, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 140, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 139, 49, 48), //statfs|fstatfs
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 153, 48, 47), //getpriority|setpriority|sched_setparam|sched_getparam|sched_setscheduler|sched_getscheduler|sched_get_priority_max|sched_get_priority_min|sched_rr_get_interval|mlock|munlock|mlockall|munlockall
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 156, 47, 46), //pivot_root
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 169, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 167, 45, 44), //prctl|arch_prctl|adjtimex|setrlimit|chroot|sync|acct|settimeofday|mount|umount2
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 172, 44, 43), //reboot|sethostname|setdomainname
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 257, 21, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 221, 11, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 202, 5, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 186, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 179, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 177, 38, 37), //init_module|delete_module
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 180, 37, 36), //quotactl
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 201, 36, 35), //gettid|readahead|setxattr|lsetxattr|fsetxattr|getxattr|lgetxattr|fgetxattr|listxattr|llistxattr|flistxattr|removexattr|lremovexattr|fremovexattr|tkill
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 217, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 206, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 205, 33, 32), //futex|sched_setaffinity|sched_getaffinity
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 211, 32, 31), //io_setup|io_destroy|io_getevents|io_submit|io_cancel
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 220, 31, 30), //getdents64|set_tid_address|restart_syscall
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 251, 5, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 247, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 233, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 232, 27, 26), //fadvise64|timer_create|timer_settime|timer_gettime|timer_getoverrun|timer_delete|clock_settime|clock_gettime|clock_getres|clock_nanosleep|exit_group
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 235, 26, 25), //epoll_ctl|tgkill
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 248, 25, 24), //waitid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 254, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 253, 23, 22), //ioprio_set|ioprio_get
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 256, 22, 21), //inotify_add_watch|inotify_rm_watch
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 302, 11, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 280, 5, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 275, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 262, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 261, 17, 16), //openat|mkdirat|mknodat|fchownat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 273, 16, 15), //newfstatat|unlinkat|renameat|linkat|symlinkat|readlinkat|fchmodat|faccessat|pselect6|ppoll|unshare
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 279, 15, 14), //splice|tee|sync_file_range|vmsplice
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 285, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 283, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 282, 12, 11), //utimensat|epoll_pwait
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 284, 11, 10), //timerfd_create
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 300, 10, 9), //fallocate|timerfd_settime|timerfd_gettime|accept4|signalfd4|eventfd2|epoll_create1|dup3|pipe2|inotify_init1|preadv|pwritev|rt_tgsigqueueinfo|perf_event_open|recvmmsg
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 321, 5, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 314, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 305, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 303, 6, 5), //prlimit64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 312, 5, 4), //clock_adjtime|syncfs|sendmmsg|setns|getcpu|process_vm_readv|process_vm_writev
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 320, 4, 3), //sched_setattr|sched_getattr|renameat2|seccomp|getrandom|memfd_create
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 325, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 323, 2, 1), //bpf|execveat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 329, 1, 0), //mlock2|copy_file_range|preadv2|pwritev2
-BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW),
-};
-
-const size_t x86_64_system_filter_size = sizeof(x86_64_system_filter) / sizeof(struct sock_filter);
diff --git a/libc/seccomp/x86_app_policy.cpp b/libc/seccomp/x86_app_policy.cpp
deleted file mode 100644
index 1cea07e..0000000
--- a/libc/seccomp/x86_app_policy.cpp
+++ /dev/null
@@ -1,131 +0,0 @@
-// Autogenerated file - edit at your peril!!
-
-#include <linux/filter.h>
-#include <errno.h>
-
-#include "seccomp_bpfs.h"
-const sock_filter x86_app_filter[] = {
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 0, 0, 120),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 140, 59, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 75, 29, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 41, 15, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 24, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 10, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 8, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 7, 113, 112), //restart_syscall|exit|fork|read|write|open|close
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 9, 112, 111), //creat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 19, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 13, 110, 109), //unlink|execve|chdir
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 21, 109, 108), //lseek|getpid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 33, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 26, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 25, 106, 105), //getuid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 27, 105, 104), //ptrace
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 36, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 34, 103, 102), //access
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 40, 102, 101), //sync|kill|rename|mkdir
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 60, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 54, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 45, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 44, 98, 97), //dup|pipe|times
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 46, 97, 96), //brk
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 57, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 56, 95, 94), //ioctl|fcntl
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 58, 94, 93), //setpgid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 66, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 63, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 61, 91, 90), //umask
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 65, 90, 89), //dup2|getppid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 68, 89, 88), //setsid|sigaction
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 114, 15, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 94, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 85, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 77, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 76, 84, 83), //setrlimit
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 79, 83, 82), //getrusage|gettimeofday
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 90, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 86, 81, 80), //readlink
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 93, 80, 79), //mmap|munmap|truncate
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 102, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 96, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 95, 77, 76), //fchmod
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 98, 76, 75), //getpriority|setpriority
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 104, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 103, 74, 73), //socketcall
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 106, 73, 72), //setitimer|getitimer
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 125, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 118, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 116, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 115, 69, 68), //wait4
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 117, 68, 67), //sysinfo
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 122, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 121, 66, 65), //fsync|sigreturn|clone
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 123, 65, 64), //uname
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 136, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 131, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 126, 62, 61), //mprotect
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 134, 61, 60), //quotactl|getpgid|fchdir
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 137, 60, 59), //personality
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 265, 29, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 207, 15, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 183, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 168, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 150, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 149, 54, 53), //_llseek|getdents|_newselect|flock|msync|readv|writev|getsid|fdatasync
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 164, 53, 52), //mlock|munlock|mlockall|munlockall|sched_setparam|sched_getparam|sched_setscheduler|sched_getscheduler|sched_yield|sched_get_priority_max|sched_get_priority_min|sched_rr_get_interval|nanosleep|mremap
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 172, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 169, 51, 50), //poll
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 182, 50, 49), //prctl|rt_sigreturn|rt_sigaction|rt_sigprocmask|rt_sigpending|rt_sigtimedwait|rt_sigqueueinfo|rt_sigsuspend|pread64|pwrite64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 199, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 190, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 188, 47, 46), //getcwd|capget|capset|sigaltstack|sendfile
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 198, 46, 45), //vfork|ugetrlimit|mmap2|truncate64|ftruncate64|stat64|lstat64|fstat64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 204, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 203, 44, 43), //getuid32|getgid32|geteuid32|getegid32
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 206, 43, 42), //setregid32|getgroups32
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 245, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 218, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 211, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 210, 39, 38), //fchown32|setresuid32|getresuid32
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 212, 38, 37), //getresgid32
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 224, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 222, 36, 35), //mincore|madvise|getdents64|fcntl64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 244, 35, 34), //gettid|readahead|setxattr|lsetxattr|fsetxattr|getxattr|lgetxattr|fgetxattr|listxattr|llistxattr|flistxattr|removexattr|lremovexattr|fremovexattr|tkill|sendfile64|futex|sched_setaffinity|sched_getaffinity|set_thread_area
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 254, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 252, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 250, 32, 31), //io_setup|io_destroy|io_getevents|io_submit|io_cancel
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 253, 31, 30), //exit_group
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 264, 30, 29), //epoll_create|epoll_ctl|epoll_wait|remap_file_pages|set_tid_address|timer_create|timer_settime|timer_gettime|timer_getoverrun|timer_delete
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 322, 15, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 295, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 284, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 272, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 271, 25, 24), //clock_gettime|clock_getres|clock_nanosleep|statfs64|fstatfs64|tgkill
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 273, 24, 23), //fadvise64_64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 291, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 285, 22, 21), //waitid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 294, 21, 20), //inotify_init|inotify_add_watch|inotify_rm_watch
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 313, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 300, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 299, 18, 17), //openat|mkdirat|mknodat|fchownat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 311, 17, 16), //fstatat64|unlinkat|renameat|linkat|symlinkat|readlinkat|fchmodat|faccessat|pselect6|ppoll|unshare
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 318, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 317, 15, 14), //splice|sync_file_range|tee|vmsplice
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 321, 14, 13), //getcpu|epoll_pwait|utimensat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 351, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 344, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 340, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 337, 10, 9), //timerfd_create|eventfd|fallocate|timerfd_settime|timerfd_gettime|signalfd4|eventfd2|epoll_create1|dup3|pipe2|inotify_init1|preadv|pwritev|rt_tgsigqueueinfo|perf_event_open
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 341, 9, 8), //prlimit64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 346, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 345, 7, 6), //syncfs
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 349, 6, 5), //setns|process_vm_readv|process_vm_writev
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 376, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 358, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 357, 3, 2), //sched_setattr|sched_getattr|renameat2|seccomp|getrandom|memfd_create
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 359, 2, 1), //execveat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 380, 1, 0), //mlock2|copy_file_range|preadv2|pwritev2
-BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW),
-};
-
-const size_t x86_app_filter_size = sizeof(x86_app_filter) / sizeof(struct sock_filter);
diff --git a/libc/seccomp/x86_global_policy.cpp b/libc/seccomp/x86_global_policy.cpp
deleted file mode 100644
index 3fd06ee..0000000
--- a/libc/seccomp/x86_global_policy.cpp
+++ /dev/null
@@ -1,129 +0,0 @@
-// Autogenerated file - edit at your peril!!
-
-#include <linux/filter.h>
-#include <errno.h>
-
-#include "seccomp_bpfs.h"
-const sock_filter x86_global_filter[] = {
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 0, 0, 118),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 136, 59, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 66, 29, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 41, 15, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 24, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 10, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 8, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 7, 111, 110), //restart_syscall|exit|fork|read|write|open|close
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 9, 110, 109), //creat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 19, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 13, 108, 107), //unlink|execve|chdir
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 22, 107, 106), //lseek|getpid|mount
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 33, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 26, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 25, 104, 103), //getuid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 27, 103, 102), //ptrace
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 36, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 34, 101, 100), //access
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 40, 100, 99), //sync|kill|rename|mkdir
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 57, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 51, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 45, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 44, 96, 95), //dup|pipe|times
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 46, 95, 94), //brk
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 54, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 53, 93, 92), //acct|umount2
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 56, 92, 91), //ioctl|fcntl
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 63, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 60, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 58, 89, 88), //setpgid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 62, 88, 87), //umask|chroot
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 65, 87, 86), //dup2|getppid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 102, 15, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 87, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 77, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 74, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 68, 82, 81), //setsid|sigaction
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 76, 81, 80), //sethostname|setrlimit
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 85, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 80, 79, 78), //getrusage|gettimeofday|settimeofday
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 86, 78, 77), //readlink
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 94, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 90, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 89, 75, 74), //swapon|reboot
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 93, 74, 73), //mmap|munmap|truncate
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 96, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 95, 72, 71), //fchmod
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 98, 71, 70), //getpriority|setpriority
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 124, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 116, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 114, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 106, 67, 66), //socketcall|syslog|setitimer|getitimer
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 115, 66, 65), //wait4
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 118, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 117, 64, 63), //sysinfo
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 123, 63, 62), //fsync|sigreturn|clone|setdomainname|uname
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 131, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 128, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 126, 60, 59), //adjtimex|mprotect
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 130, 59, 58), //init_module|delete_module
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 134, 58, 57), //quotactl|getpgid|fchdir
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 284, 29, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 213, 15, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 172, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 150, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 138, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 137, 52, 51), //personality
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 149, 51, 50), //setfsuid|setfsgid|_llseek|getdents|_newselect|flock|msync|readv|writev|getsid|fdatasync
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 168, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 164, 49, 48), //mlock|munlock|mlockall|munlockall|sched_setparam|sched_getparam|sched_setscheduler|sched_getscheduler|sched_yield|sched_get_priority_max|sched_get_priority_min|sched_rr_get_interval|nanosleep|mremap
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 169, 48, 47), //poll
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 190, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 183, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 182, 45, 44), //prctl|rt_sigreturn|rt_sigaction|rt_sigprocmask|rt_sigpending|rt_sigtimedwait|rt_sigqueueinfo|rt_sigsuspend|pread64|pwrite64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 188, 44, 43), //getcwd|capget|capset|sigaltstack|sendfile
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 199, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 198, 42, 41), //vfork|ugetrlimit|mmap2|truncate64|ftruncate64|stat64|lstat64|fstat64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 212, 41, 40), //getuid32|getgid32|geteuid32|getegid32|setreuid32|setregid32|getgroups32|setgroups32|fchown32|setresuid32|getresuid32|setresgid32|getresgid32
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 252, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 224, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 218, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 215, 37, 36), //setuid32|setgid32
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 222, 36, 35), //mincore|madvise|getdents64|fcntl64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 245, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 244, 34, 33), //gettid|readahead|setxattr|lsetxattr|fsetxattr|getxattr|lgetxattr|fgetxattr|listxattr|llistxattr|flistxattr|removexattr|lremovexattr|fremovexattr|tkill|sendfile64|futex|sched_setaffinity|sched_getaffinity|set_thread_area
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 250, 33, 32), //io_setup|io_destroy|io_getevents|io_submit|io_cancel
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 272, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 254, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 253, 30, 29), //exit_group
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 271, 29, 28), //epoll_create|epoll_ctl|epoll_wait|remap_file_pages|set_tid_address|timer_create|timer_settime|timer_gettime|timer_getoverrun|timer_delete|clock_settime|clock_gettime|clock_getres|clock_nanosleep|statfs64|fstatfs64|tgkill
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 273, 28, 27), //fadvise64_64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 318, 13, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 295, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 288, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 286, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 285, 23, 22), //waitid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 287, 22, 21), //add_key
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 291, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 289, 20, 19), //keyctl
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 294, 19, 18), //inotify_init|inotify_add_watch|inotify_rm_watch
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 313, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 300, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 299, 16, 15), //openat|mkdirat|mknodat|fchownat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 311, 15, 14), //fstatat64|unlinkat|renameat|linkat|symlinkat|readlinkat|fchmodat|faccessat|pselect6|ppoll|unshare
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 317, 14, 13), //splice|sync_file_range|tee|vmsplice
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 346, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 340, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 322, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 321, 10, 9), //getcpu|epoll_pwait|utimensat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 337, 9, 8), //timerfd_create|eventfd|fallocate|timerfd_settime|timerfd_gettime|signalfd4|eventfd2|epoll_create1|dup3|pipe2|inotify_init1|preadv|pwritev|rt_tgsigqueueinfo|perf_event_open
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 343, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 341, 7, 6), //prlimit64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 345, 6, 5), //clock_adjtime|syncfs
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 376, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 350, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 349, 3, 2), //setns|process_vm_readv|process_vm_writev
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 359, 2, 1), //finit_module|sched_setattr|sched_getattr|renameat2|seccomp|getrandom|memfd_create|bpf|execveat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 380, 1, 0), //mlock2|copy_file_range|preadv2|pwritev2
-BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW),
-};
-
-const size_t x86_global_filter_size = sizeof(x86_global_filter) / sizeof(struct sock_filter);
diff --git a/libc/seccomp/x86_system_policy.cpp b/libc/seccomp/x86_system_policy.cpp
deleted file mode 100644
index af1b14f..0000000
--- a/libc/seccomp/x86_system_policy.cpp
+++ /dev/null
@@ -1,131 +0,0 @@
-// Autogenerated file - edit at your peril!!
-
-#include <linux/filter.h>
-#include <errno.h>
-
-#include "seccomp_bpfs.h"
-const sock_filter x86_system_filter[] = {
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 0, 0, 120),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 136, 59, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 66, 29, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 43, 15, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 19, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 6, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 3, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 2, 113, 112), //restart_syscall|exit
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5, 112, 111), //read|write
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 11, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 7, 110, 109), //close
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 13, 109, 108), //execve|chdir
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 36, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 26, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 22, 106, 105), //lseek|getpid|mount
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 27, 105, 104), //ptrace
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 41, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 38, 103, 102), //sync|kill
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 42, 102, 101), //dup
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 57, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 51, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 45, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 44, 98, 97), //times
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 46, 97, 96), //brk
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 54, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 53, 95, 94), //acct|umount2
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 55, 94, 93), //ioctl
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 64, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 60, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 58, 91, 90), //setpgid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 62, 90, 89), //umask|chroot
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 65, 89, 88), //getppid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 102, 15, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 88, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 77, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 74, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 68, 84, 83), //setsid|sigaction
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 76, 83, 82), //sethostname|setrlimit
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 85, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 80, 81, 80), //getrusage|gettimeofday|settimeofday
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 86, 80, 79), //readlink
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 94, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 91, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 89, 77, 76), //reboot
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 93, 76, 75), //munmap|truncate
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 96, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 95, 74, 73), //fchmod
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 98, 73, 72), //getpriority|setpriority
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 124, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 116, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 114, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 106, 69, 68), //socketcall|syslog|setitimer|getitimer
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 115, 68, 67), //wait4
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 118, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 117, 66, 65), //sysinfo
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 123, 65, 64), //fsync|sigreturn|clone|setdomainname|uname
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 131, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 128, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 126, 62, 61), //adjtimex|mprotect
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 130, 61, 60), //init_module|delete_module
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 134, 60, 59), //quotactl|getpgid|fchdir
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 258, 29, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 199, 15, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 172, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 143, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 138, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 137, 54, 53), //personality
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 141, 53, 52), //setfsuid|setfsgid|_llseek
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 150, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 149, 51, 50), //flock|msync|readv|writev|getsid|fdatasync
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 164, 50, 49), //mlock|munlock|mlockall|munlockall|sched_setparam|sched_getparam|sched_setscheduler|sched_getscheduler|sched_yield|sched_get_priority_max|sched_get_priority_min|sched_rr_get_interval|nanosleep|mremap
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 190, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 183, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 182, 47, 46), //prctl|rt_sigreturn|rt_sigaction|rt_sigprocmask|rt_sigpending|rt_sigtimedwait|rt_sigqueueinfo|rt_sigsuspend|pread64|pwrite64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 188, 46, 45), //getcwd|capget|capset|sigaltstack|sendfile
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 197, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 195, 44, 43), //vfork|ugetrlimit|mmap2|truncate64|ftruncate64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 198, 43, 42), //fstat64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 245, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 218, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 213, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 212, 39, 38), //getuid32|getgid32|geteuid32|getegid32|setreuid32|setregid32|getgroups32|setgroups32|fchown32|setresuid32|getresuid32|setresgid32|getresgid32
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 215, 38, 37), //setuid32|setgid32
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 224, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 222, 36, 35), //mincore|madvise|getdents64|fcntl64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 244, 35, 34), //gettid|readahead|setxattr|lsetxattr|fsetxattr|getxattr|lgetxattr|fgetxattr|listxattr|llistxattr|flistxattr|removexattr|lremovexattr|fremovexattr|tkill|sendfile64|futex|sched_setaffinity|sched_getaffinity|set_thread_area
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 255, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 252, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 250, 32, 31), //io_setup|io_destroy|io_getevents|io_submit|io_cancel
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 253, 31, 30), //exit_group
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 256, 30, 29), //epoll_ctl
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 322, 15, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 295, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 284, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 272, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 271, 25, 24), //set_tid_address|timer_create|timer_settime|timer_gettime|timer_getoverrun|timer_delete|clock_settime|clock_gettime|clock_getres|clock_nanosleep|statfs64|fstatfs64|tgkill
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 273, 24, 23), //fadvise64_64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 292, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 285, 22, 21), //waitid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 294, 21, 20), //inotify_add_watch|inotify_rm_watch
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 313, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 300, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 299, 18, 17), //openat|mkdirat|mknodat|fchownat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 311, 17, 16), //fstatat64|unlinkat|renameat|linkat|symlinkat|readlinkat|fchmodat|faccessat|pselect6|ppoll|unshare
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 318, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 317, 15, 14), //splice|sync_file_range|tee|vmsplice
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 321, 14, 13), //getcpu|epoll_pwait|utimensat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 346, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 340, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 324, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 323, 10, 9), //timerfd_create
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 337, 9, 8), //fallocate|timerfd_settime|timerfd_gettime|signalfd4|eventfd2|epoll_create1|dup3|pipe2|inotify_init1|preadv|pwritev|rt_tgsigqueueinfo|perf_event_open
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 343, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 341, 7, 6), //prlimit64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 345, 6, 5), //clock_adjtime|syncfs
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 376, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 351, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 349, 3, 2), //setns|process_vm_readv|process_vm_writev
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 359, 2, 1), //sched_setattr|sched_getattr|renameat2|seccomp|getrandom|memfd_create|bpf|execveat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 380, 1, 0), //mlock2|copy_file_range|preadv2|pwritev2
-BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW),
-};
-
-const size_t x86_system_filter_size = sizeof(x86_system_filter) / sizeof(struct sock_filter);
diff --git a/libc/stdio/printf_common.h b/libc/stdio/printf_common.h
index 85c91de..9b7c329 100644
--- a/libc/stdio/printf_common.h
+++ b/libc/stdio/printf_common.h
@@ -535,7 +535,7 @@
    */
   if (tablemax >= STATIC_ARG_TBL_SIZE) {
     *argtablesiz = sizeof(union arg) * (tablemax + 1);
-    *argtable = static_cast<arg*>(mmap(NULL, *argtablesiz,
+    *argtable = static_cast<arg*>(mmap(nullptr, *argtablesiz,
                                        PROT_WRITE | PROT_READ,
                                        MAP_ANON | MAP_PRIVATE, -1, 0));
     if (*argtable == MAP_FAILED) return -1;
@@ -629,9 +629,9 @@
   ret = -1;
 
 finish:
-  if (typetable != NULL && typetable != stattypetable) {
+  if (typetable != nullptr && typetable != stattypetable) {
     munmap(typetable, *argtablesiz);
-    typetable = NULL;
+    typetable = nullptr;
   }
   return (ret);
 }
@@ -646,13 +646,13 @@
   if (new_size < getpagesize()) new_size = getpagesize();
 
   if (*tablesize == STATIC_ARG_TBL_SIZE) {
-    *typetable = static_cast<unsigned char*>(mmap(NULL, new_size,
+    *typetable = static_cast<unsigned char*>(mmap(nullptr, new_size,
                                                   PROT_WRITE | PROT_READ,
                                                   MAP_ANON | MAP_PRIVATE, -1, 0));
     if (*typetable == MAP_FAILED) return -1;
     bcopy(old_table, *typetable, *tablesize);
   } else {
-    unsigned char* new_table = static_cast<unsigned char*>(mmap(NULL, new_size,
+    unsigned char* new_table = static_cast<unsigned char*>(mmap(nullptr, new_size,
                                                                 PROT_WRITE | PROT_READ,
                                                                 MAP_ANON | MAP_PRIVATE, -1, 0));
     if (new_table == MAP_FAILED) return -1;
@@ -695,8 +695,8 @@
     if (prec < 0) {
       memset(&mbs, 0, sizeof(mbs));
       p = wcsarg;
-      nbytes = wcsrtombs(NULL, (const wchar_t**)&p, 0, &mbs);
-      if (nbytes == (size_t)-1) return NULL;
+      nbytes = wcsrtombs(nullptr, (const wchar_t**)&p, 0, &mbs);
+      if (nbytes == (size_t)-1) return nullptr;
     } else {
       // Optimisation: if the output precision is small enough,
       // just allocate enough memory for the maximum instead of
@@ -712,17 +712,17 @@
           if (clen == 0 || clen == (size_t)-1 || nbytes + clen > (size_t)prec) break;
           nbytes += clen;
         }
-        if (clen == (size_t)-1) return NULL;
+        if (clen == (size_t)-1) return nullptr;
       }
     }
-    if ((convbuf = static_cast<char*>(malloc(nbytes + 1))) == NULL) return NULL;
+    if ((convbuf = static_cast<char*>(malloc(nbytes + 1))) == nullptr) return nullptr;
 
     // Fill the output buffer.
     p = wcsarg;
     memset(&mbs, 0, sizeof(mbs));
     if ((nbytes = wcsrtombs(convbuf, (const wchar_t**)&p, nbytes, &mbs)) == (size_t)-1) {
       free(convbuf);
-      return NULL;
+      return nullptr;
     }
     convbuf[nbytes] = '\0';
     return convbuf;
@@ -764,7 +764,7 @@
     const char* p;
     size_t insize, nchars, nconv;
 
-    if (mbsarg == NULL) return NULL;
+    if (mbsarg == nullptr) return nullptr;
 
     // Supplied argument is a multibyte string; convert it to wide characters first.
     if (prec >= 0) {
@@ -779,7 +779,7 @@
         nchars++;
         insize += nconv;
       }
-      if (nconv == (size_t)-1 || nconv == (size_t)-2) return (NULL);
+      if (nconv == (size_t)-1 || nconv == (size_t)-2) return (nullptr);
     } else {
       insize = strlen(mbsarg);
     }
@@ -788,7 +788,7 @@
     // converting at most `size' bytes of the input multibyte string to
     // wide characters for printing.
     wchar_t* convbuf = static_cast<wchar_t*>(calloc(insize + 1, sizeof(*convbuf)));
-    if (convbuf == NULL) return NULL;
+    if (convbuf == nullptr) return nullptr;
     wchar_t* wcp = convbuf;
     p = mbsarg;
     bzero(&mbs, sizeof(mbs));
@@ -802,7 +802,7 @@
     }
     if (nconv == (size_t)-1 || nconv == (size_t)-2) {
       free(convbuf);
-      return NULL;
+      return nullptr;
     }
     *wcp = '\0';
 
diff --git a/libc/stdio/stdio.cpp b/libc/stdio/stdio.cpp
index 050157b..71fdd27 100644
--- a/libc/stdio/stdio.cpp
+++ b/libc/stdio/stdio.cpp
@@ -1178,8 +1178,6 @@
 }
 
 FILE* popen(const char* cmd, const char* mode) {
-  bool close_on_exec = (strchr(mode, 'e') != nullptr);
-
   // Was the request for a socketpair or just a pipe?
   int fds[2];
   bool bidirectional = false;
@@ -1231,8 +1229,6 @@
   FILE* fp = fdopen(fds[parent], mode);
   if (fp == nullptr) return __popen_fail(fds);
 
-  // The caller didn't ask for their pipe to be O_CLOEXEC, so flip it back now the child has forked.
-  if (!close_on_exec) fcntl(fds[parent], F_SETFD, 0);
   close(fds[child]);
 
   _EXT(fp)->_popen_pid = pid;
diff --git a/libc/stdio/stdio_ext.cpp b/libc/stdio/stdio_ext.cpp
index e17b62a..945813e 100644
--- a/libc/stdio/stdio_ext.cpp
+++ b/libc/stdio/stdio_ext.cpp
@@ -69,7 +69,7 @@
 
 void _flushlbf() {
   // If we flush all streams, we know we've flushed all the line-buffered streams.
-  fflush(NULL);
+  fflush(nullptr);
 }
 
 void __fseterr(FILE* fp) {
diff --git a/libc/stdio/vfprintf.cpp b/libc/stdio/vfprintf.cpp
index 17e4372..7a67868 100644
--- a/libc/stdio/vfprintf.cpp
+++ b/libc/stdio/vfprintf.cpp
@@ -64,7 +64,7 @@
    * D:	expchar holds this character; '\0' if no exponent, e.g. %f
    * F:	at least two digits for decimal, at least one digit for hex
    */
-  char* decimal_point = NULL;
+  char* decimal_point = nullptr;
   int signflag; /* true if float is negative */
   union {       /* floating point arguments %[aAeEfFgG] */
     double dbl;
@@ -77,7 +77,7 @@
   int lead;                   /* sig figs before decimal or group sep */
   int ndig;                   /* actual number of digits returned by dtoa */
   CHAR_TYPE expstr[MAXEXPDIG + 2]; /* buffer for exponent string: e+ZZZ */
-  char* dtoaresult = NULL;
+  char* dtoaresult = nullptr;
 
   uintmax_t _umax;             /* integer arguments %[diouxX] */
   enum { OCT, DEC, HEX } base; /* base for %[diouxX] conversion */
@@ -146,14 +146,14 @@
   }
 
   CHAR_TYPE* fmt = const_cast<CHAR_TYPE*>(fmt0);
-  argtable = NULL;
+  argtable = nullptr;
   nextarg = 1;
   va_copy(orgap, ap);
   uio.uio_iov = iovp = iov;
   uio.uio_resid = 0;
   uio.uio_iovcnt = 0;
   ret = 0;
-  convbuf = NULL;
+  convbuf = nullptr;
 
   /*
    * Scan the format for conversions (`%' character).
@@ -226,7 +226,7 @@
         }
         if (ch == '$') {
           nextarg = n;
-          if (argtable == NULL) {
+          if (argtable == nullptr) {
             argtable = statargtable;
             if (__find_arguments(fmt0, orgap, &argtable, &argtablesiz) == -1) {
               ret = -1;
@@ -261,7 +261,7 @@
         } while (is_digit(ch));
         if (ch == '$') {
           nextarg = n;
-          if (argtable == NULL) {
+          if (argtable == nullptr) {
             argtable = statargtable;
             if (__find_arguments(fmt0, orgap, &argtable, &argtablesiz) == -1) {
               ret = -1;
@@ -353,14 +353,14 @@
         if (flags & LONGDBL) {
           fparg.ldbl = GETARG(long double);
           dtoaresult = cp = __hldtoa(fparg.ldbl, xdigs, prec, &expt, &signflag, &dtoaend);
-          if (dtoaresult == NULL) {
+          if (dtoaresult == nullptr) {
             errno = ENOMEM;
             goto error;
           }
         } else {
           fparg.dbl = GETARG(double);
           dtoaresult = cp = __hdtoa(fparg.dbl, xdigs, prec, &expt, &signflag, &dtoaend);
-          if (dtoaresult == NULL) {
+          if (dtoaresult == nullptr) {
             errno = ENOMEM;
             goto error;
           }
@@ -390,14 +390,14 @@
         if (flags & LONGDBL) {
           fparg.ldbl = GETARG(long double);
           dtoaresult = cp = __ldtoa(&fparg.ldbl, expchar ? 2 : 3, prec, &expt, &signflag, &dtoaend);
-          if (dtoaresult == NULL) {
+          if (dtoaresult == nullptr) {
             errno = ENOMEM;
             goto error;
           }
         } else {
           fparg.dbl = GETARG(double);
           dtoaresult = cp = __dtoa(fparg.dbl, expchar ? 2 : 3, prec, &expt, &signflag, &dtoaend);
-          if (dtoaresult == NULL) {
+          if (dtoaresult == nullptr) {
             errno = ENOMEM;
             goto error;
           }
@@ -479,18 +479,18 @@
           wchar_t* wcp;
 
           free(convbuf);
-          convbuf = NULL;
-          if ((wcp = GETARG(wchar_t*)) == NULL) {
+          convbuf = nullptr;
+          if ((wcp = GETARG(wchar_t*)) == nullptr) {
             cp = const_cast<char*>("(null)");
           } else {
             convbuf = helpers::wcsconv(wcp, prec);
-            if (convbuf == NULL) {
+            if (convbuf == nullptr) {
               ret = -1;
               goto error;
             }
             cp = convbuf;
           }
-        } else if ((cp = GETARG(char*)) == NULL) {
+        } else if ((cp = GETARG(char*)) == nullptr) {
           cp = const_cast<char*>("(null)");
         }
         if (prec >= 0) {
@@ -625,7 +625,7 @@
     if ((flags & FPT) == 0) {
       PRINT(cp, size);
     } else { /* glue together f_p fragments */
-      if (decimal_point == NULL) decimal_point = nl_langinfo(RADIXCHAR);
+      if (decimal_point == nullptr) decimal_point = nl_langinfo(RADIXCHAR);
       if (!expchar) { /* %[fF] or sufficiently short %[gG] */
         if (expt <= 0) {
           PRINT(zeroes, 1);
@@ -676,9 +676,9 @@
 finish:
   free(convbuf);
   if (dtoaresult) __freedtoa(dtoaresult);
-  if (argtable != NULL && argtable != statargtable) {
+  if (argtable != nullptr && argtable != statargtable) {
     munmap(argtable, argtablesiz);
-    argtable = NULL;
+    argtable = nullptr;
   }
   return (ret);
 }
diff --git a/libc/stdio/vfscanf.cpp b/libc/stdio/vfscanf.cpp
index 49d6bf6..0fcdbed 100644
--- a/libc/stdio/vfscanf.cpp
+++ b/libc/stdio/vfscanf.cpp
@@ -97,7 +97,7 @@
   char buf[BUF];    /* buffer for numeric conversions */
   size_t nconv;     /* length of multibyte sequence converted */
   mbstate_t mbs;
-  void* allocation = NULL; // Allocated but unassigned result for %mc/%ms/%m[.
+  void* allocation = nullptr; // Allocated but unassigned result for %mc/%ms/%m[.
   size_t capacity = 0; // Number of char/wchar_t units allocated in `allocation`.
 
   /* `basefix' is used to avoid `if' tests in the integer scanner */
@@ -334,9 +334,9 @@
         if (flags & LONG) {
           if (flags & ALLOCATE) {
             allocation = wcp = reinterpret_cast<wchar_t*>(malloc(width * sizeof(wchar_t)));
-            if (allocation == NULL) goto allocation_failure;
+            if (allocation == nullptr) goto allocation_failure;
           } else if (flags & SUPPRESS) {
-            wcp = NULL;
+            wcp = nullptr;
           } else {
             wcp = va_arg(ap, wchar_t*);
           }
@@ -370,9 +370,9 @@
               break;
             }
           }
-          if (allocation != NULL) {
+          if (allocation != nullptr) {
             *va_arg(ap, wchar_t**) = reinterpret_cast<wchar_t*>(allocation);
-            allocation = NULL;
+            allocation = nullptr;
           }
           if (!(flags & SUPPRESS)) nassigned++;
         } else if (flags & SUPPRESS) {
@@ -397,15 +397,15 @@
         } else {
           if (flags & ALLOCATE) {
             allocation = p = reinterpret_cast<char*>(malloc(width));
-            if (allocation == NULL) goto allocation_failure;
+            if (allocation == nullptr) goto allocation_failure;
           } else {
             p = va_arg(ap, char*);
           }
           size_t r = fread(p, 1, width, fp);
           if (r == 0) goto input_failure;
-          if (allocation != NULL) {
+          if (allocation != nullptr) {
             *va_arg(ap, char**) = reinterpret_cast<char*>(allocation);
-            allocation = NULL;
+            allocation = nullptr;
           }
           nread += r;
           nassigned++;
@@ -423,9 +423,9 @@
           if (flags & ALLOCATE) {
             capacity = MIN(width, 32);
             allocation = wcp = reinterpret_cast<wchar_t*>(malloc(sizeof(wchar_t) * capacity));
-            if (allocation == NULL) goto allocation_failure;
+            if (allocation == nullptr) goto allocation_failure;
           } else if (flags & SUPPRESS) {
-            wcp = NULL;
+            wcp = nullptr;
           } else {
             wcp = va_arg(ap, wchar_t*);
           }
@@ -455,11 +455,11 @@
               }
               if (wcp) wcp[n] = wc;
               n++;
-              if (allocation != NULL && n == capacity) {
+              if (allocation != nullptr && n == capacity) {
                 capacity *= 2;
                 wchar_t* new_allocation =
                     reinterpret_cast<wchar_t*>(realloc(allocation, sizeof(wchar_t) * capacity));
-                if (new_allocation == NULL) goto allocation_failure;
+                if (new_allocation == nullptr) goto allocation_failure;
                 allocation = wcp = new_allocation;
               }
               nread += bytes;
@@ -478,9 +478,9 @@
             fp->_flags |= __SERR;
             goto input_failure;
           }
-          if (allocation != NULL) {
+          if (allocation != nullptr) {
             *va_arg(ap, wchar_t**) = reinterpret_cast<wchar_t*>(allocation);
-            allocation = NULL;
+            allocation = nullptr;
           }
         } else if (flags & SUPPRESS) {
           n = 0;
@@ -497,7 +497,7 @@
           if (flags & ALLOCATE) {
             capacity = MIN(width, 32);
             allocation = p = reinterpret_cast<char*>(malloc(capacity));
-            if (allocation == NULL) goto allocation_failure;
+            if (allocation == nullptr) goto allocation_failure;
           } else {
             p = va_arg(ap, char*);
           }
@@ -505,10 +505,10 @@
           while (ccltab[*fp->_p]) {
             fp->_r--;
             p[n++] = *fp->_p++;
-            if (allocation != NULL && n == capacity) {
+            if (allocation != nullptr && n == capacity) {
               capacity *= 2;
               char* new_allocation = reinterpret_cast<char*>(realloc(allocation, capacity));
-              if (new_allocation == NULL) goto allocation_failure;
+              if (new_allocation == nullptr) goto allocation_failure;
               allocation = p = new_allocation;
             }
             if (--width == 0) break;
@@ -518,9 +518,9 @@
             }
           }
           nread += n;
-          if (allocation != NULL) {
+          if (allocation != nullptr) {
             *va_arg(ap, char**) = reinterpret_cast<char*>(allocation);
-            allocation = NULL;
+            allocation = nullptr;
           }
         }
         if (c == CT_CCL && n == 0) goto match_failure;
@@ -671,9 +671,9 @@
 
           *p = '\0';
           if (flags & UNSIGNED) {
-            res = strtoumax(buf, NULL, base);
+            res = strtoumax(buf, nullptr, base);
           } else {
-            res = strtoimax(buf, NULL, base);
+            res = strtoimax(buf, nullptr, base);
           }
           if (flags & POINTER) {
             *va_arg(ap, void**) = (void*)(uintptr_t)res;
diff --git a/libc/stdio/vfwprintf.cpp b/libc/stdio/vfwprintf.cpp
index 46b6233..ae0b62f 100644
--- a/libc/stdio/vfwprintf.cpp
+++ b/libc/stdio/vfwprintf.cpp
@@ -64,7 +64,7 @@
    * D:	expchar holds this character; '\0' if no exponent, e.g. %f
    * F:	at least two digits for decimal, at least one digit for hex
    */
-  char* decimal_point = NULL;
+  char* decimal_point = nullptr;
   int signflag; /* true if float is negative */
   union {       /* floating point arguments %[aAeEfFgG] */
     double dbl;
@@ -77,7 +77,7 @@
   int lead;                      /* sig figs before decimal or group sep */
   int ndig;                      /* actual number of digits returned by dtoa */
   CHAR_TYPE expstr[MAXEXPDIG + 2]; /* buffer for exponent string: e+ZZZ */
-  char* dtoaresult = NULL;
+  char* dtoaresult = nullptr;
 
   uintmax_t _umax;             /* integer arguments %[diouxX] */
   enum { OCT, DEC, HEX } base; /* base for %[diouxX] conversion */
@@ -135,14 +135,14 @@
   }
 
   CHAR_TYPE* fmt = const_cast<CHAR_TYPE*>(fmt0);
-  argtable = NULL;
+  argtable = nullptr;
   nextarg = 1;
   va_copy(orgap, ap);
   uio.uio_iov = iovp = iov;
   uio.uio_resid = 0;
   uio.uio_iovcnt = 0;
   ret = 0;
-  convbuf = NULL;
+  convbuf = nullptr;
 
   /*
    * Scan the format for conversions (`%' character).
@@ -215,7 +215,7 @@
         }
         if (ch == '$') {
           nextarg = n;
-          if (argtable == NULL) {
+          if (argtable == nullptr) {
             argtable = statargtable;
             if (__find_arguments(fmt0, orgap, &argtable, &argtablesiz) == -1) {
               ret = -1;
@@ -250,7 +250,7 @@
         } while (is_digit(ch));
         if (ch == '$') {
           nextarg = n;
-          if (argtable == NULL) {
+          if (argtable == nullptr) {
             argtable = statargtable;
             if (__find_arguments(fmt0, orgap, &argtable, &argtablesiz) == -1) {
               ret = -1;
@@ -331,14 +331,14 @@
         if (flags & LONGDBL) {
           fparg.ldbl = GETARG(long double);
           dtoaresult = __hldtoa(fparg.ldbl, xdigs, prec, &expt, &signflag, &dtoaend);
-          if (dtoaresult == NULL) {
+          if (dtoaresult == nullptr) {
             errno = ENOMEM;
             goto error;
           }
         } else {
           fparg.dbl = GETARG(double);
           dtoaresult = __hdtoa(fparg.dbl, xdigs, prec, &expt, &signflag, &dtoaend);
-          if (dtoaresult == NULL) {
+          if (dtoaresult == nullptr) {
             errno = ENOMEM;
             goto error;
           }
@@ -347,7 +347,7 @@
         if (expt == INT_MAX) ox[1] = '\0';
         free(convbuf);
         cp = convbuf = helpers::mbsconv(dtoaresult, -1);
-        if (cp == NULL) goto error;
+        if (cp == nullptr) goto error;
         ndig = dtoaend - dtoaresult;
         goto fp_common;
       case 'e':
@@ -372,14 +372,14 @@
         if (flags & LONGDBL) {
           fparg.ldbl = GETARG(long double);
           dtoaresult = __ldtoa(&fparg.ldbl, expchar ? 2 : 3, prec, &expt, &signflag, &dtoaend);
-          if (dtoaresult == NULL) {
+          if (dtoaresult == nullptr) {
             errno = ENOMEM;
             goto error;
           }
         } else {
           fparg.dbl = GETARG(double);
           dtoaresult = __dtoa(fparg.dbl, expchar ? 2 : 3, prec, &expt, &signflag, &dtoaend);
-          if (dtoaresult == NULL) {
+          if (dtoaresult == nullptr) {
             errno = ENOMEM;
             goto error;
           }
@@ -387,7 +387,7 @@
         }
         free(convbuf);
         cp = convbuf = helpers::mbsconv(dtoaresult, -1);
-        if (cp == NULL) goto error;
+        if (cp == nullptr) goto error;
         ndig = dtoaend - dtoaresult;
       fp_common:
         if (signflag) sign = '-';
@@ -461,13 +461,13 @@
         /*FALLTHROUGH*/
       case 's':
         if (flags & LONGINT) {
-          if ((cp = GETARG(wchar_t*)) == NULL) cp = const_cast<wchar_t*>(L"(null)");
+          if ((cp = GETARG(wchar_t*)) == nullptr) cp = const_cast<wchar_t*>(L"(null)");
         } else {
           char* mbsarg;
-          if ((mbsarg = GETARG(char*)) == NULL) mbsarg = const_cast<char*>("(null)");
+          if ((mbsarg = GETARG(char*)) == nullptr) mbsarg = const_cast<char*>("(null)");
           free(convbuf);
           convbuf = helpers::mbsconv(mbsarg, prec);
-          if (convbuf == NULL) {
+          if (convbuf == nullptr) {
             fp->_flags |= __SERR;
             goto error;
           } else {
@@ -606,7 +606,7 @@
     if ((flags & FPT) == 0) {
       PRINT(cp, size);
     } else { /* glue together f_p fragments */
-      if (decimal_point == NULL) decimal_point = nl_langinfo(RADIXCHAR);
+      if (decimal_point == nullptr) decimal_point = nl_langinfo(RADIXCHAR);
       if (!expchar) { /* %[fF] or sufficiently short %[gG] */
         if (expt <= 0) {
           PRINT(zeroes, 1);
@@ -654,9 +654,9 @@
 finish:
   free(convbuf);
   if (dtoaresult) __freedtoa(dtoaresult);
-  if (argtable != NULL && argtable != statargtable) {
+  if (argtable != nullptr && argtable != statargtable) {
     munmap(argtable, argtablesiz);
-    argtable = NULL;
+    argtable = nullptr;
   }
   return (ret);
 }
diff --git a/libc/system_properties/system_properties.cpp b/libc/system_properties/system_properties.cpp
index d5c3647..d7c441b 100644
--- a/libc/system_properties/system_properties.cpp
+++ b/libc/system_properties/system_properties.cpp
@@ -214,7 +214,7 @@
 int SystemProperties::Get(const char* name, char* value) {
   const prop_info* pi = Find(name);
 
-  if (pi != 0) {
+  if (pi != nullptr) {
     return Read(pi, nullptr, value);
   } else {
     value[0] = 0;
diff --git a/libc/tools/generate-NOTICE.py b/libc/tools/generate-NOTICE.py
index e59fc7a..17429e1 100755
--- a/libc/tools/generate-NOTICE.py
+++ b/libc/tools/generate-NOTICE.py
@@ -96,6 +96,8 @@
         line = re.sub("^ \* ", "", line)
         line = line.replace("** ", "")
         line = line.replace("# ", "")
+        if "SPDX-License-Identifier:" in line:
+            continue
         if line.startswith("++Copyright++"):
             continue
         line = line.replace("--Copyright--", "")
diff --git a/libc/tools/genseccomp.py b/libc/tools/genseccomp.py
index 63d9f20..365e198 100755
--- a/libc/tools/genseccomp.py
+++ b/libc/tools/genseccomp.py
@@ -1,9 +1,14 @@
 #!/usr/bin/env python
+
+import argparse
 import collections
+import logging
 import os
+import re
+import subprocess
 import textwrap
+
 from gensyscalls import SysCallsTxtParser
-from subprocess import Popen, PIPE
 
 
 BPF_JGE = "BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, {0}, {1}, {2})"
@@ -35,48 +40,47 @@
 def merge_names(base_names, whitelist_names, blacklist_names):
   if bool(blacklist_names - base_names):
     raise RuntimeError("Blacklist item not in bionic - aborting " + str(
-        blacklist_name - base_names))
+        blacklist_names - base_names))
 
   return (base_names - blacklist_names) | whitelist_names
 
 
-def convert_names_to_NRs(names, header_dir, extra_switches):
-  # Run preprocessor over the __NR_syscall symbols, including unistd.h,
-  # to get the actual numbers
-  prefix = "__SECCOMP_"  # prefix to ensure no name collisions
-  cpp = Popen(["../../prebuilts/clang/host/linux-x86/clang-stable/bin/clang",
-               "-E", "-nostdinc", "-I" + header_dir, "-Ikernel/uapi/"]
-               + extra_switches
-               + ["-"],
-              stdin=PIPE, stdout=PIPE)
-  cpp.stdin.write("#include <asm/unistd.h>\n")
-  for name in names:
-    # In SYSCALLS.TXT, there are two arm-specific syscalls whose names start
-    # with __ARM__NR_. These we must simply write out as is.
-    if not name.startswith("__ARM_NR_"):
-      cpp.stdin.write(prefix + name + ", __NR_" + name + "\n")
-    else:
-      cpp.stdin.write(prefix + name + ", " + name + "\n")
-  content = cpp.communicate()[0].split("\n")
-
+def parse_syscall_NRs(names_path):
   # The input is now the preprocessed source file. This will contain a lot
   # of junk from the preprocessor, but our lines will be in the format:
   #
-  #     __SECCOMP_${NAME}, (0 + value)
+  #    #define __(ARM_)?NR_${NAME} ${VALUE}
+  #
+  # Where ${VALUE} is a preprocessor expression.
 
-  syscalls = []
-  for line in content:
-    if not line.startswith(prefix):
+  constant_re = re.compile(
+      r'^\s*#define\s+([A-Za-z_][A-Za-z0-9_]+)\s+(.+)\s*$')
+  token_re = re.compile(r'\b[A-Za-z_][A-Za-z0-9_]+\b')
+  constants = {}
+  with open(names_path) as f:
+    for line in f:
+      m = constant_re.match(line)
+      if not m:
+        continue
+      try:
+        name = m.group(1)
+        # eval() takes care of any arithmetic that may be done
+        value = eval(token_re.sub(lambda x: str(constants[x.group(0)]),
+                                  m.group(2)))
+
+        constants[name] = value
+      except:
+        logging.debug('Failed to parse %s', line)
+        pass
+
+  syscalls = {}
+  for name, value in constants.iteritems():
+    if not name.startswith("__NR_") and not name.startswith("__ARM_NR"):
       continue
-
-    # We might pick up extra whitespace during preprocessing, so best to strip.
-    name, value = [w.strip() for w in line.split(",")]
-    name = name[len(prefix):]
-
-    # Note that some of the numbers were expressed as base + offset, so we
-    # need to eval, not just int
-    value = eval(value)
-    syscalls.append((name, value))
+    if name.startswith("__NR_"):
+      # Remote the __NR_ prefix
+      name = name[len("__NR_"):]
+    syscalls[name] = value
 
   return syscalls
 
@@ -135,7 +139,6 @@
       bpf[i] = statement.format(fail=str(len(bpf) - i),
                                 allow=str(len(bpf) - i - 1))
 
-
   # Add the allow calls at the end. If the syscall is not matched, we will
   # continue. This allows the user to choose to match further syscalls, and
   # also to choose the action when we want to block
@@ -152,14 +155,15 @@
   else:
     name_modifier = ""
   header = textwrap.dedent("""\
-    // Autogenerated file - edit at your peril!!
+    // File autogenerated by {self_path} - edit at your peril!!
 
     #include <linux/filter.h>
     #include <errno.h>
 
-    #include "seccomp_bpfs.h"
+    #include "seccomp/seccomp_bpfs.h"
     const sock_filter {architecture}_{suffix}filter[] = {{
-    """).format(architecture=architecture,suffix=name_modifier)
+    """).format(self_path=os.path.basename(__file__), architecture=architecture,
+                suffix=name_modifier)
 
   footer = textwrap.dedent("""\
 
@@ -170,89 +174,78 @@
   return header + "\n".join(bpf) + footer
 
 
-def construct_bpf(names, architecture, header_dir, extra_switches,
-                  name_modifier):
-  syscalls = convert_names_to_NRs(names, header_dir, extra_switches)
+def construct_bpf(syscalls, architecture, name_modifier):
   ranges = convert_NRs_to_ranges(syscalls)
   bpf = convert_ranges_to_bpf(ranges)
   return convert_bpf_to_output(bpf, architecture, name_modifier)
 
 
-# final syscalls = base - blacklists + whitelists
-ANDROID_SYSTEM_SYSCALL_FILES = {
-    "base": "SYSCALLS.TXT",
-    "whitelists": [
-        "SECCOMP_WHITELIST_COMMON.TXT",
-        "SECCOMP_WHITELIST_SYSTEM.TXT"],
-    "blacklists": ["SECCOMP_BLACKLIST_COMMON.TXT"]
-}
-
-ANDROID_APP_SYSCALL_FILES = {
-    "base": "SYSCALLS.TXT",
-    "whitelists": [
-        "SECCOMP_WHITELIST_COMMON.TXT",
-        "SECCOMP_WHITELIST_APP.TXT"],
-    "blacklists": [
-        "SECCOMP_BLACKLIST_COMMON.TXT",
-        "SECCOMP_BLACKLIST_APP.TXT"]
-}
-
-ANDROID_GLOBAL_SYSCALL_FILES = {
-    "base": "SYSCALLS.TXT",
-    "whitelists": [
-        "SECCOMP_WHITELIST_COMMON.TXT",
-        "SECCOMP_WHITELIST_SYSTEM.TXT",
-        "SECCOMP_WHITELIST_APP.TXT",
-        "SECCOMP_WHITELIST_GLOBAL.TXT"],
-    "blacklists": ["SECCOMP_BLACKLIST_COMMON.TXT"]
-}
-
-
-POLICY_CONFIGS = [("arm", "kernel/uapi/asm-arm", []),
-                  ("arm64", "kernel/uapi/asm-arm64", []),
-                  ("x86", "kernel/uapi/asm-x86", ["-D__i386__"]),
-                  ("x86_64", "kernel/uapi/asm-x86", []),
-                  ("mips", "kernel/uapi/asm-mips", ["-D_MIPS_SIM=_MIPS_SIM_ABI32"]),
-                  ("mips64", "kernel/uapi/asm-mips", ["-D_MIPS_SIM=_MIPS_SIM_ABI64"])]
-
-
-def set_dir():
-  # Set working directory for predictable results
-  os.chdir(os.path.join(os.environ["ANDROID_BUILD_TOP"], "bionic/libc"))
-
-
-def gen_policy(syscall_files, name_modifier):
-  for arch, header_path, switches in POLICY_CONFIGS:
-    base_names = load_syscall_names_from_file(syscall_files["base"], arch)
+def gen_policy(name_modifier, out_dir, base_syscall_file, syscall_files, syscall_NRs):
+  for arch in ('arm', 'arm64', 'mips', 'mips64', 'x86', 'x86_64'):
+    base_names = load_syscall_names_from_file(base_syscall_file, arch)
     whitelist_names = set()
-    for f in syscall_files["whitelists"]:
-      whitelist_names |= load_syscall_names_from_file(f, arch)
     blacklist_names = set()
-    for f in syscall_files["blacklists"]:
-      blacklist_names |= load_syscall_names_from_file(f, arch)
+    for f in syscall_files:
+      if "blacklist" in f.lower():
+        blacklist_names |= load_syscall_names_from_file(f, arch)
+      else:
+        whitelist_names |= load_syscall_names_from_file(f, arch)
 
-    names = merge_names(base_names, whitelist_names, blacklist_names)
-    output = construct_bpf(names, arch, header_path, switches, name_modifier)
+    allowed_syscalls = []
+    for name in merge_names(base_names, whitelist_names, blacklist_names):
+      try:
+        allowed_syscalls.append((name, syscall_NRs[arch][name]))
+      except:
+        logging.exception("Failed to find %s in %s", name, arch)
+        raise
+    output = construct_bpf(allowed_syscalls, arch, name_modifier)
 
     # And output policy
     existing = ""
     filename_modifier = "_" + name_modifier if name_modifier else ""
-    output_path = "seccomp/{}{}_policy.cpp".format(arch, filename_modifier)
-    if os.path.isfile(output_path):
-      existing = open(output_path).read()
-    if output == existing:
-      print "File " + output_path + " not changed."
-    else:
-      with open(output_path, "w") as output_file:
-        output_file.write(output)
-      print "Generated file " + output_path
+    output_path = os.path.join(out_dir,
+                               "{}{}_policy.cpp".format(arch, filename_modifier))
+    with open(output_path, "w") as output_file:
+      output_file.write(output)
 
 
 def main():
-  set_dir()
-  gen_policy(ANDROID_SYSTEM_SYSCALL_FILES, 'system')
-  gen_policy(ANDROID_APP_SYSCALL_FILES, 'app')
-  gen_policy(ANDROID_GLOBAL_SYSCALL_FILES, 'global')
+  parser = argparse.ArgumentParser(
+      description="Generates a seccomp-bpf policy")
+  parser.add_argument("--verbose", "-v", help="Enables verbose logging.")
+  parser.add_argument("--name-modifier",
+                      help=("Specifies the name modifier for the policy. "
+                            "One of {app,global,system}."))
+  parser.add_argument("--out-dir",
+                      help="The output directory for the policy files")
+  parser.add_argument("base_file", metavar="base-file", type=str,
+                      help="The path of the base syscall list (SYSCALLS.TXT).")
+  parser.add_argument("files", metavar="FILE", type=str, nargs="+",
+                      help=("The path of the input files. In order to "
+                            "simplify the build rules, it can take any of the "
+                            "following files: \n"
+                            "* /blacklist.*\.txt$/ syscall blacklist.\n"
+                            "* /whitelist.*\.txt$/ syscall whitelist.\n"
+                            "* otherwise, syscall name-number mapping.\n"))
+  args = parser.parse_args()
+
+  if args.verbose:
+    logging.basicConfig(level=logging.DEBUG)
+  else:
+    logging.basicConfig(level=logging.INFO)
+
+  syscall_files = []
+  syscall_NRs = {}
+  for filename in args.files:
+    if filename.lower().endswith('.txt'):
+      syscall_files.append(filename)
+    else:
+      m = re.search(r"libseccomp_gen_syscall_nrs_([^/]+)", filename)
+      syscall_NRs[m.group(1)] = parse_syscall_NRs(filename)
+
+  gen_policy(name_modifier=args.name_modifier, out_dir=args.out_dir,
+             syscall_NRs=syscall_NRs, base_syscall_file=args.base_file,
+             syscall_files=args.files)
 
 
 if __name__ == "__main__":
diff --git a/libc/tools/gensyscalls.py b/libc/tools/gensyscalls.py
index 2fa4e0f..01c580f 100755
--- a/libc/tools/gensyscalls.py
+++ b/libc/tools/gensyscalls.py
@@ -26,7 +26,8 @@
 # Make sure the directory is deleted when the script exits.
 atexit.register(shutil.rmtree, bionic_temp)
 
-bionic_libc_root = os.path.join(os.environ["ANDROID_BUILD_TOP"], "bionic/libc")
+bionic_libc_root = os.path.join(os.path.dirname(os.path.abspath(__file__)),
+                                "..")
 
 warning = "Generated by gensyscalls.py. Do not edit."
 
diff --git a/libm/Android.bp b/libm/Android.bp
index 9566d5f..fee2bac 100644
--- a/libm/Android.bp
+++ b/libm/Android.bp
@@ -9,6 +9,8 @@
     recovery_available: true,
     static_ndk_lib: true,
 
+    whole_static_libs: ["libarm-optimized-routines"],
+
     srcs: [
         "upstream-freebsd/lib/msun/bsdsrc/b_exp.c",
         "upstream-freebsd/lib/msun/bsdsrc/b_log.c",
@@ -28,7 +30,6 @@
         "upstream-freebsd/lib/msun/src/e_cosh.c",
         "upstream-freebsd/lib/msun/src/e_coshf.c",
         "upstream-freebsd/lib/msun/src/e_exp.c",
-        "upstream-freebsd/lib/msun/src/e_expf.c",
         "upstream-freebsd/lib/msun/src/e_fmod.c",
         "upstream-freebsd/lib/msun/src/e_fmodf.c",
         "upstream-freebsd/lib/msun/src/e_gamma.c",
@@ -50,11 +51,8 @@
         "upstream-freebsd/lib/msun/src/e_log10.c",
         "upstream-freebsd/lib/msun/src/e_log10f.c",
         "upstream-freebsd/lib/msun/src/e_log2.c",
-        "upstream-freebsd/lib/msun/src/e_log2f.c",
         "upstream-freebsd/lib/msun/src/e_log.c",
-        "upstream-freebsd/lib/msun/src/e_logf.c",
         "upstream-freebsd/lib/msun/src/e_pow.c",
-        "upstream-freebsd/lib/msun/src/e_powf.c",
         "upstream-freebsd/lib/msun/src/e_remainder.c",
         "upstream-freebsd/lib/msun/src/e_remainderf.c",
         "upstream-freebsd/lib/msun/src/e_rem_pio2.c",
@@ -92,13 +90,17 @@
         "upstream-freebsd/lib/msun/src/s_cimag.c",
         "upstream-freebsd/lib/msun/src/s_cimagf.c",
         "upstream-freebsd/lib/msun/src/s_cimagl.c",
+        "upstream-freebsd/lib/msun/src/s_clog.c",
+        "upstream-freebsd/lib/msun/src/s_clogf.c",
         "upstream-freebsd/lib/msun/src/s_conj.c",
         "upstream-freebsd/lib/msun/src/s_conjf.c",
         "upstream-freebsd/lib/msun/src/s_conjl.c",
         "upstream-freebsd/lib/msun/src/s_copysign.c",
         "upstream-freebsd/lib/msun/src/s_copysignf.c",
         "upstream-freebsd/lib/msun/src/s_cos.c",
-        "upstream-freebsd/lib/msun/src/s_cosf.c",
+        "upstream-freebsd/lib/msun/src/s_cpow.c",
+        "upstream-freebsd/lib/msun/src/s_cpowf.c",
+        "upstream-freebsd/lib/msun/src/s_cpowl.c",
         "upstream-freebsd/lib/msun/src/s_cproj.c",
         "upstream-freebsd/lib/msun/src/s_cprojf.c",
         "upstream-freebsd/lib/msun/src/s_cprojl.c",
@@ -114,7 +116,6 @@
         "upstream-freebsd/lib/msun/src/s_erf.c",
         "upstream-freebsd/lib/msun/src/s_erff.c",
         "upstream-freebsd/lib/msun/src/s_exp2.c",
-        "upstream-freebsd/lib/msun/src/s_exp2f.c",
         "upstream-freebsd/lib/msun/src/s_expm1.c",
         "upstream-freebsd/lib/msun/src/s_expm1f.c",
         "upstream-freebsd/lib/msun/src/s_fdim.c",
@@ -164,8 +165,6 @@
         "upstream-freebsd/lib/msun/src/s_significandf.c",
         "upstream-freebsd/lib/msun/src/s_sin.c",
         "upstream-freebsd/lib/msun/src/s_sincos.c",
-        "upstream-freebsd/lib/msun/src/s_sincosf.c",
-        "upstream-freebsd/lib/msun/src/s_sinf.c",
         "upstream-freebsd/lib/msun/src/s_tan.c",
         "upstream-freebsd/lib/msun/src/s_tanf.c",
         "upstream-freebsd/lib/msun/src/s_tanh.c",
@@ -186,12 +185,6 @@
         "upstream-netbsd/lib/libm/complex/ccosl.c",
         "upstream-netbsd/lib/libm/complex/cephes_subrl.c",
         "upstream-netbsd/lib/libm/complex/cexpl.c",
-        "upstream-netbsd/lib/libm/complex/clog.c",
-        "upstream-netbsd/lib/libm/complex/clogf.c",
-        "upstream-netbsd/lib/libm/complex/clogl.c",
-        "upstream-netbsd/lib/libm/complex/cpow.c",
-        "upstream-netbsd/lib/libm/complex/cpowf.c",
-        "upstream-netbsd/lib/libm/complex/cpowl.c",
         "upstream-netbsd/lib/libm/complex/csinhl.c",
         "upstream-netbsd/lib/libm/complex/csinl.c",
         "upstream-netbsd/lib/libm/complex/ctanhl.c",
@@ -229,6 +222,7 @@
                 "upstream-freebsd/lib/msun/src/s_atanl.c",
                 "upstream-freebsd/lib/msun/src/s_cbrtl.c",
                 "upstream-freebsd/lib/msun/src/s_ceill.c",
+                "upstream-freebsd/lib/msun/src/s_clogl.c",
                 "upstream-freebsd/lib/msun/src/s_copysignl.c",
                 "upstream-freebsd/lib/msun/src/e_coshl.c",
                 "upstream-freebsd/lib/msun/src/s_cosl.c",
@@ -261,6 +255,7 @@
 
                 "upstream-freebsd/lib/msun/ld128/invtrig.c",
                 "upstream-freebsd/lib/msun/ld128/e_lgammal_r.c",
+                "upstream-freebsd/lib/msun/ld128/e_powl.c",
                 "upstream-freebsd/lib/msun/ld128/k_cosl.c",
                 "upstream-freebsd/lib/msun/ld128/k_sinl.c",
                 "upstream-freebsd/lib/msun/ld128/k_tanl.c",
diff --git a/libm/fake_long_double.c b/libm/fake_long_double.c
index fb79af4..d81fa39 100644
--- a/libm/fake_long_double.c
+++ b/libm/fake_long_double.c
@@ -37,11 +37,11 @@
 long lroundl(long double a1) { return lround(a1); }
 long double modfl(long double a1, long double* a2) { double i; double f = modf(a1, &i); *a2 = i; return f; }
 float nexttowardf(float a1, long double a2) { return nextafterf(a1, (float) a2); }
+long double powl(long double x, long double y) { return pow(x, y); }
 long double roundl(long double a1) { return round(a1); }
-void sincosl(long double x, long double* s, long double* c) { return sincos(x, (double*) s, (double*) c); }
+void sincosl(long double x, long double* s, long double* c) { sincos(x, (double*) s, (double*) c); }
 
 #endif // __LP64__
 
-// FreeBSD doesn't have ld128 implementations of powl or tgammal, so both LP32 and LP64 need these.
-long double powl(long double x, long double y) { return pow(x, y); }
+// FreeBSD doesn't have an ld128 implementations of tgammal, so both LP32 and LP64 need this.
 long double tgammal(long double x) { return tgamma(x); }
diff --git a/libm/freebsd-compat.h b/libm/freebsd-compat.h
index 0bcc40d..f400f2a 100644
--- a/libm/freebsd-compat.h
+++ b/libm/freebsd-compat.h
@@ -16,6 +16,8 @@
 
 #pragma once
 
+// Some FreeBSD source includes <complex.h> and assumes <math.h> from that.
+#include <math.h>
 #include <float.h>
 
 #define __weak_reference(sym,alias)     \
diff --git a/libm/upstream-freebsd/lib/msun/bsdsrc/b_exp.c b/libm/upstream-freebsd/lib/msun/bsdsrc/b_exp.c
index 4400992..febc1ad 100644
--- a/libm/upstream-freebsd/lib/msun/bsdsrc/b_exp.c
+++ b/libm/upstream-freebsd/lib/msun/bsdsrc/b_exp.c
@@ -1,4 +1,6 @@
-/*
+/*-
+ * SPDX-License-Identifier: BSD-4-Clause
+ *
  * Copyright (c) 1985, 1993
  *	The Regents of the University of California.  All rights reserved.
  *
@@ -33,7 +35,7 @@
 
 /* @(#)exp.c	8.1 (Berkeley) 6/4/93 */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/msun/bsdsrc/b_exp.c 325966 2017-11-18 14:26:50Z pfg $");
 
 
 /* EXP(X)
diff --git a/libm/upstream-freebsd/lib/msun/bsdsrc/b_log.c b/libm/upstream-freebsd/lib/msun/bsdsrc/b_log.c
index 5a4b964..8102226 100644
--- a/libm/upstream-freebsd/lib/msun/bsdsrc/b_log.c
+++ b/libm/upstream-freebsd/lib/msun/bsdsrc/b_log.c
@@ -1,4 +1,6 @@
-/*
+/*-
+ * SPDX-License-Identifier: BSD-4-Clause
+ *
  * Copyright (c) 1992, 1993
  *	The Regents of the University of California.  All rights reserved.
  *
@@ -33,10 +35,9 @@
 
 /* @(#)log.c	8.2 (Berkeley) 11/30/93 */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/msun/bsdsrc/b_log.c 326670 2017-12-07 20:41:23Z dim $");
 
 #include <math.h>
-#include <errno.h>
 
 #include "mathimpl.h"
 
diff --git a/libm/upstream-freebsd/lib/msun/bsdsrc/b_tgamma.c b/libm/upstream-freebsd/lib/msun/bsdsrc/b_tgamma.c
index 1d0af44..e530649 100644
--- a/libm/upstream-freebsd/lib/msun/bsdsrc/b_tgamma.c
+++ b/libm/upstream-freebsd/lib/msun/bsdsrc/b_tgamma.c
@@ -1,4 +1,6 @@
 /*-
+ * SPDX-License-Identifier: BSD-4-Clause
+ *
  * Copyright (c) 1992, 1993
  *	The Regents of the University of California.  All rights reserved.
  *
@@ -33,7 +35,7 @@
 
 /* @(#)gamma.c	8.1 (Berkeley) 6/4/93 */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/msun/bsdsrc/b_tgamma.c 325966 2017-11-18 14:26:50Z pfg $");
 
 /*
  * This code by P. McIlroy, Oct 1992;
diff --git a/libm/upstream-freebsd/lib/msun/bsdsrc/mathimpl.h b/libm/upstream-freebsd/lib/msun/bsdsrc/mathimpl.h
index 04a4b6e..e38ea4f 100644
--- a/libm/upstream-freebsd/lib/msun/bsdsrc/mathimpl.h
+++ b/libm/upstream-freebsd/lib/msun/bsdsrc/mathimpl.h
@@ -1,4 +1,6 @@
-/*
+/*-
+ * SPDX-License-Identifier: BSD-4-Clause
+ *
  * Copyright (c) 1988, 1993
  *	The Regents of the University of California.  All rights reserved.
  *
@@ -31,7 +33,7 @@
  * SUCH DAMAGE.
  *
  *	@(#)mathimpl.h	8.1 (Berkeley) 6/4/93
- * $FreeBSD$
+ * $FreeBSD: head/lib/msun/bsdsrc/mathimpl.h 325966 2017-11-18 14:26:50Z pfg $
  */
 
 #ifndef _MATHIMPL_H_
diff --git a/libm/upstream-freebsd/lib/msun/ld128/e_powl.c b/libm/upstream-freebsd/lib/msun/ld128/e_powl.c
new file mode 100644
index 0000000..15a57dd
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/ld128/e_powl.c
@@ -0,0 +1,443 @@
+/*-
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+
+/*
+ * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/* powl(x,y) return x**y
+ *
+ *		      n
+ * Method:  Let x =  2   * (1+f)
+ *	1. Compute and return log2(x) in two pieces:
+ *		log2(x) = w1 + w2,
+ *	   where w1 has 113-53 = 60 bit trailing zeros.
+ *	2. Perform y*log2(x) = n+y' by simulating muti-precision
+ *	   arithmetic, where |y'|<=0.5.
+ *	3. Return x**y = 2**n*exp(y'*log2)
+ *
+ * Special cases:
+ *	1.  (anything) ** 0  is 1
+ *	2.  (anything) ** 1  is itself
+ *	3.  (anything) ** NAN is NAN
+ *	4.  NAN ** (anything except 0) is NAN
+ *	5.  +-(|x| > 1) **  +INF is +INF
+ *	6.  +-(|x| > 1) **  -INF is +0
+ *	7.  +-(|x| < 1) **  +INF is +0
+ *	8.  +-(|x| < 1) **  -INF is +INF
+ *	9.  +-1         ** +-INF is NAN
+ *	10. +0 ** (+anything except 0, NAN)               is +0
+ *	11. -0 ** (+anything except 0, NAN, odd integer)  is +0
+ *	12. +0 ** (-anything except 0, NAN)               is +INF
+ *	13. -0 ** (-anything except 0, NAN, odd integer)  is +INF
+ *	14. -0 ** (odd integer) = -( +0 ** (odd integer) )
+ *	15. +INF ** (+anything except 0,NAN) is +INF
+ *	16. +INF ** (-anything except 0,NAN) is +0
+ *	17. -INF ** (anything)  = -0 ** (-anything)
+ *	18. (-anything) ** (integer) is (-1)**(integer)*(+anything**integer)
+ *	19. (-anything except 0 and inf) ** (non-integer) is NAN
+ *
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: head/lib/msun/ld128/e_powl.c 336362 2018-07-17 07:42:14Z bde $");
+
+#include <float.h>
+#include <math.h>
+
+#include "math_private.h"
+
+static const long double bp[] = {
+  1.0L,
+  1.5L,
+};
+
+/* log_2(1.5) */
+static const long double dp_h[] = {
+  0.0,
+  5.8496250072115607565592654282227158546448E-1L
+};
+
+/* Low part of log_2(1.5) */
+static const long double dp_l[] = {
+  0.0,
+  1.0579781240112554492329533686862998106046E-16L
+};
+
+static const long double zero = 0.0L,
+  one = 1.0L,
+  two = 2.0L,
+  two113 = 1.0384593717069655257060992658440192E34L,
+  huge = 1.0e3000L,
+  tiny = 1.0e-3000L;
+
+/* 3/2 log x = 3 z + z^3 + z^3 (z^2 R(z^2))
+   z = (x-1)/(x+1)
+   1 <= x <= 1.25
+   Peak relative error 2.3e-37 */
+static const long double LN[] =
+{
+ -3.0779177200290054398792536829702930623200E1L,
+  6.5135778082209159921251824580292116201640E1L,
+ -4.6312921812152436921591152809994014413540E1L,
+  1.2510208195629420304615674658258363295208E1L,
+ -9.9266909031921425609179910128531667336670E-1L
+};
+static const long double LD[] =
+{
+ -5.129862866715009066465422805058933131960E1L,
+  1.452015077564081884387441590064272782044E2L,
+ -1.524043275549860505277434040464085593165E2L,
+  7.236063513651544224319663428634139768808E1L,
+ -1.494198912340228235853027849917095580053E1L
+  /* 1.0E0 */
+};
+
+/* exp(x) = 1 + x - x / (1 - 2 / (x - x^2 R(x^2)))
+   0 <= x <= 0.5
+   Peak relative error 5.7e-38  */
+static const long double PN[] =
+{
+  5.081801691915377692446852383385968225675E8L,
+  9.360895299872484512023336636427675327355E6L,
+  4.213701282274196030811629773097579432957E4L,
+  5.201006511142748908655720086041570288182E1L,
+  9.088368420359444263703202925095675982530E-3L,
+};
+static const long double PD[] =
+{
+  3.049081015149226615468111430031590411682E9L,
+  1.069833887183886839966085436512368982758E8L,
+  8.259257717868875207333991924545445705394E5L,
+  1.872583833284143212651746812884298360922E3L,
+  /* 1.0E0 */
+};
+
+static const long double
+  /* ln 2 */
+  lg2 = 6.9314718055994530941723212145817656807550E-1L,
+  lg2_h = 6.9314718055994528622676398299518041312695E-1L,
+  lg2_l = 2.3190468138462996154948554638754786504121E-17L,
+  ovt = 8.0085662595372944372e-0017L,
+  /* 2/(3*log(2)) */
+  cp = 9.6179669392597560490661645400126142495110E-1L,
+  cp_h = 9.6179669392597555432899980587535537779331E-1L,
+  cp_l = 5.0577616648125906047157785230014751039424E-17L;
+
+long double
+powl(long double x, long double y)
+{
+  long double z, ax, z_h, z_l, p_h, p_l;
+  long double yy1, t1, t2, r, s, t, u, v, w;
+  long double s2, s_h, s_l, t_h, t_l;
+  int32_t i, j, k, yisint, n;
+  u_int32_t ix, iy;
+  int32_t hx, hy;
+  ieee_quad_shape_type o, p, q;
+
+  p.value = x;
+  hx = p.parts32.mswhi;
+  ix = hx & 0x7fffffff;
+
+  q.value = y;
+  hy = q.parts32.mswhi;
+  iy = hy & 0x7fffffff;
+
+
+  /* y==zero: x**0 = 1 */
+  if ((iy | q.parts32.mswlo | q.parts32.lswhi | q.parts32.lswlo) == 0)
+    return one;
+
+  /* 1.0**y = 1; -1.0**+-Inf = 1 */
+  if (x == one)
+    return one;
+  if (x == -1.0L && iy == 0x7fff0000
+      && (q.parts32.mswlo | q.parts32.lswhi | q.parts32.lswlo) == 0)
+    return one;
+
+  /* +-NaN return x+y */
+  if ((ix > 0x7fff0000)
+      || ((ix == 0x7fff0000)
+	  && ((p.parts32.mswlo | p.parts32.lswhi | p.parts32.lswlo) != 0))
+      || (iy > 0x7fff0000)
+      || ((iy == 0x7fff0000)
+	  && ((q.parts32.mswlo | q.parts32.lswhi | q.parts32.lswlo) != 0)))
+    return nan_mix(x, y);
+
+  /* determine if y is an odd int when x < 0
+   * yisint = 0       ... y is not an integer
+   * yisint = 1       ... y is an odd int
+   * yisint = 2       ... y is an even int
+   */
+  yisint = 0;
+  if (hx < 0)
+    {
+      if (iy >= 0x40700000)	/* 2^113 */
+	yisint = 2;		/* even integer y */
+      else if (iy >= 0x3fff0000)	/* 1.0 */
+	{
+	  if (floorl (y) == y)
+	    {
+	      z = 0.5 * y;
+	      if (floorl (z) == z)
+		yisint = 2;
+	      else
+		yisint = 1;
+	    }
+	}
+    }
+
+  /* special value of y */
+  if ((q.parts32.mswlo | q.parts32.lswhi | q.parts32.lswlo) == 0)
+    {
+      if (iy == 0x7fff0000)	/* y is +-inf */
+	{
+	  if (((ix - 0x3fff0000) | p.parts32.mswlo | p.parts32.lswhi |
+	    p.parts32.lswlo) == 0)
+	    return y - y;	/* +-1**inf is NaN */
+	  else if (ix >= 0x3fff0000)	/* (|x|>1)**+-inf = inf,0 */
+	    return (hy >= 0) ? y : zero;
+	  else			/* (|x|<1)**-,+inf = inf,0 */
+	    return (hy < 0) ? -y : zero;
+	}
+      if (iy == 0x3fff0000)
+	{			/* y is  +-1 */
+	  if (hy < 0)
+	    return one / x;
+	  else
+	    return x;
+	}
+      if (hy == 0x40000000)
+	return x * x;		/* y is  2 */
+      if (hy == 0x3ffe0000)
+	{			/* y is  0.5 */
+	  if (hx >= 0)		/* x >= +0 */
+	    return sqrtl (x);
+	}
+    }
+
+  ax = fabsl (x);
+  /* special value of x */
+  if ((p.parts32.mswlo | p.parts32.lswhi | p.parts32.lswlo) == 0)
+    {
+      if (ix == 0x7fff0000 || ix == 0 || ix == 0x3fff0000)
+	{
+	  z = ax;		/*x is +-0,+-inf,+-1 */
+	  if (hy < 0)
+	    z = one / z;	/* z = (1/|x|) */
+	  if (hx < 0)
+	    {
+	      if (((ix - 0x3fff0000) | yisint) == 0)
+		{
+		  z = (z - z) / (z - z);	/* (-1)**non-int is NaN */
+		}
+	      else if (yisint == 1)
+		z = -z;		/* (x<0)**odd = -(|x|**odd) */
+	    }
+	  return z;
+	}
+    }
+
+  /* (x<0)**(non-int) is NaN */
+  if (((((u_int32_t) hx >> 31) - 1) | yisint) == 0)
+    return (x - x) / (x - x);
+
+  /* |y| is huge.
+     2^-16495 = 1/2 of smallest representable value.
+     If (1 - 1/131072)^y underflows, y > 1.4986e9 */
+  if (iy > 0x401d654b)
+    {
+      /* if (1 - 2^-113)^y underflows, y > 1.1873e38 */
+      if (iy > 0x407d654b)
+	{
+	  if (ix <= 0x3ffeffff)
+	    return (hy < 0) ? huge * huge : tiny * tiny;
+	  if (ix >= 0x3fff0000)
+	    return (hy > 0) ? huge * huge : tiny * tiny;
+	}
+      /* over/underflow if x is not close to one */
+      if (ix < 0x3ffeffff)
+	return (hy < 0) ? huge * huge : tiny * tiny;
+      if (ix > 0x3fff0000)
+	return (hy > 0) ? huge * huge : tiny * tiny;
+    }
+
+  n = 0;
+  /* take care subnormal number */
+  if (ix < 0x00010000)
+    {
+      ax *= two113;
+      n -= 113;
+      o.value = ax;
+      ix = o.parts32.mswhi;
+    }
+  n += ((ix) >> 16) - 0x3fff;
+  j = ix & 0x0000ffff;
+  /* determine interval */
+  ix = j | 0x3fff0000;		/* normalize ix */
+  if (j <= 0x3988)
+    k = 0;			/* |x|<sqrt(3/2) */
+  else if (j < 0xbb67)
+    k = 1;			/* |x|<sqrt(3)   */
+  else
+    {
+      k = 0;
+      n += 1;
+      ix -= 0x00010000;
+    }
+
+  o.value = ax;
+  o.parts32.mswhi = ix;
+  ax = o.value;
+
+  /* compute s = s_h+s_l = (x-1)/(x+1) or (x-1.5)/(x+1.5) */
+  u = ax - bp[k];		/* bp[0]=1.0, bp[1]=1.5 */
+  v = one / (ax + bp[k]);
+  s = u * v;
+  s_h = s;
+
+  o.value = s_h;
+  o.parts32.lswlo = 0;
+  o.parts32.lswhi &= 0xf8000000;
+  s_h = o.value;
+  /* t_h=ax+bp[k] High */
+  t_h = ax + bp[k];
+  o.value = t_h;
+  o.parts32.lswlo = 0;
+  o.parts32.lswhi &= 0xf8000000;
+  t_h = o.value;
+  t_l = ax - (t_h - bp[k]);
+  s_l = v * ((u - s_h * t_h) - s_h * t_l);
+  /* compute log(ax) */
+  s2 = s * s;
+  u = LN[0] + s2 * (LN[1] + s2 * (LN[2] + s2 * (LN[3] + s2 * LN[4])));
+  v = LD[0] + s2 * (LD[1] + s2 * (LD[2] + s2 * (LD[3] + s2 * (LD[4] + s2))));
+  r = s2 * s2 * u / v;
+  r += s_l * (s_h + s);
+  s2 = s_h * s_h;
+  t_h = 3.0 + s2 + r;
+  o.value = t_h;
+  o.parts32.lswlo = 0;
+  o.parts32.lswhi &= 0xf8000000;
+  t_h = o.value;
+  t_l = r - ((t_h - 3.0) - s2);
+  /* u+v = s*(1+...) */
+  u = s_h * t_h;
+  v = s_l * t_h + t_l * s;
+  /* 2/(3log2)*(s+...) */
+  p_h = u + v;
+  o.value = p_h;
+  o.parts32.lswlo = 0;
+  o.parts32.lswhi &= 0xf8000000;
+  p_h = o.value;
+  p_l = v - (p_h - u);
+  z_h = cp_h * p_h;		/* cp_h+cp_l = 2/(3*log2) */
+  z_l = cp_l * p_h + p_l * cp + dp_l[k];
+  /* log2(ax) = (s+..)*2/(3*log2) = n + dp_h + z_h + z_l */
+  t = (long double) n;
+  t1 = (((z_h + z_l) + dp_h[k]) + t);
+  o.value = t1;
+  o.parts32.lswlo = 0;
+  o.parts32.lswhi &= 0xf8000000;
+  t1 = o.value;
+  t2 = z_l - (((t1 - t) - dp_h[k]) - z_h);
+
+  /* s (sign of result -ve**odd) = -1 else = 1 */
+  s = one;
+  if (((((u_int32_t) hx >> 31) - 1) | (yisint - 1)) == 0)
+    s = -one;			/* (-ve)**(odd int) */
+
+  /* split up y into yy1+y2 and compute (yy1+y2)*(t1+t2) */
+  yy1 = y;
+  o.value = yy1;
+  o.parts32.lswlo = 0;
+  o.parts32.lswhi &= 0xf8000000;
+  yy1 = o.value;
+  p_l = (y - yy1) * t1 + y * t2;
+  p_h = yy1 * t1;
+  z = p_l + p_h;
+  o.value = z;
+  j = o.parts32.mswhi;
+  if (j >= 0x400d0000) /* z >= 16384 */
+    {
+      /* if z > 16384 */
+      if (((j - 0x400d0000) | o.parts32.mswlo | o.parts32.lswhi |
+	o.parts32.lswlo) != 0)
+	return s * huge * huge;	/* overflow */
+      else
+	{
+	  if (p_l + ovt > z - p_h)
+	    return s * huge * huge;	/* overflow */
+	}
+    }
+  else if ((j & 0x7fffffff) >= 0x400d01b9)	/* z <= -16495 */
+    {
+      /* z < -16495 */
+      if (((j - 0xc00d01bc) | o.parts32.mswlo | o.parts32.lswhi |
+	o.parts32.lswlo)
+	  != 0)
+	return s * tiny * tiny;	/* underflow */
+      else
+	{
+	  if (p_l <= z - p_h)
+	    return s * tiny * tiny;	/* underflow */
+	}
+    }
+  /* compute 2**(p_h+p_l) */
+  i = j & 0x7fffffff;
+  k = (i >> 16) - 0x3fff;
+  n = 0;
+  if (i > 0x3ffe0000)
+    {				/* if |z| > 0.5, set n = [z+0.5] */
+      n = floorl (z + 0.5L);
+      t = n;
+      p_h -= t;
+    }
+  t = p_l + p_h;
+  o.value = t;
+  o.parts32.lswlo = 0;
+  o.parts32.lswhi &= 0xf8000000;
+  t = o.value;
+  u = t * lg2_h;
+  v = (p_l - (t - p_h)) * lg2 + t * lg2_l;
+  z = u + v;
+  w = v - (z - u);
+  /*  exp(z) */
+  t = z * z;
+  u = PN[0] + t * (PN[1] + t * (PN[2] + t * (PN[3] + t * PN[4])));
+  v = PD[0] + t * (PD[1] + t * (PD[2] + t * (PD[3] + t)));
+  t1 = z - t * u / v;
+  r = (z * t1) / (t1 - two) - (w + z * w);
+  z = one - (r - z);
+  o.value = z;
+  j = o.parts32.mswhi;
+  j += (n << 16);
+  if ((j >> 16) <= 0)
+    z = scalbnl (z, n);	/* subnormal output */
+  else
+    {
+      o.parts32.mswhi = j;
+      z = o.value;
+    }
+  return s * z;
+}
diff --git a/libm/upstream-freebsd/lib/msun/ld128/invtrig.c b/libm/upstream-freebsd/lib/msun/ld128/invtrig.c
index 4ceca8a..e89a226 100644
--- a/libm/upstream-freebsd/lib/msun/ld128/invtrig.c
+++ b/libm/upstream-freebsd/lib/msun/ld128/invtrig.c
@@ -1,4 +1,6 @@
 /*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
  * Copyright (c) 2008 David Schultz <das@FreeBSD.ORG>
  * All rights reserved.
  *
@@ -25,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/msun/ld128/invtrig.c 326219 2017-11-26 02:00:33Z pfg $");
 
 #include "invtrig.h"
 
diff --git a/libm/upstream-freebsd/lib/msun/ld128/invtrig.h b/libm/upstream-freebsd/lib/msun/ld128/invtrig.h
index 12f598b..fd1302a 100644
--- a/libm/upstream-freebsd/lib/msun/ld128/invtrig.h
+++ b/libm/upstream-freebsd/lib/msun/ld128/invtrig.h
@@ -1,4 +1,6 @@
 /*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
  * Copyright (c) 2008 David Schultz <das@FreeBSD.ORG>
  * All rights reserved.
  *
@@ -23,7 +25,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: head/lib/msun/ld128/invtrig.h 326219 2017-11-26 02:00:33Z pfg $
  */
 
 #include <float.h>
diff --git a/libm/upstream-freebsd/lib/msun/ld128/k_expl.h b/libm/upstream-freebsd/lib/msun/ld128/k_expl.h
index e843d43..4c041e8 100644
--- a/libm/upstream-freebsd/lib/msun/ld128/k_expl.h
+++ b/libm/upstream-freebsd/lib/msun/ld128/k_expl.h
@@ -1,6 +1,8 @@
 /* from: FreeBSD: head/lib/msun/ld128/s_expl.c 251345 2013-06-03 20:09:22Z kargl */
 
 /*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
  * Copyright (c) 2009-2013 Steven G. Kargl
  * All rights reserved.
  *
@@ -29,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/msun/ld128/k_expl.h 275819 2014-12-16 09:21:56Z ed $");
+__FBSDID("$FreeBSD: head/lib/msun/ld128/k_expl.h 326219 2017-11-26 02:00:33Z pfg $");
 
 /*
  * ld128 version of k_expl.h.  See ../ld80/s_expl.c for most comments.
diff --git a/libm/upstream-freebsd/lib/msun/ld128/s_exp2l.c b/libm/upstream-freebsd/lib/msun/ld128/s_exp2l.c
index 5afa37e..effeb78 100644
--- a/libm/upstream-freebsd/lib/msun/ld128/s_exp2l.c
+++ b/libm/upstream-freebsd/lib/msun/ld128/s_exp2l.c
@@ -1,4 +1,6 @@
 /*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
  * Copyright (c) 2005-2008 David Schultz <das@FreeBSD.ORG>
  * All rights reserved.
  *
@@ -25,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/msun/ld128/s_exp2l.c 326219 2017-11-26 02:00:33Z pfg $");
 
 #include <float.h>
 #include <stdint.h>
diff --git a/libm/upstream-freebsd/lib/msun/ld128/s_expl.c b/libm/upstream-freebsd/lib/msun/ld128/s_expl.c
index a6a9676..53bc04a 100644
--- a/libm/upstream-freebsd/lib/msun/ld128/s_expl.c
+++ b/libm/upstream-freebsd/lib/msun/ld128/s_expl.c
@@ -1,4 +1,6 @@
 /*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
  * Copyright (c) 2009-2013 Steven G. Kargl
  * All rights reserved.
  *
@@ -27,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/msun/ld128/s_expl.c 326219 2017-11-26 02:00:33Z pfg $");
 
 /*
  * ld128 version of s_expl.c.  See ../ld80/s_expl.c for most comments.
diff --git a/libm/upstream-freebsd/lib/msun/ld128/s_logl.c b/libm/upstream-freebsd/lib/msun/ld128/s_logl.c
index 391d623..6c9981b 100644
--- a/libm/upstream-freebsd/lib/msun/ld128/s_logl.c
+++ b/libm/upstream-freebsd/lib/msun/ld128/s_logl.c
@@ -1,4 +1,6 @@
 /*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
  * Copyright (c) 2007-2013 Bruce D. Evans
  * All rights reserved.
  *
@@ -25,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/msun/ld128/s_logl.c 326219 2017-11-26 02:00:33Z pfg $");
 
 /**
  * Implementation of the natural logarithm of x for 128-bit format.
diff --git a/libm/upstream-freebsd/lib/msun/ld128/s_nanl.c b/libm/upstream-freebsd/lib/msun/ld128/s_nanl.c
index 0f74a13..1b8196f 100644
--- a/libm/upstream-freebsd/lib/msun/ld128/s_nanl.c
+++ b/libm/upstream-freebsd/lib/msun/ld128/s_nanl.c
@@ -1,4 +1,6 @@
 /*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
  * Copyright (c) 2007 David Schultz
  * All rights reserved.
  *
@@ -23,7 +25,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: head/lib/msun/ld128/s_nanl.c 326219 2017-11-26 02:00:33Z pfg $
  */
 
 #include <math.h>
diff --git a/libm/upstream-freebsd/lib/msun/src/catrig.c b/libm/upstream-freebsd/lib/msun/src/catrig.c
index 025076f..4a2d076 100644
--- a/libm/upstream-freebsd/lib/msun/src/catrig.c
+++ b/libm/upstream-freebsd/lib/msun/src/catrig.c
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/msun/src/catrig.c 327232 2017-12-27 03:23:41Z eadler $");
+__FBSDID("$FreeBSD: head/lib/msun/src/catrig.c 336362 2018-07-17 07:42:14Z bde $");
 
 #include <complex.h>
 #include <float.h>
@@ -300,7 +300,7 @@
 		 * C99 leaves it optional whether to raise invalid if one of
 		 * the arguments is not NaN, so we opt not to raise it.
 		 */
-		return (CMPLX(x + 0.0L + (y + 0), x + 0.0L + (y + 0)));
+		return (CMPLX(nan_mix(x, y), nan_mix(x, y)));
 	}
 
 	if (ax > RECIP_EPSILON || ay > RECIP_EPSILON) {
@@ -384,7 +384,7 @@
 		 * C99 leaves it optional whether to raise invalid if one of
 		 * the arguments is not NaN, so we opt not to raise it.
 		 */
-		return (CMPLX(x + 0.0L + (y + 0), x + 0.0L + (y + 0)));
+		return (CMPLX(nan_mix(x, y), nan_mix(x, y)));
 	}
 
 	if (ax > RECIP_EPSILON || ay > RECIP_EPSILON) {
@@ -601,7 +601,7 @@
 		 * C99 leaves it optional whether to raise invalid if one of
 		 * the arguments is not NaN, so we opt not to raise it.
 		 */
-		return (CMPLX(x + 0.0L + (y + 0), x + 0.0L + (y + 0)));
+		return (CMPLX(nan_mix(x, y), nan_mix(x, y)));
 	}
 
 	if (ax > RECIP_EPSILON || ay > RECIP_EPSILON)
diff --git a/libm/upstream-freebsd/lib/msun/src/catrigf.c b/libm/upstream-freebsd/lib/msun/src/catrigf.c
index 344290a..e251871 100644
--- a/libm/upstream-freebsd/lib/msun/src/catrigf.c
+++ b/libm/upstream-freebsd/lib/msun/src/catrigf.c
@@ -41,7 +41,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/msun/src/catrigf.c 326219 2017-11-26 02:00:33Z pfg $");
+__FBSDID("$FreeBSD: head/lib/msun/src/catrigf.c 336362 2018-07-17 07:42:14Z bde $");
 
 #include <complex.h>
 #include <float.h>
@@ -163,7 +163,7 @@
 			return (CMPLXF(y, x + x));
 		if (y == 0)
 			return (CMPLXF(x + x, y));
-		return (CMPLXF(x + 0.0L + (y + 0), x + 0.0L + (y + 0)));
+		return (CMPLXF(nan_mix(x, y), nan_mix(x, y)));
 	}
 
 	if (ax > RECIP_EPSILON || ay > RECIP_EPSILON) {
@@ -221,7 +221,7 @@
 			return (CMPLXF(x + x, -y));
 		if (x == 0)
 			return (CMPLXF(pio2_hi + pio2_lo, y + y));
-		return (CMPLXF(x + 0.0L + (y + 0), x + 0.0L + (y + 0)));
+		return (CMPLXF(nan_mix(x, y), nan_mix(x, y)));
 	}
 
 	if (ax > RECIP_EPSILON || ay > RECIP_EPSILON) {
@@ -359,7 +359,7 @@
 		if (isinf(y))
 			return (CMPLXF(copysignf(0, x),
 			    copysignf(pio2_hi + pio2_lo, y)));
-		return (CMPLXF(x + 0.0L + (y + 0), x + 0.0L + (y + 0)));
+		return (CMPLXF(nan_mix(x, y), nan_mix(x, y)));
 	}
 
 	if (ax > RECIP_EPSILON || ay > RECIP_EPSILON)
diff --git a/libm/upstream-freebsd/lib/msun/src/catrigl.c b/libm/upstream-freebsd/lib/msun/src/catrigl.c
index 960c1ca..63b068a 100644
--- a/libm/upstream-freebsd/lib/msun/src/catrigl.c
+++ b/libm/upstream-freebsd/lib/msun/src/catrigl.c
@@ -40,7 +40,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/msun/src/catrigl.c 323003 2017-08-29 22:32:29Z rlibby $");
+__FBSDID("$FreeBSD: head/lib/msun/src/catrigl.c 336362 2018-07-17 07:42:14Z bde $");
 
 #include <complex.h>
 #include <float.h>
@@ -182,7 +182,7 @@
 			return (CMPLXL(y, x + x));
 		if (y == 0)
 			return (CMPLXL(x + x, y));
-		return (CMPLXL(x + 0.0L + (y + 0), x + 0.0L + (y + 0)));
+		return (CMPLXL(nan_mix(x, y), nan_mix(x, y)));
 	}
 
 	if (ax > RECIP_EPSILON || ay > RECIP_EPSILON) {
@@ -241,7 +241,7 @@
 			return (CMPLXL(x + x, -y));
 		if (x == 0)
 			return (CMPLXL(pio2_hi + pio2_lo, y + y));
-		return (CMPLXL(x + 0.0L + (y + 0), x + 0.0L + (y + 0)));
+		return (CMPLXL(nan_mix(x, y), nan_mix(x, y)));
 	}
 
 	if (ax > RECIP_EPSILON || ay > RECIP_EPSILON) {
@@ -380,7 +380,7 @@
 		if (isinf(y))
 			return (CMPLXL(copysignl(0, x),
 			    copysignl(pio2_hi + pio2_lo, y)));
-		return (CMPLXL(x + 0.0L + (y + 0), x + 0.0L + (y + 0)));
+		return (CMPLXL(nan_mix(x, y), nan_mix(x, y)));
 	}
 
 	if (ax > RECIP_EPSILON || ay > RECIP_EPSILON)
diff --git a/libm/upstream-freebsd/lib/msun/src/e_atan2.c b/libm/upstream-freebsd/lib/msun/src/e_atan2.c
index ee5b15d..bef9df8 100644
--- a/libm/upstream-freebsd/lib/msun/src/e_atan2.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_atan2.c
@@ -13,7 +13,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/msun/src/e_atan2.c 329259 2018-02-14 07:59:30Z eadler $");
+__FBSDID("$FreeBSD: head/lib/msun/src/e_atan2.c 336362 2018-07-17 07:42:14Z bde $");
 
 /* __ieee754_atan2(y,x)
  * Method :
@@ -70,7 +70,7 @@
 	iy = hy&0x7fffffff;
 	if(((ix|((lx|-lx)>>31))>0x7ff00000)||
 	   ((iy|((ly|-ly)>>31))>0x7ff00000))	/* x or y is NaN */
-	   return x+y;
+	    return nan_mix(x, y);
 	if(hx==0x3ff00000&&lx==0) return atan(y);   /* x=1.0 */
 	m = ((hy>>31)&1)|((hx>>30)&2);	/* 2*sign(x)+sign(y) */
 
diff --git a/libm/upstream-freebsd/lib/msun/src/e_atan2f.c b/libm/upstream-freebsd/lib/msun/src/e_atan2f.c
index fc77bff..0ce9bc0 100644
--- a/libm/upstream-freebsd/lib/msun/src/e_atan2f.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_atan2f.c
@@ -14,7 +14,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/msun/src/e_atan2f.c 336362 2018-07-17 07:42:14Z bde $");
 
 #include "math.h"
 #include "math_private.h"
@@ -41,7 +41,7 @@
 	iy = hy&0x7fffffff;
 	if((ix>0x7f800000)||
 	   (iy>0x7f800000))	/* x or y is NaN */
-	   return x+y;
+	    return nan_mix(x, y);
 	if(hx==0x3f800000) return atanf(y);   /* x=1.0 */
 	m = ((hy>>31)&1)|((hx>>30)&2);	/* 2*sign(x)+sign(y) */
 
diff --git a/libm/upstream-freebsd/lib/msun/src/e_atan2l.c b/libm/upstream-freebsd/lib/msun/src/e_atan2l.c
index 0326482..8f80acc 100644
--- a/libm/upstream-freebsd/lib/msun/src/e_atan2l.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_atan2l.c
@@ -14,7 +14,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/msun/src/e_atan2l.c 336362 2018-07-17 07:42:14Z bde $");
 
 /*
  * See comments in e_atan2.c.
@@ -62,7 +62,7 @@
 	     ((ux.bits.manh&~LDBL_NBIT)|ux.bits.manl)!=0) ||	/* x is NaN */
 	    (expty==BIAS+LDBL_MAX_EXP &&
 	     ((uy.bits.manh&~LDBL_NBIT)|uy.bits.manl)!=0))	/* y is NaN */
-	    return x+y;
+	    return nan_mix(x, y);
 	if (expsignx==BIAS && ((ux.bits.manh&~LDBL_NBIT)|ux.bits.manl)==0)
 	    return atanl(y);					/* x=1.0 */
 	m = ((expsigny>>15)&1)|((expsignx>>14)&2);	/* 2*sign(x)+sign(y) */
diff --git a/libm/upstream-freebsd/lib/msun/src/e_fmod.c b/libm/upstream-freebsd/lib/msun/src/e_fmod.c
index bad066a..fbb2d93 100644
--- a/libm/upstream-freebsd/lib/msun/src/e_fmod.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_fmod.c
@@ -12,7 +12,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/msun/src/e_fmod.c 305380 2016-09-04 12:01:32Z bde $");
+__FBSDID("$FreeBSD: head/lib/msun/src/e_fmod.c 336663 2018-07-24 10:10:16Z bde $");
 
 /* 
  * __ieee754_fmod(x,y)
@@ -42,7 +42,7 @@
     /* purge off exception values */
 	if((hy|ly)==0||(hx>=0x7ff00000)||	/* y=0,or x not finite */
 	  ((hy|((ly|-ly)>>31))>0x7ff00000))	/* or y is NaN */
-	    return (x*y)/(x*y);
+	    return nan_mix_op(x, y, *)/nan_mix_op(x, y, *);
 	if(hx<=hy) {
 	    if((hx<hy)||(lx<ly)) return x;	/* |x|<|y| return x */
 	    if(lx==ly) 
diff --git a/libm/upstream-freebsd/lib/msun/src/e_fmodf.c b/libm/upstream-freebsd/lib/msun/src/e_fmodf.c
index 52ce373..3783a88 100644
--- a/libm/upstream-freebsd/lib/msun/src/e_fmodf.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_fmodf.c
@@ -14,7 +14,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/msun/src/e_fmodf.c 336663 2018-07-24 10:10:16Z bde $");
 
 /*
  * __ieee754_fmodf(x,y)
@@ -41,7 +41,7 @@
     /* purge off exception values */
 	if(hy==0||(hx>=0x7f800000)||		/* y=0,or x not finite */
 	   (hy>0x7f800000))			/* or y is NaN */
-	    return (x*y)/(x*y);
+	    return nan_mix_op(x, y, *)/nan_mix_op(x, y, *);
 	if(hx<hy) return x;			/* |x|<|y| return x */
 	if(hx==hy)
 	    return Zero[(u_int32_t)sx>>31];	/* |x|=|y| return x*0*/
diff --git a/libm/upstream-freebsd/lib/msun/src/e_fmodl.c b/libm/upstream-freebsd/lib/msun/src/e_fmodl.c
index e315f76..77d1642 100644
--- a/libm/upstream-freebsd/lib/msun/src/e_fmodl.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_fmodl.c
@@ -11,7 +11,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/msun/src/e_fmodl.c 336663 2018-07-24 10:10:16Z bde $");
 
 #include <float.h>
 #include <stdint.h>
@@ -79,7 +79,7 @@
 	   (ux.bits.exp == BIAS + LDBL_MAX_EXP) ||	 /* or x not finite */
 	   (uy.bits.exp == BIAS + LDBL_MAX_EXP &&
 	    ((uy.bits.manh&~LDBL_NBIT)|uy.bits.manl)!=0)) /* or y is NaN */
-	    return (x*y)/(x*y);
+	    return nan_mix_op(x, y, *)/nan_mix_op(x, y, *);
 	if(ux.bits.exp<=uy.bits.exp) {
 	    if((ux.bits.exp<uy.bits.exp) ||
 	       (ux.bits.manh<=uy.bits.manh &&
diff --git a/libm/upstream-freebsd/lib/msun/src/e_hypot.c b/libm/upstream-freebsd/lib/msun/src/e_hypot.c
index 2398e98..0c16767 100644
--- a/libm/upstream-freebsd/lib/msun/src/e_hypot.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_hypot.c
@@ -12,7 +12,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/msun/src/e_hypot.c 336362 2018-07-17 07:42:14Z bde $");
 
 /* __ieee754_hypot(x,y)
  *
@@ -70,7 +70,7 @@
 	   if(ha >= 0x7ff00000) {	/* Inf or NaN */
 	       u_int32_t low;
 	       /* Use original arg order iff result is NaN; quieten sNaNs. */
-	       w = fabs(x+0.0)-fabs(y+0.0);
+	       w = fabsl(x+0.0L)-fabs(y+0);
 	       GET_LOW_WORD(low,a);
 	       if(((ha&0xfffff)|low)==0) w = a;
 	       GET_LOW_WORD(low,b);
diff --git a/libm/upstream-freebsd/lib/msun/src/e_hypotf.c b/libm/upstream-freebsd/lib/msun/src/e_hypotf.c
index 6d083e4..79e4697 100644
--- a/libm/upstream-freebsd/lib/msun/src/e_hypotf.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_hypotf.c
@@ -14,7 +14,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/msun/src/e_hypotf.c 336362 2018-07-17 07:42:14Z bde $");
 
 #include "math.h"
 #include "math_private.h"
@@ -37,7 +37,7 @@
 	if(ha > 0x58800000) {	/* a>2**50 */
 	   if(ha >= 0x7f800000) {	/* Inf or NaN */
 	       /* Use original arg order iff result is NaN; quieten sNaNs. */
-	       w = fabsf(x+0.0F)-fabsf(y+0.0F);
+	       w = fabsl(x+0.0L)-fabsf(y+0);
 	       if(ha == 0x7f800000) w = a;
 	       if(hb == 0x7f800000) w = b;
 	       return w;
diff --git a/libm/upstream-freebsd/lib/msun/src/e_hypotl.c b/libm/upstream-freebsd/lib/msun/src/e_hypotl.c
index 7b5ab89..5603b6e 100644
--- a/libm/upstream-freebsd/lib/msun/src/e_hypotl.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_hypotl.c
@@ -11,7 +11,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/msun/src/e_hypotl.c 336362 2018-07-17 07:42:14Z bde $");
 
 /* long double version of hypot().  See e_hypot.c for most comments. */
 
@@ -64,7 +64,7 @@
 	   if(ha >= ESW(MAX_EXP)) {	/* Inf or NaN */
 	       man_t manh, manl;
 	       /* Use original arg order iff result is NaN; quieten sNaNs. */
-	       w = fabsl(x+0.0)-fabsl(y+0.0);
+	       w = fabsl(x+0.0L)-fabsl(y+0);
 	       GET_LDBL_MAN(manh,manl,a);
 	       if (manh == LDBL_NBIT && manl == 0) w = a;
 	       GET_LDBL_MAN(manh,manl,b);
diff --git a/libm/upstream-freebsd/lib/msun/src/e_j0.c b/libm/upstream-freebsd/lib/msun/src/e_j0.c
index 36e72c2..cfa71c2 100644
--- a/libm/upstream-freebsd/lib/msun/src/e_j0.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_j0.c
@@ -1,4 +1,3 @@
-
 /* @(#)e_j0.c 1.3 95/01/18 */
 /*
  * ====================================================
@@ -6,13 +5,13 @@
  *
  * Developed at SunSoft, a Sun Microsystems, Inc. business.
  * Permission to use, copy, modify, and distribute this
- * software is freely granted, provided that this notice 
+ * software is freely granted, provided that this notice
  * is preserved.
  * ====================================================
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/msun/src/e_j0.c 283032 2015-05-17 16:27:06Z kargl $");
+__FBSDID("$FreeBSD: head/lib/msun/src/e_j0.c 336089 2018-07-08 16:26:13Z markj $");
 
 /* __ieee754_j0(x), __ieee754_y0(x)
  * Bessel function of the first and second kinds of order zero.
@@ -33,20 +32,20 @@
  * 	   (To avoid cancellation, use
  *		sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x))
  * 	    to compute the worse one.)
- *	   
+ *
  *	3 Special cases
  *		j0(nan)= nan
  *		j0(0) = 1
  *		j0(inf) = 0
- *		
+ *
  * Method -- y0(x):
  *	1. For x<2.
- *	   Since 
+ *	   Since
  *		y0(x) = 2/pi*(j0(x)*(ln(x/2)+Euler) + x^2/4 - ...)
  *	   therefore y0(x)-2/pi*j0(x)*ln(x) is an even function.
  *	   We use the following function to approximate y0,
  *		y0(x) = U(z)/V(z) + (2/pi)*(j0(x)*ln(x)), z= x^2
- *	   where 
+ *	   where
  *		U(z) = u00 + u01*z + ... + u06*z^6
  *		V(z) = 1  + v01*z + ... + v04*z^4
  *	   with absolute approximation error bounded by 2**-72.
@@ -71,7 +70,7 @@
 one	= 1.0,
 invsqrtpi=  5.64189583547756279280e-01, /* 0x3FE20DD7, 0x50429B6D */
 tpi      =  6.36619772367581382433e-01, /* 0x3FE45F30, 0x6DC9C883 */
- 		/* R0/S0 on [0, 2.00] */
+/* R0/S0 on [0, 2.00] */
 R02  =  1.56249999999999947958e-02, /* 0x3F8FFFFF, 0xFFFFFFFD */
 R03  = -1.89979294238854721751e-04, /* 0xBF28E6A5, 0xB61AC6E9 */
 R04  =  1.82954049532700665670e-06, /* 0x3EBEB1D1, 0x0C503919 */
@@ -157,7 +156,7 @@
 	 * y0(Inf) = 0.
 	 * y0(-Inf) = NaN and raise invalid exception.
 	 */
-	if(ix>=0x7ff00000) return vone/(x+x*x); 
+	if(ix>=0x7ff00000) return vone/(x+x*x);
 	/* y0(+-0) = -inf and raise divide-by-zero exception. */
 	if((ix|lx)==0) return -one/vzero;
 	/* y0(x<0) = NaN and raise invalid exception. */
@@ -293,7 +292,7 @@
 	s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*q[4]))));
 	return one+ r/s;
 }
-		
+
 
 /* For x >= 8, the asymptotic expansions of qzero is
  *	-1/8 s + 75/1024 s^3 - ..., where s = 1/x.
diff --git a/libm/upstream-freebsd/lib/msun/src/e_j1.c b/libm/upstream-freebsd/lib/msun/src/e_j1.c
index b11ac2d..78bb329 100644
--- a/libm/upstream-freebsd/lib/msun/src/e_j1.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_j1.c
@@ -1,4 +1,3 @@
-
 /* @(#)e_j1.c 1.3 95/01/18 */
 /*
  * ====================================================
@@ -6,13 +5,13 @@
  *
  * Developed at SunSoft, a Sun Microsystems, Inc. business.
  * Permission to use, copy, modify, and distribute this
- * software is freely granted, provided that this notice 
+ * software is freely granted, provided that this notice
  * is preserved.
  * ====================================================
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/msun/src/e_j1.c 283032 2015-05-17 16:27:06Z kargl $");
+__FBSDID("$FreeBSD: head/lib/msun/src/e_j1.c 336089 2018-07-08 16:26:13Z markj $");
 
 /* __ieee754_j1(x), __ieee754_y1(x)
  * Bessel function of the first and second kinds of order zero.
@@ -34,16 +33,16 @@
  * 	   (To avoid cancellation, use
  *		sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x))
  * 	    to compute the worse one.)
- *	   
+ *
  *	3 Special cases
  *		j1(nan)= nan
  *		j1(0) = 0
  *		j1(inf) = 0
- *		
+ *
  * Method -- y1(x):
- *	1. screen out x<=0 cases: y1(0)=-inf, y1(x<0)=NaN 
+ *	1. screen out x<=0 cases: y1(0)=-inf, y1(x<0)=NaN
  *	2. For x<2.
- *	   Since 
+ *	   Since
  *		y1(x) = 2/pi*(j1(x)*(ln(x/2)+Euler)-1/x-x/2+5/64*x^3-...)
  *	   therefore y1(x)-2/pi*j1(x)*ln(x)-1/x is an odd function.
  *	   We use the following function to approximate y1,
@@ -154,7 +153,7 @@
 	 * y1(Inf) = 0.
 	 * y1(-Inf) = NaN and raise invalid exception.
 	 */
-	if(ix>=0x7ff00000) return  vone/(x+x*x); 
+	if(ix>=0x7ff00000) return  vone/(x+x*x);
 	/* y1(+-0) = -inf and raise divide-by-zero exception. */
         if((ix|lx)==0) return -one/vzero;
 	/* y1(x<0) = NaN and raise invalid exception. */
@@ -186,10 +185,10 @@
                     z = invsqrtpi*(u*ss+v*cc)/sqrt(x);
                 }
                 return z;
-        } 
+        }
         if(ix<=0x3c900000) {    /* x < 2**-54 */
             return(-tpi/x);
-        } 
+        }
         z = x*x;
         u = U0[0]+z*(U0[1]+z*(U0[2]+z*(U0[3]+z*U0[4])));
         v = one+z*(V0[0]+z*(V0[1]+z*(V0[2]+z*(V0[3]+z*V0[4]))));
@@ -287,7 +286,7 @@
         s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*q[4]))));
         return one+ r/s;
 }
-		
+
 
 /* For x >= 8, the asymptotic expansions of qone is
  *	3/8 s - 105/1024 s^3 - ..., where s = 1/x.
diff --git a/libm/upstream-freebsd/lib/msun/src/e_j1f.c b/libm/upstream-freebsd/lib/msun/src/e_j1f.c
index 0cca823..3abe201 100644
--- a/libm/upstream-freebsd/lib/msun/src/e_j1f.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_j1f.c
@@ -14,7 +14,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/msun/src/e_j1f.c 283032 2015-05-17 16:27:06Z kargl $");
+__FBSDID("$FreeBSD: head/lib/msun/src/e_j1f.c 336089 2018-07-08 16:26:13Z markj $");
 
 /*
  * See e_j1.c for complete comments.
@@ -32,7 +32,7 @@
 one	= 1.0,
 invsqrtpi=  5.6418961287e-01, /* 0x3f106ebb */
 tpi      =  6.3661974669e-01, /* 0x3f22f983 */
-	/* R0/S0 on [0,2] */
+/* R0/S0 on [0,2] */
 r00  = -6.2500000000e-02, /* 0xbd800000 */
 r01  =  1.4070566976e-03, /* 0x3ab86cfd */
 r02  = -1.5995563444e-05, /* 0xb7862e36 */
diff --git a/libm/upstream-freebsd/lib/msun/src/e_jn.c b/libm/upstream-freebsd/lib/msun/src/e_jn.c
index a1130c5..58ec905 100644
--- a/libm/upstream-freebsd/lib/msun/src/e_jn.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_jn.c
@@ -1,4 +1,3 @@
-
 /* @(#)e_jn.c 1.4 95/01/18 */
 /*
  * ====================================================
@@ -6,19 +5,19 @@
  *
  * Developed at SunSoft, a Sun Microsystems, Inc. business.
  * Permission to use, copy, modify, and distribute this
- * software is freely granted, provided that this notice 
+ * software is freely granted, provided that this notice
  * is preserved.
  * ====================================================
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/msun/src/e_jn.c 279856 2015-03-10 17:10:54Z kargl $");
+__FBSDID("$FreeBSD: head/lib/msun/src/e_jn.c 336089 2018-07-08 16:26:13Z markj $");
 
 /*
  * __ieee754_jn(n, x), __ieee754_yn(n, x)
  * floating point Bessel's function of the 1st and 2nd kind
  * of order n
- *          
+ *
  * Special cases:
  *	y0(0)=y1(0)=yn(n,0) = -inf with division by zero signal;
  *	y0(-ve)=y1(-ve)=yn(n,-ve) are NaN with invalid signal.
@@ -37,7 +36,6 @@
  *	yn(n,x) is similar in all respects, except
  *	that forward recursion is used for all
  *	values of n>1.
- *	
  */
 
 #include "math.h"
@@ -66,7 +64,7 @@
 	ix = 0x7fffffff&hx;
     /* if J(n,NaN) is NaN */
 	if((ix|((u_int32_t)(lx|-lx))>>31)>0x7ff00000) return x+x;
-	if(n<0){		
+	if(n<0){
 		n = -n;
 		x = -x;
 		hx ^= 0x80000000;
@@ -77,14 +75,14 @@
 	x = fabs(x);
 	if((ix|lx)==0||ix>=0x7ff00000) 	/* if x is 0 or inf */
 	    b = zero;
-	else if((double)n<=x) {   
+	else if((double)n<=x) {
 		/* Safe to use J(n+1,x)=2n/x *J(n,x)-J(n-1,x) */
 	    if(ix>=0x52D00000) { /* x > 2**302 */
-    /* (x >> n**2) 
+    /* (x >> n**2)
      *	    Jn(x) = cos(x-(2n+1)*pi/4)*sqrt(2/x*pi)
      *	    Yn(x) = sin(x-(2n+1)*pi/4)*sqrt(2/x*pi)
-     *	    Let s=sin(x), c=cos(x), 
-     *		xn=x-(2n+1)*pi/4, sqt2 = sqrt(2),then
+     *	    Let s=sin(x), c=cos(x),
+     *		xn=x-(2n+1)*pi/4, sqt2 = sqrt(2), then
      *
      *		   n	sin(xn)*sqt2	cos(xn)*sqt2
      *		----------------------------------
@@ -100,7 +98,7 @@
 		    case 3: temp =  cos(x)-sin(x); break;
 		}
 		b = invsqrtpi*temp/sqrt(x);
-	    } else {	
+	    } else {
 	        a = __ieee754_j0(x);
 	        b = __ieee754_j1(x);
 	        for(i=1;i<n;i++){
@@ -111,7 +109,7 @@
 	    }
 	} else {
 	    if(ix<0x3e100000) {	/* x < 2**-29 */
-    /* x is tiny, return the first Taylor expansion of J(n,x) 
+    /* x is tiny, return the first Taylor expansion of J(n,x)
      * J(n,x) = 1/n!*(x/2)^n  - ...
      */
 		if(n>33)	/* underflow */
@@ -126,14 +124,14 @@
 		}
 	    } else {
 		/* use backward recurrence */
-		/* 			x      x^2      x^2       
+		/* 			x      x^2      x^2
 		 *  J(n,x)/J(n-1,x) =  ----   ------   ------   .....
 		 *			2n  - 2(n+1) - 2(n+2)
 		 *
-		 * 			1      1        1       
+		 * 			1      1        1
 		 *  (for large x)   =  ----  ------   ------   .....
 		 *			2n   2(n+1)   2(n+2)
-		 *			-- - ------ - ------ - 
+		 *			-- - ------ - ------ -
 		 *			 x     x         x
 		 *
 		 * Let w = 2n/x and h=2/x, then the above quotient
@@ -149,9 +147,9 @@
 		 * To determine how many terms needed, let
 		 * Q(0) = w, Q(1) = w(w+h) - 1,
 		 * Q(k) = (w+k*h)*Q(k-1) - Q(k-2),
-		 * When Q(k) > 1e4	good for single 
-		 * When Q(k) > 1e9	good for double 
-		 * When Q(k) > 1e17	good for quadruple 
+		 * When Q(k) > 1e4	good for single
+		 * When Q(k) > 1e9	good for double
+		 * When Q(k) > 1e17	good for quadruple
 		 */
 	    /* determine k */
 		double t,v;
@@ -237,11 +235,11 @@
 	if(n==1) return(sign*__ieee754_y1(x));
 	if(ix==0x7ff00000) return zero;
 	if(ix>=0x52D00000) { /* x > 2**302 */
-    /* (x >> n**2) 
+    /* (x >> n**2)
      *	    Jn(x) = cos(x-(2n+1)*pi/4)*sqrt(2/x*pi)
      *	    Yn(x) = sin(x-(2n+1)*pi/4)*sqrt(2/x*pi)
-     *	    Let s=sin(x), c=cos(x), 
-     *		xn=x-(2n+1)*pi/4, sqt2 = sqrt(2),then
+     *	    Let s=sin(x), c=cos(x),
+     *		xn=x-(2n+1)*pi/4, sqt2 = sqrt(2), then
      *
      *		   n	sin(xn)*sqt2	cos(xn)*sqt2
      *		----------------------------------
diff --git a/libm/upstream-freebsd/lib/msun/src/e_pow.c b/libm/upstream-freebsd/lib/msun/src/e_pow.c
index d088b41..411dd52 100644
--- a/libm/upstream-freebsd/lib/msun/src/e_pow.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_pow.c
@@ -10,7 +10,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/msun/src/e_pow.c 326482 2017-12-03 01:56:03Z emaste $");
+__FBSDID("$FreeBSD: head/lib/msun/src/e_pow.c 336362 2018-07-17 07:42:14Z bde $");
 
 /* __ieee754_pow(x,y) return x**y
  *
@@ -57,6 +57,7 @@
  * to produce the hexadecimal values shown.
  */
 
+#include <float.h>
 #include "math.h"
 #include "math_private.h"
 
@@ -65,6 +66,9 @@
 dp_h[] = { 0.0, 5.84962487220764160156e-01,}, /* 0x3FE2B803, 0x40000000 */
 dp_l[] = { 0.0, 1.35003920212974897128e-08,}, /* 0x3E4CFDEB, 0x43CFD006 */
 zero    =  0.0,
+half    =  0.5,
+qrtr    =  0.25,
+thrd    =  3.3333333333333331e-01, /* 0x3fd55555, 0x55555555 */
 one	=  1.0,
 two	=  2.0,
 two53	=  9007199254740992.0,	/* 0x43400000, 0x00000000 */
@@ -115,7 +119,7 @@
     /* y!=zero: result is NaN if either arg is NaN */
 	if(ix > 0x7ff00000 || ((ix==0x7ff00000)&&(lx!=0)) ||
 	   iy > 0x7ff00000 || ((iy==0x7ff00000)&&(ly!=0)))
-		return (x+0.0)+(y+0.0);
+	    return nan_mix(x, y);
 
     /* determine if y is an odd int when x < 0
      * yisint = 0	... y is not an integer
@@ -197,7 +201,7 @@
 	/* now |1-x| is tiny <= 2**-20, suffice to compute
 	   log(x) by x-x^2/2+x^3/3-x^4/4 */
 	    t = ax-one;		/* t has 20 trailing zeros */
-	    w = (t*t)*(0.5-t*(0.3333333333333333333333-t*0.25));
+	    w = (t*t)*(half-t*(thrd-t*qrtr));
 	    u = ivln2_h*t;	/* ivln2_h has 21 sig. bits */
 	    v = t*ivln2_l-w*ivln2;
 	    t1 = u+v;
@@ -234,9 +238,9 @@
 	    r = s2*s2*(L1+s2*(L2+s2*(L3+s2*(L4+s2*(L5+s2*L6)))));
 	    r += s_l*(s_h+ss);
 	    s2  = s_h*s_h;
-	    t_h = 3.0+s2+r;
+	    t_h = 3+s2+r;
 	    SET_LOW_WORD(t_h,0);
-	    t_l = r-((t_h-3.0)-s2);
+	    t_l = r-((t_h-3)-s2);
 	/* u+v = ss*(1+...) */
 	    u = s_h*t_h;
 	    v = s_l*t_h+t_l*ss;
@@ -247,7 +251,7 @@
 	    z_h = cp_h*p_h;		/* cp_h+cp_l = 2/(3*log2) */
 	    z_l = cp_l*p_h+p_l*cp+dp_l[k];
 	/* log2(ax) = (ss+..)*2/(3*log2) = n + dp_h + z_h + z_l */
-	    t = (double)n;
+	    t = n;
 	    t1 = (((z_h+z_l)+dp_h[k])+t);
 	    SET_LOW_WORD(t1,0);
 	    t2 = z_l-(((t1-t)-dp_h[k])-z_h);
@@ -304,3 +308,7 @@
 	else SET_HIGH_WORD(z,j);
 	return s*z;
 }
+
+#if (LDBL_MANT_DIG == 53)
+__weak_reference(pow, powl);
+#endif
diff --git a/libm/upstream-freebsd/lib/msun/src/e_powf.c b/libm/upstream-freebsd/lib/msun/src/e_powf.c
index 5c46478..13dd4eb 100644
--- a/libm/upstream-freebsd/lib/msun/src/e_powf.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_powf.c
@@ -14,7 +14,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/msun/src/e_powf.c 336362 2018-07-17 07:42:14Z bde $");
 
 #include "math.h"
 #include "math_private.h"
@@ -24,6 +24,9 @@
 dp_h[] = { 0.0, 5.84960938e-01,}, /* 0x3f15c000 */
 dp_l[] = { 0.0, 1.56322085e-06,}, /* 0x35d1cfdc */
 zero    =  0.0,
+half    =  0.5,
+qrtr    =  0.25,
+thrd    =  3.33333343e-01, /* 0x3eaaaaab */
 one	=  1.0,
 two	=  2.0,
 two24	=  16777216.0,	/* 0x4b800000 */
@@ -73,7 +76,7 @@
     /* y!=zero: result is NaN if either arg is NaN */
 	if(ix > 0x7f800000 ||
 	   iy > 0x7f800000)
-		return (x+0.0F)+(y+0.0F);
+	    return nan_mix(x, y);
 
     /* determine if y is an odd int when x < 0
      * yisint = 0	... y is not an integer
@@ -138,7 +141,7 @@
 	/* now |1-x| is tiny <= 2**-20, suffice to compute
 	   log(x) by x-x^2/2+x^3/3-x^4/4 */
 	    t = ax-1;		/* t has 20 trailing zeros */
-	    w = (t*t)*((float)0.5-t*((float)0.333333333333-t*(float)0.25));
+	    w = (t*t)*(half-t*(thrd-t*qrtr));
 	    u = ivln2_h*t;	/* ivln2_h has 16 sig. bits */
 	    v = t*ivln2_l-w*ivln2;
 	    t1 = u+v;
@@ -177,10 +180,10 @@
 	    r = s2*s2*(L1+s2*(L2+s2*(L3+s2*(L4+s2*(L5+s2*L6)))));
 	    r += s_l*(s_h+s);
 	    s2  = s_h*s_h;
-	    t_h = (float)3.0+s2+r;
+	    t_h = 3+s2+r;
 	    GET_FLOAT_WORD(is,t_h);
 	    SET_FLOAT_WORD(t_h,is&0xfffff000);
-	    t_l = r-((t_h-(float)3.0)-s2);
+	    t_l = r-((t_h-3)-s2);
 	/* u+v = s*(1+...) */
 	    u = s_h*t_h;
 	    v = s_l*t_h+t_l*s;
@@ -192,7 +195,7 @@
 	    z_h = cp_h*p_h;		/* cp_h+cp_l = 2/(3*log2) */
 	    z_l = cp_l*p_h+p_l*cp+dp_l[k];
 	/* log2(ax) = (s+..)*2/(3*log2) = n + dp_h + z_h + z_l */
-	    t = (float)n;
+	    t = n;
 	    t1 = (((z_h+z_l)+dp_h[k])+t);
 	    GET_FLOAT_WORD(is,t1);
 	    SET_FLOAT_WORD(t1,is&0xfffff000);
diff --git a/libm/upstream-freebsd/lib/msun/src/e_remainder.c b/libm/upstream-freebsd/lib/msun/src/e_remainder.c
index 9be513b..334d282 100644
--- a/libm/upstream-freebsd/lib/msun/src/e_remainder.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_remainder.c
@@ -12,7 +12,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/msun/src/e_remainder.c 336663 2018-07-24 10:10:16Z bde $");
 
 /* __ieee754_remainder(x,p)
  * Return :                  
@@ -45,11 +45,11 @@
 	hx &= 0x7fffffff;
 
     /* purge off exception values */
-	if((hp|lp)==0) return (x*p)/(x*p); 	/* p = 0 */
-	if((hx>=0x7ff00000)||			/* x not finite */
+	if(((hp|lp)==0)||		 	/* p = 0 */
+	  (hx>=0x7ff00000)||			/* x not finite */
 	  ((hp>=0x7ff00000)&&			/* p is NaN */
 	  (((hp-0x7ff00000)|lp)!=0)))
-	    return ((long double)x*p)/((long double)x*p);
+	    return nan_mix_op(x, p, *)/nan_mix_op(x, p, *);
 
 
 	if (hp<=0x7fdfffff) x = __ieee754_fmod(x,p+p);	/* now x < 2p */
diff --git a/libm/upstream-freebsd/lib/msun/src/e_remainderf.c b/libm/upstream-freebsd/lib/msun/src/e_remainderf.c
index b0014ae..ba3e07a 100644
--- a/libm/upstream-freebsd/lib/msun/src/e_remainderf.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_remainderf.c
@@ -14,7 +14,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/msun/src/e_remainderf.c 336663 2018-07-24 10:10:16Z bde $");
 
 #include "math.h"
 #include "math_private.h"
@@ -36,10 +36,10 @@
 	hx &= 0x7fffffff;
 
     /* purge off exception values */
-	if(hp==0) return (x*p)/(x*p);	 	/* p = 0 */
-	if((hx>=0x7f800000)||			/* x not finite */
+	if((hp==0)||			 	/* p = 0 */
+	  (hx>=0x7f800000)||			/* x not finite */
 	  ((hp>0x7f800000)))			/* p is NaN */
-	    return ((long double)x*p)/((long double)x*p);
+	    return nan_mix_op(x, p, *)/nan_mix_op(x, p, *);
 
 
 	if (hp<=0x7effffff) x = __ieee754_fmodf(x,p+p);	/* now x < 2p */
diff --git a/libm/upstream-freebsd/lib/msun/src/math_private.h b/libm/upstream-freebsd/lib/msun/src/math_private.h
index 637a09a..bc3d516 100644
--- a/libm/upstream-freebsd/lib/msun/src/math_private.h
+++ b/libm/upstream-freebsd/lib/msun/src/math_private.h
@@ -11,7 +11,7 @@
 
 /*
  * from: @(#)fdlibm.h 5.1 93/09/24
- * $FreeBSD: head/lib/msun/src/math_private.h 319047 2017-05-28 06:13:38Z mmel $
+ * $FreeBSD: head/lib/msun/src/math_private.h 336663 2018-07-24 10:10:16Z bde $
  */
 
 #ifndef _MATH_PRIVATE_H_
@@ -48,6 +48,47 @@
 #define	IEEE_WORD_ORDER	BYTE_ORDER
 #endif
 
+/* A union which permits us to convert between a long double and
+   four 32 bit ints.  */
+
+#if IEEE_WORD_ORDER == BIG_ENDIAN
+
+typedef union
+{
+  long double value;
+  struct {
+    u_int32_t mswhi;
+    u_int32_t mswlo;
+    u_int32_t lswhi;
+    u_int32_t lswlo;
+  } parts32;
+  struct {
+    u_int64_t msw;
+    u_int64_t lsw;
+  } parts64;
+} ieee_quad_shape_type;
+
+#endif
+
+#if IEEE_WORD_ORDER == LITTLE_ENDIAN
+
+typedef union
+{
+  long double value;
+  struct {
+    u_int32_t lswlo;
+    u_int32_t lswhi;
+    u_int32_t mswlo;
+    u_int32_t mswhi;
+  } parts32;
+  struct {
+    u_int64_t lsw;
+    u_int64_t msw;
+  } parts64;
+} ieee_quad_shape_type;
+
+#endif
+
 #if IEEE_WORD_ORDER == BIG_ENDIAN
 
 typedef union
@@ -294,8 +335,9 @@
 
 /* Support switching the mode to FP_PE if necessary. */
 #if defined(__i386__) && !defined(NO_FPSETPREC)
-#define	ENTERI()				\
-	long double __retval;			\
+#define	ENTERI() ENTERIT(long double)
+#define	ENTERIT(returntype)			\
+	returntype __retval;			\
 	fp_prec_t __oprec;			\
 						\
 	if ((__oprec = fpgetprec()) != FP_PE)	\
@@ -318,6 +360,7 @@
 } while (0)
 #else
 #define	ENTERI()
+#define	ENTERIT(x)
 #define	RETURNI(x)	RETURNF(x)
 #define	ENTERV()
 #define	RETURNV()	return
@@ -435,6 +478,31 @@
  */
 void _scan_nan(uint32_t *__words, int __num_words, const char *__s);
 
+/*
+ * Mix 0, 1 or 2 NaNs.  First add 0 to each arg.  This normally just turns
+ * signaling NaNs into quiet NaNs by setting a quiet bit.  We do this
+ * because we want to never return a signaling NaN, and also because we
+ * don't want the quiet bit to affect the result.  Then mix the converted
+ * args using the specified operation.
+ *
+ * When one arg is NaN, the result is typically that arg quieted.  When both
+ * args are NaNs, the result is typically the quietening of the arg whose
+ * mantissa is largest after quietening.  When neither arg is NaN, the
+ * result may be NaN because it is indeterminate, or finite for subsequent
+ * construction of a NaN as the indeterminate 0.0L/0.0L.
+ *
+ * Technical complications: the result in bits after rounding to the final
+ * precision might depend on the runtime precision and/or on compiler
+ * optimizations, especially when different register sets are used for
+ * different precisions.  Try to make the result not depend on at least the
+ * runtime precision by always doing the main mixing step in long double
+ * precision.  Try to reduce dependencies on optimizations by adding the
+ * the 0's in different precisions (unless everything is in long double
+ * precision).
+ */
+#define	nan_mix(x, y)		(nan_mix_op((x), (y), +))
+#define	nan_mix_op(x, y, op)	(((x) + 0.0L) op ((y) + 0))
+
 #ifdef _COMPLEX_H
 
 /*
@@ -510,48 +578,116 @@
 
 #endif /* _COMPLEX_H */
  
-#ifdef __GNUCLIKE_ASM
+/*
+ * The rnint() family rounds to the nearest integer for a restricted range
+ * range of args (up to about 2**MANT_DIG).  We assume that the current
+ * rounding mode is FE_TONEAREST so that this can be done efficiently.
+ * Extra precision causes more problems in practice, and we only centralize
+ * this here to reduce those problems, and have not solved the efficiency
+ * problems.  The exp2() family uses a more delicate version of this that
+ * requires extracting bits from the intermediate value, so it is not
+ * centralized here and should copy any solution of the efficiency problems.
+ */
 
-/* Asm versions of some functions. */
+static inline double
+rnint(__double_t x)
+{
+	/*
+	 * This casts to double to kill any extra precision.  This depends
+	 * on the cast being applied to a double_t to avoid compiler bugs
+	 * (this is a cleaner version of STRICT_ASSIGN()).  This is
+	 * inefficient if there actually is extra precision, but is hard
+	 * to improve on.  We use double_t in the API to minimise conversions
+	 * for just calling here.  Note that we cannot easily change the
+	 * magic number to the one that works directly with double_t, since
+	 * the rounding precision is variable at runtime on x86 so the
+	 * magic number would need to be variable.  Assuming that the
+	 * rounding precision is always the default is too fragile.  This
+	 * and many other complications will move when the default is
+	 * changed to FP_PE.
+	 */
+	return ((double)(x + 0x1.8p52) - 0x1.8p52);
+}
 
-#ifdef __amd64__
+static inline float
+rnintf(__float_t x)
+{
+	/*
+	 * As for rnint(), except we could just call that to handle the
+	 * extra precision case, usually without losing efficiency.
+	 */
+	return ((float)(x + 0x1.8p23F) - 0x1.8p23F);
+}
+
+#ifdef LDBL_MANT_DIG
+/*
+ * The complications for extra precision are smaller for rnintl() since it
+ * can safely assume that the rounding precision has been increased from
+ * its default to FP_PE on x86.  We don't exploit that here to get small
+ * optimizations from limiting the rangle to double.  We just need it for
+ * the magic number to work with long doubles.  ld128 callers should use
+ * rnint() instead of this if possible.  ld80 callers should prefer
+ * rnintl() since for amd64 this avoids swapping the register set, while
+ * for i386 it makes no difference (assuming FP_PE), and for other arches
+ * it makes little difference.
+ */
+static inline long double
+rnintl(long double x)
+{
+	return (x + __CONCAT(0x1.8p, LDBL_MANT_DIG) / 2 -
+	    __CONCAT(0x1.8p, LDBL_MANT_DIG) / 2);
+}
+#endif /* LDBL_MANT_DIG */
+
+/*
+ * irint() and i64rint() give the same result as casting to their integer
+ * return type provided their arg is a floating point integer.  They can
+ * sometimes be more efficient because no rounding is required.
+ */
+#if (defined(amd64) || defined(__i386__)) && defined(__GNUCLIKE_ASM)
+#define	irint(x)						\
+    (sizeof(x) == sizeof(float) &&				\
+    sizeof(__float_t) == sizeof(long double) ? irintf(x) :	\
+    sizeof(x) == sizeof(double) &&				\
+    sizeof(__double_t) == sizeof(long double) ? irintd(x) :	\
+    sizeof(x) == sizeof(long double) ? irintl(x) : (int)(x))
+#else
+#define	irint(x)	((int)(x))
+#endif
+
+#define	i64rint(x)	((int64_t)(x))	/* only needed for ld128 so not opt. */
+
+#if defined(__i386__) && defined(__GNUCLIKE_ASM)
 static __inline int
-irint(double x)
+irintf(float x)
 {
 	int n;
 
-	asm("cvtsd2si %1,%0" : "=r" (n) : "x" (x));
+	__asm("fistl %0" : "=m" (n) : "t" (x));
 	return (n);
 }
-#define	HAVE_EFFICIENT_IRINT
-#endif
 
-#ifdef __i386__
 static __inline int
-irint(double x)
+irintd(double x)
 {
 	int n;
 
-	asm("fistl %0" : "=m" (n) : "t" (x));
+	__asm("fistl %0" : "=m" (n) : "t" (x));
 	return (n);
 }
-#define	HAVE_EFFICIENT_IRINT
 #endif
 
-#if defined(__amd64__) || defined(__i386__)
+#if (defined(__amd64__) || defined(__i386__)) && defined(__GNUCLIKE_ASM)
 static __inline int
 irintl(long double x)
 {
 	int n;
 
-	asm("fistl %0" : "=m" (n) : "t" (x));
+	__asm("fistl %0" : "=m" (n) : "t" (x));
 	return (n);
 }
-#define	HAVE_EFFICIENT_IRINTL
 #endif
 
-#endif /* __GNUCLIKE_ASM */
-
 #ifdef DEBUG
 #if defined(__amd64__) || defined(__i386__)
 #define	breakpoint()	asm("int $3")
diff --git a/libm/upstream-freebsd/lib/msun/src/s_ccosh.c b/libm/upstream-freebsd/lib/msun/src/s_ccosh.c
index 534f4b6..da568f4 100644
--- a/libm/upstream-freebsd/lib/msun/src/s_ccosh.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_ccosh.c
@@ -39,7 +39,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/msun/src/s_ccosh.c 326219 2017-11-26 02:00:33Z pfg $");
+__FBSDID("$FreeBSD: head/lib/msun/src/s_ccosh.c 336362 2018-07-17 07:42:14Z bde $");
 
 #include <complex.h>
 #include <math.h>
@@ -146,7 +146,8 @@
 	 * Optionally raises the invalid floating-point exception for finite
 	 * nonzero y.  Choice = don't raise (except for signaling NaNs).
 	 */
-	return (CMPLX((x * x) * (y - y), (x + x) * (y - y)));
+	return (CMPLX(((long double)x * x) * (y - y),
+	    ((long double)x + x) * (y - y)));
 }
 
 double complex
diff --git a/libm/upstream-freebsd/lib/msun/src/s_ccoshf.c b/libm/upstream-freebsd/lib/msun/src/s_ccoshf.c
index 3f4423e..4aeea63 100644
--- a/libm/upstream-freebsd/lib/msun/src/s_ccoshf.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_ccoshf.c
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/msun/src/s_ccoshf.c 326219 2017-11-26 02:00:33Z pfg $");
+__FBSDID("$FreeBSD: head/lib/msun/src/s_ccoshf.c 336362 2018-07-17 07:42:14Z bde $");
 
 #include <complex.h>
 #include <math.h>
@@ -92,7 +92,8 @@
 		return (CMPLXF(INFINITY * cosf(y), x * sinf(y)));
 	}
 
-	return (CMPLXF((x * x) * (y - y), (x + x) * (y - y)));
+	return (CMPLXF(((long double)x * x) * (y - y),
+	    ((long double)x + x) * (y - y)));
 }
 
 float complex
diff --git a/libm/upstream-freebsd/lib/msun/src/s_clog.c b/libm/upstream-freebsd/lib/msun/src/s_clog.c
new file mode 100644
index 0000000..2c31095
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/s_clog.c
@@ -0,0 +1,155 @@
+/*-
+ * Copyright (c) 2013 Bruce D. Evans
+ * 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 unmodified, 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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/cdefs.h>
+__FBSDID("$FreeBSD: head/lib/msun/src/s_clog.c 333577 2018-05-13 09:54:34Z kib $");
+
+#include <complex.h>
+#include <float.h>
+
+#include "fpmath.h"
+#include "math.h"
+#include "math_private.h"
+
+#define	MANT_DIG	DBL_MANT_DIG
+#define	MAX_EXP		DBL_MAX_EXP
+#define	MIN_EXP		DBL_MIN_EXP
+
+static const double
+ln2_hi = 6.9314718055829871e-1,		/*  0x162e42fefa0000.0p-53 */
+ln2_lo = 1.6465949582897082e-12;	/*  0x1cf79abc9e3b3a.0p-92 */
+
+double complex
+clog(double complex z)
+{
+	double_t ax, ax2h, ax2l, axh, axl, ay, ay2h, ay2l, ayh, ayl, sh, sl, t;
+	double x, y, v;
+	uint32_t hax, hay;
+	int kx, ky;
+
+	x = creal(z);
+	y = cimag(z);
+	v = atan2(y, x);
+
+	ax = fabs(x);
+	ay = fabs(y);
+	if (ax < ay) {
+		t = ax;
+		ax = ay;
+		ay = t;
+	}
+
+	GET_HIGH_WORD(hax, ax);
+	kx = (hax >> 20) - 1023;
+	GET_HIGH_WORD(hay, ay);
+	ky = (hay >> 20) - 1023;
+
+	/* Handle NaNs and Infs using the general formula. */
+	if (kx == MAX_EXP || ky == MAX_EXP)
+		return (CMPLX(log(hypot(x, y)), v));
+
+	/* Avoid spurious underflow, and reduce inaccuracies when ax is 1. */
+	if (ax == 1) {
+		if (ky < (MIN_EXP - 1) / 2)
+			return (CMPLX((ay / 2) * ay, v));
+		return (CMPLX(log1p(ay * ay) / 2, v));
+	}
+
+	/* Avoid underflow when ax is not small.  Also handle zero args. */
+	if (kx - ky > MANT_DIG || ay == 0)
+		return (CMPLX(log(ax), v));
+
+	/* Avoid overflow. */
+	if (kx >= MAX_EXP - 1)
+		return (CMPLX(log(hypot(x * 0x1p-1022, y * 0x1p-1022)) +
+		    (MAX_EXP - 2) * ln2_lo + (MAX_EXP - 2) * ln2_hi, v));
+	if (kx >= (MAX_EXP - 1) / 2)
+		return (CMPLX(log(hypot(x, y)), v));
+
+	/* Reduce inaccuracies and avoid underflow when ax is denormal. */
+	if (kx <= MIN_EXP - 2)
+		return (CMPLX(log(hypot(x * 0x1p1023, y * 0x1p1023)) +
+		    (MIN_EXP - 2) * ln2_lo + (MIN_EXP - 2) * ln2_hi, v));
+
+	/* Avoid remaining underflows (when ax is small but not denormal). */
+	if (ky < (MIN_EXP - 1) / 2 + MANT_DIG)
+		return (CMPLX(log(hypot(x, y)), v));
+
+	/* Calculate ax*ax and ay*ay exactly using Dekker's algorithm. */
+	t = (double)(ax * (0x1p27 + 1));
+	axh = (double)(ax - t) + t;
+	axl = ax - axh;
+	ax2h = ax * ax;
+	ax2l = axh * axh - ax2h + 2 * axh * axl + axl * axl;
+	t = (double)(ay * (0x1p27 + 1));
+	ayh = (double)(ay - t) + t;
+	ayl = ay - ayh;
+	ay2h = ay * ay;
+	ay2l = ayh * ayh - ay2h + 2 * ayh * ayl + ayl * ayl;
+
+	/*
+	 * When log(|z|) is far from 1, accuracy in calculating the sum
+	 * of the squares is not very important since log() reduces
+	 * inaccuracies.  We depended on this to use the general
+	 * formula when log(|z|) is very far from 1.  When log(|z|) is
+	 * moderately far from 1, we go through the extra-precision
+	 * calculations to reduce branches and gain a little accuracy.
+	 *
+	 * When |z| is near 1, we subtract 1 and use log1p() and don't
+	 * leave it to log() to subtract 1, since we gain at least 1 bit
+	 * of accuracy in this way.
+	 *
+	 * When |z| is very near 1, subtracting 1 can cancel almost
+	 * 3*MANT_DIG bits.  We arrange that subtracting 1 is exact in
+	 * doubled precision, and then do the rest of the calculation
+	 * in sloppy doubled precision.  Although large cancellations
+	 * often lose lots of accuracy, here the final result is exact
+	 * in doubled precision if the large calculation occurs (because
+	 * then it is exact in tripled precision and the cancellation
+	 * removes enough bits to fit in doubled precision).  Thus the
+	 * result is accurate in sloppy doubled precision, and the only
+	 * significant loss of accuracy is when it is summed and passed
+	 * to log1p().
+	 */
+	sh = ax2h;
+	sl = ay2h;
+	_2sumF(sh, sl);
+	if (sh < 0.5 || sh >= 3)
+		return (CMPLX(log(ay2l + ax2l + sl + sh) / 2, v));
+	sh -= 1;
+	_2sum(sh, sl);
+	_2sum(ax2l, ay2l);
+	/* Briggs-Kahan algorithm (except we discard the final low term): */
+	_2sum(sh, ax2l);
+	_2sum(sl, ay2l);
+	t = ax2l + sl;
+	_2sumF(sh, t);
+	return (CMPLX(log1p(ay2l + t + sh) / 2, v));
+}
+
+#if (LDBL_MANT_DIG == 53)
+__weak_reference(clog, clogl);
+#endif
diff --git a/libm/upstream-freebsd/lib/msun/src/s_clogf.c b/libm/upstream-freebsd/lib/msun/src/s_clogf.c
new file mode 100644
index 0000000..d94977d
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/s_clogf.c
@@ -0,0 +1,151 @@
+/*-
+ * Copyright (c) 2013 Bruce D. Evans
+ * 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 unmodified, 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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/cdefs.h>
+__FBSDID("$FreeBSD: head/lib/msun/src/s_clogf.c 333577 2018-05-13 09:54:34Z kib $");
+
+#include <complex.h>
+#include <float.h>
+
+#include "fpmath.h"
+#include "math.h"
+#include "math_private.h"
+
+#define	MANT_DIG	FLT_MANT_DIG
+#define	MAX_EXP		FLT_MAX_EXP
+#define	MIN_EXP		FLT_MIN_EXP
+
+static const float
+ln2f_hi =  6.9314575195e-1,		/*  0xb17200.0p-24 */
+ln2f_lo =  1.4286067653e-6;		/*  0xbfbe8e.0p-43 */
+
+float complex
+clogf(float complex z)
+{
+	float_t ax, ax2h, ax2l, axh, axl, ay, ay2h, ay2l, ayh, ayl, sh, sl, t;
+	float x, y, v;
+	uint32_t hax, hay;
+	int kx, ky;
+
+	x = crealf(z);
+	y = cimagf(z);
+	v = atan2f(y, x);
+
+	ax = fabsf(x);
+	ay = fabsf(y);
+	if (ax < ay) {
+		t = ax;
+		ax = ay;
+		ay = t;
+	}
+
+	GET_FLOAT_WORD(hax, ax);
+	kx = (hax >> 23) - 127;
+	GET_FLOAT_WORD(hay, ay);
+	ky = (hay >> 23) - 127;
+
+	/* Handle NaNs and Infs using the general formula. */
+	if (kx == MAX_EXP || ky == MAX_EXP)
+		return (CMPLXF(logf(hypotf(x, y)), v));
+
+	/* Avoid spurious underflow, and reduce inaccuracies when ax is 1. */
+	if (hax == 0x3f800000) {
+		if (ky < (MIN_EXP - 1) / 2)
+			return (CMPLXF((ay / 2) * ay, v));
+		return (CMPLXF(log1pf(ay * ay) / 2, v));
+	}
+
+	/* Avoid underflow when ax is not small.  Also handle zero args. */
+	if (kx - ky > MANT_DIG || hay == 0)
+		return (CMPLXF(logf(ax), v));
+
+	/* Avoid overflow. */
+	if (kx >= MAX_EXP - 1)
+		return (CMPLXF(logf(hypotf(x * 0x1p-126F, y * 0x1p-126F)) +
+		    (MAX_EXP - 2) * ln2f_lo + (MAX_EXP - 2) * ln2f_hi, v));
+	if (kx >= (MAX_EXP - 1) / 2)
+		return (CMPLXF(logf(hypotf(x, y)), v));
+
+	/* Reduce inaccuracies and avoid underflow when ax is denormal. */
+	if (kx <= MIN_EXP - 2)
+		return (CMPLXF(logf(hypotf(x * 0x1p127F, y * 0x1p127F)) +
+		    (MIN_EXP - 2) * ln2f_lo + (MIN_EXP - 2) * ln2f_hi, v));
+
+	/* Avoid remaining underflows (when ax is small but not denormal). */
+	if (ky < (MIN_EXP - 1) / 2 + MANT_DIG)
+		return (CMPLXF(logf(hypotf(x, y)), v));
+
+	/* Calculate ax*ax and ay*ay exactly using Dekker's algorithm. */
+	t = (float)(ax * (0x1p12F + 1));
+	axh = (float)(ax - t) + t;
+	axl = ax - axh;
+	ax2h = ax * ax;
+	ax2l = axh * axh - ax2h + 2 * axh * axl + axl * axl;
+	t = (float)(ay * (0x1p12F + 1));
+	ayh = (float)(ay - t) + t;
+	ayl = ay - ayh;
+	ay2h = ay * ay;
+	ay2l = ayh * ayh - ay2h + 2 * ayh * ayl + ayl * ayl;
+
+	/*
+	 * When log(|z|) is far from 1, accuracy in calculating the sum
+	 * of the squares is not very important since log() reduces
+	 * inaccuracies.  We depended on this to use the general
+	 * formula when log(|z|) is very far from 1.  When log(|z|) is
+	 * moderately far from 1, we go through the extra-precision
+	 * calculations to reduce branches and gain a little accuracy.
+	 *
+	 * When |z| is near 1, we subtract 1 and use log1p() and don't
+	 * leave it to log() to subtract 1, since we gain at least 1 bit
+	 * of accuracy in this way.
+	 *
+	 * When |z| is very near 1, subtracting 1 can cancel almost
+	 * 3*MANT_DIG bits.  We arrange that subtracting 1 is exact in
+	 * doubled precision, and then do the rest of the calculation
+	 * in sloppy doubled precision.  Although large cancellations
+	 * often lose lots of accuracy, here the final result is exact
+	 * in doubled precision if the large calculation occurs (because
+	 * then it is exact in tripled precision and the cancellation
+	 * removes enough bits to fit in doubled precision).  Thus the
+	 * result is accurate in sloppy doubled precision, and the only
+	 * significant loss of accuracy is when it is summed and passed
+	 * to log1p().
+	 */
+	sh = ax2h;
+	sl = ay2h;
+	_2sumF(sh, sl);
+	if (sh < 0.5F || sh >= 3)
+		return (CMPLXF(logf(ay2l + ax2l + sl + sh) / 2, v));
+	sh -= 1;
+	_2sum(sh, sl);
+	_2sum(ax2l, ay2l);
+	/* Briggs-Kahan algorithm (except we discard the final low term): */
+	_2sum(sh, ax2l);
+	_2sum(sl, ay2l);
+	t = ax2l + sl;
+	_2sumF(sh, t);
+	return (CMPLXF(log1pf(ay2l + t + sh) / 2, v));
+}
diff --git a/libm/upstream-freebsd/lib/msun/src/s_clogl.c b/libm/upstream-freebsd/lib/msun/src/s_clogl.c
new file mode 100644
index 0000000..9f56ca3
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/s_clogl.c
@@ -0,0 +1,168 @@
+/*-
+ * Copyright (c) 2013 Bruce D. Evans
+ * 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 unmodified, 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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/cdefs.h>
+__FBSDID("$FreeBSD: head/lib/msun/src/s_clogl.c 333577 2018-05-13 09:54:34Z kib $");
+
+#include <complex.h>
+#include <float.h>
+#ifdef __i386__
+#include <ieeefp.h>
+#endif
+
+#include "fpmath.h"
+#include "math.h"
+#include "math_private.h"
+
+#define	MANT_DIG	LDBL_MANT_DIG
+#define	MAX_EXP		LDBL_MAX_EXP
+#define	MIN_EXP		LDBL_MIN_EXP
+
+static const double
+ln2_hi = 6.9314718055829871e-1;		/*  0x162e42fefa0000.0p-53 */
+
+#if LDBL_MANT_DIG == 64
+#define	MULT_REDUX	0x1p32		/* exponent MANT_DIG / 2 rounded up */
+static const double
+ln2l_lo = 1.6465949582897082e-12;	/*  0x1cf79abc9e3b3a.0p-92 */
+#elif LDBL_MANT_DIG == 113
+#define	MULT_REDUX	0x1p57
+static const long double
+ln2l_lo = 1.64659495828970812809844307550013433e-12L;	/*  0x1cf79abc9e3b39803f2f6af40f343.0p-152L */
+#else
+#error "Unsupported long double format"
+#endif
+
+long double complex
+clogl(long double complex z)
+{
+	long double ax, ax2h, ax2l, axh, axl, ay, ay2h, ay2l, ayh, ayl;
+	long double sh, sl, t;
+	long double x, y, v;
+	uint16_t hax, hay;
+	int kx, ky;
+
+	ENTERIT(long double complex);
+
+	x = creall(z);
+	y = cimagl(z);
+	v = atan2l(y, x);
+
+	ax = fabsl(x);
+	ay = fabsl(y);
+	if (ax < ay) {
+		t = ax;
+		ax = ay;
+		ay = t;
+	}
+
+	GET_LDBL_EXPSIGN(hax, ax);
+	kx = hax - 16383;
+	GET_LDBL_EXPSIGN(hay, ay);
+	ky = hay - 16383;
+
+	/* Handle NaNs and Infs using the general formula. */
+	if (kx == MAX_EXP || ky == MAX_EXP)
+		RETURNI(CMPLXL(logl(hypotl(x, y)), v));
+
+	/* Avoid spurious underflow, and reduce inaccuracies when ax is 1. */
+	if (ax == 1) {
+		if (ky < (MIN_EXP - 1) / 2)
+			RETURNI(CMPLXL((ay / 2) * ay, v));
+		RETURNI(CMPLXL(log1pl(ay * ay) / 2, v));
+	}
+
+	/* Avoid underflow when ax is not small.  Also handle zero args. */
+	if (kx - ky > MANT_DIG || ay == 0)
+		RETURNI(CMPLXL(logl(ax), v));
+
+	/* Avoid overflow. */
+	if (kx >= MAX_EXP - 1)
+		RETURNI(CMPLXL(logl(hypotl(x * 0x1p-16382L, y * 0x1p-16382L)) +
+		    (MAX_EXP - 2) * ln2l_lo + (MAX_EXP - 2) * ln2_hi, v));
+	if (kx >= (MAX_EXP - 1) / 2)
+		RETURNI(CMPLXL(logl(hypotl(x, y)), v));
+
+	/* Reduce inaccuracies and avoid underflow when ax is denormal. */
+	if (kx <= MIN_EXP - 2)
+		RETURNI(CMPLXL(logl(hypotl(x * 0x1p16383L, y * 0x1p16383L)) +
+		    (MIN_EXP - 2) * ln2l_lo + (MIN_EXP - 2) * ln2_hi, v));
+
+	/* Avoid remaining underflows (when ax is small but not denormal). */
+	if (ky < (MIN_EXP - 1) / 2 + MANT_DIG)
+		RETURNI(CMPLXL(logl(hypotl(x, y)), v));
+
+	/* Calculate ax*ax and ay*ay exactly using Dekker's algorithm. */
+	t = (long double)(ax * (MULT_REDUX + 1));
+	axh = (long double)(ax - t) + t;
+	axl = ax - axh;
+	ax2h = ax * ax;
+	ax2l = axh * axh - ax2h + 2 * axh * axl + axl * axl;
+	t = (long double)(ay * (MULT_REDUX + 1));
+	ayh = (long double)(ay - t) + t;
+	ayl = ay - ayh;
+	ay2h = ay * ay;
+	ay2l = ayh * ayh - ay2h + 2 * ayh * ayl + ayl * ayl;
+
+	/*
+	 * When log(|z|) is far from 1, accuracy in calculating the sum
+	 * of the squares is not very important since log() reduces
+	 * inaccuracies.  We depended on this to use the general
+	 * formula when log(|z|) is very far from 1.  When log(|z|) is
+	 * moderately far from 1, we go through the extra-precision
+	 * calculations to reduce branches and gain a little accuracy.
+	 *
+	 * When |z| is near 1, we subtract 1 and use log1p() and don't
+	 * leave it to log() to subtract 1, since we gain at least 1 bit
+	 * of accuracy in this way.
+	 *
+	 * When |z| is very near 1, subtracting 1 can cancel almost
+	 * 3*MANT_DIG bits.  We arrange that subtracting 1 is exact in
+	 * doubled precision, and then do the rest of the calculation
+	 * in sloppy doubled precision.  Although large cancellations
+	 * often lose lots of accuracy, here the final result is exact
+	 * in doubled precision if the large calculation occurs (because
+	 * then it is exact in tripled precision and the cancellation
+	 * removes enough bits to fit in doubled precision).  Thus the
+	 * result is accurate in sloppy doubled precision, and the only
+	 * significant loss of accuracy is when it is summed and passed
+	 * to log1p().
+	 */
+	sh = ax2h;
+	sl = ay2h;
+	_2sumF(sh, sl);
+	if (sh < 0.5 || sh >= 3)
+		RETURNI(CMPLXL(logl(ay2l + ax2l + sl + sh) / 2, v));
+	sh -= 1;
+	_2sum(sh, sl);
+	_2sum(ax2l, ay2l);
+	/* Briggs-Kahan algorithm (except we discard the final low term): */
+	_2sum(sh, ax2l);
+	_2sum(sl, ay2l);
+	t = ax2l + sl;
+	_2sumF(sh, t);
+	RETURNI(CMPLXL(log1pl(ay2l + t + sh) / 2, v));
+}
diff --git a/libm/upstream-freebsd/lib/msun/src/s_cpow.c b/libm/upstream-freebsd/lib/msun/src/s_cpow.c
new file mode 100644
index 0000000..9be5c51
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/s_cpow.c
@@ -0,0 +1,74 @@
+/*-
+ * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*							cpow
+ *
+ *	Complex power function
+ *
+ *
+ *
+ * SYNOPSIS:
+ *
+ * double complex cpow();
+ * double complex a, z, w;
+ *
+ * w = cpow (a, z);
+ *
+ *
+ *
+ * DESCRIPTION:
+ *
+ * Raises complex A to the complex Zth power.
+ * Definition is per AMS55 # 4.2.8,
+ * analytically equivalent to cpow(a,z) = cexp(z clog(a)).
+ *
+ * ACCURACY:
+ *
+ *                      Relative error:
+ * arithmetic   domain     # trials      peak         rms
+ *    IEEE      -10,+10     30000       9.4e-15     1.5e-15
+ *
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: head/lib/msun/src/s_cpow.c 336299 2018-07-15 00:23:10Z mmacy $");
+
+#include <complex.h>
+#include <float.h>
+#include <math.h>
+
+double complex
+cpow(double complex a, double complex z)
+{
+	double complex w;
+	double x, y, r, theta, absa, arga;
+
+	x = creal (z);
+	y = cimag (z);
+	absa = cabs (a);
+	if (absa == 0.0) {
+		return (0.0 + 0.0 * I);
+	}
+	arga = carg (a);
+	r = pow (absa, x);
+	theta = x * arga;
+	if (y != 0.0) {
+		r = r * exp (-y * arga);
+		theta = theta + y * log (absa);
+	}
+	w = r * cos (theta) + (r * sin (theta)) * I;
+	return (w);
+}
diff --git a/libm/upstream-freebsd/lib/msun/src/s_cpowf.c b/libm/upstream-freebsd/lib/msun/src/s_cpowf.c
new file mode 100644
index 0000000..6e27f57
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/s_cpowf.c
@@ -0,0 +1,73 @@
+/*-
+ * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*							cpowf
+ *
+ *	Complex power function
+ *
+ *
+ *
+ * SYNOPSIS:
+ *
+ * float complex cpowf();
+ * float complex a, z, w;
+ *
+ * w = cpowf (a, z);
+ *
+ *
+ *
+ * DESCRIPTION:
+ *
+ * Raises complex A to the complex Zth power.
+ * Definition is per AMS55 # 4.2.8,
+ * analytically equivalent to cpow(a,z) = cexp(z clog(a)).
+ *
+ * ACCURACY:
+ *
+ *                      Relative error:
+ * arithmetic   domain     # trials      peak         rms
+ *    IEEE      -10,+10     30000       9.4e-15     1.5e-15
+ *
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: head/lib/msun/src/s_cpowf.c 336299 2018-07-15 00:23:10Z mmacy $");
+
+#include <complex.h>
+#include <math.h>
+
+float complex
+cpowf(float complex a, float complex z)
+{
+	float complex w;
+	float x, y, r, theta, absa, arga;
+
+	x = crealf(z);
+	y = cimagf(z);
+	absa = cabsf (a);
+	if (absa == 0.0f) {
+		return (0.0f + 0.0f * I);
+	}
+	arga = cargf (a);
+	r = powf (absa, x);
+	theta = x * arga;
+	if (y != 0.0f) {
+		r = r * expf (-y * arga);
+		theta = theta + y * logf (absa);
+	}
+	w = r * cosf (theta) + (r * sinf (theta)) * I;
+	return (w);
+}
diff --git a/libm/upstream-freebsd/lib/msun/src/s_cpowl.c b/libm/upstream-freebsd/lib/msun/src/s_cpowl.c
new file mode 100644
index 0000000..fcb5c7f
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/s_cpowl.c
@@ -0,0 +1,73 @@
+/*-
+ * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*							cpowl
+ *
+ *	Complex power function
+ *
+ *
+ *
+ * SYNOPSIS:
+ *
+ * long double complex cpowl();
+ * long double complex a, z, w;
+ *
+ * w = cpowl (a, z);
+ *
+ *
+ *
+ * DESCRIPTION:
+ *
+ * Raises complex A to the complex Zth power.
+ * Definition is per AMS55 # 4.2.8,
+ * analytically equivalent to cpow(a,z) = cexp(z clog(a)).
+ *
+ * ACCURACY:
+ *
+ *                      Relative error:
+ * arithmetic   domain     # trials      peak         rms
+ *    IEEE      -10,+10     30000       9.4e-15     1.5e-15
+ *
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: head/lib/msun/src/s_cpowl.c 336299 2018-07-15 00:23:10Z mmacy $");
+
+#include <complex.h>
+#include <math.h>
+
+long double complex
+cpowl(long double complex a, long double complex z)
+{
+	long double complex w;
+	long double x, y, r, theta, absa, arga;
+
+	x = creall(z);
+	y = cimagl(z);
+	absa = cabsl(a);
+	if (absa == 0.0L) {
+		return (0.0L + 0.0L * I);
+	}
+	arga = cargl(a);
+	r = powl(absa, x);
+	theta = x * arga;
+	if (y != 0.0L) {
+		r = r * expl(-y * arga);
+		theta = theta + y * logl(absa);
+	}
+	w = r * cosl(theta) + (r * sinl(theta)) * I;
+	return (w);
+}
diff --git a/libm/upstream-freebsd/lib/msun/src/s_csinh.c b/libm/upstream-freebsd/lib/msun/src/s_csinh.c
index 5f8380e..7408b13 100644
--- a/libm/upstream-freebsd/lib/msun/src/s_csinh.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_csinh.c
@@ -39,7 +39,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/msun/src/s_csinh.c 326219 2017-11-26 02:00:33Z pfg $");
+__FBSDID("$FreeBSD: head/lib/msun/src/s_csinh.c 336362 2018-07-17 07:42:14Z bde $");
 
 #include <complex.h>
 #include <math.h>
@@ -145,7 +145,8 @@
 	 * Optionally raises the invalid floating-point exception for finite
 	 * nonzero y.  Choice = don't raise (except for signaling NaNs).
 	 */
-	return (CMPLX((x + x) * (y - y), (x * x) * (y - y)));
+	return (CMPLX(((long double)x + x) * (y - y),
+	    ((long double)x * x) * (y - y)));
 }
 
 double complex
diff --git a/libm/upstream-freebsd/lib/msun/src/s_csinhf.c b/libm/upstream-freebsd/lib/msun/src/s_csinhf.c
index 7f58b55..6e29f19 100644
--- a/libm/upstream-freebsd/lib/msun/src/s_csinhf.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_csinhf.c
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/msun/src/s_csinhf.c 326219 2017-11-26 02:00:33Z pfg $");
+__FBSDID("$FreeBSD: head/lib/msun/src/s_csinhf.c 336362 2018-07-17 07:42:14Z bde $");
 
 #include <complex.h>
 #include <math.h>
@@ -92,7 +92,8 @@
 		return (CMPLXF(x * cosf(y), INFINITY * sinf(y)));
 	}
 
-	return (CMPLXF((x + x) * (y - y), (x * x) * (y - y)));
+	return (CMPLXF(((long double)x + x) * (y - y),
+	    ((long double)x * x) * (y - y)));
 }
 
 float complex
diff --git a/libm/upstream-freebsd/lib/msun/src/s_csqrt.c b/libm/upstream-freebsd/lib/msun/src/s_csqrt.c
index ad8ef4c..215b7d7 100644
--- a/libm/upstream-freebsd/lib/msun/src/s_csqrt.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_csqrt.c
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/msun/src/s_csqrt.c 326219 2017-11-26 02:00:33Z pfg $");
+__FBSDID("$FreeBSD: head/lib/msun/src/s_csqrt.c 336488 2018-07-19 15:04:10Z bde $");
 
 #include <complex.h>
 #include <float.h>
@@ -35,25 +35,14 @@
 
 #include "math_private.h"
 
-/*
- * gcc doesn't implement complex multiplication or division correctly,
- * so we need to handle infinities specially. We turn on this pragma to
- * notify conforming c99 compilers that the fast-but-incorrect code that
- * gcc generates is acceptable, since the special cases have already been
- * handled.
- */
-#pragma	STDC CX_LIMITED_RANGE	ON
-
-/* We risk spurious overflow for components >= DBL_MAX / (1 + sqrt(2)). */
+/* For avoiding overflow for components >= DBL_MAX / (1 + sqrt(2)). */
 #define	THRESH	0x1.a827999fcef32p+1022
 
 double complex
 csqrt(double complex z)
 {
 	double complex result;
-	double a, b;
-	double t;
-	int scale;
+	double a, b, rx, ry, scale, t;
 
 	a = creal(z);
 	b = cimag(z);
@@ -65,7 +54,7 @@
 		return (CMPLX(INFINITY, b));
 	if (isnan(a)) {
 		t = (b - b) / (b - b);	/* raise invalid if b is not a NaN */
-		return (CMPLX(a, t));	/* return NaN + NaN i */
+		return (CMPLX(a + 0.0L + t, a + 0.0L + t)); /* NaN + NaN i */
 	}
 	if (isinf(a)) {
 		/*
@@ -79,34 +68,46 @@
 		else
 			return (CMPLX(a, copysign(b - b, b)));
 	}
-	/*
-	 * The remaining special case (b is NaN) is handled just fine by
-	 * the normal code path below.
-	 */
+	if (isnan(b)) {
+		t = (a - a) / (a - a);	/* raise invalid */
+		return (CMPLX(b + 0.0L + t, b + 0.0L + t)); /* NaN + NaN i */
+	}
 
 	/* Scale to avoid overflow. */
 	if (fabs(a) >= THRESH || fabs(b) >= THRESH) {
-		a *= 0.25;
-		b *= 0.25;
-		scale = 1;
+		/*
+		 * Don't scale a or b if this might give (spurious)
+		 * underflow.  Then the unscaled value is an equivalent
+		 * infinitesmal (or 0).
+		 */
+		if (fabs(a) >= 0x1p-1020)
+			a *= 0.25;
+		if (fabs(b) >= 0x1p-1020)
+			b *= 0.25;
+		scale = 2;
 	} else {
-		scale = 0;
+		scale = 1;
+	}
+
+	/* Scale to reduce inaccuracies when both components are denormal. */
+	if (fabs(a) < 0x1p-1022 && fabs(b) < 0x1p-1022) {
+		a *= 0x1p54;
+		b *= 0x1p54;
+		scale = 0x1p-27;
 	}
 
 	/* Algorithm 312, CACM vol 10, Oct 1967. */
 	if (a >= 0) {
 		t = sqrt((a + hypot(a, b)) * 0.5);
-		result = CMPLX(t, b / (2 * t));
+		rx = scale * t;
+		ry = scale * b / (2 * t);
 	} else {
 		t = sqrt((-a + hypot(a, b)) * 0.5);
-		result = CMPLX(fabs(b) / (2 * t), copysign(t, b));
+		rx = scale * fabs(b) / (2 * t);
+		ry = copysign(scale * t, b);
 	}
 
-	/* Rescale. */
-	if (scale)
-		return (result * 2);
-	else
-		return (result);
+	return (CMPLX(rx, ry));
 }
 
 #if LDBL_MANT_DIG == 53
diff --git a/libm/upstream-freebsd/lib/msun/src/s_csqrtf.c b/libm/upstream-freebsd/lib/msun/src/s_csqrtf.c
index 195e3b7..16d3266 100644
--- a/libm/upstream-freebsd/lib/msun/src/s_csqrtf.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_csqrtf.c
@@ -27,27 +27,21 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/msun/src/s_csqrtf.c 326219 2017-11-26 02:00:33Z pfg $");
+__FBSDID("$FreeBSD: head/lib/msun/src/s_csqrtf.c 336412 2018-07-17 12:01:59Z bde $");
 
 #include <complex.h>
 #include <math.h>
 
 #include "math_private.h"
 
-/*
- * gcc doesn't implement complex multiplication or division correctly,
- * so we need to handle infinities specially. We turn on this pragma to
- * notify conforming c99 compilers that the fast-but-incorrect code that
- * gcc generates is acceptable, since the special cases have already been
- * handled.
- */
-#pragma	STDC CX_LIMITED_RANGE	ON
-
 float complex
 csqrtf(float complex z)
 {
-	float a = crealf(z), b = cimagf(z);
 	double t;
+	float a, b;
+
+	a = creal(z);
+	b = cimag(z);
 
 	/* Handle special cases. */
 	if (z == 0)
@@ -56,7 +50,7 @@
 		return (CMPLXF(INFINITY, b));
 	if (isnan(a)) {
 		t = (b - b) / (b - b);	/* raise invalid if b is not a NaN */
-		return (CMPLXF(a, t));	/* return NaN + NaN i */
+		return (CMPLXF(a + 0.0L + t, a + 0.0L + t)); /* NaN + NaN i */
 	}
 	if (isinf(a)) {
 		/*
@@ -70,10 +64,10 @@
 		else
 			return (CMPLXF(a, copysignf(b - b, b)));
 	}
-	/*
-	 * The remaining special case (b is NaN) is handled just fine by
-	 * the normal code path below.
-	 */
+	if (isnan(b)) {
+		t = (a - a) / (a - a);	/* raise invalid */
+		return (CMPLXF(b + 0.0L + t, b + 0.0L + t)); /* NaN + NaN i */
+	}
 
 	/*
 	 * We compute t in double precision to avoid overflow and to
@@ -82,9 +76,9 @@
 	 */
 	if (a >= 0) {
 		t = sqrt((a + hypot(a, b)) * 0.5);
-		return (CMPLXF(t, b / (2.0 * t)));
+		return (CMPLXF(t, b / (2 * t)));
 	} else {
 		t = sqrt((-a + hypot(a, b)) * 0.5);
-		return (CMPLXF(fabsf(b) / (2.0 * t), copysignf(t, b)));
+		return (CMPLXF(fabsf(b) / (2 * t), copysignf(t, b)));
 	}
 }
diff --git a/libm/upstream-freebsd/lib/msun/src/s_csqrtl.c b/libm/upstream-freebsd/lib/msun/src/s_csqrtl.c
index a975833..e58e4ae 100644
--- a/libm/upstream-freebsd/lib/msun/src/s_csqrtl.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_csqrtl.c
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/msun/src/s_csqrtl.c 326219 2017-11-26 02:00:33Z pfg $");
+__FBSDID("$FreeBSD: head/lib/msun/src/s_csqrtl.c 336488 2018-07-19 15:04:10Z bde $");
 
 #include <complex.h>
 #include <float.h>
@@ -36,32 +36,28 @@
 #include "math_private.h"
 
 /*
- * gcc doesn't implement complex multiplication or division correctly,
- * so we need to handle infinities specially. We turn on this pragma to
- * notify conforming c99 compilers that the fast-but-incorrect code that
- * gcc generates is acceptable, since the special cases have already been
- * handled.
- */
-#pragma	STDC CX_LIMITED_RANGE	ON
-
-/*
- * We risk spurious overflow for components >= LDBL_MAX / (1 + sqrt(2)).
- * Rather than determining the fully precise value at which we might
- * overflow, just use a threshold of approximately LDBL_MAX / 4.
+ * Several thresholds require a 15-bit exponent and also the usual bias.
+ * s_logl.c and e_hypotl have less hard-coding but end up requiring the
+ * same for the exponent and more for the mantissa.
  */
 #if LDBL_MAX_EXP != 0x4000
 #error "Unsupported long double format"
-#else
-#define	THRESH	0x1p16382L
 #endif
 
+/*
+ * Overflow must be avoided for components >= LDBL_MAX / (1 + sqrt(2)).
+ * The precise threshold is nontrivial to determine and spell, so use a
+ * lower threshold of approximaely LDBL_MAX / 4, and don't use LDBL_MAX
+ * to spell this since LDBL_MAX is broken on i386 (it overflows in 53-bit
+ * precision).
+ */
+#define	THRESH	0x1p16382L
+
 long double complex
 csqrtl(long double complex z)
 {
 	long double complex result;
-	long double a, b;
-	long double t;
-	int scale;
+	long double a, b, rx, ry, scale, t;
 
 	a = creall(z);
 	b = cimagl(z);
@@ -73,7 +69,7 @@
 		return (CMPLXL(INFINITY, b));
 	if (isnan(a)) {
 		t = (b - b) / (b - b);	/* raise invalid if b is not a NaN */
-		return (CMPLXL(a, t));	/* return NaN + NaN i */
+		return (CMPLXL(a + 0.0L + t, a + 0.0L + t)); /* NaN + NaN i */
 	}
 	if (isinf(a)) {
 		/*
@@ -87,32 +83,44 @@
 		else
 			return (CMPLXL(a, copysignl(b - b, b)));
 	}
-	/*
-	 * The remaining special case (b is NaN) is handled just fine by
-	 * the normal code path below.
-	 */
+	if (isnan(b)) {
+		t = (a - a) / (a - a);	/* raise invalid */
+		return (CMPLXL(b + 0.0L + t, b + 0.0L + t)); /* NaN + NaN i */
+	}
 
 	/* Scale to avoid overflow. */
 	if (fabsl(a) >= THRESH || fabsl(b) >= THRESH) {
-		a *= 0.25;
-		b *= 0.25;
-		scale = 1;
+		/*
+		 * Don't scale a or b if this might give (spurious)
+		 * underflow.  Then the unscaled value is an equivalent
+		 * infinitesmal (or 0).
+		 */
+		if (fabsl(a) >= 0x1p-16380L)
+			a *= 0.25;
+		if (fabsl(b) >= 0x1p-16380L)
+			b *= 0.25;
+		scale = 2;
 	} else {
-		scale = 0;
+		scale = 1;
+	}
+
+	/* Scale to reduce inaccuracies when both components are denormal. */
+	if (fabsl(a) < 0x1p-16382L && fabsl(b) < 0x1p-16382L) {
+		a *= 0x1p64;
+		b *= 0x1p64;
+		scale = 0x1p-32;
 	}
 
 	/* Algorithm 312, CACM vol 10, Oct 1967. */
 	if (a >= 0) {
 		t = sqrtl((a + hypotl(a, b)) * 0.5);
-		result = CMPLXL(t, b / (2 * t));
+		rx = scale * t;
+		ry = scale * b / (2 * t);
 	} else {
 		t = sqrtl((-a + hypotl(a, b)) * 0.5);
-		result = CMPLXL(fabsl(b) / (2 * t), copysignl(t, b));
+		rx = scale * fabsl(b) / (2 * t);
+		ry = copysignl(scale * t, b);
 	}
 
-	/* Rescale. */
-	if (scale)
-		return (result * 2);
-	else
-		return (result);
+	return (CMPLXL(rx, ry));
 }
diff --git a/libm/upstream-freebsd/lib/msun/src/s_ctanh.c b/libm/upstream-freebsd/lib/msun/src/s_ctanh.c
index bd16109..d005baf 100644
--- a/libm/upstream-freebsd/lib/msun/src/s_ctanh.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_ctanh.c
@@ -66,7 +66,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/msun/src/s_ctanh.c 326219 2017-11-26 02:00:33Z pfg $");
+__FBSDID("$FreeBSD: head/lib/msun/src/s_ctanh.c 336362 2018-07-17 07:42:14Z bde $");
 
 #include <complex.h>
 #include <math.h>
@@ -104,8 +104,8 @@
 	 */
 	if (ix >= 0x7ff00000) {
 		if ((ix & 0xfffff) | lx)	/* x is NaN */
-			return (CMPLX((x + 0) * (y + 0),
-			    y == 0 ? y : (x + 0) * (y + 0)));
+			return (CMPLX(nan_mix(x, y),
+			    y == 0 ? y : nan_mix(x, y)));
 		SET_HIGH_WORD(x, hx - 0x40000000);	/* x = copysign(1, x) */
 		return (CMPLX(x, copysign(0, isinf(y) ? y : sin(y) * cos(y))));
 	}
diff --git a/libm/upstream-freebsd/lib/msun/src/s_ctanhf.c b/libm/upstream-freebsd/lib/msun/src/s_ctanhf.c
index 1124fc2..06825a3 100644
--- a/libm/upstream-freebsd/lib/msun/src/s_ctanhf.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_ctanhf.c
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/msun/src/s_ctanhf.c 326219 2017-11-26 02:00:33Z pfg $");
+__FBSDID("$FreeBSD: head/lib/msun/src/s_ctanhf.c 336362 2018-07-17 07:42:14Z bde $");
 
 #include <complex.h>
 #include <math.h>
@@ -53,8 +53,8 @@
 
 	if (ix >= 0x7f800000) {
 		if (ix & 0x7fffff)
-			return (CMPLXF((x + 0) * (y + 0),
-			    y == 0 ? y : (x + 0) * (y + 0)));
+			return (CMPLXF(nan_mix(x, y),
+			    y == 0 ? y : nan_mix(x, y)));
 		SET_FLOAT_WORD(x, hx - 0x40000000);
 		return (CMPLXF(x,
 		    copysignf(0, isinf(y) ? y : sinf(y) * cosf(y))));
diff --git a/libm/upstream-freebsd/lib/msun/src/s_remquo.c b/libm/upstream-freebsd/lib/msun/src/s_remquo.c
index d811c69..be6a2e8 100644
--- a/libm/upstream-freebsd/lib/msun/src/s_remquo.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_remquo.c
@@ -11,7 +11,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/msun/src/s_remquo.c 336663 2018-07-24 10:10:16Z bde $");
 
 #include <float.h>
 
@@ -44,7 +44,7 @@
     /* purge off exception values */
 	if((hy|ly)==0||(hx>=0x7ff00000)||	/* y=0,or x not finite */
 	  ((hy|((ly|-ly)>>31))>0x7ff00000))	/* or y is NaN */
-	    return (x*y)/(x*y);
+	    return nan_mix_op(x, y, *)/nan_mix_op(x, y, *);
 	if(hx<=hy) {
 	    if((hx<hy)||(lx<ly)) {
 		q = 0;
diff --git a/libm/upstream-freebsd/lib/msun/src/s_remquof.c b/libm/upstream-freebsd/lib/msun/src/s_remquof.c
index f7b4c00..775672f 100644
--- a/libm/upstream-freebsd/lib/msun/src/s_remquof.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_remquof.c
@@ -11,7 +11,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/msun/src/s_remquof.c 336663 2018-07-24 10:10:16Z bde $");
 
 #include "math.h"
 #include "math_private.h"
@@ -41,7 +41,7 @@
 
     /* purge off exception values */
 	if(hy==0||hx>=0x7f800000||hy>0x7f800000) /* y=0,NaN;or x not finite */
-	    return (x*y)/(x*y);
+	    return nan_mix_op(x, y, *)/nan_mix_op(x, y, *);
 	if(hx<hy) {
 	    q = 0;
 	    goto fixup;	/* |x|<|y| return x or x-y */
diff --git a/libm/upstream-freebsd/lib/msun/src/s_remquol.c b/libm/upstream-freebsd/lib/msun/src/s_remquol.c
index 712651c..5ac13e4 100644
--- a/libm/upstream-freebsd/lib/msun/src/s_remquol.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_remquol.c
@@ -11,7 +11,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/msun/src/s_remquol.c 336665 2018-07-24 11:50:05Z bde $");
 
 #include <float.h>
 #include <stdint.h>
@@ -79,14 +79,13 @@
 	sxy = sx ^ uy.bits.sign;
 	ux.bits.sign = 0;	/* |x| */
 	uy.bits.sign = 0;	/* |y| */
-	x = ux.e;
 
     /* purge off exception values */
 	if((uy.bits.exp|uy.bits.manh|uy.bits.manl)==0 || /* y=0 */
 	   (ux.bits.exp == BIAS + LDBL_MAX_EXP) ||	 /* or x not finite */
 	   (uy.bits.exp == BIAS + LDBL_MAX_EXP &&
 	    ((uy.bits.manh&~LDBL_NBIT)|uy.bits.manl)!=0)) /* or y is NaN */
-	    return (x*y)/(x*y);
+	    return nan_mix_op(x, y, *)/nan_mix_op(x, y, *);
 	if(ux.bits.exp<=uy.bits.exp) {
 	    if((ux.bits.exp<uy.bits.exp) ||
 	       (ux.bits.manh<=uy.bits.manh &&
@@ -126,7 +125,6 @@
     /* fix point fmod */
 	n = ix - iy;
 	q = 0;
-
 	while(n--) {
 	    hz=hx-hy;lz=lx-ly; if(lx<ly) hz -= 1;
 	    if(hz<0){hx = hx+hx+(lx>>MANL_SHIFT); lx = lx+lx;}
@@ -154,9 +152,8 @@
 	} else {
 	    ux.bits.exp = iy + BIAS;
 	}
-	ux.bits.sign = 0;
-	x = ux.e;
 fixup:
+	x = ux.e;		/* |x| */
 	y = fabsl(y);
 	if (y < LDBL_MIN * 2) {
 	    if (x+x>y || (x+x==y && (q & 1))) {
@@ -167,11 +164,9 @@
 	    q++;
 	    x-=y;
 	}
-
 	ux.e = x;
 	ux.bits.sign ^= sx;
 	x = ux.e;
-
 	q &= 0x7fffffff;
 	*quo = (sxy ? -q : q);
 	return x;
diff --git a/libm/upstream-netbsd/lib/libm/complex/clog.c b/libm/upstream-netbsd/lib/libm/complex/clog.c
deleted file mode 100644
index 6362c44..0000000
--- a/libm/upstream-netbsd/lib/libm/complex/clog.c
+++ /dev/null
@@ -1,47 +0,0 @@
-/* $NetBSD: clog.c,v 1.1 2007/08/20 16:01:35 drochner Exp $ */
-
-/*-
- * Copyright (c) 2007 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software written by Stephen L. Moshier.
- * It is redistributed by the NetBSD Foundation by permission of the author.
- *
- * 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.
- *
- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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 "../src/namespace.h"
-#include <complex.h>
-#include <math.h>
-
-double complex
-clog(double complex z)
-{
-	double complex w;
-	double p, rr;
-
-	rr = cabs(z);
-	p = log(rr);
-	rr = atan2(cimag(z), creal(z));
-	w = p + rr * I;
-	return w;
-}
diff --git a/libm/upstream-netbsd/lib/libm/complex/clogf.c b/libm/upstream-netbsd/lib/libm/complex/clogf.c
deleted file mode 100644
index c3cdad0..0000000
--- a/libm/upstream-netbsd/lib/libm/complex/clogf.c
+++ /dev/null
@@ -1,47 +0,0 @@
-/* $NetBSD: clogf.c,v 1.1 2007/08/20 16:01:35 drochner Exp $ */
-
-/*-
- * Copyright (c) 2007 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software written by Stephen L. Moshier.
- * It is redistributed by the NetBSD Foundation by permission of the author.
- *
- * 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.
- *
- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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 "../src/namespace.h"
-#include <complex.h>
-#include <math.h>
-
-float complex
-clogf(float complex z)
-{
-	float complex w;
-	float p, rr;
-
-	rr = cabsf(z);
-	p = logf(rr);
-	rr = atan2f(cimagf(z), crealf(z));
-	w = p + rr * I;
-	return w;
-}
diff --git a/libm/upstream-netbsd/lib/libm/complex/clogl.c b/libm/upstream-netbsd/lib/libm/complex/clogl.c
deleted file mode 100644
index 11e7a15..0000000
--- a/libm/upstream-netbsd/lib/libm/complex/clogl.c
+++ /dev/null
@@ -1,47 +0,0 @@
-/* $NetBSD: clogl.c,v 1.1 2014/10/10 00:48:18 christos Exp $ */
-
-/*-
- * Copyright (c) 2007 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software written by Stephen L. Moshier.
- * It is redistributed by the NetBSD Foundation by permission of the author.
- *
- * 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.
- *
- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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 "../src/namespace.h"
-#include <complex.h>
-#include <math.h>
-
-long double complex
-clogl(long double complex z)
-{
-	long double complex w;
-	long double p, rr;
-
-	rr = cabsl(z);
-	p = logl(rr);
-	rr = atan2l(cimagl(z), creall(z));
-	w = p + rr * I;
-	return w;
-}
diff --git a/libm/upstream-netbsd/lib/libm/complex/cpow.c b/libm/upstream-netbsd/lib/libm/complex/cpow.c
deleted file mode 100644
index 5bc8d3f..0000000
--- a/libm/upstream-netbsd/lib/libm/complex/cpow.c
+++ /dev/null
@@ -1,57 +0,0 @@
-/* $NetBSD: cpow.c,v 1.1 2007/08/20 16:01:35 drochner Exp $ */
-
-/*-
- * Copyright (c) 2007 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software written by Stephen L. Moshier.
- * It is redistributed by the NetBSD Foundation by permission of the author.
- *
- * 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.
- *
- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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 "../src/namespace.h"
-#include <complex.h>
-#include <math.h>
-
-double complex
-cpow(double complex a, double complex z)
-{
-	double complex w;
-	double x, y, r, theta, absa, arga;
-
-	x = creal(z);
-	y = cimag(z);
-	absa = cabs(a);
-	if (absa == 0.0) {
-		return (0.0 + 0.0 * I);
-	}
-	arga = carg(a);
-	r = pow(absa, x);
-	theta = x * arga;
-	if (y != 0.0) {
-		r = r * exp(-y * arga);
-		theta = theta + y * log(absa);
-	}
-	w = r * cos(theta) + (r * sin(theta)) * I;
-	return w;
-}
diff --git a/libm/upstream-netbsd/lib/libm/complex/cpowf.c b/libm/upstream-netbsd/lib/libm/complex/cpowf.c
deleted file mode 100644
index f7af10a..0000000
--- a/libm/upstream-netbsd/lib/libm/complex/cpowf.c
+++ /dev/null
@@ -1,57 +0,0 @@
-/* $NetBSD: cpowf.c,v 1.1 2007/08/20 16:01:36 drochner Exp $ */
-
-/*-
- * Copyright (c) 2007 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software written by Stephen L. Moshier.
- * It is redistributed by the NetBSD Foundation by permission of the author.
- *
- * 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.
- *
- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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 "../src/namespace.h"
-#include <complex.h>
-#include <math.h>
-
-float complex
-cpowf(float complex a, float complex z)
-{
-	float complex w;
-	float x, y, r, theta, absa, arga;
-
-	x = crealf(z);
-	y = cimagf(z);
-	absa = cabsf(a);
-	if (absa == 0.0f) {
-		return (0.0f + 0.0f * I);
-	}
-	arga = cargf(a);
-	r = powf(absa, x);
-	theta = x * arga;
-	if (y != 0.0f) {
-		r = r * expf(-y * arga);
-		theta = theta + y * logf(absa);
-	}
-	w = r * cosf(theta) + (r * sinf(theta)) * I;
-	return w;
-}
diff --git a/libm/upstream-netbsd/lib/libm/complex/cpowl.c b/libm/upstream-netbsd/lib/libm/complex/cpowl.c
deleted file mode 100644
index 39336ea..0000000
--- a/libm/upstream-netbsd/lib/libm/complex/cpowl.c
+++ /dev/null
@@ -1,57 +0,0 @@
-/* $NetBSD: cpowl.c,v 1.1 2014/10/10 00:48:18 christos Exp $ */
-
-/*-
- * Copyright (c) 2007 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software written by Stephen L. Moshier.
- * It is redistributed by the NetBSD Foundation by permission of the author.
- *
- * 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.
- *
- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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 "../src/namespace.h"
-#include <complex.h>
-#include <math.h>
-
-long double complex
-cpowl(long double complex a, long double complex z)
-{
-	long double complex w;
-	long double x, y, r, theta, absa, arga;
-
-	x = creall(z);
-	y = cimagl(z);
-	absa = cabsl(a);
-	if (absa == 0.0L) {
-		return (0.0L + 0.0L * I);
-	}
-	arga = cargl(a);
-	r = powl(absa, x);
-	theta = x * arga;
-	if (y != 0.0L) {
-		r = r * expl(-y * arga);
-		theta = theta + y * logl(absa);
-	}
-	w = r * cosl(theta) + (r * sinl(theta)) * I;
-	return w;
-}
diff --git a/linker/linker.cpp b/linker/linker.cpp
index 9094b0a..e1fe50f 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -1830,35 +1830,7 @@
         }
       }
     } else {
-#if !defined(__work_around_b_24465209__)
       async_safe_fatal("soinfo for \"%s\"@%p has no version", si->get_realpath(), si);
-#else
-      PRINT("warning: soinfo for \"%s\"@%p has no version", si->get_realpath(), si);
-      for_each_dt_needed(si, [&] (const char* library_name) {
-        TRACE("deprecated (old format of soinfo): %s needs to unload %s",
-            si->get_realpath(), library_name);
-
-        soinfo* needed = find_library(si->get_primary_namespace(),
-                                      library_name, RTLD_NOLOAD, nullptr, nullptr);
-
-        if (needed != nullptr) {
-          // Not found: for example if symlink was deleted between dlopen and dlclose
-          // Since we cannot really handle errors at this point - print and continue.
-          PRINT("warning: couldn't find %s needed by %s on unload.",
-              library_name, si->get_realpath());
-          return;
-        } else if (local_unload_list.contains(needed)) {
-          // already visited
-          return;
-        } else if (needed->is_linked() && needed->get_local_group_root() != root) {
-          // external group
-          external_unload_list.push_back(needed);
-        } else {
-          // local group
-          unload_list.push_front(needed);
-        }
-      });
-#endif
     }
   }
 
@@ -2965,8 +2937,8 @@
         TRACE_TYPE(RELO, "RELO TLS_TPREL64 *** %16llx <- %16llx - %16llx\n",
                    reloc, (sym_addr + addend), rel->r_offset);
         break;
-      case R_AARCH64_TLS_DTPREL32:
-        TRACE_TYPE(RELO, "RELO TLS_DTPREL32 *** %16llx <- %16llx - %16llx\n",
+      case R_AARCH64_TLSDESC:
+        TRACE_TYPE(RELO, "RELO TLSDESC *** %16llx <- %16llx - %16llx\n",
                    reloc, (sym_addr + addend), rel->r_offset);
         break;
 #elif defined(__x86_64__)
@@ -3486,11 +3458,11 @@
         "(new hash type from the future?)", get_realpath());
     return false;
   }
-  if (strtab_ == 0) {
+  if (strtab_ == nullptr) {
     DL_ERR("empty/missing DT_STRTAB in \"%s\"", get_realpath());
     return false;
   }
-  if (symtab_ == 0) {
+  if (symtab_ == nullptr) {
     DL_ERR("empty/missing DT_SYMTAB in \"%s\"", get_realpath());
     return false;
   }
diff --git a/linker/linker_main.cpp b/linker/linker_main.cpp
index 43f12d3..3410f90 100644
--- a/linker/linker_main.cpp
+++ b/linker/linker_main.cpp
@@ -56,6 +56,9 @@
 
 static ElfW(Addr) get_elf_exec_load_bias(const ElfW(Ehdr)* elf);
 
+static void get_elf_base_from_phdr(const ElfW(Phdr)* phdr_table, size_t phdr_count,
+                                   ElfW(Addr)* base, ElfW(Addr)* load_bias);
+
 // These should be preserved static to avoid emitting
 // RELATIVE relocations for the part of the code running
 // before linker links itself.
@@ -321,24 +324,8 @@
   si->phdr = reinterpret_cast<ElfW(Phdr)*>(args.getauxval(AT_PHDR));
   si->phnum = args.getauxval(AT_PHNUM);
 
-  /* Compute the value of si->base. We can't rely on the fact that
-   * the first entry is the PHDR because this will not be true
-   * for certain executables (e.g. some in the NDK unit test suite)
-   */
-  si->base = 0;
+  get_elf_base_from_phdr(si->phdr, si->phnum, &si->base, &si->load_bias);
   si->size = phdr_table_get_load_size(si->phdr, si->phnum);
-  si->load_bias = 0;
-  for (size_t i = 0; i < si->phnum; ++i) {
-    if (si->phdr[i].p_type == PT_PHDR) {
-      si->load_bias = reinterpret_cast<ElfW(Addr)>(si->phdr) - si->phdr[i].p_vaddr;
-      si->base = reinterpret_cast<ElfW(Addr)>(si->phdr) - si->phdr[i].p_offset;
-      break;
-    }
-  }
-
-  if (si->base == 0) {
-    async_safe_fatal("Could not find a PHDR: broken executable?");
-  }
 
   si->dynamic = nullptr;
 
@@ -503,6 +490,23 @@
   return 0;
 }
 
+/* Find the load bias and base address of an executable or shared object loaded
+ * by the kernel. The ELF file's PHDR table must have a PT_PHDR entry.
+ *
+ * A VDSO doesn't have a PT_PHDR entry in its PHDR table.
+ */
+static void get_elf_base_from_phdr(const ElfW(Phdr)* phdr_table, size_t phdr_count,
+                                   ElfW(Addr)* base, ElfW(Addr)* load_bias) {
+  for (size_t i = 0; i < phdr_count; ++i) {
+    if (phdr_table[i].p_type == PT_PHDR) {
+      *load_bias = reinterpret_cast<ElfW(Addr)>(phdr_table) - phdr_table[i].p_vaddr;
+      *base = reinterpret_cast<ElfW(Addr)>(phdr_table) - phdr_table[i].p_offset;
+      return;
+    }
+  }
+  async_safe_fatal("Could not find a PHDR: broken executable?");
+}
+
 static ElfW(Addr) __attribute__((noinline))
 __linker_init_post_relocation(KernelArgumentBlock& args,
                               ElfW(Addr) linker_addr,
@@ -524,22 +528,17 @@
   __libc_init_sysinfo(args);
 #endif
 
-  // AT_BASE is set to 0 in the case when linker is run by iself
-  // so in order to link the linker it needs to calcuate AT_BASE
-  // using information at hand. The trick below takes advantage
-  // of the fact that the value of linktime_addr before relocations
-  // are run is an offset and this can be used to calculate AT_BASE.
-  static uintptr_t linktime_addr = reinterpret_cast<uintptr_t>(&linktime_addr);
-  ElfW(Addr) linker_addr = reinterpret_cast<uintptr_t>(&linktime_addr) - linktime_addr;
-
-#if defined(__clang_analyzer__)
-  // The analyzer assumes that linker_addr will always be null. Make it an
-  // unknown value so we don't have to mark N places with NOLINTs.
-  //
-  // (`+=`, rather than `=`, allows us to sidestep a potential "unused store"
-  // complaint)
-  linker_addr += reinterpret_cast<uintptr_t>(raw_args);
-#endif
+  ElfW(Addr) linker_addr = args.getauxval(AT_BASE);
+  if (linker_addr == 0) {
+    // When the linker is run by itself (rather than as an interpreter for
+    // another program), AT_BASE is 0. In that case, the AT_PHDR and AT_PHNUM
+    // aux values describe the linker, so use the phdr to find the linker's
+    // base address.
+    ElfW(Addr) load_bias;
+    get_elf_base_from_phdr(
+      reinterpret_cast<ElfW(Phdr)*>(args.getauxval(AT_PHDR)), args.getauxval(AT_PHNUM),
+      &linker_addr, &load_bias);
+  }
 
   ElfW(Ehdr)* elf_hdr = reinterpret_cast<ElfW(Ehdr)*>(linker_addr);
   ElfW(Phdr)* phdr = reinterpret_cast<ElfW(Phdr)*>(linker_addr + elf_hdr->e_phoff);
diff --git a/tests/TemporaryFile.h b/tests/TemporaryFile.h
index 070b71a..8af92d4 100644
--- a/tests/TemporaryFile.h
+++ b/tests/TemporaryFile.h
@@ -80,7 +80,7 @@
  private:
   bool init(const char* tmp_dir) {
     snprintf(dirname, sizeof(dirname), "%s/TemporaryDir-XXXXXX", tmp_dir);
-    return (mkdtemp(dirname) != NULL);
+    return (mkdtemp(dirname) != nullptr);
   }
 
   DISALLOW_COPY_AND_ASSIGN(TemporaryDir);
diff --git a/tests/async_safe_test.cpp b/tests/async_safe_test.cpp
index e71ba7a..4940e3a 100644
--- a/tests/async_safe_test.cpp
+++ b/tests/async_safe_test.cpp
@@ -36,7 +36,7 @@
   async_safe_format_buffer(buf, sizeof(buf), "a%sb", "01234");
   EXPECT_STREQ("a01234b", buf);
 
-  char* s = NULL;
+  char* s = nullptr;
   async_safe_format_buffer(buf, sizeof(buf), "a%sb", s);
   EXPECT_STREQ("a(null)b", buf);
 
@@ -97,7 +97,7 @@
   async_safe_format_buffer(buf, sizeof(buf), "a%03d:%d:%02dz", 5, 5, 5);
   EXPECT_STREQ("a005:5:05z", buf);
 
-  void* p = NULL;
+  void* p = nullptr;
   async_safe_format_buffer(buf, sizeof(buf), "a%d,%pz", 5, p);
   EXPECT_STREQ("a5,0x0z", buf);
 
diff --git a/tests/buffer_tests.h b/tests/buffer_tests.h
index 315083b..d496d51 100644
--- a/tests/buffer_tests.h
+++ b/tests/buffer_tests.h
@@ -22,16 +22,16 @@
 
 void RunSingleBufferAlignTest(
     size_t max_test_size, void (*test_func)(uint8_t*, size_t),
-    size_t (*set_incr)(size_t) = NULL);
+    size_t (*set_incr)(size_t) = nullptr);
 
 void RunSrcDstBufferAlignTest(
     size_t max_test_size, void (*test_func)(uint8_t*, uint8_t*, size_t),
-    size_t (*set_incr)(size_t) = NULL);
+    size_t (*set_incr)(size_t) = nullptr);
 
 void RunCmpBufferAlignTest(
     size_t max_test_size, void (*test_cmp_func)(uint8_t*, uint8_t*, size_t),
     void (*test_miscmp_func)(uint8_t*, uint8_t*, size_t, size_t),
-    size_t (*set_incr)(size_t) = NULL);
+    size_t (*set_incr)(size_t) = nullptr);
 
 void RunSingleBufferOverreadTest(void (*test_func)(uint8_t*, size_t));
 
diff --git a/tests/bug_26110743_test.cpp b/tests/bug_26110743_test.cpp
index ef474a0..89c6dcc 100644
--- a/tests/bug_26110743_test.cpp
+++ b/tests/bug_26110743_test.cpp
@@ -42,15 +42,15 @@
 
 static void* ProcSelfReadlink(void*) {
   ProcSelfReadlinkBody();
-  return NULL;
+  return nullptr;
 }
 
 TEST(bug_26110743, ProcSelfReadlink) {
   pthread_t t;
-  ASSERT_EQ(0, pthread_create(&t, NULL, ProcSelfReadlink, NULL));
+  ASSERT_EQ(0, pthread_create(&t, nullptr, ProcSelfReadlink, nullptr));
   void* result;
   ASSERT_EQ(0, pthread_join(t, &result));
-  ASSERT_EQ(NULL, result);
+  ASSERT_EQ(nullptr, result);
 }
 
 TEST(bug_26110743, ProcSelfReadlink_NotDumpable) {
@@ -62,10 +62,10 @@
   });
 
   pthread_t t;
-  ASSERT_EQ(0, pthread_create(&t, NULL, ProcSelfReadlink, NULL));
+  ASSERT_EQ(0, pthread_create(&t, nullptr, ProcSelfReadlink, nullptr));
   void* result;
   ASSERT_EQ(0, pthread_join(t, &result));
-  ASSERT_EQ(NULL, result);
+  ASSERT_EQ(nullptr, result);
 }
 
 static void ProcTaskFdReadlinkBody() {
@@ -86,15 +86,15 @@
 
 static void* ProcTaskFdReadlink(void*) {
   ProcTaskFdReadlinkBody();
-  return NULL;
+  return nullptr;
 }
 
 TEST(bug_26110743, ProcTaskFdReadlink) {
   pthread_t t;
-  ASSERT_EQ(0, pthread_create(&t, NULL, ProcTaskFdReadlink, NULL));
+  ASSERT_EQ(0, pthread_create(&t, nullptr, ProcTaskFdReadlink, nullptr));
   void* result;
   ASSERT_EQ(0, pthread_join(t, &result));
-  ASSERT_EQ(NULL, result);
+  ASSERT_EQ(nullptr, result);
 }
 
 TEST(bug_26110743, ProcTaskFdReadlink_NotDumpable) {
@@ -106,8 +106,8 @@
   });
 
   pthread_t t;
-  ASSERT_EQ(0, pthread_create(&t, NULL, ProcTaskFdReadlink, NULL));
+  ASSERT_EQ(0, pthread_create(&t, nullptr, ProcTaskFdReadlink, nullptr));
   void* result;
   ASSERT_EQ(0, pthread_join(t, &result));
-  ASSERT_EQ(NULL, result);
+  ASSERT_EQ(nullptr, result);
 }
diff --git a/tests/dirent_test.cpp b/tests/dirent_test.cpp
index fa05ca1..378aea4 100644
--- a/tests/dirent_test.cpp
+++ b/tests/dirent_test.cpp
@@ -51,11 +51,11 @@
 TEST(dirent, scandir_scandir64) {
   // Get everything from /proc/self...
   dirent** entries;
-  int entry_count = scandir("/proc/self", &entries, NULL, alphasort);
+  int entry_count = scandir("/proc/self", &entries, nullptr, alphasort);
   ASSERT_GE(entry_count, 0);
 
   dirent64** entries64;
-  int entry_count64 = scandir64("/proc/self", &entries64, NULL, alphasort64);
+  int entry_count64 = scandir64("/proc/self", &entries64, nullptr, alphasort64);
   ASSERT_EQ(entry_count, entry_count64);
 
   // Turn the directory entries into a set and vector of the names.
@@ -84,18 +84,18 @@
 TEST(dirent, scandirat_scandirat64) {
   // Get everything from /proc/self...
   dirent** entries;
-  int entry_count = scandir("/proc/self", &entries, NULL, alphasort);
+  int entry_count = scandir("/proc/self", &entries, nullptr, alphasort);
   ASSERT_GE(entry_count, 0);
 
   int proc_fd = open("/proc", O_DIRECTORY);
   ASSERT_NE(-1, proc_fd);
 
   dirent** entries_at;
-  int entry_count_at = scandirat(proc_fd, "self", &entries_at, NULL, alphasort);
+  int entry_count_at = scandirat(proc_fd, "self", &entries_at, nullptr, alphasort);
   ASSERT_EQ(entry_count, entry_count_at);
 
   dirent64** entries_at64;
-  int entry_count_at64 = scandirat64(proc_fd, "self", &entries_at64, NULL, alphasort64);
+  int entry_count_at64 = scandirat64(proc_fd, "self", &entries_at64, nullptr, alphasort64);
   ASSERT_EQ(entry_count, entry_count_at64);
 
   close(proc_fd);
@@ -148,12 +148,12 @@
 }
 
 TEST(dirent, fdopendir_invalid) {
-  ASSERT_TRUE(fdopendir(-1) == NULL);
+  ASSERT_TRUE(fdopendir(-1) == nullptr);
   ASSERT_EQ(EBADF, errno);
 
   int fd = open("/dev/null", O_RDONLY);
   ASSERT_NE(fd, -1);
-  ASSERT_TRUE(fdopendir(fd) == NULL);
+  ASSERT_TRUE(fdopendir(fd) == nullptr);
   ASSERT_EQ(ENOTDIR, errno);
   close(fd);
 }
@@ -161,7 +161,7 @@
 TEST(dirent, fdopendir) {
   int fd = open("/proc/self", O_RDONLY);
   DIR* d = fdopendir(fd);
-  ASSERT_TRUE(d != NULL);
+  ASSERT_TRUE(d != nullptr);
   dirent* e = readdir(d);
   ASSERT_STREQ(e->d_name, ".");
   ASSERT_EQ(closedir(d), 0);
@@ -172,40 +172,40 @@
 }
 
 TEST(dirent, opendir_invalid) {
-  ASSERT_TRUE(opendir("/does/not/exist") == NULL);
+  ASSERT_TRUE(opendir("/does/not/exist") == nullptr);
   ASSERT_EQ(ENOENT, errno);
 
-  ASSERT_TRUE(opendir("/dev/null") == NULL);
+  ASSERT_TRUE(opendir("/dev/null") == nullptr);
   ASSERT_EQ(ENOTDIR, errno);
 }
 
 TEST(dirent, opendir) {
   DIR* d = opendir("/proc/self");
-  ASSERT_TRUE(d != NULL);
+  ASSERT_TRUE(d != nullptr);
   dirent* e = readdir(d);
   ASSERT_STREQ(e->d_name, ".");
   ASSERT_EQ(closedir(d), 0);
 }
 
 TEST(dirent, closedir_invalid) {
-  DIR* d = NULL;
+  DIR* d = nullptr;
   ASSERT_EQ(closedir(d), -1);
   ASSERT_EQ(EINVAL, errno);
 }
 
 TEST(dirent, closedir) {
   DIR* d = opendir("/proc/self");
-  ASSERT_TRUE(d != NULL);
+  ASSERT_TRUE(d != nullptr);
   ASSERT_EQ(closedir(d), 0);
 }
 
 TEST(dirent, readdir) {
   DIR* d = opendir("/proc/self");
-  ASSERT_TRUE(d != NULL);
+  ASSERT_TRUE(d != nullptr);
   std::set<std::string> name_set;
   errno = 0;
   dirent* e;
-  while ((e = readdir(d)) != NULL) {
+  while ((e = readdir(d)) != nullptr) {
     name_set.insert(e->d_name);
   }
   // Reading to the end of the directory is not an error.
@@ -218,11 +218,11 @@
 
 TEST(dirent, readdir64) {
   DIR* d = opendir("/proc/self");
-  ASSERT_TRUE(d != NULL);
+  ASSERT_TRUE(d != nullptr);
   std::set<std::string> name_set;
   errno = 0;
   dirent64* e;
-  while ((e = readdir64(d)) != NULL) {
+  while ((e = readdir64(d)) != nullptr) {
     name_set.insert(e->d_name);
   }
   // Reading to the end of the directory is not an error.
@@ -235,12 +235,12 @@
 
 TEST(dirent, readdir_r) {
   DIR* d = opendir("/proc/self");
-  ASSERT_TRUE(d != NULL);
+  ASSERT_TRUE(d != nullptr);
   std::set<std::string> name_set;
   errno = 0;
   dirent storage;
-  dirent* e = NULL;
-  while (readdir_r(d, &storage, &e) == 0 && e != NULL) {
+  dirent* e = nullptr;
+  while (readdir_r(d, &storage, &e) == 0 && e != nullptr) {
     name_set.insert(e->d_name);
   }
   // Reading to the end of the directory is not an error.
@@ -253,12 +253,12 @@
 
 TEST(dirent, readdir64_r) {
   DIR* d = opendir("/proc/self");
-  ASSERT_TRUE(d != NULL);
+  ASSERT_TRUE(d != nullptr);
   std::set<std::string> name_set;
   errno = 0;
   dirent64 storage;
-  dirent64* e = NULL;
-  while (readdir64_r(d, &storage, &e) == 0 && e != NULL) {
+  dirent64* e = nullptr;
+  while (readdir64_r(d, &storage, &e) == 0 && e != nullptr) {
     name_set.insert(e->d_name);
   }
   // Reading to the end of the directory is not an error.
@@ -271,12 +271,12 @@
 
 TEST(dirent, rewinddir) {
   DIR* d = opendir("/proc/self");
-  ASSERT_TRUE(d != NULL);
+  ASSERT_TRUE(d != nullptr);
 
   // Get all the names once...
   std::vector<std::string> pass1;
   dirent* e;
-  while ((e = readdir(d)) != NULL) {
+  while ((e = readdir(d)) != nullptr) {
     pass1.push_back(e->d_name);
   }
 
@@ -285,7 +285,7 @@
 
   // ...and get all the names again.
   std::vector<std::string> pass2;
-  while ((e = readdir(d)) != NULL) {
+  while ((e = readdir(d)) != nullptr) {
     pass2.push_back(e->d_name);
   }
 
@@ -300,15 +300,15 @@
 
 TEST(dirent, seekdir_telldir) {
   DIR* d = opendir("/proc/self");
-  ASSERT_TRUE(d != NULL);
+  ASSERT_TRUE(d != nullptr);
   std::vector<long> offset_list;
   std::vector<std::string> name_list;
-  dirent* e = NULL;
+  dirent* e = nullptr;
 
   offset_list.push_back(telldir(d));
   ASSERT_EQ(0L, offset_list.back());
 
-  while ((e = readdir(d)) != NULL) {
+  while ((e = readdir(d)) != nullptr) {
     name_list.push_back(e->d_name);
     offset_list.push_back(telldir(d));
     // Make sure telldir() point to the next entry.
@@ -324,14 +324,14 @@
     seekdir(d, offset_list[i]);
     ASSERT_EQ(offset_list[i], telldir(d));
     e = readdir(d);
-    ASSERT_TRUE(e != NULL);
+    ASSERT_TRUE(e != nullptr);
     ASSERT_STREQ(name_list[i].c_str(), e->d_name);
   }
   for (int i = static_cast<int>(offset_list.size()) - 1; i >= 0; --i) {
     seekdir(d, offset_list[i]);
     ASSERT_EQ(offset_list[i], telldir(d));
     e = readdir(d);
-    ASSERT_TRUE(e != NULL);
+    ASSERT_TRUE(e != nullptr);
     ASSERT_STREQ(name_list[i].c_str(), e->d_name);
   }
 
@@ -339,7 +339,7 @@
   seekdir(d, end_offset);
   ASSERT_EQ(end_offset, telldir(d));
   errno = 0;
-  ASSERT_EQ(NULL, readdir(d));
+  ASSERT_EQ(nullptr, readdir(d));
   ASSERT_EQ(0, errno);
 
   ASSERT_EQ(0, closedir(d));
diff --git a/tests/error_test.cpp b/tests/error_test.cpp
index 5fee16f..e03c8d4 100644
--- a/tests/error_test.cpp
+++ b/tests/error_test.cpp
@@ -52,7 +52,7 @@
 
   error_at_line(0, 0, "blah.c", 123, "hello %s", "world");
 
-  error_print_progname = NULL;
+  error_print_progname = nullptr;
 }
 
 TEST(error_DeathTest, error_exit) {
diff --git a/tests/eventfd_test.cpp b/tests/eventfd_test.cpp
index aa88a3b..68d9192 100644
--- a/tests/eventfd_test.cpp
+++ b/tests/eventfd_test.cpp
@@ -19,20 +19,7 @@
 
 #include <gtest/gtest.h>
 
-#if defined(__BIONIC__) // Android's prebuilt gcc's header files don't include <sys/eventfd.h>.
 #include <sys/eventfd.h>
-#else
-// Include the necessary components of sys/eventfd.h right here.
-#include <stdint.h>
-
-typedef uint64_t eventfd_t;
-
-__BEGIN_DECLS
-extern int eventfd(int, int);
-extern int eventfd_read(int, eventfd_t*);
-extern int eventfd_write(int, eventfd_t);
-__END_DECLS
-#endif
 
 TEST(eventfd, smoke) {
   unsigned int initial_value = 2;
diff --git a/tests/fcntl_test.cpp b/tests/fcntl_test.cpp
index 0a83dff..da44fee 100644
--- a/tests/fcntl_test.cpp
+++ b/tests/fcntl_test.cpp
@@ -174,10 +174,10 @@
 
   TemporaryFile tf;
 
-  ssize_t bytes_read = splice(in, 0, pipe_fds[1], NULL, 8*1024, SPLICE_F_MORE | SPLICE_F_MOVE);
+  ssize_t bytes_read = splice(in, nullptr, pipe_fds[1], nullptr, 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);
+  ssize_t bytes_written = splice(pipe_fds[0], nullptr, tf.fd, nullptr, bytes_read, SPLICE_F_MORE | SPLICE_F_MOVE);
   ASSERT_EQ(bytes_read, bytes_written);
 
   close(pipe_fds[0]);
@@ -200,8 +200,8 @@
 
   char buf[BUFSIZ];
   FILE* fp = fdopen(pipe_fds[0], "r");
-  ASSERT_TRUE(fp != NULL);
-  ASSERT_TRUE(fgets(buf, sizeof(buf), fp) != NULL);
+  ASSERT_TRUE(fp != nullptr);
+  ASSERT_TRUE(fgets(buf, sizeof(buf), fp) != nullptr);
   fclose(fp);
   ASSERT_STREQ("hello world\n", buf);
 }
@@ -209,8 +209,8 @@
 TEST(fcntl, tee) {
   char expected[BUFSIZ];
   FILE* expected_fp = fopen("/proc/version", "r");
-  ASSERT_TRUE(expected_fp != NULL);
-  ASSERT_TRUE(fgets(expected, sizeof(expected), expected_fp) != NULL);
+  ASSERT_TRUE(expected_fp != nullptr);
+  ASSERT_TRUE(fgets(expected, sizeof(expected), expected_fp) != nullptr);
   fclose(expected_fp);
 
   int pipe1[2];
@@ -223,7 +223,7 @@
   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);
+  ssize_t bytes_read = splice(in, nullptr, pipe1[1], nullptr, 8*1024, SPLICE_F_MORE | SPLICE_F_MOVE);
   ASSERT_NE(bytes_read, -1);
   close(pipe1[1]);
 
@@ -235,14 +235,14 @@
   // 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);
+  ASSERT_TRUE(fp1 != nullptr);
+  ASSERT_TRUE(fgets(buf1, sizeof(buf1), fp1) != nullptr);
   fclose(fp1);
 
   char buf2[BUFSIZ];
   FILE* fp2 = fdopen(pipe2[0], "r");
-  ASSERT_TRUE(fp2 != NULL);
-  ASSERT_TRUE(fgets(buf2, sizeof(buf2), fp2) != NULL);
+  ASSERT_TRUE(fp2 != nullptr);
+  ASSERT_TRUE(fgets(buf2, sizeof(buf2), fp2) != nullptr);
   fclose(fp2);
 
   ASSERT_STREQ(expected, buf1);
diff --git a/tests/fdsan_test.cpp b/tests/fdsan_test.cpp
index 99f36aa..a57e7c7 100644
--- a/tests/fdsan_test.cpp
+++ b/tests/fdsan_test.cpp
@@ -70,7 +70,7 @@
 #if defined(__BIONIC__)
   int fd = open("/dev/null", O_RDONLY);
   EXPECT_FDSAN_DEATH(android_fdsan_exchange_owner_tag(fd, 0xbadc0de, 0xdeadbeef),
-                     "failed to exchange");
+                     "failed to exchange ownership");
 #endif
 }
 
@@ -138,3 +138,23 @@
   }
 #endif
 }
+
+TEST_F(FdsanTest, owner_value_high) {
+#if defined(__BIONIC__)
+  int fd = open("/dev/null", O_RDONLY);
+  uint64_t tag = android_fdsan_create_owner_tag(ANDROID_FDSAN_OWNER_TYPE_UNIQUE_FD, ~0ULL);
+  android_fdsan_exchange_owner_tag(fd, 0, tag);
+  EXPECT_FDSAN_DEATH(android_fdsan_exchange_owner_tag(fd, 0xbadc0de, 0xdeadbeef),
+                     "0xffffffffffffffff");
+#endif
+}
+
+TEST_F(FdsanTest, owner_value_low) {
+#if defined(__BIONIC__)
+  int fd = open("/dev/null", O_RDONLY);
+  uint64_t tag = android_fdsan_create_owner_tag(ANDROID_FDSAN_OWNER_TYPE_UNIQUE_FD, 1);
+  android_fdsan_exchange_owner_tag(fd, 0, tag);
+  EXPECT_FDSAN_DEATH(android_fdsan_exchange_owner_tag(fd, 0xbadc0de, 0xdeadbeef),
+                     "0x1");
+#endif
+}
diff --git a/tests/fortify_filecheck_diagnostics_test.cpp b/tests/fortify_filecheck_diagnostics_test.cpp
index 380a344..a69b967 100644
--- a/tests/fortify_filecheck_diagnostics_test.cpp
+++ b/tests/fortify_filecheck_diagnostics_test.cpp
@@ -169,7 +169,7 @@
   sockaddr_in addr;
 
   // CLANG: error: 'recvfrom' called with size bigger than buffer
-  recvfrom(0, buf, 6, 0, reinterpret_cast<sockaddr*>(&addr), NULL);
+  recvfrom(0, buf, 6, 0, reinterpret_cast<sockaddr*>(&addr), nullptr);
 }
 
 void test_recv() {
@@ -316,9 +316,9 @@
   realpath(".", buf);
 
   // This is fine.
-  realpath(".", NULL);
+  realpath(".", nullptr);
 
   char bigbuf[PATH_MAX];
   // CLANG: error: 'realpath': NULL path is never correct; flipped arguments?
-  realpath(NULL, bigbuf);
+  realpath(nullptr, bigbuf);
 }
diff --git a/tests/ftw_test.cpp b/tests/ftw_test.cpp
index 91e9fcf..22ab399 100644
--- a/tests/ftw_test.cpp
+++ b/tests/ftw_test.cpp
@@ -50,8 +50,8 @@
 }
 
 void sanity_check_ftw(const char* fpath, const struct stat* sb, int tflag) {
-  ASSERT_TRUE(fpath != NULL);
-  ASSERT_TRUE(sb != NULL);
+  ASSERT_TRUE(fpath != nullptr);
+  ASSERT_TRUE(sb != nullptr);
 
   // Was it a case where the struct stat we're given is meaningless?
   if (tflag == FTW_NS || tflag == FTW_SLN) {
diff --git a/tests/getcwd_test.cpp b/tests/getcwd_test.cpp
index b3b4136..f8f205e 100644
--- a/tests/getcwd_test.cpp
+++ b/tests/getcwd_test.cpp
@@ -23,8 +23,8 @@
 TEST(getcwd, auto_full) {
   // If we let the library do all the work, everything's fine.
   errno = 0;
-  char* cwd = getcwd(NULL, 0);
-  ASSERT_TRUE(cwd != NULL);
+  char* cwd = getcwd(nullptr, 0);
+  ASSERT_TRUE(cwd != nullptr);
   ASSERT_EQ(0, errno);
   ASSERT_GE(strlen(cwd), 1U);
   free(cwd);
@@ -33,8 +33,8 @@
 TEST(getcwd, auto_reasonable) {
   // If we ask the library to allocate a reasonable buffer, everything's fine.
   errno = 0;
-  char* cwd = getcwd(NULL, PATH_MAX);
-  ASSERT_TRUE(cwd != NULL);
+  char* cwd = getcwd(nullptr, PATH_MAX);
+  ASSERT_TRUE(cwd != nullptr);
   ASSERT_EQ(0, errno);
   ASSERT_GE(strlen(cwd), 1U);
   free(cwd);
@@ -43,16 +43,16 @@
 TEST(getcwd, auto_too_small) {
   // If we ask the library to allocate a too-small buffer, ERANGE.
   errno = 0;
-  char* cwd = getcwd(NULL, 1);
-  ASSERT_TRUE(cwd == NULL);
+  char* cwd = getcwd(nullptr, 1);
+  ASSERT_TRUE(cwd == nullptr);
   ASSERT_EQ(ERANGE, errno);
 }
 
 TEST(getcwd, auto_too_large) {
   // If we ask the library to allocate an unreasonably large buffer, ERANGE.
   errno = 0;
-  char* cwd = getcwd(NULL, static_cast<size_t>(-1));
-  ASSERT_TRUE(cwd == NULL);
+  char* cwd = getcwd(nullptr, static_cast<size_t>(-1));
+  ASSERT_TRUE(cwd == nullptr);
   ASSERT_EQ(ENOMEM, errno);
 }
 
@@ -61,7 +61,7 @@
   char tiny_buf[1];
   errno = 0;
   char* cwd = getcwd(tiny_buf, sizeof(tiny_buf));
-  ASSERT_TRUE(cwd == NULL);
+  ASSERT_TRUE(cwd == nullptr);
   ASSERT_EQ(ERANGE, errno);
 }
 
@@ -70,7 +70,7 @@
   char tiny_buf[1];
   errno = 0;
   char* cwd = getcwd(tiny_buf, 0);
-  ASSERT_TRUE(cwd == NULL);
+  ASSERT_TRUE(cwd == nullptr);
   ASSERT_EQ(EINVAL, errno);
 }
 
diff --git a/tests/grp_pwd_test.cpp b/tests/grp_pwd_test.cpp
index 2df1ef0..68897ed 100644
--- a/tests/grp_pwd_test.cpp
+++ b/tests/grp_pwd_test.cpp
@@ -50,15 +50,15 @@
 
 static void check_passwd(const passwd* pwd, const char* username, uid_t uid, uid_type_t uid_type,
                          bool check_username) {
-  ASSERT_TRUE(pwd != NULL);
+  ASSERT_TRUE(pwd != nullptr);
   if (check_username) {
     EXPECT_STREQ(username, pwd->pw_name);
   }
   EXPECT_EQ(uid, pwd->pw_uid);
   EXPECT_EQ(uid, pwd->pw_gid);
-  EXPECT_EQ(NULL, pwd->pw_passwd);
+  EXPECT_EQ(nullptr, pwd->pw_passwd);
 #ifdef __LP64__
-  EXPECT_EQ(NULL, pwd->pw_gecos);
+  EXPECT_EQ(nullptr, pwd->pw_gecos);
 #endif
 
   if (uid_type == TYPE_SYSTEM) {
@@ -94,7 +94,7 @@
   int result;
 
   errno = 0;
-  passwd* pwd = NULL;
+  passwd* pwd = nullptr;
   result = getpwuid_r(uid, &pwd_storage, buf, sizeof(buf), &pwd);
   ASSERT_EQ(0, result);
   ASSERT_EQ(0, errno);
@@ -109,7 +109,7 @@
   int result;
 
   errno = 0;
-  passwd* pwd = NULL;
+  passwd* pwd = nullptr;
   result = getpwnam_r(username, &pwd_storage, buf, sizeof(buf), &pwd);
   ASSERT_EQ(0, result);
   ASSERT_EQ(0, errno);
@@ -264,15 +264,15 @@
   std::set<uid_t> uids;
 
   setpwent();
-  while ((pwd = getpwent()) != NULL) {
-    ASSERT_TRUE(NULL != pwd->pw_name);
+  while ((pwd = getpwent()) != nullptr) {
+    ASSERT_TRUE(nullptr != pwd->pw_name);
 
     EXPECT_EQ(pwd->pw_gid, pwd->pw_uid) << "pwd->pw_uid: " << pwd->pw_uid;
-    EXPECT_EQ(NULL, pwd->pw_passwd) << "pwd->pw_uid: " << pwd->pw_uid;
+    EXPECT_EQ(nullptr, pwd->pw_passwd) << "pwd->pw_uid: " << pwd->pw_uid;
 #ifdef __LP64__
-    EXPECT_TRUE(NULL == pwd->pw_gecos) << "pwd->pw_uid: " << pwd->pw_uid;
+    EXPECT_TRUE(nullptr == pwd->pw_gecos) << "pwd->pw_uid: " << pwd->pw_uid;
 #endif
-    EXPECT_TRUE(NULL != pwd->pw_shell);
+    EXPECT_TRUE(nullptr != pwd->pw_shell);
     if (pwd->pw_uid < AID_APP_START || pwd->pw_uid == AID_OVERFLOWUID) {
       EXPECT_STREQ("/", pwd->pw_dir) << "pwd->pw_uid: " << pwd->pw_uid;
     } else {
@@ -299,16 +299,16 @@
 
 static void check_group(const group* grp, const char* group_name, gid_t gid,
                         bool check_groupname = true) {
-  ASSERT_TRUE(grp != NULL);
+  ASSERT_TRUE(grp != nullptr);
   if (check_groupname) {
     EXPECT_STREQ(group_name, grp->gr_name);
   }
   EXPECT_EQ(gid, grp->gr_gid);
-  ASSERT_TRUE(grp->gr_mem != NULL);
+  ASSERT_TRUE(grp->gr_mem != nullptr);
   if (check_groupname) {
     EXPECT_STREQ(group_name, grp->gr_mem[0]);
   }
-  EXPECT_TRUE(grp->gr_mem[1] == NULL);
+  EXPECT_TRUE(grp->gr_mem[1] == nullptr);
 }
 
 #if defined(__BIONIC__)
@@ -523,11 +523,11 @@
   std::set<gid_t> gids;
 
   setgrent();
-  while ((grp = getgrent()) != NULL) {
-    ASSERT_TRUE(grp->gr_name != NULL) << "grp->gr_gid: " << grp->gr_gid;
-    ASSERT_TRUE(grp->gr_mem != NULL) << "grp->gr_gid: " << grp->gr_gid;
+  while ((grp = getgrent()) != nullptr) {
+    ASSERT_TRUE(grp->gr_name != nullptr) << "grp->gr_gid: " << grp->gr_gid;
+    ASSERT_TRUE(grp->gr_mem != nullptr) << "grp->gr_gid: " << grp->gr_gid;
     EXPECT_STREQ(grp->gr_name, grp->gr_mem[0]) << "grp->gr_gid: " << grp->gr_gid;
-    EXPECT_TRUE(grp->gr_mem[1] == NULL) << "grp->gr_gid: " << grp->gr_gid;
+    EXPECT_TRUE(grp->gr_mem[1] == nullptr) << "grp->gr_gid: " << grp->gr_gid;
 
     // TODO(b/27999086): fix this check with the OEM range
     // If OEMs add their own AIDs to private/android_filesystem_config.h, this check will fail.
diff --git a/tests/gtest_main.cpp b/tests/gtest_main.cpp
index 8aa94bb..ba29825 100644
--- a/tests/gtest_main.cpp
+++ b/tests/gtest_main.cpp
@@ -263,7 +263,7 @@
 
 class TestResultPrinter : public testing::EmptyTestEventListener {
  public:
-  TestResultPrinter() : pinfo_(NULL) {}
+  TestResultPrinter() : pinfo_(nullptr) {}
   virtual void OnTestStart(const testing::TestInfo& test_info) {
     pinfo_ = &test_info; // Record test_info for use in OnTestPartResult.
   }
@@ -566,7 +566,7 @@
                                 time_t epoch_iteration_start_time,
                                 int64_t elapsed_time_ns) {
   FILE* fp = fopen(xml_output_filename.c_str(), "we");
-  if (fp == NULL) {
+  if (fp == nullptr) {
     fprintf(stderr, "failed to open '%s': %s\n", xml_output_filename.c_str(), strerror(errno));
     exit(1);
   }
@@ -683,7 +683,7 @@
   strcpy(filter_arg, "--gtest_filter=");
   strcat(filter_arg, test_name.c_str());
   new_argv[argc] = filter_arg;
-  new_argv[argc + 1] = NULL;
+  new_argv[argc + 1] = nullptr;
 
   int new_argc = argc + 1;
   testing::InitGoogleTest(&new_argc, new_argv);
@@ -848,7 +848,7 @@
     timespec sleep_time;
     sleep_time.tv_sec = 0;
     sleep_time.tv_nsec = 1000000;
-    nanosleep(&sleep_time, NULL);
+    nanosleep(&sleep_time, nullptr);
   }
 }
 
@@ -922,7 +922,7 @@
        ++iteration) {
     OnTestIterationStartPrint(testcase_list, iteration, iteration_count, job_count);
     int64_t iteration_start_time_ns = NanoTime();
-    time_t epoch_iteration_start_time = time(NULL);
+    time_t epoch_iteration_start_time = time(nullptr);
 
     // Run up to job_count tests in parallel, each test in a child process.
     std::vector<ChildProcInfo> child_proc_list;
@@ -1159,8 +1159,8 @@
         }
         // Make absolute path.
         if (success && output[0] != '/') {
-          char* cwd = getcwd(NULL, 0);
-          if (cwd != NULL) {
+          char* cwd = getcwd(nullptr, 0);
+          if (cwd != nullptr) {
             output = std::string(cwd) + "/" + output;
             free(cwd);
           } else {
@@ -1223,7 +1223,7 @@
     std::vector<TestCase> testcase_list;
 
     argc = static_cast<int>(arg_list.size());
-    arg_list.push_back(NULL);
+    arg_list.push_back(nullptr);
     if (EnumerateTests(argc, arg_list.data(), testcase_list) == false) {
       return 1;
     }
@@ -1232,7 +1232,7 @@
     return all_test_passed ? 0 : 1;
   } else {
     argc = static_cast<int>(arg_list.size());
-    arg_list.push_back(NULL);
+    arg_list.push_back(nullptr);
     testing::InitGoogleTest(&argc, arg_list.data());
     return RUN_ALL_TESTS();
   }
diff --git a/tests/inttypes_test.cpp b/tests/inttypes_test.cpp
index 08258ac..f7dfdb5 100644
--- a/tests/inttypes_test.cpp
+++ b/tests/inttypes_test.cpp
@@ -123,13 +123,13 @@
 
 TEST(inttypes, strtoimax_EINVAL) {
   errno = 0;
-  strtoimax("123", NULL, -1);
+  strtoimax("123", nullptr, -1);
   ASSERT_EQ(EINVAL, errno);
   errno = 0;
-  strtoimax("123", NULL, 1);
+  strtoimax("123", nullptr, 1);
   ASSERT_EQ(EINVAL, errno);
   errno = 0;
-  strtoimax("123", NULL, 37);
+  strtoimax("123", nullptr, 37);
   ASSERT_EQ(EINVAL, errno);
 }
 
@@ -153,37 +153,37 @@
 
 TEST(inttypes, strtoumax_EINVAL) {
   errno = 0;
-  strtoumax("123", NULL, -1);
+  strtoumax("123", nullptr, -1);
   ASSERT_EQ(EINVAL, errno);
   errno = 0;
-  strtoumax("123", NULL, 1);
+  strtoumax("123", nullptr, 1);
   ASSERT_EQ(EINVAL, errno);
   errno = 0;
-  strtoumax("123", NULL, 37);
+  strtoumax("123", nullptr, 37);
   ASSERT_EQ(EINVAL, errno);
 }
 
 TEST(inttypes, wcstoimax_EINVAL) {
   errno = 0;
-  wcstoimax(L"123", NULL, -1);
+  wcstoimax(L"123", nullptr, -1);
   ASSERT_EQ(EINVAL, errno);
   errno = 0;
-  wcstoimax(L"123", NULL, 1);
+  wcstoimax(L"123", nullptr, 1);
   ASSERT_EQ(EINVAL, errno);
   errno = 0;
-  wcstoimax(L"123", NULL, 37);
+  wcstoimax(L"123", nullptr, 37);
   ASSERT_EQ(EINVAL, errno);
 }
 
 TEST(inttypes, wcstoumax_EINVAL) {
   errno = 0;
-  wcstoumax(L"123", NULL, -1);
+  wcstoumax(L"123", nullptr, -1);
   ASSERT_EQ(EINVAL, errno);
   errno = 0;
-  wcstoumax(L"123", NULL, 1);
+  wcstoumax(L"123", nullptr, 1);
   ASSERT_EQ(EINVAL, errno);
   errno = 0;
-  wcstoumax(L"123", NULL, 37);
+  wcstoumax(L"123", nullptr, 37);
   ASSERT_EQ(EINVAL, errno);
 }
 
diff --git a/tests/libgen_basename_test.cpp b/tests/libgen_basename_test.cpp
index d97e0da..91ae960 100644
--- a/tests/libgen_basename_test.cpp
+++ b/tests/libgen_basename_test.cpp
@@ -49,7 +49,7 @@
 }
 
 static void __TestPosixBasename(const char* in, const char* expected_out, int line) {
-  char* writable_in = (in != NULL) ? strdup(in) : NULL;
+  char* writable_in = (in != nullptr) ? strdup(in) : nullptr;
   errno = 0;
   const char* out = posix_basename(&writable_in[0]);
   ASSERT_STREQ(expected_out, out) << "(" << line << "): " << in << std::endl;
@@ -76,7 +76,7 @@
 }
 
 TEST(libgen_basename, posix_basename) {
-  TestPosixBasename(NULL, ".");
+  TestPosixBasename(nullptr, ".");
   TestPosixBasename("", ".");
   TestPosixBasename("/usr/lib", "lib");
   TestPosixBasename("/system/bin/sh/", "sh");
diff --git a/tests/libgen_test.cpp b/tests/libgen_test.cpp
index 8a37a3f..d5b5eb6 100644
--- a/tests/libgen_test.cpp
+++ b/tests/libgen_test.cpp
@@ -20,7 +20,7 @@
 #include <gtest/gtest.h>
 
 static void TestDirname(const char* in, const char* expected_out) {
-  char* writable_in = (in != NULL) ? strdup(in) : NULL;
+  char* writable_in = (in != nullptr) ? strdup(in) : nullptr;
   errno = 0;
   const char* out = dirname(&writable_in[0]);
   ASSERT_STREQ(expected_out, out) << in;
@@ -29,7 +29,7 @@
 }
 
 TEST(libgen, dirname) {
-  TestDirname(NULL, ".");
+  TestDirname(nullptr, ".");
   TestDirname("", ".");
   TestDirname("/usr/lib", "/usr");
   TestDirname("/usr/", "/");
@@ -45,7 +45,7 @@
   errno = 0;
   int rc = basename_r(in, buf, buf_size);
   ASSERT_EQ(expected_rc, rc) << in;
-  if (rc != -1 && buf != NULL) {
+  if (rc != -1 && buf != nullptr) {
     ASSERT_STREQ(expected_out, buf) << in;
   }
   ASSERT_EQ(expected_errno, errno) << in;
@@ -56,7 +56,7 @@
   errno = 0;
   int rc = dirname_r(in, buf, buf_size);
   ASSERT_EQ(expected_rc, rc) << in;
-  if (rc != -1 && buf != NULL) {
+  if (rc != -1 && buf != nullptr) {
     ASSERT_STREQ(expected_out, buf) << in;
   }
   ASSERT_EQ(expected_errno, errno) << in;
@@ -66,7 +66,7 @@
 TEST(libgen, basename_r) {
 #if defined(__BIONIC__) && !defined(__LP64__)
   char buf[256];
-  TestBasename("", ".",  1, NULL, 0, 0);
+  TestBasename("", ".",  1, nullptr, 0, 0);
   TestBasename("", ".", -1, buf, 0, ERANGE);
   TestBasename("", ".", -1, buf, 1, ERANGE);
   TestBasename("", ".", 1, buf, 2, 0);
@@ -85,7 +85,7 @@
 TEST(libgen, dirname_r) {
 #if defined(__BIONIC__) && !defined(__LP64__)
   char buf[256];
-  TestDirname("", ".",  1, NULL, 0, 0);
+  TestDirname("", ".",  1, nullptr, 0, 0);
   TestDirname("", ".", -1, buf, 0, ERANGE);
   TestDirname("", ".", -1, buf, 1, ERANGE);
   TestDirname("", ".", 1, buf, 2, 0);
diff --git a/tests/libs/dlopen_testlib_ifunc.cpp b/tests/libs/dlopen_testlib_ifunc.cpp
index f8acba7..f2e0025 100644
--- a/tests/libs/dlopen_testlib_ifunc.cpp
+++ b/tests/libs/dlopen_testlib_ifunc.cpp
@@ -61,7 +61,7 @@
 
 extern "C" fn_ptr foo_ifunc() {
    char* choice = getenv("IFUNC_CHOICE");
-   return choice == NULL ? f1 : f2;
+   return choice == nullptr ? f1 : f2;
 }
 
 extern "C" const char* foo_library() {
diff --git a/tests/libs/dlopen_testlib_ifunc_variable_impl.cpp b/tests/libs/dlopen_testlib_ifunc_variable_impl.cpp
index a550fef..4b13eba 100644
--- a/tests/libs/dlopen_testlib_ifunc_variable_impl.cpp
+++ b/tests/libs/dlopen_testlib_ifunc_variable_impl.cpp
@@ -49,5 +49,5 @@
 
 extern "C" void* foo_ifunc() {
    char* choice = getenv("IFUNC_CHOICE");
-   return choice == NULL ? &v1 : &v2;
+   return choice == nullptr ? &v1 : &v2;
 }
diff --git a/tests/locale_test.cpp b/tests/locale_test.cpp
index 8b38c40..b4da6de 100644
--- a/tests/locale_test.cpp
+++ b/tests/locale_test.cpp
@@ -48,14 +48,14 @@
 }
 
 TEST(locale, setlocale) {
-  EXPECT_STREQ("C.UTF-8", setlocale(LC_ALL, NULL));
-  EXPECT_STREQ("C.UTF-8", setlocale(LC_CTYPE, NULL));
+  EXPECT_STREQ("C.UTF-8", setlocale(LC_ALL, nullptr));
+  EXPECT_STREQ("C.UTF-8", setlocale(LC_CTYPE, nullptr));
 
   errno = 0;
-  EXPECT_EQ(NULL, setlocale(-1, NULL));
+  EXPECT_EQ(nullptr, setlocale(-1, nullptr));
   EXPECT_EQ(EINVAL, errno);
   errno = 0;
-  EXPECT_EQ(NULL, setlocale(13, NULL));
+  EXPECT_EQ(nullptr, setlocale(13, nullptr));
   EXPECT_EQ(EINVAL, errno);
 
 #if defined(__BIONIC__)
@@ -68,53 +68,53 @@
   EXPECT_STREQ("C", setlocale(LC_ALL, "POSIX"));
 
   errno = 0;
-  EXPECT_EQ(NULL, setlocale(LC_ALL, "this-is-not-a-locale"));
+  EXPECT_EQ(nullptr, setlocale(LC_ALL, "this-is-not-a-locale"));
   EXPECT_EQ(ENOENT, errno); // POSIX specified, not an implementation detail!
 }
 
 TEST(locale, newlocale_invalid_category_mask) {
   errno = 0;
-  EXPECT_EQ(0, newlocale(1 << 20, "C", 0));
+  EXPECT_EQ(nullptr, newlocale(1 << 20, "C", nullptr));
   EXPECT_EQ(EINVAL, errno);
 }
 
 TEST(locale, newlocale_NULL_locale_name) {
   errno = 0;
-  EXPECT_EQ(0, newlocale(LC_ALL, NULL, 0));
+  EXPECT_EQ(nullptr, newlocale(LC_ALL, nullptr, nullptr));
   EXPECT_EQ(EINVAL, errno);
 }
 
 TEST(locale, newlocale_bad_locale_name) {
   errno = 0;
-  EXPECT_EQ(0, newlocale(LC_ALL, "this-is-not-a-locale", 0));
+  EXPECT_EQ(nullptr, newlocale(LC_ALL, "this-is-not-a-locale", nullptr));
   EXPECT_EQ(ENOENT, errno); // POSIX specified, not an implementation detail!
 }
 
 TEST(locale, newlocale) {
-  locale_t l = newlocale(LC_ALL, "C", 0);
-  ASSERT_TRUE(l != NULL);
+  locale_t l = newlocale(LC_ALL, "C", nullptr);
+  ASSERT_TRUE(l != nullptr);
   freelocale(l);
 }
 
 TEST(locale, duplocale) {
   locale_t cloned_global = duplocale(LC_GLOBAL_LOCALE);
-  ASSERT_TRUE(cloned_global != NULL);
+  ASSERT_TRUE(cloned_global != nullptr);
   freelocale(cloned_global);
 }
 
 TEST(locale, uselocale) {
-  locale_t original = uselocale(NULL);
-  EXPECT_FALSE(original == 0);
+  locale_t original = uselocale(nullptr);
+  EXPECT_FALSE(original == nullptr);
   EXPECT_EQ(LC_GLOBAL_LOCALE, original);
 
-  locale_t n = newlocale(LC_ALL, "C", 0);
-  EXPECT_FALSE(n == 0);
+  locale_t n = newlocale(LC_ALL, "C", nullptr);
+  EXPECT_FALSE(n == nullptr);
   EXPECT_FALSE(n == original);
 
   locale_t old = uselocale(n);
   EXPECT_TRUE(old == original);
 
-  EXPECT_EQ(n, uselocale(NULL));
+  EXPECT_EQ(n, uselocale(nullptr));
 }
 
 TEST(locale, mb_cur_max) {
@@ -122,8 +122,8 @@
   // initial program conditions because (unless we're the only test that was
   // run), another test has almost certainly called uselocale(3) in this thread.
   // See b/16685652.
-  locale_t cloc = newlocale(LC_ALL, "C", 0);
-  locale_t cloc_utf8 = newlocale(LC_ALL, "C.UTF-8", 0);
+  locale_t cloc = newlocale(LC_ALL, "C", nullptr);
+  locale_t cloc_utf8 = newlocale(LC_ALL, "C.UTF-8", nullptr);
 
   locale_t old_locale = uselocale(cloc);
   ASSERT_EQ(1U, MB_CUR_MAX);
diff --git a/tests/malloc_test.cpp b/tests/malloc_test.cpp
index ddd78b0..4161c90 100644
--- a/tests/malloc_test.cpp
+++ b/tests/malloc_test.cpp
@@ -29,14 +29,14 @@
 TEST(malloc, malloc_std) {
   // Simple malloc test.
   void *ptr = malloc(100);
-  ASSERT_TRUE(ptr != NULL);
+  ASSERT_TRUE(ptr != nullptr);
   ASSERT_LE(100U, malloc_usable_size(ptr));
   free(ptr);
 }
 
 TEST(malloc, malloc_overflow) {
   errno = 0;
-  ASSERT_EQ(NULL, malloc(SIZE_MAX));
+  ASSERT_EQ(nullptr, malloc(SIZE_MAX));
   ASSERT_EQ(ENOMEM, errno);
 }
 
@@ -44,7 +44,7 @@
   // Simple calloc test.
   size_t alloc_len = 100;
   char *ptr = (char *)calloc(1, alloc_len);
-  ASSERT_TRUE(ptr != NULL);
+  ASSERT_TRUE(ptr != nullptr);
   ASSERT_LE(alloc_len, malloc_usable_size(ptr));
   for (size_t i = 0; i < alloc_len; i++) {
     ASSERT_EQ(0, ptr[i]);
@@ -54,22 +54,22 @@
 
 TEST(malloc, calloc_illegal) {
   errno = 0;
-  ASSERT_EQ(NULL, calloc(-1, 100));
+  ASSERT_EQ(nullptr, calloc(-1, 100));
   ASSERT_EQ(ENOMEM, errno);
 }
 
 TEST(malloc, calloc_overflow) {
   errno = 0;
-  ASSERT_EQ(NULL, calloc(1, SIZE_MAX));
+  ASSERT_EQ(nullptr, calloc(1, SIZE_MAX));
   ASSERT_EQ(ENOMEM, errno);
   errno = 0;
-  ASSERT_EQ(NULL, calloc(SIZE_MAX, SIZE_MAX));
+  ASSERT_EQ(nullptr, calloc(SIZE_MAX, SIZE_MAX));
   ASSERT_EQ(ENOMEM, errno);
   errno = 0;
-  ASSERT_EQ(NULL, calloc(2, SIZE_MAX));
+  ASSERT_EQ(nullptr, calloc(2, SIZE_MAX));
   ASSERT_EQ(ENOMEM, errno);
   errno = 0;
-  ASSERT_EQ(NULL, calloc(SIZE_MAX, 2));
+  ASSERT_EQ(nullptr, calloc(SIZE_MAX, 2));
   ASSERT_EQ(ENOMEM, errno);
 }
 
@@ -78,7 +78,7 @@
   for (size_t i = 0; i <= 12; i++) {
     for (size_t alignment = 1 << i; alignment < (1U << (i+1)); alignment++) {
       char *ptr = reinterpret_cast<char*>(memalign(alignment, 100));
-      ASSERT_TRUE(ptr != NULL) << "Failed at alignment " << alignment;
+      ASSERT_TRUE(ptr != nullptr) << "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;
@@ -88,14 +88,14 @@
 }
 
 TEST(malloc, memalign_overflow) {
-  ASSERT_EQ(NULL, memalign(4096, SIZE_MAX));
+  ASSERT_EQ(nullptr, 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;
+    ASSERT_TRUE(ptr != nullptr) << "Failed at align " << align;
     free(ptr);
   }
 }
@@ -104,22 +104,22 @@
   // Memalign and then realloc the pointer a couple of times.
   for (size_t alignment = 1; alignment <= 4096; alignment <<= 1) {
     char *ptr = (char*)memalign(alignment, 100);
-    ASSERT_TRUE(ptr != NULL);
+    ASSERT_TRUE(ptr != nullptr);
     ASSERT_LE(100U, malloc_usable_size(ptr));
     ASSERT_EQ(0U, (intptr_t)ptr % alignment);
     memset(ptr, 0x23, 100);
 
     ptr = (char*)realloc(ptr, 200);
-    ASSERT_TRUE(ptr != NULL);
+    ASSERT_TRUE(ptr != nullptr);
     ASSERT_LE(200U, malloc_usable_size(ptr));
-    ASSERT_TRUE(ptr != NULL);
+    ASSERT_TRUE(ptr != nullptr);
     for (size_t i = 0; i < 100; i++) {
       ASSERT_EQ(0x23, ptr[i]);
     }
     memset(ptr, 0x45, 200);
 
     ptr = (char*)realloc(ptr, 300);
-    ASSERT_TRUE(ptr != NULL);
+    ASSERT_TRUE(ptr != nullptr);
     ASSERT_LE(300U, malloc_usable_size(ptr));
     for (size_t i = 0; i < 200; i++) {
       ASSERT_EQ(0x45, ptr[i]);
@@ -127,7 +127,7 @@
     memset(ptr, 0x67, 300);
 
     ptr = (char*)realloc(ptr, 250);
-    ASSERT_TRUE(ptr != NULL);
+    ASSERT_TRUE(ptr != nullptr);
     ASSERT_LE(250U, malloc_usable_size(ptr));
     for (size_t i = 0; i < 250; i++) {
       ASSERT_EQ(0x67, ptr[i]);
@@ -139,12 +139,12 @@
 TEST(malloc, malloc_realloc_larger) {
   // Realloc to a larger size, malloc is used for the original allocation.
   char *ptr = (char *)malloc(100);
-  ASSERT_TRUE(ptr != NULL);
+  ASSERT_TRUE(ptr != nullptr);
   ASSERT_LE(100U, malloc_usable_size(ptr));
   memset(ptr, 67, 100);
 
   ptr = (char *)realloc(ptr, 200);
-  ASSERT_TRUE(ptr != NULL);
+  ASSERT_TRUE(ptr != nullptr);
   ASSERT_LE(200U, malloc_usable_size(ptr));
   for (size_t i = 0; i < 100; i++) {
     ASSERT_EQ(67, ptr[i]);
@@ -155,12 +155,12 @@
 TEST(malloc, malloc_realloc_smaller) {
   // Realloc to a smaller size, malloc is used for the original allocation.
   char *ptr = (char *)malloc(200);
-  ASSERT_TRUE(ptr != NULL);
+  ASSERT_TRUE(ptr != nullptr);
   ASSERT_LE(200U, malloc_usable_size(ptr));
   memset(ptr, 67, 200);
 
   ptr = (char *)realloc(ptr, 100);
-  ASSERT_TRUE(ptr != NULL);
+  ASSERT_TRUE(ptr != nullptr);
   ASSERT_LE(100U, malloc_usable_size(ptr));
   for (size_t i = 0; i < 100; i++) {
     ASSERT_EQ(67, ptr[i]);
@@ -171,26 +171,26 @@
 TEST(malloc, malloc_multiple_realloc) {
   // Multiple reallocs, malloc is used for the original allocation.
   char *ptr = (char *)malloc(200);
-  ASSERT_TRUE(ptr != NULL);
+  ASSERT_TRUE(ptr != nullptr);
   ASSERT_LE(200U, malloc_usable_size(ptr));
   memset(ptr, 0x23, 200);
 
   ptr = (char *)realloc(ptr, 100);
-  ASSERT_TRUE(ptr != NULL);
+  ASSERT_TRUE(ptr != nullptr);
   ASSERT_LE(100U, malloc_usable_size(ptr));
   for (size_t i = 0; i < 100; i++) {
     ASSERT_EQ(0x23, ptr[i]);
   }
 
   ptr = (char*)realloc(ptr, 50);
-  ASSERT_TRUE(ptr != NULL);
+  ASSERT_TRUE(ptr != nullptr);
   ASSERT_LE(50U, malloc_usable_size(ptr));
   for (size_t i = 0; i < 50; i++) {
     ASSERT_EQ(0x23, ptr[i]);
   }
 
   ptr = (char*)realloc(ptr, 150);
-  ASSERT_TRUE(ptr != NULL);
+  ASSERT_TRUE(ptr != nullptr);
   ASSERT_LE(150U, malloc_usable_size(ptr));
   for (size_t i = 0; i < 50; i++) {
     ASSERT_EQ(0x23, ptr[i]);
@@ -198,7 +198,7 @@
   memset(ptr, 0x23, 150);
 
   ptr = (char*)realloc(ptr, 425);
-  ASSERT_TRUE(ptr != NULL);
+  ASSERT_TRUE(ptr != nullptr);
   ASSERT_LE(425U, malloc_usable_size(ptr));
   for (size_t i = 0; i < 150; i++) {
     ASSERT_EQ(0x23, ptr[i]);
@@ -209,11 +209,11 @@
 TEST(malloc, calloc_realloc_larger) {
   // Realloc to a larger size, calloc is used for the original allocation.
   char *ptr = (char *)calloc(1, 100);
-  ASSERT_TRUE(ptr != NULL);
+  ASSERT_TRUE(ptr != nullptr);
   ASSERT_LE(100U, malloc_usable_size(ptr));
 
   ptr = (char *)realloc(ptr, 200);
-  ASSERT_TRUE(ptr != NULL);
+  ASSERT_TRUE(ptr != nullptr);
   ASSERT_LE(200U, malloc_usable_size(ptr));
   for (size_t i = 0; i < 100; i++) {
     ASSERT_EQ(0, ptr[i]);
@@ -224,11 +224,11 @@
 TEST(malloc, calloc_realloc_smaller) {
   // Realloc to a smaller size, calloc is used for the original allocation.
   char *ptr = (char *)calloc(1, 200);
-  ASSERT_TRUE(ptr != NULL);
+  ASSERT_TRUE(ptr != nullptr);
   ASSERT_LE(200U, malloc_usable_size(ptr));
 
   ptr = (char *)realloc(ptr, 100);
-  ASSERT_TRUE(ptr != NULL);
+  ASSERT_TRUE(ptr != nullptr);
   ASSERT_LE(100U, malloc_usable_size(ptr));
   for (size_t i = 0; i < 100; i++) {
     ASSERT_EQ(0, ptr[i]);
@@ -239,25 +239,25 @@
 TEST(malloc, calloc_multiple_realloc) {
   // Multiple reallocs, calloc is used for the original allocation.
   char *ptr = (char *)calloc(1, 200);
-  ASSERT_TRUE(ptr != NULL);
+  ASSERT_TRUE(ptr != nullptr);
   ASSERT_LE(200U, malloc_usable_size(ptr));
 
   ptr = (char *)realloc(ptr, 100);
-  ASSERT_TRUE(ptr != NULL);
+  ASSERT_TRUE(ptr != nullptr);
   ASSERT_LE(100U, malloc_usable_size(ptr));
   for (size_t i = 0; i < 100; i++) {
     ASSERT_EQ(0, ptr[i]);
   }
 
   ptr = (char*)realloc(ptr, 50);
-  ASSERT_TRUE(ptr != NULL);
+  ASSERT_TRUE(ptr != nullptr);
   ASSERT_LE(50U, malloc_usable_size(ptr));
   for (size_t i = 0; i < 50; i++) {
     ASSERT_EQ(0, ptr[i]);
   }
 
   ptr = (char*)realloc(ptr, 150);
-  ASSERT_TRUE(ptr != NULL);
+  ASSERT_TRUE(ptr != nullptr);
   ASSERT_LE(150U, malloc_usable_size(ptr));
   for (size_t i = 0; i < 50; i++) {
     ASSERT_EQ(0, ptr[i]);
@@ -265,7 +265,7 @@
   memset(ptr, 0, 150);
 
   ptr = (char*)realloc(ptr, 425);
-  ASSERT_TRUE(ptr != NULL);
+  ASSERT_TRUE(ptr != nullptr);
   ASSERT_LE(425U, malloc_usable_size(ptr));
   for (size_t i = 0; i < 150; i++) {
     ASSERT_EQ(0, ptr[i]);
@@ -275,12 +275,12 @@
 
 TEST(malloc, realloc_overflow) {
   errno = 0;
-  ASSERT_EQ(NULL, realloc(NULL, SIZE_MAX));
+  ASSERT_EQ(nullptr, realloc(nullptr, SIZE_MAX));
   ASSERT_EQ(ENOMEM, errno);
   void* ptr = malloc(100);
-  ASSERT_TRUE(ptr != NULL);
+  ASSERT_TRUE(ptr != nullptr);
   errno = 0;
-  ASSERT_EQ(NULL, realloc(ptr, SIZE_MAX));
+  ASSERT_EQ(nullptr, realloc(ptr, SIZE_MAX));
   ASSERT_EQ(ENOMEM, errno);
   free(ptr);
 }
@@ -292,26 +292,26 @@
 TEST(malloc, pvalloc_std) {
   size_t pagesize = sysconf(_SC_PAGESIZE);
   void* ptr = pvalloc(100);
-  ASSERT_TRUE(ptr != NULL);
+  ASSERT_TRUE(ptr != nullptr);
   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));
+  ASSERT_EQ(nullptr, pvalloc(SIZE_MAX));
 }
 
 TEST(malloc, valloc_std) {
   size_t pagesize = sysconf(_SC_PAGESIZE);
   void* ptr = pvalloc(100);
-  ASSERT_TRUE(ptr != NULL);
+  ASSERT_TRUE(ptr != nullptr);
   ASSERT_TRUE((reinterpret_cast<uintptr_t>(ptr) & (pagesize-1)) == 0);
   free(ptr);
 }
 
 TEST(malloc, valloc_overflow) {
-  ASSERT_EQ(NULL, valloc(SIZE_MAX));
+  ASSERT_EQ(nullptr, valloc(SIZE_MAX));
 }
 #endif
 
diff --git a/tests/mntent_test.cpp b/tests/mntent_test.cpp
index 3fb2f86..b86af9f 100644
--- a/tests/mntent_test.cpp
+++ b/tests/mntent_test.cpp
@@ -20,15 +20,15 @@
 
 TEST(mntent, mntent_smoke) {
   FILE* fp = setmntent("/proc/mounts", "r");
-  ASSERT_TRUE(fp != NULL);
+  ASSERT_TRUE(fp != nullptr);
 
-  ASSERT_TRUE(getmntent(fp) != NULL);
+  ASSERT_TRUE(getmntent(fp) != nullptr);
 
   bool saw_proc = false;
 
   struct mntent entry;
   char buf[BUFSIZ];
-  while (getmntent_r(fp, &entry, buf, sizeof(buf)) != NULL) {
+  while (getmntent_r(fp, &entry, buf, sizeof(buf)) != nullptr) {
     if (strcmp(entry.mnt_fsname, "proc") == 0 && strcmp(entry.mnt_dir, "/proc") == 0) {
       saw_proc = true;
     }
diff --git a/tests/netdb_test.cpp b/tests/netdb_test.cpp
index a624138..a805693 100644
--- a/tests/netdb_test.cpp
+++ b/tests/netdb_test.cpp
@@ -26,13 +26,13 @@
 
 // https://code.google.com/p/android/issues/detail?id=13228
 TEST(netdb, freeaddrinfo_NULL) {
-  freeaddrinfo(NULL);
+  freeaddrinfo(nullptr);
 }
 
 TEST(netdb, getaddrinfo_NULL_host) {
   // It's okay for the host argument to be NULL, as long as service isn't.
-  addrinfo* ai = NULL;
-  ASSERT_EQ(0, getaddrinfo(NULL, "smtp", NULL, &ai));
+  addrinfo* ai = nullptr;
+  ASSERT_EQ(0, getaddrinfo(nullptr, "smtp", nullptr, &ai));
   // (sockaddr_in::sin_port and sockaddr_in6::sin6_port overlap.)
   ASSERT_EQ(25U, ntohs(reinterpret_cast<sockaddr_in*>(ai->ai_addr)->sin_port));
   freeaddrinfo(ai);
@@ -40,19 +40,19 @@
 
 TEST(netdb, getaddrinfo_NULL_service) {
   // It's okay for the service argument to be NULL, as long as host isn't.
-  addrinfo* ai = NULL;
-  ASSERT_EQ(0, getaddrinfo("localhost", NULL, NULL, &ai));
-  ASSERT_TRUE(ai != NULL);
+  addrinfo* ai = nullptr;
+  ASSERT_EQ(0, getaddrinfo("localhost", nullptr, nullptr, &ai));
+  ASSERT_TRUE(ai != nullptr);
   freeaddrinfo(ai);
 }
 
 TEST(netdb, getaddrinfo_NULL_hints) {
-  addrinfo* ai = NULL;
-  ASSERT_EQ(0, getaddrinfo("localhost", "9999", NULL, &ai));
+  addrinfo* ai = nullptr;
+  ASSERT_EQ(0, getaddrinfo("localhost", "9999", nullptr, &ai));
 
   bool saw_tcp = false;
   bool saw_udp = false;
-  for (addrinfo* p = ai; p != NULL; p = p->ai_next) {
+  for (addrinfo* p = ai; p != nullptr; p = p->ai_next) {
     ASSERT_TRUE(p->ai_family == AF_INET || p->ai_family == AF_INET6);
     if (p->ai_socktype == SOCK_STREAM) {
       ASSERT_EQ(IPPROTO_TCP, p->ai_protocol);
@@ -69,8 +69,8 @@
 }
 
 TEST(netdb, getaddrinfo_service_lookup) {
-  addrinfo* ai = NULL;
-  ASSERT_EQ(0, getaddrinfo("localhost", "smtp", NULL, &ai));
+  addrinfo* ai = nullptr;
+  ASSERT_EQ(0, getaddrinfo("localhost", "smtp", nullptr, &ai));
   ASSERT_EQ(SOCK_STREAM, ai->ai_socktype);
   ASSERT_EQ(IPPROTO_TCP, ai->ai_protocol);
   ASSERT_EQ(25, ntohs(reinterpret_cast<sockaddr_in*>(ai->ai_addr)->sin_port));
@@ -84,13 +84,13 @@
   hints.ai_socktype = SOCK_STREAM;
   hints.ai_protocol = IPPROTO_TCP;
 
-  addrinfo* ai = NULL;
+  addrinfo* ai = nullptr;
   ASSERT_EQ(0, getaddrinfo( "localhost", "9999", &hints, &ai));
-  ASSERT_TRUE(ai != NULL);
+  ASSERT_TRUE(ai != nullptr);
   // In glibc, getaddrinfo() converts ::1 to 127.0.0.1 for localhost,
   // so one or two addrinfo may be returned.
   addrinfo* tai = ai;
-  while (tai != NULL) {
+  while (tai != nullptr) {
     ASSERT_EQ(AF_INET, tai->ai_family);
     ASSERT_EQ(SOCK_STREAM, tai->ai_socktype);
     ASSERT_EQ(IPPROTO_TCP, tai->ai_protocol);
@@ -100,11 +100,11 @@
 }
 
 TEST(netdb, getaddrinfo_ip6_localhost) {
-  addrinfo* ai = NULL;
-  ASSERT_EQ(0, getaddrinfo("ip6-localhost", NULL, NULL, &ai));
-  ASSERT_TRUE(ai != NULL);
+  addrinfo* ai = nullptr;
+  ASSERT_EQ(0, getaddrinfo("ip6-localhost", nullptr, nullptr, &ai));
+  ASSERT_TRUE(ai != nullptr);
   ASSERT_GE(ai->ai_addrlen, static_cast<socklen_t>(sizeof(sockaddr_in6)));
-  ASSERT_TRUE(ai->ai_addr != NULL);
+  ASSERT_TRUE(ai->ai_addr != nullptr);
   sockaddr_in6 *addr = reinterpret_cast<sockaddr_in6*>(ai->ai_addr);
   ASSERT_EQ(addr->sin6_family, AF_INET6);
   ASSERT_EQ(0, memcmp(&addr->sin6_addr, &in6addr_loopback, sizeof(in6_addr)));
@@ -122,22 +122,22 @@
   socklen_t just_right = sizeof(sockaddr_in);
   socklen_t too_little = sizeof(sockaddr_in) - 1;
 
-  ASSERT_EQ(0, getnameinfo(sa, too_much, tmp, sizeof(tmp), NULL, 0, NI_NUMERICHOST));
+  ASSERT_EQ(0, getnameinfo(sa, too_much, tmp, sizeof(tmp), nullptr, 0, NI_NUMERICHOST));
   ASSERT_STREQ("0.0.0.0", tmp);
-  ASSERT_EQ(0, getnameinfo(sa, just_right, tmp, sizeof(tmp), NULL, 0, NI_NUMERICHOST));
+  ASSERT_EQ(0, getnameinfo(sa, just_right, tmp, sizeof(tmp), nullptr, 0, NI_NUMERICHOST));
   ASSERT_STREQ("0.0.0.0", tmp);
-  ASSERT_EQ(EAI_FAMILY, getnameinfo(sa, too_little, tmp, sizeof(tmp), NULL, 0, NI_NUMERICHOST));
+  ASSERT_EQ(EAI_FAMILY, getnameinfo(sa, too_little, tmp, sizeof(tmp), nullptr, 0, NI_NUMERICHOST));
 
   ss.ss_family = AF_INET6;
   just_right = sizeof(sockaddr_in6);
   too_little = sizeof(sockaddr_in6) - 1;
   too_much = just_right + 1;
 
-  ASSERT_EQ(0, getnameinfo(sa, too_much, tmp, sizeof(tmp), NULL, 0, NI_NUMERICHOST));
+  ASSERT_EQ(0, getnameinfo(sa, too_much, tmp, sizeof(tmp), nullptr, 0, NI_NUMERICHOST));
   ASSERT_STREQ("::", tmp);
-  ASSERT_EQ(0, getnameinfo(sa, just_right, tmp, sizeof(tmp), NULL, 0, NI_NUMERICHOST));
+  ASSERT_EQ(0, getnameinfo(sa, just_right, tmp, sizeof(tmp), nullptr, 0, NI_NUMERICHOST));
   ASSERT_STREQ("::", tmp);
-  ASSERT_EQ(EAI_FAMILY, getnameinfo(sa, too_little, tmp, sizeof(tmp), NULL, 0, NI_NUMERICHOST));
+  ASSERT_EQ(EAI_FAMILY, getnameinfo(sa, too_little, tmp, sizeof(tmp), nullptr, 0, NI_NUMERICHOST));
 }
 
 TEST(netdb, getnameinfo_localhost) {
@@ -147,7 +147,7 @@
   addr.sin_family = AF_INET;
   addr.sin_addr.s_addr = htonl(0x7f000001);
   ASSERT_EQ(0, getnameinfo(reinterpret_cast<sockaddr*>(&addr), sizeof(addr),
-                           host, sizeof(host), NULL, 0, 0));
+                           host, sizeof(host), nullptr, 0, 0));
   ASSERT_STREQ(host, "localhost");
 }
 
@@ -165,14 +165,14 @@
   addr.sin6_family = AF_INET6;
   addr.sin6_addr = in6addr_loopback;
   ASSERT_EQ(0, getnameinfo(reinterpret_cast<sockaddr*>(&addr), sizeof(addr),
-                           host, sizeof(host), NULL, 0, 0));
+                           host, sizeof(host), nullptr, 0, 0));
   VerifyLocalhostName(host);
 }
 
 static void VerifyLocalhost(hostent *hent) {
-  ASSERT_TRUE(hent != NULL);
+  ASSERT_TRUE(hent != nullptr);
   VerifyLocalhostName(hent->h_name);
-  for (size_t i = 0; hent->h_aliases[i] != NULL; ++i) {
+  for (size_t i = 0; hent->h_aliases[i] != nullptr; ++i) {
     VerifyLocalhostName(hent->h_aliases[i]);
   }
   ASSERT_EQ(hent->h_addrtype, AF_INET);
@@ -273,7 +273,7 @@
   int result = gethostbyname_r("localhost", &hent, buf, sizeof(buf), &hp, &err);
   EXPECT_EQ(NETDB_INTERNAL, err);
   EXPECT_EQ(ERANGE, result);
-  EXPECT_EQ(NULL, hp);
+  EXPECT_EQ(nullptr, hp);
 }
 
 TEST(netdb, gethostbyname2_r_ERANGE) {
@@ -284,7 +284,7 @@
   int result = gethostbyname2_r("localhost", AF_INET, &hent, buf, sizeof(buf), &hp, &err);
   EXPECT_EQ(NETDB_INTERNAL, err);
   EXPECT_EQ(ERANGE, result);
-  EXPECT_EQ(NULL, hp);
+  EXPECT_EQ(nullptr, hp);
 }
 
 TEST(netdb, gethostbyaddr_r_ERANGE) {
@@ -296,7 +296,7 @@
   int result = gethostbyaddr_r(&addr, sizeof(addr), AF_INET, &hent, buf, sizeof(buf), &hp, &err);
   EXPECT_EQ(NETDB_INTERNAL, err);
   EXPECT_EQ(ERANGE, result);
-  EXPECT_EQ(NULL, hp);
+  EXPECT_EQ(nullptr, hp);
 }
 
 TEST(netdb, gethostbyname_r_HOST_NOT_FOUND) {
@@ -307,7 +307,7 @@
   int result = gethostbyname_r("does.not.exist.google.com", &hent, buf, sizeof(buf), &hp, &err);
   EXPECT_EQ(HOST_NOT_FOUND, err);
   EXPECT_EQ(0, result);
-  EXPECT_EQ(NULL, hp);
+  EXPECT_EQ(nullptr, hp);
 }
 
 TEST(netdb, gethostbyname2_r_HOST_NOT_FOUND) {
@@ -318,7 +318,7 @@
   int result = gethostbyname2_r("does.not.exist.google.com", AF_INET, &hent, buf, sizeof(buf), &hp, &err);
   EXPECT_EQ(HOST_NOT_FOUND, err);
   EXPECT_EQ(0, result);
-  EXPECT_EQ(NULL, hp);
+  EXPECT_EQ(nullptr, hp);
 }
 
 TEST(netdb, gethostbyaddr_r_HOST_NOT_FOUND) {
@@ -330,7 +330,7 @@
   int result = gethostbyaddr_r(&addr, sizeof(addr), AF_INET, &hent, buf, sizeof(buf), &hp, &err);
   EXPECT_EQ(HOST_NOT_FOUND, err);
   EXPECT_EQ(0, result);
-  EXPECT_EQ(NULL, hp);
+  EXPECT_EQ(nullptr, hp);
 }
 
 TEST(netdb, getservbyname) {
diff --git a/tests/pthread_test.cpp b/tests/pthread_test.cpp
index f2f6e01..fc8945c 100644
--- a/tests/pthread_test.cpp
+++ b/tests/pthread_test.cpp
@@ -45,7 +45,7 @@
 
 TEST(pthread, pthread_key_create) {
   pthread_key_t key;
-  ASSERT_EQ(0, pthread_key_create(&key, NULL));
+  ASSERT_EQ(0, pthread_key_create(&key, nullptr));
   ASSERT_EQ(0, pthread_key_delete(key));
   // Can't delete a key that's already been deleted.
   ASSERT_EQ(EINVAL, pthread_key_delete(key));
@@ -76,7 +76,7 @@
   for (int i = 0; i < nkeys; ++i) {
     pthread_key_t key;
     // If this fails, it's likely that LIBC_PTHREAD_KEY_RESERVED_COUNT is wrong.
-    ASSERT_EQ(0, pthread_key_create(&key, NULL)) << i << " of " << nkeys;
+    ASSERT_EQ(0, pthread_key_create(&key, nullptr)) << i << " of " << nkeys;
     keys.push_back(key);
     ASSERT_EQ(0, pthread_setspecific(key, reinterpret_cast<void*>(i)));
   }
@@ -97,7 +97,7 @@
   // be more than we are allowed to allocate now.
   for (int i = 0; i < PTHREAD_KEYS_MAX; i++) {
     pthread_key_t key;
-    rv = pthread_key_create(&key, NULL);
+    rv = pthread_key_create(&key, nullptr);
     if (rv == EAGAIN) {
       break;
     }
@@ -119,12 +119,12 @@
 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_key_create(&key, nullptr));
   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));
+  // After deletion, pthread_getspecific returns nullptr.
+  ASSERT_EQ(nullptr, pthread_getspecific(key));
   // And you can't use pthread_setspecific with the deleted key.
   ASSERT_EQ(EINVAL, pthread_setspecific(key, expected));
 }
@@ -132,7 +132,7 @@
 TEST(pthread, pthread_key_fork) {
   void* expected = reinterpret_cast<void*>(1234);
   pthread_key_t key;
-  ASSERT_EQ(0, pthread_key_create(&key, NULL));
+  ASSERT_EQ(0, pthread_key_create(&key, nullptr));
   ASSERT_EQ(0, pthread_setspecific(key, expected));
   ASSERT_EQ(expected, pthread_getspecific(key));
 
@@ -157,10 +157,10 @@
 
 TEST(pthread, pthread_key_dirty) {
   pthread_key_t key;
-  ASSERT_EQ(0, pthread_key_create(&key, NULL));
+  ASSERT_EQ(0, pthread_key_create(&key, nullptr));
 
   size_t stack_size = 640 * 1024;
-  void* stack = mmap(NULL, stack_size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
+  void* stack = mmap(nullptr, stack_size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
   ASSERT_NE(MAP_FAILED, stack);
   memset(stack, 0xff, stack_size);
 
@@ -217,7 +217,7 @@
  private:
   static void* SpinFn(void*) {
     while (spin_flag_) {}
-    return NULL;
+    return nullptr;
   }
   static std::atomic<bool> spin_flag_;
 };
@@ -228,7 +228,7 @@
 std::atomic<bool> SpinFunctionHelper::spin_flag_;
 
 static void* JoinFn(void* arg) {
-  return reinterpret_cast<void*>(pthread_join(reinterpret_cast<pthread_t>(arg), NULL));
+  return reinterpret_cast<void*>(pthread_join(reinterpret_cast<pthread_t>(arg), nullptr));
 }
 
 static void AssertDetached(pthread_t t, bool is_detached) {
@@ -241,15 +241,15 @@
 }
 
 static void MakeDeadThread(pthread_t& t) {
-  ASSERT_EQ(0, pthread_create(&t, NULL, IdFn, NULL));
-  ASSERT_EQ(0, pthread_join(t, NULL));
+  ASSERT_EQ(0, pthread_create(&t, nullptr, IdFn, nullptr));
+  ASSERT_EQ(0, pthread_join(t, nullptr));
 }
 
 TEST(pthread, pthread_create) {
   void* expected_result = reinterpret_cast<void*>(123);
   // Can we create a thread?
   pthread_t t;
-  ASSERT_EQ(0, pthread_create(&t, NULL, IdFn, expected_result));
+  ASSERT_EQ(0, pthread_create(&t, nullptr, IdFn, expected_result));
   // If we join, do we get the expected value back?
   void* result;
   ASSERT_EQ(0, pthread_join(t, &result));
@@ -262,32 +262,32 @@
   ASSERT_EQ(0, pthread_attr_setstacksize(&attributes, static_cast<size_t>(-1) & ~(getpagesize() - 1)));
 
   pthread_t t;
-  ASSERT_EQ(EAGAIN, pthread_create(&t, &attributes, IdFn, NULL));
+  ASSERT_EQ(EAGAIN, pthread_create(&t, &attributes, IdFn, nullptr));
 }
 
 TEST(pthread, pthread_no_join_after_detach) {
   SpinFunctionHelper spin_helper;
 
   pthread_t t1;
-  ASSERT_EQ(0, pthread_create(&t1, NULL, spin_helper.GetFunction(), NULL));
+  ASSERT_EQ(0, pthread_create(&t1, nullptr, spin_helper.GetFunction(), nullptr));
 
   // After a pthread_detach...
   ASSERT_EQ(0, pthread_detach(t1));
   AssertDetached(t1, true);
 
   // ...pthread_join should fail.
-  ASSERT_EQ(EINVAL, pthread_join(t1, NULL));
+  ASSERT_EQ(EINVAL, pthread_join(t1, nullptr));
 }
 
 TEST(pthread, pthread_no_op_detach_after_join) {
   SpinFunctionHelper spin_helper;
 
   pthread_t t1;
-  ASSERT_EQ(0, pthread_create(&t1, NULL, spin_helper.GetFunction(), NULL));
+  ASSERT_EQ(0, pthread_create(&t1, nullptr, spin_helper.GetFunction(), nullptr));
 
   // If thread 2 is already waiting to join thread 1...
   pthread_t t2;
-  ASSERT_EQ(0, pthread_create(&t2, NULL, JoinFn, reinterpret_cast<void*>(t1)));
+  ASSERT_EQ(0, pthread_create(&t2, nullptr, JoinFn, reinterpret_cast<void*>(t1)));
 
   sleep(1); // (Give t2 a chance to call pthread_join.)
 
@@ -307,7 +307,7 @@
 }
 
 TEST(pthread, pthread_join_self) {
-  ASSERT_EQ(EDEADLK, pthread_join(pthread_self(), NULL));
+  ASSERT_EQ(EDEADLK, pthread_join(pthread_self(), nullptr));
 }
 
 struct TestBug37410 {
@@ -317,18 +317,18 @@
   static void main() {
     TestBug37410 data;
     data.main_thread = pthread_self();
-    ASSERT_EQ(0, pthread_mutex_init(&data.mutex, NULL));
+    ASSERT_EQ(0, pthread_mutex_init(&data.mutex, nullptr));
     ASSERT_EQ(0, pthread_mutex_lock(&data.mutex));
 
     pthread_t t;
-    ASSERT_EQ(0, pthread_create(&t, NULL, TestBug37410::thread_fn, reinterpret_cast<void*>(&data)));
+    ASSERT_EQ(0, pthread_create(&t, nullptr, TestBug37410::thread_fn, reinterpret_cast<void*>(&data)));
 
     // Wait for the thread to be running...
     ASSERT_EQ(0, pthread_mutex_lock(&data.mutex));
     ASSERT_EQ(0, pthread_mutex_unlock(&data.mutex));
 
     // ...and exit.
-    pthread_exit(NULL);
+    pthread_exit(nullptr);
   }
 
  private:
@@ -339,9 +339,9 @@
     pthread_mutex_unlock(&data->mutex);
 
     // And wait for the main thread to exit.
-    pthread_join(data->main_thread, NULL);
+    pthread_join(data->main_thread, nullptr);
 
-    return NULL;
+    return nullptr;
   }
 };
 
@@ -365,29 +365,29 @@
   // Check that SIGUSR1 isn't blocked.
   sigset_t original_set;
   sigemptyset(&original_set);
-  ASSERT_EQ(0, pthread_sigmask(SIG_BLOCK, NULL, &original_set));
+  ASSERT_EQ(0, pthread_sigmask(SIG_BLOCK, nullptr, &original_set));
   ASSERT_FALSE(sigismember(&original_set, SIGUSR1));
 
   // Block SIGUSR1.
   sigset_t set;
   sigemptyset(&set);
   sigaddset(&set, SIGUSR1);
-  ASSERT_EQ(0, pthread_sigmask(SIG_BLOCK, &set, NULL));
+  ASSERT_EQ(0, pthread_sigmask(SIG_BLOCK, &set, nullptr));
 
   // Check that SIGUSR1 is blocked.
   sigset_t final_set;
   sigemptyset(&final_set);
-  ASSERT_EQ(0, pthread_sigmask(SIG_BLOCK, NULL, &final_set));
+  ASSERT_EQ(0, pthread_sigmask(SIG_BLOCK, nullptr, &final_set));
   ASSERT_TRUE(sigismember(&final_set, SIGUSR1));
   // ...and that sigprocmask agrees with pthread_sigmask.
   sigemptyset(&final_set);
-  ASSERT_EQ(0, sigprocmask(SIG_BLOCK, NULL, &final_set));
+  ASSERT_EQ(0, sigprocmask(SIG_BLOCK, nullptr, &final_set));
   ASSERT_TRUE(sigismember(&final_set, SIGUSR1));
 
   // Spawn a thread that calls sigwait and tells us what it received.
   pthread_t signal_thread;
   int received_signal = -1;
-  ASSERT_EQ(0, pthread_create(&signal_thread, NULL, SignalHandlerFn, &received_signal));
+  ASSERT_EQ(0, pthread_create(&signal_thread, nullptr, SignalHandlerFn, &received_signal));
 
   // Send that thread SIGUSR1.
   pthread_kill(signal_thread, SIGUSR1);
@@ -399,36 +399,36 @@
   ASSERT_EQ(0U, reinterpret_cast<uintptr_t>(join_result));
 
   // Restore the original signal mask.
-  ASSERT_EQ(0, pthread_sigmask(SIG_SETMASK, &original_set, NULL));
+  ASSERT_EQ(0, pthread_sigmask(SIG_SETMASK, &original_set, nullptr));
 }
 
 TEST(pthread, pthread_sigmask64_SIGTRMIN) {
   // Check that SIGRTMIN isn't blocked.
   sigset64_t original_set;
   sigemptyset64(&original_set);
-  ASSERT_EQ(0, pthread_sigmask64(SIG_BLOCK, NULL, &original_set));
+  ASSERT_EQ(0, pthread_sigmask64(SIG_BLOCK, nullptr, &original_set));
   ASSERT_FALSE(sigismember64(&original_set, SIGRTMIN));
 
   // Block SIGRTMIN.
   sigset64_t set;
   sigemptyset64(&set);
   sigaddset64(&set, SIGRTMIN);
-  ASSERT_EQ(0, pthread_sigmask64(SIG_BLOCK, &set, NULL));
+  ASSERT_EQ(0, pthread_sigmask64(SIG_BLOCK, &set, nullptr));
 
   // Check that SIGRTMIN is blocked.
   sigset64_t final_set;
   sigemptyset64(&final_set);
-  ASSERT_EQ(0, pthread_sigmask64(SIG_BLOCK, NULL, &final_set));
+  ASSERT_EQ(0, pthread_sigmask64(SIG_BLOCK, nullptr, &final_set));
   ASSERT_TRUE(sigismember64(&final_set, SIGRTMIN));
   // ...and that sigprocmask64 agrees with pthread_sigmask64.
   sigemptyset64(&final_set);
-  ASSERT_EQ(0, sigprocmask64(SIG_BLOCK, NULL, &final_set));
+  ASSERT_EQ(0, sigprocmask64(SIG_BLOCK, nullptr, &final_set));
   ASSERT_TRUE(sigismember64(&final_set, SIGRTMIN));
 
   // Spawn a thread that calls sigwait64 and tells us what it received.
   pthread_t signal_thread;
   int received_signal = -1;
-  ASSERT_EQ(0, pthread_create(&signal_thread, NULL, SignalHandlerFn, &received_signal));
+  ASSERT_EQ(0, pthread_create(&signal_thread, nullptr, SignalHandlerFn, &received_signal));
 
   // Send that thread SIGRTMIN.
   pthread_kill(signal_thread, SIGRTMIN);
@@ -440,7 +440,7 @@
   ASSERT_EQ(0U, reinterpret_cast<uintptr_t>(join_result));
 
   // Restore the original signal mask.
-  ASSERT_EQ(0, pthread_sigmask64(SIG_SETMASK, &original_set, NULL));
+  ASSERT_EQ(0, pthread_sigmask64(SIG_SETMASK, &original_set, nullptr));
 }
 
 static void test_pthread_setname_np__pthread_getname_np(pthread_t t) {
@@ -555,7 +555,7 @@
   SpinFunctionHelper spin_helper;
 
   pthread_t t;
-  ASSERT_EQ(0, pthread_create(&t, NULL, spin_helper.GetFunction(), NULL));
+  ASSERT_EQ(0, pthread_create(&t, nullptr, spin_helper.GetFunction(), nullptr));
 
   clockid_t c;
   ASSERT_EQ(0, pthread_getcpuclockid(t, &c));
@@ -627,12 +627,12 @@
   pthread_t dead_thread;
   MakeDeadThread(dead_thread);
 
-  EXPECT_DEATH(pthread_join(dead_thread, NULL), "invalid pthread_t");
+  EXPECT_DEATH(pthread_join(dead_thread, nullptr), "invalid pthread_t");
 }
 
 TEST_F(pthread_DeathTest, pthread_join__null_thread) {
   pthread_t null_thread = 0;
-  EXPECT_EQ(ESRCH, pthread_join(null_thread, NULL));
+  EXPECT_EQ(ESRCH, pthread_join(null_thread, nullptr));
 }
 
 TEST_F(pthread_DeathTest, pthread_kill__no_such_thread) {
@@ -651,15 +651,15 @@
   SpinFunctionHelper spin_helper;
 
   pthread_t t1;
-  ASSERT_EQ(0, pthread_create(&t1, NULL, spin_helper.GetFunction(), NULL));
+  ASSERT_EQ(0, pthread_create(&t1, nullptr, spin_helper.GetFunction(), nullptr));
 
   pthread_t t2;
-  ASSERT_EQ(0, pthread_create(&t2, NULL, JoinFn, reinterpret_cast<void*>(t1)));
+  ASSERT_EQ(0, pthread_create(&t2, nullptr, JoinFn, reinterpret_cast<void*>(t1)));
 
   sleep(1); // (Give t2 a chance to call pthread_join.)
 
   // Multiple joins to the same thread should fail.
-  ASSERT_EQ(EINVAL, pthread_join(t1, NULL));
+  ASSERT_EQ(EINVAL, pthread_join(t1, nullptr));
 
   spin_helper.UnSpin();
 
@@ -674,15 +674,15 @@
   // If the joiner unmapped the thread's stack, that could lead to SIGSEGV in the thread.
   for (size_t i = 0; i < 1024; ++i) {
     size_t stack_size = 640*1024;
-    void* stack = mmap(NULL, stack_size, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0);
+    void* stack = mmap(nullptr, stack_size, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0);
 
     pthread_attr_t a;
     pthread_attr_init(&a);
     pthread_attr_setstack(&a, stack, stack_size);
 
     pthread_t t;
-    ASSERT_EQ(0, pthread_create(&t, &a, IdFn, NULL));
-    ASSERT_EQ(0, pthread_join(t, NULL));
+    ASSERT_EQ(0, pthread_create(&t, &a, IdFn, nullptr));
+    ASSERT_EQ(0, pthread_join(t, nullptr));
     ASSERT_EQ(0, munmap(stack, stack_size));
   }
 }
@@ -691,14 +691,14 @@
   pthread_attr_t attributes;
   pthread_getattr_np(pthread_self(), &attributes);
   pthread_attr_getguardsize(&attributes, reinterpret_cast<size_t*>(arg));
-  return NULL;
+  return nullptr;
 }
 
 static size_t GetActualGuardSize(const pthread_attr_t& attributes) {
   size_t result;
   pthread_t t;
   pthread_create(&t, &attributes, GetActualGuardSizeFn, &result);
-  pthread_join(t, NULL);
+  pthread_join(t, nullptr);
   return result;
 }
 
@@ -706,14 +706,14 @@
   pthread_attr_t attributes;
   pthread_getattr_np(pthread_self(), &attributes);
   pthread_attr_getstacksize(&attributes, reinterpret_cast<size_t*>(arg));
-  return NULL;
+  return nullptr;
 }
 
 static size_t GetActualStackSize(const pthread_attr_t& attributes) {
   size_t result;
   pthread_t t;
   pthread_create(&t, &attributes, GetActualStackSizeFn, &result);
-  pthread_join(t, NULL);
+  pthread_join(t, nullptr);
   return result;
 }
 
@@ -827,13 +827,13 @@
 TEST(pthread, pthread_rwlock_init_same_as_PTHREAD_RWLOCK_INITIALIZER) {
   pthread_rwlock_t lock1 = PTHREAD_RWLOCK_INITIALIZER;
   pthread_rwlock_t lock2;
-  ASSERT_EQ(0, pthread_rwlock_init(&lock2, NULL));
+  ASSERT_EQ(0, pthread_rwlock_init(&lock2, nullptr));
   ASSERT_EQ(0, memcmp(&lock1, &lock2, sizeof(lock1)));
 }
 
 TEST(pthread, pthread_rwlock_smoke) {
   pthread_rwlock_t l;
-  ASSERT_EQ(0, pthread_rwlock_init(&l, NULL));
+  ASSERT_EQ(0, pthread_rwlock_init(&l, nullptr));
 
   // Single read lock
   ASSERT_EQ(0, pthread_rwlock_rdlock(&l));
@@ -911,7 +911,7 @@
 
 static void test_pthread_rwlock_reader_wakeup_writer(std::function<int (pthread_rwlock_t*)> lock_function) {
   RwlockWakeupHelperArg wakeup_arg;
-  ASSERT_EQ(0, pthread_rwlock_init(&wakeup_arg.lock, NULL));
+  ASSERT_EQ(0, pthread_rwlock_init(&wakeup_arg.lock, nullptr));
   ASSERT_EQ(0, pthread_rwlock_rdlock(&wakeup_arg.lock));
   wakeup_arg.progress = RwlockWakeupHelperArg::LOCK_INITIALIZED;
   wakeup_arg.tid = 0;
@@ -919,7 +919,7 @@
   wakeup_arg.lock_function = lock_function;
 
   pthread_t thread;
-  ASSERT_EQ(0, pthread_create(&thread, NULL,
+  ASSERT_EQ(0, pthread_create(&thread, nullptr,
     reinterpret_cast<void* (*)(void*)>(pthread_rwlock_wakeup_helper), &wakeup_arg));
   WaitUntilThreadSleep(wakeup_arg.tid);
   ASSERT_EQ(RwlockWakeupHelperArg::LOCK_WAITING, wakeup_arg.progress);
@@ -927,7 +927,7 @@
   wakeup_arg.progress = RwlockWakeupHelperArg::LOCK_RELEASED;
   ASSERT_EQ(0, pthread_rwlock_unlock(&wakeup_arg.lock));
 
-  ASSERT_EQ(0, pthread_join(thread, NULL));
+  ASSERT_EQ(0, pthread_join(thread, nullptr));
   ASSERT_EQ(RwlockWakeupHelperArg::LOCK_ACCESSED, wakeup_arg.progress);
   ASSERT_EQ(0, pthread_rwlock_destroy(&wakeup_arg.lock));
 }
@@ -960,7 +960,7 @@
 
 static void test_pthread_rwlock_writer_wakeup_reader(std::function<int (pthread_rwlock_t*)> lock_function) {
   RwlockWakeupHelperArg wakeup_arg;
-  ASSERT_EQ(0, pthread_rwlock_init(&wakeup_arg.lock, NULL));
+  ASSERT_EQ(0, pthread_rwlock_init(&wakeup_arg.lock, nullptr));
   ASSERT_EQ(0, pthread_rwlock_wrlock(&wakeup_arg.lock));
   wakeup_arg.progress = RwlockWakeupHelperArg::LOCK_INITIALIZED;
   wakeup_arg.tid = 0;
@@ -968,7 +968,7 @@
   wakeup_arg.lock_function = lock_function;
 
   pthread_t thread;
-  ASSERT_EQ(0, pthread_create(&thread, NULL,
+  ASSERT_EQ(0, pthread_create(&thread, nullptr,
     reinterpret_cast<void* (*)(void*)>(pthread_rwlock_wakeup_helper), &wakeup_arg));
   WaitUntilThreadSleep(wakeup_arg.tid);
   ASSERT_EQ(RwlockWakeupHelperArg::LOCK_WAITING, wakeup_arg.progress);
@@ -976,7 +976,7 @@
   wakeup_arg.progress = RwlockWakeupHelperArg::LOCK_RELEASED;
   ASSERT_EQ(0, pthread_rwlock_unlock(&wakeup_arg.lock));
 
-  ASSERT_EQ(0, pthread_join(thread, NULL));
+  ASSERT_EQ(0, pthread_join(thread, nullptr));
   ASSERT_EQ(RwlockWakeupHelperArg::LOCK_ACCESSED, wakeup_arg.progress);
   ASSERT_EQ(0, pthread_rwlock_destroy(&wakeup_arg.lock));
 }
@@ -1130,14 +1130,14 @@
   void CreateWriterThread(pthread_t& thread, std::atomic<pid_t>& tid) {
     tid = 0;
     ThreadArg* arg = new ThreadArg(this, tid);
-    ASSERT_EQ(0, pthread_create(&thread, NULL,
+    ASSERT_EQ(0, pthread_create(&thread, nullptr,
                                 reinterpret_cast<void* (*)(void*)>(WriterThreadFn), arg));
   }
 
   void CreateReaderThread(pthread_t& thread, std::atomic<pid_t>& tid) {
     tid = 0;
     ThreadArg* arg = new ThreadArg(this, tid);
-    ASSERT_EQ(0, pthread_create(&thread, NULL,
+    ASSERT_EQ(0, pthread_create(&thread, nullptr,
                                 reinterpret_cast<void* (*)(void*)>(ReaderThreadFn), arg));
   }
 
@@ -1185,10 +1185,10 @@
   pthread_t reader_thread;
   std::atomic<pid_t> reader_tid;
   helper.CreateReaderThread(reader_thread, reader_tid);
-  ASSERT_EQ(0, pthread_join(reader_thread, NULL));
+  ASSERT_EQ(0, pthread_join(reader_thread, nullptr));
 
   ASSERT_EQ(0, pthread_rwlock_unlock(&helper.lock));
-  ASSERT_EQ(0, pthread_join(writer_thread, NULL));
+  ASSERT_EQ(0, pthread_join(writer_thread, nullptr));
 }
 
 TEST(pthread, pthread_rwlock_kind_PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP) {
@@ -1206,8 +1206,8 @@
   WaitUntilThreadSleep(reader_tid);
 
   ASSERT_EQ(0, pthread_rwlock_unlock(&helper.lock));
-  ASSERT_EQ(0, pthread_join(writer_thread, NULL));
-  ASSERT_EQ(0, pthread_join(reader_thread, NULL));
+  ASSERT_EQ(0, pthread_join(writer_thread, nullptr));
+  ASSERT_EQ(0, pthread_join(reader_thread, nullptr));
 }
 
 static int g_once_fn_call_count = 0;
@@ -1366,7 +1366,7 @@
   void StartWaitingThread(std::function<int (pthread_cond_t* cond, pthread_mutex_t* mutex)> wait_function) {
     progress = INITIALIZED;
     this->wait_function = wait_function;
-    ASSERT_EQ(0, pthread_create(&thread, NULL, reinterpret_cast<void* (*)(void*)>(WaitThreadFn), this));
+    ASSERT_EQ(0, pthread_create(&thread, nullptr, reinterpret_cast<void* (*)(void*)>(WaitThreadFn), this));
     while (progress != WAITING) {
       usleep(5000);
     }
@@ -1517,7 +1517,7 @@
   // We do not use "[stack]" label because in native-bridge environment it is not
   // guaranteed to point to the right stack. A native bridge implementation may
   // keep separate stack for the guest code.
-  void* maps_stack_hi = NULL;
+  void* maps_stack_hi = nullptr;
   std::vector<map_record> maps;
   ASSERT_TRUE(Maps::parse_maps(&maps));
   uintptr_t stack_address = reinterpret_cast<uintptr_t>(&maps_stack_hi);
@@ -1621,7 +1621,7 @@
   ASSERT_EQ(getpid(), syscall(__NR_gettid));
 
   const size_t sig_stack_size = 16 * 1024;
-  void* sig_stack = mmap(NULL, sig_stack_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS,
+  void* sig_stack = mmap(nullptr, sig_stack_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS,
                          -1, 0);
   ASSERT_NE(MAP_FAILED, sig_stack);
   stack_t ss;
@@ -1667,10 +1667,10 @@
 // [stack_base, stack_base + stack_size). see b/18908062.
 TEST(pthread, pthread_attr_getstack_18908062) {
   pthread_t t;
-  ASSERT_EQ(0, pthread_create(&t, NULL,
+  ASSERT_EQ(0, pthread_create(&t, nullptr,
             reinterpret_cast<void* (*)(void*)>(pthread_attr_getstack_18908062_helper),
-            NULL));
-  ASSERT_EQ(0, pthread_join(t, NULL));
+            nullptr));
+  ASSERT_EQ(0, pthread_join(t, nullptr));
 }
 
 #if defined(__BIONIC__)
@@ -1682,7 +1682,7 @@
   // Wait for our parent to call pthread_gettid_np on us before exiting.
   pthread_mutex_lock(&pthread_gettid_np_mutex);
   pthread_mutex_unlock(&pthread_gettid_np_mutex);
-  return NULL;
+  return nullptr;
 }
 #endif
 
@@ -1696,13 +1696,13 @@
 
   pid_t t_gettid_result;
   pthread_t t;
-  pthread_create(&t, NULL, pthread_gettid_np_helper, &t_gettid_result);
+  pthread_create(&t, nullptr, pthread_gettid_np_helper, &t_gettid_result);
 
   pid_t t_pthread_gettid_np_result = pthread_gettid_np(t);
 
   // Release the other thread and wait for it to exit.
   pthread_mutex_unlock(&pthread_gettid_np_mutex);
-  ASSERT_EQ(0, pthread_join(t, NULL));
+  ASSERT_EQ(0, pthread_join(t, nullptr));
 
   ASSERT_EQ(t_gettid_result, t_pthread_gettid_np_result);
 #else
@@ -1721,15 +1721,15 @@
 }
 
 static void PthreadCleanupTester() {
-  pthread_cleanup_push(CountCleanupRoutine, NULL);
-  pthread_cleanup_push(CountCleanupRoutine, NULL);
-  pthread_cleanup_push(AbortCleanupRoutine, NULL);
+  pthread_cleanup_push(CountCleanupRoutine, nullptr);
+  pthread_cleanup_push(CountCleanupRoutine, nullptr);
+  pthread_cleanup_push(AbortCleanupRoutine, nullptr);
 
   pthread_cleanup_pop(0); // Pop the abort without executing it.
   pthread_cleanup_pop(1); // Pop one count while executing it.
   ASSERT_EQ(1U, cleanup_counter);
   // Exit while the other count is still on the cleanup stack.
-  pthread_exit(NULL);
+  pthread_exit(nullptr);
 
   // Calls to pthread_cleanup_pop/pthread_cleanup_push must always be balanced.
   pthread_cleanup_pop(0);
@@ -1737,13 +1737,13 @@
 
 static void* PthreadCleanupStartRoutine(void*) {
   PthreadCleanupTester();
-  return NULL;
+  return nullptr;
 }
 
 TEST(pthread, pthread_cleanup_push__pthread_cleanup_pop) {
   pthread_t t;
-  ASSERT_EQ(0, pthread_create(&t, NULL, PthreadCleanupStartRoutine, NULL));
-  ASSERT_EQ(0, pthread_join(t, NULL));
+  ASSERT_EQ(0, pthread_create(&t, nullptr, PthreadCleanupStartRoutine, nullptr));
+  ASSERT_EQ(0, pthread_join(t, nullptr));
   ASSERT_EQ(2U, cleanup_counter);
 }
 
@@ -1956,7 +1956,7 @@
     tid = 0;
 
     pthread_t thread;
-    ASSERT_EQ(0, pthread_create(&thread, NULL,
+    ASSERT_EQ(0, pthread_create(&thread, nullptr,
       reinterpret_cast<void* (*)(void*)>(MutexWakeupHelper::thread_fn), this));
 
     WaitUntilThreadSleep(tid);
@@ -1965,7 +1965,7 @@
     progress = LOCK_RELEASED;
     ASSERT_EQ(0, pthread_mutex_unlock(&m.lock));
 
-    ASSERT_EQ(0, pthread_join(thread, NULL));
+    ASSERT_EQ(0, pthread_join(thread, nullptr));
     ASSERT_EQ(LOCK_ACCESSED, progress);
   }
 };
@@ -2054,7 +2054,7 @@
     child_tid = 0;
 
     pthread_t thread;
-    ASSERT_EQ(0, pthread_create(&thread, NULL,
+    ASSERT_EQ(0, pthread_create(&thread, nullptr,
               reinterpret_cast<void* (*)(void*)>(PIMutexWakeupHelper::thread_fn), this));
 
     WaitUntilThreadSleep(child_tid);
@@ -2081,7 +2081,7 @@
 TEST(pthread, pthread_mutex_owner_tid_limit) {
 #if defined(__BIONIC__) && !defined(__LP64__)
   FILE* fp = fopen("/proc/sys/kernel/pid_max", "r");
-  ASSERT_TRUE(fp != NULL);
+  ASSERT_TRUE(fp != nullptr);
   long pid_max;
   ASSERT_EQ(1, fscanf(fp, "%ld", &pid_max));
   fclose(fp);
@@ -2168,7 +2168,7 @@
   };
 
   pthread_t thread;
-  ASSERT_EQ(0, pthread_create(&thread, NULL, ThreadFn, &thread_args));
+  ASSERT_EQ(0, pthread_create(&thread, nullptr, ThreadFn, &thread_args));
   void* result;
   ASSERT_EQ(0, pthread_join(thread, &result));
   ASSERT_EQ(ETIMEDOUT, reinterpret_cast<intptr_t>(result));
@@ -2242,21 +2242,21 @@
   StrictAlignmentAllocator allocator;
   pthread_mutex_t* mutex = reinterpret_cast<pthread_mutex_t*>(
                              allocator.allocate(sizeof(pthread_mutex_t), 4));
-  ASSERT_EQ(0, pthread_mutex_init(mutex, NULL));
+  ASSERT_EQ(0, pthread_mutex_init(mutex, nullptr));
   ASSERT_EQ(0, pthread_mutex_lock(mutex));
   ASSERT_EQ(0, pthread_mutex_unlock(mutex));
   ASSERT_EQ(0, pthread_mutex_destroy(mutex));
 
   pthread_cond_t* cond = reinterpret_cast<pthread_cond_t*>(
                            allocator.allocate(sizeof(pthread_cond_t), 4));
-  ASSERT_EQ(0, pthread_cond_init(cond, NULL));
+  ASSERT_EQ(0, pthread_cond_init(cond, nullptr));
   ASSERT_EQ(0, pthread_cond_signal(cond));
   ASSERT_EQ(0, pthread_cond_broadcast(cond));
   ASSERT_EQ(0, pthread_cond_destroy(cond));
 
   pthread_rwlock_t* rwlock = reinterpret_cast<pthread_rwlock_t*>(
                                allocator.allocate(sizeof(pthread_rwlock_t), 4));
-  ASSERT_EQ(0, pthread_rwlock_init(rwlock, NULL));
+  ASSERT_EQ(0, pthread_rwlock_init(rwlock, nullptr));
   ASSERT_EQ(0, pthread_rwlock_rdlock(rwlock));
   ASSERT_EQ(0, pthread_rwlock_unlock(rwlock));
   ASSERT_EQ(0, pthread_rwlock_wrlock(rwlock));
diff --git a/tests/pty_test.cpp b/tests/pty_test.cpp
index 609f2dc..75f228c 100644
--- a/tests/pty_test.cpp
+++ b/tests/pty_test.cpp
@@ -31,7 +31,7 @@
   int master, slave;
   char name[32];
   struct winsize w = { 123, 456, 9999, 999 };
-  ASSERT_EQ(0, openpty(&master, &slave, name, NULL, &w));
+  ASSERT_EQ(0, openpty(&master, &slave, name, nullptr, &w));
   ASSERT_NE(-1, master);
   ASSERT_NE(-1, slave);
   ASSERT_NE(master, slave);
@@ -55,7 +55,7 @@
   pid_t sid = getsid(0);
 
   int master;
-  pid_t pid = forkpty(&master, NULL, NULL, NULL);
+  pid_t pid = forkpty(&master, nullptr, nullptr, nullptr);
   ASSERT_NE(-1, pid);
 
   if (pid == 0) {
diff --git a/tests/regex_test.cpp b/tests/regex_test.cpp
index 0e7f8dd..0d88261 100644
--- a/tests/regex_test.cpp
+++ b/tests/regex_test.cpp
@@ -23,8 +23,8 @@
   // A quick test of all the regex functions.
   regex_t re;
   ASSERT_EQ(0, regcomp(&re, "ab*c", 0));
-  ASSERT_EQ(0, regexec(&re, "abbbc", 0, NULL, 0));
-  ASSERT_EQ(REG_NOMATCH, regexec(&re, "foo", 0, NULL, 0));
+  ASSERT_EQ(0, regexec(&re, "abbbc", 0, nullptr, 0));
+  ASSERT_EQ(REG_NOMATCH, regexec(&re, "foo", 0, nullptr, 0));
 
   char buf[80];
   regerror(REG_NOMATCH, &re, buf, sizeof(buf));
diff --git a/tests/sched_test.cpp b/tests/sched_test.cpp
index e70528e..9184026 100644
--- a/tests/sched_test.cpp
+++ b/tests/sched_test.cpp
@@ -56,7 +56,7 @@
   uintptr_t fake_child_stack[16];
   errno = 0;
   // If CLONE_THREAD is set, CLONE_SIGHAND must be set too.
-  ASSERT_EQ(-1, clone(child_fn, &fake_child_stack[16], CLONE_THREAD, NULL));
+  ASSERT_EQ(-1, clone(child_fn, &fake_child_stack[16], CLONE_THREAD, nullptr));
   ASSERT_EQ(EINVAL, errno);
 }
 
diff --git a/tests/search_test.cpp b/tests/search_test.cpp
index d5ab67c..1509199 100644
--- a/tests/search_test.cpp
+++ b/tests/search_test.cpp
@@ -151,18 +151,18 @@
 
   // Linear (not circular).
 
-  insque(&zero, NULL);
+  insque(&zero, nullptr);
   insque(&one, &zero);
   insque(&two, &one);
 
   int expected = 0;
-  for (q_node* q = &zero; q != NULL; q = q->next) {
+  for (q_node* q = &zero; q != nullptr; q = q->next) {
     ASSERT_EQ(expected, q->i);
     ++expected;
   }
   ASSERT_EQ(3, expected);
 
-  for (q_node* q = &two; q != NULL; q = q->prev) {
+  for (q_node* q = &two; q != nullptr; q = q->prev) {
     --expected;
     ASSERT_EQ(expected, q->i);
   }
diff --git a/tests/semaphore_test.cpp b/tests/semaphore_test.cpp
index 607e37f..10d99ea 100644
--- a/tests/semaphore_test.cpp
+++ b/tests/semaphore_test.cpp
@@ -78,9 +78,9 @@
   ASSERT_EQ(0, sem_init(&s, 0, 0));
 
   pthread_t t1, t2, t3;
-  ASSERT_EQ(0, pthread_create(&t1, NULL, SemWaitThreadFn, &s));
-  ASSERT_EQ(0, pthread_create(&t2, NULL, SemWaitThreadFn, &s));
-  ASSERT_EQ(0, pthread_create(&t3, NULL, SemWaitThreadFn, &s));
+  ASSERT_EQ(0, pthread_create(&t1, nullptr, SemWaitThreadFn, &s));
+  ASSERT_EQ(0, pthread_create(&t2, nullptr, SemWaitThreadFn, &s));
+  ASSERT_EQ(0, pthread_create(&t3, nullptr, SemWaitThreadFn, &s));
 
   ASSERT_EQ(0, sem_post(&s));
   ASSERT_EQ(0, sem_post(&s));
diff --git a/tests/setjmp_test.cpp b/tests/setjmp_test.cpp
index a49e910..05339a6 100644
--- a/tests/setjmp_test.cpp
+++ b/tests/setjmp_test.cpp
@@ -84,7 +84,7 @@
 
 void AssertSigmaskEquals(const sigset64_t& expected) {
   sigset64_t actual;
-  sigprocmask64(SIG_SETMASK, NULL, &actual);
+  sigprocmask64(SIG_SETMASK, nullptr, &actual);
   size_t end = sizeof(expected) * 8;
   for (size_t i = 1; i <= end; ++i) {
     EXPECT_EQ(sigismember64(&expected, i), sigismember64(&actual, i)) << i;
@@ -99,7 +99,7 @@
   sigprocmask64(SIG_SETMASK, &ss.one, nullptr);
   jmp_buf jb;
   if (_setjmp(jb) == 0) {
-    sigprocmask64(SIG_SETMASK, &ss.two, NULL);
+    sigprocmask64(SIG_SETMASK, &ss.two, nullptr);
     _longjmp(jb, 1);
     FAIL(); // Unreachable.
   } else {
@@ -117,7 +117,7 @@
   sigprocmask64(SIG_SETMASK, &ss.one, nullptr);
   jmp_buf jb;
   if (setjmp(jb) == 0) {
-    sigprocmask64(SIG_SETMASK, &ss.two, NULL);
+    sigprocmask64(SIG_SETMASK, &ss.two, nullptr);
     longjmp(jb, 1);
     FAIL(); // Unreachable.
   } else {
@@ -139,7 +139,7 @@
   sigprocmask64(SIG_SETMASK, &ss.one, nullptr);
   sigjmp_buf sjb;
   if (sigsetjmp(sjb, 0) == 0) {
-    sigprocmask64(SIG_SETMASK, &ss.two, NULL);
+    sigprocmask64(SIG_SETMASK, &ss.two, nullptr);
     siglongjmp(sjb, 1);
     FAIL(); // Unreachable.
   } else {
@@ -155,7 +155,7 @@
   sigprocmask64(SIG_SETMASK, &ss.one, nullptr);
   sigjmp_buf sjb;
   if (sigsetjmp(sjb, 1) == 0) {
-    sigprocmask64(SIG_SETMASK, &ss.two, NULL);
+    sigprocmask64(SIG_SETMASK, &ss.two, nullptr);
     siglongjmp(sjb, 1);
     FAIL(); // Unreachable.
   } else {
diff --git a/tests/signal_test.cpp b/tests/signal_test.cpp
index 53c91a2..cc95ef7 100644
--- a/tests/signal_test.cpp
+++ b/tests/signal_test.cpp
@@ -37,13 +37,13 @@
 
 template <typename SigSetT>
 static void TestSigSet1(int (fn)(SigSetT*)) {
-  // NULL sigset_t*/sigset64_t*.
-  SigSetT* set_ptr = NULL;
+  // nullptr sigset_t*/sigset64_t*.
+  SigSetT* set_ptr = nullptr;
   errno = 0;
   ASSERT_EQ(-1, fn(set_ptr));
   ASSERT_EQ(EINVAL, errno);
 
-  // Non-NULL.
+  // Non-nullptr.
   SigSetT set = {};
   errno = 0;
   ASSERT_EQ(0, fn(&set));
@@ -52,8 +52,8 @@
 
 template <typename SigSetT>
 static void TestSigSet2(int (fn)(SigSetT*, int)) {
-  // NULL sigset_t*/sigset64_t*.
-  SigSetT* set_ptr = NULL;
+  // nullptr sigset_t*/sigset64_t*.
+  SigSetT* set_ptr = nullptr;
   errno = 0;
   ASSERT_EQ(-1, fn(set_ptr, SIGSEGV));
   ASSERT_EQ(EINVAL, errno);
@@ -281,9 +281,9 @@
 
   // See what's currently set for this signal.
   SigActionT original_sa = {};
-  ASSERT_EQ(0, sigaction_fn(sig, NULL, &original_sa));
-  ASSERT_TRUE(original_sa.sa_handler == NULL);
-  ASSERT_TRUE(original_sa.sa_sigaction == NULL);
+  ASSERT_EQ(0, sigaction_fn(sig, nullptr, &original_sa));
+  ASSERT_TRUE(original_sa.sa_handler == nullptr);
+  ASSERT_TRUE(original_sa.sa_sigaction == nullptr);
   ASSERT_EQ(0U, original_sa.sa_flags & ~sa_restorer);
 #ifdef SA_RESTORER
   ASSERT_EQ(bool(original_sa.sa_flags & sa_restorer), bool(original_sa.sa_restorer));
@@ -295,11 +295,11 @@
   sigaddset_fn(&sa.sa_mask, sig);
   sa.sa_flags = SA_ONSTACK;
   sa.sa_handler = no_op_signal_handler;
-  ASSERT_EQ(0, sigaction_fn(sig, &sa, NULL));
+  ASSERT_EQ(0, sigaction_fn(sig, &sa, nullptr));
 
   // Check that we can read it back.
   sa = {};
-  ASSERT_EQ(0, sigaction_fn(sig, NULL, &sa));
+  ASSERT_EQ(0, sigaction_fn(sig, nullptr, &sa));
   ASSERT_TRUE(sa.sa_handler == no_op_signal_handler);
   ASSERT_TRUE((void*) sa.sa_sigaction == (void*) sa.sa_handler);
   ASSERT_EQ(static_cast<unsigned>(SA_ONSTACK), sa.sa_flags & ~sa_restorer);
@@ -313,11 +313,11 @@
   sigaddset_fn(&sa.sa_mask, sig);
   sa.sa_flags = SA_ONSTACK | SA_SIGINFO;
   sa.sa_sigaction = no_op_sigaction;
-  ASSERT_EQ(0, sigaction_fn(sig, &sa, NULL));
+  ASSERT_EQ(0, sigaction_fn(sig, &sa, nullptr));
 
   // Check that we can read it back.
   sa = {};
-  ASSERT_EQ(0, sigaction_fn(sig, NULL, &sa));
+  ASSERT_EQ(0, sigaction_fn(sig, nullptr, &sa));
   ASSERT_TRUE(sa.sa_sigaction == no_op_sigaction);
   ASSERT_TRUE((void*) sa.sa_sigaction == (void*) sa.sa_handler);
   ASSERT_EQ(static_cast<unsigned>(SA_ONSTACK | SA_SIGINFO), sa.sa_flags & ~sa_restorer);
@@ -326,7 +326,7 @@
 #endif
 
   // Put everything back how it was.
-  ASSERT_EQ(0, sigaction_fn(sig, &original_sa, NULL));
+  ASSERT_EQ(0, sigaction_fn(sig, &original_sa, nullptr));
 }
 
 TEST(signal, sigaction) {
@@ -547,7 +547,7 @@
 
 TEST(signal, sys_signame) {
 #if defined(__BIONIC__)
-  ASSERT_TRUE(sys_signame[0] == NULL);
+  ASSERT_TRUE(sys_signame[0] == nullptr);
   ASSERT_STREQ("HUP", sys_signame[SIGHUP]);
 #else
   GTEST_LOG_(INFO) << "This test does nothing.\n";
@@ -555,7 +555,7 @@
 }
 
 TEST(signal, sys_siglist) {
-  ASSERT_TRUE(sys_siglist[0] == NULL);
+  ASSERT_TRUE(sys_siglist[0] == nullptr);
   ASSERT_STREQ("Hangup", sys_siglist[SIGHUP]);
 }
 
@@ -708,7 +708,7 @@
   ASSERT_EQ(EAGAIN, errno);
   ASSERT_GE(NanoTime() - start_time, 1000000);
 
-  ASSERT_EQ(0, sigprocmask(SIG_SETMASK, &original_set, NULL));
+  ASSERT_EQ(0, sigprocmask(SIG_SETMASK, &original_set, nullptr));
 }
 
 #if defined(__BIONIC__)
@@ -806,7 +806,7 @@
 
   // sighold(SIGALRM/SIGRTMIN) should add SIGALRM/SIGRTMIN to the signal mask ...
   ASSERT_EQ(0, sighold(sig));
-  ASSERT_EQ(0, sigprocmask(SIG_SETMASK, 0, &set));
+  ASSERT_EQ(0, sigprocmask(SIG_SETMASK, nullptr, &set));
   EXPECT_TRUE(sigismember(&set, sig));
 
   // ... preventing our SIGALRM/SIGRTMIN handler from running ...
@@ -819,12 +819,12 @@
 
   if (sig >= SIGRTMIN && sizeof(void*) == 8) {
     // But sigpause(SIGALRM/SIGRTMIN) shouldn't permanently unblock SIGALRM/SIGRTMIN.
-    ASSERT_EQ(0, sigprocmask(SIG_SETMASK, 0, &set));
+    ASSERT_EQ(0, sigprocmask(SIG_SETMASK, nullptr, &set));
     EXPECT_TRUE(sigismember(&set, sig));
 
     // Whereas sigrelse(SIGALRM/SIGRTMIN) should.
     ASSERT_EQ(0, sigrelse(sig));
-    ASSERT_EQ(0, sigprocmask(SIG_SETMASK, 0, &set));
+    ASSERT_EQ(0, sigprocmask(SIG_SETMASK, nullptr, &set));
     EXPECT_FALSE(sigismember(&set, sig));
   } else {
     // sigismember won't work for SIGRTMIN on LP32.
diff --git a/tests/stack_protector_test.cpp b/tests/stack_protector_test.cpp
index 5f5a241..34e3c11 100644
--- a/tests/stack_protector_test.cpp
+++ b/tests/stack_protector_test.cpp
@@ -74,14 +74,14 @@
   size_t thread_count = 9;
   for (size_t i = 1; i < thread_count; ++i) {
     pthread_t t;
-    ASSERT_EQ(0, pthread_create(&t, NULL, [](void* arg) -> void* {
+    ASSERT_EQ(0, pthread_create(&t, nullptr, [](void* arg) -> void* {
       stack_protector_checker* checker = reinterpret_cast<stack_protector_checker*>(arg);
       checker->Check();
       return nullptr;
     }, &checker));
     void* result;
     ASSERT_EQ(0, pthread_join(t, &result));
-    ASSERT_EQ(NULL, result);
+    ASSERT_EQ(nullptr, result);
   }
   ASSERT_EQ(thread_count, checker.tids.size());
 
diff --git a/tests/stdatomic_test.cpp b/tests/stdatomic_test.cpp
index 389b251..d122d2f 100644
--- a/tests/stdatomic_test.cpp
+++ b/tests/stdatomic_test.cpp
@@ -206,7 +206,7 @@
     atomic_store_explicit(&a->z, i+1, memory_order_relaxed);
     atomic_store_explicit(&a->y, i+1, memory_order_release);
   }
-  return 0;
+  return nullptr;
 }
 
 static void* reader(void* arg) {
@@ -224,13 +224,13 @@
       // Cant just ASSERT, since we are in a non-void function.
       ADD_FAILURE() << "acquire-release ordering violation: "
                     << zval << " < " << yval << ", " << xval << "\n";
-      return 0; // Only report once.
+      return nullptr; // Only report once.
     }
     if (xval < yval) {
       // Cant just ASSERT, since we are in a non-void function.
       ADD_FAILURE() << "acquire-release ordering violation: "
                     << xval << " < " << yval << ", " << zval <<  "\n";
-      return 0; // Only report once.
+      return nullptr; // Only report once.
     }
     if (repeat < repeat_limit) ++repeat;
   }
@@ -238,7 +238,7 @@
   // But if it fails to hold, this test was useless, and we have a
   // serious scheduling issue that we should probably know about.
   EXPECT_EQ(repeat, repeat_limit);
-  return 0;
+  return nullptr;
 }
 
 TEST(stdatomic, ordering) {
@@ -249,12 +249,12 @@
   atomic_init(&a.y, 0ul);
   atomic_init(&a.z, 0ul);
   pthread_t t1,t2;
-  ASSERT_EQ(0, pthread_create(&t1, 0, reader, &a));
-  ASSERT_EQ(0, pthread_create(&t2, 0, writer, &a));
+  ASSERT_EQ(0, pthread_create(&t1, nullptr, reader, &a));
+  ASSERT_EQ(0, pthread_create(&t2, nullptr, writer, &a));
   ASSERT_EQ(0, pthread_join(t1, &result));
-  EXPECT_EQ(0, result);
+  EXPECT_EQ(nullptr, result);
   ASSERT_EQ(0, pthread_join(t2, &result));
-  EXPECT_EQ(0, result);
+  EXPECT_EQ(nullptr, result);
   EXPECT_EQ(atomic_load_explicit(&a.x, memory_order_consume), BIG + 1);
   EXPECT_EQ(atomic_load_explicit(&a.y, memory_order_seq_cst), BIG + 1);
   EXPECT_EQ(atomic_load(&a.z), BIG + 1);
diff --git a/tests/stdio_ext_test.cpp b/tests/stdio_ext_test.cpp
index 849bf0b..d4616ef 100644
--- a/tests/stdio_ext_test.cpp
+++ b/tests/stdio_ext_test.cpp
@@ -93,7 +93,7 @@
 
   char buf[16];
   char* s = fgets(buf, sizeof(buf), fp);
-  ASSERT_TRUE(s != NULL);
+  ASSERT_TRUE(s != nullptr);
   ASSERT_STREQ("b\n", s);
 
   fclose(fp);
diff --git a/tests/stdio_test.cpp b/tests/stdio_test.cpp
index d499ddb..844a9c0 100644
--- a/tests/stdio_test.cpp
+++ b/tests/stdio_test.cpp
@@ -95,7 +95,7 @@
 TEST(STDIO_TEST, flockfile_18208568_regular) {
   // We never had a bug for streams other than stdin/stdout/stderr, but test anyway.
   FILE* fp = fopen("/dev/null", "w");
-  ASSERT_TRUE(fp != NULL);
+  ASSERT_TRUE(fp != nullptr);
   flockfile(fp);
   feof(fp);
   funlockfile(fp);
@@ -104,7 +104,7 @@
 
 TEST(STDIO_TEST, tmpfile_fileno_fprintf_rewind_fgets) {
   FILE* fp = tmpfile();
-  ASSERT_TRUE(fp != NULL);
+  ASSERT_TRUE(fp != nullptr);
 
   int fd = fileno(fp);
   ASSERT_NE(fd, -1);
@@ -135,7 +135,7 @@
 
   lseek(tf.fd, 0, SEEK_SET);
   FILE* tfile = fdopen(tf.fd, "r");
-  ASSERT_TRUE(tfile != NULL);
+  ASSERT_TRUE(tfile != nullptr);
 
   AssertFileIs(tfile, "hello\n");
   fclose(tfile);
@@ -143,7 +143,7 @@
 
 TEST(STDIO_TEST, getdelim) {
   FILE* fp = tmpfile();
-  ASSERT_TRUE(fp != NULL);
+  ASSERT_TRUE(fp != nullptr);
 
   const char* line_written = "This  is a test";
   int rc = fprintf(fp, "%s", line_written);
@@ -151,7 +151,7 @@
 
   rewind(fp);
 
-  char* word_read = NULL;
+  char* word_read = nullptr;
   size_t allocated_length = 0;
 
   const char* expected[] = { "This ", " ", "is ", "a ", "test" };
@@ -178,26 +178,26 @@
 
 TEST(STDIO_TEST, getdelim_invalid) {
   FILE* fp = tmpfile();
-  ASSERT_TRUE(fp != NULL);
+  ASSERT_TRUE(fp != nullptr);
 
-  char* buffer = NULL;
+  char* buffer = nullptr;
   size_t buffer_length = 0;
 
   // The first argument can't be NULL.
   errno = 0;
-  ASSERT_EQ(getdelim(NULL, &buffer_length, ' ', fp), -1);
+  ASSERT_EQ(getdelim(nullptr, &buffer_length, ' ', fp), -1);
   ASSERT_EQ(EINVAL, errno);
 
   // The second argument can't be NULL.
   errno = 0;
-  ASSERT_EQ(getdelim(&buffer, NULL, ' ', fp), -1);
+  ASSERT_EQ(getdelim(&buffer, nullptr, ' ', fp), -1);
   ASSERT_EQ(EINVAL, errno);
   fclose(fp);
 }
 
 TEST(STDIO_TEST, getdelim_directory) {
   FILE* fp = fopen("/proc", "r");
-  ASSERT_TRUE(fp != NULL);
+  ASSERT_TRUE(fp != nullptr);
   char* word_read;
   size_t allocated_length;
   ASSERT_EQ(-1, getdelim(&word_read, &allocated_length, ' ', fp));
@@ -206,7 +206,7 @@
 
 TEST(STDIO_TEST, getline) {
   FILE* fp = tmpfile();
-  ASSERT_TRUE(fp != NULL);
+  ASSERT_TRUE(fp != nullptr);
 
   const char* line_written = "This is a test for getline\n";
   const size_t line_count = 5;
@@ -218,7 +218,7 @@
 
   rewind(fp);
 
-  char* line_read = NULL;
+  char* line_read = nullptr;
   size_t allocated_length = 0;
 
   size_t read_line_count = 0;
@@ -248,19 +248,19 @@
 
 TEST(STDIO_TEST, getline_invalid) {
   FILE* fp = tmpfile();
-  ASSERT_TRUE(fp != NULL);
+  ASSERT_TRUE(fp != nullptr);
 
-  char* buffer = NULL;
+  char* buffer = nullptr;
   size_t buffer_length = 0;
 
   // The first argument can't be NULL.
   errno = 0;
-  ASSERT_EQ(getline(NULL, &buffer_length, fp), -1);
+  ASSERT_EQ(getline(nullptr, &buffer_length, fp), -1);
   ASSERT_EQ(EINVAL, errno);
 
   // The second argument can't be NULL.
   errno = 0;
-  ASSERT_EQ(getline(&buffer, NULL, fp), -1);
+  ASSERT_EQ(getline(&buffer, nullptr, fp), -1);
   ASSERT_EQ(EINVAL, errno);
   fclose(fp);
 }
@@ -300,7 +300,7 @@
 
 TEST(STDIO_TEST, snprintf_ls) {
   char buf[BUFSIZ];
-  wchar_t* ws = NULL;
+  wchar_t* ws = nullptr;
   EXPECT_EQ(8, snprintf(buf, sizeof(buf), "<%ls>", ws));
   EXPECT_STREQ("<(null)>", buf);
 
@@ -312,7 +312,7 @@
 
 TEST(STDIO_TEST, snprintf_S) { // Synonym for %ls.
   char buf[BUFSIZ];
-  wchar_t* ws = NULL;
+  wchar_t* ws = nullptr;
   EXPECT_EQ(8, snprintf(buf, sizeof(buf), "<%S>", ws));
   EXPECT_STREQ("<(null)>", buf);
 
@@ -348,7 +348,7 @@
   snprintf(buf, sizeof(buf), "a%sb", "01234");
   EXPECT_STREQ("a01234b", buf);
 
-  char* s = NULL;
+  char* s = nullptr;
   snprintf(buf, sizeof(buf), "a%sb", s);
   EXPECT_STREQ("a(null)b", buf);
 
@@ -409,7 +409,7 @@
   snprintf(buf, sizeof(buf), "a%03d:%d:%02dz", 5, 5, 5);
   EXPECT_STREQ("a005:5:05z", buf);
 
-  void* p = NULL;
+  void* p = nullptr;
   snprintf(buf, sizeof(buf), "a%d,%pz", 5, p);
 #if defined(__BIONIC__)
   EXPECT_STREQ("a5,0x0z", buf);
@@ -786,7 +786,7 @@
 }
 
 TEST(STDIO_TEST, snprintf_utf8_15439554) {
-  locale_t cloc = newlocale(LC_ALL, "C.UTF-8", 0);
+  locale_t cloc = newlocale(LC_ALL, "C.UTF-8", nullptr);
   locale_t old_locale = uselocale(cloc);
 
   // http://b/15439554
@@ -862,7 +862,7 @@
 
   // Unbuffered case where the fprintf(3) itself fails.
   ASSERT_NE(nullptr, fp = tmpfile());
-  setbuf(fp, NULL);
+  setbuf(fp, nullptr);
   ASSERT_EQ(4, fprintf(fp, "epic"));
   ASSERT_NE(-1, dup2(fd_rdonly, fileno(fp)));
   ASSERT_EQ(-1, fprintf(fp, "fail"));
@@ -881,7 +881,7 @@
 
 TEST(STDIO_TEST, popen_r) {
   FILE* fp = popen("cat /proc/version", "r");
-  ASSERT_TRUE(fp != NULL);
+  ASSERT_TRUE(fp != nullptr);
 
   char buf[16];
   char* s = fgets(buf, sizeof(buf), fp);
@@ -893,7 +893,7 @@
 
 TEST(STDIO_TEST, popen_socketpair) {
   FILE* fp = popen("cat", "r+");
-  ASSERT_TRUE(fp != NULL);
+  ASSERT_TRUE(fp != nullptr);
 
   fputs("hello\nworld\n", fp);
   fflush(fp);
@@ -909,7 +909,7 @@
 
 TEST(STDIO_TEST, popen_socketpair_shutdown) {
   FILE* fp = popen("uniq -c", "r+");
-  ASSERT_TRUE(fp != NULL);
+  ASSERT_TRUE(fp != nullptr);
 
   fputs("a\na\na\na\nb\n", fp);
   fflush(fp);
@@ -926,7 +926,7 @@
 
 TEST(STDIO_TEST, popen_return_value_0) {
   FILE* fp = popen("true", "r");
-  ASSERT_TRUE(fp != NULL);
+  ASSERT_TRUE(fp != nullptr);
   int status = pclose(fp);
   EXPECT_TRUE(WIFEXITED(status));
   EXPECT_EQ(0, WEXITSTATUS(status));
@@ -934,7 +934,7 @@
 
 TEST(STDIO_TEST, popen_return_value_1) {
   FILE* fp = popen("false", "r");
-  ASSERT_TRUE(fp != NULL);
+  ASSERT_TRUE(fp != nullptr);
   int status = pclose(fp);
   EXPECT_TRUE(WIFEXITED(status));
   EXPECT_EQ(1, WEXITSTATUS(status));
@@ -942,7 +942,7 @@
 
 TEST(STDIO_TEST, popen_return_value_signal) {
   FILE* fp = popen("kill -7 $$", "r");
-  ASSERT_TRUE(fp != NULL);
+  ASSERT_TRUE(fp != nullptr);
   int status = pclose(fp);
   EXPECT_TRUE(WIFSIGNALED(status));
   EXPECT_EQ(7, WTERMSIG(status));
@@ -950,7 +950,7 @@
 
 TEST(STDIO_TEST, getc) {
   FILE* fp = fopen("/proc/version", "r");
-  ASSERT_TRUE(fp != NULL);
+  ASSERT_TRUE(fp != nullptr);
   ASSERT_EQ('L', getc(fp));
   ASSERT_EQ('i', getc(fp));
   ASSERT_EQ('n', getc(fp));
@@ -961,7 +961,7 @@
 
 TEST(STDIO_TEST, putc) {
   FILE* fp = fopen("/proc/version", "r");
-  ASSERT_TRUE(fp != NULL);
+  ASSERT_TRUE(fp != nullptr);
   ASSERT_EQ(EOF, putc('x', fp));
   fclose(fp);
 }
@@ -1328,7 +1328,7 @@
   uselocale(LC_GLOBAL_LOCALE);
 
   FILE* fp = tmpfile();
-  ASSERT_TRUE(fp != NULL);
+  ASSERT_TRUE(fp != nullptr);
 
   wchar_t mb_one_bytes = L'h';
   wchar_t mb_two_bytes = 0x00a2;
@@ -1398,7 +1398,7 @@
 
   TemporaryFile tf;
   FILE* fp = fdopen(tf.fd, "w+");
-  ASSERT_TRUE(fp != NULL);
+  ASSERT_TRUE(fp != nullptr);
 
   wchar_t mb_two_bytes = 0x00a2;
   wchar_t mb_three_bytes = 0x20ac;
@@ -1413,7 +1413,7 @@
   fclose(fp);
 
   fp = fopen(tf.filename, "r");
-  ASSERT_TRUE(fp != NULL);
+  ASSERT_TRUE(fp != nullptr);
 
   // Store a valid position.
   fpos_t mb_two_bytes_pos;
@@ -1900,7 +1900,7 @@
   AssertCloseOnExec(fd, false);
 
   FILE* fp = fdopen(fd, "re");
-  ASSERT_TRUE(fp != NULL);
+  ASSERT_TRUE(fp != nullptr);
 
   // ...but the new one does.
   AssertCloseOnExec(fileno(fp), true);
@@ -1910,7 +1910,7 @@
 
 TEST(STDIO_TEST, freopen_CLOEXEC) {
   FILE* fp = fopen("/proc/version", "r");
-  ASSERT_TRUE(fp != NULL);
+  ASSERT_TRUE(fp != nullptr);
 
   // This FILE* doesn't have O_CLOEXEC...
   AssertCloseOnExec(fileno(fp), false);
@@ -1935,19 +1935,19 @@
 // http://b/18556607
 TEST(STDIO_TEST, fread_unbuffered_pathological_performance) {
   FILE* fp = fopen("/dev/zero", "r");
-  ASSERT_TRUE(fp != NULL);
+  ASSERT_TRUE(fp != nullptr);
 
   // Make this stream unbuffered.
-  setvbuf(fp, 0, _IONBF, 0);
+  setvbuf(fp, nullptr, _IONBF, 0);
 
   char buf[65*1024];
   memset(buf, 0xff, sizeof(buf));
 
-  time_t t0 = time(NULL);
+  time_t t0 = time(nullptr);
   for (size_t i = 0; i < 1024; ++i) {
     ASSERT_EQ(1U, fread(buf, 64*1024, 1, fp));
   }
-  time_t t1 = time(NULL);
+  time_t t1 = time(nullptr);
 
   fclose(fp);
 
diff --git a/tests/stdlib_test.cpp b/tests/stdlib_test.cpp
index 2fbd937..6e41555 100644
--- a/tests/stdlib_test.cpp
+++ b/tests/stdlib_test.cpp
@@ -281,35 +281,35 @@
 TEST(stdlib, realpath__NULL_filename) {
   errno = 0;
   // Work around the compile-time error generated by FORTIFY here.
-  const char* path = NULL;
-  char* p = realpath(path, NULL);
-  ASSERT_TRUE(p == NULL);
+  const char* path = nullptr;
+  char* p = realpath(path, nullptr);
+  ASSERT_TRUE(p == nullptr);
   ASSERT_EQ(EINVAL, errno);
 }
 
 TEST(stdlib, realpath__empty_filename) {
   errno = 0;
-  char* p = realpath("", NULL);
-  ASSERT_TRUE(p == NULL);
+  char* p = realpath("", nullptr);
+  ASSERT_TRUE(p == nullptr);
   ASSERT_EQ(ENOENT, errno);
 }
 
 TEST(stdlib, realpath__ENOENT) {
   errno = 0;
-  char* p = realpath("/this/directory/path/almost/certainly/does/not/exist", NULL);
-  ASSERT_TRUE(p == NULL);
+  char* p = realpath("/this/directory/path/almost/certainly/does/not/exist", nullptr);
+  ASSERT_TRUE(p == nullptr);
   ASSERT_EQ(ENOENT, errno);
 }
 
 TEST(stdlib, realpath__component_after_non_directory) {
   errno = 0;
-  char* p = realpath("/dev/null/.", NULL);
-  ASSERT_TRUE(p == NULL);
+  char* p = realpath("/dev/null/.", nullptr);
+  ASSERT_TRUE(p == nullptr);
   ASSERT_EQ(ENOTDIR, errno);
 
   errno = 0;
-  p = realpath("/dev/null/..", NULL);
-  ASSERT_TRUE(p == NULL);
+  p = realpath("/dev/null/..", nullptr);
+  ASSERT_TRUE(p == nullptr);
   ASSERT_EQ(ENOTDIR, errno);
 }
 
@@ -324,7 +324,7 @@
   char* p = realpath("/proc/self/exe", buf);
   ASSERT_STREQ(executable_path, p);
 
-  p = realpath("/proc/self/exe", NULL);
+  p = realpath("/proc/self/exe", nullptr);
   ASSERT_STREQ(executable_path, p);
   free(p);
 }
@@ -354,18 +354,18 @@
 
 static void* TestBug57421_child(void* arg) {
   pthread_t main_thread = reinterpret_cast<pthread_t>(arg);
-  pthread_join(main_thread, NULL);
+  pthread_join(main_thread, nullptr);
   char* value = getenv("ENVIRONMENT_VARIABLE");
-  if (value == NULL) {
+  if (value == nullptr) {
     setenv("ENVIRONMENT_VARIABLE", "value", 1);
   }
-  return NULL;
+  return nullptr;
 }
 
 static void TestBug57421_main() {
   pthread_t t;
-  ASSERT_EQ(0, pthread_create(&t, NULL, TestBug57421_child, reinterpret_cast<void*>(pthread_self())));
-  pthread_exit(NULL);
+  ASSERT_EQ(0, pthread_create(&t, nullptr, TestBug57421_child, reinterpret_cast<void*>(pthread_self())));
+  pthread_exit(nullptr);
 }
 
 // Even though this isn't really a death test, we have to say "DeathTest" here so gtest knows to
@@ -483,20 +483,20 @@
 }
 
 TEST(stdlib, strtof_2206701) {
-  ASSERT_EQ(0.0f, strtof("7.0064923216240853546186479164495e-46", NULL));
-  ASSERT_EQ(1.4e-45f, strtof("7.0064923216240853546186479164496e-46", NULL));
+  ASSERT_EQ(0.0f, strtof("7.0064923216240853546186479164495e-46", nullptr));
+  ASSERT_EQ(1.4e-45f, strtof("7.0064923216240853546186479164496e-46", nullptr));
 }
 
 TEST(stdlib, strtod_largest_subnormal) {
   // This value has been known to cause javac and java to infinite loop.
   // http://www.exploringbinary.com/java-hangs-when-converting-2-2250738585072012e-308/
-  ASSERT_EQ(2.2250738585072014e-308, strtod("2.2250738585072012e-308", NULL));
-  ASSERT_EQ(2.2250738585072014e-308, strtod("0.00022250738585072012e-304", NULL));
-  ASSERT_EQ(2.2250738585072014e-308, strtod("00000002.2250738585072012e-308", NULL));
-  ASSERT_EQ(2.2250738585072014e-308, strtod("2.225073858507201200000e-308", NULL));
-  ASSERT_EQ(2.2250738585072014e-308, strtod("2.2250738585072012e-00308", NULL));
-  ASSERT_EQ(2.2250738585072014e-308, strtod("2.22507385850720129978001e-308", NULL));
-  ASSERT_EQ(-2.2250738585072014e-308, strtod("-2.2250738585072012e-308", NULL));
+  ASSERT_EQ(2.2250738585072014e-308, strtod("2.2250738585072012e-308", nullptr));
+  ASSERT_EQ(2.2250738585072014e-308, strtod("0.00022250738585072012e-304", nullptr));
+  ASSERT_EQ(2.2250738585072014e-308, strtod("00000002.2250738585072012e-308", nullptr));
+  ASSERT_EQ(2.2250738585072014e-308, strtod("2.225073858507201200000e-308", nullptr));
+  ASSERT_EQ(2.2250738585072014e-308, strtod("2.2250738585072012e-00308", nullptr));
+  ASSERT_EQ(2.2250738585072014e-308, strtod("2.22507385850720129978001e-308", nullptr));
+  ASSERT_EQ(-2.2250738585072014e-308, strtod("-2.2250738585072012e-308", nullptr));
 }
 
 TEST(stdlib, quick_exit) {
@@ -584,7 +584,7 @@
   int fd = getpt();
   ASSERT_NE(-1, fd);
   errno = 0;
-  char* buf = NULL;
+  char* buf = nullptr;
   ASSERT_EQ(EINVAL, ptsname_r(fd, buf, 128));
   ASSERT_EQ(EINVAL, errno);
   close(fd);
@@ -635,7 +635,7 @@
   int fd = getpt();
   ASSERT_NE(-1, fd);
   errno = 0;
-  char* buf = NULL;
+  char* buf = nullptr;
   ASSERT_EQ(EINVAL, ttyname_r(fd, buf, 128));
   ASSERT_EQ(EINVAL, errno);
   close(fd);
diff --git a/tests/string_test.cpp b/tests/string_test.cpp
index 0d42b05..8bfa964 100644
--- a/tests/string_test.cpp
+++ b/tests/string_test.cpp
@@ -78,7 +78,7 @@
   ASSERT_STREQ("Unknown error 1001", strerror1001);
 
   pthread_t t;
-  ASSERT_EQ(0, pthread_create(&t, NULL, ConcurrentStrErrorFn, NULL));
+  ASSERT_EQ(0, pthread_create(&t, nullptr, ConcurrentStrErrorFn, nullptr));
   void* result;
   ASSERT_EQ(0, pthread_join(t, &result));
   ASSERT_TRUE(static_cast<bool>(result));
@@ -144,7 +144,7 @@
   ASSERT_STREQ("Unknown signal 1001", strsignal1001);
 
   pthread_t t;
-  ASSERT_EQ(0, pthread_create(&t, NULL, ConcurrentStrSignalFn, NULL));
+  ASSERT_EQ(0, pthread_create(&t, nullptr, ConcurrentStrSignalFn, nullptr));
   void* result;
   ASSERT_EQ(0, pthread_join(t, &result));
   ASSERT_TRUE(static_cast<bool>(result));
@@ -451,7 +451,7 @@
         if (seek_char == 0) {
           expected = state.ptr1 + state.len[i] - 1;
         } else {
-          expected = NULL;
+          expected = nullptr;
         }
       } else {
         state.ptr1[pos] = seek_char;
@@ -763,7 +763,7 @@
         if (seek_char == 0) {
           expected = state.ptr1 + state.len[i] - 1;
         } else {
-          expected = NULL;
+          expected = nullptr;
         }
       } else {
         state.ptr1[pos] = seek_char;
@@ -785,7 +785,7 @@
       size_t pos = random() % state.MAX_LEN;
       char* expected;
       if (pos >= state.len[i]) {
-        expected = NULL;
+        expected = nullptr;
       } else {
         state.ptr1[pos] = seek_char;
         expected = state.ptr1 + pos;
@@ -800,8 +800,8 @@
   uint8_t* buffer;
   ASSERT_EQ(0, posix_memalign(reinterpret_cast<void**>(&buffer), 64, 64));
   memset(buffer, 10, 64);
-  ASSERT_TRUE(NULL == memchr(buffer, 5, 0));
-  ASSERT_TRUE(NULL == memchr(buffer, 10, 0));
+  ASSERT_TRUE(nullptr == memchr(buffer, 5, 0));
+  ASSERT_TRUE(nullptr == memchr(buffer, 10, 0));
 }
 
 TEST(STRING_TEST, memrchr) {
@@ -814,7 +814,7 @@
       size_t pos = random() % state.MAX_LEN;
       char* expected;
       if (pos >= state.len[i]) {
-        expected = NULL;
+        expected = nullptr;
       } else {
         state.ptr1[pos] = seek_char;
         expected = state.ptr1 + pos;
@@ -935,9 +935,9 @@
   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);
+  ASSERT_TRUE(ptr != nullptr);
+  ASSERT_TRUE(ptr1 != nullptr);
+  ASSERT_TRUE(glob_ptr2 != nullptr);
 
   for (int i = 0; i < 5; i++) {
     char* ptr2 = glob_ptr2 + alignments[i];
@@ -966,10 +966,10 @@
 
 TEST(STRING_TEST, memmove_check) {
   char* buffer = reinterpret_cast<char*>(malloc(MEMMOVE_DATA_SIZE));
-  ASSERT_TRUE(buffer != NULL);
+  ASSERT_TRUE(buffer != nullptr);
 
   char* src_data = reinterpret_cast<char*>(malloc(MEMMOVE_DATA_SIZE));
-  ASSERT_TRUE(src_data != NULL);
+  ASSERT_TRUE(src_data != nullptr);
   // Initialize to a known pattern to copy into src for each test and
   // to compare dst against.
   for (size_t i = 0; i < MEMMOVE_DATA_SIZE; i++) {
diff --git a/tests/strings_test.cpp b/tests/strings_test.cpp
index 1716843..ac327d4 100644
--- a/tests/strings_test.cpp
+++ b/tests/strings_test.cpp
@@ -45,7 +45,7 @@
 }
 
 TEST(STRINGS_TEST, strcasecmp_l) {
-  locale_t l = newlocale(LC_ALL, "C", 0);
+  locale_t l = newlocale(LC_ALL, "C", nullptr);
   ASSERT_EQ(0, strcasecmp_l("hello", "HELLO", l));
   ASSERT_LT(strcasecmp_l("hello1", "hello2", l), 0);
   ASSERT_GT(strcasecmp_l("hello2", "hello1", l), 0);
@@ -60,7 +60,7 @@
 }
 
 TEST(STRINGS_TEST, strncasecmp_l) {
-  locale_t l = newlocale(LC_ALL, "C", 0);
+  locale_t l = newlocale(LC_ALL, "C", nullptr);
   ASSERT_EQ(0, strncasecmp_l("hello", "HELLO", 3, l));
   ASSERT_EQ(0, strncasecmp_l("abcXX", "ABCYY", 3, l));
   ASSERT_LT(strncasecmp_l("hello1", "hello2", 6, l), 0);
diff --git a/tests/sys_epoll_test.cpp b/tests/sys_epoll_test.cpp
index 7233ccc..18cf380 100644
--- a/tests/sys_epoll_test.cpp
+++ b/tests/sys_epoll_test.cpp
@@ -33,11 +33,11 @@
   ASSERT_EQ(0, epoll_wait(epoll_fd, events, 1, 1));
 
   // epoll_pwait without a sigset (which is equivalent to epoll_wait).
-  ASSERT_EQ(0, epoll_pwait(epoll_fd, events, 1, 1, NULL));
+  ASSERT_EQ(0, epoll_pwait(epoll_fd, events, 1, 1, nullptr));
 
 #if defined(__BIONIC__)
   // epoll_pwait64 without a sigset (which is equivalent to epoll_wait).
-  ASSERT_EQ(0, epoll_pwait64(epoll_fd, events, 1, 1, NULL));
+  ASSERT_EQ(0, epoll_pwait64(epoll_fd, events, 1, 1, nullptr));
 #endif
 
   // epoll_pwait with a sigset.
diff --git a/tests/sys_mman_test.cpp b/tests/sys_mman_test.cpp
index e44bfed..22dc383 100644
--- a/tests/sys_mman_test.cpp
+++ b/tests/sys_mman_test.cpp
@@ -24,13 +24,13 @@
 #include "TemporaryFile.h"
 
 TEST(sys_mman, mmap_std) {
-  void* map = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
+  void* map = mmap(nullptr, 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_std) {
-  void* map = mmap64(NULL, 4096, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
+  void* map = mmap64(nullptr, 4096, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
   ASSERT_NE(MAP_FAILED, map);
   ASSERT_EQ(0, munmap(map, 4096));
 }
@@ -38,14 +38,14 @@
 TEST(sys_mman, mmap_file_bad_offset) {
   TemporaryFile tf;
 
-  void* map = mmap(NULL, 100, PROT_READ, MAP_SHARED, tf.fd, 1);
+  void* map = mmap(nullptr, 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);
+  void* map = mmap64(nullptr, 100, PROT_READ, MAP_SHARED, tf.fd, 1);
   ASSERT_EQ(MAP_FAILED, map);
 }
 
@@ -59,7 +59,7 @@
 
   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);
+  void* map = mmap(nullptr, sizeof(STRING_MSG), PROT_READ, MAP_SHARED, tf.fd, 0);
   ASSERT_NE(MAP_FAILED, map);
 
   char* data = reinterpret_cast<char*>(map);
@@ -74,7 +74,7 @@
   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);
+  void* map = mmap(nullptr, sizeof(STRING_MSG), PROT_WRITE, MAP_SHARED, tf.fd, 0);
   ASSERT_NE(MAP_FAILED, map);
   close(tf.fd);
 
@@ -110,7 +110,7 @@
 
   ASSERT_NE(-1, lseek(tf.fd, 0, SEEK_SET));
 
-  void* map = mmap(NULL, pagesize, PROT_READ, MAP_SHARED, tf.fd, pagesize);
+  void* map = mmap(nullptr, pagesize, PROT_READ, MAP_SHARED, tf.fd, pagesize);
   ASSERT_NE(MAP_FAILED, map);
 
   char* data = reinterpret_cast<char*>(map);
@@ -118,7 +118,7 @@
 
   ASSERT_EQ(0, munmap(map, pagesize));
 
-  map = mmap(NULL, pagesize, PROT_READ, MAP_SHARED, tf.fd, 2 * pagesize);
+  map = mmap(nullptr, pagesize, PROT_READ, MAP_SHARED, tf.fd, 2 * pagesize);
   ASSERT_NE(MAP_FAILED, map);
 
   data = reinterpret_cast<char*>(map);
@@ -146,7 +146,7 @@
 
   ASSERT_NE(-1, lseek(tf.fd, 0, SEEK_SET));
 
-  void* map = mmap(NULL, pagesize, PROT_WRITE, MAP_SHARED, tf.fd, pagesize);
+  void* map = mmap(nullptr, pagesize, PROT_WRITE, MAP_SHARED, tf.fd, pagesize);
   ASSERT_NE(MAP_FAILED, map);
   close(tf.fd);
 
@@ -154,7 +154,7 @@
   ASSERT_EQ(0, munmap(map, pagesize));
 
   tf.reopen();
-  map = mmap(NULL, pagesize, PROT_WRITE, MAP_SHARED, tf.fd, 2 * pagesize);
+  map = mmap(nullptr, pagesize, PROT_WRITE, MAP_SHARED, tf.fd, 2 * pagesize);
   ASSERT_NE(MAP_FAILED, map);
   close(tf.fd);
 
@@ -181,7 +181,7 @@
 
   // Prepare environment.
   ASSERT_EQ(static_cast<ssize_t>(pagesize), write(tempfile.fd, buf, pagesize));
-  void* map = mmap(NULL, pagesize, PROT_READ | PROT_WRITE, MAP_SHARED, tempfile.fd, 0);
+  void* map = mmap(nullptr, pagesize, PROT_READ | PROT_WRITE, MAP_SHARED, tempfile.fd, 0);
   ASSERT_NE(MAP_FAILED, map);
 
   // Verify different options of posix_madvise.
@@ -199,7 +199,7 @@
 TEST(sys_mman, posix_madvise_POSIX_MADV_DONTNEED) {
   size_t pagesize = sysconf(_SC_PAGESIZE);
 
-  void* map = mmap(NULL, pagesize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+  void* map = mmap(nullptr, pagesize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
   ASSERT_NE(MAP_FAILED, map);
 
   int* int_ptr = reinterpret_cast<int*>(map);
diff --git a/tests/sys_msg_test.cpp b/tests/sys_msg_test.cpp
index 05ad01b..4eb5a14 100644
--- a/tests/sys_msg_test.cpp
+++ b/tests/sys_msg_test.cpp
@@ -71,7 +71,7 @@
   ASSERT_STREQ("hello world", msg.data);
 
   // Destroy the queue.
-  ASSERT_EQ(0, msgctl(id, IPC_RMID, 0));
+  ASSERT_EQ(0, msgctl(id, IPC_RMID, nullptr));
 }
 
 TEST(sys_msg, msgctl_failure) {
diff --git a/tests/sys_select_test.cpp b/tests/sys_select_test.cpp
index 0eab876..5f019e2 100644
--- a/tests/sys_select_test.cpp
+++ b/tests/sys_select_test.cpp
@@ -89,10 +89,10 @@
   int max = STDERR_FILENO + 1;
 
   // Invalid max fd.
-  ASSERT_EQ(-1, select(-1, &r, &w, &e, NULL));
+  ASSERT_EQ(-1, select(-1, &r, &w, &e, nullptr));
   ASSERT_EQ(EINVAL, errno);
 
-  int num_fds = select(max, &r, &w, &e, NULL);
+  int num_fds = select(max, &r, &w, &e, nullptr);
   // If there is data to be read on STDIN, then the number of
   // fds ready will be 3 instead of 2. Allow this case, but verify
   // every fd that is set.
@@ -117,7 +117,7 @@
 
   FD_ZERO(&r);
   FD_SET(fd, &r);
-  ASSERT_EQ(1, select(fd+1, &r, NULL, NULL, &tv));
+  ASSERT_EQ(1, select(fd+1, &r, nullptr, nullptr, &tv));
   // Both tv_sec and tv_nsec should have been updated.
   ASSERT_EQ(0, tv.tv_sec);
   ASSERT_NE(0, tv.tv_usec);
@@ -144,13 +144,13 @@
   int max = STDERR_FILENO + 1;
 
   // Invalid max fd.
-  ASSERT_EQ(-1, pselect(-1, &r, &w, &e, NULL, &ss));
+  ASSERT_EQ(-1, pselect(-1, &r, &w, &e, nullptr, &ss));
   ASSERT_EQ(EINVAL, errno);
 
   // If there is data to be read on STDIN, then the number of
   // fds ready will be 3 instead of 2. Allow this case, but verify
   // every fd that is set.
-  int num_fds = pselect(max, &r, &w, &e, NULL, &ss);
+  int num_fds = pselect(max, &r, &w, &e, nullptr, &ss);
   ASSERT_TRUE(num_fds == 2 || num_fds == 3) << "Num fds returned " << num_fds;
   ASSERT_TRUE(FD_ISSET(STDOUT_FILENO, &w));
   ASSERT_TRUE(FD_ISSET(STDERR_FILENO, &w));
@@ -172,7 +172,7 @@
 
   FD_ZERO(&r);
   FD_SET(fd, &r);
-  ASSERT_EQ(1, pselect(fd+1, &r, NULL, NULL, &tv, NULL));
+  ASSERT_EQ(1, pselect(fd+1, &r, nullptr, nullptr, &tv, nullptr));
   // Neither tv_sec nor tv_nsec should have been updated.
   ASSERT_EQ(1, tv.tv_sec);
   ASSERT_EQ(0, tv.tv_nsec);
diff --git a/tests/sys_shm_test.cpp b/tests/sys_shm_test.cpp
index cf7f3a5..ca2d01a 100644
--- a/tests/sys_shm_test.cpp
+++ b/tests/sys_shm_test.cpp
@@ -52,19 +52,19 @@
   ASSERT_EQ(1234U, ds.shm_segsz);
 
   // Attach.
-  void* p = shmat(id, 0, SHM_RDONLY);
+  void* p = shmat(id, nullptr, SHM_RDONLY);
   ASSERT_NE(p, nullptr);
 
   // Detach.
   ASSERT_EQ(0, shmdt(p));
 
   // Destroy the segment.
-  ASSERT_EQ(0, shmctl(id, IPC_RMID, 0));
+  ASSERT_EQ(0, shmctl(id, IPC_RMID, nullptr));
 }
 
 TEST(sys_shm, shmat_failure) {
   errno = 0;
-  ASSERT_EQ(reinterpret_cast<void*>(-1), shmat(-1, 0, SHM_RDONLY));
+  ASSERT_EQ(reinterpret_cast<void*>(-1), shmat(-1, nullptr, SHM_RDONLY));
   ASSERT_TRUE(errno == EINVAL || errno == ENOSYS);
 }
 
diff --git a/tests/sys_socket_test.cpp b/tests/sys_socket_test.cpp
index 506e01f..0342547 100644
--- a/tests/sys_socket_test.cpp
+++ b/tests/sys_socket_test.cpp
@@ -34,7 +34,7 @@
 static void* ConnectFn(void* data) {
   ConnectData* pdata = reinterpret_cast<ConnectData*>(data);
   bool (*callback_fn)(int) = pdata->callback_fn;
-  void* return_value = NULL;
+  void* return_value = nullptr;
 
   int fd = socket(PF_UNIX, SOCK_SEQPACKET | SOCK_CLOEXEC | SOCK_NONBLOCK, 0);
   if (fd < 0) {
@@ -52,7 +52,7 @@
     GTEST_LOG_(ERROR) << "connect call failed: " << strerror(errno);
     return_value = reinterpret_cast<void*>(-1);
   }
-  else if (callback_fn != NULL && !callback_fn(fd)) {
+  else if (callback_fn != nullptr && !callback_fn(fd)) {
     return_value = reinterpret_cast<void*>(-1);
   }
 
@@ -79,7 +79,7 @@
   ConnectData connect_data(callback_fn, sock_path);
 
   pthread_t thread;
-  ASSERT_EQ(0, pthread_create(&thread, NULL, ConnectFn, &connect_data));
+  ASSERT_EQ(0, pthread_create(&thread, nullptr, ConnectFn, &connect_data));
 
   fd_set read_set;
   FD_ZERO(&read_set);
@@ -87,19 +87,19 @@
   timeval tv;
   tv.tv_sec = 5;
   tv.tv_usec = 0;
-  ASSERT_LT(0, select(fd+1, &read_set, NULL, NULL, &tv));
+  ASSERT_LT(0, select(fd+1, &read_set, nullptr, nullptr, &tv));
 
   test_fn(&addr, fd);
 
   void* ret_val;
   ASSERT_EQ(0, pthread_join(thread, &ret_val));
-  ASSERT_EQ(NULL, ret_val);
+  ASSERT_EQ(nullptr, ret_val);
 
   close(fd);
 }
 
 TEST(sys_socket, accept4_error) {
-  ASSERT_EQ(-1, accept4(-1, NULL, NULL, 0));
+  ASSERT_EQ(-1, accept4(-1, nullptr, nullptr, 0));
   ASSERT_EQ(EBADF, errno);
 }
 
@@ -115,7 +115,7 @@
 }
 
 TEST(sys_socket, accept4_smoke) {
-  RunTest(TestAccept4, NULL, "test_accept");
+  RunTest(TestAccept4, nullptr, "test_accept");
 }
 
 const char* g_RecvMsgs[] = {
@@ -174,7 +174,7 @@
 }
 
 TEST(sys_socket, recvmmsg_error) {
-  ASSERT_EQ(-1, recvmmsg(-1, NULL, 0, 0, NULL));
+  ASSERT_EQ(-1, recvmmsg(-1, nullptr, 0, 0, nullptr));
   ASSERT_EQ(EBADF, errno);
 }
 
@@ -217,7 +217,7 @@
     timeval tv;
     tv.tv_sec = 5;
     tv.tv_usec = 0;
-    ASSERT_LT(0, select(fd_acc+1, &read_set, NULL, NULL, &tv));
+    ASSERT_LT(0, select(fd_acc+1, &read_set, nullptr, nullptr, &tv));
     char buffer[100];
     ASSERT_EQ(strlen(g_SendMsgs[i]) + 1,
               static_cast<size_t>(recv(fd_acc, buffer, sizeof(buffer), 0)));
@@ -232,6 +232,6 @@
 }
 
 TEST(sys_socket, sendmmsg_error) {
-  ASSERT_EQ(-1, sendmmsg(-1, NULL, 0, 0));
+  ASSERT_EQ(-1, sendmmsg(-1, nullptr, 0, 0));
   ASSERT_EQ(EBADF, errno);
 }
diff --git a/tests/sys_stat_test.cpp b/tests/sys_stat_test.cpp
index 7c387ba..c0a576d 100644
--- a/tests/sys_stat_test.cpp
+++ b/tests/sys_stat_test.cpp
@@ -25,7 +25,7 @@
 
 TEST(sys_stat, futimens) {
   FILE* fp = tmpfile();
-  ASSERT_TRUE(fp != NULL);
+  ASSERT_TRUE(fp != nullptr);
 
   int fd = fileno(fp);
   ASSERT_NE(fd, -1);
diff --git a/tests/sys_time_test.cpp b/tests/sys_time_test.cpp
index e041ba0..b3ec161 100644
--- a/tests/sys_time_test.cpp
+++ b/tests/sys_time_test.cpp
@@ -134,9 +134,9 @@
 TEST(sys_time, gettimeofday) {
   // Try to ensure that our vdso gettimeofday is working.
   timeval tv1;
-  ASSERT_EQ(0, gettimeofday(&tv1, NULL));
+  ASSERT_EQ(0, gettimeofday(&tv1, nullptr));
   timeval tv2;
-  ASSERT_EQ(0, syscall(__NR_gettimeofday, &tv2, NULL));
+  ASSERT_EQ(0, syscall(__NR_gettimeofday, &tv2, nullptr));
 
   // What's the difference between the two?
   tv2.tv_sec -= tv1.tv_sec;
diff --git a/tests/sys_xattr_test.cpp b/tests/sys_xattr_test.cpp
index 113ec26..006e840 100644
--- a/tests/sys_xattr_test.cpp
+++ b/tests/sys_xattr_test.cpp
@@ -107,7 +107,7 @@
   ASSERT_EQ(0, fsetxattr(tf.fd, "user.foo", "bar", 4, 0));
   ssize_t result = flistxattr(tf.fd, buf, sizeof(buf));
   ASSERT_TRUE(result >= 9);
-  ASSERT_TRUE(memmem(buf, sizeof(buf), "user.foo", 9) != NULL);
+  ASSERT_TRUE(memmem(buf, sizeof(buf), "user.foo", 9) != nullptr);
 }
 
 TEST(sys_xattr, flistattr_opath) {
@@ -120,7 +120,7 @@
 #if defined(__BIONIC__)
   ASSERT_TRUE(res >= 9);
   ASSERT_TRUE(static_cast<size_t>(res) <= sizeof(buf));
-  ASSERT_TRUE(memmem(buf, res, "user.foo", 9) != NULL);
+  ASSERT_TRUE(memmem(buf, res, "user.foo", 9) != nullptr);
 #else
   ASSERT_EQ(-1, res);
   ASSERT_EQ(EBADF, errno);
diff --git a/tests/time_test.cpp b/tests/time_test.cpp
index 216f846..e82f15d 100644
--- a/tests/time_test.cpp
+++ b/tests/time_test.cpp
@@ -59,7 +59,7 @@
 TEST(time, gmtime) {
   time_t t = 0;
   tm* broken_down = gmtime(&t);
-  ASSERT_TRUE(broken_down != NULL);
+  ASSERT_TRUE(broken_down != nullptr);
   ASSERT_EQ(0, broken_down->tm_sec);
   ASSERT_EQ(0, broken_down->tm_min);
   ASSERT_EQ(0, broken_down->tm_hour);
@@ -86,11 +86,11 @@
   // Ensure we'll actually have to enter tzload by using a time zone that doesn't exist.
   setenv("TZ", "gmtime_stack_overflow_14313703", 1);
   tzset();
-  if (original_tz != NULL) {
+  if (original_tz != nullptr) {
     setenv("TZ", original_tz, 1);
   }
   tzset();
-  return NULL;
+  return nullptr;
 }
 
 TEST(time, gmtime_no_stack_overflow_14313703) {
@@ -102,7 +102,7 @@
   ASSERT_EQ(0, pthread_attr_setstacksize(&a, PTHREAD_STACK_MIN));
 
   pthread_t t;
-  ASSERT_EQ(0, pthread_create(&t, &a, gmtime_no_stack_overflow_14313703_fn, NULL));
+  ASSERT_EQ(0, pthread_create(&t, &a, gmtime_no_stack_overflow_14313703_fn, nullptr));
   ASSERT_EQ(0, pthread_join(t, nullptr));
 }
 
@@ -242,7 +242,7 @@
 }
 
 TEST(time, strftime_l) {
-  locale_t cloc = newlocale(LC_ALL, "C.UTF-8", 0);
+  locale_t cloc = newlocale(LC_ALL, "C.UTF-8", nullptr);
   locale_t old_locale = uselocale(cloc);
 
   setenv("TZ", "UTC", 1);
@@ -302,7 +302,7 @@
   ts.it_value.tv_nsec = value_ns;
   ts.it_interval.tv_sec = interval_s;
   ts.it_interval.tv_nsec = interval_ns;
-  ASSERT_EQ(0, timer_settime(t, 0, &ts, NULL));
+  ASSERT_EQ(0, timer_settime(t, 0, &ts, nullptr));
 }
 
 static void NoOpNotifyFunction(sigval_t) {
@@ -356,7 +356,7 @@
   ts.it_value.tv_nsec = 1;
   ts.it_interval.tv_sec = 0;
   ts.it_interval.tv_nsec = 0;
-  ASSERT_EQ(0, timer_settime(timer_id, 0, &ts, NULL));
+  ASSERT_EQ(0, timer_settime(timer_id, 0, &ts, nullptr));
 
   usleep(500000);
   ASSERT_EQ(1, timer_create_SIGEV_SIGNAL_signal_handler_invocation_count);
@@ -405,8 +405,8 @@
 
   bool ValueUpdated() {
     int current_value = value;
-    time_t start = time(NULL);
-    while (current_value == value && (time(NULL) - start) < 5) {
+    time_t start = time(nullptr);
+    while (current_value == value && (time(nullptr) - start) < 5) {
     }
     return current_value != value;
   }
@@ -458,7 +458,7 @@
 TEST(time, timer_create_NULL) {
   // A NULL sigevent* is equivalent to asking for SIGEV_SIGNAL for SIGALRM.
   timer_t timer_id;
-  ASSERT_EQ(0, timer_create(CLOCK_MONOTONIC, NULL, &timer_id));
+  ASSERT_EQ(0, timer_create(CLOCK_MONOTONIC, nullptr, &timer_id));
 
   timer_create_NULL_signal_handler_invocation_count = 0;
   ScopedSignalHandler ssh(SIGALRM, timer_create_NULL_signal_handler);
@@ -476,7 +476,7 @@
 
   // A SIGEV_SIGNAL timer is easy; the kernel does all that.
   timer_t timer_id;
-  ASSERT_EQ(-1, timer_create(invalid_clock, NULL, &timer_id));
+  ASSERT_EQ(-1, timer_create(invalid_clock, nullptr, &timer_id));
   ASSERT_EQ(EINVAL, errno);
 
   // A SIGEV_THREAD timer is more interesting because we have stuff to clean up.
@@ -490,7 +490,7 @@
 
 TEST(time, timer_delete_multiple) {
   timer_t timer_id;
-  ASSERT_EQ(0, timer_create(CLOCK_MONOTONIC, NULL, &timer_id));
+  ASSERT_EQ(0, timer_create(CLOCK_MONOTONIC, nullptr, &timer_id));
   ASSERT_EQ(0, timer_delete(timer_id));
   ASSERT_EQ(-1, timer_delete(timer_id));
   ASSERT_EQ(EINVAL, errno);
@@ -593,10 +593,10 @@
   ts.it_value.tv_nsec = 0;
   ts.it_interval.tv_sec = 0;
   ts.it_interval.tv_nsec = 0;
-  ASSERT_EQ(0, timer_settime(tdd.timer_id, 0, &ts, NULL));
+  ASSERT_EQ(0, timer_settime(tdd.timer_id, 0, &ts, nullptr));
 
-  time_t cur_time = time(NULL);
-  while (!tdd.complete && (time(NULL) - cur_time) < 5);
+  time_t cur_time = time(nullptr);
+  while (!tdd.complete && (time(nullptr) - cur_time) < 5);
   ASSERT_TRUE(tdd.complete);
 
 #if defined(__BIONIC__)
diff --git a/tests/uchar_test.cpp b/tests/uchar_test.cpp
index 2b4c4d3..522d5ac 100644
--- a/tests/uchar_test.cpp
+++ b/tests/uchar_test.cpp
@@ -49,19 +49,19 @@
 
   // Any non-initial state is invalid when calling c32rtomb.
   memset(&ps, 0, sizeof(ps));
-  EXPECT_EQ(static_cast<size_t>(-2), mbrtoc32(NULL, "\xc2", 1, &ps));
+  EXPECT_EQ(static_cast<size_t>(-2), mbrtoc32(nullptr, "\xc2", 1, &ps));
   EXPECT_EQ(static_cast<size_t>(-1), c32rtomb(out, 0x00a2, &ps));
   EXPECT_EQ(EILSEQ, errno);
 
-  // If the first argument to c32rtomb is NULL or the second is L'\0' the shift
+  // If the first argument to c32rtomb is nullptr or the second is L'\0' the shift
   // state should be reset.
   memset(&ps, 0, sizeof(ps));
-  EXPECT_EQ(static_cast<size_t>(-2), mbrtoc32(NULL, "\xc2", 1, &ps));
-  EXPECT_EQ(1U, c32rtomb(NULL, 0x00a2, &ps));
+  EXPECT_EQ(static_cast<size_t>(-2), mbrtoc32(nullptr, "\xc2", 1, &ps));
+  EXPECT_EQ(1U, c32rtomb(nullptr, 0x00a2, &ps));
   EXPECT_TRUE(mbsinit(&ps));
 
   memset(&ps, 0, sizeof(ps));
-  EXPECT_EQ(static_cast<size_t>(-2), mbrtoc32(NULL, "\xf0\xa4", 1, &ps));
+  EXPECT_EQ(static_cast<size_t>(-2), mbrtoc32(nullptr, "\xf0\xa4", 1, &ps));
   EXPECT_EQ(1U, c32rtomb(out, L'\0', &ps));
   EXPECT_TRUE(mbsinit(&ps));
 #else
@@ -71,8 +71,8 @@
 
 TEST(uchar, c16rtomb_null_out) {
 #if HAVE_UCHAR
-  EXPECT_EQ(1U, c16rtomb(NULL, L'\0', NULL));
-  EXPECT_EQ(1U, c16rtomb(NULL, L'h', NULL));
+  EXPECT_EQ(1U, c16rtomb(nullptr, L'\0', nullptr));
+  EXPECT_EQ(1U, c16rtomb(nullptr, L'h', nullptr));
 #else
   GTEST_LOG_(INFO) << "uchar.h is unavailable.\n";
 #endif
@@ -81,7 +81,7 @@
 TEST(uchar, c16rtomb_null_char) {
 #if HAVE_UCHAR
   char bytes[MB_LEN_MAX];
-  EXPECT_EQ(1U, c16rtomb(bytes, L'\0', NULL));
+  EXPECT_EQ(1U, c16rtomb(bytes, L'\0', nullptr));
 #else
   GTEST_LOG_(INFO) << "uchar.h is unavailable.\n";
 #endif
@@ -92,7 +92,7 @@
   char bytes[MB_LEN_MAX];
 
   memset(bytes, 0, sizeof(bytes));
-  EXPECT_EQ(1U, c16rtomb(bytes, L'h', NULL));
+  EXPECT_EQ(1U, c16rtomb(bytes, L'h', nullptr));
   EXPECT_EQ('h', bytes[0]);
 
   ASSERT_STREQ("C.UTF-8", setlocale(LC_CTYPE, "C.UTF-8"));
@@ -100,16 +100,16 @@
 
   // 1-byte UTF-8.
   memset(bytes, 0, sizeof(bytes));
-  EXPECT_EQ(1U, c16rtomb(bytes, L'h', NULL));
+  EXPECT_EQ(1U, c16rtomb(bytes, L'h', nullptr));
   EXPECT_EQ('h', bytes[0]);
   // 2-byte UTF-8.
   memset(bytes, 0, sizeof(bytes));
-  EXPECT_EQ(2U, c16rtomb(bytes, 0x00a2, NULL));
+  EXPECT_EQ(2U, c16rtomb(bytes, 0x00a2, nullptr));
   EXPECT_EQ('\xc2', bytes[0]);
   EXPECT_EQ('\xa2', bytes[1]);
   // 3-byte UTF-8.
   memset(bytes, 0, sizeof(bytes));
-  EXPECT_EQ(3U, c16rtomb(bytes, 0x20ac, NULL));
+  EXPECT_EQ(3U, c16rtomb(bytes, 0x20ac, nullptr));
   EXPECT_EQ('\xe2', bytes[0]);
   EXPECT_EQ('\x82', bytes[1]);
   EXPECT_EQ('\xac', bytes[2]);
@@ -123,8 +123,8 @@
   char bytes[MB_LEN_MAX];
 
   memset(bytes, 0, sizeof(bytes));
-  EXPECT_EQ(0U, c16rtomb(bytes, 0xdbea, NULL));
-  EXPECT_EQ(4U, c16rtomb(bytes, 0xdfcd, NULL));
+  EXPECT_EQ(0U, c16rtomb(bytes, 0xdbea, nullptr));
+  EXPECT_EQ(4U, c16rtomb(bytes, 0xdfcd, nullptr));
   EXPECT_EQ('\xf4', bytes[0]);
   EXPECT_EQ('\x8a', bytes[1]);
   EXPECT_EQ('\xaf', bytes[2]);
@@ -139,10 +139,10 @@
   char bytes[MB_LEN_MAX];
 
   memset(bytes, 0, sizeof(bytes));
-  EXPECT_EQ(static_cast<size_t>(-1), c16rtomb(bytes, 0xdfcd, NULL));
+  EXPECT_EQ(static_cast<size_t>(-1), c16rtomb(bytes, 0xdfcd, nullptr));
 
-  EXPECT_EQ(0U, c16rtomb(bytes, 0xdbea, NULL));
-  EXPECT_EQ(static_cast<size_t>(-1), c16rtomb(bytes, 0xdbea, NULL));
+  EXPECT_EQ(0U, c16rtomb(bytes, 0xdbea, nullptr));
+  EXPECT_EQ(static_cast<size_t>(-1), c16rtomb(bytes, 0xdbea, nullptr));
 #else
   GTEST_LOG_(INFO) << "uchar.h is unavailable.\n";
 #endif
@@ -150,7 +150,7 @@
 
 TEST(uchar, mbrtoc16_null) {
 #if HAVE_UCHAR
-  ASSERT_EQ(0U, mbrtoc16(NULL, NULL, 0, NULL));
+  ASSERT_EQ(0U, mbrtoc16(nullptr, nullptr, 0, nullptr));
 #else
   GTEST_LOG_(INFO) << "uchar.h is unavailable.\n";
 #endif
@@ -161,12 +161,12 @@
   char16_t out;
 
   out = L'x';
-  ASSERT_EQ(0U, mbrtoc16(&out, "hello", 0, NULL));
+  ASSERT_EQ(0U, mbrtoc16(&out, "hello", 0, nullptr));
   ASSERT_EQ(L'x', out);
 
-  ASSERT_EQ(0U, mbrtoc16(&out, "hello", 0, NULL));
-  ASSERT_EQ(0U, mbrtoc16(&out, "", 0, NULL));
-  ASSERT_EQ(1U, mbrtoc16(&out, "hello", 1, NULL));
+  ASSERT_EQ(0U, mbrtoc16(&out, "hello", 0, nullptr));
+  ASSERT_EQ(0U, mbrtoc16(&out, "", 0, nullptr));
+  ASSERT_EQ(1U, mbrtoc16(&out, "hello", 1, nullptr));
   ASSERT_EQ(L'h', out);
 #else
   GTEST_LOG_(INFO) << "uchar.h is unavailable.\n";
@@ -181,13 +181,13 @@
   uselocale(LC_GLOBAL_LOCALE);
 
   // 1-byte UTF-8.
-  ASSERT_EQ(1U, mbrtoc16(&out, "abcdef", 6, NULL));
+  ASSERT_EQ(1U, mbrtoc16(&out, "abcdef", 6, nullptr));
   ASSERT_EQ(L'a', out);
   // 2-byte UTF-8.
-  ASSERT_EQ(2U, mbrtoc16(&out, "\xc2\xa2" "cdef", 6, NULL));
+  ASSERT_EQ(2U, mbrtoc16(&out, "\xc2\xa2" "cdef", 6, nullptr));
   ASSERT_EQ(static_cast<char16_t>(0x00a2), out);
   // 3-byte UTF-8.
-  ASSERT_EQ(3U, mbrtoc16(&out, "\xe2\x82\xac" "def", 6, NULL));
+  ASSERT_EQ(3U, mbrtoc16(&out, "\xe2\x82\xac" "def", 6, nullptr));
   ASSERT_EQ(static_cast<char16_t>(0x20ac), out);
 #else
   GTEST_LOG_(INFO) << "uchar.h is unavailable.\n";
@@ -199,9 +199,9 @@
   char16_t out;
 
   ASSERT_EQ(static_cast<size_t>(-3),
-            mbrtoc16(&out, "\xf4\x8a\xaf\x8d", 6, NULL));
+            mbrtoc16(&out, "\xf4\x8a\xaf\x8d", 6, nullptr));
   ASSERT_EQ(static_cast<char16_t>(0xdbea), out);
-  ASSERT_EQ(4U, mbrtoc16(&out, "\xf4\x8a\xaf\x8d" "ef", 6, NULL));
+  ASSERT_EQ(4U, mbrtoc16(&out, "\xf4\x8a\xaf\x8d" "ef", 6, nullptr));
   ASSERT_EQ(static_cast<char16_t>(0xdfcd), out);
 #else
   GTEST_LOG_(INFO) << "uchar.h is unavailable.\n";
@@ -212,7 +212,7 @@
 #if HAVE_UCHAR
   char16_t out;
   ASSERT_EQ(static_cast<size_t>(-1),
-            mbrtoc16(&out, "\xf0\x80\xbf\xbf", 6, NULL));
+            mbrtoc16(&out, "\xf0\x80\xbf\xbf", 6, nullptr));
 #else
   GTEST_LOG_(INFO) << "uchar.h is unavailable.\n";
 #endif
@@ -222,7 +222,7 @@
 #if HAVE_UCHAR
   char16_t out;
   ASSERT_EQ(static_cast<size_t>(-1),
-            mbrtoc16(&out, "\xf5\x80\x80\x80", 6, NULL));
+            mbrtoc16(&out, "\xf5\x80\x80\x80", 6, nullptr));
 #else
   GTEST_LOG_(INFO) << "uchar.h is unavailable.\n";
 #endif
@@ -267,7 +267,7 @@
   memset(&ps, 0, sizeof(ps));
 
   test_mbrtoc16_incomplete(&ps);
-  test_mbrtoc16_incomplete(NULL);
+  test_mbrtoc16_incomplete(nullptr);
 #else
   GTEST_LOG_(INFO) << "uchar.h is unavailable.\n";
 #endif
@@ -275,18 +275,18 @@
 
 TEST(uchar, c32rtomb) {
 #if HAVE_UCHAR
-  EXPECT_EQ(1U, c32rtomb(NULL, L'\0', NULL));
-  EXPECT_EQ(1U, c32rtomb(NULL, L'h', NULL));
+  EXPECT_EQ(1U, c32rtomb(nullptr, L'\0', nullptr));
+  EXPECT_EQ(1U, c32rtomb(nullptr, L'h', nullptr));
 
   char bytes[MB_LEN_MAX];
 
   memset(bytes, 1, sizeof(bytes));
-  EXPECT_EQ(1U, c32rtomb(bytes, L'\0', NULL));
+  EXPECT_EQ(1U, c32rtomb(bytes, L'\0', nullptr));
   EXPECT_EQ('\0', bytes[0]);
   EXPECT_EQ('\x01', bytes[1]);
 
   memset(bytes, 0, sizeof(bytes));
-  EXPECT_EQ(1U, c32rtomb(bytes, L'h', NULL));
+  EXPECT_EQ(1U, c32rtomb(bytes, L'h', nullptr));
   EXPECT_EQ('h', bytes[0]);
 
   ASSERT_STREQ("C.UTF-8", setlocale(LC_CTYPE, "C.UTF-8"));
@@ -294,28 +294,28 @@
 
   // 1-byte UTF-8.
   memset(bytes, 0, sizeof(bytes));
-  EXPECT_EQ(1U, c32rtomb(bytes, L'h', NULL));
+  EXPECT_EQ(1U, c32rtomb(bytes, L'h', nullptr));
   EXPECT_EQ('h', bytes[0]);
   // 2-byte UTF-8.
   memset(bytes, 0, sizeof(bytes));
-  EXPECT_EQ(2U, c32rtomb(bytes, 0x00a2, NULL));
+  EXPECT_EQ(2U, c32rtomb(bytes, 0x00a2, nullptr));
   EXPECT_EQ('\xc2', bytes[0]);
   EXPECT_EQ('\xa2', bytes[1]);
   // 3-byte UTF-8.
   memset(bytes, 0, sizeof(bytes));
-  EXPECT_EQ(3U, c32rtomb(bytes, 0x20ac, NULL));
+  EXPECT_EQ(3U, c32rtomb(bytes, 0x20ac, nullptr));
   EXPECT_EQ('\xe2', bytes[0]);
   EXPECT_EQ('\x82', bytes[1]);
   EXPECT_EQ('\xac', bytes[2]);
   // 4-byte UTF-8.
   memset(bytes, 0, sizeof(bytes));
-  EXPECT_EQ(4U, c32rtomb(bytes, 0x24b62, NULL));
+  EXPECT_EQ(4U, c32rtomb(bytes, 0x24b62, nullptr));
   EXPECT_EQ('\xf0', bytes[0]);
   EXPECT_EQ('\xa4', bytes[1]);
   EXPECT_EQ('\xad', bytes[2]);
   EXPECT_EQ('\xa2', bytes[3]);
   // Invalid code point.
-  EXPECT_EQ(static_cast<size_t>(-1), c32rtomb(bytes, 0xffffffff, NULL));
+  EXPECT_EQ(static_cast<size_t>(-1), c32rtomb(bytes, 0xffffffff, nullptr));
   EXPECT_EQ(EILSEQ, errno);
 #else
   GTEST_LOG_(INFO) << "uchar.h is unavailable.\n";
@@ -356,42 +356,42 @@
   char32_t out[8];
 
   out[0] = L'x';
-  ASSERT_EQ(0U, mbrtoc32(out, "hello", 0, NULL));
+  ASSERT_EQ(0U, mbrtoc32(out, "hello", 0, nullptr));
   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(0U, mbrtoc32(out, "hello", 0, nullptr));
+  ASSERT_EQ(0U, mbrtoc32(out, "", 0, nullptr));
+  ASSERT_EQ(1U, mbrtoc32(out, "hello", 1, nullptr));
   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));
-  ASSERT_EQ(1U, mbrtoc32(NULL, "hello", 1, NULL));
+  ASSERT_EQ(0U, mbrtoc32(nullptr, "hello", 0, nullptr));
+  ASSERT_EQ(0U, mbrtoc32(nullptr, "", 0, nullptr));
+  ASSERT_EQ(1U, mbrtoc32(nullptr, "hello", 1, nullptr));
 
-  ASSERT_EQ(0U, mbrtoc32(NULL, NULL, 0, NULL));
+  ASSERT_EQ(0U, mbrtoc32(nullptr, nullptr, 0, nullptr));
 
   ASSERT_STREQ("C.UTF-8", setlocale(LC_CTYPE, "C.UTF-8"));
   uselocale(LC_GLOBAL_LOCALE);
 
   // 1-byte UTF-8.
-  ASSERT_EQ(1U, mbrtoc32(out, "abcdef", 6, NULL));
+  ASSERT_EQ(1U, mbrtoc32(out, "abcdef", 6, nullptr));
   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(2U, mbrtoc32(out, "\xc2\xa2" "cdef", 6, nullptr));
   ASSERT_EQ(static_cast<char32_t>(0x00a2), out[0]);
   // 3-byte UTF-8.
-  ASSERT_EQ(3U, mbrtoc32(out, "\xe2\x82\xac" "def", 6, NULL));
+  ASSERT_EQ(3U, mbrtoc32(out, "\xe2\x82\xac" "def", 6, nullptr));
   ASSERT_EQ(static_cast<char32_t>(0x20ac), out[0]);
   // 4-byte UTF-8.
-  ASSERT_EQ(4U, mbrtoc32(out, "\xf0\xa4\xad\xa2" "ef", 6, NULL));
+  ASSERT_EQ(4U, mbrtoc32(out, "\xf0\xa4\xad\xa2" "ef", 6, nullptr));
   ASSERT_EQ(static_cast<char32_t>(0x24b62), out[0]);
 #if defined(__BIONIC__) // glibc allows this.
   // Illegal 5-byte UTF-8.
-  ASSERT_EQ(static_cast<size_t>(-1), mbrtoc32(out, "\xf8\xa1\xa2\xa3\xa4" "f", 6, NULL));
+  ASSERT_EQ(static_cast<size_t>(-1), mbrtoc32(out, "\xf8\xa1\xa2\xa3\xa4" "f", 6, nullptr));
   ASSERT_EQ(EILSEQ, errno);
 #endif
   // Illegal over-long sequence.
-  ASSERT_EQ(static_cast<size_t>(-1), mbrtoc32(out, "\xf0\x82\x82\xac" "ef", 6, NULL));
+  ASSERT_EQ(static_cast<size_t>(-1), mbrtoc32(out, "\xf0\x82\x82\xac" "ef", 6, nullptr));
   ASSERT_EQ(EILSEQ, errno);
 #else
   GTEST_LOG_(INFO) << "uchar.h is unavailable.\n";
@@ -435,7 +435,7 @@
   memset(&ps, 0, sizeof(ps));
 
   test_mbrtoc32_incomplete(&ps);
-  test_mbrtoc32_incomplete(NULL);
+  test_mbrtoc32_incomplete(nullptr);
 #else
   GTEST_LOG_(INFO) << "uchar.h is unavailable.\n";
 #endif
diff --git a/tests/unistd_test.cpp b/tests/unistd_test.cpp
index fd99455..1f7f555 100644
--- a/tests/unistd_test.cpp
+++ b/tests/unistd_test.cpp
@@ -273,7 +273,7 @@
   ASSERT_EQ(0, setenv("test-variable", "hello", 1));
   ASSERT_STREQ("hello", getenv("test-variable"));
   ASSERT_EQ(0, unsetenv("test-variable"));
-  ASSERT_TRUE(getenv("test-variable") == NULL);
+  ASSERT_TRUE(getenv("test-variable") == nullptr);
 }
 
 TEST(UNISTD_TEST, unsetenv_EINVAL) {
@@ -284,9 +284,9 @@
 }
 
 TEST(UNISTD_TEST, setenv_EINVAL) {
-  EXPECT_EQ(-1, setenv(NULL, "value", 0));
+  EXPECT_EQ(-1, setenv(nullptr, "value", 0));
   EXPECT_EQ(EINVAL, errno);
-  EXPECT_EQ(-1, setenv(NULL, "value", 1));
+  EXPECT_EQ(-1, setenv(nullptr, "value", 1));
   EXPECT_EQ(EINVAL, errno);
   EXPECT_EQ(-1, setenv("", "value", 0));
   EXPECT_EQ(EINVAL, errno);
@@ -353,14 +353,14 @@
 
   // Stash a copy.
   std::vector<char*> old_environ;
-  for (size_t i = 0; environ[i] != NULL; ++i) {
+  for (size_t i = 0; environ[i] != nullptr; ++i) {
     old_environ.push_back(strdup(environ[i]));
   }
 
   ASSERT_EQ(0, clearenv());
 
-  EXPECT_TRUE(environ == NULL || environ[0] == NULL);
-  EXPECT_EQ(NULL, getenv("test-variable"));
+  EXPECT_TRUE(environ == nullptr || environ[0] == nullptr);
+  EXPECT_EQ(nullptr, getenv("test-variable"));
   EXPECT_EQ(0, setenv("test-variable", "post-clear", 1));
   EXPECT_STREQ("post-clear", getenv("test-variable"));
 
@@ -539,7 +539,7 @@
 
 static int CloneStartRoutine(int (*start_routine)(void*)) {
   void* child_stack[1024];
-  return clone(start_routine, &child_stack[1024], SIGCHLD, NULL);
+  return clone(start_routine, &child_stack[1024], SIGCHLD, nullptr);
 }
 
 static int GetPidCachingCloneStartRoutine(void*) {
@@ -594,20 +594,20 @@
 
 static void* GetPidCachingPthreadStartRoutine(void*) {
   AssertGetPidCorrect();
-  return NULL;
+  return nullptr;
 }
 
 TEST(UNISTD_TEST, getpid_caching_and_pthread_create) {
   pid_t parent_pid = getpid();
 
   pthread_t t;
-  ASSERT_EQ(0, pthread_create(&t, NULL, GetPidCachingPthreadStartRoutine, NULL));
+  ASSERT_EQ(0, pthread_create(&t, nullptr, GetPidCachingPthreadStartRoutine, nullptr));
 
   ASSERT_EQ(parent_pid, getpid());
 
   void* result;
   ASSERT_EQ(0, pthread_join(t, &result));
-  ASSERT_EQ(NULL, result);
+  ASSERT_EQ(nullptr, result);
 }
 
 static void* GetTidCachingPthreadStartRoutine(void*) {
@@ -620,7 +620,7 @@
   pid_t parent_tid = GetTidForTest();
 
   pthread_t t;
-  ASSERT_EQ(0, pthread_create(&t, NULL, GetTidCachingPthreadStartRoutine, &parent_tid));
+  ASSERT_EQ(0, pthread_create(&t, nullptr, GetTidCachingPthreadStartRoutine, &parent_tid));
 
   ASSERT_EQ(parent_tid, GetTidForTest());
 
diff --git a/tests/wchar_test.cpp b/tests/wchar_test.cpp
index e2def07..9aef800 100644
--- a/tests/wchar_test.cpp
+++ b/tests/wchar_test.cpp
@@ -35,32 +35,32 @@
 
 TEST(wchar, mbrlen) {
   char bytes[] = { 'h', 'e', 'l', 'l', 'o', '\0' };
-  EXPECT_EQ(0U, mbrlen(&bytes[0], 0, NULL));
-  EXPECT_EQ(1U, mbrlen(&bytes[0], 1, NULL));
+  EXPECT_EQ(0U, mbrlen(&bytes[0], 0, nullptr));
+  EXPECT_EQ(1U, mbrlen(&bytes[0], 1, nullptr));
 
-  EXPECT_EQ(1U, mbrlen(&bytes[4], 1, NULL));
-  EXPECT_EQ(0U, mbrlen(&bytes[5], 1, NULL));
+  EXPECT_EQ(1U, mbrlen(&bytes[4], 1, nullptr));
+  EXPECT_EQ(0U, mbrlen(&bytes[5], 1, nullptr));
 }
 
 TEST(wchar, wctomb_wcrtomb) {
   // wctomb and wcrtomb behave differently when s == NULL.
-  EXPECT_EQ(0, wctomb(NULL, L'h'));
-  EXPECT_EQ(0, wctomb(NULL, L'\0'));
-  EXPECT_EQ(1U, wcrtomb(NULL, L'\0', NULL));
-  EXPECT_EQ(1U, wcrtomb(NULL, L'h', NULL));
+  EXPECT_EQ(0, wctomb(nullptr, L'h'));
+  EXPECT_EQ(0, wctomb(nullptr, L'\0'));
+  EXPECT_EQ(1U, wcrtomb(nullptr, L'\0', nullptr));
+  EXPECT_EQ(1U, wcrtomb(nullptr, L'h', nullptr));
 
   char bytes[MB_LEN_MAX];
 
   // wctomb and wcrtomb behave similarly for the null wide character.
   EXPECT_EQ(1, wctomb(bytes, L'\0'));
-  EXPECT_EQ(1U, wcrtomb(bytes, L'\0', NULL));
+  EXPECT_EQ(1U, wcrtomb(bytes, L'\0', nullptr));
 
   // ...and for regular characters.
   memset(bytes, 0, sizeof(bytes));
   EXPECT_EQ(1, wctomb(bytes, L'h'));
   EXPECT_EQ('h', bytes[0]);
   memset(bytes, 0, sizeof(bytes));
-  EXPECT_EQ(1U, wcrtomb(bytes, L'h', NULL));
+  EXPECT_EQ(1U, wcrtomb(bytes, L'h', nullptr));
   EXPECT_EQ('h', bytes[0]);
 
   ASSERT_STREQ("C.UTF-8", setlocale(LC_CTYPE, "C.UTF-8"));
@@ -68,28 +68,28 @@
 
   // 1-byte UTF-8.
   memset(bytes, 0, sizeof(bytes));
-  EXPECT_EQ(1U, wcrtomb(bytes, L'h', NULL));
+  EXPECT_EQ(1U, wcrtomb(bytes, L'h', nullptr));
   EXPECT_EQ('h', bytes[0]);
   // 2-byte UTF-8.
   memset(bytes, 0, sizeof(bytes));
-  EXPECT_EQ(2U, wcrtomb(bytes, 0x00a2, NULL));
+  EXPECT_EQ(2U, wcrtomb(bytes, 0x00a2, nullptr));
   EXPECT_EQ('\xc2', bytes[0]);
   EXPECT_EQ('\xa2', bytes[1]);
   // 3-byte UTF-8.
   memset(bytes, 0, sizeof(bytes));
-  EXPECT_EQ(3U, wcrtomb(bytes, 0x20ac, NULL));
+  EXPECT_EQ(3U, wcrtomb(bytes, 0x20ac, nullptr));
   EXPECT_EQ('\xe2', bytes[0]);
   EXPECT_EQ('\x82', bytes[1]);
   EXPECT_EQ('\xac', bytes[2]);
   // 4-byte UTF-8.
   memset(bytes, 0, sizeof(bytes));
-  EXPECT_EQ(4U, wcrtomb(bytes, 0x24b62, NULL));
+  EXPECT_EQ(4U, wcrtomb(bytes, 0x24b62, nullptr));
   EXPECT_EQ('\xf0', bytes[0]);
   EXPECT_EQ('\xa4', bytes[1]);
   EXPECT_EQ('\xad', bytes[2]);
   EXPECT_EQ('\xa2', bytes[3]);
   // Invalid code point.
-  EXPECT_EQ(static_cast<size_t>(-1), wcrtomb(bytes, 0xffffffff, NULL));
+  EXPECT_EQ(static_cast<size_t>(-1), wcrtomb(bytes, 0xffffffff, nullptr));
   EXPECT_EQ(EILSEQ, errno);
 }
 
@@ -99,19 +99,19 @@
 
   // Any non-initial state is invalid when calling wcrtomb.
   memset(&ps, 0, sizeof(ps));
-  EXPECT_EQ(static_cast<size_t>(-2), mbrtowc(NULL, "\xc2", 1, &ps));
+  EXPECT_EQ(static_cast<size_t>(-2), mbrtowc(nullptr, "\xc2", 1, &ps));
   EXPECT_EQ(static_cast<size_t>(-1), wcrtomb(out, 0x00a2, &ps));
   EXPECT_EQ(EILSEQ, errno);
 
   // If the first argument to wcrtomb is NULL or the second is L'\0' the shift
   // state should be reset.
   memset(&ps, 0, sizeof(ps));
-  EXPECT_EQ(static_cast<size_t>(-2), mbrtowc(NULL, "\xc2", 1, &ps));
-  EXPECT_EQ(1U, wcrtomb(NULL, 0x00a2, &ps));
+  EXPECT_EQ(static_cast<size_t>(-2), mbrtowc(nullptr, "\xc2", 1, &ps));
+  EXPECT_EQ(1U, wcrtomb(nullptr, 0x00a2, &ps));
   EXPECT_TRUE(mbsinit(&ps));
 
   memset(&ps, 0, sizeof(ps));
-  EXPECT_EQ(static_cast<size_t>(-2), mbrtowc(NULL, "\xf0\xa4", 1, &ps));
+  EXPECT_EQ(static_cast<size_t>(-2), mbrtowc(nullptr, "\xf0\xa4", 1, &ps));
   EXPECT_EQ(1U, wcrtomb(out, L'\0', &ps));
   EXPECT_TRUE(mbsinit(&ps));
 }
@@ -123,37 +123,37 @@
   char bytes[BUFSIZ];
 
   // Given a NULL destination, these functions count valid characters.
-  EXPECT_EQ(5U, wcstombs(NULL, chars, 0));
-  EXPECT_EQ(5U, wcstombs(NULL, chars, 4));
-  EXPECT_EQ(5U, wcstombs(NULL, chars, 256));
+  EXPECT_EQ(5U, wcstombs(nullptr, chars, 0));
+  EXPECT_EQ(5U, wcstombs(nullptr, chars, 4));
+  EXPECT_EQ(5U, wcstombs(nullptr, chars, 256));
   src = chars;
-  EXPECT_EQ(5U, wcsrtombs(NULL, &src, 0, NULL));
+  EXPECT_EQ(5U, wcsrtombs(nullptr, &src, 0, nullptr));
   EXPECT_EQ(&chars[0], src);
   src = chars;
-  EXPECT_EQ(5U, wcsrtombs(NULL, &src, 4, NULL));
+  EXPECT_EQ(5U, wcsrtombs(nullptr, &src, 4, nullptr));
   EXPECT_EQ(&chars[0], src);
   src = chars;
-  EXPECT_EQ(5U, wcsrtombs(NULL, &src, 256, NULL));
+  EXPECT_EQ(5U, wcsrtombs(nullptr, &src, 256, nullptr));
   EXPECT_EQ(&chars[0], src);
 
   // An unrepresentable char just returns an error from wcstombs...
   errno = 0;
-  EXPECT_EQ(static_cast<size_t>(-1), wcstombs(NULL, bad_chars, 0));
+  EXPECT_EQ(static_cast<size_t>(-1), wcstombs(nullptr, bad_chars, 0));
   EXPECT_EQ(EILSEQ, errno);
   errno = 0;
-  EXPECT_EQ(static_cast<size_t>(-1), wcstombs(NULL, bad_chars, 256));
+  EXPECT_EQ(static_cast<size_t>(-1), wcstombs(nullptr, bad_chars, 256));
   EXPECT_EQ(EILSEQ, errno);
 
   // And wcsrtombs doesn't tell us where it got stuck because we didn't ask it
   // to actually convert anything...
   errno = 0;
   src = bad_chars;
-  EXPECT_EQ(static_cast<size_t>(-1), wcsrtombs(NULL, &src, 0, NULL));
+  EXPECT_EQ(static_cast<size_t>(-1), wcsrtombs(nullptr, &src, 0, nullptr));
   EXPECT_EQ(&bad_chars[0], src);
   EXPECT_EQ(EILSEQ, errno);
   errno = 0;
   src = bad_chars;
-  EXPECT_EQ(static_cast<size_t>(-1), wcsrtombs(NULL, &src, 256, NULL));
+  EXPECT_EQ(static_cast<size_t>(-1), wcsrtombs(nullptr, &src, 256, nullptr));
   EXPECT_EQ(&bad_chars[0], src);
   EXPECT_EQ(EILSEQ, errno);
 
@@ -180,13 +180,13 @@
   // wcsrtombs is a bit more informative...
   memset(bytes, 'x', sizeof(bytes));
   src = chars;
-  EXPECT_EQ(0U, wcsrtombs(bytes, &src, 0, NULL));
+  EXPECT_EQ(0U, wcsrtombs(bytes, &src, 0, nullptr));
   EXPECT_EQ(&chars[0], src); // No input consumed.
   EXPECT_EQ(EILSEQ, errno);
 
   memset(bytes, 'x', sizeof(bytes));
   src = chars;
-  EXPECT_EQ(4U, wcsrtombs(bytes, &src, 4, NULL));
+  EXPECT_EQ(4U, wcsrtombs(bytes, &src, 4, nullptr));
   EXPECT_EQ(&chars[4], src); // Some input consumed.
   EXPECT_EQ(EILSEQ, errno);
   bytes[5] = 0;
@@ -194,21 +194,21 @@
 
   memset(bytes, 'x', sizeof(bytes));
   src = chars;
-  EXPECT_EQ(5U, wcsrtombs(bytes, &src, 256, NULL));
-  EXPECT_EQ(NULL, src); // All input consumed!
+  EXPECT_EQ(5U, wcsrtombs(bytes, &src, 256, nullptr));
+  EXPECT_EQ(nullptr, src); // All input consumed!
   EXPECT_EQ(EILSEQ, errno);
   EXPECT_STREQ("hello", bytes);
 
   memset(bytes, 'x', sizeof(bytes));
   src = chars;
-  EXPECT_EQ(5U, wcsrtombs(bytes, &src, 6, NULL));
-  EXPECT_EQ(NULL, src); // All input consumed.
+  EXPECT_EQ(5U, wcsrtombs(bytes, &src, 6, nullptr));
+  EXPECT_EQ(nullptr, src); // All input consumed.
   EXPECT_EQ(EILSEQ, errno);
   EXPECT_STREQ("hello", bytes);
 
   memset(bytes, 'x', sizeof(bytes));
   src = bad_chars;
-  EXPECT_EQ(static_cast<size_t>(-1), wcsrtombs(bytes, &src, 256, NULL));
+  EXPECT_EQ(static_cast<size_t>(-1), wcsrtombs(bytes, &src, 256, nullptr));
   EXPECT_EQ(&bad_chars[2], src);
   EXPECT_EQ(EILSEQ, errno);
   bytes[3] = 0;
@@ -218,8 +218,8 @@
   mbstate_t ps;
   src = chars;
   memset(&ps, 0, sizeof(ps));
-  ASSERT_EQ(static_cast<size_t>(-2), mbrtowc(NULL, "\xc2", 1, &ps));
-  EXPECT_EQ(static_cast<size_t>(-1), wcsrtombs(NULL, &src, 0, &ps));
+  ASSERT_EQ(static_cast<size_t>(-2), mbrtowc(nullptr, "\xc2", 1, &ps));
+  EXPECT_EQ(static_cast<size_t>(-1), wcsrtombs(nullptr, &src, 0, &ps));
   EXPECT_EQ(EILSEQ, errno);
 }
 
@@ -235,12 +235,12 @@
 
   ASSERT_EQ(haystack, wcsstr(haystack, empty_needle));
   ASSERT_EQ(&haystack[10], wcsstr(haystack, good_needle));
-  ASSERT_EQ(NULL, wcsstr(haystack, bad_needle));
+  ASSERT_EQ(nullptr, wcsstr(haystack, bad_needle));
 }
 
 TEST(wchar, wcsstr_80199) {
   // https://code.google.com/p/android/issues/detail?id=80199
-  ASSERT_TRUE(wcsstr(L"romrom", L"rom") != NULL);
+  ASSERT_TRUE(wcsstr(L"romrom", L"rom") != nullptr);
 }
 
 TEST(wchar, mbtowc) {
@@ -255,53 +255,53 @@
   ASSERT_EQ(1, mbtowc(out, "hello", 1));
   ASSERT_EQ(L'h', out[0]);
 
-  ASSERT_EQ(0, mbtowc(NULL, "hello", 0));
-  ASSERT_EQ(0, mbtowc(NULL, "", 0));
-  ASSERT_EQ(1, mbtowc(NULL, "hello", 1));
+  ASSERT_EQ(0, mbtowc(nullptr, "hello", 0));
+  ASSERT_EQ(0, mbtowc(nullptr, "", 0));
+  ASSERT_EQ(1, mbtowc(nullptr, "hello", 1));
 
-  ASSERT_EQ(0, mbtowc(NULL, NULL, 0));
+  ASSERT_EQ(0, mbtowc(nullptr, nullptr, 0));
 }
 
 TEST(wchar, mbrtowc) {
   wchar_t out[8];
 
   out[0] = 'x';
-  ASSERT_EQ(0U, mbrtowc(out, "hello", 0, NULL));
+  ASSERT_EQ(0U, mbrtowc(out, "hello", 0, nullptr));
   ASSERT_EQ('x', out[0]);
 
-  ASSERT_EQ(0U, mbrtowc(out, "hello", 0, NULL));
-  ASSERT_EQ(0U, mbrtowc(out, "", 0, NULL));
-  ASSERT_EQ(1U, mbrtowc(out, "hello", 1, NULL));
+  ASSERT_EQ(0U, mbrtowc(out, "hello", 0, nullptr));
+  ASSERT_EQ(0U, mbrtowc(out, "", 0, nullptr));
+  ASSERT_EQ(1U, mbrtowc(out, "hello", 1, nullptr));
   ASSERT_EQ(L'h', out[0]);
 
-  ASSERT_EQ(0U, mbrtowc(NULL, "hello", 0, NULL));
-  ASSERT_EQ(0U, mbrtowc(NULL, "", 0, NULL));
-  ASSERT_EQ(1U, mbrtowc(NULL, "hello", 1, NULL));
+  ASSERT_EQ(0U, mbrtowc(nullptr, "hello", 0, nullptr));
+  ASSERT_EQ(0U, mbrtowc(nullptr, "", 0, nullptr));
+  ASSERT_EQ(1U, mbrtowc(nullptr, "hello", 1, nullptr));
 
-  ASSERT_EQ(0U, mbrtowc(NULL, NULL, 0, NULL));
+  ASSERT_EQ(0U, mbrtowc(nullptr, nullptr, 0, nullptr));
 
   ASSERT_STREQ("C.UTF-8", setlocale(LC_CTYPE, "C.UTF-8"));
   uselocale(LC_GLOBAL_LOCALE);
 
   // 1-byte UTF-8.
-  ASSERT_EQ(1U, mbrtowc(out, "abcdef", 6, NULL));
+  ASSERT_EQ(1U, mbrtowc(out, "abcdef", 6, nullptr));
   ASSERT_EQ(L'a', out[0]);
   // 2-byte UTF-8.
-  ASSERT_EQ(2U, mbrtowc(out, "\xc2\xa2" "cdef", 6, NULL));
+  ASSERT_EQ(2U, mbrtowc(out, "\xc2\xa2" "cdef", 6, nullptr));
   ASSERT_EQ(static_cast<wchar_t>(0x00a2), out[0]);
   // 3-byte UTF-8.
-  ASSERT_EQ(3U, mbrtowc(out, "\xe2\x82\xac" "def", 6, NULL));
+  ASSERT_EQ(3U, mbrtowc(out, "\xe2\x82\xac" "def", 6, nullptr));
   ASSERT_EQ(static_cast<wchar_t>(0x20ac), out[0]);
   // 4-byte UTF-8.
-  ASSERT_EQ(4U, mbrtowc(out, "\xf0\xa4\xad\xa2" "ef", 6, NULL));
+  ASSERT_EQ(4U, mbrtowc(out, "\xf0\xa4\xad\xa2" "ef", 6, nullptr));
   ASSERT_EQ(static_cast<wchar_t>(0x24b62), out[0]);
 #if defined(__BIONIC__) // glibc allows this.
   // Illegal 5-byte UTF-8.
-  ASSERT_EQ(static_cast<size_t>(-1), mbrtowc(out, "\xf8\xa1\xa2\xa3\xa4" "f", 6, NULL));
+  ASSERT_EQ(static_cast<size_t>(-1), mbrtowc(out, "\xf8\xa1\xa2\xa3\xa4" "f", 6, nullptr));
   ASSERT_EQ(EILSEQ, errno);
 #endif
   // Illegal over-long sequence.
-  ASSERT_EQ(static_cast<size_t>(-1), mbrtowc(out, "\xf0\x82\x82\xac" "ef", 6, NULL));
+  ASSERT_EQ(static_cast<size_t>(-1), mbrtowc(out, "\xf0\x82\x82\xac" "ef", 6, nullptr));
   ASSERT_EQ(EILSEQ, errno);
 }
 
@@ -361,7 +361,7 @@
   memset(&ps, 0, sizeof(ps));
 
   test_mbrtowc_incomplete(&ps);
-  test_mbrtowc_incomplete(NULL);
+  test_mbrtowc_incomplete(nullptr);
 }
 
 static void test_mbsrtowcs(mbstate_t* ps) {
@@ -419,7 +419,7 @@
   mbstate_t ps;
   memset(&ps, 0, sizeof(ps));
   test_mbsrtowcs(&ps);
-  test_mbsrtowcs(NULL);
+  test_mbsrtowcs(nullptr);
 
   // Invalid multi byte continuation.
   const char* invalid = "\x20";
@@ -531,18 +531,18 @@
 
   memset(dst, 0, sizeof(dst));
   src = s;
-  ASSERT_EQ(0U, mbsnrtowcs(dst, &src, 0, 0, NULL));
+  ASSERT_EQ(0U, mbsnrtowcs(dst, &src, 0, 0, nullptr));
 
   memset(dst, 0, sizeof(dst));
   src = s;
-  ASSERT_EQ(2U, mbsnrtowcs(dst, &src, 2, 123, NULL)); // glibc chokes on SIZE_MAX here.
+  ASSERT_EQ(2U, mbsnrtowcs(dst, &src, 2, 123, nullptr)); // glibc chokes on SIZE_MAX here.
   ASSERT_EQ(L'h', dst[0]);
   ASSERT_EQ(L'e', dst[1]);
   ASSERT_EQ(&s[2], src);
 
   memset(dst, 0, sizeof(dst));
   src = s;
-  ASSERT_EQ(3U, mbsnrtowcs(dst, &src, SIZE_MAX, 3, NULL));
+  ASSERT_EQ(3U, mbsnrtowcs(dst, &src, SIZE_MAX, 3, nullptr));
   ASSERT_EQ(L'h', dst[0]);
   ASSERT_EQ(L'e', dst[1]);
   ASSERT_EQ(L'l', dst[2]);
@@ -669,19 +669,19 @@
   size_t n;
 
   // 1-byte character.
-  n = mbrtowc(&wc, "x", MB_CUR_MAX, NULL);
+  n = mbrtowc(&wc, "x", MB_CUR_MAX, nullptr);
   EXPECT_EQ(1U, n);
   EXPECT_EQ(L'x', wc);
   // 2-byte character.
-  n = mbrtowc(&wc, "\xc2\xa2", MB_CUR_MAX, NULL);
+  n = mbrtowc(&wc, "\xc2\xa2", MB_CUR_MAX, nullptr);
   EXPECT_EQ(2U, n);
   EXPECT_EQ(L'¢', wc);
   // 3-byte character.
-  n = mbrtowc(&wc, "\xe2\x82\xac", MB_CUR_MAX, NULL);
+  n = mbrtowc(&wc, "\xe2\x82\xac", MB_CUR_MAX, nullptr);
   EXPECT_EQ(3U, n);
   EXPECT_EQ(L'€', wc);
   // 4-byte character.
-  n = mbrtowc(&wc, "\xf0\xa4\xad\xa2", MB_CUR_MAX, NULL);
+  n = mbrtowc(&wc, "\xf0\xa4\xad\xa2", MB_CUR_MAX, nullptr);
   EXPECT_EQ(4U, n);
   EXPECT_EQ(L'𤭢', wc);
 }
@@ -719,73 +719,73 @@
 
 TEST(wchar, wcstol_EINVAL) {
   errno = 0;
-  wcstol(L"123", NULL, -1);
+  wcstol(L"123", nullptr, -1);
   ASSERT_EQ(EINVAL, errno);
   errno = 0;
-  wcstol(L"123", NULL, 1);
+  wcstol(L"123", nullptr, 1);
   ASSERT_EQ(EINVAL, errno);
   errno = 0;
-  wcstol(L"123", NULL, 37);
+  wcstol(L"123", nullptr, 37);
   ASSERT_EQ(EINVAL, errno);
 }
 
 TEST(wchar, wcstoll_EINVAL) {
   errno = 0;
-  wcstoll(L"123", NULL, -1);
+  wcstoll(L"123", nullptr, -1);
   ASSERT_EQ(EINVAL, errno);
   errno = 0;
-  wcstoll(L"123", NULL, 1);
+  wcstoll(L"123", nullptr, 1);
   ASSERT_EQ(EINVAL, errno);
   errno = 0;
-  wcstoll(L"123", NULL, 37);
+  wcstoll(L"123", nullptr, 37);
   ASSERT_EQ(EINVAL, errno);
 }
 
 TEST(wchar, wcstoul_EINVAL) {
   errno = 0;
-  wcstoul(L"123", NULL, -1);
+  wcstoul(L"123", nullptr, -1);
   ASSERT_EQ(EINVAL, errno);
   errno = 0;
-  wcstoul(L"123", NULL, 1);
+  wcstoul(L"123", nullptr, 1);
   ASSERT_EQ(EINVAL, errno);
   errno = 0;
-  wcstoul(L"123", NULL, 37);
+  wcstoul(L"123", nullptr, 37);
   ASSERT_EQ(EINVAL, errno);
 }
 
 TEST(wchar, wcstoull_EINVAL) {
   errno = 0;
-  wcstoull(L"123", NULL, -1);
+  wcstoull(L"123", nullptr, -1);
   ASSERT_EQ(EINVAL, errno);
   errno = 0;
-  wcstoull(L"123", NULL, 1);
+  wcstoull(L"123", nullptr, 1);
   ASSERT_EQ(EINVAL, errno);
   errno = 0;
-  wcstoull(L"123", NULL, 37);
+  wcstoull(L"123", nullptr, 37);
   ASSERT_EQ(EINVAL, errno);
 }
 
 TEST(wchar, wcstoll_l_EINVAL) {
   errno = 0;
-  wcstoll_l(L"123", NULL, -1, LC_GLOBAL_LOCALE);
+  wcstoll_l(L"123", nullptr, -1, LC_GLOBAL_LOCALE);
   ASSERT_EQ(EINVAL, errno);
   errno = 0;
-  wcstoll_l(L"123", NULL, 1, LC_GLOBAL_LOCALE);
+  wcstoll_l(L"123", nullptr, 1, LC_GLOBAL_LOCALE);
   ASSERT_EQ(EINVAL, errno);
   errno = 0;
-  wcstoll_l(L"123", NULL, 37, LC_GLOBAL_LOCALE);
+  wcstoll_l(L"123", nullptr, 37, LC_GLOBAL_LOCALE);
   ASSERT_EQ(EINVAL, errno);
 }
 
 TEST(wchar, wcstoull_l_EINVAL) {
   errno = 0;
-  wcstoull_l(L"123", NULL, -1, LC_GLOBAL_LOCALE);
+  wcstoull_l(L"123", nullptr, -1, LC_GLOBAL_LOCALE);
   ASSERT_EQ(EINVAL, errno);
   errno = 0;
-  wcstoull_l(L"123", NULL, 1, LC_GLOBAL_LOCALE);
+  wcstoull_l(L"123", nullptr, 1, LC_GLOBAL_LOCALE);
   ASSERT_EQ(EINVAL, errno);
   errno = 0;
-  wcstoull_l(L"123", NULL, 37, LC_GLOBAL_LOCALE);
+  wcstoull_l(L"123", nullptr, 37, LC_GLOBAL_LOCALE);
   ASSERT_EQ(EINVAL, errno);
 }
 
diff --git a/tests/wctype_test.cpp b/tests/wctype_test.cpp
index 7da53e0..06e1571 100644
--- a/tests/wctype_test.cpp
+++ b/tests/wctype_test.cpp
@@ -24,7 +24,7 @@
 
 class UtfLocale {
  public:
-  UtfLocale() : l(newlocale(LC_ALL, "C.UTF-8", 0)) {}
+  UtfLocale() : l(newlocale(LC_ALL, "C.UTF-8", nullptr)) {}
   ~UtfLocale() { freelocale(l); }
   locale_t l;
 };
@@ -215,18 +215,18 @@
 }
 
 TEST(wctype, towctrans) {
-  EXPECT_TRUE(wctrans("tolower") != 0);
-  EXPECT_TRUE(wctrans("toupper") != 0);
+  EXPECT_TRUE(wctrans("tolower") != nullptr);
+  EXPECT_TRUE(wctrans("toupper") != nullptr);
 
-  EXPECT_TRUE(wctrans("monkeys") == 0);
+  EXPECT_TRUE(wctrans("monkeys") == nullptr);
 }
 
 TEST(wctype, towctrans_l) {
   UtfLocale l;
-  EXPECT_TRUE(wctrans_l("tolower", l.l) != 0);
-  EXPECT_TRUE(wctrans_l("toupper", l.l) != 0);
+  EXPECT_TRUE(wctrans_l("tolower", l.l) != nullptr);
+  EXPECT_TRUE(wctrans_l("toupper", l.l) != nullptr);
 
-  EXPECT_TRUE(wctrans_l("monkeys", l.l) == 0);
+  EXPECT_TRUE(wctrans_l("monkeys", l.l) == nullptr);
 }
 
 TEST(wctype, wctrans) {