summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--compiler/exception_test.cc24
-rw-r--r--libartbase/base/memory_tool.h11
-rw-r--r--runtime/oat_quick_method_header.h11
3 files changed, 25 insertions, 21 deletions
diff --git a/compiler/exception_test.cc b/compiler/exception_test.cc
index 82c4998217..75ade55799 100644
--- a/compiler/exception_test.cc
+++ b/compiler/exception_test.cc
@@ -69,9 +69,10 @@ class ExceptionTest : public CommonRuntimeTest {
dex_ = my_klass_->GetDexCache()->GetDexFile();
+ std::vector<uint8_t> fake_code;
uint32_t code_size = 12;
for (size_t i = 0 ; i < code_size; i++) {
- fake_code_.push_back(0x70 | i);
+ fake_code.push_back(0x70 | i);
}
const uint32_t native_pc_offset = 4u;
@@ -96,16 +97,23 @@ class ExceptionTest : public CommonRuntimeTest {
const size_t header_size = sizeof(OatQuickMethodHeader);
const size_t code_alignment = GetInstructionSetCodeAlignment(kRuntimeISA);
- fake_header_code_and_maps_.resize(stack_maps_size + header_size + code_size + code_alignment);
- // NB: The start of the vector might not have been allocated the desired alignment.
+ fake_header_code_and_maps_size_ = stack_maps_size + header_size + code_size + code_alignment;
+ // Use mmap to make sure we get untagged memory here. Real code gets allocated using
+ // mspace_memalign which is never tagged.
+ fake_header_code_and_maps_ = static_cast<uint8_t*>(mmap(nullptr,
+ fake_header_code_and_maps_size_,
+ PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANONYMOUS,
+ -1,
+ 0));
uint8_t* code_ptr =
AlignUp(&fake_header_code_and_maps_[stack_maps_size + header_size], code_alignment);
memcpy(&fake_header_code_and_maps_[0], stack_map.data(), stack_maps_size);
- OatQuickMethodHeader method_header(code_ptr - fake_header_code_and_maps_.data());
+ OatQuickMethodHeader method_header(code_ptr - fake_header_code_and_maps_);
static_assert(std::is_trivially_copyable<OatQuickMethodHeader>::value, "Cannot use memcpy");
memcpy(code_ptr - header_size, &method_header, header_size);
- memcpy(code_ptr, fake_code_.data(), fake_code_.size());
+ memcpy(code_ptr, fake_code.data(), fake_code.size());
if (kRuntimeISA == InstructionSet::kArm) {
// Check that the Thumb2 adjustment will be a NOP, see EntryPointToCodePointer().
@@ -123,10 +131,12 @@ class ExceptionTest : public CommonRuntimeTest {
method_g_->SetEntryPointFromQuickCompiledCode(code_ptr);
}
+ void TearDown() override { munmap(fake_header_code_and_maps_, fake_header_code_and_maps_size_); }
+
const DexFile* dex_;
- std::vector<uint8_t> fake_code_;
- std::vector<uint8_t> fake_header_code_and_maps_;
+ size_t fake_header_code_and_maps_size_;
+ uint8_t* fake_header_code_and_maps_;
ArtMethod* method_f_;
ArtMethod* method_g_;
diff --git a/libartbase/base/memory_tool.h b/libartbase/base/memory_tool.h
index eba1d73635..675ceb2cfd 100644
--- a/libartbase/base/memory_tool.h
+++ b/libartbase/base/memory_tool.h
@@ -75,17 +75,6 @@ constexpr size_t kMemoryToolStackGuardSizeScale = 1;
# define ATTRIBUTE_NO_SANITIZE_HWADDRESS
#endif
-// Removes the hwasan tag from the pointer (the top eight bits).
-// Those bits are used for verification by hwasan and they are ignored by normal ARM memory ops.
-template<typename PtrType>
-static inline PtrType* HWASanUntag(PtrType* p) {
-#if __has_feature(hwaddress_sanitizer) && defined(__aarch64__)
- return reinterpret_cast<PtrType*>(reinterpret_cast<uintptr_t>(p) & ((1ULL << 56) - 1));
-#else
- return p;
-#endif
-}
-
} // namespace art
#endif // ART_LIBARTBASE_BASE_MEMORY_TOOL_H_
diff --git a/runtime/oat_quick_method_header.h b/runtime/oat_quick_method_header.h
index 769d67fb61..2b7ec01830 100644
--- a/runtime/oat_quick_method_header.h
+++ b/runtime/oat_quick_method_header.h
@@ -113,10 +113,15 @@ class PACKED(4) OatQuickMethodHeader {
}
bool Contains(uintptr_t pc) const {
+ uintptr_t code_start = reinterpret_cast<uintptr_t>(code_);
// We should not call `Contains` on a stub or trampoline.
- DCHECK_NE(data_, kInvalidData) << std::hex << reinterpret_cast<uintptr_t>(code_);
- // Remove hwasan tag to make comparison below valid. The PC from the stack does not have it.
- uintptr_t code_start = reinterpret_cast<uintptr_t>(HWASanUntag(code_));
+ DCHECK_NE(data_, kInvalidData) << std::hex << code_start;
+// Let's not make assumptions about other architectures.
+#if defined(__aarch64__) || defined(__riscv__) || defined(__riscv)
+ // Verify that the code pointer is not tagged. Memory for code gets allocated with
+ // mspace_memalign or memory mapped from a file, neither of which is tagged by MTE/HWASan.
+ DCHECK_EQ(code_start, reinterpret_cast<uintptr_t>(code_start) & ((UINT64_C(1) << 56) - 1));
+#endif
static_assert(kRuntimeISA != InstructionSet::kThumb2, "kThumb2 cannot be a runtime ISA");
if (kRuntimeISA == InstructionSet::kArm) {
// On Thumb-2, the pc is offset by one.