Add a type parameter to VMOffsets for pointer size (#3020)
* Add a type parameter to `VMOffsets` for pointer size This commit adds a type parameter to `VMOffsets` representing the pointer size to improve computations in `wasmtime-runtime` which always use a constant value of the host's pointer size. The type parameter is `u8` for `wasmtime-cranelift`'s use case where cross-compilation may be involved. * fix lightbeam
This commit is contained in:
@@ -965,8 +965,20 @@ mod tests {
|
||||
|
||||
let actual_offset = (ref_count_ptr as usize) - (extern_data_ptr as usize);
|
||||
|
||||
let offsets = wasmtime_environ::VMOffsets::from(wasmtime_environ::VMOffsetsFields {
|
||||
ptr: 8,
|
||||
num_signature_ids: 0,
|
||||
num_imported_functions: 0,
|
||||
num_imported_tables: 0,
|
||||
num_imported_memories: 0,
|
||||
num_imported_globals: 0,
|
||||
num_defined_functions: 0,
|
||||
num_defined_tables: 0,
|
||||
num_defined_memories: 0,
|
||||
num_defined_globals: 0,
|
||||
});
|
||||
assert_eq!(
|
||||
wasmtime_environ::VMOffsets::vm_extern_data_ref_count(),
|
||||
offsets.vm_extern_data_ref_count(),
|
||||
actual_offset.try_into().unwrap(),
|
||||
);
|
||||
}
|
||||
@@ -981,7 +993,7 @@ mod tests {
|
||||
let actual_offset = (next_ptr as usize) - (table_ptr as usize);
|
||||
|
||||
let offsets = wasmtime_environ::VMOffsets::from(wasmtime_environ::VMOffsetsFields {
|
||||
pointer_size: 8,
|
||||
ptr: 8,
|
||||
num_signature_ids: 0,
|
||||
num_imported_functions: 0,
|
||||
num_imported_tables: 0,
|
||||
@@ -1008,7 +1020,7 @@ mod tests {
|
||||
let actual_offset = (end_ptr as usize) - (table_ptr as usize);
|
||||
|
||||
let offsets = wasmtime_environ::VMOffsets::from(wasmtime_environ::VMOffsetsFields {
|
||||
pointer_size: 8,
|
||||
ptr: 8,
|
||||
num_signature_ids: 0,
|
||||
num_imported_functions: 0,
|
||||
num_imported_tables: 0,
|
||||
|
||||
@@ -27,7 +27,7 @@ use wasmtime_environ::wasm::{
|
||||
DataIndex, DefinedGlobalIndex, DefinedMemoryIndex, DefinedTableIndex, ElemIndex, EntityIndex,
|
||||
FuncIndex, GlobalIndex, MemoryIndex, TableElementType, TableIndex, WasmType,
|
||||
};
|
||||
use wasmtime_environ::{ir, Module, VMOffsets};
|
||||
use wasmtime_environ::{ir, HostPtr, Module, VMOffsets};
|
||||
|
||||
mod allocator;
|
||||
|
||||
@@ -119,7 +119,7 @@ pub(crate) struct Instance {
|
||||
module: Arc<Module>,
|
||||
|
||||
/// Offsets in the `vmctx` region, precomputed from the `module` above.
|
||||
offsets: VMOffsets,
|
||||
offsets: VMOffsets<HostPtr>,
|
||||
|
||||
/// WebAssembly linear memory data.
|
||||
///
|
||||
|
||||
@@ -22,8 +22,8 @@ use wasmtime_environ::wasm::{
|
||||
DefinedFuncIndex, DefinedMemoryIndex, DefinedTableIndex, GlobalInit, SignatureIndex, WasmType,
|
||||
};
|
||||
use wasmtime_environ::{
|
||||
ir, MemoryInitialization, MemoryInitializer, Module, ModuleType, TableInitializer, VMOffsets,
|
||||
WASM_PAGE_SIZE,
|
||||
ir, HostPtr, MemoryInitialization, MemoryInitializer, Module, ModuleType, TableInitializer,
|
||||
VMOffsets, WASM_PAGE_SIZE,
|
||||
};
|
||||
|
||||
mod pooling;
|
||||
@@ -643,7 +643,7 @@ unsafe impl InstanceAllocator for OnDemandInstanceAllocator {
|
||||
let mut handle = {
|
||||
let instance = Instance {
|
||||
module: req.module.clone(),
|
||||
offsets: VMOffsets::new(std::mem::size_of::<*const u8>() as u8, &req.module),
|
||||
offsets: VMOffsets::new(HostPtr, &req.module),
|
||||
memories,
|
||||
tables,
|
||||
dropped_elements: EntitySet::with_capacity(req.module.passive_elements.len()),
|
||||
|
||||
@@ -21,7 +21,7 @@ use std::mem;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use wasmtime_environ::{
|
||||
entity::{EntitySet, PrimaryMap},
|
||||
MemoryStyle, Module, Tunables, VMOffsets, VMOffsetsFields, WASM_PAGE_SIZE,
|
||||
HostPtr, MemoryStyle, Module, Tunables, VMOffsets, VMOffsetsFields, WASM_PAGE_SIZE,
|
||||
};
|
||||
|
||||
cfg_if::cfg_if! {
|
||||
@@ -298,7 +298,7 @@ impl InstancePool {
|
||||
|
||||
// Calculate the maximum size of an Instance structure given the limits
|
||||
let offsets = VMOffsets::from(VMOffsetsFields {
|
||||
pointer_size: std::mem::size_of::<*const u8>() as u8,
|
||||
ptr: HostPtr,
|
||||
num_signature_ids: module_limits.types,
|
||||
num_imported_functions: module_limits.imported_functions,
|
||||
num_imported_tables: module_limits.imported_tables,
|
||||
@@ -358,10 +358,7 @@ impl InstancePool {
|
||||
instance as _,
|
||||
Instance {
|
||||
module: self.empty_module.clone(),
|
||||
offsets: VMOffsets::new(
|
||||
std::mem::size_of::<*const u8>() as u8,
|
||||
&self.empty_module,
|
||||
),
|
||||
offsets: VMOffsets::new(HostPtr, &self.empty_module),
|
||||
memories: PrimaryMap::with_capacity(limits.memories as usize),
|
||||
tables: PrimaryMap::with_capacity(limits.tables as usize),
|
||||
dropped_elements: EntitySet::new(),
|
||||
@@ -383,10 +380,7 @@ impl InstancePool {
|
||||
let instance = self.instance(index);
|
||||
|
||||
instance.module = req.module.clone();
|
||||
instance.offsets = VMOffsets::new(
|
||||
std::mem::size_of::<*const u8>() as u8,
|
||||
instance.module.as_ref(),
|
||||
);
|
||||
instance.offsets = VMOffsets::new(HostPtr, instance.module.as_ref());
|
||||
instance.host_state = std::mem::replace(&mut req.host_state, Box::new(()));
|
||||
|
||||
let mut limiter = req.store.and_then(|s| (*s).limiter());
|
||||
@@ -497,8 +491,7 @@ impl InstancePool {
|
||||
// should put everything back in a relatively pristine state for each
|
||||
// fresh allocation later on.
|
||||
instance.module = self.empty_module.clone();
|
||||
instance.offsets =
|
||||
VMOffsets::new(std::mem::size_of::<*const u8>() as u8, &self.empty_module);
|
||||
instance.offsets = VMOffsets::new(HostPtr, &self.empty_module);
|
||||
|
||||
self.free_list.lock().unwrap().push(index);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user