Change some VMContext pointers to () pointers (#4190)
* Change some `VMContext` pointers to `()` pointers This commit is motivated by my work on the component model implementation for imported functions. Currently all context pointers in wasm are `*mut VMContext` but with the component model my plan is to make some pointers instead along the lines of `*mut VMComponentContext`. In doing this though one worry I have is breaking what has otherwise been a core invariant of Wasmtime for quite some time, subtly introducing bugs by accident. To help assuage my worry I've opted here to erase knowledge of `*mut VMContext` where possible. Instead where applicable a context pointer is simply known as `*mut ()` and the embedder doesn't actually know anything about this context beyond the value of the pointer. This will help prevent Wasmtime from accidentally ever trying to interpret this context pointer as an actual `VMContext` when it might instead be a `VMComponentContext`. Overall this was a pretty smooth transition. The main change here is that the `VMTrampoline` (now sporting more docs) has its first argument changed to `*mut ()`. The second argument, the caller context, is still configured as `*mut VMContext` though because all functions are always called from wasm still. Eventually for component-to-component calls I think we'll probably "fake" the second argument as the same as the first argument, losing track of the original caller, as an intentional way of isolating components from each other. Along the way there are a few host locations which do actually assume that the first argument is indeed a `VMContext`. These are valid assumptions that are upheld from a correct implementation, but I opted to add a "magic" field to `VMContext` to assert this in debug mode. This new "magic" field is inintialized during normal vmcontext initialization and it's checked whenever a `VMContext` is reinterpreted as an `Instance` (but only in debug mode). My hope here is to catch any future accidental mistakes, if ever. * Use a VMOpaqueContext wrapper * Fix typos
This commit is contained in:
@@ -9,8 +9,8 @@ use crate::table::{Table, TableElement, TableElementType};
|
||||
use crate::traphandlers::Trap;
|
||||
use crate::vmcontext::{
|
||||
VMBuiltinFunctionsArray, VMCallerCheckedAnyfunc, VMContext, VMFunctionImport,
|
||||
VMGlobalDefinition, VMGlobalImport, VMMemoryDefinition, VMMemoryImport, VMRuntimeLimits,
|
||||
VMTableDefinition, VMTableImport,
|
||||
VMGlobalDefinition, VMGlobalImport, VMMemoryDefinition, VMMemoryImport, VMOpaqueContext,
|
||||
VMRuntimeLimits, VMTableDefinition, VMTableImport, VMCONTEXT_MAGIC,
|
||||
};
|
||||
use crate::{
|
||||
ExportFunction, ExportGlobal, ExportMemory, ExportTable, Imports, ModuleRuntimeInfo, Store,
|
||||
@@ -488,7 +488,7 @@ impl Instance {
|
||||
(self.runtime_info.image_base()
|
||||
+ self.runtime_info.function_info(def_index).start as usize)
|
||||
as *mut _,
|
||||
self.vmctx_ptr(),
|
||||
VMOpaqueContext::from_vmcontext(self.vmctx_ptr()),
|
||||
)
|
||||
} else {
|
||||
let import = self.imported_function(index);
|
||||
@@ -879,6 +879,8 @@ impl Instance {
|
||||
unsafe fn initialize_vmctx(&mut self, module: &Module, store: StorePtr, imports: Imports) {
|
||||
assert!(std::ptr::eq(module, self.module().as_ref()));
|
||||
|
||||
*self.vmctx_plus_offset(self.offsets.vmctx_magic()) = VMCONTEXT_MAGIC;
|
||||
|
||||
if let Some(store) = store.as_raw() {
|
||||
*self.runtime_limits() = (*store).vmruntime_limits();
|
||||
*self.epoch_ptr() = (*store).epoch_ptr();
|
||||
|
||||
Reference in New Issue
Block a user