mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-29 16:41:33 +00:00
Improved instance & module data pointers location
This commit is contained in:
@ -78,7 +78,11 @@ fn get_function_addr(
|
||||
|
||||
/// An Instance of a WebAssembly module
|
||||
#[derive(Debug)]
|
||||
#[repr(C)]
|
||||
pub struct Instance {
|
||||
// C-like pointers to data (heaps, globals, tables)
|
||||
pub data_pointers: DataPointers,
|
||||
|
||||
/// WebAssembly table data
|
||||
// pub tables: Arc<Vec<RwLock<Vec<usize>>>>,
|
||||
pub tables: Arc<Vec<Vec<usize>>>,
|
||||
@ -101,9 +105,6 @@ pub struct Instance {
|
||||
// Region start memory location
|
||||
// code_base: *const (),
|
||||
|
||||
// C-like pointers to data (heaps, globals, tables)
|
||||
pub data_pointers: DataPointers,
|
||||
|
||||
// Default memory bound
|
||||
// TODO: Support for only one LinearMemory for now.
|
||||
pub default_memory_bound: i32,
|
||||
@ -112,6 +113,7 @@ pub struct Instance {
|
||||
/// Contains pointers to data (heaps, globals, tables) needed
|
||||
/// by Cranelift.
|
||||
#[derive(Debug)]
|
||||
#[repr(C)]
|
||||
pub struct DataPointers {
|
||||
// Pointer to tables
|
||||
pub tables: UncheckedSlice<BoundedSlice<usize>>,
|
||||
|
@ -332,12 +332,12 @@ impl<'environment> FuncEnvironmentTrait for FuncEnvironment<'environment> {
|
||||
let vmctx = func.create_global_value(ir::GlobalValueData::VMContext);
|
||||
let ptr_size = self.ptr_size();
|
||||
|
||||
// Given a vmctx, we want to retrieve vmctx.tables
|
||||
// Create a table whose base address is stored at `vmctx+88`.
|
||||
// 88 is the offset of the vmctx.tables pointer respect to vmctx pointer
|
||||
// Given a instance, we want to retrieve instance.tables
|
||||
// Create a table whose base address is stored at `instance+0`.
|
||||
// 0 is the offset of the vmctx.tables pointer respect to vmctx pointer
|
||||
let base = func.create_global_value(ir::GlobalValueData::Load {
|
||||
base: vmctx,
|
||||
offset: Offset32::new(88),
|
||||
offset: Offset32::new(0),
|
||||
global_type: self.pointer_type(),
|
||||
});
|
||||
|
||||
@ -369,12 +369,12 @@ impl<'environment> FuncEnvironmentTrait for FuncEnvironment<'environment> {
|
||||
}
|
||||
|
||||
fn make_heap(&mut self, func: &mut ir::Function, index: MemoryIndex) -> ir::Heap {
|
||||
// Create a static heap whose base address is stored at `vmctx+96`.
|
||||
// Create a static heap whose base address is stored at `instance+8`.
|
||||
let vmctx = func.create_global_value(ir::GlobalValueData::VMContext);
|
||||
|
||||
let heap_base_addr = func.create_global_value(ir::GlobalValueData::Load {
|
||||
base: vmctx,
|
||||
offset: Offset32::new(96),
|
||||
offset: Offset32::new(8),
|
||||
global_type: self.pointer_type(),
|
||||
});
|
||||
|
||||
@ -454,7 +454,7 @@ impl<'environment> FuncEnvironmentTrait for FuncEnvironment<'environment> {
|
||||
|
||||
let globals_base_addr = func.create_global_value(ir::GlobalValueData::Load {
|
||||
base: vmctx,
|
||||
offset: Offset32::new(104),
|
||||
offset: Offset32::new(16),
|
||||
global_type: self.pointer_type(),
|
||||
});
|
||||
|
||||
@ -506,6 +506,7 @@ impl<'environment> FuncEnvironmentTrait for FuncEnvironment<'environment> {
|
||||
.special_param(ir::ArgumentPurpose::VMContext)
|
||||
.expect("Missing vmctx parameter");
|
||||
|
||||
|
||||
// The `callee` value is an index into a table of function pointers.
|
||||
// Apparently, that table is stored at absolute address 0 in this dummy environment.
|
||||
// TODO: Generate bounds checking code.
|
||||
@ -556,6 +557,9 @@ impl<'environment> FuncEnvironmentTrait for FuncEnvironment<'environment> {
|
||||
.special_param(ir::ArgumentPurpose::VMContext)
|
||||
.expect("Missing vmctx parameter");
|
||||
|
||||
// println!("POINTER BYTES {}", self.pointer_bytes());
|
||||
// println!("POINTER SIZE {}", self.ptr_size());
|
||||
|
||||
// Build a value list for the call instruction containing the call_args and the vmctx
|
||||
// parameter.
|
||||
let mut args = ir::ValueList::default();
|
||||
|
Reference in New Issue
Block a user