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 { unsafe {
let passwd = &*libc_getpwnam(name.as_ptr()); let passwd = &*libc_getpwnam(name.as_ptr());
let passwd_struct_offset = let passwd_struct_offset = (instance.emscripten_data.as_ref().unwrap().malloc)(
(instance.emscripten_data.as_ref().unwrap().malloc)(mem::size_of::<GuestPasswd>() as _, instance); mem::size_of::<GuestPasswd>() as _,
instance,
);
let passwd_struct_ptr = let passwd_struct_ptr =
instance.memory_offset_addr(0, passwd_struct_offset as _) as *mut GuestPasswd; 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 { unsafe {
let group = &*libc_getgrnam(name.as_ptr()); let group = &*libc_getgrnam(name.as_ptr());
let group_struct_offset = let group_struct_offset = (instance.emscripten_data.as_ref().unwrap().malloc)(
(instance.emscripten_data.as_ref().unwrap().malloc)(mem::size_of::<GuestGroup>() as _, instance); mem::size_of::<GuestGroup>() as _,
instance,
);
let group_struct_ptr = let group_struct_ptr =
instance.memory_offset_addr(0, group_struct_offset as _) as *mut GuestGroup; instance.memory_offset_addr(0, group_struct_offset as _) as *mut GuestGroup;

View File

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

View File

@ -12,6 +12,7 @@ use libc::{
// fcntl, ioctl, setsockopt, getppid // fcntl, ioctl, setsockopt, getppid
close, close,
connect, connect,
dup2,
exit, exit,
fstat, fstat,
getgid, getgid,
@ -36,6 +37,7 @@ use libc::{
recvmsg, recvmsg,
sendmsg, sendmsg,
sendto, sendto,
setsockopt,
sockaddr, sockaddr,
socket, socket,
socklen_t, socklen_t,
@ -45,8 +47,6 @@ use libc::{
utsname, utsname,
write, write,
writev, writev,
setsockopt,
dup2,
}; };
/// exit /// exit
@ -99,9 +99,12 @@ pub extern "C" fn ___syscall5(
let flags: i32 = varargs.get(instance); let flags: i32 = varargs.get(instance);
let mode: u32 = varargs.get(instance); let mode: u32 = varargs.get(instance);
let pathname_addr = instance.memory_offset_addr(0, pathname as usize) as *const i8; 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) }; 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 fd
} }
@ -211,7 +214,10 @@ pub extern "C" fn ___syscall102(
let ty: i32 = socket_varargs.get(instance); let ty: i32 = socket_varargs.get(instance);
let protocol: i32 = socket_varargs.get(instance); let protocol: i32 = socket_varargs.get(instance);
let socket = unsafe { socket(domain, ty, protocol) }; 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 socket
} }
2 => { 2 => {
@ -224,7 +230,10 @@ pub extern "C" fn ___syscall102(
let address = instance.memory_offset_addr(0, address as usize) as *mut sockaddr; let address = instance.memory_offset_addr(0, address as usize) as *mut sockaddr;
let status = unsafe { bind(socket, address, address_len) }; 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 status
} }
3 => { 3 => {
@ -243,7 +252,10 @@ pub extern "C" fn ___syscall102(
let socket: i32 = socket_varargs.get(instance); let socket: i32 = socket_varargs.get(instance);
let backlog: i32 = socket_varargs.get(instance); let backlog: i32 = socket_varargs.get(instance);
let status = unsafe { listen(socket, backlog) }; let status = unsafe { listen(socket, backlog) };
debug!("=> socketfd: {}, backlog: {} = status: {}", socket, backlog, status); debug!(
"=> socketfd: {}, backlog: {} = status: {}",
socket, backlog, status
);
status status
} }
5 => { 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 // 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); let socket: i32 = socket_varargs.get(instance);
// SOL_SOCKET = 0xffff in BSD // 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 // 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 value: u32 = socket_varargs.get(instance);
let option_len: 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 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 flags: i32 = varargs.get(instance);
let fd: i32 = varargs.get(instance); let fd: i32 = varargs.get(instance);
let off: 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 0
} }
@ -481,7 +498,10 @@ pub extern "C" fn ___syscall181(
let buf_ptr = instance.memory_offset_addr(0, buf as _) as _; let buf_ptr = instance.memory_offset_addr(0, buf as _) as _;
let status = unsafe { pwrite(fd, buf_ptr, count as _, offset) 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 status
} }
@ -559,7 +579,6 @@ pub extern "C" fn ___syscall202() -> gid_t {
} }
} }
// chown // chown
pub extern "C" fn ___syscall212( pub extern "C" fn ___syscall212(
_which: c_int, _which: c_int,
@ -582,7 +601,8 @@ pub extern "C" fn ___syscall221(
_which: c_int, _which: c_int,
mut varargs: VarArgs, mut varargs: VarArgs,
instance: &mut Instance, instance: &mut Instance,
) -> c_int { // fcntl64 ) -> c_int {
// fcntl64
let _fd: i32 = varargs.get(instance); let _fd: i32 = varargs.get(instance);
let cmd: u32 = varargs.get(instance); let cmd: u32 = varargs.get(instance);
match cmd { match cmd {
@ -613,7 +633,5 @@ pub extern "C" fn ___syscall63(
let src: i32 = varargs.get(instance); let src: i32 = varargs.get(instance);
let dst: i32 = varargs.get(instance); let dst: i32 = varargs.get(instance);
unsafe { unsafe { dup2(src, dst) }
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); let tm_struct = &*localtime(time_p_addr);
// Webassembly allocation // Webassembly allocation
let tm_struct_offset = let tm_struct_offset = (instance.emscripten_data.as_ref().unwrap().malloc)(
(instance.emscripten_data.as_ref().unwrap().malloc)(mem::size_of::<GuestTm>() as _, instance); mem::size_of::<GuestTm>() as _,
instance,
);
let tm_struct_ptr = instance.memory_offset_addr(0, tm_struct_offset as _) as *mut GuestTm; let tm_struct_ptr = instance.memory_offset_addr(0, tm_struct_offset as _) as *mut GuestTm;
// Initializing // Initializing

View File

@ -25,5 +25,5 @@ pub mod common;
pub mod sighandler; pub mod sighandler;
#[cfg(test)] #[cfg(test)]
mod spectests; mod spectests;
pub mod webassembly;
pub mod update; 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 //! 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. //! unless you have memory unsafety elsewhere in your code.
use nix::libc::siginfo_t;
use std::cell::{Cell, UnsafeCell}; use std::cell::{Cell, UnsafeCell};
use std::sync::Once; use std::sync::Once;
use nix::libc::siginfo_t;
extern "C" { extern "C" {
pub fn setjmp(env: *mut ::nix::libc::c_void) -> ::nix::libc::c_int; 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", Err(_) => "error while getting the Signal",
_ => "unkown trapped signal", _ => "unkown trapped signal",
}; };
Err(ErrorKind::RuntimeError(format!("trap at {:#x} - {}", addr, signal))) Err(ErrorKind::RuntimeError(format!(
"trap at {:#x} - {}",
addr, signal
)))
} else { } else {
let ret = $x; // TODO: Switch stack? let ret = $x; // TODO: Switch stack?
*jmp_buf = prev_jmp_buf; *jmp_buf = prev_jmp_buf;

View File

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

View File

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

View File

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