Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions .azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,6 @@ jobs:
submodules: true
- template: ci/azure-install-rust.yml

- script: |
powershell -Command "$ProgressPreference = 'SilentlyContinue'; iwr -outf %TEMP%\LLVM-8.0.0-win64.exe https://rust-lang-ci2.s3.amazonaws.com/rust-ci-mirror/LLVM-8.0.0-win64.exe"
%TEMP%\LLVM-8.0.0-win64.exe /S /NCRC
condition: eq(variables['Agent.OS'], 'Windows_NT')
displayName: Install clang (Windows)

- script: cargo fetch
displayName: Fetch cargo dependencies

Expand Down Expand Up @@ -118,12 +112,6 @@ jobs:
- bash: echo "##vso[task.setvariable variable=RUSTC_VERSION;]`rustc --version`"
displayName: Set rustc version string for caching

- script: |
powershell -Command "$ProgressPreference = 'SilentlyContinue'; iwr -outf %TEMP%\LLVM-8.0.0-win64.exe https://rust-lang-ci2.s3.amazonaws.com/rust-ci-mirror/LLVM-8.0.0-win64.exe"
%TEMP%\LLVM-8.0.0-win64.exe /S /NCRC
condition: eq(variables['Agent.OS'], 'Windows_NT')
displayName: Install clang (Windows)

# - bash: |
# set -e
# curl -Lfo sccache.tar.gz https://github.com/mozilla/sccache/releases/download/0.2.9/sccache-0.2.9-x86_64-apple-darwin.tar.gz
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ obtain a full checkout, like this:
git clone --recurse-submodules https://github.com/CraneStation/wasmtime.git
```

To build Wasmtime, install cmake and clang, and then build with cargo, such
as with "cargo build --release". For information on installing clang, see
[rust-bindgen's documentation](https://github.com/rust-lang/rust-bindgen/blob/master/book/src/requirements.md).
To build an optimized version of Wasmtime, use Cargo:

```
cargo build --release
```

There are Rust, C, and C++ toolchains that can compile programs with WASI. See
the [WASI intro][WASI intro] for more information, and the [WASI tutorial][WASI tutorial]
Expand Down
4 changes: 1 addition & 3 deletions wasmtime-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ indexmap = "1.0.2"
winapi = { version = "0.3.6", features = ["winbase", "memoryapi"] }

[build-dependencies]
cmake = "0.1.35"
bindgen = "0.51.0"
regex = "1.0.6"
cc = "1.0"

[features]
default = ["std"]
Expand Down
49 changes: 16 additions & 33 deletions wasmtime-runtime/build.rs
Original file line number Diff line number Diff line change
@@ -1,37 +1,20 @@
extern crate bindgen;
extern crate cmake;
extern crate regex;

use cmake::Config;
use regex::Regex;
use std::env;
use std::path::PathBuf;

fn main() {
let dst = Config::new("signalhandlers").build();

println!("cargo:rustc-link-search=native={}", dst.display());
println!("cargo:rustc-link-lib=static=SignalHandlers");

let mut bindings_builder = bindgen::Builder::default()
.header("signalhandlers/SignalHandlers.hpp")
.whitelist_type("TrapContext")
.whitelist_type("jmp_buf")
.whitelist_function("EnsureEagerSignalHandlers");

// If we're compiling for Darwin, compile in extra Darwin support routines.
if Regex::new(r"-darwin[[:digit:].]*$")
.unwrap()
.is_match(&env::var("TARGET").unwrap())
{
bindings_builder = bindings_builder.whitelist_function("EnsureDarwinMachPorts");
println!("cargo:rerun-if-changed=signalhandlers/SignalHandlers.cpp");
println!("cargo:rerun-if-changed=signalhandlers/SignalHandlers.hpp");
println!("cargo:rerun-if-changed=signalhandlers/Trampolines.cpp");
let target = std::env::var("TARGET").unwrap();
let mut build = cc::Build::new();
build
.cpp(true)
.warnings(false)
.file("signalhandlers/SignalHandlers.cpp")
.file("signalhandlers/Trampolines.cpp");
if !target.contains("windows") {
build
.flag("-std=c++11")
.flag("-fno-exceptions")
.flag("-fno-rtti");
}

let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());

bindings_builder
.generate()
.expect("Unable to generate bindings")
.write_to_file(out_path.join("signalhandlers.rs"))
.expect("Couldn't write bindings!");
build.compile("signalhandlers");
}
12 changes: 0 additions & 12 deletions wasmtime-runtime/signalhandlers/CMakeLists.txt

This file was deleted.

4 changes: 2 additions & 2 deletions wasmtime-runtime/signalhandlers/SignalHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ WasmTrapHandler(int signum, siginfo_t* info, void* context)
extern "C" MFBT_API bool IsSignalHandlingBroken();
#endif

bool
int
EnsureEagerSignalHandlers()
{
#if defined(ANDROID) && defined(MOZ_LINKER)
Expand Down Expand Up @@ -765,7 +765,7 @@ EnsureEagerSignalHandlers()
return true;
}

bool
int
EnsureDarwinMachPorts()
{
#ifdef USE_APPLE_MACH_PORTS
Expand Down
14 changes: 5 additions & 9 deletions wasmtime-runtime/signalhandlers/SignalHandlers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,11 @@ extern "C" {
// Record the Trap code and wasm bytecode offset in TLS somewhere
void RecordTrap(const uint8_t* pc);

// Initiate an unwind.
void* EnterScope(void*);
void LeaveScope(void*);
void* GetScope(void);
void Unwind(void);

// Trap initialization state.
struct TrapContext {
bool triedToInstallSignalHandlers;
bool haveSignalHandlers;
};

// This function performs the low-overhead signal handler initialization that we
// want to do eagerly to ensure a more-deterministic global process state. This
// is especially relevant for signal handlers since handler ordering depends on
Expand All @@ -31,14 +27,14 @@ struct TrapContext {
// called at the end of the startup process, after other handlers have been
// installed. This function can thus be called multiple times, having no effect
// after the first call.
bool
int
EnsureEagerSignalHandlers(void);

// Assuming EnsureEagerProcessSignalHandlers() has already been called,
// this function performs the full installation of signal handlers which must
// be performed per-thread. This operation may incur some overhead and
// so should be done only when needed to use wasm.
bool
int
EnsureDarwinMachPorts(void);

#ifdef __cplusplus
Expand Down
37 changes: 37 additions & 0 deletions wasmtime-runtime/signalhandlers/Trampolines.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <setjmp.h>

#include "SignalHandlers.hpp"

extern "C"
int WasmtimeCallTrampoline(void *vmctx, void (*body)(void*, void*), void *args) {
jmp_buf buf;
void *volatile prev;
if (setjmp(buf) != 0) {
LeaveScope(prev);
return 0;
}
prev = EnterScope(&buf);
body(vmctx, args);
LeaveScope(prev);
return 1;
}

extern "C"
int WasmtimeCall(void *vmctx, void (*body)(void*)) {
jmp_buf buf;
void *volatile prev;
if (setjmp(buf) != 0) {
LeaveScope(prev);
return 0;
}
prev = EnterScope(&buf);
body(vmctx);
LeaveScope(prev);
return 1;
}

extern "C"
void Unwind() {
jmp_buf *buf = (jmp_buf*) GetScope();
longjmp(*buf, 1);
}
31 changes: 20 additions & 11 deletions wasmtime-runtime/src/signalhandlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,20 @@

use crate::vmcontext::VMContext;
use core::borrow::{Borrow, BorrowMut};
use core::cell::RefCell;
use core::cell::Cell;
use std::sync::RwLock;

include!(concat!(env!("OUT_DIR"), "/signalhandlers.rs"));
#[derive(Default)]
struct TrapContext {
tried_to_install_signal_handlers: Cell<bool>,
have_signal_handlers: Cell<bool>,
}

extern "C" {
fn EnsureEagerSignalHandlers() -> libc::c_int;
#[cfg(any(target_os = "macos", target_os = "ios"))]
fn EnsureDarwinMachPorts() -> libc::c_int;
}

struct InstallState {
tried: bool,
Expand Down Expand Up @@ -50,16 +60,15 @@ pub extern "C" fn wasmtime_init_eager() {
state.tried = true;
assert!(!state.success);

if !unsafe { EnsureEagerSignalHandlers() } {
if unsafe { EnsureEagerSignalHandlers() == 0 } {
return;
}

state.success = true;
}

thread_local! {
static TRAP_CONTEXT: RefCell<TrapContext> =
RefCell::new(TrapContext { triedToInstallSignalHandlers: false, haveSignalHandlers: false });
static TRAP_CONTEXT: TrapContext = TrapContext::default();
}

/// Assuming `EnsureEagerProcessSignalHandlers` has already been called,
Expand All @@ -68,10 +77,10 @@ thread_local! {
/// so should be done only when needed to use wasm.
#[no_mangle]
pub extern "C" fn wasmtime_init_finish(vmctx: &mut VMContext) {
if !TRAP_CONTEXT.with(|cx| cx.borrow().triedToInstallSignalHandlers) {
if !TRAP_CONTEXT.with(|cx| cx.tried_to_install_signal_handlers.get()) {
TRAP_CONTEXT.with(|cx| {
cx.borrow_mut().triedToInstallSignalHandlers = true;
assert!(!cx.borrow().haveSignalHandlers);
cx.tried_to_install_signal_handlers.set(true);
assert!(!cx.have_signal_handlers.get());
});

{
Expand All @@ -90,12 +99,12 @@ pub extern "C" fn wasmtime_init_finish(vmctx: &mut VMContext) {
ensure_darwin_mach_ports();

TRAP_CONTEXT.with(|cx| {
cx.borrow_mut().haveSignalHandlers = true;
cx.have_signal_handlers.set(true);
})
}

let instance = unsafe { vmctx.instance() };
let have_signal_handlers = TRAP_CONTEXT.with(|cx| cx.borrow().haveSignalHandlers);
let have_signal_handlers = TRAP_CONTEXT.with(|cx| cx.have_signal_handlers.get());
if !have_signal_handlers && instance.needs_signal_handlers() {
panic!("failed to install signal handlers");
}
Expand All @@ -113,7 +122,7 @@ fn ensure_darwin_mach_ports() {
state.tried = true;
assert!(!state.success);

if !unsafe { EnsureDarwinMachPorts() } {
if unsafe { EnsureDarwinMachPorts() != 0 } {
return;
}

Expand Down
Loading