From 4f540e22fcec8c5b989104748305a81409a9a8b5 Mon Sep 17 00:00:00 2001 From: Philippe Antoine Date: Fri, 20 Sep 2019 13:32:08 +0200 Subject: [PATCH 1/2] perf: avoid multiple calls to read same self.PC --- manticore/native/cpu/abstractcpu.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/manticore/native/cpu/abstractcpu.py b/manticore/native/cpu/abstractcpu.py index 4e7aa060a..6b9ca1919 100644 --- a/manticore/native/cpu/abstractcpu.py +++ b/manticore/native/cpu/abstractcpu.py @@ -950,19 +950,21 @@ def execute(self): """ Decode, and execute one instruction pointed by register PC """ - if issymbolic(self.PC): + curpc = self.PC + if issymbolic(curpc): raise ConcretizeRegister(self, "PC", policy="ALL") - if not self.memory.access_ok(self.PC, "x"): - raise InvalidMemoryAccess(self.PC, "x") + if not self.memory.access_ok(curpc, "x"): + raise InvalidMemoryAccess(curpc, "x") - self._publish("will_decode_instruction", self.PC) + self._publish("will_decode_instruction", curpc) - insn = self.decode_instruction(self.PC) - self._last_pc = self.PC + insn = self.decode_instruction(curpc) + self._last_pc = curpc - self._publish("will_execute_instruction", self.PC, insn) + self._publish("will_execute_instruction", curpc, insn) # FIXME (theo) why just return here? + # hook changed PC, so we trust that there is nothing more to do if insn.address != self.PC: return From 4c082ac076294b2e3b5e6ec6a391ec08aab6105d Mon Sep 17 00:00:00 2001 From: Philippe Antoine Date: Sat, 21 Sep 2019 20:12:12 +0200 Subject: [PATCH 2/2] refresh PC value once --- manticore/native/cpu/abstractcpu.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/manticore/native/cpu/abstractcpu.py b/manticore/native/cpu/abstractcpu.py index 6b9ca1919..f041e2f01 100644 --- a/manticore/native/cpu/abstractcpu.py +++ b/manticore/native/cpu/abstractcpu.py @@ -959,9 +959,9 @@ def execute(self): self._publish("will_decode_instruction", curpc) insn = self.decode_instruction(curpc) - self._last_pc = curpc + self._last_pc = self.PC - self._publish("will_execute_instruction", curpc, insn) + self._publish("will_execute_instruction", self._last_pc, insn) # FIXME (theo) why just return here? # hook changed PC, so we trust that there is nothing more to do