mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-29 16:41:33 +00:00
Fixed warnings
This commit is contained in:
@ -12,7 +12,6 @@ use cranelift_entity::EntityRef;
|
||||
use cranelift_wasm::{FuncIndex, GlobalInit};
|
||||
use region;
|
||||
use std::iter::Iterator;
|
||||
use std::marker::PhantomData;
|
||||
use std::ptr::write_unaligned;
|
||||
use std::slice;
|
||||
use std::sync::Arc;
|
||||
@ -59,23 +58,23 @@ fn get_function_addr(
|
||||
}
|
||||
|
||||
// TODO: To be removed.
|
||||
#[derive(Debug)]
|
||||
#[repr(C, packed)]
|
||||
pub struct VmCtx<'phantom> {
|
||||
pub user_data: UserData,
|
||||
globals: UncheckedSlice<u8>,
|
||||
memories: UncheckedSlice<UncheckedSlice<u8>>,
|
||||
tables: UncheckedSlice<BoundedSlice<usize>>,
|
||||
phantom: PhantomData<&'phantom ()>,
|
||||
}
|
||||
// #[derive(Debug)]
|
||||
// #[repr(C, packed)]
|
||||
// pub struct VmCtx<'phantom> {
|
||||
// pub user_data: UserData,
|
||||
// globals: UncheckedSlice<u8>,
|
||||
// memories: UncheckedSlice<UncheckedSlice<u8>>,
|
||||
// tables: UncheckedSlice<BoundedSlice<usize>>,
|
||||
// phantom: PhantomData<&'phantom ()>,
|
||||
// }
|
||||
|
||||
// TODO: To be removed.
|
||||
#[derive(Debug)]
|
||||
#[repr(C, packed)]
|
||||
pub struct UserData {
|
||||
// pub process: Dispatch<Process>,
|
||||
pub instance: Instance,
|
||||
}
|
||||
// // TODO: To be removed.
|
||||
// #[derive(Debug)]
|
||||
// #[repr(C, packed)]
|
||||
// pub struct UserData {
|
||||
// // pub process: Dispatch<Process>,
|
||||
// pub instance: Instance,
|
||||
// }
|
||||
|
||||
/// An Instance of a WebAssembly module
|
||||
#[derive(Debug)]
|
||||
@ -107,10 +106,9 @@ pub struct Instance {
|
||||
|
||||
// Default memory bound
|
||||
// TODO: Support for only one LinearMemory for now.
|
||||
pub default_memory_bound: i32
|
||||
pub default_memory_bound: i32,
|
||||
}
|
||||
|
||||
|
||||
/// Contains pointers to data (heaps, globals, tables) needed
|
||||
/// by Cranelift.
|
||||
#[derive(Debug)]
|
||||
@ -464,36 +462,35 @@ impl Instance {
|
||||
}
|
||||
|
||||
// TODO: To be removed.
|
||||
pub fn generate_context(&self) -> VmCtx {
|
||||
let memories: Vec<UncheckedSlice<u8>> =
|
||||
self.memories.iter().map(|mem| mem[..].into()).collect();
|
||||
let tables: Vec<BoundedSlice<usize>> =
|
||||
self.tables.iter().map(|table| table[..].into()).collect();
|
||||
let globals: UncheckedSlice<u8> = self.globals[..].into();
|
||||
// pub fn generate_context(&self) -> VmCtx {
|
||||
// let memories: Vec<UncheckedSlice<u8>> =
|
||||
// self.memories.iter().map(|mem| mem[..].into()).collect();
|
||||
// let tables: Vec<BoundedSlice<usize>> =
|
||||
// self.tables.iter().map(|table| table[..].into()).collect();
|
||||
// let globals: UncheckedSlice<u8> = self.globals[..].into();
|
||||
|
||||
// println!("GENERATING CONTEXT {:?}", self.globals);
|
||||
// // println!("GENERATING CONTEXT {:?}", self.globals);
|
||||
|
||||
// assert!(memories.len() >= 1, "modules must have at least one memory");
|
||||
// the first memory has a space of `mem::size_of::<VmCtxData>()` rounded
|
||||
// up to the 4KiB before it. We write the VmCtxData into that.
|
||||
let instance = self.clone();
|
||||
let data = VmCtx {
|
||||
globals: globals,
|
||||
memories: memories[..].into(),
|
||||
tables: tables[..].into(),
|
||||
user_data: UserData {
|
||||
// process,
|
||||
instance: instance,
|
||||
},
|
||||
phantom: PhantomData,
|
||||
};
|
||||
data
|
||||
// let main_heap_ptr = memories[0].as_mut_ptr() as *mut VmCtxData;
|
||||
// unsafe {
|
||||
// main_heap_ptr.sub(1).write(data);
|
||||
// &*(main_heap_ptr as *const VmCtx)
|
||||
// // assert!(memories.len() >= 1, "modules must have at least one memory");
|
||||
// // the first memory has a space of `mem::size_of::<VmCtxData>()` rounded
|
||||
// // up to the 4KiB before it. We write the VmCtxData into that.
|
||||
// let instance = self.clone();
|
||||
// VmCtx {
|
||||
// globals: globals,
|
||||
// memories: memories[..].into(),
|
||||
// tables: tables[..].into(),
|
||||
// user_data: UserData {
|
||||
// // process,
|
||||
// instance: instance,
|
||||
// },
|
||||
// phantom: PhantomData,
|
||||
// }
|
||||
// // let main_heap_ptr = memories[0].as_mut_ptr() as *mut VmCtxData;
|
||||
// // unsafe {
|
||||
// // main_heap_ptr.sub(1).write(data);
|
||||
// // &*(main_heap_ptr as *const VmCtx)
|
||||
// // }
|
||||
// }
|
||||
}
|
||||
|
||||
/// Returns a slice of the contents of allocated linear memory.
|
||||
pub fn inspect_memory(&self, memory_index: usize, address: usize, len: usize) -> &[u8] {
|
||||
@ -531,8 +528,7 @@ impl Clone for Instance {
|
||||
tables: tables_pointer[..].into(),
|
||||
};
|
||||
|
||||
let default_memory_bound =
|
||||
self.memories.get(0).unwrap().current as i32;
|
||||
let default_memory_bound = self.memories.get(0).unwrap().current as i32;
|
||||
|
||||
Instance {
|
||||
tables: Arc::clone(&self.tables),
|
||||
@ -559,7 +555,11 @@ impl Clone for Instance {
|
||||
///
|
||||
extern "C" fn grow_memory(size: u32, memory_index: u32, instance: &mut Instance) -> i32 {
|
||||
// TODO: Support for only one LinearMemory for now.
|
||||
let memory_index: u32 = 0;
|
||||
debug_assert_eq!(
|
||||
memory_index, 0,
|
||||
"non-default memory_index (0) not supported yet"
|
||||
);
|
||||
|
||||
let old_mem_size = instance
|
||||
.memory_mut(memory_index as usize)
|
||||
.grow(size)
|
||||
@ -571,12 +571,14 @@ extern "C" fn grow_memory(size: u32, memory_index: u32, instance: &mut Instance
|
||||
|
||||
// The grown memory changed so data_pointers need to be updated as well.
|
||||
// TODO: Refactor repetitive code
|
||||
let tables_pointer: Vec<BoundedSlice<usize>> =
|
||||
instance.tables.iter().map(|table| table[..].into()).collect();
|
||||
let tables_pointer: Vec<BoundedSlice<usize>> = instance
|
||||
.tables
|
||||
.iter()
|
||||
.map(|table| table[..].into())
|
||||
.collect();
|
||||
let memories_pointer: Vec<UncheckedSlice<u8>> =
|
||||
instance.memories.iter().map(|mem| mem[..].into()).collect();
|
||||
let globals_pointer: UncheckedSlice<u8> =
|
||||
instance.globals[..].into();
|
||||
let globals_pointer: UncheckedSlice<u8> = instance.globals[..].into();
|
||||
|
||||
let data_pointers = DataPointers {
|
||||
memories: memories_pointer[..].into(),
|
||||
|
@ -1,7 +1,6 @@
|
||||
//! Utility functions for the webassembly library
|
||||
use super::instance::Instance;
|
||||
use std::mem::transmute;
|
||||
use super::super::common::slice::{UncheckedSlice, BoundedSlice};
|
||||
|
||||
/// Detect if a provided binary is a WASM file
|
||||
pub fn is_wasm_binary(binary: &Vec<u8>) -> bool {
|
||||
@ -37,10 +36,15 @@ instance.data_pointers.globals \t- {:X} | offset - {:?}
|
||||
instance.default_memory_bound \t- {:X} | offset - {:?}
|
||||
====== INSTANCE OFFSET TABLE ======
|
||||
",
|
||||
instance_address, 0,
|
||||
tables_pointer_address, tables_pointer_address - instance_address,
|
||||
memories_pointer_address, memories_pointer_address - instance_address,
|
||||
globals_pointer_address, globals_pointer_address - instance_address,
|
||||
default_memory_bound_address, default_memory_bound_address - instance_address,
|
||||
instance_address,
|
||||
0,
|
||||
tables_pointer_address,
|
||||
tables_pointer_address - instance_address,
|
||||
memories_pointer_address,
|
||||
memories_pointer_address - instance_address,
|
||||
globals_pointer_address,
|
||||
globals_pointer_address - instance_address,
|
||||
default_memory_bound_address,
|
||||
default_memory_bound_address - instance_address,
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user