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

feat(vm) Ability to use exports after the instance has been freed #1837

Merged
merged 30 commits into from
Dec 1, 2020
Merged
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
ca89bd5
feat(api) Rename `Extern::from_export` to `…::from_vm_export`.
Hywan Nov 19, 2020
f338b68
feat(vm) Change visibility of some `Instance`'s methods to `pub(self)`.
Hywan Nov 19, 2020
955068c
feat(vm) Move `Instance::(lookup|lookup_by_declaration|exports)` meth…
Hywan Nov 19, 2020
b93af3b
start big patch
Hywan Nov 23, 2020
e77afea
big patch: Start injecting `InstanceAllocator` everywhere.
Hywan Nov 23, 2020
d7bcc21
big patch: add some traces.
Hywan Nov 23, 2020
d5c7b62
Merge branch 'master' into fix-vm-leak
Hywan Nov 23, 2020
b7cdb8f
doc(vm) Code polishing and write more documentation.
Hywan Nov 24, 2020
0a63e56
fix(vm) Avoid casting to `NonNull<u8>`.
Hywan Nov 24, 2020
f4d9deb
try something different
Hywan Nov 24, 2020
7f06d4f
polish and update documentation
Hywan Nov 24, 2020
f968b24
feat(vm) Remove `InstanceHandle::from_vmctx`.
Hywan Nov 26, 2020
4d073ea
feat(vm) Rename `InstanceAllocator::instance_ref` to `::as_ref`.
Hywan Nov 26, 2020
0e1ed94
fix(vm) Fix the pointer size when doing arithmetics.
Hywan Nov 26, 2020
26d20e0
feat(vm) Move `MAX_REFCOUNT` as an associated constant of `InstanceAl…
Hywan Nov 26, 2020
df0e30b
fix(vm) Fix a typo in a panic message.
Hywan Nov 26, 2020
cae4bc6
fix(api) Fix `new_native_with_unsafe_mutable_env`.
Hywan Nov 26, 2020
081d3e3
fix(vm) Remove debugging statements.
Hywan Nov 26, 2020
e94f994
doc(vm) Add more documentation.
Hywan Nov 26, 2020
70455a9
doc(vm) Give more details in the API documentation.
Hywan Nov 26, 2020
c649bec
doc(vm) Remove a useless part of the documentation.
Hywan Nov 26, 2020
8e17a4c
fixup
Hywan Nov 26, 2020
0ec3b70
feat(vm) Change how the layout of `Instance` is calculated.
Hywan Nov 26, 2020
5a00f26
feat(vm) More functions can be constant functions.
Hywan Nov 26, 2020
dc2f5cf
doc(changelog) Add #1837.
Hywan Nov 26, 2020
286426a
doc(vm) Update documentation of exports for the `instance_allocator` …
Hywan Nov 26, 2020
85ae8c7
Merge branch 'master' into fix-vm-leak
Hywan Nov 26, 2020
7621991
test(api) Test that exports work after the instance has been freed.
Hywan Nov 27, 2020
2f9da8b
feat(vm) Mark `InstanceAllocator::new` as unsafe.
Hywan Dec 1, 2020
7973a96
Merge branch 'master' into fix-vm-leak
Hywan Dec 1, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/api/src/externals/function.rs
Original file line number Diff line number Diff line change
@@ -98,6 +98,7 @@ impl Function {
vmctx,
signature: ty.clone(),
call_trampoline: None,
instance_allocator: None,
},
}
}
@@ -150,6 +151,7 @@ impl Function {
vmctx,
signature: ty.clone(),
call_trampoline: None,
instance_allocator: None,
},
}
}
@@ -194,6 +196,7 @@ impl Function {
signature,
kind: VMFunctionKind::Static,
call_trampoline: None,
instance_allocator: None,
},
}
}
@@ -250,6 +253,7 @@ impl Function {
vmctx,
signature,
call_trampoline: None,
instance_allocator: None,
},
}
}
1 change: 1 addition & 0 deletions lib/api/src/externals/global.rs
Original file line number Diff line number Diff line change
@@ -218,6 +218,7 @@ impl<'a> Exportable<'a> for Global {
fn to_export(&self) -> Export {
ExportGlobal {
from: self.global.clone(),
instance_allocator: None,
}
.into()
}
1 change: 1 addition & 0 deletions lib/api/src/externals/memory.rs
Original file line number Diff line number Diff line change
@@ -248,6 +248,7 @@ impl<'a> Exportable<'a> for Memory {
fn to_export(&self) -> Export {
ExportMemory {
from: self.memory.clone(),
instance_allocator: None,
}
.into()
}
1 change: 1 addition & 0 deletions lib/api/src/externals/table.rs
Original file line number Diff line number Diff line change
@@ -156,6 +156,7 @@ impl<'a> Exportable<'a> for Table {
fn to_export(&self) -> Export {
ExportTable {
from: self.table.clone(),
instance_allocator: None,
}
.into()
}
2 changes: 2 additions & 0 deletions lib/api/src/native.rs
Original file line number Diff line number Diff line change
@@ -70,6 +70,7 @@ where
signature,
kind: other.arg_kind,
call_trampoline: None,
instance_allocator: None,
}
}
}
@@ -90,6 +91,7 @@ where
signature,
kind: other.arg_kind,
call_trampoline: None,
instance_allocator: None,
},
}
}
1 change: 1 addition & 0 deletions lib/api/src/types.rs
Original file line number Diff line number Diff line change
@@ -81,6 +81,7 @@ impl ValFuncRef for Val {
kind: wasmer_vm::VMFunctionKind::Static,
vmctx: item.vmctx,
call_trampoline: None,
instance_allocator: None,
};
let f = Function::from_vm_export(store, export);
Self::FuncRef(f)
24 changes: 12 additions & 12 deletions lib/vm/src/export.rs
Original file line number Diff line number Diff line change
@@ -39,9 +39,9 @@ pub struct ExportFunction {
/// Address of the function call trampoline owned by the same VMContext that owns the VMFunctionBody.
/// May be None when the function is a host-function (FunctionType == Dynamic or vmctx == nullptr).
pub call_trampoline: Option<VMTrampoline>,
///// A reference to the instance, to ensure it's not deallocated
///// before the function.
//pub instance_allocator: Option<Arc<InstanceAllocator>>,
/// A reference to the instance, to ensure it's not deallocated
/// before the function.
pub instance_allocator: Option<Arc<InstanceAllocator>>,
}

/// # Safety
@@ -63,9 +63,9 @@ impl From<ExportFunction> for Export {
pub struct ExportTable {
/// Pointer to the containing `Table`.
pub from: Arc<dyn Table>,
///// A reference to the instance, to ensure it's not deallocated
///// before the table.
//pub instance_allocator: Option<Arc<InstanceAllocator>>,
/// A reference to the instance, to ensure it's not deallocated
/// before the table.
pub instance_allocator: Option<Arc<InstanceAllocator>>,
}

/// # Safety
@@ -107,9 +107,9 @@ impl From<ExportTable> for Export {
pub struct ExportMemory {
/// Pointer to the containing `Memory`.
pub from: Arc<dyn Memory>,
///// A reference to the instance, to ensure it's not deallocated
///// before the memory.
//pub instance_allocator: Option<Arc<InstanceAllocator>>,
/// A reference to the instance, to ensure it's not deallocated
/// before the memory.
pub instance_allocator: Option<Arc<InstanceAllocator>>,
}

/// # Safety
@@ -151,9 +151,9 @@ impl From<ExportMemory> for Export {
pub struct ExportGlobal {
/// The global declaration, used for compatibility checking.
pub from: Arc<Global>,
///// A reference to the instance, to ensure it's not deallocated
///// before the global.
//pub instance_allocator: Option<Arc<InstanceAllocator>>,
/// A reference to the instance, to ensure it's not deallocated
/// before the global.
pub instance_allocator: Option<Arc<InstanceAllocator>>,
}

/// # Safety
8 changes: 4 additions & 4 deletions lib/vm/src/instance.rs
Original file line number Diff line number Diff line change
@@ -1073,7 +1073,7 @@ impl InstanceHandle {
signature,
vmctx,
call_trampoline,
//instance_allocator: Some(instance),
instance_allocator: Some(instance),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's 🆕.

}
.into()
}
@@ -1088,7 +1088,7 @@ impl InstanceHandle {

ExportTable {
from,
//instance_allocator: Some(instance),
instance_allocator: Some(instance),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's 🆕.

}
.into()
}
@@ -1103,7 +1103,7 @@ impl InstanceHandle {

ExportMemory {
from,
//instance_allocator: Some(instance),
instance_allocator: Some(instance),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's 🆕.

}
.into()
}
@@ -1120,7 +1120,7 @@ impl InstanceHandle {

ExportGlobal {
from,
//instance_allocator: Some(instance),
instance_allocator: Some(instance),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's 🆕.

}
.into()
}