LibAFL icon indicating copy to clipboard operation
LibAFL copied to clipboard

libafl-qemu: `Emulator` is `Clone`, but `Emulator::new` returns an error if called twice

Open langston-barrett opened this issue 2 years ago • 1 comments

In #1690, Emulator became Clone, but Emulator::new returns an error if called twice from the same thread. This is a bit confusing - am I supposed to be able to have multiple Emulators or not?

langston-barrett avatar Dec 22 '23 17:12 langston-barrett

I agree the use of Clone for Emulator is inappropriate. In fact, Emulator is allowed to be initialized once per process and is usually accessed through the Emulator::new_empty or Emulator::get method.

In my opinion, Emulator should be newed once per process and be accessed exclusively through a reference and not be usable with the structure itself, a bit like &str (since we use it just like a Rust reference, and clone here is a well hidden static reference clone).

I will prepare a patch to not allow access to Emulator::new_empty outside of emu.rs and instead use Emulator::get (it doesn't seem sane to let it accessible).

I will wait for feedback on the reference idea if it makes sense.

rmalmain avatar Dec 26 '23 15:12 rmalmain