Merge "16kb: bionic: Re-align libtest_invalid-rw_load_segment.so to 16kb" into main
diff --git a/cpu_target_features/Android.bp b/cpu_target_features/Android.bp
new file mode 100644
index 0000000..25f37d1
--- /dev/null
+++ b/cpu_target_features/Android.bp
@@ -0,0 +1,18 @@
+package {
+ default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+cc_binary {
+ name: "cpu-target-features",
+ srcs: [
+ "main.cpp",
+ ],
+ generated_headers: ["print_target_features.inc"],
+}
+
+genrule {
+ name: "print_target_features.inc",
+ out: ["print_target_features.inc"],
+ tool_files: ["generate_printer.py"],
+ cmd: "$(location generate_printer.py) $(out)",
+}
diff --git a/cpu_target_features/generate_printer.py b/cpu_target_features/generate_printer.py
new file mode 100755
index 0000000..dc56eb5
--- /dev/null
+++ b/cpu_target_features/generate_printer.py
@@ -0,0 +1,107 @@
+#!/usr/bin/env python3
+
+"""Generate the compilation target feature printing source code.
+
+The source code for detecting target features is heavily redundant and
+copy-pasted, and is easier to maintain using a generative script.
+
+This script creates the source and the include files in its current
+directory.
+"""
+
+import argparse
+from pathlib import Path
+from typing import Dict, List, Iterable
+
+_CPP_BOILERPLATE: str = """\
+#include <stdio.h>
+
+#define TO_STRING_EXP(DEF) #DEF
+#define TO_STRING(DEF) TO_STRING_EXP(DEF)
+"""
+
+_FEATURES = {
+ "Aarch64": [
+ "__ARM_FEATURE_AES",
+ "__ARM_FEATURE_BTI",
+ "__ARM_FEATURE_CRC32",
+ "__ARM_FEATURE_CRYPTO",
+ "__ARM_FEATURE_PAC_DEFAULT",
+ "__ARM_FEATURE_SHA2",
+ "__ARM_FEATURE_SHA3",
+ "__ARM_FEATURE_SHA512",
+ ],
+ "Arm32": [
+ "__ARM_ARCH_ISA_THUMB",
+ "__ARM_FEATURE_AES",
+ "__ARM_FEATURE_BTI",
+ "__ARM_FEATURE_CRC32",
+ "__ARM_FEATURE_CRYPTO",
+ "__ARM_FEATURE_PAC_DEFAULT",
+ "__ARM_FEATURE_SHA2",
+ ],
+ "X86": [
+ "__AES__",
+ "__AVX__",
+ "__CRC32__",
+ "__POPCNT__",
+ "__SHA512__",
+ "__SHA__",
+ ],
+ "Riscv": [
+ "__riscv_vector",
+ ],
+}
+
+
+def _make_function_sig(name: str) -> str:
+ return f"void print{name}TargetFeatures()"
+
+
+def check_template(define: str) -> List[str]:
+ return [
+ f"#if defined({define})",
+ f' printf("%s=%s\\n", TO_STRING_EXP({define}), TO_STRING({define}));',
+ "#else",
+ f' printf("%s not defined\\n", TO_STRING_EXP({define}));',
+ "#endif",
+ ]
+
+
+def generate_cpp_file(define_mapping: Dict[str, List[str]]) -> List[str]:
+ out: List[str] = _CPP_BOILERPLATE.split("\n")
+ for target, defines in define_mapping.items():
+ out.append("")
+ out.extend(generate_print_function(target, defines))
+ return out
+
+
+def generate_print_function(name: str, defines: List[str]) -> List[str]:
+ """Generate a print<DEFINE>TargetFeatures function."""
+ function_body = [_make_function_sig(name) + " {"]
+ for d in defines:
+ function_body.extend(check_template(d))
+ function_body.append("}")
+ return function_body
+
+
+def parse_args() -> argparse.Namespace:
+ parser = argparse.ArgumentParser(description=__doc__)
+ parser.add_argument(
+ "cpp_in",
+ type=Path,
+ help="Output path to generate the cpp file.",
+ )
+ return parser.parse_args()
+
+
+def main() -> None:
+ args = parse_args()
+ printer_cpp_filepath = args.cpp_in
+ printer_cpp_filepath.write_text(
+ "\n".join(generate_cpp_file(_FEATURES)), encoding="utf-8"
+ )
+
+
+if __name__ == "__main__":
+ main()
diff --git a/cpu_target_features/main.cpp b/cpu_target_features/main.cpp
new file mode 100644
index 0000000..61f3d25
--- /dev/null
+++ b/cpu_target_features/main.cpp
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2024 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 <stdio.h>
+
+#include "print_target_features.inc"
+
+int main() {
+#if defined(__aarch64__)
+ printAarch64TargetFeatures();
+ return 0;
+#elif defined(__arm__)
+ printArm32TargetFeatures();
+ return 0;
+#elif defined(__x86_64__) || defined(__i386__)
+ printX86TargetFeatures();
+ return 0;
+#elif defined(__riscv)
+ printRiscvTargetFeatures();
+ return 0;
+#else
+#error Unsupported arch. This binary only supports aarch64, arm, x86, x86-64, and risc-v
+#endif
+}
diff --git a/docs/fdtrack.md b/docs/fdtrack.md
index 07c69b3..8928a5c 100644
--- a/docs/fdtrack.md
+++ b/docs/fdtrack.md
@@ -4,9 +4,11 @@
fdtrack is a file descriptor leak checker added to Android in API level 30.
-fdtrack consists of two parts: a set of hooks in bionic to register a callback
-that's invoked on file descriptor operations, and a library that implements a
-hook to perform and store backtraces for file descriptor creation.
+fdtrack consists of several parts: a set of hooks in bionic to register a
+callback that's invoked on file descriptor operations, a library that implements
+a hook to perform and store backtraces for file descriptor creation, and
+code in frameworks to automatically enable it (and deliberately crash a process
+that's leaking).
### 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/main/libc/platform/bionic/fdtrack.h)>.
@@ -21,6 +23,28 @@
[libfdtrack](https://android.googlesource.com/platform/bionic/+/refs/heads/main/libfdtrack)
implements a library that uses libunwindstack to unwind and store fd creation backtraces.
+### frameworks
+As the name implies, `spawnFdLeakCheckThread` in SystemServer spawns a thread
+to monitor the number of open file descriptors every so often.
+If that passes a certain threshold, fdtrack is enabled.
+If it passes another threshold, the process is aborted.
+These thresholds are configurable via system properties:
+```
+ // Number of open file descriptors before fdtrack starts; default 1600.
+ private static final String SYSPROP_FDTRACK_ENABLE_THRESHOLD =
+ "persist.sys.debug.fdtrack_enable_threshold";
+
+ // Number of open file descriptors before aborting; default 3000.
+ private static final String SYSPROP_FDTRACK_ABORT_THRESHOLD =
+ "persist.sys.debug.fdtrack_abort_threshold";
+
+ // Number of seconds between open fd count checks; default 120s.
+ private static final String SYSPROP_FDTRACK_INTERVAL =
+ "persist.sys.debug.fdtrack_interval";
+```
+Note that it's also possible to monitor the number of open file descriptors for
+a given process from the shell. `adb shell watch ls -l /proc/<pid>/fd` will show
+them (and you can choose your own update rate as an argument to `watch`).
#### Using libfdtrack
libfdtrack registers its hook upon being loaded, so to start capturing
diff --git a/docs/status.md b/docs/status.md
index be83148..94784de 100644
--- a/docs/status.md
+++ b/docs/status.md
@@ -61,6 +61,7 @@
New libc functions in API level 36:
* `qsort_r`, `sig2str`/`str2sig` (POSIX Issue 8 additions).
+ * GNU/BSD extension `lchmod`.
* New system call wrapper: `mseal` (`<sys/mman.h>`).
New libc functions in V (API level 35):
diff --git a/libc/Android.bp b/libc/Android.bp
index 107db88..776f101 100644
--- a/libc/Android.bp
+++ b/libc/Android.bp
@@ -913,6 +913,7 @@
"bionic/isatty.cpp",
"bionic/killpg.cpp",
"bionic/langinfo.cpp",
+ "bionic/lchmod.cpp",
"bionic/lchown.cpp",
"bionic/lfs64_support.cpp",
"bionic/libc_init_common.cpp",
@@ -1656,7 +1657,6 @@
},
apex_available: [
- "//apex_available:platform",
"com.android.runtime",
],
@@ -1686,8 +1686,7 @@
llndk: {
symbol_file: "libc.map.txt",
export_headers_as_system: true,
- export_preprocessed_headers: ["include"],
- export_llndk_headers: ["libc_llndk_headers"],
+ export_llndk_headers: ["libc_headers"],
},
}
@@ -1798,7 +1797,7 @@
}
cc_library_headers {
- name: "libc_llndk_headers",
+ name: "libc_uapi_headers",
visibility: [
"//external/musl",
],
@@ -1893,13 +1892,13 @@
target: {
android: {
export_system_include_dirs: ["include"],
- header_libs: ["libc_llndk_headers"],
- export_header_lib_headers: ["libc_llndk_headers"],
+ header_libs: ["libc_uapi_headers"],
+ export_header_lib_headers: ["libc_uapi_headers"],
},
linux_bionic: {
export_system_include_dirs: ["include"],
- header_libs: ["libc_llndk_headers"],
- export_header_lib_headers: ["libc_llndk_headers"],
+ header_libs: ["libc_uapi_headers"],
+ export_header_lib_headers: ["libc_uapi_headers"],
},
},
}
@@ -2330,17 +2329,6 @@
name: "libc",
symbol_file: "libc.map.txt",
first_version: "9",
- export_header_libs: [
- "common_libc",
- "libc_uapi",
- "libc_kernel_android_uapi_linux",
- "libc_kernel_android_scsi",
- "libc_asm_arm",
- "libc_asm_arm64",
- "libc_asm_riscv64",
- "libc_asm_x86",
- "libc_asm_x86_64",
- ],
}
ndk_library {
diff --git a/libc/bionic/lchmod.cpp b/libc/bionic/lchmod.cpp
new file mode 100644
index 0000000..928a724
--- /dev/null
+++ b/libc/bionic/lchmod.cpp
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+int lchmod(const char* path, mode_t mode) {
+ return fchmodat(AT_FDCWD, path, mode, AT_SYMLINK_NOFOLLOW);
+}
diff --git a/libc/include/bits/fortify/socket.h b/libc/include/bits/fortify/socket.h
index 02f94cc..1c3605b 100644
--- a/libc/include/bits/fortify/socket.h
+++ b/libc/include/bits/fortify/socket.h
@@ -30,8 +30,7 @@
#error "Never include this file directly; instead, include <sys/socket.h>"
#endif
-extern ssize_t __sendto_chk(int, const void* _Nonnull, size_t, size_t, int, const struct sockaddr* _Nullable,
- socklen_t) __INTRODUCED_IN(26);
+ssize_t __sendto_chk(int, const void* _Nonnull, size_t, size_t, int, const struct sockaddr* _Nullable, socklen_t) __INTRODUCED_IN(26);
ssize_t __recvfrom_chk(int, void* _Nullable, size_t, size_t, int, struct sockaddr* _Nullable, socklen_t* _Nullable);
#if defined(__BIONIC_FORTIFY)
diff --git a/libc/include/bits/fortify/string.h b/libc/include/bits/fortify/string.h
index 7df0b05..4d32b04 100644
--- a/libc/include/bits/fortify/string.h
+++ b/libc/include/bits/fortify/string.h
@@ -38,7 +38,7 @@
size_t __strlcat_chk(char* _Nonnull, const char* _Nonnull, size_t, size_t);
#if defined(__BIONIC_FORTIFY)
-extern void* _Nullable __memrchr_real(const void* _Nonnull, int, size_t) __RENAME(memrchr);
+void* _Nullable __memrchr_real(const void* _Nonnull, int, size_t) __RENAME(memrchr);
#if __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
/* No diag -- clang diagnoses misuses of this on its own. */
diff --git a/libc/include/bits/getentropy.h b/libc/include/bits/getentropy.h
index 4cd44f7..b9be4d1 100644
--- a/libc/include/bits/getentropy.h
+++ b/libc/include/bits/getentropy.h
@@ -48,6 +48,6 @@
*
* See also arc4random_buf() which is available in all API levels.
*/
-int getentropy(void* _Nonnull __buffer, size_t __buffer_size) __wur __INTRODUCED_IN(28);
+__wur int getentropy(void* _Nonnull __buffer, size_t __buffer_size) __INTRODUCED_IN(28);
__END_DECLS
diff --git a/libc/include/malloc.h b/libc/include/malloc.h
index 5904519..77b5b02 100644
--- a/libc/include/malloc.h
+++ b/libc/include/malloc.h
@@ -55,7 +55,7 @@
* other processes. Obviously this is not the case for apps, which will
* be killed in preference to killing other processes.
*/
-void* _Nullable malloc(size_t __byte_count) __mallocfunc __BIONIC_ALLOC_SIZE(1) __wur;
+__wur void* _Nullable malloc(size_t __byte_count) __mallocfunc __BIONIC_ALLOC_SIZE(1);
/**
* [calloc(3)](https://man7.org/linux/man-pages/man3/calloc.3.html) allocates
@@ -64,7 +64,7 @@
* Returns a pointer to the allocated memory on success and returns a null
* pointer and sets `errno` on failure (but see the notes for malloc()).
*/
-void* _Nullable calloc(size_t __item_count, size_t __item_size) __mallocfunc __BIONIC_ALLOC_SIZE(1,2) __wur;
+__wur void* _Nullable calloc(size_t __item_count, size_t __item_size) __mallocfunc __BIONIC_ALLOC_SIZE(1,2);
/**
* [realloc(3)](https://man7.org/linux/man-pages/man3/realloc.3.html) resizes
@@ -74,11 +74,8 @@
* memory on success and returns a null pointer and sets `errno` on failure
* (but see the notes for malloc()).
*/
-void* _Nullable realloc(void* _Nullable __ptr, size_t __byte_count) __BIONIC_ALLOC_SIZE(2) __wur;
+__wur void* _Nullable realloc(void* _Nullable __ptr, size_t __byte_count) __BIONIC_ALLOC_SIZE(2);
-// Remove the explicit guard once //external/giflib has been fixed so that it no
-// longer provides a conflicting definition: http://b/352784252
-#if __ANDROID_API__ >= 29
/**
* [reallocarray(3)](https://man7.org/linux/man-pages/man3/realloc.3.html) resizes
* allocated memory on the heap.
@@ -90,7 +87,18 @@
* memory on success and returns a null pointer and sets `errno` on failure
* (but see the notes for malloc()).
*/
-void* _Nullable reallocarray(void* _Nullable __ptr, size_t __item_count, size_t __item_size) __BIONIC_ALLOC_SIZE(2, 3) __wur __INTRODUCED_IN(29);
+#if __ANDROID_API__ >= 29
+__wur void* _Nullable reallocarray(void* _Nullable __ptr, size_t __item_count, size_t __item_size) __BIONIC_ALLOC_SIZE(2, 3) __INTRODUCED_IN(29);
+#else
+#include <errno.h>
+static __inline __wur void* _Nullable reallocarray(void* _Nullable __ptr, size_t __item_count, size_t __item_size) {
+ size_t __new_size;
+ if (__builtin_mul_overflow(__item_count, __item_size, &__new_size)) {
+ errno = ENOMEM;
+ return NULL;
+ }
+ return realloc(__ptr, __new_size);
+}
#endif
/**
@@ -108,13 +116,13 @@
*
* See also posix_memalign().
*/
-void* _Nullable memalign(size_t __alignment, size_t __byte_count) __mallocfunc __BIONIC_ALLOC_SIZE(2) __wur;
+__wur void* _Nullable memalign(size_t __alignment, size_t __byte_count) __mallocfunc __BIONIC_ALLOC_SIZE(2);
/**
* [malloc_usable_size(3)](https://man7.org/linux/man-pages/man3/malloc_usable_size.3.html)
* returns the actual size of the given heap block.
*/
-size_t malloc_usable_size(const void* _Nullable __ptr) __wur;
+__wur size_t malloc_usable_size(const void* _Nullable __ptr);
#define __MALLINFO_BODY \
/** Total number of non-mmapped bytes currently allocated from OS. */ \
diff --git a/libc/include/sys/eventfd.h b/libc/include/sys/eventfd.h
index b9d3fe9..3000737 100644
--- a/libc/include/sys/eventfd.h
+++ b/libc/include/sys/eventfd.h
@@ -35,15 +35,19 @@
#include <sys/cdefs.h>
#include <fcntl.h>
+#include <linux/eventfd.h>
__BEGIN_DECLS
-/** The eventfd() flag to provide semaphore-like semantics for reads. */
-#define EFD_SEMAPHORE (1 << 0)
-/** The eventfd() flag for a close-on-exec file descriptor. */
-#define EFD_CLOEXEC O_CLOEXEC
-/** The eventfd() flag for a non-blocking file descriptor. */
-#define EFD_NONBLOCK O_NONBLOCK
+/*! \macro EFD_SEMAPHORE
+ * The eventfd() flag to provide semaphore-like semantics for reads.
+ */
+/*! \macro EFD_CLOEXEC
+ * The eventfd() flag for a close-on-exec file descriptor.
+ */
+/*! \macro EFD_NONBLOCK
+ * The eventfd() flag for a non-blocking file descriptor.
+ */
/**
* [eventfd(2)](https://man7.org/linux/man-pages/man2/eventfd.2.html) creates a file descriptor
diff --git a/libc/include/sys/inotify.h b/libc/include/sys/inotify.h
index f070857..75ed542 100644
--- a/libc/include/sys/inotify.h
+++ b/libc/include/sys/inotify.h
@@ -33,13 +33,9 @@
#include <sys/types.h>
#include <stdint.h>
#include <linux/inotify.h>
-#include <asm/fcntl.h> /* For O_CLOEXEC and O_NONBLOCK. */
__BEGIN_DECLS
-#define IN_CLOEXEC O_CLOEXEC
-#define IN_NONBLOCK O_NONBLOCK
-
int inotify_init(void);
int inotify_init1(int __flags);
int inotify_add_watch(int __fd, const char* _Nonnull __path, uint32_t __mask);
diff --git a/libc/include/sys/random.h b/libc/include/sys/random.h
index fcea419..6aba1fc 100644
--- a/libc/include/sys/random.h
+++ b/libc/include/sys/random.h
@@ -52,6 +52,6 @@
*
* See also arc4random_buf() which is available in all API levels.
*/
-ssize_t getrandom(void* _Nonnull __buffer, size_t __buffer_size, unsigned int __flags) __wur __INTRODUCED_IN(28);
+__wur ssize_t getrandom(void* _Nonnull __buffer, size_t __buffer_size, unsigned int __flags) __INTRODUCED_IN(28);
__END_DECLS
diff --git a/libc/include/sys/stat.h b/libc/include/sys/stat.h
index 0ea596b..bb188fe 100644
--- a/libc/include/sys/stat.h
+++ b/libc/include/sys/stat.h
@@ -99,7 +99,13 @@
#endif
+/** The file information returned by fstat()/fstatat()/lstat()/stat(). */
struct stat { __STAT64_BODY };
+
+/**
+ * A synonym for `struct stat` on Android,
+ * provided for source compatibility with other systems.
+ */
struct stat64 { __STAT64_BODY };
#undef __STAT64_BODY
@@ -136,32 +142,145 @@
#define S_TYPEISSHM(__sb) 0
#define S_TYPEISTMO(__sb) 0
+/**
+ * [chmod(2)](https://man7.org/linux/man-pages/man2/chmod.2.html)
+ * changes the mode of a file given a path.
+ *
+ * Returns 0 on success and returns -1 and sets `errno` on failure.
+ */
int chmod(const char* _Nonnull __path, mode_t __mode);
+
+/**
+ * [fchmod(2)](https://man7.org/linux/man-pages/man2/fchmod.2.html)
+ * changes the mode of a file given a file descriptor.
+ *
+ * Returns 0 on success and returns -1 and sets `errno` on failure.
+ */
int fchmod(int __fd, mode_t __mode);
+
+/**
+ * [fchmodat(2)](https://man7.org/linux/man-pages/man2/fchmodat.2.html)
+ * changes the mode of a file.
+ *
+ * Returns 0 on success and returns -1 and sets `errno` on failure.
+ */
+int fchmodat(int __dir_fd, const char* _Nonnull __path, mode_t __mode, int __flags);
+
+/**
+ * [chmod(2)](https://man7.org/linux/man-pages/man2/chmod.2.html)
+ * changes the mode of a file given a path, without following symlinks.
+ *
+ * Equivalent to `fchmodat(AT_FDCWD, path, mode, AT_SYMLINK_NOFOLLOW)`.
+ *
+ * Available since API 36.
+ *
+ * Returns 0 on success and returns -1 and sets `errno` on failure.
+ */
+int lchmod(const char* _Nonnull __path, mode_t __mode) __INTRODUCED_IN(36);
+
+/**
+ * [mkdir(2)](https://man7.org/linux/man-pages/man2/mkdir.2.html)
+ * creates a directory.
+ *
+ * Returns 0 on success and returns -1 and sets `errno` on failure.
+ */
int mkdir(const char* _Nonnull __path, mode_t __mode);
+/**
+ * [mkdirat(2)](https://man7.org/linux/man-pages/man2/mkdirat.2.html)
+ * creates a directory.
+ *
+ * Returns 0 on success and returns -1 and sets `errno` on failure.
+ */
+int mkdirat(int __dir_fd, const char* _Nonnull __path, mode_t __mode);
+
+/**
+ * [fstat(2)](https://man7.org/linux/man-pages/man2/fstat.2.html)
+ * gets file status given a file descriptor.
+ *
+ * Returns 0 on success and returns -1 and sets `errno` on failure.
+ */
int fstat(int __fd, struct stat* _Nonnull __buf);
+
+/** An alias for fstat(). */
int fstat64(int __fd, struct stat64* _Nonnull __buf);
+
+/**
+ * [fstatat(2)](https://man7.org/linux/man-pages/man2/fstatat.2.html)
+ * gets file status.
+ *
+ * Returns 0 on success and returns -1 and sets `errno` on failure.
+ */
int fstatat(int __dir_fd, const char* _Nonnull __path, struct stat* _Nonnull __buf, int __flags);
+
+/** An alias for fstatat(). */
int fstatat64(int __dir_fd, const char* _Nonnull __path, struct stat64* _Nonnull __buf, int __flags);
+
+/**
+ * [lstat(2)](https://man7.org/linux/man-pages/man2/lstat.2.html)
+ * gets file status given a path, without following symlinks.
+ *
+ * Returns 0 on success and returns -1 and sets `errno` on failure.
+ */
int lstat(const char* _Nonnull __path, struct stat* _Nonnull __buf);
+
+/** An alias for lstat(). */
int lstat64(const char* _Nonnull __path, struct stat64* _Nonnull __buf);
+
+/**
+ * [stat(2)](https://man7.org/linux/man-pages/man2/stat.2.html)
+ * gets file status given a path.
+ *
+ * Returns 0 on success and returns -1 and sets `errno` on failure.
+ */
int stat(const char* _Nonnull __path, struct stat* _Nonnull __buf);
+
+/** An alias for stat(). */
int stat64(const char* _Nonnull __path, struct stat64* _Nonnull __buf);
+/**
+ * [mknod(2)](https://man7.org/linux/man-pages/man2/mknod.2.html)
+ * creates a directory, special, or regular file.
+ *
+ * Returns 0 on success and returns -1 and sets `errno` on failure.
+ */
int mknod(const char* _Nonnull __path, mode_t __mode, dev_t __dev);
+
+/**
+ * [mknodat(2)](https://man7.org/linux/man-pages/man2/mknodat.2.html)
+ * creates a directory, special, or regular file.
+ *
+ * Returns 0 on success and returns -1 and sets `errno` on failure.
+ */
+int mknodat(int __dir_fd, const char* _Nonnull __path, mode_t __mode, dev_t __dev);
+
+/**
+ * [umask(2)](https://man7.org/linux/man-pages/man2/umask.2.html)
+ * gets and sets the process-wide file mode creation mask.
+ *
+ * Returns the previous file mode creation mask.
+ */
mode_t umask(mode_t __mask);
#if defined(__BIONIC_INCLUDE_FORTIFY_HEADERS)
#include <bits/fortify/stat.h>
#endif
+/**
+ * [mkfifo(2)](https://man7.org/linux/man-pages/man2/mkfifo.2.html)
+ * creates a FIFO.
+ *
+ * Returns 0 on success and returns -1 and sets `errno` on failure.
+ */
int mkfifo(const char* _Nonnull __path, mode_t __mode);
-int mkfifoat(int __dir_fd, const char* _Nonnull __path, mode_t __mode) __INTRODUCED_IN(23);
-int fchmodat(int __dir_fd, const char* _Nonnull __path, mode_t __mode, int __flags);
-int mkdirat(int __dir_fd, const char* _Nonnull __path, mode_t __mode);
-int mknodat(int __dir_fd, const char* _Nonnull __path, mode_t __mode, dev_t __dev);
+/**
+ * [mkfifoat(2)](https://man7.org/linux/man-pages/man2/mkfifoat.2.html)
+ * creates a FIFO.
+ *
+ * Returns 0 on success and returns -1 and sets `errno` on failure.
+ */
+int mkfifoat(int __dir_fd, const char* _Nonnull __path, mode_t __mode) __INTRODUCED_IN(23);
/**
* Used in the tv_nsec field of an argument to utimensat()/futimens()
diff --git a/libc/include/sys/timerfd.h b/libc/include/sys/timerfd.h
index 96d3bef..bfa9a55 100644
--- a/libc/include/sys/timerfd.h
+++ b/libc/include/sys/timerfd.h
@@ -33,17 +33,20 @@
* @brief Timer file descriptors.
*/
-#include <fcntl.h> /* For O_CLOEXEC and O_NONBLOCK. */
+#include <fcntl.h>
+#include <linux/timerfd.h>
#include <time.h>
#include <sys/cdefs.h>
#include <sys/types.h>
__BEGIN_DECLS
-/** The timerfd_create() flag for a close-on-exec file descriptor. */
-#define TFD_CLOEXEC O_CLOEXEC
-/** The timerfd_create() flag for a non-blocking file descriptor. */
-#define TFD_NONBLOCK O_NONBLOCK
+/*! \macro TFD_CLOEXEC
+ * The timerfd_create() flag for a close-on-exec file descriptor.
+ */
+/*! \macro TFD_NONBLOCK
+ * The timerfd_create() flag for a non-blocking file descriptor.
+ */
/**
* [timerfd_create(2)](https://man7.org/linux/man-pages/man2/timerfd_create.2.html) creates a
diff --git a/libc/include/sys/vfs.h b/libc/include/sys/vfs.h
index 3579799..1a640ba 100644
--- a/libc/include/sys/vfs.h
+++ b/libc/include/sys/vfs.h
@@ -40,6 +40,8 @@
typedef __fsid_t fsid_t;
#if defined(__LP64__)
+/* We can't just use the kernel struct statfs directly here because
+ * it's reused for both struct statfs *and* struct statfs64. */
#define __STATFS64_BODY \
uint64_t f_type; \
uint64_t f_bsize; \
diff --git a/libc/libc.map.txt b/libc/libc.map.txt
index 8bb84eb..0d2e42f 100644
--- a/libc/libc.map.txt
+++ b/libc/libc.map.txt
@@ -591,6 +591,7 @@
killpg;
klogctl;
labs;
+ lchmod; # introduced=36
lchown;
lcong48; # introduced=23
ldexp;
diff --git a/libdl/Android.bp b/libdl/Android.bp
index 1bbd902..87db4b1 100644
--- a/libdl/Android.bp
+++ b/libdl/Android.bp
@@ -123,7 +123,6 @@
},
apex_available: [
- "//apex_available:platform",
"com.android.runtime",
],
}
@@ -170,7 +169,6 @@
},
apex_available: [
- "//apex_available:platform",
"com.android.runtime",
],
}
diff --git a/libm/Android.bp b/libm/Android.bp
index 9fd79f8..ee86959 100644
--- a/libm/Android.bp
+++ b/libm/Android.bp
@@ -435,7 +435,6 @@
},
apex_available: [
- "//apex_available:platform",
"com.android.runtime",
],
diff --git a/libm/upstream-freebsd/lib/msun/src/e_acosf.c b/libm/upstream-freebsd/lib/msun/src/e_acosf.c
index 42ba126..ede552e 100644
--- a/libm/upstream-freebsd/lib/msun/src/e_acosf.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_acosf.c
@@ -22,11 +22,17 @@
pio2_hi = 1.5707962513e+00; /* 0x3fc90fda */
static volatile float
pio2_lo = 7.5497894159e-08; /* 0x33a22168 */
+
+/*
+ * The coefficients for the rational approximation were generated over
+ * 0x1p-12f <= x <= 0.5f. The maximum error satisfies log2(e) < -30.084.
+ */
static const float
-pS0 = 1.6666586697e-01,
-pS1 = -4.2743422091e-02,
-pS2 = -8.6563630030e-03,
-qS1 = -7.0662963390e-01;
+pS0 = 1.66666672e-01f, /* 0x3e2aaaab */
+pS1 = -1.19510300e-01f, /* 0xbdf4c1d1 */
+pS2 = 5.47002675e-03f, /* 0x3bb33de9 */
+qS1 = -1.16706085e+00f, /* 0xbf956240 */
+qS2 = 2.90115148e-01f; /* 0x3e9489f9 */
float
acosf(float x)
@@ -46,13 +52,13 @@
if(ix<=0x32800000) return pio2_hi+pio2_lo;/*if|x|<2**-26*/
z = x*x;
p = z*(pS0+z*(pS1+z*pS2));
- q = one+z*qS1;
+ q = one+z*(qS1+z*qS2);
r = p/q;
return pio2_hi - (x - (pio2_lo-x*r));
} else if (hx<0) { /* x < -0.5 */
z = (one+x)*(float)0.5;
p = z*(pS0+z*(pS1+z*pS2));
- q = one+z*qS1;
+ q = one+z*(qS1+z*qS2);
s = sqrtf(z);
r = p/q;
w = r*s-pio2_lo;
@@ -66,7 +72,7 @@
SET_FLOAT_WORD(df,idf&0xfffff000);
c = (z-df*df)/(s+df);
p = z*(pS0+z*(pS1+z*pS2));
- q = one+z*qS1;
+ q = one+z*(qS1+z*qS2);
r = p/q;
w = r*s+c;
return (float)2.0*(df+w);
diff --git a/libm/upstream-freebsd/lib/msun/src/e_asinf.c b/libm/upstream-freebsd/lib/msun/src/e_asinf.c
index a2ee1a1..8d1aca2 100644
--- a/libm/upstream-freebsd/lib/msun/src/e_asinf.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_asinf.c
@@ -18,12 +18,18 @@
static const float
one = 1.0000000000e+00, /* 0x3F800000 */
-huge = 1.000e+30,
- /* coefficient for R(x^2) */
-pS0 = 1.6666586697e-01,
-pS1 = -4.2743422091e-02,
-pS2 = -8.6563630030e-03,
-qS1 = -7.0662963390e-01;
+huge = 1.000e+30;
+
+/*
+ * The coefficients for the rational approximation were generated over
+ * 0x1p-12f <= x <= 0.5f. The maximum error satisfies log2(e) < -30.084.
+ */
+static const float
+pS0 = 1.66666672e-01f, /* 0x3e2aaaab */
+pS1 = -1.19510300e-01f, /* 0xbdf4c1d1 */
+pS2 = 5.47002675e-03f, /* 0x3bb33de9 */
+qS1 = -1.16706085e+00f, /* 0xbf956240 */
+qS2 = 2.90115148e-01f; /* 0x3e9489f9 */
static const double
pio2 = 1.570796326794896558e+00;
@@ -46,7 +52,7 @@
}
t = x*x;
p = t*(pS0+t*(pS1+t*pS2));
- q = one+t*qS1;
+ q = one+t*(qS1+t*qS2);
w = p/q;
return x+x*w;
}
@@ -54,7 +60,7 @@
w = one-fabsf(x);
t = w*(float)0.5;
p = t*(pS0+t*(pS1+t*pS2));
- q = one+t*qS1;
+ q = one+t*(qS1+t*qS2);
s = sqrt(t);
w = p/q;
t = pio2-2.0*(s+s*w);
diff --git a/libm/upstream-freebsd/lib/msun/src/math_private.h b/libm/upstream-freebsd/lib/msun/src/math_private.h
index f3f7985..1595f90 100644
--- a/libm/upstream-freebsd/lib/msun/src/math_private.h
+++ b/libm/upstream-freebsd/lib/msun/src/math_private.h
@@ -405,7 +405,7 @@
* any extra precision into the type of 'a' -- 'a' should have type float_t,
* double_t or long double. b's type should be no larger than 'a's type.
* Callers should use these types with scopes as large as possible, to
- * reduce their own extra-precision and efficiciency problems. In
+ * reduce their own extra-precision and efficiency problems. In
* particular, they shouldn't convert back and forth just to call here.
*/
#ifdef DEBUG
diff --git a/libm/upstream-freebsd/lib/msun/src/s_fma.c b/libm/upstream-freebsd/lib/msun/src/s_fma.c
index 6c889a6..23a8449 100644
--- a/libm/upstream-freebsd/lib/msun/src/s_fma.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_fma.c
@@ -260,14 +260,14 @@
spread = ex + ey;
- if (r.hi == 0.0) {
+ if (r.hi == 0.0 && xy.lo == 0) {
/*
* When the addends cancel to 0, ensure that the result has
* the correct sign.
*/
fesetround(oround);
volatile double vzs = zs; /* XXX gcc CSE bug workaround */
- return (xy.hi + vzs + ldexp(xy.lo, spread));
+ return (xy.hi + vzs);
}
if (oround != FE_TONEAREST) {
diff --git a/libm/upstream-freebsd/lib/msun/src/s_fmal.c b/libm/upstream-freebsd/lib/msun/src/s_fmal.c
index 80c835d..2fca206 100644
--- a/libm/upstream-freebsd/lib/msun/src/s_fmal.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_fmal.c
@@ -241,14 +241,14 @@
spread = ex + ey;
- if (r.hi == 0.0) {
+ if (r.hi == 0.0 && xy.lo == 0) {
/*
* When the addends cancel to 0, ensure that the result has
* the correct sign.
*/
fesetround(oround);
volatile long double vzs = zs; /* XXX gcc CSE bug workaround */
- return (xy.hi + vzs + ldexpl(xy.lo, spread));
+ return (xy.hi + vzs);
}
if (oround != FE_TONEAREST) {
diff --git a/tests/sys_ptrace_test.cpp b/tests/sys_ptrace_test.cpp
index 93daac3..499adbb 100644
--- a/tests/sys_ptrace_test.cpp
+++ b/tests/sys_ptrace_test.cpp
@@ -41,11 +41,6 @@
using android::base::unique_fd;
-// Host libc does not define this.
-#ifndef TRAP_HWBKPT
-#define TRAP_HWBKPT 4
-#endif
-
class ChildGuard {
public:
explicit ChildGuard(pid_t pid) : pid(pid) {}
diff --git a/tests/sys_stat_test.cpp b/tests/sys_stat_test.cpp
index 126f469..50c50df 100644
--- a/tests/sys_stat_test.cpp
+++ b/tests/sys_stat_test.cpp
@@ -151,12 +151,12 @@
ASSERT_ERRNO(EINVAL);
}
-TEST(sys_stat, fchmodat_nonexistant_file) {
+TEST(sys_stat, fchmodat_nonexistent_file) {
ASSERT_EQ(-1, fchmodat(AT_FDCWD, "/blah", 0751, 0));
ASSERT_ERRNO(ENOENT);
}
-TEST(sys_stat, fchmodat_AT_SYMLINK_NOFOLLOW_nonexistant_file) {
+TEST(sys_stat, fchmodat_AT_SYMLINK_NOFOLLOW_nonexistent_file) {
ASSERT_EQ(-1, fchmodat(AT_FDCWD, "/blah", 0751, AT_SYMLINK_NOFOLLOW));
#if defined(__BIONIC__)
ASSERT_ERRNO(ENOENT);
@@ -305,7 +305,7 @@
ASSERT_EQ(0, faccessat(AT_FDCWD, "/dev/null", R_OK|W_OK, 0));
}
-TEST(sys_stat, faccessat_nonexistant) {
+TEST(sys_stat, faccessat_nonexistent) {
ASSERT_EQ(-1, faccessat(AT_FDCWD, "/blah", F_OK, AT_SYMLINK_NOFOLLOW));
#if defined(__BIONIC__)
// Android doesn't support AT_SYMLINK_NOFOLLOW
@@ -314,3 +314,26 @@
ASSERT_ERRNO(ENOENT);
#endif
}
+
+TEST(sys_stat, lchmod) {
+ TemporaryFile tf;
+ struct stat tf_sb;
+ ASSERT_EQ(0, stat(tf.path, &tf_sb));
+
+ char linkname[255];
+ snprintf(linkname, sizeof(linkname), "%s.link", tf.path);
+
+ ASSERT_EQ(0, symlink(tf.path, linkname));
+ int result = lchmod(linkname, 0751);
+ // Whether or not chmod is allowed on a symlink depends on the kernel.
+ if (result == 0) {
+ AssertSymlinkModeEquals(0751, linkname);
+ } else {
+ ASSERT_EQ(-1, result);
+ ASSERT_ERRNO(ENOTSUP);
+ }
+
+ // The target file mode shouldn't be modified.
+ AssertFileModeEquals(tf_sb.st_mode, tf.path);
+ unlink(linkname);
+}