Unicorn currently implements Clone through Rc<UnsafeCell<UnicornInner<D>>>.
The design is useful: the cloned handle points to the same Unicorn engine.
(My understanding is that &D and &mut D cannot coexist.)
However, it can exec in unicorn-rs.
let emu = Unicorn::new_with_data(Arch::X86, Mode::MODE_64, 0u32)?;
let mut another = emu.clone();
let read_only: &u32 = emu.get_data();
let writable: &mut u32 = another.get_data_mut();
*writable = 42;
println!("{read_only}");
However, the current API exposes:
|
pub fn get_data(&self) -> &D { |
pub fn get_data(&self) -> &D;
pub fn get_data_mut(&mut self) -> &mut D;
Two cloned handles can therefore create &D and &mut D for the same D at the same time.
I think maybe this violates Rust's aliasing rules(see above).
Do we want to preserve Unicorn::clone() as a supported shared handle API?
Unicorncurrently implementsClonethroughRc<UnsafeCell<UnicornInner<D>>>.The design is useful: the cloned handle points to the same Unicorn engine.
(My understanding is that
&Dand&mut Dcannot coexist.)However, it can exec in unicorn-rs.
However, the current API exposes:
unicorn-engine-rs/crates/unicorn/src/lib.rs
Line 266 in e8ca055
Two cloned handles can therefore create
&Dand&mut Dfor the sameDat the same time.I think maybe this violates Rust's
aliasing rules(see above).Do we want to preserve
Unicorn::clone()as a supported shared handle API?