mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-13 17:11:21 +00:00
call_indirect checks signature structural equality instead of nominal equality
This commit is contained in:
@ -15,7 +15,6 @@ pub struct LocalBacking {
|
||||
pub vm_memories: Box<[vm::LocalMemory]>,
|
||||
pub vm_tables: Box<[vm::LocalTable]>,
|
||||
pub vm_globals: Box<[vm::LocalGlobal]>,
|
||||
pub vm_signatures: Box<[vm::SigId]>,
|
||||
}
|
||||
|
||||
impl LocalBacking {
|
||||
@ -27,7 +26,6 @@ impl LocalBacking {
|
||||
let vm_memories = Self::finalize_memories(module, &mut memories[..]);
|
||||
let vm_tables = Self::finalize_tables(module, imports, &mut tables[..]);
|
||||
let vm_globals = Self::finalize_globals(module, imports, globals);
|
||||
let vm_signatures = module.sig_registry.into_vm_sigid();
|
||||
|
||||
Self {
|
||||
memories,
|
||||
@ -36,7 +34,6 @@ impl LocalBacking {
|
||||
vm_memories,
|
||||
vm_tables,
|
||||
vm_globals,
|
||||
vm_signatures,
|
||||
}
|
||||
}
|
||||
|
||||
@ -110,7 +107,6 @@ impl LocalBacking {
|
||||
for (i, &func_index) in init.elements.iter().enumerate() {
|
||||
let sig_index = module.func_assoc[func_index];
|
||||
let vm_sig_id = vm::SigId(sig_index.index() as u32);
|
||||
|
||||
let func_data = if module.is_imported_function(func_index) {
|
||||
imports.functions[func_index.index()].clone()
|
||||
} else {
|
||||
|
@ -1,41 +1,40 @@
|
||||
use crate::{
|
||||
types::{FuncSig, Map, MapIndex, SigIndex},
|
||||
vm,
|
||||
types::{FuncSig, Map, SigIndex},
|
||||
};
|
||||
// use hashbrown::HashMap;
|
||||
use hashbrown::HashMap;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct SigRegistry {
|
||||
// func_table: HashMap<FuncSig, SigIndex>,
|
||||
func_table: HashMap<FuncSig, SigIndex>,
|
||||
sig_assoc: Map<SigIndex, FuncSig>,
|
||||
duplicated_sig_assoc: Map<SigIndex, SigIndex>,
|
||||
}
|
||||
|
||||
impl SigRegistry {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
// func_table: HashMap::new(),
|
||||
func_table: HashMap::new(),
|
||||
sig_assoc: Map::new(),
|
||||
duplicated_sig_assoc: Map::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn register(&mut self, func_sig: FuncSig) -> SigIndex {
|
||||
self.sig_assoc.push(func_sig)
|
||||
// let func_table = &mut self.func_table;
|
||||
// let sig_assoc = &mut self.sig_assoc;
|
||||
// *func_table
|
||||
// .entry(func_sig.clone())
|
||||
// .or_insert_with(|| sig_assoc.push(func_sig))
|
||||
// self.sig_assoc.push(func_sig)
|
||||
let func_table = &mut self.func_table;
|
||||
let sig_assoc = &mut self.sig_assoc;
|
||||
let sig_index = *func_table
|
||||
.entry(func_sig.clone())
|
||||
.or_insert_with(|| sig_assoc.push(func_sig));
|
||||
self.duplicated_sig_assoc.push(sig_index);
|
||||
sig_index
|
||||
}
|
||||
|
||||
pub fn lookup_deduplicated_sigindex(&self, sig_index: SigIndex) -> SigIndex {
|
||||
self.duplicated_sig_assoc[sig_index]
|
||||
}
|
||||
|
||||
pub fn lookup_func_sig(&self, sig_index: SigIndex) -> &FuncSig {
|
||||
&self.sig_assoc[sig_index]
|
||||
}
|
||||
|
||||
pub(crate) fn into_vm_sigid(&self) -> Box<[vm::SigId]> {
|
||||
let v: Vec<_> = self
|
||||
.sig_assoc
|
||||
.iter()
|
||||
.map(|(sig_index, _)| vm::SigId(sig_index.index() as u32))
|
||||
.collect();
|
||||
v.into_boxed_slice()
|
||||
}
|
||||
}
|
||||
|
@ -25,9 +25,6 @@ pub struct Ctx {
|
||||
/// A pointer to an array of imported functions, indexed by `FuncIndex`.
|
||||
pub imported_funcs: *mut ImportedFunc,
|
||||
|
||||
/// Signature identifiers for signature-checked indirect calls.
|
||||
pub signatures: *const SigId,
|
||||
|
||||
/// The parent instance.
|
||||
pub local_backing: *mut LocalBacking,
|
||||
}
|
||||
@ -43,8 +40,7 @@ impl Ctx {
|
||||
imported_tables: import_backing.tables.as_mut_ptr(),
|
||||
imported_globals: import_backing.globals.as_mut_ptr(),
|
||||
imported_funcs: import_backing.functions.as_mut_ptr(),
|
||||
|
||||
signatures: local_backing.vm_signatures.as_mut_ptr(),
|
||||
|
||||
local_backing,
|
||||
}
|
||||
}
|
||||
@ -281,11 +277,6 @@ mod vm_offset_tests {
|
||||
Ctx::offset_imported_funcs() as usize,
|
||||
offset_of!(Ctx => imported_funcs).get_byte_offset(),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
Ctx::offset_signatures() as usize,
|
||||
offset_of!(Ctx => signatures).get_byte_offset(),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Reference in New Issue
Block a user