diff options
author | Evgenii Stepanov <eugenis@google.com> | 2021-07-12 14:44:02 -0700 |
---|---|---|
committer | Roopesh Nataraja <roopeshr@codeaurora.org> | 2021-07-14 09:49:31 -0700 |
commit | f33a5e39d9fbefe45c96e1c86b2f7d9efe89f91b (patch) | |
tree | 00bee14753e163b7bc48535f3c52ed394027abf6 /tests/utils.h | |
parent | f30ccc297ab4b5b91fe3eb7efa9f568dccb1919c (diff) |
Make MTE tests pass with all values of MEMTAG_OPTIONS.
Do not assume that tests start with Sync MTE; check the initial setting
and change test logic as appropriate.
Bug: 192480262
CRs-Fixed: 2991521
Test: bionic-unit-tests with MEMTAG_OPTIONS=(off|sync|async)
Change-Id: Id80301e6426af16f89bd80a7a7ab127b6fd60425
(cherry picked from commit 53df1f3772ad4843461e78540111b21e9061c051)
Diffstat (limited to 'tests/utils.h')
-rw-r--r-- | tests/utils.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/tests/utils.h b/tests/utils.h index 145ba1ac2..592ac0e56 100644 --- a/tests/utils.h +++ b/tests/utils.h @@ -21,6 +21,7 @@ #include <fcntl.h> #include <inttypes.h> #include <sys/mman.h> +#include <sys/prctl.h> #include <sys/types.h> #include <sys/wait.h> #include <unistd.h> @@ -304,3 +305,13 @@ template <class Tp> static inline void DoNotOptimize(Tp& value) { asm volatile("" : "+r,m"(value) : : "memory"); } + +static inline bool running_with_mte() { +#ifdef __aarch64__ + int level = prctl(PR_GET_TAGGED_ADDR_CTRL, 0, 0, 0, 0); + return level >= 0 && (level & PR_TAGGED_ADDR_ENABLE) && + (level & PR_MTE_TCF_MASK) != PR_MTE_TCF_NONE; +#else + return false; +#endif +} |