diff --git a/libafl_qemu/src/cmplog.rs b/libafl_qemu/src/cmplog.rs index 07499eab8d..7651356ed1 100644 --- a/libafl_qemu/src/cmplog.rs +++ b/libafl_qemu/src/cmplog.rs @@ -246,7 +246,7 @@ impl QemuCmpLogRoutinesHelper { } } - let emu = Emulator::new_empty(); + let emu = Emulator::get().unwrap(); let a0: GuestAddr = emu .read_function_argument(CallingConvention::Cdecl, 0) diff --git a/libafl_qemu/src/emu.rs b/libafl_qemu/src/emu.rs index c97fc9eaaf..439a2b42ce 100644 --- a/libafl_qemu/src/emu.rs +++ b/libafl_qemu/src/emu.rs @@ -508,7 +508,7 @@ pub trait ArchExtras { impl CPU { #[must_use] pub fn emulator(&self) -> Emulator { - Emulator::new_empty() + unsafe { Emulator::new_empty() } } #[must_use] @@ -997,8 +997,14 @@ impl Emulator { } } + /// Get an empty emulator. + /// + /// # Safety + /// + /// Should not be used if `Emulator::new` has never been used before (otherwise QEMU will not be initialized). + /// Prefer `Emulator::get` for a safe version of this method. #[must_use] - pub fn new_empty() -> Emulator { + unsafe fn new_empty() -> Emulator { Emulator { _private: () } } diff --git a/libafl_qemu/src/executor.rs b/libafl_qemu/src/executor.rs index a5cfc0544e..77418354cc 100644 --- a/libafl_qemu/src/executor.rs +++ b/libafl_qemu/src/executor.rs @@ -212,7 +212,7 @@ where mgr: &mut EM, input: &Self::Input, ) -> Result { - let emu = Emulator::new_empty(); + let emu = Emulator::get().unwrap(); if self.first_exec { self.hooks.helpers().first_exec_all(self.hooks); self.first_exec = false; @@ -377,7 +377,7 @@ where mgr: &mut EM, input: &Self::Input, ) -> Result { - let emu = Emulator::new_empty(); + let emu = Emulator::get().unwrap(); if self.first_exec { self.hooks.helpers().first_exec_all(self.hooks); self.first_exec = false; diff --git a/libafl_qemu/src/snapshot.rs b/libafl_qemu/src/snapshot.rs index aec9abb26a..8cac85cba1 100644 --- a/libafl_qemu/src/snapshot.rs +++ b/libafl_qemu/src/snapshot.rs @@ -331,7 +331,7 @@ impl QemuSnapshotHelper { if self.mmap_limit != 0 && total_size > self.mmap_limit { let mut cb = self.stop_execution.take().unwrap(); - let emu = Emulator::new_empty(); + let emu = Emulator::get().unwrap(); (cb)(self, &emu); self.stop_execution = Some(cb); }