Formatted files

This commit is contained in:
Syrus Akbary 2018-11-28 13:25:56 -08:00
parent 02477b6e5e
commit 80ddc759a1
9 changed files with 83 additions and 73 deletions

View File

@ -44,8 +44,10 @@ pub extern "C" fn _getpwnam(name_ptr: c_int, instance: &mut Instance) -> c_int {
unsafe {
let passwd = &*libc_getpwnam(name.as_ptr());
let passwd_struct_offset =
(instance.emscripten_data.as_ref().unwrap().malloc)(mem::size_of::<GuestPasswd>() as _, instance);
let passwd_struct_offset = (instance.emscripten_data.as_ref().unwrap().malloc)(
mem::size_of::<GuestPasswd>() as _,
instance,
);
let passwd_struct_ptr =
instance.memory_offset_addr(0, passwd_struct_offset as _) as *mut GuestPasswd;
@ -79,8 +81,10 @@ pub extern "C" fn _getgrnam(name_ptr: c_int, instance: &mut Instance) -> c_int {
unsafe {
let group = &*libc_getgrnam(name.as_ptr());
let group_struct_offset =
(instance.emscripten_data.as_ref().unwrap().malloc)(mem::size_of::<GuestGroup>() as _, instance);
let group_struct_offset = (instance.emscripten_data.as_ref().unwrap().malloc)(
mem::size_of::<GuestGroup>() as _,
instance,
);
let group_struct_ptr =
instance.memory_offset_addr(0, group_struct_offset as _) as *mut GuestGroup;

View File

@ -11,11 +11,11 @@ mod lock;
mod memory;
mod nullfunc;
mod process;
mod signal;
mod storage;
mod syscalls;
mod time;
mod utils;
mod signal;
mod varargs;
pub use self::storage::{align_memory, static_alloc};
@ -108,28 +108,12 @@ pub fn generate_emscripten_env<'a, 'b>() -> ImportObject<&'a str, &'b str> {
// Print functions
import_object.set("env", "printf", ImportValue::Func(io::printf as _));
import_object.set(
"env",
"putchar",
ImportValue::Func(io::putchar as _),
);
import_object.set("env", "putchar", ImportValue::Func(io::putchar as _));
// Lock
import_object.set(
"env",
"___lock",
ImportValue::Func(lock::___lock as _),
);
import_object.set(
"env",
"___unlock",
ImportValue::Func(lock::___unlock as _),
);
import_object.set("env", "___lock", ImportValue::Func(lock::___lock as _));
import_object.set("env", "___unlock", ImportValue::Func(lock::___unlock as _));
// Env
import_object.set(
"env",
"_getenv",
ImportValue::Func(env::_getenv as _),
);
import_object.set("env", "_getenv", ImportValue::Func(env::_getenv as _));
import_object.set("env", "_getpwnam", ImportValue::Func(env::_getpwnam as _));
import_object.set("env", "_getgrnam", ImportValue::Func(env::_getgrnam as _));
// Errno
@ -281,16 +265,8 @@ pub fn generate_emscripten_env<'a, 'b>() -> ImportObject<&'a str, &'b str> {
);
// Process
import_object.set(
"env",
"abort",
ImportValue::Func(process::em_abort as _),
);
import_object.set(
"env",
"_abort",
ImportValue::Func(process::_abort as _),
);
import_object.set("env", "abort", ImportValue::Func(process::em_abort as _));
import_object.set("env", "_abort", ImportValue::Func(process::_abort as _));
import_object.set(
"env",
"abortStackOverflow",

View File

@ -12,6 +12,7 @@ use libc::{
// fcntl, ioctl, setsockopt, getppid
close,
connect,
dup2,
exit,
fstat,
getgid,
@ -36,6 +37,7 @@ use libc::{
recvmsg,
sendmsg,
sendto,
setsockopt,
sockaddr,
socket,
socklen_t,
@ -45,8 +47,6 @@ use libc::{
utsname,
write,
writev,
setsockopt,
dup2,
};
/// exit
@ -99,9 +99,12 @@ pub extern "C" fn ___syscall5(
let flags: i32 = varargs.get(instance);
let mode: u32 = varargs.get(instance);
let pathname_addr = instance.memory_offset_addr(0, pathname as usize) as *const i8;
let path_str = unsafe {std::ffi::CStr::from_ptr(pathname_addr).to_str().unwrap()};
let path_str = unsafe { std::ffi::CStr::from_ptr(pathname_addr).to_str().unwrap() };
let fd = unsafe { open(pathname_addr, flags, mode) };
debug!("=> pathname: {}, flags: {}, mode: {} = fd: {}\npath: {}", pathname, flags, mode, fd, path_str);
debug!(
"=> pathname: {}, flags: {}, mode: {} = fd: {}\npath: {}",
pathname, flags, mode, fd, path_str
);
fd
}
@ -211,7 +214,10 @@ pub extern "C" fn ___syscall102(
let ty: i32 = socket_varargs.get(instance);
let protocol: i32 = socket_varargs.get(instance);
let socket = unsafe { socket(domain, ty, protocol) };
debug!("=> domain: {} (AF_INET/2), type: {} (SOCK_STREAM/1), protocol: {} = fd: {}", domain, ty, protocol, socket);
debug!(
"=> domain: {} (AF_INET/2), type: {} (SOCK_STREAM/1), protocol: {} = fd: {}",
domain, ty, protocol, socket
);
socket
}
2 => {
@ -224,7 +230,10 @@ pub extern "C" fn ___syscall102(
let address = instance.memory_offset_addr(0, address as usize) as *mut sockaddr;
let status = unsafe { bind(socket, address, address_len) };
debug!("=> socketfd: {}, address: {:?}, address_len: {} = status: {}", socket, address, address_len, status);
debug!(
"=> socketfd: {}, address: {:?}, address_len: {} = status: {}",
socket, address, address_len, status
);
status
}
3 => {
@ -243,7 +252,10 @@ pub extern "C" fn ___syscall102(
let socket: i32 = socket_varargs.get(instance);
let backlog: i32 = socket_varargs.get(instance);
let status = unsafe { listen(socket, backlog) };
debug!("=> socketfd: {}, backlog: {} = status: {}", socket, backlog, status);
debug!(
"=> socketfd: {}, backlog: {} = status: {}",
socket, backlog, status
);
status
}
5 => {
@ -316,9 +328,11 @@ pub extern "C" fn ___syscall102(
// setsockopt (socket: c_int, level: c_int, name: c_int, value: *const c_void, option_len: socklen_t) -> c_int
let socket: i32 = socket_varargs.get(instance);
// SOL_SOCKET = 0xffff in BSD
let level: i32 = 0xffff; let _: u32 = socket_varargs.get(instance);
let level: i32 = 0xffff;
let _: u32 = socket_varargs.get(instance);
// SO_ACCEPTCONN = 0x4
let name: i32 = 0x4; let _: u32 = socket_varargs.get(instance);
let name: i32 = 0x4;
let _: u32 = socket_varargs.get(instance);
let value: u32 = socket_varargs.get(instance);
let option_len: u32 = socket_varargs.get(instance);
let value_addr = instance.memory_offset_addr(0, value as usize) as *mut c_void; // Endian problem
@ -394,7 +408,10 @@ pub extern "C" fn ___syscall192(
let flags: i32 = varargs.get(instance);
let fd: i32 = varargs.get(instance);
let off: i32 = varargs.get(instance);
debug!("=> addr: {}, len: {}, prot: {}, flags: {}, fd: {}, off: {}", addr, len, prot, flags, fd, off);
debug!(
"=> addr: {}, len: {}, prot: {}, flags: {}, fd: {}, off: {}",
addr, len, prot, flags, fd, off
);
0
}
@ -481,7 +498,10 @@ pub extern "C" fn ___syscall181(
let buf_ptr = instance.memory_offset_addr(0, buf as _) as _;
let status = unsafe { pwrite(fd, buf_ptr, count as _, offset) as _ };
debug!("=> fd: {}, buf: {}, count: {}, offset: {} = status:{}", fd, buf, count, offset, status);
debug!(
"=> fd: {}, buf: {}, count: {}, offset: {} = status:{}",
fd, buf, count, offset, status
);
status
}
@ -559,7 +579,6 @@ pub extern "C" fn ___syscall202() -> gid_t {
}
}
// chown
pub extern "C" fn ___syscall212(
_which: c_int,
@ -582,7 +601,8 @@ pub extern "C" fn ___syscall221(
_which: c_int,
mut varargs: VarArgs,
instance: &mut Instance,
) -> c_int { // fcntl64
) -> c_int {
// fcntl64
let _fd: i32 = varargs.get(instance);
let cmd: u32 = varargs.get(instance);
match cmd {
@ -613,7 +633,5 @@ pub extern "C" fn ___syscall63(
let src: i32 = varargs.get(instance);
let dst: i32 = varargs.get(instance);
unsafe {
dup2(src, dst)
}
unsafe { dup2(src, dst) }
}

View File

@ -86,8 +86,10 @@ pub extern "C" fn _localtime(time_p: u32, instance: &mut Instance) -> c_int {
let tm_struct = &*localtime(time_p_addr);
// Webassembly allocation
let tm_struct_offset =
(instance.emscripten_data.as_ref().unwrap().malloc)(mem::size_of::<GuestTm>() as _, instance);
let tm_struct_offset = (instance.emscripten_data.as_ref().unwrap().malloc)(
mem::size_of::<GuestTm>() as _,
instance,
);
let tm_struct_ptr = instance.memory_offset_addr(0, tm_struct_offset as _) as *mut GuestTm;
// Initializing

View File

@ -25,5 +25,5 @@ pub mod common;
pub mod sighandler;
#[cfg(test)]
mod spectests;
pub mod webassembly;
pub mod update;
pub mod webassembly;

View File

@ -4,9 +4,9 @@
//! are very special, the async signal unsafety of Rust's TLS implementation generally does not affect the correctness here
//! unless you have memory unsafety elsewhere in your code.
use nix::libc::siginfo_t;
use std::cell::{Cell, UnsafeCell};
use std::sync::Once;
use nix::libc::siginfo_t;
extern "C" {
pub fn setjmp(env: *mut ::nix::libc::c_void) -> ::nix::libc::c_int;
@ -58,7 +58,10 @@ macro_rules! call_protected {
Err(_) => "error while getting the Signal",
_ => "unkown trapped signal",
};
Err(ErrorKind::RuntimeError(format!("trap at {:#x} - {}", addr, signal)))
Err(ErrorKind::RuntimeError(format!(
"trap at {:#x} - {}",
addr, signal
)))
} else {
let ret = $x; // TODO: Switch stack?
*jmp_buf = prev_jmp_buf;

View File

@ -5,10 +5,10 @@
//! Please read more about this here: https://github.com/CraneStation/wasmtime/issues/15
//! This code is inspired by: https://github.com/pepyakin/wasmtime/commit/625a2b6c0815b21996e111da51b9664feb174622
use super::recovery;
use nix::libc::{c_void, siginfo_t};
use nix::sys::signal::{
sigaction, SaFlags, SigAction, SigHandler, SigSet, SIGBUS, SIGFPE, SIGILL, SIGSEGV,
};
use nix::libc::{siginfo_t, c_void};
pub unsafe fn install_sighandler() {
let sa = SigAction::new(
@ -22,7 +22,11 @@ pub unsafe fn install_sighandler() {
sigaction(SIGBUS, &sa).unwrap();
}
extern "C" fn signal_trap_handler(signum: ::nix::libc::c_int, siginfo: *mut siginfo_t, _ucontext: *mut c_void) {
extern "C" fn signal_trap_handler(
signum: ::nix::libc::c_int,
siginfo: *mut siginfo_t,
_ucontext: *mut c_void,
) {
unsafe {
recovery::do_unwind(signum, siginfo);
}

View File

@ -1,17 +1,22 @@
//! When wasmer self-update is executed, this is what gets executed
use std::process::{Command, Stdio};
use std::io;
use std::process::{Command, Stdio};
pub fn self_update() {
println!("Fetching latest installer");
let cmd = Command::new("curl").arg("https://get.wasmer.io").arg("-sSfL")
.stdout(Stdio::piped()).spawn().unwrap();
let cmd = Command::new("curl")
.arg("https://get.wasmer.io")
.arg("-sSfL")
.stdout(Stdio::piped())
.spawn()
.unwrap();
let mut the_process = Command::new("sh")
.stdin(cmd.stdout.unwrap())
.stdout(Stdio::inherit())
.spawn()
.ok().expect("Failed to execute.");
let mut the_process = Command::new("sh")
.stdin(cmd.stdout.unwrap())
.stdout(Stdio::inherit())
.spawn()
.ok()
.expect("Failed to execute.");
the_process.wait();
}

View File

@ -516,20 +516,18 @@ impl Instance {
let free_export = module.info.exports.get("_free");
if malloc_export.is_none() || free_export.is_none() {
None
}
else {
} else {
let malloc_index = if let Some(Export::Function(malloc_index)) = malloc_export {
malloc_index
}
else {
} else {
panic!("Expected malloc function")
};
let malloc_addr = get_function_addr(&malloc_index, &import_functions, &functions);
let malloc_addr =
get_function_addr(&malloc_index, &import_functions, &functions);
let free_index = if let Some(Export::Function(free_index)) = free_export {
free_index
}
else {
} else {
panic!("Expected free export function")
};
let free_addr = get_function_addr(&free_index, &import_functions, &functions);