Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unsound VM lifetime #17

Open
SpecificProtagonist opened this issue Aug 28, 2023 · 2 comments
Open

Unsound VM lifetime #17

SpecificProtagonist opened this issue Aug 28, 2023 · 2 comments

Comments

@SpecificProtagonist
Copy link

SpecificProtagonist commented Aug 28, 2023

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).
@andreabergia
Copy link
Owner

I don't think I am going to fix this honestly, it sounds too much work and I consider the project "finished" (in the sense that I learnt what I had in mind initially and I want to move on to other things).

In any case, solution 1 is pretty clear to me.

I am a bit uncertain on solution 2: what do you mean with erase lifetimes internally? Can you point out to any example or just sketch a few lines of code?

Thanks a lot!

@SpecificProtagonist
Copy link
Author

SpecificProtagonist commented Sep 7, 2023

Here's an example. I don't currently do the Arc thing though; the project is pretty unfinished (so don't judge it too harshly :3).

Happy to help ^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants