Merge branch 'master' into feature/complete-fd-seek

This commit is contained in:
Syrus 2019-07-13 15:40:51 -07:00
commit b0ead8fc04
9 changed files with 94 additions and 28 deletions

View File

@ -111,6 +111,10 @@ jobs:
name: Debug flag checked name: Debug flag checked
command: | command: |
cargo check --features "debug" --release cargo check --features "debug" --release
- run:
name: Check
command: |
make check
- run: - run:
name: Release name: Release
command: make release-fast command: make release-fast
@ -163,6 +167,11 @@ jobs:
ulimit -n 8000 ulimit -n 8000
sudo sysctl -w kern.maxfiles=655360 kern.maxfilesperproc=327680 sudo sysctl -w kern.maxfiles=655360 kern.maxfilesperproc=327680
make test make test
- run:
name: Check
command: |
export PATH="$HOME/.cargo/bin:$PATH"
make check
- run: - run:
name: Release name: Release
command: | command: |

View File

@ -67,7 +67,7 @@ rustc_version = "0.2.3"
[features] [features]
default = ["fast-tests", "wasi"] default = ["fast-tests", "wasi"]
"loader:kernel" = ["wasmer-kernel-loader"] "loader-kernel" = ["wasmer-kernel-loader"]
debug = ["wasmer-runtime-core/debug"] debug = ["wasmer-runtime-core/debug"]
trace = ["wasmer-runtime-core/trace"] trace = ["wasmer-runtime-core/trace"]
extra-debug = ["wasmer-clif-backend/debug", "wasmer-runtime-core/debug"] extra-debug = ["wasmer-clif-backend/debug", "wasmer-runtime-core/debug"]

View File

@ -117,8 +117,11 @@ debug:
install: install:
cargo install --path . cargo install --path .
check:
cargo check --release --features backend-singlepass,backend-llvm,loader-kernel
release: release:
cargo build --release --features backend-singlepass,backend-llvm,loader:kernel cargo build --release --features backend-singlepass,backend-llvm,loader-kernel
# Only one backend (cranelift) # Only one backend (cranelift)
release-fast: release-fast:

View File

@ -117,6 +117,7 @@ pub struct CompilerConfig {
pub symbol_map: Option<HashMap<u32, String>>, pub symbol_map: Option<HashMap<u32, String>>,
pub memory_bound_check_mode: MemoryBoundCheckMode, pub memory_bound_check_mode: MemoryBoundCheckMode,
pub enforce_stack_check: bool, pub enforce_stack_check: bool,
pub track_state: bool,
} }
pub trait Compiler { pub trait Compiler {

View File

@ -111,7 +111,13 @@ impl ModuleStateMap {
.unwrap(); .unwrap();
match fsm.call_offsets.get(&(ip - base)) { match fsm.call_offsets.get(&(ip - base)) {
Some(x) => Some((fsm, fsm.diffs[x.diff_id].build_state(fsm))), Some(x) => {
if x.diff_id < fsm.diffs.len() {
Some((fsm, fsm.diffs[x.diff_id].build_state(fsm)))
} else {
None
}
}
None => None, None => None,
} }
} }
@ -132,7 +138,13 @@ impl ModuleStateMap {
.unwrap(); .unwrap();
match fsm.trappable_offsets.get(&(ip - base)) { match fsm.trappable_offsets.get(&(ip - base)) {
Some(x) => Some((fsm, fsm.diffs[x.diff_id].build_state(fsm))), Some(x) => {
if x.diff_id < fsm.diffs.len() {
Some((fsm, fsm.diffs[x.diff_id].build_state(fsm)))
} else {
None
}
}
None => None, None => None,
} }
} }
@ -149,7 +161,13 @@ impl ModuleStateMap {
.unwrap(); .unwrap();
match fsm.loop_offsets.get(&(ip - base)) { match fsm.loop_offsets.get(&(ip - base)) {
Some(x) => Some((fsm, fsm.diffs[x.diff_id].build_state(fsm))), Some(x) => {
if x.diff_id < fsm.diffs.len() {
Some((fsm, fsm.diffs[x.diff_id].build_state(fsm)))
} else {
None
}
}
None => None, None => None,
} }
} }

View File

@ -317,6 +317,7 @@ pub struct CodegenError {
struct CodegenConfig { struct CodegenConfig {
memory_bound_check_mode: MemoryBoundCheckMode, memory_bound_check_mode: MemoryBoundCheckMode,
enforce_stack_check: bool, enforce_stack_check: bool,
track_state: bool,
} }
impl ModuleCodeGenerator<X64FunctionCode, X64ExecutionContext, CodegenError> impl ModuleCodeGenerator<X64FunctionCode, X64ExecutionContext, CodegenError>
@ -366,7 +367,8 @@ impl ModuleCodeGenerator<X64FunctionCode, X64ExecutionContext, CodegenError>
begin_label_info.1 = Some(begin_offset); begin_label_info.1 = Some(begin_offset);
let begin_label = begin_label_info.0; let begin_label = begin_label_info.0;
let machine = Machine::new(); let mut machine = Machine::new();
machine.track_state = self.config.as_ref().unwrap().track_state;
dynasm!( dynasm!(
assembler assembler
@ -532,6 +534,7 @@ impl ModuleCodeGenerator<X64FunctionCode, X64ExecutionContext, CodegenError>
self.config = Some(Arc::new(CodegenConfig { self.config = Some(Arc::new(CodegenConfig {
memory_bound_check_mode: config.memory_bound_check_mode, memory_bound_check_mode: config.memory_bound_check_mode,
enforce_stack_check: config.enforce_stack_check, enforce_stack_check: config.enforce_stack_check,
track_state: config.track_state,
})); }));
Ok(()) Ok(())
} }
@ -1594,6 +1597,9 @@ impl X64FunctionCode {
fsm: &mut FunctionStateMap, fsm: &mut FunctionStateMap,
control_stack: &mut [ControlFrame], control_stack: &mut [ControlFrame],
) -> usize { ) -> usize {
if !m.track_state {
return ::std::usize::MAX;
}
let last_frame = control_stack.last_mut().unwrap(); let last_frame = control_stack.last_mut().unwrap();
let mut diff = m.state.diff(&last_frame.state); let mut diff = m.state.diff(&last_frame.state);
diff.last = Some(last_frame.state_diff_id); diff.last = Some(last_frame.state_diff_id);
@ -1769,7 +1775,7 @@ impl FunctionCodeGenerator<CodegenError> for X64FunctionCode {
.unwrap() .unwrap()
.insert(a.get_offset(), callback); .insert(a.get_offset(), callback);
} }
InternalEvent::FunctionBegin(_) | InternalEvent::FunctionEnd => {}, InternalEvent::FunctionBegin(_) | InternalEvent::FunctionEnd => {}
InternalEvent::GetInternal(idx) => { InternalEvent::GetInternal(idx) => {
let idx = idx as usize; let idx = idx as usize;
assert!(idx < INTERNALS_SIZE); assert!(idx < INTERNALS_SIZE);
@ -1820,7 +1826,11 @@ impl FunctionCodeGenerator<CodegenError> for X64FunctionCode {
), ),
Location::GPR(tmp), Location::GPR(tmp),
); );
let loc = get_location_released(a, &mut self.machine, self.value_stack.pop().unwrap()); let loc = get_location_released(
a,
&mut self.machine,
self.value_stack.pop().unwrap(),
);
// Move internal into storage. // Move internal into storage.
Self::emit_relaxed_binop( Self::emit_relaxed_binop(
@ -1832,8 +1842,7 @@ impl FunctionCodeGenerator<CodegenError> for X64FunctionCode {
Location::Memory(tmp, (idx * 8) as i32), Location::Memory(tmp, (idx * 8) as i32),
); );
self.machine.release_temp_gpr(tmp); self.machine.release_temp_gpr(tmp);
} } //_ => unimplemented!(),
//_ => unimplemented!(),
} }
return Ok(()); return Ok(());
} }
@ -2411,7 +2420,14 @@ impl FunctionCodeGenerator<CodegenError> for X64FunctionCode {
loc_b, loc_b,
); );
a.emit_jmp(Condition::NotEqual, normal_path); a.emit_jmp(Condition::NotEqual, normal_path);
a.emit_mov(Size::S64, Location::Imm64(0), ret); Self::emit_relaxed_binop(
a,
&mut self.machine,
Assembler::emit_mov,
Size::S64,
Location::Imm64(0),
ret,
);
a.emit_jmp(Condition::None, end); a.emit_jmp(Condition::None, end);
a.emit_label(normal_path); a.emit_label(normal_path);
@ -4525,9 +4541,14 @@ impl FunctionCodeGenerator<CodegenError> for X64FunctionCode {
|a, m, addr| { |a, m, addr| {
match ret { match ret {
Location::GPR(_) => {} Location::GPR(_) => {}
_ => { Location::Memory(base, offset) => {
a.emit_mov(Size::S64, Location::Imm64(0), ret); a.emit_mov(
Size::S32,
Location::Imm32(0),
Location::Memory(base, offset + 4),
); // clear upper bits
} }
_ => unreachable!(),
} }
Self::emit_relaxed_binop( Self::emit_relaxed_binop(
a, a,

View File

@ -13,6 +13,7 @@ pub struct Machine {
stack_offset: MachineStackOffset, stack_offset: MachineStackOffset,
save_area_offset: Option<MachineStackOffset>, save_area_offset: Option<MachineStackOffset>,
pub state: MachineState, pub state: MachineState,
pub(crate) track_state: bool,
} }
impl Machine { impl Machine {
@ -23,6 +24,7 @@ impl Machine {
stack_offset: MachineStackOffset(0), stack_offset: MachineStackOffset(0),
save_area_offset: None, save_area_offset: None,
state: x64::new_machine_state(), state: x64::new_machine_state(),
track_state: true,
} }
} }

View File

@ -5,10 +5,10 @@ extern crate structopt;
use structopt::StructOpt; use structopt::StructOpt;
#[cfg(feature = "loader:kernel")] #[cfg(feature = "loader-kernel")]
use wasmer_singlepass_backend::SinglePassCompiler; use wasmer_singlepass_backend::SinglePassCompiler;
#[cfg(feature = "loader:kernel")] #[cfg(feature = "loader-kernel")]
use std::os::unix::net::{UnixListener, UnixStream}; use std::os::unix::net::{UnixListener, UnixStream};
#[derive(Debug, StructOpt)] #[derive(Debug, StructOpt)]
@ -24,14 +24,14 @@ struct Listen {
socket: String, socket: String,
} }
#[cfg(feature = "loader:kernel")] #[cfg(feature = "loader-kernel")]
const CMD_RUN_CODE: u32 = 0x901; const CMD_RUN_CODE: u32 = 0x901;
#[cfg(feature = "loader:kernel")] #[cfg(feature = "loader-kernel")]
const CMD_READ_MEMORY: u32 = 0x902; const CMD_READ_MEMORY: u32 = 0x902;
#[cfg(feature = "loader:kernel")] #[cfg(feature = "loader-kernel")]
const CMD_WRITE_MEMORY: u32 = 0x903; const CMD_WRITE_MEMORY: u32 = 0x903;
#[cfg(feature = "loader:kernel")] #[cfg(feature = "loader-kernel")]
fn handle_client(mut stream: UnixStream) { fn handle_client(mut stream: UnixStream) {
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
use std::io::{Read, Write}; use std::io::{Read, Write};
@ -54,6 +54,7 @@ fn handle_client(mut stream: UnixStream) {
symbol_map: None, symbol_map: None,
memory_bound_check_mode: MemoryBoundCheckMode::Disable, memory_bound_check_mode: MemoryBoundCheckMode::Disable,
enforce_stack_check: true, enforce_stack_check: true,
track_state: false,
}, },
&SinglePassCompiler::new(), &SinglePassCompiler::new(),
) )
@ -131,7 +132,7 @@ fn handle_client(mut stream: UnixStream) {
} }
} }
#[cfg(feature = "loader:kernel")] #[cfg(feature = "loader-kernel")]
fn run_listen(opts: Listen) { fn run_listen(opts: Listen) {
let listener = UnixListener::bind(&opts.socket).unwrap(); let listener = UnixListener::bind(&opts.socket).unwrap();
use std::thread; use std::thread;
@ -154,7 +155,7 @@ fn run_listen(opts: Listen) {
} }
} }
#[cfg(feature = "loader:kernel")] #[cfg(feature = "loader-kernel")]
fn main() { fn main() {
let options = CLIOptions::from_args(); let options = CLIOptions::from_args();
match options { match options {
@ -164,7 +165,7 @@ fn main() {
} }
} }
#[cfg(not(feature = "loader:kernel"))] #[cfg(not(feature = "loader-kernel"))]
fn main() { fn main() {
panic!("Kwasm loader is not enabled during compilation."); panic!("Kwasm loader is not enabled during compilation.");
} }

View File

@ -112,10 +112,16 @@ struct Run {
)] )]
loader: Option<LoaderName>, loader: Option<LoaderName>,
/// Path to previously saved instance image to resume.
#[cfg(feature = "backend-singlepass")] #[cfg(feature = "backend-singlepass")]
#[structopt(long = "resume")] #[structopt(long = "resume")]
resume: Option<String>, resume: Option<String>,
/// Whether or not state tracking should be disabled during compilation.
/// State tracking is necessary for tier switching and backtracing.
#[structopt(long = "no-track-state")]
no_track_state: bool,
/// The command name is a string that will override the first argument passed /// The command name is a string that will override the first argument passed
/// to the wasm program. This is used in wapm to provide nicer output in /// to the wasm program. This is used in wapm to provide nicer output in
/// help commands and error messages of the running wasm program /// help commands and error messages of the running wasm program
@ -137,7 +143,7 @@ struct Run {
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
enum LoaderName { enum LoaderName {
Local, Local,
#[cfg(feature = "loader:kernel")] #[cfg(feature = "loader-kernel")]
Kernel, Kernel,
} }
@ -145,7 +151,7 @@ impl LoaderName {
pub fn variants() -> &'static [&'static str] { pub fn variants() -> &'static [&'static str] {
&[ &[
"local", "local",
#[cfg(feature = "loader:kernel")] #[cfg(feature = "loader-kernel")]
"kernel", "kernel",
] ]
} }
@ -156,7 +162,7 @@ impl FromStr for LoaderName {
fn from_str(s: &str) -> Result<LoaderName, String> { fn from_str(s: &str) -> Result<LoaderName, String> {
match s.to_lowercase().as_str() { match s.to_lowercase().as_str() {
"local" => Ok(LoaderName::Local), "local" => Ok(LoaderName::Local),
#[cfg(feature = "loader:kernel")] #[cfg(feature = "loader-kernel")]
"kernel" => Ok(LoaderName::Kernel), "kernel" => Ok(LoaderName::Kernel),
_ => Err(format!("The loader {} doesn't exist", s)), _ => Err(format!("The loader {} doesn't exist", s)),
} }
@ -326,14 +332,16 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
Backend::LLVM => return Err("the llvm backend is not enabled".to_string()), Backend::LLVM => return Err("the llvm backend is not enabled".to_string()),
}; };
#[cfg(feature = "loader:kernel")] let track_state = !options.no_track_state;
#[cfg(feature = "loader-kernel")]
let is_kernel_loader = if let Some(LoaderName::Kernel) = options.loader { let is_kernel_loader = if let Some(LoaderName::Kernel) = options.loader {
true true
} else { } else {
false false
}; };
#[cfg(not(feature = "loader:kernel"))] #[cfg(not(feature = "loader-kernel"))]
let is_kernel_loader = false; let is_kernel_loader = false;
let module = if is_kernel_loader { let module = if is_kernel_loader {
@ -343,6 +351,7 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
symbol_map: em_symbol_map, symbol_map: em_symbol_map,
memory_bound_check_mode: MemoryBoundCheckMode::Disable, memory_bound_check_mode: MemoryBoundCheckMode::Disable,
enforce_stack_check: true, enforce_stack_check: true,
track_state,
}, },
&*compiler, &*compiler,
) )
@ -352,6 +361,7 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
&wasm_binary[..], &wasm_binary[..],
CompilerConfig { CompilerConfig {
symbol_map: em_symbol_map, symbol_map: em_symbol_map,
track_state,
..Default::default() ..Default::default()
}, },
&*compiler, &*compiler,
@ -397,6 +407,7 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
&wasm_binary[..], &wasm_binary[..],
CompilerConfig { CompilerConfig {
symbol_map: em_symbol_map, symbol_map: em_symbol_map,
track_state,
..Default::default() ..Default::default()
}, },
&*compiler, &*compiler,
@ -440,7 +451,7 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
.load(LocalLoader) .load(LocalLoader)
.expect("Can't use the local loader"), .expect("Can't use the local loader"),
), ),
#[cfg(feature = "loader:kernel")] #[cfg(feature = "loader-kernel")]
LoaderName::Kernel => Box::new( LoaderName::Kernel => Box::new(
instance instance
.load(::wasmer_kernel_loader::KernelLoader) .load(::wasmer_kernel_loader::KernelLoader)