wasmer/lib/emscripten/src/lib.rs

1145 lines
40 KiB
Rust
Raw Normal View History

#[macro_use]
extern crate wasmer_runtime_core;
2019-01-11 05:37:59 +00:00
2019-01-18 05:55:44 +00:00
use byteorder::{ByteOrder, LittleEndian};
use libc::c_int;
use std::cell::UnsafeCell;
2019-01-31 02:03:54 +00:00
use std::{f64, ffi::c_void, fmt, mem, ptr};
use wasmer_runtime_core::{
2019-01-31 01:19:53 +00:00
error::CallResult,
2019-01-30 02:00:08 +00:00
export::{Context, Export, FuncPointer},
func,
global::Global,
2019-01-22 00:42:20 +00:00
import::{ImportObject, Namespace},
2019-01-30 02:00:08 +00:00
imports,
memory::Memory,
2019-01-30 02:00:08 +00:00
table::Table,
2019-01-11 16:10:21 +00:00
types::{
2019-01-31 01:19:53 +00:00
ElementType, FuncSig, GlobalDescriptor, MemoryDescriptor, TableDescriptor,
2019-01-18 05:55:44 +00:00
Type::{self, *},
2019-01-31 01:19:53 +00:00
Value,
2019-01-11 16:10:21 +00:00
},
units::Pages,
2019-01-31 01:19:53 +00:00
vm::Ctx,
2019-01-19 00:36:28 +00:00
vm::LocalGlobal,
2019-01-23 20:25:56 +00:00
vm::LocalMemory,
2019-01-23 20:34:56 +00:00
vm::LocalTable,
2019-01-31 01:19:53 +00:00
Instance, Module,
2019-01-11 16:10:21 +00:00
};
2019-01-18 05:55:44 +00:00
2019-01-22 00:42:20 +00:00
#[macro_use]
mod macros;
2019-01-18 05:55:44 +00:00
//#[cfg(test)]
mod file_descriptor;
pub mod stdio;
2018-11-20 19:11:58 +00:00
// EMSCRIPTEN APIS
2018-11-21 23:10:03 +00:00
mod env;
2018-11-27 04:29:26 +00:00
mod errno;
2018-12-18 17:43:59 +00:00
mod exception;
2018-11-22 04:59:23 +00:00
mod io;
2018-12-19 01:21:12 +00:00
mod jmp;
2019-01-26 23:02:51 +00:00
mod linking;
2018-11-27 04:29:26 +00:00
mod lock;
mod math;
2018-12-18 17:43:59 +00:00
mod memory;
2018-11-27 04:29:26 +00:00
mod nullfunc;
2018-11-20 19:11:58 +00:00
mod process;
2018-11-28 21:25:56 +00:00
mod signal;
2018-11-27 04:29:26 +00:00
mod storage;
2018-11-21 23:10:03 +00:00
mod syscalls;
2018-11-27 04:29:26 +00:00
mod time;
2018-11-22 04:59:23 +00:00
mod utils;
2018-11-23 05:13:01 +00:00
mod varargs;
2018-11-20 19:11:58 +00:00
2018-12-15 06:46:11 +00:00
pub use self::storage::align_memory;
pub use self::utils::{
allocate_cstr_on_stack, allocate_on_stack, get_emscripten_memory_size,
get_emscripten_table_size, is_emscripten_module,
};
// TODO: Magic number - how is this calculated?
const TOTAL_STACK: u32 = 5_242_880;
2018-12-07 02:10:26 +00:00
// TODO: Magic number - how is this calculated?
const DYNAMICTOP_PTR_DIFF: u32 = 1088;
2018-12-07 02:10:26 +00:00
// TODO: make this variable
const STATIC_BUMP: u32 = 215_536;
2019-01-23 20:43:41 +00:00
// The address globals begin at. Very low in memory, for code size and optimization opportunities.
// Above 0 is static memory, starting with globals.
// Then the stack.
// Then 'dynamic' memory for sbrk.
const GLOBAL_BASE: u32 = 1024;
2019-01-31 02:03:54 +00:00
const STATIC_BASE: i32 = GLOBAL_BASE as i32;
2019-01-23 20:43:41 +00:00
fn stacktop(static_bump: u32) -> u32 {
align_memory(dynamictop_ptr(static_bump) + 4)
}
fn stack_max(static_bump: u32) -> u32 {
stacktop(static_bump) + TOTAL_STACK
}
fn dynamic_base(static_bump: u32) -> u32 {
align_memory(stack_max(static_bump))
}
fn dynamictop_ptr(static_bump: u32) -> u32 {
static_bump + DYNAMICTOP_PTR_DIFF
}
pub struct EmscriptenData {
pub malloc: extern "C" fn(i32, &mut Ctx) -> u32,
pub free: extern "C" fn(i32, &mut Ctx),
pub memalign: extern "C" fn(u32, u32, &mut Ctx) -> u32,
pub memset: extern "C" fn(u32, i32, u32, &mut Ctx) -> u32,
pub stack_alloc: extern "C" fn(u32, &mut Ctx) -> u32,
pub jumps: Vec<UnsafeCell<[c_int; 27]>>,
}
impl EmscriptenData {
pub fn new(instance: &mut Instance) -> Self {
unsafe {
let malloc_func = instance.func("_malloc");
let malloc_addr = if let Ok(malloc_func) = malloc_func {
malloc_func.raw() as *const u8
} else {
0 as *const u8
};
let free_func = instance.func("_free");
let free_addr = if let Ok(free_func) = free_func {
free_func.raw() as *const u8
} else {
0 as *const u8
};
let memalign_func = instance.func("_memalign");
let memalign_addr = if let Ok(memalign_func) = memalign_func {
memalign_func.raw() as *const u8
} else {
0 as *const u8
};
let memset_func = instance.func("_memset");
let memset_addr = if let Ok(memset_func) = memset_func {
memset_func.raw() as *const u8
} else {
0 as *const u8
};
let stack_alloc_func = instance.func("stackAlloc");
let stack_alloc_addr = if let Ok(stack_alloc_func) = stack_alloc_func {
stack_alloc_func.raw() as *const u8
} else {
0 as *const u8
};
EmscriptenData {
malloc: mem::transmute(malloc_addr),
free: mem::transmute(free_addr),
memalign: mem::transmute(memalign_addr),
memset: mem::transmute(memset_addr),
stack_alloc: mem::transmute(stack_alloc_addr),
jumps: Vec::new(),
}
}
}
}
2019-01-06 21:21:06 +00:00
2019-01-24 06:17:43 +00:00
impl fmt::Debug for EmscriptenData {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("EmscriptenData")
.field("malloc", &(self.malloc as usize))
.field("free", &(self.free as usize))
.finish()
}
}
pub fn run_emscripten_instance(
2019-01-24 06:00:38 +00:00
_module: &Module,
instance: &mut Instance,
2019-01-26 20:17:17 +00:00
path: &str,
args: Vec<&str>,
) -> CallResult<()> {
let mut data = EmscriptenData::new(instance);
let data_ptr = &mut data as *mut _ as *mut c_void;
instance.context_mut().data = data_ptr;
2019-01-26 20:17:17 +00:00
let main_func = instance.func("_main")?;
let num_params = main_func.signature().params().len();
2019-01-28 01:06:03 +00:00
let _result = match num_params {
2019-01-26 20:17:17 +00:00
2 => {
let (argc, argv) = store_module_arguments(path, args, instance.context_mut());
2019-01-26 20:17:17 +00:00
instance.call("_main", &[Value::I32(argc as i32), Value::I32(argv as i32)])?;
}
0 => {
instance.call("_main", &[])?;
}
_ => panic!(
"The emscripten main function has received an incorrect number of params {}",
num_params
),
};
// TODO atinit and atexit for emscripten
2019-01-24 06:17:43 +00:00
println!("{:?}", data);
Ok(())
}
2019-01-27 18:18:58 +00:00
fn store_module_arguments(path: &str, args: Vec<&str>, ctx: &mut Ctx) -> (u32, u32) {
let argc = args.len() + 1;
let mut args_slice = vec![0; argc];
args_slice[0] = unsafe { allocate_cstr_on_stack(path, ctx).0 };
for (slot, arg) in args_slice[1..argc].iter_mut().zip(args.iter()) {
*slot = unsafe { allocate_cstr_on_stack(&arg, ctx).0 };
}
let (argv_offset, argv_slice): (_, &mut [u32]) =
unsafe { allocate_on_stack(((argc + 1) * 4) as u32, ctx) };
assert!(!argv_slice.is_empty());
for (slot, arg) in argv_slice[0..argc].iter_mut().zip(args_slice.iter()) {
*slot = *arg
}
argv_slice[argc] = 0;
(argc as u32, argv_offset)
}
2019-01-26 20:17:17 +00:00
pub fn emscripten_set_up_memory(memory: &mut Memory) {
let dynamictop_ptr = dynamictop_ptr(STATIC_BUMP) as usize;
2018-11-28 21:29:50 +00:00
let dynamictop_ptr_offset = dynamictop_ptr + mem::size_of::<u32>();
2018-12-07 02:10:26 +00:00
// println!("value = {:?}");
2018-11-28 21:29:50 +00:00
// We avoid failures of setting the u32 in our memory if it's out of bounds
2019-01-30 02:00:08 +00:00
unimplemented!()
// if dynamictop_ptr_offset > memory.len() {
// return; // TODO: We should panic instead?
// }
//
// // debug!("###### dynamic_base = {:?}", dynamic_base(STATIC_BUMP));
// // debug!("###### dynamictop_ptr = {:?}", dynamictop_ptr);
// // debug!("###### dynamictop_ptr_offset = {:?}", dynamictop_ptr_offset);
//
// let mem = &mut memory[dynamictop_ptr..dynamictop_ptr_offset];
// LittleEndian::write_u32(mem, dynamic_base(STATIC_BUMP));
}
macro_rules! mock_external {
2019-01-17 18:55:25 +00:00
($namespace:ident, $name:ident) => {{
2018-11-27 04:29:26 +00:00
extern "C" fn _mocked_fn() -> i32 {
debug!("emscripten::{} <mock>", stringify!($name));
-1
}
2019-01-17 18:55:25 +00:00
$namespace.insert(
stringify!($name),
Export::Function {
2019-01-17 18:55:25 +00:00
func: unsafe { FuncPointer::new(_mocked_fn as _) },
ctx: Context::Internal,
signature: FuncSig {
2018-12-30 10:23:16 +00:00
params: vec![],
returns: vec![I32],
2018-12-30 10:23:16 +00:00
},
},
2018-12-30 10:23:16 +00:00
);
}};
}
2019-01-17 22:10:29 +00:00
macro_rules! global {
2019-01-25 00:45:22 +00:00
($value:expr) => {{
2019-01-17 22:10:29 +00:00
unsafe {
GlobalPointer::new(
// NOTE: Taking a shortcut here. LocalGlobal is a struct containing just u64.
std::mem::transmute::<&u64, *mut LocalGlobal>(&$value),
2019-01-17 22:10:29 +00:00
)
}
}};
}
pub struct EmscriptenGlobalsData {
2019-01-25 05:58:54 +00:00
abort: u64,
// Env namespace
2019-01-25 00:45:22 +00:00
stacktop: u64,
stack_max: u64,
dynamictop_ptr: u64,
memory_base: u64,
table_base: u64,
temp_double_ptr: u64,
// Global namespace
2019-01-25 00:45:22 +00:00
infinity: u64,
nan: u64,
}
pub struct EmscriptenGlobals {
// The emscripten data
pub data: EmscriptenGlobalsData,
2019-01-23 20:25:56 +00:00
// The emscripten memory
pub memory: Memory,
pub table: Table,
pub memory_min: Pages,
pub memory_max: Option<Pages>,
2019-01-11 16:10:21 +00:00
}
2019-01-25 00:46:16 +00:00
impl EmscriptenGlobals {
pub fn new(module: &Module) -> Self {
let (table_min, table_max) = get_emscripten_table_size(&module);
let (memory_min, memory_max) = get_emscripten_memory_size(&module);
2019-01-23 20:34:56 +00:00
// Memory initialization
let memory_type = MemoryDescriptor {
minimum: memory_min,
maximum: memory_max,
2019-01-23 20:25:56 +00:00
shared: false,
};
let mut memory = Memory::new(memory_type).unwrap();
2019-01-23 20:25:56 +00:00
let table_type = TableDescriptor {
element: ElementType::Anyfunc,
minimum: table_min,
maximum: table_max,
2019-01-23 20:34:56 +00:00
};
let mut table = Table::new(table_type).unwrap();
2019-01-23 20:34:56 +00:00
2019-01-25 00:45:22 +00:00
let memory_base = STATIC_BASE as u64;
let table_base = 0 as u64;
let temp_double_ptr = 0 as u64;
let data = EmscriptenGlobalsData {
2019-01-25 05:58:54 +00:00
abort: 0, // TODO review usage
// env
2019-01-25 00:45:22 +00:00
stacktop: stacktop(STATIC_BUMP) as _,
stack_max: stack_max(STATIC_BUMP) as _,
dynamictop_ptr: dynamictop_ptr(STATIC_BUMP) as _,
memory_base: memory_base,
table_base: table_base,
temp_double_ptr: temp_double_ptr,
// global
2019-01-25 00:45:22 +00:00
infinity: std::f64::INFINITY.to_bits() as _,
nan: std::f64::NAN.to_bits() as _,
};
2019-01-17 18:55:25 +00:00
2019-01-31 01:19:53 +00:00
Self {
data,
memory,
table,
memory_min,
memory_max,
}
2019-01-11 16:10:21 +00:00
}
}
2019-01-23 20:25:56 +00:00
pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject {
let mut imports = ImportObject::new();
2019-01-22 00:42:20 +00:00
let mut env_namespace = Namespace::new();
let mut asm_namespace = Namespace::new();
let mut global_namespace = Namespace::new();
2019-01-23 18:54:03 +00:00
let mut global_math_namespace = Namespace::new();
2019-01-11 16:10:21 +00:00
// Add globals.
2019-01-17 22:10:29 +00:00
// NOTE: There is really no need for checks, these globals should always be available.
2019-01-23 20:34:56 +00:00
// We generate a fake Context that traps on access
let null_ctx = Context::External(ptr::null_mut());
2019-01-23 20:25:56 +00:00
2019-01-31 02:03:54 +00:00
// env_namespace.insert("memory".to_string(), Export::Memory(globals.memory.clone()));
// env_namespace.insert("table".to_string(), Export::Table(globals.table.clone()));
let import_object = imports! {
"env" => {
"memory" => Export::Memory(globals.memory.clone()),
"table" => Export::Table(globals.table.clone()),
// Globals
"STACKTOP" => Global::new(Value::I32(stacktop(STATIC_BUMP) as i32)),
"STACK_MAX" => Global::new(Value::I32(stack_max(STATIC_BUMP) as i32)),
"DYNAMICTOP_PTR" => Global::new(Value::I32(dynamictop_ptr(STATIC_BUMP) as i32)),
"tableBase" => Global::new(Value::I32(0)),
"__table_base" => Global::new(Value::I32(0)),
"Infinity" => Global::new(Value::F64(f64::INFINITY)),
"NaN" => Global::new(Value::F64(f64::NAN)),
"ABORT" => Global::new(Value::I32(0)),
"memoryBase" => Global::new(Value::I32(STATIC_BASE)),
"__memory_base" => Global::new(Value::I32(STATIC_BASE)),
"tempDoublePtr" => Global::new(Value::I32(0)),
// IO
"printf" => func!(crate::io::printf, [i32, i32] -> [i32]),
"putchar" => func!(crate::io::putchar, [i32] -> []),
"___lock" => func!(crate::lock::___lock, [i32] -> []),
"___unlock" => func!(crate::lock::___unlock, [i32] -> []),
"___wait" => func!(crate::lock::___wait, [u32, u32, u32, u32] -> []),
// Env
"___assert_fail" => func!(crate::env::___assert_fail, [i32, i32, i32, i32] -> []),
"_getenv" => func!(crate::env::_getenv, [i32] -> [u32]),
"_setenv" => func!(crate::env::_setenv, [i32, i32, i32] -> [i32]),
"_putenv" => func!(crate::env::_putenv, [i32] -> [i32]),
"_unsetenv" => func!(crate::env::_unsetenv, [i32] -> [i32]),
"_getpwnam" => func!(crate::env::_getpwnam, [i32] -> [i32]),
"_getgrnam" => func!(crate::env::_getgrnam, [i32] -> [i32]),
"___buildEnvironment" => func!(crate::env::___build_environment, [i32] -> []),
"___setErrNo" => func!(crate::errno::___seterrno, [i32] -> []),
// Null func
"nullFunc_i" => func!(crate::nullfunc::nullfunc_i, [u32] -> []),
"nullFunc_ii" => func!(crate::nullfunc::nullfunc_ii, [u32] -> []),
"nullFunc_iii" => func!(crate::nullfunc::nullfunc_iii, [u32] -> []),
"nullFunc_iiii" => func!(crate::nullfunc::nullfunc_iiii, [u32] -> []),
"nullFunc_iiiii" => func!(crate::nullfunc::nullfunc_iiiii, [u32] -> []),
"nullFunc_iiiiii" => func!(crate::nullfunc::nullfunc_iiiiii, [u32] -> []),
"nullFunc_v" => func!(crate::nullfunc::nullfunc_v, [u32] -> []),
"nullFunc_vi" => func!(crate::nullfunc::nullfunc_vi, [u32] -> []),
"nullFunc_vii" => func!(crate::nullfunc::nullfunc_vii, [u32] -> []),
"nullFunc_viii" => func!(crate::nullfunc::nullfunc_viii, [u32] -> []),
"nullFunc_viiii" => func!(crate::nullfunc::nullfunc_viiii, [u32] -> []),
"nullFunc_viiiii" => func!(crate::nullfunc::nullfunc_viiiii, [u32] -> []),
"nullFunc_viiiiii" => func!(crate::nullfunc::nullfunc_viiiiii, [u32] -> []),
// Syscalls
"___syscall1" => func!(crate::syscalls::___syscall1, [i32, i32] -> []),
"___syscall3" => func!(crate::syscalls::___syscall3, [i32, i32] -> [i32]),
"___syscall4" => func!(crate::syscalls::___syscall4, [i32, i32] -> [i32]),
"___syscall5" => func!(crate::syscalls::___syscall5, [i32, i32] -> [i32]),
"___syscall6" => func!(crate::syscalls::___syscall6, [i32, i32] -> [i32]),
"___syscall12" => func!(crate::syscalls::___syscall12, [i32, i32] -> [i32]),
"___syscall20" => func!(crate::syscalls::___syscall20, [i32, i32] -> [i32]),
"___syscall220" => func!(crate::syscalls::___syscall220, [i32, i32] -> [i32]),
"___syscall39" => func!(crate::syscalls::___syscall39, [i32, i32] -> [i32]),
"___syscall40" => func!(crate::syscalls::___syscall40, [i32, i32] -> [i32]),
"___syscall10" => func!(crate::syscalls::___syscall10, [i32, i32] -> [i32]),
"___syscall54" => func!(crate::syscalls::___syscall54, [i32, i32] -> [i32]),
"___syscall57" => func!(crate::syscalls::___syscall57, [i32, i32] -> [i32]),
"___syscall63" => func!(crate::syscalls::___syscall63, [i32, i32] -> [i32]),
"___syscall85" => func!(crate::syscalls::___syscall85, [i32, i32] -> [i32]),
"___syscall64" => func!(crate::syscalls::___syscall64, [i32, i32] -> [i32]),
"___syscall102" => func!(crate::syscalls::___syscall102, [i32, i32] -> [i32]),
"___syscall114" => func!(crate::syscalls::___syscall114, [i32, i32] -> [i32]),
"___syscall122" => func!(crate::syscalls::___syscall122, [i32, i32] -> [i32]),
"___syscall140" => func!(crate::syscalls::___syscall140, [i32, i32] -> [i32]),
"___syscall142" => func!(crate::syscalls::___syscall142, [i32, i32] -> [i32]),
"___syscall145" => func!(crate::syscalls::___syscall145, [i32, i32] -> [i32]),
"___syscall146" => func!(crate::syscalls::___syscall146, [i32, i32] -> [i32]),
"___syscall180" => func!(crate::syscalls::___syscall180, [i32, i32] -> [i32]),
"___syscall181" => func!(crate::syscalls::___syscall181, [i32, i32] -> [i32]),
"___syscall192" => func!(crate::syscalls::___syscall192, [i32, i32] -> [i32]),
"___syscall195" => func!(crate::syscalls::___syscall195, [i32, i32] -> [i32]),
"___syscall197" => func!(crate::syscalls::___syscall197, [i32, i32] -> [i32]),
"___syscall201" => func!(crate::syscalls::___syscall201, [i32, i32] -> [i32]),
"___syscall202" => func!(crate::syscalls::___syscall202, [i32, i32] -> [i32]),
"___syscall212" => func!(crate::syscalls::___syscall212, [i32, i32] -> [i32]),
"___syscall221" => func!(crate::syscalls::___syscall221, [i32, i32] -> [i32]),
"___syscall330" => func!(crate::syscalls::___syscall330, [i32, i32] -> [i32]),
"___syscall340" => func!(crate::syscalls::___syscall340, [i32, i32] -> [i32]),
// Process
"abort" => func!(crate::process::em_abort, [u32] -> []),
"_abort" => func!(crate::process::_abort, [] -> []),
"abortStackOverflow" => func!(crate::process::abort_stack_overflow, [i32] -> []),
"_llvm_trap" => func!(crate::process::_llvm_trap, [] -> []),
"_fork" => func!(crate::process::_fork, [] -> [i32]),
"_exit" => func!(crate::process::_exit, [i32] -> []),
"_system" => func!(crate::process::_system, [i32] -> [i32]),
"_popen" => func!(crate::process::_popen, [i32, i32] -> [i32]),
// Signal
"_sigemptyset" => func!(crate::signal::_sigemptyset, [u32] -> [i32]),
"_sigaddset" => func!(crate::signal::_sigaddset, [u32, u32] -> [i32]),
"_sigprocmask" => func!(crate::signal::_sigprocmask, [i32, i32, i32] -> [i32]),
"_sigaction" => func!(crate::signal::_sigaction, [u32, u32, u32] -> [i32]),
"_signal" => func!(crate::signal::_signal, [u32, i32] -> [i32]),
// Memory
"abortOnCannotGrowMemory" => func!(crate::memory::abort_on_cannot_grow_memory, [] -> [u32]),
"_emscripten_memcpy_big" => func!(crate::memory::_emscripten_memcpy_big, [u32, u32, u32] -> [u32]),
2019-01-31 23:01:42 +00:00
"enlargeMemory" => func!(crate::memory::enlarge_memory, [] -> [u32]),
"getTotalMemory" => func!(crate::memory::get_total_memory, [] -> [u32]),
"___map_file" => func!(crate::memory::___map_file, [u32, u32] -> [i32]),
// Exception
"___cxa_allocate_exception" => func!(crate::exception::___cxa_allocate_exception, [u32] -> [u32]),
"___cxa_throw" => func!(crate::exception::___cxa_throw, [u32, u32, u32] -> []),
// Time
"_gettimeofday" => func!(crate::time::_gettimeofday, [i32, i32] -> [i32]),
"_clock_gettime" => func!(crate::time::_clock_gettime, [u32, i32] -> [i32]),
"___clock_gettime" => func!(crate::time::_clock_gettime, [u32, i32] -> [i32]),
"_clock" => func!(crate::time::_clock, [] -> [i32]),
"_difftime" => func!(crate::time::_difftime, [u32, u32] -> [f64]),
"_asctime" => func!(crate::time::_asctime, [u32] -> [u32]),
"_asctime_r" => func!(crate::time::_asctime_r, [u32, u32] -> [u32]),
"_localtime" => func!(crate::time::_localtime, [u32] -> [i32]),
"_time" => func!(crate::time::_time, [u32] -> [i64]),
"_strftime" => func!(crate::time::_strftime, [i32, u32, i32, i32] -> [i64]),
"_localtime_r" => func!(crate::time::_localtime_r, [u32, u32] -> [i32]),
},
"math" => {
"pow" => func!(crate::math::pow, [f64, f64] -> [f64]),
},
};
2019-01-31 01:19:53 +00:00
//
// env_namespace.insert(
// "_getpagesize",
// Export::Function {
// func: func!(env, _getpagesize),
// ctx: Context::Internal,
// signature: FuncSig {
// params: vec![],
// returns: vec![I32],
// },
// },
// );
//
// env_namespace.insert(
// "_sysconf",
// Export::Function {
// func: func!(env, _sysconf),
// ctx: Context::Internal,
// signature: FuncSig {
// params: vec![I32],
// returns: vec![I32],
// },
// },
// );
//
// // Math
// asm_namespace.insert(
// "f64-rem",
// Export::Function {
// func: func!(math, f64_rem),
// ctx: Context::Internal,
// signature: FuncSig {
// params: vec![F64, F64],
// returns: vec![F64],
// },
// },
// );
//
// env_namespace.insert(
// "_llvm_log10_f64",
// Export::Function {
// func: func!(math, _llvm_log10_f64),
// ctx: Context::Internal,
// signature: FuncSig {
// params: vec![F64],
// returns: vec![F64],
// },
// },
// );
//
// env_namespace.insert(
// "_llvm_log2_f64",
// Export::Function {
// func: func!(math, _llvm_log2_f64),
// ctx: Context::Internal,
// signature: FuncSig {
// params: vec![F64],
// returns: vec![F64],
// },
// },
// );
//
// //
// env_namespace.insert(
// "__setjmp",
// Export::Function {
// func: func!(jmp, __setjmp),
// ctx: Context::Internal,
// signature: FuncSig {
// params: vec![I32],
// returns: vec![I32],
// },
// },
// );
//
// env_namespace.insert(
// "__longjmp",
// Export::Function {
// func: func!(jmp, __longjmp),
// ctx: Context::Internal,
// signature: FuncSig {
// params: vec![I32, I32],
// returns: vec![],
// },
// },
// );
//
// env_namespace.insert(
// "___syscall110",
// Export::Function {
// func: func!(syscalls, ___syscall110),
// ctx: Context::Internal,
// signature: FuncSig {
// params: vec![I32, I32],
// returns: vec![I32],
// },
// },
// );
//
// env_namespace.insert(
// "___syscall15",
// Export::Function {
// func: func!(syscalls, ___syscall15),
// ctx: Context::Internal,
// signature: FuncSig {
// params: vec![I32, I32],
// returns: vec![I32],
// },
// },
// );
//
// env_namespace.insert(
// "___syscall168",
// Export::Function {
// func: func!(syscalls, ___syscall168),
// ctx: Context::Internal,
// signature: FuncSig {
// params: vec![I32, I32],
// returns: vec![I32],
// },
// },
// );
//
// env_namespace.insert(
// "___syscall191",
// Export::Function {
// func: func!(syscalls, ___syscall191),
// ctx: Context::Internal,
// signature: FuncSig {
// params: vec![I32, I32],
// returns: vec![I32],
// },
// },
// );
// env_namespace.insert(
// "___syscall194",
// Export::Function {
// func: func!(syscalls, ___syscall194),
// ctx: Context::Internal,
// signature: FuncSig {
// params: vec![I32, I32],
// returns: vec![I32],
// },
// },
// );
// env_namespace.insert(
// "___syscall196",
// Export::Function {
// func: func!(syscalls, ___syscall196),
// ctx: Context::Internal,
// signature: FuncSig {
// params: vec![I32, I32],
// returns: vec![I32],
// },
// },
// );
// env_namespace.insert(
// "___syscall199",
// Export::Function {
// func: func!(syscalls, ___syscall199),
// ctx: Context::Internal,
// signature: FuncSig {
// params: vec![I32, I32],
// returns: vec![I32],
// },
// },
// );
//
// env_namespace.insert(
// "___syscall268",
// Export::Function {
// func: func!(syscalls, ___syscall268),
// ctx: Context::Internal,
// signature: FuncSig {
// params: vec![I32, I32],
// returns: vec![I32],
// },
// },
// );
//
// env_namespace.insert(
// "___syscall272",
// Export::Function {
// func: func!(syscalls, ___syscall272),
// ctx: Context::Internal,
// signature: FuncSig {
// params: vec![I32, I32],
// returns: vec![I32],
// },
// },
// );
//
// env_namespace.insert(
// "___syscall295",
// Export::Function {
// func: func!(syscalls, ___syscall295),
// ctx: Context::Internal,
// signature: FuncSig {
// params: vec![I32, I32],
// returns: vec![I32],
// },
// },
// );
//
// env_namespace.insert(
// "___syscall300",
// Export::Function {
// func: func!(syscalls, ___syscall300),
// ctx: Context::Internal,
// signature: FuncSig {
// params: vec![I32, I32],
// returns: vec![I32],
// },
// },
// );
//
// env_namespace.insert(
// "___syscall334",
// Export::Function {
// func: func!(syscalls, ___syscall334),
// ctx: Context::Internal,
// signature: FuncSig {
// params: vec![I32, I32],
// returns: vec![I32],
// },
// },
// );
//
// env_namespace.insert(
// "___syscall38",
// Export::Function {
// func: func!(syscalls, ___syscall38),
// ctx: Context::Internal,
// signature: FuncSig {
// params: vec![I32, I32],
// returns: vec![I32],
// },
// },
// );
//
// env_namespace.insert(
// "___syscall60",
// Export::Function {
// func: func!(syscalls, ___syscall60),
// ctx: Context::Internal,
// signature: FuncSig {
// params: vec![I32, I32],
// returns: vec![I32],
// },
// },
// );
//
// env_namespace.insert(
// "___syscall66",
// Export::Function {
// func: func!(syscalls, ___syscall66),
// ctx: Context::Internal,
// signature: FuncSig {
// params: vec![I32, I32],
// returns: vec![I32],
// },
// },
// );
//
// env_namespace.insert(
// "___syscall75",
// Export::Function {
// func: func!(syscalls, ___syscall75),
// ctx: Context::Internal,
// signature: FuncSig {
// params: vec![I32, I32],
// returns: vec![I32],
// },
// },
// );
//
// env_namespace.insert(
// "___syscall91",
// Export::Function {
// func: func!(syscalls, ___syscall91),
// ctx: Context::Internal,
// signature: FuncSig {
// params: vec![I32, I32],
// returns: vec![I32],
// },
// },
// );
//
// env_namespace.insert(
// "___syscall97",
// Export::Function {
// func: func!(syscalls, ___syscall97),
// ctx: Context::Internal,
// signature: FuncSig {
// params: vec![I32, I32],
// returns: vec![I32],
// },
// },
// );
//
// env_namespace.insert(
// "_endgrent",
// Export::Function {
// func: func!(process, _endgrent),
// ctx: Context::Internal,
// signature: FuncSig {
// params: vec![],
// returns: vec![],
// },
// },
// );
//
// env_namespace.insert(
// "_execve",
// Export::Function {
// func: func!(process, _execve),
// ctx: Context::Internal,
// signature: FuncSig {
// params: vec![I32, I32, I32],
// returns: vec![I32],
// },
// },
// );
//
// env_namespace.insert(
// "_getaddrinfo",
// Export::Function {
// func: func!(env, _getaddrinfo),
// ctx: Context::Internal,
// signature: FuncSig {
// params: vec![I32, I32, I32, I32],
// returns: vec![I32],
// },
// },
// );
//
// env_namespace.insert(
// "_gmtime_r",
// Export::Function {
// func: func!(time, _gmtime_r),
// ctx: Context::Internal,
// signature: FuncSig {
// params: vec![I32, I32],
// returns: vec![I32],
// },
// },
// );
//
// env_namespace.insert(
// "_kill",
// Export::Function {
// func: func!(process, _kill),
// ctx: Context::Internal,
// signature: FuncSig {
// params: vec![I32, I32],
// returns: vec![I32],
// },
// },
// );
//
// env_namespace.insert(
// "_llvm_stackrestore",
// Export::Function {
// func: func!(process, _llvm_stackrestore),
// ctx: Context::Internal,
// signature: FuncSig {
// params: vec![I32],
// returns: vec![],
// },
// },
// );
//
// env_namespace.insert(
// "_mktime",
// Export::Function {
// func: func!(time, _mktime),
// ctx: Context::Internal,
// signature: FuncSig {
// params: vec![I32],
// returns: vec![I32],
// },
// },
// );
//
// env_namespace.insert(
// "_raise",
// Export::Function {
// func: func!(process, _raise),
// ctx: Context::Internal,
// signature: FuncSig {
// params: vec![I32],
// returns: vec![I32],
// },
// },
// );
//
// env_namespace.insert(
// "_sem_init",
// Export::Function {
// func: func!(process, _sem_init),
// ctx: Context::Internal,
// signature: FuncSig {
// params: vec![I32, I32, I32],
// returns: vec![I32],
// },
// },
// );
//
// env_namespace.insert(
// "_sem_post",
// Export::Function {
// func: func!(process, _sem_post),
// ctx: Context::Internal,
// signature: FuncSig {
// params: vec![I32],
// returns: vec![I32],
// },
// },
// );
//
// env_namespace.insert(
// "_sem_wait",
// Export::Function {
// func: func!(process, _sem_wait),
// ctx: Context::Internal,
// signature: FuncSig {
// params: vec![I32],
// returns: vec![I32],
// },
// },
// );
//
// env_namespace.insert(
// "_setgrent",
// Export::Function {
// func: func!(process, _setgrent),
// ctx: Context::Internal,
// signature: FuncSig {
// params: vec![],
// returns: vec![],
// },
// },
// );
//
// env_namespace.insert(
// "_setgroups",
// Export::Function {
// func: func!(process, _setgroups),
// ctx: Context::Internal,
// signature: FuncSig {
// params: vec![I32, I32],
// returns: vec![I32],
// },
// },
// );
//
// env_namespace.insert(
// "_setitimer",
// Export::Function {
// func: func!(process, _setitimer),
// ctx: Context::Internal,
// signature: FuncSig {
// params: vec![I32, I32, I32],
// returns: vec![I32],
// },
// },
// );
//
// //
// env_namespace.insert(
// "_sigsuspend",
// Export::Function {
// func: func!(signal, _sigsuspend),
// ctx: Context::Internal,
// signature: FuncSig {
// params: vec![I32],
// returns: vec![I32],
// },
// },
// );
//
// env_namespace.insert(
// "_setitimer",
// Export::Function {
// func: func!(process, _setitimer),
// ctx: Context::Internal,
// signature: FuncSig {
// params: vec![I32, I32, I32],
// returns: vec![I32],
// },
// },
// );
//
// env_namespace.insert(
// "_usleep",
// Export::Function {
// func: func!(process, _usleep),
// ctx: Context::Internal,
// signature: FuncSig {
// params: vec![I32],
// returns: vec![I32],
// },
// },
// );
//
// env_namespace.insert(
// "_utimes",
// Export::Function {
// func: func!(process, _utimes),
// ctx: Context::Internal,
// signature: FuncSig {
// params: vec![I32, I32],
// returns: vec![I32],
// },
// },
// );
//
// env_namespace.insert(
// "_waitpid",
// Export::Function {
// func: func!(process, _waitpid),
// ctx: Context::Internal,
// signature: FuncSig {
// params: vec![I32, I32, I32],
// returns: vec![I32],
// },
// },
// );
//
// env_namespace.insert(
// "_dlclose",
// Export::Function {
// func: func!(linking, _dlclose),
// ctx: Context::Internal,
// signature: FuncSig {
// params: vec![I32],
// returns: vec![I32],
// },
// },
// );
//
// env_namespace.insert(
// "_dlopen",
// Export::Function {
// func: func!(linking, _dlopen),
// ctx: Context::Internal,
// signature: FuncSig {
// params: vec![I32, I32],
// returns: vec![I32],
// },
// },
// );
//
// env_namespace.insert(
// "_dlsym",
// Export::Function {
// func: func!(linking, _dlsym),
// ctx: Context::Internal,
// signature: FuncSig {
// params: vec![I32, I32],
// returns: vec![I32],
// },
// },
// );
//
// env_namespace.insert(
// "_llvm_log10_f32",
// Export::Function {
// func: func!(math, _llvm_log10_f32),
// ctx: Context::Internal,
// signature: FuncSig {
// params: vec![F64],
// returns: vec![F64],
// },
// },
// );
//
// env_namespace.insert(
// "_llvm_log2_f32",
// Export::Function {
// func: func!(math, _llvm_log2_f32),
// ctx: Context::Internal,
// signature: FuncSig {
// params: vec![F64],
// returns: vec![F64],
// },
// },
// );
//
// env_namespace.insert(
// "_emscripten_random",
// Export::Function {
// func: func!(math, _emscripten_random),
// ctx: Context::Internal,
// signature: FuncSig {
// params: vec![],
// returns: vec![F64],
// },
// },
// );
//
// env_namespace.insert(
// "_gmtime",
// Export::Function {
// func: func!(time, _gmtime),
// ctx: Context::Internal,
// signature: FuncSig {
// params: vec![I32],
// returns: vec![I32],
// },
// },
// );
//
// // mock_external!(env_namespace, _time);
// // mock_external!(env_namespace, _sysconf);
// // mock_external!(env_namespace, _strftime);
// // mock_external!(env_namespace, _sigprocmask);
// // mock_external!(env_namespace, _sigemptyset);
// // mock_external!(env_namespace, _sigaddset);
// // mock_external!(env_namespace, _sigaction);
//
// mock_external!(env_namespace, _sched_yield);
// // mock_external!(env_namespace, _localtime_r);
// // mock_external!(env_namespace, _localtime);
// mock_external!(env_namespace, _llvm_stacksave);
// // mock_external!(env_namespace, _gettimeofday);
// // mock_external!(env_namespace, _getpagesize);
// mock_external!(env_namespace, _getgrent);
// // mock_external!(env_namespace, _fork);
// // mock_external!(env_namespace, _exit);
// // mock_external!(env_namespace, _clock_gettime);
// // mock_external!(env_namespace, ___syscall64);
// // mock_external!(env_namespace, ___syscall63);
// // mock_external!(env_namespace, ___syscall60);
// // mock_external!(env_namespace, ___syscall54);
// // mock_external!(env_namespace, ___syscall39);
// // mock_external!(env_namespace, ___syscall340);
// // mock_external!(env_namespace, ___syscall221);
// // mock_external!(env_namespace, ___syscall212);
// // mock_external!(env_namespace, ___syscall201);
// // mock_external!(env_namespace, ___syscall197);
// // mock_external!(env_namespace, ___syscall195);
// // mock_external!(env_namespace, ___syscall181);
// // mock_external!(env_namespace, ___syscall180);
// // mock_external!(env_namespace, ___syscall146);
// // mock_external!(env_namespace, ___syscall145);
// // mock_external!(env_namespace, ___syscall142);
// // mock_external!(env_namespace, ___syscall140);
// // mock_external!(env_namespace, ___syscall122);
// // mock_external!(env_namespace, ___syscall102);
// // mock_external!(env_namespace, ___syscall20);
// mock_external!(env_namespace, _dlerror);
// mock_external!(env_namespace, _gmtime);
2019-01-17 18:55:25 +00:00
imports.register("env", env_namespace);
imports.register("asm2wasm", asm_namespace);
2019-01-23 18:54:03 +00:00
imports.register("global", global_namespace);
imports.register("global.Math", global_math_namespace);
2018-11-26 06:17:33 +00:00
imports
}
/// The current version of this crate
pub const VERSION: &str = env!("CARGO_PKG_VERSION");