diff --git a/src/icicle/src/icicle.rs b/src/icicle/src/icicle.rs index 3f0d0175..ac0e4c9c 100644 --- a/src/icicle/src/icicle.rs +++ b/src/icicle/src/icicle.rs @@ -130,7 +130,6 @@ impl icicle_vm::CodeInjector for InstructionHookInjector { } struct ExecutionHooks { - vm_ptr: *mut icicle_vm::Vm, skip_ip: Option, stop: Rc>, generic_hooks: HookContainer, @@ -139,9 +138,8 @@ struct ExecutionHooks { } impl ExecutionHooks { - pub fn new(stop_value: Rc>, vm: &mut icicle_vm::Vm) -> Self { + pub fn new(stop_value: Rc>) -> Self { Self { - vm_ptr: vm as *mut icicle_vm::Vm, skip_ip: None, stop: stop_value, generic_hooks: HookContainer::new(), @@ -173,13 +171,6 @@ impl ExecutionHooks { if self.skip_ip.is_some() { skip = self.skip_ip.unwrap() == address; self.skip_ip = None; - - // TODO: Get rid of that - unsafe { - let vm = &mut *self.vm_ptr; - vm.icount_limit = vm.icount_limit.saturating_sub(1); - vm.next_timer = vm.next_timer.saturating_sub(1); - } } if !skip { @@ -222,7 +213,7 @@ impl ExecutionHooks { pub struct IcicleEmulator { executing_thread: std::thread::ThreadId, - vm: Box, + vm: icicle_vm::Vm, reg: registers::X64RegisterNodes, syscall_hooks: HookContainer, violation_hooks: HookContainer bool>, @@ -277,9 +268,9 @@ impl icicle_cpu::mem::IoMemory for MmioHandler { impl IcicleEmulator { pub fn new() -> Self { - let mut virtual_machine = Box::new(create_x64_vm()); + let mut virtual_machine = create_x64_vm(); let stop_value = Rc::new(RefCell::new(false)); - let exec_hooks = Rc::new(RefCell::new(ExecutionHooks::new(stop_value.clone(), &mut virtual_machine))); + let exec_hooks = Rc::new(RefCell::new(ExecutionHooks::new(stop_value.clone()))); let exec_hooks_clone = Rc::clone(&exec_hooks); @@ -307,7 +298,6 @@ impl IcicleEmulator { pub fn start(&mut self, count: u64) { self.executing_thread = std::thread::current().id(); - *self.stop.borrow_mut() = false; self.vm.icount_limit = match count { 0 => u64::MAX, @@ -315,6 +305,12 @@ impl IcicleEmulator { }; loop { + self.vm.cpu.block_id = u64::MAX; + self.vm.cpu.block_offset = 0; + self.vm.cpu.pending_exception = None; + self.vm.cpu.exception.clear(); + *self.stop.borrow_mut() = false; + let reason = self.vm.run(); match reason {