Tidy up trap-handling code.
This commit is contained in:
@@ -1,19 +1,15 @@
|
|||||||
|
os: Visual Studio 2017
|
||||||
environment:
|
environment:
|
||||||
matrix:
|
matrix:
|
||||||
- TARGET: x86_64-pc-windows-gnu
|
|
||||||
BITS: 64
|
|
||||||
MSYS2: 1
|
|
||||||
- TARGET: x86_64-pc-windows-msvc
|
- TARGET: x86_64-pc-windows-msvc
|
||||||
BITS: 64
|
|
||||||
install:
|
install:
|
||||||
- appveyor DownloadFile https://win.rustup.rs/ -FileName rustup-init.exe
|
- appveyor DownloadFile https://win.rustup.rs/ -FileName rustup-init.exe
|
||||||
- rustup-init.exe -yv --default-host %target%
|
- rustup-init.exe -yv --default-host %target%
|
||||||
- set PATH=%PATH%;%USERPROFILE%\.cargo\bin
|
- set PATH=%PATH%;%USERPROFILE%\.cargo\bin
|
||||||
- if defined MSYS2 set PATH=C:\msys64\mingw%BITS%\bin;%PATH%
|
|
||||||
- rustc -vV
|
- rustc -vV
|
||||||
- cargo -vV
|
- cargo -vV
|
||||||
- git submodule update --init --recursive
|
- git submodule update --init --recursive
|
||||||
build: false
|
build: false
|
||||||
test_script:
|
test_script:
|
||||||
- cargo build --verbose --all
|
- set RUST_BACKTRACE=1
|
||||||
- cargo test --verbose --all
|
- cargo test --verbose --all
|
||||||
|
|||||||
12
build.rs
12
build.rs
@@ -87,11 +87,13 @@ fn write_testsuite_tests(out: &mut File, dir_entry: DirEntry, testsuite: &str) -
|
|||||||
" .expect(\"instantiating \\\"spectest\\\"\");"
|
" .expect(\"instantiating \\\"spectest\\\"\");"
|
||||||
)?;
|
)?;
|
||||||
writeln!(out, " wast_context")?;
|
writeln!(out, " wast_context")?;
|
||||||
writeln!(
|
write!(out, " .run_file(&*isa, Path::new(\"")?;
|
||||||
out,
|
// Write out the string with escape_debug to prevent special characters such
|
||||||
" .run_file(&*isa, Path::new(\"{}\"))",
|
// as backslash from being reinterpreted.
|
||||||
path.display()
|
for c in path.display().to_string().chars() {
|
||||||
)?;
|
write!(out, "{}", c.escape_debug())?;
|
||||||
|
}
|
||||||
|
writeln!(out, "\"))")?;
|
||||||
writeln!(out, " .expect(\"error running wast file\");",)?;
|
writeln!(out, " .expect(\"error running wast file\");",)?;
|
||||||
writeln!(out, " }}")?;
|
writeln!(out, " }}")?;
|
||||||
writeln!(out)?;
|
writeln!(out)?;
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ wasmtime-runtime = { path = "../runtime" }
|
|||||||
region = "1.0.0"
|
region = "1.0.0"
|
||||||
failure = { version = "0.1.3", default-features = false }
|
failure = { version = "0.1.3", default-features = false }
|
||||||
failure_derive = { version = "0.1.3", default-features = false }
|
failure_derive = { version = "0.1.3", default-features = false }
|
||||||
|
target-lexicon = "0.2.0"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["std"]
|
default = ["std"]
|
||||||
|
|||||||
@@ -12,9 +12,10 @@ use std::slice;
|
|||||||
use std::string::String;
|
use std::string::String;
|
||||||
use std::vec::Vec;
|
use std::vec::Vec;
|
||||||
use std::{mem, ptr};
|
use std::{mem, ptr};
|
||||||
|
use target_tunables::target_tunables;
|
||||||
use trampoline_park::TrampolinePark;
|
use trampoline_park::TrampolinePark;
|
||||||
use wasmtime_environ::{
|
use wasmtime_environ::{
|
||||||
compile_module, Compilation, CompileError, DataInitializer, Module, ModuleEnvironment, Tunables,
|
compile_module, Compilation, CompileError, DataInitializer, Module, ModuleEnvironment,
|
||||||
};
|
};
|
||||||
use wasmtime_runtime::{
|
use wasmtime_runtime::{
|
||||||
wasmtime_call_trampoline, Export, Imports, Instance, InstantiationError, VMFunctionBody,
|
wasmtime_call_trampoline, Export, Imports, Instance, InstantiationError, VMFunctionBody,
|
||||||
@@ -42,9 +43,7 @@ impl InstancePlus {
|
|||||||
resolver: &mut Resolver,
|
resolver: &mut Resolver,
|
||||||
) -> Result<Self, ActionError> {
|
) -> Result<Self, ActionError> {
|
||||||
let mut module = Module::new();
|
let mut module = Module::new();
|
||||||
|
let tunables = target_tunables(isa.triple());
|
||||||
// TODO: Allow the tunables to be overridden.
|
|
||||||
let tunables = Tunables::default();
|
|
||||||
|
|
||||||
let (lazy_function_body_inputs, lazy_data_initializers) = {
|
let (lazy_function_body_inputs, lazy_data_initializers) = {
|
||||||
let environ = ModuleEnvironment::new(isa, &mut module, tunables);
|
let environ = ModuleEnvironment::new(isa, &mut module, tunables);
|
||||||
|
|||||||
@@ -37,12 +37,14 @@ extern crate alloc;
|
|||||||
extern crate failure;
|
extern crate failure;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate failure_derive;
|
extern crate failure_derive;
|
||||||
|
extern crate target_lexicon;
|
||||||
|
|
||||||
mod action;
|
mod action;
|
||||||
mod instance_plus;
|
mod instance_plus;
|
||||||
mod jit_code;
|
mod jit_code;
|
||||||
mod link;
|
mod link;
|
||||||
mod resolver;
|
mod resolver;
|
||||||
|
mod target_tunables;
|
||||||
mod trampoline_park;
|
mod trampoline_park;
|
||||||
|
|
||||||
pub use action::{ActionError, ActionOutcome, RuntimeValue};
|
pub use action::{ActionError, ActionOutcome, RuntimeValue};
|
||||||
@@ -50,6 +52,7 @@ pub use instance_plus::InstancePlus;
|
|||||||
pub use jit_code::JITCode;
|
pub use jit_code::JITCode;
|
||||||
pub use link::link_module;
|
pub use link::link_module;
|
||||||
pub use resolver::{NullResolver, Resolver};
|
pub use resolver::{NullResolver, Resolver};
|
||||||
|
pub use target_tunables::target_tunables;
|
||||||
|
|
||||||
#[cfg(not(feature = "std"))]
|
#[cfg(not(feature = "std"))]
|
||||||
mod std {
|
mod std {
|
||||||
|
|||||||
@@ -320,7 +320,10 @@ fn relocate(
|
|||||||
FloorF64 => wasmtime_f64_floor as usize,
|
FloorF64 => wasmtime_f64_floor as usize,
|
||||||
TruncF64 => wasmtime_f64_trunc as usize,
|
TruncF64 => wasmtime_f64_trunc as usize,
|
||||||
NearestF64 => wasmtime_f64_nearest as usize,
|
NearestF64 => wasmtime_f64_nearest as usize,
|
||||||
|
#[cfg(not(target_os = "windows"))]
|
||||||
Probestack => __rust_probestack as usize,
|
Probestack => __rust_probestack as usize,
|
||||||
|
#[cfg(all(target_os = "windows", target_pointer_width = "64"))]
|
||||||
|
Probestack => __chkstk as usize,
|
||||||
other => panic!("unexpected libcall: {}", other),
|
other => panic!("unexpected libcall: {}", other),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -357,5 +360,8 @@ fn relocate(
|
|||||||
/// A declaration for the stack probe function in Rust's standard library, for
|
/// A declaration for the stack probe function in Rust's standard library, for
|
||||||
/// catching callstack overflow.
|
/// catching callstack overflow.
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
#[cfg(not(target_os = "windows"))]
|
||||||
pub fn __rust_probestack();
|
pub fn __rust_probestack();
|
||||||
|
#[cfg(all(target_os = "windows", target_pointer_width = "64"))]
|
||||||
|
pub fn __chkstk();
|
||||||
}
|
}
|
||||||
|
|||||||
22
lib/execute/src/target_tunables.rs
Normal file
22
lib/execute/src/target_tunables.rs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
use std::cmp::min;
|
||||||
|
use target_lexicon::{OperatingSystem, Triple};
|
||||||
|
use wasmtime_environ::Tunables;
|
||||||
|
|
||||||
|
/// Return a `Tunables` instance tuned for the given target platform.
|
||||||
|
pub fn target_tunables(triple: &Triple) -> Tunables {
|
||||||
|
let mut result = Tunables::default();
|
||||||
|
|
||||||
|
match triple.operating_system {
|
||||||
|
OperatingSystem::Windows => {
|
||||||
|
// For now, use a smaller footprint on Windows so that we don't
|
||||||
|
// don't outstrip the paging file.
|
||||||
|
// TODO: Make this configurable.
|
||||||
|
result.static_memory_bound = min(result.static_memory_bound, 0x100);
|
||||||
|
result.static_memory_offset_guard_size =
|
||||||
|
min(result.static_memory_offset_guard_size, 0x10000);
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
|
||||||
|
result
|
||||||
|
}
|
||||||
@@ -23,6 +23,9 @@ cast = { version = "0.2.2", default-features = false }
|
|||||||
failure = { version = "0.1.3", default-features = false }
|
failure = { version = "0.1.3", default-features = false }
|
||||||
failure_derive = { version = "0.1.3", default-features = false }
|
failure_derive = { version = "0.1.3", default-features = false }
|
||||||
|
|
||||||
|
[target.'cfg(target_os = "windows")'.dependencies]
|
||||||
|
winapi = { version = "0.3.6", features = ["winbase", "memoryapi"] }
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
cmake = "0.1.35"
|
cmake = "0.1.35"
|
||||||
bindgen = "0.44.0"
|
bindgen = "0.44.0"
|
||||||
|
|||||||
@@ -453,7 +453,9 @@ WasmTrapHandler(LPEXCEPTION_POINTERS exception)
|
|||||||
|
|
||||||
EXCEPTION_RECORD* record = exception->ExceptionRecord;
|
EXCEPTION_RECORD* record = exception->ExceptionRecord;
|
||||||
if (record->ExceptionCode != EXCEPTION_ACCESS_VIOLATION &&
|
if (record->ExceptionCode != EXCEPTION_ACCESS_VIOLATION &&
|
||||||
record->ExceptionCode != EXCEPTION_ILLEGAL_INSTRUCTION)
|
record->ExceptionCode != EXCEPTION_ILLEGAL_INSTRUCTION &&
|
||||||
|
record->ExceptionCode != EXCEPTION_STACK_OVERFLOW &&
|
||||||
|
record->ExceptionCode != EXCEPTION_INT_DIVIDE_BY_ZERO)
|
||||||
{
|
{
|
||||||
return EXCEPTION_CONTINUE_SEARCH;
|
return EXCEPTION_CONTINUE_SEARCH;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,6 +42,8 @@ extern crate cast;
|
|||||||
extern crate failure;
|
extern crate failure;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate failure_derive;
|
extern crate failure_derive;
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
extern crate winapi;
|
||||||
|
|
||||||
mod export;
|
mod export;
|
||||||
mod imports;
|
mod imports;
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ impl Drop for Mmap {
|
|||||||
if !self.ptr.is_null() {
|
if !self.ptr.is_null() {
|
||||||
use winapi::um::memoryapi::VirtualFree;
|
use winapi::um::memoryapi::VirtualFree;
|
||||||
use winapi::um::winnt::MEM_RELEASE;
|
use winapi::um::winnt::MEM_RELEASE;
|
||||||
let r = unsafe { VirtualFree(self.ptr, self.len, MEM_RELEASE) };
|
let r = unsafe { VirtualFree(self.ptr as *mut libc::c_void, self.len, MEM_RELEASE) };
|
||||||
assert_eq!(r, 0);
|
assert_eq!(r, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use target_lexicon::HOST;
|
|||||||
use wasmtime_environ::{
|
use wasmtime_environ::{
|
||||||
translate_signature, Export, MemoryPlan, MemoryStyle, Module, TablePlan, TableStyle,
|
translate_signature, Export, MemoryPlan, MemoryStyle, Module, TablePlan, TableStyle,
|
||||||
};
|
};
|
||||||
use wasmtime_execute::{ActionError, InstancePlus};
|
use wasmtime_execute::{target_tunables, ActionError, InstancePlus};
|
||||||
use wasmtime_runtime::{Imports, VMFunctionBody};
|
use wasmtime_runtime::{Imports, VMFunctionBody};
|
||||||
|
|
||||||
extern "C" fn spectest_print() {}
|
extern "C" fn spectest_print() {}
|
||||||
@@ -199,14 +199,17 @@ pub fn instantiate_spectest() -> Result<InstancePlus, ActionError> {
|
|||||||
.exports
|
.exports
|
||||||
.insert("table".to_owned(), Export::Table(table));
|
.insert("table".to_owned(), Export::Table(table));
|
||||||
|
|
||||||
|
let tunables = target_tunables(&HOST);
|
||||||
let memory = module.memory_plans.push(MemoryPlan {
|
let memory = module.memory_plans.push(MemoryPlan {
|
||||||
memory: Memory {
|
memory: Memory {
|
||||||
minimum: 1,
|
minimum: 1,
|
||||||
maximum: Some(2),
|
maximum: Some(2),
|
||||||
shared: false,
|
shared: false,
|
||||||
},
|
},
|
||||||
style: MemoryStyle::Static { bound: 65536 },
|
style: MemoryStyle::Static {
|
||||||
offset_guard_size: 0x80000000,
|
bound: tunables.static_memory_bound,
|
||||||
|
},
|
||||||
|
offset_guard_size: tunables.static_memory_offset_guard_size,
|
||||||
});
|
});
|
||||||
module
|
module
|
||||||
.exports
|
.exports
|
||||||
|
|||||||
@@ -253,7 +253,7 @@ impl WastContext {
|
|||||||
) -> Result<(), WastFileError> {
|
) -> Result<(), WastFileError> {
|
||||||
let mut parser = ScriptParser::from_str(str::from_utf8(wast).unwrap()).unwrap();
|
let mut parser = ScriptParser::from_str(str::from_utf8(wast).unwrap()).unwrap();
|
||||||
|
|
||||||
while let Some(Command { kind, line }) = parser.next().unwrap() {
|
while let Some(Command { kind, line }) = parser.next().expect("parser") {
|
||||||
match kind {
|
match kind {
|
||||||
CommandKind::Module { module, name } => {
|
CommandKind::Module { module, name } => {
|
||||||
self.module(isa, name, module)
|
self.module(isa, name, module)
|
||||||
|
|||||||
Reference in New Issue
Block a user