Clean up untag_address.
We had two copies of this function, one (not quite correct) in tests/utils.h
and another in bionic/macros.h. Delete the former and have the users include
the latter.
Also, create an overload of the function that takes a uintptr_t, which will
be useful for out-of-process scenarios such as the MTE support in debuggerd.
Bug: 135772972
Change-Id: Ia3c2652c97797663146b3f05fa786afe09f7ea97
diff --git a/libc/platform/bionic/macros.h b/libc/platform/bionic/macros.h
index 28a69e6..076cff1 100644
--- a/libc/platform/bionic/macros.h
+++ b/libc/platform/bionic/macros.h
@@ -83,11 +83,15 @@
#define __BIONIC_FALLTHROUGH
#endif
-template <typename T>
-static inline T* untag_address(T* p) {
+static inline uintptr_t untag_address(uintptr_t p) {
#if defined(__aarch64__)
- return reinterpret_cast<T*>(reinterpret_cast<uintptr_t>(p) & ((1ULL << 56) - 1));
+ return p & ((1ULL << 56) - 1);
#else
return p;
#endif
}
+
+template <typename T>
+static inline T* untag_address(T* p) {
+ return reinterpret_cast<T*>(untag_address(reinterpret_cast<uintptr_t>(p)));
+}
diff --git a/tests/utils.h b/tests/utils.h
index 5014ef7..5085a7a 100644
--- a/tests/utils.h
+++ b/tests/utils.h
@@ -25,6 +25,8 @@
#include <sys/wait.h>
#include <unistd.h>
+#include <bionic/macros.h>
+
#include <atomic>
#include <string>
#include <regex>
@@ -66,14 +68,6 @@
#define SKIP_WITH_HWASAN if (running_with_hwasan()) GTEST_SKIP()
-static inline void* untag_address(void* addr) {
-#if defined(__LP64__)
- constexpr uintptr_t mask = (static_cast<uintptr_t>(1) << 56) - 1;
- addr = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(addr) & mask);
-#endif
- return addr;
-}
-
#if defined(__linux__)
#include <sys/sysmacros.h>