mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-12 16:41:21 +00:00
feat(runtime) Get ready for tiering (#257)
* Add local_function field to context * Add local call indirection to llvm * local call indirection * Fix vm test * Fix cranelift local call indirection * Fix unwinding on nightly
This commit is contained in:
@ -10,8 +10,8 @@ use crate::{
|
||||
table::Table,
|
||||
types::{
|
||||
ImportedFuncIndex, ImportedGlobalIndex, ImportedMemoryIndex, ImportedTableIndex,
|
||||
Initializer, LocalGlobalIndex, LocalMemoryIndex, LocalOrImport, LocalTableIndex, SigIndex,
|
||||
Value,
|
||||
Initializer, LocalFuncIndex, LocalGlobalIndex, LocalMemoryIndex, LocalOrImport,
|
||||
LocalTableIndex, SigIndex, Value,
|
||||
},
|
||||
vm,
|
||||
};
|
||||
@ -28,6 +28,7 @@ pub struct LocalBacking {
|
||||
pub(crate) vm_globals: BoxedMap<LocalGlobalIndex, *mut vm::LocalGlobal>,
|
||||
|
||||
pub(crate) dynamic_sigindices: BoxedMap<SigIndex, vm::SigId>,
|
||||
pub(crate) local_functions: BoxedMap<LocalFuncIndex, *const vm::Func>,
|
||||
}
|
||||
|
||||
// impl LocalBacking {
|
||||
@ -51,6 +52,7 @@ impl LocalBacking {
|
||||
let vm_globals = Self::finalize_globals(&mut globals);
|
||||
|
||||
let dynamic_sigindices = Self::generate_sigindices(&module.info);
|
||||
let local_functions = Self::generate_local_functions(module);
|
||||
|
||||
Self {
|
||||
memories,
|
||||
@ -62,9 +64,23 @@ impl LocalBacking {
|
||||
vm_globals,
|
||||
|
||||
dynamic_sigindices,
|
||||
local_functions,
|
||||
}
|
||||
}
|
||||
|
||||
fn generate_local_functions(module: &ModuleInner) -> BoxedMap<LocalFuncIndex, *const vm::Func> {
|
||||
(0..module.info.func_assoc.len() - module.info.imported_functions.len())
|
||||
.map(|index| {
|
||||
module
|
||||
.func_resolver
|
||||
.get(module, LocalFuncIndex::new(index))
|
||||
.unwrap()
|
||||
.as_ptr() as *const _
|
||||
})
|
||||
.collect::<Map<_, _>>()
|
||||
.into_boxed_map()
|
||||
}
|
||||
|
||||
fn generate_sigindices(info: &ModuleInfo) -> BoxedMap<SigIndex, vm::SigId> {
|
||||
info.signatures
|
||||
.iter()
|
||||
|
@ -245,6 +245,7 @@ pub enum Protect {
|
||||
Read,
|
||||
ReadWrite,
|
||||
ReadExec,
|
||||
ReadWriteExec,
|
||||
}
|
||||
|
||||
impl Protect {
|
||||
@ -254,6 +255,7 @@ impl Protect {
|
||||
Protect::Read => 1,
|
||||
Protect::ReadWrite => 1 | 2,
|
||||
Protect::ReadExec => 1 | 4,
|
||||
Protect::ReadWriteExec => 1 | 2 | 4,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -40,6 +40,8 @@ pub struct Ctx {
|
||||
/// modules safely.
|
||||
pub(crate) dynamic_sigindices: *const SigId,
|
||||
|
||||
pub(crate) local_functions: *const *const Func,
|
||||
|
||||
local_backing: *mut LocalBacking,
|
||||
import_backing: *mut ImportBacking,
|
||||
module: *const ModuleInner,
|
||||
@ -66,6 +68,7 @@ impl Ctx {
|
||||
imported_funcs: import_backing.vm_functions.as_mut_ptr(),
|
||||
|
||||
dynamic_sigindices: local_backing.dynamic_sigindices.as_ptr(),
|
||||
local_functions: local_backing.local_functions.as_ptr(),
|
||||
|
||||
local_backing,
|
||||
import_backing,
|
||||
@ -95,6 +98,7 @@ impl Ctx {
|
||||
imported_funcs: import_backing.vm_functions.as_mut_ptr(),
|
||||
|
||||
dynamic_sigindices: local_backing.dynamic_sigindices.as_ptr(),
|
||||
local_functions: local_backing.local_functions.as_ptr(),
|
||||
|
||||
local_backing,
|
||||
import_backing,
|
||||
@ -173,6 +177,10 @@ impl Ctx {
|
||||
pub fn offset_signatures() -> u8 {
|
||||
7 * (mem::size_of::<usize>() as u8)
|
||||
}
|
||||
|
||||
pub fn offset_local_functions() -> u8 {
|
||||
8 * (mem::size_of::<usize>() as u8)
|
||||
}
|
||||
}
|
||||
|
||||
enum InnerFunc {}
|
||||
@ -363,6 +371,11 @@ mod vm_offset_tests {
|
||||
Ctx::offset_imported_funcs() as usize,
|
||||
offset_of!(Ctx => imported_funcs).get_byte_offset(),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
Ctx::offset_local_functions() as usize,
|
||||
offset_of!(Ctx => local_functions).get_byte_offset(),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -470,6 +483,7 @@ mod vm_ctx_tests {
|
||||
vm_globals: Map::new().into_boxed_map(),
|
||||
|
||||
dynamic_sigindices: Map::new().into_boxed_map(),
|
||||
local_functions: Map::new().into_boxed_map(),
|
||||
};
|
||||
let mut import_backing = ImportBacking {
|
||||
memories: Map::new().into_boxed_map(),
|
||||
|
Reference in New Issue
Block a user