Merge "Use DYNAMIC entries for MTE enablement" into main
diff --git a/README.md b/README.md
index aafbcff..9a44934 100644
--- a/README.md
+++ b/README.md
@@ -288,14 +288,14 @@
Note that if you're actually just trying to expose device-specific headers to
build your device drivers, you shouldn't modify bionic. Instead use
-`TARGET_DEVICE_KERNEL_HEADERS` and friends described in [config.mk](https://android.googlesource.com/platform/build/+/master/core/config.mk#186).
+`TARGET_DEVICE_KERNEL_HEADERS` and friends described in [config.mk](https://android.googlesource.com/platform/build/+/main/core/config.mk#186).
## Updating tzdata
This is handled by the libcore team, because they own icu, and that needs to be
updated in sync with bionic). See
-[system/timezone/README.android](https://android.googlesource.com/platform/system/timezone/+/master/README.android).
+[system/timezone/README.android](https://android.googlesource.com/platform/system/timezone/+/main/README.android).
## Verifying changes
diff --git a/android-changes-for-ndk-developers.md b/android-changes-for-ndk-developers.md
index ab3b247..ef5d34d 100644
--- a/android-changes-for-ndk-developers.md
+++ b/android-changes-for-ndk-developers.md
@@ -7,7 +7,7 @@
behavior changes.
See also the
-[unwinder documentation](https://android.googlesource.com/platform/system/unwinding/+/refs/heads/master/libunwindstack/AndroidVersions.md)
+[unwinder documentation](https://android.googlesource.com/platform/system/unwinding/+/refs/heads/main/libunwindstack/AndroidVersions.md)
for details about changes in stack unwinding (crash dumps) between
different releases.
diff --git a/benchmarks/Android.bp b/benchmarks/Android.bp
index f31e127..ffb5921 100644
--- a/benchmarks/Android.bp
+++ b/benchmarks/Android.bp
@@ -57,6 +57,7 @@
"stdio_benchmark.cpp",
"stdlib_benchmark.cpp",
"string_benchmark.cpp",
+ "syscall_mmap_benchmark.cpp",
"time_benchmark.cpp",
"unistd_benchmark.cpp",
"wctype_benchmark.cpp",
diff --git a/benchmarks/NOTICE b/benchmarks/NOTICE
index e46a624..31a2570 100644
--- a/benchmarks/NOTICE
+++ b/benchmarks/NOTICE
@@ -206,3 +206,19 @@
-------------------------------------------------------------------
+Copyright (C) 2023 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.
+
+-------------------------------------------------------------------
+
diff --git a/benchmarks/README.md b/benchmarks/README.md
index 1fd17a1..3819b1a 100644
--- a/benchmarks/README.md
+++ b/benchmarks/README.md
@@ -185,4 +185,4 @@
benchmarks appear to be using the script. For more information:
* run `get_build_var BOARD_PERFSETUP_SCRIPT`
* run `m perf-setup` to install the script into `${OUT}/data/local/tmp/perf-setup.sh`
- * see: https://android.googlesource.com/platform/platform_testing/+/refs/heads/master/scripts/perf-setup/
+ * see: https://android.googlesource.com/platform/platform_testing/+/refs/heads/main/scripts/perf-setup/
diff --git a/benchmarks/bionic_benchmarks.cpp b/benchmarks/bionic_benchmarks.cpp
index 74966c0..c0f956b 100644
--- a/benchmarks/bionic_benchmarks.cpp
+++ b/benchmarks/bionic_benchmarks.cpp
@@ -521,12 +521,22 @@
all_sizes.insert(all_sizes.end(), kMediumSizes.begin(), kMediumSizes.end());
all_sizes.insert(all_sizes.end(), kLargeSizes.begin(), kLargeSizes.end());
+ int page_sz = getpagesize();
+ std::vector<int> sub_page_sizes = {page_sz / 2, page_sz / 4, page_sz / 8};
+ std::vector<int> multi_page_sizes = {page_sz, page_sz * 2, page_sz * 3, page_sz * 10,
+ page_sz * 100};
+ std::vector<int> all_page_sizes(sub_page_sizes);
+ all_page_sizes.insert(all_page_sizes.end(), multi_page_sizes.begin(), multi_page_sizes.end());
+
std::map<std::string, args_vector_t> args_shorthand {
{"AT_COMMON_SIZES", GetArgs(kCommonSizes)},
{"AT_SMALL_SIZES", GetArgs(kSmallSizes)},
{"AT_MEDIUM_SIZES", GetArgs(kMediumSizes)},
{"AT_LARGE_SIZES", GetArgs(kLargeSizes)},
{"AT_ALL_SIZES", GetArgs(all_sizes)},
+ {"AT_SUB_PAGE_SIZES", GetArgs(sub_page_sizes)},
+ {"AT_MULTI_PAGE_SIZES", GetArgs(multi_page_sizes)},
+ {"AT_All_PAGE_SIZES", GetArgs(all_page_sizes)},
{"AT_ALIGNED_ONEBUF", GetArgs(kCommonSizes, 0)},
{"AT_ALIGNED_ONEBUF_SMALL", GetArgs(kSmallSizes, 0)},
diff --git a/benchmarks/suites/syscall.xml b/benchmarks/suites/syscall.xml
new file mode 100644
index 0000000..c253a3f
--- /dev/null
+++ b/benchmarks/suites/syscall.xml
@@ -0,0 +1,52 @@
+<!-- mmap tests -->
+<fn>
+ <name>BM_syscall_mmap_anon_rw</name>
+ <iterations>10</iterations>
+ <args>AT_All_PAGE_SIZES</args>
+</fn>
+<fn>
+ <name>BM_syscall_mmap_anon_noreserve</name>
+ <iterations>10</iterations>
+ <args>AT_All_PAGE_SIZES</args>
+</fn>
+<fn>
+ <name>BM_syscall_mmap_anon_none</name>
+ <iterations>10</iterations>
+ <args>AT_All_PAGE_SIZES</args>
+</fn>
+<fn>
+ <name>BM_syscall_mmap_anon_rw_fixed</name>
+ <iterations>10</iterations>
+ <args>AT_All_PAGE_SIZES</args>
+</fn>
+<fn>
+ <name>BM_syscall_mmap_anon_none_fixed</name>
+ <iterations>10</iterations>
+ <args>AT_All_PAGE_SIZES</args>
+</fn>
+<fn>
+ <name>BM_syscall_mmap_file_rd_priv</name>
+ <iterations>10</iterations>
+ <args>AT_All_PAGE_SIZES</args>
+</fn>
+<fn>
+ <name>BM_syscall_mmap_file_rw_shared</name>
+ <iterations>10</iterations>
+ <args>AT_All_PAGE_SIZES</args>
+</fn>
+<fn>
+ <name>BM_syscall_mmap_file_rw_priv_fixed_start</name>
+ <iterations>10</iterations>
+ <args>AT_All_PAGE_SIZES</args>
+</fn>
+<fn>
+ <name>BM_syscall_mmap_file_rw_priv_fixed_mid</name>
+ <iterations>10</iterations>
+ <args>AT_MULTI_PAGE_SIZES</args>
+</fn>
+<fn>
+ <name>BM_syscall_mmap_file_rw_priv_fixed_end</name>
+ <iterations>10</iterations>
+ <args>AT_MULTI_PAGE_SIZES</args>
+</fn>
+
diff --git a/benchmarks/syscall_mmap_benchmark.cpp b/benchmarks/syscall_mmap_benchmark.cpp
new file mode 100644
index 0000000..10bae1f
--- /dev/null
+++ b/benchmarks/syscall_mmap_benchmark.cpp
@@ -0,0 +1,214 @@
+/*
+ * Copyright (C) 2023 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 <string.h>
+#include <sys/mman.h>
+#include <sys/syscall.h>
+
+#include <android-base/file.h>
+#include <android-base/stringprintf.h>
+#include <benchmark/benchmark.h>
+
+#include "util.h"
+
+static size_t page_sz = getpagesize();
+
+struct MmapParams {
+ int prot;
+ int flags;
+ int64_t size;
+};
+
+// mmap syscall benchmarks
+static void MmapBenchmark(benchmark::State& state, const struct MmapParams& params, int fd,
+ void* area = nullptr) {
+ for (auto _ : state) {
+ void* addr = mmap(area, params.size, params.prot, params.flags, fd, 0);
+ if (addr == MAP_FAILED) {
+ state.SkipWithError(android::base::StringPrintf("mmap failed: %s", strerror(errno)).c_str());
+ break;
+ }
+
+ if (params.prot & PROT_WRITE) {
+ MakeAllocationResident(addr, params.size, page_sz);
+ }
+
+ if (munmap(addr, params.size) != 0) {
+ state.SkipWithError(
+ android::base::StringPrintf("munmap failed: %s", strerror(errno)).c_str());
+ break;
+ }
+ }
+}
+
+static void MmapFixedBenchmark(benchmark::State& state, const struct MmapParams& params, int fd,
+ size_t area_size, size_t offs) {
+ uint8_t* area = reinterpret_cast<uint8_t*>(mmap(0, area_size, params.prot, params.flags, fd, 0));
+ if (area == MAP_FAILED) {
+ state.SkipWithError(android::base::StringPrintf("mmap failed: %s", strerror(errno)).c_str());
+ return;
+ }
+
+ MmapBenchmark(state, params, fd, area + offs);
+
+ if (munmap(area, area_size) != 0) {
+ state.SkipWithError(android::base::StringPrintf("munmap failed: %s", strerror(errno)).c_str());
+ return;
+ }
+}
+
+static void MmapFileBenchmark(benchmark::State& state, const struct MmapParams& params,
+ size_t area_size, size_t offs) {
+ TemporaryFile tf;
+
+ if (tf.fd < 0) {
+ state.SkipWithError(
+ android::base::StringPrintf("failed to create a temporary file: %s", strerror(errno))
+ .c_str());
+ return;
+ }
+
+ if (area_size > 0 && ftruncate(tf.fd, area_size)) {
+ state.SkipWithError(
+ android::base::StringPrintf("ftruncate failed: %s", strerror(errno)).c_str());
+ return;
+ }
+
+ if (params.flags & MAP_FIXED) {
+ MmapFixedBenchmark(state, params, tf.fd, area_size, offs);
+ } else {
+ MmapBenchmark(state, params, tf.fd);
+ }
+}
+
+// anon mmap
+static void BM_syscall_mmap_anon_rw(benchmark::State& state) {
+ struct MmapParams params = {
+ .prot = PROT_READ | PROT_WRITE,
+ .flags = MAP_PRIVATE | MAP_ANONYMOUS,
+ .size = state.range(0),
+ };
+
+ MmapBenchmark(state, params, 0);
+}
+BIONIC_BENCHMARK_WITH_ARG(BM_syscall_mmap_anon_rw, "AT_All_PAGE_SIZES");
+
+static void BM_syscall_mmap_anon_noreserve(benchmark::State& state) {
+ struct MmapParams params = {
+ .prot = PROT_NONE,
+ .flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE,
+ .size = state.range(0),
+ };
+
+ MmapBenchmark(state, params, 0);
+}
+BIONIC_BENCHMARK_WITH_ARG(BM_syscall_mmap_anon_noreserve, "AT_All_PAGE_SIZES");
+
+static void BM_syscall_mmap_anon_none(benchmark::State& state) {
+ struct MmapParams params = {
+ .prot = PROT_NONE,
+ .flags = MAP_PRIVATE | MAP_ANONYMOUS,
+ .size = state.range(0),
+ };
+
+ MmapBenchmark(state, params, 0);
+}
+BIONIC_BENCHMARK_WITH_ARG(BM_syscall_mmap_anon_none, "AT_All_PAGE_SIZES");
+
+// anon fixed mmap
+static void BM_syscall_mmap_anon_rw_fixed(benchmark::State& state) {
+ struct MmapParams params = {
+ .prot = PROT_READ | PROT_WRITE,
+ .flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED,
+ .size = state.range(0),
+ };
+
+ MmapFixedBenchmark(state, params, 0, params.size, 0);
+}
+BIONIC_BENCHMARK_WITH_ARG(BM_syscall_mmap_anon_rw_fixed, "AT_All_PAGE_SIZES");
+
+static void BM_syscall_mmap_anon_none_fixed(benchmark::State& state) {
+ struct MmapParams params = {
+ .prot = PROT_NONE,
+ .flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED,
+ .size = state.range(0),
+ };
+
+ MmapFixedBenchmark(state, params, 0, params.size, 0);
+}
+BIONIC_BENCHMARK_WITH_ARG(BM_syscall_mmap_anon_none_fixed, "AT_All_PAGE_SIZES");
+
+// file mmap
+static void BM_syscall_mmap_file_rd_priv(benchmark::State& state) {
+ struct MmapParams params = {
+ .prot = PROT_READ,
+ .flags = MAP_PRIVATE,
+ .size = state.range(0),
+ };
+
+ MmapFileBenchmark(state, params, params.size, 0);
+}
+BIONIC_BENCHMARK_WITH_ARG(BM_syscall_mmap_file_rd_priv, "AT_All_PAGE_SIZES");
+
+static void BM_syscall_mmap_file_rw_shared(benchmark::State& state) {
+ struct MmapParams params = {
+ .prot = PROT_READ | PROT_WRITE,
+ .flags = MAP_SHARED,
+ .size = state.range(0),
+ };
+
+ MmapFileBenchmark(state, params, params.size, 0);
+}
+BIONIC_BENCHMARK_WITH_ARG(BM_syscall_mmap_file_rw_shared, "AT_All_PAGE_SIZES");
+
+// file fixed mmap
+static void BM_syscall_mmap_file_rw_priv_fixed_start(benchmark::State& state) {
+ struct MmapParams params = {
+ .prot = PROT_READ | PROT_WRITE,
+ .flags = MAP_PRIVATE | MAP_FIXED,
+ .size = state.range(0),
+ };
+
+ // allocate 3x area and map at the start
+ MmapFileBenchmark(state, params, params.size * 3, 0);
+}
+BIONIC_BENCHMARK_WITH_ARG(BM_syscall_mmap_file_rw_priv_fixed_start, "AT_All_PAGE_SIZES");
+
+static void BM_syscall_mmap_file_rw_priv_fixed_mid(benchmark::State& state) {
+ struct MmapParams params = {
+ .prot = PROT_READ | PROT_WRITE,
+ .flags = MAP_PRIVATE | MAP_FIXED,
+ .size = state.range(0),
+ };
+
+ // allocate 3x area and map at the middle
+ MmapFileBenchmark(state, params, params.size * 3, params.size);
+}
+// mapping at sub-page size offset is not supported, so run only for AT_MULTI_PAGE_SIZES
+BIONIC_BENCHMARK_WITH_ARG(BM_syscall_mmap_file_rw_priv_fixed_mid, "AT_MULTI_PAGE_SIZES");
+
+static void BM_syscall_mmap_file_rw_priv_fixed_end(benchmark::State& state) {
+ struct MmapParams params = {
+ .prot = PROT_READ | PROT_WRITE,
+ .flags = MAP_PRIVATE | MAP_FIXED,
+ .size = state.range(0),
+ };
+
+ // allocate 3x area and map at the end
+ MmapFileBenchmark(state, params, params.size * 3, params.size * 2);
+}
+// mapping at sub-page size offset is not supported, so run only for AT_MULTI_PAGE_SIZES
+BIONIC_BENCHMARK_WITH_ARG(BM_syscall_mmap_file_rw_priv_fixed_end, "AT_MULTI_PAGE_SIZES");
diff --git a/benchmarks/tests/interface_test.cpp b/benchmarks/tests/interface_test.cpp
index 1d620d1..b56866e 100644
--- a/benchmarks/tests/interface_test.cpp
+++ b/benchmarks/tests/interface_test.cpp
@@ -160,8 +160,10 @@
"Google benchmark flags:\n"
"benchmark [--benchmark_list_tests={true|false}]\n"
" [--benchmark_filter=<regex>]\n"
- " [--benchmark_min_time=<min_time>]\n"
+ " [--benchmark_min_time=`<integer>x` OR `<float>s` ]\n"
+ " [--benchmark_min_warmup_time=<min_warmup_time>]\n"
" [--benchmark_repetitions=<num_repetitions>]\n"
+ " [--benchmark_enable_random_interleaving={true|false}]\n"
" [--benchmark_report_aggregates_only={true|false}]\n"
" [--benchmark_display_aggregates_only={true|false}]\n"
" [--benchmark_format=<console|json|csv>]\n"
@@ -169,6 +171,8 @@
" [--benchmark_out_format=<json|console|csv>]\n"
" [--benchmark_color={auto|true|false}]\n"
" [--benchmark_counters_tabular={true|false}]\n"
+ " [--benchmark_context=<key>=<value>,...]\n"
+ " [--benchmark_time_unit={ns|us|ms|s}]\n"
" [--v=<verbosity>]\n";
Verify(expected, 0, std::vector<const char*>{"--help"}, false);
}
diff --git a/docs/fdsan.md b/docs/fdsan.md
index 6630299..f5d1ab5 100644
--- a/docs/fdsan.md
+++ b/docs/fdsan.md
@@ -46,7 +46,7 @@
fdsan attempts to detect and/or prevent file descriptor mismanagement by enforcing file descriptor ownership. Like how most memory allocations can have their ownership handled by types such as `std::unique_ptr`, almost all file descriptors can be associated with a unique owner which is responsible for their closure. fdsan provides functions to associate a file descriptor with an owner; if someone tries to close a file descriptor that they don't own, depending on configuration, either a warning is emitted, or the process aborts.
-The way this is implemented is by providing functions to set a 64-bit closure tag on a file descriptor. The tag consists of an 8-bit type byte that identifies the type of the owner (`enum android_fdan_owner_type` in [`<android/fdsan.h>`](https://android.googlesource.com/platform/bionic/+/master/libc/include/android/fdsan.h)), and a 56-bit value. The value should ideally be something that uniquely identifies the object (object address for native objects and `System.identityHashCode` for Java objects), but in cases where it's hard to derive an identifier for the "owner" that should close a file descriptor, even using the same value for all file descriptors in the module can be useful, since it'll catch other code that closes your file descriptors.
+The way this is implemented is by providing functions to set a 64-bit closure tag on a file descriptor. The tag consists of an 8-bit type byte that identifies the type of the owner (`enum android_fdan_owner_type` in [`<android/fdsan.h>`](https://android.googlesource.com/platform/bionic/+/main/libc/include/android/fdsan.h)), and a 56-bit value. The value should ideally be something that uniquely identifies the object (object address for native objects and `System.identityHashCode` for Java objects), but in cases where it's hard to derive an identifier for the "owner" that should close a file descriptor, even using the same value for all file descriptors in the module can be useful, since it'll catch other code that closes your file descriptors.
If a file descriptor that's been marked with a tag is closed with an incorrect tag, or without a tag, we know something has gone wrong, and can generate diagnostics or abort.
@@ -62,7 +62,7 @@
- fatal (`ANDROID_FDSAN_ERROR_LEVEL_FATAL`)
- Abort upon detecting an error.
-In Android Q, fdsan has a global default of warn-once. fdsan can be made more or less strict at runtime via the `android_fdsan_set_error_level` function in [`<android/fdsan.h>`](https://android.googlesource.com/platform/bionic/+/master/libc/include/android/fdsan.h).
+In Android Q, fdsan has a global default of warn-once. fdsan can be made more or less strict at runtime via the `android_fdsan_set_error_level` function in [`<android/fdsan.h>`](https://android.googlesource.com/platform/bionic/+/main/libc/include/android/fdsan.h).
The likelihood of fdsan catching a file descriptor error is proportional to the percentage of file descriptors in your process that are tagged with an owner.
diff --git a/docs/fdtrack.md b/docs/fdtrack.md
index 7cf6e1f..07c69b3 100644
--- a/docs/fdtrack.md
+++ b/docs/fdtrack.md
@@ -9,7 +9,7 @@
hook to perform and store backtraces for file descriptor creation.
### bionic hooks
-bionic provides a header in the `bionic_libc_platform_headers` header_lib at <[bionic/fdtrack.h](https://android.googlesource.com/platform/bionic/+/refs/heads/master/libc/platform/bionic/fdtrack.h)>.
+bionic provides a header in the `bionic_libc_platform_headers` header_lib at <[bionic/fdtrack.h](https://android.googlesource.com/platform/bionic/+/refs/heads/main/libc/platform/bionic/fdtrack.h)>.
Register a callback with `android_fdtrack_compare_exchange_hook` to receive
callbacks upon file descriptor creation and destruction. This function can be
called at any point in order to start capturing events, but be sure to properly
@@ -18,7 +18,7 @@
not to call callbacks when this is the case).
### libfdtrack
-[libfdtrack](https://android.googlesource.com/platform/bionic/+/refs/heads/master/libfdtrack)
+[libfdtrack](https://android.googlesource.com/platform/bionic/+/refs/heads/main/libfdtrack)
implements a library that uses libunwindstack to unwind and store fd creation backtraces.
diff --git a/docs/native_allocator.md b/docs/native_allocator.md
index 9fc9a31..13d9738 100644
--- a/docs/native_allocator.md
+++ b/docs/native_allocator.md
@@ -323,8 +323,8 @@
time. The trace data does not include timestamps,
so it is not possible to create a completely accurate replay.
-To generate these traces, see the [Malloc Debug documentation](https://android.googlesource.com/platform/bionic/+/master/libc/malloc_debug/README.md),
-the option [record\_allocs](https://android.googlesource.com/platform/bionic/+/master/libc/malloc_debug/README.md#record_allocs_total_entries).
+To generate these traces, see the [Malloc Debug documentation](https://android.googlesource.com/platform/bionic/+/main/libc/malloc_debug/README.md),
+the option [record\_allocs](https://android.googlesource.com/platform/bionic/+/main/libc/malloc_debug/README.md#record_allocs_total_entries).
To run these benchmarks, first copy the trace files to the target using
these commands:
diff --git a/docs/status.md b/docs/status.md
index 3c5d1ba..a9afe55 100644
--- a/docs/status.md
+++ b/docs/status.md
@@ -11,7 +11,7 @@
### POSIX
You can see the current status with respect to POSIX in the form of tests:
-https://android.googlesource.com/platform/bionic/+/master/tests/headers/posix/
+https://android.googlesource.com/platform/bionic/+/main/tests/headers/posix/
Some POSIX functionality is not supported by the Linux kernel, and
is guarded with tests for `__linux__`. Other functionality is not
@@ -53,7 +53,7 @@
### libc
-Current libc symbols: https://android.googlesource.com/platform/bionic/+/master/libc/libc.map.txt
+Current libc symbols: https://android.googlesource.com/platform/bionic/+/main/libc/libc.map.txt
New libc functions in V (API level 35):
* `tcgetwinsize`, `tcsetwinsize` (POSIX Issue 8 additions).
@@ -63,12 +63,15 @@
functions for avoiding $TZ if you need to use multiple timezones in
multi-threaded C).
* `mbsrtowcs_l` and `wcsrtombs_l` aliases for `mbsrtowcs` and `wcsrtombs`.
+ * GNU extensions `strerrordesc_np` and `strerrorname_np`.
* New system call wrappers: `__riscv_flush_icache` (`<sys/cachectl.h>`),
`__riscv_hwprobe` (`<sys/hwprobe.h>`), `epoll_pwait2`/`epoll_pwait2_64` (`<sys/epoll.h>`).
New libc behavior in V (API level 35):
* Added `LD_SHOW_AUXV` to the dynamic linker to dump the ELF auxiliary
vector if the environment variable is set.
+ * The printf family now supports `%#m` to print the name of the errno
+ constant (rather than the description printed by `%m`).
New libc functions in U (API level 34):
* `close_range` and `copy_file_range` (Linux-specific GNU extensions).
@@ -296,7 +299,7 @@
### libm
-Current libm symbols: https://android.googlesource.com/platform/bionic/+/master/libm/libm.map.txt
+Current libm symbols: https://android.googlesource.com/platform/bionic/+/main/libm/libm.map.txt
0 remaining missing C11/POSIX libm functions.
diff --git a/libc/Android.bp b/libc/Android.bp
index 68a0838..fe5f6de 100644
--- a/libc/Android.bp
+++ b/libc/Android.bp
@@ -951,6 +951,7 @@
"arch-riscv64/string/memcpy_vext.S",
"arch-riscv64/string/memmove_vext.S",
"arch-riscv64/string/memset_vext.S",
+ "arch-riscv64/string/stpcpy_vext.S",
"arch-riscv64/string/strcat_vext.S",
"arch-riscv64/string/strchr_vext.S",
"arch-riscv64/string/strcmp_vext.S",
@@ -3122,3 +3123,10 @@
},
},
}
+
+// headers that will be placed on the include path when running versioner in bazel
+// this module should be a no-op in soong
+filegroup {
+ name: "versioner-dependencies",
+ srcs: ["versioner-dependencies/**/*"],
+}
diff --git a/libc/BUILD b/libc/BUILD
deleted file mode 100644
index 1777ae9..0000000
--- a/libc/BUILD
+++ /dev/null
@@ -1,42 +0,0 @@
-# Copyright (C) 2022 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.
-
-load("//build/bazel/rules/apis:cc_api_contribution.bzl", "cc_api_contribution")
-
-cc_api_contribution(
- name = "libc_contributions",
- hdrs = [
- "//bionic/libc/kernel/android:libc_kernel_android_scsi_headers",
- "//bionic/libc/kernel/android:libc_kernel_android_uapi_headers",
- "//bionic/libc/kernel/uapi:libc_kernel_uapi_asm_arm64_headers", #arm64
- "//bionic/libc/kernel/uapi:libc_kernel_uapi_asm_arm_headers", #arm
- "//bionic/libc/kernel/uapi:libc_kernel_uapi_asm_x86_64_headers", #x86_64
- "//bionic/libc/kernel/uapi:libc_kernel_uapi_asm_x86_headers", #x86
- "//bionic/libc/kernel/uapi:libc_kernel_uapi_headers",
- ],
- api = ":libc.map.txt",
- library_name = "libc",
-)
diff --git a/libc/NOTICE b/libc/NOTICE
index daea7bc..ef64e0c 100644
--- a/libc/NOTICE
+++ b/libc/NOTICE
@@ -3848,35 +3848,6 @@
-------------------------------------------------------------------
-Copyright (c) 2007-2008 Michael G Schwern
-
-This software originally derived from Paul Sheer's pivotal_gmtime_r.c.
-
-The MIT License:
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-
-Origin: http://code.google.com/p/y2038
-Modified for Bionic by the Android Open Source Project
-
--------------------------------------------------------------------
-
Copyright (c) 2008, 2016 Todd C. Miller <millert@openbsd.org>
Permission to use, copy, modify, and distribute this software for any
diff --git a/libc/arch-riscv64/dynamic_function_dispatch.cpp b/libc/arch-riscv64/dynamic_function_dispatch.cpp
index 0925c5f..5866fe4 100644
--- a/libc/arch-riscv64/dynamic_function_dispatch.cpp
+++ b/libc/arch-riscv64/dynamic_function_dispatch.cpp
@@ -58,6 +58,11 @@
RETURN_FUNC(memset_func, memset_vext);
}
+typedef char* stpcpy_func(char*, const char*);
+DEFINE_IFUNC_FOR(stpcpy) {
+ RETURN_FUNC(stpcpy_func, stpcpy_vext);
+}
+
typedef char* strcat_func(char*, const char*);
DEFINE_IFUNC_FOR(strcat) {
RETURN_FUNC(strcat_func, strcat_vext);
diff --git a/libc/arch-riscv64/static_function_dispatch.S b/libc/arch-riscv64/static_function_dispatch.S
index 3bf0275..f96d40e 100644
--- a/libc/arch-riscv64/static_function_dispatch.S
+++ b/libc/arch-riscv64/static_function_dispatch.S
@@ -40,6 +40,7 @@
FUNCTION_DELEGATE(memcpy, memcpy_vext)
FUNCTION_DELEGATE(memmove, memmove_vext)
FUNCTION_DELEGATE(memset, memset_vext)
+FUNCTION_DELEGATE(stpcpy, stpcpy_vext)
FUNCTION_DELEGATE(strcat, strcat_vext)
FUNCTION_DELEGATE(strchr, strchr_vext)
FUNCTION_DELEGATE(strcmp, strcmp_vext)
diff --git a/libc/arch-riscv64/string/stpcpy_vext.S b/libc/arch-riscv64/string/stpcpy_vext.S
new file mode 100644
index 0000000..3096e76
--- /dev/null
+++ b/libc/arch-riscv64/string/stpcpy_vext.S
@@ -0,0 +1,91 @@
+/*
+ * Copyright (C) 2023 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) 2023 SiFive, 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:
+ * 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 SIFIVE INC ``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 SIFIVE INC 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(__riscv_v)
+
+#include <private/bionic_asm.h>
+
+#define pDstPtr a0
+#define pSrc a1
+
+#define iVL a3
+#define iCurrentVL a4
+#define iActiveElemPos a5
+
+#define ELEM_LMUL_SETTING m1
+#define vMask1 v0
+#define vMask2 v1
+#define vStr1 v8
+#define vStr2 v16
+
+ENTRY(stpcpy_vext)
+L(stpcpy_loop):
+ vsetvli iVL, zero, e8, ELEM_LMUL_SETTING, ta, ma
+ vle8ff.v vStr1, (pSrc)
+ vmseq.vx vMask2, vStr1, zero
+ csrr iCurrentVL, vl
+ vfirst.m iActiveElemPos, vMask2
+ vmsif.m vMask1, vMask2
+ add pSrc, pSrc, iCurrentVL
+ vse8.v vStr1, (pDstPtr), vMask1.t
+ add pDstPtr, pDstPtr, iCurrentVL
+ bltz iActiveElemPos, L(stpcpy_loop)
+
+ // stpcpy() returns a pointer to the '\0', not the byte after it.
+ addi pDstPtr, pDstPtr, -1
+ ret
+END(stpcpy_vext)
+
+#endif
diff --git a/libc/async_safe/async_safe_log.cpp b/libc/async_safe/async_safe_log.cpp
index 2bff616..451cb8c 100644
--- a/libc/async_safe/async_safe_log.cpp
+++ b/libc/async_safe/async_safe_log.cpp
@@ -361,7 +361,19 @@
buffer[1] = 'x';
format_integer(buffer + 2, sizeof(buffer) - 2, value, 'x');
} else if (c == 'm') {
- strerror_r(errno, buffer, sizeof(buffer));
+#if __ANDROID_API_LEVEL__ >= 35 // This library is used in mainline modules.
+ if (alternate) {
+ const char* name = strerrorname_np(errno);
+ if (name) {
+ strcpy(buffer, name);
+ } else {
+ format_integer(buffer, sizeof(buffer), errno, 'd');
+ }
+ } else
+#endif
+ {
+ strerror_r(errno, buffer, sizeof(buffer));
+ }
} else if (tolower(c) == 'b' || c == 'd' || c == 'i' || c == 'o' || c == 'u' ||
tolower(c) == 'x') {
/* integers - first read value from stack */
diff --git a/libc/bionic/ctype.cpp b/libc/bionic/ctype.cpp
index 92a4772..3c0476e 100644
--- a/libc/bionic/ctype.cpp
+++ b/libc/bionic/ctype.cpp
@@ -27,62 +27,4 @@
*/
#define __BIONIC_CTYPE_INLINE /* Out of line. */
-#include <bits/ctype_inlines.h>
-
#include <ctype.h>
-
-int isalnum_l(int c, locale_t) {
- return isalnum(c);
-}
-
-int isalpha_l(int c, locale_t) {
- return isalpha(c);
-}
-
-int isblank_l(int c, locale_t) {
- return isblank(c);
-}
-
-int iscntrl_l(int c, locale_t) {
- return iscntrl(c);
-}
-
-int isdigit_l(int c, locale_t) {
- return isdigit(c);
-}
-
-int isgraph_l(int c, locale_t) {
- return isgraph(c);
-}
-
-int islower_l(int c, locale_t) {
- return islower(c);
-}
-
-int isprint_l(int c, locale_t) {
- return isprint(c);
-}
-
-int ispunct_l(int c, locale_t) {
- return ispunct(c);
-}
-
-int isspace_l(int c, locale_t) {
- return isspace(c);
-}
-
-int isupper_l(int c, locale_t) {
- return isupper(c);
-}
-
-int isxdigit_l(int c, locale_t) {
- return isxdigit(c);
-}
-
-int toupper_l(int c, locale_t) {
- return toupper(c);
-}
-
-int tolower_l(int c, locale_t) {
- return tolower(c);
-}
diff --git a/libc/bionic/fcntl.cpp b/libc/bionic/fcntl.cpp
index 754277b..7730a15 100644
--- a/libc/bionic/fcntl.cpp
+++ b/libc/bionic/fcntl.cpp
@@ -44,7 +44,7 @@
va_end(args);
if (cmd == F_SETFD && (reinterpret_cast<uintptr_t>(arg) & ~FD_CLOEXEC) != 0) {
- __fortify_fatal("fcntl(F_SETFD) passed non-FD_CLOEXEC flag: %p", arg);
+ __fortify_fatal("fcntl(F_SETFD) only supports FD_CLOEXEC but was passed %p", arg);
}
#if defined(__LP64__)
diff --git a/libc/bionic/strerror.cpp b/libc/bionic/strerror.cpp
index 0deb200..743130d 100644
--- a/libc/bionic/strerror.cpp
+++ b/libc/bionic/strerror.cpp
@@ -26,8 +26,8 @@
* SUCH DAMAGE.
*/
-// G++ automatically defines _GNU_SOURCE, which then means that <string.h>
-// gives us the GNU variant.
+// -std=gnu++XX automatically defines _GNU_SOURCE, which then means that <string.h>
+// gives us the GNU variant, which is not what we're defining here.
#undef _GNU_SOURCE
#include <string.h>
@@ -43,146 +43,28 @@
#include "bionic/pthread_internal.h"
-static const char* __sys_error_strings[] = {
- [0] = "Success",
- [EPERM] = "Operation not permitted",
- [ENOENT] = "No such file or directory",
- [ESRCH] = "No such process",
- [EINTR] = "Interrupted system call",
- [EIO] = "I/O error",
- [ENXIO] = "No such device or address",
- [E2BIG] = "Argument list too long",
- [ENOEXEC] = "Exec format error",
- [EBADF] = "Bad file descriptor",
- [ECHILD] = "No child processes",
- [EAGAIN] = "Try again",
- [ENOMEM] = "Out of memory",
- [EACCES] = "Permission denied",
- [EFAULT] = "Bad address",
- [ENOTBLK] = "Block device required",
- [EBUSY] = "Device or resource busy",
- [EEXIST] = "File exists",
- [EXDEV] = "Cross-device link",
- [ENODEV] = "No such device",
- [ENOTDIR] = "Not a directory",
- [EISDIR] = "Is a directory",
- [EINVAL] = "Invalid argument",
- [ENFILE] = "File table overflow",
- [EMFILE] = "Too many open files",
- [ENOTTY] = "Inappropriate ioctl for device",
- [ETXTBSY] = "Text file busy",
- [EFBIG] = "File too large",
- [ENOSPC] = "No space left on device",
- [ESPIPE] = "Illegal seek",
- [EROFS] = "Read-only file system",
- [EMLINK] = "Too many links",
- [EPIPE] = "Broken pipe",
- [EDOM] = "Math argument out of domain of func",
- [ERANGE] = "Math result not representable",
- [EDEADLK] = "Resource deadlock would occur",
- [ENAMETOOLONG] = "File name too long",
- [ENOLCK] = "No record locks available",
- [ENOSYS] = "Function not implemented",
- [ENOTEMPTY] = "Directory not empty",
- [ELOOP] = "Too many symbolic links encountered",
- [ENOMSG] = "No message of desired type",
- [EIDRM] = "Identifier removed",
- [ECHRNG] = "Channel number out of range",
- [EL2NSYNC] = "Level 2 not synchronized",
- [EL3HLT] = "Level 3 halted",
- [EL3RST] = "Level 3 reset",
- [ELNRNG] = "Link number out of range",
- [EUNATCH] = "Protocol driver not attached",
- [ENOCSI] = "No CSI structure available",
- [EL2HLT] = "Level 2 halted",
- [EBADE] = "Invalid exchange",
- [EBADR] = "Invalid request descriptor",
- [EXFULL] = "Exchange full",
- [ENOANO] = "No anode",
- [EBADRQC] = "Invalid request code",
- [EBADSLT] = "Invalid slot",
- [EBFONT] = "Bad font file format",
- [ENOSTR] = "Device not a stream",
- [ENODATA] = "No data available",
- [ETIME] = "Timer expired",
- [ENOSR] = "Out of streams resources",
- [ENONET] = "Machine is not on the network",
- [ENOPKG] = "Package not installed",
- [EREMOTE] = "Object is remote",
- [ENOLINK] = "Link has been severed",
- [EADV] = "Advertise error",
- [ESRMNT] = "Srmount error",
- [ECOMM] = "Communication error on send",
- [EPROTO] = "Protocol error",
- [EMULTIHOP] = "Multihop attempted",
- [EDOTDOT] = "RFS specific error",
- [EBADMSG] = "Not a data message",
- [EOVERFLOW] = "Value too large for defined data type",
- [ENOTUNIQ] = "Name not unique on network",
- [EBADFD] = "File descriptor in bad state",
- [EREMCHG] = "Remote address changed",
- [ELIBACC] = "Can not access a needed shared library",
- [ELIBBAD] = "Accessing a corrupted shared library",
- [ELIBSCN] = ".lib section in a.out corrupted",
- [ELIBMAX] = "Attempting to link in too many shared libraries",
- [ELIBEXEC] = "Cannot exec a shared library directly",
- [EILSEQ] = "Illegal byte sequence",
- [ERESTART] = "Interrupted system call should be restarted",
- [ESTRPIPE] = "Streams pipe error",
- [EUSERS] = "Too many users",
- [ENOTSOCK] = "Socket operation on non-socket",
- [EDESTADDRREQ] = "Destination address required",
- [EMSGSIZE] = "Message too long",
- [EPROTOTYPE] = "Protocol wrong type for socket",
- [ENOPROTOOPT] = "Protocol not available",
- [EPROTONOSUPPORT] = "Protocol not supported",
- [ESOCKTNOSUPPORT] = "Socket type not supported",
- [EOPNOTSUPP] = "Operation not supported on transport endpoint",
- [EPFNOSUPPORT] = "Protocol family not supported",
- [EAFNOSUPPORT] = "Address family not supported by protocol",
- [EADDRINUSE] = "Address already in use",
- [EADDRNOTAVAIL] = "Cannot assign requested address",
- [ENETDOWN] = "Network is down",
- [ENETUNREACH] = "Network is unreachable",
- [ENETRESET] = "Network dropped connection because of reset",
- [ECONNABORTED] = "Software caused connection abort",
- [ECONNRESET] = "Connection reset by peer",
- [ENOBUFS] = "No buffer space available",
- [EISCONN] = "Transport endpoint is already connected",
- [ENOTCONN] = "Transport endpoint is not connected",
- [ESHUTDOWN] = "Cannot send after transport endpoint shutdown",
- [ETOOMANYREFS] = "Too many references: cannot splice",
- [ETIMEDOUT] = "Connection timed out",
- [ECONNREFUSED] = "Connection refused",
- [EHOSTDOWN] = "Host is down",
- [EHOSTUNREACH] = "No route to host",
- [EALREADY] = "Operation already in progress",
- [EINPROGRESS] = "Operation now in progress",
- [ESTALE] = "Stale NFS file handle",
- [EUCLEAN] = "Structure needs cleaning",
- [ENOTNAM] = "Not a XENIX named type file",
- [ENAVAIL] = "No XENIX semaphores available",
- [EISNAM] = "Is a named type file",
- [EREMOTEIO] = "Remote I/O error",
- [EDQUOT] = "Quota exceeded",
- [ENOMEDIUM] = "No medium found",
- [EMEDIUMTYPE] = "Wrong medium type",
- [ECANCELED] = "Operation Canceled",
- [ENOKEY] = "Required key not available",
- [EKEYEXPIRED] = "Key has expired",
- [EKEYREVOKED] = "Key has been revoked",
- [EKEYREJECTED] = "Key was rejected by service",
- [EOWNERDEAD] = "Owner died",
- [ENOTRECOVERABLE] = "State not recoverable",
- [ERFKILL] = "Operation not possible due to RF-kill",
- [EHWPOISON] = "Memory page has hardware error",
+static const char* __sys_error_descriptions[] = {
+#define __BIONIC_ERRDEF(error_number, error_description) [error_number] = error_description,
+#include "private/bionic_errdefs.h"
};
-static inline const char* __strerror_lookup(int error_number) {
- if (error_number < 0 || error_number >= static_cast<int>(arraysize(__sys_error_strings))) {
+static const char* __sys_error_names[] = {
+#define __BIONIC_ERRDEF(error_number, error_description) [error_number] = #error_number,
+#include "private/bionic_errdefs.h"
+};
+
+extern "C" const char* strerrorname_np(int error_number) {
+ if (error_number < 0 || error_number >= static_cast<int>(arraysize(__sys_error_names))) {
return nullptr;
}
- return __sys_error_strings[error_number];
+ return __sys_error_names[error_number];
+}
+
+static inline const char* __strerror_lookup(int error_number) {
+ if (error_number < 0 || error_number >= static_cast<int>(arraysize(__sys_error_descriptions))) {
+ return nullptr;
+ }
+ return __sys_error_descriptions[error_number];
}
int strerror_r(int error_number, char* buf, size_t buf_len) {
diff --git a/libc/bionic/strsignal.cpp b/libc/bionic/strsignal.cpp
index 05d3498..f18b6d0 100644
--- a/libc/bionic/strsignal.cpp
+++ b/libc/bionic/strsignal.cpp
@@ -32,12 +32,12 @@
#include "bionic/pthread_internal.h"
const char* const sys_siglist[NSIG] = {
-#define __BIONIC_SIGDEF(signal_number, signal_description) [ signal_number ] = signal_description,
+#define __BIONIC_SIGDEF(signal_number, signal_description) [signal_number] = signal_description,
#include "private/bionic_sigdefs.h"
};
const char* const sys_signame[NSIG] = {
-#define __BIONIC_SIGDEF(signal_number, unused) [ signal_number ] = &(#signal_number)[3],
+#define __BIONIC_SIGDEF(signal_number, unused) [signal_number] = &(#signal_number)[3],
#include "private/bionic_sigdefs.h"
};
diff --git a/libc/include/android/api-level.h b/libc/include/android/api-level.h
index 6602e5d..77ec653 100644
--- a/libc/include/android/api-level.h
+++ b/libc/include/android/api-level.h
@@ -40,7 +40,7 @@
* @brief Functions and constants for dealing with multiple API levels.
*
* See
- * https://android.googlesource.com/platform/bionic/+/master/docs/defines.md.
+ * https://android.googlesource.com/platform/bionic/+/main/docs/defines.md.
*/
#include <sys/cdefs.h>
@@ -50,7 +50,7 @@
/**
* Magic version number for an Android OS build which has not yet turned
* into an official release, for comparison against `__ANDROID_API__`. See
- * https://android.googlesource.com/platform/bionic/+/master/docs/defines.md.
+ * https://android.googlesource.com/platform/bionic/+/main/docs/defines.md.
*/
#define __ANDROID_API_FUTURE__ 10000
@@ -91,7 +91,7 @@
*
* See android_get_device_api_level(),
* android_get_application_target_sdk_version() and
- * https://android.googlesource.com/platform/bionic/+/master/docs/defines.md.
+ * https://android.googlesource.com/platform/bionic/+/main/docs/defines.md.
*/
#define __ANDROID_API__ __ANDROID_API_FUTURE__
#endif
diff --git a/libc/include/bits/ctype_inlines.h b/libc/include/bits/ctype_inlines.h
deleted file mode 100644
index 089a642..0000000
--- a/libc/include/bits/ctype_inlines.h
+++ /dev/null
@@ -1,209 +0,0 @@
-/*
- * Copyright (C) 2014 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>
-#include <xlocale.h>
-
-#if !defined(__BIONIC_CTYPE_INLINE)
-#define __BIONIC_CTYPE_INLINE static __inline
-#endif
-
-/** Internal implementation detail. Do not use. */
-#define _CTYPE_U 0x01
-/** Internal implementation detail. Do not use. */
-#define _CTYPE_L 0x02
-/** Internal implementation detail. Do not use. */
-#define _CTYPE_D 0x04
-/** Internal implementation detail. Do not use. */
-#define _CTYPE_S 0x08
-/** Internal implementation detail. Do not use. */
-#define _CTYPE_P 0x10
-/** Internal implementation detail. Do not use. */
-#define _CTYPE_C 0x20
-/** Internal implementation detail. Do not use. */
-#define _CTYPE_X 0x40
-/** Internal implementation detail. Do not use. */
-#define _CTYPE_B 0x80
-/** Internal implementation detail. Do not use. */
-#define _CTYPE_R (_CTYPE_P|_CTYPE_U|_CTYPE_L|_CTYPE_D|_CTYPE_B)
-/** Internal implementation detail. Do not use. */
-#define _CTYPE_A (_CTYPE_L|_CTYPE_U)
-/** Internal implementation detail. Do not use. */
-#define _CTYPE_N _CTYPE_D
-
-__BEGIN_DECLS
-
-/** Internal implementation detail. Do not use. */
-extern const char* _Nonnull _ctype_;
-
-/** Returns true if `ch` is in `[A-Za-z0-9]`. */
-__BIONIC_CTYPE_INLINE int isalnum(int __ch) {
- // `isalnum(c)` is `isalpha(c) || isdigit(c)`, but there's no obvious way
- // to simplify that, and the table lookup is just slightly faster...
- // Note that this is unsafe for inputs less than -1 (EOF) or greater than
- // 0xff. This is true of other C libraries too.
- return (_ctype_[__ch + 1] & (_CTYPE_U|_CTYPE_L|_CTYPE_N));
-}
-
-/** Returns true if `ch` is in `[A-Za-z]`. */
-__BIONIC_CTYPE_INLINE int isalpha(int __ch) {
- return (__ch >= 'A' && __ch <= 'Z') || (__ch >= 'a' && __ch <= 'z');
-}
-
-/** Returns true if `ch` is a space or tab. */
-__BIONIC_CTYPE_INLINE int isblank(int __ch) {
- return __ch == ' ' || __ch == '\t';
-}
-
-/** Returns true if `ch` is a control character (any character before space, plus DEL). */
-__BIONIC_CTYPE_INLINE int iscntrl(int __ch) {
- return (__BIONIC_CAST(static_cast, unsigned, __ch) < ' ') || __ch == 0x7f;
-}
-
-/** Returns true if `ch` is in `[0-9]`. */
-__BIONIC_CTYPE_INLINE int isdigit(int __ch) {
- return (__ch >= '0' && __ch <= '9');
-}
-
-/** Returns true if `ch` is `[A-Za-z0-9]` or punctuation. */
-__BIONIC_CTYPE_INLINE int isgraph(int __ch) {
- return (__ch >= '!' && __ch <= '~');
-}
-
-/** Returns true if `ch` is in `[a-z]`. */
-__BIONIC_CTYPE_INLINE int islower(int __ch) {
- return (__ch >= 'a' && __ch <= 'z');
-}
-
-/** Returns true if `ch` is `[A-Za-z0-9]` or punctuation or space. */
-__BIONIC_CTYPE_INLINE int isprint(int __ch) {
- return (__ch >= ' ' && __ch <= '~');
-}
-
-/** Returns true if `ch` is punctuation. */
-__BIONIC_CTYPE_INLINE int ispunct(int __ch) {
- // `ispunct(c)` is `isgraph(c) && !isalnum(c)`, but there's no obvious way
- // to simplify that, and the table lookup is just slightly faster...
- // Note that this is unsafe for inputs less than -1 (EOF) or greater than
- // 0xff. This is true of other C libraries too.
- return (_ctype_[__ch + 1] & _CTYPE_P);
-}
-
-/** Returns true if `ch` is in `[ \f\n\r\t\v]`. */
-__BIONIC_CTYPE_INLINE int isspace(int __ch) {
- return __ch == ' ' || (__ch >= '\t' && __ch <= '\r');
-}
-
-/** Returns true if `ch` is in `[A-Z]`. */
-__BIONIC_CTYPE_INLINE int isupper(int __ch) {
- return (__ch >= 'A' && __ch <= 'Z');
-}
-
-/** Returns true if `ch` is in `[0-9A-Fa-f]`. */
-__BIONIC_CTYPE_INLINE int isxdigit(int __ch) {
- return (__ch >= '0' && __ch <= '9') || (__ch >= 'a' && __ch <= 'f') || (__ch >= 'A' && __ch <= 'F');
-}
-
-/**
- * Returns the corresponding lower-case character if `ch` is upper-case, or undefined otherwise.
- *
- * Prefer tolower() instead.
- */
-__BIONIC_CTYPE_INLINE int _tolower(int __ch) {
- return __ch | 0x20;
-}
-
-/** Returns the corresponding lower-case character if `ch` is upper-case, or `ch` otherwise. */
-__BIONIC_CTYPE_INLINE int tolower(int __ch) {
- if (__ch >= 'A' && __ch <= 'Z') return _tolower(__ch);
- return __ch;
-}
-
-/**
- * Returns the corresponding upper-case character if `ch` is lower-case, or undefined otherwise.
- *
- * Prefer toupper() instead.
- */
-__BIONIC_CTYPE_INLINE int _toupper(int __ch) {
- // Using EOR rather than AND makes no difference on arm, but saves an
- // instruction on arm64.
- return __ch ^ 0x20;
-}
-
-/** Returns the corresponding upper-case character if `ch` is lower-case, or `ch` otherwise. */
-__BIONIC_CTYPE_INLINE int toupper(int __ch) {
- if (__ch >= 'a' && __ch <= 'z') return _toupper(__ch);
- return __ch;
-}
-
-/** Returns true if `ch` is less than 0x80. */
-__BIONIC_CTYPE_INLINE int isascii(int __ch) {
- return __BIONIC_CAST(static_cast, unsigned, __ch) < 0x80;
-}
-
-/** Returns `ch & 0x7f`. */
-__BIONIC_CTYPE_INLINE int toascii(int __ch) {
- return __ch & 0x7f;
-}
-
-#if __ANDROID_API__ >= 21
-/** Like isalnum but with an ignored `locale_t`. */
-int isalnum_l(int __ch, locale_t _Nonnull __l) __INTRODUCED_IN(21);
-/** Like isalpha but with an ignored `locale_t`. */
-int isalpha_l(int __ch, locale_t _Nonnull __l) __INTRODUCED_IN(21);
-/** Like isblank but with an ignored `locale_t`. */
-int isblank_l(int __ch, locale_t _Nonnull __l) __INTRODUCED_IN(21);
-/** Like iscntrl but with an ignored `locale_t`. */
-int iscntrl_l(int __ch, locale_t _Nonnull __l) __INTRODUCED_IN(21);
-/** Like isdigit but with an ignored `locale_t`. */
-int isdigit_l(int __ch, locale_t _Nonnull __l) __INTRODUCED_IN(21);
-/** Like isgraph but with an ignored `locale_t`. */
-int isgraph_l(int __ch, locale_t _Nonnull __l) __INTRODUCED_IN(21);
-/** Like islower but with an ignored `locale_t`. */
-int islower_l(int __ch, locale_t _Nonnull __l) __INTRODUCED_IN(21);
-/** Like isprint but with an ignored `locale_t`. */
-int isprint_l(int __ch, locale_t _Nonnull __l) __INTRODUCED_IN(21);
-/** Like ispunct but with an ignored `locale_t`. */
-int ispunct_l(int __ch, locale_t _Nonnull __l) __INTRODUCED_IN(21);
-/** Like isspace but with an ignored `locale_t`. */
-int isspace_l(int __ch, locale_t _Nonnull __l) __INTRODUCED_IN(21);
-/** Like isupper but with an ignored `locale_t`. */
-int isupper_l(int __ch, locale_t _Nonnull __l) __INTRODUCED_IN(21);
-/** Like isxdigit but with an ignored `locale_t`. */
-int isxdigit_l(int __ch, locale_t _Nonnull __l) __INTRODUCED_IN(21);
-/** Like tolower but with an ignored `locale_t`. */
-int tolower_l(int __ch, locale_t _Nonnull __l) __INTRODUCED_IN(21);
-/** Like toupper but with an ignored `locale_t`. */
-int toupper_l(int __ch, locale_t _Nonnull __l) __INTRODUCED_IN(21);
-#else
-// Implemented as static inlines in libc++ before 21.
-#endif
-
-__END_DECLS
diff --git a/libc/include/ctype.h b/libc/include/ctype.h
index 3b82a76..c15ee56 100644
--- a/libc/include/ctype.h
+++ b/libc/include/ctype.h
@@ -34,6 +34,215 @@
*/
#include <sys/cdefs.h>
+#include <xlocale.h>
+/* 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
+ * also provide actual symbols for any caller that needs them.
+ */
+#if !defined(__BIONIC_CTYPE_INLINE)
#define __BIONIC_CTYPE_INLINE static __inline
-#include <bits/ctype_inlines.h>
+#endif
+
+/** Internal implementation detail. Do not use. */
+#define _CTYPE_U 0x01
+/** Internal implementation detail. Do not use. */
+#define _CTYPE_L 0x02
+/** Internal implementation detail. Do not use. */
+#define _CTYPE_D 0x04
+/** Internal implementation detail. Do not use. */
+#define _CTYPE_S 0x08
+/** Internal implementation detail. Do not use. */
+#define _CTYPE_P 0x10
+/** Internal implementation detail. Do not use. */
+#define _CTYPE_C 0x20
+/** Internal implementation detail. Do not use. */
+#define _CTYPE_X 0x40
+/** Internal implementation detail. Do not use. */
+#define _CTYPE_B 0x80
+/** Internal implementation detail. Do not use. */
+#define _CTYPE_R (_CTYPE_P|_CTYPE_U|_CTYPE_L|_CTYPE_D|_CTYPE_B)
+/** Internal implementation detail. Do not use. */
+#define _CTYPE_A (_CTYPE_L|_CTYPE_U)
+/** Internal implementation detail. Do not use. */
+#define _CTYPE_N _CTYPE_D
+
+__BEGIN_DECLS
+
+/** Internal implementation detail. Do not use. */
+extern const char* _ctype_;
+
+/** Returns true if `ch` is in `[A-Za-z]`. */
+__BIONIC_CTYPE_INLINE int isalpha(int __ch) {
+ return (__ch >= 'A' && __ch <= 'Z') || (__ch >= 'a' && __ch <= 'z');
+}
+
+/** Returns true if `ch` is a space or tab. */
+__BIONIC_CTYPE_INLINE int isblank(int __ch) {
+ return __ch == ' ' || __ch == '\t';
+}
+
+/** Returns true if `ch` is a control character (any character before space, plus DEL). */
+__BIONIC_CTYPE_INLINE int iscntrl(int __ch) {
+ return (__BIONIC_CAST(static_cast, unsigned, __ch) < ' ') || __ch == 0x7f;
+}
+
+/** Returns true if `ch` is in `[0-9]`. */
+__BIONIC_CTYPE_INLINE int isdigit(int __ch) {
+ return (__ch >= '0' && __ch <= '9');
+}
+
+/** Returns true if `ch` is `[A-Za-z0-9]` or punctuation. */
+__BIONIC_CTYPE_INLINE int isgraph(int __ch) {
+ return (__ch >= '!' && __ch <= '~');
+}
+
+/** Returns true if `ch` is in `[a-z]`. */
+__BIONIC_CTYPE_INLINE int islower(int __ch) {
+ return (__ch >= 'a' && __ch <= 'z');
+}
+
+/** Returns true if `ch` is `[A-Za-z0-9]` or punctuation or space. */
+__BIONIC_CTYPE_INLINE int isprint(int __ch) {
+ return (__ch >= ' ' && __ch <= '~');
+}
+
+/** Returns true if `ch` is in `[ \f\n\r\t\v]`. */
+__BIONIC_CTYPE_INLINE int isspace(int __ch) {
+ return __ch == ' ' || (__ch >= '\t' && __ch <= '\r');
+}
+
+/** Returns true if `ch` is in `[A-Z]`. */
+__BIONIC_CTYPE_INLINE int isupper(int __ch) {
+ return (__ch >= 'A' && __ch <= 'Z');
+}
+
+/** Returns true if `ch` is in `[0-9A-Fa-f]`. */
+__BIONIC_CTYPE_INLINE int isxdigit(int __ch) {
+ return (__ch >= '0' && __ch <= '9') || (__ch >= 'a' && __ch <= 'f') || (__ch >= 'A' && __ch <= 'F');
+}
+
+/** Returns true if `ch` is in `[A-Za-z0-9]`. */
+__BIONIC_CTYPE_INLINE int isalnum(int __ch) {
+ return isalpha(__ch) || isdigit(__ch);
+}
+
+/** Returns true if `ch` is punctuation. */
+__BIONIC_CTYPE_INLINE int ispunct(int __ch) {
+ return isgraph(__ch) && !isalnum(__ch);
+}
+
+/**
+ * Returns the corresponding lower-case character if `ch` is upper-case, or undefined otherwise.
+ *
+ * Prefer tolower() instead.
+ */
+__BIONIC_CTYPE_INLINE int _tolower(int __ch) {
+ return __ch | 0x20;
+}
+
+/** Returns the corresponding lower-case character if `ch` is upper-case, or `ch` otherwise. */
+__BIONIC_CTYPE_INLINE int tolower(int __ch) {
+ if (__ch >= 'A' && __ch <= 'Z') return _tolower(__ch);
+ return __ch;
+}
+
+/**
+ * Returns the corresponding upper-case character if `ch` is lower-case, or undefined otherwise.
+ *
+ * Prefer toupper() instead.
+ */
+__BIONIC_CTYPE_INLINE int _toupper(int __ch) {
+ // Using EOR rather than AND makes no difference on arm, but saves an
+ // instruction on arm64.
+ return __ch ^ 0x20;
+}
+
+/** Returns the corresponding upper-case character if `ch` is lower-case, or `ch` otherwise. */
+__BIONIC_CTYPE_INLINE int toupper(int __ch) {
+ if (__ch >= 'a' && __ch <= 'z') return _toupper(__ch);
+ return __ch;
+}
+
+/** Returns true if `ch` is less than 0x80. */
+__BIONIC_CTYPE_INLINE int isascii(int __ch) {
+ return __BIONIC_CAST(static_cast, unsigned, __ch) < 0x80;
+}
+
+/** Returns `ch & 0x7f`. */
+__BIONIC_CTYPE_INLINE int toascii(int __ch) {
+ return __ch & 0x7f;
+}
+
+/** Like isalnum() but with an ignored `locale_t`. */
+__BIONIC_CTYPE_INLINE int isalnum_l(int __ch, locale_t __l) {
+ return isalnum(__ch);
+}
+
+/** Like isalpha() but with an ignored `locale_t`. */
+__BIONIC_CTYPE_INLINE int isalpha_l(int __ch, locale_t __l) {
+ return isalpha(__ch);
+}
+
+/** Like isblank() but with an ignored `locale_t`. */
+__BIONIC_CTYPE_INLINE int isblank_l(int __ch, locale_t __l) {
+ return isblank(__ch);
+}
+
+/** Like iscntrl() but with an ignored `locale_t`. */
+__BIONIC_CTYPE_INLINE int iscntrl_l(int __ch, locale_t __l) {
+ return iscntrl(__ch);
+}
+
+/** Like isdigit() but with an ignored `locale_t`. */
+__BIONIC_CTYPE_INLINE int isdigit_l(int __ch, locale_t __l) {
+ return isdigit(__ch);
+}
+
+/** Like isgraph() but with an ignored `locale_t`. */
+__BIONIC_CTYPE_INLINE int isgraph_l(int __ch, locale_t __l) {
+ return isgraph(__ch);
+}
+
+/** Like islower() but with an ignored `locale_t`. */
+__BIONIC_CTYPE_INLINE int islower_l(int __ch, locale_t __l) {
+ return islower(__ch);
+}
+
+/** Like isprint() but with an ignored `locale_t`. */
+__BIONIC_CTYPE_INLINE int isprint_l(int __ch, locale_t __l) {
+ return isprint(__ch);
+}
+
+/** Like ispunct() but with an ignored `locale_t`. */
+__BIONIC_CTYPE_INLINE int ispunct_l(int __ch, locale_t __l) {
+ return ispunct(__ch);
+}
+
+/** Like isspace() but with an ignored `locale_t`. */
+__BIONIC_CTYPE_INLINE int isspace_l(int __ch, locale_t __l) {
+ return isspace(__ch);
+}
+
+/** Like isupper() but with an ignored `locale_t`. */
+__BIONIC_CTYPE_INLINE int isupper_l(int __ch, locale_t __l) {
+ return isupper(__ch);
+}
+
+/** Like isxdigit() but with an ignored `locale_t`. */
+__BIONIC_CTYPE_INLINE int isxdigit_l(int __ch, locale_t __l) {
+ return isxdigit(__ch);
+}
+
+/** Like tolower() but with an ignored `locale_t`. */
+__BIONIC_CTYPE_INLINE int tolower_l(int __ch, locale_t __l) {
+ return tolower(__ch);
+}
+
+/** Like toupper() but with an ignored `locale_t`. */
+__BIONIC_CTYPE_INLINE int toupper_l(int __ch, locale_t __l) {
+ return toupper(__ch);
+}
+
+__END_DECLS
diff --git a/libc/include/malloc.h b/libc/include/malloc.h
index 6f992d9..d22b85c 100644
--- a/libc/include/malloc.h
+++ b/libc/include/malloc.h
@@ -361,7 +361,7 @@
*
* Available since API level 28.
*
- * See also: [extra documentation](https://android.googlesource.com/platform/bionic/+/master/libc/malloc_hooks/README.md)
+ * See also: [extra documentation](https://android.googlesource.com/platform/bionic/+/main/libc/malloc_hooks/README.md)
*/
extern void* _Nonnull (*volatile _Nonnull __malloc_hook)(size_t __byte_count, const void* _Nonnull __caller) __INTRODUCED_IN(28);
@@ -372,7 +372,7 @@
*
* Available since API level 28.
*
- * See also: [extra documentation](https://android.googlesource.com/platform/bionic/+/master/libc/malloc_hooks/README.md)
+ * See also: [extra documentation](https://android.googlesource.com/platform/bionic/+/main/libc/malloc_hooks/README.md)
*/
extern void* _Nonnull (*volatile _Nonnull __realloc_hook)(void* _Nullable __ptr, size_t __byte_count, const void* _Nonnull __caller) __INTRODUCED_IN(28);
@@ -383,7 +383,7 @@
*
* Available since API level 28.
*
- * See also: [extra documentation](https://android.googlesource.com/platform/bionic/+/master/libc/malloc_hooks/README.md)
+ * See also: [extra documentation](https://android.googlesource.com/platform/bionic/+/main/libc/malloc_hooks/README.md)
*/
extern void (*volatile _Nonnull __free_hook)(void* _Nullable __ptr, const void* _Nonnull __caller) __INTRODUCED_IN(28);
@@ -394,7 +394,7 @@
*
* Available since API level 28.
*
- * See also: [extra documentation](https://android.googlesource.com/platform/bionic/+/master/libc/malloc_hooks/README.md)
+ * See also: [extra documentation](https://android.googlesource.com/platform/bionic/+/main/libc/malloc_hooks/README.md)
*/
extern void* _Nonnull (*volatile _Nonnull __memalign_hook)(size_t __alignment, size_t __byte_count, const void* _Nonnull __caller) __INTRODUCED_IN(28);
diff --git a/libc/include/stdio.h b/libc/include/stdio.h
index 2fc5b21..312b356 100644
--- a/libc/include/stdio.h
+++ b/libc/include/stdio.h
@@ -203,7 +203,7 @@
int fseek(FILE* _Nonnull __fp, long __offset, int __whence);
long ftell(FILE* _Nonnull __fp);
-/* See https://android.googlesource.com/platform/bionic/+/master/docs/32-bit-abi.md */
+/* See https://android.googlesource.com/platform/bionic/+/main/docs/32-bit-abi.md */
#if defined(__USE_FILE_OFFSET64)
int fgetpos(FILE* _Nonnull __fp, fpos_t* _Nonnull __pos) __RENAME(fgetpos64) __INTRODUCED_IN(24);
int fsetpos(FILE* _Nonnull __fp, const fpos_t* _Nonnull __pos) __RENAME(fsetpos64) __INTRODUCED_IN(24);
diff --git a/libc/include/string.h b/libc/include/string.h
index e7fd9a5..89b2a45 100644
--- a/libc/include/string.h
+++ b/libc/include/string.h
@@ -116,6 +116,33 @@
int strerror_r(int __errno_value, char* _Nonnull __buf, size_t __n);
#endif
+/**
+ * [strerrorname_np(3)](http://man7.org/linux/man-pages/man3/strerrordesc_np.3.html)
+ * returns the name of the errno constant corresponding to its argument.
+ * `strerrorname_np(38)` would return "ENOSYS", because `ENOSYS` is errno 38. This
+ * is mostly useful for error reporting in cases where a string like "ENOSYS" is
+ * more readable than a string like "Function not implemented", which would be
+ * returned by strerror().
+ *
+ * Returns a pointer to a string, or null for unknown errno values.
+ *
+ * Available since API level 35.
+ */
+#if defined(__USE_GNU)
+const char* _Nullable strerrorname_np(int __errno_value) __INTRODUCED_IN(35);
+#endif
+
+/**
+ * [strerrordesc_np(3)](http://man7.org/linux/man-pages/man3/strerrordesc_np.3.html)
+ * is like strerror() but without localization. Since Android's strerror()
+ * does not localize, this is the same as strerror() on Android.
+ *
+ * Returns a pointer to a string.
+ */
+#if defined(__USE_GNU)
+const char* _Nonnull strerrordesc_np(int __errno_value) __RENAME(strerror);
+#endif
+
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);
diff --git a/libc/include/sys/cdefs.h b/libc/include/sys/cdefs.h
index 4154e62..a8fb624 100644
--- a/libc/include/sys/cdefs.h
+++ b/libc/include/sys/cdefs.h
@@ -38,7 +38,7 @@
/**
* `__BIONIC__` is always defined if you're building with bionic. See
- * https://android.googlesource.com/platform/bionic/+/master/docs/defines.md.
+ * https://android.googlesource.com/platform/bionic/+/main/docs/defines.md.
*/
#define __BIONIC__ 1
@@ -187,7 +187,7 @@
/*
* _FILE_OFFSET_BITS 64 support.
- * See https://android.googlesource.com/platform/bionic/+/master/docs/32-bit-abi.md
+ * See https://android.googlesource.com/platform/bionic/+/main/docs/32-bit-abi.md
*/
#if !defined(__LP64__) && defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64
# define __USE_FILE_OFFSET64 1
diff --git a/libc/include/sys/mman.h b/libc/include/sys/mman.h
index f32ae61..823c9ba 100644
--- a/libc/include/sys/mman.h
+++ b/libc/include/sys/mman.h
@@ -58,7 +58,7 @@
/**
* mmap64() is a variant of mmap() that takes a 64-bit offset even on LP32.
*
- * See https://android.googlesource.com/platform/bionic/+/master/docs/32-bit-abi.md
+ * See https://android.googlesource.com/platform/bionic/+/main/docs/32-bit-abi.md
*/
void* _Nonnull mmap64(void* _Nullable __addr, size_t __size, int __prot, int __flags, int __fd, off64_t __offset);
diff --git a/libc/include/sys/sendfile.h b/libc/include/sys/sendfile.h
index a72091d..26522a6 100644
--- a/libc/include/sys/sendfile.h
+++ b/libc/include/sys/sendfile.h
@@ -38,7 +38,7 @@
__BEGIN_DECLS
-/* See https://android.googlesource.com/platform/bionic/+/master/docs/32-bit-abi.md */
+/* See https://android.googlesource.com/platform/bionic/+/main/docs/32-bit-abi.md */
#if defined(__USE_FILE_OFFSET64)
ssize_t sendfile(int __out_fd, int __in_fd, off_t* _Nullable __offset, size_t __count) __RENAME(sendfile64);
#else
diff --git a/libc/include/sys/types.h b/libc/include/sys/types.h
index f07c8fd..4622a4e 100644
--- a/libc/include/sys/types.h
+++ b/libc/include/sys/types.h
@@ -96,7 +96,7 @@
typedef __time_t time_t;
/* This historical accident means that we had a 32-bit off_t on 32-bit architectures. */
-/* See https://android.googlesource.com/platform/bionic/+/master/docs/32-bit-abi.md */
+/* See https://android.googlesource.com/platform/bionic/+/main/docs/32-bit-abi.md */
#if defined(__USE_FILE_OFFSET64) || defined(__LP64__)
typedef int64_t off_t;
typedef off_t loff_t;
diff --git a/libc/include/time64.h b/libc/include/time64.h
index 7d70030..8d31c6f 100644
--- a/libc/include/time64.h
+++ b/libc/include/time64.h
@@ -24,9 +24,6 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-Origin: http://code.google.com/p/y2038
-Modified for Bionic by the Android Open Source Project
-
*/
#ifndef TIME64_H
#define TIME64_H
diff --git a/libc/include/unistd.h b/libc/include/unistd.h
index dcad630..c8cceb2 100644
--- a/libc/include/unistd.h
+++ b/libc/include/unistd.h
@@ -265,7 +265,7 @@
int fsync(int __fd);
int fdatasync(int __fd);
-/* See https://android.googlesource.com/platform/bionic/+/master/docs/32-bit-abi.md */
+/* See https://android.googlesource.com/platform/bionic/+/main/docs/32-bit-abi.md */
#if defined(__USE_FILE_OFFSET64)
int truncate(const char* _Nonnull __path, off_t __length) __RENAME(truncate64);
off_t lseek(int __fd, off_t __offset, int __whence) __RENAME(lseek64);
diff --git a/libc/kernel/android/BUILD b/libc/kernel/android/BUILD
deleted file mode 100644
index b862a6d..0000000
--- a/libc/kernel/android/BUILD
+++ /dev/null
@@ -1,43 +0,0 @@
-# Copyright (C) 2022 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.
-
-load("//build/bazel/rules/apis:cc_api_contribution.bzl", "cc_api_headers")
-
-package(default_visibility = ["//bionic/libc:__pkg__"])
-
-cc_api_headers(
- name="libc_kernel_android_uapi_headers",
- include_dir="uapi",
- hdrs=glob(["uapi/**/*.h"]),
- system=True,
-)
-
-cc_api_headers(
- name="libc_kernel_android_scsi_headers",
- include_dir="scsi",
- hdrs=glob(["scsi/**/*.h"]),
- system=True,
-)
diff --git a/libc/kernel/tools/cpp.py b/libc/kernel/tools/cpp.py
index 40e1f26..c0b379b 100755
--- a/libc/kernel/tools/cpp.py
+++ b/libc/kernel/tools/cpp.py
@@ -1471,9 +1471,18 @@
made_change = True
i += 1
- if b.isDefine() and b.define_id in replacements:
- b.define_id = replacements[b.define_id]
- made_change = True
+ if b.isDefine():
+ tokens = CppStringTokenizer(b.define_id).tokens
+ id_change = False
+ for tok in tokens:
+ if tok.kind == TokenKind.IDENTIFIER:
+ if tok.id in replacements:
+ tok.id = replacements[tok.id]
+ id_change = True
+ if id_change:
+ b.define_id = ''.join([tok.id for tok in tokens])
+ made_change = True
+
if made_change and b.isIf():
# Keep 'expr' in sync with 'tokens'.
@@ -2578,10 +2587,12 @@
text = """\
#define SIGRTMIN 32
#define SIGRTMAX _NSIG
+#define SIGRTMAX(a,class) some_func(a, class)
"""
expected = """\
#define __SIGRTMIN 32
#define __SIGRTMAX _KERNEL__NSIG
+#define __SIGRTMAX(a,__linux_class) some_func(a, __linux_class)
"""
self.assertEqual(self.parse(text), expected)
diff --git a/libc/kernel/tools/defaults.py b/libc/kernel/tools/defaults.py
index 91d26ce..65e0117 100644
--- a/libc/kernel/tools/defaults.py
+++ b/libc/kernel/tools/defaults.py
@@ -63,6 +63,7 @@
# The kernel usage of __unused for unused struct fields conflicts with the macro defined in <sys/cdefs.h>.
"__unused": "__linux_unused",
# The kernel usage of C++ keywords causes problems for C++ code so rename.
+ "class": "__linux_class",
"private": "__linux_private",
"virtual": "__linux_virtual",
# The non-64 stuff is legacy; msqid64_ds/ipc64_perm is what userspace wants.
@@ -125,6 +126,8 @@
# These are required to support the above functions.
"__fswahw32",
"__fswahb32",
+ # This is used by various macros in <linux/ioprio.h>.
+ "ioprio_value",
]
)
diff --git a/libc/kernel/uapi/BUILD b/libc/kernel/uapi/BUILD
deleted file mode 100644
index 3c9bb69..0000000
--- a/libc/kernel/uapi/BUILD
+++ /dev/null
@@ -1,67 +0,0 @@
-# Copyright (C) 2022 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.
-
-load("//build/bazel/rules/apis:cc_api_contribution.bzl", "cc_api_headers")
-
-package(default_visibility = ["//bionic/libc:__pkg__"])
-
-cc_api_headers(
- name = "libc_kernel_uapi_headers",
- hdrs = glob(["**/*.h"]),
- system = True,
-)
-
-cc_api_headers(
- name = "libc_kernel_uapi_asm_arm_headers",
- hdrs = glob(["asm-arm/**/*.h"]),
- arch = "arm",
- include_dir = "asm-arm",
- system = True,
-)
-
-cc_api_headers(
- name = "libc_kernel_uapi_asm_arm64_headers",
- hdrs = glob(["asm-arm64/**/*.h"]),
- arch = "arm64",
- include_dir = "asm-arm64",
- system = True,
-)
-
-cc_api_headers(
- name = "libc_kernel_uapi_asm_x86_headers",
- hdrs = glob(["asm-x86/**/*.h"]),
- arch = "x86",
- include_dir = "asm-x86",
- system = True,
-)
-
-cc_api_headers(
- name = "libc_kernel_uapi_asm_x86_64_headers",
- hdrs = glob(["asm-x86_64/**/*.h"]),
- arch = "x86_64",
- include_dir = "asm-x86_64",
- system = True,
-)
diff --git a/libc/kernel/uapi/linux/ioprio.h b/libc/kernel/uapi/linux/ioprio.h
index c6dc42a..9ae9dae 100644
--- a/libc/kernel/uapi/linux/ioprio.h
+++ b/libc/kernel/uapi/linux/ioprio.h
@@ -61,6 +61,10 @@
IOPRIO_HINT_DEV_DURATION_LIMIT_7 = 7,
};
#define IOPRIO_BAD_VALUE(val,max) ((val) < 0 || (val) >= (max))
-#define IOPRIO_PRIO_VALUE(class,level) ioprio_value(class, level, IOPRIO_HINT_NONE)
-#define IOPRIO_PRIO_VALUE_HINT(class,level,hint) ioprio_value(class, level, hint)
+static __always_inline __u16 ioprio_value(int __linux_class, int level, int hint) {
+ if(IOPRIO_BAD_VALUE(__linux_class, IOPRIO_NR_CLASSES) || IOPRIO_BAD_VALUE(level, IOPRIO_NR_LEVELS) || IOPRIO_BAD_VALUE(hint, IOPRIO_NR_HINTS)) return IOPRIO_CLASS_INVALID << IOPRIO_CLASS_SHIFT;
+ return(__linux_class << IOPRIO_CLASS_SHIFT) | (hint << IOPRIO_HINT_SHIFT) | level;
+}
+#define IOPRIO_PRIO_VALUE(__linux_class,level) ioprio_value(__linux_class, level, IOPRIO_HINT_NONE)
+#define IOPRIO_PRIO_VALUE_HINT(__linux_class,level,hint) ioprio_value(__linux_class, level, hint)
#endif
diff --git a/libc/libc.map.txt b/libc/libc.map.txt
index e6ea3c2..824682b 100644
--- a/libc/libc.map.txt
+++ b/libc/libc.map.txt
@@ -1593,6 +1593,7 @@
mktime_z;
__riscv_flush_icache; # riscv64
__riscv_hwprobe; # riscv64
+ strerrorname_np;
tcgetwinsize;
tcsetwinsize;
timespec_getres;
diff --git a/libc/malloc_debug/Config.cpp b/libc/malloc_debug/Config.cpp
index be577bc..77d2f02 100644
--- a/libc/malloc_debug/Config.cpp
+++ b/libc/malloc_debug/Config.cpp
@@ -409,7 +409,8 @@
void Config::LogUsage() const {
error_log("For malloc debug option descriptions go to:");
- error_log(" https://android.googlesource.com/platform/bionic/+/master/libc/malloc_debug/README.md");
+ error_log(
+ " https://android.googlesource.com/platform/bionic/+/main/libc/malloc_debug/README.md");
}
bool Config::GetOption(const char** options_str, std::string* option, std::string* value) {
diff --git a/libc/malloc_debug/README.md b/libc/malloc_debug/README.md
index fddc4a3..37fafa7 100644
--- a/libc/malloc_debug/README.md
+++ b/libc/malloc_debug/README.md
@@ -170,7 +170,7 @@
overrides this option, and should not be used at the same time.
This option can also be used in combination with other tools such
-as [libmemunreachable](https://android.googlesource.com/platform/system/memory/libmemunreachable/+/master/README.md)
+as [libmemunreachable](https://android.googlesource.com/platform/system/memory/libmemunreachable/+/main/README.md)
to only get backtraces for sizes of allocations listed as being leaked.
### backtrace\_max\_size=ALLOCATION\_SIZE\_BYTES
@@ -183,7 +183,7 @@
overrides this option, and should not be used at the same time.
This option can also be used in combination with other tools such
-as [libmemunreachable](https://android.googlesource.com/platform/system/memory/libmemunreachable/+/master/README.md)
+as [libmemunreachable](https://android.googlesource.com/platform/system/memory/libmemunreachable/+/main/README.md)
to only get backtraces for sizes of allocations listed as being leaked.
### backtrace\_size=ALLOCATION\_SIZE\_BYTES
@@ -192,7 +192,7 @@
This option overrides the backtrace\_min\_size and the backtrace\_max\_size.
This option can also be used in combination with other tools such
-as [libmemunreachable](https://android.googlesource.com/platform/system/memory/libmemunreachable/+/master/README.md)
+as [libmemunreachable](https://android.googlesource.com/platform/system/memory/libmemunreachable/+/main/README.md)
to only get backtraces for sizes of allocations listed as being leaked.
### backtrace\_full
diff --git a/libc/malloc_debug/tests/malloc_debug_config_tests.cpp b/libc/malloc_debug/tests/malloc_debug_config_tests.cpp
index bc7af6d..a911e76 100644
--- a/libc/malloc_debug/tests/malloc_debug_config_tests.cpp
+++ b/libc/malloc_debug/tests/malloc_debug_config_tests.cpp
@@ -40,8 +40,9 @@
};
std::string usage_string(
- "6 malloc_debug For malloc debug option descriptions go to:\n"
- "6 malloc_debug https://android.googlesource.com/platform/bionic/+/master/libc/malloc_debug/README.md\n");
+ "6 malloc_debug For malloc debug option descriptions go to:\n"
+ "6 malloc_debug "
+ "https://android.googlesource.com/platform/bionic/+/main/libc/malloc_debug/README.md\n");
TEST_F(MallocDebugConfigTest, unknown_option) {
diff --git a/libc/private/bionic_errdefs.h b/libc/private/bionic_errdefs.h
new file mode 100644
index 0000000..435d49b
--- /dev/null
+++ b/libc/private/bionic_errdefs.h
@@ -0,0 +1,171 @@
+/*
+ * Copyright (C) 2023 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.
+ */
+
+/*
+ * This header is used to define error constants and names;
+ * it might be included several times.
+ */
+
+#ifndef __BIONIC_ERRDEF
+#error __BIONIC_ERRDEF not defined
+#endif
+
+__BIONIC_ERRDEF(0, "Success")
+__BIONIC_ERRDEF(EPERM, "Operation not permitted")
+__BIONIC_ERRDEF(ENOENT, "No such file or directory")
+__BIONIC_ERRDEF(ESRCH, "No such process")
+__BIONIC_ERRDEF(EINTR, "Interrupted system call")
+__BIONIC_ERRDEF(EIO, "I/O error")
+__BIONIC_ERRDEF(ENXIO, "No such device or address")
+__BIONIC_ERRDEF(E2BIG, "Argument list too long")
+__BIONIC_ERRDEF(ENOEXEC, "Exec format error")
+__BIONIC_ERRDEF(EBADF, "Bad file descriptor")
+__BIONIC_ERRDEF(ECHILD, "No child processes")
+__BIONIC_ERRDEF(EAGAIN, "Try again")
+__BIONIC_ERRDEF(ENOMEM, "Out of memory")
+__BIONIC_ERRDEF(EACCES, "Permission denied")
+__BIONIC_ERRDEF(EFAULT, "Bad address")
+__BIONIC_ERRDEF(ENOTBLK, "Block device required")
+__BIONIC_ERRDEF(EBUSY, "Device or resource busy")
+__BIONIC_ERRDEF(EEXIST, "File exists")
+__BIONIC_ERRDEF(EXDEV, "Cross-device link")
+__BIONIC_ERRDEF(ENODEV, "No such device")
+__BIONIC_ERRDEF(ENOTDIR, "Not a directory")
+__BIONIC_ERRDEF(EISDIR, "Is a directory")
+__BIONIC_ERRDEF(EINVAL, "Invalid argument")
+__BIONIC_ERRDEF(ENFILE, "File table overflow")
+__BIONIC_ERRDEF(EMFILE, "Too many open files")
+__BIONIC_ERRDEF(ENOTTY, "Inappropriate ioctl for device")
+__BIONIC_ERRDEF(ETXTBSY, "Text file busy")
+__BIONIC_ERRDEF(EFBIG, "File too large")
+__BIONIC_ERRDEF(ENOSPC, "No space left on device")
+__BIONIC_ERRDEF(ESPIPE, "Illegal seek")
+__BIONIC_ERRDEF(EROFS, "Read-only file system")
+__BIONIC_ERRDEF(EMLINK, "Too many links")
+__BIONIC_ERRDEF(EPIPE, "Broken pipe")
+__BIONIC_ERRDEF(EDOM, "Math argument out of domain of func")
+__BIONIC_ERRDEF(ERANGE, "Math result not representable")
+__BIONIC_ERRDEF(EDEADLK, "Resource deadlock would occur")
+__BIONIC_ERRDEF(ENAMETOOLONG, "File name too long")
+__BIONIC_ERRDEF(ENOLCK, "No record locks available")
+__BIONIC_ERRDEF(ENOSYS, "Function not implemented")
+__BIONIC_ERRDEF(ENOTEMPTY, "Directory not empty")
+__BIONIC_ERRDEF(ELOOP, "Too many symbolic links encountered")
+__BIONIC_ERRDEF(ENOMSG, "No message of desired type")
+__BIONIC_ERRDEF(EIDRM, "Identifier removed")
+__BIONIC_ERRDEF(ECHRNG, "Channel number out of range")
+__BIONIC_ERRDEF(EL2NSYNC, "Level 2 not synchronized")
+__BIONIC_ERRDEF(EL3HLT, "Level 3 halted")
+__BIONIC_ERRDEF(EL3RST, "Level 3 reset")
+__BIONIC_ERRDEF(ELNRNG, "Link number out of range")
+__BIONIC_ERRDEF(EUNATCH, "Protocol driver not attached")
+__BIONIC_ERRDEF(ENOCSI, "No CSI structure available")
+__BIONIC_ERRDEF(EL2HLT, "Level 2 halted")
+__BIONIC_ERRDEF(EBADE, "Invalid exchange")
+__BIONIC_ERRDEF(EBADR, "Invalid request descriptor")
+__BIONIC_ERRDEF(EXFULL, "Exchange full")
+__BIONIC_ERRDEF(ENOANO, "No anode")
+__BIONIC_ERRDEF(EBADRQC, "Invalid request code")
+__BIONIC_ERRDEF(EBADSLT, "Invalid slot")
+__BIONIC_ERRDEF(EBFONT, "Bad font file format")
+__BIONIC_ERRDEF(ENOSTR, "Device not a stream")
+__BIONIC_ERRDEF(ENODATA, "No data available")
+__BIONIC_ERRDEF(ETIME, "Timer expired")
+__BIONIC_ERRDEF(ENOSR, "Out of streams resources")
+__BIONIC_ERRDEF(ENONET, "Machine is not on the network")
+__BIONIC_ERRDEF(ENOPKG, "Package not installed")
+__BIONIC_ERRDEF(EREMOTE, "Object is remote")
+__BIONIC_ERRDEF(ENOLINK, "Link has been severed")
+__BIONIC_ERRDEF(EADV, "Advertise error")
+__BIONIC_ERRDEF(ESRMNT, "Srmount error")
+__BIONIC_ERRDEF(ECOMM, "Communication error on send")
+__BIONIC_ERRDEF(EPROTO, "Protocol error")
+__BIONIC_ERRDEF(EMULTIHOP, "Multihop attempted")
+__BIONIC_ERRDEF(EDOTDOT, "RFS specific error")
+__BIONIC_ERRDEF(EBADMSG, "Not a data message")
+__BIONIC_ERRDEF(EOVERFLOW, "Value too large for defined data type")
+__BIONIC_ERRDEF(ENOTUNIQ, "Name not unique on network")
+__BIONIC_ERRDEF(EBADFD, "File descriptor in bad state")
+__BIONIC_ERRDEF(EREMCHG, "Remote address changed")
+__BIONIC_ERRDEF(ELIBACC, "Can not access a needed shared library")
+__BIONIC_ERRDEF(ELIBBAD, "Accessing a corrupted shared library")
+__BIONIC_ERRDEF(ELIBSCN, ".lib section in a.out corrupted")
+__BIONIC_ERRDEF(ELIBMAX, "Attempting to link in too many shared libraries")
+__BIONIC_ERRDEF(ELIBEXEC, "Cannot exec a shared library directly")
+__BIONIC_ERRDEF(EILSEQ, "Illegal byte sequence")
+__BIONIC_ERRDEF(ERESTART, "Interrupted system call should be restarted")
+__BIONIC_ERRDEF(ESTRPIPE, "Streams pipe error")
+__BIONIC_ERRDEF(EUSERS, "Too many users")
+__BIONIC_ERRDEF(ENOTSOCK, "Socket operation on non-socket")
+__BIONIC_ERRDEF(EDESTADDRREQ, "Destination address required")
+__BIONIC_ERRDEF(EMSGSIZE, "Message too long")
+__BIONIC_ERRDEF(EPROTOTYPE, "Protocol wrong type for socket")
+__BIONIC_ERRDEF(ENOPROTOOPT, "Protocol not available")
+__BIONIC_ERRDEF(EPROTONOSUPPORT, "Protocol not supported")
+__BIONIC_ERRDEF(ESOCKTNOSUPPORT, "Socket type not supported")
+__BIONIC_ERRDEF(EOPNOTSUPP, "Operation not supported on transport endpoint")
+__BIONIC_ERRDEF(EPFNOSUPPORT, "Protocol family not supported")
+__BIONIC_ERRDEF(EAFNOSUPPORT, "Address family not supported by protocol")
+__BIONIC_ERRDEF(EADDRINUSE, "Address already in use")
+__BIONIC_ERRDEF(EADDRNOTAVAIL, "Cannot assign requested address")
+__BIONIC_ERRDEF(ENETDOWN, "Network is down")
+__BIONIC_ERRDEF(ENETUNREACH, "Network is unreachable")
+__BIONIC_ERRDEF(ENETRESET, "Network dropped connection because of reset")
+__BIONIC_ERRDEF(ECONNABORTED, "Software caused connection abort")
+__BIONIC_ERRDEF(ECONNRESET, "Connection reset by peer")
+__BIONIC_ERRDEF(ENOBUFS, "No buffer space available")
+__BIONIC_ERRDEF(EISCONN, "Transport endpoint is already connected")
+__BIONIC_ERRDEF(ENOTCONN, "Transport endpoint is not connected")
+__BIONIC_ERRDEF(ESHUTDOWN, "Cannot send after transport endpoint shutdown")
+__BIONIC_ERRDEF(ETOOMANYREFS, "Too many references: cannot splice")
+__BIONIC_ERRDEF(ETIMEDOUT, "Connection timed out")
+__BIONIC_ERRDEF(ECONNREFUSED, "Connection refused")
+__BIONIC_ERRDEF(EHOSTDOWN, "Host is down")
+__BIONIC_ERRDEF(EHOSTUNREACH, "No route to host")
+__BIONIC_ERRDEF(EALREADY, "Operation already in progress")
+__BIONIC_ERRDEF(EINPROGRESS, "Operation now in progress")
+__BIONIC_ERRDEF(ESTALE, "Stale NFS file handle")
+__BIONIC_ERRDEF(EUCLEAN, "Structure needs cleaning")
+__BIONIC_ERRDEF(ENOTNAM, "Not a XENIX named type file")
+__BIONIC_ERRDEF(ENAVAIL, "No XENIX semaphores available")
+__BIONIC_ERRDEF(EISNAM, "Is a named type file")
+__BIONIC_ERRDEF(EREMOTEIO, "Remote I/O error")
+__BIONIC_ERRDEF(EDQUOT, "Quota exceeded")
+__BIONIC_ERRDEF(ENOMEDIUM, "No medium found")
+__BIONIC_ERRDEF(EMEDIUMTYPE, "Wrong medium type")
+__BIONIC_ERRDEF(ECANCELED, "Operation Canceled")
+__BIONIC_ERRDEF(ENOKEY, "Required key not available")
+__BIONIC_ERRDEF(EKEYEXPIRED, "Key has expired")
+__BIONIC_ERRDEF(EKEYREVOKED, "Key has been revoked")
+__BIONIC_ERRDEF(EKEYREJECTED, "Key was rejected by service")
+__BIONIC_ERRDEF(EOWNERDEAD, "Owner died")
+__BIONIC_ERRDEF(ENOTRECOVERABLE, "State not recoverable")
+__BIONIC_ERRDEF(ERFKILL, "Operation not possible due to RF-kill")
+__BIONIC_ERRDEF(EHWPOISON, "Memory page has hardware error")
+
+#undef __BIONIC_ERRDEF
diff --git a/libc/private/bionic_sigdefs.h b/libc/private/bionic_sigdefs.h
index 44d60d9..7e1b477 100644
--- a/libc/private/bionic_sigdefs.h
+++ b/libc/private/bionic_sigdefs.h
@@ -27,8 +27,8 @@
*/
/*
- * this header is used to define signal constants and names;
- * it might be included several times
+ * This header is used to define signal constants and names;
+ * it might be included several times.
*/
#ifndef __BIONIC_SIGDEF
@@ -41,9 +41,6 @@
__BIONIC_SIGDEF(SIGILL, "Illegal instruction")
__BIONIC_SIGDEF(SIGTRAP, "Trap")
__BIONIC_SIGDEF(SIGABRT, "Aborted")
-#ifdef SIGEMT
-__BIONIC_SIGDEF(SIGEMT, "EMT")
-#endif
__BIONIC_SIGDEF(SIGFPE, "Floating point exception")
__BIONIC_SIGDEF(SIGKILL, "Killed")
__BIONIC_SIGDEF(SIGBUS, "Bus error")
@@ -67,9 +64,7 @@
__BIONIC_SIGDEF(SIGPROF, "Profiling timer expired")
__BIONIC_SIGDEF(SIGXCPU, "CPU time limit exceeded")
__BIONIC_SIGDEF(SIGXFSZ, "File size limit exceeded")
-#if defined(SIGSTKFLT)
__BIONIC_SIGDEF(SIGSTKFLT, "Stack fault")
-#endif
__BIONIC_SIGDEF(SIGSYS, "Bad system call")
#undef __BIONIC_SIGDEF
diff --git a/libc/stdio/printf_common.h b/libc/stdio/printf_common.h
index 365728b..702f8d3 100644
--- a/libc/stdio/printf_common.h
+++ b/libc/stdio/printf_common.h
@@ -786,7 +786,7 @@
//
// Returns NULL on failure.
// To find out what happened check errno for ENOMEM, EILSEQ and EINVAL.
- static wchar_t* mbsconv(char* mbsarg, int prec) {
+ static wchar_t* mbsconv(const char* mbsarg, int prec) {
mbstate_t mbs;
const char* p;
size_t insize, nchars, nconv;
diff --git a/libc/stdio/vfprintf.cpp b/libc/stdio/vfprintf.cpp
index 12cceeb..e0509aa 100644
--- a/libc/stdio/vfprintf.cpp
+++ b/libc/stdio/vfprintf.cpp
@@ -340,6 +340,7 @@
case 'd':
case 'i':
_umax = SARG();
+signed_decimal:
if ((intmax_t)_umax < 0) {
_umax = -_umax;
sign = '-';
@@ -468,7 +469,15 @@
case 'n':
__fortify_fatal("%%n not allowed on Android");
case 'm':
- cp = strerror_r(caller_errno, buf, sizeof(buf));
+ if (flags & ALT) {
+ cp = const_cast<char*>(strerrorname_np(caller_errno));
+ if (cp == nullptr) {
+ _umax = caller_errno;
+ goto signed_decimal;
+ }
+ } else {
+ cp = strerror_r(caller_errno, buf, sizeof(buf));
+ }
goto string;
case 'O':
flags |= LONGINT;
diff --git a/libc/stdio/vfwprintf.cpp b/libc/stdio/vfwprintf.cpp
index d6f6a6b..72f973c 100644
--- a/libc/stdio/vfwprintf.cpp
+++ b/libc/stdio/vfwprintf.cpp
@@ -52,6 +52,19 @@
#include "printf_common.h"
+#define print_utf8(utf8, prec) \
+ do { \
+ free(convbuf); \
+ convbuf = helpers::mbsconv(utf8, prec); \
+ if (convbuf == nullptr) { \
+ fp->_flags |= __SERR; \
+ goto error; \
+ } else { \
+ cp = convbuf; \
+ } \
+ goto string; \
+ } while (0)
+
int FUNCTION_NAME(FILE* fp, const CHAR_TYPE* fmt0, va_list ap) {
int caller_errno = errno;
int n, n2;
@@ -319,6 +332,7 @@
case 'd':
case 'i':
_umax = SARG();
+signed_decimal:
if ((intmax_t)_umax < 0) {
_umax = -_umax;
sign = '-';
@@ -447,16 +461,13 @@
case 'n':
__fortify_fatal("%%n not allowed on Android");
case 'm':
- free(convbuf);
- convbuf = helpers::mbsconv(strerror_r(caller_errno,
- reinterpret_cast<char*>(buf), sizeof(buf)), prec);
- if (convbuf == nullptr) {
- fp->_flags |= __SERR;
- goto error;
- } else {
- cp = convbuf;
+ if (flags & ALT) {
+ const char* name = strerrorname_np(caller_errno);
+ if (name) print_utf8(name, prec);
+ _umax = caller_errno;
+ goto signed_decimal;
}
- goto string;
+ print_utf8(strerror_r(caller_errno, reinterpret_cast<char*>(buf), sizeof(buf)), prec);
case 'O':
flags |= LONGINT;
__BIONIC_FALLTHROUGH;
@@ -486,14 +497,7 @@
} else {
char* mbsarg;
if ((mbsarg = GETARG(char*)) == nullptr) mbsarg = const_cast<char*>("(null)");
- free(convbuf);
- convbuf = helpers::mbsconv(mbsarg, prec);
- if (convbuf == nullptr) {
- fp->_flags |= __SERR;
- goto error;
- } else {
- cp = convbuf;
- }
+ print_utf8(mbsarg, prec);
}
string:
if (prec >= 0) {
diff --git a/libc/upstream-openbsd/lib/libc/stdio/fvwrite.c b/libc/upstream-openbsd/lib/libc/stdio/fvwrite.c
index ba58f9d..d83de88 100644
--- a/libc/upstream-openbsd/lib/libc/stdio/fvwrite.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/fvwrite.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fvwrite.c,v 1.20 2017/03/17 16:06:33 millert Exp $ */
+/* $OpenBSD: fvwrite.c,v 1.21 2023/10/06 16:41:02 millert Exp $ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -34,7 +34,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <errno.h>
#include <unistd.h>
#include "local.h"
#include "fvwrite.h"
@@ -58,10 +57,8 @@
if ((len = uio->uio_resid) == 0)
return (0);
/* make sure we can write */
- if (cantwrite(fp)) {
- errno = EBADF;
+ if (cantwrite(fp))
return (EOF);
- }
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define COPY(n) (void)memcpy(fp->_p, p, n)
diff --git a/libc/upstream-openbsd/lib/libc/stdio/wbuf.c b/libc/upstream-openbsd/lib/libc/stdio/wbuf.c
index 2d07750..edb6a50 100644
--- a/libc/upstream-openbsd/lib/libc/stdio/wbuf.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/wbuf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: wbuf.c,v 1.13 2015/08/31 02:53:57 guenther Exp $ */
+/* $OpenBSD: wbuf.c,v 1.14 2023/10/06 16:41:02 millert Exp $ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -32,7 +32,6 @@
*/
#include <stdio.h>
-#include <errno.h>
#include "local.h"
/*
@@ -54,10 +53,8 @@
* calls might wrap _w from negative to positive.
*/
fp->_w = fp->_lbfsize;
- if (cantwrite(fp)) {
- errno = EBADF;
+ if (cantwrite(fp))
return (EOF);
- }
c = (unsigned char)c;
/*
diff --git a/libc/upstream-openbsd/lib/libc/stdio/wsetup.c b/libc/upstream-openbsd/lib/libc/stdio/wsetup.c
index 0834223..842036b 100644
--- a/libc/upstream-openbsd/lib/libc/stdio/wsetup.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/wsetup.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: wsetup.c,v 1.7 2005/08/08 08:05:36 espie Exp $ */
+/* $OpenBSD: wsetup.c,v 1.8 2023/10/06 16:41:02 millert Exp $ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -31,6 +31,7 @@
* SUCH DAMAGE.
*/
+#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include "local.h"
@@ -38,7 +39,7 @@
/*
* Various output routines call wsetup to be sure it is safe to write,
* because either _flags does not include __SWR, or _buf is NULL.
- * _wsetup returns 0 if OK to write, nonzero otherwise.
+ * __swsetup returns 0 if OK to write, nonzero otherwise, setting errno.
*/
int
__swsetup(FILE *fp)
@@ -51,8 +52,11 @@
* If we are not writing, we had better be reading and writing.
*/
if ((fp->_flags & __SWR) == 0) {
- if ((fp->_flags & __SRW) == 0)
+ if ((fp->_flags & __SRW) == 0) {
+ errno = EBADF;
+ fp->_flags |= __SERR;
return (EOF);
+ }
if (fp->_flags & __SRD) {
/* clobber any ungetc data */
if (HASUB(fp))
@@ -68,8 +72,11 @@
* Make a buffer if necessary, then set _w.
*/
if (fp->_bf._base == NULL) {
- if ((fp->_flags & (__SSTR | __SALC)) == __SSTR)
+ if ((fp->_flags & (__SSTR | __SALC)) == __SSTR) {
+ errno = EINVAL;
+ fp->_flags |= __SERR;
return (EOF);
+ }
__smakebuf(fp);
}
if (fp->_flags & __SLBF) {
diff --git a/linker/linker.h b/linker/linker.h
index a803424..275182f 100644
--- a/linker/linker.h
+++ b/linker/linker.h
@@ -72,7 +72,7 @@
};
static constexpr const char* kBionicChangesUrl =
- "https://android.googlesource.com/platform/bionic/+/master/"
+ "https://android.googlesource.com/platform/bionic/+/main/"
"android-changes-for-ndk-developers.md";
soinfo* get_libdl_info(const soinfo& linker_si);
@@ -103,10 +103,6 @@
int do_dladdr(const void* addr, Dl_info* info);
-// void ___cfi_slowpath(uint64_t CallSiteTypeId, void *Ptr, void *Ret);
-// void ___cfi_slowpath_diag(uint64_t CallSiteTypeId, void *Ptr, void *DiagData, void *Ret);
-void ___cfi_fail(uint64_t CallSiteTypeId, void* Ptr, void *DiagData, void *Ret);
-
void set_application_target_sdk_version(int target);
int get_application_target_sdk_version();
diff --git a/linker/linker_soinfo.cpp b/linker/linker_soinfo.cpp
index 287e757..3e7506c 100644
--- a/linker/linker_soinfo.cpp
+++ b/linker/linker_soinfo.cpp
@@ -211,11 +211,8 @@
soinfo_do_lookup_impl<false>(name, vi, si_found_in, lookup_list);
}
-soinfo::soinfo(android_namespace_t* ns, const char* realpath,
- const struct stat* file_stat, off64_t file_offset,
- int rtld_flags) {
- memset(this, 0, sizeof(*this));
-
+soinfo::soinfo(android_namespace_t* ns, const char* realpath, const struct stat* file_stat,
+ off64_t file_offset, int rtld_flags) {
if (realpath != nullptr) {
realpath_ = realpath;
}
diff --git a/tests/android_get_device_api_level.cpp b/tests/android_get_device_api_level.cpp
index 9bd6b3a..2e51022 100644
--- a/tests/android_get_device_api_level.cpp
+++ b/tests/android_get_device_api_level.cpp
@@ -28,12 +28,12 @@
#include <gtest/gtest.h>
-#if __BIONIC__
+#if __has_include(<android/api-level.h>)
#include <android/api-level.h>
#endif
TEST(android_get_device_api_level, smoke) {
-#if __BIONIC__
+#if defined(__BIONIC__)
// This will fail if you run the tests on an old device, but who does that?
ASSERT_GE(android_get_device_api_level(), 29);
#endif
diff --git a/tests/async_safe_test.cpp b/tests/async_safe_test.cpp
index cc1b598..ffb8651 100644
--- a/tests/async_safe_test.cpp
+++ b/tests/async_safe_test.cpp
@@ -79,6 +79,18 @@
async_safe_format_buffer(buf, sizeof(buf), "a%mZ");
EXPECT_STREQ("aInvalid argumentZ", buf);
+#if __ANDROID_API_LEVEL__ >= 35
+ errno = EINVAL;
+ async_safe_format_buffer(buf, sizeof(buf), "a%#mZ");
+ EXPECT_STREQ("aEINVALZ", buf);
+#endif
+
+#if __ANDROID_API_LEVEL__ >= 35
+ errno = -1;
+ async_safe_format_buffer(buf, sizeof(buf), "a%#mZ");
+ EXPECT_STREQ("a-1Z", buf);
+#endif
+
async_safe_format_buffer(buf, sizeof(buf), "a%pb", reinterpret_cast<void*>(0xb0001234));
EXPECT_STREQ("a0xb0001234b", buf);
diff --git a/tests/cfi_test.cpp b/tests/cfi_test.cpp
index 1c45946..4b061b3 100644
--- a/tests/cfi_test.cpp
+++ b/tests/cfi_test.cpp
@@ -70,21 +70,8 @@
struct sigaction64 previous_sigtrap_;
};
-static bool KilledByCfi(int status) {
- return WIFSIGNALED(status) &&
- (WTERMSIG(status) == SIGTRAP || WTERMSIG(status) == SIGILL || WTERMSIG(status) == SIGSEGV);
-}
-
static void f() {}
-static void test_cfi_slowpath_with_alloc() {
- std::vector<void*> allocs;
- for (size_t i = 0; i < 1000; i++) {
- allocs.push_back(malloc(4096));
- __cfi_slowpath(46, allocs.back());
- }
-}
-
TEST_F(cfi_test_DeathTest, basic) {
#if defined(__BIONIC__)
void* handle;
@@ -135,12 +122,6 @@
EXPECT_EQ(get_global_address(), get_last_address());
EXPECT_EQ(c, get_count());
- // CFI check for a heap address.
- // It's possible that this allocation could wind up in the same CFI granule as
- // an unchecked library, which means the below might not crash. To force a
- // crash keep allocating up to a max until there is a crash.
- EXPECT_EXIT(test_cfi_slowpath_with_alloc(), KilledByCfi, "");
-
// Check all the addresses.
const size_t bss_size = 1024 * 1024;
static_assert(bss_size >= kLibraryAlignment * 2, "test range not big enough");
@@ -162,10 +143,6 @@
dlclose(handle);
dlclose(handle2);
-
- // CFI check for a function inside the unloaded DSO. This is always invalid and gets the process
- // killed.
- EXPECT_EXIT(__cfi_slowpath(45, reinterpret_cast<void*>(code_ptr)), KilledByCfi, "");
#endif
}
diff --git a/tests/dlext_test.cpp b/tests/dlext_test.cpp
index ea28822..3c2dcf2 100644
--- a/tests/dlext_test.cpp
+++ b/tests/dlext_test.cpp
@@ -964,10 +964,7 @@
// create memfd
int memfd = memfd_create("foobar", MFD_CLOEXEC);
- if (memfd == -1 && errno == ENOSYS) {
- return;
- }
-
+ if (memfd == -1 && errno == ENOSYS) GTEST_SKIP() << "no memfd_create() in this kernel";
ASSERT_TRUE(memfd != -1) << strerror(errno);
// Check st.f_type is TMPFS_MAGIC for memfd
diff --git a/tests/fcntl_test.cpp b/tests/fcntl_test.cpp
index f8f559b..47f3d91 100644
--- a/tests/fcntl_test.cpp
+++ b/tests/fcntl_test.cpp
@@ -320,7 +320,7 @@
}
TEST(fcntl, open_O_TMPFILE_mode) {
-#if __BIONIC__ // Our glibc is too old for O_TMPFILE.
+#if defined(__BIONIC__) // Our glibc is too old for O_TMPFILE.
TemporaryDir dir;
// Without O_EXCL, we're allowed to give this a name later.
// (This is unrelated to the O_CREAT interaction with O_EXCL.)
@@ -363,5 +363,5 @@
}
TEST_F(fcntl_DeathTest, fcntl_F_SETFD) {
- EXPECT_DEATH(fcntl(0, F_SETFD, O_NONBLOCK), "non-FD_CLOEXEC");
+ EXPECT_DEATH(fcntl(0, F_SETFD, O_NONBLOCK), "only supports FD_CLOEXEC");
}
diff --git a/tests/fdtrack_test.cpp b/tests/fdtrack_test.cpp
index ff6d8c8..5988bc4 100644
--- a/tests/fdtrack_test.cpp
+++ b/tests/fdtrack_test.cpp
@@ -235,27 +235,22 @@
FDTRACK_TEST(pidfd_open, ({
int rc = pidfd_open(getpid(), 0);
- if (rc == -1) {
- ASSERT_ERRNO(ENOSYS);
- GTEST_SKIP() << "pidfd_open not available";
- }
+ if (rc == -1 && errno == ENOSYS) GTEST_SKIP() << "no pidfd_open() in this kernel";
+ ASSERT_NE(-1, rc) << strerror(errno);
rc;
}));
FDTRACK_TEST(pidfd_getfd, ({
android_fdtrack_set_enabled(false);
int pidfd_self = pidfd_open(getpid(), 0);
- if (pidfd_self == -1) {
- ASSERT_ERRNO(ENOSYS);
- GTEST_SKIP() << "pidfd_open not available";
- }
+ if (pidfd_self == -1 && errno == ENOSYS) GTEST_SKIP() << "no pidfd_open() in this kernel";
+ ASSERT_NE(-1, pidfd_self) << strerror(errno);
+
android_fdtrack_set_enabled(true);
int rc = pidfd_getfd(pidfd_self, STDIN_FILENO, 0);
- if (rc == -1) {
- ASSERT_ERRNO(ENOSYS);
- GTEST_SKIP() << "pidfd_getfd not available";
- }
+ if (rc == -1 && errno == ENOSYS) GTEST_SKIP() << "no pidfd_getfd() in this kernel";
+ ASSERT_NE(-1, rc) << strerror(errno);
android_fdtrack_set_enabled(false);
close(pidfd_self);
diff --git a/tests/fortify_test.cpp b/tests/fortify_test.cpp
index cc3080d..12ea21b 100644
--- a/tests/fortify_test.cpp
+++ b/tests/fortify_test.cpp
@@ -29,7 +29,7 @@
#include <android-base/silent_death_test.h>
-#if __BIONIC__
+#if defined(__BIONIC__)
#define ASSERT_FORTIFY(expr) ASSERT_EXIT(expr, testing::KilledBySignal(SIGABRT), "FORTIFY")
#else
#define ASSERT_FORTIFY(expr) ASSERT_EXIT(expr, testing::KilledBySignal(SIGABRT), "")
@@ -412,9 +412,6 @@
ASSERT_FORTIFY(sprintf(buf, "%s", source_buf));
}
-#if !__has_attribute(alloc_size)
-// TODO: remove this after Clang prebuilt rebase.
-#else
TEST_F(DEATHTEST, sprintf_malloc_fortified) {
char* buf = (char *) malloc(10);
char source_buf[11];
@@ -422,7 +419,6 @@
ASSERT_FORTIFY(sprintf(buf, "%s", source_buf));
free(buf);
}
-#endif
TEST_F(DEATHTEST, sprintf2_fortified) {
char buf[5];
@@ -1014,7 +1010,7 @@
}
TEST_F(DEATHTEST, ppoll64_fortified) {
-#if __BIONIC__ // glibc doesn't have ppoll64.
+#if defined(__BIONIC__) // glibc doesn't have ppoll64.
nfds_t fd_count = atoi("2"); // suppress compiler optimizations
pollfd buf[1] = {{0, POLLIN, 0}};
// Set timeout to zero to prevent waiting in ppoll when fortify test fails.
@@ -1030,7 +1026,7 @@
}
TEST_F(DEATHTEST, open_O_TMPFILE_without_mode_fortified) {
-#if __BIONIC__ // Our glibc is too old for O_TMPFILE.
+#if defined(__BIONIC__) // Our glibc is too old for O_TMPFILE.
int flags = O_TMPFILE; // Fool the compiler.
ASSERT_FORTIFY(open("", flags));
#endif
diff --git a/tests/membarrier_test.cpp b/tests/membarrier_test.cpp
index 891488b..0cb7df4 100644
--- a/tests/membarrier_test.cpp
+++ b/tests/membarrier_test.cpp
@@ -30,7 +30,7 @@
~ScopedErrnoCleaner() { errno = 0; }
};
-bool HasMembarrier(int membarrier_cmd) {
+static bool HasMembarrier(int membarrier_cmd) {
ScopedErrnoCleaner errno_cleaner;
int supported_cmds = syscall(__NR_membarrier, MEMBARRIER_CMD_QUERY, 0);
return (supported_cmds > 0) && ((supported_cmds & membarrier_cmd) != 0);
@@ -39,11 +39,8 @@
TEST(membarrier, query) {
ScopedErrnoCleaner errno_cleaner;
int supported = syscall(__NR_membarrier, MEMBARRIER_CMD_QUERY, 0);
- if (errno == 0) {
- ASSERT_TRUE(supported >= 0);
- } else {
- ASSERT_TRUE(errno == ENOSYS && supported == -1);
- }
+ if (supported == -1 && errno == ENOSYS) GTEST_SKIP() << "no membarrier() in this kernel";
+ ASSERT_GE(supported, 0);
}
TEST(membarrier, global_barrier) {
diff --git a/tests/pidfd_test.cpp b/tests/pidfd_test.cpp
index e2e2046..c01b93f 100644
--- a/tests/pidfd_test.cpp
+++ b/tests/pidfd_test.cpp
@@ -45,10 +45,8 @@
}
unique_fd pidfd(pidfd_open(child, 0));
- if (pidfd.get() == -1) {
- ASSERT_ERRNO(ENOSYS);
- GTEST_SKIP() << "pidfd_open not available";
- }
+ if (pidfd.get() == -1 && errno == ENOSYS) GTEST_SKIP() << "no pidfd_open() in this kernel";
+ ASSERT_NE(-1, pidfd.get()) << strerror(errno);
siginfo_t siginfo;
int rc = waitid(P_PIDFD, pidfd.get(), &siginfo, WEXITED);
@@ -66,16 +64,12 @@
unique_fd r, w;
ASSERT_TRUE(android::base::Pipe(&r, &w));
unique_fd self(pidfd_open(getpid(), 0));
- if (self.get() == -1) {
- ASSERT_ERRNO(ENOSYS);
- GTEST_SKIP() << "pidfd_open not available";
- }
+ if (self.get() == -1 && errno == ENOSYS) GTEST_SKIP() << "no pidfd_open() in this kernel";
+ ASSERT_NE(-1, self.get()) << strerror(errno);
unique_fd dup(pidfd_getfd(self.get(), r.get(), 0));
- if (dup.get() == -1) {
- ASSERT_ERRNO(ENOSYS);
- GTEST_SKIP() << "pidfd_getfd not available";
- }
+ if (dup.get() == -1 && errno == ENOSYS) GTEST_SKIP() << "no pidfd_getfd() in this kernel";
+ ASSERT_NE(-1, dup.get()) << strerror(errno);
ASSERT_NE(r.get(), dup.get());
ASSERT_EQ(3, write(w.get(), "foo", 3));
@@ -88,15 +82,12 @@
TEST_F(pidfd_DeathTest, pidfd_send_signal) {
#if defined(__BIONIC__)
unique_fd self(pidfd_open(getpid(), 0));
- if (self.get() == -1) {
- ASSERT_ERRNO(ENOSYS);
- GTEST_SKIP() << "pidfd_open not available";
- }
+ if (self.get() == -1 && errno == ENOSYS) GTEST_SKIP() << "no pidfd_open() in this kernel";
+ ASSERT_NE(-1, self.get()) << strerror(errno);
- if (pidfd_send_signal(self.get(), 0, nullptr, 0) == -1) {
- ASSERT_ERRNO(ENOSYS);
- GTEST_SKIP() << "pidfd_send_signal not available";
- }
+ int rc = pidfd_send_signal(self.get(), 0, nullptr, 0);
+ if (rc == -1 && errno == ENOSYS) GTEST_SKIP() << "no pidfd_send_signal() in this kernel";
+ ASSERT_EQ(0, rc) << strerror(errno);
ASSERT_EXIT(({
// gtest will fork a child off for ASSERT_EXIT: `self` refers to the parent.
diff --git a/tests/poll_test.cpp b/tests/poll_test.cpp
index 33143f8..5799fea 100644
--- a/tests/poll_test.cpp
+++ b/tests/poll_test.cpp
@@ -49,7 +49,7 @@
}
TEST(poll, ppoll64_null_fds) {
-#if __BIONIC__
+#if defined(__BIONIC__)
// Because nanosleep(2) is relatively new to POSIX, code sometimes abuses poll.
errno = 0;
timespec ts = { .tv_nsec = 100 };
diff --git a/tests/stdio_test.cpp b/tests/stdio_test.cpp
index eed873a..5cb634c 100644
--- a/tests/stdio_test.cpp
+++ b/tests/stdio_test.cpp
@@ -2153,6 +2153,27 @@
test_fread_from_write_only_stream(64*1024);
}
+TEST(STDIO_TEST, fwrite_to_read_only_stream) {
+ FILE* fp = fopen("/proc/version", "re");
+ ASSERT_FALSE(ferror(fp));
+ ASSERT_EQ(0U, fwrite("hello", 1, 5, fp));
+ ASSERT_TRUE(ferror(fp));
+}
+
+TEST(STDIO_TEST, fputc_to_read_only_stream) {
+ FILE* fp = fopen("/proc/version", "re");
+ ASSERT_FALSE(ferror(fp));
+ ASSERT_EQ(EOF, fputc('x', fp));
+ ASSERT_TRUE(ferror(fp));
+}
+
+TEST(STDIO_TEST, fprintf_to_read_only_stream) {
+ FILE* fp = fopen("/proc/version", "re");
+ ASSERT_FALSE(ferror(fp));
+ ASSERT_EQ(-1, fprintf(fp, "%s%d", "hello", 123));
+ ASSERT_TRUE(ferror(fp));
+}
+
static void test_fwrite_after_fread(size_t n) {
TemporaryFile tf;
@@ -2523,6 +2544,24 @@
EXPECT_SWPRINTF(L"<Invalid argument>", L"<%m>");
}
+TEST(STDIO_TEST, printf_hash_m) {
+ errno = 0;
+ EXPECT_SNPRINTF("<0>", "<%#m>");
+ errno = -1;
+ EXPECT_SNPRINTF("<-1>", "<%#m>");
+ errno = EINVAL;
+ EXPECT_SNPRINTF("<EINVAL>", "<%#m>");
+}
+
+TEST(STDIO_TEST, wprintf_hash_m) {
+ errno = 0;
+ EXPECT_SWPRINTF(L"<0>", L"<%#m>");
+ errno = -1;
+ EXPECT_SWPRINTF(L"<-1>", L"<%#m>");
+ errno = EINVAL;
+ EXPECT_SWPRINTF(L"<EINVAL>", L"<%#m>");
+}
+
TEST(STDIO_TEST, printf_m_does_not_clobber_strerror) {
const char* m = strerror(-1);
ASSERT_STREQ("Unknown error -1", m);
diff --git a/tests/string_test.cpp b/tests/string_test.cpp
index 50db4fb..4cd89cc 100644
--- a/tests/string_test.cpp
+++ b/tests/string_test.cpp
@@ -1686,3 +1686,16 @@
GTEST_SKIP() << "memset_explicit not available";
#endif
}
+
+TEST(STRING_TEST, strerrorname_np) {
+#if defined(__BIONIC__)
+ ASSERT_STREQ("0", strerrorname_np(0));
+ ASSERT_STREQ("EINVAL", strerrorname_np(EINVAL));
+ ASSERT_STREQ("ENOSYS", strerrorname_np(ENOSYS));
+
+ ASSERT_EQ(nullptr, strerrorname_np(-1));
+ ASSERT_EQ(nullptr, strerrorname_np(666));
+#else
+ GTEST_SKIP() << "strerrorname_np not available";
+#endif
+}
diff --git a/tests/sys_epoll_test.cpp b/tests/sys_epoll_test.cpp
index abd928a..744f1c9 100644
--- a/tests/sys_epoll_test.cpp
+++ b/tests/sys_epoll_test.cpp
@@ -64,7 +64,7 @@
epoll_event events[1] = {};
timespec ts = {.tv_nsec = 500};
int rc = epoll_pwait2(epoll_fd, events, 1, &ts, nullptr);
- if (rc == -1 && errno == ENOSYS) GTEST_SKIP() << "no epoll_pwait2 in this kernel";
+ if (rc == -1 && errno == ENOSYS) GTEST_SKIP() << "no epoll_pwait2() in this kernel";
ASSERT_EQ(0, rc) << strerror(errno);
#else
GTEST_SKIP() << "epoll_pwait2 is only in glibc 2.35+";
@@ -94,7 +94,7 @@
sigemptyset(&ss2);
sigaddset(&ss2, SIGPIPE);
int rc = epoll_pwait2(epoll_fd, events, 1, &ts, &ss2);
- if (rc == -1 && errno == ENOSYS) GTEST_SKIP() << "no epoll_pwait2 in this kernel";
+ if (rc == -1 && errno == ENOSYS) GTEST_SKIP() << "no epoll_pwait2() in this kernel";
ASSERT_EQ(0, rc) << strerror(errno);
#else
GTEST_SKIP() << "epoll_pwait2 is only in glibc 2.35+";
@@ -112,7 +112,7 @@
sigemptyset64(&ss2);
sigaddset64(&ss2, SIGPIPE);
int rc = epoll_pwait2_64(epoll_fd, events, 1, &ts, &ss2);
- if (rc == -1 && errno == ENOSYS) GTEST_SKIP() << "no epoll_pwait2 in this kernel";
+ if (rc == -1 && errno == ENOSYS) GTEST_SKIP() << "no epoll_pwait2() in this kernel";
ASSERT_EQ(0, rc) << strerror(errno);
#else
GTEST_SKIP() << "epoll_pwait2_64 is bionic-only";
diff --git a/tests/sys_mman_test.cpp b/tests/sys_mman_test.cpp
index 9421565..e785ff4 100644
--- a/tests/sys_mman_test.cpp
+++ b/tests/sys_mman_test.cpp
@@ -279,10 +279,9 @@
// Is the MFD_CLOEXEC flag obeyed?
errno = 0;
int fd = memfd_create("doesn't matter", 0);
- if (fd == -1) {
- ASSERT_ERRNO(ENOSYS);
- GTEST_SKIP() << "no memfd_create available";
- }
+ if (fd == -1 && errno == ENOSYS) GTEST_SKIP() << "no memfd_create() in this kernel";
+ ASSERT_NE(-1, fd) << strerror(errno);
+
int f = fcntl(fd, F_GETFD);
ASSERT_NE(-1, f);
ASSERT_FALSE(f & FD_CLOEXEC);
diff --git a/tests/sys_stat_test.cpp b/tests/sys_stat_test.cpp
index b00f6e2..126f469 100644
--- a/tests/sys_stat_test.cpp
+++ b/tests/sys_stat_test.cpp
@@ -109,9 +109,7 @@
#if defined(HAVE_STATX)
struct statx sx;
int rc = statx(AT_FDCWD, "/proc/version", AT_STATX_SYNC_AS_STAT, STATX_ALL, &sx);
- if (rc == -1 && errno == ENOSYS) {
- GTEST_SKIP() << "statx returned ENOSYS";
- }
+ if (rc == -1 && errno == ENOSYS) GTEST_SKIP() << "no statx() in this kernel";
ASSERT_EQ(0, rc);
struct stat64 sb;
ASSERT_EQ(0, stat64("/proc/version", &sb));
diff --git a/tests/time_test.cpp b/tests/time_test.cpp
index 5e97c63..ca8e260 100644
--- a/tests/time_test.cpp
+++ b/tests/time_test.cpp
@@ -1269,7 +1269,7 @@
}
TEST(time, timespec_get) {
-#if __BIONIC__
+#if defined(__BIONIC__)
timespec ts = {};
ASSERT_EQ(TIME_UTC, timespec_get(&ts, TIME_UTC));
ASSERT_EQ(TIME_MONOTONIC, timespec_get(&ts, TIME_MONOTONIC));
@@ -1281,7 +1281,7 @@
}
TEST(time, timespec_get_invalid) {
-#if __BIONIC__
+#if defined(__BIONIC__)
timespec ts = {};
ASSERT_EQ(0, timespec_get(&ts, 123));
#else
@@ -1290,7 +1290,7 @@
}
TEST(time, timespec_getres) {
-#if __BIONIC__
+#if defined(__BIONIC__)
timespec ts = {};
ASSERT_EQ(TIME_UTC, timespec_getres(&ts, TIME_UTC));
ASSERT_EQ(1, ts.tv_nsec);
@@ -1301,7 +1301,7 @@
}
TEST(time, timespec_getres_invalid) {
-#if __BIONIC__
+#if defined(__BIONIC__)
timespec ts = {};
ASSERT_EQ(0, timespec_getres(&ts, 123));
#else
@@ -1315,7 +1315,7 @@
}
TEST(time, tzfree_null) {
-#if __BIONIC__
+#if defined(__BIONIC__)
tzfree(nullptr);
#else
GTEST_SKIP() << "glibc doesn't have timezone_t";
@@ -1323,7 +1323,7 @@
}
TEST(time, localtime_rz) {
-#if __BIONIC__
+#if defined(__BIONIC__)
setenv("TZ", "America/Los_Angeles", 1);
tzset();
@@ -1377,7 +1377,7 @@
}
TEST(time, mktime_z) {
-#if __BIONIC__
+#if defined(__BIONIC__)
setenv("TZ", "America/Los_Angeles", 1);
tzset();
@@ -1417,7 +1417,7 @@
}
TEST(time, tzalloc_nullptr) {
-#if __BIONIC__
+#if defined(__BIONIC__)
// tzalloc(nullptr) returns the system timezone.
timezone_t default_tz = tzalloc(nullptr);
ASSERT_NE(nullptr, default_tz);
@@ -1453,7 +1453,7 @@
}
TEST(time, tzalloc_unique_ptr) {
-#if __BIONIC__
+#if defined(__BIONIC__)
std::unique_ptr<std::remove_pointer_t<timezone_t>, decltype(&tzfree)> tz{tzalloc("Asia/Seoul"),
tzfree};
#else
diff --git a/tests/unistd_test.cpp b/tests/unistd_test.cpp
index 74bd2f4..6a94507 100644
--- a/tests/unistd_test.cpp
+++ b/tests/unistd_test.cpp
@@ -1689,16 +1689,13 @@
int fd = open("/proc/version", O_RDONLY);
ASSERT_GE(fd, 0);
- // Try to close the file descriptor (this requires a 5.9+ kernel)
- if (close_range(fd, fd, 0) == 0) {
- // we can't close it *again*
- ASSERT_EQ(close(fd), -1);
- ASSERT_ERRNO(EBADF);
- } else {
- ASSERT_ERRNO(ENOSYS);
- // since close_range() failed, we can close it normally
- ASSERT_EQ(close(fd), 0);
- }
+ int rc = close_range(fd, fd, 0);
+ if (rc == -1 && errno == ENOSYS) GTEST_SKIP() << "no close_range() in this kernel";
+ ASSERT_EQ(0, rc) << strerror(errno);
+
+ // Check the fd is actually closed.
+ ASSERT_EQ(close(fd), -1);
+ ASSERT_ERRNO(EBADF);
#endif // __GLIBC__
}
diff --git a/tests/utils.cpp b/tests/utils.cpp
index e470724..0c7c552 100644
--- a/tests/utils.cpp
+++ b/tests/utils.cpp
@@ -28,7 +28,9 @@
#include "utils.h"
+#include <string.h>
#include <syscall.h>
+
#include <string>
#include <android-base/properties.h>
@@ -72,8 +74,19 @@
#endif
void PrintTo(const Errno& e, std::ostream* os) {
- // TODO: strerrorname_np() might be more useful here, but we'd need to implement it first!
- *os << strerror(e.errno_);
+ // Prefer EINVAL or whatever, but fall back to strerror() to print
+ // "Unknown error 666" for bogus values. Not that I've ever seen one,
+ // but we shouldn't be looking at an assertion failure unless something
+ // weird has happened!
+#if defined(__BIONIC__)
+ const char* errno_name = strerrorname_np(e.errno_);
+ if (errno_name != nullptr) {
+ *os << errno_name;
+ } else
+#endif
+ {
+ *os << strerror(e.errno_);
+ }
}
bool operator==(const Errno& lhs, const Errno& rhs) {