Merge tag 'android-16.0.0_r4' of https://android.googlesource.com/platform/bionic into HEAD

Android 16.0.0 release 4

Change-Id: I05c9b16c3867e3369adb4f433eb95bb8060238b1
diff --git a/OWNERS b/OWNERS
index 7455fd7..ab0ac10 100644
--- a/OWNERS
+++ b/OWNERS
@@ -1,9 +1,8 @@
 enh@google.com
 
 cferris@google.com
-chiahungduan@google.com
 danalbert@google.com
-rprichard@google.com
+gbiv@google.com
 yabinc@google.com
 
 per-file docs/mte.md=fmayer@google.com,pcc@google.com
diff --git a/README.md b/README.md
index 4b7e42d..b76c58c 100644
--- a/README.md
+++ b/README.md
@@ -161,111 +161,191 @@
     # See 'Updating tzdata' later.
 ```
 
+## Adding a new function
+
+### Should I?
+
+The first question you should ask is "should I add this function?".
+The answer is usually "no".
+
+The answer is "yes" if the function is part of ISO C or POSIX.
+
+The answer is "probably" if the function is in glibc and musl _and_ the BSDs
+(including iOS/macOS).
+
+The answer is "probably not" if the function differs in API or behavior between
+them (ABI doesn't matter).
+
+The answer is "maybe" if the function has three/four distinct users in
+different unrelated projects, and there isn't a more specific higher-level
+library that would make more sense as the place to add the function.
+
+### How?
+
+Adding a function usually involves:
+
+1. Find the right header file to work in by looking up the official
+   specification. The POSIX documentation on
+   [opengroup.org](https://pubs.opengroup.org/onlinepubs/9799919799/functions/contents.html)
+   is the canonical source (though this may lag behind the most recent ISO C).
+   This documentation will also be useful in later steps such as writing tests.
+1. Add constants (and perhaps types) to the appropriate header file.
+   Note that you should check to see whether the constants are already in
+   kernel uapi header files, in which case you just need to make sure that
+   the appropriate header file in libc/include/ `#include`s the relevant
+   `linux/` file or files.
+1. Add function declarations to the appropriate header file. Don't forget
+   to include the appropriate `__INTRODUCED_IN()`, with the right API level
+   for the first release your system call wrapper will be in. See
+   libc/include/android/api_level.h for the API levels.
+   If the header file doesn't exist, copy all of libc/include/sys/sysinfo.h
+   into your new file --- it's a good short example to start from.
+
+   Note also our style for naming arguments: always use two leading
+   underscores (so developers are free to use any of the unadorned names as
+   macros without breaking things), avoid abbreviations, and ideally try to
+   use the same name as an existing system call (to reduce the amount of
+   English vocabulary required by people who just want to use the function
+   signatures). If there's a similar function already in the C library,
+   check what names it already used. Finally, prefer the `void*` orthography we
+   use over the `void *` you'll see on man7.org, and don't forget to include
+   nullability annotations for any pointers.
+1. Add basic documentation to the header file. Again, the existing
+   libc/include/sys/sysinfo.h is a good short example that shows the
+   expected style.
+
+   Most of the detail should actually be left to the man7.org page, with
+   only a brief one-sentence explanation (usually based on the description
+   in the NAME section of the man page) in our documentation. Always
+   include the return value/error reporting details (you can find out
+   what the system call returns from the RETURN VALUE of the man page),
+   but try to match the wording and style wording from _our_ existing
+   documentation; we're trying to minimize the number of English words
+   that readers need to understand by using the exact same wording where
+   possible).
+
+   Explicitly say which version of Android the function was added to in
+   the documentation because the documentation generation tool doesn't yet
+   understand `__INTRODUCED_IN()`.
+
+   Explicitly call out any Android-specific changes/additions/limitations
+   because they won't be on the man7.org page.
+1. Add the function name to the correct section in libc/libc.map.txt (or
+   the corresponding map file for libm or libdl).
+   If you don't add your function to the map, it won't be exported.
+   Adding the function to the map adds an implicit build-time check that your
+   function is defined for all supported architectures.
+
+   Any new function should include an `# introduced=` matching the
+   `__INTRODUCED_IN()` from the header. For several versions of Android we
+   created separate sections (such as `LIBC_Q`) to make it a little more
+   obvious in places like nm(1) output which version of Android is required.
+   Theoretically this also gave us the option of having multiple versions of
+   the same symbol with different behavior. Other OSes use this for backward
+   compatibility but we tend to use API level checks within the implementation
+   instead. When marketing moved back to numbers, and then when the alphabet
+   wrapped, this started to look like less of a good idea. The move to "2025Q4"
+   style releases made this even less convincing, so we've gone back to just
+   adding new symbols unversioned (but with the `# introduced=` annotation).
+1. Add a basic test. Don't try to test everything; concentrate on just testing
+   the code that's actually in *bionic*, not all the functionality that's
+   implemented in the kernel. At one end of the spectrum, for string routines
+   that's everything; at the other, for simple syscalls, that's just the
+   auto-generated argument and return value marshalling.
+
+   Add a test in the right file in tests/. We have one file per header, so if
+   your system call is exposed in <unistd.h>, for example, your test would go
+   in tests/unistd_test.cpp.
+
+   A trivial test that deliberately supplies an invalid argument helps check
+   that we're generating the right symbol and have the right declaration in
+   the header file, and that the change to libc.map.txt from step 5 is
+   correct. (For system calls, you can use strace(1) manually to confirm that
+   the correct system call is being made.)
+
+   For testing the *kernel* side of things, we should prefer to rely on
+   https://github.com/linux-test-project/ltp for kernel testing, but you'll
+   want to check that external/ltp/ does contain tests for the syscall you're
+   adding. Also check that external/ltp/ is using the libc wrapper for the
+   syscall rather than calling it "directly" via syscall(3)!
+
+   One common exception is for known kernel bugs where we sometimes have an
+   explicit test where the failure message says what SHA to cherrypick.
+   This has become less useful with the move to GKI kernels.
+1. Implement the function. Similar to tests, we typically try to have one
+   file per header, so a function from <sys/foo.h> would normally go in
+   sys_foo.cpp. The more complicated the implementation, the more likely it
+   warrants its own file.
+
+   Trivial system call wrappers are a special case covered in the next section.
 
 ## Adding libc wrappers for system calls
 
+### Should I?
+
 The first question you should ask is "should I add a libc wrapper for
-this system call?". The answer is usually "no".
+this system call?". The decision tree is similar to "adding a new function"
+above, but somewhat stricter because for system calls you can always just use
+[syscall(2)](https://man7.org/linux/man-pages/man2/syscall.2.html) instead.
 
-The answer is "yes" if the system call is part of the POSIX standard.
+### How?
 
-The answer is probably "yes" if the system call has a wrapper in at
-least one other C library (typically glibc/musl or Apple's libc).
+Adding a system call usually involves following all the steps from
+"adding a new function" above, with a couple of small differences:
 
-The answer may be "yes" if the system call has three/four distinct
-users in different projects, and there isn't a more specific higher-level
-library that would make more sense as the place to add the wrapper.
+1. For Linux system calls that aren't in POSIX, you can find the right header
+   file to work in by looking up your system call in the system call index on
+   [man7.org](https://man7.org/linux/man-pages/dir_section_2.html).
+   (If there's no header file given, or an explicit "glibc provides no wrapper",
+   see the points above about whether we should really be adding this or not!)
+1. To implement a trivial system call wrapper -- one where a caller could just
+   use syscall(3) with no extra logic, simply add an entry (or entries,
+   in some cases) to SYSCALLS.TXT.
 
-In all other cases, you should use
-[syscall(3)](https://man7.org/linux/man-pages/man2/syscall.2.html) instead.
+   See SYSCALLS.TXT itself for documentation on the format.
 
-Adding a system call usually involves:
+   Some trivial system call wrappers are still harder than others. The most
+   common problem is a 64-bit argument such as `off64_t` (a *pointer* to a
+   64-bit argument is fine, since pointers are always the "natural" size for
+   the architecture regardless of the size of the thing they point to).
+   Whenever you have a function that takes `off_t` or `off64_t`, you'll need to
+   consider whether you actually need a foo() and a foo64(), and whether they
+   will use the same underlying system call or are implemented as two different
+   system calls. It's usually easiest to find a similar system call and copy
+   and paste from that. You'll definitely need to test both on 32-bit and
+   64-bit. (These special cases warrant more testing than the easy cases,
+   even if only manual testing with strace. Sadly it isn't always feasible to
+   write a working test for the interesting cases -- offsets larger than 2GiB,
+   say -- so you may end up just writing a "meaningless" program whose only
+   purpose is to give you patterns to look for when run under strace(1).)
 
-  1. Add an entry (or entries, in some cases) to SYSCALLS.TXT.
-     See SYSCALLS.TXT itself for documentation on the format.
-     See also the notes below for how to deal with tricky cases like `off_t`.
-  2. Find the right header file to work in by looking up your system call
-     on [man7.org](https://man7.org/linux/man-pages/dir_section_2.html).
-     (If there's no header file given, see the points above about whether we
-     should really be adding this or not!)
-  3. Add constants (and perhaps types) to the appropriate header file.
-     Note that you should check to see whether the constants are already in
-     kernel uapi header files, in which case you just need to make sure that
-     the appropriate header file in libc/include/ `#include`s the relevant
-     `linux/` file or files.
-  4. Add function declarations to the appropriate header file. Don't forget
-     to include the appropriate `__INTRODUCED_IN()`, with the right API level
-     for the first release your system call wrapper will be in. See
-     libc/include/android/api_level.h for the API levels.
-     If the header file doesn't exist, copy all of libc/include/sys/sysinfo.h
-     into your new file --- it's a good short example to start from.
+  In some cases the syscall you're adding a wrapper for will be new enough
+  that it's not available on all supported kernels. In that case you'll need
+  to consider two extra issues:
 
-     Note also our style for naming arguments: always use two leading
-     underscores (so developers are free to use any of the unadorned names as
-     macros without breaking things), avoid abbreviations, and ideally try to
-     use the same name as an existing system call (to reduce the amount of
-     English vocabulary required by people who just want to use the function
-     signatures). If there's a similar function already in the C library,
-     check what names it's used. Finally, prefer the `void*` orthography we
-     use over the `void *` you'll see on man7.org.)
-  5. Add basic documentation to the header file. Again, the existing
-     libc/include/sys/sysinfo.h is a good short example that shows the
-     expected style.
+  1. Think about what the fallback behavior should be. There are two main
+     choices: fail clearly (usually with -1 and errno set to ENOSYS),
+     or have a "best effort" fallback implementation. When deciding between
+     these two options, always consider (a) how hard it is for us to maintain
+     the other implementation, (b) how hard it is for developers to maintain
+     their own implementation (bearing in mind that they won't be able to use
+     anything from bionic until their target API level is high enough), and
+     (c) any security implications. As an example of the last point, we didn't
+     offer fallback implementations for things like accept4() with SOCK_CLOEXEC
+     because there's no non-racy way to do that, meaning that a developer might
+     write code that _looks_ secure but which we make insecure at runtime by
+     pretending to have done what they asked for -- atomic setting of the
+     SOCK_CLOEXEC flag on the returned fd -- but not actually doing it.
 
-     Most of the detail should actually be left to the man7.org page, with
-     only a brief one-sentence explanation (usually based on the description
-     in the NAME section of the man page) in our documentation. Always
-     include the return value/error reporting details (you can find out
-     what the system call returns from the RETURN VALUE of the man page),
-     but try to match the wording and style wording from _our_ existing
-     documentation; we're trying to minimize the amount of English readers
-     need to understand by using the exact same wording where possible).
-     Explicitly say which version of Android the function was added to in
-     the documentation because the documentation generation tool doesn't yet
-     understand `__INTRODUCED_IN()`.
+  1. Make sure that you've written your unit tests so they don't fail when
+     run on devices with old (but still supported kernels). Search for ENOSYS
+     in the tests to find existing examples of the common idiom for this.
 
-     Explicitly call out any Android-specific changes/additions/limitations
-     because they won't be on the man7.org page.
-  6. Add the function name to the correct section in libc/libc.map.txt; it'll
-     be near the end of the file. You may need to add a new section if you're
-     the first to add a system call to this version of Android.
-  7. Add a basic test. Don't try to test everything; concentrate on just testing
-     the code that's actually in *bionic*, not all the functionality that's
-     implemented in the kernel. For simple syscalls, that's just the
-     auto-generated argument and return value marshalling.
+  See https://source.android.com/docs/core/architecture/kernel/android-common#feature-and-launch-kernels
+  for details of what kernels are considered supported.
 
-     Add a test in the right file in tests/. We have one file per header, so if
-     your system call is exposed in <unistd.h>, for example, your test would go
-     in tests/unistd_test.cpp.
-
-     A trivial test that deliberately supplies an invalid argument helps check
-     that we're generating the right symbol and have the right declaration in
-     the header file, and that the change to libc.map.txt from step 5 is
-     correct. (You can use strace(1) manually to confirm that the correct
-     system call is being made.)
-
-     For testing the *kernel* side of things, we should prefer to rely on
-     https://github.com/linux-test-project/ltp for kernel testing, but you'll
-     want to check that external/ltp does contain tests for the syscall you're
-     adding. Also check that external/ltp is using the libc wrapper for the
-     syscall rather than calling it "directly" via syscall(3)!
-
-Some system calls are harder than others. The most common problem is a 64-bit
-argument such as `off64_t` (a *pointer* to a 64-bit argument is fine, since
-pointers are always the "natural" size for the architecture regardless of the
-size of the thing they point to). Whenever you have a function that takes
-`off_t` or `off64_t`, you'll need to consider whether you actually need a foo()
-and a foo64(), and whether they will use the same underlying system call or are
-implemented as two different system calls. It's usually easiest to find a
-similar system call and copy and paste from that. You'll definitely need to test
-both on 32-bit and 64-bit. (These special cases warrant more testing than the
-easy cases, even if only manual testing with strace. Sadly it isn't always
-feasible to write a working test for the interesting cases -- offsets larger
-than 2GiB, say -- so you may end up just writing a "meaningless" program whose
-only purpose is to give you patterns to look for when run under strace(1).)
-
-A general example of adding a system call:
-https://android-review.googlesource.com/c/platform/bionic/+/2073827
+  You can see a general example of adding a trivial system call wrapper here:
+  https://android-review.googlesource.com/c/platform/bionic/+/2073827
 
 ### Debugging tips
 
diff --git a/TEST_MAPPING b/TEST_MAPPING
index f81d348..c16b7e4 100644
--- a/TEST_MAPPING
+++ b/TEST_MAPPING
@@ -103,5 +103,19 @@
     {
       "name": "CtsBionicTestCases"
     }
+  ],
+  "wear-cts-presubmit": [
+    {
+      "name": "CtsAppServiceTestCases",
+      "options": [
+       {
+         "include-filter": "android.app.cts.service.ServiceTest"
+       },
+       {
+        // Flaky
+        "exclude-filter": "android.app.cts.service.ServiceTest#testActivityServiceBindingLru"
+       }
+     ]
+    }
   ]
 }
diff --git a/android-changes-for-ndk-developers.md b/android-changes-for-ndk-developers.md
index 2430447..e094a1d 100644
--- a/android-changes-for-ndk-developers.md
+++ b/android-changes-for-ndk-developers.md
@@ -108,7 +108,7 @@
 to dlopen(3) (as opposed to being referenced by DT_NEEDED entries).
 
 
-## GNU hashes (Availible in API level >= 23)
+## GNU hashes (Available in API level >= 23)
 
 The GNU hash style available with `--hash-style=gnu` allows faster
 symbol lookup and is supported by Android's dynamic linker in API level 23 and
@@ -437,6 +437,8 @@
 adb shell setprop debug.ld.all dlerror,dlopen
 ```
 
+See also `LD_DEBUG`.
+
 
 ## dlclose interacts badly with thread local variables with non-trivial destructors
 
@@ -544,3 +546,20 @@
 _not_ apply if your app was debuggable. To be compatible with all API levels,
 always give files that need to be extracted a "lib" prefix and ".so" suffix,
 or avoid using `extractNativeLibs`.
+
+
+## The LD_DEBUG environment variable.
+
+On devices running API level 37 or later you can also use the `LD_DEBUG`
+environment variable when running a stand-alone executable such as a unit test.
+The syntax is broadly similar to glibc, and you can get help for the specific
+version of Android you're on by using `LD_DEBUG=help`.
+You can also enable everything by using `LD_DEBUG=all`.
+
+(Older versions of Android also supported `LD_DEBUG`,
+but used integers instead of strings.
+The meaning of those integers varied by release,
+and some releases compiled support for `LD_DEBUG` out of released builds,
+so the best advice is either "look at the corresponding source" or
+"start with `1` and keep increasing the number until you see what you want,
+or see no change in output from the previous value".)
diff --git a/apex/Android.bp b/apex/Android.bp
index d04907b..45a7d08 100644
--- a/apex/Android.bp
+++ b/apex/Android.bp
@@ -5,6 +5,7 @@
 
 package {
     default_applicable_licenses: ["bionic_apex_license"],
+    default_team: "trendy_team_native_tools_libraries",
 }
 
 license {
diff --git a/benchmarks/bionic_benchmarks.cpp b/benchmarks/bionic_benchmarks.cpp
index b88c6e5..a03a73c 100644
--- a/benchmarks/bionic_benchmarks.cpp
+++ b/benchmarks/bionic_benchmarks.cpp
@@ -18,6 +18,7 @@
 #include <getopt.h>
 #include <inttypes.h>
 #include <math.h>
+#include <sys/param.h>
 #include <sys/resource.h>
 
 #include <map>
@@ -250,8 +251,8 @@
     return false;
   }
 
-  // Verify the alignment is powers of 2.
-  if (align != 0 && (align & (align - 1)) != 0) {
+  // Verify the alignment is a power of 2.
+  if (align != 0 && !powerof2(align)) {
     return false;
   }
 
@@ -296,8 +297,7 @@
   }
 
   // Verify the alignments are powers of 2.
-  if ((align1 != 0 && (align1 & (align1 - 1)) != 0)
-      || (align2 != 0 && (align2 & (align2 - 1)) != 0)) {
+  if ((align1 != 0 && !powerof2(align1)) || (align2 != 0 && !powerof2(align2))) {
     return false;
   }
 
@@ -401,8 +401,8 @@
   // Register any of the extra benchmarks that were specified in the options.
   args_vector_t arg_vector;
   args_vector_t* run_args = &arg_vector;
-  for (const std::string& extra_fn : cmdline_opts.extra_benchmarks) {
-    android::base::Trim(extra_fn);
+  for (std::string extra_fn : cmdline_opts.extra_benchmarks) {
+    extra_fn = android::base::Trim(extra_fn);
     size_t first_space_pos = extra_fn.find(' ');
     std::string fn_name = extra_fn.substr(0, first_space_pos);
     std::string cmd_args;
diff --git a/benchmarks/semaphore_benchmark.cpp b/benchmarks/semaphore_benchmark.cpp
index ffccc82..2378f49 100644
--- a/benchmarks/semaphore_benchmark.cpp
+++ b/benchmarks/semaphore_benchmark.cpp
@@ -16,7 +16,6 @@
 
 #include <pthread.h>
 #include <semaphore.h>
-#include <stdatomic.h>
 #include <stdio.h>
 #include <stdlib.h>
 
diff --git a/benchmarks/spawn/Android.bp b/benchmarks/spawn/Android.bp
index de9b161..c218467 100644
--- a/benchmarks/spawn/Android.bp
+++ b/benchmarks/spawn/Android.bp
@@ -116,27 +116,27 @@
 }
 
 cc_binary {
-    defaults: ["bionic_spawn_benchmark_binary"],
     name: "bench_cxa_atexit",
+    defaults: ["bionic_spawn_benchmark_binary"],
     srcs: ["bench_cxa_atexit.cpp"],
 }
 
 cc_binary {
-    defaults: ["bionic_spawn_benchmark_binary"],
     name: "bench_noop",
+    defaults: ["bionic_spawn_benchmark_binary"],
     srcs: ["noop.cpp"],
 }
 
 cc_binary {
-    defaults: ["bionic_spawn_benchmark_binary"],
     name: "bench_noop_nostl",
+    defaults: ["bionic_spawn_benchmark_binary"],
     srcs: ["noop.cpp"],
     stl: "none",
 }
 
 cc_binary {
-    defaults: ["bionic_spawn_benchmark_binary"],
     name: "bench_noop_static",
+    defaults: ["bionic_spawn_benchmark_binary"],
     srcs: ["noop.cpp"],
     static_executable: true,
     stl: "libc++_static",
diff --git a/benchmarks/util.cpp b/benchmarks/util.cpp
index ec74147..78ba3de 100644
--- a/benchmarks/util.cpp
+++ b/benchmarks/util.cpp
@@ -21,13 +21,14 @@
 #include <sched.h>
 #include <stdio.h>
 #include <string.h>
+#include <sys/param.h>
 #include <wchar.h>
 
 #include <cstdlib>
 
 // This function returns a pointer less than 2 * alignment + or_mask bytes into the array.
 char* GetAlignedMemory(char* orig_ptr, size_t alignment, size_t or_mask) {
-  if ((alignment & (alignment - 1)) != 0) {
+  if (!powerof2(alignment)) {
     errx(1, "warning: alignment passed into GetAlignedMemory is not a power of two.");
   }
   if (or_mask > alignment) {
diff --git a/cpu_target_features/Android.bp b/cpu_target_features/Android.bp
index 25f37d1..135a110 100644
--- a/cpu_target_features/Android.bp
+++ b/cpu_target_features/Android.bp
@@ -1,5 +1,6 @@
 package {
     default_applicable_licenses: ["Android-Apache-2.0"],
+    default_team: "trendy_team_native_tools_libraries",
 }
 
 cc_binary {
diff --git a/docs/32-bit-abi.md b/docs/32-bit-abi.md
index efc6815..86cd57b 100644
--- a/docs/32-bit-abi.md
+++ b/docs/32-bit-abi.md
@@ -1,5 +1,8 @@
 # 32-bit ABI bugs
 
+Note: Android 16+ will only run with a 64-bit kernel, however userspace may
+still be 32-bit.
+
 ## 32-bit `off_t` and `_FILE_OFFSET_BITS=64`
 
 On 32-bit Android, `off_t` is a signed 32-bit integer. This limits functions
@@ -121,3 +124,25 @@
 these functions. Since LP32 is unlikely to be still supported long before
 those limits could ever matter, although -- unlike the others in this
 document -- this defect is actually fixable, it doesn't seem worth fixing.
+
+
+## `f_fsid` in `struct statvfs` is too small
+
+Linux uses 64 bits to represent a filesystem id in `struct statfs`,
+so the conversion to the POSIX `struct statvfs` with its `unsigned long`
+is necessarily lossy on ILP32 where `long` is 32-bit.
+
+We're not aware that anyone has ever hit this in practice,
+but it's recorded here for completeness.
+
+
+## `dev_t` and `ino_t` are too small
+
+Linux uses 64 bits to represent device and inode numbers,
+but by historical accident Android's 32-bit ABI has them both
+as 32-bit types.
+The corresponding fields in `struct stat` do have the right sizes,
+though this means that they have the wrong types.
+
+We're not aware that anyone has ever hit this in practice,
+but it's recorded here for completeness.
diff --git a/docs/EINTR.md b/docs/EINTR.md
index 8d1ab52..36f842e 100644
--- a/docs/EINTR.md
+++ b/docs/EINTR.md
@@ -65,11 +65,11 @@
 
 ### close(2)
 
-TL;DR: *never* wrap close(2) calls with `TEMP_FAILURE_RETRY`.
+TL;DR: *never* wrap close(2) calls with `TEMP_FAILURE_RETRY()`.
 
 The case of close(2) is complicated. POSIX explicitly says that close(2)
 shouldn't close the file descriptor if it returns `EINTR`, but that's *not*
-true on Linux (and thus on Android). See
+true for the Linux kernel. See
 [Returning EINTR from close()](https://lwn.net/Articles/576478/)
 for more discussion.
 
@@ -79,6 +79,11 @@
 actually closes a *different* file descriptor belonging to a *different*
 thread.
 
+Since API level 23, bionic's close() never returns EINTR,
+but portable code (or code that needs to run on API level 21)
+should not wrap close() with TEMP_FAILURE_RETRY().
+
+
 ### Timeouts
 
 System calls with timeouts are the other interesting case where "just wrap
diff --git a/docs/defines.md b/docs/defines.md
index be48ad8..1668a7c 100644
--- a/docs/defines.md
+++ b/docs/defines.md
@@ -12,6 +12,10 @@
 `__GLIBC__`, `__APPLE__`, or `_WIN32`. Note that although bionic is most often
 seen on Android devices, it is possible to use bionic on the host too.
 
+(Note that though `__APPLE__` and `_WIN32` are defined by the compiler,
+both `__BIONIC__` and `__GLIBC__` are defined by <sys/cdefs.h>,
+which you should include before testing either of these.)
+
 ## `__ANDROID__`
 
 If your code is specific to Android devices, use `__ANDROID__`. This isn't
@@ -21,6 +25,8 @@
 Genuine cases are quite rare, and `__BIONIC__` is often more specific (but
 remember that it is possible -- if unusual -- to use bionic on the host).
 
+(This is defined by the compiler.)
+
 ## `ANDROID` (rarely useful)
 
 Not to be confused with `__ANDROID__`, the similar-looking but very different
@@ -42,6 +48,8 @@
 obvious "next" API level such as 19. Once the API level has been decided, the
 value of `__ANDROID_API__` drops to that number.
 
+(This is defined by the compiler, based on the api level in your target triple.)
+
 ## `__linux__`
 
 If your code requires a Linux kernel, use `__linux__`. This is typically a good
@@ -50,6 +58,8 @@
 well on a desktop Linux distro, say. Common alternatives on this dimension
 are `__APPLE__` or `_WIN32`.
 
+(This is defined by the compiler.)
+
 ## `__ANDROID_NDK__`
 
 If your code can be built either as part of an app _or_ as part of the OS
@@ -57,12 +67,16 @@
 This is typically a good choice when your code uses non-NDK API if it's built as
 part of the OS, but sticks to just the NDK APIs otherwise.
 
+(This is available after including <sys/cdefs.h> directly or transitively.)
+
 ## `__NDK_MAJOR__`, `__NDK_MINOR__`, `__NDK_BETA__`, `__NDK_BUILD__`, `__NDK_CANARY__`
 
 If your code can be built with a variety of different NDK versions, and needs to
-work around issues with some of them, use these macros to detect the versinon of
+work around issues with some of them, use these macros to detect the version of
 the NDK you're being built with. Usually only `__NDK_MAJOR__` will be necessary.
 
+(These are available after including <sys/cdefs.h> directly or transitively.)
+
 ## `__arm__`/`__aarch64__`, `__i386__`/`__x86_64__`, `__riscv`
 
 If your code is specific to a particular processor architecture, use
@@ -73,9 +87,13 @@
 operating systems that do support riscv32, you'll also need to check
 whether `__riscv_xlen` is 32 or 64.
 
+(These are defined by the compiler.)
+
 ## `__ILP32__` and `__LP64__`
 
 If your code depends on "bitness" -- whether `long` and pointers are 32-
 or 64-bit -- use these macros to conditionally compile. Note the extra
 "I" in the 32-bit macro (since `int`, `long`, and pointers are all 32-bit
 on such systems, with `long long` being needed for a 64-bit type).
+
+(These are defined by the compiler.)
diff --git a/docs/mte.md b/docs/mte.md
index 3034cc7..4705144 100644
--- a/docs/mte.md
+++ b/docs/mte.md
@@ -75,7 +75,12 @@
 
 `__libc_init_mte` figures out the appropriate MTE level that is requested by
 the process, calls `prctl` to request this from the kernel, and stores data in
-`__libc_shared_globals` which gets picked up later to enable MTE in scudo.
+`__libc_shared_globals` which gets picked up in [SetDefaultTaggingLevel]
+to disable stack trace collection in scudo for ASYNC mode. Scudo decides whether
+to use MTE or not in [Allocator::init] when it is first initialized, depending
+on whether MTE is on for the process. Bionic calls
+`scudo_malloc_disable_memory_tagging` in [SetHeapTaggingLevel] if MTE is later
+disabled using mallopt.
 
 It also does work related to stack tagging and permissive mode, which will be
 detailed later.
@@ -242,3 +247,6 @@
 [in init]: https://cs.android.com/android/platform/superproject/main/+/main:system/core/init/service.cpp?q=f:system%2Fcore%2Finit%2Fservice.cpp%20should_upgrade_mte
 [crashes in ASYNC mode]: https://cs.android.com/android/platform/superproject/main/+/main:system/core/debuggerd/handler/debuggerd_handler.cpp;l=799?q=BIONIC_SIGNAL_ART_PROFILER
 [libc startup]: https://cs.android.com/android/platform/superproject/main/+/main:bionic/libc/bionic/libc_init_mte.cpp?q=BIONIC_MEMTAG_UPGRADE_SECS
+[SetDefaultHeapTaggingLevel]: https://cs.android.com/android/platform/superproject/main/+/main:bionic/libc/bionic/heap_tagging.cpp?q=f:bionic%20symbol:SetDefaultHeapTaggingLevel%20f:cpp$&ss=android%2Fplatform%2Fsuperproject%2Fmain
+[Allocator::init]: https://github.com/llvm/llvm-project/blob/ef962752d9fee02fe1e626dc92206eb0457e2aa3/compiler-rt/lib/scudo/standalone/combined.h#L175
+[SetHeapTaggingLevel]: https://cs.android.com/android/platform/superproject/main/+/main:bionic/libc/bionic/heap_tagging.cpp?q=f:bionic%20symbol:SetHeapTaggingLevel%20f:heap_tagging.cpp$&ss=android%2Fplatform%2Fsuperproject%2Fmain
diff --git a/docs/status.md b/docs/status.md
index 034f115..b612108 100644
--- a/docs/status.md
+++ b/docs/status.md
@@ -240,88 +240,6 @@
   * all of <error.h>.
   * re-introduced various <resolv.h> functions: `ns_format_ttl`, `ns_get16`, `ns_get32`, `ns_initparse`, `ns_makecanon`, `ns_msg_getflag`, `ns_name_compress`, `ns_name_ntol`, `ns_name_ntop`, `ns_name_pack`, `ns_name_pton`, `ns_name_rollback`, `ns_name_skip`, `ns_name_uncompress`, `ns_name_unpack`, `ns_parserr`, `ns_put16`, `ns_put32`, `ns_samename`, `ns_skiprr`, `ns_sprintrr`, and `ns_sprintrrf`.
 
-New libc functions in L (API level 21):
-  * <android/dlext.h>.
-  * <android/set_abort_message.h>.
-  * <arpa/inet.h> `inet_lnaof`, `inet_netof`, `inet_network`, `inet_makeaddr`.
-  * <wctype.h> `iswblank`.
-  * <ctype.h> `isalnum_l`, `isalpha_l`, `isblank_l`, `icntrl_l`, `isdigit_l`, `isgraph_l`, `islower_l`, `isprint_l`, `ispunct_l`, `isspace_l`, `isupper_l`, `isxdigit_l`, `_tolower`, `tolower_l`, `_toupper`, `toupper_l`.
-  * <fcntl.h> `fallocate`, `posix_fadvise`, `posix_fallocate`, `splice`, `tee`, `vmsplice`.
-  * <inttypes.h> `wcstoimax`, `wcstoumax`.
-  * <link.h> `dl_iterate_phdr`.
-  * <mntent.h> `setmntent`, `endmntent`, `getmntent_r`.
-  * <poll.h> `ppoll`.
-  * <pthread.h> `pthread_condattr_getclock`, `pthread_condattr_setclock`, `pthread_mutex_timedlock`, `pthread_gettid_np`.
-  * <sched.h> `setns`.
-  * <search.h> `insque`, `remque`, `lfind`, `lsearch`, `twalk`.
-  * <stdio.h> `dprintf`, `vdprintf`.
-  * <stdlib.h> `initstate`, `setstate`, `getprogname`/`setprogname`, `atof`/`strtof`, `at_quick_exit`/`_Exit`/`quick_exit`, `grantpt`, `mbtowc`/`wctomb`, `posix_openpt`, `rand_r`/`rand`/`random`/`srand`/`srandom`, `strtold_l`/`strtoll_l`/`strtoull_l`.
-  * <string.h> `strcoll_l`/`strxfrm_l`, `stpcpy`/`stpncpy`.
-  * <sys/resource.h> `prlimit`.
-  * <sys/socket.h> `accept4`, `sendmmsg`.
-  * <sys/stat.h> `mkfifo`/`mknodat`.
-  * <time.h> `strftime_l`.
-  * <unistd.h> `dup3`, `execvpe`, `getpagesize`, `linkat`/`symlinkat`/`readlinkat`, `truncate`.
-  * <wchar.h> `wcstof`, `vfwscanf`/`vswscanf`/`vwscanf`, `wcstold_l`/`wcstoll`/`wcstoll_l`/`wcstoull`/`wcstoull_l`, `mbsnrtowcs`/`wcsnrtombs`, `wcscoll_l`/`wcsxfrm_l`.
-  * <wctype.h> `iswalnum_l`/`iswalpha_l`/`iswblank_l`/`iswcntrl_l`/`iswctype_l`/`iswdigit_l`/`iswgraph_l`/`iswlower_l`/`iswprint_l`/`iswpunct_l`/`iswspace_l`/`iswupper_l`/`iswxdigit_l`, `wctype_l`, `towlower_l`/`towupper_l`.
-  * all of <fts.h>.
-  * all of <locale.h>.
-  * all of <sys/epoll.h>.
-  * all of <sys/fsuid.h>.
-  * all of <sys/inotify.h>.
-  * all of <uchar.h>.
-
-New libc functions in K (API level 19):
-  * <inttypes.h> `imaxabs`, `imaxdiv`.
-  * <stdlib.h> `abs`, `labs`, `llabs`.
-  * <sys/stat.h> `futimens`.
-  * all of <sys/statvfs.h>.
-  * all of <sys/swap.h>.
-  * all of <sys/timerfd.h>.
-
-New libc functions in J-MR2 (API level 18):
-  * <stdio.h> `getdelim` and `getline`.
-  * <sys/auxv.h> `getauxval`.
-  * <sys/signalfd.h> `signalfd`.
-
-New libc functions in J-MR1 (API level 17):
-  * <ftw.h>.
-  * <signal.h> `psiginfo` and `psignal`.
-  * `getsid`, `malloc_usable_size`, `mlockall`/`munlockall`, `posix_memalign`, `unshare`.
-
-New libc functions in J (API level 16):
-  * the <search.h> tree functions `tdelete`, `tdestroy`, `tfind`, and `tsearch`.
-  * `faccessat`, `readahead`, `tgkill`.
-  * all of <sys/xattr.h>.
-
-libc function count over time:
-
-| API level | Function count |
-|-----------|----------------|
-| 16        | 842            |
-| 17        | 870            |
-| 18        | 878            |
-| 19        | 893            |
-| 21        | 1016           |
-| 22        | 1038           |
-| 23        | 1103           |
-| 24        | 1147           |
-| 25        | 1147           |
-| 26        | 1199           |
-| 27        | 1199           |
-| 28        | 1298           |
-| 29        | 1312           |
-| 30        | 1368           |
-| 31        | 1379           |
-| 32        | 1379           |
-| 33        | 1386           |
-| 34        | 1392           |
-
-Data collected by:
-```
-ndk-r26c$ for i in `ls -1v toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/*/libc.so` ; \
-  do echo $i; nm $i | grep -w T | wc -l ; done
-```
 
 ### libm
 
@@ -336,13 +254,6 @@
   * <complex.h> `cabs`, `carg`, `cimag`, `cacos`, `cacosh`, `casin`, `casinh`, `catan`, `catanh`, `ccos`, `ccosh`, `cexp`, `conj`, `cproj`, `csin`, `csinh`, `csqrt`, `ctan`, `ctanh`, `creal`, `cabsf`, `cargf`, `cimagf`, `cacosf`, `cacoshf`, `casinf`, `casinhf`, `catanf`, `catanhf`, `ccosf`, `ccoshf`, `cexpf`, `conjf`, `cprojf`, `csinf`, `csinhf`, `csqrtf`, `ctanf`, `ctanhf`, `crealf`, `cabsl`, `cprojl`, `csqrtl`.
   * <math.h> `lgammal_r`.
 
-New libm functions in L (API level 21):
-  * <complex.h> `cabsl`, `cprojl`, `csqrtl`.
-  * <math.h> `isinf`, `significandl`.
-
-New libm functions in J-MR2 (API level 18):
-  * <math.h> `log2`, `log2f`.
-
 
 ## Target API level behavioral differences
 
diff --git a/libc/Android.bp b/libc/Android.bp
index f5624ef..21f91e5 100644
--- a/libc/Android.bp
+++ b/libc/Android.bp
@@ -1,5 +1,6 @@
 package {
     default_applicable_licenses: ["bionic_libc_license"],
+    default_team: "trendy_team_native_tools_libraries",
 }
 
 license {
@@ -20,7 +21,6 @@
 
 libc_common_flags = [
     "-D_LIBC=1",
-    "-D__BIONIC_LP32_USE_STAT64",
     "-Wall",
     "-Wextra",
     "-Wunused",
@@ -215,6 +215,7 @@
 // -ffreestanding.
 
 cc_library_static {
+    name: "libc_bootstrap",
 
     srcs: [
         "bionic/__libc_init_main_thread.cpp",
@@ -237,7 +238,6 @@
         "-fno-stack-protector",
         "-ffreestanding",
     ],
-    name: "libc_bootstrap",
 }
 
 filegroup {
@@ -278,6 +278,7 @@
 // ========================================================
 
 cc_library_static {
+    name: "libc_tzcode",
 
     defaults: ["libc_defaults"],
     srcs: [
@@ -320,7 +321,6 @@
         "tzcode/",
         "upstream-freebsd/android/include",
     ],
-    name: "libc_tzcode",
 }
 
 // ========================================================
@@ -328,6 +328,7 @@
 // ========================================================
 
 cc_library_static {
+    name: "libc_dns",
 
     defaults: ["libc_defaults"],
     srcs: [
@@ -351,8 +352,6 @@
         "upstream-netbsd/lib/libc/include",
         "upstream-netbsd/android/include",
     ],
-
-    name: "libc_dns",
 }
 
 // ========================================================
@@ -370,42 +369,12 @@
 }
 
 cc_library_static {
+    name: "libc_freebsd",
     defaults: ["libc_defaults"],
     srcs: [
         "upstream-freebsd/lib/libc/stdlib/getopt_long.c",
-        "upstream-freebsd/lib/libc/stdlib/hcreate.c",
-        "upstream-freebsd/lib/libc/stdlib/hcreate_r.c",
-        "upstream-freebsd/lib/libc/stdlib/hdestroy_r.c",
-        "upstream-freebsd/lib/libc/stdlib/hsearch_r.c",
-        "upstream-freebsd/lib/libc/stdlib/qsort.c",
-        "upstream-freebsd/lib/libc/stdlib/qsort_r.c",
         "upstream-freebsd/lib/libc/stdlib/quick_exit.c",
-        "upstream-freebsd/lib/libc/string/wcpcpy.c",
-        "upstream-freebsd/lib/libc/string/wcpncpy.c",
-        "upstream-freebsd/lib/libc/string/wcscasecmp.c",
-        "upstream-freebsd/lib/libc/string/wcscat.c",
-        "upstream-freebsd/lib/libc/string/wcschr.c",
-        "upstream-freebsd/lib/libc/string/wcscmp.c",
-        "upstream-freebsd/lib/libc/string/wcscpy.c",
-        "upstream-freebsd/lib/libc/string/wcscspn.c",
         "upstream-freebsd/lib/libc/string/wcsdup.c",
-        "upstream-freebsd/lib/libc/string/wcslcat.c",
-        "upstream-freebsd/lib/libc/string/wcslen.c",
-        "upstream-freebsd/lib/libc/string/wcsncasecmp.c",
-        "upstream-freebsd/lib/libc/string/wcsncat.c",
-        "upstream-freebsd/lib/libc/string/wcsncmp.c",
-        "upstream-freebsd/lib/libc/string/wcsncpy.c",
-        "upstream-freebsd/lib/libc/string/wcsnlen.c",
-        "upstream-freebsd/lib/libc/string/wcspbrk.c",
-        "upstream-freebsd/lib/libc/string/wcsrchr.c",
-        "upstream-freebsd/lib/libc/string/wcsspn.c",
-        "upstream-freebsd/lib/libc/string/wcsstr.c",
-        "upstream-freebsd/lib/libc/string/wcstok.c",
-        "upstream-freebsd/lib/libc/string/wmemchr.c",
-        "upstream-freebsd/lib/libc/string/wmemcmp.c",
-        "upstream-freebsd/lib/libc/string/wmemcpy.c",
-        "upstream-freebsd/lib/libc/string/wmemmove.c",
-        "upstream-freebsd/lib/libc/string/wmemset.c",
     ],
 
     cflags: [
@@ -417,11 +386,10 @@
     local_include_dirs: [
         "upstream-freebsd/android/include",
     ],
-
-    name: "libc_freebsd",
 }
 
 cc_library_static {
+    name: "libc_freebsd_large_stack",
     defaults: ["libc_defaults"],
     srcs: [
         "upstream-freebsd/lib/libc/gen/glob.c",
@@ -436,8 +404,6 @@
     local_include_dirs: [
         "upstream-freebsd/android/include",
     ],
-
-    name: "libc_freebsd_large_stack",
 }
 
 // ========================================================
@@ -448,13 +414,11 @@
 // automatically included.
 
 cc_library_static {
-
+    name: "libc_netbsd",
     defaults: ["libc_defaults"],
     srcs: [
         "upstream-netbsd/common/lib/libc/stdlib/random.c",
         "upstream-netbsd/lib/libc/gen/nice.c",
-        "upstream-netbsd/lib/libc/gen/psignal.c",
-        "upstream-netbsd/lib/libc/gen/utime.c",
         "upstream-netbsd/lib/libc/inet/nsap_addr.c",
         "upstream-netbsd/lib/libc/regex/regcomp.c",
         "upstream-netbsd/lib/libc/regex/regerror.c",
@@ -489,8 +453,6 @@
         "upstream-netbsd/android/include",
         "upstream-netbsd/lib/libc/include",
     ],
-
-    name: "libc_netbsd",
 }
 
 // ========================================================
@@ -500,6 +462,7 @@
 // These files are built with the openbsd-compat.h header file
 // automatically included.
 cc_library_static {
+    name: "libc_openbsd",
     defaults: ["libc_defaults"],
     srcs: [
         "upstream-openbsd/lib/libc/crypt/arc4random.c",
@@ -507,55 +470,35 @@
         "upstream-openbsd/lib/libc/gen/alarm.c",
         "upstream-openbsd/lib/libc/gen/ctype_.c",
         "upstream-openbsd/lib/libc/gen/daemon.c",
-        "upstream-openbsd/lib/libc/gen/err.c",
-        "upstream-openbsd/lib/libc/gen/errx.c",
         "upstream-openbsd/lib/libc/gen/fnmatch.c",
         "upstream-openbsd/lib/libc/gen/ftok.c",
-        "upstream-openbsd/lib/libc/gen/getprogname.c",
-        "upstream-openbsd/lib/libc/gen/setprogname.c",
-        "upstream-openbsd/lib/libc/gen/verr.c",
-        "upstream-openbsd/lib/libc/gen/verrx.c",
-        "upstream-openbsd/lib/libc/gen/vwarn.c",
-        "upstream-openbsd/lib/libc/gen/vwarnx.c",
-        "upstream-openbsd/lib/libc/gen/warn.c",
-        "upstream-openbsd/lib/libc/gen/warnx.c",
         "upstream-openbsd/lib/libc/locale/btowc.c",
         "upstream-openbsd/lib/libc/locale/mbrlen.c",
         "upstream-openbsd/lib/libc/locale/mbstowcs.c",
         "upstream-openbsd/lib/libc/locale/mbtowc.c",
-        "upstream-openbsd/lib/libc/locale/wcscoll.c",
         "upstream-openbsd/lib/libc/locale/wcstombs.c",
-        "upstream-openbsd/lib/libc/locale/wcsxfrm.c",
         "upstream-openbsd/lib/libc/locale/wctob.c",
         "upstream-openbsd/lib/libc/locale/wctomb.c",
         "upstream-openbsd/lib/libc/net/base64.c",
-        "upstream-openbsd/lib/libc/net/htonl.c",
-        "upstream-openbsd/lib/libc/net/htons.c",
         "upstream-openbsd/lib/libc/net/inet_lnaof.c",
         "upstream-openbsd/lib/libc/net/inet_makeaddr.c",
         "upstream-openbsd/lib/libc/net/inet_netof.c",
         "upstream-openbsd/lib/libc/net/inet_ntoa.c",
         "upstream-openbsd/lib/libc/net/inet_ntop.c",
         "upstream-openbsd/lib/libc/net/inet_pton.c",
-        "upstream-openbsd/lib/libc/net/ntohl.c",
-        "upstream-openbsd/lib/libc/net/ntohs.c",
         "upstream-openbsd/lib/libc/net/res_random.c",
-        "upstream-openbsd/lib/libc/stdio/fgetln.c",
         "upstream-openbsd/lib/libc/stdio/fgetwc.c",
         "upstream-openbsd/lib/libc/stdio/fgetws.c",
         "upstream-openbsd/lib/libc/stdio/flags.c",
         "upstream-openbsd/lib/libc/stdio/fputwc.c",
         "upstream-openbsd/lib/libc/stdio/fputws.c",
         "upstream-openbsd/lib/libc/stdio/fvwrite.c",
-        "upstream-openbsd/lib/libc/stdio/fwide.c",
         "upstream-openbsd/lib/libc/stdio/getdelim.c",
         "upstream-openbsd/lib/libc/stdio/gets.c",
-        "upstream-openbsd/lib/libc/stdio/makebuf.c",
         "upstream-openbsd/lib/libc/stdio/mktemp.c",
         "upstream-openbsd/lib/libc/stdio/open_memstream.c",
         "upstream-openbsd/lib/libc/stdio/open_wmemstream.c",
         "upstream-openbsd/lib/libc/stdio/rget.c",
-        "upstream-openbsd/lib/libc/stdio/setvbuf.c",
         "upstream-openbsd/lib/libc/stdio/ungetc.c",
         "upstream-openbsd/lib/libc/stdio/ungetwc.c",
         "upstream-openbsd/lib/libc/stdio/vasprintf.c",
@@ -565,37 +508,15 @@
         "upstream-openbsd/lib/libc/stdio/vswscanf.c",
         "upstream-openbsd/lib/libc/stdio/wbuf.c",
         "upstream-openbsd/lib/libc/stdio/wsetup.c",
-        "upstream-openbsd/lib/libc/stdlib/abs.c",
-        "upstream-openbsd/lib/libc/stdlib/div.c",
         "upstream-openbsd/lib/libc/stdlib/getenv.c",
         "upstream-openbsd/lib/libc/stdlib/getsubopt.c",
-        "upstream-openbsd/lib/libc/stdlib/insque.c",
-        "upstream-openbsd/lib/libc/stdlib/imaxabs.c",
-        "upstream-openbsd/lib/libc/stdlib/imaxdiv.c",
-        "upstream-openbsd/lib/libc/stdlib/labs.c",
-        "upstream-openbsd/lib/libc/stdlib/ldiv.c",
-        "upstream-openbsd/lib/libc/stdlib/llabs.c",
-        "upstream-openbsd/lib/libc/stdlib/lldiv.c",
-        "upstream-openbsd/lib/libc/stdlib/lsearch.c",
         "upstream-openbsd/lib/libc/stdlib/recallocarray.c",
-        "upstream-openbsd/lib/libc/stdlib/remque.c",
         "upstream-openbsd/lib/libc/stdlib/setenv.c",
         "upstream-openbsd/lib/libc/stdlib/tfind.c",
         "upstream-openbsd/lib/libc/stdlib/tsearch.c",
-        "upstream-openbsd/lib/libc/string/memccpy.c",
-        "upstream-openbsd/lib/libc/string/strcasecmp.c",
         "upstream-openbsd/lib/libc/string/strcasestr.c",
-        "upstream-openbsd/lib/libc/string/strcoll.c",
-        "upstream-openbsd/lib/libc/string/strcspn.c",
         "upstream-openbsd/lib/libc/string/strdup.c",
         "upstream-openbsd/lib/libc/string/strndup.c",
-        "upstream-openbsd/lib/libc/string/strpbrk.c",
-        "upstream-openbsd/lib/libc/string/strsep.c",
-        "upstream-openbsd/lib/libc/string/strspn.c",
-        "upstream-openbsd/lib/libc/string/strtok.c",
-        "upstream-openbsd/lib/libc/string/strxfrm.c",
-        "upstream-openbsd/lib/libc/string/wcslcpy.c",
-        "upstream-openbsd/lib/libc/string/wcswidth.c",
 
         // These files are originally from OpenBSD,
         // and benefit from being compiled with openbsd-compat.h.
@@ -655,8 +576,6 @@
         "upstream-openbsd/lib/libc/include/",
         "upstream-openbsd/lib/libc/stdio/",
     ],
-
-    name: "libc_openbsd",
 }
 
 cc_library_static {
@@ -685,6 +604,7 @@
 // automatically included.
 
 cc_library_static {
+    name: "libc_gdtoa",
     defaults: ["libc_defaults"],
     srcs: [
         "upstream-openbsd/android/gdtoa_support.cpp",
@@ -722,8 +642,6 @@
         "upstream-openbsd/android/include",
         "upstream-openbsd/lib/libc/include",
     ],
-
-    name: "libc_gdtoa",
 }
 
 // ========================================================
@@ -731,11 +649,10 @@
 // implementation details
 // ========================================================
 cc_library_static {
+    name: "libc_fortify",
     defaults: ["libc_defaults"],
     srcs: ["bionic/fortify.cpp"],
 
-    name: "libc_fortify",
-
     // Disable FORTIFY for the compilation of these, so we don't end up having
     // FORTIFY silently call itself.
     cflags: [
@@ -750,25 +667,25 @@
                 "-DRENAME___STRCPY_CHK",
             ],
             srcs: [
-                "arch-arm/generic/bionic/__memcpy_chk.S",
+                "arch-arm/generic/string/__memcpy_chk.S",
 
-                "arch-arm/cortex-a15/bionic/__strcat_chk.S",
-                "arch-arm/cortex-a15/bionic/__strcpy_chk.S",
+                "arch-arm/cortex-a15/string/__strcat_chk.S",
+                "arch-arm/cortex-a15/string/__strcpy_chk.S",
 
-                "arch-arm/cortex-a7/bionic/__strcat_chk.S",
-                "arch-arm/cortex-a7/bionic/__strcpy_chk.S",
+                "arch-arm/cortex-a7/string/__strcat_chk.S",
+                "arch-arm/cortex-a7/string/__strcpy_chk.S",
 
-                "arch-arm/cortex-a9/bionic/__strcat_chk.S",
-                "arch-arm/cortex-a9/bionic/__strcpy_chk.S",
+                "arch-arm/cortex-a9/string/__strcat_chk.S",
+                "arch-arm/cortex-a9/string/__strcpy_chk.S",
 
-                "arch-arm/krait/bionic/__strcat_chk.S",
-                "arch-arm/krait/bionic/__strcpy_chk.S",
+                "arch-arm/krait/string/__strcat_chk.S",
+                "arch-arm/krait/string/__strcpy_chk.S",
 
-                "arch-arm/cortex-a53/bionic/__strcat_chk.S",
-                "arch-arm/cortex-a53/bionic/__strcpy_chk.S",
+                "arch-arm/cortex-a53/string/__strcat_chk.S",
+                "arch-arm/cortex-a53/string/__strcpy_chk.S",
 
-                "arch-arm/cortex-a55/bionic/__strcat_chk.S",
-                "arch-arm/cortex-a55/bionic/__strcpy_chk.S",
+                "arch-arm/cortex-a55/string/__strcat_chk.S",
+                "arch-arm/cortex-a55/string/__strcpy_chk.S",
             ],
         },
         arm64: {
@@ -832,6 +749,7 @@
 // ========================================================
 
 cc_library_static {
+    name: "libc_bionic",
     defaults: ["libc_defaults"],
     srcs: [
         "bionic/NetdClientDispatch.cpp",
@@ -842,6 +760,7 @@
         "bionic/__gnu_basename.cpp",
         "bionic/__libc_current_sigrtmax.cpp",
         "bionic/__libc_current_sigrtmin.cpp",
+        "bionic/__progname.cpp",
         "bionic/abort.cpp",
         "bionic/accept.cpp",
         "bionic/access.cpp",
@@ -862,6 +781,7 @@
         "bionic/brk.cpp",
         "bionic/c16rtomb.cpp",
         "bionic/c32rtomb.cpp",
+        "bionic/casecmp.cpp",
         "bionic/chmod.cpp",
         "bionic/chown.cpp",
         "bionic/clearenv.cpp",
@@ -872,7 +792,9 @@
         "bionic/ctype.cpp",
         "bionic/dirent.cpp",
         "bionic/dup.cpp",
+        "bionic/endian.cpp",
         "bionic/environ.cpp",
+        "bionic/err.cpp",
         "bionic/error.cpp",
         "bionic/eventfd.cpp",
         "bionic/exec.cpp",
@@ -894,7 +816,6 @@
         "bionic/ftw.cpp",
         "bionic/futimens.cpp",
         "bionic/getcwd.cpp",
-        "bionic/getdomainname.cpp",
         "bionic/getentropy.cpp",
         "bionic/gethostname.cpp",
         "bionic/getloadavg.cpp",
@@ -1005,7 +926,6 @@
         "bionic/stdlib_l.cpp",
         "bionic/strerror.cpp",
         "bionic/string_l.cpp",
-        "bionic/strings_l.cpp",
         "bionic/strsignal.cpp",
         "bionic/strtol.cpp",
         "bionic/strtold.cpp",
@@ -1030,13 +950,13 @@
         "bionic/system_property_set.cpp",
         "bionic/tdestroy.cpp",
         "bionic/termios.cpp",
-        "bionic/thread_private.cpp",
         "bionic/threads.cpp",
         "bionic/time.cpp",
         "bionic/tmpfile.cpp",
         "bionic/umount.cpp",
         "bionic/unlink.cpp",
         "bionic/usleep.cpp",
+        "bionic/utime.cpp",
         "bionic/utmp.cpp",
         "bionic/vdso.cpp",
         "bionic/wait.cpp",
@@ -1045,7 +965,6 @@
         "bionic/wcstod.cpp",
         "bionic/wctype.cpp",
         "bionic/wcwidth.cpp",
-        "bionic/wmempcpy.cpp",
 
         // Forked but not yet cleaned up/rewritten stdio code.
         // TODO: finish cleanup.
@@ -1074,42 +993,35 @@
                 "arch-arm/bionic/syscall.S",
                 "arch-arm/bionic/vfork.S",
 
-                "arch-arm/cortex-a7/bionic/memcpy.S",
-                "arch-arm/cortex-a7/bionic/memset.S",
+                "arch-arm/cortex-a7/string/memcpy.S",
+                "arch-arm/cortex-a7/string/memset.S",
 
-                "arch-arm/cortex-a9/bionic/memcpy.S",
-                "arch-arm/cortex-a9/bionic/memset.S",
-                "arch-arm/cortex-a9/bionic/stpcpy.S",
-                "arch-arm/cortex-a9/bionic/strcat.S",
-                "arch-arm/cortex-a9/bionic/strcpy.S",
-                "arch-arm/cortex-a9/bionic/strlen.S",
+                "arch-arm/cortex-a9/string/memcpy.S",
+                "arch-arm/cortex-a9/string/memset.S",
+                "arch-arm/cortex-a9/string/stpcpy.S",
+                "arch-arm/cortex-a9/string/strcat.S",
+                "arch-arm/cortex-a9/string/strcpy.S",
+                "arch-arm/cortex-a9/string/strlen.S",
 
-                "arch-arm/cortex-a15/bionic/memcpy.S",
-                "arch-arm/cortex-a15/bionic/memmove.S",
-                "arch-arm/cortex-a15/bionic/memset.S",
-                "arch-arm/cortex-a15/bionic/stpcpy.S",
-                "arch-arm/cortex-a15/bionic/strcat.S",
-                "arch-arm/cortex-a15/bionic/strcmp.S",
-                "arch-arm/cortex-a15/bionic/strcpy.S",
-                "arch-arm/cortex-a15/bionic/strlen.S",
+                "arch-arm/cortex-a15/string/memcpy.S",
+                "arch-arm/cortex-a15/string/memmove.S",
+                "arch-arm/cortex-a15/string/memset.S",
+                "arch-arm/cortex-a15/string/stpcpy.S",
+                "arch-arm/cortex-a15/string/strcat.S",
+                "arch-arm/cortex-a15/string/strcmp.S",
+                "arch-arm/cortex-a15/string/strcpy.S",
+                "arch-arm/cortex-a15/string/strlen.S",
 
-                "arch-arm/cortex-a53/bionic/memcpy.S",
+                "arch-arm/cortex-a53/string/memcpy.S",
 
-                "arch-arm/cortex-a55/bionic/memcpy.S",
+                "arch-arm/cortex-a55/string/memcpy.S",
 
-                "arch-arm/generic/bionic/memcmp.S",
-                "arch-arm/generic/bionic/memmove.S",
-                "arch-arm/generic/bionic/memset.S",
-                "arch-arm/generic/bionic/stpcpy.c",
-                "arch-arm/generic/bionic/strcat.c",
-                "arch-arm/generic/bionic/strcmp.S",
-                "arch-arm/generic/bionic/strcpy.S",
-                "arch-arm/generic/bionic/strlen.c",
+                "arch-arm/generic/string/memcmp.S",
 
-                "arch-arm/krait/bionic/memcpy.S",
-                "arch-arm/krait/bionic/memset.S",
+                "arch-arm/krait/string/memcpy.S",
+                "arch-arm/krait/string/memset.S",
 
-                "arch-arm/kryo/bionic/memcpy.S",
+                "arch-arm/kryo/string/memcpy.S",
             ],
         },
         arm64: {
@@ -1186,6 +1098,7 @@
                 "arch-x86_64/bionic/syscall.S",
                 "arch-x86_64/bionic/vfork.S",
 
+                "arch-x86_64/string/avx2-memmove-kbl.S",
                 "arch-x86_64/string/avx2-memset-kbl.S",
                 "arch-x86_64/string/sse2-memmove-slm.S",
                 "arch-x86_64/string/sse2-memset-slm.S",
@@ -1224,7 +1137,6 @@
 
     cppflags: ["-Wold-style-cast"],
     include_dirs: ["bionic/libstdc++/include"],
-    name: "libc_bionic",
 }
 
 genrule {
@@ -1280,6 +1192,7 @@
 }
 
 cc_library_static {
+    name: "libc_syscalls",
     defaults: ["libc_defaults"],
     srcs: ["bionic/__set_errno.cpp"],
     arch: {
@@ -1299,7 +1212,6 @@
             srcs: [":syscalls-x86_64"],
         },
     },
-    name: "libc_syscalls",
 }
 
 // ========================================================
@@ -1310,13 +1222,13 @@
 // ========================================================
 
 cc_library_static {
+    name: "libc_aeabi",
     defaults: ["libc_defaults"],
     arch: {
         arm: {
             srcs: ["arch-arm/bionic/__aeabi.c"],
         },
     },
-    name: "libc_aeabi",
     cflags: ["-fno-builtin"],
 }
 
@@ -1325,8 +1237,8 @@
 // ========================================================
 
 cc_library_static {
-    defaults: ["libc_defaults"],
     name: "libc_common",
+    defaults: ["libc_defaults"],
 
     whole_static_libs: [
         "libarm-optimized-routines-string",
@@ -1356,24 +1268,23 @@
 
 // ========================================================
 // libc_static_dispatch.a/libc_dynamic_dispatch.a --- string/memory "ifuncs"
-// (Actually ifuncs for libc.so, but a home-grown alternative for libc.a.)
 // ========================================================
 
 cc_defaults {
-    name: "libc_dispatch_defaults",
+    name: "libc_ifunc_defaults",
     defaults: ["libc_defaults"],
     arch: {
-        x86_64: {
-            srcs: ["arch-x86_64/dynamic_function_dispatch.cpp"],
-        },
-        x86: {
-            srcs: ["arch-x86/dynamic_function_dispatch.cpp"],
-        },
         arm: {
-            srcs: ["arch-arm/dynamic_function_dispatch.cpp"],
+            srcs: ["arch-arm/ifuncs.cpp"],
         },
         arm64: {
-            srcs: ["arch-arm64/dynamic_function_dispatch.cpp"],
+            srcs: ["arch-arm64/ifuncs.cpp"],
+        },
+        x86: {
+            srcs: ["arch-x86/ifuncs.cpp"],
+        },
+        x86_64: {
+            srcs: ["arch-x86_64/ifuncs.cpp"],
         },
     },
     // Prevent the compiler from inserting calls to libc/taking the address of
@@ -1388,7 +1299,7 @@
 
 cc_library_static {
     name: "libc_static_dispatch",
-    defaults: ["libc_dispatch_defaults"],
+    defaults: ["libc_ifunc_defaults"],
     cflags: [
         "-DBIONIC_STATIC_DISPATCH",
     ],
@@ -1396,7 +1307,7 @@
 
 cc_library_static {
     name: "libc_dynamic_dispatch",
-    defaults: ["libc_dispatch_defaults"],
+    defaults: ["libc_ifunc_defaults"],
     cflags: [
         "-DBIONIC_DYNAMIC_DISPATCH",
     ],
@@ -1406,8 +1317,8 @@
 // libc_common_static.a For static binaries.
 // ========================================================
 cc_library_static {
-    defaults: ["libc_defaults"],
     name: "libc_common_static",
+    defaults: ["libc_defaults"],
 
     whole_static_libs: [
         "libc_common",
@@ -1419,8 +1330,8 @@
 // libc_common_shared.a For shared libraries.
 // ========================================================
 cc_library_static {
-    defaults: ["libc_defaults"],
     name: "libc_common_shared",
+    defaults: ["libc_defaults"],
 
     whole_static_libs: [
         "libc_common",
@@ -1506,13 +1417,13 @@
 // libc.a + libc.so
 // ========================================================
 cc_defaults {
+    name: "libc_library_defaults",
     defaults: [
         "libc_defaults",
         "libc_native_allocator_defaults",
         "bug_24465209_workaround",
         "keep_symbols",
     ],
-    name: "libc_library_defaults",
     product_variables: {
         platform_sdk_version: {
             asflags: ["-DPLATFORM_SDK_VERSION=%d"],
@@ -1627,6 +1538,7 @@
         export_headers_as_system: true,
         export_llndk_headers: ["libc_headers"],
     },
+    afdo: true,
 }
 
 cc_library {
@@ -1708,7 +1620,6 @@
         "//art:__subpackages__",
         "//bionic:__subpackages__",
         "//frameworks:__subpackages__",
-        "//device/generic/goldfish-opengl:__subpackages__",
         "//external/gwp_asan:__subpackages__",
         "//external/perfetto:__subpackages__",
         "//external/scudo:__subpackages__",
@@ -1852,6 +1763,7 @@
 // ========================================================
 
 cc_library {
+    name: "libstdc++",
     defaults: [
         "libc_defaults",
         "bug_24465209_workaround",
@@ -1862,7 +1774,6 @@
         "bionic/__cxa_pure_virtual.cpp",
         "bionic/new.cpp",
     ],
-    name: "libstdc++",
     static_ndk_lib: true,
     static_libs: ["libasync_safe"],
     apex_available: [
@@ -1957,7 +1868,7 @@
         "//apex_available:anyapex",
     ],
     // Generate NDK variants of the CRT objects for every supported API level.
-    min_sdk_version: "16",
+    min_sdk_version: "21",
     stl: "none",
     crt: true,
     cflags: [
@@ -1973,6 +1884,11 @@
 cc_defaults {
     name: "crt_defaults",
     defaults: ["crt_and_memtag_defaults"],
+    header_libs: ["libc_headers"],
+    local_include_dirs: [
+        "bionic", // crtbegin includes bionic/libc_init_common.h
+        "private", // crtbrand depends on private/bionic_asm_note.h
+    ],
     system_shared_libs: [],
 }
 
@@ -1984,9 +1900,7 @@
 
 cc_object {
     name: "crtbrand",
-    local_include_dirs: [
-        "private", // crtbrand.S depends on private/bionic_asm_note.h
-    ],
+    defaults: ["crt_so_defaults"],
     // crtbrand.S needs to know the platform SDK version.
     product_variables: {
         platform_sdk_version: {
@@ -1994,18 +1908,14 @@
         },
     },
     srcs: ["arch-common/bionic/crtbrand.S"],
-
-    defaults: ["crt_so_defaults"],
     // crtbrand is an intermediate artifact, not a final CRT object.
     exclude_from_ndk_sysroot: true,
 }
 
 cc_object {
     name: "crtbegin_so",
-    local_include_dirs: ["include"],
-    srcs: ["arch-common/bionic/crtbegin_so.c"],
-
     defaults: ["crt_so_defaults"],
+    srcs: ["arch-common/bionic/crtbegin_so.c"],
     objs: [
         "crtbrand",
     ],
@@ -2013,40 +1923,25 @@
 
 cc_object {
     name: "crtend_so",
-    local_include_dirs: [
-        "private", // crtend_so.S depends on private/bionic_asm_arm64.h
-    ],
-    srcs: ["arch-common/bionic/crtend_so.S"],
-
     defaults: ["crt_so_defaults"],
+    srcs: ["arch-common/bionic/crtend_so.S"],
 }
 
 cc_object {
     name: "crtbegin_static",
-
-    local_include_dirs: [
-        "include",
-        "bionic", // crtbegin.c includes bionic/libc_init_common.h
-    ],
-
+    defaults: ["crt_defaults"],
     cflags: ["-DCRTBEGIN_STATIC"],
-
     srcs: ["arch-common/bionic/crtbegin.c"],
     objs: [
         "crtbrand",
     ],
-    defaults: ["crt_defaults"],
     // When using libc.a, we're using the latest library regardless of target API level.
     min_sdk_version: "current",
 }
 
 cc_object {
     name: "crtbegin_dynamic",
-
-    local_include_dirs: [
-        "include",
-        "bionic", // crtbegin.c includes bionic/libc_init_common.h
-    ],
+    defaults: ["crt_defaults"],
     srcs: ["arch-common/bionic/crtbegin.c"],
     objs: [
         "crtbrand",
@@ -2059,53 +1954,42 @@
             ],
         },
     },
-    defaults: ["crt_defaults"],
 }
 
 cc_object {
     // We rename crtend.o to crtend_android.o to avoid a
     // name clash between gcc and bionic.
     name: "crtend_android",
-    local_include_dirs: [
-        "private", // crtend.S depends on private/bionic_asm_arm64.h
-    ],
-    srcs: ["arch-common/bionic/crtend.S"],
-
     defaults: ["crt_defaults"],
+    srcs: ["arch-common/bionic/crtend.S"],
 }
 
 cc_object {
     name: "crt_pad_segment",
-    local_include_dirs: [
-        "private", // crt_pad_segment.S depends on private/bionic_asm_note.h
-    ],
-    srcs: ["arch-common/bionic/crt_pad_segment.S"],
-
     defaults: ["crt_defaults"],
+    srcs: ["arch-common/bionic/crt_pad_segment.S"],
 }
 
 cc_library_static {
     name: "note_memtag_heap_async",
+    defaults: ["crt_and_memtag_defaults"],
     arch: {
         arm64: {
             srcs: ["arch-arm64/bionic/note_memtag_heap_async.S"],
         },
     },
     sdk_version: "minimum",
-
-    defaults: ["crt_and_memtag_defaults"],
 }
 
 cc_library_static {
     name: "note_memtag_heap_sync",
+    defaults: ["crt_and_memtag_defaults"],
     arch: {
         arm64: {
             srcs: ["arch-arm64/bionic/note_memtag_heap_sync.S"],
         },
     },
     sdk_version: "minimum",
-
-    defaults: ["crt_and_memtag_defaults"],
 }
 
 // ========================================================
@@ -2128,6 +2012,11 @@
     cflags: [
         "-Wall",
         "-Werror",
+
+        "-DBIONIC_RUST_BAREMETAL",
+    ],
+    asflags: [
+        "-DBIONIC_RUST_BAREMETAL",
     ],
     srcs: [
         "bionic/fortify.cpp",
@@ -2147,9 +2036,11 @@
         },
         x86_64: {
             asflags: [
-                // Statically choose the SSE2 memset_generic as memset for
-                // baremetal, where we do not have the dynamic function
-                // dispatch machinery.
+                // Statically choose the SSE2 variants for baremetal,
+                // where we do not have the dynamic function dispatch
+                // machinery.
+                "-D__memcpy_chk_generic=__memcpy_chk",
+                "-Dmemmove_generic=memmove",
                 "-Dmemset_generic=memset",
             ],
             srcs: [
@@ -2171,7 +2062,6 @@
     whole_static_libs: [
         "//external/llvm-libc:llvmlibc",
         "libarm-optimized-routines-mem",
-        "libc_netbsd",
     ],
     system_shared_libs: [],
     nocrt: true,
@@ -2825,6 +2715,7 @@
         "kernel/android/**/*.h",
         "execinfo/include/**/*.h",
         "b64/include/**/*.h",
+        "include/*.h",
 
         "NOTICE",
 
diff --git a/libc/NOTICE b/libc/NOTICE
index c869a31..b372199 100644
--- a/libc/NOTICE
+++ b/libc/NOTICE
@@ -1,31 +1,3 @@
- Copyright (c) 1993 John Brezak
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions
- are met:
- 1. Redistributions of source code must retain the above copyright
-    notice, this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright
-    notice, this list of conditions and the following disclaimer in the
-    documentation and/or other materials provided with the distribution.
- 3. The name of the author may 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) 2009-2013 The Linux Foundation. All rights reserved.
 
  Redistribution and use in source and binary forms, with or without
@@ -315,37 +287,6 @@
 
 -------------------------------------------------------------------
 
-Copyright (C) 2010 The Android Open Source Project
-Copyright (c) 2008 ARM Ltd
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions
-are met:
-1. Redistributions of source code must retain the above copyright
-   notice, this list of conditions and the following disclaimer.
-2. Redistributions in binary form must reproduce the above copyright
-   notice, this list of conditions and the following disclaimer in the
-   documentation and/or other materials provided with the distribution.
-3. The name of the company may not be used to endorse or promote
-   products derived from this software without specific prior written
-   permission.
-
-THIS SOFTWARE IS PROVIDED BY ARM LTD ``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 ARM LTD 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.
-
-Android adaptation and tweak by Jim Huang <jserv@0xlab.org>.
-
--------------------------------------------------------------------
-
 Copyright (C) 2011 The Android Open Source Project
 All rights reserved.
 
@@ -934,6 +875,50 @@
 
 -------------------------------------------------------------------
 
+Copyright (C) 2025 The Android Open Source Project
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+-------------------------------------------------------------------
+
+Copyright (C) 2025 The Android Open Source Project
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+ * Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in
+   the documentation and/or other materials provided with the
+   distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGE.
+
+-------------------------------------------------------------------
+
 Copyright (c) 1980, 1983, 1988, 1993
    The Regents of the University of California.  All rights reserved.
 
@@ -1805,38 +1790,6 @@
 
 Copyright (c) 1989, 1993
    The Regents of the University of California.  All rights reserved.
-
-This code is derived from software contributed to Berkeley by
-Roger L. Snyder.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions
-are met:
-1. Redistributions of source code must retain the above copyright
-   notice, this list of conditions and the following disclaimer.
-2. Redistributions in binary form must reproduce the above copyright
-   notice, this list of conditions and the following disclaimer in the
-   documentation and/or other materials provided with the distribution.
-3. Neither the name of the University nor the names of its contributors
-   may be used to endorse or promote products derived from this software
-   without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-SUCH DAMAGE.
-
--------------------------------------------------------------------
-
-Copyright (c) 1989, 1993
-   The Regents of the University of California.  All rights reserved.
 (c) UNIX System Laboratories, Inc.
 All or some portions of this file are derived from material licensed
 to the University of California by American Telephone and Telegraph
@@ -1869,38 +1822,6 @@
 
 -------------------------------------------------------------------
 
-Copyright (c) 1990 Regents of the University of California.
-All rights reserved.
-
-This code is derived from software contributed to Berkeley by
-Chris Torek.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions
-are met:
-1. Redistributions of source code must retain the above copyright
-   notice, this list of conditions and the following disclaimer.
-2. Redistributions in binary form must reproduce the above copyright
-   notice, this list of conditions and the following disclaimer in the
-   documentation and/or other materials provided with the distribution.
-3. Neither the name of the University nor the names of its contributors
-   may be used to endorse or promote products derived from this software
-   without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-SUCH DAMAGE.
-
--------------------------------------------------------------------
-
 Copyright (c) 1990 The Regents of the University of California.
 All rights reserved.
 
@@ -2182,35 +2103,6 @@
 
 -------------------------------------------------------------------
 
-Copyright (c) 1991 The Regents of the University of California.
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions
-are met:
-1. Redistributions of source code must retain the above copyright
-   notice, this list of conditions and the following disclaimer.
-2. Redistributions in binary form must reproduce the above copyright
-   notice, this list of conditions and the following disclaimer in the
-   documentation and/or other materials provided with the distribution.
-3. Neither the name of the University nor the names of its contributors
-   may be used to endorse or promote products derived from this software
-   without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-SUCH DAMAGE.
-
--------------------------------------------------------------------
-
 Copyright (c) 1991, 1993
    The Regents of the University of California.  All rights reserved.
 
@@ -2703,35 +2595,6 @@
 
 -------------------------------------------------------------------
 
-Copyright (c) 1997 The NetBSD Foundation, Inc.
-All rights reserved.
-
-This code is derived from software contributed to The NetBSD Foundation
-by Neil A. Carson and Mark Brinicombe
-
-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.
-
--------------------------------------------------------------------
-
 Copyright (c) 1997 Todd C. Miller <millert@openbsd.org>
 
 Permission to use, copy, modify, and distribute this software for any
@@ -2920,22 +2783,6 @@
 
 -------------------------------------------------------------------
 
-Copyright (c) 1998, 2015 Todd C. Miller <millert@openbsd.org>
-
-Permission to use, copy, modify, and distribute this software for any
-purpose with or without fee is hereby granted, provided that the above
-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) 2000 Ben Harris.
 Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
 All rights reserved.
@@ -3878,35 +3725,6 @@
 
 -------------------------------------------------------------------
 
-Copyright (c) 2011 The Android Open Source Project
-Copyright (c) 2008 ARM Ltd
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions
-are met:
-1. Redistributions of source code must retain the above copyright
-   notice, this list of conditions and the following disclaimer.
-2. Redistributions in binary form must reproduce the above copyright
-   notice, this list of conditions and the following disclaimer in the
-   documentation and/or other materials provided with the distribution.
-3. The name of the company may not be used to endorse or promote
-   products derived from this software without specific prior written
-   permission.
-
-THIS SOFTWARE IS PROVIDED BY ARM LTD ``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 ARM LTD 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, Intel Corporation
 All rights reserved.
 
@@ -3966,7 +3784,7 @@
 
 Copyright (c) 2012, Linaro Limited
    All rights reserved.
-   Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
+   Copyright (c) 2025 Qualcomm Innovation Center, Inc. All rights reserved.
    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions are met:
        * Redistributions of source code must retain the above copyright
@@ -4047,22 +3865,6 @@
 
 -------------------------------------------------------------------
 
-Copyright (c) 2013 Antoine Jacoutot <ajacoutot@openbsd.org>
-
-Permission to use, copy, modify, and distribute this software for any
-purpose with or without fee is hereby granted, provided that the above
-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) 2013 The NetBSD Foundation, Inc.
 All rights reserved.
 
@@ -4175,29 +3977,33 @@
 
 -------------------------------------------------------------------
 
-Copyright (c)1999 Citrus Project,
+Copyright (c) 2024, Intel Corporation
 All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions
-are met:
-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.
+modification, are permitted provided that the following conditions are met:
 
-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.
+    * Redistributions of source code must retain the above copyright notice,
+    * this list of conditions and the following disclaimer.
+
+    * Redistributions in binary form must reproduce the above copyright notice,
+    * this list of conditions and the following disclaimer in the documentation
+    * and/or other materials provided with the distribution.
+
+    * Neither the name of Intel Corporation nor the names of its contributors
+    * may be used to endorse or promote products derived from this software
+    * without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 -------------------------------------------------------------------
 
@@ -4227,32 +4033,6 @@
 
 -------------------------------------------------------------------
 
-Copyright (c)2003 Citrus Project,
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions
-are met:
-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 1989 The Regents of the University of California.
    All rights reserved.
 
@@ -4439,34 +4219,6 @@
 
 SPDX-License-Identifier: BSD-2-Clause
 
-Copyright (c) 2002 Tim J. Robbins
-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
-
 Copyright (c) 2005 Tim J. Robbins.
 All rights reserved.
 
@@ -4495,35 +4247,8 @@
 
 SPDX-License-Identifier: BSD-2-Clause
 
-Copyright (c) 2009 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
-
 Copyright (c) 2011 David Chisnall
+Copyright (c) 2023 Klara, Inc.
 All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
@@ -4606,130 +4331,6 @@
 
 -------------------------------------------------------------------
 
-SPDX-License-Identifier: BSD-2-Clause
-
-Copyright (c)1999 Citrus Project,
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions
-are met:
-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) 1989, 1993
-   The Regents of the University of California.  All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions
-are met:
-1. Redistributions of source code must retain the above copyright
-   notice, this list of conditions and the following disclaimer.
-2. Redistributions in binary form must reproduce the above copyright
-   notice, this list of conditions and the following disclaimer in the
-   documentation and/or other materials provided with the distribution.
-3. Neither the name of the University nor the names of its contributors
-   may be used to endorse or promote products derived from this software
-   without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-SUCH DAMAGE.
-
--------------------------------------------------------------------
-
-SPDX-License-Identifier: BSD-3-Clause
-
-Copyright (c) 1990, 1993
-   The Regents of the University of California.  All rights reserved.
-
-This code is derived from software contributed to Berkeley by
-Chris Torek.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions
-are met:
-1. Redistributions of source code must retain the above copyright
-   notice, this list of conditions and the following disclaimer.
-2. Redistributions in binary form must reproduce the above copyright
-   notice, this list of conditions and the following disclaimer in the
-   documentation and/or other materials provided with the distribution.
-3. Neither the name of the University nor the names of its contributors
-   may be used to endorse or promote products derived from this software
-   without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-SUCH DAMAGE.
-
--------------------------------------------------------------------
-
-SPDX-License-Identifier: BSD-3-Clause
-
-Copyright (c) 1992, 1993
-   The Regents of the University of California.  All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions
-are met:
-1. Redistributions of source code must retain the above copyright
-   notice, this list of conditions and the following disclaimer.
-2. Redistributions in binary form must reproduce the above copyright
-   notice, this list of conditions and the following disclaimer in the
-   documentation and/or other materials provided with the distribution.
-3. Neither the name of the University nor the names of its contributors
-   may be used to endorse or promote products derived from this software
-   without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-SUCH DAMAGE.
-
--------------------------------------------------------------------
-
 SPDX-License-Identifier: BSD-3-Clause
 
 Copyright (c) 1992, 1993, 1994 Henry Spencer.
@@ -4805,104 +4406,6 @@
 
 -------------------------------------------------------------------
 
-SPDX-License-Identifier: BSD-3-Clause
-
-Copyright (c) 1998 Softweyr LLC.  All rights reserved.
-
-strtok_r, from Berkeley strtok
-Oct 13, 1998 by Wes Peters <wes@softweyr.com>
-
-Copyright (c) 1988, 1993
-   The Regents of the University of California.  All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions
-are met:
-1. Redistributions of source code must retain the above copyright
-   notices, this list of conditions and the following disclaimer.
-2. Redistributions in binary form must reproduce the above copyright
-   notices, this list of conditions and the following disclaimer in the
-   documentation and/or other materials provided with the distribution.
-3. Neither the name of the University nor the names of its contributors
-   may be used to endorse or promote products derived from this software
-   without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY SOFTWEYR LLC, THE REGENTS AND CONTRIBUTORS
-``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
-PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL SOFTWEYR LLC, THE
-REGENTS, OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
-TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
--------------------------------------------------------------------
-
-SPDX-License-Identifier: BSD-3-Clause
-
-Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions
-are met:
-1. Redistributions of source code must retain the above copyright
-   notice, this list of conditions and the following disclaimer.
-2. Redistributions in binary form must reproduce the above copyright
-   notice, this list of conditions and the following disclaimer in the
-   documentation and/or other materials provided with the distribution.
-3. 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 ``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-3-Clause
-
-Copyright (c) 1999
-   David E. O'Brien
-Copyright (c) 1988, 1993
-   The Regents of the University of California.  All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions
-are met:
-1. Redistributions of source code must retain the above copyright
-   notice, this list of conditions and the following disclaimer.
-2. Redistributions in binary form must reproduce the above copyright
-   notice, this list of conditions and the following disclaimer in the
-   documentation and/or other materials provided with the distribution.
-3. Neither the name of the University nor the names of its contributors
-   may be used to endorse or promote products derived from this software
-   without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-SUCH DAMAGE.
-
--------------------------------------------------------------------
-
 The author of this software is David M. Gay.
 
 Copyright (C) 1998 by Lucent Technologies
diff --git a/libc/SECCOMP_ALLOWLIST_APP.TXT b/libc/SECCOMP_ALLOWLIST_APP.TXT
index 20f9ae0..4e339b4 100644
--- a/libc/SECCOMP_ALLOWLIST_APP.TXT
+++ b/libc/SECCOMP_ALLOWLIST_APP.TXT
@@ -12,7 +12,6 @@
 
 # b/34813887
 open(const char *path, int oflag, ... ) lp32,x86_64
-getdents(unsigned int fd, struct linux_dirent *dirp, unsigned int count) lp32,x86_64
 
 # b/34719286
 eventfd(unsigned int initval, int flags)	lp32
diff --git a/libc/SECCOMP_ALLOWLIST_COMMON.TXT b/libc/SECCOMP_ALLOWLIST_COMMON.TXT
index 41db4e8..adf1b01 100644
--- a/libc/SECCOMP_ALLOWLIST_COMMON.TXT
+++ b/libc/SECCOMP_ALLOWLIST_COMMON.TXT
@@ -3,6 +3,21 @@
 #
 # This file is processed by a python script named genseccomp.py.
 
+# These are the syscalls that are currently still multiplexed through socketcall(2) for x86.
+# We put them here for the convenience of anyone who wants to transition early,
+# or rewrite socketcall() invocations as the individual syscalls.
+# TODO: remove these when the socketcall transition is complete
+socket(int, int, int) x86
+socketpair(int, int, int, int*) x86
+connect(int, sockaddr*, socklen_t) x86
+sendto(int, const void*, size_t, int, const sockaddr*, socklen_t) x86
+recvfrom(int, void*, size_t, unsigned int, sockaddr*, socklen_t*) x86
+shutdown(int, int) x86
+setsockopt(int, int, int, const void*, socklen_t) x86
+getsockopt(int, int, int, void*, socklen_t*) x86
+recvmsg(int, msghdr*, unsigned int) x86
+sendmsg(int, const msghdr*, unsigned int) x86
+
 # Syscalls needed to boot android
 pivot_root(const char*, const char*)	lp64
 ioprio_get(int, int)	lp64
@@ -79,8 +94,21 @@
 # support seems potentially useful for Android (though the struct that
 # changes size over time is obviously problematic).
 clone3(clone_args*, size_t) all
-# Since 5.13, not in glibc. Probed for and conditionally used by
+# Since Linux 5.6, not in glibc (but coming to 2.42?). http://b/371578624
+openat2(int, const char*, open_how*, size_t) all
+# Since Linux 5.8, not in glibc. Commonly requested to reimplement faccessat()
+# for better source compatibility, but tricky to retcon into all the seccomp filters.
+faccessat2(int, const char*, int, int) all
+# Since Linux 5.13, not in glibc. Probed for and conditionally used by
 # Chrome GPU processes.
 landlock_add_rule(int, uint64_t, const void*, uint32_t) all
 landlock_create_ruleset(const landlock_ruleset_attr*, size_t, uint64_t) all
 landlock_restrict_self(int, uint64_t) all
+# Since Linux 6.6, not in glibc. Common requested to reimplement fchmodat()
+# for better source compatibility, but tricky to retcon into all the seccomp filters.
+fchmodat2(int, const char*, mode_t, int) all
+# Since Linux 6.13, not in glibc.
+setxattrat(int, const char*, unsigned, const char*, const xattr_args*, size_t) all
+getxattrat(int, const char*, unsigned, const char*, xattr_args*, size_t) all
+listxattrat(int, const char*, unsigned, char*, size_t) all
+removexattrat(int, const char*, unsigned, const char*) all
diff --git a/libc/SECCOMP_ALLOWLIST_SYSTEM.TXT b/libc/SECCOMP_ALLOWLIST_SYSTEM.TXT
index ac90aac..5454411 100644
--- a/libc/SECCOMP_ALLOWLIST_SYSTEM.TXT
+++ b/libc/SECCOMP_ALLOWLIST_SYSTEM.TXT
@@ -2,5 +2,3 @@
 # Note that the resultant policy is applied only to zygote spawned processes.
 #
 # This file is processed by a python script named genseccomp.py.
-
-bpf(int cmd, union bpf_attr *attr, unsigned int size) all
diff --git a/libc/SYSCALLS.TXT b/libc/SYSCALLS.TXT
index 31651cd..226ba70 100644
--- a/libc/SYSCALLS.TXT
+++ b/libc/SYSCALLS.TXT
@@ -35,33 +35,33 @@
 
 # Calls that have historical 16-bit variants camping on the best names (CONFIG_UID16).
 getuid:getuid32()   lp32
-getuid:getuid()     lp64
+getuid()     lp64
 getgid:getgid32()   lp32
-getgid:getgid()     lp64
+getgid()     lp64
 geteuid:geteuid32() lp32
-geteuid:geteuid()   lp64
+geteuid()   lp64
 getegid:getegid32() lp32
-getegid:getegid()   lp64
+getegid()   lp64
 getresuid:getresuid32(uid_t* ruid, uid_t* euid, uid_t* suid) lp32
-getresuid:getresuid(uid_t* ruid, uid_t* euid, uid_t* suid)   lp64
+getresuid(uid_t* ruid, uid_t* euid, uid_t* suid)   lp64
 getresgid:getresgid32(gid_t* rgid, gid_t* egid, gid_t* sgid) lp32
-getresgid:getresgid(gid_t* rgid, gid_t* egid, gid_t* sgid)   lp64
+getresgid(gid_t* rgid, gid_t* egid, gid_t* sgid)   lp64
 getgroups:getgroups32(int, gid_t*) lp32
-getgroups:getgroups(int, gid_t*)   lp64
+getgroups(int, gid_t*)   lp64
 setgid:setgid32(gid_t) lp32
-setgid:setgid(gid_t)   lp64
+setgid(gid_t)   lp64
 setuid:setuid32(uid_t) lp32
-setuid:setuid(uid_t)   lp64
+setuid(uid_t)   lp64
 setreuid:setreuid32(uid_t, uid_t) lp32
-setreuid:setreuid(uid_t, uid_t)   lp64
+setreuid(uid_t, uid_t)   lp64
 setresuid:setresuid32(uid_t, uid_t, uid_t) lp32
-setresuid:setresuid(uid_t, uid_t, uid_t)   lp64
+setresuid(uid_t, uid_t, uid_t)   lp64
 setresgid:setresgid32(gid_t, gid_t, gid_t) lp32
-setresgid:setresgid(gid_t, gid_t, gid_t)   lp64
+setresgid(gid_t, gid_t, gid_t)   lp64
 setfsgid:setfsgid32(gid_t) lp32
-setfsgid:setfsgid(gid_t)   lp64
+setfsgid(gid_t)   lp64
 setfsuid:setfsuid32(uid_t) lp32
-setfsuid:setfsuid(uid_t)   lp64
+setfsuid(uid_t)   lp64
 
 readahead(int, off64_t, size_t) all
 getpgid(pid_t) all
@@ -89,10 +89,10 @@
 prlimit64(pid_t, int, struct rlimit64*, const struct rlimit64*)  lp32
 
 setgroups:setgroups32(int, const gid_t*)   lp32
-setgroups:setgroups(int, const gid_t*)     lp64
+setgroups(int, const gid_t*)     lp64
 setpgid(pid_t, pid_t)  all
 setregid:setregid32(gid_t, gid_t)  lp32
-setregid:setregid(gid_t, gid_t)    lp64
+setregid(gid_t, gid_t)    lp64
 chroot(const char*)  all
 prctl(int, unsigned long, unsigned long, unsigned long, unsigned long) all
 capget(cap_user_header_t header, cap_user_data_t data) all
@@ -148,7 +148,7 @@
 fsync(int)  all
 fdatasync(int) all
 fchown:fchown32(int, uid_t, gid_t)  lp32
-fchown:fchown(int, uid_t, gid_t)    lp64
+fchown(int, uid_t, gid_t)    lp64
 sync(void)  all
 syncfs(int)  all
 __fsetxattr:fsetxattr(int, const char*, const void*, size_t, int) all
@@ -264,40 +264,32 @@
 # sockets
 __socket:socket(int, int, int)              arm,lp64
 __socketpair:socketpair(int, int, int, int*)    arm,lp64
-bind(int, struct sockaddr*, socklen_t)  arm,lp64
+bind(int, struct sockaddr*, socklen_t)  all
 __connect:connect(int, struct sockaddr*, socklen_t)   arm,lp64
-listen(int, int)                   arm,lp64
-__accept4:accept4(int, struct sockaddr*, socklen_t*, int)  arm,lp64
-getsockname(int, struct sockaddr*, socklen_t*)  arm,lp64
-getpeername(int, struct sockaddr*, socklen_t*)  arm,lp64
+listen(int, int) all
+__accept4:accept4(int, struct sockaddr*, socklen_t*, int)  all
+getsockname(int, struct sockaddr*, socklen_t*)  all
+getpeername(int, struct sockaddr*, socklen_t*)  all
 __sendto:sendto(int, const void*, size_t, int, const struct sockaddr*, socklen_t)  arm,lp64
 recvfrom(int, void*, size_t, unsigned int, struct sockaddr*, socklen_t*)  arm,lp64
-shutdown(int, int)  arm,lp64
+shutdown(int, int)  all
 setsockopt(int, int, int, const void*, socklen_t)  arm,lp64
-getsockopt(int, int, int, void*, socklen_t*)    arm,lp64
+getsockopt(int, int, int, void*, socklen_t*)  arm,lp64
 __recvmsg:recvmsg(int, struct msghdr*, unsigned int)   arm,lp64
 __sendmsg:sendmsg(int, const struct msghdr*, unsigned int)  arm,lp64
-__recvmmsg:recvmmsg(int, struct mmsghdr*, unsigned int, int, const struct timespec*)   arm,lp64
-__sendmmsg:sendmmsg(int, struct mmsghdr*, unsigned int, int)   arm,lp64
+__recvmmsg:recvmmsg(int, struct mmsghdr*, unsigned int, int, const struct timespec*)   all
+__sendmmsg:sendmmsg(int, struct mmsghdr*, unsigned int, int)   all
 
 # sockets for x86. These are done as an "indexed" call to socketcall syscall.
 __socket:socketcall:1(int, int, int) x86
-bind:socketcall:2(int, struct sockaddr*, int)  x86
 __connect:socketcall:3(int, struct sockaddr*, socklen_t)   x86
-listen:socketcall:4(int, int)                   x86
-getsockname:socketcall:6(int, struct sockaddr*, socklen_t*)  x86
-getpeername:socketcall:7(int, struct sockaddr*, socklen_t*)  x86
 __socketpair:socketcall:8(int, int, int, int*)    x86
 __sendto:socketcall:11(int, const void*, size_t, int, const struct sockaddr*, socklen_t)  x86
 recvfrom:socketcall:12(int, void*, size_t, unsigned int, struct sockaddr*, socklen_t*)  x86
-shutdown:socketcall:13(int, int)  x86
 setsockopt:socketcall:14(int, int, int, const void*, socklen_t)  x86
 getsockopt:socketcall:15(int, int, int, void*, socklen_t*)    x86
 __sendmsg:socketcall:16(int, const struct msghdr*, unsigned int)  x86
 __recvmsg:socketcall:17(int, struct msghdr*, unsigned int)   x86
-__accept4:socketcall:18(int, struct sockaddr*, socklen_t*, int)  x86
-__recvmmsg:socketcall:19(int, struct mmsghdr*, unsigned int, int, const struct timespec*)   x86
-__sendmmsg:socketcall:20(int, struct mmsghdr*, unsigned int, int)   x86
 
 # scheduler & real-time
 sched_get_priority_max(int policy) all
diff --git a/libc/arch-arm/cortex-a15/bionic/__strcat_chk.S b/libc/arch-arm/cortex-a15/string/__strcat_chk.S
similarity index 100%
rename from libc/arch-arm/cortex-a15/bionic/__strcat_chk.S
rename to libc/arch-arm/cortex-a15/string/__strcat_chk.S
diff --git a/libc/arch-arm/cortex-a15/bionic/__strcpy_chk.S b/libc/arch-arm/cortex-a15/string/__strcpy_chk.S
similarity index 100%
rename from libc/arch-arm/cortex-a15/bionic/__strcpy_chk.S
rename to libc/arch-arm/cortex-a15/string/__strcpy_chk.S
diff --git a/libc/arch-arm/cortex-a15/bionic/memcpy.S b/libc/arch-arm/cortex-a15/string/memcpy.S
similarity index 100%
rename from libc/arch-arm/cortex-a15/bionic/memcpy.S
rename to libc/arch-arm/cortex-a15/string/memcpy.S
diff --git a/libc/arch-arm/cortex-a15/bionic/memcpy_base.S b/libc/arch-arm/cortex-a15/string/memcpy_base.S
similarity index 100%
rename from libc/arch-arm/cortex-a15/bionic/memcpy_base.S
rename to libc/arch-arm/cortex-a15/string/memcpy_base.S
diff --git a/libc/arch-arm/cortex-a15/bionic/memmove.S b/libc/arch-arm/cortex-a15/string/memmove.S
similarity index 100%
rename from libc/arch-arm/cortex-a15/bionic/memmove.S
rename to libc/arch-arm/cortex-a15/string/memmove.S
diff --git a/libc/arch-arm/cortex-a15/bionic/memset.S b/libc/arch-arm/cortex-a15/string/memset.S
similarity index 100%
rename from libc/arch-arm/cortex-a15/bionic/memset.S
rename to libc/arch-arm/cortex-a15/string/memset.S
diff --git a/libc/arch-arm/cortex-a15/bionic/stpcpy.S b/libc/arch-arm/cortex-a15/string/stpcpy.S
similarity index 100%
rename from libc/arch-arm/cortex-a15/bionic/stpcpy.S
rename to libc/arch-arm/cortex-a15/string/stpcpy.S
diff --git a/libc/arch-arm/cortex-a15/bionic/strcat.S b/libc/arch-arm/cortex-a15/string/strcat.S
similarity index 100%
rename from libc/arch-arm/cortex-a15/bionic/strcat.S
rename to libc/arch-arm/cortex-a15/string/strcat.S
diff --git a/libc/arch-arm/cortex-a15/bionic/strcmp.S b/libc/arch-arm/cortex-a15/string/strcmp.S
similarity index 100%
rename from libc/arch-arm/cortex-a15/bionic/strcmp.S
rename to libc/arch-arm/cortex-a15/string/strcmp.S
diff --git a/libc/arch-arm/cortex-a15/bionic/strcpy.S b/libc/arch-arm/cortex-a15/string/strcpy.S
similarity index 100%
rename from libc/arch-arm/cortex-a15/bionic/strcpy.S
rename to libc/arch-arm/cortex-a15/string/strcpy.S
diff --git a/libc/arch-arm/cortex-a15/bionic/string_copy.S b/libc/arch-arm/cortex-a15/string/string_copy.S
similarity index 100%
rename from libc/arch-arm/cortex-a15/bionic/string_copy.S
rename to libc/arch-arm/cortex-a15/string/string_copy.S
diff --git a/libc/arch-arm/cortex-a15/bionic/strlen.S b/libc/arch-arm/cortex-a15/string/strlen.S
similarity index 100%
rename from libc/arch-arm/cortex-a15/bionic/strlen.S
rename to libc/arch-arm/cortex-a15/string/strlen.S
diff --git a/libc/arch-arm/cortex-a53/bionic/__strcat_chk.S b/libc/arch-arm/cortex-a53/string/__strcat_chk.S
similarity index 100%
rename from libc/arch-arm/cortex-a53/bionic/__strcat_chk.S
rename to libc/arch-arm/cortex-a53/string/__strcat_chk.S
diff --git a/libc/arch-arm/cortex-a53/bionic/__strcpy_chk.S b/libc/arch-arm/cortex-a53/string/__strcpy_chk.S
similarity index 100%
rename from libc/arch-arm/cortex-a53/bionic/__strcpy_chk.S
rename to libc/arch-arm/cortex-a53/string/__strcpy_chk.S
diff --git a/libc/arch-arm/cortex-a53/bionic/memcpy.S b/libc/arch-arm/cortex-a53/string/memcpy.S
similarity index 100%
rename from libc/arch-arm/cortex-a53/bionic/memcpy.S
rename to libc/arch-arm/cortex-a53/string/memcpy.S
diff --git a/libc/arch-arm/cortex-a53/bionic/memcpy_base.S b/libc/arch-arm/cortex-a53/string/memcpy_base.S
similarity index 100%
rename from libc/arch-arm/cortex-a53/bionic/memcpy_base.S
rename to libc/arch-arm/cortex-a53/string/memcpy_base.S
diff --git a/libc/arch-arm/cortex-a55/bionic/__strcat_chk.S b/libc/arch-arm/cortex-a55/string/__strcat_chk.S
similarity index 100%
rename from libc/arch-arm/cortex-a55/bionic/__strcat_chk.S
rename to libc/arch-arm/cortex-a55/string/__strcat_chk.S
diff --git a/libc/arch-arm/cortex-a55/bionic/__strcpy_chk.S b/libc/arch-arm/cortex-a55/string/__strcpy_chk.S
similarity index 100%
rename from libc/arch-arm/cortex-a55/bionic/__strcpy_chk.S
rename to libc/arch-arm/cortex-a55/string/__strcpy_chk.S
diff --git a/libc/arch-arm/cortex-a55/bionic/memcpy.S b/libc/arch-arm/cortex-a55/string/memcpy.S
similarity index 100%
rename from libc/arch-arm/cortex-a55/bionic/memcpy.S
rename to libc/arch-arm/cortex-a55/string/memcpy.S
diff --git a/libc/arch-arm/cortex-a55/bionic/memcpy_base.S b/libc/arch-arm/cortex-a55/string/memcpy_base.S
similarity index 100%
rename from libc/arch-arm/cortex-a55/bionic/memcpy_base.S
rename to libc/arch-arm/cortex-a55/string/memcpy_base.S
diff --git a/libc/arch-arm/cortex-a7/bionic/__strcat_chk.S b/libc/arch-arm/cortex-a7/string/__strcat_chk.S
similarity index 100%
rename from libc/arch-arm/cortex-a7/bionic/__strcat_chk.S
rename to libc/arch-arm/cortex-a7/string/__strcat_chk.S
diff --git a/libc/arch-arm/cortex-a7/bionic/__strcpy_chk.S b/libc/arch-arm/cortex-a7/string/__strcpy_chk.S
similarity index 100%
rename from libc/arch-arm/cortex-a7/bionic/__strcpy_chk.S
rename to libc/arch-arm/cortex-a7/string/__strcpy_chk.S
diff --git a/libc/arch-arm/cortex-a7/bionic/memcpy.S b/libc/arch-arm/cortex-a7/string/memcpy.S
similarity index 100%
rename from libc/arch-arm/cortex-a7/bionic/memcpy.S
rename to libc/arch-arm/cortex-a7/string/memcpy.S
diff --git a/libc/arch-arm/cortex-a7/bionic/memcpy_base.S b/libc/arch-arm/cortex-a7/string/memcpy_base.S
similarity index 100%
rename from libc/arch-arm/cortex-a7/bionic/memcpy_base.S
rename to libc/arch-arm/cortex-a7/string/memcpy_base.S
diff --git a/libc/arch-arm/cortex-a7/bionic/memset.S b/libc/arch-arm/cortex-a7/string/memset.S
similarity index 100%
rename from libc/arch-arm/cortex-a7/bionic/memset.S
rename to libc/arch-arm/cortex-a7/string/memset.S
diff --git a/libc/arch-arm/cortex-a9/bionic/__strcat_chk.S b/libc/arch-arm/cortex-a9/string/__strcat_chk.S
similarity index 100%
rename from libc/arch-arm/cortex-a9/bionic/__strcat_chk.S
rename to libc/arch-arm/cortex-a9/string/__strcat_chk.S
diff --git a/libc/arch-arm/cortex-a9/bionic/__strcpy_chk.S b/libc/arch-arm/cortex-a9/string/__strcpy_chk.S
similarity index 100%
rename from libc/arch-arm/cortex-a9/bionic/__strcpy_chk.S
rename to libc/arch-arm/cortex-a9/string/__strcpy_chk.S
diff --git a/libc/arch-arm/cortex-a9/bionic/memcpy.S b/libc/arch-arm/cortex-a9/string/memcpy.S
similarity index 100%
rename from libc/arch-arm/cortex-a9/bionic/memcpy.S
rename to libc/arch-arm/cortex-a9/string/memcpy.S
diff --git a/libc/arch-arm/cortex-a9/bionic/memcpy_base.S b/libc/arch-arm/cortex-a9/string/memcpy_base.S
similarity index 100%
rename from libc/arch-arm/cortex-a9/bionic/memcpy_base.S
rename to libc/arch-arm/cortex-a9/string/memcpy_base.S
diff --git a/libc/arch-arm/cortex-a9/bionic/memset.S b/libc/arch-arm/cortex-a9/string/memset.S
similarity index 100%
rename from libc/arch-arm/cortex-a9/bionic/memset.S
rename to libc/arch-arm/cortex-a9/string/memset.S
diff --git a/libc/arch-arm/cortex-a9/bionic/stpcpy.S b/libc/arch-arm/cortex-a9/string/stpcpy.S
similarity index 100%
rename from libc/arch-arm/cortex-a9/bionic/stpcpy.S
rename to libc/arch-arm/cortex-a9/string/stpcpy.S
diff --git a/libc/arch-arm/cortex-a9/bionic/strcat.S b/libc/arch-arm/cortex-a9/string/strcat.S
similarity index 100%
rename from libc/arch-arm/cortex-a9/bionic/strcat.S
rename to libc/arch-arm/cortex-a9/string/strcat.S
diff --git a/libc/arch-arm/cortex-a9/bionic/strcpy.S b/libc/arch-arm/cortex-a9/string/strcpy.S
similarity index 100%
rename from libc/arch-arm/cortex-a9/bionic/strcpy.S
rename to libc/arch-arm/cortex-a9/string/strcpy.S
diff --git a/libc/arch-arm/cortex-a9/bionic/string_copy.S b/libc/arch-arm/cortex-a9/string/string_copy.S
similarity index 100%
rename from libc/arch-arm/cortex-a9/bionic/string_copy.S
rename to libc/arch-arm/cortex-a9/string/string_copy.S
diff --git a/libc/arch-arm/cortex-a9/bionic/strlen.S b/libc/arch-arm/cortex-a9/string/strlen.S
similarity index 100%
rename from libc/arch-arm/cortex-a9/bionic/strlen.S
rename to libc/arch-arm/cortex-a9/string/strlen.S
diff --git a/libc/arch-arm/generic/bionic/memmove.S b/libc/arch-arm/generic/bionic/memmove.S
deleted file mode 100644
index 0cf82d1..0000000
--- a/libc/arch-arm/generic/bionic/memmove.S
+++ /dev/null
@@ -1,471 +0,0 @@
-/*	$OpenBSD: _memcpy.S,v 1.6 2016/08/06 19:16:09 guenther Exp $	*/
-/*	$NetBSD: _memcpy.S,v 1.4 2003/04/05 23:08:52 bjh21 Exp $	*/
-
-/*-
- * Copyright (c) 1997 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Neil A. Carson and Mark Brinicombe
- *
- * 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 <private/bionic_asm.h>
-
-  .syntax unified
-
-/*
- * This is one fun bit of code ...
- * Some easy listening music is suggested while trying to understand this
- * code e.g. Iron Maiden
- *
- * For anyone attempting to understand it :
- *
- * The core code is implemented here with simple stubs for memcpy()
- * memmove() and bcopy().
- *
- * All local labels are prefixed with Lmemcpy_
- * Following the prefix a label starting f is used in the forward copy code
- * while a label using b is used in the backwards copy code
- * The source and destination addresses determine whether a forward or
- * backward copy is performed.
- * Separate bits of code are used to deal with the following situations
- * for both the forward and backwards copy.
- * unaligned source address
- * unaligned destination address
- * Separate copy routines are used to produce an optimised result for each
- * of these cases.
- * The copy code will use LDM/STM instructions to copy up to 32 bytes at
- * a time where possible.
- *
- * Note: r12 (aka ip) can be trashed during the function along with
- * r0-r3 although r0-r2 have defined uses i.e. src, dest, len through out.
- * Additional registers are preserved prior to use i.e. r4, r5 & lr
- *
- * Apologies for the state of the comments ;-)
- */
-
-ENTRY_PRIVATE(bsd_safe_memcpy)
-	/* Determine copy direction */
-	cmp	r1, r0
-	bcc	.Lmemcpy_backwards
-
-	moveq	r0, #0			/* Quick abort for len=0 */
-	moveq	pc, lr
-
-	stmdb	sp!, {r0, lr}		/* memcpy() returns dest addr */
-	subs	r2, r2, #4
-	blt	.Lmemcpy_fl4		/* less than 4 bytes */
-	ands	r12, r0, #3
-	bne	.Lmemcpy_fdestul	/* oh unaligned destination addr */
-	ands	r12, r1, #3
-	bne	.Lmemcpy_fsrcul		/* oh unaligned source addr */
-
-.Lmemcpy_ft8:
-	/* We have aligned source and destination */
-	subs	r2, r2, #8
-	blt	.Lmemcpy_fl12		/* less than 12 bytes (4 from above) */
-	subs	r2, r2, #0x14         
-	blt	.Lmemcpy_fl32		/* less than 32 bytes (12 from above) */
-	stmdb	sp!, {r4}		/* borrow r4 */
-
-	/* blat 32 bytes at a time */
-	/* XXX for really big copies perhaps we should use more registers */
-.Lmemcpy_floop32:	
-	ldmia	r1!, {r3, r4, r12, lr}
-	stmia	r0!, {r3, r4, r12, lr}
-	ldmia	r1!, {r3, r4, r12, lr}
-	stmia	r0!, {r3, r4, r12, lr}
-	subs	r2, r2, #0x20         
-	bge	.Lmemcpy_floop32
-
-	cmn	r2, #0x10
-	ldmiage	r1!, {r3, r4, r12, lr}	/* blat a remaining 16 bytes */
-	stmiage	r0!, {r3, r4, r12, lr}
-	subge	r2, r2, #0x10         
-	ldmia	sp!, {r4}		/* return r4 */
-
-.Lmemcpy_fl32:
-	adds	r2, r2, #0x14         
-
-	/* blat 12 bytes at a time */
-.Lmemcpy_floop12:
-	ldmiage	r1!, {r3, r12, lr}
-	stmiage	r0!, {r3, r12, lr}
-	subsge	r2, r2, #0x0c         
-	bge	.Lmemcpy_floop12
-
-.Lmemcpy_fl12:
-	adds	r2, r2, #8
-	blt	.Lmemcpy_fl4
-
-	subs	r2, r2, #4
-	ldrlt	r3, [r1], #4
-	strlt	r3, [r0], #4
-	ldmiage	r1!, {r3, r12}
-	stmiage	r0!, {r3, r12}
-	subge	r2, r2, #4
-
-.Lmemcpy_fl4:
-	/* less than 4 bytes to go */
-	adds	r2, r2, #4
-	ldmiaeq	sp!, {r0, pc}		/* done */
-
-	/* copy the crud byte at a time */
-	cmp	r2, #2
-	ldrb	r3, [r1], #1
-	strb	r3, [r0], #1
-	ldrbge	r3, [r1], #1
-	strbge	r3, [r0], #1
-	ldrbgt	r3, [r1], #1
-	strbgt	r3, [r0], #1
-	ldmia	sp!, {r0, pc}
-
-	/* erg - unaligned destination */
-.Lmemcpy_fdestul:
-	rsb	r12, r12, #4
-	cmp	r12, #2
-
-	/* align destination with byte copies */
-	ldrb	r3, [r1], #1
-	strb	r3, [r0], #1
-	ldrbge	r3, [r1], #1
-	strbge	r3, [r0], #1
-	ldrbgt	r3, [r1], #1
-	strbgt	r3, [r0], #1
-	subs	r2, r2, r12
-	blt	.Lmemcpy_fl4		/* less the 4 bytes */
-
-	ands	r12, r1, #3
-	beq	.Lmemcpy_ft8		/* we have an aligned source */
-
-	/* erg - unaligned source */
-	/* This is where it gets nasty ... */
-.Lmemcpy_fsrcul:
-	bic	r1, r1, #3
-	ldr	lr, [r1], #4
-	cmp	r12, #2
-	bgt	.Lmemcpy_fsrcul3
-	beq	.Lmemcpy_fsrcul2
-	cmp	r2, #0x0c            
-	blt	.Lmemcpy_fsrcul1loop4
-	sub	r2, r2, #0x0c         
-	stmdb	sp!, {r4, r5}
-
-.Lmemcpy_fsrcul1loop16:
-	mov	r3, lr, lsr #8
-	ldmia	r1!, {r4, r5, r12, lr}
-	orr	r3, r3, r4, lsl #24
-	mov	r4, r4, lsr #8
-	orr	r4, r4, r5, lsl #24
-	mov	r5, r5, lsr #8
-	orr	r5, r5, r12, lsl #24
-	mov	r12, r12, lsr #8
-	orr	r12, r12, lr, lsl #24
-	stmia	r0!, {r3-r5, r12}
-	subs	r2, r2, #0x10         
-	bge	.Lmemcpy_fsrcul1loop16
-	ldmia	sp!, {r4, r5}
-	adds	r2, r2, #0x0c         
-	blt	.Lmemcpy_fsrcul1l4
-
-.Lmemcpy_fsrcul1loop4:
-	mov	r12, lr, lsr #8
-	ldr	lr, [r1], #4
-	orr	r12, r12, lr, lsl #24
-	str	r12, [r0], #4
-	subs	r2, r2, #4
-	bge	.Lmemcpy_fsrcul1loop4
-
-.Lmemcpy_fsrcul1l4:
-	sub	r1, r1, #3
-	b	.Lmemcpy_fl4
-
-.Lmemcpy_fsrcul2:
-	cmp	r2, #0x0c            
-	blt	.Lmemcpy_fsrcul2loop4
-	sub	r2, r2, #0x0c         
-	stmdb	sp!, {r4, r5}
-
-.Lmemcpy_fsrcul2loop16:
-	mov	r3, lr, lsr #16
-	ldmia	r1!, {r4, r5, r12, lr}
-	orr	r3, r3, r4, lsl #16
-	mov	r4, r4, lsr #16
-	orr	r4, r4, r5, lsl #16
-	mov	r5, r5, lsr #16
-	orr	r5, r5, r12, lsl #16
-	mov	r12, r12, lsr #16
-	orr	r12, r12, lr, lsl #16
-	stmia	r0!, {r3-r5, r12}
-	subs	r2, r2, #0x10         
-	bge	.Lmemcpy_fsrcul2loop16
-	ldmia	sp!, {r4, r5}
-	adds	r2, r2, #0x0c         
-	blt	.Lmemcpy_fsrcul2l4
-
-.Lmemcpy_fsrcul2loop4:
-	mov	r12, lr, lsr #16
-	ldr	lr, [r1], #4
-	orr	r12, r12, lr, lsl #16
-	str	r12, [r0], #4
-	subs	r2, r2, #4
-	bge	.Lmemcpy_fsrcul2loop4
-
-.Lmemcpy_fsrcul2l4:
-	sub	r1, r1, #2
-	b	.Lmemcpy_fl4
-
-.Lmemcpy_fsrcul3:
-	cmp	r2, #0x0c            
-	blt	.Lmemcpy_fsrcul3loop4
-	sub	r2, r2, #0x0c         
-	stmdb	sp!, {r4, r5}
-
-.Lmemcpy_fsrcul3loop16:
-	mov	r3, lr, lsr #24
-	ldmia	r1!, {r4, r5, r12, lr}
-	orr	r3, r3, r4, lsl #8
-	mov	r4, r4, lsr #24
-	orr	r4, r4, r5, lsl #8
-	mov	r5, r5, lsr #24
-	orr	r5, r5, r12, lsl #8
-	mov	r12, r12, lsr #24
-	orr	r12, r12, lr, lsl #8
-	stmia	r0!, {r3-r5, r12}
-	subs	r2, r2, #0x10         
-	bge	.Lmemcpy_fsrcul3loop16
-	ldmia	sp!, {r4, r5}
-	adds	r2, r2, #0x0c         
-	blt	.Lmemcpy_fsrcul3l4
-
-.Lmemcpy_fsrcul3loop4:
-	mov	r12, lr, lsr #24
-	ldr	lr, [r1], #4
-	orr	r12, r12, lr, lsl #8
-	str	r12, [r0], #4
-	subs	r2, r2, #4
-	bge	.Lmemcpy_fsrcul3loop4
-
-.Lmemcpy_fsrcul3l4:
-	sub	r1, r1, #1
-	b	.Lmemcpy_fl4
-
-.Lmemcpy_backwards:
-	add	r1, r1, r2
-	add	r0, r0, r2
-	subs	r2, r2, #4
-	blt	.Lmemcpy_bl4		/* less than 4 bytes */
-	ands	r12, r0, #3
-	bne	.Lmemcpy_bdestul	/* oh unaligned destination addr */
-	ands	r12, r1, #3
-	bne	.Lmemcpy_bsrcul		/* oh unaligned source addr */
-
-.Lmemcpy_bt8:
-	/* We have aligned source and destination */
-	subs	r2, r2, #8
-	blt	.Lmemcpy_bl12		/* less than 12 bytes (4 from above) */
-	stmdb	sp!, {r4, lr}
-	subs	r2, r2, #0x14		/* less than 32 bytes (12 from above) */
-	blt	.Lmemcpy_bl32
-
-	/* blat 32 bytes at a time */
-	/* XXX for really big copies perhaps we should use more registers */
-.Lmemcpy_bloop32:
-	ldmdb	r1!, {r3, r4, r12, lr}
-	stmdb	r0!, {r3, r4, r12, lr}
-	ldmdb	r1!, {r3, r4, r12, lr}
-	stmdb	r0!, {r3, r4, r12, lr}
-	subs	r2, r2, #0x20         
-	bge	.Lmemcpy_bloop32
-
-.Lmemcpy_bl32:
-	cmn	r2, #0x10            
-	ldmdbge	r1!, {r3, r4, r12, lr}	/* blat a remaining 16 bytes */
-	stmdbge	r0!, {r3, r4, r12, lr}
-	subge	r2, r2, #0x10         
-	adds	r2, r2, #0x14         
-	ldmdbge	r1!, {r3, r12, lr}	/* blat a remaining 12 bytes */
-	stmdbge	r0!, {r3, r12, lr}
-	subge	r2, r2, #0x0c         
-	ldmia	sp!, {r4, lr}
-
-.Lmemcpy_bl12:
-	adds	r2, r2, #8
-	blt	.Lmemcpy_bl4
-	subs	r2, r2, #4
-	ldrlt	r3, [r1, #-4]!
-	strlt	r3, [r0, #-4]!
-	ldmdbge	r1!, {r3, r12}
-	stmdbge	r0!, {r3, r12}
-	subge	r2, r2, #4
-
-.Lmemcpy_bl4:
-	/* less than 4 bytes to go */
-	adds	r2, r2, #4
-	moveq	pc, lr			/* done */
-
-	/* copy the crud byte at a time */
-	cmp	r2, #2
-	ldrb	r3, [r1, #-1]!
-	strb	r3, [r0, #-1]!
-	ldrbge	r3, [r1, #-1]!
-	strbge	r3, [r0, #-1]!
-	ldrbgt	r3, [r1, #-1]!
-	strbgt	r3, [r0, #-1]!
-	mov	pc, lr
-
-	/* erg - unaligned destination */
-.Lmemcpy_bdestul:
-	cmp	r12, #2
-
-	/* align destination with byte copies */
-	ldrb	r3, [r1, #-1]!
-	strb	r3, [r0, #-1]!
-	ldrbge	r3, [r1, #-1]!
-	strbge	r3, [r0, #-1]!
-	ldrbgt	r3, [r1, #-1]!
-	strbgt	r3, [r0, #-1]!
-	subs	r2, r2, r12
-	blt	.Lmemcpy_bl4		/* less than 4 bytes to go */
-	ands	r12, r1, #3
-	beq	.Lmemcpy_bt8		/* we have an aligned source */
-
-	/* erg - unaligned source */
-	/* This is where it gets nasty ... */
-.Lmemcpy_bsrcul:
-	bic	r1, r1, #3
-	ldr	r3, [r1, #0]
-	cmp	r12, #2
-	blt	.Lmemcpy_bsrcul1
-	beq	.Lmemcpy_bsrcul2
-	cmp	r2, #0x0c            
-	blt	.Lmemcpy_bsrcul3loop4
-	sub	r2, r2, #0x0c         
-	stmdb	sp!, {r4, r5, lr}
-
-.Lmemcpy_bsrcul3loop16:
-	mov	lr, r3, lsl #8
-	ldmdb	r1!, {r3-r5, r12}
-	orr	lr, lr, r12, lsr #24
-	mov	r12, r12, lsl #8
-	orr	r12, r12, r5, lsr #24
-	mov	r5, r5, lsl #8
-	orr	r5, r5, r4, lsr #24
-	mov	r4, r4, lsl #8
-	orr	r4, r4, r3, lsr #24
-	stmdb	r0!, {r4, r5, r12, lr}
-	subs	r2, r2, #0x10         
-	bge	.Lmemcpy_bsrcul3loop16
-	ldmia	sp!, {r4, r5, lr}
-	adds	r2, r2, #0x0c         
-	blt	.Lmemcpy_bsrcul3l4
-
-.Lmemcpy_bsrcul3loop4:
-	mov	r12, r3, lsl #8
-	ldr	r3, [r1, #-4]!
-	orr	r12, r12, r3, lsr #24
-	str	r12, [r0, #-4]!
-	subs	r2, r2, #4
-	bge	.Lmemcpy_bsrcul3loop4
-
-.Lmemcpy_bsrcul3l4:
-	add	r1, r1, #3
-	b	.Lmemcpy_bl4
-
-.Lmemcpy_bsrcul2:
-	cmp	r2, #0x0c            
-	blt	.Lmemcpy_bsrcul2loop4
-	sub	r2, r2, #0x0c         
-	stmdb	sp!, {r4, r5, lr}
-
-.Lmemcpy_bsrcul2loop16:
-	mov	lr, r3, lsl #16
-	ldmdb	r1!, {r3-r5, r12}
-	orr	lr, lr, r12, lsr #16
-	mov	r12, r12, lsl #16
-	orr	r12, r12, r5, lsr #16
-	mov	r5, r5, lsl #16
-	orr	r5, r5, r4, lsr #16
-	mov	r4, r4, lsl #16
-	orr	r4, r4, r3, lsr #16
-	stmdb	r0!, {r4, r5, r12, lr}
-	subs	r2, r2, #0x10         
-	bge	.Lmemcpy_bsrcul2loop16
-	ldmia	sp!, {r4, r5, lr}
-	adds	r2, r2, #0x0c         
-	blt	.Lmemcpy_bsrcul2l4
-
-.Lmemcpy_bsrcul2loop4:
-	mov	r12, r3, lsl #16
-	ldr	r3, [r1, #-4]!
-	orr	r12, r12, r3, lsr #16
-	str	r12, [r0, #-4]!
-	subs	r2, r2, #4
-	bge	.Lmemcpy_bsrcul2loop4
-
-.Lmemcpy_bsrcul2l4:
-	add	r1, r1, #2
-	b	.Lmemcpy_bl4
-
-.Lmemcpy_bsrcul1:
-	cmp	r2, #0x0c            
-	blt	.Lmemcpy_bsrcul1loop4
-	sub	r2, r2, #0x0c         
-	stmdb	sp!, {r4, r5, lr}
-
-.Lmemcpy_bsrcul1loop32:
-	mov	lr, r3, lsl #24
-	ldmdb	r1!, {r3-r5, r12}
-	orr	lr, lr, r12, lsr #8
-	mov	r12, r12, lsl #24
-	orr	r12, r12, r5, lsr #8
-	mov	r5, r5, lsl #24
-	orr	r5, r5, r4, lsr #8
-	mov	r4, r4, lsl #24
-	orr	r4, r4, r3, lsr #8
-	stmdb	r0!, {r4, r5, r12, lr}
-	subs	r2, r2, #0x10         
-	bge	.Lmemcpy_bsrcul1loop32
-	ldmia	sp!, {r4, r5, lr}
-	adds	r2, r2, #0x0c         
-	blt	.Lmemcpy_bsrcul1l4
-
-.Lmemcpy_bsrcul1loop4:
-	mov	r12, r3, lsl #24
-	ldr	r3, [r1, #-4]!
-	orr	r12, r12, r3, lsr #8
-	str	r12, [r0, #-4]!
-	subs	r2, r2, #4
-	bge	.Lmemcpy_bsrcul1loop4
-
-.Lmemcpy_bsrcul1l4:
-	add	r1, r1, #1
-	b	.Lmemcpy_bl4
-END(bsd_safe_memcpy)
-
-ENTRY(memmove_generic)
-        stmfd   sp!, {r0, lr}
-        bl      bsd_safe_memcpy
-        ldmfd   sp!, {r0, pc}
-END(memmove_generic)
diff --git a/libc/arch-arm/generic/bionic/memset.S b/libc/arch-arm/generic/bionic/memset.S
deleted file mode 100644
index e70002f..0000000
--- a/libc/arch-arm/generic/bionic/memset.S
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <private/bionic_asm.h>
-
-        /*
-         * Optimized memset() for ARM.
-         *
-         * memset() returns its first argument.
-         */
-
-         .syntax unified
-
-ENTRY(__memset_chk_generic)
-        cmp         r2, r3
-        bls         memset
-
-        bl          __memset_chk_fail
-END(__memset_chk_generic)
-
-ENTRY(memset_generic)
-        /* compute the offset to align the destination
-         * offset = (4-(src&3))&3 = -src & 3
-         */
-        .save       {r0, r4-r7, lr}
-        stmfd       sp!, {r0, r4-r7, lr}
-        rsb         r3, r0, #0
-        ands        r3, r3, #3
-        cmp         r3, r2
-        movhi       r3, r2
-
-        /* splat r1 */
-        mov         r1, r1, lsl #24
-        orr         r1, r1, r1, lsr #8
-        orr         r1, r1, r1, lsr #16
-
-        movs        r12, r3, lsl #31
-        strbcs      r1, [r0], #1    /* can't use strh (alignment unknown) */
-        strbcs      r1, [r0], #1
-        strbmi      r1, [r0], #1
-        subs        r2, r2, r3
-        popls       {r0, r4-r7, pc}    /* return */
-
-        /* align the destination to a cache-line */
-        mov         r12, r1
-        mov         lr, r1
-        mov         r4, r1
-        mov         r5, r1
-        mov         r6, r1
-        mov         r7, r1
-
-        rsb         r3, r0, #0
-        ands        r3, r3, #0x1C
-        beq         3f
-        cmp         r3, r2
-        andhi       r3, r2, #0x1C
-        sub         r2, r2, r3
-
-        /* conditionally writes 0 to 7 words (length in r3) */
-        movs        r3, r3, lsl #28
-        stmcs       r0!, {r1, lr}
-        stmcs       r0!, {r1, lr}
-        stmmi       r0!, {r1, lr}
-        movs        r3, r3, lsl #2
-        strcs       r1, [r0], #4
-
-3:
-        subs        r2, r2, #32
-        mov         r3, r1
-        bmi         2f
-1:      subs        r2, r2, #32
-        stmia       r0!, {r1,r3,r4,r5,r6,r7,r12,lr}
-        bhs         1b
-2:      add         r2, r2, #32
-
-        /* conditionally stores 0 to 31 bytes */
-        movs        r2, r2, lsl #28
-        stmcs       r0!, {r1,r3,r12,lr}
-        stmmi       r0!, {r1, lr}
-        movs        r2, r2, lsl #2
-        strcs       r1, [r0], #4
-        strhmi      r1, [r0], #2
-        movs        r2, r2, lsl #2
-        strbcs      r1, [r0]
-        ldmfd       sp!, {r0, r4-r7, pc}
-END(memset_generic)
diff --git a/libc/arch-arm/generic/bionic/stpcpy.c b/libc/arch-arm/generic/bionic/stpcpy.c
deleted file mode 100644
index 0aabaa5..0000000
--- a/libc/arch-arm/generic/bionic/stpcpy.c
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#define stpcpy stpcpy_generic
-#include <upstream-openbsd/lib/libc/string/stpcpy.c>
diff --git a/libc/arch-arm/generic/bionic/strcat.c b/libc/arch-arm/generic/bionic/strcat.c
deleted file mode 100644
index 8e70531..0000000
--- a/libc/arch-arm/generic/bionic/strcat.c
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#define strcat strcat_generic
-#include <upstream-openbsd/lib/libc/string/strcat.c>
diff --git a/libc/arch-arm/generic/bionic/strcmp.S b/libc/arch-arm/generic/bionic/strcmp.S
deleted file mode 100644
index 03225a0..0000000
--- a/libc/arch-arm/generic/bionic/strcmp.S
+++ /dev/null
@@ -1,320 +0,0 @@
-/*
- * Copyright (c) 2011 The Android Open Source Project
- * Copyright (c) 2008 ARM Ltd
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. The name of the company may not be used to endorse or promote
- *    products derived from this software without specific prior written
- *    permission.
- *
- * THIS SOFTWARE IS PROVIDED BY ARM LTD ``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 ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <private/bionic_asm.h>
-
-	.text
-
-        // To avoid warning about deprecated instructions, add an explicit
-        // arch. The code generated is exactly the same.
-        .arch armv7-a
-
-#ifdef __ARMEB__
-#define SHFT2LSB lsl
-#define SHFT2LSBEQ lsleq
-#define SHFT2MSB lsr
-#define SHFT2MSBEQ lsreq
-#define MSB 0x000000ff
-#define LSB 0xff000000
-#else
-#define SHFT2LSB lsr
-#define SHFT2LSBEQ lsreq
-#define SHFT2MSB lsl
-#define SHFT2MSBEQ lsleq
-#define MSB 0xff000000
-#define LSB 0x000000ff
-#endif
-
-#define magic1(REG) REG
-#define magic2(REG) REG, lsl #7
-
-ENTRY(strcmp_generic)
-	pld	[r0, #0]
-	pld	[r1, #0]
-	eor	r2, r0, r1
-	tst	r2, #3
-
-	/* Strings not at same byte offset from a word boundary.  */
-	bne	.Lstrcmp_unaligned
-	ands	r2, r0, #3
-	bic	r0, r0, #3
-	bic	r1, r1, #3
-	ldr	ip, [r0], #4
-	it	eq
-	ldreq	r3, [r1], #4
-	beq	1f
-
-	/* Although s1 and s2 have identical initial alignment, they are
-	 * not currently word aligned.  Rather than comparing bytes,
-	 * make sure that any bytes fetched from before the addressed
-	 * bytes are forced to 0xff.  Then they will always compare
-	 * equal.
-	 */
-	eor	r2, r2, #3
-	lsl	r2, r2, #3
-	mvn	r3, #MSB
-	SHFT2LSB	r2, r3, r2
-	ldr	r3, [r1], #4
-	orr	ip, ip, r2
-	orr	r3, r3, r2
-1:
-	/* Load the 'magic' constant 0x01010101. */
-	str	r4, [sp, #-4]!
-	mov	r4, #1
-	orr	r4, r4, r4, lsl #8
-	orr	r4, r4, r4, lsl #16
-	.p2align	2
-4:
-	pld	[r0, #8]
-	pld	[r1, #8]
-	sub	r2, ip, magic1(r4)
-	cmp	ip, r3
-	itttt	eq
-
-	/* check for any zero bytes in first word */
-	biceq	r2, r2, ip
-	tsteq	r2, magic2(r4)
-	ldreq	ip, [r0], #4
-	ldreq	r3, [r1], #4
-	beq	4b
-2:
-	/* There's a zero or a different byte in the word */
-	SHFT2MSB	r0, ip, #24
-	SHFT2LSB	ip, ip, #8
-	cmp	r0, #1
-	it	cs
-	cmpcs	r0, r3, SHFT2MSB #24
-	it	eq
-	SHFT2LSBEQ r3, r3, #8
-	beq	2b
-	/* On a big-endian machine, r0 contains the desired byte in bits
-	 * 0-7; on a little-endian machine they are in bits 24-31.  In
-	 * both cases the other bits in r0 are all zero.  For r3 the
-	 * interesting byte is at the other end of the word, but the
-	 * other bits are not necessarily zero.  We need a signed result
-	 * representing the differnece in the unsigned bytes, so for the
-	 * little-endian case we can't just shift the interesting bits up.
-	 */
-#ifdef __ARMEB__
-	sub	r0, r0, r3, lsr #24
-#else
-	and	r3, r3, #255
-	/* No RSB instruction in Thumb2 */
-#ifdef __thumb2__
-	lsr	r0, r0, #24
-	sub	r0, r0, r3
-#else
-	rsb	r0, r3, r0, lsr #24
-#endif
-#endif
-	ldr	r4, [sp], #4
-	bx	lr
-
-.Lstrcmp_unaligned:
-	wp1 .req r0
-	wp2 .req r1
-	b1  .req r2
-	w1  .req r4
-	w2  .req r5
-	t1  .req ip
-	@ r3 is scratch
-
-	/* First of all, compare bytes until wp1(sp1) is word-aligned. */
-1:
-	tst	wp1, #3
-	beq	2f
-	ldrb	r2, [wp1], #1
-	ldrb	r3, [wp2], #1
-	cmp	r2, #1
-	it	cs
-	cmpcs	r2, r3
-	beq	1b
-	sub	r0, r2, r3
-	bx	lr
-
-2:
-	str	r5, [sp, #-4]!
-	str	r4, [sp, #-4]!
-	mov	b1, #1
-	orr	b1, b1, b1, lsl #8
-	orr	b1, b1, b1, lsl #16
-
-	and	t1, wp2, #3
-	bic	wp2, wp2, #3
-	ldr	w1, [wp1], #4
-	ldr	w2, [wp2], #4
-	cmp	t1, #2
-	beq	2f
-	bhi	3f
-
-	/* Critical inner Loop: Block with 3 bytes initial overlap */
-	.p2align	2
-1:
-	bic	t1, w1, #MSB
-	cmp	t1, w2, SHFT2LSB #8
-	sub	r3, w1, b1
-	bic	r3, r3, w1
-	bne	4f
-	ands	r3, r3, b1, lsl #7
-	it	eq
-	ldreq	w2, [wp2], #4
-	bne	5f
-	eor	t1, t1, w1
-	cmp	t1, w2, SHFT2MSB #24
-	bne	6f
-	ldr	w1, [wp1], #4
-	b	1b
-4:
-	SHFT2LSB	w2, w2, #8
-	b	8f
-
-5:
-#ifdef __ARMEB__
-	/* The syndrome value may contain false ones if the string ends
-	 * with the bytes 0x01 0x00
-	 */
-	tst	w1, #0xff000000
-	itt	ne
-	tstne	w1, #0x00ff0000
-	tstne	w1, #0x0000ff00
-	beq	7f
-#else
-	bics	r3, r3, #0xff000000
-	bne	7f
-#endif
-	ldrb	w2, [wp2]
-	SHFT2LSB	t1, w1, #24
-#ifdef __ARMEB__
-	lsl	w2, w2, #24
-#endif
-	b	8f
-
-6:
-	SHFT2LSB	t1, w1, #24
-	and	w2, w2, #LSB
-	b	8f
-
-	/* Critical inner Loop: Block with 2 bytes initial overlap */
-	.p2align	2
-2:
-	SHFT2MSB	t1, w1, #16
-	sub	r3, w1, b1
-	SHFT2LSB	t1, t1, #16
-	bic	r3, r3, w1
-	cmp	t1, w2, SHFT2LSB #16
-	bne	4f
-	ands	r3, r3, b1, lsl #7
-	it	eq
-	ldreq	w2, [wp2], #4
-	bne	5f
-	eor	t1, t1, w1
-	cmp	t1, w2, SHFT2MSB #16
-	bne	6f
-	ldr	w1, [wp1], #4
-	b	2b
-
-5:
-#ifdef __ARMEB__
-	/* The syndrome value may contain false ones if the string ends
-	 * with the bytes 0x01 0x00
-	 */
-	tst	w1, #0xff000000
-	it	ne
-	tstne	w1, #0x00ff0000
-	beq	7f
-#else
-	lsls	r3, r3, #16
-	bne	7f
-#endif
-	ldrh	w2, [wp2]
-	SHFT2LSB	t1, w1, #16
-#ifdef __ARMEB__
-	lsl	w2, w2, #16
-#endif
-	b	8f
-
-6:
-	SHFT2MSB	w2, w2, #16
-	SHFT2LSB	t1, w1, #16
-4:
-	SHFT2LSB	w2, w2, #16
-	b	8f
-
-	/* Critical inner Loop: Block with 1 byte initial overlap */
-	.p2align	2
-3:
-	and	t1, w1, #LSB
-	cmp	t1, w2, SHFT2LSB #24
-	sub	r3, w1, b1
-	bic	r3, r3, w1
-	bne	4f
-	ands	r3, r3, b1, lsl #7
-	it	eq
-	ldreq	w2, [wp2], #4
-	bne	5f
-	eor	t1, t1, w1
-	cmp	t1, w2, SHFT2MSB #8
-	bne	6f
-	ldr	w1, [wp1], #4
-	b	3b
-4:
-	SHFT2LSB	w2, w2, #24
-	b	8f
-5:
-	/* The syndrome value may contain false ones if the string ends
-	 * with the bytes 0x01 0x00
-	 */
-	tst	w1, #LSB
-	beq	7f
-	ldr	w2, [wp2], #4
-6:
-	SHFT2LSB	t1, w1, #8
-	bic	w2, w2, #MSB
-	b	8f
-7:
-	mov	r0, #0
-	ldr	r4, [sp], #4
-	ldr	r5, [sp], #4
-	bx	lr
-
-8:
-	and	r2, t1, #LSB
-	and	r0, w2, #LSB
-	cmp	r0, #1
-	it	cs
-	cmpcs	r0, r2
-	itt	eq
-	SHFT2LSBEQ	t1, t1, #8
-	SHFT2LSBEQ	w2, w2, #8
-	beq	8b
-	sub	r0, r2, r0
-	ldr	r4, [sp], #4
-	ldr	r5, [sp], #4
-	bx	lr
-END(strcmp_generic)
diff --git a/libc/arch-arm/generic/bionic/strcpy.S b/libc/arch-arm/generic/bionic/strcpy.S
deleted file mode 100644
index 89bd699..0000000
--- a/libc/arch-arm/generic/bionic/strcpy.S
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- * Copyright (c) 2008 ARM Ltd
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. The name of the company may not be used to endorse or promote
- *    products derived from this software without specific prior written
- *    permission.
- *
- * THIS SOFTWARE IS PROVIDED BY ARM LTD ``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 ARM LTD 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.
- *
- * Android adaptation and tweak by Jim Huang <jserv@0xlab.org>.
- */
-
-#include <private/bionic_asm.h>
-
-.syntax unified
-
-// To avoid warning about deprecated instructions, add an explicit
-// arch. The code generated is exactly the same.
-.arch armv7-a
-
-ENTRY(strcpy_generic)
-	pld	[r1, #0]
-	eor	r2, r0, r1
-	mov	ip, r0
-	tst	r2, #3
-	bne	4f
-	tst	r1, #3
-	bne	3f
-5:
-	str	r5, [sp, #-4]!
-	mov	r5, #0x01
-	orr	r5, r5, r5, lsl #8
-	orr	r5, r5, r5, lsl #16
-
-	str	r4, [sp, #-4]!
-	tst	r1, #4
-	ldr	r3, [r1], #4
-	beq	2f
-	sub	r2, r3, r5
-	bics	r2, r2, r3
-	tst	r2, r5, lsl #7
-	itt	eq
-	streq	r3, [ip], #4
-	ldreq	r3, [r1], #4
-	bne	1f
-       /* Inner loop.  We now know that r1 is 64-bit aligned, so we
-	  can safely fetch up to two words.  This allows us to avoid
-	  load stalls.  */
-	.p2align 2
-2:
-	pld	[r1, #8]
-	ldr	r4, [r1], #4
-	sub	r2, r3, r5
-	bics	r2, r2, r3
-	tst	r2, r5, lsl #7
-	sub	r2, r4, r5
-	bne	1f
-	str	r3, [ip], #4
-	bics	r2, r2, r4
-	tst	r2, r5, lsl #7
-	itt	eq
-	ldreq	r3, [r1], #4
-	streq	r4, [ip], #4
-	beq	2b
-	mov	r3, r4
-1:
-#ifdef __ARMEB__
-	rors	r3, r3, #24
-#endif
-	strb	r3, [ip], #1
-	tst	r3, #0xff
-#ifdef __ARMEL__
-	ror	r3, r3, #8
-#endif
-	bne	1b
-	ldr	r4, [sp], #4
-	ldr	r5, [sp], #4
-	bx	lr
-
-       /* Strings have the same offset from word alignment, but it's
-	  not zero.  */
-3:
-	tst	r1, #1
-	beq	1f
-	ldrb	r2, [r1], #1
-	strb	r2, [ip], #1
-	cmp	r2, #0
-	it	eq
-	bxeq	lr
-1:
-	tst	r1, #2
-	beq	5b
-	ldrh	r2, [r1], #2
-#ifdef __ARMEB__
-	tst	r2, #0xff00
-	iteet	ne
-	strhne	r2, [ip], #2
-	lsreq	r2, r2, #8
-	strbeq	r2, [ip]
-	tstne	r2, #0xff
-#else
-	tst	r2, #0xff
-	itet	ne
-	strhne	r2, [ip], #2
-	strbeq	r2, [ip]
-	tstne	r2, #0xff00
-#endif
-	bne	5b
-	bx	lr
-
-       /* src and dst do not have a common word-alignement.  Fall back to
-	  byte copying.  */
-4:
-	ldrb	r2, [r1], #1
-	strb	r2, [ip], #1
-	cmp	r2, #0
-	bne	4b
-	bx	lr
-END(strcpy_generic)
diff --git a/libc/arch-arm/generic/bionic/strlen.c b/libc/arch-arm/generic/bionic/strlen.c
deleted file mode 100644
index a6fde8b..0000000
--- a/libc/arch-arm/generic/bionic/strlen.c
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <string.h>
-#include <stdint.h>
-
-size_t strlen_generic(const char *s)
-{
-    __builtin_prefetch(s);
-    __builtin_prefetch(s+32);
-
-    union {
-        const char      *b;
-        const uint32_t  *w;
-        uintptr_t       i;
-    } u;
-
-    // these are some scratch variables for the asm code below
-    uint32_t v, t;
-
-    // initialize the string length to zero
-    size_t l = 0;
-
-    // align the pointer to a 32-bit word boundary
-    u.b = s;
-    while (u.i & 0x3)  {
-        if (__builtin_expect(*u.b++ == 0, 0)) {
-            goto done;
-        }
-        l++;
-    }
-
-    // loop for each word, testing if it contains a zero byte
-    // if so, exit the loop and update the length.
-    // We need to process 32 bytes per loop to schedule PLD properly
-    // and achieve the maximum bus speed.
-    asm(
-        "ldr     %[v], [%[s]], #4           \n"
-        "sub     %[l], %[l], %[s]           \n"
-        "0:                                 \n"
-        "pld     [%[s], #64]                \n"
-        "sub     %[t], %[v], %[mask], lsr #7\n"
-        "and     %[t], %[t], %[mask]        \n"
-        "bics    %[t], %[t], %[v]           \n"
-        "bne     1f                         \n"
-        "ldr     %[v], [%[s]], #4           \n"
-#if !defined(__OPTIMIZE_SIZE__)
-        "sub     %[t], %[v], %[mask], lsr #7\n"
-        "and     %[t], %[t], %[mask]        \n"
-        "bics    %[t], %[t], %[v]           \n"
-        "bne     1f                         \n"
-        "ldr     %[v], [%[s]], #4           \n"
-        "sub     %[t], %[v], %[mask], lsr #7\n"
-        "and     %[t], %[t], %[mask]        \n"
-        "bics    %[t], %[t], %[v]           \n"
-        "bne     1f                         \n"
-        "ldr     %[v], [%[s]], #4           \n"
-        "sub     %[t], %[v], %[mask], lsr #7\n"
-        "and     %[t], %[t], %[mask]        \n"
-        "bics    %[t], %[t], %[v]           \n"
-        "bne     1f                         \n"
-        "ldr     %[v], [%[s]], #4           \n"
-        "sub     %[t], %[v], %[mask], lsr #7\n"
-        "and     %[t], %[t], %[mask]        \n"
-        "bics    %[t], %[t], %[v]           \n"
-        "bne     1f                         \n"
-        "ldr     %[v], [%[s]], #4           \n"
-        "sub     %[t], %[v], %[mask], lsr #7\n"
-        "and     %[t], %[t], %[mask]        \n"
-        "bics    %[t], %[t], %[v]           \n"
-        "bne     1f                         \n"
-        "ldr     %[v], [%[s]], #4           \n"
-        "sub     %[t], %[v], %[mask], lsr #7\n"
-        "and     %[t], %[t], %[mask]        \n"
-        "bics    %[t], %[t], %[v]           \n"
-        "bne     1f                         \n"
-        "ldr     %[v], [%[s]], #4           \n"
-        "sub     %[t], %[v], %[mask], lsr #7\n"
-        "and     %[t], %[t], %[mask]        \n"
-        "bics    %[t], %[t], %[v]           \n"
-        "bne     1f                         \n"
-        "ldr     %[v], [%[s]], #4           \n"
-#endif
-        "b       0b                         \n"
-        "1:                                 \n"
-        "add     %[l], %[l], %[s]           \n"
-        "tst     %[v], #0xFF                \n"
-        "beq     2f                         \n"
-        "add     %[l], %[l], #1             \n"
-        "tst     %[v], #0xFF00              \n"
-        "beq     2f                         \n"
-        "add     %[l], %[l], #1             \n"
-        "tst     %[v], #0xFF0000            \n"
-        "beq     2f                         \n"
-        "add     %[l], %[l], #1             \n"
-        "2:                                 \n"
-        : [l]"=&r"(l), [v]"=&r"(v), [t]"=&r"(t), [s]"=&r"(u.b)
-        : "%[l]"(l), "%[s]"(u.b), [mask]"r"(0x80808080UL)
-        : "cc"
-    );
-
-done:
-    return l;
-}
diff --git a/libc/arch-arm/generic/bionic/__memcpy_chk.S b/libc/arch-arm/generic/string/__memcpy_chk.S
similarity index 100%
rename from libc/arch-arm/generic/bionic/__memcpy_chk.S
rename to libc/arch-arm/generic/string/__memcpy_chk.S
diff --git a/libc/arch-arm/generic/bionic/memcmp.S b/libc/arch-arm/generic/string/memcmp.S
similarity index 100%
rename from libc/arch-arm/generic/bionic/memcmp.S
rename to libc/arch-arm/generic/string/memcmp.S
diff --git a/libc/arch-arm/dynamic_function_dispatch.cpp b/libc/arch-arm/ifuncs.cpp
similarity index 100%
rename from libc/arch-arm/dynamic_function_dispatch.cpp
rename to libc/arch-arm/ifuncs.cpp
diff --git a/libc/arch-arm/krait/bionic/__strcat_chk.S b/libc/arch-arm/krait/string/__strcat_chk.S
similarity index 100%
rename from libc/arch-arm/krait/bionic/__strcat_chk.S
rename to libc/arch-arm/krait/string/__strcat_chk.S
diff --git a/libc/arch-arm/krait/bionic/__strcpy_chk.S b/libc/arch-arm/krait/string/__strcpy_chk.S
similarity index 100%
rename from libc/arch-arm/krait/bionic/__strcpy_chk.S
rename to libc/arch-arm/krait/string/__strcpy_chk.S
diff --git a/libc/arch-arm/krait/bionic/memcpy.S b/libc/arch-arm/krait/string/memcpy.S
similarity index 100%
rename from libc/arch-arm/krait/bionic/memcpy.S
rename to libc/arch-arm/krait/string/memcpy.S
diff --git a/libc/arch-arm/krait/bionic/memcpy_base.S b/libc/arch-arm/krait/string/memcpy_base.S
similarity index 100%
rename from libc/arch-arm/krait/bionic/memcpy_base.S
rename to libc/arch-arm/krait/string/memcpy_base.S
diff --git a/libc/arch-arm/krait/bionic/memset.S b/libc/arch-arm/krait/string/memset.S
similarity index 100%
rename from libc/arch-arm/krait/bionic/memset.S
rename to libc/arch-arm/krait/string/memset.S
diff --git a/libc/arch-arm/kryo/bionic/memcpy.S b/libc/arch-arm/kryo/string/memcpy.S
similarity index 100%
rename from libc/arch-arm/kryo/bionic/memcpy.S
rename to libc/arch-arm/kryo/string/memcpy.S
diff --git a/libc/arch-arm64/bionic/__bionic_clone.S b/libc/arch-arm64/bionic/__bionic_clone.S
index 581b47a..03ec2f9 100644
--- a/libc/arch-arm64/bionic/__bionic_clone.S
+++ b/libc/arch-arm64/bionic/__bionic_clone.S
@@ -50,9 +50,9 @@
 
 L(child):
     # We're in the child now. Set the end of the frame record chain.
-    mov     x29, #0
-    # Setting x30 to 0 will make the unwinder stop at __start_thread.
-    mov     x30, #0
+    mov     fp, #0
+    # Setting lr to 0 will make the unwinder stop at __start_thread.
+    mov     lr, #0
     # Call __start_thread with the 'fn' and 'arg' we stored on the child stack.
     ldp     x0, x1, [sp], #16
     b       __start_thread
diff --git a/libc/arch-arm64/dynamic_function_dispatch.cpp b/libc/arch-arm64/ifuncs.cpp
similarity index 84%
rename from libc/arch-arm64/dynamic_function_dispatch.cpp
rename to libc/arch-arm64/ifuncs.cpp
index 29e47b3..49e67b4 100644
--- a/libc/arch-arm64/dynamic_function_dispatch.cpp
+++ b/libc/arch-arm64/ifuncs.cpp
@@ -29,21 +29,24 @@
 #include <private/bionic_ifuncs.h>
 #include <stddef.h>
 
+// Accessors for the fields in MIDR_EL1.
+// https://developer.arm.com/documentation/ddi0601/latest/AArch64-Registers/MIDR-EL1--Main-ID-Register
+// https://www.kernel.org/doc/html/latest/arch/arm64/cpu-feature-registers.html#list-of-registers-with-visible-features
+// We don't bother with "architecture" here because it's only meaningful for arm32.
+inline int implementer(uint64_t midr_el1) { return (midr_el1 >> 24) & 0xff; }
+inline int variant(uint64_t midr_el1) { return (midr_el1 >> 20) & 0xf; }
+inline int part(uint64_t midr_el1) { return (midr_el1 >> 4) & 0xfff; }
+inline int revision(uint64_t midr_el1) { return (midr_el1 >> 0) & 0xf; }
+
 static inline bool __bionic_is_oryon(unsigned long hwcap) {
   if (!(hwcap & HWCAP_CPUID)) return false;
 
-  // Extract the implementor and variant bits from MIDR_EL1.
-  // https://www.kernel.org/doc/html/latest/arch/arm64/cpu-feature-registers.html#list-of-registers-with-visible-features
   unsigned long midr;
   __asm__ __volatile__("mrs %0, MIDR_EL1" : "=r"(midr));
-  uint16_t cpu = (midr >> 20) & 0xfff;
 
-  auto make_cpu = [](unsigned implementor, unsigned variant) {
-    return (implementor << 4) | variant;
-  };
-
-  // Check for implementor Qualcomm's variants 0x1..0x5 (Oryon).
-  return cpu >= make_cpu('Q', 0x1) && cpu <= make_cpu('Q', 0x5);
+  // Check for implementor Qualcomm's parts 0..15 (Oryon).
+  // Variant (big vs middle vs little) and revision are ignored.
+  return implementer(midr) == 'Q' && part(midr) <= 15;
 }
 
 extern "C" {
diff --git a/libc/arch-arm64/oryon/memset-nt.S b/libc/arch-arm64/oryon/memset-nt.S
index b91e7da..8b7f76d 100644
--- a/libc/arch-arm64/oryon/memset-nt.S
+++ b/libc/arch-arm64/oryon/memset-nt.S
@@ -1,6 +1,6 @@
 /* Copyright (c) 2012, Linaro Limited
    All rights reserved.
-   Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
+   Copyright (c) 2025 Qualcomm Innovation Center, Inc. All rights reserved.
    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions are met:
        * Redistributions of source code must retain the above copyright
@@ -32,7 +32,7 @@
 #include <private/bionic_asm.h>
 
 #define dstin		x0
-#define val		    w1
+#define val		w1
 #define count		x2
 #define tmp1		x3
 #define tmp1w		w3
@@ -41,178 +41,186 @@
 #define zva_len_x	x5
 #define zva_len		w5
 #define zva_bits_x	x6
-#define A_l		    x7
+#define A_l		x7
 #define A_lw		w7
-#define dst		    x8
+#define dst		x8
+#define tmp3		x9
 #define tmp3w		w9
-#define tmp4        x10
-#define SMALL_BUFFER_SIZE    96
+#define tmp4            x10
 
 ENTRY(__memset_aarch64_nt)
-    mov	dst, dstin		/* Preserve return value.  */
-    ands	A_lw, val, #255
-    b.eq	.Lzero_mem  /* Use DC ZVA instruction if the val = 0 */
-    orr	A_lw, A_lw, A_lw, lsl #8
-    orr	A_lw, A_lw, A_lw, lsl #16
-    orr	A_l, A_l, A_l, lsl #32
+    mov    dst, dstin		/* Preserve return value.  */
+    and    A_lw, val, #255
+    orr    A_lw, A_lw, A_lw, lsl #8
+    orr    A_lw, A_lw, A_lw, lsl #16
+    orr    A_l, A_l, A_l, lsl #32
 .Ltail_maybe_long:
-    cmp	count, #64
-    b.ge	.Lnot_short
+    cmp    count, #64
+    b.ge   .LisValZero		/* Case : Size greater than or equal to 64 bytes */
 .Ltail_maybe_tiny:
-    cmp	count, #15
-    b.le	.Ltail15tiny
-.Ltail63:
-    ands	tmp1, count, #0x30
-    b.eq	.Ltail15
-    add	dst, dst, tmp1
-    cmp	tmp1w, #0x20
-    b.eq	1f
-    b.lt	2f
-    stp	A_l, A_l, [dst, #-48]
-1:
-    stp	A_l, A_l, [dst, #-32]
-2:
-    stp	A_l, A_l, [dst, #-16]
-.Ltail15:
-    and	count, count, #15
-    add	dst, dst, count
-    stp	A_l, A_l, [dst, #-16]	/* Repeat some/all of last store. */
+    cmp    count, #15
+    b.le   .Ltail15tiny		/* Case : Size is less than or equal to 15 bytes */
+.Ltail63:				/* Size is between 16 to 63 bytes */
+
+/* Size 16 - 63. Do 4x16 bytes wrire. Based on the size, adjust the offsets to cover full range of 16 - 63 bytes */
+    add    tmp4, dst, count
+    mov    tmp1, 16
+    and    tmp1, tmp1, count, lsr 1
+    sub    tmp2, tmp4, tmp1
+    add    tmp3, dst, tmp1
+
+/* 	1st Store : First 16 bytes
+ *	2nd Store : For size is less than 32, first 16 bytes. For size greater than 32,17-32 bytes.
+ *	3rd Store : For size is less than 32, last 16 bytes. For size greater than 32, write 16 bytes from address:[last address-32].
+ *	4th Store : Last 16 bytes
+ */
+    stp    A_l, A_l, [dst]
+    stp    A_l, A_l, [tmp3]
+    stp    A_l, A_l, [tmp2, -16]
+    stp    A_l, A_l, [tmp4, -16]
     ret
-.Ltail15tiny:
-    /* Set up to 15 bytes.  Does not assume earlier memory
-       being set.  */
-    tbz	count, #3, 1f
-    str	A_l, [dst], #8
-1:
-    tbz	count, #2, 1f
-    str	A_lw, [dst], #4
-1:
-    tbz	count, #1, 1f
-    strh	A_lw, [dst], #2
-1:
-    tbz	count, #0, 1f
-    strb	A_lw, [dst]
-1:
+.Ltail15tiny:				/* Size is less than or equal to 15 bytes */
+/* Size < 16. Do 4x4 bytes wrire. Based on the size, adjust the offsets to cover full range of 1-15 bytes */
+    cmp    count, 4			/* Check for Size < 4 bytes */
+    b.lt   .tiny_4B			/* Case : Size is less than 4 bytes */
+    add    tmp4, dst, count
+    lsr    tmp1, count, 3
+    sub    tmp2, tmp4, tmp1, lsl 2
+    str    A_lw, [dst]
+    str    A_lw, [dst, tmp1, lsl 2]
+    str    A_lw, [tmp2, -4]
+    str    A_lw, [tmp4, -4]
+    ret
+.tiny_4B:				/* Size is less 4 bytes */
+    cbz    count, .tiny_end		/* Check if size is 0 */
+    add    tmp4, dst, count
+    lsr    tmp1, count, 1
+    strb   A_lw, [dst]
+    strb   A_lw, [dst, tmp1]
+    strb   A_lw, [tmp4, -1]
+.tiny_end:
     ret
     /* Critical loop.  Start at a new cache line boundary.  Assuming
      * 64 bytes per line, this ensures the entire loop is in one line.  */
     .p2align 6
+.LisValZero:
+    cbnz   A_lw, .Lnot_short
+    /* For value = 0, if size is greater than BUF_SIZE_FOR_ZVA bytes,
+     * use DC ZVA to set 0, else use STP instructions to set 0 	*/
+    cmp    count, #512			/* For size greater than 512 bytes, use DC ZVA, it is better than STP */
+    b.gt   .Lzero_mem
 .Lnot_short:
-    mov tmp4, #SMALL_BUFFER_SIZE
-    cmp count, tmp4, LSL#10
-    /* Use non-temporal instruction if count > SMALL_BUFFER_SIZE */
-    bgt L(not_short_nt)
-    neg	tmp2, dst
-    ands	tmp2, tmp2, #15
-    b.eq	2f
+    cmp    count, #98304
+    /* Use non-temporal instruction if count > 98304 (96KB) . Non Temporal Store is beneficial is size is greater that 96 KB*/
+    bgt    .Lnot_short_nt
+    neg    tmp2, dst
+    ands   tmp2, tmp2, #15
+    b.eq   2f
     /* Bring DST to 128-bit (16-byte) alignment.  We know that there's
      * more than that to set, so we simply store 16 bytes and advance by
      * the amount required to reach alignment.  */
-    sub	count, count, tmp2
-    stp	A_l, A_l, [dst]
-    add	dst, dst, tmp2
+    sub    count, count, tmp2
+    stp    A_l, A_l, [dst]
+    add    dst, dst, tmp2
     /* There may be less than 63 bytes to go now.  */
-    cmp	count, #63
-    b.le	.Ltail63
+    cmp    count, #63
+    b.le   .Ltail_maybe_tiny
 2:
-    sub	dst, dst, #16		/* Pre-bias.  */
-    sub	count, count, #64
+    sub    dst, dst, #16		/* Pre-bias.  */
+    sub    count, count, #64
 1:
-    stp	A_l, A_l, [dst, #16]
-    stp	A_l, A_l, [dst, #32]
-    stp	A_l, A_l, [dst, #48]
-    stp	A_l, A_l, [dst, #64]!
-    subs	count, count, #64
-    b.ge	1b
-    tst	count, #0x3f
-    add	dst, dst, #16
-    b.ne	.Ltail63
+    stp    A_l, A_l, [dst, #16]
+    stp    A_l, A_l, [dst, #32]
+    stp    A_l, A_l, [dst, #48]
+    stp    A_l, A_l, [dst, #64]
+    add    dst, dst, #64
+    subs   count, count, #64
+    b.ge   1b
+    add    dst, dst, #16
+    add    count, count, #64
+    cbnz   count, .Ltail_maybe_tiny
     ret
 .Lnot_short_nt:
-    neg	tmp2, dst
-    ands	tmp2, tmp2, #15
-    b.eq	2f
+    neg    tmp2, dst
+    ands   tmp2, tmp2, #15
+    b.eq   2f
     /* Bring DST to 128-bit (16-byte) alignment.  We know that there's
      * more than that to set, so we simply store 16 bytes and advance by
      * the amount required to reach alignment.  */
-    sub	count, count, tmp2
-    stnp	A_l, A_l, [dst]
-    add	dst, dst, tmp2
+    sub    count, count, tmp2
+    stnp   A_l, A_l, [dst]
+    add    dst, dst, tmp2
     /* There may be less than 63 bytes to go now.  */
-    cmp	count, #63
-    b.le	.Ltail63
+    cmp    count, #63
+    b.le   .Ltail_maybe_tiny
 2:
-    sub	dst, dst, #16		/* Pre-bias.  */
-    sub	count, count, #64
+    sub    dst, dst, #16		/* Pre-bias.  */
+    sub    count, count, #64
 1:
-    stnp	A_l, A_l, [dst, #16]
-    stnp	A_l, A_l, [dst, #32]
-    stnp	A_l, A_l, [dst, #48]
-    stnp	A_l, A_l, [dst, #64]
-    add     dst, dst, #64
-    subs	count, count, #64
-    b.ge	1b
-    tst	count, #0x3f
-    add	dst, dst, #16
-    b.ne	.Ltail63
+    stnp   A_l, A_l, [dst, #16]
+    stnp   A_l, A_l, [dst, #32]
+    stnp   A_l, A_l, [dst, #48]
+    stnp   A_l, A_l, [dst, #64]
+    add    dst, dst, #64
+    subs   count, count, #64
+    b.ge   1b
+    add    dst, dst, #16
+    add    count, count, #64			/* Count is negative now as it is pre decreament in 2: Revert it to have exact count before branching to Ltail_maybe_tiny */
+    cbnz   count, .Ltail_maybe_tiny
     ret
 .Lzero_mem:
-    mov	A_l, #0
-    cmp	count, #63
-    b.le	.Ltail_maybe_tiny
-    neg	tmp2, dst
-    ands	tmp2, tmp2, #15
-    b.eq	1f
-    sub	count, count, tmp2
-    stp	A_l, A_l, [dst]
-    add	dst, dst, tmp2
-    cmp	count, #63
-    b.le	.Ltail63
+    mov    A_l, #0
+    neg    tmp2, dst
+    ands   tmp2, tmp2, #15
+    b.eq   1f
+    sub    count, count, tmp2
+    stp    A_l, A_l, [dst]
+    add    dst, dst, tmp2
+    cmp    count, #63
+    b.le   .Ltail_maybe_tiny
 1:
     /* For zeroing small amounts of memory, it's not worth setting up
      * the line-clear code.  */
-    cmp	count, #128
-    b.lt	.Lnot_short
-    mrs	tmp1, dczid_el0
-    tbnz	tmp1, #4, .Lnot_short
-    mov	tmp3w, #4
-    and	zva_len, tmp1w, #15	/* Safety: other bits reserved.  */
-    lsl	zva_len, tmp3w, zva_len
+    mrs    tmp1, dczid_el0
+    tbnz   tmp1, #4, .Lnot_short
+    mov    tmp3w, #4
+    and    zva_len, tmp1w, #15	/* Safety: other bits reserved.  */
+    lsl    zva_len, tmp3w, zva_len
 .Lzero_by_line:
     /* Compute how far we need to go to become suitably aligned.  We're
      * already at quad-word alignment.  */
-    cmp	count, zva_len_x
-    b.lt	.Lnot_short		/* Not enough to reach alignment.  */
-    sub	zva_bits_x, zva_len_x, #1
-    neg	tmp2, dst
-    ands	tmp2, tmp2, zva_bits_x
-    b.eq	1f			/* Already aligned.  */
+    cmp    count, zva_len_x
+    b.lt   .Lnot_short		/* Not enough to reach alignment.  */
+    sub	   zva_bits_x, zva_len_x, #1
+    neg    tmp2, dst
+    ands   tmp2, tmp2, zva_bits_x
+    b.eq   1f			/* Already aligned.  */
     /* Not aligned, check that there's enough to copy after alignment.  */
-    sub	tmp1, count, tmp2
-    cmp	tmp1, #64
-    ccmp	tmp1, zva_len_x, #8, ge	/* NZCV=0b1000 */
-    b.lt	.Lnot_short
+    sub    tmp1, count, tmp2
+    cmp    tmp1, #64
+    ccmp   tmp1, zva_len_x, #8, ge	/* NZCV=0b1000 */
+    b.lt   .Lnot_short
     /* We know that there's at least 64 bytes to zero and that it's safe
      * to overrun by 64 bytes.  */
-    mov	count, tmp1
+    mov    count, tmp1
 2:
-    stp	A_l, A_l, [dst]
-    stp	A_l, A_l, [dst, #16]
-    stp	A_l, A_l, [dst, #32]
-    subs	tmp2, tmp2, #64
-    stp	A_l, A_l, [dst, #48]
-    add	dst, dst, #64
-    b.ge	2b
+    stp    A_l, A_l, [dst]
+    stp    A_l, A_l, [dst, #16]
+    stp    A_l, A_l, [dst, #32]
+    subs   tmp2, tmp2, #64
+    stp    A_l, A_l, [dst, #48]
+    add    dst, dst, #64
+    b.ge   2b
     /* We've overrun a bit, so adjust dst downwards.  */
-    add	dst, dst, tmp2
+    add    dst, dst, tmp2
 1:
-    sub	count, count, zva_len_x
+    sub    count, count, zva_len_x
 3:
-    dc	zva, dst
-    add	dst, dst, zva_len_x
-    subs	count, count, zva_len_x
-    b.ge	3b
-    ands	count, count, zva_bits_x
-    b.ne	.Ltail_maybe_long
+    dc     zva, dst
+    add    dst, dst, zva_len_x
+    subs   count, count, zva_len_x
+    b.ge   3b
+    ands   count, count, zva_bits_x
+    b.ne   .Ltail_maybe_long
     ret
 END(__memset_aarch64_nt)
diff --git a/libc/arch-arm64/string/__memcpy_chk.S b/libc/arch-arm64/string/__memcpy_chk.S
index c9fc2f7..e0acdcf 100644
--- a/libc/arch-arm64/string/__memcpy_chk.S
+++ b/libc/arch-arm64/string/__memcpy_chk.S
@@ -36,10 +36,10 @@
 
 L(__memcpy_chk_fail_trampoline):
   // Preserve for accurate backtrace.
-  stp x29, x30, [sp, -16]!
+  stp fp, lr, [sp, -16]!
   .cfi_def_cfa_offset 16
-  .cfi_rel_offset x29, 0
-  .cfi_rel_offset x30, 8
+  .cfi_rel_offset fp, 0
+  .cfi_rel_offset lr, 8
 
   bl __memcpy_chk_fail
 END(__memcpy_chk)
diff --git a/libc/arch-arm64/string/__memset_chk.S b/libc/arch-arm64/string/__memset_chk.S
index 7a105ce..93c5a28 100644
--- a/libc/arch-arm64/string/__memset_chk.S
+++ b/libc/arch-arm64/string/__memset_chk.S
@@ -36,10 +36,10 @@
 
 L(__memset_chk_fail_trampoline):
   // Preserve for accurate backtrace.
-  stp x29, x30, [sp, -16]!
+  stp fp, lr, [sp, -16]!
   .cfi_def_cfa_offset 16
-  .cfi_rel_offset x29, 0
-  .cfi_rel_offset x30, 8
+  .cfi_rel_offset fp, 0
+  .cfi_rel_offset lr, 8
 
   bl __memset_chk_fail
 END(__memset_chk)
diff --git a/libc/arch-common/bionic/crt_pad_segment.S b/libc/arch-common/bionic/crt_pad_segment.S
index 2fbe0b9..2c39f93 100644
--- a/libc/arch-common/bionic/crt_pad_segment.S
+++ b/libc/arch-common/bionic/crt_pad_segment.S
@@ -26,13 +26,10 @@
  * SUCH DAMAGE.
  */
 
-#if defined(__aarch64__)
-#include <private/bionic_asm_arm64.h>
+#include <private/bionic_asm.h>
+#include <private/bionic_asm_note.h>
 
 __bionic_asm_custom_note_gnu_section()
-#endif
-
-#include <private/bionic_asm_note.h>
 
   .section ".note.android.pad_segment", "a", %note
   .balign 4
diff --git a/libc/arch-common/bionic/crtbegin.c b/libc/arch-common/bionic/crtbegin.c
index 127896a..f5c843c 100644
--- a/libc/arch-common/bionic/crtbegin.c
+++ b/libc/arch-common/bionic/crtbegin.c
@@ -85,7 +85,7 @@
 #define POST "; .size _start, .-_start"
 
 #if defined(__aarch64__)
-__asm__(PRE "bti j; mov x29,#0; mov x30,#0; mov x0,sp; b _start_main" POST);
+__asm__(PRE "bti j; mov fp,#0; mov lr,#0; mov x0,sp; b _start_main" POST);
 #elif defined(__arm__)
 __asm__(PRE "mov fp,#0; mov lr,#0; mov r0,sp; b _start_main" POST);
 #elif defined(__i386__)
diff --git a/libc/arch-common/bionic/crtbrand.S b/libc/arch-common/bionic/crtbrand.S
index b7540e9..26b973f 100644
--- a/libc/arch-common/bionic/crtbrand.S
+++ b/libc/arch-common/bionic/crtbrand.S
@@ -26,13 +26,10 @@
  * SUCH DAMAGE.
  */
 
-#if defined(__aarch64__)
-#include <private/bionic_asm_arm64.h>
+#include <private/bionic_asm.h>
+#include <private/bionic_asm_note.h>
 
 __bionic_asm_custom_note_gnu_section()
-#endif
-
-#include <private/bionic_asm_note.h>
 
   .section .note.android.ident,"a",%note
   .balign 4
diff --git a/libc/arch-common/bionic/crtend.S b/libc/arch-common/bionic/crtend.S
index 74b3aa9..8f0bce9 100644
--- a/libc/arch-common/bionic/crtend.S
+++ b/libc/arch-common/bionic/crtend.S
@@ -28,11 +28,9 @@
 
 #include "asm_multiarch.h"
 
-#if defined(__aarch64__)
-#include <private/bionic_asm_arm64.h>
+#include <private/bionic_asm.h>
 
 __bionic_asm_custom_note_gnu_section()
-#endif
 
 	.section .note.GNU-stack, "", %progbits
 
diff --git a/libc/arch-common/bionic/crtend_so.S b/libc/arch-common/bionic/crtend_so.S
index bc4bfb6..1e0a394 100644
--- a/libc/arch-common/bionic/crtend_so.S
+++ b/libc/arch-common/bionic/crtend_so.S
@@ -26,11 +26,9 @@
  * SUCH DAMAGE.
  */
 
-#if defined(__aarch64__)
-#include <private/bionic_asm_arm64.h>
+#include <private/bionic_asm.h>
 
 __bionic_asm_custom_note_gnu_section()
-#endif
 
 	.section .note.GNU-stack, "", %progbits
 
diff --git a/libc/arch-x86/dynamic_function_dispatch.cpp b/libc/arch-x86/ifuncs.cpp
similarity index 100%
rename from libc/arch-x86/dynamic_function_dispatch.cpp
rename to libc/arch-x86/ifuncs.cpp
diff --git a/libc/arch-x86_64/dynamic_function_dispatch.cpp b/libc/arch-x86_64/ifuncs.cpp
similarity index 78%
rename from libc/arch-x86_64/dynamic_function_dispatch.cpp
rename to libc/arch-x86_64/ifuncs.cpp
index cbe68a3..a654a25 100644
--- a/libc/arch-x86_64/dynamic_function_dispatch.cpp
+++ b/libc/arch-x86_64/ifuncs.cpp
@@ -32,6 +32,25 @@
 
 extern "C" {
 
+DEFINE_IFUNC_FOR(memmove) {
+  __builtin_cpu_init();
+  if (__builtin_cpu_supports("avx2")) RETURN_FUNC(memmove_func_t, memmove_avx2);
+  RETURN_FUNC(memmove_func_t, memmove_generic);
+}
+MEMMOVE_SHIM()
+
+DEFINE_IFUNC_FOR(memcpy) {
+  return memmove_resolver();
+}
+MEMCPY_SHIM()
+
+DEFINE_IFUNC_FOR(__memcpy_chk) {
+  __builtin_cpu_init();
+  if (__builtin_cpu_supports("avx2")) RETURN_FUNC(__memcpy_chk_func_t, __memcpy_chk_avx2);
+  RETURN_FUNC(__memcpy_chk_func_t, __memcpy_chk_generic);
+}
+__MEMCPY_CHK_SHIM()
+
 DEFINE_IFUNC_FOR(memset) {
   __builtin_cpu_init();
   if (__builtin_cpu_supports("avx2")) RETURN_FUNC(memset_func_t, memset_avx2);
diff --git a/libc/arch-x86_64/string/avx2-memmove-kbl.S b/libc/arch-x86_64/string/avx2-memmove-kbl.S
new file mode 100644
index 0000000..fc5758b
--- /dev/null
+++ b/libc/arch-x86_64/string/avx2-memmove-kbl.S
@@ -0,0 +1,620 @@
+/*
+Copyright (c) 2024, Intel Corporation
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice,
+    * this list of conditions and the following disclaimer.
+
+    * Redistributions in binary form must reproduce the above copyright notice,
+    * this list of conditions and the following disclaimer in the documentation
+    * and/or other materials provided with the distribution.
+
+    * Neither the name of Intel Corporation nor the names of its contributors
+    * may be used to endorse or promote products derived from this software
+    * without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+
+#ifndef MEMMOVE
+# define MEMMOVE		memmove_avx2
+#endif
+
+#ifndef L
+# define L(label)	.L##label
+#endif
+
+#ifndef cfi_startproc
+# define cfi_startproc	.cfi_startproc
+#endif
+
+#ifndef cfi_endproc
+# define cfi_endproc	.cfi_endproc
+#endif
+
+#ifndef cfi_rel_offset
+# define cfi_rel_offset(reg, off)	.cfi_rel_offset reg, off
+#endif
+
+#ifndef cfi_restore
+# define cfi_restore(reg)	.cfi_restore reg
+#endif
+
+#ifndef cfi_adjust_cfa_offset
+# define cfi_adjust_cfa_offset(off)	.cfi_adjust_cfa_offset off
+#endif
+
+#ifndef ENTRY
+# define ENTRY(name)		\
+	.type name,  @function;		\
+	.globl name;		\
+	.p2align 4;		\
+name:		\
+	cfi_startproc
+#endif
+
+#ifndef ALIAS_SYMBOL
+# define ALIAS_SYMBOL(alias, original) \
+	.globl alias; \
+	.equ alias, original
+#endif
+
+#ifndef END
+# define END(name)		\
+	cfi_endproc;		\
+	.size name, .-name
+#endif
+
+#define CFI_PUSH(REG)		\
+	cfi_adjust_cfa_offset (8);		\
+	cfi_rel_offset (REG, 0)
+
+#define CFI_POP(REG)		\
+	cfi_adjust_cfa_offset (-8);		\
+	cfi_restore (REG)
+
+#define PUSH(REG)	push REG;
+#define POP(REG)	pop REG;
+
+#define ENTRANCE	\
+	PUSH(%rbx);		\
+	CFI_PUSH (%rbx);
+#define RETURN_END	\
+	POP(%rbx);		\
+	CFI_POP (%rbx);	\
+	ret
+#define RETURN		RETURN_END;
+
+	.section .text.avx2,"ax",@progbits
+ENTRY (__memcpy_chk_avx2)
+	cmp	%rcx, %rdx
+	ja	__memcpy_chk_fail
+/* Fall through to memcpy/memmove. */
+END (__memcpy_chk_avx2)
+
+ENTRY (MEMMOVE)
+	ENTRANCE
+	mov	%rdi, %rax
+
+/* Check whether we should copy backward or forward.  */
+	cmp	%rsi, %rdi
+	je	L(mm_return)
+	jg	L(mm_len_0_or_more_backward)
+
+/* Now do checks for lengths. We do [0..16], [0..32], [0..64], [0..128]
+	separately.  */
+	cmp	$16, %rdx
+	jbe	L(mm_len_0_16_bytes_forward)
+
+	cmp	$32, %rdx
+	ja	L(mm_len_32_or_more_forward)
+
+/* Copy [0..32] and return.  */
+	movdqu	(%rsi), %xmm0
+	movdqu	-16(%rsi, %rdx), %xmm1
+	movdqu	%xmm0, (%rdi)
+	movdqu	%xmm1, -16(%rdi, %rdx)
+	jmp	L(mm_return)
+
+L(mm_len_32_or_more_forward):
+	cmp	$64, %rdx
+	ja	L(mm_len_64_or_more_forward)
+
+/* Copy [0..64] and return.  */
+	movdqu	(%rsi), %xmm0
+	movdqu	16(%rsi), %xmm1
+	movdqu	-16(%rsi, %rdx), %xmm2
+	movdqu	-32(%rsi, %rdx), %xmm3
+	movdqu	%xmm0, (%rdi)
+	movdqu	%xmm1, 16(%rdi)
+	movdqu	%xmm2, -16(%rdi, %rdx)
+	movdqu	%xmm3, -32(%rdi, %rdx)
+	jmp	L(mm_return)
+
+L(mm_len_64_or_more_forward):
+	cmp	$128, %rdx
+	ja	L(mm_len_128_or_more_forward)
+
+/* Copy [0..128] and return.  */
+	movdqu	(%rsi), %xmm0
+	movdqu	16(%rsi), %xmm1
+	movdqu	32(%rsi), %xmm2
+	movdqu	48(%rsi), %xmm3
+	movdqu	-64(%rsi, %rdx), %xmm4
+	movdqu	-48(%rsi, %rdx), %xmm5
+	movdqu	-32(%rsi, %rdx), %xmm6
+	movdqu	-16(%rsi, %rdx), %xmm7
+	movdqu	%xmm0, (%rdi)
+	movdqu	%xmm1, 16(%rdi)
+	movdqu	%xmm2, 32(%rdi)
+	movdqu	%xmm3, 48(%rdi)
+	movdqu	%xmm4, -64(%rdi, %rdx)
+	movdqu	%xmm5, -48(%rdi, %rdx)
+	movdqu	%xmm6, -32(%rdi, %rdx)
+	movdqu	%xmm7, -16(%rdi, %rdx)
+	jmp	L(mm_return)
+
+L(mm_len_128_or_more_forward):
+	cmp	$256, %rdx
+	ja	L(mm_len_256_or_more_forward)
+
+/* Copy [0..256] and return.  */
+	movdqu	(%rsi), %xmm0
+	movdqu	16(%rsi), %xmm1
+	movdqu	32(%rsi), %xmm2
+	movdqu	48(%rsi), %xmm3
+	movdqu	64(%rsi), %xmm4
+	movdqu	80(%rsi), %xmm5
+	movdqu	96(%rsi), %xmm6
+	movdqu	112(%rsi), %xmm7
+	movdqu	-128(%rsi, %rdx), %xmm8
+	movdqu	-112(%rsi, %rdx), %xmm9
+	movdqu	-96(%rsi, %rdx), %xmm10
+	movdqu	-80(%rsi, %rdx), %xmm11
+	movdqu	-64(%rsi, %rdx), %xmm12
+	movdqu	-48(%rsi, %rdx), %xmm13
+	movdqu	-32(%rsi, %rdx), %xmm14
+	movdqu	-16(%rsi, %rdx), %xmm15
+	movdqu	%xmm0, (%rdi)
+	movdqu	%xmm1, 16(%rdi)
+	movdqu	%xmm2, 32(%rdi)
+	movdqu	%xmm3, 48(%rdi)
+	movdqu	%xmm4, 64(%rdi)
+	movdqu	%xmm5, 80(%rdi)
+	movdqu	%xmm6, 96(%rdi)
+	movdqu	%xmm7, 112(%rdi)
+	movdqu	%xmm8, -128(%rdi, %rdx)
+	movdqu	%xmm9, -112(%rdi, %rdx)
+	movdqu	%xmm10, -96(%rdi, %rdx)
+	movdqu	%xmm11, -80(%rdi, %rdx)
+	movdqu	%xmm12, -64(%rdi, %rdx)
+	movdqu	%xmm13, -48(%rdi, %rdx)
+	movdqu	%xmm14, -32(%rdi, %rdx)
+	movdqu	%xmm15, -16(%rdi, %rdx)
+	jmp	L(mm_return)
+
+L(mm_len_256_or_more_forward):
+/* Aligning the address of destination.  */
+/*  save first unaligned 128 bytes */
+	vmovdqu	(%rsi), %ymm0
+	vmovdqu	32(%rsi), %ymm1
+	vmovdqu	64(%rsi), %ymm2
+	vmovdqu	96(%rsi), %ymm3
+
+	lea	128(%rdi), %r8
+	and	$-128, %r8  /* r8 now aligned to next 128 byte boundary */
+	sub	%rdi, %rsi  /* rsi = src - dst = diff */
+
+	vmovdqu	(%r8, %rsi), %ymm4
+	vmovdqu	32(%r8, %rsi), %ymm5
+	vmovdqu	64(%r8, %rsi), %ymm6
+	vmovdqu	96(%r8, %rsi), %ymm7
+
+	vmovdqu	%ymm0, (%rdi)
+	vmovdqu	%ymm1, 32(%rdi)
+	vmovdqu	%ymm2, 64(%rdi)
+	vmovdqu	%ymm3, 96(%rdi)
+	vmovdqa	%ymm4, (%r8)
+	vmovaps	%ymm5, 32(%r8)
+	vmovaps	%ymm6, 64(%r8)
+	vmovaps	%ymm7, 96(%r8)
+	add	$128, %r8
+
+	lea	(%rdi, %rdx), %rbx
+	and	$-128, %rbx
+	cmp	%r8, %rbx
+	jbe	L(mm_copy_remaining_forward)
+
+	cmp	__x86_shared_cache_size_half(%rip), %rdx
+	jae	L(mm_overlapping_check_forward)
+
+		.p2align 4
+L(mm_main_loop_forward):
+	prefetcht0	128(%r8, %rsi)
+	vmovdqu	(%r8, %rsi), %ymm0
+	vmovdqu	32(%r8, %rsi), %ymm1
+	vmovdqa	%ymm0, (%r8)
+	vmovaps	%ymm1, 32(%r8)
+	lea	64(%r8), %r8
+	cmp	%r8, %rbx
+	ja	L(mm_main_loop_forward)
+
+L(mm_copy_remaining_forward):
+	add	%rdi, %rdx
+	sub	%r8, %rdx
+/* We copied all up till %rdi position in the dst.
+	In %rdx now is how many bytes are left to copy.
+	Now we need to advance %r8. */
+	lea	(%r8, %rsi), %r9
+
+L(mm_remaining_0_128_bytes_forward):
+	cmp	$64, %rdx
+	ja	L(mm_remaining_65_128_bytes_forward)
+	cmp	$32, %rdx
+	ja	L(mm_remaining_33_64_bytes_forward)
+	vzeroupper
+	cmp	$16, %rdx
+	ja	L(mm_remaining_17_32_bytes_forward)
+	test	%rdx, %rdx
+	.p2align 4,,2
+	je	L(mm_return)
+
+	cmpb	$8, %dl
+	ja	L(mm_remaining_9_16_bytes_forward)
+	cmpb	$4, %dl
+	.p2align 4,,5
+	ja	L(mm_remaining_5_8_bytes_forward)
+	cmpb	$2, %dl
+	.p2align 4,,1
+	ja	L(mm_remaining_3_4_bytes_forward)
+	movzbl	-1(%r9,%rdx), %esi
+	movzbl	(%r9), %ebx
+	movb	%sil, -1(%r8,%rdx)
+	movb	%bl, (%r8)
+	jmp	L(mm_return)
+
+L(mm_remaining_65_128_bytes_forward):
+	vmovdqu (%r9), %ymm0
+	vmovdqu 32(%r9), %ymm1
+	vmovdqu -64(%r9, %rdx), %ymm2
+	vmovdqu -32(%r9, %rdx), %ymm3
+	vmovdqu %ymm0, (%r8)
+	vmovdqu %ymm1, 32(%r8)
+	vmovdqu %ymm2, -64(%r8, %rdx)
+	vmovdqu %ymm3, -32(%r8, %rdx)
+	jmp L(mm_return_vzeroupper)
+
+L(mm_remaining_33_64_bytes_forward):
+	vmovdqu (%r9), %ymm0
+	vmovdqu -32(%r9, %rdx), %ymm1
+	vmovdqu %ymm0, (%r8)
+	vmovdqu %ymm1, -32(%r8, %rdx)
+	jmp	L(mm_return_vzeroupper)
+
+L(mm_remaining_17_32_bytes_forward):
+	movdqu	(%r9), %xmm0
+	movdqu	-16(%r9, %rdx), %xmm1
+	movdqu	%xmm0, (%r8)
+	movdqu	%xmm1, -16(%r8, %rdx)
+	jmp	L(mm_return)
+
+L(mm_remaining_5_8_bytes_forward):
+	movl	(%r9), %esi
+	movl	-4(%r9,%rdx), %ebx
+	movl	%esi, (%r8)
+	movl	%ebx, -4(%r8,%rdx)
+	jmp	L(mm_return)
+
+L(mm_remaining_9_16_bytes_forward):
+	mov	(%r9), %rsi
+	mov	-8(%r9, %rdx), %rbx
+	mov	%rsi, (%r8)
+	mov	%rbx, -8(%r8, %rdx)
+	jmp	L(mm_return)
+
+L(mm_remaining_3_4_bytes_forward):
+	movzwl	-2(%r9,%rdx), %esi
+	movzwl	(%r9), %ebx
+	movw	%si, -2(%r8,%rdx)
+	movw	%bx, (%r8)
+	jmp	L(mm_return)
+
+L(mm_len_0_16_bytes_forward):
+	testb	$24, %dl
+	jne	L(mm_len_9_16_bytes_forward)
+	testb	$4, %dl
+	.p2align 4,,5
+	jne	L(mm_len_5_8_bytes_forward)
+	test	%rdx, %rdx
+	.p2align 4,,2
+	je	L(mm_return)
+	testb	$2, %dl
+	.p2align 4,,1
+	jne	L(mm_len_2_4_bytes_forward)
+	movzbl	-1(%rsi,%rdx), %ebx
+	movzbl	(%rsi), %esi
+	movb	%bl, -1(%rdi,%rdx)
+	movb	%sil, (%rdi)
+	jmp	L(mm_return)
+
+L(mm_len_2_4_bytes_forward):
+	movzwl	-2(%rsi,%rdx), %ebx
+	movzwl	(%rsi), %esi
+	movw	%bx, -2(%rdi,%rdx)
+	movw	%si, (%rdi)
+	jmp	L(mm_return)
+
+L(mm_len_5_8_bytes_forward):
+	movl	(%rsi), %ebx
+	movl	-4(%rsi,%rdx), %esi
+	movl	%ebx, (%rdi)
+	movl	%esi, -4(%rdi,%rdx)
+	jmp	L(mm_return)
+
+L(mm_len_9_16_bytes_forward):
+	mov	(%rsi), %rbx
+	mov	-8(%rsi, %rdx), %rsi
+	mov	%rbx, (%rdi)
+	mov	%rsi, -8(%rdi, %rdx)
+	jmp	L(mm_return)
+
+L(mm_recalc_len):
+/* Compute in %rdx how many bytes are left to copy after
+	the main loop stops.  */
+	vzeroupper
+	mov 	%rbx, %rdx
+	sub 	%rdi, %rdx
+/* The code for copying backwards.  */
+L(mm_len_0_or_more_backward):
+
+/* Now do checks for lengths. We do [0..16], [16..32], [32..64], [64..128]
+	separately.  */
+	cmp	$16, %rdx
+	jbe	L(mm_len_0_16_bytes_backward)
+
+	cmp	$32, %rdx
+	ja	L(mm_len_32_or_more_backward)
+
+/* Copy [0..32] and return.  */
+	movdqu	(%rsi), %xmm0
+	movdqu	-16(%rsi, %rdx), %xmm1
+	movdqu	%xmm0, (%rdi)
+	movdqu	%xmm1, -16(%rdi, %rdx)
+	jmp	L(mm_return)
+
+L(mm_len_32_or_more_backward):
+	cmp	$64, %rdx
+	ja	L(mm_len_64_or_more_backward)
+
+/* Copy [0..64] and return.  */
+	movdqu	(%rsi), %xmm0
+	movdqu	16(%rsi), %xmm1
+	movdqu	-16(%rsi, %rdx), %xmm2
+	movdqu	-32(%rsi, %rdx), %xmm3
+	movdqu	%xmm0, (%rdi)
+	movdqu	%xmm1, 16(%rdi)
+	movdqu	%xmm2, -16(%rdi, %rdx)
+	movdqu	%xmm3, -32(%rdi, %rdx)
+	jmp	L(mm_return)
+
+L(mm_len_64_or_more_backward):
+	cmp	$128, %rdx
+	ja	L(mm_len_128_or_more_backward)
+
+/* Copy [0..128] and return.  */
+	movdqu	(%rsi), %xmm0
+	movdqu	16(%rsi), %xmm1
+	movdqu	32(%rsi), %xmm2
+	movdqu	48(%rsi), %xmm3
+	movdqu	-64(%rsi, %rdx), %xmm4
+	movdqu	-48(%rsi, %rdx), %xmm5
+	movdqu	-32(%rsi, %rdx), %xmm6
+	movdqu	-16(%rsi, %rdx), %xmm7
+	movdqu	%xmm0, (%rdi)
+	movdqu	%xmm1, 16(%rdi)
+	movdqu	%xmm2, 32(%rdi)
+	movdqu	%xmm3, 48(%rdi)
+	movdqu	%xmm4, -64(%rdi, %rdx)
+	movdqu	%xmm5, -48(%rdi, %rdx)
+	movdqu	%xmm6, -32(%rdi, %rdx)
+	movdqu	%xmm7, -16(%rdi, %rdx)
+	jmp	L(mm_return)
+
+L(mm_len_128_or_more_backward):
+	cmp	$256, %rdx
+	ja	L(mm_len_256_or_more_backward)
+
+/* Copy [0..256] and return.  */
+	movdqu	(%rsi), %xmm0
+	movdqu	16(%rsi), %xmm1
+	movdqu	32(%rsi), %xmm2
+	movdqu	48(%rsi), %xmm3
+	movdqu	64(%rsi), %xmm4
+	movdqu	80(%rsi), %xmm5
+	movdqu	96(%rsi), %xmm6
+	movdqu	112(%rsi), %xmm7
+	movdqu	-128(%rsi, %rdx), %xmm8
+	movdqu	-112(%rsi, %rdx), %xmm9
+	movdqu	-96(%rsi, %rdx), %xmm10
+	movdqu	-80(%rsi, %rdx), %xmm11
+	movdqu	-64(%rsi, %rdx), %xmm12
+	movdqu	-48(%rsi, %rdx), %xmm13
+	movdqu	-32(%rsi, %rdx), %xmm14
+	movdqu	-16(%rsi, %rdx), %xmm15
+	movdqu	%xmm0, (%rdi)
+	movdqu	%xmm1, 16(%rdi)
+	movdqu	%xmm2, 32(%rdi)
+	movdqu	%xmm3, 48(%rdi)
+	movdqu	%xmm4, 64(%rdi)
+	movdqu	%xmm5, 80(%rdi)
+	movdqu	%xmm6, 96(%rdi)
+	movdqu	%xmm7, 112(%rdi)
+	movdqu	%xmm8, -128(%rdi, %rdx)
+	movdqu	%xmm9, -112(%rdi, %rdx)
+	movdqu	%xmm10, -96(%rdi, %rdx)
+	movdqu	%xmm11, -80(%rdi, %rdx)
+	movdqu	%xmm12, -64(%rdi, %rdx)
+	movdqu	%xmm13, -48(%rdi, %rdx)
+	movdqu	%xmm14, -32(%rdi, %rdx)
+	movdqu	%xmm15, -16(%rdi, %rdx)
+	jmp	L(mm_return)
+
+L(mm_len_256_or_more_backward):
+/* Aligning the address of destination. We need to save
+	128 bytes from the source in order not to overwrite them.  */
+	vmovdqu	-32(%rsi, %rdx), %ymm0
+	vmovdqu	-64(%rsi, %rdx), %ymm1
+	vmovdqu	-96(%rsi, %rdx), %ymm2
+	vmovdqu	-128(%rsi, %rdx), %ymm3
+
+	lea	(%rdi, %rdx), %r9
+	and	$-128, %r9 /* r9 = aligned dst */
+
+	mov	%rsi, %r8
+	sub	%rdi, %r8 /* r8 = src - dst, diff */
+
+	vmovdqu	-32(%r9, %r8), %ymm4
+	vmovdqu	-64(%r9, %r8), %ymm5
+	vmovdqu	-96(%r9, %r8), %ymm6
+	vmovdqu	-128(%r9, %r8), %ymm7
+
+	vmovdqu	%ymm0, -32(%rdi, %rdx)
+	vmovdqu	%ymm1, -64(%rdi, %rdx)
+	vmovdqu	%ymm2, -96(%rdi, %rdx)
+	vmovdqu	%ymm3, -128(%rdi, %rdx)
+	vmovdqa	%ymm4, -32(%r9)
+	vmovdqa	%ymm5, -64(%r9)
+	vmovdqa	%ymm6, -96(%r9)
+	vmovdqa	%ymm7, -128(%r9)
+	lea	-128(%r9), %r9
+
+	lea	128(%rdi), %rbx
+	and	$-128, %rbx
+
+	cmp	%r9, %rbx
+	jae	L(mm_recalc_len)
+
+	cmp	__x86_shared_cache_size_half(%rip), %rdx
+	jae	L(mm_overlapping_check_backward)
+
+	.p2align 4
+L(mm_main_loop_backward):
+	prefetcht0 -128(%r9, %r8)
+
+	vmovdqu	-64(%r9, %r8), %ymm0
+	vmovdqu	-32(%r9, %r8), %ymm1
+	vmovdqa	%ymm0, -64(%r9)
+	vmovaps	%ymm1, -32(%r9)
+	lea	-64(%r9), %r9
+	cmp	%r9, %rbx
+	jb	L(mm_main_loop_backward)
+	jmp	L(mm_recalc_len)
+
+/* Copy [0..16] and return.  */
+L(mm_len_0_16_bytes_backward):
+	testb	$24, %dl
+	jnz	L(mm_len_9_16_bytes_backward)
+	testb	$4, %dl
+	.p2align 4,,5
+	jnz	L(mm_len_5_8_bytes_backward)
+	test	%rdx, %rdx
+	.p2align 4,,2
+	je	L(mm_return)
+	testb	$2, %dl
+	.p2align 4,,1
+	jne	L(mm_len_3_4_bytes_backward)
+	movzbl	-1(%rsi,%rdx), %ebx
+	movzbl	(%rsi), %ecx
+	movb	%bl, -1(%rdi,%rdx)
+	movb	%cl, (%rdi)
+	jmp	L(mm_return)
+
+L(mm_len_3_4_bytes_backward):
+	movzwl	-2(%rsi,%rdx), %ebx
+	movzwl	(%rsi), %ecx
+	movw	%bx, -2(%rdi,%rdx)
+	movw	%cx, (%rdi)
+	jmp	L(mm_return)
+
+L(mm_len_9_16_bytes_backward):
+	movl	-4(%rsi,%rdx), %ebx
+	movl	-8(%rsi,%rdx), %ecx
+	movl	%ebx, -4(%rdi,%rdx)
+	movl	%ecx, -8(%rdi,%rdx)
+	sub	$8, %rdx
+	jmp	L(mm_len_0_16_bytes_backward)
+
+L(mm_len_5_8_bytes_backward):
+	movl	(%rsi), %ebx
+	movl	-4(%rsi,%rdx), %ecx
+	movl	%ebx, (%rdi)
+	movl	%ecx, -4(%rdi,%rdx)
+
+L(mm_return):
+	RETURN
+
+L(mm_return_vzeroupper):
+	vzeroupper
+	RETURN
+
+/* Big length copy forward part.  */
+
+	.p2align 4
+
+L(mm_overlapping_check_forward):
+	mov	%rsi, %r9
+	add	%rdx, %r9
+	cmp	__x86_shared_cache_size(%rip), %r9
+	jbe	L(mm_main_loop_forward)
+
+L(mm_large_page_loop_forward):
+	vmovdqu	  (%r8, %rsi), %ymm0
+	vmovdqu	  32(%r8, %rsi), %ymm1
+	vmovdqu	  64(%r8, %rsi), %ymm2
+	vmovdqu	  96(%r8, %rsi), %ymm3
+	vmovntdq  %ymm0, (%r8)
+	vmovntdq  %ymm1, 32(%r8)
+	vmovntdq  %ymm2, 64(%r8)
+	vmovntdq  %ymm3, 96(%r8)
+	lea 	  128(%r8), %r8
+	cmp	  %r8, %rbx
+	ja	  L(mm_large_page_loop_forward)
+	sfence
+	jmp	  L(mm_copy_remaining_forward)
+
+/* Big length copy backward part.  */
+	.p2align 4
+
+L(mm_overlapping_check_backward):
+	mov	%rdi, %r11
+	sub	%rsi, %r11 /* r11 = dst - src, diff */
+	add	%rdx, %r11
+	cmp	__x86_shared_cache_size(%rip), %r11
+	jbe	L(mm_main_loop_backward)
+
+L(mm_large_page_loop_backward):
+	vmovdqu	  -64(%r9, %r8), %ymm0
+	vmovdqu	  -32(%r9, %r8), %ymm1
+	vmovntdq  %ymm0, -64(%r9)
+	vmovntdq  %ymm1, -32(%r9)
+	lea 	  -64(%r9), %r9
+	cmp	  %r9, %rbx
+	jb	  L(mm_large_page_loop_backward)
+	sfence
+	jmp	  L(mm_recalc_len)
+
+END (MEMMOVE)
+
diff --git a/libc/arch-x86_64/string/sse2-memmove-slm.S b/libc/arch-x86_64/string/sse2-memmove-slm.S
index 9f5fb12..75f8b93 100644
--- a/libc/arch-x86_64/string/sse2-memmove-slm.S
+++ b/libc/arch-x86_64/string/sse2-memmove-slm.S
@@ -30,7 +30,7 @@
 
 
 #ifndef MEMMOVE
-# define MEMMOVE		memmove
+# define MEMMOVE		memmove_generic
 #endif
 
 #ifndef L
@@ -99,11 +99,11 @@
 #define RETURN		RETURN_END;
 
 	.section .text.sse2,"ax",@progbits
-ENTRY (__memcpy_chk)
+ENTRY (__memcpy_chk_generic)
 	cmp	%rcx, %rdx
 	ja	__memcpy_chk_fail
 /* Fall through to memcpy/memmove. */
-END (__memcpy_chk)
+END (__memcpy_chk_generic)
 ENTRY (MEMMOVE)
 	ENTRANCE
 	mov	%rdi, %rax
@@ -541,4 +541,7 @@
 
 END (MEMMOVE)
 
+#ifdef BIONIC_RUST_BAREMETAL
 ALIAS_SYMBOL(memcpy, MEMMOVE)
+#endif
+
diff --git a/libc/async_safe/Android.bp b/libc/async_safe/Android.bp
index c7de2ce..7c8e4f5 100644
--- a/libc/async_safe/Android.bp
+++ b/libc/async_safe/Android.bp
@@ -8,15 +8,16 @@
     // to get the below license kinds:
     //   SPDX-license-identifier-BSD
     default_applicable_licenses: ["bionic_libc_license"],
+    default_team: "trendy_team_native_tools_libraries",
 }
 
 cc_library_static {
+    name: "libasync_safe",
     defaults: ["libc_defaults"],
     srcs: [
         "async_safe_log.cpp",
     ],
 
-    name: "libasync_safe",
     vendor_available: true,
     product_available: true,
     recovery_available: true,
diff --git a/libc/async_safe/async_safe_log.cpp b/libc/async_safe/async_safe_log.cpp
index 07133b7..26ee30b 100644
--- a/libc/async_safe/async_safe_log.cpp
+++ b/libc/async_safe/async_safe_log.cpp
@@ -50,12 +50,14 @@
 
 #include "private/ErrnoRestorer.h"
 
-// Don't call libc's close or socket, since it might call back into us as a result of fdsan/fdtrack.
-#pragma GCC poison close
+// Don't call libc's close(), since it might call back into us as a result of fdsan/fdtrack.
+#pragma clang poison close
 static int __close(int fd) {
   return syscall(__NR_close, fd);
 }
 
+// Don't call libc's socket(), since it might call back into us as a result of fdsan/fdtrack.
+#pragma clang poison socket
 static int __socket(int domain, int type, int protocol) {
 #if defined(__i386__)
   unsigned long args[3] = {static_cast<unsigned long>(domain), static_cast<unsigned long>(type),
diff --git a/libc/bionic/__libc_init_main_thread.cpp b/libc/bionic/__libc_init_main_thread.cpp
index 0d557f1..2824340 100644
--- a/libc/bionic/__libc_init_main_thread.cpp
+++ b/libc/bionic/__libc_init_main_thread.cpp
@@ -82,6 +82,7 @@
   main_thread.tid = __getpid();
   main_thread.set_cached_pid(main_thread.tid);
   main_thread.stack_top = reinterpret_cast<uintptr_t>(args.argv);
+  main_thread.stack_bottom = 0;
 }
 
 // This code is used both by each new pthread and the code that initializes the main thread.
@@ -156,12 +157,14 @@
   const StaticTlsLayout& layout = __libc_shared_globals()->static_tls_layout;
   auto new_tcb = reinterpret_cast<bionic_tcb*>(mapping.static_tls + layout.offset_bionic_tcb());
   auto new_tls = reinterpret_cast<bionic_tls*>(mapping.static_tls + layout.offset_bionic_tls());
+  auto new_lb = reinterpret_cast<libgen_buffers*>(mapping.libgen_buffers);
 
   __init_static_tls(mapping.static_tls);
   new_tcb->copy_from_bootstrap(temp_tcb);
   new_tls->copy_from_bootstrap(temp_tls);
   __init_tcb(new_tcb, &main_thread);
   __init_bionic_tls_ptrs(new_tcb, new_tls);
+  __init_libgen_buffers_ptr(new_tls, new_lb);
 
   main_thread.mmap_base = mapping.mmap_base;
   main_thread.mmap_size = mapping.mmap_size;
diff --git a/libc/bionic/wmempcpy.cpp b/libc/bionic/__progname.cpp
similarity index 70%
copy from libc/bionic/wmempcpy.cpp
copy to libc/bionic/__progname.cpp
index 54ebf86..92279c4 100644
--- a/libc/bionic/wmempcpy.cpp
+++ b/libc/bionic/__progname.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015 The Android Open Source Project
+ * Copyright (C) 2025 The Android Open Source Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -26,8 +26,22 @@
  * SUCH DAMAGE.
  */
 
-#include <wchar.h>
+#include <stdlib.h>
+#include <string.h>
 
-wchar_t* wmempcpy(wchar_t* dst, const wchar_t* src, size_t n) {
-  return wmemcpy(dst, src, n) + n;
+#include "private/bionic_defs.h"
+
+// Not exported in a public header file, but accessible via `extern`,
+// and well-known in the BSDs (though they also only publicly export
+// the functional interface these days).
+__BIONIC_WEAK_VARIABLE_FOR_NATIVE_BRIDGE
+const char* __progname;
+
+const char* getprogname() {
+  return __progname;
+}
+
+void setprogname(const char* name) {
+  const char* last_slash = strrchr(name, '/');
+  __progname = (last_slash != nullptr) ? last_slash + 1 : name;
 }
diff --git a/libc/bionic/android_unsafe_frame_pointer_chase.cpp b/libc/bionic/android_unsafe_frame_pointer_chase.cpp
index 7d5cd6c..44ca0b3 100644
--- a/libc/bionic/android_unsafe_frame_pointer_chase.cpp
+++ b/libc/bionic/android_unsafe_frame_pointer_chase.cpp
@@ -38,6 +38,11 @@
   return __get_thread()->stack_top;
 }
 
+__BIONIC_WEAK_FOR_NATIVE_BRIDGE
+extern "C" __LIBC_HIDDEN__ uintptr_t __get_thread_stack_bottom() {
+  return __get_thread()->stack_bottom;
+}
+
 /*
  * Implement fast stack unwinding for stack frames with frame pointers. Stores at most num_entries
  * return addresses to buffer buf. Returns the number of available return addresses, which may be
@@ -62,12 +67,22 @@
     uintptr_t next_frame, return_addr;
   };
 
-  auto begin = reinterpret_cast<uintptr_t>(__builtin_frame_address(0));
-  auto end = __get_thread_stack_top();
+  static uintptr_t main_thread_bottom = UINTPTR_MAX;
 
-  stack_t ss;
-  if (sigaltstack(nullptr, &ss) == 0 && (ss.ss_flags & SS_ONSTACK)) {
-    end = reinterpret_cast<uintptr_t>(ss.ss_sp) + ss.ss_size;
+  auto bottom = __get_thread_stack_bottom();
+  if (bottom == 0) {
+    bottom = main_thread_bottom;
+  }
+  auto fp = reinterpret_cast<uintptr_t>(__builtin_frame_address(0));
+  auto top = __get_thread_stack_top();
+
+  if (fp < bottom || fp > top) {
+    stack_t ss;
+    if (sigaltstack(nullptr, &ss) == 0 && (ss.ss_flags & SS_ONSTACK)) {
+      top = reinterpret_cast<uintptr_t>(ss.ss_sp) + ss.ss_size;
+    } else if (__get_thread_stack_bottom() == 0) {
+      main_thread_bottom = MIN(main_thread_bottom, fp);
+    }
   }
 
   size_t num_frames = 0;
@@ -77,9 +92,9 @@
     // See https://reviews.llvm.org/D87579. We did at least manage to get this
     // documented in the RISC-V psABI though:
     // https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/master/riscv-cc.adoc#frame-pointer-convention
-    auto* frame = reinterpret_cast<frame_record*>(begin - 16);
+    auto* frame = reinterpret_cast<frame_record*>(fp - 16);
 #else
-    auto* frame = reinterpret_cast<frame_record*>(begin);
+    auto* frame = reinterpret_cast<frame_record*>(fp);
 #endif
     if (num_frames < num_entries) {
       uintptr_t addr = __bionic_clear_pac_bits(frame->return_addr);
@@ -89,11 +104,11 @@
       buf[num_frames] = addr;
     }
     ++num_frames;
-    if (frame->next_frame < begin + sizeof(frame_record) || frame->next_frame >= end ||
+    if (frame->next_frame < fp + sizeof(frame_record) || frame->next_frame >= top ||
         frame->next_frame % sizeof(void*) != 0) {
       break;
     }
-    begin = frame->next_frame;
+    fp = frame->next_frame;
   }
 
   return num_frames;
diff --git a/libc/bionic/arpa_inet.cpp b/libc/bionic/arpa_inet.cpp
index 9d4afe3..f8e2d46 100644
--- a/libc/bionic/arpa_inet.cpp
+++ b/libc/bionic/arpa_inet.cpp
@@ -35,12 +35,12 @@
 int inet_aton(const char* cp, in_addr* addr) {
   ErrnoRestorer errno_restorer;
 
-  unsigned long parts[4];
+  unsigned long long parts[4];
   size_t i;
   for (i = 0; i < 4; ++i) {
     char* end;
     errno = 0;
-    parts[i] = strtoul(cp, &end, 0);
+    parts[i] = strtoull(cp, &end, 0);
     if (errno != 0 || end == cp || (*end != '.' && *end != '\0')) return 0;
     if (*end == '\0') break;
     cp = end + 1;
diff --git a/libc/bionic/bionic_allocator.cpp b/libc/bionic/bionic_allocator.cpp
index 41baf8b..c0c5d13 100644
--- a/libc/bionic/bionic_allocator.cpp
+++ b/libc/bionic/bionic_allocator.cpp
@@ -28,6 +28,7 @@
 
 #include "private/bionic_allocator.h"
 
+#include <stdbit.h>
 #include <stdlib.h>
 #include <string.h>
 #include <sys/mman.h>
@@ -41,7 +42,6 @@
 #include <async_safe/CHECK.h>
 
 #include "platform/bionic/page.h"
-#include "platform/bionic/macros.h"
 
 //
 // BionicAllocator is a general purpose allocator designed to provide the same
@@ -81,7 +81,7 @@
 
 // Allocated pointers must be at least 16-byte aligned.  Round up the size of
 // page_info to multiple of 16.
-static constexpr size_t kPageInfoSize = __BIONIC_ALIGN(sizeof(page_info), 16);
+static constexpr size_t kPageInfoSize = __builtin_align_up(sizeof(page_info), 16);
 
 static inline uint16_t log2(size_t number) {
   uint16_t result = 0;
@@ -207,7 +207,7 @@
 
   // Align the first block to block_size_.
   const uintptr_t first_block_addr =
-      __BIONIC_ALIGN(reinterpret_cast<uintptr_t>(page + 1), block_size_);
+      __builtin_align_up(reinterpret_cast<uintptr_t>(page + 1), block_size_);
   small_object_block_record* const first_block =
       reinterpret_cast<small_object_block_record*>(first_block_addr);
 
@@ -262,7 +262,7 @@
 }
 
 void* BionicAllocator::alloc_mmap(size_t align, size_t size) {
-  size_t header_size = __BIONIC_ALIGN(kPageInfoSize, align);
+  size_t header_size = __builtin_align_up(kPageInfoSize, align);
   size_t allocated_size;
   if (__builtin_add_overflow(header_size, size, &allocated_size) ||
       page_end(allocated_size) < allocated_size) {
@@ -315,9 +315,7 @@
   // enough for ELF TLS.
   align = MIN(align, page_size());
   align = MAX(align, 16);
-  if (!powerof2(align)) {
-    align = BIONIC_ROUND_UP_POWER_OF_2(align);
-  }
+  align = stdc_bit_ceil(align);
   size = MAX(size, align);
   return alloc_impl(align, size);
 }
diff --git a/libc/bionic/bionic_call_ifunc_resolver.cpp b/libc/bionic/bionic_call_ifunc_resolver.cpp
index d5a812c..532f9b8 100644
--- a/libc/bionic/bionic_call_ifunc_resolver.cpp
+++ b/libc/bionic/bionic_call_ifunc_resolver.cpp
@@ -48,8 +48,11 @@
     arg._size = sizeof(__ifunc_arg_t);
     arg._hwcap = getauxval(AT_HWCAP);
     arg._hwcap2 = getauxval(AT_HWCAP2);
+    arg._hwcap3 = getauxval(AT_HWCAP3);
+    arg._hwcap4 = getauxval(AT_HWCAP4);
   }
-  return reinterpret_cast<ifunc_resolver_t>(resolver_addr)(arg._hwcap | _IFUNC_ARG_HWCAP, &arg);
+  ifunc_resolver_t resolver = reinterpret_cast<ifunc_resolver_t>(resolver_addr);
+  return resolver(arg._hwcap | _IFUNC_ARG_HWCAP, &arg);
 #elif defined(__arm__)
   typedef ElfW(Addr) (*ifunc_resolver_t)(unsigned long);
   static unsigned long hwcap = getauxval(AT_HWCAP);
diff --git a/libc/bionic/bionic_elf_tls.cpp b/libc/bionic/bionic_elf_tls.cpp
index 3245b90..f8d9dca 100644
--- a/libc/bionic/bionic_elf_tls.cpp
+++ b/libc/bionic/bionic_elf_tls.cpp
@@ -30,11 +30,11 @@
 
 #include <async_safe/CHECK.h>
 #include <async_safe/log.h>
+#include <stdbit.h>
 #include <string.h>
 #include <sys/param.h>
 #include <unistd.h>
 
-#include "platform/bionic/macros.h"
 #include "platform/bionic/page.h"
 #include "private/ScopedRWLock.h"
 #include "private/ScopedSignalBlocker.h"
@@ -289,10 +289,7 @@
 // The lock on TlsModules must be held.
 static size_t calculate_new_dtv_count() {
   size_t loaded_cnt = __libc_shared_globals()->tls_modules.module_count;
-  size_t bytes = dtv_size_in_bytes(MAX(1, loaded_cnt));
-  if (!powerof2(bytes)) {
-    bytes = BIONIC_ROUND_UP_POWER_OF_2(bytes);
-  }
+  size_t bytes = stdc_bit_ceil(dtv_size_in_bytes(MAX(1, loaded_cnt)));
   return (bytes - sizeof(TlsDtv)) / sizeof(void*);
 }
 
diff --git a/libc/bionic/bionic_systrace.cpp b/libc/bionic/bionic_systrace.cpp
index 227cb84..ff22293 100644
--- a/libc/bionic/bionic_systrace.cpp
+++ b/libc/bionic/bionic_systrace.cpp
@@ -37,31 +37,25 @@
 static int g_trace_marker_fd = -1;
 
 static bool should_trace() {
-  g_lock.lock();
+  LockGuard guard(g_lock);
   if (g_debug_atrace_tags_enableflags.DidChange()) {
     g_tags = strtoull(g_debug_atrace_tags_enableflags.Get(), nullptr, 0);
   }
-  g_lock.unlock();
-  return ((g_tags & ATRACE_TAG_BIONIC) != 0);
+  return g_tags & ATRACE_TAG_BIONIC;
 }
 
 static int get_trace_marker_fd() {
-  g_lock.lock();
+  LockGuard guard(g_lock);
   if (g_trace_marker_fd == -1) {
     g_trace_marker_fd = open("/sys/kernel/tracing/trace_marker", O_CLOEXEC | O_WRONLY);
     if (g_trace_marker_fd == -1) {
       g_trace_marker_fd = open("/sys/kernel/debug/tracing/trace_marker", O_CLOEXEC | O_WRONLY);
     }
   }
-  g_lock.unlock();
   return g_trace_marker_fd;
 }
 
 static void trace_begin_internal(const char* message) {
-  if (!should_trace()) {
-    return;
-  }
-
   int trace_marker_fd = get_trace_marker_fd();
   if (trace_marker_fd == -1) {
     return;
@@ -83,21 +77,16 @@
   // bionic_trace_begin(). Prevent infinite recursion and non-recursive mutex
   // deadlock by using a flag in the thread local storage.
   bionic_tls& tls = __get_bionic_tls();
-  if (tls.bionic_systrace_disabled) {
-    return;
-  }
-  tls.bionic_systrace_disabled = true;
+  if (!tls.bionic_systrace_enabled || !should_trace()) return;
+
+  tls.bionic_systrace_enabled = false;
 
   trace_begin_internal(message);
 
-  tls.bionic_systrace_disabled = false;
+  tls.bionic_systrace_enabled = true;
 }
 
 static void trace_end_internal() {
-  if (!should_trace()) {
-    return;
-  }
-
   int trace_marker_fd = get_trace_marker_fd();
   if (trace_marker_fd == -1) {
     return;
@@ -125,18 +114,25 @@
   // bionic_trace_begin(). Prevent infinite recursion and non-recursive mutex
   // deadlock by using a flag in the thread local storage.
   bionic_tls& tls = __get_bionic_tls();
-  if (tls.bionic_systrace_disabled) {
-    return;
-  }
-  tls.bionic_systrace_disabled = true;
+  if (!tls.bionic_systrace_enabled || !should_trace()) return;
+
+  tls.bionic_systrace_enabled = false;
 
   trace_end_internal();
 
-  tls.bionic_systrace_disabled = false;
+  tls.bionic_systrace_enabled = true;
 }
 
 ScopedTrace::ScopedTrace(const char* message) : called_end_(false) {
-  bionic_trace_begin(message);
+  // Do not call should_trace if tracing is disabled, the call can crash if
+  // done during initialization.
+  bionic_tls& tls = __get_bionic_tls();
+  should_trace_ = tls.bionic_systrace_enabled && should_trace();
+  if (!should_trace_) return;
+
+  tls.bionic_systrace_enabled = false;
+  trace_begin_internal(message);
+  tls.bionic_systrace_enabled = true;
 }
 
 ScopedTrace::~ScopedTrace() {
@@ -144,8 +140,11 @@
 }
 
 void ScopedTrace::End() {
-  if (!called_end_) {
-    bionic_trace_end();
-    called_end_ = true;
-  }
+  if (!should_trace_ || called_end_) return;
+
+  bionic_tls& tls = __get_bionic_tls();
+  tls.bionic_systrace_enabled = false;
+  trace_end_internal();
+  tls.bionic_systrace_enabled = true;
+  called_end_ = true;
 }
diff --git a/libc/bionic/casecmp.cpp b/libc/bionic/casecmp.cpp
new file mode 100644
index 0000000..703d08f
--- /dev/null
+++ b/libc/bionic/casecmp.cpp
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2025 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <ctype.h>
+#include <stddef.h>
+#include <string.h>
+#include <wchar.h>
+#include <wctype.h>
+
+// We don't use the llvm-libc routines because they don't just call out to
+// tolower()/towlower(), preferring their own implementations, which don't
+// match ours.
+
+// We can also make all the _l() variants simple aliases for the regular
+// functions, since bionic doesn't implement locales (because if you're
+// serious about i18n, you want icu anyway).
+
+template <typename CharT, typename MapperFn>
+int CaseCmp(const CharT* lhs, const CharT* rhs, MapperFn mapper) {
+  while (*lhs && mapper(*lhs) == mapper(*rhs)) {
+    lhs++;
+    rhs++;
+  }
+  return static_cast<unsigned>(mapper(*lhs)) - static_cast<unsigned>(mapper(*rhs));
+}
+
+template <typename CharT, typename MapperFn>
+int CaseCmp(const CharT* lhs, const CharT* rhs, size_t n, MapperFn mapper) {
+  if (n-- == 0) return 0;
+  while (*lhs && *rhs && n > 0 && mapper(*lhs) == mapper(*rhs)) {
+    if (*lhs == '\0') return 0;
+    lhs++;
+    rhs++;
+    n--;
+  }
+  return static_cast<unsigned>(mapper(*lhs)) - static_cast<unsigned>(mapper(*rhs));
+}
+
+int strcasecmp(const char* lhs, const char* rhs) {
+  return CaseCmp(lhs, rhs, tolower);
+}
+__strong_alias(strcasecmp_l, strcasecmp);
+
+int strncasecmp(const char* lhs, const char* rhs, size_t n) {
+  return CaseCmp(lhs, rhs, n, tolower);
+}
+__strong_alias(strncasecmp_l, strncasecmp);
+
+int wcscasecmp(const wchar_t* lhs, const wchar_t* rhs) {
+  return CaseCmp(lhs, rhs, towlower);
+}
+__strong_alias(wcscasecmp_l, wcscasecmp);
+
+int wcsncasecmp(const wchar_t* lhs, const wchar_t* rhs, size_t n) {
+  return CaseCmp(lhs, rhs, n, towlower);
+}
+__strong_alias(wcsncasecmp_l, wcsncasecmp);
diff --git a/libc/bionic/wmempcpy.cpp b/libc/bionic/endian.cpp
similarity index 82%
rename from libc/bionic/wmempcpy.cpp
rename to libc/bionic/endian.cpp
index 54ebf86..bbdbead 100644
--- a/libc/bionic/wmempcpy.cpp
+++ b/libc/bionic/endian.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015 The Android Open Source Project
+ * Copyright (C) 2025 The Android Open Source Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -26,8 +26,20 @@
  * SUCH DAMAGE.
  */
 
-#include <wchar.h>
+#include <endian.h>
 
-wchar_t* wmempcpy(wchar_t* dst, const wchar_t* src, size_t n) {
-  return wmemcpy(dst, src, n) + n;
+uint32_t (htonl)(uint32_t x) {
+  return htonl(x);
+}
+
+uint16_t (htons)(uint16_t x) {
+  return htons(x);
+}
+
+uint32_t (ntohl)(uint32_t x) {
+  return ntohl(x);
+}
+
+uint16_t (ntohs)(uint16_t x) {
+  return ntohs(x);
 }
diff --git a/libc/bionic/err.cpp b/libc/bionic/err.cpp
new file mode 100644
index 0000000..2f3eee1
--- /dev/null
+++ b/libc/bionic/err.cpp
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2025 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <err.h>
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+static void report_err(bool show_errno, const char* fmt, va_list args) {
+  int error = errno;
+  fflush(stdout);
+
+  fprintf(stderr, "%s: ", getprogname());
+  if (fmt) {
+    vfprintf(stderr, fmt, args);
+    if (show_errno) fprintf(stderr, ": ");
+  }
+  if (show_errno) fprintf(stderr, "%s", strerror(error));
+  putc('\n', stderr);
+  fflush(stderr);
+}
+
+void err(int status, const char* _Nullable fmt, ...) {
+  va_list va;
+  va_start(va, fmt);
+  verr(status, fmt, va);
+}
+
+void verr(int status, const char* _Nullable fmt, va_list args) {
+  report_err(true, fmt, args);
+  exit(status);
+}
+
+void errx(int status, const char* _Nullable fmt, ...) {
+  va_list va;
+  va_start(va, fmt);
+  verrx(status, fmt, va);
+}
+
+void verrx(int status, const char* _Nullable fmt, va_list args) {
+  report_err(false, fmt, args);
+  exit(status);
+}
+
+void warn(const char* _Nullable fmt, ...) {
+  va_list va;
+  va_start(va, fmt);
+  vwarn(fmt, va);
+  va_end(va);
+}
+
+void vwarn(const char* _Nullable fmt, va_list args) {
+  report_err(true, fmt, args);
+}
+
+void warnx(const char* _Nullable fmt, ...) {
+  va_list va;
+  va_start(va, fmt);
+  vwarnx(fmt, va);
+  va_end(va);
+}
+
+void vwarnx(const char* _Nullable fmt, va_list args) {
+  report_err(false, fmt, args);
+}
diff --git a/libc/bionic/fdsan.cpp b/libc/bionic/fdsan.cpp
index 0b0678b..382696c 100644
--- a/libc/bionic/fdsan.cpp
+++ b/libc/bionic/fdsan.cpp
@@ -50,7 +50,6 @@
 #include "pthread_internal.h"
 
 extern "C" int __close(int fd);
-pid_t __get_cached_pid();
 
 static constexpr const char* kFdsanPropertyName = "debug.fdsan";
 
@@ -81,7 +80,7 @@
 
     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_size = __builtin_align_up(required_size, page_size());
     size_t aligned_count = (aligned_size - sizeof(FdTableOverflow)) / sizeof(FdEntry);
 
     void* allocation =
@@ -161,7 +160,7 @@
     case ANDROID_FDSAN_ERROR_LEVEL_WARN_ONCE:
       atomic_compare_exchange_strong(&fd_table.error_level, &error_level,
                                      ANDROID_FDSAN_ERROR_LEVEL_DISABLED);
-      __BIONIC_FALLTHROUGH;
+      [[fallthrough]];
     case ANDROID_FDSAN_ERROR_LEVEL_WARN_ALWAYS:
       inline_raise(BIONIC_SIGNAL_DEBUGGER, &abort_message);
       break;
@@ -385,8 +384,11 @@
 
 int close(int fd) {
   int rc = android_fdsan_close_with_tag(fd, 0);
+
+  // See the "close" section of bionic/docs/EINTR.md for more.
   if (rc == -1 && errno == EINTR) {
     return 0;
   }
+
   return rc;
 }
diff --git a/libc/bionic/fortify.cpp b/libc/bionic/fortify.cpp
index 15053d3..a1cc4e8 100644
--- a/libc/bionic/fortify.cpp
+++ b/libc/bionic/fortify.cpp
@@ -231,10 +231,10 @@
 
 // Runtime implementation of __builtin____stpcpy_chk (used directly by compiler, not in headers)..
 extern "C" char* __stpcpy_chk(char* dst, const char* src, size_t dst_len) {
-  // TODO: optimize so we don't scan src twice.
   size_t src_len = strlen(src) + 1;
   __check_buffer_access("stpcpy", "write into", src_len, dst_len);
-  return stpcpy(dst, src);
+  // stpcpy() returns a pointer to the NUL, but mempcpy() returns a pointer _past_ the last byte.
+  return static_cast<char*>(mempcpy(dst, src, src_len)) - 1;
 }
 
 // Runtime implementation of __builtin____stpncpy_chk (used directly by compiler, not in headers).
@@ -483,10 +483,9 @@
 
 // Runtime implementation of __builtin____strcpy_chk (used directly by compiler, not in headers).
 extern "C" char* __STRCPY_CHK(char* dst, const char* src, size_t dst_len) {
-  // TODO: optimize so we don't scan src twice.
   size_t src_len = strlen(src) + 1;
   __check_buffer_access("strcpy", "write into", src_len, dst_len);
-  return strcpy(dst, src);
+  return static_cast<char*>(memcpy(dst, src, src_len));
 }
 
 // Runtime implementation of __mempcpy_chk (used directly by compiler, not in headers).
diff --git a/libc/bionic/getdomainname.cpp b/libc/bionic/getdomainname.cpp
deleted file mode 100644
index 761a999..0000000
--- a/libc/bionic/getdomainname.cpp
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <errno.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/utsname.h>
-
-int getdomainname(char* name, size_t len) {
-  utsname uts;
-  if (uname(&uts) == -1) return -1;
-
-  // Note: getdomainname()'s behavior varies across implementations when len is
-  // too small.  bionic follows the historical libc policy of returning EINVAL,
-  // instead of glibc's policy of copying the first len bytes without a NULL
-  // terminator.
-  if (strlen(uts.domainname) >= len) {
-      errno = EINVAL;
-      return -1;
-  }
-
-  strncpy(name, uts.domainname, len);
-  return 0;
-}
diff --git a/libc/bionic/getentropy.cpp b/libc/bionic/getentropy.cpp
index 9c93e71..5272c34 100644
--- a/libc/bionic/getentropy.cpp
+++ b/libc/bionic/getentropy.cpp
@@ -28,6 +28,7 @@
 
 #include <errno.h>
 #include <fcntl.h>
+#include <limits.h>
 #include <sys/random.h>
 #include <unistd.h>
 
@@ -50,8 +51,8 @@
 }
 
 int getentropy(void* buffer, size_t buffer_size) {
-  if (buffer_size > 256) {
-    errno = EIO;
+  if (buffer_size > GETENTROPY_MAX) {
+    errno = EINVAL;
     return -1;
   }
 
@@ -62,11 +63,17 @@
     long count = TEMP_FAILURE_RETRY(getrandom(static_cast<char*>(buffer) + collected,
                                               buffer_size - collected, GRND_NONBLOCK));
     if (count == -1) {
+      // One of several things could have gone wrong:
       // EAGAIN: there isn't enough entropy right now.
       // ENOSYS/EINVAL: getrandom(2) or GRND_NONBLOCK isn't supported.
       // EFAULT: `buffer` is invalid.
-      // Try /dev/urandom regardless because it can't hurt,
+      // Realistically we're here because of EAGAIN,
+      // for which /dev/urandom is the solution ---
+      // it'll return low entropy randomness where getrandom() won't,
+      // but we fall back /dev/urandom for all cases because it can't hurt,
       // and we don't need to optimize the EFAULT case.
+      // See https://man7.org/linux/man-pages/man7/random.7.html for getrandom()
+      // vs /dev/random vs /dev/urandom.
       // See http://b/33059407 and http://b/67015565.
       return getentropy_urandom(buffer, buffer_size, saved_errno);
     }
diff --git a/libc/bionic/gethostname.cpp b/libc/bionic/gethostname.cpp
index b780a2f..fd5c914 100644
--- a/libc/bionic/gethostname.cpp
+++ b/libc/bionic/gethostname.cpp
@@ -31,16 +31,24 @@
 #include <sys/utsname.h>
 #include <unistd.h>
 
-int gethostname(char* buf, size_t n) {
-  utsname name = {};
-  uname(&name);
-
-  size_t name_length = static_cast<size_t>(strlen(name.nodename) + 1);
+static inline int __safe_name_copy(char* dst, size_t n, const char* src, int too_long_errno) {
+  size_t name_length = static_cast<size_t>(strlen(src) + 1);
   if (name_length > n) {
-    errno = ENAMETOOLONG;
+    errno = too_long_errno;
     return -1;
   }
-
-  memcpy(buf, name.nodename, name_length);
+  memcpy(dst, src, name_length);
   return 0;
 }
+
+int gethostname(char* buf, size_t n) {
+  utsname uts = {};
+  if (uname(&uts) == -1) return -1;
+  return __safe_name_copy(buf, n, uts.nodename, ENAMETOOLONG);
+}
+
+int getdomainname(char* buf, size_t n) {
+  utsname uts = {};
+  if (uname(&uts) == -1) return -1;
+  return __safe_name_copy(buf, n, uts.domainname, EINVAL);
+}
diff --git a/libc/bionic/grp_pwd.cpp b/libc/bionic/grp_pwd.cpp
index 82ee7ba..48c005c 100644
--- a/libc/bionic/grp_pwd.cpp
+++ b/libc/bionic/grp_pwd.cpp
@@ -240,7 +240,7 @@
 }
 #endif  // if defined(__ANDROID__)
 
-// This provides an iterater for app_ids within the first user's app id's.
+// This provides an iterator for app_ids within the first user's app id's.
 static id_t get_next_app_id(id_t current_id, bool is_group) {
   auto ranges_size = is_group ? arraysize(group_ranges) : arraysize(user_ranges);
   auto ranges = is_group ? group_ranges : user_ranges;
@@ -585,7 +585,7 @@
   ErrnoRestorer errno_restorer;
   *result = nullptr;
   char* p =
-      reinterpret_cast<char*>(__BIONIC_ALIGN(reinterpret_cast<uintptr_t>(buf), sizeof(uintptr_t)));
+      reinterpret_cast<char*>(__builtin_align_up(reinterpret_cast<uintptr_t>(buf), sizeof(uintptr_t)));
   if (p + sizeof(passwd_state_t) > buf + buflen) {
     return ERANGE;
   }
@@ -753,7 +753,7 @@
   ErrnoRestorer errno_restorer;
   *result = nullptr;
   char* p = reinterpret_cast<char*>(
-      __BIONIC_ALIGN(reinterpret_cast<uintptr_t>(buf), sizeof(uintptr_t)));
+      __builtin_align_up(reinterpret_cast<uintptr_t>(buf), sizeof(uintptr_t)));
   if (p + sizeof(group_state_t) > buf + buflen) {
     return ERANGE;
   }
diff --git a/libc/bionic/gwp_asan_wrappers.cpp b/libc/bionic/gwp_asan_wrappers.cpp
index 2124f51..d416775 100644
--- a/libc/bionic/gwp_asan_wrappers.cpp
+++ b/libc/bionic/gwp_asan_wrappers.cpp
@@ -34,6 +34,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/param.h>
 #include <sys/types.h>
 
 #include "gwp_asan/crash_handler.h"
@@ -172,13 +173,8 @@
     Malloc(malloc_info),
 };
 
-bool isPowerOfTwo(uint64_t x) {
-  assert(x != 0);
-  return (x & (x - 1)) == 0;
-}
-
 bool ShouldGwpAsanSampleProcess(unsigned sample_rate) {
-  if (!isPowerOfTwo(sample_rate)) {
+  if (!powerof2(sample_rate)) {
     warning_log(
         "GWP-ASan process sampling rate of %u is not a power-of-two, and so modulo bias occurs.",
         sample_rate);
diff --git a/libc/bionic/jemalloc_wrapper.cpp b/libc/bionic/jemalloc_wrapper.cpp
index 63c9fab..4178703 100644
--- a/libc/bionic/jemalloc_wrapper.cpp
+++ b/libc/bionic/jemalloc_wrapper.cpp
@@ -17,6 +17,7 @@
 #include <errno.h>
 #include <inttypes.h>
 #include <malloc.h>
+#include <stdbit.h>
 #include <sys/param.h>
 #include <unistd.h>
 
@@ -37,7 +38,7 @@
 
 void* je_pvalloc(size_t bytes) {
   size_t pagesize = getpagesize();
-  size_t size = __BIONIC_ALIGN(bytes, pagesize);
+  size_t size = __builtin_align_up(bytes, pagesize);
   if (size < bytes) {
     return nullptr;
   }
@@ -48,17 +49,12 @@
 #undef je_memalign
 #endif
 
-// The man page for memalign says it fails if boundary is not a power of 2,
-// but this is not true. Both glibc and dlmalloc round up to the next power
-// of 2, so we'll do the same.
 void* je_memalign_round_up_boundary(size_t boundary, size_t size) {
-  if (boundary != 0) {
-    if (!powerof2(boundary)) {
-      boundary = BIONIC_ROUND_UP_POWER_OF_2(boundary);
-    }
-  } else {
-    boundary = 1;
-  }
+  // The man page for memalign says it fails if boundary is not a power of 2,
+  // but this is not true. Both glibc and dlmalloc round up to the next power
+  // of 2, so we'll do the same.
+  boundary = stdc_bit_ceil(boundary);
+
   return je_memalign(boundary, size);
 }
 
diff --git a/libc/bionic/legacy_32_bit_support.cpp b/libc/bionic/legacy_32_bit_support.cpp
index e66126b..19bf3c0 100644
--- a/libc/bionic/legacy_32_bit_support.cpp
+++ b/libc/bionic/legacy_32_bit_support.cpp
@@ -124,7 +124,7 @@
 
   // Prevent allocations large enough for `end - start` to overflow,
   // to avoid security bugs.
-  size_t rounded = __BIONIC_ALIGN(size, page_size());
+  size_t rounded = __builtin_align_up(size, page_size());
   if (rounded < size || rounded > PTRDIFF_MAX) {
     errno = ENOMEM;
     return MAP_FAILED;
@@ -144,7 +144,7 @@
 void* mremap(void* old_address, size_t old_size, size_t new_size, int flags, ...) {
   // Prevent allocations large enough for `end - start` to overflow,
   // to avoid security bugs.
-  size_t rounded = __BIONIC_ALIGN(new_size, page_size());
+  size_t rounded = __builtin_align_up(new_size, page_size());
   if (rounded < new_size || rounded > PTRDIFF_MAX) {
     errno = ENOMEM;
     return MAP_FAILED;
diff --git a/libc/bionic/libc_init_common.cpp b/libc/bionic/libc_init_common.cpp
index 94ba7e4..502ae09 100644
--- a/libc/bionic/libc_init_common.cpp
+++ b/libc/bionic/libc_init_common.cpp
@@ -49,7 +49,6 @@
 #include "private/bionic_defs.h"
 #include "private/bionic_globals.h"
 #include "private/bionic_tls.h"
-#include "private/thread_private.h"
 #include "pthread_internal.h"
 
 extern "C" int __system_properties_init(void);
@@ -60,10 +59,6 @@
 __LIBC_HIDDEN__ constinit _Atomic(bool) __libc_memtag_stack;
 __LIBC_HIDDEN__ constinit bool __libc_memtag_stack_abi;
 
-// Not public, but well-known in the BSDs.
-__BIONIC_WEAK_VARIABLE_FOR_NATIVE_BRIDGE
-const char* __progname;
-
 #if defined(__i386__) || defined(__x86_64__)
 // Default sizes based on the old hard-coded values for Atom/Silvermont (x86) and Core 2 (x86-64)...
 size_t __x86_data_cache_size = 24 * 1024;
@@ -108,11 +103,6 @@
 }
 #endif
 
-static void arc4random_fork_handler() {
-  _rs_forked = 1;
-  _thread_arc4_lock();
-}
-
 __BIONIC_WEAK_FOR_NATIVE_BRIDGE
 void __libc_init_scudo() {
   // Heap tagging level *must* be set before interacting with Scudo, otherwise
@@ -203,9 +193,12 @@
 #endif
 }
 
+extern "C" void arc4random_mutex_lock();
+extern "C" void arc4random_mutex_unlock();
+
 void __libc_init_fork_handler() {
   // Register atfork handlers to take and release the arc4random lock.
-  pthread_atfork(arc4random_fork_handler, _thread_arc4_unlock, _thread_arc4_unlock);
+  pthread_atfork(arc4random_mutex_lock, arc4random_mutex_unlock, arc4random_mutex_unlock);
 }
 
 extern "C" void scudo_malloc_set_add_large_allocation_slack(int add_slack);
diff --git a/libc/bionic/libc_init_dynamic.cpp b/libc/bionic/libc_init_dynamic.cpp
index 541e71c..2032b65 100644
--- a/libc/bionic/libc_init_dynamic.cpp
+++ b/libc/bionic/libc_init_dynamic.cpp
@@ -120,6 +120,9 @@
   __libc_shared_globals()->set_target_sdk_version_hook = __libc_set_target_sdk_version;
 
   netdClientInit();
+
+  // Wait until everything is initialized before enabled systracing.
+  __get_bionic_tls().bionic_systrace_enabled = true;
 }
 
 // We flag the __libc_preinit function as a constructor to ensure that
diff --git a/libc/bionic/libc_init_static.cpp b/libc/bionic/libc_init_static.cpp
index 9cc3060..330e999 100644
--- a/libc/bionic/libc_init_static.cpp
+++ b/libc/bionic/libc_init_static.cpp
@@ -202,6 +202,9 @@
   __libc_init_mte_late();
 #endif
 
+  // Wait until everything is initialized before enabled systracing.
+  __get_bionic_tls().bionic_systrace_enabled = true;
+
   exit(slingshot(args.argc, args.argv, args.envp));
 }
 
diff --git a/libc/bionic/libgen.cpp b/libc/bionic/libgen.cpp
index b952822..f02e68a 100644
--- a/libc/bionic/libgen.cpp
+++ b/libc/bionic/libgen.cpp
@@ -158,13 +158,13 @@
 }
 
 char* basename(const char* path) {
-  char* buf = __get_bionic_tls().basename_buf;
-  int rc = __basename_r(path, buf, sizeof(__get_bionic_tls().basename_buf));
+  char* buf = (__get_bionic_tls().libgen_buffers_ptr)->basename_buf;
+  int rc = __basename_r(path, buf, sizeof((__get_bionic_tls().libgen_buffers_ptr)->basename_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));
+  char* buf = (__get_bionic_tls().libgen_buffers_ptr)->dirname_buf;
+  int rc = __dirname_r(path, buf, sizeof((__get_bionic_tls().libgen_buffers_ptr)->dirname_buf));
   return (rc < 0) ? nullptr : buf;
 }
diff --git a/libc/bionic/memset_explicit.cpp b/libc/bionic/memset_explicit.cpp
index 2bcc20c..6d7fdd3 100644
--- a/libc/bionic/memset_explicit.cpp
+++ b/libc/bionic/memset_explicit.cpp
@@ -28,9 +28,5 @@
 
 #include <string.h>
 
-void* memset_explicit(void* __dst, int __ch, size_t __n) {
-  void* result = memset(__dst, __ch, __n);
-  // https://bugs.llvm.org/show_bug.cgi?id=15495
-  __asm__ __volatile__("" : : "r"(__dst) : "memory");
-  return result;
-}
+#define __BIONIC_MEMSET_EXPLICIT_INLINE /* Out of line. */
+#include <bits/memset_explicit_impl.h>
diff --git a/libc/bionic/ndk_cruft.cpp b/libc/bionic/ndk_cruft.cpp
index a69b77f..bc06d9d 100644
--- a/libc/bionic/ndk_cruft.cpp
+++ b/libc/bionic/ndk_cruft.cpp
@@ -31,6 +31,8 @@
 // LP64 doesn't need to support any legacy cruft.
 #if !defined(__LP64__)
 
+#define __BIONIC_DISABLE_MALLOC_USABLE_SIZE_FORTIFY_WARNINGS
+
 #include <ctype.h>
 #include <dirent.h>
 #include <errno.h>
diff --git a/libc/bionic/net_if.cpp b/libc/bionic/net_if.cpp
index ad53364..e94a2ee 100644
--- a/libc/bionic/net_if.cpp
+++ b/libc/bionic/net_if.cpp
@@ -49,17 +49,24 @@
   if (s.get() == -1) return nullptr;
 
   ifreq ifr = {.ifr_ifindex = static_cast<int>(ifindex)};
-  return (ioctl(s.get(), SIOCGIFNAME, &ifr) == -1) ? nullptr
-                                                   : strncpy(ifname, ifr.ifr_name, IFNAMSIZ);
+  if (ioctl(s.get(), SIOCGIFNAME, &ifr) == -1) return nullptr;
+
+  strcpy(ifname, ifr.ifr_name);
+  return ifname;
 }
 
 unsigned if_nametoindex(const char* ifname) {
+  ifreq ifr = {};
+
+  if (strlen(ifname) >= sizeof(ifr.ifr_name)) {
+    errno = ENODEV;
+    return 0;
+  }
+  strcpy(ifr.ifr_name, ifname);
+
   ScopedFd s(socket(AF_INET, SOCK_DGRAM|SOCK_CLOEXEC, 0));
   if (s.get() == -1) return 0;
 
-  ifreq ifr = {};
-  strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
-  ifr.ifr_name[IFNAMSIZ - 1] = 0;
   return (ioctl(s.get(), SIOCGIFINDEX, &ifr) == -1) ? 0 : ifr.ifr_ifindex;
 }
 
diff --git a/libc/bionic/pthread_create.cpp b/libc/bionic/pthread_create.cpp
index 1bd2da7..f6d7fa8 100644
--- a/libc/bionic/pthread_create.cpp
+++ b/libc/bionic/pthread_create.cpp
@@ -70,22 +70,30 @@
   tcb->tls_slot(TLS_SLOT_BIONIC_TLS) = tls;
 }
 
+void __init_libgen_buffers_ptr(bionic_tls* tls, libgen_buffers* lb) {
+  tls->libgen_buffers_ptr = lb;
+}
+
+static inline size_t get_temp_bionic_tls_size() {
+  return __builtin_align_up(sizeof(bionic_tls) + sizeof(libgen_buffers), page_size());
+}
+
 // Allocate a temporary bionic_tls that the dynamic linker's main thread can
 // use while it's loading the initial set of ELF modules.
 bionic_tls* __allocate_temp_bionic_tls() {
-  size_t allocation_size = __BIONIC_ALIGN(sizeof(bionic_tls), page_size());
-  void* allocation = mmap(nullptr, allocation_size,
-                          PROT_READ | PROT_WRITE,
-                          MAP_PRIVATE | MAP_ANONYMOUS,
-                          -1, 0);
+  void* allocation = mmap(nullptr, get_temp_bionic_tls_size(), PROT_READ | PROT_WRITE,
+                          MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
   if (allocation == MAP_FAILED) {
     async_safe_fatal("failed to allocate bionic_tls: %m");
   }
-  return static_cast<bionic_tls*>(allocation);
+  bionic_tls* tls = static_cast<bionic_tls*>(allocation);
+  tls->libgen_buffers_ptr =
+      reinterpret_cast<libgen_buffers*>(static_cast<char*>(allocation) + sizeof(bionic_tls));
+  return tls;
 }
 
 void __free_temp_bionic_tls(bionic_tls* tls) {
-  munmap(tls, __BIONIC_ALIGN(sizeof(bionic_tls), page_size()));
+  munmap(tls, get_temp_bionic_tls_size());
 }
 
 static void __init_alternate_signal_stack(pthread_internal_t* thread) {
@@ -216,15 +224,18 @@
 ThreadMapping __allocate_thread_mapping(size_t stack_size, size_t stack_guard_size) {
   const StaticTlsLayout& layout = __libc_shared_globals()->static_tls_layout;
 
-  // Allocate in order: stack guard, stack, static TLS, guard page.
+  // Allocate in order: stack guard, stack, static TLS, libgen buffers, guard page.
   size_t mmap_size;
   if (__builtin_add_overflow(stack_size, stack_guard_size, &mmap_size)) return {};
   if (__builtin_add_overflow(mmap_size, layout.size(), &mmap_size)) return {};
   if (__builtin_add_overflow(mmap_size, PTHREAD_GUARD_SIZE, &mmap_size)) return {};
+  // Add space for the dedicated libgen buffers page(s).
+  size_t libgen_buffers_padded_size = __builtin_align_up(sizeof(libgen_buffers), page_size());
+  if (__builtin_add_overflow(mmap_size, libgen_buffers_padded_size, &mmap_size)) return {};
 
   // Align the result to a page size.
   const size_t unaligned_size = mmap_size;
-  mmap_size = __BIONIC_ALIGN(mmap_size, page_size());
+  mmap_size = __builtin_align_up(mmap_size, page_size());
   if (mmap_size < unaligned_size) return {};
 
   // Create a new private anonymous map. Make the entire mapping PROT_NONE, then carve out a
@@ -255,12 +266,21 @@
     return {};
   }
 
+  // Layout from the end of the mmap-ed region (before the top PTHREAD_GUARD_SIZE):
+  //
+  // [ PTHREAD_GUARD_SIZE ]
+  // [ libgen_buffers_padded_size (for dedicated page(s) for libgen buffers) ]
+  // [ layout.size() (for static TLS) ]
+  // [ stack_size ]
+  // [ stack_guard_size ]
+
   ThreadMapping result = {};
   result.mmap_base = space;
   result.mmap_size = mmap_size;
   result.mmap_base_unguarded = space + stack_guard_size;
   result.mmap_size_unguarded = mmap_size - stack_guard_size - PTHREAD_GUARD_SIZE;
-  result.static_tls = space + mmap_size - PTHREAD_GUARD_SIZE - layout.size();
+  result.libgen_buffers = space + mmap_size - PTHREAD_GUARD_SIZE - libgen_buffers_padded_size;
+  result.static_tls = result.libgen_buffers - layout.size();
   result.stack_base = space;
   result.stack_top = result.static_tls;
   return result;
@@ -276,7 +296,7 @@
 
     // Make sure the guard size is a multiple of page_size().
     const size_t unaligned_guard_size = attr->guard_size;
-    attr->guard_size = __BIONIC_ALIGN(attr->guard_size, page_size());
+    attr->guard_size = __builtin_align_up(attr->guard_size, page_size());
     if (attr->guard_size < unaligned_guard_size) return EAGAIN;
 
     mapping = __allocate_thread_mapping(attr->stack_size, attr->guard_size);
@@ -309,6 +329,7 @@
   const StaticTlsLayout& layout = __libc_shared_globals()->static_tls_layout;
   auto tcb = reinterpret_cast<bionic_tcb*>(mapping.static_tls + layout.offset_bionic_tcb());
   auto tls = reinterpret_cast<bionic_tls*>(mapping.static_tls + layout.offset_bionic_tls());
+  auto lb = reinterpret_cast<libgen_buffers*>(mapping.libgen_buffers);
 
   // Initialize TLS memory.
   __init_static_tls(mapping.static_tls);
@@ -316,6 +337,7 @@
   __init_tcb_dtv(tcb);
   __init_tcb_stack_guard(tcb);
   __init_bionic_tls_ptrs(tcb, tls);
+  __init_libgen_buffers_ptr(tls, lb);
 
   attr->stack_size = stack_top - static_cast<char*>(attr->stack_base);
   thread->attr = *attr;
@@ -324,6 +346,7 @@
   thread->mmap_base_unguarded = mapping.mmap_base_unguarded;
   thread->mmap_size_unguarded = mapping.mmap_size_unguarded;
   thread->stack_top = reinterpret_cast<uintptr_t>(stack_top);
+  thread->stack_bottom = reinterpret_cast<uintptr_t>(attr->stack_base);
 
   *tcbp = tcb;
   *child_stack = stack_top;
diff --git a/libc/bionic/pthread_internal.cpp b/libc/bionic/pthread_internal.cpp
index 4f2ad0c..7c66c75 100644
--- a/libc/bionic/pthread_internal.cpp
+++ b/libc/bionic/pthread_internal.cpp
@@ -130,7 +130,7 @@
     async_safe_fatal("couldn't open /proc/self/stat: %m");
   }
 
-  char line[BUFSIZ];
+  char line[BUFSIZ] __attribute__((__uninitialized__));
   if (fgets(line, sizeof(line), fp) == nullptr) {
     async_safe_fatal("couldn't read /proc/self/stat: %m");
   }
@@ -165,7 +165,7 @@
   if (fp == nullptr) {
     async_safe_fatal("couldn't open /proc/self/maps: %m");
   }
-  char line[BUFSIZ];
+  char line[BUFSIZ] __attribute__((__uninitialized__));
   while (fgets(line, sizeof(line), fp) != nullptr) {
     uintptr_t lo, hi;
     if (sscanf(line, "%" SCNxPTR "-%" SCNxPTR, &lo, &hi) == 2) {
diff --git a/libc/bionic/pthread_internal.h b/libc/bionic/pthread_internal.h
index ae9a791..b3133a9 100644
--- a/libc/bionic/pthread_internal.h
+++ b/libc/bionic/pthread_internal.h
@@ -146,9 +146,11 @@
   //    code to handle retries.
   void* shadow_call_stack_guard_region;
 
-  // A pointer to the top of the stack. This lets android_unsafe_frame_pointer_chase determine the
-  // top of the stack quickly, which would otherwise require special logic for the main thread.
+  // Pointers to the top and bottom of the stack. This lets android_unsafe_frame_pointer_chase
+  // determine the top and bottom of the stack quickly, which would otherwise require special logic
+  // for the main thread.
   uintptr_t stack_top;
+  uintptr_t stack_bottom;
 
   // Whether the thread is in the process of terminating (has blocked signals), or has already
   // terminated. This is used by android_run_on_all_threads() to avoid sending a signal to a thread
@@ -195,12 +197,14 @@
   char* static_tls;
   char* stack_base;
   char* stack_top;
+  char* libgen_buffers;
 };
 
 __LIBC_HIDDEN__ void __init_tcb(bionic_tcb* tcb, pthread_internal_t* thread);
 __LIBC_HIDDEN__ void __init_tcb_stack_guard(bionic_tcb* tcb);
 __LIBC_HIDDEN__ void __init_tcb_dtv(bionic_tcb* tcb);
 __LIBC_HIDDEN__ void __init_bionic_tls_ptrs(bionic_tcb* tcb, bionic_tls* tls);
+__LIBC_HIDDEN__ void __init_libgen_buffers_ptr(bionic_tls* tls, libgen_buffers* lb);
 __LIBC_HIDDEN__ bionic_tls* __allocate_temp_bionic_tls();
 __LIBC_HIDDEN__ void __free_temp_bionic_tls(bionic_tls* tls);
 __LIBC_HIDDEN__ void __init_additional_stacks(pthread_internal_t*);
diff --git a/libc/bionic/raise.cpp b/libc/bionic/raise.cpp
index 1f204d4..b015f4e 100644
--- a/libc/bionic/raise.cpp
+++ b/libc/bionic/raise.cpp
@@ -26,15 +26,11 @@
  * SUCH DAMAGE.
  */
 
-#include <errno.h>
 #include <signal.h>
-#include <unistd.h>
-#include <sys/syscall.h>
 
+#include "private/bionic_inline_raise.h"
+
+// Reuse inline_raise() to minimize uninteresting stack frames in unwinds.
 int raise(int sig) {
-  // Protect ourselves against stale cached PID/TID values by fetching them via syscall.
-  // http://b/37769298
-  pid_t pid = syscall(__NR_getpid);
-  pid_t tid = syscall(__NR_gettid);
-  return tgkill(pid, tid, sig);
+  return inline_raise(sig);
 }
diff --git a/libc/bionic/realpath.cpp b/libc/bionic/realpath.cpp
index e43d8e2..400bddb 100644
--- a/libc/bionic/realpath.cpp
+++ b/libc/bionic/realpath.cpp
@@ -41,7 +41,7 @@
 // (Remember that readlink(2) won't tell you the needed size, so the multi-pass
 // algorithm isn't even an option unless you want to just guess, in which case
 // you're back needing to trim again.)
-#pragma GCC diagnostic ignored "-Wframe-larger-than="
+#pragma clang diagnostic ignored "-Wframe-larger-than="
 
 char* realpath(const char* path, char* result) {
   // Weird special case.
@@ -55,10 +55,8 @@
   if (fd.get() == -1) return nullptr;
 
   // (...remember the device/inode that we're talking about and...)
-  struct stat sb;
-  if (fstat(fd.get(), &sb) == -1) return nullptr;
-  dev_t st_dev = sb.st_dev;
-  ino_t st_ino = sb.st_ino;
+  struct stat sb_before;
+  if (fstat(fd.get(), &sb_before) == -1) return nullptr;
 
   // ...ask the kernel to do the hard work for us.
   FdPath fd_path(fd.get());
@@ -69,7 +67,10 @@
 
   // What if the file was removed in the meantime? readlink(2) will have
   // returned "/a/b/c (deleted)", and we want to return ENOENT instead.
-  if (stat(dst, &sb) == -1 || st_dev != sb.st_dev || st_ino != sb.st_ino) {
+  struct stat sb_after;
+  if (stat(dst, &sb_after) == -1 ||
+      sb_before.st_dev != sb_after.st_dev ||
+      sb_before.st_ino != sb_after.st_ino) {
     errno = ENOENT;
     return nullptr;
   }
diff --git a/libc/bionic/signal.cpp b/libc/bionic/signal.cpp
index 77e6acf..0d60546 100644
--- a/libc/bionic/signal.cpp
+++ b/libc/bionic/signal.cpp
@@ -29,6 +29,7 @@
 #include <errno.h>
 #include <pthread.h>
 #include <signal.h>
+#include <stdio.h>
 #include <string.h>
 #include <sys/epoll.h>
 #include <sys/signalfd.h>
@@ -305,3 +306,15 @@
 int sigwaitinfo64(const sigset64_t* set, siginfo_t* info) {
   return sigtimedwait64(set, info, nullptr);
 }
+
+extern "C" const char* __strsignal(int, char*, size_t);
+
+void psignal(int sig, const char* msg) {
+  if (msg == nullptr) msg = "";
+  char buf[NL_TEXTMAX];
+  fprintf(stderr, "%s%s%s\n", msg, (*msg == '\0') ? "" : ": ", __strsignal(sig, buf, sizeof(buf)));
+}
+
+void psiginfo(const siginfo_t* si, const char* msg) {
+  psignal(si->si_signo, msg);
+}
diff --git a/libc/bionic/spawn.cpp b/libc/bionic/spawn.cpp
index d97057f..f1b8eb0 100644
--- a/libc/bionic/spawn.cpp
+++ b/libc/bionic/spawn.cpp
@@ -42,28 +42,6 @@
 
 #include "private/ScopedSignalBlocker.h"
 
-static int set_cloexec(int i) {
-  int v = fcntl(i, F_GETFD);
-  if (v == -1) return -1;  // almost certainly: errno == EBADF
-  return fcntl(i, F_SETFD, v | FD_CLOEXEC);
-}
-
-// mark all open fds except stdin/out/err as close-on-exec
-static int cloexec_except_stdioe() {
-  // requires 5.11+ or ACK 5.10-T kernel, otherwise returns ENOSYS or EINVAL
-  if (!close_range(3, ~0U, CLOSE_RANGE_CLOEXEC)) return 0;
-
-  // unfortunately getrlimit can lie:
-  // - both soft and hard limits can be lowered to 0, with fds still open, so it can underestimate
-  // - in practice it usually is some really large value (like 32K or more)
-  //   even though only a handful of small fds are actually open (ie. < 500),
-  //   this results in poor performance when trying to act on all possibly open fds
-  struct rlimit m;
-  int max = getrlimit(RLIMIT_NOFILE, &m) ? 1000000 : m.rlim_max;
-  for (int i = 3; i < max; ++i) set_cloexec(i);
-  return 0;
-}
-
 enum Action {
   kOpen,
   kClose,
@@ -175,7 +153,8 @@
   }
 
   if ((flags & POSIX_SPAWN_CLOEXEC_DEFAULT) != 0) {
-    if (cloexec_except_stdioe()) _exit(127);
+    // mark all open fds except stdin/out/err as close-on-exec
+    if (close_range(3, ~0U, CLOSE_RANGE_CLOEXEC)) _exit(127);
   }
 }
 
diff --git a/libc/bionic/string_l.cpp b/libc/bionic/string_l.cpp
index 84396bf..1d60ad8 100644
--- a/libc/bionic/string_l.cpp
+++ b/libc/bionic/string_l.cpp
@@ -29,10 +29,12 @@
 #include <string.h>
 #include <xlocale.h>
 
-int strcoll_l(const char* s1, const char* s2, locale_t) {
-  return strcoll(s1, s2);
+int strcoll(const char* lhs, const char* rhs) {
+  return strcmp(lhs, rhs);
 }
+__strong_alias(strcoll_l, strcoll);
 
-size_t strxfrm_l(char* dst, const char* src, size_t n, locale_t) {
-  return strxfrm(dst, src, n);
+size_t strxfrm(char* dst, const char* src, size_t n) {
+  return strlcpy(dst, src, n);
 }
+__strong_alias(strxfrm_l, strxfrm);
diff --git a/libc/bionic/strings_l.cpp b/libc/bionic/strings_l.cpp
deleted file mode 100644
index 0983ab1..0000000
--- a/libc/bionic/strings_l.cpp
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <strings.h>
-#include <xlocale.h>
-
-int strcasecmp_l(const char* s1, const char* s2, locale_t) {
-  return strcasecmp(s1, s2);
-}
-
-int strncasecmp_l(const char* s1, const char* s2, size_t n, locale_t) {
-  return strncasecmp(s1, s2, n);
-}
diff --git a/libc/bionic/sys_statvfs.cpp b/libc/bionic/sys_statvfs.cpp
index 3a05c3f..18ee340 100644
--- a/libc/bionic/sys_statvfs.cpp
+++ b/libc/bionic/sys_statvfs.cpp
@@ -26,7 +26,8 @@
   dst->f_files = src->f_files;
   dst->f_ffree = src->f_ffree;
   dst->f_favail = src->f_ffree;
-  dst->f_fsid = src->f_fsid.__val[0] | static_cast<uint64_t>(src->f_fsid.__val[1]) << 32;
+  dst->f_fsid = static_cast<uint64_t>(src->f_fsid.__val[0]) |
+                static_cast<uint64_t>(src->f_fsid.__val[1]) << 32;
   dst->f_flag = src->f_flags;
   dst->f_namemax = src->f_namelen;
 }
diff --git a/libc/bionic/syslog.cpp b/libc/bionic/syslog.cpp
index a459c6b..9ac55b3 100644
--- a/libc/bionic/syslog.cpp
+++ b/libc/bionic/syslog.cpp
@@ -23,7 +23,8 @@
 #include <async_safe/log.h>
 
 static const char* syslog_log_tag = nullptr;
-static int syslog_priority_mask = 0xff;
+// The "mask" is of _enabled_ log priorities, and defaults to all.
+static int syslog_priority_mask = LOG_UPTO(LOG_DEBUG);
 static int syslog_options = 0;
 
 void closelog() {
@@ -83,7 +84,7 @@
   int n = vsnprintf(log_line, sizeof(log_line), fmt, args);
   if (n < 0) return;
 
-  async_safe_format_log(android_log_priority, log_tag, "%s", log_line);
+  async_safe_write_log(android_log_priority, log_tag, log_line);
   if ((syslog_options & LOG_PERROR) != 0) {
     bool have_newline =
         (n > 0 && n < static_cast<int>(sizeof(log_line)) && log_line[n - 1] == '\n');
diff --git a/libc/bionic/sysprop_helpers.cpp b/libc/bionic/sysprop_helpers.cpp
index 5627034..e025edd 100644
--- a/libc/bionic/sysprop_helpers.cpp
+++ b/libc/bionic/sysprop_helpers.cpp
@@ -32,10 +32,15 @@
 #include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
-#include "sys/system_properties.h"
+#include <sys/system_properties.h>
+
+#include <async_safe/CHECK.h>
 
 static bool get_property_value(const char* property_name, char* dest, size_t dest_size) {
-  assert(property_name && dest && dest_size != 0);
+  CHECK(property_name);
+  CHECK(dest);
+  CHECK(dest_size != 0);
+
   const prop_info* prop = __system_property_find(property_name);
   if (!prop) return false;
 
@@ -50,7 +55,7 @@
       prop,
       [](void* cookie, const char* /* name */, const char* value, uint32_t /* serial */) {
         auto* cb_cookie = reinterpret_cast<PropCbCookie*>(cookie);
-        strncpy(cb_cookie->dest, value, cb_cookie->size);
+        strlcpy(cb_cookie->dest, value, cb_cookie->size);
       },
       &cb_cookie);
   return *dest != '\0';
@@ -61,8 +66,7 @@
                                      size_t options_size) {
   const char* env = getenv(env_var_name);
   if (env && *env != '\0') {
-    strncpy(options, env, options_size);
-    options[options_size - 1] = '\0';  // Ensure null-termination.
+    strlcpy(options, env, options_size);
     return true;
   }
 
diff --git a/libc/bionic/thread_private.cpp b/libc/bionic/thread_private.cpp
deleted file mode 100644
index 94fb8bb..0000000
--- a/libc/bionic/thread_private.cpp
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <pthread.h>
-#include "private/thread_private.h"
-
-// Some simple glue used to make BSD code thread-safe.
-
-static pthread_mutex_t g_arc4_lock = PTHREAD_MUTEX_INITIALIZER;
-
-void _thread_arc4_lock() {
-  pthread_mutex_lock(&g_arc4_lock);
-}
-
-void _thread_arc4_unlock() {
-  pthread_mutex_unlock(&g_arc4_lock);
-}
diff --git a/libc/bionic/time.cpp b/libc/bionic/time.cpp
index 800395e..8d33888 100644
--- a/libc/bionic/time.cpp
+++ b/libc/bionic/time.cpp
@@ -28,6 +28,54 @@
 
 #include <time.h>
 
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+
+char* asctime(const tm* tm) {
+  static char buf[128];
+  return asctime_r(tm, buf);
+}
+
+char* asctime_r(const tm* tm, char* buf) {
+  if (tm == nullptr) {
+    errno = EINVAL;
+    return strcpy(buf, "??? ??? ?? ??:??:?? ????\n");
+  }
+
+  auto pick = [](unsigned n, unsigned max, const char* s) {
+    return (n < max) ? s + 3*n : "???";
+  };
+  const char* day = pick(tm->tm_wday, 7, "SunMonTueWedThuFriSat");
+  const char* mon = pick(tm->tm_mon, 12, "JanFebMarAprMayJunJulAugSepOctNovDec");
+
+  // This format string is specified by ISO C.
+  char tmp_buf[26];
+  int n = snprintf(tmp_buf, 26, "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n", day, mon,
+                   tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, 1900 + tm->tm_year);
+  if (n > 25) {
+    errno = EOVERFLOW;
+    return nullptr;
+  }
+  strcpy(buf, tmp_buf);
+  return buf;
+}
+
+char* ctime(const time_t* tp) {
+  static char buf[128];
+  return ctime_r(tp, buf);
+}
+
+char* ctime_r(const time_t* tp, char* buf) {
+  struct tm tm;
+  if (localtime_r(tp, &tm) == nullptr) return nullptr;
+  return asctime_r(&tm, buf);
+}
+
+double difftime(time_t t1, time_t t0) {
+  return t1 - t0;
+}
+
 int timespec_get(timespec* ts, int base) {
   return (clock_gettime(base - 1, ts) != -1) ? base : 0;
 }
diff --git a/libc/bionic/wmempcpy.cpp b/libc/bionic/utime.cpp
similarity index 77%
copy from libc/bionic/wmempcpy.cpp
copy to libc/bionic/utime.cpp
index 54ebf86..95079d1 100644
--- a/libc/bionic/wmempcpy.cpp
+++ b/libc/bionic/utime.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015 The Android Open Source Project
+ * Copyright (C) 2025 The Android Open Source Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -26,8 +26,14 @@
  * SUCH DAMAGE.
  */
 
-#include <wchar.h>
+#include <utime.h>
 
-wchar_t* wmempcpy(wchar_t* dst, const wchar_t* src, size_t n) {
-  return wmemcpy(dst, src, n) + n;
+#include <fcntl.h>
+#include <sys/stat.h>
+
+int utime(const char* _Nonnull path, const struct utimbuf* _Nullable times) {
+  if (times == nullptr) return utimensat(AT_FDCWD, path, nullptr, 0);
+
+  timespec ts[2] = { {.tv_sec = times->actime}, {.tv_sec = times->modtime} };
+  return utimensat(AT_FDCWD, path, ts, 0);
 }
diff --git a/libc/bionic/vdso.cpp b/libc/bionic/vdso.cpp
index 0a9a9e5..1b5b13f 100644
--- a/libc/bionic/vdso.cpp
+++ b/libc/bionic/vdso.cpp
@@ -83,12 +83,12 @@
 }
 
 #if defined(__riscv)
-int __riscv_hwprobe(struct riscv_hwprobe* _Nonnull pairs, size_t pair_count, size_t cpu_count,
-                    unsigned long* _Nullable cpus, unsigned flags) {
+int __riscv_hwprobe(struct riscv_hwprobe* _Nonnull pairs, size_t pair_count, size_t cpu_set_size,
+                    cpu_set_t* _Nullable cpu_set, unsigned flags) {
   auto vdso_riscv_hwprobe =
       reinterpret_cast<decltype(&__riscv_hwprobe)>(__libc_globals->vdso[VDSO_RISCV_HWPROBE].fn);
   if (__predict_true(vdso_riscv_hwprobe)) {
-    return -vdso_riscv_hwprobe(pairs, pair_count, cpu_count, cpus, flags);
+    return -vdso_riscv_hwprobe(pairs, pair_count, cpu_set_size, cpu_set, flags);
   }
   // Inline the syscall directly in case someone's calling it from an
   // ifunc resolver where we won't be able to set errno on failure.
@@ -97,8 +97,8 @@
   // is to return an error value rather than setting errno.)
   register long a0 __asm__("a0") = reinterpret_cast<long>(pairs);
   register long a1 __asm__("a1") = pair_count;
-  register long a2 __asm__("a2") = cpu_count;
-  register long a3 __asm__("a3") = reinterpret_cast<long>(cpus);
+  register long a2 __asm__("a2") = cpu_set_size;
+  register long a3 __asm__("a3") = reinterpret_cast<long>(cpu_set);
   register long a4 __asm__("a4") = flags;
   register long a7 __asm__("a7") = __NR_riscv_hwprobe;
   __asm__ volatile("ecall" : "=r"(a0) : "r"(a0), "r"(a1), "r"(a2), "r"(a3), "r"(a4), "r"(a7));
diff --git a/libc/bionic/wchar_l.cpp b/libc/bionic/wchar_l.cpp
index b2c4a00..503d264 100644
--- a/libc/bionic/wchar_l.cpp
+++ b/libc/bionic/wchar_l.cpp
@@ -29,18 +29,12 @@
 #include <wchar.h>
 #include <xlocale.h>
 
-int wcscasecmp_l(const wchar_t* ws1, const wchar_t* ws2, locale_t) {
-  return wcscasecmp(ws1, ws2);
+int wcscoll(const wchar_t* lhs, const wchar_t* rhs) {
+  return wcscmp(lhs, rhs);
 }
+__strong_alias(wcscoll_l, wcscoll);
 
-int wcsncasecmp_l(const wchar_t* ws1, const wchar_t* ws2, size_t n, locale_t) {
-  return wcsncasecmp(ws1, ws2, n);
+size_t wcsxfrm(wchar_t* dst, const wchar_t* src, size_t n) {
+  return wcslcpy(dst, src, n);
 }
-
-int wcscoll_l(const wchar_t* ws1, const wchar_t* ws2, locale_t) {
-  return wcscoll(ws1, ws2);
-}
-
-size_t wcsxfrm_l(wchar_t* dst, const wchar_t* src, size_t n, locale_t) {
-  return wcsxfrm(dst, src, n);
-}
+__strong_alias(wcsxfrm_l, wcsxfrm);
diff --git a/libc/bionic/wcstod.cpp b/libc/bionic/wcstod.cpp
index 00c8a08..4256677 100644
--- a/libc/bionic/wcstod.cpp
+++ b/libc/bionic/wcstod.cpp
@@ -53,14 +53,13 @@
   ascii_str[max_len] = 0;
 
   // Set up a fake FILE that points to those ASCII characters, for `parsefloat`.
-  FILE f;
-  __sfileext fext;
+  FILE f = {};
+  __sfileext fext = {};
   _FILEEXT_SETUP(&f, &fext);
   f._flags = __SRD;
   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 = nullptr;
 
   // Ask `parsefloat` to look at the same data more carefully.
 
diff --git a/libc/bionic/wcwidth.cpp b/libc/bionic/wcwidth.cpp
index 633d83e..38e76fb 100644
--- a/libc/bionic/wcwidth.cpp
+++ b/libc/bionic/wcwidth.cpp
@@ -96,3 +96,12 @@
 
   return 0;
 }
+
+int wcswidth(const wchar_t* wcs, size_t n) {
+  int result = 0, width;
+  for (size_t i = 0; i < n && wcs[i] != L'\0'; ++i) {
+    if ((width = wcwidth(wcs[i])) == -1) return -1;
+    result += width;
+  }
+  return result;
+}
diff --git a/libc/dns/nameser/ns_print.c b/libc/dns/nameser/ns_print.c
index 32c8715..ec2ed4a 100644
--- a/libc/dns/nameser/ns_print.c
+++ b/libc/dns/nameser/ns_print.c
@@ -466,11 +466,7 @@
 			goto formerr;
 
 		/* Key flags, Protocol, Algorithm. */
-#ifndef _LIBC
-		key_id = dst_s_dns_key_id(rdata, edata-rdata);
-#else
 		key_id = 0;
-#endif
 		keyflags = ns_get16(rdata);  rdata += NS_INT16SZ;
 		protocol = *rdata++;
 		algorithm = *rdata++;
diff --git a/libc/dns/nameser/ns_samedomain.c b/libc/dns/nameser/ns_samedomain.c
index 0be0c28..dd8602c 100644
--- a/libc/dns/nameser/ns_samedomain.c
+++ b/libc/dns/nameser/ns_samedomain.c
@@ -154,7 +154,6 @@
 }
 #endif
 
-#ifdef _LIBC
 /*
  *	make a canonical copy of domain name "src"
  *
@@ -207,4 +206,3 @@
 	else
 		return (0);
 }
-#endif
diff --git a/libc/dns/nameser/ns_ttl.c b/libc/dns/nameser/ns_ttl.c
index de073b8..9b7e7d2 100644
--- a/libc/dns/nameser/ns_ttl.c
+++ b/libc/dns/nameser/ns_ttl.c
@@ -92,58 +92,6 @@
 	return (int)(dst - odst);
 }
 
-#ifndef _LIBC
-int
-ns_parse_ttl(const char *src, u_long *dst) {
-	u_long ttl, tmp;
-	int ch, digits, dirty;
-
-	ttl = 0;
-	tmp = 0;
-	digits = 0;
-	dirty = 0;
-	while ((ch = *src++) != '\0') {
-		if (!isascii(ch) || !isprint(ch))
-			goto einval;
-		if (isdigit(ch)) {
-			tmp *= 10;
-			tmp += (ch - '0');
-			digits++;
-			continue;
-		}
-		if (digits == 0)
-			goto einval;
-		if (islower(ch))
-			ch = toupper(ch);
-		switch (ch) {
-		case 'W':  tmp *= 7;	/*FALLTHROUGH*/
-		case 'D':  tmp *= 24;	/*FALLTHROUGH*/
-		case 'H':  tmp *= 60;	/*FALLTHROUGH*/
-		case 'M':  tmp *= 60;	/*FALLTHROUGH*/
-		case 'S':  break;
-		default:   goto einval;
-		}
-		ttl += tmp;
-		tmp = 0;
-		digits = 0;
-		dirty = 1;
-	}
-	if (digits > 0) {
-		if (dirty)
-			goto einval;
-		else
-			ttl += tmp;
-	} else if (!dirty)
-		goto einval;
-	*dst = ttl;
-	return (0);
-
- einval:
-	errno = EINVAL;
-	return (-1);
-}
-#endif
-
 /* Private. */
 
 static int
diff --git a/libc/dns/resolv/res_debug.c b/libc/dns/resolv/res_debug.c
index 4fe7553..c09fd37 100644
--- a/libc/dns/resolv/res_debug.c
+++ b/libc/dns/resolv/res_debug.c
@@ -147,22 +147,6 @@
   "ZONEREF",
 };
 
-#ifndef _LIBC
-/*
- * Print the current options.
- */
-void
-fp_resstat(const res_state statp, FILE *file) {
-	u_long mask;
-
-	fprintf(file, ";; res options:");
-	for (mask = 1;  mask != 0U;  mask <<= 1)
-		if (statp->options & mask)
-			fprintf(file, " %s", p_option(mask));
-	putc('\n', file);
-}
-#endif
-
 static void
 do_section(const res_state statp,
 	   ns_msg *handle, ns_sect section,
diff --git a/libc/include/alloca.h b/libc/include/alloca.h
index 2786e2f..71cceae 100644
--- a/libc/include/alloca.h
+++ b/libc/include/alloca.h
@@ -35,6 +35,8 @@
 
 #include <sys/cdefs.h>
 
+__BEGIN_DECLS
+
 /**
  * [alloca(3)](https://man7.org/linux/man-pages/man3/alloca.3.html) allocates space on the stack.
  *
@@ -44,3 +46,5 @@
  * @return a pointer to the space on success, but has undefined behavior on failure.
  */
 #define alloca(size)   __builtin_alloca(size)
+
+__END_DECLS
diff --git a/libc/include/android/api-level.h b/libc/include/android/api-level.h
index 2a4f7df..b954731 100644
--- a/libc/include/android/api-level.h
+++ b/libc/include/android/api-level.h
@@ -162,16 +162,15 @@
 #define __ANDROID_API_V__ 35
 
 /* This file is included in <features.h>, and might be used from .S files. */
-#if !defined(__ASSEMBLY__)
+#if !defined(__ASSEMBLER__)
 
 /**
  * Returns the `targetSdkVersion` of the caller, or `__ANDROID_API_FUTURE__` if
  * there is no known target SDK version (for code not running in the context of
  * an app).
  *
- * The returned values correspond to the named constants in `<android/api-level.h>`,
- * and is equivalent to the AndroidManifest.xml `targetSdkVersion`.
- *
+ * The returned value is the same as the AndroidManifest.xml `targetSdkVersion`.
+ * This is mostly useful for the OS to decide what behavior an app is expecting.
  * See also android_get_device_api_level().
  *
  * Available since API level 24.
@@ -180,7 +179,6 @@
 int android_get_application_target_sdk_version() __INTRODUCED_IN(24);
 #endif /* __BIONIC_AVAILABILITY_GUARD(24) */
 
-
 #if __ANDROID_API__ < 29
 
 /* android_get_device_api_level is a static inline before API level 29. */
@@ -192,9 +190,10 @@
 
 /**
  * Returns the API level of the device we're actually running on, or -1 on failure.
- * The returned values correspond to the named constants in `<android/api-level.h>`,
- * and is equivalent to the Java `Build.VERSION.SDK_INT` API.
  *
+ * The returned value is the same as the Java `Build.VERSION.SDK_INT`.
+ * This is mostly useful for an app to work out what version of the OS it's
+ * running on.
  * See also android_get_application_target_sdk_version().
  *
  * Available since API level 29.
@@ -203,7 +202,7 @@
 
 #endif
 
-#endif /* defined(__ASSEMBLY__) */
+#endif /* defined(__ASSEMBLER__) */
 
 __END_DECLS
 
diff --git a/libc/include/android/crash_detail.h b/libc/include/android/crash_detail.h
index fd1312a..f8785af 100644
--- a/libc/include/android/crash_detail.h
+++ b/libc/include/android/crash_detail.h
@@ -80,10 +80,10 @@
  *
  * \return a handle to the extra crash detail.
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(35)
 crash_detail_t* _Nullable android_crash_detail_register(
     const void* _Nonnull name, size_t name_size, const void* _Nullable data, size_t data_size) __INTRODUCED_IN(35);
+    #endif /* __BIONIC_AVAILABILITY_GUARD(35) */
 
 /**
  * Unregister crash detail from being logged into tombstones.
@@ -95,7 +95,9 @@
  *
  * \param crash_detail the crash_detail that should be removed.
  */
+#if __BIONIC_AVAILABILITY_GUARD(35)
 void android_crash_detail_unregister(crash_detail_t* _Nonnull crash_detail) __INTRODUCED_IN(35);
+#endif /* __BIONIC_AVAILABILITY_GUARD(35) */
 
 /**
  * Replace data of crash detail.
@@ -110,7 +112,9 @@
  *             android_crash_detail_replace_data is called again with non-null data.
  * \param data_size the number of bytes of the buffer pointed to by data.
  */
+#if __BIONIC_AVAILABILITY_GUARD(35)
 void android_crash_detail_replace_data(crash_detail_t* _Nonnull crash_detail, const void* _Nullable data, size_t data_size) __INTRODUCED_IN(35);
+#endif /* __BIONIC_AVAILABILITY_GUARD(35) */
 
 /**
  * Replace name of crash detail.
@@ -124,8 +128,8 @@
  * \param name identifying name for this extra data.
  * \param name_size number of bytes of the buffer pointed to by name
  */
+#if __BIONIC_AVAILABILITY_GUARD(35)
 void android_crash_detail_replace_name(crash_detail_t* _Nonnull crash_detail, const void* _Nonnull name, size_t name_size) __INTRODUCED_IN(35);
 #endif /* __BIONIC_AVAILABILITY_GUARD(35) */
 
-
 __END_DECLS
diff --git a/libc/include/android/fdsan.h b/libc/include/android/fdsan.h
index a04fc7e..b9090ba 100644
--- a/libc/include/android/fdsan.h
+++ b/libc/include/android/fdsan.h
@@ -135,45 +135,53 @@
 /*
  * Create an owner tag with the specified type and least significant 56 bits of tag.
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(29)
 uint64_t android_fdsan_create_owner_tag(enum android_fdsan_owner_type type, uint64_t tag) __INTRODUCED_IN(29) __attribute__((__weak__));
+#endif /* __BIONIC_AVAILABILITY_GUARD(29) */
 
 /*
  * Exchange a file descriptor's tag.
  *
  * Logs and aborts if the fd's tag does not match expected_tag.
  */
+#if __BIONIC_AVAILABILITY_GUARD(29)
 void android_fdsan_exchange_owner_tag(int fd, uint64_t expected_tag, uint64_t new_tag) __INTRODUCED_IN(29) __attribute__((__weak__));
+#endif /* __BIONIC_AVAILABILITY_GUARD(29) */
 
 /*
  * Close a file descriptor with a tag, and resets the tag to 0.
  *
  * Logs and aborts if the tag is incorrect.
  */
+#if __BIONIC_AVAILABILITY_GUARD(29)
 int android_fdsan_close_with_tag(int fd, uint64_t tag) __INTRODUCED_IN(29) __attribute__((__weak__));
+#endif /* __BIONIC_AVAILABILITY_GUARD(29) */
 
 /*
  * Get a file descriptor's current owner tag.
  *
  * Returns 0 for untagged and invalid file descriptors.
  */
+#if __BIONIC_AVAILABILITY_GUARD(29)
 uint64_t android_fdsan_get_owner_tag(int fd) __INTRODUCED_IN(29);
+#endif /* __BIONIC_AVAILABILITY_GUARD(29) */
 
 /*
  * Get an owner tag's string representation.
  *
  * The return value points to memory with static lifetime, do not attempt to modify it.
  */
+#if __BIONIC_AVAILABILITY_GUARD(29)
 const char* _Nonnull android_fdsan_get_tag_type(uint64_t tag) __INTRODUCED_IN(29);
+#endif /* __BIONIC_AVAILABILITY_GUARD(29) */
 
 /*
  * Get an owner tag's value, with the type masked off.
  */
+#if __BIONIC_AVAILABILITY_GUARD(29)
 uint64_t android_fdsan_get_tag_value(uint64_t tag) __INTRODUCED_IN(29);
 #endif /* __BIONIC_AVAILABILITY_GUARD(29) */
 
-
 enum android_fdsan_error_level {
   // No errors.
   ANDROID_FDSAN_ERROR_LEVEL_DISABLED,
diff --git a/libc/include/ar.h b/libc/include/ar.h
index e79fa49..f2daa3b 100644
--- a/libc/include/ar.h
+++ b/libc/include/ar.h
@@ -46,6 +46,8 @@
 
 #include <sys/cdefs.h>
 
+__BEGIN_DECLS
+
 /** The magic at the beginning of a `.a` file. */
 #define ARMAG  "!<arch>\n"
 /** The length of the magic at the beginning of a `.a` file. */
@@ -70,3 +72,5 @@
   /** Consistency check. Always contains `ARFMAG`. */
   char ar_fmag[2];
 };
+
+__END_DECLS
diff --git a/libc/include/arpa/ftp.h b/libc/include/arpa/ftp.h
index fecbf7f..c39bc51 100644
--- a/libc/include/arpa/ftp.h
+++ b/libc/include/arpa/ftp.h
@@ -36,6 +36,8 @@
 
 #include <sys/cdefs.h>
 
+__BEGIN_DECLS
+
 /* Definitions for FTP; see RFC-765. */
 
 /*
@@ -106,4 +108,6 @@
 
 #define	BLK_BYTECOUNT	2	/* Bytes in this block */
 
+__END_DECLS
+
 #endif /* !_FTP_H_ */
diff --git a/libc/include/arpa/inet.h b/libc/include/arpa/inet.h
index ce9dd93..246b438 100644
--- a/libc/include/arpa/inet.h
+++ b/libc/include/arpa/inet.h
@@ -31,6 +31,7 @@
 
 #include <sys/cdefs.h>
 
+#include <endian.h>
 #include <netinet/in.h>
 #include <stdint.h>
 #include <sys/types.h>
diff --git a/libc/include/arpa/nameser.h b/libc/include/arpa/nameser.h
index 3e0025e..e7742a3 100644
--- a/libc/include/arpa/nameser.h
+++ b/libc/include/arpa/nameser.h
@@ -59,6 +59,8 @@
 
 #include <sys/types.h>
 
+__BEGIN_DECLS
+
 /*
  * Revision information.  This is the release date in YYYYMMDD format.
  * It can change every day so the right thing to do with it is use it
@@ -520,8 +522,6 @@
 	(cp) += NS_INT32SZ; \
 } while (/*CONSTCOND*/0)
 
-__BEGIN_DECLS
-
 #if !defined(__LP64__)
 /* Annoyingly, LP32 shipped with __ names. */
 #define ns_format_ttl __ns_format_ttl
diff --git a/libc/include/arpa/nameser_compat.h b/libc/include/arpa/nameser_compat.h
index 027e5ca..b0812ac 100644
--- a/libc/include/arpa/nameser_compat.h
+++ b/libc/include/arpa/nameser_compat.h
@@ -44,6 +44,8 @@
 
 #include <endian.h>
 
+__BEGIN_DECLS
+
 #define	__BIND		19950621	/* (DEAD) interface version stamp. */
 
 /*
@@ -174,4 +176,6 @@
 #define	PUTSHORT		NS_PUT16
 #define	PUTLONG			NS_PUT32
 
+__END_DECLS
+
 #endif /* _ARPA_NAMESER_COMPAT_ */
diff --git a/libc/include/arpa/telnet.h b/libc/include/arpa/telnet.h
index 30d8f21..043cd2d 100644
--- a/libc/include/arpa/telnet.h
+++ b/libc/include/arpa/telnet.h
@@ -35,6 +35,8 @@
 
 #include <sys/cdefs.h>
 
+__BEGIN_DECLS
+
 /*
  * Definitions for the TELNET protocol.
  */
@@ -342,4 +344,6 @@
 #define	ENCTYPE_NAME_OK(x)	((unsigned int)(x) < ENCTYPE_CNT)
 #define	ENCTYPE_NAME(x)		enctype_names[x]
 
+__END_DECLS
+
 #endif /* !_TELNET_H_ */
diff --git a/libc/include/arpa/tftp.h b/libc/include/arpa/tftp.h
index 20733ec..d0586ee 100644
--- a/libc/include/arpa/tftp.h
+++ b/libc/include/arpa/tftp.h
@@ -35,6 +35,8 @@
 
 #include <sys/cdefs.h>
 
+__BEGIN_DECLS
+
 /*
  * Trivial File Transfer Protocol (IEN-133)
  */
@@ -78,4 +80,6 @@
 #define	ENOUSER		7		/* no such user */
 #define	EOPTNEG		8		/* option negotiation failed */
 
+__END_DECLS
+
 #endif /* !_TFTP_H_ */
diff --git a/libc/include/bits/auxvec.h b/libc/include/bits/auxvec.h
index 2d6522a..7531100 100644
--- a/libc/include/bits/auxvec.h
+++ b/libc/include/bits/auxvec.h
@@ -45,6 +45,8 @@
 #include <asm/hwcap2.h>
 #endif
 
+__BEGIN_DECLS
+
 /** Historical SuperH cruft. Irrelevant on Android. */
 #define AT_FPUCW 18
 /** Historical PowerPC cruft. Irrelevant on Android. */
@@ -55,3 +57,5 @@
 #define AT_UCACHEBSIZE 21
 /** Historical PowerPC cruft. Irrelevant on Android. */
 #define AT_IGNOREPPC 22
+
+__END_DECLS
diff --git a/libc/include/bits/epoll_event.h b/libc/include/bits/epoll_event.h
index b2b4c87..5cd204b 100644
--- a/libc/include/bits/epoll_event.h
+++ b/libc/include/bits/epoll_event.h
@@ -36,6 +36,8 @@
 #include <sys/cdefs.h>
 #include <stdint.h>
 
+__BEGIN_DECLS
+
 /** The union of possible data types for an `epoll_event`. */
 typedef union epoll_data {
   void* ptr;
@@ -53,3 +55,5 @@
 __packed
 #endif
 ;
+
+__END_DECLS
diff --git a/libc/include/bits/fortify/fcntl.h b/libc/include/bits/fortify/fcntl.h
index 05c62eb..61386a8 100644
--- a/libc/include/bits/fortify/fcntl.h
+++ b/libc/include/bits/fortify/fcntl.h
@@ -47,7 +47,7 @@
 
 __BIONIC_ERROR_FUNCTION_VISIBILITY
 int open(const char* _Nonnull pathname, int flags, mode_t modes, ...) __overloadable
-        __errorattr(__open_too_many_args_error);
+        __clang_error_if(1, __open_too_many_args_error);
 
 /*
  * pass_object_size serves two purposes here, neither of which involve __bos: it
@@ -77,7 +77,7 @@
 __BIONIC_ERROR_FUNCTION_VISIBILITY
 int openat(int dirfd, const char* _Nonnull pathname, int flags, mode_t modes, ...)
         __overloadable
-        __errorattr(__open_too_many_args_error);
+        __clang_error_if(1, __open_too_many_args_error);
 
 __BIONIC_FORTIFY_INLINE
 int openat(int dirfd, const char* _Nonnull const __pass_object_size pathname, int flags)
@@ -102,7 +102,7 @@
 
 __BIONIC_ERROR_FUNCTION_VISIBILITY
 int open64(const char* _Nonnull pathname, int flags, mode_t modes, ...) __overloadable
-        __errorattr(__open_too_many_args_error);
+        __clang_error_if(1, __open_too_many_args_error);
 
 __BIONIC_FORTIFY_INLINE
 int open64(const char* _Nonnull const __pass_object_size pathname, int flags)
@@ -122,7 +122,7 @@
 __BIONIC_ERROR_FUNCTION_VISIBILITY
 int openat64(int dirfd, const char* _Nonnull pathname, int flags, mode_t modes, ...)
         __overloadable
-        __errorattr(__open_too_many_args_error);
+        __clang_error_if(1, __open_too_many_args_error);
 
 __BIONIC_FORTIFY_INLINE
 int openat64(int dirfd, const char* _Nonnull const __pass_object_size pathname, int flags)
diff --git a/libc/include/bits/fortify/poll.h b/libc/include/bits/fortify/poll.h
index 1b4a5bf..94158f0 100644
--- a/libc/include/bits/fortify/poll.h
+++ b/libc/include/bits/fortify/poll.h
@@ -30,18 +30,18 @@
 #error "Never include this file directly; instead, include <poll.h>"
 #endif
 
-
 #if __BIONIC_AVAILABILITY_GUARD(23)
 int __poll_chk(struct pollfd* _Nullable, nfds_t, int, size_t) __INTRODUCED_IN(23);
-int __ppoll_chk(struct pollfd* _Nullable, nfds_t, const struct timespec* _Nullable, const sigset_t* _Nullable, size_t) __INTRODUCED_IN(23);
 #endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
+#if __BIONIC_AVAILABILITY_GUARD(23)
+int __ppoll_chk(struct pollfd* _Nullable, nfds_t, const struct timespec* _Nullable, const sigset_t* _Nullable, size_t) __INTRODUCED_IN(23);
+#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
 #if __BIONIC_AVAILABILITY_GUARD(28)
 int __ppoll64_chk(struct pollfd* _Nullable, nfds_t, const struct timespec* _Nullable, const sigset64_t* _Nullable, size_t) __INTRODUCED_IN(28);
 #endif /* __BIONIC_AVAILABILITY_GUARD(28) */
 
-
 #if defined(__BIONIC_FORTIFY)
 #define __bos_fd_count_trivially_safe(bos_val, fds, fd_count)              \
   __bos_dynamic_check_impl_and((bos_val), >=, (sizeof(*fds) * (fd_count)), \
diff --git a/libc/include/bits/fortify/socket.h b/libc/include/bits/fortify/socket.h
index bd626f9..a582a37 100644
--- a/libc/include/bits/fortify/socket.h
+++ b/libc/include/bits/fortify/socket.h
@@ -30,7 +30,6 @@
 #error "Never include this file directly; instead, include <sys/socket.h>"
 #endif
 
-
 #if __BIONIC_AVAILABILITY_GUARD(26)
 ssize_t __sendto_chk(int, const void* _Nonnull, size_t, size_t, int, const struct sockaddr* _Nullable, socklen_t) __INTRODUCED_IN(26);
 #endif /* __BIONIC_AVAILABILITY_GUARD(26) */
diff --git a/libc/include/bits/fortify/stdio.h b/libc/include/bits/fortify/stdio.h
index f9faeba..f7f2b1d 100644
--- a/libc/include/bits/fortify/stdio.h
+++ b/libc/include/bits/fortify/stdio.h
@@ -34,9 +34,11 @@
 
 #if __BIONIC_AVAILABILITY_GUARD(24)
 size_t __fread_chk(void* _Nonnull, size_t, size_t, FILE* _Nonnull, size_t) __INTRODUCED_IN(24);
-size_t __fwrite_chk(const void* _Nonnull, size_t, size_t, FILE* _Nonnull, size_t) __INTRODUCED_IN(24);
 #endif /* __BIONIC_AVAILABILITY_GUARD(24) */
 
+#if __BIONIC_AVAILABILITY_GUARD(24)
+size_t __fwrite_chk(const void* _Nonnull, size_t, size_t, FILE* _Nonnull, size_t) __INTRODUCED_IN(24);
+#endif /* __BIONIC_AVAILABILITY_GUARD(24) */
 
 #if defined(__BIONIC_FORTIFY) && !defined(__BIONIC_NO_STDIO_FORTIFY)
 
@@ -60,7 +62,7 @@
     __overloadable
     __enable_if(__bos_unevaluated_lt(__bos(dest), __builtin_strlen(format)),
                 "format string will always overflow destination buffer")
-    __errorattr("format string will always overflow destination buffer");
+    __clang_error_if(1, "format string will always overflow destination buffer");
 
 #if __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
 __BIONIC_FORTIFY_VARIADIC __printflike(2, 3)
@@ -85,14 +87,17 @@
 }
 #endif
 
+/* __builtin_mul_overflow cannot be used in static_assert or constexpr contexts. */
+#define __would_mul_overflow(x, y) ((__SIZE_TYPE__)-1 / (x) < (y))
+
 #define __bos_trivially_ge_mul(bos_val, size, count) \
   __bos_dynamic_check_impl_and(bos_val, >=, (size) * (count), \
-                               !__unsafe_check_mul_overflow(size, count))
+                               !__would_mul_overflow(size, count))
 
 __BIONIC_FORTIFY_INLINE
 size_t fread(void* const _Nonnull __pass_object_size0 buf, size_t size, size_t count, FILE* _Nonnull stream)
         __overloadable
-        __clang_error_if(__unsafe_check_mul_overflow(size, count),
+        __clang_error_if(__would_mul_overflow(size, count),
                          "in call to 'fread', size * count overflows")
         __clang_error_if(__bos_unevaluated_lt(__bos0(buf), size * count),
                          "in call to 'fread', size * count is too large for the given buffer") {
@@ -109,7 +114,7 @@
 __BIONIC_FORTIFY_INLINE
 size_t fwrite(const void* const _Nonnull __pass_object_size0 buf, size_t size, size_t count, FILE* _Nonnull stream)
         __overloadable
-        __clang_error_if(__unsafe_check_mul_overflow(size, count),
+        __clang_error_if(__would_mul_overflow(size, count),
                          "in call to 'fwrite', size * count overflows")
         __clang_error_if(__bos_unevaluated_lt(__bos0(buf), size * count),
                          "in call to 'fwrite', size * count is too large for the given buffer") {
@@ -122,6 +127,8 @@
 #endif
     return __call_bypassing_fortify(fwrite)(buf, size, count, stream);
 }
+
+#undef __would_mul_overflow
 #undef __bos_trivially_ge_mul
 
 __BIONIC_FORTIFY_INLINE
diff --git a/libc/include/bits/fortify/string.h b/libc/include/bits/fortify/string.h
index 15cb17d..cdad2e7 100644
--- a/libc/include/bits/fortify/string.h
+++ b/libc/include/bits/fortify/string.h
@@ -30,9 +30,11 @@
 #error "Never include this file directly; instead, include <string.h>"
 #endif
 
-
 #if __BIONIC_AVAILABILITY_GUARD(23)
 void* _Nullable __memchr_chk(const void* _Nonnull, int, size_t, size_t) __INTRODUCED_IN(23);
+#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
+
+#if __BIONIC_AVAILABILITY_GUARD(23)
 void* _Nullable __memrchr_chk(const void* _Nonnull, int, size_t, size_t) __INTRODUCED_IN(23);
 #endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
@@ -71,7 +73,7 @@
         __diagnose_as_builtin(__builtin_memset, 1, 2, 3)
         __overloadable
         /* If you're a user who wants this warning to go away: use `(&memset)(foo, bar, baz)`. */
-        __clang_warning_if(c && !n, "'memset' will set 0 bytes; maybe the arguments got flipped?") {
+        __clang_warning_if(!n, "'memset' will set 0 bytes; maybe the arguments got flipped?") {
 /* hwasan intercepts memset() but not the _chk variant. */
 #if __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED && !__has_feature(hwaddress_sanitizer)
     return __builtin___memset_chk(s, c, n, __bos0(s));
@@ -80,14 +82,11 @@
 #endif
 }
 
-#if defined(__USE_GNU)
-#if __ANDROID_API__ >= 30
+#if defined(__USE_GNU) && __ANDROID_API__ >= 30
 __BIONIC_FORTIFY_INLINE
 void* _Nonnull mempcpy(void* _Nonnull const dst __pass_object_size0, const void* _Nonnull src, size_t copy_amount)
         __diagnose_as_builtin(__builtin_mempcpy, 1, 2, 3)
-        __overloadable
-        __clang_error_if(__bos_unevaluated_lt(__bos0(dst), copy_amount),
-                         "'mempcpy' called with size bigger than buffer") {
+        __overloadable {
 #if __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
     size_t bos_dst = __bos0(dst);
     if (!__bos_trivially_ge(bos_dst, copy_amount)) {
@@ -96,8 +95,7 @@
 #endif
     return __builtin_mempcpy(dst, src, copy_amount);
 }
-#endif /* __ANDROID_API__ >= 30 */
-#endif /* __USE_GNU */
+#endif
 
 __BIONIC_FORTIFY_INLINE
 char* _Nonnull stpcpy(char* _Nonnull const dst __pass_object_size, const char* _Nonnull src)
@@ -114,9 +112,7 @@
 __BIONIC_FORTIFY_INLINE
 char* _Nonnull strcpy(char* _Nonnull const dst __pass_object_size, const char* _Nonnull src)
         __diagnose_as_builtin(__builtin_strcpy, 1, 2)
-        __overloadable
-        __clang_error_if(__bos_unevaluated_le(__bos(dst), __builtin_strlen(src)),
-                         "'strcpy' called with string bigger than buffer") {
+        __overloadable {
 #if __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
     return __builtin___strcpy_chk(dst, src, __bos(dst));
 #else
diff --git a/libc/include/bits/fortify/unistd.h b/libc/include/bits/fortify/unistd.h
index 9acb942..a863208 100644
--- a/libc/include/bits/fortify/unistd.h
+++ b/libc/include/bits/fortify/unistd.h
@@ -29,34 +29,28 @@
 #error "Never include this file directly; instead, include <unistd.h>"
 #endif
 
-
 #if __BIONIC_AVAILABILITY_GUARD(24)
 char* _Nullable __getcwd_chk(char* _Nullable, size_t, size_t) __INTRODUCED_IN(24);
 #endif /* __BIONIC_AVAILABILITY_GUARD(24) */
 
-
-
 #if __BIONIC_AVAILABILITY_GUARD(23)
 ssize_t __pread_chk(int, void* _Nonnull, size_t, off_t, size_t) __INTRODUCED_IN(23);
 #endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
 ssize_t __pread_real(int, void* _Nonnull, size_t, off_t) __RENAME(pread);
 
-
 #if __BIONIC_AVAILABILITY_GUARD(23)
 ssize_t __pread64_chk(int, void* _Nonnull, size_t, off64_t, size_t) __INTRODUCED_IN(23);
 #endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
 ssize_t __pread64_real(int, void* _Nonnull, size_t, off64_t) __RENAME(pread64);
 
-
 #if __BIONIC_AVAILABILITY_GUARD(24)
 ssize_t __pwrite_chk(int, const void* _Nonnull, size_t, off_t, size_t) __INTRODUCED_IN(24);
 #endif /* __BIONIC_AVAILABILITY_GUARD(24) */
 
 ssize_t __pwrite_real(int, const void* _Nonnull, size_t, off_t) __RENAME(pwrite);
 
-
 #if __BIONIC_AVAILABILITY_GUARD(24)
 ssize_t __pwrite64_chk(int, const void* _Nonnull, size_t, off64_t, size_t) __INTRODUCED_IN(24);
 #endif /* __BIONIC_AVAILABILITY_GUARD(24) */
@@ -69,12 +63,13 @@
 ssize_t __write_chk(int, const void* __BIONIC_COMPLICATED_NULLNESS, size_t, size_t) __INTRODUCED_IN(24);
 #endif /* __BIONIC_AVAILABILITY_GUARD(24) */
 
-
 #if __BIONIC_AVAILABILITY_GUARD(23)
 ssize_t __readlink_chk(const char* _Nonnull, char* _Nonnull, size_t, size_t) __INTRODUCED_IN(23);
-ssize_t __readlinkat_chk(int dirfd, const char* _Nonnull, char* _Nonnull, size_t, size_t) __INTRODUCED_IN(23);
 #endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
+#if __BIONIC_AVAILABILITY_GUARD(23)
+ssize_t __readlinkat_chk(int dirfd, const char* _Nonnull, char* _Nonnull, size_t, size_t) __INTRODUCED_IN(23);
+#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
 #if defined(__BIONIC_FORTIFY)
 
diff --git a/libc/include/bits/getentropy.h b/libc/include/bits/getentropy.h
index c878470..c1d9d7c 100644
--- a/libc/include/bits/getentropy.h
+++ b/libc/include/bits/getentropy.h
@@ -48,10 +48,8 @@
  *
  * See also arc4random_buf() which is available in all API levels.
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(28)
 __nodiscard int getentropy(void* _Nonnull __buffer, size_t __buffer_size) __INTRODUCED_IN(28);
 #endif /* __BIONIC_AVAILABILITY_GUARD(28) */
 
-
 __END_DECLS
diff --git a/libc/include/bits/glibc-syscalls.h b/libc/include/bits/glibc-syscalls.h
index 8c5a91d..6eeaaf5 100644
--- a/libc/include/bits/glibc-syscalls.h
+++ b/libc/include/bits/glibc-syscalls.h
@@ -438,6 +438,9 @@
 #if defined(__NR_getxattr)
   #define SYS_getxattr __NR_getxattr
 #endif
+#if defined(__NR_getxattrat)
+  #define SYS_getxattrat __NR_getxattrat
+#endif
 #if defined(__NR_gtty)
   #define SYS_gtty __NR_gtty
 #endif
@@ -555,6 +558,9 @@
 #if defined(__NR_listxattr)
   #define SYS_listxattr __NR_listxattr
 #endif
+#if defined(__NR_listxattrat)
+  #define SYS_listxattrat __NR_listxattrat
+#endif
 #if defined(__NR_llistxattr)
   #define SYS_llistxattr __NR_llistxattr
 #endif
@@ -756,6 +762,9 @@
 #if defined(__NR_open_tree)
   #define SYS_open_tree __NR_open_tree
 #endif
+#if defined(__NR_open_tree_attr)
+  #define SYS_open_tree_attr __NR_open_tree_attr
+#endif
 #if defined(__NR_openat)
   #define SYS_openat __NR_openat
 #endif
@@ -921,6 +930,9 @@
 #if defined(__NR_removexattr)
   #define SYS_removexattr __NR_removexattr
 #endif
+#if defined(__NR_removexattrat)
+  #define SYS_removexattrat __NR_removexattrat
+#endif
 #if defined(__NR_rename)
   #define SYS_rename __NR_rename
 #endif
@@ -1158,6 +1170,9 @@
 #if defined(__NR_setxattr)
   #define SYS_setxattr __NR_setxattr
 #endif
+#if defined(__NR_setxattrat)
+  #define SYS_setxattrat __NR_setxattrat
+#endif
 #if defined(__NR_sgetmask)
   #define SYS_sgetmask __NR_sgetmask
 #endif
diff --git a/libc/include/bits/in_addr.h b/libc/include/bits/in_addr.h
index 30eb04b..7a68c9b 100644
--- a/libc/include/bits/in_addr.h
+++ b/libc/include/bits/in_addr.h
@@ -36,6 +36,8 @@
 #include <sys/cdefs.h>
 #include <stdint.h>
 
+__BEGIN_DECLS
+
 /** An integral type representing an IPv4 address. */
 typedef uint32_t in_addr_t;
 
@@ -43,3 +45,5 @@
 struct in_addr {
   in_addr_t s_addr;
 };
+
+__END_DECLS
diff --git a/libc/include/bits/ip_mreq_source.h b/libc/include/bits/ip_mreq_source.h
index 83490a4..5e5f2e9 100644
--- a/libc/include/bits/ip_mreq_source.h
+++ b/libc/include/bits/ip_mreq_source.h
@@ -36,6 +36,8 @@
 #include <sys/cdefs.h>
 #include <bits/in_addr.h>
 
+__BEGIN_DECLS
+
 /**
  * The type representing an IPv4 multicast source.
  */
@@ -44,3 +46,5 @@
   struct in_addr imr_interface;
   struct in_addr imr_sourceaddr;
 };
+
+__END_DECLS
diff --git a/libc/include/bits/ip_msfilter.h b/libc/include/bits/ip_msfilter.h
index cb3350b..11d7aae 100644
--- a/libc/include/bits/ip_msfilter.h
+++ b/libc/include/bits/ip_msfilter.h
@@ -36,6 +36,8 @@
 #include <sys/cdefs.h>
 #include <bits/in_addr.h>
 
+__BEGIN_DECLS
+
 /** The type representing an IPv4 multicast filter. */
 struct ip_msfilter {
   struct in_addr imsf_multiaddr;
@@ -44,3 +46,5 @@
   uint32_t imsf_numsrc;
   struct in_addr imsf_slist[1];
 };
+
+__END_DECLS
diff --git a/libc/include/bits/lockf.h b/libc/include/bits/lockf.h
index 8f922b9..a52d511 100644
--- a/libc/include/bits/lockf.h
+++ b/libc/include/bits/lockf.h
@@ -36,6 +36,8 @@
 #include <sys/cdefs.h>
 #include <sys/types.h>
 
+__BEGIN_DECLS
+
 /** lockf() command to unlock a section of a file. */
 #define F_ULOCK 0
 /** lockf() command to block until it locks a section of a file. */
@@ -45,8 +47,6 @@
 /** lockf() command to test whether a section of a file is unlocked (or locked by the caller). */
 #define F_TEST 3
 
-__BEGIN_DECLS
-
 /**
  * [lockf(3)](https://man7.org/linux/man-pages/man3/lockf.3.html) manipulates POSIX file locks.
  *
@@ -56,16 +56,16 @@
  *
  * See also flock().
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(24)
 int lockf(int __fd, int __op, off_t __length) __RENAME_IF_FILE_OFFSET64(lockf64) __INTRODUCED_IN(24);
+#endif /* __BIONIC_AVAILABILITY_GUARD(24) */
 
 /**
  * Like lockf() but allows using a 64-bit length
  * even from a 32-bit process without `_FILE_OFFSET_BITS=64`.
  */
+#if __BIONIC_AVAILABILITY_GUARD(24)
 int lockf64(int __fd, int __op, off64_t __length) __INTRODUCED_IN(24);
 #endif /* __BIONIC_AVAILABILITY_GUARD(24) */
 
-
 __END_DECLS
diff --git a/libc/include/bits/mbstate_t.h b/libc/include/bits/mbstate_t.h
index 0f9323d..8e407f9 100644
--- a/libc/include/bits/mbstate_t.h
+++ b/libc/include/bits/mbstate_t.h
@@ -35,6 +35,8 @@
 
 #include <sys/cdefs.h>
 
+__BEGIN_DECLS
+
 /**
  * An opaque type used by the multibyte conversion functions.
  * Do not make assumptions about the content of this type.
@@ -45,3 +47,5 @@
   unsigned char __reserved[4];
 #endif
 } mbstate_t;
+
+__END_DECLS
diff --git a/libc/bionic/wmempcpy.cpp b/libc/include/bits/memset_explicit_impl.h
similarity index 79%
copy from libc/bionic/wmempcpy.cpp
copy to libc/include/bits/memset_explicit_impl.h
index 54ebf86..9562f30 100644
--- a/libc/bionic/wmempcpy.cpp
+++ b/libc/include/bits/memset_explicit_impl.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015 The Android Open Source Project
+ * Copyright (C) 2025 The Android Open Source Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -26,8 +26,9 @@
  * SUCH DAMAGE.
  */
 
-#include <wchar.h>
-
-wchar_t* wmempcpy(wchar_t* dst, const wchar_t* src, size_t n) {
-  return wmemcpy(dst, src, n) + n;
+__BIONIC_MEMSET_EXPLICIT_INLINE void* _Nonnull memset_explicit(void* _Nonnull __dst, int __ch, size_t __n) {
+  void* __result = memset(__dst, __ch, __n);
+  // https://bugs.llvm.org/show_bug.cgi?id=15495
+  __asm__ __volatile__("" : : "r"(__dst) : "memory");
+  return __result;
 }
diff --git a/libc/include/bits/posix_limits.h b/libc/include/bits/posix_limits.h
index d98be27..e585116 100644
--- a/libc/include/bits/posix_limits.h
+++ b/libc/include/bits/posix_limits.h
@@ -31,6 +31,8 @@
 
 #include <sys/cdefs.h>
 
+__BEGIN_DECLS
+
 #define _POSIX_VERSION 200809L
 #define _POSIX2_VERSION _POSIX_VERSION
 #define _XOPEN_VERSION 700
@@ -177,4 +179,6 @@
 #define _XOPEN_NAME_MAX             255
 #define _XOPEN_PATH_MAX             1024
 
+__END_DECLS
+
 #endif
diff --git a/libc/include/bits/pthread_types.h b/libc/include/bits/pthread_types.h
index e30c4c1..11587a6 100644
--- a/libc/include/bits/pthread_types.h
+++ b/libc/include/bits/pthread_types.h
@@ -31,6 +31,8 @@
 #include <sys/cdefs.h>
 #include <sys/types.h>
 
+__BEGIN_DECLS
+
 typedef struct {
   uint32_t flags;
   void* stack_base;
@@ -96,3 +98,5 @@
 } pthread_spinlock_t;
 
 typedef long pthread_t;
+
+__END_DECLS
diff --git a/libc/include/bits/sa_family_t.h b/libc/include/bits/sa_family_t.h
index df8b695..117d583 100644
--- a/libc/include/bits/sa_family_t.h
+++ b/libc/include/bits/sa_family_t.h
@@ -35,5 +35,9 @@
 
 #include <sys/cdefs.h>
 
+__BEGIN_DECLS
+
 /** The type of fields like `sa_family`. */
 typedef unsigned short sa_family_t;
+
+__END_DECLS
diff --git a/libc/include/bits/seek_constants.h b/libc/include/bits/seek_constants.h
index a4fffb2..b9c665e 100644
--- a/libc/include/bits/seek_constants.h
+++ b/libc/include/bits/seek_constants.h
@@ -35,14 +35,28 @@
 
 #include <sys/cdefs.h>
 
-/** Seek to an absolute offset. */
-#define SEEK_SET 0
-/** Seek relative to the current offset. */
-#define SEEK_CUR 1
-/** Seek relative to the end of the file. */
-#define SEEK_END 2
+__BEGIN_DECLS
 
-#if defined(__USE_GNU)
+/**
+ * Seek to an absolute offset.
+ *
+ * See [lseek(2)](https://man7.org/linux/man-pages/man2/lseek.2.html).
+ */
+#define SEEK_SET 0
+
+/**
+ * Seek relative to the current offset.
+ *
+ * See [lseek(2)](https://man7.org/linux/man-pages/man2/lseek.2.html).
+ */
+#define SEEK_CUR 1
+
+/**
+ * Seek relative to the end of the file.
+ *
+ * See [lseek(2)](https://man7.org/linux/man-pages/man2/lseek.2.html).
+ */
+#define SEEK_END 2
 
 /**
  * Seek to the first data (non-hole) location in the file
@@ -60,4 +74,4 @@
  */
 #define SEEK_HOLE 4
 
-#endif
+__END_DECLS
diff --git a/libc/include/bits/signal_types.h b/libc/include/bits/signal_types.h
index 41a697e..3ca829a 100644
--- a/libc/include/bits/signal_types.h
+++ b/libc/include/bits/signal_types.h
@@ -34,6 +34,8 @@
 #include <linux/signal.h>
 #include <sys/types.h>
 
+__BEGIN_DECLS
+
 /**
  * The highest kernel-supported signal number, plus one.
  *
@@ -184,3 +186,5 @@
 };
 
 #endif
+
+__END_DECLS
diff --git a/libc/include/bits/sockaddr_storage.h b/libc/include/bits/sockaddr_storage.h
index 4b3bfb6..95a8df9 100644
--- a/libc/include/bits/sockaddr_storage.h
+++ b/libc/include/bits/sockaddr_storage.h
@@ -37,6 +37,8 @@
 
 #include <bits/sa_family_t.h>
 
+__BEGIN_DECLS
+
 #pragma clang diagnostic push
 #pragma clang diagnostic ignored "-Wnullability-completeness"
 /**
@@ -55,3 +57,5 @@
   };
 };
 #pragma clang diagnostic pop
+
+__END_DECLS
diff --git a/libc/include/bits/strcasecmp.h b/libc/include/bits/strcasecmp.h
index d76cec9..c2736b0 100644
--- a/libc/include/bits/strcasecmp.h
+++ b/libc/include/bits/strcasecmp.h
@@ -51,12 +51,10 @@
 /**
  * Like strcasecmp() but taking a `locale_t`.
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(23)
 int strcasecmp_l(const char* _Nonnull __s1, const char* _Nonnull __s2, locale_t _Nonnull __l) __attribute_pure__ __INTRODUCED_IN(23);
 #endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
-
 /**
  * [strncasecmp(3)](https://man7.org/linux/man-pages/man3/strncasecmp.3.html) compares the first
  * `n` bytes of two strings ignoring case.
@@ -70,10 +68,8 @@
 /**
  * Like strncasecmp() but taking a `locale_t`.
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(23)
 int strncasecmp_l(const char* _Nonnull __s1, const char* _Nonnull __s2, size_t __n, locale_t _Nonnull __l) __attribute_pure__ __INTRODUCED_IN(23);
 #endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
-
 __END_DECLS
diff --git a/libc/include/bits/sysconf.h b/libc/include/bits/sysconf.h
index 303f7c6..845946e 100644
--- a/libc/include/bits/sysconf.h
+++ b/libc/include/bits/sysconf.h
@@ -30,6 +30,8 @@
 
 #include <sys/cdefs.h>
 
+__BEGIN_DECLS
+
 /** sysconf() query for the maximum number of bytes of exec() arguments. */
 #define _SC_ARG_MAX 0x0000
 /** sysconf() query for bc(1) behavior equivalent to _POSIX2_BC_BASE_MAX. */
@@ -331,8 +333,6 @@
 /** sysconf() query equivalent to NSIG. Available from API level 37. */
 #define _SC_NSIG 0x009e
 
-__BEGIN_DECLS
-
 /**
  * [sysconf(3)](https://man7.org/linux/man-pages/man3/sysconf.3.html)
  * gets system configuration at runtime, corresponding to the given
diff --git a/libc/include/bits/timespec.h b/libc/include/bits/timespec.h
index daad03f..f1c7f5c 100644
--- a/libc/include/bits/timespec.h
+++ b/libc/include/bits/timespec.h
@@ -36,6 +36,8 @@
 #include <sys/cdefs.h>
 #include <sys/types.h>
 
+__BEGIN_DECLS
+
 /*
  * This file is used to include timespec definition without introducing the whole
  * <linux/time.h>, <sys/time.h> or <time.h>.
@@ -50,3 +52,5 @@
   long tv_nsec;
 };
 #endif
+
+__END_DECLS
diff --git a/libc/include/bits/wait.h b/libc/include/bits/wait.h
index c7f1fb0..f1ab150 100644
--- a/libc/include/bits/wait.h
+++ b/libc/include/bits/wait.h
@@ -37,6 +37,8 @@
 
 #include <linux/wait.h>
 
+__BEGIN_DECLS
+
 /** Returns the exit status from a process for which `WIFEXITED` is true. */
 #define WEXITSTATUS(__status) (((__status) & 0xff00) >> 8)
 
@@ -66,3 +68,5 @@
 
 /** Constructs a status value for a process stopped by the given signal. */
 #define W_STOPCODE(__signal_number) ((__signal_number) << 8 | 0x7f)
+
+__END_DECLS
diff --git a/libc/include/bits/wchar_limits.h b/libc/include/bits/wchar_limits.h
index 311b02e..eb22713 100644
--- a/libc/include/bits/wchar_limits.h
+++ b/libc/include/bits/wchar_limits.h
@@ -35,6 +35,8 @@
 
 #include <sys/cdefs.h>
 
+__BEGIN_DECLS
+
 /** The maximum value of a `wchar_t`. */
 #define WCHAR_MAX __WCHAR_MAX__
 
@@ -46,3 +48,5 @@
 /** The minimum value of a `wchar_t`. */
 #  define WCHAR_MIN (-(WCHAR_MAX) - 1)
 #endif
+
+__END_DECLS
diff --git a/libc/include/bits/wctype.h b/libc/include/bits/wctype.h
index d0cffec..237da1a 100644
--- a/libc/include/bits/wctype.h
+++ b/libc/include/bits/wctype.h
@@ -61,9 +61,11 @@
 
 #if __BIONIC_AVAILABILITY_GUARD(26)
 wint_t towctrans(wint_t __wc, wctrans_t _Nonnull __transform) __INTRODUCED_IN(26);
-wctrans_t _Nullable wctrans(const char* _Nonnull __name) __INTRODUCED_IN(26);
 #endif /* __BIONIC_AVAILABILITY_GUARD(26) */
 
+#if __BIONIC_AVAILABILITY_GUARD(26)
+wctrans_t _Nullable wctrans(const char* _Nonnull __name) __INTRODUCED_IN(26);
+#endif /* __BIONIC_AVAILABILITY_GUARD(26) */
 
 __END_DECLS
 
diff --git a/libc/include/byteswap.h b/libc/include/byteswap.h
index a679ea0..36b30b3 100644
--- a/libc/include/byteswap.h
+++ b/libc/include/byteswap.h
@@ -36,6 +36,8 @@
 #include <sys/cdefs.h>
 #include <sys/endian.h>
 
+__BEGIN_DECLS
+
 /**
  * [bswap_16(3)](https://man7.org/linux/man-pages/man3/bswap_16.3.html) swaps the bytes in a
  * 16-bit value.
@@ -53,3 +55,5 @@
  * 64-bit value.
  */
 #define bswap_64(x) __swap64(x)
+
+__END_DECLS
diff --git a/libc/include/complex.h b/libc/include/complex.h
index 1115862..c5280e3 100644
--- a/libc/include/complex.h
+++ b/libc/include/complex.h
@@ -31,6 +31,8 @@
 
 #include <sys/cdefs.h>
 
+__BEGIN_DECLS
+
 #ifdef __GNUC__
 #define	_Complex_I	((float _Complex)1.0i)
 #endif
@@ -49,16 +51,16 @@
 #define	CMPLXL(x, y)	((long double complex){ x, y })
 #endif
 
-__BEGIN_DECLS
-
 /* 7.3.5 Trigonometric functions */
 /* 7.3.5.1 The cacos functions */
 
 #if __BIONIC_AVAILABILITY_GUARD(23)
 double complex cacos(double complex __z) __INTRODUCED_IN(23);
-float complex cacosf(float complex __z) __INTRODUCED_IN(23);
 #endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
+#if __BIONIC_AVAILABILITY_GUARD(23)
+float complex cacosf(float complex __z) __INTRODUCED_IN(23);
+#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
 #if __BIONIC_AVAILABILITY_GUARD(26)
 long double complex cacosl(long double complex __z) __INTRODUCED_IN(26);
@@ -68,9 +70,11 @@
 
 #if __BIONIC_AVAILABILITY_GUARD(23)
 double complex casin(double complex __z) __INTRODUCED_IN(23);
-float complex casinf(float complex __z) __INTRODUCED_IN(23);
 #endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
+#if __BIONIC_AVAILABILITY_GUARD(23)
+float complex casinf(float complex __z) __INTRODUCED_IN(23);
+#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
 #if __BIONIC_AVAILABILITY_GUARD(26)
 long double complex casinl(long double complex __z) __INTRODUCED_IN(26);
@@ -80,9 +84,11 @@
 
 #if __BIONIC_AVAILABILITY_GUARD(23)
 double complex catan(double complex __z) __INTRODUCED_IN(23);
-float complex catanf(float complex __z) __INTRODUCED_IN(23);
 #endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
+#if __BIONIC_AVAILABILITY_GUARD(23)
+float complex catanf(float complex __z) __INTRODUCED_IN(23);
+#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
 #if __BIONIC_AVAILABILITY_GUARD(26)
 long double complex catanl(long double complex __z) __INTRODUCED_IN(26);
@@ -92,9 +98,11 @@
 
 #if __BIONIC_AVAILABILITY_GUARD(23)
 double complex ccos(double complex __z) __INTRODUCED_IN(23);
-float complex ccosf(float complex __z) __INTRODUCED_IN(23);
 #endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
+#if __BIONIC_AVAILABILITY_GUARD(23)
+float complex ccosf(float complex __z) __INTRODUCED_IN(23);
+#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
 #if __BIONIC_AVAILABILITY_GUARD(26)
 long double complex ccosl(long double complex __z) __INTRODUCED_IN(26);
@@ -104,9 +112,11 @@
 
 #if __BIONIC_AVAILABILITY_GUARD(23)
 double complex csin(double complex __z) __INTRODUCED_IN(23);
-float complex csinf(float complex __z) __INTRODUCED_IN(23);
 #endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
+#if __BIONIC_AVAILABILITY_GUARD(23)
+float complex csinf(float complex __z) __INTRODUCED_IN(23);
+#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
 #if __BIONIC_AVAILABILITY_GUARD(26)
 long double complex csinl(long double complex __z) __INTRODUCED_IN(26);
@@ -116,9 +126,11 @@
 
 #if __BIONIC_AVAILABILITY_GUARD(23)
 double complex ctan(double complex __z) __INTRODUCED_IN(23);
-float complex ctanf(float complex __z) __INTRODUCED_IN(23);
 #endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
+#if __BIONIC_AVAILABILITY_GUARD(23)
+float complex ctanf(float complex __z) __INTRODUCED_IN(23);
+#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
 #if __BIONIC_AVAILABILITY_GUARD(26)
 long double complex ctanl(long double complex __z) __INTRODUCED_IN(26);
@@ -130,9 +142,11 @@
 
 #if __BIONIC_AVAILABILITY_GUARD(23)
 double complex cacosh(double complex __z) __INTRODUCED_IN(23);
-float complex cacoshf(float complex __z) __INTRODUCED_IN(23);
 #endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
+#if __BIONIC_AVAILABILITY_GUARD(23)
+float complex cacoshf(float complex __z) __INTRODUCED_IN(23);
+#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
 #if __BIONIC_AVAILABILITY_GUARD(26)
 long double complex cacoshl(long double complex __z) __INTRODUCED_IN(26);
@@ -142,9 +156,11 @@
 
 #if __BIONIC_AVAILABILITY_GUARD(23)
 double complex casinh(double complex __z) __INTRODUCED_IN(23);
-float complex casinhf(float complex __z) __INTRODUCED_IN(23);
 #endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
+#if __BIONIC_AVAILABILITY_GUARD(23)
+float complex casinhf(float complex __z) __INTRODUCED_IN(23);
+#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
 #if __BIONIC_AVAILABILITY_GUARD(26)
 long double complex casinhl(long double complex __z) __INTRODUCED_IN(26);
@@ -154,9 +170,11 @@
 
 #if __BIONIC_AVAILABILITY_GUARD(23)
 double complex catanh(double complex __z) __INTRODUCED_IN(23);
-float complex catanhf(float complex __z) __INTRODUCED_IN(23);
 #endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
+#if __BIONIC_AVAILABILITY_GUARD(23)
+float complex catanhf(float complex __z) __INTRODUCED_IN(23);
+#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
 #if __BIONIC_AVAILABILITY_GUARD(26)
 long double complex catanhl(long double complex __z) __INTRODUCED_IN(26);
@@ -166,9 +184,11 @@
 
 #if __BIONIC_AVAILABILITY_GUARD(23)
 double complex ccosh(double complex __z) __INTRODUCED_IN(23);
-float complex ccoshf(float complex __z) __INTRODUCED_IN(23);
 #endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
+#if __BIONIC_AVAILABILITY_GUARD(23)
+float complex ccoshf(float complex __z) __INTRODUCED_IN(23);
+#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
 #if __BIONIC_AVAILABILITY_GUARD(26)
 long double complex ccoshl(long double complex __z) __INTRODUCED_IN(26);
@@ -178,9 +198,11 @@
 
 #if __BIONIC_AVAILABILITY_GUARD(23)
 double complex csinh(double complex __z) __INTRODUCED_IN(23);
-float complex csinhf(float complex __z) __INTRODUCED_IN(23);
 #endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
+#if __BIONIC_AVAILABILITY_GUARD(23)
+float complex csinhf(float complex __z) __INTRODUCED_IN(23);
+#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
 #if __BIONIC_AVAILABILITY_GUARD(26)
 long double complex csinhl(long double complex __z) __INTRODUCED_IN(26);
@@ -190,9 +212,11 @@
 
 #if __BIONIC_AVAILABILITY_GUARD(23)
 double complex ctanh(double complex __z) __INTRODUCED_IN(23);
-float complex ctanhf(float complex __z) __INTRODUCED_IN(23);
 #endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
+#if __BIONIC_AVAILABILITY_GUARD(23)
+float complex ctanhf(float complex __z) __INTRODUCED_IN(23);
+#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
 #if __BIONIC_AVAILABILITY_GUARD(26)
 long double complex ctanhl(long double complex __z) __INTRODUCED_IN(26);
@@ -204,25 +228,42 @@
 
 #if __BIONIC_AVAILABILITY_GUARD(23)
 double complex cexp(double complex __z) __INTRODUCED_IN(23);
+#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
+
+#if __BIONIC_AVAILABILITY_GUARD(23)
 float complex cexpf(float complex __z) __INTRODUCED_IN(23);
 #endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
-
 #if __BIONIC_AVAILABILITY_GUARD(26)
 long double complex cexpl(long double complex __z) __INTRODUCED_IN(26);
-/* 7.3.7.2 The clog functions */
-double complex clog(double complex __z) __INTRODUCED_IN(26);
-float complex clogf(float complex __z) __INTRODUCED_IN(26);
-long double complex clogl(long double complex __z) __INTRODUCED_IN(26);
 #endif /* __BIONIC_AVAILABILITY_GUARD(26) */
 
+/* 7.3.7.2 The clog functions */
+
+#if __BIONIC_AVAILABILITY_GUARD(26)
+double complex clog(double complex __z) __INTRODUCED_IN(26);
+#endif /* __BIONIC_AVAILABILITY_GUARD(26) */
+
+#if __BIONIC_AVAILABILITY_GUARD(26)
+float complex clogf(float complex __z) __INTRODUCED_IN(26);
+#endif /* __BIONIC_AVAILABILITY_GUARD(26) */
+
+#if __BIONIC_AVAILABILITY_GUARD(26)
+long double complex clogl(long double complex __z) __INTRODUCED_IN(26);
+#endif /* __BIONIC_AVAILABILITY_GUARD(26) */
 
 /* 7.3.8 Power and absolute-value functions */
 /* 7.3.8.1 The cabs functions */
 
 #if __BIONIC_AVAILABILITY_GUARD(23)
 double cabs(double complex __z) __INTRODUCED_IN(23);
+#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
+
+#if __BIONIC_AVAILABILITY_GUARD(23)
 float cabsf(float complex __z) __INTRODUCED_IN(23);
+#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
+
+#if __BIONIC_AVAILABILITY_GUARD(23)
 long double cabsl(long double complex __z) __INTRODUCED_IN(23);
 #endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
@@ -230,7 +271,13 @@
 
 #if __BIONIC_AVAILABILITY_GUARD(26)
 double complex cpow(double complex __x, double complex __z) __INTRODUCED_IN(26);
+#endif /* __BIONIC_AVAILABILITY_GUARD(26) */
+
+#if __BIONIC_AVAILABILITY_GUARD(26)
 float complex cpowf(float complex __x, float complex __z) __INTRODUCED_IN(26);
+#endif /* __BIONIC_AVAILABILITY_GUARD(26) */
+
+#if __BIONIC_AVAILABILITY_GUARD(26)
 long double complex cpowl(long double complex __x, long double complex __z) __INTRODUCED_IN(26);
 #endif /* __BIONIC_AVAILABILITY_GUARD(26) */
 
@@ -238,32 +285,87 @@
 
 #if __BIONIC_AVAILABILITY_GUARD(23)
 double complex csqrt(double complex __z) __INTRODUCED_IN(23);
+#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
+
+#if __BIONIC_AVAILABILITY_GUARD(23)
 float complex csqrtf(float complex __z) __INTRODUCED_IN(23);
+#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
+
+#if __BIONIC_AVAILABILITY_GUARD(23)
 long double complex csqrtl(long double complex __z) __INTRODUCED_IN(23);
+#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
+
 
 /* 7.3.9 Manipulation functions */
 /* 7.3.9.1 The carg functions */
+
+#if __BIONIC_AVAILABILITY_GUARD(23)
 double carg(double complex __z) __INTRODUCED_IN(23);
-float cargf(float complex __z) __INTRODUCED_IN(23);
-long double cargl(long double complex __z) __INTRODUCED_IN(23);
-/* 7.3.9.2 The cimag functions */
-double cimag(double complex __z) __INTRODUCED_IN(23);
-float cimagf(float complex __z) __INTRODUCED_IN(23);
-long double cimagl(long double complex __z) __INTRODUCED_IN(23);
-/* 7.3.9.3 The conj functions */
-double complex conj(double complex __z) __INTRODUCED_IN(23);
-float complex conjf(float complex __z) __INTRODUCED_IN(23);
-long double complex conjl(long double complex __z) __INTRODUCED_IN(23);
-/* 7.3.9.4 The cproj functions */
-double complex cproj(double complex __z) __INTRODUCED_IN(23);
-float complex cprojf(float complex __z) __INTRODUCED_IN(23);
-long double complex cprojl(long double complex __z) __INTRODUCED_IN(23);
-/* 7.3.9.5 The creal functions */
-double creal(double complex __z) __INTRODUCED_IN(23);
-float crealf(float complex __z) __INTRODUCED_IN(23);
-long double creall(long double complex __z) __INTRODUCED_IN(23);
 #endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
+#if __BIONIC_AVAILABILITY_GUARD(23)
+float cargf(float complex __z) __INTRODUCED_IN(23);
+#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
+
+#if __BIONIC_AVAILABILITY_GUARD(23)
+long double cargl(long double complex __z) __INTRODUCED_IN(23);
+#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
+
+/* 7.3.9.2 The cimag functions */
+
+#if __BIONIC_AVAILABILITY_GUARD(23)
+double cimag(double complex __z) __INTRODUCED_IN(23);
+#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
+
+#if __BIONIC_AVAILABILITY_GUARD(23)
+float cimagf(float complex __z) __INTRODUCED_IN(23);
+#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
+
+#if __BIONIC_AVAILABILITY_GUARD(23)
+long double cimagl(long double complex __z) __INTRODUCED_IN(23);
+#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
+
+/* 7.3.9.3 The conj functions */
+
+#if __BIONIC_AVAILABILITY_GUARD(23)
+double complex conj(double complex __z) __INTRODUCED_IN(23);
+#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
+
+#if __BIONIC_AVAILABILITY_GUARD(23)
+float complex conjf(float complex __z) __INTRODUCED_IN(23);
+#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
+
+#if __BIONIC_AVAILABILITY_GUARD(23)
+long double complex conjl(long double complex __z) __INTRODUCED_IN(23);
+#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
+
+/* 7.3.9.4 The cproj functions */
+
+#if __BIONIC_AVAILABILITY_GUARD(23)
+double complex cproj(double complex __z) __INTRODUCED_IN(23);
+#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
+
+#if __BIONIC_AVAILABILITY_GUARD(23)
+float complex cprojf(float complex __z) __INTRODUCED_IN(23);
+#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
+
+#if __BIONIC_AVAILABILITY_GUARD(23)
+long double complex cprojl(long double complex __z) __INTRODUCED_IN(23);
+#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
+
+/* 7.3.9.5 The creal functions */
+
+#if __BIONIC_AVAILABILITY_GUARD(23)
+double creal(double complex __z) __INTRODUCED_IN(23);
+#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
+
+#if __BIONIC_AVAILABILITY_GUARD(23)
+float crealf(float complex __z) __INTRODUCED_IN(23);
+#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
+
+#if __BIONIC_AVAILABILITY_GUARD(23)
+long double creall(long double complex __z) __INTRODUCED_IN(23);
+#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
 __END_DECLS
 
diff --git a/libc/include/cpio.h b/libc/include/cpio.h
index c2c20c2..9248a16 100644
--- a/libc/include/cpio.h
+++ b/libc/include/cpio.h
@@ -35,6 +35,8 @@
 
 #include <sys/cdefs.h>
 
+__BEGIN_DECLS
+
 /** Readable by user mode field bit. */
 #define C_IRUSR 0000400
 /** Writable by user mode field bit. */
@@ -78,3 +80,5 @@
 
 /** cpio file magic. */
 #define MAGIC "070707"
+
+__END_DECLS
diff --git a/libc/include/ctype.h b/libc/include/ctype.h
index dc3f673..beabc90 100644
--- a/libc/include/ctype.h
+++ b/libc/include/ctype.h
@@ -36,6 +36,8 @@
 #include <sys/cdefs.h>
 #include <xlocale.h>
 
+__BEGIN_DECLS
+
 /* All the functions in this file are trivial, being but a single
  * instruction on most architectures. For that reason, we inline them by
  * default. This macro is meant for internal use only, so that we can
@@ -68,8 +70,6 @@
 /** Internal implementation detail. Do not use. */
 #define _CTYPE_N _CTYPE_D
 
-__BEGIN_DECLS
-
 /** Internal implementation detail. Do not use. */
 extern const char* _ctype_;
 
diff --git a/libc/include/dirent.h b/libc/include/dirent.h
index af22fb3..399af18 100644
--- a/libc/include/dirent.h
+++ b/libc/include/dirent.h
@@ -150,9 +150,9 @@
  *
  * Available since API level 23.
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(23)
 void seekdir(DIR* _Nonnull __dir, long __location) __INTRODUCED_IN(23);
+#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
 /**
  * [telldir(3)](https://man7.org/linux/man-pages/man3/telldir.3.html)
@@ -163,6 +163,7 @@
  *
  * Available since API level 23.
  */
+#if __BIONIC_AVAILABILITY_GUARD(23)
 long telldir(DIR* _Nonnull __dir) __INTRODUCED_IN(23);
 #endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
@@ -211,8 +212,6 @@
  */
 int scandir64(const char* _Nonnull __path, struct dirent64* _Nonnull * _Nonnull * _Nonnull __name_list, int (* _Nullable __filter)(const struct dirent64* _Nonnull), int (* _Nullable __comparator)(const struct dirent64* _Nonnull * _Nonnull, const struct dirent64* _Nonnull * _Nonnull));
 
-#if defined(__USE_GNU)
-
 /**
  * [scandirat64(3)](https://man7.org/linux/man-pages/man3/scandirat.3.html)
  * scans all the directory referenced by the pair of `__dir_fd` and `__path`,
@@ -224,11 +223,11 @@
  * Returns the number of entries returned in the list on success,
  * and returns -1 and sets `errno` on failure.
  *
- * Available since API level 24.
+ * Available since API level 24 when compiling with `_GNU_SOURCE`.
  */
-
-#if __BIONIC_AVAILABILITY_GUARD(24)
+#if defined(__USE_GNU) && __BIONIC_AVAILABILITY_GUARD(24)
 int scandirat64(int __dir_fd, const char* _Nonnull __path, struct dirent64* _Nonnull * _Nonnull * _Nonnull __name_list, int (* _Nullable __filter)(const struct dirent64* _Nonnull), int (* _Nullable __comparator)(const struct dirent64* _Nonnull * _Nonnull, const struct dirent64* _Nonnull * _Nonnull)) __INTRODUCED_IN(24);
+#endif
 
 /**
  * [scandirat(3)](https://man7.org/linux/man-pages/man3/scandirat.3.html)
@@ -241,12 +240,10 @@
  * Returns the number of entries returned in the list on success,
  * and returns -1 and sets `errno` on failure.
  *
- * Available since API level 24.
+ * Available since API level 24 when compiling with `_GNU_SOURCE`.
  */
+#if defined(__USE_GNU) && __BIONIC_AVAILABILITY_GUARD(24)
 int scandirat(int __dir_fd, const char* _Nonnull __path, struct dirent* _Nonnull * _Nonnull * _Nonnull __name_list, int (* _Nullable __filter)(const struct dirent* _Nonnull), int (* _Nullable __comparator)(const struct dirent* _Nonnull * _Nonnull, const struct dirent* _Nonnull * _Nonnull)) __INTRODUCED_IN(24);
-#endif /* __BIONIC_AVAILABILITY_GUARD(24) */
-
-
 #endif
 
 __END_DECLS
diff --git a/libc/include/dlfcn.h b/libc/include/dlfcn.h
index dc5b7bb..c8fa6fd 100644
--- a/libc/include/dlfcn.h
+++ b/libc/include/dlfcn.h
@@ -47,6 +47,10 @@
 
 /**
  * dladdr() returns information using this structure.
+ * `Dl_info` is the traditional name for this,
+ * and thus the more portable choice.
+ * POSIX accidentally standardized `Dl_info_t` instead in 2024,
+ * so we provide both names.
  */
 typedef struct {
   /** Pathname of the shared object that contains the given address. */
@@ -57,7 +61,7 @@
   const char* _Nullable dli_sname;
   /** Exact address of the symbol named in `dli_sname`. */
   void* _Nullable dli_saddr;
-} Dl_info;
+} Dl_info, Dl_info_t;
 
 /**
  * [dlopen(3)](https://man7.org/linux/man-pages/man3/dlopen.3.html)
@@ -146,7 +150,6 @@
  * Returns the address of the symbol on success, and returns NULL on failure,
  * in which case dlerror() can be used to retrieve the specific error.
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(24)
 void* _Nullable dlvsym(void* __BIONIC_COMPLICATED_NULLNESS __handle, const char* _Nullable __symbol, const char* _Nullable __version) __INTRODUCED_IN(24);
 #endif /* __BIONIC_AVAILABILITY_GUARD(24) */
diff --git a/libc/include/elf.h b/libc/include/elf.h
index 24454d7..70fc3db 100644
--- a/libc/include/elf.h
+++ b/libc/include/elf.h
@@ -37,6 +37,8 @@
 #include <bits/auxvec.h>
 #include <bits/elf_common.h>
 
+__BEGIN_DECLS
+
 /* http://www.sco.com/developers/gabi/latest/ch4.intro.html */
 typedef __u64 Elf32_Xword;
 typedef __s64 Elf32_Sxword;
@@ -110,39 +112,6 @@
   Elf64_Half si_flags;
 } Elf64_Syminfo;
 
-typedef Elf32_Half Elf32_Versym;
-typedef Elf64_Half Elf64_Versym;
-
-typedef struct {
-  Elf32_Half vd_version;
-  Elf32_Half vd_flags;
-  Elf32_Half vd_ndx;
-  Elf32_Half vd_cnt;
-  Elf32_Word vd_hash;
-  Elf32_Word vd_aux;
-  Elf32_Word vd_next;
-} Elf32_Verdef;
-
-typedef struct {
-  Elf32_Word vda_name;
-  Elf32_Word vda_next;
-} Elf32_Verdaux;
-
-typedef struct {
-  Elf64_Half vd_version;
-  Elf64_Half vd_flags;
-  Elf64_Half vd_ndx;
-  Elf64_Half vd_cnt;
-  Elf64_Word vd_hash;
-  Elf64_Word vd_aux;
-  Elf64_Word vd_next;
-} Elf64_Verdef;
-
-typedef struct {
-  Elf64_Word vda_name;
-  Elf64_Word vda_next;
-} Elf64_Verdaux;
-
 typedef struct {
   Elf32_Half vn_version;
   Elf32_Half vn_cnt;
@@ -297,3 +266,5 @@
 
 /* FreeBSD spells this slightly differently to Linux. */
 #define R_X86_64_JUMP_SLOT R_X86_64_JMP_SLOT
+
+__END_DECLS
diff --git a/libc/include/err.h b/libc/include/err.h
index 81b11e3..cbfd2a0 100644
--- a/libc/include/err.h
+++ b/libc/include/err.h
@@ -45,7 +45,7 @@
 
 /**
  * [err(3)](https://man7.org/linux/man-pages/man3/err.3.html) outputs the program name,
- * the printf()-like formatted message, and the result of strerror() if `errno` is non-zero.
+ * the printf()-like formatted message, and the result of strerror().
  *
  * Calls exit() with `__status`.
  *
@@ -55,7 +55,7 @@
 
 /**
  * [verr(3)](https://man7.org/linux/man-pages/man3/verr.3.html) outputs the program name,
- * the vprintf()-like formatted message, and the result of strerror() if `errno` is non-zero.
+ * the vprintf()-like formatted message, and the result of strerror().
  *
  * Calls exit() with `__status`.
  *
@@ -85,7 +85,7 @@
 
 /**
  * [warn(3)](https://man7.org/linux/man-pages/man3/warn.3.html) outputs the program name,
- * the printf()-like formatted message, and the result of strerror() if `errno` is non-zero.
+ * the printf()-like formatted message, and the result of strerror().
  *
  * New code should consider error() in `<error.h>`.
  */
@@ -93,7 +93,7 @@
 
 /**
  * [vwarn(3)](https://man7.org/linux/man-pages/man3/vwarn.3.html) outputs the program name,
- * the vprintf()-like formatted message, and the result of strerror() if `errno` is non-zero.
+ * the vprintf()-like formatted message, and the result of strerror().
  *
  * New code should consider error() in `<error.h>`.
  */
diff --git a/libc/include/error.h b/libc/include/error.h
index a9bdc24..cf03b4e 100644
--- a/libc/include/error.h
+++ b/libc/include/error.h
@@ -44,9 +44,9 @@
  *
  * Available since API level 23.
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(23)
 extern void (* _Nullable error_print_progname)(void) __INTRODUCED_IN(23);
+#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
 /**
  * [error_message_count(3)](https://man7.org/linux/man-pages/man3/error_message_count.3.html) is
@@ -54,7 +54,9 @@
  *
  * Available since API level 23.
  */
+#if __BIONIC_AVAILABILITY_GUARD(23)
 extern unsigned int error_message_count __INTRODUCED_IN(23);
+#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
 /**
  * [error_one_per_line(3)](https://man7.org/linux/man-pages/man3/error_one_per_line.3.html) is
@@ -63,7 +65,9 @@
  *
  * Available since API level 23.
  */
+#if __BIONIC_AVAILABILITY_GUARD(23)
 extern int error_one_per_line __INTRODUCED_IN(23);
+#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
 /**
  * [error(3)](https://man7.org/linux/man-pages/man3/error.3.html) formats the given printf()-like
@@ -72,7 +76,9 @@
  *
  * Available since API level 23.
  */
+#if __BIONIC_AVAILABILITY_GUARD(23)
 void error(int __status, int __errno, const char* _Nonnull __fmt, ...) __printflike(3, 4) __INTRODUCED_IN(23);
+#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
 /**
  * [error_at_line(3)](https://man7.org/linux/man-pages/man3/error_at_line.3.html) formats the given
@@ -82,8 +88,8 @@
  *
  * Available since API level 23.
  */
+#if __BIONIC_AVAILABILITY_GUARD(23)
 void error_at_line(int __status, int __errno, const char* _Nonnull __filename, unsigned int __line_number, const char* _Nonnull __fmt, ...) __printflike(5, 6) __INTRODUCED_IN(23);
 #endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
-
 __END_DECLS
diff --git a/libc/include/execinfo.h b/libc/include/execinfo.h
index 84b637c..c8fc434 100644
--- a/libc/include/execinfo.h
+++ b/libc/include/execinfo.h
@@ -47,9 +47,9 @@
  *
  * Available since API level 33.
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(33)
 int backtrace(void* _Nonnull * _Nonnull buffer, int size) __INTRODUCED_IN(33);
+#endif /* __BIONIC_AVAILABILITY_GUARD(33) */
 
 /**
  * [backtrace_symbols(3)](https://man7.org/linux/man-pages/man3/backtrace_symbols.3.html)
@@ -61,7 +61,9 @@
  *
  * Available since API level 33.
  */
+#if __BIONIC_AVAILABILITY_GUARD(33)
 char* _Nullable * _Nullable backtrace_symbols(void* _Nonnull const* _Nonnull buffer, int size) __INTRODUCED_IN(33);
+#endif /* __BIONIC_AVAILABILITY_GUARD(33) */
 
 /**
  * [backtrace_symbols_fd(3)](https://man7.org/linux/man-pages/man3/backtrace_symbols_fd.3.html)
@@ -71,8 +73,8 @@
  *
  * Available since API level 33.
  */
+#if __BIONIC_AVAILABILITY_GUARD(33)
 void backtrace_symbols_fd(void* _Nonnull const* _Nonnull buffer, int size, int fd) __INTRODUCED_IN(33);
 #endif /* __BIONIC_AVAILABILITY_GUARD(33) */
 
-
 __END_DECLS
diff --git a/libc/include/fcntl.h b/libc/include/fcntl.h
index 2bd1fc6..4385053 100644
--- a/libc/include/fcntl.h
+++ b/libc/include/fcntl.h
@@ -208,15 +208,17 @@
 /** See posix_fallocate(). */
 int posix_fallocate64(int __fd, off64_t __offset, off64_t __length);
 
-#if defined(__USE_GNU)
-
 /**
  * [readahead(2)](https://man7.org/linux/man-pages/man2/readahead.2.html)
  * initiates readahead for the given file.
  *
  * Returns 0 on success and returns -1 and sets `errno` on failure.
+ *
+ * Available when compiling with `_GNU_SOURCE`.
  */
+#if defined(__USE_GNU)
 ssize_t readahead(int __fd, off64_t __offset, size_t __length);
+#endif
 
 /**
  * [sync_file_range(2)](https://man7.org/linux/man-pages/man2/sync_file_range.2.html)
@@ -226,13 +228,11 @@
  * `SYNC_FILE_RANGE_WAIT_AFTER`.
  *
  * Returns 0 on success and returns -1 and sets `errno` on failure.
+ *
+ * Available since API level 26 when compiling with `_GNU_SOURCE`.
  */
-
-#if __BIONIC_AVAILABILITY_GUARD(26)
+#if defined(__USE_GNU) && __BIONIC_AVAILABILITY_GUARD(26)
 int sync_file_range(int __fd, off64_t __offset, off64_t __length, unsigned int __flags) __INTRODUCED_IN(26);
-#endif /* __BIONIC_AVAILABILITY_GUARD(26) */
-
-
 #endif
 
 #if defined(__BIONIC_INCLUDE_FORTIFY_HEADERS)
diff --git a/libc/include/fts.h b/libc/include/fts.h
index 69e17df..67c69da 100644
--- a/libc/include/fts.h
+++ b/libc/include/fts.h
@@ -38,6 +38,8 @@
 #include <sys/cdefs.h>
 #include <sys/types.h>
 
+__BEGIN_DECLS
+
 typedef struct _ftsent {
 	struct _ftsent * _Nullable fts_cycle;	/* cycle node */
 	struct _ftsent * _Nullable fts_parent;	/* parent directory */
@@ -115,8 +117,6 @@
 	int fts_options;		/* fts_open options, global flags */
 } FTS;
 
-__BEGIN_DECLS
-
 FTSENT* _Nullable fts_children(FTS* _Nonnull __fts, int __options);
 int fts_close(FTS* _Nonnull __fts);
 FTS* _Nullable fts_open(char* _Nullable const* _Nonnull __path, int __options, int (* _Nullable __comparator)(const FTSENT* _Nonnull * _Nonnull  __lhs, const FTSENT* _Nonnull * _Nonnull __rhs));
diff --git a/libc/include/ftw.h b/libc/include/ftw.h
index ac2473a..39a552a 100644
--- a/libc/include/ftw.h
+++ b/libc/include/ftw.h
@@ -29,6 +29,8 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 
+__BEGIN_DECLS
+
 /*
  * Valid flags for the 3rd argument to the function that is passed as the
  * second argument to ftw(3) and nftw(3).  Say it three times fast!
@@ -54,11 +56,11 @@
 	int level;
 };
 
-__BEGIN_DECLS
 int ftw(const char* _Nonnull __dir_path, int (* _Nonnull __callback)(const char* _Nonnull, const struct stat* _Nonnull, int), int __max_fd_count);
 int nftw(const char* _Nonnull __dir_path, int (* _Nonnull __callback)(const char* _Nonnull, const struct stat* _Nonnull, int, struct FTW* _Nonnull), int __max_fd_count, int __flags);
 int ftw64(const char* _Nonnull __dir_path, int (* _Nonnull __callback)(const char* _Nonnull, const struct stat64* _Nonnull, int), int __max_fd_count);
 int nftw64(const char* _Nonnull __dir_path, int (* _Nonnull __callback)(const char* _Nonnull, const struct stat64* _Nonnull, int, struct FTW* _Nonnull), int __max_fd_count, int __flags);
+
 __END_DECLS
 
 #endif
diff --git a/libc/include/getopt.h b/libc/include/getopt.h
index 56892aa..ec7a791 100644
--- a/libc/include/getopt.h
+++ b/libc/include/getopt.h
@@ -41,6 +41,8 @@
 
 #include <bits/getopt.h>
 
+__BEGIN_DECLS
+
 /** A `has_arg` value for `struct option`. */
 #define no_argument 0
 /** A `has_arg` value for `struct option`. */
@@ -67,8 +69,6 @@
   int val;
 };
 
-__BEGIN_DECLS
-
 /**
  * [getopt_long(3)](https://man7.org/linux/man-pages/man3/getopt_long.3.html) parses command-line options.
  */
diff --git a/libc/include/glob.h b/libc/include/glob.h
index ccdf2e9..be09174 100644
--- a/libc/include/glob.h
+++ b/libc/include/glob.h
@@ -33,12 +33,13 @@
  * $FreeBSD$
  */
 
-#ifndef _GLOB_H_
-#define _GLOB_H_
+#pragma once
 
 #include <sys/cdefs.h>
 #include <sys/types.h>
 
+__BEGIN_DECLS
+
 struct dirent;
 struct stat;
 
@@ -80,25 +81,47 @@
 #define GLOB_ABORTED	(-2)	/* Unignored error. */
 #define GLOB_NOMATCH	(-3)	/* No match and GLOB_NOCHECK was not set. */
 
+/** Use alternately specified directory funcs. */
 #if __USE_BSD
-#define GLOB_ALTDIRFUNC	0x0040	/* Use alternately specified directory funcs. */
-#define GLOB_BRACE	0x0080	/* Expand braces like csh. */
-#define GLOB_MAGCHAR	0x0100	/* Set in `gl_flags` if the pattern had globbing characters. */
-#define GLOB_NOMAGIC	0x0200	/* GLOB_NOCHECK without magic chars (csh). */
-#define GLOB_QUOTE	0x0400	/* Quote special chars with \. */
-#define GLOB_TILDE	0x0800	/* Expand tilde names from the passwd file. */
-#define GLOB_LIMIT	0x1000	/* limit number of returned paths */
+#define GLOB_ALTDIRFUNC	0x0040
 #endif
 
-__BEGIN_DECLS
+/** Expand braces like csh. */
+#if __USE_BSD
+#define GLOB_BRACE	0x0080
+#endif
 
+/** Set in `gl_flags` if the pattern had globbing characters. */
+#if __USE_BSD
+#define GLOB_MAGCHAR	0x0100
+#endif
+
+/** GLOB_NOCHECK without magic chars (csh). */
+#if __USE_BSD
+#define GLOB_NOMAGIC	0x0200
+#endif
+
+/** Quote special chars with \. */
+#if __USE_BSD
+#define GLOB_QUOTE	0x0400
+#endif
+
+/** Expand tilde names from the passwd file. */
+#if __USE_BSD
+#define GLOB_TILDE	0x0800
+#endif
+
+/** Limit number of returned paths. */
+#if __USE_BSD
+#define GLOB_LIMIT	0x1000
+#endif
 
 #if __BIONIC_AVAILABILITY_GUARD(28)
 int glob(const char* _Nonnull __pattern, int __flags, int (* _Nullable __error_callback)(const char* _Nonnull __failure_path, int __failure_errno), glob_t* _Nonnull __result_ptr) __INTRODUCED_IN(28);
+#endif /* __BIONIC_AVAILABILITY_GUARD(28) */
+
+#if __BIONIC_AVAILABILITY_GUARD(28)
 void globfree(glob_t* _Nonnull __result_ptr) __INTRODUCED_IN(28);
 #endif /* __BIONIC_AVAILABILITY_GUARD(28) */
 
-
 __END_DECLS
-
-#endif
diff --git a/libc/include/grp.h b/libc/include/grp.h
index a48c046..30973b6 100644
--- a/libc/include/grp.h
+++ b/libc/include/grp.h
@@ -38,6 +38,8 @@
 #include <sys/cdefs.h>
 #include <sys/types.h>
 
+__BEGIN_DECLS
+
 struct group {
   char* _Nullable gr_name; /* group name */
   char* _Nullable gr_passwd; /* group password */
@@ -45,8 +47,6 @@
   char* _Nullable * _Nullable gr_mem; /* group members */
 };
 
-__BEGIN_DECLS
-
 struct group* _Nullable getgrgid(gid_t __gid);
 struct group* _Nullable getgrnam(const char* _Nonnull __name);
 
@@ -54,14 +54,21 @@
 
 #if __BIONIC_AVAILABILITY_GUARD(26)
 struct group* _Nullable getgrent(void) __INTRODUCED_IN(26);
+#endif /* __BIONIC_AVAILABILITY_GUARD(26) */
 
+#if __BIONIC_AVAILABILITY_GUARD(26)
 void setgrent(void) __INTRODUCED_IN(26);
+#endif /* __BIONIC_AVAILABILITY_GUARD(26) */
+
+#if __BIONIC_AVAILABILITY_GUARD(26)
 void endgrent(void) __INTRODUCED_IN(26);
 #endif /* __BIONIC_AVAILABILITY_GUARD(26) */
 
-
 #if __BIONIC_AVAILABILITY_GUARD(24)
 int getgrgid_r(gid_t __gid, struct group* __BIONIC_COMPLICATED_NULLNESS __group, char* _Nonnull __buf, size_t __n, struct group* _Nullable * _Nonnull __result) __INTRODUCED_IN(24);
+#endif /* __BIONIC_AVAILABILITY_GUARD(24) */
+
+#if __BIONIC_AVAILABILITY_GUARD(24)
 int getgrnam_r(const char* _Nonnull __name, struct group* __BIONIC_COMPLICATED_NULLNESS __group, char* _Nonnull __buf, size_t __n, struct group* _Nullable *_Nonnull __result) __INTRODUCED_IN(24);
 #endif /* __BIONIC_AVAILABILITY_GUARD(24) */
 
diff --git a/libc/include/iconv.h b/libc/include/iconv.h
index 35328ee..f120d42 100644
--- a/libc/include/iconv.h
+++ b/libc/include/iconv.h
@@ -60,9 +60,9 @@
  *
  * Available since API level 28.
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(28)
 iconv_t _Nonnull iconv_open(const char* _Nonnull __dst_encoding, const char* _Nonnull __src_encoding) __INTRODUCED_IN(28);
+#endif /* __BIONIC_AVAILABILITY_GUARD(28) */
 
 /**
  * [iconv(3)](https://man7.org/linux/man-pages/man3/iconv.3.html) converts characters from one
@@ -73,7 +73,9 @@
  *
  * Available since API level 28.
  */
+#if __BIONIC_AVAILABILITY_GUARD(28)
 size_t iconv(iconv_t _Nonnull __converter, char* _Nullable * _Nullable __src_buf, size_t* __BIONIC_COMPLICATED_NULLNESS __src_bytes_left, char* _Nullable * _Nullable __dst_buf, size_t* __BIONIC_COMPLICATED_NULLNESS __dst_bytes_left) __INTRODUCED_IN(28);
+#endif /* __BIONIC_AVAILABILITY_GUARD(28) */
 
 /**
  * [iconv_close(3)](https://man7.org/linux/man-pages/man3/iconv_close.3.html) deallocates a converter
@@ -83,8 +85,8 @@
  *
  * Available since API level 28.
  */
+#if __BIONIC_AVAILABILITY_GUARD(28)
 int iconv_close(iconv_t _Nonnull __converter) __INTRODUCED_IN(28);
 #endif /* __BIONIC_AVAILABILITY_GUARD(28) */
 
-
 __END_DECLS
diff --git a/libc/include/ifaddrs.h b/libc/include/ifaddrs.h
index 87d2947..2eba91a 100644
--- a/libc/include/ifaddrs.h
+++ b/libc/include/ifaddrs.h
@@ -80,9 +80,9 @@
  *
  * Available since API level 24.
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(24)
 int getifaddrs(struct ifaddrs* _Nullable * _Nonnull __list_ptr) __INTRODUCED_IN(24);
+#endif /* __BIONIC_AVAILABILITY_GUARD(24) */
 
 /**
  * [freeifaddrs(3)](https://man7.org/linux/man-pages/man3/freeifaddrs.3.html) frees a linked list
@@ -90,8 +90,8 @@
  *
  * Available since API level 24.
  */
+#if __BIONIC_AVAILABILITY_GUARD(24)
 void freeifaddrs(struct ifaddrs* _Nullable __ptr) __INTRODUCED_IN(24);
 #endif /* __BIONIC_AVAILABILITY_GUARD(24) */
 
-
 __END_DECLS
diff --git a/libc/include/inttypes.h b/libc/include/inttypes.h
index 790030e..43c8ea8 100644
--- a/libc/include/inttypes.h
+++ b/libc/include/inttypes.h
@@ -22,6 +22,8 @@
 #include <sys/cdefs.h>
 #include <stdint.h>
 
+__BEGIN_DECLS
+
 #ifdef __LP64__
 #define __PRI_64_prefix  "l"
 #define __PRI_PTR_prefix "l"
@@ -326,13 +328,26 @@
 	intmax_t rem;		/* remainder */
 } imaxdiv_t;
 
-__BEGIN_DECLS
+/**
+ * Returns the absolute value where possible.
+ * For the most negative value, the result is unchanged (and thus also negative).
+ */
 intmax_t imaxabs(intmax_t __i) __attribute_const__;
+
+/**
+ * Returns `__numerator / __denominator` and `__numerator % __denominator`,
+ * truncating towards zero.
+ *
+ * This function was useful for portability before C99,
+ * where `/` and `%` were also defined to truncate towards zero.
+ */
 imaxdiv_t imaxdiv(intmax_t __numerator, intmax_t __denominator) __attribute_const__;
+
 intmax_t strtoimax(const char* _Nonnull __s, char* _Nullable * _Nullable __end_ptr, int __base);
 uintmax_t strtoumax(const char* _Nonnull __s, char* _Nullable * _Nullable __end_ptr, int __base);
 intmax_t wcstoimax(const wchar_t* _Nonnull __s, wchar_t* _Nullable * _Nullable __end_ptr, int __base);
 uintmax_t wcstoumax(const wchar_t* _Nonnull __s, wchar_t* _Nullable * _Nullable __end_ptr, int __base);
+
 __END_DECLS
 
 #endif
diff --git a/libc/include/langinfo.h b/libc/include/langinfo.h
index b9d695c..a39c259 100644
--- a/libc/include/langinfo.h
+++ b/libc/include/langinfo.h
@@ -92,12 +92,13 @@
 #define NOEXPR 54
 #define CRNCYSTR 55
 
-
 #if __BIONIC_AVAILABILITY_GUARD(26)
 char* _Nonnull nl_langinfo(nl_item __item) __INTRODUCED_IN(26);
-char* _Nonnull nl_langinfo_l(nl_item __item, locale_t _Nonnull __l) __INTRODUCED_IN(26);
 #endif /* __BIONIC_AVAILABILITY_GUARD(26) */
 
+#if __BIONIC_AVAILABILITY_GUARD(26)
+char* _Nonnull nl_langinfo_l(nl_item __item, locale_t _Nonnull __l) __INTRODUCED_IN(26);
+#endif /* __BIONIC_AVAILABILITY_GUARD(26) */
 
 __END_DECLS
 
diff --git a/libc/include/limits.h b/libc/include/limits.h
index 3220415..a8ff2cb 100644
--- a/libc/include/limits.h
+++ b/libc/include/limits.h
@@ -60,6 +60,11 @@
 /* Many of the POSIX limits come from the kernel. */
 #include <linux/limits.h>
 
+__BEGIN_DECLS
+
+/** Maximum buffer size for getentropy(). */
+#define GETENTROPY_MAX 256
+
 /** Maximum number of positional arguments in a printf()/scanf() format string. */
 #define NL_ARGMAX 9
 /** Maximum number of bytes in a $LANG name. */
@@ -141,3 +146,5 @@
 
 /** bionic has no fixed limit on the number of threads. */
 #undef PTHREAD_THREADS_MAX
+
+__END_DECLS
diff --git a/libc/include/link.h b/libc/include/link.h
index 331070e..2afc5dc 100644
--- a/libc/include/link.h
+++ b/libc/include/link.h
@@ -101,12 +101,21 @@
 
 /**
  * [dl_iterate_phdr(3)](https://man7.org/linux/man-pages/man3/dl_iterate_phdr.3.html)
- * calls the given callback once for every loaded shared object. The size
- * argument to the callback lets you determine whether you have a smaller
- * `dl_phdr_info` from before API level 30, or the newer full one.
+ * calls the given callback once for every loaded shared object.
+ *
+ * The size argument to the callback lets you determine whether you have a
+ * smaller `dl_phdr_info` from before API level 30, or the newer full one.
  * The data argument to the callback is whatever you pass as the data argument
  * to dl_iterate_phdr().
  *
+ * Before API level 38, iteration starts with the dynamic linker itself
+ * followed by the main executable.
+ *
+ * From API level 38, iteration starts with the main executable.
+ *
+ * On Android, the `dlpi_name` field for a dynamic executable points to
+ * its canonical path.
+ *
  * Returns the value returned by the final call to the callback.
  */
 int dl_iterate_phdr(int (* _Nonnull __callback)(struct dl_phdr_info* _Nonnull __info, size_t __size, void* _Nullable __data), void* _Nullable __data);
diff --git a/libc/include/malloc.h b/libc/include/malloc.h
index bb4916a..6fb12a2 100644
--- a/libc/include/malloc.h
+++ b/libc/include/malloc.h
@@ -121,10 +121,17 @@
 /**
  * [malloc_usable_size(3)](https://man7.org/linux/man-pages/man3/malloc_usable_size.3.html)
  * returns the actual size of the given heap block.
+ *
+ * malloc_usable_size() and _FORTIFY_SOURCE>=3 are incompatible if you are using more of the
+ * allocation than originally requested. However, malloc_usable_size() can be used to keep track
+ * of allocation/deallocation byte counts and this is an exception to the incompatible rule. In this
+ * case, you can define __BIONIC_DISABLE_MALLOC_USABLE_SIZE_FORTIFY_WARNINGS to disable the
+ * compiler error.
  */
 __nodiscard size_t malloc_usable_size(const void* _Nullable __ptr)
-#if defined(_FORTIFY_SOURCE)
-    __clang_error_if(_FORTIFY_SOURCE == 3, "malloc_usable_size() and _FORTIFY_SOURCE=3 are incompatible")
+#if defined(_FORTIFY_SOURCE) && !defined(__BIONIC_DISABLE_MALLOC_USABLE_SIZE_FORTIFY_WARNINGS)
+    __clang_error_if(_FORTIFY_SOURCE >= 3,
+      "malloc_usable_size() and _FORTIFY_SOURCE>=3 are incompatible: see malloc_usable_size() documentation")
 #endif
 ;
 
@@ -199,7 +206,6 @@
  *
  * Available since API level 23.
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(23)
 int malloc_info(int __must_be_zero, FILE* _Nonnull __fp) __INTRODUCED_IN(23);
 #endif /* __BIONIC_AVAILABILITY_GUARD(23) */
@@ -376,7 +382,6 @@
  *
  * Available since API level 26.
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(26)
 int mallopt(int __option, int __value) __INTRODUCED_IN(26);
 #endif /* __BIONIC_AVAILABILITY_GUARD(26) */
@@ -391,9 +396,9 @@
  *
  * See also: [extra documentation](https://android.googlesource.com/platform/bionic/+/main/libc/malloc_hooks/README.md)
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(28)
 extern void* _Nonnull (*volatile _Nonnull __malloc_hook)(size_t __byte_count, const void* _Nonnull __caller) __INTRODUCED_IN(28);
+#endif /* __BIONIC_AVAILABILITY_GUARD(28) */
 
 /**
  * [__realloc_hook(3)](https://man7.org/linux/man-pages/man3/__realloc_hook.3.html)
@@ -404,7 +409,9 @@
  *
  * See also: [extra documentation](https://android.googlesource.com/platform/bionic/+/main/libc/malloc_hooks/README.md)
  */
+#if __BIONIC_AVAILABILITY_GUARD(28)
 extern void* _Nonnull (*volatile _Nonnull __realloc_hook)(void* _Nullable __ptr, size_t __byte_count, const void* _Nonnull __caller) __INTRODUCED_IN(28);
+#endif /* __BIONIC_AVAILABILITY_GUARD(28) */
 
 /**
  * [__free_hook(3)](https://man7.org/linux/man-pages/man3/__free_hook.3.html)
@@ -415,7 +422,9 @@
  *
  * See also: [extra documentation](https://android.googlesource.com/platform/bionic/+/main/libc/malloc_hooks/README.md)
  */
+#if __BIONIC_AVAILABILITY_GUARD(28)
 extern void (*volatile _Nonnull __free_hook)(void* _Nullable __ptr, const void* _Nonnull __caller) __INTRODUCED_IN(28);
+#endif /* __BIONIC_AVAILABILITY_GUARD(28) */
 
 /**
  * [__memalign_hook(3)](https://man7.org/linux/man-pages/man3/__memalign_hook.3.html)
@@ -426,8 +435,8 @@
  *
  * See also: [extra documentation](https://android.googlesource.com/platform/bionic/+/main/libc/malloc_hooks/README.md)
  */
+#if __BIONIC_AVAILABILITY_GUARD(28)
 extern void* _Nonnull (*volatile _Nonnull __memalign_hook)(size_t __alignment, size_t __byte_count, const void* _Nonnull __caller) __INTRODUCED_IN(28);
 #endif /* __BIONIC_AVAILABILITY_GUARD(28) */
 
-
 __END_DECLS
diff --git a/libc/include/math.h b/libc/include/math.h
index 59161bf..0d03940 100644
--- a/libc/include/math.h
+++ b/libc/include/math.h
@@ -330,53 +330,6 @@
 #define M_SQRT2		1.41421356237309504880	/* sqrt(2) */
 #define M_SQRT1_2	0.70710678118654752440	/* 1/sqrt(2) */
 
-#define MAXFLOAT	((float)3.40282346638528860e+38)
-
-/* BSD extensions. */
-
-#if defined(__USE_BSD)
-#define HUGE MAXFLOAT
-#endif
-
-/* Extensions in both BSD and GNU. */
-
-#if defined(__USE_BSD) || defined(__USE_GNU)
-double gamma(double __x);
-double scalb(double __x, double __exponent);
-double drem(double __x, double __y);
-int finite(double __x) __attribute_const__;
-int isinff(float __x) __attribute_const__;
-int isnanf(float __x) __attribute_const__;
-double gamma_r(double __x, int* _Nonnull __sign);
-double lgamma_r(double __x, int* _Nonnull __sign);
-double significand(double __x);
-
-#if __BIONIC_AVAILABILITY_GUARD(23)
-long double lgammal_r(long double __x, int* _Nonnull __sign) __INTRODUCED_IN(23);
-#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
-
-long double significandl(long double __x);
-float dremf(float __x, float __y);
-int finitef(float __x) __attribute_const__;
-float gammaf(float __x);
-float j0f(float __x);
-float j1f(float __x);
-float jnf(int __n, float __x);
-float scalbf(float __x, float __exponent);
-float y0f(float __x);
-float y1f(float __x);
-float ynf(int __n, float __x);
-float gammaf_r(float __x, int* _Nonnull __sign);
-float lgammaf_r(float __x, int* _Nonnull __sign);
-float significandf(float __x);
-void sincos(double __x, double* _Nonnull __sin, double* _Nonnull __cos);
-void sincosf(float __x, float* _Nonnull __sin, float* _Nonnull __cos);
-void sincosl(long double __x, long double* _Nonnull __sin, long double* _Nonnull __cos);
-#endif
-
-/* GNU extensions. */
-
-#if defined(__USE_GNU)
 #define M_El            2.718281828459045235360287471352662498L /* e */
 #define M_LOG2El        1.442695040888963407359924681001892137L /* log 2e */
 #define M_LOG10El       0.434294481903251827651128918916605082L /* log 10e */
@@ -390,7 +343,130 @@
 #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) */
+
+#define MAXFLOAT	((float)3.40282346638528860e+38)
+
+/* BSD extensions. */
+
+#if defined(__USE_BSD)
+#define HUGE MAXFLOAT
+#endif
+
+/* Extensions in both BSD and GNU. */
+
+#if defined(__USE_BSD) || defined(__USE_GNU)
+double gamma(double __x);
+#endif
+
+#if defined(__USE_BSD) || defined(__USE_GNU)
+double scalb(double __x, double __exponent);
+#endif
+
+#if defined(__USE_BSD) || defined(__USE_GNU)
+double drem(double __x, double __y);
+#endif
+
+#if defined(__USE_BSD) || defined(__USE_GNU)
+int finite(double __x) __attribute_const__;
+#endif
+
+#if defined(__USE_BSD) || defined(__USE_GNU)
+int isinff(float __x) __attribute_const__;
+#endif
+
+#if defined(__USE_BSD) || defined(__USE_GNU)
+int isnanf(float __x) __attribute_const__;
+#endif
+
+#if defined(__USE_BSD) || defined(__USE_GNU)
+double gamma_r(double __x, int* _Nonnull __sign);
+#endif
+
+#if defined(__USE_BSD) || defined(__USE_GNU)
+double lgamma_r(double __x, int* _Nonnull __sign);
+#endif
+
+#if defined(__USE_BSD) || defined(__USE_GNU)
+double significand(double __x);
+#endif
+
+#if (defined(__USE_BSD) || defined(__USE_GNU)) && __BIONIC_AVAILABILITY_GUARD(23)
+long double lgammal_r(long double __x, int* _Nonnull __sign) __INTRODUCED_IN(23);
+#endif
+
+#if defined(__USE_BSD) || defined(__USE_GNU)
+long double significandl(long double __x);
+#endif
+
+#if defined(__USE_BSD) || defined(__USE_GNU)
+float dremf(float __x, float __y);
+#endif
+
+#if defined(__USE_BSD) || defined(__USE_GNU)
+int finitef(float __x) __attribute_const__;
+#endif
+
+#if defined(__USE_BSD) || defined(__USE_GNU)
+float gammaf(float __x);
+#endif
+
+#if defined(__USE_BSD) || defined(__USE_GNU)
+float j0f(float __x);
+#endif
+
+#if defined(__USE_BSD) || defined(__USE_GNU)
+float j1f(float __x);
+#endif
+
+#if defined(__USE_BSD) || defined(__USE_GNU)
+float jnf(int __n, float __x);
+#endif
+
+#if defined(__USE_BSD) || defined(__USE_GNU)
+float scalbf(float __x, float __exponent);
+#endif
+
+#if defined(__USE_BSD) || defined(__USE_GNU)
+float y0f(float __x);
+#endif
+
+#if defined(__USE_BSD) || defined(__USE_GNU)
+float y1f(float __x);
+#endif
+
+#if defined(__USE_BSD) || defined(__USE_GNU)
+float ynf(int __n, float __x);
+#endif
+
+#if defined(__USE_BSD) || defined(__USE_GNU)
+float gammaf_r(float __x, int* _Nonnull __sign);
+#endif
+
+#if defined(__USE_BSD) || defined(__USE_GNU)
+float lgammaf_r(float __x, int* _Nonnull __sign);
+#endif
+
+#if defined(__USE_BSD) || defined(__USE_GNU)
+float significandf(float __x);
+#endif
+
+#if defined(__USE_BSD) || defined(__USE_GNU)
+void sincos(double __x, double* _Nonnull __sin, double* _Nonnull __cos);
+#endif
+
+#if defined(__USE_BSD) || defined(__USE_GNU)
+void sincosf(float __x, float* _Nonnull __sin, float* _Nonnull __cos);
+#endif
+
+#if defined(__USE_BSD) || defined(__USE_GNU)
+void sincosl(long double __x, long double* _Nonnull __sin, long double* _Nonnull __cos);
+#endif
+
+#if defined(__USE_GNU)
 int isinfl(long double __x) __attribute_const__;
+#endif
+
+#if defined(__USE_GNU)
 int isnanl(long double __x) __attribute_const__;
 #endif
 
diff --git a/libc/include/mntent.h b/libc/include/mntent.h
index 4c03602..009d685 100644
--- a/libc/include/mntent.h
+++ b/libc/include/mntent.h
@@ -34,6 +34,8 @@
 #include <stdio.h>
 #include <paths.h>  /* for _PATH_MOUNTED */
 
+__BEGIN_DECLS
+
 #define MOUNTED _PATH_MOUNTED
 
 #define MNTTYPE_IGNORE "ignore"
@@ -56,8 +58,6 @@
   int mnt_passno;
 };
 
-__BEGIN_DECLS
-
 int endmntent(FILE* _Nullable __fp);
 struct mntent* _Nullable getmntent(FILE* _Nonnull __fp);
 struct mntent* _Nullable getmntent_r(FILE* _Nonnull __fp, struct mntent* _Nonnull __entry, char* _Nonnull __buf, int __size);
diff --git a/libc/include/net/ethernet.h b/libc/include/net/ethernet.h
index d5ba11f..830e079 100644
--- a/libc/include/net/ethernet.h
+++ b/libc/include/net/ethernet.h
@@ -34,6 +34,8 @@
 
 #include <linux/if_ether.h>
 
+__BEGIN_DECLS
+
 #define ETHERTYPE_IP 0x0800
 #define ETHERTYPE_ARP 0x0806
 #define ETHERTYPE_REVARP 0x8035
@@ -77,4 +79,6 @@
 #define	ETHERMTU	(ETHER_MAX_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN)
 #define	ETHERMIN	(ETHER_MIN_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN)
 
+__END_DECLS
+
 #endif
diff --git a/libc/include/net/if.h b/libc/include/net/if.h
index 50bc74c..fad6f65 100644
--- a/libc/include/net/if.h
+++ b/libc/include/net/if.h
@@ -34,12 +34,12 @@
 #include <sys/socket.h>
 #include <linux/if.h>
 
+__BEGIN_DECLS
+
 #ifndef IF_NAMESIZE
 #define IF_NAMESIZE IFNAMSIZ
 #endif
 
-__BEGIN_DECLS
-
 struct if_nameindex {
   unsigned if_index;
   char* _Nullable if_name;
@@ -50,9 +50,11 @@
 
 #if __BIONIC_AVAILABILITY_GUARD(24)
 struct if_nameindex* _Nullable if_nameindex(void) __INTRODUCED_IN(24);
-void if_freenameindex(struct if_nameindex* _Nullable __ptr) __INTRODUCED_IN(24);
 #endif /* __BIONIC_AVAILABILITY_GUARD(24) */
 
+#if __BIONIC_AVAILABILITY_GUARD(24)
+void if_freenameindex(struct if_nameindex* _Nullable __ptr) __INTRODUCED_IN(24);
+#endif /* __BIONIC_AVAILABILITY_GUARD(24) */
 
 __END_DECLS
 
diff --git a/libc/include/netdb.h b/libc/include/netdb.h
index 04aaf5c..ab20c2d 100644
--- a/libc/include/netdb.h
+++ b/libc/include/netdb.h
@@ -65,6 +65,8 @@
 #include <sys/types.h>
 #include <sys/socket.h>
 
+__BEGIN_DECLS
+
 #ifndef _PATH_HEQUIV
 # define	_PATH_HEQUIV	"/system/etc/hosts.equiv"
 #endif
@@ -197,8 +199,6 @@
 
 #define IPPORT_RESERVED 1024
 
-__BEGIN_DECLS
-
 int getaddrinfo(const char* _Nullable __node, const char* _Nullable __service, const struct addrinfo* _Nullable __hints, struct addrinfo* _Nullable * _Nonnull __result);
 void freeaddrinfo(struct addrinfo* _Nullable __ptr);
 
@@ -225,7 +225,6 @@
 int gethostbyname2_r(const char* _Nonnull __name, int __af, struct hostent* _Nonnull __ret, char* _Nonnull __buf, size_t __buf_size, struct hostent* _Nullable * _Nonnull __result, int* _Nonnull __h_errno_ptr) __INTRODUCED_IN(23);
 #endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
-
 #if __BIONIC_AVAILABILITY_GUARD(28)
 void endhostent(void) __INTRODUCED_IN(28);
 #endif /* __BIONIC_AVAILABILITY_GUARD(28) */
@@ -234,8 +233,11 @@
 
 #if __BIONIC_AVAILABILITY_GUARD(28)
 void sethostent(int __stay_open) __INTRODUCED_IN(28);
+#endif /* __BIONIC_AVAILABILITY_GUARD(28) */
 
 /* These functions are obsolete. None of these functions return anything but nullptr. */
+
+#if __BIONIC_AVAILABILITY_GUARD(28)
 void endnetent(void) __INTRODUCED_IN(28);
 #endif /* __BIONIC_AVAILABILITY_GUARD(28) */
 
@@ -244,9 +246,14 @@
 
 #if __BIONIC_AVAILABILITY_GUARD(28)
 struct netent* _Nullable getnetent(void) __INTRODUCED_IN(28);
+#endif /* __BIONIC_AVAILABILITY_GUARD(28) */
+#if __BIONIC_AVAILABILITY_GUARD(28)
 void setnetent(int __stay_open) __INTRODUCED_IN(28);
+#endif /* __BIONIC_AVAILABILITY_GUARD(28) */
 
 /* None of these functions return anything but nullptr. */
+
+#if __BIONIC_AVAILABILITY_GUARD(28)
 void endprotoent(void) __INTRODUCED_IN(28);
 #endif /* __BIONIC_AVAILABILITY_GUARD(28) */
 
@@ -255,6 +262,8 @@
 
 #if __BIONIC_AVAILABILITY_GUARD(28)
 struct protoent* _Nullable getprotoent(void) __INTRODUCED_IN(28);
+#endif /* __BIONIC_AVAILABILITY_GUARD(28) */
+#if __BIONIC_AVAILABILITY_GUARD(28)
 void setprotoent(int __stay_open) __INTRODUCED_IN(28);
 #endif /* __BIONIC_AVAILABILITY_GUARD(28) */
 
diff --git a/libc/include/netinet/icmp6.h b/libc/include/netinet/icmp6.h
index ebd9f6c..47cca03 100644
--- a/libc/include/netinet/icmp6.h
+++ b/libc/include/netinet/icmp6.h
@@ -69,6 +69,8 @@
 
 #include <netinet/in.h> /* android-added: glibc source compatibility. */
 
+__BEGIN_DECLS
+
 #define ICMPV6_PLD_MAXLEN	1232	/* IPV6_MMTU - sizeof(struct ip6_hdr)
 					   - sizeof(struct icmp6_hdr) */
 
@@ -513,4 +515,6 @@
  * END android-changed
  */
 
+__END_DECLS
+
 #endif /* !_NETINET_ICMP6_H_ */
diff --git a/libc/include/netinet/if_ether.h b/libc/include/netinet/if_ether.h
index b1b9ed0..7dc419e 100644
--- a/libc/include/netinet/if_ether.h
+++ b/libc/include/netinet/if_ether.h
@@ -31,40 +31,32 @@
  *	@(#)if_ether.h	8.3 (Berkeley) 5/2/95
  */
 
-#ifndef _NETINET_IF_ETHER_H_
-#define _NETINET_IF_ETHER_H_
+#pragma once
 
 #include <sys/cdefs.h>
 #include <sys/types.h>
-
-#if defined(__USE_BSD)
-
-/* pull in Ethernet-specific definitions and packet structures */
-
 #include <linux/if_ether.h>
-
-/* pull in ARP-specific definitions and packet structures */
-
+#include <net/ethernet.h>
 #include <net/if_arp.h>
 
-#include <net/ethernet.h>
+__BEGIN_DECLS
 
-/* ... and define some more which we don't need anymore: */
-
-/*
+/**
  * Ethernet Address Resolution Protocol.
  *
- * See RFC 826 for protocol description.  Structure below is not
- * used by our kernel!!! Only for userland programs which are externally
- * maintained and need it.
+ * See RFC 826 for protocol description.
  */
-
-struct	ether_arp {
-	struct	 arphdr ea_hdr;			/* fixed-size header */
-	u_int8_t arp_sha[ETHER_ADDR_LEN];	/* sender hardware address */
-	u_int8_t arp_spa[4];			/* sender protocol address */
-	u_int8_t arp_tha[ETHER_ADDR_LEN];	/* target hardware address */
-	u_int8_t arp_tpa[4];			/* target protocol address */
+struct ether_arp {
+	/** Fixed-size header. */
+	struct arphdr ea_hdr;
+	/** Sender hardware address. */
+	u_int8_t arp_sha[ETHER_ADDR_LEN];
+	/** Sender protocol address. */
+	u_int8_t arp_spa[4];
+  /** Target hardware address. */
+  u_int8_t arp_tha[ETHER_ADDR_LEN];
+  /** Target protocol address. */
+  u_int8_t arp_tpa[4];
 } __packed;
 #define	arp_hrd	ea_hdr.ar_hrd
 #define	arp_pro	ea_hdr.ar_pro
@@ -72,8 +64,8 @@
 #define	arp_pln	ea_hdr.ar_pln
 #define	arp_op	ea_hdr.ar_op
 
-/*
- * Macro to map an IP multicast address to an Ethernet multicast address.
+/**
+ * Maps an IP multicast address to an Ethernet multicast address.
  * The high-order 25 bits of the Ethernet address are statically assigned,
  * and the low-order 23 bits are taken from the low end of the IP address.
  */
@@ -88,8 +80,9 @@
 	(enaddr)[4] = ((u_int8_t *)ipaddr)[2];				\
 	(enaddr)[5] = ((u_int8_t *)ipaddr)[3];				\
 }
-/*
- * Macro to map an IP6 multicast address to an Ethernet multicast address.
+
+/**
+ * Maps an IP6 multicast address to an Ethernet multicast address.
  * The high-order 16 bits of the Ethernet address are statically assigned,
  * and the low-order 32 bits are taken from the low end of the IP6 address.
  */
@@ -105,6 +98,4 @@
 	(enaddr)[5] = ((u_int8_t *)ip6addr)[15];			\
 }
 
-#endif /* __USE_BSD */
-
-#endif /* !_NET_IF_ETHER_H_ */
+__END_DECLS
diff --git a/libc/include/netinet/igmp.h b/libc/include/netinet/igmp.h
index 497d02d..a0c1a7c 100644
--- a/libc/include/netinet/igmp.h
+++ b/libc/include/netinet/igmp.h
@@ -38,6 +38,8 @@
 
 #include <linux/igmp.h>
 
+__BEGIN_DECLS
+
 /**
  * The uapi type is called `igmphdr`,
  * doesn't have the `igmp_` prefix on each field,
@@ -54,3 +56,5 @@
 
 /** Commonly-used BSD synonym for the Linux constant. */
 #define IGMP_MEMBERSHIP_QUERY IGMP_HOST_MEMBERSHIP_QUERY
+
+__END_DECLS
diff --git a/libc/include/netinet/in6.h b/libc/include/netinet/in6.h
index 44b3e3e..ffe86d0 100644
--- a/libc/include/netinet/in6.h
+++ b/libc/include/netinet/in6.h
@@ -33,6 +33,8 @@
 
 #include <linux/in6.h>
 
+__BEGIN_DECLS
+
 #define IN6_IS_ADDR_UNSPECIFIED(a) \
   ((((a)->s6_addr32[0]) == 0) && \
    (((a)->s6_addr32[1]) == 0) && \
@@ -101,4 +103,6 @@
 
 #define ipv6mr_interface ipv6mr_ifindex
 
+__END_DECLS
+
 #endif /* _NETINET_IN6_H */
diff --git a/libc/include/netinet/in_systm.h b/libc/include/netinet/in_systm.h
index 8da19a5..cc74ba8 100644
--- a/libc/include/netinet/in_systm.h
+++ b/libc/include/netinet/in_systm.h
@@ -37,6 +37,8 @@
 #include <sys/cdefs.h>
 #include <sys/types.h>
 
+__BEGIN_DECLS
+
 /*
  * Miscellaneous internetwork
  * definitions for kernel.
@@ -55,4 +57,6 @@
 
 typedef u_int32_t n_time;		/* ms since 00:00 GMT, byte rev */
 
+__END_DECLS
+
 #endif /* !_NETINET_IN_SYSTM_H_ */
diff --git a/libc/include/netinet/ip6.h b/libc/include/netinet/ip6.h
index b4f6ce6..ed7eace 100644
--- a/libc/include/netinet/ip6.h
+++ b/libc/include/netinet/ip6.h
@@ -70,6 +70,8 @@
 
 #include <linux/in6.h>
 
+__BEGIN_DECLS
+
 /*
  * Definition for internet protocol version 6.
  * RFC 2460
@@ -239,4 +241,6 @@
 #define IPV6_MMTU	1280	/* minimal MTU and reassembly. 1024 + 256 */
 #define IPV6_MAXPACKET	65535	/* ip6 max packet size without Jumbo payload*/
 
+__END_DECLS
+
 #endif /* !_NETINET_IP6_H_ */
diff --git a/libc/include/netinet/udp.h b/libc/include/netinet/udp.h
index ef517d6..40a04d9 100644
--- a/libc/include/netinet/udp.h
+++ b/libc/include/netinet/udp.h
@@ -34,6 +34,8 @@
 
 #include <linux/udp.h>
 
+__BEGIN_DECLS
+
 struct udphdr {
     __extension__ union {
         struct /* BSD names */ {
@@ -51,4 +53,6 @@
     };
 };
 
+__END_DECLS
+
 #endif /* _NETINET_UDP_H */
diff --git a/libc/include/nl_types.h b/libc/include/nl_types.h
index 172d80d..a4b1d7a 100644
--- a/libc/include/nl_types.h
+++ b/libc/include/nl_types.h
@@ -62,9 +62,9 @@
  *
  * Available since API level 28.
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(26)
 nl_catd _Nonnull catopen(const char* _Nonnull __name, int __flag) __INTRODUCED_IN(26);
+#endif /* __BIONIC_AVAILABILITY_GUARD(26) */
 
 /**
  * [catgets(3)](https://man7.org/linux/man-pages/man3/catgets.3.html) translates the given message
@@ -74,15 +74,17 @@
  *
  * Available since API level 28.
  */
+#if __BIONIC_AVAILABILITY_GUARD(26)
 char* _Nonnull catgets(nl_catd _Nonnull __catalog, int __set_number, int __msg_number, const char* _Nonnull __msg) __INTRODUCED_IN(26);
+#endif /* __BIONIC_AVAILABILITY_GUARD(26) */
 
 /**
  * [catclose(3)](https://man7.org/linux/man-pages/man3/catclose.3.html) closes a message catalog.
  *
  * On Android, this always returns -1 with `errno` set to `EBADF`.
  */
+#if __BIONIC_AVAILABILITY_GUARD(26)
 int catclose(nl_catd _Nonnull __catalog) __INTRODUCED_IN(26);
 #endif /* __BIONIC_AVAILABILITY_GUARD(26) */
 
-
 __END_DECLS
diff --git a/libc/include/paths.h b/libc/include/paths.h
index 9116f4e..477c9b6 100644
--- a/libc/include/paths.h
+++ b/libc/include/paths.h
@@ -38,6 +38,8 @@
 
 #include <sys/cdefs.h>
 
+__BEGIN_DECLS
+
 /** Path to the default system shell. Historically the 'B' was to specify the Bourne shell. */
 #define _PATH_BSHELL "/system/bin/sh"
 
@@ -61,3 +63,5 @@
 
 /** Path to the calling process' tty. */
 #define _PATH_TTY "/dev/tty"
+
+__END_DECLS
diff --git a/libc/include/poll.h b/libc/include/poll.h
index e57f812..873f970 100644
--- a/libc/include/poll.h
+++ b/libc/include/poll.h
@@ -69,7 +69,6 @@
 int ppoll64(struct pollfd* _Nullable  __fds, nfds_t __count, const struct timespec* _Nullable __timeout, const sigset64_t* _Nullable __mask) __INTRODUCED_IN(28);
 #endif /* __BIONIC_AVAILABILITY_GUARD(28) */
 
-
 #if defined(__BIONIC_INCLUDE_FORTIFY_HEADERS)
 #define _POLL_H_
 #include <bits/fortify/poll.h>
diff --git a/libc/include/pthread.h b/libc/include/pthread.h
index 5a3376a..06c952b 100644
--- a/libc/include/pthread.h
+++ b/libc/include/pthread.h
@@ -314,25 +314,46 @@
 
 #if __BIONIC_AVAILABILITY_GUARD(24)
 int pthread_barrierattr_init(pthread_barrierattr_t* _Nonnull __attr) __INTRODUCED_IN(24);
+#endif /* __BIONIC_AVAILABILITY_GUARD(24) */
+#if __BIONIC_AVAILABILITY_GUARD(24)
 int pthread_barrierattr_destroy(pthread_barrierattr_t* _Nonnull __attr) __INTRODUCED_IN(24);
+#endif /* __BIONIC_AVAILABILITY_GUARD(24) */
+#if __BIONIC_AVAILABILITY_GUARD(24)
 int pthread_barrierattr_getpshared(const pthread_barrierattr_t* _Nonnull __attr, int* _Nonnull __shared) __INTRODUCED_IN(24);
+#endif /* __BIONIC_AVAILABILITY_GUARD(24) */
+#if __BIONIC_AVAILABILITY_GUARD(24)
 int pthread_barrierattr_setpshared(pthread_barrierattr_t* _Nonnull __attr, int __shared) __INTRODUCED_IN(24);
+#endif /* __BIONIC_AVAILABILITY_GUARD(24) */
 
+#if __BIONIC_AVAILABILITY_GUARD(24)
 int pthread_barrier_init(pthread_barrier_t* _Nonnull __barrier, const pthread_barrierattr_t* _Nullable __attr, unsigned __count) __INTRODUCED_IN(24);
+#endif /* __BIONIC_AVAILABILITY_GUARD(24) */
+#if __BIONIC_AVAILABILITY_GUARD(24)
 int pthread_barrier_destroy(pthread_barrier_t* _Nonnull __barrier) __INTRODUCED_IN(24);
+#endif /* __BIONIC_AVAILABILITY_GUARD(24) */
+#if __BIONIC_AVAILABILITY_GUARD(24)
 int pthread_barrier_wait(pthread_barrier_t* _Nonnull __barrier) __INTRODUCED_IN(24);
+#endif /* __BIONIC_AVAILABILITY_GUARD(24) */
 
+#if __BIONIC_AVAILABILITY_GUARD(24)
 int pthread_spin_destroy(pthread_spinlock_t* _Nonnull __spinlock) __INTRODUCED_IN(24);
+#endif /* __BIONIC_AVAILABILITY_GUARD(24) */
+#if __BIONIC_AVAILABILITY_GUARD(24)
 int pthread_spin_init(pthread_spinlock_t* _Nonnull __spinlock, int __shared) __INTRODUCED_IN(24);
+#endif /* __BIONIC_AVAILABILITY_GUARD(24) */
+#if __BIONIC_AVAILABILITY_GUARD(24)
 int pthread_spin_lock(pthread_spinlock_t* _Nonnull __spinlock) __INTRODUCED_IN(24);
+#endif /* __BIONIC_AVAILABILITY_GUARD(24) */
+#if __BIONIC_AVAILABILITY_GUARD(24)
 int pthread_spin_trylock(pthread_spinlock_t* _Nonnull __spinlock) __INTRODUCED_IN(24);
+#endif /* __BIONIC_AVAILABILITY_GUARD(24) */
+#if __BIONIC_AVAILABILITY_GUARD(24)
 int pthread_spin_unlock(pthread_spinlock_t* _Nonnull __spinlock) __INTRODUCED_IN(24);
 #endif /* __BIONIC_AVAILABILITY_GUARD(24) */
 
 
 pthread_t pthread_self(void) __attribute_const__;
 
-#if defined(__USE_GNU) && __BIONIC_AVAILABILITY_GUARD(26)
 /**
  * [pthread_getname_np(3)](https://man7.org/linux/man-pages/man3/pthread_getname_np.3.html)
  * gets the name of the given thread.
@@ -340,8 +361,9 @@
  *
  * Returns 0 on success and returns an error number on failure.
  *
- * Available since API level 26.
+ * Available since API level 26 when compiling with `_GNU_SOURCE`.
  */
+#if defined(__USE_GNU) && __BIONIC_AVAILABILITY_GUARD(26)
 int pthread_getname_np(pthread_t __pthread, char* _Nonnull __buf, size_t __n) __INTRODUCED_IN(26);
 #endif
 
@@ -365,7 +387,7 @@
  *
  * Returns 0 on success and returns an error number on failure.
  *
- * Available since API level 36.
+ * Available since API level 36 when compiling with `_GNU_SOURCE`.
  * See sched_getaffinity() and pthread_gettid_np() for greater portability.
  */
 #if defined(__USE_GNU) && __BIONIC_AVAILABILITY_GUARD(36)
@@ -378,7 +400,7 @@
  *
  * Returns 0 on success and returns an error number on failure.
  *
- * Available since API level 36.
+ * Available since API level 36 when compiling with `_GNU_SOURCE`.
  * See sched_getaffinity() and pthread_gettid_np() for greater portability.
  */
 #if defined(__USE_GNU) && __BIONIC_AVAILABILITY_GUARD(36)
diff --git a/libc/include/pty.h b/libc/include/pty.h
index 92d7fbb..dce7691 100644
--- a/libc/include/pty.h
+++ b/libc/include/pty.h
@@ -49,9 +49,9 @@
  *
  * Available since API level 23.
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(23)
 int openpty(int* _Nonnull __pty_fd, int* _Nonnull __tty_fd, char* _Nullable __tty_name, const struct termios* _Nullable __termios_ptr, const struct winsize* _Nullable __winsize_ptr) __INTRODUCED_IN(23);
+#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
 /**
  * [forkpty(3)](https://man7.org/linux/man-pages/man3/forkpty.3.html) creates
@@ -62,8 +62,8 @@
  *
  * Available since API level 23.
  */
+#if __BIONIC_AVAILABILITY_GUARD(23)
 int forkpty(int* _Nonnull __parent_pty_fd, char* _Nullable __child_tty_name, const struct termios* _Nullable __termios_ptr, const struct winsize* _Nullable __winsize_ptr) __INTRODUCED_IN(23);
 #endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
-
 __END_DECLS
diff --git a/libc/include/pwd.h b/libc/include/pwd.h
index 09592bc..464c45b 100644
--- a/libc/include/pwd.h
+++ b/libc/include/pwd.h
@@ -87,11 +87,15 @@
 
 #if __BIONIC_AVAILABILITY_GUARD(26)
 struct passwd* _Nullable getpwent(void) __INTRODUCED_IN(26);
-
-void setpwent(void) __INTRODUCED_IN(26);
-void endpwent(void) __INTRODUCED_IN(26);
 #endif /* __BIONIC_AVAILABILITY_GUARD(26) */
 
+#if __BIONIC_AVAILABILITY_GUARD(26)
+void setpwent(void) __INTRODUCED_IN(26);
+#endif /* __BIONIC_AVAILABILITY_GUARD(26) */
+
+#if __BIONIC_AVAILABILITY_GUARD(26)
+void endpwent(void) __INTRODUCED_IN(26);
+#endif /* __BIONIC_AVAILABILITY_GUARD(26) */
 
 int getpwnam_r(const char* _Nonnull __name, struct passwd* _Nonnull __pwd, char* _Nonnull __buf, size_t __n, struct passwd* _Nullable * _Nonnull __result);
 int getpwuid_r(uid_t __uid, struct passwd* _Nonnull __pwd, char* _Nonnull __buf, size_t __n, struct passwd* _Nullable * _Nonnull __result);
diff --git a/libc/include/regex.h b/libc/include/regex.h
index be33819..3107591 100644
--- a/libc/include/regex.h
+++ b/libc/include/regex.h
@@ -42,6 +42,8 @@
 #include <sys/cdefs.h>
 #include <sys/types.h>
 
+__BEGIN_DECLS
+
 /* POSIX says regoff_t is at least as large as the larger of ptrdiff_t and
  * ssize_t. BSD uses off_t, but that interacts badly with _FILE_OFFSET_BITS. */
 typedef ssize_t regoff_t;
@@ -98,11 +100,12 @@
 #define	REG_LARGE	01000	/* force large representation */
 #define	REG_BACKR	02000	/* force use of backref code */
 
-__BEGIN_DECLS
+
 int regcomp(regex_t* _Nonnull __re, const char* _Nonnull __regex, int __flags);
 size_t regerror(int __error_code, const regex_t* _Nullable __re, char* _Nullable __buf, size_t __n);
 int regexec(const regex_t* _Nonnull __re, const char* _Nonnull __s, size_t __match_count, regmatch_t __matches[_Nullable], int __flags);
 void regfree(regex_t* _Nonnull __re);
+
 __END_DECLS
 
 #endif
diff --git a/libc/include/resolv.h b/libc/include/resolv.h
index c49cefc..d0f246c 100644
--- a/libc/include/resolv.h
+++ b/libc/include/resolv.h
@@ -66,7 +66,6 @@
 u_int __res_randomid(void) __INTRODUCED_IN(29);
 #endif /* __BIONIC_AVAILABILITY_GUARD(29) */
 
-
 __END_DECLS
 
 #endif
diff --git a/libc/include/sched.h b/libc/include/sched.h
index c68ebf0..4b67538 100644
--- a/libc/include/sched.h
+++ b/libc/include/sched.h
@@ -165,8 +165,6 @@
  */
 int sched_rr_get_interval(pid_t __pid, struct timespec* _Nonnull __quantum);
 
-#if defined(__USE_GNU)
-
 /**
  * [clone(2)](https://man7.org/linux/man-pages/man2/clone.2.html)
  * creates a new child process.
@@ -174,7 +172,9 @@
  * Returns the pid of the child to the caller on success and
  * returns -1 and sets `errno` on failure.
  */
+#if defined(__USE_GNU)
 int clone(int (* __BIONIC_COMPLICATED_NULLNESS __fn)(void* __BIONIC_COMPLICATED_NULLNESS ), void* __BIONIC_COMPLICATED_NULLNESS __child_stack, int __flags, void* _Nullable __arg, ...);
+#endif
 
 /**
  * [unshare(2)](https://man7.org/linux/man-pages/man2/unshare.2.html)
@@ -182,7 +182,9 @@
  *
  * Returns 0 on success and returns -1 and sets `errno` on failure.
  */
+#if defined(__USE_GNU)
 int unshare(int __flags);
+#endif
 
 /**
  * [setns(2)](https://man7.org/linux/man-pages/man2/setns.2.html)
@@ -190,7 +192,9 @@
  *
  * Returns 0 on success and returns -1 and sets `errno` on failure.
  */
+#if defined(__USE_GNU)
 int setns(int __fd, int __ns_type);
+#endif
 
 /**
  * [sched_getcpu(3)](https://man7.org/linux/man-pages/man3/sched_getcpu.3.html)
@@ -199,26 +203,43 @@
  * Returns a non-negative CPU number on success and returns -1 and sets
  * `errno` on failure.
  */
+#if defined(__USE_GNU)
 int sched_getcpu(void);
+#endif
 
+#if defined(__USE_GNU)
 #ifdef __LP64__
 #define CPU_SETSIZE 1024
 #else
 #define CPU_SETSIZE 32
 #endif
+#endif
 
+#if defined(__USE_GNU)
 #define __CPU_BITTYPE  unsigned long int  /* mandated by the kernel  */
+#endif
+
+#if defined(__USE_GNU)
 #define __CPU_BITS     (8 * sizeof(__CPU_BITTYPE))
+#endif
+
+#if defined(__USE_GNU)
 #define __CPU_ELT(x)   ((x) / __CPU_BITS)
+#endif
+
+#if defined(__USE_GNU)
 #define __CPU_MASK(x)  ((__CPU_BITTYPE)1 << ((x) & (__CPU_BITS - 1)))
+#endif
 
 /**
  * [cpu_set_t](https://man7.org/linux/man-pages/man3/CPU_SET.3.html) is a
  * statically-sized CPU set. See `CPU_ALLOC` for dynamically-sized CPU sets.
  */
+#if defined(__USE_GNU)
 typedef struct {
   __CPU_BITTYPE  __bits[ CPU_SETSIZE / __CPU_BITS ];
 } cpu_set_t;
+#endif
 
 /**
  * [sched_setaffinity(2)](https://man7.org/linux/man-pages/man2/sched_setaffinity.2.html)
@@ -226,7 +247,9 @@
  *
  * Returns 0 on success and returns -1 and sets `errno` on failure.
  */
-int sched_setaffinity(pid_t __pid, size_t __set_size, const cpu_set_t* _Nonnull __set);
+#if defined(__USE_GNU)
+int sched_setaffinity(pid_t __pid, size_t __cpu_set_size, const cpu_set_t* _Nonnull __cpu_set);
+#endif
 
 /**
  * [sched_getaffinity(2)](https://man7.org/linux/man-pages/man2/sched_getaffinity.2.html)
@@ -234,15 +257,22 @@
  *
  * Returns 0 on success and returns -1 and sets `errno` on failure.
  */
-int sched_getaffinity(pid_t __pid, size_t __set_size, cpu_set_t* _Nonnull __set);
+#if defined(__USE_GNU)
+int sched_getaffinity(pid_t __pid, size_t __cpu_set_size, cpu_set_t* _Nonnull __cpu_set);
+#endif
 
 /**
  * [sched_setattr(2)](https://man7.org/linux/man-pages/man2/sched_setattr.2.html)
  * sets the scheduling attributes for the given thread.
  *
  * Returns 0 on success and returns -1 and sets `errno` on failure.
+ * If the failure is E2BIG,
+ * the kernel writes the expected size into the given `sched_attr`,
+ * which is why that argument is not `const`.
  */
+#if defined(__USE_GNU)
 int sched_setattr(pid_t __pid, struct sched_attr* _Nonnull __attr, unsigned __flags) __INTRODUCED_IN(37);
+#endif
 
 /**
  * [sched_getattr(2)](https://man7.org/linux/man-pages/man2/sched_getattr.2.html)
@@ -250,60 +280,81 @@
  *
  * Returns 0 on success and returns -1 and sets `errno` on failure.
  */
+#if defined(__USE_GNU)
 int sched_getattr(pid_t __pid, struct sched_attr* _Nonnull __attr, unsigned __size, unsigned __flags) __INTRODUCED_IN(37);
+#endif
 
 /**
  * [CPU_ZERO](https://man7.org/linux/man-pages/man3/CPU_ZERO.3.html) clears all
  * bits in a static CPU set.
  */
+#if defined(__USE_GNU)
 #define CPU_ZERO(set)          CPU_ZERO_S(sizeof(cpu_set_t), set)
+#endif
+
 /**
  * [CPU_ZERO_S](https://man7.org/linux/man-pages/man3/CPU_ZERO_S.3.html) clears all
  * bits in a dynamic CPU set allocated by `CPU_ALLOC`.
  */
+#if defined(__USE_GNU)
 #define CPU_ZERO_S(setsize, set)  __builtin_memset(set, 0, setsize)
+#endif
 
 /**
  * [CPU_SET](https://man7.org/linux/man-pages/man3/CPU_SET.3.html) sets one
  * bit in a static CPU set.
  */
+#if defined(__USE_GNU)
 #define CPU_SET(cpu, set)      CPU_SET_S(cpu, sizeof(cpu_set_t), set)
+#endif
+
 /**
  * [CPU_SET_S](https://man7.org/linux/man-pages/man3/CPU_SET_S.3.html) sets one
  * bit in a dynamic CPU set allocated by `CPU_ALLOC`.
  */
+#if defined(__USE_GNU)
 #define CPU_SET_S(cpu, setsize, set) \
   do { \
     size_t __cpu = (cpu); \
     if (__cpu < 8 * (setsize)) \
       (set)->__bits[__CPU_ELT(__cpu)] |= __CPU_MASK(__cpu); \
   } while (0)
+#endif
 
 /**
  * [CPU_CLR](https://man7.org/linux/man-pages/man3/CPU_CLR.3.html) clears one
  * bit in a static CPU set.
  */
+#if defined(__USE_GNU)
 #define CPU_CLR(cpu, set)      CPU_CLR_S(cpu, sizeof(cpu_set_t), set)
+#endif
+
 /**
  * [CPU_CLR_S](https://man7.org/linux/man-pages/man3/CPU_CLR_S.3.html) clears one
  * bit in a dynamic CPU set allocated by `CPU_ALLOC`.
  */
+#if defined(__USE_GNU)
 #define CPU_CLR_S(cpu, setsize, set) \
   do { \
     size_t __cpu = (cpu); \
     if (__cpu < 8 * (setsize)) \
       (set)->__bits[__CPU_ELT(__cpu)] &= ~__CPU_MASK(__cpu); \
   } while (0)
+#endif
 
 /**
  * [CPU_ISSET](https://man7.org/linux/man-pages/man3/CPU_ISSET.3.html) tests
  * whether the given bit is set in a static CPU set.
  */
+#if defined(__USE_GNU)
 #define CPU_ISSET(cpu, set)    CPU_ISSET_S(cpu, sizeof(cpu_set_t), set)
+#endif
+
 /**
  * [CPU_ISSET_S](https://man7.org/linux/man-pages/man3/CPU_ISSET_S.3.html) tests
  * whether the given bit is set in a dynamic CPU set allocated by `CPU_ALLOC`.
  */
+#if defined(__USE_GNU)
 #define CPU_ISSET_S(cpu, setsize, set) \
   (__extension__ ({ \
     size_t __cpu = (cpu); \
@@ -311,66 +362,95 @@
       ? ((set)->__bits[__CPU_ELT(__cpu)] & __CPU_MASK(__cpu)) != 0 \
       : 0; \
   }))
+#endif
 
 /**
  * [CPU_COUNT](https://man7.org/linux/man-pages/man3/CPU_COUNT.3.html) counts
  * how many bits are set in a static CPU set.
  */
+#if defined(__USE_GNU)
 #define CPU_COUNT(set)         CPU_COUNT_S(sizeof(cpu_set_t), set)
+#endif
+
 /**
  * [CPU_COUNT_S](https://man7.org/linux/man-pages/man3/CPU_COUNT_S.3.html) counts
  * how many bits are set in a dynamic CPU set allocated by `CPU_ALLOC`.
  */
+#if defined(__USE_GNU)
 #define CPU_COUNT_S(setsize, set)  __sched_cpucount((setsize), (set))
-int __sched_cpucount(size_t __set_size, const cpu_set_t* _Nonnull __set);
+int __sched_cpucount(size_t __cpu_set_size, const cpu_set_t* _Nonnull __cpu_set);
+#endif
 
 /**
  * [CPU_EQUAL](https://man7.org/linux/man-pages/man3/CPU_EQUAL.3.html) tests
  * whether two static CPU sets have the same bits set and cleared as each other.
  */
+#if defined(__USE_GNU)
 #define CPU_EQUAL(set1, set2)  CPU_EQUAL_S(sizeof(cpu_set_t), set1, set2)
+#endif
+
 /**
  * [CPU_EQUAL_S](https://man7.org/linux/man-pages/man3/CPU_EQUAL_S.3.html) tests
  * whether two dynamic CPU sets allocated by `CPU_ALLOC` have the same bits
  * set and cleared as each other.
  */
+#if defined(__USE_GNU)
 #define CPU_EQUAL_S(setsize, set1, set2)  (__builtin_memcmp(set1, set2, setsize) == 0)
+#endif
 
 /**
  * [CPU_AND](https://man7.org/linux/man-pages/man3/CPU_AND.3.html) ands two
  * static CPU sets.
  */
+#if defined(__USE_GNU)
 #define CPU_AND(dst, set1, set2)  __CPU_OP(dst, set1, set2, &)
+#endif
+
 /**
  * [CPU_AND_S](https://man7.org/linux/man-pages/man3/CPU_AND_S.3.html) ands two
  * dynamic CPU sets allocated by `CPU_ALLOC`.
  */
+#if defined(__USE_GNU)
 #define CPU_AND_S(setsize, dst, set1, set2)  __CPU_OP_S(setsize, dst, set1, set2, &)
+#endif
 
 /**
  * [CPU_OR](https://man7.org/linux/man-pages/man3/CPU_OR.3.html) ors two
  * static CPU sets.
  */
+#if defined(__USE_GNU)
 #define CPU_OR(dst, set1, set2)   __CPU_OP(dst, set1, set2, |)
+#endif
+
 /**
  * [CPU_OR_S](https://man7.org/linux/man-pages/man3/CPU_OR_S.3.html) ors two
  * dynamic CPU sets allocated by `CPU_ALLOC`.
  */
+#if defined(__USE_GNU)
 #define CPU_OR_S(setsize, dst, set1, set2)   __CPU_OP_S(setsize, dst, set1, set2, |)
+#endif
 
 /**
  * [CPU_XOR](https://man7.org/linux/man-pages/man3/CPU_XOR.3.html)
  * exclusive-ors two static CPU sets.
  */
+#if defined(__USE_GNU)
 #define CPU_XOR(dst, set1, set2)  __CPU_OP(dst, set1, set2, ^)
+#endif
+
 /**
  * [CPU_XOR_S](https://man7.org/linux/man-pages/man3/CPU_XOR_S.3.html)
  * exclusive-ors two dynamic CPU sets allocated by `CPU_ALLOC`.
  */
+#if defined(__USE_GNU)
 #define CPU_XOR_S(setsize, dst, set1, set2)  __CPU_OP_S(setsize, dst, set1, set2, ^)
+#endif
 
+#if defined(__USE_GNU)
 #define __CPU_OP(dst, set1, set2, op)  __CPU_OP_S(sizeof(cpu_set_t), dst, set1, set2, op)
+#endif
 
+#if defined(__USE_GNU)
 #define __CPU_OP_S(setsize, dstset, srcset1, srcset2, op) \
   do { \
     cpu_set_t* __dst = (dstset); \
@@ -380,28 +460,33 @@
     for (; __nn < __nn_max; __nn++) \
       (__dst)->__bits[__nn] = __src1[__nn] op __src2[__nn]; \
   } while (0)
+#endif
 
 /**
  * [CPU_ALLOC_SIZE](https://man7.org/linux/man-pages/man3/CPU_ALLOC_SIZE.3.html)
  * returns the size of a CPU set large enough for CPUs in the range 0..count-1.
  */
+#if defined(__USE_GNU)
 #define CPU_ALLOC_SIZE(count) \
   __CPU_ELT((count) + (__CPU_BITS - 1)) * sizeof(__CPU_BITTYPE)
+#endif
 
 /**
  * [CPU_ALLOC](https://man7.org/linux/man-pages/man3/CPU_ALLOC.3.html)
  * allocates a CPU set large enough for CPUs in the range 0..count-1.
  */
+#if defined(__USE_GNU)
 #define CPU_ALLOC(count)  __sched_cpualloc((count))
 cpu_set_t* _Nullable __sched_cpualloc(size_t __count);
+#endif
 
 /**
  * [CPU_FREE](https://man7.org/linux/man-pages/man3/CPU_FREE.3.html)
  * deallocates a CPU set allocated by `CPU_ALLOC`.
  */
+#if defined(__USE_GNU)
 #define CPU_FREE(set)     __sched_cpufree((set))
-void __sched_cpufree(cpu_set_t* _Nonnull __set);
-
-#endif /* __USE_GNU */
+void __sched_cpufree(cpu_set_t* _Nonnull __cpu_set);
+#endif
 
 __END_DECLS
diff --git a/libc/include/search.h b/libc/include/search.h
index 2f43d91..ff6a47a 100644
--- a/libc/include/search.h
+++ b/libc/include/search.h
@@ -16,6 +16,8 @@
 #include <sys/cdefs.h>
 #include <sys/types.h>
 
+__BEGIN_DECLS
+
 /** See hsearch()/hsearch_r(). */
 typedef enum {
   FIND,
@@ -54,15 +56,13 @@
   leaf
 } VISIT;
 
-#if defined(__USE_BSD) || defined(__USE_GNU)
 /** The hash table type for hcreate_r()/hdestroy_r()/hsearch_r(). */
+#if defined(__USE_BSD) || defined(__USE_GNU)
 struct hsearch_data {
-  struct __hsearch* _Nullable __hsearch;
+  void* _Nullable __opaque;
 };
 #endif
 
-__BEGIN_DECLS
-
 /**
  * [insque(3)](https://man7.org/linux/man-pages/man3/insque.3.html) inserts
  * an item in a queue (an intrusive doubly-linked list).
@@ -85,9 +85,9 @@
  *
  * Available since API level 28.
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(28)
 int hcreate(size_t __n) __INTRODUCED_IN(28);
+#endif /* __BIONIC_AVAILABILITY_GUARD(28) */
 
 /**
  * [hdestroy(3)](https://man7.org/linux/man-pages/man3/hdestroy.3.html) destroys
@@ -97,7 +97,9 @@
  *
  * Available since API level 28.
  */
+#if __BIONIC_AVAILABILITY_GUARD(28)
 void hdestroy(void) __INTRODUCED_IN(28);
+#endif /* __BIONIC_AVAILABILITY_GUARD(28) */
 
 /**
  * [hsearch(3)](https://man7.org/linux/man-pages/man3/hsearch.3.html) finds or
@@ -110,31 +112,31 @@
  *
  * Available since API level 28.
  */
+#if __BIONIC_AVAILABILITY_GUARD(28)
 ENTRY* _Nullable hsearch(ENTRY __entry, ACTION __action) __INTRODUCED_IN(28);
 #endif /* __BIONIC_AVAILABILITY_GUARD(28) */
 
-
-#if defined(__USE_BSD) || defined(__USE_GNU)
-
 /**
  * [hcreate_r(3)](https://man7.org/linux/man-pages/man3/hcreate_r.3.html)
  * initializes a hash table `__table` with space for at least `__n` elements.
  *
  * Returns *non-zero* on success and returns 0 and sets `errno` on failure.
  *
- * Available since API level 28.
+ * Available since API level 28 when compiling with `_BSD_SOURCE` or `_GNU_SOURCE`.
  */
-
-#if __BIONIC_AVAILABILITY_GUARD(28)
+#if (defined(__USE_BSD) || defined(__USE_GNU)) && __BIONIC_AVAILABILITY_GUARD(28)
 int hcreate_r(size_t __n, struct hsearch_data* _Nonnull __table) __INTRODUCED_IN(28);
+#endif
 
 /**
  * [hdestroy_r(3)](https://man7.org/linux/man-pages/man3/hdestroy_r.3.html) destroys
  * the hash table `__table`.
  *
- * Available since API level 28.
+ * Available since API level 28 when compiling with `_BSD_SOURCE` or `_GNU_SOURCE`.
  */
+#if (defined(__USE_BSD) || defined(__USE_GNU)) && __BIONIC_AVAILABILITY_GUARD(28)
 void hdestroy_r(struct hsearch_data* _Nonnull __table) __INTRODUCED_IN(28);
+#endif
 
 /**
  * [hsearch_r(3)](https://man7.org/linux/man-pages/man3/hsearch_r.3.html) finds or
@@ -143,12 +145,10 @@
  * Returns *non-zero* on success and returns 0 and sets `errno` on failure.
  * A pointer to the entry is returned in `*__result`.
  *
- * Available since API level 28.
+ * Available since API level 28 when compiling with `_BSD_SOURCE` or `_GNU_SOURCE`.
  */
+#if (defined(__USE_BSD) || defined(__USE_GNU)) && __BIONIC_AVAILABILITY_GUARD(28)
 int hsearch_r(ENTRY __entry, ACTION __action, ENTRY* _Nullable * _Nonnull __result, struct hsearch_data* _Nonnull __table) __INTRODUCED_IN(28);
-#endif /* __BIONIC_AVAILABILITY_GUARD(28) */
-
-
 #endif
 
 /**
diff --git a/libc/include/semaphore.h b/libc/include/semaphore.h
index 9c4702d..08ee491 100644
--- a/libc/include/semaphore.h
+++ b/libc/include/semaphore.h
@@ -45,7 +45,6 @@
 
 #define SEM_FAILED __BIONIC_CAST(reinterpret_cast, sem_t*, 0)
 
-
 #if __BIONIC_AVAILABILITY_GUARD(30)
 int sem_clockwait(sem_t* _Nonnull __sem, clockid_t __clock, const struct timespec* _Nonnull __ts) __INTRODUCED_IN(30);
 #endif /* __BIONIC_AVAILABILITY_GUARD(30) */
diff --git a/libc/include/setjmp.h b/libc/include/setjmp.h
index 6c141cb..0236fe6 100644
--- a/libc/include/setjmp.h
+++ b/libc/include/setjmp.h
@@ -46,6 +46,8 @@
 
 #include <sys/cdefs.h>
 
+__BEGIN_DECLS
+
 #if defined(__aarch64__)
 /**
  * The size in words of an arm64 jmp_buf. Room for callee-saved registers,
@@ -87,8 +89,6 @@
 
 #undef _JBLEN
 
-__BEGIN_DECLS
-
 /**
  * Equivalent to sigsetjmp() with the second argument 0, so that the signal
  * mask is not saved.
diff --git a/libc/include/signal.h b/libc/include/signal.h
index 38dcbde..c4b6b13 100644
--- a/libc/include/signal.h
+++ b/libc/include/signal.h
@@ -65,7 +65,6 @@
 int sigaction64(int __signal, const struct sigaction64* _Nullable __new_action, struct sigaction64* _Nullable __old_action) __INTRODUCED_IN(28);
 #endif /* __BIONIC_AVAILABILITY_GUARD(28) */
 
-
 int siginterrupt(int __signal, int __flag);
 
 sighandler_t _Nonnull signal(int __signal, sighandler_t _Nullable __handler);
@@ -124,23 +123,32 @@
 int sigwait64(const sigset64_t* _Nonnull __set, int* _Nonnull __signal) __INTRODUCED_IN(28);
 #endif /* __BIONIC_AVAILABILITY_GUARD(28) */
 
-
-
 #if __BIONIC_AVAILABILITY_GUARD(26)
 int sighold(int __signal)
   __attribute__((__deprecated__("use sigprocmask() or pthread_sigmask() instead")))
   __INTRODUCED_IN(26);
+#endif /* __BIONIC_AVAILABILITY_GUARD(26) */
+
+#if __BIONIC_AVAILABILITY_GUARD(26)
 int sigignore(int __signal)
   __attribute__((__deprecated__("use sigaction() instead"))) __INTRODUCED_IN(26);
-int sigpause(int __signal)
-  __attribute__((__deprecated__("use sigsuspend() instead"))) __INTRODUCED_IN(26);
-int sigrelse(int __signal)
-  __attribute__((__deprecated__("use sigprocmask() or pthread_sigmask() instead")))
-  __INTRODUCED_IN(26);
-sighandler_t _Nonnull sigset(int __signal, sighandler_t _Nullable __handler)
-  __attribute__((__deprecated__("use sigaction() instead"))) __INTRODUCED_IN(26);
 #endif /* __BIONIC_AVAILABILITY_GUARD(26) */
 
+#if __BIONIC_AVAILABILITY_GUARD(26)
+int sigpause(int __signal)
+  __attribute__((__deprecated__("use sigsuspend() instead"))) __INTRODUCED_IN(26);
+#endif /* __BIONIC_AVAILABILITY_GUARD(26) */
+
+#if __BIONIC_AVAILABILITY_GUARD(26)
+int sigrelse(int __signal)
+  __attribute__((__deprecated__("use sigprocmask() or pthread_sigmask() instead")))
+  __INTRODUCED_IN(26);
+#endif /* __BIONIC_AVAILABILITY_GUARD(26) */
+
+#if __BIONIC_AVAILABILITY_GUARD(26)
+sighandler_t _Nonnull sigset(int __signal, sighandler_t _Nullable __handler)
+  __attribute__((__deprecated__("use sigaction() instead"))) __INTRODUCED_IN(26);
+#endif /* __BIONIC_AVAILABILITY_GUARD(26) */
 
 int raise(int __signal);
 int kill(pid_t __pid, int __signal);
@@ -153,12 +161,9 @@
 void psignal(int __signal, const char* _Nullable __msg);
 
 int pthread_kill(pthread_t __pthread, int __signal);
-#if defined(__USE_GNU)
 
-#if __BIONIC_AVAILABILITY_GUARD(29)
+#if defined(__USE_GNU) && __BIONIC_AVAILABILITY_GUARD(29)
 int pthread_sigqueue(pthread_t __pthread, int __signal, const union sigval __value) __INTRODUCED_IN(29);
-#endif /* __BIONIC_AVAILABILITY_GUARD(29) */
-
 #endif
 
 int pthread_sigmask(int __how, const sigset_t* _Nullable __new_set, sigset_t* _Nullable __old_set);
@@ -167,29 +172,26 @@
 int pthread_sigmask64(int __how, const sigset64_t* _Nullable __new_set, sigset64_t* _Nullable __old_set) __INTRODUCED_IN(28);
 #endif /* __BIONIC_AVAILABILITY_GUARD(28) */
 
-
-
 #if __BIONIC_AVAILABILITY_GUARD(23)
 int sigqueue(pid_t __pid, int __signal, const union sigval __value) __INTRODUCED_IN(23);
-int sigtimedwait(const sigset_t* _Nonnull __set, siginfo_t* _Nullable __info, const struct timespec* _Nullable __timeout) __INTRODUCED_IN(23);
 #endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
+#if __BIONIC_AVAILABILITY_GUARD(23)
+int sigtimedwait(const sigset_t* _Nonnull __set, siginfo_t* _Nullable __info, const struct timespec* _Nullable __timeout) __INTRODUCED_IN(23);
+#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
 #if __BIONIC_AVAILABILITY_GUARD(28)
 int sigtimedwait64(const sigset64_t* _Nonnull __set, siginfo_t* _Nullable __info, const struct timespec* _Nullable __timeout) __INTRODUCED_IN(28);
 #endif /* __BIONIC_AVAILABILITY_GUARD(28) */
 
-
 #if __BIONIC_AVAILABILITY_GUARD(23)
 int sigwaitinfo(const sigset_t* _Nonnull __set, siginfo_t* _Nullable __info) __INTRODUCED_IN(23);
 #endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
-
 #if __BIONIC_AVAILABILITY_GUARD(28)
 int sigwaitinfo64(const sigset64_t* _Nonnull __set, siginfo_t* _Nullable __info) __INTRODUCED_IN(28);
 #endif /* __BIONIC_AVAILABILITY_GUARD(28) */
 
-
 /**
  * Buffer size suitable for any call to sig2str().
  */
@@ -201,13 +203,16 @@
  * like "SEGV" (not including the "SIG" used in the constants).
  * SIG2STR_MAX is a safe size to use for the buffer.
  *
+ * Use strsignal() instead to convert the integer corresponding to SIGSEGV (say)
+ * into a string like "Segmentation violation".
+ *
  * Returns 0 on success, and returns -1 _without_ setting errno otherwise.
  *
- * Available since API level 36.
+ * Available since API level 36 (but see also strsignal()).
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(36)
 int sig2str(int __signal, char* _Nonnull __buf) __INTRODUCED_IN(36);
+#endif /* __BIONIC_AVAILABILITY_GUARD(36) */
 
 /**
  * [str2sig(3)](https://man7.org/linux/man-pages/man3/str2sig.3.html)
@@ -218,10 +223,10 @@
  *
  * Available since API level 36.
  */
+#if __BIONIC_AVAILABILITY_GUARD(36)
 int str2sig(const char* _Nonnull __name, int* _Nonnull __signal) __INTRODUCED_IN(36);
 #endif /* __BIONIC_AVAILABILITY_GUARD(36) */
 
-
 __END_DECLS
 
 #endif
diff --git a/libc/include/spawn.h b/libc/include/spawn.h
index b105754..3a4cd11 100644
--- a/libc/include/spawn.h
+++ b/libc/include/spawn.h
@@ -26,8 +26,7 @@
  * SUCH DAMAGE.
  */
 
-#ifndef _SPAWN_H_
-#define _SPAWN_H_
+#pragma once
 
 #include <sys/cdefs.h>
 #include <sys/types.h>
@@ -44,6 +43,8 @@
 #define POSIX_SPAWN_SETSCHEDULER 32
 #if defined(__USE_GNU)
 #define POSIX_SPAWN_USEVFORK 64
+#endif
+#if defined(__USE_GNU)
 #define POSIX_SPAWN_SETSID 128
 #endif
 /**
@@ -55,52 +56,134 @@
 typedef struct __posix_spawnattr* posix_spawnattr_t;
 typedef struct __posix_spawn_file_actions* posix_spawn_file_actions_t;
 
-
 #if __BIONIC_AVAILABILITY_GUARD(28)
 int posix_spawn(pid_t* _Nullable __pid, const char* _Nonnull __path, const posix_spawn_file_actions_t _Nullable * _Nullable __actions, const posix_spawnattr_t _Nullable * _Nullable __attr, char* const _Nullable __argv[_Nullable], char* const _Nullable __env[_Nullable]) __INTRODUCED_IN(28);
+#endif
+
+#if __BIONIC_AVAILABILITY_GUARD(28)
 int posix_spawnp(pid_t* _Nullable __pid, const char* _Nonnull __file, const posix_spawn_file_actions_t _Nullable * _Nullable __actions, const posix_spawnattr_t _Nullable * _Nullable __attr, char* const _Nullable __argv[_Nullable], char* const _Nullable __env[_Nullable]) __INTRODUCED_IN(28);
+#endif
 
+#if __BIONIC_AVAILABILITY_GUARD(28)
 int posix_spawnattr_init(posix_spawnattr_t _Nullable * _Nonnull __attr) __INTRODUCED_IN(28);
+#endif
+
+#if __BIONIC_AVAILABILITY_GUARD(28)
 int posix_spawnattr_destroy(posix_spawnattr_t _Nonnull * _Nonnull __attr) __INTRODUCED_IN(28);
+#endif
 
+#if __BIONIC_AVAILABILITY_GUARD(28)
 int posix_spawnattr_setflags(posix_spawnattr_t _Nonnull * _Nonnull __attr, short __flags) __INTRODUCED_IN(28);
+#endif
+
+#if __BIONIC_AVAILABILITY_GUARD(28)
 int posix_spawnattr_getflags(const posix_spawnattr_t _Nonnull * _Nonnull __attr, short* _Nonnull __flags) __INTRODUCED_IN(28);
+#endif
 
+#if __BIONIC_AVAILABILITY_GUARD(28)
 int posix_spawnattr_setpgroup(posix_spawnattr_t _Nonnull * _Nonnull __attr, pid_t __pgroup) __INTRODUCED_IN(28);
+#endif
+
+#if __BIONIC_AVAILABILITY_GUARD(28)
 int posix_spawnattr_getpgroup(const posix_spawnattr_t _Nonnull * _Nonnull __attr, pid_t* _Nonnull __pgroup) __INTRODUCED_IN(28);
+#endif
 
+#if __BIONIC_AVAILABILITY_GUARD(28)
 int posix_spawnattr_setsigmask(posix_spawnattr_t _Nonnull * _Nonnull __attr, const sigset_t* _Nonnull __mask) __INTRODUCED_IN(28);
+#endif
+
+#if __BIONIC_AVAILABILITY_GUARD(28)
 int posix_spawnattr_setsigmask64(posix_spawnattr_t _Nonnull * _Nonnull __attr, const sigset64_t* _Nonnull __mask) __INTRODUCED_IN(28);
+#endif
+
+#if __BIONIC_AVAILABILITY_GUARD(28)
 int posix_spawnattr_getsigmask(const posix_spawnattr_t _Nonnull * _Nonnull __attr, sigset_t* _Nonnull __mask) __INTRODUCED_IN(28);
+#endif
+
+#if __BIONIC_AVAILABILITY_GUARD(28)
 int posix_spawnattr_getsigmask64(const posix_spawnattr_t _Nonnull * _Nonnull __attr, sigset64_t* _Nonnull __mask) __INTRODUCED_IN(28);
+#endif
 
+#if __BIONIC_AVAILABILITY_GUARD(28)
 int posix_spawnattr_setsigdefault(posix_spawnattr_t _Nonnull * _Nonnull __attr, const sigset_t* _Nonnull __mask) __INTRODUCED_IN(28);
+#endif
+
+#if __BIONIC_AVAILABILITY_GUARD(28)
 int posix_spawnattr_setsigdefault64(posix_spawnattr_t _Nonnull * _Nonnull __attr, const sigset64_t* _Nonnull __mask) __INTRODUCED_IN(28);
+#endif
+
+#if __BIONIC_AVAILABILITY_GUARD(28)
 int posix_spawnattr_getsigdefault(const posix_spawnattr_t _Nonnull * _Nonnull __attr, sigset_t* _Nonnull __mask) __INTRODUCED_IN(28);
+#endif
+
+#if __BIONIC_AVAILABILITY_GUARD(28)
 int posix_spawnattr_getsigdefault64(const posix_spawnattr_t _Nonnull * _Nonnull __attr, sigset64_t* _Nonnull __mask) __INTRODUCED_IN(28);
+#endif
 
+#if __BIONIC_AVAILABILITY_GUARD(28)
 int posix_spawnattr_setschedparam(posix_spawnattr_t _Nonnull * _Nonnull __attr, const struct sched_param* _Nonnull __param) __INTRODUCED_IN(28);
+#endif
+
+#if __BIONIC_AVAILABILITY_GUARD(28)
 int posix_spawnattr_getschedparam(const posix_spawnattr_t _Nonnull * _Nonnull __attr, struct sched_param* _Nonnull __param) __INTRODUCED_IN(28);
+#endif
 
+#if __BIONIC_AVAILABILITY_GUARD(28)
 int posix_spawnattr_setschedpolicy(posix_spawnattr_t _Nonnull * _Nonnull __attr, int __policy) __INTRODUCED_IN(28);
+#endif
+
+#if __BIONIC_AVAILABILITY_GUARD(28)
 int posix_spawnattr_getschedpolicy(const posix_spawnattr_t _Nonnull * _Nonnull __attr, int* _Nonnull __policy) __INTRODUCED_IN(28);
+#endif
 
+#if __BIONIC_AVAILABILITY_GUARD(28)
 int posix_spawn_file_actions_init(posix_spawn_file_actions_t _Nonnull * _Nonnull __actions) __INTRODUCED_IN(28);
+#endif
+
+#if __BIONIC_AVAILABILITY_GUARD(28)
 int posix_spawn_file_actions_destroy(posix_spawn_file_actions_t _Nonnull * _Nonnull __actions) __INTRODUCED_IN(28);
+#endif
 
+#if __BIONIC_AVAILABILITY_GUARD(28)
 int posix_spawn_file_actions_addopen(posix_spawn_file_actions_t _Nonnull * _Nonnull __actions, int __fd, const char* _Nonnull __path, int __flags, mode_t __mode) __INTRODUCED_IN(28);
+#endif
+
+#if __BIONIC_AVAILABILITY_GUARD(28)
 int posix_spawn_file_actions_addclose(posix_spawn_file_actions_t _Nonnull * _Nonnull __actions, int __fd) __INTRODUCED_IN(28);
+#endif
+
+#if __BIONIC_AVAILABILITY_GUARD(28)
 int posix_spawn_file_actions_adddup2(posix_spawn_file_actions_t _Nonnull * _Nonnull __actions, int __fd, int __new_fd) __INTRODUCED_IN(28);
-#endif /* __BIONIC_AVAILABILITY_GUARD(28) */
+#endif
 
-
-
+/** Synonym for posix_spawn_file_actions_addchdir(). */
 #if __BIONIC_AVAILABILITY_GUARD(34)
 int posix_spawn_file_actions_addchdir_np(posix_spawn_file_actions_t _Nonnull * _Nonnull __actions, const char* _Nonnull __path) __INTRODUCED_IN(34);
-int posix_spawn_file_actions_addfchdir_np(posix_spawn_file_actions_t _Nonnull * _Nonnull __actions, int __fd) __INTRODUCED_IN(34);
-#endif /* __BIONIC_AVAILABILITY_GUARD(34) */
+#endif
 
+/**
+ * posix_spawn_file_actions_addchdir() adds a chdir() as an action
+ * to be performed between the fork() and exec().
+ *
+ * Returns 0 on success and returns an error number on failure.
+ */
+#if __BIONIC_AVAILABILITY_GUARD(34)
+int posix_spawn_file_actions_addchdir(posix_spawn_file_actions_t _Nonnull * _Nonnull __actions, const char* _Nonnull __path) __INTRODUCED_IN(34) __RENAME(posix_spawn_file_actions_addchdir_np);
+#endif
+
+/** Synonym for posix_spawn_file_actions_addfchdir(). */
+#if __BIONIC_AVAILABILITY_GUARD(34)
+int posix_spawn_file_actions_addfchdir_np(posix_spawn_file_actions_t _Nonnull * _Nonnull __actions, int __fd) __INTRODUCED_IN(34);
+#endif
+
+/**
+ * posix_spawn_file_actions_addfchdir() adds an fchdir() as an action
+ * to be performed between the fork() and exec().
+ *
+ * Returns 0 on success and returns an error number on failure.
+ */
+#if __BIONIC_AVAILABILITY_GUARD(34)
+int posix_spawn_file_actions_addfchdir(posix_spawn_file_actions_t _Nonnull * _Nonnull __actions, int __fd) __INTRODUCED_IN(34) __RENAME(posix_spawn_file_actions_addfchdir_np);
+#endif
 
 __END_DECLS
-
-#endif
diff --git a/libc/include/stdbit.h b/libc/include/stdbit.h
new file mode 100644
index 0000000..d9d9bfa
--- /dev/null
+++ b/libc/include/stdbit.h
@@ -0,0 +1,351 @@
+/*
+ * Copyright (C) 2025 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include <sys/cdefs.h>
+
+/* C23 7.18.1 says this header also makes int*_t/uint*_t etc available. */
+#include <stdint.h>
+
+__BEGIN_DECLS
+
+/* C23 7.18.1 General */
+
+/** Declares this implementation as supporting the C23 functionality. */
+#define __STDC_VERSION_STDBIT_H__ 202311L
+
+
+/* C23 7.18.2 Endian */
+
+/** Constant representing little-endian. */
+#define __STDC_ENDIAN_LITTLE__ 1234
+/** Constant representing big-endian. */
+#define __STDC_ENDIAN_BIG__ 4321
+
+/**
+ * Constant representing the endian of the target.
+ * Android is always little-endian.
+ */
+#define __STDC_ENDIAN_NATIVE__ __STDC_ENDIAN_LITTLE__
+
+/*
+ * Notes on the implementation.
+ *
+ * Ideally we'd have clang builtins for all of these, like gcc has.
+ * If/when clang catches up, we can replace all of this with direct calls to
+ * the relevant builtins.
+ *
+ * In the meantime:
+ *
+ * We only use macros because (a) we want to support all api levels and
+ * (b) the whole point of these functions is that they should all be just an
+ * instruction or two, where function call overhead would ruin everything.
+ *
+ * Where there's a similar generic builtin (such as __builtin_clzg) we
+ * forward all the type-specific variants to that.
+ *
+ * Even when not, we try to forward all the type-specific variants to the
+ * generic variant so it's all "obviously correct".
+ *
+ * (It's 2025, and this will only be used in new code, so we haven't bothered
+ * with special cases for ILP32 systems.)
+ *
+ * We cast the arguments to the expected argument types because the builtins
+ * do argument type checking that the <stdbit.h> functionality is not expected
+ * to do (causing warnings rather than silent conversion when passing a signed
+ * int, say).
+ *
+ * We cast the results to the expected `unsigned int` type because the builtins
+ * return signed results.
+ *
+ * We don't worry about C++ casts because it's unclear how this file is
+ * supposed to interact with C++, and C++ has had <bit> longer than C has
+ * had <stdbit.h>.
+ */
+
+
+/* C23 7.18.3 Count Leading Zeros */
+
+/** Returns the count of consecutive 0 bits, starting from the most-significant. */
+#define stdc_leading_zeros_uc(__x) stdc_leading_zeros((unsigned char) (__x))
+/** Returns the count of consecutive 0 bits, starting from the most-significant. */
+#define stdc_leading_zeros_us(__x) stdc_leading_zeros((unsigned short) (__x))
+/** Returns the count of consecutive 0 bits, starting from the most-significant. */
+#define stdc_leading_zeros_ui(__x) stdc_leading_zeros((unsigned int) (__x))
+/** Returns the count of consecutive 0 bits, starting from the most-significant. */
+#define stdc_leading_zeros_ul(__x) stdc_leading_zeros((unsigned long) (__x))
+/** Returns the count of consecutive 0 bits, starting from the most-significant. */
+#define stdc_leading_zeros_ull(__x) stdc_leading_zeros((unsigned long long) (__x))
+/** Returns the count of consecutive 0 bits, starting from the most-significant. */
+#define stdc_leading_zeros(__x) \
+    ((unsigned int) __builtin_clzg(__x, (int) (8 * sizeof(__x))))
+
+
+/* C23 7.18.4 Count Leading Ones */
+
+/** Returns the count of consecutive 1 bits, starting from the most-significant. */
+#define stdc_leading_ones_uc(__x) stdc_leading_ones((unsigned char) (__x))
+/** Returns the count of consecutive 1 bits, starting from the most-significant. */
+#define stdc_leading_ones_us(__x) stdc_leading_ones((unsigned short) (__x))
+/** Returns the count of consecutive 1 bits, starting from the most-significant. */
+#define stdc_leading_ones_ui(__x) stdc_leading_ones((unsigned int) (__x))
+/** Returns the count of consecutive 1 bits, starting from the most-significant. */
+#define stdc_leading_ones_ul(__x) stdc_leading_ones((unsigned long) (__x))
+/** Returns the count of consecutive 1 bits, starting from the most-significant. */
+#define stdc_leading_ones_ull(__x) stdc_leading_ones((unsigned long long) (__x))
+/** Returns the count of consecutive 1 bits, starting from the most-significant. */
+#define stdc_leading_ones(__x) \
+    ((unsigned int) (__builtin_clzg(~(((unsigned long long) (__x)) << ((8 * sizeof(unsigned long long)) - (8 * sizeof(__x)))), \
+                                    (int) (8 * sizeof(__x)))))
+
+
+/* C23 7.18.5 Count Trailing Zeros */
+
+/** Returns the count of consecutive 0 bits, starting from the least-significant. */
+#define stdc_trailing_zeros_uc(__x) stdc_trailing_zeros((unsigned char) (__x))
+/** Returns the count of consecutive 0 bits, starting from the least-significant. */
+#define stdc_trailing_zeros_us(__x) stdc_trailing_zeros((unsigned short) (__x))
+/** Returns the count of consecutive 0 bits, starting from the least-significant. */
+#define stdc_trailing_zeros_ui(__x) stdc_trailing_zeros((unsigned int) (__x))
+/** Returns the count of consecutive 0 bits, starting from the least-significant. */
+#define stdc_trailing_zeros_ul(__x) stdc_trailing_zeros((unsigned long) (__x))
+/** Returns the count of consecutive 0 bits, starting from the least-significant. */
+#define stdc_trailing_zeros_ull(__x) stdc_trailing_zeros((unsigned long long) (__x))
+/** Returns the count of consecutive 0 bits, starting from the least-significant. */
+#define stdc_trailing_zeros(__x) \
+    ((unsigned int) __builtin_ctzg(__x, \
+                                   (int) (8 * sizeof(__x))))
+
+
+/* C23 7.18.6 Count Trailing Ones */
+
+/** Returns the count of consecutive 1 bits, starting from the least-significant. */
+#define stdc_trailing_ones_uc(__x) stdc_trailing_ones((unsigned char) (__x))
+/** Returns the count of consecutive 1 bits, starting from the least-significant. */
+#define stdc_trailing_ones_us(__x) stdc_trailing_ones((unsigned short) (__x))
+/** Returns the count of consecutive 1 bits, starting from the least-significant. */
+#define stdc_trailing_ones_ui(__x) stdc_trailing_ones((unsigned int) (__x))
+/** Returns the count of consecutive 1 bits, starting from the least-significant. */
+#define stdc_trailing_ones_ul(__x) stdc_trailing_ones((unsigned long) (__x))
+/** Returns the count of consecutive 1 bits, starting from the least-significant. */
+#define stdc_trailing_ones_ull(__x) stdc_trailing_ones((unsigned long long) (__x))
+/** Returns the count of consecutive 1 bits, starting from the least-significant. */
+#define stdc_trailing_ones(__x) \
+    ((unsigned int) (__builtin_ctzg((typeof(__x)) ~(__x), \
+                                    (int) (8 * sizeof(__x)))))
+
+
+/* C23 7.18.7 First Leading Zero */
+
+/** Returns the index of the first 0 bit, plus 1, starting from the most-significant (0 if none). */
+#define stdc_first_leading_zero_uc(__x) stdc_first_leading_zero((unsigned char) (__x))
+/** Returns the index of the first 0 bit, plus 1, starting from the most-significant (0 if none). */
+#define stdc_first_leading_zero_us(__x) stdc_first_leading_zero((unsigned short) (__x))
+/** Returns the index of the first 0 bit, plus 1, starting from the most-significant (0 if none). */
+#define stdc_first_leading_zero_ui(__x) stdc_first_leading_zero((unsigned int) (__x))
+/** Returns the index of the first 0 bit, plus 1, starting from the most-significant (0 if none). */
+#define stdc_first_leading_zero_ul(__x) stdc_first_leading_zero((unsigned long) (__x))
+/** Returns the index of the first 0 bit, plus 1, starting from the most-significant (0 if none). */
+#define stdc_first_leading_zero_ull(__x) stdc_first_leading_zero((unsigned long long) (__x))
+/** Returns the index of the first 0 bit, plus 1, starting from the most-significant (0 if none). */
+#define stdc_first_leading_zero(__x) ({ \
+    typeof(__x) __val = (__x); \
+    ((unsigned int) ((__val == (typeof(__x)) -1 \
+        ? 0 \
+        : 1 + __builtin_clzg((typeof(__x)) ~__val)))); \
+  })
+
+
+/* C23 7.18.8 First Leading One */
+
+/** Returns the index of the first 1 bit, plus 1, starting from the most-significant (0 if none). */
+#define stdc_first_leading_one_uc(__x) stdc_first_leading_one((unsigned char) (__x))
+/** Returns the index of the first 1 bit, plus 1, starting from the most-significant (0 if none). */
+#define stdc_first_leading_one_us(__x) stdc_first_leading_one((unsigned short) (__x))
+/** Returns the index of the first 1 bit, plus 1, starting from the most-significant (0 if none). */
+#define stdc_first_leading_one_ui(__x) stdc_first_leading_one((unsigned int) (__x))
+/** Returns the index of the first 1 bit, plus 1, starting from the most-significant (0 if none). */
+#define stdc_first_leading_one_ul(__x) stdc_first_leading_one((unsigned long) (__x))
+/** Returns the index of the first 1 bit, plus 1, starting from the most-significant (0 if none). */
+#define stdc_first_leading_one_ull(__x) stdc_first_leading_one((unsigned long long) (__x))
+/** Returns the index of the first 1 bit, plus 1, starting from the most-significant (0 if none). */
+#define stdc_first_leading_one(__x) ({ \
+    typeof(__x) __val = (__x); \
+    ((unsigned int) ((__val == (typeof(__val)) 0 \
+        ? 0 \
+        : 1 + __builtin_clzg(__val)))); \
+  })
+
+
+/* C23 7.18.9 First Trailing Zero */
+/** Returns the index of the first 0 bit, plus 1, starting from the least-significant (0 if none). */
+#define stdc_first_trailing_zero_uc(__x) stdc_first_trailing_zero((unsigned char) (__x))
+/** Returns the index of the first 0 bit, plus 1, starting from the least-significant (0 if none). */
+#define stdc_first_trailing_zero_us(__x) stdc_first_trailing_zero((unsigned short) (__x))
+/** Returns the index of the first 0 bit, plus 1, starting from the least-significant (0 if none). */
+#define stdc_first_trailing_zero_ui(__x) stdc_first_trailing_zero((unsigned int) (__x))
+/** Returns the index of the first 0 bit, plus 1, starting from the least-significant (0 if none). */
+#define stdc_first_trailing_zero_ul(__x) stdc_first_trailing_zero((unsigned long) (__x))
+/** Returns the index of the first 0 bit, plus 1, starting from the least-significant (0 if none). */
+#define stdc_first_trailing_zero_ull(__x) stdc_first_trailing_zero((unsigned long long) (__x))
+/** Returns the index of the first 0 bit, plus 1, starting from the least-significant (0 if none). */
+#define stdc_first_trailing_zero(__x) ({ \
+    typeof(__x) __val = (__x); \
+    ((unsigned int) ((__val == (typeof(__val)) -1 \
+        ? 0 \
+        : 1 + __builtin_ctzg((typeof(__val)) ~__val)))); \
+  })
+
+/* C23 7.18.10 First Trailing One */
+/** Returns the index of the first 1 bit, plus 1, starting from the least-significant (0 if none). */
+#define stdc_first_trailing_one_uc(__x) stdc_first_trailing_one((unsigned char) (__x))
+/** Returns the index of the first 1 bit, plus 1, starting from the least-significant (0 if none). */
+#define stdc_first_trailing_one_us(__x) stdc_first_trailing_one((unsigned short) (__x))
+/** Returns the index of the first 1 bit, plus 1, starting from the least-significant (0 if none). */
+#define stdc_first_trailing_one_ui(__x) stdc_first_trailing_one((unsigned int) (__x))
+/** Returns the index of the first 1 bit, plus 1, starting from the least-significant (0 if none). */
+#define stdc_first_trailing_one_ul(__x) stdc_first_trailing_one((unsigned long) (__x))
+/** Returns the index of the first 1 bit, plus 1, starting from the least-significant (0 if none). */
+#define stdc_first_trailing_one_ull(__x) stdc_first_trailing_one((unsigned long long) (__x))
+/** Returns the index of the first 1 bit, plus 1, starting from the least-significant (0 if none). */
+#define stdc_first_trailing_one(__x) \
+    ((unsigned int) (((__x) == (typeof(__x)) 0 \
+        ? 0 \
+        : 1 + __builtin_ctzg(__x))))
+
+
+/* C23 7.18.11 Count Zeros */
+
+/** Returns the count of 0 bits. */
+#define stdc_count_zeros_uc(__x) stdc_count_zeros((unsigned char) (__x))
+/** Returns the count of 0 bits. */
+#define stdc_count_zeros_us(__x) stdc_count_zeros((unsigned short) (__x))
+/** Returns the count of 0 bits. */
+#define stdc_count_zeros_ui(__x) stdc_count_zeros((unsigned int) (__x))
+/** Returns the count of 0 bits. */
+#define stdc_count_zeros_ul(__x) stdc_count_zeros((unsigned long) (__x))
+/** Returns the count of 0 bits. */
+#define stdc_count_zeros_ull(__x) stdc_count_zeros((unsigned long long) (__x))
+/** Returns the count of 0 bits. */
+#define stdc_count_zeros(__x) ((unsigned int) ((8 * sizeof(__x)) -  __builtin_popcountg(__x)))
+
+
+/* C23 7.18.12 Count Ones */
+
+/** Returns the count of 1 bits. */
+#define stdc_count_ones_uc(__x) stdc_count_ones((unsigned char) (__x))
+/** Returns the count of 1 bits. */
+#define stdc_count_ones_us(__x) stdc_count_ones((unsigned short) (__x))
+/** Returns the count of 1 bits. */
+#define stdc_count_ones_ui(__x) stdc_count_ones((unsigned int) (__x))
+/** Returns the count of 1 bits. */
+#define stdc_count_ones_ul(__x) stdc_count_ones((unsigned long) (__x))
+/** Returns the count of 1 bits. */
+#define stdc_count_ones_ull(__x) stdc_count_ones((unsigned long long) (__x))
+/** Returns the count of 1 bits. */
+#define stdc_count_ones(__x) ((unsigned int) __builtin_popcountg(__x))
+
+
+/* C23 7.18.13 Single-Bit Check */
+/** Returns true if exactly one bit is set (that is: it's a non-zero power of 2). */
+#define stdc_has_single_bit_uc(__x) stdc_has_single_bit((unsigned char) (__x))
+/** Returns true if exactly one bit is set (that is: it's a non-zero power of 2). */
+#define stdc_has_single_bit_us(__x) stdc_has_single_bit((unsigned short) (__x))
+/** Returns true if exactly one bit is set (that is: it's a non-zero power of 2). */
+#define stdc_has_single_bit_ui(__x) stdc_has_single_bit((unsigned int) (__x))
+/** Returns true if exactly one bit is set (that is: it's a non-zero power of 2). */
+#define stdc_has_single_bit_ul(__x) stdc_has_single_bit((unsigned long) (__x))
+/** Returns true if exactly one bit is set (that is: it's a non-zero power of 2). */
+#define stdc_has_single_bit_ull(__x) stdc_has_single_bit((unsigned long long) (__x))
+/** Returns true if exactly one bit is set (that is: it's a non-zero power of 2). */
+#define stdc_has_single_bit(__x) ({ \
+    typeof(__x) __val = (__x); \
+    ((bool) (__val != 0 && ((__val & (__val - 1)) == 0))); \
+  })
+
+
+/* C23 7.18.14 Bit Width */
+/** Returns the smallest number of bits needed to store the value (0 for 0). */
+#define stdc_bit_width_uc(__x) stdc_bit_width((unsigned char) (__x))
+/** Returns the smallest number of bits needed to store the value (0 for 0). */
+#define stdc_bit_width_us(__x) stdc_bit_width((unsigned short) (__x))
+/** Returns the smallest number of bits needed to store the value (0 for 0). */
+#define stdc_bit_width_ui(__x) stdc_bit_width((unsigned int) (__x))
+/** Returns the smallest number of bits needed to store the value (0 for 0). */
+#define stdc_bit_width_ul(__x) stdc_bit_width((unsigned long) (__x))
+/** Returns the smallest number of bits needed to store the value (0 for 0). */
+#define stdc_bit_width_ull(__x) stdc_bit_width((unsigned long long) (__x))
+/** Returns the smallest number of bits needed to store the value (0 for 0). */
+#define stdc_bit_width(__x) \
+    ((unsigned int) (8 * sizeof(__x)) - __builtin_clzg(__x, \
+                                                       (int) (8 * sizeof(__x))))
+
+
+/* C23 7.18.15 Bit Floor */
+/** Returns the largest integral power of 2 not greater than the value (0 for 0). */
+#define stdc_bit_floor_uc(__x) stdc_bit_floor((unsigned char) (__x))
+/** Returns the largest integral power of 2 not greater than the value (0 for 0). */
+#define stdc_bit_floor_us(__x) stdc_bit_floor((unsigned short) (__x))
+/** Returns the largest integral power of 2 not greater than the value (0 for 0). */
+#define stdc_bit_floor_ui(__x) stdc_bit_floor((unsigned int) (__x))
+/** Returns the largest integral power of 2 not greater than the value (0 for 0). */
+#define stdc_bit_floor_ul(__x) stdc_bit_floor((unsigned long) (__x))
+/** Returns the largest integral power of 2 not greater than the value (0 for 0). */
+#define stdc_bit_floor_ull(__x) stdc_bit_floor((unsigned long long) (__x))
+/** Returns the largest integral power of 2 not greater than the value (0 for 0). */
+#define stdc_bit_floor(__x) ({ \
+    typeof(__x) __val = (__x); \
+    ((typeof(__val)) (__val == 0 ? 0 : ((typeof(__val)) 1) << (stdc_bit_width(__val) - 1))); \
+  })
+
+
+/* C23 7.18.15 Bit Ceil */
+/** Returns the smallest integral power of 2 not less than the value. */
+#define stdc_bit_ceil_uc(__x) stdc_bit_ceil((unsigned char) (__x))
+/** Returns the smallest integral power of 2 not less than the value. */
+#define stdc_bit_ceil_us(__x) stdc_bit_ceil((unsigned short) (__x))
+/** Returns the smallest integral power of 2 not less than the value. */
+#define stdc_bit_ceil_ui(__x) stdc_bit_ceil((unsigned int) (__x))
+/** Returns the smallest integral power of 2 not less than the value. */
+#define stdc_bit_ceil_ul(__x) stdc_bit_ceil((unsigned long) (__x))
+/** Returns the smallest integral power of 2 not less than the value. */
+#define stdc_bit_ceil_ull(__x) stdc_bit_ceil((unsigned long long) (__x))
+/** Returns the smallest integral power of 2 not less than the value. */
+#define stdc_bit_ceil(__x) ({ \
+    typeof(__x) __result = 1; \
+    typeof(__x) __val = (__x); \
+    if (__val > 1) { \
+      /* Avoid shifts greater than the width of the type. */ \
+      unsigned __shift = stdc_bit_width(__val - 1u); \
+      if (__shift < 8 * sizeof(__result)) __result = 1ull << __shift; \
+      else __result = 0; \
+    } \
+    __result; })
+
+__END_DECLS
diff --git a/libc/include/stdint.h b/libc/include/stdint.h
index 772fe8b..1e228fa 100644
--- a/libc/include/stdint.h
+++ b/libc/include/stdint.h
@@ -34,6 +34,8 @@
 #include <bits/wchar_limits.h>
 #include <stddef.h>
 
+__BEGIN_DECLS
+
 typedef signed char __int8_t;
 typedef unsigned char __uint8_t;
 typedef short __int16_t;
@@ -167,23 +169,23 @@
 #define INT16_MAX        (32767)
 #define INT_LEAST16_MIN  INT16_MIN
 #define INT_LEAST16_MAX  INT16_MAX
-#define INT_FAST16_MIN   INT32_MIN
-#define INT_FAST16_MAX   INT32_MAX
+#define INT_FAST16_MIN   (-__LONG_MAX__ - 1L)
+#define INT_FAST16_MAX   __LONG_MAX__
 
 #define UINT16_MAX       (65535)
 #define UINT_LEAST16_MAX UINT16_MAX
-#define UINT_FAST16_MAX  UINT32_MAX
+#define UINT_FAST16_MAX  (__LONG_MAX__ * 2UL + 1UL)
 
 #define INT32_MIN        (-2147483647-1)
 #define INT32_MAX        (2147483647)
 #define INT_LEAST32_MIN  INT32_MIN
 #define INT_LEAST32_MAX  INT32_MAX
-#define INT_FAST32_MIN   INT32_MIN
-#define INT_FAST32_MAX   INT32_MAX
+#define INT_FAST32_MIN   (-__LONG_MAX__ - 1L)
+#define INT_FAST32_MAX   __LONG_MAX__
 
 #define UINT32_MAX       (4294967295U)
 #define UINT_LEAST32_MAX UINT32_MAX
-#define UINT_FAST32_MAX  UINT32_MAX
+#define UINT_FAST32_MAX  (__LONG_MAX__ * 2UL + 1UL)
 
 #define INT64_MIN        (INT64_C(-9223372036854775807)-1)
 #define INT64_MAX        (INT64_C(9223372036854775807))
@@ -196,35 +198,67 @@
 #define UINT_LEAST64_MAX UINT64_MAX
 #define UINT_FAST64_MAX  UINT64_MAX
 
-#define INTMAX_MIN       INT64_MIN
-#define INTMAX_MAX       INT64_MAX
-#define UINTMAX_MAX      UINT64_MAX
+#define INTMAX_MAX __INTMAX_MAX__
+#define INTMAX_MIN (-__INTMAX_MAX__-1)
+#define UINTMAX_MAX __UINTMAX_MAX__
 
 #define SIG_ATOMIC_MAX   INT32_MAX
 #define SIG_ATOMIC_MIN   INT32_MIN
 
-#if defined(__WINT_UNSIGNED__)
-#  define WINT_MAX       UINT32_MAX
-#  define WINT_MIN       0
-#else
-#  define WINT_MAX       INT32_MAX
-#  define WINT_MIN       INT32_MIN
-#endif
+#define WINT_MAX       UINT32_MAX
+#define WINT_MIN       0
 
-#if defined(__LP64__)
-#  define INTPTR_MIN     INT64_MIN
-#  define INTPTR_MAX     INT64_MAX
-#  define UINTPTR_MAX    UINT64_MAX
-#  define PTRDIFF_MIN    INT64_MIN
-#  define PTRDIFF_MAX    INT64_MAX
-#  define SIZE_MAX       UINT64_MAX
-#else
-#  define INTPTR_MIN     INT32_MIN
-#  define INTPTR_MAX     INT32_MAX
-#  define UINTPTR_MAX    UINT32_MAX
-#  define PTRDIFF_MIN    INT32_MIN
-#  define PTRDIFF_MAX    INT32_MAX
-#  define SIZE_MAX       UINT32_MAX
-#endif
+#define INTPTR_MAX __INTPTR_MAX__
+#define INTPTR_MIN (-__INTPTR_MAX__-1)
+#define UINTPTR_MAX __UINTPTR_MAX__
+
+#define PTRDIFF_MAX __PTRDIFF_MAX__
+#define PTRDIFF_MIN (-__PTRDIFF_MAX__-1)
+
+#define SIZE_MAX __SIZE_MAX__
+
+#define INT8_WIDTH 8
+#define UINT8_WIDTH 8
+#define INT16_WIDTH 16
+#define UINT16_WIDTH 16
+#define INT32_WIDTH 32
+#define UINT32_WIDTH 32
+#define INT64_WIDTH 64
+#define UINT64_WIDTH 64
+
+#define INT_FAST8_WIDTH 8
+#define UINT_FAST8_WIDTH 8
+#define INT_FAST16_WIDTH __WORDSIZE
+#define UINT_FAST16_WIDTH __WORDSIZE
+#define INT_FAST32_WIDTH __WORDSIZE
+#define UINT_FAST32_WIDTH __WORDSIZE
+#define INT_FAST64_WIDTH 64
+#define UINT_FAST64_WIDTH 64
+
+#define INT_LEAST8_WIDTH 8
+#define UINT_LEAST8_WIDTH 8
+#define INT_LEAST16_WIDTH 16
+#define UINT_LEAST16_WIDTH 16
+#define INT_LEAST32_WIDTH 32
+#define UINT_LEAST32_WIDTH 32
+#define INT_LEAST64_WIDTH 64
+#define UINT_LEAST64_WIDTH 64
+
+#define WCHAR_WIDTH __WCHAR_WIDTH__
+#define WINT_WIDTH __WINT_WIDTH__
+
+#define INTPTR_WIDTH __INTPTR_WIDTH__
+#define UINTPTR_WIDTH __UINTPTR_WIDTH__
+
+#define INTMAX_WIDTH __INTMAX_WIDTH__
+#define UINTMAX_WIDTH __UINTMAX_WIDTH__
+
+#define PTRDIFF_WIDTH __PTRDIFF_WIDTH__
+
+#define SIZE_WIDTH __SIZE_WIDTH__
+
+#define SIG_ATOMIC_WIDTH __SIG_ATOMIC_WIDTH__
+
+__END_DECLS
 
 #endif /* _STDINT_H */
diff --git a/libc/include/stdio.h b/libc/include/stdio.h
index 2c2dc01..101256a 100644
--- a/libc/include/stdio.h
+++ b/libc/include/stdio.h
@@ -118,8 +118,26 @@
 size_t fwrite(const void* _Nonnull __buf, size_t __size, size_t __count, FILE* _Nonnull __fp);
 __nodiscard int getc(FILE* _Nonnull __fp);
 __nodiscard int getchar(void);
-ssize_t getdelim(char* _Nullable * _Nonnull __line_ptr, size_t* _Nonnull __line_length_ptr, int __delimiter, FILE* _Nonnull __fp);
-ssize_t getline(char* _Nullable * _Nonnull __line_ptr, size_t* _Nonnull __line_length_ptr, FILE* _Nonnull __fp);
+
+/**
+ * [getdelim(2)](https://man7.org/linux/man-pages/man3/getdelim.3.html)
+ * reads a delimited chunk from the given file.
+ *
+ * The memory to be used (and the size of the allocation) are the first
+ * two arguments. Idiomatic code passes NULL on the first call,
+ * and reuses the buffer on successive calls (hence the need to know its length).
+ * Note in particular that the size of the allocation is generally _larger_
+ * than the length of the chunk returned (hence the need to use the return value).
+ *
+ * Returns the length of the chunk (excluding the terminating NUL),
+ * and returns -1 and sets `errno` on failure.
+ */
+ssize_t getdelim(char* _Nullable * _Nonnull __line_ptr, size_t* _Nonnull __allocated_size_ptr, int __delimiter, FILE* _Nonnull __fp);
+
+/**
+ * Equivalent to getdelim() with '\n' as the delimiter.
+ */
+ssize_t getline(char* _Nullable * _Nonnull __line_ptr, size_t* _Nonnull __allocated_size_ptr, FILE* _Nonnull __fp);
 
 void perror(const char* _Nullable __msg);
 int printf(const char* _Nonnull __fmt, ...) __printflike(1, 2);
@@ -140,18 +158,25 @@
 int vdprintf(int __fd, const char* _Nonnull __fmt, va_list __args) __printflike(2, 0);
 
 #if (defined(__STDC_VERSION__) && __STDC_VERSION__ < 201112L) || \
-    (defined(__cplusplus) && __cplusplus <= 201103L)
-char* _Nullable gets(char* _Nonnull __buf) __attribute__((__deprecated__("gets is unsafe, use fgets instead")));
+    (defined(__cplusplus) && __cplusplus < 201402L)
+/**
+ * gets() is an unsafe version of getline() for stdin.
+ *
+ * It was removed in C11 and C++14,
+ * and should not be used by new code.
+ */
+char* _Nullable gets(char* _Nonnull __buf) __attribute__((__deprecated__("gets() is unsafe, use getline() instead")));
 #endif
+
 int sprintf(char* __BIONIC_COMPLICATED_NULLNESS __s, const char* _Nonnull __fmt, ...)
     __printflike(2, 3) __warnattr_strict("sprintf is often misused; please use snprintf");
 int vsprintf(char* __BIONIC_COMPLICATED_NULLNESS __s, const char* _Nonnull __fmt, va_list __args)
     __printflike(2, 0) __warnattr_strict("vsprintf is often misused; please use vsnprintf");
 char* _Nullable tmpnam(char* _Nullable __s)
-    __warnattr("tmpnam is unsafe, use mkstemp or tmpfile instead");
+    __attribute__((__deprecated__("tmpnam is unsafe, use mkstemp or tmpfile instead")));
 #define P_tmpdir "/tmp/" /* deprecated */
 char* _Nullable tempnam(const char* _Nullable __dir, const char* _Nullable __prefix)
-    __warnattr("tempnam is unsafe, use mkstemp or tmpfile instead");
+    __attribute__((__deprecated__("tempnam is unsafe, use mkstemp or tmpfile instead")));
 
 /**
  * [rename(2)](https://man7.org/linux/man-pages/man2/rename.2.html) changes
@@ -169,25 +194,29 @@
  */
 int renameat(int __old_dir_fd, const char* _Nonnull __old_path, int __new_dir_fd, const char* _Nonnull __new_path);
 
-#if defined(__USE_GNU)
-
 /**
  * Flag for [renameat2(2)](https://man7.org/linux/man-pages/man2/renameat2.2.html)
  * to fail if the new path already exists.
  */
+#if defined(__USE_GNU)
 #define RENAME_NOREPLACE (1<<0)
+#endif
 
 /**
  * Flag for [renameat2(2)](https://man7.org/linux/man-pages/man2/renameat2.2.html)
  * to atomically exchange the two paths.
  */
+#if defined(__USE_GNU)
 #define RENAME_EXCHANGE (1<<1)
+#endif
 
 /**
  * Flag for [renameat2(2)](https://man7.org/linux/man-pages/man2/renameat2.2.html)
  * to create a union/overlay filesystem object.
  */
+#if defined(__USE_GNU)
 #define RENAME_WHITEOUT (1<<2)
+#endif
 
 /**
  * [renameat2(2)](https://man7.org/linux/man-pages/man2/renameat2.2.html) changes
@@ -195,13 +224,11 @@
  * with optional `RENAME_` flags.
  *
  * Returns 0 on success, and returns -1 and sets `errno` on failure.
+ *
+ * Available since API level 30 when compiling with `_GNU_SOURCE`.
  */
-
-#if __BIONIC_AVAILABILITY_GUARD(30)
+#if defined(__USE_GNU) && __BIONIC_AVAILABILITY_GUARD(30)
 int renameat2(int __old_dir_fd, const char* _Nonnull __old_path, int __new_dir_fd, const char* _Nonnull __new_path, unsigned __flags) __INTRODUCED_IN(30);
-#endif /* __BIONIC_AVAILABILITY_GUARD(30) */
-
-
 #endif
 
 int fseek(FILE* _Nonnull __fp, long __offset, int __whence);
@@ -212,56 +239,67 @@
 
 #if __BIONIC_AVAILABILITY_GUARD(24)
 int fgetpos(FILE* _Nonnull __fp, fpos_t* _Nonnull __pos) __RENAME(fgetpos64) __INTRODUCED_IN(24);
+#endif /* __BIONIC_AVAILABILITY_GUARD(24) */
+
+#if __BIONIC_AVAILABILITY_GUARD(24)
 int fsetpos(FILE* _Nonnull __fp, const fpos_t* _Nonnull __pos) __RENAME(fsetpos64) __INTRODUCED_IN(24);
+#endif /* __BIONIC_AVAILABILITY_GUARD(24) */
+
+#if __BIONIC_AVAILABILITY_GUARD(24)
 int fseeko(FILE* _Nonnull __fp, off_t __offset, int __whence) __RENAME(fseeko64) __INTRODUCED_IN(24);
+#endif /* __BIONIC_AVAILABILITY_GUARD(24) */
+
+#if __BIONIC_AVAILABILITY_GUARD(24)
 __nodiscard off_t ftello(FILE* _Nonnull __fp) __RENAME(ftello64) __INTRODUCED_IN(24);
 #endif /* __BIONIC_AVAILABILITY_GUARD(24) */
 
-#  if defined(__USE_BSD)
 /* If __read_fn and __write_fn are both nullptr, it will cause EINVAL */
-
-#if __BIONIC_AVAILABILITY_GUARD(24)
+#if defined(__USE_BSD) && __BIONIC_AVAILABILITY_GUARD(24)
 __nodiscard FILE* _Nullable funopen(const void* _Nullable __cookie,
               int (* __BIONIC_COMPLICATED_NULLNESS __read_fn)(void* _Nonnull, char* _Nonnull, int),
               int (* __BIONIC_COMPLICATED_NULLNESS __write_fn)(void* _Nonnull, const char* _Nonnull, int),
               fpos_t (* _Nullable __seek_fn)(void* _Nonnull, fpos_t, int),
               int (* _Nullable __close_fn)(void* _Nonnull)) __RENAME(funopen64) __INTRODUCED_IN(24);
-#endif /* __BIONIC_AVAILABILITY_GUARD(24) */
+#endif
 
-#  endif
 #else
 int fgetpos(FILE* _Nonnull __fp, fpos_t* _Nonnull __pos);
 int fsetpos(FILE* _Nonnull __fp, const fpos_t* _Nonnull __pos);
 int fseeko(FILE* _Nonnull __fp, off_t __offset, int __whence);
 __nodiscard off_t ftello(FILE* _Nonnull __fp);
-#  if defined(__USE_BSD)
+#if defined(__USE_BSD)
 /* If __read_fn and __write_fn are both nullptr, it will cause EINVAL */
 __nodiscard FILE* _Nullable funopen(const void* _Nullable __cookie,
               int (* __BIONIC_COMPLICATED_NULLNESS __read_fn)(void* _Nonnull, char* _Nonnull, int),
               int (* __BIONIC_COMPLICATED_NULLNESS __write_fn)(void* _Nonnull, const char* _Nonnull, int),
               fpos_t (* _Nullable __seek_fn)(void* _Nonnull, fpos_t, int),
               int (* _Nullable __close_fn)(void* _Nonnull));
-#  endif
+#endif
 #endif
 
 #if __BIONIC_AVAILABILITY_GUARD(24)
 int fgetpos64(FILE* _Nonnull __fp, fpos64_t* _Nonnull __pos) __INTRODUCED_IN(24);
+#endif /* __BIONIC_AVAILABILITY_GUARD(24) */
+
+#if __BIONIC_AVAILABILITY_GUARD(24)
 int fsetpos64(FILE* _Nonnull __fp, const fpos64_t* _Nonnull __pos) __INTRODUCED_IN(24);
+#endif /* __BIONIC_AVAILABILITY_GUARD(24) */
+
+#if __BIONIC_AVAILABILITY_GUARD(24)
 int fseeko64(FILE* _Nonnull __fp, off64_t __offset, int __whence) __INTRODUCED_IN(24);
+#endif /* __BIONIC_AVAILABILITY_GUARD(24) */
+
+#if __BIONIC_AVAILABILITY_GUARD(24)
 __nodiscard off64_t ftello64(FILE* _Nonnull __fp) __INTRODUCED_IN(24);
 #endif /* __BIONIC_AVAILABILITY_GUARD(24) */
 
-#if defined(__USE_BSD)
 /* If __read_fn and __write_fn are both nullptr, it will cause EINVAL */
-
-#if __BIONIC_AVAILABILITY_GUARD(24)
+#if defined(__USE_BSD) && __BIONIC_AVAILABILITY_GUARD(24)
 __nodiscard FILE* _Nullable funopen64(const void* _Nullable __cookie,
                 int (* __BIONIC_COMPLICATED_NULLNESS __read_fn)(void* _Nonnull, char* _Nonnull, int),
                 int (* __BIONIC_COMPLICATED_NULLNESS __write_fn)(void* _Nonnull, const char* _Nonnull, int),
                 fpos64_t (* _Nullable __seek_fn)(void* _Nonnull, fpos64_t, int),
                 int (* _Nullable __close_fn)(void* _Nonnull)) __INTRODUCED_IN(24);
-#endif /* __BIONIC_AVAILABILITY_GUARD(24) */
-
 #endif
 
 __nodiscard FILE* _Nullable fopen(const char* _Nonnull __path, const char* _Nonnull __mode);
@@ -308,16 +346,23 @@
 int putc_unlocked(int __ch, FILE* _Nonnull __fp);
 int putchar_unlocked(int __ch);
 
-
 #if __BIONIC_AVAILABILITY_GUARD(23)
 __nodiscard FILE* _Nullable fmemopen(void* _Nullable __buf, size_t __size, const char* _Nonnull __mode) __INTRODUCED_IN(23);
+#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
+#if __BIONIC_AVAILABILITY_GUARD(23)
 __nodiscard FILE* _Nullable open_memstream(char* _Nonnull * _Nonnull __ptr, size_t* _Nonnull __size_ptr) __INTRODUCED_IN(23);
 #endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
-
-#if defined(__USE_BSD) || defined(__BIONIC__) /* Historically bionic exposed these. */
 int  asprintf(char* _Nullable * _Nonnull __s_ptr, const char* _Nonnull __fmt, ...) __printflike(2, 3);
+
+/**
+ * fgetln() is a less portable and harder to use variant of getline().
+ * In particular, fgetln() does not guarantee a terminating NUL byte.
+ *
+ * New code should use getline().
+ */
 char* _Nullable fgetln(FILE* _Nonnull __fp, size_t* _Nonnull __length_ptr);
+
 int fpurge(FILE* _Nonnull __fp);
 void setbuffer(FILE* _Nonnull __fp, char* _Nullable __buf, int __size);
 int setlinebuf(FILE* _Nonnull __fp);
@@ -325,38 +370,47 @@
 
 #if __BIONIC_AVAILABILITY_GUARD(23)
 void clearerr_unlocked(FILE* _Nonnull __fp) __INTRODUCED_IN(23);
+#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
+#if __BIONIC_AVAILABILITY_GUARD(23)
 __nodiscard int feof_unlocked(FILE* _Nonnull __fp) __INTRODUCED_IN(23);
+#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
+#if __BIONIC_AVAILABILITY_GUARD(23)
 __nodiscard int ferror_unlocked(FILE* _Nonnull __fp) __INTRODUCED_IN(23);
 #endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
-
 #if __BIONIC_AVAILABILITY_GUARD(24)
 __nodiscard int fileno_unlocked(FILE* _Nonnull __fp) __INTRODUCED_IN(24);
 #endif /* __BIONIC_AVAILABILITY_GUARD(24) */
 
 #define fropen(cookie, fn) funopen(cookie, fn, 0, 0, 0)
 #define fwopen(cookie, fn) funopen(cookie, 0, fn, 0, 0)
-#endif
 
-#if defined(__USE_BSD)
-
-#if __BIONIC_AVAILABILITY_GUARD(28)
+#if defined(__USE_BSD) && __BIONIC_AVAILABILITY_GUARD(28)
 int fflush_unlocked(FILE* _Nullable __fp) __INTRODUCED_IN(28);
-__nodiscard int fgetc_unlocked(FILE* _Nonnull __fp) __INTRODUCED_IN(28);
-int fputc_unlocked(int __ch, FILE* _Nonnull __fp) __INTRODUCED_IN(28);
-size_t fread_unlocked(void* _Nonnull __buf, size_t __size, size_t __count, FILE* _Nonnull __fp) __INTRODUCED_IN(28);
-size_t fwrite_unlocked(const void* _Nonnull __buf, size_t __size, size_t __count, FILE* _Nonnull __fp) __INTRODUCED_IN(28);
-#endif /* __BIONIC_AVAILABILITY_GUARD(28) */
-
 #endif
 
-#if defined(__USE_GNU)
+#if defined(__USE_BSD) && __BIONIC_AVAILABILITY_GUARD(28)
+__nodiscard int fgetc_unlocked(FILE* _Nonnull __fp) __INTRODUCED_IN(28);
+#endif
 
-#if __BIONIC_AVAILABILITY_GUARD(28)
+#if defined(__USE_BSD) && __BIONIC_AVAILABILITY_GUARD(28)
+int fputc_unlocked(int __ch, FILE* _Nonnull __fp) __INTRODUCED_IN(28);
+#endif
+
+#if defined(__USE_BSD) && __BIONIC_AVAILABILITY_GUARD(28)
+size_t fread_unlocked(void* _Nonnull __buf, size_t __size, size_t __count, FILE* _Nonnull __fp) __INTRODUCED_IN(28);
+#endif
+
+#if defined(__USE_BSD) && __BIONIC_AVAILABILITY_GUARD(28)
+size_t fwrite_unlocked(const void* _Nonnull __buf, size_t __size, size_t __count, FILE* _Nonnull __fp) __INTRODUCED_IN(28);
+#endif
+
+#if defined(__USE_GNU) && __BIONIC_AVAILABILITY_GUARD(28)
 int fputs_unlocked(const char* _Nonnull __s, FILE* _Nonnull __fp) __INTRODUCED_IN(28);
-char* _Nullable fgets_unlocked(char* _Nonnull __buf, int __size, FILE* _Nonnull __fp) __INTRODUCED_IN(28);
-#endif /* __BIONIC_AVAILABILITY_GUARD(28) */
+#endif
 
+#if defined(__USE_GNU) && __BIONIC_AVAILABILITY_GUARD(28)
+char* _Nullable fgets_unlocked(char* _Nonnull __buf, int __size, FILE* _Nonnull __fp) __INTRODUCED_IN(28);
 #endif
 
 #if defined(__BIONIC_INCLUDE_FORTIFY_HEADERS)
diff --git a/libc/include/stdio_ext.h b/libc/include/stdio_ext.h
index 9ff07da..cc8d5b1 100644
--- a/libc/include/stdio_ext.h
+++ b/libc/include/stdio_ext.h
@@ -44,9 +44,9 @@
  *
  * Available since API level 23.
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(23)
 size_t __fbufsize(FILE* _Nonnull __fp) __INTRODUCED_IN(23);
+#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
 /**
  * [__freadable(3)](https://man7.org/linux/man-pages/man3/__freadable.3.html) returns non-zero if
@@ -54,58 +54,50 @@
  *
  * Available since API level 23.
  */
+#if __BIONIC_AVAILABILITY_GUARD(23)
 int __freadable(FILE* _Nonnull __fp) __INTRODUCED_IN(23);
 #endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
-
 /**
  * [__freading(3)](https://man7.org/linux/man-pages/man3/__freading.3.html) returns non-zero if
  * the stream's last operation was a read, 0 otherwise.
  *
  * Available since API level 28.
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(28)
 int __freading(FILE* _Nonnull __fp) __INTRODUCED_IN(28);
 #endif /* __BIONIC_AVAILABILITY_GUARD(28) */
 
-
 /**
  * [__fwritable(3)](https://man7.org/linux/man-pages/man3/__fwritable.3.html) returns non-zero if
  * the stream allows writing, 0 otherwise.
  *
  * Available since API level 23.
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(23)
 int __fwritable(FILE* _Nonnull __fp) __INTRODUCED_IN(23);
 #endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
-
 /**
  * [__fwriting(3)](https://man7.org/linux/man-pages/man3/__fwriting.3.html) returns non-zero if
  * the stream's last operation was a write, 0 otherwise.
  *
  * Available since API level 28.
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(28)
 int __fwriting(FILE* _Nonnull __fp) __INTRODUCED_IN(28);
 #endif /* __BIONIC_AVAILABILITY_GUARD(28) */
 
-
 /**
  * [__flbf(3)](https://man7.org/linux/man-pages/man3/__flbf.3.html) returns non-zero if
  * the stream is line-buffered, 0 otherwise.
  *
  * Available since API level 23.
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(23)
 int __flbf(FILE* _Nonnull __fp) __INTRODUCED_IN(23);
 #endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
-
 /**
  * [__fpurge(3)](https://man7.org/linux/man-pages/man3/__fpurge.3.html) discards the contents of
  * the stream's buffer.
@@ -118,48 +110,40 @@
  *
  * Available since API level 23.
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(23)
 size_t __fpending(FILE* _Nonnull __fp) __INTRODUCED_IN(23);
 #endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
-
 /**
  * __freadahead(3) returns the number of bytes in the input buffer.
  * See __fpending() for the output buffer.
  *
  * Available since API level 34.
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(34)
 size_t __freadahead(FILE* _Nonnull __fp) __INTRODUCED_IN(34);
 #endif /* __BIONIC_AVAILABILITY_GUARD(34) */
 
-
 /**
  * [_flushlbf(3)](https://man7.org/linux/man-pages/man3/_flushlbf.3.html) flushes all
  * line-buffered streams.
  *
  * Available since API level 23.
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(23)
 void _flushlbf(void) __INTRODUCED_IN(23);
 #endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
-
 /**
  * `__fseterr` sets the
  * stream's error flag (as tested by ferror() and cleared by fclearerr()).
  *
  * Available since API level 28.
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(28)
 void __fseterr(FILE* _Nonnull __fp) __INTRODUCED_IN(28);
 #endif /* __BIONIC_AVAILABILITY_GUARD(28) */
 
-
 /** __fsetlocking() constant to query locking type. */
 #define FSETLOCKING_QUERY 0
 /** __fsetlocking() constant to set locking to be maintained by stdio. */
@@ -175,10 +159,8 @@
  *
  * Available since API level 23.
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(23)
 int __fsetlocking(FILE* _Nonnull __fp, int __type) __INTRODUCED_IN(23);
 #endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
-
 __END_DECLS
diff --git a/libc/include/stdlib.h b/libc/include/stdlib.h
index 7081d7c..9946952 100644
--- a/libc/include/stdlib.h
+++ b/libc/include/stdlib.h
@@ -63,8 +63,14 @@
 
 #if __BIONIC_AVAILABILITY_GUARD(23)
 int mkostemp64(char* _Nonnull __template, int __flags) __INTRODUCED_IN(23);
+#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
+#if __BIONIC_AVAILABILITY_GUARD(23)
 int mkostemp(char* _Nonnull __template, int __flags) __INTRODUCED_IN(23);
+#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
+#if __BIONIC_AVAILABILITY_GUARD(23)
 int mkostemps64(char* _Nonnull __template, int __suffix_length, int __flags) __INTRODUCED_IN(23);
+#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
+#if __BIONIC_AVAILABILITY_GUARD(23)
 int mkostemps(char* _Nonnull __template, int __suffix_length, int __flags) __INTRODUCED_IN(23);
 #endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
@@ -125,6 +131,9 @@
 /**
  * [qsort(3)](https://man7.org/linux/man-pages/man3/qsort.3.html) sorts an array
  * of n elements each of the given size, using the given comparator.
+ *
+ * qsort() is not stable, so elements with the same key might be reordered.
+ * libc++ offers both std::sort() and std::stable_sort().
  */
 void qsort(void* _Nullable __array, size_t __n, size_t __size, int (* _Nonnull __comparator)(const void* _Nullable __lhs, const void* _Nullable __rhs));
 
@@ -133,14 +142,16 @@
  * array of n elements each of the given size, using the given comparator,
  * and passing the given context argument to the comparator.
  *
+ * qsort_r() is not stable, so elements with the same key might be reordered.
+ * libc++ offers both std::sort() and std::stable_sort().
+ *
  * Available since API level 36.
+ * std::sort() is available at all API levels.
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(36)
 void qsort_r(void* _Nullable __array, size_t __n, size_t __size, int (* _Nonnull __comparator)(const void* _Nullable __lhs, const void* _Nullable __rhs, void* _Nullable __context), void* _Nullable __context) __INTRODUCED_IN(36);
 #endif /* __BIONIC_AVAILABILITY_GUARD(36) */
 
-
 uint32_t arc4random(void);
 uint32_t arc4random_uniform(uint32_t __upper_bound);
 void arc4random_buf(void* _Nonnull __buf, size_t __n);
@@ -172,17 +183,22 @@
 int ptsname_r(int __fd, char* _Nonnull __buf, size_t __n);
 int unlockpt(int __fd);
 
-
 #if __BIONIC_AVAILABILITY_GUARD(26)
 int getsubopt(char* _Nonnull * _Nonnull __option, char* _Nonnull const* _Nonnull __tokens, char* _Nullable * _Nonnull __value_ptr) __INTRODUCED_IN(26);
 #endif /* __BIONIC_AVAILABILITY_GUARD(26) */
 
-
 typedef struct {
   int quot;
   int rem;
 } div_t;
 
+/**
+ * Returns `__numerator / __denominator` and `__numerator % __denominator`,
+ * truncating towards zero.
+ *
+ * This function was useful for portability before C99,
+ * where `/` and `%` were also defined to truncate towards zero.
+ */
 div_t div(int __numerator, int __denominator) __attribute_const__;
 
 typedef struct {
@@ -190,6 +206,13 @@
   long int rem;
 } ldiv_t;
 
+/**
+ * Returns `__numerator / __denominator` and `__numerator % __denominator`,
+ * truncating towards zero.
+ *
+ * This function was useful for portability before C99,
+ * where `/` and `%` were also defined to truncate towards zero.
+ */
 ldiv_t ldiv(long __numerator, long __denominator) __attribute_const__;
 
 typedef struct {
@@ -197,6 +220,13 @@
   long long int rem;
 } lldiv_t;
 
+/**
+ * Returns `__numerator / __denominator` and `__numerator % __denominator`,
+ * truncating towards zero.
+ *
+ * This function was useful for portability before C99,
+ * where `/` and `%` were also defined to truncate towards zero.
+ */
 lldiv_t lldiv(long long __numerator, long long __denominator) __attribute_const__;
 
 /**
@@ -206,7 +236,6 @@
  *
  * Returns the number of samples written to `__averages` (at most 3), and returns -1 on failure.
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(29)
 int getloadavg(double __averages[_Nonnull], int __n) __INTRODUCED_IN(29);
 #endif /* __BIONIC_AVAILABILITY_GUARD(29) */
@@ -216,7 +245,6 @@
 const char* _Nullable getprogname(void);
 void setprogname(const char* _Nonnull __name);
 
-
 #if __BIONIC_AVAILABILITY_GUARD(26)
 int mblen(const char* _Nullable __s, size_t __n) __INTRODUCED_IN(26);
 #endif /* __BIONIC_AVAILABILITY_GUARD(26) */
@@ -234,8 +262,22 @@
 #include <bits/fortify/stdlib.h>
 #endif
 
+/**
+ * Returns the absolute value where possible.
+ * For the most negative value, the result is unchanged (and thus also negative).
+ */
 int abs(int __x) __attribute_const__;
+
+/**
+ * Returns the absolute value where possible.
+ * For the most negative value, the result is unchanged (and thus also negative).
+ */
 long labs(long __x) __attribute_const__;
+
+/**
+ * Returns the absolute value where possible.
+ * For the most negative value, the result is unchanged (and thus also negative).
+ */
 long long llabs(long long __x) __attribute_const__;
 
 int rand(void);
diff --git a/libc/include/string.h b/libc/include/string.h
index a0a7cc4..eb2ce53 100644
--- a/libc/include/string.h
+++ b/libc/include/string.h
@@ -51,13 +51,11 @@
 #endif
 int memcmp(const void* _Nonnull __lhs, const void* _Nonnull __rhs, size_t __n) __attribute_pure__;
 void* _Nonnull memcpy(void* _Nonnull, const void* _Nonnull, size_t);
-#if defined(__USE_GNU)
 
-#if __BIONIC_AVAILABILITY_GUARD(23)
+#if defined(__USE_GNU) && __BIONIC_AVAILABILITY_GUARD(23)
 void* _Nonnull mempcpy(void* _Nonnull __dst, const void* _Nonnull __src, size_t __n) __INTRODUCED_IN(23);
-#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
-
 #endif
+
 void* _Nonnull memmove(void* _Nonnull __dst, const void* _Nonnull __src, size_t __n);
 
 /**
@@ -74,31 +72,28 @@
  * but won't be optimized out by the compiler.
  *
  * Returns `dst`.
+ *
+ * Available from API level 34, or with __ANDROID_UNAVAILABLE_SYMBOLS_ARE_WEAK__.
  */
-
-#if __BIONIC_AVAILABILITY_GUARD(34)
+#if __ANDROID_API__ >= 34
 void* _Nonnull memset_explicit(void* _Nonnull __dst, int __ch, size_t __n) __INTRODUCED_IN(34);
-#endif /* __BIONIC_AVAILABILITY_GUARD(34) */
-
+#elif defined(__ANDROID_UNAVAILABLE_SYMBOLS_ARE_WEAK__)
+#define __BIONIC_MEMSET_EXPLICIT_INLINE static __inline
+#include <bits/memset_explicit_impl.h>
+#undef __BIONIC_MEMSET_EXPLICIT_INLINE
+#endif
 
 void* _Nullable memmem(const void* _Nonnull __haystack, size_t __haystack_size, const void* _Nonnull __needle, size_t __needle_size) __attribute_pure__;
 
 char* _Nullable strchr(const char* _Nonnull __s, int __ch) __attribute_pure__;
 char* _Nullable __strchr_chk(const char* _Nonnull __s, int __ch, size_t __n);
-#if defined(__USE_GNU)
-#if defined(__cplusplus)
 
-#if __BIONIC_AVAILABILITY_GUARD(24)
+#if defined(__USE_GNU) && __BIONIC_AVAILABILITY_GUARD(24)
+#if defined(__cplusplus)
 extern "C++" char* _Nonnull strchrnul(char* _Nonnull __s, int __ch) __RENAME(strchrnul) __attribute_pure__ __INTRODUCED_IN(24);
 extern "C++" const char* _Nonnull strchrnul(const char* _Nonnull __s, int __ch) __RENAME(strchrnul) __attribute_pure__ __INTRODUCED_IN(24);
-#endif /* __BIONIC_AVAILABILITY_GUARD(24) */
-
 #else
-
-#if __BIONIC_AVAILABILITY_GUARD(24)
 char* _Nonnull strchrnul(const char* _Nonnull __s, int __ch) __attribute_pure__ __INTRODUCED_IN(24);
-#endif /* __BIONIC_AVAILABILITY_GUARD(24) */
-
 #endif
 #endif
 
@@ -115,13 +110,26 @@
 char* _Nullable strdup(const char* _Nonnull __s);
 
 char* _Nullable strstr(const char* _Nonnull __haystack, const char* _Nonnull __needle) __attribute_pure__;
-#if defined(__cplusplus)
-extern "C++" char* _Nullable strcasestr(char* _Nonnull, const char* _Nonnull) __RENAME(strcasestr) __attribute_pure__;
-extern "C++" const char* _Nullable strcasestr(const char* _Nonnull, const char* _Nonnull) __RENAME(strcasestr) __attribute_pure__;
-#else
 char* _Nullable strcasestr(const char* _Nonnull __haystack, const char* _Nonnull __needle) __attribute_pure__;
-#endif
-char* _Nullable strtok(char* _Nullable __s, const char* _Nonnull __delimiter);
+
+/**
+ * [strtok(3)](https://man7.org/linux/man-pages/man3/strtok.3.html)
+ * extracts non-empty tokens from strings.
+ *
+ * Code on Android should use strtok_r() instead,
+ * since strtok() isn't thread-safe.
+ *
+ * See strsep() if you want empty tokens returned too.
+ */
+char* _Nullable strtok(char* _Nullable __s, const char* _Nonnull __delimiter)
+    __attribute__((__deprecated__("strtok() is not thread-safe; use strtok_r() instead")));
+
+/**
+ * [strtok_r(3)](https://man7.org/linux/man-pages/man3/strtok_r.3.html)
+ * extracts non-empty tokens from strings.
+ *
+ * See strsep() if you want empty tokens returned too.
+ */
 char* _Nullable strtok_r(char* _Nullable __s, const char* _Nonnull __delimiter, char* _Nonnull * _Nonnull __pos_ptr);
 
 /**
@@ -169,14 +177,10 @@
  *
  * Returns a pointer to a string, or null for unknown errno values.
  *
- * Available since API level 35.
+ * Available since API level 35 when compiling with `_GNU_SOURCE`.
  */
-#if defined(__USE_GNU)
-
-#if __BIONIC_AVAILABILITY_GUARD(35)
+#if defined(__USE_GNU) && __BIONIC_AVAILABILITY_GUARD(35)
 const char* _Nullable strerrorname_np(int __errno_value) __INTRODUCED_IN(35);
-#endif /* __BIONIC_AVAILABILITY_GUARD(35) */
-
 #endif
 
 /**
@@ -185,6 +189,8 @@
  * does not localize, this is the same as strerror() on Android.
  *
  * Returns a pointer to a string.
+ *
+ * Available when compiling with `_GNU_SOURCE`.
  */
 #if defined(__USE_GNU)
 const char* _Nonnull strerrordesc_np(int __errno_value) __RENAME(strerror);
@@ -200,37 +206,71 @@
 size_t strlcat(char* _Nonnull __dst, const char* _Nonnull __src, size_t __n);
 size_t strlcpy(char* _Nonnull __dst, const char* _Nonnull __src, size_t __n);
 
+/**
+ * [strcspn(3)](https://man7.org/linux/man-pages/man3/strcspn.3.html)
+ * returns the length of the prefix containing only characters _not_ in
+ * the reject set.
+ */
 size_t strcspn(const char* _Nonnull __s, const char* _Nonnull __reject) __attribute_pure__;
+
+/**
+ * [strpbrk(3)](https://man7.org/linux/man-pages/man3/strpbrk.3.html)
+ * returns a pointer to the first character in the string that's
+ * in the accept set, or null.
+ *
+ * See strspn() if you want an index instead.
+ */
 char* _Nullable strpbrk(const char* _Nonnull __s, const char* _Nonnull __accept) __attribute_pure__;
+
+/**
+ * [strsep(3)](https://man7.org/linux/man-pages/man3/strsep.3.html)
+ * extracts tokens (including empty ones) from strings.
+ *
+ * See strtok_r() if you don't want empty tokens.
+ */
 char* _Nullable strsep(char* _Nullable * _Nonnull __s_ptr, const char* _Nonnull __delimiter);
+
+/**
+ * [strspn(3)](https://man7.org/linux/man-pages/man3/strspn.3.html)
+ * returns the length of the prefix containing only characters in
+ * the accept set.
+ *
+ * See strpbrk() if you want a pointer instead.
+ */
 size_t strspn(const char* _Nonnull __s, const char* _Nonnull __accept);
 
+/**
+ * [strsignal(3)](https://man7.org/linux/man-pages/man3/strsignal.3.html)
+ * converts the integer corresponding to SIGSEGV (say) into a string
+ * like "Segmentation violation".
+ *
+ * Use sig2str() instead to convert the integer corresponding to SIGSEGV (say)
+ * into a string like "SEGV".
+ *
+ * Returns a pointer to a string. For invalid signals, the string is in TLS.
+ */
 char* _Nonnull strsignal(int __signal);
 
+/** Equivalent to strcmp() on Android. */
 int strcoll(const char* _Nonnull __lhs, const char* _Nonnull __rhs) __attribute_pure__;
-size_t strxfrm(char* __BIONIC_COMPLICATED_NULLNESS __dst, const char* _Nonnull __src, size_t __n);
-
+/** Equivalent to strcmp() on Android. */
 int strcoll_l(const char* _Nonnull __lhs, const char* _Nonnull __rhs, locale_t _Nonnull __l) __attribute_pure__;
+
+/** Equivalent to strlcpy() on Android. */
+size_t strxfrm(char* __BIONIC_COMPLICATED_NULLNESS __dst, const char* _Nonnull __src, size_t __n);
+/** Equivalent to strlcpy() on Android. */
 size_t strxfrm_l(char* __BIONIC_COMPLICATED_NULLNESS __dst, const char* _Nonnull __src, size_t __n, locale_t _Nonnull __l);
 
-#if defined(__USE_GNU) && !defined(basename)
 /*
  * glibc has a basename in <string.h> that's different to the POSIX one in <libgen.h>.
  * It doesn't modify its argument, and in C++ it's const-correct.
  */
+#if defined(__USE_GNU) && __BIONIC_AVAILABILITY_GUARD(23) && !defined(basename)
 #if defined(__cplusplus)
-
-#if __BIONIC_AVAILABILITY_GUARD(23)
 extern "C++" char* _Nonnull basename(char* _Nullable __path) __RENAME(__gnu_basename) __INTRODUCED_IN(23);
 extern "C++" const char* _Nonnull basename(const char* _Nonnull __path) __RENAME(__gnu_basename) __INTRODUCED_IN(23);
-#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
-
 #else
-
-#if __BIONIC_AVAILABILITY_GUARD(23)
 char* _Nonnull basename(const char* _Nonnull __path) __RENAME(__gnu_basename) __INTRODUCED_IN(23);
-#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
-
 #endif
 #endif
 
@@ -294,8 +334,26 @@
 }
 
 /* Functions with no FORTIFY counterpart. */
+
 inline __always_inline
-char* _Nullable __bionic_strstr(const char* _Nonnull h, const char* _Nonnull n) { return strstr(h, n); }
+char* _Nullable __bionic_strcasestr(const char* _Nonnull h, const char* _Nonnull n) {
+    return strcasestr(h, n);
+}
+
+inline __always_inline
+const char* _Nullable strcasestr(const char* _Nonnull h, const char* _Nonnull n) __prefer_this_overload {
+    return __bionic_strcasestr(h, n);
+}
+
+inline __always_inline
+char* _Nullable strcasestr(char* _Nonnull h, const char* _Nonnull n) __prefer_this_overload {
+    return __bionic_strcasestr(h, n);
+}
+
+inline __always_inline
+char* _Nullable __bionic_strstr(const char* _Nonnull h, const char* _Nonnull n) {
+    return strstr(h, n);
+}
 
 inline __always_inline
 const char* _Nullable strstr(const char* _Nonnull h, const char* _Nonnull n) __prefer_this_overload {
diff --git a/libc/include/sys/cdefs.h b/libc/include/sys/cdefs.h
index a74a514..c4d8ea5 100644
--- a/libc/include/sys/cdefs.h
+++ b/libc/include/sys/cdefs.h
@@ -50,6 +50,7 @@
 #define __END_DECLS
 #endif
 
+/** Adds an alias for a symbol that's defined in the same .o file. */
 #define __strong_alias(alias, sym) \
     __asm__(".global " #alias "\n" \
             #alias " = " #sym);
@@ -60,8 +61,6 @@
 #define __BIONIC_CAST(_k,_t,_v) ((_t) (_v))
 #endif
 
-#define __BIONIC_ALIGN(__value, __alignment) (((__value) + (__alignment)-1) & ~((__alignment)-1))
-
 /*
  * The nullness constraints of this parameter or return value are
  * quite complex. This is used to highlight spots where developers
@@ -143,19 +142,15 @@
 #define __nodiscard __attribute__((__warn_unused_result__))
 #define __wur __nodiscard
 
-#define __errorattr(msg) __attribute__((__unavailable__(msg)))
-#define __warnattr(msg) __attribute__((__deprecated__(msg)))
-#define __warnattr_real(msg) __attribute__((__deprecated__(msg)))
 #define __enable_if(cond, msg) __attribute__((__enable_if__(cond, msg)))
 #define __clang_error_if(cond, msg) __attribute__((__diagnose_if__(cond, msg, "error")))
 #define __clang_warning_if(cond, msg) __attribute__((__diagnose_if__(cond, msg, "warning")))
 
 #if defined(ANDROID_STRICT)
 /*
- * For things that are sketchy, but not necessarily an error. FIXME: Enable
- * this.
+ * For things that are sketchy, but not necessarily an error.
  */
-#  define __warnattr_strict(msg) /* __warnattr(msg) */
+#  define __warnattr_strict(msg) __attribute__((__deprecated__(msg)))
 #else
 #  define __warnattr_strict(msg)
 #endif
@@ -247,12 +242,21 @@
 #  define __bos_level 0
 #endif
 
-#define __bosn(s, n) __builtin_object_size((s), (n))
+#if _FORTIFY_SOURCE >= 3
+#  define __bosn(s, n) __builtin_dynamic_object_size((s), (n))
+#else
+#  define __bosn(s, n) __builtin_object_size((s), (n))
+#endif
 #define __bos(s) __bosn((s), __bos_level)
 
 #if defined(__BIONIC_FORTIFY)
 #  define __bos0(s) __bosn((s), 0)
-#  define __pass_object_size_n(n) __attribute__((__pass_object_size__(n)))
+#  if _FORTIFY_SOURCE >= 3
+#    define __pass_object_size_n(n) __attribute__((__pass_dynamic_object_size__(n)))
+#  else
+#    define __pass_object_size_n(n) __attribute__((__pass_object_size__(n)))
+#  endif
+
 /*
  * FORTIFY'ed functions all have either enable_if or pass_object_size, which
  * makes taking their address impossible. Saying (&read)(foo, bar, baz); will
@@ -291,8 +295,8 @@
 
 /* Intended for use in evaluated contexts. */
 #define __bos_dynamic_check_impl_and(bos_val, op, index, cond) \
-  ((bos_val) == __BIONIC_FORTIFY_UNKNOWN_SIZE ||                 \
-   (__builtin_constant_p(index) && bos_val op index && (cond)))
+  (__builtin_constant_p(bos_val) && ((bos_val) == __BIONIC_FORTIFY_UNKNOWN_SIZE || \
+   (__builtin_constant_p(index) && bos_val op index && (cond))))
 
 #define __bos_dynamic_check_impl(bos_val, op, index) \
   __bos_dynamic_check_impl_and(bos_val, op, index, 1)
@@ -324,15 +328,6 @@
 /* Used to rename functions so that the compiler emits a call to 'x' rather than the function this was applied to. */
 #define __RENAME(x) __asm__(#x)
 
-/*
- * Used when we need to check for overflow when multiplying x and y. This
- * should only be used where __builtin_umull_overflow can not work, because it makes
- * assumptions that __builtin_umull_overflow doesn't (x and y are positive, ...),
- * *and* doesn't make use of compiler intrinsics, so it's probably slower than
- * __builtin_umull_overflow.
- */
-#define __unsafe_check_mul_overflow(x, y) ((__SIZE_TYPE__)-1 / (x) < (y))
-
 #include <android/versioning.h>
 #include <android/api-level.h>
 #if __has_include(<android/ndk-version.h>)
diff --git a/libc/include/sys/endian.h b/libc/include/sys/endian.h
index 1c7448c..a6f01e2 100644
--- a/libc/include/sys/endian.h
+++ b/libc/include/sys/endian.h
@@ -22,86 +22,142 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef _SYS_ENDIAN_H_
-#define _SYS_ENDIAN_H_
+#pragma once
+
+/**
+ * @file sys/endian.h
+ * @brief Endianness utilities.
+ */
 
 #include <sys/cdefs.h>
 
 #include <stdint.h>
 
-#define _LITTLE_ENDIAN	1234
-#define _BIG_ENDIAN	4321
-#define _PDP_ENDIAN	3412
-#define _BYTE_ORDER _LITTLE_ENDIAN
-#define __LITTLE_ENDIAN_BITFIELD
-
-#ifndef __LITTLE_ENDIAN
-#define __LITTLE_ENDIAN _LITTLE_ENDIAN
-#endif
-#ifndef __BIG_ENDIAN
-#define __BIG_ENDIAN _BIG_ENDIAN
-#endif
-#define __BYTE_ORDER _BYTE_ORDER
+__BEGIN_DECLS
 
 #define __swap16 __builtin_bswap16
 #define __swap32 __builtin_bswap32
 #define __swap64(x) __BIONIC_CAST(static_cast,uint64_t,__builtin_bswap64(x))
 
-/* glibc compatibility. */
-__BEGIN_DECLS
-uint32_t htonl(uint32_t __x) __attribute_const__;
-uint16_t htons(uint16_t __x) __attribute_const__;
-uint32_t ntohl(uint32_t __x) __attribute_const__;
-uint16_t ntohs(uint16_t __x) __attribute_const__;
-__END_DECLS
+/* POSIX. */
 
-#define htonl(x) __swap32(x)
-#define htons(x) __swap16(x)
-#define ntohl(x) __swap32(x)
-#define ntohs(x) __swap16(x)
+/** The value of BYTE_ORDER on little-endian systems. */
+#define LITTLE_ENDIAN 1234
 
-/* Bionic additions */
-#define htonq(x) __swap64(x)
-#define ntohq(x) __swap64(x)
+/** The value of BYTE_ORDER on big-endian systems. */
+#define BIG_ENDIAN 4321
 
-#if defined(__USE_BSD) || defined(__BIONIC__) /* Historically bionic exposed these. */
-#define LITTLE_ENDIAN _LITTLE_ENDIAN
-#define BIG_ENDIAN _BIG_ENDIAN
-#define PDP_ENDIAN _PDP_ENDIAN
-#define BYTE_ORDER _BYTE_ORDER
+/** Android is always little-endian. */
+#define BYTE_ORDER LITTLE_ENDIAN
 
-#define	NTOHL(x) (x) = ntohl(__BIONIC_CAST(static_cast,u_int32_t,(x)))
-#define	NTOHS(x) (x) = ntohs(__BIONIC_CAST(static_cast,u_int16_t,(x)))
-#define	HTONL(x) (x) = htonl(__BIONIC_CAST(static_cast,u_int32_t,(x)))
-#define	HTONS(x) (x) = htons(__BIONIC_CAST(static_cast,u_int16_t,(x)))
+/** Swap big-endian 16-bit quantity to host (little-endian) byte order. */
+#define be16toh(x) __swap16(x)
+/** Swap big-endian 32-bit quantity to host (little-endian) byte order. */
+#define be32toh(x) __swap32(x)
+/** Swap big-endian 64-bit quantity to host (little-endian) byte order. */
+#define be64toh(x) __swap64(x)
 
+/** Swap host (little-endian) 16-bit quantity to big-endian. */
 #define htobe16(x) __swap16(x)
+/** Swap host (little-endian) 32-bit quantity to big-endian. */
 #define htobe32(x) __swap32(x)
+/** swap host (little-endian) 64-bit quantity to big-endian. */
 #define htobe64(x) __swap64(x)
-#define betoh16(x) __swap16(x)
-#define betoh32(x) __swap32(x)
-#define betoh64(x) __swap64(x)
 
+/** No-op conversion of host (little-endian) 16-bit quantity to little-endian. */
 #define htole16(x) (x)
+/** No-op conversion of host (little-endian) 32-bit quantity to little-endian. */
 #define htole32(x) (x)
+/** No-op conversion of host (little-endian) 64-bit quantity to little-endian. */
 #define htole64(x) (x)
-#define letoh16(x) (x)
-#define letoh32(x) (x)
-#define letoh64(x) (x)
+
+/** No-op conversion of little-endian 16-bit quantity to host (little-endian) byte order. */
+#define le16toh(x) (x)
+/** No-op conversion of little-endian 32-bit quantity to host (little-endian) byte order. */
+#define le32toh(x) (x)
+/** No-op conversion of little-endian 64-bit quantity to host (little-endian) byte order. */
+#define le64toh(x) (x)
+
+/** Synonym for BIG_ENDIAN. */
+#define _BIG_ENDIAN	BIG_ENDIAN
+/** Synonym for BYTE_ORDER. */
+#define _BYTE_ORDER BYTE_ORDER
+/** Synonym for LITTLE_ENDIAN. */
+#define _LITTLE_ENDIAN LITTLE_ENDIAN
+
+/** Synonym for BIG_ENDIAN. */
+#define __BIG_ENDIAN BIG_ENDIAN
+/** Synonym for BYTE_ORDER. */
+#define __BYTE_ORDER BYTE_ORDER
+/** Synonym for LITTLE_ENDIAN. */
+#define __LITTLE_ENDIAN LITTLE_ENDIAN
+
+/** The byte order of bitfields. Accidental Linux header leakage. */
+#define __LITTLE_ENDIAN_BITFIELD
+
 
 /*
- * glibc-compatible beXXtoh/leXXtoh synonyms for htobeXX/htoleXX.
- * The BSDs export both sets of names, bionic historically only
- * exported the ones above (or on the rhs here), and glibc only
- * exports these names (on the lhs).
+ * POSIX has these in <arpa/inet.h>,
+ * but we have them here for glibc source compatibility.
  */
-#define be16toh(x) htobe16(x)
-#define be32toh(x) htobe32(x)
-#define be64toh(x) htobe64(x)
-#define le16toh(x) htole16(x)
-#define le32toh(x) htole32(x)
-#define le64toh(x) htole64(x)
 
-#endif
+/** Swap host (little-endian) 32-bit quantity to network (big-endian). */
+uint32_t htonl(uint32_t __x) __attribute_const__;
+#define htonl(x) __swap32(x)
 
-#endif
+/** Swap host (little-endian) 16-bit quantity to network (big-endian). */
+uint16_t htons(uint16_t __x) __attribute_const__;
+#define htons(x) __swap16(x)
+
+/** Swap network (big-endian) 32-bit quantity to host (little-endian). */
+uint32_t ntohl(uint32_t __x) __attribute_const__;
+#define ntohl(x) __swap32(x)
+
+/** Swap network (big-endian) 16-bit quantity to host (little-endian). */
+uint16_t ntohs(uint16_t __x) __attribute_const__;
+#define ntohs(x) __swap16(x)
+
+
+/* Bionic additions */
+
+/** Swap host (little-endian) 64-bit quantity to network (big-endian). */
+#define htonq(x) __swap64(x)
+
+/** Swap network (big-endian) 64-bit quantity to host (little-endian). */
+#define ntohq(x) __swap64(x)
+
+
+/* BSD extensions unconditionally exposed by bionic. */
+
+/** The value of BYTE_ORDER on PDP-endian systems. */
+#define PDP_ENDIAN 3412
+/** Synonym for PDP_ENDIAN. */
+#define _PDP_ENDIAN	PDP_ENDIAN
+
+/** In-place byte swap of 32-bit argument. */
+#define	NTOHL(x) (x) = ntohl(__BIONIC_CAST(static_cast,u_int32_t,(x)))
+/** In-place byte swap of 16-bit argument. */
+#define	NTOHS(x) (x) = ntohs(__BIONIC_CAST(static_cast,u_int16_t,(x)))
+/** In-place byte swap of 32-bit argument. */
+#define	HTONL(x) (x) = htonl(__BIONIC_CAST(static_cast,u_int32_t,(x)))
+/** In-place byte swap of 16-bit argument. */
+#define	HTONS(x) (x) = htons(__BIONIC_CAST(static_cast,u_int16_t,(x)))
+
+
+/* glibc extensions. */
+
+/** Swap big-endian 16-bit quantity to host (little-endian). */
+#define betoh16(x) __swap16(x)
+/** Swap big-endian 32-bit quantity to host (little-endian). */
+#define betoh32(x) __swap32(x)
+/** Swap big-endian 64-bit quantity to host (little-endian). */
+#define betoh64(x) __swap64(x)
+
+/** No-op conversion of little-endian 16-bit quantity to host (little-endian). */
+#define letoh16(x) (x)
+/** No-op conversion of little-endian 32-bit quantity to host (little-endian). */
+#define letoh32(x) (x)
+/** No-op conversion of little-endian 64-bit quantity to host (little-endian). */
+#define letoh64(x) (x)
+
+__END_DECLS
diff --git a/libc/include/sys/epoll.h b/libc/include/sys/epoll.h
index bec7c64..4d21e43 100644
--- a/libc/include/sys/epoll.h
+++ b/libc/include/sys/epoll.h
@@ -88,28 +88,26 @@
  *
  * Available since API level 28.
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(28)
 int epoll_pwait64(int __epoll_fd, struct epoll_event* _Nonnull __events, int __event_count, int __timeout_ms, const sigset64_t* _Nullable __mask) __INTRODUCED_IN(28);
 #endif /* __BIONIC_AVAILABILITY_GUARD(28) */
 
-
 /**
  * Like epoll_pwait() but with a `struct timespec` timeout, for nanosecond resolution.
  *
  * Available since API level 35.
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(35)
 int epoll_pwait2(int __epoll_fd, struct epoll_event* _Nonnull __events, int __event_count, const struct timespec* _Nullable __timeout, const sigset_t* _Nullable __mask) __INTRODUCED_IN(35);
+#endif /* __BIONIC_AVAILABILITY_GUARD(35) */
 
 /**
  * Like epoll_pwait2() but using a 64-bit signal mask even on 32-bit systems.
  *
  * Available since API level 35.
  */
+#if __BIONIC_AVAILABILITY_GUARD(35)
 int epoll_pwait2_64(int __epoll_fd, struct epoll_event* _Nonnull __events, int __event_count, const struct timespec* _Nullable __timeout, const sigset64_t* _Nullable __mask) __INTRODUCED_IN(35);
 #endif /* __BIONIC_AVAILABILITY_GUARD(35) */
 
-
 __END_DECLS
diff --git a/libc/include/sys/hwprobe.h b/libc/include/sys/hwprobe.h
index 8e69e8a..1b83996 100644
--- a/libc/include/sys/hwprobe.h
+++ b/libc/include/sys/hwprobe.h
@@ -38,6 +38,9 @@
 #include <sys/cdefs.h>
 #include <sys/types.h>
 
+/* For cpu_set_t. */
+#include <sched.h>
+
 /* Pull in struct riscv_hwprobe and corresponding constants. */
 #include <asm/hwprobe.h>
 
@@ -47,11 +50,11 @@
  * [__riscv_hwprobe(2)](https://docs.kernel.org/riscv/hwprobe.html)
  * queries hardware characteristics.
  *
- * A `__cpu_count` of 0 and null `__cpus` means "all online cpus".
+ * A `__cpu_set_size` of 0 and null `__cpu_set` means "all online cpus".
  *
  * Returns 0 on success and returns an error number on failure.
  */
-int __riscv_hwprobe(struct riscv_hwprobe* _Nonnull __pairs, size_t __pair_count, size_t __cpu_count, unsigned long* _Nullable __cpus, unsigned __flags);
+int __riscv_hwprobe(struct riscv_hwprobe* _Nonnull __pairs, size_t __pair_count, size_t __cpu_set_size, cpu_set_t* _Nullable __cpu_set, unsigned __flags);
 
 /**
  * The type of the second argument passed to riscv64 ifunc resolvers.
@@ -59,7 +62,7 @@
  * without worrying about whether that relocation is resolved before
  * the ifunc resolver is called.
  */
-typedef int (*__riscv_hwprobe_t)(struct riscv_hwprobe* _Nonnull __pairs, size_t __pair_count, size_t __cpu_count, unsigned long* _Nullable __cpus, unsigned __flags);
+typedef int (*__riscv_hwprobe_t)(struct riscv_hwprobe* _Nonnull __pairs, size_t __pair_count, size_t __cpu_set_size, cpu_set_t* _Nullable __cpu_set, unsigned __flags);
 
 __END_DECLS
 
diff --git a/libc/include/sys/ifunc.h b/libc/include/sys/ifunc.h
index d35600e..cb93a1c 100644
--- a/libc/include/sys/ifunc.h
+++ b/libc/include/sys/ifunc.h
@@ -30,6 +30,9 @@
 
 #include <sys/cdefs.h>
 
+#include <stddef.h>
+#include <stdint.h>
+
 /**
  * @file sys/ifunc.h
  * @brief Declarations used for ifunc resolvers. Currently only meaningful for arm64.
@@ -40,18 +43,43 @@
 #if defined(__aarch64__)
 
 /**
+ * Helper function that returns the given AT_HWCAP if available, 0 otherwise.
+ *
+ * The first argument is which hwcap: 1 for AT_HWCAP, 2 for AT_HWCAP2, and so on.
+ * The second argument is the first argument passed to your ifunc resolver;
+ * it's unused, but there for glibc source compatibility.
+ * The third argument is the second argument passed to your ifunc resolver.
+ *
+ * TODO: should this call getauxval() for < api level 30?
+ */
+static __inline unsigned long __ifunc_hwcap(size_t __which, uint64_t __unused __ifunc_arg0, uint64_t* __ifunc_arg1) {
+  return (__which > 0) && (__which < __ifunc_arg1[0] / sizeof(uint64_t)) ? __ifunc_arg1[__which] : 0;
+}
+
+/**
  * Provides information about hardware capabilities to arm64 ifunc resolvers.
  *
+ * New code should use __ifunc_hwcap() rather than interpreting ifunc arguments
+ * directly.
+ *
+ * See https://github.com/ARM-software/abi-aa/blob/main/sysvabi64/sysvabi64.rst#gnu-indirect-functions
+ * for more information.
+ *
  * Prior to API level 30, arm64 ifunc resolvers are passed no arguments.
  *
  * Starting with API level 30, arm64 ifunc resolvers are passed two arguments.
- * The first is a uint64_t whose value is equal to getauxval(AT_HWCAP) | _IFUNC_ARG_HWCAP.
- * The second is a pointer to a data structure of this type.
+ * The first is a uint64_t whose value is equal to `getauxval(AT_HWCAP) | _IFUNC_ARG_HWCAP`.
+ * The second is a pointer to an `__ifunc_arg_t`.
  *
  * Code that wishes to be compatible with API levels before 30 must call getauxval() itself.
  */
 typedef struct __ifunc_arg_t {
-  /** Set to sizeof(__ifunc_arg_t). */
+  /**
+   * Used to determine which subset of fields are actually available
+   * on the device the ifunc is being run on.
+   *
+   * New code should use the __ifunc_hwcap() helper which takes care of this.
+   */
   unsigned long _size;
 
   /** Set to getauxval(AT_HWCAP). */
@@ -59,6 +87,12 @@
 
   /** Set to getauxval(AT_HWCAP2). */
   unsigned long _hwcap2;
+
+  /** Unsafe to access without checking `_size`; use __ifunc_hwcap(). */
+  unsigned long _hwcap3;
+
+  /** Unsafe to access without checking `_size`; use __ifunc_hwcap(). */
+  unsigned long _hwcap4;
 } __ifunc_arg_t;
 
 /**
diff --git a/libc/include/sys/ipc.h b/libc/include/sys/ipc.h
index f557ce5..aba8d32 100644
--- a/libc/include/sys/ipc.h
+++ b/libc/include/sys/ipc.h
@@ -37,6 +37,8 @@
 #include <sys/types.h>
 #include <linux/ipc.h>
 
+__BEGIN_DECLS
+
 #if defined(__USE_GNU)
 #define __key key
 #define __seq seq
@@ -44,8 +46,6 @@
 
 #define ipc_perm ipc64_perm
 
-__BEGIN_DECLS
-
 /**
  * [ftok(3)](https://man7.org/linux/man-pages/man3/ftok.3.html) converts a path and id to a
  * System V IPC key.
diff --git a/libc/include/sys/mman.h b/libc/include/sys/mman.h
index 3fe1f9c..993ec0f 100644
--- a/libc/include/sys/mman.h
+++ b/libc/include/sys/mman.h
@@ -86,12 +86,6 @@
  */
 int mprotect(void* _Nonnull __addr, size_t __size, int __prot);
 
-/** Flag for mremap(). */
-#define MREMAP_MAYMOVE  1
-
-/** Flag for mremap(). */
-#define MREMAP_FIXED    2
-
 /**
  * [mremap(2)](https://man7.org/linux/man-pages/man2/mremap.2.html)
  * expands or shrinks an existing memory mapping.
@@ -133,12 +127,10 @@
  *
  * Returns 0 on success, and returns -1 and sets `errno` on failure.
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(30)
 int mlock2(const void* _Nonnull __addr, size_t __size, int __flags) __INTRODUCED_IN(30);
 #endif /* __BIONIC_AVAILABILITY_GUARD(30) */
 
-
 /**
  * [munlock(2)](https://man7.org/linux/man-pages/man2/munlock.2.html)
  * unlocks pages (allowing swapping).
@@ -175,28 +167,20 @@
  *
  * Returns the number of bytes advised on success, and returns -1 and sets `errno` on failure.
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(31)
 ssize_t process_madvise(int __pid_fd, const struct iovec* _Nonnull __iov, size_t __count, int __advice, unsigned __flags) __INTRODUCED_IN(31);
 #endif /* __BIONIC_AVAILABILITY_GUARD(31) */
 
-
-#if defined(__USE_GNU)
-
 /**
  * [memfd_create(2)](https://man7.org/linux/man-pages/man2/memfd_create.2.html)
  * creates an anonymous file.
  *
- * Available since API level 30.
- *
  * Returns an fd on success, and returns -1 and sets `errno` on failure.
+ *
+ * Available since API level 30 when compiling with `_GNU_SOURCE`.
  */
-
-#if __BIONIC_AVAILABILITY_GUARD(30)
+#if defined(__USE_GNU) && __BIONIC_AVAILABILITY_GUARD(30)
 int memfd_create(const char* _Nonnull __name, unsigned __flags) __INTRODUCED_IN(30);
-#endif /* __BIONIC_AVAILABILITY_GUARD(30) */
-
-
 #endif
 
 #if __ANDROID_API__ >= 23
@@ -232,12 +216,10 @@
  *
  * Returns 0 on success, and returns a positive error number on failure.
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(23)
 int posix_madvise(void* _Nonnull __addr, size_t __size, int __advice) __INTRODUCED_IN(23);
 #endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
-
 /**
  * [mseal(2)](https://man7.org/linux/man-pages/man2/mseal.2.html)
  * seals the given range to prevent modifications such as mprotect() calls.
@@ -248,10 +230,8 @@
  *
  * Returns 0 on success, and returns -1 and sets `errno` on failure.
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(36)
 int mseal(void* _Nonnull __addr, size_t __size, unsigned long __flags) __INTRODUCED_IN(36);
 #endif /* __BIONIC_AVAILABILITY_GUARD(36) */
 
-
 __END_DECLS
diff --git a/libc/include/sys/msg.h b/libc/include/sys/msg.h
index 8b619be..bd19b8c 100644
--- a/libc/include/sys/msg.h
+++ b/libc/include/sys/msg.h
@@ -38,24 +38,31 @@
 
 #include <linux/msg.h>
 
-#define msqid_ds msqid64_ds
-
 __BEGIN_DECLS
 
+#define msqid_ds msqid64_ds
+
 typedef __kernel_ulong_t msgqnum_t;
 typedef __kernel_ulong_t msglen_t;
 
 /** Not useful on Android; disallowed by SELinux. */
-
 #if __BIONIC_AVAILABILITY_GUARD(26)
 int msgctl(int __msg_id, int __op, struct msqid_ds* _Nullable __buf) __INTRODUCED_IN(26);
-/** Not useful on Android; disallowed by SELinux. */
-int msgget(key_t __key, int __flags) __INTRODUCED_IN(26);
-/** Not useful on Android; disallowed by SELinux. */
-ssize_t msgrcv(int __msg_id, void* _Nonnull __msgbuf_ptr, size_t __size, long __type, int __flags) __INTRODUCED_IN(26);
-/** Not useful on Android; disallowed by SELinux. */
-int msgsnd(int __msg_id, const void* _Nonnull __msgbuf_ptr, size_t __size, int __flags) __INTRODUCED_IN(26);
 #endif /* __BIONIC_AVAILABILITY_GUARD(26) */
 
+/** Not useful on Android; disallowed by SELinux. */
+#if __BIONIC_AVAILABILITY_GUARD(26)
+int msgget(key_t __key, int __flags) __INTRODUCED_IN(26);
+#endif /* __BIONIC_AVAILABILITY_GUARD(26) */
+
+/** Not useful on Android; disallowed by SELinux. */
+#if __BIONIC_AVAILABILITY_GUARD(26)
+ssize_t msgrcv(int __msg_id, void* _Nonnull __msgbuf_ptr, size_t __size, long __type, int __flags) __INTRODUCED_IN(26);
+#endif /* __BIONIC_AVAILABILITY_GUARD(26) */
+
+/** Not useful on Android; disallowed by SELinux. */
+#if __BIONIC_AVAILABILITY_GUARD(26)
+int msgsnd(int __msg_id, const void* _Nonnull __msgbuf_ptr, size_t __size, int __flags) __INTRODUCED_IN(26);
+#endif /* __BIONIC_AVAILABILITY_GUARD(26) */
 
 __END_DECLS
diff --git a/libc/include/sys/param.h b/libc/include/sys/param.h
index 99b6a07..fdac888 100644
--- a/libc/include/sys/param.h
+++ b/libc/include/sys/param.h
@@ -39,6 +39,8 @@
 #include <limits.h>
 #include <linux/param.h>
 
+__BEGIN_DECLS
+
 /** The unit of `st_blocks` in `struct stat`. */
 #define DEV_BSIZE 512
 
@@ -48,28 +50,71 @@
 /** A historical name for NGROUPS_MAX. Use NGROUPS_MAX in new code. */
 #define NGROUPS NGROUPS_MAX
 
-#define MAXSYMLINKS 8
+/**
+ * The maximum number of symbolic links the kernel will traverse in one path
+ * lookup before failing with ELOOP.
+ *
+ * This is hard-coded to 40 in Linux in "include/linux/namei.h" but not
+ * exported in any uapi header.
+ */
+#define MAXSYMLINKS 40
 
 #ifndef howmany
+/**
+ * howmany(3) returns the number of elements of size y needed to hold x.
+ *
+ * Note that this macro may evaluate its arguments more than once.
+ */
 #define howmany(x, y)   (((x)+((y)-1))/(y))
 #endif
+
+/**
+ * [roundup(3)](https://man7.org/linux/man-pages/man3/roundup.3.html)
+ * returns x rounded up to the smallest multiple of y not less than x.
+ *
+ * Note that this macro may evaluate its arguments more than once.
+ */
 #define roundup(x, y)   ((((x)+((y)-1))/(y))*(y))
 
 /**
- * Returns true if the binary representation of the argument is all zeros
- * or has exactly one bit set. Contrary to the macro name, this macro
- * DOES NOT determine if the provided value is a power of 2. In particular,
- * this function falsely returns true for powerof2(0) and some negative
- * numbers.
+ * [powerof2(3)](https://man7.org/linux/man-pages/man3/roundup.3.html)
+ * returns true if x is zero or has exactly one bit set.
+ *
+ * Contrary to the macro name, this macro DOES NOT determine if the provided
+ * value is a power of 2. In particular, this function falsely returns true for
+ * powerof2(0) and some negative numbers.
+ *
+ * See also stdc_has_single_bit() in <stdbit.h>.
  */
 #define powerof2(x)                                               \
   ({                                                              \
-    __typeof__(x) _x = (x);                                       \
-    __typeof__(x) _x2;                                            \
+    __auto_type _x = (x);                                         \
+    __auto_type _x2 = _x;                                         \
     __builtin_add_overflow(_x, -1, &_x2) ? 1 : ((_x2 & _x) == 0); \
   })
 
-/** Returns the lesser of its two arguments. */
-#define MIN(a,b) (((a)<(b))?(a):(b))
-/** Returns the greater of its two arguments. */
-#define MAX(a,b) (((a)>(b))?(a):(b))
+/**
+ * [MIN(3)](https://man7.org/linux/man-pages/man3/MIN.3.html)
+ * returns the lesser of its two arguments.
+ *
+ * Note that this macro may evaluate its arguments more than once,
+ * and cannot be fixed because statement expressions are not allowed at file
+ * scope but this macro is.
+ *
+ * See also fmin()/fminf()/fminl() for floating point types.
+ */
+#define MIN(a, b) (((a)<(b))?(a):(b))
+
+/**
+ * [MAX(3)](https://man7.org/linux/man-pages/man3/MAX.3.html)
+ * returns the greater of its two arguments.
+ *
+ * Note that this macro may evaluate its arguments more than once,
+ * and cannot be fixed because statement expressions are not allowed at file
+ * scope but this macro is.
+ *
+ * See also fmax()/fmaxf()/fmaxl() for floating point types.
+ */
+#define MAX(a, b) (((a)>(b))?(a):(b))
+
+__END_DECLS
diff --git a/libc/include/sys/pidfd.h b/libc/include/sys/pidfd.h
index bd2b01e..a18f474 100644
--- a/libc/include/sys/pidfd.h
+++ b/libc/include/sys/pidfd.h
@@ -49,9 +49,9 @@
  *
  * Available since API level 31.
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(31)
 int pidfd_open(pid_t __pid, unsigned int __flags) __INTRODUCED_IN(31);
+#endif /* __BIONIC_AVAILABILITY_GUARD(31) */
 
 /**
  * [pidfd_getfd(2)](https://man7.org/linux/man-pages/man2/pidfd_getfd.2.html)
@@ -63,7 +63,9 @@
  *
  * Available since API level 31.
  */
+#if __BIONIC_AVAILABILITY_GUARD(31)
 int pidfd_getfd(int __pidfd, int __targetfd, unsigned int __flags) __INTRODUCED_IN(31);
+#endif /* __BIONIC_AVAILABILITY_GUARD(31) */
 
 /**
  * [pidfd_send_signal(2)](https://man7.org/linux/man-pages/man2/pidfd_send_signal.2.html)
@@ -73,8 +75,8 @@
  *
  * Available since API level 31.
  */
+#if __BIONIC_AVAILABILITY_GUARD(31)
 int pidfd_send_signal(int __pidfd, int __sig, siginfo_t * _Nullable __info, unsigned int __flags) __INTRODUCED_IN(31);
 #endif /* __BIONIC_AVAILABILITY_GUARD(31) */
 
-
 __END_DECLS
diff --git a/libc/include/sys/quota.h b/libc/include/sys/quota.h
index af09674..3c854e8 100644
--- a/libc/include/sys/quota.h
+++ b/libc/include/sys/quota.h
@@ -51,10 +51,8 @@
  *
  * Available since API level 26.
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(26)
 int quotactl(int __op, const char* _Nullable __special, int __id, char* __BIONIC_COMPLICATED_NULLNESS __addr) __INTRODUCED_IN(26);
 #endif /* __BIONIC_AVAILABILITY_GUARD(26) */
 
-
 __END_DECLS
diff --git a/libc/include/sys/random.h b/libc/include/sys/random.h
index 23d2c3a..d2008b3 100644
--- a/libc/include/sys/random.h
+++ b/libc/include/sys/random.h
@@ -52,7 +52,6 @@
  *
  * See also arc4random_buf() which is available in all API levels.
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(28)
 __nodiscard ssize_t getrandom(void* _Nonnull __buffer, size_t __buffer_size, unsigned int __flags) __INTRODUCED_IN(28);
 #endif /* __BIONIC_AVAILABILITY_GUARD(28) */
diff --git a/libc/include/sys/reg.h b/libc/include/sys/reg.h
index 6c496ba..a77b029 100644
--- a/libc/include/sys/reg.h
+++ b/libc/include/sys/reg.h
@@ -31,6 +31,8 @@
 
 #include <sys/cdefs.h>
 
+__BEGIN_DECLS
+
 #if defined(__i386__)
 
 #define EBX 0
@@ -83,4 +85,6 @@
 
 #endif
 
+__END_DECLS
+
 #endif
diff --git a/libc/include/sys/sem.h b/libc/include/sys/sem.h
index 72f567e..c01603a 100644
--- a/libc/include/sys/sem.h
+++ b/libc/include/sys/sem.h
@@ -51,20 +51,20 @@
   void* _Nullable __pad;
 };
 
-
 #if __BIONIC_AVAILABILITY_GUARD(26)
 int semctl(int __sem_id, int __sem_num, int __op, ...) __INTRODUCED_IN(26);
+#endif /* __BIONIC_AVAILABILITY_GUARD(26) */
+
+#if __BIONIC_AVAILABILITY_GUARD(26)
 int semget(key_t __key, int __sem_count, int __flags) __INTRODUCED_IN(26);
+#endif /* __BIONIC_AVAILABILITY_GUARD(26) */
+
+#if __BIONIC_AVAILABILITY_GUARD(26)
 int semop(int __sem_id, struct sembuf* _Nonnull __ops, size_t __op_count) __INTRODUCED_IN(26);
 #endif /* __BIONIC_AVAILABILITY_GUARD(26) */
 
-
-#if defined(__USE_GNU)
-
-#if __BIONIC_AVAILABILITY_GUARD(26)
+#if defined(__USE_GNU) && __BIONIC_AVAILABILITY_GUARD(26)
 int semtimedop(int __sem_id, struct sembuf* _Nonnull __ops, size_t __op_count, const struct timespec* _Nullable __timeout) __INTRODUCED_IN(26);
-#endif /* __BIONIC_AVAILABILITY_GUARD(26) */
-
 #endif
 
 __END_DECLS
diff --git a/libc/include/sys/shm.h b/libc/include/sys/shm.h
index a960781..5406cda 100644
--- a/libc/include/sys/shm.h
+++ b/libc/include/sys/shm.h
@@ -40,24 +40,31 @@
 
 #include <linux/shm.h>
 
+__BEGIN_DECLS
+
 #define shmid_ds shmid64_ds
 #define SHMLBA getpagesize()
 
-__BEGIN_DECLS
-
 typedef unsigned long shmatt_t;
 
 /** Not useful on Android; disallowed by SELinux. */
-
 #if __BIONIC_AVAILABILITY_GUARD(26)
 void* _Nonnull shmat(int __shm_id, const void* _Nullable __addr, int __flags) __INTRODUCED_IN(26);
-/** Not useful on Android; disallowed by SELinux. */
-int shmctl(int __shm_id, int __op, struct shmid_ds* _Nullable __buf) __INTRODUCED_IN(26);
-/** Not useful on Android; disallowed by SELinux. */
-int shmdt(const void* _Nonnull __addr) __INTRODUCED_IN(26);
-/** Not useful on Android; disallowed by SELinux. */
-int shmget(key_t __key, size_t __size, int __flags) __INTRODUCED_IN(26);
 #endif /* __BIONIC_AVAILABILITY_GUARD(26) */
 
+/** Not useful on Android; disallowed by SELinux. */
+#if __BIONIC_AVAILABILITY_GUARD(26)
+int shmctl(int __shm_id, int __op, struct shmid_ds* _Nullable __buf) __INTRODUCED_IN(26);
+#endif /* __BIONIC_AVAILABILITY_GUARD(26) */
+
+/** Not useful on Android; disallowed by SELinux. */
+#if __BIONIC_AVAILABILITY_GUARD(26)
+int shmdt(const void* _Nonnull __addr) __INTRODUCED_IN(26);
+#endif /* __BIONIC_AVAILABILITY_GUARD(26) */
+
+/** Not useful on Android; disallowed by SELinux. */
+#if __BIONIC_AVAILABILITY_GUARD(26)
+int shmget(key_t __key, size_t __size, int __flags) __INTRODUCED_IN(26);
+#endif /* __BIONIC_AVAILABILITY_GUARD(26) */
 
 __END_DECLS
diff --git a/libc/include/sys/signalfd.h b/libc/include/sys/signalfd.h
index eaea525..ed2c7bc 100644
--- a/libc/include/sys/signalfd.h
+++ b/libc/include/sys/signalfd.h
@@ -51,10 +51,8 @@
 /**
  * Like signalfd() but allows setting a signal mask with RT signals even from a 32-bit process.
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(28)
 int signalfd64(int __fd, const sigset64_t* _Nonnull __mask, int __flags) __INTRODUCED_IN(28);
 #endif /* __BIONIC_AVAILABILITY_GUARD(28) */
 
-
 __END_DECLS
diff --git a/libc/include/sys/stat.h b/libc/include/sys/stat.h
index 12bfedc..344a7c3 100644
--- a/libc/include/sys/stat.h
+++ b/libc/include/sys/stat.h
@@ -124,16 +124,33 @@
 #define st_mtime_nsec st_mtim.tv_nsec
 #define st_ctime_nsec st_ctim.tv_nsec
 
+/** BSD macro corresponding to `a+rwx`, useful as a mask of just the permission bits. */
 #if defined(__USE_BSD)
-/* Permission macros provided by glibc for compatibility with BSDs. */
 #define ACCESSPERMS (S_IRWXU | S_IRWXG | S_IRWXO) /* 0777 */
+#endif
+
+/** BSD macro useful as a mask of the permission bits and setuid/setgid/sticky bits. */
+#if defined(__USE_BSD)
 #define ALLPERMS    (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO) /* 07777 */
+#endif
+
+/** BSD macro corresponding to `a+rw`, useful as a default. */
+#if defined(__USE_BSD)
 #define DEFFILEMODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) /* 0666 */
 #endif
 
+/** BSD/GNU synonym for S_IRUSR. */
 #if defined(__USE_BSD) || defined(__USE_GNU)
 #define S_IREAD S_IRUSR
+#endif
+
+/** BSD/GNU synonym for S_IWUSR. */
+#if defined(__USE_BSD) || defined(__USE_GNU)
 #define S_IWRITE S_IWUSR
+#endif
+
+/** BSD/GNU synonym for S_IXUSR. */
+#if defined(__USE_BSD) || defined(__USE_GNU)
 #define S_IEXEC S_IXUSR
 #endif
 
@@ -177,12 +194,10 @@
  *
  * Returns 0 on success and returns -1 and sets `errno` on failure.
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(36)
 int lchmod(const char* _Nonnull __path, mode_t __mode) __INTRODUCED_IN(36);
 #endif /* __BIONIC_AVAILABILITY_GUARD(36) */
 
-
 /**
  * [mkdir(2)](https://man7.org/linux/man-pages/man2/mkdir.2.html)
  * creates a directory.
@@ -285,7 +300,6 @@
  *
  * Returns 0 on success and returns -1 and sets `errno` on failure.
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(23)
 int mkfifoat(int __dir_fd, const char* _Nonnull __path, mode_t __mode) __INTRODUCED_IN(23);
 #endif /* __BIONIC_AVAILABILITY_GUARD(23) */
@@ -331,20 +345,16 @@
  */
 int futimens(int __fd, const struct timespec __times[_Nullable 2]);
 
-#if defined(__USE_GNU)
 /**
  * [statx(2)](https://man7.org/linux/man-pages/man2/statx.2.html) returns
  * extended file status information.
  *
  * Returns 0 on success and returns -1 and sets `errno` on failure.
  *
- * Available since API level 30.
+ * Available since API level 30 when compiling with `_GNU_SOURCE`.
  */
-
-#if __BIONIC_AVAILABILITY_GUARD(30)
+#if defined(__USE_GNU) && __BIONIC_AVAILABILITY_GUARD(30)
 int statx(int __dir_fd, const char* _Nullable __path, int __flags, unsigned __mask, struct statx* _Nonnull __buf) __INTRODUCED_IN(30);
-#endif /* __BIONIC_AVAILABILITY_GUARD(30) */
-
 #endif
 
 __END_DECLS
diff --git a/libc/include/sys/sysinfo.h b/libc/include/sys/sysinfo.h
index ed6a007..e9e95d5 100644
--- a/libc/include/sys/sysinfo.h
+++ b/libc/include/sys/sysinfo.h
@@ -53,9 +53,9 @@
  *
  * See also sysconf().
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(23)
 int get_nprocs_conf(void) __INTRODUCED_IN(23);
+#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
 /**
  * [get_nprocs(3)](https://man7.org/linux/man-pages/man3/get_nprocs.3.html) returns
@@ -65,7 +65,9 @@
  *
  * See also sysconf().
  */
+#if __BIONIC_AVAILABILITY_GUARD(23)
 int get_nprocs(void) __INTRODUCED_IN(23);
+#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
 /**
  * [get_phys_pages(3)](https://man7.org/linux/man-pages/man3/get_phys_pages.3.html) returns
@@ -75,7 +77,9 @@
  *
  * See also sysconf().
  */
+#if __BIONIC_AVAILABILITY_GUARD(23)
 long get_phys_pages(void) __INTRODUCED_IN(23);
+#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
 /**
  * [get_avphys_pages(3)](https://man7.org/linux/man-pages/man3/get_avphys_pages.3.html) returns
@@ -85,8 +89,8 @@
  *
  * See also sysconf().
  */
+#if __BIONIC_AVAILABILITY_GUARD(23)
 long get_avphys_pages(void) __INTRODUCED_IN(23);
 #endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
-
 __END_DECLS
diff --git a/libc/include/sys/sysmacros.h b/libc/include/sys/sysmacros.h
index 64cf289..a020ba8 100644
--- a/libc/include/sys/sysmacros.h
+++ b/libc/include/sys/sysmacros.h
@@ -35,6 +35,8 @@
 
 #include <sys/cdefs.h>
 
+__BEGIN_DECLS
+
 /** Combines `major` and `minor` into a device number. */
 #define makedev(__major, __minor) \
   ( \
@@ -49,3 +51,5 @@
 /** Extracts the minor part of a device number. */
 #define minor(__dev) \
   ((unsigned) ((((__dev) >> 12) & 0xffffff00) | ((__dev) & 0xff)))
+
+__END_DECLS
diff --git a/libc/include/sys/system_properties.h b/libc/include/sys/system_properties.h
index 1303079..d850b1e 100644
--- a/libc/include/sys/system_properties.h
+++ b/libc/include/sys/system_properties.h
@@ -71,14 +71,12 @@
  *
  * Available since API level 26.
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(26)
 void __system_property_read_callback(const prop_info* _Nonnull __pi,
     void (* _Nonnull __callback)(void* _Nullable __cookie, const char* _Nonnull __name, const char* _Nonnull __value, uint32_t __serial),
     void* _Nullable __cookie) __INTRODUCED_IN(26);
 #endif /* __BIONIC_AVAILABILITY_GUARD(26) */
 
-
 /**
  * Passes a `prop_info` for each system property to the provided
  * callback. Use __system_property_read_callback() to read the value of
@@ -111,7 +109,6 @@
     __INTRODUCED_IN(26);
 #endif /* __BIONIC_AVAILABILITY_GUARD(26) */
 
-
 /**
  * Deprecated: there's no limit on the length of a property name since
  * API level 26, though the limit on property values (PROP_VALUE_MAX) remains.
@@ -241,12 +238,10 @@
  *
  * Available since API level 35.
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(35)
 int __system_properties_zygote_reload(void) __INTRODUCED_IN(35);
 #endif /* __BIONIC_AVAILABILITY_GUARD(35) */
 
-
 /**
  * Deprecated: previously for testing, but now that SystemProperties is its own
  * testable class, there is never a reason to call this function and its
diff --git a/libc/include/sys/thread_properties.h b/libc/include/sys/thread_properties.h
index b6214ee..fb69ccb 100644
--- a/libc/include/sys/thread_properties.h
+++ b/libc/include/sys/thread_properties.h
@@ -54,7 +54,7 @@
 #if __BIONIC_AVAILABILITY_GUARD(31)
 void __libc_get_static_tls_bounds(void* _Nonnull * _Nonnull __static_tls_begin,
                                   void* _Nonnull * _Nonnull __static_tls_end) __INTRODUCED_IN(31);
-
+#endif /* __BIONIC_AVAILABILITY_GUARD(31) */
 
 /**
  * Registers callback to be called right before the thread is dead.
@@ -68,7 +68,9 @@
  *
  * Available since API level 31.
  */
+#if __BIONIC_AVAILABILITY_GUARD(31)
 void __libc_register_thread_exit_callback(void (* _Nonnull __cb)(void)) __INTRODUCED_IN(31);
+#endif /* __BIONIC_AVAILABILITY_GUARD(31) */
 
 /**
  * Iterates over all dynamic TLS chunks for the given thread.
@@ -77,12 +79,14 @@
  *
  * Available since API level 31.
  */
+#if __BIONIC_AVAILABILITY_GUARD(31)
 void __libc_iterate_dynamic_tls(pid_t __tid,
                                 void (* _Nonnull __cb)(void* _Nonnull __dynamic_tls_begin,
                                              void* _Nonnull __dynamic_tls_end,
                                              size_t __dso_id,
                                              void* _Nullable __arg),
                                 void* _Nullable __arg) __INTRODUCED_IN(31);
+#endif /* __BIONIC_AVAILABILITY_GUARD(31) */
 
 /**
  * Register on_creation and on_destruction callbacks, which will be called after a dynamic
@@ -90,6 +94,7 @@
  *
  * Available since API level 31.
  */
+#if __BIONIC_AVAILABILITY_GUARD(31)
 void __libc_register_dynamic_tls_listeners(
     void (* _Nonnull __on_creation)(void* _Nonnull __dynamic_tls_begin,
                           void* _Nonnull __dynamic_tls_end),
@@ -97,5 +102,4 @@
                              void* _Nonnull __dynamic_tls_end)) __INTRODUCED_IN(31);
 #endif /* __BIONIC_AVAILABILITY_GUARD(31) */
 
-
 __END_DECLS
diff --git a/libc/include/sys/time.h b/libc/include/sys/time.h
index d12c306..a7c0ecf 100644
--- a/libc/include/sys/time.h
+++ b/libc/include/sys/time.h
@@ -46,16 +46,14 @@
 
 int utimes(const char* _Nonnull __path, const struct timeval __times[_Nullable 2]);
 
-#if defined(__USE_BSD)
-
-#if __BIONIC_AVAILABILITY_GUARD(26)
+#if defined(__USE_BSD) && __BIONIC_AVAILABILITY_GUARD(26)
 int futimes(int __fd, const struct timeval __times[_Nullable 2]) __INTRODUCED_IN(26);
-int lutimes(const char* _Nonnull __path, const struct timeval __times[_Nullable 2]) __INTRODUCED_IN(26);
-#endif /* __BIONIC_AVAILABILITY_GUARD(26) */
-
 #endif
 
-#if defined(__USE_GNU)
+#if defined(__USE_BSD) && __BIONIC_AVAILABILITY_GUARD(26)
+int lutimes(const char* _Nonnull __path, const struct timeval __times[_Nullable 2]) __INTRODUCED_IN(26);
+#endif
+
 /**
  * [futimesat(2)](https://man7.org/linux/man-pages/man2/futimesat.2.html) sets
  * file timestamps.
@@ -67,13 +65,10 @@
  *
  * Returns 0 on success and -1 and sets `errno` on failure.
  *
- * Available since API level 26.
+ * Available since API level 26 when compiling with `_GNU_SOURCE`.
  */
-
-#if __BIONIC_AVAILABILITY_GUARD(26)
+#if defined(__USE_GNU) && __BIONIC_AVAILABILITY_GUARD(26)
 int futimesat(int __dir_fd, const char* __BIONIC_COMPLICATED_NULLNESS __path, const struct timeval __times[_Nullable 2]) __INTRODUCED_IN(26);
-#endif /* __BIONIC_AVAILABILITY_GUARD(26) */
-
 #endif
 
 #define timerclear(a)   \
diff --git a/libc/include/sys/timex.h b/libc/include/sys/timex.h
index 6fb58e4..e740da5 100644
--- a/libc/include/sys/timex.h
+++ b/libc/include/sys/timex.h
@@ -46,9 +46,9 @@
  *
  * Available since API level 24.
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(24)
 int adjtimex(struct timex* _Nonnull __buf) __INTRODUCED_IN(24);
+#endif /* __BIONIC_AVAILABILITY_GUARD(24) */
 
 /**
  * clock_adjtime adjusts a specific kernel clock.
@@ -57,8 +57,8 @@
  *
  * Available since API level 24.
  */
+#if __BIONIC_AVAILABILITY_GUARD(24)
 int clock_adjtime(clockid_t __clock, struct timex* _Nonnull __tx) __INTRODUCED_IN(24);
 #endif /* __BIONIC_AVAILABILITY_GUARD(24) */
 
-
 __END_DECLS
diff --git a/libc/include/sys/ttydefaults.h b/libc/include/sys/ttydefaults.h
index 4dcc649..569c87b 100644
--- a/libc/include/sys/ttydefaults.h
+++ b/libc/include/sys/ttydefaults.h
@@ -44,6 +44,8 @@
 
 #include <sys/cdefs.h>
 
+__BEGIN_DECLS
+
 /*
  * Defaults on "first" open.
  */
@@ -80,4 +82,6 @@
 #define CRPRNT		CREPRINT
 #define	CFLUSH		CDISCARD
 
+__END_DECLS
+
 #endif /* !_SYS_TTYDEFAULTS_H_ */
diff --git a/libc/include/sys/types.h b/libc/include/sys/types.h
index 0446260..dcb0e58 100644
--- a/libc/include/sys/types.h
+++ b/libc/include/sys/types.h
@@ -39,6 +39,8 @@
 
 #include <bits/pthread_types.h>
 
+__BEGIN_DECLS
+
 /* gids, uids, and pids are all 32-bit. */
 typedef __kernel_gid32_t __gid_t;
 typedef __gid_t gid_t;
@@ -119,29 +121,35 @@
 
 typedef __builtin_va_list __va_list;
 
-#ifndef _SSIZE_T_DEFINED_
-#define _SSIZE_T_DEFINED_
-/* Traditionally, bionic's ssize_t was "long int". This caused GCC to emit warnings when you
- * pass a ssize_t to a printf-style function. The correct type is __kernel_ssize_t, which is
- * "int", which isn't an ABI change for C code (because they're the same size) but is an ABI
- * change for C++ because "int" and "long int" mangle to "i" and "l" respectively. So until
- * we can fix the ABI, this change should not be propagated to the NDK. http://b/8253769. */
+/**
+ * A signed alternative to size_t,
+ * generally for cases that return -1 and set errno on error.
+ */
 typedef __kernel_ssize_t ssize_t;
-#endif
 
+/** BSD synonym for unsigned int that's always exposed by historical accident. */
 typedef unsigned int        uint_t;
+/** BSD synonym for unsigned int that's always exposed by historical accident. */
 typedef unsigned int        uint;
 
-#if defined(__USE_BSD) || defined(__BIONIC__) /* Historically bionic exposed these. */
+/** BSD synonym for unsigned char that's always exposed by historical accident. */
 typedef unsigned char  u_char;
+/** BSD synonym for unsigned short that's always exposed by historical accident. */
 typedef unsigned short u_short;
+/** BSD synonym for unsigned int that's always exposed by historical accident. */
 typedef unsigned int   u_int;
+/** BSD synonym for unsigned long that's always exposed by historical accident. */
 typedef unsigned long  u_long;
 
+/** BSD synonym for uint32_t that's always exposed by historical accident. */
 typedef uint32_t u_int32_t;
+/** BSD synonym for uint16_t that's always exposed by historical accident. */
 typedef uint16_t u_int16_t;
+/** BSD synonym for uint8_t that's always exposed by historical accident. */
 typedef uint8_t  u_int8_t;
+/** BSD synonym for uint64_t that's always exposed by historical accident. */
 typedef uint64_t u_int64_t;
-#endif
+
+__END_DECLS
 
 #endif
diff --git a/libc/include/sys/uio.h b/libc/include/sys/uio.h
index eff3b14..4f14ece 100644
--- a/libc/include/sys/uio.h
+++ b/libc/include/sys/uio.h
@@ -57,8 +57,6 @@
  */
 ssize_t writev(int __fd, const struct iovec* _Nonnull __iov, int __count);
 
-#if defined(__USE_GNU)
-
 /**
  * [preadv(2)](https://man7.org/linux/man-pages/man2/preadv.2.html) reads
  * from an fd into the `__count` buffers described by `__iov`, starting at
@@ -67,11 +65,11 @@
  * Returns the number of bytes read on success,
  * and returns -1 and sets `errno` on failure.
  *
- * Available since API level 24.
+ * Available since API level 24 when compiling with `_GNU_SOURCE`.
  */
-
-#if __BIONIC_AVAILABILITY_GUARD(24)
+#if defined(__USE_GNU) && __BIONIC_AVAILABILITY_GUARD(24)
 ssize_t preadv(int __fd, const struct iovec* _Nonnull __iov, int __count, off_t __offset) __RENAME_IF_FILE_OFFSET64(preadv64) __INTRODUCED_IN(24);
+#endif
 
 /**
  * [pwritev(2)](https://man7.org/linux/man-pages/man2/pwritev.2.html) writes
@@ -81,25 +79,29 @@
  * Returns the number of bytes written on success,
  * and returns -1 and sets `errno` on failure.
  *
- * Available since API level 24.
+ * Available since API level 24 when compiling with `_GNU_SOURCE`.
  */
+#if defined(__USE_GNU) && __BIONIC_AVAILABILITY_GUARD(24)
 ssize_t pwritev(int __fd, const struct iovec* _Nonnull __iov, int __count, off_t __offset) __RENAME_IF_FILE_OFFSET64(pwritev64) __INTRODUCED_IN(24);
+#endif
 
 /**
  * Like preadv() but with a 64-bit offset even in a 32-bit process.
  *
- * Available since API level 24.
+ * Available since API level 24 when compiling with `_GNU_SOURCE`.
  */
+#if defined(__USE_GNU) && __BIONIC_AVAILABILITY_GUARD(24)
 ssize_t preadv64(int __fd, const struct iovec* _Nonnull __iov, int __count, off64_t __offset) __INTRODUCED_IN(24);
+#endif
 
 /**
  * Like pwritev() but with a 64-bit offset even in a 32-bit process.
  *
- * Available since API level 24.
+ * Available since API level 24 when compiling with `_GNU_SOURCE`.
  */
+#if defined(__USE_GNU) && __BIONIC_AVAILABILITY_GUARD(24)
 ssize_t pwritev64(int __fd, const struct iovec* _Nonnull __iov, int __count, off64_t __offset) __INTRODUCED_IN(24);
-#endif /* __BIONIC_AVAILABILITY_GUARD(24) */
-
+#endif
 
 /**
  * [preadv2(2)](https://man7.org/linux/man-pages/man2/preadv2.2.html) reads
@@ -109,11 +111,11 @@
  * Returns the number of bytes read on success,
  * and returns -1 and sets `errno` on failure.
  *
- * Available since API level 33.
+ * Available since API level 33 when compiling with `_GNU_SOURCE`.
  */
-
-#if __BIONIC_AVAILABILITY_GUARD(33)
+#if defined(__USE_GNU) && __BIONIC_AVAILABILITY_GUARD(33)
 ssize_t preadv2(int __fd, const struct iovec* _Nonnull __iov, int __count, off_t __offset, int __flags) __RENAME_IF_FILE_OFFSET64(preadv64v2) __INTRODUCED_IN(33);
+#endif
 
 /**
  * [pwritev2(2)](https://man7.org/linux/man-pages/man2/pwritev2.2.html) writes
@@ -123,25 +125,29 @@
  * Returns the number of bytes written on success,
  * and returns -1 and sets `errno` on failure.
  *
- * Available since API level 33.
+ * Available since API level 33 when compiling with `_GNU_SOURCE`.
  */
+#if defined(__USE_GNU) && __BIONIC_AVAILABILITY_GUARD(33)
 ssize_t pwritev2(int __fd, const struct iovec* _Nonnull __iov, int __count, off_t __offset, int __flags) __RENAME_IF_FILE_OFFSET64(pwritev64v2) __INTRODUCED_IN(33);
+#endif
 
 /**
  * Like preadv2() but with a 64-bit offset even in a 32-bit process.
  *
- * Available since API level 33.
+ * Available since API level 33 when compiling with `_GNU_SOURCE`.
  */
+#if defined(__USE_GNU) && __BIONIC_AVAILABILITY_GUARD(33)
 ssize_t preadv64v2(int __fd, const struct iovec* _Nonnull __iov, int __count, off64_t __offset, int __flags) __INTRODUCED_IN(33);
+#endif
 
 /**
  * Like pwritev2() but with a 64-bit offset even in a 32-bit process.
  *
- * Available since API level 33.
+ * Available since API level 33 when compiling with `_GNU_SOURCE`.
  */
+#if defined(__USE_GNU) && __BIONIC_AVAILABILITY_GUARD(33)
 ssize_t pwritev64v2(int __fd, const struct iovec* _Nonnull __iov, int __count, off64_t __offset, int __flags) __INTRODUCED_IN(33);
-#endif /* __BIONIC_AVAILABILITY_GUARD(33) */
-
+#endif
 
 /**
  * [process_vm_readv(2)](https://man7.org/linux/man-pages/man2/process_vm_readv.2.html)
@@ -150,11 +156,11 @@
  * Returns the number of bytes read on success,
  * and returns -1 and sets `errno` on failure.
  *
- * Available since API level 23.
+ * Available since API level 23 when compiling with `_GNU_SOURCE`.
  */
-
-#if __BIONIC_AVAILABILITY_GUARD(23)
+#if defined(__USE_GNU) && __BIONIC_AVAILABILITY_GUARD(23)
 ssize_t process_vm_readv(pid_t __pid, const struct iovec* __BIONIC_COMPLICATED_NULLNESS __local_iov, unsigned long __local_iov_count, const struct iovec* __BIONIC_COMPLICATED_NULLNESS __remote_iov, unsigned long __remote_iov_count, unsigned long __flags) __INTRODUCED_IN(23);
+#endif
 
 /**
  * [process_vm_writev(2)](https://man7.org/linux/man-pages/man2/process_vm_writev.2.html)
@@ -163,12 +169,10 @@
  * Returns the number of bytes read on success,
  * and returns -1 and sets `errno` on failure.
  *
- * Available since API level 23.
+ * Available since API level 23 when compiling with `_GNU_SOURCE`.
  */
+#if defined(__USE_GNU) && __BIONIC_AVAILABILITY_GUARD(23)
 ssize_t process_vm_writev(pid_t __pid, const struct iovec* __BIONIC_COMPLICATED_NULLNESS __local_iov, unsigned long __local_iov_count, const struct iovec* __BIONIC_COMPLICATED_NULLNESS __remote_iov, unsigned long __remote_iov_count, unsigned long __flags) __INTRODUCED_IN(23);
-#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
-
-
 #endif
 
 __END_DECLS
diff --git a/libc/include/sys/un.h b/libc/include/sys/un.h
index c2bfcb0..a2f0532 100644
--- a/libc/include/sys/un.h
+++ b/libc/include/sys/un.h
@@ -38,8 +38,12 @@
 #include <bits/sa_family_t.h>
 #include <linux/un.h>
 
+__BEGIN_DECLS
+
 #if defined(__USE_BSD) || defined(__USE_GNU)
 #include <string.h>
 /** Returns the actual length of the given `sockaddr_un`. */
 #define SUN_LEN(__ptr) (offsetof(struct sockaddr_un, sun_path) + strlen((__ptr)->sun_path))
 #endif
+
+__END_DECLS
diff --git a/libc/include/sysexits.h b/libc/include/sysexits.h
index b0001e6..b9fade3 100644
--- a/libc/include/sysexits.h
+++ b/libc/include/sysexits.h
@@ -44,6 +44,8 @@
 
 #include <sys/cdefs.h>
 
+__BEGIN_DECLS
+
 /** Successful termination. */
 #define EX_OK  0
 
@@ -163,3 +165,5 @@
 
 /** Maximum listed value. */
 #define EX__MAX  78
+
+__END_DECLS
diff --git a/libc/include/tar.h b/libc/include/tar.h
index 9d0c3ba..3905bfe 100644
--- a/libc/include/tar.h
+++ b/libc/include/tar.h
@@ -35,6 +35,8 @@
 
 #include <sys/cdefs.h>
 
+__BEGIN_DECLS
+
 /** `.tar` file magic. (Includes the NUL.) */
 #define TMAGIC "ustar"
 /** `.tar` file magic length in bytes. */
@@ -87,3 +89,5 @@
 #define TOWRITE 00002
 /** Executable by other mode field bit. */
 #define TOEXEC 00001
+
+__END_DECLS
diff --git a/libc/include/threads.h b/libc/include/threads.h
index 1074fa4..4a42f80 100644
--- a/libc/include/threads.h
+++ b/libc/include/threads.h
@@ -38,6 +38,8 @@
 #include <pthread.h>
 #include <time.h>
 
+__BEGIN_DECLS
+
 #define ONCE_FLAG_INIT PTHREAD_ONCE_INIT
 #define TSS_DTOR_ITERATIONS PTHREAD_DESTRUCTOR_ITERATIONS
 
@@ -78,8 +80,6 @@
 # define thread_local _Thread_local
 #endif
 
-__BEGIN_DECLS
-
 #if __ANDROID_API__ >= 30
 // This file is implemented as static inlines before API level 30.
 
diff --git a/libc/include/time.h b/libc/include/time.h
index 777e648..04451d5 100644
--- a/libc/include/time.h
+++ b/libc/include/time.h
@@ -119,7 +119,7 @@
 
 /**
  * [asctime(3)](https://man7.org/linux/man-pages/man3/asctime.3p.html) formats
- * the time `tm` as a string.
+ * the time `tm` as a string of the form "Thu Aug  1 12:34:56 2025\n".
  *
  * Returns a pointer to a string on success, and returns NULL on failure.
  *
@@ -131,7 +131,11 @@
 
 /**
  * [asctime_r(3)](https://man7.org/linux/man-pages/man3/asctime_r.3p.html) formats
- * the time `tm` as a string in the given buffer `buf`.
+ * the time `tm` as a string of the form "Thu Aug  1 12:34:56 2025\n"
+ * in the given buffer `buf`.
+ *
+ * For realistic times (those with 4 digit years),
+ * the buffer should be 26 bytes long.
  *
  * Returns a pointer to a string on success, and returns NULL on failure.
  *
@@ -140,12 +144,38 @@
 char* _Nullable asctime_r(const struct tm* _Nonnull __tm, char* _Nonnull __buf);
 
 /**
+ * [ctime(3)](https://man7.org/linux/man-pages/man3/ctime.3p.html) formats
+ * the time `tm` as a string of the form "Thu Aug  1 12:34:56 2025\n".
+ *
+ * Returns a pointer to a string on success, and returns NULL on failure.
+ *
+ * That string will be overwritten by later calls to this function.
+ *
+ * New code should prefer strftime().
+ */
+char* _Nullable ctime(const time_t* _Nonnull __t);
+
+/**
+ * [ctime_r(3)](https://man7.org/linux/man-pages/man3/ctime_r.3p.html) formats
+ * the time `tm` as a string of the form "Thu Aug  1 12:34:56 2025\n"
+ * in the given buffer `buf`.
+ *
+ * For realistic times (those with 4 digit years),
+ * the buffer should be 26 bytes long.
+ *
+ * Returns a pointer to a string on success, and returns NULL on failure.
+ *
+ * New code should prefer strftime().
+ */
+char* _Nullable ctime_r(const time_t* _Nonnull __t, char* _Nonnull __buf);
+
+/**
  * [difftime(3)](https://man7.org/linux/man-pages/man3/difftime.3.html) returns
- * the difference between two times.
+ * the difference between two times, equivalent to (time1 - time0).
  *
  * Returns the difference in seconds.
  */
-double difftime(time_t __lhs, time_t __rhs);
+double difftime(time_t __time1, time_t __time0);
 
 /**
  * [mktime(3)](https://man7.org/linux/man-pages/man3/mktime.3p.html) converts
@@ -166,7 +196,6 @@
  *
  * Available since API level 35.
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(35)
 time_t mktime_z(timezone_t _Nonnull __tz, struct tm* _Nonnull __tm) __INTRODUCED_IN(35);
 #endif /* __BIONIC_AVAILABILITY_GUARD(35) */
@@ -204,7 +233,6 @@
  *
  * Available since API level 35.
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(35)
 struct tm* _Nullable localtime_rz(timezone_t _Nonnull __tz, const time_t* _Nonnull __t, struct tm* _Nonnull __tm) __INTRODUCED_IN(35);
 #endif /* __BIONIC_AVAILABILITY_GUARD(35) */
@@ -259,7 +287,8 @@
  * [strftime(3)](https://man7.org/linux/man-pages/man3/strftime.3.html) formats
  * a broken-down time `tm` into the buffer `buf` using format `fmt`.
  *
- * Returns a pointer to the first character _not_ parsed, or null if no characters were parsed.
+ * Returns the number of bytes written (not including the NUL),
+ * or zero if the buffer is too small.
  */
 size_t strftime(char* _Nonnull __buf, size_t __n, const char* _Nonnull __fmt, const struct tm* _Nullable __tm) __strftimelike(3);
 
@@ -269,28 +298,6 @@
 size_t strftime_l(char* _Nonnull __buf, size_t __n, const char* _Nonnull __fmt, const struct tm* _Nullable __tm, locale_t _Nonnull __l) __strftimelike(3);
 
 /**
- * [ctime(3)](https://man7.org/linux/man-pages/man3/ctime.3p.html) formats
- * the time `tm` as a string.
- *
- * Returns a pointer to a string on success, and returns NULL on failure.
- *
- * That string will be overwritten by later calls to this function.
- *
- * New code should prefer strftime().
- */
-char* _Nullable ctime(const time_t* _Nonnull __t);
-
-/**
- * [ctime_r(3)](https://man7.org/linux/man-pages/man3/ctime_r.3p.html) formats
- * the time `tm` as a string in the given buffer `buf`.
- *
- * Returns a pointer to a string on success, and returns NULL on failure.
- *
- * New code should prefer strftime().
- */
-char* _Nullable ctime_r(const time_t* _Nonnull __t, char* _Nonnull __buf);
-
-/**
  * [tzset(3)](https://man7.org/linux/man-pages/man3/tzset.3.html) tells
  * libc that the timezone has changed.
  *
@@ -322,9 +329,9 @@
  *
  * Available since API level 35.
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(35)
 timezone_t _Nullable tzalloc(const char* _Nullable __id) __INTRODUCED_IN(35);
+#endif /* __BIONIC_AVAILABILITY_GUARD(35) */
 
 /**
  * tzfree(3) frees a timezone object returned by tzalloc().
@@ -335,10 +342,10 @@
  *
  * Available since API level 35.
  */
+#if __BIONIC_AVAILABILITY_GUARD(35)
 void tzfree(timezone_t _Nullable __tz) __INTRODUCED_IN(35);
 #endif /* __BIONIC_AVAILABILITY_GUARD(35) */
 
-
 /**
  * [clock(3)](https://man7.org/linux/man-pages/man3/clock.3.html)
  * returns an approximation of CPU time used, equivalent to
@@ -355,9 +362,8 @@
  * [clock_getcpuclockid(3)](https://man7.org/linux/man-pages/man3/clock_getcpuclockid.3.html)
  * gets the clock ID of the cpu-time clock for the given `pid`.
  *
- * Returns 0 on success, and returns -1 and returns an error number on failure.
+ * Returns 0 on success, and returns an error number on failure (unlike other clock functions).
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(23)
 int clock_getcpuclockid(pid_t __pid, clockid_t* _Nonnull __clock) __INTRODUCED_IN(23);
 #endif /* __BIONIC_AVAILABILITY_GUARD(23) */
@@ -367,7 +373,7 @@
  * [clock_getres(2)](https://man7.org/linux/man-pages/man2/clock_getres.2.html)
  * gets the resolution of the given clock.
  *
- * Returns 0 on success, and returns -1 and returns an error number on failure.
+ * Returns 0 on success, and returns -1 and sets `errno` on failure.
  */
 int clock_getres(clockid_t __clock, struct timespec* _Nullable __resolution);
 
@@ -375,7 +381,7 @@
  * [clock_gettime(2)](https://man7.org/linux/man-pages/man2/clock_gettime.2.html)
  * gets the time according to the given clock.
  *
- * Returns 0 on success, and returns -1 and returns an error number on failure.
+ * Returns 0 on success, and returns -1 and sets `errno` on failure.
  */
 int clock_gettime(clockid_t __clock, struct timespec* _Nonnull __ts);
 
@@ -384,7 +390,7 @@
  * sleeps for the given time (or until the given time if the TIMER_ABSTIME flag
  * is used), as measured by the given clock.
  *
- * Returns 0 on success, and returns -1 and returns an error number on failure.
+ * Returns 0 on success, and returns an error number on failure (unlike other clock functions).
  * If the sleep was interrupted by a signal, the return value will be `EINTR`
  * and `remainder` will be the amount of time remaining.
  */
@@ -394,7 +400,7 @@
  * [clock_settime(2)](https://man7.org/linux/man-pages/man2/clock_settime.2.html)
  * sets the time for the given clock.
  *
- * Returns 0 on success, and returns -1 and returns an error number on failure.
+ * Returns 0 on success, and returns -1 and sets `errno` on failure.
  */
 int clock_settime(clockid_t __clock, const struct timespec* _Nonnull __ts);
 
@@ -475,12 +481,10 @@
  * Available since API level 29 for TIME_UTC; other bases arrived later.
  * Code for Android should prefer clock_gettime().
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(29)
 int timespec_get(struct timespec* _Nonnull __ts, int __base) __INTRODUCED_IN(29);
 #endif /* __BIONIC_AVAILABILITY_GUARD(29) */
 
-
 /**
  * timespec_getres(3) is equivalent to clock_getres() for the clock corresponding to the given base.
  *
@@ -489,10 +493,8 @@
  * Available since API level 35.
  * Code for Android should prefer clock_gettime().
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(35)
 int timespec_getres(struct timespec* _Nonnull __ts, int __base) __INTRODUCED_IN(35);
 #endif /* __BIONIC_AVAILABILITY_GUARD(35) */
 
-
 __END_DECLS
diff --git a/libc/include/unistd.h b/libc/include/unistd.h
index 808568a..9aa5a5c 100644
--- a/libc/include/unistd.h
+++ b/libc/include/unistd.h
@@ -30,6 +30,7 @@
 
 #include <sys/cdefs.h>
 
+#include <errno.h>
 #include <stddef.h>
 #include <sys/types.h>
 #include <sys/select.h>
@@ -101,12 +102,10 @@
  *
  * Available since API level 35.
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(35)
 pid_t _Fork(void) __INTRODUCED_IN(35);
 #endif /* __BIONIC_AVAILABILITY_GUARD(35) */
 
-
 /**
  * [vfork(2)](https://man7.org/linux/man-pages/man2/vfork.2.html) creates a new
  * process. vfork() differs from fork() in that it does not run any handlers
@@ -155,7 +154,6 @@
 int fexecve(int __fd, char* _Nullable const* _Nullable __argv, char* _Nullable const* _Nullable __envp) __INTRODUCED_IN(28);
 #endif /* __BIONIC_AVAILABILITY_GUARD(28) */
 
-
 int nice(int __incr);
 
 /**
@@ -260,7 +258,6 @@
 int getlogin_r(char* _Nonnull __buffer, size_t __buffer_size) __INTRODUCED_IN(28);
 #endif /* __BIONIC_AVAILABILITY_GUARD(28) */
 
-
 long fpathconf(int __fd, int __name);
 long pathconf(const char* _Nonnull __path, int __name);
 
@@ -294,10 +291,22 @@
 int fchdir(int __fd);
 
 int rmdir(const char* _Nonnull __path);
+
+/**
+ * [pipe(2)](https://man7.org/linux/man-pages/man2/pipe.2.html) creates a pipe.
+ *
+ * Returns 0 on success, and returns -1 and sets `errno` on failure.
+ */
 int pipe(int __fds[_Nonnull 2]);
-#if defined(__USE_GNU)
+
+/**
+ * [pipe2(2)](https://man7.org/linux/man-pages/man2/pipe2.2.html) creates a pipe,
+ * with flags.
+ *
+ * Returns 0 on success, and returns -1 and sets `errno` on failure.
+ */
 int pipe2(int __fds[_Nonnull 2], int __flags);
-#endif
+
 int chroot(const char* _Nonnull __path);
 int symlink(const char* _Nonnull __old_path, const char* _Nonnull __new_path);
 int symlinkat(const char* _Nonnull __old_path, int __new_dir_fd, const char* _Nonnull __new_path);
@@ -309,13 +318,22 @@
 int lchown(const char* _Nonnull __path, uid_t __owner, gid_t __group);
 char* _Nullable getcwd(char* _Nullable __buf, size_t __size);
 
+/**
+ * [sync(2)](https://man7.org/linux/man-pages/man2/sync.2.html) syncs changes
+ * to disk, for all file systems.
+ */
 void sync(void);
-#if defined(__USE_GNU)
 
-#if __BIONIC_AVAILABILITY_GUARD(28)
+/**
+ * [syncfs(2)](https://man7.org/linux/man-pages/man2/sync.2.html) syncs changes
+ * to disk, for the file system corresponding to the given file descriptor.
+ *
+ * Returns 0 on success, and returns -1 and sets `errno` on failure.
+ *
+ * Available since API level 28 when compiling with `_GNU_SOURCE`.
+ */
+#if defined(__USE_GNU) && __BIONIC_AVAILABILITY_GUARD(28)
 int syncfs(int __fd) __INTRODUCED_IN(28);
-#endif /* __BIONIC_AVAILABILITY_GUARD(28) */
-
 #endif
 
 int close(int __fd);
@@ -376,13 +394,39 @@
 unsigned int sleep(unsigned int __seconds);
 int usleep(useconds_t __microseconds);
 
+#if __BIONIC_AVAILABILITY_GUARD(26)
+/**
+ * [getdomainname(2)](https://man7.org/linux/man-pages/man2/getdomainname.2.html)
+ * copies the system's domain name into the supplied buffer.
+ *
+ * A buffer of size SYS_NMLN from <sys/utsname.h> is guaranteed large enough,
+ * because this is just a wrapper for uname().
+ *
+ * Returns 0 on success, and returns -1 and sets `errno` on failure.
+ */
+int getdomainname(char* _Nonnull __buf, size_t __buf_size) __INTRODUCED_IN(26);
+#endif /* __BIONIC_AVAILABILITY_GUARD(26) */
+
+#if __BIONIC_AVAILABILITY_GUARD(26)
+int setdomainname(const char* _Nonnull __name, size_t __n) __INTRODUCED_IN(26);
+#endif /* __BIONIC_AVAILABILITY_GUARD(26) */
+
+/**
+ * [gethostname(2)](https://man7.org/linux/man-pages/man2/gethostname.2.html)
+ * copies the system's host name into the supplied buffer.
+ *
+ * Contrary to POSIX, this implementation fails if the buffer is too small.
+ * A buffer of size SYS_NMLN from <sys/utsname.h> is guaranteed large enough,
+ * because this is just a wrapper for uname().
+ *
+ * Returns 0 on success, and returns -1 and sets `errno` on failure.
+ */
 int gethostname(char* _Nonnull _buf, size_t __buf_size);
 
 #if __BIONIC_AVAILABILITY_GUARD(23)
 int sethostname(const char* _Nonnull __name, size_t __n) __INTRODUCED_IN(23);
 #endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
-
 int brk(void* _Nonnull __addr);
 void* _Nullable sbrk(ptrdiff_t __increment);
 
@@ -424,13 +468,6 @@
     } while (_rc == -1 && errno == EINTR); \
     _rc; })
 
-
-#if __BIONIC_AVAILABILITY_GUARD(26)
-int getdomainname(char* _Nonnull __buf, size_t __buf_size) __INTRODUCED_IN(26);
-int setdomainname(const char* _Nonnull __name, size_t __n) __INTRODUCED_IN(26);
-#endif /* __BIONIC_AVAILABILITY_GUARD(26) */
-
-
 /**
  * [copy_file_range(2)](https://man7.org/linux/man-pages/man2/copy_file_range.2.html) copies
  * a range of data from one file descriptor to another.
@@ -440,7 +477,6 @@
  * Returns the number of bytes copied on success, and returns -1 and sets
  * `errno` on failure.
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(34)
 ssize_t copy_file_range(int __fd_in, off64_t* _Nullable __off_in, int __fd_out, off64_t* _Nullable __off_out, size_t __length, unsigned int __flags) __INTRODUCED_IN(34);
 #endif /* __BIONIC_AVAILABILITY_GUARD(34) */
@@ -464,7 +500,6 @@
  *
  * Returns 0 on success, and returns -1 and sets `errno` on failure.
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(34)
 int close_range(unsigned int __min_fd, unsigned int __max_fd, int __flags) __INTRODUCED_IN(34);
 #endif /* __BIONIC_AVAILABILITY_GUARD(34) */
diff --git a/libc/include/utime.h b/libc/include/utime.h
index f06a028..51da492 100644
--- a/libc/include/utime.h
+++ b/libc/include/utime.h
@@ -41,12 +41,12 @@
 
 /**
  * [utime(2)](https://man7.org/linux/man-pages/man2/utime.2.html) changes the access and
- * modification time of `__filename`. If `__times` is null, the current time is used.
+ * modification times of the given path. If `__times` is null, the current time is used.
  *
  * New code should prefer utimensat().
  *
  * Returns 0 on success and returns -1 and sets `errno` on failure.
  */
-int utime(const char* _Nonnull __filename, const struct utimbuf* _Nullable __times);
+int utime(const char* _Nonnull __path, const struct utimbuf* _Nullable __times);
 
 __END_DECLS
diff --git a/libc/include/utmp.h b/libc/include/utmp.h
index 1674491..d64bd19 100644
--- a/libc/include/utmp.h
+++ b/libc/include/utmp.h
@@ -37,6 +37,8 @@
 #include <sys/types.h>
 #include <time.h>
 
+__BEGIN_DECLS
+
 #define _PATH_UTMP      "/var/run/utmp"
 #define _PATH_WTMP      "/var/log/wtmp"
 #define _PATH_LASTLOG   "/var/log/lastlog"
@@ -94,8 +96,6 @@
 #define ut_time ut_tv.tv_sec
 #define ut_addr ut_addr_v6[0]
 
-__BEGIN_DECLS
-
 /**
  * Returns -1 and sets errno to ENOTSUP.
  */
@@ -131,10 +131,8 @@
  *
  * Available since API level 23.
  */
-
 #if __BIONIC_AVAILABILITY_GUARD(23)
 int login_tty(int __fd) __INTRODUCED_IN(23);
 #endif /* __BIONIC_AVAILABILITY_GUARD(23) */
 
-
 __END_DECLS
diff --git a/libc/include/utmpx.h b/libc/include/utmpx.h
index 5ed8e1a..3f00209 100644
--- a/libc/include/utmpx.h
+++ b/libc/include/utmpx.h
@@ -37,6 +37,8 @@
 #include <sys/types.h>
 #include <time.h>
 
+__BEGIN_DECLS
+
 #define EMPTY         0
 #define RUN_LVL       1
 #define BOOT_TIME     2
@@ -68,8 +70,6 @@
   char unused[20];
 };
 
-__BEGIN_DECLS
-
 /**
  * Does nothing.
  */
diff --git a/libc/include/wchar.h b/libc/include/wchar.h
index 56594dc..f3cd98d 100644
--- a/libc/include/wchar.h
+++ b/libc/include/wchar.h
@@ -44,14 +44,33 @@
 
 __BEGIN_DECLS
 
-wint_t btowc(int __ch);
 int fwprintf(FILE* _Nonnull __fp, const wchar_t* _Nonnull __fmt, ...);
 int fwscanf(FILE* _Nonnull __fp, const wchar_t* _Nonnull __fmt, ...);
 wint_t fgetwc(FILE* _Nonnull __fp);
 wchar_t* _Nullable fgetws(wchar_t* _Nonnull __buf, int __size, FILE* _Nonnull __fp);
 wint_t fputwc(wchar_t __wc, FILE* _Nonnull __fp);
 int fputws(const wchar_t* _Nonnull __s, FILE* _Nonnull __fp);
+
+/**
+ * [fwide(3)](https://www.man7.org/linux/man-pages/man3/fwide.3.html)
+ * gets/sets the orientation of a stream.
+ *
+ * Use a positive value to set wide character orientation,
+ * a negative value to set byte orientation,
+ * or 0 to leave the orientation unset if it hasn't already been set.
+ *
+ * ISO C says that byte operations "shall not" be applied to a wide character
+ * stream and vice versa, but Android -- and other BSD-derived stdio
+ * implementations -- do not enforce this.
+ * On Android orientation is largely meaningless, and only tells you whether
+ * the first operation on the stream was a byte or a wide character operation.
+ *
+ * Returns a positive value for a wide stream,
+ * a negative value for a byte stream,
+ * or 0 if the orientation has not yet been set.
+ */
 int fwide(FILE* _Nonnull __fp, int __mode);
+
 wint_t getwc(FILE* _Nonnull __fp);
 wint_t getwchar(void);
 int mbsinit(const mbstate_t* _Nullable __ps);
@@ -83,7 +102,6 @@
 wchar_t* _Nonnull wcscat(wchar_t* _Nonnull __dst, const wchar_t* _Nonnull __src);
 wchar_t* _Nullable wcschr(const wchar_t * _Nonnull __s, wchar_t __wc);
 int wcscmp(const wchar_t* _Nonnull __lhs, const wchar_t* _Nonnull __rhs);
-int wcscoll(const wchar_t* _Nonnull __lhs, const wchar_t* _Nonnull __rhs);
 wchar_t* _Nonnull wcscpy(wchar_t* _Nonnull __dst, const wchar_t* _Nonnull __src);
 size_t wcscspn(const wchar_t* _Nonnull __s, const wchar_t* _Nonnull __accept);
 size_t wcsftime(wchar_t* _Nonnull __buf, size_t __n, const wchar_t* _Nullable __fmt, const struct tm* _Nonnull __tm);
@@ -122,19 +140,15 @@
 unsigned long wcstoul_l(const wchar_t* _Nonnull __s, wchar_t* __BIONIC_COMPLICATED_NULLNESS * _Nullable __end_ptr, int __base, locale_t _Nonnull __l) __RENAME(wcstoul);
 unsigned long long wcstoull(const wchar_t* _Nonnull __s, wchar_t* __BIONIC_COMPLICATED_NULLNESS * _Nullable __end_ptr, int __base);
 int wcswidth(const wchar_t* _Nonnull __s, size_t __n);
-size_t wcsxfrm(wchar_t* __BIONIC_COMPLICATED_NULLNESS __dst, const wchar_t* _Nonnull __src, size_t __n);
-int wctob(wint_t __wc);
 int wcwidth(wchar_t __wc);
 wchar_t* _Nullable wmemchr(const wchar_t* _Nonnull __src, wchar_t __wc, size_t __n);
 int wmemcmp(const wchar_t* _Nullable __lhs, const wchar_t* _Nullable __rhs, size_t __n);
 wchar_t* _Nonnull wmemcpy(wchar_t* _Nonnull __dst, const wchar_t* _Nonnull __src, size_t __n);
-#if defined(__USE_GNU)
 
-#if __BIONIC_AVAILABILITY_GUARD(23)
+#if defined(__USE_GNU) && __BIONIC_AVAILABILITY_GUARD(23)
 wchar_t* _Nonnull wmempcpy(wchar_t* _Nonnull __dst, const wchar_t* _Nonnull __src, size_t __n) __INTRODUCED_IN(23);
-#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
-
 #endif
+
 wchar_t* _Nonnull wmemmove(wchar_t* _Nonnull __dst, const wchar_t* _Nonnull __src, size_t __n);
 wchar_t* _Nonnull wmemset(wchar_t* _Nonnull __dst, wchar_t __wc, size_t __n);
 int wprintf(const wchar_t* _Nonnull __fmt, ...);
@@ -144,8 +158,15 @@
 unsigned long long wcstoull_l(const wchar_t* _Nonnull __s, wchar_t* _Nullable * _Nullable __end_ptr, int __base, locale_t _Nonnull __l);
 long double wcstold_l(const wchar_t* _Nonnull __s, wchar_t* _Nullable * _Nullable __end_ptr, locale_t _Nonnull __l);
 
+/** Equivalent to wcscmp() on Android. */
+int wcscoll(const wchar_t* _Nonnull __lhs, const wchar_t* _Nonnull __rhs);
+/** Equivalent to wcscmp() on Android. */
 int wcscoll_l(const wchar_t* _Nonnull __lhs, const wchar_t* _Nonnull __rhs, locale_t _Nonnull __l) __attribute_pure__;
+/** Equivalent to wcslcpy() on Android. */
+size_t wcsxfrm(wchar_t* __BIONIC_COMPLICATED_NULLNESS __dst, const wchar_t* _Nonnull __src, size_t __n);
+/** Equivalent to wcslcpy() on Android. */
 size_t wcsxfrm_l(wchar_t* __BIONIC_COMPLICATED_NULLNESS __dst, const wchar_t* _Nonnull __src, size_t __n, locale_t _Nonnull __l);
+
 size_t wcslcat(wchar_t* _Nonnull __dst, const wchar_t* _Nonnull __src, size_t __n);
 size_t wcslcpy(wchar_t* _Nonnull __dst, const wchar_t* _Nonnull __src, size_t __n);
 
@@ -157,6 +178,11 @@
 wchar_t* _Nullable wcsdup(const wchar_t* _Nonnull __s);
 size_t wcsnlen(const wchar_t* _Nonnull __s, size_t __n);
 
+/** ASCII-only; use mbtowc() instead. */
+wint_t btowc(int __ch) __attribute__((__deprecated__("ASCII-only; use mbtowc() instead")));
+/** ASCII-only; use wctomb() instead. */
+int wctob(wint_t __wc) __attribute__((__deprecated__("ASCII-only; use wctomb() instead")));
+
 __END_DECLS
 
 #endif
diff --git a/libc/include/wctype.h b/libc/include/wctype.h
index 30ec04f..b1d716c 100644
--- a/libc/include/wctype.h
+++ b/libc/include/wctype.h
@@ -52,12 +52,13 @@
 wint_t towlower_l(wint_t __wc, locale_t _Nonnull __l);
 wint_t towupper_l(wint_t __wc, locale_t _Nonnull __l);
 
-
 #if __BIONIC_AVAILABILITY_GUARD(26)
 wint_t towctrans_l(wint_t __wc, wctrans_t _Nonnull __transform, locale_t _Nonnull __l) __INTRODUCED_IN(26);
-wctrans_t _Nonnull wctrans_l(const char* _Nonnull __name, locale_t _Nonnull __l) __INTRODUCED_IN(26);
 #endif /* __BIONIC_AVAILABILITY_GUARD(26) */
 
+#if __BIONIC_AVAILABILITY_GUARD(26)
+wctrans_t _Nonnull wctrans_l(const char* _Nonnull __name, locale_t _Nonnull __l) __INTRODUCED_IN(26);
+#endif /* __BIONIC_AVAILABILITY_GUARD(26) */
 
 wctype_t wctype_l(const char* _Nonnull __name, locale_t _Nonnull __l);
 int iswctype_l(wint_t __wc, wctype_t __transform, locale_t _Nonnull __l);
diff --git a/libc/include/xlocale.h b/libc/include/xlocale.h
index d04a711..aa1cefd 100644
--- a/libc/include/xlocale.h
+++ b/libc/include/xlocale.h
@@ -40,6 +40,8 @@
 
 #include <sys/cdefs.h>
 
+__BEGIN_DECLS
+
 /* If we just use void* in the typedef, the compiler exposes that in error messages. */
 struct __locale_t;
 
@@ -47,3 +49,5 @@
  * The `locale_t` type that represents a locale.
  */
 typedef struct __locale_t* locale_t;
+
+__END_DECLS
diff --git a/libc/kernel/android/scsi/scsi/scsi_proto.h b/libc/kernel/android/scsi/scsi/scsi_proto.h
index 754e12a..7d15cce 100644
--- a/libc/kernel/android/scsi/scsi/scsi_proto.h
+++ b/libc/kernel/android/scsi/scsi/scsi_proto.h
@@ -23,8 +23,8 @@
 #define INQUIRY 0x12
 #define RECOVER_BUFFERED_DATA 0x14
 #define MODE_SELECT 0x15
-#define RESERVE 0x16
-#define RELEASE 0x17
+#define RESERVE_6 0x16
+#define RELEASE_6 0x17
 #define COPY 0x18
 #define ERASE 0x19
 #define MODE_SENSE 0x1a
diff --git a/libc/kernel/uapi/asm-arm/asm/unistd-eabi.h b/libc/kernel/uapi/asm-arm/asm/unistd-eabi.h
index 9c4e459..38de194 100644
--- a/libc/kernel/uapi/asm-arm/asm/unistd-eabi.h
+++ b/libc/kernel/uapi/asm-arm/asm/unistd-eabi.h
@@ -421,4 +421,9 @@
 #define __NR_lsm_set_self_attr (__NR_SYSCALL_BASE + 460)
 #define __NR_lsm_list_modules (__NR_SYSCALL_BASE + 461)
 #define __NR_mseal (__NR_SYSCALL_BASE + 462)
+#define __NR_setxattrat (__NR_SYSCALL_BASE + 463)
+#define __NR_getxattrat (__NR_SYSCALL_BASE + 464)
+#define __NR_listxattrat (__NR_SYSCALL_BASE + 465)
+#define __NR_removexattrat (__NR_SYSCALL_BASE + 466)
+#define __NR_open_tree_attr (__NR_SYSCALL_BASE + 467)
 #endif
diff --git a/libc/kernel/uapi/asm-arm/asm/unistd-oabi.h b/libc/kernel/uapi/asm-arm/asm/unistd-oabi.h
index 5060c2f..7fab02e 100644
--- a/libc/kernel/uapi/asm-arm/asm/unistd-oabi.h
+++ b/libc/kernel/uapi/asm-arm/asm/unistd-oabi.h
@@ -433,4 +433,9 @@
 #define __NR_lsm_set_self_attr (__NR_SYSCALL_BASE + 460)
 #define __NR_lsm_list_modules (__NR_SYSCALL_BASE + 461)
 #define __NR_mseal (__NR_SYSCALL_BASE + 462)
+#define __NR_setxattrat (__NR_SYSCALL_BASE + 463)
+#define __NR_getxattrat (__NR_SYSCALL_BASE + 464)
+#define __NR_listxattrat (__NR_SYSCALL_BASE + 465)
+#define __NR_removexattrat (__NR_SYSCALL_BASE + 466)
+#define __NR_open_tree_attr (__NR_SYSCALL_BASE + 467)
 #endif
diff --git a/libc/kernel/uapi/asm-arm64/asm/hwcap.h b/libc/kernel/uapi/asm-arm64/asm/hwcap.h
index 45cc945..635eef8 100644
--- a/libc/kernel/uapi/asm-arm64/asm/hwcap.h
+++ b/libc/kernel/uapi/asm-arm64/asm/hwcap.h
@@ -38,6 +38,22 @@
 #define HWCAP_SB (1 << 29)
 #define HWCAP_PACA (1 << 30)
 #define HWCAP_PACG (1UL << 31)
+#define HWCAP_GCS (1UL << 32)
+#define HWCAP_CMPBR (1UL << 33)
+#define HWCAP_FPRCVT (1UL << 34)
+#define HWCAP_F8MM8 (1UL << 35)
+#define HWCAP_F8MM4 (1UL << 36)
+#define HWCAP_SVE_F16MM (1UL << 37)
+#define HWCAP_SVE_ELTPERM (1UL << 38)
+#define HWCAP_SVE_AES2 (1UL << 39)
+#define HWCAP_SVE_BFSCALE (1UL << 40)
+#define HWCAP_SVE2P2 (1UL << 41)
+#define HWCAP_SME2P2 (1UL << 42)
+#define HWCAP_SME_SBITPERM (1UL << 43)
+#define HWCAP_SME_AES (1UL << 44)
+#define HWCAP_SME_SFEXPA (1UL << 45)
+#define HWCAP_SME_STMOP (1UL << 46)
+#define HWCAP_SME_SMOP4 (1UL << 47)
 #define HWCAP2_DCPODP (1 << 0)
 #define HWCAP2_SVE2 (1 << 1)
 #define HWCAP2_SVEAES (1 << 2)
diff --git a/libc/kernel/uapi/asm-arm64/asm/kvm.h b/libc/kernel/uapi/asm-arm64/asm/kvm.h
index 1818c5f..f6078ed 100644
--- a/libc/kernel/uapi/asm-arm64/asm/kvm.h
+++ b/libc/kernel/uapi/asm-arm64/asm/kvm.h
@@ -22,7 +22,6 @@
 #define __KVM_HAVE_VCPU_EVENTS
 #define KVM_COALESCED_MMIO_PAGE_OFFSET 1
 #define KVM_DIRTY_LOG_PAGE_OFFSET 64
-#define KVM_REG_SIZE(id) (1U << (((id) & KVM_REG_SIZE_MASK) >> KVM_REG_SIZE_SHIFT))
 struct kvm_regs {
   struct user_pt_regs regs;
   __u64 sp_el1;
@@ -61,6 +60,7 @@
 #define KVM_ARM_VCPU_PTRAUTH_ADDRESS 5
 #define KVM_ARM_VCPU_PTRAUTH_GENERIC 6
 #define KVM_ARM_VCPU_HAS_EL2 7
+#define KVM_ARM_VCPU_HAS_EL2_E2H0 8
 struct kvm_vcpu_init {
   __u32 target;
   __u32 features[7];
@@ -197,6 +197,11 @@
   KVM_REG_ARM_VENDOR_HYP_BIT_FUNC_FEAT = 0,
   KVM_REG_ARM_VENDOR_HYP_BIT_PTP = 1,
 };
+#define KVM_REG_ARM_VENDOR_HYP_BMAP_2 KVM_REG_ARM_FW_FEAT_BMAP_REG(3)
+enum {
+  KVM_REG_ARM_VENDOR_HYP_BIT_DISCOVER_IMPL_VER = 0,
+  KVM_REG_ARM_VENDOR_HYP_BIT_DISCOVER_IMPL_CPUS = 1,
+};
 #define KVM_ARM_VM_SMCCC_CTRL 0
 #define KVM_ARM_VM_SMCCC_FILTER 0
 #define KVM_DEV_ARM_VGIC_GRP_ADDR 0
@@ -215,6 +220,7 @@
 #define KVM_DEV_ARM_VGIC_GRP_CPU_SYSREGS 6
 #define KVM_DEV_ARM_VGIC_GRP_LEVEL_INFO 7
 #define KVM_DEV_ARM_VGIC_GRP_ITS_REGS 8
+#define KVM_DEV_ARM_VGIC_GRP_MAINT_IRQ 9
 #define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT 10
 #define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_MASK (0x3fffffULL << KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT)
 #define KVM_DEV_ARM_VGIC_LINE_LEVEL_INTID_MASK 0x3ff
@@ -229,6 +235,7 @@
 #define KVM_ARM_VCPU_PMU_V3_INIT 1
 #define KVM_ARM_VCPU_PMU_V3_FILTER 2
 #define KVM_ARM_VCPU_PMU_V3_SET_PMU 3
+#define KVM_ARM_VCPU_PMU_V3_SET_NR_COUNTERS 4
 #define KVM_ARM_VCPU_TIMER_CTRL 1
 #define KVM_ARM_VCPU_TIMER_IRQ_VTIMER 0
 #define KVM_ARM_VCPU_TIMER_IRQ_PTIMER 1
@@ -262,6 +269,7 @@
 #define KVM_PSCI_RET_INVAL PSCI_RET_INVALID_PARAMS
 #define KVM_PSCI_RET_DENIED PSCI_RET_DENIED
 #define KVM_SYSTEM_EVENT_RESET_FLAG_PSCI_RESET2 (1ULL << 0)
+#define KVM_SYSTEM_EVENT_SHUTDOWN_FLAG_PSCI_OFF2 (1ULL << 0)
 #define KVM_EXIT_FAIL_ENTRY_CPU_UNSUPPORTED (1ULL << 0)
 enum kvm_smccc_filter_action {
   KVM_SMCCC_FILTER_HANDLE = 0,
diff --git a/libc/kernel/uapi/asm-arm64/asm/ptrace.h b/libc/kernel/uapi/asm-arm64/asm/ptrace.h
index 4541a66..6d79ecd 100644
--- a/libc/kernel/uapi/asm-arm64/asm/ptrace.h
+++ b/libc/kernel/uapi/asm-arm64/asm/ptrace.h
@@ -127,5 +127,10 @@
 #define ZA_PT_ZAV_OFFSET(vq,n) (ZA_PT_ZA_OFFSET + ((vq * __SVE_VQ_BYTES) * n))
 #define ZA_PT_ZA_SIZE(vq) ((vq * __SVE_VQ_BYTES) * (vq * __SVE_VQ_BYTES))
 #define ZA_PT_SIZE(vq) (ZA_PT_ZA_OFFSET + ZA_PT_ZA_SIZE(vq))
+struct user_gcs {
+  __u64 features_enabled;
+  __u64 features_locked;
+  __u64 gcspr_el0;
+};
 #endif
 #endif
diff --git a/libc/kernel/uapi/asm-arm64/asm/sigcontext.h b/libc/kernel/uapi/asm-arm64/asm/sigcontext.h
index a845a03..b21a44c 100644
--- a/libc/kernel/uapi/asm-arm64/asm/sigcontext.h
+++ b/libc/kernel/uapi/asm-arm64/asm/sigcontext.h
@@ -74,6 +74,13 @@
   __u16 nregs;
   __u16 __reserved[3];
 };
+#define GCS_MAGIC 0x47435300
+struct gcs_context {
+  struct _aarch64_ctx head;
+  __u64 gcspr;
+  __u64 features_enabled;
+  __u64 reserved;
+};
 #endif
 #include <asm/sve_context.h>
 #define SVE_VQ_BYTES __SVE_VQ_BYTES
diff --git a/libc/kernel/uapi/asm-arm64/asm/unistd_64.h b/libc/kernel/uapi/asm-arm64/asm/unistd_64.h
index 0a0a1c0..cf278a4 100644
--- a/libc/kernel/uapi/asm-arm64/asm/unistd_64.h
+++ b/libc/kernel/uapi/asm-arm64/asm/unistd_64.h
@@ -324,4 +324,9 @@
 #define __NR_lsm_set_self_attr 460
 #define __NR_lsm_list_modules 461
 #define __NR_mseal 462
+#define __NR_setxattrat 463
+#define __NR_getxattrat 464
+#define __NR_listxattrat 465
+#define __NR_removexattrat 466
+#define __NR_open_tree_attr 467
 #endif
diff --git a/libc/kernel/uapi/asm-generic/ioctl.h b/libc/kernel/uapi/asm-generic/ioctl.h
index d614fef..88fab7f 100644
--- a/libc/kernel/uapi/asm-generic/ioctl.h
+++ b/libc/kernel/uapi/asm-generic/ioctl.h
@@ -34,12 +34,12 @@
 #define _IOC(dir,type,nr,size) (((dir) << _IOC_DIRSHIFT) | ((type) << _IOC_TYPESHIFT) | ((nr) << _IOC_NRSHIFT) | ((size) << _IOC_SIZESHIFT))
 #define _IOC_TYPECHECK(t) (sizeof(t))
 #define _IO(type,nr) _IOC(_IOC_NONE, (type), (nr), 0)
-#define _IOR(type,nr,size) _IOC(_IOC_READ, (type), (nr), (_IOC_TYPECHECK(size)))
-#define _IOW(type,nr,size) _IOC(_IOC_WRITE, (type), (nr), (_IOC_TYPECHECK(size)))
-#define _IOWR(type,nr,size) _IOC(_IOC_READ | _IOC_WRITE, (type), (nr), (_IOC_TYPECHECK(size)))
-#define _IOR_BAD(type,nr,size) _IOC(_IOC_READ, (type), (nr), sizeof(size))
-#define _IOW_BAD(type,nr,size) _IOC(_IOC_WRITE, (type), (nr), sizeof(size))
-#define _IOWR_BAD(type,nr,size) _IOC(_IOC_READ | _IOC_WRITE, (type), (nr), sizeof(size))
+#define _IOR(type,nr,argtype) _IOC(_IOC_READ, (type), (nr), (_IOC_TYPECHECK(argtype)))
+#define _IOW(type,nr,argtype) _IOC(_IOC_WRITE, (type), (nr), (_IOC_TYPECHECK(argtype)))
+#define _IOWR(type,nr,argtype) _IOC(_IOC_READ | _IOC_WRITE, (type), (nr), (_IOC_TYPECHECK(argtype)))
+#define _IOR_BAD(type,nr,argtype) _IOC(_IOC_READ, (type), (nr), sizeof(argtype))
+#define _IOW_BAD(type,nr,argtype) _IOC(_IOC_WRITE, (type), (nr), sizeof(argtype))
+#define _IOWR_BAD(type,nr,argtype) _IOC(_IOC_READ | _IOC_WRITE, (type), (nr), sizeof(argtype))
 #define _IOC_DIR(nr) (((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK)
 #define _IOC_TYPE(nr) (((nr) >> _IOC_TYPESHIFT) & _IOC_TYPEMASK)
 #define _IOC_NR(nr) (((nr) >> _IOC_NRSHIFT) & _IOC_NRMASK)
diff --git a/libc/kernel/uapi/asm-generic/mman-common.h b/libc/kernel/uapi/asm-generic/mman-common.h
index 55e0ca1..9dabadf 100644
--- a/libc/kernel/uapi/asm-generic/mman-common.h
+++ b/libc/kernel/uapi/asm-generic/mman-common.h
@@ -52,7 +52,10 @@
 #define MADV_POPULATE_WRITE 23
 #define MADV_DONTNEED_LOCKED 24
 #define MADV_COLLAPSE 25
+#define MADV_GUARD_INSTALL 102
+#define MADV_GUARD_REMOVE 103
 #define MAP_FILE 0
+#define PKEY_UNRESTRICTED 0x0
 #define PKEY_DISABLE_ACCESS 0x1
 #define PKEY_DISABLE_WRITE 0x2
 #define PKEY_ACCESS_MASK (PKEY_DISABLE_ACCESS | PKEY_DISABLE_WRITE)
diff --git a/libc/kernel/uapi/asm-generic/mman.h b/libc/kernel/uapi/asm-generic/mman.h
index a2a5de9..d6e6d5f 100644
--- a/libc/kernel/uapi/asm-generic/mman.h
+++ b/libc/kernel/uapi/asm-generic/mman.h
@@ -15,4 +15,6 @@
 #define MCL_CURRENT 1
 #define MCL_FUTURE 2
 #define MCL_ONFAULT 4
+#define SHADOW_STACK_SET_TOKEN (1ULL << 0)
+#define SHADOW_STACK_SET_MARKER (1ULL << 1)
 #endif
diff --git a/libc/kernel/uapi/asm-generic/socket.h b/libc/kernel/uapi/asm-generic/socket.h
index a580c4c..49ce006 100644
--- a/libc/kernel/uapi/asm-generic/socket.h
+++ b/libc/kernel/uapi/asm-generic/socket.h
@@ -97,6 +97,9 @@
 #define SO_DEVMEM_DMABUF 79
 #define SCM_DEVMEM_DMABUF SO_DEVMEM_DMABUF
 #define SO_DEVMEM_DONTNEED 80
+#define SCM_TS_OPT_ID 81
+#define SO_RCVPRIORITY 82
+#define SO_PASSRIGHTS 83
 #if __BITS_PER_LONG == 64 || defined(__x86_64__) && defined(__ILP32__)
 #define SO_TIMESTAMP SO_TIMESTAMP_OLD
 #define SO_TIMESTAMPNS SO_TIMESTAMPNS_OLD
diff --git a/libc/kernel/uapi/asm-generic/unistd.h b/libc/kernel/uapi/asm-generic/unistd.h
index 652e7a2..0ab40ca 100644
--- a/libc/kernel/uapi/asm-generic/unistd.h
+++ b/libc/kernel/uapi/asm-generic/unistd.h
@@ -411,8 +411,13 @@
 #define __NR_lsm_set_self_attr 460
 #define __NR_lsm_list_modules 461
 #define __NR_mseal 462
+#define __NR_setxattrat 463
+#define __NR_getxattrat 464
+#define __NR_listxattrat 465
+#define __NR_removexattrat 466
+#define __NR_open_tree_attr 467
 #undef __NR_syscalls
-#define __NR_syscalls 463
+#define __NR_syscalls 468
 #if __BITS_PER_LONG == 64 && !defined(__SYSCALL_COMPAT)
 #define __NR_fcntl __NR3264_fcntl
 #define __NR_statfs __NR3264_statfs
diff --git a/libc/kernel/uapi/asm-riscv/asm/hwprobe.h b/libc/kernel/uapi/asm-riscv/asm/hwprobe.h
index 2e5f9a4..7cbe220 100644
--- a/libc/kernel/uapi/asm-riscv/asm/hwprobe.h
+++ b/libc/kernel/uapi/asm-riscv/asm/hwprobe.h
@@ -66,6 +66,16 @@
 #define RISCV_HWPROBE_EXT_ZCF (1ULL << 46)
 #define RISCV_HWPROBE_EXT_ZCMOP (1ULL << 47)
 #define RISCV_HWPROBE_EXT_ZAWRS (1ULL << 48)
+#define RISCV_HWPROBE_EXT_SUPM (1ULL << 49)
+#define RISCV_HWPROBE_EXT_ZICNTR (1ULL << 50)
+#define RISCV_HWPROBE_EXT_ZIHPM (1ULL << 51)
+#define RISCV_HWPROBE_EXT_ZFBFMIN (1ULL << 52)
+#define RISCV_HWPROBE_EXT_ZVFBFMIN (1ULL << 53)
+#define RISCV_HWPROBE_EXT_ZVFBFWMA (1ULL << 54)
+#define RISCV_HWPROBE_EXT_ZICBOM (1ULL << 55)
+#define RISCV_HWPROBE_EXT_ZAAMO (1ULL << 56)
+#define RISCV_HWPROBE_EXT_ZALRSC (1ULL << 57)
+#define RISCV_HWPROBE_EXT_ZABHA (1ULL << 58)
 #define RISCV_HWPROBE_KEY_CPUPERF_0 5
 #define RISCV_HWPROBE_MISALIGNED_UNKNOWN (0 << 0)
 #define RISCV_HWPROBE_MISALIGNED_EMULATED (1 << 0)
@@ -82,5 +92,13 @@
 #define RISCV_HWPROBE_MISALIGNED_SCALAR_SLOW 2
 #define RISCV_HWPROBE_MISALIGNED_SCALAR_FAST 3
 #define RISCV_HWPROBE_MISALIGNED_SCALAR_UNSUPPORTED 4
+#define RISCV_HWPROBE_KEY_MISALIGNED_VECTOR_PERF 10
+#define RISCV_HWPROBE_MISALIGNED_VECTOR_UNKNOWN 0
+#define RISCV_HWPROBE_MISALIGNED_VECTOR_SLOW 2
+#define RISCV_HWPROBE_MISALIGNED_VECTOR_FAST 3
+#define RISCV_HWPROBE_MISALIGNED_VECTOR_UNSUPPORTED 4
+#define RISCV_HWPROBE_KEY_VENDOR_EXT_THEAD_0 11
+#define RISCV_HWPROBE_KEY_ZICBOM_BLOCK_SIZE 12
+#define RISCV_HWPROBE_KEY_VENDOR_EXT_SIFIVE_0 13
 #define RISCV_HWPROBE_WHICH_CPUS (1 << 0)
 #endif
diff --git a/libc/kernel/uapi/asm-riscv/asm/kvm.h b/libc/kernel/uapi/asm-riscv/asm/kvm.h
index 51f4977..4b1f874 100644
--- a/libc/kernel/uapi/asm-riscv/asm/kvm.h
+++ b/libc/kernel/uapi/asm-riscv/asm/kvm.h
@@ -135,6 +135,15 @@
   KVM_RISCV_ISA_EXT_ZCF,
   KVM_RISCV_ISA_EXT_ZCMOP,
   KVM_RISCV_ISA_EXT_ZAWRS,
+  KVM_RISCV_ISA_EXT_SMNPM,
+  KVM_RISCV_ISA_EXT_SSNPM,
+  KVM_RISCV_ISA_EXT_SVADE,
+  KVM_RISCV_ISA_EXT_SVADU,
+  KVM_RISCV_ISA_EXT_SVVPTC,
+  KVM_RISCV_ISA_EXT_ZABHA,
+  KVM_RISCV_ISA_EXT_ZICCRSE,
+  KVM_RISCV_ISA_EXT_ZAAMO,
+  KVM_RISCV_ISA_EXT_ZALRSC,
   KVM_RISCV_ISA_EXT_MAX,
 };
 enum KVM_RISCV_SBI_EXT_ID {
@@ -149,6 +158,7 @@
   KVM_RISCV_SBI_EXT_VENDOR,
   KVM_RISCV_SBI_EXT_DBCN,
   KVM_RISCV_SBI_EXT_STA,
+  KVM_RISCV_SBI_EXT_SUSP,
   KVM_RISCV_SBI_EXT_MAX,
 };
 struct kvm_riscv_sbi_sta {
@@ -157,7 +167,6 @@
 };
 #define KVM_RISCV_TIMER_STATE_OFF 0
 #define KVM_RISCV_TIMER_STATE_ON 1
-#define KVM_REG_SIZE(id) (1U << (((id) & KVM_REG_SIZE_MASK) >> KVM_REG_SIZE_SHIFT))
 #define KVM_REG_RISCV_TYPE_MASK 0x00000000FF000000
 #define KVM_REG_RISCV_TYPE_SHIFT 24
 #define KVM_REG_RISCV_SUBTYPE_MASK 0x0000000000FF0000
diff --git a/libc/kernel/uapi/asm-riscv/asm/unistd_32.h b/libc/kernel/uapi/asm-riscv/asm/unistd_32.h
index 864a556..03487ce 100644
--- a/libc/kernel/uapi/asm-riscv/asm/unistd_32.h
+++ b/libc/kernel/uapi/asm-riscv/asm/unistd_32.h
@@ -315,4 +315,9 @@
 #define __NR_lsm_set_self_attr 460
 #define __NR_lsm_list_modules 461
 #define __NR_mseal 462
+#define __NR_setxattrat 463
+#define __NR_getxattrat 464
+#define __NR_listxattrat 465
+#define __NR_removexattrat 466
+#define __NR_open_tree_attr 467
 #endif
diff --git a/libc/kernel/uapi/asm-riscv/asm/unistd_64.h b/libc/kernel/uapi/asm-riscv/asm/unistd_64.h
index f15b65b..d3977a3 100644
--- a/libc/kernel/uapi/asm-riscv/asm/unistd_64.h
+++ b/libc/kernel/uapi/asm-riscv/asm/unistd_64.h
@@ -325,4 +325,9 @@
 #define __NR_lsm_set_self_attr 460
 #define __NR_lsm_list_modules 461
 #define __NR_mseal 462
+#define __NR_setxattrat 463
+#define __NR_getxattrat 464
+#define __NR_listxattrat 465
+#define __NR_removexattrat 466
+#define __NR_open_tree_attr 467
 #endif
diff --git a/libc/kernel/uapi/asm-riscv/asm/vendor/sifive.h b/libc/kernel/uapi/asm-riscv/asm/vendor/sifive.h
new file mode 100644
index 0000000..bd2739a
--- /dev/null
+++ b/libc/kernel/uapi/asm-riscv/asm/vendor/sifive.h
@@ -0,0 +1,10 @@
+/*
+ * This file is auto-generated. Modifications will be lost.
+ *
+ * See https://android.googlesource.com/platform/bionic/+/master/libc/kernel/
+ * for more information.
+ */
+#define RISCV_HWPROBE_VENDOR_EXT_XSFVQMACCDOD (1 << 0)
+#define RISCV_HWPROBE_VENDOR_EXT_XSFVQMACCQOQ (1 << 1)
+#define RISCV_HWPROBE_VENDOR_EXT_XSFVFNRCLIPXFQF (1 << 2)
+#define RISCV_HWPROBE_VENDOR_EXT_XSFVFWMACCQQQ (1 << 3)
diff --git a/libc/kernel/uapi/asm-riscv/asm/vendor/thead.h b/libc/kernel/uapi/asm-riscv/asm/vendor/thead.h
new file mode 100644
index 0000000..a1d9607
--- /dev/null
+++ b/libc/kernel/uapi/asm-riscv/asm/vendor/thead.h
@@ -0,0 +1,7 @@
+/*
+ * This file is auto-generated. Modifications will be lost.
+ *
+ * See https://android.googlesource.com/platform/bionic/+/master/libc/kernel/
+ * for more information.
+ */
+#define RISCV_HWPROBE_VENDOR_EXT_XTHEADVECTOR (1 << 0)
diff --git a/libc/kernel/uapi/asm-x86/asm/amd_hsmp.h b/libc/kernel/uapi/asm-x86/asm/amd_hsmp.h
index 0d630bf..d7a6919 100644
--- a/libc/kernel/uapi/asm-x86/asm/amd_hsmp.h
+++ b/libc/kernel/uapi/asm-x86/asm/amd_hsmp.h
@@ -47,6 +47,12 @@
   HSMP_GET_METRIC_TABLE_VER,
   HSMP_GET_METRIC_TABLE,
   HSMP_GET_METRIC_TABLE_DRAM_ADDR,
+  HSMP_SET_XGMI_PSTATE_RANGE,
+  HSMP_CPU_RAIL_ISO_FREQ_POLICY,
+  HSMP_DFC_ENABLE_CTRL,
+  HSMP_GET_RAPL_UNITS = 0x30,
+  HSMP_GET_RAPL_CORE_COUNTER,
+  HSMP_GET_RAPL_PACKAGE_COUNTER,
   HSMP_MSG_ID_MAX,
 };
 struct hsmp_message {
@@ -60,136 +66,21 @@
   HSMP_RSVD = - 1,
   HSMP_SET = 0,
   HSMP_GET = 1,
+  HSMP_SET_GET = 2,
 };
 enum hsmp_proto_versions {
   HSMP_PROTO_VER2 = 2,
   HSMP_PROTO_VER3,
   HSMP_PROTO_VER4,
   HSMP_PROTO_VER5,
-  HSMP_PROTO_VER6
+  HSMP_PROTO_VER6,
+  HSMP_PROTO_VER7
 };
 struct hsmp_msg_desc {
   int num_args;
   int response_sz;
   enum hsmp_msg_type type;
 };
-static const struct hsmp_msg_desc hsmp_msg_desc_table[] = {
- {
-    0, 0, HSMP_RSVD
-  }
- , {
-    1, 1, HSMP_GET
-  }
- , {
-    0, 1, HSMP_GET
-  }
- , {
-    0, 1, HSMP_GET
-  }
- , {
-    0, 1, HSMP_GET
-  }
- , {
-    1, 0, HSMP_SET
-  }
- , {
-    0, 1, HSMP_GET
-  }
- , {
-    0, 1, HSMP_GET
-  }
- , {
-    1, 0, HSMP_SET
-  }
- , {
-    1, 0, HSMP_SET
-  }
- , {
-    1, 1, HSMP_GET
-  }
- , {
-    0, 1, HSMP_GET
-  }
- , {
-    1, 0, HSMP_SET
-  }
- , {
-    1, 0, HSMP_SET
-  }
- , {
-    0, 0, HSMP_SET
-  }
- , {
-    0, 2, HSMP_GET
-  }
- , {
-    0, 1, HSMP_GET
-  }
- , {
-    0, 1, HSMP_GET
-  }
- , {
-    1, 0, HSMP_SET
-  }
- , {
-    1, 1, HSMP_GET
-  }
- , {
-    0, 1, HSMP_GET
-  }
- , {
-    0, 1, HSMP_GET
-  }
- , {
-    1, 1, HSMP_GET
-  }
- , {
-    1, 1, HSMP_GET
-  }
- , {
-    1, 1, HSMP_GET
-  }
- , {
-    0, 1, HSMP_GET
-  }
- , {
-    1, 1, HSMP_GET
-  }
- , {
-    0, 1, HSMP_GET
-  }
- , {
-    0, 1, HSMP_GET
-  }
- , {
-    1, 1, HSMP_GET
-  }
- , {
-    1, 1, HSMP_GET
-  }
- , {
-    1, 0, HSMP_SET
-  }
- , {
-    1, 1, HSMP_SET
-  }
- , {
-    1, 0, HSMP_SET
-  }
- , {
-    1, 0, HSMP_SET
-  }
- , {
-    0, 1, HSMP_GET
-  }
- , {
-    0, 0, HSMP_GET
-  }
- , {
-    0, 2, HSMP_GET
-  }
- ,
-};
 struct hsmp_metric_table {
   __u32 accumulation_counter;
   __u32 max_socket_temperature;
diff --git a/libc/kernel/uapi/asm-x86/asm/bootparam.h b/libc/kernel/uapi/asm-x86/asm/bootparam.h
index 6a4b59c..663ac46 100644
--- a/libc/kernel/uapi/asm-x86/asm/bootparam.h
+++ b/libc/kernel/uapi/asm-x86/asm/bootparam.h
@@ -23,7 +23,7 @@
 #define XLF_5LEVEL (1 << 5)
 #define XLF_5LEVEL_ENABLED (1 << 6)
 #define XLF_MEM_ENCRYPTION (1 << 7)
-#ifndef __ASSEMBLY__
+#ifndef __ASSEMBLER__
 #include <linux/types.h>
 #include <linux/screen_info.h>
 #include <linux/apm_bios.h>
diff --git a/libc/kernel/uapi/asm-x86/asm/e820.h b/libc/kernel/uapi/asm-x86/asm/e820.h
index ed1d1a1..b836bb0 100644
--- a/libc/kernel/uapi/asm-x86/asm/e820.h
+++ b/libc/kernel/uapi/asm-x86/asm/e820.h
@@ -18,7 +18,7 @@
 #define E820_PMEM 7
 #define E820_PRAM 12
 #define E820_RESERVED_KERN 128
-#ifndef __ASSEMBLY__
+#ifndef __ASSEMBLER__
 #include <linux/types.h>
 struct e820entry {
   __u64 addr;
diff --git a/libc/kernel/uapi/asm-x86/asm/kvm.h b/libc/kernel/uapi/asm-x86/asm/kvm.h
index 0a35412..2f649b0 100644
--- a/libc/kernel/uapi/asm-x86/asm/kvm.h
+++ b/libc/kernel/uapi/asm-x86/asm/kvm.h
@@ -343,6 +343,8 @@
 #define KVM_X86_QUIRK_FIX_HYPERCALL_INSN (1 << 5)
 #define KVM_X86_QUIRK_MWAIT_NEVER_UD_FAULTS (1 << 6)
 #define KVM_X86_QUIRK_SLOT_ZAP_ALL (1 << 7)
+#define KVM_X86_QUIRK_STUFF_FEATURE_MSRS (1 << 8)
+#define KVM_X86_QUIRK_IGNORE_GUEST_PAT (1 << 9)
 #define KVM_STATE_NESTED_FORMAT_VMX 0
 #define KVM_STATE_NESTED_FORMAT_SVM 1
 #define KVM_STATE_NESTED_GUEST_MODE 0x00000001
@@ -423,6 +425,8 @@
 #define KVM_XEN_HVM_CONFIG_RUNSTATE_UPDATE_FLAG (1 << 6)
 #define KVM_XEN_HVM_CONFIG_PVCLOCK_TSC_UNSTABLE (1 << 7)
 #define KVM_XEN_HVM_CONFIG_SHARED_INFO_HVA (1 << 8)
+#define KVM_XEN_MSR_MIN_INDEX 0x40000000u
+#define KVM_XEN_MSR_MAX_INDEX 0x4fffffffu
 struct kvm_xen_hvm_config {
   __u32 flags;
   __u32 msr;
@@ -656,6 +660,7 @@
   __u8 pad0[6];
   __u64 pad1[4];
 };
+#define KVM_SEV_PAGE_TYPE_INVALID 0x0
 #define KVM_SEV_SNP_PAGE_TYPE_NORMAL 0x1
 #define KVM_SEV_SNP_PAGE_TYPE_ZERO 0x3
 #define KVM_SEV_SNP_PAGE_TYPE_UNMEASURED 0x4
@@ -709,4 +714,45 @@
 #define KVM_X86_SEV_VM 2
 #define KVM_X86_SEV_ES_VM 3
 #define KVM_X86_SNP_VM 4
+#define KVM_X86_TDX_VM 5
+enum kvm_tdx_cmd_id {
+  KVM_TDX_CAPABILITIES = 0,
+  KVM_TDX_INIT_VM,
+  KVM_TDX_INIT_VCPU,
+  KVM_TDX_INIT_MEM_REGION,
+  KVM_TDX_FINALIZE_VM,
+  KVM_TDX_GET_CPUID,
+  KVM_TDX_CMD_NR_MAX,
+};
+struct kvm_tdx_cmd {
+  __u32 id;
+  __u32 flags;
+  __u64 data;
+  __u64 hw_error;
+};
+struct kvm_tdx_capabilities {
+  __u64 supported_attrs;
+  __u64 supported_xfam;
+  __u64 kernel_tdvmcallinfo_1_r11;
+  __u64 user_tdvmcallinfo_1_r11;
+  __u64 kernel_tdvmcallinfo_1_r12;
+  __u64 user_tdvmcallinfo_1_r12;
+  __u64 reserved[250];
+  struct kvm_cpuid2 cpuid;
+};
+struct kvm_tdx_init_vm {
+  __u64 attributes;
+  __u64 xfam;
+  __u64 mrconfigid[6];
+  __u64 mrowner[6];
+  __u64 mrownerconfig[6];
+  __u64 reserved[12];
+  struct kvm_cpuid2 cpuid;
+};
+#define KVM_TDX_MEASURE_MEMORY_REGION _BITULL(0)
+struct kvm_tdx_init_mem_region {
+  __u64 source_addr;
+  __u64 gpa;
+  __u64 nr_pages;
+};
 #endif
diff --git a/libc/kernel/uapi/asm-x86/asm/ldt.h b/libc/kernel/uapi/asm-x86/asm/ldt.h
index 9c22a0b..226ab74 100644
--- a/libc/kernel/uapi/asm-x86/asm/ldt.h
+++ b/libc/kernel/uapi/asm-x86/asm/ldt.h
@@ -8,7 +8,7 @@
 #define _ASM_X86_LDT_H
 #define LDT_ENTRIES 8192
 #define LDT_ENTRY_SIZE 8
-#ifndef __ASSEMBLY__
+#ifndef __ASSEMBLER__
 struct user_desc {
   unsigned int entry_number;
   unsigned int base_addr;
diff --git a/libc/kernel/uapi/asm-x86/asm/mman.h b/libc/kernel/uapi/asm-x86/asm/mman.h
index 90269d6..5574009 100644
--- a/libc/kernel/uapi/asm-x86/asm/mman.h
+++ b/libc/kernel/uapi/asm-x86/asm/mman.h
@@ -8,6 +8,5 @@
 #define _ASM_X86_MMAN_H
 #define MAP_32BIT 0x40
 #define MAP_ABOVE4G 0x80
-#define SHADOW_STACK_SET_TOKEN (1ULL << 0)
 #include <asm-generic/mman.h>
 #endif
diff --git a/libc/kernel/uapi/asm-x86/asm/msr.h b/libc/kernel/uapi/asm-x86/asm/msr.h
index 34b7bd8..80466eb 100644
--- a/libc/kernel/uapi/asm-x86/asm/msr.h
+++ b/libc/kernel/uapi/asm-x86/asm/msr.h
@@ -6,7 +6,7 @@
  */
 #ifndef _UAPI_ASM_X86_MSR_H
 #define _UAPI_ASM_X86_MSR_H
-#ifndef __ASSEMBLY__
+#ifndef __ASSEMBLER__
 #include <linux/types.h>
 #include <linux/ioctl.h>
 #define X86_IOC_RDMSR_REGS _IOWR('c', 0xA0, __u32[8])
diff --git a/libc/kernel/uapi/asm-x86/asm/ptrace-abi.h b/libc/kernel/uapi/asm-x86/asm/ptrace-abi.h
index aa314e0..ec14525 100644
--- a/libc/kernel/uapi/asm-x86/asm/ptrace-abi.h
+++ b/libc/kernel/uapi/asm-x86/asm/ptrace-abi.h
@@ -26,7 +26,7 @@
 #define SS 16
 #define FRAME_SIZE 17
 #else
-#if defined(__ASSEMBLY__) || defined(__FRAME_OFFSETS)
+#if defined(__ASSEMBLER__) || defined(__FRAME_OFFSETS)
 #define R15 0
 #define R14 8
 #define R13 16
@@ -66,7 +66,7 @@
 #define PTRACE_SYSEMU 31
 #define PTRACE_SYSEMU_SINGLESTEP 32
 #define PTRACE_SINGLEBLOCK 33
-#ifndef __ASSEMBLY__
+#ifndef __ASSEMBLER__
 #include <linux/types.h>
 #endif
 #endif
diff --git a/libc/kernel/uapi/asm-x86/asm/ptrace.h b/libc/kernel/uapi/asm-x86/asm/ptrace.h
index a791592..66ae903 100644
--- a/libc/kernel/uapi/asm-x86/asm/ptrace.h
+++ b/libc/kernel/uapi/asm-x86/asm/ptrace.h
@@ -9,7 +9,7 @@
 #include <linux/compiler.h>
 #include <asm/ptrace-abi.h>
 #include <asm/processor-flags.h>
-#ifndef __ASSEMBLY__
+#ifndef __ASSEMBLER__
 #ifdef __i386__
 struct pt_regs {
   long ebx;
diff --git a/libc/kernel/uapi/asm-x86/asm/setup_data.h b/libc/kernel/uapi/asm-x86/asm/setup_data.h
index d00a554..0f51952 100644
--- a/libc/kernel/uapi/asm-x86/asm/setup_data.h
+++ b/libc/kernel/uapi/asm-x86/asm/setup_data.h
@@ -16,10 +16,11 @@
 #define SETUP_CC_BLOB 7
 #define SETUP_IMA 8
 #define SETUP_RNG_SEED 9
-#define SETUP_ENUM_MAX SETUP_RNG_SEED
+#define SETUP_KEXEC_KHO 10
+#define SETUP_ENUM_MAX SETUP_KEXEC_KHO
 #define SETUP_INDIRECT (1 << 31)
 #define SETUP_TYPE_MAX (SETUP_ENUM_MAX | SETUP_INDIRECT)
-#ifndef __ASSEMBLY__
+#ifndef __ASSEMBLER__
 #include <linux/types.h>
 struct setup_data {
   __u64 next;
@@ -60,5 +61,11 @@
   __u64 addr;
   __u64 size;
 } __attribute__((packed));
+struct kho_data {
+  __u64 fdt_addr;
+  __u64 fdt_size;
+  __u64 scratch_addr;
+  __u64 scratch_size;
+} __attribute__((packed));
 #endif
 #endif
diff --git a/libc/kernel/uapi/asm-x86/asm/signal.h b/libc/kernel/uapi/asm-x86/asm/signal.h
index 6cffef3..0b99732 100644
--- a/libc/kernel/uapi/asm-x86/asm/signal.h
+++ b/libc/kernel/uapi/asm-x86/asm/signal.h
@@ -6,7 +6,7 @@
  */
 #ifndef _UAPI_ASM_X86_SIGNAL_H
 #define _UAPI_ASM_X86_SIGNAL_H
-#ifndef __ASSEMBLY__
+#ifndef __ASSEMBLER__
 #include <linux/types.h>
 #include <linux/compiler.h>
 struct siginfo;
@@ -53,7 +53,7 @@
 #define MINSIGSTKSZ 2048
 #define SIGSTKSZ 8192
 #include <asm-generic/signal-defs.h>
-#ifndef __ASSEMBLY__
+#ifndef __ASSEMBLER__
 #ifdef __i386__
 struct __kernel_sigaction {
   union {
diff --git a/libc/kernel/uapi/asm-x86/asm/svm.h b/libc/kernel/uapi/asm-x86/asm/svm.h
index 4f165fa..7c45066 100644
--- a/libc/kernel/uapi/asm-x86/asm/svm.h
+++ b/libc/kernel/uapi/asm-x86/asm/svm.h
@@ -99,6 +99,8 @@
 #define SVM_EXIT_CR14_WRITE_TRAP 0x09e
 #define SVM_EXIT_CR15_WRITE_TRAP 0x09f
 #define SVM_EXIT_INVPCID 0x0a2
+#define SVM_EXIT_BUS_LOCK 0x0a5
+#define SVM_EXIT_IDLE_HLT 0x0a6
 #define SVM_EXIT_NPF 0x400
 #define SVM_EXIT_AVIC_INCOMPLETE_IPI 0x401
 #define SVM_EXIT_AVIC_UNACCELERATED_ACCESS 0x402
@@ -124,5 +126,5 @@
 #define SVM_VMGEXIT_UNSUPPORTED_EVENT 0x8000ffff
 #define SVM_EXIT_SW 0xf0000000
 #define SVM_EXIT_ERR - 1
-#define SVM_EXIT_REASONS { SVM_EXIT_READ_CR0, "read_cr0" }, { SVM_EXIT_READ_CR2, "read_cr2" }, { SVM_EXIT_READ_CR3, "read_cr3" }, { SVM_EXIT_READ_CR4, "read_cr4" }, { SVM_EXIT_READ_CR8, "read_cr8" }, { SVM_EXIT_WRITE_CR0, "write_cr0" }, { SVM_EXIT_WRITE_CR2, "write_cr2" }, { SVM_EXIT_WRITE_CR3, "write_cr3" }, { SVM_EXIT_WRITE_CR4, "write_cr4" }, { SVM_EXIT_WRITE_CR8, "write_cr8" }, { SVM_EXIT_READ_DR0, "read_dr0" }, { SVM_EXIT_READ_DR1, "read_dr1" }, { SVM_EXIT_READ_DR2, "read_dr2" }, { SVM_EXIT_READ_DR3, "read_dr3" }, { SVM_EXIT_READ_DR4, "read_dr4" }, { SVM_EXIT_READ_DR5, "read_dr5" }, { SVM_EXIT_READ_DR6, "read_dr6" }, { SVM_EXIT_READ_DR7, "read_dr7" }, { SVM_EXIT_WRITE_DR0, "write_dr0" }, { SVM_EXIT_WRITE_DR1, "write_dr1" }, { SVM_EXIT_WRITE_DR2, "write_dr2" }, { SVM_EXIT_WRITE_DR3, "write_dr3" }, { SVM_EXIT_WRITE_DR4, "write_dr4" }, { SVM_EXIT_WRITE_DR5, "write_dr5" }, { SVM_EXIT_WRITE_DR6, "write_dr6" }, { SVM_EXIT_WRITE_DR7, "write_dr7" }, { SVM_EXIT_EXCP_BASE + DE_VECTOR, "DE excp" }, { SVM_EXIT_EXCP_BASE + DB_VECTOR, "DB excp" }, { SVM_EXIT_EXCP_BASE + BP_VECTOR, "BP excp" }, { SVM_EXIT_EXCP_BASE + OF_VECTOR, "OF excp" }, { SVM_EXIT_EXCP_BASE + BR_VECTOR, "BR excp" }, { SVM_EXIT_EXCP_BASE + UD_VECTOR, "UD excp" }, { SVM_EXIT_EXCP_BASE + NM_VECTOR, "NM excp" }, { SVM_EXIT_EXCP_BASE + DF_VECTOR, "DF excp" }, { SVM_EXIT_EXCP_BASE + TS_VECTOR, "TS excp" }, { SVM_EXIT_EXCP_BASE + NP_VECTOR, "NP excp" }, { SVM_EXIT_EXCP_BASE + SS_VECTOR, "SS excp" }, { SVM_EXIT_EXCP_BASE + GP_VECTOR, "GP excp" }, { SVM_EXIT_EXCP_BASE + PF_VECTOR, "PF excp" }, { SVM_EXIT_EXCP_BASE + MF_VECTOR, "MF excp" }, { SVM_EXIT_EXCP_BASE + AC_VECTOR, "AC excp" }, { SVM_EXIT_EXCP_BASE + MC_VECTOR, "MC excp" }, { SVM_EXIT_EXCP_BASE + XM_VECTOR, "XF excp" }, { SVM_EXIT_INTR, "interrupt" }, { SVM_EXIT_NMI, "nmi" }, { SVM_EXIT_SMI, "smi" }, { SVM_EXIT_INIT, "init" }, { SVM_EXIT_VINTR, "vintr" }, { SVM_EXIT_CR0_SEL_WRITE, "cr0_sel_write" }, { SVM_EXIT_IDTR_READ, "read_idtr" }, { SVM_EXIT_GDTR_READ, "read_gdtr" }, { SVM_EXIT_LDTR_READ, "read_ldtr" }, { SVM_EXIT_TR_READ, "read_rt" }, { SVM_EXIT_IDTR_WRITE, "write_idtr" }, { SVM_EXIT_GDTR_WRITE, "write_gdtr" }, { SVM_EXIT_LDTR_WRITE, "write_ldtr" }, { SVM_EXIT_TR_WRITE, "write_rt" }, { SVM_EXIT_RDTSC, "rdtsc" }, { SVM_EXIT_RDPMC, "rdpmc" }, { SVM_EXIT_PUSHF, "pushf" }, { SVM_EXIT_POPF, "popf" }, { SVM_EXIT_CPUID, "cpuid" }, { SVM_EXIT_RSM, "rsm" }, { SVM_EXIT_IRET, "iret" }, { SVM_EXIT_SWINT, "swint" }, { SVM_EXIT_INVD, "invd" }, { SVM_EXIT_PAUSE, "pause" }, { SVM_EXIT_HLT, "hlt" }, { SVM_EXIT_INVLPG, "invlpg" }, { SVM_EXIT_INVLPGA, "invlpga" }, { SVM_EXIT_IOIO, "io" }, { SVM_EXIT_MSR, "msr" }, { SVM_EXIT_TASK_SWITCH, "task_switch" }, { SVM_EXIT_FERR_FREEZE, "ferr_freeze" }, { SVM_EXIT_SHUTDOWN, "shutdown" }, { SVM_EXIT_VMRUN, "vmrun" }, { SVM_EXIT_VMMCALL, "hypercall" }, { SVM_EXIT_VMLOAD, "vmload" }, { SVM_EXIT_VMSAVE, "vmsave" }, { SVM_EXIT_STGI, "stgi" }, { SVM_EXIT_CLGI, "clgi" }, { SVM_EXIT_SKINIT, "skinit" }, { SVM_EXIT_RDTSCP, "rdtscp" }, { SVM_EXIT_ICEBP, "icebp" }, { SVM_EXIT_WBINVD, "wbinvd" }, { SVM_EXIT_MONITOR, "monitor" }, { SVM_EXIT_MWAIT, "mwait" }, { SVM_EXIT_XSETBV, "xsetbv" }, { SVM_EXIT_EFER_WRITE_TRAP, "write_efer_trap" }, { SVM_EXIT_CR0_WRITE_TRAP, "write_cr0_trap" }, { SVM_EXIT_CR4_WRITE_TRAP, "write_cr4_trap" }, { SVM_EXIT_CR8_WRITE_TRAP, "write_cr8_trap" }, { SVM_EXIT_INVPCID, "invpcid" }, { SVM_EXIT_NPF, "npf" }, { SVM_EXIT_AVIC_INCOMPLETE_IPI, "avic_incomplete_ipi" }, { SVM_EXIT_AVIC_UNACCELERATED_ACCESS, "avic_unaccelerated_access" }, { SVM_EXIT_VMGEXIT, "vmgexit" }, { SVM_VMGEXIT_MMIO_READ, "vmgexit_mmio_read" }, { SVM_VMGEXIT_MMIO_WRITE, "vmgexit_mmio_write" }, { SVM_VMGEXIT_NMI_COMPLETE, "vmgexit_nmi_complete" }, { SVM_VMGEXIT_AP_HLT_LOOP, "vmgexit_ap_hlt_loop" }, { SVM_VMGEXIT_AP_JUMP_TABLE, "vmgexit_ap_jump_table" }, { SVM_VMGEXIT_PSC, "vmgexit_page_state_change" }, { SVM_VMGEXIT_GUEST_REQUEST, "vmgexit_guest_request" }, { SVM_VMGEXIT_EXT_GUEST_REQUEST, "vmgexit_ext_guest_request" }, { SVM_VMGEXIT_AP_CREATION, "vmgexit_ap_creation" }, { SVM_VMGEXIT_HV_FEATURES, "vmgexit_hypervisor_feature" }, { SVM_EXIT_ERR, "invalid_guest_state" }
+#define SVM_EXIT_REASONS { SVM_EXIT_READ_CR0, "read_cr0" }, { SVM_EXIT_READ_CR2, "read_cr2" }, { SVM_EXIT_READ_CR3, "read_cr3" }, { SVM_EXIT_READ_CR4, "read_cr4" }, { SVM_EXIT_READ_CR8, "read_cr8" }, { SVM_EXIT_WRITE_CR0, "write_cr0" }, { SVM_EXIT_WRITE_CR2, "write_cr2" }, { SVM_EXIT_WRITE_CR3, "write_cr3" }, { SVM_EXIT_WRITE_CR4, "write_cr4" }, { SVM_EXIT_WRITE_CR8, "write_cr8" }, { SVM_EXIT_READ_DR0, "read_dr0" }, { SVM_EXIT_READ_DR1, "read_dr1" }, { SVM_EXIT_READ_DR2, "read_dr2" }, { SVM_EXIT_READ_DR3, "read_dr3" }, { SVM_EXIT_READ_DR4, "read_dr4" }, { SVM_EXIT_READ_DR5, "read_dr5" }, { SVM_EXIT_READ_DR6, "read_dr6" }, { SVM_EXIT_READ_DR7, "read_dr7" }, { SVM_EXIT_WRITE_DR0, "write_dr0" }, { SVM_EXIT_WRITE_DR1, "write_dr1" }, { SVM_EXIT_WRITE_DR2, "write_dr2" }, { SVM_EXIT_WRITE_DR3, "write_dr3" }, { SVM_EXIT_WRITE_DR4, "write_dr4" }, { SVM_EXIT_WRITE_DR5, "write_dr5" }, { SVM_EXIT_WRITE_DR6, "write_dr6" }, { SVM_EXIT_WRITE_DR7, "write_dr7" }, { SVM_EXIT_EXCP_BASE + DE_VECTOR, "DE excp" }, { SVM_EXIT_EXCP_BASE + DB_VECTOR, "DB excp" }, { SVM_EXIT_EXCP_BASE + BP_VECTOR, "BP excp" }, { SVM_EXIT_EXCP_BASE + OF_VECTOR, "OF excp" }, { SVM_EXIT_EXCP_BASE + BR_VECTOR, "BR excp" }, { SVM_EXIT_EXCP_BASE + UD_VECTOR, "UD excp" }, { SVM_EXIT_EXCP_BASE + NM_VECTOR, "NM excp" }, { SVM_EXIT_EXCP_BASE + DF_VECTOR, "DF excp" }, { SVM_EXIT_EXCP_BASE + TS_VECTOR, "TS excp" }, { SVM_EXIT_EXCP_BASE + NP_VECTOR, "NP excp" }, { SVM_EXIT_EXCP_BASE + SS_VECTOR, "SS excp" }, { SVM_EXIT_EXCP_BASE + GP_VECTOR, "GP excp" }, { SVM_EXIT_EXCP_BASE + PF_VECTOR, "PF excp" }, { SVM_EXIT_EXCP_BASE + MF_VECTOR, "MF excp" }, { SVM_EXIT_EXCP_BASE + AC_VECTOR, "AC excp" }, { SVM_EXIT_EXCP_BASE + MC_VECTOR, "MC excp" }, { SVM_EXIT_EXCP_BASE + XM_VECTOR, "XF excp" }, { SVM_EXIT_INTR, "interrupt" }, { SVM_EXIT_NMI, "nmi" }, { SVM_EXIT_SMI, "smi" }, { SVM_EXIT_INIT, "init" }, { SVM_EXIT_VINTR, "vintr" }, { SVM_EXIT_CR0_SEL_WRITE, "cr0_sel_write" }, { SVM_EXIT_IDTR_READ, "read_idtr" }, { SVM_EXIT_GDTR_READ, "read_gdtr" }, { SVM_EXIT_LDTR_READ, "read_ldtr" }, { SVM_EXIT_TR_READ, "read_rt" }, { SVM_EXIT_IDTR_WRITE, "write_idtr" }, { SVM_EXIT_GDTR_WRITE, "write_gdtr" }, { SVM_EXIT_LDTR_WRITE, "write_ldtr" }, { SVM_EXIT_TR_WRITE, "write_rt" }, { SVM_EXIT_RDTSC, "rdtsc" }, { SVM_EXIT_RDPMC, "rdpmc" }, { SVM_EXIT_PUSHF, "pushf" }, { SVM_EXIT_POPF, "popf" }, { SVM_EXIT_CPUID, "cpuid" }, { SVM_EXIT_RSM, "rsm" }, { SVM_EXIT_IRET, "iret" }, { SVM_EXIT_SWINT, "swint" }, { SVM_EXIT_INVD, "invd" }, { SVM_EXIT_PAUSE, "pause" }, { SVM_EXIT_HLT, "hlt" }, { SVM_EXIT_INVLPG, "invlpg" }, { SVM_EXIT_INVLPGA, "invlpga" }, { SVM_EXIT_IOIO, "io" }, { SVM_EXIT_MSR, "msr" }, { SVM_EXIT_TASK_SWITCH, "task_switch" }, { SVM_EXIT_FERR_FREEZE, "ferr_freeze" }, { SVM_EXIT_SHUTDOWN, "shutdown" }, { SVM_EXIT_VMRUN, "vmrun" }, { SVM_EXIT_VMMCALL, "hypercall" }, { SVM_EXIT_VMLOAD, "vmload" }, { SVM_EXIT_VMSAVE, "vmsave" }, { SVM_EXIT_STGI, "stgi" }, { SVM_EXIT_CLGI, "clgi" }, { SVM_EXIT_SKINIT, "skinit" }, { SVM_EXIT_RDTSCP, "rdtscp" }, { SVM_EXIT_ICEBP, "icebp" }, { SVM_EXIT_WBINVD, "wbinvd" }, { SVM_EXIT_MONITOR, "monitor" }, { SVM_EXIT_MWAIT, "mwait" }, { SVM_EXIT_XSETBV, "xsetbv" }, { SVM_EXIT_EFER_WRITE_TRAP, "write_efer_trap" }, { SVM_EXIT_CR0_WRITE_TRAP, "write_cr0_trap" }, { SVM_EXIT_CR4_WRITE_TRAP, "write_cr4_trap" }, { SVM_EXIT_CR8_WRITE_TRAP, "write_cr8_trap" }, { SVM_EXIT_INVPCID, "invpcid" }, { SVM_EXIT_BUS_LOCK, "buslock" }, { SVM_EXIT_IDLE_HLT, "idle-halt" }, { SVM_EXIT_NPF, "npf" }, { SVM_EXIT_AVIC_INCOMPLETE_IPI, "avic_incomplete_ipi" }, { SVM_EXIT_AVIC_UNACCELERATED_ACCESS, "avic_unaccelerated_access" }, { SVM_EXIT_VMGEXIT, "vmgexit" }, { SVM_VMGEXIT_MMIO_READ, "vmgexit_mmio_read" }, { SVM_VMGEXIT_MMIO_WRITE, "vmgexit_mmio_write" }, { SVM_VMGEXIT_NMI_COMPLETE, "vmgexit_nmi_complete" }, { SVM_VMGEXIT_AP_HLT_LOOP, "vmgexit_ap_hlt_loop" }, { SVM_VMGEXIT_AP_JUMP_TABLE, "vmgexit_ap_jump_table" }, { SVM_VMGEXIT_PSC, "vmgexit_page_state_change" }, { SVM_VMGEXIT_GUEST_REQUEST, "vmgexit_guest_request" }, { SVM_VMGEXIT_EXT_GUEST_REQUEST, "vmgexit_ext_guest_request" }, { SVM_VMGEXIT_AP_CREATION, "vmgexit_ap_creation" }, { SVM_VMGEXIT_HV_FEATURES, "vmgexit_hypervisor_feature" }, { SVM_EXIT_ERR, "invalid_guest_state" }
 #endif
diff --git a/libc/kernel/uapi/asm-x86/asm/unistd_32.h b/libc/kernel/uapi/asm-x86/asm/unistd_32.h
index 59c693d..4813a94 100644
--- a/libc/kernel/uapi/asm-x86/asm/unistd_32.h
+++ b/libc/kernel/uapi/asm-x86/asm/unistd_32.h
@@ -458,4 +458,9 @@
 #define __NR_lsm_set_self_attr 460
 #define __NR_lsm_list_modules 461
 #define __NR_mseal 462
+#define __NR_setxattrat 463
+#define __NR_getxattrat 464
+#define __NR_listxattrat 465
+#define __NR_removexattrat 466
+#define __NR_open_tree_attr 467
 #endif
diff --git a/libc/kernel/uapi/asm-x86/asm/unistd_64.h b/libc/kernel/uapi/asm-x86/asm/unistd_64.h
index d5408a3..f2fe75b 100644
--- a/libc/kernel/uapi/asm-x86/asm/unistd_64.h
+++ b/libc/kernel/uapi/asm-x86/asm/unistd_64.h
@@ -381,4 +381,9 @@
 #define __NR_lsm_set_self_attr 460
 #define __NR_lsm_list_modules 461
 #define __NR_mseal 462
+#define __NR_setxattrat 463
+#define __NR_getxattrat 464
+#define __NR_listxattrat 465
+#define __NR_removexattrat 466
+#define __NR_open_tree_attr 467
 #endif
diff --git a/libc/kernel/uapi/asm-x86/asm/unistd_x32.h b/libc/kernel/uapi/asm-x86/asm/unistd_x32.h
index fdcf7e6..8a5ff8d 100644
--- a/libc/kernel/uapi/asm-x86/asm/unistd_x32.h
+++ b/libc/kernel/uapi/asm-x86/asm/unistd_x32.h
@@ -334,6 +334,11 @@
 #define __NR_lsm_set_self_attr (__X32_SYSCALL_BIT + 460)
 #define __NR_lsm_list_modules (__X32_SYSCALL_BIT + 461)
 #define __NR_mseal (__X32_SYSCALL_BIT + 462)
+#define __NR_setxattrat (__X32_SYSCALL_BIT + 463)
+#define __NR_getxattrat (__X32_SYSCALL_BIT + 464)
+#define __NR_listxattrat (__X32_SYSCALL_BIT + 465)
+#define __NR_removexattrat (__X32_SYSCALL_BIT + 466)
+#define __NR_open_tree_attr (__X32_SYSCALL_BIT + 467)
 #define __NR_rt_sigaction (__X32_SYSCALL_BIT + 512)
 #define __NR_rt_sigreturn (__X32_SYSCALL_BIT + 513)
 #define __NR_ioctl (__X32_SYSCALL_BIT + 514)
diff --git a/libc/kernel/uapi/asm-x86/asm/vmx.h b/libc/kernel/uapi/asm-x86/asm/vmx.h
index 206a32b..c021387 100644
--- a/libc/kernel/uapi/asm-x86/asm/vmx.h
+++ b/libc/kernel/uapi/asm-x86/asm/vmx.h
@@ -13,6 +13,7 @@
 #define EXIT_REASON_TRIPLE_FAULT 2
 #define EXIT_REASON_INIT_SIGNAL 3
 #define EXIT_REASON_SIPI_SIGNAL 4
+#define EXIT_REASON_OTHER_SMI 6
 #define EXIT_REASON_INTERRUPT_WINDOW 7
 #define EXIT_REASON_NMI_WINDOW 8
 #define EXIT_REASON_TASK_SWITCH 9
@@ -70,7 +71,8 @@
 #define EXIT_REASON_TPAUSE 68
 #define EXIT_REASON_BUS_LOCK 74
 #define EXIT_REASON_NOTIFY 75
-#define VMX_EXIT_REASONS { EXIT_REASON_EXCEPTION_NMI, "EXCEPTION_NMI" }, { EXIT_REASON_EXTERNAL_INTERRUPT, "EXTERNAL_INTERRUPT" }, { EXIT_REASON_TRIPLE_FAULT, "TRIPLE_FAULT" }, { EXIT_REASON_INIT_SIGNAL, "INIT_SIGNAL" }, { EXIT_REASON_SIPI_SIGNAL, "SIPI_SIGNAL" }, { EXIT_REASON_INTERRUPT_WINDOW, "INTERRUPT_WINDOW" }, { EXIT_REASON_NMI_WINDOW, "NMI_WINDOW" }, { EXIT_REASON_TASK_SWITCH, "TASK_SWITCH" }, { EXIT_REASON_CPUID, "CPUID" }, { EXIT_REASON_HLT, "HLT" }, { EXIT_REASON_INVD, "INVD" }, { EXIT_REASON_INVLPG, "INVLPG" }, { EXIT_REASON_RDPMC, "RDPMC" }, { EXIT_REASON_RDTSC, "RDTSC" }, { EXIT_REASON_VMCALL, "VMCALL" }, { EXIT_REASON_VMCLEAR, "VMCLEAR" }, { EXIT_REASON_VMLAUNCH, "VMLAUNCH" }, { EXIT_REASON_VMPTRLD, "VMPTRLD" }, { EXIT_REASON_VMPTRST, "VMPTRST" }, { EXIT_REASON_VMREAD, "VMREAD" }, { EXIT_REASON_VMRESUME, "VMRESUME" }, { EXIT_REASON_VMWRITE, "VMWRITE" }, { EXIT_REASON_VMOFF, "VMOFF" }, { EXIT_REASON_VMON, "VMON" }, { EXIT_REASON_CR_ACCESS, "CR_ACCESS" }, { EXIT_REASON_DR_ACCESS, "DR_ACCESS" }, { EXIT_REASON_IO_INSTRUCTION, "IO_INSTRUCTION" }, { EXIT_REASON_MSR_READ, "MSR_READ" }, { EXIT_REASON_MSR_WRITE, "MSR_WRITE" }, { EXIT_REASON_INVALID_STATE, "INVALID_STATE" }, { EXIT_REASON_MSR_LOAD_FAIL, "MSR_LOAD_FAIL" }, { EXIT_REASON_MWAIT_INSTRUCTION, "MWAIT_INSTRUCTION" }, { EXIT_REASON_MONITOR_TRAP_FLAG, "MONITOR_TRAP_FLAG" }, { EXIT_REASON_MONITOR_INSTRUCTION, "MONITOR_INSTRUCTION" }, { EXIT_REASON_PAUSE_INSTRUCTION, "PAUSE_INSTRUCTION" }, { EXIT_REASON_MCE_DURING_VMENTRY, "MCE_DURING_VMENTRY" }, { EXIT_REASON_TPR_BELOW_THRESHOLD, "TPR_BELOW_THRESHOLD" }, { EXIT_REASON_APIC_ACCESS, "APIC_ACCESS" }, { EXIT_REASON_EOI_INDUCED, "EOI_INDUCED" }, { EXIT_REASON_GDTR_IDTR, "GDTR_IDTR" }, { EXIT_REASON_LDTR_TR, "LDTR_TR" }, { EXIT_REASON_EPT_VIOLATION, "EPT_VIOLATION" }, { EXIT_REASON_EPT_MISCONFIG, "EPT_MISCONFIG" }, { EXIT_REASON_INVEPT, "INVEPT" }, { EXIT_REASON_RDTSCP, "RDTSCP" }, { EXIT_REASON_PREEMPTION_TIMER, "PREEMPTION_TIMER" }, { EXIT_REASON_INVVPID, "INVVPID" }, { EXIT_REASON_WBINVD, "WBINVD" }, { EXIT_REASON_XSETBV, "XSETBV" }, { EXIT_REASON_APIC_WRITE, "APIC_WRITE" }, { EXIT_REASON_RDRAND, "RDRAND" }, { EXIT_REASON_INVPCID, "INVPCID" }, { EXIT_REASON_VMFUNC, "VMFUNC" }, { EXIT_REASON_ENCLS, "ENCLS" }, { EXIT_REASON_RDSEED, "RDSEED" }, { EXIT_REASON_PML_FULL, "PML_FULL" }, { EXIT_REASON_XSAVES, "XSAVES" }, { EXIT_REASON_XRSTORS, "XRSTORS" }, { EXIT_REASON_UMWAIT, "UMWAIT" }, { EXIT_REASON_TPAUSE, "TPAUSE" }, { EXIT_REASON_BUS_LOCK, "BUS_LOCK" }, { EXIT_REASON_NOTIFY, "NOTIFY" }
+#define EXIT_REASON_TDCALL 77
+#define VMX_EXIT_REASONS { EXIT_REASON_EXCEPTION_NMI, "EXCEPTION_NMI" }, { EXIT_REASON_EXTERNAL_INTERRUPT, "EXTERNAL_INTERRUPT" }, { EXIT_REASON_TRIPLE_FAULT, "TRIPLE_FAULT" }, { EXIT_REASON_INIT_SIGNAL, "INIT_SIGNAL" }, { EXIT_REASON_SIPI_SIGNAL, "SIPI_SIGNAL" }, { EXIT_REASON_INTERRUPT_WINDOW, "INTERRUPT_WINDOW" }, { EXIT_REASON_NMI_WINDOW, "NMI_WINDOW" }, { EXIT_REASON_TASK_SWITCH, "TASK_SWITCH" }, { EXIT_REASON_CPUID, "CPUID" }, { EXIT_REASON_HLT, "HLT" }, { EXIT_REASON_INVD, "INVD" }, { EXIT_REASON_INVLPG, "INVLPG" }, { EXIT_REASON_RDPMC, "RDPMC" }, { EXIT_REASON_RDTSC, "RDTSC" }, { EXIT_REASON_VMCALL, "VMCALL" }, { EXIT_REASON_VMCLEAR, "VMCLEAR" }, { EXIT_REASON_VMLAUNCH, "VMLAUNCH" }, { EXIT_REASON_VMPTRLD, "VMPTRLD" }, { EXIT_REASON_VMPTRST, "VMPTRST" }, { EXIT_REASON_VMREAD, "VMREAD" }, { EXIT_REASON_VMRESUME, "VMRESUME" }, { EXIT_REASON_VMWRITE, "VMWRITE" }, { EXIT_REASON_VMOFF, "VMOFF" }, { EXIT_REASON_VMON, "VMON" }, { EXIT_REASON_CR_ACCESS, "CR_ACCESS" }, { EXIT_REASON_DR_ACCESS, "DR_ACCESS" }, { EXIT_REASON_IO_INSTRUCTION, "IO_INSTRUCTION" }, { EXIT_REASON_MSR_READ, "MSR_READ" }, { EXIT_REASON_MSR_WRITE, "MSR_WRITE" }, { EXIT_REASON_INVALID_STATE, "INVALID_STATE" }, { EXIT_REASON_MSR_LOAD_FAIL, "MSR_LOAD_FAIL" }, { EXIT_REASON_MWAIT_INSTRUCTION, "MWAIT_INSTRUCTION" }, { EXIT_REASON_MONITOR_TRAP_FLAG, "MONITOR_TRAP_FLAG" }, { EXIT_REASON_MONITOR_INSTRUCTION, "MONITOR_INSTRUCTION" }, { EXIT_REASON_PAUSE_INSTRUCTION, "PAUSE_INSTRUCTION" }, { EXIT_REASON_MCE_DURING_VMENTRY, "MCE_DURING_VMENTRY" }, { EXIT_REASON_TPR_BELOW_THRESHOLD, "TPR_BELOW_THRESHOLD" }, { EXIT_REASON_APIC_ACCESS, "APIC_ACCESS" }, { EXIT_REASON_EOI_INDUCED, "EOI_INDUCED" }, { EXIT_REASON_GDTR_IDTR, "GDTR_IDTR" }, { EXIT_REASON_LDTR_TR, "LDTR_TR" }, { EXIT_REASON_EPT_VIOLATION, "EPT_VIOLATION" }, { EXIT_REASON_EPT_MISCONFIG, "EPT_MISCONFIG" }, { EXIT_REASON_INVEPT, "INVEPT" }, { EXIT_REASON_RDTSCP, "RDTSCP" }, { EXIT_REASON_PREEMPTION_TIMER, "PREEMPTION_TIMER" }, { EXIT_REASON_INVVPID, "INVVPID" }, { EXIT_REASON_WBINVD, "WBINVD" }, { EXIT_REASON_XSETBV, "XSETBV" }, { EXIT_REASON_APIC_WRITE, "APIC_WRITE" }, { EXIT_REASON_RDRAND, "RDRAND" }, { EXIT_REASON_INVPCID, "INVPCID" }, { EXIT_REASON_VMFUNC, "VMFUNC" }, { EXIT_REASON_ENCLS, "ENCLS" }, { EXIT_REASON_RDSEED, "RDSEED" }, { EXIT_REASON_PML_FULL, "PML_FULL" }, { EXIT_REASON_XSAVES, "XSAVES" }, { EXIT_REASON_XRSTORS, "XRSTORS" }, { EXIT_REASON_UMWAIT, "UMWAIT" }, { EXIT_REASON_TPAUSE, "TPAUSE" }, { EXIT_REASON_BUS_LOCK, "BUS_LOCK" }, { EXIT_REASON_NOTIFY, "NOTIFY" }, { EXIT_REASON_TDCALL, "TDCALL" }
 #define VMX_EXIT_REASON_FLAGS { VMX_EXIT_REASONS_FAILED_VMENTRY, "FAILED_VMENTRY" }
 #define VMX_ABORT_SAVE_GUEST_MSR_FAIL 1
 #define VMX_ABORT_LOAD_HOST_PDPTE_FAIL 2
diff --git a/libc/kernel/uapi/cxl/features.h b/libc/kernel/uapi/cxl/features.h
new file mode 100644
index 0000000..8a5e701
--- /dev/null
+++ b/libc/kernel/uapi/cxl/features.h
@@ -0,0 +1,81 @@
+/*
+ * This file is auto-generated. Modifications will be lost.
+ *
+ * See https://android.googlesource.com/platform/bionic/+/master/libc/kernel/
+ * for more information.
+ */
+#ifndef _UAPI_CXL_FEATURES_H_
+#define _UAPI_CXL_FEATURES_H_
+#include <linux/types.h>
+typedef unsigned char __uapi_uuid_t[16];
+struct cxl_mbox_get_sup_feats_in {
+  __le32 count;
+  __le16 start_idx;
+  __u8 reserved[2];
+} __attribute__((__packed__));
+#define CXL_CMD_CONFIG_CHANGE_COLD_RESET BIT(0)
+#define CXL_CMD_CONFIG_CHANGE_IMMEDIATE BIT(1)
+#define CXL_CMD_DATA_CHANGE_IMMEDIATE BIT(2)
+#define CXL_CMD_POLICY_CHANGE_IMMEDIATE BIT(3)
+#define CXL_CMD_LOG_CHANGE_IMMEDIATE BIT(4)
+#define CXL_CMD_SECURITY_STATE_CHANGE BIT(5)
+#define CXL_CMD_BACKGROUND BIT(6)
+#define CXL_CMD_BGCMD_ABORT_SUPPORTED BIT(7)
+#define CXL_CMD_EFFECTS_VALID BIT(9)
+#define CXL_CMD_CONFIG_CHANGE_CONV_RESET BIT(10)
+#define CXL_CMD_CONFIG_CHANGE_CXL_RESET BIT(11)
+#define CXL_CMD_EFFECTS_RESERVED GENMASK(15, 12)
+struct cxl_feat_entry {
+  __uapi_uuid_t uuid;
+  __le16 id;
+  __le16 get_feat_size;
+  __le16 set_feat_size;
+  __le32 flags;
+  __u8 get_feat_ver;
+  __u8 set_feat_ver;
+  __le16 effects;
+  __u8 reserved[18];
+} __attribute__((__packed__));
+#define CXL_FEATURE_F_CHANGEABLE BIT(0)
+#define CXL_FEATURE_F_PERSIST_FW_UPDATE BIT(4)
+#define CXL_FEATURE_F_DEFAULT_SEL BIT(5)
+#define CXL_FEATURE_F_SAVED_SEL BIT(6)
+struct cxl_mbox_get_sup_feats_out {
+  __struct_group(cxl_mbox_get_sup_feats_out_hdr, hdr,, __le16 num_entries;
+  __le16 supported_feats;
+  __u8 reserved[4];
+ );
+  struct cxl_feat_entry ents[] __counted_by_le(num_entries);
+} __attribute__((__packed__));
+struct cxl_mbox_get_feat_in {
+  __uapi_uuid_t uuid;
+  __le16 offset;
+  __le16 count;
+  __u8 selection;
+} __attribute__((__packed__));
+enum cxl_get_feat_selection {
+  CXL_GET_FEAT_SEL_CURRENT_VALUE,
+  CXL_GET_FEAT_SEL_DEFAULT_VALUE,
+  CXL_GET_FEAT_SEL_SAVED_VALUE,
+  CXL_GET_FEAT_SEL_MAX
+};
+struct cxl_mbox_set_feat_in {
+  __struct_group(cxl_mbox_set_feat_hdr, hdr,, __uapi_uuid_t uuid;
+  __le32 flags;
+  __le16 offset;
+  __u8 version;
+  __u8 rsvd[9];
+ );
+  __u8 feat_data[];
+} __attribute__((__packed__));
+enum cxl_set_feat_flag_data_transfer {
+  CXL_SET_FEAT_FLAG_FULL_DATA_TRANSFER = 0,
+  CXL_SET_FEAT_FLAG_INITIATE_DATA_TRANSFER,
+  CXL_SET_FEAT_FLAG_CONTINUE_DATA_TRANSFER,
+  CXL_SET_FEAT_FLAG_FINISH_DATA_TRANSFER,
+  CXL_SET_FEAT_FLAG_ABORT_DATA_TRANSFER,
+  CXL_SET_FEAT_FLAG_DATA_TRANSFER_MAX
+};
+#define CXL_SET_FEAT_FLAG_DATA_TRANSFER_MASK GENMASK(2, 0)
+#define CXL_SET_FEAT_FLAG_DATA_SAVED_ACROSS_RESET BIT(3)
+#endif
diff --git a/libc/kernel/uapi/drm/amdgpu_drm.h b/libc/kernel/uapi/drm/amdgpu_drm.h
index 7bbd5de..5369be6 100644
--- a/libc/kernel/uapi/drm/amdgpu_drm.h
+++ b/libc/kernel/uapi/drm/amdgpu_drm.h
@@ -26,6 +26,9 @@
 #define DRM_AMDGPU_VM 0x13
 #define DRM_AMDGPU_FENCE_TO_HANDLE 0x14
 #define DRM_AMDGPU_SCHED 0x15
+#define DRM_AMDGPU_USERQ 0x16
+#define DRM_AMDGPU_USERQ_SIGNAL 0x17
+#define DRM_AMDGPU_USERQ_WAIT 0x18
 #define DRM_IOCTL_AMDGPU_GEM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_CREATE, union drm_amdgpu_gem_create)
 #define DRM_IOCTL_AMDGPU_GEM_MMAP DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_MMAP, union drm_amdgpu_gem_mmap)
 #define DRM_IOCTL_AMDGPU_CTX DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_CTX, union drm_amdgpu_ctx)
@@ -42,6 +45,9 @@
 #define DRM_IOCTL_AMDGPU_VM DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_VM, union drm_amdgpu_vm)
 #define DRM_IOCTL_AMDGPU_FENCE_TO_HANDLE DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_FENCE_TO_HANDLE, union drm_amdgpu_fence_to_handle)
 #define DRM_IOCTL_AMDGPU_SCHED DRM_IOW(DRM_COMMAND_BASE + DRM_AMDGPU_SCHED, union drm_amdgpu_sched)
+#define DRM_IOCTL_AMDGPU_USERQ DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ, union drm_amdgpu_userq)
+#define DRM_IOCTL_AMDGPU_USERQ_SIGNAL DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ_SIGNAL, struct drm_amdgpu_userq_signal)
+#define DRM_IOCTL_AMDGPU_USERQ_WAIT DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ_WAIT, struct drm_amdgpu_userq_wait)
 #define AMDGPU_GEM_DOMAIN_CPU 0x1
 #define AMDGPU_GEM_DOMAIN_GTT 0x2
 #define AMDGPU_GEM_DOMAIN_VRAM 0x4
@@ -155,6 +161,76 @@
   struct drm_amdgpu_ctx_in in;
   union drm_amdgpu_ctx_out out;
 };
+#define AMDGPU_USERQ_OP_CREATE 1
+#define AMDGPU_USERQ_OP_FREE 2
+#define AMDGPU_USERQ_CREATE_FLAGS_QUEUE_PRIORITY_MASK 0x3
+#define AMDGPU_USERQ_CREATE_FLAGS_QUEUE_PRIORITY_SHIFT 0
+#define AMDGPU_USERQ_CREATE_FLAGS_QUEUE_PRIORITY_NORMAL_LOW 0
+#define AMDGPU_USERQ_CREATE_FLAGS_QUEUE_PRIORITY_LOW 1
+#define AMDGPU_USERQ_CREATE_FLAGS_QUEUE_PRIORITY_NORMAL_HIGH 2
+#define AMDGPU_USERQ_CREATE_FLAGS_QUEUE_PRIORITY_HIGH 3
+#define AMDGPU_USERQ_CREATE_FLAGS_QUEUE_SECURE (1 << 2)
+struct drm_amdgpu_userq_in {
+  __u32 op;
+  __u32 queue_id;
+  __u32 ip_type;
+  __u32 doorbell_handle;
+  __u32 doorbell_offset;
+  __u32 flags;
+  __u64 queue_va;
+  __u64 queue_size;
+  __u64 rptr_va;
+  __u64 wptr_va;
+  __u64 mqd;
+  __u64 mqd_size;
+};
+struct drm_amdgpu_userq_out {
+  __u32 queue_id;
+  __u32 _pad;
+};
+union drm_amdgpu_userq {
+  struct drm_amdgpu_userq_in in;
+  struct drm_amdgpu_userq_out out;
+};
+struct drm_amdgpu_userq_mqd_gfx11 {
+  __u64 shadow_va;
+  __u64 csa_va;
+};
+struct drm_amdgpu_userq_mqd_sdma_gfx11 {
+  __u64 csa_va;
+};
+struct drm_amdgpu_userq_mqd_compute_gfx11 {
+  __u64 eop_va;
+};
+struct drm_amdgpu_userq_signal {
+  __u32 queue_id;
+  __u32 pad;
+  __u64 syncobj_handles;
+  __u64 num_syncobj_handles;
+  __u64 bo_read_handles;
+  __u64 bo_write_handles;
+  __u32 num_bo_read_handles;
+  __u32 num_bo_write_handles;
+};
+struct drm_amdgpu_userq_fence_info {
+  __u64 va;
+  __u64 value;
+};
+struct drm_amdgpu_userq_wait {
+  __u32 waitq_id;
+  __u32 pad;
+  __u64 syncobj_handles;
+  __u64 syncobj_timeline_handles;
+  __u64 syncobj_timeline_points;
+  __u64 bo_read_handles;
+  __u64 bo_write_handles;
+  __u16 num_syncobj_timeline_handles;
+  __u16 num_fences;
+  __u32 num_syncobj_handles;
+  __u32 num_bo_read_handles;
+  __u32 num_bo_write_handles;
+  __u64 out_fences;
+};
 #define AMDGPU_VM_OP_RESERVE_VMID 1
 #define AMDGPU_VM_OP_UNRESERVE_VMID 2
 struct drm_amdgpu_vm_in {
@@ -225,6 +301,10 @@
 #define AMDGPU_TILING_GFX12_DCC_NUMBER_TYPE_MASK 0x7
 #define AMDGPU_TILING_GFX12_DCC_DATA_FORMAT_SHIFT 8
 #define AMDGPU_TILING_GFX12_DCC_DATA_FORMAT_MASK 0x3f
+#define AMDGPU_TILING_GFX12_DCC_WRITE_COMPRESS_DISABLE_SHIFT 14
+#define AMDGPU_TILING_GFX12_DCC_WRITE_COMPRESS_DISABLE_MASK 0x1
+#define AMDGPU_TILING_GFX12_SCANOUT_SHIFT 63
+#define AMDGPU_TILING_GFX12_SCANOUT_MASK 0x1
 #define AMDGPU_TILING_SET(field,value) (((__u64) (value) & AMDGPU_TILING_ ##field ##_MASK) << AMDGPU_TILING_ ##field ##_SHIFT)
 #define AMDGPU_TILING_GET(value,field) (((__u64) (value) >> AMDGPU_TILING_ ##field ##_SHIFT) & AMDGPU_TILING_ ##field ##_MASK)
 #define AMDGPU_GEM_METADATA_OP_SET_METADATA 1
@@ -331,6 +411,10 @@
   __u64 va_address;
   __u64 offset_in_bo;
   __u64 map_size;
+  __u64 vm_timeline_point;
+  __u32 vm_timeline_syncobj_out;
+  __u32 num_syncobj_handles;
+  __u64 input_fence_syncobj_handles;
 };
 #define AMDGPU_HW_IP_GFX 0
 #define AMDGPU_HW_IP_COMPUTE 1
@@ -438,6 +522,11 @@
 #define AMDGPU_IDS_FLAGS_PREEMPTION 0x2
 #define AMDGPU_IDS_FLAGS_TMZ 0x4
 #define AMDGPU_IDS_FLAGS_CONFORMANT_TRUNC_COORD 0x8
+#define AMDGPU_IDS_FLAGS_MODE_MASK 0x300
+#define AMDGPU_IDS_FLAGS_MODE_SHIFT 0x8
+#define AMDGPU_IDS_FLAGS_MODE_PF 0x0
+#define AMDGPU_IDS_FLAGS_MODE_VF 0x1
+#define AMDGPU_IDS_FLAGS_MODE_PT 0x2
 #define AMDGPU_INFO_ACCEL_WORKING 0x00
 #define AMDGPU_INFO_CRTC_FROM_ID 0x01
 #define AMDGPU_INFO_HW_IP_INFO 0x02
@@ -522,6 +611,7 @@
 #define AMDGPU_INFO_VIDEO_CAPS_ENCODE 1
 #define AMDGPU_INFO_MAX_IBS 0x22
 #define AMDGPU_INFO_GPUVM_FAULT 0x23
+#define AMDGPU_INFO_UQ_FW_AREAS 0x24
 #define AMDGPU_INFO_MMR_SE_INDEX_SHIFT 0
 #define AMDGPU_INFO_MMR_SE_INDEX_MASK 0xff
 #define AMDGPU_INFO_MMR_SH_INDEX_SHIFT 8
@@ -615,6 +705,7 @@
 #define AMDGPU_VRAM_TYPE_DDR5 10
 #define AMDGPU_VRAM_TYPE_LPDDR4 11
 #define AMDGPU_VRAM_TYPE_LPDDR5 12
+#define AMDGPU_VRAM_TYPE_HBM3E 13
 struct drm_amdgpu_info_device {
   __u32 device_id;
   __u32 chip_rev;
@@ -679,6 +770,8 @@
   __u32 shadow_alignment;
   __u32 csa_size;
   __u32 csa_alignment;
+  __u32 userq_ip_mask;
+  __u32 pad;
 };
 struct drm_amdgpu_info_hw_ip {
   __u32 hw_ip_version_major;
@@ -689,6 +782,17 @@
   __u32 available_rings;
   __u32 ip_discovery_version;
 };
+struct drm_amdgpu_info_uq_fw_areas_gfx {
+  __u32 shadow_size;
+  __u32 shadow_alignment;
+  __u32 csa_size;
+  __u32 csa_alignment;
+};
+struct drm_amdgpu_info_uq_fw_areas {
+  union {
+    struct drm_amdgpu_info_uq_fw_areas_gfx gfx;
+  };
+};
 struct drm_amdgpu_info_num_handles {
   __u32 uvd_max_handles;
   __u32 uvd_used_handles;
@@ -737,6 +841,17 @@
   __u32 status;
   __u32 vmhub;
 };
+struct drm_amdgpu_info_uq_metadata_gfx {
+  __u32 shadow_size;
+  __u32 shadow_alignment;
+  __u32 csa_size;
+  __u32 csa_alignment;
+};
+struct drm_amdgpu_info_uq_metadata {
+  union {
+    struct drm_amdgpu_info_uq_metadata_gfx gfx;
+  };
+};
 #define AMDGPU_FAMILY_UNKNOWN 0
 #define AMDGPU_FAMILY_SI 110
 #define AMDGPU_FAMILY_CI 120
diff --git a/libc/kernel/uapi/drm/amdxdna_accel.h b/libc/kernel/uapi/drm/amdxdna_accel.h
new file mode 100644
index 0000000..4f23e80
--- /dev/null
+++ b/libc/kernel/uapi/drm/amdxdna_accel.h
@@ -0,0 +1,248 @@
+/*
+ * This file is auto-generated. Modifications will be lost.
+ *
+ * See https://android.googlesource.com/platform/bionic/+/master/libc/kernel/
+ * for more information.
+ */
+#ifndef _UAPI_AMDXDNA_ACCEL_H_
+#define _UAPI_AMDXDNA_ACCEL_H_
+#include <linux/stddef.h>
+#include "drm.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+#define AMDXDNA_INVALID_CMD_HANDLE (~0UL)
+#define AMDXDNA_INVALID_ADDR (~0UL)
+#define AMDXDNA_INVALID_CTX_HANDLE 0
+#define AMDXDNA_INVALID_BO_HANDLE 0
+#define AMDXDNA_INVALID_FENCE_HANDLE 0
+enum amdxdna_device_type {
+  AMDXDNA_DEV_TYPE_UNKNOWN = - 1,
+  AMDXDNA_DEV_TYPE_KMQ,
+};
+enum amdxdna_drm_ioctl_id {
+  DRM_AMDXDNA_CREATE_HWCTX,
+  DRM_AMDXDNA_DESTROY_HWCTX,
+  DRM_AMDXDNA_CONFIG_HWCTX,
+  DRM_AMDXDNA_CREATE_BO,
+  DRM_AMDXDNA_GET_BO_INFO,
+  DRM_AMDXDNA_SYNC_BO,
+  DRM_AMDXDNA_EXEC_CMD,
+  DRM_AMDXDNA_GET_INFO,
+  DRM_AMDXDNA_SET_STATE,
+};
+struct amdxdna_qos_info {
+  __u32 gops;
+  __u32 fps;
+  __u32 dma_bandwidth;
+  __u32 latency;
+  __u32 frame_exec_time;
+  __u32 priority;
+};
+struct amdxdna_drm_create_hwctx {
+  __u64 ext;
+  __u64 ext_flags;
+  __u64 qos_p;
+  __u32 umq_bo;
+  __u32 log_buf_bo;
+  __u32 max_opc;
+  __u32 num_tiles;
+  __u32 mem_size;
+  __u32 umq_doorbell;
+  __u32 handle;
+  __u32 syncobj_handle;
+};
+struct amdxdna_drm_destroy_hwctx {
+  __u32 handle;
+  __u32 pad;
+};
+struct amdxdna_cu_config {
+  __u32 cu_bo;
+  __u8 cu_func;
+  __u8 pad[3];
+};
+struct amdxdna_hwctx_param_config_cu {
+  __u16 num_cus;
+  __u16 pad[3];
+  struct amdxdna_cu_config cu_configs[] __counted_by(num_cus);
+};
+enum amdxdna_drm_config_hwctx_param {
+  DRM_AMDXDNA_HWCTX_CONFIG_CU,
+  DRM_AMDXDNA_HWCTX_ASSIGN_DBG_BUF,
+  DRM_AMDXDNA_HWCTX_REMOVE_DBG_BUF,
+};
+struct amdxdna_drm_config_hwctx {
+  __u32 handle;
+  __u32 param_type;
+  __u64 param_val;
+  __u32 param_val_size;
+  __u32 pad;
+};
+enum amdxdna_bo_type {
+  AMDXDNA_BO_INVALID = 0,
+  AMDXDNA_BO_SHMEM,
+  AMDXDNA_BO_DEV_HEAP,
+  AMDXDNA_BO_DEV,
+  AMDXDNA_BO_CMD,
+};
+struct amdxdna_drm_create_bo {
+  __u64 flags;
+  __u64 vaddr;
+  __u64 size;
+  __u32 type;
+  __u32 handle;
+};
+struct amdxdna_drm_get_bo_info {
+  __u64 ext;
+  __u64 ext_flags;
+  __u32 handle;
+  __u32 pad;
+  __u64 map_offset;
+  __u64 vaddr;
+  __u64 xdna_addr;
+};
+struct amdxdna_drm_sync_bo {
+  __u32 handle;
+#define SYNC_DIRECT_TO_DEVICE 0U
+#define SYNC_DIRECT_FROM_DEVICE 1U
+  __u32 direction;
+  __u64 offset;
+  __u64 size;
+};
+enum amdxdna_cmd_type {
+  AMDXDNA_CMD_SUBMIT_EXEC_BUF = 0,
+  AMDXDNA_CMD_SUBMIT_DEPENDENCY,
+  AMDXDNA_CMD_SUBMIT_SIGNAL,
+};
+struct amdxdna_drm_exec_cmd {
+  __u64 ext;
+  __u64 ext_flags;
+  __u32 hwctx;
+  __u32 type;
+  __u64 cmd_handles;
+  __u64 args;
+  __u32 cmd_count;
+  __u32 arg_count;
+  __u64 seq;
+};
+struct amdxdna_drm_query_aie_status {
+  __u64 buffer;
+  __u32 buffer_size;
+  __u32 cols_filled;
+};
+struct amdxdna_drm_query_aie_version {
+  __u32 major;
+  __u32 minor;
+};
+struct amdxdna_drm_query_aie_tile_metadata {
+  __u16 row_count;
+  __u16 row_start;
+  __u16 dma_channel_count;
+  __u16 lock_count;
+  __u16 event_reg_count;
+  __u16 pad[3];
+};
+struct amdxdna_drm_query_aie_metadata {
+  __u32 col_size;
+  __u16 cols;
+  __u16 rows;
+  struct amdxdna_drm_query_aie_version version;
+  struct amdxdna_drm_query_aie_tile_metadata core;
+  struct amdxdna_drm_query_aie_tile_metadata mem;
+  struct amdxdna_drm_query_aie_tile_metadata shim;
+};
+struct amdxdna_drm_query_clock {
+  __u8 name[16];
+  __u32 freq_mhz;
+  __u32 pad;
+};
+struct amdxdna_drm_query_clock_metadata {
+  struct amdxdna_drm_query_clock mp_npu_clock;
+  struct amdxdna_drm_query_clock h_clock;
+};
+enum amdxdna_sensor_type {
+  AMDXDNA_SENSOR_TYPE_POWER
+};
+struct amdxdna_drm_query_sensor {
+  __u8 label[64];
+  __u32 input;
+  __u32 max;
+  __u32 average;
+  __u32 highest;
+  __u8 status[64];
+  __u8 units[16];
+  __s8 unitm;
+  __u8 type;
+  __u8 pad[6];
+};
+struct amdxdna_drm_query_hwctx {
+  __u32 context_id;
+  __u32 start_col;
+  __u32 num_col;
+  __u32 pad;
+  __s64 pid;
+  __u64 command_submissions;
+  __u64 command_completions;
+  __u64 migrations;
+  __u64 preemptions;
+  __u64 errors;
+};
+enum amdxdna_power_mode_type {
+  POWER_MODE_DEFAULT,
+  POWER_MODE_LOW,
+  POWER_MODE_MEDIUM,
+  POWER_MODE_HIGH,
+  POWER_MODE_TURBO,
+};
+struct amdxdna_drm_get_power_mode {
+  __u8 power_mode;
+  __u8 pad[7];
+};
+struct amdxdna_drm_query_firmware_version {
+  __u32 major;
+  __u32 minor;
+  __u32 patch;
+  __u32 build;
+};
+enum amdxdna_drm_get_param {
+  DRM_AMDXDNA_QUERY_AIE_STATUS,
+  DRM_AMDXDNA_QUERY_AIE_METADATA,
+  DRM_AMDXDNA_QUERY_AIE_VERSION,
+  DRM_AMDXDNA_QUERY_CLOCK_METADATA,
+  DRM_AMDXDNA_QUERY_SENSORS,
+  DRM_AMDXDNA_QUERY_HW_CONTEXTS,
+  DRM_AMDXDNA_QUERY_FIRMWARE_VERSION = 8,
+  DRM_AMDXDNA_GET_POWER_MODE,
+};
+struct amdxdna_drm_get_info {
+  __u32 param;
+  __u32 buffer_size;
+  __u64 buffer;
+};
+enum amdxdna_drm_set_param {
+  DRM_AMDXDNA_SET_POWER_MODE,
+  DRM_AMDXDNA_WRITE_AIE_MEM,
+  DRM_AMDXDNA_WRITE_AIE_REG,
+};
+struct amdxdna_drm_set_state {
+  __u32 param;
+  __u32 buffer_size;
+  __u64 buffer;
+};
+struct amdxdna_drm_set_power_mode {
+  __u8 power_mode;
+  __u8 pad[7];
+};
+#define DRM_IOCTL_AMDXDNA_CREATE_HWCTX DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDXDNA_CREATE_HWCTX, struct amdxdna_drm_create_hwctx)
+#define DRM_IOCTL_AMDXDNA_DESTROY_HWCTX DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDXDNA_DESTROY_HWCTX, struct amdxdna_drm_destroy_hwctx)
+#define DRM_IOCTL_AMDXDNA_CONFIG_HWCTX DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDXDNA_CONFIG_HWCTX, struct amdxdna_drm_config_hwctx)
+#define DRM_IOCTL_AMDXDNA_CREATE_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDXDNA_CREATE_BO, struct amdxdna_drm_create_bo)
+#define DRM_IOCTL_AMDXDNA_GET_BO_INFO DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDXDNA_GET_BO_INFO, struct amdxdna_drm_get_bo_info)
+#define DRM_IOCTL_AMDXDNA_SYNC_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDXDNA_SYNC_BO, struct amdxdna_drm_sync_bo)
+#define DRM_IOCTL_AMDXDNA_EXEC_CMD DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDXDNA_EXEC_CMD, struct amdxdna_drm_exec_cmd)
+#define DRM_IOCTL_AMDXDNA_GET_INFO DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDXDNA_GET_INFO, struct amdxdna_drm_get_info)
+#define DRM_IOCTL_AMDXDNA_SET_STATE DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDXDNA_SET_STATE, struct amdxdna_drm_set_state)
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/libc/kernel/uapi/drm/asahi_drm.h b/libc/kernel/uapi/drm/asahi_drm.h
new file mode 100644
index 0000000..3a8faca
--- /dev/null
+++ b/libc/kernel/uapi/drm/asahi_drm.h
@@ -0,0 +1,266 @@
+/*
+ * This file is auto-generated. Modifications will be lost.
+ *
+ * See https://android.googlesource.com/platform/bionic/+/master/libc/kernel/
+ * for more information.
+ */
+#ifndef _ASAHI_DRM_H_
+#define _ASAHI_DRM_H_
+#include "drm.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+enum drm_asahi_ioctl_id {
+  DRM_ASAHI_GET_PARAMS = 0,
+  DRM_ASAHI_GET_TIME,
+  DRM_ASAHI_VM_CREATE,
+  DRM_ASAHI_VM_DESTROY,
+  DRM_ASAHI_VM_BIND,
+  DRM_ASAHI_GEM_CREATE,
+  DRM_ASAHI_GEM_MMAP_OFFSET,
+  DRM_ASAHI_GEM_BIND_OBJECT,
+  DRM_ASAHI_QUEUE_CREATE,
+  DRM_ASAHI_QUEUE_DESTROY,
+  DRM_ASAHI_SUBMIT,
+};
+#define DRM_ASAHI_MAX_CLUSTERS 64
+struct drm_asahi_params_global {
+  __u64 features;
+  __u32 gpu_generation;
+  __u32 gpu_variant;
+  __u32 gpu_revision;
+  __u32 chip_id;
+  __u32 num_dies;
+  __u32 num_clusters_total;
+  __u32 num_cores_per_cluster;
+  __u32 max_frequency_khz;
+  __u64 core_masks[DRM_ASAHI_MAX_CLUSTERS];
+  __u64 vm_start;
+  __u64 vm_end;
+  __u64 vm_kernel_min_size;
+  __u32 max_commands_per_submission;
+  __u32 max_attachments;
+  __u64 command_timestamp_frequency_hz;
+};
+enum drm_asahi_feature {
+  DRM_ASAHI_FEATURE_SOFT_FAULTS = (1UL) << 0,
+};
+struct drm_asahi_get_params {
+  __u32 param_group;
+  __u32 pad;
+  __u64 pointer;
+  __u64 size;
+};
+struct drm_asahi_vm_create {
+  __u64 kernel_start;
+  __u64 kernel_end;
+  __u32 vm_id;
+  __u32 pad;
+};
+struct drm_asahi_vm_destroy {
+  __u32 vm_id;
+  __u32 pad;
+};
+enum drm_asahi_gem_flags {
+  DRM_ASAHI_GEM_WRITEBACK = (1L << 0),
+  DRM_ASAHI_GEM_VM_PRIVATE = (1L << 1),
+};
+struct drm_asahi_gem_create {
+  __u64 size;
+  __u32 flags;
+  __u32 vm_id;
+  __u32 handle;
+  __u32 pad;
+};
+struct drm_asahi_gem_mmap_offset {
+  __u32 handle;
+  __u32 flags;
+  __u64 offset;
+};
+enum drm_asahi_bind_flags {
+  DRM_ASAHI_BIND_UNBIND = (1L << 0),
+  DRM_ASAHI_BIND_READ = (1L << 1),
+  DRM_ASAHI_BIND_WRITE = (1L << 2),
+  DRM_ASAHI_BIND_SINGLE_PAGE = (1L << 3),
+};
+struct drm_asahi_gem_bind_op {
+  __u32 flags;
+  __u32 handle;
+  __u64 offset;
+  __u64 range;
+  __u64 addr;
+};
+struct drm_asahi_vm_bind {
+  __u32 vm_id;
+  __u32 num_binds;
+  __u32 stride;
+  __u32 pad;
+  __u64 userptr;
+};
+enum drm_asahi_bind_object_op {
+  DRM_ASAHI_BIND_OBJECT_OP_BIND = 0,
+  DRM_ASAHI_BIND_OBJECT_OP_UNBIND = 1,
+};
+enum drm_asahi_bind_object_flags {
+  DRM_ASAHI_BIND_OBJECT_USAGE_TIMESTAMPS = (1L << 0),
+};
+struct drm_asahi_gem_bind_object {
+  __u32 op;
+  __u32 flags;
+  __u32 handle;
+  __u32 vm_id;
+  __u64 offset;
+  __u64 range;
+  __u32 object_handle;
+  __u32 pad;
+};
+enum drm_asahi_cmd_type {
+  DRM_ASAHI_CMD_RENDER = 0,
+  DRM_ASAHI_CMD_COMPUTE = 1,
+  DRM_ASAHI_SET_VERTEX_ATTACHMENTS = 2,
+  DRM_ASAHI_SET_FRAGMENT_ATTACHMENTS = 3,
+  DRM_ASAHI_SET_COMPUTE_ATTACHMENTS = 4,
+};
+enum drm_asahi_priority {
+  DRM_ASAHI_PRIORITY_LOW = 0,
+  DRM_ASAHI_PRIORITY_MEDIUM = 1,
+  DRM_ASAHI_PRIORITY_HIGH = 2,
+  DRM_ASAHI_PRIORITY_REALTIME = 3,
+};
+struct drm_asahi_queue_create {
+  __u32 flags;
+  __u32 vm_id;
+  __u32 priority;
+  __u32 queue_id;
+  __u64 usc_exec_base;
+};
+struct drm_asahi_queue_destroy {
+  __u32 queue_id;
+  __u32 pad;
+};
+enum drm_asahi_sync_type {
+  DRM_ASAHI_SYNC_SYNCOBJ = 0,
+  DRM_ASAHI_SYNC_TIMELINE_SYNCOBJ = 1,
+};
+struct drm_asahi_sync {
+  __u32 sync_type;
+  __u32 handle;
+  __u64 timeline_value;
+};
+#define DRM_ASAHI_BARRIER_NONE (0xFFFFu)
+struct drm_asahi_cmd_header {
+  __u16 cmd_type;
+  __u16 size;
+  __u16 vdm_barrier;
+  __u16 cdm_barrier;
+};
+struct drm_asahi_submit {
+  __u64 syncs;
+  __u64 cmdbuf;
+  __u32 flags;
+  __u32 queue_id;
+  __u32 in_sync_count;
+  __u32 out_sync_count;
+  __u32 cmdbuf_size;
+  __u32 pad;
+};
+struct drm_asahi_attachment {
+  __u64 pointer;
+  __u64 size;
+  __u32 pad;
+  __u32 flags;
+};
+enum drm_asahi_render_flags {
+  DRM_ASAHI_RENDER_VERTEX_SCRATCH = (1U << 0),
+  DRM_ASAHI_RENDER_PROCESS_EMPTY_TILES = (1U << 1),
+  DRM_ASAHI_RENDER_NO_VERTEX_CLUSTERING = (1U << 2),
+  DRM_ASAHI_RENDER_DBIAS_IS_INT = (1U << 18),
+};
+struct drm_asahi_zls_buffer {
+  __u64 base;
+  __u64 comp_base;
+  __u32 stride;
+  __u32 comp_stride;
+};
+struct drm_asahi_timestamp {
+  __u32 handle;
+  __u32 offset;
+};
+struct drm_asahi_timestamps {
+  struct drm_asahi_timestamp start;
+  struct drm_asahi_timestamp end;
+};
+struct drm_asahi_helper_program {
+  __u32 binary;
+  __u32 cfg;
+  __u64 data;
+};
+struct drm_asahi_bg_eot {
+  __u32 usc;
+  __u32 rsrc_spec;
+};
+struct drm_asahi_cmd_render {
+  __u32 flags;
+  __u32 isp_zls_pixels;
+  __u64 vdm_ctrl_stream_base;
+  struct drm_asahi_helper_program vertex_helper;
+  struct drm_asahi_helper_program fragment_helper;
+  __u64 isp_scissor_base;
+  __u64 isp_dbias_base;
+  __u64 isp_oclqry_base;
+  struct drm_asahi_zls_buffer depth;
+  struct drm_asahi_zls_buffer stencil;
+  __u64 zls_ctrl;
+  __u64 ppp_multisamplectl;
+  __u64 sampler_heap;
+  __u32 ppp_ctrl;
+  __u16 width_px;
+  __u16 height_px;
+  __u16 layers;
+  __u16 sampler_count;
+  __u8 utile_width_px;
+  __u8 utile_height_px;
+  __u8 samples;
+  __u8 sample_size_B;
+  __u32 isp_merge_upper_x;
+  __u32 isp_merge_upper_y;
+  struct drm_asahi_bg_eot bg;
+  struct drm_asahi_bg_eot eot;
+  struct drm_asahi_bg_eot partial_bg;
+  struct drm_asahi_bg_eot partial_eot;
+  __u32 isp_bgobjdepth;
+  __u32 isp_bgobjvals;
+  struct drm_asahi_timestamps ts_vtx;
+  struct drm_asahi_timestamps ts_frag;
+};
+struct drm_asahi_cmd_compute {
+  __u32 flags;
+  __u32 sampler_count;
+  __u64 cdm_ctrl_stream_base;
+  __u64 cdm_ctrl_stream_end;
+  __u64 sampler_heap;
+  struct drm_asahi_helper_program helper;
+  struct drm_asahi_timestamps ts;
+};
+struct drm_asahi_get_time {
+  __u64 flags;
+  __u64 gpu_timestamp;
+};
+#define DRM_IOCTL_ASAHI(__access,__id,__type) DRM_IO ##__access(DRM_COMMAND_BASE + DRM_ASAHI_ ##__id, struct drm_asahi_ ##__type)
+enum {
+  DRM_IOCTL_ASAHI_GET_PARAMS = DRM_IOCTL_ASAHI(W, GET_PARAMS, get_params),
+  DRM_IOCTL_ASAHI_GET_TIME = DRM_IOCTL_ASAHI(WR, GET_TIME, get_time),
+  DRM_IOCTL_ASAHI_VM_CREATE = DRM_IOCTL_ASAHI(WR, VM_CREATE, vm_create),
+  DRM_IOCTL_ASAHI_VM_DESTROY = DRM_IOCTL_ASAHI(W, VM_DESTROY, vm_destroy),
+  DRM_IOCTL_ASAHI_VM_BIND = DRM_IOCTL_ASAHI(W, VM_BIND, vm_bind),
+  DRM_IOCTL_ASAHI_GEM_CREATE = DRM_IOCTL_ASAHI(WR, GEM_CREATE, gem_create),
+  DRM_IOCTL_ASAHI_GEM_MMAP_OFFSET = DRM_IOCTL_ASAHI(WR, GEM_MMAP_OFFSET, gem_mmap_offset),
+  DRM_IOCTL_ASAHI_GEM_BIND_OBJECT = DRM_IOCTL_ASAHI(WR, GEM_BIND_OBJECT, gem_bind_object),
+  DRM_IOCTL_ASAHI_QUEUE_CREATE = DRM_IOCTL_ASAHI(WR, QUEUE_CREATE, queue_create),
+  DRM_IOCTL_ASAHI_QUEUE_DESTROY = DRM_IOCTL_ASAHI(W, QUEUE_DESTROY, queue_destroy),
+  DRM_IOCTL_ASAHI_SUBMIT = DRM_IOCTL_ASAHI(W, SUBMIT, submit),
+};
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/libc/kernel/uapi/drm/drm.h b/libc/kernel/uapi/drm/drm.h
index c8fab3c..fbdedc5 100644
--- a/libc/kernel/uapi/drm/drm.h
+++ b/libc/kernel/uapi/drm/drm.h
@@ -385,12 +385,15 @@
   __u32 pad;
 };
 #define DRM_SYNCOBJ_FD_TO_HANDLE_FLAGS_IMPORT_SYNC_FILE (1 << 0)
+#define DRM_SYNCOBJ_FD_TO_HANDLE_FLAGS_TIMELINE (1 << 1)
 #define DRM_SYNCOBJ_HANDLE_TO_FD_FLAGS_EXPORT_SYNC_FILE (1 << 0)
+#define DRM_SYNCOBJ_HANDLE_TO_FD_FLAGS_TIMELINE (1 << 1)
 struct drm_syncobj_handle {
   __u32 handle;
   __u32 flags;
   __s32 fd;
   __u32 pad;
+  __u64 point;
 };
 struct drm_syncobj_transfer {
   __u32 src_handle;
@@ -456,6 +459,11 @@
   __u64 sequence;
   __u64 user_data;
 };
+#define DRM_CLIENT_NAME_MAX_LEN 64
+struct drm_set_client_name {
+  __u64 name_len;
+  __u64 name;
+};
 #ifdef __cplusplus
 }
 #endif
@@ -576,6 +584,7 @@
 #define DRM_IOCTL_MODE_GETFB2 DRM_IOWR(0xCE, struct drm_mode_fb_cmd2)
 #define DRM_IOCTL_SYNCOBJ_EVENTFD DRM_IOWR(0xCF, struct drm_syncobj_eventfd)
 #define DRM_IOCTL_MODE_CLOSEFB DRM_IOWR(0xD0, struct drm_mode_closefb)
+#define DRM_IOCTL_SET_CLIENT_NAME DRM_IOWR(0xD1, struct drm_set_client_name)
 #define DRM_COMMAND_BASE 0x40
 #define DRM_COMMAND_END 0xA0
 struct drm_event {
diff --git a/libc/kernel/uapi/drm/drm_fourcc.h b/libc/kernel/uapi/drm/drm_fourcc.h
index c0f5ff1..8f6bfa0 100644
--- a/libc/kernel/uapi/drm/drm_fourcc.h
+++ b/libc/kernel/uapi/drm/drm_fourcc.h
@@ -149,6 +149,8 @@
 #define DRM_FORMAT_MOD_VENDOR_ARM 0x08
 #define DRM_FORMAT_MOD_VENDOR_ALLWINNER 0x09
 #define DRM_FORMAT_MOD_VENDOR_AMLOGIC 0x0a
+#define DRM_FORMAT_MOD_VENDOR_MTK 0x0b
+#define DRM_FORMAT_MOD_VENDOR_APPLE 0x0c
 #define DRM_FORMAT_RESERVED ((1ULL << 56) - 1)
 #define fourcc_mod_get_vendor(modifier) (((modifier) >> 56) & 0xff)
 #define fourcc_mod_is_vendor(modifier,vendor) (fourcc_mod_get_vendor(modifier) == DRM_FORMAT_MOD_VENDOR_ ##vendor)
@@ -251,6 +253,20 @@
 #define AMLOGIC_FBC_LAYOUT_BASIC (1ULL)
 #define AMLOGIC_FBC_LAYOUT_SCATTER (2ULL)
 #define AMLOGIC_FBC_OPTION_MEM_SAVING (1ULL << 0)
+#define DRM_FORMAT_MOD_MTK(__flags) fourcc_mod_code(MTK, __flags)
+#define MTK_FMT_MOD_TILE_MASK 0xf
+#define MTK_FMT_MOD_TILE_NONE 0x0
+#define MTK_FMT_MOD_TILE_16L32S 0x1
+#define MTK_FMT_MOD_COMPRESS_MASK (0xf << 8)
+#define MTK_FMT_MOD_COMPRESS_NONE (0x0 << 8)
+#define MTK_FMT_MOD_COMPRESS_V1 (0x1 << 8)
+#define MTK_FMT_MOD_10BIT_LAYOUT_MASK (0xf << 16)
+#define MTK_FMT_MOD_10BIT_LAYOUT_PACKED (0x0 << 16)
+#define MTK_FMT_MOD_10BIT_LAYOUT_LSBTILED (0x1 << 16)
+#define MTK_FMT_MOD_10BIT_LAYOUT_LSBRASTER (0x2 << 16)
+#define DRM_FORMAT_MOD_MTK_16L_32S_TILE DRM_FORMAT_MOD_MTK(MTK_FMT_MOD_TILE_16L32S)
+#define DRM_FORMAT_MOD_APPLE_GPU_TILED fourcc_mod_code(APPLE, 1)
+#define DRM_FORMAT_MOD_APPLE_GPU_TILED_COMPRESSED fourcc_mod_code(APPLE, 2)
 #define AMD_FMT_MOD fourcc_mod_code(AMD, 0)
 #define IS_AMD_FMT_MOD(val) (((val) >> 56) == DRM_FORMAT_MOD_VENDOR_AMD)
 #define AMD_FMT_MOD_TILE_VER_GFX9 1
@@ -260,6 +276,7 @@
 #define AMD_FMT_MOD_TILE_VER_GFX12 5
 #define AMD_FMT_MOD_TILE_GFX9_64K_S 9
 #define AMD_FMT_MOD_TILE_GFX9_64K_D 10
+#define AMD_FMT_MOD_TILE_GFX9_4K_D_X 22
 #define AMD_FMT_MOD_TILE_GFX9_64K_S_X 25
 #define AMD_FMT_MOD_TILE_GFX9_64K_D_X 26
 #define AMD_FMT_MOD_TILE_GFX9_64K_R_X 27
diff --git a/libc/kernel/uapi/drm/ivpu_accel.h b/libc/kernel/uapi/drm/ivpu_accel.h
index 960bd43..f8dd3af 100644
--- a/libc/kernel/uapi/drm/ivpu_accel.h
+++ b/libc/kernel/uapi/drm/ivpu_accel.h
@@ -10,8 +10,6 @@
 #ifdef __cplusplus
 extern "C" {
 #endif
-#define DRM_IVPU_DRIVER_MAJOR 1
-#define DRM_IVPU_DRIVER_MINOR 0
 #define DRM_IVPU_GET_PARAM 0x00
 #define DRM_IVPU_SET_PARAM 0x01
 #define DRM_IVPU_BO_CREATE 0x02
@@ -22,6 +20,9 @@
 #define DRM_IVPU_METRIC_STREAMER_STOP 0x08
 #define DRM_IVPU_METRIC_STREAMER_GET_DATA 0x09
 #define DRM_IVPU_METRIC_STREAMER_GET_INFO 0x0a
+#define DRM_IVPU_CMDQ_CREATE 0x0b
+#define DRM_IVPU_CMDQ_DESTROY 0x0c
+#define DRM_IVPU_CMDQ_SUBMIT 0x0d
 #define DRM_IOCTL_IVPU_GET_PARAM DRM_IOWR(DRM_COMMAND_BASE + DRM_IVPU_GET_PARAM, struct drm_ivpu_param)
 #define DRM_IOCTL_IVPU_SET_PARAM DRM_IOW(DRM_COMMAND_BASE + DRM_IVPU_SET_PARAM, struct drm_ivpu_param)
 #define DRM_IOCTL_IVPU_BO_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_IVPU_BO_CREATE, struct drm_ivpu_bo_create)
@@ -32,6 +33,9 @@
 #define DRM_IOCTL_IVPU_METRIC_STREAMER_STOP DRM_IOW(DRM_COMMAND_BASE + DRM_IVPU_METRIC_STREAMER_STOP, struct drm_ivpu_metric_streamer_stop)
 #define DRM_IOCTL_IVPU_METRIC_STREAMER_GET_DATA DRM_IOWR(DRM_COMMAND_BASE + DRM_IVPU_METRIC_STREAMER_GET_DATA, struct drm_ivpu_metric_streamer_get_data)
 #define DRM_IOCTL_IVPU_METRIC_STREAMER_GET_INFO DRM_IOWR(DRM_COMMAND_BASE + DRM_IVPU_METRIC_STREAMER_GET_INFO, struct drm_ivpu_metric_streamer_get_data)
+#define DRM_IOCTL_IVPU_CMDQ_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_IVPU_CMDQ_CREATE, struct drm_ivpu_cmdq_create)
+#define DRM_IOCTL_IVPU_CMDQ_DESTROY DRM_IOW(DRM_COMMAND_BASE + DRM_IVPU_CMDQ_DESTROY, struct drm_ivpu_cmdq_destroy)
+#define DRM_IOCTL_IVPU_CMDQ_SUBMIT DRM_IOW(DRM_COMMAND_BASE + DRM_IVPU_CMDQ_SUBMIT, struct drm_ivpu_cmdq_submit)
 #define DRM_IVPU_PARAM_DEVICE_ID 0
 #define DRM_IVPU_PARAM_DEVICE_REVISION 1
 #define DRM_IVPU_PARAM_PLATFORM_TYPE 2
@@ -58,6 +62,7 @@
 #define DRM_IVPU_JOB_PRIORITY_REALTIME 4
 #define DRM_IVPU_CAP_METRIC_STREAMER 1
 #define DRM_IVPU_CAP_DMA_MEMORY_RANGE 2
+#define DRM_IVPU_CAP_MANAGE_CMDQ 3
 struct drm_ivpu_param {
   __u32 param;
   __u32 index;
@@ -95,6 +100,13 @@
   __u32 commands_offset;
   __u32 priority;
 };
+struct drm_ivpu_cmdq_submit {
+  __u64 buffers_ptr;
+  __u32 buffer_count;
+  __u32 cmdq_id;
+  __u32 flags;
+  __u32 commands_offset;
+};
 #define DRM_IVPU_JOB_STATUS_SUCCESS 0
 #define DRM_IVPU_JOB_STATUS_ABORTED 256
 struct drm_ivpu_bo_wait {
@@ -117,6 +129,13 @@
   __u64 buffer_size;
   __u64 data_size;
 };
+struct drm_ivpu_cmdq_create {
+  __u32 cmdq_id;
+  __u32 priority;
+};
+struct drm_ivpu_cmdq_destroy {
+  __u32 cmdq_id;
+};
 struct drm_ivpu_metric_streamer_stop {
   __u64 metric_group_mask;
 };
diff --git a/libc/kernel/uapi/drm/msm_drm.h b/libc/kernel/uapi/drm/msm_drm.h
index 582da62..e8b790f 100644
--- a/libc/kernel/uapi/drm/msm_drm.h
+++ b/libc/kernel/uapi/drm/msm_drm.h
@@ -40,6 +40,7 @@
 #define MSM_PARAM_RAYTRACING 0x11
 #define MSM_PARAM_UBWC_SWIZZLE 0x12
 #define MSM_PARAM_MACROTILE_MODE 0x13
+#define MSM_PARAM_UCHE_TRAP_BASE 0x14
 #define MSM_PARAM_NR_RINGS MSM_PARAM_PRIORITIES
 struct drm_msm_param {
   __u32 pipe;
@@ -169,7 +170,8 @@
   __u32 madv;
   __u32 retained;
 };
-#define MSM_SUBMITQUEUE_FLAGS (0)
+#define MSM_SUBMITQUEUE_ALLOW_PREEMPT 0x00000001
+#define MSM_SUBMITQUEUE_FLAGS (MSM_SUBMITQUEUE_ALLOW_PREEMPT | 0)
 struct drm_msm_submitqueue {
   __u32 flags;
   __u32 prio;
diff --git a/libc/kernel/uapi/drm/nova_drm.h b/libc/kernel/uapi/drm/nova_drm.h
new file mode 100644
index 0000000..668e50a
--- /dev/null
+++ b/libc/kernel/uapi/drm/nova_drm.h
@@ -0,0 +1,39 @@
+/*
+ * This file is auto-generated. Modifications will be lost.
+ *
+ * See https://android.googlesource.com/platform/bionic/+/master/libc/kernel/
+ * for more information.
+ */
+#ifndef __NOVA_DRM_H__
+#define __NOVA_DRM_H__
+#include "drm.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+#define NOVA_GETPARAM_VRAM_BAR_SIZE 0x1
+struct drm_nova_getparam {
+  __u64 param;
+  __u64 value;
+};
+struct drm_nova_gem_create {
+  __u32 handle;
+  __u32 pad;
+  __u64 size;
+};
+struct drm_nova_gem_info {
+  __u32 handle;
+  __u32 pad;
+  __u64 size;
+};
+#define DRM_NOVA_GETPARAM 0x00
+#define DRM_NOVA_GEM_CREATE 0x01
+#define DRM_NOVA_GEM_INFO 0x02
+enum {
+  DRM_IOCTL_NOVA_GETPARAM = DRM_IOWR(DRM_COMMAND_BASE + DRM_NOVA_GETPARAM, struct drm_nova_getparam),
+  DRM_IOCTL_NOVA_GEM_CREATE = DRM_IOWR(DRM_COMMAND_BASE + DRM_NOVA_GEM_CREATE, struct drm_nova_gem_create),
+  DRM_IOCTL_NOVA_GEM_INFO = DRM_IOWR(DRM_COMMAND_BASE + DRM_NOVA_GEM_INFO, struct drm_nova_gem_info),
+};
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/libc/kernel/uapi/drm/panfrost_drm.h b/libc/kernel/uapi/drm/panfrost_drm.h
index 66a46fc..bb55fd3 100644
--- a/libc/kernel/uapi/drm/panfrost_drm.h
+++ b/libc/kernel/uapi/drm/panfrost_drm.h
@@ -29,6 +29,7 @@
 #define DRM_IOCTL_PANFROST_PERFCNT_ENABLE DRM_IOW(DRM_COMMAND_BASE + DRM_PANFROST_PERFCNT_ENABLE, struct drm_panfrost_perfcnt_enable)
 #define DRM_IOCTL_PANFROST_PERFCNT_DUMP DRM_IOW(DRM_COMMAND_BASE + DRM_PANFROST_PERFCNT_DUMP, struct drm_panfrost_perfcnt_dump)
 #define PANFROST_JD_REQ_FS (1 << 0)
+#define PANFROST_JD_REQ_CYCLE_COUNT (1 << 1)
 struct drm_panfrost_submit {
   __u64 jc;
   __u64 in_syncs;
@@ -99,6 +100,8 @@
   DRM_PANFROST_PARAM_NR_CORE_GROUPS,
   DRM_PANFROST_PARAM_THREAD_TLS_ALLOC,
   DRM_PANFROST_PARAM_AFBC_FEATURES,
+  DRM_PANFROST_PARAM_SYSTEM_TIMESTAMP,
+  DRM_PANFROST_PARAM_SYSTEM_TIMESTAMP_FREQUENCY,
 };
 struct drm_panfrost_get_param {
   __u32 param;
diff --git a/libc/kernel/uapi/drm/panthor_drm.h b/libc/kernel/uapi/drm/panthor_drm.h
index b45c1dc..840b7ee 100644
--- a/libc/kernel/uapi/drm/panthor_drm.h
+++ b/libc/kernel/uapi/drm/panthor_drm.h
@@ -28,21 +28,8 @@
   DRM_PANTHOR_GROUP_GET_STATE,
   DRM_PANTHOR_TILER_HEAP_CREATE,
   DRM_PANTHOR_TILER_HEAP_DESTROY,
+  DRM_PANTHOR_BO_SET_LABEL,
 };
-#define DRM_IOCTL_PANTHOR(__access,__id,__type) DRM_IO ##__access(DRM_COMMAND_BASE + DRM_PANTHOR_ ##__id, struct drm_panthor_ ##__type)
-#define DRM_IOCTL_PANTHOR_DEV_QUERY DRM_IOCTL_PANTHOR(WR, DEV_QUERY, dev_query)
-#define DRM_IOCTL_PANTHOR_VM_CREATE DRM_IOCTL_PANTHOR(WR, VM_CREATE, vm_create)
-#define DRM_IOCTL_PANTHOR_VM_DESTROY DRM_IOCTL_PANTHOR(WR, VM_DESTROY, vm_destroy)
-#define DRM_IOCTL_PANTHOR_VM_BIND DRM_IOCTL_PANTHOR(WR, VM_BIND, vm_bind)
-#define DRM_IOCTL_PANTHOR_VM_GET_STATE DRM_IOCTL_PANTHOR(WR, VM_GET_STATE, vm_get_state)
-#define DRM_IOCTL_PANTHOR_BO_CREATE DRM_IOCTL_PANTHOR(WR, BO_CREATE, bo_create)
-#define DRM_IOCTL_PANTHOR_BO_MMAP_OFFSET DRM_IOCTL_PANTHOR(WR, BO_MMAP_OFFSET, bo_mmap_offset)
-#define DRM_IOCTL_PANTHOR_GROUP_CREATE DRM_IOCTL_PANTHOR(WR, GROUP_CREATE, group_create)
-#define DRM_IOCTL_PANTHOR_GROUP_DESTROY DRM_IOCTL_PANTHOR(WR, GROUP_DESTROY, group_destroy)
-#define DRM_IOCTL_PANTHOR_GROUP_SUBMIT DRM_IOCTL_PANTHOR(WR, GROUP_SUBMIT, group_submit)
-#define DRM_IOCTL_PANTHOR_GROUP_GET_STATE DRM_IOCTL_PANTHOR(WR, GROUP_GET_STATE, group_get_state)
-#define DRM_IOCTL_PANTHOR_TILER_HEAP_CREATE DRM_IOCTL_PANTHOR(WR, TILER_HEAP_CREATE, tiler_heap_create)
-#define DRM_IOCTL_PANTHOR_TILER_HEAP_DESTROY DRM_IOCTL_PANTHOR(WR, TILER_HEAP_DESTROY, tiler_heap_destroy)
 struct drm_panthor_obj_array {
   __u32 stride;
   __u32 count;
@@ -64,6 +51,8 @@
 enum drm_panthor_dev_query_type {
   DRM_PANTHOR_DEV_QUERY_GPU_INFO = 0,
   DRM_PANTHOR_DEV_QUERY_CSIF_INFO,
+  DRM_PANTHOR_DEV_QUERY_TIMESTAMP_INFO,
+  DRM_PANTHOR_DEV_QUERY_GROUP_PRIORITIES_INFO,
 };
 struct drm_panthor_gpu_info {
   __u32 gpu_id;
@@ -108,6 +97,15 @@
   __u32 unpreserved_cs_reg_count;
   __u32 pad;
 };
+struct drm_panthor_timestamp_info {
+  __u64 timestamp_frequency;
+  __u64 current_timestamp;
+  __u64 timestamp_offset;
+};
+struct drm_panthor_group_priorities_info {
+  __u8 allowed_mask;
+  __u8 pad[3];
+};
 struct drm_panthor_dev_query {
   __u32 type;
   __u32 size;
@@ -179,6 +177,7 @@
   PANTHOR_GROUP_PRIORITY_LOW = 0,
   PANTHOR_GROUP_PRIORITY_MEDIUM,
   PANTHOR_GROUP_PRIORITY_HIGH,
+  PANTHOR_GROUP_PRIORITY_REALTIME,
 };
 struct drm_panthor_group_create {
   struct drm_panthor_obj_array queues;
@@ -213,6 +212,7 @@
 enum drm_panthor_group_state_flags {
   DRM_PANTHOR_GROUP_STATE_TIMEDOUT = 1 << 0,
   DRM_PANTHOR_GROUP_STATE_FATAL_FAULT = 1 << 1,
+  DRM_PANTHOR_GROUP_STATE_INNOCENT = 1 << 2,
 };
 struct drm_panthor_group_get_state {
   __u32 group_handle;
@@ -234,6 +234,28 @@
   __u32 handle;
   __u32 pad;
 };
+struct drm_panthor_bo_set_label {
+  __u32 handle;
+  __u32 pad;
+  __u64 label;
+};
+#define DRM_IOCTL_PANTHOR(__access,__id,__type) DRM_IO ##__access(DRM_COMMAND_BASE + DRM_PANTHOR_ ##__id, struct drm_panthor_ ##__type)
+enum {
+  DRM_IOCTL_PANTHOR_DEV_QUERY = DRM_IOCTL_PANTHOR(WR, DEV_QUERY, dev_query),
+  DRM_IOCTL_PANTHOR_VM_CREATE = DRM_IOCTL_PANTHOR(WR, VM_CREATE, vm_create),
+  DRM_IOCTL_PANTHOR_VM_DESTROY = DRM_IOCTL_PANTHOR(WR, VM_DESTROY, vm_destroy),
+  DRM_IOCTL_PANTHOR_VM_BIND = DRM_IOCTL_PANTHOR(WR, VM_BIND, vm_bind),
+  DRM_IOCTL_PANTHOR_VM_GET_STATE = DRM_IOCTL_PANTHOR(WR, VM_GET_STATE, vm_get_state),
+  DRM_IOCTL_PANTHOR_BO_CREATE = DRM_IOCTL_PANTHOR(WR, BO_CREATE, bo_create),
+  DRM_IOCTL_PANTHOR_BO_MMAP_OFFSET = DRM_IOCTL_PANTHOR(WR, BO_MMAP_OFFSET, bo_mmap_offset),
+  DRM_IOCTL_PANTHOR_GROUP_CREATE = DRM_IOCTL_PANTHOR(WR, GROUP_CREATE, group_create),
+  DRM_IOCTL_PANTHOR_GROUP_DESTROY = DRM_IOCTL_PANTHOR(WR, GROUP_DESTROY, group_destroy),
+  DRM_IOCTL_PANTHOR_GROUP_SUBMIT = DRM_IOCTL_PANTHOR(WR, GROUP_SUBMIT, group_submit),
+  DRM_IOCTL_PANTHOR_GROUP_GET_STATE = DRM_IOCTL_PANTHOR(WR, GROUP_GET_STATE, group_get_state),
+  DRM_IOCTL_PANTHOR_TILER_HEAP_CREATE = DRM_IOCTL_PANTHOR(WR, TILER_HEAP_CREATE, tiler_heap_create),
+  DRM_IOCTL_PANTHOR_TILER_HEAP_DESTROY = DRM_IOCTL_PANTHOR(WR, TILER_HEAP_DESTROY, tiler_heap_destroy),
+  DRM_IOCTL_PANTHOR_BO_SET_LABEL = DRM_IOCTL_PANTHOR(WR, BO_SET_LABEL, bo_set_label),
+};
 #ifdef __cplusplus
 }
 #endif
diff --git a/libc/kernel/uapi/drm/v3d_drm.h b/libc/kernel/uapi/drm/v3d_drm.h
index b7aca21..0c09113 100644
--- a/libc/kernel/uapi/drm/v3d_drm.h
+++ b/libc/kernel/uapi/drm/v3d_drm.h
@@ -23,6 +23,7 @@
 #define DRM_V3D_PERFMON_GET_VALUES 0x0a
 #define DRM_V3D_SUBMIT_CPU 0x0b
 #define DRM_V3D_PERFMON_GET_COUNTER 0x0c
+#define DRM_V3D_PERFMON_SET_GLOBAL 0x0d
 #define DRM_IOCTL_V3D_SUBMIT_CL DRM_IOWR(DRM_COMMAND_BASE + DRM_V3D_SUBMIT_CL, struct drm_v3d_submit_cl)
 #define DRM_IOCTL_V3D_WAIT_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_V3D_WAIT_BO, struct drm_v3d_wait_bo)
 #define DRM_IOCTL_V3D_CREATE_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_V3D_CREATE_BO, struct drm_v3d_create_bo)
@@ -36,6 +37,7 @@
 #define DRM_IOCTL_V3D_PERFMON_GET_VALUES DRM_IOWR(DRM_COMMAND_BASE + DRM_V3D_PERFMON_GET_VALUES, struct drm_v3d_perfmon_get_values)
 #define DRM_IOCTL_V3D_SUBMIT_CPU DRM_IOW(DRM_COMMAND_BASE + DRM_V3D_SUBMIT_CPU, struct drm_v3d_submit_cpu)
 #define DRM_IOCTL_V3D_PERFMON_GET_COUNTER DRM_IOWR(DRM_COMMAND_BASE + DRM_V3D_PERFMON_GET_COUNTER, struct drm_v3d_perfmon_get_counter)
+#define DRM_IOCTL_V3D_PERFMON_SET_GLOBAL DRM_IOW(DRM_COMMAND_BASE + DRM_V3D_PERFMON_SET_GLOBAL, struct drm_v3d_perfmon_set_global)
 #define DRM_V3D_SUBMIT_CL_FLUSH_CACHE 0x01
 #define DRM_V3D_SUBMIT_EXTENSION 0x02
 struct drm_v3d_extension {
@@ -122,6 +124,7 @@
   DRM_V3D_PARAM_SUPPORTS_MULTISYNC_EXT,
   DRM_V3D_PARAM_SUPPORTS_CPU_QUEUE,
   DRM_V3D_PARAM_MAX_PERF_COUNTERS,
+  DRM_V3D_PARAM_SUPPORTS_SUPER_PAGES,
 };
 struct drm_v3d_get_param {
   __u32 param;
@@ -337,6 +340,11 @@
   __u8 description[DRM_V3D_PERFCNT_MAX_DESCRIPTION];
   __u8 reserved[7];
 };
+#define DRM_V3D_PERFMON_CLEAR_GLOBAL 0x0001
+struct drm_v3d_perfmon_set_global {
+  __u32 flags;
+  __u32 id;
+};
 #ifdef __cplusplus
 }
 #endif
diff --git a/libc/kernel/uapi/drm/virtgpu_drm.h b/libc/kernel/uapi/drm/virtgpu_drm.h
index d79c7d9..fb1edfa 100644
--- a/libc/kernel/uapi/drm/virtgpu_drm.h
+++ b/libc/kernel/uapi/drm/virtgpu_drm.h
@@ -114,6 +114,12 @@
   __u32 handle;
   __u32 flags;
 };
+#define VIRTGPU_DRM_CAPSET_VIRGL 1
+#define VIRTGPU_DRM_CAPSET_VIRGL2 2
+#define VIRTGPU_DRM_CAPSET_GFXSTREAM_VULKAN 3
+#define VIRTGPU_DRM_CAPSET_VENUS 4
+#define VIRTGPU_DRM_CAPSET_CROSS_DOMAIN 5
+#define VIRTGPU_DRM_CAPSET_DRM 6
 struct drm_virtgpu_get_caps {
   __u32 cap_set_id;
   __u32 cap_set_ver;
diff --git a/libc/kernel/uapi/drm/xe_drm.h b/libc/kernel/uapi/drm/xe_drm.h
index 16bc3b3..6aa2bc6 100644
--- a/libc/kernel/uapi/drm/xe_drm.h
+++ b/libc/kernel/uapi/drm/xe_drm.h
@@ -92,6 +92,8 @@
 #define DRM_XE_QUERY_CONFIG_REV_AND_DEVICE_ID 0
 #define DRM_XE_QUERY_CONFIG_FLAGS 1
 #define DRM_XE_QUERY_CONFIG_FLAG_HAS_VRAM (1 << 0)
+#define DRM_XE_QUERY_CONFIG_FLAG_HAS_LOW_LATENCY (1 << 1)
+#define DRM_XE_QUERY_CONFIG_FLAG_HAS_CPU_ADDR_MIRROR (1 << 2)
 #define DRM_XE_QUERY_CONFIG_MIN_ALIGNMENT 2
 #define DRM_XE_QUERY_CONFIG_VA_BITS 3
 #define DRM_XE_QUERY_CONFIG_MAX_EXEC_QUEUE_PRIORITY 4
@@ -149,6 +151,10 @@
   __u32 pad2;
   __u64 reserved;
 };
+struct drm_xe_query_pxp_status {
+  __u32 status;
+  __u32 supported_session_types;
+};
 struct drm_xe_device_query {
   __u64 extensions;
 #define DRM_XE_DEVICE_QUERY_ENGINES 0
@@ -160,12 +166,16 @@
 #define DRM_XE_DEVICE_QUERY_ENGINE_CYCLES 6
 #define DRM_XE_DEVICE_QUERY_UC_FW_VERSION 7
 #define DRM_XE_DEVICE_QUERY_OA_UNITS 8
+#define DRM_XE_DEVICE_QUERY_PXP_STATUS 9
+#define DRM_XE_DEVICE_QUERY_EU_STALL 10
   __u32 query;
   __u32 size;
   __u64 data;
   __u64 reserved[2];
 };
 struct drm_xe_gem_create {
+#define DRM_XE_GEM_CREATE_EXTENSION_SET_PROPERTY 0
+#define DRM_XE_GEM_CREATE_SET_PROPERTY_PXP_TYPE 0
   __u64 extensions;
   __u64 size;
   __u32 placement;
@@ -184,6 +194,7 @@
 struct drm_xe_gem_mmap_offset {
   __u64 extensions;
   __u32 handle;
+#define DRM_XE_MMAP_OFFSET_FLAG_PCI_BARRIER (1 << 0)
   __u32 flags;
   __u64 offset;
   __u64 reserved[2];
@@ -210,6 +221,7 @@
   union {
     __u64 obj_offset;
     __u64 userptr;
+    __s64 cpu_addr_mirror_offset;
   };
   __u64 range;
   __u64 addr;
@@ -223,6 +235,8 @@
 #define DRM_XE_VM_BIND_FLAG_IMMEDIATE (1 << 1)
 #define DRM_XE_VM_BIND_FLAG_NULL (1 << 2)
 #define DRM_XE_VM_BIND_FLAG_DUMPABLE (1 << 3)
+#define DRM_XE_VM_BIND_FLAG_CHECK_PXP (1 << 4)
+#define DRM_XE_VM_BIND_FLAG_CPU_ADDR_MIRROR (1 << 5)
   __u32 flags;
   __u32 prefetch_mem_region_instance;
   __u32 pad2;
@@ -247,10 +261,12 @@
 #define DRM_XE_EXEC_QUEUE_EXTENSION_SET_PROPERTY 0
 #define DRM_XE_EXEC_QUEUE_SET_PROPERTY_PRIORITY 0
 #define DRM_XE_EXEC_QUEUE_SET_PROPERTY_TIMESLICE 1
+#define DRM_XE_EXEC_QUEUE_SET_PROPERTY_PXP_TYPE 2
   __u64 extensions;
   __u16 width;
   __u16 num_placements;
   __u32 vm_id;
+#define DRM_XE_EXEC_QUEUE_LOW_LATENCY_HINT (1 << 0)
   __u32 flags;
   __u32 exec_queue_id;
   __u64 instances;
@@ -316,6 +332,7 @@
 };
 enum drm_xe_observation_type {
   DRM_XE_OBSERVATION_TYPE_OA,
+  DRM_XE_OBSERVATION_TYPE_EU_STALL,
 };
 enum drm_xe_observation_op {
   DRM_XE_OBSERVATION_OP_STREAM_OPEN,
@@ -345,6 +362,9 @@
   __u32 oa_unit_type;
   __u64 capabilities;
 #define DRM_XE_OA_CAPS_BASE (1 << 0)
+#define DRM_XE_OA_CAPS_SYNCS (1 << 1)
+#define DRM_XE_OA_CAPS_OA_BUFFER_SIZE (1 << 2)
+#define DRM_XE_OA_CAPS_WAIT_NUM_REPORTS (1 << 3)
   __u64 oa_timestamp_freq;
   __u64 reserved[4];
   __u64 num_engines;
@@ -379,6 +399,10 @@
   DRM_XE_OA_PROPERTY_EXEC_QUEUE_ID,
   DRM_XE_OA_PROPERTY_OA_ENGINE_INSTANCE,
   DRM_XE_OA_PROPERTY_NO_PREEMPT,
+  DRM_XE_OA_PROPERTY_NUM_SYNCS,
+  DRM_XE_OA_PROPERTY_SYNCS,
+  DRM_XE_OA_PROPERTY_OA_BUFFER_SIZE,
+  DRM_XE_OA_PROPERTY_WAIT_NUM_REPORTS,
 };
 struct drm_xe_oa_config {
   __u64 extensions;
@@ -400,6 +424,27 @@
   __u64 oa_buf_size;
   __u64 reserved[3];
 };
+enum drm_xe_pxp_session_type {
+  DRM_XE_PXP_TYPE_NONE = 0,
+  DRM_XE_PXP_TYPE_HWDRM = 1,
+};
+#define DRM_XE_PXP_HWDRM_DEFAULT_SESSION 0xf
+enum drm_xe_eu_stall_property_id {
+#define DRM_XE_EU_STALL_EXTENSION_SET_PROPERTY 0
+  DRM_XE_EU_STALL_PROP_GT_ID = 1,
+  DRM_XE_EU_STALL_PROP_SAMPLE_RATE,
+  DRM_XE_EU_STALL_PROP_WAIT_NUM_REPORTS,
+};
+struct drm_xe_query_eu_stall {
+  __u64 extensions;
+  __u64 capabilities;
+#define DRM_XE_EU_STALL_CAPS_BASE (1 << 0)
+  __u64 record_size;
+  __u64 per_xecore_buf_size;
+  __u64 reserved[5];
+  __u64 num_sampling_rates;
+  __u64 sampling_rates[];
+};
 #ifdef __cplusplus
 }
 #endif
diff --git a/libc/kernel/uapi/fwctl/cxl.h b/libc/kernel/uapi/fwctl/cxl.h
new file mode 100644
index 0000000..b67c477
--- /dev/null
+++ b/libc/kernel/uapi/fwctl/cxl.h
@@ -0,0 +1,33 @@
+/*
+ * This file is auto-generated. Modifications will be lost.
+ *
+ * See https://android.googlesource.com/platform/bionic/+/master/libc/kernel/
+ * for more information.
+ */
+#ifndef _UAPI_FWCTL_CXL_H_
+#define _UAPI_FWCTL_CXL_H_
+#include <linux/types.h>
+#include <linux/stddef.h>
+#include <cxl/features.h>
+struct fwctl_rpc_cxl {
+  __struct_group(fwctl_rpc_cxl_hdr, hdr,, __u32 opcode;
+  __u32 flags;
+  __u32 op_size;
+  __u32 reserved1;
+ );
+  union {
+    struct cxl_mbox_get_sup_feats_in get_sup_feats_in;
+    struct cxl_mbox_get_feat_in get_feat_in;
+    struct cxl_mbox_set_feat_in set_feat_in;
+  };
+};
+struct fwctl_rpc_cxl_out {
+  __struct_group(fwctl_rpc_cxl_out_hdr, hdr,, __u32 size;
+  __u32 retval;
+ );
+  union {
+    struct cxl_mbox_get_sup_feats_out get_sup_feats_out;
+    __DECLARE_FLEX_ARRAY(__u8, payload);
+  };
+};
+#endif
diff --git a/libc/kernel/uapi/fwctl/fwctl.h b/libc/kernel/uapi/fwctl/fwctl.h
new file mode 100644
index 0000000..9c126f6
--- /dev/null
+++ b/libc/kernel/uapi/fwctl/fwctl.h
@@ -0,0 +1,46 @@
+/*
+ * This file is auto-generated. Modifications will be lost.
+ *
+ * See https://android.googlesource.com/platform/bionic/+/master/libc/kernel/
+ * for more information.
+ */
+#ifndef _UAPI_FWCTL_H
+#define _UAPI_FWCTL_H
+#include <linux/types.h>
+#include <linux/ioctl.h>
+#define FWCTL_TYPE 0x9A
+enum {
+  FWCTL_CMD_BASE = 0,
+  FWCTL_CMD_INFO = 0,
+  FWCTL_CMD_RPC = 1,
+};
+enum fwctl_device_type {
+  FWCTL_DEVICE_TYPE_ERROR = 0,
+  FWCTL_DEVICE_TYPE_MLX5 = 1,
+  FWCTL_DEVICE_TYPE_CXL = 2,
+  FWCTL_DEVICE_TYPE_PDS = 4,
+};
+struct fwctl_info {
+  __u32 size;
+  __u32 flags;
+  __u32 out_device_type;
+  __u32 device_data_len;
+  __aligned_u64 out_device_data;
+};
+#define FWCTL_INFO _IO(FWCTL_TYPE, FWCTL_CMD_INFO)
+enum fwctl_rpc_scope {
+  FWCTL_RPC_CONFIGURATION = 0,
+  FWCTL_RPC_DEBUG_READ_ONLY = 1,
+  FWCTL_RPC_DEBUG_WRITE = 2,
+  FWCTL_RPC_DEBUG_WRITE_FULL = 3,
+};
+struct fwctl_rpc {
+  __u32 size;
+  __u32 scope;
+  __u32 in_len;
+  __u32 out_len;
+  __aligned_u64 in;
+  __aligned_u64 out;
+};
+#define FWCTL_RPC _IO(FWCTL_TYPE, FWCTL_CMD_RPC)
+#endif
diff --git a/libc/kernel/uapi/fwctl/mlx5.h b/libc/kernel/uapi/fwctl/mlx5.h
new file mode 100644
index 0000000..871a3d4
--- /dev/null
+++ b/libc/kernel/uapi/fwctl/mlx5.h
@@ -0,0 +1,14 @@
+/*
+ * This file is auto-generated. Modifications will be lost.
+ *
+ * See https://android.googlesource.com/platform/bionic/+/master/libc/kernel/
+ * for more information.
+ */
+#ifndef _UAPI_FWCTL_MLX5_H
+#define _UAPI_FWCTL_MLX5_H
+#include <linux/types.h>
+struct fwctl_info_mlx5 {
+  __u32 uid;
+  __u32 uctx_caps;
+};
+#endif
diff --git a/libc/kernel/uapi/fwctl/pds.h b/libc/kernel/uapi/fwctl/pds.h
new file mode 100644
index 0000000..85b4563
--- /dev/null
+++ b/libc/kernel/uapi/fwctl/pds.h
@@ -0,0 +1,32 @@
+/*
+ * This file is auto-generated. Modifications will be lost.
+ *
+ * See https://android.googlesource.com/platform/bionic/+/master/libc/kernel/
+ * for more information.
+ */
+#ifndef _UAPI_FWCTL_PDS_H_
+#define _UAPI_FWCTL_PDS_H_
+#include <linux/types.h>
+struct fwctl_info_pds {
+  __u32 uctx_caps;
+};
+enum pds_fwctl_capabilities {
+  PDS_FWCTL_QUERY_CAP = 0,
+  PDS_FWCTL_SEND_CAP,
+};
+struct fwctl_rpc_pds {
+  struct {
+    __u32 op;
+    __u32 ep;
+    __u32 rsvd;
+    __u32 len;
+    __aligned_u64 payload;
+  } in;
+  struct {
+    __u32 retval;
+    __u32 rsvd[2];
+    __u32 len;
+    __aligned_u64 payload;
+  } out;
+};
+#endif
diff --git a/libc/kernel/uapi/linux/audit.h b/libc/kernel/uapi/linux/audit.h
index ae50fcc..32510db 100644
--- a/libc/kernel/uapi/linux/audit.h
+++ b/libc/kernel/uapi/linux/audit.h
@@ -98,6 +98,8 @@
 #define AUDIT_IPE_ACCESS 1420
 #define AUDIT_IPE_CONFIG_CHANGE 1421
 #define AUDIT_IPE_POLICY_LOAD 1422
+#define AUDIT_LANDLOCK_ACCESS 1423
+#define AUDIT_LANDLOCK_DOMAIN 1424
 #define AUDIT_FIRST_KERN_ANOM_MSG 1700
 #define AUDIT_LAST_KERN_ANOM_MSG 1799
 #define AUDIT_ANOM_PROMISCUOUS 1700
@@ -112,6 +114,7 @@
 #define AUDIT_INTEGRITY_RULE 1805
 #define AUDIT_INTEGRITY_EVM_XATTR 1806
 #define AUDIT_INTEGRITY_POLICY_RULE 1807
+#define AUDIT_INTEGRITY_USERSPACE 1808
 #define AUDIT_KERNEL 2000
 #define AUDIT_FILTER_USER 0x00
 #define AUDIT_FILTER_TASK 0x01
diff --git a/libc/kernel/uapi/linux/batadv_packet.h b/libc/kernel/uapi/linux/batadv_packet.h
index 83e5e71..3c5a859 100644
--- a/libc/kernel/uapi/linux/batadv_packet.h
+++ b/libc/kernel/uapi/linux/batadv_packet.h
@@ -8,6 +8,7 @@
 #define _UAPI_LINUX_BATADV_PACKET_H_
 #include <asm/byteorder.h>
 #include <linux/if_ether.h>
+#include <linux/stddef.h>
 #include <linux/types.h>
 #define batadv_tp_is_error(n) ((__u8) (n) > 127 ? 1 : 0)
 enum batadv_packettype {
@@ -252,16 +253,17 @@
   __be32 bandwidth_down;
   __be32 bandwidth_up;
 };
-struct batadv_tvlv_tt_data {
-  __u8 flags;
-  __u8 ttvn;
-  __be16 num_vlan;
-};
 struct batadv_tvlv_tt_vlan_data {
   __be32 crc;
   __be16 vid;
   __u16 reserved;
 };
+struct batadv_tvlv_tt_data {
+  __u8 flags;
+  __u8 ttvn;
+  __be16 num_vlan;
+  struct batadv_tvlv_tt_vlan_data vlan_data[] __counted_by_be(num_vlan);
+};
 struct batadv_tvlv_tt_change {
   __u8 flags;
   __u8 reserved[3];
diff --git a/libc/kernel/uapi/linux/bits.h b/libc/kernel/uapi/linux/bits.h
index 2b8dbe2..3c8646e 100644
--- a/libc/kernel/uapi/linux/bits.h
+++ b/libc/kernel/uapi/linux/bits.h
@@ -6,7 +6,7 @@
  */
 #ifndef _UAPI_LINUX_BITS_H
 #define _UAPI_LINUX_BITS_H
-#define __GENMASK(h,l) (((~_UL(0)) - (_UL(1) << (l)) + 1) & (~_UL(0) >> (__BITS_PER_LONG - 1 - (h))))
-#define __GENMASK_ULL(h,l) (((~_ULL(0)) - (_ULL(1) << (l)) + 1) & (~_ULL(0) >> (__BITS_PER_LONG_LONG - 1 - (h))))
+#define __GENMASK(h,l) (((~_UL(0)) << (l)) & (~_UL(0) >> (__BITS_PER_LONG - 1 - (h))))
+#define __GENMASK_ULL(h,l) (((~_ULL(0)) << (l)) & (~_ULL(0) >> (__BITS_PER_LONG_LONG - 1 - (h))))
 #define __GENMASK_U128(h,l) ((_BIT128((h)) << 1) - (_BIT128(l)))
 #endif
diff --git a/libc/kernel/uapi/linux/blk-crypto.h b/libc/kernel/uapi/linux/blk-crypto.h
new file mode 100644
index 0000000..a4a48a2
--- /dev/null
+++ b/libc/kernel/uapi/linux/blk-crypto.h
@@ -0,0 +1,33 @@
+/*
+ * This file is auto-generated. Modifications will be lost.
+ *
+ * See https://android.googlesource.com/platform/bionic/+/master/libc/kernel/
+ * for more information.
+ */
+#ifndef _UAPI_LINUX_BLK_CRYPTO_H
+#define _UAPI_LINUX_BLK_CRYPTO_H
+#include <linux/ioctl.h>
+#include <linux/types.h>
+struct blk_crypto_import_key_arg {
+  __u64 raw_key_ptr;
+  __u64 raw_key_size;
+  __u64 lt_key_ptr;
+  __u64 lt_key_size;
+  __u64 reserved[4];
+};
+struct blk_crypto_generate_key_arg {
+  __u64 lt_key_ptr;
+  __u64 lt_key_size;
+  __u64 reserved[4];
+};
+struct blk_crypto_prepare_key_arg {
+  __u64 lt_key_ptr;
+  __u64 lt_key_size;
+  __u64 eph_key_ptr;
+  __u64 eph_key_size;
+  __u64 reserved[4];
+};
+#define BLKCRYPTOIMPORTKEY _IOWR(0x12, 137, struct blk_crypto_import_key_arg)
+#define BLKCRYPTOGENERATEKEY _IOWR(0x12, 138, struct blk_crypto_generate_key_arg)
+#define BLKCRYPTOPREPAREKEY _IOWR(0x12, 139, struct blk_crypto_prepare_key_arg)
+#endif
diff --git a/libc/kernel/uapi/linux/bpf.h b/libc/kernel/uapi/linux/bpf.h
index c0d862d..ee88f06 100644
--- a/libc/kernel/uapi/linux/bpf.h
+++ b/libc/kernel/uapi/linux/bpf.h
@@ -34,6 +34,8 @@
 #define BPF_FETCH 0x01
 #define BPF_XCHG (0xe0 | BPF_FETCH)
 #define BPF_CMPXCHG (0xf0 | BPF_FETCH)
+#define BPF_LOAD_ACQ 0x100
+#define BPF_STORE_REL 0x110
 enum bpf_cond_pseudo_jmp {
   BPF_MAY_GOTO = 0,
 };
@@ -273,6 +275,7 @@
   BPF_NETKIT_PRIMARY,
   BPF_NETKIT_PEER,
   BPF_TRACE_KPROBE_SESSION,
+  BPF_TRACE_UPROBE_SESSION,
   __MAX_BPF_ATTACH_TYPE
 };
 #define MAX_BPF_ATTACH_TYPE __MAX_BPF_ATTACH_TYPE
@@ -310,6 +313,7 @@
 #define BPF_F_BEFORE (1U << 3)
 #define BPF_F_AFTER (1U << 4)
 #define BPF_F_ID (1U << 5)
+#define BPF_F_PREORDER (1U << 6)
 #define BPF_F_LINK BPF_F_LINK
 #define BPF_F_STRICT_ALIGNMENT (1U << 0)
 #define BPF_F_ANY_ALIGNMENT (1U << 1)
@@ -455,6 +459,7 @@
     __u32 core_relo_rec_size;
     __u32 log_true_size;
     __s32 prog_token_fd;
+    __u32 fd_array_cnt;
   };
   struct {
     __aligned_u64 pathname;
@@ -504,6 +509,7 @@
     };
     __u32 next_id;
     __u32 open_flags;
+    __s32 fd_by_id_token_fd;
   };
   struct {
     __u32 bpf_fd;
@@ -669,6 +675,7 @@
   BPF_F_PSEUDO_HDR = (1ULL << 4),
   BPF_F_MARK_MANGLED_0 = (1ULL << 5),
   BPF_F_MARK_ENFORCE = (1ULL << 6),
+  BPF_F_IPV6 = (1ULL << 7),
 };
 enum {
   BPF_F_TUNINFO_IPV6 = (1ULL << 0),
@@ -1126,6 +1133,7 @@
           __u32 name_len;
           __u32 offset;
           __u64 cookie;
+          __u64 ref_ctr_offset;
         } uprobe;
         struct {
           __aligned_u64 func_name;
@@ -1233,6 +1241,10 @@
   BPF_SOCK_OPS_ALL_CB_FLAGS = 0x7F,
 };
 enum {
+  SK_BPF_CB_TX_TIMESTAMPING = 1 << 0,
+  SK_BPF_CB_MASK = (SK_BPF_CB_TX_TIMESTAMPING - 1) | SK_BPF_CB_TX_TIMESTAMPING
+};
+enum {
   BPF_SOCK_OPS_VOID,
   BPF_SOCK_OPS_TIMEOUT_INIT,
   BPF_SOCK_OPS_RWND_INIT,
@@ -1249,6 +1261,11 @@
   BPF_SOCK_OPS_PARSE_HDR_OPT_CB,
   BPF_SOCK_OPS_HDR_OPT_LEN_CB,
   BPF_SOCK_OPS_WRITE_HDR_OPT_CB,
+  BPF_SOCK_OPS_TSTAMP_SCHED_CB,
+  BPF_SOCK_OPS_TSTAMP_SND_SW_CB,
+  BPF_SOCK_OPS_TSTAMP_SND_HW_CB,
+  BPF_SOCK_OPS_TSTAMP_ACK_CB,
+  BPF_SOCK_OPS_TSTAMP_SENDMSG_CB,
 };
 enum {
   BPF_TCP_ESTABLISHED = 1,
@@ -1275,6 +1292,7 @@
   TCP_BPF_SYN_IP = 1006,
   TCP_BPF_SYN_MAC = 1007,
   TCP_BPF_SOCK_OPS_CB_FLAGS = 1008,
+  SK_BPF_CB_FLAGS = 1009,
 };
 enum {
   BPF_LOAD_HDR_OPT_TCP_SYN = (1ULL << 0),
diff --git a/libc/kernel/uapi/linux/btrfs.h b/libc/kernel/uapi/linux/btrfs.h
index a3ebc4f..bba3670 100644
--- a/libc/kernel/uapi/linux/btrfs.h
+++ b/libc/kernel/uapi/linux/btrfs.h
@@ -311,13 +311,20 @@
 };
 #define BTRFS_DEFRAG_RANGE_COMPRESS 1
 #define BTRFS_DEFRAG_RANGE_START_IO 2
-#define BTRFS_DEFRAG_RANGE_FLAGS_SUPP (BTRFS_DEFRAG_RANGE_COMPRESS | BTRFS_DEFRAG_RANGE_START_IO)
+#define BTRFS_DEFRAG_RANGE_COMPRESS_LEVEL 4
+#define BTRFS_DEFRAG_RANGE_FLAGS_SUPP (BTRFS_DEFRAG_RANGE_COMPRESS | BTRFS_DEFRAG_RANGE_COMPRESS_LEVEL | BTRFS_DEFRAG_RANGE_START_IO)
 struct btrfs_ioctl_defrag_range_args {
   __u64 start;
   __u64 len;
   __u64 flags;
   __u32 extent_thresh;
-  __u32 compress_type;
+  union {
+    __u32 compress_type;
+    struct {
+      __u8 type;
+      __s8 level;
+    } compress;
+  };
   __u32 unused[4];
 };
 #define BTRFS_SAME_DATA_DIFFERS 1
@@ -486,6 +493,16 @@
 #define BTRFS_ENCODED_IO_COMPRESSION_TYPES 8
 #define BTRFS_ENCODED_IO_ENCRYPTION_NONE 0
 #define BTRFS_ENCODED_IO_ENCRYPTION_TYPES 1
+struct btrfs_ioctl_subvol_wait {
+  __u64 subvolid;
+  __u32 mode;
+  __u32 count;
+};
+#define BTRFS_SUBVOL_SYNC_WAIT_FOR_ONE (0)
+#define BTRFS_SUBVOL_SYNC_WAIT_FOR_QUEUED (1)
+#define BTRFS_SUBVOL_SYNC_COUNT (2)
+#define BTRFS_SUBVOL_SYNC_PEEK_FIRST (3)
+#define BTRFS_SUBVOL_SYNC_PEEK_LAST (4)
 enum btrfs_err_code {
   BTRFS_ERROR_DEV_RAID1_MIN_NOT_MET = 1,
   BTRFS_ERROR_DEV_RAID10_MIN_NOT_MET,
@@ -561,6 +578,7 @@
 #define BTRFS_IOC_SNAP_DESTROY_V2 _IOW(BTRFS_IOCTL_MAGIC, 63, struct btrfs_ioctl_vol_args_v2)
 #define BTRFS_IOC_ENCODED_READ _IOR(BTRFS_IOCTL_MAGIC, 64, struct btrfs_ioctl_encoded_io_args)
 #define BTRFS_IOC_ENCODED_WRITE _IOW(BTRFS_IOCTL_MAGIC, 64, struct btrfs_ioctl_encoded_io_args)
+#define BTRFS_IOC_SUBVOL_SYNC_WAIT _IOW(BTRFS_IOCTL_MAGIC, 65, struct btrfs_ioctl_subvol_wait)
 #ifdef __cplusplus
 }
 #endif
diff --git a/libc/kernel/uapi/linux/can.h b/libc/kernel/uapi/linux/can.h
index a913d73..c766d73 100644
--- a/libc/kernel/uapi/linux/can.h
+++ b/libc/kernel/uapi/linux/can.h
@@ -55,6 +55,7 @@
 };
 #define CANXL_XLF 0x80
 #define CANXL_SEC 0x01
+#define CANXL_RRS 0x02
 #define CANXL_VCID_OFFSET 16
 #define CANXL_VCID_VAL_MASK 0xFFUL
 #define CANXL_VCID_MASK (CANXL_VCID_VAL_MASK << CANXL_VCID_OFFSET)
diff --git a/libc/kernel/uapi/linux/counter.h b/libc/kernel/uapi/linux/counter.h
index 5d6f01f..e601e10 100644
--- a/libc/kernel/uapi/linux/counter.h
+++ b/libc/kernel/uapi/linux/counter.h
@@ -35,6 +35,7 @@
   COUNTER_EVENT_INDEX,
   COUNTER_EVENT_CHANGE_OF_STATE,
   COUNTER_EVENT_CAPTURE,
+  COUNTER_EVENT_DIRECTION_CHANGE,
 };
 struct counter_watch {
   struct counter_component component;
diff --git a/libc/kernel/uapi/linux/counter/microchip-tcb-capture.h b/libc/kernel/uapi/linux/counter/microchip-tcb-capture.h
new file mode 100644
index 0000000..77ce663
--- /dev/null
+++ b/libc/kernel/uapi/linux/counter/microchip-tcb-capture.h
@@ -0,0 +1,15 @@
+/*
+ * This file is auto-generated. Modifications will be lost.
+ *
+ * See https://android.googlesource.com/platform/bionic/+/master/libc/kernel/
+ * for more information.
+ */
+#ifndef _UAPI_COUNTER_MCHP_TCB_H_
+#define _UAPI_COUNTER_MCHP_TCB_H_
+#define COUNTER_MCHP_EXCAP_RA 0
+#define COUNTER_MCHP_EXCAP_RB 1
+#define COUNTER_MCHP_EVCHN_CV 0
+#define COUNTER_MCHP_EVCHN_RA 0
+#define COUNTER_MCHP_EVCHN_RB 1
+#define COUNTER_MCHP_EVCHN_RC 2
+#endif
diff --git a/libc/kernel/uapi/linux/cryptouser.h b/libc/kernel/uapi/linux/cryptouser.h
index 9ffab6d..eefd897 100644
--- a/libc/kernel/uapi/linux/cryptouser.h
+++ b/libc/kernel/uapi/linux/cryptouser.h
@@ -43,6 +43,7 @@
   CRYPTOCFGA_STAT_AKCIPHER,
   CRYPTOCFGA_STAT_KPP,
   CRYPTOCFGA_STAT_ACOMP,
+  CRYPTOCFGA_REPORT_SIG,
   __CRYPTOCFGA_MAX
 #define CRYPTOCFGA_MAX (__CRYPTOCFGA_MAX - 1)
 };
@@ -157,5 +158,8 @@
 struct crypto_report_acomp {
   char type[CRYPTO_MAX_NAME];
 };
+struct crypto_report_sig {
+  char type[CRYPTO_MAX_NAME];
+};
 #define CRYPTO_REPORT_MAXSIZE (sizeof(struct crypto_user_alg) + sizeof(struct crypto_report_blkcipher))
 #endif
diff --git a/libc/kernel/uapi/linux/devlink.h b/libc/kernel/uapi/linux/devlink.h
index d87c189..f63bfb7 100644
--- a/libc/kernel/uapi/linux/devlink.h
+++ b/libc/kernel/uapi/linux/devlink.h
@@ -237,6 +237,17 @@
   __DEVLINK_LINECARD_STATE_MAX,
   DEVLINK_LINECARD_STATE_MAX = __DEVLINK_LINECARD_STATE_MAX - 1
 };
+enum devlink_var_attr_type {
+  DEVLINK_VAR_ATTR_TYPE_U8 = 1,
+  DEVLINK_VAR_ATTR_TYPE_U16,
+  DEVLINK_VAR_ATTR_TYPE_U32,
+  DEVLINK_VAR_ATTR_TYPE_U64,
+  DEVLINK_VAR_ATTR_TYPE_STRING,
+  DEVLINK_VAR_ATTR_TYPE_FLAG,
+  DEVLINK_VAR_ATTR_TYPE_NUL_STRING = 10,
+  DEVLINK_VAR_ATTR_TYPE_BINARY,
+  __DEVLINK_VAR_ATTR_TYPE_CUSTOM_BASE = 0x80,
+};
 enum devlink_attr {
   DEVLINK_ATTR_UNSPEC,
   DEVLINK_ATTR_BUS_NAME,
diff --git a/libc/kernel/uapi/linux/dm-ioctl.h b/libc/kernel/uapi/linux/dm-ioctl.h
index f24b441..8d403f4 100644
--- a/libc/kernel/uapi/linux/dm-ioctl.h
+++ b/libc/kernel/uapi/linux/dm-ioctl.h
@@ -73,6 +73,7 @@
   DM_DEV_SET_GEOMETRY_CMD,
   DM_DEV_ARM_POLL_CMD,
   DM_GET_TARGET_VERSION_CMD,
+  DM_MPATH_PROBE_PATHS_CMD,
 };
 #define DM_IOCTL 0xfd
 #define DM_VERSION _IOWR(DM_IOCTL, DM_VERSION_CMD, struct dm_ioctl)
@@ -93,10 +94,11 @@
 #define DM_GET_TARGET_VERSION _IOWR(DM_IOCTL, DM_GET_TARGET_VERSION_CMD, struct dm_ioctl)
 #define DM_TARGET_MSG _IOWR(DM_IOCTL, DM_TARGET_MSG_CMD, struct dm_ioctl)
 #define DM_DEV_SET_GEOMETRY _IOWR(DM_IOCTL, DM_DEV_SET_GEOMETRY_CMD, struct dm_ioctl)
+#define DM_MPATH_PROBE_PATHS _IO(DM_IOCTL, DM_MPATH_PROBE_PATHS_CMD)
 #define DM_VERSION_MAJOR 4
-#define DM_VERSION_MINOR 48
+#define DM_VERSION_MINOR 50
 #define DM_VERSION_PATCHLEVEL 0
-#define DM_VERSION_EXTRA "-ioctl(2023-03-01)"
+#define DM_VERSION_EXTRA "-ioctl(2025-04-28)"
 #define DM_READONLY_FLAG (1 << 0)
 #define DM_SUSPEND_FLAG (1 << 1)
 #define DM_PERSISTENT_DEV_FLAG (1 << 3)
diff --git a/libc/kernel/uapi/linux/dpll.h b/libc/kernel/uapi/linux/dpll.h
index 7d6182b..276add0 100644
--- a/libc/kernel/uapi/linux/dpll.h
+++ b/libc/kernel/uapi/linux/dpll.h
@@ -30,6 +30,18 @@
   __DPLL_LOCK_STATUS_ERROR_MAX,
   DPLL_LOCK_STATUS_ERROR_MAX = (__DPLL_LOCK_STATUS_ERROR_MAX - 1)
 };
+enum dpll_clock_quality_level {
+  DPLL_CLOCK_QUALITY_LEVEL_ITU_OPT1_PRC = 1,
+  DPLL_CLOCK_QUALITY_LEVEL_ITU_OPT1_SSU_A,
+  DPLL_CLOCK_QUALITY_LEVEL_ITU_OPT1_SSU_B,
+  DPLL_CLOCK_QUALITY_LEVEL_ITU_OPT1_EEC1,
+  DPLL_CLOCK_QUALITY_LEVEL_ITU_OPT1_PRTC,
+  DPLL_CLOCK_QUALITY_LEVEL_ITU_OPT1_EPRTC,
+  DPLL_CLOCK_QUALITY_LEVEL_ITU_OPT1_EEEC,
+  DPLL_CLOCK_QUALITY_LEVEL_ITU_OPT1_EPRC,
+  __DPLL_CLOCK_QUALITY_LEVEL_MAX,
+  DPLL_CLOCK_QUALITY_LEVEL_MAX = (__DPLL_CLOCK_QUALITY_LEVEL_MAX - 1)
+};
 #define DPLL_TEMP_DIVIDER 1000
 enum dpll_type {
   DPLL_TYPE_PPS = 1,
@@ -80,6 +92,7 @@
   DPLL_A_TEMP,
   DPLL_A_TYPE,
   DPLL_A_LOCK_STATUS_ERROR,
+  DPLL_A_CLOCK_QUALITY_LEVEL,
   __DPLL_A_MAX,
   DPLL_A_MAX = (__DPLL_A_MAX - 1)
 };
diff --git a/libc/kernel/uapi/linux/elf.h b/libc/kernel/uapi/linux/elf.h
index ea40103..24faa2a 100644
--- a/libc/kernel/uapi/linux/elf.h
+++ b/libc/kernel/uapi/linux/elf.h
@@ -13,6 +13,7 @@
 typedef __u32 Elf32_Off;
 typedef __s32 Elf32_Sword;
 typedef __u32 Elf32_Word;
+typedef __u16 Elf32_Versym;
 typedef __u64 Elf64_Addr;
 typedef __u16 Elf64_Half;
 typedef __s16 Elf64_SHalf;
@@ -21,6 +22,7 @@
 typedef __u32 Elf64_Word;
 typedef __u64 Elf64_Xword;
 typedef __s64 Elf64_Sxword;
+typedef __u16 Elf64_Versym;
 #define PT_NULL 0
 #define PT_LOAD 1
 #define PT_DYNAMIC 2
@@ -77,6 +79,7 @@
 #define DT_VALRNGLO 0x6ffffd00
 #define DT_VALRNGHI 0x6ffffdff
 #define DT_ADDRRNGLO 0x6ffffe00
+#define DT_GNU_HASH 0x6ffffef5
 #define DT_ADDRRNGHI 0x6ffffeff
 #define DT_VERSYM 0x6ffffff0
 #define DT_RELACOUNT 0x6ffffff9
@@ -92,6 +95,7 @@
 #define STB_LOCAL 0
 #define STB_GLOBAL 1
 #define STB_WEAK 2
+#define STN_UNDEF 0
 #define STT_NOTYPE 0
 #define STT_OBJECT 1
 #define STT_FUNC 2
@@ -99,6 +103,8 @@
 #define STT_FILE 4
 #define STT_COMMON 5
 #define STT_TLS 6
+#define VER_FLG_BASE 0x1
+#define VER_FLG_WEAK 0x2
 #define ELF_ST_BIND(x) ((x) >> 4)
 #define ELF_ST_TYPE(x) ((x) & 0xf)
 #define ELF32_ST_BIND(x) ELF_ST_BIND(x)
@@ -233,8 +239,18 @@
 #define SHF_WRITE 0x1
 #define SHF_ALLOC 0x2
 #define SHF_EXECINSTR 0x4
+#define SHF_MERGE 0x10
+#define SHF_STRINGS 0x20
+#define SHF_INFO_LINK 0x40
+#define SHF_LINK_ORDER 0x80
+#define SHF_OS_NONCONFORMING 0x100
+#define SHF_GROUP 0x200
+#define SHF_TLS 0x400
 #define SHF_RELA_LIVEPATCH 0x00100000
 #define SHF_RO_AFTER_INIT 0x00200000
+#define SHF_ORDERED 0x04000000
+#define SHF_EXCLUDE 0x08000000
+#define SHF_MASKOS 0x0ff00000
 #define SHF_MASKPROC 0xf0000000
 #define SHN_UNDEF 0
 #define SHN_LORESERVE 0xff00
@@ -298,84 +314,166 @@
 #ifndef ELF_OSABI
 #define ELF_OSABI ELFOSABI_NONE
 #endif
-#define NT_PRSTATUS 1
-#define NT_PRFPREG 2
-#define NT_PRPSINFO 3
-#define NT_TASKSTRUCT 4
-#define NT_AUXV 6
-#define NT_SIGINFO 0x53494749
-#define NT_FILE 0x46494c45
-#define NT_PRXFPREG 0x46e62b7f
-#define NT_PPC_VMX 0x100
-#define NT_PPC_SPE 0x101
-#define NT_PPC_VSX 0x102
-#define NT_PPC_TAR 0x103
-#define NT_PPC_PPR 0x104
-#define NT_PPC_DSCR 0x105
-#define NT_PPC_EBB 0x106
-#define NT_PPC_PMU 0x107
-#define NT_PPC_TM_CGPR 0x108
-#define NT_PPC_TM_CFPR 0x109
-#define NT_PPC_TM_CVMX 0x10a
-#define NT_PPC_TM_CVSX 0x10b
-#define NT_PPC_TM_SPR 0x10c
-#define NT_PPC_TM_CTAR 0x10d
-#define NT_PPC_TM_CPPR 0x10e
-#define NT_PPC_TM_CDSCR 0x10f
-#define NT_PPC_PKEY 0x110
-#define NT_PPC_DEXCR 0x111
-#define NT_PPC_HASHKEYR 0x112
-#define NT_386_TLS 0x200
-#define NT_386_IOPERM 0x201
-#define NT_X86_XSTATE 0x202
-#define NT_X86_SHSTK 0x204
-#define NT_X86_XSAVE_LAYOUT 0x205
-#define NT_S390_HIGH_GPRS 0x300
-#define NT_S390_TIMER 0x301
-#define NT_S390_TODCMP 0x302
-#define NT_S390_TODPREG 0x303
-#define NT_S390_CTRS 0x304
-#define NT_S390_PREFIX 0x305
-#define NT_S390_LAST_BREAK 0x306
-#define NT_S390_SYSTEM_CALL 0x307
-#define NT_S390_TDB 0x308
-#define NT_S390_VXRS_LOW 0x309
-#define NT_S390_VXRS_HIGH 0x30a
-#define NT_S390_GS_CB 0x30b
-#define NT_S390_GS_BC 0x30c
-#define NT_S390_RI_CB 0x30d
-#define NT_S390_PV_CPU_DATA 0x30e
-#define NT_ARM_VFP 0x400
-#define NT_ARM_TLS 0x401
-#define NT_ARM_HW_BREAK 0x402
-#define NT_ARM_HW_WATCH 0x403
-#define NT_ARM_SYSTEM_CALL 0x404
-#define NT_ARM_SVE 0x405
-#define NT_ARM_PAC_MASK 0x406
-#define NT_ARM_PACA_KEYS 0x407
-#define NT_ARM_PACG_KEYS 0x408
-#define NT_ARM_TAGGED_ADDR_CTRL 0x409
-#define NT_ARM_PAC_ENABLED_KEYS 0x40a
-#define NT_ARM_SSVE 0x40b
-#define NT_ARM_ZA 0x40c
-#define NT_ARM_ZT 0x40d
-#define NT_ARM_FPMR 0x40e
-#define NT_ARM_POE 0x40f
-#define NT_ARC_V2 0x600
-#define NT_VMCOREDD 0x700
-#define NT_MIPS_DSP 0x800
-#define NT_MIPS_FP_MODE 0x801
-#define NT_MIPS_MSA 0x802
-#define NT_RISCV_CSR 0x900
-#define NT_RISCV_VECTOR 0x901
-#define NT_LOONGARCH_CPUCFG 0xa00
-#define NT_LOONGARCH_CSR 0xa01
-#define NT_LOONGARCH_LSX 0xa02
-#define NT_LOONGARCH_LASX 0xa03
-#define NT_LOONGARCH_LBT 0xa04
-#define NT_LOONGARCH_HW_BREAK 0xa05
-#define NT_LOONGARCH_HW_WATCH 0xa06
+#define NN_GNU_PROPERTY_TYPE_0 "GNU"
 #define NT_GNU_PROPERTY_TYPE_0 5
+#define NN_PRSTATUS "CORE"
+#define NT_PRSTATUS 1
+#define NN_PRFPREG "CORE"
+#define NT_PRFPREG 2
+#define NN_PRPSINFO "CORE"
+#define NT_PRPSINFO 3
+#define NN_TASKSTRUCT "CORE"
+#define NT_TASKSTRUCT 4
+#define NN_AUXV "CORE"
+#define NT_AUXV 6
+#define NN_SIGINFO "CORE"
+#define NT_SIGINFO 0x53494749
+#define NN_FILE "CORE"
+#define NT_FILE 0x46494c45
+#define NN_PRXFPREG "LINUX"
+#define NT_PRXFPREG 0x46e62b7f
+#define NN_PPC_VMX "LINUX"
+#define NT_PPC_VMX 0x100
+#define NN_PPC_SPE "LINUX"
+#define NT_PPC_SPE 0x101
+#define NN_PPC_VSX "LINUX"
+#define NT_PPC_VSX 0x102
+#define NN_PPC_TAR "LINUX"
+#define NT_PPC_TAR 0x103
+#define NN_PPC_PPR "LINUX"
+#define NT_PPC_PPR 0x104
+#define NN_PPC_DSCR "LINUX"
+#define NT_PPC_DSCR 0x105
+#define NN_PPC_EBB "LINUX"
+#define NT_PPC_EBB 0x106
+#define NN_PPC_PMU "LINUX"
+#define NT_PPC_PMU 0x107
+#define NN_PPC_TM_CGPR "LINUX"
+#define NT_PPC_TM_CGPR 0x108
+#define NN_PPC_TM_CFPR "LINUX"
+#define NT_PPC_TM_CFPR 0x109
+#define NN_PPC_TM_CVMX "LINUX"
+#define NT_PPC_TM_CVMX 0x10a
+#define NN_PPC_TM_CVSX "LINUX"
+#define NT_PPC_TM_CVSX 0x10b
+#define NN_PPC_TM_SPR "LINUX"
+#define NT_PPC_TM_SPR 0x10c
+#define NN_PPC_TM_CTAR "LINUX"
+#define NT_PPC_TM_CTAR 0x10d
+#define NN_PPC_TM_CPPR "LINUX"
+#define NT_PPC_TM_CPPR 0x10e
+#define NN_PPC_TM_CDSCR "LINUX"
+#define NT_PPC_TM_CDSCR 0x10f
+#define NN_PPC_PKEY "LINUX"
+#define NT_PPC_PKEY 0x110
+#define NN_PPC_DEXCR "LINUX"
+#define NT_PPC_DEXCR 0x111
+#define NN_PPC_HASHKEYR "LINUX"
+#define NT_PPC_HASHKEYR 0x112
+#define NN_386_TLS "LINUX"
+#define NT_386_TLS 0x200
+#define NN_386_IOPERM "LINUX"
+#define NT_386_IOPERM 0x201
+#define NN_X86_XSTATE "LINUX"
+#define NT_X86_XSTATE 0x202
+#define NN_X86_SHSTK "LINUX"
+#define NT_X86_SHSTK 0x204
+#define NN_X86_XSAVE_LAYOUT "LINUX"
+#define NT_X86_XSAVE_LAYOUT 0x205
+#define NN_S390_HIGH_GPRS "LINUX"
+#define NT_S390_HIGH_GPRS 0x300
+#define NN_S390_TIMER "LINUX"
+#define NT_S390_TIMER 0x301
+#define NN_S390_TODCMP "LINUX"
+#define NT_S390_TODCMP 0x302
+#define NN_S390_TODPREG "LINUX"
+#define NT_S390_TODPREG 0x303
+#define NN_S390_CTRS "LINUX"
+#define NT_S390_CTRS 0x304
+#define NN_S390_PREFIX "LINUX"
+#define NT_S390_PREFIX 0x305
+#define NN_S390_LAST_BREAK "LINUX"
+#define NT_S390_LAST_BREAK 0x306
+#define NN_S390_SYSTEM_CALL "LINUX"
+#define NT_S390_SYSTEM_CALL 0x307
+#define NN_S390_TDB "LINUX"
+#define NT_S390_TDB 0x308
+#define NN_S390_VXRS_LOW "LINUX"
+#define NT_S390_VXRS_LOW 0x309
+#define NN_S390_VXRS_HIGH "LINUX"
+#define NT_S390_VXRS_HIGH 0x30a
+#define NN_S390_GS_CB "LINUX"
+#define NT_S390_GS_CB 0x30b
+#define NN_S390_GS_BC "LINUX"
+#define NT_S390_GS_BC 0x30c
+#define NN_S390_RI_CB "LINUX"
+#define NT_S390_RI_CB 0x30d
+#define NN_S390_PV_CPU_DATA "LINUX"
+#define NT_S390_PV_CPU_DATA 0x30e
+#define NN_ARM_VFP "LINUX"
+#define NT_ARM_VFP 0x400
+#define NN_ARM_TLS "LINUX"
+#define NT_ARM_TLS 0x401
+#define NN_ARM_HW_BREAK "LINUX"
+#define NT_ARM_HW_BREAK 0x402
+#define NN_ARM_HW_WATCH "LINUX"
+#define NT_ARM_HW_WATCH 0x403
+#define NN_ARM_SYSTEM_CALL "LINUX"
+#define NT_ARM_SYSTEM_CALL 0x404
+#define NN_ARM_SVE "LINUX"
+#define NT_ARM_SVE 0x405
+#define NN_ARM_PAC_MASK "LINUX"
+#define NT_ARM_PAC_MASK 0x406
+#define NN_ARM_PACA_KEYS "LINUX"
+#define NT_ARM_PACA_KEYS 0x407
+#define NN_ARM_PACG_KEYS "LINUX"
+#define NT_ARM_PACG_KEYS 0x408
+#define NN_ARM_TAGGED_ADDR_CTRL "LINUX"
+#define NT_ARM_TAGGED_ADDR_CTRL 0x409
+#define NN_ARM_PAC_ENABLED_KEYS "LINUX"
+#define NT_ARM_PAC_ENABLED_KEYS 0x40a
+#define NN_ARM_SSVE "LINUX"
+#define NT_ARM_SSVE 0x40b
+#define NN_ARM_ZA "LINUX"
+#define NT_ARM_ZA 0x40c
+#define NN_ARM_ZT "LINUX"
+#define NT_ARM_ZT 0x40d
+#define NN_ARM_FPMR "LINUX"
+#define NT_ARM_FPMR 0x40e
+#define NN_ARM_POE "LINUX"
+#define NT_ARM_POE 0x40f
+#define NN_ARM_GCS "LINUX"
+#define NT_ARM_GCS 0x410
+#define NN_ARC_V2 "LINUX"
+#define NT_ARC_V2 0x600
+#define NN_VMCOREDD "LINUX"
+#define NT_VMCOREDD 0x700
+#define NN_MIPS_DSP "LINUX"
+#define NT_MIPS_DSP 0x800
+#define NN_MIPS_FP_MODE "LINUX"
+#define NT_MIPS_FP_MODE 0x801
+#define NN_MIPS_MSA "LINUX"
+#define NT_MIPS_MSA 0x802
+#define NN_RISCV_CSR "LINUX"
+#define NT_RISCV_CSR 0x900
+#define NN_RISCV_VECTOR "LINUX"
+#define NT_RISCV_VECTOR 0x901
+#define NN_RISCV_TAGGED_ADDR_CTRL "LINUX"
+#define NT_RISCV_TAGGED_ADDR_CTRL 0x902
+#define NN_LOONGARCH_CPUCFG "LINUX"
+#define NT_LOONGARCH_CPUCFG 0xa00
+#define NN_LOONGARCH_CSR "LINUX"
+#define NT_LOONGARCH_CSR 0xa01
+#define NN_LOONGARCH_LSX "LINUX"
+#define NT_LOONGARCH_LSX 0xa02
+#define NN_LOONGARCH_LASX "LINUX"
+#define NT_LOONGARCH_LASX 0xa03
+#define NN_LOONGARCH_LBT "LINUX"
+#define NT_LOONGARCH_LBT 0xa04
+#define NN_LOONGARCH_HW_BREAK "LINUX"
+#define NT_LOONGARCH_HW_BREAK 0xa05
+#define NN_LOONGARCH_HW_WATCH "LINUX"
+#define NT_LOONGARCH_HW_WATCH 0xa06
 typedef struct elf32_note {
   Elf32_Word n_namesz;
   Elf32_Word n_descsz;
@@ -388,4 +486,30 @@
 } Elf64_Nhdr;
 #define GNU_PROPERTY_AARCH64_FEATURE_1_AND 0xc0000000
 #define GNU_PROPERTY_AARCH64_FEATURE_1_BTI (1U << 0)
+typedef struct {
+  Elf32_Half vd_version;
+  Elf32_Half vd_flags;
+  Elf32_Half vd_ndx;
+  Elf32_Half vd_cnt;
+  Elf32_Word vd_hash;
+  Elf32_Word vd_aux;
+  Elf32_Word vd_next;
+} Elf32_Verdef;
+typedef struct {
+  Elf64_Half vd_version;
+  Elf64_Half vd_flags;
+  Elf64_Half vd_ndx;
+  Elf64_Half vd_cnt;
+  Elf64_Word vd_hash;
+  Elf64_Word vd_aux;
+  Elf64_Word vd_next;
+} Elf64_Verdef;
+typedef struct {
+  Elf32_Word vda_name;
+  Elf32_Word vda_next;
+} Elf32_Verdaux;
+typedef struct {
+  Elf64_Word vda_name;
+  Elf64_Word vda_next;
+} Elf64_Verdaux;
 #endif
diff --git a/libc/kernel/uapi/linux/errqueue.h b/libc/kernel/uapi/linux/errqueue.h
index 790ae1e..7678c51 100644
--- a/libc/kernel/uapi/linux/errqueue.h
+++ b/libc/kernel/uapi/linux/errqueue.h
@@ -48,5 +48,6 @@
   SCM_TSTAMP_SND,
   SCM_TSTAMP_SCHED,
   SCM_TSTAMP_ACK,
+  SCM_TSTAMP_COMPLETION,
 };
 #endif
diff --git a/libc/kernel/uapi/linux/ethtool.h b/libc/kernel/uapi/linux/ethtool.h
index 323c4fc..86e527b 100644
--- a/libc/kernel/uapi/linux/ethtool.h
+++ b/libc/kernel/uapi/linux/ethtool.h
@@ -255,6 +255,8 @@
   ETH_SS_STATS_ETH_MAC,
   ETH_SS_STATS_ETH_CTRL,
   ETH_SS_STATS_RMON,
+  ETH_SS_STATS_PHY,
+  ETH_SS_TS_FLAGS,
   ETH_SS_COUNT
 };
 enum ethtool_mac_stats_src {
@@ -806,6 +808,24 @@
   ETHTOOL_LINK_MODE_10baseT1S_Half_BIT = 100,
   ETHTOOL_LINK_MODE_10baseT1S_P2MP_Half_BIT = 101,
   ETHTOOL_LINK_MODE_10baseT1BRR_Full_BIT = 102,
+  ETHTOOL_LINK_MODE_200000baseCR_Full_BIT = 103,
+  ETHTOOL_LINK_MODE_200000baseKR_Full_BIT = 104,
+  ETHTOOL_LINK_MODE_200000baseDR_Full_BIT = 105,
+  ETHTOOL_LINK_MODE_200000baseDR_2_Full_BIT = 106,
+  ETHTOOL_LINK_MODE_200000baseSR_Full_BIT = 107,
+  ETHTOOL_LINK_MODE_200000baseVR_Full_BIT = 108,
+  ETHTOOL_LINK_MODE_400000baseCR2_Full_BIT = 109,
+  ETHTOOL_LINK_MODE_400000baseKR2_Full_BIT = 110,
+  ETHTOOL_LINK_MODE_400000baseDR2_Full_BIT = 111,
+  ETHTOOL_LINK_MODE_400000baseDR2_2_Full_BIT = 112,
+  ETHTOOL_LINK_MODE_400000baseSR2_Full_BIT = 113,
+  ETHTOOL_LINK_MODE_400000baseVR2_Full_BIT = 114,
+  ETHTOOL_LINK_MODE_800000baseCR4_Full_BIT = 115,
+  ETHTOOL_LINK_MODE_800000baseKR4_Full_BIT = 116,
+  ETHTOOL_LINK_MODE_800000baseDR4_Full_BIT = 117,
+  ETHTOOL_LINK_MODE_800000baseDR4_2_Full_BIT = 118,
+  ETHTOOL_LINK_MODE_800000baseSR4_Full_BIT = 119,
+  ETHTOOL_LINK_MODE_800000baseVR4_Full_BIT = 120,
   __ETHTOOL_LINK_MODE_MASK_NBITS
 };
 #define __ETHTOOL_LINK_MODE_LEGACY_MASK(base_name) (1UL << (ETHTOOL_LINK_MODE_ ##base_name ##_BIT))
@@ -935,37 +955,41 @@
 #define WAKE_FILTER (1 << 7)
 #define WOL_MODE_COUNT 8
 #define RXH_XFRM_SYM_XOR (1 << 0)
+#define RXH_XFRM_SYM_OR_XOR (1 << 1)
 #define RXH_XFRM_NO_CHANGE 0xff
-#define TCP_V4_FLOW 0x01
-#define UDP_V4_FLOW 0x02
-#define SCTP_V4_FLOW 0x03
-#define AH_ESP_V4_FLOW 0x04
-#define TCP_V6_FLOW 0x05
-#define UDP_V6_FLOW 0x06
-#define SCTP_V6_FLOW 0x07
-#define AH_ESP_V6_FLOW 0x08
-#define AH_V4_FLOW 0x09
-#define ESP_V4_FLOW 0x0a
-#define AH_V6_FLOW 0x0b
-#define ESP_V6_FLOW 0x0c
-#define IPV4_USER_FLOW 0x0d
-#define IP_USER_FLOW IPV4_USER_FLOW
-#define IPV6_USER_FLOW 0x0e
-#define IPV4_FLOW 0x10
-#define IPV6_FLOW 0x11
-#define ETHER_FLOW 0x12
-#define GTPU_V4_FLOW 0x13
-#define GTPU_V6_FLOW 0x14
-#define GTPC_V4_FLOW 0x15
-#define GTPC_V6_FLOW 0x16
-#define GTPC_TEID_V4_FLOW 0x17
-#define GTPC_TEID_V6_FLOW 0x18
-#define GTPU_EH_V4_FLOW 0x19
-#define GTPU_EH_V6_FLOW 0x1a
-#define GTPU_UL_V4_FLOW 0x1b
-#define GTPU_UL_V6_FLOW 0x1c
-#define GTPU_DL_V4_FLOW 0x1d
-#define GTPU_DL_V6_FLOW 0x1e
+enum {
+  TCP_V4_FLOW = 0x01,
+  UDP_V4_FLOW = 0x02,
+  SCTP_V4_FLOW = 0x03,
+  AH_ESP_V4_FLOW = 0x04,
+  TCP_V6_FLOW = 0x05,
+  UDP_V6_FLOW = 0x06,
+  SCTP_V6_FLOW = 0x07,
+  AH_ESP_V6_FLOW = 0x08,
+  AH_V4_FLOW = 0x09,
+  ESP_V4_FLOW = 0x0a,
+  AH_V6_FLOW = 0x0b,
+  ESP_V6_FLOW = 0x0c,
+  IPV4_USER_FLOW = 0x0d,
+  IP_USER_FLOW = IPV4_USER_FLOW,
+  IPV6_USER_FLOW = 0x0e,
+  IPV4_FLOW = 0x10,
+  IPV6_FLOW = 0x11,
+  ETHER_FLOW = 0x12,
+  GTPU_V4_FLOW = 0x13,
+  GTPU_V6_FLOW = 0x14,
+  GTPC_V4_FLOW = 0x15,
+  GTPC_V6_FLOW = 0x16,
+  GTPC_TEID_V4_FLOW = 0x17,
+  GTPC_TEID_V6_FLOW = 0x18,
+  GTPU_EH_V4_FLOW = 0x19,
+  GTPU_EH_V6_FLOW = 0x1a,
+  GTPU_UL_V4_FLOW = 0x1b,
+  GTPU_UL_V6_FLOW = 0x1c,
+  GTPU_DL_V4_FLOW = 0x1d,
+  GTPU_DL_V6_FLOW = 0x1e,
+  __FLOW_TYPE_COUNT,
+};
 #define FLOW_EXT 0x80000000
 #define FLOW_MAC_EXT 0x40000000
 #define FLOW_RSS 0x20000000
diff --git a/libc/kernel/uapi/linux/ethtool_netlink.h b/libc/kernel/uapi/linux/ethtool_netlink.h
index 7120c03..a0c481f 100644
--- a/libc/kernel/uapi/linux/ethtool_netlink.h
+++ b/libc/kernel/uapi/linux/ethtool_netlink.h
@@ -7,405 +7,9 @@
 #ifndef _UAPI_LINUX_ETHTOOL_NETLINK_H_
 #define _UAPI_LINUX_ETHTOOL_NETLINK_H_
 #include <linux/ethtool.h>
-enum {
-  ETHTOOL_MSG_USER_NONE,
-  ETHTOOL_MSG_STRSET_GET,
-  ETHTOOL_MSG_LINKINFO_GET,
-  ETHTOOL_MSG_LINKINFO_SET,
-  ETHTOOL_MSG_LINKMODES_GET,
-  ETHTOOL_MSG_LINKMODES_SET,
-  ETHTOOL_MSG_LINKSTATE_GET,
-  ETHTOOL_MSG_DEBUG_GET,
-  ETHTOOL_MSG_DEBUG_SET,
-  ETHTOOL_MSG_WOL_GET,
-  ETHTOOL_MSG_WOL_SET,
-  ETHTOOL_MSG_FEATURES_GET,
-  ETHTOOL_MSG_FEATURES_SET,
-  ETHTOOL_MSG_PRIVFLAGS_GET,
-  ETHTOOL_MSG_PRIVFLAGS_SET,
-  ETHTOOL_MSG_RINGS_GET,
-  ETHTOOL_MSG_RINGS_SET,
-  ETHTOOL_MSG_CHANNELS_GET,
-  ETHTOOL_MSG_CHANNELS_SET,
-  ETHTOOL_MSG_COALESCE_GET,
-  ETHTOOL_MSG_COALESCE_SET,
-  ETHTOOL_MSG_PAUSE_GET,
-  ETHTOOL_MSG_PAUSE_SET,
-  ETHTOOL_MSG_EEE_GET,
-  ETHTOOL_MSG_EEE_SET,
-  ETHTOOL_MSG_TSINFO_GET,
-  ETHTOOL_MSG_CABLE_TEST_ACT,
-  ETHTOOL_MSG_CABLE_TEST_TDR_ACT,
-  ETHTOOL_MSG_TUNNEL_INFO_GET,
-  ETHTOOL_MSG_FEC_GET,
-  ETHTOOL_MSG_FEC_SET,
-  ETHTOOL_MSG_MODULE_EEPROM_GET,
-  ETHTOOL_MSG_STATS_GET,
-  ETHTOOL_MSG_PHC_VCLOCKS_GET,
-  ETHTOOL_MSG_MODULE_GET,
-  ETHTOOL_MSG_MODULE_SET,
-  ETHTOOL_MSG_PSE_GET,
-  ETHTOOL_MSG_PSE_SET,
-  ETHTOOL_MSG_RSS_GET,
-  ETHTOOL_MSG_PLCA_GET_CFG,
-  ETHTOOL_MSG_PLCA_SET_CFG,
-  ETHTOOL_MSG_PLCA_GET_STATUS,
-  ETHTOOL_MSG_MM_GET,
-  ETHTOOL_MSG_MM_SET,
-  ETHTOOL_MSG_MODULE_FW_FLASH_ACT,
-  ETHTOOL_MSG_PHY_GET,
-  __ETHTOOL_MSG_USER_CNT,
-  ETHTOOL_MSG_USER_MAX = __ETHTOOL_MSG_USER_CNT - 1
-};
-enum {
-  ETHTOOL_MSG_KERNEL_NONE,
-  ETHTOOL_MSG_STRSET_GET_REPLY,
-  ETHTOOL_MSG_LINKINFO_GET_REPLY,
-  ETHTOOL_MSG_LINKINFO_NTF,
-  ETHTOOL_MSG_LINKMODES_GET_REPLY,
-  ETHTOOL_MSG_LINKMODES_NTF,
-  ETHTOOL_MSG_LINKSTATE_GET_REPLY,
-  ETHTOOL_MSG_DEBUG_GET_REPLY,
-  ETHTOOL_MSG_DEBUG_NTF,
-  ETHTOOL_MSG_WOL_GET_REPLY,
-  ETHTOOL_MSG_WOL_NTF,
-  ETHTOOL_MSG_FEATURES_GET_REPLY,
-  ETHTOOL_MSG_FEATURES_SET_REPLY,
-  ETHTOOL_MSG_FEATURES_NTF,
-  ETHTOOL_MSG_PRIVFLAGS_GET_REPLY,
-  ETHTOOL_MSG_PRIVFLAGS_NTF,
-  ETHTOOL_MSG_RINGS_GET_REPLY,
-  ETHTOOL_MSG_RINGS_NTF,
-  ETHTOOL_MSG_CHANNELS_GET_REPLY,
-  ETHTOOL_MSG_CHANNELS_NTF,
-  ETHTOOL_MSG_COALESCE_GET_REPLY,
-  ETHTOOL_MSG_COALESCE_NTF,
-  ETHTOOL_MSG_PAUSE_GET_REPLY,
-  ETHTOOL_MSG_PAUSE_NTF,
-  ETHTOOL_MSG_EEE_GET_REPLY,
-  ETHTOOL_MSG_EEE_NTF,
-  ETHTOOL_MSG_TSINFO_GET_REPLY,
-  ETHTOOL_MSG_CABLE_TEST_NTF,
-  ETHTOOL_MSG_CABLE_TEST_TDR_NTF,
-  ETHTOOL_MSG_TUNNEL_INFO_GET_REPLY,
-  ETHTOOL_MSG_FEC_GET_REPLY,
-  ETHTOOL_MSG_FEC_NTF,
-  ETHTOOL_MSG_MODULE_EEPROM_GET_REPLY,
-  ETHTOOL_MSG_STATS_GET_REPLY,
-  ETHTOOL_MSG_PHC_VCLOCKS_GET_REPLY,
-  ETHTOOL_MSG_MODULE_GET_REPLY,
-  ETHTOOL_MSG_MODULE_NTF,
-  ETHTOOL_MSG_PSE_GET_REPLY,
-  ETHTOOL_MSG_RSS_GET_REPLY,
-  ETHTOOL_MSG_PLCA_GET_CFG_REPLY,
-  ETHTOOL_MSG_PLCA_GET_STATUS_REPLY,
-  ETHTOOL_MSG_PLCA_NTF,
-  ETHTOOL_MSG_MM_GET_REPLY,
-  ETHTOOL_MSG_MM_NTF,
-  ETHTOOL_MSG_MODULE_FW_FLASH_NTF,
-  ETHTOOL_MSG_PHY_GET_REPLY,
-  ETHTOOL_MSG_PHY_NTF,
-  __ETHTOOL_MSG_KERNEL_CNT,
-  ETHTOOL_MSG_KERNEL_MAX = __ETHTOOL_MSG_KERNEL_CNT - 1
-};
-enum ethtool_header_flags {
-  ETHTOOL_FLAG_COMPACT_BITSETS = 1 << 0,
-  ETHTOOL_FLAG_OMIT_REPLY = 1 << 1,
-  ETHTOOL_FLAG_STATS = 1 << 2,
-};
+#include <linux/ethtool_netlink_generated.h>
 #define ETHTOOL_FLAG_ALL (ETHTOOL_FLAG_COMPACT_BITSETS | ETHTOOL_FLAG_OMIT_REPLY | ETHTOOL_FLAG_STATS)
 enum {
-  ETHTOOL_A_HEADER_UNSPEC,
-  ETHTOOL_A_HEADER_DEV_INDEX,
-  ETHTOOL_A_HEADER_DEV_NAME,
-  ETHTOOL_A_HEADER_FLAGS,
-  ETHTOOL_A_HEADER_PHY_INDEX,
-  __ETHTOOL_A_HEADER_CNT,
-  ETHTOOL_A_HEADER_MAX = __ETHTOOL_A_HEADER_CNT - 1
-};
-enum {
-  ETHTOOL_A_BITSET_BIT_UNSPEC,
-  ETHTOOL_A_BITSET_BIT_INDEX,
-  ETHTOOL_A_BITSET_BIT_NAME,
-  ETHTOOL_A_BITSET_BIT_VALUE,
-  __ETHTOOL_A_BITSET_BIT_CNT,
-  ETHTOOL_A_BITSET_BIT_MAX = __ETHTOOL_A_BITSET_BIT_CNT - 1
-};
-enum {
-  ETHTOOL_A_BITSET_BITS_UNSPEC,
-  ETHTOOL_A_BITSET_BITS_BIT,
-  __ETHTOOL_A_BITSET_BITS_CNT,
-  ETHTOOL_A_BITSET_BITS_MAX = __ETHTOOL_A_BITSET_BITS_CNT - 1
-};
-enum {
-  ETHTOOL_A_BITSET_UNSPEC,
-  ETHTOOL_A_BITSET_NOMASK,
-  ETHTOOL_A_BITSET_SIZE,
-  ETHTOOL_A_BITSET_BITS,
-  ETHTOOL_A_BITSET_VALUE,
-  ETHTOOL_A_BITSET_MASK,
-  __ETHTOOL_A_BITSET_CNT,
-  ETHTOOL_A_BITSET_MAX = __ETHTOOL_A_BITSET_CNT - 1
-};
-enum {
-  ETHTOOL_A_STRING_UNSPEC,
-  ETHTOOL_A_STRING_INDEX,
-  ETHTOOL_A_STRING_VALUE,
-  __ETHTOOL_A_STRING_CNT,
-  ETHTOOL_A_STRING_MAX = __ETHTOOL_A_STRING_CNT - 1
-};
-enum {
-  ETHTOOL_A_STRINGS_UNSPEC,
-  ETHTOOL_A_STRINGS_STRING,
-  __ETHTOOL_A_STRINGS_CNT,
-  ETHTOOL_A_STRINGS_MAX = __ETHTOOL_A_STRINGS_CNT - 1
-};
-enum {
-  ETHTOOL_A_STRINGSET_UNSPEC,
-  ETHTOOL_A_STRINGSET_ID,
-  ETHTOOL_A_STRINGSET_COUNT,
-  ETHTOOL_A_STRINGSET_STRINGS,
-  __ETHTOOL_A_STRINGSET_CNT,
-  ETHTOOL_A_STRINGSET_MAX = __ETHTOOL_A_STRINGSET_CNT - 1
-};
-enum {
-  ETHTOOL_A_STRINGSETS_UNSPEC,
-  ETHTOOL_A_STRINGSETS_STRINGSET,
-  __ETHTOOL_A_STRINGSETS_CNT,
-  ETHTOOL_A_STRINGSETS_MAX = __ETHTOOL_A_STRINGSETS_CNT - 1
-};
-enum {
-  ETHTOOL_A_STRSET_UNSPEC,
-  ETHTOOL_A_STRSET_HEADER,
-  ETHTOOL_A_STRSET_STRINGSETS,
-  ETHTOOL_A_STRSET_COUNTS_ONLY,
-  __ETHTOOL_A_STRSET_CNT,
-  ETHTOOL_A_STRSET_MAX = __ETHTOOL_A_STRSET_CNT - 1
-};
-enum {
-  ETHTOOL_A_LINKINFO_UNSPEC,
-  ETHTOOL_A_LINKINFO_HEADER,
-  ETHTOOL_A_LINKINFO_PORT,
-  ETHTOOL_A_LINKINFO_PHYADDR,
-  ETHTOOL_A_LINKINFO_TP_MDIX,
-  ETHTOOL_A_LINKINFO_TP_MDIX_CTRL,
-  ETHTOOL_A_LINKINFO_TRANSCEIVER,
-  __ETHTOOL_A_LINKINFO_CNT,
-  ETHTOOL_A_LINKINFO_MAX = __ETHTOOL_A_LINKINFO_CNT - 1
-};
-enum {
-  ETHTOOL_A_LINKMODES_UNSPEC,
-  ETHTOOL_A_LINKMODES_HEADER,
-  ETHTOOL_A_LINKMODES_AUTONEG,
-  ETHTOOL_A_LINKMODES_OURS,
-  ETHTOOL_A_LINKMODES_PEER,
-  ETHTOOL_A_LINKMODES_SPEED,
-  ETHTOOL_A_LINKMODES_DUPLEX,
-  ETHTOOL_A_LINKMODES_MASTER_SLAVE_CFG,
-  ETHTOOL_A_LINKMODES_MASTER_SLAVE_STATE,
-  ETHTOOL_A_LINKMODES_LANES,
-  ETHTOOL_A_LINKMODES_RATE_MATCHING,
-  __ETHTOOL_A_LINKMODES_CNT,
-  ETHTOOL_A_LINKMODES_MAX = __ETHTOOL_A_LINKMODES_CNT - 1
-};
-enum {
-  ETHTOOL_A_LINKSTATE_UNSPEC,
-  ETHTOOL_A_LINKSTATE_HEADER,
-  ETHTOOL_A_LINKSTATE_LINK,
-  ETHTOOL_A_LINKSTATE_SQI,
-  ETHTOOL_A_LINKSTATE_SQI_MAX,
-  ETHTOOL_A_LINKSTATE_EXT_STATE,
-  ETHTOOL_A_LINKSTATE_EXT_SUBSTATE,
-  ETHTOOL_A_LINKSTATE_EXT_DOWN_CNT,
-  __ETHTOOL_A_LINKSTATE_CNT,
-  ETHTOOL_A_LINKSTATE_MAX = __ETHTOOL_A_LINKSTATE_CNT - 1
-};
-enum {
-  ETHTOOL_A_DEBUG_UNSPEC,
-  ETHTOOL_A_DEBUG_HEADER,
-  ETHTOOL_A_DEBUG_MSGMASK,
-  __ETHTOOL_A_DEBUG_CNT,
-  ETHTOOL_A_DEBUG_MAX = __ETHTOOL_A_DEBUG_CNT - 1
-};
-enum {
-  ETHTOOL_A_WOL_UNSPEC,
-  ETHTOOL_A_WOL_HEADER,
-  ETHTOOL_A_WOL_MODES,
-  ETHTOOL_A_WOL_SOPASS,
-  __ETHTOOL_A_WOL_CNT,
-  ETHTOOL_A_WOL_MAX = __ETHTOOL_A_WOL_CNT - 1
-};
-enum {
-  ETHTOOL_A_FEATURES_UNSPEC,
-  ETHTOOL_A_FEATURES_HEADER,
-  ETHTOOL_A_FEATURES_HW,
-  ETHTOOL_A_FEATURES_WANTED,
-  ETHTOOL_A_FEATURES_ACTIVE,
-  ETHTOOL_A_FEATURES_NOCHANGE,
-  __ETHTOOL_A_FEATURES_CNT,
-  ETHTOOL_A_FEATURES_MAX = __ETHTOOL_A_FEATURES_CNT - 1
-};
-enum {
-  ETHTOOL_A_PRIVFLAGS_UNSPEC,
-  ETHTOOL_A_PRIVFLAGS_HEADER,
-  ETHTOOL_A_PRIVFLAGS_FLAGS,
-  __ETHTOOL_A_PRIVFLAGS_CNT,
-  ETHTOOL_A_PRIVFLAGS_MAX = __ETHTOOL_A_PRIVFLAGS_CNT - 1
-};
-enum {
-  ETHTOOL_TCP_DATA_SPLIT_UNKNOWN = 0,
-  ETHTOOL_TCP_DATA_SPLIT_DISABLED,
-  ETHTOOL_TCP_DATA_SPLIT_ENABLED,
-};
-enum {
-  ETHTOOL_A_RINGS_UNSPEC,
-  ETHTOOL_A_RINGS_HEADER,
-  ETHTOOL_A_RINGS_RX_MAX,
-  ETHTOOL_A_RINGS_RX_MINI_MAX,
-  ETHTOOL_A_RINGS_RX_JUMBO_MAX,
-  ETHTOOL_A_RINGS_TX_MAX,
-  ETHTOOL_A_RINGS_RX,
-  ETHTOOL_A_RINGS_RX_MINI,
-  ETHTOOL_A_RINGS_RX_JUMBO,
-  ETHTOOL_A_RINGS_TX,
-  ETHTOOL_A_RINGS_RX_BUF_LEN,
-  ETHTOOL_A_RINGS_TCP_DATA_SPLIT,
-  ETHTOOL_A_RINGS_CQE_SIZE,
-  ETHTOOL_A_RINGS_TX_PUSH,
-  ETHTOOL_A_RINGS_RX_PUSH,
-  ETHTOOL_A_RINGS_TX_PUSH_BUF_LEN,
-  ETHTOOL_A_RINGS_TX_PUSH_BUF_LEN_MAX,
-  __ETHTOOL_A_RINGS_CNT,
-  ETHTOOL_A_RINGS_MAX = (__ETHTOOL_A_RINGS_CNT - 1)
-};
-enum {
-  ETHTOOL_A_CHANNELS_UNSPEC,
-  ETHTOOL_A_CHANNELS_HEADER,
-  ETHTOOL_A_CHANNELS_RX_MAX,
-  ETHTOOL_A_CHANNELS_TX_MAX,
-  ETHTOOL_A_CHANNELS_OTHER_MAX,
-  ETHTOOL_A_CHANNELS_COMBINED_MAX,
-  ETHTOOL_A_CHANNELS_RX_COUNT,
-  ETHTOOL_A_CHANNELS_TX_COUNT,
-  ETHTOOL_A_CHANNELS_OTHER_COUNT,
-  ETHTOOL_A_CHANNELS_COMBINED_COUNT,
-  __ETHTOOL_A_CHANNELS_CNT,
-  ETHTOOL_A_CHANNELS_MAX = (__ETHTOOL_A_CHANNELS_CNT - 1)
-};
-enum {
-  ETHTOOL_A_COALESCE_UNSPEC,
-  ETHTOOL_A_COALESCE_HEADER,
-  ETHTOOL_A_COALESCE_RX_USECS,
-  ETHTOOL_A_COALESCE_RX_MAX_FRAMES,
-  ETHTOOL_A_COALESCE_RX_USECS_IRQ,
-  ETHTOOL_A_COALESCE_RX_MAX_FRAMES_IRQ,
-  ETHTOOL_A_COALESCE_TX_USECS,
-  ETHTOOL_A_COALESCE_TX_MAX_FRAMES,
-  ETHTOOL_A_COALESCE_TX_USECS_IRQ,
-  ETHTOOL_A_COALESCE_TX_MAX_FRAMES_IRQ,
-  ETHTOOL_A_COALESCE_STATS_BLOCK_USECS,
-  ETHTOOL_A_COALESCE_USE_ADAPTIVE_RX,
-  ETHTOOL_A_COALESCE_USE_ADAPTIVE_TX,
-  ETHTOOL_A_COALESCE_PKT_RATE_LOW,
-  ETHTOOL_A_COALESCE_RX_USECS_LOW,
-  ETHTOOL_A_COALESCE_RX_MAX_FRAMES_LOW,
-  ETHTOOL_A_COALESCE_TX_USECS_LOW,
-  ETHTOOL_A_COALESCE_TX_MAX_FRAMES_LOW,
-  ETHTOOL_A_COALESCE_PKT_RATE_HIGH,
-  ETHTOOL_A_COALESCE_RX_USECS_HIGH,
-  ETHTOOL_A_COALESCE_RX_MAX_FRAMES_HIGH,
-  ETHTOOL_A_COALESCE_TX_USECS_HIGH,
-  ETHTOOL_A_COALESCE_TX_MAX_FRAMES_HIGH,
-  ETHTOOL_A_COALESCE_RATE_SAMPLE_INTERVAL,
-  ETHTOOL_A_COALESCE_USE_CQE_MODE_TX,
-  ETHTOOL_A_COALESCE_USE_CQE_MODE_RX,
-  ETHTOOL_A_COALESCE_TX_AGGR_MAX_BYTES,
-  ETHTOOL_A_COALESCE_TX_AGGR_MAX_FRAMES,
-  ETHTOOL_A_COALESCE_TX_AGGR_TIME_USECS,
-  ETHTOOL_A_COALESCE_RX_PROFILE,
-  ETHTOOL_A_COALESCE_TX_PROFILE,
-  __ETHTOOL_A_COALESCE_CNT,
-  ETHTOOL_A_COALESCE_MAX = (__ETHTOOL_A_COALESCE_CNT - 1)
-};
-enum {
-  ETHTOOL_A_PROFILE_UNSPEC,
-  ETHTOOL_A_PROFILE_IRQ_MODERATION,
-  __ETHTOOL_A_PROFILE_CNT,
-  ETHTOOL_A_PROFILE_MAX = (__ETHTOOL_A_PROFILE_CNT - 1)
-};
-enum {
-  ETHTOOL_A_IRQ_MODERATION_UNSPEC,
-  ETHTOOL_A_IRQ_MODERATION_USEC,
-  ETHTOOL_A_IRQ_MODERATION_PKTS,
-  ETHTOOL_A_IRQ_MODERATION_COMPS,
-  __ETHTOOL_A_IRQ_MODERATION_CNT,
-  ETHTOOL_A_IRQ_MODERATION_MAX = (__ETHTOOL_A_IRQ_MODERATION_CNT - 1)
-};
-enum {
-  ETHTOOL_A_PAUSE_UNSPEC,
-  ETHTOOL_A_PAUSE_HEADER,
-  ETHTOOL_A_PAUSE_AUTONEG,
-  ETHTOOL_A_PAUSE_RX,
-  ETHTOOL_A_PAUSE_TX,
-  ETHTOOL_A_PAUSE_STATS,
-  ETHTOOL_A_PAUSE_STATS_SRC,
-  __ETHTOOL_A_PAUSE_CNT,
-  ETHTOOL_A_PAUSE_MAX = (__ETHTOOL_A_PAUSE_CNT - 1)
-};
-enum {
-  ETHTOOL_A_PAUSE_STAT_UNSPEC,
-  ETHTOOL_A_PAUSE_STAT_PAD,
-  ETHTOOL_A_PAUSE_STAT_TX_FRAMES,
-  ETHTOOL_A_PAUSE_STAT_RX_FRAMES,
-  __ETHTOOL_A_PAUSE_STAT_CNT,
-  ETHTOOL_A_PAUSE_STAT_MAX = (__ETHTOOL_A_PAUSE_STAT_CNT - 1)
-};
-enum {
-  ETHTOOL_A_EEE_UNSPEC,
-  ETHTOOL_A_EEE_HEADER,
-  ETHTOOL_A_EEE_MODES_OURS,
-  ETHTOOL_A_EEE_MODES_PEER,
-  ETHTOOL_A_EEE_ACTIVE,
-  ETHTOOL_A_EEE_ENABLED,
-  ETHTOOL_A_EEE_TX_LPI_ENABLED,
-  ETHTOOL_A_EEE_TX_LPI_TIMER,
-  __ETHTOOL_A_EEE_CNT,
-  ETHTOOL_A_EEE_MAX = (__ETHTOOL_A_EEE_CNT - 1)
-};
-enum {
-  ETHTOOL_A_TSINFO_UNSPEC,
-  ETHTOOL_A_TSINFO_HEADER,
-  ETHTOOL_A_TSINFO_TIMESTAMPING,
-  ETHTOOL_A_TSINFO_TX_TYPES,
-  ETHTOOL_A_TSINFO_RX_FILTERS,
-  ETHTOOL_A_TSINFO_PHC_INDEX,
-  ETHTOOL_A_TSINFO_STATS,
-  __ETHTOOL_A_TSINFO_CNT,
-  ETHTOOL_A_TSINFO_MAX = (__ETHTOOL_A_TSINFO_CNT - 1)
-};
-enum {
-  ETHTOOL_A_TS_STAT_UNSPEC,
-  ETHTOOL_A_TS_STAT_TX_PKTS,
-  ETHTOOL_A_TS_STAT_TX_LOST,
-  ETHTOOL_A_TS_STAT_TX_ERR,
-  __ETHTOOL_A_TS_STAT_CNT,
-  ETHTOOL_A_TS_STAT_MAX = (__ETHTOOL_A_TS_STAT_CNT - 1)
-};
-enum {
-  ETHTOOL_A_PHC_VCLOCKS_UNSPEC,
-  ETHTOOL_A_PHC_VCLOCKS_HEADER,
-  ETHTOOL_A_PHC_VCLOCKS_NUM,
-  ETHTOOL_A_PHC_VCLOCKS_INDEX,
-  __ETHTOOL_A_PHC_VCLOCKS_CNT,
-  ETHTOOL_A_PHC_VCLOCKS_MAX = (__ETHTOOL_A_PHC_VCLOCKS_CNT - 1)
-};
-enum {
-  ETHTOOL_A_CABLE_TEST_UNSPEC,
-  ETHTOOL_A_CABLE_TEST_HEADER,
-  __ETHTOOL_A_CABLE_TEST_CNT,
-  ETHTOOL_A_CABLE_TEST_MAX = __ETHTOOL_A_CABLE_TEST_CNT - 1
-};
-enum {
   ETHTOOL_A_CABLE_RESULT_CODE_UNSPEC,
   ETHTOOL_A_CABLE_RESULT_CODE_OK,
   ETHTOOL_A_CABLE_RESULT_CODE_OPEN,
@@ -427,58 +31,11 @@
   ETHTOOL_A_CABLE_INF_SRC_ALCD,
 };
 enum {
-  ETHTOOL_A_CABLE_RESULT_UNSPEC,
-  ETHTOOL_A_CABLE_RESULT_PAIR,
-  ETHTOOL_A_CABLE_RESULT_CODE,
-  ETHTOOL_A_CABLE_RESULT_SRC,
-  __ETHTOOL_A_CABLE_RESULT_CNT,
-  ETHTOOL_A_CABLE_RESULT_MAX = (__ETHTOOL_A_CABLE_RESULT_CNT - 1)
-};
-enum {
-  ETHTOOL_A_CABLE_FAULT_LENGTH_UNSPEC,
-  ETHTOOL_A_CABLE_FAULT_LENGTH_PAIR,
-  ETHTOOL_A_CABLE_FAULT_LENGTH_CM,
-  ETHTOOL_A_CABLE_FAULT_LENGTH_SRC,
-  __ETHTOOL_A_CABLE_FAULT_LENGTH_CNT,
-  ETHTOOL_A_CABLE_FAULT_LENGTH_MAX = (__ETHTOOL_A_CABLE_FAULT_LENGTH_CNT - 1)
-};
-enum {
   ETHTOOL_A_CABLE_TEST_NTF_STATUS_UNSPEC,
   ETHTOOL_A_CABLE_TEST_NTF_STATUS_STARTED,
   ETHTOOL_A_CABLE_TEST_NTF_STATUS_COMPLETED
 };
 enum {
-  ETHTOOL_A_CABLE_NEST_UNSPEC,
-  ETHTOOL_A_CABLE_NEST_RESULT,
-  ETHTOOL_A_CABLE_NEST_FAULT_LENGTH,
-  __ETHTOOL_A_CABLE_NEST_CNT,
-  ETHTOOL_A_CABLE_NEST_MAX = (__ETHTOOL_A_CABLE_NEST_CNT - 1)
-};
-enum {
-  ETHTOOL_A_CABLE_TEST_NTF_UNSPEC,
-  ETHTOOL_A_CABLE_TEST_NTF_HEADER,
-  ETHTOOL_A_CABLE_TEST_NTF_STATUS,
-  ETHTOOL_A_CABLE_TEST_NTF_NEST,
-  __ETHTOOL_A_CABLE_TEST_NTF_CNT,
-  ETHTOOL_A_CABLE_TEST_NTF_MAX = (__ETHTOOL_A_CABLE_TEST_NTF_CNT - 1)
-};
-enum {
-  ETHTOOL_A_CABLE_TEST_TDR_CFG_UNSPEC,
-  ETHTOOL_A_CABLE_TEST_TDR_CFG_FIRST,
-  ETHTOOL_A_CABLE_TEST_TDR_CFG_LAST,
-  ETHTOOL_A_CABLE_TEST_TDR_CFG_STEP,
-  ETHTOOL_A_CABLE_TEST_TDR_CFG_PAIR,
-  __ETHTOOL_A_CABLE_TEST_TDR_CFG_CNT,
-  ETHTOOL_A_CABLE_TEST_TDR_CFG_MAX = __ETHTOOL_A_CABLE_TEST_TDR_CFG_CNT - 1
-};
-enum {
-  ETHTOOL_A_CABLE_TEST_TDR_UNSPEC,
-  ETHTOOL_A_CABLE_TEST_TDR_HEADER,
-  ETHTOOL_A_CABLE_TEST_TDR_CFG,
-  __ETHTOOL_A_CABLE_TEST_TDR_CNT,
-  ETHTOOL_A_CABLE_TEST_TDR_MAX = __ETHTOOL_A_CABLE_TEST_TDR_CNT - 1
-};
-enum {
   ETHTOOL_A_CABLE_AMPLITUDE_UNSPEC,
   ETHTOOL_A_CABLE_AMPLITUDE_PAIR,
   ETHTOOL_A_CABLE_AMPLITUDE_mV,
@@ -508,110 +65,14 @@
   ETHTOOL_A_CABLE_TDR_NEST_MAX = (__ETHTOOL_A_CABLE_TDR_NEST_CNT - 1)
 };
 enum {
-  ETHTOOL_A_CABLE_TEST_TDR_NTF_UNSPEC,
-  ETHTOOL_A_CABLE_TEST_TDR_NTF_HEADER,
-  ETHTOOL_A_CABLE_TEST_TDR_NTF_STATUS,
-  ETHTOOL_A_CABLE_TEST_TDR_NTF_NEST,
-  __ETHTOOL_A_CABLE_TEST_TDR_NTF_CNT,
-  ETHTOOL_A_CABLE_TEST_TDR_NTF_MAX = __ETHTOOL_A_CABLE_TEST_TDR_NTF_CNT - 1
-};
-enum {
-  ETHTOOL_UDP_TUNNEL_TYPE_VXLAN,
-  ETHTOOL_UDP_TUNNEL_TYPE_GENEVE,
-  ETHTOOL_UDP_TUNNEL_TYPE_VXLAN_GPE,
-  __ETHTOOL_UDP_TUNNEL_TYPE_CNT
-};
-enum {
-  ETHTOOL_A_TUNNEL_UDP_ENTRY_UNSPEC,
-  ETHTOOL_A_TUNNEL_UDP_ENTRY_PORT,
-  ETHTOOL_A_TUNNEL_UDP_ENTRY_TYPE,
-  __ETHTOOL_A_TUNNEL_UDP_ENTRY_CNT,
-  ETHTOOL_A_TUNNEL_UDP_ENTRY_MAX = (__ETHTOOL_A_TUNNEL_UDP_ENTRY_CNT - 1)
-};
-enum {
-  ETHTOOL_A_TUNNEL_UDP_TABLE_UNSPEC,
-  ETHTOOL_A_TUNNEL_UDP_TABLE_SIZE,
-  ETHTOOL_A_TUNNEL_UDP_TABLE_TYPES,
-  ETHTOOL_A_TUNNEL_UDP_TABLE_ENTRY,
-  __ETHTOOL_A_TUNNEL_UDP_TABLE_CNT,
-  ETHTOOL_A_TUNNEL_UDP_TABLE_MAX = (__ETHTOOL_A_TUNNEL_UDP_TABLE_CNT - 1)
-};
-enum {
-  ETHTOOL_A_TUNNEL_UDP_UNSPEC,
-  ETHTOOL_A_TUNNEL_UDP_TABLE,
-  __ETHTOOL_A_TUNNEL_UDP_CNT,
-  ETHTOOL_A_TUNNEL_UDP_MAX = (__ETHTOOL_A_TUNNEL_UDP_CNT - 1)
-};
-enum {
-  ETHTOOL_A_TUNNEL_INFO_UNSPEC,
-  ETHTOOL_A_TUNNEL_INFO_HEADER,
-  ETHTOOL_A_TUNNEL_INFO_UDP_PORTS,
-  __ETHTOOL_A_TUNNEL_INFO_CNT,
-  ETHTOOL_A_TUNNEL_INFO_MAX = (__ETHTOOL_A_TUNNEL_INFO_CNT - 1)
-};
-enum {
-  ETHTOOL_A_FEC_UNSPEC,
-  ETHTOOL_A_FEC_HEADER,
-  ETHTOOL_A_FEC_MODES,
-  ETHTOOL_A_FEC_AUTO,
-  ETHTOOL_A_FEC_ACTIVE,
-  ETHTOOL_A_FEC_STATS,
-  __ETHTOOL_A_FEC_CNT,
-  ETHTOOL_A_FEC_MAX = (__ETHTOOL_A_FEC_CNT - 1)
-};
-enum {
-  ETHTOOL_A_FEC_STAT_UNSPEC,
-  ETHTOOL_A_FEC_STAT_PAD,
-  ETHTOOL_A_FEC_STAT_CORRECTED,
-  ETHTOOL_A_FEC_STAT_UNCORR,
-  ETHTOOL_A_FEC_STAT_CORR_BITS,
-  __ETHTOOL_A_FEC_STAT_CNT,
-  ETHTOOL_A_FEC_STAT_MAX = (__ETHTOOL_A_FEC_STAT_CNT - 1)
-};
-enum {
-  ETHTOOL_A_MODULE_EEPROM_UNSPEC,
-  ETHTOOL_A_MODULE_EEPROM_HEADER,
-  ETHTOOL_A_MODULE_EEPROM_OFFSET,
-  ETHTOOL_A_MODULE_EEPROM_LENGTH,
-  ETHTOOL_A_MODULE_EEPROM_PAGE,
-  ETHTOOL_A_MODULE_EEPROM_BANK,
-  ETHTOOL_A_MODULE_EEPROM_I2C_ADDRESS,
-  ETHTOOL_A_MODULE_EEPROM_DATA,
-  __ETHTOOL_A_MODULE_EEPROM_CNT,
-  ETHTOOL_A_MODULE_EEPROM_MAX = (__ETHTOOL_A_MODULE_EEPROM_CNT - 1)
-};
-enum {
-  ETHTOOL_A_STATS_UNSPEC,
-  ETHTOOL_A_STATS_PAD,
-  ETHTOOL_A_STATS_HEADER,
-  ETHTOOL_A_STATS_GROUPS,
-  ETHTOOL_A_STATS_GRP,
-  ETHTOOL_A_STATS_SRC,
-  __ETHTOOL_A_STATS_CNT,
-  ETHTOOL_A_STATS_MAX = (__ETHTOOL_A_STATS_CNT - 1)
-};
-enum {
   ETHTOOL_STATS_ETH_PHY,
   ETHTOOL_STATS_ETH_MAC,
   ETHTOOL_STATS_ETH_CTRL,
   ETHTOOL_STATS_RMON,
+  ETHTOOL_STATS_PHY,
   __ETHTOOL_STATS_CNT
 };
 enum {
-  ETHTOOL_A_STATS_GRP_UNSPEC,
-  ETHTOOL_A_STATS_GRP_PAD,
-  ETHTOOL_A_STATS_GRP_ID,
-  ETHTOOL_A_STATS_GRP_SS_ID,
-  ETHTOOL_A_STATS_GRP_STAT,
-  ETHTOOL_A_STATS_GRP_HIST_RX,
-  ETHTOOL_A_STATS_GRP_HIST_TX,
-  ETHTOOL_A_STATS_GRP_HIST_BKT_LOW,
-  ETHTOOL_A_STATS_GRP_HIST_BKT_HI,
-  ETHTOOL_A_STATS_GRP_HIST_VAL,
-  __ETHTOOL_A_STATS_GRP_CNT,
-  ETHTOOL_A_STATS_GRP_MAX = (__ETHTOOL_A_STATS_GRP_CNT - 1)
-};
-enum {
   ETHTOOL_A_STATS_ETH_PHY_5_SYM_ERR,
   __ETHTOOL_A_STATS_ETH_PHY_CNT,
   ETHTOOL_A_STATS_ETH_PHY_MAX = (__ETHTOOL_A_STATS_ETH_PHY_CNT - 1)
@@ -658,116 +119,14 @@
   ETHTOOL_A_STATS_RMON_MAX = (__ETHTOOL_A_STATS_RMON_CNT - 1)
 };
 enum {
-  ETHTOOL_A_MODULE_UNSPEC,
-  ETHTOOL_A_MODULE_HEADER,
-  ETHTOOL_A_MODULE_POWER_MODE_POLICY,
-  ETHTOOL_A_MODULE_POWER_MODE,
-  __ETHTOOL_A_MODULE_CNT,
-  ETHTOOL_A_MODULE_MAX = (__ETHTOOL_A_MODULE_CNT - 1)
+  ETHTOOL_A_STATS_PHY_RX_PKTS,
+  ETHTOOL_A_STATS_PHY_RX_BYTES,
+  ETHTOOL_A_STATS_PHY_RX_ERRORS,
+  ETHTOOL_A_STATS_PHY_TX_PKTS,
+  ETHTOOL_A_STATS_PHY_TX_BYTES,
+  ETHTOOL_A_STATS_PHY_TX_ERRORS,
+  __ETHTOOL_A_STATS_PHY_CNT,
+  ETHTOOL_A_STATS_PHY_MAX = (__ETHTOOL_A_STATS_PHY_CNT - 1)
 };
-enum {
-  ETHTOOL_A_C33_PSE_PW_LIMIT_UNSPEC,
-  ETHTOOL_A_C33_PSE_PW_LIMIT_MIN,
-  ETHTOOL_A_C33_PSE_PW_LIMIT_MAX,
-};
-enum {
-  ETHTOOL_A_PSE_UNSPEC,
-  ETHTOOL_A_PSE_HEADER,
-  ETHTOOL_A_PODL_PSE_ADMIN_STATE,
-  ETHTOOL_A_PODL_PSE_ADMIN_CONTROL,
-  ETHTOOL_A_PODL_PSE_PW_D_STATUS,
-  ETHTOOL_A_C33_PSE_ADMIN_STATE,
-  ETHTOOL_A_C33_PSE_ADMIN_CONTROL,
-  ETHTOOL_A_C33_PSE_PW_D_STATUS,
-  ETHTOOL_A_C33_PSE_PW_CLASS,
-  ETHTOOL_A_C33_PSE_ACTUAL_PW,
-  ETHTOOL_A_C33_PSE_EXT_STATE,
-  ETHTOOL_A_C33_PSE_EXT_SUBSTATE,
-  ETHTOOL_A_C33_PSE_AVAIL_PW_LIMIT,
-  ETHTOOL_A_C33_PSE_PW_LIMIT_RANGES,
-  __ETHTOOL_A_PSE_CNT,
-  ETHTOOL_A_PSE_MAX = (__ETHTOOL_A_PSE_CNT - 1)
-};
-enum {
-  ETHTOOL_A_RSS_UNSPEC,
-  ETHTOOL_A_RSS_HEADER,
-  ETHTOOL_A_RSS_CONTEXT,
-  ETHTOOL_A_RSS_HFUNC,
-  ETHTOOL_A_RSS_INDIR,
-  ETHTOOL_A_RSS_HKEY,
-  ETHTOOL_A_RSS_INPUT_XFRM,
-  ETHTOOL_A_RSS_START_CONTEXT,
-  __ETHTOOL_A_RSS_CNT,
-  ETHTOOL_A_RSS_MAX = (__ETHTOOL_A_RSS_CNT - 1),
-};
-enum {
-  ETHTOOL_A_PLCA_UNSPEC,
-  ETHTOOL_A_PLCA_HEADER,
-  ETHTOOL_A_PLCA_VERSION,
-  ETHTOOL_A_PLCA_ENABLED,
-  ETHTOOL_A_PLCA_STATUS,
-  ETHTOOL_A_PLCA_NODE_CNT,
-  ETHTOOL_A_PLCA_NODE_ID,
-  ETHTOOL_A_PLCA_TO_TMR,
-  ETHTOOL_A_PLCA_BURST_CNT,
-  ETHTOOL_A_PLCA_BURST_TMR,
-  __ETHTOOL_A_PLCA_CNT,
-  ETHTOOL_A_PLCA_MAX = (__ETHTOOL_A_PLCA_CNT - 1)
-};
-enum {
-  ETHTOOL_A_MM_STAT_UNSPEC,
-  ETHTOOL_A_MM_STAT_PAD,
-  ETHTOOL_A_MM_STAT_REASSEMBLY_ERRORS,
-  ETHTOOL_A_MM_STAT_SMD_ERRORS,
-  ETHTOOL_A_MM_STAT_REASSEMBLY_OK,
-  ETHTOOL_A_MM_STAT_RX_FRAG_COUNT,
-  ETHTOOL_A_MM_STAT_TX_FRAG_COUNT,
-  ETHTOOL_A_MM_STAT_HOLD_COUNT,
-  __ETHTOOL_A_MM_STAT_CNT,
-  ETHTOOL_A_MM_STAT_MAX = (__ETHTOOL_A_MM_STAT_CNT - 1)
-};
-enum {
-  ETHTOOL_A_MM_UNSPEC,
-  ETHTOOL_A_MM_HEADER,
-  ETHTOOL_A_MM_PMAC_ENABLED,
-  ETHTOOL_A_MM_TX_ENABLED,
-  ETHTOOL_A_MM_TX_ACTIVE,
-  ETHTOOL_A_MM_TX_MIN_FRAG_SIZE,
-  ETHTOOL_A_MM_RX_MIN_FRAG_SIZE,
-  ETHTOOL_A_MM_VERIFY_ENABLED,
-  ETHTOOL_A_MM_VERIFY_STATUS,
-  ETHTOOL_A_MM_VERIFY_TIME,
-  ETHTOOL_A_MM_MAX_VERIFY_TIME,
-  ETHTOOL_A_MM_STATS,
-  __ETHTOOL_A_MM_CNT,
-  ETHTOOL_A_MM_MAX = (__ETHTOOL_A_MM_CNT - 1)
-};
-enum {
-  ETHTOOL_A_MODULE_FW_FLASH_UNSPEC,
-  ETHTOOL_A_MODULE_FW_FLASH_HEADER,
-  ETHTOOL_A_MODULE_FW_FLASH_FILE_NAME,
-  ETHTOOL_A_MODULE_FW_FLASH_PASSWORD,
-  ETHTOOL_A_MODULE_FW_FLASH_STATUS,
-  ETHTOOL_A_MODULE_FW_FLASH_STATUS_MSG,
-  ETHTOOL_A_MODULE_FW_FLASH_DONE,
-  ETHTOOL_A_MODULE_FW_FLASH_TOTAL,
-  __ETHTOOL_A_MODULE_FW_FLASH_CNT,
-  ETHTOOL_A_MODULE_FW_FLASH_MAX = (__ETHTOOL_A_MODULE_FW_FLASH_CNT - 1)
-};
-enum {
-  ETHTOOL_A_PHY_UNSPEC,
-  ETHTOOL_A_PHY_HEADER,
-  ETHTOOL_A_PHY_INDEX,
-  ETHTOOL_A_PHY_DRVNAME,
-  ETHTOOL_A_PHY_NAME,
-  ETHTOOL_A_PHY_UPSTREAM_TYPE,
-  ETHTOOL_A_PHY_UPSTREAM_INDEX,
-  ETHTOOL_A_PHY_UPSTREAM_SFP_NAME,
-  ETHTOOL_A_PHY_DOWNSTREAM_SFP_NAME,
-  __ETHTOOL_A_PHY_CNT,
-  ETHTOOL_A_PHY_MAX = (__ETHTOOL_A_PHY_CNT - 1)
-};
-#define ETHTOOL_GENL_NAME "ethtool"
-#define ETHTOOL_GENL_VERSION 1
 #define ETHTOOL_MCGRP_MONITOR_NAME "monitor"
 #endif
diff --git a/libc/kernel/uapi/linux/ethtool_netlink_generated.h b/libc/kernel/uapi/linux/ethtool_netlink_generated.h
new file mode 100644
index 0000000..adaeb77
--- /dev/null
+++ b/libc/kernel/uapi/linux/ethtool_netlink_generated.h
@@ -0,0 +1,696 @@
+/*
+ * This file is auto-generated. Modifications will be lost.
+ *
+ * See https://android.googlesource.com/platform/bionic/+/master/libc/kernel/
+ * for more information.
+ */
+#ifndef _UAPI_LINUX_ETHTOOL_NETLINK_GENERATED_H
+#define _UAPI_LINUX_ETHTOOL_NETLINK_GENERATED_H
+#define ETHTOOL_GENL_NAME "ethtool"
+#define ETHTOOL_GENL_VERSION 1
+enum {
+  ETHTOOL_UDP_TUNNEL_TYPE_VXLAN,
+  ETHTOOL_UDP_TUNNEL_TYPE_GENEVE,
+  ETHTOOL_UDP_TUNNEL_TYPE_VXLAN_GPE,
+  __ETHTOOL_UDP_TUNNEL_TYPE_CNT,
+  ETHTOOL_UDP_TUNNEL_TYPE_MAX = (__ETHTOOL_UDP_TUNNEL_TYPE_CNT - 1)
+};
+enum ethtool_header_flags {
+  ETHTOOL_FLAG_COMPACT_BITSETS = 1,
+  ETHTOOL_FLAG_OMIT_REPLY = 2,
+  ETHTOOL_FLAG_STATS = 4,
+};
+enum ethtool_tcp_data_split {
+  ETHTOOL_TCP_DATA_SPLIT_UNKNOWN,
+  ETHTOOL_TCP_DATA_SPLIT_DISABLED,
+  ETHTOOL_TCP_DATA_SPLIT_ENABLED,
+};
+enum hwtstamp_source {
+  HWTSTAMP_SOURCE_NETDEV = 1,
+  HWTSTAMP_SOURCE_PHYLIB,
+};
+enum {
+  ETHTOOL_A_HEADER_UNSPEC,
+  ETHTOOL_A_HEADER_DEV_INDEX,
+  ETHTOOL_A_HEADER_DEV_NAME,
+  ETHTOOL_A_HEADER_FLAGS,
+  ETHTOOL_A_HEADER_PHY_INDEX,
+  __ETHTOOL_A_HEADER_CNT,
+  ETHTOOL_A_HEADER_MAX = (__ETHTOOL_A_HEADER_CNT - 1)
+};
+enum {
+  ETHTOOL_A_BITSET_BIT_UNSPEC,
+  ETHTOOL_A_BITSET_BIT_INDEX,
+  ETHTOOL_A_BITSET_BIT_NAME,
+  ETHTOOL_A_BITSET_BIT_VALUE,
+  __ETHTOOL_A_BITSET_BIT_CNT,
+  ETHTOOL_A_BITSET_BIT_MAX = (__ETHTOOL_A_BITSET_BIT_CNT - 1)
+};
+enum {
+  ETHTOOL_A_BITSET_BITS_UNSPEC,
+  ETHTOOL_A_BITSET_BITS_BIT,
+  __ETHTOOL_A_BITSET_BITS_CNT,
+  ETHTOOL_A_BITSET_BITS_MAX = (__ETHTOOL_A_BITSET_BITS_CNT - 1)
+};
+enum {
+  ETHTOOL_A_BITSET_UNSPEC,
+  ETHTOOL_A_BITSET_NOMASK,
+  ETHTOOL_A_BITSET_SIZE,
+  ETHTOOL_A_BITSET_BITS,
+  ETHTOOL_A_BITSET_VALUE,
+  ETHTOOL_A_BITSET_MASK,
+  __ETHTOOL_A_BITSET_CNT,
+  ETHTOOL_A_BITSET_MAX = (__ETHTOOL_A_BITSET_CNT - 1)
+};
+enum {
+  ETHTOOL_A_STRING_UNSPEC,
+  ETHTOOL_A_STRING_INDEX,
+  ETHTOOL_A_STRING_VALUE,
+  __ETHTOOL_A_STRING_CNT,
+  ETHTOOL_A_STRING_MAX = (__ETHTOOL_A_STRING_CNT - 1)
+};
+enum {
+  ETHTOOL_A_STRINGS_UNSPEC,
+  ETHTOOL_A_STRINGS_STRING,
+  __ETHTOOL_A_STRINGS_CNT,
+  ETHTOOL_A_STRINGS_MAX = (__ETHTOOL_A_STRINGS_CNT - 1)
+};
+enum {
+  ETHTOOL_A_STRINGSET_UNSPEC,
+  ETHTOOL_A_STRINGSET_ID,
+  ETHTOOL_A_STRINGSET_COUNT,
+  ETHTOOL_A_STRINGSET_STRINGS,
+  __ETHTOOL_A_STRINGSET_CNT,
+  ETHTOOL_A_STRINGSET_MAX = (__ETHTOOL_A_STRINGSET_CNT - 1)
+};
+enum {
+  ETHTOOL_A_STRINGSETS_UNSPEC,
+  ETHTOOL_A_STRINGSETS_STRINGSET,
+  __ETHTOOL_A_STRINGSETS_CNT,
+  ETHTOOL_A_STRINGSETS_MAX = (__ETHTOOL_A_STRINGSETS_CNT - 1)
+};
+enum {
+  ETHTOOL_A_STRSET_UNSPEC,
+  ETHTOOL_A_STRSET_HEADER,
+  ETHTOOL_A_STRSET_STRINGSETS,
+  ETHTOOL_A_STRSET_COUNTS_ONLY,
+  __ETHTOOL_A_STRSET_CNT,
+  ETHTOOL_A_STRSET_MAX = (__ETHTOOL_A_STRSET_CNT - 1)
+};
+enum {
+  ETHTOOL_A_PRIVFLAGS_UNSPEC,
+  ETHTOOL_A_PRIVFLAGS_HEADER,
+  ETHTOOL_A_PRIVFLAGS_FLAGS,
+  __ETHTOOL_A_PRIVFLAGS_CNT,
+  ETHTOOL_A_PRIVFLAGS_MAX = (__ETHTOOL_A_PRIVFLAGS_CNT - 1)
+};
+enum {
+  ETHTOOL_A_RINGS_UNSPEC,
+  ETHTOOL_A_RINGS_HEADER,
+  ETHTOOL_A_RINGS_RX_MAX,
+  ETHTOOL_A_RINGS_RX_MINI_MAX,
+  ETHTOOL_A_RINGS_RX_JUMBO_MAX,
+  ETHTOOL_A_RINGS_TX_MAX,
+  ETHTOOL_A_RINGS_RX,
+  ETHTOOL_A_RINGS_RX_MINI,
+  ETHTOOL_A_RINGS_RX_JUMBO,
+  ETHTOOL_A_RINGS_TX,
+  ETHTOOL_A_RINGS_RX_BUF_LEN,
+  ETHTOOL_A_RINGS_TCP_DATA_SPLIT,
+  ETHTOOL_A_RINGS_CQE_SIZE,
+  ETHTOOL_A_RINGS_TX_PUSH,
+  ETHTOOL_A_RINGS_RX_PUSH,
+  ETHTOOL_A_RINGS_TX_PUSH_BUF_LEN,
+  ETHTOOL_A_RINGS_TX_PUSH_BUF_LEN_MAX,
+  ETHTOOL_A_RINGS_HDS_THRESH,
+  ETHTOOL_A_RINGS_HDS_THRESH_MAX,
+  __ETHTOOL_A_RINGS_CNT,
+  ETHTOOL_A_RINGS_MAX = (__ETHTOOL_A_RINGS_CNT - 1)
+};
+enum {
+  ETHTOOL_A_MM_STAT_UNSPEC,
+  ETHTOOL_A_MM_STAT_PAD,
+  ETHTOOL_A_MM_STAT_REASSEMBLY_ERRORS,
+  ETHTOOL_A_MM_STAT_SMD_ERRORS,
+  ETHTOOL_A_MM_STAT_REASSEMBLY_OK,
+  ETHTOOL_A_MM_STAT_RX_FRAG_COUNT,
+  ETHTOOL_A_MM_STAT_TX_FRAG_COUNT,
+  ETHTOOL_A_MM_STAT_HOLD_COUNT,
+  __ETHTOOL_A_MM_STAT_CNT,
+  ETHTOOL_A_MM_STAT_MAX = (__ETHTOOL_A_MM_STAT_CNT - 1)
+};
+enum {
+  ETHTOOL_A_MM_UNSPEC,
+  ETHTOOL_A_MM_HEADER,
+  ETHTOOL_A_MM_PMAC_ENABLED,
+  ETHTOOL_A_MM_TX_ENABLED,
+  ETHTOOL_A_MM_TX_ACTIVE,
+  ETHTOOL_A_MM_TX_MIN_FRAG_SIZE,
+  ETHTOOL_A_MM_RX_MIN_FRAG_SIZE,
+  ETHTOOL_A_MM_VERIFY_ENABLED,
+  ETHTOOL_A_MM_VERIFY_STATUS,
+  ETHTOOL_A_MM_VERIFY_TIME,
+  ETHTOOL_A_MM_MAX_VERIFY_TIME,
+  ETHTOOL_A_MM_STATS,
+  __ETHTOOL_A_MM_CNT,
+  ETHTOOL_A_MM_MAX = (__ETHTOOL_A_MM_CNT - 1)
+};
+enum {
+  ETHTOOL_A_LINKINFO_UNSPEC,
+  ETHTOOL_A_LINKINFO_HEADER,
+  ETHTOOL_A_LINKINFO_PORT,
+  ETHTOOL_A_LINKINFO_PHYADDR,
+  ETHTOOL_A_LINKINFO_TP_MDIX,
+  ETHTOOL_A_LINKINFO_TP_MDIX_CTRL,
+  ETHTOOL_A_LINKINFO_TRANSCEIVER,
+  __ETHTOOL_A_LINKINFO_CNT,
+  ETHTOOL_A_LINKINFO_MAX = (__ETHTOOL_A_LINKINFO_CNT - 1)
+};
+enum {
+  ETHTOOL_A_LINKMODES_UNSPEC,
+  ETHTOOL_A_LINKMODES_HEADER,
+  ETHTOOL_A_LINKMODES_AUTONEG,
+  ETHTOOL_A_LINKMODES_OURS,
+  ETHTOOL_A_LINKMODES_PEER,
+  ETHTOOL_A_LINKMODES_SPEED,
+  ETHTOOL_A_LINKMODES_DUPLEX,
+  ETHTOOL_A_LINKMODES_MASTER_SLAVE_CFG,
+  ETHTOOL_A_LINKMODES_MASTER_SLAVE_STATE,
+  ETHTOOL_A_LINKMODES_LANES,
+  ETHTOOL_A_LINKMODES_RATE_MATCHING,
+  __ETHTOOL_A_LINKMODES_CNT,
+  ETHTOOL_A_LINKMODES_MAX = (__ETHTOOL_A_LINKMODES_CNT - 1)
+};
+enum {
+  ETHTOOL_A_LINKSTATE_UNSPEC,
+  ETHTOOL_A_LINKSTATE_HEADER,
+  ETHTOOL_A_LINKSTATE_LINK,
+  ETHTOOL_A_LINKSTATE_SQI,
+  ETHTOOL_A_LINKSTATE_SQI_MAX,
+  ETHTOOL_A_LINKSTATE_EXT_STATE,
+  ETHTOOL_A_LINKSTATE_EXT_SUBSTATE,
+  ETHTOOL_A_LINKSTATE_EXT_DOWN_CNT,
+  __ETHTOOL_A_LINKSTATE_CNT,
+  ETHTOOL_A_LINKSTATE_MAX = (__ETHTOOL_A_LINKSTATE_CNT - 1)
+};
+enum {
+  ETHTOOL_A_DEBUG_UNSPEC,
+  ETHTOOL_A_DEBUG_HEADER,
+  ETHTOOL_A_DEBUG_MSGMASK,
+  __ETHTOOL_A_DEBUG_CNT,
+  ETHTOOL_A_DEBUG_MAX = (__ETHTOOL_A_DEBUG_CNT - 1)
+};
+enum {
+  ETHTOOL_A_WOL_UNSPEC,
+  ETHTOOL_A_WOL_HEADER,
+  ETHTOOL_A_WOL_MODES,
+  ETHTOOL_A_WOL_SOPASS,
+  __ETHTOOL_A_WOL_CNT,
+  ETHTOOL_A_WOL_MAX = (__ETHTOOL_A_WOL_CNT - 1)
+};
+enum {
+  ETHTOOL_A_FEATURES_UNSPEC,
+  ETHTOOL_A_FEATURES_HEADER,
+  ETHTOOL_A_FEATURES_HW,
+  ETHTOOL_A_FEATURES_WANTED,
+  ETHTOOL_A_FEATURES_ACTIVE,
+  ETHTOOL_A_FEATURES_NOCHANGE,
+  __ETHTOOL_A_FEATURES_CNT,
+  ETHTOOL_A_FEATURES_MAX = (__ETHTOOL_A_FEATURES_CNT - 1)
+};
+enum {
+  ETHTOOL_A_CHANNELS_UNSPEC,
+  ETHTOOL_A_CHANNELS_HEADER,
+  ETHTOOL_A_CHANNELS_RX_MAX,
+  ETHTOOL_A_CHANNELS_TX_MAX,
+  ETHTOOL_A_CHANNELS_OTHER_MAX,
+  ETHTOOL_A_CHANNELS_COMBINED_MAX,
+  ETHTOOL_A_CHANNELS_RX_COUNT,
+  ETHTOOL_A_CHANNELS_TX_COUNT,
+  ETHTOOL_A_CHANNELS_OTHER_COUNT,
+  ETHTOOL_A_CHANNELS_COMBINED_COUNT,
+  __ETHTOOL_A_CHANNELS_CNT,
+  ETHTOOL_A_CHANNELS_MAX = (__ETHTOOL_A_CHANNELS_CNT - 1)
+};
+enum {
+  ETHTOOL_A_IRQ_MODERATION_UNSPEC,
+  ETHTOOL_A_IRQ_MODERATION_USEC,
+  ETHTOOL_A_IRQ_MODERATION_PKTS,
+  ETHTOOL_A_IRQ_MODERATION_COMPS,
+  __ETHTOOL_A_IRQ_MODERATION_CNT,
+  ETHTOOL_A_IRQ_MODERATION_MAX = (__ETHTOOL_A_IRQ_MODERATION_CNT - 1)
+};
+enum {
+  ETHTOOL_A_PROFILE_UNSPEC,
+  ETHTOOL_A_PROFILE_IRQ_MODERATION,
+  __ETHTOOL_A_PROFILE_CNT,
+  ETHTOOL_A_PROFILE_MAX = (__ETHTOOL_A_PROFILE_CNT - 1)
+};
+enum {
+  ETHTOOL_A_COALESCE_UNSPEC,
+  ETHTOOL_A_COALESCE_HEADER,
+  ETHTOOL_A_COALESCE_RX_USECS,
+  ETHTOOL_A_COALESCE_RX_MAX_FRAMES,
+  ETHTOOL_A_COALESCE_RX_USECS_IRQ,
+  ETHTOOL_A_COALESCE_RX_MAX_FRAMES_IRQ,
+  ETHTOOL_A_COALESCE_TX_USECS,
+  ETHTOOL_A_COALESCE_TX_MAX_FRAMES,
+  ETHTOOL_A_COALESCE_TX_USECS_IRQ,
+  ETHTOOL_A_COALESCE_TX_MAX_FRAMES_IRQ,
+  ETHTOOL_A_COALESCE_STATS_BLOCK_USECS,
+  ETHTOOL_A_COALESCE_USE_ADAPTIVE_RX,
+  ETHTOOL_A_COALESCE_USE_ADAPTIVE_TX,
+  ETHTOOL_A_COALESCE_PKT_RATE_LOW,
+  ETHTOOL_A_COALESCE_RX_USECS_LOW,
+  ETHTOOL_A_COALESCE_RX_MAX_FRAMES_LOW,
+  ETHTOOL_A_COALESCE_TX_USECS_LOW,
+  ETHTOOL_A_COALESCE_TX_MAX_FRAMES_LOW,
+  ETHTOOL_A_COALESCE_PKT_RATE_HIGH,
+  ETHTOOL_A_COALESCE_RX_USECS_HIGH,
+  ETHTOOL_A_COALESCE_RX_MAX_FRAMES_HIGH,
+  ETHTOOL_A_COALESCE_TX_USECS_HIGH,
+  ETHTOOL_A_COALESCE_TX_MAX_FRAMES_HIGH,
+  ETHTOOL_A_COALESCE_RATE_SAMPLE_INTERVAL,
+  ETHTOOL_A_COALESCE_USE_CQE_MODE_TX,
+  ETHTOOL_A_COALESCE_USE_CQE_MODE_RX,
+  ETHTOOL_A_COALESCE_TX_AGGR_MAX_BYTES,
+  ETHTOOL_A_COALESCE_TX_AGGR_MAX_FRAMES,
+  ETHTOOL_A_COALESCE_TX_AGGR_TIME_USECS,
+  ETHTOOL_A_COALESCE_RX_PROFILE,
+  ETHTOOL_A_COALESCE_TX_PROFILE,
+  __ETHTOOL_A_COALESCE_CNT,
+  ETHTOOL_A_COALESCE_MAX = (__ETHTOOL_A_COALESCE_CNT - 1)
+};
+enum {
+  ETHTOOL_A_PAUSE_STAT_UNSPEC,
+  ETHTOOL_A_PAUSE_STAT_PAD,
+  ETHTOOL_A_PAUSE_STAT_TX_FRAMES,
+  ETHTOOL_A_PAUSE_STAT_RX_FRAMES,
+  __ETHTOOL_A_PAUSE_STAT_CNT,
+  ETHTOOL_A_PAUSE_STAT_MAX = (__ETHTOOL_A_PAUSE_STAT_CNT - 1)
+};
+enum {
+  ETHTOOL_A_PAUSE_UNSPEC,
+  ETHTOOL_A_PAUSE_HEADER,
+  ETHTOOL_A_PAUSE_AUTONEG,
+  ETHTOOL_A_PAUSE_RX,
+  ETHTOOL_A_PAUSE_TX,
+  ETHTOOL_A_PAUSE_STATS,
+  ETHTOOL_A_PAUSE_STATS_SRC,
+  __ETHTOOL_A_PAUSE_CNT,
+  ETHTOOL_A_PAUSE_MAX = (__ETHTOOL_A_PAUSE_CNT - 1)
+};
+enum {
+  ETHTOOL_A_EEE_UNSPEC,
+  ETHTOOL_A_EEE_HEADER,
+  ETHTOOL_A_EEE_MODES_OURS,
+  ETHTOOL_A_EEE_MODES_PEER,
+  ETHTOOL_A_EEE_ACTIVE,
+  ETHTOOL_A_EEE_ENABLED,
+  ETHTOOL_A_EEE_TX_LPI_ENABLED,
+  ETHTOOL_A_EEE_TX_LPI_TIMER,
+  __ETHTOOL_A_EEE_CNT,
+  ETHTOOL_A_EEE_MAX = (__ETHTOOL_A_EEE_CNT - 1)
+};
+enum {
+  ETHTOOL_A_TS_STAT_UNSPEC,
+  ETHTOOL_A_TS_STAT_TX_PKTS,
+  ETHTOOL_A_TS_STAT_TX_LOST,
+  ETHTOOL_A_TS_STAT_TX_ERR,
+  ETHTOOL_A_TS_STAT_TX_ONESTEP_PKTS_UNCONFIRMED,
+  __ETHTOOL_A_TS_STAT_CNT,
+  ETHTOOL_A_TS_STAT_MAX = (__ETHTOOL_A_TS_STAT_CNT - 1)
+};
+enum {
+  ETHTOOL_A_TS_HWTSTAMP_PROVIDER_UNSPEC,
+  ETHTOOL_A_TS_HWTSTAMP_PROVIDER_INDEX,
+  ETHTOOL_A_TS_HWTSTAMP_PROVIDER_QUALIFIER,
+  __ETHTOOL_A_TS_HWTSTAMP_PROVIDER_CNT,
+  ETHTOOL_A_TS_HWTSTAMP_PROVIDER_MAX = (__ETHTOOL_A_TS_HWTSTAMP_PROVIDER_CNT - 1)
+};
+enum {
+  ETHTOOL_A_TSINFO_UNSPEC,
+  ETHTOOL_A_TSINFO_HEADER,
+  ETHTOOL_A_TSINFO_TIMESTAMPING,
+  ETHTOOL_A_TSINFO_TX_TYPES,
+  ETHTOOL_A_TSINFO_RX_FILTERS,
+  ETHTOOL_A_TSINFO_PHC_INDEX,
+  ETHTOOL_A_TSINFO_STATS,
+  ETHTOOL_A_TSINFO_HWTSTAMP_PROVIDER,
+  ETHTOOL_A_TSINFO_HWTSTAMP_SOURCE,
+  ETHTOOL_A_TSINFO_HWTSTAMP_PHYINDEX,
+  __ETHTOOL_A_TSINFO_CNT,
+  ETHTOOL_A_TSINFO_MAX = (__ETHTOOL_A_TSINFO_CNT - 1)
+};
+enum {
+  ETHTOOL_A_CABLE_RESULT_UNSPEC,
+  ETHTOOL_A_CABLE_RESULT_PAIR,
+  ETHTOOL_A_CABLE_RESULT_CODE,
+  ETHTOOL_A_CABLE_RESULT_SRC,
+  __ETHTOOL_A_CABLE_RESULT_CNT,
+  ETHTOOL_A_CABLE_RESULT_MAX = (__ETHTOOL_A_CABLE_RESULT_CNT - 1)
+};
+enum {
+  ETHTOOL_A_CABLE_FAULT_LENGTH_UNSPEC,
+  ETHTOOL_A_CABLE_FAULT_LENGTH_PAIR,
+  ETHTOOL_A_CABLE_FAULT_LENGTH_CM,
+  ETHTOOL_A_CABLE_FAULT_LENGTH_SRC,
+  __ETHTOOL_A_CABLE_FAULT_LENGTH_CNT,
+  ETHTOOL_A_CABLE_FAULT_LENGTH_MAX = (__ETHTOOL_A_CABLE_FAULT_LENGTH_CNT - 1)
+};
+enum {
+  ETHTOOL_A_CABLE_NEST_UNSPEC,
+  ETHTOOL_A_CABLE_NEST_RESULT,
+  ETHTOOL_A_CABLE_NEST_FAULT_LENGTH,
+  __ETHTOOL_A_CABLE_NEST_CNT,
+  ETHTOOL_A_CABLE_NEST_MAX = (__ETHTOOL_A_CABLE_NEST_CNT - 1)
+};
+enum {
+  ETHTOOL_A_CABLE_TEST_UNSPEC,
+  ETHTOOL_A_CABLE_TEST_HEADER,
+  __ETHTOOL_A_CABLE_TEST_CNT,
+  ETHTOOL_A_CABLE_TEST_MAX = (__ETHTOOL_A_CABLE_TEST_CNT - 1)
+};
+enum {
+  ETHTOOL_A_CABLE_TEST_NTF_UNSPEC,
+  ETHTOOL_A_CABLE_TEST_NTF_HEADER,
+  ETHTOOL_A_CABLE_TEST_NTF_STATUS,
+  ETHTOOL_A_CABLE_TEST_NTF_NEST,
+  __ETHTOOL_A_CABLE_TEST_NTF_CNT,
+  ETHTOOL_A_CABLE_TEST_NTF_MAX = (__ETHTOOL_A_CABLE_TEST_NTF_CNT - 1)
+};
+enum {
+  ETHTOOL_A_CABLE_TEST_TDR_CFG_UNSPEC,
+  ETHTOOL_A_CABLE_TEST_TDR_CFG_FIRST,
+  ETHTOOL_A_CABLE_TEST_TDR_CFG_LAST,
+  ETHTOOL_A_CABLE_TEST_TDR_CFG_STEP,
+  ETHTOOL_A_CABLE_TEST_TDR_CFG_PAIR,
+  __ETHTOOL_A_CABLE_TEST_TDR_CFG_CNT,
+  ETHTOOL_A_CABLE_TEST_TDR_CFG_MAX = (__ETHTOOL_A_CABLE_TEST_TDR_CFG_CNT - 1)
+};
+enum {
+  ETHTOOL_A_CABLE_TEST_TDR_NTF_UNSPEC,
+  ETHTOOL_A_CABLE_TEST_TDR_NTF_HEADER,
+  ETHTOOL_A_CABLE_TEST_TDR_NTF_STATUS,
+  ETHTOOL_A_CABLE_TEST_TDR_NTF_NEST,
+  __ETHTOOL_A_CABLE_TEST_TDR_NTF_CNT,
+  ETHTOOL_A_CABLE_TEST_TDR_NTF_MAX = (__ETHTOOL_A_CABLE_TEST_TDR_NTF_CNT - 1)
+};
+enum {
+  ETHTOOL_A_CABLE_TEST_TDR_UNSPEC,
+  ETHTOOL_A_CABLE_TEST_TDR_HEADER,
+  ETHTOOL_A_CABLE_TEST_TDR_CFG,
+  __ETHTOOL_A_CABLE_TEST_TDR_CNT,
+  ETHTOOL_A_CABLE_TEST_TDR_MAX = (__ETHTOOL_A_CABLE_TEST_TDR_CNT - 1)
+};
+enum {
+  ETHTOOL_A_TUNNEL_UDP_ENTRY_UNSPEC,
+  ETHTOOL_A_TUNNEL_UDP_ENTRY_PORT,
+  ETHTOOL_A_TUNNEL_UDP_ENTRY_TYPE,
+  __ETHTOOL_A_TUNNEL_UDP_ENTRY_CNT,
+  ETHTOOL_A_TUNNEL_UDP_ENTRY_MAX = (__ETHTOOL_A_TUNNEL_UDP_ENTRY_CNT - 1)
+};
+enum {
+  ETHTOOL_A_TUNNEL_UDP_TABLE_UNSPEC,
+  ETHTOOL_A_TUNNEL_UDP_TABLE_SIZE,
+  ETHTOOL_A_TUNNEL_UDP_TABLE_TYPES,
+  ETHTOOL_A_TUNNEL_UDP_TABLE_ENTRY,
+  __ETHTOOL_A_TUNNEL_UDP_TABLE_CNT,
+  ETHTOOL_A_TUNNEL_UDP_TABLE_MAX = (__ETHTOOL_A_TUNNEL_UDP_TABLE_CNT - 1)
+};
+enum {
+  ETHTOOL_A_TUNNEL_UDP_UNSPEC,
+  ETHTOOL_A_TUNNEL_UDP_TABLE,
+  __ETHTOOL_A_TUNNEL_UDP_CNT,
+  ETHTOOL_A_TUNNEL_UDP_MAX = (__ETHTOOL_A_TUNNEL_UDP_CNT - 1)
+};
+enum {
+  ETHTOOL_A_TUNNEL_INFO_UNSPEC,
+  ETHTOOL_A_TUNNEL_INFO_HEADER,
+  ETHTOOL_A_TUNNEL_INFO_UDP_PORTS,
+  __ETHTOOL_A_TUNNEL_INFO_CNT,
+  ETHTOOL_A_TUNNEL_INFO_MAX = (__ETHTOOL_A_TUNNEL_INFO_CNT - 1)
+};
+enum {
+  ETHTOOL_A_FEC_STAT_UNSPEC,
+  ETHTOOL_A_FEC_STAT_PAD,
+  ETHTOOL_A_FEC_STAT_CORRECTED,
+  ETHTOOL_A_FEC_STAT_UNCORR,
+  ETHTOOL_A_FEC_STAT_CORR_BITS,
+  __ETHTOOL_A_FEC_STAT_CNT,
+  ETHTOOL_A_FEC_STAT_MAX = (__ETHTOOL_A_FEC_STAT_CNT - 1)
+};
+enum {
+  ETHTOOL_A_FEC_UNSPEC,
+  ETHTOOL_A_FEC_HEADER,
+  ETHTOOL_A_FEC_MODES,
+  ETHTOOL_A_FEC_AUTO,
+  ETHTOOL_A_FEC_ACTIVE,
+  ETHTOOL_A_FEC_STATS,
+  __ETHTOOL_A_FEC_CNT,
+  ETHTOOL_A_FEC_MAX = (__ETHTOOL_A_FEC_CNT - 1)
+};
+enum {
+  ETHTOOL_A_MODULE_EEPROM_UNSPEC,
+  ETHTOOL_A_MODULE_EEPROM_HEADER,
+  ETHTOOL_A_MODULE_EEPROM_OFFSET,
+  ETHTOOL_A_MODULE_EEPROM_LENGTH,
+  ETHTOOL_A_MODULE_EEPROM_PAGE,
+  ETHTOOL_A_MODULE_EEPROM_BANK,
+  ETHTOOL_A_MODULE_EEPROM_I2C_ADDRESS,
+  ETHTOOL_A_MODULE_EEPROM_DATA,
+  __ETHTOOL_A_MODULE_EEPROM_CNT,
+  ETHTOOL_A_MODULE_EEPROM_MAX = (__ETHTOOL_A_MODULE_EEPROM_CNT - 1)
+};
+enum {
+  ETHTOOL_A_STATS_GRP_UNSPEC,
+  ETHTOOL_A_STATS_GRP_PAD,
+  ETHTOOL_A_STATS_GRP_ID,
+  ETHTOOL_A_STATS_GRP_SS_ID,
+  ETHTOOL_A_STATS_GRP_STAT,
+  ETHTOOL_A_STATS_GRP_HIST_RX,
+  ETHTOOL_A_STATS_GRP_HIST_TX,
+  ETHTOOL_A_STATS_GRP_HIST_BKT_LOW,
+  ETHTOOL_A_STATS_GRP_HIST_BKT_HI,
+  ETHTOOL_A_STATS_GRP_HIST_VAL,
+  __ETHTOOL_A_STATS_GRP_CNT,
+  ETHTOOL_A_STATS_GRP_MAX = (__ETHTOOL_A_STATS_GRP_CNT - 1)
+};
+enum {
+  ETHTOOL_A_STATS_UNSPEC,
+  ETHTOOL_A_STATS_PAD,
+  ETHTOOL_A_STATS_HEADER,
+  ETHTOOL_A_STATS_GROUPS,
+  ETHTOOL_A_STATS_GRP,
+  ETHTOOL_A_STATS_SRC,
+  __ETHTOOL_A_STATS_CNT,
+  ETHTOOL_A_STATS_MAX = (__ETHTOOL_A_STATS_CNT - 1)
+};
+enum {
+  ETHTOOL_A_PHC_VCLOCKS_UNSPEC,
+  ETHTOOL_A_PHC_VCLOCKS_HEADER,
+  ETHTOOL_A_PHC_VCLOCKS_NUM,
+  ETHTOOL_A_PHC_VCLOCKS_INDEX,
+  __ETHTOOL_A_PHC_VCLOCKS_CNT,
+  ETHTOOL_A_PHC_VCLOCKS_MAX = (__ETHTOOL_A_PHC_VCLOCKS_CNT - 1)
+};
+enum {
+  ETHTOOL_A_MODULE_UNSPEC,
+  ETHTOOL_A_MODULE_HEADER,
+  ETHTOOL_A_MODULE_POWER_MODE_POLICY,
+  ETHTOOL_A_MODULE_POWER_MODE,
+  __ETHTOOL_A_MODULE_CNT,
+  ETHTOOL_A_MODULE_MAX = (__ETHTOOL_A_MODULE_CNT - 1)
+};
+enum {
+  ETHTOOL_A_C33_PSE_PW_LIMIT_UNSPEC,
+  ETHTOOL_A_C33_PSE_PW_LIMIT_MIN,
+  ETHTOOL_A_C33_PSE_PW_LIMIT_MAX,
+  __ETHTOOL_A_C33_PSE_PW_LIMIT_CNT,
+  __ETHTOOL_A_C33_PSE_PW_LIMIT_MAX = (__ETHTOOL_A_C33_PSE_PW_LIMIT_CNT - 1)
+};
+enum {
+  ETHTOOL_A_PSE_UNSPEC,
+  ETHTOOL_A_PSE_HEADER,
+  ETHTOOL_A_PODL_PSE_ADMIN_STATE,
+  ETHTOOL_A_PODL_PSE_ADMIN_CONTROL,
+  ETHTOOL_A_PODL_PSE_PW_D_STATUS,
+  ETHTOOL_A_C33_PSE_ADMIN_STATE,
+  ETHTOOL_A_C33_PSE_ADMIN_CONTROL,
+  ETHTOOL_A_C33_PSE_PW_D_STATUS,
+  ETHTOOL_A_C33_PSE_PW_CLASS,
+  ETHTOOL_A_C33_PSE_ACTUAL_PW,
+  ETHTOOL_A_C33_PSE_EXT_STATE,
+  ETHTOOL_A_C33_PSE_EXT_SUBSTATE,
+  ETHTOOL_A_C33_PSE_AVAIL_PW_LIMIT,
+  ETHTOOL_A_C33_PSE_PW_LIMIT_RANGES,
+  __ETHTOOL_A_PSE_CNT,
+  ETHTOOL_A_PSE_MAX = (__ETHTOOL_A_PSE_CNT - 1)
+};
+enum {
+  ETHTOOL_A_RSS_UNSPEC,
+  ETHTOOL_A_RSS_HEADER,
+  ETHTOOL_A_RSS_CONTEXT,
+  ETHTOOL_A_RSS_HFUNC,
+  ETHTOOL_A_RSS_INDIR,
+  ETHTOOL_A_RSS_HKEY,
+  ETHTOOL_A_RSS_INPUT_XFRM,
+  ETHTOOL_A_RSS_START_CONTEXT,
+  __ETHTOOL_A_RSS_CNT,
+  ETHTOOL_A_RSS_MAX = (__ETHTOOL_A_RSS_CNT - 1)
+};
+enum {
+  ETHTOOL_A_PLCA_UNSPEC,
+  ETHTOOL_A_PLCA_HEADER,
+  ETHTOOL_A_PLCA_VERSION,
+  ETHTOOL_A_PLCA_ENABLED,
+  ETHTOOL_A_PLCA_STATUS,
+  ETHTOOL_A_PLCA_NODE_CNT,
+  ETHTOOL_A_PLCA_NODE_ID,
+  ETHTOOL_A_PLCA_TO_TMR,
+  ETHTOOL_A_PLCA_BURST_CNT,
+  ETHTOOL_A_PLCA_BURST_TMR,
+  __ETHTOOL_A_PLCA_CNT,
+  ETHTOOL_A_PLCA_MAX = (__ETHTOOL_A_PLCA_CNT - 1)
+};
+enum {
+  ETHTOOL_A_MODULE_FW_FLASH_UNSPEC,
+  ETHTOOL_A_MODULE_FW_FLASH_HEADER,
+  ETHTOOL_A_MODULE_FW_FLASH_FILE_NAME,
+  ETHTOOL_A_MODULE_FW_FLASH_PASSWORD,
+  ETHTOOL_A_MODULE_FW_FLASH_STATUS,
+  ETHTOOL_A_MODULE_FW_FLASH_STATUS_MSG,
+  ETHTOOL_A_MODULE_FW_FLASH_DONE,
+  ETHTOOL_A_MODULE_FW_FLASH_TOTAL,
+  __ETHTOOL_A_MODULE_FW_FLASH_CNT,
+  ETHTOOL_A_MODULE_FW_FLASH_MAX = (__ETHTOOL_A_MODULE_FW_FLASH_CNT - 1)
+};
+enum {
+  ETHTOOL_A_PHY_UNSPEC,
+  ETHTOOL_A_PHY_HEADER,
+  ETHTOOL_A_PHY_INDEX,
+  ETHTOOL_A_PHY_DRVNAME,
+  ETHTOOL_A_PHY_NAME,
+  ETHTOOL_A_PHY_UPSTREAM_TYPE,
+  ETHTOOL_A_PHY_UPSTREAM_INDEX,
+  ETHTOOL_A_PHY_UPSTREAM_SFP_NAME,
+  ETHTOOL_A_PHY_DOWNSTREAM_SFP_NAME,
+  __ETHTOOL_A_PHY_CNT,
+  ETHTOOL_A_PHY_MAX = (__ETHTOOL_A_PHY_CNT - 1)
+};
+enum {
+  ETHTOOL_A_TSCONFIG_UNSPEC,
+  ETHTOOL_A_TSCONFIG_HEADER,
+  ETHTOOL_A_TSCONFIG_HWTSTAMP_PROVIDER,
+  ETHTOOL_A_TSCONFIG_TX_TYPES,
+  ETHTOOL_A_TSCONFIG_RX_FILTERS,
+  ETHTOOL_A_TSCONFIG_HWTSTAMP_FLAGS,
+  __ETHTOOL_A_TSCONFIG_CNT,
+  ETHTOOL_A_TSCONFIG_MAX = (__ETHTOOL_A_TSCONFIG_CNT - 1)
+};
+enum {
+  ETHTOOL_MSG_USER_NONE = 0,
+  ETHTOOL_MSG_STRSET_GET = 1,
+  ETHTOOL_MSG_LINKINFO_GET,
+  ETHTOOL_MSG_LINKINFO_SET,
+  ETHTOOL_MSG_LINKMODES_GET,
+  ETHTOOL_MSG_LINKMODES_SET,
+  ETHTOOL_MSG_LINKSTATE_GET,
+  ETHTOOL_MSG_DEBUG_GET,
+  ETHTOOL_MSG_DEBUG_SET,
+  ETHTOOL_MSG_WOL_GET,
+  ETHTOOL_MSG_WOL_SET,
+  ETHTOOL_MSG_FEATURES_GET,
+  ETHTOOL_MSG_FEATURES_SET,
+  ETHTOOL_MSG_PRIVFLAGS_GET,
+  ETHTOOL_MSG_PRIVFLAGS_SET,
+  ETHTOOL_MSG_RINGS_GET,
+  ETHTOOL_MSG_RINGS_SET,
+  ETHTOOL_MSG_CHANNELS_GET,
+  ETHTOOL_MSG_CHANNELS_SET,
+  ETHTOOL_MSG_COALESCE_GET,
+  ETHTOOL_MSG_COALESCE_SET,
+  ETHTOOL_MSG_PAUSE_GET,
+  ETHTOOL_MSG_PAUSE_SET,
+  ETHTOOL_MSG_EEE_GET,
+  ETHTOOL_MSG_EEE_SET,
+  ETHTOOL_MSG_TSINFO_GET,
+  ETHTOOL_MSG_CABLE_TEST_ACT,
+  ETHTOOL_MSG_CABLE_TEST_TDR_ACT,
+  ETHTOOL_MSG_TUNNEL_INFO_GET,
+  ETHTOOL_MSG_FEC_GET,
+  ETHTOOL_MSG_FEC_SET,
+  ETHTOOL_MSG_MODULE_EEPROM_GET,
+  ETHTOOL_MSG_STATS_GET,
+  ETHTOOL_MSG_PHC_VCLOCKS_GET,
+  ETHTOOL_MSG_MODULE_GET,
+  ETHTOOL_MSG_MODULE_SET,
+  ETHTOOL_MSG_PSE_GET,
+  ETHTOOL_MSG_PSE_SET,
+  ETHTOOL_MSG_RSS_GET,
+  ETHTOOL_MSG_PLCA_GET_CFG,
+  ETHTOOL_MSG_PLCA_SET_CFG,
+  ETHTOOL_MSG_PLCA_GET_STATUS,
+  ETHTOOL_MSG_MM_GET,
+  ETHTOOL_MSG_MM_SET,
+  ETHTOOL_MSG_MODULE_FW_FLASH_ACT,
+  ETHTOOL_MSG_PHY_GET,
+  ETHTOOL_MSG_TSCONFIG_GET,
+  ETHTOOL_MSG_TSCONFIG_SET,
+  __ETHTOOL_MSG_USER_CNT,
+  ETHTOOL_MSG_USER_MAX = (__ETHTOOL_MSG_USER_CNT - 1)
+};
+enum {
+  ETHTOOL_MSG_KERNEL_NONE = 0,
+  ETHTOOL_MSG_STRSET_GET_REPLY = 1,
+  ETHTOOL_MSG_LINKINFO_GET_REPLY,
+  ETHTOOL_MSG_LINKINFO_NTF,
+  ETHTOOL_MSG_LINKMODES_GET_REPLY,
+  ETHTOOL_MSG_LINKMODES_NTF,
+  ETHTOOL_MSG_LINKSTATE_GET_REPLY,
+  ETHTOOL_MSG_DEBUG_GET_REPLY,
+  ETHTOOL_MSG_DEBUG_NTF,
+  ETHTOOL_MSG_WOL_GET_REPLY,
+  ETHTOOL_MSG_WOL_NTF,
+  ETHTOOL_MSG_FEATURES_GET_REPLY,
+  ETHTOOL_MSG_FEATURES_SET_REPLY,
+  ETHTOOL_MSG_FEATURES_NTF,
+  ETHTOOL_MSG_PRIVFLAGS_GET_REPLY,
+  ETHTOOL_MSG_PRIVFLAGS_NTF,
+  ETHTOOL_MSG_RINGS_GET_REPLY,
+  ETHTOOL_MSG_RINGS_NTF,
+  ETHTOOL_MSG_CHANNELS_GET_REPLY,
+  ETHTOOL_MSG_CHANNELS_NTF,
+  ETHTOOL_MSG_COALESCE_GET_REPLY,
+  ETHTOOL_MSG_COALESCE_NTF,
+  ETHTOOL_MSG_PAUSE_GET_REPLY,
+  ETHTOOL_MSG_PAUSE_NTF,
+  ETHTOOL_MSG_EEE_GET_REPLY,
+  ETHTOOL_MSG_EEE_NTF,
+  ETHTOOL_MSG_TSINFO_GET_REPLY,
+  ETHTOOL_MSG_CABLE_TEST_NTF,
+  ETHTOOL_MSG_CABLE_TEST_TDR_NTF,
+  ETHTOOL_MSG_TUNNEL_INFO_GET_REPLY,
+  ETHTOOL_MSG_FEC_GET_REPLY,
+  ETHTOOL_MSG_FEC_NTF,
+  ETHTOOL_MSG_MODULE_EEPROM_GET_REPLY,
+  ETHTOOL_MSG_STATS_GET_REPLY,
+  ETHTOOL_MSG_PHC_VCLOCKS_GET_REPLY,
+  ETHTOOL_MSG_MODULE_GET_REPLY,
+  ETHTOOL_MSG_MODULE_NTF,
+  ETHTOOL_MSG_PSE_GET_REPLY,
+  ETHTOOL_MSG_RSS_GET_REPLY,
+  ETHTOOL_MSG_PLCA_GET_CFG_REPLY,
+  ETHTOOL_MSG_PLCA_GET_STATUS_REPLY,
+  ETHTOOL_MSG_PLCA_NTF,
+  ETHTOOL_MSG_MM_GET_REPLY,
+  ETHTOOL_MSG_MM_NTF,
+  ETHTOOL_MSG_MODULE_FW_FLASH_NTF,
+  ETHTOOL_MSG_PHY_GET_REPLY,
+  ETHTOOL_MSG_PHY_NTF,
+  ETHTOOL_MSG_TSCONFIG_GET_REPLY,
+  ETHTOOL_MSG_TSCONFIG_SET_REPLY,
+  __ETHTOOL_MSG_KERNEL_CNT,
+  ETHTOOL_MSG_KERNEL_MAX = (__ETHTOOL_MSG_KERNEL_CNT - 1)
+};
+#endif
diff --git a/libc/kernel/uapi/linux/f2fs.h b/libc/kernel/uapi/linux/f2fs.h
index c4c8a65..413c90a 100644
--- a/libc/kernel/uapi/linux/f2fs.h
+++ b/libc/kernel/uapi/linux/f2fs.h
@@ -34,6 +34,8 @@
 #define F2FS_IOC_DECOMPRESS_FILE _IO(F2FS_IOCTL_MAGIC, 23)
 #define F2FS_IOC_COMPRESS_FILE _IO(F2FS_IOCTL_MAGIC, 24)
 #define F2FS_IOC_START_ATOMIC_REPLACE _IO(F2FS_IOCTL_MAGIC, 25)
+#define F2FS_IOC_GET_DEV_ALIAS_FILE _IOR(F2FS_IOCTL_MAGIC, 26, __u32)
+#define F2FS_IOC_IO_PRIO _IOW(F2FS_IOCTL_MAGIC, 27, __u32)
 #define F2FS_IOC_SHUTDOWN _IOR('X', 125, __u32)
 #define F2FS_GOING_DOWN_FULLSYNC 0x0
 #define F2FS_GOING_DOWN_METASYNC 0x1
@@ -43,6 +45,10 @@
 #define F2FS_TRIM_FILE_DISCARD 0x1
 #define F2FS_TRIM_FILE_ZEROOUT 0x2
 #define F2FS_TRIM_FILE_MASK 0x3
+enum {
+  F2FS_IOPRIO_WRITE = 1,
+  F2FS_IOPRIO_MAX,
+};
 struct f2fs_gc_range {
   __u32 sync;
   __u64 start;
diff --git a/libc/kernel/uapi/linux/fanotify.h b/libc/kernel/uapi/linux/fanotify.h
index 8a5a4f0..29b6526 100644
--- a/libc/kernel/uapi/linux/fanotify.h
+++ b/libc/kernel/uapi/linux/fanotify.h
@@ -25,6 +25,9 @@
 #define FAN_OPEN_PERM 0x00010000
 #define FAN_ACCESS_PERM 0x00020000
 #define FAN_OPEN_EXEC_PERM 0x00040000
+#define FAN_PRE_ACCESS 0x00100000
+#define FAN_MNT_ATTACH 0x01000000
+#define FAN_MNT_DETACH 0x02000000
 #define FAN_EVENT_ON_CHILD 0x08000000
 #define FAN_RENAME 0x10000000
 #define FAN_ONDIR 0x40000000
@@ -45,6 +48,8 @@
 #define FAN_REPORT_DIR_FID 0x00000400
 #define FAN_REPORT_NAME 0x00000800
 #define FAN_REPORT_TARGET_FID 0x00001000
+#define FAN_REPORT_FD_ERROR 0x00002000
+#define FAN_REPORT_MNT 0x00004000
 #define FAN_REPORT_DFID_NAME (FAN_REPORT_DIR_FID | FAN_REPORT_NAME)
 #define FAN_REPORT_DFID_NAME_TARGET (FAN_REPORT_DFID_NAME | FAN_REPORT_FID | FAN_REPORT_TARGET_FID)
 #define FAN_ALL_INIT_FLAGS (FAN_CLOEXEC | FAN_NONBLOCK | FAN_ALL_CLASS_BITS | FAN_UNLIMITED_QUEUE | FAN_UNLIMITED_MARKS)
@@ -60,6 +65,7 @@
 #define FAN_MARK_INODE 0x00000000
 #define FAN_MARK_MOUNT 0x00000010
 #define FAN_MARK_FILESYSTEM 0x00000100
+#define FAN_MARK_MNTNS 0x00000110
 #define FAN_MARK_IGNORE_SURV (FAN_MARK_IGNORE | FAN_MARK_IGNORED_SURV_MODIFY)
 #define FAN_ALL_MARK_FLAGS (FAN_MARK_ADD | FAN_MARK_REMOVE | FAN_MARK_DONT_FOLLOW | FAN_MARK_ONLYDIR | FAN_MARK_MOUNT | FAN_MARK_IGNORED_MASK | FAN_MARK_IGNORED_SURV_MODIFY | FAN_MARK_FLUSH)
 #define FAN_ALL_EVENTS (FAN_ACCESS | FAN_MODIFY | FAN_CLOSE | FAN_OPEN)
@@ -80,6 +86,8 @@
 #define FAN_EVENT_INFO_TYPE_DFID 3
 #define FAN_EVENT_INFO_TYPE_PIDFD 4
 #define FAN_EVENT_INFO_TYPE_ERROR 5
+#define FAN_EVENT_INFO_TYPE_RANGE 6
+#define FAN_EVENT_INFO_TYPE_MNT 7
 #define FAN_EVENT_INFO_TYPE_OLD_DFID_NAME 10
 #define FAN_EVENT_INFO_TYPE_NEW_DFID_NAME 12
 struct fanotify_event_info_header {
@@ -101,6 +109,16 @@
   __s32 error;
   __u32 error_count;
 };
+struct fanotify_event_info_range {
+  struct fanotify_event_info_header hdr;
+  __u32 pad;
+  __u64 offset;
+  __u64 count;
+};
+struct fanotify_event_info_mnt {
+  struct fanotify_event_info_header hdr;
+  __u64 mnt_id;
+};
 #define FAN_RESPONSE_INFO_NONE 0
 #define FAN_RESPONSE_INFO_AUDIT_RULE 1
 struct fanotify_response {
@@ -120,6 +138,10 @@
 };
 #define FAN_ALLOW 0x01
 #define FAN_DENY 0x02
+#define FAN_ERRNO_BITS 8
+#define FAN_ERRNO_SHIFT (32 - FAN_ERRNO_BITS)
+#define FAN_ERRNO_MASK ((1 << FAN_ERRNO_BITS) - 1)
+#define FAN_DENY_ERRNO(err) (FAN_DENY | ((((__u32) (err)) & FAN_ERRNO_MASK) << FAN_ERRNO_SHIFT))
 #define FAN_AUDIT 0x10
 #define FAN_INFO 0x20
 #define FAN_NOFD - 1
diff --git a/libc/kernel/uapi/linux/fcntl.h b/libc/kernel/uapi/linux/fcntl.h
index 22ca65d..d83322b 100644
--- a/libc/kernel/uapi/linux/fcntl.h
+++ b/libc/kernel/uapi/linux/fcntl.h
@@ -60,4 +60,6 @@
 #define AT_REMOVEDIR 0x200
 #define AT_HANDLE_FID 0x200
 #define AT_HANDLE_MNT_ID_UNIQUE 0x001
+#define AT_HANDLE_CONNECTABLE 0x002
+#define AT_EXECVE_CHECK 0x10000
 #endif
diff --git a/libc/kernel/uapi/linux/fib_rules.h b/libc/kernel/uapi/linux/fib_rules.h
index 339ccce..5108bca 100644
--- a/libc/kernel/uapi/linux/fib_rules.h
+++ b/libc/kernel/uapi/linux/fib_rules.h
@@ -4,8 +4,8 @@
  * See https://android.googlesource.com/platform/bionic/+/master/libc/kernel/
  * for more information.
  */
-#ifndef __LINUX_FIB_RULES_H
-#define __LINUX_FIB_RULES_H
+#ifndef _UAPI__LINUX_FIB_RULES_H
+#define _UAPI__LINUX_FIB_RULES_H
 #include <linux/types.h>
 #include <linux/rtnetlink.h>
 #define FIB_RULE_PERMANENT 0x00000001
@@ -62,6 +62,11 @@
   FRA_SPORT_RANGE,
   FRA_DPORT_RANGE,
   FRA_DSCP,
+  FRA_FLOWLABEL,
+  FRA_FLOWLABEL_MASK,
+  FRA_SPORT_MASK,
+  FRA_DPORT_MASK,
+  FRA_DSCP_MASK,
   __FRA_MAX
 };
 #define FRA_MAX (__FRA_MAX - 1)
diff --git a/libc/kernel/uapi/linux/fs.h b/libc/kernel/uapi/linux/fs.h
index adab56f..bc4f541 100644
--- a/libc/kernel/uapi/linux/fs.h
+++ b/libc/kernel/uapi/linux/fs.h
@@ -16,6 +16,10 @@
 #define INR_OPEN_MAX 4096
 #define BLOCK_SIZE_BITS 10
 #define BLOCK_SIZE (1 << BLOCK_SIZE_BITS)
+#define IO_INTEGRITY_CHK_GUARD (1U << 0)
+#define IO_INTEGRITY_CHK_REFTAG (1U << 1)
+#define IO_INTEGRITY_CHK_APPTAG (1U << 2)
+#define IO_INTEGRITY_VALID_FLAGS (IO_INTEGRITY_CHK_GUARD | IO_INTEGRITY_CHK_REFTAG | IO_INTEGRITY_CHK_APPTAG)
 #define SEEK_SET 0
 #define SEEK_CUR 1
 #define SEEK_END 2
@@ -195,7 +199,8 @@
 #define RWF_APPEND (( __kernel_rwf_t) 0x00000010)
 #define RWF_NOAPPEND (( __kernel_rwf_t) 0x00000020)
 #define RWF_ATOMIC (( __kernel_rwf_t) 0x00000040)
-#define RWF_SUPPORTED (RWF_HIPRI | RWF_DSYNC | RWF_SYNC | RWF_NOWAIT | RWF_APPEND | RWF_NOAPPEND | RWF_ATOMIC)
+#define RWF_DONTCACHE (( __kernel_rwf_t) 0x00000080)
+#define RWF_SUPPORTED (RWF_HIPRI | RWF_DSYNC | RWF_SYNC | RWF_NOWAIT | RWF_APPEND | RWF_NOAPPEND | RWF_ATOMIC | RWF_DONTCACHE)
 #define PROCFS_IOCTL_MAGIC 'f'
 #define PAGEMAP_SCAN _IOWR(PROCFS_IOCTL_MAGIC, 16, struct pm_scan_arg)
 #define PAGE_IS_WPALLOWED (1 << 0)
@@ -206,6 +211,7 @@
 #define PAGE_IS_PFNZERO (1 << 5)
 #define PAGE_IS_HUGE (1 << 6)
 #define PAGE_IS_SOFT_DIRTY (1 << 7)
+#define PAGE_IS_GUARD (1 << 8)
 struct page_region {
   __u64 start;
   __u64 end;
diff --git a/libc/kernel/uapi/linux/fscrypt.h b/libc/kernel/uapi/linux/fscrypt.h
index 9a53f4c..79c5292 100644
--- a/libc/kernel/uapi/linux/fscrypt.h
+++ b/libc/kernel/uapi/linux/fscrypt.h
@@ -73,14 +73,16 @@
 };
 struct fscrypt_provisioning_key_payload {
   __u32 type;
-  __u32 __reserved;
+  __u32 flags;
   __u8 raw[];
 };
 struct fscrypt_add_key_arg {
   struct fscrypt_key_specifier key_spec;
   __u32 raw_size;
   __u32 key_id;
-  __u32 __reserved[7];
+#define FSCRYPT_ADD_KEY_FLAG_HW_WRAPPED 0x00000001
+  __u32 flags;
+  __u32 __reserved[6];
 #define __FSCRYPT_ADD_KEY_FLAG_HW_WRAPPED 0x00000001
   __u32 __flags;
   __u8 raw[];
diff --git a/libc/kernel/uapi/linux/fuse.h b/libc/kernel/uapi/linux/fuse.h
index c1d64ce..5bdd7e5 100644
--- a/libc/kernel/uapi/linux/fuse.h
+++ b/libc/kernel/uapi/linux/fuse.h
@@ -8,7 +8,7 @@
 #define _LINUX_FUSE_H
 #include <stdint.h>
 #define FUSE_KERNEL_VERSION 7
-#define FUSE_KERNEL_MINOR_VERSION 41
+#define FUSE_KERNEL_MINOR_VERSION 44
 #define FUSE_ROOT_ID 1
 struct fuse_attr {
   uint64_t ino;
@@ -136,6 +136,8 @@
 #define FUSE_HAS_RESEND (1ULL << 39)
 #define FUSE_DIRECT_IO_RELAX FUSE_DIRECT_IO_ALLOW_MMAP
 #define FUSE_ALLOW_IDMAP (1ULL << 40)
+#define FUSE_OVER_IO_URING (1ULL << 41)
+#define FUSE_REQUEST_TIMEOUT (1ULL << 42)
 #define CUSE_UNRESTRICTED_IOCTL (1 << 0)
 #define FUSE_RELEASE_FLUSH (1 << 0)
 #define FUSE_RELEASE_FLOCK_UNLOCK (1 << 1)
@@ -228,6 +230,7 @@
   FUSE_NOTIFY_RETRIEVE = 5,
   FUSE_NOTIFY_DELETE = 6,
   FUSE_NOTIFY_RESEND = 7,
+  FUSE_NOTIFY_INC_EPOCH = 8,
   FUSE_NOTIFY_CODE_MAX,
 };
 #define FUSE_MIN_READ_BUFFER 8192
@@ -429,7 +432,8 @@
   uint16_t map_alignment;
   uint32_t flags2;
   uint32_t max_stack_depth;
-  uint32_t unused[6];
+  uint16_t request_timeout;
+  uint16_t unused[11];
 };
 #define CUSE_INIT_INFO_MAX 4096
 struct cuse_init_in {
@@ -633,4 +637,29 @@
   uint32_t nr_groups;
   uint32_t groups[];
 };
+#define FUSE_URING_IN_OUT_HEADER_SZ 128
+#define FUSE_URING_OP_IN_OUT_SZ 128
+struct fuse_uring_ent_in_out {
+  uint64_t flags;
+  uint64_t commit_id;
+  uint32_t payload_sz;
+  uint32_t padding;
+  uint64_t reserved;
+};
+struct fuse_uring_req_header {
+  char in_out[FUSE_URING_IN_OUT_HEADER_SZ];
+  char op_in[FUSE_URING_OP_IN_OUT_SZ];
+  struct fuse_uring_ent_in_out ring_ent_in_out;
+};
+enum fuse_uring_cmd {
+  FUSE_IO_URING_CMD_INVALID = 0,
+  FUSE_IO_URING_CMD_REGISTER = 1,
+  FUSE_IO_URING_CMD_COMMIT_AND_FETCH = 2,
+};
+struct fuse_uring_cmd_req {
+  uint64_t flags;
+  uint64_t commit_id;
+  uint16_t qid;
+  uint8_t padding[6];
+};
 #endif
diff --git a/libc/kernel/uapi/linux/futex.h b/libc/kernel/uapi/linux/futex.h
index 32c9d28..f2cb2b6 100644
--- a/libc/kernel/uapi/linux/futex.h
+++ b/libc/kernel/uapi/linux/futex.h
@@ -43,9 +43,11 @@
 #define FUTEX2_SIZE_U32 0x02
 #define FUTEX2_SIZE_U64 0x03
 #define FUTEX2_NUMA 0x04
+#define FUTEX2_MPOL 0x08
 #define FUTEX2_PRIVATE FUTEX_PRIVATE_FLAG
 #define FUTEX2_SIZE_MASK 0x03
 #define FUTEX_32 FUTEX2_SIZE_U32
+#define FUTEX_NO_NODE (- 1)
 #define FUTEX_WAITV_MAX 128
 struct futex_waitv {
   __u64 val;
diff --git a/libc/kernel/uapi/linux/if_addr.h b/libc/kernel/uapi/linux/if_addr.h
index aa27d70..23bf379 100644
--- a/libc/kernel/uapi/linux/if_addr.h
+++ b/libc/kernel/uapi/linux/if_addr.h
@@ -4,8 +4,8 @@
  * See https://android.googlesource.com/platform/bionic/+/master/libc/kernel/
  * for more information.
  */
-#ifndef __LINUX_IF_ADDR_H
-#define __LINUX_IF_ADDR_H
+#ifndef _UAPI__LINUX_IF_ADDR_H
+#define _UAPI__LINUX_IF_ADDR_H
 #include <linux/types.h>
 #include <linux/netlink.h>
 struct ifaddrmsg {
diff --git a/libc/kernel/uapi/linux/if_addrlabel.h b/libc/kernel/uapi/linux/if_addrlabel.h
index c622b87..353c983 100644
--- a/libc/kernel/uapi/linux/if_addrlabel.h
+++ b/libc/kernel/uapi/linux/if_addrlabel.h
@@ -4,8 +4,8 @@
  * See https://android.googlesource.com/platform/bionic/+/master/libc/kernel/
  * for more information.
  */
-#ifndef __LINUX_IF_ADDRLABEL_H
-#define __LINUX_IF_ADDRLABEL_H
+#ifndef _UAPI__LINUX_IF_ADDRLABEL_H
+#define _UAPI__LINUX_IF_ADDRLABEL_H
 #include <linux/types.h>
 struct ifaddrlblmsg {
   __u8 ifal_family;
diff --git a/libc/kernel/uapi/linux/if_alg.h b/libc/kernel/uapi/linux/if_alg.h
index 00e0123..a4298f1 100644
--- a/libc/kernel/uapi/linux/if_alg.h
+++ b/libc/kernel/uapi/linux/if_alg.h
@@ -4,8 +4,8 @@
  * See https://android.googlesource.com/platform/bionic/+/master/libc/kernel/
  * for more information.
  */
-#ifndef _LINUX_IF_ALG_H
-#define _LINUX_IF_ALG_H
+#ifndef _UAPI_LINUX_IF_ALG_H
+#define _UAPI_LINUX_IF_ALG_H
 #include <linux/types.h>
 struct sockaddr_alg {
   __u16 salg_family;
diff --git a/libc/kernel/uapi/linux/if_arcnet.h b/libc/kernel/uapi/linux/if_arcnet.h
index 188ce17..0ed6b6b 100644
--- a/libc/kernel/uapi/linux/if_arcnet.h
+++ b/libc/kernel/uapi/linux/if_arcnet.h
@@ -4,8 +4,8 @@
  * See https://android.googlesource.com/platform/bionic/+/master/libc/kernel/
  * for more information.
  */
-#ifndef _LINUX_IF_ARCNET_H
-#define _LINUX_IF_ARCNET_H
+#ifndef _UAPI_LINUX_IF_ARCNET_H
+#define _UAPI_LINUX_IF_ARCNET_H
 #include <linux/types.h>
 #include <linux/if_ether.h>
 #define ARC_P_IP 212
diff --git a/libc/kernel/uapi/linux/if_bonding.h b/libc/kernel/uapi/linux/if_bonding.h
index 304dcf3..ef67519 100644
--- a/libc/kernel/uapi/linux/if_bonding.h
+++ b/libc/kernel/uapi/linux/if_bonding.h
@@ -4,8 +4,8 @@
  * See https://android.googlesource.com/platform/bionic/+/master/libc/kernel/
  * for more information.
  */
-#ifndef _LINUX_IF_BONDING_H
-#define _LINUX_IF_BONDING_H
+#ifndef _UAPI_LINUX_IF_BONDING_H
+#define _UAPI_LINUX_IF_BONDING_H
 #include <linux/if.h>
 #include <linux/types.h>
 #include <linux/if_ether.h>
diff --git a/libc/kernel/uapi/linux/if_bridge.h b/libc/kernel/uapi/linux/if_bridge.h
index 97c0fb6..5efa8e1 100644
--- a/libc/kernel/uapi/linux/if_bridge.h
+++ b/libc/kernel/uapi/linux/if_bridge.h
@@ -551,6 +551,7 @@
 #define MDB_FLAGS_FAST_LEAVE (1 << 1)
 #define MDB_FLAGS_STAR_EXCL (1 << 2)
 #define MDB_FLAGS_BLOCKED (1 << 3)
+#define MDB_FLAGS_OFFLOAD_FAILED (1 << 4)
   __u8 flags;
   __u16 vid;
   struct {
@@ -639,6 +640,7 @@
   BR_BOOLOPT_NO_LL_LEARN,
   BR_BOOLOPT_MCAST_VLAN_SNOOPING,
   BR_BOOLOPT_MST_ENABLE,
+  BR_BOOLOPT_MDB_OFFLOAD_FAIL_NOTIFICATION,
   BR_BOOLOPT_MAX
 };
 struct br_boolopt_multi {
diff --git a/libc/kernel/uapi/linux/if_cablemodem.h b/libc/kernel/uapi/linux/if_cablemodem.h
deleted file mode 100644
index 79b3017..0000000
--- a/libc/kernel/uapi/linux/if_cablemodem.h
+++ /dev/null
@@ -1,15 +0,0 @@
-/*
- * This file is auto-generated. Modifications will be lost.
- *
- * See https://android.googlesource.com/platform/bionic/+/master/libc/kernel/
- * for more information.
- */
-#ifndef _LINUX_CABLEMODEM_H_
-#define _LINUX_CABLEMODEM_H_
-#define SIOCGCMSTATS (SIOCDEVPRIVATE + 0)
-#define SIOCGCMFIRMWARE (SIOCDEVPRIVATE + 1)
-#define SIOCGCMFREQUENCY (SIOCDEVPRIVATE + 2)
-#define SIOCSCMFREQUENCY (SIOCDEVPRIVATE + 3)
-#define SIOCGCMPIDS (SIOCDEVPRIVATE + 4)
-#define SIOCSCMPIDS (SIOCDEVPRIVATE + 5)
-#endif
diff --git a/libc/kernel/uapi/linux/if_fc.h b/libc/kernel/uapi/linux/if_fc.h
index 52a1890..365e154 100644
--- a/libc/kernel/uapi/linux/if_fc.h
+++ b/libc/kernel/uapi/linux/if_fc.h
@@ -4,8 +4,8 @@
  * See https://android.googlesource.com/platform/bionic/+/master/libc/kernel/
  * for more information.
  */
-#ifndef _LINUX_IF_FC_H
-#define _LINUX_IF_FC_H
+#ifndef _UAPI_LINUX_IF_FC_H
+#define _UAPI_LINUX_IF_FC_H
 #include <linux/types.h>
 #define FC_ALEN 6
 #define FC_HLEN (sizeof(struct fch_hdr) + sizeof(struct fcllc))
diff --git a/libc/kernel/uapi/linux/if_hippi.h b/libc/kernel/uapi/linux/if_hippi.h
index a17d118..e25f1de 100644
--- a/libc/kernel/uapi/linux/if_hippi.h
+++ b/libc/kernel/uapi/linux/if_hippi.h
@@ -4,8 +4,8 @@
  * See https://android.googlesource.com/platform/bionic/+/master/libc/kernel/
  * for more information.
  */
-#ifndef _LINUX_IF_HIPPI_H
-#define _LINUX_IF_HIPPI_H
+#ifndef _UAPI_LINUX_IF_HIPPI_H
+#define _UAPI_LINUX_IF_HIPPI_H
 #include <linux/types.h>
 #include <asm/byteorder.h>
 #define HIPPI_ALEN 6
diff --git a/libc/kernel/uapi/linux/if_link.h b/libc/kernel/uapi/linux/if_link.h
index c2483a2..6f684cd 100644
--- a/libc/kernel/uapi/linux/if_link.h
+++ b/libc/kernel/uapi/linux/if_link.h
@@ -158,6 +158,8 @@
   IFLA_GSO_IPV4_MAX_SIZE,
   IFLA_GRO_IPV4_MAX_SIZE,
   IFLA_DPLL_PIN,
+  IFLA_MAX_PACING_OFFLOAD_HORIZON,
+  IFLA_NETNS_IMMUTABLE,
   __IFLA_MAX
 };
 #define IFLA_MAX (__IFLA_MAX - 1)
@@ -461,6 +463,10 @@
   NETKIT_L2,
   NETKIT_L3,
 };
+enum netkit_scrub {
+  NETKIT_SCRUB_NONE,
+  NETKIT_SCRUB_DEFAULT,
+};
 enum {
   IFLA_NETKIT_UNSPEC,
   IFLA_NETKIT_PEER_INFO,
@@ -468,6 +474,10 @@
   IFLA_NETKIT_POLICY,
   IFLA_NETKIT_PEER_POLICY,
   IFLA_NETKIT_MODE,
+  IFLA_NETKIT_SCRUB,
+  IFLA_NETKIT_PEER_SCRUB,
+  IFLA_NETKIT_HEADROOM,
+  IFLA_NETKIT_TAILROOM,
   __IFLA_NETKIT_MAX,
 };
 #define IFLA_NETKIT_MAX (__IFLA_NETKIT_MAX - 1)
@@ -537,6 +547,7 @@
   IFLA_VXLAN_VNIFILTER,
   IFLA_VXLAN_LOCALBYPASS,
   IFLA_VXLAN_LABEL_POLICY,
+  IFLA_VXLAN_RESERVED_BITS,
   __IFLA_VXLAN_MAX
 };
 #define IFLA_VXLAN_MAX (__IFLA_VXLAN_MAX - 1)
@@ -573,6 +584,7 @@
   IFLA_GENEVE_TTL_INHERIT,
   IFLA_GENEVE_DF,
   IFLA_GENEVE_INNER_PROTO_INHERIT,
+  IFLA_GENEVE_PORT_RANGE,
   __IFLA_GENEVE_MAX
 };
 #define IFLA_GENEVE_MAX (__IFLA_GENEVE_MAX - 1)
@@ -583,6 +595,10 @@
   __GENEVE_DF_END,
   GENEVE_DF_MAX = __GENEVE_DF_END - 1,
 };
+struct ifla_geneve_port_range {
+  __be16 low;
+  __be16 high;
+};
 enum {
   IFLA_BAREUDP_UNSPEC,
   IFLA_BAREUDP_PORT,
@@ -968,6 +984,7 @@
 enum {
   IFLA_MCTP_UNSPEC,
   IFLA_MCTP_NET,
+  IFLA_MCTP_PHYS_BINDING,
   __IFLA_MCTP_MAX,
 };
 #define IFLA_MCTP_MAX (__IFLA_MCTP_MAX - 1)
@@ -978,4 +995,14 @@
   __IFLA_DSA_MAX,
 };
 #define IFLA_DSA_MAX (__IFLA_DSA_MAX - 1)
+enum ovpn_mode {
+  OVPN_MODE_P2P,
+  OVPN_MODE_MP,
+};
+enum {
+  IFLA_OVPN_UNSPEC,
+  IFLA_OVPN_MODE,
+  __IFLA_OVPN_MAX,
+};
+#define IFLA_OVPN_MAX (__IFLA_OVPN_MAX - 1)
 #endif
diff --git a/libc/kernel/uapi/linux/if_packet.h b/libc/kernel/uapi/linux/if_packet.h
index 362b5b7..4d9806b 100644
--- a/libc/kernel/uapi/linux/if_packet.h
+++ b/libc/kernel/uapi/linux/if_packet.h
@@ -4,8 +4,8 @@
  * See https://android.googlesource.com/platform/bionic/+/master/libc/kernel/
  * for more information.
  */
-#ifndef __LINUX_IF_PACKET_H
-#define __LINUX_IF_PACKET_H
+#ifndef _UAPI__LINUX_IF_PACKET_H
+#define _UAPI__LINUX_IF_PACKET_H
 #include <asm/byteorder.h>
 #include <linux/types.h>
 struct sockaddr_pkt {
diff --git a/libc/kernel/uapi/linux/if_plip.h b/libc/kernel/uapi/linux/if_plip.h
index cef0d6d..34d3383 100644
--- a/libc/kernel/uapi/linux/if_plip.h
+++ b/libc/kernel/uapi/linux/if_plip.h
@@ -4,8 +4,8 @@
  * See https://android.googlesource.com/platform/bionic/+/master/libc/kernel/
  * for more information.
  */
-#ifndef _LINUX_IF_PLIP_H
-#define _LINUX_IF_PLIP_H
+#ifndef _UAPI_LINUX_IF_PLIP_H
+#define _UAPI_LINUX_IF_PLIP_H
 #include <linux/sockios.h>
 #define SIOCDEVPLIP SIOCDEVPRIVATE
 struct plipconf {
diff --git a/libc/kernel/uapi/linux/if_slip.h b/libc/kernel/uapi/linux/if_slip.h
index c7e4751..9dc7aec 100644
--- a/libc/kernel/uapi/linux/if_slip.h
+++ b/libc/kernel/uapi/linux/if_slip.h
@@ -4,8 +4,8 @@
  * See https://android.googlesource.com/platform/bionic/+/master/libc/kernel/
  * for more information.
  */
-#ifndef __LINUX_SLIP_H
-#define __LINUX_SLIP_H
+#ifndef _UAPI__LINUX_SLIP_H
+#define _UAPI__LINUX_SLIP_H
 #define SL_MODE_SLIP 0
 #define SL_MODE_CSLIP 1
 #define SL_MODE_KISS 4
diff --git a/libc/kernel/uapi/linux/if_x25.h b/libc/kernel/uapi/linux/if_x25.h
index 9b2ad0a..b315186 100644
--- a/libc/kernel/uapi/linux/if_x25.h
+++ b/libc/kernel/uapi/linux/if_x25.h
@@ -4,8 +4,8 @@
  * See https://android.googlesource.com/platform/bionic/+/master/libc/kernel/
  * for more information.
  */
-#ifndef _IF_X25_H
-#define _IF_X25_H
+#ifndef _UAPI_IF_X25_H
+#define _UAPI_IF_X25_H
 #include <linux/types.h>
 #define X25_IFACE_DATA 0x00
 #define X25_IFACE_CONNECT 0x01
diff --git a/libc/kernel/uapi/linux/if_xdp.h b/libc/kernel/uapi/linux/if_xdp.h
index 7201e06..68bb719 100644
--- a/libc/kernel/uapi/linux/if_xdp.h
+++ b/libc/kernel/uapi/linux/if_xdp.h
@@ -4,8 +4,8 @@
  * See https://android.googlesource.com/platform/bionic/+/master/libc/kernel/
  * for more information.
  */
-#ifndef _LINUX_IF_XDP_H
-#define _LINUX_IF_XDP_H
+#ifndef _UAPI_LINUX_IF_XDP_H
+#define _UAPI_LINUX_IF_XDP_H
 #include <linux/types.h>
 #define XDP_SHARED_UMEM (1 << 0)
 #define XDP_COPY (1 << 1)
@@ -71,12 +71,14 @@
 #define XSK_UNALIGNED_BUF_ADDR_MASK ((1ULL << XSK_UNALIGNED_BUF_OFFSET_SHIFT) - 1)
 #define XDP_TXMD_FLAGS_TIMESTAMP (1 << 0)
 #define XDP_TXMD_FLAGS_CHECKSUM (1 << 1)
+#define XDP_TXMD_FLAGS_LAUNCH_TIME (1 << 2)
 struct xsk_tx_metadata {
   __u64 flags;
   union {
     struct {
       __u16 csum_start;
       __u16 csum_offset;
+      __u64 launch_time;
     } request;
     struct {
       __u64 tx_timestamp;
diff --git a/libc/kernel/uapi/linux/iio/types.h b/libc/kernel/uapi/linux/iio/types.h
index f40cb95..6bff5ec 100644
--- a/libc/kernel/uapi/linux/iio/types.h
+++ b/libc/kernel/uapi/linux/iio/types.h
@@ -46,6 +46,7 @@
   IIO_DELTA_VELOCITY,
   IIO_COLORTEMP,
   IIO_CHROMATICITY,
+  IIO_ATTENTION,
 };
 enum iio_modifier {
   IIO_NO_MOD,
@@ -111,6 +112,7 @@
   IIO_EV_TYPE_CHANGE,
   IIO_EV_TYPE_MAG_REFERENCED,
   IIO_EV_TYPE_GESTURE,
+  IIO_EV_TYPE_FAULT,
 };
 enum iio_event_direction {
   IIO_EV_DIR_EITHER,
@@ -119,5 +121,6 @@
   IIO_EV_DIR_NONE,
   IIO_EV_DIR_SINGLETAP,
   IIO_EV_DIR_DOUBLETAP,
+  IIO_EV_DIR_FAULT_OPENWIRE,
 };
 #endif
diff --git a/libc/kernel/uapi/linux/in.h b/libc/kernel/uapi/linux/in.h
index 97bf493..e128d1b 100644
--- a/libc/kernel/uapi/linux/in.h
+++ b/libc/kernel/uapi/linux/in.h
@@ -67,6 +67,8 @@
 #define IPPROTO_MPLS IPPROTO_MPLS
   IPPROTO_ETHERNET = 143,
 #define IPPROTO_ETHERNET IPPROTO_ETHERNET
+  IPPROTO_AGGFRAG = 144,
+#define IPPROTO_AGGFRAG IPPROTO_AGGFRAG
   IPPROTO_RAW = 255,
 #define IPPROTO_RAW IPPROTO_RAW
   IPPROTO_SMC = 256,
diff --git a/libc/kernel/uapi/linux/input-event-codes.h b/libc/kernel/uapi/linux/input-event-codes.h
index 4f93d5e..a48cb83 100644
--- a/libc/kernel/uapi/linux/input-event-codes.h
+++ b/libc/kernel/uapi/linux/input-event-codes.h
@@ -455,6 +455,7 @@
 #define KEY_NOTIFICATION_CENTER 0x1bc
 #define KEY_PICKUP_PHONE 0x1bd
 #define KEY_HANGUP_PHONE 0x1be
+#define KEY_LINK_PHONE 0x1bf
 #define KEY_DEL_EOL 0x1c0
 #define KEY_DEL_EOS 0x1c1
 #define KEY_INS_LINE 0x1c2
@@ -752,7 +753,8 @@
 #define SW_MUTE_DEVICE 0x0e
 #define SW_PEN_INSERTED 0x0f
 #define SW_MACHINE_COVER 0x10
-#define SW_MAX 0x10
+#define SW_USB_INSERT 0x11
+#define SW_MAX 0x11
 #define SW_CNT (SW_MAX + 1)
 #define MSC_SERIAL 0x00
 #define MSC_PULSELED 0x01
diff --git a/libc/kernel/uapi/linux/io_uring.h b/libc/kernel/uapi/linux/io_uring.h
index 5564bff..88a77fd 100644
--- a/libc/kernel/uapi/linux/io_uring.h
+++ b/libc/kernel/uapi/linux/io_uring.h
@@ -60,6 +60,7 @@
     __u32 futex_flags;
     __u32 install_fd_flags;
     __u32 nop_flags;
+    __u32 pipe_flags;
   };
   __u64 user_data;
   union {
@@ -70,21 +71,39 @@
   union {
     __s32 splice_fd_in;
     __u32 file_index;
+    __u32 zcrx_ifq_idx;
     __u32 optlen;
     struct {
       __u16 addr_len;
       __u16 __pad3[1];
     };
+    struct {
+      __u8 write_stream;
+      __u8 __pad4[3];
+    };
   };
   union {
     struct {
       __u64 addr3;
       __u64 __pad2[1];
     };
+    struct {
+      __u64 attr_ptr;
+      __u64 attr_type_mask;
+    };
     __u64 optval;
     __u8 cmd[0];
   };
 };
+#define IORING_RW_ATTR_FLAG_PI (1U << 0)
+struct io_uring_attr_pi {
+  __u16 flags;
+  __u16 app_tag;
+  __u32 len;
+  __u64 addr;
+  __u64 seed;
+  __u64 rsvd;
+};
 #define IORING_FILE_INDEX_ALLOC (~0U)
 enum io_uring_sqe_flags_bit {
   IOSQE_FIXED_FILE_BIT,
@@ -119,6 +138,7 @@
 #define IORING_SETUP_NO_MMAP (1U << 14)
 #define IORING_SETUP_REGISTERED_FD_ONLY (1U << 15)
 #define IORING_SETUP_NO_SQARRAY (1U << 16)
+#define IORING_SETUP_HYBRID_IOPOLL (1U << 17)
 enum io_uring_op {
   IORING_OP_NOP,
   IORING_OP_READV,
@@ -178,6 +198,11 @@
   IORING_OP_FTRUNCATE,
   IORING_OP_BIND,
   IORING_OP_LISTEN,
+  IORING_OP_RECV_ZC,
+  IORING_OP_EPOLL_WAIT,
+  IORING_OP_READV_FIXED,
+  IORING_OP_WRITEV_FIXED,
+  IORING_OP_PIPE,
   IORING_OP_LAST,
 };
 #define IORING_URING_CMD_FIXED (1U << 0)
@@ -220,6 +245,9 @@
 #define IORING_MSG_RING_FLAGS_PASS (1U << 1)
 #define IORING_FIXED_FD_NO_CLOEXEC (1U << 0)
 #define IORING_NOP_INJECT_RESULT (1U << 0)
+#define IORING_NOP_FILE (1U << 1)
+#define IORING_NOP_FIXED_FILE (1U << 2)
+#define IORING_NOP_FIXED_BUFFER (1U << 3)
 struct io_uring_cqe {
   __u64 user_data;
   __s32 res;
@@ -270,6 +298,8 @@
 #define IORING_ENTER_EXT_ARG (1U << 3)
 #define IORING_ENTER_REGISTERED_RING (1U << 4)
 #define IORING_ENTER_ABS_TIMER (1U << 5)
+#define IORING_ENTER_EXT_ARG_REG (1U << 6)
+#define IORING_ENTER_NO_IOWAIT (1U << 7)
 struct io_uring_params {
   __u32 sq_entries;
   __u32 cq_entries;
@@ -298,6 +328,8 @@
 #define IORING_FEAT_REG_REG_RING (1U << 13)
 #define IORING_FEAT_RECVSEND_BUNDLE (1U << 14)
 #define IORING_FEAT_MIN_TIMEOUT (1U << 15)
+#define IORING_FEAT_RW_ATTR (1U << 16)
+#define IORING_FEAT_NO_IOWAIT (1U << 17)
 enum io_uring_register_op {
   IORING_REGISTER_BUFFERS = 0,
   IORING_UNREGISTER_BUFFERS = 1,
@@ -330,6 +362,10 @@
   IORING_UNREGISTER_NAPI = 28,
   IORING_REGISTER_CLOCK = 29,
   IORING_REGISTER_CLONE_BUFFERS = 30,
+  IORING_REGISTER_SEND_MSG_RING = 31,
+  IORING_REGISTER_ZCRX_IFQ = 32,
+  IORING_REGISTER_RESIZE_RINGS = 33,
+  IORING_REGISTER_MEM_REGION = 34,
   IORING_REGISTER_LAST,
   IORING_REGISTER_USE_REGISTERED_RING = 1U << 31
 };
@@ -342,6 +378,25 @@
   __u32 resv;
   __aligned_u64 fds;
 };
+enum {
+  IORING_MEM_REGION_TYPE_USER = 1,
+};
+struct io_uring_region_desc {
+  __u64 user_addr;
+  __u64 size;
+  __u32 flags;
+  __u32 id;
+  __u64 mmap_offset;
+  __u64 __resv[4];
+};
+enum {
+  IORING_MEM_REGION_REG_WAIT_ARG = 1,
+};
+struct io_uring_mem_region_reg {
+  __u64 region_uptr;
+  __u64 flags;
+  __u64 __resv[2];
+};
 #define IORING_RSRC_REGISTER_SPARSE (1U << 0)
 struct io_uring_rsrc_register {
   __u32 nr;
@@ -393,12 +448,16 @@
   __u32 __resv[3];
 };
 enum {
-  IORING_REGISTER_SRC_REGISTERED = 1,
+  IORING_REGISTER_SRC_REGISTERED = (1U << 0),
+  IORING_REGISTER_DST_REPLACE = (1U << 1),
 };
 struct io_uring_clone_buffers {
   __u32 src_fd;
   __u32 flags;
-  __u32 pad[6];
+  __u32 src_off;
+  __u32 dst_off;
+  __u32 nr;
+  __u32 pad[3];
 };
 struct io_uring_buf {
   __u64 addr;
@@ -433,11 +492,23 @@
   __u32 head;
   __u32 resv[8];
 };
+enum io_uring_napi_op {
+  IO_URING_NAPI_REGISTER_OP = 0,
+  IO_URING_NAPI_STATIC_ADD_ID = 1,
+  IO_URING_NAPI_STATIC_DEL_ID = 2
+};
+enum io_uring_napi_tracking_strategy {
+  IO_URING_NAPI_TRACKING_DYNAMIC = 0,
+  IO_URING_NAPI_TRACKING_STATIC = 1,
+  IO_URING_NAPI_TRACKING_INACTIVE = 255
+};
 struct io_uring_napi {
   __u32 busy_poll_to;
   __u8 prefer_busy_poll;
-  __u8 pad[3];
-  __u64 resv;
+  __u8 opcode;
+  __u8 pad[2];
+  __u32 op_param;
+  __u32 resv;
 };
 enum io_uring_register_restriction_op {
   IORING_RESTRICTION_REGISTER_OP = 0,
@@ -446,6 +517,18 @@
   IORING_RESTRICTION_SQE_FLAGS_REQUIRED = 3,
   IORING_RESTRICTION_LAST
 };
+enum {
+  IORING_REG_WAIT_TS = (1U << 0),
+};
+struct io_uring_reg_wait {
+  struct __kernel_timespec ts;
+  __u32 min_wait_usec;
+  __u32 flags;
+  __u64 sigmask;
+  __u32 sigmask_sz;
+  __u32 pad[3];
+  __u64 pad2[2];
+};
 struct io_uring_getevents_arg {
   __u64 sigmask;
   __u32 sigmask_sz;
@@ -478,6 +561,47 @@
   SOCKET_URING_OP_GETSOCKOPT,
   SOCKET_URING_OP_SETSOCKOPT,
 };
+struct io_uring_zcrx_rqe {
+  __u64 off;
+  __u32 len;
+  __u32 __pad;
+};
+struct io_uring_zcrx_cqe {
+  __u64 off;
+  __u64 __pad;
+};
+#define IORING_ZCRX_AREA_SHIFT 48
+#define IORING_ZCRX_AREA_MASK (~(((__u64) 1 << IORING_ZCRX_AREA_SHIFT) - 1))
+struct io_uring_zcrx_offsets {
+  __u32 head;
+  __u32 tail;
+  __u32 rqes;
+  __u32 __resv2;
+  __u64 __resv[2];
+};
+enum io_uring_zcrx_area_flags {
+  IORING_ZCRX_AREA_DMABUF = 1,
+};
+struct io_uring_zcrx_area_reg {
+  __u64 addr;
+  __u64 len;
+  __u64 rq_area_token;
+  __u32 flags;
+  __u32 dmabuf_fd;
+  __u64 __resv2[2];
+};
+struct io_uring_zcrx_ifq_reg {
+  __u32 if_idx;
+  __u32 if_rxq;
+  __u32 rq_entries;
+  __u32 flags;
+  __u64 area_ptr;
+  __u64 region_ptr;
+  struct io_uring_zcrx_offsets offsets;
+  __u32 zcrx_id;
+  __u32 __resv2;
+  __u64 __resv[3];
+};
 #ifdef __cplusplus
 }
 #endif
diff --git a/libc/kernel/uapi/linux/iommufd.h b/libc/kernel/uapi/linux/iommufd.h
index 3bbcd40c6..7dd1f94 100644
--- a/libc/kernel/uapi/linux/iommufd.h
+++ b/libc/kernel/uapi/linux/iommufd.h
@@ -26,6 +26,11 @@
   IOMMUFD_CMD_HWPT_GET_DIRTY_BITMAP = 0x8c,
   IOMMUFD_CMD_HWPT_INVALIDATE = 0x8d,
   IOMMUFD_CMD_FAULT_QUEUE_ALLOC = 0x8e,
+  IOMMUFD_CMD_IOAS_MAP_FILE = 0x8f,
+  IOMMUFD_CMD_VIOMMU_ALLOC = 0x90,
+  IOMMUFD_CMD_VDEVICE_ALLOC = 0x91,
+  IOMMUFD_CMD_IOAS_CHANGE_PROCESS = 0x92,
+  IOMMUFD_CMD_VEVENTQ_ALLOC = 0x93,
 };
 struct iommu_destroy {
   __u32 size;
@@ -74,6 +79,16 @@
   __aligned_u64 iova;
 };
 #define IOMMU_IOAS_MAP _IO(IOMMUFD_TYPE, IOMMUFD_CMD_IOAS_MAP)
+struct iommu_ioas_map_file {
+  __u32 size;
+  __u32 flags;
+  __u32 ioas_id;
+  __s32 fd;
+  __aligned_u64 start;
+  __aligned_u64 length;
+  __aligned_u64 iova;
+};
+#define IOMMU_IOAS_MAP_FILE _IO(IOMMUFD_TYPE, IOMMUFD_CMD_IOAS_MAP_FILE)
 struct iommu_ioas_copy {
   __u32 size;
   __u32 flags;
@@ -124,6 +139,7 @@
   IOMMU_HWPT_ALLOC_NEST_PARENT = 1 << 0,
   IOMMU_HWPT_ALLOC_DIRTY_TRACKING = 1 << 1,
   IOMMU_HWPT_FAULT_ID_VALID = 1 << 2,
+  IOMMU_HWPT_ALLOC_PASID = 1 << 3,
 };
 enum iommu_hwpt_vtd_s1_flags {
   IOMMU_VTD_S1_SRE = 1 << 0,
@@ -136,9 +152,13 @@
   __u32 addr_width;
   __u32 __reserved;
 };
+struct iommu_hwpt_arm_smmuv3 {
+  __aligned_le64 ste[2];
+};
 enum iommu_hwpt_data_type {
   IOMMU_HWPT_DATA_NONE = 0,
   IOMMU_HWPT_DATA_VTD_S1 = 1,
+  IOMMU_HWPT_DATA_ARM_SMMUV3 = 2,
 };
 struct iommu_hwpt_alloc {
   __u32 size;
@@ -163,12 +183,22 @@
   __aligned_u64 cap_reg;
   __aligned_u64 ecap_reg;
 };
+struct iommu_hw_info_arm_smmuv3 {
+  __u32 flags;
+  __u32 __reserved;
+  __u32 idr[6];
+  __u32 iidr;
+  __u32 aidr;
+};
 enum iommu_hw_info_type {
   IOMMU_HW_INFO_TYPE_NONE = 0,
   IOMMU_HW_INFO_TYPE_INTEL_VTD = 1,
+  IOMMU_HW_INFO_TYPE_ARM_SMMUV3 = 2,
 };
 enum iommufd_hw_capabilities {
   IOMMU_HW_CAP_DIRTY_TRACKING = 1 << 0,
+  IOMMU_HW_CAP_PCI_PASID_EXEC = 1 << 1,
+  IOMMU_HW_CAP_PCI_PASID_PRIV = 1 << 2,
 };
 struct iommu_hw_info {
   __u32 size;
@@ -177,7 +207,8 @@
   __u32 data_len;
   __aligned_u64 data_uptr;
   __u32 out_data_type;
-  __u32 __reserved;
+  __u8 out_max_pasid_log2;
+  __u8 __reserved[3];
   __aligned_u64 out_capabilities;
 };
 #define IOMMU_GET_HW_INFO _IO(IOMMUFD_TYPE, IOMMUFD_CMD_GET_HW_INFO)
@@ -207,6 +238,7 @@
 #define IOMMU_HWPT_GET_DIRTY_BITMAP _IO(IOMMUFD_TYPE, IOMMUFD_CMD_HWPT_GET_DIRTY_BITMAP)
 enum iommu_hwpt_invalidate_data_type {
   IOMMU_HWPT_INVALIDATE_DATA_VTD_S1 = 0,
+  IOMMU_VIOMMU_INVALIDATE_DATA_ARM_SMMUV3 = 1,
 };
 enum iommu_hwpt_vtd_s1_invalidate_flags {
   IOMMU_VTD_INV_FLAGS_LEAF = 1 << 0,
@@ -217,6 +249,9 @@
   __u32 flags;
   __u32 __reserved;
 };
+struct iommu_viommu_arm_smmuv3_invalidate {
+  __aligned_le64 cmd[2];
+};
 struct iommu_hwpt_invalidate {
   __u32 size;
   __u32 hwpt_id;
@@ -243,7 +278,8 @@
   __u32 pasid;
   __u32 grpid;
   __u32 perm;
-  __u64 addr;
+  __u32 __reserved;
+  __aligned_u64 addr;
   __u32 length;
   __u32 cookie;
 };
@@ -262,4 +298,55 @@
   __u32 out_fault_fd;
 };
 #define IOMMU_FAULT_QUEUE_ALLOC _IO(IOMMUFD_TYPE, IOMMUFD_CMD_FAULT_QUEUE_ALLOC)
+enum iommu_viommu_type {
+  IOMMU_VIOMMU_TYPE_DEFAULT = 0,
+  IOMMU_VIOMMU_TYPE_ARM_SMMUV3 = 1,
+};
+struct iommu_viommu_alloc {
+  __u32 size;
+  __u32 flags;
+  __u32 type;
+  __u32 dev_id;
+  __u32 hwpt_id;
+  __u32 out_viommu_id;
+};
+#define IOMMU_VIOMMU_ALLOC _IO(IOMMUFD_TYPE, IOMMUFD_CMD_VIOMMU_ALLOC)
+struct iommu_vdevice_alloc {
+  __u32 size;
+  __u32 viommu_id;
+  __u32 dev_id;
+  __u32 out_vdevice_id;
+  __aligned_u64 virt_id;
+};
+#define IOMMU_VDEVICE_ALLOC _IO(IOMMUFD_TYPE, IOMMUFD_CMD_VDEVICE_ALLOC)
+struct iommu_ioas_change_process {
+  __u32 size;
+  __u32 __reserved;
+};
+#define IOMMU_IOAS_CHANGE_PROCESS _IO(IOMMUFD_TYPE, IOMMUFD_CMD_IOAS_CHANGE_PROCESS)
+enum iommu_veventq_flag {
+  IOMMU_VEVENTQ_FLAG_LOST_EVENTS = (1U << 0),
+};
+struct iommufd_vevent_header {
+  __u32 flags;
+  __u32 sequence;
+};
+enum iommu_veventq_type {
+  IOMMU_VEVENTQ_TYPE_DEFAULT = 0,
+  IOMMU_VEVENTQ_TYPE_ARM_SMMUV3 = 1,
+};
+struct iommu_vevent_arm_smmuv3 {
+  __aligned_le64 evt[4];
+};
+struct iommu_veventq_alloc {
+  __u32 size;
+  __u32 flags;
+  __u32 viommu_id;
+  __u32 type;
+  __u32 veventq_depth;
+  __u32 out_veventq_id;
+  __u32 out_veventq_fd;
+  __u32 __reserved;
+};
+#define IOMMU_VEVENTQ_ALLOC _IO(IOMMUFD_TYPE, IOMMUFD_CMD_VEVENTQ_ALLOC)
 #endif
diff --git a/libc/kernel/uapi/linux/ip.h b/libc/kernel/uapi/linux/ip.h
index 332c447..9f10901 100644
--- a/libc/kernel/uapi/linux/ip.h
+++ b/libc/kernel/uapi/linux/ip.h
@@ -103,6 +103,20 @@
   __u8 padlen;
   __u8 reserved;
 };
+struct ip_iptfs_hdr {
+  __u8 subtype;
+  __u8 flags;
+  __be16 block_offset;
+};
+struct ip_iptfs_cc_hdr {
+  __u8 subtype;
+  __u8 flags;
+  __be16 block_offset;
+  __be32 loss_rate;
+  __be64 rtt_adelay_xdelay;
+  __be32 tval;
+  __be32 techo;
+};
 enum {
   IPV4_DEVCONF_FORWARDING = 1,
   IPV4_DEVCONF_MC_FORWARDING,
diff --git a/libc/kernel/uapi/linux/ip6_tunnel.h b/libc/kernel/uapi/linux/ip6_tunnel.h
index 54a379c..50abd57 100644
--- a/libc/kernel/uapi/linux/ip6_tunnel.h
+++ b/libc/kernel/uapi/linux/ip6_tunnel.h
@@ -4,8 +4,8 @@
  * See https://android.googlesource.com/platform/bionic/+/master/libc/kernel/
  * for more information.
  */
-#ifndef _IP6_TUNNEL_H
-#define _IP6_TUNNEL_H
+#ifndef _UAPI_IP6_TUNNEL_H
+#define _UAPI_IP6_TUNNEL_H
 #include <linux/types.h>
 #include <linux/if.h>
 #include <linux/in6.h>
diff --git a/libc/kernel/uapi/linux/ipsec.h b/libc/kernel/uapi/linux/ipsec.h
index 3fe7a1b..c525ad5 100644
--- a/libc/kernel/uapi/linux/ipsec.h
+++ b/libc/kernel/uapi/linux/ipsec.h
@@ -14,7 +14,8 @@
   IPSEC_MODE_ANY = 0,
   IPSEC_MODE_TRANSPORT = 1,
   IPSEC_MODE_TUNNEL = 2,
-  IPSEC_MODE_BEET = 3
+  IPSEC_MODE_BEET = 3,
+  IPSEC_MODE_IPTFS = 4
 };
 enum {
   IPSEC_DIR_ANY = 0,
diff --git a/libc/kernel/uapi/linux/isst_if.h b/libc/kernel/uapi/linux/isst_if.h
index 8d0b64a..6cda5ca 100644
--- a/libc/kernel/uapi/linux/isst_if.h
+++ b/libc/kernel/uapi/linux/isst_if.h
@@ -140,6 +140,16 @@
   __u16 bucket_core_counts[TRL_MAX_BUCKETS];
   __u16 trl_freq_mhz[TRL_MAX_LEVELS][TRL_MAX_BUCKETS];
 };
+#define MAX_FABRIC_COUNT 8
+struct isst_perf_level_fabric_info {
+  __u8 socket_id;
+  __u8 power_domain_id;
+  __u16 level;
+  __u16 max_fabrics;
+  __u16 p0_fabric_freq_mhz[MAX_FABRIC_COUNT];
+  __u16 p1_fabric_freq_mhz[MAX_FABRIC_COUNT];
+  __u16 pm_fabric_freq_mhz[MAX_FABRIC_COUNT];
+};
 struct isst_perf_level_cpu_mask {
   __u8 socket_id;
   __u8 power_domain_id;
@@ -187,4 +197,5 @@
 #define ISST_IF_GET_BASE_FREQ_INFO _IOR(ISST_IF_MAGIC, 14, struct isst_base_freq_info *)
 #define ISST_IF_GET_BASE_FREQ_CPU_MASK _IOR(ISST_IF_MAGIC, 15, struct isst_perf_level_cpu_mask *)
 #define ISST_IF_GET_TURBO_FREQ_INFO _IOR(ISST_IF_MAGIC, 16, struct isst_turbo_freq_info *)
+#define ISST_IF_GET_PERF_LEVEL_FABRIC_INFO _IOR(ISST_IF_MAGIC, 17, struct isst_perf_level_fabric_info *)
 #endif
diff --git a/libc/kernel/uapi/linux/kfd_ioctl.h b/libc/kernel/uapi/linux/kfd_ioctl.h
index 8948a13..8ca9af2 100644
--- a/libc/kernel/uapi/linux/kfd_ioctl.h
+++ b/libc/kernel/uapi/linux/kfd_ioctl.h
@@ -9,7 +9,7 @@
 #include <drm/drm.h>
 #include <linux/ioctl.h>
 #define KFD_IOCTL_MAJOR_VERSION 1
-#define KFD_IOCTL_MINOR_VERSION 17
+#define KFD_IOCTL_MINOR_VERSION 18
 struct kfd_ioctl_get_version_args {
   __u32 major_version;
   __u32 minor_version;
@@ -21,6 +21,7 @@
 #define KFD_IOC_QUEUE_TYPE_SDMA_BY_ENG_ID 0x4
 #define KFD_MAX_QUEUE_PERCENTAGE 100
 #define KFD_MAX_QUEUE_PRIORITY 15
+#define KFD_MIN_QUEUE_RING_SIZE 1024
 struct kfd_ioctl_create_queue_args {
   __u64 ring_base_address;
   __u64 write_pointer_address;
@@ -95,13 +96,14 @@
 };
 #define KFD_IOC_CACHE_POLICY_COHERENT 0
 #define KFD_IOC_CACHE_POLICY_NONCOHERENT 1
+#define KFD_PROC_FLAG_MFMA_HIGH_PRECISION (1 << 0)
 struct kfd_ioctl_set_memory_policy_args {
   __u64 alternate_aperture_base;
   __u64 alternate_aperture_size;
   __u32 gpu_id;
   __u32 default_policy;
   __u32 alternate_policy;
-  __u32 pad;
+  __u32 misc_process_flag;
 };
 struct kfd_ioctl_get_clock_counters_args {
   __u64 gpu_clock_counter;
@@ -334,6 +336,8 @@
   KFD_SMI_EVENT_QUEUE_EVICTION = 9,
   KFD_SMI_EVENT_QUEUE_RESTORE = 10,
   KFD_SMI_EVENT_UNMAP_FROM_GPU = 11,
+  KFD_SMI_EVENT_PROCESS_START = 12,
+  KFD_SMI_EVENT_PROCESS_END = 13,
   KFD_SMI_EVENT_ALL_PROCESS = 64
 };
 enum KFD_MIGRATE_TRIGGERS {
@@ -367,10 +371,11 @@
 #define KFD_EVENT_FMT_PAGEFAULT_START(ns,pid,addr,node,rw) "%lld -%d @%lx(%x) %c\n", (ns), (pid), (addr), (node), (rw)
 #define KFD_EVENT_FMT_PAGEFAULT_END(ns,pid,addr,node,migrate_update) "%lld -%d @%lx(%x) %c\n", (ns), (pid), (addr), (node), (migrate_update)
 #define KFD_EVENT_FMT_MIGRATE_START(ns,pid,start,size,from,to,prefetch_loc,preferred_loc,migrate_trigger) "%lld -%d @%lx(%lx) %x->%x %x:%x %d\n", (ns), (pid), (start), (size), (from), (to), (prefetch_loc), (preferred_loc), (migrate_trigger)
-#define KFD_EVENT_FMT_MIGRATE_END(ns,pid,start,size,from,to,migrate_trigger) "%lld -%d @%lx(%lx) %x->%x %d\n", (ns), (pid), (start), (size), (from), (to), (migrate_trigger)
+#define KFD_EVENT_FMT_MIGRATE_END(ns,pid,start,size,from,to,migrate_trigger,error_code) "%lld -%d @%lx(%lx) %x->%x %d %d\n", (ns), (pid), (start), (size), (from), (to), (migrate_trigger), (error_code)
 #define KFD_EVENT_FMT_QUEUE_EVICTION(ns,pid,node,evict_trigger) "%lld -%d %x %d\n", (ns), (pid), (node), (evict_trigger)
 #define KFD_EVENT_FMT_QUEUE_RESTORE(ns,pid,node,rescheduled) "%lld -%d %x %c\n", (ns), (pid), (node), (rescheduled)
 #define KFD_EVENT_FMT_UNMAP_FROM_GPU(ns,pid,addr,size,node,unmap_trigger) "%lld -%d @%lx(%lx) %x %d\n", (ns), (pid), (addr), (size), (node), (unmap_trigger)
+#define KFD_EVENT_FMT_PROCESS(pid,task_name) "%x %s\n", (pid), (task_name)
 enum kfd_criu_op {
   KFD_CRIU_OP_PROCESS_INFO,
   KFD_CRIU_OP_CHECKPOINT,
diff --git a/libc/kernel/uapi/linux/kfd_sysfs.h b/libc/kernel/uapi/linux/kfd_sysfs.h
index 7771582..119a8de 100644
--- a/libc/kernel/uapi/linux/kfd_sysfs.h
+++ b/libc/kernel/uapi/linux/kfd_sysfs.h
@@ -36,7 +36,10 @@
 #define HSA_CAP_FLAGS_COHERENTHOSTACCESS 0x10000000
 #define HSA_CAP_TRAP_DEBUG_FIRMWARE_SUPPORTED 0x20000000
 #define HSA_CAP_TRAP_DEBUG_PRECISE_ALU_OPERATIONS_SUPPORTED 0x40000000
-#define HSA_CAP_RESERVED 0x800f8000
+#define HSA_CAP_PER_QUEUE_RESET_SUPPORTED 0x80000000
+#define HSA_CAP_RESERVED 0x000f8000
+#define HSA_CAP2_PER_SDMA_QUEUE_RESET_SUPPORTED 0x00000001
+#define HSA_CAP2_RESERVED 0xfffffffe
 #define HSA_DBG_WATCH_ADDR_MASK_LO_BIT_MASK 0x0000000f
 #define HSA_DBG_WATCH_ADDR_MASK_LO_BIT_SHIFT 0
 #define HSA_DBG_WATCH_ADDR_MASK_HI_BIT_MASK 0x000003f0
diff --git a/libc/kernel/uapi/linux/kvm.h b/libc/kernel/uapi/linux/kvm.h
index 297a09d..29de8b0 100644
--- a/libc/kernel/uapi/linux/kvm.h
+++ b/libc/kernel/uapi/linux/kvm.h
@@ -144,6 +144,7 @@
 #define KVM_EXIT_NOTIFY 37
 #define KVM_EXIT_LOONGARCH_IOCSR 38
 #define KVM_EXIT_MEMORY_FAULT 39
+#define KVM_EXIT_TDX 40
 #define KVM_INTERNAL_ERROR_EMULATION 1
 #define KVM_INTERNAL_ERROR_SIMUL_EX 2
 #define KVM_INTERNAL_ERROR_DELIVERY_EV 3
@@ -271,6 +272,7 @@
 #define KVM_SYSTEM_EVENT_WAKEUP 4
 #define KVM_SYSTEM_EVENT_SUSPEND 5
 #define KVM_SYSTEM_EVENT_SEV_TERM 6
+#define KVM_SYSTEM_EVENT_TDX_FATAL 7
       __u32 type;
       __u32 ndata;
       union {
@@ -328,6 +330,30 @@
       __u64 gpa;
       __u64 size;
     } memory_fault;
+    struct {
+      __u64 flags;
+      __u64 nr;
+      union {
+        struct {
+          __u64 ret;
+          __u64 data[5];
+        } unknown;
+        struct {
+          __u64 ret;
+          __u64 gpa;
+          __u64 size;
+        } get_quote;
+        struct {
+          __u64 ret;
+          __u64 leaf;
+          __u64 r11, r12, r13, r14;
+        } get_tdvmcall_info;
+        struct {
+          __u64 ret;
+          __u64 vector;
+        } setup_event_notify;
+      };
+    } tdx;
     char padding[256];
   };
 #define SYNC_REGS_SIZE_BYTES 2048
@@ -446,7 +472,6 @@
 #define KVM_X86_DISABLE_EXITS_HLT (1 << 1)
 #define KVM_X86_DISABLE_EXITS_PAUSE (1 << 2)
 #define KVM_X86_DISABLE_EXITS_CSTATE (1 << 3)
-#define KVM_X86_DISABLE_VALID_EXITS (KVM_X86_DISABLE_EXITS_MWAIT | KVM_X86_DISABLE_EXITS_HLT | KVM_X86_DISABLE_EXITS_PAUSE | KVM_X86_DISABLE_EXITS_CSTATE)
 struct kvm_enable_cap {
   __u32 cap;
   __u32 flags;
@@ -723,6 +748,10 @@
 #define KVM_CAP_PRE_FAULT_MEMORY 236
 #define KVM_CAP_X86_APIC_BUS_CYCLES_NS 237
 #define KVM_CAP_X86_GUEST_MODE 238
+#define KVM_CAP_ARM_WRITABLE_IMP_ID_REGS 239
+#define KVM_CAP_ARM_EL2 240
+#define KVM_CAP_ARM_EL2_E2H0 241
+#define KVM_CAP_RISCV_MP_STATE_RESET 242
 struct kvm_irq_routing_irqchip {
   __u32 irqchip;
   __u32 pin;
@@ -822,6 +851,7 @@
 #define KVM_REG_LOONGARCH 0x9000000000000000ULL
 #define KVM_REG_SIZE_SHIFT 52
 #define KVM_REG_SIZE_MASK 0x00f0000000000000ULL
+#define KVM_REG_SIZE(id) (1U << (((id) & KVM_REG_SIZE_MASK) >> KVM_REG_SIZE_SHIFT))
 #define KVM_REG_SIZE_U8 0x0000000000000000ULL
 #define KVM_REG_SIZE_U16 0x0010000000000000ULL
 #define KVM_REG_SIZE_U32 0x0020000000000000ULL
@@ -894,6 +924,12 @@
 #define KVM_DEV_TYPE_ARM_PV_TIME KVM_DEV_TYPE_ARM_PV_TIME
   KVM_DEV_TYPE_RISCV_AIA,
 #define KVM_DEV_TYPE_RISCV_AIA KVM_DEV_TYPE_RISCV_AIA
+  KVM_DEV_TYPE_LOONGARCH_IPI,
+#define KVM_DEV_TYPE_LOONGARCH_IPI KVM_DEV_TYPE_LOONGARCH_IPI
+  KVM_DEV_TYPE_LOONGARCH_EIOINTC,
+#define KVM_DEV_TYPE_LOONGARCH_EIOINTC KVM_DEV_TYPE_LOONGARCH_EIOINTC
+  KVM_DEV_TYPE_LOONGARCH_PCHPIC,
+#define KVM_DEV_TYPE_LOONGARCH_PCHPIC KVM_DEV_TYPE_LOONGARCH_PCHPIC
   KVM_DEV_TYPE_MAX,
 };
 struct kvm_vfio_spapr_tce {
diff --git a/libc/kernel/uapi/linux/landlock.h b/libc/kernel/uapi/linux/landlock.h
index 8f83780..f99e4ba 100644
--- a/libc/kernel/uapi/linux/landlock.h
+++ b/libc/kernel/uapi/linux/landlock.h
@@ -13,6 +13,10 @@
   __u64 scoped;
 };
 #define LANDLOCK_CREATE_RULESET_VERSION (1U << 0)
+#define LANDLOCK_CREATE_RULESET_ERRATA (1U << 1)
+#define LANDLOCK_RESTRICT_SELF_LOG_SAME_EXEC_OFF (1U << 0)
+#define LANDLOCK_RESTRICT_SELF_LOG_NEW_EXEC_ON (1U << 1)
+#define LANDLOCK_RESTRICT_SELF_LOG_SUBDOMAINS_OFF (1U << 2)
 enum landlock_rule_type {
   LANDLOCK_RULE_PATH_BENEATH = 1,
   LANDLOCK_RULE_NET_PORT,
diff --git a/libc/kernel/uapi/linux/lockd_netlink.h b/libc/kernel/uapi/linux/lockd_netlink.h
new file mode 100644
index 0000000..7510fd3
--- /dev/null
+++ b/libc/kernel/uapi/linux/lockd_netlink.h
@@ -0,0 +1,24 @@
+/*
+ * This file is auto-generated. Modifications will be lost.
+ *
+ * See https://android.googlesource.com/platform/bionic/+/master/libc/kernel/
+ * for more information.
+ */
+#ifndef _UAPI_LINUX_LOCKD_NETLINK_H
+#define _UAPI_LINUX_LOCKD_NETLINK_H
+#define LOCKD_FAMILY_NAME "lockd"
+#define LOCKD_FAMILY_VERSION 1
+enum {
+  LOCKD_A_SERVER_GRACETIME = 1,
+  LOCKD_A_SERVER_TCP_PORT,
+  LOCKD_A_SERVER_UDP_PORT,
+  __LOCKD_A_SERVER_MAX,
+  LOCKD_A_SERVER_MAX = (__LOCKD_A_SERVER_MAX - 1)
+};
+enum {
+  LOCKD_CMD_SERVER_SET = 1,
+  LOCKD_CMD_SERVER_GET,
+  __LOCKD_CMD_MAX,
+  LOCKD_CMD_MAX = (__LOCKD_CMD_MAX - 1)
+};
+#endif
diff --git a/libc/kernel/uapi/linux/mdio.h b/libc/kernel/uapi/linux/mdio.h
index 7a4d4db..d7c56f0 100644
--- a/libc/kernel/uapi/linux/mdio.h
+++ b/libc/kernel/uapi/linux/mdio.h
@@ -99,6 +99,7 @@
 #define MDIO_STAT1_LPOWERABLE 0x0002
 #define MDIO_STAT1_LSTATUS BMSR_LSTATUS
 #define MDIO_STAT1_FAULT 0x0080
+#define MDIO_PCS_STAT1_CLKSTOP_CAP 0x0040
 #define MDIO_AN_STAT1_LPABLE 0x0001
 #define MDIO_AN_STAT1_ABLE BMSR_ANEGCAPABLE
 #define MDIO_AN_STAT1_RFAULT BMSR_RFAULT
diff --git a/libc/kernel/uapi/linux/media-bus-format.h b/libc/kernel/uapi/linux/media-bus-format.h
index cb36554..01f7054 100644
--- a/libc/kernel/uapi/linux/media-bus-format.h
+++ b/libc/kernel/uapi/linux/media-bus-format.h
@@ -40,6 +40,8 @@
 #define MEDIA_BUS_FMT_ARGB8888_1X32 0x100d
 #define MEDIA_BUS_FMT_RGB888_1X32_PADHI 0x100f
 #define MEDIA_BUS_FMT_RGB101010_1X30 0x1018
+#define MEDIA_BUS_FMT_RGB101010_1X7X5_SPWG 0x1026
+#define MEDIA_BUS_FMT_RGB101010_1X7X5_JEIDA 0x1027
 #define MEDIA_BUS_FMT_RGB666_1X36_CPADLO 0x1020
 #define MEDIA_BUS_FMT_RGB888_1X36_CPADLO 0x1021
 #define MEDIA_BUS_FMT_RGB121212_1X36 0x1019
diff --git a/libc/kernel/uapi/linux/media/amlogic/c3-isp-config.h b/libc/kernel/uapi/linux/media/amlogic/c3-isp-config.h
new file mode 100644
index 0000000..65e64bd
--- /dev/null
+++ b/libc/kernel/uapi/linux/media/amlogic/c3-isp-config.h
@@ -0,0 +1,159 @@
+/*
+ * This file is auto-generated. Modifications will be lost.
+ *
+ * See https://android.googlesource.com/platform/bionic/+/master/libc/kernel/
+ * for more information.
+ */
+#ifndef _UAPI_C3_ISP_CONFIG_H_
+#define _UAPI_C3_ISP_CONFIG_H_
+#include <linux/types.h>
+#define C3_ISP_AE_MAX_ZONES (17 * 15)
+#define C3_ISP_AF_MAX_ZONES (17 * 15)
+#define C3_ISP_AWB_MAX_ZONES (32 * 24)
+#define C3_ISP_AE_MAX_PT_NUM 18
+#define C3_ISP_AF_MAX_PT_NUM 18
+#define C3_ISP_AWB_MAX_PT_NUM 33
+struct c3_isp_awb_zone_stats {
+  __u16 rg;
+  __u16 bg;
+  __u32 pixel_sum;
+};
+struct c3_isp_awb_stats {
+  struct c3_isp_awb_zone_stats stats[C3_ISP_AWB_MAX_ZONES];
+} __attribute__((aligned(16)));
+struct c3_isp_ae_zone_stats {
+  __u16 hist0;
+  __u16 hist1;
+  __u16 hist3;
+  __u16 hist4;
+};
+struct c3_isp_ae_stats {
+  struct c3_isp_ae_zone_stats stats[C3_ISP_AE_MAX_ZONES];
+  __u32 reserved[2];
+  __u32 hist[1024];
+} __attribute__((aligned(16)));
+struct c3_isp_af_zone_stats {
+  __u16 i2_mat;
+  __u16 i4_mat;
+  __u16 e4_mat;
+  __u16 e4_exp : 5;
+  __u16 i2_exp : 5;
+  __u16 i4_exp : 6;
+};
+struct c3_isp_af_stats {
+  struct c3_isp_af_zone_stats stats[C3_ISP_AF_MAX_ZONES];
+  __u32 reserved[2];
+} __attribute__((aligned(16)));
+struct c3_isp_stats_info {
+  struct c3_isp_awb_stats awb;
+  struct c3_isp_ae_stats ae;
+  struct c3_isp_af_stats af;
+};
+enum c3_isp_params_buffer_version {
+  C3_ISP_PARAMS_BUFFER_V0,
+};
+enum c3_isp_params_block_type {
+  C3_ISP_PARAMS_BLOCK_AWB_GAINS,
+  C3_ISP_PARAMS_BLOCK_AWB_CONFIG,
+  C3_ISP_PARAMS_BLOCK_AE_CONFIG,
+  C3_ISP_PARAMS_BLOCK_AF_CONFIG,
+  C3_ISP_PARAMS_BLOCK_PST_GAMMA,
+  C3_ISP_PARAMS_BLOCK_CCM,
+  C3_ISP_PARAMS_BLOCK_CSC,
+  C3_ISP_PARAMS_BLOCK_BLC,
+  C3_ISP_PARAMS_BLOCK_SENTINEL
+};
+#define C3_ISP_PARAMS_BLOCK_FL_DISABLE (1U << 0)
+#define C3_ISP_PARAMS_BLOCK_FL_ENABLE (1U << 1)
+struct c3_isp_params_block_header {
+  __u16 type;
+  __u16 flags;
+  __u32 size;
+};
+struct c3_isp_params_awb_gains {
+  struct c3_isp_params_block_header header;
+  __u16 gr_gain;
+  __u16 r_gain;
+  __u16 b_gain;
+  __u16 gb_gain;
+} __attribute__((aligned(8)));
+enum c3_isp_params_awb_tap_points {
+  C3_ISP_AWB_STATS_TAP_OFE = 0,
+  C3_ISP_AWB_STATS_TAP_GE,
+  C3_ISP_AWB_STATS_TAP_BEFORE_WB,
+  C3_ISP_AWB_STATS_TAP_AFTER_WB,
+};
+struct c3_isp_params_awb_config {
+  struct c3_isp_params_block_header header;
+  __u8 tap_point;
+  __u8 satur_vald;
+  __u8 horiz_zones_num;
+  __u8 vert_zones_num;
+  __u16 rg_min;
+  __u16 rg_max;
+  __u16 bg_min;
+  __u16 bg_max;
+  __u16 rg_low;
+  __u16 rg_high;
+  __u16 bg_low;
+  __u16 bg_high;
+  __u8 zone_weight[C3_ISP_AWB_MAX_ZONES];
+  __u16 horiz_coord[C3_ISP_AWB_MAX_PT_NUM];
+  __u16 vert_coord[C3_ISP_AWB_MAX_PT_NUM];
+} __attribute__((aligned(8)));
+enum c3_isp_params_ae_tap_points {
+  C3_ISP_AE_STATS_TAP_GE = 0,
+  C3_ISP_AE_STATS_TAP_MLS,
+};
+struct c3_isp_params_ae_config {
+  struct c3_isp_params_block_header header;
+  __u8 tap_point;
+  __u8 horiz_zones_num;
+  __u8 vert_zones_num;
+  __u8 zone_weight[C3_ISP_AE_MAX_ZONES];
+  __u16 horiz_coord[C3_ISP_AE_MAX_PT_NUM];
+  __u16 vert_coord[C3_ISP_AE_MAX_PT_NUM];
+  __u16 reserved[3];
+} __attribute__((aligned(8)));
+enum c3_isp_params_af_tap_points {
+  C3_ISP_AF_STATS_TAP_SNR = 0,
+  C3_ISP_AF_STATS_TAP_DMS,
+};
+struct c3_isp_params_af_config {
+  struct c3_isp_params_block_header header;
+  __u8 tap_point;
+  __u8 horiz_zones_num;
+  __u8 vert_zones_num;
+  __u8 reserved[5];
+  __u16 horiz_coord[C3_ISP_AF_MAX_PT_NUM];
+  __u16 vert_coord[C3_ISP_AF_MAX_PT_NUM];
+} __attribute__((aligned(8)));
+struct c3_isp_params_pst_gamma {
+  struct c3_isp_params_block_header header;
+  __u16 lut[129];
+  __u16 reserved[3];
+} __attribute__((aligned(8)));
+struct c3_isp_params_ccm {
+  struct c3_isp_params_block_header header;
+  __s16 matrix[3][3];
+  __u16 reserved[3];
+} __attribute__((aligned(8)));
+struct c3_isp_params_csc {
+  struct c3_isp_params_block_header header;
+  __s16 matrix[3][3];
+  __u16 reserved[3];
+} __attribute__((aligned(8)));
+struct c3_isp_params_blc {
+  struct c3_isp_params_block_header header;
+  __u16 gr_ofst;
+  __u16 r_ofst;
+  __u16 b_ofst;
+  __u16 gb_ofst;
+};
+#define C3_ISP_PARAMS_MAX_SIZE (sizeof(struct c3_isp_params_awb_gains) + sizeof(struct c3_isp_params_awb_config) + sizeof(struct c3_isp_params_ae_config) + sizeof(struct c3_isp_params_af_config) + sizeof(struct c3_isp_params_pst_gamma) + sizeof(struct c3_isp_params_ccm) + sizeof(struct c3_isp_params_csc) + sizeof(struct c3_isp_params_blc))
+struct c3_isp_params_cfg {
+  __u32 version;
+  __u32 data_size;
+  __u8 data[C3_ISP_PARAMS_MAX_SIZE];
+};
+#endif
diff --git a/libc/kernel/uapi/linux/media/raspberrypi/pisp_fe_config.h b/libc/kernel/uapi/linux/media/raspberrypi/pisp_fe_config.h
new file mode 100644
index 0000000..5f23237
--- /dev/null
+++ b/libc/kernel/uapi/linux/media/raspberrypi/pisp_fe_config.h
@@ -0,0 +1,218 @@
+/*
+ * This file is auto-generated. Modifications will be lost.
+ *
+ * See https://android.googlesource.com/platform/bionic/+/master/libc/kernel/
+ * for more information.
+ */
+#ifndef _UAPI_PISP_FE_CONFIG_
+#define _UAPI_PISP_FE_CONFIG_
+#include <linux/types.h>
+#include "pisp_common.h"
+#include "pisp_fe_statistics.h"
+#define PISP_FE_NUM_OUTPUTS 2
+enum pisp_fe_enable {
+  PISP_FE_ENABLE_INPUT = 0x000001,
+  PISP_FE_ENABLE_DECOMPRESS = 0x000002,
+  PISP_FE_ENABLE_DECOMPAND = 0x000004,
+  PISP_FE_ENABLE_BLA = 0x000008,
+  PISP_FE_ENABLE_DPC = 0x000010,
+  PISP_FE_ENABLE_STATS_CROP = 0x000020,
+  PISP_FE_ENABLE_DECIMATE = 0x000040,
+  PISP_FE_ENABLE_BLC = 0x000080,
+  PISP_FE_ENABLE_CDAF_STATS = 0x000100,
+  PISP_FE_ENABLE_AWB_STATS = 0x000200,
+  PISP_FE_ENABLE_RGBY = 0x000400,
+  PISP_FE_ENABLE_LSC = 0x000800,
+  PISP_FE_ENABLE_AGC_STATS = 0x001000,
+  PISP_FE_ENABLE_CROP0 = 0x010000,
+  PISP_FE_ENABLE_DOWNSCALE0 = 0x020000,
+  PISP_FE_ENABLE_COMPRESS0 = 0x040000,
+  PISP_FE_ENABLE_OUTPUT0 = 0x080000,
+  PISP_FE_ENABLE_CROP1 = 0x100000,
+  PISP_FE_ENABLE_DOWNSCALE1 = 0x200000,
+  PISP_FE_ENABLE_COMPRESS1 = 0x400000,
+  PISP_FE_ENABLE_OUTPUT1 = 0x800000
+};
+#define PISP_FE_ENABLE_CROP(i) (PISP_FE_ENABLE_CROP0 << (4 * (i)))
+#define PISP_FE_ENABLE_DOWNSCALE(i) (PISP_FE_ENABLE_DOWNSCALE0 << (4 * (i)))
+#define PISP_FE_ENABLE_COMPRESS(i) (PISP_FE_ENABLE_COMPRESS0 << (4 * (i)))
+#define PISP_FE_ENABLE_OUTPUT(i) (PISP_FE_ENABLE_OUTPUT0 << (4 * (i)))
+enum pisp_fe_dirty {
+  PISP_FE_DIRTY_GLOBAL = 0x0001,
+  PISP_FE_DIRTY_FLOATING = 0x0002,
+  PISP_FE_DIRTY_OUTPUT_AXI = 0x0004
+};
+struct pisp_fe_global_config {
+  __u32 enables;
+  __u8 bayer_order;
+  __u8 pad[3];
+} __attribute__((packed));
+struct pisp_fe_input_axi_config {
+  __u8 maxlen_flags;
+  __u8 cache_prot;
+  __u16 qos;
+} __attribute__((packed));
+struct pisp_fe_output_axi_config {
+  __u8 maxlen_flags;
+  __u8 cache_prot;
+  __u16 qos;
+  __u16 thresh;
+  __u16 throttle;
+} __attribute__((packed));
+struct pisp_fe_input_config {
+  __u8 streaming;
+  __u8 pad[3];
+  struct pisp_image_format_config format;
+  struct pisp_fe_input_axi_config axi;
+  __u8 holdoff;
+  __u8 pad2[3];
+} __attribute__((packed));
+struct pisp_fe_output_config {
+  struct pisp_image_format_config format;
+  __u16 ilines;
+  __u8 pad[2];
+} __attribute__((packed));
+struct pisp_fe_input_buffer_config {
+  __u32 addr_lo;
+  __u32 addr_hi;
+  __u16 frame_id;
+  __u16 pad;
+} __attribute__((packed));
+#define PISP_FE_DECOMPAND_LUT_SIZE 65
+struct pisp_fe_decompand_config {
+  __u16 lut[PISP_FE_DECOMPAND_LUT_SIZE];
+  __u16 pad;
+} __attribute__((packed));
+struct pisp_fe_dpc_config {
+  __u8 coeff_level;
+  __u8 coeff_range;
+  __u8 coeff_range2;
+#define PISP_FE_DPC_FLAG_FOLDBACK 1
+#define PISP_FE_DPC_FLAG_VFLAG 2
+  __u8 flags;
+} __attribute__((packed));
+#define PISP_FE_LSC_LUT_SIZE 16
+struct pisp_fe_lsc_config {
+  __u8 shift;
+  __u8 pad0;
+  __u16 scale;
+  __u16 centre_x;
+  __u16 centre_y;
+  __u16 lut[PISP_FE_LSC_LUT_SIZE];
+} __attribute__((packed));
+struct pisp_fe_rgby_config {
+  __u16 gain_r;
+  __u16 gain_g;
+  __u16 gain_b;
+  __u8 maxflag;
+  __u8 pad;
+} __attribute__((packed));
+struct pisp_fe_agc_stats_config {
+  __u16 offset_x;
+  __u16 offset_y;
+  __u16 size_x;
+  __u16 size_y;
+  __u8 weights[PISP_AGC_STATS_NUM_ZONES / 2];
+  __u16 row_offset_x;
+  __u16 row_offset_y;
+  __u16 row_size_x;
+  __u16 row_size_y;
+  __u8 row_shift;
+  __u8 float_shift;
+  __u8 pad1[2];
+} __attribute__((packed));
+struct pisp_fe_awb_stats_config {
+  __u16 offset_x;
+  __u16 offset_y;
+  __u16 size_x;
+  __u16 size_y;
+  __u8 shift;
+  __u8 pad[3];
+  __u16 r_lo;
+  __u16 r_hi;
+  __u16 g_lo;
+  __u16 g_hi;
+  __u16 b_lo;
+  __u16 b_hi;
+} __attribute__((packed));
+struct pisp_fe_floating_stats_region {
+  __u16 offset_x;
+  __u16 offset_y;
+  __u16 size_x;
+  __u16 size_y;
+} __attribute__((packed));
+struct pisp_fe_floating_stats_config {
+  struct pisp_fe_floating_stats_region regions[PISP_FLOATING_STATS_NUM_ZONES];
+} __attribute__((packed));
+#define PISP_FE_CDAF_NUM_WEIGHTS 8
+struct pisp_fe_cdaf_stats_config {
+  __u16 noise_constant;
+  __u16 noise_slope;
+  __u16 offset_x;
+  __u16 offset_y;
+  __u16 size_x;
+  __u16 size_y;
+  __u16 skip_x;
+  __u16 skip_y;
+  __u32 mode;
+} __attribute__((packed));
+struct pisp_fe_stats_buffer_config {
+  __u32 addr_lo;
+  __u32 addr_hi;
+} __attribute__((packed));
+struct pisp_fe_crop_config {
+  __u16 offset_x;
+  __u16 offset_y;
+  __u16 width;
+  __u16 height;
+} __attribute__((packed));
+enum pisp_fe_downscale_flags {
+  DOWNSCALE_BAYER = 1,
+  DOWNSCALE_BIN = 2,
+};
+struct pisp_fe_downscale_config {
+  __u8 xin;
+  __u8 xout;
+  __u8 yin;
+  __u8 yout;
+  __u8 flags;
+  __u8 pad[3];
+  __u16 output_width;
+  __u16 output_height;
+} __attribute__((packed));
+struct pisp_fe_output_buffer_config {
+  __u32 addr_lo;
+  __u32 addr_hi;
+} __attribute__((packed));
+struct pisp_fe_output_branch_config {
+  struct pisp_fe_crop_config crop;
+  struct pisp_fe_downscale_config downscale;
+  struct pisp_compress_config compress;
+  struct pisp_fe_output_config output;
+  __u32 pad;
+} __attribute__((packed));
+struct pisp_fe_config {
+  struct pisp_fe_stats_buffer_config stats_buffer;
+  struct pisp_fe_output_buffer_config output_buffer[PISP_FE_NUM_OUTPUTS];
+  struct pisp_fe_input_buffer_config input_buffer;
+  struct pisp_fe_global_config global;
+  struct pisp_fe_input_config input;
+  struct pisp_decompress_config decompress;
+  struct pisp_fe_decompand_config decompand;
+  struct pisp_bla_config bla;
+  struct pisp_fe_dpc_config dpc;
+  struct pisp_fe_crop_config stats_crop;
+  __u32 spare1;
+  struct pisp_bla_config blc;
+  struct pisp_fe_rgby_config rgby;
+  struct pisp_fe_lsc_config lsc;
+  struct pisp_fe_agc_stats_config agc_stats;
+  struct pisp_fe_awb_stats_config awb_stats;
+  struct pisp_fe_cdaf_stats_config cdaf_stats;
+  struct pisp_fe_floating_stats_config floating_stats;
+  struct pisp_fe_output_axi_config output_axi;
+  struct pisp_fe_output_branch_config ch[PISP_FE_NUM_OUTPUTS];
+  __u32 dirty_flags;
+  __u32 dirty_flags_extra;
+} __attribute__((packed));
+#endif
diff --git a/libc/kernel/uapi/linux/media/raspberrypi/pisp_fe_statistics.h b/libc/kernel/uapi/linux/media/raspberrypi/pisp_fe_statistics.h
new file mode 100644
index 0000000..dd07893
--- /dev/null
+++ b/libc/kernel/uapi/linux/media/raspberrypi/pisp_fe_statistics.h
@@ -0,0 +1,48 @@
+/*
+ * This file is auto-generated. Modifications will be lost.
+ *
+ * See https://android.googlesource.com/platform/bionic/+/master/libc/kernel/
+ * for more information.
+ */
+#ifndef _UAPI_PISP_FE_STATISTICS_H_
+#define _UAPI_PISP_FE_STATISTICS_H_
+#include <linux/types.h>
+#define PISP_FLOATING_STATS_NUM_ZONES 4
+#define PISP_AGC_STATS_NUM_BINS 1024
+#define PISP_AGC_STATS_SIZE 16
+#define PISP_AGC_STATS_NUM_ZONES (PISP_AGC_STATS_SIZE * PISP_AGC_STATS_SIZE)
+#define PISP_AGC_STATS_NUM_ROW_SUMS 512
+struct pisp_agc_statistics_zone {
+  __u64 Y_sum;
+  __u32 counted;
+  __u32 pad;
+} __attribute__((packed));
+struct pisp_agc_statistics {
+  __u32 row_sums[PISP_AGC_STATS_NUM_ROW_SUMS];
+  __u32 histogram[PISP_AGC_STATS_NUM_BINS];
+  struct pisp_agc_statistics_zone floating[PISP_FLOATING_STATS_NUM_ZONES];
+} __attribute__((packed));
+#define PISP_AWB_STATS_SIZE 32
+#define PISP_AWB_STATS_NUM_ZONES (PISP_AWB_STATS_SIZE * PISP_AWB_STATS_SIZE)
+struct pisp_awb_statistics_zone {
+  __u32 R_sum;
+  __u32 G_sum;
+  __u32 B_sum;
+  __u32 counted;
+} __attribute__((packed));
+struct pisp_awb_statistics {
+  struct pisp_awb_statistics_zone zones[PISP_AWB_STATS_NUM_ZONES];
+  struct pisp_awb_statistics_zone floating[PISP_FLOATING_STATS_NUM_ZONES];
+} __attribute__((packed));
+#define PISP_CDAF_STATS_SIZE 8
+#define PISP_CDAF_STATS_NUM_FOMS (PISP_CDAF_STATS_SIZE * PISP_CDAF_STATS_SIZE)
+struct pisp_cdaf_statistics {
+  __u64 foms[PISP_CDAF_STATS_NUM_FOMS];
+  __u64 floating[PISP_FLOATING_STATS_NUM_ZONES];
+} __attribute__((packed));
+struct pisp_statistics {
+  struct pisp_awb_statistics awb;
+  struct pisp_agc_statistics agc;
+  struct pisp_cdaf_statistics cdaf;
+} __attribute__((packed));
+#endif
diff --git a/libc/kernel/uapi/linux/mount.h b/libc/kernel/uapi/linux/mount.h
index c4278b5..20b6297 100644
--- a/libc/kernel/uapi/linux/mount.h
+++ b/libc/kernel/uapi/linux/mount.h
@@ -109,7 +109,18 @@
   __u32 mnt_root;
   __u32 mnt_point;
   __u64 mnt_ns_id;
-  __u64 __spare2[49];
+  __u32 fs_subtype;
+  __u32 sb_source;
+  __u32 opt_num;
+  __u32 opt_array;
+  __u32 opt_sec_num;
+  __u32 opt_sec_array;
+  __u64 supported_mask;
+  __u32 mnt_uidmap_num;
+  __u32 mnt_uidmap;
+  __u32 mnt_gidmap_num;
+  __u32 mnt_gidmap;
+  __u64 __spare2[43];
   char str[];
 };
 struct mnt_id_req {
@@ -129,6 +140,13 @@
 #define STATMOUNT_FS_TYPE 0x00000020U
 #define STATMOUNT_MNT_NS_ID 0x00000040U
 #define STATMOUNT_MNT_OPTS 0x00000080U
+#define STATMOUNT_FS_SUBTYPE 0x00000100U
+#define STATMOUNT_SB_SOURCE 0x00000200U
+#define STATMOUNT_OPT_ARRAY 0x00000400U
+#define STATMOUNT_OPT_SEC_ARRAY 0x00000800U
+#define STATMOUNT_SUPPORTED_MASK 0x00001000U
+#define STATMOUNT_MNT_UIDMAP 0x00002000U
+#define STATMOUNT_MNT_GIDMAP 0x00004000U
 #define LSMT_ROOT 0xffffffffffffffff
 #define LISTMOUNT_REVERSE (1 << 0)
 #endif
diff --git a/libc/kernel/uapi/linux/mshv.h b/libc/kernel/uapi/linux/mshv.h
new file mode 100644
index 0000000..7bace49
--- /dev/null
+++ b/libc/kernel/uapi/linux/mshv.h
@@ -0,0 +1,147 @@
+/*
+ * This file is auto-generated. Modifications will be lost.
+ *
+ * See https://android.googlesource.com/platform/bionic/+/master/libc/kernel/
+ * for more information.
+ */
+#ifndef _UAPI_LINUX_MSHV_H
+#define _UAPI_LINUX_MSHV_H
+#include <linux/types.h>
+#define MSHV_IOCTL 0xB8
+enum {
+  MSHV_PT_BIT_LAPIC,
+  MSHV_PT_BIT_X2APIC,
+  MSHV_PT_BIT_GPA_SUPER_PAGES,
+  MSHV_PT_BIT_COUNT,
+};
+#define MSHV_PT_FLAGS_MASK ((1 << MSHV_PT_BIT_COUNT) - 1)
+enum {
+  MSHV_PT_ISOLATION_NONE,
+  MSHV_PT_ISOLATION_COUNT,
+};
+struct mshv_create_partition {
+  __u64 pt_flags;
+  __u64 pt_isolation;
+};
+#define MSHV_CREATE_PARTITION _IOW(MSHV_IOCTL, 0x00, struct mshv_create_partition)
+struct mshv_create_vp {
+  __u32 vp_index;
+};
+enum {
+  MSHV_SET_MEM_BIT_WRITABLE,
+  MSHV_SET_MEM_BIT_EXECUTABLE,
+  MSHV_SET_MEM_BIT_UNMAP,
+  MSHV_SET_MEM_BIT_COUNT
+};
+#define MSHV_SET_MEM_FLAGS_MASK ((1 << MSHV_SET_MEM_BIT_COUNT) - 1)
+#define MSHV_HV_PAGE_SIZE 0x1000
+struct mshv_user_mem_region {
+  __u64 size;
+  __u64 guest_pfn;
+  __u64 userspace_addr;
+  __u8 flags;
+  __u8 rsvd[7];
+};
+enum {
+  MSHV_IRQFD_BIT_DEASSIGN,
+  MSHV_IRQFD_BIT_RESAMPLE,
+  MSHV_IRQFD_BIT_COUNT,
+};
+#define MSHV_IRQFD_FLAGS_MASK ((1 << MSHV_IRQFD_BIT_COUNT) - 1)
+struct mshv_user_irqfd {
+  __s32 fd;
+  __s32 resamplefd;
+  __u32 gsi;
+  __u32 flags;
+};
+enum {
+  MSHV_IOEVENTFD_BIT_DATAMATCH,
+  MSHV_IOEVENTFD_BIT_PIO,
+  MSHV_IOEVENTFD_BIT_DEASSIGN,
+  MSHV_IOEVENTFD_BIT_COUNT,
+};
+#define MSHV_IOEVENTFD_FLAGS_MASK ((1 << MSHV_IOEVENTFD_BIT_COUNT) - 1)
+struct mshv_user_ioeventfd {
+  __u64 datamatch;
+  __u64 addr;
+  __u32 len;
+  __s32 fd;
+  __u32 flags;
+  __u8 rsvd[4];
+};
+struct mshv_user_irq_entry {
+  __u32 gsi;
+  __u32 address_lo;
+  __u32 address_hi;
+  __u32 data;
+};
+struct mshv_user_irq_table {
+  __u32 nr;
+  __u32 rsvd;
+  struct mshv_user_irq_entry entries[];
+};
+enum {
+  MSHV_GPAP_ACCESS_TYPE_ACCESSED,
+  MSHV_GPAP_ACCESS_TYPE_DIRTY,
+  MSHV_GPAP_ACCESS_TYPE_COUNT
+};
+enum {
+  MSHV_GPAP_ACCESS_OP_NOOP,
+  MSHV_GPAP_ACCESS_OP_CLEAR,
+  MSHV_GPAP_ACCESS_OP_SET,
+  MSHV_GPAP_ACCESS_OP_COUNT
+};
+struct mshv_gpap_access_bitmap {
+  __u8 access_type;
+  __u8 access_op;
+  __u8 rsvd[6];
+  __u64 page_count;
+  __u64 gpap_base;
+  __u64 bitmap_ptr;
+};
+struct mshv_root_hvcall {
+  __u16 code;
+  __u16 reps;
+  __u16 in_sz;
+  __u16 out_sz;
+  __u16 status;
+  __u8 rsvd[6];
+  __u64 in_ptr;
+  __u64 out_ptr;
+};
+#define MSHV_INITIALIZE_PARTITION _IO(MSHV_IOCTL, 0x00)
+#define MSHV_CREATE_VP _IOW(MSHV_IOCTL, 0x01, struct mshv_create_vp)
+#define MSHV_SET_GUEST_MEMORY _IOW(MSHV_IOCTL, 0x02, struct mshv_user_mem_region)
+#define MSHV_IRQFD _IOW(MSHV_IOCTL, 0x03, struct mshv_user_irqfd)
+#define MSHV_IOEVENTFD _IOW(MSHV_IOCTL, 0x04, struct mshv_user_ioeventfd)
+#define MSHV_SET_MSI_ROUTING _IOW(MSHV_IOCTL, 0x05, struct mshv_user_irq_table)
+#define MSHV_GET_GPAP_ACCESS_BITMAP _IOWR(MSHV_IOCTL, 0x06, struct mshv_gpap_access_bitmap)
+#define MSHV_ROOT_HVCALL _IOWR(MSHV_IOCTL, 0x07, struct mshv_root_hvcall)
+#define MSHV_RUN_VP_BUF_SZ 256
+enum {
+  MSHV_VP_MMAP_OFFSET_REGISTERS,
+  MSHV_VP_MMAP_OFFSET_INTERCEPT_MESSAGE,
+  MSHV_VP_MMAP_OFFSET_GHCB,
+  MSHV_VP_MMAP_OFFSET_COUNT
+};
+struct mshv_run_vp {
+  __u8 msg_buf[MSHV_RUN_VP_BUF_SZ];
+};
+enum {
+  MSHV_VP_STATE_LAPIC,
+  MSHV_VP_STATE_XSAVE,
+  MSHV_VP_STATE_SIMP,
+  MSHV_VP_STATE_SIEFP,
+  MSHV_VP_STATE_SYNTHETIC_TIMERS,
+  MSHV_VP_STATE_COUNT,
+};
+struct mshv_get_set_vp_state {
+  __u8 type;
+  __u8 rsvd[3];
+  __u32 buf_sz;
+  __u64 buf_ptr;
+};
+#define MSHV_RUN_VP _IOR(MSHV_IOCTL, 0x00, struct mshv_run_vp)
+#define MSHV_GET_VP_STATE _IOWR(MSHV_IOCTL, 0x01, struct mshv_get_set_vp_state)
+#define MSHV_SET_VP_STATE _IOWR(MSHV_IOCTL, 0x02, struct mshv_get_set_vp_state)
+#endif
diff --git a/libc/kernel/uapi/linux/neighbour.h b/libc/kernel/uapi/linux/neighbour.h
index 7a67601..bb164a0 100644
--- a/libc/kernel/uapi/linux/neighbour.h
+++ b/libc/kernel/uapi/linux/neighbour.h
@@ -4,8 +4,8 @@
  * See https://android.googlesource.com/platform/bionic/+/master/libc/kernel/
  * for more information.
  */
-#ifndef __LINUX_NEIGHBOUR_H
-#define __LINUX_NEIGHBOUR_H
+#ifndef _UAPI__LINUX_NEIGHBOUR_H
+#define _UAPI__LINUX_NEIGHBOUR_H
 #include <linux/types.h>
 #include <linux/netlink.h>
 struct ndmsg {
diff --git a/libc/kernel/uapi/linux/net_dropmon.h b/libc/kernel/uapi/linux/net_dropmon.h
index 2d75388..0dad665 100644
--- a/libc/kernel/uapi/linux/net_dropmon.h
+++ b/libc/kernel/uapi/linux/net_dropmon.h
@@ -4,8 +4,8 @@
  * See https://android.googlesource.com/platform/bionic/+/master/libc/kernel/
  * for more information.
  */
-#ifndef __NET_DROPMON_H
-#define __NET_DROPMON_H
+#ifndef _UAPI__NET_DROPMON_H
+#define _UAPI__NET_DROPMON_H
 #include <linux/types.h>
 #include <linux/netlink.h>
 struct net_dm_drop_point {
diff --git a/libc/kernel/uapi/linux/net_shaper.h b/libc/kernel/uapi/linux/net_shaper.h
new file mode 100644
index 0000000..bd9bb95
--- /dev/null
+++ b/libc/kernel/uapi/linux/net_shaper.h
@@ -0,0 +1,66 @@
+/*
+ * This file is auto-generated. Modifications will be lost.
+ *
+ * See https://android.googlesource.com/platform/bionic/+/master/libc/kernel/
+ * for more information.
+ */
+#ifndef _UAPI_LINUX_NET_SHAPER_H
+#define _UAPI_LINUX_NET_SHAPER_H
+#define NET_SHAPER_FAMILY_NAME "net-shaper"
+#define NET_SHAPER_FAMILY_VERSION 1
+enum net_shaper_scope {
+  NET_SHAPER_SCOPE_UNSPEC,
+  NET_SHAPER_SCOPE_NETDEV,
+  NET_SHAPER_SCOPE_QUEUE,
+  NET_SHAPER_SCOPE_NODE,
+  __NET_SHAPER_SCOPE_MAX,
+  NET_SHAPER_SCOPE_MAX = (__NET_SHAPER_SCOPE_MAX - 1)
+};
+enum net_shaper_metric {
+  NET_SHAPER_METRIC_BPS,
+  NET_SHAPER_METRIC_PPS,
+};
+enum {
+  NET_SHAPER_A_HANDLE = 1,
+  NET_SHAPER_A_METRIC,
+  NET_SHAPER_A_BW_MIN,
+  NET_SHAPER_A_BW_MAX,
+  NET_SHAPER_A_BURST,
+  NET_SHAPER_A_PRIORITY,
+  NET_SHAPER_A_WEIGHT,
+  NET_SHAPER_A_IFINDEX,
+  NET_SHAPER_A_PARENT,
+  NET_SHAPER_A_LEAVES,
+  __NET_SHAPER_A_MAX,
+  NET_SHAPER_A_MAX = (__NET_SHAPER_A_MAX - 1)
+};
+enum {
+  NET_SHAPER_A_HANDLE_SCOPE = 1,
+  NET_SHAPER_A_HANDLE_ID,
+  __NET_SHAPER_A_HANDLE_MAX,
+  NET_SHAPER_A_HANDLE_MAX = (__NET_SHAPER_A_HANDLE_MAX - 1)
+};
+enum {
+  NET_SHAPER_A_CAPS_IFINDEX = 1,
+  NET_SHAPER_A_CAPS_SCOPE,
+  NET_SHAPER_A_CAPS_SUPPORT_METRIC_BPS,
+  NET_SHAPER_A_CAPS_SUPPORT_METRIC_PPS,
+  NET_SHAPER_A_CAPS_SUPPORT_NESTING,
+  NET_SHAPER_A_CAPS_SUPPORT_BW_MIN,
+  NET_SHAPER_A_CAPS_SUPPORT_BW_MAX,
+  NET_SHAPER_A_CAPS_SUPPORT_BURST,
+  NET_SHAPER_A_CAPS_SUPPORT_PRIORITY,
+  NET_SHAPER_A_CAPS_SUPPORT_WEIGHT,
+  __NET_SHAPER_A_CAPS_MAX,
+  NET_SHAPER_A_CAPS_MAX = (__NET_SHAPER_A_CAPS_MAX - 1)
+};
+enum {
+  NET_SHAPER_CMD_GET = 1,
+  NET_SHAPER_CMD_SET,
+  NET_SHAPER_CMD_DELETE,
+  NET_SHAPER_CMD_GROUP,
+  NET_SHAPER_CMD_CAP_GET,
+  __NET_SHAPER_CMD_MAX,
+  NET_SHAPER_CMD_MAX = (__NET_SHAPER_CMD_MAX - 1)
+};
+#endif
diff --git a/libc/kernel/uapi/linux/net_tstamp.h b/libc/kernel/uapi/linux/net_tstamp.h
index b0df344..cf37a90 100644
--- a/libc/kernel/uapi/linux/net_tstamp.h
+++ b/libc/kernel/uapi/linux/net_tstamp.h
@@ -4,10 +4,15 @@
  * See https://android.googlesource.com/platform/bionic/+/master/libc/kernel/
  * for more information.
  */
-#ifndef _NET_TIMESTAMPING_H
-#define _NET_TIMESTAMPING_H
+#ifndef _UAPI_NET_TIMESTAMPING_H
+#define _UAPI_NET_TIMESTAMPING_H
 #include <linux/types.h>
 #include <linux/socket.h>
+enum hwtstamp_provider_qualifier {
+  HWTSTAMP_PROVIDER_QUALIFIER_PRECISE,
+  HWTSTAMP_PROVIDER_QUALIFIER_APPROX,
+  HWTSTAMP_PROVIDER_QUALIFIER_CNT,
+};
 enum {
   SOF_TIMESTAMPING_TX_HARDWARE = (1 << 0),
   SOF_TIMESTAMPING_TX_SOFTWARE = (1 << 1),
@@ -27,10 +32,11 @@
   SOF_TIMESTAMPING_BIND_PHC = (1 << 15),
   SOF_TIMESTAMPING_OPT_ID_TCP = (1 << 16),
   SOF_TIMESTAMPING_OPT_RX_FILTER = (1 << 17),
-  SOF_TIMESTAMPING_LAST = SOF_TIMESTAMPING_OPT_RX_FILTER,
+  SOF_TIMESTAMPING_TX_COMPLETION = (1 << 18),
+  SOF_TIMESTAMPING_LAST = SOF_TIMESTAMPING_TX_COMPLETION,
   SOF_TIMESTAMPING_MASK = (SOF_TIMESTAMPING_LAST - 1) | SOF_TIMESTAMPING_LAST
 };
-#define SOF_TIMESTAMPING_TX_RECORD_MASK (SOF_TIMESTAMPING_TX_HARDWARE | SOF_TIMESTAMPING_TX_SOFTWARE | SOF_TIMESTAMPING_TX_SCHED | SOF_TIMESTAMPING_TX_ACK)
+#define SOF_TIMESTAMPING_TX_RECORD_MASK (SOF_TIMESTAMPING_TX_HARDWARE | SOF_TIMESTAMPING_TX_SOFTWARE | SOF_TIMESTAMPING_TX_SCHED | SOF_TIMESTAMPING_TX_ACK | SOF_TIMESTAMPING_TX_COMPLETION)
 struct so_timestamping {
   int flags;
   int bind_phc;
diff --git a/libc/kernel/uapi/linux/netdev.h b/libc/kernel/uapi/linux/netdev.h
index a7c5706..e97bca7 100644
--- a/libc/kernel/uapi/linux/netdev.h
+++ b/libc/kernel/uapi/linux/netdev.h
@@ -26,6 +26,7 @@
 enum netdev_xsk_flags {
   NETDEV_XSK_FLAGS_TX_TIMESTAMP = 1,
   NETDEV_XSK_FLAGS_TX_CHECKSUM = 2,
+  NETDEV_XSK_FLAGS_TX_LAUNCH_TIME_FIFO = 4,
 };
 enum netdev_queue_type {
   NETDEV_QUEUE_TYPE_RX,
@@ -45,6 +46,10 @@
   NETDEV_A_DEV_MAX = (__NETDEV_A_DEV_MAX - 1)
 };
 enum {
+  __NETDEV_A_IO_URING_PROVIDER_INFO_MAX,
+  NETDEV_A_IO_URING_PROVIDER_INFO_MAX = (__NETDEV_A_IO_URING_PROVIDER_INFO_MAX - 1)
+};
+enum {
   NETDEV_A_PAGE_POOL_ID = 1,
   NETDEV_A_PAGE_POOL_IFINDEX,
   NETDEV_A_PAGE_POOL_NAPI_ID,
@@ -52,6 +57,7 @@
   NETDEV_A_PAGE_POOL_INFLIGHT_MEM,
   NETDEV_A_PAGE_POOL_DETACH_TIME,
   NETDEV_A_PAGE_POOL_DMABUF,
+  NETDEV_A_PAGE_POOL_IO_URING,
   __NETDEV_A_PAGE_POOL_MAX,
   NETDEV_A_PAGE_POOL_MAX = (__NETDEV_A_PAGE_POOL_MAX - 1)
 };
@@ -76,15 +82,24 @@
   NETDEV_A_NAPI_ID,
   NETDEV_A_NAPI_IRQ,
   NETDEV_A_NAPI_PID,
+  NETDEV_A_NAPI_DEFER_HARD_IRQS,
+  NETDEV_A_NAPI_GRO_FLUSH_TIMEOUT,
+  NETDEV_A_NAPI_IRQ_SUSPEND_TIMEOUT,
   __NETDEV_A_NAPI_MAX,
   NETDEV_A_NAPI_MAX = (__NETDEV_A_NAPI_MAX - 1)
 };
 enum {
+  __NETDEV_A_XSK_INFO_MAX,
+  NETDEV_A_XSK_INFO_MAX = (__NETDEV_A_XSK_INFO_MAX - 1)
+};
+enum {
   NETDEV_A_QUEUE_ID = 1,
   NETDEV_A_QUEUE_IFINDEX,
   NETDEV_A_QUEUE_TYPE,
   NETDEV_A_QUEUE_NAPI_ID,
   NETDEV_A_QUEUE_DMABUF,
+  NETDEV_A_QUEUE_IO_URING,
+  NETDEV_A_QUEUE_XSK,
   __NETDEV_A_QUEUE_MAX,
   NETDEV_A_QUEUE_MAX = (__NETDEV_A_QUEUE_MAX - 1)
 };
@@ -145,6 +160,8 @@
   NETDEV_CMD_NAPI_GET,
   NETDEV_CMD_QSTATS_GET,
   NETDEV_CMD_BIND_RX,
+  NETDEV_CMD_NAPI_SET,
+  NETDEV_CMD_BIND_TX,
   __NETDEV_CMD_MAX,
   NETDEV_CMD_MAX = (__NETDEV_CMD_MAX - 1)
 };
diff --git a/libc/kernel/uapi/linux/netfilter/nf_tables.h b/libc/kernel/uapi/linux/netfilter/nf_tables.h
index bfc6e25..d5f92b7 100644
--- a/libc/kernel/uapi/linux/netfilter/nf_tables.h
+++ b/libc/kernel/uapi/linux/netfilter/nf_tables.h
@@ -217,6 +217,8 @@
   NFTA_SET_HANDLE,
   NFTA_SET_EXPR,
   NFTA_SET_EXPRESSIONS,
+  NFTA_SET_TYPE,
+  NFTA_SET_COUNT,
   __NFTA_SET_MAX
 };
 #define NFTA_SET_MAX (__NFTA_SET_MAX - 1)
@@ -285,10 +287,14 @@
 };
 #define NFTA_IMMEDIATE_MAX (__NFTA_IMMEDIATE_MAX - 1)
 enum nft_bitwise_ops {
-  NFT_BITWISE_BOOL,
+  NFT_BITWISE_MASK_XOR,
   NFT_BITWISE_LSHIFT,
   NFT_BITWISE_RSHIFT,
+  NFT_BITWISE_AND,
+  NFT_BITWISE_OR,
+  NFT_BITWISE_XOR,
 };
+#define NFT_BITWISE_BOOL NFT_BITWISE_MASK_XOR
 enum nft_bitwise_attributes {
   NFTA_BITWISE_UNSPEC,
   NFTA_BITWISE_SREG,
@@ -298,6 +304,7 @@
   NFTA_BITWISE_XOR,
   NFTA_BITWISE_OP,
   NFTA_BITWISE_DATA,
+  NFTA_BITWISE_SREG2,
   __NFTA_BITWISE_MAX
 };
 #define NFTA_BITWISE_MAX (__NFTA_BITWISE_MAX - 1)
@@ -954,6 +961,10 @@
   NFTA_TRACE_NFPROTO,
   NFTA_TRACE_POLICY,
   NFTA_TRACE_PAD,
+  NFTA_TRACE_CT_ID,
+  NFTA_TRACE_CT_DIRECTION,
+  NFTA_TRACE_CT_STATUS,
+  NFTA_TRACE_CT_STATE,
   __NFTA_TRACE_MAX
 };
 #define NFTA_TRACE_MAX (__NFTA_TRACE_MAX - 1)
diff --git a/libc/kernel/uapi/linux/netfilter/nfnetlink_conntrack.h b/libc/kernel/uapi/linux/netfilter/nfnetlink_conntrack.h
index b0a1d41..a0e0d10 100644
--- a/libc/kernel/uapi/linux/netfilter/nfnetlink_conntrack.h
+++ b/libc/kernel/uapi/linux/netfilter/nfnetlink_conntrack.h
@@ -56,6 +56,7 @@
   CTA_SYNPROXY,
   CTA_FILTER,
   CTA_STATUS_MASK,
+  CTA_TIMESTAMP_EVENT,
   __CTA_MAX
 };
 #define CTA_MAX (__CTA_MAX - 1)
diff --git a/libc/kernel/uapi/linux/netlink_diag.h b/libc/kernel/uapi/linux/netlink_diag.h
index aef637d..042fed2 100644
--- a/libc/kernel/uapi/linux/netlink_diag.h
+++ b/libc/kernel/uapi/linux/netlink_diag.h
@@ -4,8 +4,8 @@
  * See https://android.googlesource.com/platform/bionic/+/master/libc/kernel/
  * for more information.
  */
-#ifndef __NETLINK_DIAG_H__
-#define __NETLINK_DIAG_H__
+#ifndef _UAPI__NETLINK_DIAG_H__
+#define _UAPI__NETLINK_DIAG_H__
 #include <linux/types.h>
 struct netlink_diag_req {
   __u8 sdiag_family;
diff --git a/libc/kernel/uapi/linux/nfc.h b/libc/kernel/uapi/linux/nfc.h
index 393ce7c..0db8567 100644
--- a/libc/kernel/uapi/linux/nfc.h
+++ b/libc/kernel/uapi/linux/nfc.h
@@ -79,6 +79,7 @@
   NFC_ATTR_VENDOR_ID,
   NFC_ATTR_VENDOR_SUBCMD,
   NFC_ATTR_VENDOR_DATA,
+  NFC_ATTR_TARGET_ATS,
   __NFC_ATTR_AFTER_LAST
 };
 #define NFC_ATTR_MAX (__NFC_ATTR_AFTER_LAST - 1)
@@ -102,6 +103,7 @@
 #define NFC_GB_MAXSIZE 48
 #define NFC_FIRMWARE_NAME_MAXSIZE 32
 #define NFC_ISO15693_UID_MAXSIZE 8
+#define NFC_ATS_MAXSIZE 20
 #define NFC_PROTO_JEWEL 1
 #define NFC_PROTO_MIFARE 2
 #define NFC_PROTO_FELICA 3
diff --git a/libc/kernel/uapi/linux/nfs4.h b/libc/kernel/uapi/linux/nfs4.h
index 6512901..387d862 100644
--- a/libc/kernel/uapi/linux/nfs4.h
+++ b/libc/kernel/uapi/linux/nfs4.h
@@ -43,7 +43,7 @@
 #define NFS4_SHARE_DENY_READ 0x0001
 #define NFS4_SHARE_DENY_WRITE 0x0002
 #define NFS4_SHARE_DENY_BOTH 0x0003
-#define NFS4_SHARE_WANT_MASK 0xFF00
+#define NFS4_SHARE_WANT_TYPE_MASK 0xFF00
 #define NFS4_SHARE_WANT_NO_PREFERENCE 0x0000
 #define NFS4_SHARE_WANT_READ_DELEG 0x0100
 #define NFS4_SHARE_WANT_WRITE_DELEG 0x0200
@@ -53,8 +53,10 @@
 #define NFS4_SHARE_WHEN_MASK 0xF0000
 #define NFS4_SHARE_SIGNAL_DELEG_WHEN_RESRC_AVAIL 0x10000
 #define NFS4_SHARE_PUSH_DELEG_WHEN_UNCONTENDED 0x20000
+#define NFS4_SHARE_WANT_MOD_MASK 0xF00000
 #define NFS4_SHARE_WANT_DELEG_TIMESTAMPS 0x100000
 #define NFS4_SHARE_WANT_OPEN_XOR_DELEGATION 0x200000
+#define NFS4_SHARE_WANT_MASK (NFS4_SHARE_WANT_TYPE_MASK | NFS4_SHARE_WANT_MOD_MASK)
 #define NFS4_CDFC4_FORE 0x1
 #define NFS4_CDFC4_BACK 0x2
 #define NFS4_CDFC4_BOTH 0x3
diff --git a/libc/kernel/uapi/linux/nilfs2_ondisk.h b/libc/kernel/uapi/linux/nilfs2_ondisk.h
index 9df95cb..9f95142 100644
--- a/libc/kernel/uapi/linux/nilfs2_ondisk.h
+++ b/libc/kernel/uapi/linux/nilfs2_ondisk.h
@@ -91,7 +91,7 @@
   __le16 s_checkpoint_size;
   __le16 s_segment_usage_size;
   __u8 s_uuid[16];
-  char s_volume_name[80];
+  char s_volume_name[80] __kernel_nonstring;
   __le32 s_c_interval;
   __le32 s_c_block_max;
   __le64 s_feature_compat;
diff --git a/libc/kernel/uapi/linux/nl80211.h b/libc/kernel/uapi/linux/nl80211.h
index 1bad2f2..5c72c0e 100644
--- a/libc/kernel/uapi/linux/nl80211.h
+++ b/libc/kernel/uapi/linux/nl80211.h
@@ -181,6 +181,8 @@
   NL80211_CMD_SET_HW_TIMESTAMP,
   NL80211_CMD_LINKS_REMOVED,
   NL80211_CMD_SET_TID_TO_LINK_MAPPING,
+  NL80211_CMD_ASSOC_MLO_RECONF,
+  NL80211_CMD_EPCS_CFG,
   __NL80211_CMD_AFTER_LAST,
   NL80211_CMD_MAX = __NL80211_CMD_AFTER_LAST - 1
 };
@@ -530,6 +532,11 @@
   NL80211_ATTR_ASSOC_SPP_AMSDU,
   NL80211_ATTR_WIPHY_RADIOS,
   NL80211_ATTR_WIPHY_INTERFACE_COMBINATIONS,
+  NL80211_ATTR_VIF_RADIO_MASK,
+  NL80211_ATTR_SUPPORTED_SELECTORS,
+  NL80211_ATTR_MLO_RECONF_REM_LINKS,
+  NL80211_ATTR_EPCS,
+  NL80211_ATTR_ASSOC_MLD_EXT_CAPA_OPS,
   __NL80211_ATTR_AFTER_LAST,
   NUM_NL80211_ATTR = __NL80211_ATTR_AFTER_LAST,
   NL80211_ATTR_MAX = __NL80211_ATTR_AFTER_LAST - 1
@@ -563,6 +570,7 @@
 #define NL80211_ATTR_FEATURE_FLAGS NL80211_ATTR_FEATURE_FLAGS
 #define NL80211_WIPHY_NAME_MAXLEN 64
 #define NL80211_MAX_SUPP_RATES 32
+#define NL80211_MAX_SUPP_SELECTORS 128
 #define NL80211_MAX_SUPP_HT_RATES 77
 #define NL80211_MAX_SUPP_REG_RULES 128
 #define NL80211_TKIP_DATA_OFFSET_ENCR_KEY 0
@@ -881,6 +889,7 @@
   NL80211_FREQUENCY_ATTR_NO_6GHZ_AFC_CLIENT,
   NL80211_FREQUENCY_ATTR_CAN_MONITOR,
   NL80211_FREQUENCY_ATTR_ALLOW_6GHZ_VLP_AP,
+  NL80211_FREQUENCY_ATTR_ALLOW_20MHZ_ACTIVITY,
   __NL80211_FREQUENCY_ATTR_AFTER_LAST,
   NL80211_FREQUENCY_ATTR_MAX = __NL80211_FREQUENCY_ATTR_AFTER_LAST - 1
 };
@@ -959,6 +968,7 @@
   NL80211_RRF_NO_6GHZ_VLP_CLIENT = 1 << 22,
   NL80211_RRF_NO_6GHZ_AFC_CLIENT = 1 << 23,
   NL80211_RRF_ALLOW_6GHZ_VLP_AP = 1 << 24,
+  NL80211_RRF_ALLOW_20MHZ_ACTIVITY = 1 << 25,
 };
 #define NL80211_RRF_PASSIVE_SCAN NL80211_RRF_NO_IR
 #define NL80211_RRF_NO_IBSS NL80211_RRF_NO_IR
@@ -1009,6 +1019,7 @@
   NL80211_MNTR_FLAG_OTHER_BSS,
   NL80211_MNTR_FLAG_COOK_FRAMES,
   NL80211_MNTR_FLAG_ACTIVE,
+  NL80211_MNTR_FLAG_SKIP_TX,
   __NL80211_MNTR_FLAG_AFTER_LAST,
   NL80211_MNTR_FLAG_MAX = __NL80211_MNTR_FLAG_AFTER_LAST - 1
 };
@@ -1970,6 +1981,7 @@
   NL80211_MBSSID_CONFIG_ATTR_INDEX,
   NL80211_MBSSID_CONFIG_ATTR_TX_IFINDEX,
   NL80211_MBSSID_CONFIG_ATTR_EMA,
+  NL80211_MBSSID_CONFIG_ATTR_TX_LINK_ID,
   __NL80211_MBSSID_CONFIG_ATTR_LAST,
   NL80211_MBSSID_CONFIG_ATTR_MAX = __NL80211_MBSSID_CONFIG_ATTR_LAST - 1,
 };
@@ -1982,6 +1994,7 @@
   NL80211_WIPHY_RADIO_ATTR_INDEX,
   NL80211_WIPHY_RADIO_ATTR_FREQ_RANGE,
   NL80211_WIPHY_RADIO_ATTR_INTERFACE_COMBINATION,
+  NL80211_WIPHY_RADIO_ATTR_ANTENNA_MASK,
   __NL80211_WIPHY_RADIO_ATTR_LAST,
   NL80211_WIPHY_RADIO_ATTR_MAX = __NL80211_WIPHY_RADIO_ATTR_LAST - 1,
 };
diff --git a/libc/kernel/uapi/linux/ntsync.h b/libc/kernel/uapi/linux/ntsync.h
index 857b31b..2028da4 100644
--- a/libc/kernel/uapi/linux/ntsync.h
+++ b/libc/kernel/uapi/linux/ntsync.h
@@ -8,10 +8,41 @@
 #define __LINUX_NTSYNC_H
 #include <linux/types.h>
 struct ntsync_sem_args {
-  __u32 sem;
   __u32 count;
   __u32 max;
 };
-#define NTSYNC_IOC_CREATE_SEM _IOWR('N', 0x80, struct ntsync_sem_args)
-#define NTSYNC_IOC_SEM_POST _IOWR('N', 0x81, __u32)
+struct ntsync_mutex_args {
+  __u32 owner;
+  __u32 count;
+};
+struct ntsync_event_args {
+  __u32 manual;
+  __u32 signaled;
+};
+#define NTSYNC_WAIT_REALTIME 0x1
+struct ntsync_wait_args {
+  __u64 timeout;
+  __u64 objs;
+  __u32 count;
+  __u32 index;
+  __u32 flags;
+  __u32 owner;
+  __u32 alert;
+  __u32 pad;
+};
+#define NTSYNC_MAX_WAIT_COUNT 64
+#define NTSYNC_IOC_CREATE_SEM _IOW('N', 0x80, struct ntsync_sem_args)
+#define NTSYNC_IOC_WAIT_ANY _IOWR('N', 0x82, struct ntsync_wait_args)
+#define NTSYNC_IOC_WAIT_ALL _IOWR('N', 0x83, struct ntsync_wait_args)
+#define NTSYNC_IOC_CREATE_MUTEX _IOW('N', 0x84, struct ntsync_mutex_args)
+#define NTSYNC_IOC_CREATE_EVENT _IOW('N', 0x87, struct ntsync_event_args)
+#define NTSYNC_IOC_SEM_RELEASE _IOWR('N', 0x81, __u32)
+#define NTSYNC_IOC_MUTEX_UNLOCK _IOWR('N', 0x85, struct ntsync_mutex_args)
+#define NTSYNC_IOC_MUTEX_KILL _IOW('N', 0x86, __u32)
+#define NTSYNC_IOC_EVENT_SET _IOR('N', 0x88, __u32)
+#define NTSYNC_IOC_EVENT_RESET _IOR('N', 0x89, __u32)
+#define NTSYNC_IOC_EVENT_PULSE _IOR('N', 0x8a, __u32)
+#define NTSYNC_IOC_SEM_READ _IOR('N', 0x8b, struct ntsync_sem_args)
+#define NTSYNC_IOC_MUTEX_READ _IOR('N', 0x8c, struct ntsync_mutex_args)
+#define NTSYNC_IOC_EVENT_READ _IOR('N', 0x8d, struct ntsync_event_args)
 #endif
diff --git a/libc/kernel/uapi/linux/ovpn.h b/libc/kernel/uapi/linux/ovpn.h
new file mode 100644
index 0000000..23bfd22
--- /dev/null
+++ b/libc/kernel/uapi/linux/ovpn.h
@@ -0,0 +1,93 @@
+/*
+ * This file is auto-generated. Modifications will be lost.
+ *
+ * See https://android.googlesource.com/platform/bionic/+/master/libc/kernel/
+ * for more information.
+ */
+#ifndef _UAPI_LINUX_OVPN_H
+#define _UAPI_LINUX_OVPN_H
+#define OVPN_FAMILY_NAME "ovpn"
+#define OVPN_FAMILY_VERSION 1
+#define OVPN_NONCE_TAIL_SIZE 8
+enum ovpn_cipher_alg {
+  OVPN_CIPHER_ALG_NONE,
+  OVPN_CIPHER_ALG_AES_GCM,
+  OVPN_CIPHER_ALG_CHACHA20_POLY1305,
+};
+enum ovpn_del_peer_reason {
+  OVPN_DEL_PEER_REASON_TEARDOWN,
+  OVPN_DEL_PEER_REASON_USERSPACE,
+  OVPN_DEL_PEER_REASON_EXPIRED,
+  OVPN_DEL_PEER_REASON_TRANSPORT_ERROR,
+  OVPN_DEL_PEER_REASON_TRANSPORT_DISCONNECT,
+};
+enum ovpn_key_slot {
+  OVPN_KEY_SLOT_PRIMARY,
+  OVPN_KEY_SLOT_SECONDARY,
+};
+enum {
+  OVPN_A_PEER_ID = 1,
+  OVPN_A_PEER_REMOTE_IPV4,
+  OVPN_A_PEER_REMOTE_IPV6,
+  OVPN_A_PEER_REMOTE_IPV6_SCOPE_ID,
+  OVPN_A_PEER_REMOTE_PORT,
+  OVPN_A_PEER_SOCKET,
+  OVPN_A_PEER_SOCKET_NETNSID,
+  OVPN_A_PEER_VPN_IPV4,
+  OVPN_A_PEER_VPN_IPV6,
+  OVPN_A_PEER_LOCAL_IPV4,
+  OVPN_A_PEER_LOCAL_IPV6,
+  OVPN_A_PEER_LOCAL_PORT,
+  OVPN_A_PEER_KEEPALIVE_INTERVAL,
+  OVPN_A_PEER_KEEPALIVE_TIMEOUT,
+  OVPN_A_PEER_DEL_REASON,
+  OVPN_A_PEER_VPN_RX_BYTES,
+  OVPN_A_PEER_VPN_TX_BYTES,
+  OVPN_A_PEER_VPN_RX_PACKETS,
+  OVPN_A_PEER_VPN_TX_PACKETS,
+  OVPN_A_PEER_LINK_RX_BYTES,
+  OVPN_A_PEER_LINK_TX_BYTES,
+  OVPN_A_PEER_LINK_RX_PACKETS,
+  OVPN_A_PEER_LINK_TX_PACKETS,
+  __OVPN_A_PEER_MAX,
+  OVPN_A_PEER_MAX = (__OVPN_A_PEER_MAX - 1)
+};
+enum {
+  OVPN_A_KEYCONF_PEER_ID = 1,
+  OVPN_A_KEYCONF_SLOT,
+  OVPN_A_KEYCONF_KEY_ID,
+  OVPN_A_KEYCONF_CIPHER_ALG,
+  OVPN_A_KEYCONF_ENCRYPT_DIR,
+  OVPN_A_KEYCONF_DECRYPT_DIR,
+  __OVPN_A_KEYCONF_MAX,
+  OVPN_A_KEYCONF_MAX = (__OVPN_A_KEYCONF_MAX - 1)
+};
+enum {
+  OVPN_A_KEYDIR_CIPHER_KEY = 1,
+  OVPN_A_KEYDIR_NONCE_TAIL,
+  __OVPN_A_KEYDIR_MAX,
+  OVPN_A_KEYDIR_MAX = (__OVPN_A_KEYDIR_MAX - 1)
+};
+enum {
+  OVPN_A_IFINDEX = 1,
+  OVPN_A_PEER,
+  OVPN_A_KEYCONF,
+  __OVPN_A_MAX,
+  OVPN_A_MAX = (__OVPN_A_MAX - 1)
+};
+enum {
+  OVPN_CMD_PEER_NEW = 1,
+  OVPN_CMD_PEER_SET,
+  OVPN_CMD_PEER_GET,
+  OVPN_CMD_PEER_DEL,
+  OVPN_CMD_PEER_DEL_NTF,
+  OVPN_CMD_KEY_NEW,
+  OVPN_CMD_KEY_GET,
+  OVPN_CMD_KEY_SWAP,
+  OVPN_CMD_KEY_SWAP_NTF,
+  OVPN_CMD_KEY_DEL,
+  __OVPN_CMD_MAX,
+  OVPN_CMD_MAX = (__OVPN_CMD_MAX - 1)
+};
+#define OVPN_MCGRP_PEERS "peers"
+#endif
diff --git a/libc/kernel/uapi/linux/pci_regs.h b/libc/kernel/uapi/linux/pci_regs.h
index 7083391..e0feb0d 100644
--- a/libc/kernel/uapi/linux/pci_regs.h
+++ b/libc/kernel/uapi/linux/pci_regs.h
@@ -267,6 +267,7 @@
 #define PCI_MSIX_ENTRY_DATA 0x8
 #define PCI_MSIX_ENTRY_VECTOR_CTRL 0xc
 #define PCI_MSIX_ENTRY_CTRL_MASKBIT 0x00000001
+#define PCI_MSIX_ENTRY_CTRL_ST 0xffff0000
 #define PCI_CHSWP_CSR 2
 #define PCI_CHSWP_DHA 0x01
 #define PCI_CHSWP_EIM 0x02
@@ -382,6 +383,7 @@
 #define PCI_EXP_TYPE_RC_EC 0xa
 #define PCI_EXP_FLAGS_SLOT 0x0100
 #define PCI_EXP_FLAGS_IRQ 0x3e00
+#define PCI_EXP_FLAGS_FLIT 0x8000
 #define PCI_EXP_DEVCAP 0x04
 #define PCI_EXP_DEVCAP_PAYLOAD 0x00000007
 #define PCI_EXP_DEVCAP_PHANTOM 0x00000018
@@ -548,10 +550,12 @@
 #define PCI_EXP_DEVCAP2_ATOMIC_COMP64 0x00000100
 #define PCI_EXP_DEVCAP2_ATOMIC_COMP128 0x00000200
 #define PCI_EXP_DEVCAP2_LTR 0x00000800
+#define PCI_EXP_DEVCAP2_TPH_COMP_MASK 0x00003000
 #define PCI_EXP_DEVCAP2_OBFF_MASK 0x000c0000
 #define PCI_EXP_DEVCAP2_OBFF_MSG 0x00040000
 #define PCI_EXP_DEVCAP2_OBFF_WAKE 0x00080000
 #define PCI_EXP_DEVCAP2_EE_PREFIX 0x00200000
+#define PCI_EXP_DEVCAP2_EE_PREFIX_MAX 0x00c00000
 #define PCI_EXP_DEVCTL2 0x28
 #define PCI_EXP_DEVCTL2_COMP_TIMEOUT 0x000f
 #define PCI_EXP_DEVCTL2_COMP_TMOUT_DIS 0x0010
@@ -567,6 +571,7 @@
 #define PCI_EXP_DEVSTA2 0x2a
 #define PCI_CAP_EXP_RC_ENDPOINT_SIZEOF_V2 0x2c
 #define PCI_EXP_LNKCAP2 0x2c
+#define PCI_EXP_LNKCAP2_SLS 0x000000fe
 #define PCI_EXP_LNKCAP2_SLS_2_5GB 0x00000002
 #define PCI_EXP_LNKCAP2_SLS_5_0GB 0x00000004
 #define PCI_EXP_LNKCAP2_SLS_8_0GB 0x00000008
@@ -631,7 +636,8 @@
 #define PCI_EXT_CAP_ID_NPEM 0x29
 #define PCI_EXT_CAP_ID_PL_32GT 0x2A
 #define PCI_EXT_CAP_ID_DOE 0x2E
-#define PCI_EXT_CAP_ID_MAX PCI_EXT_CAP_ID_DOE
+#define PCI_EXT_CAP_ID_PL_64GT 0x31
+#define PCI_EXT_CAP_ID_MAX PCI_EXT_CAP_ID_PL_64GT
 #define PCI_EXT_CAP_DSN_SIZEOF 12
 #define PCI_EXT_CAP_MCAST_ENDPOINT_SIZEOF 40
 #define PCI_ERR_UNCOR_STATUS 0x04
@@ -670,6 +676,9 @@
 #define PCI_ERR_CAP_ECRC_GENE 0x00000040
 #define PCI_ERR_CAP_ECRC_CHKC 0x00000080
 #define PCI_ERR_CAP_ECRC_CHKE 0x00000100
+#define PCI_ERR_CAP_PREFIX_LOG_PRESENT 0x00000800
+#define PCI_ERR_CAP_TLP_LOG_FLIT 0x00040000
+#define PCI_ERR_CAP_TLP_LOG_SIZE 0x00f80000
 #define PCI_ERR_HEADER_LOG 0x1c
 #define PCI_ERR_ROOT_COMMAND 0x2c
 #define PCI_ERR_ROOT_CMD_COR_EN 0x00000001
@@ -685,6 +694,7 @@
 #define PCI_ERR_ROOT_FATAL_RCV 0x00000040
 #define PCI_ERR_ROOT_AER_IRQ 0xf8000000
 #define PCI_ERR_ROOT_ERR_SRC 0x34
+#define PCI_ERR_PREFIX_LOG 0x38
 #define PCI_VC_PORT_CAP1 0x04
 #define PCI_VC_CAP1_EVCC 0x00000007
 #define PCI_VC_CAP1_LPEVCC 0x00000070
@@ -846,15 +856,13 @@
 #define PCI_ACS_EGRESS_BITS 0x05
 #define PCI_ACS_CTRL 0x06
 #define PCI_ACS_EGRESS_CTL_V 0x08
-#define PCI_VSEC_HDR 4
-#define PCI_VSEC_HDR_LEN_SHIFT 20
 #define PCI_SATA_REGS 4
 #define PCI_SATA_REGS_MASK 0xF
 #define PCI_SATA_REGS_INLINE 0xF
 #define PCI_SATA_SIZEOF_SHORT 8
 #define PCI_SATA_SIZEOF_LONG 16
 #define PCI_REBAR_CAP 4
-#define PCI_REBAR_CAP_SIZES 0x00FFFFF0
+#define PCI_REBAR_CAP_SIZES 0xFFFFFFF0
 #define PCI_REBAR_CTRL 8
 #define PCI_REBAR_CTRL_BAR_IDX 0x00000007
 #define PCI_REBAR_CTRL_NBAR_MASK 0x000000E0
@@ -864,14 +872,30 @@
 #define PCI_DPA_CAP 4
 #define PCI_DPA_CAP_SUBSTATE_MASK 0x1F
 #define PCI_DPA_BASE_SIZEOF 16
+#define PCI_EXP_DEVCAP2_TPH_COMP_NONE 0x0
+#define PCI_EXP_DEVCAP2_TPH_COMP_TPH_ONLY 0x1
+#define PCI_EXP_DEVCAP2_TPH_COMP_EXT_TPH 0x3
 #define PCI_TPH_CAP 4
-#define PCI_TPH_CAP_LOC_MASK 0x600
-#define PCI_TPH_LOC_NONE 0x000
-#define PCI_TPH_LOC_CAP 0x200
-#define PCI_TPH_LOC_MSIX 0x400
+#define PCI_TPH_CAP_ST_NS 0x00000001
+#define PCI_TPH_CAP_ST_IV 0x00000002
+#define PCI_TPH_CAP_ST_DS 0x00000004
+#define PCI_TPH_CAP_EXT_TPH 0x00000100
+#define PCI_TPH_CAP_LOC_MASK 0x00000600
+#define PCI_TPH_LOC_NONE 0x00000000
+#define PCI_TPH_LOC_CAP 0x00000200
+#define PCI_TPH_LOC_MSIX 0x00000400
 #define PCI_TPH_CAP_ST_MASK 0x07FF0000
 #define PCI_TPH_CAP_ST_SHIFT 16
 #define PCI_TPH_BASE_SIZEOF 0xc
+#define PCI_TPH_CTRL 8
+#define PCI_TPH_CTRL_MODE_SEL_MASK 0x00000007
+#define PCI_TPH_ST_NS_MODE 0x0
+#define PCI_TPH_ST_IV_MODE 0x1
+#define PCI_TPH_ST_DS_MODE 0x2
+#define PCI_TPH_CTRL_REQ_EN_MASK 0x00000300
+#define PCI_TPH_REQ_DISABLE 0x0
+#define PCI_TPH_REQ_TPH_ONLY 0x1
+#define PCI_TPH_REQ_EXT_TPH 0x3
 #define PCI_EXP_DPC_CAP 0x04
 #define PCI_EXP_DPC_IRQ 0x001F
 #define PCI_EXP_DPC_CAP_RP_EXT 0x0020
@@ -879,6 +903,7 @@
 #define PCI_EXP_DPC_CAP_SW_TRIGGER 0x0080
 #define PCI_EXP_DPC_RP_PIO_LOG_SIZE 0x0F00
 #define PCI_EXP_DPC_CAP_DL_ACTIVE 0x1000
+#define PCI_EXP_DPC_RP_PIO_LOG_SIZE4 0x2000
 #define PCI_EXP_DPC_CTL 0x06
 #define PCI_EXP_DPC_CTL_EN_FATAL 0x0001
 #define PCI_EXP_DPC_CTL_EN_NONFATAL 0x0002
@@ -943,10 +968,13 @@
 #define PCI_DVSEC_HEADER2_ID(x) ((x) & 0xffff)
 #define PCI_DLF_CAP 0x04
 #define PCI_DLF_EXCHANGE_ENABLE 0x80000000
+#define PCI_SECPCI_LE_CTRL 0x0c
 #define PCI_PL_16GT_LE_CTRL 0x20
 #define PCI_PL_16GT_LE_CTRL_DSP_TX_PRESET_MASK 0x0000000F
 #define PCI_PL_16GT_LE_CTRL_USP_TX_PRESET_MASK 0x000000F0
 #define PCI_PL_16GT_LE_CTRL_USP_TX_PRESET_SHIFT 4
+#define PCI_PL_32GT_LE_CTRL 0x20
+#define PCI_PL_64GT_LE_CTRL 0x20
 #define PCI_NPEM_CAP 0x04
 #define PCI_NPEM_CAP_CAPABLE 0x00000001
 #define PCI_NPEM_CTRL 0x08
@@ -993,8 +1021,9 @@
 #define PCI_DOE_DATA_OBJECT_DISC_REQ_3_INDEX 0x000000ff
 #define PCI_DOE_DATA_OBJECT_DISC_REQ_3_VER 0x0000ff00
 #define PCI_DOE_DATA_OBJECT_DISC_RSP_3_VID 0x0000ffff
-#define PCI_DOE_DATA_OBJECT_DISC_RSP_3_PROTOCOL 0x00ff0000
+#define PCI_DOE_DATA_OBJECT_DISC_RSP_3_TYPE 0x00ff0000
 #define PCI_DOE_DATA_OBJECT_DISC_RSP_3_NEXT_INDEX 0xff000000
+#define PCI_DOE_DATA_OBJECT_DISC_RSP_3_PROTOCOL PCI_DOE_DATA_OBJECT_DISC_RSP_3_TYPE
 #define PCI_DVSEC_CXL_PORT 3
 #define PCI_DVSEC_CXL_PORT_CTL 0x0c
 #define PCI_DVSEC_CXL_PORT_CTL_UNMASK_SBR 0x00000001
diff --git a/libc/kernel/uapi/linux/pcitest.h b/libc/kernel/uapi/linux/pcitest.h
index 38e498d..13a3adc 100644
--- a/libc/kernel/uapi/linux/pcitest.h
+++ b/libc/kernel/uapi/linux/pcitest.h
@@ -16,7 +16,13 @@
 #define PCITEST_MSIX _IOW('P', 0x7, int)
 #define PCITEST_SET_IRQTYPE _IOW('P', 0x8, int)
 #define PCITEST_GET_IRQTYPE _IO('P', 0x9)
+#define PCITEST_BARS _IO('P', 0xa)
 #define PCITEST_CLEAR_IRQ _IO('P', 0x10)
+#define PCITEST_IRQ_TYPE_UNDEFINED - 1
+#define PCITEST_IRQ_TYPE_INTX 0
+#define PCITEST_IRQ_TYPE_MSI 1
+#define PCITEST_IRQ_TYPE_MSIX 2
+#define PCITEST_IRQ_TYPE_AUTO 3
 #define PCITEST_FLAGS_USE_DMA 0x00000001
 struct pci_endpoint_test_xfer_param {
   unsigned long size;
diff --git a/libc/kernel/uapi/linux/perf_event.h b/libc/kernel/uapi/linux/perf_event.h
index ec9b856..693609c 100644
--- a/libc/kernel/uapi/linux/perf_event.h
+++ b/libc/kernel/uapi/linux/perf_event.h
@@ -265,7 +265,12 @@
   __u16 sample_max_stack;
   __u16 __reserved_2;
   __u32 aux_sample_size;
-  __u32 __reserved_3;
+  union {
+    __u32 aux_action;
+    struct {
+      __u32 aux_start_paused : 1, aux_pause : 1, aux_resume : 1, __reserved_3 : 29;
+    };
+  };
   __u64 sig_data;
   __u64 config3;
 };
@@ -405,10 +410,10 @@
   PERF_CONTEXT_GUEST_USER = (__u64) - 2560,
   PERF_CONTEXT_MAX = (__u64) - 4095,
 };
-#define PERF_AUX_FLAG_TRUNCATED 0x01
-#define PERF_AUX_FLAG_OVERWRITE 0x02
-#define PERF_AUX_FLAG_PARTIAL 0x04
-#define PERF_AUX_FLAG_COLLISION 0x08
+#define PERF_AUX_FLAG_TRUNCATED 0x0001
+#define PERF_AUX_FLAG_OVERWRITE 0x0002
+#define PERF_AUX_FLAG_PARTIAL 0x0004
+#define PERF_AUX_FLAG_COLLISION 0x0008
 #define PERF_AUX_FLAG_PMU_FORMAT_TYPE_MASK 0xff00
 #define PERF_AUX_FLAG_CORESIGHT_FORMAT_CORESIGHT 0x0000
 #define PERF_AUX_FLAG_CORESIGHT_FORMAT_RAW 0x0100
@@ -433,72 +438,72 @@
 #else
 #error "Unknown endianness"
 #endif
-#define PERF_MEM_OP_NA 0x01
-#define PERF_MEM_OP_LOAD 0x02
-#define PERF_MEM_OP_STORE 0x04
-#define PERF_MEM_OP_PFETCH 0x08
-#define PERF_MEM_OP_EXEC 0x10
+#define PERF_MEM_OP_NA 0x0001
+#define PERF_MEM_OP_LOAD 0x0002
+#define PERF_MEM_OP_STORE 0x0004
+#define PERF_MEM_OP_PFETCH 0x0008
+#define PERF_MEM_OP_EXEC 0x0010
 #define PERF_MEM_OP_SHIFT 0
-#define PERF_MEM_LVL_NA 0x01
-#define PERF_MEM_LVL_HIT 0x02
-#define PERF_MEM_LVL_MISS 0x04
-#define PERF_MEM_LVL_L1 0x08
-#define PERF_MEM_LVL_LFB 0x10
-#define PERF_MEM_LVL_L2 0x20
-#define PERF_MEM_LVL_L3 0x40
-#define PERF_MEM_LVL_LOC_RAM 0x80
-#define PERF_MEM_LVL_REM_RAM1 0x100
-#define PERF_MEM_LVL_REM_RAM2 0x200
-#define PERF_MEM_LVL_REM_CCE1 0x400
-#define PERF_MEM_LVL_REM_CCE2 0x800
+#define PERF_MEM_LVL_NA 0x0001
+#define PERF_MEM_LVL_HIT 0x0002
+#define PERF_MEM_LVL_MISS 0x0004
+#define PERF_MEM_LVL_L1 0x0008
+#define PERF_MEM_LVL_LFB 0x0010
+#define PERF_MEM_LVL_L2 0x0020
+#define PERF_MEM_LVL_L3 0x0040
+#define PERF_MEM_LVL_LOC_RAM 0x0080
+#define PERF_MEM_LVL_REM_RAM1 0x0100
+#define PERF_MEM_LVL_REM_RAM2 0x0200
+#define PERF_MEM_LVL_REM_CCE1 0x0400
+#define PERF_MEM_LVL_REM_CCE2 0x0800
 #define PERF_MEM_LVL_IO 0x1000
 #define PERF_MEM_LVL_UNC 0x2000
 #define PERF_MEM_LVL_SHIFT 5
-#define PERF_MEM_REMOTE_REMOTE 0x01
+#define PERF_MEM_REMOTE_REMOTE 0x0001
 #define PERF_MEM_REMOTE_SHIFT 37
-#define PERF_MEM_LVLNUM_L1 0x01
-#define PERF_MEM_LVLNUM_L2 0x02
-#define PERF_MEM_LVLNUM_L3 0x03
-#define PERF_MEM_LVLNUM_L4 0x04
-#define PERF_MEM_LVLNUM_L2_MHB 0x05
-#define PERF_MEM_LVLNUM_MSC 0x06
-#define PERF_MEM_LVLNUM_UNC 0x08
-#define PERF_MEM_LVLNUM_CXL 0x09
-#define PERF_MEM_LVLNUM_IO 0x0a
-#define PERF_MEM_LVLNUM_ANY_CACHE 0x0b
-#define PERF_MEM_LVLNUM_LFB 0x0c
-#define PERF_MEM_LVLNUM_RAM 0x0d
-#define PERF_MEM_LVLNUM_PMEM 0x0e
-#define PERF_MEM_LVLNUM_NA 0x0f
+#define PERF_MEM_LVLNUM_L1 0x0001
+#define PERF_MEM_LVLNUM_L2 0x0002
+#define PERF_MEM_LVLNUM_L3 0x0003
+#define PERF_MEM_LVLNUM_L4 0x0004
+#define PERF_MEM_LVLNUM_L2_MHB 0x0005
+#define PERF_MEM_LVLNUM_MSC 0x0006
+#define PERF_MEM_LVLNUM_UNC 0x0008
+#define PERF_MEM_LVLNUM_CXL 0x0009
+#define PERF_MEM_LVLNUM_IO 0x000a
+#define PERF_MEM_LVLNUM_ANY_CACHE 0x000b
+#define PERF_MEM_LVLNUM_LFB 0x000c
+#define PERF_MEM_LVLNUM_RAM 0x000d
+#define PERF_MEM_LVLNUM_PMEM 0x000e
+#define PERF_MEM_LVLNUM_NA 0x000f
 #define PERF_MEM_LVLNUM_SHIFT 33
-#define PERF_MEM_SNOOP_NA 0x01
-#define PERF_MEM_SNOOP_NONE 0x02
-#define PERF_MEM_SNOOP_HIT 0x04
-#define PERF_MEM_SNOOP_MISS 0x08
-#define PERF_MEM_SNOOP_HITM 0x10
+#define PERF_MEM_SNOOP_NA 0x0001
+#define PERF_MEM_SNOOP_NONE 0x0002
+#define PERF_MEM_SNOOP_HIT 0x0004
+#define PERF_MEM_SNOOP_MISS 0x0008
+#define PERF_MEM_SNOOP_HITM 0x0010
 #define PERF_MEM_SNOOP_SHIFT 19
-#define PERF_MEM_SNOOPX_FWD 0x01
-#define PERF_MEM_SNOOPX_PEER 0x02
+#define PERF_MEM_SNOOPX_FWD 0x0001
+#define PERF_MEM_SNOOPX_PEER 0x0002
 #define PERF_MEM_SNOOPX_SHIFT 38
-#define PERF_MEM_LOCK_NA 0x01
-#define PERF_MEM_LOCK_LOCKED 0x02
+#define PERF_MEM_LOCK_NA 0x0001
+#define PERF_MEM_LOCK_LOCKED 0x0002
 #define PERF_MEM_LOCK_SHIFT 24
-#define PERF_MEM_TLB_NA 0x01
-#define PERF_MEM_TLB_HIT 0x02
-#define PERF_MEM_TLB_MISS 0x04
-#define PERF_MEM_TLB_L1 0x08
-#define PERF_MEM_TLB_L2 0x10
-#define PERF_MEM_TLB_WK 0x20
-#define PERF_MEM_TLB_OS 0x40
+#define PERF_MEM_TLB_NA 0x0001
+#define PERF_MEM_TLB_HIT 0x0002
+#define PERF_MEM_TLB_MISS 0x0004
+#define PERF_MEM_TLB_L1 0x0008
+#define PERF_MEM_TLB_L2 0x0010
+#define PERF_MEM_TLB_WK 0x0020
+#define PERF_MEM_TLB_OS 0x0040
 #define PERF_MEM_TLB_SHIFT 26
-#define PERF_MEM_BLK_NA 0x01
-#define PERF_MEM_BLK_DATA 0x02
-#define PERF_MEM_BLK_ADDR 0x04
+#define PERF_MEM_BLK_NA 0x0001
+#define PERF_MEM_BLK_DATA 0x0002
+#define PERF_MEM_BLK_ADDR 0x0004
 #define PERF_MEM_BLK_SHIFT 40
-#define PERF_MEM_HOPS_0 0x01
-#define PERF_MEM_HOPS_1 0x02
-#define PERF_MEM_HOPS_2 0x03
-#define PERF_MEM_HOPS_3 0x04
+#define PERF_MEM_HOPS_0 0x0001
+#define PERF_MEM_HOPS_1 0x0002
+#define PERF_MEM_HOPS_2 0x0003
+#define PERF_MEM_HOPS_3 0x0004
 #define PERF_MEM_HOPS_SHIFT 43
 #define PERF_MEM_S(a,s) (((__u64) PERF_MEM_ ##a ##_ ##s) << PERF_MEM_ ##a ##_SHIFT)
 struct perf_branch_entry {
diff --git a/libc/kernel/uapi/linux/pidfd.h b/libc/kernel/uapi/linux/pidfd.h
index 9068727..276f98b 100644
--- a/libc/kernel/uapi/linux/pidfd.h
+++ b/libc/kernel/uapi/linux/pidfd.h
@@ -14,6 +14,38 @@
 #define PIDFD_SIGNAL_THREAD (1UL << 0)
 #define PIDFD_SIGNAL_THREAD_GROUP (1UL << 1)
 #define PIDFD_SIGNAL_PROCESS_GROUP (1UL << 2)
+#define PIDFD_INFO_PID (1UL << 0)
+#define PIDFD_INFO_CREDS (1UL << 1)
+#define PIDFD_INFO_CGROUPID (1UL << 2)
+#define PIDFD_INFO_EXIT (1UL << 3)
+#define PIDFD_INFO_COREDUMP (1UL << 4)
+#define PIDFD_INFO_SIZE_VER0 64
+#define PIDFD_COREDUMPED (1U << 0)
+#define PIDFD_COREDUMP_SKIP (1U << 1)
+#define PIDFD_COREDUMP_USER (1U << 2)
+#define PIDFD_COREDUMP_ROOT (1U << 3)
+#define PIDFD_SELF_THREAD - 10000
+#define PIDFD_SELF_THREAD_GROUP - 20000
+#define PIDFD_SELF PIDFD_SELF_THREAD
+#define PIDFD_SELF_PROCESS PIDFD_SELF_THREAD_GROUP
+struct pidfd_info {
+  __u64 mask;
+  __u64 cgroupid;
+  __u32 pid;
+  __u32 tgid;
+  __u32 ppid;
+  __u32 ruid;
+  __u32 rgid;
+  __u32 euid;
+  __u32 egid;
+  __u32 suid;
+  __u32 sgid;
+  __u32 fsuid;
+  __u32 fsgid;
+  __s32 exit_code;
+  __u32 coredump_mask;
+  __u32 __spare1;
+};
 #define PIDFS_IOCTL_MAGIC 0xFF
 #define PIDFD_GET_CGROUP_NAMESPACE _IO(PIDFS_IOCTL_MAGIC, 1)
 #define PIDFD_GET_IPC_NAMESPACE _IO(PIDFS_IOCTL_MAGIC, 2)
@@ -25,4 +57,5 @@
 #define PIDFD_GET_TIME_FOR_CHILDREN_NAMESPACE _IO(PIDFS_IOCTL_MAGIC, 8)
 #define PIDFD_GET_USER_NAMESPACE _IO(PIDFS_IOCTL_MAGIC, 9)
 #define PIDFD_GET_UTS_NAMESPACE _IO(PIDFS_IOCTL_MAGIC, 10)
+#define PIDFD_GET_INFO _IOWR(PIDFS_IOCTL_MAGIC, 11, struct pidfd_info)
 #endif
diff --git a/libc/kernel/uapi/linux/pkt_cls.h b/libc/kernel/uapi/linux/pkt_cls.h
index c5d8d79..d2f041d 100644
--- a/libc/kernel/uapi/linux/pkt_cls.h
+++ b/libc/kernel/uapi/linux/pkt_cls.h
@@ -4,8 +4,8 @@
  * See https://android.googlesource.com/platform/bionic/+/master/libc/kernel/
  * for more information.
  */
-#ifndef __LINUX_PKT_CLS_H
-#define __LINUX_PKT_CLS_H
+#ifndef _UAPI__LINUX_PKT_CLS_H
+#define _UAPI__LINUX_PKT_CLS_H
 #include <linux/types.h>
 #include <linux/pkt_sched.h>
 #define TC_COOKIE_MAX_SIZE 16
@@ -179,12 +179,7 @@
   int offmask;
 };
 struct tc_u32_sel {
-  /**
-   ** ANDROID FIX: Comment out TAG value to avoid C++ error about using
-   ** a type declared in an anonymous union. This is being fixed upstream
-   ** and should be corrected by the next kernel import.
-   */
-  __struct_group(/*tc_u32_sel_hdr*/, hdr,, unsigned char flags;
+  __struct_group(tc_u32_sel_hdr, hdr,, unsigned char flags;
   unsigned char offshift;
   unsigned char nkeys;
   __be16 offmask;
@@ -519,6 +514,7 @@
   __TCA_FLOWER_KEY_CFM_OPT_MAX,
 };
 #define TCA_FLOWER_KEY_CFM_OPT_MAX (__TCA_FLOWER_KEY_CFM_OPT_MAX - 1)
+#define TCA_FLOWER_KEY_CFM_MAX (__TCA_FLOWER_KEY_CFM_OPT_MAX - 1)
 #define TCA_FLOWER_MASK_FLAGS_RANGE (1 << 0)
 struct tc_matchall_pcnt {
   __u64 rhit;
diff --git a/libc/kernel/uapi/linux/pkt_sched.h b/libc/kernel/uapi/linux/pkt_sched.h
index c3488c2..08f168d 100644
--- a/libc/kernel/uapi/linux/pkt_sched.h
+++ b/libc/kernel/uapi/linux/pkt_sched.h
@@ -4,8 +4,8 @@
  * See https://android.googlesource.com/platform/bionic/+/master/libc/kernel/
  * for more information.
  */
-#ifndef __LINUX_PKT_SCHED_H
-#define __LINUX_PKT_SCHED_H
+#ifndef _UAPI__LINUX_PKT_SCHED_H
+#define _UAPI__LINUX_PKT_SCHED_H
 #include <linux/const.h>
 #include <linux/types.h>
 #define TC_PRIO_BESTEFFORT 0
@@ -591,6 +591,7 @@
   TCA_FQ_HORIZON_DROP,
   TCA_FQ_PRIOMAP,
   TCA_FQ_WEIGHTS,
+  TCA_FQ_OFFLOAD_HORIZON,
   __TCA_FQ_MAX
 };
 #define TCA_FQ_MAX (__TCA_FQ_MAX - 1)
@@ -866,6 +867,7 @@
   TCA_TAPRIO_ATTR_SCHED_SINGLE_ENTRY,
   TCA_TAPRIO_ATTR_SCHED_CLOCKID,
   TCA_TAPRIO_PAD,
+  TCA_TAPRIO_ATTR_PAD = TCA_TAPRIO_PAD,
   TCA_TAPRIO_ATTR_ADMIN_SCHED,
   TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME,
   TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME_EXTENSION,
diff --git a/libc/kernel/uapi/linux/pps_gen.h b/libc/kernel/uapi/linux/pps_gen.h
new file mode 100644
index 0000000..e83addf
--- /dev/null
+++ b/libc/kernel/uapi/linux/pps_gen.h
@@ -0,0 +1,19 @@
+/*
+ * This file is auto-generated. Modifications will be lost.
+ *
+ * See https://android.googlesource.com/platform/bionic/+/master/libc/kernel/
+ * for more information.
+ */
+#ifndef _PPS_GEN_H_
+#define _PPS_GEN_H_
+#include <linux/types.h>
+#include <linux/ioctl.h>
+struct pps_gen_event {
+  unsigned int event;
+  unsigned int sequence;
+};
+#define PPS_GEN_EVENT_MISSEDPULSE 1
+#define PPS_GEN_SETENABLE _IOW('p', 0xb1, unsigned int *)
+#define PPS_GEN_USESYSTEMCLOCK _IOR('p', 0xb2, unsigned int *)
+#define PPS_GEN_FETCHEVENT _IOR('p', 0xb3, struct pps_gen_event *)
+#endif
diff --git a/libc/kernel/uapi/linux/prctl.h b/libc/kernel/uapi/linux/prctl.h
index 136a10f..338dcec 100644
--- a/libc/kernel/uapi/linux/prctl.h
+++ b/libc/kernel/uapi/linux/prctl.h
@@ -149,6 +149,8 @@
 #define PR_MTE_TAG_SHIFT 3
 #define PR_MTE_TAG_MASK (0xffffUL << PR_MTE_TAG_SHIFT)
 #define PR_MTE_TCF_SHIFT 1
+#define PR_PMLEN_SHIFT 24
+#define PR_PMLEN_MASK (0x7fUL << PR_PMLEN_SHIFT)
 #define PR_SET_IO_FLUSHER 57
 #define PR_GET_IO_FLUSHER 58
 #define PR_SET_SYSCALL_USER_DISPATCH 59
@@ -207,4 +209,19 @@
 #define PR_PPC_DEXCR_CTRL_SET_ONEXEC 0x8
 #define PR_PPC_DEXCR_CTRL_CLEAR_ONEXEC 0x10
 #define PR_PPC_DEXCR_CTRL_MASK 0x1f
+#define PR_GET_SHADOW_STACK_STATUS 74
+#define PR_SET_SHADOW_STACK_STATUS 75
+#define PR_SHADOW_STACK_ENABLE (1UL << 0)
+#define PR_SHADOW_STACK_WRITE (1UL << 1)
+#define PR_SHADOW_STACK_PUSH (1UL << 2)
+#define PR_LOCK_SHADOW_STACK_STATUS 76
+#define PR_TIMER_CREATE_RESTORE_IDS 77
+#define PR_TIMER_CREATE_RESTORE_IDS_OFF 0
+#define PR_TIMER_CREATE_RESTORE_IDS_ON 1
+#define PR_TIMER_CREATE_RESTORE_IDS_GET 2
+#define PR_FUTEX_HASH 78
+#define PR_FUTEX_HASH_SET_SLOTS 1
+#define FH_FLAG_IMMUTABLE (1ULL << 0)
+#define PR_FUTEX_HASH_GET_SLOTS 2
+#define PR_FUTEX_HASH_GET_IMMUTABLE 3
 #endif
diff --git a/libc/kernel/uapi/linux/psci.h b/libc/kernel/uapi/linux/psci.h
index 343268f..9461c82 100644
--- a/libc/kernel/uapi/linux/psci.h
+++ b/libc/kernel/uapi/linux/psci.h
@@ -37,6 +37,7 @@
 #define PSCI_1_1_FN_SYSTEM_RESET2 PSCI_0_2_FN(18)
 #define PSCI_1_1_FN_MEM_PROTECT PSCI_0_2_FN(19)
 #define PSCI_1_1_FN_MEM_PROTECT_CHECK_RANGE PSCI_0_2_FN(20)
+#define PSCI_1_3_FN_SYSTEM_OFF2 PSCI_0_2_FN(21)
 #define PSCI_1_0_FN64_CPU_DEFAULT_SUSPEND PSCI_0_2_FN64(12)
 #define PSCI_1_0_FN64_NODE_HW_STATE PSCI_0_2_FN64(13)
 #define PSCI_1_0_FN64_SYSTEM_SUSPEND PSCI_0_2_FN64(14)
@@ -44,6 +45,7 @@
 #define PSCI_1_0_FN64_STAT_COUNT PSCI_0_2_FN64(17)
 #define PSCI_1_1_FN64_SYSTEM_RESET2 PSCI_0_2_FN64(18)
 #define PSCI_1_1_FN64_MEM_PROTECT_CHECK_RANGE PSCI_0_2_FN64(20)
+#define PSCI_1_3_FN64_SYSTEM_OFF2 PSCI_0_2_FN64(21)
 #define PSCI_0_2_POWER_STATE_ID_MASK 0xffff
 #define PSCI_0_2_POWER_STATE_ID_SHIFT 0
 #define PSCI_0_2_POWER_STATE_TYPE_SHIFT 16
@@ -62,6 +64,7 @@
 #define PSCI_0_2_TOS_MP 2
 #define PSCI_1_1_RESET_TYPE_SYSTEM_WARM_RESET 0
 #define PSCI_1_1_RESET_TYPE_VENDOR_START 0x80000000U
+#define PSCI_1_3_OFF_TYPE_HIBERNATE_OFF BIT(0)
 #define PSCI_VERSION_MAJOR_SHIFT 16
 #define PSCI_VERSION_MINOR_MASK ((1U << PSCI_VERSION_MAJOR_SHIFT) - 1)
 #define PSCI_VERSION_MAJOR_MASK ~PSCI_VERSION_MINOR_MASK
diff --git a/libc/kernel/uapi/linux/psp-sev.h b/libc/kernel/uapi/linux/psp-sev.h
index 7274081..24ffb1f 100644
--- a/libc/kernel/uapi/linux/psp-sev.h
+++ b/libc/kernel/uapi/linux/psp-sev.h
@@ -51,13 +51,20 @@
   SEV_RET_INVALID_PARAM,
   SEV_RET_RESOURCE_LIMIT,
   SEV_RET_SECURE_DATA_INVALID,
-  SEV_RET_INVALID_KEY = 0x27,
-  SEV_RET_INVALID_PAGE_SIZE,
-  SEV_RET_INVALID_PAGE_STATE,
-  SEV_RET_INVALID_MDATA_ENTRY,
-  SEV_RET_INVALID_PAGE_OWNER,
-  SEV_RET_INVALID_PAGE_AEAD_OFLOW,
-  SEV_RET_RMP_INIT_REQUIRED,
+  SEV_RET_INVALID_PAGE_SIZE = 0x0019,
+  SEV_RET_INVALID_PAGE_STATE = 0x001A,
+  SEV_RET_INVALID_MDATA_ENTRY = 0x001B,
+  SEV_RET_INVALID_PAGE_OWNER = 0x001C,
+  SEV_RET_AEAD_OFLOW = 0x001D,
+  SEV_RET_EXIT_RING_BUFFER = 0x001F,
+  SEV_RET_RMP_INIT_REQUIRED = 0x0020,
+  SEV_RET_BAD_SVN = 0x0021,
+  SEV_RET_BAD_VERSION = 0x0022,
+  SEV_RET_SHUTDOWN_REQUIRED = 0x0023,
+  SEV_RET_UPDATE_FAILED = 0x0024,
+  SEV_RET_RESTORE_REQUIRED = 0x0025,
+  SEV_RET_RMP_INITIALIZATION_FAILED = 0x0026,
+  SEV_RET_INVALID_KEY = 0x0027,
   SEV_RET_MAX,
 } sev_ret_code;
 struct sev_user_data_status {
diff --git a/libc/kernel/uapi/linux/ptrace.h b/libc/kernel/uapi/linux/ptrace.h
index 7bb5b09..2083fdb 100644
--- a/libc/kernel/uapi/linux/ptrace.h
+++ b/libc/kernel/uapi/linux/ptrace.h
@@ -44,13 +44,15 @@
   __u64 flags;
 };
 #define PTRACE_GET_SYSCALL_INFO 0x420e
+#define PTRACE_SET_SYSCALL_INFO 0x4212
 #define PTRACE_SYSCALL_INFO_NONE 0
 #define PTRACE_SYSCALL_INFO_ENTRY 1
 #define PTRACE_SYSCALL_INFO_EXIT 2
 #define PTRACE_SYSCALL_INFO_SECCOMP 3
 struct ptrace_syscall_info {
   __u8 op;
-  __u8 pad[3];
+  __u8 reserved;
+  __u16 flags;
   __u32 arch;
   __u64 instruction_pointer;
   __u64 stack_pointer;
@@ -67,6 +69,7 @@
       __u64 nr;
       __u64 args[6];
       __u32 ret_data;
+      __u32 reserved2;
     } seccomp;
   };
 };
diff --git a/libc/kernel/uapi/linux/raid/md_u.h b/libc/kernel/uapi/linux/raid/md_u.h
index f291f64..0d0c117 100644
--- a/libc/kernel/uapi/linux/raid/md_u.h
+++ b/libc/kernel/uapi/linux/raid/md_u.h
@@ -57,6 +57,7 @@
   int layout;
   int chunk_size;
 } mdu_array_info_t;
+#define LEVEL_LINEAR (- 1)
 #define LEVEL_NONE (- 1000000)
 typedef struct mdu_disk_info_s {
   int number;
diff --git a/libc/kernel/uapi/linux/reiserfs_fs.h b/libc/kernel/uapi/linux/reiserfs_fs.h
deleted file mode 100644
index e0bd0a0..0000000
--- a/libc/kernel/uapi/linux/reiserfs_fs.h
+++ /dev/null
@@ -1,16 +0,0 @@
-/*
- * This file is auto-generated. Modifications will be lost.
- *
- * See https://android.googlesource.com/platform/bionic/+/master/libc/kernel/
- * for more information.
- */
-#ifndef _LINUX_REISER_FS_H
-#define _LINUX_REISER_FS_H
-#include <linux/types.h>
-#include <linux/magic.h>
-#define REISERFS_IOC_UNPACK _IOW(0xCD, 1, long)
-#define REISERFS_IOC_GETFLAGS FS_IOC_GETFLAGS
-#define REISERFS_IOC_SETFLAGS FS_IOC_SETFLAGS
-#define REISERFS_IOC_GETVERSION FS_IOC_GETVERSION
-#define REISERFS_IOC_SETVERSION FS_IOC_SETVERSION
-#endif
diff --git a/libc/kernel/uapi/linux/reiserfs_xattr.h b/libc/kernel/uapi/linux/reiserfs_xattr.h
deleted file mode 100644
index 2caed30..0000000
--- a/libc/kernel/uapi/linux/reiserfs_xattr.h
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * This file is auto-generated. Modifications will be lost.
- *
- * See https://android.googlesource.com/platform/bionic/+/master/libc/kernel/
- * for more information.
- */
-#ifndef _LINUX_REISERFS_XATTR_H
-#define _LINUX_REISERFS_XATTR_H
-#include <linux/types.h>
-#define REISERFS_XATTR_MAGIC 0x52465841
-struct reiserfs_xattr_header {
-  __le32 h_magic;
-  __le32 h_hash;
-};
-struct reiserfs_security_handle {
-  const char * name;
-  void * value;
-  __kernel_size_t length;
-};
-#endif
diff --git a/libc/kernel/uapi/linux/rtnetlink.h b/libc/kernel/uapi/linux/rtnetlink.h
index 70038f2..a534feb 100644
--- a/libc/kernel/uapi/linux/rtnetlink.h
+++ b/libc/kernel/uapi/linux/rtnetlink.h
@@ -75,9 +75,17 @@
 #define RTM_GETACTION RTM_GETACTION
   RTM_NEWPREFIX = 52,
 #define RTM_NEWPREFIX RTM_NEWPREFIX
-  RTM_GETMULTICAST = 58,
+  RTM_NEWMULTICAST = 56,
+#define RTM_NEWMULTICAST RTM_NEWMULTICAST
+  RTM_DELMULTICAST,
+#define RTM_DELMULTICAST RTM_DELMULTICAST
+  RTM_GETMULTICAST,
 #define RTM_GETMULTICAST RTM_GETMULTICAST
-  RTM_GETANYCAST = 62,
+  RTM_NEWANYCAST = 60,
+#define RTM_NEWANYCAST RTM_NEWANYCAST
+  RTM_DELANYCAST,
+#define RTM_DELANYCAST RTM_DELANYCAST
+  RTM_GETANYCAST,
 #define RTM_GETANYCAST RTM_GETANYCAST
   RTM_NEWNEIGHTBL = 64,
 #define RTM_NEWNEIGHTBL RTM_NEWNEIGHTBL
@@ -142,7 +150,7 @@
   RTM_GETLINKPROP,
 #define RTM_GETLINKPROP RTM_GETLINKPROP
   RTM_NEWVLAN = 112,
-#define RTM_NEWNVLAN RTM_NEWVLAN
+#define RTM_NEWVLAN RTM_NEWVLAN
   RTM_DELVLAN,
 #define RTM_DELVLAN RTM_DELVLAN
   RTM_GETVLAN,
@@ -221,6 +229,7 @@
 #define RTPROT_MROUTED 17
 #define RTPROT_KEEPALIVED 18
 #define RTPROT_BABEL 42
+#define RTPROT_OVN 84
 #define RTPROT_OPENR 99
 #define RTPROT_BGP 186
 #define RTPROT_ISIS 187
@@ -283,6 +292,7 @@
   RTA_SPORT,
   RTA_DPORT,
   RTA_NH_ID,
+  RTA_FLOWLABEL,
   __RTA_MAX
 };
 #define RTA_MAX (__RTA_MAX - 1)
@@ -563,6 +573,12 @@
 #define RTNLGRP_TUNNEL RTNLGRP_TUNNEL
   RTNLGRP_STATS,
 #define RTNLGRP_STATS RTNLGRP_STATS
+  RTNLGRP_IPV4_MCADDR,
+#define RTNLGRP_IPV4_MCADDR RTNLGRP_IPV4_MCADDR
+  RTNLGRP_IPV6_MCADDR,
+#define RTNLGRP_IPV6_MCADDR RTNLGRP_IPV6_MCADDR
+  RTNLGRP_IPV6_ACADDR,
+#define RTNLGRP_IPV6_ACADDR RTNLGRP_IPV6_ACADDR
   __RTNLGRP_MAX
 };
 #define RTNLGRP_MAX (__RTNLGRP_MAX - 1)
diff --git a/libc/kernel/uapi/linux/rxrpc.h b/libc/kernel/uapi/linux/rxrpc.h
index 5b60716..2b1edca 100644
--- a/libc/kernel/uapi/linux/rxrpc.h
+++ b/libc/kernel/uapi/linux/rxrpc.h
@@ -26,6 +26,7 @@
 #define RXRPC_MIN_SECURITY_LEVEL 4
 #define RXRPC_UPGRADEABLE_SERVICE 5
 #define RXRPC_SUPPORTED_CMSG 6
+#define RXRPC_MANAGE_RESPONSE 7
 enum rxrpc_cmsg_type {
   RXRPC_USER_CALL_ID = 1,
   RXRPC_ABORT = 2,
@@ -39,6 +40,11 @@
   RXRPC_TX_LENGTH = 12,
   RXRPC_SET_CALL_TIMEOUT = 13,
   RXRPC_CHARGE_ACCEPT = 14,
+  RXRPC_OOB_ID = 15,
+  RXRPC_CHALLENGED = 16,
+  RXRPC_RESPOND = 17,
+  RXRPC_RESPONDED = 18,
+  RXRPC_RESP_RXGK_APPDATA = 19,
   RXRPC__SUPPORTED
 };
 #define RXRPC_SECURITY_PLAIN 0
@@ -48,6 +54,7 @@
 #define RXRPC_SECURITY_RXKAD 2
 #define RXRPC_SECURITY_RXGK 4
 #define RXRPC_SECURITY_RXK5 5
+#define RXRPC_SECURITY_YFS_RXGK 6
 #define RX_CALL_DEAD - 1
 #define RX_INVALID_OPERATION - 2
 #define RX_CALL_TIMEOUT - 3
@@ -77,4 +84,24 @@
 #define RXKADSEALEDINCON 19270410
 #define RXKADDATALEN 19270411
 #define RXKADILLEGALLEVEL 19270412
+#define RXGK_INCONSISTENCY 1233242880
+#define RXGK_PACKETSHORT 1233242881
+#define RXGK_BADCHALLENGE 1233242882
+#define RXGK_SEALEDINCON 1233242883
+#define RXGK_NOTAUTH 1233242884
+#define RXGK_EXPIRED 1233242885
+#define RXGK_BADLEVEL 1233242886
+#define RXGK_BADKEYNO 1233242887
+#define RXGK_NOTRXGK 1233242888
+#define RXGK_UNSUPPORTED 1233242889
+#define RXGK_GSSERROR 1233242890
+struct rxrpc_challenge {
+  __u16 service_id;
+  __u8 security_index;
+  __u8 pad;
+};
+struct rxgk_challenge {
+  struct rxrpc_challenge base;
+  __u32 enctype;
+};
 #endif
diff --git a/libc/kernel/uapi/linux/securebits.h b/libc/kernel/uapi/linux/securebits.h
index b50eec9..b9f79b3 100644
--- a/libc/kernel/uapi/linux/securebits.h
+++ b/libc/kernel/uapi/linux/securebits.h
@@ -24,6 +24,15 @@
 #define SECURE_NO_CAP_AMBIENT_RAISE_LOCKED 7
 #define SECBIT_NO_CAP_AMBIENT_RAISE (issecure_mask(SECURE_NO_CAP_AMBIENT_RAISE))
 #define SECBIT_NO_CAP_AMBIENT_RAISE_LOCKED (issecure_mask(SECURE_NO_CAP_AMBIENT_RAISE_LOCKED))
-#define SECURE_ALL_BITS (issecure_mask(SECURE_NOROOT) | issecure_mask(SECURE_NO_SETUID_FIXUP) | issecure_mask(SECURE_KEEP_CAPS) | issecure_mask(SECURE_NO_CAP_AMBIENT_RAISE))
+#define SECURE_EXEC_RESTRICT_FILE 8
+#define SECURE_EXEC_RESTRICT_FILE_LOCKED 9
+#define SECBIT_EXEC_RESTRICT_FILE (issecure_mask(SECURE_EXEC_RESTRICT_FILE))
+#define SECBIT_EXEC_RESTRICT_FILE_LOCKED (issecure_mask(SECURE_EXEC_RESTRICT_FILE_LOCKED))
+#define SECURE_EXEC_DENY_INTERACTIVE 10
+#define SECURE_EXEC_DENY_INTERACTIVE_LOCKED 11
+#define SECBIT_EXEC_DENY_INTERACTIVE (issecure_mask(SECURE_EXEC_DENY_INTERACTIVE))
+#define SECBIT_EXEC_DENY_INTERACTIVE_LOCKED (issecure_mask(SECURE_EXEC_DENY_INTERACTIVE_LOCKED))
+#define SECURE_ALL_BITS (issecure_mask(SECURE_NOROOT) | issecure_mask(SECURE_NO_SETUID_FIXUP) | issecure_mask(SECURE_KEEP_CAPS) | issecure_mask(SECURE_NO_CAP_AMBIENT_RAISE) | issecure_mask(SECURE_EXEC_RESTRICT_FILE) | issecure_mask(SECURE_EXEC_DENY_INTERACTIVE))
 #define SECURE_ALL_LOCKS (SECURE_ALL_BITS << 1)
+#define SECURE_ALL_UNPRIVILEGED (issecure_mask(SECURE_EXEC_RESTRICT_FILE) | issecure_mask(SECURE_EXEC_DENY_INTERACTIVE))
 #endif
diff --git a/libc/kernel/uapi/linux/sed-opal.h b/libc/kernel/uapi/linux/sed-opal.h
index 6274ede..285e26b 100644
--- a/libc/kernel/uapi/linux/sed-opal.h
+++ b/libc/kernel/uapi/linux/sed-opal.h
@@ -169,4 +169,5 @@
 #define IOC_OPAL_GET_GEOMETRY _IOR('p', 238, struct opal_geometry)
 #define IOC_OPAL_DISCOVERY _IOW('p', 239, struct opal_discovery)
 #define IOC_OPAL_REVERT_LSP _IOW('p', 240, struct opal_revert_lsp)
+#define IOC_OPAL_SET_SID_PW _IOW('p', 241, struct opal_new_pw)
 #endif
diff --git a/libc/kernel/uapi/linux/snmp.h b/libc/kernel/uapi/linux/snmp.h
index 0f72302..cc62ecb 100644
--- a/libc/kernel/uapi/linux/snmp.h
+++ b/libc/kernel/uapi/linux/snmp.h
@@ -11,9 +11,14 @@
   IPSTATS_MIB_INPKTS,
   IPSTATS_MIB_INOCTETS,
   IPSTATS_MIB_INDELIVERS,
-  IPSTATS_MIB_OUTFORWDATAGRAMS,
+  IPSTATS_MIB_NOECTPKTS,
+  IPSTATS_MIB_ECT1PKTS,
+  IPSTATS_MIB_ECT0PKTS,
+  IPSTATS_MIB_CEPKTS,
   IPSTATS_MIB_OUTREQUESTS,
+  IPSTATS_MIB_OUTPKTS,
   IPSTATS_MIB_OUTOCTETS,
+  IPSTATS_MIB_OUTFORWDATAGRAMS,
   IPSTATS_MIB_INHDRERRORS,
   IPSTATS_MIB_INTOOBIGERRORS,
   IPSTATS_MIB_INNOROUTES,
@@ -39,12 +44,7 @@
   IPSTATS_MIB_INBCASTOCTETS,
   IPSTATS_MIB_OUTBCASTOCTETS,
   IPSTATS_MIB_CSUMERRORS,
-  IPSTATS_MIB_NOECTPKTS,
-  IPSTATS_MIB_ECT1PKTS,
-  IPSTATS_MIB_ECT0PKTS,
-  IPSTATS_MIB_CEPKTS,
   IPSTATS_MIB_REASM_OVERLAPS,
-  IPSTATS_MIB_OUTPKTS,
   __IPSTATS_MIB_MAX
 };
 enum {
@@ -141,6 +141,9 @@
   LINUX_MIB_TIMEWAITKILLED,
   LINUX_MIB_PAWSACTIVEREJECTED,
   LINUX_MIB_PAWSESTABREJECTED,
+  LINUX_MIB_TSECRREJECTED,
+  LINUX_MIB_PAWS_OLD_ACK,
+  LINUX_MIB_PAWS_TW_REJECTED,
   LINUX_MIB_DELAYEDACKS,
   LINUX_MIB_DELAYEDACKLOCKED,
   LINUX_MIB_DELAYEDACKLOST,
@@ -291,6 +294,8 @@
   LINUX_MIB_XFRMACQUIREERROR,
   LINUX_MIB_XFRMOUTSTATEDIRERROR,
   LINUX_MIB_XFRMINSTATEDIRERROR,
+  LINUX_MIB_XFRMINIPTFSERROR,
+  LINUX_MIB_XFRMOUTNOQSPACE,
   __LINUX_MIB_XFRMMAX
 };
 enum {
@@ -307,6 +312,11 @@
   LINUX_MIB_TLSRXDEVICERESYNC,
   LINUX_MIB_TLSDECRYPTRETRY,
   LINUX_MIB_TLSRXNOPADVIOL,
+  LINUX_MIB_TLSRXREKEYOK,
+  LINUX_MIB_TLSRXREKEYERROR,
+  LINUX_MIB_TLSTXREKEYOK,
+  LINUX_MIB_TLSTXREKEYERROR,
+  LINUX_MIB_TLSRXREKEYRECEIVED,
   __LINUX_MIB_TLSMAX
 };
 #endif
diff --git a/libc/kernel/uapi/linux/stat.h b/libc/kernel/uapi/linux/stat.h
index aae9ed4..e454e53 100644
--- a/libc/kernel/uapi/linux/stat.h
+++ b/libc/kernel/uapi/linux/stat.h
@@ -72,8 +72,10 @@
   __u32 stx_atomic_write_unit_min;
   __u32 stx_atomic_write_unit_max;
   __u32 stx_atomic_write_segments_max;
-  __u32 __spare1[1];
-  __u64 __spare3[9];
+  __u32 stx_dio_read_offset_align;
+  __u32 stx_atomic_write_unit_max_opt;
+  __u32 __spare2[1];
+  __u64 __spare3[8];
 };
 #define STATX_TYPE 0x00000001U
 #define STATX_MODE 0x00000002U
@@ -93,6 +95,7 @@
 #define STATX_MNT_ID_UNIQUE 0x00004000U
 #define STATX_SUBVOL 0x00008000U
 #define STATX_WRITE_ATOMIC 0x00010000U
+#define STATX_DIO_READ_ALIGN 0x00020000U
 #define STATX__RESERVED 0x80000000U
 #define STATX_ALL 0x00000fffU
 #define STATX_ATTR_COMPRESSED 0x00000004
diff --git a/libc/kernel/uapi/linux/stddef.h b/libc/kernel/uapi/linux/stddef.h
index dc37c6f..2a0e3db 100644
--- a/libc/kernel/uapi/linux/stddef.h
+++ b/libc/kernel/uapi/linux/stddef.h
@@ -10,7 +10,12 @@
 #ifndef __always_inline
 #define __always_inline inline
 #endif
-#define __struct_group(TAG,NAME,ATTRS,MEMBERS...) union { struct { MEMBERS } ATTRS; struct TAG { MEMBERS } ATTRS NAME; } ATTRS
+#ifndef __cplusplus
+#define __struct_group_tag(TAG) TAG
+#else
+#define __struct_group_tag(TAG)
+#endif
+#define __struct_group(TAG,NAME,ATTRS,MEMBERS...) union { struct { MEMBERS } ATTRS; struct __struct_group_tag(TAG) { MEMBERS } ATTRS NAME; } ATTRS
 #ifdef __cplusplus
 #define __DECLARE_FLEX_ARRAY(T,member) T member[0]
 #else
@@ -25,4 +30,5 @@
 #ifndef __counted_by_be
 #define __counted_by_be(m)
 #endif
+#define __kernel_nonstring
 #endif
diff --git a/libc/kernel/uapi/linux/taskstats.h b/libc/kernel/uapi/linux/taskstats.h
index 4914b2f..b19c184 100644
--- a/libc/kernel/uapi/linux/taskstats.h
+++ b/libc/kernel/uapi/linux/taskstats.h
@@ -7,7 +7,7 @@
 #ifndef _LINUX_TASKSTATS_H
 #define _LINUX_TASKSTATS_H
 #include <linux/types.h>
-#define TASKSTATS_VERSION 14
+#define TASKSTATS_VERSION 16
 #define TS_COMM_LEN 32
 struct taskstats {
   __u16 version;
@@ -67,6 +67,22 @@
   __u64 wpcopy_delay_total;
   __u64 irq_count;
   __u64 irq_delay_total;
+  __u64 cpu_delay_max;
+  __u64 cpu_delay_min;
+  __u64 blkio_delay_max;
+  __u64 blkio_delay_min;
+  __u64 swapin_delay_max;
+  __u64 swapin_delay_min;
+  __u64 freepages_delay_max;
+  __u64 freepages_delay_min;
+  __u64 thrashing_delay_max;
+  __u64 thrashing_delay_min;
+  __u64 compact_delay_max;
+  __u64 compact_delay_min;
+  __u64 wpcopy_delay_max;
+  __u64 wpcopy_delay_min;
+  __u64 irq_delay_max;
+  __u64 irq_delay_min;
 };
 enum {
   TASKSTATS_CMD_UNSPEC = 0,
diff --git a/libc/kernel/uapi/linux/tcp.h b/libc/kernel/uapi/linux/tcp.h
index c71715c..57b76ce 100644
--- a/libc/kernel/uapi/linux/tcp.h
+++ b/libc/kernel/uapi/linux/tcp.h
@@ -16,6 +16,7 @@
 };
 #define tcp_flag_word(tp) (((union tcp_word_hdr *) (tp))->words[3])
 enum {
+  TCP_FLAG_AE = __constant_cpu_to_be32(0x01000000),
   TCP_FLAG_CWR = __constant_cpu_to_be32(0x00800000),
   TCP_FLAG_ECE = __constant_cpu_to_be32(0x00400000),
   TCP_FLAG_URG = __constant_cpu_to_be32(0x00200000),
@@ -24,7 +25,7 @@
   TCP_FLAG_RST = __constant_cpu_to_be32(0x00040000),
   TCP_FLAG_SYN = __constant_cpu_to_be32(0x00020000),
   TCP_FLAG_FIN = __constant_cpu_to_be32(0x00010000),
-  TCP_RESERVED_BITS = __constant_cpu_to_be32(0x0F000000),
+  TCP_RESERVED_BITS = __constant_cpu_to_be32(0x0E000000),
   TCP_DATA_OFFSET = __constant_cpu_to_be32(0xF0000000)
 };
 #define TCP_MSS_DEFAULT 536U
@@ -72,6 +73,9 @@
 #define TCP_AO_GET_KEYS 41
 #define TCP_AO_REPAIR 42
 #define TCP_IS_MPTCP 43
+#define TCP_RTO_MAX_MS 44
+#define TCP_RTO_MIN_US 45
+#define TCP_DELACK_MAX_US 46
 #define TCP_REPAIR_ON 1
 #define TCP_REPAIR_OFF 0
 #define TCP_REPAIR_OFF_NO_WP - 1
@@ -105,6 +109,7 @@
 #define TCPI_OPT_ECN_SEEN 16
 #define TCPI_OPT_SYN_DATA 32
 #define TCPI_OPT_USEC_TS 64
+#define TCPI_OPT_TFO_CHILD 128
 enum tcp_ca_state {
   TCP_CA_Open = 0,
 #define TCPF_CA_Open (1 << TCP_CA_Open)
diff --git a/libc/kernel/uapi/linux/thermal.h b/libc/kernel/uapi/linux/thermal.h
index f9d67c5..79b4079 100644
--- a/libc/kernel/uapi/linux/thermal.h
+++ b/libc/kernel/uapi/linux/thermal.h
@@ -7,6 +7,8 @@
 #ifndef _UAPI_LINUX_THERMAL_H
 #define _UAPI_LINUX_THERMAL_H
 #define THERMAL_NAME_LENGTH 20
+#define THERMAL_THRESHOLD_WAY_UP 0x1
+#define THERMAL_THRESHOLD_WAY_DOWN 0x2
 enum thermal_device_mode {
   THERMAL_DEVICE_DISABLED = 0,
   THERMAL_DEVICE_ENABLED,
@@ -18,7 +20,7 @@
   THERMAL_TRIP_CRITICAL,
 };
 #define THERMAL_GENL_FAMILY_NAME "thermal"
-#define THERMAL_GENL_VERSION 0x01
+#define THERMAL_GENL_VERSION 0x02
 #define THERMAL_GENL_SAMPLING_GROUP_NAME "sampling"
 #define THERMAL_GENL_EVENT_GROUP_NAME "event"
 enum thermal_genl_attr {
@@ -46,6 +48,10 @@
   THERMAL_GENL_ATTR_CPU_CAPABILITY_ID,
   THERMAL_GENL_ATTR_CPU_CAPABILITY_PERFORMANCE,
   THERMAL_GENL_ATTR_CPU_CAPABILITY_EFFICIENCY,
+  THERMAL_GENL_ATTR_THRESHOLD,
+  THERMAL_GENL_ATTR_THRESHOLD_TEMP,
+  THERMAL_GENL_ATTR_THRESHOLD_DIRECTION,
+  THERMAL_GENL_ATTR_TZ_PREV_TEMP,
   __THERMAL_GENL_ATTR_MAX,
 };
 #define THERMAL_GENL_ATTR_MAX (__THERMAL_GENL_ATTR_MAX - 1)
@@ -70,6 +76,11 @@
   THERMAL_GENL_EVENT_CDEV_STATE_UPDATE,
   THERMAL_GENL_EVENT_TZ_GOV_CHANGE,
   THERMAL_GENL_EVENT_CPU_CAPABILITY_CHANGE,
+  THERMAL_GENL_EVENT_THRESHOLD_ADD,
+  THERMAL_GENL_EVENT_THRESHOLD_DELETE,
+  THERMAL_GENL_EVENT_THRESHOLD_FLUSH,
+  THERMAL_GENL_EVENT_THRESHOLD_UP,
+  THERMAL_GENL_EVENT_THRESHOLD_DOWN,
   __THERMAL_GENL_EVENT_MAX,
 };
 #define THERMAL_GENL_EVENT_MAX (__THERMAL_GENL_EVENT_MAX - 1)
@@ -81,6 +92,10 @@
   THERMAL_GENL_CMD_TZ_GET_GOV,
   THERMAL_GENL_CMD_TZ_GET_MODE,
   THERMAL_GENL_CMD_CDEV_GET,
+  THERMAL_GENL_CMD_THRESHOLD_GET,
+  THERMAL_GENL_CMD_THRESHOLD_ADD,
+  THERMAL_GENL_CMD_THRESHOLD_DELETE,
+  THERMAL_GENL_CMD_THRESHOLD_FLUSH,
   __THERMAL_GENL_CMD_MAX,
 };
 #define THERMAL_GENL_CMD_MAX (__THERMAL_GENL_CMD_MAX - 1)
diff --git a/libc/kernel/uapi/linux/tiocl.h b/libc/kernel/uapi/linux/tiocl.h
index c4297ad..7e1380f 100644
--- a/libc/kernel/uapi/linux/tiocl.h
+++ b/libc/kernel/uapi/linux/tiocl.h
@@ -33,4 +33,5 @@
 #define TIOCL_BLANKSCREEN 14
 #define TIOCL_BLANKEDSCREEN 15
 #define TIOCL_GETKMSGREDIRECT 17
+#define TIOCL_GETBRACKETEDPASTE 18
 #endif
diff --git a/libc/kernel/uapi/linux/types.h b/libc/kernel/uapi/linux/types.h
index 2f57e85..f33febd 100644
--- a/libc/kernel/uapi/linux/types.h
+++ b/libc/kernel/uapi/linux/types.h
@@ -24,6 +24,7 @@
 typedef __u16 __bitwise __sum16;
 typedef __u32 __bitwise __wsum;
 #define __aligned_u64 __u64 __attribute__((aligned(8)))
+#define __aligned_s64 __s64 __attribute__((aligned(8)))
 #define __aligned_be64 __be64 __attribute__((aligned(8)))
 #define __aligned_le64 __le64 __attribute__((aligned(8)))
 typedef unsigned __bitwise __poll_t;
diff --git a/libc/kernel/uapi/linux/ublk_cmd.h b/libc/kernel/uapi/linux/ublk_cmd.h
index 8e7732b..858363d 100644
--- a/libc/kernel/uapi/linux/ublk_cmd.h
+++ b/libc/kernel/uapi/linux/ublk_cmd.h
@@ -31,6 +31,8 @@
 #define UBLK_U_CMD_GET_DEV_INFO2 _IOR('u', UBLK_CMD_GET_DEV_INFO2, struct ublksrv_ctrl_cmd)
 #define UBLK_U_CMD_GET_FEATURES _IOR('u', 0x13, struct ublksrv_ctrl_cmd)
 #define UBLK_U_CMD_DEL_DEV_ASYNC _IOR('u', 0x14, struct ublksrv_ctrl_cmd)
+#define UBLK_U_CMD_UPDATE_SIZE _IOWR('u', 0x15, struct ublksrv_ctrl_cmd)
+#define UBLK_U_CMD_QUIESCE_DEV _IOWR('u', 0x16, struct ublksrv_ctrl_cmd)
 #define UBLK_FEATURES_LEN 8
 #define UBLK_IO_FETCH_REQ 0x20
 #define UBLK_IO_COMMIT_AND_FETCH_REQ 0x21
@@ -38,6 +40,8 @@
 #define UBLK_U_IO_FETCH_REQ _IOWR('u', UBLK_IO_FETCH_REQ, struct ublksrv_io_cmd)
 #define UBLK_U_IO_COMMIT_AND_FETCH_REQ _IOWR('u', UBLK_IO_COMMIT_AND_FETCH_REQ, struct ublksrv_io_cmd)
 #define UBLK_U_IO_NEED_GET_DATA _IOWR('u', UBLK_IO_NEED_GET_DATA, struct ublksrv_io_cmd)
+#define UBLK_U_IO_REGISTER_IO_BUF _IOWR('u', 0x23, struct ublksrv_io_cmd)
+#define UBLK_U_IO_UNREGISTER_IO_BUF _IOWR('u', 0x24, struct ublksrv_io_cmd)
 #define UBLK_IO_RES_OK 0
 #define UBLK_IO_RES_NEED_GET_DATA 1
 #define UBLK_IO_RES_ABORT (- ENODEV)
@@ -65,9 +69,15 @@
 #define UBLK_F_CMD_IOCTL_ENCODE (1UL << 6)
 #define UBLK_F_USER_COPY (1UL << 7)
 #define UBLK_F_ZONED (1ULL << 8)
+#define UBLK_F_USER_RECOVERY_FAIL_IO (1ULL << 9)
+#define UBLK_F_UPDATE_SIZE (1ULL << 10)
+#define UBLK_F_AUTO_BUF_REG (1ULL << 11)
+#define UBLK_F_QUIESCE (1ULL << 12)
+#define UBLK_F_PER_IO_DAEMON (1ULL << 13)
 #define UBLK_S_DEV_DEAD 0
 #define UBLK_S_DEV_LIVE 1
 #define UBLK_S_DEV_QUIESCED 2
+#define UBLK_S_DEV_FAIL_IO 3
 struct ublksrv_ctrl_cmd {
   __u32 dev_id;
   __u16 queue_id;
@@ -114,6 +124,7 @@
 #define UBLK_IO_F_FUA (1U << 13)
 #define UBLK_IO_F_NOUNMAP (1U << 15)
 #define UBLK_IO_F_SWAP (1U << 16)
+#define UBLK_IO_F_NEED_REG_BUF (1U << 17)
 struct ublksrv_io_desc {
   __u32 op_flags;
   union {
@@ -123,6 +134,14 @@
   __u64 start_sector;
   __u64 addr;
 };
+#define UBLK_AUTO_BUF_REG_FALLBACK (1 << 0)
+#define UBLK_AUTO_BUF_REG_F_MASK UBLK_AUTO_BUF_REG_FALLBACK
+struct ublk_auto_buf_reg {
+  __u16 index;
+  __u8 flags;
+  __u8 reserved0;
+  __u32 reserved1;
+};
 struct ublksrv_io_cmd {
   __u16 q_id;
   __u16 tag;
@@ -167,16 +186,31 @@
   __u32 max_zone_append_sectors;
   __u8 reserved[20];
 };
+struct ublk_param_dma_align {
+  __u32 alignment;
+  __u8 pad[4];
+};
+#define UBLK_MIN_SEGMENT_SIZE 4096
+struct ublk_param_segment {
+  __u64 seg_boundary_mask;
+  __u32 max_segment_size;
+  __u16 max_segments;
+  __u8 pad[2];
+};
 struct ublk_params {
   __u32 len;
 #define UBLK_PARAM_TYPE_BASIC (1 << 0)
 #define UBLK_PARAM_TYPE_DISCARD (1 << 1)
 #define UBLK_PARAM_TYPE_DEVT (1 << 2)
 #define UBLK_PARAM_TYPE_ZONED (1 << 3)
+#define UBLK_PARAM_TYPE_DMA_ALIGN (1 << 4)
+#define UBLK_PARAM_TYPE_SEGMENT (1 << 5)
   __u32 types;
   struct ublk_param_basic basic;
   struct ublk_param_discard discard;
   struct ublk_param_devt devt;
   struct ublk_param_zoned zoned;
+  struct ublk_param_dma_align dma;
+  struct ublk_param_segment seg;
 };
 #endif
diff --git a/libc/kernel/uapi/linux/udp.h b/libc/kernel/uapi/linux/udp.h
index 0367ad9..ea2bbcc 100644
--- a/libc/kernel/uapi/linux/udp.h
+++ b/libc/kernel/uapi/linux/udp.h
@@ -26,4 +26,5 @@
 #define UDP_ENCAP_GTP1U 5
 #define UDP_ENCAP_RXRPC 6
 #define TCP_ENCAP_ESPINTCP 7
+#define UDP_ENCAP_OVPNINUDP 8
 #endif
diff --git a/libc/kernel/uapi/linux/usb/ch9.h b/libc/kernel/uapi/linux/usb/ch9.h
index c1121fb..c1bfc5f 100644
--- a/libc/kernel/uapi/linux/usb/ch9.h
+++ b/libc/kernel/uapi/linux/usb/ch9.h
@@ -118,6 +118,7 @@
 #define USB_DT_BOS 0x0f
 #define USB_DT_DEVICE_CAPABILITY 0x10
 #define USB_DT_WIRELESS_ENDPOINT_COMP 0x11
+#define USB_DT_EUSB2_ISOC_ENDPOINT_COMP 0x12
 #define USB_DT_WIRE_ADAPTER 0x21
 #define USB_DT_DFU_FUNCTIONAL 0x21
 #define USB_DT_RPIPE 0x22
@@ -169,6 +170,7 @@
 #define USB_CLASS_AUDIO_VIDEO 0x10
 #define USB_CLASS_BILLBOARD 0x11
 #define USB_CLASS_USB_TYPE_C_BRIDGE 0x12
+#define USB_CLASS_MCTP 0x14
 #define USB_CLASS_MISC 0xef
 #define USB_CLASS_APP_SPEC 0xfe
 #define USB_SUBCLASS_DFU 0x01
@@ -246,6 +248,13 @@
 #define USB_ENDPOINT_USAGE_DATA 0x00
 #define USB_ENDPOINT_USAGE_FEEDBACK 0x10
 #define USB_ENDPOINT_USAGE_IMPLICIT_FB 0x20
+struct usb_eusb2_isoc_ep_comp_descriptor {
+  __u8 bLength;
+  __u8 bDescriptorType;
+  __le16 wMaxPacketSize;
+  __le32 dwBytesPerInterval;
+} __attribute__((packed));
+#define USB_DT_EUSB2_ISOC_EP_COMP_SIZE 8
 struct usb_ssp_isoc_ep_comp_descriptor {
   __u8 bLength;
   __u8 bDescriptorType;
diff --git a/libc/kernel/uapi/linux/usb/video.h b/libc/kernel/uapi/linux/usb/video.h
index 8b688e1..bbbb7ca 100644
--- a/libc/kernel/uapi/linux/usb/video.h
+++ b/libc/kernel/uapi/linux/usb/video.h
@@ -71,6 +71,7 @@
 #define UVC_CT_ROLL_ABSOLUTE_CONTROL 0x0f
 #define UVC_CT_ROLL_RELATIVE_CONTROL 0x10
 #define UVC_CT_PRIVACY_CONTROL 0x11
+#define UVC_CT_REGION_OF_INTEREST_CONTROL 0x14
 #define UVC_PU_CONTROL_UNDEFINED 0x00
 #define UVC_PU_BACKLIGHT_COMPENSATION_CONTROL 0x01
 #define UVC_PU_BRIGHTNESS_CONTROL 0x02
@@ -386,4 +387,39 @@
 #define UVC_FRAME_MJPEG(n) uvc_frame_mjpeg_ ##n
 #define DECLARE_UVC_FRAME_MJPEG(n) struct UVC_FRAME_MJPEG(n) { __u8 bLength; __u8 bDescriptorType; __u8 bDescriptorSubType; __u8 bFrameIndex; __u8 bmCapabilities; __le16 wWidth; __le16 wHeight; __le32 dwMinBitRate; __le32 dwMaxBitRate; __le32 dwMaxVideoFrameBufferSize; __le32 dwDefaultFrameInterval; __u8 bFrameIntervalType; __le32 dwFrameInterval[n]; \
 } __attribute__((packed))
+struct uvc_format_framebased {
+  __u8 bLength;
+  __u8 bDescriptorType;
+  __u8 bDescriptorSubType;
+  __u8 bFormatIndex;
+  __u8 bNumFrameDescriptors;
+  __u8 guidFormat[16];
+  __u8 bBitsPerPixel;
+  __u8 bDefaultFrameIndex;
+  __u8 bAspectRatioX;
+  __u8 bAspectRatioY;
+  __u8 bmInterfaceFlags;
+  __u8 bCopyProtect;
+  __u8 bVariableSize;
+} __attribute__((__packed__));
+#define UVC_DT_FORMAT_FRAMEBASED_SIZE 28
+struct uvc_frame_framebased {
+  __u8 bLength;
+  __u8 bDescriptorType;
+  __u8 bDescriptorSubType;
+  __u8 bFrameIndex;
+  __u8 bmCapabilities;
+  __u16 wWidth;
+  __u16 wHeight;
+  __u32 dwMinBitRate;
+  __u32 dwMaxBitRate;
+  __u32 dwDefaultFrameInterval;
+  __u8 bFrameIntervalType;
+  __u32 dwBytesPerLine;
+  __u32 dwFrameInterval[];
+} __attribute__((__packed__));
+#define UVC_DT_FRAME_FRAMEBASED_SIZE(n) (26 + 4 * (n))
+#define UVC_FRAME_FRAMEBASED(n) uvc_frame_framebased_ ##n
+#define DECLARE_UVC_FRAME_FRAMEBASED(n) struct UVC_FRAME_FRAMEBASED(n) { __u8 bLength; __u8 bDescriptorType; __u8 bDescriptorSubType; __u8 bFrameIndex; __u8 bmCapabilities; __u16 wWidth; __u16 wHeight; __u32 dwMinBitRate; __u32 dwMaxBitRate; __u32 dwDefaultFrameInterval; __u8 bFrameIntervalType; __u32 dwBytesPerLine; __u32 dwFrameInterval[n]; \
+} __attribute__((packed))
 #endif
diff --git a/libc/kernel/uapi/linux/uvcvideo.h b/libc/kernel/uapi/linux/uvcvideo.h
index cdaf6a5..c1752df 100644
--- a/libc/kernel/uapi/linux/uvcvideo.h
+++ b/libc/kernel/uapi/linux/uvcvideo.h
@@ -14,6 +14,7 @@
 #define UVC_CTRL_DATA_TYPE_BOOLEAN 3
 #define UVC_CTRL_DATA_TYPE_ENUM 4
 #define UVC_CTRL_DATA_TYPE_BITMASK 5
+#define UVC_CTRL_DATA_TYPE_RECT 6
 #define UVC_CTRL_FLAG_SET_CUR (1 << 0)
 #define UVC_CTRL_FLAG_GET_CUR (1 << 1)
 #define UVC_CTRL_FLAG_GET_MIN (1 << 2)
@@ -25,6 +26,16 @@
 #define UVC_CTRL_FLAG_ASYNCHRONOUS (1 << 8)
 #define UVC_CTRL_FLAG_GET_RANGE (UVC_CTRL_FLAG_GET_CUR | UVC_CTRL_FLAG_GET_MIN | UVC_CTRL_FLAG_GET_MAX | UVC_CTRL_FLAG_GET_RES | UVC_CTRL_FLAG_GET_DEF)
 #define UVC_MENU_NAME_LEN 32
+#define V4L2_CID_UVC_REGION_OF_INTEREST_RECT (V4L2_CID_USER_UVC_BASE + 1)
+#define V4L2_CID_UVC_REGION_OF_INTEREST_AUTO (V4L2_CID_USER_UVC_BASE + 2)
+#define V4L2_UVC_REGION_OF_INTEREST_AUTO_EXPOSURE (1 << 0)
+#define V4L2_UVC_REGION_OF_INTEREST_AUTO_IRIS (1 << 1)
+#define V4L2_UVC_REGION_OF_INTEREST_AUTO_WHITE_BALANCE (1 << 2)
+#define V4L2_UVC_REGION_OF_INTEREST_AUTO_FOCUS (1 << 3)
+#define V4L2_UVC_REGION_OF_INTEREST_AUTO_FACE_DETECT (1 << 4)
+#define V4L2_UVC_REGION_OF_INTEREST_AUTO_DETECT_AND_TRACK (1 << 5)
+#define V4L2_UVC_REGION_OF_INTEREST_AUTO_IMAGE_STABILIZATION (1 << 6)
+#define V4L2_UVC_REGION_OF_INTEREST_AUTO_HIGHER_QUALITY (1 << 7)
 struct uvc_menu_info {
   __u32 value;
   __u8 name[UVC_MENU_NAME_LEN];
diff --git a/libc/kernel/uapi/linux/v4l2-controls.h b/libc/kernel/uapi/linux/v4l2-controls.h
index f6ef26c..b231cab 100644
--- a/libc/kernel/uapi/linux/v4l2-controls.h
+++ b/libc/kernel/uapi/linux/v4l2-controls.h
@@ -112,6 +112,7 @@
 #define V4L2_CID_USER_ASPEED_BASE (V4L2_CID_USER_BASE + 0x11a0)
 #define V4L2_CID_USER_NPCM_BASE (V4L2_CID_USER_BASE + 0x11b0)
 #define V4L2_CID_USER_THP7312_BASE (V4L2_CID_USER_BASE + 0x11c0)
+#define V4L2_CID_USER_UVC_BASE (V4L2_CID_USER_BASE + 0x11e0)
 #define V4L2_CID_CODEC_BASE (V4L2_CTRL_CLASS_CODEC | 0x900)
 #define V4L2_CID_CODEC_CLASS (V4L2_CTRL_CLASS_CODEC | 1)
 #define V4L2_CID_MPEG_STREAM_TYPE (V4L2_CID_CODEC_BASE + 0)
diff --git a/libc/kernel/uapi/linux/version.h b/libc/kernel/uapi/linux/version.h
index 728b80a..309ac32 100644
--- a/libc/kernel/uapi/linux/version.h
+++ b/libc/kernel/uapi/linux/version.h
@@ -4,8 +4,8 @@
  * See https://android.googlesource.com/platform/bionic/+/master/libc/kernel/
  * for more information.
  */
-#define LINUX_VERSION_CODE 396288
+#define LINUX_VERSION_CODE 397312
 #define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + ((c) > 255 ? 255 : (c)))
 #define LINUX_VERSION_MAJOR 6
-#define LINUX_VERSION_PATCHLEVEL 12
+#define LINUX_VERSION_PATCHLEVEL 16
 #define LINUX_VERSION_SUBLEVEL 0
diff --git a/libc/kernel/uapi/linux/vfio.h b/libc/kernel/uapi/linux/vfio.h
index 5910e40..35e954a 100644
--- a/libc/kernel/uapi/linux/vfio.h
+++ b/libc/kernel/uapi/linux/vfio.h
@@ -14,7 +14,7 @@
 #define VFIO_TYPE1v2_IOMMU 3
 #define VFIO_DMA_CC_IOMMU 4
 #define VFIO_EEH 5
-#define VFIO_TYPE1_NESTING_IOMMU 6
+#define __VFIO_RESERVED_TYPE1_NESTING_IOMMU 6
 #define VFIO_SPAPR_TCE_v2_IOMMU 7
 #define VFIO_NOIOMMU_IOMMU 8
 #define VFIO_UNMAP_ALL 9
@@ -218,6 +218,7 @@
 };
 enum {
   VFIO_AP_REQ_IRQ_INDEX,
+  VFIO_AP_CFG_CHG_IRQ_INDEX,
   VFIO_AP_NUM_IRQS
 };
 struct vfio_pci_dependent_device {
@@ -306,12 +307,16 @@
 struct vfio_device_attach_iommufd_pt {
   __u32 argsz;
   __u32 flags;
+#define VFIO_DEVICE_ATTACH_PASID (1 << 0)
   __u32 pt_id;
+  __u32 pasid;
 };
 #define VFIO_DEVICE_ATTACH_IOMMUFD_PT _IO(VFIO_TYPE, VFIO_BASE + 19)
 struct vfio_device_detach_iommufd_pt {
   __u32 argsz;
   __u32 flags;
+#define VFIO_DEVICE_DETACH_PASID (1 << 0)
+  __u32 pasid;
 };
 #define VFIO_DEVICE_DETACH_IOMMUFD_PT _IO(VFIO_TYPE, VFIO_BASE + 20)
 #define VFIO_DEVICE_FEATURE_PCI_VF_TOKEN (0)
diff --git a/libc/kernel/uapi/linux/videodev2.h b/libc/kernel/uapi/linux/videodev2.h
index e49f5ea..a6ea45b 100644
--- a/libc/kernel/uapi/linux/videodev2.h
+++ b/libc/kernel/uapi/linux/videodev2.h
@@ -51,9 +51,10 @@
   V4L2_BUF_TYPE_META_OUTPUT = 14,
   V4L2_BUF_TYPE_PRIVATE = 0x80,
 };
+#define V4L2_TYPE_IS_VALID(type) ((type) >= V4L2_BUF_TYPE_VIDEO_CAPTURE && (type) <= V4L2_BUF_TYPE_META_OUTPUT)
 #define V4L2_TYPE_IS_MULTIPLANAR(type) ((type) == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE || (type) == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
-#define V4L2_TYPE_IS_OUTPUT(type) ((type) == V4L2_BUF_TYPE_VIDEO_OUTPUT || (type) == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE || (type) == V4L2_BUF_TYPE_VIDEO_OVERLAY || (type) == V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY || (type) == V4L2_BUF_TYPE_VBI_OUTPUT || (type) == V4L2_BUF_TYPE_SLICED_VBI_OUTPUT || (type) == V4L2_BUF_TYPE_SDR_OUTPUT || (type) == V4L2_BUF_TYPE_META_OUTPUT)
-#define V4L2_TYPE_IS_CAPTURE(type) (! V4L2_TYPE_IS_OUTPUT(type))
+#define V4L2_TYPE_IS_OUTPUT(type) ((type) == V4L2_BUF_TYPE_VIDEO_OUTPUT || (type) == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE || (type) == V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY || (type) == V4L2_BUF_TYPE_VBI_OUTPUT || (type) == V4L2_BUF_TYPE_SLICED_VBI_OUTPUT || (type) == V4L2_BUF_TYPE_SDR_OUTPUT || (type) == V4L2_BUF_TYPE_META_OUTPUT)
+#define V4L2_TYPE_IS_CAPTURE(type) (V4L2_TYPE_IS_VALID(type) && ! V4L2_TYPE_IS_OUTPUT(type))
 enum v4l2_tuner_type {
   V4L2_TUNER_RADIO = 1,
   V4L2_TUNER_ANALOG_TV = 2,
@@ -280,8 +281,10 @@
 #define V4L2_PIX_FMT_Y216 v4l2_fourcc('Y', '2', '1', '6')
 #define V4L2_PIX_FMT_NV12 v4l2_fourcc('N', 'V', '1', '2')
 #define V4L2_PIX_FMT_NV21 v4l2_fourcc('N', 'V', '2', '1')
+#define V4L2_PIX_FMT_NV15 v4l2_fourcc('N', 'V', '1', '5')
 #define V4L2_PIX_FMT_NV16 v4l2_fourcc('N', 'V', '1', '6')
 #define V4L2_PIX_FMT_NV61 v4l2_fourcc('N', 'V', '6', '1')
+#define V4L2_PIX_FMT_NV20 v4l2_fourcc('N', 'V', '2', '0')
 #define V4L2_PIX_FMT_NV24 v4l2_fourcc('N', 'V', '2', '4')
 #define V4L2_PIX_FMT_NV42 v4l2_fourcc('N', 'V', '4', '2')
 #define V4L2_PIX_FMT_P010 v4l2_fourcc('P', '0', '1', '0')
@@ -412,6 +415,7 @@
 #define V4L2_PIX_FMT_S5C_UYVY_JPG v4l2_fourcc('S', '5', 'C', 'I')
 #define V4L2_PIX_FMT_Y8I v4l2_fourcc('Y', '8', 'I', ' ')
 #define V4L2_PIX_FMT_Y12I v4l2_fourcc('Y', '1', '2', 'I')
+#define V4L2_PIX_FMT_Y16I v4l2_fourcc('Y', '1', '6', 'I')
 #define V4L2_PIX_FMT_Z16 v4l2_fourcc('Z', '1', '6', ' ')
 #define V4L2_PIX_FMT_MT21C v4l2_fourcc('M', 'T', '2', '1')
 #define V4L2_PIX_FMT_MM21 v4l2_fourcc('M', 'M', '2', '1')
@@ -458,7 +462,11 @@
 #define V4L2_META_FMT_RK_ISP1_PARAMS v4l2_fourcc('R', 'K', '1', 'P')
 #define V4L2_META_FMT_RK_ISP1_STAT_3A v4l2_fourcc('R', 'K', '1', 'S')
 #define V4L2_META_FMT_RK_ISP1_EXT_PARAMS v4l2_fourcc('R', 'K', '1', 'E')
+#define V4L2_META_FMT_C3ISP_PARAMS v4l2_fourcc('C', '3', 'P', 'M')
+#define V4L2_META_FMT_C3ISP_STATS v4l2_fourcc('C', '3', 'S', 'T')
 #define V4L2_META_FMT_RPI_BE_CFG v4l2_fourcc('R', 'P', 'B', 'C')
+#define V4L2_META_FMT_RPI_FE_CFG v4l2_fourcc('R', 'P', 'F', 'C')
+#define V4L2_META_FMT_RPI_FE_STATS v4l2_fourcc('R', 'P', 'F', 'S')
 #define V4L2_PIX_FMT_PRIV_MAGIC 0xfeedcafe
 #define V4L2_PIX_FMT_FLAG_PREMUL_ALPHA 0x00000001
 #define V4L2_PIX_FMT_FLAG_SET_CSC 0x00000002
@@ -482,6 +490,7 @@
 #define V4L2_FMT_FLAG_CSC_HSV_ENC V4L2_FMT_FLAG_CSC_YCBCR_ENC
 #define V4L2_FMT_FLAG_CSC_QUANTIZATION 0x0100
 #define V4L2_FMT_FLAG_META_LINE_BASED 0x0200
+#define V4L2_FMTDESC_FLAG_ENUM_ALL 0x80000000
 enum v4l2_frmsizetypes {
   V4L2_FRMSIZE_TYPE_DISCRETE = 1,
   V4L2_FRMSIZE_TYPE_CONTINUOUS = 2,
@@ -930,6 +939,7 @@
     __s32  * p_s32;
     __s64  * p_s64;
     struct v4l2_area  * p_area;
+    struct v4l2_rect  * p_rect;
     struct v4l2_ctrl_h264_sps  * p_h264_sps;
     struct v4l2_ctrl_h264_pps  * p_h264_pps;
     struct v4l2_ctrl_h264_scaling_matrix  * p_h264_scaling_matrix;
@@ -976,6 +986,8 @@
 #define V4L2_CTRL_WHICH_CUR_VAL 0
 #define V4L2_CTRL_WHICH_DEF_VAL 0x0f000000
 #define V4L2_CTRL_WHICH_REQUEST_VAL 0x0f010000
+#define V4L2_CTRL_WHICH_MIN_VAL 0x0f020000
+#define V4L2_CTRL_WHICH_MAX_VAL 0x0f030000
 enum v4l2_ctrl_type {
   V4L2_CTRL_TYPE_INTEGER = 1,
   V4L2_CTRL_TYPE_BOOLEAN = 2,
@@ -991,6 +1003,7 @@
   V4L2_CTRL_TYPE_U16 = 0x0101,
   V4L2_CTRL_TYPE_U32 = 0x0102,
   V4L2_CTRL_TYPE_AREA = 0x0106,
+  V4L2_CTRL_TYPE_RECT = 0x0107,
   V4L2_CTRL_TYPE_HDR10_CLL_INFO = 0x0110,
   V4L2_CTRL_TYPE_HDR10_MASTERING_DISPLAY = 0x0111,
   V4L2_CTRL_TYPE_H264_SPS = 0x0200,
@@ -1063,6 +1076,7 @@
 #define V4L2_CTRL_FLAG_EXECUTE_ON_WRITE 0x0200
 #define V4L2_CTRL_FLAG_MODIFY_LAYOUT 0x0400
 #define V4L2_CTRL_FLAG_DYNAMIC_ARRAY 0x0800
+#define V4L2_CTRL_FLAG_HAS_WHICH_MIN_MAX 0x1000
 #define V4L2_CTRL_FLAG_NEXT_CTRL 0x80000000
 #define V4L2_CTRL_FLAG_NEXT_COMPOUND 0x40000000
 #define V4L2_CID_MAX_CTRLS 1024
diff --git a/libc/kernel/uapi/linux/virtio_gpu.h b/libc/kernel/uapi/linux/virtio_gpu.h
index bf35cf7..28f0217 100644
--- a/libc/kernel/uapi/linux/virtio_gpu.h
+++ b/libc/kernel/uapi/linux/virtio_gpu.h
@@ -194,7 +194,9 @@
 };
 #define VIRTIO_GPU_CAPSET_VIRGL 1
 #define VIRTIO_GPU_CAPSET_VIRGL2 2
+#define VIRTIO_GPU_CAPSET_GFXSTREAM_VULKAN 3
 #define VIRTIO_GPU_CAPSET_VENUS 4
+#define VIRTIO_GPU_CAPSET_CROSS_DOMAIN 5
 #define VIRTIO_GPU_CAPSET_DRM 6
 struct virtio_gpu_get_capset_info {
   struct virtio_gpu_ctrl_hdr hdr;
diff --git a/libc/kernel/uapi/linux/virtio_net.h b/libc/kernel/uapi/linux/virtio_net.h
index 26ff301..b9f6957 100644
--- a/libc/kernel/uapi/linux/virtio_net.h
+++ b/libc/kernel/uapi/linux/virtio_net.h
@@ -172,6 +172,17 @@
   __u8 hash_key_length;
   __u8 hash_key_data[];
 };
+struct virtio_net_rss_config_hdr {
+  __le32 hash_types;
+  __le16 indirection_table_mask;
+  __le16 unclassified_queue;
+  __le16 indirection_table[];
+};
+struct virtio_net_rss_config_trailer {
+  __le16 max_tx_vq;
+  __u8 hash_key_length;
+  __u8 hash_key_data[];
+};
 #define VIRTIO_NET_CTRL_MQ_RSS_CONFIG 1
 struct virtio_net_hash_config {
   __le32 hash_types;
diff --git a/libc/kernel/uapi/linux/virtio_pci.h b/libc/kernel/uapi/linux/virtio_pci.h
index 8921155..5249fc0 100644
--- a/libc/kernel/uapi/linux/virtio_pci.h
+++ b/libc/kernel/uapi/linux/virtio_pci.h
@@ -7,6 +7,7 @@
 #ifndef _LINUX_VIRTIO_PCI_H
 #define _LINUX_VIRTIO_PCI_H
 #include <linux/types.h>
+#include <linux/kernel.h>
 #ifndef VIRTIO_PCI_NO_LEGACY
 #define VIRTIO_PCI_HOST_FEATURES 0
 #define VIRTIO_PCI_GUEST_FEATURES 4
@@ -33,6 +34,7 @@
 #define VIRTIO_PCI_CAP_DEVICE_CFG 4
 #define VIRTIO_PCI_CAP_PCI_CFG 5
 #define VIRTIO_PCI_CAP_SHARED_MEMORY_CFG 8
+#define VIRTIO_PCI_CAP_VENDOR_CFG 9
 struct virtio_pci_cap {
   __u8 cap_vndr;
   __u8 cap_next;
@@ -44,6 +46,13 @@
   __le32 offset;
   __le32 length;
 };
+struct virtio_pci_vndr_data {
+  __u8 cap_vndr;
+  __u8 cap_next;
+  __u8 cap_len;
+  __u8 cfg_type;
+  __u16 vendor_id;
+};
 struct virtio_pci_cap64 {
   struct virtio_pci_cap cap;
   __le32 offset_hi;
@@ -120,12 +129,22 @@
 #define VIRTIO_ADMIN_STATUS_OK 0
 #define VIRTIO_ADMIN_CMD_LIST_QUERY 0x0
 #define VIRTIO_ADMIN_CMD_LIST_USE 0x1
+#define VIRTIO_ADMIN_GROUP_TYPE_SELF 0x0
 #define VIRTIO_ADMIN_GROUP_TYPE_SRIOV 0x1
 #define VIRTIO_ADMIN_CMD_LEGACY_COMMON_CFG_WRITE 0x2
 #define VIRTIO_ADMIN_CMD_LEGACY_COMMON_CFG_READ 0x3
 #define VIRTIO_ADMIN_CMD_LEGACY_DEV_CFG_WRITE 0x4
 #define VIRTIO_ADMIN_CMD_LEGACY_DEV_CFG_READ 0x5
 #define VIRTIO_ADMIN_CMD_LEGACY_NOTIFY_INFO 0x6
+#define VIRTIO_ADMIN_CMD_CAP_ID_LIST_QUERY 0x7
+#define VIRTIO_ADMIN_CMD_DEVICE_CAP_GET 0x8
+#define VIRTIO_ADMIN_CMD_DRIVER_CAP_SET 0x9
+#define VIRTIO_ADMIN_CMD_RESOURCE_OBJ_CREATE 0xa
+#define VIRTIO_ADMIN_CMD_RESOURCE_OBJ_DESTROY 0xd
+#define VIRTIO_ADMIN_CMD_DEV_PARTS_METADATA_GET 0xe
+#define VIRTIO_ADMIN_CMD_DEV_PARTS_GET 0xf
+#define VIRTIO_ADMIN_CMD_DEV_PARTS_SET 0x10
+#define VIRTIO_ADMIN_CMD_DEV_MODE_SET 0x11
 struct virtio_admin_cmd_hdr {
   __le16 opcode;
   __le16 group_type;
@@ -158,4 +177,101 @@
 struct virtio_admin_cmd_notify_info_result {
   struct virtio_admin_cmd_notify_info_data entries[VIRTIO_ADMIN_CMD_MAX_NOTIFY_INFO];
 };
+#define VIRTIO_DEV_PARTS_CAP 0x0000
+struct virtio_dev_parts_cap {
+  __u8 get_parts_resource_objects_limit;
+  __u8 set_parts_resource_objects_limit;
+};
+#define MAX_CAP_ID __KERNEL_DIV_ROUND_UP(VIRTIO_DEV_PARTS_CAP + 1, 64)
+struct virtio_admin_cmd_query_cap_id_result {
+  __le64 supported_caps[MAX_CAP_ID];
+};
+struct virtio_admin_cmd_cap_get_data {
+  __le16 id;
+  __u8 reserved[6];
+};
+struct virtio_admin_cmd_cap_set_data {
+  __le16 id;
+  __u8 reserved[6];
+  __u8 cap_specific_data[];
+};
+struct virtio_admin_cmd_resource_obj_cmd_hdr {
+  __le16 type;
+  __u8 reserved[2];
+  __le32 id;
+};
+struct virtio_admin_cmd_resource_obj_create_data {
+  struct virtio_admin_cmd_resource_obj_cmd_hdr hdr;
+  __le64 flags;
+  __u8 resource_obj_specific_data[];
+};
+#define VIRTIO_RESOURCE_OBJ_DEV_PARTS 0
+#define VIRTIO_RESOURCE_OBJ_DEV_PARTS_TYPE_GET 0
+#define VIRTIO_RESOURCE_OBJ_DEV_PARTS_TYPE_SET 1
+struct virtio_resource_obj_dev_parts {
+  __u8 type;
+  __u8 reserved[7];
+};
+#define VIRTIO_ADMIN_CMD_DEV_PARTS_METADATA_TYPE_SIZE 0
+#define VIRTIO_ADMIN_CMD_DEV_PARTS_METADATA_TYPE_COUNT 1
+#define VIRTIO_ADMIN_CMD_DEV_PARTS_METADATA_TYPE_LIST 2
+struct virtio_admin_cmd_dev_parts_metadata_data {
+  struct virtio_admin_cmd_resource_obj_cmd_hdr hdr;
+  __u8 type;
+  __u8 reserved[7];
+};
+#define VIRTIO_DEV_PART_F_OPTIONAL 0
+struct virtio_dev_part_hdr {
+  __le16 part_type;
+  __u8 flags;
+  __u8 reserved;
+  union {
+    struct {
+      __le32 offset;
+      __le32 reserved;
+    } pci_common_cfg;
+    struct {
+      __le16 index;
+      __u8 reserved[6];
+    } vq_index;
+  } selector;
+  __le32 length;
+};
+struct virtio_dev_part {
+  struct virtio_dev_part_hdr hdr;
+  __u8 value[];
+};
+struct virtio_admin_cmd_dev_parts_metadata_result {
+  union {
+    struct {
+      __le32 size;
+      __le32 reserved;
+    } parts_size;
+    struct {
+      __le32 count;
+      __le32 reserved;
+    } hdr_list_count;
+    struct {
+      __le32 count;
+      __le32 reserved;
+      struct virtio_dev_part_hdr hdrs[];
+    } hdr_list;
+  };
+};
+#define VIRTIO_ADMIN_CMD_DEV_PARTS_GET_TYPE_SELECTED 0
+#define VIRTIO_ADMIN_CMD_DEV_PARTS_GET_TYPE_ALL 1
+struct virtio_admin_cmd_dev_parts_get_data {
+  struct virtio_admin_cmd_resource_obj_cmd_hdr hdr;
+  __u8 type;
+  __u8 reserved[7];
+  struct virtio_dev_part_hdr hdr_list[];
+};
+struct virtio_admin_cmd_dev_parts_set_data {
+  struct virtio_admin_cmd_resource_obj_cmd_hdr hdr;
+  struct virtio_dev_part parts[];
+};
+#define VIRTIO_ADMIN_CMD_DEV_MODE_F_STOPPED 0
+struct virtio_admin_cmd_dev_mode_set_data {
+  __u8 flags;
+};
 #endif
diff --git a/libc/kernel/uapi/linux/virtio_rtc.h b/libc/kernel/uapi/linux/virtio_rtc.h
new file mode 100644
index 0000000..e4f0ee0
--- /dev/null
+++ b/libc/kernel/uapi/linux/virtio_rtc.h
@@ -0,0 +1,160 @@
+/*
+ * This file is auto-generated. Modifications will be lost.
+ *
+ * See https://android.googlesource.com/platform/bionic/+/master/libc/kernel/
+ * for more information.
+ */
+#ifndef _LINUX_VIRTIO_RTC_H
+#define _LINUX_VIRTIO_RTC_H
+#include <linux/types.h>
+#define VIRTIO_RTC_F_ALARM 0
+#define VIRTIO_RTC_REQ_READ 0x0001
+#define VIRTIO_RTC_REQ_READ_CROSS 0x0002
+#define VIRTIO_RTC_REQ_CFG 0x1000
+#define VIRTIO_RTC_REQ_CLOCK_CAP 0x1001
+#define VIRTIO_RTC_REQ_CROSS_CAP 0x1002
+#define VIRTIO_RTC_REQ_READ_ALARM 0x1003
+#define VIRTIO_RTC_REQ_SET_ALARM 0x1004
+#define VIRTIO_RTC_REQ_SET_ALARM_ENABLED 0x1005
+#define VIRTIO_RTC_NOTIF_ALARM 0x2000
+struct virtio_rtc_req_head {
+  __le16 msg_type;
+  __u8 reserved[6];
+};
+struct virtio_rtc_resp_head {
+#define VIRTIO_RTC_S_OK 0
+#define VIRTIO_RTC_S_EOPNOTSUPP 2
+#define VIRTIO_RTC_S_ENODEV 3
+#define VIRTIO_RTC_S_EINVAL 4
+#define VIRTIO_RTC_S_EIO 5
+  __u8 status;
+  __u8 reserved[7];
+};
+struct virtio_rtc_notif_head {
+  __le16 msg_type;
+  __u8 reserved[6];
+};
+struct virtio_rtc_req_read {
+  struct virtio_rtc_req_head head;
+  __le16 clock_id;
+  __u8 reserved[6];
+};
+struct virtio_rtc_resp_read {
+  struct virtio_rtc_resp_head head;
+  __le64 clock_reading;
+};
+struct virtio_rtc_req_read_cross {
+  struct virtio_rtc_req_head head;
+  __le16 clock_id;
+#define VIRTIO_RTC_COUNTER_ARM_VCT 0
+#define VIRTIO_RTC_COUNTER_X86_TSC 1
+#define VIRTIO_RTC_COUNTER_INVALID 0xFF
+  __u8 hw_counter;
+  __u8 reserved[5];
+};
+struct virtio_rtc_resp_read_cross {
+  struct virtio_rtc_resp_head head;
+  __le64 clock_reading;
+  __le64 counter_cycles;
+};
+struct virtio_rtc_req_cfg {
+  struct virtio_rtc_req_head head;
+};
+struct virtio_rtc_resp_cfg {
+  struct virtio_rtc_resp_head head;
+  __le16 num_clocks;
+  __u8 reserved[6];
+};
+struct virtio_rtc_req_clock_cap {
+  struct virtio_rtc_req_head head;
+  __le16 clock_id;
+  __u8 reserved[6];
+};
+struct virtio_rtc_resp_clock_cap {
+  struct virtio_rtc_resp_head head;
+#define VIRTIO_RTC_CLOCK_UTC 0
+#define VIRTIO_RTC_CLOCK_TAI 1
+#define VIRTIO_RTC_CLOCK_MONOTONIC 2
+#define VIRTIO_RTC_CLOCK_UTC_SMEARED 3
+#define VIRTIO_RTC_CLOCK_UTC_MAYBE_SMEARED 4
+  __u8 type;
+#define VIRTIO_RTC_SMEAR_UNSPECIFIED 0
+#define VIRTIO_RTC_SMEAR_NOON_LINEAR 1
+#define VIRTIO_RTC_SMEAR_UTC_SLS 2
+  __u8 leap_second_smearing;
+#define VIRTIO_RTC_FLAG_ALARM_CAP (1 << 0)
+  __u8 flags;
+  __u8 reserved[5];
+};
+struct virtio_rtc_req_cross_cap {
+  struct virtio_rtc_req_head head;
+  __le16 clock_id;
+  __u8 hw_counter;
+  __u8 reserved[5];
+};
+struct virtio_rtc_resp_cross_cap {
+  struct virtio_rtc_resp_head head;
+#define VIRTIO_RTC_FLAG_CROSS_CAP (1 << 0)
+  __u8 flags;
+  __u8 reserved[7];
+};
+struct virtio_rtc_req_read_alarm {
+  struct virtio_rtc_req_head head;
+  __le16 clock_id;
+  __u8 reserved[6];
+};
+struct virtio_rtc_resp_read_alarm {
+  struct virtio_rtc_resp_head head;
+  __le64 alarm_time;
+#define VIRTIO_RTC_FLAG_ALARM_ENABLED (1 << 0)
+  __u8 flags;
+  __u8 reserved[7];
+};
+struct virtio_rtc_req_set_alarm {
+  struct virtio_rtc_req_head head;
+  __le64 alarm_time;
+  __le16 clock_id;
+  __u8 flags;
+  __u8 reserved[5];
+};
+struct virtio_rtc_resp_set_alarm {
+  struct virtio_rtc_resp_head head;
+};
+struct virtio_rtc_req_set_alarm_enabled {
+  struct virtio_rtc_req_head head;
+  __le16 clock_id;
+  __u8 flags;
+  __u8 reserved[5];
+};
+struct virtio_rtc_resp_set_alarm_enabled {
+  struct virtio_rtc_resp_head head;
+};
+union virtio_rtc_req_requestq {
+  struct virtio_rtc_req_read read;
+  struct virtio_rtc_req_read_cross read_cross;
+  struct virtio_rtc_req_cfg cfg;
+  struct virtio_rtc_req_clock_cap clock_cap;
+  struct virtio_rtc_req_cross_cap cross_cap;
+  struct virtio_rtc_req_read_alarm read_alarm;
+  struct virtio_rtc_req_set_alarm set_alarm;
+  struct virtio_rtc_req_set_alarm_enabled set_alarm_enabled;
+};
+union virtio_rtc_resp_requestq {
+  struct virtio_rtc_resp_read read;
+  struct virtio_rtc_resp_read_cross read_cross;
+  struct virtio_rtc_resp_cfg cfg;
+  struct virtio_rtc_resp_clock_cap clock_cap;
+  struct virtio_rtc_resp_cross_cap cross_cap;
+  struct virtio_rtc_resp_read_alarm read_alarm;
+  struct virtio_rtc_resp_set_alarm set_alarm;
+  struct virtio_rtc_resp_set_alarm_enabled set_alarm_enabled;
+};
+struct virtio_rtc_notif_alarm {
+  struct virtio_rtc_notif_head head;
+  __le16 clock_id;
+  __u8 reserved[6];
+};
+union virtio_rtc_notif_alarmq {
+  struct virtio_rtc_notif_alarm alarm;
+};
+#endif
diff --git a/libc/kernel/uapi/linux/vm_sockets.h b/libc/kernel/uapi/linux/vm_sockets.h
index bd84f44..4a1063f 100644
--- a/libc/kernel/uapi/linux/vm_sockets.h
+++ b/libc/kernel/uapi/linux/vm_sockets.h
@@ -6,6 +6,7 @@
  */
 #ifndef _UAPI_VM_SOCKETS_H
 #define _UAPI_VM_SOCKETS_H
+#include <sys/socket.h>
 #include <linux/socket.h>
 #include <linux/types.h>
 #define SO_VM_SOCKETS_BUFFER_SIZE 0
diff --git a/libc/kernel/uapi/linux/vmclock-abi.h b/libc/kernel/uapi/linux/vmclock-abi.h
new file mode 100644
index 0000000..cd67376
--- /dev/null
+++ b/libc/kernel/uapi/linux/vmclock-abi.h
@@ -0,0 +1,65 @@
+/*
+ * This file is auto-generated. Modifications will be lost.
+ *
+ * See https://android.googlesource.com/platform/bionic/+/master/libc/kernel/
+ * for more information.
+ */
+#ifndef __VMCLOCK_ABI_H__
+#define __VMCLOCK_ABI_H__
+#include <linux/types.h>
+struct vmclock_abi {
+  __le32 magic;
+#define VMCLOCK_MAGIC 0x4b4c4356
+  __le32 size;
+  __le16 version;
+  __u8 counter_id;
+#define VMCLOCK_COUNTER_ARM_VCNT 0
+#define VMCLOCK_COUNTER_X86_TSC 1
+#define VMCLOCK_COUNTER_INVALID 0xff
+  __u8 time_type;
+#define VMCLOCK_TIME_UTC 0
+#define VMCLOCK_TIME_TAI 1
+#define VMCLOCK_TIME_MONOTONIC 2
+#define VMCLOCK_TIME_INVALID_SMEARED 3
+#define VMCLOCK_TIME_INVALID_MAYBE_SMEARED 4
+  __le32 seq_count;
+  __le64 disruption_marker;
+  __le64 flags;
+#define VMCLOCK_FLAG_TAI_OFFSET_VALID (1 << 0)
+#define VMCLOCK_FLAG_DISRUPTION_SOON (1 << 1)
+#define VMCLOCK_FLAG_DISRUPTION_IMMINENT (1 << 2)
+#define VMCLOCK_FLAG_PERIOD_ESTERROR_VALID (1 << 3)
+#define VMCLOCK_FLAG_PERIOD_MAXERROR_VALID (1 << 4)
+#define VMCLOCK_FLAG_TIME_ESTERROR_VALID (1 << 5)
+#define VMCLOCK_FLAG_TIME_MAXERROR_VALID (1 << 6)
+#define VMCLOCK_FLAG_TIME_MONOTONIC (1 << 7)
+  __u8 pad[2];
+  __u8 clock_status;
+#define VMCLOCK_STATUS_UNKNOWN 0
+#define VMCLOCK_STATUS_INITIALIZING 1
+#define VMCLOCK_STATUS_SYNCHRONIZED 2
+#define VMCLOCK_STATUS_FREERUNNING 3
+#define VMCLOCK_STATUS_UNRELIABLE 4
+  __u8 leap_second_smearing_hint;
+#define VMCLOCK_SMEARING_STRICT 0
+#define VMCLOCK_SMEARING_NOON_LINEAR 1
+#define VMCLOCK_SMEARING_UTC_SLS 2
+  __le16 tai_offset_sec;
+  __u8 leap_indicator;
+#define VMCLOCK_LEAP_NONE 0x00
+#define VMCLOCK_LEAP_PRE_POS 0x01
+#define VMCLOCK_LEAP_PRE_NEG 0x02
+#define VMCLOCK_LEAP_POS 0x03
+#define VMCLOCK_LEAP_POST_POS 0x04
+#define VMCLOCK_LEAP_POST_NEG 0x05
+  __u8 counter_period_shift;
+  __le64 counter_value;
+  __le64 counter_period_frac_sec;
+  __le64 counter_period_esterror_rate_frac_sec;
+  __le64 counter_period_maxerror_rate_frac_sec;
+  __le64 time_sec;
+  __le64 time_frac_sec;
+  __le64 time_esterror_nanosec;
+  __le64 time_maxerror_nanosec;
+};
+#endif
diff --git a/libc/kernel/uapi/linux/vt.h b/libc/kernel/uapi/linux/vt.h
index a89e78c..5e50035 100644
--- a/libc/kernel/uapi/linux/vt.h
+++ b/libc/kernel/uapi/linux/vt.h
@@ -6,6 +6,8 @@
  */
 #ifndef _UAPI_LINUX_VT_H
 #define _UAPI_LINUX_VT_H
+#include <linux/ioctl.h>
+#include <linux/types.h>
 #define MIN_NR_CONSOLES 1
 #define MAX_NR_CONSOLES 63
 #define VT_OPENQRY 0x5600
@@ -67,4 +69,11 @@
   struct vt_mode mode;
 };
 #define VT_SETACTIVATE 0x560F
+struct vt_consizecsrpos {
+  __u16 con_rows;
+  __u16 con_cols;
+  __u16 csr_row;
+  __u16 csr_col;
+};
+#define VT_GETCONSIZECSRPOS _IOR('V', 0x10, struct vt_consizecsrpos)
 #endif
diff --git a/libc/kernel/uapi/linux/wireguard.h b/libc/kernel/uapi/linux/wireguard.h
index 2d3cbfd..fcdc886 100644
--- a/libc/kernel/uapi/linux/wireguard.h
+++ b/libc/kernel/uapi/linux/wireguard.h
@@ -53,11 +53,16 @@
   __WGPEER_A_LAST
 };
 #define WGPEER_A_MAX (__WGPEER_A_LAST - 1)
+enum wgallowedip_flag {
+  WGALLOWEDIP_F_REMOVE_ME = 1U << 0,
+  __WGALLOWEDIP_F_ALL = WGALLOWEDIP_F_REMOVE_ME
+};
 enum wgallowedip_attribute {
   WGALLOWEDIP_A_UNSPEC,
   WGALLOWEDIP_A_FAMILY,
   WGALLOWEDIP_A_IPADDR,
   WGALLOWEDIP_A_CIDR_MASK,
+  WGALLOWEDIP_A_FLAGS,
   __WGALLOWEDIP_A_LAST
 };
 #define WGALLOWEDIP_A_MAX (__WGALLOWEDIP_A_LAST - 1)
diff --git a/libc/kernel/uapi/linux/xattr.h b/libc/kernel/uapi/linux/xattr.h
index e126151..3b4084a 100644
--- a/libc/kernel/uapi/linux/xattr.h
+++ b/libc/kernel/uapi/linux/xattr.h
@@ -5,12 +5,18 @@
  * for more information.
  */
 #include <linux/libc-compat.h>
+#include <linux/types.h>
 #ifndef _UAPI_LINUX_XATTR_H
 #define _UAPI_LINUX_XATTR_H
 #if __UAPI_DEF_XATTR
 #define __USE_KERNEL_XATTR_DEFS
 #define XATTR_CREATE 0x1
 #define XATTR_REPLACE 0x2
+struct xattr_args {
+  __aligned_u64  value;
+  __u32 size;
+  __u32 flags;
+};
 #endif
 #define XATTR_OS2_PREFIX "os2."
 #define XATTR_OS2_PREFIX_LEN (sizeof(XATTR_OS2_PREFIX) - 1)
@@ -50,6 +56,9 @@
 #define XATTR_NAME_APPARMOR XATTR_SECURITY_PREFIX XATTR_APPARMOR_SUFFIX
 #define XATTR_CAPS_SUFFIX "capability"
 #define XATTR_NAME_CAPS XATTR_SECURITY_PREFIX XATTR_CAPS_SUFFIX
+#define XATTR_BPF_LSM_SUFFIX "bpf."
+#define XATTR_NAME_BPF_LSM (XATTR_SECURITY_PREFIX XATTR_BPF_LSM_SUFFIX)
+#define XATTR_NAME_BPF_LSM_LEN (sizeof(XATTR_NAME_BPF_LSM) - 1)
 #define XATTR_POSIX_ACL_ACCESS "posix_acl_access"
 #define XATTR_NAME_POSIX_ACL_ACCESS XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_ACCESS
 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
diff --git a/libc/kernel/uapi/linux/xfrm.h b/libc/kernel/uapi/linux/xfrm.h
index 9509efe..50cf1cd 100644
--- a/libc/kernel/uapi/linux/xfrm.h
+++ b/libc/kernel/uapi/linux/xfrm.h
@@ -126,7 +126,8 @@
 #define XFRM_MODE_ROUTEOPTIMIZATION 2
 #define XFRM_MODE_IN_TRIGGER 3
 #define XFRM_MODE_BEET 4
-#define XFRM_MODE_MAX 5
+#define XFRM_MODE_IPTFS 5
+#define XFRM_MODE_MAX 6
 enum {
   XFRM_MSG_BASE = 0x10,
   XFRM_MSG_NEWSA = 0x10,
@@ -261,6 +262,13 @@
   XFRMA_MTIMER_THRESH,
   XFRMA_SA_DIR,
   XFRMA_NAT_KEEPALIVE_INTERVAL,
+  XFRMA_SA_PCPU,
+  XFRMA_IPTFS_DROP_TIME,
+  XFRMA_IPTFS_REORDER_WINDOW,
+  XFRMA_IPTFS_DONT_FRAG,
+  XFRMA_IPTFS_INIT_DELAY,
+  XFRMA_IPTFS_MAX_QSIZE,
+  XFRMA_IPTFS_PKT_SIZE,
   __XFRMA_MAX
 #define XFRMA_OUTPUT_MARK XFRMA_SET_MARK
 #define XFRMA_MAX (__XFRMA_MAX - 1)
@@ -359,6 +367,7 @@
   __u8 flags;
 #define XFRM_POLICY_LOCALOK 1
 #define XFRM_POLICY_ICMP 2
+#define XFRM_POLICY_CPU_ACQUIRE 4
   __u8 share;
 };
 struct xfrm_userpolicy_id {
diff --git a/libc/kernel/uapi/misc/amd-apml.h b/libc/kernel/uapi/misc/amd-apml.h
new file mode 100644
index 0000000..705622e
--- /dev/null
+++ b/libc/kernel/uapi/misc/amd-apml.h
@@ -0,0 +1,36 @@
+/*
+ * This file is auto-generated. Modifications will be lost.
+ *
+ * See https://android.googlesource.com/platform/bionic/+/master/libc/kernel/
+ * for more information.
+ */
+#ifndef _AMD_APML_H_
+#define _AMD_APML_H_
+#include <linux/types.h>
+#define AMD_SBI_MB_DATA_SIZE 4
+struct apml_mbox_msg {
+  __u32 cmd;
+  __u32 mb_in_out;
+  __u32 fw_ret_code;
+};
+struct apml_cpuid_msg {
+  __u64 cpu_in_out;
+  __u32 fw_ret_code;
+  __u32 pad;
+};
+struct apml_mcamsr_msg {
+  __u64 mcamsr_in_out;
+  __u32 fw_ret_code;
+  __u32 pad;
+};
+struct apml_reg_xfer_msg {
+  __u16 reg_addr;
+  __u8 data_in_out;
+  __u8 rflag;
+};
+#define SB_BASE_IOCTL_NR 0xF9
+#define SBRMI_IOCTL_MBOX_CMD _IOWR(SB_BASE_IOCTL_NR, 0, struct apml_mbox_msg)
+#define SBRMI_IOCTL_CPUID_CMD _IOWR(SB_BASE_IOCTL_NR, 1, struct apml_cpuid_msg)
+#define SBRMI_IOCTL_MCAMSR_CMD _IOWR(SB_BASE_IOCTL_NR, 2, struct apml_mcamsr_msg)
+#define SBRMI_IOCTL_REG_XFER_CMD _IOWR(SB_BASE_IOCTL_NR, 3, struct apml_reg_xfer_msg)
+#endif
diff --git a/libc/kernel/uapi/misc/cxl.h b/libc/kernel/uapi/misc/cxl.h
deleted file mode 100644
index d05ef53..0000000
--- a/libc/kernel/uapi/misc/cxl.h
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * This file is auto-generated. Modifications will be lost.
- *
- * See https://android.googlesource.com/platform/bionic/+/master/libc/kernel/
- * for more information.
- */
-#ifndef _UAPI_MISC_CXL_H
-#define _UAPI_MISC_CXL_H
-#include <linux/types.h>
-#include <linux/ioctl.h>
-struct cxl_ioctl_start_work {
-  __u64 flags;
-  __u64 work_element_descriptor;
-  __u64 amr;
-  __s16 num_interrupts;
-  __u16 tid;
-  __s32 reserved1;
-  __u64 reserved2;
-  __u64 reserved3;
-  __u64 reserved4;
-  __u64 reserved5;
-};
-#define CXL_START_WORK_AMR 0x0000000000000001ULL
-#define CXL_START_WORK_NUM_IRQS 0x0000000000000002ULL
-#define CXL_START_WORK_ERR_FF 0x0000000000000004ULL
-#define CXL_START_WORK_TID 0x0000000000000008ULL
-#define CXL_START_WORK_ALL (CXL_START_WORK_AMR | CXL_START_WORK_NUM_IRQS | CXL_START_WORK_ERR_FF | CXL_START_WORK_TID)
-#define CXL_MODE_DEDICATED 0x1
-#define CXL_MODE_DIRECTED 0x2
-#define CXL_AFUID_FLAG_SLAVE 0x1
-struct cxl_afu_id {
-  __u64 flags;
-  __u32 card_id;
-  __u32 afu_offset;
-  __u32 afu_mode;
-  __u32 reserved1;
-  __u64 reserved2;
-  __u64 reserved3;
-  __u64 reserved4;
-  __u64 reserved5;
-  __u64 reserved6;
-};
-#define CXL_AI_NEED_HEADER 0x0000000000000001ULL
-#define CXL_AI_ALL CXL_AI_NEED_HEADER
-#define CXL_AI_HEADER_SIZE 128
-#define CXL_AI_BUFFER_SIZE 4096
-#define CXL_AI_MAX_ENTRIES 256
-#define CXL_AI_MAX_CHUNK_SIZE (CXL_AI_BUFFER_SIZE * CXL_AI_MAX_ENTRIES)
-struct cxl_adapter_image {
-  __u64 flags;
-  __u64 data;
-  __u64 len_data;
-  __u64 len_image;
-  __u64 reserved1;
-  __u64 reserved2;
-  __u64 reserved3;
-  __u64 reserved4;
-};
-#define CXL_MAGIC 0xCA
-#define CXL_IOCTL_START_WORK _IOW(CXL_MAGIC, 0x00, struct cxl_ioctl_start_work)
-#define CXL_IOCTL_GET_PROCESS_ELEMENT _IOR(CXL_MAGIC, 0x01, __u32)
-#define CXL_IOCTL_GET_AFU_ID _IOR(CXL_MAGIC, 0x02, struct cxl_afu_id)
-#define CXL_IOCTL_DOWNLOAD_IMAGE _IOW(CXL_MAGIC, 0x0A, struct cxl_adapter_image)
-#define CXL_IOCTL_VALIDATE_IMAGE _IOW(CXL_MAGIC, 0x0B, struct cxl_adapter_image)
-#define CXL_READ_MIN_SIZE 0x1000
-enum cxl_event_type {
-  CXL_EVENT_RESERVED = 0,
-  CXL_EVENT_AFU_INTERRUPT = 1,
-  CXL_EVENT_DATA_STORAGE = 2,
-  CXL_EVENT_AFU_ERROR = 3,
-  CXL_EVENT_AFU_DRIVER = 4,
-};
-struct cxl_event_header {
-  __u16 type;
-  __u16 size;
-  __u16 process_element;
-  __u16 reserved1;
-};
-struct cxl_event_afu_interrupt {
-  __u16 flags;
-  __u16 irq;
-  __u32 reserved1;
-};
-struct cxl_event_data_storage {
-  __u16 flags;
-  __u16 reserved1;
-  __u32 reserved2;
-  __u64 addr;
-  __u64 dsisr;
-  __u64 reserved3;
-};
-struct cxl_event_afu_error {
-  __u16 flags;
-  __u16 reserved1;
-  __u32 reserved2;
-  __u64 error;
-};
-struct cxl_event_afu_driver_reserved {
-  __u32 data_size;
-  __u8 data[];
-};
-struct cxl_event {
-  struct cxl_event_header header;
-  union {
-    struct cxl_event_afu_interrupt irq;
-    struct cxl_event_data_storage fault;
-    struct cxl_event_afu_error afu_error;
-    struct cxl_event_afu_driver_reserved afu_driver_event;
-  };
-};
-#endif
diff --git a/libc/kernel/uapi/mtd/ubi-user.h b/libc/kernel/uapi/mtd/ubi-user.h
index bb9a6cb..4c22a9b 100644
--- a/libc/kernel/uapi/mtd/ubi-user.h
+++ b/libc/kernel/uapi/mtd/ubi-user.h
@@ -17,6 +17,7 @@
 #define UBI_IOCRNVOL _IOW(UBI_IOC_MAGIC, 3, struct ubi_rnvol_req)
 #define UBI_IOCRPEB _IOW(UBI_IOC_MAGIC, 4, __s32)
 #define UBI_IOCSPEB _IOW(UBI_IOC_MAGIC, 5, __s32)
+#define UBI_IOCECNFO _IOWR(UBI_IOC_MAGIC, 6, struct ubi_ecinfo_req)
 #define UBI_CTRL_IOC_MAGIC 'o'
 #define UBI_IOCATT _IOW(UBI_CTRL_IOC_MAGIC, 64, struct ubi_attach_req)
 #define UBI_IOCDET _IOW(UBI_CTRL_IOC_MAGIC, 65, __s32)
@@ -76,6 +77,13 @@
     char name[UBI_MAX_VOLUME_NAME + 1];
   } ents[UBI_MAX_RNVOL];
 } __attribute__((__packed__));
+struct ubi_ecinfo_req {
+  __s32 start;
+  __s32 length;
+  __s32 read_length;
+  __s8 padding[16];
+  __s32 erase_counters[];
+} __attribute__((__packed__));
 struct ubi_leb_change_req {
   __s32 lnum;
   __s32 bytes;
diff --git a/libc/kernel/uapi/rdma/efa-abi.h b/libc/kernel/uapi/rdma/efa-abi.h
index d4a9089..3e807d2 100644
--- a/libc/kernel/uapi/rdma/efa-abi.h
+++ b/libc/kernel/uapi/rdma/efa-abi.h
@@ -72,7 +72,8 @@
   __u32 sq_ring_size;
   __u32 driver_qp_type;
   __u16 flags;
-  __u8 reserved_90[6];
+  __u8 sl;
+  __u8 reserved_98[5];
 };
 struct efa_ibv_create_qp_resp {
   __u32 comp_mask;
diff --git a/libc/kernel/uapi/rdma/ib_user_ioctl_cmds.h b/libc/kernel/uapi/rdma/ib_user_ioctl_cmds.h
index 5f5c426..b4d4605 100644
--- a/libc/kernel/uapi/rdma/ib_user_ioctl_cmds.h
+++ b/libc/kernel/uapi/rdma/ib_user_ioctl_cmds.h
@@ -54,6 +54,7 @@
 enum uverbs_attrs_get_context_attr_ids {
   UVERBS_ATTR_GET_CONTEXT_NUM_COMP_VECTORS,
   UVERBS_ATTR_GET_CONTEXT_CORE_SUPPORT,
+  UVERBS_ATTR_GET_CONTEXT_FD_ARR,
 };
 enum uverbs_attrs_query_context_attr_ids {
   UVERBS_ATTR_QUERY_CONTEXT_NUM_COMP_VECTORS,
diff --git a/libc/kernel/uapi/rdma/ib_user_verbs.h b/libc/kernel/uapi/rdma/ib_user_verbs.h
index 6e27db4..2a018e6 100644
--- a/libc/kernel/uapi/rdma/ib_user_verbs.h
+++ b/libc/kernel/uapi/rdma/ib_user_verbs.h
@@ -160,6 +160,20 @@
   __u32 comp_mask;
   __u32 reserved;
 };
+enum ib_uverbs_odp_general_cap_bits {
+  IB_UVERBS_ODP_SUPPORT = 1 << 0,
+  IB_UVERBS_ODP_SUPPORT_IMPLICIT = 1 << 1,
+};
+enum ib_uverbs_odp_transport_cap_bits {
+  IB_UVERBS_ODP_SUPPORT_SEND = 1 << 0,
+  IB_UVERBS_ODP_SUPPORT_RECV = 1 << 1,
+  IB_UVERBS_ODP_SUPPORT_WRITE = 1 << 2,
+  IB_UVERBS_ODP_SUPPORT_READ = 1 << 3,
+  IB_UVERBS_ODP_SUPPORT_ATOMIC = 1 << 4,
+  IB_UVERBS_ODP_SUPPORT_SRQ_RECV = 1 << 5,
+  IB_UVERBS_ODP_SUPPORT_FLUSH = 1 << 6,
+  IB_UVERBS_ODP_SUPPORT_ATOMIC_WRITE = 1 << 7,
+};
 struct ib_uverbs_odp_caps {
   __aligned_u64 general_caps;
   struct {
diff --git a/libc/kernel/uapi/rdma/mlx5-abi.h b/libc/kernel/uapi/rdma/mlx5-abi.h
index 22cf99e..7989456 100644
--- a/libc/kernel/uapi/rdma/mlx5-abi.h
+++ b/libc/kernel/uapi/rdma/mlx5-abi.h
@@ -165,6 +165,7 @@
   MLX5_IB_QUERY_DEV_RESP_FLAGS_CQE_128B_PAD = 1 << 1,
   MLX5_IB_QUERY_DEV_RESP_PACKET_BASED_CREDIT_MODE = 1 << 2,
   MLX5_IB_QUERY_DEV_RESP_FLAGS_SCAT2CQE_DCT = 1 << 3,
+  MLX5_IB_QUERY_DEV_RESP_FLAGS_OOO_DP = 1 << 4,
 };
 enum mlx5_ib_tunnel_offloads {
   MLX5_IB_TUNNELED_OFFLOADS_VXLAN = 1 << 0,
@@ -321,6 +322,9 @@
   __u16 typical_pkt_sz;
   __u16 reserved;
 };
+enum mlx5_ib_modify_qp_mask {
+  MLX5_IB_MODIFY_QP_OOO_DP = 1 << 0,
+};
 struct mlx5_ib_modify_qp {
   __u32 comp_mask;
   struct mlx5_ib_burst_info burst_info;
diff --git a/libc/kernel/uapi/rdma/mlx5_user_ioctl_cmds.h b/libc/kernel/uapi/rdma/mlx5_user_ioctl_cmds.h
index 2e61c71..119d9d1 100644
--- a/libc/kernel/uapi/rdma/mlx5_user_ioctl_cmds.h
+++ b/libc/kernel/uapi/rdma/mlx5_user_ioctl_cmds.h
@@ -177,6 +177,7 @@
   MLX5_IB_ATTR_FLOW_MATCHER_MATCH_CRITERIA,
   MLX5_IB_ATTR_FLOW_MATCHER_FLOW_FLAGS,
   MLX5_IB_ATTR_FLOW_MATCHER_FT_TYPE,
+  MLX5_IB_ATTR_FLOW_MATCHER_IB_PORT,
 };
 enum mlx5_ib_flow_matcher_destroy_attrs {
   MLX5_IB_ATTR_FLOW_MATCHER_DESTROY_HANDLE = (1U << UVERBS_ID_NS_SHIFT),
diff --git a/libc/kernel/uapi/rdma/mlx5_user_ioctl_verbs.h b/libc/kernel/uapi/rdma/mlx5_user_ioctl_verbs.h
index 3fe3c82..6af77c4 100644
--- a/libc/kernel/uapi/rdma/mlx5_user_ioctl_verbs.h
+++ b/libc/kernel/uapi/rdma/mlx5_user_ioctl_verbs.h
@@ -16,6 +16,8 @@
   MLX5_IB_UAPI_FLOW_TABLE_TYPE_FDB = 0x2,
   MLX5_IB_UAPI_FLOW_TABLE_TYPE_RDMA_RX = 0x3,
   MLX5_IB_UAPI_FLOW_TABLE_TYPE_RDMA_TX = 0x4,
+  MLX5_IB_UAPI_FLOW_TABLE_TYPE_RDMA_TRANSPORT_RX = 0x5,
+  MLX5_IB_UAPI_FLOW_TABLE_TYPE_RDMA_TRANSPORT_TX = 0x6,
 };
 enum mlx5_ib_uapi_flow_action_packet_reformat_type {
   MLX5_IB_UAPI_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2 = 0x0,
diff --git a/libc/kernel/uapi/rdma/rdma_netlink.h b/libc/kernel/uapi/rdma/rdma_netlink.h
index 137b68f..d8d5745 100644
--- a/libc/kernel/uapi/rdma/rdma_netlink.h
+++ b/libc/kernel/uapi/rdma/rdma_netlink.h
@@ -315,6 +315,7 @@
   RDMA_NLDEV_ATTR_NAME_ASSIGN_TYPE,
   RDMA_NLDEV_ATTR_EVENT_TYPE,
   RDMA_NLDEV_SYS_ATTR_MONITOR_MODE,
+  RDMA_NLDEV_ATTR_STAT_OPCOUNTER_ENABLED,
   RDMA_NLDEV_ATTR_MAX
 };
 enum rdma_nl_counter_mode {
@@ -339,5 +340,7 @@
   RDMA_UNREGISTER_EVENT,
   RDMA_NETDEV_ATTACH_EVENT,
   RDMA_NETDEV_DETACH_EVENT,
+  RDMA_RENAME_EVENT,
+  RDMA_NETDEV_RENAME_EVENT,
 };
 #endif
diff --git a/libc/kernel/uapi/scsi/cxlflash_ioctl.h b/libc/kernel/uapi/scsi/cxlflash_ioctl.h
deleted file mode 100644
index 008b77c..0000000
--- a/libc/kernel/uapi/scsi/cxlflash_ioctl.h
+++ /dev/null
@@ -1,174 +0,0 @@
-/*
- * This file is auto-generated. Modifications will be lost.
- *
- * See https://android.googlesource.com/platform/bionic/+/master/libc/kernel/
- * for more information.
- */
-#ifndef _CXLFLASH_IOCTL_H
-#define _CXLFLASH_IOCTL_H
-#include <linux/types.h>
-#define CXLFLASH_WWID_LEN 16
-#define DK_CXLFLASH_VERSION_0 0
-struct dk_cxlflash_hdr {
-  __u16 version;
-  __u16 rsvd[3];
-  __u64 flags;
-  __u64 return_flags;
-};
-#define DK_CXLFLASH_ALL_PORTS_ACTIVE 0x0000000000000001ULL
-#define DK_CXLFLASH_APP_CLOSE_ADAP_FD 0x0000000000000002ULL
-#define DK_CXLFLASH_CONTEXT_SQ_CMD_MODE 0x0000000000000004ULL
-#define DK_CXLFLASH_ATTACH_REUSE_CONTEXT 0x8000000000000000ULL
-struct dk_cxlflash_attach {
-  struct dk_cxlflash_hdr hdr;
-  __u64 num_interrupts;
-  __u64 context_id;
-  __u64 mmio_size;
-  __u64 block_size;
-  __u64 adap_fd;
-  __u64 last_lba;
-  __u64 max_xfer;
-  __u64 reserved[8];
-};
-struct dk_cxlflash_detach {
-  struct dk_cxlflash_hdr hdr;
-  __u64 context_id;
-  __u64 reserved[8];
-};
-struct dk_cxlflash_udirect {
-  struct dk_cxlflash_hdr hdr;
-  __u64 context_id;
-  __u64 rsrc_handle;
-  __u64 last_lba;
-  __u64 reserved[8];
-};
-#define DK_CXLFLASH_UVIRTUAL_NEED_WRITE_SAME 0x8000000000000000ULL
-struct dk_cxlflash_uvirtual {
-  struct dk_cxlflash_hdr hdr;
-  __u64 context_id;
-  __u64 lun_size;
-  __u64 rsrc_handle;
-  __u64 last_lba;
-  __u64 reserved[8];
-};
-struct dk_cxlflash_release {
-  struct dk_cxlflash_hdr hdr;
-  __u64 context_id;
-  __u64 rsrc_handle;
-  __u64 reserved[8];
-};
-struct dk_cxlflash_resize {
-  struct dk_cxlflash_hdr hdr;
-  __u64 context_id;
-  __u64 rsrc_handle;
-  __u64 req_size;
-  __u64 last_lba;
-  __u64 reserved[8];
-};
-struct dk_cxlflash_clone {
-  struct dk_cxlflash_hdr hdr;
-  __u64 context_id_src;
-  __u64 context_id_dst;
-  __u64 adap_fd_src;
-  __u64 reserved[8];
-};
-#define DK_CXLFLASH_VERIFY_SENSE_LEN 18
-#define DK_CXLFLASH_VERIFY_HINT_SENSE 0x8000000000000000ULL
-struct dk_cxlflash_verify {
-  struct dk_cxlflash_hdr hdr;
-  __u64 context_id;
-  __u64 rsrc_handle;
-  __u64 hint;
-  __u64 last_lba;
-  __u8 sense_data[DK_CXLFLASH_VERIFY_SENSE_LEN];
-  __u8 pad[6];
-  __u64 reserved[8];
-};
-#define DK_CXLFLASH_RECOVER_AFU_CONTEXT_RESET 0x8000000000000000ULL
-struct dk_cxlflash_recover_afu {
-  struct dk_cxlflash_hdr hdr;
-  __u64 reason;
-  __u64 context_id;
-  __u64 mmio_size;
-  __u64 adap_fd;
-  __u64 reserved[8];
-};
-#define DK_CXLFLASH_MANAGE_LUN_WWID_LEN CXLFLASH_WWID_LEN
-#define DK_CXLFLASH_MANAGE_LUN_ENABLE_SUPERPIPE 0x8000000000000000ULL
-#define DK_CXLFLASH_MANAGE_LUN_DISABLE_SUPERPIPE 0x4000000000000000ULL
-#define DK_CXLFLASH_MANAGE_LUN_ALL_PORTS_ACCESSIBLE 0x2000000000000000ULL
-struct dk_cxlflash_manage_lun {
-  struct dk_cxlflash_hdr hdr;
-  __u8 wwid[DK_CXLFLASH_MANAGE_LUN_WWID_LEN];
-  __u64 reserved[8];
-};
-union cxlflash_ioctls {
-  struct dk_cxlflash_attach attach;
-  struct dk_cxlflash_detach detach;
-  struct dk_cxlflash_udirect udirect;
-  struct dk_cxlflash_uvirtual uvirtual;
-  struct dk_cxlflash_release release;
-  struct dk_cxlflash_resize resize;
-  struct dk_cxlflash_clone clone;
-  struct dk_cxlflash_verify verify;
-  struct dk_cxlflash_recover_afu recover_afu;
-  struct dk_cxlflash_manage_lun manage_lun;
-};
-#define MAX_CXLFLASH_IOCTL_SZ (sizeof(union cxlflash_ioctls))
-#define CXL_MAGIC 0xCA
-#define CXL_IOWR(_n,_s) _IOWR(CXL_MAGIC, _n, struct _s)
-#define DK_CXLFLASH_ATTACH CXL_IOWR(0x80, dk_cxlflash_attach)
-#define DK_CXLFLASH_USER_DIRECT CXL_IOWR(0x81, dk_cxlflash_udirect)
-#define DK_CXLFLASH_RELEASE CXL_IOWR(0x82, dk_cxlflash_release)
-#define DK_CXLFLASH_DETACH CXL_IOWR(0x83, dk_cxlflash_detach)
-#define DK_CXLFLASH_VERIFY CXL_IOWR(0x84, dk_cxlflash_verify)
-#define DK_CXLFLASH_RECOVER_AFU CXL_IOWR(0x85, dk_cxlflash_recover_afu)
-#define DK_CXLFLASH_MANAGE_LUN CXL_IOWR(0x86, dk_cxlflash_manage_lun)
-#define DK_CXLFLASH_USER_VIRTUAL CXL_IOWR(0x87, dk_cxlflash_uvirtual)
-#define DK_CXLFLASH_VLUN_RESIZE CXL_IOWR(0x88, dk_cxlflash_resize)
-#define DK_CXLFLASH_VLUN_CLONE CXL_IOWR(0x89, dk_cxlflash_clone)
-#define HT_CXLFLASH_VERSION_0 0
-struct ht_cxlflash_hdr {
-  __u16 version;
-  __u16 subcmd;
-  __u16 rsvd[2];
-  __u64 flags;
-  __u64 return_flags;
-};
-#define HT_CXLFLASH_HOST_READ 0x0000000000000000ULL
-#define HT_CXLFLASH_HOST_WRITE 0x0000000000000001ULL
-#define HT_CXLFLASH_LUN_PROVISION_SUBCMD_CREATE_LUN 0x0001
-#define HT_CXLFLASH_LUN_PROVISION_SUBCMD_DELETE_LUN 0x0002
-#define HT_CXLFLASH_LUN_PROVISION_SUBCMD_QUERY_PORT 0x0003
-struct ht_cxlflash_lun_provision {
-  struct ht_cxlflash_hdr hdr;
-  __u16 port;
-  __u16 reserved16[3];
-  __u64 size;
-  __u64 lun_id;
-  __u8 wwid[CXLFLASH_WWID_LEN];
-  __u64 max_num_luns;
-  __u64 cur_num_luns;
-  __u64 max_cap_port;
-  __u64 cur_cap_port;
-  __u64 reserved[8];
-};
-#define HT_CXLFLASH_AFU_DEBUG_MAX_DATA_LEN 262144
-#define HT_CXLFLASH_AFU_DEBUG_SUBCMD_LEN 12
-struct ht_cxlflash_afu_debug {
-  struct ht_cxlflash_hdr hdr;
-  __u8 reserved8[4];
-  __u8 afu_subcmd[HT_CXLFLASH_AFU_DEBUG_SUBCMD_LEN];
-  __u64 data_ea;
-  __u32 data_len;
-  __u32 reserved32;
-  __u64 reserved[8];
-};
-union cxlflash_ht_ioctls {
-  struct ht_cxlflash_lun_provision lun_provision;
-  struct ht_cxlflash_afu_debug afu_debug;
-};
-#define MAX_HT_CXLFLASH_IOCTL_SZ (sizeof(union cxlflash_ht_ioctls))
-#define HT_CXLFLASH_LUN_PROVISION CXL_IOWR(0xBF, ht_cxlflash_lun_provision)
-#define HT_CXLFLASH_AFU_DEBUG CXL_IOWR(0xBE, ht_cxlflash_afu_debug)
-#endif
diff --git a/libc/kernel/uapi/sound/asequencer.h b/libc/kernel/uapi/sound/asequencer.h
index 83b38f1..6b9d024 100644
--- a/libc/kernel/uapi/sound/asequencer.h
+++ b/libc/kernel/uapi/sound/asequencer.h
@@ -7,7 +7,7 @@
 #ifndef _UAPI__SOUND_ASEQUENCER_H
 #define _UAPI__SOUND_ASEQUENCER_H
 #include <sound/asound.h>
-#define SNDRV_SEQ_VERSION SNDRV_PROTOCOL_VERSION(1, 0, 4)
+#define SNDRV_SEQ_VERSION SNDRV_PROTOCOL_VERSION(1, 0, 5)
 #define SNDRV_SEQ_EVENT_SYSTEM 0
 #define SNDRV_SEQ_EVENT_RESULT 1
 #define SNDRV_SEQ_EVENT_NOTE 5
@@ -48,6 +48,8 @@
 #define SNDRV_SEQ_EVENT_PORT_CHANGE 65
 #define SNDRV_SEQ_EVENT_PORT_SUBSCRIBED 66
 #define SNDRV_SEQ_EVENT_PORT_UNSUBSCRIBED 67
+#define SNDRV_SEQ_EVENT_UMP_EP_CHANGE 68
+#define SNDRV_SEQ_EVENT_UMP_BLOCK_CHANGE 69
 #define SNDRV_SEQ_EVENT_USR0 90
 #define SNDRV_SEQ_EVENT_USR1 91
 #define SNDRV_SEQ_EVENT_USR2 92
@@ -152,6 +154,10 @@
   unsigned short value;
   struct snd_seq_event * event;
 } __attribute__((__packed__));
+struct snd_seq_ev_ump_notify {
+  unsigned char client;
+  unsigned char block;
+};
 union snd_seq_event_data {
   struct snd_seq_ev_note note;
   struct snd_seq_ev_ctrl control;
@@ -164,6 +170,7 @@
   struct snd_seq_connect connect;
   struct snd_seq_result result;
   struct snd_seq_ev_quote quote;
+  struct snd_seq_ev_ump_notify ump_notify;
 };
 struct snd_seq_event {
   snd_seq_event_type_t type;
diff --git a/libc/kernel/uapi/sound/asound.h b/libc/kernel/uapi/sound/asound.h
index cbebef3..6048a77 100644
--- a/libc/kernel/uapi/sound/asound.h
+++ b/libc/kernel/uapi/sound/asound.h
@@ -559,7 +559,7 @@
 #define SNDRV_PCM_IOCTL_READN_FRAMES _IOR('A', 0x53, struct snd_xfern)
 #define SNDRV_PCM_IOCTL_LINK _IOW('A', 0x60, int)
 #define SNDRV_PCM_IOCTL_UNLINK _IO('A', 0x61)
-#define SNDRV_RAWMIDI_VERSION SNDRV_PROTOCOL_VERSION(2, 0, 4)
+#define SNDRV_RAWMIDI_VERSION SNDRV_PROTOCOL_VERSION(2, 0, 5)
 enum {
   SNDRV_RAWMIDI_STREAM_OUTPUT = 0,
   SNDRV_RAWMIDI_STREAM_INPUT,
@@ -569,6 +569,8 @@
 #define SNDRV_RAWMIDI_INFO_INPUT 0x00000002
 #define SNDRV_RAWMIDI_INFO_DUPLEX 0x00000004
 #define SNDRV_RAWMIDI_INFO_UMP 0x00000008
+#define SNDRV_RAWMIDI_INFO_STREAM_INACTIVE 0x00000010
+#define SNDRV_RAWMIDI_DEVICE_UNKNOWN 0
 struct snd_rawmidi_info {
   unsigned int device;
   unsigned int subdevice;
@@ -580,7 +582,8 @@
   unsigned char subname[32];
   unsigned int subdevices_count;
   unsigned int subdevices_avail;
-  unsigned char reserved[64];
+  int tied_device;
+  unsigned char reserved[60];
 };
 #define SNDRV_RAWMIDI_MODE_FRAMING_MASK (7 << 0)
 #define SNDRV_RAWMIDI_MODE_FRAMING_SHIFT 0
diff --git a/libc/kernel/uapi/sound/compress_offload.h b/libc/kernel/uapi/sound/compress_offload.h
index db72c29..f014492 100644
--- a/libc/kernel/uapi/sound/compress_offload.h
+++ b/libc/kernel/uapi/sound/compress_offload.h
@@ -9,7 +9,7 @@
 #include <linux/types.h>
 #include <sound/asound.h>
 #include <sound/compress_params.h>
-#define SNDRV_COMPRESS_VERSION SNDRV_PROTOCOL_VERSION(0, 2, 0)
+#define SNDRV_COMPRESS_VERSION SNDRV_PROTOCOL_VERSION(0, 3, 0)
 struct snd_compressed_buffer {
   __u32 fragment_size;
   __u32 fragments;
@@ -32,7 +32,8 @@
 } __attribute__((packed, aligned(4)));
 enum snd_compr_direction {
   SND_COMPRESS_PLAYBACK = 0,
-  SND_COMPRESS_CAPTURE
+  SND_COMPRESS_CAPTURE,
+  SND_COMPRESS_ACCEL
 };
 struct snd_compr_caps {
   __u32 num_codecs;
@@ -57,6 +58,29 @@
   __u32 key;
   __u32 value[8];
 } __attribute__((packed, aligned(4)));
+#define SND_COMPRESS_TFLG_NEW_STREAM (1 << 0)
+struct snd_compr_task {
+  __u64 seqno;
+  __u64 origin_seqno;
+  int input_fd;
+  int output_fd;
+  __u64 input_size;
+  __u32 flags;
+  __u8 reserved[16];
+} __attribute__((packed, aligned(4)));
+enum snd_compr_state {
+  SND_COMPRESS_TASK_STATE_IDLE = 0,
+  SND_COMPRESS_TASK_STATE_ACTIVE,
+  SND_COMPRESS_TASK_STATE_FINISHED
+};
+struct snd_compr_task_status {
+  __u64 seqno;
+  __u64 input_size;
+  __u64 output_size;
+  __u32 output_flags;
+  __u8 state;
+  __u8 reserved[15];
+} __attribute__((packed, aligned(4)));
 #define SNDRV_COMPRESS_IOCTL_VERSION _IOR('C', 0x00, int)
 #define SNDRV_COMPRESS_GET_CAPS _IOWR('C', 0x10, struct snd_compr_caps)
 #define SNDRV_COMPRESS_GET_CODEC_CAPS _IOWR('C', 0x11, struct snd_compr_codec_caps)
@@ -73,6 +97,11 @@
 #define SNDRV_COMPRESS_DRAIN _IO('C', 0x34)
 #define SNDRV_COMPRESS_NEXT_TRACK _IO('C', 0x35)
 #define SNDRV_COMPRESS_PARTIAL_DRAIN _IO('C', 0x36)
+#define SNDRV_COMPRESS_TASK_CREATE _IOWR('C', 0x60, struct snd_compr_task)
+#define SNDRV_COMPRESS_TASK_FREE _IOW('C', 0x61, __u64)
+#define SNDRV_COMPRESS_TASK_START _IOWR('C', 0x62, struct snd_compr_task)
+#define SNDRV_COMPRESS_TASK_STOP _IOW('C', 0x63, __u64)
+#define SNDRV_COMPRESS_TASK_STATUS _IOWR('C', 0x68, struct snd_compr_task_status)
 #define SND_COMPR_TRIGGER_DRAIN 7
 #define SND_COMPR_TRIGGER_NEXT_TRACK 8
 #define SND_COMPR_TRIGGER_PARTIAL_DRAIN 9
diff --git a/libc/kernel/uapi/sound/compress_params.h b/libc/kernel/uapi/sound/compress_params.h
index 800f8f9..8920545 100644
--- a/libc/kernel/uapi/sound/compress_params.h
+++ b/libc/kernel/uapi/sound/compress_params.h
@@ -198,6 +198,13 @@
   struct snd_dec_wma wma_d;
   struct snd_dec_alac alac_d;
   struct snd_dec_ape ape_d;
+  struct {
+    __u32 out_sample_rate;
+  } src_d;
+} __attribute__((packed, aligned(4)));
+struct snd_codec_desc_src {
+  __u32 out_sample_rate_min;
+  __u32 out_sample_rate_max;
 } __attribute__((packed, aligned(4)));
 struct snd_codec_desc {
   __u32 max_ch;
@@ -210,7 +217,12 @@
   __u32 modes;
   __u32 formats;
   __u32 min_buffer;
-  __u32 reserved[15];
+  __u32 pcm_formats;
+  union {
+    __u32 u_space[6];
+    struct snd_codec_desc_src src;
+  } __attribute__((packed, aligned(4)));
+  __u32 reserved[8];
 } __attribute__((packed, aligned(4)));
 struct snd_codec {
   __u32 id;
@@ -225,6 +237,7 @@
   __u32 format;
   __u32 align;
   union snd_codec_options options;
-  __u32 reserved[3];
+  __u32 pcm_format;
+  __u32 reserved[2];
 } __attribute__((packed, aligned(4)));
 #endif
diff --git a/libc/kernel/uapi/sound/fcp.h b/libc/kernel/uapi/sound/fcp.h
new file mode 100644
index 0000000..104c5e0
--- /dev/null
+++ b/libc/kernel/uapi/sound/fcp.h
@@ -0,0 +1,45 @@
+/*
+ * This file is auto-generated. Modifications will be lost.
+ *
+ * See https://android.googlesource.com/platform/bionic/+/master/libc/kernel/
+ * for more information.
+ */
+#ifndef __UAPI_SOUND_FCP_H
+#define __UAPI_SOUND_FCP_H
+#include <linux/types.h>
+#include <linux/ioctl.h>
+#define FCP_HWDEP_MAJOR 2
+#define FCP_HWDEP_MINOR 0
+#define FCP_HWDEP_SUBMINOR 0
+#define FCP_HWDEP_VERSION ((FCP_HWDEP_MAJOR << 16) | (FCP_HWDEP_MINOR << 8) | FCP_HWDEP_SUBMINOR)
+#define FCP_HWDEP_VERSION_MAJOR(v) (((v) >> 16) & 0xFF)
+#define FCP_HWDEP_VERSION_MINOR(v) (((v) >> 8) & 0xFF)
+#define FCP_HWDEP_VERSION_SUBMINOR(v) ((v) & 0xFF)
+#define FCP_IOCTL_PVERSION _IOR('S', 0x60, int)
+struct fcp_init {
+  __u16 step0_resp_size;
+  __u16 step2_resp_size;
+  __u32 init1_opcode;
+  __u32 init2_opcode;
+  __u8 resp[];
+} __attribute__((packed));
+#define FCP_IOCTL_INIT _IOWR('S', 0x64, struct fcp_init)
+struct fcp_cmd {
+  __u32 opcode;
+  __u16 req_size;
+  __u16 resp_size;
+  __u8 data[];
+} __attribute__((packed));
+#define FCP_IOCTL_CMD _IOWR('S', 0x65, struct fcp_cmd)
+struct fcp_meter_map {
+  __u16 map_size;
+  __u16 meter_slots;
+  __s16 map[];
+} __attribute__((packed));
+#define FCP_IOCTL_SET_METER_MAP _IOW('S', 0x66, struct fcp_meter_map)
+struct fcp_meter_labels {
+  __u16 labels_size;
+  char labels[];
+} __attribute__((packed));
+#define FCP_IOCTL_SET_METER_LABELS _IOW('S', 0x67, struct fcp_meter_labels)
+#endif
diff --git a/libc/kernel/uapi/sound/intel/avs/tokens.h b/libc/kernel/uapi/sound/intel/avs/tokens.h
index 01b20a5..8f3d808 100644
--- a/libc/kernel/uapi/sound/intel/avs/tokens.h
+++ b/libc/kernel/uapi/sound/intel/avs/tokens.h
@@ -65,6 +65,17 @@
   AVS_TKN_MODCFG_UPDOWN_MIX_CHAN_MAP_U32 = 430,
   AVS_TKN_MODCFG_EXT_NUM_INPUT_PINS_U16 = 431,
   AVS_TKN_MODCFG_EXT_NUM_OUTPUT_PINS_U16 = 432,
+  AVS_TKN_MODCFG_WHM_REF_AFMT_ID_U32 = 433,
+  AVS_TKN_MODCFG_WHM_OUT_AFMT_ID_U32 = 434,
+  AVS_TKN_MODCFG_WHM_WAKE_TICK_PERIOD_U32 = 435,
+  AVS_TKN_MODCFG_WHM_VINDEX_U8 = 436,
+  AVS_TKN_MODCFG_WHM_DMA_TYPE_U32 = 437,
+  AVS_TKN_MODCFG_WHM_DMABUFF_SIZE_U32 = 438,
+  AVS_TKN_MODCFG_WHM_BLOB_AFMT_ID_U32 = 439,
+  AVS_TKN_MODCFG_PEAKVOL_VOLUME_U32 = 440,
+  AVS_TKN_MODCFG_PEAKVOL_CHANNEL_ID_U32 = 441,
+  AVS_TKN_MODCFG_PEAKVOL_CURVE_TYPE_U32 = 442,
+  AVS_TKN_MODCFG_PEAKVOL_CURVE_DURATION_U32 = 443,
   AVS_TKN_PPLCFG_ID_U32 = 1401,
   AVS_TKN_PPLCFG_REQ_SIZE_U16 = 1402,
   AVS_TKN_PPLCFG_PRIORITY_U8 = 1403,
diff --git a/libc/kernel/uapi/sound/sof/tokens.h b/libc/kernel/uapi/sound/sof/tokens.h
index c4257d9..922dec0 100644
--- a/libc/kernel/uapi/sound/sof/tokens.h
+++ b/libc/kernel/uapi/sound/sof/tokens.h
@@ -86,6 +86,8 @@
 #define SOF_TKN_IMX_ESAI_MCLK_ID 1100
 #define SOF_TKN_STREAM_PLAYBACK_COMPATIBLE_D0I3 1200
 #define SOF_TKN_STREAM_CAPTURE_COMPATIBLE_D0I3 1201
+#define SOF_TKN_STREAM_PLAYBACK_PAUSE_SUPPORTED 1202
+#define SOF_TKN_STREAM_CAPTURE_PAUSE_SUPPORTED 1203
 #define SOF_TKN_MUTE_LED_USE 1300
 #define SOF_TKN_MUTE_LED_DIRECTION 1301
 #define SOF_TKN_INTEL_ALH_RATE 1400
diff --git a/libc/kernel/uapi/sound/tlv.h b/libc/kernel/uapi/sound/tlv.h
index d9df82f..b31a5ef 100644
--- a/libc/kernel/uapi/sound/tlv.h
+++ b/libc/kernel/uapi/sound/tlv.h
@@ -15,6 +15,7 @@
 #define SNDRV_CTL_TLVT_CHMAP_FIXED 0x101
 #define SNDRV_CTL_TLVT_CHMAP_VAR 0x102
 #define SNDRV_CTL_TLVT_CHMAP_PAIRED 0x103
+#define SNDRV_CTL_TLVT_FCP_CHANNEL_LABELS 0x110
 #define SNDRV_CTL_TLVD_ITEM(type,...) (type), SNDRV_CTL_TLVD_LENGTH(__VA_ARGS__), __VA_ARGS__
 #define SNDRV_CTL_TLVD_LENGTH(...) ((unsigned int) sizeof((const unsigned int[]) { __VA_ARGS__ }))
 #define SNDRV_CTL_TLVO_TYPE 0
diff --git a/libc/malloc_debug/Android.bp b/libc/memory/malloc_debug/Android.bp
similarity index 88%
rename from libc/malloc_debug/Android.bp
rename to libc/memory/malloc_debug/Android.bp
index 50f24f6..fadaae3 100644
--- a/libc/malloc_debug/Android.bp
+++ b/libc/memory/malloc_debug/Android.bp
@@ -25,8 +25,9 @@
     stl: "libc++_static",
 
     whole_static_libs: [
-        "libbase",
         "libasync_safe",
+        "libbase",
+        "libunwindstack_demangle",
     ],
 
     include_dirs: ["bionic/libc"],
@@ -125,18 +126,12 @@
 // ==============================================================
 // Unit Tests
 // ==============================================================
-cc_test {
-    name: "malloc_debug_unit_tests",
-    test_suites: ["device-tests"],
-    isolated: true,
+cc_defaults {
+    name: "malloc_debug_tests",
 
     srcs: [
-        "tests/backtrace_fake.cpp",
         "tests/log_fake.cpp",
         "tests/libc_fake.cpp",
-        "tests/malloc_debug_config_tests.cpp",
-        "tests/malloc_debug_record_data_tests.cpp",
-        "tests/malloc_debug_unit_tests.cpp",
     ],
 
     local_include_dirs: ["tests"],
@@ -149,16 +144,15 @@
         "bionic_libc_platform_headers",
     ],
 
-    static_libs: [
-        "libc_malloc_debug",
-        "libtinyxml2",
-    ],
-
     shared_libs: [
         "libbase",
         "libunwindstack",
     ],
 
+    static_libs: [
+        "libc_malloc_debug",
+    ],
+
     cflags: [
         "-Wall",
         "-Werror",
@@ -167,6 +161,41 @@
     ],
 }
 
+cc_test {
+    name: "malloc_debug_system_record_unit_tests",
+    defaults: ["malloc_debug_tests"],
+    test_suites: ["device-tests"],
+    isolated: true,
+
+    srcs: [
+        "tests/malloc_debug_config_tests.cpp",
+        "tests/malloc_debug_record_data_tests.cpp",
+    ],
+}
+
+cc_test {
+    name: "malloc_debug_unit_tests",
+    defaults: ["malloc_debug_tests"],
+    test_suites: ["device-tests"],
+    isolated: true,
+
+    srcs: [
+        "tests/backtrace_fake.cpp",
+        "tests/malloc_debug_unit_tests.cpp",
+    ],
+
+    static_libs: [
+        "libtinyxml2",
+    ],
+
+    cflags: [
+        // This code uses malloc_usable_size(),
+        // and thus can't be built with _FORTIFY_SOURCE=3.
+        "-U_FORTIFY_SOURCE",
+        "-D_FORTIFY_SOURCE=2",
+    ],
+}
+
 // ==============================================================
 // System Tests
 // ==============================================================
diff --git a/libc/malloc_debug/Config.cpp b/libc/memory/malloc_debug/Config.cpp
similarity index 98%
rename from libc/malloc_debug/Config.cpp
rename to libc/memory/malloc_debug/Config.cpp
index 6be899d..f20bc10 100644
--- a/libc/malloc_debug/Config.cpp
+++ b/libc/memory/malloc_debug/Config.cpp
@@ -282,7 +282,7 @@
 
   // It's necessary to align the front guard to MINIMUM_ALIGNMENT_BYTES to
   // make sure that the header is aligned properly.
-  front_guard_bytes_ = __BIONIC_ALIGN(rear_guard_bytes_, MINIMUM_ALIGNMENT_BYTES);
+  front_guard_bytes_ = __builtin_align_up(rear_guard_bytes_, MINIMUM_ALIGNMENT_BYTES);
   return true;
 }
 
@@ -292,7 +292,7 @@
   }
   // It's necessary to align the front guard to MINIMUM_ALIGNMENT_BYTES to
   // make sure that the header is aligned properly.
-  front_guard_bytes_ = __BIONIC_ALIGN(front_guard_bytes_, MINIMUM_ALIGNMENT_BYTES);
+  front_guard_bytes_ = __builtin_align_up(front_guard_bytes_, MINIMUM_ALIGNMENT_BYTES);
   return true;
 }
 
diff --git a/libc/malloc_debug/Config.h b/libc/memory/malloc_debug/Config.h
similarity index 100%
rename from libc/malloc_debug/Config.h
rename to libc/memory/malloc_debug/Config.h
diff --git a/libc/malloc_debug/DebugData.cpp b/libc/memory/malloc_debug/DebugData.cpp
similarity index 97%
rename from libc/malloc_debug/DebugData.cpp
rename to libc/memory/malloc_debug/DebugData.cpp
index 885cc95..e8e695b 100644
--- a/libc/malloc_debug/DebugData.cpp
+++ b/libc/memory/malloc_debug/DebugData.cpp
@@ -44,7 +44,7 @@
   // Check to see if the options that require a header are enabled.
   if (config_.options() & HEADER_OPTIONS) {
     // Initialize all of the static header offsets.
-    pointer_offset_ = __BIONIC_ALIGN(sizeof(Header), MINIMUM_ALIGNMENT_BYTES);
+    pointer_offset_ = __builtin_align_up(sizeof(Header), MINIMUM_ALIGNMENT_BYTES);
 
     if (config_.options() & FRONT_GUARD) {
       front_guard.reset(new FrontGuardData(this, config_, &pointer_offset_));
diff --git a/libc/malloc_debug/DebugData.h b/libc/memory/malloc_debug/DebugData.h
similarity index 100%
rename from libc/malloc_debug/DebugData.h
rename to libc/memory/malloc_debug/DebugData.h
diff --git a/libc/malloc_debug/GuardData.cpp b/libc/memory/malloc_debug/GuardData.cpp
similarity index 100%
rename from libc/malloc_debug/GuardData.cpp
rename to libc/memory/malloc_debug/GuardData.cpp
diff --git a/libc/malloc_debug/GuardData.h b/libc/memory/malloc_debug/GuardData.h
similarity index 100%
rename from libc/malloc_debug/GuardData.h
rename to libc/memory/malloc_debug/GuardData.h
diff --git a/libc/malloc_debug/LogAllocatorStats.cpp b/libc/memory/malloc_debug/LogAllocatorStats.cpp
similarity index 98%
rename from libc/malloc_debug/LogAllocatorStats.cpp
rename to libc/memory/malloc_debug/LogAllocatorStats.cpp
index ee6bfdf..6ba505e 100644
--- a/libc/malloc_debug/LogAllocatorStats.cpp
+++ b/libc/memory/malloc_debug/LogAllocatorStats.cpp
@@ -31,6 +31,8 @@
 #include <signal.h>
 #include <unistd.h>
 
+#include <atomic>
+
 #include "Config.h"
 #include "LogAllocatorStats.h"
 #include "debug_log.h"
diff --git a/libc/malloc_debug/LogAllocatorStats.h b/libc/memory/malloc_debug/LogAllocatorStats.h
similarity index 100%
rename from libc/malloc_debug/LogAllocatorStats.h
rename to libc/memory/malloc_debug/LogAllocatorStats.h
diff --git a/libc/malloc_debug/MapData.cpp b/libc/memory/malloc_debug/MapData.cpp
similarity index 100%
rename from libc/malloc_debug/MapData.cpp
rename to libc/memory/malloc_debug/MapData.cpp
diff --git a/libc/malloc_debug/MapData.h b/libc/memory/malloc_debug/MapData.h
similarity index 100%
rename from libc/malloc_debug/MapData.h
rename to libc/memory/malloc_debug/MapData.h
diff --git a/libc/malloc_debug/Nanotime.h b/libc/memory/malloc_debug/Nanotime.h
similarity index 100%
rename from libc/malloc_debug/Nanotime.h
rename to libc/memory/malloc_debug/Nanotime.h
diff --git a/libc/malloc_debug/OptionData.h b/libc/memory/malloc_debug/OptionData.h
similarity index 100%
rename from libc/malloc_debug/OptionData.h
rename to libc/memory/malloc_debug/OptionData.h
diff --git a/libc/malloc_debug/PointerData.cpp b/libc/memory/malloc_debug/PointerData.cpp
similarity index 97%
rename from libc/malloc_debug/PointerData.cpp
rename to libc/memory/malloc_debug/PointerData.cpp
index e3a35a6..5129bf6 100644
--- a/libc/malloc_debug/PointerData.cpp
+++ b/libc/memory/malloc_debug/PointerData.cpp
@@ -26,7 +26,6 @@
  * SUCH DAMAGE.
  */
 
-#include <cxxabi.h>
 #include <errno.h>
 #include <inttypes.h>
 #include <signal.h>
@@ -36,6 +35,9 @@
 #include <sys/types.h>
 #include <unistd.h>
 
+#include <algorithm>
+#include <atomic>
+#include <deque>
 #include <functional>
 #include <mutex>
 #include <string>
@@ -46,6 +48,7 @@
 #include <android-base/stringprintf.h>
 #include <android-base/thread_annotations.h>
 #include <platform/bionic/macros.h>
+#include <unwindstack/Demangle.h>
 
 #include "Config.h"
 #include "DebugData.h"
@@ -616,16 +619,9 @@
         if (frame.function_name.empty()) {
           dprintf(fd, " \"\" 0}");
         } else {
-          char* demangled_name =
-              abi::__cxa_demangle(frame.function_name.c_str(), nullptr, nullptr, nullptr);
-          const char* name;
-          if (demangled_name != nullptr) {
-            name = demangled_name;
-          } else {
-            name = frame.function_name.c_str();
-          }
-          dprintf(fd, " \"%s\" %" PRIx64 "}", name, frame.function_offset);
-          free(demangled_name);
+          dprintf(fd, " \"%s\" %" PRIx64 "}",
+                  unwindstack::DemangleNameIfNeeded(frame.function_name).c_str(),
+                  frame.function_offset);
         }
       }
       dprintf(fd, "\n");
diff --git a/libc/malloc_debug/PointerData.h b/libc/memory/malloc_debug/PointerData.h
similarity index 100%
rename from libc/malloc_debug/PointerData.h
rename to libc/memory/malloc_debug/PointerData.h
diff --git a/libc/malloc_debug/README.md b/libc/memory/malloc_debug/README.md
similarity index 100%
rename from libc/malloc_debug/README.md
rename to libc/memory/malloc_debug/README.md
diff --git a/libc/malloc_debug/README_api.md b/libc/memory/malloc_debug/README_api.md
similarity index 100%
rename from libc/malloc_debug/README_api.md
rename to libc/memory/malloc_debug/README_api.md
diff --git a/libc/malloc_debug/README_marshmallow_and_earlier.md b/libc/memory/malloc_debug/README_marshmallow_and_earlier.md
similarity index 100%
rename from libc/malloc_debug/README_marshmallow_and_earlier.md
rename to libc/memory/malloc_debug/README_marshmallow_and_earlier.md
diff --git a/libc/malloc_debug/RecordData.cpp b/libc/memory/malloc_debug/RecordData.cpp
similarity index 100%
rename from libc/malloc_debug/RecordData.cpp
rename to libc/memory/malloc_debug/RecordData.cpp
diff --git a/libc/malloc_debug/RecordData.h b/libc/memory/malloc_debug/RecordData.h
similarity index 100%
rename from libc/malloc_debug/RecordData.h
rename to libc/memory/malloc_debug/RecordData.h
diff --git a/libc/malloc_debug/Unreachable.cpp b/libc/memory/malloc_debug/Unreachable.cpp
similarity index 100%
rename from libc/malloc_debug/Unreachable.cpp
rename to libc/memory/malloc_debug/Unreachable.cpp
diff --git a/libc/malloc_debug/Unreachable.h b/libc/memory/malloc_debug/Unreachable.h
similarity index 100%
rename from libc/malloc_debug/Unreachable.h
rename to libc/memory/malloc_debug/Unreachable.h
diff --git a/libc/malloc_debug/UnwindBacktrace.cpp b/libc/memory/malloc_debug/UnwindBacktrace.cpp
similarity index 91%
rename from libc/malloc_debug/UnwindBacktrace.cpp
rename to libc/memory/malloc_debug/UnwindBacktrace.cpp
index 8a6ff7b..740fabe 100644
--- a/libc/malloc_debug/UnwindBacktrace.cpp
+++ b/libc/memory/malloc_debug/UnwindBacktrace.cpp
@@ -26,7 +26,6 @@
  * SUCH DAMAGE.
  */
 
-#include <cxxabi.h>
 #include <inttypes.h>
 #include <pthread.h>
 #include <stdint.h>
@@ -38,6 +37,7 @@
 
 #include <android-base/stringprintf.h>
 #include <unwindstack/AndroidUnwinder.h>
+#include <unwindstack/Demangle.h>
 #include <unwindstack/Unwinder.h>
 
 #include "UnwindBacktrace.h"
@@ -88,14 +88,7 @@
 
     if (!info->function_name.empty()) {
       line += " (";
-      char* demangled_name =
-          abi::__cxa_demangle(info->function_name.c_str(), nullptr, nullptr, nullptr);
-      if (demangled_name != nullptr) {
-        line += demangled_name;
-        free(demangled_name);
-      } else {
-        line += info->function_name;
-      }
+      line += unwindstack::DemangleNameIfNeeded(info->function_name);
       if (info->function_offset != 0) {
         line += "+" + std::to_string(info->function_offset);
       }
diff --git a/libc/malloc_debug/UnwindBacktrace.h b/libc/memory/malloc_debug/UnwindBacktrace.h
similarity index 100%
rename from libc/malloc_debug/UnwindBacktrace.h
rename to libc/memory/malloc_debug/UnwindBacktrace.h
diff --git a/libc/malloc_debug/backtrace.cpp b/libc/memory/malloc_debug/backtrace.cpp
similarity index 90%
rename from libc/malloc_debug/backtrace.cpp
rename to libc/memory/malloc_debug/backtrace.cpp
index 6a32fca..8b58be3 100644
--- a/libc/malloc_debug/backtrace.cpp
+++ b/libc/memory/malloc_debug/backtrace.cpp
@@ -26,7 +26,6 @@
  * SUCH DAMAGE.
  */
 
-#include <cxxabi.h>
 #include <dlfcn.h>
 #include <errno.h>
 #include <inttypes.h>
@@ -41,6 +40,8 @@
 #include "backtrace.h"
 #include "debug_log.h"
 
+#include <unwindstack/Demangle.h>
+
 #if defined(__LP64__)
 #define PAD_PTR "016" PRIxPTR
 #else
@@ -154,18 +155,10 @@
 
     char buf[1024];
     if (symbol != nullptr) {
-      char* demangled_name = abi::__cxa_demangle(symbol, nullptr, nullptr, nullptr);
-      const char* name;
-      if (demangled_name != nullptr) {
-        name = demangled_name;
-      } else {
-        name = symbol;
-      }
-      async_safe_format_buffer(buf, sizeof(buf),
-                               "          #%02zd  pc %" PAD_PTR "  %s%s (%s+%" PRIuPTR ")\n",
-                               frame_num, rel_pc, soname, offset_buf, name,
-                               frames[frame_num] - offset);
-      free(demangled_name);
+      async_safe_format_buffer(
+          buf, sizeof(buf), "          #%02zd  pc %" PAD_PTR "  %s%s (%s+%" PRIuPTR ")\n",
+          frame_num, rel_pc, soname, offset_buf, unwindstack::DemangleNameIfNeeded(symbol).c_str(),
+          frames[frame_num] - offset);
     } else {
       async_safe_format_buffer(buf, sizeof(buf), "          #%02zd  pc %" PAD_PTR "  %s%s\n",
                                frame_num, rel_pc, soname, offset_buf);
diff --git a/libc/malloc_debug/backtrace.h b/libc/memory/malloc_debug/backtrace.h
similarity index 100%
rename from libc/malloc_debug/backtrace.h
rename to libc/memory/malloc_debug/backtrace.h
diff --git a/libc/malloc_debug/debug_disable.cpp b/libc/memory/malloc_debug/debug_disable.cpp
similarity index 100%
rename from libc/malloc_debug/debug_disable.cpp
rename to libc/memory/malloc_debug/debug_disable.cpp
diff --git a/libc/malloc_debug/debug_disable.h b/libc/memory/malloc_debug/debug_disable.h
similarity index 100%
rename from libc/malloc_debug/debug_disable.h
rename to libc/memory/malloc_debug/debug_disable.h
diff --git a/libc/malloc_debug/debug_log.h b/libc/memory/malloc_debug/debug_log.h
similarity index 100%
rename from libc/malloc_debug/debug_log.h
rename to libc/memory/malloc_debug/debug_log.h
diff --git a/libc/malloc_debug/exported32.map b/libc/memory/malloc_debug/exported32.map
similarity index 100%
rename from libc/malloc_debug/exported32.map
rename to libc/memory/malloc_debug/exported32.map
diff --git a/libc/malloc_debug/exported64.map b/libc/memory/malloc_debug/exported64.map
similarity index 100%
rename from libc/malloc_debug/exported64.map
rename to libc/memory/malloc_debug/exported64.map
diff --git a/libc/malloc_debug/malloc_debug.cpp b/libc/memory/malloc_debug/malloc_debug.cpp
similarity index 99%
rename from libc/malloc_debug/malloc_debug.cpp
rename to libc/memory/malloc_debug/malloc_debug.cpp
index 7e96169..dbf2d64 100644
--- a/libc/malloc_debug/malloc_debug.cpp
+++ b/libc/memory/malloc_debug/malloc_debug.cpp
@@ -39,6 +39,7 @@
 #include <sys/syscall.h>
 #include <unistd.h>
 
+#include <bit>
 #include <mutex>
 #include <vector>
 
@@ -751,9 +752,7 @@
   void* pointer;
   if (g_debug->HeaderEnabled()) {
     // Make the alignment a power of two.
-    if (!powerof2(alignment)) {
-      alignment = BIONIC_ROUND_UP_POWER_OF_2(alignment);
-    }
+    alignment = std::bit_ceil(alignment);
     // Force the alignment to at least MINIMUM_ALIGNMENT_BYTES to guarantee
     // that the header is aligned properly.
     if (alignment < MINIMUM_ALIGNMENT_BYTES) {
@@ -1195,7 +1194,7 @@
   }
 
   size_t pagesize = getpagesize();
-  size_t size = __BIONIC_ALIGN(bytes, pagesize);
+  size_t size = __builtin_align_up(bytes, pagesize);
   if (size < bytes) {
     // Overflow
     errno = ENOMEM;
diff --git a/libc/malloc_debug/malloc_debug.h b/libc/memory/malloc_debug/malloc_debug.h
similarity index 100%
rename from libc/malloc_debug/malloc_debug.h
rename to libc/memory/malloc_debug/malloc_debug.h
diff --git a/libc/malloc_debug/tests/AndroidTest.xml b/libc/memory/malloc_debug/tests/AndroidTest.xml
similarity index 100%
rename from libc/malloc_debug/tests/AndroidTest.xml
rename to libc/memory/malloc_debug/tests/AndroidTest.xml
diff --git a/libc/malloc_debug/tests/backtrace_fake.cpp b/libc/memory/malloc_debug/tests/backtrace_fake.cpp
similarity index 100%
rename from libc/malloc_debug/tests/backtrace_fake.cpp
rename to libc/memory/malloc_debug/tests/backtrace_fake.cpp
diff --git a/libc/malloc_debug/tests/backtrace_fake.h b/libc/memory/malloc_debug/tests/backtrace_fake.h
similarity index 100%
rename from libc/malloc_debug/tests/backtrace_fake.h
rename to libc/memory/malloc_debug/tests/backtrace_fake.h
diff --git a/libc/malloc_debug/tests/libc_fake.cpp b/libc/memory/malloc_debug/tests/libc_fake.cpp
similarity index 100%
rename from libc/malloc_debug/tests/libc_fake.cpp
rename to libc/memory/malloc_debug/tests/libc_fake.cpp
diff --git a/libc/malloc_debug/tests/log_fake.cpp b/libc/memory/malloc_debug/tests/log_fake.cpp
similarity index 100%
rename from libc/malloc_debug/tests/log_fake.cpp
rename to libc/memory/malloc_debug/tests/log_fake.cpp
diff --git a/libc/malloc_debug/tests/log_fake.h b/libc/memory/malloc_debug/tests/log_fake.h
similarity index 100%
rename from libc/malloc_debug/tests/log_fake.h
rename to libc/memory/malloc_debug/tests/log_fake.h
diff --git a/libc/malloc_debug/tests/malloc_debug_config_tests.cpp b/libc/memory/malloc_debug/tests/malloc_debug_config_tests.cpp
similarity index 100%
rename from libc/malloc_debug/tests/malloc_debug_config_tests.cpp
rename to libc/memory/malloc_debug/tests/malloc_debug_config_tests.cpp
diff --git a/libc/malloc_debug/tests/malloc_debug_record_data_tests.cpp b/libc/memory/malloc_debug/tests/malloc_debug_record_data_tests.cpp
similarity index 100%
rename from libc/malloc_debug/tests/malloc_debug_record_data_tests.cpp
rename to libc/memory/malloc_debug/tests/malloc_debug_record_data_tests.cpp
diff --git a/libc/malloc_debug/tests/malloc_debug_system_tests.cpp b/libc/memory/malloc_debug/tests/malloc_debug_system_tests.cpp
similarity index 100%
rename from libc/malloc_debug/tests/malloc_debug_system_tests.cpp
rename to libc/memory/malloc_debug/tests/malloc_debug_system_tests.cpp
diff --git a/libc/malloc_debug/tests/malloc_debug_unit_tests.cpp b/libc/memory/malloc_debug/tests/malloc_debug_unit_tests.cpp
similarity index 92%
rename from libc/malloc_debug/tests/malloc_debug_unit_tests.cpp
rename to libc/memory/malloc_debug/tests/malloc_debug_unit_tests.cpp
index 79f946f..08a3a1f 100644
--- a/libc/malloc_debug/tests/malloc_debug_unit_tests.cpp
+++ b/libc/memory/malloc_debug/tests/malloc_debug_unit_tests.cpp
@@ -26,6 +26,7 @@
 #include <unistd.h>
 
 #include <algorithm>
+#include <bit>
 #include <memory>
 #include <string>
 #include <string_view>
@@ -99,7 +100,7 @@
     "6 malloc_debug *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***\n";
 
 static size_t get_tag_offset() {
-  return __BIONIC_ALIGN(sizeof(Header), MINIMUM_ALIGNMENT_BYTES);
+  return __builtin_align_up(sizeof(Header), MINIMUM_ALIGNMENT_BYTES);
 }
 
 static constexpr const char RECORD_ALLOCS_FILE[] = "/data/local/tmp/record_allocs";
@@ -185,26 +186,21 @@
   return diff;
 }
 
-static void VerifyRecords(std::vector<std::string>& expected, std::string& actual) {
-  ASSERT_TRUE(expected.size() != 0);
-  size_t offset = 0;
-  for (std::string& str : expected) {
-    ASSERT_STREQ(str.c_str(), actual.substr(offset, str.size()).c_str());
-    if (str.find("thread_done") != std::string::npos) {
-      offset = actual.find_first_of("\n", offset) + 1;
-      continue;
-    }
-    offset += str.size() + 1;
-    uint64_t st = strtoull(&actual[offset], nullptr, 10);
-    offset = actual.find_first_of(" ", offset) + 1;
-    uint64_t et = strtoull(&actual[offset], nullptr, 10);
-    ASSERT_GT(et, st);
-    offset = actual.find_first_of("\n", offset) + 1;
+static std::string PrintAllEntries(const std::vector<memory_trace::Entry>& expected,
+                                   const std::vector<memory_trace::Entry>& actual) {
+  std::string result = "\nAll Entries\n  Expected:\n";
+  for (const auto& entry : expected) {
+    result += "    " + memory_trace::CreateStringFromEntry(entry) + "\n";
   }
+  result += "  Actual:\n";
+  for (const auto& entry : actual) {
+    result += "    " + memory_trace::CreateStringFromEntry(entry) + "\n";
+  }
+  return result;
 }
 
 static void VerifyRecordEntries(const std::vector<memory_trace::Entry>& expected,
-                                std::string& actual) {
+                                std::string& actual, bool check_present_bytes = false) {
   ASSERT_TRUE(expected.size() != 0);
   // Convert the text to entries.
   std::vector<memory_trace::Entry> actual_entries;
@@ -217,28 +213,33 @@
     ASSERT_TRUE(memory_trace::FillInEntryFromString(line, entry, error)) << error;
     actual_entries.emplace_back(entry);
   }
-  auto expected_iter = expected.begin();
-  for (const auto& actual_entry : actual_entries) {
-    if (actual_entry.type == memory_trace::THREAD_DONE) {
-      // Skip thread done entries.
-      continue;
-    }
-    ASSERT_NE(expected_iter, expected.end())
-        << "Found extra entry " << memory_trace::CreateStringFromEntry(*expected_iter);
+  ASSERT_EQ(actual_entries.size(), expected.size()) << PrintAllEntries(expected, actual_entries);
+  for (size_t i = 0; i < actual_entries.size(); i++) {
     SCOPED_TRACE(testing::Message()
-                 << "\nExpected entry:\n  " << memory_trace::CreateStringFromEntry(*expected_iter)
-                 << "\nActual entry:\n  " << memory_trace::CreateStringFromEntry(actual_entry));
-    EXPECT_EQ(actual_entry.type, expected_iter->type);
-    EXPECT_EQ(actual_entry.ptr, expected_iter->ptr);
-    EXPECT_EQ(actual_entry.size, expected_iter->size);
-    EXPECT_EQ(actual_entry.u.old_ptr, expected_iter->u.old_ptr);
-    EXPECT_EQ(actual_entry.present_bytes, expected_iter->present_bytes);
+                 << "\nEntry " << i + 1 << "\nExpected entry:\n  "
+                 << memory_trace::CreateStringFromEntry(expected[i]) << "\nActual entry:\n  "
+                 << memory_trace::CreateStringFromEntry(actual_entries[i]) << "\n"
+                 << PrintAllEntries(expected, actual_entries));
+    if (expected[i].tid != 0) {
+      EXPECT_EQ(actual_entries[i].tid, expected[i].tid);
+    }
+    EXPECT_EQ(actual_entries[i].type, expected[i].type);
+    EXPECT_EQ(actual_entries[i].ptr, expected[i].ptr);
+    EXPECT_EQ(actual_entries[i].size, expected[i].size);
+    EXPECT_EQ(actual_entries[i].u.old_ptr, expected[i].u.old_ptr);
+    if (check_present_bytes) {
+      EXPECT_EQ(actual_entries[i].present_bytes, expected[i].present_bytes);
+    }
     // Verify the timestamps are non-zero.
-    EXPECT_NE(actual_entry.start_ns, 0U);
-    EXPECT_NE(actual_entry.end_ns, 0U);
-    ++expected_iter;
+    if (actual_entries[i].type == memory_trace::THREAD_DONE) {
+      // Thread done sets start to 0 since we don't know when the thread started.
+      EXPECT_EQ(actual_entries[i].start_ns, 0U);
+    } else {
+      // All other entries should have a non-zero start.
+      EXPECT_NE(actual_entries[i].start_ns, 0U);
+    }
+    EXPECT_NE(actual_entries[i].end_ns, 0U);
   }
-  EXPECT_TRUE(expected_iter == expected.end()) << "Not all expected entries found.";
 }
 
 void VerifyAllocCalls(bool all_options) {
@@ -517,16 +518,13 @@
   memset(pointer, 0xff, 100);
   debug_free(pointer);
 
-  // Loop through a bunch alignments.
+  // Loop through a bunch of alignments.
   for (size_t alignment = 1; alignment <= 256; alignment++) {
     pointer = reinterpret_cast<uint8_t*>(debug_memalign(alignment, 100));
     ASSERT_TRUE(pointer != nullptr);
     ASSERT_TRUE(memcmp(buffer.data(), &pointer[-buffer.size()], buffer.size()) == 0)
         << ShowDiffs(buffer.data(), &pointer[-buffer.size()], buffer.size());
-    size_t alignment_mask = alignment - 1;
-    if (!powerof2(alignment)) {
-      alignment_mask = BIONIC_ROUND_UP_POWER_OF_2(alignment) - 1;
-    }
+    size_t alignment_mask = std::bit_ceil(alignment) - 1;
     ASSERT_EQ(0U, reinterpret_cast<uintptr_t>(pointer) & alignment_mask);
     memset(pointer, 0xff, 100);
     debug_free(pointer);
@@ -614,17 +612,14 @@
   memset(pointer, 0xff, 100);
   debug_free(pointer);
 
-  // Loop through a bunch alignments.
+  // Loop through a bunch of alignments.
   for (size_t alignment = 1; alignment <= 256; alignment++) {
     pointer = reinterpret_cast<uint8_t*>(debug_memalign(alignment, 100));
     ASSERT_TRUE(pointer != nullptr);
     ASSERT_EQ(100U, debug_malloc_usable_size(pointer));
     ASSERT_TRUE(memcmp(buffer.data(), &pointer[100], buffer.size()) == 0)
         << ShowDiffs(buffer.data(), &pointer[100], buffer.size());
-    size_t alignment_mask = alignment - 1;
-    if (!powerof2(alignment)) {
-      alignment_mask = BIONIC_ROUND_UP_POWER_OF_2(alignment) - 1;
-    }
+    size_t alignment_mask = std::bit_ceil(alignment) - 1;
     ASSERT_EQ(0U, reinterpret_cast<uintptr_t>(pointer) & alignment_mask)
         << "Failed at alignment " << alignment << " mask " << alignment_mask;
     memset(pointer, 0xff, 100);
@@ -2242,61 +2237,104 @@
 #endif
 
 void VerifyRecordAllocs(const std::string& record_filename) {
-  std::vector<std::string> expected;
+  std::vector<memory_trace::Entry> expected;
 
   void* pointer = debug_malloc(10);
   ASSERT_TRUE(pointer != nullptr);
-  expected.push_back(android::base::StringPrintf("%d: malloc %p 10", getpid(), pointer));
+  expected.push_back(memory_trace::Entry{
+      .type = memory_trace::MALLOC, .ptr = reinterpret_cast<uint64_t>(pointer), .size = 10});
+
   debug_free(pointer);
-  expected.push_back(android::base::StringPrintf("%d: free %p", getpid(), pointer));
+  expected.push_back(
+      memory_trace::Entry{.type = memory_trace::FREE, .ptr = reinterpret_cast<uint64_t>(pointer)});
 
   pointer = debug_calloc(20, 1);
   ASSERT_TRUE(pointer != nullptr);
-  expected.push_back(android::base::StringPrintf("%d: calloc %p 20 1", getpid(), pointer));
+  expected.push_back(memory_trace::Entry{.type = memory_trace::CALLOC,
+                                         .ptr = reinterpret_cast<uint64_t>(pointer),
+                                         .size = 1,
+                                         .u.n_elements = 20});
+
   debug_free(pointer);
-  expected.push_back(android::base::StringPrintf("%d: free %p", getpid(), pointer));
+  expected.push_back(
+      memory_trace::Entry{.type = memory_trace::FREE, .ptr = reinterpret_cast<uint64_t>(pointer)});
 
   pointer = debug_realloc(nullptr, 30);
   ASSERT_TRUE(pointer != nullptr);
-  expected.push_back(android::base::StringPrintf("%d: realloc %p 0x0 30", getpid(), pointer));
+  expected.push_back(memory_trace::Entry{.type = memory_trace::REALLOC,
+                                         .ptr = reinterpret_cast<uint64_t>(pointer),
+                                         .size = 30,
+                                         .u.old_ptr = 0});
+
   void* old_pointer = pointer;
   pointer = debug_realloc(pointer, 2048);
   ASSERT_TRUE(pointer != nullptr);
-  expected.push_back(
-      android::base::StringPrintf("%d: realloc %p %p 2048", getpid(), pointer, old_pointer));
+  expected.push_back(memory_trace::Entry{.type = memory_trace::REALLOC,
+                                         .ptr = reinterpret_cast<uint64_t>(pointer),
+                                         .size = 2048,
+                                         .u.old_ptr = reinterpret_cast<uint64_t>(old_pointer)});
+
   debug_realloc(pointer, 0);
-  expected.push_back(android::base::StringPrintf("%d: realloc 0x0 %p 0", getpid(), pointer));
+  expected.push_back(memory_trace::Entry{.type = memory_trace::REALLOC,
+                                         .ptr = 0,
+                                         .size = 0,
+                                         .u.old_ptr = reinterpret_cast<uint64_t>(pointer)});
 
   pointer = debug_memalign(16, 40);
   ASSERT_TRUE(pointer != nullptr);
-  expected.push_back(android::base::StringPrintf("%d: memalign %p 16 40", getpid(), pointer));
+  expected.push_back(memory_trace::Entry{.type = memory_trace::MEMALIGN,
+                                         .ptr = reinterpret_cast<uint64_t>(pointer),
+                                         .size = 40,
+                                         .u.align = 16});
+
   debug_free(pointer);
-  expected.push_back(android::base::StringPrintf("%d: free %p", getpid(), pointer));
+  expected.push_back(
+      memory_trace::Entry{.type = memory_trace::FREE, .ptr = reinterpret_cast<uint64_t>(pointer)});
 
   pointer = debug_aligned_alloc(32, 64);
   ASSERT_TRUE(pointer != nullptr);
-  expected.push_back(android::base::StringPrintf("%d: memalign %p 32 64", getpid(), pointer));
+  expected.push_back(memory_trace::Entry{.type = memory_trace::MEMALIGN,
+                                         .ptr = reinterpret_cast<uint64_t>(pointer),
+                                         .size = 64,
+                                         .u.align = 32});
+
   debug_free(pointer);
-  expected.push_back(android::base::StringPrintf("%d: free %p", getpid(), pointer));
+  expected.push_back(
+      memory_trace::Entry{.type = memory_trace::FREE, .ptr = reinterpret_cast<uint64_t>(pointer)});
 
   ASSERT_EQ(0, debug_posix_memalign(&pointer, 32, 50));
   ASSERT_TRUE(pointer != nullptr);
-  expected.push_back(android::base::StringPrintf("%d: memalign %p 32 50", getpid(), pointer));
+  expected.push_back(memory_trace::Entry{.type = memory_trace::MEMALIGN,
+                                         .ptr = reinterpret_cast<uint64_t>(pointer),
+                                         .size = 50,
+                                         .u.align = 32});
+
   debug_free(pointer);
-  expected.push_back(android::base::StringPrintf("%d: free %p", getpid(), pointer));
+  expected.push_back(
+      memory_trace::Entry{.type = memory_trace::FREE, .ptr = reinterpret_cast<uint64_t>(pointer)});
 
 #if defined(HAVE_DEPRECATED_MALLOC_FUNCS)
   pointer = debug_pvalloc(60);
   ASSERT_TRUE(pointer != nullptr);
-  expected.push_back(android::base::StringPrintf("%d: memalign %p 4096 4096", getpid(), pointer));
+  expected.push_back(memory_trace::Entry{.type = memory_trace::MEMALIGN,
+                                         .ptr = reinterpret_cast<uint64_t>(pointer),
+                                         .size = 4096,
+                                         .u.align = 4096});
+
   debug_free(pointer);
-  expected.push_back(android::base::StringPrintf("%d: free %p", getpid(), pointer));
+  expected.push_back(
+      memory_trace::Entry{.type = memory_trace::FREE, .ptr = reinterpret_cast<uint64_t>(pointer)});
 
   pointer = debug_valloc(70);
   ASSERT_TRUE(pointer != nullptr);
-  expected.push_back(android::base::StringPrintf("%d: memalign %p 4096 70", getpid(), pointer));
+  expected.push_back(memory_trace::Entry{.type = memory_trace::MEMALIGN,
+                                         .ptr = reinterpret_cast<uint64_t>(pointer),
+                                         .size = 70,
+                                         .u.align = 4096});
+
   debug_free(pointer);
-  expected.push_back(android::base::StringPrintf("%d: free %p", getpid(), pointer));
+  expected.push_back(
+      memory_trace::Entry{.type = memory_trace::FREE, .ptr = reinterpret_cast<uint64_t>(pointer)});
 #endif
 
   // Dump all of the data accumulated so far.
@@ -2305,8 +2343,7 @@
   // Read all of the contents.
   std::string actual;
   ASSERT_TRUE(android::base::ReadFileToString(record_filename, &actual));
-
-  VerifyRecords(expected, actual);
+  VerifyRecordEntries(expected, actual);
 
   ASSERT_STREQ("", getFakeLogBuf().c_str());
   ASSERT_STREQ("", getFakeLogPrint().c_str());
@@ -2327,23 +2364,32 @@
 TEST_F(MallocDebugTest, record_allocs_max) {
   InitRecordAllocs("record_allocs=5");
 
-  std::vector<std::string> expected;
+  std::vector<memory_trace::Entry> expected;
 
   void* pointer = debug_malloc(10);
   ASSERT_TRUE(pointer != nullptr);
-  expected.push_back(android::base::StringPrintf("%d: malloc %p 10", getpid(), pointer));
+  expected.push_back(memory_trace::Entry{
+      .type = memory_trace::MALLOC, .ptr = reinterpret_cast<uint64_t>(pointer), .size = 10});
+
   debug_free(pointer);
-  expected.push_back(android::base::StringPrintf("%d: free %p", getpid(), pointer));
+  expected.push_back(
+      memory_trace::Entry{.type = memory_trace::FREE, .ptr = reinterpret_cast<uint64_t>(pointer)});
 
   pointer = debug_malloc(20);
   ASSERT_TRUE(pointer != nullptr);
-  expected.push_back(android::base::StringPrintf("%d: malloc %p 20", getpid(), pointer));
+  expected.push_back(memory_trace::Entry{
+      .type = memory_trace::MALLOC, .ptr = reinterpret_cast<uint64_t>(pointer), .size = 20});
+
   debug_free(pointer);
-  expected.push_back(android::base::StringPrintf("%d: free %p", getpid(), pointer));
+  expected.push_back(
+      memory_trace::Entry{.type = memory_trace::FREE, .ptr = reinterpret_cast<uint64_t>(pointer)});
 
   pointer = debug_malloc(1024);
   ASSERT_TRUE(pointer != nullptr);
-  expected.push_back(android::base::StringPrintf("%d: malloc %p 1024", getpid(), pointer));
+  expected.push_back(memory_trace::Entry{
+      .type = memory_trace::MALLOC, .ptr = reinterpret_cast<uint64_t>(pointer), .size = 1024});
+
+  // This entry will not be written since we hit the maximum number we can store.
   debug_free(pointer);
 
   // Dump all of the data accumulated so far.
@@ -2352,8 +2398,7 @@
   // Read all of the contents.
   std::string actual;
   ASSERT_TRUE(android::base::ReadFileToString(record_filename, &actual));
-
-  VerifyRecords(expected, actual);
+  VerifyRecordEntries(expected, actual);
 
   ASSERT_STREQ("", getFakeLogBuf().c_str());
   ASSERT_STREQ(
@@ -2374,10 +2419,14 @@
   });
   thread.join();
 
-  std::vector<std::string> expected;
-  expected.push_back(android::base::StringPrintf("%d: malloc %p 100", tid, pointer));
-  expected.push_back(android::base::StringPrintf("%d: free %p", tid, pointer));
-  expected.push_back(android::base::StringPrintf("%d: thread_done 0x0", tid));
+  std::vector<memory_trace::Entry> expected;
+  expected.push_back(memory_trace::Entry{.tid = tid,
+                                         .type = memory_trace::MALLOC,
+                                         .ptr = reinterpret_cast<uint64_t>(pointer),
+                                         .size = 100});
+  expected.push_back(memory_trace::Entry{
+      .tid = tid, .type = memory_trace::FREE, .ptr = reinterpret_cast<uint64_t>(pointer)});
+  expected.push_back(memory_trace::Entry{.tid = tid, .type = memory_trace::THREAD_DONE});
 
   // Dump all of the data accumulated so far.
   ASSERT_TRUE(kill(getpid(), SIGRTMAX - 18) == 0);
@@ -2385,8 +2434,7 @@
   // Read all of the contents.
   std::string actual;
   ASSERT_TRUE(android::base::ReadFileToString(record_filename, &actual));
-
-  VerifyRecords(expected, actual);
+  VerifyRecordEntries(expected, actual);
 
   ASSERT_STREQ("", getFakeLogBuf().c_str());
   ASSERT_STREQ("", getFakeLogPrint().c_str());
@@ -2401,13 +2449,15 @@
 
   ASSERT_EQ(0, symlink("/data/local/tmp/does_not_exist", record_filename.c_str()));
 
-  std::vector<std::string> expected;
+  std::vector<memory_trace::Entry> expected;
 
   void* pointer = debug_malloc(10);
   ASSERT_TRUE(pointer != nullptr);
-  expected.push_back(android::base::StringPrintf("%d: malloc %p 10", getpid(), pointer));
+  expected.push_back(memory_trace::Entry{
+      .type = memory_trace::MALLOC, .ptr = reinterpret_cast<uint64_t>(pointer), .size = 10});
   debug_free(pointer);
-  expected.push_back(android::base::StringPrintf("%d: free %p", getpid(), pointer));
+  expected.push_back(
+      memory_trace::Entry{.type = memory_trace::FREE, .ptr = reinterpret_cast<uint64_t>(pointer)});
 
   // Dump all of the data accumulated so far.
   ASSERT_TRUE(kill(getpid(), SIGRTMAX - 18) == 0);
@@ -2423,8 +2473,7 @@
   ASSERT_TRUE(kill(getpid(), SIGRTMAX - 18) == 0);
 
   ASSERT_TRUE(android::base::ReadFileToString(record_filename, &actual));
-
-  VerifyRecords(expected, actual);
+  VerifyRecordEntries(expected, actual);
 
   ASSERT_STREQ("", getFakeLogBuf().c_str());
   std::string expected_log = android::base::StringPrintf(
@@ -2448,13 +2497,16 @@
 TEST_F(MallocDebugTest, record_allocs_write_entries_does_not_allocate) {
   InitRecordAllocs("record_allocs=5");
 
-  std::vector<std::string> expected;
+  std::vector<memory_trace::Entry> expected;
 
   void* pointer = debug_malloc(10);
   ASSERT_TRUE(pointer != nullptr);
-  expected.push_back(android::base::StringPrintf("%d: malloc %p 10", getpid(), pointer));
+  expected.push_back(memory_trace::Entry{
+      .type = memory_trace::MALLOC, .ptr = reinterpret_cast<uint64_t>(pointer), .size = 10});
+
   debug_free(pointer);
-  expected.push_back(android::base::StringPrintf("%d: free %p", getpid(), pointer));
+  expected.push_back(
+      memory_trace::Entry{.type = memory_trace::FREE, .ptr = reinterpret_cast<uint64_t>(pointer)});
 
   malloc_disable();
   kill(getpid(), SIGRTMAX - 18);
@@ -2462,8 +2514,7 @@
 
   std::string actual;
   ASSERT_TRUE(android::base::ReadFileToString(record_filename, &actual));
-
-  VerifyRecords(expected, actual);
+  VerifyRecordEntries(expected, actual);
 
   ASSERT_STREQ("", getFakeLogBuf().c_str());
   ASSERT_STREQ("", getFakeLogPrint().c_str());
@@ -2476,13 +2527,20 @@
   // Modify the variable so the file is deleted at the end of the test.
   record_filename += '.' + std::to_string(getpid());
 
-  std::vector<std::string> expected;
+  std::vector<memory_trace::Entry> expected;
+
   void* ptr = debug_malloc(100);
-  expected.push_back(android::base::StringPrintf("%d: malloc %p 100", getpid(), ptr));
+  ASSERT_TRUE(ptr != nullptr);
+  expected.push_back(memory_trace::Entry{
+      .type = memory_trace::MALLOC, .ptr = reinterpret_cast<uint64_t>(ptr), .size = 100});
   ptr = debug_malloc(200);
-  expected.push_back(android::base::StringPrintf("%d: malloc %p 200", getpid(), ptr));
+  ASSERT_TRUE(ptr != nullptr);
+  expected.push_back(memory_trace::Entry{
+      .type = memory_trace::MALLOC, .ptr = reinterpret_cast<uint64_t>(ptr), .size = 200});
   ptr = debug_malloc(400);
-  expected.push_back(android::base::StringPrintf("%d: malloc %p 400", getpid(), ptr));
+  ASSERT_TRUE(ptr != nullptr);
+  expected.push_back(memory_trace::Entry{
+      .type = memory_trace::MALLOC, .ptr = reinterpret_cast<uint64_t>(ptr), .size = 400});
 
   // Call the exit function manually.
   debug_finalize();
@@ -2490,7 +2548,7 @@
   // Read all of the contents.
   std::string actual;
   ASSERT_TRUE(android::base::ReadFileToString(record_filename, &actual));
-  VerifyRecords(expected, actual);
+  VerifyRecordEntries(expected, actual);
 
   ASSERT_STREQ("", getFakeLogBuf().c_str());
   ASSERT_STREQ("", getFakeLogPrint().c_str());
@@ -2509,9 +2567,9 @@
       .type = memory_trace::MALLOC, .ptr = reinterpret_cast<uint64_t>(ptr), .size = 100});
 
   // Make the entire allocation present.
-  memset(ptr, 1, 100);
-
   int64_t real_size = debug_malloc_usable_size(ptr);
+  memset(ptr, 1, real_size);
+
   debug_free(ptr);
   expected.push_back(memory_trace::Entry{.type = memory_trace::FREE,
                                          .ptr = reinterpret_cast<uint64_t>(ptr),
@@ -2521,8 +2579,8 @@
   expected.push_back(memory_trace::Entry{
       .type = memory_trace::MALLOC, .ptr = reinterpret_cast<uint64_t>(ptr), .size = 4096});
 
-  memset(ptr, 1, 4096);
   real_size = debug_malloc_usable_size(ptr);
+  memset(ptr, 1, real_size);
   void* new_ptr = debug_realloc(ptr, 8192);
   expected.push_back(memory_trace::Entry{.type = memory_trace::REALLOC,
                                          .ptr = reinterpret_cast<uint64_t>(new_ptr),
@@ -2530,8 +2588,8 @@
                                          .u.old_ptr = reinterpret_cast<uint64_t>(ptr),
                                          .present_bytes = real_size});
 
-  memset(new_ptr, 1, 8192);
   real_size = debug_malloc_usable_size(new_ptr);
+  memset(new_ptr, 1, real_size);
   debug_free(new_ptr);
   expected.push_back(memory_trace::Entry{.type = memory_trace::FREE,
                                          .ptr = reinterpret_cast<uint64_t>(new_ptr),
@@ -2540,10 +2598,10 @@
   ptr = debug_malloc(4096);
   expected.push_back(memory_trace::Entry{
       .type = memory_trace::MALLOC, .ptr = reinterpret_cast<uint64_t>(ptr), .size = 4096});
-  memset(ptr, 1, 4096);
+  real_size = debug_malloc_usable_size(ptr);
+  memset(ptr, 1, real_size);
 
   // Verify a free realloc does update the present bytes.
-  real_size = debug_malloc_usable_size(ptr);
   EXPECT_TRUE(debug_realloc(ptr, 0) == nullptr);
   expected.push_back(memory_trace::Entry{.type = memory_trace::REALLOC,
                                          .ptr = 0,
@@ -2556,7 +2614,7 @@
   // Read all of the contents.
   std::string actual;
   ASSERT_TRUE(android::base::ReadFileToString(record_filename, &actual));
-  VerifyRecordEntries(expected, actual);
+  VerifyRecordEntries(expected, actual, /*check_present_bytes*/ true);
 
   ASSERT_STREQ("", getFakeLogBuf().c_str());
   ASSERT_STREQ("", getFakeLogPrint().c_str());
@@ -2598,7 +2656,7 @@
   // Read all of the contents.
   std::string actual;
   ASSERT_TRUE(android::base::ReadFileToString(record_filename, &actual));
-  VerifyRecordEntries(expected, actual);
+  VerifyRecordEntries(expected, actual, /*check_present_bytes*/ true);
 
   ASSERT_STREQ("", getFakeLogBuf().c_str());
   ASSERT_STREQ("", getFakeLogPrint().c_str());
@@ -2982,7 +3040,7 @@
   debug_free(pointer);
 
   ASSERT_STREQ("", getFakeLogBuf().c_str());
-  if (!running_with_hwasan()) {
+  if (!android::base::running_with_hwasan()) {
     // Do an exact match because the mallopt should not fail in normal operation.
     ASSERT_STREQ("4 malloc_debug Logging allocator stats...\n", getFakeLogPrint().c_str());
   } else {
@@ -3001,7 +3059,7 @@
   debug_finalize();
 
   ASSERT_STREQ("", getFakeLogBuf().c_str());
-  if (!running_with_hwasan()) {
+  if (!android::base::running_with_hwasan()) {
     // Do an exact match because the mallopt should not fail in normal operation.
     ASSERT_STREQ("4 malloc_debug Logging allocator stats...\n", getFakeLogPrint().c_str());
   } else {
diff --git a/libc/malloc_debug/tools/gen_malloc.pl b/libc/memory/malloc_debug/tools/gen_malloc.pl
similarity index 100%
rename from libc/malloc_debug/tools/gen_malloc.pl
rename to libc/memory/malloc_debug/tools/gen_malloc.pl
diff --git a/libc/malloc_hooks/Android.bp b/libc/memory/malloc_hooks/Android.bp
similarity index 95%
rename from libc/malloc_hooks/Android.bp
rename to libc/memory/malloc_hooks/Android.bp
index 06e91c6..c7e45a6 100644
--- a/libc/malloc_hooks/Android.bp
+++ b/libc/memory/malloc_hooks/Android.bp
@@ -80,7 +80,6 @@
     cflags: [
         "-Wall",
         "-Werror",
-        "-O1", // FIXME: http://b/169206016 - issues with aligned_alloc and -O2
     ],
     test_suites: ["general-tests"],
 }
diff --git a/libc/malloc_hooks/README.md b/libc/memory/malloc_hooks/README.md
similarity index 100%
rename from libc/malloc_hooks/README.md
rename to libc/memory/malloc_hooks/README.md
diff --git a/libc/malloc_hooks/exported32.map b/libc/memory/malloc_hooks/exported32.map
similarity index 100%
rename from libc/malloc_hooks/exported32.map
rename to libc/memory/malloc_hooks/exported32.map
diff --git a/libc/malloc_hooks/exported64.map b/libc/memory/malloc_hooks/exported64.map
similarity index 100%
rename from libc/malloc_hooks/exported64.map
rename to libc/memory/malloc_hooks/exported64.map
diff --git a/libc/malloc_hooks/malloc_hooks.cpp b/libc/memory/malloc_hooks/malloc_hooks.cpp
similarity index 95%
rename from libc/malloc_hooks/malloc_hooks.cpp
rename to libc/memory/malloc_hooks/malloc_hooks.cpp
index 1ba8696..e039065 100644
--- a/libc/malloc_hooks/malloc_hooks.cpp
+++ b/libc/memory/malloc_hooks/malloc_hooks.cpp
@@ -209,14 +209,17 @@
   return g_dispatch->posix_memalign(memptr, alignment, size);
 }
 
-int hooks_malloc_iterate(uintptr_t, size_t, void (*)(uintptr_t, size_t, void*), void*) {
-  return 0;
+int hooks_malloc_iterate(uintptr_t base, size_t size,
+                         void (*callback)(uintptr_t base, size_t size, void* arg), void* arg) {
+  return g_dispatch->malloc_iterate(base, size, callback, arg);
 }
 
 void hooks_malloc_disable() {
+  g_dispatch->malloc_disable();
 }
 
 void hooks_malloc_enable() {
+  g_dispatch->malloc_enable();
 }
 
 ssize_t hooks_malloc_backtrace(void*, uintptr_t*, size_t) {
@@ -230,7 +233,7 @@
 #if defined(HAVE_DEPRECATED_MALLOC_FUNCS)
 void* hooks_pvalloc(size_t bytes) {
   size_t pagesize = getpagesize();
-  size_t size = __BIONIC_ALIGN(bytes, pagesize);
+  size_t size = __builtin_align_up(bytes, pagesize);
   if (size < bytes) {
     // Overflow
     errno = ENOMEM;
diff --git a/libc/malloc_hooks/tests/malloc_hooks_tests.cpp b/libc/memory/malloc_hooks/tests/malloc_hooks_tests.cpp
similarity index 97%
rename from libc/malloc_hooks/tests/malloc_hooks_tests.cpp
rename to libc/memory/malloc_hooks/tests/malloc_hooks_tests.cpp
index 3ff2537..582872b 100644
--- a/libc/malloc_hooks/tests/malloc_hooks_tests.cpp
+++ b/libc/memory/malloc_hooks/tests/malloc_hooks_tests.cpp
@@ -26,6 +26,13 @@
  * SUCH DAMAGE.
  */
 
+// (b/291762537): This code uses malloc_usable_size(), and thus can't be
+// built with _FORTIFY_SOURCE>=3.
+#if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE >= 3
+#undef _FORTIFY_SOURCE
+#define _FORTIFY_SOURCE 2
+#endif
+
 #include <fcntl.h>
 #include <malloc.h>
 #include <stdlib.h>
@@ -210,8 +217,8 @@
 
   ASSERT_TRUE(android_mallopt(M_FREE_MALLOC_LEAK_INFO, &leak_info, sizeof(leak_info)));
 
-  malloc_enable();
   malloc_disable();
+  malloc_enable();
 
   EXPECT_EQ(0, malloc_iterate(0, 0, nullptr, nullptr));
 
diff --git a/libc/memory/trace_analysis/Analysis.h b/libc/memory/trace_analysis/Analysis.h
new file mode 100644
index 0000000..f24cf60
--- /dev/null
+++ b/libc/memory/trace_analysis/Analysis.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2025 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <ostream>
+#include <string>
+
+#include <memory_trace/TraceInfo.h>
+
+class Analysis {
+ public:
+  Analysis() = default;
+  virtual ~Analysis() = default;
+
+  virtual const std::string Name() = 0;
+
+  virtual bool Gather(memory_trace::TraceInfo& info) = 0;
+
+  virtual bool StreamResult(std::ostream& os, const std::string& prefix) = 0;
+};
diff --git a/libc/memory/trace_analysis/Android.bp b/libc/memory/trace_analysis/Android.bp
new file mode 100644
index 0000000..f562413
--- /dev/null
+++ b/libc/memory/trace_analysis/Android.bp
@@ -0,0 +1,78 @@
+//
+// Copyright (C) 2025 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+package {
+    default_team: "trendy_team_native_tools_libraries",
+    default_applicable_licenses: ["bionic_libc_memory_trace_analysis_license"],
+}
+
+license {
+    name: "bionic_libc_memory_trace_analysis_license",
+    visibility: [":__subpackages__"],
+    license_kinds: [
+        "SPDX-license-identifier-Apache-2.0",
+    ],
+    license_text: [
+        "NOTICE",
+    ],
+}
+
+cc_defaults {
+    name: "memory_trace_analysis_defaults",
+    host_supported: true,
+
+    cflags: [
+        "-Wall",
+        "-Wextra",
+        "-Werror",
+    ],
+
+    srcs: [
+        "OpGenAnalysis.cpp",
+        "OpOverlapAnalysis.cpp",
+    ],
+
+    static_libs: [
+        "libmemory_trace",
+    ],
+    shared_libs: [
+        "libbase",
+        "liblog",
+        "libziparchive",
+    ],
+}
+
+cc_binary_host {
+    name: "memory_trace_analysis",
+    defaults: ["memory_trace_analysis_defaults"],
+
+    srcs: [
+        "main.cpp",
+    ],
+}
+
+cc_test_host {
+    name: "memory_trace_analysis_unit_tests",
+    defaults: ["memory_trace_analysis_defaults"],
+    isolated: true,
+
+    srcs: [
+        "tests/AnalysisTest.cpp",
+    ],
+    local_include_dirs: [
+        ".",
+    ],
+}
diff --git a/libc/memory/trace_analysis/NOTICE b/libc/memory/trace_analysis/NOTICE
new file mode 100644
index 0000000..8530865
--- /dev/null
+++ b/libc/memory/trace_analysis/NOTICE
@@ -0,0 +1,190 @@
+
+   Copyright (c) 2015, The Android Open Source Project
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
diff --git a/libc/memory/trace_analysis/OpGenAnalysis.cpp b/libc/memory/trace_analysis/OpGenAnalysis.cpp
new file mode 100644
index 0000000..c3f9dc4
--- /dev/null
+++ b/libc/memory/trace_analysis/OpGenAnalysis.cpp
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2025 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "OpGenAnalysis.h"
+
+#include <algorithm>
+#include <ostream>
+#include <string>
+#include <unordered_map>
+#include <utility>
+
+#include <memory_trace/MemoryTrace.h>
+#include <memory_trace/TraceInfo.h>
+
+bool OpAverageAnalysis::Gather(memory_trace::TraceInfo& info) {
+  memory_trace::Entry* entries = info.entries();
+  for (size_t i = 0; i < info.num_entries(); i++) {
+    auto& iter = stats_[entries[i].type];
+    iter.first += entries[i].end_ns - entries[i].start_ns;
+    ++iter.second;
+  }
+  return true;
+}
+
+bool OpAverageAnalysis::StreamResult(std::ostream& os, const std::string& prefix) {
+  constexpr memory_trace::TypeEnum outputOrder[] = {memory_trace::MALLOC, memory_trace::CALLOC,
+                                                    memory_trace::MEMALIGN, memory_trace::REALLOC,
+                                                    memory_trace::FREE};
+  for (memory_trace::TypeEnum type : outputOrder) {
+    auto [total_time, total_count] = stats_[type];
+    os << prefix << memory_trace::TypeToName(type) << ": avg exec time = ";
+    if (total_count == 0) {
+      os << "0.0 ns" << std::endl;
+    } else {
+      os << total_time / total_count;
+      uint64_t fraction = total_time % total_count;
+      os << "." << (fraction * 1000) / total_count << " ns" << std::endl;
+    }
+  }
+
+  return true;
+}
+
+bool OpMinMaxAnalysis::Gather(memory_trace::TraceInfo& info) {
+  memory_trace::Entry* entries = info.entries();
+  for (size_t i = 0; i < info.num_entries(); i++) {
+    auto& iter = stats_[entries[i].type];
+    uint64_t period = entries[i].end_ns - entries[i].start_ns;
+    iter.first = iter.first == 0 ? period : std::min(iter.first, period);
+    iter.second = std::max(iter.second, period);
+  }
+
+  return true;
+}
+
+bool OpMinMaxAnalysis::StreamResult(std::ostream& os, const std::string& prefix) {
+  constexpr memory_trace::TypeEnum outputOrder[] = {memory_trace::MALLOC, memory_trace::CALLOC,
+                                                    memory_trace::MEMALIGN, memory_trace::REALLOC,
+                                                    memory_trace::FREE};
+  for (memory_trace::TypeEnum type : outputOrder) {
+    auto [min_exec, max_exec] = stats_[type];
+    os << prefix << memory_trace::TypeToName(type) << ": min exec time = " << min_exec
+       << " ns, max exec time = " << max_exec << " ns" << std::endl;
+  }
+
+  return true;
+}
diff --git a/libc/memory/trace_analysis/OpGenAnalysis.h b/libc/memory/trace_analysis/OpGenAnalysis.h
new file mode 100644
index 0000000..ebb5b50
--- /dev/null
+++ b/libc/memory/trace_analysis/OpGenAnalysis.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2025 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <ostream>
+#include <string>
+#include <unordered_map>
+#include <utility>
+
+#include <memory_trace/MemoryTrace.h>
+#include <memory_trace/TraceInfo.h>
+
+#include "Analysis.h"
+
+// Return the average execution time of each allocation operation.
+class OpAverageAnalysis : public Analysis {
+ public:
+  OpAverageAnalysis() = default;
+  virtual ~OpAverageAnalysis() = default;
+
+  const std::string Name() override final { return "OpAverageAnalysis"; }
+
+  bool Gather(memory_trace::TraceInfo& info) override final;
+
+  bool StreamResult(std::ostream& os, const std::string& prefix) override final;
+
+ private:
+  std::unordered_map<memory_trace::TypeEnum, std::pair<uint64_t, uint64_t>> stats_;
+};
+
+// Return the min/max execution time of each allocation operation.
+class OpMinMaxAnalysis : public Analysis {
+ public:
+  OpMinMaxAnalysis() = default;
+  virtual ~OpMinMaxAnalysis() = default;
+
+  const std::string Name() override final { return "OpMinMaxAnalysis"; }
+
+  bool Gather(memory_trace::TraceInfo& info) override final;
+
+  bool StreamResult(std::ostream& os, const std::string& prefix) override final;
+
+ private:
+  std::unordered_map<memory_trace::TypeEnum, std::pair<uint64_t, uint64_t>> stats_;
+};
diff --git a/libc/memory/trace_analysis/OpOverlapAnalysis.cpp b/libc/memory/trace_analysis/OpOverlapAnalysis.cpp
new file mode 100644
index 0000000..c9c19b1
--- /dev/null
+++ b/libc/memory/trace_analysis/OpOverlapAnalysis.cpp
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2025 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "OpOverlapAnalysis.h"
+
+#include <algorithm>
+#include <iostream>
+#include <string>
+#include <tuple>
+
+#include <memory_trace/MemoryTrace.h>
+#include <memory_trace/TraceInfo.h>
+
+bool OpOverlapAnalysis::Gather(memory_trace::TraceInfo& info) {
+  if (info.num_entries() <= 1) return true;
+
+  memory_trace::Entry* entries = info.entries();
+
+  auto [cur_start_ns, cur_end_ns] = std::tie(entries[0].start_ns, entries[0].end_ns);
+  total_overlapping_ = 0;
+  for (size_t i = 1; i < info.num_entries(); ++i) {
+    auto [start_ns, end_ns] = std::tie(entries[i].start_ns, entries[i].end_ns);
+    if (end_ns <= cur_start_ns) continue;
+
+    if (start_ns >= cur_end_ns) {
+      std::tie(cur_start_ns, cur_end_ns) = std::tie(start_ns, end_ns);
+    } else if (end_ns < cur_end_ns) {
+      total_overlapping_ += end_ns - std::max(start_ns, cur_start_ns);
+      cur_start_ns = std::min(start_ns, cur_start_ns);
+    } else {
+      total_overlapping_ += cur_end_ns - std::max(start_ns, cur_start_ns);
+      cur_end_ns = end_ns;
+    }
+  }
+
+  return true;
+}
+
+bool OpOverlapAnalysis::StreamResult(std::ostream& os, const std::string& prefix) {
+  os << prefix << "Overlap of all operations is " << total_overlapping_ << " ns" << std::endl;
+  return true;
+}
diff --git a/libc/memory/trace_analysis/OpOverlapAnalysis.h b/libc/memory/trace_analysis/OpOverlapAnalysis.h
new file mode 100644
index 0000000..8becc83
--- /dev/null
+++ b/libc/memory/trace_analysis/OpOverlapAnalysis.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2025 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <ostream>
+#include <string>
+
+#include <memory_trace/TraceInfo.h>
+
+#include "Analysis.h"
+
+// Accumulate the overlap in time intervals of a trace with at least two allocation
+// entries.
+// For example,
+//
+//   1234: malloc 0x0 32 1 100
+//   5678: malloc 0x0 32 50 120
+//
+// The interval [50, 100] contains two malloc calls that overlap by 51 nanoseconds.
+class OpOverlapAnalysis : public Analysis {
+ public:
+  OpOverlapAnalysis() = default;
+  virtual ~OpOverlapAnalysis() = default;
+
+  const std::string Name() override final { return "OpOverlapAnalysis"; }
+
+  bool Gather(memory_trace::TraceInfo& info) override final;
+
+  bool StreamResult(std::ostream& os, const std::string& prefix) override final;
+
+ private:
+  uint64_t total_overlapping_;
+};
diff --git a/libc/memory/trace_analysis/main.cpp b/libc/memory/trace_analysis/main.cpp
new file mode 100644
index 0000000..ce938eb
--- /dev/null
+++ b/libc/memory/trace_analysis/main.cpp
@@ -0,0 +1,189 @@
+/*
+ * Copyright (C) 2025 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <errno.h>
+#include <string.h>
+#include <sys/stat.h>
+
+#include <iostream>
+#include <memory>
+#include <string_view>
+
+#include <memory_trace/TraceInfo.h>
+
+#include "OpGenAnalysis.h"
+#include "OpOverlapAnalysis.h"
+
+namespace {
+
+class OptionBase;
+
+class OptionRegistry {
+ public:
+  static OptionRegistry& get() {
+    static OptionRegistry registry;
+    return registry;
+  }
+
+  void RegisterOption(OptionBase* opt) { options_.push_back(opt); }
+
+  auto begin() { return options_.begin(); }
+  auto end() { return options_.end(); }
+
+  void Stream(std::ostream& os, std::string_view indent = "\t");
+
+ private:
+  OptionRegistry() {}
+
+  std::vector<OptionBase*> options_;
+};
+
+class OptionBase {
+ public:
+  template <typename... Analyses>
+  OptionBase(std::string_view name, std::string_view desc) : name_(name), desc_(desc) {
+    OptionRegistry::get().RegisterOption(this);
+  }
+
+  std::string_view name() const { return name_; }
+  std::string_view desc() const { return desc_; }
+
+  void GetAnalyses(std::vector<Analysis*>& analyses) {
+    for (auto& analysis : analyses_) analyses.push_back(analysis.get());
+  }
+
+ protected:
+  template <typename Analysis, typename... Analyses,
+            std::enable_if_t<(sizeof...(Analyses) > 0), bool> = true>
+  void AppendAnalyses() {
+    AppendAnalyses<Analysis>();
+    AppendAnalyses<Analyses...>();
+  }
+  template <typename Analysis>
+  void AppendAnalyses() {
+    analyses_.push_back(std::move(std::make_unique<Analysis>()));
+  }
+
+  std::string_view name_;
+  std::string_view desc_;
+  std::vector<std::unique_ptr<Analysis>> analyses_;
+};
+
+template <typename... Analyses>
+class Option : public OptionBase {
+ public:
+  Option(std::string_view name, std::string_view desc) : OptionBase(name, desc) {
+    AppendAnalyses<Analyses...>();
+  }
+};
+
+}  // namespace
+
+void OptionRegistry::Stream(std::ostream& os, std::string_view indent) {
+  for (OptionBase* opt : options_) {
+    os << indent << "--" << opt->name() << ": " << opt->desc() << std::endl;
+  }
+}
+
+static bool ParseArgs(int argc, char** argv, std::vector<Analysis*>& analyses,
+                      std::vector<std::string>& traces) {
+  auto& registry = OptionRegistry::get();
+  for (int i = 0; i < argc; ++i) {
+    if (argv[i][0] != '-') {
+      traces.push_back(argv[i]);
+      struct stat st;
+      if (stat(traces.back().c_str(), &st) != 0) {
+        if (errno == ENOENT) {
+          std::cerr << traces.back() << " does not exist." << std::endl;
+        } else {
+          std::cerr << "stat of file " << traces.back() << " failed: " << strerror(errno)
+                    << std::endl;
+        }
+        return false;
+      }
+      if (!S_ISREG(st.st_mode)) {
+        std::cerr << traces.back() << " is not a regular file." << std::endl;
+        return false;
+      }
+      continue;
+    } else if (argv[i][1] != '-') {
+      std::cerr << "Unknown option: " << argv[i] << std::endl;
+      return false;
+    }
+
+    bool found = false;
+    std::string_view arg(&argv[i][2]);
+    for (auto* option : registry) {
+      if (option->name() == arg) {
+        option->GetAnalyses(analyses);
+        found = true;
+        break;
+      }
+    }
+    if (!found) {
+      std::cerr << "Unknown option: " << argv[i] << std::endl;
+      return false;
+    }
+  }
+  return true;
+}
+
+void Usage() {
+  std::cerr << "Usage: memory_trace_analysis TRACE_FILE1 TRACE_FILE2 ... [Analyses...]\n";
+  std::cerr << "Analyses:\n";
+  OptionRegistry::get().Stream(std::cerr);
+}
+
+int main(int argc, char** argv) {
+  static Option<OpMinMaxAnalysis, OpAverageAnalysis> gen(
+      "op-gen-stats", "get the min/max/avg of each kind of alloc operation");
+  static Option<OpOverlapAnalysis> overlap(
+      "op-overlap", "get the amount of overlap in between each kind of alloc operation");
+
+  if (argc < 2) {
+    Usage();
+    return 1;
+  }
+
+  std::vector<Analysis*> analyses;
+  std::vector<std::string> traces;
+  if (!ParseArgs(argc - 1, argv + 1, analyses, traces)) {
+    Usage();
+    return 1;
+  }
+  if (analyses.empty()) {
+    std::cerr << "No analyses chosen.\n";
+    Usage();
+    return 1;
+  }
+  if (traces.empty()) {
+    std::cerr << "No trace files.\n";
+    Usage();
+    return 1;
+  }
+
+  for (auto& trace : traces) {
+    std::cout << "Analyzing trace " << trace << std::endl;
+    memory_trace::TraceInfo info;
+    info.Init(trace.c_str());
+    for (auto& analysis : analyses) {
+      std::cout << "  " << analysis->Name() << std::endl;
+      analysis->Gather(info);
+      analysis->StreamResult(std::cout, "    ");
+    }
+  }
+  return 0;
+}
diff --git a/libc/memory/trace_analysis/tests/AnalysisTest.cpp b/libc/memory/trace_analysis/tests/AnalysisTest.cpp
new file mode 100644
index 0000000..700ee1f
--- /dev/null
+++ b/libc/memory/trace_analysis/tests/AnalysisTest.cpp
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2025 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gtest/gtest.h>
+
+#include <memory>
+#include <sstream>
+
+#include <android-base/file.h>
+#include <memory_trace/TraceInfo.h>
+
+#include "OpGenAnalysis.h"
+#include "OpOverlapAnalysis.h"
+
+class AnalysisTest : public ::testing::Test {
+ protected:
+  template <typename Analysis>
+  void Gather(std::stringstream& res) {
+    auto analysis = std::make_unique<Analysis>();
+    analysis->Gather(*trace_info_);
+    analysis->StreamResult(res, "  ");
+  }
+
+  void InitTraceInfo(const char* contents) {
+    TemporaryFile tf;
+    ASSERT_NE(-1, tf.fd);
+    ASSERT_TRUE(android::base::WriteStringToFd(contents, tf.fd));
+    close(tf.fd);
+
+    trace_info_.reset(new memory_trace::TraceInfo);
+    trace_info_->Init(tf.path);
+  }
+
+ private:
+  std::unique_ptr<memory_trace::TraceInfo> trace_info_;
+};
+
+TEST_F(AnalysisTest, Average) {
+  const char* const entries =
+      "1234: malloc 0x0 32 1 1101\n"
+      "1234: malloc 0x10 32 2001 3001\n"
+      "1234: malloc 0x20 32 4001 4901\n";
+  ASSERT_NO_FATAL_FAILURE(InitTraceInfo(entries));
+
+  std::stringstream result;
+  Gather<OpAverageAnalysis>(result);
+
+  std::string expected =
+      "  malloc: avg exec time = 1000.0 ns\n"
+      "  calloc: avg exec time = 0.0 ns\n"
+      "  memalign: avg exec time = 0.0 ns\n"
+      "  realloc: avg exec time = 0.0 ns\n"
+      "  free: avg exec time = 0.0 ns\n";
+  EXPECT_EQ(expected, result.str());
+}
+
+TEST_F(AnalysisTest, MinMax) {
+  const char* const entries =
+      "1234: malloc 0x0 32 1 1001\n"
+      "1234: malloc 0x10 32 2001 3001\n"
+      "1234: malloc 0x20 32 4001 5001\n";
+  ASSERT_NO_FATAL_FAILURE(InitTraceInfo(entries));
+
+  std::stringstream result;
+  Gather<OpMinMaxAnalysis>(result);
+
+  std::string expected =
+      "  malloc: min exec time = 1000 ns, max exec time = 1000 ns\n"
+      "  calloc: min exec time = 0 ns, max exec time = 0 ns\n"
+      "  memalign: min exec time = 0 ns, max exec time = 0 ns\n"
+      "  realloc: min exec time = 0 ns, max exec time = 0 ns\n"
+      "  free: min exec time = 0 ns, max exec time = 0 ns\n";
+  EXPECT_EQ(expected, result.str());
+}
+
+TEST_F(AnalysisTest, Overlap) {
+  const char* const entries =
+      "1234: malloc 0x0 32 1 1001\n"
+      "1235: malloc 0x30 256 600 800\n"
+      "1236: malloc 0x10 48 500 2500\n"
+      "1237: malloc 0x20 128 2200 3200\n";
+  ASSERT_NO_FATAL_FAILURE(InitTraceInfo(entries));
+
+  std::stringstream result;
+  Gather<OpOverlapAnalysis>(result);
+
+  EXPECT_EQ("  Overlap of all operations is 1001 ns\n", result.str());
+}
diff --git a/libc/platform/bionic/dlext_namespaces.h b/libc/platform/bionic/dlext_namespaces.h
new file mode 100644
index 0000000..33dd18c
--- /dev/null
+++ b/libc/platform/bionic/dlext_namespaces.h
@@ -0,0 +1,139 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <sys/cdefs.h>
+
+#include <android/dlext.h>
+#include <stdbool.h>
+#include <stdint.h>
+
+__BEGIN_DECLS
+
+/**
+ * Initializes the anonymous namespace.
+ *
+ * `shared_libs_sonames` is a list of sonames to be shared with the default namespace,
+ * separated by colons (such as "libc.so:libm.so:libdl.so").
+ *
+ * `library_search_path` is the search path for the anonymous namespace.
+ * The anonymous namespace is used when the linker cannot identify the caller of
+ * dlopen() or dlsym(). This happens for code not loaded by the dynamic linker,
+ * such as calls from a custom JIT.
+ */
+extern bool android_init_anonymous_namespace(const char* shared_libs_sonames,
+                                             const char* library_search_path);
+
+/**
+ * Bitmask flags for the android_create_namespace() `type` argument.
+ */
+enum {
+  /**
+   * A regular namespace is a namespace with a custom search path that does
+   * not impose any restrictions on the location of native libraries.
+   */
+  ANDROID_NAMESPACE_TYPE_REGULAR = 0,
+
+  /**
+   * An isolated namespace requires all the libraries to be on the search path
+   * or under `permitted_when_isolated_path`. The search path is the union of
+   * `ld_library_path` and `default_library_path`.
+   */
+  ANDROID_NAMESPACE_TYPE_ISOLATED = 1,
+
+  /**
+   * "Share" the caller namespace's list of libraries.
+   *
+   * This actually _clones_ the list of libraries of the caller namespace
+   * upon creation rather than actually sharing:
+   *
+   * 1. Both the caller namespace and the new one will use the same copy of a
+   *    library if it was already loaded in the caller namespace.
+   *
+   * but
+   *
+   * 2. Libraries loaded after the namespace is created will not be shared.
+   *
+   * Shared namespaces can be isolated or regular.
+   *
+   * Shared namespaces do not inherit the search path or permitted path from
+   * the caller namespace.
+   */
+  ANDROID_NAMESPACE_TYPE_SHARED = 2,
+
+  /**
+   * Enable the exempt-list workaround for the namespace.
+   * See http://b/26394120 for details.
+   */
+  ANDROID_NAMESPACE_TYPE_EXEMPT_LIST_ENABLED = 0x08000000,
+
+  /**
+   * Use this namespace as the anonymous namespace.
+   *
+   * There can be only one anonymous namespace in a process.
+   * If there is already an anonymous namespace in the process,
+   * using this flag when creating a new namespace is an error.
+   */
+  ANDROID_NAMESPACE_TYPE_ALSO_USED_AS_ANONYMOUS = 0x10000000,
+
+  /** A common combination. */
+  ANDROID_NAMESPACE_TYPE_SHARED_ISOLATED = ANDROID_NAMESPACE_TYPE_SHARED |
+                                           ANDROID_NAMESPACE_TYPE_ISOLATED,
+};
+
+/**
+ * Create a new linker namespace.
+ *
+ * `ld_library_path` and `default_library_path` represent the search path
+ * for the libraries in the namespace.
+ *
+ * The libraries in the namespace are searched in the following order:
+ * 1. `ld_library_path` (think of this as a namespace-local $LD_LIBRARY_PATH).
+ * 2. In directories specified by DT_RUNPATH of the "needed by" binary.
+ * 3. `default_library_path` (think of this as a namespace-local default library path).
+ *
+ * If the ANDROID_NAMESPACE_TYPE_ISOLATED bit is set in `type`,
+ * the resulting namespace requires all of the libraries to be on the search
+ * path or under the `permitted_when_isolated_path`;
+ * the search path is `ld_library_path` followed by `default_library_path`.
+ * Note that the `permitted_when_isolated_path` path is not part of the search
+ * path and does not affect the search order: it's a way to allow loading
+ * libraries from specific locations when using absolute paths.
+ *
+ * If a library or any of its dependencies are outside of the `permitted_when_isolated_path`
+ * and search path, and not part of the public namespace, dlopen() will fail.
+ */
+extern struct android_namespace_t* android_create_namespace(const char* name,
+                                                            const char* ld_library_path,
+                                                            const char* default_library_path,
+                                                            uint64_t type,
+                                                            const char* permitted_when_isolated_path,
+                                                            struct android_namespace_t* parent);
+
+extern bool android_link_namespaces(struct android_namespace_t* from,
+                                    struct android_namespace_t* to,
+                                    const char* shared_libs_sonames);
+
+extern bool android_link_namespaces_all_libs(struct android_namespace_t* from,
+                                             struct android_namespace_t* to);
+
+extern struct android_namespace_t* android_get_exported_namespace(const char* name);
+
+// TODO: move this somewhere else, since it's unrelated to linker namespaces.
+extern void android_set_application_target_sdk_version(int target);
+
+__END_DECLS
diff --git a/libc/platform/bionic/macros.h b/libc/platform/bionic/macros.h
index c4af3b9..217b985 100644
--- a/libc/platform/bionic/macros.h
+++ b/libc/platform/bionic/macros.h
@@ -27,15 +27,8 @@
   TypeName() = delete;                                  \
   BIONIC_DISALLOW_COPY_AND_ASSIGN(TypeName)
 
-#define BIONIC_ROUND_UP_POWER_OF_2(value) \
-  ((sizeof(value) == 8) \
-    ? (1UL << (64 - __builtin_clzl(static_cast<unsigned long>(value)))) \
-    : (1UL << (32 - __builtin_clz(static_cast<unsigned int>(value)))))
-
-#if defined(__arm__)
-#define BIONIC_STOP_UNWIND asm volatile(".cfi_undefined r14")
-#elif defined(__aarch64__)
-#define BIONIC_STOP_UNWIND asm volatile(".cfi_undefined x30")
+#if defined(__arm__) || defined(__aarch64__)
+#define BIONIC_STOP_UNWIND asm volatile(".cfi_undefined lr")
 #elif defined(__i386__)
 #define BIONIC_STOP_UNWIND asm volatile(".cfi_undefined \%eip")
 #elif defined(__riscv)
@@ -60,14 +53,6 @@
 
 #define arraysize(array) (sizeof(ArraySizeHelper(array)))
 
-// Used to inform clang's -Wimplicit-fallthrough that a fallthrough is intended. There's no way to
-// silence (or enable, apparently) -Wimplicit-fallthrough in C yet.
-#ifdef __cplusplus
-#define __BIONIC_FALLTHROUGH [[clang::fallthrough]]
-#else
-#define __BIONIC_FALLTHROUGH
-#endif
-
 static inline uintptr_t untag_address(uintptr_t p) {
 #if defined(__aarch64__)
   return p & ((1ULL << 56) - 1);
diff --git a/libc/platform/bionic/mte.h b/libc/platform/bionic/mte.h
index 27cbae1..1d521bf 100644
--- a/libc/platform/bionic/mte.h
+++ b/libc/platform/bionic/mte.h
@@ -128,9 +128,10 @@
 }
 
 inline void stack_mte_free_ringbuffer(uintptr_t stack_mte_tls) {
-  size_t size = stack_mte_ringbuffer_size_from_pointer(stack_mte_tls);
+  size_t page_aligned_size =
+      __builtin_align_up(stack_mte_ringbuffer_size_from_pointer(stack_mte_tls), page_size());
   void* ptr = reinterpret_cast<void*>(stack_mte_tls & ((1ULL << 56ULL) - 1ULL));
-  munmap(ptr, size);
+  munmap(ptr, page_aligned_size);
 }
 
 inline void* stack_mte_ringbuffer_allocate(size_t n, const char* name) {
@@ -147,8 +148,9 @@
   // bytes left.
   size_t size = stack_mte_ringbuffer_size(n);
   size_t pgsize = page_size();
+  size_t page_aligned_size = __builtin_align_up(size, pgsize);
 
-  size_t alloc_size = __BIONIC_ALIGN(3 * size - pgsize, pgsize);
+  size_t alloc_size = 3 * page_aligned_size - pgsize;
   void* allocation_ptr =
       mmap(nullptr, alloc_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
   if (allocation_ptr == MAP_FAILED)
@@ -156,7 +158,7 @@
   uintptr_t allocation = reinterpret_cast<uintptr_t>(allocation_ptr);
 
   size_t alignment = 2 * size;
-  uintptr_t aligned_allocation = __BIONIC_ALIGN(allocation, alignment);
+  uintptr_t aligned_allocation = __builtin_align_up(allocation, alignment);
   if (allocation != aligned_allocation) {
     munmap(reinterpret_cast<void*>(allocation), aligned_allocation - allocation);
   }
diff --git a/libc/platform/bionic/pac.h b/libc/platform/bionic/pac.h
index 34efc48..7de3c29 100644
--- a/libc/platform/bionic/pac.h
+++ b/libc/platform/bionic/pac.h
@@ -29,13 +29,14 @@
 #pragma once
 
 #include <stddef.h>
+#include <stdint.h>
 
 inline uintptr_t __bionic_clear_pac_bits(uintptr_t ptr) {
 #if defined(__aarch64__)
-  register uintptr_t x30 __asm("x30") = ptr;
+  register uintptr_t lr __asm("lr") = ptr;
   // This is a NOP on pre-Armv8.3-A architectures.
-  asm("xpaclri" : "+r"(x30));
-  return x30;
+  asm("xpaclri" : "+r"(lr));
+  return lr;
 #else
   return ptr;
 #endif
diff --git a/libc/platform/bionic/reserved_signals.h b/libc/platform/bionic/reserved_signals.h
index 1c7076b..22d8c36 100644
--- a/libc/platform/bionic/reserved_signals.h
+++ b/libc/platform/bionic/reserved_signals.h
@@ -35,40 +35,54 @@
 #include "macros.h"
 
 // Realtime signals reserved for internal use:
-//   32 (__SIGRTMIN + 0)        POSIX timers
-//   33 (__SIGRTMIN + 1)        libbacktrace
-//   34 (__SIGRTMIN + 2)        libcore
-//   35 (__SIGRTMIN + 3)        debuggerd
-//   36 (__SIGRTMIN + 4)        platform profilers (heapprofd, traced_perf)
-//   37 (__SIGRTMIN + 5)        coverage (libprofile-extras)
-//   38 (__SIGRTMIN + 6)        heapprofd ART managed heap dumps
-//   39 (__SIGRTMIN + 7)        fdtrack
-//   40 (__SIGRTMIN + 8)        android_run_on_all_threads (bionic/pthread_internal.cpp)
-//   41 (__SIGRTMIN + 9)        re-enable MTE on thread
 
+//   32 (__SIGRTMIN + 0)        POSIX timers
 #define BIONIC_SIGNAL_POSIX_TIMERS (__SIGRTMIN + 0)
+
+//   33 (__SIGRTMIN + 1)        libbacktrace
 #define BIONIC_SIGNAL_BACKTRACE (__SIGRTMIN + 1)
+
+//   34 (__SIGRTMIN + 2)        libcore
+// There's no constant for this because it's hard-coded in the OpenJDK source.
+// It's used to implement Java's "close() on a Socket wakes blocked readers and
+// writers" semantics.
+
+//   35 (__SIGRTMIN + 3)        debuggerd
 #define BIONIC_SIGNAL_DEBUGGER (__SIGRTMIN + 3)
+
+//   36 (__SIGRTMIN + 4)        platform profilers (heapprofd, traced_perf)
 #define BIONIC_SIGNAL_PROFILER (__SIGRTMIN + 4)
-// When used for the dumping a heap dump, BIONIC_SIGNAL_ART_PROFILER is always handled
-// gracefully without crashing.
+
+//   37 (__SIGRTMIN + 5)        coverage (libprofile-extras)
+// Used by the clang coverage support to flush coverage data to disk.
+#define BIONIC_SIGNAL_FLUSH_COVERAGE (__SIGRTMIN + 5)
+
+//   38 (__SIGRTMIN + 6)        heapprofd ART managed heap dumps
+// When used in ART for heap dumps, this is handled without crashing.
 // In debuggerd, we crash the process with this signal to indicate to init that
 // a process has been terminated by an MTEAERR SEGV. This works because there is
 // no other reason a process could have terminated with this signal.
 // This is to work around the limitation of that it is not possible to get the
 // si_code that terminated a process.
 #define BIONIC_SIGNAL_ART_PROFILER (__SIGRTMIN + 6)
+
+//   39 (__SIGRTMIN + 7)        fdtrack
 #define BIONIC_SIGNAL_FDTRACK (__SIGRTMIN + 7)
+
+//   40 (__SIGRTMIN + 8)        android_run_on_all_threads (bionic/pthread_internal.cpp)
 #define BIONIC_SIGNAL_RUN_ON_ALL_THREADS (__SIGRTMIN + 8)
+
+//   41 (__SIGRTMIN + 9)        re-enable MTE on thread
 #define BIONIC_ENABLE_MTE (__SIGRTMIN + 9)
 
 #define __SIGRT_RESERVED 10
+
 static inline __always_inline sigset64_t filter_reserved_signals(sigset64_t sigset, int how) {
   int (*block)(sigset64_t*, int);
   int (*unblock)(sigset64_t*, int);
   switch (how) {
     case SIG_BLOCK:
-      __BIONIC_FALLTHROUGH;
+      [[fallthrough]];
     case SIG_SETMASK:
       block = sigaddset64;
       unblock = sigdelset64;
@@ -81,17 +95,12 @@
   }
 
   // The POSIX timer signal must be blocked.
-  block(&sigset, __SIGRTMIN + 0);
+  block(&sigset, BIONIC_SIGNAL_POSIX_TIMERS);
 
   // Everything else must remain unblocked.
-  unblock(&sigset, __SIGRTMIN + 1);
-  unblock(&sigset, __SIGRTMIN + 2);
-  unblock(&sigset, __SIGRTMIN + 3);
-  unblock(&sigset, __SIGRTMIN + 4);
-  unblock(&sigset, __SIGRTMIN + 5);
-  unblock(&sigset, __SIGRTMIN + 6);
-  unblock(&sigset, __SIGRTMIN + 7);
-  unblock(&sigset, __SIGRTMIN + 8);
-  unblock(&sigset, __SIGRTMIN + 9);
+  for (int i = 1; i < __SIGRT_RESERVED; ++i) {
+    unblock(&sigset, __SIGRTMIN + i);
+  }
+
   return sigset;
 }
diff --git a/libc/private/CFIShadow.h b/libc/private/CFIShadow.h
index b40c063..c62a4ef 100644
--- a/libc/private/CFIShadow.h
+++ b/libc/private/CFIShadow.h
@@ -14,8 +14,9 @@
  * limitations under the License.
  */
 
-#ifndef CFI_SHADOW_H
-#define CFI_SHADOW_H
+#pragma once
+
+#include <sys/cdefs.h>
 
 #include <stdint.h>
 
@@ -86,5 +87,3 @@
                            // kRegularShadowMin.
   };
 };
-
-#endif  // CFI_SHADOW_H
diff --git a/libc/private/CachedProperty.h b/libc/private/CachedProperty.h
index 7accdb3..440db52 100644
--- a/libc/private/CachedProperty.h
+++ b/libc/private/CachedProperty.h
@@ -28,6 +28,8 @@
 
 #pragma once
 
+#include <sys/cdefs.h>
+
 #include <string.h>
 #include <sys/system_properties.h>
 
diff --git a/libc/private/ErrnoRestorer.h b/libc/private/ErrnoRestorer.h
index cecf103..8802604 100644
--- a/libc/private/ErrnoRestorer.h
+++ b/libc/private/ErrnoRestorer.h
@@ -16,6 +16,8 @@
 
 #pragma once
 
+#include <sys/cdefs.h>
+
 #include <errno.h>
 
 #include "platform/bionic/macros.h"
diff --git a/libc/private/FdPath.h b/libc/private/FdPath.h
index 4a6a2d5..d17ac56 100644
--- a/libc/private/FdPath.h
+++ b/libc/private/FdPath.h
@@ -16,6 +16,10 @@
 
 #pragma once
 
+#include <sys/cdefs.h>
+
+#include <stdio.h>
+
 class FdPath {
  public:
   explicit FdPath(int fd) {
diff --git a/libc/private/KernelArgumentBlock.h b/libc/private/KernelArgumentBlock.h
index e1f655a..53bf569 100644
--- a/libc/private/KernelArgumentBlock.h
+++ b/libc/private/KernelArgumentBlock.h
@@ -16,6 +16,8 @@
 
 #pragma once
 
+#include <sys/cdefs.h>
+
 #include <elf.h>
 #include <link.h>
 #include <stdint.h>
diff --git a/libc/private/MallocXmlElem.h b/libc/private/MallocXmlElem.h
index f8c72ab..3c8b693 100644
--- a/libc/private/MallocXmlElem.h
+++ b/libc/private/MallocXmlElem.h
@@ -16,6 +16,8 @@
 
 #pragma once
 
+#include <sys/cdefs.h>
+
 #include <stdarg.h>
 #include <stdio.h>
 #include <unistd.h>
diff --git a/libc/private/ScopedFd.h b/libc/private/ScopedFd.h
index ea7f59e..b258479 100644
--- a/libc/private/ScopedFd.h
+++ b/libc/private/ScopedFd.h
@@ -28,6 +28,8 @@
 
 #pragma once
 
+#include <sys/cdefs.h>
+
 #include <unistd.h>
 
 #include "platform/bionic/macros.h"
diff --git a/libc/private/ScopedPthreadMutexLocker.h b/libc/private/ScopedPthreadMutexLocker.h
index a87750c..8431cda 100644
--- a/libc/private/ScopedPthreadMutexLocker.h
+++ b/libc/private/ScopedPthreadMutexLocker.h
@@ -16,6 +16,8 @@
 
 #pragma once
 
+#include <sys/cdefs.h>
+
 #include <pthread.h>
 
 #include "platform/bionic/macros.h"
diff --git a/libc/private/ScopedRWLock.h b/libc/private/ScopedRWLock.h
index 0af372b..af1cf9a 100644
--- a/libc/private/ScopedRWLock.h
+++ b/libc/private/ScopedRWLock.h
@@ -28,6 +28,8 @@
 
 #pragma once
 
+#include <sys/cdefs.h>
+
 #include <pthread.h>
 
 #include "platform/bionic/macros.h"
diff --git a/libc/private/ScopedReaddir.h b/libc/private/ScopedReaddir.h
index 7b07921..a30060b 100644
--- a/libc/private/ScopedReaddir.h
+++ b/libc/private/ScopedReaddir.h
@@ -16,6 +16,8 @@
 
 #pragma once
 
+#include <sys/cdefs.h>
+
 #include <dirent.h>
 
 #include "platform/bionic/macros.h"
diff --git a/libc/private/ScopedSignalBlocker.h b/libc/private/ScopedSignalBlocker.h
index f6ba9ed..c2ed68c 100644
--- a/libc/private/ScopedSignalBlocker.h
+++ b/libc/private/ScopedSignalBlocker.h
@@ -16,6 +16,8 @@
 
 #pragma once
 
+#include <sys/cdefs.h>
+
 #include <signal.h>
 
 #include "platform/bionic/macros.h"
diff --git a/libc/private/ScopedSignalHandler.h b/libc/private/ScopedSignalHandler.h
index 7031752..edb5c4c 100644
--- a/libc/private/ScopedSignalHandler.h
+++ b/libc/private/ScopedSignalHandler.h
@@ -16,6 +16,8 @@
 
 #pragma once
 
+#include <sys/cdefs.h>
+
 #include <signal.h>
 
 class ScopedSignalHandler {
diff --git a/libc/private/SigSetConverter.h b/libc/private/SigSetConverter.h
index 9e9df73..5870cc9 100644
--- a/libc/private/SigSetConverter.h
+++ b/libc/private/SigSetConverter.h
@@ -28,6 +28,10 @@
 
 #pragma once
 
+#include <sys/cdefs.h>
+
+#include <signal.h>
+
 // Android's 32-bit ABI shipped with a sigset_t too small to include any
 // of the realtime signals, so we have both sigset_t and sigset64_t. Many
 // new system calls only accept a sigset64_t, so this helps paper over
diff --git a/libc/private/WriteProtected.h b/libc/private/WriteProtected.h
index f269125..bc09fc5 100644
--- a/libc/private/WriteProtected.h
+++ b/libc/private/WriteProtected.h
@@ -16,9 +16,10 @@
 
 #pragma once
 
+#include <sys/cdefs.h>
+
 #include <errno.h>
 #include <string.h>
-#include <sys/cdefs.h>
 #include <sys/mman.h>
 #include <sys/user.h>
 
diff --git a/libc/private/bionic_allocator.h b/libc/private/bionic_allocator.h
index 9872669..58dbcea 100644
--- a/libc/private/bionic_allocator.h
+++ b/libc/private/bionic_allocator.h
@@ -29,6 +29,7 @@
 #pragma once
 
 #include <sys/cdefs.h>
+
 #include <stddef.h>
 #include <stdint.h>
 
diff --git a/libc/private/bionic_arc4random.h b/libc/private/bionic_arc4random.h
index cdc9b6d..f57ca50 100644
--- a/libc/private/bionic_arc4random.h
+++ b/libc/private/bionic_arc4random.h
@@ -26,8 +26,9 @@
  * SUCH DAMAGE.
  */
 
-#ifndef _PRIVATE_BIONIC_ARC4RANDOM_H_
-#define _PRIVATE_BIONIC_ARC4RANDOM_H_
+#pragma once
+
+#include <sys/cdefs.h>
 
 #include <stddef.h>
 
@@ -37,5 +38,3 @@
 // wrapper falls back to AT_RANDOM if the kernel doesn't have enough
 // entropy for getrandom(2) or /dev/urandom.
 void __libc_safe_arc4random_buf(void* buf, size_t n);
-
-#endif
diff --git a/libc/private/bionic_asm.h b/libc/private/bionic_asm.h
index b3b2b47..05af4ab 100644
--- a/libc/private/bionic_asm.h
+++ b/libc/private/bionic_asm.h
@@ -28,8 +28,8 @@
 
 #pragma once
 
-/* https://github.com/android/ndk/issues/1422 */
-#include <features.h>
+/* This should be valid for assembler too: https://github.com/android/ndk/issues/1422 */
+#include <sys/cdefs.h>
 
 #include <asm/unistd.h> /* For system call numbers. */
 #define MAX_ERRNO 4095  /* For recognizing system call error returns. */
diff --git a/libc/private/bionic_call_ifunc_resolver.h b/libc/private/bionic_call_ifunc_resolver.h
index e0ea35b..cdc62a0 100644
--- a/libc/private/bionic_call_ifunc_resolver.h
+++ b/libc/private/bionic_call_ifunc_resolver.h
@@ -28,7 +28,8 @@
 
 #pragma once
 
-#include <link.h>
 #include <sys/cdefs.h>
 
+#include <link.h>
+
 __LIBC_HIDDEN__ ElfW(Addr) __bionic_call_ifunc_resolver(ElfW(Addr) resolver_addr);
diff --git a/libc/private/bionic_config.h b/libc/private/bionic_config.h
index 0c9811c..6d35807 100644
--- a/libc/private/bionic_config.h
+++ b/libc/private/bionic_config.h
@@ -14,13 +14,12 @@
  * limitations under the License.
  */
 
-#ifndef _BIONIC_CONFIG_H_
-#define _BIONIC_CONFIG_H_
+#pragma once
+
+#include <sys/cdefs.h>
 
 // valloc(3) and pvalloc(3) were removed from POSIX 2004. We do not include them
 // for LP64, but the symbols remain in LP32 for binary compatibility.
 #if !defined(__LP64__)
 #define HAVE_DEPRECATED_MALLOC_FUNCS 1
 #endif
-
-#endif // _BIONIC_CONFIG_H_
diff --git a/libc/private/bionic_constants.h b/libc/private/bionic_constants.h
index ce484d8..a56c9e6 100644
--- a/libc/private/bionic_constants.h
+++ b/libc/private/bionic_constants.h
@@ -16,6 +16,8 @@
 
 #pragma once
 
+#include <sys/cdefs.h>
+
 #define US_PER_S 1'000'000LL
 #define NS_PER_S 1'000'000'000LL
 
diff --git a/libc/private/bionic_defs.h b/libc/private/bionic_defs.h
index 5a48f25..b46452f 100644
--- a/libc/private/bionic_defs.h
+++ b/libc/private/bionic_defs.h
@@ -26,8 +26,9 @@
  * SUCH DAMAGE.
  */
 
-#ifndef __BIONIC_PRIVATE_BIONIC_DEFS_H_
-#define __BIONIC_PRIVATE_BIONIC_DEFS_H_
+#pragma once
+
+#include <sys/cdefs.h>
 
 /*
  * This label is used to mark libc/libdl symbols that may need to be replaced
@@ -43,5 +44,3 @@
 #define __BIONIC_WEAK_VARIABLE_FOR_NATIVE_BRIDGE
 #define __BIONIC_WEAK_FOR_NATIVE_BRIDGE_INLINE static inline
 #endif
-
-#endif /* __BIONIC_PRIVATE_BIONIC_DEFS_H_ */
diff --git a/libc/private/bionic_elf_dtv_offset.h b/libc/private/bionic_elf_dtv_offset.h
index 8d9f3b9..0b6fd20 100644
--- a/libc/private/bionic_elf_dtv_offset.h
+++ b/libc/private/bionic_elf_dtv_offset.h
@@ -28,6 +28,8 @@
 
 #pragma once
 
+#include <sys/cdefs.h>
+
 #if defined(__riscv)
 // TLS_DTV_OFFSET is a constant used in relocation fields, defined in RISC-V ELF Specification[1]
 // The front of the TCB contains a pointer to the DTV, and each pointer in DTV
diff --git a/libc/private/bionic_elf_tls.h b/libc/private/bionic_elf_tls.h
index 04297ad..bc0ffa9 100644
--- a/libc/private/bionic_elf_tls.h
+++ b/libc/private/bionic_elf_tls.h
@@ -28,11 +28,12 @@
 
 #pragma once
 
+#include <sys/cdefs.h>
+
 #include <link.h>
 #include <pthread.h>
 #include <stdatomic.h>
 #include <stdint.h>
-#include <sys/cdefs.h>
 
 #include "bionic_elf_dtv_offset.h"
 
diff --git a/libc/private/bionic_fdsan.h b/libc/private/bionic_fdsan.h
index f403d08..c511494 100644
--- a/libc/private/bionic_fdsan.h
+++ b/libc/private/bionic_fdsan.h
@@ -28,12 +28,13 @@
 
 #pragma once
 
+#include <sys/cdefs.h>
+
 #include <android/fdsan.h>
 
 #include <errno.h>
 #include <stdatomic.h>
 #include <string.h>
-#include <sys/cdefs.h>
 #include <sys/mman.h>
 #include <sys/resource.h>
 #include <sys/user.h>
diff --git a/libc/private/bionic_fdtrack.h b/libc/private/bionic_fdtrack.h
index c05b32b..d3d68b2 100644
--- a/libc/private/bionic_fdtrack.h
+++ b/libc/private/bionic_fdtrack.h
@@ -28,9 +28,10 @@
 
 #pragma once
 
-#include <stdatomic.h>
 #include <sys/cdefs.h>
 
+#include <stdatomic.h>
+
 #include "platform/bionic/fdtrack.h"
 
 #include "bionic/pthread_internal.h"
diff --git a/libc/private/bionic_fortify.h b/libc/private/bionic_fortify.h
index df83360..dcc6416 100644
--- a/libc/private/bionic_fortify.h
+++ b/libc/private/bionic_fortify.h
@@ -28,12 +28,15 @@
 
 #pragma once
 
+#include <sys/cdefs.h>
+
 #include <poll.h> // For struct pollfd.
 #include <stdarg.h>
 #include <stdlib.h>
 #include <sys/select.h> // For struct fd_set.
 
 #include <async_safe/log.h>
+#include <private/bionic_inline_raise.h>
 
 //
 // LLVM can't inline variadic functions, and we don't want one definition of
@@ -44,6 +47,11 @@
   va_start(args, fmt);
   async_safe_fatal_va_list("FORTIFY", fmt, args);
   va_end(args);
+
+  // Assume we can save a stack frame in the crash, fall back to abort() if not.
+#if !defined(BIONIC_RUST_BAREMETAL)
+  inline_raise(SIGABRT);
+#endif
   abort();
 }
 
diff --git a/libc/private/bionic_futex.h b/libc/private/bionic_futex.h
index b340690..9af2035 100644
--- a/libc/private/bionic_futex.h
+++ b/libc/private/bionic_futex.h
@@ -25,14 +25,15 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
-#ifndef _BIONIC_FUTEX_H
-#define _BIONIC_FUTEX_H
+
+#pragma once
+
+#include <sys/cdefs.h>
 
 #include <errno.h>
 #include <linux/futex.h>
 #include <stdbool.h>
 #include <stddef.h>
-#include <sys/cdefs.h>
 #include <sys/syscall.h>
 #include <unistd.h>
 
@@ -76,5 +77,3 @@
 
 __LIBC_HIDDEN__ int __futex_pi_lock_ex(volatile void* ftx, bool shared, bool use_realtime_clock,
                                        const timespec* abs_timeout);
-
-#endif /* _BIONIC_FUTEX_H */
diff --git a/libc/private/bionic_globals.h b/libc/private/bionic_globals.h
index 2346a4d..a7a4afe 100644
--- a/libc/private/bionic_globals.h
+++ b/libc/private/bionic_globals.h
@@ -26,15 +26,15 @@
  * SUCH DAMAGE.
  */
 
-#ifndef _PRIVATE_BIONIC_GLOBALS_H
-#define _PRIVATE_BIONIC_GLOBALS_H
+#pragma once
+
+#include <sys/cdefs.h>
 
 #include <inttypes.h>
 #include <link.h>
 #include <platform/bionic/malloc.h>
 #include <pthread.h>
 #include <stdatomic.h>
-#include <sys/cdefs.h>
 
 #include "private/WriteProtected.h"
 #include "private/bionic_allocator.h"
@@ -177,5 +177,3 @@
 extern "C" __LIBC_HIDDEN__ void __libc_int0x80();
 __LIBC_HIDDEN__ void __libc_init_sysinfo();
 #endif
-
-#endif
diff --git a/libc/private/bionic_ieee.h b/libc/private/bionic_ieee.h
index 69095f0..9fb3c0c 100644
--- a/libc/private/bionic_ieee.h
+++ b/libc/private/bionic_ieee.h
@@ -45,8 +45,9 @@
  *	@(#)ieee.h	8.1 (Berkeley) 6/11/93
  */
 
-#ifndef _MACHINE_IEEE_H_
-#define _MACHINE_IEEE_H_
+#pragma once
+
+#include <sys/cdefs.h>
 
 #include <sys/types.h>
 
@@ -114,5 +115,3 @@
 #endif
 
 __END_DECLS
-
-#endif /* _MACHINE_IEEE_H_ */
diff --git a/libc/private/bionic_ifuncs.h b/libc/private/bionic_ifuncs.h
index b31c903..0d48038 100644
--- a/libc/private/bionic_ifuncs.h
+++ b/libc/private/bionic_ifuncs.h
@@ -28,6 +28,8 @@
 
 #pragma once
 
+#include <sys/cdefs.h>
+
 #include <stdint.h>
 #include <sys/ifunc.h>
 
@@ -98,6 +100,12 @@
     FORWARD(memcpy)(dst, src, n);                                         \
   })
 
+typedef void* __memcpy_chk_func_t(void*, const void*, size_t, size_t);
+#define __MEMCPY_CHK_SHIM()                                                                \
+  DEFINE_STATIC_SHIM(void* __memcpy_chk(void* dst, const void* src, size_t n, size_t n2) { \
+    FORWARD(__memcpy_chk)(dst, src, n, n2);                                                \
+  })
+
 typedef void* memmove_func_t(void*, const void*, size_t);
 #define MEMMOVE_SHIM()                                                     \
   DEFINE_STATIC_SHIM(void* memmove(void* dst, const void* src, size_t n) { \
diff --git a/libc/private/bionic_inline_raise.h b/libc/private/bionic_inline_raise.h
index 82a564d..253831c 100644
--- a/libc/private/bionic_inline_raise.h
+++ b/libc/private/bionic_inline_raise.h
@@ -29,13 +29,14 @@
 #pragma once
 
 #include <sys/cdefs.h>
+
 #include <sys/syscall.h>
 #include <sys/types.h>
 #include <unistd.h>
 
 // An inline version of pthread_sigqueue(pthread_self(), ...), to reduce the number of
 // uninteresting stack frames at the top of a crash.
-static inline __always_inline void inline_raise(int sig, void* value = nullptr) {
+static inline __always_inline int inline_raise(int sig, void* value = nullptr) {
   // Protect ourselves against stale cached PID/TID values by fetching them via syscall.
   // http://b/37769298
   pid_t pid = syscall(__NR_getpid);
@@ -46,6 +47,7 @@
   info.si_uid = getuid();
   info.si_value.sival_ptr = value;
 
+  long result;
 #if defined(__arm__)
   register long r0 __asm__("r0") = pid;
   register long r1 __asm__("r1") = tid;
@@ -53,6 +55,7 @@
   register long r3 __asm__("r3") = reinterpret_cast<long>(&info);
   register long r7 __asm__("r7") = __NR_rt_tgsigqueueinfo;
   __asm__("swi #0" : "=r"(r0) : "r"(r0), "r"(r1), "r"(r2), "r"(r3), "r"(r7) : "memory");
+  result = r0;
 #elif defined(__aarch64__)
   register long x0 __asm__("x0") = pid;
   register long x1 __asm__("x1") = tid;
@@ -60,6 +63,7 @@
   register long x3 __asm__("x3") = reinterpret_cast<long>(&info);
   register long x8 __asm__("x8") = __NR_rt_tgsigqueueinfo;
   __asm__("svc #0" : "=r"(x0) : "r"(x0), "r"(x1), "r"(x2), "r"(x3), "r"(x8) : "memory");
+  result = x0;
 #elif defined(__riscv)
   register long a0 __asm__("a0") = pid;
   register long a1 __asm__("a1") = tid;
@@ -67,6 +71,7 @@
   register long a3 __asm__("a3") = reinterpret_cast<long>(&info);
   register long a7 __asm__("a7") = __NR_rt_tgsigqueueinfo;
   __asm__("ecall" : "=r"(a0) : "r"(a0), "r"(a1), "r"(a2), "r"(a3), "r"(a7) : "memory");
+  result = a0;
 #elif defined(__x86_64__)
   register long rax __asm__("rax") = __NR_rt_tgsigqueueinfo;
   register long rdi __asm__("rdi") = pid;
@@ -77,8 +82,15 @@
           : "+r"(rax)
           : "r"(rdi), "r"(rsi), "r"(rdx), "r"(r10)
           : "memory", "cc", "r11", "rcx");
+  result = rax;
 #else
   // 32-bit x86 is a huge mess, so don't even bother...
-  syscall(__NR_rt_tgsigqueueinfo, pid, tid, sig, &info);
+  return syscall(__NR_rt_tgsigqueueinfo, pid, tid, sig, &info);
 #endif
+
+  if (result < 0) {
+    errno = -result;
+    return -1;
+  }
+  return 0;
 }
diff --git a/libc/private/bionic_lock.h b/libc/private/bionic_lock.h
index d0c6d5e..0089675 100644
--- a/libc/private/bionic_lock.h
+++ b/libc/private/bionic_lock.h
@@ -28,6 +28,8 @@
 
 #pragma once
 
+#include <sys/cdefs.h>
+
 #include <stdatomic.h>
 #include "private/bionic_futex.h"
 #include "platform/bionic/macros.h"
diff --git a/libc/private/bionic_malloc_dispatch.h b/libc/private/bionic_malloc_dispatch.h
index 52d8573..f76b75b 100644
--- a/libc/private/bionic_malloc_dispatch.h
+++ b/libc/private/bionic_malloc_dispatch.h
@@ -26,8 +26,9 @@
  * SUCH DAMAGE.
  */
 
-#ifndef _PRIVATE_BIONIC_MALLOC_DISPATCH_H
-#define _PRIVATE_BIONIC_MALLOC_DISPATCH_H
+#pragma once
+
+#include <sys/cdefs.h>
 
 #include <stddef.h>
 #include <stdint.h>
@@ -77,5 +78,3 @@
   MallocAlignedAlloc aligned_alloc;
   MallocMallocInfo malloc_info;
 } __attribute__((aligned(32)));
-
-#endif
diff --git a/libc/private/bionic_mbstate.h b/libc/private/bionic_mbstate.h
index fb85775..89ceda7 100644
--- a/libc/private/bionic_mbstate.h
+++ b/libc/private/bionic_mbstate.h
@@ -26,8 +26,9 @@
  * SUCH DAMAGE.
  */
 
-#ifndef _BIONIC_MBSTATE_H
-#define _BIONIC_MBSTATE_H
+#pragma once
+
+#include <sys/cdefs.h>
 
 #include <errno.h>
 #include <wchar.h>
@@ -73,5 +74,3 @@
 }
 
 __END_DECLS
-
-#endif // _BIONIC_MBSTATE_H
diff --git a/libc/private/bionic_ssp.h b/libc/private/bionic_ssp.h
index ea62cb9..7372d49 100644
--- a/libc/private/bionic_ssp.h
+++ b/libc/private/bionic_ssp.h
@@ -28,9 +28,10 @@
 
 #pragma once
 
-#include <stdint.h>
 #include <sys/cdefs.h>
 
+#include <stdint.h>
+
 __BEGIN_DECLS
 
 // The compiler uses this if it's not using TLS.
diff --git a/libc/private/bionic_systrace.h b/libc/private/bionic_systrace.h
index dbe1739..6c11697 100644
--- a/libc/private/bionic_systrace.h
+++ b/libc/private/bionic_systrace.h
@@ -16,6 +16,8 @@
 
 #pragma once
 
+#include <sys/cdefs.h>
+
 #include "platform/bionic/macros.h"
 
 // Tracing class for bionic. To begin a trace at a specified point:
@@ -28,7 +30,9 @@
   ~ScopedTrace();
 
   void End();
+
  private:
+  bool should_trace_;
   bool called_end_;
   BIONIC_DISALLOW_COPY_AND_ASSIGN(ScopedTrace);
 };
diff --git a/libc/private/bionic_time_conversions.h b/libc/private/bionic_time_conversions.h
index ce7de0d..5dc28d1 100644
--- a/libc/private/bionic_time_conversions.h
+++ b/libc/private/bionic_time_conversions.h
@@ -28,9 +28,10 @@
 
 #pragma once
 
+#include <sys/cdefs.h>
+
 #include <errno.h>
 #include <time.h>
-#include <sys/cdefs.h>
 
 #include "private/bionic_constants.h"
 
diff --git a/libc/private/bionic_tls.h b/libc/private/bionic_tls.h
index 53fe3d5..b87d257 100644
--- a/libc/private/bionic_tls.h
+++ b/libc/private/bionic_tls.h
@@ -28,10 +28,11 @@
 
 #pragma once
 
+#include <sys/cdefs.h>
+
 #include <locale.h>
 #include <mntent.h>
 #include <stdio.h>
-#include <sys/cdefs.h>
 #include <sys/param.h>
 
 #include <platform/bionic/tls.h>
@@ -106,15 +107,27 @@
   void* data;
 };
 
-// ~3 pages. This struct is allocated as static TLS memory (i.e. at a fixed
-// offset from the thread pointer).
+// Defines the memory layout for the TLS buffers used by basename() and
+// dirname() in libgen.h.
+//
+// This struct is separated out from bionic TLS to ensure that the libgen
+// buffers, when mapped, occupy their own set of memory pages distinct
+// from the primary bionic_tls structure. This helps improve memory usage
+// if libgen functions are not heavily used, especially on 16KB page size
+// systems.
+struct libgen_buffers {
+  char basename_buf[MAXPATHLEN];
+  char dirname_buf[MAXPATHLEN];
+};
+
+// This struct is allocated as static TLS memory (i.e. at a fixed offset
+// from the thread pointer).
 struct bionic_tls {
   pthread_key_data_t key_data[BIONIC_PTHREAD_KEY_COUNT];
 
   locale_t locale;
 
-  char basename_buf[MAXPATHLEN];
-  char dirname_buf[MAXPATHLEN];
+  libgen_buffers* libgen_buffers_ptr;
 
   mntent mntent_buf;
   char mntent_strings[BUFSIZ];
@@ -129,7 +142,7 @@
   passwd_state_t passwd;
 
   char fdtrack_disabled;
-  char bionic_systrace_disabled;
+  char bionic_systrace_enabled;
   char padding[2];
 
   // Initialize the main thread's final object using its bootstrap object.
diff --git a/libc/private/bionic_vdso.h b/libc/private/bionic_vdso.h
index 406b064..aa0c07f 100644
--- a/libc/private/bionic_vdso.h
+++ b/libc/private/bionic_vdso.h
@@ -28,6 +28,8 @@
 
 #pragma once
 
+#include <sys/cdefs.h>
+
 #if defined(__aarch64__)
 #define VDSO_CLOCK_GETTIME_SYMBOL "__kernel_clock_gettime"
 #define VDSO_CLOCK_GETRES_SYMBOL "__kernel_clock_getres"
diff --git a/libc/private/elf_note.h b/libc/private/elf_note.h
index 6a9399b..59be761 100644
--- a/libc/private/elf_note.h
+++ b/libc/private/elf_note.h
@@ -28,6 +28,8 @@
 
 #pragma once
 
+#include <sys/cdefs.h>
+
 #include <elf.h>
 #include <link.h>
 
diff --git a/libc/private/get_cpu_count_from_string.h b/libc/private/get_cpu_count_from_string.h
index a0cb95d..96ef7c5 100644
--- a/libc/private/get_cpu_count_from_string.h
+++ b/libc/private/get_cpu_count_from_string.h
@@ -26,6 +26,10 @@
  * SUCH DAMAGE.
  */
 
+#pragma once
+
+#include <sys/cdefs.h>
+
 #include <ctype.h>
 #include <stdlib.h>
 
diff --git a/libc/private/grp_pwd.h b/libc/private/grp_pwd.h
index ab79586..83b2d66 100644
--- a/libc/private/grp_pwd.h
+++ b/libc/private/grp_pwd.h
@@ -28,6 +28,10 @@
  * SUCH DAMAGE.
  */
 
+#pragma once
+
+#include <sys/cdefs.h>
+
 #include <grp.h>
 #include <pwd.h>
 
diff --git a/libc/private/icu4x.h b/libc/private/icu4x.h
index 8b7e1d0..2f7b742 100644
--- a/libc/private/icu4x.h
+++ b/libc/private/icu4x.h
@@ -28,6 +28,8 @@
 
 #pragma once
 
+#include <sys/cdefs.h>
+
 #include <ctype.h>
 #include <stdint.h>
 #include <wchar.h>
diff --git a/libc/private/linker_native_bridge.h b/libc/private/linker_native_bridge.h
index bfd0153..a772515 100644
--- a/libc/private/linker_native_bridge.h
+++ b/libc/private/linker_native_bridge.h
@@ -28,4 +28,6 @@
 
 #pragma once
 
+#include <sys/cdefs.h>
+
 extern "C" void __linker_reserve_bionic_tls_in_static_tls();
diff --git a/libc/private/thread_private.h b/libc/private/thread_private.h
deleted file mode 100644
index 1a13690..0000000
--- a/libc/private/thread_private.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/* $OpenBSD: thread_private.h,v 1.18 2006/02/22 07:16:31 otto Exp $ */
-
-/* PUBLIC DOMAIN: No Rights Reserved. Marco S Hyman <marc@snafu.org> */
-
-#pragma once
-
-#include <pthread.h>
-
-__BEGIN_DECLS
-
-/*
- * This file defines the thread library interface to libc.  Thread
- * libraries must implement the functions described here for proper
- * inter-operation with libc.   libc contains weak versions of the
- * described functions for operation in a non-threaded environment.
- */
-
-#define __MUTEX_NAME(name) __CONCAT(__libc_mutex_,name)
-#define _THREAD_PRIVATE_MUTEX(name) static pthread_mutex_t __MUTEX_NAME(name) = PTHREAD_MUTEX_INITIALIZER
-#define _THREAD_PRIVATE_MUTEX_LOCK(name) pthread_mutex_lock(&__MUTEX_NAME(name))
-#define _THREAD_PRIVATE_MUTEX_UNLOCK(name) pthread_mutex_unlock(&__MUTEX_NAME(name))
-
-/* Note that these aren't compatible with the usual OpenBSD ones which lazy-initialize! */
-#define _MUTEX_LOCK(l) pthread_mutex_lock((pthread_mutex_t*) l)
-#define _MUTEX_UNLOCK(l) pthread_mutex_unlock((pthread_mutex_t*) l)
-
-__LIBC_HIDDEN__ void    _thread_arc4_lock(void);
-__LIBC_HIDDEN__ void    _thread_arc4_unlock(void);
-
-#define _ARC4_LOCK() _thread_arc4_lock()
-#define _ARC4_UNLOCK() _thread_arc4_unlock()
-
-extern volatile sig_atomic_t _rs_forked;
-
-__END_DECLS
diff --git a/libc/stdio/glue.h b/libc/stdio/glue.h
deleted file mode 100644
index cb1d182..0000000
--- a/libc/stdio/glue.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/*	$OpenBSD: glue.h,v 1.4 2004/01/11 21:39:51 millert Exp $	*/
-
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-
-__BEGIN_DECLS
-
-/*
- * The first few FILEs are statically allocated; others are dynamically
- * allocated and linked in via this glue structure.
- */
-struct glue {
-	struct	glue *next;
-	int	niobs;
-	FILE	*iobs;
-};
-
-/* This was referenced by a couple of different pieces of middleware and the Crystax NDK. */
-__LIBC32_LEGACY_PUBLIC__ extern struct glue __sglue;
-
-__END_DECLS
diff --git a/libc/stdio/local.h b/libc/stdio/local.h
index a60468e..2d88a14 100644
--- a/libc/stdio/local.h
+++ b/libc/stdio/local.h
@@ -38,10 +38,6 @@
 #include <stdbool.h>
 #include <wchar.h>
 
-#if defined(__cplusplus)  // Until we fork all of stdio...
-#include "private/bionic_fortify.h"
-#endif
-
 /*
  * Information local to this implementation of stdio,
  * in particular, macros and private variables.
@@ -84,29 +80,37 @@
   unsigned char* _up; /* saved _p when _p is doing ungetc data */
   int _ur;            /* saved _r when _r is counting ungetc data */
 
-  /* tricks to meet minimum requirements even when malloc() fails */
-  unsigned char _ubuf[3]; /* guarantee an ungetc() buffer */
-  unsigned char _nbuf[1]; /* guarantee a getc() buffer */
+  // Tricks to avoid calling malloc() in common cases.
+  unsigned char _ubuf[3]; // Guarantee an ungetc() buffer.
+  unsigned char _nbuf[1]; // Guarantee a getc() buffer.
 
   /* separate buffer for fgetln() when line crosses buffer boundary */
   struct __sbuf _lb; /* buffer for fgetln() */
 
-  /* Unix stdio files get aligned to block boundaries on fseek() */
-  int _blksize; /* stat.st_blksize (may be != _bf._size) */
-
-  fpos_t _unused_0;  // This was the `_offset` field (see below).
-
-  // Do not add new fields here. (Or remove or change the size of any above.)
-  // Although bionic currently exports `stdin`, `stdout`, and `stderr` symbols,
-  // that still hasn't made it to the NDK. All NDK-built apps index directly
-  // into an array of this struct (which was in <stdio.h> historically), so if
-  // you need to make any changes, they need to be in the `__sfileext` struct
-  // below, and accessed via `_EXT`.
+  int _unused_0;  // This was the `_blksize` field (see below).
+  fpos_t _unused_1;  // This was the `_offset` field (see below).
 };
 
+// Do not add/remove/change the size of any fields anywhere in this struct.
+//
+// Although bionic exports `stdin`, `stdout`, and `stderr` symbols
+// from API 23 on, apps supporting earlier APIs index directly into `__sF[]`
+// which is an array of this struct (which was in <stdio.h> historically).
+// That means that if the size of this struct changes, `stdout` and `stderr`
+// are broken.
+//
+// If you need to make any changes, they need to be in the `__sfileext` struct
+// below, and accessed via `_EXT()`.
+#if defined(__LP64__)
+_Static_assert(sizeof(struct __sFILE) == 152, "__sFILE changed size");
+#else
+_Static_assert(sizeof(struct __sFILE) == 84, "__sFILE changed size");
+#endif
+
 /* minimal requirement of SUSv2 */
 #define WCIO_UNGETWC_BUFSIZE 1
 
+// TODO: this struct isn't useful on its own; inline directly into __sfileext.
 struct wchar_io_data {
   mbstate_t wcio_mbstate_in;
   mbstate_t wcio_mbstate_out;
@@ -114,7 +118,7 @@
   wchar_t wcio_ungetwc_buf[WCIO_UNGETWC_BUFSIZE];
   size_t wcio_ungetwc_inbuf;
 
-  int wcio_mode; /* orientation */
+  int orientation;
 };
 
 struct __sfileext {
@@ -148,21 +152,16 @@
 #define __SRW 0x0010   // Was opened for reading & writing.
 #define __SEOF 0x0020  // Found EOF.
 #define __SERR 0x0040  // Found error.
-#define __SMBF 0x0080  // `_buf` is from malloc.
+#define __SMBF 0x0080  // `_bf` is from malloc.
 // #define __SAPP 0x0100 --- historical (fdopen()ed in append mode).
 #define __SSTR 0x0200  // This is an sprintf/snprintf string.
 // #define __SOPT 0x0400 --- historical (do fseek() optimization).
 // #define __SNPT 0x0800 --- historical (do not do fseek() optimization).
 // #define __SOFF 0x1000 --- historical (set iff _offset is in fact correct).
-// #define __SMOD 0x2000 --- historical (set iff fgetln modified _p text).
+// #define __SMOD 0x2000 --- historical (set iff fgetln() returned _bf pointer).
 #define __SALC 0x4000  // Allocate string space dynamically.
 #define __SIGN 0x8000  // Ignore this file in _fwalk.
 
-// TODO: remove remaining references to these obsolete flags (see above).
-#define __SMOD 0
-#define __SNPT 0
-#define __SOPT 0
-
 #define _EXT(fp) __BIONIC_CAST(reinterpret_cast, struct __sfileext*, (fp)->_ext._base)
 
 #define _UB(fp) _EXT(fp)->_ub
@@ -198,9 +197,12 @@
 __LIBC32_LEGACY_PUBLIC__ int __sclose(void*);
 __LIBC32_LEGACY_PUBLIC__ int _fwalk(int (*)(FILE*));
 
+/* This was referenced by a couple of different pieces of middleware and the Crystax NDK. */
+__LIBC32_LEGACY_PUBLIC__ extern struct glue __sglue;
+
 off64_t __sseek64(void*, off64_t, int);
 int __sflush_locked(FILE*);
-int __swhatbuf(FILE*, size_t*, int*);
+void __swhatbuf(FILE*, size_t*, int*);
 wint_t __fgetwc_unlock(FILE*);
 wint_t __ungetwc(wint_t, FILE*);
 int __vfprintf(FILE*, const char*, va_list);
@@ -254,11 +256,6 @@
 size_t parsefloat(FILE*, char*, char*);
 size_t wparsefloat(FILE*, wchar_t*, wchar_t*);
 
-// Check a FILE* isn't nullptr, so we can emit a clear diagnostic message
-// instead of just crashing with SIGSEGV.
-#define CHECK_FP(fp) \
-  if (fp == nullptr) __fortify_fatal("%s: null FILE*", __FUNCTION__)
-
 /*
  * Floating point scanf/printf (input/output) definitions.
  */
@@ -284,25 +281,25 @@
 char* __hldtoa(long double, const char*, int, int*, int*, char**);
 char* __ldtoa(long double*, int, int, int*, int*, char**);
 
-#define WCIO_GET(fp) (_EXT(fp) ? &(_EXT(fp)->_wcio) : NULL)
+#define WCIO_GET(fp) (&(_EXT(fp)->_wcio))
 
 #define ORIENT_BYTES (-1)
 #define ORIENT_UNKNOWN 0
 #define ORIENT_CHARS 1
 
-#define _SET_ORIENTATION(fp, mode)                                              \
-  do {                                                                          \
-    struct wchar_io_data* _wcio = WCIO_GET(fp);                                 \
-    if (_wcio && _wcio->wcio_mode == ORIENT_UNKNOWN) _wcio->wcio_mode = (mode); \
+#define _SET_ORIENTATION(fp, mode) \
+  do { \
+    struct wchar_io_data* _wcio = WCIO_GET(fp); \
+    if (_wcio->orientation == ORIENT_UNKNOWN) { \
+      _wcio->orientation = (mode > 0) ? ORIENT_CHARS : ORIENT_BYTES; \
+     } \
   } while (0)
 
-#define WCIO_FREE(fp)                           \
-  do {                                          \
+#define WCIO_FREE(fp) \
+  do { \
     struct wchar_io_data* _wcio = WCIO_GET(fp); \
-    if (_wcio) {                                \
-      _wcio->wcio_mode = ORIENT_UNKNOWN;        \
-      _wcio->wcio_ungetwc_inbuf = 0;            \
-    }                                           \
+    _wcio->orientation = ORIENT_UNKNOWN; \
+    _wcio->wcio_ungetwc_inbuf = 0; \
   } while (0)
 
 __END_DECLS
diff --git a/libc/stdio/printf_common.h b/libc/stdio/printf_common.h
index 653bba2..d1d96c2 100644
--- a/libc/stdio/printf_common.h
+++ b/libc/stdio/printf_common.h
@@ -50,6 +50,8 @@
 
 #include <platform/bionic/macros.h>
 
+#include "private/bionic_fortify.h"
+
 #include "fvwrite.h"
 #include "gdtoa.h"
 #include "local.h"
@@ -478,7 +480,7 @@
         goto rflag;
       case 'C':
         flags |= LONGINT;
-        __BIONIC_FALLTHROUGH;
+        [[fallthrough]];
       case 'c':
         if (flags & LONGINT)
           ADDTYPE(T_WINT);
@@ -487,7 +489,7 @@
         break;
       case 'D':
         flags |= LONGINT;
-        __BIONIC_FALLTHROUGH;
+        [[fallthrough]];
       case 'd':
       case 'i':
         ADDSARG();
@@ -509,7 +511,7 @@
         __fortify_fatal("%%n not allowed on Android");
       case 'O':
         flags |= LONGINT;
-        __BIONIC_FALLTHROUGH;
+        [[fallthrough]];
       case 'o':
         ADDUARG();
         break;
@@ -518,13 +520,13 @@
         break;
       case 'S':
         flags |= LONGINT;
-        __BIONIC_FALLTHROUGH;
+        [[fallthrough]];
       case 's':
         ADDTYPE((flags & LONGINT) ? TP_WCHAR : TP_CHAR);
         break;
       case 'U':
         flags |= LONGINT;
-        __BIONIC_FALLTHROUGH;
+        [[fallthrough]];
       case 'u':
       case 'X':
       case 'x':
diff --git a/libc/stdio/stdio.cpp b/libc/stdio/stdio.cpp
index a5f2f81..8e02644 100644
--- a/libc/stdio/stdio.cpp
+++ b/libc/stdio/stdio.cpp
@@ -1,4 +1,3 @@
-/*	$OpenBSD: findfp.c,v 1.15 2013/12/17 16:33:27 deraadt Exp $ */
 /*-
  * Copyright (c) 1990, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -50,15 +49,18 @@
 
 #include <async_safe/log.h>
 
-#include "glue.h"
 #include "local.h"
 #include "private/ErrnoRestorer.h"
 #include "private/FdPath.h"
 #include "private/__bionic_get_shell_path.h"
 #include "private/bionic_fortify.h"
-#include "private/thread_private.h"
 
-#define	NDYNAMIC 10		/* add ten more whenever necessary */
+// Check a FILE* isn't nullptr, so we can emit a clear diagnostic message
+// instead of just crashing with SIGSEGV.
+#define CHECK_FP(fp) \
+  if (fp == nullptr) __fortify_fatal("%s: null FILE*", __FUNCTION__)
+
+#define NDYNAMIC 10  /* add ten more whenever necessary */
 
 #define PRINTF_IMPL(expr) \
     va_list ap; \
@@ -116,6 +118,14 @@
                                         reinterpret_cast<uint64_t>(fp));
 }
 
+// The first few FILEs are statically allocated; others are dynamically
+// allocated and linked in via this glue structure.
+// TODO: replace this with an intrusive doubly-linked list of the FILE*s (via _EXT())
+struct glue {
+  struct glue* next;
+  int niobs;
+  FILE* iobs;
+};
 struct glue __sglue = { nullptr, 3, __sF };
 static struct glue* lastglue = &__sglue;
 
@@ -164,48 +174,48 @@
  * Find a free FILE for fopen et al.
  */
 FILE* __sfp(void) {
-	FILE *fp;
-	int n;
-	struct glue *g;
+  FILE *fp;
+  int n;
+  struct glue *g;
 
-	pthread_mutex_lock(&__stdio_mutex);
-	for (g = &__sglue; g != nullptr; g = g->next) {
-		for (fp = g->iobs, n = g->niobs; --n >= 0; fp++)
-			if (fp->_flags == 0)
-				goto found;
-	}
+  pthread_mutex_lock(&__stdio_mutex);
+  for (g = &__sglue; g != nullptr; g = g->next) {
+    for (fp = g->iobs, n = g->niobs; --n >= 0; fp++) {
+      if (fp->_flags == 0) goto found;
+    }
+  }
 
-	/* release lock while mallocing */
-	pthread_mutex_unlock(&__stdio_mutex);
-	if ((g = moreglue(NDYNAMIC)) == nullptr) return nullptr;
-	pthread_mutex_lock(&__stdio_mutex);
-	lastglue->next = g;
-	lastglue = g;
-	fp = g->iobs;
+  /* release lock while mallocing */
+  pthread_mutex_unlock(&__stdio_mutex);
+  if ((g = moreglue(NDYNAMIC)) == nullptr) return nullptr;
+  pthread_mutex_lock(&__stdio_mutex);
+  lastglue->next = g;
+  lastglue = g;
+  fp = g->iobs;
 found:
-	fp->_flags = 1;		/* reserve this slot; caller sets real flags */
-	pthread_mutex_unlock(&__stdio_mutex);
-	fp->_p = nullptr;		/* no current pointer */
-	fp->_w = 0;		/* nothing to read or write */
-	fp->_r = 0;
-	fp->_bf._base = nullptr;	/* no buffer */
-	fp->_bf._size = 0;
-	fp->_lbfsize = 0;	/* not line buffered */
-	fp->_file = -1;		/* no file */
+  fp->_flags = 1;  /* reserve this slot; caller sets real flags */
+  pthread_mutex_unlock(&__stdio_mutex);
+  fp->_p = nullptr;  /* no current pointer */
+  fp->_w = 0;  /* nothing to read or write */
+  fp->_r = 0;
+  fp->_bf._base = nullptr;  /* no buffer */
+  fp->_bf._size = 0;
+  fp->_lbfsize = 0;  /* not line buffered */
+  fp->_file = -1;  /* no file */
 
-	fp->_lb._base = nullptr;	/* no line buffer */
-	fp->_lb._size = 0;
+  fp->_lb._base = nullptr;  /* no line buffer */
+  fp->_lb._size = 0;
 
-	memset(_EXT(fp), 0, sizeof(struct __sfileext));
-	_EXT(fp)->_lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
-	_EXT(fp)->_caller_handles_locking = false;
+  memset(_EXT(fp), 0, sizeof(struct __sfileext));
+  _EXT(fp)->_lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
+  _EXT(fp)->_caller_handles_locking = false;
 
-	// Caller sets cookie, _read/_write etc.
-	// We explicitly clear _seek and _seek64 to prevent subtle bugs.
-	fp->_seek = nullptr;
-	_EXT(fp)->_seek64 = nullptr;
+  // Caller sets cookie, _read/_write etc.
+  // We explicitly clear _seek and _seek64 to prevent subtle bugs.
+  fp->_seek = nullptr;
+  _EXT(fp)->_seek64 = nullptr;
 
-	return fp;
+  return fp;
 }
 
 int _fwalk(int (*callback)(FILE*)) {
@@ -226,6 +236,56 @@
   _fwalk(__sflush);
 }
 
+/*
+ * Allocate a file buffer, or switch to unbuffered I/O.
+ * Per the ANSI C standard, ALL tty devices default to line buffered.
+ */
+void __smakebuf(FILE* fp) {
+  unsigned char *p;
+  int flags = 0;
+  size_t size;
+  int couldbetty;
+
+  if (fp->_flags & __SNBF) {
+    fp->_bf._base = fp->_p = fp->_nbuf;
+    fp->_bf._size = 1;
+    return;
+  }
+  __swhatbuf(fp, &size, &couldbetty);
+  if ((p = static_cast<unsigned char*>(malloc(size))) == NULL) {
+    fp->_flags |= __SNBF;
+    fp->_bf._base = fp->_p = fp->_nbuf;
+    fp->_bf._size = 1;
+    return;
+  }
+  flags |= __SMBF;
+  fp->_bf._base = fp->_p = p;
+  fp->_bf._size = size;
+  if (couldbetty && isatty(fp->_file)) flags |= __SLBF;
+  fp->_flags |= flags;
+}
+
+/*
+ * Internal routine to determine `proper' buffering for a file.
+ */
+void __swhatbuf(FILE* fp, size_t* bufsize, int* couldbetty) {
+  struct stat st;
+  if (fp->_file < 0 || fstat(fp->_file, &st) == -1) {
+    *couldbetty = 0;
+    *bufsize = BUFSIZ;
+    return;
+  }
+
+  /* could be a tty iff it is a character device */
+  *couldbetty = S_ISCHR(st.st_mode);
+  if (st.st_blksize == 0) {
+    *bufsize = BUFSIZ;
+    return;
+  }
+
+  *bufsize = st.st_blksize;
+}
+
 static FILE* __FILE_init(FILE* fp, int fd, int flags) {
   if (fp == nullptr) return nullptr;
 
@@ -403,7 +463,9 @@
 }
 __strong_alias(freopen64, freopen);
 
-static int __FILE_close(FILE* fp) {
+int fclose(FILE* fp) {
+  CHECK_FP(fp);
+
   if (fp->_flags == 0) {
     // Already freed!
     errno = EBADF;
@@ -438,11 +500,7 @@
   fp->_flags = 0;
   return r;
 }
-
-int fclose(FILE* fp) {
-  CHECK_FP(fp);
-  return __FILE_close(fp);
-}
+__strong_alias(pclose, fclose);
 
 int fileno_unlocked(FILE* fp) {
   CHECK_FP(fp);
@@ -623,7 +681,7 @@
   if (HASUB(fp)) FREEUB(fp);
   fp->_p = fp->_bf._base;
   fp->_r = 0;
-  /* fp->_w = 0; */	/* unnecessary (I think...) */
+  /* fp->_w = 0; */    /* unnecessary (I think...) */
   fp->_flags &= ~__SEOF;
   return 0;
 }
@@ -760,6 +818,17 @@
   return getc_unlocked(fp);
 }
 
+char* fgetln(FILE* fp, size_t* length_ptr) {
+  CHECK_FP(fp);
+  ScopedFileLock sfl(fp);
+  // Implementing fgetln() in terms of getdelim() means lines are actually always NUL terminated.
+  // We could explicitly overwrite the NUL to be "bug compatible", but that seems silly?
+  ssize_t n = getdelim(reinterpret_cast<char**>(&fp->_lb._base), &fp->_lb._size, '\n', fp);
+  if (n <= 0) return nullptr;
+  *length_ptr = n;
+  return reinterpret_cast<char*>(fp->_lb._base);
+}
+
 char* fgets(char* buf, int n, FILE* fp) {
   CHECK_FP(fp);
   ScopedFileLock sfl(fp);
@@ -966,6 +1035,115 @@
   return setvbuf(fp, nullptr, _IOLBF, 0);
 }
 
+/*
+ * Set one of the three kinds of buffering, optionally including
+ * a buffer.
+ */
+int setvbuf(FILE* fp, char* buf, int mode, size_t size) {
+  int ret, flags;
+  size_t iosize;
+  int ignored;
+
+  /*
+   * Verify arguments.  The `int' limit on `size' is due to this
+   * particular implementation.  Note, buf and size are ignored
+   * when setting _IONBF.
+   */
+  if (mode != _IONBF)
+    if ((mode != _IOFBF && mode != _IOLBF) || size > INT_MAX)
+      return (EOF);
+
+  /*
+   * Write current buffer, if any.  Discard unread input (including
+   * ungetc data), cancel line buffering, and free old buffer if
+   * malloc()ed.  We also clear any eof condition, as if this were
+   * a seek.
+   */
+  FLOCKFILE(fp);
+  ret = 0;
+  (void)__sflush(fp);
+  if (HASUB(fp)) FREEUB(fp);
+  WCIO_FREE(fp);
+  fp->_r = fp->_lbfsize = 0;
+  flags = fp->_flags;
+  if (flags & __SMBF) free(fp->_bf._base);
+    flags &= ~(__SLBF | __SNBF | __SMBF | __SEOF);
+
+  /* If setting unbuffered mode, skip all the hard work. */
+  if (mode == _IONBF) goto nbf;
+
+  /*
+   * Note that size == 0 is unspecified behavior:
+   *
+   * musl returns an error,
+   * glibc interprets it as "unbuffered",
+   * macOS' man page says it interprets it as "defer allocation" --
+   * the default if you hadn't called setvbuf() --
+   * but it actually seems to have the same BSD behavior we currently see here.
+   *
+   * TODO: investigate whether this whole "i/o size" thing is actually useful.
+   */
+  __swhatbuf(fp, &iosize, &ignored);
+  if (size == 0) {
+    buf = NULL; /* force local allocation */
+    size = iosize;
+  }
+
+  /* Allocate buffer if needed. */
+  if (buf == NULL) {
+    if ((buf = static_cast<char*>(malloc(size))) == NULL) {
+      /*
+       * Unable to honor user's request.  We will return
+       * failure, but try again with file system size.
+       */
+      ret = EOF;
+      if (size != iosize) {
+        size = iosize;
+        buf = static_cast<char*>(malloc(size));
+      }
+    }
+    if (buf == NULL) {
+      /* No luck; switch to unbuffered I/O. */
+nbf:
+      fp->_flags = flags | __SNBF;
+      fp->_w = 0;
+      fp->_bf._base = fp->_p = fp->_nbuf;
+      fp->_bf._size = 1;
+      FUNLOCKFILE(fp);
+      return (ret);
+    }
+    flags |= __SMBF;
+  }
+
+  /*
+   * Fix up the FILE fields, and set __cleanup for output flush on
+   * exit (since we are buffered in some way).
+   */
+  if (mode == _IOLBF) flags |= __SLBF;
+  fp->_flags = flags;
+  fp->_bf._base = fp->_p = reinterpret_cast<unsigned char*>(buf);
+  fp->_bf._size = size;
+  /* fp->_lbfsize is still 0 */
+  if (flags & __SWR) {
+    /*
+     * Begin or continue writing: see __swsetup().  Note
+     * that __SNBF is impossible (it was handled earlier).
+     */
+    if (flags & __SLBF) {
+      fp->_w = 0;
+      fp->_lbfsize = -fp->_bf._size;
+    } else {
+      fp->_w = size;
+    }
+  } else {
+    /* begin/continue reading, or stay in intermediate state */
+    fp->_w = 0;
+  }
+  FUNLOCKFILE(fp);
+
+  return (ret);
+}
+
 int snprintf(char* s, size_t n, const char* fmt, ...) {
   PRINTF_IMPL(vsnprintf(s, n, fmt, ap));
 }
@@ -1254,11 +1432,6 @@
   return fp;
 }
 
-int pclose(FILE* fp) {
-  CHECK_FP(fp);
-  return __FILE_close(fp);
-}
-
 void flockfile(FILE* fp) {
   CHECK_FP(fp);
   pthread_mutex_lock(&_EXT(fp)->_lock);
@@ -1276,6 +1449,13 @@
   pthread_mutex_unlock(&_EXT(fp)->_lock);
 }
 
+int fwide(FILE* fp, int mode) {
+  CHECK_FP(fp);
+  ScopedFileLock sfl(fp);
+  if (mode != 0) _SET_ORIENTATION(fp, mode);
+  return WCIO_GET(fp)->orientation;
+}
+
 namespace {
 
 namespace phony {
diff --git a/libc/stdio/vfprintf.cpp b/libc/stdio/vfprintf.cpp
index 354317c..a4ee4bf 100644
--- a/libc/stdio/vfprintf.cpp
+++ b/libc/stdio/vfprintf.cpp
@@ -209,7 +209,7 @@
         if (width >= 0) goto rflag;
         if (width == INT_MIN) goto overflow;
         width = -width;
-        __BIONIC_FALLTHROUGH;
+        [[fallthrough]];
       case '-':
         flags |= LADJUST;
         goto rflag;
@@ -314,7 +314,7 @@
         goto nosign;
       case 'C':
         flags |= LONGINT;
-        __BIONIC_FALLTHROUGH;
+        [[fallthrough]];
       case 'c':
         if (flags & LONGINT) {
           mbstate_t mbs;
@@ -336,7 +336,7 @@
         break;
       case 'D':
         flags |= LONGINT;
-        __BIONIC_FALLTHROUGH;
+        [[fallthrough]];
       case 'd':
       case 'i':
         _umax = SARG();
@@ -481,7 +481,7 @@
         goto string;
       case 'O':
         flags |= LONGINT;
-        __BIONIC_FALLTHROUGH;
+        [[fallthrough]];
       case 'o':
         _umax = UARG();
         base = OCT;
@@ -501,7 +501,7 @@
         goto nosign;
       case 'S':
         flags |= LONGINT;
-        __BIONIC_FALLTHROUGH;
+        [[fallthrough]];
       case 's':
         if (flags & LONGINT) {
           wchar_t* wcp;
@@ -534,7 +534,7 @@
         break;
       case 'U':
         flags |= LONGINT;
-        __BIONIC_FALLTHROUGH;
+        [[fallthrough]];
       case 'u':
         _umax = UARG();
         base = DEC;
diff --git a/libc/stdio/vfscanf.cpp b/libc/stdio/vfscanf.cpp
index 92ff541..1242963 100644
--- a/libc/stdio/vfscanf.cpp
+++ b/libc/stdio/vfscanf.cpp
@@ -149,7 +149,7 @@
 
       case 'D': /* compat */
         flags |= LONG;
-        __BIONIC_FALLTHROUGH;
+        [[fallthrough]];
       case 'd':
         c = CT_INT;
         base = 10;
@@ -162,7 +162,7 @@
 
       case 'O': /* compat */
         flags |= LONG;
-        __BIONIC_FALLTHROUGH;
+        [[fallthrough]];
       case 'o':
         c = CT_INT;
         flags |= UNSIGNED;
@@ -559,7 +559,7 @@
                 goto ok;
               }
               // No? Fall through and see if it's a hex digit instead then...
-              __BIONIC_FALLTHROUGH;
+              [[fallthrough]];
             case '1':
             case '2':
             case '3':
diff --git a/libc/stdio/vfwprintf.cpp b/libc/stdio/vfwprintf.cpp
index 89e889e..5ba6379 100644
--- a/libc/stdio/vfwprintf.cpp
+++ b/libc/stdio/vfwprintf.cpp
@@ -212,7 +212,7 @@
         if (width >= 0) goto rflag;
         if (width == INT_MIN) goto overflow;
         width = -width;
-        __BIONIC_FALLTHROUGH;
+        [[fallthrough]];
       case '-':
         flags |= LADJUST;
         goto rflag;
@@ -317,7 +317,7 @@
         goto nosign;
       case 'C':
         flags |= LONGINT;
-        __BIONIC_FALLTHROUGH;
+        [[fallthrough]];
       case 'c':
         if (flags & LONGINT)
           *(cp = buf) = (wchar_t)GETARG(wint_t);
@@ -328,7 +328,7 @@
         break;
       case 'D':
         flags |= LONGINT;
-        __BIONIC_FALLTHROUGH;
+        [[fallthrough]];
       case 'd':
       case 'i':
         _umax = SARG();
@@ -470,7 +470,7 @@
         print_utf8(strerror_r(caller_errno, reinterpret_cast<char*>(buf), sizeof(buf)), prec);
       case 'O':
         flags |= LONGINT;
-        __BIONIC_FALLTHROUGH;
+        [[fallthrough]];
       case 'o':
         _umax = UARG();
         base = OCT;
@@ -490,7 +490,7 @@
         goto nosign;
       case 'S':
         flags |= LONGINT;
-        __BIONIC_FALLTHROUGH;
+        [[fallthrough]];
       case 's':
         if (flags & LONGINT) {
           if ((cp = GETARG(wchar_t*)) == nullptr) cp = const_cast<wchar_t*>(L"(null)");
@@ -512,7 +512,7 @@
         break;
       case 'U':
         flags |= LONGINT;
-        __BIONIC_FALLTHROUGH;
+        [[fallthrough]];
       case 'u':
         _umax = UARG();
         base = DEC;
diff --git a/libc/stdio/vfwscanf.cpp b/libc/stdio/vfwscanf.cpp
index 21d1783..ba17652 100644
--- a/libc/stdio/vfwscanf.cpp
+++ b/libc/stdio/vfwscanf.cpp
@@ -71,8 +71,8 @@
   return !member_result;
 }
 
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wframe-larger-than="
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wframe-larger-than="
 
 /*
  * vfwscanf
@@ -194,7 +194,7 @@
 
       case 'D': /* compat */
         flags |= LONG;
-        __BIONIC_FALLTHROUGH;
+        [[fallthrough]];
       case 'd':
         c = CT_INT;
         base = 10;
@@ -207,7 +207,7 @@
 
       case 'O': /* compat */
         flags |= LONG;
-        __BIONIC_FALLTHROUGH;
+        [[fallthrough]];
       case 'o':
         c = CT_INT;
         flags |= UNSIGNED;
@@ -465,7 +465,7 @@
                 goto ok;
               }
               // No? Fall through and see if it's a hex digit instead then...
-              __BIONIC_FALLTHROUGH;
+              [[fallthrough]];
             case '1':
             case '2':
             case '3':
@@ -601,4 +601,4 @@
 match_failure:
   return (nassigned);
 }
-#pragma GCC diagnostic pop
+#pragma clang diagnostic pop
diff --git a/libc/system_properties/include/system_properties/prop_area.h b/libc/system_properties/include/system_properties/prop_area.h
index 089cf52..6bf0331 100644
--- a/libc/system_properties/include/system_properties/prop_area.h
+++ b/libc/system_properties/include/system_properties/prop_area.h
@@ -119,7 +119,7 @@
     // serial is the same: if it is, the dirty backup area hasn't been
     // reused for something else and we can complete the
     // read immediately.
-    bytes_used_ +=  __BIONIC_ALIGN(PROP_VALUE_MAX, sizeof(uint_least32_t));
+    bytes_used_ +=  __builtin_align_up(PROP_VALUE_MAX, sizeof(uint_least32_t));
   }
 
   const prop_info* find(const char* name);
diff --git a/libc/system_properties/prop_area.cpp b/libc/system_properties/prop_area.cpp
index faa3edf..58b9970 100644
--- a/libc/system_properties/prop_area.cpp
+++ b/libc/system_properties/prop_area.cpp
@@ -148,7 +148,7 @@
 }
 
 void* prop_area::allocate_obj(const size_t size, uint_least32_t* const off) {
-  const size_t aligned = __BIONIC_ALIGN(size, sizeof(uint_least32_t));
+  const size_t aligned = __builtin_align_up(size, sizeof(uint_least32_t));
   if (bytes_used_ + aligned > pa_data_size_) {
     return nullptr;
   }
diff --git a/libc/system_properties/system_properties.cpp b/libc/system_properties/system_properties.cpp
index e0d38a8..6924ff1 100644
--- a/libc/system_properties/system_properties.cpp
+++ b/libc/system_properties/system_properties.cpp
@@ -305,23 +305,27 @@
   if (have_override) {
     memcpy(override_pa->dirty_backup_area(), override_pi->value, old_len + 1);
   }
-  atomic_thread_fence(memory_order_release);
   serial |= 1;
-  atomic_store_explicit(&pi->serial, serial, memory_order_relaxed);
-  strlcpy(pi->value, value, len + 1);
+  atomic_store_explicit(&pi->serial, serial, memory_order_release);
+  atomic_thread_fence(memory_order_release);  // Order preceding store w.r.t. memcpy().
+  memcpy(pi->value, value, len + 1);
+  // TODO: Eventually replace the above with something like atomic_store_per_byte_memcpy from
+  // wg21.link/p1478 . This is needed for the preceding memcpy and the reader-side copies as well.
+  // In general, memcpy uses near atomic_thread_fence() are suspect.
   if (have_override) {
     atomic_store_explicit(&override_pi->serial, serial, memory_order_relaxed);
-    strlcpy(override_pi->value, value, len + 1);
+    memcpy(override_pi->value, value, len + 1);
   }
   // Now the primary value property area is up-to-date. Let readers know that they should
   // look at the property value instead of the backup area.
-  atomic_thread_fence(memory_order_release);
   int new_serial = (len << 24) | ((serial + 1) & 0xffffff);
-  atomic_store_explicit(&pi->serial, new_serial, memory_order_relaxed);
+  atomic_store_explicit(&pi->serial, new_serial, memory_order_release);
   if (have_override) {
     atomic_store_explicit(&override_pi->serial, new_serial, memory_order_relaxed);
   }
-  __futex_wake(&pi->serial, INT32_MAX);  // Fence by side effect
+  // Implicitly includes a fence to ensure the serial number update becomes visible before
+  // we reuse the backup area the next time.
+  __futex_wake(&pi->serial, INT32_MAX);
   atomic_store_explicit(serial_pa->serial(),
                         atomic_load_explicit(serial_pa->serial(), memory_order_relaxed) + 1,
                         memory_order_release);
@@ -400,7 +404,7 @@
       // before any readers are started. Check that only init or root can write appcompat props.
       CHECK(getpid() == 1 || getuid() == 0);
       atomic_thread_fence(memory_order_release);
-      strlcpy(other_pi->value, value, valuelen + 1);
+      memcpy(other_pi->value, value, valuelen + 1);
     }
   }
 
diff --git a/libc/tools/gensyscalls.py b/libc/tools/gensyscalls.py
index d371b72..a93506d 100755
--- a/libc/tools/gensyscalls.py
+++ b/libc/tools/gensyscalls.py
@@ -4,15 +4,7 @@
 # the header files listing all available system calls, and the
 # makefiles used to build all the stubs.
 
-import atexit
-import filecmp
-import glob
-import re
-import shutil
-import stat
-import string
 import sys
-import tempfile
 
 
 SupportedArchitectures = [ "arm", "arm64", "riscv64", "x86", "x86_64" ]
@@ -152,25 +144,24 @@
 """
 
 
-def param_uses_64bits(param):
+def param_uses_64bits_on_ilp32(param):
     """Returns True iff a syscall parameter description corresponds
        to a 64-bit type."""
-    param = param.strip()
-    # First, check that the param type begins with one of the known
-    # 64-bit types.
-    if not ( \
-       param.startswith("int64_t") or param.startswith("uint64_t") or \
-       param.startswith("loff_t") or param.startswith("off64_t") or \
-       param.startswith("long long") or param.startswith("unsigned long long") or
-       param.startswith("signed long long") ):
-           return False
+    # Canonicalize whitespace so there's no leading/trailing spaces,
+    # and there's never more than one contiguous space.
+    param = ' '.join(param.split())
 
-    # Second, check that there is no pointer type here
+    # On ilp32 pointers are always 32 bits.
     if param.find("*") >= 0:
         return False
 
-    # Ok
-    return True
+    # Since this script can't resolve typedefs to their underlying types,
+    # we have to list all the names used for 64-bit types.
+    return ( \
+       param.startswith("int64_t") or param.startswith("uint64_t") or \
+       param.startswith("loff_t") or param.startswith("off64_t") or \
+       param.startswith("long long") or param.startswith("unsigned long long") or \
+       param.startswith("signed long long"))
 
 
 def count_param_registers_arm32(params):
@@ -189,7 +180,7 @@
    """
     count = 0
     for param in params:
-        if param_uses_64bits(param):
+        if param_uses_64bits_on_ilp32(param):
             if (count & 1) != 0:
                 count += 1
             count += 2
@@ -201,7 +192,7 @@
 def count_param_registers_x86(params):
     count = 0
     for param in params:
-        if param_uses_64bits(param):
+        if param_uses_64bits_on_ilp32(param):
             count += 2
         else:
             count += 1
@@ -217,12 +208,11 @@
         return "__NR_%s" % (name)
 
 
-def add_footer(pointer_length, stub, syscall):
-    # Add any aliases for this syscall.
-    aliases = syscall["aliases"]
-    for alias in aliases:
-        stub += "\nALIAS_SYMBOL(%s, %s)\n" % (alias, syscall["func"])
-    return stub
+def aliases(syscall):
+    result = ''
+    for alias in syscall["aliases"]:
+        result += "ALIAS_SYMBOL(%s, %s)\n" % (alias, syscall["func"])
+    return result
 
 
 def arm_genstub(syscall):
@@ -420,6 +410,12 @@
                     E("invalid syscall architecture '%s' in '%s'" % (arch, line))
                     return
 
+        if socketcall_id >= 0:
+            for arch in SupportedArchitectures:
+                if arch != 'x86' and arch in t:
+                    E("socketcall is x86-only")
+                    return
+
         self.syscalls.append(t)
 
     def parse_open_file(self, fp):
@@ -445,25 +441,22 @@
         syscall["__NR_name"] = make__NR_name(syscall["name"])
 
         if "arm" in syscall:
-            syscall["asm-arm"] = add_footer(32, arm_genstub(syscall), syscall)
+            syscall["asm-arm"] = arm_genstub(syscall) + aliases(syscall)
 
         if "arm64" in syscall:
-            syscall["asm-arm64"] = add_footer(64, arm64_genstub(syscall), syscall)
+            syscall["asm-arm64"] = arm64_genstub(syscall) + aliases(syscall)
 
         if "riscv64" in syscall:
-            syscall["asm-riscv64"] = add_footer(64, riscv64_genstub(syscall), syscall)
+            syscall["asm-riscv64"] = riscv64_genstub(syscall) + aliases(syscall)
 
         if "x86" in syscall:
             if syscall["socketcall_id"] >= 0:
-                syscall["asm-x86"] = add_footer(32, x86_genstub_socketcall(syscall), syscall)
+                syscall["asm-x86"] = x86_genstub_socketcall(syscall) + aliases(syscall)
             else:
-                syscall["asm-x86"] = add_footer(32, x86_genstub(syscall), syscall)
-        elif syscall["socketcall_id"] >= 0:
-            E("socketcall_id for dispatch syscalls is only supported for x86 in '%s'" % t)
-            return
+                syscall["asm-x86"] = x86_genstub(syscall) + aliases(syscall)
 
         if "x86_64" in syscall:
-            syscall["asm-x86_64"] = add_footer(64, x86_64_genstub(syscall), syscall)
+            syscall["asm-x86_64"] = x86_64_genstub(syscall) + aliases(syscall)
 
     print("/* Generated by gensyscalls.py. Do not edit. */\n")
     print("#include <private/bionic_asm.h>\n")
diff --git a/libc/tzcode/asctime.c b/libc/tzcode/asctime.c
deleted file mode 100644
index 4cdfd13..0000000
--- a/libc/tzcode/asctime.c
+++ /dev/null
@@ -1,131 +0,0 @@
-/* asctime and asctime_r a la POSIX and ISO C, except pad years before 1000.  */
-
-/*
-** This file is in the public domain, so clarified as of
-** 1996-06-05 by Arthur David Olson.
-*/
-
-/*
-** Avoid the temptation to punt entirely to strftime;
-** the output of strftime is supposed to be locale specific
-** whereas the output of asctime is supposed to be constant.
-*/
-
-/*LINTLIBRARY*/
-
-#include "private.h"
-#include <stdio.h>
-
-/*
-** All years associated with 32-bit time_t values are exactly four digits long;
-** some years associated with 64-bit time_t values are not.
-** Vintage programs are coded for years that are always four digits long
-** and may assume that the newline always lands in the same place.
-** For years that are less than four digits, we pad the output with
-** leading zeroes to get the newline in the traditional place.
-** The -4 ensures that we get four characters of output even if
-** we call a strftime variant that produces fewer characters for some years.
-** The ISO C and POSIX standards prohibit padding the year,
-** but many implementations pad anyway; most likely the standards are buggy.
-*/
-static char const ASCTIME_FMT[] = "%s %s%3d %.2d:%.2d:%.2d %-4s\n";
-/*
-** For years that are more than four digits we put extra spaces before the year
-** so that code trying to overwrite the newline won't end up overwriting
-** a digit within a year and truncating the year (operating on the assumption
-** that no output is better than wrong output).
-*/
-static char const ASCTIME_FMT_B[] = "%s %s%3d %.2d:%.2d:%.2d     %s\n";
-
-enum { STD_ASCTIME_BUF_SIZE = 26 };
-/*
-** Big enough for something such as
-** ??? ???-2147483648 -2147483648:-2147483648:-2147483648     -2147483648\n
-** (two three-character abbreviations, five strings denoting integers,
-** seven explicit spaces, two explicit colons, a newline,
-** and a trailing NUL byte).
-** The values above are for systems where an int is 32 bits and are provided
-** as an example; the size expression below is a bound for the system at
-** hand.
-*/
-static char buf_asctime[2*3 + 5*INT_STRLEN_MAXIMUM(int) + 7 + 2 + 1 + 1];
-
-/* A similar buffer for ctime.
-   C89 requires that they be the same buffer.
-   This requirement was removed in C99, so support it only if requested,
-   as support is more likely to lead to bugs in badly written programs.  */
-#if SUPPORT_C89
-# define buf_ctime buf_asctime
-#else
-static char buf_ctime[sizeof buf_asctime];
-#endif
-
-char *
-asctime_r(struct tm const *restrict timeptr, char *restrict buf)
-{
-	static const char	wday_name[][4] = {
-		"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
-	};
-	static const char	mon_name[][4] = {
-		"Jan", "Feb", "Mar", "Apr", "May", "Jun",
-		"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
-	};
-	register const char *	wn;
-	register const char *	mn;
-	char			year[INT_STRLEN_MAXIMUM(int) + 2];
-	char result[sizeof buf_asctime];
-
-	if (timeptr == NULL) {
-		errno = EINVAL;
-		return strcpy(buf, "??? ??? ?? ??:??:?? ????\n");
-	}
-	if (timeptr->tm_wday < 0 || timeptr->tm_wday >= DAYSPERWEEK)
-		wn = "???";
-	else	wn = wday_name[timeptr->tm_wday];
-	if (timeptr->tm_mon < 0 || timeptr->tm_mon >= MONSPERYEAR)
-		mn = "???";
-	else	mn = mon_name[timeptr->tm_mon];
-	/*
-	** Use strftime's %Y to generate the year, to avoid overflow problems
-	** when computing timeptr->tm_year + TM_YEAR_BASE.
-	** Assume that strftime is unaffected by other out-of-range members
-	** (e.g., timeptr->tm_mday) when processing "%Y".
-	*/
-	strftime(year, sizeof year, "%Y", timeptr);
-	/*
-	** We avoid using snprintf since it's not available on all systems.
-	*/
-	snprintf(result, sizeof(result), /* Android change: use snprintf. */
-		((strlen(year) <= 4) ? ASCTIME_FMT : ASCTIME_FMT_B),
-		wn, mn,
-		timeptr->tm_mday, timeptr->tm_hour,
-		timeptr->tm_min, timeptr->tm_sec,
-		year);
-	if (strlen(result) < STD_ASCTIME_BUF_SIZE
-	    || buf == buf_ctime || buf == buf_asctime)
-		return strcpy(buf, result);
-	else {
-		errno = EOVERFLOW;
-		return NULL;
-	}
-}
-
-char *
-asctime(register const struct tm *timeptr)
-{
-	return asctime_r(timeptr, buf_asctime);
-}
-
-char *
-ctime_r(const time_t *timep, char *buf)
-{
-  struct tm mytm;
-  struct tm *tmp = localtime_r(timep, &mytm);
-  return tmp ? asctime_r(tmp, buf) : NULL;
-}
-
-char *
-ctime(const time_t *timep)
-{
-  return ctime_r(timep, buf_ctime);
-}
diff --git a/libc/tzcode/difftime.c b/libc/tzcode/difftime.c
deleted file mode 100644
index ff78f03..0000000
--- a/libc/tzcode/difftime.c
+++ /dev/null
@@ -1,60 +0,0 @@
-/* Return the difference between two timestamps.  */
-
-/*
-** This file is in the public domain, so clarified as of
-** 1996-06-05 by Arthur David Olson.
-*/
-
-/*LINTLIBRARY*/
-
-#include "private.h"	/* for time_t and TYPE_SIGNED */
-
-/* Return -X as a double.  Using this avoids casting to 'double'.  */
-static double
-dminus(double x)
-{
-  return -x;
-}
-
-double
-difftime(time_t time1, time_t time0)
-{
-	/*
-	** If double is large enough, simply convert and subtract
-	** (assuming that the larger type has more precision).
-	*/
-	if (sizeof(time_t) < sizeof(double)) {
-	  double t1 = time1, t0 = time0;
-	  return t1 - t0;
-	}
-
-	/*
-	** The difference of two unsigned values can't overflow
-	** if the minuend is greater than or equal to the subtrahend.
-	*/
-	if (!TYPE_SIGNED(time_t))
-	  return time0 <= time1 ? time1 - time0 : dminus(time0 - time1);
-
-	/* Use uintmax_t if wide enough.  */
-	if (sizeof(time_t) <= sizeof(uintmax_t)) {
-	  uintmax_t t1 = time1, t0 = time0;
-	  return time0 <= time1 ? t1 - t0 : dminus(t0 - t1);
-	}
-
-	/*
-	** Handle cases where both time1 and time0 have the same sign
-	** (meaning that their difference cannot overflow).
-	*/
-	if ((time1 < 0) == (time0 < 0))
-	  return time1 - time0;
-
-	/*
-	** The values have opposite signs and uintmax_t is too narrow.
-	** This suffers from double rounding; attempt to lessen that
-	** by using long double temporaries.
-	*/
-	{
-	  long double t1 = time1, t0 = time0;
-	  return t1 - t0;
-	}
-}
diff --git a/libc/tzcode/strptime.c b/libc/tzcode/strptime.c
index 20160c9..3ae010b 100644
--- a/libc/tzcode/strptime.c
+++ b/libc/tzcode/strptime.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: strptime.c,v 1.31 2023/03/02 16:21:51 millert Exp $ */
+/*	$OpenBSD: strptime.c,v 1.33 2025/08/26 22:30:42 millert Exp $ */
 /*	$NetBSD: strptime.c,v 1.12 1998/01/20 21:39:40 mycroft Exp $	*/
 /*-
  * Copyright (c) 1997, 1998, 2005, 2008 The NetBSD Foundation, Inc.
@@ -68,8 +68,8 @@
 #define FIELD_TM_YDAY	(1 << 3)
 #define FIELD_TM_YEAR	(1 << 4)
 
-static const char gmt[] = { "GMT" };
-static const char utc[] = { "UTC" };
+static char const gmt[] = { "GMT" };
+static char const utc[] = { "UTC" };
 /* RFC-822/RFC-2822 */
 static const char * const nast[5] = {
        "EST",    "CST",    "MST",    "PST",    "\0\0\0"
@@ -194,7 +194,7 @@
 				return (NULL);
 			break;
 
-		case 'v':	/* Android: the date as "%e-%b-%Y" for strftime() compat; glibc does this too. */
+		case 'v':	/* The date as "%e-%b-%Y". */
 			_LEGAL_ALT(0);
 			if (!(bp = _strptime(bp, "%e-%b-%Y", tm, 0)))
 				return (NULL);
@@ -632,11 +632,19 @@
 	char *ep;
 
 	errno = 0;
+#if defined(__LP64__)
 	secs = strtoll(*buf, &ep, 10);
+#else
+	secs = strtol(*buf, &ep, 10);
+#endif
 	if (*buf == (unsigned char *)ep)
 		goto done;
 	if (secs < 0 ||
+#if defined(__LP64__)
 	    secs == LLONG_MAX && errno == ERANGE)
+#else
+	    secs == LONG_MAX && errno == ERANGE)
+#endif
 		goto done;
 	if (localtime_r(&secs, tm) == NULL)
 		goto done;
diff --git a/libc/upstream-freebsd/lib/libc/locale/wcsftime.c b/libc/upstream-freebsd/lib/libc/locale/wcsftime.c
index 4fe6ad5..f77b4e9 100644
--- a/libc/upstream-freebsd/lib/libc/locale/wcsftime.c
+++ b/libc/upstream-freebsd/lib/libc/locale/wcsftime.c
@@ -31,9 +31,6 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
 #include <errno.h>
 #include <limits.h>
 #include <stdlib.h>
diff --git a/libc/upstream-freebsd/lib/libc/stdlib/getopt_long.c b/libc/upstream-freebsd/lib/libc/stdlib/getopt_long.c
index 1f3548b..5cf6a55 100644
--- a/libc/upstream-freebsd/lib/libc/stdlib/getopt_long.c
+++ b/libc/upstream-freebsd/lib/libc/stdlib/getopt_long.c
@@ -49,14 +49,6 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-#if 0
-#if defined(LIBC_SCCS) && !defined(lint)
-static char *rcsid = "$OpenBSD: getopt_long.c,v 1.16 2004/02/04 18:17:25 millert Exp $";
-#endif /* LIBC_SCCS and not lint */
-#endif
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
 #include <err.h>
 #include <errno.h>
 #include <getopt.h>
diff --git a/libc/upstream-freebsd/lib/libc/stdlib/hcreate.c b/libc/upstream-freebsd/lib/libc/stdlib/hcreate.c
index c9a0847..261f55b 100644
--- a/libc/upstream-freebsd/lib/libc/stdlib/hcreate.c
+++ b/libc/upstream-freebsd/lib/libc/stdlib/hcreate.c
@@ -25,9 +25,6 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
 #include <search.h>
 #include <stdbool.h>
 #include <stddef.h>
diff --git a/libc/upstream-freebsd/lib/libc/stdlib/hcreate_r.c b/libc/upstream-freebsd/lib/libc/stdlib/hcreate_r.c
index 83e322a..90eff33 100644
--- a/libc/upstream-freebsd/lib/libc/stdlib/hcreate_r.c
+++ b/libc/upstream-freebsd/lib/libc/stdlib/hcreate_r.c
@@ -23,9 +23,6 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
 #include <search.h>
 #include <stdlib.h>
 
diff --git a/libc/upstream-freebsd/lib/libc/stdlib/hdestroy_r.c b/libc/upstream-freebsd/lib/libc/stdlib/hdestroy_r.c
index 890bd08..e9435c4 100644
--- a/libc/upstream-freebsd/lib/libc/stdlib/hdestroy_r.c
+++ b/libc/upstream-freebsd/lib/libc/stdlib/hdestroy_r.c
@@ -23,9 +23,6 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
 #include <search.h>
 #include <stdlib.h>
 
diff --git a/libc/upstream-freebsd/lib/libc/stdlib/hsearch.h b/libc/upstream-freebsd/lib/libc/stdlib/hsearch.h
index 649933d..2d84935 100644
--- a/libc/upstream-freebsd/lib/libc/stdlib/hsearch.h
+++ b/libc/upstream-freebsd/lib/libc/stdlib/hsearch.h
@@ -21,8 +21,6 @@
  * 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.
- *
- * $FreeBSD$
  */
 
 #ifndef HSEARCH_H
diff --git a/libc/upstream-freebsd/lib/libc/stdlib/hsearch_r.c b/libc/upstream-freebsd/lib/libc/stdlib/hsearch_r.c
index 2fb5991..15c2c15 100644
--- a/libc/upstream-freebsd/lib/libc/stdlib/hsearch_r.c
+++ b/libc/upstream-freebsd/lib/libc/stdlib/hsearch_r.c
@@ -23,9 +23,6 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
 #include <errno.h>
 #include <limits.h>
 #include <search.h>
diff --git a/libc/upstream-freebsd/lib/libc/stdlib/qsort.c b/libc/upstream-freebsd/lib/libc/stdlib/qsort.c
deleted file mode 100644
index 0d65cd1..0000000
--- a/libc/upstream-freebsd/lib/libc/stdlib/qsort.c
+++ /dev/null
@@ -1,267 +0,0 @@
-/*-
- * SPDX-License-Identifier: BSD-3-Clause
- *
- * Copyright (c) 1992, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)qsort.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <errno.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
-#include "libc_private.h"
-
-#if defined(I_AM_QSORT_R)
-typedef int		 cmp_t(const void *, const void *, void *);
-#elif defined(I_AM_QSORT_R_COMPAT)
-typedef int		 cmp_t(void *, const void *, const void *);
-#elif defined(I_AM_QSORT_S)
-typedef int		 cmp_t(const void *, const void *, void *);
-#else
-typedef int		 cmp_t(const void *, const void *);
-#endif
-static inline char	*med3(char *, char *, char *, cmp_t *, void *);
-
-#define	MIN(a, b)	((a) < (b) ? a : b)
-
-/*
- * Qsort routine from Bentley & McIlroy's "Engineering a Sort Function".
- */
-
-static inline void
-swapfunc(char *a, char *b, size_t es)
-{
-	char t;
-
-	do {
-		t = *a;
-		*a++ = *b;
-		*b++ = t;
-	} while (--es > 0);
-}
-
-#define	vecswap(a, b, n)				\
-	if ((n) > 0) swapfunc(a, b, n)
-
-#if defined(I_AM_QSORT_R)
-#define	CMP(t, x, y) (cmp((x), (y), (t)))
-#elif defined(I_AM_QSORT_R_COMPAT)
-#define	CMP(t, x, y) (cmp((t), (x), (y)))
-#elif defined(I_AM_QSORT_S)
-#define	CMP(t, x, y) (cmp((x), (y), (t)))
-#else
-#define	CMP(t, x, y) (cmp((x), (y)))
-#endif
-
-static inline char *
-med3(char *a, char *b, char *c, cmp_t *cmp, void *thunk
-#if !defined(I_AM_QSORT_R) && !defined(I_AM_QSORT_R_COMPAT) && !defined(I_AM_QSORT_S)
-__unused
-#endif
-)
-{
-	return CMP(thunk, a, b) < 0 ?
-	       (CMP(thunk, b, c) < 0 ? b : (CMP(thunk, a, c) < 0 ? c : a ))
-	      :(CMP(thunk, b, c) > 0 ? b : (CMP(thunk, a, c) < 0 ? a : c ));
-}
-
-/*
- * The actual qsort() implementation is static to avoid preemptible calls when
- * recursing. Also give them different names for improved debugging.
- */
-#if defined(I_AM_QSORT_R)
-#define local_qsort local_qsort_r
-#elif defined(I_AM_QSORT_R_COMPAT)
-#define local_qsort local_qsort_r_compat
-#elif defined(I_AM_QSORT_S)
-#define local_qsort local_qsort_s
-#endif
-static void
-local_qsort(void *a, size_t n, size_t es, cmp_t *cmp, void *thunk)
-{
-	char *pa, *pb, *pc, *pd, *pl, *pm, *pn;
-	size_t d1, d2;
-	int cmp_result;
-	int swap_cnt;
-
-	/* if there are less than 2 elements, then sorting is not needed */
-	if (__predict_false(n < 2))
-		return;
-loop:
-	swap_cnt = 0;
-	if (n < 7) {
-		for (pm = (char *)a + es; pm < (char *)a + n * es; pm += es)
-			for (pl = pm; 
-			     pl > (char *)a && CMP(thunk, pl - es, pl) > 0;
-			     pl -= es)
-				swapfunc(pl, pl - es, es);
-		return;
-	}
-	pm = (char *)a + (n / 2) * es;
-	if (n > 7) {
-		pl = a;
-		pn = (char *)a + (n - 1) * es;
-		if (n > 40) {
-			size_t d = (n / 8) * es;
-
-			pl = med3(pl, pl + d, pl + 2 * d, cmp, thunk);
-			pm = med3(pm - d, pm, pm + d, cmp, thunk);
-			pn = med3(pn - 2 * d, pn - d, pn, cmp, thunk);
-		}
-		pm = med3(pl, pm, pn, cmp, thunk);
-	}
-	swapfunc(a, pm, es);
-	pa = pb = (char *)a + es;
-
-	pc = pd = (char *)a + (n - 1) * es;
-	for (;;) {
-		while (pb <= pc && (cmp_result = CMP(thunk, pb, a)) <= 0) {
-			if (cmp_result == 0) {
-				swap_cnt = 1;
-				swapfunc(pa, pb, es);
-				pa += es;
-			}
-			pb += es;
-		}
-		while (pb <= pc && (cmp_result = CMP(thunk, pc, a)) >= 0) {
-			if (cmp_result == 0) {
-				swap_cnt = 1;
-				swapfunc(pc, pd, es);
-				pd -= es;
-			}
-			pc -= es;
-		}
-		if (pb > pc)
-			break;
-		swapfunc(pb, pc, es);
-		swap_cnt = 1;
-		pb += es;
-		pc -= es;
-	}
-	if (swap_cnt == 0) {  /* Switch to insertion sort */
-		for (pm = (char *)a + es; pm < (char *)a + n * es; pm += es)
-			for (pl = pm; 
-			     pl > (char *)a && CMP(thunk, pl - es, pl) > 0;
-			     pl -= es)
-				swapfunc(pl, pl - es, es);
-		return;
-	}
-
-	pn = (char *)a + n * es;
-	d1 = MIN(pa - (char *)a, pb - pa);
-	vecswap(a, pb - d1, d1);
-	/*
-	 * Cast es to preserve signedness of right-hand side of MIN()
-	 * expression, to avoid sign ambiguity in the implied comparison.  es
-	 * is safely within [0, SSIZE_MAX].
-	 */
-	d1 = MIN(pd - pc, pn - pd - (ssize_t)es);
-	vecswap(pb, pn - d1, d1);
-
-	d1 = pb - pa;
-	d2 = pd - pc;
-	if (d1 <= d2) {
-		/* Recurse on left partition, then iterate on right partition */
-		if (d1 > es) {
-			local_qsort(a, d1 / es, es, cmp, thunk);
-		}
-		if (d2 > es) {
-			/* Iterate rather than recurse to save stack space */
-			/* qsort(pn - d2, d2 / es, es, cmp); */
-			a = pn - d2;
-			n = d2 / es;
-			goto loop;
-		}
-	} else {
-		/* Recurse on right partition, then iterate on left partition */
-		if (d2 > es) {
-			local_qsort(pn - d2, d2 / es, es, cmp, thunk);
-		}
-		if (d1 > es) {
-			/* Iterate rather than recurse to save stack space */
-			/* qsort(a, d1 / es, es, cmp); */
-			n = d1 / es;
-			goto loop;
-		}
-	}
-}
-
-#if defined(I_AM_QSORT_R)
-void
-(qsort_r)(void *a, size_t n, size_t es, cmp_t *cmp, void *thunk)
-{
-	local_qsort_r(a, n, es, cmp, thunk);
-}
-#elif defined(I_AM_QSORT_R_COMPAT)
-void
-__qsort_r_compat(void *a, size_t n, size_t es, void *thunk, cmp_t *cmp)
-{
-	local_qsort_r_compat(a, n, es, cmp, thunk);
-}
-#elif defined(I_AM_QSORT_S)
-errno_t
-qsort_s(void *a, rsize_t n, rsize_t es, cmp_t *cmp, void *thunk)
-{
-	if (n > RSIZE_MAX) {
-		__throw_constraint_handler_s("qsort_s : n > RSIZE_MAX", EINVAL);
-		return (EINVAL);
-	} else if (es > RSIZE_MAX) {
-		__throw_constraint_handler_s("qsort_s : es > RSIZE_MAX",
-		    EINVAL);
-		return (EINVAL);
-	} else if (n != 0) {
-		if (a == NULL) {
-			__throw_constraint_handler_s("qsort_s : a == NULL",
-			    EINVAL);
-			return (EINVAL);
-		} else if (cmp == NULL) {
-			__throw_constraint_handler_s("qsort_s : cmp == NULL",
-			    EINVAL);
-			return (EINVAL);
-		} else if (es <= 0) {
-			__throw_constraint_handler_s("qsort_s : es <= 0",
-			    EINVAL);
-			return (EINVAL);
-		}
-	}
-
-	local_qsort_s(a, n, es, cmp, thunk);
-	return (0);
-}
-#else
-void
-qsort(void *a, size_t n, size_t es, cmp_t *cmp)
-{
-	local_qsort(a, n, es, cmp, NULL);
-}
-#endif
diff --git a/libc/upstream-freebsd/lib/libc/stdlib/qsort_r.c b/libc/upstream-freebsd/lib/libc/stdlib/qsort_r.c
deleted file mode 100644
index b382b40..0000000
--- a/libc/upstream-freebsd/lib/libc/stdlib/qsort_r.c
+++ /dev/null
@@ -1,6 +0,0 @@
-/*
- * This file is in the public domain.  Originally written by Garrett
- * A. Wollman.
- */
-#define I_AM_QSORT_R
-#include "qsort.c"
diff --git a/libc/upstream-freebsd/lib/libc/stdlib/quick_exit.c b/libc/upstream-freebsd/lib/libc/stdlib/quick_exit.c
index d486b1a..4dee7b2 100644
--- a/libc/upstream-freebsd/lib/libc/stdlib/quick_exit.c
+++ b/libc/upstream-freebsd/lib/libc/stdlib/quick_exit.c
@@ -2,6 +2,7 @@
  * SPDX-License-Identifier: BSD-2-Clause
  *
  * Copyright (c) 2011 David Chisnall
+ * Copyright (c) 2023 Klara, Inc.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -24,49 +25,38 @@
  * 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.
- *
- * $FreeBSD$
  */
 
 #include <sys/types.h>
-#include <machine/atomic.h>
+
+#include <stdatomic.h>
 #include <stdlib.h>
-#include <pthread.h>
 
 /**
- * Linked list of quick exit handlers.  This is simpler than the atexit()
- * version, because it is not required to support C++ destructors or
- * DSO-specific cleanups.
+ * Linked list of quick exit handlers.  These will be invoked in reverse
+ * order of insertion when quick_exit() is called.  This is simpler than
+ * the atexit() version, because it is not required to support C++
+ * destructors or DSO-specific cleanups.
  */
 struct quick_exit_handler {
 	struct quick_exit_handler *next;
 	void (*cleanup)(void);
 };
 
-/**
- * Lock protecting the handlers list.
- */
-static pthread_mutex_t atexit_mutex = PTHREAD_MUTEX_INITIALIZER;
-/**
- * Stack of cleanup handlers.  These will be invoked in reverse order when 
- */
-static struct quick_exit_handler *handlers;
+static _Atomic(struct quick_exit_handler *) handlers;
 
 int
 at_quick_exit(void (*func)(void))
 {
 	struct quick_exit_handler *h;
-	
-	h = malloc(sizeof(*h));
 
-	if (NULL == h)
-		return (1);
+	if ((h = calloc(1, sizeof(*h))) == NULL) {
+		return (-1);
+	}
 	h->cleanup = func;
-	pthread_mutex_lock(&atexit_mutex);
-	h->next = handlers;
-	__compiler_membar();
-	handlers = h;
-	pthread_mutex_unlock(&atexit_mutex);
+	while (!atomic_compare_exchange_strong(&handlers, &h->next, h)) {
+		/* nothing */ ;
+	}
 	return (0);
 }
 
@@ -79,8 +69,8 @@
 	 * XXX: The C++ spec requires us to call std::terminate if there is an
 	 * exception here.
 	 */
-	for (h = handlers; NULL != h; h = h->next) {
-		__compiler_membar();
+	for (h = atomic_load_explicit(&handlers, memory_order_acquire);
+	     h != NULL; h = h->next) {
 		h->cleanup();
 	}
 	_Exit(status);
diff --git a/libc/upstream-freebsd/lib/libc/string/wcpcpy.c b/libc/upstream-freebsd/lib/libc/string/wcpcpy.c
deleted file mode 100644
index 41b7c51..0000000
--- a/libc/upstream-freebsd/lib/libc/string/wcpcpy.c
+++ /dev/null
@@ -1,48 +0,0 @@
-/*-
- * SPDX-License-Identifier: BSD-3-Clause
- *
- * Copyright (c) 1999
- *	David E. O'Brien
- * Copyright (c) 1988, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)strcpy.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <wchar.h>
-
-wchar_t *
-wcpcpy(wchar_t * __restrict to, const wchar_t * __restrict from)
-{
-
-	for (; (*to = *from); ++from, ++to);
-	return(to);
-}
diff --git a/libc/upstream-freebsd/lib/libc/string/wcpncpy.c b/libc/upstream-freebsd/lib/libc/string/wcpncpy.c
deleted file mode 100644
index ccc64cd..0000000
--- a/libc/upstream-freebsd/lib/libc/string/wcpncpy.c
+++ /dev/null
@@ -1,47 +0,0 @@
-/*-
- * SPDX-License-Identifier: BSD-2-Clause
- *
- * Copyright (c) 2009 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.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <wchar.h>
-
-wchar_t *
-wcpncpy(wchar_t * __restrict dst, const wchar_t * __restrict src, size_t n)
-{
-
-	for (; n--; dst++, src++) {
-		if (!(*dst = *src)) {
-			wchar_t *ret = dst;
-			while (n--)
-				*++dst = L'\0';
-			return (ret);
-		}
-	}
-	return (dst);
-}
diff --git a/libc/upstream-freebsd/lib/libc/string/wcscasecmp.c b/libc/upstream-freebsd/lib/libc/string/wcscasecmp.c
deleted file mode 100644
index 03a61f8..0000000
--- a/libc/upstream-freebsd/lib/libc/string/wcscasecmp.c
+++ /dev/null
@@ -1,47 +0,0 @@
-/*-
- * SPDX-License-Identifier: BSD-2-Clause
- *
- * Copyright (c) 2009 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.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <wchar.h>
-#include <wctype.h>
-
-int
-wcscasecmp(const wchar_t *s1, const wchar_t *s2)
-{
-	wchar_t c1, c2;
-
-	for (; *s1; s1++, s2++) {
-		c1 = towlower(*s1);
-		c2 = towlower(*s2);
-		if (c1 != c2)
-			return ((int)c1 - c2);
-	}
-	return (-*s2);
-}
diff --git a/libc/upstream-freebsd/lib/libc/string/wcscat.c b/libc/upstream-freebsd/lib/libc/string/wcscat.c
deleted file mode 100644
index 777a576..0000000
--- a/libc/upstream-freebsd/lib/libc/string/wcscat.c
+++ /dev/null
@@ -1,53 +0,0 @@
-/*-
- * SPDX-License-Identifier: BSD-2-Clause
- *
- * Copyright (c)1999 Citrus Project,
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 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.
- *
- *	citrus Id: wcscat.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp
- */
-
-#include <sys/cdefs.h>
-#if 0
-#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: wcscat.c,v 1.1 2000/12/23 23:14:36 itojun Exp $");
-#endif /* LIBC_SCCS and not lint */
-#endif
-__FBSDID("$FreeBSD$");
-
-#include <wchar.h>
-
-wchar_t *
-wcscat(wchar_t * __restrict s1, const wchar_t * __restrict s2)
-{
-	wchar_t *cp;
-
-	cp = s1;
-	while (*cp != L'\0')
-		cp++;
-	while ((*cp++ = *s2++) != L'\0')
-		;
-
-	return (s1);
-}
diff --git a/libc/upstream-freebsd/lib/libc/string/wcschr.c b/libc/upstream-freebsd/lib/libc/string/wcschr.c
deleted file mode 100644
index a7f1de0..0000000
--- a/libc/upstream-freebsd/lib/libc/string/wcschr.c
+++ /dev/null
@@ -1,43 +0,0 @@
-/*-
- * SPDX-License-Identifier: BSD-2-Clause
- *
- * Copyright (c) 2002 Tim J. Robbins
- * 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.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <wchar.h>
-
-wchar_t *
-wcschr(const wchar_t *s, wchar_t c)
-{
-
-	while (*s != c && *s != L'\0')
-		s++;
-	if (*s == c)
-		return ((wchar_t *)s);
-	return (NULL);
-}
diff --git a/libc/upstream-freebsd/lib/libc/string/wcscmp.c b/libc/upstream-freebsd/lib/libc/string/wcscmp.c
deleted file mode 100644
index 7205238..0000000
--- a/libc/upstream-freebsd/lib/libc/string/wcscmp.c
+++ /dev/null
@@ -1,58 +0,0 @@
-/*-
- * SPDX-License-Identifier: BSD-3-Clause
- *
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)strcmp.c	8.1 (Berkeley) 6/4/93";
-#if 0
-__RCSID("$NetBSD: wcscmp.c,v 1.3 2001/01/05 12:13:12 itojun Exp $");
-#endif
-#endif /* LIBC_SCCS and not lint */
-__FBSDID("$FreeBSD$");
-
-#include <wchar.h>
-
-/*
- * Compare strings.
- */
-int
-wcscmp(const wchar_t *s1, const wchar_t *s2)
-{
-
-	while (*s1 == *s2++)
-		if (*s1++ == '\0')
-			return (0);
-	/* XXX assumes wchar_t = int */
-	return (*(const unsigned int *)s1 - *(const unsigned int *)--s2);
-}
diff --git a/libc/upstream-freebsd/lib/libc/string/wcscpy.c b/libc/upstream-freebsd/lib/libc/string/wcscpy.c
deleted file mode 100644
index b400fae..0000000
--- a/libc/upstream-freebsd/lib/libc/string/wcscpy.c
+++ /dev/null
@@ -1,51 +0,0 @@
-/*-
- * SPDX-License-Identifier: BSD-2-Clause
- *
- * Copyright (c)1999 Citrus Project,
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 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.
- *
- *	citrus Id: wcscpy.c,v 1.2 2000/12/21 04:51:09 itojun Exp
- */
-
-#include <sys/cdefs.h>
-#if 0
-#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: wcscpy.c,v 1.1 2000/12/23 23:14:36 itojun Exp $");
-#endif /* LIBC_SCCS and not lint */
-#endif
-__FBSDID("$FreeBSD$");
-
-#include <wchar.h>
-
-wchar_t *
-wcscpy(wchar_t * __restrict s1, const wchar_t * __restrict s2)
-{
-	wchar_t *cp;
-
-	cp = s1;
-	while ((*cp++ = *s2++) != L'\0')
-		;
-
-	return (s1);
-}
diff --git a/libc/upstream-freebsd/lib/libc/string/wcscspn.c b/libc/upstream-freebsd/lib/libc/string/wcscspn.c
deleted file mode 100644
index a0db715..0000000
--- a/libc/upstream-freebsd/lib/libc/string/wcscspn.c
+++ /dev/null
@@ -1,60 +0,0 @@
-/*-
- * SPDX-License-Identifier: BSD-2-Clause
- *
- * Copyright (c)1999 Citrus Project,
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 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.
- *
- *	citrus Id: wcscspn.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp
- */
-
-#include <sys/cdefs.h>
-#if 0
-#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: wcscspn.c,v 1.1 2000/12/23 23:14:36 itojun Exp $");
-#endif /* LIBC_SCCS and not lint */
-#endif
-__FBSDID("$FreeBSD$");
-
-#include <wchar.h>
-
-size_t
-wcscspn(const wchar_t *s, const wchar_t *set)
-{
-	const wchar_t *p;
-	const wchar_t *q;
-
-	p = s;
-	while (*p) {
-		q = set;
-		while (*q) {
-			if (*p == *q)
-				goto done;
-			q++;
-		}
-		p++;
-	}
-
-done:
-	return (p - s);
-}
diff --git a/libc/upstream-freebsd/lib/libc/string/wcsdup.c b/libc/upstream-freebsd/lib/libc/string/wcsdup.c
index 327574b..517acfa 100644
--- a/libc/upstream-freebsd/lib/libc/string/wcsdup.c
+++ b/libc/upstream-freebsd/lib/libc/string/wcsdup.c
@@ -26,9 +26,6 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
 #include <stdlib.h>
 #include <wchar.h>
 
diff --git a/libc/upstream-freebsd/lib/libc/string/wcslcat.c b/libc/upstream-freebsd/lib/libc/string/wcslcat.c
deleted file mode 100644
index f954b73..0000000
--- a/libc/upstream-freebsd/lib/libc/string/wcslcat.c
+++ /dev/null
@@ -1,76 +0,0 @@
-/*-
- * SPDX-License-Identifier: BSD-3-Clause
- *
- * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. 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 ``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.
- *
- *	from OpenBSD: strlcat.c,v 1.3 2000/11/24 11:10:02 itojun Exp
- */
-
-#include <sys/cdefs.h>
-#if 0
-#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: wcslcat.c,v 1.1 2000/12/23 23:14:36 itojun Exp $");
-#endif /* LIBC_SCCS and not lint */
-#endif
-__FBSDID("$FreeBSD$");
-
-#include <sys/types.h>
-#include <wchar.h>
-
-/*
- * Appends src to string dst of size siz (unlike wcsncat, siz is the
- * full size of dst, not space left).  At most siz-1 characters
- * will be copied.  Always NUL terminates (unless siz == 0).
- * Returns wcslen(initial dst) + wcslen(src); if retval >= siz,
- * truncation occurred.
- */
-size_t
-wcslcat(wchar_t *dst, const wchar_t *src, size_t siz)
-{
-	wchar_t *d = dst;
-	const wchar_t *s = src;
-	size_t n = siz;
-	size_t dlen;
-
-	/* Find the end of dst and adjust bytes left but don't go past end */
-	while (n-- != 0 && *d != '\0')
-		d++;
-	dlen = d - dst;
-	n = siz - dlen;
-
-	if (n == 0)
-		return(dlen + wcslen(s));
-	while (*s != '\0') {
-		if (n != 1) {
-			*d++ = *s;
-			n--;
-		}
-		s++;
-	}
-	*d = '\0';
-
-	return(dlen + (s - src));	/* count does not include NUL */
-}
diff --git a/libc/upstream-freebsd/lib/libc/string/wcslen.c b/libc/upstream-freebsd/lib/libc/string/wcslen.c
deleted file mode 100644
index cfd3aa2..0000000
--- a/libc/upstream-freebsd/lib/libc/string/wcslen.c
+++ /dev/null
@@ -1,51 +0,0 @@
-/*-
- * SPDX-License-Identifier: BSD-2-Clause
- *
- * Copyright (c)1999 Citrus Project,
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 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.
- *
- *	citrus Id: wcslen.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp
- */
-
-#include <sys/cdefs.h>
-#if 0
-#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: wcslen.c,v 1.1 2000/12/23 23:14:36 itojun Exp $");
-#endif /* LIBC_SCCS and not lint */
-#endif
-__FBSDID("$FreeBSD$");
-
-#include <wchar.h>
-
-size_t
-wcslen(const wchar_t *s)
-{
-	const wchar_t *p;
-
-	p = s;
-	while (*p)
-		p++;
-
-	return p - s;
-}
diff --git a/libc/upstream-freebsd/lib/libc/string/wcsncasecmp.c b/libc/upstream-freebsd/lib/libc/string/wcsncasecmp.c
deleted file mode 100644
index 39f58be..0000000
--- a/libc/upstream-freebsd/lib/libc/string/wcsncasecmp.c
+++ /dev/null
@@ -1,51 +0,0 @@
-/*-
- * SPDX-License-Identifier: BSD-2-Clause
- *
- * Copyright (c) 2009 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.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <wchar.h>
-#include <wctype.h>
-
-int
-wcsncasecmp(const wchar_t *s1, const wchar_t *s2, size_t n)
-{
-	wchar_t c1, c2;
-
-	if (n == 0)
-		return (0);
-	for (; *s1; s1++, s2++) {
-		c1 = towlower(*s1);
-		c2 = towlower(*s2);
-		if (c1 != c2)
-			return ((int)c1 - c2);
-		if (--n == 0)
-			return (0);
-	}
-	return (-*s2);
-}
diff --git a/libc/upstream-freebsd/lib/libc/string/wcsncat.c b/libc/upstream-freebsd/lib/libc/string/wcsncat.c
deleted file mode 100644
index eb13fab..0000000
--- a/libc/upstream-freebsd/lib/libc/string/wcsncat.c
+++ /dev/null
@@ -1,59 +0,0 @@
-/*-
- * SPDX-License-Identifier: BSD-2-Clause
- *
- * Copyright (c)1999 Citrus Project,
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 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.
- *
- *	citrus Id: wcsncat.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp
- */
-
-#include <sys/cdefs.h>
-#if 0
-#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: wcsncat.c,v 1.1 2000/12/23 23:14:36 itojun Exp $");
-#endif /* LIBC_SCCS and not lint */
-#endif
-__FBSDID("$FreeBSD$");
-
-#include <wchar.h>
-
-wchar_t *
-wcsncat(wchar_t * __restrict s1, const wchar_t * __restrict s2, size_t n)
-{
-	wchar_t *p;
-	wchar_t *q;
-	const wchar_t *r;
-
-	p = s1;
-	while (*p)
-		p++;
-	q = p;
-	r = s2;
-	while (n && *r) {
-		*q++ = *r++;
-		n--;
-	}
-	*q = '\0';
-	return s1;
-}
diff --git a/libc/upstream-freebsd/lib/libc/string/wcsncmp.c b/libc/upstream-freebsd/lib/libc/string/wcsncmp.c
deleted file mode 100644
index 55c88f6..0000000
--- a/libc/upstream-freebsd/lib/libc/string/wcsncmp.c
+++ /dev/null
@@ -1,59 +0,0 @@
-/*-
- * SPDX-License-Identifier: BSD-3-Clause
- *
- * Copyright (c) 1989, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-#if 0
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)strncmp.c	8.1 (Berkeley) 6/4/93";
-__RCSID("$NetBSD: wcsncmp.c,v 1.3 2001/01/05 12:13:13 itojun Exp $");
-#endif /* LIBC_SCCS and not lint */
-#endif
-__FBSDID("$FreeBSD$");
-
-#include <wchar.h>
-
-int
-wcsncmp(const wchar_t *s1, const wchar_t *s2, size_t n)
-{
-
-	if (n == 0)
-		return (0);
-	do {
-		if (*s1 != *s2++) {
-			/* XXX assumes wchar_t = int */
-			return (*(const unsigned int *)s1 -
-			    *(const unsigned int *)--s2);
-		}
-		if (*s1++ == 0)
-			break;
-	} while (--n != 0);
-	return (0);
-}
diff --git a/libc/upstream-freebsd/lib/libc/string/wcsncpy.c b/libc/upstream-freebsd/lib/libc/string/wcsncpy.c
deleted file mode 100644
index f86e40f..0000000
--- a/libc/upstream-freebsd/lib/libc/string/wcsncpy.c
+++ /dev/null
@@ -1,66 +0,0 @@
-/*-
- * SPDX-License-Identifier: BSD-3-Clause
- *
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if 0
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)strncpy.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#endif
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <wchar.h>
-
-/*
- * Copy src to dst, truncating or null-padding to always copy n bytes.
- * Return dst.
- */
-wchar_t *
-wcsncpy(wchar_t * __restrict dst, const wchar_t * __restrict src, size_t n)
-{
-	if (n != 0) {
-		wchar_t *d = dst;
-		const wchar_t *s = src;
-
-		do {
-			if ((*d++ = *s++) == L'\0') {
-				/* NUL pad the remaining n-1 bytes */
-				while (--n != 0)
-					*d++ = L'\0';
-				break;
-			}
-		} while (--n != 0);
-	}
-	return (dst);
-}
diff --git a/libc/upstream-freebsd/lib/libc/string/wcsnlen.c b/libc/upstream-freebsd/lib/libc/string/wcsnlen.c
deleted file mode 100644
index 15fd520..0000000
--- a/libc/upstream-freebsd/lib/libc/string/wcsnlen.c
+++ /dev/null
@@ -1,44 +0,0 @@
-/*-
- * SPDX-License-Identifier: BSD-2-Clause
- *
- * Copyright (c) 2009 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.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <wchar.h>
-
-size_t
-wcsnlen(const wchar_t *s, size_t maxlen)
-{
-	size_t len;
-
-	for (len = 0; len < maxlen; len++, s++) {
-		if (!*s)
-			break;
-	}
-	return (len);
-}
diff --git a/libc/upstream-freebsd/lib/libc/string/wcspbrk.c b/libc/upstream-freebsd/lib/libc/string/wcspbrk.c
deleted file mode 100644
index 0e9ccf6..0000000
--- a/libc/upstream-freebsd/lib/libc/string/wcspbrk.c
+++ /dev/null
@@ -1,60 +0,0 @@
-/*-
- * SPDX-License-Identifier: BSD-2-Clause
- *
- * Copyright (c)1999 Citrus Project,
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 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.
- *
- *	citrus Id: wcspbrk.c,v 1.2 2000/12/21 05:07:25 itojun Exp
- */
-
-#include <sys/cdefs.h>
-#if 0
-#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: wcspbrk.c,v 1.1 2000/12/23 23:14:37 itojun Exp $");
-#endif /* LIBC_SCCS and not lint */
-#endif
-__FBSDID("$FreeBSD$");
-
-#include <wchar.h>
-
-wchar_t *
-wcspbrk(const wchar_t *s, const wchar_t *set)
-{
-	const wchar_t *p;
-	const wchar_t *q;
-
-	p = s;
-	while (*p) {
-		q = set;
-		while (*q) {
-			if (*p == *q) {
-				/* LINTED interface specification */
-				return (wchar_t *)p;
-			}
-			q++;
-		}
-		p++;
-	}
-	return NULL;
-}
diff --git a/libc/upstream-freebsd/lib/libc/string/wcsrchr.c b/libc/upstream-freebsd/lib/libc/string/wcsrchr.c
deleted file mode 100644
index cc5e7f2..0000000
--- a/libc/upstream-freebsd/lib/libc/string/wcsrchr.c
+++ /dev/null
@@ -1,49 +0,0 @@
-/*-
- * SPDX-License-Identifier: BSD-2-Clause
- *
- * Copyright (c) 2002 Tim J. Robbins
- * 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.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <wchar.h>
-
-wchar_t *
-wcsrchr(const wchar_t *s, wchar_t c)
-{
-	const wchar_t *last;
-
-	last = NULL;
-	for (;;) {
-		if (*s == c)
-			last = s;
-		if (*s == L'\0')
-			break;
-		s++;
-	}
-
-	return ((wchar_t *)last);
-}
diff --git a/libc/upstream-freebsd/lib/libc/string/wcsspn.c b/libc/upstream-freebsd/lib/libc/string/wcsspn.c
deleted file mode 100644
index 2b08acb..0000000
--- a/libc/upstream-freebsd/lib/libc/string/wcsspn.c
+++ /dev/null
@@ -1,62 +0,0 @@
-/*-
- * SPDX-License-Identifier: BSD-2-Clause
- *
- * Copyright (c)1999 Citrus Project,
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 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.
- *
- *	citrus Id: wcsspn.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp
- */
-
-#include <sys/cdefs.h>
-#if 0
-#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: wcsspn.c,v 1.1 2000/12/23 23:14:37 itojun Exp $");
-#endif /* LIBC_SCCS and not lint */
-#endif
-__FBSDID("$FreeBSD$");
-
-#include <wchar.h>
-
-size_t
-wcsspn(const wchar_t *s, const wchar_t *set)
-{
-	const wchar_t *p;
-	const wchar_t *q;
-
-	p = s;
-	while (*p) {
-		q = set;
-		while (*q) {
-			if (*p == *q)
-				break;
-			q++;
-		}
-		if (!*q)
-			goto done;
-		p++;
-	}
-
-done:
-	return (p - s);
-}
diff --git a/libc/upstream-freebsd/lib/libc/string/wcsstr.c b/libc/upstream-freebsd/lib/libc/string/wcsstr.c
deleted file mode 100644
index 74921fe..0000000
--- a/libc/upstream-freebsd/lib/libc/string/wcsstr.c
+++ /dev/null
@@ -1,65 +0,0 @@
-/*-
- * SPDX-License-Identifier: BSD-3-Clause
- *
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if 0
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)strstr.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#endif
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <wchar.h>
-
-/*
- * Find the first occurrence of find in s.
- */
-wchar_t *
-wcsstr(const wchar_t * __restrict s, const wchar_t * __restrict find)
-{
-	wchar_t c, sc;
-	size_t len;
-
-	if ((c = *find++) != L'\0') {
-		len = wcslen(find);
-		do {
-			do {
-				if ((sc = *s++) == L'\0')
-					return (NULL);
-			} while (sc != c);
-		} while (wcsncmp(s, find, len) != 0);
-		s--;
-	}
-	return ((wchar_t *)s);
-}
diff --git a/libc/upstream-freebsd/lib/libc/string/wcstok.c b/libc/upstream-freebsd/lib/libc/string/wcstok.c
deleted file mode 100644
index b4bdc86..0000000
--- a/libc/upstream-freebsd/lib/libc/string/wcstok.c
+++ /dev/null
@@ -1,88 +0,0 @@
-/*-
- * SPDX-License-Identifier: BSD-3-Clause
- *
- * Copyright (c) 1998 Softweyr LLC.  All rights reserved.
- *
- * strtok_r, from Berkeley strtok
- * Oct 13, 1998 by Wes Peters <wes@softweyr.com>
- *
- * Copyright (c) 1988, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notices, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notices, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY SOFTWEYR LLC, THE REGENTS AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL SOFTWEYR LLC, THE
- * REGENTS, OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <wchar.h>
-
-wchar_t *
-wcstok(wchar_t * __restrict s, const wchar_t * __restrict delim,
-    wchar_t ** __restrict last)
-{
-	const wchar_t *spanp;
-	wchar_t *tok;
-	wchar_t c, sc;
-
-	if (s == NULL && (s = *last) == NULL)
-		return (NULL);
-
-	/*
-	 * Skip (span) leading delimiters (s += wcsspn(s, delim), sort of).
-	 */
-cont:
-	c = *s++;
-	for (spanp = delim; (sc = *spanp++) != L'\0';) {
-		if (c == sc)
-			goto cont;
-	}
-
-	if (c == L'\0') {	/* no non-delimiter characters */
-		*last = NULL;
-		return (NULL);
-	}
-	tok = s - 1;
-
-	/*
-	 * Scan token (scan for delimiters: s += wcscspn(s, delim), sort of).
-	 * Note that delim must have one NUL; we stop if we see that, too.
-	 */
-	for (;;) {
-		c = *s++;
-		spanp = delim;
-		do {
-			if ((sc = *spanp++) == c) {
-				if (c == L'\0')
-					s = NULL;
-				else
-					s[-1] = L'\0';
-				*last = s;
-				return (tok);
-			}
-		} while (sc != L'\0');
-	}
-	/* NOTREACHED */
-}
diff --git a/libc/upstream-freebsd/lib/libc/string/wmemchr.c b/libc/upstream-freebsd/lib/libc/string/wmemchr.c
deleted file mode 100644
index 42ae286..0000000
--- a/libc/upstream-freebsd/lib/libc/string/wmemchr.c
+++ /dev/null
@@ -1,54 +0,0 @@
-/*-
- * SPDX-License-Identifier: BSD-2-Clause
- *
- * Copyright (c)1999 Citrus Project,
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 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.
- *
- *	citrus Id: wmemchr.c,v 1.2 2000/12/20 14:08:31 itojun Exp
- */
-
-#include <sys/cdefs.h>
-#if 0
-#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: wmemchr.c,v 1.1 2000/12/23 23:14:37 itojun Exp $");
-#endif /* LIBC_SCCS and not lint */
-#endif
-__FBSDID("$FreeBSD$");
-
-#include <wchar.h>
-
-wchar_t	*
-wmemchr(const wchar_t *s, wchar_t c, size_t n)
-{
-	size_t i;
-
-	for (i = 0; i < n; i++) {
-		if (*s == c) {
-			/* LINTED const castaway */
-			return (wchar_t *)s;
-		}
-		s++;
-	}
-	return NULL;
-}
diff --git a/libc/upstream-freebsd/lib/libc/string/wmemcmp.c b/libc/upstream-freebsd/lib/libc/string/wmemcmp.c
deleted file mode 100644
index f1b1b00..0000000
--- a/libc/upstream-freebsd/lib/libc/string/wmemcmp.c
+++ /dev/null
@@ -1,55 +0,0 @@
-/*-
- * SPDX-License-Identifier: BSD-2-Clause
- *
- * Copyright (c)1999 Citrus Project,
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 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.
- *
- *	citrus Id: wmemcmp.c,v 1.2 2000/12/20 14:08:31 itojun Exp
- */
-
-#include <sys/cdefs.h>
-#if 0
-#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: wmemcmp.c,v 1.1 2000/12/23 23:14:37 itojun Exp $");
-#endif /* LIBC_SCCS and not lint */
-#endif
-__FBSDID("$FreeBSD$");
-
-#include <wchar.h>
-
-int
-wmemcmp(const wchar_t *s1, const wchar_t *s2, size_t n)
-{
-	size_t i;
-
-	for (i = 0; i < n; i++) {
-		if (*s1 != *s2) {
-			/* wchar might be unsigned */
-			return *s1 > *s2 ? 1 : -1; 
-		}
-		s1++;
-		s2++;
-	}
-	return 0;
-}
diff --git a/libc/upstream-freebsd/lib/libc/string/wmemcpy.c b/libc/upstream-freebsd/lib/libc/string/wmemcpy.c
deleted file mode 100644
index 30956eb..0000000
--- a/libc/upstream-freebsd/lib/libc/string/wmemcpy.c
+++ /dev/null
@@ -1,46 +0,0 @@
-/*-
- * SPDX-License-Identifier: BSD-2-Clause
- *
- * Copyright (c)1999 Citrus Project,
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 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.
- *
- *	citrus Id: wmemcpy.c,v 1.2 2000/12/20 14:08:31 itojun Exp
- */
-
-#include <sys/cdefs.h>
-#if 0
-#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: wmemcpy.c,v 1.1 2000/12/23 23:14:37 itojun Exp $");
-#endif /* LIBC_SCCS and not lint */
-#endif
-__FBSDID("$FreeBSD$");
-
-#include <string.h>
-#include <wchar.h>
-
-wchar_t *
-wmemcpy(wchar_t * __restrict d, const wchar_t * __restrict s, size_t n)
-{
-	return (wchar_t *)memcpy(d, s, n * sizeof(wchar_t));
-}
diff --git a/libc/upstream-freebsd/lib/libc/string/wmemmove.c b/libc/upstream-freebsd/lib/libc/string/wmemmove.c
deleted file mode 100644
index 5e8da9f..0000000
--- a/libc/upstream-freebsd/lib/libc/string/wmemmove.c
+++ /dev/null
@@ -1,46 +0,0 @@
-/*-
- * SPDX-License-Identifier: BSD-2-Clause
- *
- * Copyright (c)1999 Citrus Project,
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 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.
- *
- *	citrus Id: wmemmove.c,v 1.2 2000/12/20 14:08:31 itojun Exp
- */
-
-#include <sys/cdefs.h>
-#if 0
-#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: wmemmove.c,v 1.1 2000/12/23 23:14:37 itojun Exp $");
-#endif /* LIBC_SCCS and not lint */
-#endif
-__FBSDID("$FreeBSD$");
-
-#include <string.h>
-#include <wchar.h>
-
-wchar_t *
-wmemmove(wchar_t *d, const wchar_t *s, size_t n)
-{
-	return (wchar_t *)memmove(d, s, n * sizeof(wchar_t));
-}
diff --git a/libc/upstream-freebsd/lib/libc/string/wmemset.c b/libc/upstream-freebsd/lib/libc/string/wmemset.c
deleted file mode 100644
index fcf40ef..0000000
--- a/libc/upstream-freebsd/lib/libc/string/wmemset.c
+++ /dev/null
@@ -1,53 +0,0 @@
-/*-
- * SPDX-License-Identifier: BSD-2-Clause
- *
- * Copyright (c)1999 Citrus Project,
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 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.
- *
- *	citrus Id: wmemset.c,v 1.2 2000/12/20 14:08:31 itojun Exp
- */
-
-#include <sys/cdefs.h>
-#if 0
-#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: wmemset.c,v 1.1 2000/12/23 23:14:37 itojun Exp $");
-#endif /* LIBC_SCCS and not lint */
-#endif
-__FBSDID("$FreeBSD$");
-
-#include <wchar.h>
-
-wchar_t	*
-wmemset(wchar_t *s, wchar_t c, size_t n)
-{
-	size_t i;
-	wchar_t *p;
-
-	p = (wchar_t *)s;
-	for (i = 0; i < n; i++) {
-		*p = c;
-		p++;
-	}
-	return s;
-}
diff --git a/libc/upstream-netbsd/android/include/extern.h b/libc/upstream-netbsd/android/include/extern.h
deleted file mode 100644
index b8e6151..0000000
--- a/libc/upstream-netbsd/android/include/extern.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <sys/cdefs.h>
-
-__BEGIN_DECLS
-
-const char* __strsignal(int, char*, size_t);
-
-__END_DECLS
diff --git a/libc/upstream-netbsd/common/lib/libc/hash/sha1/sha1.c b/libc/upstream-netbsd/common/lib/libc/hash/sha1/sha1.c
index cbd60fc..adfeaf4 100644
--- a/libc/upstream-netbsd/common/lib/libc/hash/sha1/sha1.c
+++ b/libc/upstream-netbsd/common/lib/libc/hash/sha1/sha1.c
@@ -1,4 +1,4 @@
-/*	$NetBSD: sha1.c,v 1.6 2009/11/06 20:31:18 joerg Exp $	*/
+/*	$NetBSD: sha1.c,v 1.7 2021/10/28 15:09:08 christos Exp $	*/
 /*	$OpenBSD: sha1.c,v 1.9 1997/07/23 21:12:32 kstailey Exp $	*/
 
 /*
@@ -20,14 +20,14 @@
 #include <sys/cdefs.h>
 
 #if defined(_KERNEL) || defined(_STANDALONE)
-__KERNEL_RCSID(0, "$NetBSD: sha1.c,v 1.6 2009/11/06 20:31:18 joerg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sha1.c,v 1.7 2021/10/28 15:09:08 christos Exp $");
 
 #include <lib/libkern/libkern.h>
 
 #else
 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: sha1.c,v 1.6 2009/11/06 20:31:18 joerg Exp $");
+__RCSID("$NetBSD: sha1.c,v 1.7 2021/10/28 15:09:08 christos Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include "namespace.h"
@@ -262,7 +262,7 @@
 /*
  * Add padding and return the message digest.
  */
-void SHA1Final(uint8_t digest[20], SHA1_CTX *context)
+void SHA1Final(uint8_t digest[SHA1_DIGEST_LENGTH], SHA1_CTX *context)
 {
     unsigned int i;
     uint8_t finalcount[8];
diff --git a/libc/upstream-netbsd/common/lib/libc/stdlib/random.c b/libc/upstream-netbsd/common/lib/libc/stdlib/random.c
index 0e6eac0..19094ce 100644
--- a/libc/upstream-netbsd/common/lib/libc/stdlib/random.c
+++ b/libc/upstream-netbsd/common/lib/libc/stdlib/random.c
@@ -1,4 +1,4 @@
-/*	$NetBSD: random.c,v 1.5 2016/02/08 05:27:24 dholland Exp $	*/
+/*	$NetBSD: random.c,v 1.7 2021/12/12 22:20:52 andvar Exp $	*/
 
 /*
  * Copyright (c) 1983, 1993
@@ -35,7 +35,7 @@
 #if 0
 static char sccsid[] = "@(#)random.c	8.2 (Berkeley) 5/19/95";
 #else
-__RCSID("$NetBSD: random.c,v 1.5 2016/02/08 05:27:24 dholland Exp $");
+__RCSID("$NetBSD: random.c,v 1.7 2021/12/12 22:20:52 andvar Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -79,7 +79,7 @@
  * then initialized to contain information for random number generation with
  * that much state information.  Good sizes for the amount of state
  * information are 32, 64, 128, and 256 bytes.  The state can be switched by
- * calling the setstate() routine with the same array as was initiallized
+ * calling the setstate() routine with the same array as was initialized
  * with initstate().  By default, the package runs with 128 bytes of state
  * information and generates far better random numbers than a linear
  * congruential generator.  If the amount of state information is less than
@@ -189,7 +189,7 @@
  */
 
 /* LINTED */
-static int randtbl[DEG_3 + 1] = {
+static uint32_t randtbl[DEG_3 + 1] = {
 	TYPE_3,
 #ifdef USE_BETTER_RANDOM
 	0x991539b1, 0x16a5bce3, 0x6774a4cd,
@@ -232,8 +232,8 @@
  * in the initialization of randtbl) because the state table pointer is set
  * to point to randtbl[1] (as explained below).
  */
-static int *fptr = &randtbl[SEP_3 + 1];
-static int *rptr = &randtbl[1];
+static uint32_t *fptr = &randtbl[SEP_3 + 1];
+static uint32_t *rptr = &randtbl[1];
 
 /*
  * The following things are the pointer to the state information table, the
@@ -245,11 +245,11 @@
  * this is more efficient than indexing every time to find the address of
  * the last element to see if the front and rear pointers have wrapped.
  */
-static int *state = &randtbl[1];
+static uint32_t *state = &randtbl[1];
 static int rand_type = TYPE_3;
 static int rand_deg = DEG_3;
 static int rand_sep = SEP_3;
-static int *end_ptr = &randtbl[DEG_3 + 1];
+static uint32_t *end_ptr = &randtbl[DEG_3 + 1];
 
 /*
  * srandom:
@@ -340,17 +340,17 @@
 	size_t n)			/* # bytes of state info */
 {
 	void *ostate = (void *)(&state[-1]);
-	int *int_arg_state;
+	uint32_t *int_arg_state;
 
 	_DIAGASSERT(arg_state != NULL);
 
-	int_arg_state = (int *)(void *)arg_state;
+	int_arg_state = (uint32_t *)(void *)arg_state;
 
 	mutex_lock(&random_mutex);
 	if (rand_type == TYPE_0)
 		state[-1] = rand_type;
 	else
-		state[-1] = MAX_TYPES * (int)(rptr - state) + rand_type;
+		state[-1] = MAX_TYPES * (uint32_t)(rptr - state) + rand_type;
 	if (n < BREAK_0) {
 		mutex_unlock(&random_mutex);
 		return (NULL);
@@ -375,13 +375,13 @@
 		rand_deg = DEG_4;
 		rand_sep = SEP_4;
 	}
-	state = (int *) (int_arg_state + 1); /* first location */
+	state = (uint32_t *) (int_arg_state + 1); /* first location */
 	end_ptr = &state[rand_deg];	/* must set end_ptr before srandom */
 	srandom_unlocked(seed);
 	if (rand_type == TYPE_0)
 		int_arg_state[0] = rand_type;
 	else
-		int_arg_state[0] = MAX_TYPES * (int)(rptr - state) + rand_type;
+		int_arg_state[0] = MAX_TYPES * (uint32_t)(rptr - state) + rand_type;
 	mutex_unlock(&random_mutex);
 	return((char *)ostate);
 }
@@ -408,22 +408,22 @@
 char *
 setstate(char *arg_state)		/* pointer to state array */
 {
-	int *new_state;
-	int type;
-	int rear;
+	uint32_t *new_state;
+	uint32_t type;
+	uint32_t rear;
 	void *ostate = (void *)(&state[-1]);
 
 	_DIAGASSERT(arg_state != NULL);
 
-	new_state = (int *)(void *)arg_state;
-	type = (int)(new_state[0] % MAX_TYPES);
-	rear = (int)(new_state[0] / MAX_TYPES);
+	new_state = (uint32_t *)(void *)arg_state;
+	type = (uint32_t)(new_state[0] % MAX_TYPES);
+	rear = (uint32_t)(new_state[0] / MAX_TYPES);
 
 	mutex_lock(&random_mutex);
 	if (rand_type == TYPE_0)
 		state[-1] = rand_type;
 	else
-		state[-1] = MAX_TYPES * (int)(rptr - state) + rand_type;
+		state[-1] = MAX_TYPES * (uint32_t)(rptr - state) + rand_type;
 	switch(type) {
 	case TYPE_0:
 	case TYPE_1:
@@ -438,7 +438,7 @@
 		mutex_unlock(&random_mutex);
 		return (NULL);
 	}
-	state = (int *) (new_state + 1);
+	state = (uint32_t *) (new_state + 1);
 	if (rand_type != TYPE_0) {
 		rptr = &state[rear];
 		fptr = &state[(rear + rand_sep) % rand_deg];
@@ -468,8 +468,8 @@
 static long
 random_unlocked(void)
 {
-	int i;
-	int *f, *r;
+	uint32_t i;
+	uint32_t *f, *r;
 
 	if (rand_type == TYPE_0) {
 		i = state[0];
@@ -481,7 +481,7 @@
 		f = fptr; r = rptr;
 		*f += *r;
 		/* chucking least random bit */
-		i = ((unsigned int)*f >> 1) & 0x7fffffff;
+		i = ((uint32_t)*f >> 1) & 0x7fffffff;
 		if (++f >= end_ptr) {
 			f = state;
 			++r;
diff --git a/libc/upstream-netbsd/lib/libc/gen/psignal.c b/libc/upstream-netbsd/lib/libc/gen/psignal.c
deleted file mode 100644
index 4472be6..0000000
--- a/libc/upstream-netbsd/lib/libc/gen/psignal.c
+++ /dev/null
@@ -1,85 +0,0 @@
-/*	$NetBSD: psignal.c,v 1.23 2012/03/13 21:13:36 christos Exp $	*/
-
-/*
- * Copyright (c) 1983, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-#if 0
-static char sccsid[] = "@(#)psignal.c	8.1 (Berkeley) 6/4/93";
-#else
-__RCSID("$NetBSD: psignal.c,v 1.23 2012/03/13 21:13:36 christos Exp $");
-#endif
-#endif /* LIBC_SCCS and not lint */
-
-#include "namespace.h"
-
-#include <sys/types.h>
-#include <sys/uio.h>
-
-#include <limits.h>
-#include <signal.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "extern.h"
-
-#ifdef __weak_alias
-__weak_alias(psignal,_psignal)
-#endif
-
-void
-psignal(int sig, const char *s)
-{
-	struct iovec *v;
-	struct iovec iov[4];
-	char buf[NL_TEXTMAX];
-
-	v = iov;
-	if (s && *s) {
-		v->iov_base = __UNCONST(s);
-		v->iov_len = strlen(s);
-		v++;
-		v->iov_base = __UNCONST(": ");
-		v->iov_len = 2;
-		v++;
-	}
-	v->iov_base = __UNCONST(__strsignal((int)sig, buf, sizeof(buf)));
-	v->iov_len = strlen(v->iov_base);
-	v++;
-	v->iov_base = __UNCONST("\n");
-	v->iov_len = 1;
-	(void)writev(STDERR_FILENO, iov, (int)((v - iov) + 1));
-}
-
-void
-psiginfo(const siginfo_t *si, const char *s)
-{
-	psignal(si->si_signo, s);
-}
diff --git a/libc/upstream-netbsd/lib/libc/gen/utime.c b/libc/upstream-netbsd/lib/libc/gen/utime.c
deleted file mode 100644
index d41aac7..0000000
--- a/libc/upstream-netbsd/lib/libc/gen/utime.c
+++ /dev/null
@@ -1,65 +0,0 @@
-/*	$NetBSD: utime.c,v 1.14 2012/06/25 22:32:44 abs Exp $	*/
-
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-#if 0
-static char sccsid[] = "@(#)utime.c	8.1 (Berkeley) 6/4/93";
-#else
-__RCSID("$NetBSD: utime.c,v 1.14 2012/06/25 22:32:44 abs Exp $");
-#endif
-#endif /* LIBC_SCCS and not lint */
-
-#include "namespace.h"
-#include <sys/time.h>
-
-#include <assert.h>
-#include <errno.h>
-#include <stddef.h>
-#include <utime.h>
-
-int
-utime(const char *path, const struct utimbuf *times)
-{
-	struct timeval tv[2], *tvp;
-
-	_DIAGASSERT(path != NULL);
-
-	if (times == (struct utimbuf *) NULL)
-		tvp = NULL;
-	else {
-		tv[0].tv_sec = times->actime;
-		tv[1].tv_sec = times->modtime;
-		tv[0].tv_usec = tv[1].tv_usec = 0;
-		tvp = tv;
-	}
-	return (utimes(path, tvp));
-}
diff --git a/libc/upstream-netbsd/lib/libc/regex/engine.c b/libc/upstream-netbsd/lib/libc/regex/engine.c
index ca8b24d..3ad2638 100644
--- a/libc/upstream-netbsd/lib/libc/regex/engine.c
+++ b/libc/upstream-netbsd/lib/libc/regex/engine.c
@@ -1,4 +1,4 @@
-/* $NetBSD: engine.c,v 1.29 2021/02/25 21:47:46 christos Exp $ */
+/* $NetBSD: engine.c,v 1.30 2024/01/23 15:32:54 christos Exp $ */
 
 /*-
  * SPDX-License-Identifier: BSD-3-Clause
@@ -41,7 +41,7 @@
 #ifdef __FBSDID
 __FBSDID("$FreeBSD: head/lib/libc/regex/engine.c 368358 2020-12-05 03:16:05Z kevans $");
 #endif
-__RCSID("$NetBSD: engine.c,v 1.29 2021/02/25 21:47:46 christos Exp $");
+__RCSID("$NetBSD: engine.c,v 1.30 2024/01/23 15:32:54 christos Exp $");
 
 #include <stdbool.h>
 
@@ -784,13 +784,13 @@
 		if (m->pmatch[i].rm_eo == -1)
 			return(NULL);
 		assert(m->pmatch[i].rm_so != -1);
-		len = m->pmatch[i].rm_eo - m->pmatch[i].rm_so;
+		len = (size_t)(m->pmatch[i].rm_eo - m->pmatch[i].rm_so);
 		if (len == 0 && rec++ > MAX_RECURSION)
 			return(NULL);
 		assert(stop - m->beginp >= len);
 		if (sp > stop - len)
 			return(NULL);	/* not enough left to match */
-		ssp = m->offp + m->pmatch[i].rm_so;
+		ssp = m->offp + (size_t)m->pmatch[i].rm_so;
 		if (memcmp(sp, ssp, len) != 0)
 			return(NULL);
 		while (m->g->strip[ss] != SOP(O_BACK, i))
diff --git a/libc/upstream-openbsd/android/include/arc4random.h b/libc/upstream-openbsd/android/include/arc4random.h
index 96f94be..1940398 100644
--- a/libc/upstream-openbsd/android/include/arc4random.h
+++ b/libc/upstream-openbsd/android/include/arc4random.h
@@ -1,4 +1,4 @@
-/*	$OpenBSD: arc4random_linux.h,v 1.7 2014/07/20 20:51:13 bcook Exp $	*/
+/*    $OpenBSD: arc4random_linux.h,v 1.7 2014/07/20 20:51:13 bcook Exp $    */
 
 /*
  * Copyright (c) 1996, David Mazieres <dm@uun.org>
@@ -18,62 +18,56 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-/*
- * Stub functions for portability.
- */
-
-#include <errno.h>
 #include <pthread.h>
-#include <signal.h>
 #include <sys/mman.h>
 #include <sys/prctl.h>
 
 #include <async_safe/log.h>
 
-// Android gets these from "thread_private.h".
-#include "thread_private.h"
-//static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER;
-//#define _ARC4_LOCK()   pthread_mutex_lock(&arc4random_mtx)
-//#define _ARC4_UNLOCK() pthread_mutex_unlock(&arc4random_mtx)
+static pthread_mutex_t g_arc4random_mutex = PTHREAD_MUTEX_INITIALIZER;
+
+void arc4random_mutex_lock() {
+  pthread_mutex_lock(&g_arc4random_mutex);
+}
+
+void arc4random_mutex_unlock() {
+  pthread_mutex_unlock(&g_arc4random_mutex);
+}
+
+#define _ARC4_LOCK() arc4random_mutex_lock()
+#define _ARC4_UNLOCK() arc4random_mutex_unlock()
 
 static inline void _getentropy_fail(void) {
-    async_safe_fatal("getentropy failed: %s", strerror(errno));
+  async_safe_fatal("getentropy failed: %m");
 }
 
-volatile sig_atomic_t _rs_forked;
-
-static inline void
-_rs_forkdetect(void)
-{
-	static pid_t _rs_pid = 0;
-	pid_t pid = getpid();
-
-	if (_rs_pid == 0 || _rs_pid != pid || _rs_forked) {
-		_rs_pid = pid;
-		_rs_forked = 0;
-		if (rs)
-			memset(rs, 0, sizeof(*rs));
-	}
+static inline void _rs_forkdetect(void) {
+  // Not needed thanks to the MADV_WIPEONFORK below.
 }
 
-static inline int
-_rs_allocate(struct _rs **rsp, struct _rsx **rsxp)
-{
-	// OpenBSD's arc4random_linux.h allocates two separate mappings, but for
-	// themselves they just allocate both structs into one mapping like this.
-	struct {
-		struct _rs rs;
-		struct _rsx rsx;
-	} *p;
+static inline int _rs_allocate(struct _rs** rsp, struct _rsx** rsxp) {
+  // OpenBSD's arc4random_linux.h allocates two separate mappings, but for
+  // themselves they just allocate both structs into one mapping like this.
+  struct data {
+    struct _rs rs;
+    struct _rsx rsx;
+  };
+  const size_t size = sizeof(struct data);
 
-	if ((p = mmap(NULL, sizeof(*p), PROT_READ|PROT_WRITE,
-	    MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED)
-		return (-1);
+  struct data* p = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0);
+  if (p == MAP_FAILED) {
+    async_safe_fatal("arc4random data allocation failed: %m");
+  }
 
-	prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, p, sizeof(*p), "arc4random data");
+  // Equivalent to OpenBSD's minherit(MAP_INHERIT_ZERO).
+  if (madvise(p, size, MADV_WIPEONFORK) == -1) {
+    async_safe_fatal("arc4random data MADV_WIPEONFORK failed: %m");
+  }
 
-	*rsp = &p->rs;
-	*rsxp = &p->rsx;
+  // Give the allocation a name to make tombstones more intelligible.
+  prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, p, size, "arc4random data");
 
-	return (0);
+  *rsp = &p->rs;
+  *rsxp = &p->rsx;
+  return 0;
 }
diff --git a/libc/upstream-openbsd/android/include/openbsd-compat.h b/libc/upstream-openbsd/android/include/openbsd-compat.h
index 19f28ad..e0d289f 100644
--- a/libc/upstream-openbsd/android/include/openbsd-compat.h
+++ b/libc/upstream-openbsd/android/include/openbsd-compat.h
@@ -39,6 +39,7 @@
 #define __warn_references(sym,msg)
 
 #define PROTO_NORMAL(x)
+#define WRAP(x) x
 
 #if !defined(ANDROID_HOST_MUSL)
 #define explicit_bzero(p, s) memset_explicit(p, 0, s)
diff --git a/tests/DoNotOptimize.h b/libc/upstream-openbsd/android/include/thread_private.h
similarity index 61%
rename from tests/DoNotOptimize.h
rename to libc/upstream-openbsd/android/include/thread_private.h
index 711d339..c2418e2 100644
--- a/tests/DoNotOptimize.h
+++ b/libc/upstream-openbsd/android/include/thread_private.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012 The Android Open Source Project
+ * Copyright (C) 2025 The Android Open Source Project
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -16,12 +16,9 @@
 
 #pragma once
 
-// From <benchmark/benchmark.h>.
-template <class Tp>
-static inline void DoNotOptimize(Tp const& value) {
-  asm volatile("" : : "r,m"(value) : "memory");
-}
-template <class Tp>
-static inline void DoNotOptimize(Tp& value) {
-  asm volatile("" : "+r,m"(value) : : "memory");
-}
+#include <pthread.h>
+
+// An internal OpenBSD interface, used by gdtoa and res_random.c.
+// Note that these aren't exactly the usual OpenBSD ones which lazy-initialize!
+#define _MUTEX_LOCK(l) pthread_mutex_lock((pthread_mutex_t*) l)
+#define _MUTEX_UNLOCK(l) pthread_mutex_unlock((pthread_mutex_t*) l)
diff --git a/libc/upstream-openbsd/lib/libc/gen/err.c b/libc/upstream-openbsd/lib/libc/gen/err.c
deleted file mode 100644
index 15e1b97..0000000
--- a/libc/upstream-openbsd/lib/libc/gen/err.c
+++ /dev/null
@@ -1,43 +0,0 @@
-/*	$OpenBSD: err.c,v 1.12 2015/08/31 02:53:57 guenther Exp $ */
-/*-
- * Copyright (c) 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <err.h>
-#include <stdarg.h>
-
-__dead void
-err(int eval, const char *fmt, ...)
-{
-	va_list ap;
-
-	va_start(ap, fmt);
-	verr(eval, fmt, ap);
-	va_end(ap);
-}
-DEF_WEAK(err);
diff --git a/libc/upstream-openbsd/lib/libc/gen/errx.c b/libc/upstream-openbsd/lib/libc/gen/errx.c
deleted file mode 100644
index e6b5d23..0000000
--- a/libc/upstream-openbsd/lib/libc/gen/errx.c
+++ /dev/null
@@ -1,43 +0,0 @@
-/*	$OpenBSD: errx.c,v 1.11 2015/08/31 02:53:57 guenther Exp $ */
-/*-
- * Copyright (c) 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <err.h>
-#include <stdarg.h>
-
-__dead void
-errx(int eval, const char *fmt, ...)
-{
-	va_list ap;
-
-	va_start(ap, fmt);
-	verrx(eval, fmt, ap);
-	va_end(ap);
-}
-DEF_WEAK(errx);
diff --git a/libc/upstream-openbsd/lib/libc/gen/fnmatch.c b/libc/upstream-openbsd/lib/libc/gen/fnmatch.c
index 3ec0222..ff6b26e 100644
--- a/libc/upstream-openbsd/lib/libc/gen/fnmatch.c
+++ b/libc/upstream-openbsd/lib/libc/gen/fnmatch.c
@@ -46,11 +46,11 @@
  *
  * Derived from The Open Group Base Specifications Issue 7, IEEE Std 1003.1-2008
  * as described in;
- *   https://pubs.opengroup.org/onlinepubs/9799919799.2024edition/functions/fnmatch.html
+ *   http://pubs.opengroup.org/onlinepubs/9699919799/functions/fnmatch.html
  *
  * Filename pattern matches defined in section 2.13, "Pattern Matching Notation"
  * from chapter 2. "Shell Command Language"
- *   https://pubs.opengroup.org/onlinepubs/9799919799.2024edition/utilities/V3_chap02.html#tag_18_13
+ *   http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_13
  * where; 1. A bracket expression starting with an unquoted <circumflex> '^'
  * character CONTINUES to specify a non-matching list; 2. an explicit <period> '.'
  * in a bracket expression matching list, e.g. "[.abc]" does NOT match a leading
@@ -61,7 +61,7 @@
  *
  * Bracket expansion defined in section 9.3.5, "RE Bracket Expression",
  * from chapter 9, "Regular Expressions"
- *   https://pubs.opengroup.org/onlinepubs/9799919799.2024edition/basedefs/V1_chap09.html#tag_09_03_05
+ *   http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html#tag_09_03_05
  * with no support for collating symbols, equivalence class expressions or
  * character class expressions.  A partial range expression with a leading
  * hyphen following a valid range expression will match only the ordinary
diff --git a/libc/upstream-openbsd/lib/libc/gen/getprogname.c b/libc/upstream-openbsd/lib/libc/gen/getprogname.c
deleted file mode 100644
index a020830..0000000
--- a/libc/upstream-openbsd/lib/libc/gen/getprogname.c
+++ /dev/null
@@ -1,24 +0,0 @@
-/* $OpenBSD: getprogname.c,v 1.4 2016/03/13 18:34:20 guenther Exp $ */
-/*
- * Copyright (c) 2013 Antoine Jacoutot <ajacoutot@openbsd.org>
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * 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.
- */
-
-#include <stdlib.h>
-
-const char *
-getprogname(void)
-{
-	return (__progname);
-}
diff --git a/libc/upstream-openbsd/lib/libc/gen/setprogname.c b/libc/upstream-openbsd/lib/libc/gen/setprogname.c
deleted file mode 100644
index bce4cbd..0000000
--- a/libc/upstream-openbsd/lib/libc/gen/setprogname.c
+++ /dev/null
@@ -1,31 +0,0 @@
-/* $OpenBSD: setprogname.c,v 1.6 2017/09/17 06:38:03 otto Exp $ */
-/*
- * Copyright (c) 2013 Antoine Jacoutot <ajacoutot@openbsd.org>
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * 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.
- */
-
-#include <string.h>
-#include <stdlib.h>
-
-void
-setprogname(const char *progname)
-{
-	char *tmpn;
-
-	tmpn = strrchr(progname, '/');
-	if (tmpn == NULL)
-		__progname = (char *)progname;
-	else
-		__progname = tmpn + 1;
-}
diff --git a/libc/upstream-openbsd/lib/libc/gen/verr.c b/libc/upstream-openbsd/lib/libc/gen/verr.c
deleted file mode 100644
index b27b9ca..0000000
--- a/libc/upstream-openbsd/lib/libc/gen/verr.c
+++ /dev/null
@@ -1,52 +0,0 @@
-/*	$OpenBSD: verr.c,v 1.11 2016/03/13 18:34:20 guenther Exp $ */
-/*-
- * Copyright (c) 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <err.h>
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdarg.h>
-
-__dead void
-verr(int eval, const char *fmt, va_list ap)
-{
-	int sverrno;
-
-	sverrno = errno;
-	(void)fprintf(stderr, "%s: ", __progname);
-	if (fmt != NULL) {
-		(void)vfprintf(stderr, fmt, ap);
-		(void)fprintf(stderr, ": ");
-	}
-	(void)fprintf(stderr, "%s\n", strerror(sverrno));
-	exit(eval);
-}
-DEF_WEAK(verr);
diff --git a/libc/upstream-openbsd/lib/libc/gen/verrx.c b/libc/upstream-openbsd/lib/libc/gen/verrx.c
deleted file mode 100644
index 0c9308f..0000000
--- a/libc/upstream-openbsd/lib/libc/gen/verrx.c
+++ /dev/null
@@ -1,45 +0,0 @@
-/*	$OpenBSD: verrx.c,v 1.11 2016/03/13 18:34:20 guenther Exp $ */
-/*-
- * Copyright (c) 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <err.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-
-__dead void
-verrx(int eval, const char *fmt, va_list ap)
-{
-	(void)fprintf(stderr, "%s: ", __progname);
-	if (fmt != NULL)
-		(void)vfprintf(stderr, fmt, ap);
-	(void)fprintf(stderr, "\n");
-	exit(eval);
-}
-DEF_WEAK(verrx);
diff --git a/libc/upstream-openbsd/lib/libc/gen/vwarn.c b/libc/upstream-openbsd/lib/libc/gen/vwarn.c
deleted file mode 100644
index 457d619..0000000
--- a/libc/upstream-openbsd/lib/libc/gen/vwarn.c
+++ /dev/null
@@ -1,51 +0,0 @@
-/*	$OpenBSD: vwarn.c,v 1.11 2016/03/13 18:34:20 guenther Exp $ */
-/*-
- * Copyright (c) 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <err.h>
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdarg.h>
-
-void
-vwarn(const char *fmt, va_list ap)
-{
-	int sverrno;
-
-	sverrno = errno;
-	(void)fprintf(stderr, "%s: ", __progname);
-	if (fmt != NULL) {
-		(void)vfprintf(stderr, fmt, ap);
-		(void)fprintf(stderr, ": ");
-	}
-	(void)fprintf(stderr, "%s\n", strerror(sverrno));
-}
-DEF_WEAK(vwarn);
diff --git a/libc/upstream-openbsd/lib/libc/gen/vwarnx.c b/libc/upstream-openbsd/lib/libc/gen/vwarnx.c
deleted file mode 100644
index 146e267..0000000
--- a/libc/upstream-openbsd/lib/libc/gen/vwarnx.c
+++ /dev/null
@@ -1,44 +0,0 @@
-/*	$OpenBSD: vwarnx.c,v 1.11 2016/03/13 18:34:20 guenther Exp $ */
-/*-
- * Copyright (c) 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <err.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-
-void
-vwarnx(const char *fmt, va_list ap)
-{
-	(void)fprintf(stderr, "%s: ", __progname);
-	if (fmt != NULL)
-		(void)vfprintf(stderr, fmt, ap);
-	(void)fprintf(stderr, "\n");
-}
-DEF_WEAK(vwarnx);
diff --git a/libc/upstream-openbsd/lib/libc/gen/warn.c b/libc/upstream-openbsd/lib/libc/gen/warn.c
deleted file mode 100644
index 6784cf6..0000000
--- a/libc/upstream-openbsd/lib/libc/gen/warn.c
+++ /dev/null
@@ -1,43 +0,0 @@
-/*	$OpenBSD: warn.c,v 1.11 2015/08/31 02:53:57 guenther Exp $ */
-/*-
- * Copyright (c) 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <err.h>
-#include <stdarg.h>
-
-void
-warn(const char *fmt, ...)
-{
-	va_list ap;
-
-	va_start(ap, fmt);
-	vwarn(fmt, ap);
-	va_end(ap);
-}
-DEF_WEAK(warn);
diff --git a/libc/upstream-openbsd/lib/libc/gen/warnx.c b/libc/upstream-openbsd/lib/libc/gen/warnx.c
deleted file mode 100644
index 723bc0d..0000000
--- a/libc/upstream-openbsd/lib/libc/gen/warnx.c
+++ /dev/null
@@ -1,43 +0,0 @@
-/*	$OpenBSD: warnx.c,v 1.10 2015/08/31 02:53:57 guenther Exp $ */
-/*-
- * Copyright (c) 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <err.h>
-#include <stdarg.h>
-
-void
-warnx(const char *fmt, ...)
-{
-	va_list ap;
-
-	va_start(ap, fmt);
-	vwarnx(fmt, ap);
-	va_end(ap);
-}
-DEF_WEAK(warnx);
diff --git a/libc/upstream-openbsd/lib/libc/locale/wcscoll.c b/libc/upstream-openbsd/lib/libc/locale/wcscoll.c
deleted file mode 100644
index 8ec32ce..0000000
--- a/libc/upstream-openbsd/lib/libc/locale/wcscoll.c
+++ /dev/null
@@ -1,41 +0,0 @@
-/*	$OpenBSD: wcscoll.c,v 1.2 2012/12/05 23:20:00 deraadt Exp $ */
-/*	$NetBSD: wcscoll.c,v 1.1 2003/03/02 22:18:16 tshiozak Exp $	*/
-
-/*-
- * Copyright (c)2003 Citrus Project,
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 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.
- */
-
-#include <assert.h>
-#include <wchar.h>
-
-/*
- * Compare strings with using collating information.
- */
-int
-wcscoll(const wchar_t *s1, const wchar_t *s2)
-{
-	/* XXX: LC_COLLATE should be implemented. */
-	return (wcscmp(s1, s2));
-}
diff --git a/libc/upstream-openbsd/lib/libc/locale/wcsxfrm.c b/libc/upstream-openbsd/lib/libc/locale/wcsxfrm.c
deleted file mode 100644
index 3d1e580..0000000
--- a/libc/upstream-openbsd/lib/libc/locale/wcsxfrm.c
+++ /dev/null
@@ -1,42 +0,0 @@
-/*	$OpenBSD: wcsxfrm.c,v 1.3 2017/09/05 03:16:13 schwarze Exp $ */
-/*	$NetBSD: multibyte_sb.c,v 1.4 2003/08/07 16:43:04 agc Exp $ */
-
-/*
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <wchar.h>
-
-size_t 
-wcsxfrm(wchar_t *dest, const wchar_t *src, size_t n)
-{
-	if (n == 0)
-		return wcslen(src);
-	return wcslcpy(dest, src, n);
-}
-DEF_STRONG(wcsxfrm);
diff --git a/libc/upstream-openbsd/lib/libc/net/htonl.c b/libc/upstream-openbsd/lib/libc/net/htonl.c
deleted file mode 100644
index 58bfb46..0000000
--- a/libc/upstream-openbsd/lib/libc/net/htonl.c
+++ /dev/null
@@ -1,15 +0,0 @@
-/*	$OpenBSD: htonl.c,v 1.8 2024/04/15 14:30:48 naddy Exp $ */
-/*
- * Public domain.
- */
-
-#include <sys/types.h>
-#include <endian.h>
-
-#undef htonl
-
-uint32_t
-htonl(uint32_t x)
-{
-	return htobe32(x);
-}
diff --git a/libc/upstream-openbsd/lib/libc/net/htons.c b/libc/upstream-openbsd/lib/libc/net/htons.c
deleted file mode 100644
index 28b13ce..0000000
--- a/libc/upstream-openbsd/lib/libc/net/htons.c
+++ /dev/null
@@ -1,15 +0,0 @@
-/*	$OpenBSD: htons.c,v 1.10 2024/04/15 14:30:48 naddy Exp $ */
-/*
- * Public domain.
- */
-
-#include <sys/types.h>
-#include <endian.h>
-
-#undef htons
-
-uint16_t
-htons(uint16_t x)
-{
-	return htobe16(x);
-}
diff --git a/libc/upstream-openbsd/lib/libc/net/inet_pton.c b/libc/upstream-openbsd/lib/libc/net/inet_pton.c
index 5d7148e..45bafd2 100644
--- a/libc/upstream-openbsd/lib/libc/net/inet_pton.c
+++ b/libc/upstream-openbsd/lib/libc/net/inet_pton.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: inet_pton.c,v 1.10 2015/09/13 21:36:08 guenther Exp $	*/
+/*	$OpenBSD: inet_pton.c,v 1.11 2024/09/03 17:05:59 deraadt Exp $	*/
 
 /* Copyright (c) 1996 by Internet Software Consortium.
  *
@@ -87,7 +87,7 @@
 
 			if (new > 255)
 				return (0);
-			if (! saw_digit) {
+			if (!saw_digit) {
 				if (++octets > 4)
 					return (0);
 				saw_digit = 1;
diff --git a/libc/upstream-openbsd/lib/libc/net/ntohl.c b/libc/upstream-openbsd/lib/libc/net/ntohl.c
deleted file mode 100644
index 7592398..0000000
--- a/libc/upstream-openbsd/lib/libc/net/ntohl.c
+++ /dev/null
@@ -1,15 +0,0 @@
-/*	$OpenBSD: ntohl.c,v 1.8 2024/04/15 14:30:48 naddy Exp $ */
-/*
- * Public domain.
- */
-
-#include <sys/types.h>
-#include <endian.h>
-
-#undef ntohl
-
-uint32_t
-ntohl(uint32_t x)
-{
-	return be32toh(x);
-}
diff --git a/libc/upstream-openbsd/lib/libc/net/ntohs.c b/libc/upstream-openbsd/lib/libc/net/ntohs.c
deleted file mode 100644
index ef22ea3..0000000
--- a/libc/upstream-openbsd/lib/libc/net/ntohs.c
+++ /dev/null
@@ -1,15 +0,0 @@
-/*	$OpenBSD: ntohs.c,v 1.10 2024/04/15 14:30:48 naddy Exp $ */
-/*
- * Public domain.
- */
-
-#include <sys/types.h>
-#include <endian.h>
-
-#undef ntohs
-
-uint16_t
-ntohs(uint16_t x)
-{
-	return be16toh(x);
-}
diff --git a/libc/upstream-openbsd/lib/libc/net/res_random.c b/libc/upstream-openbsd/lib/libc/net/res_random.c
index 72b9c41..447a240 100644
--- a/libc/upstream-openbsd/lib/libc/net/res_random.c
+++ b/libc/upstream-openbsd/lib/libc/net/res_random.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: res_random.c,v 1.23 2015/10/05 02:57:16 guenther Exp $ */
+/* $OpenBSD: res_random.c,v 1.27 2024/09/03 18:21:55 op Exp $ */
 
 /*
  * Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de>
@@ -51,7 +51,7 @@
  * The transaction id is determined by:
  * id[n] = seed xor (g^X[n] mod n)
  *
- * Effectivly the id is restricted to the lower 15 bits, thus
+ * Effectively the id is restricted to the lower 15 bits, thus
  * yielding two different cycles by toggling the msb on and off.
  * This avoids reuse issues caused by reseeding.
  *
@@ -70,7 +70,7 @@
 
 #include "thread_private.h"
 
-#define RU_OUT  	180	/* Time after wich will be reseeded */
+#define RU_OUT  	180	/* Time after which will be reseeded */
 #define RU_MAX		30000	/* Uniq cycle, avoid blackjack prediction */
 #define RU_GEN		2	/* Starting generator */
 #define RU_N		32749	/* RU_N-1 = 2*2*3*2729 */
@@ -219,7 +219,7 @@
 	if (ru_prf != NULL)
 		arc4random_buf(ru_prf, sizeof(*ru_prf));
 
-	clock_gettime(CLOCK_MONOTONIC, &ts);
+	WRAP(clock_gettime)(CLOCK_MONOTONIC, &ts);
 	ru_reseed = ts.tv_sec + RU_OUT;
 	ru_msb = ru_msb == 0x8000 ? 0 : 0x8000; 
 }
@@ -230,12 +230,12 @@
 	struct timespec ts;
 	pid_t pid;
 	u_int r;
-	_THREAD_PRIVATE_MUTEX(random);
+	static void *randomid_mutex;
 
-	clock_gettime(CLOCK_MONOTONIC, &ts);
+	WRAP(clock_gettime)(CLOCK_MONOTONIC, &ts);
 	pid = getpid();
 
-	_THREAD_PRIVATE_MUTEX_LOCK(random);
+	_MUTEX_LOCK(&randomid_mutex);
 
 	if (ru_counter >= RU_MAX || ts.tv_sec > ru_reseed || pid != ru_pid) {
 		res_initid();
@@ -248,7 +248,7 @@
 
 	r = permute15(ru_seed ^ pmod(ru_g, ru_seed2 + ru_x, RU_N)) | ru_msb;
 
-	_THREAD_PRIVATE_MUTEX_UNLOCK(random);
+	_MUTEX_UNLOCK(&randomid_mutex);
 
 	return (r);
 }
diff --git a/libc/upstream-openbsd/lib/libc/stdio/fgetln.c b/libc/upstream-openbsd/lib/libc/stdio/fgetln.c
deleted file mode 100644
index 903dbd6..0000000
--- a/libc/upstream-openbsd/lib/libc/stdio/fgetln.c
+++ /dev/null
@@ -1,146 +0,0 @@
-/*	$OpenBSD: fgetln.c,v 1.17 2017/03/17 14:53:08 deraadt Exp $ */
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include "local.h"
-
-/*
- * Expand the line buffer.  Return -1 on error.
- */
-static int
-__slbexpand(FILE *fp, size_t newsize)
-{
-	void *p;
-
-	if (fp->_lb._size >= newsize)
-		return (0);
-	if ((p = recallocarray(fp->_lb._base, fp->_lb._size, newsize, 1)) == NULL)
-		return (-1);
-	fp->_lb._base = p;
-	fp->_lb._size = newsize;
-	return (0);
-}
-
-/*
- * Get an input line.  The returned pointer often (but not always)
- * points into a stdio buffer.  Fgetline does not alter the text of
- * the returned line (which is thus not a C string because it will
- * not necessarily end with '\0'), but does allow callers to modify
- * it if they wish.  Thus, we set __SMOD in case the caller does.
- */
-char *
-fgetln(FILE *fp, size_t *lenp)
-{
-	unsigned char *p;
-	char *ret;
-	size_t len;
-	size_t off;
-
-	FLOCKFILE(fp);
-	_SET_ORIENTATION(fp, -1);
-
-	/* make sure there is input */
-	if (fp->_r <= 0 && __srefill(fp))
-		goto error;
-
-	/* look for a newline in the input */
-	if ((p = memchr(fp->_p, '\n', fp->_r)) != NULL) {
-		/*
-		 * Found one.  Flag buffer as modified to keep fseek from
-		 * `optimising' a backward seek, in case the user stomps on
-		 * the text.
-		 */
-		p++;		/* advance over it */
-		ret = (char *)fp->_p;
-		*lenp = len = p - fp->_p;
-		fp->_flags |= __SMOD;
-		fp->_r -= len;
-		fp->_p = p;
-		FUNLOCKFILE(fp);
-		return (ret);
-	}
-
-	/*
-	 * We have to copy the current buffered data to the line buffer.
-	 * As a bonus, though, we can leave off the __SMOD.
-	 *
-	 * OPTIMISTIC is length that we (optimistically) expect will
-	 * accommodate the `rest' of the string, on each trip through the
-	 * loop below.
-	 */
-#define OPTIMISTIC 80
-
-	for (len = fp->_r, off = 0;; len += fp->_r) {
-		size_t diff;
-
-		/*
-		 * Make sure there is room for more bytes.  Copy data from
-		 * file buffer to line buffer, refill file and look for
-		 * newline.  The loop stops only when we find a newline.
-		 */
-		if (__slbexpand(fp, len + OPTIMISTIC))
-			goto error;
-		(void)memcpy(fp->_lb._base + off, fp->_p, len - off);
-		off = len;
-		if (__srefill(fp)) {
-			if (fp->_flags & __SEOF)
-				break;
-			goto error;
-		}
-		if ((p = memchr(fp->_p, '\n', fp->_r)) == NULL)
-			continue;
-
-		/* got it: finish up the line (like code above) */
-		p++;
-		diff = p - fp->_p;
-		len += diff;
-		if (__slbexpand(fp, len))
-			goto error;
-		(void)memcpy(fp->_lb._base + off, fp->_p, diff);
-		fp->_r -= diff;
-		fp->_p = p;
-		break;
-	}
-	*lenp = len;
-	ret = (char *)fp->_lb._base;
-	FUNLOCKFILE(fp);
-	return (ret);
-
-error:
-	FUNLOCKFILE(fp);
-	*lenp = 0;
-	return (NULL);
-}
-DEF_WEAK(fgetln);
diff --git a/libc/upstream-openbsd/lib/libc/stdio/fwide.c b/libc/upstream-openbsd/lib/libc/stdio/fwide.c
deleted file mode 100644
index 4b93d59..0000000
--- a/libc/upstream-openbsd/lib/libc/stdio/fwide.c
+++ /dev/null
@@ -1,67 +0,0 @@
-/*	$OpenBSD: fwide.c,v 1.6 2019/12/03 05:03:37 asou Exp $	*/
-/* $NetBSD: fwide.c,v 1.2 2003/01/18 11:29:54 thorpej Exp $ */
-
-/*-
- * Copyright (c)2001 Citrus Project,
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 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.
- *
- * $Citrus$
- */
-
-#include <stdio.h>
-#include <wchar.h>
-#include "local.h"
-
-int
-fwide(FILE *fp, int mode)
-{
-	struct wchar_io_data *wcio;
-
-	/*
-	 * this implementation use only -1, 0, 1
-	 * for mode value.
-	 * (we don't need to do this, but
-	 *  this can make things simpler.)
-	 */
-	if (mode > 0)
-		mode = 1;
-	else if (mode < 0)
-		mode = -1;
-
-	FLOCKFILE(fp);
-	wcio = WCIO_GET(fp);
-	if (!wcio) {
-		FUNLOCKFILE(fp);
-		return 0; /* XXX */
-	}
-
-	if (wcio->wcio_mode == 0 && mode != 0)
-		wcio->wcio_mode = mode;
-	else
-		mode = wcio->wcio_mode;
-	FUNLOCKFILE(fp);
-
-	return mode;
-}
-DEF_STRONG(fwide);
diff --git a/libc/upstream-openbsd/lib/libc/stdio/makebuf.c b/libc/upstream-openbsd/lib/libc/stdio/makebuf.c
deleted file mode 100644
index b771a40..0000000
--- a/libc/upstream-openbsd/lib/libc/stdio/makebuf.c
+++ /dev/null
@@ -1,106 +0,0 @@
-/*	$OpenBSD: makebuf.c,v 1.10 2019/06/28 13:32:42 deraadt Exp $ */
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include "local.h"
-
-/*
- * Allocate a file buffer, or switch to unbuffered I/O.
- * Per the ANSI C standard, ALL tty devices default to line buffered.
- *
- * As a side effect, we set __SOPT or __SNPT (en/dis-able fseek
- * optimisation) right after the fstat() that finds the buffer size.
- */
-void
-__smakebuf(FILE *fp)
-{
-	void *p;
-	int flags;
-	size_t size;
-	int couldbetty;
-
-	if (fp->_flags & __SNBF) {
-		fp->_bf._base = fp->_p = fp->_nbuf;
-		fp->_bf._size = 1;
-		return;
-	}
-	flags = __swhatbuf(fp, &size, &couldbetty);
-	if ((p = malloc(size)) == NULL) {
-		fp->_flags |= __SNBF;
-		fp->_bf._base = fp->_p = fp->_nbuf;
-		fp->_bf._size = 1;
-		return;
-	}
-	flags |= __SMBF;
-	fp->_bf._base = fp->_p = p;
-	fp->_bf._size = size;
-	if (couldbetty && isatty(fp->_file))
-		flags |= __SLBF;
-	fp->_flags |= flags;
-}
-
-/*
- * Internal routine to determine `proper' buffering for a file.
- */
-int
-__swhatbuf(FILE *fp, size_t *bufsize, int *couldbetty)
-{
-	struct stat st;
-
-	if (fp->_file < 0 || fstat(fp->_file, &st) == -1) {
-		*couldbetty = 0;
-		*bufsize = BUFSIZ;
-		return (__SNPT);
-	}
-
-	/* could be a tty iff it is a character device */
-	*couldbetty = S_ISCHR(st.st_mode);
-	if (st.st_blksize == 0) {
-		*bufsize = BUFSIZ;
-		return (__SNPT);
-	}
-
-	/*
-	 * Optimise fseek() only if it is a regular file.  (The test for
-	 * __sseek is mainly paranoia.)  It is safe to set _blksize
-	 * unconditionally; it will only be used if __SOPT is also set.
-	 */
-	*bufsize = st.st_blksize;
-	fp->_blksize = st.st_blksize;
-	return ((st.st_mode & S_IFMT) == S_IFREG && fp->_seek == __sseek ?
-	    __SOPT : __SNPT);
-}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/setvbuf.c b/libc/upstream-openbsd/lib/libc/stdio/setvbuf.c
deleted file mode 100644
index 74a1695..0000000
--- a/libc/upstream-openbsd/lib/libc/stdio/setvbuf.c
+++ /dev/null
@@ -1,162 +0,0 @@
-/*	$OpenBSD: setvbuf.c,v 1.15 2022/09/28 16:44:14 gnezdo Exp $ */
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <limits.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include "local.h"
-
-/*
- * Set one of the three kinds of buffering, optionally including
- * a buffer.
- */
-int
-setvbuf(FILE *fp, char *buf, int mode, size_t size)
-{
-	int ret, flags;
-	size_t iosize;
-	int ttyflag;
-
-	/*
-	 * Verify arguments.  The `int' limit on `size' is due to this
-	 * particular implementation.  Note, buf and size are ignored
-	 * when setting _IONBF.
-	 */
-	if (mode != _IONBF)
-		if ((mode != _IOFBF && mode != _IOLBF) || size > INT_MAX)
-			return (EOF);
-
-	/*
-	 * Write current buffer, if any.  Discard unread input (including
-	 * ungetc data), cancel line buffering, and free old buffer if
-	 * malloc()ed.  We also clear any eof condition, as if this were
-	 * a seek.
-	 */
-	FLOCKFILE(fp);
-	ret = 0;
-	(void)__sflush(fp);
-	if (HASUB(fp))
-		FREEUB(fp);
-	WCIO_FREE(fp);
-	fp->_r = fp->_lbfsize = 0;
-	flags = fp->_flags;
-	if (flags & __SMBF)
-		free(fp->_bf._base);
-	flags &= ~(__SLBF | __SNBF | __SMBF | __SOPT | __SNPT | __SEOF);
-
-	/* If setting unbuffered mode, skip all the hard work. */
-	if (mode == _IONBF)
-		goto nbf;
-
-	/*
-	 * Find optimal I/O size for seek optimization.  This also returns
-	 * a `tty flag' to suggest that we check isatty(fd), but we do not
-	 * care since our caller told us how to buffer.
-	 */
-	flags |= __swhatbuf(fp, &iosize, &ttyflag);
-	if (size == 0) {
-		buf = NULL;	/* force local allocation */
-		size = iosize;
-	}
-
-	/* Allocate buffer if needed. */
-	if (buf == NULL) {
-		if ((buf = malloc(size)) == NULL) {
-			/*
-			 * Unable to honor user's request.  We will return
-			 * failure, but try again with file system size.
-			 */
-			ret = EOF;
-			if (size != iosize) {
-				size = iosize;
-				buf = malloc(size);
-			}
-		}
-		if (buf == NULL) {
-			/* No luck; switch to unbuffered I/O. */
-nbf:
-			fp->_flags = flags | __SNBF;
-			fp->_w = 0;
-			fp->_bf._base = fp->_p = fp->_nbuf;
-			fp->_bf._size = 1;
-			FUNLOCKFILE(fp);
-			return (ret);
-		}
-		flags |= __SMBF;
-	}
-
-	/*
-	 * We're committed to buffering from here, so make sure we've
-	 * registered to flush buffers on exit.
-	 */
-	if (!__sdidinit)
-		__sinit();
-
-	/*
-	 * Kill any seek optimization if the buffer is not the
-	 * right size.
-	 *
-	 * SHOULD WE ALLOW MULTIPLES HERE (i.e., ok iff (size % iosize) == 0)?
-	 */
-	if (size != iosize)
-		flags |= __SNPT;
-
-	/*
-	 * Fix up the FILE fields, and set __cleanup for output flush on
-	 * exit (since we are buffered in some way).
-	 */
-	if (mode == _IOLBF)
-		flags |= __SLBF;
-	fp->_flags = flags;
-	fp->_bf._base = fp->_p = (unsigned char *)buf;
-	fp->_bf._size = size;
-	/* fp->_lbfsize is still 0 */
-	if (flags & __SWR) {
-		/*
-		 * Begin or continue writing: see __swsetup().  Note
-		 * that __SNBF is impossible (it was handled earlier).
-		 */
-		if (flags & __SLBF) {
-			fp->_w = 0;
-			fp->_lbfsize = -fp->_bf._size;
-		} else
-			fp->_w = size;
-	} else {
-		/* begin/continue reading, or stay in intermediate state */
-		fp->_w = 0;
-	}
-	FUNLOCKFILE(fp);
-
-	return (ret);
-}
-DEF_STRONG(setvbuf);
diff --git a/libc/upstream-openbsd/lib/libc/stdlib/abs.c b/libc/upstream-openbsd/lib/libc/stdlib/abs.c
deleted file mode 100644
index 0e39cc5..0000000
--- a/libc/upstream-openbsd/lib/libc/stdlib/abs.c
+++ /dev/null
@@ -1,38 +0,0 @@
-/*	$OpenBSD: abs.c,v 1.6 2015/09/13 08:31:47 guenther Exp $ */
-/*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <stdlib.h>
-
-int
-abs(int j)
-{
-	return(j < 0 ? -j : j);
-}
-DEF_STRONG(abs);
diff --git a/libc/upstream-openbsd/lib/libc/stdlib/div.c b/libc/upstream-openbsd/lib/libc/stdlib/div.c
deleted file mode 100644
index 5e6164f..0000000
--- a/libc/upstream-openbsd/lib/libc/stdlib/div.c
+++ /dev/null
@@ -1,72 +0,0 @@
-/*	$OpenBSD: div.c,v 1.7 2022/12/27 17:10:06 jmc Exp $ */
-/*
- * Copyright (c) 1990 Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <stdlib.h>		/* div_t */
-
-div_t
-div(int num, int denom)
-{
-	div_t r;
-
-	r.quot = num / denom;
-	r.rem = num % denom;
-	/*
-	 * The ANSI standard says that |r.quot| <= |n/d|, where
-	 * n/d is to be computed in infinite precision.  In other
-	 * words, we should always truncate the quotient towards
-	 * 0, never -infinity.
-	 *
-	 * Machine division and remainder may work either way when
-	 * one or both of n or d is negative.  If only one is
-	 * negative and r.quot has been truncated towards -inf,
-	 * r.rem will have the same sign as denom and the opposite
-	 * sign of num; if both are negative and r.quot has been
-	 * truncated towards -inf, r.rem will be positive (will
-	 * have the opposite sign of num).  These are considered
-	 * `wrong'.
-	 *
-	 * If both are num and denom are positive, r will always
-	 * be positive.
-	 *
-	 * This all boils down to:
-	 *	if num >= 0, but r.rem < 0, we got the wrong answer.
-	 * In that case, to get the right answer, add 1 to r.quot and
-	 * subtract denom from r.rem.
-	 */
-	if (num >= 0 && r.rem < 0) {
-		r.quot++;
-		r.rem -= denom;
-	}
-	return (r);
-}
-DEF_STRONG(div);
diff --git a/libc/upstream-openbsd/lib/libc/stdlib/getenv.c b/libc/upstream-openbsd/lib/libc/stdlib/getenv.c
index 054497b..068d70a 100644
--- a/libc/upstream-openbsd/lib/libc/stdlib/getenv.c
+++ b/libc/upstream-openbsd/lib/libc/stdlib/getenv.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: getenv.c,v 1.12 2016/03/13 18:34:21 guenther Exp $ */
+/*	$OpenBSD: getenv.c,v 1.13 2024/07/10 14:17:58 jca Exp $ */
 /*
  * Copyright (c) 1987, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -39,8 +39,6 @@
  *	Sets offset to be the offset of the name/value combination in the
  *	environmental array, for use by putenv(3), setenv(3) and unsetenv(3).
  *	Explicitly removes '=' in argument name.
- *
- *	This routine *should* be a static; don't use it.
  */
 char *
 __findenv(const char *name, int len, int *offset)
diff --git a/libc/upstream-openbsd/lib/libc/stdlib/imaxabs.c b/libc/upstream-openbsd/lib/libc/stdlib/imaxabs.c
deleted file mode 100644
index b7e910e..0000000
--- a/libc/upstream-openbsd/lib/libc/stdlib/imaxabs.c
+++ /dev/null
@@ -1,38 +0,0 @@
-/*	$OpenBSD: imaxabs.c,v 1.1 2006/01/13 17:58:09 millert Exp $	*/
-
-/*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <inttypes.h>
-
-intmax_t
-imaxabs(intmax_t j)
-{
-	return (j < 0 ? -j : j);
-}
diff --git a/libc/upstream-openbsd/lib/libc/stdlib/imaxdiv.c b/libc/upstream-openbsd/lib/libc/stdlib/imaxdiv.c
deleted file mode 100644
index 0515a94..0000000
--- a/libc/upstream-openbsd/lib/libc/stdlib/imaxdiv.c
+++ /dev/null
@@ -1,50 +0,0 @@
-/*	$OpenBSD: imaxdiv.c,v 1.1 2006/01/13 17:58:09 millert Exp $	*/
-/*
- * Copyright (c) 1990 Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <inttypes.h>		/* imaxdiv_t */
-
-imaxdiv_t
-imaxdiv(intmax_t num, intmax_t denom)
-{
-	imaxdiv_t r;
-
-	/* see div.c for comments */
-
-	r.quot = num / denom;
-	r.rem = num % denom;
-	if (num >= 0 && r.rem < 0) {
-		r.quot++;
-		r.rem -= denom;
-	}
-	return (r);
-}
diff --git a/libc/upstream-openbsd/lib/libc/stdlib/insque.c b/libc/upstream-openbsd/lib/libc/stdlib/insque.c
deleted file mode 100644
index 590ff83..0000000
--- a/libc/upstream-openbsd/lib/libc/stdlib/insque.c
+++ /dev/null
@@ -1,54 +0,0 @@
-/*	$OpenBSD: insque.c,v 1.3 2014/08/15 04:14:36 guenther Exp $	*/
-
-/*
- *  Copyright (c) 1993 John Brezak
- *  All rights reserved.
- * 
- *  Redistribution and use in source and binary forms, with or without
- *  modification, are permitted provided that the following conditions
- *  are met:
- *  1. Redistributions of source code must retain the above copyright
- *     notice, this list of conditions and the following disclaimer.
- *  2. Redistributions in binary form must reproduce the above copyright
- *     notice, this list of conditions and the following disclaimer in the
- *     documentation and/or other materials provided with the distribution.
- *  3. The name of the author may 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.
- */
-
-#include <stdlib.h>
-#include <search.h>
-
-struct qelem {
-        struct qelem *q_forw;
-        struct qelem *q_back;
-};
-
-void
-insque(void *entry, void *pred)
-{
-	struct qelem *e = entry;
-	struct qelem *p = pred;
-
-	if (p == NULL)
-		e->q_forw = e->q_back = NULL;
-	else {
-		e->q_forw = p->q_forw;
-		e->q_back = p;
-		if (p->q_forw != NULL)
-			p->q_forw->q_back = e;
-		p->q_forw = e;
-	}
-}
diff --git a/libc/upstream-openbsd/lib/libc/stdlib/labs.c b/libc/upstream-openbsd/lib/libc/stdlib/labs.c
deleted file mode 100644
index ca60b9a..0000000
--- a/libc/upstream-openbsd/lib/libc/stdlib/labs.c
+++ /dev/null
@@ -1,37 +0,0 @@
-/*	$OpenBSD: labs.c,v 1.5 2005/08/08 08:05:36 espie Exp $ */
-/*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <stdlib.h>
-
-long
-labs(long j)
-{
-	return(j < 0 ? -j : j);
-}
diff --git a/libc/upstream-openbsd/lib/libc/stdlib/ldiv.c b/libc/upstream-openbsd/lib/libc/stdlib/ldiv.c
deleted file mode 100644
index 775065f..0000000
--- a/libc/upstream-openbsd/lib/libc/stdlib/ldiv.c
+++ /dev/null
@@ -1,50 +0,0 @@
-/*	$OpenBSD: ldiv.c,v 1.5 2005/08/08 08:05:36 espie Exp $ */
-/*
- * Copyright (c) 1990 Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <stdlib.h>		/* ldiv_t */
-
-ldiv_t
-ldiv(long num, long denom)
-{
-	ldiv_t r;
-
-	/* see div.c for comments */
-
-	r.quot = num / denom;
-	r.rem = num % denom;
-	if (num >= 0 && r.rem < 0) {
-		r.quot++;
-		r.rem -= denom;
-	}
-	return (r);
-}
diff --git a/libc/upstream-openbsd/lib/libc/stdlib/llabs.c b/libc/upstream-openbsd/lib/libc/stdlib/llabs.c
deleted file mode 100644
index f4a260f..0000000
--- a/libc/upstream-openbsd/lib/libc/stdlib/llabs.c
+++ /dev/null
@@ -1,40 +0,0 @@
-/*	$OpenBSD: llabs.c,v 1.4 2016/08/14 23:18:03 guenther Exp $	*/
-
-/*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <stdlib.h>
-
-long long
-llabs(long long j)
-{
-	return (j < 0 ? -j : j);
-}
-
-__weak_alias(qabs, llabs);
diff --git a/libc/upstream-openbsd/lib/libc/stdlib/lldiv.c b/libc/upstream-openbsd/lib/libc/stdlib/lldiv.c
deleted file mode 100644
index 59c37b8..0000000
--- a/libc/upstream-openbsd/lib/libc/stdlib/lldiv.c
+++ /dev/null
@@ -1,52 +0,0 @@
-/*	$OpenBSD: lldiv.c,v 1.2 2016/08/14 23:18:03 guenther Exp $	*/
-/*
- * Copyright (c) 1990 Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <stdlib.h>		/* lldiv_t */
-
-lldiv_t
-lldiv(long long num, long long denom)
-{
-	lldiv_t r;
-
-	/* see div.c for comments */
-
-	r.quot = num / denom;
-	r.rem = num % denom;
-	if (num >= 0 && r.rem < 0) {
-		r.quot++;
-		r.rem -= denom;
-	}
-	return (r);
-}
-
-__weak_alias(qdiv, lldiv);
diff --git a/libc/upstream-openbsd/lib/libc/stdlib/lsearch.c b/libc/upstream-openbsd/lib/libc/stdlib/lsearch.c
deleted file mode 100644
index 95ebf49..0000000
--- a/libc/upstream-openbsd/lib/libc/stdlib/lsearch.c
+++ /dev/null
@@ -1,70 +0,0 @@
-/*	$OpenBSD: lsearch.c,v 1.7 2021/12/08 22:06:28 cheloha Exp $	*/
-
-/*
- * Copyright (c) 1989, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Roger L. Snyder.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/types.h>
-#include <string.h>
-#include <search.h>
-
-typedef int (*cmp_fn_t)(const void *, const void *);
-
-void *
-lsearch(const void *key, void *base, size_t *nelp, size_t width,
-    	cmp_fn_t compar)
-{
-	void *element = lfind(key, base, nelp, width, compar);
-
-	/*
-	 * Use memmove(3) to ensure the key is copied cleanly into the
-	 * array, even if the key overlaps with the end of the array.
-	 */
-	if (element == NULL) {
-		element = memmove((char *)base + *nelp * width, key, width);
-		*nelp += 1;
-	}
-	return element;
-}
-
-void *
-lfind(const void *key, const void *base, size_t *nelp, size_t width,
-	cmp_fn_t compar)
-{
-	const char *element, *end;
-
-	end = (const char *)base + *nelp * width;
-	for (element = base; element < end; element += width)
-		if (!compar(key, element))		/* key found */
-			return((void *)element);
-	return NULL;
-}
-DEF_WEAK(lfind);
diff --git a/libc/upstream-openbsd/lib/libc/stdlib/remque.c b/libc/upstream-openbsd/lib/libc/stdlib/remque.c
deleted file mode 100644
index 71b74b2..0000000
--- a/libc/upstream-openbsd/lib/libc/stdlib/remque.c
+++ /dev/null
@@ -1,48 +0,0 @@
-/*	$OpenBSD: remque.c,v 1.3 2014/08/15 04:14:36 guenther Exp $	*/
-
-/*
- *  Copyright (c) 1993 John Brezak
- *  All rights reserved.
- * 
- *  Redistribution and use in source and binary forms, with or without
- *  modification, are permitted provided that the following conditions
- *  are met:
- *  1. Redistributions of source code must retain the above copyright
- *     notice, this list of conditions and the following disclaimer.
- *  2. Redistributions in binary form must reproduce the above copyright
- *     notice, this list of conditions and the following disclaimer in the
- *     documentation and/or other materials provided with the distribution.
- *  3. The name of the author may 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.
- */
-
-#include <stdlib.h>
-#include <search.h>
-
-struct qelem {
-        struct qelem *q_forw;
-        struct qelem *q_back;
-};
-
-void
-remque(void *element)
-{
-	struct qelem *e = element;
-
-	if (e->q_forw != NULL)
-		e->q_forw->q_back = e->q_back;
-	if (e->q_back != NULL)
-		e->q_back->q_forw = e->q_forw;
-}
diff --git a/libc/upstream-openbsd/lib/libc/string/memccpy.c b/libc/upstream-openbsd/lib/libc/string/memccpy.c
deleted file mode 100644
index 635061b..0000000
--- a/libc/upstream-openbsd/lib/libc/string/memccpy.c
+++ /dev/null
@@ -1,49 +0,0 @@
-/*	$OpenBSD: memccpy.c,v 1.7 2015/08/31 02:53:57 guenther Exp $	*/
-
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <string.h>
-
-void *
-memccpy(void *t, const void *f, int c, size_t n)
-{
-
-	if (n) {
-		unsigned char *tp = t;
-		const unsigned char *fp = f;
-		unsigned char uc = c;
-		do {
-			if ((*tp++ = *fp++) == uc)
-				return (tp);
-		} while (--n != 0);
-	}
-	return (0);
-}
-DEF_WEAK(memccpy);
diff --git a/libc/upstream-openbsd/lib/libc/string/stpcpy.c b/libc/upstream-openbsd/lib/libc/string/stpcpy.c
deleted file mode 100644
index 5a86541..0000000
--- a/libc/upstream-openbsd/lib/libc/string/stpcpy.c
+++ /dev/null
@@ -1,44 +0,0 @@
-/*	$OpenBSD: stpcpy.c,v 1.3 2017/11/28 06:55:49 tb Exp $	*/
-
-/*
- * Copyright (c) 1988 Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <string.h>
-
-#if defined(APIWARN)
-__warn_references(stpcpy,
-    "stpcpy() is dangerous; do not use it");
-#endif
-
-char *
-stpcpy(char *to, const char *from)
-{
-	for (; (*to = *from) != '\0'; ++from, ++to);
-	return(to);
-}
diff --git a/libc/upstream-openbsd/lib/libc/string/strcasecmp.c b/libc/upstream-openbsd/lib/libc/string/strcasecmp.c
deleted file mode 100644
index edbd638..0000000
--- a/libc/upstream-openbsd/lib/libc/string/strcasecmp.c
+++ /dev/null
@@ -1,107 +0,0 @@
-/*	$OpenBSD: strcasecmp.c,v 1.7 2015/08/31 02:53:57 guenther Exp $	*/
-
-/*
- * Copyright (c) 1987, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <string.h>
-
-typedef unsigned char u_char;
-
-/*
- * This array is designed for mapping upper and lower case letter
- * together for a case independent comparison.  The mappings are
- * based upon ascii character sequences.
- */
-static const u_char charmap[] = {
-	'\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
-	'\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
-	'\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
-	'\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
-	'\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047',
-	'\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057',
-	'\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067',
-	'\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077',
-	'\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
-	'\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
-	'\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
-	'\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137',
-	'\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
-	'\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
-	'\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
-	'\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177',
-	'\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207',
-	'\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217',
-	'\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227',
-	'\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237',
-	'\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247',
-	'\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257',
-	'\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267',
-	'\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277',
-	'\300', '\301', '\302', '\303', '\304', '\305', '\306', '\307',
-	'\310', '\311', '\312', '\313', '\314', '\315', '\316', '\317',
-	'\320', '\321', '\322', '\323', '\324', '\325', '\326', '\327',
-	'\330', '\331', '\332', '\333', '\334', '\335', '\336', '\337',
-	'\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
-	'\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
-	'\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
-	'\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377',
-};
-
-int
-strcasecmp(const char *s1, const char *s2)
-{
-	const u_char *cm = charmap;
-	const u_char *us1 = (const u_char *)s1;
-	const u_char *us2 = (const u_char *)s2;
-
-	while (cm[*us1] == cm[*us2++])
-		if (*us1++ == '\0')
-			return (0);
-	return (cm[*us1] - cm[*--us2]);
-}
-DEF_WEAK(strcasecmp);
-
-int
-strncasecmp(const char *s1, const char *s2, size_t n)
-{
-	if (n != 0) {
-		const u_char *cm = charmap;
-		const u_char *us1 = (const u_char *)s1;
-		const u_char *us2 = (const u_char *)s2;
-
-		do {
-			if (cm[*us1] != cm[*us2++])
-				return (cm[*us1] - cm[*--us2]);
-			if (*us1++ == '\0')
-				break;
-		} while (--n != 0);
-	}
-	return (0);
-}
-DEF_WEAK(strncasecmp);
diff --git a/libc/upstream-openbsd/lib/libc/string/strcoll.c b/libc/upstream-openbsd/lib/libc/string/strcoll.c
deleted file mode 100644
index 47a6ea4..0000000
--- a/libc/upstream-openbsd/lib/libc/string/strcoll.c
+++ /dev/null
@@ -1,45 +0,0 @@
-/*	$OpenBSD: strcoll.c,v 1.6 2015/08/31 02:53:57 guenther Exp $ */
-/*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <string.h>
-
-/*
- * Compare strings according to LC_COLLATE category of current locale.
- */
-int
-strcoll(const char *s1, const char *s2)
-{
-	/* LC_COLLATE is unimplemented, hence always "C" */
-	return (strcmp(s1, s2));
-}
-DEF_STRONG(strcoll);
diff --git a/libc/upstream-openbsd/lib/libc/string/strcspn.c b/libc/upstream-openbsd/lib/libc/string/strcspn.c
deleted file mode 100644
index 3c1f5a4..0000000
--- a/libc/upstream-openbsd/lib/libc/string/strcspn.c
+++ /dev/null
@@ -1,59 +0,0 @@
-/*	$OpenBSD: strcspn.c,v 1.6 2015/08/31 02:53:57 guenther Exp $ */
-/*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <string.h>
-
-/*
- * Span the complement of string s2.
- */
-size_t
-strcspn(const char *s1, const char *s2)
-{
-	const char *p, *spanp;
-	char c, sc;
-
-	/*
-	 * Stop as soon as we find any character from s2.  Note that there
-	 * must be a NUL in s2; it suffices to stop when we find that, too.
-	 */
-	for (p = s1;;) {
-		c = *p++;
-		spanp = s2;
-		do {
-			if ((sc = *spanp++) == c)
-				return (p - 1 - s1);
-		} while (sc != 0);
-	}
-	/* NOTREACHED */
-}
-DEF_STRONG(strcspn);
diff --git a/libc/upstream-openbsd/lib/libc/string/strpbrk.c b/libc/upstream-openbsd/lib/libc/string/strpbrk.c
deleted file mode 100644
index 336c22d..0000000
--- a/libc/upstream-openbsd/lib/libc/string/strpbrk.c
+++ /dev/null
@@ -1,49 +0,0 @@
-/*	$OpenBSD: strpbrk.c,v 1.6 2015/08/31 02:53:57 guenther Exp $ */
-/*
- * Copyright (c) 1985 Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <string.h>
-
-/*
- * Find the first occurrence in s1 of a character in s2 (excluding NUL).
- */
-char *
-strpbrk(const char *s1, const char *s2)
-{
-	const char *scanp;
-	int c, sc;
-
-	while ((c = *s1++) != 0) {
-		for (scanp = s2; (sc = *scanp++) != 0;)
-			if (sc == c)
-				return ((char *)(s1 - 1));
-	}
-	return (NULL);
-}
-DEF_STRONG(strpbrk);
diff --git a/libc/upstream-openbsd/lib/libc/string/strsep.c b/libc/upstream-openbsd/lib/libc/string/strsep.c
deleted file mode 100644
index 97c3cbf..0000000
--- a/libc/upstream-openbsd/lib/libc/string/strsep.c
+++ /dev/null
@@ -1,71 +0,0 @@
-/*	$OpenBSD: strsep.c,v 1.8 2015/08/31 02:53:57 guenther Exp $	*/
-
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <string.h>
-
-/*
- * Get next token from string *stringp, where tokens are possibly-empty
- * strings separated by characters from delim.  
- *
- * Writes NULs into the string at *stringp to end tokens.
- * delim need not remain constant from call to call.
- * On return, *stringp points past the last NUL written (if there might
- * be further tokens), or is NULL (if there are definitely no more tokens).
- *
- * If *stringp is NULL, strsep returns NULL.
- */
-char *
-strsep(char **stringp, const char *delim)
-{
-	char *s;
-	const char *spanp;
-	int c, sc;
-	char *tok;
-
-	if ((s = *stringp) == NULL)
-		return (NULL);
-	for (tok = s;;) {
-		c = *s++;
-		spanp = delim;
-		do {
-			if ((sc = *spanp++) == c) {
-				if (c == 0)
-					s = NULL;
-				else
-					s[-1] = 0;
-				*stringp = s;
-				return (tok);
-			}
-		} while (sc != 0);
-	}
-	/* NOTREACHED */
-}
-DEF_WEAK(strsep);
diff --git a/libc/upstream-openbsd/lib/libc/string/strspn.c b/libc/upstream-openbsd/lib/libc/string/strspn.c
deleted file mode 100644
index 0ce41cb..0000000
--- a/libc/upstream-openbsd/lib/libc/string/strspn.c
+++ /dev/null
@@ -1,52 +0,0 @@
-/*	$OpenBSD: strspn.c,v 1.6 2015/08/31 02:53:57 guenther Exp $ */
-/*
- * Copyright (c) 1989 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <string.h>
-
-/*
- * Span the string s2 (skip characters that are in s2).
- */
-size_t
-strspn(const char *s1, const char *s2)
-{
-	const char *p = s1, *spanp;
-	char c, sc;
-
-	/*
-	 * Skip any characters in s2, excluding the terminating \0.
-	 */
-cont:
-	c = *p++;
-	for (spanp = s2; (sc = *spanp++) != 0;)
-		if (sc == c)
-			goto cont;
-	return (p - 1 - s1);
-}
-DEF_STRONG(strspn);
diff --git a/libc/upstream-openbsd/lib/libc/string/strtok.c b/libc/upstream-openbsd/lib/libc/string/strtok.c
deleted file mode 100644
index c576575..0000000
--- a/libc/upstream-openbsd/lib/libc/string/strtok.c
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Copyright (c) 1988 Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <string.h>
-
-char *
-strtok(char *s, const char *delim)
-{
-	static char *last;
-
-	return strtok_r(s, delim, &last);
-}
-DEF_STRONG(strtok);
-
-char *
-strtok_r(char *s, const char *delim, char **last)
-{
-	const char *spanp;
-	int c, sc;
-	char *tok;
-
-	if (s == NULL && (s = *last) == NULL)
-		return (NULL);
-
-	/*
-	 * Skip (span) leading delimiters (s += strspn(s, delim), sort of).
-	 */
-cont:
-	c = *s++;
-	for (spanp = delim; (sc = *spanp++) != 0;) {
-		if (c == sc)
-			goto cont;
-	}
-
-	if (c == 0) {		/* no non-delimiter characters */
-		*last = NULL;
-		return (NULL);
-	}
-	tok = s - 1;
-
-	/*
-	 * Scan token (scan for delimiters: s += strcspn(s, delim), sort of).
-	 * Note that delim must have one NUL; we stop if we see that, too.
-	 */
-	for (;;) {
-		c = *s++;
-		spanp = delim;
-		do {
-			if ((sc = *spanp++) == c) {
-				if (c == 0)
-					s = NULL;
-				else
-					s[-1] = '\0';
-				*last = s;
-				return (tok);
-			}
-		} while (sc != 0);
-	}
-	/* NOTREACHED */
-}
-DEF_WEAK(strtok_r);
diff --git a/libc/upstream-openbsd/lib/libc/string/strxfrm.c b/libc/upstream-openbsd/lib/libc/string/strxfrm.c
deleted file mode 100644
index 97df097..0000000
--- a/libc/upstream-openbsd/lib/libc/string/strxfrm.c
+++ /dev/null
@@ -1,52 +0,0 @@
-/*	$OpenBSD: strxfrm.c,v 1.7 2015/08/31 02:53:57 guenther Exp $ */
-/*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <string.h>
-
-/*
- * Transform src, storing the result in dst, such that
- * strcmp() on transformed strings returns what strcoll()
- * on the original untransformed strings would return.
- */
-size_t
-strxfrm(char *dst, const char *src, size_t n)
-{
-
-	/*
-	 * Since locales are unimplemented, this is just a copy.
-	 */
-	if (n == 0)
-		return (strlen(src));
-	return (strlcpy(dst, src, n));
-}
-DEF_STRONG(strxfrm);
diff --git a/libc/upstream-openbsd/lib/libc/string/wcslcpy.c b/libc/upstream-openbsd/lib/libc/string/wcslcpy.c
deleted file mode 100644
index 9c433c8..0000000
--- a/libc/upstream-openbsd/lib/libc/string/wcslcpy.c
+++ /dev/null
@@ -1,51 +0,0 @@
-/*	$OpenBSD: wcslcpy.c,v 1.8 2019/01/25 00:19:25 millert Exp $	*/
-
-/*
- * Copyright (c) 1998, 2015 Todd C. Miller <millert@openbsd.org>
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * 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.
- */
-
-#include <sys/types.h>
-#include <wchar.h>
-
-/*
- * Copy string src to buffer dst of size dsize.  At most dsize-1
- * chars will be copied.  Always NUL terminates (unless dsize == 0).
- * Returns wcslen(src); if retval >= dsize, truncation occurred.
- */
-size_t
-wcslcpy(wchar_t *dst, const wchar_t *src, size_t dsize)
-{
-	const wchar_t *osrc = src;
-	size_t nleft = dsize;
-
-	/* Copy as many bytes as will fit. */
-	if (nleft != 0) {
-		while (--nleft != 0) {
-			if ((*dst++ = *src++) == L'\0')
-				break;
-		}
-	}
-
-	/* Not enough room in dst, add NUL and traverse rest of src. */
-	if (nleft == 0) {
-		if (dsize != 0)
-			*dst = L'\0';		/* NUL-terminate dst */
-		while (*src++)
-			;
-	}
-
-	return(src - osrc - 1);	/* count does not include NUL */
-}
-DEF_WEAK(wcslcpy);
diff --git a/libc/upstream-openbsd/lib/libc/string/wcswidth.c b/libc/upstream-openbsd/lib/libc/string/wcswidth.c
deleted file mode 100644
index 9f003f9..0000000
--- a/libc/upstream-openbsd/lib/libc/string/wcswidth.c
+++ /dev/null
@@ -1,51 +0,0 @@
-/*	$OpenBSD: wcswidth.c,v 1.5 2015/09/12 16:23:14 guenther Exp $	*/
-/*	$NetBSD: wcswidth.c,v 1.2 2001/01/03 14:29:37 lukem Exp $	*/
-
-/*-
- * Copyright (c)1999 Citrus Project,
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 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.
- *
- *	citrus Id: wcswidth.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp
- */
-
-#include <wchar.h>
-
-int
-wcswidth(const wchar_t *s, size_t n)
-{
-	int w, q;
-
-	w = 0;
-	while (n && *s) {
-		q = wcwidth(*s);
-		if (q == -1)
-			return (-1);
-		w += q;
-		s++;
-		n--;
-	}
-
-	return w;
-}
-DEF_WEAK(wcswidth);
diff --git a/libdl/Android.bp b/libdl/Android.bp
index 205c454..9d472d1 100644
--- a/libdl/Android.bp
+++ b/libdl/Android.bp
@@ -60,8 +60,6 @@
     native_bridge_supported: true,
     static_ndk_lib: true,
 
-    export_include_dirs: ["include_private"],
-
     defaults: [
         "linux_bionic_supported",
         "bug_24465209_workaround",
@@ -100,7 +98,10 @@
 
     nocrt: true,
     system_shared_libs: [],
-    header_libs: ["libc_headers"],
+    header_libs: [
+        "libc_headers",
+        "bionic_libc_platform_headers",
+    ],
 
     // Opt out of native_coverage when opting out of system_shared_libs
     native_coverage: false,
@@ -138,6 +139,8 @@
     recovery_available: true,
     native_bridge_supported: true,
 
+    export_include_dirs: ["include_private"],
+
     srcs: ["libdl_android.cpp"],
     version_script: "libdl_android.map.txt",
 
@@ -152,7 +155,12 @@
 
     nocrt: true,
     system_shared_libs: [],
-    header_libs: ["libc_headers"],
+    header_libs: [
+        "libc_headers",
+        "bionic_libc_platform_headers",
+    ],
+
+    export_header_lib_headers: ["bionic_libc_platform_headers"],
 
     // Opt out of native_coverage when opting out of system_shared_libs
     native_coverage: false,
diff --git a/libdl/include_private/android/dlext_private.h b/libdl/include_private/android/dlext_private.h
index fda1086..ac1a781 100644
--- a/libdl/include_private/android/dlext_private.h
+++ b/libdl/include_private/android/dlext_private.h
@@ -21,9 +21,6 @@
 
 __BEGIN_DECLS
 
-// TODO: libdl has several private extensions, but they have not all moved into a standard
-// private header.
-
 /**
  * Set whether to load libraries in app compat mode.
  *
diff --git a/libdl/libdl.map.txt b/libdl/libdl.map.txt
index 043ec53..a3bffcb 100644
--- a/libdl/libdl.map.txt
+++ b/libdl/libdl.map.txt
@@ -16,8 +16,8 @@
 
 LIBC {
   global:
-    android_dlopen_ext; # introduced=21
-    dl_iterate_phdr; # introduced-arm=21
+    android_dlopen_ext;
+    dl_iterate_phdr;
     dl_unwind_find_exidx; # arm
     dladdr;
     dlclose;
@@ -45,5 +45,6 @@
   global:
     android_get_LD_LIBRARY_PATH;
     __cfi_init;
+    __cfi_shadow_load;
     android_handle_signal;
 } LIBC_OMR1;
diff --git a/libdl/libdl_cfi.cpp b/libdl/libdl_cfi.cpp
index e096f9a..5b25e3b 100644
--- a/libdl/libdl_cfi.cpp
+++ b/libdl/libdl_cfi.cpp
@@ -51,6 +51,10 @@
   return *reinterpret_cast<uint16_t*>(shadow_base_storage.v + ofs);
 }
 
+extern "C" uint16_t __cfi_shadow_load(void* p) {
+  return shadow_load(p);
+}
+
 static uintptr_t cfi_check_addr(uint16_t v, void* Ptr) {
   uintptr_t addr = reinterpret_cast<uintptr_t>(Ptr);
   // The aligned range of [0, kShadowAlign) uses a single shadow element, therefore all pointers in
diff --git a/libfdtrack/Android.bp b/libfdtrack/Android.bp
index 644d46d..ca1da8a 100644
--- a/libfdtrack/Android.bp
+++ b/libfdtrack/Android.bp
@@ -42,6 +42,7 @@
 
 cc_test {
     name: "fdtrack_test",
+    isolated: true,
     srcs: ["fdtrack_test.cpp"],
     whole_static_libs: ["libBionicCtsGtestMain"],
     static_libs: ["liblog"],
diff --git a/libm/Android.bp b/libm/Android.bp
index 86b32db..040606b 100644
--- a/libm/Android.bp
+++ b/libm/Android.bp
@@ -3,6 +3,7 @@
 //
 package {
     default_applicable_licenses: ["bionic_libm_license"],
+    default_team: "trendy_team_native_tools_libraries",
 }
 
 license {
@@ -19,19 +20,8 @@
     ],
 }
 
-cc_library {
-    name: "libm",
-    defaults: [
-        "linux_bionic_supported",
-        "bug_24465209_workaround",
-    ],
-    ramdisk_available: true,
-    vendor_ramdisk_available: true,
-    recovery_available: true,
-    static_ndk_lib: true,
-
-    whole_static_libs: ["libarm-optimized-routines-math"],
-
+filegroup {
+    name: "libm_common_sources",
     srcs: [
         "upstream-freebsd/lib/msun/bsdsrc/b_tgamma.c",
         "upstream-freebsd/lib/msun/src/catrig.c",
@@ -130,28 +120,14 @@
         "upstream-freebsd/lib/msun/src/s_fdim.c",
         "upstream-freebsd/lib/msun/src/s_finite.c",
         "upstream-freebsd/lib/msun/src/s_finitef.c",
-        "upstream-freebsd/lib/msun/src/s_fma.c",
-        "upstream-freebsd/lib/msun/src/s_fmaf.c",
-        "upstream-freebsd/lib/msun/src/s_fmax.c",
-        "upstream-freebsd/lib/msun/src/s_fmaxf.c",
-        "upstream-freebsd/lib/msun/src/s_fmin.c",
-        "upstream-freebsd/lib/msun/src/s_fminf.c",
         "upstream-freebsd/lib/msun/src/s_frexp.c",
         "upstream-freebsd/lib/msun/src/s_frexpf.c",
         "upstream-freebsd/lib/msun/src/s_ilogb.c",
         "upstream-freebsd/lib/msun/src/s_ilogbf.c",
-        "upstream-freebsd/lib/msun/src/s_llrint.c",
-        "upstream-freebsd/lib/msun/src/s_llrintf.c",
-        "upstream-freebsd/lib/msun/src/s_llround.c",
-        "upstream-freebsd/lib/msun/src/s_llroundf.c",
         "upstream-freebsd/lib/msun/src/s_log1p.c",
         "upstream-freebsd/lib/msun/src/s_log1pf.c",
         "upstream-freebsd/lib/msun/src/s_logb.c",
         "upstream-freebsd/lib/msun/src/s_logbf.c",
-        "upstream-freebsd/lib/msun/src/s_lrint.c",
-        "upstream-freebsd/lib/msun/src/s_lrintf.c",
-        "upstream-freebsd/lib/msun/src/s_lround.c",
-        "upstream-freebsd/lib/msun/src/s_lroundf.c",
         "upstream-freebsd/lib/msun/src/s_modf.c",
         "upstream-freebsd/lib/msun/src/s_modff.c",
         "upstream-freebsd/lib/msun/src/s_nan.c",
@@ -160,8 +136,6 @@
         "upstream-freebsd/lib/msun/src/s_nextafterf.c",
         "upstream-freebsd/lib/msun/src/s_remquo.c",
         "upstream-freebsd/lib/msun/src/s_remquof.c",
-        "upstream-freebsd/lib/msun/src/s_round.c",
-        "upstream-freebsd/lib/msun/src/s_roundf.c",
         "upstream-freebsd/lib/msun/src/s_scalbln.c",
         "upstream-freebsd/lib/msun/src/s_scalbn.c",
         "upstream-freebsd/lib/msun/src/s_scalbnf.c",
@@ -202,90 +176,222 @@
         "builtins.cpp",
         "signbit.cpp",
     ],
+}
+
+filegroup {
+    name: "libm_lp64_sources",
+    srcs: [
+        "upstream-freebsd/lib/msun/src/catrigl.c",
+        "upstream-freebsd/lib/msun/src/e_acosl.c",
+        "upstream-freebsd/lib/msun/src/e_acoshl.c",
+        "upstream-freebsd/lib/msun/src/e_asinl.c",
+        "upstream-freebsd/lib/msun/src/e_atan2l.c",
+        "upstream-freebsd/lib/msun/src/e_atanhl.c",
+        "upstream-freebsd/lib/msun/src/e_fmodl.c",
+        "upstream-freebsd/lib/msun/src/e_hypotl.c",
+        "upstream-freebsd/lib/msun/src/e_lgammal.c",
+        "upstream-freebsd/lib/msun/src/e_remainderl.c",
+        "upstream-freebsd/lib/msun/src/e_sqrtl.c",
+        "upstream-freebsd/lib/msun/src/s_asinhl.c",
+        "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/e_coshl.c",
+        "upstream-freebsd/lib/msun/src/s_cosl.c",
+        "upstream-freebsd/lib/msun/src/s_csqrtl.c",
+        "upstream-freebsd/lib/msun/src/s_floorl.c",
+        "upstream-freebsd/lib/msun/src/s_fmal.c",
+        "upstream-freebsd/lib/msun/src/s_fmaxl.c",
+        "upstream-freebsd/lib/msun/src/s_fminl.c",
+        "upstream-freebsd/lib/msun/src/s_modfl.c",
+        "upstream-freebsd/lib/msun/src/s_frexpl.c",
+        "upstream-freebsd/lib/msun/src/s_ilogbl.c",
+        "upstream-freebsd/lib/msun/src/s_llrintl.c",
+        "upstream-freebsd/lib/msun/src/s_llroundl.c",
+        "upstream-freebsd/lib/msun/src/s_logbl.c",
+        "upstream-freebsd/lib/msun/src/s_lrintl.c",
+        "upstream-freebsd/lib/msun/src/s_lroundl.c",
+        "upstream-freebsd/lib/msun/src/s_nextafterl.c",
+        "upstream-freebsd/lib/msun/src/s_nexttoward.c",
+        "upstream-freebsd/lib/msun/src/s_nexttowardf.c",
+        "upstream-freebsd/lib/msun/src/s_remquol.c",
+        "upstream-freebsd/lib/msun/src/s_rintl.c",
+        "upstream-freebsd/lib/msun/src/s_roundl.c",
+        "upstream-freebsd/lib/msun/src/s_scalbnl.c",
+        "upstream-freebsd/lib/msun/src/s_sincosl.c",
+        "upstream-freebsd/lib/msun/src/e_sinhl.c",
+        "upstream-freebsd/lib/msun/src/s_sinl.c",
+        "upstream-freebsd/lib/msun/src/s_tanhl.c",
+        "upstream-freebsd/lib/msun/src/s_tanl.c",
+        "upstream-freebsd/lib/msun/src/s_truncl.c",
+
+        "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",
+        "upstream-freebsd/lib/msun/ld128/s_erfl.c",
+        "upstream-freebsd/lib/msun/ld128/s_exp2l.c",
+        "upstream-freebsd/lib/msun/ld128/s_expl.c",
+        "upstream-freebsd/lib/msun/ld128/s_logl.c",
+        "upstream-freebsd/lib/msun/ld128/s_nanl.c",
+    ],
+}
+
+filegroup {
+    name: "libm_arm_sources",
+    srcs: [
+        "fenv-arm.c",
+
+        // Even armv8 arm32 doesn't have instructions for these.
+        "upstream-freebsd/lib/msun/src/s_llrint.c",
+        "upstream-freebsd/lib/msun/src/s_llrintf.c",
+        "upstream-freebsd/lib/msun/src/s_lrint.c",
+        "upstream-freebsd/lib/msun/src/s_lrintf.c",
+        "upstream-freebsd/lib/msun/src/s_llround.c",
+        "upstream-freebsd/lib/msun/src/s_llroundf.c",
+        "upstream-freebsd/lib/msun/src/s_lround.c",
+        "upstream-freebsd/lib/msun/src/s_lroundf.c",
+    ],
+}
+
+filegroup {
+    name: "libm_arm_soft_ceil_floor_sources",
+    srcs: [
+        "upstream-freebsd/lib/msun/src/s_ceil.c",
+        "upstream-freebsd/lib/msun/src/s_ceilf.c",
+        "upstream-freebsd/lib/msun/src/s_floor.c",
+        "upstream-freebsd/lib/msun/src/s_floorf.c",
+        "upstream-freebsd/lib/msun/src/s_fma.c",
+        "upstream-freebsd/lib/msun/src/s_fmaf.c",
+        "upstream-freebsd/lib/msun/src/s_fmax.c",
+        "upstream-freebsd/lib/msun/src/s_fmaxf.c",
+        "upstream-freebsd/lib/msun/src/s_fmin.c",
+        "upstream-freebsd/lib/msun/src/s_fminf.c",
+        "upstream-freebsd/lib/msun/src/s_rint.c",
+        "upstream-freebsd/lib/msun/src/s_rintf.c",
+        "upstream-freebsd/lib/msun/src/s_round.c",
+        "upstream-freebsd/lib/msun/src/s_roundf.c",
+        "upstream-freebsd/lib/msun/src/s_trunc.c",
+        "upstream-freebsd/lib/msun/src/s_truncf.c",
+    ],
+}
+
+filegroup {
+    name: "libm_arm64_sources",
+    srcs: [
+        "fenv-arm64.c",
+    ],
+}
+
+filegroup {
+    name: "libm_riscv64_sources",
+    srcs: [
+        "fenv-riscv64.c",
+    ],
+}
+
+filegroup {
+    name: "libm_x86_sources",
+    srcs: [
+        "fenv-x86.c",
+
+        // These require x86-64-v3.
+        "upstream-freebsd/lib/msun/src/s_fma.c",
+        "upstream-freebsd/lib/msun/src/s_fmaf.c",
+
+        // https://github.com/llvm/llvm-project/issues/140252
+        "upstream-freebsd/lib/msun/src/s_round.c",
+        "upstream-freebsd/lib/msun/src/s_roundf.c",
+
+        // There are no x86-64 instructions for these.
+        "upstream-freebsd/lib/msun/src/s_llround.c",
+        "upstream-freebsd/lib/msun/src/s_llroundf.c",
+        "upstream-freebsd/lib/msun/src/s_lround.c",
+        "upstream-freebsd/lib/msun/src/s_lroundf.c",
+    ],
+}
+
+filegroup {
+    name: "libm_x86_64_sources",
+    srcs: [
+        "fenv-x86_64.c",
+
+        // These require x86-64-v3.
+        "upstream-freebsd/lib/msun/src/s_fma.c",
+        "upstream-freebsd/lib/msun/src/s_fmaf.c",
+
+        // https://github.com/llvm/llvm-project/issues/140252
+        "upstream-freebsd/lib/msun/src/s_round.c",
+        "upstream-freebsd/lib/msun/src/s_roundf.c",
+
+        // There are no x86-64 instructions for these.
+        "upstream-freebsd/lib/msun/src/s_llround.c",
+        "upstream-freebsd/lib/msun/src/s_llroundf.c",
+        "upstream-freebsd/lib/msun/src/s_lround.c",
+        "upstream-freebsd/lib/msun/src/s_lroundf.c",
+    ],
+}
+
+cc_library_headers {
+    name: "libm_headers",
+    defaults: ["linux_bionic_supported"],
 
     multilib: {
         lib64: {
-            srcs: [
-                "upstream-freebsd/lib/msun/src/catrigl.c",
-                "upstream-freebsd/lib/msun/src/e_acosl.c",
-                "upstream-freebsd/lib/msun/src/e_acoshl.c",
-                "upstream-freebsd/lib/msun/src/e_asinl.c",
-                "upstream-freebsd/lib/msun/src/e_atan2l.c",
-                "upstream-freebsd/lib/msun/src/e_atanhl.c",
-                "upstream-freebsd/lib/msun/src/e_fmodl.c",
-                "upstream-freebsd/lib/msun/src/e_hypotl.c",
-                "upstream-freebsd/lib/msun/src/e_lgammal.c",
-                "upstream-freebsd/lib/msun/src/e_remainderl.c",
-                "upstream-freebsd/lib/msun/src/e_sqrtl.c",
-                "upstream-freebsd/lib/msun/src/s_asinhl.c",
-                "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/e_coshl.c",
-                "upstream-freebsd/lib/msun/src/s_cosl.c",
-                "upstream-freebsd/lib/msun/src/s_csqrtl.c",
-                "upstream-freebsd/lib/msun/src/s_floorl.c",
-                "upstream-freebsd/lib/msun/src/s_fmal.c",
-                "upstream-freebsd/lib/msun/src/s_fmaxl.c",
-                "upstream-freebsd/lib/msun/src/s_fminl.c",
-                "upstream-freebsd/lib/msun/src/s_modfl.c",
-                "upstream-freebsd/lib/msun/src/s_frexpl.c",
-                "upstream-freebsd/lib/msun/src/s_ilogbl.c",
-                "upstream-freebsd/lib/msun/src/s_llrintl.c",
-                "upstream-freebsd/lib/msun/src/s_llroundl.c",
-                "upstream-freebsd/lib/msun/src/s_logbl.c",
-                "upstream-freebsd/lib/msun/src/s_lrintl.c",
-                "upstream-freebsd/lib/msun/src/s_lroundl.c",
-                "upstream-freebsd/lib/msun/src/s_nextafterl.c",
-                "upstream-freebsd/lib/msun/src/s_nexttoward.c",
-                "upstream-freebsd/lib/msun/src/s_nexttowardf.c",
-                "upstream-freebsd/lib/msun/src/s_remquol.c",
-                "upstream-freebsd/lib/msun/src/s_rintl.c",
-                "upstream-freebsd/lib/msun/src/s_roundl.c",
-                "upstream-freebsd/lib/msun/src/s_scalbnl.c",
-                "upstream-freebsd/lib/msun/src/s_sincosl.c",
-                "upstream-freebsd/lib/msun/src/e_sinhl.c",
-                "upstream-freebsd/lib/msun/src/s_sinl.c",
-                "upstream-freebsd/lib/msun/src/s_tanhl.c",
-                "upstream-freebsd/lib/msun/src/s_tanl.c",
-                "upstream-freebsd/lib/msun/src/s_truncl.c",
+            export_include_dirs: ["upstream-freebsd/lib/msun/ld128/"],
+        },
+    },
 
-                "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",
-                "upstream-freebsd/lib/msun/ld128/s_erfl.c",
-                "upstream-freebsd/lib/msun/ld128/s_exp2l.c",
-                "upstream-freebsd/lib/msun/ld128/s_expl.c",
-                "upstream-freebsd/lib/msun/ld128/s_logl.c",
-                "upstream-freebsd/lib/msun/ld128/s_nanl.c",
-            ],
-            local_include_dirs: ["upstream-freebsd/lib/msun/ld128/"],
+    export_include_dirs: [
+        "upstream-freebsd/android/include/",
+        "upstream-freebsd/lib/msun/src/",
+    ],
+
+    target: {
+        bionic: {
+            system_shared_libs: ["libc"],
+        },
+    },
+    stl: "none",
+    native_bridge_supported: true,
+    apex_available: [
+        "com.android.runtime",
+    ],
+}
+
+cc_defaults {
+    name: "libm_defaults",
+    defaults: [
+        "linux_bionic_supported",
+        "bug_24465209_workaround",
+    ],
+    ramdisk_available: true,
+    vendor_ramdisk_available: true,
+    recovery_available: true,
+    static_ndk_lib: true,
+
+    whole_static_libs: ["libarm-optimized-routines-math"],
+    header_libs: ["libm_headers"],
+
+    srcs: [":libm_common_sources"],
+
+    multilib: {
+        lib64: {
+            srcs: [":libm_lp64_sources"],
         },
     },
 
     arch: {
         arm: {
-            srcs: [
-                "fenv-arm.c",
-            ],
-            armv7_a_neon: {
+            srcs: [":libm_arm_sources"],
+            soft_ceil_floor: {
                 // armv7 arm32 has no instructions to implement these as
                 // builtins, so we build the portable implementations for armv7,
                 // because the NDK still supports armv7.
-                srcs: [
-                    "upstream-freebsd/lib/msun/src/s_ceil.c",
-                    "upstream-freebsd/lib/msun/src/s_ceilf.c",
-                    "upstream-freebsd/lib/msun/src/s_floor.c",
-                    "upstream-freebsd/lib/msun/src/s_floorf.c",
-                    "upstream-freebsd/lib/msun/src/s_rint.c",
-                    "upstream-freebsd/lib/msun/src/s_rintf.c",
-                    "upstream-freebsd/lib/msun/src/s_trunc.c",
-                    "upstream-freebsd/lib/msun/src/s_truncf.c",
-                ],
+                srcs: [":libm_arm_soft_ceil_floor_sources"],
             },
             instruction_set: "arm",
             version_script: ":libm.arm.map",
@@ -299,66 +405,17 @@
         },
 
         arm64: {
-            srcs: [
-                "fenv-arm64.c",
-            ],
-            exclude_srcs: [
-                "upstream-freebsd/lib/msun/src/s_fma.c",
-                "upstream-freebsd/lib/msun/src/s_fmaf.c",
-                "upstream-freebsd/lib/msun/src/s_fmax.c",
-                "upstream-freebsd/lib/msun/src/s_fmaxf.c",
-                "upstream-freebsd/lib/msun/src/s_fmin.c",
-                "upstream-freebsd/lib/msun/src/s_fminf.c",
-                "upstream-freebsd/lib/msun/src/s_llrint.c",
-                "upstream-freebsd/lib/msun/src/s_llrintf.c",
-                "upstream-freebsd/lib/msun/src/s_llround.c",
-                "upstream-freebsd/lib/msun/src/s_llroundf.c",
-                "upstream-freebsd/lib/msun/src/s_lrint.c",
-                "upstream-freebsd/lib/msun/src/s_lrintf.c",
-                "upstream-freebsd/lib/msun/src/s_lround.c",
-                "upstream-freebsd/lib/msun/src/s_lroundf.c",
-                "upstream-freebsd/lib/msun/src/s_round.c",
-                "upstream-freebsd/lib/msun/src/s_roundf.c",
-            ],
+            srcs: [":libm_arm64_sources"],
             version_script: ":libm.arm64.map",
         },
 
         riscv64: {
-            srcs: [
-                "fenv-riscv64.c",
-            ],
-
-            exclude_srcs: [
-                "upstream-freebsd/lib/msun/src/s_fma.c",
-                "upstream-freebsd/lib/msun/src/s_fmaf.c",
-                "upstream-freebsd/lib/msun/src/s_fmax.c",
-                "upstream-freebsd/lib/msun/src/s_fmaxf.c",
-                "upstream-freebsd/lib/msun/src/s_fmin.c",
-                "upstream-freebsd/lib/msun/src/s_fminf.c",
-                "upstream-freebsd/lib/msun/src/s_llrint.c",
-                "upstream-freebsd/lib/msun/src/s_llrintf.c",
-                "upstream-freebsd/lib/msun/src/s_llround.c",
-                "upstream-freebsd/lib/msun/src/s_llroundf.c",
-                "upstream-freebsd/lib/msun/src/s_lrint.c",
-                "upstream-freebsd/lib/msun/src/s_lrintf.c",
-                "upstream-freebsd/lib/msun/src/s_lround.c",
-                "upstream-freebsd/lib/msun/src/s_lroundf.c",
-                "upstream-freebsd/lib/msun/src/s_round.c",
-                "upstream-freebsd/lib/msun/src/s_roundf.c",
-            ],
+            srcs: [":libm_riscv64_sources"],
             version_script: ":libm.riscv64.map",
         },
 
         x86: {
-            srcs: [
-                "fenv-x86.c",
-            ],
-            exclude_srcs: [
-                "upstream-freebsd/lib/msun/src/s_llrint.c",
-                "upstream-freebsd/lib/msun/src/s_llrintf.c",
-                "upstream-freebsd/lib/msun/src/s_lrint.c",
-                "upstream-freebsd/lib/msun/src/s_lrintf.c",
-            ],
+            srcs: [":libm_x86_sources"],
             // The x86 ABI doesn't include this, which is needed for the
             // roundss/roundsd instructions that we've used since API level 23,
             // originally by hand-written assembler but later via intrinsics.
@@ -367,24 +424,11 @@
         },
 
         x86_64: {
-            srcs: [
-                "fenv-x86_64.c",
-            ],
-            exclude_srcs: [
-                "upstream-freebsd/lib/msun/src/s_llrint.c",
-                "upstream-freebsd/lib/msun/src/s_llrintf.c",
-                "upstream-freebsd/lib/msun/src/s_lrint.c",
-                "upstream-freebsd/lib/msun/src/s_lrintf.c",
-            ],
+            srcs: [":libm_x86_64_sources"],
             version_script: ":libm.x86_64.map",
         },
     },
 
-    local_include_dirs: [
-        "upstream-freebsd/android/include/",
-        "upstream-freebsd/lib/msun/src/",
-    ],
-
     cflags: [
         "-include freebsd-compat.h",
         "-fno-builtin",
@@ -404,7 +448,11 @@
         "-Wl,--Bsymbolic-functions",
     ],
 
-    include_dirs: ["bionic/libc"],
+    include_dirs: [
+        "bionic/libm",
+        "bionic/libc",
+    ],
+
     target: {
         bionic: {
             system_shared_libs: ["libc"],
@@ -413,12 +461,31 @@
 
     sanitize: {
         address: false,
-        fuzzer: false,
         integer_overflow: false,
     },
     stl: "none",
     native_bridge_supported: true,
 
+    apex_available: [
+        "com.android.runtime",
+    ],
+
+    lto: {
+        never: true,
+    },
+}
+
+cc_library {
+    name: "libm",
+    defaults: ["libm_defaults"],
+    target: {
+        native_bridge: {
+            shared: {
+                installable: false,
+            },
+        },
+    },
+
     stubs: {
         symbol_file: "libm.map.txt",
         versions: [
@@ -430,14 +497,6 @@
     llndk: {
         symbol_file: "libm.map.txt",
     },
-
-    apex_available: [
-        "com.android.runtime",
-    ],
-
-    lto: {
-        never: true,
-    },
 }
 
 ndk_library {
@@ -486,7 +545,7 @@
     cmd: "$(location generate-version-script) x86_64 $(in) $(out)",
 }
 
-// Because of a historical accidnt, ldexp() is in libc,
+// Because of a historical accident, ldexp() is in libc,
 // even though ldexpf() and ldexpl() are in libm.
 filegroup {
     name: "libc_ldexp_srcs",
diff --git a/libm/NOTICE b/libm/NOTICE
index bcdce54..3394eaa 100644
--- a/libm/NOTICE
+++ b/libm/NOTICE
@@ -678,34 +678,6 @@
 
 SPDX-License-Identifier: BSD-2-Clause
 
-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
-
 Copyright (c) 2005 David Schultz <das@FreeBSD.ORG>
 All rights reserved.
 
@@ -790,6 +762,34 @@
 
 SPDX-License-Identifier: BSD-2-Clause
 
+Copyright (c) 2005-2025 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
+
 Copyright (c) 2007 David Schultz
 All rights reserved.
 
diff --git a/libm/builtins.cpp b/libm/builtins.cpp
index 97db425..a638aa3 100644
--- a/libm/builtins.cpp
+++ b/libm/builtins.cpp
@@ -48,13 +48,20 @@
 #endif
 #endif
 
-#if defined(__aarch64__) || defined(__riscv)
+#if (defined(__arm__) && (__ARM_ARCH >= 8)) || defined(__aarch64__) || defined(__riscv)
 float fmaf(float x, float y, float z) { return __builtin_fmaf(x, y, z); }
 double fma(double x, double y, double z) { return __builtin_fma(x, y, z); }
+#if defined(__ILP32__)
+__weak_reference(fma, fmal);
+#endif
+#endif
 
+#if (defined(__arm__) && (__ARM_ARCH <= 7))
+// armv7 arm32 has no instructions to implement these builtins,
+// so we include the msun source in the .bp file instead.
+#else
 float fmaxf(float x, float y) { return __builtin_fmaxf(x, y); }
 double fmax(double x, double y) { return __builtin_fmax(x, y); }
-
 float fminf(float x, float y) { return __builtin_fminf(x, y); }
 double fmin(double x, double y) { return __builtin_fmin(x, y); }
 #endif
@@ -84,7 +91,7 @@
 #endif
 #endif
 
-#if defined(__aarch64__) || defined(__riscv)
+#if (defined(__arm__) && (__ARM_ARCH >= 8)) || defined(__aarch64__) || defined(__riscv)
 double round(double x) { return __builtin_round(x); }
 float roundf(float x) { return __builtin_roundf(x); }
 #endif
diff --git a/libm/upstream-freebsd/lib/msun/bsdsrc/b_tgamma.c b/libm/upstream-freebsd/lib/msun/bsdsrc/b_tgamma.c
index 8369477..a7e97bc 100644
--- a/libm/upstream-freebsd/lib/msun/bsdsrc/b_tgamma.c
+++ b/libm/upstream-freebsd/lib/msun/bsdsrc/b_tgamma.c
@@ -259,7 +259,7 @@
 static double
 smaller_gam(double x)
 {
-	double d, rhi, rlo, t, xhi, xlo;
+	double d, t, xhi, xlo;
 	struct Double r;
 
 	if (x < x0 + left) {
diff --git a/libm/upstream-freebsd/lib/msun/src/e_fmod.c b/libm/upstream-freebsd/lib/msun/src/e_fmod.c
index 77afd11..ced9cce 100644
--- a/libm/upstream-freebsd/lib/msun/src/e_fmod.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_fmod.c
@@ -26,14 +26,14 @@
 double
 fmod(double x, double y)
 {
-	int32_t n,hx,hy,hz,ix,iy,sx,i;
-	u_int32_t lx,ly,lz;
+	int32_t hx, hy, hz, ix, iy, n, sx;
+	u_int32_t lx, ly, lz;
 
 	EXTRACT_WORDS(hx,lx,x);
 	EXTRACT_WORDS(hy,ly,y);
 	sx = hx&0x80000000;		/* sign of x */
-	hx ^=sx;		/* |x| */
-	hy &= 0x7fffffff;	/* |y| */
+	hx ^= sx;			/* |x| */
+	hy &= 0x7fffffff;		/* |y| */
 
     /* purge off exception values */
 	if((hy|ly)==0||(hx>=0x7ff00000)||	/* y=0,or x not finite */
@@ -46,22 +46,16 @@
 	}
 
     /* determine ix = ilogb(x) */
-	if(hx<0x00100000) {	/* subnormal x */
-	    if(hx==0) {
-		for (ix = -1043, i=lx; i>0; i<<=1) ix -=1;
-	    } else {
-		for (ix = -1022,i=(hx<<11); i>0; i<<=1) ix -=1;
-	    }
-	} else ix = (hx>>20)-1023;
+	if(hx<0x00100000)
+	    ix = subnormal_ilogb(hx, lx);
+	else
+	    ix = (hx>>20)-1023;
 
     /* determine iy = ilogb(y) */
-	if(hy<0x00100000) {	/* subnormal y */
-	    if(hy==0) {
-		for (iy = -1043, i=ly; i>0; i<<=1) iy -=1;
-	    } else {
-		for (iy = -1022,i=(hy<<11); i>0; i<<=1) iy -=1;
-	    }
-	} else iy = (hy>>20)-1023;
+	if(hy<0x00100000)
+	    iy = subnormal_ilogb(hy, ly);
+	else
+	    iy = (hy>>20)-1023;
 
     /* set up {hx,lx}, {hy,ly} and align y to x */
 	if(ix >= -1022) 
diff --git a/libm/upstream-freebsd/lib/msun/src/e_fmodf.c b/libm/upstream-freebsd/lib/msun/src/e_fmodf.c
index a7d1a0c..ada969d 100644
--- a/libm/upstream-freebsd/lib/msun/src/e_fmodf.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_fmodf.c
@@ -27,7 +27,7 @@
 float
 fmodf(float x, float y)
 {
-	int32_t n,hx,hy,hz,ix,iy,sx,i;
+	int32_t hx, hy, hz, ix, iy, n, sx;
 
 	GET_FLOAT_WORD(hx,x);
 	GET_FLOAT_WORD(hy,y);
@@ -44,14 +44,16 @@
 	    return Zero[(u_int32_t)sx>>31];	/* |x|=|y| return x*0*/
 
     /* determine ix = ilogb(x) */
-	if(hx<0x00800000) {	/* subnormal x */
-	    for (ix = -126,i=(hx<<8); i>0; i<<=1) ix -=1;
-	} else ix = (hx>>23)-127;
+	if(hx<0x00800000)
+	    ix = subnormal_ilogbf(hx);
+	else
+	    ix = (hx>>23)-127;
 
     /* determine iy = ilogb(y) */
-	if(hy<0x00800000) {	/* subnormal y */
-	    for (iy = -126,i=(hy<<8); i>=0; i<<=1) iy -=1;
-	} else iy = (hy>>23)-127;
+	if(hy<0x00800000)
+	    iy = subnormal_ilogbf(hy);
+	else
+	    iy = (hy>>23)-127;
 
     /* set up {hx,lx}, {hy,ly} and align y to x */
 	if(ix >= -126)
diff --git a/libm/upstream-freebsd/lib/msun/src/math_private.h b/libm/upstream-freebsd/lib/msun/src/math_private.h
index 1595f90..fbd84e2 100644
--- a/libm/upstream-freebsd/lib/msun/src/math_private.h
+++ b/libm/upstream-freebsd/lib/msun/src/math_private.h
@@ -739,6 +739,41 @@
 	(ar) = (x) - (ai);				\
 } while (0)
 
+/*
+ * For a subnormal double entity split into high and low parts, compute ilogb.
+ */
+static inline int32_t
+subnormal_ilogb(int32_t hi, int32_t lo)
+{
+	int32_t j;
+	uint32_t i;
+
+	j = -1022;
+	if (hi == 0) {
+	    j -= 21;
+	    i = (uint32_t)lo;
+	} else
+	    i = (uint32_t)hi << 11;
+
+	for (; i < 0x7fffffff; i <<= 1) j -= 1;
+
+	return (j);
+}
+
+/*
+ * For a subnormal float entity represented as an int32_t, compute ilogb.
+ */
+static inline int32_t
+subnormal_ilogbf(int32_t hx)
+{
+	int32_t j;
+	uint32_t i;
+	i = (uint32_t) hx << 8;
+	for (j = -126; i < 0x7fffffff; i <<= 1) j -=1;
+
+	return (j);
+}
+
 #ifdef DEBUG
 #if defined(__amd64__) || defined(__i386__)
 #define	breakpoint()	asm("int $3")
diff --git a/libm/upstream-freebsd/lib/msun/src/s_cbrt.c b/libm/upstream-freebsd/lib/msun/src/s_cbrt.c
index 6bf8424..568a365 100644
--- a/libm/upstream-freebsd/lib/msun/src/s_cbrt.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_cbrt.c
@@ -90,7 +90,7 @@
      * the result is larger in magnitude than cbrt(x) but not much more than
      * 2 23-bit ulps larger).  With rounding towards zero, the error bound
      * would be ~5/6 instead of ~4/6.  With a maximum error of 2 23-bit ulps
-     * in the rounded t, the infinite-precision error in the Newton
+     * in the rounded t, the infinite-precision error in the Halley
      * approximation barely affects third digit in the final error
      * 0.667; the error in the rounded t can be up to about 3 23-bit ulps
      * before the final error is larger than 0.667 ulps.
@@ -99,7 +99,7 @@
 	u.bits=(u.bits+0x80000000)&0xffffffffc0000000ULL;
 	t=u.value;
 
-    /* one step Newton iteration to 53 bits with error < 0.667 ulps */
+    /* one step Halley iteration to 53 bits with error < 0.667 ulps */
 	s=t*t;				/* t*t is exact */
 	r=x/s;				/* error <= 0.5 ulps; |r| < |t| */
 	w=t+t;				/* t+t is exact */
diff --git a/libm/upstream-freebsd/lib/msun/src/s_cbrtf.c b/libm/upstream-freebsd/lib/msun/src/s_cbrtf.c
index a225d3e..c69e0fa 100644
--- a/libm/upstream-freebsd/lib/msun/src/s_cbrtf.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_cbrtf.c
@@ -50,7 +50,7 @@
 	    SET_FLOAT_WORD(t,sign|(hx/3+B1));
 
     /*
-     * First step Newton iteration (solving t*t-x/t == 0) to 16 bits.  In
+     * First step Halley iteration (solving t*t-x/t == 0) to 16 bits.  In
      * double precision so that its terms can be arranged for efficiency
      * without causing overflow or underflow.
      */
@@ -59,7 +59,7 @@
 	T=T*((double)x+x+r)/(x+r+r);
 
     /*
-     * Second step Newton iteration to 47 bits.  In double precision for
+     * Second step Halley iteration to 47 bits.  In double precision for
      * efficiency and accuracy.
      */
 	r=T*T*T;
diff --git a/libm/upstream-freebsd/lib/msun/src/s_cbrtl.c b/libm/upstream-freebsd/lib/msun/src/s_cbrtl.c
index f1950e2..ff527cc 100644
--- a/libm/upstream-freebsd/lib/msun/src/s_cbrtl.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_cbrtl.c
@@ -126,7 +126,7 @@
 #endif
 
 	/*
-     	 * Final step Newton iteration to 64 or 113 bits with
+	 * Final step Halley iteration to 64 or 113 bits with
 	 * error < 0.667 ulps
 	 */
 	s=t*t;				/* t*t is exact */
diff --git a/libm/upstream-freebsd/lib/msun/src/s_ccosh.c b/libm/upstream-freebsd/lib/msun/src/s_ccosh.c
index 3d46c99..14a8931 100644
--- a/libm/upstream-freebsd/lib/msun/src/s_ccosh.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_ccosh.c
@@ -1,7 +1,7 @@
 /*-
  * SPDX-License-Identifier: BSD-2-Clause
  *
- * Copyright (c) 2005 Bruce D. Evans and Steven G. Kargl
+ * Copyright (c) 2005-2025 Bruce D. Evans and Steven G. Kargl
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -48,7 +48,7 @@
 double complex
 ccosh(double complex z)
 {
-	double x, y, h;
+	double c, h, s, x, y;
 	int32_t hx, hy, ix, iy, lx, ly;
 
 	x = creal(z);
@@ -64,14 +64,16 @@
 	if (ix < 0x7ff00000 && iy < 0x7ff00000) {
 		if ((iy | ly) == 0)
 			return (CMPLX(cosh(x), x * y));
+
+		sincos(y, &s, &c);
 		if (ix < 0x40360000)	/* |x| < 22: normal case */
-			return (CMPLX(cosh(x) * cos(y), sinh(x) * sin(y)));
+			return (CMPLX(cosh(x) * c, sinh(x) * s));
 
 		/* |x| >= 22, so cosh(x) ~= exp(|x|) */
 		if (ix < 0x40862e42) {
 			/* x < 710: exp(|x|) won't overflow */
-			h = exp(fabs(x)) * 0.5;
-			return (CMPLX(h * cos(y), copysign(h, x) * sin(y)));
+			h = exp(fabs(x)) / 2;
+			return (CMPLX(h * c, copysign(h, x) * s));
 		} else if (ix < 0x4096bbaa) {
 			/* x < 1455: scale to avoid overflow */
 			z = __ldexp_cexp(CMPLX(fabs(x), y), -1);
@@ -79,7 +81,7 @@
 		} else {
 			/* x >= 1455: the result always overflows */
 			h = huge * x;
-			return (CMPLX(h * h * cos(y), h * sin(y)));
+			return (CMPLX(h * h * c, h * s));
 		}
 	}
 
@@ -129,7 +131,9 @@
 	if (ix == 0x7ff00000 && lx == 0) {
 		if (iy >= 0x7ff00000)
 			return (CMPLX(INFINITY, x * (y - y)));
-		return (CMPLX(INFINITY * cos(y), x * sin(y)));
+
+		sincos(y, &s, &c);
+		return (CMPLX(INFINITY * c, x * s));
 	}
 
 	/*
@@ -154,3 +158,8 @@
 	/* ccos(z) = ccosh(I * z) */
 	return (ccosh(CMPLX(-cimag(z), creal(z))));
 }
+
+#if (LDBL_MANT_DIG == 53)
+__weak_reference(ccosh, ccoshl);
+__weak_reference(ccos, ccosl);
+#endif
diff --git a/libm/upstream-freebsd/lib/msun/src/s_ccoshf.c b/libm/upstream-freebsd/lib/msun/src/s_ccoshf.c
index aeb2dec..fa41fdf 100644
--- a/libm/upstream-freebsd/lib/msun/src/s_ccoshf.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_ccoshf.c
@@ -1,7 +1,7 @@
 /*-
  * SPDX-License-Identifier: BSD-2-Clause
  *
- * Copyright (c) 2005 Bruce D. Evans and Steven G. Kargl
+ * Copyright (c) 2005-2025 Bruce D. Evans and Steven G. Kargl
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -40,7 +40,7 @@
 float complex
 ccoshf(float complex z)
 {
-	float x, y, h;
+	float c, h, s, x, y;
 	int32_t hx, hy, ix, iy;
 
 	x = crealf(z);
@@ -55,14 +55,16 @@
 	if (ix < 0x7f800000 && iy < 0x7f800000) {
 		if (iy == 0)
 			return (CMPLXF(coshf(x), x * y));
+
+		sincosf(y, &s, &c);
 		if (ix < 0x41100000)	/* |x| < 9: normal case */
-			return (CMPLXF(coshf(x) * cosf(y), sinhf(x) * sinf(y)));
+			return (CMPLXF(coshf(x) * c, sinhf(x) * s));
 
 		/* |x| >= 9, so cosh(x) ~= exp(|x|) */
 		if (ix < 0x42b17218) {
 			/* x < 88.7: expf(|x|) won't overflow */
-			h = expf(fabsf(x)) * 0.5F;
-			return (CMPLXF(h * cosf(y), copysignf(h, x) * sinf(y)));
+			h = expf(fabsf(x)) / 2;
+			return (CMPLXF(h * c, copysignf(h, x) * s));
 		} else if (ix < 0x4340b1e7) {
 			/* x < 192.7: scale to avoid overflow */
 			z = __ldexp_cexpf(CMPLXF(fabsf(x), y), -1);
@@ -70,7 +72,7 @@
 		} else {
 			/* x >= 192.7: the result always overflows */
 			h = huge * x;
-			return (CMPLXF(h * h * cosf(y), h * sinf(y)));
+			return (CMPLXF(h * h * c, h * s));
 		}
 	}
 
@@ -86,7 +88,9 @@
 	if (ix == 0x7f800000) {
 		if (iy >= 0x7f800000)
 			return (CMPLXF(INFINITY, x * (y - y)));
-		return (CMPLXF(INFINITY * cosf(y), x * sinf(y)));
+
+		sincosf(y, &s, &c);
+		return (CMPLXF(INFINITY * c, x * s));
 	}
 
 	return (CMPLXF(((long double)x * x) * (y - y),
diff --git a/libm/upstream-freebsd/lib/msun/src/s_cpow.c b/libm/upstream-freebsd/lib/msun/src/s_cpow.c
index b887db5..2c20a8f 100644
--- a/libm/upstream-freebsd/lib/msun/src/s_cpow.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_cpow.c
@@ -58,7 +58,10 @@
 	y = cimag (z);
 	absa = cabs (a);
 	if (absa == 0.0) {
-		return (CMPLX(0.0, 0.0));
+		if (x == 0 && y == 0)
+		    return (CMPLX(1., 0.));
+		else
+		    return (CMPLX(0., 0.));
 	}
 	arga = carg (a);
 	r = pow (absa, x);
diff --git a/libm/upstream-freebsd/lib/msun/src/s_cpowf.c b/libm/upstream-freebsd/lib/msun/src/s_cpowf.c
index 1442910..b8bdbd9 100644
--- a/libm/upstream-freebsd/lib/msun/src/s_cpowf.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_cpowf.c
@@ -57,7 +57,10 @@
 	y = cimagf(z);
 	absa = cabsf (a);
 	if (absa == 0.0f) {
-		return (CMPLXF(0.0f, 0.0f));
+		if (x == 0 && y == 0)
+		    return (CMPLXF(1.f, 0.f));
+		else
+		    return (CMPLXF(0.f, 0.f));
 	}
 	arga = cargf (a);
 	r = powf (absa, x);
diff --git a/libm/upstream-freebsd/lib/msun/src/s_cpowl.c b/libm/upstream-freebsd/lib/msun/src/s_cpowl.c
index 39797ca..efbe493 100644
--- a/libm/upstream-freebsd/lib/msun/src/s_cpowl.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_cpowl.c
@@ -57,7 +57,10 @@
 	y = cimagl(z);
 	absa = cabsl(a);
 	if (absa == 0.0L) {
-		return (CMPLXL(0.0L, 0.0L));
+		if (x == 0 && y == 0)
+		    return (CMPLXL(1.L, 0.L));
+		else
+		    return (CMPLXL(0.L, 0.L));
 	}
 	arga = cargl(a);
 	r = powl(absa, x);
diff --git a/libm/upstream-freebsd/lib/msun/src/s_csinh.c b/libm/upstream-freebsd/lib/msun/src/s_csinh.c
index e7ed10e..11c2ec3 100644
--- a/libm/upstream-freebsd/lib/msun/src/s_csinh.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_csinh.c
@@ -1,7 +1,7 @@
 /*-
  * SPDX-License-Identifier: BSD-2-Clause
  *
- * Copyright (c) 2005 Bruce D. Evans and Steven G. Kargl
+ * Copyright (c) 2005-2025 Bruce D. Evans and Steven G. Kargl
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -48,7 +48,7 @@
 double complex
 csinh(double complex z)
 {
-	double x, y, h;
+	double c, h, s, x, y;
 	int32_t hx, hy, ix, iy, lx, ly;
 
 	x = creal(z);
@@ -64,14 +64,16 @@
 	if (ix < 0x7ff00000 && iy < 0x7ff00000) {
 		if ((iy | ly) == 0)
 			return (CMPLX(sinh(x), y));
+
+		sincos(y, &s, &c);
 		if (ix < 0x40360000)	/* |x| < 22: normal case */
-			return (CMPLX(sinh(x) * cos(y), cosh(x) * sin(y)));
+			return (CMPLX(sinh(x) * c, cosh(x) * s));
 
 		/* |x| >= 22, so cosh(x) ~= exp(|x|) */
 		if (ix < 0x40862e42) {
 			/* x < 710: exp(|x|) won't overflow */
-			h = exp(fabs(x)) * 0.5;
-			return (CMPLX(copysign(h, x) * cos(y), h * sin(y)));
+			h = exp(fabs(x)) / 2;
+			return (CMPLX(copysign(h, x) * c, h * s));
 		} else if (ix < 0x4096bbaa) {
 			/* x < 1455: scale to avoid overflow */
 			z = __ldexp_cexp(CMPLX(fabs(x), y), -1);
@@ -79,7 +81,7 @@
 		} else {
 			/* x >= 1455: the result always overflows */
 			h = huge * x;
-			return (CMPLX(h * cos(y), h * h * sin(y)));
+			return (CMPLX(h * c, h * h * s));
 		}
 	}
 
@@ -128,7 +130,9 @@
 	if (ix == 0x7ff00000 && lx == 0) {
 		if (iy >= 0x7ff00000)
 			return (CMPLX(x, y - y));
-		return (CMPLX(x * cos(y), INFINITY * sin(y)));
+
+		sincos(y, &s, &c);
+		return (CMPLX(x * c, INFINITY * s));
 	}
 
 	/*
@@ -154,3 +158,8 @@
 	z = csinh(CMPLX(cimag(z), creal(z)));
 	return (CMPLX(cimag(z), creal(z)));
 }
+
+#if (LDBL_MANT_DIG == 53)
+__weak_reference(csinh, csinhl);
+__weak_reference(csin, csinl);
+#endif
diff --git a/libm/upstream-freebsd/lib/msun/src/s_csinhf.c b/libm/upstream-freebsd/lib/msun/src/s_csinhf.c
index c439275..fcfc011 100644
--- a/libm/upstream-freebsd/lib/msun/src/s_csinhf.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_csinhf.c
@@ -1,7 +1,7 @@
 /*-
  * SPDX-License-Identifier: BSD-2-Clause
  *
- * Copyright (c) 2005 Bruce D. Evans and Steven G. Kargl
+ * Copyright (c) 2005-2025 Bruce D. Evans and Steven G. Kargl
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -40,7 +40,7 @@
 float complex
 csinhf(float complex z)
 {
-	float x, y, h;
+	float c, h, s, x, y;
 	int32_t hx, hy, ix, iy;
 
 	x = crealf(z);
@@ -55,14 +55,16 @@
 	if (ix < 0x7f800000 && iy < 0x7f800000) {
 		if (iy == 0)
 			return (CMPLXF(sinhf(x), y));
+
+		sincosf(y, &s, &c);
 		if (ix < 0x41100000)	/* |x| < 9: normal case */
-			return (CMPLXF(sinhf(x) * cosf(y), coshf(x) * sinf(y)));
+			return (CMPLXF(sinhf(x) * c, coshf(x) * s));
 
 		/* |x| >= 9, so cosh(x) ~= exp(|x|) */
 		if (ix < 0x42b17218) {
 			/* x < 88.7: expf(|x|) won't overflow */
-			h = expf(fabsf(x)) * 0.5F;
-			return (CMPLXF(copysignf(h, x) * cosf(y), h * sinf(y)));
+			h = expf(fabsf(x)) / 2;
+			return (CMPLXF(copysignf(h, x) * c, h * s));
 		} else if (ix < 0x4340b1e7) {
 			/* x < 192.7: scale to avoid overflow */
 			z = __ldexp_cexpf(CMPLXF(fabsf(x), y), -1);
@@ -70,7 +72,7 @@
 		} else {
 			/* x >= 192.7: the result always overflows */
 			h = huge * x;
-			return (CMPLXF(h * cosf(y), h * h * sinf(y)));
+			return (CMPLXF(h * c, h * h * s));
 		}
 	}
 
@@ -86,7 +88,9 @@
 	if (ix == 0x7f800000) {
 		if (iy >= 0x7f800000)
 			return (CMPLXF(x, y - y));
-		return (CMPLXF(x * cosf(y), INFINITY * sinf(y)));
+
+		sincosf(y, &s, &c);
+		return (CMPLXF(x * c, INFINITY * s));
 	}
 
 	return (CMPLXF(((long double)x + x) * (y - y),
diff --git a/libm/upstream-freebsd/lib/msun/src/s_ilogb.c b/libm/upstream-freebsd/lib/msun/src/s_ilogb.c
index 27e0bbb..aa707d5 100644
--- a/libm/upstream-freebsd/lib/msun/src/s_ilogb.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_ilogb.c
@@ -21,21 +21,18 @@
 #include "math.h"
 #include "math_private.h"
 
-	int ilogb(double x)
+int
+ilogb(double x)
 {
-	int32_t hx,lx,ix;
+	int32_t hx, ix, lx;
 
 	EXTRACT_WORDS(hx,lx,x);
 	hx &= 0x7fffffff;
 	if(hx<0x00100000) {
 	    if((hx|lx)==0)
 		return FP_ILOGB0;
-	    else			/* subnormal x */
-		if(hx==0) {
-		    for (ix = -1043; lx>0; lx<<=1) ix -=1;
-		} else {
-		    for (ix = -1022,hx<<=11; hx>0; hx<<=1) ix -=1;
-		}
+	    else
+		ix = subnormal_ilogb(hx, lx);
 	    return ix;
 	}
 	else if (hx<0x7ff00000) return (hx>>20)-1023;
diff --git a/libm/upstream-freebsd/lib/msun/src/s_ilogbf.c b/libm/upstream-freebsd/lib/msun/src/s_ilogbf.c
index e0f8fee..5195e23 100644
--- a/libm/upstream-freebsd/lib/msun/src/s_ilogbf.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_ilogbf.c
@@ -18,7 +18,8 @@
 #include "math.h"
 #include "math_private.h"
 
-	int ilogbf(float x)
+int
+ilogbf(float x)
 {
 	int32_t hx,ix;
 
@@ -28,7 +29,7 @@
 	    if(hx==0)
 		return FP_ILOGB0;
 	    else			/* subnormal x */
-	        for (ix = -126,hx<<=8; hx>0; hx<<=1) ix -=1;
+		ix = subnormal_ilogbf(hx);
 	    return ix;
 	}
 	else if (hx<0x7f800000) return (hx>>23)-127;
diff --git a/libm/upstream-freebsd/lib/msun/src/s_remquo.c b/libm/upstream-freebsd/lib/msun/src/s_remquo.c
index 206d290..b26b561 100644
--- a/libm/upstream-freebsd/lib/msun/src/s_remquo.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_remquo.c
@@ -4,7 +4,7 @@
  *
  * 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.
  * ====================================================
  */
@@ -27,7 +27,7 @@
 double
 remquo(double x, double y, int *quo)
 {
-	int32_t n,hx,hy,hz,ix,iy,sx,i;
+	int32_t hx,hy,hz,ix,iy,n,sx;
 	u_int32_t lx,ly,lz,q,sxy;
 
 	EXTRACT_WORDS(hx,lx,x);
@@ -53,25 +53,19 @@
 	}
 
     /* determine ix = ilogb(x) */
-	if(hx<0x00100000) {	/* subnormal x */
-	    if(hx==0) {
-		for (ix = -1043, i=lx; i>0; i<<=1) ix -=1;
-	    } else {
-		for (ix = -1022,i=(hx<<11); i>0; i<<=1) ix -=1;
-	    }
-	} else ix = (hx>>20)-1023;
+	if(hx<0x00100000)
+	    ix = subnormal_ilogb(hx, lx);
+	else
+	    ix = (hx>>20)-1023;
 
     /* determine iy = ilogb(y) */
-	if(hy<0x00100000) {	/* subnormal y */
-	    if(hy==0) {
-		for (iy = -1043, i=ly; i>0; i<<=1) iy -=1;
-	    } else {
-		for (iy = -1022,i=(hy<<11); i>0; i<<=1) iy -=1;
-	    }
-	} else iy = (hy>>20)-1023;
+	if(hy<0x00100000)
+	    iy = subnormal_ilogb(hy, ly);
+	else
+	    iy = (hy>>20)-1023;
 
     /* set up {hx,lx}, {hy,ly} and align y to x */
-	if(ix >= -1022) 
+	if(ix >= -1022)
 	    hx = 0x00100000|(0x000fffff&hx);
 	else {		/* subnormal x, shift x to normal */
 	    n = -1022-ix;
@@ -83,7 +77,7 @@
 		lx = 0;
 	    }
 	}
-	if(iy >= -1022) 
+	if(iy >= -1022)
 	    hy = 0x00100000|(0x000fffff&hy);
 	else {		/* subnormal y, shift y to normal */
 	    n = -1022-iy;
diff --git a/libm/upstream-freebsd/lib/msun/src/s_remquof.c b/libm/upstream-freebsd/lib/msun/src/s_remquof.c
index 9cd1485..e4adb83 100644
--- a/libm/upstream-freebsd/lib/msun/src/s_remquof.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_remquof.c
@@ -25,7 +25,7 @@
 float
 remquof(float x, float y, int *quo)
 {
-	int32_t n,hx,hy,hz,ix,iy,sx,i;
+	int32_t hx, hy, hz, ix, iy, n, sx;
 	u_int32_t q,sxy;
 
 	GET_FLOAT_WORD(hx,x);
@@ -47,14 +47,16 @@
 	}
 
     /* determine ix = ilogb(x) */
-	if(hx<0x00800000) {	/* subnormal x */
-	    for (ix = -126,i=(hx<<8); i>0; i<<=1) ix -=1;
-	} else ix = (hx>>23)-127;
+	if(hx<0x00800000)
+	    ix = subnormal_ilogbf(hx);
+	else
+	    ix = (hx>>23)-127;
 
     /* determine iy = ilogb(y) */
-	if(hy<0x00800000) {	/* subnormal y */
-	    for (iy = -126,i=(hy<<8); i>0; i<<=1) iy -=1;
-	} else iy = (hy>>23)-127;
+	if(hy<0x00800000)
+	    iy = subnormal_ilogbf(hy);
+	else
+	    iy = (hy>>23)-127;
 
     /* set up {hx,lx}, {hy,ly} and align y to x */
 	if(ix >= -126)
diff --git a/linker/Android.bp b/linker/Android.bp
index ea4e699..5970dea 100644
--- a/linker/Android.bp
+++ b/linker/Android.bp
@@ -435,6 +435,7 @@
 }
 
 cc_library {
+    name: "ld-android",
     srcs: ["ld_android.cpp"],
     cflags: [
         "-Wall",
@@ -444,7 +445,6 @@
     ],
     stl: "none",
 
-    name: "ld-android",
     defaults: [
         "linux_bionic_supported",
         "linker_version_script_overlay",
@@ -474,6 +474,7 @@
 cc_test {
     name: "linker-unit-tests",
     test_suites: ["device-tests"],
+    isolated: true,
 
     cflags: [
         "-g",
@@ -509,7 +510,8 @@
         "linker_mapped_file_fragment.cpp",
         "linker_sdk_versions.cpp",
         "linker_dlwarning.cpp",
-        "linker_phdr_16kib_compat.cpp"
+        "linker_phdr_16kib_compat.cpp",
+        "linker_transparent_hugepage_support.cpp",
     ],
 
     static_libs: [
@@ -531,6 +533,7 @@
         },
         arm64: {
             srcs: ["arch/arm_neon/linker_gnu_hash_neon.cpp"],
+            data_libs: ["note_gnu_property"],
         },
     },
 }
diff --git a/linker/arch/arm/begin.S b/linker/arch/arm/begin.S
index 3b673f0..515e1ba 100644
--- a/linker/arch/arm/begin.S
+++ b/linker/arch/arm/begin.S
@@ -30,7 +30,7 @@
 
 ENTRY(_start)
   // Force unwinds to end in this function.
-  .cfi_undefined r14
+  .cfi_undefined lr
 
   mov r0, sp
   bl __linker_init
diff --git a/linker/arch/arm64/begin.S b/linker/arch/arm64/begin.S
index 14999cd..a35a294 100644
--- a/linker/arch/arm64/begin.S
+++ b/linker/arch/arm64/begin.S
@@ -30,7 +30,7 @@
 
 ENTRY(_start)
   // Force unwinds to end in this function.
-  .cfi_undefined x30
+  .cfi_undefined lr
 
   mov x0, sp
   bl __linker_init
diff --git a/linker/arch/arm64/tlsdesc_resolver.S b/linker/arch/arm64/tlsdesc_resolver.S
index 84407dd..ff8e20f 100644
--- a/linker/arch/arm64/tlsdesc_resolver.S
+++ b/linker/arch/arm64/tlsdesc_resolver.S
@@ -115,12 +115,12 @@
 ENTRY_PRIVATE(tlsdesc_resolver_dynamic_slow_path)
   sub sp, sp, #(8 * 84)
   .cfi_def_cfa_offset (8 * 84)
-  SAVE_GPR_PAIR(x29, x30, 0)
-  mov x29, sp
+  SAVE_GPR_PAIR(fp, lr, 0)
+  mov fp, sp
 
   // Avoid leaking the contents of the shadow call stack register (x18) into
-  // memory. x19 through x29 are callee-save registers, so we do not need to
-  // save them.
+  // memory. x19 through x29 (fp) are callee-save registers, so we do not need
+  // to save them.
   SAVE_GPR_PAIR(x1,  x2,  2)
   SAVE_GPR_PAIR(x3,  x4,  4)
   SAVE_GPR_PAIR(x5,  x6,  6)
@@ -180,7 +180,7 @@
   RESTORE_REG_PAIR(x3,  x4,  4)
   RESTORE_REG_PAIR(x1,  x2,  2)
 
-  RESTORE_REG_PAIR(x29, x30, 0)
+  RESTORE_REG_PAIR(fp, lr, 0)
   add sp, sp, #(8 * 84)
   .cfi_def_cfa_offset 0
   ret
diff --git a/linker/dlfcn.cpp b/linker/dlfcn.cpp
index fc95903..afd8993 100644
--- a/linker/dlfcn.cpp
+++ b/linker/dlfcn.cpp
@@ -330,6 +330,8 @@
     __libdl_info->load_bias = linker_si.load_bias;
     __libdl_info->phdr = linker_si.phdr;
     __libdl_info->phnum = linker_si.phnum;
+    __libdl_info->base = linker_si.base;
+    __libdl_info->size = linker_si.size;
 
     __libdl_info->gnu_nbucket_ = linker_si.gnu_nbucket_;
     __libdl_info->gnu_maskwords_ = linker_si.gnu_maskwords_;
diff --git a/linker/linker.cpp b/linker/linker.cpp
index 4cf93b9..29e67ce 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -376,18 +376,21 @@
   g_default_namespace.set_ld_library_paths(std::move(ld_libary_paths));
 }
 
+static bool is_proc_mounted() {
+  static bool result = (access("/proc/self/fd", F_OK) == 0);
+  return result;
+}
+
 static bool realpath_fd(int fd, std::string* realpath) {
   // proc_self_fd needs to be large enough to hold "/proc/self/fd/" plus an
   // integer, plus the NULL terminator.
   char proc_self_fd[32];
-  // We want to statically allocate this large buffer so that we don't grow
-  // the stack by too much.
-  static char buf[PATH_MAX];
-
   async_safe_format_buffer(proc_self_fd, sizeof(proc_self_fd), "/proc/self/fd/%d", fd);
+
+  char buf[PATH_MAX];
   auto length = readlink(proc_self_fd, buf, sizeof(buf));
   if (length == -1) {
-    if (!is_first_stage_init()) {
+    if (is_proc_mounted()) {
       DL_WARN("readlink(\"%s\" [fd=%d]) failed: %m", proc_self_fd, fd);
     }
     return false;
@@ -642,9 +645,10 @@
     si_->set_gap_size(elf_reader.gap_size());
     si_->set_should_pad_segments(elf_reader.should_pad_segments());
     si_->set_should_use_16kib_app_compat(elf_reader.should_use_16kib_app_compat());
+    si_->set_should_16kib_app_compat_use_rwx(elf_reader.should_16kib_app_compat_use_rwx());
     if (si_->should_use_16kib_app_compat()) {
-      si_->set_compat_relro_start(elf_reader.compat_relro_start());
-      si_->set_compat_relro_size(elf_reader.compat_relro_size());
+      si_->set_compat_code_start(elf_reader.compat_code_start());
+      si_->set_compat_code_size(elf_reader.compat_code_size());
     }
 
     return true;
@@ -844,7 +848,7 @@
   // Since RTLD_GLOBAL is always set for the main executable and all dt_needed shared
   // libraries and they are loaded in breath-first (correct) order we can just execute
   // dlsym(RTLD_DEFAULT, ...); instead of doing two stage lookup.
-  if (si == solist_get_somain()) {
+  if (si == solist_get_executable()) {
     return dlsym_linear_lookup(&g_default_namespace, name, vi, found, nullptr, RTLD_DEFAULT);
   }
 
@@ -981,7 +985,7 @@
   if (realpath_fd(fd, realpath)) {
     *realpath += separator;
   } else {
-    if (!is_first_stage_init()) {
+    if (is_proc_mounted()) {
       DL_WARN("unable to get realpath for the library \"%s\". Will use given path.",
               normalized_path.c_str());
     }
@@ -1014,7 +1018,7 @@
     if (fd != -1) {
       *file_offset = 0;
       if (!realpath_fd(fd, realpath)) {
-        if (!is_first_stage_init()) {
+        if (is_proc_mounted()) {
           DL_WARN("unable to get realpath for the library \"%s\". Will use given path.", path);
         }
         *realpath = path;
@@ -1326,7 +1330,7 @@
 
     std::string realpath;
     if (!realpath_fd(extinfo->library_fd, &realpath)) {
-      if (!is_first_stage_init()) {
+      if (is_proc_mounted()) {
         DL_WARN("unable to get realpath for the library \"%s\" by extinfo->library_fd. "
                 "Will use given name.",
                 name);
@@ -1653,8 +1657,13 @@
       return t->get_soinfo() == si;
     };
 
-    if (!si->is_linked() &&
-        std::find_if(load_list.begin(), load_list.end(), pred) == load_list.end() ) {
+    // If the executable depends on itself (directly or indirectly), then the executable ends up on
+    // the list of LoadTask objects (b/328822319). It is already loaded, so don't try to load it
+    // again, which will fail because its ElfReader isn't ready. This can happen if ldd is invoked
+    // on a shared library that depends on itself, which happens with HWASan-ified Bionic libraries
+    // like libc.so, libm.so, etc.
+    if (!si->is_linked() && !si->is_main_executable() &&
+        std::find_if(load_list.begin(), load_list.end(), pred) == load_list.end()) {
       load_list.push_back(task);
     }
   }
@@ -1858,7 +1867,7 @@
   soinfo* si = nullptr;
 
   if (name == nullptr) {
-    si = solist_get_somain();
+    si = solist_get_head();
   } else if (!find_libraries(ns,
                              needed_by,
                              &name,
@@ -3324,7 +3333,7 @@
   // they could no longer be found by DT_NEEDED from another library.
   // The main executable does not need to have a DT_SONAME.
   // The linker has a DT_SONAME, but the soname_ field is initialized later on.
-  if (soname_.empty() && this != solist_get_somain() && !relocating_linker &&
+  if (soname_.empty() && this != solist_get_executable() && !relocating_linker &&
       get_application_target_sdk_version() < 23) {
     soname_ = basename(realpath_.c_str());
     // The `if` above means we don't get here for targetSdkVersion >= 23,
@@ -3414,6 +3423,12 @@
     return false;
   }
 
+  // Now that we've finished linking we can apply execute permission to code segments in compat
+  // loaded binaries, and remove write permission from .text and GNU RELRO in RX|RW compat mode.
+  if (!protect_16kib_app_compat_code()) {
+    return false;
+  }
+
   if (should_tag_memtag_globals()) {
     std::list<std::string>* vma_names_ptr = vma_names();
     // should_tag_memtag_globals -> __aarch64__ -> vma_names() != nullptr
@@ -3444,18 +3459,31 @@
 
 bool soinfo::protect_relro() {
   if (should_use_16kib_app_compat_) {
-    if (phdr_table_protect_gnu_relro_16kib_compat(compat_relro_start_, compat_relro_size_) < 0) {
-      DL_ERR("can't enable COMPAT GNU RELRO protection for \"%s\": %s", get_realpath(),
-             strerror(errno));
-      return false;
-    }
-  } else {
-    if (phdr_table_protect_gnu_relro(phdr, phnum, load_bias, should_pad_segments_,
-                                     should_use_16kib_app_compat_) < 0) {
-      DL_ERR("can't enable GNU RELRO protection for \"%s\": %m", get_realpath());
-      return false;
-    }
+    return true;
   }
+
+  if (phdr_table_protect_gnu_relro(phdr, phnum, load_bias, should_pad_segments_) < 0) {
+    DL_ERR("can't enable GNU RELRO protection for \"%s\": %m", get_realpath());
+    return false;
+  }
+
+  return true;
+}
+
+bool soinfo::protect_16kib_app_compat_code() {
+  if (!should_use_16kib_app_compat_) {
+    return true;
+  }
+
+  auto note_gnu_property = GnuPropertySection(this);
+  if (phdr_table_protect_16kib_app_compat_code(compat_code_start_, compat_code_size_,
+                                               should_16kib_app_compat_use_rwx_,
+                                               &note_gnu_property) < 0) {
+    DL_ERR("failed to set execute permission for compat loaded binary \"%s\": %s", get_realpath(),
+           strerror(errno));
+    return false;
+  }
+
   return true;
 }
 
@@ -3644,8 +3672,8 @@
     LD_DEBUG(any, "[ Reading linker config \"%s\" ]", ld_config_file_path.c_str());
     ScopedTrace trace(("linker config " + ld_config_file_path).c_str());
     std::string error_msg;
-    if (!Config::read_binary_config(ld_config_file_path.c_str(), executable_path, g_is_asan, g_is_hwasan,
-                                    &config, &error_msg)) {
+    if (!Config::read_config_for_binary(ld_config_file_path.c_str(), executable_path,
+                                        g_is_asan, g_is_hwasan, &config, &error_msg)) {
       if (!error_msg.empty()) {
         DL_WARN("Warning: couldn't read '%s' for '%s' (using default configuration instead): %s",
                 ld_config_file_path.c_str(), executable_path, error_msg.c_str());
@@ -3711,7 +3739,7 @@
   }
   // we can no longer rely on the fact that libdl.so is part of default namespace
   // this is why we want to add ld-android.so to all namespaces from ld.config.txt
-  soinfo* ld_android_so = solist_get_head();
+  soinfo* ld_android_so = solist_get_linker();
 
   // we also need vdso to be available for all namespaces (if present)
   soinfo* vdso = solist_get_vdso();
diff --git a/linker/linker.h b/linker/linker.h
index 86ef762..80ee00d 100644
--- a/linker/linker.h
+++ b/linker/linker.h
@@ -36,6 +36,7 @@
 #include <sys/stat.h>
 #include <unistd.h>
 
+#include "platform/bionic/dlext_namespaces.h"
 #include "platform/bionic/page.h"
 #include "linked_list.h"
 #include "linker_common_types.h"
@@ -107,45 +108,6 @@
 void set_16kb_appcompat_mode(bool enable_app_compat);
 bool get_16kb_appcompat_mode();
 
-enum {
-  /* A regular namespace is the namespace with a custom search path that does
-   * not impose any restrictions on the location of native libraries.
-   */
-  ANDROID_NAMESPACE_TYPE_REGULAR = 0,
-
-  /* An isolated namespace requires all the libraries to be on the search path
-   * or under permitted_when_isolated_path. The search path is the union of
-   * ld_library_path and default_library_path.
-   */
-  ANDROID_NAMESPACE_TYPE_ISOLATED = 1,
-
-  /* The shared namespace clones the list of libraries of the caller namespace upon creation
-   * which means that they are shared between namespaces - the caller namespace and the new one
-   * will use the same copy of a library if it was loaded prior to android_create_namespace call.
-   *
-   * Note that libraries loaded after the namespace is created will not be shared.
-   *
-   * Shared namespaces can be isolated or regular. Note that they do not inherit the search path nor
-   * permitted_path from the caller's namespace.
-   */
-  ANDROID_NAMESPACE_TYPE_SHARED = 2,
-
-  /* This flag instructs linker to enable exempt-list workaround for the namespace.
-   * See http://b/26394120 for details.
-   */
-  ANDROID_NAMESPACE_TYPE_EXEMPT_LIST_ENABLED = 0x08000000,
-
-  /* This flag instructs linker to use this namespace as the anonymous
-   * namespace. There can be only one anonymous namespace in a process. If there
-   * already an anonymous namespace in the process, using this flag when
-   * creating a new namespace causes an error
-   */
-  ANDROID_NAMESPACE_TYPE_ALSO_USED_AS_ANONYMOUS = 0x10000000,
-
-  ANDROID_NAMESPACE_TYPE_SHARED_ISOLATED = ANDROID_NAMESPACE_TYPE_SHARED |
-                                           ANDROID_NAMESPACE_TYPE_ISOLATED,
-};
-
 bool init_anonymous_namespace(const char* shared_lib_sonames, const char* library_search_path);
 android_namespace_t* create_namespace(const void* caller_addr,
                                       const char* name,
diff --git a/linker/linker_block_allocator.cpp b/linker/linker_block_allocator.cpp
index e70e6ae..d7f517e 100644
--- a/linker/linker_block_allocator.cpp
+++ b/linker/linker_block_allocator.cpp
@@ -55,7 +55,7 @@
 static_assert(kBlockSizeMin == sizeof(FreeBlockInfo));
 
 LinkerBlockAllocator::LinkerBlockAllocator(size_t block_size)
-    : block_size_(__BIONIC_ALIGN(MAX(block_size, kBlockSizeMin), kBlockSizeAlign)),
+    : block_size_(__builtin_align_up(MAX(block_size, kBlockSizeMin), kBlockSizeAlign)),
       page_list_(nullptr),
       free_block_list_(nullptr),
       allocated_(0) {}
diff --git a/linker/linker_block_allocator_test.cpp b/linker/linker_block_allocator_test.cpp
index 56fbee8..4dab5d5 100644
--- a/linker/linker_block_allocator_test.cpp
+++ b/linker/linker_block_allocator_test.cpp
@@ -78,7 +78,7 @@
   ASSERT_TRUE(ptr2 != nullptr);
 
   // they should be next to each other.
-  size_t dist = __BIONIC_ALIGN(MAX(sizeof(Element), kBlockSizeMin), kBlockSizeAlign);
+  size_t dist = __builtin_align_up(MAX(sizeof(Element), kBlockSizeMin), kBlockSizeAlign);
   ASSERT_EQ(reinterpret_cast<uint8_t*>(ptr1) + dist, reinterpret_cast<uint8_t*>(ptr2));
 
   allocator.free(ptr1);
diff --git a/linker/linker_config.cpp b/linker/linker_config.cpp
index 35a93fc..91f7811 100644
--- a/linker/linker_config.cpp
+++ b/linker/linker_config.cpp
@@ -454,12 +454,12 @@
   DISALLOW_IMPLICIT_CONSTRUCTORS(Properties);
 };
 
-bool Config::read_binary_config(const char* ld_config_file_path,
-                                      const char* binary_realpath,
-                                      bool is_asan,
-                                      bool is_hwasan,
-                                      const Config** config,
-                                      std::string* error_msg) {
+bool Config::read_config_for_binary(const char* ld_config_file_path,
+                                    const char* binary_realpath,
+                                    bool is_asan,
+                                    bool is_hwasan,
+                                    const Config** config,
+                                    std::string* error_msg) {
   g_config.clear();
 
   std::unordered_map<std::string, PropertyValue> property_map;
diff --git a/linker/linker_config.h b/linker/linker_config.h
index 09fea45..72056c5 100644
--- a/linker/linker_config.h
+++ b/linker/linker_config.h
@@ -163,12 +163,12 @@
   // most one configuration.
   // Returns false in case of an error. If binary config was not found
   // sets *config = nullptr.
-  static bool read_binary_config(const char* ld_config_file_path,
-                                 const char* binary_realpath,
-                                 bool is_asan,
-                                 bool is_hwasan,
-                                 const Config** config,
-                                 std::string* error_msg);
+  static bool read_config_for_binary(const char* ld_config_file_path,
+                                     const char* binary_realpath,
+                                     bool is_asan,
+                                     bool is_hwasan,
+                                     const Config** config,
+                                     std::string* error_msg);
 
   static std::string get_vndk_version_string(const char delimiter);
  private:
diff --git a/linker/linker_config_test.cpp b/linker/linker_config_test.cpp
index 7e947f3..5fabc98 100644
--- a/linker/linker_config_test.cpp
+++ b/linker/linker_config_test.cpp
@@ -182,12 +182,12 @@
   // read config
   const Config* config = nullptr;
   std::string error_msg;
-  ASSERT_TRUE(Config::read_binary_config(tmp_file.path,
-                                         executable_path.c_str(),
-                                         type == SmokeTestType::Asan,
-                                         type == SmokeTestType::Hwasan,
-                                         &config,
-                                         &error_msg)) << error_msg;
+  ASSERT_TRUE(Config::read_config_for_binary(tmp_file.path,
+                                             executable_path.c_str(),
+                                             type == SmokeTestType::Asan,
+                                             type == SmokeTestType::Hwasan,
+                                             &config,
+                                             &error_msg)) << error_msg;
   ASSERT_TRUE(config != nullptr);
   ASSERT_TRUE(error_msg.empty());
 
@@ -296,12 +296,12 @@
 
   const Config* config = nullptr;
   std::string error_msg;
-  ASSERT_FALSE(Config::read_binary_config(tmp_file.path,
-                                          executable_path.c_str(),
-                                          false,
-                                          false,
-                                          &config,
-                                          &error_msg));
+  ASSERT_FALSE(Config::read_config_for_binary(tmp_file.path,
+                                              executable_path.c_str(),
+                                              false,
+                                              false,
+                                              &config,
+                                              &error_msg));
   ASSERT_TRUE(config == nullptr);
   ASSERT_EQ(std::string(tmp_file.path) + ":6: "
             "error: both shared_libs and allow_all_shared_libs are set for default->system link.",
@@ -342,12 +342,12 @@
   const Config* config = nullptr;
   std::string error_msg;
 
-  ASSERT_TRUE(Config::read_binary_config(tmp_file.path,
-                                         executable_path.c_str(),
-                                         false,
-                                         false,
-                                         &config,
-                                         &error_msg)) << error_msg;
+  ASSERT_TRUE(Config::read_config_for_binary(tmp_file.path,
+                                             executable_path.c_str(),
+                                             false,
+                                             false,
+                                             &config,
+                                             &error_msg)) << error_msg;
 
   ASSERT_TRUE(config != nullptr) << error_msg;
   ASSERT_TRUE(error_msg.empty()) << error_msg;
diff --git a/linker/linker_debug.h b/linker/linker_debug.h
index e5f17c4..e453934 100644
--- a/linker/linker_debug.h
+++ b/linker/linker_debug.h
@@ -60,9 +60,10 @@
 
 extern LinkerDebugConfig g_linker_debug_config;
 
-__LIBC_HIDDEN__ void init_LD_DEBUG(const std::string& value);
-__LIBC_HIDDEN__ void __linker_log(int prio, const char* fmt, ...) __printflike(2, 3);
-__LIBC_HIDDEN__ void __linker_error(const char* fmt, ...) __printflike(1, 2);
+void init_LD_DEBUG(const std::string& value);
+
+void __linker_log(int prio, const char* fmt, ...) __printflike(2, 3);
+void __linker_error(const char* fmt, ...) __printflike(1, 2);
 
 #define LD_DEBUG(what, x...) \
   do { \
diff --git a/linker/linker_gdb_support.cpp b/linker/linker_gdb_support.cpp
index d120e35..38489bf 100644
--- a/linker/linker_gdb_support.cpp
+++ b/linker/linker_gdb_support.cpp
@@ -60,7 +60,7 @@
   r_debug_tail = map;
 }
 
-void remove_link_map_from_debug_map(link_map* map) {
+static void remove_link_map_from_debug_map(link_map* map) {
   if (r_debug_tail == map) {
     r_debug_tail = map->l_prev;
   }
diff --git a/linker/linker_gdb_support.h b/linker/linker_gdb_support.h
index 4ae18ee..3d17edc 100644
--- a/linker/linker_gdb_support.h
+++ b/linker/linker_gdb_support.h
@@ -34,7 +34,6 @@
 __BEGIN_DECLS
 
 void insert_link_map_into_debug_map(link_map* map);
-void remove_link_map_from_debug_map(link_map* map);
 void notify_gdb_of_load(link_map* map);
 void notify_gdb_of_unload(link_map* map);
 void notify_gdb_of_libraries();
diff --git a/linker/linker_globals.h b/linker/linker_globals.h
index 777e7b8..be1b1fd 100644
--- a/linker/linker_globals.h
+++ b/linker/linker_globals.h
@@ -105,5 +105,5 @@
   std::string saved_error_msg_;
 };
 
-__LIBC_HIDDEN__ extern bool g_is_ldd;
-__LIBC_HIDDEN__ extern pthread_mutex_t g_dl_mutex;
+extern bool g_is_ldd;
+extern pthread_mutex_t g_dl_mutex;
diff --git a/linker/linker_main.cpp b/linker/linker_main.cpp
index 425bcda..ce1337c 100644
--- a/linker/linker_main.cpp
+++ b/linker/linker_main.cpp
@@ -62,7 +62,7 @@
 
 #include <vector>
 
-__LIBC_HIDDEN__ extern "C" void _start();
+extern "C" void _start();
 
 static ElfW(Addr) get_elf_exec_load_bias(const ElfW(Ehdr)* elf);
 
@@ -80,56 +80,70 @@
   __linker_error("CANNOT LINK EXECUTABLE \"%s\": %s", argv0, linker_get_error_buffer());
 }
 
-// These should be preserved static to avoid emitting
+// These all need to be static to avoid emitting
 // RELATIVE relocations for the part of the code running
 // before linker links itself.
 
-// TODO (dimtiry): remove somain, rename solist to solist_head
-static soinfo* solist;
-static soinfo* sonext;
-static soinfo* somain; // main process, always the one after libdl_info
+/** The head of the list of all objects (including the executable and the linker itself), used for iteration. */
+static soinfo* solist_head;
+/** The tail of the list of all objects (including the executable and the linker itself), used for insertion. */
+static soinfo* solist_tail;
+
+/** The main executable. */
+static soinfo* somain;
+/** The linker. */
 static soinfo* solinker;
-static soinfo* vdso; // vdso if present
+/** The vdso (can be null). */
+static soinfo* vdso;
 
 void solist_add_soinfo(soinfo* si) {
-  sonext->next = si;
-  sonext = si;
+  if (solist_tail == nullptr) {
+    solist_head = solist_tail = si;
+  } else {
+    solist_tail->next = si;
+    solist_tail = si;
+  }
 }
 
 bool solist_remove_soinfo(soinfo* si) {
-  soinfo *prev = nullptr, *trav;
-  for (trav = solist; trav != nullptr; trav = trav->next) {
-    if (trav == si) {
+  soinfo *prev = nullptr, *it;
+  for (it = solist_get_head(); it != nullptr; it = it->next) {
+    if (it == si) {
       break;
     }
-    prev = trav;
+    prev = it;
   }
 
-  if (trav == nullptr) {
-    // si was not in solist
+  if (it == nullptr) {
     DL_WARN("name \"%s\"@%p is not in solist!", si->get_realpath(), si);
     return false;
   }
 
-  // prev will never be null, because the first entry in solist is
-  // always the static libdl_info.
+  // prev will never be null, nor the head of the list,
+  // because the main executable and linker are first,
+  // and they can't be removed.
   CHECK(prev != nullptr);
+  CHECK(prev != solist_head);
   prev->next = si->next;
-  if (si == sonext) {
-    sonext = prev;
+  if (solist_tail == si) {
+    solist_tail = prev;
   }
 
   return true;
 }
 
 soinfo* solist_get_head() {
-  return solist;
+  return solist_head;
 }
 
-soinfo* solist_get_somain() {
+soinfo* solist_get_executable() {
   return somain;
 }
 
+soinfo* solist_get_linker() {
+  return solinker;
+}
+
 soinfo* solist_get_vdso() {
   return vdso;
 }
@@ -218,9 +232,9 @@
   // Stat "/proc/self/exe" instead of executable_path because
   // the executable could be unlinked by this point and it should
   // not cause a crash (see http://b/31084669)
-  if (TEMP_FAILURE_RETRY(stat(exe_path, &result.file_stat) == -1)) {
+  if (TEMP_FAILURE_RETRY(stat(exe_path, &result.file_stat)) == -1) {
     // Fallback to argv[0] for the case where /proc isn't available
-    if (TEMP_FAILURE_RETRY(stat(arg_path, &result.file_stat) == -1)) {
+    if (TEMP_FAILURE_RETRY(stat(arg_path, &result.file_stat)) == -1) {
       async_safe_fatal("unable to stat either \"/proc/self/exe\" or \"%s\": %m", arg_path);
     }
     exe_path = arg_path;
@@ -329,6 +343,7 @@
   LD_DEBUG(any, "[ Linking executable \"%s\" ]", exe_info.path.c_str());
 
   // Initialize the main exe's soinfo.
+  // TODO: lose `si` and go straight to somain for clarity.
   soinfo* si = soinfo_alloc(&g_default_namespace,
                             exe_info.path.c_str(), &exe_info.file_stat,
                             0, RTLD_GLOBAL);
@@ -341,9 +356,14 @@
   si->dynamic = nullptr;
   si->set_main_executable();
   init_link_map_head(*si);
-
   set_bss_vma_name(si);
 
+  // Add the linker's soinfo.
+  // We need to do this manually because it's placement-new'ed by get_libdl_info(),
+  // not created by soinfo_alloc() like everything else.
+  // We do it here because we want it to come after the executable in solist.
+  solist_add_soinfo(solinker);
+
   // Use the executable's PT_INTERP string as the solinker filename in the
   // dynamic linker's module list. gdb reads both PT_INTERP and the module list,
   // and if the paths for the linker are different, gdb will report that the
@@ -393,7 +413,7 @@
   // and ".plt" sections. Gdb could also potentially use this to
   // relocate the offset of our exported 'rtld_db_dlactivity' symbol.
   //
-  insert_link_map_into_debug_map(&si->link_map_head);
+  insert_link_map_into_debug_map(&somain->link_map_head);
   insert_link_map_into_debug_map(&solinker->link_map_head);
 
   add_vdso();
@@ -480,7 +500,7 @@
   linker_finalize_static_tls();
   __libc_init_main_thread_final();
 
-  if (!get_cfi_shadow()->InitialLinkDone(solist)) __linker_cannot_link(g_argv[0]);
+  if (!get_cfi_shadow()->InitialLinkDone(solist_get_head())) __linker_cannot_link(g_argv[0]);
 
   si->call_pre_init_constructors();
   si->call_constructors();
@@ -580,7 +600,9 @@
 const unsigned kRelSzTag = DT_RELSZ;
 #endif
 
-extern __LIBC_HIDDEN__ ElfW(Ehdr) __ehdr_start;
+// Magic linker-provided pointer to the ELF header.
+// Hidden so it's accessible before linker relocations have been processed.
+extern "C" const ElfW(Ehdr) __ehdr_start __attribute__((__visibility__("hidden")));
 
 static void call_ifunc_resolvers_for_section(RelType* begin, RelType* end) {
   auto ehdr = reinterpret_cast<ElfW(Addr)>(&__ehdr_start);
@@ -820,22 +842,18 @@
     }
   }
 
-  // store argc/argv/envp to use them for calling constructors
+  // Store argc/argv/envp to use them for calling constructors.
   g_argc = args.argc - __libc_shared_globals()->initial_linker_arg_count;
   g_argv = args.argv + __libc_shared_globals()->initial_linker_arg_count;
   g_envp = args.envp;
   __libc_shared_globals()->init_progname = g_argv[0];
 
-  // Initialize static variables. Note that in order to
-  // get correct libdl_info we need to call constructors
-  // before get_libdl_info().
-  sonext = solist = solinker = get_libdl_info(tmp_linker_so);
+  solinker = get_libdl_info(tmp_linker_so);
   g_default_namespace.add_soinfo(solinker);
 
   ElfW(Addr) start_address = linker_main(args, exe_to_load);
 
-  LD_DEBUG(any, "[ Jumping to _start (%p)... ]", reinterpret_cast<void*>(start_address));
-
   // Return the address that the calling assembly stub should jump to.
+  LD_DEBUG(any, "[ Jumping to _start (%p)... ]", reinterpret_cast<void*>(start_address));
   return start_address;
 }
diff --git a/linker/linker_main.h b/linker/linker_main.h
index bec9d35..7341fa8 100644
--- a/linker/linker_main.h
+++ b/linker/linker_main.h
@@ -68,8 +68,17 @@
 
 void solist_add_soinfo(soinfo* si);
 bool solist_remove_soinfo(soinfo* si);
+
+/** Everything: the executable, the linker, and all the libraries. */
 soinfo* solist_get_head();
-soinfo* solist_get_somain();
+
+/** The executable. */
+soinfo* solist_get_executable();
+
+/** The linker. */
+soinfo* solist_get_linker();
+
+/** The VDSO. */
 soinfo* solist_get_vdso();
 
 void linker_memcpy(void* dst, const void* src, size_t n);
diff --git a/linker/linker_note_gnu_property_test.cpp b/linker/linker_note_gnu_property_test.cpp
index 2a5eddc..525d39d 100644
--- a/linker/linker_note_gnu_property_test.cpp
+++ b/linker/linker_note_gnu_property_test.cpp
@@ -31,13 +31,19 @@
 #include <sstream>
 #include <string>
 
+#include <android-base/file.h>
+#include <android-base/unique_fd.h>
 #include <gtest/gtest.h>
 
 #include "linker.h"
 #include "linker_globals.h"
 #include "linker_note_gnu_property.h"
+#include "linker_phdr.h"
 #include "platform/bionic/macros.h"
 
+using ::android::base::GetExecutableDirectory;
+using ::android::base::unique_fd;
+
 #define SONAME "test_so"
 
 static char error_buffer[1024];
@@ -433,3 +439,36 @@
   GTEST_SKIP() << "BTI is not supported on this architecture.";
 #endif
 }
+
+// Test that .note.gnu.property is properly loaded from a binary with a non-zero image base.
+TEST(note_gnu_property, find_gnu_property_offset_image_base) {
+#if defined(__aarch64__)
+  std::string path = GetExecutableDirectory() + "/note_gnu_property.so";
+
+  unique_fd fd{TEMP_FAILURE_RETRY(open(path.c_str(), O_RDONLY | O_CLOEXEC))};
+  ASSERT_GE(fd.get(), 0) << "Failed to open " << path << ": " << strerror(errno);
+
+  struct stat file_stat;
+  ASSERT_NE(TEMP_FAILURE_RETRY(fstat(fd.get(), &file_stat)), -1)
+      << "Failed to stat " << path << ": " << strerror(errno);
+
+  ElfReader elf_reader;
+  ASSERT_TRUE(elf_reader.Read(path.c_str(), fd.get(), 0, file_stat.st_size))
+      << "Failed to read ELF file";
+
+  // Load the binary as if BTI isn't supported so that we can run on any CPU.
+  auto bti_supported_orig = g_platform_properties.bti_supported;
+  g_platform_properties.bti_supported = false;
+
+  address_space_params address_space;
+  EXPECT_TRUE(elf_reader.Load(&address_space)) << "Failed to load ELF file";
+
+  // IsBTICompatible() checks for g_platform_properties.bti_supported.
+  g_platform_properties.bti_supported = true;
+  EXPECT_TRUE(elf_reader.note_gnu_property()->IsBTICompatible()) << "Binary is not BTI-compatible";
+
+  g_platform_properties.bti_supported = bti_supported_orig;
+#else
+  GTEST_SKIP() << "BTI is not supported on this architecture.";
+#endif
+}
diff --git a/linker/linker_phdr.cpp b/linker/linker_phdr.cpp
index 5967e2d..048593b 100644
--- a/linker/linker_phdr.cpp
+++ b/linker/linker_phdr.cpp
@@ -31,6 +31,7 @@
 #include <errno.h>
 #include <string.h>
 #include <sys/mman.h>
+#include <sys/param.h>
 #include <sys/prctl.h>
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -45,12 +46,16 @@
 #include "linker_soinfo.h"
 #include "linker_utils.h"
 
+#include "private/CFIShadow.h"  // For kLibraryAlignment
 #include "private/bionic_asm_note.h"
-#include "private/CFIShadow.h" // For kLibraryAlignment
+#include "private/bionic_inline_raise.h"
 #include "private/elf_note.h"
 
 #include <android-base/file.h>
+#include <android-base/parsebool.h>
 #include <android-base/properties.h>
+#include <android-base/stringprintf.h>
+#include <android/set_abort_message.h>
 
 static int GetTargetElfMachine() {
 #if defined(__arm__)
@@ -182,13 +187,22 @@
     did_read_ = true;
   }
 
-  if (kPageSize == 16*1024 && min_align_ == 4096) {
-    // This prop needs to be read on 16KiB devices for each ELF where min_palign is 4KiB.
-    // It cannot be cached since the developer may toggle app compat on/off.
-    // This check will be removed once app compat is made the default on 16KiB devices.
+  if (kPageSize == 16 * 1024 && min_align_ < kPageSize) {
+    // This prop needs to be read on 16KiB devices for each ELF where min_align_ is less than
+    // 16KiB. It cannot be cached since the developer may toggle app compat on/off. This check will
+    // be removed once app compat is made the default on 16KiB devices.
+    auto compat_prop_val =
+        ::android::base::GetProperty("bionic.linker.16kb.app_compat.enabled", "false");
+
+    using ::android::base::ParseBool;
+    using ::android::base::ParseBoolResult;
+
     should_use_16kib_app_compat_ =
-        ::android::base::GetBoolProperty("bionic.linker.16kb.app_compat.enabled", false) ||
-        get_16kb_appcompat_mode();
+        ParseBool(compat_prop_val) == ParseBoolResult::kTrue || get_16kb_appcompat_mode();
+
+    if (compat_prop_val == "fatal") {
+      dlopen_16kib_err_is_fatal_ = true;
+    }
   }
 
   return did_read_;
@@ -552,7 +566,7 @@
     // or a positive, integral power of two.
     // The kernel ignores loadable segments with other values,
     // so we just warn rather than reject them.
-    if ((phdr->p_align & (phdr->p_align - 1)) != 0) {
+    if (!powerof2(phdr->p_align)) {
       DL_WARN("\"%s\" has invalid p_align %zx in phdr %zu", name_.c_str(),
                      static_cast<size_t>(phdr->p_align), i);
       continue;
@@ -565,6 +579,8 @@
     }
   }
 
+  if (kPageSize == 16 * 1024) FixMinAlignFor16KiB();
+
   return true;
 }
 
@@ -583,13 +599,13 @@
     return mmap_ptr;
   }
 
+#if defined(__LP64__)
   // Minimum alignment of shared library gap. For efficiency, this should match the second level
   // page size of the platform.
-#if defined(__LP64__)
   constexpr size_t kGapAlignment = 2 * 1024 * 1024;
-#endif
   // Maximum gap size, in the units of kGapAlignment.
   constexpr size_t kMaxGapUnits = 32;
+#endif
   // Allocate enough space so that the end of the desired region aligned up is still inside the
   // mapping.
   size_t mmap_size = __builtin_align_up(size, mapping_align) + mapping_align - page_size();
@@ -599,9 +615,9 @@
     return nullptr;
   }
   size_t gap_size = 0;
+#if defined(__LP64__)
   size_t first_byte = reinterpret_cast<size_t>(__builtin_align_up(mmap_ptr, mapping_align));
   size_t last_byte = reinterpret_cast<size_t>(__builtin_align_down(mmap_ptr + mmap_size, mapping_align) - 1);
-#if defined(__LP64__)
   if (first_byte / kGapAlignment != last_byte / kGapAlignment) {
     // This library crosses a 2MB boundary and will fragment a new huge page.
     // Lets take advantage of that and insert a random number of inaccessible huge pages before that
@@ -979,15 +995,21 @@
   // Apps may rely on undefined behavior here on 4 KB systems,
   // which is the norm before this change is introduced
   if (kPageSize >= 16384 && min_align_ < kPageSize && !should_use_16kib_app_compat_) {
-    DL_ERR_AND_LOG("\"%s\" program alignment (%zu) cannot be smaller than system page size (%zu)",
-                   name_.c_str(), min_align_, kPageSize);
+    std::string err_msg = android::base::StringPrintf(
+        "\"%s\" program alignment (%zu) cannot be smaller than system page size (%zu)",
+        name_.c_str(), min_align_, kPageSize);
+
+    DL_ERR_AND_LOG("%s", err_msg.c_str());
+
+    if (dlopen_16kib_err_is_fatal_) {
+      android_set_abort_message(err_msg.c_str());
+      inline_raise(SIGABRT);
+    }
+
     return false;
   }
 
-  if (!Setup16KiBAppCompat()) {
-    DL_ERR("\"%s\" failed to setup 16KiB App Compat", name_.c_str());
-    return false;
-  }
+  if (!Setup16KiBAppCompat()) return false;
 
   for (size_t i = 0; i < phdr_num_; ++i) {
     const ElfW(Phdr)* phdr = &phdr_table_[i];
@@ -1069,7 +1091,7 @@
  */
 static int _phdr_table_set_load_prot(const ElfW(Phdr)* phdr_table, size_t phdr_count,
                                      ElfW(Addr) load_bias, int extra_prot_flags,
-                                     bool should_pad_segments, bool should_use_16kib_app_compat) {
+                                     bool should_pad_segments) {
   for (size_t i = 0; i < phdr_count; ++i) {
     const ElfW(Phdr)* phdr = &phdr_table[i];
 
@@ -1080,7 +1102,7 @@
     ElfW(Addr) p_memsz = phdr->p_memsz;
     ElfW(Addr) p_filesz = phdr->p_filesz;
     _extend_load_segment_vma(phdr_table, phdr_count, i, &p_memsz, &p_filesz, should_pad_segments,
-                             should_use_16kib_app_compat);
+                             /*should_use_16kib_app_compat=*/false);
 
     ElfW(Addr) seg_page_start = page_start(phdr->p_vaddr + load_bias);
     ElfW(Addr) seg_page_end = page_end(phdr->p_vaddr + p_memsz + load_bias);
@@ -1128,14 +1150,18 @@
                                 ElfW(Addr) load_bias, bool should_pad_segments,
                                 bool should_use_16kib_app_compat,
                                 const GnuPropertySection* prop __unused) {
+  // Segment permissions are handled separately in 16KiB compatibility mode.
+  if (should_use_16kib_app_compat) {
+    return 0;
+  }
+
   int prot = 0;
 #if defined(__aarch64__)
   if ((prop != nullptr) && prop->IsBTICompatible()) {
     prot |= PROT_BTI;
   }
 #endif
-  return _phdr_table_set_load_prot(phdr_table, phdr_count, load_bias, prot, should_pad_segments,
-                                   should_use_16kib_app_compat);
+  return _phdr_table_set_load_prot(phdr_table, phdr_count, load_bias, prot, should_pad_segments);
 }
 
 static bool segment_needs_memtag_globals_remapping(const ElfW(Phdr) * phdr) {
@@ -1225,31 +1251,13 @@
     // VMA_ANON_NAME to be copied into the kernel), we can get rid of the storage here.
     // For now, that is not the case:
     // https://source.android.com/docs/core/architecture/kernel/android-common#compatibility-matrix
-    constexpr int kVmaNameLimit = 80;
     std::string& vma_name = vma_names->emplace_back(kVmaNameLimit, '\0');
-    int full_vma_length =
-        async_safe_format_buffer(vma_name.data(), kVmaNameLimit, "mt:%s+%" PRIxPTR, soname,
-                                 page_start(phdr->p_vaddr)) +
-        /* include the null terminator */ 1;
-    // There's an upper limit of 80 characters, including the null terminator, in the anonymous VMA
-    // name. If we run over that limit, we end up truncating the segment offset and parts of the
-    // DSO's name, starting on the right hand side of the basename. Because the basename is the most
-    // important thing, chop off the soname from the left hand side first.
-    //
-    // Example (with '#' as the null terminator):
-    //   - "mt:/data/nativetest64/bionic-unit-tests/bionic-loader-test-libs/libdlext_test.so+e000#"
-    //     is a `full_vma_length` == 86.
-    //
-    // We need to left-truncate (86 - 80) 6 characters from the soname, plus the
-    // `vma_truncation_prefix`, so 9 characters total.
-    if (full_vma_length > kVmaNameLimit) {
-      const char vma_truncation_prefix[] = "...";
-      int soname_truncated_bytes =
-          full_vma_length - kVmaNameLimit + sizeof(vma_truncation_prefix) - 1;
-      async_safe_format_buffer(vma_name.data(), kVmaNameLimit, "mt:%s%s+%" PRIxPTR,
-                               vma_truncation_prefix, soname + soname_truncated_bytes,
-                               page_start(phdr->p_vaddr));
-    }
+    // 18 characters are enough for the '+' prefix, 16 hex digits, and the null terminator.
+    char suffix_buffer[18] = {};
+    async_safe_format_buffer(suffix_buffer, sizeof(suffix_buffer), "+%" PRIxPTR,
+                             page_start(phdr->p_vaddr));
+    format_left_truncated_vma_anon_name(vma_name.data(), vma_name.size(), "mt:", soname,
+                                        suffix_buffer);
     if (prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, reinterpret_cast<void*>(seg_page_start),
               seg_page_aligned_size, vma_name.data()) != 0) {
       DL_WARN("Failed to rename memtag global segment: %m");
@@ -1257,6 +1265,31 @@
   }
 }
 
+/* There's an upper limit of 80 characters, including the null terminator, on the anonymous VMA
+ * name. This limit is easily exceeded when setting the mapping's name to a path. To stay within the
+ * character limit, we must truncate the name to fit into 80 bytes. Since the most important part of
+ * a path is the basename, we start truncating from the left side.
+ *
+ * Example (with prefix = "mt:", suffix = "+e000", and '#' as the null terminator):
+ *   - "mt:/data/nativetest64/bionic-unit-tests/bionic-loader-test-libs/libdlext_test.so+e000#"
+ * This mapping name would have a length of 86, so we left-truncate (86 - 80 + 3) 9 characters from
+ * the path in order to add "..." to the front and fit into the 80 character limit:
+ *   - "mt:...ivetest64/bionic-unit-tests/bionic-loader-test-libs/libdlext_test.so+e000#"
+ */
+void format_left_truncated_vma_anon_name(char* buffer, size_t buffer_size, const char* prefix,
+                                         const char* name, const char* suffix) {
+  size_t full_vma_name_length =
+      async_safe_format_buffer(buffer, buffer_size, "%s%s%s", prefix, name, suffix) +
+      /* null terminator */ 1;
+  if (full_vma_name_length > buffer_size) {
+    const char* truncation_prefix = "...";
+    size_t truncation_prefix_length = strlen(truncation_prefix);
+    size_t truncated_bytes = full_vma_name_length - buffer_size + truncation_prefix_length;
+    async_safe_format_buffer(buffer, buffer_size, "%s%s%s%s", prefix, truncation_prefix,
+                             name + truncated_bytes, suffix);
+  }
+}
+
 /* Change the protection of all loaded segments in memory to writable.
  * This is useful before performing relocations. Once completed, you
  * will have to call phdr_table_protect_segments to restore the original
@@ -1278,15 +1311,21 @@
 int phdr_table_unprotect_segments(const ElfW(Phdr)* phdr_table, size_t phdr_count,
                                   ElfW(Addr) load_bias, bool should_pad_segments,
                                   bool should_use_16kib_app_compat) {
+  // Segment permissions are handled separately in 16KiB compatibility mode. Also in this case
+  // binaries are mapped entirely RW until relro protection is applied, so they don't need to be
+  // unprotected before performing dynamic relocations.
+  if (should_use_16kib_app_compat) {
+    return 0;
+  }
+
   return _phdr_table_set_load_prot(phdr_table, phdr_count, load_bias, PROT_WRITE,
-                                   should_pad_segments, should_use_16kib_app_compat);
+                                   should_pad_segments);
 }
 
 static inline void _extend_gnu_relro_prot_end(const ElfW(Phdr)* relro_phdr,
                                               const ElfW(Phdr)* phdr_table, size_t phdr_count,
                                               ElfW(Addr) load_bias, ElfW(Addr)* seg_page_end,
-                                              bool should_pad_segments,
-                                              bool should_use_16kib_app_compat) {
+                                              bool should_pad_segments) {
   // Find the index and phdr of the LOAD containing the GNU_RELRO segment
   for (size_t index = 0; index < phdr_count; ++index) {
     const ElfW(Phdr)* phdr = &phdr_table[index];
@@ -1334,7 +1373,7 @@
       // mprotect will only RO protect a part of the extended RW LOAD segment, which
       // will leave an extra split RW VMA (the gap).
       _extend_load_segment_vma(phdr_table, phdr_count, index, &p_memsz, &p_filesz,
-                               should_pad_segments, should_use_16kib_app_compat);
+                               should_pad_segments, /*should_use_16kib_app_compat=*/false);
 
       *seg_page_end = page_end(phdr->p_vaddr + p_memsz + load_bias);
       return;
@@ -1347,8 +1386,7 @@
  */
 static int _phdr_table_set_gnu_relro_prot(const ElfW(Phdr)* phdr_table, size_t phdr_count,
                                           ElfW(Addr) load_bias, int prot_flags,
-                                          bool should_pad_segments,
-                                          bool should_use_16kib_app_compat) {
+                                          bool should_pad_segments) {
   const ElfW(Phdr)* phdr = phdr_table;
   const ElfW(Phdr)* phdr_limit = phdr + phdr_count;
 
@@ -1376,7 +1414,7 @@
     ElfW(Addr) seg_page_start = page_start(phdr->p_vaddr) + load_bias;
     ElfW(Addr) seg_page_end = page_end(phdr->p_vaddr + phdr->p_memsz) + load_bias;
     _extend_gnu_relro_prot_end(phdr, phdr_table, phdr_count, load_bias, &seg_page_end,
-                               should_pad_segments, should_use_16kib_app_compat);
+                               should_pad_segments);
 
     int ret = mprotect(reinterpret_cast<void*>(seg_page_start),
                        seg_page_end - seg_page_start,
@@ -1407,24 +1445,9 @@
  *   0 on success, -1 on failure (error code in errno).
  */
 int phdr_table_protect_gnu_relro(const ElfW(Phdr)* phdr_table, size_t phdr_count,
-                                 ElfW(Addr) load_bias, bool should_pad_segments,
-                                 bool should_use_16kib_app_compat) {
+                                 ElfW(Addr) load_bias, bool should_pad_segments) {
   return _phdr_table_set_gnu_relro_prot(phdr_table, phdr_count, load_bias, PROT_READ,
-                                        should_pad_segments, should_use_16kib_app_compat);
-}
-
-/*
- * Apply RX protection to the compat relro region of the ELF being loaded in
- * 16KiB compat mode.
- *
- * Input:
- *   start  -> start address of the compat relro region.
- *   size   -> size of the compat relro region in bytes.
- * Return:
- *   0 on success, -1 on failure (error code in errno).
- */
-int phdr_table_protect_gnu_relro_16kib_compat(ElfW(Addr) start, ElfW(Addr) size) {
-  return mprotect(reinterpret_cast<void*>(start), size, PROT_READ | PROT_EXEC);
+                                        should_pad_segments);
 }
 
 /* Serialize the GNU relro segments to the given file descriptor. This can be
@@ -1686,7 +1709,7 @@
 // It is not considered an error if such section is missing.
 bool ElfReader::FindGnuPropertySection() {
 #if defined(__aarch64__)
-  note_gnu_property_ = GnuPropertySection(phdr_table_, phdr_num_, load_start(), name_.c_str());
+  note_gnu_property_ = GnuPropertySection(phdr_table_, phdr_num_, load_bias_, name_.c_str());
 #endif
   return true;
 }
diff --git a/linker/linker_phdr.h b/linker/linker_phdr.h
index 3b68528..8da4488 100644
--- a/linker/linker_phdr.h
+++ b/linker/linker_phdr.h
@@ -47,6 +47,7 @@
                                       MAYBE_MAP_FLAG((x), PF_W, PROT_WRITE))
 
 static constexpr size_t kCompatPageSize = 0x1000;
+static constexpr size_t kVmaNameLimit = 80;
 
 class ElfReader {
  public:
@@ -69,8 +70,10 @@
   ElfW(Addr) entry_point() const { return header_.e_entry + load_bias_; }
   bool should_pad_segments() const { return should_pad_segments_; }
   bool should_use_16kib_app_compat() const { return should_use_16kib_app_compat_; }
-  ElfW(Addr) compat_relro_start() const { return compat_relro_start_; }
-  ElfW(Addr) compat_relro_size() const { return compat_relro_size_; }
+  bool should_16kib_app_compat_use_rwx() const { return should_16kib_app_compat_use_rwx_; }
+  ElfW(Addr) compat_code_start() const { return compat_code_start_; }
+  ElfW(Addr) compat_code_size() const { return compat_code_size_; }
+  const GnuPropertySection* note_gnu_property() const { return &note_gnu_property_; }
 
  private:
   [[nodiscard]] bool ReadElfHeader();
@@ -87,8 +90,12 @@
   void DropPaddingPages(const ElfW(Phdr)* phdr, uint64_t seg_file_end);
   [[nodiscard]] bool MapBssSection(const ElfW(Phdr)* phdr, ElfW(Addr) seg_page_end,
                                    ElfW(Addr) seg_file_end);
-  [[nodiscard]] bool IsEligibleFor16KiBAppCompat(ElfW(Addr)* vaddr);
+  [[nodiscard]] bool IsEligibleForRXRWAppCompat(ElfW(Addr)* vaddr);
   [[nodiscard]] bool HasAtMostOneRelroSegment(const ElfW(Phdr)** relro_phdr);
+  void FixMinAlignFor16KiB();
+  void LabelCompatVma();
+  void SetupRXRWAppCompat(ElfW(Addr) rx_rw_boundary);
+  void SetupRWXAppCompat();
   [[nodiscard]] bool Setup16KiBAppCompat();
   [[nodiscard]] bool LoadSegments();
   [[nodiscard]] bool FindPhdr();
@@ -147,9 +154,17 @@
   // Use app compat mode when loading 4KiB max-page-size ELFs on 16KiB page-size devices?
   bool should_use_16kib_app_compat_ = false;
 
-  // RELRO region for 16KiB compat loading
-  ElfW(Addr) compat_relro_start_ = 0;
-  ElfW(Addr) compat_relro_size_ = 0;
+  // Map ELF segments RWX in app compat mode?
+  bool should_16kib_app_compat_use_rwx_ = false;
+
+  // Should fail hard on 16KiB related dlopen() errors?
+  bool dlopen_16kib_err_is_fatal_ = false;
+
+  // Region that needs execute permission for 16KiB compat loading.
+  // RX|RW compat mode: Contains code and GNU RELRO sections.
+  // RWX compat mode: Contains the whole ELF.
+  ElfW(Addr) compat_code_start_ = 0;
+  ElfW(Addr) compat_code_size_ = 0;
 
   // Only used by AArch64 at the moment.
   GnuPropertySection note_gnu_property_ __unused;
@@ -168,10 +183,11 @@
                                   bool should_use_16kib_app_compat);
 
 int phdr_table_protect_gnu_relro(const ElfW(Phdr)* phdr_table, size_t phdr_count,
-                                 ElfW(Addr) load_bias, bool should_pad_segments,
-                                 bool should_use_16kib_app_compat);
+                                 ElfW(Addr) load_bias, bool should_pad_segments);
 
-int phdr_table_protect_gnu_relro_16kib_compat(ElfW(Addr) start, ElfW(Addr) size);
+int phdr_table_protect_16kib_app_compat_code(ElfW(Addr) start, ElfW(Addr) size,
+                                             bool should_16kib_app_compat_use_rwx,
+                                             const GnuPropertySection* note_gnu_property = nullptr);
 
 int phdr_table_serialize_gnu_relro(const ElfW(Phdr)* phdr_table, size_t phdr_count,
                                    ElfW(Addr) load_bias, int fd, size_t* file_offset);
@@ -202,3 +218,6 @@
 void name_memtag_globals_segments(const ElfW(Phdr) * phdr_table, size_t phdr_count,
                                   ElfW(Addr) load_bias, const char* soname,
                                   std::list<std::string>* vma_names);
+
+void format_left_truncated_vma_anon_name(char* buffer, size_t buffer_size, const char* prefix,
+                                         const char* name, const char* suffix);
diff --git a/linker/linker_phdr_16kib_compat.cpp b/linker/linker_phdr_16kib_compat.cpp
index d3783cf..23346b7 100644
--- a/linker/linker_phdr_16kib_compat.cpp
+++ b/linker/linker_phdr_16kib_compat.cpp
@@ -28,7 +28,7 @@
 
 #include "linker_phdr.h"
 
-#include <linux/prctl.h>
+#include <stdlib.h>
 #include <sys/mman.h>
 #include <sys/prctl.h>
 #include <unistd.h>
@@ -40,7 +40,13 @@
 #include "platform/bionic/macros.h"
 #include "platform/bionic/page.h"
 
+#include <android-base/stringprintf.h>
+
+#include <algorithm>
+#include <iterator>
+#include <numeric>
 #include <string>
+#include <vector>
 
 static bool g_enable_16kb_app_compat;
 
@@ -117,18 +123,19 @@
  * a 16KiB page boundary; since a single page cannot share multiple
  * permissions.
  *
- * IsEligibleFor16KiBAppCompat() identifies compatible ELFs and populates @vaddr
+ * IsEligibleForRXRWAppCompat() identifies compatible ELFs and populates @vaddr
  * with the boundary between RX|RW portions.
  *
  * Returns true if the ELF can be loaded in compat mode, else false.
  */
-bool ElfReader::IsEligibleFor16KiBAppCompat(ElfW(Addr)* vaddr) {
+bool ElfReader::IsEligibleForRXRWAppCompat(ElfW(Addr)* vaddr) {
   const ElfW(Phdr)* relro_phdr = nullptr;
   if (!HasAtMostOneRelroSegment(&relro_phdr)) {
-    DL_WARN("\"%s\": Compat loading failed: Multiple RELRO segments found", name_.c_str());
+    DL_WARN("\"%s\": RX|RW compat loading failed: Multiple RELRO segments found", name_.c_str());
     return false;
   }
 
+  const ElfW(Phdr)* last_rx = nullptr;
   const ElfW(Phdr)* last_rw = nullptr;
   const ElfW(Phdr)* first_rw = nullptr;
 
@@ -148,12 +155,22 @@
       }
 
       if (last_rw && last_rw != prev) {
-        DL_WARN("\"%s\": Compat loading failed: ELF contains multiple non-adjacent RW segments",
+        DL_WARN("\"%s\": RX|RW compat loading failed: ELF contains non-adjacent RW segments",
                 name_.c_str());
         return false;
       }
 
       last_rw = curr;
+    } else if ((prot & PROT_EXEC) && (prot & PROT_READ)) {
+      if (!last_rx || last_rx > last_rw) {
+        last_rx = curr;
+      } else  {
+        DL_WARN(
+            "\"%s\": RX|RW compat loading failed: ELF contains RX segments "
+            "separated by RW segments",
+            name_.c_str());
+        return false;
+      }
     }
   }
 
@@ -164,14 +181,14 @@
 
   // The RELRO segment is present, it must be the prefix of the first RW segment.
   if (!segment_contains_prefix(first_rw, relro_phdr)) {
-    DL_WARN("\"%s\": Compat loading failed: RELRO is not in the first RW segment",
+    DL_WARN("\"%s\": RX|RW compat loading failed: RELRO is not in the first RW segment",
             name_.c_str());
     return false;
   }
 
   uint64_t end;
   if (__builtin_add_overflow(relro_phdr->p_vaddr, relro_phdr->p_memsz, &end)) {
-    DL_WARN("\"%s\": Compat loading failed: relro vaddr + memsz overflowed", name_.c_str());
+    DL_WARN("\"%s\": RX|RW compat loading failed: relro vaddr + memsz overflowed", name_.c_str());
     return false;
   }
 
@@ -180,7 +197,8 @@
 }
 
 /*
- * Returns the offset/shift needed to align @vaddr to a page boundary.
+ * Returns the offset/shift needed to align @vaddr to a page boundary
+ * for RX|RW compat loading.
  */
 static inline ElfW(Addr) perm_boundary_offset(const ElfW(Addr) addr) {
   ElfW(Addr) offset = page_offset(addr);
@@ -188,34 +206,190 @@
   return offset ? page_size() - offset : 0;
 }
 
-bool ElfReader::Setup16KiBAppCompat() {
-  if (!should_use_16kib_app_compat_) {
-    return true;
+enum relro_pos_t {
+  NONE,    // No RELRO in the LOAD segment
+  PREFIX,  // RELRO is a prefix of the LOAD segment
+  MIDDLE,  // RELRO is contained in the middle of the LOAD segment
+  SUFFIX,  // RELRO is a suffix of the LOAD segment
+  ENTIRE,  // RELRO is the entire LOAD segment
+  ERROR,   // The relro size invalid (spans multiple segments?)
+};
+
+struct segment {
+  const ElfW(Phdr)* phdr;
+  relro_pos_t relro_pos;
+};
+
+static inline relro_pos_t relro_pos(const ElfW(Phdr)* phdr, const ElfW(Phdr)* relro) {
+  // For checking the relro boundaries we use instead the LOAD segment's p_align
+  // instead of the system or compat page size.
+  uint64_t align = phdr->p_align;
+  uint64_t seg_start = __builtin_align_down(phdr->p_vaddr, align);
+  uint64_t seg_end = __builtin_align_up(phdr->p_vaddr + phdr->p_memsz, align);
+  uint64_t relro_start = __builtin_align_down(relro->p_vaddr, align);
+  uint64_t relro_end = __builtin_align_up(relro->p_vaddr + relro->p_memsz, align);
+
+  if (relro_end <= seg_start || relro_start >= seg_end) return NONE;
+
+  // Spans multiple LOAD segments?
+  if (relro_start < seg_start || relro_end > seg_end) return ERROR;
+
+  // Prefix or entire?
+  if (relro_start == seg_start) return (relro_end < seg_end) ? PREFIX : ENTIRE;
+
+  // Must be suffix or middle
+  return (relro_end == seg_end) ? SUFFIX : MIDDLE;
+}
+
+static std::vector<struct segment> elf_segments(const ElfW(Phdr)* phdr_table, size_t phdr_count) {
+  std::vector<struct segment> segments;
+
+  for (size_t index = 0; index < phdr_count; ++index) {
+    const ElfW(Phdr)* phdr = &phdr_table[index];
+
+    if (phdr->p_type != PT_LOAD) continue;
+
+    struct segment segment = {
+        .phdr = phdr,
+        .relro_pos = NONE,
+    };
+
+    segments.emplace_back(segment);
   }
 
-  ElfW(Addr) rx_rw_boundary;  // Permission bounadry for compat mode
-  if (!IsEligibleFor16KiBAppCompat(&rx_rw_boundary)) {
-    return false;
+  for (size_t index = 0; index < phdr_count; ++index) {
+    const ElfW(Phdr)* relro = &phdr_table[index];
+
+    if (relro->p_type != PT_GNU_RELRO) continue;
+
+    for (struct segment& segment : segments) {
+      if (segment.relro_pos != NONE) continue;
+
+      segment.relro_pos = relro_pos(segment.phdr, relro);
+    }
   }
 
+  // Sort by vaddr
+  std::sort(segments.begin(), segments.end(), [](const struct segment& a, const struct segment& b) {
+    return a.phdr->p_vaddr < b.phdr->p_vaddr;
+  });
+
+  return segments;
+}
+
+static inline std::string prot_str(const struct segment& segment) {
+  int prot = PFLAGS_TO_PROT(segment.phdr->p_flags);
+  std::string str;
+
+  if (prot & PROT_READ) str += "R";
+  if (prot & PROT_WRITE) str += "W";
+  if (prot & PROT_EXEC) str += "X";
+
+  return str;
+}
+
+static inline std::string relro_pos_str(const struct segment& segment) {
+  relro_pos_t relro_pos = segment.relro_pos;
+
+  switch (relro_pos) {
+    case NONE:
+      return "";
+    case PREFIX:
+      return "(PREFIX)";
+    case MIDDLE:
+      return "(MIDDLE)";
+    case SUFFIX:
+      return "(SUFFIX)";
+    case ENTIRE:
+      return "(ENTIRE)";
+    case ERROR:
+      return "(ERROR)";
+  }
+
+  // Unreachable
+  abort();
+}
+
+static inline std::string segment_format(const struct segment& segment) {
+  uint64_t align_kbytes = segment.phdr->p_align / 1024;
+  std::string format = prot_str(segment);
+
+  if (segment.relro_pos != NONE) format += " " + relro_pos_str(segment);
+
+  return format + " " + std::to_string(align_kbytes) + "K";
+}
+
+/*
+ * Returns a string representing the ELF's load segment layout.
+ *
+ * Each segment has the format: <permissions> [(<relro position>)] <p_align>
+ *
+ *   e.g. "RX 4K|RW (ENTIRE) 4K|RW 4K|RW 16K|RX 16K|R 16K|RW 16K"
+ */
+static inline std::string elf_layout(const ElfW(Phdr)* phdr_table, size_t phdr_count) {
+  std::vector<struct segment> segments = elf_segments(phdr_table, phdr_count);
+  std::vector<std::string> layout;
+
+  for (struct segment& segment : segments) {
+    layout.emplace_back(segment_format(segment));
+  }
+
+  if (layout.empty()) return "";
+
+  return std::accumulate(std::next(layout.begin()), layout.end(), layout[0],
+                         [](std::string a, std::string b) { return std::move(a) + "," + b; });
+}
+
+void ElfReader::LabelCompatVma() {
+  // Label the ELF VMA, since compat mode uses anonymous mappings, and some applications may rely on
+  // them having their name set to the ELF's path.
+  // Since kernel 5.10 it is safe to use non-global storage for the VMA name because it will be
+  // copied into the kernel. 16KiB pages require a minimum kernel version of 6.1 so we can safely
+  // use a stack-allocated buffer here.
+  char vma_name_buffer[kVmaNameLimit] = {};
+  format_left_truncated_vma_anon_name(vma_name_buffer, sizeof(vma_name_buffer),
+                                      "16k:", name_.c_str(), "");
+  if (prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, load_start_, load_size_, vma_name_buffer) != 0) {
+    DL_WARN("\"%s\": Failed to rename 16KiB compat segment: %m", name_.c_str());
+  }
+}
+
+void ElfReader::SetupRXRWAppCompat(ElfW(Addr) rx_rw_boundary) {
   // Adjust the load_bias to position the RX|RW boundary on a page boundary
   load_bias_ += perm_boundary_offset(rx_rw_boundary);
 
   // RW region (.data, .bss ...)
   ElfW(Addr) rw_start = load_bias_ + rx_rw_boundary;
-  ElfW(Addr) rw_size = load_size_ - (rw_start - reinterpret_cast<ElfW(Addr)>(load_start_));
+  CHECK(rw_start % page_size() == 0);
 
-  CHECK(rw_start % getpagesize() == 0);
-  CHECK(rw_size % getpagesize() == 0);
+  // Compat code and RELRO (RX) region (.text, .data.relro, ...)
+  compat_code_start_ = load_start();
+  compat_code_size_ = rw_start - load_start();
+}
 
-  // Compat RELRO (RX) region (.text, .data.relro, ...)
-  compat_relro_start_ = reinterpret_cast<ElfW(Addr)>(load_start_);
-  compat_relro_size_ = load_size_ - rw_size;
+void ElfReader::SetupRWXAppCompat() {
+  // Warn and fallback to RWX mapping
+  const std::string layout = elf_layout(phdr_table_, phdr_num_);
+  DL_WARN("\"%s\": RX|RW compat loading failed, falling back to RWX compat: load segments [%s]",
+          name_.c_str(), layout.c_str());
+  compat_code_start_ = load_start();
+  compat_code_size_ = load_size();
+}
 
-  // Label the ELF VMA, since compat mode uses anonymous mappings.
-  std::string compat_name = name_ + " (compat loaded)";
-  prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, load_start_, load_size_, compat_name.c_str());
+bool ElfReader::Setup16KiBAppCompat() {
+  if (!should_use_16kib_app_compat_) {
+    return true;
+  }
 
+  ElfW(Addr) rx_rw_boundary;  // Permission boundary for RX|RW compat mode
+  if (IsEligibleForRXRWAppCompat(&rx_rw_boundary)) {
+    SetupRXRWAppCompat(rx_rw_boundary);
+  } else {
+    should_16kib_app_compat_use_rwx_ = true;
+    SetupRWXAppCompat();
+  }
+
+  LabelCompatVma();
   return true;
 }
 
@@ -245,3 +419,81 @@
 
   return true;
 }
+
+static size_t phdr_table_get_relro_min_align(const ElfW(Phdr)* relro_phdr,
+                                             const ElfW(Phdr)* phdr_table, size_t phdr_count) {
+  for (size_t index = 0; index < phdr_count; ++index) {
+    const ElfW(Phdr)* phdr = &phdr_table[index];
+
+    if (phdr->p_type != PT_LOAD) {
+      continue;
+    }
+
+    // Only check for the case, where the relro segment is a prefix of a load segment. Conventional
+    // linkers will only generate binaries where the relro segment is either the prefix of the first
+    // RW load segment, or is entirely contained in the first RW segment.
+    if (phdr->p_vaddr == relro_phdr->p_vaddr) {
+      // No extra alignment checks needed if the whole load segment is relro.
+      if (phdr->p_memsz <= relro_phdr->p_memsz) {
+        return 0;
+      }
+
+      ElfW(Addr) relro_end = relro_phdr->p_vaddr + relro_phdr->p_memsz;
+      // Alignments must be powers of two, so the RELRO segment's alignment can be determined by
+      // calculating its lowest set bit with (n & -n).
+      size_t relro_align = static_cast<size_t>(relro_end & -relro_end);
+      // We only care about relro segments that are aligned to at least 4KiB. This is always
+      // expected for outputs of a conventional linker.
+      return relro_align >= kCompatPageSize ? relro_align : 0;
+    }
+  }
+  return 0;
+}
+
+/*
+ * In the base page size is 16KiB and the RELRO's end alignment is less than min_align_;
+ *  override min_align_ with the relro's end alignment. This ensures that the ELF is
+ * loaded in compat mode even if the LOAD segments are 16KB aligned.
+ * Linker bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28824
+ */
+void ElfReader::FixMinAlignFor16KiB() {
+  // A binary with LOAD segment alignments of at least 16KiB can still be incompatible with 16KiB
+  // page sizes if the first RW segment has a RELRO prefix ending at a non-16KiB-aligned address. We
+  // need to check for this possibility here and adjust min_align_ accordingly.
+  // We only check if the ELF file contains a single RELRO segment, because that's what the 16KiB
+  // compatibility loader can handle.
+  const ElfW(Phdr)* relro_phdr = nullptr;
+  if (HasAtMostOneRelroSegment(&relro_phdr) && relro_phdr != nullptr) {
+    size_t relro_min_align = phdr_table_get_relro_min_align(relro_phdr, phdr_table_, phdr_num_);
+    if (relro_min_align) {
+      min_align_ = std::min(min_align_, relro_min_align);
+    }
+  }
+}
+
+/*
+ * Apply RX or RWX protection to the code region of the ELF being loaded in
+ * 16KiB compat mode.
+ *
+ * Input:
+ *   start                            -> start address of the compat code region.
+ *   size                             -> size of the compat code region in bytes.
+ *   should_16kib_app_compat_use_rwx  -> use RWX or RX permission.
+ *   note_gnu_property                -> AArch64-only: use PROT_BTI if the ELF is BTI-compatible.
+ * Return:
+ *   0 on success, -1 on failure (error code in errno).
+ */
+int phdr_table_protect_16kib_app_compat_code(ElfW(Addr) start, ElfW(Addr) size,
+                                             bool should_16kib_app_compat_use_rwx,
+                                             const GnuPropertySection* note_gnu_property __unused) {
+  int prot = PROT_READ | PROT_EXEC;
+  if (should_16kib_app_compat_use_rwx) {
+    prot |= PROT_WRITE;
+  }
+#ifdef __aarch64__
+  if (note_gnu_property != nullptr && note_gnu_property->IsBTICompatible()) {
+    prot |= PROT_BTI;
+  }
+#endif
+  return mprotect(reinterpret_cast<void*>(start), size, prot);
+}
diff --git a/linker/linker_soinfo.h b/linker/linker_soinfo.h
index 8f56c9f..d107c73 100644
--- a/linker/linker_soinfo.h
+++ b/linker/linker_soinfo.h
@@ -254,6 +254,7 @@
   bool link_image(const SymbolLookupList& lookup_list, soinfo* local_group_root,
                   const android_dlextinfo* extinfo, size_t* relro_fd_offset);
   bool protect_relro();
+  bool protect_16kib_app_compat_code();
 
   void tag_globals(bool deterministic_memtag_globals);
   ElfW(Addr) apply_memtag_if_mte_globals(ElfW(Addr) sym_addr) const;
@@ -406,11 +407,16 @@
   }
   bool should_use_16kib_app_compat() const { return should_use_16kib_app_compat_; }
 
-  void set_compat_relro_start(ElfW(Addr) start) { compat_relro_start_ = start; }
-  ElfW(Addr) compat_relro_start() const { return compat_relro_start_; }
+  void set_should_16kib_app_compat_use_rwx(bool should_16kib_app_compat_use_rwx) {
+    should_16kib_app_compat_use_rwx_ = should_16kib_app_compat_use_rwx;
+  }
+  bool should_16kib_app_compat_use_rwx() const { return should_16kib_app_compat_use_rwx_; }
 
-  void set_compat_relro_size(ElfW(Addr) size) { compat_relro_size_ = size; }
-  ElfW(Addr) compat_relro_size() const { return compat_relro_start_; }
+  void set_compat_code_start(ElfW(Addr) start) { compat_code_start_ = start; }
+  ElfW(Addr) compat_code_start() const { return compat_code_start_; }
+
+  void set_compat_code_size(ElfW(Addr) size) { compat_code_size_ = size; }
+  ElfW(Addr) compat_code_size() const { return compat_code_size_; }
 
  private:
   bool is_image_linked() const;
@@ -503,9 +509,14 @@
   // Use app compat mode when loading 4KiB max-page-size ELFs on 16KiB page-size devices?
   bool should_use_16kib_app_compat_ = false;
 
-  // RELRO region for 16KiB compat loading
-  ElfW(Addr) compat_relro_start_ = 0;
-  ElfW(Addr) compat_relro_size_ = 0;
+  // Map ELF segments RWX in app compat mode?
+  bool should_16kib_app_compat_use_rwx_ = false;
+
+  // Region that needs execute permission for 16KiB compat loading.
+  // RX|RW compat mode: Contains code and GNU RELRO sections.
+  // RWX compat mode: Contains the whole ELF.
+  ElfW(Addr) compat_code_start_ = 0;
+  ElfW(Addr) compat_code_size_ = 0;
 };
 
 // This function is used by dlvsym() to calculate hash of sym_ver
diff --git a/linker/linker_tls.cpp b/linker/linker_tls.cpp
index e90b8cb..d407bc4 100644
--- a/linker/linker_tls.cpp
+++ b/linker/linker_tls.cpp
@@ -108,16 +108,16 @@
 }
 
 void linker_setup_exe_static_tls(const char* progname) {
-  soinfo* somain = solist_get_somain();
+  soinfo* executable = solist_get_executable();
   StaticTlsLayout& layout = __libc_shared_globals()->static_tls_layout;
 
   // For ldd, don't add the executable's TLS segment to the static TLS layout.
   // It is likely to trigger the underaligned TLS segment error on arm32/arm64
   // when the ldd argument is actually a shared object.
-  if (somain->get_tls() == nullptr || g_is_ldd) {
+  if (executable->get_tls() == nullptr || g_is_ldd) {
     layout.reserve_exe_segment_and_tcb(nullptr, progname);
   } else {
-    register_tls_module(somain, layout.reserve_exe_segment_and_tcb(&somain->get_tls()->segment, progname));
+    register_tls_module(executable, layout.reserve_exe_segment_and_tcb(&executable->get_tls()->segment, progname));
   }
 
   // The pthread key data is located at the very front of bionic_tls. As a
diff --git a/linker/linker_tls.h b/linker/linker_tls.h
index 87e1f0d..5a20a64 100644
--- a/linker/linker_tls.h
+++ b/linker/linker_tls.h
@@ -60,6 +60,6 @@
   TlsIndex index;
 };
 
-__LIBC_HIDDEN__ extern "C" size_t tlsdesc_resolver_static(size_t);
-__LIBC_HIDDEN__ extern "C" size_t tlsdesc_resolver_dynamic(size_t);
-__LIBC_HIDDEN__ extern "C" size_t tlsdesc_resolver_unresolved_weak(size_t);
+extern "C" size_t tlsdesc_resolver_static(size_t);
+extern "C" size_t tlsdesc_resolver_dynamic(size_t);
+extern "C" size_t tlsdesc_resolver_unresolved_weak(size_t);
diff --git a/linker/linker_wrapper.cpp b/linker/linker_wrapper.cpp
index 5ee2d3e..a5e741b 100644
--- a/linker/linker_wrapper.cpp
+++ b/linker/linker_wrapper.cpp
@@ -34,7 +34,7 @@
 extern const char __dlwrap_linker_offset;
 
 // The real entry point of the binary to use after linker bootstrapping.
-__LIBC_HIDDEN__ extern "C" void _start();
+extern "C" void _start();
 
 /* 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.
diff --git a/linker/testdata/Android.bp b/linker/testdata/Android.bp
index f998180..211c1d8 100644
--- a/linker/testdata/Android.bp
+++ b/linker/testdata/Android.bp
@@ -14,6 +14,7 @@
 
 package {
     default_applicable_licenses: ["Android-Apache-2.0"],
+    default_team: "trendy_team_native_tools_libraries",
 }
 
 cc_library_shared {
@@ -36,3 +37,21 @@
     srcs: ["hello_world.c"],
     no_crt_pad_segment: true,
 }
+
+cc_library_shared {
+    name: "note_gnu_property",
+    srcs: ["hello_world.c"],
+    enabled: false,
+    arch: {
+        arm64: {
+            enabled: true,
+            cflags: ["-mbranch-protection=bti"],
+            ldflags: [
+                "-Wl,--image-base=0x10000",
+                "-Wl,-zbti-report=error",
+            ],
+        },
+    },
+    nocrt: true,
+    no_crt_pad_segment: true,
+}
diff --git a/tests/Android.bp b/tests/Android.bp
index 4509cc4..97a340e 100644
--- a/tests/Android.bp
+++ b/tests/Android.bp
@@ -40,6 +40,7 @@
         },
         android: {
             header_libs: ["bionic_libc_platform_headers"],
+            shared_libs: ["libdl_android"],
         },
         linux_bionic: {
             header_libs: ["bionic_libc_platform_headers"],
@@ -97,242 +98,171 @@
 filegroup {
     name: "bionic_prebuilt_test_elf_files_arm64",
     srcs: [
-        "prebuilt-elf-files/arm64/*.so",
+        "prebuilt-elf-files/*.so",
+        "prebuilt-elf-files/arm64/libtest_invalid-local-tls.so",
     ],
 }
 
-cc_prebuilt_test_library_shared {
+genrule_defaults {
+    name: "gen_invalid_lib_defaults",
+    tools: ["gen_invalid_elf"],
+    srcs: [":libtest_empty"],
+}
+
+cc_defaults {
+    name: "invalid_lib_defaults",
+    strip: {
+        none: true,
+    },
+    check_elf_files: false,
+    relative_install_path: "bionic-loader-test-libs/prebuilt-elf-files",
+}
+
+cc_genrule {
+    name: "gen_invalid-rwx_load_segment",
+    defaults: ["gen_invalid_lib_defaults"],
+    cmd: "$(location gen_invalid_elf) --ref-elf=$(location :libtest_empty) --output=$(out) --invalid-type=rwx_load_segment",
+    out: ["libtest_invalid-rwx_load_segment.so"],
+}
+
+cc_prebuilt_library_shared {
     name: "libtest_invalid-rw_load_segment",
-    strip: {
-        none: true,
-    },
-    check_elf_files: false,
-    relative_install_path: "bionic-loader-test-libs/prebuilt-elf-files",
-    arch: {
-        arm: {
-            srcs: ["prebuilt-elf-files/arm/libtest_invalid-rw_load_segment.so"],
-        },
-        arm64: {
-            srcs: ["prebuilt-elf-files/arm64/libtest_invalid-rw_load_segment.so"],
-        },
-        riscv64: {
-            srcs: ["prebuilt-elf-files/riscv64/libtest_invalid-rw_load_segment.so"],
-        },
-        x86: {
-            srcs: ["prebuilt-elf-files/x86/libtest_invalid-rw_load_segment.so"],
-        },
-        x86_64: {
-            srcs: ["prebuilt-elf-files/x86_64/libtest_invalid-rw_load_segment.so"],
-        },
-    },
+    defaults: ["invalid_lib_defaults"],
+    srcs: [":gen_invalid-rwx_load_segment"],
 }
 
-cc_prebuilt_test_library_shared {
+cc_genrule {
+    name: "gen_invalid-unaligned_shdr_offset",
+    defaults: ["gen_invalid_lib_defaults"],
+    cmd: "$(location gen_invalid_elf) --ref-elf=$(location :libtest_empty) --output=$(out) --invalid-type=unaligned_shdr_offset",
+    out: ["libtest_invalid-unaligned_shdr_offset.so"],
+}
+
+cc_prebuilt_library_shared {
     name: "libtest_invalid-unaligned_shdr_offset",
-    strip: {
-        none: true,
-    },
-    check_elf_files: false,
-    relative_install_path: "bionic-loader-test-libs/prebuilt-elf-files",
-    arch: {
-        arm: {
-            srcs: ["prebuilt-elf-files/arm/libtest_invalid-unaligned_shdr_offset.so"],
-        },
-        arm64: {
-            srcs: ["prebuilt-elf-files/arm64/libtest_invalid-unaligned_shdr_offset.so"],
-        },
-        riscv64: {
-            srcs: ["prebuilt-elf-files/riscv64/libtest_invalid-unaligned_shdr_offset.so"],
-        },
-        x86: {
-            srcs: ["prebuilt-elf-files/x86/libtest_invalid-unaligned_shdr_offset.so"],
-        },
-        x86_64: {
-            srcs: ["prebuilt-elf-files/x86_64/libtest_invalid-unaligned_shdr_offset.so"],
-        },
-    },
+    defaults: ["invalid_lib_defaults"],
+    srcs: [":gen_invalid-unaligned_shdr_offset"],
 }
 
-cc_prebuilt_test_library_shared {
+cc_genrule {
+    name: "gen_invalid-zero_shentsize",
+    defaults: ["gen_invalid_lib_defaults"],
+    cmd: "$(location gen_invalid_elf) --ref-elf=$(location :libtest_empty) --output=$(out) --invalid-type=zero_shentsize",
+    out: ["libtest_invalid-zero_shentsize.so"],
+}
+
+cc_prebuilt_library_shared {
     name: "libtest_invalid-zero_shentsize",
-    strip: {
-        none: true,
-    },
-    check_elf_files: false,
-    relative_install_path: "bionic-loader-test-libs/prebuilt-elf-files",
-    arch: {
-        arm: {
-            srcs: ["prebuilt-elf-files/arm/libtest_invalid-zero_shentsize.so"],
-        },
-        arm64: {
-            srcs: ["prebuilt-elf-files/arm64/libtest_invalid-zero_shentsize.so"],
-        },
-        riscv64: {
-            srcs: ["prebuilt-elf-files/riscv64/libtest_invalid-zero_shentsize.so"],
-        },
-        x86: {
-            srcs: ["prebuilt-elf-files/x86/libtest_invalid-zero_shentsize.so"],
-        },
-        x86_64: {
-            srcs: ["prebuilt-elf-files/x86_64/libtest_invalid-zero_shentsize.so"],
-        },
-    },
+    defaults: ["invalid_lib_defaults"],
+    srcs: [":gen_invalid-zero_shentsize"],
 }
 
-cc_prebuilt_test_library_shared {
+cc_genrule {
+    name: "gen_invalid-zero_shstrndx",
+    defaults: ["gen_invalid_lib_defaults"],
+    cmd: "$(location gen_invalid_elf) --ref-elf=$(location :libtest_empty) --output=$(out) --invalid-type=zero_shstrndx",
+    out: ["libtest_invalid-zero_shstrndx.so"],
+}
+
+cc_prebuilt_library_shared {
     name: "libtest_invalid-zero_shstrndx",
-    strip: {
-        none: true,
-    },
-    check_elf_files: false,
-    relative_install_path: "bionic-loader-test-libs/prebuilt-elf-files",
-    arch: {
-        arm: {
-            srcs: ["prebuilt-elf-files/arm/libtest_invalid-zero_shstrndx.so"],
-        },
-        arm64: {
-            srcs: ["prebuilt-elf-files/arm64/libtest_invalid-zero_shstrndx.so"],
-        },
-        riscv64: {
-            srcs: ["prebuilt-elf-files/riscv64/libtest_invalid-zero_shstrndx.so"],
-        },
-        x86: {
-            srcs: ["prebuilt-elf-files/x86/libtest_invalid-zero_shstrndx.so"],
-        },
-        x86_64: {
-            srcs: ["prebuilt-elf-files/x86_64/libtest_invalid-zero_shstrndx.so"],
-        },
-    },
+    defaults: ["invalid_lib_defaults"],
+    srcs: [":gen_invalid-zero_shstrndx"],
 }
 
-cc_prebuilt_test_library_shared {
+cc_genrule {
+    name: "gen_invalid-empty_shdr_table",
+    defaults: ["gen_invalid_lib_defaults"],
+    cmd: "$(location gen_invalid_elf) --ref-elf=$(location :libtest_empty) --output=$(out) --invalid-type=empty_shdr_table",
+    out: ["libtest_invalid-empty_shdr_table.so"],
+}
+
+cc_prebuilt_library_shared {
     name: "libtest_invalid-empty_shdr_table",
-    strip: {
-        none: true,
-    },
-    check_elf_files: false,
-    relative_install_path: "bionic-loader-test-libs/prebuilt-elf-files",
-    arch: {
-        arm: {
-            srcs: ["prebuilt-elf-files/arm/libtest_invalid-empty_shdr_table.so"],
-        },
-        arm64: {
-            srcs: ["prebuilt-elf-files/arm64/libtest_invalid-empty_shdr_table.so"],
-        },
-        riscv64: {
-            srcs: ["prebuilt-elf-files/riscv64/libtest_invalid-empty_shdr_table.so"],
-        },
-        x86: {
-            srcs: ["prebuilt-elf-files/x86/libtest_invalid-empty_shdr_table.so"],
-        },
-        x86_64: {
-            srcs: ["prebuilt-elf-files/x86_64/libtest_invalid-empty_shdr_table.so"],
-        },
-    },
+    defaults: ["invalid_lib_defaults"],
+    srcs: [":gen_invalid-empty_shdr_table"],
 }
 
-cc_prebuilt_test_library_shared {
+cc_genrule {
+    name: "gen_invalid-zero_shdr_table_offset",
+    defaults: ["gen_invalid_lib_defaults"],
+    cmd: "$(location gen_invalid_elf) --ref-elf=$(location :libtest_empty) --output=$(out) --invalid-type=zero_shdr_table_offset",
+    out: ["libtest_invalid-zero_shdr_table_offset.so"],
+}
+
+cc_prebuilt_library_shared {
     name: "libtest_invalid-zero_shdr_table_offset",
-    strip: {
-        none: true,
-    },
-    check_elf_files: false,
-    relative_install_path: "bionic-loader-test-libs/prebuilt-elf-files",
-    arch: {
-        arm: {
-            srcs: ["prebuilt-elf-files/arm/libtest_invalid-zero_shdr_table_offset.so"],
-        },
-        arm64: {
-            srcs: ["prebuilt-elf-files/arm64/libtest_invalid-zero_shdr_table_offset.so"],
-        },
-        riscv64: {
-            srcs: ["prebuilt-elf-files/riscv64/libtest_invalid-zero_shdr_table_offset.so"],
-        },
-        x86: {
-            srcs: ["prebuilt-elf-files/x86/libtest_invalid-zero_shdr_table_offset.so"],
-        },
-        x86_64: {
-            srcs: ["prebuilt-elf-files/x86_64/libtest_invalid-zero_shdr_table_offset.so"],
-        },
-    },
+    defaults: ["invalid_lib_defaults"],
+    srcs: [":gen_invalid-zero_shdr_table_offset"],
 }
 
-cc_prebuilt_test_library_shared {
+cc_genrule {
+    name: "gen_invalid-zero_shdr_table_content",
+    defaults: ["gen_invalid_lib_defaults"],
+    cmd: "$(location gen_invalid_elf) --ref-elf=$(location :libtest_empty) --output=$(out) --invalid-type=zero_shdr_table_content",
+    out: ["libtest_invalid-zero_shdr_table_content.so"],
+}
+
+cc_prebuilt_library_shared {
     name: "libtest_invalid-zero_shdr_table_content",
-    strip: {
-        none: true,
-    },
-    check_elf_files: false,
-    relative_install_path: "bionic-loader-test-libs/prebuilt-elf-files",
-    arch: {
-        arm: {
-            srcs: ["prebuilt-elf-files/arm/libtest_invalid-zero_shdr_table_content.so"],
-        },
-        arm64: {
-            srcs: ["prebuilt-elf-files/arm64/libtest_invalid-zero_shdr_table_content.so"],
-        },
-        riscv64: {
-            srcs: ["prebuilt-elf-files/riscv64/libtest_invalid-zero_shdr_table_content.so"],
-        },
-        x86: {
-            srcs: ["prebuilt-elf-files/x86/libtest_invalid-zero_shdr_table_content.so"],
-        },
-        x86_64: {
-            srcs: ["prebuilt-elf-files/x86_64/libtest_invalid-zero_shdr_table_content.so"],
-        },
-    },
+    defaults: ["invalid_lib_defaults"],
+    srcs: [":gen_invalid-zero_shdr_table_content"],
 }
 
-cc_prebuilt_test_library_shared {
+cc_genrule {
+    name: "gen_invalid-textrels",
+    defaults: ["gen_invalid_lib_defaults"],
+    cmd: "$(location gen_invalid_elf) --ref-elf=$(location :libtest_empty) --output=$(out) --invalid-type=textrels",
+    out: ["libtest_invalid-textrels.so"],
+}
+
+cc_prebuilt_library_shared {
     name: "libtest_invalid-textrels",
-    strip: {
-        none: true,
-    },
-    check_elf_files: false,
-    relative_install_path: "bionic-loader-test-libs/prebuilt-elf-files",
-    arch: {
-        arm: {
-            srcs: ["prebuilt-elf-files/arm/libtest_invalid-textrels.so"],
-        },
-        arm64: {
-            srcs: ["prebuilt-elf-files/arm64/libtest_invalid-textrels.so"],
-        },
-        riscv64: {
-            srcs: ["prebuilt-elf-files/riscv64/libtest_invalid-textrels.so"],
-        },
-        x86: {
-            srcs: ["prebuilt-elf-files/x86/libtest_invalid-textrels.so"],
-        },
-        x86_64: {
-            srcs: ["prebuilt-elf-files/x86_64/libtest_invalid-textrels.so"],
-        },
-    },
+    defaults: ["invalid_lib_defaults"],
+    srcs: [":gen_invalid-textrels"],
 }
 
-cc_prebuilt_test_library_shared {
+cc_genrule {
+    name: "gen_invalid-textrels2",
+    defaults: ["gen_invalid_lib_defaults"],
+    cmd: "$(location gen_invalid_elf) --ref-elf=$(location :libtest_empty) --output=$(out) --invalid-type=textrels2",
+    out: ["libtest_invalid-textrels2.so"],
+}
+
+cc_prebuilt_library_shared {
     name: "libtest_invalid-textrels2",
-    strip: {
-        none: true,
-    },
-    check_elf_files: false,
-    relative_install_path: "bionic-loader-test-libs/prebuilt-elf-files",
-    arch: {
-        arm: {
-            srcs: ["prebuilt-elf-files/arm/libtest_invalid-textrels2.so"],
-        },
-        arm64: {
-            srcs: ["prebuilt-elf-files/arm64/libtest_invalid-textrels2.so"],
-        },
-        riscv64: {
-            srcs: ["prebuilt-elf-files/riscv64/libtest_invalid-textrels2.so"],
-        },
-        x86: {
-            srcs: ["prebuilt-elf-files/x86/libtest_invalid-textrels2.so"],
-        },
-        x86_64: {
-            srcs: ["prebuilt-elf-files/x86_64/libtest_invalid-textrels2.so"],
-        },
-    },
+    defaults: ["invalid_lib_defaults"],
+    srcs: [":gen_invalid-textrels2"],
+}
+
+cc_genrule {
+    name: "gen_invalid-rw_rx_rw_load_segments",
+    tools: ["gen_invalid_elf"],
+    // Force the segment alignment to 4KiB
+    srcs: [":libtest_elf_max_page_size_4kib"],
+    out: ["libtest_invalid-load_segments_rw_rx_rw.so"],
+    cmd: "$(location gen_invalid_elf) --ref-elf=$(location :libtest_elf_max_page_size_4kib) --output=$(out) --invalid-type=load_segments_rw_rx_rw",
+}
+
+cc_prebuilt_library_shared {
+    name: "libtest_invalid-rw_rx_rw_load_segments",
+    defaults: ["invalid_lib_defaults"],
+    srcs: [":gen_invalid-rw_rx_rw_load_segments"],
+}
+
+cc_genrule {
+    name: "gen_invalid-rx_rw_rx_load_segments",
+    tools: ["gen_invalid_elf"],
+    // Force the segment alignment to 4KiB
+    srcs: [":libtest_elf_max_page_size_4kib"],
+    out: ["libtest_invalid-load_segments_rx_rw_rx.so"],
+    cmd: "$(location gen_invalid_elf) --ref-elf=$(location :libtest_elf_max_page_size_4kib) --output=$(out) --invalid-type=load_segments_rx_rw_rx",
+}
+
+cc_prebuilt_library_shared {
+    name: "libtest_invalid-rx_rw_rx_load_segments",
+    defaults: ["invalid_lib_defaults"],
+    srcs: [":gen_invalid-rx_rw_rx_load_segments"],
 }
 
 cc_prebuilt_test_library_shared {
@@ -349,6 +279,8 @@
         arm64: {
             srcs: ["prebuilt-elf-files/arm64/libtest_invalid-local-tls.so"],
         },
+        // No riscv64 here because the gold linker never had riscv64 support,
+        // and this is a test for a gold-specific bug.
         x86: {
             srcs: ["prebuilt-elf-files/x86/libtest_invalid-local-tls.so"],
         },
@@ -400,6 +332,7 @@
         "dirent_test.cpp",
         "elf_test.cpp",
         "endian_test.cpp",
+        "err_test.cpp",
         "errno_test.cpp",
         "error_test.cpp",
         "eventfd_test.cpp",
@@ -432,6 +365,7 @@
         "locale_test.cpp",
         "malloc_iterate_test.cpp",
         "malloc_test.cpp",
+        "malloc_test_with_usable_size.cpp",
         "math_test.cpp",
         "membarrier_test.cpp",
         "memtag_globals_test.cpp",
@@ -467,6 +401,7 @@
         "stdalign_test.cpp",
         "stdarg_test.cpp",
         "stdatomic_test.cpp",
+        "stdbit_test.cpp",
         "stdbool_test.c",
         "stdint_test.cpp",
         "stdio_nofortify_test.cpp",
@@ -528,6 +463,7 @@
         "unistd_nofortify_test.cpp",
         "unistd_test.cpp",
         "utils.cpp",
+        "utime_test.cpp",
         "utmp_test.cpp",
         "utmpx_test.cpp",
         "wchar_test.cpp",
@@ -633,6 +569,7 @@
     name: "bionic_clang_fortify_tests_w_flags",
     cflags: [
         "-Wno-builtin-memcpy-chk-size",
+        "-Wno-deprecated-declarations",
         "-Wno-format-security",
         "-Wno-format-zero-length",
         "-Wno-fortify-source",
@@ -647,10 +584,19 @@
 
 cc_defaults {
     name: "bionic_fortify_tests_defaults",
+    defaults: [
+        "bionic_tests_defaults",
+    ],
     cflags: [
         "-U_FORTIFY_SOURCE",
+        // Without this, HWASan will not recognize (i.e. will not detect errors involving)
+        // calls to mem* functions.
+        "-fbuiltin",
     ],
     srcs: ["fortify_test_main.cpp"],
+    shared: {
+        enabled: false,
+    },
     static_libs: [
         "libbase",
     ],
@@ -673,7 +619,8 @@
     ],
     cflags: [
         "-Werror",
-        "-D_FORTIFY_SOURCE=2",
+        "-U_FORTIFY_SOURCE",
+        "-D_FORTIFY_SOURCE=3",
         "-D__clang_analyzer__",
     ],
     srcs: ["clang_fortify_tests.cpp"],
@@ -683,40 +630,50 @@
     name: "libfortify1-tests-clang",
     defaults: [
         "bionic_fortify_tests_defaults",
-        "bionic_tests_defaults",
     ],
     cflags: [
         "-D_FORTIFY_SOURCE=1",
         "-DTEST_NAME=Fortify1_clang",
     ],
-    shared: {
-        enabled: false,
-    },
 }
 
 cc_test_library {
     name: "libfortify2-tests-clang",
     defaults: [
         "bionic_fortify_tests_defaults",
-        "bionic_tests_defaults",
     ],
     cflags: [
         "-D_FORTIFY_SOURCE=2",
         "-DTEST_NAME=Fortify2_clang",
     ],
-    shared: {
-        enabled: false,
-    },
+}
+
+cc_test_library {
+    name: "libfortify3-tests-clang",
+    defaults: [
+        "bionic_fortify_tests_defaults",
+    ],
+    cflags: [
+        "-D_FORTIFY_SOURCE=3",
+        "-DTEST_NAME=Fortify3_clang",
+    ],
 }
 
 cc_defaults {
     name: "bionic_new_fortify_tests_defaults",
     defaults: [
         "bionic_clang_fortify_tests_w_flags",
+        "bionic_tests_defaults",
     ],
     cflags: [
         "-U_FORTIFY_SOURCE",
+        // Without this, HWASan will not recognize (i.e. will not detect errors involving)
+        // calls to mem* functions.
+        "-fbuiltin",
     ],
+    shared: {
+        enabled: false,
+    },
     srcs: ["clang_fortify_tests.cpp"],
 }
 
@@ -724,30 +681,33 @@
     name: "libfortify1-new-tests-clang",
     defaults: [
         "bionic_new_fortify_tests_defaults",
-        "bionic_tests_defaults",
     ],
     cflags: [
         "-D_FORTIFY_SOURCE=1",
         "-DTEST_NAME=Fortify1_clang_new",
     ],
-    shared: {
-        enabled: false,
-    },
 }
 
 cc_test_library {
     name: "libfortify2-new-tests-clang",
     defaults: [
         "bionic_new_fortify_tests_defaults",
-        "bionic_tests_defaults",
     ],
     cflags: [
         "-D_FORTIFY_SOURCE=2",
         "-DTEST_NAME=Fortify2_clang_new",
     ],
-    shared: {
-        enabled: false,
-    },
+}
+
+cc_test_library {
+    name: "libfortify3-new-tests-clang",
+    defaults: [
+        "bionic_new_fortify_tests_defaults",
+    ],
+    cflags: [
+        "-D_FORTIFY_SOURCE=3",
+        "-DTEST_NAME=Fortify3_clang_new",
+    ],
 }
 
 cc_defaults {
@@ -783,6 +743,12 @@
     cflags: ["-D_FORTIFY_SOURCE=2"],
 }
 
+cc_test_library {
+    name: "libfortify3-c-tests-clang",
+    defaults: ["bionic_fortify_c_tests_defaults"],
+    cflags: ["-D_FORTIFY_SOURCE=3"],
+}
+
 // -----------------------------------------------------------------------------
 // Library of all tests (excluding the dynamic linker tests).
 // -----------------------------------------------------------------------------
@@ -800,6 +766,9 @@
         "libfortify2-c-tests-clang",
         "libfortify2-tests-clang",
         "libfortify2-new-tests-clang",
+        "libfortify3-c-tests-clang",
+        "libfortify3-tests-clang",
+        "libfortify3-new-tests-clang",
     ],
     shared: {
         enabled: false,
@@ -1002,6 +971,8 @@
         "libtest_invalid-empty_shdr_table",
         "libtest_invalid-local-tls",
         "libtest_invalid-rw_load_segment",
+        "libtest_invalid-rw_rx_rw_load_segments",
+        "libtest_invalid-rx_rw_rx_load_segments",
         "libtest_invalid-textrels",
         "libtest_invalid-textrels2",
         "libtest_invalid-unaligned_shdr_offset",
@@ -1350,6 +1321,7 @@
         "dlfcn_test.cpp",
         "dl_test.cpp",
         "execinfo_test.cpp",
+        "link_test.cpp",
         "gtest_globals.cpp",
         "gtest_main.cpp",
         "pthread_dlfcn_test.cpp",
@@ -1369,6 +1341,7 @@
         "libBionicElfTlsLoaderTests",
         "libfortify1-tests-clang",
         "libfortify2-tests-clang",
+        "libfortify3-tests-clang",
     ],
 
     static_libs: [
@@ -1405,6 +1378,7 @@
                 // Musl doesn't have fortify
                 "libfortify1-tests-clang",
                 "libfortify2-tests-clang",
+                "libfortify3-tests-clang",
             ],
         },
     },
@@ -1423,6 +1397,7 @@
         "-Wformat-nonliteral",
         "-U_FORTIFY_SOURCE",
     ],
+    header_libs: ["libbase_headers"],
     srcs: ["clang_fortify_tests.cpp"],
 }
 
diff --git a/tests/NOTICE b/tests/NOTICE
index de95698..accde44 100644
--- a/tests/NOTICE
+++ b/tests/NOTICE
@@ -482,3 +482,31 @@
 
 -------------------------------------------------------------------
 
+Copyright (C) 2025 The Android Open Source Project
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+ * Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in
+   the documentation and/or other materials provided with the
+   distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGE.
+
+-------------------------------------------------------------------
+
diff --git a/tests/cfi_test.cpp b/tests/cfi_test.cpp
index 79a9e35..46454c5 100644
--- a/tests/cfi_test.cpp
+++ b/tests/cfi_test.cpp
@@ -15,6 +15,7 @@
  */
 
 #include <dlfcn.h>
+#include <link.h>
 #include <sys/stat.h>
 
 #include <vector>
@@ -33,6 +34,7 @@
 void __cfi_slowpath(uint64_t CallSiteTypeId, void* Ptr);
 void __cfi_slowpath_diag(uint64_t CallSiteTypeId, void* Ptr, void* DiagData);
 size_t __cfi_shadow_size();
+uintptr_t __cfi_shadow_load(void* p);
 }
 
 // Disables debuggerd stack traces to speed up death tests, make them less
@@ -177,3 +179,28 @@
   eth.Run([&]() { execve(helper.c_str(), eth.GetArgs(), eth.GetEnv()); }, 0, nullptr);
 #endif
 }
+
+TEST(cfi_test, every_loaded_dso_has_valid_shadow) {
+#if defined(__BIONIC__)
+  if (__cfi_shadow_size() == 0) GTEST_SKIP();
+
+  auto callback = [](dl_phdr_info* info, size_t, void*) {
+    if (info->dlpi_phnum == 0 || !info->dlpi_phdr) return 0;
+    for (ElfW(Half) i = 0; i < info->dlpi_phnum; ++i) {
+      auto& ph = info->dlpi_phdr[i];
+      if (ph.p_type != PT_LOAD || !(ph.p_flags & PF_X)) continue;
+      uintptr_t sample_addr = info->dlpi_addr + ph.p_vaddr;
+      uint16_t v = __cfi_shadow_load(reinterpret_cast<void*>(sample_addr));
+
+      EXPECT_NE(uint16_t(CFIShadow::kInvalidShadow), v)
+          << "ERROR: cfi shadow value is invalid, " << info->dlpi_name
+          << " @ 0x" << std::hex << sample_addr
+          << " → shadow=0x" << v
+          << " (" << std::dec << v << ")";
+    }
+    return 0;
+  };
+
+  dl_iterate_phdr(callback, nullptr);
+#endif
+}
diff --git a/tests/clang_fortify_tests.cpp b/tests/clang_fortify_tests.cpp
index da7926d..2dea8f1 100644
--- a/tests/clang_fortify_tests.cpp
+++ b/tests/clang_fortify_tests.cpp
@@ -25,7 +25,8 @@
 // (https://clang.llvm.org/doxygen/classclang_1_1VerifyDiagnosticConsumer.html#details)
 // to check diagnostics (e.g. the expected-* comments everywhere).
 //
-// 2. For run-time checks, we build and run as regular gtests.
+// 2. For run-time checks, we build and run as regular gtests (as described in
+// bionic/README.md).
 
 // Note that these tests do things like leaking memory. That's WAI.
 
@@ -91,7 +92,7 @@
 
 #include <array>
 
-#include "DoNotOptimize.h"
+#include <android-base/test_utils.h>
 
 #ifndef COMPILATION_TESTS
 #include <android-base/silent_death_test.h>
@@ -125,6 +126,12 @@
 #define EXPECT_FORTIFY_DEATH_STRUCT EXPECT_NO_DEATH
 #endif
 
+#if __has_feature(hwaddress_sanitizer)
+#define EXPECT_FORTIFY_OR_HWASAN_DEATH(expr) DIE_WITH(expr, testing::KilledBySignal(SIGABRT), "HWAddressSanitizer")
+#else
+#define EXPECT_FORTIFY_OR_HWASAN_DEATH EXPECT_FORTIFY_DEATH
+#endif
+
 #define FORTIFY_TEST(test_name) TEST_F(FORTIFY_TEST_NAME, test_name)
 
 #else  // defined(COMPILATION_TESTS)
@@ -132,6 +139,7 @@
 #define EXPECT_NO_DEATH(expr) expr
 #define EXPECT_FORTIFY_DEATH(expr) expr
 #define EXPECT_FORTIFY_DEATH_STRUCT EXPECT_FORTIFY_DEATH
+#define EXPECT_FORTIFY_OR_HWASAN_DEATH EXPECT_FORTIFY_DEATH
 #define FORTIFY_TEST(test_name) void test_name()
 #endif
 
@@ -148,7 +156,7 @@
     for (char& c : contents) {
       c ^= always_zero;
     }
-    DoNotOptimize(strlen(&contents.front()));
+    android::base::DoNotOptimize(strlen(&contents.front()));
   };
 
   EXPECT_NO_DEATH(run_strlen_with_contents({'f', 'o', '\0'}));
@@ -161,15 +169,13 @@
   {
     char large_buffer[sizeof(small_buffer) + 1] = {};
     // expected-error@+1{{will always overflow}}
-    EXPECT_FORTIFY_DEATH(memcpy(small_buffer, large_buffer, sizeof(large_buffer)));
+    EXPECT_FORTIFY_OR_HWASAN_DEATH(memcpy(small_buffer, large_buffer, sizeof(large_buffer)));
     // expected-error@+1{{will always overflow}}
-    EXPECT_FORTIFY_DEATH(memmove(small_buffer, large_buffer, sizeof(large_buffer)));
-    // FIXME(gbiv): look into removing mempcpy's diagnose_if bits once the b/149839606 roll sticks.
-    // expected-error@+2{{will always overflow}}
-    // expected-error@+1{{size bigger than buffer}}
+    EXPECT_FORTIFY_OR_HWASAN_DEATH(memmove(small_buffer, large_buffer, sizeof(large_buffer)));
+    // expected-error@+1{{will always overflow}}
     EXPECT_FORTIFY_DEATH(mempcpy(small_buffer, large_buffer, sizeof(large_buffer)));
     // expected-error@+1{{will always overflow}}
-    EXPECT_FORTIFY_DEATH(memset(small_buffer, 0, sizeof(large_buffer)));
+    EXPECT_FORTIFY_OR_HWASAN_DEATH(memset(small_buffer, 0, sizeof(large_buffer)));
     // expected-warning@+1{{arguments got flipped?}}
     EXPECT_NO_DEATH(memset(small_buffer, sizeof(small_buffer), 0));
     // expected-error@+1{{size bigger than buffer}}
@@ -182,8 +188,7 @@
     const char large_string[] = "Hello!!!";
     static_assert(sizeof(large_string) > sizeof(small_buffer), "");
 
-    // expected-error@+2{{will always overflow}}
-    // expected-error@+1{{string bigger than buffer}}
+    // expected-error@+1{{will always overflow}}
     EXPECT_FORTIFY_DEATH(strcpy(small_buffer, large_string));
     // expected-error@+1{{string bigger than buffer}}
     EXPECT_FORTIFY_DEATH(stpcpy(small_buffer, large_string));
@@ -220,8 +225,7 @@
     static_assert(sizeof(small_string) > sizeof(split.tiny_buffer), "");
 
 #if _FORTIFY_SOURCE > 1
-    // expected-error@+3{{will always overflow}}
-    // expected-error@+2{{string bigger than buffer}}
+    // expected-error@+2{{will always overflow}}
 #endif
     EXPECT_FORTIFY_DEATH_STRUCT(strcpy(split.tiny_buffer, small_string));
 
diff --git a/tests/dlext_private_tests.h b/tests/dlext_private_tests.h
deleted file mode 100644
index 262af4c..0000000
--- a/tests/dlext_private_tests.h
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __ANDROID_DLEXT_NAMESPACES_H__
-#define __ANDROID_DLEXT_NAMESPACES_H__
-
-#include <android/dlext.h>
-
-__BEGIN_DECLS
-
-/*
- * Initializes anonymous namespaces. The shared_libs_sonames is the list of sonames
- * to be shared by default namespace separated by colon. Example: "libc.so:libm.so:libdl.so".
- *
- * The library_search_path is the search path for anonymous namespace. The anonymous namespace
- * is used in the case when linker cannot identify the caller of dlopen/dlsym. This happens
- * for the code not loaded by dynamic linker; for example calls from the mono-compiled code.
- */
-extern bool android_init_anonymous_namespace(const char* shared_libs_sonames,
-                                             const char* library_search_path);
-
-
-enum {
-  /* A regular namespace is the namespace with a custom search path that does
-   * not impose any restrictions on the location of native libraries.
-   */
-  ANDROID_NAMESPACE_TYPE_REGULAR = 0,
-
-  /* An isolated namespace requires all the libraries to be on the search path
-   * or under permitted_when_isolated_path. The search path is the union of
-   * ld_library_path and default_library_path.
-   */
-  ANDROID_NAMESPACE_TYPE_ISOLATED = 1,
-
-  /* The shared namespace clones the list of libraries of the caller namespace upon creation
-   * which means that they are shared between namespaces - the caller namespace and the new one
-   * will use the same copy of a library if it was loaded prior to android_create_namespace call.
-   *
-   * Note that libraries loaded after the namespace is created will not be shared.
-   *
-   * Shared namespaces can be isolated or regular. Note that they do not inherit the search path nor
-   * permitted_path from the caller's namespace.
-   */
-  ANDROID_NAMESPACE_TYPE_SHARED = 2,
-
-  /* This flag instructs linker to enable exempt-list workaround for the namespace.
-   * See http://b/26394120 for details.
-   */
-  ANDROID_NAMESPACE_TYPE_EXEMPT_LIST_ENABLED = 0x08000000,
-
-  ANDROID_NAMESPACE_TYPE_SHARED_ISOLATED = ANDROID_NAMESPACE_TYPE_SHARED |
-                                           ANDROID_NAMESPACE_TYPE_ISOLATED,
-};
-
-/*
- * Creates new linker namespace.
- * ld_library_path and default_library_path represent the search path
- * for the libraries in the namespace.
- *
- * The libraries in the namespace are searched by folowing order:
- * 1. ld_library_path (Think of this as namespace-local LD_LIBRARY_PATH)
- * 2. In directories specified by DT_RUNPATH of the "needed by" binary.
- * 3. deault_library_path (This of this as namespace-local default library path)
- *
- * When type is ANDROID_NAMESPACE_TYPE_ISOLATED the resulting namespace requires all of
- * the libraries to be on the search path or under the permitted_when_isolated_path;
- * the search_path is ld_library_path:default_library_path. Note that the
- * permitted_when_isolated_path path is not part of the search_path and
- * does not affect the search order. It is a way to allow loading libraries from specific
- * locations when using absolute path.
- * If a library or any of its dependencies are outside of the permitted_when_isolated_path
- * and search_path, and it is not part of the public namespace dlopen will fail.
- */
-extern struct android_namespace_t* android_create_namespace(const char* name,
-                                                            const char* ld_library_path,
-                                                            const char* default_library_path,
-                                                            uint64_t type,
-                                                            const char* permitted_when_isolated_path,
-                                                            android_namespace_t* parent);
-
-extern bool android_link_namespaces(android_namespace_t* from,
-                                    android_namespace_t* to,
-                                    const char* shared_libs_sonames);
-
-extern bool android_link_namespaces_all_libs(android_namespace_t* from,
-                                             android_namespace_t* to);
-
-extern void android_set_application_target_sdk_version(int target);
-
-__END_DECLS
-
-#endif /* __ANDROID_DLEXT_NAMESPACES_H__ */
diff --git a/tests/dlext_test.cpp b/tests/dlext_test.cpp
index b5bf753..9c56f47 100644
--- a/tests/dlext_test.cpp
+++ b/tests/dlext_test.cpp
@@ -44,11 +44,12 @@
 #include "bionic/mte.h"
 #include "bionic/page.h"
 #include "core_shared_libs.h"
-#include "dlext_private_tests.h"
 #include "dlfcn_symlink_support.h"
 #include "gtest_globals.h"
 #include "utils.h"
 
+#include "platform/bionic/dlext_namespaces.h"
+
 #define ASSERT_DL_NOTNULL(ptr) \
     ASSERT_TRUE((ptr) != nullptr) << "dlerror: " << dlerror()
 
diff --git a/tests/dlfcn_symlink_support.cpp b/tests/dlfcn_symlink_support.cpp
index a5d3c3e..f96c23d 100644
--- a/tests/dlfcn_symlink_support.cpp
+++ b/tests/dlfcn_symlink_support.cpp
@@ -37,13 +37,6 @@
   // is disregarded intentionally since in bionic dlpi_name should always
   // be realpath to a shared object.
   const std::string suffix = std::string("/") + source_file_name;
-
-  // TODO (dimitry): remove this check once fake libdl.so is gone
-  if (info->dlpi_name == nullptr) {
-    // This is linker imposing as libdl.so - skip it
-    return 0;
-  }
-
   if (android::base::EndsWith(info->dlpi_name, suffix)) {
     std::string* path = reinterpret_cast<std::string*>(data);
     *path = info->dlpi_name;
diff --git a/tests/err_test.cpp b/tests/err_test.cpp
new file mode 100644
index 0000000..1fc2268
--- /dev/null
+++ b/tests/err_test.cpp
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2025 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <gtest/gtest.h>
+
+#include <err.h>
+
+#include <android-base/file.h>
+#include <android-base/silent_death_test.h>
+#include <android-base/test_utils.h>
+
+using err_DeathTest = SilentDeathTest;
+
+static std::string name() {
+  return android::base::Basename(android::base::GetExecutablePath());
+}
+
+TEST(err_DeathTest, err) {
+  ASSERT_EXIT({ errno = 0; err(22, "x%c", 'y'); },
+              ::testing::ExitedWithCode(22), name() + ": xy: Success\n");
+}
+
+TEST(err_DeathTest, err_errno) {
+  ASSERT_EXIT({ errno = EINVAL; err(22, "x%c", 'y'); },
+              ::testing::ExitedWithCode(22), name() + ": xy: Invalid argument\n");
+}
+
+TEST(err_DeathTest, err_null_fmt) {
+  ASSERT_EXIT({ errno = EINVAL; err(22, nullptr); },
+              ::testing::ExitedWithCode(22), name() + ": Invalid argument\n");
+}
+
+TEST(err, errx) {
+  ASSERT_EXIT({ errno = 0; errx(22, "x%c", 'y'); },
+              ::testing::ExitedWithCode(22), name() + ": xy\n");
+}
+
+TEST(err, errx_null_format) {
+  ASSERT_EXIT({ errno = EINVAL; errx(22, nullptr); },
+              ::testing::ExitedWithCode(22), name() + ": \n");
+}
+
+TEST(err, warn) {
+  CapturedStderr cap;
+  errno = 0;
+  warn("x%c", 'y');
+  ASSERT_EQ(cap.str(), name() + ": xy: Success\n");
+}
+
+TEST(err, warn_errno) {
+  CapturedStderr cap;
+  errno = EINVAL;
+  warn("x%c", 'y');
+  ASSERT_EQ(cap.str(), name() + ": xy: Invalid argument\n");
+}
+
+TEST(err, warnx) {
+  CapturedStderr cap;
+  errno = EINVAL;
+  warnx("x%c", 'y');
+  ASSERT_EQ(cap.str(), name() + ": xy\n");
+}
diff --git a/tests/fcntl_test.cpp b/tests/fcntl_test.cpp
index 57766ef..4f6fc7f 100644
--- a/tests/fcntl_test.cpp
+++ b/tests/fcntl_test.cpp
@@ -26,10 +26,6 @@
 #include <android-base/silent_death_test.h>
 #include <android-base/stringprintf.h>
 
-// Glibc v2.19 doesn't include these in fcntl.h so host builds will fail without.
-#if !defined(FALLOC_FL_PUNCH_HOLE) || !defined(FALLOC_FL_KEEP_SIZE)
-#include <linux/falloc.h>
-#endif
 #if !defined(EXT4_SUPER_MAGIC)
 #include <linux/magic.h>
 #endif
diff --git a/tests/fenv_test.cpp b/tests/fenv_test.cpp
index bbf339f..c1b4c8e 100644
--- a/tests/fenv_test.cpp
+++ b/tests/fenv_test.cpp
@@ -16,28 +16,29 @@
 
 #include <gtest/gtest.h>
 
-#include "DoNotOptimize.h"
 #include "utils.h"
 
 #include <fenv.h>
 #include <stdint.h>
 #include <sys/cdefs.h>
 
+#include <android-base/test_utils.h>
+
 static void TestRounding(float expectation1, float expectation2) {
   // Volatile to prevent compile-time evaluation.
   volatile float f = 1.968750f;
   volatile float m = 0x1.0p23f;
   float x;
-  DoNotOptimize(x = f + m);
+  android::base::DoNotOptimize(x = f + m);
   ASSERT_FLOAT_EQ(expectation1, x);
-  DoNotOptimize(x = x - m);
+  android::base::DoNotOptimize(x = x - m);
   ASSERT_EQ(expectation2, x);
 }
 
 static void DivideByZero() {
   // Volatile to prevent compile-time evaluation.
   volatile float zero = 0.0f;
-  DoNotOptimize(123.0f / zero);
+  android::base::DoNotOptimize(123.0f / zero);
 }
 
 TEST(fenv, fesetround_fegetround_FE_TONEAREST) {
diff --git a/tests/fortify_test.cpp b/tests/fortify_test.cpp
index fd1680b..f85b65f 100644
--- a/tests/fortify_test.cpp
+++ b/tests/fortify_test.cpp
@@ -28,6 +28,7 @@
 #include <time.h>
 
 #include <android-base/silent_death_test.h>
+#include <android-base/test_utils.h>
 
 #if defined(__BIONIC__)
 #define ASSERT_FORTIFY(expr) ASSERT_EXIT(expr, testing::KilledBySignal(SIGABRT), "FORTIFY")
@@ -35,6 +36,12 @@
 #define ASSERT_FORTIFY(expr) ASSERT_EXIT(expr, testing::KilledBySignal(SIGABRT), "")
 #endif
 
+#if __has_feature(hwaddress_sanitizer)
+#define ASSERT_FORTIFY_OR_HWASAN(expr) ASSERT_EXIT(expr, testing::KilledBySignal(SIGABRT), "HWAddressSanitizer")
+#else
+#define ASSERT_FORTIFY_OR_HWASAN ASSERT_FORTIFY
+#endif
+
 // Fortify test code needs to run multiple times, so TEST_NAME macro is used to
 // distinguish different tests. TEST_NAME is defined in compilation command.
 #define DEATHTEST_PASTER(name) name##_DeathTest
@@ -294,7 +301,22 @@
   ASSERT_FORTIFY(bzero(myfoo.b, n));
 }
 
-#endif /* defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE=2 */
+#endif /* defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE>=2 */
+
+#if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE >= 3
+
+TEST_F(DEATHTEST, dynamic_object_size_malloc) {
+#if __BIONIC__  // glibc doesn't use __builtin_dynamic_object_size
+  // Volatile because we have to fool both the frontend and the optimizer.
+  volatile int i = 32;
+  volatile int j = i + 1;
+  void* mem = malloc(i);
+  ASSERT_FORTIFY(memset(mem, 0, j));
+  free(mem);
+#endif
+}
+
+#endif /* defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE>=3 */
 
 // multibyte target where we over fill (should fail)
 TEST_F(DEATHTEST, strcpy_fortified) {
@@ -415,8 +437,13 @@
 }
 
 TEST_F(DEATHTEST, sprintf2_fortified) {
+  // glibc's fortified implementation of sprintf is smart enough to be able to detect this bug at
+  // compile time, but we want to check if it can also be detected at runtime.
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wformat-overflow"
   char buf[5];
   ASSERT_FORTIFY(sprintf(buf, "aaaaa"));
+#pragma clang diagnostic pop
 }
 
 static int vsprintf_helper(const char* fmt, ...) {
@@ -480,7 +507,7 @@
   char buf[20];
   strcpy(buf, "0123456789");
   volatile size_t n = 10;
-  ASSERT_FORTIFY(memmove(buf + 11, buf, n));
+  ASSERT_FORTIFY_OR_HWASAN(android::base::DoNotOptimize(memmove(buf + 11, buf, n)));
 }
 
 TEST_F(DEATHTEST, memcpy_fortified) {
@@ -488,13 +515,13 @@
   char bufb[10];
   strcpy(bufa, "012345678");
   volatile size_t n = 11;
-  ASSERT_FORTIFY(memcpy(bufb, bufa, n));
+  ASSERT_FORTIFY_OR_HWASAN(android::base::DoNotOptimize(memcpy(bufb, bufa, n)));
 }
 
 TEST_F(DEATHTEST, memset_fortified) {
   char buf[10];
   volatile size_t n = 11;
-  ASSERT_FORTIFY(memset(buf, 0, n));
+  ASSERT_FORTIFY_OR_HWASAN(android::base::DoNotOptimize(memset(buf, 0, n)));
 }
 
 TEST_F(DEATHTEST, stpncpy_fortified) {
diff --git a/tests/grp_pwd_test.cpp b/tests/grp_pwd_test.cpp
index 2c22081..6ced378 100644
--- a/tests/grp_pwd_test.cpp
+++ b/tests/grp_pwd_test.cpp
@@ -26,7 +26,10 @@
 #include <sys/types.h>
 #include <unistd.h>
 
+#include <algorithm>
+#include <iterator>
 #include <set>
+#include <string>
 #include <vector>
 
 #include <android-base/file.h>
@@ -504,6 +507,18 @@
       EXPECT_STREQ(getpwuid(AID_UPDATE_ENGINE_LOG)->pw_name, "update_engine_log");
     }
   }
+  // AID_AP_FIRMWARE (1097) was added in API level 37, but "trunk stable" means
+  // that the 2025Q{1,2} builds are tested with the _previous_ release's CTS.
+  if (android::base::GetIntProperty("ro.build.version.sdk", 0) == 36) {
+#if !defined(AID_AP_FIRMWARE)
+#define AID_AP_FIRMWARE 1097
+#endif
+    ids.erase(AID_AP_FIRMWARE);
+    expected_ids.erase(AID_AP_FIRMWARE);
+    if (getpwuid(AID_AP_FIRMWARE)) {
+      EXPECT_STREQ(getpwuid(AID_AP_FIRMWARE)->pw_name, "ap_firmware");
+    }
+  }
 
   EXPECT_EQ(expected_ids, ids) << return_differences();
 }
diff --git a/tests/gtest_globals.cpp b/tests/gtest_globals.cpp
index f146c08..64e6515 100644
--- a/tests/gtest_globals.cpp
+++ b/tests/gtest_globals.cpp
@@ -30,7 +30,7 @@
 
   std::string out_path;
   if (!android::base::Realpath(path.c_str(), &out_path)) {
-    printf("Failed to get realpath for \"%s\"\n", path.c_str());
+    fprintf(stderr, "Failed to get realpath for \"%s\"\n", path.c_str());
     abort();
   }
 
@@ -38,7 +38,7 @@
 
   std::string real_path;
   if (!android::base::Realpath(out_path, &real_path)) {
-    printf("\"%s\": does not exists\n", out_path.c_str());
+    fprintf(stderr, "\"%s\": does not exist\n", out_path.c_str());
     abort();
   }
 
diff --git a/tests/headers/posix/Android.bp b/tests/headers/posix/Android.bp
index 0809cdb..077c7cb 100644
--- a/tests/headers/posix/Android.bp
+++ b/tests/headers/posix/Android.bp
@@ -16,6 +16,7 @@
 
 package {
     default_applicable_licenses: ["bionic_tests_license"],
+    default_team: "trendy_team_native_tools_libraries",
 }
 
 cc_library_static {
@@ -27,6 +28,10 @@
         "-Werror",
         "-D_POSIX_C_SOURCE=200809L",
         "-D_XOPEN_SOURCE=700",
+
+        // Ensure that __BIONIC__ or __GLIBC__ is always defined.
+        // Any header suffices for bionic, but glibc is pretty ad hoc.
+        "-include features.h",
     ],
     host_supported: true,
     target: {
diff --git a/tests/headers/posix/dlfcn_h.c b/tests/headers/posix/dlfcn_h.c
index 3a32fdd..ce0b25b 100644
--- a/tests/headers/posix/dlfcn_h.c
+++ b/tests/headers/posix/dlfcn_h.c
@@ -11,13 +11,26 @@
   MACRO(RTLD_GLOBAL);
   MACRO(RTLD_LOCAL);
 
-#if !defined(__GLIBC__)  // Our glibc is too old.
+  // POSIX accidentally standardized `Dl_info_t`,
+  // rather than the `Dl_info` that everyone was using.
+  // See https://www.austingroupbugs.net/view.php?id=1847.
+#if !defined(__GLIBC__)
+  // Our glibc does have the old name,
+  // but only hidden behind _GNU_SOURCE as an extension.
   TYPE(Dl_info);
   STRUCT_MEMBER(Dl_info, const char*, dli_fname);
   STRUCT_MEMBER(Dl_info, void*, dli_fbase);
   STRUCT_MEMBER(Dl_info, const char*, dli_sname);
   STRUCT_MEMBER(Dl_info, void*, dli_saddr);
 #endif
+#if !defined(__GLIBC__)
+  // Our glibc is too old for the new name.
+  TYPE(Dl_info_t);
+  STRUCT_MEMBER(Dl_info_t, const char*, dli_fname);
+  STRUCT_MEMBER(Dl_info_t, void*, dli_fbase);
+  STRUCT_MEMBER(Dl_info_t, const char*, dli_sname);
+  STRUCT_MEMBER(Dl_info_t, void*, dli_saddr);
+#endif
 
 #if !defined(__GLIBC__)  // Our glibc is too old.
   FUNCTION(dladdr, int (*f)(const void*, Dl_info*));
diff --git a/tests/headers/posix/endian_h.c b/tests/headers/posix/endian_h.c
new file mode 100644
index 0000000..2b36d5e
--- /dev/null
+++ b/tests/headers/posix/endian_h.c
@@ -0,0 +1,35 @@
+// Copyright (C) 2025 The Android Open Source Project
+// SPDX-License-Identifier: BSD-2-Clause
+
+#include <endian.h>
+
+#include "header_checks.h"
+
+static void endian_h() {
+#if !defined(__GLIBC__) // glibc still has this POSIX 2024 header as extensions.
+  MACRO(BYTE_ORDER);
+  MACRO(LITTLE_ENDIAN);
+  MACRO(BIG_ENDIAN);
+
+  // TODO: better support for function-like macros.
+  be16toh(1234);
+  be32toh(1234);
+  be64toh(1234);
+
+  htobe16(1234);
+  htobe32(1234);
+  htobe64(1234);
+
+  htole16(1234);
+  htole32(1234);
+  htole64(1234);
+
+  le16toh(1234);
+  le32toh(1234);
+  le64toh(1234);
+
+  TYPE(uint16_t);
+  TYPE(uint32_t);
+  TYPE(uint64_t);
+#endif
+}
diff --git a/tests/headers/posix/fcntl_h.c b/tests/headers/posix/fcntl_h.c
index 5416dd1..0352d97 100644
--- a/tests/headers/posix/fcntl_h.c
+++ b/tests/headers/posix/fcntl_h.c
@@ -18,6 +18,12 @@
   MACRO(F_GETOWN);
   MACRO(F_SETOWN);
 
+#if !defined(__GLIBC__) // Our glibc is too old.
+  MACRO(F_OFD_GETLK);
+  MACRO(F_OFD_SETLK);
+  MACRO(F_OFD_SETLKW);
+#endif
+
   MACRO(FD_CLOEXEC);
 
   MACRO(F_RDLCK);
diff --git a/tests/headers/posix/fnmatch_h.c b/tests/headers/posix/fnmatch_h.c
index db263ca..6111035 100644
--- a/tests/headers/posix/fnmatch_h.c
+++ b/tests/headers/posix/fnmatch_h.c
@@ -10,6 +10,10 @@
   MACRO(FNM_PATHNAME);
   MACRO(FNM_PERIOD);
   MACRO(FNM_NOESCAPE);
+#if !defined(__GLIBC__) // Our glibc is too old.
+  MACRO(FNM_CASEFOLD);
+  MACRO(FNM_IGNORECASE);
+#endif
 
   FUNCTION(fnmatch, int (*f)(const char*, const char*, int));
 }
diff --git a/tests/headers/posix/limits_h.c b/tests/headers/posix/limits_h.c
index 4a076bb..0605136 100644
--- a/tests/headers/posix/limits_h.c
+++ b/tests/headers/posix/limits_h.c
@@ -194,6 +194,10 @@
   MACRO(USHRT_MAX);
   MACRO(WORD_BIT);
 
+#if defined(__BIONIC__)
+  MACRO(GETENTROPY_MAX);
+#endif
+
   MACRO(NL_ARGMAX);
   MACRO(NL_LANGMAX);
   MACRO(NL_MSGMAX);
diff --git a/tests/headers/posix/math_h.c b/tests/headers/posix/math_h.c
index dfd7604..5581f34 100644
--- a/tests/headers/posix/math_h.c
+++ b/tests/headers/posix/math_h.c
@@ -47,18 +47,44 @@
 #endif
 
   MACRO(M_E);
+  // TODO: MACRO(M_EGAMMA);
   MACRO(M_LOG2E);
   MACRO(M_LOG10E);
   MACRO(M_LN2);
   MACRO(M_LN10);
+  // TODO: MACRO(M_PHI);
   MACRO(M_PI);
   MACRO(M_PI_2);
   MACRO(M_PI_4);
   MACRO(M_1_PI);
+  // TODO: MACRO(M_1_SQRTPI);
   MACRO(M_2_PI);
   MACRO(M_2_SQRTPI);
   MACRO(M_SQRT2);
+  // TODO: MACRO(M_SQRT3);
   MACRO(M_SQRT1_2);
+  // TODO: MACRO(M_SQRT1_3);
+
+#if !defined(__GLIBC__) // glibc hasn't updated to POSIX 2024 yet.
+  MACRO(M_El);
+  // TODO: MACRO(M_EGAMMAl);
+  MACRO(M_LOG2El);
+  MACRO(M_LOG10El);
+  MACRO(M_LN2l);
+  MACRO(M_LN10l);
+  // TODO: MACRO(M_PHIl);
+  MACRO(M_PIl);
+  MACRO(M_PI_2l);
+  MACRO(M_PI_4l);
+  MACRO(M_1_PIl);
+  // TODO: MACRO(M_1_SQRTPIl);
+  MACRO(M_2_PIl);
+  MACRO(M_2_SQRTPIl);
+  MACRO(M_SQRT2l);
+  // TODO: MACRO(M_SQRT3l);
+  MACRO(M_SQRT1_2l);
+  // TODO: MACRO(M_SQRT1_3l);
+#endif
 
   MACRO(MAXFLOAT);
 
diff --git a/tests/headers/posix/spawn_h.c b/tests/headers/posix/spawn_h.c
index 2b43600..0b55dcb 100644
--- a/tests/headers/posix/spawn_h.c
+++ b/tests/headers/posix/spawn_h.c
@@ -24,8 +24,14 @@
   MACRO(POSIX_SPAWN_SETSIGMASK);
 
   FUNCTION(posix_spawn, int (*f)(pid_t*, const char*, const posix_spawn_file_actions_t*, const posix_spawnattr_t*, char* const[], char* const[]));
+#if !defined(__GLIBC__) // Our glibc is too old.
+  FUNCTION(posix_spawn_file_actions_addchdir, int (*f)(posix_spawn_file_actions_t*, const char*));
+#endif
   FUNCTION(posix_spawn_file_actions_addclose, int (*f)(posix_spawn_file_actions_t*, int));
   FUNCTION(posix_spawn_file_actions_adddup2, int (*f)(posix_spawn_file_actions_t*, int, int));
+#if !defined(__GLIBC__) // Our glibc is too old.
+  FUNCTION(posix_spawn_file_actions_addfchdir, int (*f)(posix_spawn_file_actions_t*, int));
+#endif
   FUNCTION(posix_spawn_file_actions_addopen, int (*f)(posix_spawn_file_actions_t*, int, const char*, int, mode_t));
   FUNCTION(posix_spawn_file_actions_destroy, int (*f)(posix_spawn_file_actions_t*));
   FUNCTION(posix_spawn_file_actions_init, int (*f)(posix_spawn_file_actions_t*));
diff --git a/tests/headers/posix/stdio_h.c b/tests/headers/posix/stdio_h.c
index 5b1677d..e8ad32f 100644
--- a/tests/headers/posix/stdio_h.c
+++ b/tests/headers/posix/stdio_h.c
@@ -50,6 +50,9 @@
   fp = stdin;
   fp = stdout;
 
+#if !defined(__GLIBC__) // Our glibc is too old.
+  FUNCTION(asprintf, int (*f)(char**, const char*, ...));
+#endif
   FUNCTION(clearerr, void (*f)(FILE*));
   FUNCTION(ctermid, char* (*f)(char*));
   FUNCTION(dprintf, int (*f)(int, const char*, ...));
@@ -111,6 +114,9 @@
   FUNCTION(tmpfile, FILE* (*f)(void));
   FUNCTION(tmpnam, char* (*f)(char*));
   FUNCTION(ungetc, int (*f)(int, FILE*));
+#if !defined(__GLIBC__) // Our glibc is too old.
+  FUNCTION(vasprintf, int (*f)(char**, const char*, va_list));
+#endif
   FUNCTION(vdprintf, int (*f)(int, const char*, va_list));
   FUNCTION(vfprintf, int (*f)(FILE*, const char*, va_list));
   FUNCTION(vfscanf, int (*f)(FILE*, const char*, va_list));
diff --git a/tests/headers/posix/stdlib_h.c b/tests/headers/posix/stdlib_h.c
index fc9ffed..33858ff 100644
--- a/tests/headers/posix/stdlib_h.c
+++ b/tests/headers/posix/stdlib_h.c
@@ -48,6 +48,7 @@
 #endif
   FUNCTION(abort, void (*f)(void));
   FUNCTION(abs, int (*f)(int));
+  FUNCTION(aligned_alloc, void* (*f)(size_t, size_t));
   FUNCTION(atexit, int (*f)(void (*)(void)));
   FUNCTION(atof, double (*f)(const char*));
   FUNCTION(atoi, int (*f)(const char*));
@@ -79,12 +80,18 @@
   FUNCTION(mbstowcs, size_t (*f)(wchar_t*, const char*, size_t));
   FUNCTION(mbtowc, int (*f)(wchar_t*, const char*, size_t));
   FUNCTION(mkdtemp, char* (*f)(char*));
+#if !defined(__GLIBC__) // Our glibc is too old.
+  FUNCTION(mkostemp, int (*f)(char*, int));
+#endif
   FUNCTION(mkstemp, int (*f)(char*));
   FUNCTION(mrand48, long (*f)(void));
   FUNCTION(nrand48, long (*f)(unsigned short[3]));
   FUNCTION(posix_memalign, int (*f)(void**, size_t, size_t));
   FUNCTION(posix_openpt, int (*f)(int));
   FUNCTION(ptsname, char* (*f)(int));
+#if !defined(__GLIBC__) // Our glibc is too old.
+  FUNCTION(ptsname_r, int (*f)(int, char*, size_t));
+#endif
   FUNCTION(putenv, int (*f)(char*));
   FUNCTION(qsort, void (*f)(void*, size_t, size_t, int (*)(const void*, const void*)));
 #if !defined(__GLIBC__) // Our glibc is too old.
diff --git a/tests/headers/posix/sys_mman_h.c b/tests/headers/posix/sys_mman_h.c
index 881e4e8..88a39fc 100644
--- a/tests/headers/posix/sys_mman_h.c
+++ b/tests/headers/posix/sys_mman_h.c
@@ -14,6 +14,10 @@
   MACRO(MAP_FIXED);
   MACRO(MAP_PRIVATE);
   MACRO(MAP_SHARED);
+#if !defined(__GLIBC__) // Our glibc is too old.
+  MACRO(MAP_ANON);
+  MACRO(MAP_ANONYMOUS);
+#endif
 
   MACRO(MS_ASYNC);
   MACRO(MS_INVALIDATE);
diff --git a/tests/headers/posix/sys_socket_h.c b/tests/headers/posix/sys_socket_h.c
index 7f9c91e..35a1685 100644
--- a/tests/headers/posix/sys_socket_h.c
+++ b/tests/headers/posix/sys_socket_h.c
@@ -108,6 +108,9 @@
   TYPE(ssize_t);
 
   FUNCTION(accept, int (*f)(int, struct sockaddr*, socklen_t*));
+#if !defined(__GLIBC__) // Our glibc is too old.
+  FUNCTION(accept4, int (*f)(int, struct sockaddr*, socklen_t*, int));
+#endif
   FUNCTION(bind, int (*f)(int, const struct sockaddr*, socklen_t));
   FUNCTION(connect, int (*f)(int, const struct sockaddr*, socklen_t));
   FUNCTION(getpeername, int (*f)(int, struct sockaddr*, socklen_t*));
diff --git a/tests/headers/posix/unistd_h.c b/tests/headers/posix/unistd_h.c
index d2262b3..86767c0 100644
--- a/tests/headers/posix/unistd_h.c
+++ b/tests/headers/posix/unistd_h.c
@@ -120,6 +120,10 @@
   MACRO(SEEK_CUR);
   MACRO(SEEK_END);
   MACRO(SEEK_SET);
+#if !defined(__GLIBC__) // Our glibc is too old.
+  MACRO(SEEK_HOLE);
+  MACRO(SEEK_DATA);
+#endif
 
   MACRO(F_LOCK);
   MACRO(F_TEST);
@@ -292,6 +296,9 @@
 #endif
   FUNCTION(dup, int (*f)(int));
   FUNCTION(dup2, int (*f)(int, int));
+#if !defined(__GLIBC__) // Our glibc is too old.
+  FUNCTION(dup3, int (*f)(int, int, int));
+#endif
   FUNCTION(_exit, void (*f)(int));
 #if !defined(__BIONIC__)
   FUNCTION(encrypt, void (*f)(char[64], int));
@@ -334,6 +341,10 @@
   FUNCTION(getpgrp, pid_t (*f)(void));
   FUNCTION(getpid, pid_t (*f)(void));
   FUNCTION(getppid, pid_t (*f)(void));
+#if !defined(__GLIBC__) // Our glibc is too old.
+  FUNCTION(getresgid, int (*f)(gid_t*, gid_t*, gid_t*));
+  FUNCTION(getresuid, int (*f)(uid_t*, uid_t*, uid_t*));
+#endif
   FUNCTION(getsid, pid_t (*f)(pid_t));
   FUNCTION(getuid, uid_t (*f)(void));
   FUNCTION(isatty, int (*f)(int));
@@ -346,6 +357,9 @@
   FUNCTION(pathconf, long (*f)(const char*, int));
   FUNCTION(pause, int (*f)(void));
   FUNCTION(pipe, int (*f)(int[2]));
+#if !defined(__GLIBC__) // Our glibc is too old.
+  FUNCTION(pipe2, int (*f)(int[2], int));
+#endif
   FUNCTION(pread, ssize_t (*f)(int, void*, size_t, off_t));
   FUNCTION(pwrite, ssize_t (*f)(int, const void*, size_t, off_t));
   FUNCTION(read, ssize_t (*f)(int, void*, size_t));
@@ -358,6 +372,10 @@
   FUNCTION(setpgid, int (*f)(pid_t, pid_t));
   FUNCTION(setpgrp, pid_t (*f)(void));
   FUNCTION(setregid, int (*f)(gid_t, gid_t));
+#if !defined(__GLIBC__) // Our glibc is too old.
+  FUNCTION(setresgid, int (*f)(gid_t, gid_t, gid_t));
+  FUNCTION(setresuid, int (*f)(uid_t, uid_t, uid_t));
+#endif
   FUNCTION(setreuid, int (*f)(uid_t, uid_t));
   FUNCTION(setsid, pid_t (*f)(void));
   FUNCTION(setuid, int (*f)(uid_t));
diff --git a/tests/heap_tagging_level_test.cpp b/tests/heap_tagging_level_test.cpp
index 4defc5d..12e2687 100644
--- a/tests/heap_tagging_level_test.cpp
+++ b/tests/heap_tagging_level_test.cpp
@@ -58,9 +58,7 @@
   if (mte_supported()) {
     GTEST_SKIP() << "Tagged pointers are not used on MTE hardware.";
   }
-  if (running_with_hwasan()) {
-    GTEST_SKIP() << "Tagged heap pointers feature is disabled under HWASan.";
-  }
+  SKIP_WITH_HWASAN << "Tagged heap pointers feature is disabled under HWASan.";
 
   void *x = malloc(1);
 
@@ -152,9 +150,7 @@
 
 TEST(heap_tagging_level, none_pointers_untagged) {
 #if defined(__BIONIC__)
-  if (running_with_hwasan()) {
-    GTEST_SKIP() << "HWASan is unaffected by heap tagging level.";
-  }
+  SKIP_WITH_HWASAN << "HWASan is unaffected by heap tagging level.";
   EXPECT_TRUE(SetHeapTaggingLevel(M_HEAP_TAGGING_LEVEL_NONE));
   std::unique_ptr<int[]> p = std::make_unique<int[]>(4);
   EXPECT_EQ(untag_address(p.get()), p.get());
@@ -171,7 +167,7 @@
 
   EXPECT_FALSE(SetHeapTaggingLevel(static_cast<HeapTaggingLevel>(12345)));
 
-  if (running_with_hwasan()) {
+  if (android::base::running_with_hwasan()) {
     // NONE -> ...
     EXPECT_FALSE(SetHeapTaggingLevel(M_HEAP_TAGGING_LEVEL_TBI));
     EXPECT_FALSE(SetHeapTaggingLevel(M_HEAP_TAGGING_LEVEL_ASYNC));
diff --git a/tests/hwasan_test.cpp b/tests/hwasan_test.cpp
index ddf84cb..30727f9 100644
--- a/tests/hwasan_test.cpp
+++ b/tests/hwasan_test.cpp
@@ -86,5 +86,5 @@
 }
 
 TEST(HwasanTest, IsRunningWithHWasan) {
-  EXPECT_TRUE(running_with_hwasan());
+  EXPECT_TRUE(android::base::running_with_hwasan());
 }
diff --git a/tests/ifaddrs_test.cpp b/tests/ifaddrs_test.cpp
index 01779f7..c22a6a5 100644
--- a/tests/ifaddrs_test.cpp
+++ b/tests/ifaddrs_test.cpp
@@ -18,6 +18,7 @@
 
 #include <ifaddrs.h>
 
+#include <arpa/inet.h>
 #include <dirent.h>
 #include <fcntl.h>
 #include <net/ethernet.h>
@@ -32,6 +33,7 @@
 
 #include <algorithm>
 #include <map>
+#include <sstream>
 #include <thread>
 #include <vector>
 
@@ -114,8 +116,19 @@
                                   sys_class_net.begin()));
 }
 
+static std::string ToString(const std::set<in_addr_t>& set) {
+  std::stringstream ss;
+  ss << "{";
+  for (auto it = set.begin(); it != set.end(); ++it) {
+    struct in_addr addr{*it};
+    ss << " " << inet_ntoa(addr);
+  }
+  ss << " }";
+  return ss.str();
+}
+
 static void CheckAddressIsInSet(const std::string& if_name, bool unicast,
-                                const std::set<in_addr_t>& addrs) {
+                                const std::set<in_addr_t>& getifaddrs_addrs) {
   ifreq ifr = {.ifr_addr.sa_family = AF_INET};
   if_name.copy(ifr.ifr_name, IFNAMSIZ - 1);
 
@@ -133,9 +146,13 @@
   close(fd);
 
   sockaddr_in* sock = reinterpret_cast<sockaddr_in*>(&ifr.ifr_addr);
-  in_addr_t addr = sock->sin_addr.s_addr;
+  in_addr_t ioctl_addr = sock->sin_addr.s_addr;
 
-  EXPECT_TRUE(addrs.contains(addr)) << if_name << ' ' << std::hex << ntohl(addr);
+  EXPECT_TRUE(getifaddrs_addrs.contains(ioctl_addr))
+      << if_name << ' ' << unicast << ' '
+      << std::hex << ntohl(ioctl_addr) << std::dec
+      << " not in "
+      << ToString(getifaddrs_addrs);
 }
 
 TEST(ifaddrs, getifaddrs_INET) {
diff --git a/tests/ifunc_test.cpp b/tests/ifunc_test.cpp
index 09d987d..6410529 100644
--- a/tests/ifunc_test.cpp
+++ b/tests/ifunc_test.cpp
@@ -97,8 +97,27 @@
   EXPECT_EQ(getauxval(AT_HWCAP) | _IFUNC_ARG_HWCAP, g_hwcap);
 
   EXPECT_EQ(sizeof(__ifunc_arg_t), g_arg._size);
+  EXPECT_EQ(5 * sizeof(uint64_t), g_arg._size);
+
+  // Test the fields.
   EXPECT_EQ(getauxval(AT_HWCAP), g_arg._hwcap);
   EXPECT_EQ(getauxval(AT_HWCAP2), g_arg._hwcap2);
+  EXPECT_EQ(getauxval(AT_HWCAP3), g_arg._hwcap3);
+  EXPECT_EQ(getauxval(AT_HWCAP4), g_arg._hwcap4);
+
+  // (Real users should just declare their ifunc resolver with the appropriate
+  // type, but we're deliberately trying to test all the options.)
+  uint64_t* raw_arg = reinterpret_cast<uint64_t*>(&g_arg);
+
+  // Test the helper function.
+  EXPECT_EQ(getauxval(AT_HWCAP), __ifunc_hwcap(1, g_hwcap, raw_arg));
+  EXPECT_EQ(getauxval(AT_HWCAP2), __ifunc_hwcap(2, g_hwcap, raw_arg));
+  EXPECT_EQ(getauxval(AT_HWCAP3), __ifunc_hwcap(3, g_hwcap, raw_arg));
+  EXPECT_EQ(getauxval(AT_HWCAP4), __ifunc_hwcap(4, g_hwcap, raw_arg));
+
+  // Test helper function edge cases.
+  EXPECT_EQ(0u, __ifunc_hwcap(-1, g_hwcap, raw_arg));
+  EXPECT_EQ(0u, __ifunc_hwcap(5, g_hwcap, raw_arg));
 #elif defined(__arm__)
   EXPECT_EQ(getauxval(AT_HWCAP), g_hwcap);
 #elif defined(__riscv)
diff --git a/tests/libs/Android.bp b/tests/libs/Android.bp
index 5b86e78..5374232 100644
--- a/tests/libs/Android.bp
+++ b/tests/libs/Android.bp
@@ -628,6 +628,7 @@
         "libns_hidden_child_global",
         "libdl_android",
     ],
+    include_dirs: ["bionic/libc"],
     ldflags: ["-Wl,--rpath,${ORIGIN}/.."],
 }
 
diff --git a/tests/libs/bionic_tests_zipalign.cpp b/tests/libs/bionic_tests_zipalign.cpp
index adb731f..ec7a3d0 100644
--- a/tests/libs/bionic_tests_zipalign.cpp
+++ b/tests/libs/bionic_tests_zipalign.cpp
@@ -17,6 +17,7 @@
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <sys/param.h>
 
 #include <algorithm>
 #include <memory>
@@ -129,7 +130,7 @@
     usage();
     return 1;
   }
-  if (((alignment - 1) & alignment) != 0) {
+  if (!powerof2(alignment)) {
     fprintf(stderr, "ALIGNMENT value is not a power of 2: %s\n", argv[1]);
     return 1;
   }
diff --git a/tests/libs/ns_hidden_child_helper.cpp b/tests/libs/ns_hidden_child_helper.cpp
index 77608e2..8f9c816 100644
--- a/tests/libs/ns_hidden_child_helper.cpp
+++ b/tests/libs/ns_hidden_child_helper.cpp
@@ -33,7 +33,7 @@
 #include <string>
 
 #include "../core_shared_libs.h"
-#include "../dlext_private_tests.h"
+#include "platform/bionic/dlext_namespaces.h"
 
 extern "C" void global_function();
 extern "C" void internal_function();
diff --git a/tests/limits_test.cpp b/tests/limits_test.cpp
index 64d9a33..e7bb927 100644
--- a/tests/limits_test.cpp
+++ b/tests/limits_test.cpp
@@ -23,6 +23,9 @@
   ASSERT_EQ(8 * static_cast<int>(sizeof(int)), WORD_BIT);
   ASSERT_EQ(2048, LINE_MAX);
   ASSERT_EQ(20, NZERO);
+#if defined(__BIONIC__)
+  ASSERT_GE(GETENTROPY_MAX, 256);
+#endif
 #if !defined(MB_LEN_MAX)
 #error MB_LEN_MAX
 #endif
diff --git a/tests/link_test.cpp b/tests/link_test.cpp
index ae3a1cd..04026fc 100644
--- a/tests/link_test.cpp
+++ b/tests/link_test.cpp
@@ -37,6 +37,8 @@
 #include <string>
 #include <unordered_map>
 
+extern "C" void* __executable_start;
+
 TEST(link, dl_iterate_phdr_early_exit) {
   static size_t call_count = 0;
   ASSERT_EQ(123, dl_iterate_phdr([](dl_phdr_info*, size_t, void*) { ++call_count; return 123; },
@@ -162,6 +164,24 @@
   return nullptr;
 }
 
+TEST(link, dl_iterate_phdr_order) {
+  struct Object {
+    std::string name;
+    void* addr;
+  };
+  auto callback = [](dl_phdr_info* info, size_t, void* data) {
+    std::vector<Object>& names = *static_cast<std::vector<Object>*>(data);
+    names.push_back(Object{info->dlpi_name ?: "(null)", reinterpret_cast<void*>(info->dlpi_addr)});
+    return 0;
+  };
+  std::vector<Object> objects;
+  ASSERT_EQ(0, dl_iterate_phdr(callback, &objects));
+
+  // The executable should come first.
+  ASSERT_TRUE(!objects.empty());
+  ASSERT_EQ(&__executable_start, objects[0].addr) << objects[0].name;
+}
+
 // Walk the DT_DEBUG/_r_debug global module list and compare it with the same
 // information from dl_iterate_phdr. Verify that the executable appears first
 // in _r_debug.
diff --git a/tests/malloc_iterate_test.cpp b/tests/malloc_iterate_test.cpp
index 297f637..8f4d728 100644
--- a/tests/malloc_iterate_test.cpp
+++ b/tests/malloc_iterate_test.cpp
@@ -14,6 +14,13 @@
  * limitations under the License.
  */
 
+// (b/291762537): This code uses malloc_usable_size(), and thus can't be
+// built with _FORTIFY_SOURCE>=3.
+#if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE >= 3
+#undef _FORTIFY_SOURCE
+#define _FORTIFY_SOURCE 2
+#endif
+
 #include <gtest/gtest.h>
 
 #if defined(__BIONIC__)
@@ -24,8 +31,10 @@
 #include <time.h>
 #include <unistd.h>
 
+#include <ios>
 #include <vector>
 
+#include <android-base/stringprintf.h>
 #include <android-base/test_utils.h>
 #include <async_safe/log.h>
 #include <procinfo/process_map.h>
@@ -44,9 +53,15 @@
   size_t count;
 };
 
+constexpr size_t kMaxFailures = 10;
 struct TestDataType {
   size_t total_allocated_bytes;
   std::vector<AllocDataType> allocs;
+  // This data structure is updated during the callback for malloc_iterate.
+  // Since no allocations are allowed in this callback, we have an array to
+  // contain any errors encountered to be reported after the call is done.
+  AllocDataType failures[kMaxFailures] = {};
+  size_t num_failures = 0;
 };
 
 static void AllocPtr(TestDataType* test_data, size_t size) {
@@ -73,7 +88,12 @@
 
   uintptr_t end;
   if (__builtin_add_overflow(base, size, &end)) {
-    // Skip this entry.
+    size_t index = test_data->num_failures;
+    if (index < kMaxFailures) {
+      test_data->failures[index].ptr = reinterpret_cast<void*>(base);
+      test_data->failures[index].size = size;
+      test_data->num_failures++;
+    }
     return;
   }
 
@@ -82,12 +102,15 @@
     if (ptr >= base && ptr < end) {
       test_data->allocs[i].count++;
 
-      uintptr_t max_size = end - ptr;
-      if (max_size > test_data->allocs[i].size) {
+      uintptr_t usable_size = end - ptr;
+      if (usable_size > test_data->allocs[i].size) {
+        // The usable size is greater than the allocated size, so set
+        // the size reported to allocated size.
         test_data->allocs[i].size_reported = test_data->allocs[i].size;
       } else {
-        test_data->allocs[i].size_reported = max_size;
+        test_data->allocs[i].size_reported = usable_size;
       }
+      break;
     }
   }
 }
@@ -115,8 +138,19 @@
 
   ASSERT_TRUE(parsed) << "Failed to parse /proc/self/maps";
 
+  if (test_data->num_failures != 0) {
+    std::string error_msg;
+    for (size_t i = 0; i < test_data->num_failures; i++) {
+      error_msg +=
+          android::base::StringPrintf("Pointer overflow %p size %zu\n", test_data->failures[i].ptr,
+                                      test_data->failures[i].size);
+    }
+    FAIL() << error_msg;
+  }
+
   for (size_t i = 0; i < test_data->allocs.size(); i++) {
-    EXPECT_EQ(1UL, test_data->allocs[i].count) << "Failed on size " << test_data->allocs[i].size;
+    EXPECT_EQ(1UL, test_data->allocs[i].count)
+        << "Unable to find allocation of size " << test_data->allocs[i].size;
     if (test_data->allocs[i].count == 1) {
       EXPECT_EQ(test_data->allocs[i].size, test_data->allocs[i].size_reported);
     }
diff --git a/tests/malloc_test.cpp b/tests/malloc_test.cpp
index db814dc..f6249e0 100644
--- a/tests/malloc_test.cpp
+++ b/tests/malloc_test.cpp
@@ -47,14 +47,13 @@
 #include <android-base/file.h>
 #include <android-base/test_utils.h>
 
-#include "DoNotOptimize.h"
 #include "utils.h"
 
 #if defined(__BIONIC__)
 
 #include "SignalUtils.h"
-#include "dlext_private_tests.h"
 
+#include "platform/bionic/dlext_namespaces.h"
 #include "platform/bionic/malloc.h"
 #include "platform/bionic/mte.h"
 #include "platform/bionic/reserved_signals.h"
@@ -72,14 +71,6 @@
 
 #endif
 
-TEST(malloc, malloc_std) {
-  // Simple malloc test.
-  void *ptr = malloc(100);
-  ASSERT_TRUE(ptr != nullptr);
-  ASSERT_LE(100U, malloc_usable_size(ptr));
-  free(ptr);
-}
-
 TEST(malloc, malloc_overflow) {
   SKIP_WITH_HWASAN;
   errno = 0;
@@ -87,18 +78,6 @@
   ASSERT_ERRNO(ENOMEM);
 }
 
-TEST(malloc, calloc_std) {
-  // Simple calloc test.
-  size_t alloc_len = 100;
-  char *ptr = (char *)calloc(1, alloc_len);
-  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]);
-  }
-  free(ptr);
-}
-
 TEST(malloc, calloc_mem_init_disabled) {
 #if defined(__BIONIC__)
   // calloc should still zero memory if mem-init is disabled.
@@ -140,21 +119,6 @@
   ASSERT_ERRNO(ENOMEM);
 }
 
-TEST(malloc, memalign_multiple) {
-  SKIP_WITH_HWASAN << "hwasan requires power of 2 alignment";
-  // Memalign test where the alignment is any value.
-  for (size_t i = 0; i <= 12; i++) {
-    for (size_t alignment = 1 << i; alignment < (1U << (i+1)); alignment++) {
-      char *ptr = reinterpret_cast<char*>(memalign(alignment, 100));
-      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;
-      free(ptr);
-    }
-  }
-}
-
 TEST(malloc, memalign_overflow) {
   SKIP_WITH_HWASAN;
   ASSERT_EQ(nullptr, memalign(4096, SIZE_MAX));
@@ -170,179 +134,6 @@
   }
 }
 
-TEST(malloc, memalign_realloc) {
-  // 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 != 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 != nullptr);
-    ASSERT_LE(200U, malloc_usable_size(ptr));
-    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 != nullptr);
-    ASSERT_LE(300U, malloc_usable_size(ptr));
-    for (size_t i = 0; i < 200; i++) {
-      ASSERT_EQ(0x45, ptr[i]);
-    }
-    memset(ptr, 0x67, 300);
-
-    ptr = (char*)realloc(ptr, 250);
-    ASSERT_TRUE(ptr != nullptr);
-    ASSERT_LE(250U, malloc_usable_size(ptr));
-    for (size_t i = 0; i < 250; i++) {
-      ASSERT_EQ(0x67, ptr[i]);
-    }
-    free(ptr);
-  }
-}
-
-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 != nullptr);
-  ASSERT_LE(100U, malloc_usable_size(ptr));
-  memset(ptr, 67, 100);
-
-  ptr = (char *)realloc(ptr, 200);
-  ASSERT_TRUE(ptr != nullptr);
-  ASSERT_LE(200U, malloc_usable_size(ptr));
-  for (size_t i = 0; i < 100; i++) {
-    ASSERT_EQ(67, ptr[i]);
-  }
-  free(ptr);
-}
-
-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 != nullptr);
-  ASSERT_LE(200U, malloc_usable_size(ptr));
-  memset(ptr, 67, 200);
-
-  ptr = (char *)realloc(ptr, 100);
-  ASSERT_TRUE(ptr != nullptr);
-  ASSERT_LE(100U, malloc_usable_size(ptr));
-  for (size_t i = 0; i < 100; i++) {
-    ASSERT_EQ(67, ptr[i]);
-  }
-  free(ptr);
-}
-
-TEST(malloc, malloc_multiple_realloc) {
-  // Multiple reallocs, malloc is used for the original allocation.
-  char *ptr = (char *)malloc(200);
-  ASSERT_TRUE(ptr != nullptr);
-  ASSERT_LE(200U, malloc_usable_size(ptr));
-  memset(ptr, 0x23, 200);
-
-  ptr = (char *)realloc(ptr, 100);
-  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 != 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 != nullptr);
-  ASSERT_LE(150U, malloc_usable_size(ptr));
-  for (size_t i = 0; i < 50; i++) {
-    ASSERT_EQ(0x23, ptr[i]);
-  }
-  memset(ptr, 0x23, 150);
-
-  ptr = (char*)realloc(ptr, 425);
-  ASSERT_TRUE(ptr != nullptr);
-  ASSERT_LE(425U, malloc_usable_size(ptr));
-  for (size_t i = 0; i < 150; i++) {
-    ASSERT_EQ(0x23, ptr[i]);
-  }
-  free(ptr);
-}
-
-TEST(malloc, calloc_realloc_larger) {
-  // Realloc to a larger size, calloc is used for the original allocation.
-  char *ptr = (char *)calloc(1, 100);
-  ASSERT_TRUE(ptr != nullptr);
-  ASSERT_LE(100U, malloc_usable_size(ptr));
-
-  ptr = (char *)realloc(ptr, 200);
-  ASSERT_TRUE(ptr != nullptr);
-  ASSERT_LE(200U, malloc_usable_size(ptr));
-  for (size_t i = 0; i < 100; i++) {
-    ASSERT_EQ(0, ptr[i]);
-  }
-  free(ptr);
-}
-
-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 != nullptr);
-  ASSERT_LE(200U, malloc_usable_size(ptr));
-
-  ptr = (char *)realloc(ptr, 100);
-  ASSERT_TRUE(ptr != nullptr);
-  ASSERT_LE(100U, malloc_usable_size(ptr));
-  for (size_t i = 0; i < 100; i++) {
-    ASSERT_EQ(0, ptr[i]);
-  }
-  free(ptr);
-}
-
-TEST(malloc, calloc_multiple_realloc) {
-  // Multiple reallocs, calloc is used for the original allocation.
-  char *ptr = (char *)calloc(1, 200);
-  ASSERT_TRUE(ptr != nullptr);
-  ASSERT_LE(200U, malloc_usable_size(ptr));
-
-  ptr = (char *)realloc(ptr, 100);
-  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 != 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 != nullptr);
-  ASSERT_LE(150U, malloc_usable_size(ptr));
-  for (size_t i = 0; i < 50; i++) {
-    ASSERT_EQ(0, ptr[i]);
-  }
-  memset(ptr, 0, 150);
-
-  ptr = (char*)realloc(ptr, 425);
-  ASSERT_TRUE(ptr != nullptr);
-  ASSERT_LE(425U, malloc_usable_size(ptr));
-  for (size_t i = 0; i < 150; i++) {
-    ASSERT_EQ(0, ptr[i]);
-  }
-  free(ptr);
-}
-
 TEST(malloc, realloc_overflow) {
   SKIP_WITH_HWASAN;
   errno = 0;
@@ -361,19 +152,6 @@
 extern "C" void* valloc(size_t);
 #endif
 
-TEST(malloc, pvalloc_std) {
-#if defined(HAVE_DEPRECATED_MALLOC_FUNCS)
-  size_t pagesize = sysconf(_SC_PAGESIZE);
-  void* ptr = pvalloc(100);
-  ASSERT_TRUE(ptr != nullptr);
-  ASSERT_TRUE((reinterpret_cast<uintptr_t>(ptr) & (pagesize-1)) == 0);
-  ASSERT_LE(pagesize, malloc_usable_size(ptr));
-  free(ptr);
-#else
-  GTEST_SKIP() << "pvalloc not supported.";
-#endif
-}
-
 TEST(malloc, pvalloc_overflow) {
 #if defined(HAVE_DEPRECATED_MALLOC_FUNCS)
   ASSERT_EQ(nullptr, pvalloc(SIZE_MAX));
@@ -538,25 +316,6 @@
 #endif
 }
 
-TEST(malloc, calloc_usable_size) {
-  for (size_t size = 1; size <= 2048; size++) {
-    void* pointer = malloc(size);
-    ASSERT_TRUE(pointer != nullptr);
-    memset(pointer, 0xeb, malloc_usable_size(pointer));
-    free(pointer);
-
-    // We should get a previous pointer that has been set to non-zero.
-    // If calloc does not zero out all of the data, this will fail.
-    uint8_t* zero_mem = reinterpret_cast<uint8_t*>(calloc(1, size));
-    ASSERT_TRUE(pointer != nullptr);
-    size_t usable_size = malloc_usable_size(zero_mem);
-    for (size_t i = 0; i < usable_size; i++) {
-      ASSERT_EQ(0, zero_mem[i]) << "Failed at allocation size " << size << " at byte " << i;
-    }
-    free(zero_mem);
-  }
-}
-
 TEST(malloc, malloc_0) {
   void* p = malloc(0);
   ASSERT_TRUE(p != nullptr);
@@ -808,132 +567,6 @@
 #endif
 }
 
-TEST(malloc, reallocarray) {
-#if HAVE_REALLOCARRAY
-  void* p = reallocarray(nullptr, 2, 32);
-  ASSERT_TRUE(p != nullptr);
-  ASSERT_GE(malloc_usable_size(p), 64U);
-#else
-  GTEST_SKIP() << "reallocarray not available";
-#endif
-}
-
-TEST(malloc, mallinfo) {
-#if defined(__BIONIC__) || defined(ANDROID_HOST_MUSL)
-  SKIP_WITH_HWASAN << "hwasan does not implement mallinfo";
-  static size_t sizes[] = {
-    8, 32, 128, 4096, 32768, 131072, 1024000, 10240000, 20480000, 300000000
-  };
-
-  static constexpr size_t kMaxAllocs = 50;
-
-  for (size_t size : sizes) {
-    // If some of these allocations are stuck in a thread cache, then keep
-    // looping until we make an allocation that changes the total size of the
-    // memory allocated.
-    // jemalloc implementations counts the thread cache allocations against
-    // total memory allocated.
-    void* ptrs[kMaxAllocs] = {};
-    bool pass = false;
-    for (size_t i = 0; i < kMaxAllocs; i++) {
-      size_t allocated = mallinfo().uordblks;
-      ptrs[i] = malloc(size);
-      ASSERT_TRUE(ptrs[i] != nullptr);
-      size_t new_allocated = mallinfo().uordblks;
-      if (allocated != new_allocated) {
-        size_t usable_size = malloc_usable_size(ptrs[i]);
-        // Only check if the total got bigger by at least allocation size.
-        // Sometimes the mallinfo numbers can go backwards due to compaction
-        // and/or freeing of cached data.
-        if (new_allocated >= allocated + usable_size) {
-          pass = true;
-          break;
-        }
-      }
-    }
-    for (void* ptr : ptrs) {
-      free(ptr);
-    }
-    ASSERT_TRUE(pass)
-        << "For size " << size << " allocated bytes did not increase after "
-        << kMaxAllocs << " allocations.";
-  }
-#else
-  GTEST_SKIP() << "glibc is broken";
-#endif
-}
-
-TEST(malloc, mallinfo2) {
-#if defined(__BIONIC__) || defined(ANDROID_HOST_MUSL)
-  SKIP_WITH_HWASAN << "hwasan does not implement mallinfo2";
-  static size_t sizes[] = {8, 32, 128, 4096, 32768, 131072, 1024000, 10240000, 20480000, 300000000};
-
-  static constexpr size_t kMaxAllocs = 50;
-
-  for (size_t size : sizes) {
-    // If some of these allocations are stuck in a thread cache, then keep
-    // looping until we make an allocation that changes the total size of the
-    // memory allocated.
-    // jemalloc implementations counts the thread cache allocations against
-    // total memory allocated.
-    void* ptrs[kMaxAllocs] = {};
-    bool pass = false;
-    for (size_t i = 0; i < kMaxAllocs; i++) {
-      struct mallinfo info = mallinfo();
-      struct mallinfo2 info2 = mallinfo2();
-      // Verify that mallinfo and mallinfo2 are exactly the same.
-      ASSERT_EQ(static_cast<size_t>(info.arena), info2.arena);
-      ASSERT_EQ(static_cast<size_t>(info.ordblks), info2.ordblks);
-      ASSERT_EQ(static_cast<size_t>(info.smblks), info2.smblks);
-      ASSERT_EQ(static_cast<size_t>(info.hblks), info2.hblks);
-      ASSERT_EQ(static_cast<size_t>(info.hblkhd), info2.hblkhd);
-      ASSERT_EQ(static_cast<size_t>(info.usmblks), info2.usmblks);
-      ASSERT_EQ(static_cast<size_t>(info.fsmblks), info2.fsmblks);
-      ASSERT_EQ(static_cast<size_t>(info.uordblks), info2.uordblks);
-      ASSERT_EQ(static_cast<size_t>(info.fordblks), info2.fordblks);
-      ASSERT_EQ(static_cast<size_t>(info.keepcost), info2.keepcost);
-
-      size_t allocated = info2.uordblks;
-      ptrs[i] = malloc(size);
-      ASSERT_TRUE(ptrs[i] != nullptr);
-
-      info = mallinfo();
-      info2 = mallinfo2();
-      // Verify that mallinfo and mallinfo2 are exactly the same.
-      ASSERT_EQ(static_cast<size_t>(info.arena), info2.arena);
-      ASSERT_EQ(static_cast<size_t>(info.ordblks), info2.ordblks);
-      ASSERT_EQ(static_cast<size_t>(info.smblks), info2.smblks);
-      ASSERT_EQ(static_cast<size_t>(info.hblks), info2.hblks);
-      ASSERT_EQ(static_cast<size_t>(info.hblkhd), info2.hblkhd);
-      ASSERT_EQ(static_cast<size_t>(info.usmblks), info2.usmblks);
-      ASSERT_EQ(static_cast<size_t>(info.fsmblks), info2.fsmblks);
-      ASSERT_EQ(static_cast<size_t>(info.uordblks), info2.uordblks);
-      ASSERT_EQ(static_cast<size_t>(info.fordblks), info2.fordblks);
-      ASSERT_EQ(static_cast<size_t>(info.keepcost), info2.keepcost);
-
-      size_t new_allocated = info2.uordblks;
-      if (allocated != new_allocated) {
-        size_t usable_size = malloc_usable_size(ptrs[i]);
-        // Only check if the total got bigger by at least allocation size.
-        // Sometimes the mallinfo2 numbers can go backwards due to compaction
-        // and/or freeing of cached data.
-        if (new_allocated >= allocated + usable_size) {
-          pass = true;
-          break;
-        }
-      }
-    }
-    for (void* ptr : ptrs) {
-      free(ptr);
-    }
-    ASSERT_TRUE(pass) << "For size " << size << " allocated bytes did not increase after "
-                      << kMaxAllocs << " allocations.";
-  }
-#else
-  GTEST_SKIP() << "glibc is broken";
-#endif
-}
-
 template <typename Type>
 void __attribute__((optnone)) VerifyAlignment(Type* floating) {
   size_t expected_alignment = alignof(Type);
@@ -1065,69 +698,6 @@
   AlignCheck();
 }
 
-// Jemalloc doesn't pass this test right now, so leave it as disabled.
-TEST(malloc, DISABLED_alloc_after_fork) {
-  // Both of these need to be a power of 2.
-  static constexpr size_t kMinAllocationSize = 8;
-  static constexpr size_t kMaxAllocationSize = 2097152;
-
-  static constexpr size_t kNumAllocatingThreads = 5;
-  static constexpr size_t kNumForkLoops = 100;
-
-  std::atomic_bool stop;
-
-  // Create threads that simply allocate and free different sizes.
-  std::vector<std::thread*> threads;
-  for (size_t i = 0; i < kNumAllocatingThreads; i++) {
-    std::thread* t = new std::thread([&stop] {
-      while (!stop) {
-        for (size_t size = kMinAllocationSize; size <= kMaxAllocationSize; size <<= 1) {
-          void* ptr;
-          DoNotOptimize(ptr = malloc(size));
-          free(ptr);
-        }
-      }
-    });
-    threads.push_back(t);
-  }
-
-  // Create a thread to fork and allocate.
-  for (size_t i = 0; i < kNumForkLoops; i++) {
-    pid_t pid;
-    if ((pid = fork()) == 0) {
-      for (size_t size = kMinAllocationSize; size <= kMaxAllocationSize; size <<= 1) {
-        void* ptr;
-        DoNotOptimize(ptr = malloc(size));
-        ASSERT_TRUE(ptr != nullptr);
-        // Make sure we can touch all of the allocation.
-        memset(ptr, 0x1, size);
-        ASSERT_LE(size, malloc_usable_size(ptr));
-        free(ptr);
-      }
-      _exit(10);
-    }
-    ASSERT_NE(-1, pid);
-    AssertChildExited(pid, 10);
-  }
-
-  stop = true;
-  for (auto thread : threads) {
-    thread->join();
-    delete thread;
-  }
-}
-
-TEST(android_mallopt, error_on_unexpected_option) {
-#if defined(__BIONIC__)
-  const int unrecognized_option = -1;
-  errno = 0;
-  EXPECT_EQ(false, android_mallopt(unrecognized_option, nullptr, 0));
-  EXPECT_ERRNO(ENOTSUP);
-#else
-  GTEST_SKIP() << "bionic-only test";
-#endif
-}
-
 bool IsDynamic() {
 #if defined(__LP64__)
   Elf64_Ehdr ehdr;
@@ -1582,167 +1152,6 @@
   }
 }
 
-void VerifyAllocationsAreZero(std::function<void*(size_t)> alloc_func, std::string function_name,
-                              std::vector<size_t>& test_sizes, size_t max_allocations) {
-  // Vector of zero'd data used for comparisons. Make it twice the largest size.
-  std::vector<char> zero(test_sizes.back() * 2, 0);
-
-  SCOPED_TRACE(testing::Message() << function_name << " failed to zero memory");
-
-  for (size_t test_size : test_sizes) {
-    std::vector<void*> ptrs(max_allocations);
-    for (size_t i = 0; i < ptrs.size(); i++) {
-      SCOPED_TRACE(testing::Message() << "size " << test_size << " at iteration " << i);
-      ptrs[i] = alloc_func(test_size);
-      ASSERT_TRUE(ptrs[i] != nullptr);
-      size_t alloc_size = malloc_usable_size(ptrs[i]);
-      ASSERT_LE(alloc_size, zero.size());
-      ASSERT_EQ(0, memcmp(ptrs[i], zero.data(), alloc_size));
-
-      // Set the memory to non-zero to make sure if the pointer
-      // is reused it's still zero.
-      memset(ptrs[i], 0xab, alloc_size);
-    }
-    // Free the pointers.
-    for (size_t i = 0; i < ptrs.size(); i++) {
-      free(ptrs[i]);
-    }
-    for (size_t i = 0; i < ptrs.size(); i++) {
-      SCOPED_TRACE(testing::Message() << "size " << test_size << " at iteration " << i);
-      ptrs[i] = malloc(test_size);
-      ASSERT_TRUE(ptrs[i] != nullptr);
-      size_t alloc_size = malloc_usable_size(ptrs[i]);
-      ASSERT_LE(alloc_size, zero.size());
-      ASSERT_EQ(0, memcmp(ptrs[i], zero.data(), alloc_size));
-    }
-    // Free all of the pointers later to maximize the chance of reusing from
-    // the first loop.
-    for (size_t i = 0; i < ptrs.size(); i++) {
-      free(ptrs[i]);
-    }
-  }
-}
-
-// Verify that small and medium allocations are always zero.
-// @CddTest = 9.7/C-4-1
-TEST(malloc, zeroed_allocations_small_medium_sizes) {
-#if !defined(__BIONIC__)
-  GTEST_SKIP() << "Only valid on bionic";
-#endif
-  SKIP_WITH_HWASAN << "Only test system allocator, not hwasan allocator.";
-
-  if (IsLowRamDevice()) {
-    GTEST_SKIP() << "Skipped on low memory devices.";
-  }
-
-  constexpr size_t kMaxAllocations = 1024;
-  std::vector<size_t> test_sizes = {16, 48, 128, 1024, 4096, 65536};
-  VerifyAllocationsAreZero([](size_t size) -> void* { return malloc(size); }, "malloc", test_sizes,
-                           kMaxAllocations);
-
-  VerifyAllocationsAreZero([](size_t size) -> void* { return memalign(64, size); }, "memalign",
-                           test_sizes, kMaxAllocations);
-
-  VerifyAllocationsAreZero(
-      [](size_t size) -> void* {
-        void* ptr;
-        if (posix_memalign(&ptr, 64, size) == 0) {
-          return ptr;
-        }
-        return nullptr;
-      },
-      "posix_memalign", test_sizes, kMaxAllocations);
-}
-
-// Verify that large allocations are always zero.
-// @CddTest = 9.7/C-4-1
-TEST(malloc, zeroed_allocations_large_sizes) {
-#if !defined(__BIONIC__)
-  GTEST_SKIP() << "Only valid on bionic";
-#endif
-  SKIP_WITH_HWASAN << "Only test system allocator, not hwasan allocator.";
-
-  if (IsLowRamDevice()) {
-    GTEST_SKIP() << "Skipped on low memory devices.";
-  }
-
-  constexpr size_t kMaxAllocations = 20;
-  std::vector<size_t> test_sizes = {1000000, 2000000, 3000000, 4000000};
-  VerifyAllocationsAreZero([](size_t size) -> void* { return malloc(size); }, "malloc", test_sizes,
-                           kMaxAllocations);
-
-  VerifyAllocationsAreZero([](size_t size) -> void* { return memalign(64, size); }, "memalign",
-                           test_sizes, kMaxAllocations);
-
-  VerifyAllocationsAreZero(
-      [](size_t size) -> void* {
-        void* ptr;
-        if (posix_memalign(&ptr, 64, size) == 0) {
-          return ptr;
-        }
-        return nullptr;
-      },
-      "posix_memalign", test_sizes, kMaxAllocations);
-}
-
-// Verify that reallocs are zeroed when expanded.
-// @CddTest = 9.7/C-4-1
-TEST(malloc, zeroed_allocations_realloc) {
-#if !defined(__BIONIC__)
-  GTEST_SKIP() << "Only valid on bionic";
-#endif
-  SKIP_WITH_HWASAN << "Only test system allocator, not hwasan allocator.";
-
-  if (IsLowRamDevice()) {
-    GTEST_SKIP() << "Skipped on low memory devices.";
-  }
-
-  // Vector of zero'd data used for comparisons.
-  constexpr size_t kMaxMemorySize = 131072;
-  std::vector<char> zero(kMaxMemorySize, 0);
-
-  constexpr size_t kMaxAllocations = 1024;
-  std::vector<size_t> test_sizes = {16, 48, 128, 1024, 4096, 65536};
-  // Do a number of allocations and set them to non-zero.
-  for (size_t test_size : test_sizes) {
-    std::vector<void*> ptrs(kMaxAllocations);
-    for (size_t i = 0; i < kMaxAllocations; i++) {
-      ptrs[i] = malloc(test_size);
-      ASSERT_TRUE(ptrs[i] != nullptr);
-
-      // Set the memory to non-zero to make sure if the pointer
-      // is reused it's still zero.
-      memset(ptrs[i], 0xab, malloc_usable_size(ptrs[i]));
-    }
-    // Free the pointers.
-    for (size_t i = 0; i < kMaxAllocations; i++) {
-      free(ptrs[i]);
-    }
-  }
-
-  // Do the reallocs to a larger size and verify the rest of the allocation
-  // is zero.
-  constexpr size_t kInitialSize = 8;
-  for (size_t test_size : test_sizes) {
-    std::vector<void*> ptrs(kMaxAllocations);
-    for (size_t i = 0; i < kMaxAllocations; i++) {
-      ptrs[i] = malloc(kInitialSize);
-      ASSERT_TRUE(ptrs[i] != nullptr);
-      size_t orig_alloc_size = malloc_usable_size(ptrs[i]);
-
-      ptrs[i] = realloc(ptrs[i], test_size);
-      ASSERT_TRUE(ptrs[i] != nullptr);
-      size_t new_alloc_size = malloc_usable_size(ptrs[i]);
-      char* ptr = reinterpret_cast<char*>(ptrs[i]);
-      ASSERT_EQ(0, memcmp(&ptr[orig_alloc_size], zero.data(), new_alloc_size - orig_alloc_size))
-          << "realloc from " << kInitialSize << " to size " << test_size << " at iteration " << i;
-    }
-    for (size_t i = 0; i < kMaxAllocations; i++) {
-      free(ptrs[i]);
-    }
-  }
-}
-
 TEST(android_mallopt, get_decay_time_enabled_errors) {
 #if defined(__BIONIC__)
   errno = 0;
diff --git a/tests/malloc_test_with_usable_size.cpp b/tests/malloc_test_with_usable_size.cpp
new file mode 100644
index 0000000..fb4fecd
--- /dev/null
+++ b/tests/malloc_test_with_usable_size.cpp
@@ -0,0 +1,671 @@
+/*
+ * Copyright (C) 2025 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+// (b/291762537): This code uses malloc_usable_size(), and thus can't be
+// built with _FORTIFY_SOURCE>=3.
+#if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE >= 3
+#undef _FORTIFY_SOURCE
+#define _FORTIFY_SOURCE 2
+#endif
+
+#include <gtest/gtest.h>
+
+#include <elf.h>
+#include <limits.h>
+#include <malloc.h>
+#include <pthread.h>
+#include <semaphore.h>
+#include <signal.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/auxv.h>
+#include <sys/cdefs.h>
+#include <sys/prctl.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <unistd.h>
+
+#include <algorithm>
+#include <atomic>
+#include <functional>
+#include <string>
+#include <thread>
+#include <unordered_map>
+#include <utility>
+#include <vector>
+
+#include <tinyxml2.h>
+
+#include <android-base/file.h>
+#include <android-base/test_utils.h>
+
+#include "utils.h"
+
+#if defined(__BIONIC__)
+
+#include "SignalUtils.h"
+
+#include "platform/bionic/dlext_namespaces.h"
+#include "platform/bionic/malloc.h"
+#include "platform/bionic/mte.h"
+#include "platform/bionic/reserved_signals.h"
+#include "private/bionic_config.h"
+
+#define HAVE_REALLOCARRAY 1
+
+#elif defined(__GLIBC__)
+
+#define HAVE_REALLOCARRAY __GLIBC_PREREQ(2, 26)
+
+#elif defined(ANDROID_HOST_MUSL)
+
+#define HAVE_REALLOCARRAY 1
+
+#endif
+
+TEST(malloc, malloc_std) {
+  // Simple malloc test.
+  void* ptr = malloc(100);
+  ASSERT_TRUE(ptr != nullptr);
+  ASSERT_LE(100U, malloc_usable_size(ptr));
+  free(ptr);
+}
+
+TEST(malloc, calloc_std) {
+  // Simple calloc test.
+  size_t alloc_len = 100;
+  char* ptr = (char*)calloc(1, alloc_len);
+  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]);
+  }
+  free(ptr);
+}
+
+TEST(malloc, memalign_multiple) {
+  SKIP_WITH_HWASAN << "hwasan requires power of 2 alignment";
+  // Memalign test where the alignment is any value.
+  for (size_t i = 0; i <= 12; i++) {
+    for (size_t alignment = 1 << i; alignment < (1U << (i + 1)); alignment++) {
+      char* ptr = reinterpret_cast<char*>(memalign(alignment, 100));
+      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;
+      free(ptr);
+    }
+  }
+}
+
+TEST(malloc, memalign_realloc) {
+  // 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 != 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 != nullptr);
+    ASSERT_LE(200U, malloc_usable_size(ptr));
+    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 != nullptr);
+    ASSERT_LE(300U, malloc_usable_size(ptr));
+    for (size_t i = 0; i < 200; i++) {
+      ASSERT_EQ(0x45, ptr[i]);
+    }
+    memset(ptr, 0x67, 300);
+
+    ptr = (char*)realloc(ptr, 250);
+    ASSERT_TRUE(ptr != nullptr);
+    ASSERT_LE(250U, malloc_usable_size(ptr));
+    for (size_t i = 0; i < 250; i++) {
+      ASSERT_EQ(0x67, ptr[i]);
+    }
+    free(ptr);
+  }
+}
+
+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 != nullptr);
+  ASSERT_LE(100U, malloc_usable_size(ptr));
+  memset(ptr, 67, 100);
+
+  ptr = (char*)realloc(ptr, 200);
+  ASSERT_TRUE(ptr != nullptr);
+  ASSERT_LE(200U, malloc_usable_size(ptr));
+  for (size_t i = 0; i < 100; i++) {
+    ASSERT_EQ(67, ptr[i]);
+  }
+  free(ptr);
+}
+
+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 != nullptr);
+  ASSERT_LE(200U, malloc_usable_size(ptr));
+  memset(ptr, 67, 200);
+
+  ptr = (char*)realloc(ptr, 100);
+  ASSERT_TRUE(ptr != nullptr);
+  ASSERT_LE(100U, malloc_usable_size(ptr));
+  for (size_t i = 0; i < 100; i++) {
+    ASSERT_EQ(67, ptr[i]);
+  }
+  free(ptr);
+}
+
+TEST(malloc, malloc_multiple_realloc) {
+  // Multiple reallocs, malloc is used for the original allocation.
+  char* ptr = (char*)malloc(200);
+  ASSERT_TRUE(ptr != nullptr);
+  ASSERT_LE(200U, malloc_usable_size(ptr));
+  memset(ptr, 0x23, 200);
+
+  ptr = (char*)realloc(ptr, 100);
+  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 != 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 != nullptr);
+  ASSERT_LE(150U, malloc_usable_size(ptr));
+  for (size_t i = 0; i < 50; i++) {
+    ASSERT_EQ(0x23, ptr[i]);
+  }
+  memset(ptr, 0x23, 150);
+
+  ptr = (char*)realloc(ptr, 425);
+  ASSERT_TRUE(ptr != nullptr);
+  ASSERT_LE(425U, malloc_usable_size(ptr));
+  for (size_t i = 0; i < 150; i++) {
+    ASSERT_EQ(0x23, ptr[i]);
+  }
+  free(ptr);
+}
+
+TEST(malloc, calloc_realloc_larger) {
+  // Realloc to a larger size, calloc is used for the original allocation.
+  char* ptr = (char*)calloc(1, 100);
+  ASSERT_TRUE(ptr != nullptr);
+  ASSERT_LE(100U, malloc_usable_size(ptr));
+
+  ptr = (char*)realloc(ptr, 200);
+  ASSERT_TRUE(ptr != nullptr);
+  ASSERT_LE(200U, malloc_usable_size(ptr));
+  for (size_t i = 0; i < 100; i++) {
+    ASSERT_EQ(0, ptr[i]);
+  }
+  free(ptr);
+}
+
+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 != nullptr);
+  ASSERT_LE(200U, malloc_usable_size(ptr));
+
+  ptr = (char*)realloc(ptr, 100);
+  ASSERT_TRUE(ptr != nullptr);
+  ASSERT_LE(100U, malloc_usable_size(ptr));
+  for (size_t i = 0; i < 100; i++) {
+    ASSERT_EQ(0, ptr[i]);
+  }
+  free(ptr);
+}
+
+TEST(malloc, calloc_multiple_realloc) {
+  // Multiple reallocs, calloc is used for the original allocation.
+  char* ptr = (char*)calloc(1, 200);
+  ASSERT_TRUE(ptr != nullptr);
+  ASSERT_LE(200U, malloc_usable_size(ptr));
+
+  ptr = (char*)realloc(ptr, 100);
+  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 != 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 != nullptr);
+  ASSERT_LE(150U, malloc_usable_size(ptr));
+  for (size_t i = 0; i < 50; i++) {
+    ASSERT_EQ(0, ptr[i]);
+  }
+  memset(ptr, 0, 150);
+
+  ptr = (char*)realloc(ptr, 425);
+  ASSERT_TRUE(ptr != nullptr);
+  ASSERT_LE(425U, malloc_usable_size(ptr));
+  for (size_t i = 0; i < 150; i++) {
+    ASSERT_EQ(0, ptr[i]);
+  }
+  free(ptr);
+}
+
+#if defined(HAVE_DEPRECATED_MALLOC_FUNCS)
+extern "C" void* pvalloc(size_t);
+#endif
+
+TEST(malloc, pvalloc_std) {
+#if defined(HAVE_DEPRECATED_MALLOC_FUNCS)
+  size_t pagesize = sysconf(_SC_PAGESIZE);
+  void* ptr = pvalloc(100);
+  ASSERT_TRUE(ptr != nullptr);
+  ASSERT_TRUE((reinterpret_cast<uintptr_t>(ptr) & (pagesize - 1)) == 0);
+  ASSERT_LE(pagesize, malloc_usable_size(ptr));
+  free(ptr);
+#else
+  GTEST_SKIP() << "pvalloc not supported.";
+#endif
+}
+
+TEST(malloc, calloc_usable_size) {
+  for (size_t size = 1; size <= 2048; size++) {
+    void* pointer = malloc(size);
+    ASSERT_TRUE(pointer != nullptr);
+    memset(pointer, 0xeb, malloc_usable_size(pointer));
+    free(pointer);
+
+    // We should get a previous pointer that has been set to non-zero.
+    // If calloc does not zero out all of the data, this will fail.
+    uint8_t* zero_mem = reinterpret_cast<uint8_t*>(calloc(1, size));
+    ASSERT_TRUE(pointer != nullptr);
+    size_t usable_size = malloc_usable_size(zero_mem);
+    for (size_t i = 0; i < usable_size; i++) {
+      ASSERT_EQ(0, zero_mem[i]) << "Failed at allocation size " << size << " at byte " << i;
+    }
+    free(zero_mem);
+  }
+}
+
+TEST(malloc, reallocarray) {
+#if HAVE_REALLOCARRAY
+  void* p = reallocarray(nullptr, 2, 32);
+  ASSERT_TRUE(p != nullptr);
+  ASSERT_GE(malloc_usable_size(p), 64U);
+#else
+  GTEST_SKIP() << "reallocarray not available";
+#endif
+}
+
+TEST(malloc, mallinfo) {
+#if defined(__BIONIC__) || defined(ANDROID_HOST_MUSL)
+  SKIP_WITH_HWASAN << "hwasan does not implement mallinfo";
+  static size_t sizes[] = {8, 32, 128, 4096, 32768, 131072, 1024000, 10240000, 20480000, 300000000};
+
+  static constexpr size_t kMaxAllocs = 50;
+
+  for (size_t size : sizes) {
+    // If some of these allocations are stuck in a thread cache, then keep
+    // looping until we make an allocation that changes the total size of the
+    // memory allocated.
+    // jemalloc implementations counts the thread cache allocations against
+    // total memory allocated.
+    void* ptrs[kMaxAllocs] = {};
+    bool pass = false;
+    for (size_t i = 0; i < kMaxAllocs; i++) {
+      size_t allocated = mallinfo().uordblks;
+      ptrs[i] = malloc(size);
+      ASSERT_TRUE(ptrs[i] != nullptr);
+      size_t new_allocated = mallinfo().uordblks;
+      if (allocated != new_allocated) {
+        size_t usable_size = malloc_usable_size(ptrs[i]);
+        // Only check if the total got bigger by at least allocation size.
+        // Sometimes the mallinfo numbers can go backwards due to compaction
+        // and/or freeing of cached data.
+        if (new_allocated >= allocated + usable_size) {
+          pass = true;
+          break;
+        }
+      }
+    }
+    for (void* ptr : ptrs) {
+      free(ptr);
+    }
+    ASSERT_TRUE(pass) << "For size " << size << " allocated bytes did not increase after "
+                      << kMaxAllocs << " allocations.";
+  }
+#else
+  GTEST_SKIP() << "glibc is broken";
+#endif
+}
+
+TEST(malloc, mallinfo2) {
+#if defined(__BIONIC__) || defined(ANDROID_HOST_MUSL)
+  SKIP_WITH_HWASAN << "hwasan does not implement mallinfo2";
+  static size_t sizes[] = {8, 32, 128, 4096, 32768, 131072, 1024000, 10240000, 20480000, 300000000};
+
+  static constexpr size_t kMaxAllocs = 50;
+
+  for (size_t size : sizes) {
+    // If some of these allocations are stuck in a thread cache, then keep
+    // looping until we make an allocation that changes the total size of the
+    // memory allocated.
+    // jemalloc implementations counts the thread cache allocations against
+    // total memory allocated.
+    void* ptrs[kMaxAllocs] = {};
+    bool pass = false;
+    for (size_t i = 0; i < kMaxAllocs; i++) {
+      struct mallinfo info = mallinfo();
+      struct mallinfo2 info2 = mallinfo2();
+      // Verify that mallinfo and mallinfo2 are exactly the same.
+      ASSERT_EQ(static_cast<size_t>(info.arena), info2.arena);
+      ASSERT_EQ(static_cast<size_t>(info.ordblks), info2.ordblks);
+      ASSERT_EQ(static_cast<size_t>(info.smblks), info2.smblks);
+      ASSERT_EQ(static_cast<size_t>(info.hblks), info2.hblks);
+      ASSERT_EQ(static_cast<size_t>(info.hblkhd), info2.hblkhd);
+      ASSERT_EQ(static_cast<size_t>(info.usmblks), info2.usmblks);
+      ASSERT_EQ(static_cast<size_t>(info.fsmblks), info2.fsmblks);
+      ASSERT_EQ(static_cast<size_t>(info.uordblks), info2.uordblks);
+      ASSERT_EQ(static_cast<size_t>(info.fordblks), info2.fordblks);
+      ASSERT_EQ(static_cast<size_t>(info.keepcost), info2.keepcost);
+
+      size_t allocated = info2.uordblks;
+      ptrs[i] = malloc(size);
+      ASSERT_TRUE(ptrs[i] != nullptr);
+
+      info = mallinfo();
+      info2 = mallinfo2();
+      // Verify that mallinfo and mallinfo2 are exactly the same.
+      ASSERT_EQ(static_cast<size_t>(info.arena), info2.arena);
+      ASSERT_EQ(static_cast<size_t>(info.ordblks), info2.ordblks);
+      ASSERT_EQ(static_cast<size_t>(info.smblks), info2.smblks);
+      ASSERT_EQ(static_cast<size_t>(info.hblks), info2.hblks);
+      ASSERT_EQ(static_cast<size_t>(info.hblkhd), info2.hblkhd);
+      ASSERT_EQ(static_cast<size_t>(info.usmblks), info2.usmblks);
+      ASSERT_EQ(static_cast<size_t>(info.fsmblks), info2.fsmblks);
+      ASSERT_EQ(static_cast<size_t>(info.uordblks), info2.uordblks);
+      ASSERT_EQ(static_cast<size_t>(info.fordblks), info2.fordblks);
+      ASSERT_EQ(static_cast<size_t>(info.keepcost), info2.keepcost);
+
+      size_t new_allocated = info2.uordblks;
+      if (allocated != new_allocated) {
+        size_t usable_size = malloc_usable_size(ptrs[i]);
+        // Only check if the total got bigger by at least allocation size.
+        // Sometimes the mallinfo2 numbers can go backwards due to compaction
+        // and/or freeing of cached data.
+        if (new_allocated >= allocated + usable_size) {
+          pass = true;
+          break;
+        }
+      }
+    }
+    for (void* ptr : ptrs) {
+      free(ptr);
+    }
+    ASSERT_TRUE(pass) << "For size " << size << " allocated bytes did not increase after "
+                      << kMaxAllocs << " allocations.";
+  }
+#else
+  GTEST_SKIP() << "glibc is broken";
+#endif
+}
+
+// Jemalloc doesn't pass this test right now, so leave it as disabled.
+TEST(malloc, DISABLED_alloc_after_fork) {
+  // Both of these need to be a power of 2.
+  static constexpr size_t kMinAllocationSize = 8;
+  static constexpr size_t kMaxAllocationSize = 2097152;
+
+  static constexpr size_t kNumAllocatingThreads = 5;
+  static constexpr size_t kNumForkLoops = 100;
+
+  std::atomic_bool stop;
+
+  // Create threads that simply allocate and free different sizes.
+  std::vector<std::thread*> threads;
+  for (size_t i = 0; i < kNumAllocatingThreads; i++) {
+    std::thread* t = new std::thread([&stop] {
+      while (!stop) {
+        for (size_t size = kMinAllocationSize; size <= kMaxAllocationSize; size <<= 1) {
+          void* ptr;
+          android::base::DoNotOptimize(ptr = malloc(size));
+          free(ptr);
+        }
+      }
+    });
+    threads.push_back(t);
+  }
+
+  // Create a thread to fork and allocate.
+  for (size_t i = 0; i < kNumForkLoops; i++) {
+    pid_t pid;
+    if ((pid = fork()) == 0) {
+      for (size_t size = kMinAllocationSize; size <= kMaxAllocationSize; size <<= 1) {
+        void* ptr;
+        android::base::DoNotOptimize(ptr = malloc(size));
+        ASSERT_TRUE(ptr != nullptr);
+        // Make sure we can touch all of the allocation.
+        memset(ptr, 0x1, size);
+        ASSERT_LE(size, malloc_usable_size(ptr));
+        free(ptr);
+      }
+      _exit(10);
+    }
+    ASSERT_NE(-1, pid);
+    AssertChildExited(pid, 10);
+  }
+
+  stop = true;
+  for (auto thread : threads) {
+    thread->join();
+    delete thread;
+  }
+}
+
+void VerifyAllocationsAreZero(std::function<void*(size_t)> alloc_func, std::string function_name,
+                              std::vector<size_t>& test_sizes, size_t max_allocations) {
+  // Vector of zero'd data used for comparisons. Make it twice the largest size.
+  std::vector<char> zero(test_sizes.back() * 2, 0);
+
+  SCOPED_TRACE(testing::Message() << function_name << " failed to zero memory");
+
+  for (size_t test_size : test_sizes) {
+    std::vector<void*> ptrs(max_allocations);
+    for (size_t i = 0; i < ptrs.size(); i++) {
+      SCOPED_TRACE(testing::Message() << "size " << test_size << " at iteration " << i);
+      ptrs[i] = alloc_func(test_size);
+      ASSERT_TRUE(ptrs[i] != nullptr);
+      size_t alloc_size = malloc_usable_size(ptrs[i]);
+      ASSERT_LE(alloc_size, zero.size());
+      ASSERT_EQ(0, memcmp(ptrs[i], zero.data(), alloc_size));
+
+      // Set the memory to non-zero to make sure if the pointer
+      // is reused it's still zero.
+      memset(ptrs[i], 0xab, alloc_size);
+    }
+    // Free the pointers.
+    for (size_t i = 0; i < ptrs.size(); i++) {
+      free(ptrs[i]);
+    }
+    for (size_t i = 0; i < ptrs.size(); i++) {
+      SCOPED_TRACE(testing::Message() << "size " << test_size << " at iteration " << i);
+      ptrs[i] = malloc(test_size);
+      ASSERT_TRUE(ptrs[i] != nullptr);
+      size_t alloc_size = malloc_usable_size(ptrs[i]);
+      ASSERT_LE(alloc_size, zero.size());
+      ASSERT_EQ(0, memcmp(ptrs[i], zero.data(), alloc_size));
+    }
+    // Free all of the pointers later to maximize the chance of reusing from
+    // the first loop.
+    for (size_t i = 0; i < ptrs.size(); i++) {
+      free(ptrs[i]);
+    }
+  }
+}
+
+// Verify that small and medium allocations are always zero.
+// @CddTest = 9.7/C-4-1
+TEST(malloc, zeroed_allocations_small_medium_sizes) {
+#if !defined(__BIONIC__)
+  GTEST_SKIP() << "Only valid on bionic";
+#endif
+  SKIP_WITH_HWASAN << "Only test system allocator, not hwasan allocator.";
+
+  if (IsLowRamDevice()) {
+    GTEST_SKIP() << "Skipped on low memory devices.";
+  }
+
+  constexpr size_t kMaxAllocations = 1024;
+  std::vector<size_t> test_sizes = {16, 48, 128, 1024, 4096, 65536};
+  VerifyAllocationsAreZero([](size_t size) -> void* { return malloc(size); }, "malloc", test_sizes,
+                           kMaxAllocations);
+
+  VerifyAllocationsAreZero([](size_t size) -> void* { return memalign(64, size); }, "memalign",
+                           test_sizes, kMaxAllocations);
+
+  VerifyAllocationsAreZero(
+      [](size_t size) -> void* {
+        void* ptr;
+        if (posix_memalign(&ptr, 64, size) == 0) {
+          return ptr;
+        }
+        return nullptr;
+      },
+      "posix_memalign", test_sizes, kMaxAllocations);
+}
+
+// Verify that large allocations are always zero.
+// @CddTest = 9.7/C-4-1
+TEST(malloc, zeroed_allocations_large_sizes) {
+#if !defined(__BIONIC__)
+  GTEST_SKIP() << "Only valid on bionic";
+#endif
+  SKIP_WITH_HWASAN << "Only test system allocator, not hwasan allocator.";
+
+  if (IsLowRamDevice()) {
+    GTEST_SKIP() << "Skipped on low memory devices.";
+  }
+
+  constexpr size_t kMaxAllocations = 20;
+  std::vector<size_t> test_sizes = {1000000, 2000000, 3000000, 4000000};
+  VerifyAllocationsAreZero([](size_t size) -> void* { return malloc(size); }, "malloc", test_sizes,
+                           kMaxAllocations);
+
+  VerifyAllocationsAreZero([](size_t size) -> void* { return memalign(64, size); }, "memalign",
+                           test_sizes, kMaxAllocations);
+
+  VerifyAllocationsAreZero(
+      [](size_t size) -> void* {
+        void* ptr;
+        if (posix_memalign(&ptr, 64, size) == 0) {
+          return ptr;
+        }
+        return nullptr;
+      },
+      "posix_memalign", test_sizes, kMaxAllocations);
+}
+
+// Verify that reallocs are zeroed when expanded.
+// @CddTest = 9.7/C-4-1
+TEST(malloc, zeroed_allocations_realloc) {
+#if !defined(__BIONIC__)
+  GTEST_SKIP() << "Only valid on bionic";
+#endif
+  SKIP_WITH_HWASAN << "Only test system allocator, not hwasan allocator.";
+
+  if (IsLowRamDevice()) {
+    GTEST_SKIP() << "Skipped on low memory devices.";
+  }
+
+  // Vector of zero'd data used for comparisons.
+  constexpr size_t kMaxMemorySize = 131072;
+  std::vector<char> zero(kMaxMemorySize, 0);
+
+  constexpr size_t kMaxAllocations = 1024;
+  std::vector<size_t> test_sizes = {16, 48, 128, 1024, 4096, 65536};
+  // Do a number of allocations and set them to non-zero.
+  for (size_t test_size : test_sizes) {
+    std::vector<void*> ptrs(kMaxAllocations);
+    for (size_t i = 0; i < kMaxAllocations; i++) {
+      ptrs[i] = malloc(test_size);
+      ASSERT_TRUE(ptrs[i] != nullptr);
+
+      // Set the memory to non-zero to make sure if the pointer
+      // is reused it's still zero.
+      memset(ptrs[i], 0xab, malloc_usable_size(ptrs[i]));
+    }
+    // Free the pointers.
+    for (size_t i = 0; i < kMaxAllocations; i++) {
+      free(ptrs[i]);
+    }
+  }
+
+  // Do the reallocs to a larger size and verify the rest of the allocation
+  // is zero.
+  constexpr size_t kInitialSize = 8;
+  for (size_t test_size : test_sizes) {
+    std::vector<void*> ptrs(kMaxAllocations);
+    for (size_t i = 0; i < kMaxAllocations; i++) {
+      ptrs[i] = malloc(kInitialSize);
+      ASSERT_TRUE(ptrs[i] != nullptr);
+      size_t orig_alloc_size = malloc_usable_size(ptrs[i]);
+
+      ptrs[i] = realloc(ptrs[i], test_size);
+      ASSERT_TRUE(ptrs[i] != nullptr);
+      size_t new_alloc_size = malloc_usable_size(ptrs[i]);
+      char* ptr = reinterpret_cast<char*>(ptrs[i]);
+      ASSERT_EQ(0, memcmp(&ptr[orig_alloc_size], zero.data(), new_alloc_size - orig_alloc_size))
+          << "realloc from " << kInitialSize << " to size " << test_size << " at iteration " << i;
+    }
+    for (size_t i = 0; i < kMaxAllocations; i++) {
+      free(ptrs[i]);
+    }
+  }
+}
diff --git a/tests/memtag_stack_test.cpp b/tests/memtag_stack_test.cpp
index 98e340a..02ec014 100644
--- a/tests/memtag_stack_test.cpp
+++ b/tests/memtag_stack_test.cpp
@@ -33,7 +33,7 @@
     GTEST_SKIP() << "MTE unsupported";
   }
   bool is_static = std::get<1>(GetParam());
-  if (running_with_hwasan() && !is_static) {
+  if (android::base::running_with_hwasan() && !is_static) {
     GTEST_SKIP() << "Can't run with HWASanified libc.so";
   }
   std::string helper =
diff --git a/tests/net_if_test.cpp b/tests/net_if_test.cpp
index caaed5f..7b6d2c2 100644
--- a/tests/net_if_test.cpp
+++ b/tests/net_if_test.cpp
@@ -32,10 +32,19 @@
 }
 
 TEST(net_if, if_nametoindex_fail) {
-  unsigned index = if_nametoindex("this-interface-does-not-exist");
+  unsigned index = if_nametoindex("does-not-exist");
   ASSERT_EQ(0U, index);
 }
 
+TEST(net_if, if_nametoindex_too_long) {
+  // We have 16 bytes, but one of them needs to be the '\0'.
+  EXPECT_EQ(16, IFNAMSIZ);
+  const char* name = "01234567890123456";
+  unsigned index = if_nametoindex(name);
+  EXPECT_EQ(0U, index);
+  EXPECT_EQ(ENODEV, errno);
+}
+
 TEST(net_if, if_nameindex) {
   struct if_nameindex* list = if_nameindex();
   ASSERT_TRUE(list != nullptr);
diff --git a/tests/page_size_16kib_compat_test.cpp b/tests/page_size_16kib_compat_test.cpp
index cfd52e2..7aa60fd 100644
--- a/tests/page_size_16kib_compat_test.cpp
+++ b/tests/page_size_16kib_compat_test.cpp
@@ -32,25 +32,79 @@
 
 #include "page_size_compat_helpers.h"
 
+#include <android-base/parsebool.h>
 #include <android-base/properties.h>
+#include <android-base/silent_death_test.h>
+
+using PageSize16KiBCompatTest_DeathTest = SilentDeathTest;
+using ::android::base::ParseBool;
+using ::android::base::ParseBoolResult;
 
 #if defined(IS_ANDROID_DL)
 #include <android/dlext_private.h>
 #endif
 
+static inline std::string CompatMode() {
+  return android::base::GetProperty("bionic.linker.16kb.app_compat.enabled", "false");
+}
+
+static inline bool CompatModeDisabled(const std::string& compat_mode) {
+  return ParseBool(compat_mode) == ParseBoolResult::kFalse;
+}
+
+static inline bool CompatModeEnabled(const std::string& compat_mode) {
+  return ParseBool(compat_mode) == ParseBoolResult::kTrue;
+}
+
+static inline bool CompatModeFatal(const std::string& compat_mode) {
+  return compat_mode == "fatal";
+}
+
+static inline std::string TestLibPath() {
+  return GetTestLibRoot() + "/libtest_elf_max_page_size_4kib.so";
+}
+
 TEST(PageSize16KiBCompatTest, ElfAlignment4KiB_LoadElf) {
   if (getpagesize() != 0x4000) {
     GTEST_SKIP() << "This test is only applicable to 16kB page-size devices";
   }
 
-  bool app_compat_enabled =
-      android::base::GetBoolProperty("bionic.linker.16kb.app_compat.enabled", false);
-  std::string lib = GetTestLibRoot() + "/libtest_elf_max_page_size_4kib.so";
+  std::string compat_mode = CompatMode();
+  if (CompatModeFatal(compat_mode)) {
+    GTEST_SKIP() << "This test is only applicable if dlopen() errors are not fatal";
+  }
+
+  std::string lib = TestLibPath();
   void* handle = nullptr;
 
-  OpenTestLibrary(lib, !app_compat_enabled, &handle);
+  OpenTestLibrary(lib, CompatModeDisabled(compat_mode), &handle);
 
-  if (app_compat_enabled) CallTestFunction(handle);
+  if (CompatModeEnabled(compat_mode)) CallTestFunction(handle);
+}
+
+TEST(PageSize16KiBCompatTest, ElfAlignment4KiB_NonAdajacentWritableSegments_LoadElf) {
+  if (getpagesize() != 0x4000) {
+    GTEST_SKIP() << "This test is only applicable to 16kB page-size devices";
+  }
+
+  std::string lib = GetPrebuiltElfDir() + "/libtest_invalid-rw_rx_rw_load_segments.so";
+  std::string compat_mode = CompatMode();
+  void* handle = nullptr;
+
+  OpenTestLibrary(lib, CompatModeDisabled(compat_mode), &handle);
+}
+
+TEST(PageSize16KiBCompatTest,
+     ElfAlignment4KiB_ExecutalbeSegmentsSeparatedByWritableSegment_LoadElf) {
+  if (getpagesize() != 0x4000) {
+    GTEST_SKIP() << "This test is only applicable to 16kB page-size devices";
+  }
+
+  std::string lib = GetPrebuiltElfDir() + "/libtest_invalid-rw_rx_rw_load_segments.so";
+  std::string compat_mode = CompatMode();
+  void* handle = nullptr;
+
+  OpenTestLibrary(lib, CompatModeDisabled(compat_mode), &handle);
 }
 
 TEST(PageSize16KiBCompatTest, ElfAlignment4KiB_LoadElf_perAppOption) {
@@ -58,11 +112,16 @@
     GTEST_SKIP() << "This test is only applicable to 16kB page-size devices";
   }
 
+  std::string compat_mode = CompatMode();
+  if (CompatModeFatal(compat_mode)) {
+    GTEST_SKIP() << "This test is only applicable if dlopen() errors are not fatal";
+  }
+
 #if defined(IS_ANDROID_DL)
   android_set_16kb_appcompat_mode(true);
 #endif
 
-  std::string lib = GetTestLibRoot() + "/libtest_elf_max_page_size_4kib.so";
+  std::string lib = TestLibPath();
   void* handle = nullptr;
 
   OpenTestLibrary(lib, false /*should_fail*/, &handle);
@@ -72,3 +131,24 @@
   android_set_16kb_appcompat_mode(false);
 #endif
 }
+
+static void FatalDlError() {
+  std::string lib = TestLibPath();
+  void* handle = nullptr;
+
+  OpenTestLibrary(lib, true /*should_fail*/, &handle);
+}
+
+TEST(PageSize16KiBCompatTest_DeathTest, AppDlopenErrIsFatal) {
+  if (getpagesize() != 0x4000) {
+    GTEST_SKIP() << "This test is only applicable to 16kB page-size devices";
+  }
+
+  std::string compat_mode = CompatMode();
+  if (!CompatModeFatal(compat_mode)) {
+    GTEST_SKIP() << "This test is only applicable if dlopen() errors are fatal";
+  }
+
+  ASSERT_DEATH(FatalDlError(),
+               ".*program alignment (.*) cannot be smaller than system page size.*");
+}
diff --git a/tests/prebuilt-elf-files/arm/libtest_empty.so b/tests/prebuilt-elf-files/arm/libtest_empty.so
deleted file mode 100755
index de72522..0000000
--- a/tests/prebuilt-elf-files/arm/libtest_empty.so
+++ /dev/null
Binary files differ
diff --git a/tests/prebuilt-elf-files/arm/libtest_invalid-empty_shdr_table.so b/tests/prebuilt-elf-files/arm/libtest_invalid-empty_shdr_table.so
deleted file mode 100755
index 386f392..0000000
--- a/tests/prebuilt-elf-files/arm/libtest_invalid-empty_shdr_table.so
+++ /dev/null
Binary files differ
diff --git a/tests/prebuilt-elf-files/arm/libtest_invalid-rw_load_segment.so b/tests/prebuilt-elf-files/arm/libtest_invalid-rw_load_segment.so
deleted file mode 100755
index 8e2981b..0000000
--- a/tests/prebuilt-elf-files/arm/libtest_invalid-rw_load_segment.so
+++ /dev/null
Binary files differ
diff --git a/tests/prebuilt-elf-files/arm/libtest_invalid-textrels.so b/tests/prebuilt-elf-files/arm/libtest_invalid-textrels.so
deleted file mode 100755
index 22d42ab..0000000
--- a/tests/prebuilt-elf-files/arm/libtest_invalid-textrels.so
+++ /dev/null
Binary files differ
diff --git a/tests/prebuilt-elf-files/arm/libtest_invalid-textrels2.so b/tests/prebuilt-elf-files/arm/libtest_invalid-textrels2.so
deleted file mode 100755
index 82099f0..0000000
--- a/tests/prebuilt-elf-files/arm/libtest_invalid-textrels2.so
+++ /dev/null
Binary files differ
diff --git a/tests/prebuilt-elf-files/arm/libtest_invalid-unaligned_shdr_offset.so b/tests/prebuilt-elf-files/arm/libtest_invalid-unaligned_shdr_offset.so
deleted file mode 100755
index c2bfada..0000000
--- a/tests/prebuilt-elf-files/arm/libtest_invalid-unaligned_shdr_offset.so
+++ /dev/null
Binary files differ
diff --git a/tests/prebuilt-elf-files/arm/libtest_invalid-zero_shdr_table_content.so b/tests/prebuilt-elf-files/arm/libtest_invalid-zero_shdr_table_content.so
deleted file mode 100755
index cc4bbca..0000000
--- a/tests/prebuilt-elf-files/arm/libtest_invalid-zero_shdr_table_content.so
+++ /dev/null
Binary files differ
diff --git a/tests/prebuilt-elf-files/arm/libtest_invalid-zero_shdr_table_offset.so b/tests/prebuilt-elf-files/arm/libtest_invalid-zero_shdr_table_offset.so
deleted file mode 100755
index 9858c26..0000000
--- a/tests/prebuilt-elf-files/arm/libtest_invalid-zero_shdr_table_offset.so
+++ /dev/null
Binary files differ
diff --git a/tests/prebuilt-elf-files/arm/libtest_invalid-zero_shentsize.so b/tests/prebuilt-elf-files/arm/libtest_invalid-zero_shentsize.so
deleted file mode 100755
index e84b0c1..0000000
--- a/tests/prebuilt-elf-files/arm/libtest_invalid-zero_shentsize.so
+++ /dev/null
Binary files differ
diff --git a/tests/prebuilt-elf-files/arm/libtest_invalid-zero_shstrndx.so b/tests/prebuilt-elf-files/arm/libtest_invalid-zero_shstrndx.so
deleted file mode 100755
index c699ef9..0000000
--- a/tests/prebuilt-elf-files/arm/libtest_invalid-zero_shstrndx.so
+++ /dev/null
Binary files differ
diff --git a/tests/prebuilt-elf-files/arm64/libtest_empty.so b/tests/prebuilt-elf-files/arm64/libtest_empty.so
deleted file mode 100755
index 76c569b..0000000
--- a/tests/prebuilt-elf-files/arm64/libtest_empty.so
+++ /dev/null
Binary files differ
diff --git a/tests/prebuilt-elf-files/arm64/libtest_invalid-empty_shdr_table.so b/tests/prebuilt-elf-files/arm64/libtest_invalid-empty_shdr_table.so
deleted file mode 100755
index 21a8f26..0000000
--- a/tests/prebuilt-elf-files/arm64/libtest_invalid-empty_shdr_table.so
+++ /dev/null
Binary files differ
diff --git a/tests/prebuilt-elf-files/arm64/libtest_invalid-rw_load_segment.so b/tests/prebuilt-elf-files/arm64/libtest_invalid-rw_load_segment.so
deleted file mode 100755
index 46af37f..0000000
--- a/tests/prebuilt-elf-files/arm64/libtest_invalid-rw_load_segment.so
+++ /dev/null
Binary files differ
diff --git a/tests/prebuilt-elf-files/arm64/libtest_invalid-textrels.so b/tests/prebuilt-elf-files/arm64/libtest_invalid-textrels.so
deleted file mode 100755
index c60b0d6..0000000
--- a/tests/prebuilt-elf-files/arm64/libtest_invalid-textrels.so
+++ /dev/null
Binary files differ
diff --git a/tests/prebuilt-elf-files/arm64/libtest_invalid-textrels2.so b/tests/prebuilt-elf-files/arm64/libtest_invalid-textrels2.so
deleted file mode 100755
index eb33692..0000000
--- a/tests/prebuilt-elf-files/arm64/libtest_invalid-textrels2.so
+++ /dev/null
Binary files differ
diff --git a/tests/prebuilt-elf-files/arm64/libtest_invalid-unaligned_shdr_offset.so b/tests/prebuilt-elf-files/arm64/libtest_invalid-unaligned_shdr_offset.so
deleted file mode 100755
index fb86bca..0000000
--- a/tests/prebuilt-elf-files/arm64/libtest_invalid-unaligned_shdr_offset.so
+++ /dev/null
Binary files differ
diff --git a/tests/prebuilt-elf-files/arm64/libtest_invalid-zero_shdr_table_content.so b/tests/prebuilt-elf-files/arm64/libtest_invalid-zero_shdr_table_content.so
deleted file mode 100755
index 0416db2..0000000
--- a/tests/prebuilt-elf-files/arm64/libtest_invalid-zero_shdr_table_content.so
+++ /dev/null
Binary files differ
diff --git a/tests/prebuilt-elf-files/arm64/libtest_invalid-zero_shdr_table_offset.so b/tests/prebuilt-elf-files/arm64/libtest_invalid-zero_shdr_table_offset.so
deleted file mode 100755
index 90892a6..0000000
--- a/tests/prebuilt-elf-files/arm64/libtest_invalid-zero_shdr_table_offset.so
+++ /dev/null
Binary files differ
diff --git a/tests/prebuilt-elf-files/arm64/libtest_invalid-zero_shentsize.so b/tests/prebuilt-elf-files/arm64/libtest_invalid-zero_shentsize.so
deleted file mode 100755
index c186b1d..0000000
--- a/tests/prebuilt-elf-files/arm64/libtest_invalid-zero_shentsize.so
+++ /dev/null
Binary files differ
diff --git a/tests/prebuilt-elf-files/arm64/libtest_invalid-zero_shstrndx.so b/tests/prebuilt-elf-files/arm64/libtest_invalid-zero_shstrndx.so
deleted file mode 100755
index 857f702..0000000
--- a/tests/prebuilt-elf-files/arm64/libtest_invalid-zero_shstrndx.so
+++ /dev/null
Binary files differ
diff --git a/tests/prebuilt-elf-files/riscv64/libtest_empty.so b/tests/prebuilt-elf-files/riscv64/libtest_empty.so
deleted file mode 100755
index f3218f7..0000000
--- a/tests/prebuilt-elf-files/riscv64/libtest_empty.so
+++ /dev/null
Binary files differ
diff --git a/tests/prebuilt-elf-files/riscv64/libtest_invalid-empty_shdr_table.so b/tests/prebuilt-elf-files/riscv64/libtest_invalid-empty_shdr_table.so
deleted file mode 100755
index 9f15ff9..0000000
--- a/tests/prebuilt-elf-files/riscv64/libtest_invalid-empty_shdr_table.so
+++ /dev/null
Binary files differ
diff --git a/tests/prebuilt-elf-files/riscv64/libtest_invalid-rw_load_segment.so b/tests/prebuilt-elf-files/riscv64/libtest_invalid-rw_load_segment.so
deleted file mode 100755
index 32db3b9..0000000
--- a/tests/prebuilt-elf-files/riscv64/libtest_invalid-rw_load_segment.so
+++ /dev/null
Binary files differ
diff --git a/tests/prebuilt-elf-files/riscv64/libtest_invalid-textrels.so b/tests/prebuilt-elf-files/riscv64/libtest_invalid-textrels.so
deleted file mode 100755
index 5ee9aab..0000000
--- a/tests/prebuilt-elf-files/riscv64/libtest_invalid-textrels.so
+++ /dev/null
Binary files differ
diff --git a/tests/prebuilt-elf-files/riscv64/libtest_invalid-textrels2.so b/tests/prebuilt-elf-files/riscv64/libtest_invalid-textrels2.so
deleted file mode 100755
index 664d3df..0000000
--- a/tests/prebuilt-elf-files/riscv64/libtest_invalid-textrels2.so
+++ /dev/null
Binary files differ
diff --git a/tests/prebuilt-elf-files/riscv64/libtest_invalid-unaligned_shdr_offset.so b/tests/prebuilt-elf-files/riscv64/libtest_invalid-unaligned_shdr_offset.so
deleted file mode 100755
index 3e773c0..0000000
--- a/tests/prebuilt-elf-files/riscv64/libtest_invalid-unaligned_shdr_offset.so
+++ /dev/null
Binary files differ
diff --git a/tests/prebuilt-elf-files/riscv64/libtest_invalid-zero_shdr_table_content.so b/tests/prebuilt-elf-files/riscv64/libtest_invalid-zero_shdr_table_content.so
deleted file mode 100755
index d3bcd9a..0000000
--- a/tests/prebuilt-elf-files/riscv64/libtest_invalid-zero_shdr_table_content.so
+++ /dev/null
Binary files differ
diff --git a/tests/prebuilt-elf-files/riscv64/libtest_invalid-zero_shdr_table_offset.so b/tests/prebuilt-elf-files/riscv64/libtest_invalid-zero_shdr_table_offset.so
deleted file mode 100755
index 956dca8..0000000
--- a/tests/prebuilt-elf-files/riscv64/libtest_invalid-zero_shdr_table_offset.so
+++ /dev/null
Binary files differ
diff --git a/tests/prebuilt-elf-files/riscv64/libtest_invalid-zero_shentsize.so b/tests/prebuilt-elf-files/riscv64/libtest_invalid-zero_shentsize.so
deleted file mode 100755
index e663dae..0000000
--- a/tests/prebuilt-elf-files/riscv64/libtest_invalid-zero_shentsize.so
+++ /dev/null
Binary files differ
diff --git a/tests/prebuilt-elf-files/riscv64/libtest_invalid-zero_shstrndx.so b/tests/prebuilt-elf-files/riscv64/libtest_invalid-zero_shstrndx.so
deleted file mode 100755
index 294f854..0000000
--- a/tests/prebuilt-elf-files/riscv64/libtest_invalid-zero_shstrndx.so
+++ /dev/null
Binary files differ
diff --git a/tests/prebuilt-elf-files/x86/libtest_empty.so b/tests/prebuilt-elf-files/x86/libtest_empty.so
deleted file mode 100755
index 7369b05..0000000
--- a/tests/prebuilt-elf-files/x86/libtest_empty.so
+++ /dev/null
Binary files differ
diff --git a/tests/prebuilt-elf-files/x86/libtest_invalid-empty_shdr_table.so b/tests/prebuilt-elf-files/x86/libtest_invalid-empty_shdr_table.so
deleted file mode 100755
index 7cbe6f3..0000000
--- a/tests/prebuilt-elf-files/x86/libtest_invalid-empty_shdr_table.so
+++ /dev/null
Binary files differ
diff --git a/tests/prebuilt-elf-files/x86/libtest_invalid-rw_load_segment.so b/tests/prebuilt-elf-files/x86/libtest_invalid-rw_load_segment.so
deleted file mode 100755
index 81672a7..0000000
--- a/tests/prebuilt-elf-files/x86/libtest_invalid-rw_load_segment.so
+++ /dev/null
Binary files differ
diff --git a/tests/prebuilt-elf-files/x86/libtest_invalid-textrels.so b/tests/prebuilt-elf-files/x86/libtest_invalid-textrels.so
deleted file mode 100755
index 0e858ed..0000000
--- a/tests/prebuilt-elf-files/x86/libtest_invalid-textrels.so
+++ /dev/null
Binary files differ
diff --git a/tests/prebuilt-elf-files/x86/libtest_invalid-textrels2.so b/tests/prebuilt-elf-files/x86/libtest_invalid-textrels2.so
deleted file mode 100755
index 09b767e..0000000
--- a/tests/prebuilt-elf-files/x86/libtest_invalid-textrels2.so
+++ /dev/null
Binary files differ
diff --git a/tests/prebuilt-elf-files/x86/libtest_invalid-unaligned_shdr_offset.so b/tests/prebuilt-elf-files/x86/libtest_invalid-unaligned_shdr_offset.so
deleted file mode 100755
index a493ad0..0000000
--- a/tests/prebuilt-elf-files/x86/libtest_invalid-unaligned_shdr_offset.so
+++ /dev/null
Binary files differ
diff --git a/tests/prebuilt-elf-files/x86/libtest_invalid-zero_shdr_table_content.so b/tests/prebuilt-elf-files/x86/libtest_invalid-zero_shdr_table_content.so
deleted file mode 100755
index 2cc7723..0000000
--- a/tests/prebuilt-elf-files/x86/libtest_invalid-zero_shdr_table_content.so
+++ /dev/null
Binary files differ
diff --git a/tests/prebuilt-elf-files/x86/libtest_invalid-zero_shdr_table_offset.so b/tests/prebuilt-elf-files/x86/libtest_invalid-zero_shdr_table_offset.so
deleted file mode 100755
index e9d4c54..0000000
--- a/tests/prebuilt-elf-files/x86/libtest_invalid-zero_shdr_table_offset.so
+++ /dev/null
Binary files differ
diff --git a/tests/prebuilt-elf-files/x86/libtest_invalid-zero_shentsize.so b/tests/prebuilt-elf-files/x86/libtest_invalid-zero_shentsize.so
deleted file mode 100755
index 1c6f58e..0000000
--- a/tests/prebuilt-elf-files/x86/libtest_invalid-zero_shentsize.so
+++ /dev/null
Binary files differ
diff --git a/tests/prebuilt-elf-files/x86/libtest_invalid-zero_shstrndx.so b/tests/prebuilt-elf-files/x86/libtest_invalid-zero_shstrndx.so
deleted file mode 100755
index 1a3b3a7..0000000
--- a/tests/prebuilt-elf-files/x86/libtest_invalid-zero_shstrndx.so
+++ /dev/null
Binary files differ
diff --git a/tests/prebuilt-elf-files/x86_64/libtest_empty.so b/tests/prebuilt-elf-files/x86_64/libtest_empty.so
deleted file mode 100755
index ce519b2..0000000
--- a/tests/prebuilt-elf-files/x86_64/libtest_empty.so
+++ /dev/null
Binary files differ
diff --git a/tests/prebuilt-elf-files/x86_64/libtest_invalid-empty_shdr_table.so b/tests/prebuilt-elf-files/x86_64/libtest_invalid-empty_shdr_table.so
deleted file mode 100755
index 00fefd4..0000000
--- a/tests/prebuilt-elf-files/x86_64/libtest_invalid-empty_shdr_table.so
+++ /dev/null
Binary files differ
diff --git a/tests/prebuilt-elf-files/x86_64/libtest_invalid-rw_load_segment.so b/tests/prebuilt-elf-files/x86_64/libtest_invalid-rw_load_segment.so
deleted file mode 100755
index 9d2c5f1..0000000
--- a/tests/prebuilt-elf-files/x86_64/libtest_invalid-rw_load_segment.so
+++ /dev/null
Binary files differ
diff --git a/tests/prebuilt-elf-files/x86_64/libtest_invalid-textrels.so b/tests/prebuilt-elf-files/x86_64/libtest_invalid-textrels.so
deleted file mode 100755
index f231d11..0000000
--- a/tests/prebuilt-elf-files/x86_64/libtest_invalid-textrels.so
+++ /dev/null
Binary files differ
diff --git a/tests/prebuilt-elf-files/x86_64/libtest_invalid-textrels2.so b/tests/prebuilt-elf-files/x86_64/libtest_invalid-textrels2.so
deleted file mode 100755
index 97fb5c4..0000000
--- a/tests/prebuilt-elf-files/x86_64/libtest_invalid-textrels2.so
+++ /dev/null
Binary files differ
diff --git a/tests/prebuilt-elf-files/x86_64/libtest_invalid-unaligned_shdr_offset.so b/tests/prebuilt-elf-files/x86_64/libtest_invalid-unaligned_shdr_offset.so
deleted file mode 100755
index f9c310f..0000000
--- a/tests/prebuilt-elf-files/x86_64/libtest_invalid-unaligned_shdr_offset.so
+++ /dev/null
Binary files differ
diff --git a/tests/prebuilt-elf-files/x86_64/libtest_invalid-zero_shdr_table_content.so b/tests/prebuilt-elf-files/x86_64/libtest_invalid-zero_shdr_table_content.so
deleted file mode 100755
index 3d1f5d3..0000000
--- a/tests/prebuilt-elf-files/x86_64/libtest_invalid-zero_shdr_table_content.so
+++ /dev/null
Binary files differ
diff --git a/tests/prebuilt-elf-files/x86_64/libtest_invalid-zero_shdr_table_offset.so b/tests/prebuilt-elf-files/x86_64/libtest_invalid-zero_shdr_table_offset.so
deleted file mode 100755
index aeea1d2..0000000
--- a/tests/prebuilt-elf-files/x86_64/libtest_invalid-zero_shdr_table_offset.so
+++ /dev/null
Binary files differ
diff --git a/tests/prebuilt-elf-files/x86_64/libtest_invalid-zero_shentsize.so b/tests/prebuilt-elf-files/x86_64/libtest_invalid-zero_shentsize.so
deleted file mode 100755
index 8146676..0000000
--- a/tests/prebuilt-elf-files/x86_64/libtest_invalid-zero_shentsize.so
+++ /dev/null
Binary files differ
diff --git a/tests/prebuilt-elf-files/x86_64/libtest_invalid-zero_shstrndx.so b/tests/prebuilt-elf-files/x86_64/libtest_invalid-zero_shstrndx.so
deleted file mode 100755
index 4ac70f7..0000000
--- a/tests/prebuilt-elf-files/x86_64/libtest_invalid-zero_shstrndx.so
+++ /dev/null
Binary files differ
diff --git a/tests/pthread_test.cpp b/tests/pthread_test.cpp
index 680ef6e..ced67f3 100644
--- a/tests/pthread_test.cpp
+++ b/tests/pthread_test.cpp
@@ -47,6 +47,7 @@
 #include "private/bionic_constants.h"
 #include "private/bionic_time_conversions.h"
 #include "SignalUtils.h"
+#include "sme_utils.h"
 #include "utils.h"
 
 using pthread_DeathTest = SilentDeathTest;
@@ -3206,3 +3207,49 @@
   // but it ought to be safe to ask for the same affinity you already have.
   ASSERT_EQ(0, pthread_setaffinity_np(pthread_self(), sizeof(set), &set));
 }
+
+#if defined(__aarch64__)
+
+static void* sme_state_checking_thread(void*) {
+  // Expected state in the child thread:
+  //  - PSTATE.SM is 0
+  //  - PSTATE.ZA is 0
+  //  - TPIDR2_EL0 is 0
+  EXPECT_FALSE(sme_is_sm_on());
+  EXPECT_FALSE(sme_is_za_on());
+  EXPECT_EQ(0UL, sme_tpidr2_el0());
+
+  return nullptr;
+}
+
+static void create_thread() {
+  pthread_t thread;
+  // Even if these asserts fail sme_state_cleanup() will still be run.
+  ASSERT_EQ(0, pthread_create(&thread, nullptr, &sme_state_checking_thread, nullptr));
+  ASSERT_EQ(0, pthread_join(thread, nullptr));
+}
+
+// It is expected that the new thread is started with SME off.
+TEST(pthread, pthread_create_with_sme_off) {
+  if (!sme_is_enabled()) {
+    GTEST_SKIP() << "FEAT_SME is not enabled on the device.";
+  }
+
+  // It is safe to call __arm_za_disable(). This is required to avoid inter-test dependencies.
+  __arm_za_disable();
+  create_thread();
+  sme_state_cleanup();
+}
+
+// It is expected that the new thread is started with SME off.
+TEST(pthread, pthread_create_with_sme_dormant_state) {
+  if (!sme_is_enabled()) {
+    GTEST_SKIP() << "FEAT_SME is not enabled on the device.";
+  }
+
+  __arm_za_disable();
+  sme_dormant_caller(&create_thread);
+  sme_state_cleanup();
+}
+
+#endif  // defined(__aarch64__)
diff --git a/tests/setjmp_test.cpp b/tests/setjmp_test.cpp
index 836aadc..454390e 100644
--- a/tests/setjmp_test.cpp
+++ b/tests/setjmp_test.cpp
@@ -26,6 +26,7 @@
 #include <android-base/test_utils.h>
 
 #include "SignalUtils.h"
+#include "sme_utils.h"
 
 using setjmp_DeathTest = SilentDeathTest;
 
@@ -368,39 +369,35 @@
 
 #if defined(__aarch64__)
 TEST(setjmp, sigsetjmp_sme) {
-  if (!(getauxval(AT_HWCAP2) & HWCAP2_SME)) {
+  if (!sme_is_enabled()) {
     GTEST_SKIP() << "SME is not enabled on device.";
   }
 
-  uint64_t svcr, za_state;
   sigjmp_buf jb;
-  __asm__ __volatile__(".arch_extension sme; smstart za");
+  sme_enable_za();
   sigsetjmp(jb, 0);
-  __asm__ __volatile__(".arch_extension sme; mrs %0, SVCR" : "=r"(svcr));
-  __asm__ __volatile__(".arch_extension sme; smstop za");  // Turn ZA off anyway.
-  za_state = svcr & 0x2UL;
-  ASSERT_EQ(0UL, za_state);
+  bool za_state = sme_is_za_on();
+  sme_disable_za();  // Turn ZA off anyway.
+  ASSERT_FALSE(za_state);
 }
 
 TEST(setjmp, siglongjmp_sme) {
-  if (!(getauxval(AT_HWCAP2) & HWCAP2_SME)) {
+  if (!sme_is_enabled()) {
     GTEST_SKIP() << "SME is not enabled on device.";
   }
 
-  uint64_t svcr, za_state;
   int value;
   sigjmp_buf jb;
   if ((value = sigsetjmp(jb, 0)) == 0) {
-    __asm__ __volatile__(".arch_extension sme; smstart za");
+    sme_enable_za();
     siglongjmp(jb, 789);
-    __asm__ __volatile__(".arch_extension sme; smstop za");
+    sme_disable_za();
     FAIL();  // Unreachable.
   } else {
-    __asm__ __volatile__(".arch_extension sme; mrs %0, SVCR" : "=r"(svcr));
-    __asm__ __volatile__(".arch_extension sme; smstop za");  // Turn ZA off anyway.
-    za_state = svcr & 0x2UL;
+    bool za_state = sme_is_za_on();
+    sme_disable_za();  // Turn ZA off anyway.
     ASSERT_EQ(789, value);
-    ASSERT_EQ(0UL, za_state);
+    ASSERT_FALSE(za_state);
   }
 }
 #endif
diff --git a/tests/signal_test.cpp b/tests/signal_test.cpp
index 27f5c6c..d9bfa78 100644
--- a/tests/signal_test.cpp
+++ b/tests/signal_test.cpp
@@ -26,11 +26,13 @@
 #include <thread>
 
 #include <android-base/macros.h>
+#include <android-base/test_utils.h>
 #include <android-base/threads.h>
 
 #include <gtest/gtest.h>
 
 #include "SignalUtils.h"
+#include "sme_utils.h"
 #include "utils.h"
 
 using namespace std::chrono_literals;
@@ -1073,29 +1075,28 @@
 }
 
 #if defined(__aarch64__)
-__attribute__((target("arch=armv9+sme"))) __arm_new("za") static void FunctionUsingZA() {
+static void raises_sigusr1() {
   raise(SIGUSR1);
 }
 
 TEST(signal, sme_tpidr2_clear) {
   // When using SME, on entering a signal handler the kernel should clear TPIDR2_EL0, but this was
   // not always correctly done. This tests checks if the kernel correctly clears it or not.
-  if (!(getauxval(AT_HWCAP2) & HWCAP2_SME)) {
+  if (!sme_is_enabled()) {
     GTEST_SKIP() << "SME is not enabled on device.";
   }
 
   static uint64_t tpidr2 = 0;
   struct sigaction handler = {};
   handler.sa_sigaction = [](int, siginfo_t*, void*) {
-    uint64_t zero = 0;
-    __asm__ __volatile__(".arch_extension sme; mrs %0, TPIDR2_EL0" : "=r"(tpidr2));
-    __asm__ __volatile__(".arch_extension sme; msr TPIDR2_EL0, %0" : : "r"(zero));  // Clear TPIDR2.
+    tpidr2 = sme_tpidr2_el0();
+    sme_set_tpidr2_el0(0UL);
   };
   handler.sa_flags = SA_SIGINFO;
 
   ASSERT_EQ(0, sigaction(SIGUSR1, &handler, nullptr));
 
-  FunctionUsingZA();
+  sme_dormant_caller(&raises_sigusr1);
 
   ASSERT_EQ(0x0UL, tpidr2)
       << "Broken kernel! TPIDR2_EL0 was not null in the signal handler! "
@@ -1103,3 +1104,42 @@
       << "https://lore.kernel.org/linux-arm-kernel/20250417190113.3778111-1-mark.rutland@arm.com/";
 }
 #endif
+
+TEST(signal, psignal) {
+  CapturedStderr cap;
+  psignal(SIGINT, "a b c");
+  ASSERT_EQ(cap.str(), "a b c: Interrupt\n");
+}
+
+TEST(signal, psignal_null) {
+  CapturedStderr cap;
+  psignal(SIGINT, nullptr);
+  ASSERT_EQ(cap.str(), "Interrupt\n");
+}
+
+TEST(signal, psignal_empty) {
+  CapturedStderr cap;
+  psignal(SIGINT, "");
+  ASSERT_EQ(cap.str(), "Interrupt\n");
+}
+
+TEST(signal, psiginfo) {
+  CapturedStderr cap;
+  siginfo_t si{.si_signo = SIGINT};
+  psiginfo(&si, "a b c");
+  ASSERT_EQ(cap.str(), "a b c: Interrupt\n");
+}
+
+TEST(signal, psiginfo_null) {
+  CapturedStderr cap;
+  siginfo_t si{.si_signo = SIGINT};
+  psiginfo(&si, nullptr);
+  ASSERT_EQ(cap.str(), "Interrupt\n");
+}
+
+TEST(signal, psiginfo_empty) {
+  CapturedStderr cap;
+  siginfo_t si{.si_signo = SIGINT};
+  psiginfo(&si, "");
+  ASSERT_EQ(cap.str(), "Interrupt\n");
+}
diff --git a/tests/sme_utils.h b/tests/sme_utils.h
new file mode 100644
index 0000000..08b86f1
--- /dev/null
+++ b/tests/sme_utils.h
@@ -0,0 +1,147 @@
+/*
+ * Copyright (C) 2025 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include <sys/auxv.h>
+
+#include <cstdint>
+
+#if defined(__aarch64__)
+
+#include <arm_sme.h>
+
+// Detects whether FEAT_SME is available.
+//
+// FEAT_SME is optional from Armv9.2.
+[[maybe_unused]] static bool sme_is_enabled() {
+  return ((getauxval(AT_HWCAP2) & HWCAP2_SME) != 0);
+}
+
+// Sets PSTATE.SM to 0.
+//
+// Requires FEAT_SME, which is optional from Armv9.2.
+[[maybe_unused]] __attribute__((naked)) static void sme_disable_sm() {
+  __asm__ __volatile__(".arch_extension sme; bti c; smstop sm; ret;");
+}
+
+// Sets PSTATE.ZA to 1.
+//
+// Requires FEAT_SME, which is optional from Armv9.2.
+[[maybe_unused]] __attribute__((naked)) static void sme_enable_za() {
+  __asm__ __volatile__(".arch_extension sme; bti c; smstart za; ret;");
+}
+
+// Sets PSTATE.ZA to 0.
+//
+// Requires FEAT_SME, which is optional from Armv9.2.
+[[maybe_unused]] __attribute__((naked)) static void sme_disable_za() {
+  __asm__ __volatile__(".arch_extension sme; bti c; smstop za; ret;");
+}
+
+// Sets TPIDR2_EL0 to a given value.
+//
+// Requires FEAT_SME, which is optional from Armv9.2.
+[[maybe_unused]] __attribute__((naked)) static void sme_set_tpidr2_el0(uint64_t value) {
+  __asm__ __volatile__(".arch_extension sme; bti c; msr TPIDR2_EL0, x0; ret;");
+}
+
+// Reads TPIDR2_EL0 and returns its value.
+//
+// Requires FEAT_SME, which is optional from Armv9.2.
+[[maybe_unused]] __attribute__((naked)) static uint64_t sme_tpidr2_el0() {
+  __asm__ __volatile__(".arch_extension sme; bti c; mrs x0, TPIDR2_EL0; ret;");
+}
+
+// Reads SVCR special register.
+//
+// Requires FEAT_SME, which is optional from Armv9.2.
+[[maybe_unused]] __attribute__((naked)) static uint64_t sme_read_svcr() {
+  __asm__ __volatile__(".arch_extension sme; bti c; mrs x0, SVCR; ret;");
+}
+
+// Returns true if PSTATE.SM is 1, otherwise false.
+//
+// Requires FEAT_SME, which is optional from Armv9.2.
+[[maybe_unused]] static bool sme_is_sm_on() {
+  static constexpr uint64_t kSvcrSmMask = 0x01UL;
+  return ((sme_read_svcr() & kSvcrSmMask) != 0);
+}
+
+// Returns true if PSTATE.ZA is 1, otherwise false.
+//
+// Requires FEAT_SME, which is optional from Armv9.2.
+[[maybe_unused]] static bool sme_is_za_on() {
+  static constexpr uint64_t kSvcrZaMask = 0x02UL;
+  return ((sme_read_svcr() & kSvcrZaMask) != 0);
+}
+
+// Assembly is required to ensure the test does not depend on compiler optimizations.
+[[maybe_unused]] __attribute__((naked)) static void sme_dormant_caller(void (*fn_address)()) {
+  // clang-format off
+  __asm__ __volatile__(
+    ".arch_extension sme\n\r"
+    "bti      c\n\r"
+    "stp      fp, lr, [sp, #-16]!\n\r"
+    "mov      fp, sp\n\r"
+    // Set up a lazy-save buffer on the stack.
+    // It is 16 bytes + size according to VL.
+    "sub      sp, sp, #16\n\r"
+    "rdsvl    x8, #1\n\r"
+    "mul      x9, x8, x8\n\r"
+    "sub      sp, sp, x9\n\r"
+    "mov      x9, sp\n\r"
+    // Bytes 0-7: za_save_buffer
+    // Bytes 8-9: num_za_save_slices
+    // Other bytes are cleared.
+    "stp      x9, x8, [fp, #-16]\n\r"
+    // Finalize the lazy-save buffer.
+    "msr      TPIDR2_EL0, x9\n\r"
+    // Call the given function with dormant SME state.
+    "smstart  za\n\r"
+    "blr      x0\n\r"
+    // Set SME state to off.
+    "msr      TPIDR2_EL0, xzr\n\r"
+    "smstop   za\n\r"
+    "mov      sp, fp\n\r"
+    "ldp      fp, lr, [sp], #16\n\r"
+    "ret\n\r"
+  );
+  // clang-format on
+}
+
+// Turns all SME state off.
+//
+// Requires FEAT_SME, which is optional from Armv9.2.
+[[maybe_unused]] static void sme_state_cleanup() {
+  sme_disable_sm();
+  sme_set_tpidr2_el0(0UL);
+  sme_disable_za();
+}
+
+#endif  // defined(__aarch64__)
diff --git a/tests/spawn_test.cpp b/tests/spawn_test.cpp
index ab3e877..0bef16f 100644
--- a/tests/spawn_test.cpp
+++ b/tests/spawn_test.cpp
@@ -249,10 +249,10 @@
   ASSERT_EQ(0, posix_spawn_file_actions_addopen(&fa, 56, "/proc/version", O_RDONLY, 0));
   // Test addfchdir by opening the same file a second way...
   ASSERT_EQ(0, posix_spawn_file_actions_addopen(&fa, 57, "/proc", O_PATH, 0));
-  ASSERT_EQ(0, posix_spawn_file_actions_addfchdir_np(&fa, 57));
+  ASSERT_EQ(0, posix_spawn_file_actions_addfchdir(&fa, 57));
   ASSERT_EQ(0, posix_spawn_file_actions_addopen(&fa, 58, "version", O_RDONLY, 0));
   // Test addchdir by opening the same file a third way...
-  ASSERT_EQ(0, posix_spawn_file_actions_addchdir_np(&fa, "/"));
+  ASSERT_EQ(0, posix_spawn_file_actions_addchdir(&fa, "/"));
   ASSERT_EQ(0, posix_spawn_file_actions_addopen(&fa, 59, "proc/version", O_RDONLY, 0));
 
   ExecTestHelper eth;
diff --git a/tests/static_tls_layout_test.cpp b/tests/static_tls_layout_test.cpp
index ada29a5..992b2ce 100644
--- a/tests/static_tls_layout_test.cpp
+++ b/tests/static_tls_layout_test.cpp
@@ -163,8 +163,8 @@
 
   // Amount of memory needed for negative TLS slots, given a segment p_align of
   // 8 or 16 words.
-  const size_t base8 = __BIONIC_ALIGN(-MIN_TLS_SLOT, 8) * sizeof(void*);
-  const size_t base16 = __BIONIC_ALIGN(-MIN_TLS_SLOT, 16) * sizeof(void*);
+  const size_t base8 = __builtin_align_up(-MIN_TLS_SLOT, 8) * sizeof(void*);
+  const size_t base16 = __builtin_align_up(-MIN_TLS_SLOT, 16) * sizeof(void*);
 
   StaticTlsLayout layout;
 
diff --git a/tests/stdatomic_test.cpp b/tests/stdatomic_test.cpp
index 23e9b3e..a56e953 100644
--- a/tests/stdatomic_test.cpp
+++ b/tests/stdatomic_test.cpp
@@ -23,7 +23,14 @@
 // This doesn't entirely work because gtest also (transitively) pulls in <atomic>.
 // It's not clear there's a good fix for this,
 // other than switching to a non-C++ unit test framework for bionic.
+// Bionic has <stdatomic.h>, which includes <bits/stdatomic.h>, but GCC and
+// Clang only provide <stdatomic.h>, so only include <bits/stdatomic.h> when it
+// exists. That is, include <bits/stdatomic.h> for bionic but not for glibc.
+#if __has_include(<bits/stdatomic.h>)
 #include <bits/stdatomic.h>
+#else
+#include <stdatomic.h>
+#endif
 
 #include <pthread.h>
 #include <stdint.h>
diff --git a/tests/stdbit_test.cpp b/tests/stdbit_test.cpp
new file mode 100644
index 0000000..136e9f2
--- /dev/null
+++ b/tests/stdbit_test.cpp
@@ -0,0 +1,388 @@
+/*
+ * Copyright (C) 2025 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+
+#if __has_include(<stdbit.h>)
+
+#include <gtest/gtest.h>
+
+#include <stdbit.h>
+
+#include <limits.h>
+
+typedef unsigned char uc;
+typedef unsigned short us;
+typedef unsigned int ui;
+typedef unsigned long int ul;
+typedef unsigned long long int ull;
+
+TEST(stdbit, version) {
+  EXPECT_EQ(202311L, __STDC_VERSION_STDBIT_H__);
+}
+
+TEST(stdbit, endian) {
+  EXPECT_EQ(__STDC_ENDIAN_LITTLE__, __STDC_ENDIAN_NATIVE__);
+}
+
+static constexpr unsigned kLongBit = static_cast<unsigned>(LONG_BIT);
+
+TEST(stdbit, stdc_leading_zeros) {
+  EXPECT_EQ(64u, stdc_leading_zeros(0x0000000000000000ull));
+  EXPECT_EQ(32u, stdc_leading_zeros(0x00000000ffffffffull));
+  EXPECT_EQ(48u, stdc_leading_zeros(0x000000000000ffffull));
+  EXPECT_EQ(0u, stdc_leading_zeros(0xffffffffffffffffull));
+}
+
+TEST(stdbit, stdc_leading_zeros_forwarding) {
+  EXPECT_EQ(8u, stdc_leading_zeros_uc(0x0000000000000000ull));
+  EXPECT_EQ(16u, stdc_leading_zeros_us(0x0000000000000000ull));
+  EXPECT_EQ(32u, stdc_leading_zeros_ui(0x0000000000000000ull));
+  EXPECT_EQ(kLongBit, stdc_leading_zeros_ul(0x0000000000000000ull));
+  EXPECT_EQ(64u, stdc_leading_zeros_ull(0x0000000000000000ull));
+}
+
+TEST(stdbit, stdc_leading_ones) {
+  EXPECT_EQ(64u, stdc_leading_ones(0xffffffffffffffffull));
+  EXPECT_EQ(32u, stdc_leading_ones(0xffffffff00000000ull));
+  EXPECT_EQ(16u, stdc_leading_ones(0xffff000000000000ull));
+  EXPECT_EQ(0u, stdc_leading_ones(0x0000000000000000ull));
+}
+
+TEST(stdbit, stdc_leading_ones_forwarding) {
+  EXPECT_EQ(8u, stdc_leading_ones_uc(0xffffffffffffffffull));
+  EXPECT_EQ(16u, stdc_leading_ones_us(0xffffffffffffffffull));
+  EXPECT_EQ(32u, stdc_leading_ones_ui(0xffffffffffffffffull));
+  EXPECT_EQ(kLongBit, stdc_leading_ones_ul(0xffffffffffffffffull));
+  EXPECT_EQ(64u, stdc_leading_ones_ull(0xffffffffffffffffull));
+}
+
+TEST(stdbit, stdc_trailing_zeros) {
+  EXPECT_EQ(64u, stdc_trailing_zeros(0x0000000000000000ull));
+  EXPECT_EQ(0u, stdc_trailing_zeros(0x0000000000000001ull));
+  EXPECT_EQ(8u, stdc_trailing_zeros(0x0000000000000100ull));
+  EXPECT_EQ(16u, stdc_trailing_zeros(0x0000000000010000ull));
+  EXPECT_EQ(32u, stdc_trailing_zeros(0x0000000100000000ull));
+  EXPECT_EQ(63u, stdc_trailing_zeros(0x8000000000000000ull));
+  EXPECT_EQ(0u, stdc_trailing_zeros(0xffffffffffffffffull));
+}
+
+TEST(stdbit, stdc_trailing_zeros_forwarding) {
+  EXPECT_EQ(8u, stdc_trailing_zeros_uc(0x0000000000000000ull));
+  EXPECT_EQ(16u, stdc_trailing_zeros_us(0x0000000000000000ull));
+  EXPECT_EQ(32u, stdc_trailing_zeros_ui(0x0000000000000000ull));
+  EXPECT_EQ(kLongBit, stdc_trailing_zeros_ul(0x0000000000000000ull));
+  EXPECT_EQ(64u, stdc_trailing_zeros_ull(0x0000000000000000ull));
+}
+
+TEST(stdbit, stdc_trailing_ones) {
+  EXPECT_EQ(0u, stdc_trailing_ones(0x0000000000000000ull));
+  EXPECT_EQ(8u, stdc_trailing_ones(0x00000000000000ffull));
+  EXPECT_EQ(16u, stdc_trailing_ones(0x000000000000ffffull));
+  EXPECT_EQ(32u, stdc_trailing_ones(0x00000000ffffffffull));
+  EXPECT_EQ(64u, stdc_trailing_ones(0xffffffffffffffffull));
+}
+
+TEST(stdbit, stdc_trailing_ones_forwarding) {
+  EXPECT_EQ(8u, stdc_trailing_ones_uc(0xffffffffffffffffull));
+  EXPECT_EQ(16u, stdc_trailing_ones_us(0xffffffffffffffffull));
+  EXPECT_EQ(32u, stdc_trailing_ones_ui(0xffffffffffffffffull));
+  EXPECT_EQ(kLongBit, stdc_trailing_ones_ul(0xffffffffffffffffull));
+  EXPECT_EQ(64u, stdc_trailing_ones_ull(0xffffffffffffffffull));
+}
+
+TEST(stdbit, stdc_first_leading_zero) {
+  EXPECT_EQ(1u, stdc_first_leading_zero(0x0000000000000000ull));
+  EXPECT_EQ(9u, stdc_first_leading_zero(0xff00000000000000ull));
+  EXPECT_EQ(17u, stdc_first_leading_zero(0xffff000000000000ull));
+  EXPECT_EQ(33u, stdc_first_leading_zero(0xffffffff00000000ull));
+  EXPECT_EQ(0u, stdc_first_leading_zero(0xffffffffffffffffull));
+}
+
+TEST(stdbit, stdc_first_leading_zero_forwarding) {
+  EXPECT_EQ(8u, stdc_first_leading_zero_uc(0xfffffffffffffffeull));
+  EXPECT_EQ(16u, stdc_first_leading_zero_us(0xfffffffffffffffeull));
+  EXPECT_EQ(32u, stdc_first_leading_zero_ui(0xfffffffffffffffeull));
+#if defined(__LP64__)
+  EXPECT_EQ(64u, stdc_first_leading_zero_ul(0xfffffffffffffffeull));
+#else
+  EXPECT_EQ(32u, stdc_first_leading_zero_ul(0xfffffffffffffffeull));
+#endif
+  EXPECT_EQ(64u, stdc_first_leading_zero_ull(0xfffffffffffffffeull));
+}
+
+TEST(stdbit, stdc_first_leading_one) {
+  EXPECT_EQ(0u, stdc_first_leading_one(0x0000000000000000ull));
+  EXPECT_EQ(57u, stdc_first_leading_one(0x00000000000000ffull));
+  EXPECT_EQ(49u, stdc_first_leading_one(0x000000000000ffffull));
+  EXPECT_EQ(33u, stdc_first_leading_one(0x00000000ffffffffull));
+  EXPECT_EQ(1u, stdc_first_leading_one(0xffffffffffffffffull));
+}
+
+TEST(stdbit, stdc_first_leading_one_forwarding) {
+  EXPECT_EQ(8u, stdc_first_leading_one_uc(0x0000000000000001ull));
+  EXPECT_EQ(16u, stdc_first_leading_one_us(0x0000000000000001ull));
+  EXPECT_EQ(32u, stdc_first_leading_one_ui(0x0000000000000001ull));
+  EXPECT_EQ(kLongBit, stdc_first_leading_one_ul(0x0000000000000001ull));
+  EXPECT_EQ(64u, stdc_first_leading_one_ull(0x0000000000000001ull));
+}
+
+TEST(stdbit, stdc_first_trailing_zero) {
+  EXPECT_EQ(1u, stdc_first_trailing_zero(0x0000000000000000ull));
+  EXPECT_EQ(9u, stdc_first_trailing_zero(0x00000000000000ffull));
+  EXPECT_EQ(17u, stdc_first_trailing_zero(0x000000000000ffffull));
+  EXPECT_EQ(33u, stdc_first_trailing_zero(0x00000000ffffffffull));
+  EXPECT_EQ(0u, stdc_first_trailing_zero(0xffffffffffffffffull));
+}
+
+TEST(stdbit, stdc_first_trailing_zero_forwarding) {
+  EXPECT_EQ(8u, stdc_first_trailing_zero_uc(0x00000000000007full));
+  EXPECT_EQ(16u, stdc_first_trailing_zero_us(0x000000000007fffull));
+  EXPECT_EQ(32u, stdc_first_trailing_zero_ui(0x00000007fffffffull));
+#if defined(__LP64__)
+  EXPECT_EQ(64u, stdc_first_trailing_zero_ul(0x7fffffffffffffffull));
+#else
+  EXPECT_EQ(32u, stdc_first_trailing_zero_ul(0x00000007fffffffull));
+#endif
+  EXPECT_EQ(64u, stdc_first_trailing_zero_ull(0x7fffffffffffffffull));
+}
+
+TEST(stdbit, stdc_first_trailing_one) {
+  EXPECT_EQ(0u, stdc_first_trailing_one(0x0000000000000000ull));
+  EXPECT_EQ(57u, stdc_first_trailing_one(0xff00000000000000ull));
+  EXPECT_EQ(49u, stdc_first_trailing_one(0xffff000000000000ull));
+  EXPECT_EQ(33u, stdc_first_trailing_one(0xffffffff00000000ull));
+  EXPECT_EQ(1u, stdc_first_trailing_one(0xffffffffffffffffull));
+}
+
+TEST(stdbit, stdc_first_trailing_one_forwarding) {
+  EXPECT_EQ(8u, stdc_first_trailing_one_uc(0x000000000000080ull));
+  EXPECT_EQ(16u, stdc_first_trailing_one_us(0x000000000008000ull));
+  EXPECT_EQ(32u, stdc_first_trailing_one_ui(0x000000080000000ull));
+#if defined(__LP64__)
+  EXPECT_EQ(64u, stdc_first_trailing_one_ul(0x8000000000000000ull));
+#else
+  EXPECT_EQ(32u, stdc_first_trailing_one_ul(0x000000080000000ull));
+#endif
+  EXPECT_EQ(64u, stdc_first_trailing_one_ull(0x8000000000000000ull));
+}
+
+TEST(stdbit, stdc_count_zeros) {
+  EXPECT_EQ(64u, stdc_count_zeros(0x0000000000000000ull));
+  EXPECT_EQ(56u, stdc_count_zeros(0xff00000000000000ull));
+  EXPECT_EQ(48u, stdc_count_zeros(0xffff000000000000ull));
+  EXPECT_EQ(32u, stdc_count_zeros(0xffffffff00000000ull));
+  EXPECT_EQ(0u, stdc_count_zeros(0xffffffffffffffffull));
+}
+
+TEST(stdbit, stdc_count_zeros_forwarding) {
+  EXPECT_EQ(8u, stdc_count_zeros_uc(0x0000000000000000ull));
+  EXPECT_EQ(16u, stdc_count_zeros_us(0x0000000000000000ull));
+  EXPECT_EQ(32u, stdc_count_zeros_ui(0x0000000000000000ull));
+  EXPECT_EQ(kLongBit, stdc_count_zeros_ul(0x0000000000000000ull));
+  EXPECT_EQ(64u, stdc_count_zeros_ull(0x0000000000000000ull));
+}
+
+TEST(stdbit, stdc_count_ones) {
+  EXPECT_EQ(0u, stdc_count_ones(0x0000000000000000ull));
+  EXPECT_EQ(8u, stdc_count_ones(0xff00000000000000ull));
+  EXPECT_EQ(16u, stdc_count_ones(0xffff000000000000ull));
+  EXPECT_EQ(32u, stdc_count_ones(0xffffffff00000000ull));
+  EXPECT_EQ(64u, stdc_count_ones(0xffffffffffffffffull));
+}
+
+TEST(stdbit, stdc_count_ones_forwarding) {
+  EXPECT_EQ(8u, stdc_count_ones_uc(0xffffffffffffffffull));
+  EXPECT_EQ(16u, stdc_count_ones_us(0xffffffffffffffffull));
+  EXPECT_EQ(32u, stdc_count_ones_ui(0xffffffffffffffffull));
+  EXPECT_EQ(kLongBit, stdc_count_ones_ul(0xffffffffffffffffull));
+  EXPECT_EQ(64u, stdc_count_ones_ull(0xffffffffffffffffull));
+}
+
+TEST(stdbit, stdc_has_single_bit) {
+  EXPECT_EQ(false, stdc_has_single_bit(0x0000000000000000ull));
+  EXPECT_EQ(false, stdc_has_single_bit(0x0000000000000003ull));
+  EXPECT_EQ(false, stdc_has_single_bit(0x1000000000000001ull));
+  EXPECT_EQ(false, stdc_has_single_bit(0xffffffffffffffffull));
+
+  EXPECT_EQ(true, stdc_has_single_bit(0x0000000000000001ull));
+  EXPECT_EQ(true, stdc_has_single_bit(0x0000000000008000ull));
+  EXPECT_EQ(true, stdc_has_single_bit(0x0000000080000000ull));
+  EXPECT_EQ(true, stdc_has_single_bit(0x8000000000000000ull));
+}
+
+TEST(stdbit, stdc_has_single_bit_forwarding) {
+  EXPECT_EQ(true, stdc_has_single_bit_uc(0x8000000080008080ull));
+  EXPECT_EQ(true, stdc_has_single_bit_us(0x8000000080008000ull));
+  EXPECT_EQ(true, stdc_has_single_bit_ui(0x8000000080000000ull));
+#if defined(__LP64__)
+  EXPECT_EQ(true, stdc_has_single_bit_ul(0x8000000000000000ull));
+#else
+  EXPECT_EQ(true, stdc_has_single_bit_ul(0x8000000080000000ull));
+#endif
+  EXPECT_EQ(true, stdc_has_single_bit_ull(0x8000000000000000ull));
+}
+
+TEST(stdbit, stdc_bit_width) {
+  EXPECT_EQ(0u, stdc_bit_width(0x0000000000000000ull));
+  EXPECT_EQ(8u, stdc_bit_width(0x0000000000000080ull));
+  EXPECT_EQ(16u, stdc_bit_width(0x0000000000008000ull));
+  EXPECT_EQ(32u, stdc_bit_width(0x0000000080000000ull));
+  EXPECT_EQ(64u, stdc_bit_width(0x8000000000000000ull));
+  EXPECT_EQ(64u, stdc_bit_width(0xffffffffffffffffull));
+}
+
+TEST(stdbit, stdc_bit_width_forwarding) {
+  EXPECT_EQ(8u, stdc_bit_width_uc(0xffffffffffffffffull));
+  EXPECT_EQ(16u, stdc_bit_width_us(0xffffffffffffffffull));
+  EXPECT_EQ(32u, stdc_bit_width_ui(0xffffffffffffffffull));
+  EXPECT_EQ(kLongBit, stdc_bit_width_ul(0xffffffffffffffffull));
+  EXPECT_EQ(64u, stdc_bit_width_ull(0xffffffffffffffffull));
+}
+
+TEST(stdbit, stdc_bit_floor) {
+  EXPECT_EQ(0x0000000000000000ull, stdc_bit_floor(0x0000000000000000ull));
+
+  EXPECT_EQ(0x0000000000000040ull, stdc_bit_floor(0x000000000000007full));
+  EXPECT_EQ(0x0000000000000080ull, stdc_bit_floor(0x0000000000000080ull));
+  EXPECT_EQ(0x0000000000000100ull, stdc_bit_floor(0x0000000000000100ull));
+  EXPECT_EQ(0x0000000000004000ull, stdc_bit_floor(0x0000000000007fffull));
+  EXPECT_EQ(0x0000000000008000ull, stdc_bit_floor(0x0000000000008000ull));
+  EXPECT_EQ(0x0000000000010000ull, stdc_bit_floor(0x0000000000010000ull));
+  EXPECT_EQ(0x0000000040000000ull, stdc_bit_floor(0x000000007fffffffull));
+  EXPECT_EQ(0x0000000080000000ull, stdc_bit_floor(0x0000000080000000ull));
+  EXPECT_EQ(0x0000000100000000ull, stdc_bit_floor(0x0000000100000000ull));
+  EXPECT_EQ(0x4000000000000000ull, stdc_bit_floor(0x7fffffffffffffffull));
+  EXPECT_EQ(0x8000000000000000ull, stdc_bit_floor(0x8000000000000000ull));
+
+  EXPECT_EQ(0x8000000000000000ull, stdc_bit_floor(0xffffffffffffffffull));
+}
+
+TEST(stdbit, stdc_bit_floor_forwarding) {
+  EXPECT_EQ(0x0000000000000080ull, stdc_bit_floor_uc(0x8000000080008080ull));
+  EXPECT_EQ(0x0000000000008000ull, stdc_bit_floor_us(0x8000000080008080ull));
+  EXPECT_EQ(0x0000000080000000ull, stdc_bit_floor_ui(0x8000000080008080ull));
+#if defined(__LP64__)
+  EXPECT_EQ(0x8000000000000000ull, stdc_bit_floor_ul(0x8000000080008080ull));
+#else
+  EXPECT_EQ(0x0000000080000000ull, stdc_bit_floor_ul(0x8000000080008080ull));
+#endif
+  EXPECT_EQ(0x8000000000000000ull, stdc_bit_floor_ull(0x8000000080008080ull));
+}
+
+TEST(stdbit, stdc_bit_ceil) {
+  EXPECT_EQ(0x0000000000000001ull, stdc_bit_ceil(0x0000000000000000ull));
+
+  EXPECT_EQ(0x0000000000000080ull, stdc_bit_ceil(0x000000000000007full));
+  EXPECT_EQ(0x0000000000000080ull, stdc_bit_ceil(0x0000000000000080ull));
+  EXPECT_EQ(0x0000000000000100ull, stdc_bit_ceil(0x0000000000000100ull));
+  EXPECT_EQ(0x0000000000008000ull, stdc_bit_ceil(0x0000000000007fffull));
+  EXPECT_EQ(0x0000000000008000ull, stdc_bit_ceil(0x0000000000008000ull));
+  EXPECT_EQ(0x0000000000010000ull, stdc_bit_ceil(0x0000000000010000ull));
+  EXPECT_EQ(0x0000000080000000ull, stdc_bit_ceil(0x000000007fffffffull));
+  EXPECT_EQ(0x0000000080000000ull, stdc_bit_ceil(0x0000000080000000ull));
+  EXPECT_EQ(0x0000000100000000ull, stdc_bit_ceil(0x0000000100000000ull));
+  EXPECT_EQ(0x8000000000000000ull, stdc_bit_ceil(0x7fffffffffffffffull));
+  EXPECT_EQ(0x8000000000000000ull, stdc_bit_ceil(0x8000000000000000ull));
+
+  EXPECT_EQ(0x0000000000000000ull, stdc_bit_ceil(0xffffffffffffffffull));
+}
+
+TEST(stdbit, stdc_bit_ceil_forwarding) {
+  EXPECT_EQ(0x0000000000000080ull, stdc_bit_ceil_uc(0x800000008000807full));
+  EXPECT_EQ(0x0000000000008000ull, stdc_bit_ceil_us(0x8000000080007fffull));
+  EXPECT_EQ(0x0000000080000000ull, stdc_bit_ceil_ui(0x800000007fffffffull));
+#if defined(__LP64__)
+  EXPECT_EQ(0x8000000000000000ull, stdc_bit_ceil_ul(0x7fffffffffffffffull));
+#else
+  EXPECT_EQ(0x0000000080000000ull, stdc_bit_ceil_ul(0x800000007fffffffull));
+#endif
+  EXPECT_EQ(0x8000000000000000ull, stdc_bit_ceil_ull(0x7fffffffffffffffull));
+}
+
+TEST(stdbit, no_double_evaluation) {
+  ull x;
+
+  x = 0;
+  stdc_leading_zeros(x++);
+  EXPECT_EQ(x, 1u);
+
+  x = 0;
+  stdc_leading_ones(x++);
+  EXPECT_EQ(x, 1u);
+
+  x = 0;
+  stdc_trailing_zeros(x++);
+  EXPECT_EQ(x, 1u);
+
+  x = 0;
+  stdc_trailing_ones(x++);
+  EXPECT_EQ(x, 1u);
+
+  x = 0;
+  stdc_first_leading_zero(x++);
+  EXPECT_EQ(x, 1u);
+
+  x = 0;
+  stdc_first_leading_one(x++);
+  EXPECT_EQ(x, 1u);
+
+  x = 0;
+  stdc_first_trailing_zero(x++);
+  EXPECT_EQ(x, 1u);
+
+  x = 0;
+  stdc_first_trailing_one(x++);
+  EXPECT_EQ(x, 1u);
+
+  x = 0;
+  stdc_count_zeros(x++);
+  EXPECT_EQ(x, 1u);
+
+  x = 0;
+  stdc_count_ones(x++);
+  EXPECT_EQ(x, 1u);
+
+  x = 0;
+  stdc_has_single_bit(x++);
+  EXPECT_EQ(x, 1u);
+
+  x = 0;
+  stdc_bit_width(x++);
+  EXPECT_EQ(x, 1u);
+
+  x = 0;
+  stdc_bit_floor(x++);
+  EXPECT_EQ(x, 1u);
+
+  x = 0;
+  stdc_bit_ceil(x++);
+  EXPECT_EQ(x, 1u);
+}
+
+#endif
diff --git a/tests/stdint_test.cpp b/tests/stdint_test.cpp
index 5dafee3..ee609d1 100644
--- a/tests/stdint_test.cpp
+++ b/tests/stdint_test.cpp
@@ -14,24 +14,156 @@
  * limitations under the License.
  */
 
-#include <gtest/gtest.h>
-
 #include <stdint.h>
 
-TEST(stdint_types, type_sizes) {
-  ASSERT_EQ(1U, sizeof(int_fast8_t));
-  ASSERT_EQ(8U, sizeof(int_fast64_t));
-  ASSERT_EQ(1U, sizeof(uint_fast8_t));
-  ASSERT_EQ(8U, sizeof(uint_fast64_t));
+#include <gtest/gtest.h>
+
+#include <limits>
+
+TEST(stdint, fast_type_sizes) {
+  EXPECT_EQ(1U, sizeof(int_fast8_t));
+  EXPECT_EQ(8U, sizeof(int_fast64_t));
+  EXPECT_EQ(1U, sizeof(uint_fast8_t));
+  EXPECT_EQ(8U, sizeof(uint_fast64_t));
 #if defined(__LP64__)
-  ASSERT_EQ(8U, sizeof(int_fast16_t));
-  ASSERT_EQ(8U, sizeof(int_fast32_t));
-  ASSERT_EQ(8U, sizeof(uint_fast16_t));
-  ASSERT_EQ(8U, sizeof(uint_fast32_t));
+  EXPECT_EQ(8U, sizeof(int_fast16_t));
+  EXPECT_EQ(8U, sizeof(int_fast32_t));
+  EXPECT_EQ(8U, sizeof(uint_fast16_t));
+  EXPECT_EQ(8U, sizeof(uint_fast32_t));
 #else
-  ASSERT_EQ(4U, sizeof(int_fast16_t));
-  ASSERT_EQ(4U, sizeof(int_fast32_t));
-  ASSERT_EQ(4U, sizeof(uint_fast16_t));
-  ASSERT_EQ(4U, sizeof(uint_fast32_t));
+  EXPECT_EQ(4U, sizeof(int_fast16_t));
+  EXPECT_EQ(4U, sizeof(int_fast32_t));
+  EXPECT_EQ(4U, sizeof(uint_fast16_t));
+  EXPECT_EQ(4U, sizeof(uint_fast32_t));
+#endif
+}
+
+TEST(stdint, least_type_sizes) {
+  EXPECT_EQ(1U, sizeof(int_least8_t));
+  EXPECT_EQ(1U, sizeof(uint_least8_t));
+  EXPECT_EQ(2U, sizeof(int_least16_t));
+  EXPECT_EQ(2U, sizeof(uint_least16_t));
+  EXPECT_EQ(4U, sizeof(int_least32_t));
+  EXPECT_EQ(4U, sizeof(uint_least32_t));
+  EXPECT_EQ(8U, sizeof(int_least64_t));
+  EXPECT_EQ(8U, sizeof(uint_least64_t));
+}
+
+TEST(stdint, max) {
+  EXPECT_EQ(std::numeric_limits<int8_t>::max(), INT8_MAX);
+  EXPECT_EQ(std::numeric_limits<uint8_t>::max(), UINT8_MAX);
+  EXPECT_EQ(std::numeric_limits<int16_t>::max(), INT16_MAX);
+  EXPECT_EQ(std::numeric_limits<uint16_t>::max(), UINT16_MAX);
+  EXPECT_EQ(std::numeric_limits<int32_t>::max(), INT32_MAX);
+  EXPECT_EQ(std::numeric_limits<uint32_t>::max(), UINT32_MAX);
+  EXPECT_EQ(std::numeric_limits<int64_t>::max(), INT64_MAX);
+  EXPECT_EQ(std::numeric_limits<uint64_t>::max(), UINT64_MAX);
+
+  EXPECT_EQ(std::numeric_limits<int_fast8_t>::max(), INT_FAST8_MAX);
+  EXPECT_EQ(std::numeric_limits<uint_fast8_t>::max(), UINT_FAST8_MAX);
+  EXPECT_EQ(std::numeric_limits<int_fast16_t>::max(), INT_FAST16_MAX);
+  EXPECT_EQ(std::numeric_limits<uint_fast16_t>::max(), UINT_FAST16_MAX);
+  EXPECT_EQ(std::numeric_limits<int_fast32_t>::max(), INT_FAST32_MAX);
+  EXPECT_EQ(std::numeric_limits<uint_fast32_t>::max(), UINT_FAST32_MAX);
+  EXPECT_EQ(std::numeric_limits<int_fast64_t>::max(), INT_FAST64_MAX);
+  EXPECT_EQ(std::numeric_limits<uint_fast64_t>::max(), UINT_FAST64_MAX);
+
+  EXPECT_EQ(std::numeric_limits<int_least8_t>::max(), INT_LEAST8_MAX);
+  EXPECT_EQ(std::numeric_limits<uint_least8_t>::max(), UINT_LEAST8_MAX);
+  EXPECT_EQ(std::numeric_limits<int_least16_t>::max(), INT_LEAST16_MAX);
+  EXPECT_EQ(std::numeric_limits<uint_least16_t>::max(), UINT_LEAST16_MAX);
+  EXPECT_EQ(std::numeric_limits<int_least32_t>::max(), INT_LEAST32_MAX);
+  EXPECT_EQ(std::numeric_limits<uint_least32_t>::max(), UINT_LEAST32_MAX);
+  EXPECT_EQ(std::numeric_limits<int_least64_t>::max(), INT_LEAST64_MAX);
+  EXPECT_EQ(std::numeric_limits<uint_least64_t>::max(), UINT_LEAST64_MAX);
+
+  EXPECT_EQ(std::numeric_limits<wchar_t>::max(), WCHAR_MAX);
+  EXPECT_EQ(std::numeric_limits<wint_t>::max(), WINT_MAX);
+
+  EXPECT_EQ(std::numeric_limits<intptr_t>::max(), INTPTR_MAX);
+  EXPECT_EQ(std::numeric_limits<uintptr_t>::max(), UINTPTR_MAX);
+  EXPECT_EQ(std::numeric_limits<intmax_t>::max(), INTMAX_MAX);
+  EXPECT_EQ(std::numeric_limits<uintmax_t>::max(), UINTMAX_MAX);
+
+  EXPECT_EQ(std::numeric_limits<ptrdiff_t>::max(), PTRDIFF_MAX);
+
+  EXPECT_EQ(std::numeric_limits<size_t>::max(), SIZE_MAX);
+
+  EXPECT_EQ(std::numeric_limits<sig_atomic_t>::max(), SIG_ATOMIC_MAX);
+}
+
+TEST(stdint, min) {
+  EXPECT_EQ(std::numeric_limits<int8_t>::min(), INT8_MIN);
+  EXPECT_EQ(std::numeric_limits<int16_t>::min(), INT16_MIN);
+  EXPECT_EQ(std::numeric_limits<int32_t>::min(), INT32_MIN);
+  EXPECT_EQ(std::numeric_limits<int64_t>::min(), INT64_MIN);
+
+  EXPECT_EQ(std::numeric_limits<int_fast8_t>::min(), INT_FAST8_MIN);
+  EXPECT_EQ(std::numeric_limits<int_fast16_t>::min(), INT_FAST16_MIN);
+  EXPECT_EQ(std::numeric_limits<int_fast32_t>::min(), INT_FAST32_MIN);
+  EXPECT_EQ(std::numeric_limits<int_fast64_t>::min(), INT_FAST64_MIN);
+
+  EXPECT_EQ(std::numeric_limits<int_least8_t>::min(), INT_LEAST8_MIN);
+  EXPECT_EQ(std::numeric_limits<int_least16_t>::min(), INT_LEAST16_MIN);
+  EXPECT_EQ(std::numeric_limits<int_least32_t>::min(), INT_LEAST32_MIN);
+  EXPECT_EQ(std::numeric_limits<int_least64_t>::min(), INT_LEAST64_MIN);
+
+  EXPECT_EQ(std::numeric_limits<wchar_t>::min(), WCHAR_MIN);
+  EXPECT_EQ(std::numeric_limits<wint_t>::min(), static_cast<uintmax_t>(WINT_MIN));
+
+  EXPECT_EQ(std::numeric_limits<intptr_t>::min(), INTPTR_MIN);
+  EXPECT_EQ(std::numeric_limits<intmax_t>::min(), INTMAX_MIN);
+
+  EXPECT_EQ(std::numeric_limits<ptrdiff_t>::min(), PTRDIFF_MIN);
+
+  EXPECT_EQ(std::numeric_limits<sig_atomic_t>::min(), SIG_ATOMIC_MIN);
+}
+template <typename T>
+static inline int bitSize() {
+  return sizeof(T) * 8;
+}
+
+TEST(stdint, widths) {
+#if defined(__BIONIC__)
+  EXPECT_EQ(bitSize<int8_t>(), INT8_WIDTH);
+  EXPECT_EQ(bitSize<uint8_t>(), UINT8_WIDTH);
+  EXPECT_EQ(bitSize<int16_t>(), INT16_WIDTH);
+  EXPECT_EQ(bitSize<uint16_t>(), UINT16_WIDTH);
+  EXPECT_EQ(bitSize<int32_t>(), INT32_WIDTH);
+  EXPECT_EQ(bitSize<uint32_t>(), UINT32_WIDTH);
+  EXPECT_EQ(bitSize<int64_t>(), INT64_WIDTH);
+  EXPECT_EQ(bitSize<uint64_t>(), UINT64_WIDTH);
+
+  EXPECT_EQ(bitSize<int_fast8_t>(), INT_FAST8_WIDTH);
+  EXPECT_EQ(bitSize<uint_fast8_t>(), UINT_FAST8_WIDTH);
+  EXPECT_EQ(bitSize<int_fast16_t>(), INT_FAST16_WIDTH);
+  EXPECT_EQ(bitSize<uint_fast16_t>(), UINT_FAST16_WIDTH);
+  EXPECT_EQ(bitSize<int_fast32_t>(), INT_FAST32_WIDTH);
+  EXPECT_EQ(bitSize<uint_fast32_t>(), UINT_FAST32_WIDTH);
+  EXPECT_EQ(bitSize<int_fast64_t>(), INT_FAST64_WIDTH);
+  EXPECT_EQ(bitSize<uint_fast64_t>(), UINT_FAST64_WIDTH);
+
+  EXPECT_EQ(bitSize<int_least8_t>(), INT_LEAST8_WIDTH);
+  EXPECT_EQ(bitSize<uint_least8_t>(), UINT_LEAST8_WIDTH);
+  EXPECT_EQ(bitSize<int_least16_t>(), INT_LEAST16_WIDTH);
+  EXPECT_EQ(bitSize<uint_least16_t>(), UINT_LEAST16_WIDTH);
+  EXPECT_EQ(bitSize<int_least32_t>(), INT_LEAST32_WIDTH);
+  EXPECT_EQ(bitSize<uint_least32_t>(), UINT_LEAST32_WIDTH);
+  EXPECT_EQ(bitSize<int_least64_t>(), INT_LEAST64_WIDTH);
+  EXPECT_EQ(bitSize<uint_least64_t>(), UINT_LEAST64_WIDTH);
+
+  EXPECT_EQ(bitSize<wchar_t>(), WCHAR_WIDTH);
+  EXPECT_EQ(bitSize<wint_t>(), WINT_WIDTH);
+
+  EXPECT_EQ(bitSize<intptr_t>(), INTPTR_WIDTH);
+  EXPECT_EQ(bitSize<uintptr_t>(), UINTPTR_WIDTH);
+  EXPECT_EQ(bitSize<intmax_t>(), INTMAX_WIDTH);
+  EXPECT_EQ(bitSize<uintmax_t>() , UINTMAX_WIDTH);
+
+  EXPECT_EQ(bitSize<ptrdiff_t>(), PTRDIFF_WIDTH);
+
+  EXPECT_EQ(bitSize<size_t>(), SIZE_WIDTH);
+
+  EXPECT_EQ(bitSize<sig_atomic_t>(), SIG_ATOMIC_WIDTH);
 #endif
 }
diff --git a/tests/stdio_test.cpp b/tests/stdio_test.cpp
index 7cdfa42..36830c7 100644
--- a/tests/stdio_test.cpp
+++ b/tests/stdio_test.cpp
@@ -40,6 +40,7 @@
 #include <android-base/test_utils.h>
 #include <android-base/unique_fd.h>
 
+#include "android-base/stringprintf.h"
 #include "utils.h"
 
 // This #include is actually a test too. We have to duplicate the
@@ -261,16 +262,63 @@
   fclose(fp);
 }
 
+TEST(STDIO_TEST, fgetln) {
+#if !defined(__GLIBC__)
+  FILE* fp = tmpfile();
+  ASSERT_TRUE(fp != nullptr);
+
+  std::vector<std::string> lines;
+  for (size_t i = 0; i < 5; ++i) {
+    lines.push_back(android::base::StringPrintf("This is test line %zu for fgetln()\n", i));
+  }
+
+  for (size_t i = 0; i < lines.size(); ++i) {
+    int rc = fprintf(fp, "%s", lines[i].c_str());
+    ASSERT_EQ(rc, static_cast<int>(lines[i].size()));
+  }
+
+  rewind(fp);
+
+  size_t i = 0;
+  char* line = nullptr;
+  size_t line_length;
+  while ((line = fgetln(fp, &line_length)) != nullptr) {
+    ASSERT_EQ(line_length, lines[i].size());
+    // "lines" aren't necessarily NUL-terminated, so we need to use memcmp().
+    ASSERT_EQ(0, memcmp(lines[i].c_str(), line, line_length));
+    ++i;
+  }
+  ASSERT_EQ(i, lines.size());
+
+  // The last read should have set the end-of-file indicator for the stream.
+  ASSERT_TRUE(feof(fp));
+  clearerr(fp);
+
+  // fgetln() returns nullptr but doesn't set errno if we're already at EOF.
+  // It should set the end-of-file indicator for the stream, though.
+  errno = 0;
+  ASSERT_EQ(fgetln(fp, &line_length), nullptr);
+  ASSERT_ERRNO(0);
+  ASSERT_TRUE(feof(fp));
+
+  fclose(fp);
+#else
+  GTEST_SKIP() << "no fgetln() in glibc";
+#endif
+}
+
 TEST(STDIO_TEST, getline) {
   FILE* fp = tmpfile();
   ASSERT_TRUE(fp != nullptr);
 
-  const char* line_written = "This is a test for getline\n";
-  const size_t line_count = 5;
+  std::vector<std::string> lines;
+  for (size_t i = 0; i < 5; ++i) {
+    lines.push_back(android::base::StringPrintf("This is test line %zu for getline()\n", i));
+  }
 
-  for (size_t i = 0; i < line_count; ++i) {
-    int rc = fprintf(fp, "%s", line_written);
-    ASSERT_EQ(rc, static_cast<int>(strlen(line_written)));
+  for (size_t i = 0; i < lines.size(); ++i) {
+    int rc = fprintf(fp, "%s", lines[i].c_str());
+    ASSERT_EQ(rc, static_cast<int>(lines[i].size()));
   }
 
   rewind(fp);
@@ -278,15 +326,15 @@
   char* line_read = nullptr;
   size_t allocated_length = 0;
 
-  size_t read_line_count = 0;
+  size_t i = 0;
   ssize_t read_char_count;
   while ((read_char_count = getline(&line_read, &allocated_length, fp)) != -1) {
-    ASSERT_EQ(read_char_count, static_cast<int>(strlen(line_written)));
-    ASSERT_GE(allocated_length, strlen(line_written));
-    ASSERT_STREQ(line_written, line_read);
-    ++read_line_count;
+    ASSERT_EQ(read_char_count, static_cast<int>(lines[i].size()));
+    ASSERT_GE(allocated_length, lines[i].size());
+    ASSERT_EQ(lines[i], line_read);
+    ++i;
   }
-  ASSERT_EQ(read_line_count, line_count);
+  ASSERT_EQ(i, lines.size());
 
   // The last read should have set the end-of-file indicator for the stream.
   ASSERT_TRUE(feof(fp));
@@ -2641,25 +2689,45 @@
 }
 
 TEST(STDIO_TEST, perror) {
-  ExecTestHelper eth;
-  eth.Run([&]() { errno = EINVAL; perror("a b c"); exit(0); }, 0, "a b c: Invalid argument\n");
-  eth.Run([&]() { errno = EINVAL; perror(nullptr); exit(0); }, 0, "Invalid argument\n");
-  eth.Run([&]() { errno = EINVAL; perror(""); exit(0); }, 0, "Invalid argument\n");
+  CapturedStderr cap;
+  errno = EINVAL;
+  perror("a b c");
+  ASSERT_EQ(cap.str(), "a b c: Invalid argument\n");
+}
+
+TEST(STDIO_TEST, perror_null) {
+  CapturedStderr cap;
+  errno = EINVAL;
+  perror(nullptr);
+  ASSERT_EQ(cap.str(), "Invalid argument\n");
+}
+
+TEST(STDIO_TEST, perror_empty) {
+  CapturedStderr cap;
+  errno = EINVAL;
+  perror("");
+  ASSERT_EQ(cap.str(), "Invalid argument\n");
 }
 
 TEST(STDIO_TEST, puts) {
-  ExecTestHelper eth;
-  eth.Run([&]() { exit(puts("a b c")); }, 0, "a b c\n");
+  CapturedStdout cap;
+  puts("a b c");
+  fflush(stdout);
+  ASSERT_EQ(cap.str(), "a b c\n");
 }
 
 TEST(STDIO_TEST, putchar) {
-  ExecTestHelper eth;
-  eth.Run([&]() { exit(putchar('A')); }, 65, "A");
+  CapturedStdout cap;
+  ASSERT_EQ(65, putchar('A'));
+  fflush(stdout);
+  ASSERT_EQ(cap.str(), "A");
 }
 
 TEST(STDIO_TEST, putchar_unlocked) {
-  ExecTestHelper eth;
-  eth.Run([&]() { exit(putchar('B')); }, 66, "B");
+  CapturedStdout cap;
+  ASSERT_EQ(66, putchar_unlocked('B'));
+  fflush(stdout);
+  ASSERT_EQ(cap.str(), "B");
 }
 
 TEST(STDIO_TEST, unlocked) {
@@ -3028,27 +3096,52 @@
 }
 #endif
 
-TEST(STDIO_TEST, fread_int_overflow) {
-#if defined(__LP64__)
-  if (GetTotalRamGiB() <= 4) GTEST_SKIP() << "not enough memory";
+TEST(STDIO_TEST, fread_EOVERFLOW) {
+  TemporaryFile tf;
+  FILE* fp = fopen(tf.path, "r");
+  ASSERT_TRUE(fp != nullptr);
 
-  const size_t too_big_for_an_int = 0x80000000ULL;
-  std::vector<char> buf(too_big_for_an_int);
-  std::unique_ptr<FILE, decltype(&fclose)> fp{fopen("/dev/zero", "re"), fclose};
-  ASSERT_EQ(too_big_for_an_int, fread(&buf[0], 1, too_big_for_an_int, fp.get()));
-#else
-  GTEST_SKIP() << "32-bit can't allocate 2GiB";
-#endif
+  volatile size_t big = SIZE_MAX;
+  char buf[BUFSIZ];
+  errno = 0;
+  ASSERT_EQ(0u, fread(buf, big, big, fp));
+  ASSERT_ERRNO(EOVERFLOW);
+  ASSERT_TRUE(ferror(fp));
+  fclose(fp);
 }
 
-TEST(STDIO_TEST, fwrite_int_overflow) {
+TEST(STDIO_TEST, fwrite_EOVERFLOW) {
+  TemporaryFile tf;
+  FILE* fp = fopen(tf.path, "w");
+  ASSERT_TRUE(fp != nullptr);
+
+  volatile size_t big = SIZE_MAX;
+  char buf[BUFSIZ];
+  errno = 0;
+  ASSERT_EQ(0u, fwrite(buf, big, big, fp));
+  ASSERT_ERRNO(EOVERFLOW);
+  ASSERT_TRUE(ferror(fp));
+  fclose(fp);
+}
+
+TEST(STDIO_TEST, fread_fwrite_int_overflow) {
 #if defined(__LP64__)
   if (GetTotalRamGiB() <= 4) GTEST_SKIP() << "not enough memory";
 
+  // Historically the implementation used ints where it should have used size_t.
   const size_t too_big_for_an_int = 0x80000000ULL;
   std::vector<char> buf(too_big_for_an_int);
-  std::unique_ptr<FILE, decltype(&fclose)> fp{fopen("/dev/null", "we"), fclose};
-  ASSERT_EQ(too_big_for_an_int, fwrite(&buf[0], 1, too_big_for_an_int, fp.get()));
+
+  // We test both fread() and fwrite() in the same function to avoid two tests
+  // both allocating 2GiB of ram at the same time.
+  {
+    std::unique_ptr<FILE, decltype(&fclose)> fp{fopen("/dev/zero", "re"), fclose};
+    ASSERT_EQ(too_big_for_an_int, fread(&buf[0], 1, too_big_for_an_int, fp.get()));
+  }
+  {
+    std::unique_ptr<FILE, decltype(&fclose)> fp{fopen("/dev/null", "we"), fclose};
+    ASSERT_EQ(too_big_for_an_int, fwrite(&buf[0], 1, too_big_for_an_int, fp.get()));
+  }
 #else
   GTEST_SKIP() << "32-bit can't allocate 2GiB";
 #endif
diff --git a/tests/string_test.cpp b/tests/string_test.cpp
index 502405f..9fb6cb3 100644
--- a/tests/string_test.cpp
+++ b/tests/string_test.cpp
@@ -1615,6 +1615,11 @@
   ASSERT_EQ(haystack + 4, strcasestr(haystack, "Da"));
 }
 
+TEST(STRING_TEST, strcasestr_empty) {
+  const char* empty_haystack = "";
+  ASSERT_EQ(empty_haystack, strcasestr(empty_haystack, ""));
+}
+
 TEST(STRING_TEST, strcoll_smoke) {
   ASSERT_TRUE(strcoll("aab", "aac") < 0);
   ASSERT_TRUE(strcoll("aab", "aab") == 0);
@@ -1696,3 +1701,140 @@
   GTEST_SKIP() << "strerrorname_np not available";
 #endif
 }
+
+TEST(STRING_TEST, strpbrk) {
+  EXPECT_EQ(nullptr, strpbrk("hello", ""));
+  EXPECT_STREQ("hello", strpbrk("hello", "ehl"));
+  EXPECT_STREQ("llo", strpbrk("hello", "l"));
+  EXPECT_STREQ(" world", strpbrk("hello world", "\t "));
+
+  // Check that the implementation copes with top bit set characters.
+  EXPECT_STREQ("\x80world", strpbrk("hello\x80world", "\x80 "));
+}
+
+TEST(STRING_TEST, strspn) {
+  EXPECT_EQ(0u, strspn("hello", ""));
+  EXPECT_EQ(4u, strspn("hello", "ehl"));
+  EXPECT_EQ(5u, strspn("hello", "ehlo"));
+  EXPECT_EQ(5u, strspn("hello world", "abcdefghijklmnopqrstuvwxyz"));
+
+  // Check that the implementation copes with top bit set characters.
+  EXPECT_EQ(6u, strspn("hello\x80world", "helo\x80rld"));
+}
+
+TEST(STRING_TEST, strcspn) {
+  EXPECT_EQ(5u, strcspn("hello", ""));
+  EXPECT_EQ(0u, strcspn("hello", "ehl"));
+  EXPECT_EQ(5u, strcspn("hello", "abc"));
+  EXPECT_EQ(5u, strcspn("hello world", " "));
+
+  // Check that the implementation copes with top bit set characters.
+  EXPECT_EQ(5u, strcspn("hello\x80world", "\x80"));
+}
+
+TEST(STRING_TEST, strsep) {
+  char* p = nullptr;
+  EXPECT_EQ(nullptr, strsep(&p, ":"));
+
+  // Unlike strtok(), strsep() _does_ return empty strings.
+  char str[] = ":hello:world:::foo:";
+  p = str;
+  EXPECT_STREQ("", strsep(&p, ":"));
+  EXPECT_STREQ("hello", strsep(&p, ":"));
+  EXPECT_STREQ("world", strsep(&p, ":"));
+  EXPECT_STREQ("", strsep(&p, ":"));
+  EXPECT_STREQ("", strsep(&p, ":"));
+  EXPECT_STREQ("foo", strsep(&p, ":"));
+  EXPECT_STREQ("", strsep(&p, ":"));
+  EXPECT_EQ(nullptr, strsep(&p, ":"));
+  // Repeated calls after the first nullptr keep returning nullptr.
+  for (size_t i = 0; i < 1024; ++i) {
+    EXPECT_EQ(nullptr, strsep(&p, ":"));
+  }
+
+  // Some existing implementations have a separate return path for this.
+  char non_empty_at_end[] = "hello:world";
+  p = non_empty_at_end;
+  EXPECT_STREQ("hello", strsep(&p, ":"));
+  EXPECT_STREQ("world", strsep(&p, ":"));
+  for (size_t i = 0; i < 1024; ++i) {
+    EXPECT_EQ(nullptr, strsep(&p, ":"));
+  }
+
+  // Check that the implementation copes with top bit set characters.
+  char top_bit_set_str[] = "hello\x80world";
+  p = top_bit_set_str;
+  EXPECT_STREQ("hello", strsep(&p, "\x80"));
+  EXPECT_STREQ("world", strsep(&p, "\x80"));
+  EXPECT_EQ(nullptr, strsep(&p, "\x80"));
+}
+
+TEST(STRING_TEST, strtok) {
+  char empty[] = "";
+  EXPECT_EQ(nullptr, strtok(empty, ":"));
+
+  char only_delimiters[] = ":::";
+  EXPECT_EQ(nullptr, strtok(only_delimiters, ":"));
+
+  // Unlike strsep(), strtok() doesn't return empty strings.
+  char str[] = ":hello:world:::foo:";
+  EXPECT_STREQ("hello", strtok(str, ":"));
+  EXPECT_STREQ("world", strtok(nullptr, ":"));
+  EXPECT_STREQ("foo", strtok(nullptr, ":"));
+  EXPECT_EQ(nullptr, strtok(nullptr, ":"));
+  // Repeated calls after the first nullptr keep returning nullptr.
+  for (size_t i = 0; i < 1024; ++i) {
+    EXPECT_EQ(nullptr, strtok(nullptr, ":"));
+  }
+
+  // Some existing implementations have a separate return path for this.
+  char non_empty_at_end[] = "hello:world";
+  EXPECT_STREQ("hello", strtok(non_empty_at_end, ":"));
+  EXPECT_STREQ("world", strtok(nullptr, ":"));
+  for (size_t i = 0; i < 1024; ++i) {
+    EXPECT_EQ(nullptr, strtok(nullptr, ":"));
+  }
+
+  // Check that the implementation copes with top bit set characters.
+  char top_bit_set_str[] = "hello\x80world";
+  EXPECT_STREQ("hello", strtok(top_bit_set_str, "\x80"));
+  EXPECT_STREQ("world", strtok(nullptr, "\x80"));
+  EXPECT_EQ(nullptr, strtok(nullptr, "\x80"));
+}
+
+TEST(STRING_TEST, strtok_r) {
+  char* p;
+
+  char empty[] = "";
+  EXPECT_EQ(nullptr, strtok_r(empty, ":", &p));
+
+  char only_delimiters[] = ":::";
+  EXPECT_EQ(nullptr, strtok_r(only_delimiters, ":", &p));
+
+  // Unlike strsep(), strtok_r() doesn't return empty strings.
+  char str[] = ":hello:world:::foo:";
+  EXPECT_STREQ("hello", strtok_r(str, ":", &p));
+  EXPECT_STREQ("world", strtok_r(nullptr, ":", &p));
+  EXPECT_STREQ("foo", strtok_r(nullptr, ":", &p));
+  EXPECT_EQ(nullptr, strtok_r(nullptr, ":", &p));
+  // Repeated calls after the first nullptr keep returning nullptr.
+  for (size_t i = 0; i < 1024; ++i) {
+    EXPECT_EQ(nullptr, p);
+    EXPECT_EQ(nullptr, strtok_r(nullptr, ":", &p));
+  }
+
+  // Some existing implementations have a separate return path for this.
+  char non_empty_at_end[] = "hello:world";
+  EXPECT_STREQ("hello", strtok_r(non_empty_at_end, ":", &p));
+  EXPECT_STREQ("world", strtok_r(nullptr, ":", &p));
+  for (size_t i = 0; i < 1024; ++i) {
+    EXPECT_EQ(nullptr, p);
+    EXPECT_EQ(nullptr, strtok_r(nullptr, ":", &p));
+  }
+
+  // Check that the implementation copes with top bit set characters.
+  char top_bit_set_str[] = "hello\x80world";
+  EXPECT_STREQ("hello", strtok_r(top_bit_set_str, "\x80", &p));
+  EXPECT_STREQ("world", strtok_r(nullptr, "\x80", &p));
+  EXPECT_EQ(nullptr, strtok_r(nullptr, "\x80", &p));
+}
diff --git a/tests/strings_test.cpp b/tests/strings_test.cpp
index 0226d1a..eec2da4 100644
--- a/tests/strings_test.cpp
+++ b/tests/strings_test.cpp
@@ -86,6 +86,11 @@
   ASSERT_GT(strcasecmp("hello2", "hello1"), 0);
 }
 
+TEST(STRINGS_TEST, strcasecmp_sign) {
+  ASSERT_LT(strcasecmp("\xfe", "\xff"), 0);
+  ASSERT_GT(strcasecmp("\xff", "\xfe"), 0);
+}
+
 TEST(STRINGS_TEST, strcasecmp_l) {
   locale_t l = newlocale(LC_ALL, "C", nullptr);
   ASSERT_EQ(0, strcasecmp_l("hello", "HELLO", l));
@@ -101,6 +106,11 @@
   ASSERT_GT(strncasecmp("hello2", "hello1", 6), 0);
 }
 
+TEST(STRINGS_TEST, strncasecmp_sign) {
+  ASSERT_LT(strncasecmp("\xfe", "\xff", 1), 0);
+  ASSERT_GT(strncasecmp("\xff", "\xfe", 1), 0);
+}
+
 TEST(STRINGS_TEST, strncasecmp_l) {
   locale_t l = newlocale(LC_ALL, "C", nullptr);
   ASSERT_EQ(0, strncasecmp_l("hello", "HELLO", 3, l));
diff --git a/tests/struct_layout_test.cpp b/tests/struct_layout_test.cpp
index b9fd315..3574d0c 100644
--- a/tests/struct_layout_test.cpp
+++ b/tests/struct_layout_test.cpp
@@ -26,11 +26,11 @@
 template <typename CheckSize, typename CheckOffset>
 void tests(CheckSize check_size, CheckOffset check_offset) {
 #define CHECK_SIZE(name, size) \
-    check_size(#name, sizeof(name), size);
+    check_size(#name, sizeof(name), size)
 #define CHECK_OFFSET(name, field, offset) \
-    check_offset(#name, #field, offsetof(name, field), offset);
+    check_offset(#name, #field, offsetof(name, field), offset)
 #ifdef __LP64__
-  CHECK_SIZE(pthread_internal_t, 824);
+  CHECK_SIZE(pthread_internal_t, 832);
   CHECK_OFFSET(pthread_internal_t, next, 0);
   CHECK_OFFSET(pthread_internal_t, prev, 8);
   CHECK_OFFSET(pthread_internal_t, tid, 16);
@@ -44,38 +44,38 @@
   CHECK_OFFSET(pthread_internal_t, alternate_signal_stack, 128);
   CHECK_OFFSET(pthread_internal_t, shadow_call_stack_guard_region, 136);
   CHECK_OFFSET(pthread_internal_t, stack_top, 144);
-  CHECK_OFFSET(pthread_internal_t, startup_handshake_lock, 156);
-  CHECK_OFFSET(pthread_internal_t, mmap_base, 168);
-  CHECK_OFFSET(pthread_internal_t, mmap_size, 176);
-  CHECK_OFFSET(pthread_internal_t, mmap_base_unguarded, 184);
-  CHECK_OFFSET(pthread_internal_t, mmap_size_unguarded, 192);
-  CHECK_OFFSET(pthread_internal_t, vma_name_buffer, 200);
-  CHECK_OFFSET(pthread_internal_t, thread_local_dtors, 232);
-  CHECK_OFFSET(pthread_internal_t, current_dlerror, 240);
-  CHECK_OFFSET(pthread_internal_t, dlerror_buffer, 248);
-  CHECK_OFFSET(pthread_internal_t, bionic_tls, 760);
-  CHECK_OFFSET(pthread_internal_t, errno_value, 768);
-  CHECK_OFFSET(pthread_internal_t, bionic_tcb, 776);
-  CHECK_OFFSET(pthread_internal_t, stack_mte_ringbuffer_vma_name_buffer, 784);
-  CHECK_OFFSET(pthread_internal_t, should_allocate_stack_mte_ringbuffer, 816);
-  CHECK_SIZE(bionic_tls, 12200);
+  CHECK_OFFSET(pthread_internal_t, stack_bottom, 152);
+  CHECK_OFFSET(pthread_internal_t, startup_handshake_lock, 164);
+  CHECK_OFFSET(pthread_internal_t, mmap_base, 176);
+  CHECK_OFFSET(pthread_internal_t, mmap_size, 184);
+  CHECK_OFFSET(pthread_internal_t, mmap_base_unguarded, 192);
+  CHECK_OFFSET(pthread_internal_t, mmap_size_unguarded, 200);
+  CHECK_OFFSET(pthread_internal_t, vma_name_buffer, 208);
+  CHECK_OFFSET(pthread_internal_t, thread_local_dtors, 240);
+  CHECK_OFFSET(pthread_internal_t, current_dlerror, 248);
+  CHECK_OFFSET(pthread_internal_t, dlerror_buffer, 256);
+  CHECK_OFFSET(pthread_internal_t, bionic_tls, 768);
+  CHECK_OFFSET(pthread_internal_t, errno_value, 776);
+  CHECK_OFFSET(pthread_internal_t, bionic_tcb, 784);
+  CHECK_OFFSET(pthread_internal_t, stack_mte_ringbuffer_vma_name_buffer, 792);
+  CHECK_OFFSET(pthread_internal_t, should_allocate_stack_mte_ringbuffer, 824);
+  CHECK_SIZE(bionic_tls, 4016);
   CHECK_OFFSET(bionic_tls, key_data, 0);
   CHECK_OFFSET(bionic_tls, locale, 2080);
-  CHECK_OFFSET(bionic_tls, basename_buf, 2088);
-  CHECK_OFFSET(bionic_tls, dirname_buf, 6184);
-  CHECK_OFFSET(bionic_tls, mntent_buf, 10280);
-  CHECK_OFFSET(bionic_tls, mntent_strings, 10320);
-  CHECK_OFFSET(bionic_tls, ptsname_buf, 11344);
-  CHECK_OFFSET(bionic_tls, ttyname_buf, 11376);
-  CHECK_OFFSET(bionic_tls, strerror_buf, 11440);
-  CHECK_OFFSET(bionic_tls, strsignal_buf, 11695);
-  CHECK_OFFSET(bionic_tls, group, 11952);
-  CHECK_OFFSET(bionic_tls, passwd, 12040);
-  CHECK_OFFSET(bionic_tls, fdtrack_disabled, 12192);
-  CHECK_OFFSET(bionic_tls, bionic_systrace_disabled, 12193);
-  CHECK_OFFSET(bionic_tls, padding, 12194);
+  CHECK_OFFSET(bionic_tls, libgen_buffers_ptr, 2088);
+  CHECK_OFFSET(bionic_tls, mntent_buf, 2096);
+  CHECK_OFFSET(bionic_tls, mntent_strings, 2136);
+  CHECK_OFFSET(bionic_tls, ptsname_buf, 3160);
+  CHECK_OFFSET(bionic_tls, ttyname_buf, 3192);
+  CHECK_OFFSET(bionic_tls, strerror_buf, 3256);
+  CHECK_OFFSET(bionic_tls, strsignal_buf, 3511);
+  CHECK_OFFSET(bionic_tls, group, 3768);
+  CHECK_OFFSET(bionic_tls, passwd, 3856);
+  CHECK_OFFSET(bionic_tls, fdtrack_disabled, 4008);
+  CHECK_OFFSET(bionic_tls, bionic_systrace_enabled, 4009);
+  CHECK_OFFSET(bionic_tls, padding, 4010);
 #else
-  CHECK_SIZE(pthread_internal_t, 708);
+  CHECK_SIZE(pthread_internal_t, 712);
   CHECK_OFFSET(pthread_internal_t, next, 0);
   CHECK_OFFSET(pthread_internal_t, prev, 4);
   CHECK_OFFSET(pthread_internal_t, tid, 8);
@@ -89,36 +89,36 @@
   CHECK_OFFSET(pthread_internal_t, alternate_signal_stack, 68);
   CHECK_OFFSET(pthread_internal_t, shadow_call_stack_guard_region, 72);
   CHECK_OFFSET(pthread_internal_t, stack_top, 76);
-  CHECK_OFFSET(pthread_internal_t, startup_handshake_lock, 84);
-  CHECK_OFFSET(pthread_internal_t, mmap_base, 92);
-  CHECK_OFFSET(pthread_internal_t, mmap_size, 96);
-  CHECK_OFFSET(pthread_internal_t, mmap_base_unguarded, 100);
-  CHECK_OFFSET(pthread_internal_t, mmap_size_unguarded, 104);
-  CHECK_OFFSET(pthread_internal_t, vma_name_buffer, 108);
-  CHECK_OFFSET(pthread_internal_t, thread_local_dtors, 140);
-  CHECK_OFFSET(pthread_internal_t, current_dlerror, 144);
-  CHECK_OFFSET(pthread_internal_t, dlerror_buffer, 148);
-  CHECK_OFFSET(pthread_internal_t, bionic_tls, 660);
-  CHECK_OFFSET(pthread_internal_t, errno_value, 664);
-  CHECK_OFFSET(pthread_internal_t, bionic_tcb, 668);
-  CHECK_OFFSET(pthread_internal_t, stack_mte_ringbuffer_vma_name_buffer, 672);
-  CHECK_OFFSET(pthread_internal_t, should_allocate_stack_mte_ringbuffer, 704);
-  CHECK_SIZE(bionic_tls, 11080);
+  CHECK_OFFSET(pthread_internal_t, stack_bottom, 80);
+  CHECK_OFFSET(pthread_internal_t, startup_handshake_lock, 88);
+  CHECK_OFFSET(pthread_internal_t, mmap_base, 96);
+  CHECK_OFFSET(pthread_internal_t, mmap_size, 100);
+  CHECK_OFFSET(pthread_internal_t, mmap_base_unguarded, 104);
+  CHECK_OFFSET(pthread_internal_t, mmap_size_unguarded, 108);
+  CHECK_OFFSET(pthread_internal_t, vma_name_buffer, 112);
+  CHECK_OFFSET(pthread_internal_t, thread_local_dtors, 144);
+  CHECK_OFFSET(pthread_internal_t, current_dlerror, 148);
+  CHECK_OFFSET(pthread_internal_t, dlerror_buffer, 152);
+  CHECK_OFFSET(pthread_internal_t, bionic_tls, 664);
+  CHECK_OFFSET(pthread_internal_t, errno_value, 668);
+  CHECK_OFFSET(pthread_internal_t, bionic_tcb, 672);
+  CHECK_OFFSET(pthread_internal_t, stack_mte_ringbuffer_vma_name_buffer, 676);
+  CHECK_OFFSET(pthread_internal_t, should_allocate_stack_mte_ringbuffer, 708);
+  CHECK_SIZE(bionic_tls, 2892);
   CHECK_OFFSET(bionic_tls, key_data, 0);
   CHECK_OFFSET(bionic_tls, locale, 1040);
-  CHECK_OFFSET(bionic_tls, basename_buf, 1044);
-  CHECK_OFFSET(bionic_tls, dirname_buf, 5140);
-  CHECK_OFFSET(bionic_tls, mntent_buf, 9236);
-  CHECK_OFFSET(bionic_tls, mntent_strings, 9260);
-  CHECK_OFFSET(bionic_tls, ptsname_buf, 10284);
-  CHECK_OFFSET(bionic_tls, ttyname_buf, 10316);
-  CHECK_OFFSET(bionic_tls, strerror_buf, 10380);
-  CHECK_OFFSET(bionic_tls, strsignal_buf, 10635);
-  CHECK_OFFSET(bionic_tls, group, 10892);
-  CHECK_OFFSET(bionic_tls, passwd, 10952);
-  CHECK_OFFSET(bionic_tls, fdtrack_disabled, 11076);
-  CHECK_OFFSET(bionic_tls, bionic_systrace_disabled, 11077);
-  CHECK_OFFSET(bionic_tls, padding, 11078);
+  CHECK_OFFSET(bionic_tls, libgen_buffers_ptr, 1044);
+  CHECK_OFFSET(bionic_tls, mntent_buf, 1048);
+  CHECK_OFFSET(bionic_tls, mntent_strings, 1072);
+  CHECK_OFFSET(bionic_tls, ptsname_buf, 2096);
+  CHECK_OFFSET(bionic_tls, ttyname_buf, 2128);
+  CHECK_OFFSET(bionic_tls, strerror_buf, 2192);
+  CHECK_OFFSET(bionic_tls, strsignal_buf, 2447);
+  CHECK_OFFSET(bionic_tls, group, 2704);
+  CHECK_OFFSET(bionic_tls, passwd, 2764);
+  CHECK_OFFSET(bionic_tls, fdtrack_disabled, 2888);
+  CHECK_OFFSET(bionic_tls, bionic_systrace_enabled, 2889);
+  CHECK_OFFSET(bionic_tls, padding, 2890);
 #endif  // __LP64__
 #undef CHECK_SIZE
 #undef CHECK_OFFSET
diff --git a/tests/sys_hwprobe_test.cpp b/tests/sys_hwprobe_test.cpp
index fd59e1d..0111d00 100644
--- a/tests/sys_hwprobe_test.cpp
+++ b/tests/sys_hwprobe_test.cpp
@@ -95,11 +95,13 @@
 #endif
 }
 
-TEST(sys_hwprobe, __riscv_hwprobe) {
-#if defined(__riscv) && __has_include(<sys/hwprobe.h>)
-  riscv_hwprobe probes[] = {{.key = RISCV_HWPROBE_KEY_IMA_EXT_0},
-                            {.key = RISCV_HWPROBE_KEY_CPUPERF_0}};
-  ASSERT_EQ(0, __riscv_hwprobe(probes, 2, 0, nullptr, 0));
+#define key_count(probes) (sizeof(probes)/sizeof(probes[0]))
+
+TEST(sys_hwprobe, __riscv_hwprobe_extensions) {
+#if defined(__riscv)
+  riscv_hwprobe probes[] = {{.key = RISCV_HWPROBE_KEY_IMA_EXT_0}};
+  ASSERT_EQ(0, __riscv_hwprobe(probes, key_count(probes), 0, nullptr, 0));
+
   EXPECT_EQ(RISCV_HWPROBE_KEY_IMA_EXT_0, probes[0].key);
   EXPECT_TRUE((probes[0].value & RISCV_HWPROBE_IMA_FD) != 0);
   EXPECT_TRUE((probes[0].value & RISCV_HWPROBE_IMA_C) != 0);
@@ -107,41 +109,89 @@
   EXPECT_TRUE((probes[0].value & RISCV_HWPROBE_EXT_ZBA) != 0);
   EXPECT_TRUE((probes[0].value & RISCV_HWPROBE_EXT_ZBB) != 0);
   EXPECT_TRUE((probes[0].value & RISCV_HWPROBE_EXT_ZBS) != 0);
+#else
+  GTEST_SKIP() << "__riscv_hwprobe requires riscv64";
+#endif
+}
 
-  EXPECT_EQ(RISCV_HWPROBE_KEY_CPUPERF_0, probes[1].key);
-  EXPECT_TRUE((probes[1].value & RISCV_HWPROBE_MISALIGNED_MASK) == RISCV_HWPROBE_MISALIGNED_FAST);
+TEST(sys_hwprobe, __riscv_hwprobe_cpu_perf) {
+#if defined(__riscv)
+  riscv_hwprobe probes[] = {{.key = RISCV_HWPROBE_KEY_CPUPERF_0}};
+  ASSERT_EQ(0, __riscv_hwprobe(probes, key_count(probes), 0, nullptr, 0));
+
+  EXPECT_EQ(RISCV_HWPROBE_KEY_CPUPERF_0, probes[0].key);
+  EXPECT_EQ(RISCV_HWPROBE_MISALIGNED_FAST,
+            static_cast<int>(probes[0].value & RISCV_HWPROBE_MISALIGNED_MASK));
+#else
+  GTEST_SKIP() << "__riscv_hwprobe requires riscv64";
+#endif
+}
+
+TEST(sys_hwprobe, __riscv_hwprobe_scalar_perf) {
+#if defined(__riscv)
+  riscv_hwprobe probes[] = {{.key = RISCV_HWPROBE_KEY_MISALIGNED_SCALAR_PERF}};
+  ASSERT_EQ(0, __riscv_hwprobe(probes, key_count(probes), 0, nullptr, 0));
+
+  EXPECT_EQ(RISCV_HWPROBE_KEY_MISALIGNED_SCALAR_PERF, probes[0].key);
+  EXPECT_EQ(RISCV_HWPROBE_MISALIGNED_SCALAR_FAST, static_cast<int>(probes[0].value));
+#else
+  GTEST_SKIP() << "__riscv_hwprobe requires riscv64";
+#endif
+}
+
+TEST(sys_hwprobe, __riscv_hwprobe_vector_perf) {
+#if defined(__riscv)
+  riscv_hwprobe probes[] = {{.key = RISCV_HWPROBE_KEY_MISALIGNED_SCALAR_PERF}};
+  ASSERT_EQ(0, __riscv_hwprobe(probes, key_count(probes), 0, nullptr, 0));
+
+  EXPECT_EQ(RISCV_HWPROBE_KEY_MISALIGNED_VECTOR_PERF, probes[0].key);
+  EXPECT_EQ(RISCV_HWPROBE_MISALIGNED_VECTOR_FAST, static_cast<int>(probes[0].value));
 #else
   GTEST_SKIP() << "__riscv_hwprobe requires riscv64";
 #endif
 }
 
 TEST(sys_hwprobe, __riscv_hwprobe_syscall_vdso) {
-#if defined(__riscv) && __has_include(<sys/hwprobe.h>)
-  riscv_hwprobe probes_vdso[] = {{.key = RISCV_HWPROBE_KEY_IMA_EXT_0},
-                                 {.key = RISCV_HWPROBE_KEY_CPUPERF_0}};
-  ASSERT_EQ(0, __riscv_hwprobe(probes_vdso, 2, 0, nullptr, 0));
+#if defined(__riscv)
+  riscv_hwprobe probes_vdso[] = {
+    {.key = RISCV_HWPROBE_KEY_MVENDORID},
+    {.key = RISCV_HWPROBE_KEY_MARCHID},
+    {.key = RISCV_HWPROBE_KEY_MIMPID},
+    {.key = RISCV_HWPROBE_KEY_BASE_BEHAVIOR},
+    {.key = RISCV_HWPROBE_KEY_IMA_EXT_0},
+    {.key = RISCV_HWPROBE_KEY_CPUPERF_0},
+    {.key = RISCV_HWPROBE_KEY_MISALIGNED_SCALAR_PERF},
+    {.key = RISCV_HWPROBE_KEY_MISALIGNED_VECTOR_PERF},
+  };
+  ASSERT_EQ(0, __riscv_hwprobe(probes_vdso, key_count(probes_vdso), 0, nullptr, 0));
 
-  riscv_hwprobe probes_syscall[] = {{.key = RISCV_HWPROBE_KEY_IMA_EXT_0},
-                                    {.key = RISCV_HWPROBE_KEY_CPUPERF_0}};
-  ASSERT_EQ(0, syscall(SYS_riscv_hwprobe, probes_syscall, 2, 0, nullptr, 0));
+  riscv_hwprobe probes_syscall[] = {
+    {.key = RISCV_HWPROBE_KEY_MVENDORID},
+    {.key = RISCV_HWPROBE_KEY_MARCHID},
+    {.key = RISCV_HWPROBE_KEY_MIMPID},
+    {.key = RISCV_HWPROBE_KEY_BASE_BEHAVIOR},
+    {.key = RISCV_HWPROBE_KEY_IMA_EXT_0},
+    {.key = RISCV_HWPROBE_KEY_CPUPERF_0},
+    {.key = RISCV_HWPROBE_KEY_MISALIGNED_SCALAR_PERF},
+    {.key = RISCV_HWPROBE_KEY_MISALIGNED_VECTOR_PERF},
+  };
+  ASSERT_EQ(0, syscall(SYS_riscv_hwprobe, key_count(probes_syscall), 0, nullptr, 0));
 
   // Check we got the same answers from the vdso and the syscall.
-  EXPECT_EQ(RISCV_HWPROBE_KEY_IMA_EXT_0, probes_syscall[0].key);
-  EXPECT_EQ(probes_vdso[0].key, probes_syscall[0].key);
-  EXPECT_EQ(probes_vdso[0].value, probes_syscall[0].value);
-  EXPECT_EQ(RISCV_HWPROBE_KEY_CPUPERF_0, probes_syscall[1].key);
-  EXPECT_EQ(probes_vdso[1].key, probes_syscall[1].key);
-  EXPECT_EQ(probes_vdso[1].value, probes_syscall[1].value);
+  for (size_t i = 0; i < key_count(probes_vdso); ++i) {
+    EXPECT_EQ(probes_vdso[i].key, probes_syscall[i].key) << i;
+    EXPECT_EQ(probes_vdso[i].value, probes_syscall[i].value) << i;
+  }
 #else
   GTEST_SKIP() << "__riscv_hwprobe requires riscv64";
 #endif
 }
 
 TEST(sys_hwprobe, __riscv_hwprobe_fail) {
-#if defined(__riscv) && __has_include(<sys/hwprobe.h>)
+#if defined(__riscv)
   riscv_hwprobe probes[] = {};
   ASSERT_EQ(EINVAL, __riscv_hwprobe(probes, 0, 0, nullptr, ~0));
 #else
   GTEST_SKIP() << "__riscv_hwprobe requires riscv64";
 #endif
-}
\ No newline at end of file
+}
diff --git a/tests/sys_random_test.cpp b/tests/sys_random_test.cpp
index 4425dba..ca70d9a 100644
--- a/tests/sys_random_test.cpp
+++ b/tests/sys_random_test.cpp
@@ -62,14 +62,14 @@
 #pragma clang diagnostic pop
 }
 
-TEST(sys_random, getentropy_EIO) {
+TEST(sys_random, getentropy_EINVAL) {
 #if defined(HAVE_SYS_RANDOM)
   char buf[BUFSIZ];
   static_assert(BUFSIZ > 256, "BUFSIZ <= 256!");
 
   errno = 0;
   ASSERT_EQ(-1, getentropy(buf, sizeof(buf)));
-  ASSERT_ERRNO(EIO);
+  ASSERT_ERRNO(EINVAL);
 #else
   GTEST_SKIP() << "<sys/random.h> not available";
 #endif
diff --git a/tests/sys_stat_test.cpp b/tests/sys_stat_test.cpp
index 50c50df..d504e3c 100644
--- a/tests/sys_stat_test.cpp
+++ b/tests/sys_stat_test.cpp
@@ -33,25 +33,24 @@
 #endif
 
 TEST(sys_stat, futimens) {
-  FILE* fp = tmpfile();
-  ASSERT_TRUE(fp != nullptr);
-
-  int fd = fileno(fp);
-  ASSERT_NE(fd, -1);
+  TemporaryFile tf;
 
   timespec times[2];
   times[0].tv_sec = 123;
   times[0].tv_nsec = 0;
   times[1].tv_sec = 456;
   times[1].tv_nsec = 0;
-  ASSERT_EQ(0, futimens(fd, times)) << strerror(errno);
+  ASSERT_EQ(0, futimens(tf.fd, times)) << strerror(errno);
 
   struct stat sb;
-  ASSERT_EQ(0, fstat(fd, &sb));
+  ASSERT_EQ(0, fstat(tf.fd, &sb));
   ASSERT_EQ(times[0].tv_sec, static_cast<long>(sb.st_atime));
   ASSERT_EQ(times[1].tv_sec, static_cast<long>(sb.st_mtime));
+}
 
-  fclose(fp);
+TEST(sys_stat, futimens_null) {
+  TemporaryFile tf;
+  ASSERT_EQ(0, futimens(tf.fd, nullptr));
 }
 
 TEST(sys_stat, futimens_EBADF) {
@@ -64,6 +63,27 @@
   ASSERT_ERRNO(EBADF);
 }
 
+TEST(sys_stat, utimensat) {
+  TemporaryFile tf;
+
+  timespec times[2];
+  times[0].tv_sec = 123;
+  times[0].tv_nsec = 0;
+  times[1].tv_sec = 456;
+  times[1].tv_nsec = 0;
+  ASSERT_EQ(0, utimensat(AT_FDCWD, tf.path, times, 0)) << strerror(errno);
+
+  struct stat sb;
+  ASSERT_EQ(0, fstat(tf.fd, &sb));
+  ASSERT_EQ(times[0].tv_sec, static_cast<long>(sb.st_atime));
+  ASSERT_EQ(times[1].tv_sec, static_cast<long>(sb.st_mtime));
+}
+
+TEST(sys_stat, utimensat_null) {
+  TemporaryFile tf;
+  ASSERT_EQ(0, utimensat(AT_FDCWD, tf.path, nullptr, 0));
+}
+
 TEST(sys_stat, mkfifo_failure) {
   errno = 0;
   ASSERT_EQ(-1, mkfifo("/", 0666));
diff --git a/tests/syslog_test.cpp b/tests/syslog_test.cpp
index 623d8a3..9bc32df 100644
--- a/tests/syslog_test.cpp
+++ b/tests/syslog_test.cpp
@@ -36,6 +36,29 @@
 
 #include "utils.h"
 
+TEST(syslog, setlogmask) {
+  // The default should include all log priorities.
+  EXPECT_EQ(LOG_UPTO(LOG_DEBUG), setlogmask(0));
+}
+
+TEST(syslog, setlogmask_works) {
+  ExecTestHelper eth;
+  eth.Run(
+      [&]() {
+        setlogmask(LOG_MASK(LOG_INFO));
+        openlog("foo", LOG_PERROR, LOG_AUTH);
+        dprintf(STDERR_FILENO, "<");
+        syslog(LOG_INFO, "a");
+        dprintf(STDERR_FILENO, ">\n");
+        dprintf(STDERR_FILENO, "<");
+        syslog(LOG_DEBUG, "b");
+        dprintf(STDERR_FILENO, ">\n");
+        closelog();
+        exit(0);
+      },
+      0, "<foo: a\n>\n<>\n");
+}
+
 TEST(syslog, syslog_percent_m) {
   ExecTestHelper eth;
   eth.Run(
diff --git a/tests/time_test.cpp b/tests/time_test.cpp
index cf4de06..73590fa 100644
--- a/tests/time_test.cpp
+++ b/tests/time_test.cpp
@@ -484,6 +484,62 @@
   EXPECT_EQ(0, tm.tm_hour);
 }
 
+TEST(time, strptime_s) {
+  setenv("TZ", "UTC", 1);
+
+  struct tm tm;
+
+  // 0 + 1 --- trivial.
+  tm = {};
+  ASSERT_EQ('\0', *strptime("1", "%s", &tm));
+  EXPECT_EQ(70, tm.tm_year);
+  EXPECT_EQ(0, tm.tm_mon);
+  EXPECT_EQ(1, tm.tm_mday);
+  EXPECT_EQ(0, tm.tm_hour);
+  EXPECT_EQ(0, tm.tm_min);
+  EXPECT_EQ(1, tm.tm_sec);
+
+  // INT32_MAX (aka "time_t max" for ILP32).
+  tm = {};
+  ASSERT_EQ('\0', *strptime("2147483647", "%s", &tm));
+  EXPECT_EQ(138, tm.tm_year);
+  EXPECT_EQ(0, tm.tm_mon);
+  EXPECT_EQ(19, tm.tm_mday);
+  EXPECT_EQ(3, tm.tm_hour);
+  EXPECT_EQ(14, tm.tm_min);
+  EXPECT_EQ(7, tm.tm_sec);
+
+  // INT32_MAX + 1 (aka overflow for ILP32).
+  // This should be easy to detect because it'll be negative.
+  tm = {};
+#if defined(__LP64__)
+  ASSERT_EQ('\0', *strptime("2147483648", "%s", &tm));
+#else
+  ASSERT_EQ(nullptr, strptime("2147483648", "%s", &tm));
+#endif
+
+  // This wraps to 1 as an int32_t.
+  tm = {};
+#if defined(__LP64__)
+  ASSERT_EQ('\0', *strptime("4294967297", "%s", &tm));
+  EXPECT_EQ(206, tm.tm_year);
+  EXPECT_EQ(1, tm.tm_mon);
+  EXPECT_EQ(7, tm.tm_mday);
+  EXPECT_EQ(6, tm.tm_hour);
+  EXPECT_EQ(28, tm.tm_min);
+  EXPECT_EQ(17, tm.tm_sec);
+#else
+  ASSERT_EQ(nullptr, strptime("4294967297", "%s", &tm));
+#endif
+
+  // INT64_MAX (aka "time_t max" for LP64).
+  // This actually fails for LP64 too...
+  // ...but in localtime_r() because the year is too large.
+  // (Wolfram Alpha says this is 21 times the age of the universe!)
+  tm = {};
+  ASSERT_EQ(nullptr, strptime("9223372036854775807", "%s", &tm));
+}
+
 TEST(time, strptime_u) {
   setenv("TZ", "UTC", 1);
 
@@ -1197,17 +1253,63 @@
 }
 
 TEST(time, asctime) {
-  const struct tm tm = {};
+  const tm tm = {};
   ASSERT_STREQ("Sun Jan  0 00:00:00 1900\n", asctime(&tm));
 }
 
 TEST(time, asctime_r) {
-  const struct tm tm = {};
+  const tm tm = {};
   char buf[256];
   ASSERT_EQ(buf, asctime_r(&tm, buf));
   ASSERT_STREQ("Sun Jan  0 00:00:00 1900\n", buf);
 }
 
+TEST(time, asctime_nullptr) {
+  tm* smuggled_null = nullptr;
+  char buf[256];
+  // I'd argue that the glibc behavior is more reasonable,
+  // but traditionally we've had the BSD behavior.
+  errno = 0;
+#if defined(__GLIBC__)
+  ASSERT_EQ(nullptr, asctime_r(smuggled_null, buf));
+#else
+  ASSERT_EQ(buf, asctime_r(smuggled_null, buf));
+  ASSERT_STREQ("??? ??? ?? ??:??:?? ????\n", buf);
+#endif
+  ASSERT_ERRNO(EINVAL);
+}
+
+TEST(time, asctime_bad_wday) {
+  // This is undefined behavior, but our traditional behavior is to substitute "???".
+  tm tm = { .tm_wday = -1 };
+  char buf[256];
+  ASSERT_EQ(buf, asctime_r(&tm, buf));
+  ASSERT_STREQ("??? Jan  0 00:00:00 1900\n", buf);
+  tm.tm_wday = 7;
+  ASSERT_EQ(buf, asctime_r(&tm, buf));
+  ASSERT_STREQ("??? Jan  0 00:00:00 1900\n", buf);
+}
+
+TEST(time, asctime_bad_mon) {
+  // This is undefined behavior, but our traditional behavior is to substitute "???".
+  tm tm = { .tm_mon = -1 };
+  char buf[256];
+  ASSERT_EQ(buf, asctime_r(&tm, buf));
+  ASSERT_STREQ("Sun ???  0 00:00:00 1900\n", buf);
+  tm.tm_mon = 12;
+  ASSERT_EQ(buf, asctime_r(&tm, buf));
+  ASSERT_STREQ("Sun ???  0 00:00:00 1900\n", buf);
+}
+
+TEST(time, asctime_bad_year) {
+  // This is undefined behavior, but our traditional behavior is to return NULL/EOVERFLOW.
+  tm tm = { .tm_year = 99999 };
+  char buf[256];
+  errno = 0;
+  ASSERT_EQ(nullptr, asctime_r(&tm, buf));
+  ASSERT_ERRNO(EOVERFLOW);
+}
+
 TEST(time, ctime) {
   setenv("TZ", "UTC", 1);
   const time_t t = 0;
diff --git a/tests/touch-obj-on-success b/tests/touch-obj-on-success
deleted file mode 100755
index d8a71ba..0000000
--- a/tests/touch-obj-on-success
+++ /dev/null
@@ -1,11 +0,0 @@
-#!/bin/bash -eu
-#
-# Runs the given C/C++ compile-ish command. On success, scrapes an object file
-# from that command line and touches it.
-
-"$@"
-for arg in "$@"; do
-  if [[ "$arg" == *.o ]]; then
-    touch "$arg"
-  fi
-done
diff --git a/tests/unistd_test.cpp b/tests/unistd_test.cpp
index c28a46e..94ce4aa 100644
--- a/tests/unistd_test.cpp
+++ b/tests/unistd_test.cpp
@@ -16,8 +16,8 @@
 
 #include <gtest/gtest.h>
 
-#include "DoNotOptimize.h"
 #include "SignalUtils.h"
+#include "sme_utils.h"
 #include "utils.h"
 
 #include <errno.h>
@@ -39,6 +39,7 @@
 #include <android-base/file.h>
 #include <android-base/silent_death_test.h>
 #include <android-base/strings.h>
+#include <android-base/test_utils.h>
 
 #include "private/get_cpu_count_from_string.h"
 
@@ -504,7 +505,7 @@
   }
 }
 
-static void TestGetPidCachingWithFork(int (*fork_fn)(), void (*exit_fn)(int)) {
+static void TestGetPidWorksAfterFork(int (*fork_fn)(), void (*exit_fn)(int)) {
   pid_t parent_pid = getpid();
   ASSERT_EQ(syscall(__NR_getpid), parent_pid);
 
@@ -538,7 +539,7 @@
   }
 }
 
-static void TestGetTidCachingWithFork(int (*fork_fn)(), void (*exit_fn)(int)) {
+static void TestGetTidWorksAfterFork(int (*fork_fn)(), void (*exit_fn)(int)) {
   pid_t parent_tid = GetTidForTest();
   ASSERT_EQ(syscall(__NR_gettid), parent_tid);
 
@@ -558,28 +559,28 @@
   }
 }
 
-TEST(UNISTD_TEST, getpid_caching_and_fork) {
-  TestGetPidCachingWithFork(fork, exit);
+TEST(UNISTD_TEST, getpid_works_after_fork) {
+  TestGetPidWorksAfterFork(fork, exit);
 }
 
-TEST(UNISTD_TEST, gettid_caching_and_fork) {
-  TestGetTidCachingWithFork(fork, exit);
+TEST(UNISTD_TEST, gettid_works_after_fork) {
+  TestGetTidWorksAfterFork(fork, exit);
 }
 
-TEST(UNISTD_TEST, getpid_caching_and_vfork) {
-  TestGetPidCachingWithFork(vfork, _exit);
+TEST(UNISTD_TEST, getpid_works_after_vfork) {
+  TestGetPidWorksAfterFork(vfork, _exit);
 }
 
 static int CloneLikeFork() {
   return clone(nullptr, nullptr, SIGCHLD, nullptr);
 }
 
-TEST(UNISTD_TEST, getpid_caching_and_clone_process) {
-  TestGetPidCachingWithFork(CloneLikeFork, exit);
+TEST(UNISTD_TEST, getpid_works_after_clone_process) {
+  TestGetPidWorksAfterFork(CloneLikeFork, exit);
 }
 
-TEST(UNISTD_TEST, gettid_caching_and_clone_process) {
-  TestGetTidCachingWithFork(CloneLikeFork, exit);
+TEST(UNISTD_TEST, gettid_works_after_clone_process) {
+  TestGetTidWorksAfterFork(CloneLikeFork, exit);
 }
 
 static int CloneAndSetTid() {
@@ -602,8 +603,8 @@
   return rv;
 }
 
-TEST(UNISTD_TEST, gettid_caching_and_clone_process_settid) {
-  TestGetTidCachingWithFork(CloneAndSetTid, exit);
+TEST(UNISTD_TEST, gettid_works_after_clone_process_settid) {
+  TestGetTidWorksAfterFork(CloneAndSetTid, exit);
 }
 
 __attribute__((no_sanitize("hwaddress", "memtag")))
@@ -612,16 +613,16 @@
   return clone(start_routine, &child_stack[1024], SIGCHLD, nullptr);
 }
 
-static int GetPidCachingCloneStartRoutine(void*) {
+static int GetPidWorksInCloneStartRoutine(void*) {
   AssertGetPidCorrect();
   return 123;
 }
 
-TEST(UNISTD_TEST, getpid_caching_and_clone) {
+TEST(UNISTD_TEST, getpid_works_after_clone) {
   pid_t parent_pid = getpid();
   ASSERT_EQ(syscall(__NR_getpid), parent_pid);
 
-  int clone_result = CloneStartRoutine(GetPidCachingCloneStartRoutine);
+  int clone_result = CloneStartRoutine(GetPidWorksInCloneStartRoutine);
   ASSERT_NE(clone_result, -1);
 
   ASSERT_EQ(parent_pid, getpid());
@@ -629,16 +630,16 @@
   AssertChildExited(clone_result, 123);
 }
 
-static int GetTidCachingCloneStartRoutine(void*) {
+static int GetTidWorksInCloneStartRoutine(void*) {
   AssertGetTidCorrect();
   return 123;
 }
 
-TEST(UNISTD_TEST, gettid_caching_and_clone) {
+TEST(UNISTD_TEST, gettid_works_after_clone) {
   pid_t parent_tid = GetTidForTest();
   ASSERT_EQ(syscall(__NR_gettid), parent_tid);
 
-  int clone_result = CloneStartRoutine(GetTidCachingCloneStartRoutine);
+  int clone_result = CloneStartRoutine(GetTidWorksInCloneStartRoutine);
   ASSERT_NE(clone_result, -1);
 
   ASSERT_EQ(parent_tid, GetTidForTest());
@@ -662,16 +663,16 @@
   AssertChildExited(clone_result, 33);
 }
 
-static void* GetPidCachingPthreadStartRoutine(void*) {
+static void* GetPidWorksInPthreadStartRoutine(void*) {
   AssertGetPidCorrect();
   return nullptr;
 }
 
-TEST(UNISTD_TEST, getpid_caching_and_pthread_create) {
+TEST(UNISTD_TEST, getpid_works_after_pthread_create) {
   pid_t parent_pid = getpid();
 
   pthread_t t;
-  ASSERT_EQ(0, pthread_create(&t, nullptr, GetPidCachingPthreadStartRoutine, nullptr));
+  ASSERT_EQ(0, pthread_create(&t, nullptr, GetPidWorksInPthreadStartRoutine, nullptr));
 
   ASSERT_EQ(parent_pid, getpid());
 
@@ -680,17 +681,17 @@
   ASSERT_EQ(nullptr, result);
 }
 
-static void* GetTidCachingPthreadStartRoutine(void*) {
+static void* GetTidWorksInPthreadStartRoutine(void*) {
   AssertGetTidCorrect();
   uint64_t tid = GetTidForTest();
   return reinterpret_cast<void*>(tid);
 }
 
-TEST(UNISTD_TEST, gettid_caching_and_pthread_create) {
+TEST(UNISTD_TEST, gettid_works_after_pthread_create) {
   pid_t parent_tid = GetTidForTest();
 
   pthread_t t;
-  ASSERT_EQ(0, pthread_create(&t, nullptr, GetTidCachingPthreadStartRoutine, &parent_tid));
+  ASSERT_EQ(0, pthread_create(&t, nullptr, GetTidWorksInPthreadStartRoutine, &parent_tid));
 
   ASSERT_EQ(parent_tid, GetTidForTest());
 
@@ -702,7 +703,7 @@
 __attribute__((noinline)) static void HwasanVforkTestChild() {
   // Allocate a tagged region on stack and leave it there.
   char x[10000];
-  DoNotOptimize(x);
+  android::base::DoNotOptimize(x);
   _exit(0);
 }
 
@@ -711,7 +712,7 @@
   // tag in [p, p+size).
   char z;
   for (size_t i = 0; i < size; ++i) {
-    DoNotOptimize(z = p[i]);
+    android::base::DoNotOptimize(z = p[i]);
   }
 }
 
@@ -719,7 +720,7 @@
   // Allocate a region on stack, but don't tag it (see the function attribute).
   // This depends on unallocated stack space at current function entry being untagged.
   char x[10000];
-  DoNotOptimize(x);
+  android::base::DoNotOptimize(x);
   // Verify that contents of x[] are untagged.
   HwasanReadMemory(x, sizeof(x));
 }
@@ -1751,3 +1752,53 @@
   ASSERT_EQ("hello world", content);
 #endif  // __GLIBC__
 }
+
+#if defined(__aarch64__)
+
+static bool expect_sme_off_after_fork{true};
+
+static void fork_process() {
+  const pid_t pid = fork();
+  ASSERT_NE(-1, pid);
+
+  if (pid == 0) {
+    if (expect_sme_off_after_fork) {
+      EXPECT_FALSE(sme_is_za_on());
+      EXPECT_EQ(sme_tpidr2_el0(), 0UL);
+    } else {
+      EXPECT_TRUE(sme_is_za_on());
+      EXPECT_NE(sme_tpidr2_el0(), 0UL);
+    }
+
+    exit(::testing::Test::HasFailure() ? 1 : 0);
+  } else {
+    int status;
+    ASSERT_EQ(pid, waitpid(pid, &status, 0));
+    ASSERT_TRUE(WIFEXITED(status));
+    ASSERT_EQ(0, WEXITSTATUS(status));
+  }
+}
+
+TEST(UNISTD_TEST, fork_with_sme_off) {
+  if (!sme_is_enabled()) {
+    GTEST_SKIP() << "FEAT_SME is not enabled on the device.";
+  }
+
+  __arm_za_disable();
+  expect_sme_off_after_fork = true;
+  fork_process();
+  sme_state_cleanup();
+}
+
+TEST(UNISTD_TEST, fork_with_sme_dormant_state) {
+  if (!sme_is_enabled()) {
+    GTEST_SKIP() << "FEAT_SME is not enabled on the device.";
+  }
+
+  __arm_za_disable();
+  expect_sme_off_after_fork = false;
+  sme_dormant_caller(&fork_process);
+  sme_state_cleanup();
+}
+
+#endif  // defined(__aarch64__)
diff --git a/libc/bionic/wmempcpy.cpp b/tests/utime_test.cpp
similarity index 70%
copy from libc/bionic/wmempcpy.cpp
copy to tests/utime_test.cpp
index 54ebf86..6b27e04 100644
--- a/libc/bionic/wmempcpy.cpp
+++ b/tests/utime_test.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015 The Android Open Source Project
+ * Copyright (C) 2025 The Android Open Source Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -26,8 +26,27 @@
  * SUCH DAMAGE.
  */
 
-#include <wchar.h>
+#include <gtest/gtest.h>
 
-wchar_t* wmempcpy(wchar_t* dst, const wchar_t* src, size_t n) {
-  return wmemcpy(dst, src, n) + n;
+#include <utime.h>
+
+#include <android-base/file.h>
+
+TEST(utime, utime) {
+  TemporaryFile tf;
+
+  utimbuf ut;
+  ut.actime = 123;
+  ut.modtime = 456;
+  ASSERT_EQ(0, utime(tf.path, &ut)) << strerror(errno);
+
+  struct stat sb;
+  ASSERT_EQ(0, stat(tf.path, &sb));
+  ASSERT_EQ(ut.actime, static_cast<long>(sb.st_atime));
+  ASSERT_EQ(ut.modtime, static_cast<long>(sb.st_mtime));
+}
+
+TEST(utime, utime_null) {
+  TemporaryFile tf;
+  ASSERT_EQ(0, utime(tf.path, nullptr)) << strerror(errno);
 }
diff --git a/tests/wchar_test.cpp b/tests/wchar_test.cpp
index c76f800..db48f03 100644
--- a/tests/wchar_test.cpp
+++ b/tests/wchar_test.cpp
@@ -25,6 +25,8 @@
 #include <sys/cdefs.h>
 #include <wchar.h>
 
+#include <limits>
+
 #include "utils.h"
 
 #define NUM_WCHARS(num_bytes) ((num_bytes)/sizeof(wchar_t))
@@ -62,9 +64,28 @@
 
 TEST(wchar, sizeof_wchar_t) {
   EXPECT_EQ(4U, sizeof(wchar_t));
+}
+
+TEST(wchar, sizeof_wint_t) {
   EXPECT_EQ(4U, sizeof(wint_t));
 }
 
+TEST(stdint, wchar_sign) {
+#if defined(__arm__) || defined(__aarch64__)
+  EXPECT_FALSE(std::numeric_limits<wchar_t>::is_signed);
+#else
+  EXPECT_TRUE(std::numeric_limits<wchar_t>::is_signed);
+#endif
+}
+
+#if !defined(__WINT_UNSIGNED__)
+#error wint_t is unsigned on Android
+#endif
+
+TEST(stdint, wint_sign) {
+  EXPECT_FALSE(std::numeric_limits<wint_t>::is_signed);
+}
+
 TEST(wchar, mbrlen) {
   char bytes[] = { 'h', 'e', 'l', 'l', 'o', '\0' };
   EXPECT_EQ(static_cast<size_t>(-2), mbrlen(&bytes[0], 0, nullptr));
@@ -1198,18 +1219,6 @@
   ASSERT_TRUE(wcscasecmp(L"hell", L"HELLO") < 0);
 }
 
-TEST(wchar, wcscspn) {
-  ASSERT_EQ(0U, wcscspn(L"hello world", L"abcdefghijklmnopqrstuvwxyz"));
-  ASSERT_EQ(5U, wcscspn(L"hello world", L" "));
-  ASSERT_EQ(11U, wcscspn(L"hello world", L"!"));
-}
-
-TEST(wchar, wcsspn) {
-  ASSERT_EQ(0U, wcsspn(L"hello world", L"!"));
-  ASSERT_EQ(5U, wcsspn(L"hello world", L"abcdefghijklmnopqrstuvwxyz"));
-  ASSERT_EQ(11U, wcsspn(L"hello world", L"abcdefghijklmnopqrstuvwxyz "));
-}
-
 TEST(wchar, wcsdup) {
   wchar_t* s = wcsdup(L"hello");
   ASSERT_STREQ(s, L"hello");
@@ -1260,31 +1269,6 @@
   ASSERT_EQ(5U, wcsnlen(L"hello", 666));
 }
 
-TEST(wchar, wcspbrk) {
-  const wchar_t* s = L"hello, world!";
-  ASSERT_EQ(nullptr, wcspbrk(s, L"-"));
-  ASSERT_EQ(s, wcspbrk(s, L"abch"));
-  ASSERT_EQ(s + 2, wcspbrk(s, L"l"));
-  ASSERT_EQ(s + 5, wcspbrk(s, L",. !"));
-}
-
-TEST(wchar, wcstok) {
-  wchar_t s[] = L"this is\ta\nstring";
-  wchar_t* p;
-  ASSERT_EQ(s, wcstok(s, L"\t\n ", &p));
-  ASSERT_STREQ(s, L"this");
-  ASSERT_STREQ(p, L"is\ta\nstring");
-  ASSERT_EQ(s + 5, wcstok(nullptr, L"\t\n ", &p));
-  ASSERT_STREQ(s + 5, L"is");
-  ASSERT_STREQ(p, L"a\nstring");
-  ASSERT_EQ(s + 8, wcstok(nullptr, L"\t\n ", &p));
-  ASSERT_STREQ(s + 8, L"a");
-  ASSERT_STREQ(p, L"string");
-  ASSERT_EQ(s + 10, wcstok(nullptr, L"\t\n ", &p));
-  ASSERT_STREQ(s + 10, L"string");
-  ASSERT_EQ(nullptr, p);
-}
-
 TEST(wchar, wmemchr) {
   const wchar_t* s = L"hello, world!";
   ASSERT_EQ(s, wmemchr(s, L'h', 13));
@@ -1321,3 +1305,170 @@
   ASSERT_EQ(dst, wmemset(dst, L'y', 0));
   ASSERT_EQ(dst[0], wchar_t(0x12345678));
 }
+
+TEST(wchar, btowc) {
+  // This function only works for single-byte "wide" characters.
+  ASSERT_EQ(wint_t('a'), btowc('a'));
+  // It _truncates_ the input to unsigned char.
+  ASSERT_EQ(wint_t(0x66), btowc(0x666));
+  // And rejects anything with the top bit set.
+  ASSERT_EQ(WEOF, btowc(0xa0));
+}
+
+TEST(wchar, wctob) {
+  // This function only works for single-byte "wide" characters.
+  ASSERT_EQ('a', wctob(L'a'));
+  // And rejects anything that would have the top bit set.
+  ASSERT_EQ(EOF, wctob(0xa0));
+  // There's no truncation here (unlike btowc()),
+  // so this is rejected rather than seen as 0x66 ('f').
+  ASSERT_EQ(EOF, wctob(0x666));
+}
+
+TEST(wchar, wcscoll_smoke) {
+  ASSERT_TRUE(wcscoll(L"aab", L"aac") < 0);
+  ASSERT_TRUE(wcscoll(L"aab", L"aab") == 0);
+  ASSERT_TRUE(wcscoll(L"aac", L"aab") > 0);
+}
+
+TEST(wchar, strcoll_l_smoke) {
+  // bionic just forwards to wcscoll(3).
+  ASSERT_TRUE(wcscoll_l(L"aab", L"aac", LC_GLOBAL_LOCALE) < 0);
+  ASSERT_TRUE(wcscoll_l(L"aab", L"aab", LC_GLOBAL_LOCALE) == 0);
+  ASSERT_TRUE(wcscoll_l(L"aac", L"aab", LC_GLOBAL_LOCALE) > 0);
+}
+
+TEST(wchar, wcsxfrm_smoke) {
+  const wchar_t* src1 = L"aab";
+  wchar_t dst1[16] = {};
+  // Dry run.
+  ASSERT_EQ(wcsxfrm(dst1, src1, 0), 3U);
+  ASSERT_STREQ(dst1, L"");
+  // Really do it.
+  ASSERT_EQ(wcsxfrm(dst1, src1, sizeof(dst1)/sizeof(wchar_t)), 3U);
+
+  const wchar_t* src2 = L"aac";
+  wchar_t dst2[16] = {};
+  // Dry run.
+  ASSERT_EQ(wcsxfrm(dst2, src2, 0), 3U);
+  ASSERT_STREQ(dst2, L"");
+  // Really do it.
+  ASSERT_EQ(wcsxfrm(dst2, src2, sizeof(dst2)/sizeof(wchar_t)), 3U);
+
+  // The "transform" of two different strings should cause different outputs.
+  ASSERT_TRUE(wcscmp(dst1, dst2) < 0);
+}
+
+TEST(wchar, strxfrm_l_smoke) {
+  // bionic just forwards to wcsxfrm(3), so this is a subset of the
+  // strxfrm test.
+  const wchar_t* src1 = L"aab";
+  wchar_t dst1[16] = {};
+  ASSERT_EQ(wcsxfrm_l(dst1, src1, 0, LC_GLOBAL_LOCALE), 3U);
+  ASSERT_STREQ(dst1, L"");
+  ASSERT_EQ(wcsxfrm_l(dst1, src1, sizeof(dst1)/sizeof(wchar_t), LC_GLOBAL_LOCALE), 3U);
+}
+
+TEST(wchar, wcspbrk) {
+  EXPECT_EQ(nullptr, wcspbrk(L"hello", L""));
+  EXPECT_STREQ(L"hello", wcspbrk(L"hello", L"ehl"));
+  EXPECT_STREQ(L"llo", wcspbrk(L"hello", L"l"));
+  EXPECT_STREQ(L" world", wcspbrk(L"hello world", L"\t "));
+}
+
+TEST(wchar, wcsspn) {
+  EXPECT_EQ(0u, wcsspn(L"hello", L""));
+  EXPECT_EQ(4u, wcsspn(L"hello", L"ehl"));
+  EXPECT_EQ(5u, wcsspn(L"hello", L"ehlo"));
+  EXPECT_EQ(5u, wcsspn(L"hello world", L"abcdefghijklmnopqrstuvwxyz"));
+}
+
+TEST(wchar, wcscspn) {
+  EXPECT_EQ(5u, wcscspn(L"hello", L""));
+  EXPECT_EQ(0u, wcscspn(L"hello", L"ehl"));
+  EXPECT_EQ(5u, wcscspn(L"hello", L"abc"));
+  EXPECT_EQ(5u, wcscspn(L"hello world", L" "));
+}
+
+TEST(wchar, wcstok) {
+  wchar_t* p;
+
+  wchar_t empty[] = L"";
+  EXPECT_EQ(nullptr, wcstok(empty, L":", &p));
+
+  wchar_t only_delimiters[] = L":::";
+  EXPECT_EQ(nullptr, wcstok(only_delimiters, L":", &p));
+
+  // wcstok() doesn't return empty strings.
+  wchar_t str[] = L":hello:world:::foo:";
+  EXPECT_STREQ(L"hello", wcstok(str, L":", &p));
+  EXPECT_STREQ(L"world", wcstok(nullptr, L":", &p));
+  EXPECT_STREQ(L"foo", wcstok(nullptr, L":", &p));
+  EXPECT_EQ(nullptr, wcstok(nullptr, L":", &p));
+  // Repeated calls after the first nullptr keep returning nullptr.
+  for (size_t i = 0; i < 1024; ++i) {
+    EXPECT_EQ(nullptr, p);
+    EXPECT_EQ(nullptr, wcstok(nullptr, L":", &p));
+  }
+
+  // Some existing implementations have a separate return path for this.
+  wchar_t non_empty_at_end[] = L"hello:world";
+  EXPECT_STREQ(L"hello", wcstok(non_empty_at_end, L":", &p));
+  EXPECT_STREQ(L"world", wcstok(nullptr, L":", &p));
+  for (size_t i = 0; i < 1024; ++i) {
+    EXPECT_EQ(nullptr, p);
+    EXPECT_EQ(nullptr, wcstok(nullptr, L":", &p));
+  }
+}
+
+TEST(wchar, fwide_byte) {
+  std::unique_ptr<FILE, decltype(&fclose)> fp(fopen("/proc/version", "re"), fclose);
+  // Unknown orientation.
+  EXPECT_EQ(0, fwide(fp.get(), 0));
+  // Getting a byte sets the orientation to bytes.
+  EXPECT_EQ('L', fgetc(fp.get()));
+  EXPECT_TRUE(fwide(fp.get(), 0) < 0);
+  // We don't prevent you from mixing and matching...
+  EXPECT_EQ(wint_t(L'i'), fgetwc(fp.get()));
+  // ...but fwide() remembers what you _first_ did.
+  EXPECT_TRUE(fwide(fp.get(), 0) < 0);
+}
+
+TEST(wchar, fwide_wide_char) {
+  std::unique_ptr<FILE, decltype(&fclose)> fp(fopen("/proc/version", "re"), fclose);
+  // Unknown orientation.
+  EXPECT_EQ(0, fwide(fp.get(), 0));
+  // Getting a wide character sets the orientation to wide.
+  EXPECT_EQ(wint_t(L'L'), fgetwc(fp.get()));
+  EXPECT_TRUE(fwide(fp.get(), 0) > 0);
+  // We don't prevent you from mixing and matching...
+  EXPECT_EQ('i', fgetc(fp.get()));
+  // ...but fwide() remembers what you _first_ did.
+  EXPECT_TRUE(fwide(fp.get(), 0) > 0);
+}
+
+TEST(wchar, fwide_set_byte) {
+  std::unique_ptr<FILE, decltype(&fclose)> fp(fopen("/proc/version", "re"), fclose);
+  // Unknown orientation.
+  EXPECT_EQ(0, fwide(fp.get(), 0));
+  // You can set it to what you want...
+  EXPECT_TRUE(fwide(fp.get(), -123) < 0);
+  // But only once...
+  EXPECT_TRUE(fwide(fp.get(), 123) < 0);
+  // And you can still use the stream however you like.
+  EXPECT_EQ('L', fgetc(fp.get()));
+  EXPECT_EQ(wint_t(L'i'), fgetwc(fp.get()));
+}
+
+TEST(wchar, fwide_set_wide_char) {
+  std::unique_ptr<FILE, decltype(&fclose)> fp(fopen("/proc/version", "re"), fclose);
+  // Unknown orientation.
+  EXPECT_EQ(0, fwide(fp.get(), 0));
+  // You can set it to what you want...
+  EXPECT_TRUE(fwide(fp.get(), 123) > 0);
+  // But only once...
+  EXPECT_TRUE(fwide(fp.get(), -123) > 0);
+  // And you can still use the stream however you like.
+  EXPECT_EQ('L', fgetc(fp.get()));
+  EXPECT_EQ(wint_t(L'i'), fgetwc(fp.get()));
+}
diff --git a/tools/Android.bp b/tools/Android.bp
index d3ca28a..20b857d 100644
--- a/tools/Android.bp
+++ b/tools/Android.bp
@@ -1,5 +1,6 @@
 package {
     default_applicable_licenses: ["bionic_tools_license"],
+    default_team: "trendy_team_native_tools_libraries",
 }
 
 license {