cargo fmt

This commit is contained in:
Brandon Fish
2019-01-18 00:18:13 -06:00
parent 5e1287d9d9
commit e43c3cb2eb
11 changed files with 59 additions and 59 deletions

View File

@ -8,4 +8,4 @@ fn main() {
if env::var(EMTESTS_ENV_VAR).unwrap_or("0".to_string()) == "1" { if env::var(EMTESTS_ENV_VAR).unwrap_or("0".to_string()) == "1" {
emtests::build(); emtests::build();
} }
} }

View File

@ -1,5 +1,5 @@
use super::process::_abort;
use super::env; use super::env;
use super::process::_abort;
use wasmer_runtime::Instance; use wasmer_runtime::Instance;
/// emscripten: ___cxa_allocate_exception /// emscripten: ___cxa_allocate_exception

View File

@ -1,40 +1,40 @@
use wasmer_runtime::Instance;
use libc::{c_int, c_void}; use libc::{c_int, c_void};
use std::cell::UnsafeCell; use std::cell::UnsafeCell;
use wasmer_runtime::Instance;
/// setjmp /// setjmp
pub extern "C" fn __setjmp(env_addr: u32, instance: &mut Instance) -> c_int { pub extern "C" fn __setjmp(env_addr: u32, instance: &mut Instance) -> c_int {
debug!("emscripten::__setjmp (setjmp)"); debug!("emscripten::__setjmp (setjmp)");
unimplemented!() unimplemented!()
// unsafe { // unsafe {
// // Rather than using the env as the holder of the jump buffer pointer, // // Rather than using the env as the holder of the jump buffer pointer,
// // we use the environment address to store the index relative to jumps // // we use the environment address to store the index relative to jumps
// // so the address of the jump it's outside the wasm memory itself. // // so the address of the jump it's outside the wasm memory itself.
// let jump_index = instance.memory_offset_addr(0, env_addr as usize) as *mut i8; // let jump_index = instance.memory_offset_addr(0, env_addr as usize) as *mut i8;
// // We create the jump buffer outside of the wasm memory // // We create the jump buffer outside of the wasm memory
// let jump_buf: UnsafeCell<[c_int; 27]> = UnsafeCell::new([0; 27]); // let jump_buf: UnsafeCell<[c_int; 27]> = UnsafeCell::new([0; 27]);
// let mut jumps = &mut instance.emscripten_data().as_mut().unwrap().jumps; // let mut jumps = &mut instance.emscripten_data().as_mut().unwrap().jumps;
// let result = setjmp(jump_buf.get() as _); // let result = setjmp(jump_buf.get() as _);
// // We set the jump index to be the last value of jumps // // We set the jump index to be the last value of jumps
// *jump_index = jumps.len() as _; // *jump_index = jumps.len() as _;
// // We hold the reference of the jump buffer // // We hold the reference of the jump buffer
// jumps.push(jump_buf); // jumps.push(jump_buf);
// result // result
// } // }
} }
/// longjmp /// longjmp
pub extern "C" fn __longjmp(env_addr: u32, val: c_int, instance: &mut Instance) -> ! { pub extern "C" fn __longjmp(env_addr: u32, val: c_int, instance: &mut Instance) -> ! {
debug!("emscripten::__longjmp (longjmp) {}", val); debug!("emscripten::__longjmp (longjmp) {}", val);
unimplemented!() unimplemented!()
// unsafe { // unsafe {
// // We retrieve the jump index from the env address // // We retrieve the jump index from the env address
// let jump_index = instance.memory_offset_addr(0, env_addr as usize) as *mut i8; // let jump_index = instance.memory_offset_addr(0, env_addr as usize) as *mut i8;
// let mut jumps = &mut instance.emscripten_data().as_mut().unwrap().jumps; // let mut jumps = &mut instance.emscripten_data().as_mut().unwrap().jumps;
// // We get the real jump buffer from the jumps vector, using the retrieved index // // We get the real jump buffer from the jumps vector, using the retrieved index
// let mut jump_buf = &jumps[*jump_index as usize]; // let mut jump_buf = &jumps[*jump_index as usize];
// longjmp(jump_buf.get() as _, val) // longjmp(jump_buf.get() as _, val)
// }; // };
} }
extern "C" { extern "C" {

View File

@ -1,5 +1,5 @@
use wasmer_runtime::Instance;
use libc::c_int; use libc::c_int;
use wasmer_runtime::Instance;
// NOTE: Not implemented by Emscripten // NOTE: Not implemented by Emscripten
pub extern "C" fn ___lock(which: c_int, varargs: c_int, _instance: &mut Instance) { pub extern "C" fn ___lock(which: c_int, varargs: c_int, _instance: &mut Instance) {

View File

@ -1,6 +1,6 @@
use super::process::abort_with_message; use super::process::abort_with_message;
use wasmer_runtime::Instance;
use libc::{c_int, c_void, memcpy, size_t}; use libc::{c_int, c_void, memcpy, size_t};
use wasmer_runtime::Instance;
/// emscripten: _emscripten_memcpy_big /// emscripten: _emscripten_memcpy_big
pub extern "C" fn _emscripten_memcpy_big( pub extern "C" fn _emscripten_memcpy_big(

View File

@ -1,7 +1,7 @@
use libc::{abort, c_char, c_int, exit, pid_t, EAGAIN}; use libc::{abort, c_char, c_int, exit, pid_t, EAGAIN};
use wasmer_runtime::Instance;
use std::ffi::CStr; use std::ffi::CStr;
use wasmer_runtime::Instance;
pub extern "C" fn abort_with_message(message: &str) { pub extern "C" fn abort_with_message(message: &str) {
debug!("emscripten::abort_with_message"); debug!("emscripten::abort_with_message");

View File

@ -1,6 +1,5 @@
use super::utils::copy_stat_into_wasm; use super::utils::copy_stat_into_wasm;
use super::varargs::VarArgs; use super::varargs::VarArgs;
use wasmer_runtime::Instance;
use byteorder::{ByteOrder, LittleEndian}; use byteorder::{ByteOrder, LittleEndian};
/// NOTE: TODO: These syscalls only support wasm_32 for now because they assume offsets are u32 /// NOTE: TODO: These syscalls only support wasm_32 for now because they assume offsets are u32
/// Syscall list: https://www.cs.utexas.edu/~bismith/test/syscalls/syscalls32.html /// Syscall list: https://www.cs.utexas.edu/~bismith/test/syscalls/syscalls32.html
@ -71,6 +70,7 @@ use libc::{
SO_REUSEADDR, SO_REUSEADDR,
TIOCGWINSZ, TIOCGWINSZ,
}; };
use wasmer_runtime::Instance;
use super::env; use super::env;
use std::mem; use std::mem;

View File

@ -1,4 +1,4 @@
use wasmer_runtime::{Instance, module::Module}; use wasmer_runtime::{module::Module, Instance};
//use wasmer_runtime::Instance; //use wasmer_runtime::Instance;
use super::env; use super::env;
use libc::stat; use libc::stat;
@ -9,12 +9,12 @@ use std::slice;
use std::sync::Arc; use std::sync::Arc;
/// We check if a provided module is an Emscripten generated one /// We check if a provided module is an Emscripten generated one
pub fn is_emscripten_module(module: &Arc<Module>) -> bool { pub fn is_emscripten_module(module: &Arc<Module>) -> bool {
for (_, import_name) in &module.0.imported_functions { for (_, import_name) in &module.0.imported_functions {
if import_name.name == "_emscripten_memcpy_big" && import_name.namespace == "env" { if import_name.name == "_emscripten_memcpy_big" && import_name.namespace == "env" {
return true; return true;
} }
} }
false false
} }
pub unsafe fn write_to_buf(string: *const c_char, buf: u32, max: u32, instance: &Instance) -> u32 { pub unsafe fn write_to_buf(string: *const c_char, buf: u32, max: u32, instance: &Instance) -> u32 {
@ -51,14 +51,14 @@ pub unsafe fn allocate_on_stack<'a, T: Copy>(
instance: &'a Instance, instance: &'a Instance,
) -> (u32, &'a mut [T]) { ) -> (u32, &'a mut [T]) {
unimplemented!("allocate_on_stack not implemented") unimplemented!("allocate_on_stack not implemented")
// let offset = (instance.emscripten_data().as_ref().unwrap().stack_alloc)( // let offset = (instance.emscripten_data().as_ref().unwrap().stack_alloc)(
// count * (size_of::<T>() as u32), // count * (size_of::<T>() as u32),
// instance, // instance,
// ); // );
// let addr = instance.memory_offset_addr(0, offset as _) as *mut T; // let addr = instance.memory_offset_addr(0, offset as _) as *mut T;
// let slice = slice::from_raw_parts_mut(addr, count as usize); // let slice = slice::from_raw_parts_mut(addr, count as usize);
// //
// (offset, slice) // (offset, slice)
} }
pub unsafe fn allocate_cstr_on_stack<'a>(s: &str, instance: &'a Instance) -> (u32, &'a [u8]) { pub unsafe fn allocate_cstr_on_stack<'a>(s: &str, instance: &'a Instance) -> (u32, &'a [u8]) {
@ -142,19 +142,17 @@ pub unsafe fn copy_stat_into_wasm(instance: &mut Instance, buf: u32, stat: &stat
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::is_emscripten_module; use super::is_emscripten_module;
use wasmer_clif_backend::CraneliftCompiler;
use wasmer_runtime::{
compile,
module::Module,
};
use wabt::wat2wasm;
use std::sync::Arc; use std::sync::Arc;
use wabt::wat2wasm;
use wasmer_clif_backend::CraneliftCompiler;
use wasmer_runtime::{compile, module::Module};
#[test] #[test]
fn should_detect_emscripten_files() { fn should_detect_emscripten_files() {
const wast_bytes: &[u8] = include_bytes!("tests/is_emscripten_true.wast"); const wast_bytes: &[u8] = include_bytes!("tests/is_emscripten_true.wast");
let wasm_binary = wat2wasm(wast_bytes.to_vec()).expect("Can't convert to wasm"); let wasm_binary = wat2wasm(wast_bytes.to_vec()).expect("Can't convert to wasm");
let module = compile(&wasm_binary[..], &CraneliftCompiler::new()).expect("WASM can't be compiled"); let module =
compile(&wasm_binary[..], &CraneliftCompiler::new()).expect("WASM can't be compiled");
let module = Arc::new(module); let module = Arc::new(module);
assert!(is_emscripten_module(&module)); assert!(is_emscripten_module(&module));
} }
@ -163,7 +161,8 @@ mod tests {
fn should_detect_non_emscripten_files() { fn should_detect_non_emscripten_files() {
const wast_bytes: &[u8] = include_bytes!("tests/is_emscripten_false.wast"); const wast_bytes: &[u8] = include_bytes!("tests/is_emscripten_false.wast");
let wasm_binary = wat2wasm(wast_bytes.to_vec()).expect("Can't convert to wasm"); let wasm_binary = wat2wasm(wast_bytes.to_vec()).expect("Can't convert to wasm");
let module = compile(&wasm_binary[..], &CraneliftCompiler::new()).expect("WASM can't be compiled"); let module =
compile(&wasm_binary[..], &CraneliftCompiler::new()).expect("WASM can't be compiled");
let module = Arc::new(module); let module = Arc::new(module);
assert!(!is_emscripten_module(&module)); assert!(!is_emscripten_module(&module));
} }

View File

@ -1,5 +1,5 @@
use wasmer_runtime::Instance;
use std::mem; use std::mem;
use wasmer_runtime::Instance;
#[repr(transparent)] #[repr(transparent)]
pub struct VarArgs { pub struct VarArgs {

View File

@ -6,14 +6,14 @@ use std::io;
use std::io::Read; use std::io::Read;
use std::path::PathBuf; use std::path::PathBuf;
use std::process::exit; use std::process::exit;
use std::sync::Arc;
use std::rc::Rc; use std::rc::Rc;
use std::sync::Arc;
use structopt::StructOpt; use structopt::StructOpt;
use wasmer::*; use wasmer::*;
use wasmer_runtime;
use wasmer_emscripten; use wasmer_emscripten;
use wasmer_runtime;
#[derive(Debug, StructOpt)] #[derive(Debug, StructOpt)]
#[structopt(name = "wasmer", about = "WASM execution runtime.")] #[structopt(name = "wasmer", about = "WASM execution runtime.")]
@ -99,7 +99,8 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
debug!("webassembly - creating instance"); debug!("webassembly - creating instance");
let mut instance = module.instantiate(import_object) let mut instance = module
.instantiate(import_object)
.map_err(|err| format!("Can't instantiate the WebAssembly module: {}", err))?; .map_err(|err| format!("Can't instantiate the WebAssembly module: {}", err))?;
webassembly::start_instance( webassembly::start_instance(

View File

@ -6,9 +6,9 @@ pub mod utils;
use wasmer_clif_backend::CraneliftCompiler; use wasmer_clif_backend::CraneliftCompiler;
use wasmer_runtime::{ use wasmer_runtime::{
backend::Compiler, backend::Compiler,
module::{Module, ModuleInner},
import::Imports, import::Imports,
instance::Instance, instance::Instance,
module::{Module, ModuleInner},
}; };
use cranelift_codegen::{ use cranelift_codegen::{
@ -16,9 +16,9 @@ use cranelift_codegen::{
settings::{self, Configurable}, settings::{self, Configurable},
}; };
use std::panic; use std::panic;
use std::rc::Rc;
use std::str::FromStr; use std::str::FromStr;
use std::sync::Arc; use std::sync::Arc;
use std::rc::Rc;
use target_lexicon; use target_lexicon;
use wasmparser; use wasmparser;
use wasmparser::WasmDecoder; use wasmparser::WasmDecoder;