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

* vm.rs - calling Ctx data_finalizer upon destruction #561

Merged
merged 3 commits into from
Jul 24, 2019
Merged

* vm.rs - calling Ctx data_finalizer upon destruction #561

merged 3 commits into from
Jul 24, 2019

Conversation

YaronWittenstein
Copy link
Contributor

@YaronWittenstein YaronWittenstein commented Jul 15, 2019

It seems that the data_finalizer field of the Ctx is never being called upon instance destruction.

It seems a bit tricky to assert that in though

@syrusakbary @Hywan

@Hywan Hywan self-assigned this Jul 15, 2019
@Hywan Hywan added 🎉 enhancement New feature! 📦 lib-deprecated About the deprecated crates 🧪 tests I love tests labels Jul 15, 2019
YaronWittenstein added a commit to spacemeshos/svm that referenced this pull request Jul 15, 2019
@syrusakbary
Copy link
Member

Ummm... tests are broken on windows, so we have to take a deeper look.
Will trigger bors to see the results on macos/linux.

@syrusakbary
Copy link
Member

bors try

bors bot added a commit that referenced this pull request Jul 15, 2019
@bors
Copy link
Contributor

bors bot commented Jul 15, 2019

try

Build failed

@syrusakbary
Copy link
Member

(still investigating)

@syrusakbary
Copy link
Member

bors try

bors bot added a commit that referenced this pull request Jul 17, 2019
@bors
Copy link
Contributor

bors bot commented Jul 17, 2019

try

Build failed

@MarkMcCaskey
Copy link
Contributor

MarkMcCaskey commented Jul 24, 2019

Hey @YaronWittenstein I found the issue on our side! We are breaking the contract on std::mem::uninitialized() and calling Drop on garbage memory interpreted as a Ctx.

The reason is that we do something like

let ctx = Box::new(std::mem::uninit());
something_else.val = Box::into_raw(ctx);
something_else.val = real_ctx; // this is invalid because it causes the uninit Ctx to Drop

And the solution is to change the last line to

let mut real_ctx = real_ctx;
std::mem::swap(&mut real_ctx, &mut something_else.val);
std::mem::forget(real_ctx); // tell Rust to not Drop our garbage Ctx

I have a fix locally that I need to clean up -- and actually I need to port it to the new MaybeUninit style for Rust 1.38 -- but your PR was passing all the tests I tried on my computer last night.

Thanks! I'll ping you again when its merged into master

bors bot added a commit that referenced this pull request Jul 24, 2019
576: fix Drop of uninit Ctx; use MaybeUninit r=MarkMcCaskey a=MarkMcCaskey

I'm somewhat concerned that we need to call
`intrinsics::panic_if_uninhabited::<T>();` or something to tell the compiler that we know it's safe.

We just reinterpret the pointer later as initialized which is safe in theory due to `repr(transparent)`

this should unblock #561

Co-authored-by: Mark McCaskey <mark@wasmer.io>
bors bot added a commit that referenced this pull request Jul 24, 2019
576: fix Drop of uninit Ctx; use MaybeUninit r=MarkMcCaskey a=MarkMcCaskey

I'm somewhat concerned that we need to call
`intrinsics::panic_if_uninhabited::<T>();` or something to tell the compiler that we know it's safe.

We just reinterpret the pointer later as initialized which is safe in theory due to `repr(transparent)`

this should unblock #561

Co-authored-by: Mark McCaskey <mark@wasmer.io>
bors bot added a commit that referenced this pull request Jul 24, 2019
576: fix Drop of uninit Ctx; use MaybeUninit r=MarkMcCaskey a=MarkMcCaskey

I'm somewhat concerned that we need to call
`intrinsics::panic_if_uninhabited::<T>();` or something to tell the compiler that we know it's safe.

We just reinterpret the pointer later as initialized which is safe in theory due to `repr(transparent)`

this should unblock #561

Co-authored-by: Mark McCaskey <mark@wasmer.io>
bors bot added a commit that referenced this pull request Jul 24, 2019
576: fix Drop of uninit Ctx; use MaybeUninit r=MarkMcCaskey a=MarkMcCaskey

I'm somewhat concerned that we need to call
`intrinsics::panic_if_uninhabited::<T>();` or something to tell the compiler that we know it's safe.

We just reinterpret the pointer later as initialized which is safe in theory due to `repr(transparent)`

this should unblock #561

Co-authored-by: Mark McCaskey <mark@wasmer.io>
Co-authored-by: Mark McCaskey <markmccaskey@users.noreply.github.com>
bors bot added a commit that referenced this pull request Jul 24, 2019
576: fix Drop of uninit Ctx; use MaybeUninit r=MarkMcCaskey a=MarkMcCaskey

I'm somewhat concerned that we need to call
`intrinsics::panic_if_uninhabited::<T>();` or something to tell the compiler that we know it's safe.

We just reinterpret the pointer later as initialized which is safe in theory due to `repr(transparent)`

this should unblock #561

Co-authored-by: Mark McCaskey <mark@wasmer.io>
Co-authored-by: Mark McCaskey <markmccaskey@users.noreply.github.com>
@MarkMcCaskey
Copy link
Contributor

bors try

bors bot added a commit that referenced this pull request Jul 24, 2019
@bors
Copy link
Contributor

bors bot commented Jul 24, 2019

@syrusakbary syrusakbary merged commit 6a810bc into wasmerio:master Jul 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🎉 enhancement New feature! 📦 lib-deprecated About the deprecated crates 🧪 tests I love tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants