Skip to content

Commit

Permalink
some debug info, tables stub & warnings fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ovstinga authored and camilbancioiu committed Oct 4, 2022
1 parent 59f64ba commit b05a251
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/runtime-c-api/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ pub unsafe extern "C" fn wasmer_instantiate_with_options(
wasmer_result_t::WASMER_OK
}

/// todo: add documentation
/// TODO: add documentation
#[allow(clippy::cast_ptr_alignment)]
#[no_mangle]
pub unsafe extern "C" fn wasmer_instantiate_reset(
Expand Down
2 changes: 1 addition & 1 deletion lib/runtime-c-api/src/trampoline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub unsafe extern "C" fn wasmer_trampoline_buffer_builder_build(
#[allow(clippy::cast_ptr_alignment)]
pub unsafe extern "C" fn wasmer_trampoline_buffer_destroy(buffer: *mut wasmer_trampoline_buffer_t) {
if !buffer.is_null() {
Box::from_raw(buffer as *mut TrampolineBuffer);
drop(Box::from_raw(buffer as *mut TrampolineBuffer));
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/runtime-c-api/wasmer.h
Original file line number Diff line number Diff line change
Expand Up @@ -1149,7 +1149,7 @@ wasmer_result_t wasmer_instantiate(wasmer_instance_t **instance,
int imports_len);

/**
* todo: add documentation
* TODO: add documentation
*/
wasmer_result_t wasmer_instantiate_reset(wasmer_instance_t *instance);

Expand Down
2 changes: 1 addition & 1 deletion lib/runtime-c-api/wasmer.hh
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ wasmer_result_t wasmer_instantiate(wasmer_instance_t **instance,
wasmer_import_t *imports,
int imports_len);

/// todo: add documentation
/// TODO: add documentation
wasmer_result_t wasmer_instantiate_reset(wasmer_instance_t *instance);

wasmer_result_t wasmer_instantiate_with_options(wasmer_instance_t **instance,
Expand Down
56 changes: 51 additions & 5 deletions lib/runtime-core/src/backing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ impl LocalBacking {
})
}

/// todo: add documentation
/// TODO: add documentation
pub(crate) fn reset(&mut self, module_info: &ModuleInfo) -> RuntimeResult<()> {
// todo: remove debug prints
// TODO: remove debug prints
println!("Resetting Local Backing:");
Self::reset_memories(&module_info, &mut self.memories)?;
Self::reset_tables(&module_info, &mut self.tables)?;
Expand All @@ -117,7 +117,7 @@ impl LocalBacking {
module_info: &ModuleInfo,
memories: &mut SliceMap<LocalMemoryIndex, Memory>,
) -> RuntimeResult<()> {
// todo: remove debug prints
// TODO: remove debug prints
for data_initializer in module_info.data_initializers.iter() {
let DataInitializer {
memory_index,
Expand All @@ -134,6 +134,9 @@ impl LocalBacking {

if let LocalOrImport::Local(index) = memory_index.local_or_import(&module_info) {
if let Some(memory) = memories.get_mut(index) {
// ?let's debug some memory info
println!(" Memory: {:?}", memory);

let cells = &memory.view()[base..base + data.len()];
let cells = cells.iter().zip(data.iter());
for (cell, data) in cells {
Expand All @@ -150,11 +153,13 @@ impl LocalBacking {
Ok(())
}

// ? do we really need this
#[allow(clippy::cast_ptr_alignment)]
fn reset_tables(
module_info: &ModuleInfo,
_tables: &mut SliceMap<LocalTableIndex, Table>,
) -> RuntimeResult<()> {
// todo: remove debug prints
// TODO: remove debug prints
for table_initializer in &module_info.elem_initializers {
let TableInitializer {
table_index: _,
Expand All @@ -168,6 +173,42 @@ impl LocalBacking {
"Can only reset tables with const base",
)));
};

// FIXME: need `module` as @param
// if let LocalOrImport::Local(index) = table_index {
// if let Some(table) = tables.get_mut(index) {
// table.anyfunc_direct_access_mut(|elements| {
// for (i, &func_index) in elements.iter().enumerate() {
// let sig_index = module_info.func_assoc[func_index];
// let signature = SigRegistry
// .lookup_signature_ref(&module_info.signatures[sig_index]);
// let sig_id =
// vm::SigId(SigRegistry.lookup_sig_index(signature).index() as u32);
// let (func, ctx) = if let LocalOrImport::Local(local_func_index) =
// func_index.local_or_import(&module_info)
// {
// (
// module
// .runnable_module
// .get_func(&module_info, local_func_index)
// .unwrap()
// .as_ptr()
// as *const vm::Func,
// vmctx,
// )
// } else {
// continue;
// };

// elements[base + i] = vm::Anyfunc { func, ctx, sig_id };
// }
// });
// } else {
// return Err(RuntimeError(Box::new("Missing table to reset")));
// }
// } else {
// return Err(RuntimeError(Box::new("Can only reset local table")));
// }
}
println!(" [x] tables");
Ok(())
Expand All @@ -177,7 +218,7 @@ impl LocalBacking {
module_info: &ModuleInfo,
globals: &mut SliceMap<LocalGlobalIndex, Global>,
) -> RuntimeResult<()> {
// todo: remove debug prints
// TODO: remove debug prints
for (index, global_init) in module_info.globals.iter() {
let GlobalInit { desc, init } = global_init;
let value = if let Initializer::Const(value) = init {
Expand Down Expand Up @@ -234,6 +275,11 @@ impl LocalBacking {

let mut memories = Map::with_capacity(memories_count);
for (_, &desc) in &module.info.memories {
// ?move conditionn onn a lower layer
// ?handle pages count ('10' can be cached into a const like `MAX_MEMORIES_COUNT`)
if desc.minimum.0 > 10 {
return Err(CreationError::UnableToCreateMemory);
}
let memory = Memory::new(desc)?;
memories.push(memory);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/runtime-core/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl Instance {
Ok(instance)
}

/// todo: add documentation
/// TODO: add documentation
pub fn reset(&mut self) -> RuntimeResult<()> {
self.inner.backing.reset(&self.module.info)?;
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion lib/runtime-core/src/memory/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub mod ptr;
mod static_;
mod view;

/// todo: add documentation
/// TODO: add documentation
pub const MAX_MEMORIES_COUNT: usize = 1;

#[derive(Clone)]
Expand Down
2 changes: 1 addition & 1 deletion lib/runtime-core/src/typed_func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ impl<'a> DynamicFunc<'a> {
fn drop(&mut self) {
unsafe {
TrampolineBufferBuilder::remove_global(self.ptr);
Box::from_raw(self.ctx);
drop(Box::from_raw(self.ctx));
}
}
}
Expand Down

0 comments on commit b05a251

Please sign in to comment.