Skip to content

RFC: define safe shared handle for Unicorn #14

Description

@Jvlegod

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions