Merge "Update bionic to use the MTE API proposed on LKML."

This commit is contained in:
Peter Collingbourne 2019-12-16 17:02:11 +00:00 committed by Gerrit Code Review
commit e5dbd3f71b
2 changed files with 23 additions and 2 deletions

View file

@ -42,6 +42,7 @@
#include <unistd.h>
#include <async_safe/log.h>
#include <platform/bionic/mte_kernel.h>
#include "private/WriteProtected.h"
#include "private/bionic_defs.h"
@ -109,8 +110,18 @@ void __libc_init_common() {
#if defined(__aarch64__)
#define PR_SET_TAGGED_ADDR_CTRL 55
#define PR_TAGGED_ADDR_ENABLE (1UL << 0)
#ifdef ANDROID_EXPERIMENTAL_MTE
// First, try enabling MTE in asynchronous mode, with tag 0 excluded. This will fail if the kernel
// or hardware doesn't support MTE, and we will fall back to just enabling tagged pointers in
// syscall arguments.
if (prctl(PR_SET_TAGGED_ADDR_CTRL,
PR_TAGGED_ADDR_ENABLE | PR_MTE_TCF_ASYNC | (1 << PR_MTE_EXCL_SHIFT), 0, 0, 0)) {
prctl(PR_SET_TAGGED_ADDR_CTRL, PR_TAGGED_ADDR_ENABLE, 0, 0, 0);
}
#else
prctl(PR_SET_TAGGED_ADDR_CTRL, PR_TAGGED_ADDR_ENABLE, 0, 0, 0);
#endif
#endif
}
void __libc_init_fork_handler() {

View file

@ -36,6 +36,16 @@
// This interface should not be considered to be stable.
#ifdef ANDROID_EXPERIMENTAL_MTE
#define HWCAP2_MTE (1UL << 31)
#define PROT_MTE 0x10
#define HWCAP2_MTE (1 << 10)
#define PROT_MTE 0x20
#define PR_MTE_TCF_SHIFT 1
#define PR_MTE_TCF_NONE (0UL << PR_MTE_TCF_SHIFT)
#define PR_MTE_TCF_SYNC (1UL << PR_MTE_TCF_SHIFT)
#define PR_MTE_TCF_ASYNC (2UL << PR_MTE_TCF_SHIFT)
#define PR_MTE_TCF_MASK (3UL << PR_MTE_TCF_SHIFT)
#define PR_MTE_EXCL_SHIFT 3
#define PR_MTE_EXCL_MASK (0xffffUL << PR_MTE_EXCL_SHIFT)
#endif