Merge "Remove <stdlib.h> abs/labs/llabs inline for API level 19."
diff --git a/libc/Android.bp b/libc/Android.bp
index c5ed234..b86313c 100644
--- a/libc/Android.bp
+++ b/libc/Android.bp
@@ -2300,7 +2300,6 @@
     ],
     arch: {
         arm64: {
-            cflags: ["-DHAVE_ASSEMBLER___MEMCPY_CHK"],
             srcs: [
                 "arch-arm64/string/__memcpy_chk.S",
             ],
diff --git a/libc/include/android/legacy_sys_wait_inlines.h b/libc/include/android/legacy_sys_wait_inlines.h
deleted file mode 100644
index eadc752..0000000
--- a/libc/include/android/legacy_sys_wait_inlines.h
+++ /dev/null
@@ -1,47 +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.
- */
-
-#pragma once
-
-#include <sys/cdefs.h>
-
-#if __ANDROID_API__ < 18
-
-#include <sys/syscall.h>
-#include <sys/wait.h>
-#include <unistd.h>
-
-__BEGIN_DECLS
-
-static __inline pid_t wait4(pid_t pid, int* status, int options, struct rusage* rusage) {
-  return __BIONIC_CAST(static_cast, pid_t, syscall(__NR_wait4, pid, status, options, rusage));
-}
-
-__END_DECLS
-
-#endif
diff --git a/libc/include/fenv.h b/libc/include/fenv.h
index 3fd9852..5f15ff3 100644
--- a/libc/include/fenv.h
+++ b/libc/include/fenv.h
@@ -46,18 +46,18 @@
 // fenv was always available on x86.
 #if __ANDROID_API__ >= 21 || defined(__i386__)
 int feclearexcept(int __exceptions) __INTRODUCED_IN_ARM(21) __INTRODUCED_IN_X86(9);
-int fegetexceptflag(fexcept_t* __flag_ptr, int __exceptions) __INTRODUCED_IN_ARM(21) __INTRODUCED_IN_X86(9);
+int fegetexceptflag(fexcept_t* _Nonnull __flag_ptr, int __exceptions) __INTRODUCED_IN_ARM(21) __INTRODUCED_IN_X86(9);
 int feraiseexcept(int __exceptions) __INTRODUCED_IN_ARM(21) __INTRODUCED_IN_X86(9);
-int fesetexceptflag(const fexcept_t* __flag_ptr, int __exceptions) __INTRODUCED_IN_ARM(21) __INTRODUCED_IN_X86(9);
+int fesetexceptflag(const fexcept_t* _Nonnull __flag_ptr, int __exceptions) __INTRODUCED_IN_ARM(21) __INTRODUCED_IN_X86(9);
 int fetestexcept(int __exceptions) __INTRODUCED_IN_ARM(21) __INTRODUCED_IN_X86(9);
 
 int fegetround(void) __INTRODUCED_IN_ARM(21) __INTRODUCED_IN_X86(9);
 int fesetround(int __rounding_mode) __INTRODUCED_IN_ARM(21) __INTRODUCED_IN_X86(9);
 
-int fegetenv(fenv_t* __env) __INTRODUCED_IN_ARM(21) __INTRODUCED_IN_X86(9);
-int feholdexcept(fenv_t* __env) __INTRODUCED_IN_ARM(21) __INTRODUCED_IN_X86(9);
-int fesetenv(const fenv_t* __env) __INTRODUCED_IN_ARM(21) __INTRODUCED_IN_X86(9);
-int feupdateenv(const fenv_t* __env) __INTRODUCED_IN_ARM(21) __INTRODUCED_IN_X86(9);
+int fegetenv(fenv_t* _Nonnull __env) __INTRODUCED_IN_ARM(21) __INTRODUCED_IN_X86(9);
+int feholdexcept(fenv_t* _Nonnull __env) __INTRODUCED_IN_ARM(21) __INTRODUCED_IN_X86(9);
+int fesetenv(const fenv_t* _Nonnull __env) __INTRODUCED_IN_ARM(21) __INTRODUCED_IN_X86(9);
+int feupdateenv(const fenv_t* _Nonnull __env) __INTRODUCED_IN_ARM(21) __INTRODUCED_IN_X86(9);
 
 int feenableexcept(int __exceptions) __INTRODUCED_IN_ARM(21) __INTRODUCED_IN_X86(9);
 int fedisableexcept(int __exceptions) __INTRODUCED_IN_ARM(21) __INTRODUCED_IN_X86(9);
diff --git a/libc/include/glob.h b/libc/include/glob.h
index 0ba2848..2c2b8d1 100644
--- a/libc/include/glob.h
+++ b/libc/include/glob.h
@@ -47,21 +47,23 @@
   size_t gl_matchc;	/* Count of paths matching pattern. */
   size_t gl_offs;		/* Reserved at beginning of gl_pathv. */
   int gl_flags;		/* Copy of flags parameter to glob. */
-  char** gl_pathv;	/* List of paths matching pattern. */
 
-  /* Copy of `__error_callback` parameter to glob. */
-  int (*gl_errfunc)(const char* __failure_path, int __failure_errno);
+  /** List of paths matching pattern. */
+  char* _Nullable * _Nullable gl_pathv;
 
-  /*
-   * Alternate filesystem access methods for glob; replacement
-   * versions of closedir(3), readdir(3), opendir(3), stat(2)
-   * and lstat(2).
-   */
-  void (*gl_closedir)(void*);
-  struct dirent* (*gl_readdir)(void*);
-  void* (*gl_opendir)(const char*);
-  int (*gl_lstat)(const char*, struct stat*);
-  int (*gl_stat)(const char*, struct stat*);
+  /** Copy of `__error_callback` parameter to glob. */
+  int (* _Nullable gl_errfunc)(const char* _Nonnull __failure_path, int __failure_errno);
+
+  /** Called instead of closedir() when GLOB_ALTDIRFUNC flag is specified. */
+  void (* _Nullable gl_closedir)(void* _Nonnull);
+  /** Called instead of readdir() when GLOB_ALTDIRFUNC flag is specified. */
+  struct dirent* _Nullable (* _Nonnull gl_readdir)(void* _Nonnull);
+  /** Called instead of opendir() when GLOB_ALTDIRFUNC flag is specified. */
+  void* _Nullable (* _Nonnull gl_opendir)(const char* _Nonnull);
+  /** Called instead of lstat() when GLOB_ALTDIRFUNC flag is specified. */
+  int (* _Nullable gl_lstat)(const char* _Nonnull, struct stat* _Nonnull);
+  /** Called instead of stat() when GLOB_ALTDIRFUNC flag is specified. */
+  int (* _Nullable gl_stat)(const char* _Nonnull, struct stat* _Nonnull);
 } glob_t;
 
 /* Believed to have been introduced in 1003.2-1992 */
@@ -90,8 +92,8 @@
 
 __BEGIN_DECLS
 
-int glob(const char* __pattern, int __flags, int (*__error_callback)(const char* __failure_path, int __failure_errno), glob_t* __result_ptr) __INTRODUCED_IN(28);
-void globfree(glob_t* __result_ptr) __INTRODUCED_IN(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);
+void globfree(glob_t* _Nonnull __result_ptr) __INTRODUCED_IN(28);
 
 __END_DECLS
 
diff --git a/libc/include/pthread.h b/libc/include/pthread.h
index 8bc897a..22f949b 100644
--- a/libc/include/pthread.h
+++ b/libc/include/pthread.h
@@ -26,8 +26,12 @@
  * SUCH DAMAGE.
  */
 
-#ifndef _PTHREAD_H_
-#define _PTHREAD_H_
+#pragma once
+
+/**
+ * @file pthread.h
+ * @brief POSIX threads.
+ */
 
 #include <limits.h>
 #include <bits/pthread_types.h>
@@ -165,8 +169,6 @@
 
 int pthread_getcpuclockid(pthread_t __pthread, clockid_t* __clock);
 
-int pthread_getschedparam(pthread_t __pthread, int* __policy, struct sched_param* __param);
-
 void* pthread_getspecific(pthread_key_t __key);
 
 pid_t pthread_gettid_np(pthread_t __pthread) __INTRODUCED_IN(21);
@@ -283,7 +285,40 @@
 /* TODO: this should be __USE_GNU too. */
 int pthread_setname_np(pthread_t __pthread, const char* __name);
 
+/**
+ * [pthread_setschedparam(3)](https://man7.org/linux/man-pages/man3/pthread_setschedparam.3.html)
+ * sets the scheduler policy and parameters of the given thread.
+ *
+ * This call is not useful to applications on Android, because they don't
+ * have permission to set their scheduling policy, and the only priority
+ * for their policy is 0 anyway. If you only need to set your scheduling
+ * priority, see setpriority() instead.
+ *
+ * Returns 0 on success and returns an error number on failure.
+ */
 int pthread_setschedparam(pthread_t __pthread, int __policy, const struct sched_param* __param);
+
+/**
+ * [pthread_getschedparam(3)](https://man7.org/linux/man-pages/man3/pthread_getschedparam.3.html)
+ * gets the scheduler policy and parameters of the given thread.
+ *
+ * Returns 0 on success and returns an error number on failure.
+ */
+int pthread_getschedparam(pthread_t __pthread, int* __policy, struct sched_param* __param);
+
+/**
+ * [pthread_setschedprio(3)](https://man7.org/linux/man-pages/man3/pthread_setschedprio.3.html)
+ * sets the scheduler priority of the given thread.
+ *
+ * This call is not useful to applications on Android, because they don't
+ * have permission to set their scheduling policy, and the only priority
+ * for their policy is 0 anyway. If you only need to set your scheduling
+ * priority, see setpriority() instead.
+ *
+ * Returns 0 on success and returns an error number on failure.
+ *
+ * Available since API level 28.
+ */
 int pthread_setschedprio(pthread_t __pthread, int __priority) __INTRODUCED_IN(28);
 
 int pthread_setspecific(pthread_key_t __key, const void* __value);
@@ -315,5 +350,3 @@
     } while (0);                                       \
 
 __END_DECLS
-
-#endif
diff --git a/libc/include/string.h b/libc/include/string.h
index 59c4687..74dfbda 100644
--- a/libc/include/string.h
+++ b/libc/include/string.h
@@ -41,20 +41,20 @@
 #include <strings.h>
 #endif
 
-void* memccpy(void* __dst, const void* __src, int __stop_char, size_t __n);
-void* memchr(const void* __s, int __ch, size_t __n) __attribute_pure__;
+void* _Nullable memccpy(void* _Nonnull __dst, const void* _Nonnull __src, int __stop_char, size_t __n);
+void* _Nullable memchr(const void* _Nonnull __s, int __ch, size_t __n) __attribute_pure__;
 #if defined(__cplusplus)
-extern "C++" void* memrchr(void* __s, int __ch, size_t __n) __RENAME(memrchr) __attribute_pure__;
-extern "C++" const void* memrchr(const void* __s, int __ch, size_t __n) __RENAME(memrchr) __attribute_pure__;
+extern "C++" void* _Nullable memrchr(void* _Nonnull __s, int __ch, size_t __n) __RENAME(memrchr) __attribute_pure__;
+extern "C++" const void* _Nullable memrchr(const void* _Nonnull __s, int __ch, size_t __n) __RENAME(memrchr) __attribute_pure__;
 #else
-void* memrchr(const void* __s, int __ch, size_t __n) __attribute_pure__;
+void* _Nullable memrchr(const void* _Nonnull __s, int __ch, size_t __n) __attribute_pure__;
 #endif
-int memcmp(const void* __lhs, const void* __rhs, size_t __n) __attribute_pure__;
-void* memcpy(void*, const void*, size_t);
+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)
-void* mempcpy(void* __dst, const void* __src, size_t __n) __INTRODUCED_IN(23);
+void* _Nonnull mempcpy(void* _Nonnull __dst, const void* _Nonnull __src, size_t __n) __INTRODUCED_IN(23);
 #endif
-void* memmove(void* __dst, const void* __src, size_t __n);
+void* _Nonnull memmove(void* _Nonnull __dst, const void* _Nonnull __src, size_t __n);
 
 /**
  * [memset(3)](http://man7.org/linux/man-pages/man3/memset.3.html) writes the
@@ -62,7 +62,7 @@
  *
  * Returns `dst`.
  */
-void* memset(void* __dst, int __ch, size_t __n);
+void* _Nonnull memset(void* _Nonnull __dst, int __ch, size_t __n);
 
 /**
  * [memset_explicit(3)](http://man7.org/linux/man-pages/man3/memset_explicit.3.html)
@@ -71,74 +71,74 @@
  *
  * Returns `dst`.
  */
-void* memset_explicit(void* __dst, int __ch, size_t __n) __INTRODUCED_IN(34);
+void* _Nonnull memset_explicit(void* _Nonnull __dst, int __ch, size_t __n) __INTRODUCED_IN(34);
 
-void* memmem(const void* __haystack, size_t __haystack_size, const void* __needle, size_t __needle_size) __attribute_pure__;
+void* _Nullable memmem(const void* _Nonnull __haystack, size_t __haystack_size, const void* _Nonnull __needle, size_t __needle_size) __attribute_pure__;
 
-char* strchr(const char* __s, int __ch) __attribute_pure__;
-char* __strchr_chk(const char* __s, int __ch, size_t __n) __INTRODUCED_IN(18);
+char* _Nullable strchr(const char* _Nonnull __s, int __ch) __attribute_pure__;
+char* _Nullable __strchr_chk(const char* _Nonnull __s, int __ch, size_t __n) __INTRODUCED_IN(18);
 #if defined(__USE_GNU)
 #if defined(__cplusplus)
-extern "C++" char* strchrnul(char* __s, int __ch) __RENAME(strchrnul) __attribute_pure__ __INTRODUCED_IN(24);
-extern "C++" const char* strchrnul(const char* __s, int __ch) __RENAME(strchrnul) __attribute_pure__ __INTRODUCED_IN(24);
+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);
 #else
-char* strchrnul(const char* __s, int __ch) __attribute_pure__ __INTRODUCED_IN(24);
+char* _Nonnull strchrnul(const char* _Nonnull __s, int __ch) __attribute_pure__ __INTRODUCED_IN(24);
 #endif
 #endif
 
-char* strrchr(const char* __s, int __ch) __attribute_pure__;
-char* __strrchr_chk(const char* __s, int __ch, size_t __n) __INTRODUCED_IN(18);
+char* _Nullable strrchr(const char* _Nonnull __s, int __ch) __attribute_pure__;
+char* _Nullable __strrchr_chk(const char* _Nonnull __s, int __ch, size_t __n) __INTRODUCED_IN(18);
 
-size_t strlen(const char* __s) __attribute_pure__;
-size_t __strlen_chk(const char* __s, size_t __n) __INTRODUCED_IN(17);
+size_t strlen(const char* _Nonnull __s) __attribute_pure__;
+size_t __strlen_chk(const char* _Nonnull __s, size_t __n) __INTRODUCED_IN(17);
 
-int strcmp(const char* __lhs, const char* __rhs) __attribute_pure__;
-char* stpcpy(char* __dst, const char* __src) __INTRODUCED_IN(21);
-char* strcpy(char* __dst, const char* __src);
-char* strcat(char* __dst, const char* __src);
-char* strdup(const char* __s);
+int strcmp(const char* _Nonnull __lhs, const char* _Nonnull __rhs) __attribute_pure__;
+char* _Nonnull stpcpy(char* _Nonnull __dst, const char* _Nonnull __src) __INTRODUCED_IN(21);
+char* _Nonnull strcpy(char* _Nonnull __dst, const char* _Nonnull __src);
+char* _Nonnull strcat(char* _Nonnull __dst, const char* _Nonnull __src);
+char* _Nullable strdup(const char* _Nonnull __s);
 
-char* strstr(const char* __haystack, const char* __needle) __attribute_pure__;
+char* _Nullable strstr(const char* _Nonnull __haystack, const char* _Nonnull __needle) __attribute_pure__;
 #if defined(__cplusplus)
-extern "C++" char* strcasestr(char*, const char*) __RENAME(strcasestr) __attribute_pure__;
-extern "C++" const char* strcasestr(const char*, const char*) __RENAME(strcasestr) __attribute_pure__;
+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* strcasestr(const char* __haystack, const char* __needle) __attribute_pure__;
+char* _Nullable strcasestr(const char* _Nonnull __haystack, const char* _Nonnull __needle) __attribute_pure__;
 #endif
-char* strtok(char* __s, const char* __delimiter);
-char* strtok_r(char* __s, const char* __delimiter, char** __pos_ptr);
+char* _Nullable strtok(char* _Nullable __s, const char* _Nonnull __delimiter);
+char* _Nullable strtok_r(char* _Nullable __s, const char* _Nonnull __delimiter, char* _Nonnull * _Nonnull __pos_ptr);
 
-char* strerror(int __errno_value);
-char* strerror_l(int __errno_value, locale_t __l) __INTRODUCED_IN(23);
+char* _Nonnull strerror(int __errno_value);
+char* _Nonnull strerror_l(int __errno_value, locale_t _Nonnull __l) __INTRODUCED_IN(23);
 #if defined(__USE_GNU) && __ANDROID_API__ >= 23
-char* strerror_r(int __errno_value, char* __buf, size_t __n) __RENAME(__gnu_strerror_r) __INTRODUCED_IN(23);
+char* _Nonnull strerror_r(int __errno_value, char* _Nullable __buf, size_t __n) __RENAME(__gnu_strerror_r) __INTRODUCED_IN(23);
 #else /* POSIX */
-int strerror_r(int __errno_value, char* __buf, size_t __n);
+int strerror_r(int __errno_value, char* _Nonnull __buf, size_t __n);
 #endif
 
-size_t strnlen(const char* __s, size_t __n) __attribute_pure__;
-char* strncat(char* __dst, const char* __src, size_t __n);
-char* strndup(const char* __s, size_t __n);
-int strncmp(const char* __lhs, const char* __rhs, size_t __n) __attribute_pure__;
-char* stpncpy(char* __dst, const char* __src, size_t __n) __INTRODUCED_IN(21);
-char* strncpy(char* __dst, const char* __src, size_t __n);
+size_t strnlen(const char* _Nonnull __s, size_t __n) __attribute_pure__;
+char* _Nonnull strncat(char* _Nonnull __dst, const char* _Nonnull __src, size_t __n);
+char* _Nullable strndup(const char* _Nonnull __s, size_t __n);
+int strncmp(const char* _Nonnull __lhs, const char* _Nonnull __rhs, size_t __n) __attribute_pure__;
+char* _Nonnull stpncpy(char* _Nonnull __dst, const char* _Nonnull __src, size_t __n) __INTRODUCED_IN(21);
+char* _Nonnull strncpy(char* _Nonnull __dst, const char* _Nonnull __src, size_t __n);
 
-size_t strlcat(char* __dst, const char* __src, size_t __n);
-size_t strlcpy(char* __dst, const char* __src, size_t __n);
+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);
 
-size_t strcspn(const char* __s, const char* __reject) __attribute_pure__;
-char* strpbrk(const char* __s, const char* __accept) __attribute_pure__;
-char* strsep(char** __s_ptr, const char* __delimiter);
-size_t strspn(const char* __s, const char* __accept);
+size_t strcspn(const char* _Nonnull __s, const char* _Nonnull __reject) __attribute_pure__;
+char* _Nullable strpbrk(const char* _Nonnull __s, const char* _Nonnull __accept) __attribute_pure__;
+char* _Nullable strsep(char* _Nullable * _Nonnull __s_ptr, const char* _Nonnull __delimiter);
+size_t strspn(const char* _Nonnull __s, const char* _Nonnull __accept);
 
-char* strsignal(int __signal);
+char* _Nonnull strsignal(int __signal);
 
-int strcoll(const char* __lhs, const char* __rhs) __attribute_pure__;
-size_t strxfrm(char* __dst, const char* __src, size_t __n);
+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);
 
 #if __ANDROID_API__ >= 21
-int strcoll_l(const char* __lhs, const char* __rhs, locale_t __l) __attribute_pure__ __INTRODUCED_IN(21);
-size_t strxfrm_l(char* __dst, const char* __src, size_t __n, locale_t __l) __INTRODUCED_IN(21);
+int strcoll_l(const char* _Nonnull __lhs, const char* _Nonnull __rhs, locale_t _Nonnull __l) __attribute_pure__ __INTRODUCED_IN(21);
+size_t strxfrm_l(char* __BIONIC_COMPLICATED_NULLNESS __dst, const char* _Nonnull __src, size_t __n, locale_t _Nonnull __l) __INTRODUCED_IN(21);
 #else
 // Implemented as static inlines before 21.
 #endif
@@ -149,10 +149,10 @@
  * It doesn't modify its argument, and in C++ it's const-correct.
  */
 #if defined(__cplusplus)
-extern "C++" char* basename(char* __path) __RENAME(__gnu_basename) __INTRODUCED_IN(23);
-extern "C++" const char* basename(const char* __path) __RENAME(__gnu_basename) __INTRODUCED_IN(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);
 #else
-char* basename(const char* __path) __RENAME(__gnu_basename) __INTRODUCED_IN(23);
+char* _Nonnull basename(const char* _Nonnull __path) __RENAME(__gnu_basename) __INTRODUCED_IN(23);
 #endif
 #endif
 
@@ -169,77 +169,77 @@
 #define __prefer_this_overload __enable_if(true, "preferred overload") __enable_if(true, "")
 extern "C++" {
 inline __always_inline
-void* __bionic_memchr(const void* const s __pass_object_size, int c, size_t n) {
+void* _Nullable __bionic_memchr(const void* _Nonnull const s __pass_object_size, int c, size_t n) {
     return memchr(s, c, n);
 }
 
 inline __always_inline
-const void* memchr(const void* const s __pass_object_size, int c, size_t n)
+const void* _Nullable memchr(const void* _Nonnull const s __pass_object_size, int c, size_t n)
         __prefer_this_overload {
     return __bionic_memchr(s, c, n);
 }
 
 inline __always_inline
-void* memchr(void* const s __pass_object_size, int c, size_t n) __prefer_this_overload {
+void* _Nullable memchr(void* _Nonnull const s __pass_object_size, int c, size_t n) __prefer_this_overload {
     return __bionic_memchr(s, c, n);
 }
 
 inline __always_inline
-char* __bionic_strchr(const char* const s __pass_object_size, int c) {
+char* _Nullable __bionic_strchr(const char* _Nonnull const s __pass_object_size, int c) {
     return strchr(s, c);
 }
 
 inline __always_inline
-const char* strchr(const char* const s __pass_object_size, int c)
+const char* _Nullable strchr(const char* _Nonnull const s __pass_object_size, int c)
         __prefer_this_overload {
     return __bionic_strchr(s, c);
 }
 
 inline __always_inline
-char* strchr(char* const s __pass_object_size, int c)
+char* _Nullable strchr(char* _Nonnull const s __pass_object_size, int c)
         __prefer_this_overload {
     return __bionic_strchr(s, c);
 }
 
 inline __always_inline
-char* __bionic_strrchr(const char* const s __pass_object_size, int c) {
+char* _Nullable __bionic_strrchr(const char* _Nonnull const s __pass_object_size, int c) {
     return strrchr(s, c);
 }
 
 inline __always_inline
-const char* strrchr(const char* const s __pass_object_size, int c) __prefer_this_overload {
+const char* _Nullable strrchr(const char* _Nonnull const s __pass_object_size, int c) __prefer_this_overload {
     return __bionic_strrchr(s, c);
 }
 
 inline __always_inline
-char* strrchr(char* const s __pass_object_size, int c) __prefer_this_overload {
+char* _Nullable strrchr(char* _Nonnull const s __pass_object_size, int c) __prefer_this_overload {
     return __bionic_strrchr(s, c);
 }
 
 /* Functions with no FORTIFY counterpart. */
 inline __always_inline
-char* __bionic_strstr(const char* h, const char* n) { return strstr(h, n); }
+char* _Nullable __bionic_strstr(const char* _Nonnull h, const char* _Nonnull n) { return strstr(h, n); }
 
 inline __always_inline
-const char* strstr(const char* h, const char* n) __prefer_this_overload {
+const char* _Nullable strstr(const char* _Nonnull h, const char* _Nonnull n) __prefer_this_overload {
     return __bionic_strstr(h, n);
 }
 
 inline __always_inline
-char* strstr(char* h, const char* n) __prefer_this_overload {
+char* _Nullable strstr(char* _Nonnull h, const char* _Nonnull n) __prefer_this_overload {
     return __bionic_strstr(h, n);
 }
 
 inline __always_inline
-char* __bionic_strpbrk(const char* h, const char* n) { return strpbrk(h, n); }
+char* _Nullable __bionic_strpbrk(const char* _Nonnull h, const char* _Nonnull n) { return strpbrk(h, n); }
 
 inline __always_inline
-char* strpbrk(char* h, const char* n) __prefer_this_overload {
+char* _Nullable strpbrk(char* _Nonnull h, const char* _Nonnull n) __prefer_this_overload {
     return __bionic_strpbrk(h, n);
 }
 
 inline __always_inline
-const char* strpbrk(const char* h, const char* n) __prefer_this_overload {
+const char* _Nullable strpbrk(const char* _Nonnull h, const char* _Nonnull n) __prefer_this_overload {
     return __bionic_strpbrk(h, n);
 }
 }
diff --git a/libc/include/strings.h b/libc/include/strings.h
index ff6b925..2f4f764 100644
--- a/libc/include/strings.h
+++ b/libc/include/strings.h
@@ -61,13 +61,13 @@
 
 /** Deprecated. Use memmove() instead. */
 #define bcopy(b1, b2, len) __bionic_bcopy((b1), (b2), (len))
-static __inline__ __always_inline void __bionic_bcopy(const void* b1, void* b2, size_t len) {
+static __inline__ __always_inline void __bionic_bcopy(const void* _Nonnull b1, void* _Nonnull b2, size_t len) {
   __builtin_memmove(b2, b1, len);
 }
 
 /** Deprecated. Use memset() instead. */
 #define bzero(b, len) __bionic_bzero((b), (len))
-static __inline__ __always_inline void __bionic_bzero(void* b, size_t len) {
+static __inline__ __always_inline void __bionic_bzero(void* _Nonnull b, size_t len) {
   __builtin_memset(b, 0, len);
 }
 
diff --git a/libc/include/sys/epoll.h b/libc/include/sys/epoll.h
index 3745737..302c8c3 100644
--- a/libc/include/sys/epoll.h
+++ b/libc/include/sys/epoll.h
@@ -55,10 +55,10 @@
 #undef EPOLL_CLOEXEC
 #endif
 
-int epoll_ctl(int __epoll_fd, int __op, int __fd, struct epoll_event* __event);
-int epoll_wait(int __epoll_fd, struct epoll_event* __events, int __event_count, int __timeout_ms);
-int epoll_pwait(int __epoll_fd, struct epoll_event* __events, int __event_count, int __timeout_ms, const sigset_t* __mask) __INTRODUCED_IN(21);
-int epoll_pwait64(int __epoll_fd, struct epoll_event* __events, int __event_count, int __timeout_ms, const sigset64_t* __mask) __INTRODUCED_IN(28);
+int epoll_ctl(int __epoll_fd, int __op, int __fd, struct epoll_event* __BIONIC_COMPLICATED_NULLNESS __event);
+int epoll_wait(int __epoll_fd, struct epoll_event* _Nonnull __events, int __event_count, int __timeout_ms);
+int epoll_pwait(int __epoll_fd, struct epoll_event* _Nonnull __events, int __event_count, int __timeout_ms, const sigset_t* _Nullable __mask) __INTRODUCED_IN(21);
+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);
 
 __END_DECLS
 
diff --git a/libc/include/sys/swap.h b/libc/include/sys/swap.h
index 467b98c..9d016d4 100644
--- a/libc/include/sys/swap.h
+++ b/libc/include/sys/swap.h
@@ -58,7 +58,7 @@
  *
  * Available since API level 19.
  */
-int swapon(const char* __path,  int __flags) __INTRODUCED_IN(19);
+int swapon(const char* _Nonnull __path,  int __flags) __INTRODUCED_IN(19);
 
 /**
  * [swapoff(2)](http://man7.org/linux/man-pages/man2/swapoff.2.html) disables swapping.
@@ -67,6 +67,6 @@
  *
  * Available since API level 19.
  */
-int swapoff(const char* __path) __INTRODUCED_IN(19);
+int swapoff(const char* _Nonnull __path) __INTRODUCED_IN(19);
 
 __END_DECLS
diff --git a/libc/include/sys/vfs.h b/libc/include/sys/vfs.h
index ad859f0..18ae428 100644
--- a/libc/include/sys/vfs.h
+++ b/libc/include/sys/vfs.h
@@ -104,10 +104,10 @@
 #define XENIX_SUPER_MAGIC     0x012FF7B4
 #define XFS_SUPER_MAGIC       0x58465342
 
-int statfs(const char* __path, struct statfs* __buf);
-int statfs64(const char* __path, struct statfs64* __buf) __INTRODUCED_IN(21);
-int fstatfs(int __fd, struct statfs* __buf);
-int fstatfs64(int __fd, struct statfs64* __buf) __INTRODUCED_IN(21);
+int statfs(const char* _Nonnull __path, struct statfs* _Nonnull __buf);
+int statfs64(const char* _Nonnull __path, struct statfs64* _Nonnull __buf) __INTRODUCED_IN(21);
+int fstatfs(int __fd, struct statfs* _Nonnull __buf);
+int fstatfs64(int __fd, struct statfs64* _Nonnull __buf) __INTRODUCED_IN(21);
 
 __END_DECLS
 
diff --git a/libc/include/sys/wait.h b/libc/include/sys/wait.h
index 8c0655f..96974a2 100644
--- a/libc/include/sys/wait.h
+++ b/libc/include/sys/wait.h
@@ -26,8 +26,7 @@
  * SUCH DAMAGE.
  */
 
-#ifndef _SYS_WAIT_H_
-#define _SYS_WAIT_H_
+#pragma once
 
 #include <bits/wait.h>
 #include <sys/cdefs.h>
@@ -40,11 +39,7 @@
 
 pid_t wait(int* __status);
 pid_t waitpid(pid_t __pid, int* __status, int __options);
-#if __ANDROID_API__ >= 18
 pid_t wait4(pid_t __pid, int* __status, int __options, struct rusage* __rusage) __INTRODUCED_IN(18);
-#else
-// Implemented as a static inline before 18.
-#endif
 
 /* Posix states that idtype_t should be an enumeration type, but
  * the kernel headers define P_ALL, P_PID and P_PGID as constant macros
@@ -55,7 +50,3 @@
 int waitid(idtype_t __type, id_t __id, siginfo_t* __info, int __options);
 
 __END_DECLS
-
-#include <android/legacy_sys_wait_inlines.h>
-
-#endif
diff --git a/libc/include/wctype.h b/libc/include/wctype.h
index 58510ae..7da2bb4 100644
--- a/libc/include/wctype.h
+++ b/libc/include/wctype.h
@@ -36,30 +36,30 @@
 __BEGIN_DECLS
 
 #if __ANDROID_API__ >= 21
-int iswalnum_l(wint_t __wc, locale_t __l) __INTRODUCED_IN(21);
-int iswalpha_l(wint_t __wc, locale_t __l) __INTRODUCED_IN(21);
-int iswblank_l(wint_t __wc, locale_t __l) __INTRODUCED_IN(21);
-int iswcntrl_l(wint_t __wc, locale_t __l) __INTRODUCED_IN(21);
-int iswdigit_l(wint_t __wc, locale_t __l) __INTRODUCED_IN(21);
-int iswgraph_l(wint_t __wc, locale_t __l) __INTRODUCED_IN(21);
-int iswlower_l(wint_t __wc, locale_t __l) __INTRODUCED_IN(21);
-int iswprint_l(wint_t __wc, locale_t __l) __INTRODUCED_IN(21);
-int iswpunct_l(wint_t __wc, locale_t __l) __INTRODUCED_IN(21);
-int iswspace_l(wint_t __wc, locale_t __l) __INTRODUCED_IN(21);
-int iswupper_l(wint_t __wc, locale_t __l) __INTRODUCED_IN(21);
-int iswxdigit_l(wint_t __wc, locale_t __l) __INTRODUCED_IN(21);
+int iswalnum_l(wint_t __wc, locale_t _Nonnull __l) __INTRODUCED_IN(21);
+int iswalpha_l(wint_t __wc, locale_t _Nonnull __l) __INTRODUCED_IN(21);
+int iswblank_l(wint_t __wc, locale_t _Nonnull __l) __INTRODUCED_IN(21);
+int iswcntrl_l(wint_t __wc, locale_t _Nonnull __l) __INTRODUCED_IN(21);
+int iswdigit_l(wint_t __wc, locale_t _Nonnull __l) __INTRODUCED_IN(21);
+int iswgraph_l(wint_t __wc, locale_t _Nonnull __l) __INTRODUCED_IN(21);
+int iswlower_l(wint_t __wc, locale_t _Nonnull __l) __INTRODUCED_IN(21);
+int iswprint_l(wint_t __wc, locale_t _Nonnull __l) __INTRODUCED_IN(21);
+int iswpunct_l(wint_t __wc, locale_t _Nonnull __l) __INTRODUCED_IN(21);
+int iswspace_l(wint_t __wc, locale_t _Nonnull __l) __INTRODUCED_IN(21);
+int iswupper_l(wint_t __wc, locale_t _Nonnull __l) __INTRODUCED_IN(21);
+int iswxdigit_l(wint_t __wc, locale_t _Nonnull __l) __INTRODUCED_IN(21);
 
-wint_t towlower_l(wint_t __wc, locale_t __l) __INTRODUCED_IN(21);
-wint_t towupper_l(wint_t __wc, locale_t __l) __INTRODUCED_IN(21);
+wint_t towlower_l(wint_t __wc, locale_t _Nonnull __l) __INTRODUCED_IN(21);
+wint_t towupper_l(wint_t __wc, locale_t _Nonnull __l) __INTRODUCED_IN(21);
 #else
 // Implemented as static inlines before 21.
 #endif
 
-wint_t towctrans_l(wint_t __wc, wctrans_t __transform, locale_t __l) __INTRODUCED_IN(26);
-wctrans_t wctrans_l(const char* __name, locale_t __l) __INTRODUCED_IN(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);
 
-wctype_t wctype_l(const char* __name, locale_t __l) __INTRODUCED_IN(21);
-int iswctype_l(wint_t __wc, wctype_t __transform, locale_t __l) __INTRODUCED_IN(21);
+wctype_t wctype_l(const char* _Nonnull __name, locale_t _Nonnull __l) __INTRODUCED_IN(21);
+int iswctype_l(wint_t __wc, wctype_t __transform, locale_t _Nonnull __l) __INTRODUCED_IN(21);
 
 __END_DECLS