ART: Avoid obvious segfault in arm & x86 fault handler
These handlers need to read an instruction to determine where to
look for info. Don't try to read from pc=0.
Bug: 20040863
Change-Id: I38b56dc6dd806df22e608ee8d46c4091a738e4bc
diff --git a/runtime/arch/arm/fault_handler_arm.cc b/runtime/arch/arm/fault_handler_arm.cc
index 325b283..3e8b367 100644
--- a/runtime/arch/arm/fault_handler_arm.cc
+++ b/runtime/arch/arm/fault_handler_arm.cc
@@ -95,6 +95,13 @@
// Need to work out the size of the instruction that caused the exception.
uint8_t* ptr = reinterpret_cast<uint8_t*>(sc->arm_pc);
VLOG(signals) << "pc: " << std::hex << static_cast<void*>(ptr);
+
+ if (ptr == nullptr) {
+ // Somebody jumped to 0x0. Definitely not ours, and will definitely segfault below.
+ *out_method = nullptr;
+ return;
+ }
+
uint32_t instr_size = GetInstructionSize(ptr);
*out_return_pc = (sc->arm_pc + instr_size) | 1;
diff --git a/runtime/arch/x86/fault_handler_x86.cc b/runtime/arch/x86/fault_handler_x86.cc
index ad962e2..27a4adf 100644
--- a/runtime/arch/x86/fault_handler_x86.cc
+++ b/runtime/arch/x86/fault_handler_x86.cc
@@ -275,6 +275,12 @@
uint8_t* pc = reinterpret_cast<uint8_t*>(uc->CTX_EIP);
VLOG(signals) << HexDump(pc, 32, true, "PC ");
+ if (pc == nullptr) {
+ // Somebody jumped to 0x0. Definitely not ours, and will definitely segfault below.
+ *out_method = nullptr;
+ return;
+ }
+
uint32_t instr_size = GetInstructionSize(pc);
if (instr_size == 0) {
// Unknown instruction, tell caller it's not ours.