Skip to content

Unsound VM lifetime #17

Open
Open
@SpecificProtagonist

Description

@SpecificProtagonist

VM has a lifetime 'a. This lifetime is arbitrary – it is chosen by the caller with no restrictions. This means it can outlive the VM, but other structs assume the VM is life for 'a. This is unsound.

Segfaulting example:

    let mut vm = create_base_vm(DEFAULT_MAX_MEMORY);
    let call_stack = vm.allocate_call_stack();
    let main_method = vm
        .resolve_class_method(
            call_stack,
            "rjvm/SimpleMain",
            "main",
            "([Ljava/lang/String;)V",
        )
        .expect("should find main method");
    drop(vm);
    println!("{main_method:?}");

Possible solutions:

  • Remove lifetime from VM. All methods that produce lifetimed objects take their lifetime from the reference to the VM.
  • Remove lifetime from VM. Keep VM in an Arc. Erase lifetimes internally. Don't hand out structs referencing VM memory directly, instead hand out a wrapper object that also contains a copy of the Arc (this can be transparent to the user).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions