From e40e1bfb830e7854ffaf9029280f3ce9b9947ecc Mon Sep 17 00:00:00 2001 From: momo5502 Date: Sun, 6 Apr 2025 10:32:00 +0200 Subject: [PATCH] Ugly hack to *sometimes* fix instruction skipping --- src/icicle/src/icicle.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/icicle/src/icicle.rs b/src/icicle/src/icicle.rs index 3aea4d53..3f0d0175 100644 --- a/src/icicle/src/icicle.rs +++ b/src/icicle/src/icicle.rs @@ -130,6 +130,7 @@ impl icicle_vm::CodeInjector for InstructionHookInjector { } struct ExecutionHooks { + vm_ptr: *mut icicle_vm::Vm, skip_ip: Option, stop: Rc>, generic_hooks: HookContainer, @@ -138,8 +139,9 @@ struct ExecutionHooks { } impl ExecutionHooks { - pub fn new(stop_value: Rc>) -> Self { + pub fn new(stop_value: Rc>, vm: &mut icicle_vm::Vm) -> Self { Self { + vm_ptr: vm as *mut icicle_vm::Vm, skip_ip: None, stop: stop_value, generic_hooks: HookContainer::new(), @@ -171,6 +173,13 @@ 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 { @@ -213,7 +222,7 @@ impl ExecutionHooks { pub struct IcicleEmulator { executing_thread: std::thread::ThreadId, - vm: icicle_vm::Vm, + vm: Box, reg: registers::X64RegisterNodes, syscall_hooks: HookContainer, violation_hooks: HookContainer bool>, @@ -268,9 +277,9 @@ impl icicle_cpu::mem::IoMemory for MmioHandler { impl IcicleEmulator { pub fn new() -> Self { - let mut virtual_machine = create_x64_vm(); + let mut virtual_machine = Box::new(create_x64_vm()); let stop_value = Rc::new(RefCell::new(false)); - let exec_hooks = Rc::new(RefCell::new(ExecutionHooks::new(stop_value.clone()))); + let exec_hooks = Rc::new(RefCell::new(ExecutionHooks::new(stop_value.clone(), &mut virtual_machine))); let exec_hooks_clone = Rc::clone(&exec_hooks);