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

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

View File

@ -1,40 +1,40 @@
use wasmer_runtime::Instance;
use libc::{c_int, c_void};
use std::cell::UnsafeCell;
use wasmer_runtime::Instance;
/// setjmp
pub extern "C" fn __setjmp(env_addr: u32, instance: &mut Instance) -> c_int {
debug!("emscripten::__setjmp (setjmp)");
unimplemented!()
// unsafe {
// // 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
// // 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;
// // We create the jump buffer outside of the wasm memory
// let jump_buf: UnsafeCell<[c_int; 27]> = UnsafeCell::new([0; 27]);
// let mut jumps = &mut instance.emscripten_data().as_mut().unwrap().jumps;
// let result = setjmp(jump_buf.get() as _);
// // We set the jump index to be the last value of jumps
// *jump_index = jumps.len() as _;
// // We hold the reference of the jump buffer
// jumps.push(jump_buf);
// result
// }
// unsafe {
// // 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
// // 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;
// // We create the jump buffer outside of the wasm memory
// let jump_buf: UnsafeCell<[c_int; 27]> = UnsafeCell::new([0; 27]);
// let mut jumps = &mut instance.emscripten_data().as_mut().unwrap().jumps;
// let result = setjmp(jump_buf.get() as _);
// // We set the jump index to be the last value of jumps
// *jump_index = jumps.len() as _;
// // We hold the reference of the jump buffer
// jumps.push(jump_buf);
// result
// }
}
/// longjmp
pub extern "C" fn __longjmp(env_addr: u32, val: c_int, instance: &mut Instance) -> ! {
debug!("emscripten::__longjmp (longjmp) {}", val);
unimplemented!()
// unsafe {
// // 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 mut jumps = &mut instance.emscripten_data().as_mut().unwrap().jumps;
// // We get the real jump buffer from the jumps vector, using the retrieved index
// let mut jump_buf = &jumps[*jump_index as usize];
// longjmp(jump_buf.get() as _, val)
// };
// unsafe {
// // 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 mut jumps = &mut instance.emscripten_data().as_mut().unwrap().jumps;
// // We get the real jump buffer from the jumps vector, using the retrieved index
// let mut jump_buf = &jumps[*jump_index as usize];
// longjmp(jump_buf.get() as _, val)
// };
}
extern "C" {

View File

@ -1,5 +1,5 @@
use wasmer_runtime::Instance;
use libc::c_int;
use wasmer_runtime::Instance;
// NOTE: Not implemented by Emscripten
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 wasmer_runtime::Instance;
use libc::{c_int, c_void, memcpy, size_t};
use wasmer_runtime::Instance;
/// emscripten: _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 wasmer_runtime::Instance;
use std::ffi::CStr;
use wasmer_runtime::Instance;
pub extern "C" fn abort_with_message(message: &str) {
debug!("emscripten::abort_with_message");

View File

@ -1,6 +1,5 @@
use super::utils::copy_stat_into_wasm;
use super::varargs::VarArgs;
use wasmer_runtime::Instance;
use byteorder::{ByteOrder, LittleEndian};
/// 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
@ -71,6 +70,7 @@ use libc::{
SO_REUSEADDR,
TIOCGWINSZ,
};
use wasmer_runtime::Instance;
use super::env;
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 super::env;
use libc::stat;
@ -9,12 +9,12 @@ use std::slice;
use std::sync::Arc;
/// We check if a provided module is an Emscripten generated one
pub fn is_emscripten_module(module: &Arc<Module>) -> bool {
for (_, import_name) in &module.0.imported_functions {
if import_name.name == "_emscripten_memcpy_big" && import_name.namespace == "env" {
return true;
}
}
false
for (_, import_name) in &module.0.imported_functions {
if import_name.name == "_emscripten_memcpy_big" && import_name.namespace == "env" {
return true;
}
}
false
}
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,
) -> (u32, &'a mut [T]) {
unimplemented!("allocate_on_stack not implemented")
// let offset = (instance.emscripten_data().as_ref().unwrap().stack_alloc)(
// count * (size_of::<T>() as u32),
// instance,
// );
// let addr = instance.memory_offset_addr(0, offset as _) as *mut T;
// let slice = slice::from_raw_parts_mut(addr, count as usize);
//
// (offset, slice)
// let offset = (instance.emscripten_data().as_ref().unwrap().stack_alloc)(
// count * (size_of::<T>() as u32),
// instance,
// );
// let addr = instance.memory_offset_addr(0, offset as _) as *mut T;
// let slice = slice::from_raw_parts_mut(addr, count as usize);
//
// (offset, slice)
}
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)]
mod tests {
use super::is_emscripten_module;
use wasmer_clif_backend::CraneliftCompiler;
use wasmer_runtime::{
compile,
module::Module,
};
use wabt::wat2wasm;
use std::sync::Arc;
use wabt::wat2wasm;
use wasmer_clif_backend::CraneliftCompiler;
use wasmer_runtime::{compile, module::Module};
#[test]
fn should_detect_emscripten_files() {
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 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);
assert!(is_emscripten_module(&module));
}
@ -163,7 +161,8 @@ mod tests {
fn should_detect_non_emscripten_files() {
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 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);
assert!(!is_emscripten_module(&module));
}

View File

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