Merge "Stop trying to be clever with sysconf(_SC_NGROUPS_MAX)." into main
diff --git a/README.md b/README.md
index e731e5f..0ad06a8 100644
--- a/README.md
+++ b/README.md
@@ -336,7 +336,9 @@
 
 ## Running the tests
 
-The tests are all built from the tests/ directory.
+The tests are all built from the tests/ directory. There is a separate
+directory `benchmarks/` containing benchmarks, and that has its own
+documentation on [running the benchmarks](benchmarks/README.md).
 
 ### Device tests
 
diff --git a/libc/bionic/__bionic_get_shell_path.cpp b/libc/bionic/__bionic_get_shell_path.cpp
index b78aede..5d22e00 100644
--- a/libc/bionic/__bionic_get_shell_path.cpp
+++ b/libc/bionic/__bionic_get_shell_path.cpp
@@ -28,29 +28,11 @@
 
 #include "private/__bionic_get_shell_path.h"
 
-#include <errno.h>
-#include <string.h>
-#include <sys/cdefs.h>
-#include <unistd.h>
-
-#define VENDOR_PREFIX "/vendor/"
-
-static const char* init_sh_path() {
+const char* __bionic_get_shell_path() {
 #if !defined(__ANDROID__)
   // For the host Bionic, use the standard /bin/sh
   return "/bin/sh";
 #else
-  // Look for /system or /vendor prefix.
-  char exe_path[strlen(VENDOR_PREFIX)];
-  ssize_t len = readlink("/proc/self/exe", exe_path, sizeof(exe_path));
-  if (len != -1 && !strncmp(exe_path, VENDOR_PREFIX, strlen(VENDOR_PREFIX))) {
-    return "/vendor/bin/sh";
-  }
   return "/system/bin/sh";
 #endif  // if !defined(__ANDROID__)
 }
-
-const char* __bionic_get_shell_path() {
-  static const char* sh_path = init_sh_path();
-  return sh_path;
-}
diff --git a/libc/bionic/pathconf.cpp b/libc/bionic/pathconf.cpp
index 9724f44..9bbecc3 100644
--- a/libc/bionic/pathconf.cpp
+++ b/libc/bionic/pathconf.cpp
@@ -107,14 +107,6 @@
     case _PC_REC_MIN_XFER_SIZE:
       return s.f_bsize;
 
-#if 0
-    case _PC_REC_INCR_XFER_SIZE:
-    case _PC_REC_MAX_XFER_SIZE:
-#endif
-
-    case _PC_SYMLINK_MAX:
-      return -1; /* no limit */
-
     case _PC_CHOWN_RESTRICTED:
       return _POSIX_CHOWN_RESTRICTED;
 
@@ -125,12 +117,15 @@
       return _POSIX_VDISABLE;
 
     case _PC_ASYNC_IO:
-      return -1;
-
     case _PC_PRIO_IO:
-      return -1;
-
+    case _PC_REC_INCR_XFER_SIZE:
+    case _PC_REC_MAX_XFER_SIZE:
+    case _PC_SYMLINK_MAX:
     case _PC_SYNC_IO:
+      // No API to answer these: the caller will have to "try it and see".
+      // This differs from the next case in not setting errno to EINVAL,
+      // since we did understand the question --- we just don't have a
+      // good answer.
       return -1;
 
     default:
diff --git a/tests/NOTICE b/tests/NOTICE
index cc99d20..de95698 100644
--- a/tests/NOTICE
+++ b/tests/NOTICE
@@ -454,3 +454,31 @@
 
 -------------------------------------------------------------------
 
+Copyright (C) 2024 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/grp_pwd_test.cpp b/tests/grp_pwd_test.cpp
index 16b8d5a..ddc0fc1 100644
--- a/tests/grp_pwd_test.cpp
+++ b/tests/grp_pwd_test.cpp
@@ -444,16 +444,33 @@
     return result;
   };
 
-  // AID_PRNG_SEEDER (1092) was added in TM-QPR2, but CTS is shared
-  // across Android 13 versions so we may or may not find it in this
-  // test (b/253185870).
-  if (android::base::GetIntProperty("ro.build.version.sdk", 0) == __ANDROID_API_T__) {
-#ifndef AID_PRNG_SEEDER
-#define AID_PRNG_SEEDER 1092
+  // AID_UPROBESTATS (1093) was added in V, but "trunk stable" means
+  // that the 2024Q builds don't have branches like the QPR builds used
+  // to, and are tested with the _previous_ release's CTS.
+  if (android::base::GetIntProperty("ro.build.version.sdk", 0) == __ANDROID_API_U__) {
+#if !defined(AID_UPROBESTATS)
+#define AID_UPROBESTATS 1093
 #endif
-    ids.erase(AID_PRNG_SEEDER);
-    expected_ids.erase(AID_PRNG_SEEDER);
+    ids.erase(AID_UPROBESTATS);
+    expected_ids.erase(AID_UPROBESTATS);
+    if (getpwuid(AID_UPROBESTATS)) {
+      EXPECT_STREQ(getpwuid(AID_UPROBESTATS)->pw_name, "uprobestats");
+    }
   }
+  // AID_VIRTUALMACHINE (3013) was added in V, but "trunk stable" means
+  // that the 2024Q builds don't have branches like the QPR builds used
+  // to, and are tested with the _previous_ release's CTS.
+  if (android::base::GetIntProperty("ro.build.version.sdk", 0) == __ANDROID_API_U__) {
+#if !defined(AID_VIRTUALMACHINE)
+#define AID_VIRTUALMACHINE 3013
+#endif
+    ids.erase(AID_VIRTUALMACHINE);
+    expected_ids.erase(AID_VIRTUALMACHINE);
+    if (getpwuid(AID_VIRTUALMACHINE)) {
+      EXPECT_STREQ(getpwuid(AID_VIRTUALMACHINE)->pw_name, "virtualmachine");
+    }
+  }
+
   EXPECT_EQ(expected_ids, ids) << return_differences();
 }
 #endif
diff --git a/tests/libs/dlopen_testlib_depends_on_simple.cpp b/tests/libs/dlopen_testlib_depends_on_simple.cpp
index 9e130d4..3652be8 100644
--- a/tests/libs/dlopen_testlib_depends_on_simple.cpp
+++ b/tests/libs/dlopen_testlib_depends_on_simple.cpp
@@ -1,17 +1,29 @@
 /*
  * Copyright (C) 2024 The Android Open Source Project
+ * All rights reserved.
  *
- * 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
+ * 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.
  *
- *      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.
+ * 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 <stdint.h>
diff --git a/tests/libs/testbinary_is_stack_mte.cpp b/tests/libs/testbinary_is_stack_mte.cpp
index 8dde83c..d8074d5 100644
--- a/tests/libs/testbinary_is_stack_mte.cpp
+++ b/tests/libs/testbinary_is_stack_mte.cpp
@@ -1,17 +1,29 @@
 /*
  * Copyright (C) 2024 The Android Open Source Project
+ * All rights reserved.
  *
- * 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
+ * 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.
  *
- *      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.
+ * 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 <stdint.h>
diff --git a/tests/libs/testbinary_is_stack_mte_after_dlopen.cpp b/tests/libs/testbinary_is_stack_mte_after_dlopen.cpp
index c5e6868..937ac4c 100644
--- a/tests/libs/testbinary_is_stack_mte_after_dlopen.cpp
+++ b/tests/libs/testbinary_is_stack_mte_after_dlopen.cpp
@@ -1,17 +1,29 @@
 /*
  * Copyright (C) 2024 The Android Open Source Project
+ * All rights reserved.
  *
- * 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
+ * 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.
  *
- *      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.
+ * 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 <stdint.h>
diff --git a/tests/mte_utils.h b/tests/mte_utils.h
index 0f18442..6e8385c 100644
--- a/tests/mte_utils.h
+++ b/tests/mte_utils.h
@@ -1,17 +1,29 @@
 /*
  * Copyright (C) 2024 The Android Open Source Project
+ * All rights reserved.
  *
- * 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
+ * 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.
  *
- *      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.
+ * 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
diff --git a/tests/unistd_test.cpp b/tests/unistd_test.cpp
index 88f5851..6c08972 100644
--- a/tests/unistd_test.cpp
+++ b/tests/unistd_test.cpp
@@ -753,22 +753,36 @@
 
 TEST(UNISTD_TEST, pathconf_fpathconf) {
   TemporaryFile tf;
-  long rc = 0L;
+  long l;
+
   // As a file system's block size is always power of 2, the configure values
   // for ALLOC and XFER should be power of 2 as well.
-  rc = pathconf(tf.path, _PC_ALLOC_SIZE_MIN);
-  ASSERT_TRUE(rc > 0 && powerof2(rc));
-  rc = pathconf(tf.path, _PC_REC_MIN_XFER_SIZE);
-  ASSERT_TRUE(rc > 0 && powerof2(rc));
-  rc = pathconf(tf.path, _PC_REC_XFER_ALIGN);
-  ASSERT_TRUE(rc > 0 && powerof2(rc));
+  l = pathconf(tf.path, _PC_ALLOC_SIZE_MIN);
+  ASSERT_TRUE(l > 0 && powerof2(l));
+  l = pathconf(tf.path, _PC_REC_MIN_XFER_SIZE);
+  ASSERT_TRUE(l > 0 && powerof2(l));
+  l = pathconf(tf.path, _PC_REC_XFER_ALIGN);
+  ASSERT_TRUE(l > 0 && powerof2(l));
 
-  rc = fpathconf(tf.fd, _PC_ALLOC_SIZE_MIN);
-  ASSERT_TRUE(rc > 0 && powerof2(rc));
-  rc = fpathconf(tf.fd, _PC_REC_MIN_XFER_SIZE);
-  ASSERT_TRUE(rc > 0 && powerof2(rc));
-  rc = fpathconf(tf.fd, _PC_REC_XFER_ALIGN);
-  ASSERT_TRUE(rc > 0 && powerof2(rc));
+  l = fpathconf(tf.fd, _PC_ALLOC_SIZE_MIN);
+  ASSERT_TRUE(l > 0 && powerof2(l));
+  l = fpathconf(tf.fd, _PC_REC_MIN_XFER_SIZE);
+  ASSERT_TRUE(l > 0 && powerof2(l));
+  l = fpathconf(tf.fd, _PC_REC_XFER_ALIGN);
+  ASSERT_TRUE(l > 0 && powerof2(l));
+
+  // Check that the "I can't answer that, you'll have to try it and see"
+  // cases don't set errno.
+  int names[] = {
+      _PC_ASYNC_IO, _PC_PRIO_IO, _PC_REC_INCR_XFER_SIZE, _PC_REC_MAX_XFER_SIZE, _PC_SYMLINK_MAX,
+      _PC_SYNC_IO,  -1};
+  for (size_t i = 0; names[i] != -1; i++) {
+    errno = 0;
+    ASSERT_EQ(-1, pathconf(tf.path, names[i])) << names[i];
+    ASSERT_ERRNO(0) << names[i];
+    ASSERT_EQ(-1, fpathconf(tf.fd, names[i])) << names[i];
+    ASSERT_ERRNO(0) << names[i];
+  }
 }
 
 TEST(UNISTD_TEST, _POSIX_constants) {
diff --git a/tools/update_notice.sh b/tools/update_notice.sh
index c45311a..69e090c 100755
--- a/tools/update_notice.sh
+++ b/tools/update_notice.sh
@@ -11,4 +11,4 @@
 python3 ./libc/tools/generate_notice.py linker > linker/NOTICE
 python3 ./libc/tools/generate_notice.py tests > tests/NOTICE
 python3 ./libc/tools/generate_notice.py tools > tools/NOTICE
-git diff --exit-code HEAD libc/NOTICE
+git diff --exit-code HEAD */NOTICE