Merge "Add sched_getattr()/sched_setattr()." into main
diff --git a/libc/Android.bp b/libc/Android.bp
index 794ccc7..ee50dad 100644
--- a/libc/Android.bp
+++ b/libc/Android.bp
@@ -787,12 +787,6 @@
                 "arch-arm64/string/__memset_chk.S",
             ],
         },
-        riscv64: {
-            srcs: [
-                "arch-riscv64/string/__memset_chk.S",
-                "arch-riscv64/string/__memcpy_chk.S",
-            ],
-        },
     },
 }
 
@@ -1102,21 +1096,21 @@
                 "arch-riscv64/bionic/syscall.S",
                 "arch-riscv64/bionic/vfork.S",
 
-                "arch-riscv64/string/memchr_v.S",
-                "arch-riscv64/string/memcmp_v.S",
-                "arch-riscv64/string/memcpy_v.S",
-                "arch-riscv64/string/memmove_v.S",
-                "arch-riscv64/string/memset_v.S",
-                "arch-riscv64/string/stpcpy_v.S",
-                "arch-riscv64/string/strcat_v.S",
-                "arch-riscv64/string/strchr_v.S",
-                "arch-riscv64/string/strcmp_v.S",
-                "arch-riscv64/string/strcpy_v.S",
-                "arch-riscv64/string/strlen_v.S",
-                "arch-riscv64/string/strncat_v.S",
-                "arch-riscv64/string/strncmp_v.S",
-                "arch-riscv64/string/strncpy_v.S",
-                "arch-riscv64/string/strnlen_v.S",
+                "arch-riscv64/string/memchr.S",
+                "arch-riscv64/string/memcmp.S",
+                "arch-riscv64/string/memcpy.S",
+                "arch-riscv64/string/memmove.S",
+                "arch-riscv64/string/memset.S",
+                "arch-riscv64/string/stpcpy.S",
+                "arch-riscv64/string/strcat.S",
+                "arch-riscv64/string/strchr.S",
+                "arch-riscv64/string/strcmp.S",
+                "arch-riscv64/string/strcpy.S",
+                "arch-riscv64/string/strlen.S",
+                "arch-riscv64/string/strncat.S",
+                "arch-riscv64/string/strncmp.S",
+                "arch-riscv64/string/strncpy.S",
+                "arch-riscv64/string/strnlen.S",
             ],
         },
 
@@ -2109,11 +2103,6 @@
                 "arch-arm64/string/__memcpy_chk.S",
             ],
         },
-        riscv64: {
-            srcs: [
-                "arch-riscv64/string/__memcpy_chk.S",
-            ],
-        },
     },
     whole_static_libs: [
         "//external/llvm-libc:llvmlibc",
diff --git a/libc/arch-riscv64/string/__memcpy_chk.S b/libc/arch-riscv64/string/__memcpy_chk.S
deleted file mode 100644
index 4a2d13d..0000000
--- a/libc/arch-riscv64/string/__memcpy_chk.S
+++ /dev/null
@@ -1,9 +0,0 @@
-#include <private/bionic_asm.h>
-
-ENTRY(__memcpy_chk)
-  bleu a2, a3, 1f
-  call __memcpy_chk_fail
-
-1:
-   tail memcpy
-END(__memcpy_chk)
diff --git a/libc/arch-riscv64/string/__memset_chk.S b/libc/arch-riscv64/string/__memset_chk.S
deleted file mode 100644
index a5562cb..0000000
--- a/libc/arch-riscv64/string/__memset_chk.S
+++ /dev/null
@@ -1,10 +0,0 @@
-#include <private/bionic_asm.h>
-
-ENTRY(__memset_chk)
-    bleu    a2, a3, 1f
-    call    __memset_chk_fail
-
-1:
-    tail   memset
-END(__memset_chk)
-
diff --git a/libc/arch-riscv64/string/bcopy.c b/libc/arch-riscv64/string/bcopy.c
deleted file mode 100644
index 57adcf6..0000000
--- a/libc/arch-riscv64/string/bcopy.c
+++ /dev/null
@@ -1,122 +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/types.h>
-
-typedef	intptr_t word;		/* "word" used for optimal copy speed */
-
-#define	wsize	sizeof(word)
-#define	wmask	(wsize - 1)
-
-/*
- * Copy a block of memory, handling overlap.
- */
-#include <string.h>
-
-void *
-#ifdef MEMCOPY
-memcpy_gc
-#else
-memmove_gc
-#endif
-(void *dst0, const void *src0, size_t length)
-{
-	char *dst = dst0;
-	const char *src = src0;
-	size_t t;
-
-	if (length == 0 || dst == src)		/* nothing to do */
-		goto done;
-
-	/*
-	 * Macros: loop-t-times; and loop-t-times, t>0
-	 */
-#define	TLOOP(s) if (t) TLOOP1(s)
-#define	TLOOP1(s) do { s; } while (--t)
-
-	if ((unsigned long)dst < (unsigned long)src) {
-		/*
-		 * Copy forward.
-		 */
-		t = (uintptr_t)src;	/* only need low bits */
-		if ((t | (uintptr_t)dst) & wmask) {
-			/*
-			 * Try to align operands.  This cannot be done
-			 * unless the low bits match.
-			 */
-			if ((t ^ (uintptr_t)dst) & wmask || length < wsize)
-				t = length;
-			else
-				t = wsize - (t & wmask);
-			length -= t;
-			TLOOP1(*dst++ = *src++);
-		}
-		/*
-		 * Copy whole words, then mop up any trailing bytes.
-		 */
-		t = length / wsize;
-		TLOOP(*(word *)(void *)dst = *(const word *)(const void *)src;
-		    src += wsize; dst += wsize);
-		t = length & wmask;
-		TLOOP(*dst++ = *src++);
-	} else {
-		/*
-		 * Copy backwards.  Otherwise essentially the same.
-		 * Alignment works as before, except that it takes
-		 * (t&wmask) bytes to align, not wsize-(t&wmask).
-		 */
-		src += length;
-		dst += length;
-		t = (uintptr_t)src;
-		if ((t | (uintptr_t)dst) & wmask) {
-			if ((t ^ (uintptr_t)dst) & wmask || length <= wsize)
-				t = length;
-			else
-				t &= wmask;
-			length -= t;
-			TLOOP1(*--dst = *--src);
-		}
-		t = length / wsize;
-		TLOOP(src -= wsize; dst -= wsize;
-		    *(word *)(void *)dst = *(const word *)(const void *)src);
-		t = length & wmask;
-		TLOOP(*--dst = *--src);
-	}
-done:
-#if defined(MEMCOPY) || defined(MEMMOVE)
-	return (dst0);
-#else
-	return;
-#endif
-}
diff --git a/libc/arch-riscv64/string/memchr_v.S b/libc/arch-riscv64/string/memchr.S
similarity index 100%
rename from libc/arch-riscv64/string/memchr_v.S
rename to libc/arch-riscv64/string/memchr.S
diff --git a/libc/arch-riscv64/string/memcmp_v.S b/libc/arch-riscv64/string/memcmp.S
similarity index 100%
rename from libc/arch-riscv64/string/memcmp_v.S
rename to libc/arch-riscv64/string/memcmp.S
diff --git a/libc/arch-riscv64/string/memcpy_v.S b/libc/arch-riscv64/string/memcpy.S
similarity index 87%
rename from libc/arch-riscv64/string/memcpy_v.S
rename to libc/arch-riscv64/string/memcpy.S
index def1d9b..2e41069 100644
--- a/libc/arch-riscv64/string/memcpy_v.S
+++ b/libc/arch-riscv64/string/memcpy.S
@@ -55,31 +55,34 @@
 
 #include <private/bionic_asm.h>
 
-#define pDst a0
-#define pSrc a1
-#define iNum a2
+// Arguments.
+#define dst a0
+#define src a1
+#define n a2
+#define dst_len a3 // __memcpy_chk() only
 
+// Locals.
 #define iVL a3
-#define pDstPtr a4
+#define p a4
 
-#define ELEM_LMUL_SETTING m8
-#define vData v0
+ENTRY(__memcpy_chk)
+    bleu n, dst_len, 1f
+    call __memcpy_chk_fail
+1:  // Fall through to memcpy().
+END(__memcpy_chk)
 
 ENTRY(memcpy)
-
-    mv pDstPtr, pDst
+    mv p, dst
 
 L(loop):
-    vsetvli iVL, iNum, e8, ELEM_LMUL_SETTING, ta, ma
+    vsetvli iVL, n, e8, m8, ta, ma
 
-    vle8.v vData, (pSrc)
-    sub iNum, iNum, iVL
-    add pSrc, pSrc, iVL
-    vse8.v vData, (pDstPtr)
-    add pDstPtr, pDstPtr, iVL
-
-    bnez iNum, L(loop)
+    vle8.v v0, (src)
+    sub n, n, iVL
+    add src, src, iVL
+    vse8.v v0, (p)
+    add p, p, iVL
+    bnez n, L(loop)
 
     ret
-
 END(memcpy)
diff --git a/libc/arch-riscv64/string/memmove_v.S b/libc/arch-riscv64/string/memmove.S
similarity index 100%
rename from libc/arch-riscv64/string/memmove_v.S
rename to libc/arch-riscv64/string/memmove.S
diff --git a/libc/arch-riscv64/string/memset_v.S b/libc/arch-riscv64/string/memset.S
similarity index 87%
rename from libc/arch-riscv64/string/memset_v.S
rename to libc/arch-riscv64/string/memset.S
index 5aa525e..2ebf3e9 100644
--- a/libc/arch-riscv64/string/memset_v.S
+++ b/libc/arch-riscv64/string/memset.S
@@ -55,31 +55,35 @@
 
 #include <private/bionic_asm.h>
 
-#define pDst a0
-#define iValue a1
-#define iNum a2
+// Arguments.
+#define dst a0
+#define ch a1
+#define n a2
+#define dst_len a3 // __memset_chk() only
 
+// Locals.
 #define iVL a3
 #define iTemp a4
-#define pDstPtr a5
+#define p a5
 
-#define ELEM_LMUL_SETTING m8
-#define vData v0
+ENTRY(__memset_chk)
+    bleu n, dst_len, 1f
+    call __memset_chk_fail
+1:  // Fall through to memset().
+END(__memset_chk)
 
 ENTRY(memset)
+    mv p, dst
 
-    mv pDstPtr, pDst
-
-    vsetvli iVL, iNum, e8, ELEM_LMUL_SETTING, ta, ma
-    vmv.v.x vData, iValue
+    vsetvli iVL, n, e8, m8, ta, ma
+    vmv.v.x v0, ch
 
 L(loop):
-    vse8.v vData, (pDstPtr)
-    sub iNum, iNum, iVL
-    add pDstPtr, pDstPtr, iVL
-    vsetvli iVL, iNum, e8, ELEM_LMUL_SETTING, ta, ma
-    bnez iNum, L(loop)
+    vse8.v v0, (p)
+    sub n, n, iVL
+    add p, p, iVL
+    vsetvli iVL, n, e8, m8, ta, ma
+    bnez n, L(loop)
 
     ret
-
 END(memset)
diff --git a/libc/arch-riscv64/string/stpcpy_v.S b/libc/arch-riscv64/string/stpcpy.S
similarity index 100%
rename from libc/arch-riscv64/string/stpcpy_v.S
rename to libc/arch-riscv64/string/stpcpy.S
diff --git a/libc/arch-riscv64/string/strcat_v.S b/libc/arch-riscv64/string/strcat.S
similarity index 100%
rename from libc/arch-riscv64/string/strcat_v.S
rename to libc/arch-riscv64/string/strcat.S
diff --git a/libc/arch-riscv64/string/strchr_v.S b/libc/arch-riscv64/string/strchr.S
similarity index 100%
rename from libc/arch-riscv64/string/strchr_v.S
rename to libc/arch-riscv64/string/strchr.S
diff --git a/libc/arch-riscv64/string/strcmp_v.S b/libc/arch-riscv64/string/strcmp.S
similarity index 100%
rename from libc/arch-riscv64/string/strcmp_v.S
rename to libc/arch-riscv64/string/strcmp.S
diff --git a/libc/arch-riscv64/string/strcpy_v.S b/libc/arch-riscv64/string/strcpy.S
similarity index 100%
rename from libc/arch-riscv64/string/strcpy_v.S
rename to libc/arch-riscv64/string/strcpy.S
diff --git a/libc/arch-riscv64/string/strlen_v.S b/libc/arch-riscv64/string/strlen.S
similarity index 100%
rename from libc/arch-riscv64/string/strlen_v.S
rename to libc/arch-riscv64/string/strlen.S
diff --git a/libc/arch-riscv64/string/strncat_v.S b/libc/arch-riscv64/string/strncat.S
similarity index 100%
rename from libc/arch-riscv64/string/strncat_v.S
rename to libc/arch-riscv64/string/strncat.S
diff --git a/libc/arch-riscv64/string/strncmp_v.S b/libc/arch-riscv64/string/strncmp.S
similarity index 100%
rename from libc/arch-riscv64/string/strncmp_v.S
rename to libc/arch-riscv64/string/strncmp.S
diff --git a/libc/arch-riscv64/string/strncpy_v.S b/libc/arch-riscv64/string/strncpy.S
similarity index 100%
rename from libc/arch-riscv64/string/strncpy_v.S
rename to libc/arch-riscv64/string/strncpy.S
diff --git a/libc/arch-riscv64/string/strnlen_v.S b/libc/arch-riscv64/string/strnlen.S
similarity index 100%
rename from libc/arch-riscv64/string/strnlen_v.S
rename to libc/arch-riscv64/string/strnlen.S
diff --git a/linker/linker.cpp b/linker/linker.cpp
index 5b200eb..2393f13 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -798,7 +798,7 @@
   for (auto it = start, end = soinfo_list.end(); it != end; ++it) {
     soinfo* si = *it;
     // Do not skip RTLD_LOCAL libraries in dlsym(RTLD_DEFAULT, ...)
-    // if the library is opened by application with target api level < M.
+    // if the library is opened by an application with target sdk version < 23.
     // See http://b/21565766
     if ((si->get_rtld_flags() & RTLD_GLOBAL) == 0 && si->get_target_sdk_version() >= 23) {
       continue;
@@ -1224,7 +1224,7 @@
         const soinfo* needed_or_dlopened_by = task->get_needed_by();
         const char* sopath = needed_or_dlopened_by == nullptr ? "(unknown)" :
                                                       needed_or_dlopened_by->get_realpath();
-        // is_exempt_lib() always returns true for api levels < 24,
+        // is_exempt_lib() always returns true for targetSdkVersion < 24,
         // so no need to check the return value of DL_ERROR_AFTER().
         // We still call it rather than DL_WARN() to get the extra clarification.
         DL_ERROR_AFTER(24, "library \"%s\" (\"%s\") needed or dlopened by \"%s\" "
@@ -3327,7 +3327,7 @@
   if (soname_.empty() && this != solist_get_somain() && !relocating_linker &&
       get_application_target_sdk_version() < 23) {
     soname_ = basename(realpath_.c_str());
-    // The `if` above means we don't get here for api levels >= 23,
+    // The `if` above means we don't get here for targetSdkVersion >= 23,
     // so no need to check the return value of DL_ERROR_AFTER().
     // We still call it rather than DL_WARN() to get the extra clarification.
     DL_ERROR_AFTER(23, "\"%s\" has no DT_SONAME (will use %s instead)",
diff --git a/linker/linker_globals.cpp b/linker/linker_globals.cpp
index c3a3bcd..0d820b6 100644
--- a/linker/linker_globals.cpp
+++ b/linker/linker_globals.cpp
@@ -61,10 +61,12 @@
 
   if (get_application_target_sdk_version() < target_sdk_version) {
     android::base::StringAppendF(&result,
-                                 " and will not work when the app moves to API level %d or later "
+                                 " and will not work when the app moves to "
+                                 "targetSdkVersion %d or later "
                                  "(see https://android.googlesource.com/platform/bionic/+/main/"
                                  "android-changes-for-ndk-developers.md); "
-                                 "allowing for now because this app's target API level is still %d",
+                                 "allowing for now because this app's "
+                                 "targetSdkVersion is still %d",
                                  target_sdk_version,
                                  get_application_target_sdk_version());
     DL_WARN("Warning: %s", result.c_str());
diff --git a/linker/linker_globals.h b/linker/linker_globals.h
index e6b4bc6..777e7b8 100644
--- a/linker/linker_globals.h
+++ b/linker/linker_globals.h
@@ -51,7 +51,7 @@
       async_safe_format_fd(2, "\n"); \
     } while (false)
 
-bool DL_ERROR_AFTER(int target_sdk_version, const char* fmt, ...);
+bool DL_ERROR_AFTER(int target_sdk_version, const char* fmt, ...) __printflike(2, 3);
 
 #define DL_ERR_AND_LOG(fmt, x...) \
   do { \
diff --git a/linker/linker_soinfo.cpp b/linker/linker_soinfo.cpp
index 176c133..b626313 100644
--- a/linker/linker_soinfo.cpp
+++ b/linker/linker_soinfo.cpp
@@ -811,7 +811,7 @@
 
 // This function returns api-level at the time of
 // dlopen/load. Note that libraries opened by system
-// will always have 'current' api level.
+// will always have 'current' target sdk version.
 int soinfo::get_target_sdk_version() const {
   if (!has_min_version(2)) {
     return __ANDROID_API__;