Fix table/memory import

This commit is contained in:
Brandon Fish
2019-01-30 19:19:53 -06:00
parent cf325f7cd6
commit 9dcbea7408

View File

@ -6,25 +6,25 @@ use libc::c_int;
use std::cell::UnsafeCell; use std::cell::UnsafeCell;
use std::{ffi::c_void, fmt, mem, ptr}; use std::{ffi::c_void, fmt, mem, ptr};
use wasmer_runtime_core::{ use wasmer_runtime_core::{
error::CallResult,
export::{Context, Export, FuncPointer}, export::{Context, Export, FuncPointer},
func, func,
global::Global, global::Global,
import::{ImportObject, Namespace}, import::{ImportObject, Namespace},
imports, imports,
memory::Memory, memory::Memory,
error::CallResult,
table::Table, table::Table,
types::{ types::{
ElementType, FuncSig, GlobalDescriptor, ElementType, FuncSig, GlobalDescriptor, MemoryDescriptor, TableDescriptor,
Type::{self, *}, Type::{self, *},
Value, TableDescriptor, MemoryDescriptor Value,
}, },
Module, Instance,
units::Pages, units::Pages,
vm::Ctx,
vm::LocalGlobal, vm::LocalGlobal,
vm::LocalMemory, vm::LocalMemory,
vm::LocalTable, vm::LocalTable,
vm::Ctx, Instance, Module,
}; };
#[macro_use] #[macro_use]
@ -281,12 +281,7 @@ pub struct EmscriptenGlobals {
pub data: EmscriptenGlobalsData, pub data: EmscriptenGlobalsData,
// The emscripten memory // The emscripten memory
pub memory: Memory, pub memory: Memory,
pub vm_memory: LocalMemory,
// The emscripten table
pub table: Table, pub table: Table,
pub vm_table: LocalTable,
pub table_min: u32,
pub table_max: Option<u32>,
pub memory_min: Pages, pub memory_min: Pages,
pub memory_max: Option<Pages>, pub memory_max: Option<Pages>,
} }
@ -303,8 +298,6 @@ impl EmscriptenGlobals {
shared: false, shared: false,
}; };
let mut memory = Memory::new(memory_type).unwrap(); let mut memory = Memory::new(memory_type).unwrap();
let vm_memory = memory.vm_local_memory();
let table_type = TableDescriptor { let table_type = TableDescriptor {
element: ElementType::Anyfunc, element: ElementType::Anyfunc,
@ -312,7 +305,6 @@ impl EmscriptenGlobals {
maximum: table_max, maximum: table_max,
}; };
let mut table = Table::new(table_type).unwrap(); let mut table = Table::new(table_type).unwrap();
let vm_table = table.vm_local_table();
let memory_base = STATIC_BASE as u64; let memory_base = STATIC_BASE as u64;
let table_base = 0 as u64; let table_base = 0 as u64;
@ -332,19 +324,13 @@ impl EmscriptenGlobals {
nan: std::f64::NAN.to_bits() as _, nan: std::f64::NAN.to_bits() as _,
}; };
unimplemented!() Self {
data,
// Self { memory,
// data, table,
// memory, memory_min,
// vm_memory, memory_max,
// table, }
// vm_table,
// table_min,
// table_max,
// memory_min,
// memory_max,
// }
} }
} }
@ -361,38 +347,9 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject
// We generate a fake Context that traps on access // We generate a fake Context that traps on access
let null_ctx = Context::External(ptr::null_mut()); let null_ctx = Context::External(ptr::null_mut());
// Memory env_namespace.insert("memory".to_string(), Export::Memory(globals.memory.clone()));
// let local_memory = unsafe { MemoryPointer::new(&mut globals.vm_memory) };
// env_namespace.insert( env_namespace.insert("table".to_string(), Export::Table(globals.table.clone()));
// "memory".to_string(),
// Export::Memory {
// local: local_memory,
// ctx: null_ctx,
// memory: Memory {
// min: globals.memory_min,
// max: globals.memory_max,
// shared: false,
// },
// },
// );
//
// // Table
// let local_table = unsafe { TablePointer::new(&mut globals.vm_table) };
//
// env_namespace.insert(
// "table".to_string(),
// Export::Table {
// local: local_table,
// // We generate a fake Context that traps on access
// ctx: null_ctx,
// table: Table {
// ty: ElementType::Anyfunc,
// min: globals.table_min,
// max: globals.table_max,
// },
// },
// );
// //
// env_namespace.insert( // env_namespace.insert(
// "STACKTOP".to_string(), // "STACKTOP".to_string(),