From 18a41f0ae2368a83b8febafc13f53d106755fe9b Mon Sep 17 00:00:00 2001 From: Mythri Alle Date: Tue, 1 Nov 2022 12:21:29 +0000 Subject: Fix ExceptionTest to properly untag when setting up a fake stack ExceptionTest.StackTraceElement sets up a fake stack to test stack walking. When setting up this stack, the return pc is obtained from ToNativeQuickPc which returns HWAsan tagged pointers. We don't expect tagged values on stack so untag before setting it as return pc. Bug: 230392320 Test: gtest.py --gtest_filter=ExceptionTest.StackTrace (on hwasan) Change-Id: Ic4783e37b4d5d46fbe5c3817eb094a04d97fd565 --- compiler/exception_test.cc | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'compiler/exception_test.cc') diff --git a/compiler/exception_test.cc b/compiler/exception_test.cc index 9a3a2bafc9..66045223b0 100644 --- a/compiler/exception_test.cc +++ b/compiler/exception_test.cc @@ -170,7 +170,6 @@ TEST_F(ExceptionTest, FindCatchHandler) { } TEST_F(ExceptionTest, StackTraceElement) { - SKIP_WITH_HWASAN; // TODO(b/230392320): re-enable with HWASan once fixed. Thread* thread = Thread::Current(); thread->TransitionFromSuspendedToRunnable(); bool started = runtime_->Start(); @@ -197,13 +196,22 @@ TEST_F(ExceptionTest, StackTraceElement) { OatQuickMethodHeader* header = OatQuickMethodHeader::FromEntryPoint( method_g_->GetEntryPointFromQuickCompiledCode()); - fake_stack.push_back(header->ToNativeQuickPc(method_g_, kDexPc)); // return pc + // Untag native pc when running with hwasan since the pcs on the stack aren't tagged and we use + // this to create a fake stack. See OatQuickMethodHeader::Contains where we untag code pointers + // before comparing it with the PC from the stack. + uintptr_t native_pc = header->ToNativeQuickPc(method_g_, kDexPc); + if (running_with_hwasan()) { + // TODO(228989263): Use HWASanUntag once we have a hwasan target for tests too. HWASanUntag + // uses static checks which won't work if we don't have a dedicated target. + native_pc = (native_pc & ((1ULL << 56) - 1)); + } + fake_stack.push_back(native_pc); // return pc // Create/push fake 16byte stack frame for method g fake_stack.push_back(reinterpret_cast(method_g_)); fake_stack.push_back(0); fake_stack.push_back(0); - fake_stack.push_back(header->ToNativeQuickPc(method_g_, kDexPc)); // return pc + fake_stack.push_back(native_pc); // return pc. // Create/push fake 16byte stack frame for method f fake_stack.push_back(reinterpret_cast(method_f_)); -- cgit v1.2.3-59-g8ed1b