[go: nahoru, domu]

[Android Unwinder] Add support for refuse to unwind

This CL adds the support for unwind instruction
10000000 00000000.

Bug: 1240698
Change-Id: Ie8b04daf034631518c4d13ab5471f22db4983b87
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3153978
Commit-Queue: Charlie Hu <chenleihu@google.com>
Reviewed-by: Mike Wittman <wittman@chromium.org>
Cr-Commit-Position: refs/heads/main@{#921309}
diff --git a/base/profiler/chrome_unwind_table_android_unittest.cc b/base/profiler/chrome_unwind_table_android_unittest.cc
index 6d9dc02b..51538e8 100644
--- a/base/profiler/chrome_unwind_table_android_unittest.cc
+++ b/base/profiler/chrome_unwind_table_android_unittest.cc
@@ -19,7 +19,7 @@
   bool pc_was_updated = false;
   ASSERT_EQ(ExecuteUnwindInstruction(current_instruction, pc_was_updated,
                                      &thread_context),
-            UnwindInstructionResult::INSTRUCTION_PENDING);
+            UnwindInstructionResult::kInstructionPending);
   EXPECT_FALSE(pc_was_updated);
   ASSERT_EQ(current_instruction, &instruction + 1);
   EXPECT_EQ(0x10000004ul, thread_context.arm_sp);
@@ -35,7 +35,7 @@
   bool pc_was_updated = false;
   ASSERT_EQ(ExecuteUnwindInstruction(current_instruction, pc_was_updated,
                                      &thread_context),
-            UnwindInstructionResult::INSTRUCTION_PENDING);
+            UnwindInstructionResult::kInstructionPending);
   EXPECT_FALSE(pc_was_updated);
   ASSERT_EQ(current_instruction, &instruction + 1);
   EXPECT_EQ(0x10000014ul, thread_context.arm_sp);
@@ -50,7 +50,7 @@
   bool pc_was_updated = false;
   ASSERT_EQ(ExecuteUnwindInstruction(current_instruction, pc_was_updated,
                                      &thread_context),
-            UnwindInstructionResult::INSTRUCTION_PENDING);
+            UnwindInstructionResult::kInstructionPending);
   EXPECT_FALSE(pc_was_updated);
   ASSERT_EQ(current_instruction, &instruction + 1);
   EXPECT_EQ(0x10000100ul, thread_context.arm_sp);
@@ -65,7 +65,7 @@
   bool pc_was_updated = false;
   ASSERT_EQ(ExecuteUnwindInstruction(current_instruction, pc_was_updated,
                                      &thread_context),
-            UnwindInstructionResult::STACK_POINTER_OUT_OF_BOUNDS);
+            UnwindInstructionResult::kAborted);
   ASSERT_EQ(current_instruction, &instruction + 1);
   EXPECT_EQ(0xffffffff, thread_context.arm_sp);
 }
@@ -79,7 +79,7 @@
   bool pc_was_updated = false;
   ASSERT_EQ(ExecuteUnwindInstruction(current_instruction, pc_was_updated,
                                      &thread_context),
-            UnwindInstructionResult::INSTRUCTION_PENDING);
+            UnwindInstructionResult::kInstructionPending);
   EXPECT_FALSE(pc_was_updated);
   ASSERT_EQ(current_instruction, &instruction + 1);
   EXPECT_EQ(0x0ffffffcul, thread_context.arm_sp);
@@ -95,7 +95,7 @@
   bool pc_was_updated = false;
   ASSERT_EQ(ExecuteUnwindInstruction(current_instruction, pc_was_updated,
                                      &thread_context),
-            UnwindInstructionResult::INSTRUCTION_PENDING);
+            UnwindInstructionResult::kInstructionPending);
   EXPECT_FALSE(pc_was_updated);
   ASSERT_EQ(current_instruction, &instruction + 1);
   EXPECT_EQ(0x0fffffecul, thread_context.arm_sp);
@@ -110,7 +110,7 @@
   bool pc_was_updated = false;
   ASSERT_EQ(ExecuteUnwindInstruction(current_instruction, pc_was_updated,
                                      &thread_context),
-            UnwindInstructionResult::INSTRUCTION_PENDING);
+            UnwindInstructionResult::kInstructionPending);
   EXPECT_FALSE(pc_was_updated);
   ASSERT_EQ(current_instruction, &instruction + 1);
   EXPECT_EQ(0x0fffff00ul, thread_context.arm_sp);
@@ -125,7 +125,7 @@
   bool pc_was_updated = false;
   ASSERT_EQ(ExecuteUnwindInstruction(current_instruction, pc_was_updated,
                                      &thread_context),
-            UnwindInstructionResult::STACK_POINTER_OUT_OF_BOUNDS);
+            UnwindInstructionResult::kAborted);
   EXPECT_FALSE(pc_was_updated);
   ASSERT_EQ(current_instruction, &instruction + 1);
   EXPECT_EQ(0x0ul, thread_context.arm_sp);
@@ -168,7 +168,7 @@
   bool pc_was_updated = false;
   ASSERT_EQ(ExecuteUnwindInstruction(current_instruction, pc_was_updated,
                                      &thread_context),
-            UnwindInstructionResult::INSTRUCTION_PENDING);
+            UnwindInstructionResult::kInstructionPending);
   EXPECT_FALSE(pc_was_updated);
   ASSERT_EQ(current_instruction, &instruction + 1);
   EXPECT_EQ(100ul + register_index, thread_context.arm_sp);
@@ -183,7 +183,7 @@
   bool pc_was_updated = false;
   ASSERT_EQ(ExecuteUnwindInstruction(current_instruction, pc_was_updated,
                                      &thread_context),
-            UnwindInstructionResult::COMPLETED);
+            UnwindInstructionResult::kCompleted);
   ASSERT_EQ(current_instruction, &instruction + 1);
   EXPECT_EQ(114ul, thread_context.arm_pc);
 }
@@ -197,7 +197,7 @@
   bool pc_was_updated = true;
   ASSERT_EQ(ExecuteUnwindInstruction(current_instruction, pc_was_updated,
                                      &thread_context),
-            UnwindInstructionResult::COMPLETED);
+            UnwindInstructionResult::kCompleted);
   ASSERT_EQ(current_instruction, &instruction + 1);
   EXPECT_EQ(115ul, thread_context.arm_pc);
 }
@@ -233,7 +233,7 @@
   bool pc_was_updated = false;
   ASSERT_EQ(ExecuteUnwindInstruction(current_instruction, pc_was_updated,
                                      &thread_context),
-            UnwindInstructionResult::INSTRUCTION_PENDING);
+            UnwindInstructionResult::kInstructionPending);
   EXPECT_TRUE(pc_was_updated);
   ASSERT_EQ(current_instruction, instruction + 2);
   EXPECT_EQ(reinterpret_cast<uintptr_t>(&stack[0] + 4), thread_context.arm_sp);
@@ -285,7 +285,7 @@
   bool pc_was_updated = false;
   ASSERT_EQ(ExecuteUnwindInstruction(current_instruction, pc_was_updated,
                                      &thread_context),
-            UnwindInstructionResult::INSTRUCTION_PENDING);
+            UnwindInstructionResult::kInstructionPending);
   EXPECT_FALSE(pc_was_updated);
   ASSERT_EQ(current_instruction, instruction + 2);
   EXPECT_EQ(reinterpret_cast<uintptr_t>(&stack[0] + 3), thread_context.arm_sp);
@@ -336,7 +336,7 @@
   bool pc_was_updated = false;
   ASSERT_EQ(ExecuteUnwindInstruction(current_instruction, pc_was_updated,
                                      &thread_context),
-            UnwindInstructionResult::STACK_POINTER_OUT_OF_BOUNDS);
+            UnwindInstructionResult::kAborted);
   EXPECT_FALSE(pc_was_updated);
   ASSERT_EQ(current_instruction, instruction + 2);
   EXPECT_EQ(0xffffffff, thread_context.arm_sp);
@@ -358,6 +358,20 @@
   EXPECT_EQ(114ul, thread_context.arm_pc);
 }
 
+TEST(ChromeAndroidUnwindInstructionTest, TestRefuseToUnwind) {
+  RegisterContext thread_context = {};
+
+  const uint8_t instruction[] = {0b10000000, 0b0};
+  const uint8_t* current_instruction = instruction;
+
+  bool pc_was_updated = false;
+  ASSERT_EQ(ExecuteUnwindInstruction(current_instruction, pc_was_updated,
+                                     &thread_context),
+            UnwindInstructionResult::kAborted);
+  EXPECT_FALSE(pc_was_updated);
+  ASSERT_EQ(current_instruction, instruction + 2);
+}
+
 TEST(ChromeAndroidUnwindInstructionTest,
      TestPopRegistersIncludingR14MinRegisters) {
   RegisterContext thread_context = {};
@@ -387,7 +401,7 @@
   bool pc_was_updated = false;
   ASSERT_EQ(ExecuteUnwindInstruction(current_instruction, pc_was_updated,
                                      &thread_context),
-            UnwindInstructionResult::INSTRUCTION_PENDING);
+            UnwindInstructionResult::kInstructionPending);
   EXPECT_FALSE(pc_was_updated);
   ASSERT_EQ(current_instruction, &instruction + 1);
   EXPECT_EQ(reinterpret_cast<uintptr_t>(&stack[0] + 2), thread_context.arm_sp);
@@ -437,7 +451,7 @@
   bool pc_was_updated = false;
   ASSERT_EQ(ExecuteUnwindInstruction(current_instruction, pc_was_updated,
                                      &thread_context),
-            UnwindInstructionResult::INSTRUCTION_PENDING);
+            UnwindInstructionResult::kInstructionPending);
   EXPECT_FALSE(pc_was_updated);
   ASSERT_EQ(current_instruction, &instruction + 1);
   EXPECT_EQ(reinterpret_cast<uintptr_t>(&stack[0] + 6), thread_context.arm_sp);
@@ -487,7 +501,7 @@
   bool pc_was_updated = false;
   ASSERT_EQ(ExecuteUnwindInstruction(current_instruction, pc_was_updated,
                                      &thread_context),
-            UnwindInstructionResult::INSTRUCTION_PENDING);
+            UnwindInstructionResult::kInstructionPending);
   EXPECT_FALSE(pc_was_updated);
   ASSERT_EQ(current_instruction, &instruction + 1);
   EXPECT_EQ(reinterpret_cast<uintptr_t>(&stack[0] + 9), thread_context.arm_sp);
@@ -534,7 +548,7 @@
   bool pc_was_updated = false;
   ASSERT_EQ(ExecuteUnwindInstruction(current_instruction, pc_was_updated,
                                      &thread_context),
-            UnwindInstructionResult::STACK_POINTER_OUT_OF_BOUNDS);
+            UnwindInstructionResult::kAborted);
   EXPECT_FALSE(pc_was_updated);
   ASSERT_EQ(current_instruction, &instruction + 1);
   EXPECT_EQ(0xffffffff, thread_context.arm_sp);
@@ -567,7 +581,7 @@
   bool pc_was_updated = false;
   ASSERT_EQ(ExecuteUnwindInstruction(current_instruction, pc_was_updated,
                                      &thread_context),
-            UnwindInstructionResult::INSTRUCTION_PENDING);
+            UnwindInstructionResult::kInstructionPending);
   EXPECT_FALSE(pc_was_updated);
   ASSERT_EQ(current_instruction, increment_0 + sizeof(increment_0));
   // vsp + 0x204 + (0 << 2)
@@ -591,7 +605,7 @@
   bool pc_was_updated = false;
   ASSERT_EQ(ExecuteUnwindInstruction(current_instruction, pc_was_updated,
                                      &thread_context),
-            UnwindInstructionResult::INSTRUCTION_PENDING);
+            UnwindInstructionResult::kInstructionPending);
   EXPECT_FALSE(pc_was_updated);
   ASSERT_EQ(current_instruction, increment_4 + sizeof(increment_4));
   EXPECT_EQ(0x10000214ul, thread_context.arm_sp);
@@ -615,7 +629,7 @@
   bool pc_was_updated = false;
   ASSERT_EQ(ExecuteUnwindInstruction(current_instruction, pc_was_updated,
                                      &thread_context),
-            UnwindInstructionResult::INSTRUCTION_PENDING);
+            UnwindInstructionResult::kInstructionPending);
   EXPECT_FALSE(pc_was_updated);
   ASSERT_EQ(current_instruction, increment_128 + sizeof(increment_128));
   EXPECT_EQ(0x10000404ul, thread_context.arm_sp);
@@ -634,7 +648,7 @@
   bool pc_was_updated = false;
   ASSERT_EQ(ExecuteUnwindInstruction(current_instruction, pc_was_updated,
                                      &thread_context),
-            UnwindInstructionResult::STACK_POINTER_OUT_OF_BOUNDS);
+            UnwindInstructionResult::kAborted);
   EXPECT_FALSE(pc_was_updated);
   ASSERT_EQ(current_instruction,
             increment_overflow + sizeof(increment_overflow));