Merge "Remove ANDROID_EXPERIMENTAL_MTE."
diff --git a/apex/Android.bp b/apex/Android.bp
index c97eb15..8aec64a 100644
--- a/apex/Android.bp
+++ b/apex/Android.bp
@@ -60,6 +60,8 @@
],
native_static_libs: [
"libasync_safe",
+ "note_memtag_heap_async",
+ "note_memtag_heap_sync",
],
native_objects: [
"crtbegin_dynamic",
diff --git a/libc/bionic/bionic_appcompat.cpp b/libc/bionic/bionic_appcompat.cpp
index 5b31c29..dcca0da 100644
--- a/libc/bionic/bionic_appcompat.cpp
+++ b/libc/bionic/bionic_appcompat.cpp
@@ -88,4 +88,4 @@
close(file);
return 0;
-}
\ No newline at end of file
+}
diff --git a/libc/bionic/bionic_appcompat.h b/libc/bionic/bionic_appcompat.h
index 1976e0b..fd37035 100644
--- a/libc/bionic/bionic_appcompat.h
+++ b/libc/bionic/bionic_appcompat.h
@@ -41,4 +41,4 @@
int get_package_name(char* buffer, const int bufferlen);
bool should_apply_soft_mac_bind_restrictions();
-bool should_apply_soft_mac_getlink_restrictions();
\ No newline at end of file
+bool should_apply_soft_mac_getlink_restrictions();
diff --git a/libc/bionic/fts.c b/libc/bionic/fts.c
index 8888ab1..34de992 100644
--- a/libc/bionic/fts.c
+++ b/libc/bionic/fts.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fts.c,v 1.48 2014/11/20 04:14:15 guenther Exp $ */
+/* $OpenBSD: fts.c,v 1.60 2021/01/08 16:06:30 tb Exp $ */
/*-
* Copyright (c) 1990, 1993, 1994
@@ -29,10 +29,9 @@
* SUCH DAMAGE.
*/
-#include <sys/param.h>
+#include <sys/param.h> /* ALIGN */
#include <sys/stat.h>
-#include <assert.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
@@ -42,7 +41,9 @@
#include <string.h>
#include <unistd.h>
-static FTSENT *fts_alloc(FTS *, char *, size_t);
+#define MAXIMUM(a, b) (((a) > (b)) ? (a) : (b))
+
+static FTSENT *fts_alloc(FTS *, const char *, size_t);
static FTSENT *fts_build(FTS *, int);
static void fts_lfree(FTSENT *);
static void fts_load(FTS *, FTSENT *);
@@ -51,11 +52,13 @@
static int fts_palloc(FTS *, size_t);
static FTSENT *fts_sort(FTS *, FTSENT *, int);
static u_short fts_stat(FTS *, FTSENT *, int, int);
-static int fts_safe_changedir(FTS *, FTSENT *, int, char *);
+static int fts_safe_changedir(FTS *, FTSENT *, int, const char *);
+#define DEF_WEAK(s) /* nothing */
#define ALIGNBYTES (sizeof(uintptr_t) - 1)
#define ALIGN(p) (((uintptr_t)(p) + ALIGNBYTES) &~ ALIGNBYTES)
void* reallocarray(void*, size_t, size_t);
+void* recallocarray(void*, size_t, size_t, size_t);
#define ISDOT(a) (a[0] == '.' && (!a[1] || (a[1] == '.' && !a[2])))
@@ -70,12 +73,22 @@
#define BNAMES 2 /* fts_children, names only */
#define BREAD 3 /* fts_read */
-FTS* __fts_open(char* const* argv, int options, int (*compar)(const FTSENT**, const FTSENT**)) {
+FTS *
+__fts_open(char * const *argv, int options,
+ int (*compar)(const FTSENT **, const FTSENT **))
+{
FTS *sp;
FTSENT *p, *root;
int nitems;
- FTSENT *parent, *tmp;
- size_t len;
+ FTSENT *parent, *prev;
+
+ /* Android: options check moved to __fts_open() for ftw(). */
+
+ /* At least one path must be specified. */
+ if (*argv == NULL) {
+ errno = EINVAL;
+ return (NULL);
+ }
/* Allocate/initialize the stream */
if ((sp = calloc(1, sizeof(FTS))) == NULL)
@@ -91,7 +104,7 @@
* Start out with 1K of path space, and enough, in any case,
* to hold the user's paths.
*/
- if (fts_palloc(sp, MAX(fts_maxarglen(argv), PATH_MAX)))
+ if (fts_palloc(sp, MAXIMUM(fts_maxarglen(argv), PATH_MAX)))
goto mem1;
/* Allocate/initialize root's parent. */
@@ -100,21 +113,15 @@
parent->fts_level = FTS_ROOTPARENTLEVEL;
/* Allocate/initialize root(s). */
- for (root = NULL, nitems = 0; *argv; ++argv, ++nitems) {
- /* Don't allow zero-length paths. */
- if ((len = strlen(*argv)) == 0) {
- errno = ENOENT;
- goto mem3;
- }
-
- if ((p = fts_alloc(sp, *argv, len)) == NULL)
+ for (root = prev = NULL, nitems = 0; *argv; ++argv, ++nitems) {
+ if ((p = fts_alloc(sp, *argv, strlen(*argv))) == NULL)
goto mem3;
p->fts_level = FTS_ROOTLEVEL;
p->fts_parent = parent;
p->fts_accpath = p->fts_name;
p->fts_info = fts_stat(sp, p, ISSET(FTS_COMFOLLOW), -1);
- // For ftw/nftw we need to fail early: http://b/31152735
+ // Android: for ftw/nftw we need to fail early: http://b/31152735
if ((options & FTS_FOR_FTW) != 0 && p->fts_info == FTS_NS) goto mem3;
/* Command-line "." and ".." are real directories. */
@@ -131,11 +138,10 @@
} else {
p->fts_link = NULL;
if (root == NULL)
- tmp = root = p;
- else {
- tmp->fts_link = p;
- tmp = p;
- }
+ root = p;
+ else
+ prev->fts_link = p;
+ prev = p;
}
}
if (compar && nitems > 1)
@@ -158,7 +164,8 @@
* and ".." are all fairly nasty problems. Note, if we can't get the
* descriptor we run anyway, just more slowly.
*/
- if (!ISSET(FTS_NOCHDIR) && (sp->fts_rfd = open(".", O_RDONLY|O_CLOEXEC, 0)) < 0)
+ if (!ISSET(FTS_NOCHDIR) &&
+ (sp->fts_rfd = open(".", O_RDONLY | O_CLOEXEC)) == -1)
SET(FTS_NOCHDIR);
if (nitems == 0)
@@ -172,6 +179,7 @@
mem1: free(sp);
return (NULL);
}
+DEF_WEAK(fts_open);
static void
fts_load(FTS *sp, FTSENT *p)
@@ -221,7 +229,8 @@
rfd = ISSET(FTS_NOCHDIR) ? -1 : sp->fts_rfd;
/* Free up child linked list, sort array, path buffer, stream ptr.*/
- fts_lfree(sp->fts_child);
+ if (sp->fts_child)
+ fts_lfree(sp->fts_child);
free(sp->fts_array);
free(sp->fts_path);
free(sp);
@@ -237,6 +246,7 @@
return (error);
}
+DEF_WEAK(fts_close);
/*
* Special case of "/" at the end of the path so that slashes aren't
@@ -281,7 +291,8 @@
(p->fts_info == FTS_SL || p->fts_info == FTS_SLNONE)) {
p->fts_info = fts_stat(sp, p, 1, -1);
if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) {
- if ((p->fts_symfd = open(".", O_RDONLY|O_CLOEXEC, 0)) < 0) {
+ if ((p->fts_symfd =
+ open(".", O_RDONLY | O_CLOEXEC)) == -1) {
p->fts_errno = errno;
p->fts_info = FTS_ERR;
} else
@@ -370,7 +381,8 @@
if (p->fts_instr == FTS_FOLLOW) {
p->fts_info = fts_stat(sp, p, 1, -1);
if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) {
- if ((p->fts_symfd = open(".", O_RDONLY|O_CLOEXEC, 0)) < 0) {
+ if ((p->fts_symfd =
+ open(".", O_RDONLY | O_CLOEXEC)) == -1) {
p->fts_errno = errno;
p->fts_info = FTS_ERR;
} else
@@ -432,6 +444,7 @@
p->fts_info = p->fts_errno ? FTS_ERR : FTS_DP;
return (sp->fts_cur = p);
}
+DEF_WEAK(fts_read);
/*
* Fts_set takes the stream as an argument although it's not used in this
@@ -439,7 +452,6 @@
* semantics to fts using fts_set. An error return is allowed for similar
* reasons.
*/
-/* ARGSUSED */
int
fts_set(FTS *sp __unused, FTSENT *p, int instr)
{
@@ -451,6 +463,7 @@
p->fts_instr = instr;
return (0);
}
+DEF_WEAK(fts_set);
FTSENT *
fts_children(FTS *sp, int instr)
@@ -489,7 +502,8 @@
return (NULL);
/* Free up any previous child list. */
- fts_lfree(sp->fts_child);
+ if (sp->fts_child)
+ fts_lfree(sp->fts_child);
if (instr == FTS_NAMEONLY) {
SET(FTS_NAMEONLY);
@@ -508,7 +522,7 @@
ISSET(FTS_NOCHDIR))
return (sp->fts_child = fts_build(sp, instr));
- if ((fd = open(".", O_RDONLY|O_CLOEXEC, 0)) < 0)
+ if ((fd = open(".", O_RDONLY | O_CLOEXEC)) == -1)
return (NULL);
sp->fts_child = fts_build(sp, instr);
if (fchdir(fd)) {
@@ -518,6 +532,7 @@
(void)close(fd);
return (sp->fts_child);
}
+DEF_WEAK(fts_children);
/*
* This is the tricky part -- do not casually change *anything* in here. The
@@ -542,9 +557,9 @@
DIR *dirp;
void *oldaddr;
size_t len, maxlen;
- int nitems, cderrno, descend, level, nlinks, nostat = 0, doadjust;
+ int nitems, cderrno, descend, level, nlinks, nostat, doadjust;
int saved_errno;
- char *cp = NULL;
+ char *cp;
/* Set current node pointer. */
cur = sp->fts_cur;
@@ -709,8 +724,7 @@
/* Build a file name for fts_stat to stat. */
if (ISSET(FTS_NOCHDIR)) {
p->fts_accpath = p->fts_path;
- assert(cp && "cp should be non-null if FTS_NOCHDIR is set");
- memmove(cp, p->fts_name, p->fts_namelen + 1); // NOLINT
+ memmove(cp, p->fts_name, p->fts_namelen + 1);
p->fts_info = fts_stat(sp, p, 0, dirfd(dirp));
} else {
p->fts_accpath = p->fts_name;
@@ -806,9 +820,9 @@
* fail, set the errno from the stat call.
*/
if (ISSET(FTS_LOGICAL) || follow) {
- if (fstatat(dfd, path, sbp, 0) == -1) {
+ if (fstatat(dfd, path, sbp, 0)) {
saved_errno = errno;
- if (fstatat(dfd, path, sbp, AT_SYMLINK_NOFOLLOW) == 0) {
+ if (!fstatat(dfd, path, sbp, AT_SYMLINK_NOFOLLOW)) {
errno = 0;
return (FTS_SLNONE);
}
@@ -872,19 +886,19 @@
if (nitems > sp->fts_nitems) {
struct _ftsent **a;
- sp->fts_nitems = nitems + 40;
if ((a = reallocarray(sp->fts_array,
- sp->fts_nitems, sizeof(FTSENT *))) == NULL) {
+ nitems + 40, sizeof(FTSENT *))) == NULL) {
free(sp->fts_array);
sp->fts_array = NULL;
sp->fts_nitems = 0;
return (head);
}
+ sp->fts_nitems = nitems + 40;
sp->fts_array = a;
}
for (ap = sp->fts_array, p = head; p; p = p->fts_link)
*ap++ = p;
- qsort((void *)sp->fts_array, nitems, sizeof(FTSENT *), sp->fts_compar);
+ qsort(sp->fts_array, nitems, sizeof(FTSENT *), sp->fts_compar);
for (head = *(ap = sp->fts_array); --nitems; ++ap)
ap[0]->fts_link = ap[1];
ap[0]->fts_link = NULL;
@@ -892,7 +906,7 @@
}
static FTSENT *
-fts_alloc(FTS *sp, char *name, size_t namelen)
+fts_alloc(FTS *sp, const char *name, size_t namelen)
{
FTSENT *p;
size_t len;
@@ -954,13 +968,14 @@
errno = ENAMETOOLONG;
return (1);
}
- sp->fts_pathlen += more;
- p = realloc(sp->fts_path, sp->fts_pathlen);
+ p = recallocarray(sp->fts_path, sp->fts_pathlen,
+ sp->fts_pathlen + more, 1);
if (p == NULL) {
free(sp->fts_path);
sp->fts_path = NULL;
return (1);
}
+ sp->fts_pathlen += more;
sp->fts_path = p;
return (0);
}
@@ -1010,7 +1025,7 @@
* Assumes p->fts_dev and p->fts_ino are filled in.
*/
static int
-fts_safe_changedir(FTS *sp, FTSENT *p, int fd, char *path)
+fts_safe_changedir(FTS *sp, FTSENT *p, int fd, const char *path)
{
int ret, oerrno, newfd;
struct stat sb;
@@ -1018,9 +1033,9 @@
newfd = fd;
if (ISSET(FTS_NOCHDIR))
return (0);
- if (fd < 0 && (newfd = open(path, O_RDONLY|O_DIRECTORY|O_CLOEXEC, 0)) < 0)
+ if (fd == -1 && (newfd = open(path, O_RDONLY|O_DIRECTORY|O_CLOEXEC)) == -1)
return (-1);
- if (fstat(newfd, &sb)) {
+ if (fstat(newfd, &sb) == -1) {
ret = -1;
goto bail;
}
@@ -1032,17 +1047,21 @@
ret = fchdir(newfd);
bail:
oerrno = errno;
- if (fd < 0)
+ if (fd == -1)
(void)close(newfd);
errno = oerrno;
return (ret);
}
-FTS* fts_open(char* const* argv, int options, int (*compar)(const FTSENT**, const FTSENT**)) {
- // Options check.
- if ((options & ~FTS_OPTIONMASK) != 0) {
- errno = EINVAL;
- return NULL;
- }
- return __fts_open(argv, options, compar);
+FTS *
+fts_open(char * const *argv, int options,
+ int (*compar)(const FTSENT **, const FTSENT **))
+{
+ // Android needs to an __fts_open() that doesn't make this check
+ // so that FTS_FOR_FTW works.
+ if (options & ~FTS_OPTIONMASK) {
+ errno = EINVAL;
+ return (NULL);
+ }
+ return __fts_open(argv, options, compar);
}
diff --git a/libc/bionic/heap_tagging.cpp b/libc/bionic/heap_tagging.cpp
index 788722f..49b02da 100644
--- a/libc/bionic/heap_tagging.cpp
+++ b/libc/bionic/heap_tagging.cpp
@@ -127,8 +127,12 @@
case M_HEAP_TAGGING_LEVEL_ASYNC:
case M_HEAP_TAGGING_LEVEL_SYNC:
if (heap_tagging_level == M_HEAP_TAGGING_LEVEL_NONE) {
+#if !__has_feature(hwaddress_sanitizer)
+ // Suppress the error message in HWASan builds. Apps can try to enable TBI (or even MTE
+ // modes) being unaware of HWASan, fail them silently.
error_log(
"SetHeapTaggingLevel: re-enabling tagging after it was disabled is not supported");
+#endif
return false;
} else if (tag_level == M_HEAP_TAGGING_LEVEL_TBI ||
heap_tagging_level == M_HEAP_TAGGING_LEVEL_TBI) {
diff --git a/libc/bionic/recvmsg.cpp b/libc/bionic/recvmsg.cpp
index 003f43d..4d3f989 100644
--- a/libc/bionic/recvmsg.cpp
+++ b/libc/bionic/recvmsg.cpp
@@ -39,7 +39,7 @@
static inline __attribute__((artificial)) __attribute__((always_inline)) void track_fds(
struct msghdr* msg, const char* function_name) {
- if (!__android_fdtrack_hook) {
+ if (!atomic_load(&__android_fdtrack_hook)) {
return;
}
diff --git a/libc/include/android/api-level.h b/libc/include/android/api-level.h
index bcddddd..40846fb 100644
--- a/libc/include/android/api-level.h
+++ b/libc/include/android/api-level.h
@@ -151,6 +151,9 @@
/** Names the "S" API level (31), for comparison against `__ANDROID_API__`. */
#define __ANDROID_API_S__ 31
+/* This file is included in <features.h>, and might be used from .S files. */
+#if !defined(__ASSEMBLY__)
+
/**
* Returns the `targetSdkVersion` of the caller, or `__ANDROID_API_FUTURE__` if
* there is no known target SDK version (for code not running in the context of
@@ -167,7 +170,7 @@
#if __ANDROID_API__ < 29
-// android_get_device_api_level is a static inline before API level 29.
+/* android_get_device_api_level is a static inline before API level 29. */
#define __BIONIC_GET_DEVICE_API_LEVEL_INLINE static __inline
#include <bits/get_device_api_level_inlines.h>
#undef __BIONIC_GET_DEVICE_API_LEVEL_INLINE
@@ -185,6 +188,8 @@
#endif
+#endif /* defined(__ASSEMBLY__) */
+
__END_DECLS
/** @} */
diff --git a/libc/private/bionic_asm.h b/libc/private/bionic_asm.h
index 6d4f7d5..d68a2d6 100644
--- a/libc/private/bionic_asm.h
+++ b/libc/private/bionic_asm.h
@@ -26,8 +26,10 @@
* SUCH DAMAGE.
*/
-#ifndef _PRIVATE_BIONIC_ASM_H_
-#define _PRIVATE_BIONIC_ASM_H_
+#pragma once
+
+/* https://github.com/android/ndk/issues/1422 */
+#include <features.h>
#include <asm/unistd.h> /* For system call numbers. */
#define MAX_ERRNO 4095 /* For recognizing system call error returns. */
@@ -86,5 +88,3 @@
#define NOTE_GNU_PROPERTY() \
__bionic_asm_custom_note_gnu_section()
-
-#endif
diff --git a/libc/private/bionic_fdtrack.h b/libc/private/bionic_fdtrack.h
index 752dd8d..259897c 100644
--- a/libc/private/bionic_fdtrack.h
+++ b/libc/private/bionic_fdtrack.h
@@ -58,7 +58,7 @@
event.fd = __fd; \
event.type = ANDROID_FDTRACK_EVENT_TYPE_CREATE; \
event.data.create.function_name = name; \
- __android_fdtrack_hook(&event); \
+ atomic_load(&__android_fdtrack_hook)(&event); \
tls.fdtrack_disabled = false; \
} \
} \
@@ -86,7 +86,7 @@
android_fdtrack_event event; \
event.fd = __fd; \
event.type = ANDROID_FDTRACK_EVENT_TYPE_CLOSE; \
- __android_fdtrack_hook(&event); \
+ atomic_load(&__android_fdtrack_hook)(&event); \
tls.fdtrack_disabled = false; \
errno = saved_errno; \
} \
diff --git a/tools/versioner/src/Driver.cpp b/tools/versioner/src/Driver.cpp
index adf93c3..24dc5ec 100644
--- a/tools/versioner/src/Driver.cpp
+++ b/tools/versioner/src/Driver.cpp
@@ -149,7 +149,7 @@
cmd.push_back("-");
auto diags = constructDiags();
- driver::Driver driver("versioner", llvm::sys::getDefaultTargetTriple(), *diags, vfs);
+ driver::Driver driver("versioner", llvm::sys::getDefaultTargetTriple(), *diags, "versioner", vfs);
driver.setCheckInputsExist(false);
llvm::SmallVector<const char*, 32> driver_args;